VMTK
Loading...
Searching...
No Matches
vtkvmtkPolyDataBranchSections Class Reference

Extract a vessel (cross) section n-spheres distance from from the start point of a branch. More...

#include <vtkvmtkPolyDataBranchSections.h>

Inheritance diagram for vtkvmtkPolyDataBranchSections:
[legend]
Collaboration diagram for vtkvmtkPolyDataBranchSections:
[legend]

Public Types

typedef vtkPolyDataAlgorithm Superclass

Public Member Functions

virtual int IsA (const char *type)
vtkvmtkPolyDataBranchSections * NewInstance () const
void PrintSelf (std::ostream &os, vtkIndent indent) override
virtual void SetGroupIdsArrayName (const char *)
virtual char * GetGroupIdsArrayName ()
virtual void SetCenterlines (vtkPolyData *)
virtual vtkPolyData * GetCenterlines ()
virtual void SetCenterlineRadiusArrayName (const char *)
virtual char * GetCenterlineRadiusArrayName ()
virtual void SetCenterlineGroupIdsArrayName (const char *)
virtual char * GetCenterlineGroupIdsArrayName ()
virtual void SetCenterlineIdsArrayName (const char *)
virtual char * GetCenterlineIdsArrayName ()
virtual void SetCenterlineTractIdsArrayName (const char *)
virtual char * GetCenterlineTractIdsArrayName ()
virtual void SetBlankingArrayName (const char *)
virtual char * GetBlankingArrayName ()
virtual void SetBranchSectionAreaArrayName (const char *)
virtual char * GetBranchSectionAreaArrayName ()
virtual void SetBranchSectionMinSizeArrayName (const char *)
virtual char * GetBranchSectionMinSizeArrayName ()
virtual void SetBranchSectionMaxSizeArrayName (const char *)
virtual char * GetBranchSectionMaxSizeArrayName ()
virtual void SetBranchSectionShapeArrayName (const char *)
virtual char * GetBranchSectionShapeArrayName ()
virtual void SetBranchSectionGroupIdsArrayName (const char *)
virtual char * GetBranchSectionGroupIdsArrayName ()
virtual void SetBranchSectionClosedArrayName (const char *)
virtual char * GetBranchSectionClosedArrayName ()
virtual void SetBranchSectionDistanceSpheresArrayName (const char *)
virtual char * GetBranchSectionDistanceSpheresArrayName ()
virtual void SetNumberOfDistanceSpheres (int)
virtual int GetNumberOfDistanceSpheres ()
virtual void SetReverseDirection (int)
virtual int GetReverseDirection ()
virtual void ReverseDirectionOn ()
virtual void ReverseDirectionOff ()

Static Public Member Functions

static int IsTypeOf (const char *type)
static vtkvmtkPolyDataBranchSections * SafeDownCast (vtkObjectBase *o)
static vtkvmtkPolyDataBranchSections * New ()
static double ComputeBranchSectionArea (vtkPolyData *branchSection)
static double ComputeBranchSectionShape (vtkPolyData *branchSection, double center[3], double sizeRange[2])
static void ExtractCylinderSection (vtkPolyData *cylinder, double origin[3], double normal[3], vtkPolyData *section, bool &closed, const char *idsArrayName=nullptr)
static int CountBranchSectionCenterlines (vtkPolyData *section, vtkPolyData *centerlines, double origin[3], double normal[3])
static int CountBranchSectionIds (vtkPolyData *section, const char *idsArrayName)

Protected Member Functions

virtual vtkObjectBase * NewInstanceInternal () const
 vtkvmtkPolyDataBranchSections ()
 ~vtkvmtkPolyDataBranchSections ()
virtual int RequestData (vtkInformation *, vtkInformationVector **, vtkInformationVector *) override
void ComputeBranchSections (vtkPolyData *input, int groupId, vtkPolyData *output)

Protected Attributes

vtkPolyData * Centerlines
char * GroupIdsArrayName
char * CenterlineRadiusArrayName
char * CenterlineGroupIdsArrayName
char * CenterlineIdsArrayName
char * CenterlineTractIdsArrayName
char * BlankingArrayName
char * BranchSectionGroupIdsArrayName
char * BranchSectionAreaArrayName
char * BranchSectionMinSizeArrayName
char * BranchSectionMaxSizeArrayName
char * BranchSectionShapeArrayName
char * BranchSectionClosedArrayName
char * BranchSectionDistanceSpheresArrayName
int NumberOfDistanceSpheres
int ReverseDirection

Detailed Description

Extract a vessel (cross) section n-spheres distance from from the start point of a branch.

Takes as input a surface and centerlines that have both already been split into branches. This is the filter behind the vmtkbranchsections pype script; unlike vtkvmtkPolyDataBifurcationSections (which cuts near bifurcations), this class cuts one section per branch, at a fixed number of touching spheres from the branch's start (or end, if ReverseDirection is on).

See also
vtkvmtkPolyDataBifurcationSections

The set of vessel sections contain the profile as well as the the following information about the section:

  • Branch Section Group Ids
  • Branch Section Bifurcation Group Ids
  • Branch Section Orientation
  • Branch Section Distance Spheres
  • Branch Section Point
  • Branch Section Normal
  • Branch Section Area
  • Branch Section Min Size
  • Branch Section Max Size
  • Branch Section Shape
  • Branch Section Closed

Definition at line 53 of file vtkvmtkPolyDataBranchSections.h.

Member Typedef Documentation

◆ Superclass

typedef vtkPolyDataAlgorithm vtkvmtkPolyDataBranchSections::Superclass

Definition at line 56 of file vtkvmtkPolyDataBranchSections.h.

Constructor & Destructor Documentation

◆ vtkvmtkPolyDataBranchSections()

vtkvmtkPolyDataBranchSections::vtkvmtkPolyDataBranchSections ( )
protected

Definition at line 62 of file vtkvmtkPolyDataBranchSections.cxx.

63{
64 this->GroupIdsArrayName = NULL;
65
66 this->Centerlines = NULL;
67
68 this->CenterlineRadiusArrayName = NULL;
69 this->CenterlineGroupIdsArrayName = NULL;
70 this->CenterlineIdsArrayName = NULL;
71 this->CenterlineTractIdsArrayName = NULL;
72 this->BlankingArrayName = NULL;
73
75 this->BranchSectionAreaArrayName = NULL;
78 this->BranchSectionShapeArrayName = NULL;
81
83 this->ReverseDirection = 0;
84}

◆ ~vtkvmtkPolyDataBranchSections()

vtkvmtkPolyDataBranchSections::~vtkvmtkPolyDataBranchSections ( )
protected

Definition at line 86 of file vtkvmtkPolyDataBranchSections.cxx.

87{
88 if (this->GroupIdsArrayName)
89 {
90 delete[] this->GroupIdsArrayName;
91 this->GroupIdsArrayName = NULL;
92 }
93
94 if (this->Centerlines)
95 {
96 this->Centerlines->Delete();
97 this->Centerlines = NULL;
98 }
99
101 {
102 delete[] this->CenterlineRadiusArrayName;
103 this->CenterlineRadiusArrayName = NULL;
104 }
105
107 {
108 delete[] this->CenterlineGroupIdsArrayName;
109 this->CenterlineGroupIdsArrayName = NULL;
110 }
111
112 if (this->CenterlineIdsArrayName)
113 {
114 delete[] this->CenterlineIdsArrayName;
115 this->CenterlineIdsArrayName = NULL;
116 }
117
119 {
120 delete[] this->CenterlineTractIdsArrayName;
121 this->CenterlineTractIdsArrayName = NULL;
122 }
123
124 if (this->BlankingArrayName)
125 {
126 delete[] this->BlankingArrayName;
127 this->BlankingArrayName = NULL;
128 }
129
131 {
132 delete[] this->BranchSectionGroupIdsArrayName;
134 }
135
137 {
138 delete[] this->BranchSectionAreaArrayName;
139 this->BranchSectionAreaArrayName = NULL;
140 }
141
143 {
144 delete[] this->BranchSectionMinSizeArrayName;
146 }
147
149 {
150 delete[] this->BranchSectionMaxSizeArrayName;
152 }
153
155 {
156 delete[] this->BranchSectionShapeArrayName;
157 this->BranchSectionShapeArrayName = NULL;
158 }
159
161 {
162 delete[] this->BranchSectionClosedArrayName;
163 this->BranchSectionClosedArrayName = NULL;
164 }
165
167 {
170 }
171}

