forked from Kitware/VTK
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathvtkCell.cxx
251 lines (221 loc) · 6.75 KB
/
vtkCell.cxx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
/*=========================================================================
Program: Visualization Toolkit
Module: vtkCell.cxx
Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
All rights reserved.
See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notice for more information.
=========================================================================*/
#include "vtkCell.h"
#include "vtkMath.h"
#include "vtkMarchingSquaresCases.h"
#include "vtkPoints.h"
//----------------------------------------------------------------------------
// Construct cell.
vtkCell::vtkCell()
{
this->Points = vtkPoints::New();
this->Points->SetDataTypeToDouble();
this->PointIds = vtkIdList::New();
// Consistent Register/Deletes (ShallowCopy uses Register.)
this->Points->Register(this);
this->Points->Delete();
this->PointIds->Register(this);
this->PointIds->Delete();
}
//----------------------------------------------------------------------------
vtkCell::~vtkCell()
{
this->Points->UnRegister(this);
this->PointIds->UnRegister(this);
}
//----------------------------------------------------------------------------
// Instantiate cell from outside
//
void vtkCell::Initialize(int npts, vtkIdType *pts, vtkPoints *p)
{
this->PointIds->Reset();
this->Points->Reset();
for (int i=0; i<npts; i++)
{
this->PointIds->InsertId(i,pts[i]);
this->Points->InsertPoint(i,p->GetPoint(pts[i]));
}
}
//----------------------------------------------------------------------------
void vtkCell::ShallowCopy(vtkCell *c)
{
this->Points->ShallowCopy(c->Points);
if ( this->PointIds )
{
this->PointIds->UnRegister(this);
this->PointIds = c->PointIds;
this->PointIds->Register(this);
}
}
//----------------------------------------------------------------------------
void vtkCell::DeepCopy(vtkCell *c)
{
this->Points->DeepCopy(c->Points);
this->PointIds->DeepCopy(c->PointIds);
}
//----------------------------------------------------------------------------
// Compute cell bounding box (xmin,xmax,ymin,ymax,zmin,zmax). Return pointer
// to array of six double values.
double *vtkCell::GetBounds ()
{
double x[3];
int i, numPts=this->Points->GetNumberOfPoints();
if (numPts)
{
this->Points->GetPoint(0, x);
this->Bounds[0] = x[0];
this->Bounds[2] = x[1];
this->Bounds[4] = x[2];
this->Bounds[1] = x[0];
this->Bounds[3] = x[1];
this->Bounds[5] = x[2];
for (i=1; i<numPts; i++)
{
this->Points->GetPoint(i, x);
this->Bounds[0] = (x[0] < this->Bounds[0] ? x[0] : this->Bounds[0]);
this->Bounds[1] = (x[0] > this->Bounds[1] ? x[0] : this->Bounds[1]);
this->Bounds[2] = (x[1] < this->Bounds[2] ? x[1] : this->Bounds[2]);
this->Bounds[3] = (x[1] > this->Bounds[3] ? x[1] : this->Bounds[3]);
this->Bounds[4] = (x[2] < this->Bounds[4] ? x[2] : this->Bounds[4]);
this->Bounds[5] = (x[2] > this->Bounds[5] ? x[2] : this->Bounds[5]);
}
}
else
{
vtkMath::UninitializeBounds(this->Bounds);
}
return this->Bounds;
}
//----------------------------------------------------------------------------
// Compute cell bounding box (xmin,xmax,ymin,ymax,zmin,zmax). Copy result into
// user provided array.
void vtkCell::GetBounds(double bounds[6])
{
this->GetBounds();
for (int i=0; i < 6; i++)
{
bounds[i] = this->Bounds[i];
}
}
//----------------------------------------------------------------------------
// Compute Length squared of cell (i.e., bounding box diagonal squared).
double vtkCell::GetLength2 ()
{
double diff, l=0.0;
int i;
this->GetBounds();
for (i=0; i<3; i++)
{
diff = this->Bounds[2*i+1] - this->Bounds[2*i];
l += diff * diff;
}
return l;
}
//----------------------------------------------------------------------------
// Return center of the cell in parametric coordinates.
// Note that the parametric center is not always located
// at (0.5,0.5,0.5). The return value is the subId that
// the center is in (if a composite cell). If you want the
// center in x-y-z space, invoke the EvaluateLocation() method.
int vtkCell::GetParametricCenter(double pcoords[3])
{
pcoords[0] = pcoords[1] = pcoords[2] = 0.5;
return 0;
}
//----------------------------------------------------------------------------
// This method works fine for all "rectangular" cells, not triangular
// and tetrahedral topologies.
double vtkCell::GetParametricDistance(double pcoords[3])
{
int i;
double pDist, pDistMax=0.0;
for (i=0; i<3; i++)
{
if ( pcoords[i] < 0.0 )
{
pDist = -pcoords[i];
}
else if ( pcoords[i] > 1.0 )
{
pDist = pcoords[i] - 1.0;
}
else //inside the cell in the parametric direction
{
pDist = 0.0;
}
if ( pDist > pDistMax )
{
pDistMax = pDist;
}
}
return pDistMax;
}
//----------------------------------------------------------------------------
void vtkCell::PrintSelf(ostream& os, vtkIndent indent)
{
this->Superclass::PrintSelf(os,indent);
int numIds=this->PointIds->GetNumberOfIds();
os << indent << "Number Of Points: " << numIds << "\n";
if ( numIds > 0 )
{
double *bounds=this->GetBounds();
os << indent << "Bounds: \n";
os << indent << " Xmin,Xmax: (" << bounds[0] << ", " << bounds[1] << ")\n";
os << indent << " Ymin,Ymax: (" << bounds[2] << ", " << bounds[3] << ")\n";
os << indent << " Zmin,Zmax: (" << bounds[4] << ", " << bounds[5] << ")\n";
os << indent << " Point ids are: ";
for (int i=0; i < numIds; i++)
{
os << this->PointIds->GetId(i);
if ( i && !(i % 12) )
{
os << "\n\t";
}
else
{
if ( i != (numIds-1) )
{
os << ", ";
}
}
}
os << indent << "\n";
}
}
// Note: the following code is placed here to deal with cross-library
// symbol export and import on Microsoft compilers.
static vtkMarchingSquaresLineCases VTK_MARCHING_SQUARES_LINECASES[] = {
{{-1, -1, -1, -1, -1}},
{{0, 3, -1, -1, -1}},
{{1, 0, -1, -1, -1}},
{{1, 3, -1, -1, -1}},
{{2, 1, -1, -1, -1}},
{{0, 3, 2, 1, -1}},
{{2, 0, -1, -1, -1}},
{{2, 3, -1, -1, -1}},
{{3, 2, -1, -1, -1}},
{{0, 2, -1, -1, -1}},
{{1, 0, 3, 2, -1}},
{{1, 2, -1, -1, -1}},
{{3, 1, -1, -1, -1}},
{{0, 1, -1, -1, -1}},
{{3, 0, -1, -1, -1}},
{{-1, -1, -1, -1, -1}}
};
vtkMarchingSquaresLineCases* vtkMarchingSquaresLineCases::GetCases()
{
return VTK_MARCHING_SQUARES_LINECASES;
}
// Usually overridden. Only composite cells do not override this.
double *vtkCell::GetParametricCoords()
{
return NULL;
}