125 vtkInformation *vtkNotUsed(request),
126 vtkInformationVector **inputVector,
127 vtkInformationVector *outputVector)
129 vtkInformation *inInfo = inputVector[0]->GetInformationObject(0);
130 vtkInformation *outInfo = outputVector->GetInformationObject(0);
132 vtkPolyData *input = vtkPolyData::SafeDownCast(
133 inInfo->Get(vtkDataObject::DATA_OBJECT()));
134 vtkPolyData *output = vtkPolyData::SafeDownCast(
135 outInfo->Get(vtkDataObject::DATA_OBJECT()));
139 vtkErrorMacro(<<
"BoundaryMetricArrayName not set.");
145 vtkErrorMacro(<<
"GroupIdsArrayName not set.");
149 vtkDataArray* groupIdsArray = input->GetPointData()->GetArray(this->
GroupIdsArrayName);
153 vtkErrorMacro(<<
"GroupIdsArray with name specified does not exist.");
159 vtkErrorMacro(<<
"Centerlines not set");
165 vtkErrorMacro(<<
"CenterlineAbscissasArrayName not set.");
171 if (!centerlineAbscissasArray)
173 vtkErrorMacro(<<
"CenterlineAbscissasArray with name specified does not exist.");
179 vtkErrorMacro(<<
"CenterlineRadiusArrayName not set.");
185 if (!centerlineRadiusArray)
187 vtkErrorMacro(<<
"CenterlineRadiusArray with name specified does not exist.");
193 vtkErrorMacro(<<
"CenterlineGroupIdsArrayName not set.");
199 if (!centerlineGroupIdsArray)
201 vtkErrorMacro(<<
"CenterlineGroupIdsArrayName with name specified does not exist.");
207 vtkErrorMacro(<<
"CenterlineIdsArrayName not set.");
213 if (!centerlineIdsArray)
215 vtkErrorMacro(<<
"CenterlineIdsArrayName with name specified does not exist.");
221 vtkErrorMacro(<<
"CenterlineTractIdsArrayName not set.");
227 if (!centerlineTractIdsArray)
229 vtkErrorMacro(<<
"CenterlineTractIdsArrayName with name specified does not exist.");
235 vtkErrorMacro(<<
"ReferenceSystems not set");
241 vtkErrorMacro(<<
"ReferenceSystemGroupIdsArrayName not set.");
247 if (!referenceSystemGroupIdsArray)
249 vtkErrorMacro(<<
"ReferenceSystemGroupIdsArrayName with name specified does not exist.");
253 int numberOfInputPoints = input->GetNumberOfPoints();
255 output->DeepCopy(input);
257 vtkDoubleArray* boundaryMetricArray = vtkDoubleArray::New();
259 boundaryMetricArray->SetNumberOfComponents(1);
260 boundaryMetricArray->SetNumberOfTuples(numberOfInputPoints);
261 boundaryMetricArray->FillComponent(0,0.0);
263 output->GetPointData()->AddArray(boundaryMetricArray);
267 vtkIdList* groupIds = vtkIdList::New();
270 for (i=0; i<groupIds->GetNumberOfIds(); i++)
272 vtkIdType groupId = groupIds->GetId(i);
273 vtkPolyData* cylinder = vtkPolyData::New();
277 boundaryExtractor->SetInputData(cylinder);
278 boundaryExtractor->Update();
280 int numberOfBoundaries = boundaryExtractor->GetOutput()->GetNumberOfCells();
282 if (numberOfBoundaries != 2)
284 vtkErrorMacro(<<
"Branch is not topologically a cylinder");
288 vtkIdList* centerlineGroupCellIds = vtkIdList::New();
297 double boundaryAbscissa[2];
300 for (j=0; j<numberOfBoundaries; j++)
302 vtkPolyLine* boundary = vtkPolyLine::SafeDownCast(boundaryExtractor->GetOutput()->GetCell(j));
304 if (boundary->GetNumberOfPoints() == 0)
306 vtkErrorMacro(<<
"Zero-length boundary found");
315 double abscissa = 0.0;
318 boundaryAbscissa[j] = abscissa;
321 int boundaryOrderedIds[2];
322 boundaryOrderedIds[0] = 0;
323 boundaryOrderedIds[1] = 1;
324 if (boundaryAbscissa[0] > boundaryAbscissa[1])
326 boundaryOrderedIds[0] = 1;
327 boundaryOrderedIds[1] = 0;
332 vtkIdList* upStreamGroupIds = vtkIdList::New();
333 vtkIdList* downStreamGroupIds = vtkIdList::New();
337 if ((upStreamGroupIds->GetNumberOfIds() > 1) || (downStreamGroupIds->GetNumberOfIds() > 1))
339 vtkErrorMacro(<<
"More than one adjacent group found for current group. Not topologically a cylinder.");
343 vtkIdType referenceSystemGroupIds[2];
344 referenceSystemGroupIds[0] = -1;
345 referenceSystemGroupIds[1] = -1;
346 vtkIdType referenceSystemPointIds[2];
347 referenceSystemPointIds[0] = -1;
348 referenceSystemPointIds[1] = -1;
350 if (upStreamGroupIds->GetNumberOfIds() > 0)
352 referenceSystemGroupIds[0] = upStreamGroupIds->GetId(0);
355 if (downStreamGroupIds->GetNumberOfIds() > 0)
357 referenceSystemGroupIds[1] = downStreamGroupIds->GetId(0);
363 if (referenceSystemGroupIds[n] == -1)
368 if (referenceSystemPointIds[n] == -1)
370 vtkErrorMacro(<<
"Centerline group ids and reference system group ids are inconsistent.");
378 double referenceSystemAbscissas[2];
379 referenceSystemAbscissas[0] = 0.0;
380 referenceSystemAbscissas[1] = 0.0;
384 if (referenceSystemGroupIds[n] != -1)
390 double weightSum = 0.0;
392 vtkIdList* centerlineGroupAllCellIds = vtkIdList::New();
394 for (j=0; j<centerlineGroupAllCellIds->GetNumberOfIds(); j++)
396 centerlineGroupCellIds->Initialize();
397 centerlineGroupCellIds->InsertNextId(centerlineGroupAllCellIds->GetId(j));
408 double weight = radius * radius;
409 double abscissa = 0.0;
412 referenceSystemAbscissas[n] += weight * abscissa;
415 referenceSystemAbscissas[n] /= weightSum;
422 referenceSystemAbscissas[n] = VTK_DOUBLE_MAX;
424 vtkIdList* centerlineGroupCellIds = vtkIdList::New();
426 for (j=0; j<centerlineGroupCellIds->GetNumberOfIds(); j++)
428 vtkIdType centerlineCellId = centerlineGroupCellIds->GetId(j);
429 double abscissa = centerlineAbscissasArray->GetComponent(this->
Centerlines->GetCell(centerlineCellId)->GetPointId(0),0);
430 if (abscissa < referenceSystemAbscissas[n])
432 referenceSystemAbscissas[n] = abscissa;
435 centerlineGroupCellIds->Delete();
439 referenceSystemAbscissas[n] = VTK_DOUBLE_MIN;
441 vtkIdList* centerlineGroupCellIds = vtkIdList::New();
443 for (j=0; j<centerlineGroupCellIds->GetNumberOfIds(); j++)
445 vtkIdType centerlineCellId = centerlineGroupCellIds->GetId(j);
447 int numberOfCellPoints = this->
Centerlines->GetCell(centerlineCellId)->GetNumberOfPoints();
448 double abscissa = centerlineAbscissasArray->GetComponent(this->
Centerlines->GetCell(centerlineCellId)->GetPointId(numberOfCellPoints-1),0);
449 if (abscissa > referenceSystemAbscissas[n])
451 referenceSystemAbscissas[n] = abscissa;
462 vtkCell* boundary = boundaryExtractor->GetOutput()->GetCell(boundaryOrderedIds[n]);
463 vtkDataArray* boundaryPointIds = boundaryExtractor->GetOutput()->GetPointData()->GetScalars();
464 int numberOfBoundaryPoints = boundary->GetNumberOfPoints();
465 for (j=0; j<numberOfBoundaryPoints; j++)
467 vtkIdType boundaryPointId =
static_cast<int>(boundaryPointIds->GetComponent(boundary->GetPointId(j),0));
468 boundaryMetricArray->SetComponent(boundaryPointId,0,referenceSystemAbscissas[n]);
473 centerlineGroupCellIds->Delete();
474 boundaryExtractor->Delete();
476 upStreamGroupIds->Delete();
477 downStreamGroupIds->Delete();
481 boundaryMetricArray->Delete();