VMTK
Loading...
Searching...
No Matches
vtkvmtkPolyDataLaplaceBeltramiStencil.cxx
Go to the documentation of this file.
1/*=========================================================================
2
3 Program: VMTK
4 Module: $RCSfile: vtkvmtkPolyDataLaplaceBeltramiStencil.cxx,v $
5 Language: C++
6 Date: $Date: 2005/11/15 17:39:25 $
7 Version: $Revision: 1.4 $
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 "vtkvmtkMath.h"
24#include "vtkMath.h"
25#include "vtkObjectFactory.h"
26
27#include "vtkvmtkConstants.h"
28
29
30
35
36void vtkvmtkPolyDataLaplaceBeltramiStencil::BuildBoundaryWeights(vtkIdType boundaryPointId, vtkIdType boundaryNeighborPointId, double &boundaryWeight, double &boundaryNeighborWeight)
37 {
38 double point[3], point1[3], point2[3];
39 double vector1[3], vector2[3];
40 double triangleArea;
41
42 if (!this->IsBoundary)
43 return;
44
45 this->DataSet->GetPoint(this->DataSetPointId,point);
46 this->DataSet->GetPoint(boundaryPointId,point1);
47 this->DataSet->GetPoint(boundaryNeighborPointId,point2);
48
49 vector1[0] = point1[0] - point[0];
50 vector1[1] = point1[1] - point[1];
51 vector1[2] = point1[2] - point[2];
52
53 vector2[0] = point2[0] - point[0];
54 vector2[1] = point2[1] - point[1];
55 vector2[2] = point2[2] - point[2];
56
57 triangleArea = vtkvmtkMath::TriangleArea(point,point1,point2);
58
59 boundaryWeight = vtkMath::Distance2BetweenPoints(point,point2);
60 boundaryNeighborWeight = vtkMath::Dot(vector1,vector2);
61
62 if (triangleArea<VTK_VMTK_DOUBLE_TOL)
63 {
64 if (fabs(boundaryWeight)<VTK_VMTK_DOUBLE_TOL)
65 boundaryWeight = 0.0;
66 else
67 boundaryWeight = VTK_VMTK_LARGE_DOUBLE;
68
69 if (fabs(boundaryNeighborWeight)<VTK_VMTK_DOUBLE_TOL)
70 boundaryNeighborWeight = 0.0;
71 else
72 boundaryNeighborWeight = VTK_VMTK_LARGE_DOUBLE;
73 }
74 else
75 {
76 boundaryWeight /= 4.0 * triangleArea;
77 boundaryNeighborWeight /= 4.0 * triangleArea;
78 }
79 }
80
82 {
83 double point[3], point1[3], point2[3];
84 double boundaryWeight, boundaryNeighborWeight;
85 double cotangent;
86 vtkIdType j, firstId, lastId;
87
88 this->Superclass::Build();
89
90 vtkPolyData* pdata = vtkPolyData::SafeDownCast(this->DataSet);
91
92 if (!this->IsBoundary)
93 {
94 firstId = 0;
95 lastId = this->NPoints-1;
96 }
97 else
98 {
99 firstId = 1;
100 lastId = this->NPoints-3;
101 }
102
103 pdata->GetPoint(this->DataSetPointId,point);
104
105 for (j=0; j<this->NPoints; j++)
106 this->Weights[j] = 0.0;
107
108 for (j=firstId; j<=lastId; j++)
109 {
110 pdata->GetPoint(this->PointIds[j],point1);
111
112 pdata->GetPoint(this->PointIds[(j+1)%this->NPoints],point2);
113
114 cotangent = vtkvmtkMath::Cotangent(point,point2,point1);
115 this->Weights[j] += cotangent / 2.0;
116
117 cotangent = vtkvmtkMath::Cotangent(point,point1,point2);
118 this->Weights[(j+1)%this->NPoints] += cotangent / 2.0;
119 }
120
121 if (this->IsBoundary)
122 {
123 this->BuildBoundaryWeights(this->PointIds[0],this->PointIds[1],boundaryWeight,boundaryNeighborWeight);
124 this->Weights[0] += boundaryWeight;
125 this->Weights[1] += boundaryNeighborWeight;
126
127 this->BuildBoundaryWeights(this->PointIds[this->NPoints-1],this->PointIds[this->NPoints-2],boundaryWeight,boundaryNeighborWeight);
128 this->Weights[this->NPoints-1] += boundaryWeight;
129 this->Weights[this->NPoints-2] += boundaryNeighborWeight;
130 }
131
132 this->CenterWeight[0] = 0.0;
133 for (j=0; j<this->NPoints; j++)
134 {
135 this->CenterWeight[0] += this->Weights[j];
136 }
137
138 this->ComputeArea();
139 this->ScaleWithArea();
140 this->ChangeWeightSign();
141 }
142
static double Cotangent(double point0[3], double point1[3], double point2[3])
static double TriangleArea(double point0[3], double point1[3], double point2[3])
void BuildBoundaryWeights(vtkIdType boundaryPointId, vtkIdType boundaryNeighborPointId, double &boundaryWeight, double &boundaryNeighborWeight)
virtual void ScaleWithArea()=0
vtkIdType NumberOfComponents
double * CenterWeight
#define VTK_VMTK_DOUBLE_TOL
#define VTK_VMTK_LARGE_DOUBLE