Moka libraries
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
image-3d-extraction-with-precodes.icc
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 #include "image-3d.hh"
26 #include "geometry.hh"
27 #include "pixel-step.hh"
28 
29 namespace GMap3d
30 {
31 //******************************************************************************
32 INLINE
33 bool CExtractionImage::extract3dImageWithPrecodes(CImage3d * AImage, int ALevel,
34  bool ADestroyBorder,
35  bool AKeepFictiveEdges,
36  bool AShiftFictiveEdges)
37 {
38  assert(AImage != NULL);
39  if (!AImage->isOk()) return false;
40 
41  // Marque pour les arêtes fictives
42  int fictiveMark = FMap->getNewMark();
43 
44  CDart *last, *up, *behind; // les 3 brins utile pour le parcours
45 
46  // Les coordonnées du pointel courant
47  // (multipliés ensuite par STEP3D_X, STEP3D_Y et STEP3D_Z)
48  CVertex CurrentPointel(1,1,1);
49 
50  // Les coordonnées du voxel courant sont i,j,k. C'est presque pareil que
51  // celles du pointel sauf pour les bords ou on replie l'espace sur un tore :)
52  unsigned int k=0;
53 
54 #ifdef DEBUG_EXTRACT_IMAGE
55  cout<<"Avant de créer le bord supérieur : "<<endl;
56 #endif
57 
58  last = createBorder3d(AImage->getWidth(),AImage->getHeight());
59 
60 #ifdef DEBUG_EXTRACT_IMAGE
61  cout<<"Ok on FMap->alpha créé le bord supérieur."<<endl;
62 #endif
63 
64  do // On boucle tant qu'on peut lire un prochain plan
65  {
66  for (unsigned int j=0; j<=AImage->getHeight(); ++j)
67  {
68  for (unsigned int i=0; i<=AImage->getWidth(); ++i)
69  {
70 #ifdef DEBUG_EXTRACT_IMAGE
71  cout<<"On traite le voxel ("<<i<<", "<<j<<", "<<k<<")"<<endl;
72 #endif
73 
74  if (ALevel==0)
75  {
76  CDart* tmp = createCubeForExtract3d(CurrentPointel);
77  sew3Cube(tmp,last);
78  last = FMap->alpha101(tmp);
79  }
80  else if (ALevel > 0)
81  {
82  up = computeUpFromLast3d(last);
83  behind = computeBehindFromLast3d(last);
84 
85  if ( AImage->sameVoxelActuLeft(i,j) )
86  { // same region actu and left
87  if ( AImage->sameVoxelActuBehind(i,j) )
88  { // sameRegionActuBehind
89  if ( AImage->sameVoxelActuUp(i,j) )
90  subcasePrecodeL8(*AImage,i,j,last,up,behind,
91  ALevel,CurrentPointel, fictiveMark,
92  AKeepFictiveEdges,
93  AShiftFictiveEdges);
94  else
95  subcasePrecodeL5(*AImage,i,j,last,up,behind,
96  ALevel,CurrentPointel, fictiveMark,
97  AKeepFictiveEdges,
98  AShiftFictiveEdges);
99  }
100  else // no sameRegionActuBehind
101  {
102  if ( AImage->sameVoxelActuUp(i,j) )
103  subcasePrecodeL6(*AImage,i,j,last,up,behind,
104  ALevel,CurrentPointel, fictiveMark,
105  AKeepFictiveEdges,
106  AShiftFictiveEdges);
107  else
108  subcasePrecodeL2(*AImage,i,j,last,up,behind,
109  ALevel,CurrentPointel, fictiveMark,
110  AKeepFictiveEdges,
111  AShiftFictiveEdges);
112  }
113  }
114  else // no same region actu and left
115  {
116  if ( AImage->sameVoxelActuBehind(i,j) )
117  { // sameRegionActuBehind
118  if ( AImage->sameVoxelActuUp(i,j) )
119  subcasePrecodeL7(*AImage,i,j,last,up,behind,
120  ALevel,CurrentPointel, fictiveMark,
121  AKeepFictiveEdges,
122  AShiftFictiveEdges);
123  else
124  subcasePrecodeL4(*AImage,i,j,last,up,behind,
125  ALevel,CurrentPointel, fictiveMark,
126  AKeepFictiveEdges,
127  AShiftFictiveEdges);
128  }
129  else // no sameRegionActuBehind
130  {
131  if ( AImage->sameVoxelActuUp(i,j) )
132  subcasePrecodeL3(*AImage,i,j,last,up,behind,
133  ALevel,CurrentPointel,fictiveMark,
134  AKeepFictiveEdges,
135  AShiftFictiveEdges);
136  else
137  subcasePrecodeL1(*AImage,i,j,last,up,behind,
138  ALevel,CurrentPointel, fictiveMark,
139  AKeepFictiveEdges,
140  AShiftFictiveEdges);
141  }
142  }
143  }
144 
145  // Calcule la prochaine position du pointel courant
146  // Équivalent à faire :
147  // CurrentPointel.setX((i+1)%(columns+1));
148  // CurrentPointel.setY((j+1+((i+1)/(columns+1)))%(rows+1));
149  // CurrentPointel.setZ(k+1+((j+1+((i+1)/(columns+1)))/(rows+1)));
150  // Mais ici c'est optimisé car moins de formule math :)
151  if ( i == AImage->getWidth()-1 )
152  {
153  CurrentPointel.setX(0);
154 
155  if ( j == AImage->getHeight()-1 )
156  {
157  CurrentPointel.setY(0);
158  CurrentPointel.setZ(CurrentPointel.getZ()+1);
159  }
160  else
161  CurrentPointel.setY(CurrentPointel.getY()+1);
162  }
163  else
164  CurrentPointel.setX(CurrentPointel.getX()+1);
165  }
166  }
167 
168  std::cout << "Ok pour l'extraction de la plaque num "
169  << AImage->getPlaneActu() << std::endl;
170  ++k;
171  }
172  while(AImage->readNextPlane());
173 
174  FMap->unmarkAll(fictiveMark);
175  FMap->freeMark(fictiveMark);
176 
177  if (ADestroyBorder && ALevel > 0)
178  {
179  CStaticCoverage012 it(FMap,last);
180  while(it.cont())
181  FMap->delMapDart(it++);
182  }
183 
184  return true;
185 }
186 //******************************************************************************
187 INLINE
188 bool CExtractionImage::extract3dImageWithPrecodes(const std::string & AFilename,
189  int FirstPlane,
190  int NbPlaneToRead,
191  int Level,
192  int Lg,
193  bool DestroyBorder,
194  bool KeepFictiveEdges,
195  bool ShiftFictiveEdges )
196 {
197 #ifdef MODULE_EXTRACTION_IMAGE_WITHOUT_MAGICK
198  return false;
199 #else
200  CImage3dMagick image(AFilename, FirstPlane, NbPlaneToRead, Lg);
201 
202  return extract3dImageWithPrecodes(& image, Level,
203  DestroyBorder,
204  KeepFictiveEdges,
205  ShiftFictiveEdges);
206 #endif // MODULE_EXTRACTION_IMAGE_WITHOUT_MAGICK
207 }
208 //******************************************************************************
209 INLINE
210 bool CExtractionImage::
211 extract3dImageCEAWithPrecodes(const std::string & AFilename,
212  int FirstPlane,
213  int NbPlaneToRead,
214  int Level,
215  bool DestroyBorder,
216  bool KeepFictiveEdges,
217  bool ShiftFictiveEdges )
218 {
219  CImage3dCEA image(AFilename, FirstPlane, NbPlaneToRead);
220 
221  return extract3dImageWithPrecodes(& image, Level,
222  DestroyBorder,
223  KeepFictiveEdges,
224  ShiftFictiveEdges);
225 }
226 //******************************************************************************
227 } // namespace GMap3d