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

Split and group centerlines. More...

#include <vtkvmtkCenterlineBranchExtractor.h>

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

Public Types

typedef vtkvmtkCenterlineSplittingAndGroupingFilter Superclass
Public Types inherited from vtkvmtkCenterlineSplittingAndGroupingFilter
enum  { FIRSTPOINT , LASTPOINT , POINTINTUBE }
typedef vtkPolyDataAlgorithm Superclass

Public Member Functions

virtual int IsA (const char *type)
vtkvmtkCenterlineBranchExtractor * NewInstance () const
void PrintSelf (std::ostream &os, vtkIndent indent) override
Public Member Functions inherited from vtkvmtkCenterlineSplittingAndGroupingFilter
vtkvmtkCenterlineSplittingAndGroupingFilter * NewInstance () const
void PrintSelf (std::ostream &os, vtkIndent indent) override
void SetGroupingModeToFirstPoint ()
void SetGroupingModeToLastPoint ()
void SetGroupingModeToPointInTube ()
virtual void SetRadiusArrayName (const char *)
virtual char * GetRadiusArrayName ()
virtual void SetGroupIdsArrayName (const char *)
virtual char * GetGroupIdsArrayName ()
virtual void SetCenterlineIdsArrayName (const char *)
virtual char * GetCenterlineIdsArrayName ()
virtual void SetBlankingArrayName (const char *)
virtual char * GetBlankingArrayName ()
virtual void SetTractIdsArrayName (const char *)
virtual char * GetTractIdsArrayName ()
virtual void SetGroupingMode (int)
virtual int GetGroupingMode ()

Static Public Member Functions

static int IsTypeOf (const char *type)
static vtkvmtkCenterlineBranchExtractor * SafeDownCast (vtkObjectBase *o)
static vtkvmtkCenterlineBranchExtractor * New ()
Static Public Member Functions inherited from vtkvmtkCenterlineSplittingAndGroupingFilter
static int IsTypeOf (const char *type)
static vtkvmtkCenterlineSplittingAndGroupingFilter * SafeDownCast (vtkObjectBase *o)

Protected Member Functions

virtual vtkObjectBase * NewInstanceInternal () const
 vtkvmtkCenterlineBranchExtractor ()
 ~vtkvmtkCenterlineBranchExtractor ()
virtual void ComputeCenterlineSplitting (vtkPolyData *input, vtkIdType cellId) override
virtual void GroupTracts (vtkPolyData *input, vtkPolyData *centerlineTracts) override
Protected Member Functions inherited from vtkvmtkCenterlineSplittingAndGroupingFilter
 vtkvmtkCenterlineSplittingAndGroupingFilter ()
 ~vtkvmtkCenterlineSplittingAndGroupingFilter ()
virtual int RequestData (vtkInformation *, vtkInformationVector **, vtkInformationVector *) override
void CoincidentExtremePointGroupTracts (vtkPolyData *input, vtkPolyData *centerlineTracts, bool first=true)
void PointInTubeGroupTracts (vtkPolyData *input, vtkPolyData *centerlineTracts)
virtual void MergeTracts (vtkPolyData *centerlineTracts)
void SplitCenterline (vtkPolyData *input, vtkIdType cellId, int numberOfSplittingPoints, const vtkIdType *subIds, const double *pcoords, const int *tractBlanking, vtkPolyData *splitCenterline)
void MakeGroupIdsAdjacent (vtkPolyData *centerlineTracts)
void MakeTractIdsAdjacent (vtkPolyData *centerlineTracts)

Additional Inherited Members

Protected Attributes inherited from vtkvmtkCenterlineSplittingAndGroupingFilter
char * RadiusArrayName
char * GroupIdsArrayName
char * CenterlineIdsArrayName
char * BlankingArrayName
char * TractIdsArrayName
int NumberOfSplittingPoints
vtkIdType * SubIds
double * PCoords
int * TractBlanking
int GroupingMode

Detailed Description

Split and group centerlines.

A centerline is split into individual tracts and the tracts are merged together into branches.

Tracts are formed (in the example of a bifurcation, though this is generalized to a n-furcation), by identifying two points on each centerline (which we termed the reference points). The first is located where the centerline intersects another centerline’s tube (in the vascular tree assumption, each centerline will intersect all the other centerlines’ tube once). The second is located one maximum inscribed sphere upstream. The second reference point may be thought of as the start of the bifurcation region. We can then identify three tracts along each centerline, the first preceding the bifurcation, the second lying in-between the two points and the last following the bifurcation

