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: 2005/08/14 21:21:28 $
00007 Version:   $Revision: 1.6 $
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 __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     // stores the center for each simplex mesh cell, key is the point id
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);
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           //std::cout << "cellId: " << cellId << "  center = " << center << std::endl; 
00136           }
00137 
00138         PointMapPointer GetCenterMap()
00139           {
00140           return m_CenterMap;
00141           }
00142 
00143         void SetMesh(InputMeshPointer mesh)
00144           {
00145           this->m_Mesh = mesh;
00146           }
00147 
00148       protected:
00149         InputMeshPointer 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 
00168     ~SimplexMeshToTriangleMeshFilter();
00169 
00170     SimplexMeshToTriangleMeshFilter(const Self&) {}
00171 
00172   void operator=(const Self&) {}
00173 
00174   void PrintSelf(std::ostream& os, Indent indent) const;
00175 
00176   virtual void GenerateData();
00177 
00178   void Initialize();
00179 
00181   void CreateTriangles();
00182 
00184   unsigned long FindCellId(unsigned long id1, unsigned long id2, unsigned long id3);
00185 
00187   PointMapPointer m_Centers;
00188 
00189 };
00190 
00191 } //end of namespace
00192 
00193 #ifndef ITK_MANUAL_INSTANTIATION
00194 #include "itkSimplexMeshToTriangleMeshFilter.txx"
00195 #endif
00196 
00197 #endif //__SimplexMeshToTriangleMeshFilter_h

Generated at Thu May 25 00:04:39 2006 for ITK by doxygen 1.3.5 written by Dimitri van Heesch, © 1997-2000