Member Function Documentation

◆ IsTypeOf()

int vtkvmtkPolyDataBranchSections::IsTypeOf ( const char * type)
static

◆ IsA()

virtual int vtkvmtkPolyDataBranchSections::IsA ( const char * type)
virtual

◆ SafeDownCast()

vtkvmtkPolyDataBranchSections * vtkvmtkPolyDataBranchSections::SafeDownCast ( vtkObjectBase * o)
static

◆ NewInstanceInternal()

virtual vtkObjectBase * vtkvmtkPolyDataBranchSections::NewInstanceInternal ( ) const
protectedvirtual

◆ NewInstance()

vtkvmtkPolyDataBranchSections * vtkvmtkPolyDataBranchSections::NewInstance ( ) const

◆ PrintSelf()

void vtkvmtkPolyDataBranchSections::PrintSelf ( std::ostream & os,
vtkIndent indent )
override

Definition at line 1180 of file vtkvmtkPolyDataBranchSections.cxx.

1181{
1182 this->Superclass::PrintSelf(os,indent);
1183}

◆ New()

vtkvmtkPolyDataBranchSections * vtkvmtkPolyDataBranchSections::New ( )
static

◆ SetGroupIdsArrayName()

virtual void vtkvmtkPolyDataBranchSections::SetGroupIdsArrayName ( const char * )
virtual

Set/Get the name of the cell data array of the input surface holding the branch group id of each cell. Required input. Commonly named "GroupIds".

◆ GetGroupIdsArrayName()

virtual char * vtkvmtkPolyDataBranchSections::GetGroupIdsArrayName ( )
virtual

Set/Get the name of the cell data array of the input surface holding the branch group id of each cell. Required input. Commonly named "GroupIds".

◆ SetCenterlines()

virtual void vtkvmtkPolyDataBranchSections::SetCenterlines ( vtkPolyData * )
virtual

Set/Get the split, grouped centerlines corresponding to the input surface. Required input.

◆ GetCenterlines()

virtual vtkPolyData * vtkvmtkPolyDataBranchSections::GetCenterlines ( )
virtual

Set/Get the split, grouped centerlines corresponding to the input surface. Required input.

◆ SetCenterlineRadiusArrayName()

virtual void vtkvmtkPolyDataBranchSections::SetCenterlineRadiusArrayName ( const char * )
virtual

Set/Get the name of the point data array of Centerlines holding the maximum inscribed sphere radius at each point. Commonly named "MaximumInscribedSphereRadius".

◆ GetCenterlineRadiusArrayName()

virtual char * vtkvmtkPolyDataBranchSections::GetCenterlineRadiusArrayName ( )
virtual

Set/Get the name of the point data array of Centerlines holding the maximum inscribed sphere radius at each point. Commonly named "MaximumInscribedSphereRadius".

◆ SetCenterlineGroupIdsArrayName()

virtual void vtkvmtkPolyDataBranchSections::SetCenterlineGroupIdsArrayName ( const char * )
virtual

Set/Get the name of the cell data array of Centerlines holding the branch group id of each cell. Commonly named "GroupIds".

◆ GetCenterlineGroupIdsArrayName()

virtual char * vtkvmtkPolyDataBranchSections::GetCenterlineGroupIdsArrayName ( )
virtual

Set/Get the name of the cell data array of Centerlines holding the branch group id of each cell. Commonly named "GroupIds".

◆ SetCenterlineIdsArrayName()

virtual void vtkvmtkPolyDataBranchSections::SetCenterlineIdsArrayName ( const char * )
virtual

Set/Get the name of the cell data array of Centerlines holding the id of the original, unsplit centerline that each cell belongs to. Commonly named "CenterlineIds".

◆ GetCenterlineIdsArrayName()

virtual char * vtkvmtkPolyDataBranchSections::GetCenterlineIdsArrayName ( )
virtual

Set/Get the name of the cell data array of Centerlines holding the id of the original, unsplit centerline that each cell belongs to. Commonly named "CenterlineIds".

◆ SetCenterlineTractIdsArrayName()

virtual void vtkvmtkPolyDataBranchSections::SetCenterlineTractIdsArrayName ( const char * )
virtual

Set/Get the name of the cell data array of Centerlines holding the tract id of each cell. Commonly named "TractIds".

◆ GetCenterlineTractIdsArrayName()

virtual char * vtkvmtkPolyDataBranchSections::GetCenterlineTractIdsArrayName ( )
virtual

Set/Get the name of the cell data array of Centerlines holding the tract id of each cell. Commonly named "TractIds".

◆ SetBlankingArrayName()

virtual void vtkvmtkPolyDataBranchSections::SetBlankingArrayName ( const char * )
virtual

Set/Get the name of the cell data array of Centerlines holding, for each cell, whether it is a "blanked" (redundant, overlapping) tract. Commonly named "Blanking".

◆ GetBlankingArrayName()

virtual char * vtkvmtkPolyDataBranchSections::GetBlankingArrayName ( )
virtual

Set/Get the name of the cell data array of Centerlines holding, for each cell, whether it is a "blanked" (redundant, overlapping) tract. Commonly named "Blanking".

◆ SetBranchSectionAreaArrayName()

virtual void vtkvmtkPolyDataBranchSections::SetBranchSectionAreaArrayName ( const char * )
virtual

Set/Get the name of the output cell data array where the cross-sectional area of each branch section is stored. Commonly named "BranchSectionArea".

◆ GetBranchSectionAreaArrayName()

virtual char * vtkvmtkPolyDataBranchSections::GetBranchSectionAreaArrayName ( )
virtual

Set/Get the name of the output cell data array where the cross-sectional area of each branch section is stored. Commonly named "BranchSectionArea".

◆ SetBranchSectionMinSizeArrayName()

virtual void vtkvmtkPolyDataBranchSections::SetBranchSectionMinSizeArrayName ( const char * )
virtual

Set/Get the name of the output cell data array where the minimum diameter of each branch section is stored. Commonly named "BranchSectionMinSize".

◆ GetBranchSectionMinSizeArrayName()

virtual char * vtkvmtkPolyDataBranchSections::GetBranchSectionMinSizeArrayName ( )
virtual

Set/Get the name of the output cell data array where the minimum diameter of each branch section is stored. Commonly named "BranchSectionMinSize".

◆ SetBranchSectionMaxSizeArrayName()

virtual void vtkvmtkPolyDataBranchSections::SetBranchSectionMaxSizeArrayName ( const char * )
virtual

Set/Get the name of the output cell data array where the maximum diameter of each branch section is stored. Commonly named "BranchSectionMaxSize".

◆ GetBranchSectionMaxSizeArrayName()

virtual char * vtkvmtkPolyDataBranchSections::GetBranchSectionMaxSizeArrayName ( )
virtual

Set/Get the name of the output cell data array where the maximum diameter of each branch section is stored. Commonly named "BranchSectionMaxSize".

◆ SetBranchSectionShapeArrayName()

virtual void vtkvmtkPolyDataBranchSections::SetBranchSectionShapeArrayName ( const char * )
virtual

Set/Get the name of the output cell data array where the shape index of each branch section (the ratio between its minimum and maximum diameter) is stored. Commonly named "BranchSectionShape".

◆ GetBranchSectionShapeArrayName()

virtual char * vtkvmtkPolyDataBranchSections::GetBranchSectionShapeArrayName ( )
virtual

Set/Get the name of the output cell data array where the shape index of each branch section (the ratio between its minimum and maximum diameter) is stored. Commonly named "BranchSectionShape".

◆ SetBranchSectionGroupIdsArrayName()