Note that in the first tract the two centerlines are one in each other’s tube. The same thing holds true for the second tract, since by definition the second tract ends where the centerlines exit the other centerline’s tube. The last tracts are instead outside each other’s tube.

We can therefore group the tracts based on these tube containment relationships: the first group will be composed of the first tracts of the two centerlines, the second of the second tracts of the two centerlines, the ones located at the bifurcation region in-between the reference points, the third of the second tract of the first centerline and the fourth of the second tract of the second centerline. Each group will basically represent a branch, except for the second group, which will be relative to the bifurcation.

This process gives us the "Blanking" label for tracts free of charge. Tracts which lie between the two reference points (within the bifurcation region), are said to be Blanked. This is label will become important during processing steps downstream in the pipeline.

Definition at line 40 of file vtkvmtkCenterlineBranchExtractor.h.

Member Typedef Documentation

◆ Superclass

Constructor & Destructor Documentation

◆ vtkvmtkCenterlineBranchExtractor()

vtkvmtkCenterlineBranchExtractor::vtkvmtkCenterlineBranchExtractor ( )
protected

Definition at line 37 of file vtkvmtkCenterlineBranchExtractor.cxx.

38{
39}

◆ ~vtkvmtkCenterlineBranchExtractor()

vtkvmtkCenterlineBranchExtractor::~vtkvmtkCenterlineBranchExtractor ( )
protected

Definition at line 41 of file vtkvmtkCenterlineBranchExtractor.cxx.

42{
43}

Member Function Documentation

◆ IsTypeOf()

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

◆ IsA()

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

◆ SafeDownCast()

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

◆ NewInstanceInternal()

virtual vtkObjectBase * vtkvmtkCenterlineBranchExtractor::NewInstanceInternal ( ) const
protectedvirtual

◆ NewInstance()

vtkvmtkCenterlineBranchExtractor * vtkvmtkCenterlineBranchExtractor::NewInstance ( ) const

◆ PrintSelf()

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

Definition at line 360 of file vtkvmtkCenterlineBranchExtractor.cxx.

361{
362 this->Superclass::PrintSelf(os,indent);
363}
void PrintSelf(std::ostream &os, vtkIndent indent) override

◆ New()

vtkvmtkCenterlineBranchExtractor * vtkvmtkCenterlineBranchExtractor::New ( )
static

◆ ComputeCenterlineSplitting()

void vtkvmtkCenterlineBranchExtractor::ComputeCenterlineSplitting ( vtkPolyData * input,
vtkIdType cellId )
overrideprotectedvirtual

Implements vtkvmtkCenterlineSplittingAndGroupingFilter.

Definition at line 45 of file vtkvmtkCenterlineBranchExtractor.cxx.

