00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #ifndef __itkBinaryMask3DMeshSource_h
00018 #define __itkBinaryMask3DMeshSource_h
00019
00020 #include "vnl/vnl_matrix_fixed.h"
00021 #include "itkMesh.h"
00022 #include "itkImageToMeshFilter.h"
00023 #include "itkVector.h"
00024 #include "itkCellInterface.h"
00025 #include "itkTriangleCell.h"
00026 #include "itkCovariantVector.h"
00027 #include "itkDefaultStaticMeshTraits.h"
00028 #include "itkImageRegionConstIterator.h"
00029
00030 namespace itk
00031 {
00032
00072 #ifndef ITK_EXPLICIT_INSTANTIATION
00073
00074 template class Image<unsigned short,3>;
00075 #endif
00076
00077 template <class TInputImage, class TOutputMesh>
00078 class ITK_EXPORT BinaryMask3DMeshSource : public ImageToMeshFilter< TInputImage, TOutputMesh >
00079 {
00080 public:
00082 typedef BinaryMask3DMeshSource Self;
00083 typedef ImageToMeshFilter< TInputImage, TOutputMesh > Superclass;
00084 typedef SmartPointer<Self> Pointer;
00085 typedef SmartPointer<const Self> ConstPointer;
00086
00088 itkNewMacro(Self);
00089
00091 itkTypeMacro(BinaryMask3DMeshSource, ImageToMeshFilter);
00092
00094 typedef TOutputMesh OutputMeshType;
00095 typedef typename OutputMeshType::MeshTraits OMeshTraits;
00096 typedef typename OutputMeshType::PointType OPointType;
00097 typedef typename OMeshTraits::PixelType OPixelType;
00098
00100 typedef typename OutputMeshType::Pointer OutputMeshPointer;
00101 typedef typename OutputMeshType::CellTraits CellTraits;
00102 typedef typename OutputMeshType::PointsContainerPointer PointsContainerPointer;
00103 typedef typename OutputMeshType::PointsContainer PointsContainer;
00104 typedef typename OutputMeshType::CellsContainerPointer CellsContainerPointer;
00105 typedef typename OutputMeshType::CellsContainer CellsContainer;
00106 typedef CovariantVector<double, 2> doubleVector;
00107 typedef CovariantVector<int, 2> intVector;
00108
00111 typedef CellInterface<OPixelType, CellTraits> TCellInterface;
00112 typedef TriangleCell<TCellInterface> TriCell;
00113 typedef typename TriCell::SelfAutoPointer TriCellAutoPointer;
00114
00116 typedef TInputImage InputImageType;
00117 typedef typename InputImageType::Pointer InputImagePointer;
00118 typedef typename InputImageType::ConstPointer InputImageConstPointer;
00119 typedef typename InputImageType::PixelType InputPixelType;
00120 typedef typename InputImageType::SpacingType SpacingType;
00121 typedef typename InputImageType::PointType OriginType;
00122
00124 typedef typename InputImageType::IndexType InputImageIndexType;
00125
00126 typedef ImageRegionConstIterator< InputImageType > InputImageIterator;
00127
00128 itkSetMacro(ObjectValue, InputPixelType);
00129
00130 itkGetMacro(NumberOfNodes, unsigned long);
00131 itkGetMacro(NumberOfCells, unsigned long);
00132
00134 virtual void SetInput( const InputImageType * inputImage );
00135
00136
00137 protected:
00138 BinaryMask3DMeshSource();
00139 ~BinaryMask3DMeshSource();
00140 void PrintSelf(std::ostream& os, Indent indent) const;
00141
00142 void GenerateData();
00143 virtual void GenerateOutputInformation(){};
00144
00145 private:
00146 BinaryMask3DMeshSource(const Self&);
00147 void operator=(const Self&);
00148
00149 typedef typename InputImageType::SizeType InputImageSizeType;
00150
00151 void CreateMesh();
00152 void XFlip ( unsigned char *tp );
00153 void YFlip ( unsigned char *tp );
00154 void ZFlip ( unsigned char *tp );
00155 void XRotation ( unsigned char *tp );
00156 void YRotation ( unsigned char *tp );
00157 void ZRotation ( unsigned char *tp );
00158 void inverse ( unsigned char *tp );
00159 void InitializeLUT();
00160 void AddCells( unsigned char celltype, unsigned char celltran, int index );
00161 void AddNodes( int index, unsigned char *nodesid, unsigned long *globalnodesid, unsigned long **currentrowtmp, unsigned long **currentframetmp );
00162 void CellTransfer( unsigned char *nodesid, unsigned char celltran );
00163 unsigned long SearchThroughLastRow( int index, int start, int end );
00164 unsigned long SearchThroughLastFrame( int index, int start, int end );
00165
00166 unsigned char m_LUT[256][2];
00167
00168 unsigned long m_LastVoxel[14];
00169 unsigned long m_CurrentVoxel[14];
00170
00171 unsigned long **m_LastRow;
00172 unsigned long **m_LastFrame;
00173 unsigned long **m_CurrentRow;
00174 unsigned long **m_CurrentFrame;
00175
00176 unsigned short m_CurrentRowIndex;
00177 unsigned short m_CurrentFrameIndex;
00178 unsigned short m_LastRowNum;
00179 unsigned short m_LastFrameNum;
00180 unsigned short m_CurrentRowNum;
00181 unsigned short m_CurrentFrameNum;
00182 unsigned char m_AvailableNodes[14];
00183
00184 double m_LocationOffset[14][3];
00185
00186 unsigned long m_NumberOfNodes;
00187 unsigned long m_NumberOfCells;
00188 int m_NodeLimit;
00189 int m_CellLimit;
00190 int m_ImageWidth;
00191 int m_ImageHeight;
00192 int m_ImageDepth;
00193 int m_ColFlag;
00194 int m_RowFlag;
00195 int m_FrameFlag;
00196 int m_LastRowIndex;
00197 int m_LastVoxelIndex;
00198 int m_LastFrameIndex;
00199 unsigned char m_PointFound;
00200 InputPixelType m_ObjectValue;
00201 };
00202
00203 }
00204
00205 #ifndef ITK_MANUAL_INSTANTIATION
00206 #include "itkBinaryMask3DMeshSource.txx"
00207 #endif
00208
00209 #endif