virtual void vtkvmtkPolyDataBranchSections::SetBranchSectionGroupIdsArrayName ( const char * )
virtual

Set/Get the name of the output cell data array where the group id (branch) that each section belongs to is stored. Commonly named "BranchSectionGroupIds".

◆ GetBranchSectionGroupIdsArrayName()

virtual char * vtkvmtkPolyDataBranchSections::GetBranchSectionGroupIdsArrayName ( )
virtual

Set/Get the name of the output cell data array where the group id (branch) that each section belongs to is stored. Commonly named "BranchSectionGroupIds".

◆ SetBranchSectionClosedArrayName()

virtual void vtkvmtkPolyDataBranchSections::SetBranchSectionClosedArrayName ( const char * )
virtual

Set/Get the name of the output cell data array where, for each section, whether the cutting plane fully closes off the vessel lumen (1) or not (0) is stored. Commonly named "BranchSectionClosed".

◆ GetBranchSectionClosedArrayName()

virtual char * vtkvmtkPolyDataBranchSections::GetBranchSectionClosedArrayName ( )
virtual

Set/Get the name of the output cell data array where, for each section, whether the cutting plane fully closes off the vessel lumen (1) or not (0) is stored. Commonly named "BranchSectionClosed".

◆ SetBranchSectionDistanceSpheresArrayName()

virtual void vtkvmtkPolyDataBranchSections::SetBranchSectionDistanceSpheresArrayName ( const char * )
virtual

Set/Get the name of the output cell data array where the number of touching spheres (see NumberOfDistanceSpheres) each section was cut at is stored. Commonly named "BranchSectionDistanceSpheres".

◆ GetBranchSectionDistanceSpheresArrayName()

virtual char * vtkvmtkPolyDataBranchSections::GetBranchSectionDistanceSpheresArrayName ( )
virtual

Set/Get the name of the output cell data array where the number of touching spheres (see NumberOfDistanceSpheres) each section was cut at is stored. Commonly named "BranchSectionDistanceSpheres".

◆ SetNumberOfDistanceSpheres()

virtual void vtkvmtkPolyDataBranchSections::SetNumberOfDistanceSpheres ( int )
virtual

Set/Get the distance from the branch's start point (or end point, if ReverseDirection is on) at which the section is cut, expressed in number of touching inscribed spheres (each sphere touching the center of the previous one). Default: 1.

◆ GetNumberOfDistanceSpheres()

virtual int vtkvmtkPolyDataBranchSections::GetNumberOfDistanceSpheres ( )
virtual

Set/Get the distance from the branch's start point (or end point, if ReverseDirection is on) at which the section is cut, expressed in number of touching inscribed spheres (each sphere touching the center of the previous one). Default: 1.

◆ SetReverseDirection()

virtual void vtkvmtkPolyDataBranchSections::SetReverseDirection ( int )
virtual

Toggle measuring NumberOfDistanceSpheres from the end of each branch instead of its start. Default: off.

◆ GetReverseDirection()

virtual int vtkvmtkPolyDataBranchSections::GetReverseDirection ( )
virtual

Toggle measuring NumberOfDistanceSpheres from the end of each branch instead of its start. Default: off.

◆ ReverseDirectionOn()

virtual void vtkvmtkPolyDataBranchSections::ReverseDirectionOn ( )
virtual

Toggle measuring NumberOfDistanceSpheres from the end of each branch instead of its start. Default: off.

◆ ReverseDirectionOff()

virtual void vtkvmtkPolyDataBranchSections::ReverseDirectionOff ( )
virtual

Toggle measuring NumberOfDistanceSpheres from the end of each branch instead of its start. Default: off.

◆ ComputeBranchSectionArea()

double vtkvmtkPolyDataBranchSections::ComputeBranchSectionArea ( vtkPolyData * branchSection)
static

Compute the area of a single cross-section polygon (typically one cell of the output).

Definition at line 772 of file vtkvmtkPolyDataBranchSections.cxx.

773{
774 branchSection->BuildCells();
775
776 if (branchSection->GetNumberOfCells() == 0)
777 {
778 return 0.0;
779 }
780
781 vtkPolygon* sectionPolygon = vtkPolygon::SafeDownCast(branchSection->GetCell(0));
782
783 vtkIdList* trianglePointIds = vtkIdList::New();
784
785 sectionPolygon->EarCutTriangulation(trianglePointIds);
786
787 int numberOfTriangles = trianglePointIds->GetNumberOfIds() / 3;
788
789 double polygonArea = 0.0;
790
791 for (int i=0; i<numberOfTriangles; i++)
792 {
793 vtkIdType pointId0 = trianglePointIds->GetId(3*i);
794 vtkIdType pointId1 = trianglePointIds->GetId(3*i+1);
795 vtkIdType pointId2 = trianglePointIds->GetId(3*i+2);
796
797 double point0[3], point1[3], point2[3];
798
799 sectionPolygon->GetPoints()->GetPoint(pointId0,point0);
800 sectionPolygon->GetPoints()->GetPoint(pointId1,point1);
801 sectionPolygon->GetPoints()->GetPoint(pointId2,point2);
802
803 double triangleArea = vtkTriangle::TriangleArea(point0,point1,point2);
804
805 polygonArea += triangleArea;
806 }
807
808 trianglePointIds->Delete();
809
810 return polygonArea;
811}

◆ ComputeBranchSectionShape()

double vtkvmtkPolyDataBranchSections::ComputeBranchSectionShape ( vtkPolyData * branchSection,
double center[3],
double sizeRange[2] )
static

Compute the shape index (ratio of minimum to maximum diameter) of a single cross-section polygon, also returning its center and the [min,max] diameter range in sizeRange.

Definition at line 856 of file vtkvmtkPolyDataBranchSections.cxx.

