aimsalgo  5.0.5
Neuroimaging image processing
mesher.h
Go to the documentation of this file.
1 /* This software and supporting documentation are distributed by
2  * Institut Federatif de Recherche 49
3  * CEA/NeuroSpin, Batiment 145,
4  * 91191 Gif-sur-Yvette cedex
5  * France
6  *
7  * This software is governed by the CeCILL-B license under
8  * French law and abiding by the rules of distribution of free software.
9  * You can use, modify and/or redistribute the software under the
10  * terms of the CeCILL-B license as circulated by CEA, CNRS
11  * and INRIA at the following URL "http://www.cecill.info".
12  *
13  * As a counterpart to the access to the source code and rights to copy,
14  * modify and redistribute granted by the license, users are provided only
15  * with a limited warranty and the software's author, the holder of the
16  * economic rights, and the successive licensors have only limited
17  * liability.
18  *
19  * In this respect, the user's attention is drawn to the risks associated
20  * with loading, using, modifying and/or developing or reproducing the
21  * software by the user in light of its specific status of free software,
22  * that may mean that it is complicated to manipulate, and that also
23  * therefore means that it is reserved for developers and experienced
24  * professionals having in-depth computer knowledge. Users are therefore
25  * encouraged to load and test the software's suitability as regards their
26  * requirements in conditions enabling the security of their systems and/or
27  * data to be ensured and, more generally, to use and operate it in the
28  * same conditions as regards security.
29  *
30  * The fact that you are presently reading this means that you have had
31  * knowledge of the CeCILL-B license and that you accept its terms.
32  */
33 
34 
35 #ifndef AIMS_MESH_MESHER_H
36 #define AIMS_MESH_MESHER_H
37 
39 #include <aims/mesh/facet.h>
40 #include <aims/mesh/surface.h>
41 #include <aims/data/data.h>
42 #include <map>
43 #include <list>
44 #include <vector>
45 
46 typedef std::map< uint, Facet*, std::less< int > > MapOfFacet;
47 
48 template <typename T> class TimeTexture;
49 
50 
52 {
53  public:
55  {
60  };
61 
62  Mesher() : _smoothFlag( false ),
63  _smoothIt( 30 ),
64  _smoothRate( 0.4 ),
65  _smoothFeatureAngle( 180. ),
66  _smoothForce( 0.2 ),
67  _smoothType( LOWPASS ),
68  _deciFlag( false ),
69  _splittingFlag( false ),
70  _labelInf( 1 ),
71  _labelSup( 32767 ), // should maybe disapear ?
72  _minSurface( 0.0f ),
73  _triOutputFlag( false ),
74  _minFacetNumber( 50 ),
75  _verbose( true ) { }
76  virtual ~Mesher() { }
77 
78  // GETTING INTERFACE / MESH
79  // =========================
80  void getInterface( std::map<size_t, std::list< MapOfFacet > >& interface,
81  const AimsData<short>& thing );
82  void doit( const AimsData<short>& thing, const std::string& name,
83  const std::string& mode = "binar" );
84  void doit( const AimsData<short>& thing,
85  std::map<size_t, std::list<AimsSurfaceTriangle> >& surface );
86  void getBrain( const AimsData<short>& thing,
87  AimsSurfaceTriangle& surface, bool insideinterface=false );
88  // like getBrain but dedicated to gray/white interface in 6 connectivity,
89  // which solves hole problems. JFM
90  void getWhite( const AimsData<short>& thing,
91  AimsSurfaceTriangle& surface );
92 
93  // create one mesh for all components of each label
94  void getSingleLabel( const AimsData<short>& thing,
95  AimsSurfaceTriangle& surface );
96 
97  // create one smoothed and decimated mesh from a map of facets
98  // (used by getBrain and getSingleLabel)
99  void getMeshFromMapOfFacet(const AimsData<short>& thing,
100  AimsSurfaceTriangle& surface, MapOfFacet &mof);
101 
102  // SMOOTHING
103  // =========
104  // default : smoothType = LOWPASS
105  // smoothIt = 30
106  // smoothRate in [0.0;1.0] (instance : 0.4)
107  // smoothFeatureAngle = 180.0 deg
108  // smoothForce in [0.0;1.0] (instance : 0.2)
109  void setSmoothing( SmoothingType smoothType, int smoothIt, float smoothRate );
110  void setSmoothingLaplacian( float smoothFeatureAngle );
111  void setSmoothingSpring( float smoothForce );
112  void unsetSmoothing();
113  void smooth( AimsSurfaceTriangle& surface );
114 
115  // DECIMATION
116  // ==========
117  // default : deciReductionRate = 100.0 %
118  // deciMaxClearance = 5.0
119  // deciMaxError = 0.003
120  // deciFeatureAngle = 120.0 deg
121  void setDecimation( float deciReductionRate,
122  float deciMaxClearance,
123  float deciMaxError,
124  float deciFeatureAngle );
125  void unsetDecimation();
126  float decimate( AimsSurfaceTriangle& surface );
135  float decimate( AimsSurfaceTriangle& surface,
136  const std::vector<float> & precthresholds,
137  const TimeTexture<float> & precisionmap );
138 
139  // SPLITTING SURFACE OF CONNECTED COMP.
140  // ====================================
141  void doit( const AimsData<short>& thing,
142  std::map< size_t, std::list< std::map<short,
143  std::list<AimsSurfaceTriangle > > > >& surface );
144  void setSplitting();
145  void unsetSplitting();
146 
147  // LABELS
148  // ======
149  void setLabelInf( int labelInf ) { _labelInf = labelInf; }
150  void setLabelSup( int labelSup ) { _labelSup = labelSup; }
151 
152  // SURFACE VALUE
153  // =============
154  void setMinSurface( float minSurface ) { _minSurface = minSurface; }
155  float surfaceOfInterface( const AimsSurfaceTriangle& surface );
156 
157  // OUTPUT FORMAT
158  // =============
162  __attribute__((__deprecated__("specify extension in the output filename "
163  "of setMeshOutputFile() or doit()")))
164  { _triOutputFlag = true; }
165  void setMeshOutputFile() { _triOutputFlag = false; }
166 
167  // MINIMUM NUMBER OF FACETS TO ALLOW DECIMATION
168  // ============================================
169  void setMinFacetNumber( uint m ) { _minFacetNumber = m; }
170 
171  bool verbose() const { return _verbose; }
172  void setVerbose( bool x ) { _verbose = x; }
173 
174  protected:
175 
178  float _smoothRate;
182 
183  bool _deciFlag;
188 
190 
193 
194  float _minSurface;
195 
197 
199 
200  bool _verbose;
201 
202  void getReducedNeighOutwardCycles( MapOfFacet& thing );
203  void getExtendedNeighOfFacet( MapOfFacet& thing );
204 
205  void getVertices( const std::vector< Facet* >& vfac,
206  std::vector< Point3df >& vertex,
207  float sizeX, float sizeY, float sizeZ );
208  void getSmoothedVertices( const std::vector< Facet* >& vfac,
209  AimsSurfaceTriangle& surface,
210  float rate );
211  void getSmoothedLaplacian( const std::vector< Facet* >& vfac,
212  AimsSurfaceTriangle& surface,
213  float featureAngle,
214  int nIteration,
215  float rate );
216  void getSmoothedSimpleSpring( const std::vector< Facet* >& vfac,
217  AimsSurfaceTriangle& surface,
218  float force,
219  int nIteration,
220  float rate );
221  void getSmoothedPolygonSpring( const std::vector< Facet* >& vfac,
222  AimsSurfaceTriangle& surface,
223  float force,
224  int nIteration,
225  float rate );
226  void getSmoothedLowPassFilter( const std::vector< Facet* >& vfac,
227  AimsSurfaceTriangle& surface,
228  int nIteration,
229  float rate );
230  void getDecimatedVertices( std::vector< Facet* >& vfac,
231  std::vector< Point3df >& vertex,
232  float reductionRatePercent,
233  float maxClearanceMm,
234  float maxErrorMm,
235  float minFeatureEdgeAngleDegree );
236  void getDecimatedVertices( std::vector< Facet* >& vfac,
237  std::vector< Point3df >& vertex,
238  float reductionRatePercent,
239  float maxClearanceMm,
240  float maxErrorMm,
241  float minFeatureEdgeAngleDegree,
242  const std::vector<float> & thresholds,
243  const TimeTexture<float> *precisionmap = 0
244  );
245  float decimate( AimsSurfaceTriangle& surface,
246  const std::vector<float> & thresholds,
247  const TimeTexture<float> *precisionmap );
248 
249  void getNormals( const std::vector< Facet* >& vfac,
250  const std::vector< Point3df >& vertex,
251  std::vector< Point3df >& normal );
252  void getTriangles( const std::vector< Facet* >& vfac,
253  std::vector< AimsVector< uint, 3 > >& triangle );
254 
255  void splitting( const AimsData< short >& thing,
256  const std::vector< Facet* >& vfac,
257  const AimsSurfaceTriangle& surface,
258  std::map<short,std::list< AimsSurfaceTriangle> >&
259  splitted );
260 
261  void getFacet( const AimsSurfaceTriangle& surface,
262  std::vector< Facet* >& vfac );
263 
264  void clear( std::map< size_t, std::list< MapOfFacet > >& interface );
265 };
266 
267 
268 #endif
void setTriOutputFile() __attribute__((__deprecated__("specify extension in the output filename " "of setMeshOutputFile() or doit()")))
OBSOLETE - specify extension in the output filename of setMeshOutputFile() or doit() ...
Definition: mesher.h:161
int _labelInf
Definition: mesher.h:191
bool _deciFlag
Definition: mesher.h:183
float _deciReductionRate
Definition: mesher.h:184
AIMSDATA_API AimsTimeSurface< 3, Void > AimsSurfaceTriangle
int _labelSup
Definition: mesher.h:192
float _deciFeatureAngle
Definition: mesher.h:187
bool _triOutputFlag
Definition: mesher.h:196
void setMinFacetNumber(uint m)
Definition: mesher.h:169
float _smoothForce
Definition: mesher.h:180
bool _verbose
Definition: mesher.h:200
bool _splittingFlag
Definition: mesher.h:189
float _deciMaxClearance
Definition: mesher.h:185
float _minSurface
Definition: mesher.h:194
void setMeshOutputFile()
Definition: mesher.h:165
bool verbose() const
Definition: mesher.h:171
float _deciMaxError
Definition: mesher.h:186
void setVerbose(bool x)
Definition: mesher.h:172
uint _minFacetNumber
Definition: mesher.h:198
void setLabelInf(int labelInf)
Definition: mesher.h:149
Definition: mesher.h:51
void setMinSurface(float minSurface)
Definition: mesher.h:154
bool _smoothFlag
Definition: mesher.h:176
SmoothingType _smoothType
Definition: mesher.h:181
float _smoothRate
Definition: mesher.h:178
unsigned int uint
int _smoothIt
Definition: mesher.h:177
float _smoothFeatureAngle
Definition: mesher.h:179
void setLabelSup(int labelSup)
Definition: mesher.h:150
Mesher()
Definition: mesher.h:62
std::map< uint, Facet *, std::less< int > > MapOfFacet
Definition: mesher.h:46
virtual ~Mesher()
Definition: mesher.h:76
#define AIMSALGO_API
SmoothingType
Definition: mesher.h:54