ITK  4.1.0
Insight Segmentation and Registration Toolkit
itkBalloonForceFilter.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 __itkBalloonForceFilter_h
00019 #define __itkBalloonForceFilter_h
00020 
00021 #include "itkMeshToMeshFilter.h"
00022 #include "vnl/vnl_matrix_fixed.h"
00023 #include "vnl/vnl_math.h"
00024 #include "itkMesh.h"
00025 #include "itkTriangleCell.h"
00026 #include "itkImage.h"
00027 #include "itkImageRegionIterator.h"
00028 #include <itkCovariantVector.h>
00029 
00030 namespace itk
00031 {
00055 template< class TInputMesh, class TOutputMesh >
00056 class ITK_EXPORT BalloonForceFilter:public MeshToMeshFilter< TInputMesh, TOutputMesh >
00057 {
00058 public:
00060   typedef BalloonForceFilter                          Self;
00061   typedef MeshToMeshFilter< TInputMesh, TOutputMesh > Superclass;
00062   typedef SmartPointer< Self >                        Pointer;
00063   typedef SmartPointer< const Self >                  ConstPointer;
00064 
00066   itkNewMacro(Self);
00067 
00069   itkTypeMacro(BalloonForceFilter, MeshToMeshFilter);
00070 
00072   typedef TInputMesh  InputMeshType;
00073   typedef TOutputMesh OutputMeshType;
00074 
00076   typedef typename InputMeshType::PointsContainerPointer
00077   InputPointsContainerPointer;
00078   typedef typename InputMeshType::PointsContainer::Iterator
00079   InputPointsContainerIterator;
00080   typedef typename InputMeshType::PointsContainerConstPointer
00081   InputPointsContainerConstPointer;
00082   typedef typename InputMeshType::PointsContainer::ConstIterator
00083   InputPointsContainerConstIterator;
00084   typedef typename InputMeshType::PointDataContainerPointer
00085   InputPointDataContainerPointer;
00086   typedef typename InputMeshType::PointDataContainer::Iterator
00087   InputPointDataContainerIterator;
00088   typedef typename InputMeshType::CellsContainerPointer
00089   InputCellsContainerPointer;
00090   typedef typename InputMeshType::CellsContainer::Iterator
00091   InputCellsContainerIterator;
00092   typedef typename InputMeshType::CellDataContainerPointer
00093   InputCellDataContainerPointer;
00094   typedef typename InputMeshType::CellDataContainer::Iterator
00095   InputCellDataContainerIterator;
00096   typedef typename InputMeshType::CellsContainerConstPointer
00097   InputCellsContainerConstPointer;
00098   typedef typename InputMeshType::CellsContainer::ConstIterator
00099   InputCellsContainerConstIterator;
00100   typedef typename InputMeshType::CellDataContainerConstPointer
00101   InputCellDataContainerConstPointer;
00102   typedef typename InputMeshType::CellDataContainer::ConstIterator
00103   InputCellDataContainerConstIterator;
00104 
00105   typedef typename OutputMeshType::PointsContainerPointer
00106   OutputPointsContainerPointer;
00107   typedef typename OutputMeshType::PointsContainer::Iterator
00108   OutputPointsContainerIterator;
00109 
00111   typedef typename InputMeshType::PointType IPixelType;
00112   typedef typename InputMeshType::PixelType PixelType;
00113 
00114   typedef Image< unsigned short, 2 >            ImageType;
00115   typedef CovariantVector< PixelType, 2 >       GradientType;
00116   typedef Image< GradientType, 2 >              GradientImageType;
00117   typedef typename InputMeshType::Pointer       InputMeshPointer;
00118   typedef typename InputMeshType::ConstPointer  InputMeshConstPointer;
00119   typedef typename OutputMeshType::Pointer      OutputMeshPointer;
00120   typedef typename ImageType::Pointer           ImagePointer;
00121   typedef typename ImageType::IndexType         IndexType;
00122   typedef typename GradientImageType::Pointer   GradientImagePointer;
00123   typedef typename GradientImageType::IndexType GradientIndexType;
00124   typedef ImageRegionIterator< ImageType >      ImageIterator;
00125   typedef Vector< float, 3 >                    FloatVector;
00126   typedef Vector< int, 3 >                      IntVector;
00127   typedef Vector< double, 2 >                   Double2Vector;
00128   typedef Vector< int, 2 >                      Int2Vector;
00129 
00131   typedef typename InputMeshType::CellType             CellType;
00132   typedef typename InputMeshType::CellTraits           CellTraits;
00133   typedef::itk::CellInterface< PixelType, CellTraits > CellInterface;
00134   typedef::itk::TriangleCell< CellInterface >          TriCell;
00135 
00137   void ComputeForce();
00138 
00139   void Initialize();
00140 
00141   void SetStiffnessMatrix();
00142 
00143   void Advance();             // update data for next iteration
00144 
00145   void Reset();               // reset all data
00146 
00147   void ComputeDt();             // compute point positions
00148 
00149   void ComputeOutput();
00150 
00151   void NodeAddition(int i, int res, IPixelType z); // (folowing 3) for adding
00152                                                    // new nodes, now disabled
00153                                                    // for further tests
00154 
00155   void NodesRearrange();
00156 
00157   void GapSearch();
00158 
00159   void GradientFit();           // fit the model with gradient information
00160 
00161   void ComputeNormals();
00162 
00163   void ACDSearch();             // remove weird structures on the model surface
00164 
00166   itkSetMacro(ImageOutput, ImagePointer);
00167   itkGetConstMacro(ImageOutput, ImagePointer);
00168   itkSetMacro(Gradient, GradientImagePointer);
00170 
00172   itkSetMacro(Stiffness, Double2Vector);
00173   itkSetMacro(TimeStep, double);
00174   itkSetMacro(GradientBegin, int);
00175   itkSetMacro(Resolution, int);
00176   itkSetMacro(Center, IndexType);
00177   itkGetConstMacro(Normals, InputMeshPointer);
00178   itkSetMacro(DistanceForGradient, float);
00179   itkSetMacro(DistanceToStop, float);
00180   itkSetMacro(Potential, ImagePointer);
00181   itkGetConstMacro(Locations, InputMeshPointer);
00182   itkGetConstMacro(Displacements, InputMeshPointer);
00183   itkGetConstMacro(Derives, InputMeshPointer);
00184   itkGetConstMacro(Forces, InputMeshPointer);
00185 protected:
00186   BalloonForceFilter();
00187   ~BalloonForceFilter();
00188   void PrintSelf(std::ostream & os, Indent indent) const;
00190 
00191   virtual void GenerateData();
00192 
00193 private:
00194   BalloonForceFilter(const Self &); //purposely not implemented
00195   void operator=(const Self &);     //purposely not implemented
00196 
00198   InputMeshPointer  m_Forces;
00199   InputMeshPointer  m_Normals;
00200   InputMeshPointer  m_Displacements;
00201   InputMeshPointer  m_Derives;
00202   InputMeshPointer  m_Locations;
00203   InputMeshPointer  m_Input;
00204   OutputMeshPointer m_Output;
00205 
00207   vnl_matrix_fixed< double, 4, 4 >   m_NStiffness;
00208   vnl_matrix_fixed< double, 4, 4 >   m_SStiffness;
00209   vnl_matrix_fixed< double, 4, 4 >   m_CStiffness;
00210   vnl_matrix_fixed< double, 4, 4 > **m_K;
00211 
00212   Double2Vector m_Stiffness;
00213   double        m_TimeStep;        // the time step of each iteration
00214   int           m_Resolution;
00215   IndexType     m_Center;
00216   float         m_MiniT;         // variabel help to stop the model when near
00217                                  // potential estimation
00218   int           m_Step;          // the number of iteration
00219 
00220   unsigned int m_NumberOfNodes;
00221   unsigned int m_NumberOfCells;
00222   unsigned int m_NumNewNodes;        // for adding new nodes, now disabled for
00223                                      // further tests
00224   int *        m_GapLocations;
00225   float **     m_NewNodes;
00226   int          m_NewNodesExisted;
00227   unsigned int m_NewNodeLimit;
00228   unsigned int m_ImageWidth;         // input image size
00229   unsigned int m_ImageHeight;
00230   unsigned int m_ImageDepth;
00231 
00232   int   m_ModelXUpLimit;    // the following 4 variables record the size of the
00233                             // model
00234   int   m_ModelXDownLimit;
00235   int   m_ModelYUpLimit;
00236   int   m_ModelYDownLimit;
00237   int **m_ACD;        // help to remove the weird structure on the model surface
00238   int   m_ModelRestart;
00239   int   m_GradientBegin;
00240 
00241   Int2Vector m_StepThreshold;     // the threshold decide when to transfer from
00242                                   // potential fit to gradient fit
00243 
00244   // and the threshold decide when to stop the model
00245   float m_DistanceToBoundary;
00246   float m_DistanceToStop;
00247   float m_DistanceForGradient;
00248 
00249   ImagePointer         m_Potential;     // for calculate of image force from
00250                                         // potential
00251   GradientImagePointer m_Gradient;      // for calculate of image force from
00252                                         // gradient
00253 
00254   // for Gibbs Prior Model parameters' recalculation
00255   ImagePointer   m_ImageOutput;
00256   unsigned short m_ObjectLabel;
00257 
00258   typedef ImageType::SizeType ImageSizeType;
00259 };
00260 } // end namespace itk
00261 
00262 #ifndef ITK_MANUAL_INSTANTIATION
00263 #include "itkBalloonForceFilter.hxx"
00264 #endif
00265 
00266 #endif
00267