forked from Kitware/VTK
-
Notifications
You must be signed in to change notification settings - Fork 0
/
vtkPoints.cxx
225 lines (196 loc) · 5.68 KB
/
vtkPoints.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
/*=========================================================================
Program: Visualization Toolkit
Module: vtkPoints.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 "vtkPoints.h"
#include "vtkBitArray.h"
#include "vtkCharArray.h"
#include "vtkDoubleArray.h"
#include "vtkFloatArray.h"
#include "vtkIdList.h"
#include "vtkIdTypeArray.h"
#include "vtkIntArray.h"
#include "vtkLongArray.h"
#include "vtkObjectFactory.h"
#include "vtkShortArray.h"
#include "vtkUnsignedCharArray.h"
#include "vtkUnsignedIntArray.h"
#include "vtkUnsignedLongArray.h"
#include "vtkUnsignedShortArray.h"
//----------------------------------------------------------------------------
vtkPoints* vtkPoints::New(int dataType)
{
// First try to create the object from the vtkObjectFactory
vtkObject* ret = vtkObjectFactory::CreateInstance("vtkPoints");
if (ret)
{
if (dataType != VTK_FLOAT)
{
static_cast<vtkPoints*>(ret)->SetDataType(dataType);
}
return static_cast<vtkPoints*>(ret);
}
// If the factory was unable to create the object, then create it here.
vtkPoints *result = new vtkPoints(dataType);
result->InitializeObjectBase();
return result;
}
vtkPoints* vtkPoints::New()
{
return vtkPoints::New(VTK_FLOAT);
}
// Construct object with an initial data array of type float.
vtkPoints::vtkPoints(int dataType)
{
this->Data = vtkFloatArray::New();
this->Data->Register(this);
this->Data->Delete();
this->SetDataType(dataType);
this->Data->SetNumberOfComponents(3);
this->Data->SetName("Points");
this->Bounds[0] = this->Bounds[2] = this->Bounds[4] = VTK_DOUBLE_MAX;
this->Bounds[1] = this->Bounds[3] = this->Bounds[5] = -VTK_DOUBLE_MAX;
}
vtkPoints::~vtkPoints()
{
this->Data->UnRegister(this);
}
// Given a list of pt ids, return an array of points.
void vtkPoints::GetPoints(vtkIdList *ptIds, vtkPoints *outPoints)
{
outPoints->Data->SetNumberOfTuples(ptIds->GetNumberOfIds());
this->Data->GetTuples(ptIds, outPoints->Data);
}
// Determine (xmin,xmax, ymin,ymax, zmin,zmax) bounds of points.
void vtkPoints::ComputeBounds()
{
if (this->GetMTime() > this->ComputeTime)
{
this->Data->ComputeScalarRange(this->Bounds);
this->ComputeTime.Modified();
}
}
// Return the bounds of the points.
double *vtkPoints::GetBounds()
{
this->ComputeBounds();
return this->Bounds;
}
// Return the bounds of the points.
void vtkPoints::GetBounds(double bounds[6])
{
this->ComputeBounds();
memcpy(bounds, this->Bounds, 6 * sizeof(double));
}
vtkMTimeType vtkPoints::GetMTime()
{
vtkMTimeType doTime = this->Superclass::GetMTime();
if ( this->Data->GetMTime() > doTime )
{
doTime = this->Data->GetMTime();
}
return doTime;
}
int vtkPoints::Allocate(const vtkIdType sz, const vtkIdType ext)
{
int numComp = this->Data->GetNumberOfComponents();
return this->Data->Allocate(sz * numComp, ext * numComp);
}
void vtkPoints::Initialize()
{
this->Data->Initialize();
this->Modified();
}
int vtkPoints::GetDataType()
{
return this->Data->GetDataType();
}
// Specify the underlying data type of the object.
void vtkPoints::SetDataType(int dataType)
{
if (dataType == this->Data->GetDataType())
{
return;
}
this->Data->Delete();
this->Data = vtkDataArray::CreateDataArray(dataType);
this->Data->SetNumberOfComponents(3);
this->Data->SetName("Points");
this->Modified();
}
// Set the data for this object. The tuple dimension must be consistent with
// the object.
void vtkPoints::SetData(vtkDataArray *data)
{
if (data != this->Data && data != NULL)
{
if (data->GetNumberOfComponents() != this->Data->GetNumberOfComponents())
{
vtkErrorMacro(<<"Number of components is different...can't set data");
return;
}
this->Data->UnRegister(this);
this->Data = data;
this->Data->Register(this);
if (!this->Data->GetName())
{
this->Data->SetName("Points");
}
this->Modified();
}
}
// Deep copy of data. Checks consistency to make sure this operation
// makes sense.
void vtkPoints::DeepCopy(vtkPoints *da)
{
if (da == NULL)
{
return;
}
if (da->Data != this->Data && da->Data != NULL)
{
if (da->Data->GetNumberOfComponents() != this->Data->GetNumberOfComponents())
{
vtkErrorMacro(<<"Number of components is different...can't copy");
return;
}
this->Data->DeepCopy(da->Data);
this->Modified();
}
}
// Shallow copy of data (i.e. via reference counting). Checks
// consistency to make sure this operation makes sense.
void vtkPoints::ShallowCopy(vtkPoints *da)
{
this->SetData(da->GetData());
}
unsigned long vtkPoints::GetActualMemorySize()
{
return this->Data->GetActualMemorySize();
}
void vtkPoints::PrintSelf(ostream& os, vtkIndent indent)
{
this->Superclass::PrintSelf(os, indent);
os << indent << "Data: " << this->Data << "\n";
os << indent << "Data Array Name: ";
if (this->Data->GetName())
{
os << this->Data->GetName() << "\n";
}
else
{
os << "(none)\n";
}
os << indent << "Number Of Points: " << this->GetNumberOfPoints() << "\n";
const 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";
}