src/biu/LatticeFrame.cc
Go to the documentation of this file.00001 #include <biu/LatticeFrame.hh>
00002 #include <climits>
00003
00004 namespace biu
00005 {
00006
00007
00008 LatticeFrame::LatticeFrame( const LatticeDescriptor* const latDescriptor,
00009 const unsigned int frameSize_)
00010 : LatticeModel(latDescriptor),
00011 frameSize(frameSize_),
00012 frameSizeP2(frameSize*frameSize)
00013 {
00014 assertbiu(INT_MAX >= (frameSize*frameSize*frameSize),
00015 "the frame size is to big to assure a one-to-one indexing");
00016 }
00017
00018 LatticeFrame::LatticeFrame(const LatticeFrame& toCopy)
00019 : LatticeModel(toCopy.latDescriptor),
00020 frameSize(toCopy.frameSize),
00021 frameSizeP2(toCopy.frameSizeP2)
00022 {
00023 }
00024
00025 LatticeFrame::~LatticeFrame()
00026 {
00027 }
00028
00029 void
00030 LatticeFrame::setFrameSize(const unsigned int frameSize_) {
00031 frameSize = frameSize_;
00032 frameSizeP2 = frameSize*frameSize;
00033 assertbiu(INT_MAX >= (frameSize*frameSize*frameSize),
00034 "the frame size is to big to assure a one-to-one indexing");
00035 }
00036
00037 bool
00038 LatticeFrame::isInFrame(const IntPoint& point) const {
00039 return point.getX() >= 0 && (unsigned int)point.getX() < frameSize
00040 && point.getY() >= 0 && (unsigned int)point.getY() < frameSize
00041 && point.getZ() >= 0 && (unsigned int)point.getZ() < frameSize;
00042 }
00043
00044 LatticeFrame::index_type
00045 LatticeFrame::getIndex(const IntPoint& point) const {
00046 return point.getX() + point.getY()*frameSize + point.getZ()*frameSizeP2;
00047 }
00048
00049 IntPoint
00050 LatticeFrame::getPoint(const index_type& index) const {
00051 return IntPoint( index%frameSize,
00052 (index/frameSize)%frameSize,
00053 (index/frameSizeP2)%frameSize);
00054 }
00055
00056
00057 bool
00058 LatticeFrame::operator== (const LatticeFrame &lf2) const {
00059 bool retVal = true;
00060 retVal &= latDescriptor == lf2.latDescriptor;
00061 retVal &= frameSize == lf2.frameSize;
00062 return retVal;
00063 }
00064
00065 bool
00066 LatticeFrame::operator!= (const LatticeFrame &lf2) const {
00067 return latDescriptor != lf2.latDescriptor || frameSize != lf2.frameSize;
00068 }
00069
00070 std::vector<LatticeFrame::index_type>
00071 LatticeFrame::getIndexedNeighborhood() const {
00072 std::vector<index_type> nInd(latDescriptor->getNeighborhood().size());
00073 LatticeNeighborhood::const_iterator it = latDescriptor->getNeighborhood().begin();
00074 for(size_t i = 0; it != latDescriptor->getNeighborhood().end(); it++)
00075 nInd[i++] = getIndex(*it);
00076 return nInd;
00077 }
00078
00079 MoveSequence
00080 LatticeFrame::indicesToAbsMoves(const std::vector<index_type> indVec) const{
00081 IPointVec points;
00082 for (std::vector<index_type>::const_iterator it = indVec.begin();
00083 it != indVec.end(); it++) {
00084 points.push_back(getPoint(*it));
00085 }
00086 return this->pointsToAbsMoves(points);
00087 }
00088
00089 std::ostream & operator <<(std::ostream &os, IndexSet &x) {
00090 os <<"( ";
00091 for (IndexSet::const_iterator it = x.begin(); it != x.end(); it++)
00092 os <<*it <<", ";
00093 os <<")";
00094 return os;
00095 }
00096
00097 std::ostream & operator <<(std::ostream &os, IndexVec &x) {
00098 os <<"( ";
00099 for (IndexVec::const_iterator it = x.begin(); it != x.end(); it++)
00100 os <<*it <<", ";
00101 os <<")";
00102 return os;
00103 }
00104
00105 }