88 vtkInformation *inInfo = inputVector[0]->GetInformationObject(0);
89 vtkInformation *outInfo = outputVector->GetInformationObject(0);
91 vtkPolyData *input = vtkPolyData::SafeDownCast(inInfo->Get(vtkDataObject::DATA_OBJECT()));
92 vtkPolyData *output = vtkPolyData::SafeDownCast(outInfo->Get(vtkDataObject::DATA_OBJECT()));
96 vtkErrorMacro(<<
"RadiusArrayName not specified");
100 vtkDataArray* radiusArray = input->GetPointData()->GetArray(this->
RadiusArrayName);
104 vtkErrorMacro(<<
"RadiusArray with name specified does not exist");
110 vtkErrorMacro(<<
"GroupIdsArrayName not specified");
114 vtkDataArray* groupIdsArray = input->GetCellData()->GetArray(this->
GroupIdsArrayName);
118 vtkErrorMacro(<<
"GroupIdsArray with name specified does not exist");
124 vtkErrorMacro(<<
"CenterlineIdsArrayName not specified");
130 if (!centerlineIdsArray)
132 vtkErrorMacro(<<
"CenterlineIdsArray with name specified does not exist");
138 vtkErrorMacro(<<
"TractIdsArrayName not specified");
142 vtkDataArray* tractIdsArray = input->GetCellData()->GetArray(this->
TractIdsArrayName);
146 vtkErrorMacro(<<
"TractIdsArray with name specified does not exist");
152 vtkErrorMacro(<<
"BlankingArrayName not specified");
156 vtkDataArray* blankingArray = input->GetCellData()->GetArray(this->
BlankingArrayName);
160 vtkErrorMacro(<<
"BlankingArray with name specified does not exist");
164 vtkCleanPolyData* cleaner = vtkCleanPolyData::New();
165 cleaner->SetInputData(input);
173 vtkSplineFilter* resampler = vtkSplineFilter::New();
174 resampler->SetInputConnection(cleaner->GetOutputPort());
175 resampler->SetSubdivideToLength();
179 vtkPolyData* resampledCenterlines = vtkPolyData::New();
180 resampledCenterlines->DeepCopy(resampler->GetOutput());
185 radiusArray = resampledCenterlines->GetPointData()->GetArray(this->
RadiusArrayName);
187 vtkPoints* outputPoints = vtkPoints::New();
188 vtkCellArray* outputLines = vtkCellArray::New();
190 output->SetPoints(outputPoints);
191 output->SetLines(outputLines);
193 output->GetPointData()->CopyAllocate(resampledCenterlines->GetPointData());
194 output->GetCellData()->CopyAllocate(resampledCenterlines->GetCellData());
196 vtkIdList* nonBlankedGroupIds = vtkIdList::New();
199 vtkIdList* groupIdsToMergedCells = vtkIdList::New();
201 groupIdsToMergedCells->SetNumberOfIds(maxGroupId);
203 for (i=0; i<maxGroupId; i++)
205 groupIdsToMergedCells->SetId(i,-1);
208 vtkIdTypeArray* cellEndPointIds = vtkIdTypeArray::New();
209 cellEndPointIds->SetNumberOfComponents(2);
211 for (i=0; i<nonBlankedGroupIds->GetNumberOfIds(); i++)
213 vtkIdType groupId = nonBlankedGroupIds->GetId(i);
214 vtkIdList* groupUniqueCellIds = vtkIdList::New();
218 int numberOfMergedCellPoints = 0;
220 for (j=0; j<groupUniqueCellIds->GetNumberOfIds(); j++)
222 vtkIdType cellId = groupUniqueCellIds->GetId(j);
223 int numberOfCellPoints = resampledCenterlines->GetCell(cellId)->GetNumberOfPoints();
224 if ((j==0) || (numberOfCellPoints < numberOfMergedCellPoints))
226 numberOfMergedCellPoints = numberOfCellPoints;
230 vtkIdType mergedCellId = outputLines->InsertNextCell(numberOfMergedCellPoints);
231 groupIdsToMergedCells->InsertId(groupId,mergedCellId);
233 for (k=0; k<numberOfMergedCellPoints; k++)
235 double mergedPoint[3];
236 mergedPoint[0] = 0.0;
237 mergedPoint[1] = 0.0;
238 mergedPoint[2] = 0.0;
239 double weightSum = 0.0;
240 for (j=0; j<groupUniqueCellIds->GetNumberOfIds(); j++)
242 vtkIdType cellId = groupUniqueCellIds->GetId(j);
244 vtkIdType pointId = resampledCenterlines->GetCell(cellId)->GetPointId(k);
245 resampledCenterlines->GetPoint(pointId,point);
246 double radius = radiusArray->GetTuple1(pointId);
247 double weight = radius*radius;
248 resampledCenterlines->GetCell(cellId)->GetPoints()->GetPoint(k,point);
249 mergedPoint[0] += weight * point[0];
250 mergedPoint[1] += weight * point[1];
251 mergedPoint[2] += weight * point[2];
254 mergedPoint[0] /= weightSum;
255 mergedPoint[1] /= weightSum;
256 mergedPoint[2] /= weightSum;
257 vtkIdType mergedPointId = outputPoints->InsertNextPoint(mergedPoint);
258 outputLines->InsertCellPoint(mergedPointId);
259 vtkIdType cellId = groupUniqueCellIds->GetId(0);
260 vtkIdType pointId = resampledCenterlines->GetCell(cellId)->GetPointId(k);
261 output->GetPointData()->CopyData(resampledCenterlines->GetPointData(),pointId,mergedPointId);
262 if (k==0 || k==numberOfMergedCellPoints-1)
264 cellEndPointIds->InsertNextValue(mergedPointId);
268 vtkIdType cellId = groupUniqueCellIds->GetId(0);
269 output->GetCellData()->CopyData(resampledCenterlines->GetCellData(),cellId,mergedCellId);
271 groupUniqueCellIds->Delete();
276 nonBlankedGroupIds->Delete();
277 resampledCenterlines->Delete();
278 outputPoints->Delete();
279 outputLines->Delete();
280 groupIdsToMergedCells->Delete();
281 cellEndPointIds->Delete();
286 referenceSystemsFilter->SetInputData(resampledCenterlines);
292 referenceSystemsFilter->Update();
294 vtkPolyData* referenceSystems = referenceSystemsFilter->GetOutput();
296 int numberOfMergedCells = outputLines->GetNumberOfCells();
298 vtkIdList* blankedGroupIds = vtkIdList::New();
300 vtkIdList* groupIdsToBifurcationPointIds = vtkIdList::New();
301 vtkIdTypeArray* cellAdditionalEndPointIds = vtkIdTypeArray::New();
302 cellAdditionalEndPointIds->SetNumberOfComponents(2);
303 cellAdditionalEndPointIds->SetNumberOfTuples(numberOfMergedCells);
304 vtkIdType tupleValue[2];
305 tupleValue[0] = tupleValue[1] = -1;
306 for (i=0; i<numberOfMergedCells; i++)
308 cellAdditionalEndPointIds->SetTypedTuple(i, tupleValue);
311 for (i=0; i<blankedGroupIds->GetNumberOfIds(); i++)
313 vtkIdType groupId = blankedGroupIds->GetId(i);
317 vtkIdList* upStreamGroupIds = vtkIdList::New();
318 vtkIdList* downStreamGroupIds = vtkIdList::New();
322 double bifurcationPoint[3];
323 referenceSystems->GetPoint(referenceSystemPointId,bifurcationPoint);
325 vtkIdType bifurcationPointId = outputPoints->InsertNextPoint(bifurcationPoint);
327 vtkIdType sourcePointId = -1;
329 for (j=0; j<upStreamGroupIds->GetNumberOfIds(); j++)
331 vtkIdType mergedCellId = groupIdsToMergedCells->GetId(upStreamGroupIds->GetId(j));
332 if (mergedCellId == -1)
336 if (sourcePointId == -1)
338 vtkIdList* groupUniqueCellIds = vtkIdList::New();
340 vtkCell* resampledCell = resampledCenterlines->GetCell(groupUniqueCellIds->GetId(0));
341 sourcePointId = resampledCell->GetPointId(resampledCell->GetNumberOfPoints()-1);
342 groupUniqueCellIds->Delete();
344 vtkIdType tupleValue[2];
345 cellAdditionalEndPointIds->GetTypedTuple(mergedCellId,tupleValue);
346 tupleValue[1] = bifurcationPointId;
347 cellAdditionalEndPointIds->SetTypedTuple(mergedCellId, tupleValue);
350 for (j=0; j<downStreamGroupIds->GetNumberOfIds(); j++)
352 vtkIdType mergedCellId = groupIdsToMergedCells->GetId(downStreamGroupIds->GetId(j));
353 if (mergedCellId == -1)
357 if (sourcePointId == -1)
359 vtkIdList* groupUniqueCellIds = vtkIdList::New();
361 vtkCell* resampledCell = resampledCenterlines->GetCell(groupUniqueCellIds->GetId(0));
362 sourcePointId = resampledCell->GetPointId(0);
363 groupUniqueCellIds->Delete();
365 vtkIdType tupleValue[2];
366 cellAdditionalEndPointIds->GetTypedTuple(mergedCellId, tupleValue);
367 tupleValue[0] = bifurcationPointId;
368 cellAdditionalEndPointIds->SetTypedTuple(mergedCellId, tupleValue);
370 if (sourcePointId == -1)
372 upStreamGroupIds->Delete();
373 downStreamGroupIds->Delete();
378 output->GetPointData()->CopyData(resampledCenterlines->GetPointData(),sourcePointId,bifurcationPointId);
380 upStreamGroupIds->Delete();
381 downStreamGroupIds->Delete();
384 vtkCellArray* extendedOutputLines = vtkCellArray::New();
385 outputLines->InitTraversal();
386 for (i=0; i<numberOfMergedCells; i++)
389 const vtkIdType *pts;
392 outputLines->GetNextCell(npts,pts);
393 vtkIdType tupleValue[2];
394 cellAdditionalEndPointIds->GetTypedTuple(i, tupleValue);
395 vtkIdType extendedNpts = npts;
396 if (tupleValue[0] != -1)
400 if (tupleValue[1] != -1)
404 extendedOutputLines->InsertNextCell(extendedNpts);
405 if (tupleValue[0] != -1)
407 extendedOutputLines->InsertCellPoint(tupleValue[0]);
410 for (j=0; j<npts; j++)
412 extendedOutputLines->InsertCellPoint(pts[j]);
414 if (tupleValue[1] != -1)
416 extendedOutputLines->InsertCellPoint(tupleValue[1]);
420 output->SetLines(extendedOutputLines);
422 nonBlankedGroupIds->Delete();
423 resampledCenterlines->Delete();
424 outputPoints->Delete();
425 outputLines->Delete();
426 groupIdsToMergedCells->Delete();
427 cellEndPointIds->Delete();
429 referenceSystemsFilter->Delete();
430 blankedGroupIds->Delete();
431 groupIdsToBifurcationPointIds->Delete();
432 cellAdditionalEndPointIds->Delete();
433 extendedOutputLines->Delete();