3D Human Airway Tree
Program generuje ludzkie drzewo oskrzelowe
ObjectConnector.hpp
Idź do dokumentacji tego pliku.
1 /*
2  <one line to give the program's name and a brief idea of what it does.>
3  Copyright (C) 2011 Kacper Pluta <kacperp@wsinf.edu.pl>
4 
5  This program is free software; you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation; either version 2 of the License, or
8  (at your option) any later version.
9 
10  This program is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU General Public License for more details.
14 
15  You should have received a copy of the GNU General Public License along
16  with this program; if not, write to the Free Software Foundation, Inc.,
17  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 */
19 
20 
21 #ifndef OBJECTCONNECTOR_H
22 #define OBJECTCONNECTOR_H
23 
24 #include <vtkPolyData.h>
25 #include <vtkTriangleFilter.h>
27 
28 namespace meta
29 {
30  namespace helpers
31  {
32  template<typename T>
33  vtkPolyData* Connect(T &e0, T &e1, T &e2)
34  {
35  vtkTriangleFilter *tf0 = vtkTriangleFilter::New();
36  tf0->ReleaseDataFlagOn();
37  tf0->PassVertsOff();
38  tf0->PassLinesOff();
39  tf0->SetInputConnection(e0.GetOutputPort());
40 
41  vtkTriangleFilter *tf1 = vtkTriangleFilter::New();
42  tf1->ReleaseDataFlagOn();
43  tf1->PassVertsOff();
44  tf1->PassLinesOff();
45  tf1->SetInputConnection(e1.GetOutputPort());
46 
47  vtkTriangleFilter *tf2 = vtkTriangleFilter::New();
48  tf2->ReleaseDataFlagOn();
49  tf2->PassVertsOff();
50  tf2->PassLinesOff();
51  tf2->SetInputConnection(e2->GetOutputPort());
52 
54  b1->ReleaseDataFlagOn();
55  b1->SetOperationToUnion();
56  b1->AddInputConnection(0,tf0->GetOutputPort());
57  b1->AddInputConnection(1,tf1->GetOutputPort());
58 
59  b1->Update();
60 
62  b2->ReleaseDataFlagOn();
63  b2->SetOperationToUnion();
64  b2->AddInputConnection(1,b1->GetOutputPort());
65  b2->AddInputConnection(0,tf2->GetOutputPort());
66 
67  b2->Update();
68 
69  tf0->Delete();
70  tf1->Delete();
71  tf2->Delete();
72  b1->Delete();
73 
74  vtkPolyData *tmp = b2->GetOutput();
75 
76  return tmp;
77  }
78 
79  template<class T, class P>
80  vtkPolyData* Connect(T &e0, T &e1, P &e2)
81  {
82  vtkTriangleFilter *tf0 = vtkTriangleFilter::New();
83  tf0->ReleaseDataFlagOn();
84  tf0->PassVertsOff();
85  tf0->PassLinesOff();
86  tf0->SetInput(e0.GetOutput());
87 
88  vtkTriangleFilter *tf1 = vtkTriangleFilter::New();
89  tf1->ReleaseDataFlagOn();
90  tf1->PassVertsOff();
91  tf1->PassLinesOff();
92  tf1->SetInput(e1.GetOutput());
93 
94  vtkTriangleFilter *tf2 = vtkTriangleFilter::New();
95  tf2->ReleaseDataFlagOn();
96  tf2->PassVertsOff();
97  tf2->PassLinesOff();
98  tf2->SetInputConnection(e2->GetOutputPort());
99 
101  b1->ReleaseDataFlagOn();
102  b1->SetOperationToUnion();
103  b1->AddInputConnection(0,tf0->GetOutputPort());
104  b1->AddInputConnection(1,tf1->GetOutputPort());
105 
106  b1->Update();
107 
109  b2->ReleaseDataFlagOn();
110  b2->SetOperationToUnion();
111  b2->AddInputConnection(1,b1->GetOutputPort());
112  b2->AddInputConnection(0,tf2->GetOutputPort());
113 
114  b2->Update();
115 
116  tf0->Delete();
117  tf1->Delete();
118  tf2->Delete();
119  b1->Delete();
120 
121  return b2->GetOutput();
122  }
123  template<class T, class P>
124  vtkPolyData* Connect(T &e0, T &e1, P *e2)
125  {
126  vtkTriangleFilter *tf0 = vtkTriangleFilter::New();
127  tf0->ReleaseDataFlagOn();
128  tf0->PassVertsOff();
129  tf0->PassLinesOff();
130  tf0->SetInputConnection(e0->GetOutputPort());
131 
132  vtkTriangleFilter *tf1 = vtkTriangleFilter::New();
133  tf1->ReleaseDataFlagOn();
134  tf1->PassVertsOff();
135  tf1->PassLinesOff();
136  tf1->SetInputConnection(e1->GetOutputPort());
137 
138  vtkTriangleFilter *tf2 = vtkTriangleFilter::New();
139  tf2->ReleaseDataFlagOn();
140  tf2->PassVertsOff();
141  tf2->PassLinesOff();
142  tf2->SetInput(e2);
143 
145  b1->ReleaseDataFlagOn();
146  b1->SetOperationToUnion();
147  b1->AddInputConnection(0,tf0->GetOutputPort());
148  b1->AddInputConnection(1,tf1->GetOutputPort());
149 
150  b1->Update();
151 
153  b2->ReleaseDataFlagOn();
154  b2->SetOperationToUnion();
155  b2->AddInputConnection(1,b1->GetOutputPort());
156  b2->AddInputConnection(0,tf2->GetOutputPort());
157 
158  b2->Update();
159 
160  tf0->Delete();
161  tf1->Delete();
162  tf2->Delete();
163  b1->Delete();
164 
165  return b2->GetOutput();
166  }
167  }
168 }
169 
170 #endif // OBJECTCONNECTOR_H