110 vtkInformation *vtkNotUsed(request),
111 vtkInformationVector **inputVector,
112 vtkInformationVector *outputVector)
114 vtkInformation *inInfo = inputVector[0]->GetInformationObject(0);
115 vtkInformation *outInfo = outputVector->GetInformationObject(0);
117 vtkPolyData *input = vtkPolyData::SafeDownCast(
118 inInfo->Get(vtkDataObject::DATA_OBJECT()));
119 vtkPolyData *output = vtkPolyData::SafeDownCast(
120 outInfo->Get(vtkDataObject::DATA_OBJECT()));
124 vtkErrorMacro(<<
"RadiusArrayName not specified");
128 vtkDataArray* radiusArray = input->GetPointData()->GetArray(this->
RadiusArrayName);
132 vtkErrorMacro(<<
"RadiusArray with name specified does not exist");
138 vtkErrorMacro(<<
"GroupIdsArrayName not specified");
142 vtkDataArray* groupIdsArray = input->GetCellData()->GetArray(this->
GroupIdsArrayName);
146 vtkErrorMacro(<<
"GroupIdsArray 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");
166 vtkErrorMacro(<<
"LengthArrayName not specified");
172 vtkErrorMacro(<<
"CurvatureArrayName not specified");
178 vtkErrorMacro(<<
"TorsionArrayName not specified");
184 vtkErrorMacro(<<
"TortuosityArrayName not specified");
188 vtkDoubleArray* lengthArray = vtkDoubleArray::New();
191 vtkDoubleArray* curvatureArray = vtkDoubleArray::New();
194 vtkDoubleArray* torsionArray = vtkDoubleArray::New();
197 vtkDoubleArray* tortuosityArray = vtkDoubleArray::New();
200 vtkDoubleArray* branchGroupIdsArray = vtkDoubleArray::New();
203 output->GetPointData()->AddArray(lengthArray);
204 output->GetPointData()->AddArray(curvatureArray);
205 output->GetPointData()->AddArray(torsionArray);
206 output->GetPointData()->AddArray(tortuosityArray);
207 output->GetPointData()->AddArray(branchGroupIdsArray);
209 vtkPoints* outputPoints = vtkPoints::New();
210 vtkCellArray* outputVerts = vtkCellArray::New();
212 output->SetPoints(outputPoints);
213 output->SetVerts(outputVerts);
215 vtkIdList* nonBlankedGroupIds = vtkIdList::New();
217 for (
int i=0; i<nonBlankedGroupIds->GetNumberOfIds(); i++)
219 vtkIdType groupId = nonBlankedGroupIds->GetId(i);
226 branchGroupIdsArray->InsertNextTuple1(groupId);
227 lengthArray->InsertNextTuple1(groupLength);
228 curvatureArray->InsertNextTuple1(groupCurvature);
229 torsionArray->InsertNextTuple1(groupTorsion);
230 tortuosityArray->InsertNextTuple1(groupTortuosity);
233 zeroPoint[0] = zeroPoint[1] = zeroPoint[2] = 0.0;
234 vtkIdType pointId = outputPoints->InsertNextPoint(zeroPoint);
235 outputVerts->InsertNextCell(1);
236 outputVerts->InsertCellPoint(pointId);
238 nonBlankedGroupIds->Delete();
240 outputPoints->Delete();
241 outputVerts->Delete();
243 lengthArray->Delete();
244 curvatureArray->Delete();
245 torsionArray->Delete();
246 tortuosityArray->Delete();
247 branchGroupIdsArray->Delete();
254 double groupLength = 0.0;
256 vtkDataArray* groupIdsArray = input->GetCellData()->GetArray(this->
GroupIdsArrayName);
258 int numberOfCells = input->GetNumberOfCells();
260 double lengthWeightSum = 0.0;
262 for (
int i=0; i<numberOfCells; i++)
264 int groupId =
static_cast<int>(groupIdsArray->GetComponent(i,0));
266 if (groupId != branchGroupId)
271 int numberOfCellPoints = input->GetCell(i)->GetNumberOfPoints();
275 double point0[3], point1[3];
276 for (
int j=0; j<numberOfCellPoints-1; j++)
278 input->GetCell(i)->GetPoints()->GetPoint(j,point0);
279 input->GetCell(i)->GetPoints()->GetPoint(j+1,point1);
281 length += sqrt(vtkMath::Distance2BetweenPoints(point0,point1));
284 groupLength += length;
285 lengthWeightSum += 1.0;
288 groupLength /= lengthWeightSum;
295 double groupCurvature = 0.0;
297 vtkDataArray* groupIdsArray = input->GetCellData()->GetArray(this->
GroupIdsArrayName);
299 int numberOfCells = input->GetNumberOfCells();
301 double groupCurvatureWeightSum = 0.0;
303 for (
int i=0; i<numberOfCells; i++)
305 int groupId =
static_cast<int>(groupIdsArray->GetComponent(i,0));
307 if (groupId != branchGroupId)
312 vtkPoints* linePoints = vtkPoints::New();
314 linePoints->DeepCopy(input->GetCell(i)->GetPoints());
316 int numberOfSectors = 5;
317 for (
int j=0; j<numberOfSectors; j++)
320 point[0] = cos(j*2.0*vtkMath::Pi()/numberOfSectors);
321 point[1] = sin(j*2.0*vtkMath::Pi()/numberOfSectors);
322 point[2] = j*(2.0*vtkMath::Pi()/numberOfSectors);
323 linePoints->InsertNextPoint(point);
329 vtkPoints* smoothLinePoints = vtkPoints::New();
331 linePoints->DeepCopy(smoothLinePoints);
332 smoothLinePoints->Delete();
337 vtkPoints* subsampledLinePoints = vtkPoints::New();
346 linePoints->DeepCopy(subsampledLinePoints);
347 subsampledLinePoints->Delete();
350 vtkDoubleArray* curvatureArray = vtkDoubleArray::New();
353 curvatureArray->Delete();
354 linePoints->Delete();
356 groupCurvature += curvature;
357 groupCurvatureWeightSum += 1.0;
360 groupCurvature /= groupCurvatureWeightSum;
364 return groupCurvature;
369 double groupTorsion = 0.0;
371 vtkDataArray* groupIdsArray = input->GetCellData()->GetArray(this->
GroupIdsArrayName);
373 int numberOfCells = input->GetNumberOfCells();
375 double groupTorsionWeightSum = 0.0;
377 for (
int i=0; i<numberOfCells; i++)
379 int groupId =
static_cast<int>(groupIdsArray->GetComponent(i,0));
381 if (groupId != branchGroupId)
386 vtkPoints* linePoints = vtkPoints::New();
388 linePoints->DeepCopy(input->GetCell(i)->GetPoints());
390 int numberOfSectors = 5;
391 for (
int j=0; j<numberOfSectors; j++)
394 point[0] = cos(j*2.0*vtkMath::Pi()/numberOfSectors);
395 point[1] = sin(j*2.0*vtkMath::Pi()/numberOfSectors);
396 point[2] = j*(2.0*vtkMath::Pi()/numberOfSectors);
397 linePoints->InsertNextPoint(point);
403 vtkPoints* smoothLinePoints = vtkPoints::New();
405 linePoints->DeepCopy(smoothLinePoints);
406 smoothLinePoints->Delete();
411 vtkPoints* subsampledLinePoints = vtkPoints::New();
420 linePoints->DeepCopy(subsampledLinePoints);
421 subsampledLinePoints->Delete();
424 vtkDoubleArray* torsionArray = vtkDoubleArray::New();
427 torsionArray->Delete();
429 linePoints->Delete();
431 groupTorsion += torsion;
432 groupTorsionWeightSum += 1.0;
435 groupTorsion /= groupTorsionWeightSum;
445 int numberOfPoints = linePoints->GetNumberOfPoints();
450 double spacing = 0.0;
451 linePoints->GetPoint(0,point0);
452 subsampledLinePoints->InsertNextPoint(point0);
453 for (
int j=1; j<numberOfPoints-1; j++)
455 linePoints->GetPoint(j,point1);
457 spacing += sqrt(vtkMath::Distance2BetweenPoints(point0,point1));
459 if (spacing < minSpacing)
464 subsampledLinePoints->InsertNextPoint(point1);
465 linePoints->GetPoint(j,point0);
469 linePoints->GetPoint(numberOfPoints-1,point1);
471 spacing = sqrt(vtkMath::Distance2BetweenPoints(point0,point1));
473 if (spacing<minSpacing)
475 int numberOfSubsampledPoints = subsampledLinePoints->GetNumberOfPoints();
476 subsampledLinePoints->InsertPoint(numberOfSubsampledPoints-1,point1);
480 subsampledLinePoints->InsertNextPoint(point1);
489 vtkIdType touchingSubId = 0;
490 double touchingPCoord = 0.0;
496 subsampledLinePoints->InsertNextPoint(input->GetCell(cellId)->GetPoints()->GetPoint(0));
498 while (touchingSubId != -1)
502 if (touchingSubId == -1)
507 input->GetCell(cellId)->GetPoints()->GetPoint(touchingSubId,point0);
508 input->GetCell(cellId)->GetPoints()->GetPoint(touchingSubId+1,point1);
510 point[0] = (1.0 - touchingPCoord) * point0[0] + touchingPCoord * point1[0];
511 point[1] = (1.0 - touchingPCoord) * point0[1] + touchingPCoord * point1[1];
512 point[2] = (1.0 - touchingPCoord) * point0[2] + touchingPCoord * point1[2];
514 subsampledLinePoints->InsertNextPoint(point);
516 subId = touchingSubId;
517 pcoord = touchingPCoord;
520 subsampledLinePoints->InsertNextPoint(input->GetCell(cellId)->GetPoints()->GetPoint(input->GetCell(cellId)->GetNumberOfPoints()-1));
526 double groupTortuosity = 0.0;
528 vtkDataArray* groupIdsArray = input->GetCellData()->GetArray(this->
GroupIdsArrayName);
529 vtkDataArray* radiusArray = input->GetPointData()->GetArray(this->
RadiusArrayName);
531 int numberOfCells = input->GetNumberOfCells();
533 double averageFirstPoint[3], averageLastPoint[3];
534 averageFirstPoint[0] = averageFirstPoint[1] = averageFirstPoint[2] = 0.0;
535 averageLastPoint[0] = averageLastPoint[1] = averageLastPoint[2] = 0.0;
536 double firstPointWeightSum = 0.0;
537 double lastPointWeightSum = 0.0;
539 for (
int i=0; i<numberOfCells; i++)
541 int groupId =
static_cast<int>(groupIdsArray->GetComponent(i,0));
543 if (groupId != branchGroupId)
548 int numberOfCellPoints = input->GetCell(i)->GetNumberOfPoints();
550 double firstPoint[3], lastPoint[3];
552 input->GetCell(i)->GetPoints()->GetPoint(0,firstPoint);
553 input->GetCell(i)->GetPoints()->GetPoint(numberOfCellPoints-1,lastPoint);
555 double firstPointRadius = radiusArray->GetComponent(input->GetCell(i)->GetPointId(0),0);
556 double lastPointRadius = radiusArray->GetComponent(input->GetCell(i)->GetPointId(numberOfCellPoints-1),0);
558 averageFirstPoint[0] += firstPointRadius * firstPointRadius * firstPoint[0];
559 averageFirstPoint[1] += firstPointRadius * firstPointRadius * firstPoint[1];
560 averageFirstPoint[2] += firstPointRadius * firstPointRadius * firstPoint[2];
562 firstPointWeightSum += firstPointRadius * firstPointRadius;
564 averageLastPoint[0] += lastPointRadius * lastPointRadius * lastPoint[0];
565 averageLastPoint[1] += lastPointRadius * lastPointRadius * lastPoint[1];
566 averageLastPoint[2] += lastPointRadius * lastPointRadius * lastPoint[2];
568 lastPointWeightSum += lastPointRadius * lastPointRadius;
571 averageFirstPoint[0] /= firstPointWeightSum;
572 averageFirstPoint[1] /= firstPointWeightSum;
573 averageFirstPoint[2] /= firstPointWeightSum;
575 averageLastPoint[0] /= lastPointWeightSum;
576 averageLastPoint[1] /= lastPointWeightSum;
577 averageLastPoint[2] /= lastPointWeightSum;
579 groupTortuosity = groupLength / sqrt(vtkMath::Distance2BetweenPoints(averageFirstPoint,averageLastPoint)) - 1.0;
581 return groupTortuosity;