ITK  4.0.0
Insight Segmentation and Registration Toolkit
itkDeformableSimplexMesh3DGradientConstraintForceFilter.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 __itkDeformableSimplexMesh3DGradientConstraintForceFilter_h
00019 #define __itkDeformableSimplexMesh3DGradientConstraintForceFilter_h
00020 
00021 #include "itkDeformableSimplexMesh3DFilter.h"
00022 #include "itkMesh.h"
00023 #include "itkConstNeighborhoodIterator.h"
00024 #include "itkCovariantVector.h"
00025 
00026 #include <set>
00027 #include <vector>
00028 namespace itk
00029 {
00030 class ImageVoxel
00031 {
00032 public:
00033   // voxel coordinates
00034   unsigned int m_Vpos[3];
00035   // subvoxel coordinates (in cartesian space)
00036   double m_Spos[3];
00037   // voxel value converted to a double
00038   double m_Value;
00039   // distance from line origin
00040   double m_Distance;
00041   // index
00042   unsigned int m_Index;
00043 
00044   ImageVoxel() {}
00045   ImageVoxel(int *pos, double *subpos, double val, double dist, unsigned int ind)
00046   {
00047     this->m_Vpos[0] = pos[0];
00048     this->m_Vpos[1] = pos[1];
00049     this->m_Vpos[2] = pos[2];
00050     this->m_Spos[0] = subpos[0];
00051     this->m_Spos[1] = subpos[1];
00052     this->m_Spos[2] = subpos[2];
00053     this->m_Value = val;
00054     this->m_Distance = dist;
00055     this->m_Index = ind;
00056   }
00057 
00059   unsigned int GetX(void) const { return m_Vpos[0]; }
00061   unsigned int GetY(void) const { return m_Vpos[1]; }
00063   unsigned int GetZ(void) const { return m_Vpos[2]; }
00065   double GetDistance(void) const { return m_Distance; }
00067   double GetValue(void) const { return m_Value; }
00069 
00071   void SetValue(const double val) { m_Value = val; }
00072 };
00073 
00085 template< class TInputMesh, class TOutputMesh >
00086 class ITK_EXPORT DeformableSimplexMesh3DGradientConstraintForceFilter :
00087   public DeformableSimplexMesh3DFilter< TInputMesh, TOutputMesh >
00088 {
00089 public:
00091   typedef DeformableSimplexMesh3DGradientConstraintForceFilter Self;
00092 
00094   typedef  DeformableSimplexMesh3DFilter< TInputMesh, TOutputMesh > Superclass;
00095 
00097   typedef SmartPointer< Self >       Pointer;
00098   typedef SmartPointer< const Self > ConstPointer;
00099 
00101   itkNewMacro(Self);
00102 
00104   itkTypeMacro(DeformableSimplexMesh3DGradientConstraintForceFilter, DeformableSimplexMesh3DFilter);
00105 
00107   typedef TInputMesh  InputMeshType;
00108   typedef TOutputMesh OutputMeshType;
00109 
00110   typedef typename Superclass::PointType              PointType;
00111   typedef typename Superclass::GradientIndexType      GradientIndexType;
00112   typedef typename Superclass::GradientIndexValueType GradientIndexValueType;
00113   typedef typename Superclass::GradientType           GradientType;
00114   typedef typename Superclass::GradientImageType      GradientImageType;
00115 
00116   /* Mesh pointer definition. */
00117   typedef typename InputMeshType::Pointer  InputMeshPointer;
00118   typedef typename OutputMeshType::Pointer OutputMeshPointer;
00119 
00120   typedef typename InputMeshType::PixelType PixelType;
00121 
00122   typedef Image< PixelType, 3 >                        GradientIntensityImageType;
00123   typedef typename GradientIntensityImageType::Pointer GradientIntensityImagePointer;
00124 
00125   typedef Image< float, 3 >                               OriginalImageType;
00126   typedef typename OriginalImageType::IndexType           OriginalImageIndexType;
00127   typedef typename OriginalImageIndexType::IndexValueType ImageIndexValueType;
00128   typedef typename OriginalImageType::ConstPointer        OriginalImagePointer;
00129 
00131   itkSetMacro(Range, int);
00132   itkGetConstMacro(Range, int);
00134 
00135   // full segment or half segment direction
00136   enum SIDE {
00137     // half segment in direction
00138     NORMAL,
00139     // half segment in -direction
00140     INVERSE,
00141     // complete segment
00142     BOTH
00143     };
00144 
00148   itkSetConstObjectMacro(Image, OriginalImageType);
00149 protected:
00150   DeformableSimplexMesh3DGradientConstraintForceFilter();
00151   ~DeformableSimplexMesh3DGradientConstraintForceFilter();
00152   DeformableSimplexMesh3DGradientConstraintForceFilter(const Self &) {}
00153   void operator=(const Self &){}
00154   void PrintSelf(std::ostream & os, Indent indent) const;
00156 
00160   virtual void ComputeExternalForce(SimplexMeshGeometry *data);
00161 
00165   int m_Range;
00166 private:
00167   double NextVoxel(const double *pp, int *ic, double *x, double *y, double *z);
00169 
00170   int Signi(double a);
00171 
00172   void Clear();
00173 
00174   // line starting voxel
00175   ImageVoxel *m_StartVoxel;
00176   // line voxels in direction
00177   std::vector< ImageVoxel * > m_Positive;
00178   // line voxels in -direction
00179   std::vector< ImageVoxel * > m_Negative;
00180 
00181   OriginalImagePointer m_Image;
00182 }; // end of class
00183 } // namespace itk
00184 
00185 #ifndef ITK_MANUAL_INSTANTIATION
00186 #include "itkDeformableSimplexMesh3DGradientConstraintForceFilter.hxx"
00187 #endif
00188 
00189 #endif /* __DeformableSimplexMesh3DGradientConstraintForceFilter_h */
00190