00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include "cpsp/HCore.hh"
00021 #include <biu/assertbiu.hh>
00022
00023 namespace cpsp
00024 {
00025
00026 HCore::HCore() :
00027 contacts(0), size(0), numOfPSinglets(-1), numOfHSinglets(-1),
00028 evenPositions(0)
00029 {
00030 coreFrame.reset();
00031 }
00032
00033 HCore::HCore(const unsigned int contacts_, const unsigned int size_) :
00034 contacts(contacts_), size(size_), numOfPSinglets(-1),
00035 numOfHSinglets(-1), evenPositions(0)
00036 {
00037 coreFrame.reset();
00038 }
00039
00040 HCore::~HCore()
00041 {
00042 }
00043
00044 void
00045 HCore::reset(const unsigned int contacts_, const unsigned int size_) {
00046 contacts = contacts_;
00047 size = size_;
00048 points.clear();
00049 coreFrame.reset();
00050 actFrameSize = 0;
00051 numOfPSinglets = -1;
00052 numOfHSinglets = -1;
00053 evenPositions = 0;
00054 }
00055
00056 void
00057 HCore::addPoint(const CorePoint& toAdd) {
00058 points.insert(toAdd);
00059 coreFrame.resize(toAdd);
00060 if (toAdd.isEven())
00061 evenPositions++;
00062 }
00063
00064 void
00065 HCore::indexHulls( const biu::LatticeFrame* latFrame,
00066 const unsigned int maxHullLevel) {
00067 assertbiu(latFrame != NULL, "tried to index the hulls without LatticeFrame.");
00068
00069 if ( actFrameSize != latFrame->getFrameSize() )
00070 {
00071
00072 actFrameSize = latFrame->getFrameSize();
00073 hull.clear();
00074 numOfPSinglets = -1;
00075 numOfHSinglets = -1;
00076 }
00077
00078 if ( hull.size() > maxHullLevel)
00079 return;
00080
00081 biu::IntPoint shift = latFrame->getCenter() - coreFrame.getCenter();
00082
00083 if (hull.size() == 0) {
00084 hull.push_back(biu::IndexSet());
00085 for ( CPointSet::const_iterator it = points.begin();
00086 it != points.end(); it++) {
00087
00088 hull[0].insert(latFrame->getIndex((*it) + shift));
00089 }
00090 }
00091
00092 biu::IndexVec neighInd = latFrame->getIndexedNeighborhood();
00093
00094
00095
00096 for (unsigned int lev = hull.size(); lev <= maxHullLevel; lev++) {
00097 if (lev>1)
00098 hull.push_back(biu::IndexSet(hull[lev-1]));
00099 else
00100 hull.push_back(biu::IndexSet());
00101
00102 for ( biu::IndexSet::const_iterator it = hull[lev-1].begin();
00103 it != hull[lev-1].end(); it++) {
00104
00105 for (biu::IndexVec::size_type i = 0; i<neighInd.size(); i++) {
00106
00107 if (hull[0].find((*it) + neighInd[i]) == hull[0].end()) {
00108
00109 hull[lev].insert((*it) + neighInd[i]);
00110 }
00111 }
00112 }
00113 }
00114 }
00115
00116 const biu::IndexSet&
00117 HCore::getIndexedHull( const biu::LatticeFrame* latFrame,
00118 const unsigned int hullLevel) {
00119 indexHulls(latFrame, hullLevel);
00120 return hull[hullLevel];
00121 }
00122
00123 int
00124 HCore::getNumOfHSinglets(const biu::LatticeFrame* latFrame) {
00125 if (!isValid())
00126 numOfHSinglets = -1;
00127 else {
00128 if ( actFrameSize != latFrame->getFrameSize()
00129 || numOfHSinglets == -1)
00130 {
00131 biu::IndexSet core = getIndexedHull(latFrame, 0),
00132 hull = getIndexedHull(latFrame, 1);
00133 biu::IndexVec neighInd = latFrame->getIndexedNeighborhood();
00134 biu::IndexVec::const_iterator neigh;
00135 unsigned int n=0;
00136
00137 numOfHSinglets = 0;
00138 hSinglets.clear();
00139
00140 for ( biu::IndexSet::const_iterator it = core.begin();
00141 it!= core.end();
00142 it++) {
00143
00144 n = 0;
00145
00146 for (neigh=neighInd.begin(); neigh != neighInd.end(); neigh++) {
00147 if ( hull.find((*it)+(*neigh)) != hull.end())
00148 n++;
00149 if (n>1) {
00150 numOfHSinglets++;
00151 hSinglets.insert(*it);
00152 break;
00153 }
00154 }
00155 }
00156 }
00157 }
00158 return numOfHSinglets;
00159 }
00160
00161 int
00162 HCore::getNumOfPSinglets(const biu::LatticeFrame* latFrame) {
00163 if (!isValid())
00164 numOfPSinglets = -1;
00165 else {
00166 if ( actFrameSize != latFrame->getFrameSize()
00167 || numOfPSinglets == -1)
00168 {
00169 biu::IndexSet core = getIndexedHull(latFrame, 0),
00170 hull = getIndexedHull(latFrame, 1);
00171 biu::IndexVec neighInd = latFrame->getIndexedNeighborhood();
00172 biu::IndexVec::const_iterator neigh;
00173 unsigned int n=0;
00174
00175 numOfPSinglets = 0;
00176 pSinglets.clear();
00177
00178 for ( biu::IndexSet::const_iterator it = hull.begin();
00179 it!= hull.end();
00180 it++) {
00181
00182 n = 0;
00183
00184 for (neigh=neighInd.begin(); neigh != neighInd.end(); neigh++) {
00185 if ( core.find((*it)+(*neigh)) != core.end())
00186 n++;
00187 if (n>1) {
00188 numOfPSinglets++;
00189 pSinglets.insert(*it);
00190 break;
00191 }
00192 }
00193 }
00194 }
00195 }
00196 return numOfPSinglets;
00197 }
00198
00201 const biu::IndexSet&
00202 HCore::getIndexedPSinglets(const biu::LatticeFrame* latFrame) {
00203 getNumOfPSinglets(latFrame);
00204 return pSinglets;
00205 }
00206
00207 const biu::IndexSet&
00208 HCore::getIndexedHSinglets(const biu::LatticeFrame* latFrame) {
00209 getNumOfHSinglets(latFrame);
00210 return hSinglets;
00211 }
00212
00213 unsigned int
00214 HCore::getMinEvenOdd(void) {
00215 return ( (points.size()-evenPositions) > evenPositions) ?
00216 evenPositions :
00217 points.size()-evenPositions;
00218 }
00219
00220 }