ITK  4.1.0
Insight Segmentation and Registration Toolkit
itkBinaryMask3DMeshSource.h
Go to the documentation of this file.
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 __itkBinaryMask3DMeshSource_h
00019 #define __itkBinaryMask3DMeshSource_h
00020 
00021 #include "vnl/vnl_matrix_fixed.h"
00022 #include "itkMesh.h"
00023 #include "itkImageToMeshFilter.h"
00024 #include "itkTriangleCell.h"
00025 #include "itkCovariantVector.h"
00026 #include "itkDefaultStaticMeshTraits.h"
00027 #include "itkImageRegionConstIterator.h"
00028 
00029 namespace itk
00030 {
00070 template< class TInputImage, class TOutputMesh >
00071 class ITK_EXPORT BinaryMask3DMeshSource:public ImageToMeshFilter< TInputImage, TOutputMesh >
00072 {
00073 public:
00075   typedef BinaryMask3DMeshSource                        Self;
00076   typedef ImageToMeshFilter< TInputImage, TOutputMesh > Superclass;
00077   typedef SmartPointer< Self >                          Pointer;
00078   typedef SmartPointer< const Self >                    ConstPointer;
00079 
00081   itkNewMacro(Self);
00082 
00084   itkTypeMacro(BinaryMask3DMeshSource, ImageToMeshFilter);
00085 
00087   typedef TOutputMesh                         OutputMeshType;
00088   typedef typename OutputMeshType::MeshTraits OMeshTraits;
00089   typedef typename OutputMeshType::PointType  OPointType;
00090   typedef typename OMeshTraits::PixelType     OPixelType;
00091 
00093   typedef typename OutputMeshType::Pointer                OutputMeshPointer;
00094   typedef typename OutputMeshType::CellTraits             CellTraits;
00095   typedef typename OutputMeshType::PointsContainerPointer PointsContainerPointer;
00096   typedef typename OutputMeshType::PointsContainer        PointsContainer;
00097   typedef typename OutputMeshType::CellsContainerPointer  CellsContainerPointer;
00098   typedef typename OutputMeshType::CellsContainer         CellsContainer;
00099   typedef CovariantVector< double, 2 >                    doubleVector;
00100   typedef CovariantVector< int, 2 >                       intVector;
00101 
00104   typedef CellInterface< OPixelType, CellTraits > TCellInterface;
00105   typedef TriangleCell< TCellInterface >          TriCell;
00106   typedef typename TriCell::SelfAutoPointer       TriCellAutoPointer;
00107 
00109   typedef TInputImage                           InputImageType;
00110   typedef typename InputImageType::Pointer      InputImagePointer;
00111   typedef typename InputImageType::ConstPointer InputImageConstPointer;
00112   typedef typename InputImageType::PixelType    InputPixelType;
00113   typedef typename InputImageType::SpacingType  SpacingType;
00114   typedef typename InputImageType::PointType    OriginType;
00115   typedef typename InputImageType::RegionType   RegionType;
00116   typedef typename InputImageType::SizeType     SizeType;
00117 
00119   typedef typename InputImageType::IndexType           InputImageIndexType;
00120 
00121   typedef ImageRegionConstIterator< InputImageType > InputImageIterator;
00122 
00123   typedef itk::IdentifierType                   IdentifierType;
00124   typedef itk::SizeValueType                    SizeValueType;
00125 
00126   itkSetMacro(ObjectValue, InputPixelType);
00127 
00128   itkGetConstMacro(NumberOfNodes, SizeValueType);
00129   itkGetConstMacro(NumberOfCells, SizeValueType);
00130 
00132   using Superclass::SetInput;
00133   virtual void SetInput(const InputImageType *inputImage);
00134 
00135   void SetRegionOfInterest( const RegionType & iRegion )
00136     {
00137     if( iRegion != m_RegionOfInterest )
00138       {
00139       this->m_RegionOfInterest = iRegion;
00140       this->m_RegionOfInterestProvidedByUser = true;
00141       this->Modified();
00142       }
00143     }
00144 
00145   itkGetConstReferenceMacro(RegionOfInterest, RegionType);
00146 
00147 protected:
00148   BinaryMask3DMeshSource();
00149   ~BinaryMask3DMeshSource();
00150   void PrintSelf(std::ostream & os, Indent indent) const;
00151 
00152   void GenerateData();
00153 
00154 
00155   bool       m_RegionOfInterestProvidedByUser;
00156   RegionType m_RegionOfInterest;
00157 
00158   virtual void GenerateOutputInformation(){}  // do nothing
00159 private:
00160   BinaryMask3DMeshSource(const Self &); //purposely not implemented
00161   void operator=(const Self &);         //purposely not implemented
00162 
00163   typedef typename InputImageType::SizeType InputImageSizeType;
00164 
00165   void CreateMesh();
00166 
00167   void XFlip(unsigned char *tp);     // 7 kinds of transformation
00168 
00169   void YFlip(unsigned char *tp);
00170 
00171   void ZFlip(unsigned char *tp);
00172 
00173   void XRotation(unsigned char *tp);
00174 
00175   void YRotation(unsigned char *tp);
00176 
00177   void ZRotation(unsigned char *tp);
00178 
00179   void inverse(unsigned char *tp);
00180 
00181   void InitializeLUT(); // initialize the look up table before the mesh
00182                         // construction
00183 
00184   void AddCells(unsigned char celltype, unsigned char celltran, int index);
00185 
00186   void AddNodes(int index,
00187                 unsigned char *nodesid,
00188                 IdentifierType *globalnodesid,
00189                 IdentifierType **currentrowtmp,
00190                 IdentifierType **currentframetmp);
00191 
00192   void CellTransfer(unsigned char *nodesid, unsigned char celltran);
00193 
00194   IdentifierType SearchThroughLastRow(int index, int start, int end);
00195 
00196   IdentifierType SearchThroughLastFrame(int index, int start, int end);
00197 
00198   unsigned char m_LUT[256][2]; // the two lookup tables
00199 
00200   IdentifierType m_LastVoxel[14];
00201   IdentifierType m_CurrentVoxel[14];
00202 
00203   IdentifierType **m_LastRow;
00204   IdentifierType **m_LastFrame;
00205   IdentifierType **m_CurrentRow;
00206   IdentifierType **m_CurrentFrame;
00207 
00208   unsigned short m_CurrentRowIndex;
00209   unsigned short m_CurrentFrameIndex;
00210   unsigned short m_LastRowNum;
00211   unsigned short m_LastFrameNum;
00212   unsigned short m_CurrentRowNum;
00213   unsigned short m_CurrentFrameNum;
00214   unsigned char  m_AvailableNodes[14];
00215 
00216   double m_LocationOffset[14][3];
00217 
00218   SizeValueType m_NumberOfNodes;
00219   SizeValueType m_NumberOfCells;
00220 
00221   int m_NodeLimit;
00222   int m_CellLimit;
00223   int m_ImageWidth;
00224   int m_ImageHeight;
00225   int m_ImageDepth;
00226   int m_ColFlag;
00227   int m_RowFlag;
00228   int m_FrameFlag;
00229   int m_LastRowIndex;
00230   int m_LastVoxelIndex;
00231   int m_LastFrameIndex;
00232 
00233   unsigned char  m_PointFound;
00234   InputPixelType m_ObjectValue;
00235 };
00236 } // end namespace itk
00237 
00238 #ifndef ITK_MANUAL_INSTANTIATION
00239 #include "itkBinaryMask3DMeshSource.hxx"
00240 #endif
00241 
00242 #endif
00243