VMTK
Loading...
Searching...
No Matches
vtkvmtkCenterlineBifurcationVectors.cxx
Go to the documentation of this file.
1/*=========================================================================
2
3Program: VMTK
4Module: $RCSfile: vtkvmtkCenterlineBifurcationVectors.cxx,v $
5Language: C++
6Date: $Date: 2006/10/17 15:16:16 $
7Version: $Revision: 1.1 $
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 "vtkPolyData.h"
24#include "vtkIdList.h"
25#include "vtkPointData.h"
26#include "vtkCellData.h"
27#include "vtkCellArray.h"
28#include "vtkPolyLine.h"
29#include "vtkDoubleArray.h"
30#include "vtkIntArray.h"
31#include "vtkMath.h"
32#include "vtkvmtkMath.h"
34#include "vtkInformation.h"
35#include "vtkInformationVector.h"
36#include "vtkObjectFactory.h"
37
40
41
43
69
71{
72 if (this->RadiusArrayName)
73 {
74 delete[] this->RadiusArrayName;
75 this->RadiusArrayName = NULL;
76 }
77
78 if (this->GroupIdsArrayName)
79 {
80 delete[] this->GroupIdsArrayName;
81 this->GroupIdsArrayName = NULL;
82 }
83
84 if (this->CenterlineIdsArrayName)
85 {
86 delete[] this->CenterlineIdsArrayName;
87 this->CenterlineIdsArrayName = NULL;
88 }
89
90 if (this->TractIdsArrayName)
91 {
92 delete[] this->TractIdsArrayName;
93 this->TractIdsArrayName = NULL;
94 }
95
96 if (this->BlankingArrayName)
97 {
98 delete[] this->BlankingArrayName;
99 this->BlankingArrayName = NULL;
100 }
101
102 if (this->ReferenceSystems)
103 {
104 this->ReferenceSystems->Delete();
105 }
106
108 {
111 }
112
114 {
115 delete[] this->ReferenceSystemNormalArrayName;
117 }
118
120 {
123 }
124
126 {
127 delete[] this->BifurcationVectorsArrayName;
128 this->BifurcationVectorsArrayName = NULL;
129 }
130
132 {
135 }
136
138 {
141 }
142
144 {
147 }
148
150 {
153 }
154
156 {
159 }
160
162 {
163 delete[] this->BifurcationGroupIdsArrayName;
164 this->BifurcationGroupIdsArrayName = NULL;
165 }
166}
167
169 vtkInformation *vtkNotUsed(request),
170 vtkInformationVector **inputVector,
171 vtkInformationVector *outputVector)
172{
173 vtkInformation *inInfo = inputVector[0]->GetInformationObject(0);
174 vtkInformation *outInfo = outputVector->GetInformationObject(0);
175
176 vtkPolyData *input = vtkPolyData::SafeDownCast(
177 inInfo->Get(vtkDataObject::DATA_OBJECT()));
178 vtkPolyData *output = vtkPolyData::SafeDownCast(
179 outInfo->Get(vtkDataObject::DATA_OBJECT()));
180
181 if (!this->RadiusArrayName)
182 {
183 vtkErrorMacro(<<"RadiusArrayName not specified");
184 return 1;
185 }
186
187 vtkDataArray* radiusArray = input->GetPointData()->GetArray(this->RadiusArrayName);
188
189 if (!radiusArray)
190 {
191 vtkErrorMacro(<<"RadiusArray with name specified does not exist");
192 return 1;
193 }
194
195 if (!this->GroupIdsArrayName)
196 {
197 vtkErrorMacro(<<"GroupIdsArrayName not specified");
198 return 1;
199 }
200
201 vtkDataArray* groupIdsArray = input->GetCellData()->GetArray(this->GroupIdsArrayName);
202
203 if (!groupIdsArray)
204 {
205 vtkErrorMacro(<<"GroupIdsArray with name specified does not exist");
206 return 1;
207 }
208
209 if (!this->CenterlineIdsArrayName)
210 {
211 vtkErrorMacro(<<"CenterlineIdsArrayName not specified");
212 return 1;
213 }
214
215 vtkDataArray* centerlineIdsArray = input->GetCellData()->GetArray(this->CenterlineIdsArrayName);
216
217 if (!centerlineIdsArray)
218 {
219 vtkErrorMacro(<<"CenterlineIdsArray with name specified does not exist");
220 return 1;
221 }
222
223 if (!this->TractIdsArrayName)
224 {
225 vtkErrorMacro(<<"TractIdsArrayName not specified");
226 return 1;
227 }
228
229 vtkDataArray* tractIdsArray = input->GetCellData()->GetArray(this->TractIdsArrayName);
230
231 if (!tractIdsArray)
232 {
233 vtkErrorMacro(<<"TractIdsArray with name specified does not exist");
234 return 1;
235 }
236
237 if (!this->BlankingArrayName)
238 {
239 vtkErrorMacro(<<"BlankingArrayName not specified");
240 return 1;
241 }
242
243 vtkDataArray* blankingArray = input->GetCellData()->GetArray(this->BlankingArrayName);
244
245 if (!blankingArray)
246 {
247 vtkErrorMacro(<<"BlankingArray with name specified does not exist");
248 return 1;
249 }
250
252 {
253 vtkErrorMacro(<<"ReferenceSystemGroupIdsArrayName not specified");
254 return 1;
255 }
256
257 vtkDataArray* referenceSystemGroupIdsArray = this->ReferenceSystems->GetPointData()->GetArray(this->ReferenceSystemGroupIdsArrayName);
258
259 if (!referenceSystemGroupIdsArray)
260 {
261 vtkErrorMacro(<<"ReferenceSystemGroupIdsArray with name specified does not exist");
262 return 1;
263 }
264
266 {
267 vtkErrorMacro(<<"ReferenceSystemNormalArrayName not specified");
268 return 1;
269 }
270
271 vtkDataArray* referenceSystemNormalArray = this->ReferenceSystems->GetPointData()->GetArray(this->ReferenceSystemNormalArrayName);
272
273 if (!referenceSystemNormalArray)
274 {
275 vtkErrorMacro(<<"ReferenceSystemNormalArray with name specified does not exist");
276 return 1;
277 }
278
280 {
281 vtkErrorMacro(<<"ReferenceSystemUpNormalArrayName not specified");
282 return 1;
283 }
284
285 vtkDataArray* referenceSystemUpNormalArray = this->ReferenceSystems->GetPointData()->GetArray(this->ReferenceSystemUpNormalArrayName);
286
287 if (!referenceSystemUpNormalArray)
288 {
289 vtkErrorMacro(<<"ReferenceSystemUpNormalArray with name specified does not exist");
290 return 1;
291 }
292
294 {
295 vtkErrorMacro(<<"BifurcationVectorsArrayName not specified");
296 return 1;
297 }
298
300 {
301 vtkErrorMacro(<<"InPlaneBifurcationVectorsArrayName not specified");
302 return 1;
303 }
304
306 {
307 vtkErrorMacro(<<"OutOfPlaneBifurcationVectorsArrayName not specified");
308 return 1;
309 }
310
312 {
313 vtkErrorMacro(<<"BifurcationVectorsOrientationArrayName not specified");
314 return 1;
315 }
316
318 {
319 vtkErrorMacro(<<"BifurcationGroupIdsArrayName not specified");
320 return 1;
321 }
322
324 {
325 vtkErrorMacro(<<"InPlaneBifurcationVectorAnglesArrayName not specified");
326 return 1;
327 }
328
330 {
331 vtkErrorMacro(<<"OutOfPlaneBifurcationVectorAnglesArrayName not specified");
332 return 1;
333 }
334
335 vtkPoints* outputPoints = vtkPoints::New();
336 vtkCellArray* outputVerts = vtkCellArray::New();
337
338 output->SetPoints(outputPoints);
339 output->SetVerts(outputVerts);
340
341 vtkDoubleArray* bifurcationVectorsArray = vtkDoubleArray::New();
342 bifurcationVectorsArray->SetName(this->BifurcationVectorsArrayName);
343 bifurcationVectorsArray->SetNumberOfComponents(3);
344
345 vtkDoubleArray* inPlaneBifurcationVectorsArray = vtkDoubleArray::New();
346 inPlaneBifurcationVectorsArray->SetName(this->InPlaneBifurcationVectorsArrayName);
347 inPlaneBifurcationVectorsArray->SetNumberOfComponents(3);
348
349 vtkDoubleArray* outOfPlaneBifurcationVectorsArray = vtkDoubleArray::New();
350 outOfPlaneBifurcationVectorsArray->SetName(this->OutOfPlaneBifurcationVectorsArrayName);
351 outOfPlaneBifurcationVectorsArray->SetNumberOfComponents(3);
352
353 vtkDoubleArray* inPlaneBifurcationVectorAnglesArray = vtkDoubleArray::New();
354 inPlaneBifurcationVectorAnglesArray->SetName(this->InPlaneBifurcationVectorAnglesArrayName);
355 inPlaneBifurcationVectorAnglesArray->SetNumberOfComponents(1);
356
357 vtkDoubleArray* outOfPlaneBifurcationVectorAnglesArray = vtkDoubleArray::New();
358 outOfPlaneBifurcationVectorAnglesArray->SetName(this->OutOfPlaneBifurcationVectorAnglesArrayName);
359 outOfPlaneBifurcationVectorAnglesArray->SetNumberOfComponents(1);
360
361 vtkIntArray* bifurcationVectorsOrientationArray = vtkIntArray::New();
362 bifurcationVectorsOrientationArray->SetName(this->BifurcationVectorsOrientationArrayName);
363 bifurcationVectorsOrientationArray->SetNumberOfComponents(1);
364
365 vtkIntArray* bifurcationVectorsGroupIdsArray = vtkIntArray::New();
366 bifurcationVectorsGroupIdsArray->SetName(this->GroupIdsArrayName);
367 bifurcationVectorsGroupIdsArray->SetNumberOfComponents(1);
368
369 vtkIntArray* bifurcationVectorsBifurcationGroupIdsArray = vtkIntArray::New();
370 bifurcationVectorsBifurcationGroupIdsArray->SetName(this->BifurcationGroupIdsArrayName);
371 bifurcationVectorsBifurcationGroupIdsArray->SetNumberOfComponents(1);
372
373 output->GetPointData()->AddArray(bifurcationVectorsArray);
374 output->GetPointData()->AddArray(inPlaneBifurcationVectorsArray);
375 output->GetPointData()->AddArray(outOfPlaneBifurcationVectorsArray);
376 output->GetPointData()->AddArray(inPlaneBifurcationVectorAnglesArray);
377 output->GetPointData()->AddArray(outOfPlaneBifurcationVectorAnglesArray);
378 output->GetPointData()->AddArray(bifurcationVectorsOrientationArray);
379 output->GetPointData()->AddArray(bifurcationVectorsGroupIdsArray);
380 output->GetPointData()->AddArray(bifurcationVectorsBifurcationGroupIdsArray);
381
382 vtkIdList* blankedGroupIds = vtkIdList::New();
384 int i;
385 for (i=0; i<blankedGroupIds->GetNumberOfIds(); i++)
386 {
387 vtkIdType bifurcationGroupId = blankedGroupIds->GetId(i);
388
389 vtkIdList* groupBifurcationVectorsGroupIds = vtkIdList::New();
390 vtkIntArray* groupBifurcationVectorsOrientation = vtkIntArray::New();
391 vtkDoubleArray* groupBifurcationVectors = vtkDoubleArray::New();
392 vtkPoints* groupBifurcationVectorsPoints = vtkPoints::New();
393 vtkDoubleArray* groupInPlaneBifurcationVectors = vtkDoubleArray::New();
394 vtkDoubleArray* groupOutOfPlaneBifurcationVectors = vtkDoubleArray::New();
395 vtkDoubleArray* groupInPlaneBifurcationVectorAngles = vtkDoubleArray::New();
396 vtkDoubleArray* groupOutOfPlaneBifurcationVectorAngles = vtkDoubleArray::New();
397
398 this->ComputeBifurcationVectors(input,bifurcationGroupId,groupBifurcationVectorsGroupIds,groupBifurcationVectorsOrientation,groupBifurcationVectors,groupBifurcationVectorsPoints);
399 this->ComputeBifurcationVectorComponents(bifurcationGroupId,groupBifurcationVectors,groupInPlaneBifurcationVectors,groupOutOfPlaneBifurcationVectors);
400 this->ComputeBifurcationVectorAngles(bifurcationGroupId,groupBifurcationVectors,groupInPlaneBifurcationVectors,groupOutOfPlaneBifurcationVectors,groupInPlaneBifurcationVectorAngles,groupOutOfPlaneBifurcationVectorAngles);
401
402 int j;
403 for (j=0; j<groupBifurcationVectorsGroupIds->GetNumberOfIds(); j++)
404 {
405 vtkIdType pointId = outputPoints->InsertNextPoint(groupBifurcationVectorsPoints->GetPoint(j));
406 outputVerts->InsertNextCell(1);
407 outputVerts->InsertCellPoint(pointId);
408
409 bifurcationVectorsArray->InsertNextTuple(groupBifurcationVectors->GetTuple(j));
410 inPlaneBifurcationVectorsArray->InsertNextTuple(groupInPlaneBifurcationVectors->GetTuple(j));
411 outOfPlaneBifurcationVectorsArray->InsertNextTuple(groupOutOfPlaneBifurcationVectors->GetTuple(j));
412 inPlaneBifurcationVectorAnglesArray->InsertNextTuple(groupInPlaneBifurcationVectorAngles->GetTuple(j));
413 outOfPlaneBifurcationVectorAnglesArray->InsertNextTuple(groupOutOfPlaneBifurcationVectorAngles->GetTuple(j));
414 bifurcationVectorsOrientationArray->InsertNextValue(groupBifurcationVectorsOrientation->GetValue(j));
415 bifurcationVectorsGroupIdsArray->InsertNextValue(groupBifurcationVectorsGroupIds->GetId(j));
416 bifurcationVectorsBifurcationGroupIdsArray->InsertNextValue(bifurcationGroupId);
417 }
418
419 groupBifurcationVectorsGroupIds->Delete();
420 groupBifurcationVectorsOrientation->Delete();
421 groupBifurcationVectors->Delete();
422 groupBifurcationVectorsPoints->Delete();
423 groupInPlaneBifurcationVectors->Delete();
424 groupOutOfPlaneBifurcationVectors->Delete();
425 groupInPlaneBifurcationVectorAngles->Delete();
426 groupOutOfPlaneBifurcationVectorAngles->Delete();
427 }
428
429 blankedGroupIds->Delete();
430
431 outputPoints->Delete();
432 outputVerts->Delete();
433
434 bifurcationVectorsArray->Delete();
435 inPlaneBifurcationVectorsArray->Delete();
436 outOfPlaneBifurcationVectorsArray->Delete();
437 inPlaneBifurcationVectorAnglesArray->Delete();
438 outOfPlaneBifurcationVectorAnglesArray->Delete();
439 bifurcationVectorsOrientationArray->Delete();
440 bifurcationVectorsGroupIdsArray->Delete();
441 bifurcationVectorsBifurcationGroupIdsArray->Delete();
442
443 return 1;
444}
445
446void vtkvmtkCenterlineBifurcationVectors::ComputeBifurcationVectors(vtkPolyData* input, int bifurcationGroupId, vtkIdList* bifurcationVectorsGroupIds, vtkIntArray* bifurcationVectorsOrientation, vtkDoubleArray* bifurcationVectors, vtkPoints* bifurcationVectorsPoints)
447{
448 vtkDataArray* radiusArray = input->GetPointData()->GetArray(this->RadiusArrayName);
449
450 bifurcationVectorsGroupIds->Initialize();
451 bifurcationVectorsOrientation->Initialize();
452
453 vtkIdList* upStreamGroupIds = vtkIdList::New();
454 vtkIdList* downStreamGroupIds = vtkIdList::New();
455
456 vtkvmtkCenterlineUtilities::FindAdjacentCenterlineGroupIds(input,this->GroupIdsArrayName,this->CenterlineIdsArrayName,this->TractIdsArrayName,bifurcationGroupId,upStreamGroupIds,downStreamGroupIds);
457
458 int numberOfUpStreamGroupIds = upStreamGroupIds->GetNumberOfIds();
459 int numberOfDownStreamGroupIds = downStreamGroupIds->GetNumberOfIds();
460
461 int i;
462 for (i=0; i<numberOfUpStreamGroupIds; i++)
463 {
464 bifurcationVectorsGroupIds->InsertNextId(upStreamGroupIds->GetId(i));
465 bifurcationVectorsOrientation->InsertNextValue(VTK_VMTK_UPSTREAM_ORIENTATION);
466 }
467 for (i=0; i<numberOfDownStreamGroupIds; i++)
468 {
469 bifurcationVectorsGroupIds->InsertNextId(downStreamGroupIds->GetId(i));
470 bifurcationVectorsOrientation->InsertNextValue(VTK_VMTK_DOWNSTREAM_ORIENTATION);
471 }
472
473 upStreamGroupIds->Delete();
474 downStreamGroupIds->Delete();
475
476 bifurcationVectors->Initialize();
477 bifurcationVectors->SetNumberOfComponents(3);
478
479 int numberOfBifurcationVectors = bifurcationVectorsGroupIds->GetNumberOfIds();
480
481 for (i=0; i<numberOfBifurcationVectors; i++)
482 {
483 int bifurcationVectorGroupId = bifurcationVectorsGroupIds->GetId(i);
484 int bifurcationVectorOrientation = bifurcationVectorsOrientation->GetValue(i);
485 double averageLastPoint[3], averageTouchingPoint[3];
486 averageLastPoint[0] = averageLastPoint[1] = averageLastPoint[2] = 0.0;
487 averageTouchingPoint[0] = averageTouchingPoint[1] = averageTouchingPoint[2] = 0.0;
488 double lastPointWeightSum = 0.0;
489 double touchingPointWeightSum = 0.0;
490 vtkIdList* groupCellIds = vtkIdList::New();
491 vtkvmtkCenterlineUtilities::GetGroupUniqueCellIds(input,this->GroupIdsArrayName,bifurcationVectorGroupId,groupCellIds);
492 for (int j=0; j<groupCellIds->GetNumberOfIds(); j++)
493 {
494 vtkIdType cellId = groupCellIds->GetId(j);
495 vtkCell* cell = input->GetCell(cellId);
496 int numberOfCellPoints = cell->GetNumberOfPoints();
497
498 vtkIdType touchingSubId = -1;
499 double touchingPCoord = 0.0;
500
501 vtkIdType pointSubId = -1;
502 double pointPCoord = 0.0;
503 bool forward = true;
504
505 double lastPoint[3];
506 double lastPointRadius = 0.0;
507
508 if (bifurcationVectorOrientation == VTK_VMTK_UPSTREAM_ORIENTATION)
509 {
510 pointSubId = numberOfCellPoints-2;
511 pointPCoord = 1.0;
512 forward = true;
513 cell->GetPoints()->GetPoint(numberOfCellPoints-1,lastPoint);
514 lastPointRadius = radiusArray->GetComponent(cell->GetPointId(numberOfCellPoints-1),0);
515 }
516 else if (bifurcationVectorOrientation == VTK_VMTK_DOWNSTREAM_ORIENTATION)
517 {
518 pointSubId = 0;
519 pointPCoord = 0.0;
520 forward = false;
521 cell->GetPoints()->GetPoint(0,lastPoint);
522 lastPointRadius = radiusArray->GetComponent(cell->GetPointId(0),0);
523 }
524 else
525 {
526 vtkErrorMacro("Error: invalid BifurcationVectorOrientation");
527 return;
528 }
529
530 vtkvmtkCenterlineSphereDistance::FindTouchingSphereCenter(input,this->RadiusArrayName,cellId,pointSubId,pointPCoord,touchingSubId,touchingPCoord,forward);
531
532 if (touchingSubId == -1)
533 {
534 touchingSubId = numberOfCellPoints-2;
535 touchingPCoord = 1.0;
536 }
537
538 //accumulate last point and touching point (weighted with radius^2)
539
540 averageLastPoint[0] += lastPointRadius * lastPointRadius * lastPoint[0];
541 averageLastPoint[1] += lastPointRadius * lastPointRadius * lastPoint[1];
542 averageLastPoint[2] += lastPointRadius * lastPointRadius * lastPoint[2];
543
544 lastPointWeightSum += lastPointRadius * lastPointRadius;
545 double touchingPoint[3], touchingPointRadius;
546 vtkvmtkCenterlineUtilities::InterpolatePoint(input,cellId,touchingSubId,touchingPCoord,touchingPoint);
547 vtkvmtkCenterlineUtilities::InterpolateTuple(input,this->RadiusArrayName,cellId,touchingSubId,touchingPCoord,&touchingPointRadius);
548
549 averageTouchingPoint[0] += touchingPointRadius * touchingPointRadius * touchingPoint[0];
550 averageTouchingPoint[1] += touchingPointRadius * touchingPointRadius * touchingPoint[1];
551 averageTouchingPoint[2] += touchingPointRadius * touchingPointRadius * touchingPoint[2];
552
553 touchingPointWeightSum += touchingPointRadius * touchingPointRadius;
554 }
555 groupCellIds->Delete();
556
557 averageLastPoint[0] /= lastPointWeightSum;
558 averageLastPoint[1] /= lastPointWeightSum;
559 averageLastPoint[2] /= lastPointWeightSum;
560
561 averageTouchingPoint[0] /= touchingPointWeightSum;
562 averageTouchingPoint[1] /= touchingPointWeightSum;
563 averageTouchingPoint[2] /= touchingPointWeightSum;
564
565 //build and store bifurcationVector for this group
566
567 double bifurcationVector[3], bifurcationVectorPoint[3];
568
569 if (bifurcationVectorOrientation == VTK_VMTK_UPSTREAM_ORIENTATION)
570 {
571 bifurcationVector[0] = averageLastPoint[0] - averageTouchingPoint[0];
572 bifurcationVector[1] = averageLastPoint[1] - averageTouchingPoint[1];
573 bifurcationVector[2] = averageLastPoint[2] - averageTouchingPoint[2];
574 bifurcationVectorPoint[0] = averageTouchingPoint[0];
575 bifurcationVectorPoint[1] = averageTouchingPoint[1];
576 bifurcationVectorPoint[2] = averageTouchingPoint[2];
577 }
578 else if (bifurcationVectorOrientation == VTK_VMTK_DOWNSTREAM_ORIENTATION)
579 {
580 bifurcationVector[0] = averageTouchingPoint[0] - averageLastPoint[0];
581 bifurcationVector[1] = averageTouchingPoint[1] - averageLastPoint[1];
582 bifurcationVector[2] = averageTouchingPoint[2] - averageLastPoint[2];
583 bifurcationVectorPoint[0] = averageLastPoint[0];
584 bifurcationVectorPoint[1] = averageLastPoint[1];
585 bifurcationVectorPoint[2] = averageLastPoint[2];
586 }
587 else
588 {
589 vtkErrorMacro("Error: invalid BifurcationVectorOrientation");
590 return;
591 }
592
594 {
595 vtkMath::Normalize(bifurcationVector);
596 }
597
598 bifurcationVectors->InsertNextTuple(bifurcationVector);
599 bifurcationVectorsPoints->InsertNextPoint(bifurcationVectorPoint);
600 }
601}
602
603void vtkvmtkCenterlineBifurcationVectors::ComputeBifurcationVectorComponents(int bifurcationGroupId, vtkDoubleArray* bifurcationVectors, vtkDoubleArray* inPlaneBifurcationVectors, vtkDoubleArray* outOfPlaneBifurcationVectors)
604{
605 // get the reference system, get the normal, project the angles.
606
607 vtkDataArray* referenceSystemNormalArray = this->ReferenceSystems->GetPointData()->GetArray(this->ReferenceSystemNormalArrayName);
608 vtkDataArray* referenceSystemUpNormalArray = this->ReferenceSystems->GetPointData()->GetArray(this->ReferenceSystemUpNormalArrayName);
609
610 inPlaneBifurcationVectors->Initialize();
611 inPlaneBifurcationVectors->SetNumberOfComponents(3);
612 outOfPlaneBifurcationVectors->Initialize();
613 outOfPlaneBifurcationVectors->SetNumberOfComponents(3);
614
616
617 double bifurcationPlaneNormal[3];
618 referenceSystemNormalArray->GetTuple(referenceSystemPointId,bifurcationPlaneNormal);
619
620 double bifurcationUpNormal[3];
621 referenceSystemUpNormalArray->GetTuple(referenceSystemPointId,bifurcationUpNormal);
622
623 double bifurcationVector[3], inPlaneBifurcationVector[3], outOfPlaneBifurcationVector[3];
624
625 int numberOfBifurcationVectors = bifurcationVectors->GetNumberOfTuples();
626
627 int j;
628 for (j=0; j<numberOfBifurcationVectors; j++)
629 {
630 bifurcationVectors->GetTuple(j,bifurcationVector);
631
632 double dot = vtkMath::Dot(bifurcationVector,bifurcationPlaneNormal);
633
634 outOfPlaneBifurcationVector[0] = dot * bifurcationPlaneNormal[0];
635 outOfPlaneBifurcationVector[1] = dot * bifurcationPlaneNormal[1];
636 outOfPlaneBifurcationVector[2] = dot * bifurcationPlaneNormal[2];
637
638 inPlaneBifurcationVector[0] = bifurcationVector[0] - outOfPlaneBifurcationVector[0];
639 inPlaneBifurcationVector[1] = bifurcationVector[1] - outOfPlaneBifurcationVector[1];
640 inPlaneBifurcationVector[2] = bifurcationVector[2] - outOfPlaneBifurcationVector[2];
641
642 inPlaneBifurcationVectors->InsertNextTuple(inPlaneBifurcationVector);
643 outOfPlaneBifurcationVectors->InsertNextTuple(outOfPlaneBifurcationVector);
644 }
645}
646
647void vtkvmtkCenterlineBifurcationVectors::ComputeBifurcationVectorAngles(int bifurcationGroupId, vtkDoubleArray* bifurcationVectors, vtkDoubleArray* inPlaneBifurcationVectors, vtkDoubleArray* outOfPlaneBifurcationVectors, vtkDoubleArray* inPlaneBifurcationVectorAngles, vtkDoubleArray* outOfPlaneBifurcationVectorAngles)
648{
649 vtkDataArray* referenceSystemNormalArray = this->ReferenceSystems->GetPointData()->GetArray(this->ReferenceSystemNormalArrayName);
650 vtkDataArray* referenceSystemUpNormalArray = this->ReferenceSystems->GetPointData()->GetArray(this->ReferenceSystemUpNormalArrayName);
651
653
654 double bifurcationPlaneNormal[3], bifurcationUpNormal[3];
655
656 referenceSystemNormalArray->GetTuple(referenceSystemPointId,bifurcationPlaneNormal);
657 referenceSystemUpNormalArray->GetTuple(referenceSystemPointId,bifurcationUpNormal);
658
659 int numberOfBifurcationVectors = bifurcationVectors->GetNumberOfTuples();
660 int i;
661 for (i=0; i<numberOfBifurcationVectors; i++)
662 {
663 double bifurcationVector[3], inPlaneBifurcationVector[3], outOfPlaneBifurcationVector[3];
664
665 bifurcationVectors->GetTuple(i,bifurcationVector);
666 inPlaneBifurcationVectors->GetTuple(i,inPlaneBifurcationVector);
667 outOfPlaneBifurcationVectors->GetTuple(i,outOfPlaneBifurcationVector);
668
669 vtkMath::Normalize(bifurcationVector);
670 vtkMath::Normalize(inPlaneBifurcationVector);
671
672 double inPlaneBifurcationVectorAngle = vtkvmtkMath::AngleBetweenNormals(inPlaneBifurcationVector,bifurcationUpNormal);
673 double cross[3];
674 vtkMath::Cross(inPlaneBifurcationVector,bifurcationUpNormal,cross);
675 if (vtkMath::Dot(cross,bifurcationPlaneNormal) < 0.0)
676 {
677 inPlaneBifurcationVectorAngle *= -1.0;
678 }
679
680 double outOfPlaneBifurcationVectorAngle = vtkMath::Pi()/2.0 - vtkvmtkMath::AngleBetweenNormals(bifurcationVector,bifurcationPlaneNormal);
681
682 inPlaneBifurcationVectorAngles->InsertNextValue(inPlaneBifurcationVectorAngle);
683 outOfPlaneBifurcationVectorAngles->InsertNextValue(outOfPlaneBifurcationVectorAngle);
684 }
685}
686
687void vtkvmtkCenterlineBifurcationVectors::PrintSelf(std::ostream& os, vtkIndent indent)
688{
689 this->Superclass::PrintSelf(os,indent);
690}
Compute vectors which represent the orientation of branches involved within a bifurcation from a spli...
void PrintSelf(std::ostream &os, vtkIndent indent) override
void ComputeBifurcationVectorComponents(int bifurcationGroupId, vtkDoubleArray *bifurcationVectors, vtkDoubleArray *inPlaneBifurcationVectors, vtkDoubleArray *outOfPlaneBifurcationVectors)
void ComputeBifurcationVectors(vtkPolyData *input, int bifurcationGroupId, vtkIdList *bifurcationVectorsGroupIds, vtkIntArray *bifurcationVectorsOrientation, vtkDoubleArray *bifurcationVectors, vtkPoints *bifurcationVectorsPoints)
void ComputeBifurcationVectorAngles(int bifurcationGroupId, vtkDoubleArray *bifurcationVectors, vtkDoubleArray *inPlaneBifurcationVectors, vtkDoubleArray *outOfPlaneBifurcationVectors, vtkDoubleArray *inPlaneBifurcationVectorAngles, vtkDoubleArray *outOfPlaneBifurcationVectorAngles)
virtual int RequestData(vtkInformation *, vtkInformationVector **, vtkInformationVector *) override
static void FindTouchingSphereCenter(vtkPolyData *centerlines, const char *radiusArrayName, vtkIdType cellId, vtkIdType subId, double pcoord, vtkIdType &touchingSubId, double &touchingPCoord, bool forward=true)
static void GetBlankedGroupsIdList(vtkPolyData *centerlines, const char *groupIdsArrayName, const char *blankingArrayName, vtkIdList *groupIds)
static void InterpolatePoint(vtkPolyData *centerlines, int cellId, int subId, double pcoord, double interpolatedPoint[3])
static void GetGroupUniqueCellIds(vtkPolyData *centerlines, const char *groupIdsArrayName, vtkIdType groupId, vtkIdList *groupCellIds)
static void InterpolateTuple(vtkPolyData *centerlines, const char *arrayName, int cellId, int subId, double pcoord, double *interpolatedTuple)
static void FindAdjacentCenterlineGroupIds(vtkPolyData *centerlines, const char *groupIdsArrayName, const char *centerlineIdsArrayName, const char *tractIdsArrayName, vtkIdType groupId, vtkIdList *upStreamGroupIds, vtkIdList *downStreamGroupIds)
static double AngleBetweenNormals(double normal0[3], double normal1[3])
static vtkIdType GetReferenceSystemPointId(vtkPolyData *referenceSystems, const char *groupIdsArrayName, vtkIdType groupId)
vtkStandardNewMacro(vtkvmtkCenterlineBifurcationVectors)