itkSimplexMeshToTriangleMeshFilter.h
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
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 ITK_EXPORT 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::ConstPointer InputMeshConstPointer;
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
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;
00118 center.Fill(0);
00120
00121 InputPointType p;
00122 p.Fill(0);
00123
00124 while ( it != poly->PointIdsEnd() )
00125 {
00126 this->m_Mesh->GetPoint(*it, &p);
00127 center += p.GetVectorFromOrigin();
00128 it++;
00129 }
00130
00131 center[0] /= poly->GetNumberOfPoints();
00132 center[1] /= poly->GetNumberOfPoints();
00133 center[2] /= poly->GetNumberOfPoints();
00134
00135 m_CenterMap->InsertElement(cellId, center);
00136 }
00137
00138 PointMapPointer GetCenterMap()
00139 {
00140 return m_CenterMap;
00141 }
00142
00143 void SetMesh( const InputMeshType * mesh)
00144 {
00145 this->m_Mesh = mesh;
00146 }
00147
00148 protected:
00149 InputMeshConstPointer m_Mesh;
00150 PointMapPointer m_CenterMap;
00151 };
00152
00153 typedef itk::CellInterfaceVisitorImplementation<InputPixelType,
00154 InputCellTraitsType,
00155 SimplexPolygonType,
00156 SimplexCellVisitor>
00157 SimplexVisitorInterfaceType;
00158
00159 typedef typename SimplexVisitorInterfaceType::Pointer SimplexVisitorInterfacePointer;
00160 typedef typename SimplexCellType::MultiVisitor CellMultiVisitorType;
00161 typedef typename CellMultiVisitorType::Pointer CellMultiVisitorPointer;
00162
00163
00164 protected:
00165
00166 SimplexMeshToTriangleMeshFilter();
00167 ~SimplexMeshToTriangleMeshFilter();
00168 SimplexMeshToTriangleMeshFilter(const Self&) {}
00169 void operator=(const Self&) {}
00170
00171 void PrintSelf(std::ostream& os, Indent indent) const;
00172
00173 virtual void GenerateData();
00174
00175 void Initialize();
00176
00178 void CreateTriangles();
00179
00181 unsigned long FindCellId(unsigned long id1, unsigned long id2, unsigned long id3);
00182
00184 PointMapPointer m_Centers;
00185
00186 };
00187
00188 }
00189
00190 #ifndef ITK_MANUAL_INSTANTIATION
00191 #include "itkSimplexMeshToTriangleMeshFilter.txx"
00192 #endif
00193
00194 #endif //__SimplexMeshToTriangleMeshFilter_h
00195