VTK
Main Page
Related Pages
Namespaces
Classes
Files
File List
File Members
dox
Common
vtkVector.h
Go to the documentation of this file.
1
/*=========================================================================
2
3
Program: Visualization Toolkit
4
Module: vtkVector.h
5
6
Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
7
All rights reserved.
8
See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
9
10
This software is distributed WITHOUT ANY WARRANTY; without even
11
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
12
PURPOSE. See the above copyright notice for more information.
13
14
=========================================================================*/
15
30
#ifndef __vtkVector_h
31
#define __vtkVector_h
32
33
template
<
typename
T,
int
Size>
34
class
vtkVector
35
{
36
public
:
37
vtkVector
()
38
{
39
for
(
int
i = 0; i < Size; ++i)
40
{
41
Data
[i] = 0;
42
}
43
}
44
45
explicit
vtkVector
(
const
T* init)
46
{
47
for
(
int
i = 0; i < Size; ++i)
48
{
49
Data
[i] = init[i];
50
}
51
}
52
54
int
GetSize
()
const
{
return
Size; }
55
57
58
T*
GetData
() {
return
this->
Data
; }
59
const
T*
GetData
()
const
{
return
this->
Data
; }
61
63
65
T&
operator[]
(
int
i) {
return
this->
Data
[i]; }
66
const
T&
operator[]
(
int
i)
const
{
return
this->
Data
[i]; }
68
71
T
operator()
(
int
i)
const
{
return
this->
Data
[i]; }
72
74
75
template
<
typename
TR>
76
vtkVector<TR, Size>
Cast
()
const
77
{
78
vtkVector<TR, Size>
result;
79
for
(
int
i = 0; i < Size; ++i)
80
{
81
result[i] =
static_cast<
TR
>
(
Data
[i]);
82
}
83
return
result;
84
}
86
87
protected
:
89
90
T
Data
[Size];
91
};
93
94
// .NAME vtkVector2 - templated base type for storage of 2D vectors.
95
//
96
template
<
typename
T>
97
class
vtkVector2
:
public
vtkVector
<T, 2>
98
{
99
public
:
100
vtkVector2
(
const
T& x = 0,
const
T& y = 0)
101
{
102
this->
Data
[0] = x;
103
this->
Data
[1] = y;
104
}
105
106
explicit
vtkVector2
(
const
T* init) :
vtkVector
<T, 2>(init)
107
{
108
}
109
111
112
void
Set
(
const
T& x,
const
T& y)
113
{
114
this->
Data
[0] = x;
115
this->
Data
[1] = y;
116
}
118
120
void
SetX
(
const
T& x) { this->
Data
[0] = x; }
121
123
124
const
T&
GetX
()
const
{
return
this->
Data
[0]; }
125
const
T&
X
()
const
{
return
this->
Data
[0]; }
127
129
void
SetY
(
const
T& y) { this->
Data
[1] = y; }
130
132
133
const
T&
GetY
()
const
{
return
this->
Data
[1]; }
134
const
T&
Y
()
const
{
return
this->
Data
[1]; }
135
};
137
138
// .NAME vtkVector3 - templated base type for storage of 3D vectors.
139
//
140
template
<
typename
T>
141
class
vtkVector3
:
public
vtkVector
<T, 3>
142
{
143
public
:
144
vtkVector3
(
const
T& x = 0,
const
T& y = 0,
const
T& z = 0)
145
{
146
this->
Data
[0] = x;
147
this->
Data
[1] = y;
148
this->
Data
[2] = z;
149
}
150
151
explicit
vtkVector3
(
const
T* init) :
vtkVector
<T, 3>(init) { }
152
154
155
void
Set
(
const
T& x,
const
T& y,
const
T& z)
156
{
157
this->
Data
[0] = x;
158
this->
Data
[1] = y;
159
this->
Data
[2] = z;
160
}
162
164
void
SetX
(
const
T& x) { this->
Data
[0] = x; }
165
167
168
const
T&
GetX
()
const
{
return
this->
Data
[0]; }
169
const
T&
X
()
const
{
return
this->
Data
[0]; }
171
173
void
SetY
(
const
T& y) { this->
Data
[1] = y; }
174
176
177
const
T&
GetY
()
const
{
return
this->
Data
[1]; }
178
const
T&
Y
()
const
{
return
this->
Data
[1]; }
180
182
void
SetZ
(
const
T& z) { this->
Data
[2] = z; }
183
185
186
const
T&
GetZ
()
const
{
return
this->
Data
[2]; }
187
const
T&
Z
()
const
{
return
this->
Data
[2]; }
189
190
};
191
193
194
class
vtkVector2i
:
public
vtkVector2
<int>
195
{
196
public
:
197
vtkVector2i
(
int
x = 0,
int
y = 0) :
vtkVector2
<int>(x, y) {}
198
explicit
vtkVector2i
(
const
int
*init) :
vtkVector2
<int>(init) {}
199
};
201
202
class
vtkVector2f
:
public
vtkVector2
<float>
203
{
204
public
:
205
vtkVector2f
(
float
x = 0.0,
float
y = 0.0) :
vtkVector2
<float>(x, y) {}
206
vtkVector2f
(
const
float
* i) :
vtkVector2
<float>(i) {}
207
};
208
209
class
vtkVector2d
:
public
vtkVector2
<double>
210
{
211
public
:
212
vtkVector2d
(
double
x = 0.0,
double
y = 0.0) :
vtkVector2
<double>(x, y) {}
213
explicit
vtkVector2d
(
const
double
*init) :
vtkVector2
<double>(init) {}
214
};
215
216
class
vtkVector3i
:
public
vtkVector3
<int>
217
{
218
public
:
219
vtkVector3i
(
int
x = 0,
int
y = 0,
int
z = 0) :
vtkVector3
<int>(x, y, z) {}
220
explicit
vtkVector3i
(
const
int
*init) :
vtkVector3
<int>(init) {}
221
};
222
223
class
vtkVector3f
:
public
vtkVector3
<float>
224
{
225
public
:
226
vtkVector3f
(
float
x = 0.0,
float
y = 0.0,
float
z = 0.0)
227
:
vtkVector3
<float>(x, y, z) {}
228
explicit
vtkVector3f
(
const
float
*init) :
vtkVector3
<float>(init) {}
229
};
230
231
class
vtkVector3d
:
public
vtkVector3
<double>
232
{
233
public
:
234
vtkVector3d
(
double
x = 0.0,
double
y = 0.0,
double
z = 0.0)
235
:
vtkVector3
<double>(x, y, z) {}
236
explicit
vtkVector3d
(
const
double
*init) :
vtkVector3
<double>(init) {}
237
};
238
239
// Some operators for easy addition etc
240
inline
const
vtkVector2f
operator+
(
const
vtkVector2f
&lhs,
const
vtkVector2f
&rhs)
241
{
242
return
vtkVector2f
(lhs[0] + rhs[0], lhs[1] + rhs[1]);
243
}
244
inline
const
vtkVector2f
operator-
(
const
vtkVector2f
&lhs,
const
vtkVector2f
&rhs)
245
{
246
return
vtkVector2f
(lhs[0] - rhs[0], lhs[1] - rhs[1]);
247
}
248
249
#endif // __vtkVector_h
Generated on Wed Nov 21 2012 21:33:44 for VTK by
1.8.2