GOFIGURE2  0.9.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
itkvtkPolyDataToitkQuadEdgeMesh.h
Go to the documentation of this file.
1 /*=========================================================================
2  Authors: The GoFigure Dev. Team.
3  at Megason Lab, Systems biology, Harvard Medical school, 2009-11
4 
5  Copyright (c) 2009-11, President and Fellows of Harvard College.
6  All rights reserved.
7 
8  Redistribution and use in source and binary forms, with or without
9  modification, are permitted provided that the following conditions are met:
10 
11  Redistributions of source code must retain the above copyright notice,
12  this list of conditions and the following disclaimer.
13  Redistributions in binary form must reproduce the above copyright notice,
14  this list of conditions and the following disclaimer in the documentation
15  and/or other materials provided with the distribution.
16  Neither the name of the President and Fellows of Harvard College
17  nor the names of its contributors may be used to endorse or promote
18  products derived from this software without specific prior written
19  permission.
20 
21  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
23  THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
24  PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
25  BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
26  OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
27  OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
28  OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
29  WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
30  OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
31  ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 
33 =========================================================================*/
34 
35 #ifndef __vtkPolyDataToitkQuadEdgeMesh_h
36 #define __vtkPolyDataToitkQuadEdgeMesh_h
37 
38 #include "vtkSmartPointer.h"
39 #include "vtkPolyData.h"
40 #include "vtkIdList.h"
41 
42 #include "itkQuadEdgeMesh.h"
43 #include "itkTriangleCell.h"
44 
45 #include "itkObject.h"
46 
47 namespace itk
48 {
49 template< class TMesh >
50 class vtkPolyDataToitkQuadEdgeMesh : public Object
51 {
52 public:
54  typedef Object Superclass;
55  typedef SmartPointer< Self > Pointer;
56  typedef SmartPointer< const Self > ConstPointer;
57 
60 
63 
64  typedef TMesh MeshType;
65  typedef typename MeshType::Pointer MeshPointer;
66  typedef typename MeshType::PointsContainerPointer PointsContainerPointer;
67  typedef typename MeshType::PointIdentifier PointIdentifier;
68  typedef typename MeshType::CellAutoPointer CellAutoPointer;
69  typedef typename MeshType::CellType CellType;
70  typedef typename MeshType::PointType PointType;
71  typedef typename PointType::CoordRepType CoordType;
72 
73  typedef TriangleCell< CellType > TriangleCellType;
74 
75  void SetInput( vtkPolyData* iMesh )
76  {
77  m_PolyData = iMesh;
78  }
79 
80  void Update()
81  {
82  GenerateData();
83  }
84 
86  {
87  return m_OutputMesh.GetPointer();
88  }
89 
90 protected:
92  {
93  m_OutputMesh = MeshType::New();
94  }
95 
97 
98  vtkSmartPointer< vtkPolyData > m_PolyData;
100 
102  {
103  vtkIdType NbOfPoints = m_PolyData->GetNumberOfPoints();
104 
105  if( NbOfPoints == 0 )
106  {
107  itkGenericExceptionMacro( <<"Number Of Points is 0" );
108  }
109 
110  vtkIdType NbOfCells = m_PolyData->GetNumberOfCells();
111 
112  if( NbOfCells == 0 )
113  {
114  itkGenericExceptionMacro( <<"Number Of Cells is 0" );
115  }
116 
117  PointsContainerPointer points = m_OutputMesh->GetPoints();
118  points->Reserve( NbOfPoints );
119 
120  double vtk_p[3];
121  PointType itk_p;
122  unsigned int dim;
123 
124  for( vtkIdType i = 0; i < NbOfPoints; ++i )
125  {
126  m_PolyData->GetPoint( i, vtk_p );
127  for( dim = 0; dim < 3; ++dim )
128  {
129  itk_p[dim] = static_cast< CoordType >( vtk_p[dim] );
130  }
131  m_OutputMesh->SetPoint( i, itk_p );
132  }
133 
134  for( vtkIdType i = 0; i < NbOfCells; ++i )
135  {
136  vtkIdList* cell_list = vtkIdList::New();
137 
138  m_PolyData->GetCellPoints( i, cell_list );
139 
140  CellAutoPointer cell;
141  TriangleCellType *triangleCell = new TriangleCellType;
142  for ( vtkIdType k = 0; k < cell_list->GetNumberOfIds(); ++k )
143  {
144  triangleCell->SetPointId( k, cell_list->GetId( k ) );
145  }
146 
147  cell.TakeOwnership(triangleCell);
148  m_OutputMesh->SetCell(i, cell);
149 
150  cell_list->Delete();
151  }
152  }
153 
154 private:
156  void operator = ( const Self & );
157 };
158 }
159 
160 #endif // __vtkPolyDataToitkQuadEdgeMesh_h
itkTypeMacro(vtkPolyDataToitkQuadEdgeMesh, Object)
MeshType::PointsContainerPointer PointsContainerPointer