Moka libraries
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
extraction-images.hh
Go to the documentation of this file.
1 /*
2  * lib-extraction-images : Extraction de cartes à partir d'images 2D et 3D.
3  * Copyright (C) 2004, Moka Team, Université de Poitiers, Laboratoire SIC
4  * http://www.sic.sp2mi.univ-poitiers.fr/
5  * Copyright (C) 2009, Guillaume Damiand, CNRS, LIRIS,
6  * guillaume.damiand@liris.cnrs.fr, http://liris.cnrs.fr/
7  *
8  * This file is part of lib-extraction-images
9  *
10  * This program is free software: you can redistribute it and/or modify
11  * it under the terms of the GNU Lesser General Public License as published by
12  * the Free Software Foundation, either version 3 of the License, or
13  * (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  * GNU Lesser General Public License for more details.
19  *
20  * You should have received a copy of the GNU Lesser General Public License
21  * along with this program. If not, see <http://www.gnu.org/licenses/>.
22  */
23 
24 //******************************************************************************
25 #ifdef MODULE_EXTRACTION_IMAGE
26 //******************************************************************************
27 #ifndef EXTRACTION_IMAGES_HH
28 #define EXTRACTION_IMAGES_HH
29 //******************************************************************************
30 #include "inline-macro.hh"
31 #include <string>
32 
33 class CVertex;
34 
35 #ifndef MODULE_EXTRACTION_IMAGE_WITHOUT_MAGICK
36 #include <Magick++.h>
37 #endif
38 
39 namespace GMap3d
40 {
41  class CDart;
42  class CDartVertex;
43  class CGMapVertex;
44  class CImage3d;
45 
52  class CExtractionImage
53  {
54  public:
56 
57  CExtractionImage(CGMapVertex * AMap);
58 
59  ~CExtractionImage();
60 
62 
64 
71  bool extract2dImage(const std::string & AFilename);
72 
91  bool extract3dImage(const std::string & AFilename, int FirstPlane,
92  int NbPlaneToRead, int Level, int Lg,
93  bool DestroyBorder,
94  bool KeepFictiveEdges, bool ShiftFictiveEdges);
95 
113  bool extract3dImageCEA(const std::string & AFilename, int FirstPlane,
114  int NbPlaneToRead, int Level,
115  bool DestroyBorder, bool KeepFictiveEdges,
116  bool ShiftFictiveEdges );
117 
126  bool extract3dImageWithPrecodes(const std::string & AFilename,
127  int FirstPlane,
128  int NbPlaneToRead, int Level, int Lg,
129  bool DestroyBorder,
130  bool KeepFictiveEdges,
131  bool ShiftFictiveEdges );
132 
141  bool extract3dImageCEAWithPrecodes(const std::string & AFilename,
142  int FirstPlane,
143  int NbPlaneToRead, int Level,
144  bool DestroyBorder,
145  bool KeepFictiveEdges,
146  bool ShiftFictiveEdges );
147 
166  bool extractOneRegionVoxels(const std::string & AFilename,
167  int FirstPlane,
168  int NbPlaneToRead,
169  int Lg,
170  int ARed, int AGreen, int ABlue, int AAlpha );
171 
173 
174  private:
176 #ifndef MODULE_EXTRACTION_IMAGE_WITHOUT_MAGICK
177 
178  CDart* computeUpFromLast2d(CDart* ADart);
179 
180  CDart* createBorder2d(unsigned int rows);
181  CDartVertex* createFaceForExtract2d(unsigned int x, unsigned int y);
182 
183  bool samePixelActuLeft2d(Magick::Image & image,
184  unsigned int x, unsigned int y);
185  bool samePixelActuUp2d (Magick::Image & image,
186  unsigned int x, unsigned int y);
187 
188  void mergeImage2dFaces(CDart* ADart);
189  void mergeImage2dEdges(CDart* ADart);
190 
191  bool isDegre2Vertex2d(CDart* ADart);
192 
193 #endif // MODULE_EXTRACTION_IMAGE_WITHOUT_MAGICK
194 
195  bool areEdgesAlign(CDart* ADart, CDart* ADart2);
196 
209  bool extract3dImage(CImage3d * AImage, int ALevel = 3,
210  bool ADestroyBorder = true,
211  bool AKeepFictiveEdges = true,
212  bool AShiftFictiveEdges = true);
213 
226  bool extractOneRegionVoxels(CImage3d * AImage,
227  int ARed, int AGreen, int ABlue, int AAlpha );
228 
229  CDart* computeUpFromLast3d (CDart* ADart);
230  CDart* computeBehindFromLast3d(CDart* ADart);
231 
232  CDart* createBorder3d(unsigned int columns, unsigned int rows);
233  CDartVertex* createFaceForExtract3d();
234  CDartVertex* createFaceForExtract3d( const CVertex & AVertex );
235  CDartVertex* createCubeForExtract3d( const CVertex & AVertex );
236  void sew3Cube(CDart* ADart, CDart* TheLastDart);
237 
238  void mergeImage3dVolumes(CDart* ADart);
239  void mergeImage3dFaces (CDart* ADart);
240  void mergeImage3dEdges (CDart* ADart);
241 
242  bool isDegre2Edge3d (CDart* ADart);
243  bool isDegre2Vertex3d (CDart* ADart);
244  CDart* isRealDegre2Vertex3d (CDart* ADart, int AMark);
245  bool areFacesColinear (CDart* ADart);
246  bool faceMergingWillDisconnect(CDart* ADart);
247 
248  bool extract3dImageWithPrecodes(CImage3d * AImage, int ALevel = 3,
249  bool ADestroyBorder = true,
250  bool AKeepFictiveEdges = true,
251  bool AShiftFictiveEdges = true);
252 
253  CDart* newEdge();
254  void closeFace( CDart* d1, CDart* d2,CDart* d3 );
255  void closeFace( CDart* d1, CDart* d2 );
256  void closeFace( CDart* d );
257 
258  void shiftFictiveEdgesForFacesXy( CDart* last, CDart* up, CDart* behind,
259  int FictiveMark );
260  void shiftFictiveEdgesForFacesXz( CDart* last, CDart* up, CDart* behind,
261  int FictiveMark );
262  void shiftFictiveEdgesForFacesYz( CDart* last, CDart* up, CDart* behind,
263  int FictiveMark );
264 
265  // Pour extraire la carte de niveau 1
266  CDart* oneSameNeighboorV( CDart* d1, CDart* fo1, CDart* fo2,
267  const CVertex & AVertex );
268  CDart* twoSameNeighboorV( CDart* d1, CDart* d5 , CDart* fo ,
269  const CVertex & AVertex );
270 
271  void precodeL1( CDart* &last, CDart* up, CDart* behind,
272  const CVertex & AVertex );
273  void precodeL2( CDart* &last, CDart* up, CDart* behind,
274  const CVertex & AVertex );
275  void precodeL3( CDart* &last, CDart* up, CDart* behind,
276  const CVertex & AVertex );
277  void precodeL4( CDart* &last, CDart* up, CDart* behind,
278  const CVertex & AVertex );
279  void precodeL5( CDart* &last, CDart* up, CDart* behind,
280  const CVertex & AVertex );
281  void precodeL6( CDart* &last, CDart* up, CDart* behind,
282  const CVertex & AVertex );
283  void precodeL7( CDart* &last, CDart* up, CDart* behind,
284  const CVertex & AVertex );
285  void precodeL8( CDart* &last, CDart* up, CDart* behind,
286  const CVertex & AVertex );
287 
288  void subcasePrecodeL1( CImage3d & image,
289  unsigned int x, unsigned int y,
290  CDart* &last, CDart* up, CDart* behind,
291  int level, const CVertex & AVertex, int FictiveMark,
292  bool keepFictiveEdges, bool shiftFictiveEdges );
293  void subcasePrecodeL2( CImage3d & image,
294  unsigned int x, unsigned int y,
295  CDart* &last, CDart* up, CDart* behind,
296  int level, const CVertex & AVertex, int FictiveMark,
297  bool keepFictiveEdges, bool shiftFictiveEdges );
298  void subcasePrecodeL3( CImage3d & image,
299  unsigned int x, unsigned int y,
300  CDart* &last, CDart* up, CDart* behind,
301  int level, const CVertex & AVertex, int FictiveMark,
302  bool keepFictiveEdges, bool shiftFictiveEdges );
303  void subcasePrecodeL4( CImage3d & image,
304  unsigned int x, unsigned int y,
305  CDart* &last, CDart* up, CDart* behind,
306  int level, const CVertex & AVertex, int FictiveMark,
307  bool keepFictiveEdges, bool shiftFictiveEdges );
308  void subcasePrecodeL5( CImage3d & image,
309  unsigned int x, unsigned int y,
310  CDart* &last, CDart* up, CDart* behind,
311  int level, const CVertex & AVertex, int FictiveMark,
312  bool keepFictiveEdges, bool shiftFictiveEdges );
313  void subcasePrecodeL6( CImage3d & image,
314  unsigned int x, unsigned int y,
315  CDart* &last, CDart* up, CDart* behind,
316  int level, const CVertex & AVertex, int FictiveMark,
317  bool keepFictiveEdges, bool shiftFictiveEdges );
318  void subcasePrecodeL7( CImage3d & image,
319  unsigned int x, unsigned int y,
320  CDart* &last, CDart* up, CDart* behind,
321  int level, const CVertex & AVertex, int FictiveMark,
322  bool keepFictiveEdges, bool shiftFictiveEdges );
323  void subcasePrecodeL8( CImage3d & image,
324  unsigned int x, unsigned int y,
325  CDart* &last, CDart* up, CDart* behind,
326  int level, const CVertex & AVertex, int FictiveMark,
327  bool keepFictiveEdges, bool shiftFictiveEdges );
328 
329  // Pour extraire la carte de niveau 2
330  CDart* oneSameNeighboorFc ( const CVertex & AVertex,
331  CDart* d1, CDart* fo1, CDart* fo2,
332  int fusionCase );
333  CDart* twoSameNeighboorFc1( const CVertex & AVertex,
334  CDart* d1, CDart* d5, CDart* fo );
335  CDart* twoSameNeighboorFc2( const CVertex & AVertex,
336  CDart* d1, CDart* d5, CDart* fo );
337  CDart* twoSameNeighboorFc3( const CVertex & AVertex,
338  CDart* d1, CDart* d5, CDart* fo );
339 
340  void precodeFc1 ( CDart* &last, CDart* up, CDart* behind,
341  const CVertex & AVertex );
342  void precodeFc2 ( CDart* &last, CDart* up, CDart* behind,
343  const CVertex & AVertex );
344  void precodeFc3 ( CDart* &last, CDart* up, CDart* behind,
345  const CVertex & AVertex );
346  void precodeFc4 ( CDart* &last, CDart* up, CDart* behind,
347  const CVertex & AVertex );
348  void precodeFc5 ( CDart* &last, CDart* up, CDart* behind,
349  const CVertex & AVertex );
350  void precodeFc6 ( CDart* &last, CDart* up, CDart* behind,
351  const CVertex & AVertex );
352  void precodeFc7 ( CDart* &last, CDart* up, CDart* behind,
353  const CVertex & AVertex );
354  void precodeFc8 ( CDart* &last, CDart* up, CDart* behind,
355  const CVertex & AVertex );
356  void precodeFc9 ( CDart* &last, CDart* up, CDart* behind,
357  const CVertex & AVertex );
358  void precodeFc10( CDart* &last, CDart* up, CDart* behind,
359  const CVertex & AVertex );
360  void precodeFc11( CDart* &last, CDart* up, CDart* behind,
361  const CVertex & AVertex );
362  void precodeFc12( CDart* &last, CDart* up, CDart* behind,
363  const CVertex & AVertex );
364  void precodeFc13( CDart* &last, CDart* up, CDart* behind,
365  const CVertex & AVertex );
366  void precodeFc14( CDart* &last, CDart* up, CDart* behind,
367  const CVertex & AVertex );
368  void precodeFc15( CDart* &last, CDart* up, CDart* behind,
369  const CVertex & AVertex );
370  void precodeFc16( CDart* &last, CDart* up, CDart* behind,
371  const CVertex & AVertex );
372  void precodeFc17( CDart* &last, CDart* up, CDart* behind,
373  const CVertex & AVertex );
374  void precodeFc18( CDart* &last, CDart* up, CDart* behind,
375  const CVertex & AVertex );
376 
377  void subcasePrecodeFc1 ( CImage3d & image,
378  unsigned int x, unsigned int y,
379  CDart* &last, CDart* up, CDart* behind,
380  int level, const CVertex & AVertex,
381  int FictiveMark,
382  bool keepFictiveEdges, bool shiftFictiveEdges );
383  void subcasePrecodeFc2 ( CImage3d & image,
384  unsigned int x, unsigned int y,
385  CDart* &last, CDart* up, CDart* behind,
386  int level, const CVertex & AVertex,
387  int FictiveMark,
388  bool keepFictiveEdges, bool shiftFictiveEdges );
389  void subcasePrecodeFc3 ( CImage3d & image,
390  unsigned int x, unsigned int y,
391  CDart* &last, CDart* up, CDart* behind,
392  int level, const CVertex & AVertex,
393  int FictiveMark,
394  bool keepFictiveEdges, bool shiftFictiveEdges );
395  void subcasePrecodeFc4 ( CImage3d & image,
396  unsigned int x, unsigned int y,
397  CDart* &last, CDart* up, CDart* behind,
398  int level, const CVertex & AVertex,
399  int FictiveMark,
400  bool keepFictiveEdges, bool shiftFictiveEdges );
401  void subcasePrecodeFc5 ( CImage3d & image,
402  unsigned int x, unsigned int y,
403  CDart* &last, CDart* up, CDart* behind,
404  int level, const CVertex & AVertex,
405  int FictiveMark,
406  bool keepFictiveEdges, bool shiftFictiveEdges );
407  void subcasePrecodeFc6 ( CImage3d & image,
408  unsigned int x, unsigned int y,
409  CDart* &last, CDart* up, CDart* behind,
410  int level, const CVertex & AVertex,
411  int FictiveMark,
412  bool keepFictiveEdges, bool shiftFictiveEdges );
413  void subcasePrecodeFc7 ( CImage3d & image,
414  unsigned int x, unsigned int y,
415  CDart* &last, CDart* up, CDart* behind,
416  int level, const CVertex & AVertex,
417  int FictiveMark,
418  bool keepFictiveEdges, bool shiftFictiveEdges );
419  void subcasePrecodeFc8 ( CImage3d & image,
420  unsigned int x, unsigned int y,
421  CDart* &last, CDart* up, CDart* behind,
422  int level, const CVertex & AVertex,
423  int FictiveMark,
424  bool keepFictiveEdges, bool shiftFictiveEdges );
425  void subcasePrecodeFc9 ( CImage3d & image,
426  unsigned int x, unsigned int y,
427  CDart* &last, CDart* up, CDart* behind,
428  int level, const CVertex & AVertex,
429  int FictiveMark,
430  bool keepFictiveEdges, bool shiftFictiveEdges );
431  void subcasePrecodeFc10( CImage3d & image,
432  unsigned int x, unsigned int y,
433  CDart* &last, CDart* up, CDart* behind,
434  int level, const CVertex & AVertex,
435  int FictiveMark,
436  bool keepFictiveEdges, bool shiftFictiveEdges );
437  void subcasePrecodeFc11( CImage3d & image,
438  unsigned int x, unsigned int y,
439  CDart* &last, CDart* up, CDart* behind,
440  int level, const CVertex & AVertex,
441  int FictiveMark,
442  bool keepFictiveEdges, bool shiftFictiveEdges );
443  void subcasePrecodeFc12( CImage3d & image,
444  unsigned int x, unsigned int y,
445  CDart* &last, CDart* up, CDart* behind,
446  int level, const CVertex & AVertex,
447  int FictiveMark,
448  bool keepFictiveEdges, bool shiftFictiveEdges );
449  void subcasePrecodeFc13( CImage3d & image,
450  unsigned int x, unsigned int y,
451  CDart* &last, CDart* up, CDart* behind,
452  int level, const CVertex & AVertex,
453  int FictiveMark,
454  bool keepFictiveEdges, bool shiftFictiveEdges );
455  void subcasePrecodeFc14( CImage3d & image,
456  unsigned int x, unsigned int y,
457  CDart* &last, CDart* up, CDart* behind,
458  int level, const CVertex & AVertex,
459  int FictiveMark,
460  bool keepFictiveEdges, bool shiftFictiveEdges );
461  void subcasePrecodeFc15( CImage3d & image,
462  unsigned int x, unsigned int y,
463  CDart* &last, CDart* up, CDart* behind,
464  int level, const CVertex & AVertex,
465  int FictiveMark,
466  bool keepFictiveEdges, bool shiftFictiveEdges );
467  void subcasePrecodeFc16( CImage3d & image,
468  unsigned int x, unsigned int y,
469  CDart* &last, CDart* up, CDart* behind,
470  int level, const CVertex & AVertex,
471  int FictiveMark,
472  bool keepFictiveEdges, bool shiftFictiveEdges );
473  void subcasePrecodeFc17( CImage3d & image,
474  unsigned int x, unsigned int y,
475  CDart* &last, CDart* up, CDart* behind,
476  int level, const CVertex & AVertex,
477  int FictiveMark,
478  bool keepFictiveEdges, bool shiftFictiveEdges );
479  void subcasePrecodeFc18( CImage3d & image,
480  unsigned int x, unsigned int y,
481  CDart* &last, CDart* up, CDart* behind,
482  int level, const CVertex & AVertex,
483  int FictiveMark,
484  bool keepFictiveEdges, bool shiftFictiveEdges );
485 
486  // Pour extraire la carte de niveau 3
487  CDart* oneSameNeighboorF (CDart* d1, CDart* fo1, CDart* fo2,
488  const CVertex & AVertex );
489  CDart* twoSameNeighboorF1 (CDart* d1, CDart* d5, CDart* fo,
490  const CVertex & AVertex );
491  CDart* twoSameNeighboorF2 (CDart* d1, CDart* d5, CDart* fo,
492  const CVertex & AVertex );
493  CDart* threeSameNeighboorF(CDart* d1, CDart* d5, CDart* fo,
494  const CVertex & AVertex );
495 
496  void precodesF1F4F7F10( CDart* &last, CDart* up, CDart* behind,
497  const CVertex & AVertex );
498  void precodesF2F5F8F11( CDart* &last, CDart* up, CDart* behind,
499  const CVertex & AVertex );
500  void precodesF3F6F9F12( CDart* &last, CDart* up, CDart* behind,
501  const CVertex & AVertex );
502  void precodesF13F19 ( CDart* &last, CDart* up, CDart* behind,
503  const CVertex & AVertex );
504  void precodesF14F20 ( CDart* &last, CDart* up, CDart* behind,
505  const CVertex & AVertex );
506  void precodesF15F21 ( CDart* &last, CDart* up, CDart* behind,
507  const CVertex & AVertex );
508  void precodesF16F22 ( CDart* &last, CDart* up, CDart* behind,
509  const CVertex & AVertex );
510  void precodesF17F23 ( CDart* &last, CDart* up, CDart* behind,
511  const CVertex & AVertex );
512  void precodesF18F24 ( CDart* &last, CDart* up, CDart* behind,
513  const CVertex & AVertex );
514  void precodeF25 ( CDart* &last, CDart* up, CDart* behind,
515  const CVertex & AVertex );
516  void precodeF26 ( CDart* &last, CDart* up, CDart* behind,
517  const CVertex & AVertex );
518  void precodeF27 ( CDart* &last, CDart* up, CDart* behind,
519  const CVertex & AVertex );
520 
521 
522  void subcasePrecodesF1F4F7F10( CImage3d & image,
523  unsigned int x, unsigned int y,
524  CDart* &last, CDart* up, CDart* behind,
525  int level, const CVertex & AVertex,
526  int FictiveMark,
527  bool keepFictiveEdges,
528  bool shiftFictiveEdges );
529  void subcasePrecodesF2F5F8F11( CImage3d & image,
530  unsigned int x, unsigned int y,
531  CDart* &last, CDart* up, CDart* behind,
532  int level, const CVertex & AVertex,
533  int FictiveMark,
534  bool keepFictiveEdges,
535  bool shiftFictiveEdges );
536  void subcasePrecodesF3F6F9F12( CImage3d & image,
537  unsigned int x, unsigned int y,
538  CDart* &last, CDart* up, CDart* behind,
539  int level, const CVertex & AVertex,
540  int FictiveMark,
541  bool keepFictiveEdges,
542  bool shiftFictiveEdges );
543  void subcasePrecodesF13F19( CImage3d & image,
544  unsigned int x, unsigned int y,
545  CDart* &last, CDart* up, CDart* behind,
546  int level, const CVertex & AVertex,
547  int FictiveMark,
548  bool keepFictiveEdges,
549  bool shiftFictiveEdges );
550  void subcasePrecodesF14F20( CImage3d & image,
551  unsigned int x, unsigned int y,
552  CDart* &last, CDart* up, CDart* behind,
553  int level, const CVertex & AVertex,
554  int FictiveMark,
555  bool keepFictiveEdges, bool shiftFictiveEdges );
556  void subcasePrecodesF15F21( CImage3d & image,
557  unsigned int x, unsigned int y,
558  CDart* &last, CDart* up, CDart* behind,
559  int level, const CVertex & AVertex,
560  int FictiveMark,
561  bool keepFictiveEdges, bool shiftFictiveEdges );
562  void subcasePrecodesF16F22( CImage3d & image,
563  unsigned int x, unsigned int y,
564  CDart* &last, CDart* up, CDart* behind,
565  int level, const CVertex & AVertex,
566  int FictiveMark,
567  bool keepFictiveEdges, bool shiftFictiveEdges );
568  void subcasePrecodesF17F23( CImage3d & image,
569  unsigned int x, unsigned int y,
570  CDart* &last, CDart* up, CDart* behind,
571  int level, const CVertex & AVertex,
572  int FictiveMark,
573  bool keepFictiveEdges, bool shiftFictiveEdges );
574  void subcasePrecodesF18F24( CImage3d & image,
575  unsigned int x, unsigned int y,
576  CDart* &last, CDart* up, CDart* behind,
577  int level, const CVertex & AVertex,
578  int FictiveMark,
579  bool keepFictiveEdges, bool shiftFictiveEdges );
580  void subcasePrecodeF25( CImage3d & image,
581  unsigned int x, unsigned int y,
582  CDart* &last, CDart* up, CDart* behind,
583  int level, const CVertex & AVertex, int FictiveMark,
584  bool keepFictiveEdges, bool shiftFictiveEdges );
585  void subcasePrecodeF26( CImage3d & image,
586  unsigned int x, unsigned int y,
587  CDart* &last, CDart* up, CDart* behind,
588  int level, const CVertex & AVertex, int FictiveMark,
589  bool keepFictiveEdges, bool shiftFictiveEdges );
590  void subcasePrecodeF27( CImage3d & image,
591  unsigned int x, unsigned int y,
592  CDart* &last, CDart* up, CDart* behind,
593  int level, const CVertex & AVertex, int FictiveMark,
594  bool keepFictiveEdges, bool shiftFictiveEdges );
595 
596  CGMapVertex * FMap;
597  bool FKeepFictiveEdges;
598  bool FShiftFictiveEdges;
600  };
601 
602 } // namespace GMap3d
603 //******************************************************************************
604 #include INCLUDE_INLINE("extraction-images.icc")
605 //******************************************************************************
606 #endif // EXTRACTION_IMAGES_HH
607 //******************************************************************************
608 #endif // MODULE_EXTRACTION_IMAGE
609 //******************************************************************************