VMTK
Loading...
Searching...
No Matches
vtkvmtkPolyDataCenterlineMetricFilter.cxx
Go to the documentation of this file.
1/*=========================================================================
2
3 Program: VMTK
4 Module: $RCSfile: vtkvmtkPolyDataCenterlineMetricFilter.cxx,v $
5 Language: C++
6 Date: $Date: 2005/03/31 15:07:48 $
7 Version: $Revision: 1.6 $
8
9 Copyright (c) Luca Antiga, David Steinman. All rights reserved.
10 See LICENSE file for details.
11
12 Portions of this code are covered under the VTK copyright.
13 See VTKCopyright.txt or http://www.kitware.com/VTKCopyright.htm
14 for details.
15
16 This software is distributed WITHOUT ANY WARRANTY; without even
17 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
18 PURPOSE. See the above copyright notices for more information.
19
20=========================================================================*/
21
23#include "vtkPointData.h"
24#include "vtkCellData.h"
25#include "vtkDoubleArray.h"
26#include "vtkvmtkPolyBallLine.h"
27#include "vtkCell.h"
28#include "vtkInformation.h"
29#include "vtkInformationVector.h"
30#include "vtkObjectFactory.h"
31
32
33
35{
36 this->MetricArrayName = NULL;
37 this->BlankingArrayName = NULL;
38
39 this->GroupIdsArrayName = NULL;
40
41 this->Centerlines = NULL;
42
43 this->RadiusArrayName = NULL;
44 this->CenterlineGroupIdsArrayName = NULL;
45 this->CenterlineIdsArrayName = NULL;
46 this->CenterlineTractIdsArrayName = NULL;
47
48 this->UseRadiusInformation = 1;
49 this->IncludeBifurcations = 1;
50}
51
53{
54 if (this->MetricArrayName)
55 {
56 delete[] this->MetricArrayName;
57 this->MetricArrayName = NULL;
58 }
59
60 if (this->GroupIdsArrayName)
61 {
62 delete[] this->GroupIdsArrayName;
63 this->GroupIdsArrayName = NULL;
64 }
65
66 if (this->Centerlines)
67 {
68 this->Centerlines->Delete();
69 this->Centerlines = NULL;
70 }
71
72 if (this->RadiusArrayName)
73 {
74 delete[] this->RadiusArrayName;
75 this->RadiusArrayName = NULL;
76 }
77
78 if (this->BlankingArrayName)
79 {
80 delete[] this->BlankingArrayName;
81 this->BlankingArrayName = NULL;
82 }
83
85 {
86 delete[] this->CenterlineGroupIdsArrayName;
87 this->CenterlineGroupIdsArrayName = NULL;
88 }
89
91 {
92 delete[] this->CenterlineGroupIdsArrayName;
93 this->CenterlineGroupIdsArrayName = NULL;
94 }
95
96 if (this->CenterlineIdsArrayName)
97 {
98 delete[] this->CenterlineIdsArrayName;
99 this->CenterlineIdsArrayName = NULL;
100 }
101}
102
104 vtkInformation *vtkNotUsed(request),
105 vtkInformationVector **inputVector,
106 vtkInformationVector *outputVector)
107{
108 vtkInformation *inInfo = inputVector[0]->GetInformationObject(0);
109 vtkInformation *outInfo = outputVector->GetInformationObject(0);
110
111 vtkPolyData *input = vtkPolyData::SafeDownCast(
112 inInfo->Get(vtkDataObject::DATA_OBJECT()));
113 vtkPolyData *output = vtkPolyData::SafeDownCast(
114 outInfo->Get(vtkDataObject::DATA_OBJECT()));
115
116 if (!this->MetricArrayName)
117 {
118 vtkErrorMacro(<<"MetricArrayName not set.");
119 return 1;
120 }
121
122 if (!this->GroupIdsArrayName)
123 {
124 vtkErrorMacro(<<"GroupIdsArrayName not set.");
125 return 1;
126 }
127
128 vtkDataArray* groupIdsArray = input->GetPointData()->GetArray(this->GroupIdsArrayName);
129
130 if (!groupIdsArray)
131 {
132 vtkErrorMacro(<<"GroupIdsArray with name specified does not exist.");
133 return 1;
134 }
135
136 if (!this->Centerlines)
137 {
138 vtkErrorMacro(<<"Centerlines not set");
139 return 1;
140 }
141
142 if (this->UseRadiusInformation)
143 {
144 if (!this->RadiusArrayName)
145 {
146 vtkErrorMacro(<<"RadiusArrayName not set.");
147 return 1;
148 }
149
150 vtkDataArray* radiusArray = this->Centerlines->GetPointData()->GetArray(this->RadiusArrayName);
151
152 if (!radiusArray)
153 {
154 vtkErrorMacro(<<"RadiusArray with name specified does not exist.");
155 return 1;
156 }
157 }
158
159 if (this->IncludeBifurcations)
160 {
161 if (!this->BlankingArrayName)
162 {
163 vtkErrorMacro(<<"BlankingArrayName not set.");
164 return 1;
165 }
166
167 vtkDataArray* blankingArray = this->Centerlines->GetCellData()->GetArray(this->BlankingArrayName);
168
169 if (!blankingArray)
170 {
171 vtkErrorMacro(<<"BlankingArray with name specified does not exist.");
172 return 1;
173 }
174
175 if (!this->CenterlineIdsArrayName)
176 {
177 vtkErrorMacro(<<"CenterlineIdsArrayName not set.");
178 return 1;
179 }
180
181 vtkDataArray* centerlineIdsArray = this->Centerlines->GetCellData()->GetArray(this->CenterlineIdsArrayName);
182
183 if (!centerlineIdsArray)
184 {
185 vtkErrorMacro(<<"CenterlineIdsArray with name specified does not exist.");
186 return 1;
187 }
188
190 {
191 vtkErrorMacro(<<"CenterlineTractIdsArrayName not set.");
192 return 1;
193 }
194
195 vtkDataArray* centerlineTractIdsArray = this->Centerlines->GetCellData()->GetArray(this->CenterlineTractIdsArrayName);
196
197 if (!centerlineTractIdsArray)
198 {
199 vtkErrorMacro(<<"CenterlineTractIdsArray with name specified does not exist.");
200 return 1;
201 }
202 }
203
205 {
206 vtkErrorMacro(<<"CenterlineGroupIdsArrayName not set.");
207 return 1;
208 }
209
210 vtkDataArray* centerlineGroupIdsArray = this->Centerlines->GetCellData()->GetArray(this->CenterlineGroupIdsArrayName);
211
212 if (!centerlineGroupIdsArray)
213 {
214 vtkErrorMacro(<<"CenterlineGroupIdsArrayName with name specified does not exist.");
215 return 1;
216 }
217
218 int numberOfInputPoints = input->GetNumberOfPoints();
219
220 output->DeepCopy(input);
221
222 vtkDoubleArray* metricArray = vtkDoubleArray::New();
223 metricArray->SetName(this->MetricArrayName);
224 metricArray->SetNumberOfComponents(1);
225 metricArray->SetNumberOfTuples(numberOfInputPoints);
226 metricArray->FillComponent(0,0.0);
227
228 output->GetPointData()->AddArray(metricArray);
229
230 vtkIdType groupId;
231 for (int i=0; i<numberOfInputPoints; i++)
232 {
233 groupId = static_cast<int>(groupIdsArray->GetComponent(i,0));
234 this->EvaluateMetric(i,input->GetPoint(i),groupId,metricArray);
235 }
236
237 metricArray->Delete();
238
239 return 1;
240}
virtual int RequestData(vtkInformation *, vtkInformationVector **, vtkInformationVector *) override
virtual void EvaluateMetric(vtkIdType pointId, double point[3], vtkIdType groupId, vtkDataArray *metricArray)=0