VMTK
Loading...
Searching...
No Matches
vtkvmtkPolyDataMeanCurvature.cxx
Go to the documentation of this file.
1/*=========================================================================
2
3 Program: VMTK
4 Module: $RCSfile: vtkvmtkPolyDataMeanCurvature.cxx,v $
5 Language: C++
6 Date: $Date: 2006/04/06 16:46:44 $
7 Version: $Revision: 1.5 $
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 "vtkvmtkStencils.h"
24#include "vtkvmtkStencil.h"
25#include "vtkDoubleArray.h"
26#include "vtkPointData.h"
27#include "vtkCellData.h"
28#include "vtkvmtkMath.h"
29#include "vtkvmtkConstants.h"
30#include "vtkMath.h"
31#include "vtkInformation.h"
32#include "vtkInformationVector.h"
33#include "vtkObjectFactory.h"
34
35
37
47
52
54{
55 if (this->Stencils)
56 {
57 this->Stencils->UnRegister(this);
58 this->Stencils = NULL;
59 }
60}
61
62void vtkvmtkPolyDataMeanCurvature::ComputePointMeanCurvatureVector(vtkPolyData* input, vtkIdType pointId, double* meanCurvatureVector)
63{
64 double point[3], stencilPoint[3];
65 vtkIdType j;
66 vtkvmtkStencil* stencil;
67
68 meanCurvatureVector[0] = 0.0;
69 meanCurvatureVector[1] = 0.0;
70 meanCurvatureVector[2] = 0.0;
71
72 input->GetPoint(pointId,point);
73
74 stencil = this->Stencils->GetStencil(pointId);
75
76 for (j=0; j<stencil->GetNumberOfPoints(); j++)
77 {
78 input->GetPoint(stencil->GetPointId(j),stencilPoint);
79
80 meanCurvatureVector[0] += stencil->GetWeight(j) * stencilPoint[0];
81 meanCurvatureVector[1] += stencil->GetWeight(j) * stencilPoint[1];
82 meanCurvatureVector[2] += stencil->GetWeight(j) * stencilPoint[2];
83 }
84
85 meanCurvatureVector[0] += stencil->GetCenterWeight() * point[0];
86 meanCurvatureVector[1] += stencil->GetCenterWeight() * point[1];
87 meanCurvatureVector[2] += stencil->GetCenterWeight() * point[2];
88
89 meanCurvatureVector[0] *= 0.5;
90 meanCurvatureVector[1] *= 0.5;
91 meanCurvatureVector[2] *= 0.5;
92
93}
94
96 vtkInformation *vtkNotUsed(request),
97 vtkInformationVector **inputVector,
98 vtkInformationVector *outputVector)
99{
100 vtkInformation *inInfo = inputVector[0]->GetInformationObject(0);
101 vtkInformation *outInfo = outputVector->GetInformationObject(0);
102
103 vtkPolyData *input = vtkPolyData::SafeDownCast(
104 inInfo->Get(vtkDataObject::DATA_OBJECT()));
105 vtkPolyData *output = vtkPolyData::SafeDownCast(
106 outInfo->Get(vtkDataObject::DATA_OBJECT()));
107
108 vtkIdType pointId, numberOfPoints;
109 double meanCurvatureVector[3], meanCurvature;
110 vtkDoubleArray* meanCurvatureScalarsArray = NULL;
111 vtkDoubleArray* meanCurvatureNormalsArray = NULL;
112
114 {
115 vtkErrorMacro(<< "No mean curvature scalars array name specified!");
116 return 1;
117 }
118
120 {
121 vtkErrorMacro(<< "No mean curvature vectors array name specified!");
122 return 1;
123 }
124
126 this->Stencils->SetItemType(this->StencilType);
127 this->Stencils->SetDataSet(input);
128 this->Stencils->Build();
129
131 {
132 meanCurvatureScalarsArray = vtkDoubleArray::New();
133 meanCurvatureScalarsArray->SetName(this->MeanCurvatureScalarsArrayName);
134 meanCurvatureScalarsArray->SetNumberOfTuples(input->GetNumberOfPoints());
135 meanCurvatureScalarsArray->FillComponent(0,0.0);
136 meanCurvatureScalarsArray->Register(this);
137 meanCurvatureScalarsArray->Delete();
138 }
139
141 {
142 meanCurvatureNormalsArray = vtkDoubleArray::New();
143 meanCurvatureNormalsArray->SetName(this->MeanCurvatureNormalsArrayName);
144 meanCurvatureNormalsArray->SetNumberOfComponents(3);
145 meanCurvatureNormalsArray->SetNumberOfTuples(input->GetNumberOfPoints());
146 meanCurvatureNormalsArray->FillComponent(0,0.0);
147 meanCurvatureNormalsArray->FillComponent(1,0.0);
148 meanCurvatureNormalsArray->FillComponent(2,0.0);
149 meanCurvatureNormalsArray->Register(this);
150 meanCurvatureNormalsArray->Delete();
151 }
152
153 numberOfPoints = input->GetNumberOfPoints();
154
155 for (pointId=0; pointId<numberOfPoints; pointId++)
156 {
157 this->ComputePointMeanCurvatureVector(input,pointId,meanCurvatureVector);
158
160 {
161 meanCurvature = vtkMath::Norm(meanCurvatureVector);
162 meanCurvatureScalarsArray->SetComponent(pointId,0,meanCurvature);
163 }
164
166 {
167 vtkMath::Normalize(meanCurvatureVector);
168 meanCurvatureNormalsArray->SetTuple(pointId,meanCurvatureVector);
169 }
170 }
171
172 output->CopyStructure(input);
173 output->GetPointData()->PassData(input->GetPointData());
174 output->GetCellData()->PassData(input->GetCellData());
175
177 {
178 output->GetPointData()->AddArray(meanCurvatureScalarsArray);
179 output->GetPointData()->SetActiveScalars(this->MeanCurvatureScalarsArrayName);
180 }
181
183 {
184 output->GetPointData()->AddArray(meanCurvatureNormalsArray);
185 output->GetPointData()->SetActiveNormals(this->MeanCurvatureNormalsArrayName);
186 }
187
188 return 1;
189}
190
191void vtkvmtkPolyDataMeanCurvature::PrintSelf(std::ostream& os, vtkIndent indent)
192{
193 this->Superclass::PrintSelf(os,indent);
194}
195
vtkIdType GetPointId(vtkIdType i)
Compute the mean curvature and mean curvature normals of surface point neighborhoods with a particula...
virtual int RequestData(vtkInformation *, vtkInformationVector **, vtkInformationVector *) override
void PrintSelf(std::ostream &os, vtkIndent indent) override
void ComputePointMeanCurvatureVector(vtkPolyData *input, vtkIdType pointId, double *meanCurvatureVector)
Serves as an abstract base for a weighting scheme applied to a single point's neighborhood of a data ...
double GetCenterWeight()
double GetWeight(vtkIdType i)
static vtkvmtkStencils * New()
@ VTK_VMTK_FE_LAPLACE_BELTRAMI_STENCIL
vtkStandardNewMacro(vtkvmtkPolyDataMeanCurvature)