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

itkSimplexMeshToTriangleMeshFilter.h

Go to the documentation of this file.
00001 /*=========================================================================
00002 
00003 Program:   Insight Segmentation & Registration Toolkit
00004 Module:    $RCSfile: itkSimplexMeshToTriangleMeshFilter.h,v $
00005 Language:  C++
00006 Date:      $Date: 2008-10-17 20:49:56 $
00007 Version:   $Revision: 1.7 $
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 __itkSimplexMeshToTriangleMeshFilter_h
00018 #define __itkSimplexMeshToTriangleMeshFilter_h
00019 
00020 #include <itkMesh.h>
00021 #include <itkLineCell.h>
00022 #include <itkPolygonCell.h>
00023 #include <itkVertexCell.h>
00024 #include <itkMapContainer.h>
00025 
00026 #include "itkSimplexMesh.h"
00027 #include "itkMeshToMeshFilter.h"
00028 #include "itkVectorContainer.h"
00029 #include "itkMapContainer.h"
00030 #include "itkAutomaticTopologyMeshSource.h"
00031 
00032 namespace itk
00033 {
00034 
00035 
00047 template <class TInputMesh, class TOutputMesh>
00048 class SimplexMeshToTriangleMeshFilter : public MeshToMeshFilter<TInputMesh, TOutputMesh>
00049 {
00050 
00051 public:
00053   typedef SimplexMeshToTriangleMeshFilter  Self;
00054 
00056   typedef MeshToMeshFilter<TInputMesh, TOutputMesh> Superclass;
00057 
00059   typedef SmartPointer<Self>        Pointer;
00060   typedef SmartPointer<const Self>  ConstPointer;
00061 
00063   itkNewMacro(Self);
00064 
00066   itkTypeMacro(SimplexMeshToTriangleMeshFilter,MeshToMeshFilter);
00067 
00068 
00069   typedef TInputMesh                                     InputMeshType;
00070   typedef typename InputMeshType::Pointer                InputMeshPointer;
00071   typedef typename InputMeshType::PointType              InputPointType;
00072   typedef typename InputMeshType::PixelType              InputPixelType;
00073   typedef typename InputMeshType::MeshTraits::CellTraits InputCellTraitsType;
00074 
00075   typedef typename InputMeshType::PointsContainer        InputPointsContainer;
00076   typedef typename InputPointsContainer::Pointer         InputPointsContainerPointer;
00077   typedef typename InputPointsContainer::Iterator        InputPointsContainerIterator;
00078 
00079   typedef typename InputMeshType::NeighborListType           InputNeighbors;
00080   typedef typename InputMeshType::NeighborListType::iterator InputNeighborsIterator;
00081 
00082   typedef          itk::AutomaticTopologyMeshSource<TOutputMesh>  AutoMeshSourceType;
00083 
00084   typedef typename InputMeshType::CellType                        SimplexCellType;
00085   typedef          itk::PolygonCell<SimplexCellType>              SimplexPolygonType;
00086 
00087   // stores the center for each simplex mesh cell, key is the point id
00088   typedef          itk::MapContainer<unsigned long, InputPointType> PointMapType;
00089   typedef typename PointMapType::Pointer                            PointMapPointer;
00090 
00091   
00097   class SimplexCellVisitor
00098     {
00099 
00100     public:
00101 
00105     SimplexCellVisitor()
00106       {
00107       m_CenterMap = PointMapType::New();
00108       }
00109 
00113     void Visit(unsigned long cellId, SimplexPolygonType * poly)
00114       {
00115       typedef typename SimplexPolygonType::PointIdIterator   PointIdIterator;
00116       PointIdIterator  it =  poly->PointIdsBegin();
00117       InputPointType center,p;
00118       center.Fill(0);
00120 
00121       while ( it != poly->PointIdsEnd() )
00122         {
00123         this->m_Mesh->GetPoint(*it, &p);
00124         center += p.GetVectorFromOrigin();
00125         it++;
00126         }
00127 
00128       center[0] /= poly->GetNumberOfPoints();
00129       center[1] /= poly->GetNumberOfPoints();
00130       center[2] /= poly->GetNumberOfPoints();
00131 
00132       m_CenterMap->InsertElement(cellId, center);
00133       }
00134 
00135     PointMapPointer GetCenterMap()
00136       {
00137       return m_CenterMap;
00138       }
00139 
00140     void SetMesh(InputMeshPointer mesh)
00141       {
00142       this->m_Mesh = mesh;
00143       }
00144 
00145     protected:
00146       InputMeshPointer m_Mesh;
00147       PointMapPointer m_CenterMap; 
00148   };
00149 
00150     typedef itk::CellInterfaceVisitorImplementation<InputPixelType,
00151       InputCellTraitsType,
00152       SimplexPolygonType,
00153       SimplexCellVisitor>
00154       SimplexVisitorInterfaceType;
00155 
00156     typedef typename SimplexVisitorInterfaceType::Pointer  SimplexVisitorInterfacePointer;
00157     typedef typename SimplexCellType::MultiVisitor         CellMultiVisitorType;
00158     typedef typename CellMultiVisitorType::Pointer         CellMultiVisitorPointer;
00159 
00160 
00161 protected:
00162 
00163   SimplexMeshToTriangleMeshFilter();
00164   ~SimplexMeshToTriangleMeshFilter();
00165   SimplexMeshToTriangleMeshFilter(const Self&) {}
00166   void operator=(const Self&) {}
00167 
00168   void PrintSelf(std::ostream& os, Indent indent) const;
00169 
00170   virtual void GenerateData();
00171 
00172   void Initialize();
00173 
00175   void CreateTriangles();
00176 
00178   unsigned long FindCellId(unsigned long id1, unsigned long id2, unsigned long id3);
00179 
00181   PointMapPointer m_Centers;
00182 
00183 };
00184 
00185 } //end of namespace
00186 
00187 #ifndef ITK_MANUAL_INSTANTIATION
00188 #include "itkSimplexMeshToTriangleMeshFilter.txx"
00189 #endif
00190 
00191 #endif //__SimplexMeshToTriangleMeshFilter_h
00192 

Generated at Thu Nov 6 00:14:02 2008 for ITK by doxygen 1.5.1 written by Dimitri van Heesch, © 1997-2000