443{
445 vtkPoints* outputPoints = output->GetPoints();
446 vtkCellArray* outputPolys = output->GetPolys();
447 vtkDoubleArray* bifurcationSectionPointArray = vtkDoubleArray::SafeDownCast(output->GetCellData()->GetArray(this->BifurcationSectionPointArrayName));
448 vtkDoubleArray* bifurcationSectionNormalArray = vtkDoubleArray::SafeDownCast(output->GetCellData()->GetArray(this->BifurcationSectionNormalArrayName));
449 vtkDoubleArray* bifurcationSectionAreaArray = vtkDoubleArray::SafeDownCast(output->GetCellData()->GetArray(this->BifurcationSectionAreaArrayName));
450 vtkDoubleArray* bifurcationSectionMinSizeArray = vtkDoubleArray::SafeDownCast(output->GetCellData()->GetArray(this->BifurcationSectionMinSizeArrayName));
451 vtkDoubleArray* bifurcationSectionMaxSizeArray = vtkDoubleArray::SafeDownCast(output->GetCellData()->GetArray(this->BifurcationSectionMaxSizeArrayName));
452 vtkDoubleArray* bifurcationSectionShapeArray = vtkDoubleArray::SafeDownCast(output->GetCellData()->GetArray(this->BifurcationSectionShapeArrayName));
453 vtkIntArray* bifurcationSectionClosedArray = vtkIntArray::SafeDownCast(output->GetCellData()->GetArray(this->BifurcationSectionClosedArrayName));
454 vtkIntArray* bifurcationSectionOrientationArray = vtkIntArray::SafeDownCast(output->GetCellData()->GetArray(this->BifurcationSectionOrientationArrayName));
455 vtkIntArray* bifurcationSectionDistanceSpheresArray = vtkIntArray::SafeDownCast(output->GetCellData()->GetArray(this->BifurcationSectionDistanceSpheresArrayName));
456 vtkIntArray* bifurcationSectionGroupIdsArray = vtkIntArray::SafeDownCast(output->GetCellData()->GetArray(this->BifurcationSectionGroupIdsArrayName));
457 vtkIntArray* bifurcationSectionBifurcationGroupIdsArray = vtkIntArray::SafeDownCast(output->GetCellData()->GetArray(this->BifurcationSectionBifurcationGroupIdsArrayName));
458
459 vtkIdList* bifurcationSectionGroupIds = vtkIdList::New();
460 vtkIntArray* bifurcationSectionOrientations = vtkIntArray::New();
461
462 int numberOfUpStreamGroupIds = upStreamGroupIds->GetNumberOfIds();
463 int numberOfDownStreamGroupIds = downStreamGroupIds->GetNumberOfIds();
464 int i;
465 for (i=0; i<numberOfUpStreamGroupIds; i++)
466 {
467 bifurcationSectionGroupIds->InsertNextId(upStreamGroupIds->GetId(i));
469 }
470 for (i=0; i<numberOfDownStreamGroupIds; i++)
471 {
472 bifurcationSectionGroupIds->InsertNextId(downStreamGroupIds->GetId(i));
474 }
475
476 int numberOfBifurcationSections = bifurcationSectionGroupIds->GetNumberOfIds();
477
478 for (i=0; i<numberOfBifurcationSections; i++)
479 {
480 int bifurcationSectionGroupId = bifurcationSectionGroupIds->GetId(i);
481 int bifurcationSectionOrientation = bifurcationSectionOrientations->GetValue(i);
482
483 double averagePoint[3];
484 averagePoint[0] = averagePoint[1] = averagePoint[2] = 0.0;
485
486 double averageTangent[3];
487 averageTangent[0] = averageTangent[1] = averageTangent[2] = 0.0;
488
489 double weightSum = 0.0;
490
491 int j;
492 bool anyPoint = false;
493 vtkIdList* groupCellIds = vtkIdList::New();
495 for (j=0; j<groupCellIds->GetNumberOfIds(); j++)
496 {
497 vtkIdType cellId = groupCellIds->GetId(j);
498 vtkCell* cell = this->
Centerlines->GetCell(cellId);
499 int numberOfCellPoints = cell->GetNumberOfPoints();
500
501 vtkIdType touchingSubId = -1;
502 double touchingPCoord = 0.0;
503
504 vtkIdType pointSubId = -1;
505 double pointPCoord = 0.0;
506 bool forward = true;
507
508 double lastPoint[3];
509 double lastPointRadius = 0.0;
510
512 {
513 pointSubId = numberOfCellPoints-2;
514 pointPCoord = 1.0;
515 forward = true;
516 cell->GetPoints()->GetPoint(numberOfCellPoints-1,lastPoint);
517 lastPointRadius = radiusArray->GetComponent(cell->GetPointId(numberOfCellPoints-1),0);
518 }
520 {
521 pointSubId = 0;
522 pointPCoord = 0.0;
523 forward = false;
524 cell->GetPoints()->GetPoint(0,lastPoint);
525 lastPointRadius = radiusArray->GetComponent(cell->GetPointId(0),0);
526 }
527 else
528 {
529 vtkErrorMacro("Error: invalid BifurcationVectorOrientation");
530 return;
531 }
532
534
535 if (touchingSubId == -1)
536 {
537 continue;
538 }
539
540 anyPoint = true;
541 double touchingPoint[3];
543
544 double touchingPoint0[3], touchingPoint1[3];
545 this->
Centerlines->GetCell(cellId)->GetPoints()->GetPoint(touchingSubId,touchingPoint0);
546 this->
Centerlines->GetCell(cellId)->GetPoints()->GetPoint(touchingSubId+1,touchingPoint1);
547
548 double touchingPointTangent[3];
549 touchingPointTangent[0] = touchingPoint1[0] - touchingPoint0[0];
550 touchingPointTangent[1] = touchingPoint1[1] - touchingPoint0[1];
551 touchingPointTangent[2] = touchingPoint1[2] - touchingPoint0[2];
552
553 vtkMath::Normalize(touchingPointTangent);
554 double touchingPointRadius = 0.0;
556
557 averagePoint[0] += touchingPointRadius * touchingPointRadius * touchingPoint[0];
558 averagePoint[1] += touchingPointRadius * touchingPointRadius * touchingPoint[1];
559 averagePoint[2] += touchingPointRadius * touchingPointRadius * touchingPoint[2];
560
561 averageTangent[0] += touchingPointRadius * touchingPointRadius * touchingPointTangent[0];
562 averageTangent[1] += touchingPointRadius * touchingPointRadius * touchingPointTangent[1];
563 averageTangent[2] += touchingPointRadius * touchingPointRadius * touchingPointTangent[2];
564
565 weightSum += touchingPointRadius * touchingPointRadius;
566 }
567
568 if (!anyPoint)
569 {
570 continue;
571 }
572
573 averagePoint[0] /= weightSum;
574 averagePoint[1] /= weightSum;
575 averagePoint[2] /= weightSum;
576
577 averageTangent[0] /= weightSum;
578 averageTangent[1] /= weightSum;
579 averageTangent[2] /= weightSum;
580
581 vtkMath::Normalize(averageTangent);
582
583
584
585 vtkPolyData* cylinder = vtkPolyData::New();
587
588 vtkPolyData* section = vtkPolyData::New();
589 bool closed = false;
591
592 section->BuildCells();
593 if (section->GetNumberOfCells() == 0)
594 {
595 cylinder->Delete();
596 section->Delete();
597 continue;
598 }
599 vtkPoints* sectionCellPoints = section->GetCell(0)->GetPoints();
600 int numberOfSectionCellPoints = sectionCellPoints->GetNumberOfPoints();
601 outputPolys->InsertNextCell(numberOfSectionCellPoints);
602 for (j=0; j<numberOfSectionCellPoints; j++)
603 {
604 vtkIdType pointId = outputPoints->InsertNextPoint(sectionCellPoints->GetPoint(j));
605 outputPolys->InsertCellPoint(pointId);
606 }
607
609 double sizeRange[2];
611 int closedValue = closed ? 1 : 0;
612
613 bifurcationSectionGroupIdsArray->InsertNextValue(bifurcationSectionGroupId);
614 bifurcationSectionBifurcationGroupIdsArray->InsertNextValue(bifurcationGroupId);
615 bifurcationSectionPointArray->InsertNextTuple(averagePoint);
616 bifurcationSectionNormalArray->InsertNextTuple(averageTangent);
617 bifurcationSectionAreaArray->InsertNextValue(area);
618 bifurcationSectionMinSizeArray->InsertNextValue(sizeRange[0]);
619 bifurcationSectionMaxSizeArray->InsertNextValue(sizeRange[1]);
620 bifurcationSectionShapeArray->InsertNextValue(shape);
621 bifurcationSectionClosedArray->InsertNextValue(closedValue);
622 bifurcationSectionOrientationArray->InsertNextValue(bifurcationSectionOrientation);
624
625 groupCellIds->Delete();
626 cylinder->Delete();
627 section->Delete();
628 }
629
630 bifurcationSectionGroupIds->Delete();
631 bifurcationSectionOrientations->Delete();
632}
@ VTK_VMTK_DOWNSTREAM_ORIENTATION
@ VTK_VMTK_UPSTREAM_ORIENTATION
static void FindNTouchingSphereCenter(vtkPolyData *centerlines, const char *radiusArrayName, vtkIdType cellId, vtkIdType subId, double pcoord, int numberOfTouchingSpheres, vtkIdType &touchingSubId, double &touchingPCoord, bool forward=true)
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 InterpolateTuple1(vtkPolyData *centerlines, const char *arrayName, int cellId, int subId, double pcoord, double &interpolatedTuple1)
static double ComputeBranchSectionArea(vtkPolyData *branchSection)
static void ExtractCylinderSection(vtkPolyData *cylinder, double origin[3], double normal[3], vtkPolyData *section, bool &closed, const char *idsArrayName=nullptr)
static double ComputeBranchSectionShape(vtkPolyData *branchSection, double center[3], double sizeRange[2])
static void ExtractGroup(vtkPolyData *surface, const char *groupIdsArrayName, vtkIdType groupId, bool cleanGroupSurface, vtkPolyData *groupSurface)