VMTK
Loading...
Searching...
No Matches
vtkvmtkCenterlineReferenceSystemAttributesOffset.cxx
Go to the documentation of this file.
1/*=========================================================================
2
3Program: VMTK
4Module: $RCSfile: vtkvmtkCenterlineReferenceSystemAttributesOffset.cxx,v $
5Language: C++
6Date: $Date: 2006/04/06 16:46:43 $
7Version: $Revision: 1.8 $
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 "vtkIdList.h"
26#include "vtkCell.h"
27#include "vtkDoubleArray.h"
28#include "vtkTransform.h"
29#include "vtkvmtkPolyBallLine.h"
30#include "vtkvmtkMath.h"
31#include "vtkInformation.h"
32#include "vtkInformationVector.h"
33#include "vtkObjectFactory.h"
34
37
38
40
58
60{
62 {
63 delete[] this->OffsetAbscissasArrayName;
64 this->OffsetAbscissasArrayName = NULL;
65 }
66
67 if (this->OffsetNormalsArrayName)
68 {
69 delete[] this->OffsetNormalsArrayName;
70 this->OffsetNormalsArrayName = NULL;
71 }
72
73 if (this->AbscissasArrayName)
74 {
75 delete[] this->AbscissasArrayName;
76 this->AbscissasArrayName = NULL;
77 }
78
79 if (this->NormalsArrayName)
80 {
81 delete[] this->NormalsArrayName;
82 this->NormalsArrayName = NULL;
83 }
84
85 if (this->GroupIdsArrayName)
86 {
87 delete[] this->GroupIdsArrayName;
88 this->GroupIdsArrayName = NULL;
89 }
90
91 if (this->CenterlineIdsArrayName)
92 {
93 delete[] this->CenterlineIdsArrayName;
94 this->CenterlineIdsArrayName = NULL;
95 }
96
97 if (this->NormalsArrayName)
98 {
99 delete[] this->NormalsArrayName;
100 this->NormalsArrayName = NULL;
101 }
102
103 if (this->ReferenceSystems)
104 {
105 this->ReferenceSystems->Delete();
106 this->ReferenceSystems = NULL;
107 }
108
110 {
111 delete[] this->ReferenceSystemsNormalArrayName;
113 }
114
116 {
119 }
120}
121
123 vtkInformation *vtkNotUsed(request),
124 vtkInformationVector **inputVector,
125 vtkInformationVector *outputVector)
126{
127 vtkInformation *inInfo = inputVector[0]->GetInformationObject(0);
128 vtkInformation *outInfo = outputVector->GetInformationObject(0);
129
130 vtkPolyData *input = vtkPolyData::SafeDownCast(
131 inInfo->Get(vtkDataObject::DATA_OBJECT()));
132 vtkPolyData *output = vtkPolyData::SafeDownCast(
133 outInfo->Get(vtkDataObject::DATA_OBJECT()));
134
135 if (!this->OffsetAbscissasArrayName)
136 {
137 vtkErrorMacro(<<"OffsetAbscissasArrayName not specified");
138 return 1;
139 }
140
141 if (!this->OffsetNormalsArrayName)
142 {
143 vtkErrorMacro(<<"OffsetNormalsArrayName not specified");
144 return 1;
145 }
146
147 if (!this->AbscissasArrayName)
148 {
149 vtkErrorMacro(<<"AbscissasArrayName not specified");
150 return 1;
151 }
152
153 vtkDataArray* abscissasArray = input->GetPointData()->GetArray(this->AbscissasArrayName);
154
155 if (!abscissasArray)
156 {
157 vtkErrorMacro(<<"AbscissasArray with name specified does not exist");
158 return 1;
159 }
160
161 if (!this->NormalsArrayName)
162 {
163 vtkErrorMacro(<<"NormalsArrayName not specified");
164 return 1;
165 }
166
167 vtkDataArray* normalsArray = input->GetPointData()->GetArray(this->NormalsArrayName);
168
169 if (!normalsArray)
170 {
171 vtkErrorMacro(<<"NormalsArray with name specified does not exist");
172 return 1;
173 }
174
175 if (!this->GroupIdsArrayName)
176 {
177 vtkErrorMacro(<<"GroupIdsArrayName not specified");
178 return 1;
179 }
180
181 vtkDataArray* groupIdsArray = input->GetCellData()->GetArray(this->GroupIdsArrayName);
182
183 if (!groupIdsArray)
184 {
185 vtkErrorMacro(<<"GroupIdsArray with name specified does not exist");
186 return 1;
187 }
188
189 if (!this->CenterlineIdsArrayName)
190 {
191 vtkErrorMacro(<<"CenterlineIdsArrayName not specified");
192 return 1;
193 }
194
195 vtkDataArray* centerlineIdsArray = input->GetCellData()->GetArray(this->CenterlineIdsArrayName);
196
197 if (!centerlineIdsArray)
198 {
199 vtkErrorMacro(<<"CenterlineIdsArray with name specified does not exist");
200 return 1;
201 }
202
203 if (!this->ReferenceSystems)
204 {
205 vtkErrorMacro(<<"ReferenceSystems not specified");
206 return 1;
207 }
208
209 if (this->ReferenceSystems->GetNumberOfPoints() == 0)
210 {
211 vtkErrorMacro(<<"ReferenceSystems empty");
212 return 1;
213 }
214
216 {
217 vtkErrorMacro(<<"ReferenceSystemsNormalArrayName not specified");
218 return 1;
219 }
220
221 vtkDataArray* referenceSystemsNormalArray = this->ReferenceSystems->GetPointData()->GetArray(this->ReferenceSystemsNormalArrayName);
222
223 if (!referenceSystemsNormalArray)
224 {
225 vtkErrorMacro(<<"ReferenceSystemNormalsArray with name specified does not exist");
226 return 1;
227 }
228
230 {
231 vtkErrorMacro(<<"ReferenceSystemsGroupIdsArrayName not specified");
232 return 1;
233 }
234
235 vtkDataArray* referenceSystemsGroupIdsArray = this->ReferenceSystems->GetPointData()->GetArray(this->ReferenceSystemsGroupIdsArrayName);
236
237 if (!referenceSystemsGroupIdsArray)
238 {
239 vtkErrorMacro(<<"ReferenceSystemsGroupIdsArray with name specified does not exist");
240 return 1;
241 }
242
243 output->DeepCopy(input);
244
245 vtkDoubleArray* offsetAbscissasArray = vtkDoubleArray::New();
246 offsetAbscissasArray->SetName(this->OffsetAbscissasArrayName);
247 offsetAbscissasArray->SetNumberOfComponents(1);
248 offsetAbscissasArray->SetNumberOfTuples(input->GetNumberOfPoints());
249
250 vtkDoubleArray* offsetNormalsArray = vtkDoubleArray::New();
251 offsetNormalsArray->SetName(this->OffsetNormalsArrayName);
252 offsetNormalsArray->SetNumberOfComponents(3);
253 offsetNormalsArray->SetNumberOfTuples(input->GetNumberOfPoints());
254
255 // For each branch in the reference group, compute nearest point. Get abscissa and normal at that point.
256 // Compute abscissa offset and normal offset rotation.
257 // Apply abscissa offset and normal offset rotation to each branch in the centerline.
258
260 tube->SetInput(input);
262
263 vtkIdList* tubeInputCellIds = vtkIdList::New();
264
265 double referenceSystemOrigin[3], referenceSystemNormal[3];
266
267 if (this->ReferenceGroupId == -1)
268 {
269 this->ReferenceGroupId = static_cast<int>(referenceSystemsGroupIdsArray->GetComponent(0,0));
270 }
271
273
274 if (referenceSystemPointId == -1)
275 {
276 vtkErrorMacro(<<"Invalid ReferenceGroupId");
277 return 1;
278 }
279
280 this->ReferenceSystems->GetPoint(referenceSystemPointId,referenceSystemOrigin);
281 referenceSystemsNormalArray->GetTuple(referenceSystemPointId,referenceSystemNormal);
282
283 vtkIdList* groupCellIds = vtkIdList::New();
285 for (int i=0; i<groupCellIds->GetNumberOfIds(); i++)
286 {
287 vtkIdType currentCellId = groupCellIds->GetId(i);
288
289 vtkIdType centerlineId = static_cast<int>(centerlineIdsArray->GetComponent(currentCellId,0));
290 tubeInputCellIds->Initialize();
291 tubeInputCellIds->InsertNextId(currentCellId);
292 tube->SetInputCellIds(tubeInputCellIds);
293
294 tube->EvaluateFunction(referenceSystemOrigin);
295
296 vtkIdType cellId = tube->GetLastPolyBallCellId();
297 vtkIdType subId = tube->GetLastPolyBallCellSubId();
298 double pcoord = tube->GetLastPolyBallCellPCoord();
299
300 double abscissa = 0.0;
301 vtkvmtkCenterlineUtilities::InterpolateTuple1(input,this->AbscissasArrayName,cellId,subId,pcoord,abscissa);
302 double abscissaOffset = - abscissa;
303
304 double normal[3];
305 vtkvmtkCenterlineUtilities::InterpolateTuple3(input,this->NormalsArrayName,cellId,subId,pcoord,normal);
306 vtkMath::Normalize(normal);
307
308 double point0[3], point1[3], tangent[3];
309 input->GetCell(cellId)->GetPoints()->GetPoint(subId,point0);
310 input->GetCell(cellId)->GetPoints()->GetPoint(subId+1,point1);
311 tangent[0] = point1[0] - point0[0];
312 tangent[1] = point1[1] - point0[1];
313 tangent[2] = point1[2] - point0[2];
314 double normalDot = vtkMath::Dot(tangent,normal);
315 tangent[0] -= normalDot * normal[0];
316 tangent[1] -= normalDot * normal[1];
317 tangent[2] -= normalDot * normal[2];
318 vtkMath::Normalize(tangent);
319
320 double dot = vtkMath::Dot(tangent,referenceSystemNormal);
321 double projectedReferenceSystemNormal[3];
322 projectedReferenceSystemNormal[0] = referenceSystemNormal[0] - dot * tangent[0];
323 projectedReferenceSystemNormal[1] = referenceSystemNormal[1] - dot * tangent[1];
324 projectedReferenceSystemNormal[2] = referenceSystemNormal[2] - dot * tangent[2];
325 vtkMath::Normalize(projectedReferenceSystemNormal);
326
327 double angle = vtkvmtkMath::AngleBetweenNormals(normal,projectedReferenceSystemNormal);
328
329 double cross[3];
330 vtkMath::Cross(projectedReferenceSystemNormal,normal,cross);
331 double tangentDot = vtkMath::Dot(tangent,cross);
332
333 if (tangentDot < 0.0)
334 {
335 angle *= -1.0;
336 }
337
338 double angleOffset = -angle;
339
340 vtkIdList* centerlineCellIds = vtkIdList::New();
341 vtkvmtkCenterlineUtilities::GetCenterlineCellIds(input,this->CenterlineIdsArrayName,centerlineId,centerlineCellIds);
342 for (int j=0; j<centerlineCellIds->GetNumberOfIds(); j++)
343 {
344 vtkCell* branchCell = input->GetCell(centerlineCellIds->GetId(j));
345 int numberOfBranchPoints = branchCell->GetNumberOfPoints();
346 for (int k=0; k<numberOfBranchPoints; k++)
347 {
348 vtkIdType branchPointId = branchCell->GetPointId(k);
349 double branchPointAbscissa = abscissasArray->GetComponent(branchPointId,0);
350 double offsetBranchPointAbscissa = branchPointAbscissa + abscissaOffset;
351 offsetAbscissasArray->SetComponent(branchPointId,0,offsetBranchPointAbscissa);
352
353 double branchPointNormal[3];
354 normalsArray->GetTuple(branchPointId,branchPointNormal);
355 double branchPoint[3];
356 branchCell->GetPoints()->GetPoint(k,branchPoint);
357 double branchTangent[3];
358 branchTangent[0] = branchTangent[1] = branchTangent[2] = 0.0;
359 if (k > 0)
360 {
361 double branchPoint0[3];
362 branchCell->GetPoints()->GetPoint(k-1,branchPoint0);
363 branchTangent[0] += branchPoint[0] - branchPoint0[0];
364 branchTangent[1] += branchPoint[1] - branchPoint0[1];
365 branchTangent[2] += branchPoint[2] - branchPoint0[2];
366 }
367 if (k < numberOfBranchPoints-1)
368 {
369 double branchPoint1[3];
370 branchCell->GetPoints()->GetPoint(k+1,branchPoint1);
371 branchTangent[0] += branchPoint1[0] - branchPoint[0];
372 branchTangent[1] += branchPoint1[1] - branchPoint[1];
373 branchTangent[2] += branchPoint1[2] - branchPoint[2];
374 }
375 double branchNormalDot = vtkMath::Dot(branchTangent,branchPointNormal);
376 branchTangent[0] -= branchNormalDot * branchPointNormal[0];
377 branchTangent[1] -= branchNormalDot * branchPointNormal[1];
378 branchTangent[2] -= branchNormalDot * branchPointNormal[2];
379 vtkMath::Normalize(branchTangent);
380
381 vtkTransform* transform = vtkTransform::New();
382 transform->RotateWXYZ(angleOffset/vtkMath::Pi()*180.0,branchTangent);
383
384 double offsetBranchPointNormal[3];
385 transform->TransformNormal(branchPointNormal,offsetBranchPointNormal);
386 offsetNormalsArray->SetTuple(branchPointId,offsetBranchPointNormal);
387
388 transform->Delete();
389 }
390 }
391 centerlineCellIds->Delete();
392 }
393
394 groupCellIds->Delete();
395
396 output->GetPointData()->AddArray(offsetAbscissasArray);
397 output->GetPointData()->AddArray(offsetNormalsArray);
398
399 offsetAbscissasArray->Delete();
400 offsetNormalsArray->Delete();
401 tube->Delete();
402 tubeInputCellIds->Delete();
403
404 return 1;
405}
406
408{
409 this->Superclass::PrintSelf(os,indent);
410}
Move the abscissa metric such that its zero point is at a bifurcation center and rotate parallel tran...
virtual int RequestData(vtkInformation *, vtkInformationVector **, vtkInformationVector *) override
static void GetCenterlineCellIds(vtkPolyData *centerlines, const char *centerlineIdsArrayName, vtkIdType centerlineId, vtkIdList *centerlineCellIds)
static void GetGroupCellIds(vtkPolyData *centerlines, const char *groupIdsArrayName, vtkIdType groupId, vtkIdList *groupCellIds)
static void InterpolateTuple1(vtkPolyData *centerlines, const char *arrayName, int cellId, int subId, double pcoord, double &interpolatedTuple1)
static void InterpolateTuple3(vtkPolyData *centerlines, const char *arrayName, int cellId, int subId, double pcoord, double interpolatedTuple3[3])
static double AngleBetweenNormals(double normal0[3], double normal1[3])
Implements vtkImplicitFunction to evaluate the minimum sphere function for an envelope created by an ...
virtual double GetLastPolyBallCellPCoord()
virtual void SetInput(vtkPolyData *)
virtual void SetInputCellIds(vtkIdList *)
virtual vtkIdType GetLastPolyBallCellId()
static vtkvmtkPolyBallLine * New()
double EvaluateFunction(double x[3]) override
virtual vtkIdType GetLastPolyBallCellSubId()
virtual void UseRadiusInformationOff()
static vtkIdType GetReferenceSystemPointId(vtkPolyData *referenceSystems, const char *groupIdsArrayName, vtkIdType groupId)
vtkStandardNewMacro(vtkvmtkCenterlineReferenceSystemAttributesOffset)