00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #ifndef __itkTriangleMeshToBinaryImageFilter_h
00018 #define __itkTriangleMeshToBinaryImageFilter_h
00019
00020 #include "itkImageSource.h"
00021
00022 #include <itkMesh.h>
00023 #include <itkLineCell.h>
00024 #include <itkPolygonCell.h>
00025 #include <itkVertexCell.h>
00026 #include <itkMapContainer.h>
00027 #include <itkVectorContainer.h>
00028 #include <itkVector.h>
00029 #include <itkPoint.h>
00030 #include <itkArray.h>
00031 #include "itkAutomaticTopologyMeshSource.h"
00032 #include "itkPointSet.h"
00033
00034 #include <vector>
00035
00036 namespace itk
00037 {
00038
00039 class Point1D
00040 {
00041 public:
00042 double x;
00043 int sign;
00044
00045 Point1D(){};
00046 Point1D(const double p, const int s)
00047 {
00048 x = p;
00049 sign = s;
00050 };
00051 Point1D(const Point1D &point)
00052 {
00053 x = point.x;
00054 sign = point.sign;
00055 };
00056 double getX() const
00057 {
00058 return x;
00059 };
00060 int getSign() const
00061 {
00062 return sign;
00063 };
00064
00065 };
00072 template <class TInputMesh, class TOutputImage>
00073 class ITK_EXPORT TriangleMeshToBinaryImageFilter : public ImageSource<TOutputImage>
00074 {
00075 public:
00077 typedef TriangleMeshToBinaryImageFilter Self;
00078 typedef ImageSource<TOutputImage> Superclass;
00079 typedef SmartPointer<Self> Pointer;
00080 typedef SmartPointer<const Self> ConstPointer;
00081 typedef typename TOutputImage::IndexType IndexType;
00082 typedef typename TOutputImage::SizeType SizeType;
00083 typedef TOutputImage OutputImageType;
00084 typedef typename OutputImageType::Pointer OutputImagePointer;
00085 typedef typename OutputImageType::ValueType ValueType;
00086 typedef typename OutputImageType::SpacingType SpacingType;
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
00113 typedef PointSetType::PointsContainer PointsContainer;
00114
00115
00116 typedef itk::Point < double, 3> PointType;
00117 typedef itk::Point < double, 2> Point2DType;
00118
00119 typedef itk::Array<double> DoubleArrayType;
00120
00121 typedef std::vector< Point1D > Point1DVector;
00122 typedef std::vector< std::vector< Point1D> > Point1DArray;
00123
00124 typedef std::vector< Point2DType > Point2DVector;
00125 typedef std::vector< std::vector< Point2DType > > Point2DArray;
00126
00127 typedef std::vector< PointType > PointVector;
00128 typedef std::vector< std::vector< PointType > > PointArray;
00129
00130 typedef std::vector< int > StencilIndexVector;
00135 itkSetMacro(Spacing, SpacingType);
00136 virtual void SetSpacing( const double spacing[3] );
00137 virtual void SetSpacing( const float spacing[3] );
00138 itkGetConstReferenceMacro(Spacing, SpacingType);
00140
00146 itkSetMacro(InsideValue, ValueType);
00147 itkGetMacro(InsideValue, ValueType);
00149
00155 itkSetMacro(OutsideValue, ValueType);
00156 itkGetMacro(OutsideValue, ValueType);
00158
00163 itkSetMacro(Origin, PointType);
00164 virtual void SetOrigin( const double origin[3] );
00165 virtual void SetOrigin( const float origin[3] );
00166 itkGetConstReferenceMacro(Origin, PointType);
00168
00170 itkSetMacro(Index,IndexType);
00171 itkGetMacro(Index,IndexType);
00173
00175 itkSetMacro(Size,SizeType);
00176 itkGetMacro(Size,SizeType);
00178
00180 void SetInput(InputMeshType *input);
00181
00183 InputMeshType * GetInput(void);
00184 InputMeshType * GetInput(unsigned int idx);
00186
00187
00188 itkSetMacro(Tolerance, double);
00189 itkGetMacro(Tolerance, double);
00190
00191 protected:
00192 TriangleMeshToBinaryImageFilter();
00193 ~TriangleMeshToBinaryImageFilter();
00194
00195 virtual void GenerateOutputInformation(){};
00196 virtual void GenerateData();
00197
00198 virtual void RasterizeTriangles();
00199 static int PolygonToImageRaster( PointVector coords, Point1DArray & zymatrix, int extent[6]);
00200
00201
00202 IndexType m_Index;
00203 SizeType m_Size;
00204 SpacingType m_Spacing;
00205 PointType m_Origin;
00206 double m_Tolerance;
00207 ValueType m_InsideValue;
00208 ValueType m_OutsideValue;
00209 StencilIndexVector StencilIndex;
00210
00211 virtual void PrintSelf(std::ostream& os, Indent indent) const;
00212
00213 private:
00214 TriangleMeshToBinaryImageFilter(const Self&);
00215 void operator=(const Self&);
00216
00217 static bool ComparePoints2D(Point2DType a, Point2DType b);
00218 static bool ComparePoints1D(Point1D a, Point1D b);
00219 };
00220
00221 }
00222
00223 #ifndef ITK_MANUAL_INSTANTIATION
00224 #include "itkTriangleMeshToBinaryImageFilter.txx"
00225 #endif
00226
00227 #endif
00228