857{
858 branchSection->BuildCells();
859
860 if (branchSection->GetNumberOfCells() == 0)
861 {
862 sizeRange[0] = sizeRange[1] = 0.0;
863 return 0.0;
864 }
865
866 vtkPolygon* sectionPolygon = vtkPolygon::SafeDownCast(branchSection->GetCell(0));
867
868 int numberOfSectionPolygonPoints = sectionPolygon->GetNumberOfPoints();
869
870 double minDistance = VTK_VMTK_LARGE_DOUBLE;
871 double maxDistance = 0.0;
872
873 vtkIdType minDistanceId = -1;
874 vtkIdType maxDistanceId = -1;
875 double point[3];
876
877 for (int i=0; i<numberOfSectionPolygonPoints; i++)
878 {
879 sectionPolygon->GetPoints()->GetPoint(i,point);
880 double distance = sqrt(vtkMath::Distance2BetweenPoints(point,center));
881
882 if (distance > maxDistance)
883 {
884 maxDistance = distance;
885 maxDistanceId = i;
886 }
887
888 if (distance < minDistance)
889 {
890 minDistance = distance;
891 minDistanceId = i;
892 }
893 }
894
895 if (minDistance == -1 || maxDistance == -1)
896 {
897 sizeRange[0] = 0.0;
898 sizeRange[1] = 0.0;
899 return 0.0;
900 }
901
902 double point0[3];
903 double point1[3];
904
905 double planeNormal[3];
906 double radialVector0[3];
907 double radialVector1[3];
908 double cross[3];
909
910 planeNormal[0] = 0.0;
911 planeNormal[1] = 0.0;
912 planeNormal[2] = 0.0;
913
914 for (int i=0; i<numberOfSectionPolygonPoints; i++)
915 {
916 sectionPolygon->GetPoints()->GetPoint(i,point0);
917 sectionPolygon->GetPoints()->GetPoint((i+numberOfSectionPolygonPoints/4)%numberOfSectionPolygonPoints,point1);
918
919 radialVector0[0] = point0[0] - center[0];
920 radialVector0[1] = point0[1] - center[1];
921 radialVector0[2] = point0[2] - center[2];
922
923 radialVector1[0] = point1[0] - center[0];
924 radialVector1[1] = point1[1] - center[1];
925 radialVector1[2] = point1[2] - center[2];
926
927 vtkMath::Cross(point0,point1,cross);
928
929 planeNormal[0] += cross[0];
930 planeNormal[1] += cross[1];
931 planeNormal[2] += cross[2];
932 }
933
934 vtkMath::Normalize(planeNormal);
935
936 double minDistancePoint[3];
937 sectionPolygon->GetPoints()->GetPoint(minDistanceId,minDistancePoint);
938
939 double maxDistancePoint[3];
940 sectionPolygon->GetPoints()->GetPoint(maxDistanceId,maxDistancePoint);
941
942 double minDistanceNormal[3];
943 double maxDistanceNormal[3];
944
945 minDistanceNormal[0] = minDistancePoint[0] - center[0];
946 minDistanceNormal[1] = minDistancePoint[1] - center[1];
947 minDistanceNormal[2] = minDistancePoint[2] - center[2];
948
949 vtkMath::Normalize(minDistanceNormal);
950
951 maxDistanceNormal[0] = maxDistancePoint[0] - center[0];
952 maxDistanceNormal[1] = maxDistancePoint[1] - center[1];
953 maxDistanceNormal[2] = maxDistancePoint[2] - center[2];
954
955 vtkMath::Normalize(maxDistanceNormal);
956
957 double minDistanceOppositePoint[3];
958 double maxDistanceOppositePoint[3];
959
960 minDistanceOppositePoint[0] = center[0] - 2.0 * maxDistance * minDistanceNormal[0];
961 minDistanceOppositePoint[1] = center[1] - 2.0 * maxDistance * minDistanceNormal[1];
962 minDistanceOppositePoint[2] = center[2] - 2.0 * maxDistance * minDistanceNormal[2];
963
964 maxDistanceOppositePoint[0] = center[0] - 2.0 * maxDistance * maxDistanceNormal[0];
965 maxDistanceOppositePoint[1] = center[1] - 2.0 * maxDistance * maxDistanceNormal[1];
966 maxDistanceOppositePoint[2] = center[2] - 2.0 * maxDistance * maxDistanceNormal[2];
967
968 double intersectionPoint[3];
969 double maxIntersectionDistance = 0.0;
970
971 int intersection;
972 double u,v;
973 for (int i=0; i<numberOfSectionPolygonPoints; i++)
974 {
975 sectionPolygon->GetPoints()->GetPoint(i,point0);
976 sectionPolygon->GetPoints()->GetPoint((i+1)%numberOfSectionPolygonPoints,point1);
977
978 intersection = vtkLine::Intersection(minDistanceOppositePoint,center,point0,point1,u,v);
979
980 if (intersection == 0)
981 {
982 continue;
983 }
984
985 intersectionPoint[0] = (1.0 - u) * minDistanceOppositePoint[0] + u * center[0];
986 intersectionPoint[1] = (1.0 - u) * minDistanceOppositePoint[1] + u * center[1];
987 intersectionPoint[2] = (1.0 - u) * minDistanceOppositePoint[2] + u * center[2];
988
989 double intersectionDistance = sqrt(vtkMath::Distance2BetweenPoints(intersectionPoint,center));
990
991 if (intersectionDistance > maxIntersectionDistance)
992 {
993 maxIntersectionDistance = intersectionDistance;
994 }
995 }
996
997 minDistance += maxIntersectionDistance;
998
999 maxIntersectionDistance = 0.0;
1000
1001 for (int i=0; i<numberOfSectionPolygonPoints; i++)
1002 {
1003 sectionPolygon->GetPoints()->GetPoint(i,point0);
1004 sectionPolygon->GetPoints()->GetPoint((i+1)%numberOfSectionPolygonPoints,point1);
1005
1006 intersection = vtkLine::Intersection(maxDistanceOppositePoint,center,point0,point1,u,v);
1007
1008 if (intersection == 0)
1009 {
1010 continue;
1011 }
1012
1013 intersectionPoint[0] = (1.0 - u) * maxDistanceOppositePoint[0] + u * center[0];
1014 intersectionPoint[1] = (1.0 - u) * maxDistanceOppositePoint[1] + u * center[1];
1015 intersectionPoint[2] = (1.0 - u) * maxDistanceOppositePoint[2] + u * center[2];
1016
1017 double intersectionDistance = sqrt(vtkMath::Distance2BetweenPoints(intersectionPoint,center));
1018
1019 if (intersectionDistance > maxIntersectionDistance)
1020 {
1021 maxIntersectionDistance = intersectionDistance;
1022 }
1023 }
1024
1025 maxDistance += maxIntersectionDistance;
1026
1027 sizeRange[0] = minDistance;
1028 sizeRange[1] = maxDistance;
1029
1030 double sectionShape = minDistance / maxDistance;
1031
1032 return sectionShape;
1033}
#define VTK_VMTK_LARGE_DOUBLE

◆ ExtractCylinderSection()

void vtkvmtkPolyDataBranchSections::ExtractCylinderSection ( vtkPolyData * cylinder,
double origin[3],
double normal[3],
vtkPolyData * section,
bool & closed,
const char * idsArrayName = nullptr )
static

Cut a surface with a plane (specified by origin and normal) and store the cross-section as a single polygon cell in section.

The name comes from this class cutting one branch at a time, but the input does not have to be a cylinder or even tube-like: any polygonal surface can be cut, such as a whole vessel tree. When the plane cuts the surface along several separate contours (for example across two vessels), only the connected contour that contains the cut point closest to origin is kept. The polygon points are ordered along the contour, so section can be passed directly to ComputeBranchSectionArea and ComputeBranchSectionShape.

closed is set to true if the contour is a closed loop. It is false if the contour is open, for example when the plane crosses an open end of the surface; the polygon then closes the gap with a straight edge, so its area and shape are not meaningful. If the plane does not cut the surface, section is left empty (it has no cells) and closed is false; any previous content of section is discarded.

If idsArrayName is set, that point data array of cylinder, such as vessel or branch labels, is copied to the points of section, so that CountBranchSectionIds can be used on the result. The values are not interpolated: each section point takes the value of the nearer end point of the cut surface edge it lies on, so the array only contains values that exist on the surface. No other point data and no cell data is copied, and if cylinder has no such array, section has no point data. Default: none.

Definition at line 583 of file vtkvmtkPolyDataBranchSections.cxx.