46{
48
49 if (this->SubIds)
50 {
51 delete[] this->SubIds;
52 this->SubIds = NULL;
53 }
54
55 if (this->PCoords)
56 {
57 delete[] this->PCoords;
58 this->PCoords = NULL;
59 }
60
61 if (this->TractBlanking)
62 {
63 delete[] this->TractBlanking;
64 this->TractBlanking = NULL;
65 }
66
67 if (!this->RadiusArrayName)
68 {
69 return;
70 }
71
72 if (input->GetCell(cellId)->GetCellType() != VTK_LINE && input->GetCell(cellId)->GetCellType() != VTK_POLY_LINE)
73 {
74 return;
75 }
76
77 vtkDataArray* radiusArray = input->GetPointData()->GetArray(this->RadiusArrayName);
78
79 if (!radiusArray)
80 {
81 return;
82 }
83
84 // TODO: remove assumption: centerlines organized in a tree, parent branches as sources and children as targets
85
86 vtkvmtkPolyBallLine* tube = vtkvmtkPolyBallLine::New();
87
88 tube->SetInput(input);
90
91 vtkIdList* tubeCellIds = vtkIdList::New();
92
93 vtkIdList* intersectionSubIds = vtkIdList::New();
94 vtkDoubleArray* intersectionPCoords = vtkDoubleArray::New();
95
96 vtkIdType numberOfCells = input->GetNumberOfCells();
97
98 //for every other cell than cellId, find intersection of cellId with the tube function of the other cell
99 int j;
100 for (j=0; j<numberOfCells; j++)
101 {
102 if (j==cellId)
103 {
104 continue;
105 }
106
107 if (input->GetCell(j)->GetCellType() != VTK_LINE && input->GetCell(j)->GetCellType() != VTK_POLY_LINE)
108 {
109 continue;
110 }
111
112 tubeCellIds->Initialize();
113 tubeCellIds->InsertNextId(j);
114 tube->SetInputCellIds(tubeCellIds);
115
116 int numberOfCellPoints = input->GetCell(cellId)->GetNumberOfPoints();
117
118 double point0[3], point1[3];
119 double tubeValue0, tubeValue1;
120 for (int k=0; k<numberOfCellPoints-1; k++)
121 {
122 input->GetCell(cellId)->GetPoints()->GetPoint(k,point0);
123 input->GetCell(cellId)->GetPoints()->GetPoint(k+1,point1);
124 tubeValue0 = tube->EvaluateFunction(point0);
125 tubeValue1 = tube->EvaluateFunction(point1);
126
127// if (tubeValue0 * tubeValue1 <= 0.0)
128 if ((tubeValue0 <= 0.0) && (tubeValue1 > 0.0)) // this is for divergent networks
129 {
130 double radius0, radius1;
131 radius0 = radiusArray->GetComponent(input->GetCell(cellId)->GetPointId(k),0);
132 radius1 = radiusArray->GetComponent(input->GetCell(cellId)->GetPointId(k+1),0);
133
134 //TODO: use Newton iterations
135 double segmentLength, stepSize, pcoordStepSize;
136 int numberOfSteps;
137 double subPoint0[3], subPoint1[3];
138 double subTubeValue0, subTubeValue1;
139 segmentLength = vtkMath::Distance2BetweenPoints(point0,point1);
140 stepSize = 1E-2 * (radius0 + radius1) / 2.0;
141 numberOfSteps = (int)ceil(segmentLength / stepSize);
142 stepSize = segmentLength / numberOfSteps;
143 pcoordStepSize = 1.0 / (double)numberOfSteps;
144
145 double pcoord = 0.0;
146 int s;
147 for (s=0; s<numberOfSteps; s++)
148 {
149 for (int d=0; d<3; d++)
150 {
151 subPoint0[d] = point0[d] + pcoord * (point1[d] - point0[d]);
152 subPoint1[d] = point0[d] + (pcoord + pcoordStepSize) * (point1[d] - point0[d]);
153 }
154
155 subTubeValue0 = tube->EvaluateFunction(subPoint0);
156 subTubeValue1 = tube->EvaluateFunction(subPoint1);
157
158// if (subTubeValue0 * subTubeValue1 <= 0.0)
159 if ((subTubeValue0 <= 0.0) && (subTubeValue1 > 0.0)) // this is for divergent networks
160 {
161 pcoord += pcoordStepSize;
162 break;
163 }
164
165 pcoord += pcoordStepSize;
166 }
167
168 //since we are considering each other cell separately, we need to decide where to put the intersection point in order to have them sorted along cellId
169 int numberOfIntersections = intersectionSubIds->GetNumberOfIds();
170 int insertLocation = 0;
171 for (s=0; s<numberOfIntersections; s++)
172 {
173 bool afterThis = (k > intersectionSubIds->GetId(s)) || (k==intersectionSubIds->GetId(s) && pcoord > intersectionPCoords->GetValue(s));
174 bool beforeNext = true;
175 if (s<numberOfIntersections-1)
176 {
177 beforeNext = (k < intersectionSubIds->GetId(s+1)) || (k==intersectionSubIds->GetId(s+1) && pcoord <= intersectionPCoords->GetValue(s+1));
178 }
179 if (afterThis && beforeNext)
180 {
181 insertLocation = s+1;
182 break;
183 }
184 }
185 for (s=numberOfIntersections-1; s>=insertLocation; s--)
186 {
187 intersectionSubIds->InsertId(s+1,intersectionSubIds->GetId(s));
188 intersectionPCoords->InsertValue(s+1,intersectionPCoords->GetValue(s));
189 }
190 intersectionSubIds->InsertId(insertLocation,k);
191 intersectionPCoords->InsertValue(insertLocation,pcoord);
192 }
193 }
194 }
195
196 // For each branch, find point at one-sphere distance upstream (i.e. touching forward).
197
198 vtkIdType touchingSubId;
199 double touchingPCoord;
200
201 const int numberOfGapSpheres = 1;
202 const bool forward = true;
203
204 vtkIdList* touchingSubIds = vtkIdList::New();
205 vtkDoubleArray* touchingPCoords = vtkDoubleArray::New();
206
207 int i;
208 for (i=0; i<intersectionSubIds->GetNumberOfIds(); i++)
209 {
210 vtkvmtkCenterlineSphereDistance::FindNTouchingSphereCenter(input,this->RadiusArrayName,cellId,intersectionSubIds->GetId(i),intersectionPCoords->GetValue(i),numberOfGapSpheres,touchingSubId,touchingPCoord,forward);
211 if (touchingSubId == -1)
212 {
213 touchingSubId = 0;
214 touchingPCoord = 0.0;
215 touchingSubIds->InsertNextId(touchingSubId);
216 touchingPCoords->InsertNextValue(touchingPCoord);
217 continue;
218 }
219
220 touchingSubIds->InsertNextId(touchingSubId);
221 touchingPCoords->InsertNextValue(touchingPCoord);
222 }
223
224 vtkIdList* splittingSubIds = vtkIdList::New();
225 vtkDoubleArray* splittingPCoords = vtkDoubleArray::New();
226 vtkIdList* blankingFlags = vtkIdList::New();
227
228 blankingFlags->InsertNextId(0);
229/*
230 for (i=0; i<intersectionSubIds->GetNumberOfIds(); i++)
231 {
232 // put one intersection every touching. Blank out between touching and intersection.
233 if (i==0)
234 {
235 splittingSubIds->InsertNextId(touchingSubIds->GetId(i));
236 splittingPCoords->InsertNextValue(touchingPCoords->GetValue(i));
237 blankingFlags->InsertNextId(1);
238 }
239 else
240 {
241 // check if this touching is before previous intersection. If it is, skip the touching.
242 if (!((touchingSubIds->GetId(i) < intersectionSubIds->GetId(i-1)) ||
243 ((touchingSubIds->GetId(i) == intersectionSubIds->GetId(i-1)) && (touchingPCoords->GetValue(i) <= intersectionPCoords->GetValue(i-1)))))
244 {
245 splittingSubIds->InsertNextId(touchingSubIds->GetId(i));
246 splittingPCoords->InsertNextValue(touchingPCoords->GetValue(i));
247 blankingFlags->InsertNextId(1);
248 }
249 }
250
251 if (i==intersectionSubIds->GetNumberOfIds()-1)
252 {
253 splittingSubIds->InsertNextId(intersectionSubIds->GetId(i));
254 splittingPCoords->InsertNextValue(intersectionPCoords->GetValue(i));
255 blankingFlags->InsertNextId(0);
256 }
257 else
258 {
259 // check if subsequent touching is before this intersection. If it is, and if subsequent intersection is after this intersection, skip the intersection.
260 if (!
261 (((touchingSubIds->GetId(i+1) < intersectionSubIds->GetId(i)) ||
262 ((touchingSubIds->GetId(i+1) == intersectionSubIds->GetId(i)) && (touchingPCoords->GetValue(i+1) <= intersectionPCoords->GetValue(i))))) &&
263 (((intersectionSubIds->GetId(i+1) > intersectionSubIds->GetId(i)) ||
264 ((intersectionSubIds->GetId(i+1) == intersectionSubIds->GetId(i)) && (intersectionPCoords->GetValue(i+1) > intersectionPCoords->GetValue(i))))) )
265 {
266 splittingSubIds->InsertNextId(intersectionSubIds->GetId(i));
267 splittingPCoords->InsertNextValue(intersectionPCoords->GetValue(i));
268 blankingFlags->InsertNextId(0);
269 }
270 }
271 }
272*/
273
274 //for every touching, put one intersection, and blank in between. If a subsequent touching falls between a previous touching and the corresponding intersection, take the farthest intersection
275 vtkIdType prevIntersectionId = -1;
276 for (i=0; i<touchingSubIds->GetNumberOfIds(); i++)
277 {
278 if (i > 0)
279 {
280 if ((touchingSubIds->GetId(i) < intersectionSubIds->GetId(prevIntersectionId)) ||
281 ((touchingSubIds->GetId(i) == intersectionSubIds->GetId(prevIntersectionId)) && (touchingPCoords->GetValue(i) <= intersectionPCoords->GetValue(prevIntersectionId))))
282 {
283 continue;
284 }
285 }
286
287 splittingSubIds->InsertNextId(touchingSubIds->GetId(i));
288 splittingPCoords->InsertNextValue(touchingPCoords->GetValue(i));
289 blankingFlags->InsertNextId(1);
290
291 vtkIdType maxIntersectionId = i;
292
293 if (i < touchingSubIds->GetNumberOfIds()-1)
294 {
295 for (j=i+1; j<touchingSubIds->GetNumberOfIds(); j++)
296 {
297 if ((touchingSubIds->GetId(j) < intersectionSubIds->GetId(maxIntersectionId)) ||
298 ((touchingSubIds->GetId(j) == intersectionSubIds->GetId(maxIntersectionId)) && (touchingPCoords->GetValue(j) <= intersectionPCoords->GetValue(maxIntersectionId))))
299 {
300 if ((intersectionSubIds->GetId(j) > intersectionSubIds->GetId(maxIntersectionId)) ||
301 ((intersectionSubIds->GetId(j) == intersectionSubIds->GetId(maxIntersectionId)) && (intersectionPCoords->GetValue(j) >= intersectionPCoords->GetValue(maxIntersectionId))))
302 {
303 maxIntersectionId = j;
304 }
305 }
306 else
307 {
308 break;
309 }
310 }
311 }
312
313 splittingSubIds->InsertNextId(intersectionSubIds->GetId(maxIntersectionId));
314 splittingPCoords->InsertNextValue(intersectionPCoords->GetValue(maxIntersectionId));
315 blankingFlags->InsertNextId(0);
316
317 prevIntersectionId = maxIntersectionId;
318 }
319
320 this->NumberOfSplittingPoints = splittingSubIds->GetNumberOfIds();
321
322 this->SubIds = new vtkIdType[this->NumberOfSplittingPoints];
323 this->PCoords = new double[this->NumberOfSplittingPoints];
324
325 for (i=0; i<splittingSubIds->GetNumberOfIds(); i++)
326 {
327 this->SubIds[i] = splittingSubIds->GetId(i);
328 this->PCoords[i] = splittingPCoords->GetValue(i);
329 }
330
331 this->TractBlanking = new int[this->NumberOfSplittingPoints+1];
332
333 for (i=0; i<this->NumberOfSplittingPoints+1; i++)
334 {
335 this->TractBlanking[i] = blankingFlags->GetId(i);
336 }
337
338 tube->Delete();
339 tubeCellIds->Delete();
340
341 intersectionSubIds->Delete();
342 intersectionPCoords->Delete();
343
344 touchingSubIds->Delete();
345 touchingPCoords->Delete();
346
347 splittingSubIds->Delete();
348 splittingPCoords->Delete();
349 blankingFlags->Delete();
350}
static void FindNTouchingSphereCenter(vtkPolyData *centerlines, const char *radiusArrayName, vtkIdType cellId, vtkIdType subId, double pcoord, int numberOfTouchingSpheres, vtkIdType &touchingSubId, double &touchingPCoord, bool forward=true)
virtual void SetInput(vtkPolyData *)
virtual void SetPolyBallRadiusArrayName(const char *)
virtual void SetInputCellIds(vtkIdList *)
static vtkvmtkPolyBallLine * New()
double EvaluateFunction(double x[3]) override

◆ GroupTracts()

void vtkvmtkCenterlineBranchExtractor::GroupTracts ( vtkPolyData * input,
vtkPolyData * centerlineTracts )
overrideprotectedvirtual

Reimplemented from vtkvmtkCenterlineSplittingAndGroupingFilter.

Definition at line 352 of file vtkvmtkCenterlineBranchExtractor.cxx.

353{
354 Superclass::GroupTracts(input,centerlineTracts);
355
356 //New ideas:
357 // loop over group ids, if blanked group, if same centerlineId as another tract in same group, make it another group. And what about the rest? No, better: assume net is a tree. For every group, look at which tracts of each centerline are downstream (via TractIdsArray) and group them in a bifurcation. In order to relax the assumption on the tree, for every group, for every direction, look for all the groups to which the next next tracts belong (tractId + 2 or -2).
358}
virtual void GroupTracts(vtkPolyData *input, vtkPolyData *centerlineTracts)

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