25 #include "geometry.hh"
31 #ifndef MODULE_EXTRACTION_IMAGE_WITHOUT_MAGICK
34 CDart* CExtractionImage::createBorder2d(
unsigned int columns)
38 CDartVertex* first = (CDartVertex *) FMap->addMapDart();
39 FMap->linkAlpha0(first, FMap->addMapDart());
41 FMap->addAttribute(first, ORBIT_VERTEX,
new CAttributeVertex(0,
STEP2D_Y,0));
45 for (
unsigned int i=0;i<columns;++i)
47 actu = (CDartVertex *) FMap->addMapDart();
48 FMap->linkAlpha0(actu, FMap->addMapDart());
49 FMap->linkAlpha1(actu, FMap->alpha0(prev));
51 FMap->addAttribute(actu, ORBIT_VERTEX,
new CAttributeVertex(i*
STEP2D_X,0,0));
56 actu = (CDartVertex *) FMap->addMapDart();
57 FMap->linkAlpha0(actu, FMap->addMapDart());
58 FMap->addAttribute(actu, ORBIT_VERTEX,
new CAttributeVertex(columns*
STEP2D_X,0,0));
60 FMap->linkAlpha1(actu, FMap->alpha0(prev));
61 FMap->linkAlpha1(FMap->alpha0(actu), first);
67 CDart* CExtractionImage::computeUpFromLast2d(CDart* ADart)
69 CDart* res = FMap->alpha01(ADart);
71 while(!FMap->isFree2(res))
72 res = FMap->alpha21(res);
78 CDartVertex* CExtractionImage::createFaceForExtract2d(
unsigned int x,
unsigned int y)
80 CDartVertex* first = (CDartVertex *) FMap->createTopoPolygon(4);
82 FMap->addAttribute(first, ORBIT_VERTEX,
83 new CAttributeVertex(x*STEP2D_X,y*
STEP2D_Y,0));
90 bool CExtractionImage::samePixelActuLeft2d(Magick::Image & image,
91 unsigned int x,
unsigned int y)
93 if (y==image.rows())
return true;
94 if (x==0 || x==image.columns())
return false;
96 return image.pixelColor(x,y)==image.pixelColor(x-1,y);
100 bool CExtractionImage::samePixelActuUp2d(Magick::Image &image,
101 unsigned int x,
unsigned int y)
103 if (x==image.columns())
return true;
104 if (y==0 || y==image.rows())
return false;
106 return image.pixelColor(x,y)==image.pixelColor(x,y-1);
110 void CExtractionImage::mergeImage2dFaces(CDart* ADart)
114 if (FMap->alpha2(ADart)!=FMap->alpha1(ADart))
116 tmp=FMap->alpha1(ADart); tmp2=FMap->alpha21(ADart);
118 FMap->unsew1(ADart); FMap->unsew1(FMap->alpha2(ADart));
120 FMap->sew1(tmp,tmp2);
123 if (FMap->alpha02(ADart)!=FMap->alpha01(ADart))
125 tmp=FMap->alpha01(ADart); tmp2=FMap->alpha021(ADart);
127 FMap->unsew1(FMap->alpha0(ADart)); FMap->unsew1(FMap->alpha02(ADart));
129 FMap->sew1(tmp,tmp2);
132 FMap->delMapDart(FMap->alpha02(ADart));
133 FMap->delMapDart(FMap->alpha2(ADart));
134 FMap->delMapDart(FMap->alpha0(ADart));
135 FMap->delMapDart(ADart);
139 void CExtractionImage::mergeImage2dEdges(CDart* ADart)
144 tmp = FMap->alpha0(ADart);
145 tmp2 = FMap->alpha10(ADart);
147 FMap->unlinkAlpha0(FMap->alpha12(ADart)); FMap->unlinkAlpha0(FMap->alpha1(ADart));
148 FMap->unlinkAlpha0(FMap->alpha2(ADart)); FMap->unlinkAlpha0(ADart);
150 FMap->linkAlpha0(FMap->alpha2(tmp),FMap->alpha2(tmp2));
151 FMap->linkAlpha0(tmp,tmp2);
153 FMap->delMapDart(FMap->alpha12(ADart));
154 FMap->delMapDart(FMap->alpha2(ADart));
155 FMap->delMapDart(FMap->alpha1(ADart));
156 FMap->delMapDart(ADart);
160 bool CExtractionImage::isDegre2Vertex2d(CDart* ADart)
162 if (FMap->alpha2(ADart)==FMap->alpha1(ADart))
return false;
164 return (FMap->alpha12(ADart)==FMap->alpha21(ADart));
167 #endif // MODULE_EXTRACTION_IMAGE_WITHOUT_MAGICK
170 bool CExtractionImage::areEdgesAlign(CDart* ADart, CDart* ADart2)
172 CAttributeVertex C = *FMap->findVertex(ADart);
174 return CGeometry::areColinear(*FMap->findVertex(FMap->alpha0(ADart)) - *FMap->findVertex(ADart),
175 *FMap->findVertex(FMap->alpha0(ADart2)) - *FMap->findVertex(ADart2));
179 bool CExtractionImage::extract2dImage(
const std::string & AFilename)
181 #ifdef MODULE_EXTRACTION_IMAGE_WITHOUT_MAGICK
185 Magick::Image image(AFilename);
187 std::cout<<
"Apres lecture dans CExtractionImage::extract2dImage"<<std::endl;
188 std::cout<<
" columns="<<image.columns()<<std::endl
189 <<
" rows="<<image.rows()<<std::endl;
192 CDart* last = createBorder2d(image.columns());
198 for(j=0;j<=image.rows();++j)
199 for(i=0;i<=image.columns();++i)
201 tmp = createFaceForExtract2d((i+1)%(image.columns()+1),
202 j+1+((i+1)/(image.columns()+1)));
203 FMap->topoSew2(last,FMap->alpha101(tmp));
204 FMap->topoSew2(computeUpFromLast2d(last),FMap->alpha010(tmp));
210 if (samePixelActuLeft2d(image,i,j))
212 mergeImage2dFaces(FMap->alpha101(last));
213 tmp = FMap->alpha010(last);
216 if (samePixelActuUp2d(image,i,j))
218 mergeImage2dFaces(FMap->alpha01(last));
220 if (tmp==NULL) tmp = FMap->alpha1010(last);
226 isDegre2Vertex2d(tmp) &&
227 areEdgesAlign(tmp,FMap->alpha1(tmp)) )
228 mergeImage2dEdges(tmp);
231 CStaticCoverage01 it(FMap,last);
233 FMap->delMapDart(it++);
236 catch( Magick::Exception &error_ )
238 std::cerr <<
"Exception dans CExtractionImage::extract2dImage: "
239 << error_.what() << std::endl;
244 #endif // MODULE_EXTRACTION_IMAGE_WITHOUT_MAGICK