00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #ifndef __SimplexMeshToTriangleMeshFilter_h
00018 #define __SimplexMeshToTriangleMeshFilter_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
00083 typedef itk::AutomaticTopologyMeshSource<TOutputMesh> AutoMeshSourceType;
00084
00085 typedef typename InputMeshType::CellType SimplexCellType;
00086 typedef itk::PolygonCell<SimplexCellType> SimplexPolygonType;
00087
00088
00089 typedef itk::MapContainer<unsigned long, InputPointType> PointMapType;
00090 typedef typename PointMapType::Pointer PointMapPointer;
00091
00092
00098 class SimplexCellVisitor
00099 {
00100
00101 public:
00102
00106 SimplexCellVisitor()
00107 {
00108 m_CenterMap = PointMapType::New();
00109 }
00110
00114 void Visit(unsigned long cellId, SimplexPolygonType * poly)
00115 {
00116 typedef typename SimplexPolygonType::PointIdIterator PointIdIterator;
00117 PointIdIterator it = poly->PointIdsBegin();
00118 InputPointType center,p;
00119 center.Fill(0);
00121
00122 while ( it != poly->PointIdsEnd() )
00123 {
00124 this->m_Mesh->GetPoint(*it, &p);
00125 center += p.GetVectorFromOrigin();
00126 it++;
00127 }
00128
00129 center[0] /= poly->GetNumberOfPoints();
00130 center[1] /= poly->GetNumberOfPoints();
00131 center[2] /= poly->GetNumberOfPoints();
00132
00133 m_CenterMap->InsertElement(cellId, center);
00134
00135
00136
00137 }
00138
00139 PointMapPointer GetCenterMap()
00140 {
00141 return m_CenterMap;
00142 }
00143
00144 void SetMesh(InputMeshPointer mesh)
00145 {
00146 this->m_Mesh = mesh;
00147 }
00148
00149 protected:
00150 InputMeshPointer m_Mesh;
00151 PointMapPointer m_CenterMap;
00152 };
00153
00154 typedef itk::CellInterfaceVisitorImplementation<InputPixelType,
00155 InputCellTraitsType,
00156 SimplexPolygonType,
00157 SimplexCellVisitor>
00158 SimplexVisitorInterfaceType;
00159
00160 typedef typename SimplexVisitorInterfaceType::Pointer SimplexVisitorInterfacePointer;
00161 typedef typename SimplexCellType::MultiVisitor CellMultiVisitorType;
00162 typedef typename CellMultiVisitorType::Pointer CellMultiVisitorPointer;
00163
00164
00165 protected:
00166
00167 SimplexMeshToTriangleMeshFilter();
00168
00169 ~SimplexMeshToTriangleMeshFilter();
00170
00171 SimplexMeshToTriangleMeshFilter(const Self&) {}
00172
00173 void operator=(const Self&) {}
00174
00175 void PrintSelf(std::ostream& os, Indent indent) const;
00176
00177 virtual void GenerateData();
00178
00179 void Initialize();
00180
00182 void CreateTriangles();
00183
00185 unsigned long FindCellId(unsigned long id1, unsigned long id2, unsigned long id3);
00186
00188 PointMapPointer m_Centers;
00189
00190 };
00191
00192 }
00193
00194 #ifndef ITK_MANUAL_INSTANTIATION
00195 #include "itkSimplexMeshToTriangleMeshFilter.txx"
00196 #endif
00197
00198 #endif //__SimplexMeshToTriangleMeshFilter_h
00199