VMTK
Loading...
Searching...
No Matches
vtkvmtkCenterlineAttributesFilter.cxx
Go to the documentation of this file.
1/*=========================================================================
2
3Program: VMTK
4Module: $RCSfile: vtkvmtkCenterlineAttributesFilter.cxx,v $
5Language: C++
6Date: $Date: 2006/07/17 09:52:56 $
7Version: $Revision: 1.7 $
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 "vtkvmtkConstants.h"
24#include "vtkPolyData.h"
25#include "vtkDoubleArray.h"
26#include "vtkPointData.h"
27#include "vtkPolyLine.h"
28#include "vtkMath.h"
29#include "vtkTransform.h"
30#include "vtkInformation.h"
31#include "vtkInformationVector.h"
32#include "vtkObjectFactory.h"
33
34
36
42
57
59 vtkInformation *vtkNotUsed(request),
60 vtkInformationVector **inputVector,
61 vtkInformationVector *outputVector)
62{
63 // get the info objects
64 vtkInformation *inInfo = inputVector[0]->GetInformationObject(0);
65 vtkInformation *outInfo = outputVector->GetInformationObject(0);
66
67 // get the input and output
68 vtkPolyData *input = vtkPolyData::SafeDownCast(
69 inInfo->Get(vtkDataObject::DATA_OBJECT()));
70 vtkPolyData *output = vtkPolyData::SafeDownCast(
71 outInfo->Get(vtkDataObject::DATA_OBJECT()));
72
73 if (!this->AbscissasArrayName)
74 {
75 vtkErrorMacro(<<"AbscissasArrayName not specified");
76 return 1;
77 }
78
80 {
81 vtkErrorMacro(<<"ParallelTransportNormalsArrayName not specified");
82 return 1;
83 }
84
85 output->DeepCopy(input);
86
87 vtkDoubleArray* abscissasArray = vtkDoubleArray::New();
88 abscissasArray->SetNumberOfComponents(1);
89 abscissasArray->SetName(this->AbscissasArrayName);
90
91 this->ComputeAbscissas(input,abscissasArray);
92 output->GetPointData()->AddArray(abscissasArray);
93
94 vtkDoubleArray* parallelTransportNormalsArray = vtkDoubleArray::New();
95 parallelTransportNormalsArray->SetNumberOfComponents(3);
96 parallelTransportNormalsArray->SetName(this->ParallelTransportNormalsArrayName);
97
98 this->ComputeParallelTransportNormals(input,parallelTransportNormalsArray);
99 output->GetPointData()->AddArray(parallelTransportNormalsArray);
100
101 abscissasArray->Delete();
102 parallelTransportNormalsArray->Delete();
103
104 return 1;
105}
106
107void vtkvmtkCenterlineAttributesFilter::ComputeAbscissas(vtkPolyData* input, vtkDoubleArray* abscissasArray)
108{
109 int numberOfPoints = input->GetNumberOfPoints();
110
111 abscissasArray->SetNumberOfTuples(numberOfPoints);
112 abscissasArray->FillComponent(0,0.0);
113
114 double point0[3], point1[3];
115 double abscissa;
116 vtkIdType id0, id1;
117
118 int numberOfCells = input->GetNumberOfCells();
119 int numberOfPointsInCell;
120
121 for (int k=0; k<numberOfCells; k++)
122 {
123 vtkPolyLine* polyLine = vtkPolyLine::SafeDownCast(input->GetCell(k));
124
125 if (!polyLine)
126 {
127 continue;
128 }
129
130 numberOfPointsInCell = polyLine->GetNumberOfPoints();
131
132 abscissa = 0.0;
133
134 id0 = polyLine->GetPointId(0);
135 abscissasArray->SetValue(id0,abscissa);
136
137 for (int i=1; i<numberOfPointsInCell; i++)
138 {
139 id0 = polyLine->GetPointId(i-1);
140 id1 = polyLine->GetPointId(i);
141 input->GetPoint(id0,point0);
142 input->GetPoint(id1,point1);
143 abscissa += sqrt(vtkMath::Distance2BetweenPoints(point0,point1));
144 abscissasArray->SetValue(id1,abscissa);
145 }
146 }
147}
148
149void vtkvmtkCenterlineAttributesFilter::ComputeParallelTransportNormals(vtkPolyData* input, vtkDoubleArray* parallelTransportNormalsArray)
150{
151 int numberOfPoints = input->GetNumberOfPoints();
152
153 parallelTransportNormalsArray->SetNumberOfTuples(numberOfPoints);
154 parallelTransportNormalsArray->FillComponent(0,0.0);
155
156 int numberOfCells = input->GetNumberOfCells();
157 int numberOfPointsInCell;
158
159 vtkTransform* transform = vtkTransform::New();
160
161 vtkIdType id0, id1, id2;
162 double p0[3], p1[3], p2[3];
163
164 double t0[3], t1[3], v[3];
165 double dot, theta;
166 double n0[3], n1[3];
167
168 id2 = -1;
169
170 for (int k=0; k<numberOfCells; k++)
171 {
172 vtkPolyLine* polyLine = vtkPolyLine::SafeDownCast(input->GetCell(k));
173
174 if (!polyLine)
175 {
176 continue;
177 }
178
179 numberOfPointsInCell = polyLine->GetNumberOfPoints();
180
181 if (numberOfPointsInCell < 2)
182 {
183 continue;
184 }
185
186 t0[0] = t0[1] = t0[2] = 0.0;
187
188 id0 = polyLine->GetPointId(0);
189 input->GetPoint(id0,p0);
190
191 vtkIdType nextId = 1;
192 while (vtkMath::Norm(t0) < VTK_VMTK_DOUBLE_TOL)
193 {
194 id1 = polyLine->GetPointId(nextId);
195 input->GetPoint(id1,p1);
196
197 t0[0] = p1[0] - p0[0];
198 t0[1] = p1[1] - p0[1];
199 t0[2] = p1[2] - p0[2];
200
201 ++nextId;
202 }
203
204 vtkMath::Normalize(t0);
205
206 double dummy[3];
207 vtkMath::Perpendiculars(t0,n0,dummy,0.0);
208
209 parallelTransportNormalsArray->SetTuple(id0,n0);
210
211 for (int i=1; i<numberOfPointsInCell-1; i++)
212 {
213 id0 = polyLine->GetPointId(i-1);
214 id1 = polyLine->GetPointId(i);
215 id2 = polyLine->GetPointId(i+1);
216 input->GetPoint(id0,p0);
217 input->GetPoint(id1,p1);
218 input->GetPoint(id2,p2);
219
220 t0[0] = p1[0] - p0[0];
221 t0[1] = p1[1] - p0[1];
222 t0[2] = p1[2] - p0[2];
223
224 t1[0] = p2[0] - p1[0];
225 t1[1] = p2[1] - p1[1];
226 t1[2] = p2[2] - p1[2];
227
228 vtkMath::Normalize(t0);
229 vtkMath::Normalize(t1);
230
231 dot = vtkMath::Dot(t0,t1);
232
233 if (1-dot < VTK_VMTK_DOUBLE_TOL)
234 {
235 theta = 0.0;
236 }
237 else
238 {
239 theta = acos(dot) * 180.0 / vtkMath::Pi();
240 }
241
242 vtkMath::Cross(t0,t1,v);
243
244 transform->Identity();
245 transform->RotateWXYZ(theta,v);
246 transform->TransformPoint(n0,n1);
247
248 dot = vtkMath::Dot(t1,n1);
249 n1[0] -= dot * t1[0];
250 n1[1] -= dot * t1[1];
251 n1[2] -= dot * t1[2];
252
253 vtkMath::Normalize(n1);
254
255 parallelTransportNormalsArray->SetTuple(id1,n1);
256
257 n0[0] = n1[0];
258 n0[1] = n1[1];
259 n0[2] = n1[2];
260 }
261
262 parallelTransportNormalsArray->SetTuple(id2,n1);
263 }
264
265 transform->Delete();
266}
267
268void vtkvmtkCenterlineAttributesFilter::PrintSelf(std::ostream& os, vtkIndent indent)
269{
270 this->Superclass::PrintSelf(os,indent);
271}
Computes the abscissa and parallel transport normal along a centerline.
void PrintSelf(std::ostream &os, vtkIndent indent) override
virtual int RequestData(vtkInformation *, vtkInformationVector **, vtkInformationVector *) override
void ComputeAbscissas(vtkPolyData *input, vtkDoubleArray *abscissasArray)
void ComputeParallelTransportNormals(vtkPolyData *input, vtkDoubleArray *parallelTransportNormalsArray)
vtkStandardNewMacro(vtkvmtkCenterlineAttributesFilter)
#define VTK_VMTK_DOUBLE_TOL