102 vtkInformation *vtkNotUsed(request),
103 vtkInformationVector **inputVector,
104 vtkInformationVector *outputVector)
107 vtkInformation *inInfo = inputVector[0]->GetInformationObject(0);
108 vtkInformation *outInfo = outputVector->GetInformationObject(0);
111 vtkPolyData *input = vtkPolyData::SafeDownCast(
112 inInfo->Get(vtkDataObject::DATA_OBJECT()));
113 vtkPolyData *output = vtkPolyData::SafeDownCast(
114 outInfo->Get(vtkDataObject::DATA_OBJECT()));
118 vtkErrorMacro(<<
"LengthArrayName not specified");
124 vtkErrorMacro(<<
"CurvatureArrayName not specified");
130 vtkErrorMacro(<<
"TorsionArrayName not specified");
136 vtkErrorMacro(<<
"TorsionArrayName not specified");
142 vtkErrorMacro(<<
"FrenetTangentArrayName not specified");
148 vtkErrorMacro(<<
"FrenetNormalArrayName not specified");
154 vtkErrorMacro(<<
"FrenetBinormalArrayName not specified");
158 output->DeepCopy(input);
160 int numberOfInputPoints = input->GetNumberOfPoints();
161 int numberOfInputCells = input->GetNumberOfCells();
163 vtkDoubleArray* lengthArray = vtkDoubleArray::New();
165 lengthArray->SetNumberOfComponents(1);
166 lengthArray->SetNumberOfTuples(numberOfInputCells);
167 lengthArray->FillComponent(0,0.0);
169 output->GetCellData()->AddArray(lengthArray);
171 vtkDoubleArray* curvatureArray = vtkDoubleArray::New();
173 curvatureArray->SetNumberOfComponents(1);
174 curvatureArray->SetNumberOfTuples(numberOfInputPoints);
175 curvatureArray->FillComponent(0,0.0);
177 output->GetPointData()->AddArray(curvatureArray);
179 vtkDoubleArray* torsionArray = vtkDoubleArray::New();
181 torsionArray->SetNumberOfComponents(1);
182 torsionArray->SetNumberOfTuples(numberOfInputPoints);
183 torsionArray->FillComponent(0,0.0);
185 output->GetPointData()->AddArray(torsionArray);
187 vtkDoubleArray* tortuosityArray = vtkDoubleArray::New();
189 tortuosityArray->SetNumberOfComponents(1);
190 tortuosityArray->SetNumberOfTuples(numberOfInputCells);
191 tortuosityArray->FillComponent(0,0.0);
193 output->GetCellData()->AddArray(tortuosityArray);
195 vtkDoubleArray* frenetTangentArray = vtkDoubleArray::New();
197 frenetTangentArray->SetNumberOfComponents(3);
198 frenetTangentArray->SetNumberOfTuples(numberOfInputPoints);
199 frenetTangentArray->FillComponent(0,0.0);
200 frenetTangentArray->FillComponent(1,0.0);
201 frenetTangentArray->FillComponent(2,0.0);
203 output->GetPointData()->AddArray(frenetTangentArray);
205 vtkDoubleArray* frenetNormalArray = vtkDoubleArray::New();
207 frenetNormalArray->SetNumberOfComponents(3);
208 frenetNormalArray->SetNumberOfTuples(numberOfInputPoints);
209 frenetNormalArray->FillComponent(0,0.0);
210 frenetNormalArray->FillComponent(1,0.0);
211 frenetNormalArray->FillComponent(2,0.0);
213 output->GetPointData()->AddArray(frenetNormalArray);
215 vtkDoubleArray* frenetBinormalArray = vtkDoubleArray::New();
217 frenetBinormalArray->SetNumberOfComponents(3);
218 frenetBinormalArray->SetNumberOfTuples(numberOfInputPoints);
219 frenetBinormalArray->FillComponent(0,0.0);
220 frenetBinormalArray->FillComponent(1,0.0);
221 frenetBinormalArray->FillComponent(2,0.0);
223 output->GetPointData()->AddArray(frenetBinormalArray);
225 for (
int i=0; i<input->GetNumberOfCells(); i++)
227 vtkCell* line = input->GetCell(i);
228 if (line->GetCellType() != VTK_LINE && line->GetCellType() != VTK_POLY_LINE)
233 vtkDoubleArray* lineCurvatureArray = vtkDoubleArray::New();
234 vtkDoubleArray* lineTorsionArray = vtkDoubleArray::New();
235 vtkDoubleArray* lineTangentArray = vtkDoubleArray::New();
236 vtkDoubleArray* lineNormalArray = vtkDoubleArray::New();
237 vtkDoubleArray* lineBinormalArray = vtkDoubleArray::New();
239 vtkPoints* linePoints = vtkPoints::New();
240 linePoints->DeepCopy(line->GetPoints());
244 vtkPoints* smoothLinePoints = vtkPoints::New();
246 linePoints->DeepCopy(smoothLinePoints);
247 smoothLinePoints->Delete();
254 int numberOfLinePoints = linePoints->GetNumberOfPoints();
257 double point0[3], point1[3];
258 for (
int j=0; j<numberOfLinePoints; j++)
260 vtkIdType pointId = line->GetPointId(j);
263 output->GetPoints()->SetPoint(pointId,linePoints->GetPoint(j));
267 linePoints->GetPoint(j-1,point0);
268 linePoints->GetPoint(j,point1);
269 length += sqrt(vtkMath::Distance2BetweenPoints(point0,point1));
271 curvatureArray->SetComponent(pointId,0,lineCurvatureArray->GetComponent(j,0));
272 torsionArray->SetComponent(pointId,0,lineTorsionArray->GetComponent(j,0));
274 lineTangentArray->GetTuple(j,tuple);
275 frenetTangentArray->SetTuple(pointId,tuple);
276 lineNormalArray->GetTuple(j,tuple);
277 frenetNormalArray->SetTuple(pointId,tuple);
278 lineBinormalArray->GetTuple(j,tuple);
279 frenetBinormalArray->SetTuple(pointId,tuple);
282 linePoints->GetPoint(0,point0);
283 linePoints->GetPoint(numberOfLinePoints-1,point1);
284 double tortuosity = length / sqrt(vtkMath::Distance2BetweenPoints(point0,point1)) - 1.0;
286 lengthArray->SetComponent(i,0,length);
287 tortuosityArray->SetComponent(i,0,tortuosity);
289 lineCurvatureArray->Delete();
290 lineTorsionArray->Delete();
291 linePoints->Delete();
292 lineTangentArray->Delete();
293 lineNormalArray->Delete();
294 lineBinormalArray->Delete();
297 lengthArray->Delete();
298 curvatureArray->Delete();
299 torsionArray->Delete();
300 tortuosityArray->Delete();
301 frenetTangentArray->Delete();
302 frenetNormalArray->Delete();
303 frenetBinormalArray->Delete();
310 int numberOfPoints = linePoints->GetNumberOfPoints();
312 lineTangentArray->SetNumberOfComponents(3);
313 lineTangentArray->SetNumberOfTuples(numberOfPoints);
314 lineTangentArray->FillComponent(0,0.0);
315 lineTangentArray->FillComponent(1,0.0);
316 lineTangentArray->FillComponent(2,0.0);
318 lineNormalArray->SetNumberOfComponents(3);
319 lineNormalArray->SetNumberOfTuples(numberOfPoints);
320 lineNormalArray->FillComponent(0,0.0);
321 lineNormalArray->FillComponent(1,0.0);
322 lineNormalArray->FillComponent(2,0.0);
324 lineBinormalArray->SetNumberOfComponents(3);
325 lineBinormalArray->SetNumberOfTuples(numberOfPoints);
326 lineBinormalArray->FillComponent(0,0.0);
327 lineBinormalArray->FillComponent(1,0.0);
328 lineBinormalArray->FillComponent(2,0.0);
330 double point0[3], point1[3], point2[3];
331 double vector0[3], vector1[3];
333 for (
int j=1; j<numberOfPoints-1; j++)
335 linePoints->GetPoint(j-1,point0);
336 linePoints->GetPoint(j,point1);
337 linePoints->GetPoint(j+1,point2);
339 vector0[0] = point1[0] - point0[0];
340 vector0[1] = point1[1] - point0[1];
341 vector0[2] = point1[2] - point0[2];
343 vector1[0] = point2[0] - point1[0];
344 vector1[1] = point2[1] - point1[1];
345 vector1[2] = point2[2] - point1[2];
347 double norm0 = vtkMath::Norm(vector0);
348 double norm1 = vtkMath::Norm(vector1);
356 xp[0] = point2[0] - point0[0];
357 xp[1] = point2[1] - point0[1];
358 xp[2] = point2[2] - point0[2];
359 xp[0] /= norm0 + norm1;
360 xp[1] /= norm0 + norm1;
361 xp[2] /= norm0 + norm1;
364 xpp[0] = (point2[0] - point1[0]) / norm1 - (point1[0] - point0[0]) / norm0;
365 xpp[1] = (point2[1] - point1[1]) / norm1 - (point1[1] - point0[1]) / norm0;
366 xpp[2] = (point2[2] - point1[2]) / norm1 - (point1[2] - point0[2]) / norm0;
367 xpp[0] /= (norm0 + norm1) / 2.0;
368 xpp[1] /= (norm0 + norm1) / 2.0;
369 xpp[2] /= (norm0 + norm1) / 2.0;
371 double xpxppcross[3];
372 vtkMath::Cross(xp,xpp,xpxppcross);
374 double tangent[3], normal[3], binormal[3];
379 vtkMath::Normalize(tangent);
381 binormal[0] = xpxppcross[0];
382 binormal[1] = xpxppcross[1];
383 binormal[2] = xpxppcross[2];
384 vtkMath::Normalize(binormal);
386 vtkMath::Cross(binormal,tangent,normal);
387 vtkMath::Normalize(normal);
389 lineTangentArray->SetTuple(j,tangent);
390 lineNormalArray->SetTuple(j,normal);
391 lineBinormalArray->SetTuple(j,binormal);
395 lineTangentArray->GetTuple(1,tuple);
396 lineTangentArray->SetTuple(0,tuple);
397 lineNormalArray->GetTuple(1,tuple);
398 lineNormalArray->SetTuple(0,tuple);
399 lineBinormalArray->GetTuple(1,tuple);
400 lineBinormalArray->SetTuple(0,tuple);
401 lineTangentArray->GetTuple(numberOfPoints-2,tuple);
402 lineTangentArray->SetTuple(numberOfPoints-1,tuple);
403 lineNormalArray->GetTuple(numberOfPoints-2,tuple);
404 lineNormalArray->SetTuple(numberOfPoints-1,tuple);
405 lineBinormalArray->GetTuple(numberOfPoints-2,tuple);
406 lineBinormalArray->SetTuple(numberOfPoints-1,tuple);
411 int numberOfPoints = linePoints->GetNumberOfPoints();
413 curvatureArray->SetNumberOfComponents(1);
414 curvatureArray->SetNumberOfTuples(numberOfPoints);
415 curvatureArray->FillComponent(0,0.0);
417 double point0[3], point1[3], point2[3];
418 double vector0[3], vector1[3];
420 double averageCurvature = 0.0;
421 double weightSum = 0.0;
423 for (
int j=1; j<numberOfPoints-1; j++)
425 linePoints->GetPoint(j-1,point0);
426 linePoints->GetPoint(j,point1);
427 linePoints->GetPoint(j+1,point2);
429 vector0[0] = point1[0] - point0[0];
430 vector0[1] = point1[1] - point0[1];
431 vector0[2] = point1[2] - point0[2];
433 vector1[0] = point2[0] - point1[0];
434 vector1[1] = point2[1] - point1[1];
435 vector1[2] = point2[2] - point1[2];
437 double norm0 = vtkMath::Norm(vector0);
438 double norm1 = vtkMath::Norm(vector1);
446 xp[0] = point2[0] - point0[0];
447 xp[1] = point2[1] - point0[1];
448 xp[2] = point2[2] - point0[2];
449 xp[0] /= norm0 + norm1;
450 xp[1] /= norm0 + norm1;
451 xp[2] /= norm0 + norm1;
454 xpp[0] = (point2[0] - point1[0]) / norm1 - (point1[0] - point0[0]) / norm0;
455 xpp[1] = (point2[1] - point1[1]) / norm1 - (point1[1] - point0[1]) / norm0;
456 xpp[2] = (point2[2] - point1[2]) / norm1 - (point1[2] - point0[2]) / norm0;
457 xpp[0] /= (norm0 + norm1) / 2.0;
458 xpp[1] /= (norm0 + norm1) / 2.0;
459 xpp[2] /= (norm0 + norm1) / 2.0;
461 double xpxppcross[3];
462 vtkMath::Cross(xp,xpp,xpxppcross);
464 double curvature = vtkMath::Norm(xpxppcross) / pow(vtkMath::Norm(xp),3.0);
465 curvatureArray->SetComponent(j,0,curvature);
466 double weight = (norm0 + norm1) / 2.0;
467 averageCurvature += curvature * weight;
474 averageCurvature /= weightSum;
477 return averageCurvature;
482 int numberOfPoints = linePoints->GetNumberOfPoints();
484 torsionArray->SetNumberOfComponents(1);
485 torsionArray->SetNumberOfTuples(numberOfPoints);
486 torsionArray->FillComponent(0,0.0);
488 double point0[3], point1[3], point2[3];
489 double vector0[3], vector1[3];
491 double averageTorsion = 0.0;
492 double weightSum = 0.0;
494 double* xps =
new double[3*numberOfPoints];
495 double* xpps =
new double[3*numberOfPoints];
498 for (j=0; j<numberOfPoints; j++)
500 xps[3*j+0] = xps[3*j+1] = xps[3*j+2] = 0.0;
501 xpps[3*j+0] = xpps[3*j+1] = xpps[3*j+2] = 0.0;
504 for (j=1; j<numberOfPoints-1; j++)
506 linePoints->GetPoint(j-1,point0);
507 linePoints->GetPoint(j,point1);
508 linePoints->GetPoint(j+1,point2);
510 vector0[0] = point1[0] - point0[0];
511 vector0[1] = point1[1] - point0[1];
512 vector0[2] = point1[2] - point0[2];
514 vector1[0] = point2[0] - point1[0];
515 vector1[1] = point2[1] - point1[1];
516 vector1[2] = point2[2] - point1[2];
518 double norm0 = vtkMath::Norm(vector0);
519 double norm1 = vtkMath::Norm(vector1);
526 xps[3*j+0] = point2[0] - point0[0];
527 xps[3*j+1] = point2[1] - point0[1];
528 xps[3*j+2] = point2[2] - point0[2];
529 xps[3*j+0] /= norm0 + norm1;
530 xps[3*j+1] /= norm0 + norm1;
531 xps[3*j+2] /= norm0 + norm1;
533 xpps[3*j+0] = (point2[0] - point1[0]) / norm1 - (point1[0] - point0[0]) / norm0;
534 xpps[3*j+1] = (point2[1] - point1[1]) / norm1 - (point1[1] - point0[1]) / norm0;
535 xpps[3*j+2] = (point2[2] - point1[2]) / norm1 - (point1[2] - point0[2]) / norm0;
536 xpps[3*j+0] /= (norm0 + norm1) / 2.0;
537 xpps[3*j+1] /= (norm0 + norm1) / 2.0;
538 xpps[3*j+2] /= (norm0 + norm1) / 2.0;
541 for (j=2; j<numberOfPoints-2; j++)
543 linePoints->GetPoint(j-1,point0);
544 linePoints->GetPoint(j,point1);
545 linePoints->GetPoint(j+1,point2);
547 vector0[0] = point1[0] - point0[0];
548 vector0[1] = point1[1] - point0[1];
549 vector0[2] = point1[2] - point0[2];
551 vector1[0] = point2[0] - point1[0];
552 vector1[1] = point2[1] - point1[1];
553 vector1[2] = point2[2] - point1[2];
555 double norm0 = vtkMath::Norm(vector0);
556 double norm1 = vtkMath::Norm(vector1);
569 xpp[0] = xpps[3*j+0];
570 xpp[1] = xpps[3*j+1];
571 xpp[2] = xpps[3*j+2];
573 double xpxppcross[3];
574 vtkMath::Cross(xp,xpp,xpxppcross);
577 xppp[0] = xpps[3*(j+1)+0] - xpps[3*(j-1)+0];
578 xppp[1] = xpps[3*(j+1)+1] - xpps[3*(j-1)+1];
579 xppp[2] = xpps[3*(j+1)+2] - xpps[3*(j-1)+2];
581 xppp[0] /= norm0 + norm1;
582 xppp[1] /= norm0 + norm1;
583 xppp[2] /= norm0 + norm1;
585 double xpxppcrossNorm = vtkMath::Norm(xpxppcross);
586 double torsion = (xpxppcrossNorm > 0 ? vtkMath::Dot(xpxppcross, xppp) / pow(xpxppcrossNorm, 2.0) : 0);
588 torsionArray->SetComponent(j,0,torsion);
589 double weight = (norm0 + norm1) / 2.0;
590 averageTorsion += torsion * weight;
600 averageTorsion /= weightSum;
603 return averageTorsion;