584{
585 // Start from an empty section, so that a section with no cells always
586 // means that no section was found, even if section held an earlier cut.
587 section->Initialize();
588 closed = false;
589
590 vtkNew<vtkPlane> plane;
591 plane->SetOrigin(origin);
592 plane->SetNormal(normal);
593
594 vtkDataArray* surfaceIdsArray = idsArrayName != NULL ? cylinder->GetPointData()->GetArray(idsArrayName) : NULL;
595
596 vtkNew<vtkCutter> cutter;
597 vtkNew<vtkPolyData> cutInput;
598 if (surfaceIdsArray != NULL)
599 {
600 // The ids are not interpolated by the cutter but copied afterwards, so the
601 // surface is cut without its attributes, with only the source cell id of
602 // each cell attached.
603 cutInput->CopyStructure(cylinder);
604 vtkNew<vtkIdTypeArray> sourceCellIds;
605 sourceCellIds->SetName(SourceCellIdsArrayName);
606 sourceCellIds->SetNumberOfValues(cutInput->GetNumberOfCells());
607 for (vtkIdType i=0; i<cutInput->GetNumberOfCells(); i++)
608 {
609 sourceCellIds->SetValue(i,i);
610 }
611 cutInput->GetCellData()->AddArray(sourceCellIds);
612 cutter->SetInputData(cutInput);
613 }
614 else
615 {
616 cutter->SetInputData(cylinder);
617 }
618 cutter->SetCutFunction(plane);
619 // Without cut scalars the cutter passes no cell data on to its output, so
620 // section points could not be traced back to the cut surface cells.
621 cutter->GenerateCutScalarsOn();
622 cutter->SetValue(0,0.0);
623 cutter->Update();
624
625 vtkNew<vtkCleanPolyData> cleaner;
626 if (surfaceIdsArray != NULL)
627 {
628 cleaner->SetInputConnection(cutter->GetOutputPort());
629 }
630 else
631 {
632 // Interpolating and merging attributes nobody reads would be wasted
633 // work, so only the geometry of the cut is passed on.
634 vtkNew<vtkPolyData> cutGeometry;
635 cutGeometry->CopyStructure(cutter->GetOutput());
636 cleaner->SetInputData(cutGeometry);
637 }
638 cleaner->Update();
639
640 if (cleaner->GetOutput()->GetNumberOfPoints() == 0)
641 {
642 return;
643 }
644
645 vtkNew<vtkPolyDataConnectivityFilter> connectivityFilter;
646 connectivityFilter->SetInputConnection(cleaner->GetOutputPort());
647 connectivityFilter->SetExtractionModeToClosestPointRegion();
648 connectivityFilter->SetClosestPoint(origin);
649 connectivityFilter->Update();
650
651 section->DeepCopy(connectivityFilter->GetOutput());
652
653 // TODO: manually reconstruct single cell line from connectivity output
654
655 if (section->GetNumberOfCells() == 0)
656 {
657 return;
658 }
659
660 section->BuildCells();
661 section->BuildLinks();
662
663 if (surfaceIdsArray != NULL)
664 {
665 CopyIdsFromNearestEdgePoint(cylinder,surfaceIdsArray,section);
666 }
667
668 // find first point
669
670 int numberOfLinePoints = section->GetNumberOfPoints();
671
672 vtkIdType* cells;
673 vtkIdType npts;
674 const vtkIdType *pts;
675 vtkIdType ncells;
676
677 int numberOfSingleCellPoints = 0;
678 vtkIdType firstPointId = -1;
679
680 for (int i=0; i<numberOfLinePoints; i++)
681 {
682 section->GetPointCells(i,ncells,cells);
683 if (ncells == 1)
684 {
685 ++numberOfSingleCellPoints;
686 firstPointId = i;
687 }
688 }
689
690 if (numberOfSingleCellPoints == 0)
691 {
692 firstPointId = section->GetCell(0)->GetPointId(0);
693 }
694
695 vtkNew<vtkIdList> polygonPointIds;
696 polygonPointIds->InsertNextId(firstPointId);
697
698 bool done = false;
699 vtkIdType pointId = firstPointId;
700
701 vtkIdType cellId = -1;
702 while (!done)
703 {
704 section->GetPointCells(pointId,ncells,cells);
705 if (ncells == 1)
706 {
707 if (pointId == firstPointId)
708 {
709 cellId = cells[0];
710 }
711 else
712 {
713 done = true;
714 break;
715 }
716 }
717 else if (ncells == 2)
718 {
719 if (cells[0] == cellId)
720 {
721 cellId = cells[1];
722 }
723 else
724 {
725 cellId = cells[0];
726 }
727 }
728
729 section->GetCellPoints(cellId,npts,pts);
730
731 if (pts[0] == pointId)
732 {
733 pointId = pts[1];
734 }
735 else
736 {
737 pointId = pts[0];
738 }
739
740 if (pointId == firstPointId)
741 {
742 closed = true;
743 done = true;
744 break;
745 }
746
747 polygonPointIds->InsertNextId(pointId);
748 }
749
750 // Replace the connectivity line cells with the single reconstructed
751 // polygon. The arrays returned by GetLines()/GetPolys() must not be
752 // mutated in place: since VTK 9, GetPolys() hands back a dummy container
753 // when the polydata has no polys, so a polygon inserted into it would be
754 // lost. Also drop the cell map and links built above - they refer to the
755 // discarded line cells, and vtkPolyData::BuildCells() does not rebuild an
756 // existing map, so callers would crash reading the new cell through the
757 // stale bookkeeping.
758 vtkNew<vtkCellArray> sectionLines;
759 section->SetLines(sectionLines);
760
761 vtkNew<vtkCellArray> sectionPolys;
762 sectionPolys->InsertNextCell(polygonPointIds);
763 section->SetPolys(sectionPolys);
764
765 // The line cells carried the cell data; the polygon has none of its own.
766 section->GetCellData()->Initialize();
767
768 section->DeleteCells();
769 section->DeleteLinks();
770}

◆ CountBranchSectionCenterlines()

int vtkvmtkPolyDataBranchSections::CountBranchSectionCenterlines ( vtkPolyData * section,
vtkPolyData * centerlines,
double origin[3],
double normal[3] )
static

Count how many centerlines pass through a vessel cross-section.

centerlines is cut with the plane (specified by origin and normal), and the crossing points that lie inside the first cell of section are counted. section must be the polygon returned by ExtractCylinderSection for the same plane. Returns 0 if section has fewer than 3 points or no centerline crosses the plane.

The count tells whether a section cuts a single vessel or reaches into a bifurcation region: a section perpendicular to a branch contains only that branch's centerline, while near a bifurcation the section widens to include the centerlines of the child vessels as well. For example, cutting a section at each centerline point with the centerline tangent as normal and marking the points with a count other than 1 delineates the bifurcation regions along the centerlines. Similarly, the count can confirm that a section used for area or diameter measurement cuts only one vessel.

Each crossing point is counted once, so centerlines must not overlap. Centerlines computed from the inlet to each outlet run almost on top of each other along their shared segments, where a section would count each of them; merge them into a single tree without duplicated segments first. A count of 1 is not a guarantee that the section is outside a bifurcation region, since an oblique plane may miss a nearby centerline; CountBranchSectionIds can be used as an additional check.

Definition at line 1036 of file vtkvmtkPolyDataBranchSections.cxx.

