src/biu/LatticeModel.cc
Go to the documentation of this file.00001 #include <biu/LatticeModel.hh>
00002
00003 namespace biu
00004 {
00005
00006 LatticeModel::LatticeModel(const LatticeDescriptor* const _latDescriptor)
00007 : latDescriptor(_latDescriptor),
00008 latNeighborhood(latDescriptor->getNeighborhood())
00009 {
00010 assertbiu(latDescriptor != NULL,
00011 "tried to create a LatticeModel without a LatticeDescriptor");
00012 }
00013
00014 LatticeModel::LatticeModel(const LatticeModel& toCopy) :
00015
00016 latDescriptor(toCopy.latDescriptor),
00017 latNeighborhood(latDescriptor->getNeighborhood())
00018 {
00019 assertbiu(latDescriptor != NULL,
00020 "tried to create a LatticeModel without a LatticeDescriptor");
00021 }
00022
00023 LatticeModel::~LatticeModel()
00024 {
00025 }
00026
00027
00028
00029
00030
00031 MoveSequence
00032 LatticeModel::relMovesToAbsMoves( const MoveSequence &relMoves ) const {
00033
00034 MoveSequence absMoves(relMoves.size());
00035
00036
00037 Automorphism base=latNeighborhood.getElement(0).getRel2AbsRotation();
00038
00039 for (MoveSequence::size_type i=0; i<relMoves.size(); ++i) {
00040
00041 base = base
00042 * latNeighborhood.getElement(relMoves[i]).getRel2AbsRotation();
00043
00044 IntPoint absVec = base*latNeighborhood.getElement(0);
00045
00046
00047 absMoves[i] = latNeighborhood.getElement(absVec).getMove();
00048 }
00049
00050 return absMoves;
00051 }
00052
00053 MoveSequence
00054 LatticeModel::absMovesToRelMoves( const MoveSequence &absMoves ) const {
00055
00056 MoveSequence relMoves(absMoves.size());
00057
00058
00059 Automorphism base
00060 = latNeighborhood.getElement(absMoves[0]).getAbs2RelRotation();
00061
00062 Move relMove;
00063
00064 for (MoveSequence::size_type i=0; i<absMoves.size(); ++i) {
00065
00066
00067 const IntPoint relVec = base * latNeighborhood.getElement(absMoves[i]);
00068
00069
00070 relMove = latNeighborhood.getElement(relVec).getMove();
00071 relMoves[i] = relMove;
00072
00073 base = latNeighborhood.getElement(relMove).getAbs2RelRotation()
00074 * base;
00075
00076 }
00077 return relMoves;
00078 }
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088 IntPoint
00089 LatticeModel::applyAbsMove( const IntPoint& actPoint,
00090 const Move& absMove) const {
00091 assertbiu(latDescriptor != NULL,
00092 "LatticeModel has no LatticeDescriptor");
00093
00094 LatticeNeighborhood::const_iterator neighbor;
00095 LatticeNeighborhood::const_iterator end = latNeighborhood.end();
00096 for (neighbor = latNeighborhood.begin(); neighbor != end; neighbor++)
00097 if (neighbor->getMove() == absMove) {
00098 return actPoint + (*neighbor);
00099 }
00100
00101 assertbiu(neighbor != end,
00102 "cant find the absolute move in the neighborhood"
00103 "of the LatticeDescriptor");
00104 return IntPoint(actPoint);
00105 }
00106
00107
00108 IPointVec
00109 LatticeModel::absMovesToPoints( const MoveSequence& absMoveSeq ) const {
00110 assertbiu(latDescriptor != NULL,
00111 "LatticeModel has no LatticeDescriptor");
00112
00113 IPointVec points(absMoveSeq.size()+1);
00114 points[0] = biu::IntPoint(0,0,0);
00115 for (MoveSequence::size_type i=0; i< absMoveSeq.size(); i++){
00116
00117 points[i+1] = applyAbsMove( points[i], absMoveSeq[i] );
00118 }
00119 return points;
00120 }
00121
00122 IPointVec
00123 LatticeModel::relMovesToPoints( const MoveSequence& relMoves) const {
00124
00125 IPointVec points(relMoves.size()+1);
00126 points[0] = biu::IntPoint(0,0,0);
00127 return relMovesToPoints(relMoves, points);
00128
00129 }
00130
00131 IPointVec&
00132 LatticeModel::relMovesToPoints( const MoveSequence& relMoves,
00133 IPointVec& toFill) const
00134 {
00135 assertbiu(latDescriptor != NULL,
00136 "LatticeModel has no LatticeDescriptor");
00137
00138
00139 Automorphism base=latNeighborhood.getElement(0).getRel2AbsRotation();
00140
00141 toFill.resize(relMoves.size()+1);
00142 toFill[0] = biu::IntPoint(0,0,0);
00143
00144 for (MoveSequence::size_type i=0; i<relMoves.size(); ++i) {
00145
00146 base = base
00147 * latNeighborhood.getElement(relMoves[i]).getRel2AbsRotation();
00148
00149
00150 toFill[i+1] = toFill[i] +
00151 base*latNeighborhood.getElement(relMoves[0]);
00152 }
00153
00154 return toFill;
00155 }
00156
00157 MoveSequence
00158 LatticeModel::pointsToAbsMoves( const IPointVec& points ) const {
00159 assert(points.size() > 0);
00160 MoveSequence absmoves(points.size()-1);
00161 MoveSequence::size_type i = 0;
00162 biu::IPointVec::const_iterator act = points.begin(), last = act;
00163 for (act++; act != points.end(); last++, act++) {
00164
00165 absmoves[i++] = getAbsMove(*last, *act);
00166 }
00167 return absmoves;
00168 }
00169
00170 IPointSet
00171 LatticeModel::getAllNeighPoints(const IntPoint& center) const
00172 {
00173 assertbiu(latDescriptor != NULL,
00174 "LatticeModel has no LatticeDescriptor");
00175 IPointSet retSet;
00176 for (LatticeNeighborhood::const_iterator it = latNeighborhood.begin();
00177 it != latNeighborhood.end(); it++) {
00178 retSet.insert(center + (*it));
00179 }
00180 return retSet;
00181 }
00182
00183 }