GOFIGURE2  0.9.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
MeshToContourFilter.cxx
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 #include "MeshToContourFilter.h"
35 
36 #include "vtkPolyData.h"
37 #include "vtkPlane.h"
38 #include "vtkCutter.h"
39 
40 //-----------------------------------------------------------------------------
43  m_Input(NULL)
44 {
45  SetSpacing(0., 0., 0.);
46 }
47 //-----------------------------------------------------------------------------
48 
49 //-----------------------------------------------------------------------------
52 {
53 }
54 //-----------------------------------------------------------------------------
55 
56 //-----------------------------------------------------------------------------
57 void
59 SetInput(vtkPolyData* iInput)
60 {
61  m_Input = iInput;
62 }
63 //-----------------------------------------------------------------------------
64 
65 //-----------------------------------------------------------------------------
66 void
68 SetSpacing(const double& iX, const double & iY, const double& iZ)
69 {
70  m_Spacing[0] = iX;
71  m_Spacing[1] = iY;
72  m_Spacing[2] = iZ;
73 }
74 //-----------------------------------------------------------------------------
75 
76 //-----------------------------------------------------------------------------
77 std::map<double, vtkPolyData *>
80 {
81  std::map<double, vtkPolyData*> contours;
82 
83  // create plane to extract contours (based on orientation)
84  double normal[3] = {0., 0., 0.};
85 
86  switch (iOrientation)
87  {
88  case XY:
89  {
90  normal[2] = 1;
91  break;
92  }
93  case XZ:
94  {
95  normal[1] = 1;
96  break;
97  }
98  case YZ:
99  {
100  normal[0] = 1;
101  break;
102  }
103  default:
104  {
105  break;
106  }
107  }
108 
109  double origin[3] = {0., 0., 0.};
110  origin[0] = m_Input->GetCenter()[0];
111  origin[1] = m_Input->GetCenter()[1];
112  origin[2] = m_Input->GetCenter()[2];
113 
114  double position = m_Input->GetBounds()[4 - 2*iOrientation];
115  double maxPosition = m_Input->GetBounds()[5 - 2*iOrientation];
116  double spacing = this->m_Spacing[2-iOrientation];
117 
118  while( position < maxPosition)
119  {
120  origin[2-iOrientation] = position;
121 
122  vtkPlane* plane = vtkPlane::New();
123  plane->SetNormal(normal);
124  plane->SetOrigin(origin);
125 
126  // cut
127  vtkCutter* cutter = vtkCutter::New();
128  cutter->SetInput(m_Input);
129  cutter->SetCutFunction(plane);
130  cutter->Update();
131 
132  vtkPolyData* polydata = vtkPolyData::New();
133  polydata->DeepCopy( cutter->GetOutput() );
134 
135  plane->Delete();
136  cutter->Delete();
137 
138  contours[position] = polydata;
139 
140  // increase position
141  position += spacing;
142  }
143 
144  return contours;
145 }
146 //-----------------------------------------------------------------------------
void SetSpacing(const double &iX, const double &iY, const double &iZ)
Set spacing of the original image to know how many slices to extract.
void SetInput(vtkPolyData *iInput)
Set polydata to be splitted.
std::map< double, vtkPolyData * > ExtractPolyData(ORIENTATION iOrientation)
Extract contours from polydata given an orientation.