VMTK
Loading...
Searching...
No Matches
vtkvmtkCenterlineSplittingAndGroupingFilter.cxx
Go to the documentation of this file.
1/*=========================================================================
2
3Program: VMTK
4Module: $RCSfile: vtkvmtkCenterlineSplittingAndGroupingFilter.cxx,v $
5Language: C++
6Date: $Date: 2006/07/07 10:46:19 $
7Version: $Revision: 1.11 $
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 "vtkvmtkPolyBallLine.h"
25#include "vtkPolyData.h"
26#include "vtkPolyLine.h"
27#include "vtkLine.h"
28#include "vtkPointData.h"
29#include "vtkCellData.h"
30#include "vtkCellArray.h"
31#include "vtkIdList.h"
32#include "vtkIntArray.h"
33#include "vtkDoubleArray.h"
34#include "vtkAppendPolyData.h"
35#include "vtkvmtkConstants.h"
36#include "vtkMath.h"
37#include "vtkvmtkMath.h"
38#include "vtkInformation.h"
39#include "vtkInformationVector.h"
40#include "vtkObjectFactory.h"
41#include "vtkVersion.h"
42
43
45{
46 this->RadiusArrayName = NULL;
47 this->GroupIdsArrayName = NULL;
48 this->CenterlineIdsArrayName = NULL;
49 this->BlankingArrayName = NULL;
50 this->TractIdsArrayName = NULL;
51
53 this->SubIds = NULL;
54 this->PCoords = NULL;
55 this->TractBlanking = NULL;
56
58}
59
61{
62 if (this->RadiusArrayName)
63 {
64 delete[] this->RadiusArrayName;
65 this->RadiusArrayName = NULL;
66 }
67
68 if (this->GroupIdsArrayName)
69 {
70 delete[] this->GroupIdsArrayName;
71 this->GroupIdsArrayName = NULL;
72 }
73
74 if (this->CenterlineIdsArrayName)
75 {
76 delete[] this->CenterlineIdsArrayName;
77 this->CenterlineIdsArrayName = NULL;
78 }
79
80 if (this->BlankingArrayName)
81 {
82 delete[] this->BlankingArrayName;
83 this->BlankingArrayName = NULL;
84 }
85
86 if (this->TractIdsArrayName)
87 {
88 delete[] this->TractIdsArrayName;
89 this->TractIdsArrayName = NULL;
90 }
91
92 if (this->SubIds)
93 {
94 delete[] this->SubIds;
95 this->SubIds = NULL;
96 }
97
98 if (this->PCoords)
99 {
100 delete[] this->PCoords;
101 this->PCoords = NULL;
102 }
103
104 if (this->TractBlanking)
105 {
106 delete[] this->TractBlanking;
107 this->TractBlanking = NULL;
108 }
109}
110
112 vtkInformation *vtkNotUsed(request),
113 vtkInformationVector **inputVector,
114 vtkInformationVector *outputVector)
115{
116 vtkInformation *inInfo = inputVector[0]->GetInformationObject(0);
117 vtkInformation *outInfo = outputVector->GetInformationObject(0);
118
119 vtkPolyData *input = vtkPolyData::SafeDownCast(
120 inInfo->Get(vtkDataObject::DATA_OBJECT()));
121 vtkPolyData *output = vtkPolyData::SafeDownCast(
122 outInfo->Get(vtkDataObject::DATA_OBJECT()));
123
124 vtkIdType numberOfInputCells;
125
126 if (!this->RadiusArrayName)
127 {
128 vtkErrorMacro(<<"RadiusArrayName not specified");
129 return 1;
130 }
131
132 if (!input->GetPointData()->GetArray(this->RadiusArrayName))
133 {
134 vtkErrorMacro(<<"RadiusArray with name specified does not exist");
135 return 1;
136 }
137
138 if (!this->GroupIdsArrayName)
139 {
140 vtkErrorMacro(<<"GroupIdsArrayName not specified");
141 return 1;
142 }
143
144 if (!this->CenterlineIdsArrayName)
145 {
146 vtkErrorMacro(<<"CenterlineIdsArrayName not specified");
147 return 1;
148 }
149
150 if (!this->BlankingArrayName)
151 {
152 vtkErrorMacro(<<"BlankingArrayName not specified");
153 return 1;
154 }
155
156 if (!this->TractIdsArrayName)
157 {
158 vtkErrorMacro(<<"TractIdsArrayName not specified");
159 return 1;
160 }
161
162 numberOfInputCells = input->GetNumberOfCells();
163
164 vtkAppendPolyData* appendCenterlinesFilter = vtkAppendPolyData::New();
165
166 for (int i=0; i<numberOfInputCells; i++)
167 {
168 this->ComputeCenterlineSplitting(input,i);
169 vtkPolyData* splitCenterline = vtkPolyData::New();
170 this->SplitCenterline(input,i,this->NumberOfSplittingPoints,this->SubIds,this->PCoords,this->TractBlanking,splitCenterline);
171 appendCenterlinesFilter->AddInputData(splitCenterline);
172 splitCenterline->Delete();
173 }
174
175 appendCenterlinesFilter->Update();
176
177 vtkPolyData* centerlineTracts = vtkPolyData::New();
178 centerlineTracts->DeepCopy(appendCenterlinesFilter->GetOutput());
179
180 appendCenterlinesFilter->Delete();
181
182 this->GroupTracts(input,centerlineTracts);
183 this->MergeTracts(centerlineTracts);
184 //FIXME: now, ill situations may still occur after merging: a branch that was in between two same-group and has been merged, might have had a buddy that didn't need to be merged on another centerline. In that case ehat should we do? Leave the other one alone? Or rething the whole thing once for all?
185 this->MakeGroupIdsAdjacent(centerlineTracts);
186 this->MakeTractIdsAdjacent(centerlineTracts);
187
188 output->DeepCopy(centerlineTracts);
189
190 centerlineTracts->Delete();
191
192 return 1;
193}
194
196{
197 int numberOfCenterlineCells = centerlineTracts->GetNumberOfCells();
198 vtkPolyData* mergedCenterlineTracts = vtkPolyData::New();
199 vtkPoints* mergedCenterlineTractsPoints = vtkPoints::New();
200 mergedCenterlineTractsPoints->DeepCopy(centerlineTracts->GetPoints());
201 mergedCenterlineTracts->SetPoints(mergedCenterlineTractsPoints);
202 mergedCenterlineTracts->GetPointData()->DeepCopy(centerlineTracts->GetPointData());
203 mergedCenterlineTracts->GetCellData()->CopyAllocate(centerlineTracts->GetCellData());
204
205 vtkCellArray* mergedCellArray = vtkCellArray::New();
206
207 vtkIntArray* groupIdsArray = vtkIntArray::SafeDownCast(centerlineTracts->GetCellData()->GetArray(this->GroupIdsArrayName));
208 vtkIdList* centerlineCellIds = vtkIdList::New();
209 int i;
210 for (i=0; i<numberOfCenterlineCells; i++)
211 {
212 centerlineCellIds->Initialize();
213 vtkvmtkCenterlineUtilities::GetCenterlineCellIds(centerlineTracts,this->CenterlineIdsArrayName,this->TractIdsArrayName,i,centerlineCellIds);
214 int numberOfCenterlineTracts = centerlineCellIds->GetNumberOfIds();
215 //loop over groupids and keep track of merges (a bit redundant, but clearer)
216 int j;
217 for (j=0; j<numberOfCenterlineTracts; j++)
218 {
219 int tractCellId = centerlineCellIds->GetId(j);
220 int groupId = groupIdsArray->GetValue(tractCellId);
221 int k;
222 for (k=numberOfCenterlineTracts-1; k > j; k--)
223 {
224 int downstreamTractCellId = centerlineCellIds->GetId(k);
225 if (groupId == groupIdsArray->GetValue(downstreamTractCellId))
226 {
227 //merge from j to k
228 int l;
229 for (l=j+1; l<k; l++)
230 {
231 groupIdsArray->SetValue(centerlineCellIds->GetId(l),groupId);
232 }
233 }
234 }
235 }
236
237 // at this point we have to merge based on the repeated groupIds (which are now adjacent)
238 vtkIdList* tractCellPointIds = vtkIdList::New();
239 vtkIdList* mergedCellPointIds = vtkIdList::New();
240 int previousGroupId = -1;
241 int currentMergedCellId = -1;
242 int firstTractCellId = 0;
243 for (j=0; j<numberOfCenterlineTracts; j++)
244 {
245 // copy cell if not repeated, copy first cell and keep adding points if repeated.
246 // Note that point data remains the same, only cells change
247 int tractCellId = centerlineCellIds->GetId(j);
248 centerlineTracts->GetCellPoints(tractCellId,tractCellPointIds);
249 int groupId = groupIdsArray->GetValue(tractCellId);
250 if ((groupId != previousGroupId) || (j == numberOfCenterlineTracts-1))
251 {
252 if (previousGroupId != -1)
253 {
254 currentMergedCellId = mergedCellArray->InsertNextCell(mergedCellPointIds);
255 mergedCenterlineTracts->GetCellData()->CopyData(centerlineTracts->GetCellData(),firstTractCellId,currentMergedCellId);
256 }
257 firstTractCellId = tractCellId;
258 mergedCellPointIds->DeepCopy(tractCellPointIds);
259 if (j == numberOfCenterlineTracts-1)
260 {
261 currentMergedCellId = mergedCellArray->InsertNextCell(mergedCellPointIds);
262 mergedCenterlineTracts->GetCellData()->CopyData(centerlineTracts->GetCellData(),firstTractCellId,currentMergedCellId);
263 }
264 }
265 else
266 {
267 int numberOfTractCellPoints = tractCellPointIds->GetNumberOfIds();
268 int k;
269 for (k=1; k<numberOfTractCellPoints; k++)
270 {
271 mergedCellPointIds->InsertNextId(tractCellPointIds->GetId(k));
272 }
273 }
274 previousGroupId = groupId;
275 }
276 tractCellPointIds->Delete();
277 mergedCellPointIds->Delete();
278 }
279
280 mergedCenterlineTracts->SetLines(mergedCellArray);
281
282 centerlineTracts->DeepCopy(mergedCenterlineTracts);
283
284 mergedCellArray->Delete();
285 mergedCenterlineTracts->Delete();
286 mergedCenterlineTractsPoints->Delete();
287 centerlineCellIds->Delete();
288}
289
290void vtkvmtkCenterlineSplittingAndGroupingFilter::GroupTracts(vtkPolyData* input, vtkPolyData* centerlineTracts)
291{
292 switch (this->GroupingMode)
293 {
294 case FIRSTPOINT:
295 this->CoincidentExtremePointGroupTracts(input,centerlineTracts,true);
296 break;
297 case LASTPOINT:
298 this->CoincidentExtremePointGroupTracts(input,centerlineTracts,false);
299 break;
300 case POINTINTUBE:
301 this->PointInTubeGroupTracts(input,centerlineTracts);
302 break;
303 default:
304 vtkErrorMacro("Unknown GroupingMode");
305 }
306}
307
308void vtkvmtkCenterlineSplittingAndGroupingFilter::CoincidentExtremePointGroupTracts(vtkPolyData* input, vtkPolyData* centerlineTracts, bool first)
309{
310 vtkIntArray* groupIdsArray = vtkIntArray::New();
311 groupIdsArray->SetName(this->GroupIdsArrayName);
312 int numberOfCells = centerlineTracts->GetNumberOfCells();
313 groupIdsArray->SetNumberOfComponents(1);
314 groupIdsArray->SetNumberOfTuples(numberOfCells);
315
316 int i;
317 for (i=0; i<numberOfCells; i++)
318 {
319 groupIdsArray->SetValue(i,i);
320 }
321
322 // group based on point-in-tube criterion
323 for (i=0; i<numberOfCells; i++)
324 {
325 if (centerlineTracts->GetCell(i)->GetCellType() != VTK_LINE && centerlineTracts->GetCell(i)->GetCellType() != VTK_POLY_LINE)
326 {
327 continue;
328 }
329
330 int tractGroupId = groupIdsArray->GetValue(i);
331 double point[3];
332 if (first)
333 {
334 centerlineTracts->GetCell(i)->GetPoints()->GetPoint(0,point);
335 }
336 else
337 {
338 int numberOfCellPoints = centerlineTracts->GetCell(i)->GetNumberOfPoints();
339 centerlineTracts->GetCell(i)->GetPoints()->GetPoint(numberOfCellPoints-1,point);
340 }
341
342 int j;
343 for (j=i; j<numberOfCells; j++)
344 {
345 double currentPoint[3];
346 if (first)
347 {
348 centerlineTracts->GetCell(j)->GetPoints()->GetPoint(0,currentPoint);
349 }
350 else
351 {
352 int numberOfCellPoints = centerlineTracts->GetCell(j)->GetNumberOfPoints();
353 centerlineTracts->GetCell(j)->GetPoints()->GetPoint(numberOfCellPoints-1,currentPoint);
354 }
355
356 if (sqrt(vtkMath::Distance2BetweenPoints(point,currentPoint)) < VTK_VMTK_DOUBLE_TOL)
357 {
358 groupIdsArray->SetValue(j,tractGroupId);
359 }
360 }
361 }
362
363 centerlineTracts->GetCellData()->AddArray(groupIdsArray);
364
365 groupIdsArray->Delete();
366}
367
368void vtkvmtkCenterlineSplittingAndGroupingFilter::PointInTubeGroupTracts(vtkPolyData* input, vtkPolyData* centerlineTracts)
369{
370 vtkIntArray* blankingArray = vtkIntArray::SafeDownCast(centerlineTracts->GetCellData()->GetArray(this->BlankingArrayName));
371 vtkIntArray* centerlineIdsArray = vtkIntArray::SafeDownCast(centerlineTracts->GetCellData()->GetArray(this->CenterlineIdsArrayName));
372
373 vtkIntArray* groupIdsArray = vtkIntArray::New();
374 groupIdsArray->SetName(this->GroupIdsArrayName);
375 int numberOfCells = centerlineTracts->GetNumberOfCells();
376 groupIdsArray->SetNumberOfComponents(1);
377 groupIdsArray->SetNumberOfTuples(numberOfCells);
378
379 int i;
380 for (i=0; i<numberOfCells; i++)
381 {
382 groupIdsArray->SetValue(i,i);
383 }
384
386 tube->SetInput(centerlineTracts);
388
389 vtkIdList* tubeCellIds = vtkIdList::New();
390
392 centerlineTube->SetInput(centerlineTracts);
393 centerlineTube->SetPolyBallRadiusArrayName(this->RadiusArrayName);
394
395 vtkIdList* centerlineTubeCellIds = vtkIdList::New();
396
397 int numberOfCenterlineCells = input->GetNumberOfCells();
398
399 // group based on point-in-tube criterion
400 for (i=0; i<numberOfCells; i++)
401 {
402 // for all points in the present cell, check if there's one which contains it. If yes, put current id equal to the other's group.
403 // Alternative: for the first point present cell (i.e. the first reference point), check if there's one tube which contains it. If yes, put current id equal to the other's group.
404 if (centerlineTracts->GetCell(i)->GetCellType() != VTK_LINE && centerlineTracts->GetCell(i)->GetCellType() != VTK_POLY_LINE)
405 {
406 continue;
407 }
408
409 centerlineTubeCellIds->Initialize();
410 centerlineTubeCellIds->InsertNextId(i);
411 centerlineTube->SetInputCellIds(centerlineTubeCellIds);
412
413 int centerlineGroupId = groupIdsArray->GetValue(i);
414
415 int centerlineId = centerlineIdsArray->GetValue(i);
416
417 for (int k=0; k<numberOfCenterlineCells; k++)
418 {
419 if (k == centerlineId)
420 {
421 continue;
422 }
423
424 bool centerlineTractAlreadyInGroup = false;
425 int j;
426 for (j=0; j<numberOfCells; j++)
427 {
428 if (j==i)
429 {
430 continue;
431 }
432
433 int tubeCenterlineId = centerlineIdsArray->GetValue(j);
434
435 if (tubeCenterlineId != k)
436 {
437 continue;
438 }
439
440 int tubeCenterlineGroupId = groupIdsArray->GetValue(j);
441 if (tubeCenterlineGroupId == centerlineGroupId)
442 {
443 centerlineTractAlreadyInGroup = true;
444 }
445 }
446
447 if (centerlineTractAlreadyInGroup)
448 {
449 continue;
450 }
451
452 int sameGroupTubeGroupId = -1;
453
454 for (j=0; j<numberOfCells; j++)
455 {
456 if (j==i)
457 {
458 continue;
459 }
460
461 int tubeCenterlineId = centerlineIdsArray->GetValue(j);
462
463 if (tubeCenterlineId != k)
464 {
465 continue;
466 }
467
468 // don't group blanked tracts with non-blanked ones and vice-versa
469 if (blankingArray->GetValue(i) != blankingArray->GetValue(j))
470 {
471 continue;
472 }
473
474 if ((centerlineTracts->GetCell(j)->GetCellType() != VTK_POLY_LINE) && (centerlineTracts->GetCell(j)->GetCellType() != VTK_LINE))
475 {
476 continue;
477 }
478
479 int tubeGroupId = groupIdsArray->GetValue(j);
480
481 if (tubeGroupId == centerlineGroupId)
482 {
483 continue;
484 }
485
486 tubeCellIds->Initialize();
487 tubeCellIds->InsertNextId(j);
488 tube->SetInputCellIds(tubeCellIds);
489 bool pointInTube = false;
490 double minTubeValue = VTK_VMTK_LARGE_DOUBLE;
491 double minCenterlineTubeValue = VTK_VMTK_LARGE_DOUBLE;
492 int l;
493// for (l=0; l<centerlineTracts->GetCell(i)->GetNumberOfPoints(); l++) // any point in tube criterion
494 for (l=0; l<=0; l++) // first point in tube criterion (divergent networks only)
495 {
496 double tubeValue = tube->EvaluateFunction(centerlineTracts->GetCell(i)->GetPoints()->GetPoint(l));
497 double centerlineTubeValue = centerlineTube->EvaluateFunction(tube->GetLastPolyBallCenter());
498
499 if ((tubeValue < -VTK_VMTK_DOUBLE_TOL) && (centerlineTubeValue < -VTK_VMTK_DOUBLE_TOL))
500 {
501 pointInTube = true;
502 if (tubeValue < minTubeValue)
503 {
504 minTubeValue = tubeValue;
505 }
506 if (centerlineTubeValue < minCenterlineTubeValue)
507 {
508 minCenterlineTubeValue = centerlineTubeValue;
509 sameGroupTubeGroupId = tubeGroupId;
510 }
511 }
512 }
513 }
514
515 if (sameGroupTubeGroupId == -1)
516 {
517 continue;
518 }
519
520 for (j=0; j<groupIdsArray->GetNumberOfTuples(); j++)
521 {
522 if (groupIdsArray->GetValue(j) == sameGroupTubeGroupId)
523 {
524 groupIdsArray->SetValue(j,centerlineGroupId);
525 }
526 }
527 }
528 }
529
530 centerlineTracts->GetCellData()->AddArray(groupIdsArray);
531
532 groupIdsArray->Delete();
533 tube->Delete();
534 tubeCellIds->Delete();
535 centerlineTube->Delete();
536 centerlineTubeCellIds->Delete();
537}
538
540{
541 vtkIntArray* groupIdsArray = vtkIntArray::SafeDownCast(centerlineTracts->GetCellData()->GetArray(this->GroupIdsArrayName));
542
543 int currentGroupId = 0;
544 for (int i=0; i<groupIdsArray->GetNumberOfTuples(); i++)
545 {
546 int minGroupId = VTK_VMTK_LARGE_INTEGER;
547 int j;
548 for (j=0; j<groupIdsArray->GetNumberOfTuples(); j++)
549 {
550 int groupId = groupIdsArray->GetValue(j);
551 if ((groupId<minGroupId) && (groupId >= currentGroupId))
552 {
553 minGroupId = groupId;
554 }
555 }
556 for (j=0; j<groupIdsArray->GetNumberOfTuples(); j++)
557 {
558 if (groupIdsArray->GetValue(j)==minGroupId)
559 {
560 groupIdsArray->SetValue(j,currentGroupId);
561 }
562 }
563 ++currentGroupId;
564 }
565}
566
568{
569 vtkIntArray* centerlineIdsArray = vtkIntArray::SafeDownCast(centerlineTracts->GetCellData()->GetArray(this->CenterlineIdsArrayName));
570 vtkIntArray* tractIdsArray = vtkIntArray::SafeDownCast(centerlineTracts->GetCellData()->GetArray(this->TractIdsArrayName));
571
572 vtkIdList* centerlineIds = vtkIdList::New();
573 for (int i=0; i<centerlineIdsArray->GetNumberOfTuples(); i++)
574 {
575 int centerlineId = centerlineIdsArray->GetValue(i);
576 centerlineIds->InsertUniqueId(centerlineId);
577 }
578
579 for (int i=0; i<centerlineIds->GetNumberOfIds(); i++)
580 {
581 int centerlineId = centerlineIds->GetId(i);
582 vtkIdList* tractIdsMap = vtkIdList::New();
583 int maxTractId = -1;
584 for (int j=0; j<tractIdsArray->GetNumberOfTuples(); j++)
585 {
586 if (centerlineIdsArray->GetValue(j) != centerlineId)
587 {
588 continue;
589 }
590 int tractId = tractIdsArray->GetValue(j);
591 if (tractId > maxTractId)
592 {
593 maxTractId = tractId;
594 }
595 }
596 tractIdsMap->SetNumberOfIds(maxTractId+1);
597 for (int j=0; j<tractIdsMap->GetNumberOfIds(); j++)
598 {
599 tractIdsMap->SetId(j,0);
600 }
601 for (int j=0; j<tractIdsArray->GetNumberOfTuples(); j++)
602 {
603 if (centerlineIdsArray->GetValue(j) != centerlineId)
604 {
605 continue;
606 }
607 int tractId = tractIdsArray->GetValue(j);
608 tractIdsMap->SetId(tractId,1);
609 }
610 int currentTractId = 0;
611 for (int j=0; j<tractIdsMap->GetNumberOfIds(); j++)
612 {
613 if (tractIdsMap->GetId(j) == 0)
614 {
615 continue;
616 }
617 tractIdsMap->SetId(j,currentTractId);
618 currentTractId += 1;
619 }
620 for (int j=0; j<tractIdsArray->GetNumberOfTuples(); j++)
621 {
622 if (centerlineIdsArray->GetValue(j) != centerlineId)
623 {
624 continue;
625 }
626 int tractId = tractIdsArray->GetValue(j);
627 tractIdsArray->SetValue(j,tractIdsMap->GetId(tractId));
628 }
629 tractIdsMap->Delete();
630 }
631 centerlineIds->Delete();
632}
633
634void vtkvmtkCenterlineSplittingAndGroupingFilter::SplitCenterline(vtkPolyData* input, vtkIdType cellId, int numberOfSplittingPoints, const vtkIdType* subIds, const double* pcoords, const int* tractBlanking, vtkPolyData* splitCenterline)
635{
636 vtkPointData* inputPD = input->GetPointData();
637 vtkCell* centerline = input->GetCell(cellId);
638
639 if (centerline->GetCellType() != VTK_POLY_LINE && centerline->GetCellType() != VTK_LINE)
640 {
641 return;
642 }
643
644 vtkIdType numberOfCenterlinePoints = centerline->GetNumberOfPoints();
645
646 int numberOfTractPoints;
647
648 splitCenterline->Initialize();
649 vtkPoints* splitCenterlinePoints = vtkPoints::New();
650 vtkCellArray* splitCenterlineCellArray = vtkCellArray::New();
651 vtkIdList* splitCenterlineCellPointIds = vtkIdList::New();
652 vtkPointData* splitCenterlinePD = splitCenterline->GetPointData();
653
654 vtkIntArray* centerlineIdsArray = vtkIntArray::New();
655 centerlineIdsArray->SetNumberOfComponents(1);
656 centerlineIdsArray->SetName(this->CenterlineIdsArrayName);
657
658 vtkIntArray* tractIdsArray = vtkIntArray::New();
659 tractIdsArray->SetNumberOfComponents(1);
660 tractIdsArray->SetName(this->TractIdsArrayName);
661
662 vtkIntArray* blankingArray = vtkIntArray::New();
663 blankingArray->SetNumberOfComponents(1);
664 blankingArray->SetName(this->BlankingArrayName);
665
666 int i;
667 if (numberOfSplittingPoints == 0)
668 {
669 splitCenterlinePoints->DeepCopy(centerline->GetPoints());
670 splitCenterlineCellArray->InsertNextCell(numberOfCenterlinePoints);
671 splitCenterlinePD->CopyAllocate(inputPD,numberOfCenterlinePoints);
672 for (i=0; i<numberOfCenterlinePoints; i++)
673 {
674 splitCenterlinePD->CopyData(inputPD,centerline->GetPointId(i),i);
675 splitCenterlineCellArray->InsertCellPoint(i);
676 }
677 centerlineIdsArray->InsertNextValue(cellId);
678 tractIdsArray->InsertNextValue(0);
679 blankingArray->InsertNextValue(0);
680
681 splitCenterline->SetPoints(splitCenterlinePoints);
682 splitCenterline->SetLines(splitCenterlineCellArray);
683 splitCenterline->GetCellData()->CopyAllocate(input->GetCellData(),1);
684 splitCenterline->GetCellData()->CopyData(input->GetCellData(),cellId,0);
685 splitCenterline->GetCellData()->AddArray(centerlineIdsArray);
686 splitCenterline->GetCellData()->AddArray(tractIdsArray);
687 splitCenterline->GetCellData()->AddArray(blankingArray);
688
689 splitCenterlinePoints->Delete();
690 splitCenterlineCellArray->Delete();
691 splitCenterlineCellPointIds->Delete();
692 centerlineIdsArray->Delete();
693 tractIdsArray->Delete();
694 blankingArray->Delete();
695 return;
696 }
697
698 int numberOfSplitCenterlinePoints = 0;
699 for (i=0; i<=numberOfSplittingPoints; i++)
700 {
701 if (tractBlanking[i] == 1)
702 {
703 continue;
704 }
705 vtkIdType lowerId, higherId;
706
707 numberOfTractPoints = 0;
708
709 if (i==0)
710 {
711 lowerId = 0;
712 }
713 else
714 {
715 lowerId = subIds[i-1]+1;
716 numberOfTractPoints += 1;
717 }
718 if (i==numberOfSplittingPoints)
719 {
720 higherId = numberOfCenterlinePoints-1;
721 }
722 else
723 {
724 higherId = subIds[i];
725 numberOfTractPoints += 1;
726 }
727 if (higherId - lowerId > 0)
728 {
729 numberOfTractPoints += higherId - lowerId;
730 }
731 numberOfSplitCenterlinePoints += numberOfTractPoints;
732 }
733
734 splitCenterlinePD->InterpolateAllocate(inputPD,numberOfSplitCenterlinePoints);
735 splitCenterline->GetCellData()->CopyAllocate(input->GetCellData(),numberOfSplittingPoints+1);
736
737 for (i=0; i<=numberOfSplittingPoints; i++)
738 {
739// if (tractBlanking[i] == 1)
740// {
741// // don't skip here! [Kept as a caveat!]
742// continue;
743// }
744
745 splitCenterlineCellPointIds->Initialize();
746
747 vtkIdType lowerId, higherId;
748
749 lowerId = (i == 0) ? 0 : subIds[i-1]+1;
750 higherId = (i == numberOfSplittingPoints) ? numberOfCenterlinePoints-1 : subIds[i];
751
752 double point[3], point0[3], point1[3];
753 vtkIdType pointId;
754
755 // insert first interpolated point if necessary
756 int j, k;
757 if (i>0)
758 {
759 centerline->GetPoints()->GetPoint(subIds[i-1],point0);
760 centerline->GetPoints()->GetPoint(subIds[i-1]+1,point1);
761 for (k=0; k<3; k++)
762 {
763 point[k] = point0[k] + pcoords[i-1]*(point1[k] - point0[k]);
764 }
765 if (vtkMath::Distance2BetweenPoints(point,centerline->GetPoints()->GetPoint(lowerId))>VTK_VMTK_FLOAT_TOL)
766 {
767 pointId = splitCenterlinePoints->InsertNextPoint(point);
768 splitCenterlineCellPointIds->InsertNextId(pointId);
769 splitCenterlinePD->InterpolateEdge(inputPD,pointId,centerline->GetPointId(subIds[i-1]),centerline->GetPointId(subIds[i-1]+1),pcoords[i-1]);
770 }
771 }
772
773 for (j=lowerId; j<=higherId; j++)
774 {
775 pointId = splitCenterlinePoints->InsertNextPoint(centerline->GetPoints()->GetPoint(j));
776 splitCenterlineCellPointIds->InsertNextId(pointId);
777 splitCenterlinePD->CopyData(inputPD,centerline->GetPointId(j),pointId);
778 }
779
780 // insert last interpolated point if necessary
781 if (i<numberOfSplittingPoints)
782 {
783 centerline->GetPoints()->GetPoint(subIds[i],point0);
784 centerline->GetPoints()->GetPoint(subIds[i]+1,point1);
785 for (k=0; k<3; k++)
786 {
787 point[k] = point0[k] + pcoords[i]*(point1[k] - point0[k]);
788 }
789 if (vtkMath::Distance2BetweenPoints(point,centerline->GetPoints()->GetPoint(higherId))>VTK_VMTK_FLOAT_TOL)
790 {
791 pointId = splitCenterlinePoints->InsertNextPoint(point);
792 splitCenterlineCellPointIds->InsertNextId(pointId);
793 splitCenterlinePD->InterpolateEdge(inputPD,pointId,centerline->GetPointId(subIds[i]),centerline->GetPointId(subIds[i]+1),pcoords[i]);
794 }
795 }
796
797 splitCenterlineCellArray->InsertNextCell(splitCenterlineCellPointIds);
798 centerlineIdsArray->InsertNextValue(cellId);
799 tractIdsArray->InsertNextValue(i);
800 blankingArray->InsertNextValue(tractBlanking[i]);
801 splitCenterline->GetCellData()->CopyData(input->GetCellData(),cellId,i);
802 }
803
804 splitCenterline->SetPoints(splitCenterlinePoints);
805 splitCenterline->SetLines(splitCenterlineCellArray);
806 splitCenterline->GetCellData()->AddArray(centerlineIdsArray);
807 splitCenterline->GetCellData()->AddArray(tractIdsArray);
808 splitCenterline->GetCellData()->AddArray(blankingArray);
809
810 splitCenterlinePoints->Delete();
811 splitCenterlineCellArray->Delete();
812 splitCenterlineCellPointIds->Delete();
813 centerlineIdsArray->Delete();
814 tractIdsArray->Delete();
815 blankingArray->Delete();
816}
817
818void vtkvmtkCenterlineSplittingAndGroupingFilter::PrintSelf(std::ostream& os, vtkIndent indent)
819{
820 this->Superclass::PrintSelf(os,indent);
821}
void SplitCenterline(vtkPolyData *input, vtkIdType cellId, int numberOfSplittingPoints, const vtkIdType *subIds, const double *pcoords, const int *tractBlanking, vtkPolyData *splitCenterline)
virtual int RequestData(vtkInformation *, vtkInformationVector **, vtkInformationVector *) override
void CoincidentExtremePointGroupTracts(vtkPolyData *input, vtkPolyData *centerlineTracts, bool first=true)
void PointInTubeGroupTracts(vtkPolyData *input, vtkPolyData *centerlineTracts)
void PrintSelf(std::ostream &os, vtkIndent indent) override
virtual void ComputeCenterlineSplitting(vtkPolyData *input, vtkIdType cellId)=0
virtual void GroupTracts(vtkPolyData *input, vtkPolyData *centerlineTracts)
static void GetCenterlineCellIds(vtkPolyData *centerlines, const char *centerlineIdsArrayName, vtkIdType centerlineId, vtkIdList *centerlineCellIds)
Implements vtkImplicitFunction to evaluate the minimum sphere function for an envelope created by an ...
virtual double * GetLastPolyBallCenter()
virtual void SetInput(vtkPolyData *)
virtual void SetPolyBallRadiusArrayName(const char *)
virtual void SetInputCellIds(vtkIdList *)
static vtkvmtkPolyBallLine * New()
double EvaluateFunction(double x[3]) override
#define VTK_VMTK_LARGE_INTEGER
#define VTK_VMTK_FLOAT_TOL
#define VTK_VMTK_DOUBLE_TOL
#define VTK_VMTK_LARGE_DOUBLE