VMTK
Loading...
Searching...
No Matches
vtkvmtkPolyDataGradientStencil.cxx
Go to the documentation of this file.
1/*=========================================================================
2
3 Program: VMTK
4 Module: $RCSfile: vtkvmtkPolyDataGradientStencil.cxx,v $
5 Language: C++
6 Date: $Date: 2006/04/06 16:46:44 $
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 "vtkPolyData.h"
24#include "vtkvmtkMath.h"
25#include "vtkMath.h"
26#include "vtkObjectFactory.h"
27
28#include "vtkvmtkConstants.h"
29
30
32
38
43
44void vtkvmtkPolyDataGradientStencil::Gamma(double p0[3], double p1[3], double p2[3], double gamma[3])
45{
46 double p01[3], p12[3], p20[3];
47 p01[0] = p0[0] - p1[0];
48 p01[1] = p0[1] - p1[1];
49 p01[2] = p0[2] - p1[2];
50 p12[0] = p1[0] - p2[0];
51 p12[1] = p1[1] - p2[1];
52 p12[2] = p1[2] - p2[2];
53 p20[0] = p2[0] - p0[0];
54 p20[1] = p2[1] - p0[1];
55 p20[2] = p2[2] - p0[2];
56
57 double dot = vtkMath::Dot(p01,p12);
58 gamma[0] = dot * p20[0];
59 gamma[1] = dot * p20[1];
60 gamma[2] = dot * p20[2];
61}
62
64{
65 double point[3], point1[3], point2[3];
66 vtkIdType j, firstId, lastId;
67
68 this->Superclass::Build();
69
70 vtkPolyData* pdata = vtkPolyData::SafeDownCast(this->DataSet);
71
72 if (!this->IsBoundary)
73 {
74 firstId = 0;
75 lastId = this->NPoints-1;
76 }
77 else
78 {
79 firstId = 0;
80 lastId = this->NPoints-2;
81 }
82
83 pdata->GetPoint(this->DataSetPointId,point);
84
85 for (j=0; j<3*this->NPoints; j++)
86 this->Weights[j] = 0.0;
87
88 this->CenterWeight[0] = 0.0;
89 this->CenterWeight[1] = 0.0;
90 this->CenterWeight[2] = 0.0;
91
92 double gamma[3];
93 for (j=firstId; j<=lastId; j++)
94 {
95 pdata->GetPoint(this->PointIds[j],point1);
96
97 int jplus = (j+1) % this->NPoints;
98 pdata->GetPoint(this->PointIds[jplus],point2);
99
100 double areaWeight = 1.0 / (4.0 * vtkvmtkMath::TriangleArea(point,point1,point2));
101
102 this->Gamma(point,point1,point2,gamma);
103 this->CenterWeight[0] += gamma[0] * areaWeight;
104 this->CenterWeight[1] += gamma[1] * areaWeight;
105 this->CenterWeight[2] += gamma[2] * areaWeight;
106
107 this->Gamma(point,point2,point1,gamma);
108 this->CenterWeight[0] += gamma[0] * areaWeight;
109 this->CenterWeight[1] += gamma[1] * areaWeight;
110 this->CenterWeight[2] += gamma[2] * areaWeight;
111
112 this->Gamma(point1,point,point2,gamma);
113 this->Weights[3*j+0] += gamma[0] * areaWeight;
114 this->Weights[3*j+1] += gamma[1] * areaWeight;
115 this->Weights[3*j+2] += gamma[2] * areaWeight;
116
117 this->Gamma(point1,point2,point,gamma);
118 this->Weights[3*j+0] += gamma[0] * areaWeight;
119 this->Weights[3*j+1] += gamma[1] * areaWeight;
120 this->Weights[3*j+2] += gamma[2] * areaWeight;
121
122 this->Gamma(point2,point1,point,gamma);
123 this->Weights[3*jplus+0] += gamma[0] * areaWeight;
124 this->Weights[3*jplus+1] += gamma[1] * areaWeight;
125 this->Weights[3*jplus+2] += gamma[2] * areaWeight;
126
127 this->Gamma(point2,point,point1,gamma);
128 this->Weights[3*jplus+0] += gamma[0] * areaWeight;
129 this->Weights[3*jplus+1] += gamma[1] * areaWeight;
130 this->Weights[3*jplus+2] += gamma[2] * areaWeight;
131 }
132
133 this->ComputeArea();
134 this->ScaleWithArea();
135}
136
static double TriangleArea(double point0[3], double point1[3], double point2[3])
Apply gradient weighting to the neighborhood connections of a surface.
void Gamma(double p0[3], double p1[3], double p2[3], double gamma[3])
vtkIdType NumberOfComponents
double * CenterWeight
vtkStandardNewMacro(vtkvmtkPolyDataGradientStencil)