ITK
4.1.0
Insight Segmentation and Registration Toolkit
|
00001 /*========================================================================= 00002 * 00003 * Copyright Insight Software Consortium 00004 * 00005 * Licensed under the Apache License, Version 2.0 (the "License"); 00006 * you may not use this file except in compliance with the License. 00007 * You may obtain a copy of the License at 00008 * 00009 * http://www.apache.org/licenses/LICENSE-2.0.txt 00010 * 00011 * Unless required by applicable law or agreed to in writing, software 00012 * distributed under the License is distributed on an "AS IS" BASIS, 00013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00014 * See the License for the specific language governing permissions and 00015 * limitations under the License. 00016 * 00017 *=========================================================================*/ 00018 #ifndef __itkTriangleMeshToBinaryImageFilter_h 00019 #define __itkTriangleMeshToBinaryImageFilter_h 00020 00021 #include "itkImageSource.h" 00022 00023 #include "itkPolygonCell.h" 00024 #include "itkMapContainer.h" 00025 #include "itkVectorContainer.h" 00026 #include "itkAutomaticTopologyMeshSource.h" 00027 #include "itkPointSet.h" 00028 00029 #include <vector> 00030 00031 namespace itk 00032 { 00033 class Point1D 00034 { 00035 public: 00036 double m_X; 00037 int m_Sign; 00038 00039 Point1D(){} 00040 Point1D(const double p, const int s) 00041 { 00042 m_X = p; 00043 m_Sign = s; 00044 } 00045 00046 Point1D(const Point1D & point) 00047 { 00048 m_X = point.m_X; 00049 m_Sign = point.m_Sign; 00050 } 00051 00052 double getX() const 00053 { 00054 return m_X; 00055 } 00056 00057 int getSign() const 00058 { 00059 return m_Sign; 00060 } 00061 }; 00062 00070 template< class TInputMesh, class TOutputImage > 00071 class ITK_EXPORT TriangleMeshToBinaryImageFilter:public ImageSource< TOutputImage > 00072 { 00073 public: 00075 typedef TriangleMeshToBinaryImageFilter Self; 00076 typedef ImageSource< TOutputImage > Superclass; 00077 typedef SmartPointer< Self > Pointer; 00078 typedef SmartPointer< const Self > ConstPointer; 00079 00080 typedef typename TOutputImage::IndexType IndexType; 00081 typedef typename TOutputImage::SizeType SizeType; 00082 typedef TOutputImage OutputImageType; 00083 typedef typename OutputImageType::Pointer OutputImagePointer; 00084 typedef typename OutputImageType::ValueType ValueType; 00085 typedef typename OutputImageType::SpacingType SpacingType; 00086 typedef typename OutputImageType::DirectionType DirectionType; 00087 00089 itkNewMacro(Self); 00090 00092 itkTypeMacro(TriangleMeshToBinaryImageFilter, ImageSource); 00093 00095 typedef typename Superclass::OutputImageRegionType OutputImageRegionType; 00096 00098 typedef TInputMesh InputMeshType; 00099 typedef typename InputMeshType::Pointer InputMeshPointer; 00100 typedef typename InputMeshType::PointType InputPointType; 00101 typedef typename InputMeshType::PixelType InputPixelType; 00102 typedef typename InputMeshType::MeshTraits::CellTraits InputCellTraitsType; 00103 typedef typename InputMeshType::CellType CellType; 00104 typedef typename InputMeshType::CellsContainerPointer CellsContainerPointer; 00105 typedef typename InputMeshType::CellsContainerIterator CellsContainerIterator; 00106 00107 typedef typename InputMeshType::PointsContainer InputPointsContainer; 00108 typedef typename InputPointsContainer::Pointer InputPointsContainerPointer; 00109 typedef typename InputPointsContainer::Iterator InputPointsContainerIterator; 00110 00111 typedef itk::PointSet< double, 3 > PointSetType; 00112 typedef typename PointSetType::PointsContainer PointsContainer; 00113 00114 typedef itk::Point< double, 3 > PointType; 00115 typedef itk::Point< double, 2 > Point2DType; 00116 00117 typedef itk::Array< double > DoubleArrayType; 00118 00119 typedef std::vector< Point1D > Point1DVector; 00120 typedef std::vector< std::vector< Point1D > > Point1DArray; 00121 00122 typedef std::vector< Point2DType > Point2DVector; 00123 typedef std::vector< std::vector< Point2DType > > Point2DArray; 00124 00125 typedef std::vector< PointType > PointVector; 00126 typedef std::vector< std::vector< PointType > > PointArray; 00127 00128 typedef std::vector< int > StencilIndexVector; 00133 itkSetMacro(Spacing, SpacingType); 00134 virtual void SetSpacing(const double spacing[3]); 00136 00137 virtual void SetSpacing(const float spacing[3]); 00138 00139 itkGetConstReferenceMacro(Spacing, SpacingType); 00140 00144 itkSetMacro(Direction, DirectionType); 00145 itkGetConstMacro(Direction, DirectionType); 00147 00153 itkSetMacro(InsideValue, ValueType); 00154 itkGetConstMacro(InsideValue, ValueType); 00156 00162 itkSetMacro(OutsideValue, ValueType); 00163 itkGetConstMacro(OutsideValue, ValueType); 00165 00170 itkSetMacro(Origin, PointType); 00171 virtual void SetOrigin(const double origin[3]); 00173 00174 virtual void SetOrigin(const float origin[3]); 00175 00176 itkGetConstReferenceMacro(Origin, PointType); 00177 00179 itkSetMacro(Index, IndexType); 00180 itkGetConstMacro(Index, IndexType); 00182 00184 itkSetMacro(Size, SizeType); 00185 itkGetConstMacro(Size, SizeType); 00187 00189 using Superclass::SetInput; 00190 void SetInput(InputMeshType *input); 00191 00192 void SetInfoImage(OutputImageType *InfoImage) 00193 { 00194 if ( InfoImage != m_InfoImage ) 00195 { 00196 this->Modified(); 00197 m_InfoImage = InfoImage; 00198 } 00199 } 00200 00202 InputMeshType * GetInput(void); 00203 00204 InputMeshType * GetInput(unsigned int idx); 00205 00206 /* Set the tolerance for doing spatial searches of the polydata. */ 00207 itkSetMacro(Tolerance, double); 00208 itkGetConstMacro(Tolerance, double); 00209 protected: 00210 TriangleMeshToBinaryImageFilter(); 00211 ~TriangleMeshToBinaryImageFilter(); 00212 00213 virtual void GenerateOutputInformation(){} // do nothing 00214 virtual void GenerateData(); 00215 00216 virtual void RasterizeTriangles(); 00217 00218 static int PolygonToImageRaster(PointVector coords, Point1DArray & zymatrix, int extent[6]); 00219 00220 OutputImageType *m_InfoImage; 00221 00222 IndexType m_Index; 00223 00224 SizeType m_Size; 00225 00226 SpacingType m_Spacing; 00227 00228 PointType m_Origin; //start value 00229 00230 double m_Tolerance; 00231 00232 ValueType m_InsideValue; 00233 ValueType m_OutsideValue; 00234 00235 DirectionType m_Direction; 00236 00237 StencilIndexVector m_StencilIndex; 00238 00239 virtual void PrintSelf(std::ostream & os, Indent indent) const; 00240 00241 private: 00242 TriangleMeshToBinaryImageFilter(const Self &); //purposely not implemented 00243 void operator=(const Self &); //purposely not implemented 00244 00245 static bool ComparePoints2D(Point2DType a, Point2DType b); 00246 00247 static bool ComparePoints1D(Point1D a, Point1D b); 00248 }; 00249 } // end namespace itk 00250 00251 #ifndef ITK_MANUAL_INSTANTIATION 00252 #include "itkTriangleMeshToBinaryImageFilter.hxx" 00253 #endif 00254 00255 #endif 00256