298{
300 vtkPoints* outputPoints = output->GetPoints();
301 vtkCellArray* outputLines = output->GetLines();
302 vtkIntArray* bifurcationProfileOrientationArray = vtkIntArray::SafeDownCast(output->GetCellData()->GetArray(this->BifurcationProfileOrientationArrayName));
303 vtkIntArray* bifurcationProfileGroupIdsArray = vtkIntArray::SafeDownCast(output->GetCellData()->GetArray(this->BifurcationProfileGroupIdsArrayName));
304 vtkIntArray* bifurcationProfileBifurcationGroupIdsArray = vtkIntArray::SafeDownCast(output->GetCellData()->GetArray(this->BifurcationProfileBifurcationGroupIdsArrayName));
305
306 vtkIdList* bifurcationProfileGroupIds = vtkIdList::New();
307 vtkIntArray* bifurcationProfileOrientations = vtkIntArray::New();
308
309 int numberOfUpStreamGroupIds = upStreamGroupIds->GetNumberOfIds();
310 int numberOfDownStreamGroupIds = downStreamGroupIds->GetNumberOfIds();
311 int i;
312 for (i=0; i<numberOfUpStreamGroupIds; i++)
313 {
314 bifurcationProfileGroupIds->InsertNextId(upStreamGroupIds->GetId(i));
316 }
317 for (i=0; i<numberOfDownStreamGroupIds; i++)
318 {
319 bifurcationProfileGroupIds->InsertNextId(downStreamGroupIds->GetId(i));
321 }
322
323 int numberOfBifurcationProfiles = bifurcationProfileGroupIds->GetNumberOfIds();
324
325 for (i=0; i<numberOfBifurcationProfiles; i++)
326 {
327 int bifurcationProfileGroupId = bifurcationProfileGroupIds->GetId(i);
328 int bifurcationProfileOrientation = bifurcationProfileOrientations->GetValue(i);
329
330 double averagePoint[3];
331 averagePoint[0] = averagePoint[1] = averagePoint[2] = 0.0;
332
333 double weightSum = 0.0;
334
335 int j;
336 vtkIdList* groupCellIds = vtkIdList::New();
338 for (j=0; j<groupCellIds->GetNumberOfIds(); j++)
339 {
340 vtkIdType cellId = groupCellIds->GetId(j);
341 vtkCell* cell = this->
Centerlines->GetCell(cellId);
342 int numberOfCellPoints = cell->GetNumberOfPoints();
343
344 double lastPoint[3];
345 double lastPointRadius = 0.0;
346
348 {
349 cell->GetPoints()->GetPoint(numberOfCellPoints-1,lastPoint);
350 lastPointRadius = radiusArray->GetComponent(cell->GetPointId(numberOfCellPoints-1),0);
351 }
353 {
354 cell->GetPoints()->GetPoint(0,lastPoint);
355 lastPointRadius = radiusArray->GetComponent(cell->GetPointId(0),0);
356 }
357 else
358 {
359 vtkErrorMacro("Error: invalid BifurcationVectorOrientation");
360 return;
361 }
362
363 averagePoint[0] += lastPointRadius * lastPointRadius * lastPoint[0];
364 averagePoint[1] += lastPointRadius * lastPointRadius * lastPoint[1];
365 averagePoint[2] += lastPointRadius * lastPointRadius * lastPoint[2];
366
367 weightSum += lastPointRadius * lastPointRadius;
368 }
369
370 averagePoint[0] /= weightSum;
371 averagePoint[1] /= weightSum;
372 averagePoint[2] /= weightSum;
373
374 vtkPolyData* cylinder = vtkPolyData::New();
376
378 boundaryExtractor->SetInputData(cylinder);
379 boundaryExtractor->Update();
380
381 vtkPolyData* profile = boundaryExtractor->GetOutput();
382
383 int numberOfCells = profile->GetNumberOfCells();
384 int closestCellId = -1;
386 for (j=0; j<numberOfCells; j++)
387 {
388 double barycenter[3];
390 double barycenterDistance = vtkMath::Distance2BetweenPoints(barycenter,averagePoint);
391 if (barycenterDistance < minDistance)
392 {
393 closestCellId = j;
394 minDistance = barycenterDistance;
395 }
396 }
397
398 vtkPoints* profileCellPoints = profile->GetCell(closestCellId)->GetPoints();
399 int numberOfProfileCellPoints = profileCellPoints->GetNumberOfPoints();
400 outputLines->InsertNextCell(numberOfProfileCellPoints);
401 for (j=0; j<numberOfProfileCellPoints; j++)
402 {
403 vtkIdType pointId = outputPoints->InsertNextPoint(profileCellPoints->GetPoint(j));
404 outputLines->InsertCellPoint(pointId);
405 }
406
407 bifurcationProfileGroupIdsArray->InsertNextValue(bifurcationProfileGroupId);
408 bifurcationProfileBifurcationGroupIdsArray->InsertNextValue(bifurcationGroupId);
409 bifurcationProfileOrientationArray->InsertNextValue(bifurcationProfileOrientation);
410
411 groupCellIds->Delete();
412 cylinder->Delete();
413 boundaryExtractor->Delete();
414 }
415
416 bifurcationProfileGroupIds->Delete();
417 bifurcationProfileOrientations->Delete();
418}
static void ComputeBoundaryBarycenter(vtkPoints *points, double barycenter[3])
@ VTK_VMTK_DOWNSTREAM_ORIENTATION
@ VTK_VMTK_UPSTREAM_ORIENTATION
static void GetGroupUniqueCellIds(vtkPolyData *centerlines, const char *groupIdsArrayName, vtkIdType groupId, vtkIdList *groupCellIds)
static void ExtractGroup(vtkPolyData *surface, const char *groupIdsArrayName, vtkIdType groupId, bool cleanGroupSurface, vtkPolyData *groupSurface)
#define VTK_VMTK_LARGE_DOUBLE