Main Page   Groups   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Concepts

itkSimplexMeshAdaptTopologyFilter.h

Go to the documentation of this file.
00001 /*=========================================================================
00002 
00003 Program:   Insight Segmentation & Registration Toolkit
00004 Module:    $RCSfile: itkSimplexMeshAdaptTopologyFilter.h,v $
00005 Language:  C++
00006 Date:      $Date: 2006/02/05 20:57:46 $
00007 Version:   $Revision: 1.10 $
00008 
00009 Copyright (c) Insight Software Consortium. All rights reserved.
00010 See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details.
00011 
00012 This software is distributed WITHOUT ANY WARRANTY; without even 
00013 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
00014 PURPOSE.  See the above copyright notices for more information.
00015 
00016 =========================================================================*/
00017 #ifndef __itkSimplexMeshAdaptTopologyFilter_h
00018 #define __itkSimplexMeshAdaptTopologyFilter_h
00019 
00020 #include "itkMesh.h"
00021 #include "itkPolygonCell.h"
00022 #include "itkMapContainer.h"
00023 #include "itkCellInterfaceVisitor.h"
00024 
00025 #include "itkSimplexMesh.h"
00026 #include "itkSimplexMeshGeometry.h"
00027 #include "itkMeshToMeshFilter.h"
00028 #include "itkVectorContainer.h"
00029 
00030 #include <vxl_version.h>
00031 #if VXL_VERSION_DATE_FULL > 20040406
00032 # include <vnl/vnl_cross.h>
00033 # define itk_cross_3d vnl_cross_3d
00034 #else
00035 # define itk_cross_3d cross_3d
00036 #endif
00037 
00038 namespace itk
00039   {
00050   template <class TInputMesh, class TOutputMesh>
00051 class SimplexMeshAdaptTopologyFilter : public MeshToMeshFilter<TInputMesh, TOutputMesh>
00052   {
00053 
00054   public:
00056     typedef SimplexMeshAdaptTopologyFilter Self;
00057 
00059     typedef MeshToMeshFilter<TInputMesh, TOutputMesh> Superclass;
00060 
00062     typedef SmartPointer<Self>  Pointer;
00063 
00065     typedef SmartPointer<const Self>  ConstPointer;
00066 
00068     itkNewMacro(Self);
00069 
00071     itkTypeMacro(SimplexMeshAdaptTopologyFilter,MeshToMeshFilter);
00072 
00073     typedef TInputMesh                                              InputMeshType;
00074     typedef typename InputMeshType::Pointer                         InputMeshPointer;
00075     typedef typename InputMeshType::PointType                       InputPointType;
00076     typedef typename InputMeshType::VectorType                      InputVectorType;
00077     typedef typename InputMeshType::PixelType                       InputPixelType;
00078     typedef typename InputMeshType::MeshTraits::CellTraits          InputCellTraitsType;
00079     typedef typename InputMeshType::CellType                        InputCellType;
00080     typedef typename InputCellType::PointIdIterator                 InputCellPointIdIterator;
00081     typedef typename InputCellType::CellAutoPointer                 InputCellAutoPointer;
00082     typedef typename InputMeshType::CellAutoPointer                 CellAutoPointer;
00083     typedef          itk::PolygonCell<InputCellType>                InputPolygonType;
00084     typedef typename InputPolygonType::PointIdIterator              InputPolygonPointIdIterator;
00085 
00086 
00087     typedef  TOutputMesh                                            OutputMeshType;
00088     typedef typename OutputMeshType::Pointer                        OutputMeshPointer;
00089     typedef typename OutputMeshType::CellType                       OutputCellType;
00090     typedef          itk::PolygonCell<OutputCellType>               OutputPolygonType;
00091 
00092     typedef          itk::MapContainer<unsigned long, double>       DoubleValueMapType;
00093     typedef typename DoubleValueMapType::Iterator                   DoubleContainerIterator;
00094 
00095 
00102     class SimplexCellVisitor
00103       {
00104 
00105       public:
00106         InputMeshPointer mesh;
00107         double totalArea;
00108         double totalCurvature;
00109         double minCellSize;
00110         double maxCellSize;
00111         DoubleValueMapType::Pointer areaMap;
00112         DoubleValueMapType::Pointer curvatureMap;
00113 
00114         double minCurvature;
00115         double maxCurvature;
00116 
00117         SimplexCellVisitor()
00118           {
00119           areaMap = DoubleValueMapType::New();
00120           curvatureMap = DoubleValueMapType::New();
00121           totalArea = 0;
00122           totalCurvature = 0;
00123           minCellSize = NumericTraits<double>::max();
00124           maxCellSize = 0;
00125           minCurvature = NumericTraits<double>::max();
00126           maxCurvature = 0;
00127           }
00128 
00129 
00133         void Visit(unsigned long cellId, InputPolygonType * poly)
00134           {
00135           typename InputPolygonType::PointIdIterator it =  poly->PointIdsBegin();
00136 
00137           double meanCurvature = 0;
00138           unsigned long refPoint = *it;
00139           double val = mesh->GetMeanCurvature(*it++);
00140           meanCurvature += vcl_abs(val);
00141 
00142           unsigned long id1 = *it;
00143           val = mesh->GetMeanCurvature(*it++);
00144           meanCurvature += vcl_abs(val);
00145 
00146           unsigned long id2;
00147 
00148           double area = 0;
00149 
00150           int cnt = 0; 
00151 
00152           while ( it != poly->PointIdsEnd() )
00153             {
00154             id2 = *it;
00155             area += ComputeArea(refPoint,id1,id2);
00156             id1 = id2;
00157             val = mesh->GetMeanCurvature(*it);
00158             meanCurvature += vcl_abs(val);
00159             cnt++;
00160             it++;
00161             }
00162 
00163           meanCurvature /= (double)cnt;
00164           totalArea += area;
00165           totalCurvature += meanCurvature;
00166 
00167           areaMap->InsertElement(cellId, area);
00168           curvatureMap->InsertElement(cellId, meanCurvature);
00169 
00170           if (area > maxCellSize ) maxCellSize = area;
00171           if (area < minCellSize ) minCellSize = area;
00172           if (meanCurvature > maxCurvature ) maxCurvature = meanCurvature;
00173           if (meanCurvature < minCurvature ) minCurvature = meanCurvature;
00174           }
00175 
00176         double ComputeArea(unsigned long p1,unsigned long p2, unsigned long p3)
00177           {
00178           InputPointType v1,v2,v3;
00179           mesh->GetPoint(p1, &v1);
00180           mesh->GetPoint(p2, &v2);
00181           mesh->GetPoint(p3, &v3);
00182           return vcl_abs (itk_cross_3d((v2-v1).GetVnlVector(), (v3-v1).GetVnlVector()).two_norm() /2.0);
00183           }
00184 
00185         DoubleValueMapType::Pointer GetAreaMap()
00186           {
00187           return areaMap;
00188           }
00189 
00190         DoubleValueMapType::Pointer GetCurvatureMap()
00191           {
00192           return curvatureMap;
00193           }
00194 
00195         double GetTotalMeshArea()
00196           {
00197           return totalArea;
00198           }
00199 
00200         double GetTotalMeanCurvature()
00201           {
00202           return totalCurvature/(curvatureMap->Size());
00203           }
00204 
00205         double GetMaximumCellSize()
00206           {
00207           return maxCellSize;
00208           }
00209 
00210         double GetMinimumCellSize()
00211           {
00212           return minCellSize;
00213           }
00214         double GetMaximumCurvature()
00215           {
00216           return maxCurvature;
00217           }
00218 
00219         double GetMinimumCurvature()
00220           {
00221           return minCurvature;
00222           }
00223 
00224       };
00225 
00226     // cell visitor stuff
00227     typedef itk::CellInterfaceVisitorImplementation<InputPixelType,
00228       InputCellTraitsType,
00229       InputPolygonType,
00230       SimplexCellVisitor>
00231       SimplexVisitorInterfaceType;
00232 
00233     typedef typename SimplexVisitorInterfaceType::Pointer   SimplexVisitorInterfacePointer;
00234     typedef typename InputCellType::MultiVisitor            CellMultiVisitorType;
00235     typedef typename CellMultiVisitorType::Pointer          CellMultiVisitorPointer;
00236 
00237 
00238     itkSetMacro(Threshold, double);
00239     itkGetMacro(Threshold, double);
00240 
00241     itkSetMacro(SelectionMethod, int);
00242     itkGetMacro(SelectionMethod, int);
00243 
00244     itkGetMacro(ModifiedCount, int);
00245 
00246 
00247   protected:
00248 
00249     SimplexMeshAdaptTopologyFilter();
00250 
00251     ~SimplexMeshAdaptTopologyFilter();
00252 
00253     SimplexMeshAdaptTopologyFilter(const Self&) 
00254       {
00255       }
00256 
00257     void operator=(const Self&)
00258       {
00259       }
00260 
00261     void PrintSelf(std::ostream& os, Indent indent) const;
00262 
00263     virtual void GenerateData();
00264 
00265 
00269     void Initialize();
00270 
00276     void ComputeCellParameters();
00277 
00281     void InsertNewCells();
00282 
00288     void ModifyNeighborCells(unsigned long id1, unsigned long id2, unsigned long insertPointId);
00289 
00290 
00294     InputPointType ComputeCellCenter(InputCellAutoPointer &simplexCell);
00295 
00296 
00300     unsigned long m_IdOffset;
00301 
00302 
00307     double m_Threshold;
00308 
00312     int  m_SelectionMethod;
00313 
00318     int m_ModifiedCount;
00319 
00324     OutputMeshPointer m_Output;
00325 
00326     InputCellAutoPointer  NewSimplexCellPointer;
00327 
00328   };
00329 
00330   } //end of namespace
00331 
00332 #ifndef ITK_MANUAL_INSTANTIATION
00333 #include "itkSimplexMeshAdaptTopologyFilter.txx"
00334 #endif
00335 
00336 #endif // __itkSimplexMeshAdaptTopologyFilter_h
00337 
00338 

Generated at Fri Sep 8 04:08:04 2006 for ITK by doxygen 1.4.7 written by Dimitri van Heesch, © 1997-2000