112 vtkInformation *vtkNotUsed(request),
113 vtkInformationVector **inputVector,
114 vtkInformationVector *outputVector)
116 vtkInformation *inInfo = inputVector[0]->GetInformationObject(0);
117 vtkInformation *outInfo = outputVector->GetInformationObject(0);
119 vtkPolyData *input = vtkPolyData::SafeDownCast(
120 inInfo->Get(vtkDataObject::DATA_OBJECT()));
121 vtkPolyData *output = vtkPolyData::SafeDownCast(
122 outInfo->Get(vtkDataObject::DATA_OBJECT()));
124 vtkIdType numberOfInputCells;
128 vtkErrorMacro(<<
"RadiusArrayName not specified");
132 if (!input->GetPointData()->GetArray(this->RadiusArrayName))
134 vtkErrorMacro(<<
"RadiusArray with name specified does not exist");
140 vtkErrorMacro(<<
"GroupIdsArrayName not specified");
146 vtkErrorMacro(<<
"CenterlineIdsArrayName not specified");
152 vtkErrorMacro(<<
"BlankingArrayName not specified");
158 vtkErrorMacro(<<
"TractIdsArrayName not specified");
162 numberOfInputCells = input->GetNumberOfCells();
164 vtkAppendPolyData* appendCenterlinesFilter = vtkAppendPolyData::New();
166 for (
int i=0; i<numberOfInputCells; i++)
169 vtkPolyData* splitCenterline = vtkPolyData::New();
171 appendCenterlinesFilter->AddInputData(splitCenterline);
172 splitCenterline->Delete();
175 appendCenterlinesFilter->Update();
177 vtkPolyData* centerlineTracts = vtkPolyData::New();
178 centerlineTracts->DeepCopy(appendCenterlinesFilter->GetOutput());
180 appendCenterlinesFilter->Delete();
188 output->DeepCopy(centerlineTracts);
190 centerlineTracts->Delete();
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());
205 vtkCellArray* mergedCellArray = vtkCellArray::New();
207 vtkIntArray* groupIdsArray = vtkIntArray::SafeDownCast(centerlineTracts->GetCellData()->GetArray(this->GroupIdsArrayName));
208 vtkIdList* centerlineCellIds = vtkIdList::New();
210 for (i=0; i<numberOfCenterlineCells; i++)
212 centerlineCellIds->Initialize();
214 int numberOfCenterlineTracts = centerlineCellIds->GetNumberOfIds();
217 for (j=0; j<numberOfCenterlineTracts; j++)
219 int tractCellId = centerlineCellIds->GetId(j);
220 int groupId = groupIdsArray->GetValue(tractCellId);
222 for (k=numberOfCenterlineTracts-1; k > j; k--)
224 int downstreamTractCellId = centerlineCellIds->GetId(k);
225 if (groupId == groupIdsArray->GetValue(downstreamTractCellId))
229 for (l=j+1; l<k; l++)
231 groupIdsArray->SetValue(centerlineCellIds->GetId(l),groupId);
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++)
247 int tractCellId = centerlineCellIds->GetId(j);
248 centerlineTracts->GetCellPoints(tractCellId,tractCellPointIds);
249 int groupId = groupIdsArray->GetValue(tractCellId);
250 if ((groupId != previousGroupId) || (j == numberOfCenterlineTracts-1))
252 if (previousGroupId != -1)
254 currentMergedCellId = mergedCellArray->InsertNextCell(mergedCellPointIds);
255 mergedCenterlineTracts->GetCellData()->CopyData(centerlineTracts->GetCellData(),firstTractCellId,currentMergedCellId);
257 firstTractCellId = tractCellId;
258 mergedCellPointIds->DeepCopy(tractCellPointIds);
259 if (j == numberOfCenterlineTracts-1)
261 currentMergedCellId = mergedCellArray->InsertNextCell(mergedCellPointIds);
262 mergedCenterlineTracts->GetCellData()->CopyData(centerlineTracts->GetCellData(),firstTractCellId,currentMergedCellId);
267 int numberOfTractCellPoints = tractCellPointIds->GetNumberOfIds();
269 for (k=1; k<numberOfTractCellPoints; k++)
271 mergedCellPointIds->InsertNextId(tractCellPointIds->GetId(k));
274 previousGroupId = groupId;
276 tractCellPointIds->Delete();
277 mergedCellPointIds->Delete();
280 mergedCenterlineTracts->SetLines(mergedCellArray);
282 centerlineTracts->DeepCopy(mergedCenterlineTracts);
284 mergedCellArray->Delete();
285 mergedCenterlineTracts->Delete();
286 mergedCenterlineTractsPoints->Delete();
287 centerlineCellIds->Delete();
310 vtkIntArray* groupIdsArray = vtkIntArray::New();
312 int numberOfCells = centerlineTracts->GetNumberOfCells();
313 groupIdsArray->SetNumberOfComponents(1);
314 groupIdsArray->SetNumberOfTuples(numberOfCells);
317 for (i=0; i<numberOfCells; i++)
319 groupIdsArray->SetValue(i,i);
323 for (i=0; i<numberOfCells; i++)
325 if (centerlineTracts->GetCell(i)->GetCellType() != VTK_LINE && centerlineTracts->GetCell(i)->GetCellType() != VTK_POLY_LINE)
330 int tractGroupId = groupIdsArray->GetValue(i);
334 centerlineTracts->GetCell(i)->GetPoints()->GetPoint(0,point);
338 int numberOfCellPoints = centerlineTracts->GetCell(i)->GetNumberOfPoints();
339 centerlineTracts->GetCell(i)->GetPoints()->GetPoint(numberOfCellPoints-1,point);
343 for (j=i; j<numberOfCells; j++)
345 double currentPoint[3];
348 centerlineTracts->GetCell(j)->GetPoints()->GetPoint(0,currentPoint);
352 int numberOfCellPoints = centerlineTracts->GetCell(j)->GetNumberOfPoints();
353 centerlineTracts->GetCell(j)->GetPoints()->GetPoint(numberOfCellPoints-1,currentPoint);
358 groupIdsArray->SetValue(j,tractGroupId);
363 centerlineTracts->GetCellData()->AddArray(groupIdsArray);
365 groupIdsArray->Delete();
370 vtkIntArray* blankingArray = vtkIntArray::SafeDownCast(centerlineTracts->GetCellData()->GetArray(this->BlankingArrayName));
371 vtkIntArray* centerlineIdsArray = vtkIntArray::SafeDownCast(centerlineTracts->GetCellData()->GetArray(this->CenterlineIdsArrayName));
373 vtkIntArray* groupIdsArray = vtkIntArray::New();
375 int numberOfCells = centerlineTracts->GetNumberOfCells();
376 groupIdsArray->SetNumberOfComponents(1);
377 groupIdsArray->SetNumberOfTuples(numberOfCells);
380 for (i=0; i<numberOfCells; i++)
382 groupIdsArray->SetValue(i,i);
389 vtkIdList* tubeCellIds = vtkIdList::New();
392 centerlineTube->
SetInput(centerlineTracts);
395 vtkIdList* centerlineTubeCellIds = vtkIdList::New();
397 int numberOfCenterlineCells = input->GetNumberOfCells();
400 for (i=0; i<numberOfCells; i++)
404 if (centerlineTracts->GetCell(i)->GetCellType() != VTK_LINE && centerlineTracts->GetCell(i)->GetCellType() != VTK_POLY_LINE)
409 centerlineTubeCellIds->Initialize();
410 centerlineTubeCellIds->InsertNextId(i);
413 int centerlineGroupId = groupIdsArray->GetValue(i);
415 int centerlineId = centerlineIdsArray->GetValue(i);
417 for (
int k=0; k<numberOfCenterlineCells; k++)
419 if (k == centerlineId)
424 bool centerlineTractAlreadyInGroup =
false;
426 for (j=0; j<numberOfCells; j++)
433 int tubeCenterlineId = centerlineIdsArray->GetValue(j);
435 if (tubeCenterlineId != k)
440 int tubeCenterlineGroupId = groupIdsArray->GetValue(j);
441 if (tubeCenterlineGroupId == centerlineGroupId)
443 centerlineTractAlreadyInGroup =
true;
447 if (centerlineTractAlreadyInGroup)
452 int sameGroupTubeGroupId = -1;
454 for (j=0; j<numberOfCells; j++)
461 int tubeCenterlineId = centerlineIdsArray->GetValue(j);
463 if (tubeCenterlineId != k)
469 if (blankingArray->GetValue(i) != blankingArray->GetValue(j))
474 if ((centerlineTracts->GetCell(j)->GetCellType() != VTK_POLY_LINE) && (centerlineTracts->GetCell(j)->GetCellType() != VTK_LINE))
479 int tubeGroupId = groupIdsArray->GetValue(j);
481 if (tubeGroupId == centerlineGroupId)
486 tubeCellIds->Initialize();
487 tubeCellIds->InsertNextId(j);
489 bool pointInTube =
false;
496 double tubeValue = tube->
EvaluateFunction(centerlineTracts->GetCell(i)->GetPoints()->GetPoint(l));
502 if (tubeValue < minTubeValue)
504 minTubeValue = tubeValue;
506 if (centerlineTubeValue < minCenterlineTubeValue)
508 minCenterlineTubeValue = centerlineTubeValue;
509 sameGroupTubeGroupId = tubeGroupId;
515 if (sameGroupTubeGroupId == -1)
520 for (j=0; j<groupIdsArray->GetNumberOfTuples(); j++)
522 if (groupIdsArray->GetValue(j) == sameGroupTubeGroupId)
524 groupIdsArray->SetValue(j,centerlineGroupId);
530 centerlineTracts->GetCellData()->AddArray(groupIdsArray);
532 groupIdsArray->Delete();
534 tubeCellIds->Delete();
535 centerlineTube->Delete();
536 centerlineTubeCellIds->Delete();
569 vtkIntArray* centerlineIdsArray = vtkIntArray::SafeDownCast(centerlineTracts->GetCellData()->GetArray(this->CenterlineIdsArrayName));
570 vtkIntArray* tractIdsArray = vtkIntArray::SafeDownCast(centerlineTracts->GetCellData()->GetArray(this->TractIdsArrayName));
572 vtkIdList* centerlineIds = vtkIdList::New();
573 for (
int i=0; i<centerlineIdsArray->GetNumberOfTuples(); i++)
575 int centerlineId = centerlineIdsArray->GetValue(i);
576 centerlineIds->InsertUniqueId(centerlineId);
579 for (
int i=0; i<centerlineIds->GetNumberOfIds(); i++)
581 int centerlineId = centerlineIds->GetId(i);
582 vtkIdList* tractIdsMap = vtkIdList::New();
584 for (
int j=0; j<tractIdsArray->GetNumberOfTuples(); j++)
586 if (centerlineIdsArray->GetValue(j) != centerlineId)
590 int tractId = tractIdsArray->GetValue(j);
591 if (tractId > maxTractId)
593 maxTractId = tractId;
596 tractIdsMap->SetNumberOfIds(maxTractId+1);
597 for (
int j=0; j<tractIdsMap->GetNumberOfIds(); j++)
599 tractIdsMap->SetId(j,0);
601 for (
int j=0; j<tractIdsArray->GetNumberOfTuples(); j++)
603 if (centerlineIdsArray->GetValue(j) != centerlineId)
607 int tractId = tractIdsArray->GetValue(j);
608 tractIdsMap->SetId(tractId,1);
610 int currentTractId = 0;
611 for (
int j=0; j<tractIdsMap->GetNumberOfIds(); j++)
613 if (tractIdsMap->GetId(j) == 0)
617 tractIdsMap->SetId(j,currentTractId);
620 for (
int j=0; j<tractIdsArray->GetNumberOfTuples(); j++)
622 if (centerlineIdsArray->GetValue(j) != centerlineId)
626 int tractId = tractIdsArray->GetValue(j);
627 tractIdsArray->SetValue(j,tractIdsMap->GetId(tractId));
629 tractIdsMap->Delete();
631 centerlineIds->Delete();
636 vtkPointData* inputPD = input->GetPointData();
637 vtkCell* centerline = input->GetCell(cellId);
639 if (centerline->GetCellType() != VTK_POLY_LINE && centerline->GetCellType() != VTK_LINE)
644 vtkIdType numberOfCenterlinePoints = centerline->GetNumberOfPoints();
646 int numberOfTractPoints;
648 splitCenterline->Initialize();
649 vtkPoints* splitCenterlinePoints = vtkPoints::New();
650 vtkCellArray* splitCenterlineCellArray = vtkCellArray::New();
651 vtkIdList* splitCenterlineCellPointIds = vtkIdList::New();
652 vtkPointData* splitCenterlinePD = splitCenterline->GetPointData();
654 vtkIntArray* centerlineIdsArray = vtkIntArray::New();
655 centerlineIdsArray->SetNumberOfComponents(1);
658 vtkIntArray* tractIdsArray = vtkIntArray::New();
659 tractIdsArray->SetNumberOfComponents(1);
662 vtkIntArray* blankingArray = vtkIntArray::New();
663 blankingArray->SetNumberOfComponents(1);
667 if (numberOfSplittingPoints == 0)
669 splitCenterlinePoints->DeepCopy(centerline->GetPoints());
670 splitCenterlineCellArray->InsertNextCell(numberOfCenterlinePoints);
671 splitCenterlinePD->CopyAllocate(inputPD,numberOfCenterlinePoints);
672 for (i=0; i<numberOfCenterlinePoints; i++)
674 splitCenterlinePD->CopyData(inputPD,centerline->GetPointId(i),i);
675 splitCenterlineCellArray->InsertCellPoint(i);
677 centerlineIdsArray->InsertNextValue(cellId);
678 tractIdsArray->InsertNextValue(0);
679 blankingArray->InsertNextValue(0);
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);
689 splitCenterlinePoints->Delete();
690 splitCenterlineCellArray->Delete();
691 splitCenterlineCellPointIds->Delete();
692 centerlineIdsArray->Delete();
693 tractIdsArray->Delete();
694 blankingArray->Delete();
698 int numberOfSplitCenterlinePoints = 0;
699 for (i=0; i<=numberOfSplittingPoints; i++)
701 if (tractBlanking[i] == 1)
705 vtkIdType lowerId, higherId;
707 numberOfTractPoints = 0;
715 lowerId = subIds[i-1]+1;
716 numberOfTractPoints += 1;
718 if (i==numberOfSplittingPoints)
720 higherId = numberOfCenterlinePoints-1;
724 higherId = subIds[i];
725 numberOfTractPoints += 1;
727 if (higherId - lowerId > 0)
729 numberOfTractPoints += higherId - lowerId;
731 numberOfSplitCenterlinePoints += numberOfTractPoints;
734 splitCenterlinePD->InterpolateAllocate(inputPD,numberOfSplitCenterlinePoints);
735 splitCenterline->GetCellData()->CopyAllocate(input->GetCellData(),numberOfSplittingPoints+1);
737 for (i=0; i<=numberOfSplittingPoints; i++)
745 splitCenterlineCellPointIds->Initialize();
747 vtkIdType lowerId, higherId;
749 lowerId = (i == 0) ? 0 : subIds[i-1]+1;
750 higherId = (i == numberOfSplittingPoints) ? numberOfCenterlinePoints-1 : subIds[i];
752 double point[3], point0[3], point1[3];
759 centerline->GetPoints()->GetPoint(subIds[i-1],point0);
760 centerline->GetPoints()->GetPoint(subIds[i-1]+1,point1);
763 point[k] = point0[k] + pcoords[i-1]*(point1[k] - point0[k]);
765 if (vtkMath::Distance2BetweenPoints(point,centerline->GetPoints()->GetPoint(lowerId))>
VTK_VMTK_FLOAT_TOL)
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]);
773 for (j=lowerId; j<=higherId; j++)
775 pointId = splitCenterlinePoints->InsertNextPoint(centerline->GetPoints()->GetPoint(j));
776 splitCenterlineCellPointIds->InsertNextId(pointId);
777 splitCenterlinePD->CopyData(inputPD,centerline->GetPointId(j),pointId);
781 if (i<numberOfSplittingPoints)
783 centerline->GetPoints()->GetPoint(subIds[i],point0);
784 centerline->GetPoints()->GetPoint(subIds[i]+1,point1);
787 point[k] = point0[k] + pcoords[i]*(point1[k] - point0[k]);
789 if (vtkMath::Distance2BetweenPoints(point,centerline->GetPoints()->GetPoint(higherId))>
VTK_VMTK_FLOAT_TOL)
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]);
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);
804 splitCenterline->SetPoints(splitCenterlinePoints);
805 splitCenterline->SetLines(splitCenterlineCellArray);
806 splitCenterline->GetCellData()->AddArray(centerlineIdsArray);
807 splitCenterline->GetCellData()->AddArray(tractIdsArray);
808 splitCenterline->GetCellData()->AddArray(blankingArray);
810 splitCenterlinePoints->Delete();
811 splitCenterlineCellArray->Delete();
812 splitCenterlineCellPointIds->Delete();
813 centerlineIdsArray->Delete();
814 tractIdsArray->Delete();
815 blankingArray->Delete();