1037{
1038 section->BuildCells();
1039
1040 if (section->GetNumberOfCells() == 0)
1041 {
1042 return 0;
1043 }
1044
1045 // The points where the centerline segments cross the plane. This is called
1046 // for every centerline point, and the setup of a vtkCutter for lines of a
1047 // few thousand points costs several times the crossings themselves, so they
1048 // are computed here, the same way as vtkCutter with vtkLine::Contour: the
1049 // signed distance of each point is stored as a float, a segment is crossed
1050 // where the distance of one end is below 0 and of the other at or above 0,
1051 // the crossing is interpolated from the end below 0 and stored with the
1052 // precision of the centerline points, and crossings at the same coordinates
1053 // are one point.
1054 std::set<std::array<double,3>> crossingPoints;
1055 if (centerlines->GetPoints())
1056 {
1057 std::vector<double> signedDistances(centerlines->GetNumberOfPoints());
1058 double point[3];
1059 for (vtkIdType i=0; i<centerlines->GetNumberOfPoints(); i++)
1060 {
1061 centerlines->GetPoint(i,point);
1062 signedDistances[i] = static_cast<float>(normal[0] * (point[0] - origin[0]) + normal[1] * (point[1] - origin[1]) + normal[2] * (point[2] - origin[2]));
1063 }
1064 const bool floatPoints = centerlines->GetPoints()->GetDataType() == VTK_FLOAT;
1065 vtkNew<vtkIdList> cellPointIds;
1066 double point0[3], point1[3];
1067 for (vtkIdType cellId=0; cellId<centerlines->GetNumberOfCells(); cellId++)
1068 {
1069 int cellType = centerlines->GetCellType(cellId);
1070 if (cellType != VTK_LINE && cellType != VTK_POLY_LINE)
1071 {
1072 continue;
1073 }
1074 centerlines->GetCellPoints(cellId,cellPointIds);
1075 for (vtkIdType k=0; k+1<cellPointIds->GetNumberOfIds(); k++)
1076 {
1077 vtkIdType pointId0 = cellPointIds->GetId(k);
1078 vtkIdType pointId1 = cellPointIds->GetId(k+1);
1079 double distance0 = signedDistances[pointId0];
1080 double distance1 = signedDistances[pointId1];
1081 if ((distance0 >= 0.0) == (distance1 >= 0.0))
1082 {
1083 continue;
1084 }
1085 // Interpolate from the end below 0 to the end at or above 0
1086 if (distance0 >= 0.0)
1087 {
1088 std::swap(pointId0,pointId1);
1089 std::swap(distance0,distance1);
1090 }
1091 centerlines->GetPoint(pointId0,point0);
1092 centerlines->GetPoint(pointId1,point1);
1093 const double t = (0.0 - distance0) / (distance1 - distance0);
1094 std::array<double,3> crossing;
1095 for (int j=0; j<3; j++)
1096 {
1097 crossing[j] = point0[j] + t * (point1[j] - point0[j]);
1098 if (floatPoints)
1099 {
1100 crossing[j] = static_cast<float>(crossing[j]);
1101 }
1102 }
1103 crossingPoints.insert(crossing);
1104 }
1105 }
1106 }
1107 if (crossingPoints.empty())
1108 {
1109 return 0;
1110 }
1111
1112 // Section and crossing points all lie in the cutting plane, so the
1113 // inside test is done in an orthonormal frame of that plane, with z set to
1114 // exactly 0. vtkPolygon::PointInPolygon rejects points outside the polygon
1115 // bounds without tolerance, and the bounds of a planar section have no
1116 // thickness along the normal, so a crossing point off the plane by rounding
1117 // alone would otherwise be counted as outside.
1118 double planeNormal[3] = {normal[0], normal[1], normal[2]};
1119 vtkMath::Normalize(planeNormal);
1120 double axis0[3], axis1[3];
1121 vtkMath::Perpendiculars(planeNormal,axis0,axis1,0.0);
1122
1123 vtkPoints* sectionPoints = section->GetCell(0)->GetPoints();
1124 const int numberOfPolygonPoints = static_cast<int>(sectionPoints->GetNumberOfPoints());
1125 if (numberOfPolygonPoints < 3)
1126 {
1127 return 0;
1128 }
1129 std::vector<double> polygon(3*numberOfPolygonPoints);
1130 double polygonBounds[6] = {VTK_DOUBLE_MAX, VTK_DOUBLE_MIN, VTK_DOUBLE_MAX, VTK_DOUBLE_MIN, 0.0, 0.0};
1131 double point[3], planePoint[3];
1132 for (int i=0; i<numberOfPolygonPoints; i++)
1133 {
1134 sectionPoints->GetPoint(i,point);
1135 vtkMath::Subtract(point,origin,point);
1136 double* polygonPoint = &polygon[3*i];
1137 polygonPoint[0] = vtkMath::Dot(point,axis0);
1138 polygonPoint[1] = vtkMath::Dot(point,axis1);
1139 polygonPoint[2] = 0.0;
1140 polygonBounds[0] = vtkMath::Min(polygonBounds[0],polygonPoint[0]);
1141 polygonBounds[1] = vtkMath::Max(polygonBounds[1],polygonPoint[0]);
1142 polygonBounds[2] = vtkMath::Min(polygonBounds[2],polygonPoint[1]);
1143 polygonBounds[3] = vtkMath::Max(polygonBounds[3],polygonPoint[1]);
1144 }
1145 double polygonNormal[3] = {0.0, 0.0, 1.0};
1146
1147 int numberOfCenterlines = 0;
1148 for (const std::array<double,3>& crossing : crossingPoints)
1149 {
1150 vtkMath::Subtract(crossing.data(),origin,point);
1151 planePoint[0] = vtkMath::Dot(point,axis0);
1152 planePoint[1] = vtkMath::Dot(point,axis1);
1153 planePoint[2] = 0.0;
1154 if (vtkPolygon::PointInPolygon(planePoint,numberOfPolygonPoints,polygon.data(),polygonBounds,polygonNormal) == 1)
1155 {
1156 ++numberOfCenterlines;
1157 }
1158 }
1159
1160 return numberOfCenterlines;
1161}

◆ CountBranchSectionIds()

int vtkvmtkPolyDataBranchSections::CountBranchSectionIds ( vtkPolyData * section,
const char * idsArrayName )
static

Count how many labeled regions of a surface a vessel cross-section touches.

The distinct values of the point data array idsArrayName on the points of section are counted. section must be extracted with ExtractCylinderSection, with the same idsArrayName, from a surface whose points carry idsArrayName as integer labels, for example the id of the vessel or branch each point belongs to. Values are converted to integers. Returns 0 if section has no such array.

The count tells whether a section lies within a single labeled region: a section across one vessel touches only the label of that vessel, while a section that runs across a boundary between regions touches two or more. For example, together with CountBranchSectionCenterlines it can classify sections cut along centerlines: a section is in a single branch if both counts are 1. The two checks complement each other, since an oblique section can run onto the wall of a neighboring vessel whose centerline it does not contain. Similarly, the count can confirm that a section used for area or diameter measurement lies within one labeled region.

ExtractCylinderSection copies the labels to the section points without interpolation, so only labels that exist on the surface are counted, even where regions with labels that are not consecutive integers meet (for example 0 and 3).

Definition at line 1163 of file vtkvmtkPolyDataBranchSections.cxx.

1164{
1165 vtkDataArray* idsArray = section->GetPointData()->GetArray(idsArrayName);
1166 if (idsArray == NULL)
1167 {
1168 return 0;
1169 }
1170
1171 std::set<vtkIdType> ids;
1172 for (vtkIdType i=0; i<idsArray->GetNumberOfTuples(); i++)
1173 {
1174 ids.insert(static_cast<vtkIdType>(idsArray->GetComponent(i,0)));
1175 }
1176
1177 return static_cast<int>(ids.size());
1178}

◆ RequestData()

int vtkvmtkPolyDataBranchSections::RequestData ( vtkInformation * ,
vtkInformationVector ** ,
vtkInformationVector *  )
overrideprotectedvirtual

Definition at line 173 of file vtkvmtkPolyDataBranchSections.cxx.

