ITK  5.0.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()= default;
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:
74  ITK_DISALLOW_COPY_AND_ASSIGN(TriangleMeshToBinaryImageFilter);
75 
81 
83  using SizeType = typename TOutputImage::SizeType;
84  using OutputImageType = TOutputImage;
85  using OutputImagePointer = typename OutputImageType::Pointer;
86  using ValueType = typename OutputImageType::ValueType;
87  using SpacingType = typename OutputImageType::SpacingType;
89 
91  itkNewMacro(Self);
92 
95 
97  using OutputImageRegionType = typename Superclass::OutputImageRegionType;
98 
100  using InputMeshType = TInputMesh;
101  using InputMeshPointer = typename InputMeshType::Pointer;
103  using InputPixelType = typename InputMeshType::PixelType;
104  using InputCellTraitsType = typename InputMeshType::MeshTraits::CellTraits;
105  using CellType = typename InputMeshType::CellType;
106  using CellsContainerPointer = typename InputMeshType::CellsContainerPointer;
107  using CellsContainerIterator = typename InputMeshType::CellsContainerIterator;
108 
109  using InputPointsContainer = typename InputMeshType::PointsContainer;
110  using InputPointsContainerPointer = typename InputPointsContainer::Pointer;
111  using InputPointsContainerIterator = typename InputPointsContainer::Iterator;
112 
115 
118 
120 
121  using Point1DVector = std::vector< Point1D >;
122  using Point1DArray = std::vector< std::vector< Point1D > >;
123 
124  using Point2DVector = std::vector< Point2DType >;
125  using Point2DArray = std::vector< std::vector< Point2DType > >;
126 
127  using PointVector = std::vector< PointType >;
128  using PointArray = std::vector< std::vector< PointType > >;
129 
130  using StencilIndexVector = std::vector< int >;
135  itkSetMacro(Spacing, SpacingType);
136  virtual void SetSpacing(const double spacing[3]);
138 
139  virtual void SetSpacing(const float spacing[3]);
140 
141  itkGetConstReferenceMacro(Spacing, SpacingType);
142 
146  itkSetMacro(Direction, DirectionType);
147  itkGetConstMacro(Direction, DirectionType);
149 
155  itkSetMacro(InsideValue, ValueType);
156  itkGetConstMacro(InsideValue, ValueType);
158 
164  itkSetMacro(OutsideValue, ValueType);
165  itkGetConstMacro(OutsideValue, ValueType);
167 
172  itkSetMacro(Origin, PointType);
173  virtual void SetOrigin(const double origin[3]);
175 
176  virtual void SetOrigin(const float origin[3]);
177 
178  itkGetConstReferenceMacro(Origin, PointType);
179 
181  itkSetMacro(Index, IndexType);
182  itkGetConstMacro(Index, IndexType);
184 
186  itkSetMacro(Size, SizeType);
187  itkGetConstMacro(Size, SizeType);
189 
191  using Superclass::SetInput;
192  void SetInput(InputMeshType *input);
193 
194  void SetInfoImage(OutputImageType *InfoImage)
195  {
196  if ( InfoImage != m_InfoImage )
197  {
198  this->Modified();
199  m_InfoImage = InfoImage;
200  }
201  }
202 
204  InputMeshType * GetInput();
205 
206  InputMeshType * GetInput(unsigned int idx);
207 
208  /* Set the tolerance for doing spatial searches of the polydata. */
209  itkSetMacro(Tolerance, double);
210  itkGetConstMacro(Tolerance, double);
211 
212 protected:
214  ~TriangleMeshToBinaryImageFilter() override = default;
215 
216  void GenerateOutputInformation() override {} // do nothing
217  void GenerateData() override;
218 
219  virtual void RasterizeTriangles();
220 
221  static int PolygonToImageRaster(PointVector coords, Point1DArray & zymatrix, int extent[6]);
222 
224 
226 
228 
230 
231  PointType m_Origin; //start value
232 
233  double m_Tolerance;
234 
237 
239 
241 
242  void PrintSelf(std::ostream & os, Indent indent) const override;
243 
244 private:
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)
typename InputMeshType::PointsContainer InputPointsContainer
std::vector< std::vector< Point1D > > Point1DArray
typename InputPointsContainer::Iterator InputPointsContainerIterator
typename OutputImageType::Pointer OutputImagePointer
3D Rasterization algorithm Courtesy of Dr David Gobbi of Atamai Inc.
Represent a n-dimensional index in a n-dimensional image.
Definition: itkIndex.h:66
The base class for all process objects (source, filters, mappers) in the Insight data processing pipe...
Base class for all process objects that output image data.
Point1D(const double p, const int s)
std::vector< std::vector< PointType > > PointArray
Point1D()=default
std::vector< std::vector< Point2DType > > Point2DArray
typename InputPointsContainer::Pointer InputPointsContainerPointer
typename InputMeshType::CellsContainerIterator CellsContainerIterator
typename MeshTraits::PointsContainer PointsContainer
Definition: itkPointSet.h:109
typename OutputImageType::RegionType OutputImageRegionType
Represent a n-dimensional size (bounds) of a n-dimensional image.
Definition: itkSize.h:68
A superclass of the N-dimensional mesh structure; supports point (geometric coordinate and attribute)...
Definition: itkPointSet.h:84
typename OutputImageType::DirectionType DirectionType
typename PointSetType::PointsContainer PointsContainer
Control indentation during Print() invocation.
Definition: itkIndent.h:49
typename InputMeshType::MeshTraits::CellTraits InputCellTraitsType
typename OutputImageType::SpacingType SpacingType
typename InputMeshType::CellsContainerPointer CellsContainerPointer