aimsalgo  5.1.2
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>
42 #include <aims/bucket/bucket.h>
43 #include <map>
44 #include <list>
45 #include <vector>
46 
47 typedef std::map< uint, Facet*, std::less< int > > MapOfFacet;
48 
49 template <typename T> class TimeTexture;
50 
51 
52 class Mesher
53 {
54  public:
56  {
61  };
62 
63  Mesher() : _smoothFlag( false ),
64  _smoothIt( 30 ),
65  _smoothRate( 0.4 ),
66  _smoothFeatureAngle( 180. ),
67  _smoothForce( 0.2 ),
69  _deciFlag( false ),
70  _deciReductionRate( 99. ),
71  _deciMaxClearance( 3. ),
72  _deciMaxError( .2 ),
73  _deciFeatureAngle( 180. ),
74  _splittingFlag( false ),
75  _labelInf( 1 ),
76  _labelSup( 32767 ), // should maybe disapear ?
77  _minSurface( 0.0f ),
78  _triOutputFlag( false ),
79  _minFacetNumber( 50 ),
80  _verbose( true ) { }
81  virtual ~Mesher() { }
82 
83  // GETTING INTERFACE / MESH
84  // =========================
85  void getInterface( std::map<size_t, std::list< MapOfFacet > > & interface,
86  const carto::rc_ptr<carto::Volume<short> > & thing );
87  void doit( const carto::rc_ptr<carto::Volume<short> > & thing,
88  const std::string& name, const std::string& mode = "binar" );
89  void doit( const aims::BucketMap<Void>& thing, const std::string& name,
90  const std::string& mode = "binar" );
91  void doit( const carto::rc_ptr<carto::Volume<short> > & thing,
92  std::map<size_t, std::list<AimsSurfaceTriangle> >& surface );
93  void doit( const aims::BucketMap<Void>& thing,
94  std::map<size_t, std::list<AimsSurfaceTriangle> >& surface );
96  AimsSurfaceTriangle& surface, bool insideinterface=false );
97  void getBrain( const aims::BucketMap<Void>& thing,
98  AimsSurfaceTriangle& surface, bool insideinterface=false );
99  // like getBrain but dedicated to gray/white interface in 6 connectivity,
100  // which solves hole problems. JFM
102  AimsSurfaceTriangle& surface );
103  void getWhite( const aims::BucketMap<Void>& thing,
104  AimsSurfaceTriangle& surface );
105 
106  // create one mesh for all components of each label
108  AimsSurfaceTriangle& surface );
109 
110  // create one smoothed and decimated mesh from a map of facets
111  // (used by getBrain and getSingleLabel)
113  const carto::rc_ptr<carto::Volume<short> > & thing,
114  AimsSurfaceTriangle& surface, MapOfFacet &mof);
115 
124  void setSmoothing( SmoothingType smoothType, int smoothIt, float smoothRate );
125  // smoothFeatureAngle good value: 180. degrees
126  void setSmoothingLaplacian( float smoothFeatureAngle );
127  void setSmoothingSpring( float smoothForce );
129  void smooth( AimsSurfaceTriangle& surface );
130 
138  void setDecimation( float deciReductionRate,
139  float deciMaxClearance,
140  float deciMaxError,
141  float deciFeatureAngle );
143  float decimate( AimsSurfaceTriangle& surface );
152  float decimate( AimsSurfaceTriangle& surface,
153  const std::vector<float> & precthresholds,
154  const TimeTexture<float> & precisionmap );
155 
156  // SPLITTING SURFACE OF CONNECTED COMP.
157  // ====================================
158  void doit( const carto::rc_ptr<carto::Volume<short> > & thing,
159  std::map< size_t, std::list< std::map<short,
160  std::list<AimsSurfaceTriangle > > > >& surface );
161  void doit( const aims::BucketMap<Void>& thing,
162  std::map< size_t, std::list< std::map<short,
163  std::list<AimsSurfaceTriangle > > > >& surface );
164  void setSplitting();
166 
167  // LABELS
168  // ======
169  void setLabelInf( int labelInf ) { _labelInf = labelInf; }
170  void setLabelSup( int labelSup ) { _labelSup = labelSup; }
171 
172  // SURFACE VALUE
173  // =============
174  void setMinSurface( float minSurface ) { _minSurface = minSurface; }
175  float surfaceOfInterface( const AimsSurfaceTriangle& surface );
176 
177  // OUTPUT FORMAT
178  // =============
182  __attribute__((__deprecated__("specify extension in the output filename "
183  "of setMeshOutputFile() or doit()")))
184  { _triOutputFlag = true; }
185  void setMeshOutputFile() { _triOutputFlag = false; }
186 
187  // MINIMUM NUMBER OF FACETS TO ALLOW DECIMATION
188  // ============================================
190 
191  bool verbose() const { return _verbose; }
192  void setVerbose( bool x ) { _verbose = x; }
193 
194  protected:
195 
198  float _smoothRate;
202 
203  bool _deciFlag;
208 
210 
213 
214  float _minSurface;
215 
217 
219 
220  bool _verbose;
221 
224 
225  void getVertices( const std::vector< Facet* >& vfac,
226  std::vector< Point3df >& vertex,
227  float sizeX, float sizeY, float sizeZ );
228  void getSmoothedVertices( const std::vector< Facet* >& vfac,
229  AimsSurfaceTriangle& surface,
230  float rate );
231  void getSmoothedLaplacian( const std::vector< Facet* >& vfac,
232  AimsSurfaceTriangle& surface,
233  float featureAngle,
234  int nIteration,
235  float rate );
236  void getSmoothedSimpleSpring( const std::vector< Facet* >& vfac,
237  AimsSurfaceTriangle& surface,
238  float force,
239  int nIteration,
240  float rate );
241  void getSmoothedPolygonSpring( const std::vector< Facet* >& vfac,
242  AimsSurfaceTriangle& surface,
243  float force,
244  int nIteration,
245  float rate );
246  void getSmoothedLowPassFilter( const std::vector< Facet* >& vfac,
247  AimsSurfaceTriangle& surface,
248  int nIteration,
249  float rate );
250  void getDecimatedVertices( std::vector< Facet* >& vfac,
251  std::vector< Point3df >& vertex,
252  float reductionRatePercent,
253  float maxClearanceMm,
254  float maxErrorMm,
255  float minFeatureEdgeAngleDegree );
256  void getDecimatedVertices( std::vector< Facet* >& vfac,
257  std::vector< Point3df >& vertex,
258  float reductionRatePercent,
259  float maxClearanceMm,
260  float maxErrorMm,
261  float minFeatureEdgeAngleDegree,
262  const std::vector<float> & thresholds,
263  const TimeTexture<float> *precisionmap = 0
264  );
265  float decimate( AimsSurfaceTriangle& surface,
266  const std::vector<float> & thresholds,
267  const TimeTexture<float> *precisionmap );
268 
269  void getNormals( const std::vector< Facet* >& vfac,
270  const std::vector< Point3df >& vertex,
271  std::vector< Point3df >& normal );
272  void getTriangles( const std::vector< Facet* >& vfac,
273  std::vector< AimsVector< uint, 3 > >& triangle );
274 
276  const std::vector< Facet* >& vfac,
277  const AimsSurfaceTriangle& surface,
278  std::map<short,std::list< AimsSurfaceTriangle> >&
279  splitted );
280 
281  void getFacet( const AimsSurfaceTriangle& surface,
282  std::vector< Facet* >& vfac );
283 
284  void clear( std::map< size_t, std::list< MapOfFacet > >& interface );
287  const carto::VolumeRef<int16_t> in_vol );
288 };
289 
290 
291 #endif
Definition: mesher.h:53
void doit(const carto::rc_ptr< carto::Volume< short > > &thing, std::map< size_t, std::list< AimsSurfaceTriangle > > &surface)
void getSmoothedLaplacian(const std::vector< Facet * > &vfac, AimsSurfaceTriangle &surface, float featureAngle, int nIteration, float rate)
void unsetDecimation()
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:181
void unsetSplitting()
void getBrain(const carto::rc_ptr< carto::Volume< short > > &thing, AimsSurfaceTriangle &surface, bool insideinterface=false)
void setSmoothingSpring(float smoothForce)
void getVertices(const std::vector< Facet * > &vfac, std::vector< Point3df > &vertex, float sizeX, float sizeY, float sizeZ)
bool _splittingFlag
Definition: mesher.h:209
void doit(const aims::BucketMap< Void > &thing, const std::string &name, const std::string &mode="binar")
void getSmoothedVertices(const std::vector< Facet * > &vfac, AimsSurfaceTriangle &surface, float rate)
void getNormals(const std::vector< Facet * > &vfac, const std::vector< Point3df > &vertex, std::vector< Point3df > &normal)
void getExtendedNeighOfFacet(MapOfFacet &thing)
Mesher()
Definition: mesher.h:63
void getTriangles(const std::vector< Facet * > &vfac, std::vector< AimsVector< uint, 3 > > &triangle)
float decimate(AimsSurfaceTriangle &surface, const std::vector< float > &thresholds, const TimeTexture< float > *precisionmap)
void setMinSurface(float minSurface)
Definition: mesher.h:174
void getReducedNeighOutwardCycles(MapOfFacet &thing)
void doit(const carto::rc_ptr< carto::Volume< short > > &thing, std::map< size_t, std::list< std::map< short, std::list< AimsSurfaceTriangle > > > > &surface)
uint _minFacetNumber
Definition: mesher.h:218
void getSmoothedLowPassFilter(const std::vector< Facet * > &vfac, AimsSurfaceTriangle &surface, int nIteration, float rate)
void getWhite(const carto::rc_ptr< carto::Volume< short > > &thing, AimsSurfaceTriangle &surface)
void doit(const carto::rc_ptr< carto::Volume< short > > &thing, const std::string &name, const std::string &mode="binar")
void doit(const aims::BucketMap< Void > &thing, std::map< size_t, std::list< std::map< short, std::list< AimsSurfaceTriangle > > > > &surface)
void getMeshFromMapOfFacet(const carto::rc_ptr< carto::Volume< short > > &thing, AimsSurfaceTriangle &surface, MapOfFacet &mof)
float decimate(AimsSurfaceTriangle &surface, const std::vector< float > &precthresholds, const TimeTexture< float > &precisionmap)
Decimation using a precision texture map.
int _labelInf
Definition: mesher.h:211
float _minSurface
Definition: mesher.h:214
void getInterface(std::map< size_t, std::list< MapOfFacet > > &interface, const carto::rc_ptr< carto::Volume< short > > &thing)
static carto::VolumeRef< int16_t > reshapedVolume(const carto::VolumeRef< int16_t > in_vol)
reshape (if needed) the input volume to add a border filled with -1
void getSingleLabel(const carto::rc_ptr< carto::Volume< short > > &thing, AimsSurfaceTriangle &surface)
float _smoothRate
Definition: mesher.h:198
void doit(const aims::BucketMap< Void > &thing, std::map< size_t, std::list< AimsSurfaceTriangle > > &surface)
void getBrain(const aims::BucketMap< Void > &thing, AimsSurfaceTriangle &surface, bool insideinterface=false)
void clear(std::map< size_t, std::list< MapOfFacet > > &interface)
SmoothingType
Definition: mesher.h:56
@ LAPLACIAN
Definition: mesher.h:57
@ SIMPLESPRING
Definition: mesher.h:58
@ LOWPASS
Definition: mesher.h:60
@ POLYGONSPRING
Definition: mesher.h:59
void setSmoothing(SmoothingType smoothType, int smoothIt, float smoothRate)
Smoothing.
bool verbose() const
Definition: mesher.h:191
void getSmoothedPolygonSpring(const std::vector< Facet * > &vfac, AimsSurfaceTriangle &surface, float force, int nIteration, float rate)
void setVerbose(bool x)
Definition: mesher.h:192
float decimate(AimsSurfaceTriangle &surface)
float _smoothForce
Definition: mesher.h:200
void setSplitting()
void getWhite(const aims::BucketMap< Void > &thing, AimsSurfaceTriangle &surface)
void setDecimation(float deciReductionRate, float deciMaxClearance, float deciMaxError, float deciFeatureAngle)
Decimation.
float _deciMaxError
Definition: mesher.h:206
bool _smoothFlag
Definition: mesher.h:196
bool _deciFlag
Definition: mesher.h:203
void setLabelInf(int labelInf)
Definition: mesher.h:169
int _smoothIt
Definition: mesher.h:197
SmoothingType _smoothType
Definition: mesher.h:201
void getDecimatedVertices(std::vector< Facet * > &vfac, std::vector< Point3df > &vertex, float reductionRatePercent, float maxClearanceMm, float maxErrorMm, float minFeatureEdgeAngleDegree)
float _smoothFeatureAngle
Definition: mesher.h:199
void getFacet(const AimsSurfaceTriangle &surface, std::vector< Facet * > &vfac)
void setMinFacetNumber(uint m)
Definition: mesher.h:189
void setLabelSup(int labelSup)
Definition: mesher.h:170
void splitting(const carto::rc_ptr< carto::Volume< short > > &thing, const std::vector< Facet * > &vfac, const AimsSurfaceTriangle &surface, std::map< short, std::list< AimsSurfaceTriangle > > &splitted)
void getDecimatedVertices(std::vector< Facet * > &vfac, std::vector< Point3df > &vertex, float reductionRatePercent, float maxClearanceMm, float maxErrorMm, float minFeatureEdgeAngleDegree, const std::vector< float > &thresholds, const TimeTexture< float > *precisionmap=0)
float _deciFeatureAngle
Definition: mesher.h:207
void unsetSmoothing()
bool _triOutputFlag
Definition: mesher.h:216
void setMeshOutputFile()
Definition: mesher.h:185
virtual ~Mesher()
Definition: mesher.h:81
void smooth(AimsSurfaceTriangle &surface)
float _deciMaxClearance
Definition: mesher.h:205
void setSmoothingLaplacian(float smoothFeatureAngle)
bool _verbose
Definition: mesher.h:220
float _deciReductionRate
Definition: mesher.h:204
void getSmoothedSimpleSpring(const std::vector< Facet * > &vfac, AimsSurfaceTriangle &surface, float force, int nIteration, float rate)
int _labelSup
Definition: mesher.h:212
float surfaceOfInterface(const AimsSurfaceTriangle &surface)
std::map< uint, Facet *, std::less< int > > MapOfFacet
Definition: mesher.h:47
AIMSDATA_API AimsTimeSurface< 3, Void > AimsSurfaceTriangle
unsigned int uint