GOFIGURE2  0.9.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
itkExtractMeshesFromLabelImageFilter.h
Go to the documentation of this file.
1 /*=========================================================================
2  Authors: The GoFigure Dev. Team.
3  at Megason Lab, Systems biology, Harvard Medical school, 2009-11
4 
5  Copyright (c) 2009-11, President and Fellows of Harvard College.
6  All rights reserved.
7 
8  Redistribution and use in source and binary forms, with or without
9  modification, are permitted provided that the following conditions are met:
10 
11  Redistributions of source code must retain the above copyright notice,
12  this list of conditions and the following disclaimer.
13  Redistributions in binary form must reproduce the above copyright notice,
14  this list of conditions and the following disclaimer in the documentation
15  and/or other materials provided with the distribution.
16  Neither the name of the President and Fellows of Harvard College
17  nor the names of its contributors may be used to endorse or promote
18  products derived from this software without specific prior written
19  permission.
20 
21  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
23  THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
24  PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
25  BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
26  OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
27  OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
28  OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
29  WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
30  OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
31  ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 
33 =========================================================================*/
34 #ifndef __itkExtractMeshesFromLabelImageFilter_h
35 #define __itkExtractMeshesFromLabelImageFilter_h
36 
37 #ifdef _MSC_VER
38 #pragma warning ( disable : 4786 )
39 #endif
40 
41 #include "itkImageToImageFilter.h"
42 #include "itkImage.h"
43 
44 #include "itkImageRegionIteratorWithIndex.h"
45 #include "itkRegionOfInterestImageFilter.h"
46 #include "itkShapeLabelObject.h"
47 #include "itkLabelMap.h"
48 #include "itkLabelImageToShapeLabelMapFilter.h"
49 #include "itkLabelImageToStatisticsLabelMapFilter.h"
50 #include "itkShapeRelabelImageFilter.h"
51 
52 #include "itkVector.h"
53 #include "itkQuadEdgeMesh.h"
54 #ifdef ITKv4
55 #include "itkSmoothingQuadEdgeMeshFilter.h"
56 #include "itkSquaredEdgeLengthDecimationQuadEdgeMeshFilter.h"
57 #else
58 #include "itkQuadEdgeMeshSmoothing.h"
59 #include "itkQuadEdgeMeshSquaredEdgeLengthDecimation.h"
60 #endif
61 
62 #include "itkQuadEdgeMeshParamMatrixCoefficients.h"
63 #include "itkQuadEdgeMeshDecimationCriteria.h"
64 
65 #include "itkBinaryMask3DMeshSource.h"
66 
67 #include <fstream>
68 #include "itkVTKPolyDataWriter.h"
69 #include "itkMultiThreader.h"
70 
71 namespace itk
72 {
73 
79 template< class TImage, class TFeatureImage = TImage >
80 class ExtractMeshesFromLabelImageFilter : public Object
81 {
82 public:
84  typedef Object Superclass;
85  typedef SmartPointer<Self> Pointer;
86  typedef SmartPointer<const Self> ConstPointer;
87 
88  itkStaticConstMacro ( ImageDimension, unsigned int, TImage::ImageDimension );
89 
92 
95 
97  typedef TImage ImageType;
98  typedef typename ImageType::Pointer ImagePointer;
99  typedef typename ImageType::ConstPointer ImageConstPointer;
100  typedef typename ImageType::IndexType IndexType;
101  typedef typename IndexType::IndexValueType IndexValueType;
102  typedef typename ImageType::PixelType PixelType;
103  typedef typename ImageType::SizeType SizeType;
104  typedef typename SizeType::SizeValueType SizeValueType;
105  typedef typename ImageType::RegionType RegionType;
106  typedef typename ImageType::SpacingType SpacingType;
107  typedef typename ImageType::PointType PointType;
108  typedef typename PointType::CoordRepType CoordType;
109 
110  typedef TFeatureImage FeatureImageType;
111  typedef typename FeatureImageType::Pointer FeatureImagePointer;
112 
113  typedef std::vector< FeatureImagePointer > FeatureImageVectorType;
114 
116  typedef QuadEdgeMesh< CoordType, ImageDimension > MeshType;
117  typedef typename MeshType::Pointer MeshPointer;
118 
119  typedef std::vector< MeshPointer > MeshVectorType;
120 
122  typedef unsigned int LabelType;
123 
124  // ---------------------------------------------------------------------------
125 
127  typedef ShapeLabelObject< LabelType, ImageDimension > ShapeLabelObjectType;
128  typedef typename ShapeLabelObjectType::Pointer ShapeLabelObjectPointer;
129 
131  typedef LabelMap< ShapeLabelObjectType > ShapeLabelMapType;
132  typedef typename ShapeLabelMapType::Pointer ShapeLabelMapPointer;
133 
135  typedef LabelImageToShapeLabelMapFilter< ImageType,
138  typedef typename ShapeConverterType::Pointer ShapeConverterPointer;
139 
140 
141  typedef typename ShapeLabelMapType::LabelObjectContainerType
143  typedef typename LabelObjectContainerType::const_iterator
145 
146  // ---------------------------------------------------------------------------
147 
149  typedef StatisticsLabelObject< LabelType, ImageDimension > StatLabelObjectType;
150  typedef typename StatLabelObjectType::Pointer StatLabelObjectPointer;
151 
152 
153  typedef LabelMap< StatLabelObjectType > StatLabelMapType;
154  typedef typename StatLabelMapType::Pointer StatLabelMapPointer;
155 
156  typedef LabelImageToStatisticsLabelMapFilter<
157  ImageType,
158  ImageType,
160 
161  typedef typename StatConverterType::Pointer StatConverterPointer;
162 
163  // ---------------------------------------------------------------------------
164 
165  typedef RegionOfInterestImageFilter< ImageType, ImageType > ROIFilterType;
166  typedef typename ROIFilterType::Pointer ROIFilterPointer;
167 
168  typedef ImageRegionIterator< ImageType > IteratorType;
169  typedef ImageRegionIteratorWithIndex< ImageType > IndexIteratorType;
170 
171  typedef BinaryMask3DMeshSource< ImageType, MeshType > MeshSourceType;
172  typedef typename MeshSourceType::Pointer MeshSourcePointer;
173 
174  #ifdef ITKv4
175  typedef SmoothingQuadEdgeMeshFilter< MeshType, MeshType > MeshSmoothingType;
176  #else
177  typedef QuadEdgeMeshSmoothing< MeshType, MeshType > MeshSmoothingType;
178  #endif
179  typedef typename MeshSmoothingType::Pointer MeshSmoothingPointer;
180 
181  typedef NumberOfFacesCriterion< MeshType > CriterionType;
182  typedef typename CriterionType::Pointer CriterionPointer;
183 
184  #ifdef ITKv4
185  typedef SquaredEdgeLengthDecimationQuadEdgeMeshFilter<
187  #else
188  typedef QuadEdgeMeshSquaredEdgeLengthDecimation<
190  #endif
191  typedef typename DecimationType::Pointer DecimationPointer;
192 
193  typedef VTKPolyDataWriter< MeshType > MeshWriterType;
194  typedef typename MeshWriterType::Pointer MeshWriterPointer;
195 
196  typedef MultiThreader ThreaderType;
197  typedef typename ThreaderType::Pointer ThreaderPointer;
198 
200 
201  void SetNumberOfFeatureImages( const size_t& iN );
202  void SetFeatureImage( const size_t& iId, FeatureImageType* iF );
203 
204  itkGetConstMacro( NumberOfMeshes, unsigned int );
205 
206  itkSetMacro( NumberOfTrianglesPerMesh, unsigned int );
207  itkGetConstMacro( NumberOfTrianglesPerMesh, unsigned int );
208 
209  itkGetConstMacro( DelaunayConforming, bool );
210  itkSetMacro( DelaunayConforming, bool );
211 
212  itkSetMacro( UseDecimation, bool );
213  itkGetConstMacro( UseDecimation, bool );
214 
215  itkSetMacro( UseSmoothing, bool );
216  itkGetConstMacro( UseSmoothing, bool );
217 
218  itkSetMacro( NumberOfSmoothingIterations, unsigned int );
219  itkGetConstMacro( NumberOfSmoothingIterations, unsigned int );
220 
221  itkSetMacro( SmoothingRelaxationFactor, double );
222  itkGetConstMacro( SmoothingRelaxationFactor, double );
223 
224 #ifdef ITKv4
225  itkGetConstMacro( NumberOfThreads, ThreadIdType );
226  itkSetMacro( NumberOfThreads, ThreadIdType );
227 #else
228  itkGetConstMacro( NumberOfThreads, int );
229  itkSetMacro( NumberOfThreads, int );
230 #endif
231 
232  itkGetObjectMacro( ShapeLabelMap, ShapeLabelMapType );
233  std::vector< StatLabelMapPointer > GetStatLabelMap()
234  {
235  return m_StatLabelMap;
236  }
237 
238  void Update();
239 
241 
242 protected:
245  void PrintSelf(std::ostream& os, Indent indent) const;
246  void ThreadedExtractMesh( const unsigned int& startLabel,
247  const unsigned int& endLabel );
248 
249  static ITK_THREAD_RETURN_TYPE ThreaderCallback(void * arg);
250 
252  {
253  ThreadStruct( Self* iFilter ) : Filter( iFilter ) {}
254 
256  };
257 
258  void GenerateData();
259 
262  std::vector< StatLabelMapPointer > m_StatLabelMap;
263  std::map< size_t, LabelType > m_MeshtoLabelIdMap;
264 
267 
268 #ifdef ITKv4
269  ThreadIdType m_NumberOfThreads;
270 #else
272 #endif
273 
274  unsigned int m_NumberOfMeshes;
278 
283 
284 private:
286  void operator=(const Self&) {}
287 };
288 
289 } // end namespace itk
290 
291 #include "itkExtractMeshesFromLabelImageFilter.txx"
292 #endif
itkGetConstMacro(NumberOfMeshes, unsigned int)
itkTypeMacro(ExtractMeshesFromLabelImageFilter, Object)
void PrintSelf(std::ostream &os, Indent indent) const
BinaryMask3DMeshSource< ImageType, MeshType > MeshSourceType
RegionOfInterestImageFilter< ImageType, ImageType > ROIFilterType
LabelImageToStatisticsLabelMapFilter< ImageType, ImageType, StatLabelMapType > StatConverterType
void SetNumberOfFeatureImages(const size_t &iN)
itkStaticConstMacro(ImageDimension, unsigned int, TImage::ImageDimension)
void ThreadedExtractMesh(const unsigned int &startLabel, const unsigned int &endLabel)
StatisticsLabelObject< LabelType, ImageDimension > StatLabelObjectType
LabelObjectContainerType::const_iterator LabelObjectIterator
LabelImageToShapeLabelMapFilter< ImageType, ShapeLabelMapType > ShapeConverterType
QuadEdgeMeshSmoothing< MeshType, MeshType > MeshSmoothingType
ShapeLabelMapType::LabelObjectContainerType LabelObjectContainerType
ImageRegionIteratorWithIndex< ImageType > IndexIteratorType
void SetFeatureImage(const size_t &iId, FeatureImageType *iF)
QuadEdgeMesh< CoordType, ImageDimension > MeshType
static ITK_THREAD_RETURN_TYPE ThreaderCallback(void *arg)
itkGetObjectMacro(ShapeLabelMap, ShapeLabelMapType)
QuadEdgeMeshSquaredEdgeLengthDecimation< MeshType, MeshType, CriterionType > DecimationType
ShapeLabelObject< LabelType, ImageDimension > ShapeLabelObjectType
itkSetMacro(NumberOfTrianglesPerMesh, unsigned int)