177{
178 vtkInformation *inInfo = inputVector[0]->GetInformationObject(0);
179 vtkInformation *outInfo = outputVector->GetInformationObject(0);
180
181 vtkPolyData *input = vtkPolyData::SafeDownCast(
182 inInfo->Get(vtkDataObject::DATA_OBJECT()));
183 vtkPolyData *output = vtkPolyData::SafeDownCast(
184 outInfo->Get(vtkDataObject::DATA_OBJECT()));
185
186 if (!this->GroupIdsArrayName)
187 {
188 vtkErrorMacro(<<"GroupIdsArrayName not specified");
189 return 1;
190 }
191
192 vtkDataArray* groupIdsArray = input->GetPointData()->GetArray(this->GroupIdsArrayName);
193
194 if (!groupIdsArray)
195 {
196 vtkErrorMacro(<<"GroupIdsArray with name specified does not exist");
197 return 1;
198 }
199
200 if (!this->Centerlines)
201 {
202 vtkErrorMacro(<<"Centerlines not set");
203 return 1;
204 }
205
206 if (!this->CenterlineRadiusArrayName)
207 {
208 vtkErrorMacro(<<"CenterlineRadiusArrayName not specified");
209 return 1;
210 }
211
212 vtkDataArray* centerlineRadiusArray = this->Centerlines->GetPointData()->GetArray(this->CenterlineRadiusArrayName);
213
214 if (!centerlineRadiusArray)
215 {
216 vtkErrorMacro(<<"CenterlineRadiusArray with name specified does not exist");
217 return 1;
218 }
219
221 {
222 vtkErrorMacro(<<"CenterlineGroupIdsArrayName not specified");
223 return 1;
224 }
225
226 vtkDataArray* centerlineGroupIdsArray = this->Centerlines->GetCellData()->GetArray(this->CenterlineGroupIdsArrayName);
227
228 if (!centerlineGroupIdsArray)
229 {
230 vtkErrorMacro(<<"CenterlineGroupIdsArray with name specified does not exist");
231 return 1;
232 }
233
234 if (!this->CenterlineIdsArrayName)
235 {
236 vtkErrorMacro(<<"CenterlineIdsArrayName not specified");
237 return 1;
238 }
239
240 vtkDataArray* centerlineIdsArray = this->Centerlines->GetCellData()->GetArray(this->CenterlineIdsArrayName);
241
242 if (!centerlineIdsArray)
243 {
244 vtkErrorMacro(<<"CenterlineIdsArray with name specified does not exist");
245 return 1;
246 }
247
249 {
250 vtkErrorMacro(<<"CenterlineTractIdsArrayName not specified");
251 return 1;
252 }
253
254 vtkDataArray* centerlineTractIdsArray = this->Centerlines->GetCellData()->GetArray(this->CenterlineTractIdsArrayName);
255
256 if (!centerlineTractIdsArray)
257 {
258 vtkErrorMacro(<<"CenterlineTractIdsArray with name specified does not exist");
259 return 1;
260 }
261
262 if (!this->BlankingArrayName)
263 {
264 vtkErrorMacro(<<"BlankingArrayName not specified");
265 return 1;
266 }
267
268 vtkDataArray* blankingArray = this->Centerlines->GetCellData()->GetArray(this->BlankingArrayName);
269
270 if (!blankingArray)
271 {
272 vtkErrorMacro(<<"BlankingArray with name specified does not exist");
273 return 1;
274 }
275
277 {
278 vtkErrorMacro(<<"BranchSectionGroupIdsArrayName not specified");
279 return 1;
280 }
281
283 {
284 vtkErrorMacro(<<"BranchSectionAreaArrayName not specified");
285 return 1;
286 }
287
289 {
290 vtkErrorMacro(<<"BranchSectionMinSizeArrayName not specified");
291 return 1;
292 }
293
295 {
296 vtkErrorMacro(<<"BranchSectionMaxSizeArrayName not specified");
297 return 1;
298 }
299
301 {
302 vtkErrorMacro(<<"BranchSectionShapeArrayName not specified");
303 return 1;
304 }
305
307 {
308 vtkErrorMacro(<<"BranchSectionClosedArrayName not specified");
309 return 1;
310 }
311
313 {
314 vtkErrorMacro(<<"BranchSectionDistanceSpheresArrayName not specified");
315 return 1;
316 }
317
318 vtkPoints* outputPoints = vtkPoints::New();
319 vtkCellArray* outputPolys = vtkCellArray::New();
320
321 output->SetPoints(outputPoints);
322 output->SetPolys(outputPolys);
323
324 vtkIntArray* branchSectionGroupIdsArray = vtkIntArray::New();
325 branchSectionGroupIdsArray->SetName(this->BranchSectionGroupIdsArrayName);
326
327 vtkDoubleArray* branchSectionAreaArray = vtkDoubleArray::New();
328 branchSectionAreaArray->SetName(this->BranchSectionAreaArrayName);
329
330 vtkDoubleArray* branchSectionShapeArray = vtkDoubleArray::New();
331 branchSectionShapeArray->SetName(this->BranchSectionShapeArrayName);
332
333 vtkDoubleArray* branchSectionMinSizeArray = vtkDoubleArray::New();
334 branchSectionMinSizeArray->SetName(this->BranchSectionMinSizeArrayName);
335
336 vtkDoubleArray* branchSectionMaxSizeArray = vtkDoubleArray::New();
337 branchSectionMaxSizeArray->SetName(this->BranchSectionMaxSizeArrayName);
338
339 vtkIntArray* branchSectionClosedArray = vtkIntArray::New();
340 branchSectionClosedArray->SetName(this->BranchSectionClosedArrayName);
341
342 vtkIntArray* branchSectionDistanceSpheresArray = vtkIntArray::New();
343 branchSectionDistanceSpheresArray->SetName(this->BranchSectionDistanceSpheresArrayName);
344
345 output->GetCellData()->AddArray(branchSectionGroupIdsArray);
346 output->GetCellData()->AddArray(branchSectionAreaArray);
347 output->GetCellData()->AddArray(branchSectionMinSizeArray);
348 output->GetCellData()->AddArray(branchSectionMaxSizeArray);
349 output->GetCellData()->AddArray(branchSectionShapeArray);
350 output->GetCellData()->AddArray(branchSectionClosedArray);
351 output->GetCellData()->AddArray(branchSectionDistanceSpheresArray);
352
353 vtkIdList* nonBlankedGroupIds = vtkIdList::New();
355 int i;
356 for (i=0; i<nonBlankedGroupIds->GetNumberOfIds(); i++)
357 {
358 vtkIdType groupId = nonBlankedGroupIds->GetId(i);
359
360 this->ComputeBranchSections(input,groupId,output);
361 }
362
363 nonBlankedGroupIds->Delete();
364
365 outputPoints->Delete();
366 outputPolys->Delete();
367
368 branchSectionGroupIdsArray->Delete();
369 branchSectionAreaArray->Delete();
370 branchSectionMinSizeArray->Delete();
371 branchSectionMaxSizeArray->Delete();
372 branchSectionShapeArray->Delete();
373 branchSectionClosedArray->Delete();
374 branchSectionDistanceSpheresArray->Delete();
375
376 return 1;
377}
static void GetNonBlankedGroupsIdList(vtkPolyData *centerlines, const char *groupIdsArrayName, const char *blankingArrayName, vtkIdList *groupIds)
void ComputeBranchSections(vtkPolyData *input, int groupId, vtkPolyData *output)

◆ ComputeBranchSections()

void vtkvmtkPolyDataBranchSections::ComputeBranchSections ( vtkPolyData * input,
int groupId,
vtkPolyData * output )
protected

Definition at line 379 of file vtkvmtkPolyDataBranchSections.cxx.

