VMTK
Loading...
Searching...
No Matches
vtkvmtkNonManifoldSteepestDescent.cxx
Go to the documentation of this file.
1/*=========================================================================
2
3Program: VMTK
4Module: $RCSfile: vtkvmtkNonManifoldSteepestDescent.cxx,v $
5Language: C++
6Date: $Date: 2006/04/06 16:46:43 $
7Version: $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 "vtkPointData.h"
25#include "vtkDoubleArray.h"
26#include "vtkIdList.h"
27#include "vtkMath.h"
28#include "vtkObjectFactory.h"
29#include "vtkInformation.h"
30#include "vtkInformationVector.h"
31#include "vtkvmtkConstants.h"
32
33
35
43
47
48double vtkvmtkNonManifoldSteepestDescent::GetSteepestDescentInCell(vtkPolyData* input, vtkIdType cellId, vtkIdType* edge, double s, vtkIdType* steepestDescentEdge, double &steepestDescentS, double &steepestDescentLength)
49{
50 double currentPoint[3], currentScalar;
51 double descent, steepestDescent;
52 double descentLength;
53 double point0[3], point1[3], point[3];
54 double scalar0, scalar1, scalar;
55 double currentS;
56 double directionFactor = 0.0;
57 vtkIdType npts;
58 const vtkIdType *pts;
59 vtkIdType i, j;
60
61 if (!this->DescentArray)
62 {
63 vtkErrorMacro("DescentArray not set.");
64 }
65
67 {
68 directionFactor = 1.0;
69 }
70 else if (this->Direction==VTK_VMTK_UPWARD)
71 {
72 directionFactor = - 1.0;
73 }
74
75 double edgePoint0[3], edgePoint1[3];
76 input->GetPoint(edge[0],edgePoint0);
77 input->GetPoint(edge[1],edgePoint1);
78
79 currentPoint[0] = edgePoint0[0] * (1.0 - s) + edgePoint1[0] * s;
80 currentPoint[1] = edgePoint0[1] * (1.0 - s) + edgePoint1[1] * s;
81 currentPoint[2] = edgePoint0[2] * (1.0 - s) + edgePoint1[2] * s;
82 currentScalar = this->DescentArray->GetTuple1(edge[0]) * (1.0 - s) + this->DescentArray->GetTuple1(edge[1]) * s;
83
84 steepestDescent = - VTK_VMTK_LARGE_DOUBLE * directionFactor;
85 steepestDescentLength = VTK_VMTK_LARGE_DOUBLE;
86
87 input->GetCellPoints(cellId,npts,pts);
88
89 for (i=0; i<npts; i++)
90 {
91 input->GetPoint(pts[i],point0);
92 input->GetPoint(pts[(i+1)%npts],point1);
93 scalar0 = this->DescentArray->GetTuple1(pts[i]);
94 scalar1 = this->DescentArray->GetTuple1(pts[(i+1)%npts]);
95
96 if (edge[0]==edge[1])
97 {
98 if (pts[i]==edge[0])
99 {
100 continue;
101 }
102 }
103 else
104 {
105 if (((pts[i]==edge[0]) && (pts[(i+1)%npts]==edge[1]))||((pts[i]==edge[1]) && (pts[(i+1)%npts]==edge[0])))
106 {
107 point[0] = point0[0];
108 point[1] = point0[1];
109 point[2] = point0[2];
110 scalar = scalar0;
111 currentS = 0.0;
112 descentLength = sqrt(vtkMath::Distance2BetweenPoints(point,currentPoint));
113 if (descentLength > VTK_VMTK_DOUBLE_TOL)
114 {
115 descent = - (scalar - currentScalar) / descentLength;
116 }
117 else
118 {
119 descent = 0.0;
120 }
121 if (directionFactor*(descent - steepestDescent) > VTK_VMTK_DOUBLE_TOL)
122 {
123 steepestDescent = descent;
124 steepestDescentLength = descentLength;
125 steepestDescentEdge[0] = pts[i];
126 steepestDescentEdge[1] = pts[i];
127 steepestDescentS = currentS;
128 }
129 continue;
130 }
131 }
132
133 currentS = 0.0;
134 for (j=0; j<this->NumberOfEdgeSubdivisions; j++)
135 {
136 point[0] = point0[0] * (1.0 - currentS) + point1[0] * currentS;
137 point[1] = point0[1] * (1.0 - currentS) + point1[1] * currentS;
138 point[2] = point0[2] * (1.0 - currentS) + point1[2] * currentS;
139 scalar = scalar0 * (1.0 - currentS) + scalar1 * currentS;
140 descentLength = sqrt(vtkMath::Distance2BetweenPoints(point,currentPoint));
141 if (descentLength > VTK_VMTK_DOUBLE_TOL)
142 {
143 descent = - (scalar - currentScalar) / descentLength;
144 }
145 else
146 {
147 descent = 0.0;
148 }
149 if (directionFactor * (descent - steepestDescent) > VTK_VMTK_DOUBLE_TOL)
150 {
151 steepestDescent = descent;
152 steepestDescentLength = descentLength;
153 if (fabs(currentS)<VTK_VMTK_DOUBLE_TOL)
154 {
155 steepestDescentEdge[0] = pts[i];
156 steepestDescentEdge[1] = pts[i];
157 }
158 else
159 {
160 steepestDescentEdge[0] = pts[i];
161 steepestDescentEdge[1] = pts[(i+1)%npts];
162 }
163 steepestDescentS = currentS;
164 }
165
166 currentS += 1.0 / (double)this->NumberOfEdgeSubdivisions;
167 }
168 }
169
170 return steepestDescent;
171}
172
173double vtkvmtkNonManifoldSteepestDescent::GetSteepestDescent(vtkPolyData* input, vtkIdType* edge, double s, vtkIdType* steepestDescentEdge, double &steepestDescentS)
174{
175 double descent, steepestDescent;
176 double descentLength, steepestDescentLength;
177 vtkIdType descentEdge[2];
178 double descentS;
179 vtkIdList *neighborCells;
180 vtkIdType i, cellId;
181 double directionFactor = 0.0;
182
183 neighborCells = vtkIdList::New();
184
185 input->GetCellEdgeNeighbors(-1,edge[0],edge[1],neighborCells);
186
187 if (this->Direction==VTK_VMTK_DOWNWARD)
188 {
189 directionFactor = 1.0;
190 }
191 else if (this->Direction==VTK_VMTK_UPWARD)
192 {
193 directionFactor = - 1.0;
194 }
195
196 steepestDescent = - VTK_VMTK_LARGE_DOUBLE * directionFactor;
197 steepestDescentLength = VTK_VMTK_LARGE_DOUBLE;
198 steepestDescentEdge[0] = -1;
199 steepestDescentEdge[1] = -1;
200 for (i=0; i<neighborCells->GetNumberOfIds(); i++)
201 {
202 cellId = neighborCells->GetId(i);
203 descent = this->GetSteepestDescentInCell(input,cellId,edge,s,descentEdge,descentS,descentLength);
204 if (directionFactor*(descent - steepestDescent) > VTK_VMTK_DOUBLE_TOL)
205 {
206 steepestDescent = descent;
207 steepestDescentLength = descentLength;
208 steepestDescentEdge[0] = descentEdge[0];
209 steepestDescentEdge[1] = descentEdge[1];
210 steepestDescentS = descentS;
211 }
212 }
213
214 neighborCells->Delete();
215
216 return steepestDescent;
217}
218
220 vtkInformation *vtkNotUsed(request),
221 vtkInformationVector **inputVector,
222 vtkInformationVector *outputVector)
223{
224 vtkInformation *inInfo = inputVector[0]->GetInformationObject(0);
225// vtkInformation *outInfo = outputVector->GetInformationObject(0);
226
227 vtkPolyData *input = vtkPolyData::SafeDownCast(
228 inInfo->Get(vtkDataObject::DATA_OBJECT()));
229// vtkPolyData *output = vtkPolyData::SafeDownCast(
230// outInfo->Get(vtkDataObject::DATA_OBJECT()));
231
232 if (!this->DescentArrayName)
233 {
234 vtkErrorMacro("No descent array name specified!");
235 return 1;
236 }
237
238 if (!input->GetPointData()->GetArray(this->DescentArrayName))
239 {
240 vtkErrorMacro("Descent array with specified name does not exist!");
241 return 1;
242 }
243
244 this->DescentArray = input->GetPointData()->GetArray(this->DescentArrayName);
245
246 return 1;
247}
248
249void vtkvmtkNonManifoldSteepestDescent::PrintSelf(std::ostream& os, vtkIndent indent)
250{
251 this->Superclass::PrintSelf(os,indent);
252}
Provides an abstract base class for steepest descent on a polygonal non-manifold.
double GetSteepestDescent(vtkPolyData *input, vtkIdType *edge, double s, vtkIdType *steepestDescentEdge, double &steepestDescentS)
double GetSteepestDescentInCell(vtkPolyData *input, vtkIdType cellId, vtkIdType *edge, double s, vtkIdType *steepestDescentEdge, double &steepestDescentS, double &steepestDescentLength)
virtual int RequestData(vtkInformation *, vtkInformationVector **, vtkInformationVector *) override
void PrintSelf(std::ostream &os, vtkIndent indent) override
#define VTK_VMTK_DOUBLE_TOL
#define VTK_VMTK_LARGE_DOUBLE
vtkStandardNewMacro(vtkvmtkNonManifoldSteepestDescent)