ITK  4.13.0
Insight Segmentation and Registration Toolkit
itkTriangleMeshToBinaryImageFilter.h
Go to the documentation of this file.
1 /*=========================================================================
2  *
3  * Copyright Insight Software Consortium
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0.txt
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  *=========================================================================*/
18 #ifndef itkTriangleMeshToBinaryImageFilter_h
19 #define itkTriangleMeshToBinaryImageFilter_h
20 
21 #include "itkImageSource.h"
22 
23 #include "itkPolygonCell.h"
24 #include "itkMapContainer.h"
25 #include "itkVectorContainer.h"
27 #include "itkPointSet.h"
28 
29 #include <vector>
30 
31 namespace itk
32 {
33 class Point1D
34 {
35 public:
36  double m_X;
37  int m_Sign;
38 
39  Point1D(){}
40  Point1D(const double p, const int s)
41  {
42  m_X = p;
43  m_Sign = s;
44  }
45 
46  Point1D(const Point1D & point)
47  {
48  m_X = point.m_X;
49  m_Sign = point.m_Sign;
50  }
51 
52  double getX() const
53  {
54  return m_X;
55  }
56 
57  int getSign() const
58  {
59  return m_Sign;
60  }
61 };
62 
70 template< typename TInputMesh, typename TOutputImage >
71 class ITK_TEMPLATE_EXPORT TriangleMeshToBinaryImageFilter:public ImageSource< TOutputImage >
72 {
73 public:
79 
81  typedef typename TOutputImage::SizeType SizeType;
82  typedef TOutputImage OutputImageType;
83  typedef typename OutputImageType::Pointer OutputImagePointer;
84  typedef typename OutputImageType::ValueType ValueType;
85  typedef typename OutputImageType::SpacingType SpacingType;
87 
89  itkNewMacro(Self);
90 
93 
95  typedef typename Superclass::OutputImageRegionType OutputImageRegionType;
96 
98  typedef TInputMesh InputMeshType;
99  typedef typename InputMeshType::Pointer InputMeshPointer;
101  typedef typename InputMeshType::PixelType InputPixelType;
102  typedef typename InputMeshType::MeshTraits::CellTraits InputCellTraitsType;
103  typedef typename InputMeshType::CellType CellType;
104  typedef typename InputMeshType::CellsContainerPointer CellsContainerPointer;
105  typedef typename InputMeshType::CellsContainerIterator CellsContainerIterator;
106 
107  typedef typename InputMeshType::PointsContainer InputPointsContainer;
108  typedef typename InputPointsContainer::Pointer InputPointsContainerPointer;
109  typedef typename InputPointsContainer::Iterator InputPointsContainerIterator;
110 
113 
116 
118 
119  typedef std::vector< Point1D > Point1DVector;
120  typedef std::vector< std::vector< Point1D > > Point1DArray;
121 
122  typedef std::vector< Point2DType > Point2DVector;
123  typedef std::vector< std::vector< Point2DType > > Point2DArray;
124 
125  typedef std::vector< PointType > PointVector;
126  typedef std::vector< std::vector< PointType > > PointArray;
127 
128  typedef std::vector< int > StencilIndexVector;
133  itkSetMacro(Spacing, SpacingType);
134  virtual void SetSpacing(const double spacing[3]);
136 
137  virtual void SetSpacing(const float spacing[3]);
138 
139  itkGetConstReferenceMacro(Spacing, SpacingType);
140 
144  itkSetMacro(Direction, DirectionType);
145  itkGetConstMacro(Direction, DirectionType);
147 
153  itkSetMacro(InsideValue, ValueType);
154  itkGetConstMacro(InsideValue, ValueType);
156 
162  itkSetMacro(OutsideValue, ValueType);
163  itkGetConstMacro(OutsideValue, ValueType);
165 
170  itkSetMacro(Origin, PointType);
171  virtual void SetOrigin(const double origin[3]);
173 
174  virtual void SetOrigin(const float origin[3]);
175 
176  itkGetConstReferenceMacro(Origin, PointType);
177 
179  itkSetMacro(Index, IndexType);
180  itkGetConstMacro(Index, IndexType);
182 
184  itkSetMacro(Size, SizeType);
185  itkGetConstMacro(Size, SizeType);
187 
189  using Superclass::SetInput;
190  void SetInput(InputMeshType *input);
191 
192  void SetInfoImage(OutputImageType *InfoImage)
193  {
194  if ( InfoImage != m_InfoImage )
195  {
196  this->Modified();
197  m_InfoImage = InfoImage;
198  }
199  }
200 
202  InputMeshType * GetInput();
203 
204  InputMeshType * GetInput(unsigned int idx);
205 
206  /* Set the tolerance for doing spatial searches of the polydata. */
207  itkSetMacro(Tolerance, double);
208  itkGetConstMacro(Tolerance, double);
209 
210 protected:
212  ~TriangleMeshToBinaryImageFilter() ITK_OVERRIDE;
213 
214  virtual void GenerateOutputInformation() ITK_OVERRIDE {} // do nothing
215  virtual void GenerateData() ITK_OVERRIDE;
216 
217  virtual void RasterizeTriangles();
218 
219  static int PolygonToImageRaster(PointVector coords, Point1DArray & zymatrix, int extent[6]);
220 
221  OutputImageType *m_InfoImage;
222 
223  IndexType m_Index;
224 
225  SizeType m_Size;
226 
227  SpacingType m_Spacing;
228 
229  PointType m_Origin; //start value
230 
231  double m_Tolerance;
232 
233  ValueType m_InsideValue;
235 
236  DirectionType m_Direction;
237 
238  StencilIndexVector m_StencilIndex;
239 
240  virtual void PrintSelf(std::ostream & os, Indent indent) const ITK_OVERRIDE;
241 
242 private:
243  ITK_DISALLOW_COPY_AND_ASSIGN(TriangleMeshToBinaryImageFilter);
244 
245  static bool ComparePoints2D(Point2DType a, Point2DType b);
246 
247  static bool ComparePoints1D(Point1D a, Point1D b);
248 };
249 } // end namespace itk
250 
251 #ifndef ITK_MANUAL_INSTANTIATION
252 #include "itkTriangleMeshToBinaryImageFilter.hxx"
253 #endif
254 
255 #endif
Point1D(const Point1D &point)
InputMeshType::CellsContainerIterator CellsContainerIterator
3D Rasterization algorithm Courtesy of Dr David Gobbi of Atamai Inc.
Represent the size (bounds) of a n-dimensional image.
Definition: itkSize.h:52
Superclass::OutputImageRegionType OutputImageRegionType
InputPointsContainer::Iterator InputPointsContainerIterator
InputMeshType::CellsContainerPointer CellsContainerPointer
Base class for all process objects that output image data.
Point1D(const double p, const int s)
InputMeshType::MeshTraits::CellTraits InputCellTraitsType
std::vector< std::vector< Point1D > > Point1DArray
A superclass of the N-dimensional mesh structure; supports point (geometric coordinate and attribute)...
Definition: itkPointSet.h:84
MeshTraits::PointsContainer PointsContainer
Definition: itkPointSet.h:107
TOutput m_OutsideValue
std::vector< std::vector< PointType > > PointArray
Control indentation during Print() invocation.
Definition: itkIndent.h:49
std::vector< std::vector< Point2DType > > Point2DArray
Represent a n-dimensional index in a n-dimensional image.
Definition: itkIndex.h:72