forked from Kitware/VTK
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathvtkGenericDataSet.cxx
219 lines (187 loc) · 6.66 KB
/
vtkGenericDataSet.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
/*=========================================================================
Program: Visualization Toolkit
Module: vtkGenericDataSet.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 "vtkGenericDataSet.h"
#include "vtkCellTypes.h"
#include "vtkGenericAdaptorCell.h"
#include "vtkGenericAttributeCollection.h"
#include "vtkGenericCellIterator.h"
#include "vtkGenericCellTessellator.h"
#include "vtkInformation.h"
#include "vtkInformationVector.h"
#include "vtkMath.h"
#include <assert.h>
vtkCxxSetObjectMacro(vtkGenericDataSet,Tessellator,vtkGenericCellTessellator);
//----------------------------------------------------------------------------
vtkGenericDataSet::vtkGenericDataSet()
{
this->Tessellator = 0;
this->Attributes = vtkGenericAttributeCollection::New();
vtkMath::UninitializeBounds(this->Bounds);
}
//----------------------------------------------------------------------------
vtkGenericDataSet::~vtkGenericDataSet()
{
if(this->Tessellator!=0)
{
this->Tessellator->Delete();
}
this->Attributes->Delete();
}
//----------------------------------------------------------------------------
void vtkGenericDataSet::PrintSelf(ostream& os, vtkIndent indent)
{
this->Superclass::PrintSelf(os,indent);
os << indent << "Number Of Points: " << this->GetNumberOfPoints() << "\n";
os << indent << "Number Of Cells: " << this->GetNumberOfCells() << "\n";
os << indent << "Attributes:\n";
this->GetAttributes()->PrintSelf(os,indent.GetNextIndent());
this->ComputeBounds();
os << indent << "Bounds: \n";
os << indent << " Xmin,Xmax: (" <<this->Bounds[0] << ", " << this->Bounds[1] << ")\n";
os << indent << " Ymin,Ymax: (" <<this->Bounds[2] << ", " << this->Bounds[3] << ")\n";
os << indent << " Zmin,Zmax: (" <<this->Bounds[4] << ", " << this->Bounds[5] << ")\n";
os << indent << "Tessellator:" << this->Tessellator << endl;
}
//----------------------------------------------------------------------------
// Description:
// Get a list of types of cells in a dataset. The list consists of an array
// of types (not necessarily in any order), with a single entry per type.
// For example a dataset 5 triangles, 3 lines, and 100 hexahedra would
// result a list of three entries, corresponding to the types VTK_TRIANGLE,
// VTK_LINE, and VTK_HEXAHEDRON.
// THIS METHOD IS THREAD SAFE IF FIRST CALLED FROM A SINGLE THREAD AND
// THE DATASET IS NOT MODIFIED
// \pre types_exist: types!=0
void vtkGenericDataSet::GetCellTypes(vtkCellTypes *types)
{
assert("pre: types_exist" && types!=0);
unsigned char type;
vtkGenericCellIterator *it = this->NewCellIterator(-1);
vtkGenericAdaptorCell *c = it->NewCell();
types->Reset();
it->Begin();
while(!it->IsAtEnd())
{
it->GetCell(c);
type=c->GetType();
if ( ! types->IsType(type) )
{
types->InsertNextType(type);
}
it->Next();
}
c->Delete();
it->Delete();
}
//----------------------------------------------------------------------------
// Return a pointer to the geometry bounding box in the form
// (xmin,xmax, ymin,ymax, zmin,zmax).
// The return value is VOLATILE.
// \post result_exists: result!=0
double *vtkGenericDataSet::GetBounds()
{
this->ComputeBounds();
return this->Bounds;
}
//----------------------------------------------------------------------------
// Description:
// Return the geometry bounding box in global coordinates in
// the form (xmin,xmax, ymin,ymax, zmin,zmax) into `bounds'.
void vtkGenericDataSet::GetBounds(double bounds[6])
{
this->ComputeBounds();
memcpy(bounds,this->Bounds,sizeof(double)*6);
}
//----------------------------------------------------------------------------
// Description:
// Get the center of the bounding box in global coordinates.
// The return value is VOLATILE.
// - \post result_exists: result!=0
double *vtkGenericDataSet::GetCenter()
{
this->ComputeBounds();
for (int i=0; i<3; i++)
{
this->Center[i] = (this->Bounds[2*i+1] + this->Bounds[2*i]) * 0.5;
}
return this->Center;
}
//----------------------------------------------------------------------------
// Description:
// Get the center of the bounding box in global coordinates.
void vtkGenericDataSet::GetCenter(double center[3])
{
this->ComputeBounds();
for (int i=0; i<3; i++)
{
center[i] = (this->Bounds[2*i+1] + this->Bounds[2*i]) * 0.5;
}
}
//----------------------------------------------------------------------------
// Description:
// Length of the diagonal of the bounding box.
double vtkGenericDataSet::GetLength()
{
double result, l=0.0;
int i;
this->ComputeBounds();
for (i=0; i<3; i++)
{
result = this->Bounds[2*i+1] - this->Bounds[2*i];
l += result * result;
}
result = sqrt(l);
assert("post: positive_result" && result>=0);
return result;
}
//----------------------------------------------------------------------------
unsigned long int vtkGenericDataSet::GetMTime()
{
unsigned long result;
unsigned long mtime;
result = this->Superclass::GetMTime();
mtime = this->Attributes->GetMTime();
result = ( mtime > result ? mtime : result );
if(this->Tessellator)
{
mtime = this->Tessellator->GetMTime();
result = ( mtime > result ? mtime : result );
}
return result;
}
//----------------------------------------------------------------------------
// Description:
// Actual size of the data in kilobytes; only valid after the pipeline has
// updated. It is guaranteed to be greater than or equal to the memory
// required to represent the data.
unsigned long vtkGenericDataSet::GetActualMemorySize()
{
unsigned long result = this->Superclass::GetActualMemorySize();
result += this->Attributes->GetActualMemorySize();
return result;
}
//----------------------------------------------------------------------------
// Description:
// Return the type of data object.
int vtkGenericDataSet::GetDataObjectType()
{
return VTK_GENERIC_DATA_SET;
}
//----------------------------------------------------------------------------
vtkGenericDataSet* vtkGenericDataSet::GetData(vtkInformation* info)
{
return info ? vtkGenericDataSet::SafeDownCast(info->Get(DATA_OBJECT())) : 0;
}
//----------------------------------------------------------------------------
vtkGenericDataSet* vtkGenericDataSet::GetData(vtkInformationVector* v, int i)
{
return vtkGenericDataSet::GetData(v->GetInformationObject(i));
}