380{
381 vtkPoints* branchSectionPoints = output->GetPoints();
382 vtkCellArray* branchSectionPolys = output->GetPolys();
383
384 vtkIntArray* branchSectionGroupIdsArray = vtkIntArray::SafeDownCast(output->GetCellData()->GetArray(this->BranchSectionGroupIdsArrayName));
385 vtkDoubleArray* branchSectionAreaArray = vtkDoubleArray::SafeDownCast(output->GetCellData()->GetArray(this->BranchSectionAreaArrayName));
386 vtkDoubleArray* branchSectionMinSizeArray = vtkDoubleArray::SafeDownCast(output->GetCellData()->GetArray(this->BranchSectionMinSizeArrayName));
387 vtkDoubleArray* branchSectionMaxSizeArray = vtkDoubleArray::SafeDownCast(output->GetCellData()->GetArray(this->BranchSectionMaxSizeArrayName));
388 vtkDoubleArray* branchSectionShapeArray = vtkDoubleArray::SafeDownCast(output->GetCellData()->GetArray(this->BranchSectionShapeArrayName));
389 vtkIntArray* branchSectionClosedArray = vtkIntArray::SafeDownCast(output->GetCellData()->GetArray(this->BranchSectionClosedArrayName));
390 vtkIntArray* branchSectionDistanceSpheresArray = vtkIntArray::SafeDownCast(output->GetCellData()->GetArray(this->BranchSectionDistanceSpheresArrayName));
391
392 int i, j;
393
394 for (i=0; ; i++)
395 {
396 double averagePoint[3];
397 averagePoint[0] = averagePoint[1] = averagePoint[2] = 0.0;
398
399 double averageTangent[3];
400 averageTangent[0] = averageTangent[1] = averageTangent[2] = 0.0;
401
402 double weightSum = 0.0;
403
404 int totalNumberOfSpheres = i * this->NumberOfDistanceSpheres;
405 bool anyPoint = false;
406
407 vtkIdList* groupCellIds = vtkIdList::New();
409 for (j=0; j<groupCellIds->GetNumberOfIds(); j++)
410 {
411 vtkIdType centerlineCellId = groupCellIds->GetId(j);
412 vtkPoints* centerlineCellPoints = this->Centerlines->GetCell(centerlineCellId)->GetPoints();
413
414 vtkIdType firstSubId = 0;
415 double firstPCoord = 0.0;
416 bool reverseTouchingDirection = false;
417
418 if (this->ReverseDirection) {
419 firstSubId = centerlineCellPoints->GetNumberOfPoints()-2;
420 firstPCoord = 1.0;
421 reverseTouchingDirection = true;
422 }
423
424 vtkIdType touchingSubId = -1;
425 double touchingPCoord = 0.0;
426 vtkvmtkCenterlineSphereDistance::FindNTouchingSphereCenter(this->Centerlines,this->CenterlineRadiusArrayName,centerlineCellId,firstSubId,firstPCoord,totalNumberOfSpheres,touchingSubId,touchingPCoord,reverseTouchingDirection);
427
428 if (touchingSubId == -1)
429 {
430 continue;
431 }
432
433 anyPoint = true;
434 double touchingPoint[3];
435 vtkvmtkCenterlineUtilities::InterpolatePoint(this->Centerlines,centerlineCellId,touchingSubId,touchingPCoord,touchingPoint);
436
437 double touchingPoint0[3], touchingPoint1[3];
438 centerlineCellPoints->GetPoint(touchingSubId,touchingPoint0);
439 centerlineCellPoints->GetPoint(touchingSubId+1,touchingPoint1);
440
441 double touchingPointTangent[3];
442 touchingPointTangent[0] = touchingPoint1[0] - touchingPoint0[0];
443 touchingPointTangent[1] = touchingPoint1[1] - touchingPoint0[1];
444 touchingPointTangent[2] = touchingPoint1[2] - touchingPoint0[2];
445
446 vtkMath::Normalize(touchingPointTangent);
447 double touchingPointRadius = 0.0;
448 vtkvmtkCenterlineUtilities::InterpolateTuple1(this->Centerlines,this->CenterlineRadiusArrayName,centerlineCellId,touchingSubId,touchingPCoord,touchingPointRadius);
449
450 averagePoint[0] += touchingPointRadius * touchingPointRadius * touchingPoint[0];
451 averagePoint[1] += touchingPointRadius * touchingPointRadius * touchingPoint[1];
452 averagePoint[2] += touchingPointRadius * touchingPointRadius * touchingPoint[2];
453
454 averageTangent[0] += touchingPointRadius * touchingPointRadius * touchingPointTangent[0];
455 averageTangent[1] += touchingPointRadius * touchingPointRadius * touchingPointTangent[1];
456 averageTangent[2] += touchingPointRadius * touchingPointRadius * touchingPointTangent[2];
457
458 weightSum += touchingPointRadius * touchingPointRadius;
459 }
460
461 if (!anyPoint)
462 {
463 break;
464 }
465
466 averagePoint[0] /= weightSum;
467 averagePoint[1] /= weightSum;
468 averagePoint[2] /= weightSum;
469
470 averageTangent[0] /= weightSum;
471 averageTangent[1] /= weightSum;
472 averageTangent[2] /= weightSum;
473
474 vtkMath::Normalize(averageTangent);
475
476 //now cut branch with plane and get section. Compute section properties and store them.
477
478 vtkPolyData* cylinder = vtkPolyData::New();
479 vtkvmtkPolyDataBranchUtilities::ExtractGroup(input,this->GroupIdsArrayName,groupId,false,cylinder);
480
481 vtkPolyData* section = vtkPolyData::New();
482 bool closed = false;
483 this->ExtractCylinderSection(cylinder,averagePoint,averageTangent,section,closed);
484
485 section->BuildCells();
486 if (section->GetNumberOfCells() == 0)
487 {
488 groupCellIds->Delete();
489 cylinder->Delete();
490 section->Delete();
491 continue;
492 }
493 vtkPoints* sectionCellPoints = section->GetCell(0)->GetPoints();
494 int numberOfSectionCellPoints = sectionCellPoints->GetNumberOfPoints();
495 branchSectionPolys->InsertNextCell(numberOfSectionCellPoints);
496 int k;
497 for (k=0; k<numberOfSectionCellPoints; k++)
498 {
499 vtkIdType branchPointId = branchSectionPoints->InsertNextPoint(sectionCellPoints->GetPoint(k));
500 branchSectionPolys->InsertCellPoint(branchPointId);
501 }
502
503 double area = this->ComputeBranchSectionArea(section);
504 double sizeRange[2];
505 double shape = this->ComputeBranchSectionShape(section,averagePoint,sizeRange);
506
507 branchSectionGroupIdsArray->InsertNextValue(groupId);
508 branchSectionAreaArray->InsertNextValue(area);
509 branchSectionMinSizeArray->InsertNextValue(sizeRange[0]);
510 branchSectionMaxSizeArray->InsertNextValue(sizeRange[1]);
511 branchSectionShapeArray->InsertNextValue(shape);
512 branchSectionClosedArray->InsertNextValue(closed);
513 branchSectionDistanceSpheresArray->InsertNextValue(totalNumberOfSpheres);
514
515 groupCellIds->Delete();
516 cylinder->Delete();
517 section->Delete();
518 }
519}
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)

Member Data Documentation

◆ Centerlines

vtkPolyData* vtkvmtkPolyDataBranchSections::Centerlines
protected

Definition at line 310 of file vtkvmtkPolyDataBranchSections.h.

◆ GroupIdsArrayName

char* vtkvmtkPolyDataBranchSections::GroupIdsArrayName
protected

Definition at line 312 of file vtkvmtkPolyDataBranchSections.h.

◆ CenterlineRadiusArrayName

char* vtkvmtkPolyDataBranchSections::CenterlineRadiusArrayName
protected

Definition at line 313 of file vtkvmtkPolyDataBranchSections.h.

◆ CenterlineGroupIdsArrayName

char* vtkvmtkPolyDataBranchSections::CenterlineGroupIdsArrayName
protected

Definition at line 314 of file vtkvmtkPolyDataBranchSections.h.

◆ CenterlineIdsArrayName

char* vtkvmtkPolyDataBranchSections::CenterlineIdsArrayName
protected

Definition at line 315 of file vtkvmtkPolyDataBranchSections.h.

◆ CenterlineTractIdsArrayName

char* vtkvmtkPolyDataBranchSections::CenterlineTractIdsArrayName
protected

Definition at line 316 of file vtkvmtkPolyDataBranchSections.h.

◆ BlankingArrayName

char* vtkvmtkPolyDataBranchSections::BlankingArrayName
protected

Definition at line 317 of file vtkvmtkPolyDataBranchSections.h.

◆ BranchSectionGroupIdsArrayName

char* vtkvmtkPolyDataBranchSections::BranchSectionGroupIdsArrayName
protected

Definition at line 319 of file vtkvmtkPolyDataBranchSections.h.

◆ BranchSectionAreaArrayName

char* vtkvmtkPolyDataBranchSections::BranchSectionAreaArrayName
protected

Definition at line 320 of file vtkvmtkPolyDataBranchSections.h.

◆ BranchSectionMinSizeArrayName

char* vtkvmtkPolyDataBranchSections::BranchSectionMinSizeArrayName
protected

Definition at line 321 of file vtkvmtkPolyDataBranchSections.h.

◆ BranchSectionMaxSizeArrayName

char* vtkvmtkPolyDataBranchSections::BranchSectionMaxSizeArrayName
protected

Definition at line 322 of file vtkvmtkPolyDataBranchSections.h.

◆ BranchSectionShapeArrayName

char* vtkvmtkPolyDataBranchSections::BranchSectionShapeArrayName
protected

Definition at line 323 of file vtkvmtkPolyDataBranchSections.h.

◆ BranchSectionClosedArrayName

char* vtkvmtkPolyDataBranchSections::BranchSectionClosedArrayName
protected

Definition at line 324 of file vtkvmtkPolyDataBranchSections.h.

◆ BranchSectionDistanceSpheresArrayName

char* vtkvmtkPolyDataBranchSections::BranchSectionDistanceSpheresArrayName
protected

Definition at line 325 of file vtkvmtkPolyDataBranchSections.h.

◆ NumberOfDistanceSpheres

int vtkvmtkPolyDataBranchSections::NumberOfDistanceSpheres
protected

Definition at line 327 of file vtkvmtkPolyDataBranchSections.h.

◆ ReverseDirection

int vtkvmtkPolyDataBranchSections::ReverseDirection
protected

Definition at line 328 of file vtkvmtkPolyDataBranchSections.h.


The documentation for this class was generated from the following files: