00001 #include "GT2005Clusterliste.h" 00002 using namespace std; 00003 00004 GT2005Clusterliste::GT2005Clusterliste(){ 00005 } 00006 00007 00008 /*a method that add a cluster to the clusterlist and updates the navigation information in vNavi/hNavi. 00009 * if v equals to true, the direction of scanning is vertical and the iterator i gives the position of the new cluster 00010 * in vNavi. 00011 * if v equals to false, the direction of scanning is horizontal and the iterator i gives the position of the new 00012 * cluster in hNavi. 00013 */ 00014 void GT2005Clusterliste::addCluster(GT2005Cluster c, list<list<GT2005Cluster>::iterator>::iterator i, bool v) 00015 { 00016 /* clusterliste clist is empty, so the cluster can be inserted at the front of clist and the navigation-information 00017 * at the front of vNavi and hNavi. 00018 * the cluster stores the iterators of the elements in vNavi and hNavi, which points on it. 00019 */ 00020 if(clist.empty()) 00021 { 00022 //inserting the elements at the front 00023 00024 clist.push_front(c); 00025 vNavi.push_front(clist.begin()); 00026 hNavi.push_front(clist.begin()); 00027 00028 //store the iterators of the element of vNavi and hNavi 00029 clist.begin()->setVPointer(vNavi.begin()); 00030 clist.begin()->setHPointer(hNavi.begin()); 00031 } 00032 else 00033 { 00034 clist.push_front(c); 00035 vhIter = NULL; 00036 00037 if(v) //if scan-line direction is vertical 00038 { 00039 /* update navigation-information vNavi and hNavi. 00040 * the position of the new element in vNavi is given: i 00041 * the position of the new element in hNavi has to be calculated 00042 */ 00043 vNavi.insert(i,clist.begin()); 00044 //stores the iterator of the element in vNavi, which points on the new inserted cluster 00045 --i; 00046 clist.begin()->setVPointer(i); 00047 00048 00049 //calculating the position in hNavi 00050 vhIter = hNavi.begin(); 00051 posGefunden = false; 00052 while((posGefunden == false) && (vhIter != hNavi.end())) 00053 { 00054 cIter = *vhIter; 00055 if(clist.begin()->getYMin() <= cIter->getYMin()) 00056 { 00057 posGefunden = true; 00058 } 00059 ++vhIter; 00060 } 00061 00062 00063 00064 //in case that vhIter doesn´t point to after last element (null) 00065 if(posGefunden) 00066 { 00067 //if posGefunden is set to true, the right position (--vhIter) is found. but at the end of the while-run 00068 //vhIter will be incremented one time. so that has to be set back through --vhIter. 00069 --vhIter; 00070 hNavi.insert(vhIter, clist.begin()); 00071 //stores the iterator of the element in hNavi, which points on the new inserted cluster 00072 --vhIter; 00073 clist.begin()->setHPointer(vhIter); 00074 } 00075 00076 //in case that the end of the list is reached, the new element will be inserted at the end of hNavi 00077 else if((posGefunden == false) && (vhIter == hNavi.end())) 00078 { 00079 hNavi.push_back(clist.begin()); 00080 //stores the iterator of the element in hNavi, which points on the new inserted cluster 00081 //hNavi.end() returns the iterator to after last element (null), so last element can be reached through --vhIter 00082 --vhIter; 00083 clist.begin()->setHPointer(vhIter); 00084 } 00085 00086 }//end of if(v) 00087 00088 00089 00090 else //the same process as above for horizontal scan-lines 00091 { 00092 /* update navigation-information vNavi and hNavi. 00093 * the position of the new element in hNavi is given: i 00094 * the position of the new element in vNavi has to be calculated 00095 */ 00096 00097 //inserting in hNavi 00098 hNavi.insert(i,clist.begin()); 00099 //stores the iterator of the element in hNavi, which points on the new inserted cluster 00100 --i; 00101 clist.begin()->setHPointer(i); 00102 00103 00104 //calculating the position in vNavi 00105 vhIter = vNavi.begin(); 00106 posGefunden = false; 00107 while((posGefunden == false) && (vhIter != vNavi.end())) 00108 { 00109 cIter = *vhIter; 00110 if(clist.begin()->getXMin() <= cIter->getXMin()) 00111 { 00112 posGefunden = true; 00113 } 00114 ++vhIter; 00115 } 00116 00117 00118 00119 //in case that vhIter doesn´t point to after last element (null) 00120 if(posGefunden) 00121 { 00122 //if posGefunden is set to true, the right position (--vhIter) is found. but at the end of the while-run 00123 //vhIter will be incremented one time. so that has to be set back through --vhIter. 00124 --vhIter; 00125 vNavi.insert(vhIter, clist.begin()); 00126 --vhIter; 00127 clist.begin()->setVPointer(vhIter); 00128 } 00129 //in case that the end of the list is reached, the new element will be inserted at the end of vNavi 00130 else if((posGefunden == false) && (vhIter == vNavi.end())) 00131 { 00132 vNavi.push_back(clist.begin()); 00133 --vhIter; 00134 clist.begin()->setVPointer(vhIter); 00135 } 00136 00137 00138 }//end of else() of if(v) 00139 00140 00141 }//end else() of if(clist.empty()) 00142 00143 }//end of addCluster 00144 00145 00146 00147 //a method that delete all clusters and navigation information 00148 void GT2005Clusterliste::deleteAll() 00149 { 00150 clist.clear(); 00151 vNavi.clear(); 00152 hNavi.clear(); 00153 midlist.clear(); 00154 } 00155 00156 00157 00158 //this method is used in clustering. rc is a iterator that points on the element of clist that contains the cluster 00159 //which should be removed 00160 void GT2005Clusterliste::removeCluster(list<GT2005Cluster>::iterator rc) 00161 { 00162 //navigation-information of this cluster (elements in vNavi and hNavi)will be removed first 00163 00164 //vNavi 00165 vhIter = rc->getVPointer(); 00166 vNavi.erase(vhIter); 00167 00168 //hNavi 00169 vhIter = rc->getHPointer(); 00170 hNavi.erase(vhIter); 00171 00172 //clist 00173 cIter = clist.erase(rc); 00174 00175 } 00176 00177 00178 //return of a list,which stores the midpoints of the cluster 00179 list<Vector2<double> > GT2005Clusterliste::getMidpoints() 00180 { 00181 midlist.clear(); 00182 for(cIter = clist.begin(); cIter != clist.end(); ++cIter ) 00183 { 00184 midlist.push_back(cIter->getMidpoint()); 00185 } 00186 return(midlist); 00187 } 00188 00189 00190 list<GT2005Cluster>::iterator GT2005Clusterliste::getCListBegin() 00191 { 00192 return(clist.begin()); 00193 } 00194 00195 00196 list<GT2005Cluster>::iterator GT2005Clusterliste::getCListEnd() 00197 { 00198 return(clist.end()); 00199 } 00200 00201 00202 00203 list<list<GT2005Cluster>::iterator>::iterator GT2005Clusterliste::getVNaviBegin() 00204 { 00205 return(vNavi.begin()); 00206 } 00207 00208 list<list<GT2005Cluster>::iterator>::iterator GT2005Clusterliste::getVNaviEnd() 00209 { 00210 return(vNavi.end()); 00211 } 00212 00213 00214 list<list<GT2005Cluster>::iterator>::iterator GT2005Clusterliste::getHNaviBegin() 00215 { 00216 return(hNavi.begin()); 00217 } 00218 00219 00220 00221 list<list<GT2005Cluster>::iterator>::iterator GT2005Clusterliste::getHNaviEnd() 00222 { 00223 return(hNavi.end()); 00224 } 00225 00226 00227 bool GT2005Clusterliste::getEmpty() 00228 { 00229 return(clist.empty()); 00230 } 00231 00232 00233 00234
1.3.6