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::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
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 }
00186
00187 #ifndef ITK_MANUAL_INSTANTIATION
00188 #include "itkSimplexMeshToTriangleMeshFilter.txx"
00189 #endif
00190
00191 #endif //__SimplexMeshToTriangleMeshFilter_h
00192