VMTK
Loading...
Searching...
No Matches
vtkvmtkCenterlineSmoothing.cxx
Go to the documentation of this file.
1/*=========================================================================
2
3Program: VTK Blood Vessel Smoothing
4Module: $RCSfile: vtkvmtkCenterlineSmoothing.cxx,v $
5Language: C++
6Date: $Date: 2006/07/17 09:52:56 $
7Version: $Revision: 1.1 $
8
9 Copyright (c) Luca Antiga, David Steinman. All rights reserved.
10 See LICENSE file for details.
11
12 Portions of this code are covered under the VTK copyright.
13 See VTKCopyright.txt or http://www.kitware.com/VTKCopyright.htm
14 for details.
15
16 This software is distributed WITHOUT ANY WARRANTY; without even
17 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
18 PURPOSE. See the above copyright notices for more information.
19
20=========================================================================*/
21
23#include "vtkvmtkConstants.h"
24#include "vtkPolyData.h"
25#include "vtkPointData.h"
26#include "vtkCellData.h"
27#include "vtkPolyLine.h"
28#include "vtkInformation.h"
29#include "vtkInformationVector.h"
30#include "vtkObjectFactory.h"
31
32
34
40
44
46 vtkInformation *vtkNotUsed(request),
47 vtkInformationVector **inputVector,
48 vtkInformationVector *outputVector)
49{
50 // get the info objects
51 vtkInformation *inInfo = inputVector[0]->GetInformationObject(0);
52 vtkInformation *outInfo = outputVector->GetInformationObject(0);
53
54 // get the input and output
55 vtkPolyData *input = vtkPolyData::SafeDownCast(
56 inInfo->Get(vtkDataObject::DATA_OBJECT()));
57 vtkPolyData *output = vtkPolyData::SafeDownCast(
58 outInfo->Get(vtkDataObject::DATA_OBJECT()));
59
60 output->DeepCopy(input);
61
62 for (int i=0; i<input->GetNumberOfCells(); i++)
63 {
64 vtkCell* line = input->GetCell(i);
65 if (line->GetCellType() != VTK_LINE && line->GetCellType() != VTK_POLY_LINE)
66 {
67 continue;
68 }
69
70 vtkPoints* smoothLinePoints = vtkPoints::New();
71 this->SmoothLine(line->GetPoints(),smoothLinePoints,this->NumberOfSmoothingIterations,this->SmoothingFactor);
72
73 int numberOfLinePoints = smoothLinePoints->GetNumberOfPoints();
74
75 for (int j=0; j<numberOfLinePoints; j++)
76 {
77 vtkIdType pointId = line->GetPointId(j);
78 output->GetPoints()->SetPoint(pointId,smoothLinePoints->GetPoint(j));
79 }
80
81 smoothLinePoints->Delete();
82 }
83
84 return 1;
85}
86
87void vtkvmtkCenterlineSmoothing::SmoothLine(vtkPoints* linePoints, vtkPoints* smoothLinePoints, int numberOfIterations, double relaxation)
88{
89 int numberOfPoints = linePoints->GetNumberOfPoints();
90
91 smoothLinePoints->DeepCopy(linePoints);
92
93 double point0[3];
94 double point1[3];
95 double point2[3];
96
97 for (int i=0; i<numberOfIterations; i++)
98 {
99 for (int j=1; j<numberOfPoints-1; j++)
100 {
101 smoothLinePoints->GetPoint(j-1,point0);
102 smoothLinePoints->GetPoint(j ,point1);
103 smoothLinePoints->GetPoint(j+1,point2);
104
105 point1[0] += relaxation * (0.5 * (point0[0] + point2[0]) - point1[0]);
106 point1[1] += relaxation * (0.5 * (point0[1] + point2[1]) - point1[1]);
107 point1[2] += relaxation * (0.5 * (point0[2] + point2[2]) - point1[2]);
108
109 smoothLinePoints->SetPoint(j,point1);
110 }
111 }
112}
113
114void vtkvmtkCenterlineSmoothing::PrintSelf(std::ostream& os, vtkIndent indent)
115{
116 this->Superclass::PrintSelf(os,indent);
117}
Iteratively smooth a centerline with a Laplacian kernel.
static void SmoothLine(vtkPoints *linePoints, vtkPoints *smoothLinePoints, int numberOfIterations=10, double relaxation=0.1)
virtual int RequestData(vtkInformation *, vtkInformationVector **, vtkInformationVector *) override
void PrintSelf(std::ostream &os, vtkIndent indent) override
vtkStandardNewMacro(vtkvmtkCenterlineSmoothing)