#include <vector.h>
Public Member Functions | |
~TVector () | |
Destructor. | |
void | SetN (uint N) |
Size change. | |
T & | operator() (uint i) |
Reference operator. | |
T * | GetAnsiRef () |
ANSI (C/C++ array) reference. | |
uint | GetN () |
Vector's cardinality. | |
int | GetType () |
Vector's type (ROW_VECTOR/COL_VECTOR). | |
T | GetNorm () |
Mathematical norm (L2). | |
void | Normalize () |
Normalizes the vector. | |
T | Dot (const TVector< T > &r) |
Dot product. | |
TVector (uint N=3, T data=(T) 0, int type=0x02) | |
Default constructor. | |
TVector (const TVector< T > &r) | |
Copy constructor. | |
TVector (T *block, uint N, bool copy=true, int type=0x02) | |
Use this to treat an ANSI array as a TVector. | |
TVector< T > & | operator= (const TVector< T > &r) |
Vector assignation. | |
TVector< T > & | operator= (TMatrix< T > &r) |
Matrix assignation (defined in class TMatrix). | |
TVector< T > & | operator= (T *r) |
ANSI assignation (r size must be, at least, N). | |
TVector< T > & | operator= (T r) |
Scalar assignation. | |
bool | operator== (const TVector< T > &r) |
Equality. | |
bool | operator!= (const TVector< T > &r) |
Inequality. | |
TVector< T > | operator+ (const TVector< T > &r) |
Addition. | |
TVector< T > | operator- (const TVector< T > &r) |
Substraction. | |
TVector< T > | operator * (const TVector< T > &r) |
Cross product. | |
TMatrix< T > | operator * (TMatrix< T > &r) |
Matrix product (defined in class TMatrix). | |
TVector< T > | operator * (T r) |
Scalar product. | |
TVector< T > & | operator+= (const TVector< T > &r) |
Addition. | |
TVector< T > & | operator-= (const TVector< T > &r) |
Substraction. | |
TVector< T > & | operator *= (const TVector< T > &r) |
Cross product. | |
TVector< T > & | operator *= (T r) |
Scalar product. | |
TVector< T > | operator- () |
Unary operators. | |
TVector< T > | operator! () |
Normalized vector. | |
TVector< T > | operator~ () |
Transposed vector. | |
Private Attributes | |
T * | _vector |
Vector's internal state. | |
uint | _N |
Cardinality. | |
int | _type |
Type (ROW_VECTOR/COL_VECTOR). | |
bool | _myMemory |
Have I created _vector? |
This class defines a C++ template to use mathematical vectors in a N space.
Definition at line 48 of file vector.h.
gtm::TVector< T >::TVector | ( | uint | N = 3 , |
|
T | data = ( T )0 , |
|||
int | type = 0x02 | |||
) | [inline] |
Default constructor.
Contructors.
N | Cardinality. | |
data | Initial data. | |
type | Vector type (ROW_VECTOR/COL_VECTOR). | |
r | Right object (vector or matrix). | |
block | ANSI array. | |
copy | Make a copy of given array? |
Definition at line 211 of file vector.h.
References gtm::TVector< T >::_myMemory, gtm::TVector< T >::_N, gtm::TVector< T >::_type, and gtm::TVector< T >::_vector.
00212 { 00213 _N = N; 00214 _type = type; 00215 _vector = VectorAllocateMemory< T >( _N ); 00216 _myMemory = true; 00217 VectorAssignScalar< T >( _vector, data, _N ); 00218 00219 }
gtm::TVector< T >::TVector | ( | const TVector< T > & | r | ) | [inline] |
Copy constructor.
Definition at line 223 of file vector.h.
References gtm::TVector< T >::_myMemory, gtm::TVector< T >::_N, gtm::TVector< T >::_type, and gtm::TVector< T >::_vector.
00224 { 00225 _N = r._N; 00226 _type = r._type; 00227 _myMemory = true; 00228 _vector = VectorCopyMemory< T >( r._vector, _N ); 00229 00230 }
gtm::TVector< T >::TVector | ( | T * | block, | |
uint | N, | |||
bool | copy = true , |
|||
int | type = 0x02 | |||
) | [inline] |
Use this to treat an ANSI array as a TVector.
Definition at line 234 of file vector.h.
References gtm::TVector< T >::_myMemory, gtm::TVector< T >::_N, gtm::TVector< T >::_type, and gtm::TVector< T >::_vector.
00235 { 00236 _N = N; 00237 _type = type; 00238 _myMemory = copy; 00239 _vector = ( copy )? VectorCopyMemory< T >( block, _N ): block; 00240 00241 }
gtm::TVector< T >::~TVector | ( | ) | [inline] |
Destructor.
Definition at line 71 of file vector.h.
References gtm::TVector< T >::_myMemory, and gtm::TVector< T >::_vector.
void gtm::TVector< T >::SetN | ( | uint | N | ) | [inline] |
Size change.
Definition at line 245 of file vector.h.
References gtm::TVector< T >::_myMemory, gtm::TVector< T >::_N, and gtm::TVector< T >::_vector.
00246 { 00247 if( _myMemory ) VectorFreeMemory< T >( _vector ); 00248 _N = N; 00249 _vector = VectorAllocateMemory< T >( _N ); 00250 _myMemory = true; 00251 VectorAssignScalar< T >( _vector, ( T )0, _N ); 00252 00253 }
TVector< T > & gtm::TVector< T >::operator= | ( | const TVector< T > & | r | ) | [inline] |
Vector assignation.
Assignation operators.
r | Right object (vector or matrix). |
Definition at line 257 of file vector.h.
References gtm::TVector< T >::_N, gtm::TVector< T >::_type, gtm::TVector< T >::_vector, and GTM_MIN.
00258 { 00259 /* 00260 * Only assigns the minimum cardinality (WARNING WITH NON-LOCAL MEMORY). 00261 */ 00262 _type = r._type; 00263 VectorAssignMemory< T >( _vector, r._vector, GTM_MIN( _N, r._N ) ); 00264 return( *this ); 00265 00266 }
TVector< T > & gtm::TVector< T >::operator= | ( | TMatrix< T > & | r | ) | [inline] |
Matrix assignation (defined in class TMatrix).
Definition at line 190 of file matrix.h.
References gtm::TVector< T >::_N, gtm::TVector< T >::_type, gtm::TVector< T >::_vector, COL_VECTOR, gtm::TMatrix< T >::GetM(), gtm::TMatrix< T >::GetN(), GTM_MIN, min, and ROW_VECTOR.
00191 { 00192 uint i, j, k, min; 00193 00194 // This min calc. avoids to reserve temporary memory, so, be careful. 00195 min = GTM_MIN( r.GetN( ) * r.GetM( ), _N ); 00196 _type = ( r.GetN( ) == 1 )? COL_VECTOR: ROW_VECTOR; 00197 for( i = 0, k = 0; i < r.GetN( ) && k < min; i++ ) 00198 for( j = 0; j < r.GetM( ) && k < min; _vector[ k++ ] = r( i, j ), j++ ); 00199 return( *this ); 00200 00201 }
TVector< T >& gtm::TVector< T >::operator= | ( | T * | r | ) | [inline] |
ANSI assignation (r size must be, at least, N).
Definition at line 88 of file vector.h.
References gtm::TVector< T >::_N, and gtm::TVector< T >::_vector.
TVector< T >& gtm::TVector< T >::operator= | ( | T | r | ) | [inline] |
Scalar assignation.
Definition at line 93 of file vector.h.
References gtm::TVector< T >::_N, and gtm::TVector< T >::_vector.
bool gtm::TVector< T >::operator== | ( | const TVector< T > & | r | ) | [inline] |
Equality.
Comparation operators.
r | Right object. |
Definition at line 270 of file vector.h.
References gtm::TVector< T >::_N, and gtm::TVector< T >::_vector.
00271 { 00272 uint i; 00273 bool ret; 00274 00275 for( 00276 i = 0, ret = ( _N == r._N ); 00277 i < _N && ret; 00278 ret &= ( _vector[ i ] == r._vector[ i ] ), i++ 00279 ); 00280 return( ret ); 00281 00282 }
bool gtm::TVector< T >::operator!= | ( | const TVector< T > & | r | ) | [inline] |
Inequality.
Definition at line 286 of file vector.h.
References gtm::TVector< T >::_N, and gtm::TVector< T >::_vector.
00287 { 00288 uint i; 00289 bool ret; 00290 00291 for( 00292 i = 0, ret = ( _N != r._N ); 00293 i < _N && !ret; 00294 ret |= ( _vector[ i ] != r._vector[ i ] ), i++ 00295 ); 00296 return( ret ); 00297 00298 }
T& gtm::TVector< T >::operator() | ( | uint | i | ) | [inline] |
Reference operator.
Definition at line 111 of file vector.h.
References gtm::TVector< T >::_vector.
00111 { 00112 return( _vector[ i ] ); 00113 };
T* gtm::TVector< T >::GetAnsiRef | ( | ) | [inline] |
ANSI (C/C++ array) reference.
Definition at line 115 of file vector.h.
References gtm::TVector< T >::_vector.
Referenced by UtilVtk3DGeometriSelection::FindCubePointsFromPoints(), vtk3DSurfaceSTLWidget::FindCubePointsFromPoints(), UtilVtk3DGeometriSelection::GetPointAndNormalIntersection(), vtk3DSurfaceSTLWidget::GetPointAndNormalIntersection(), vtkInteractorStyle3DView::SelectMarchibCubePoint(), vtk3DSurfaceWidget::SetInitialPoint(), and vtk3DSurfaceSTLWidget::SetInitialPoint().
00115 { 00116 return( _vector ); 00117 };
uint gtm::TVector< T >::GetN | ( | ) | [inline] |
Vector's cardinality.
Definition at line 119 of file vector.h.
References gtm::TVector< T >::_N.
Referenced by gtm::TMatrix< T >::operator=().
00119 { 00120 return( _N ); 00121 };
int gtm::TVector< T >::GetType | ( | ) | [inline] |
Vector's type (ROW_VECTOR/COL_VECTOR).
Definition at line 123 of file vector.h.
References gtm::TVector< T >::_type.
Referenced by gtm::TMatrix< T >::operator=().
00123 { 00124 return( _type ); 00125 };
T gtm::TVector< T >::GetNorm | ( | ) | [inline] |
Mathematical norm (L2).
Definition at line 127 of file vector.h.
References gtm::TVector< T >::_N, and gtm::TVector< T >::_vector.
void gtm::TVector< T >::Normalize | ( | ) | [inline] |
Normalizes the vector.
Definition at line 131 of file vector.h.
References gtm::TVector< T >::_N, and gtm::TVector< T >::_vector.
Referenced by UtilVtk3DGeometriSelection::GetPointAndNormalIntersection(), and vtk3DSurfaceSTLWidget::GetPointAndNormalIntersection().
T gtm::TVector< T >::Dot | ( | const TVector< T > & | r | ) | [inline] |
Dot product.
Definition at line 135 of file vector.h.
References gtm::TVector< T >::_N, gtm::TVector< T >::_vector, and GTM_MIN.
TVector< T > gtm::TVector< T >::operator+ | ( | const TVector< T > & | r | ) | [inline] |
Addition.
Binary operators.
r | Right object (vector, matrix or scalar). |
Definition at line 302 of file vector.h.
References gtm::TVector< T >::_N, gtm::TVector< T >::_vector, and GTM_MIN.
00303 { 00304 TVector< T > ret( GTM_MIN( _N, r._N ) ); 00305 00306 VectorAdd< T >( ret._vector, _vector, r._vector, GTM_MIN( _N, r._N ) ); 00307 return( ret ); 00308 00309 }
TVector< T > gtm::TVector< T >::operator- | ( | const TVector< T > & | r | ) | [inline] |
Substraction.
Definition at line 313 of file vector.h.
References gtm::TVector< T >::_N, gtm::TVector< T >::_vector, and GTM_MIN.
00314 { 00315 TVector< T > ret( GTM_MIN( _N, r._N ) ); 00316 00317 VectorSubtract< T >( ret._vector, _vector, r._vector, GTM_MIN( _N, r._N ) ); 00318 return( ret ); 00319 00320 }
TVector< T > gtm::TVector< T >::operator * | ( | const TVector< T > & | r | ) | [inline] |
Cross product.
Definition at line 324 of file vector.h.
References gtm::TVector< T >::_N, gtm::TVector< T >::_vector, and GTM_MIN.
00325 { 00326 TVector< T > ret( GTM_MIN( _N, r._N ) ); 00327 00328 VectorCrossProduct< T >( ret._vector, _vector, r._vector ); 00329 return( ret ); 00330 00331 }
TMatrix< T > gtm::TVector< T >::operator * | ( | TMatrix< T > & | r | ) | [inline] |
TVector< T > gtm::TVector< T >::operator * | ( | T | r | ) | [inline] |
Scalar product.
Definition at line 335 of file vector.h.
References gtm::TVector< T >::_N, and gtm::TVector< T >::_vector.
00336 { 00337 TVector< T > ret( _N ); 00338 00339 VectorScalarProduct< T >( ret._vector, _vector, r, _N ); 00340 return( ret ); 00341 00342 }
TVector< T >& gtm::TVector< T >::operator+= | ( | const TVector< T > & | r | ) | [inline] |
TVector< T >& gtm::TVector< T >::operator-= | ( | const TVector< T > & | r | ) | [inline] |
TVector< T >& gtm::TVector< T >::operator *= | ( | const TVector< T > & | r | ) | [inline] |
TVector< T >& gtm::TVector< T >::operator *= | ( | T | r | ) | [inline] |
TVector< T > gtm::TVector< T >::operator- | ( | ) | [inline] |
Unary operators.
Additive inverse.
Definition at line 346 of file vector.h.
References gtm::TVector< T >::_N, and gtm::TVector< T >::_vector.
00347 { 00348 TVector< T > ret( _N ); 00349 uint i; 00350 00351 for( i = 0; i < _N; ret._vector[ i ] = ( T )0 - _vector[ i ], i++ ); 00352 return( ret ); 00353 00354 }
TVector< T > gtm::TVector< T >::operator! | ( | ) | [inline] |
Normalized vector.
Definition at line 358 of file vector.h.
References gtm::TVector< T >::_N, and gtm::TVector< T >::_vector.
00359 { 00360 TVector< T > ret( _N ); 00361 00362 VectorNormalize< T >( ret._vector, _vector, _N ); 00363 return( ret ); 00364 00365 }
TVector< T > gtm::TVector< T >::operator~ | ( | ) | [inline] |
Transposed vector.
Definition at line 369 of file vector.h.
References gtm::TVector< T >::_type, COL_VECTOR, and ROW_VECTOR.
00370 { 00371 TVector< T > ret = *this; 00372 00373 ret._type = ( _type == COL_VECTOR )? ROW_VECTOR: COL_VECTOR; 00374 return( ret ); 00375 00376 }
T* gtm::TVector< T >::_vector [private] |
Vector's internal state.
Memory block.
Definition at line 198 of file vector.h.
Referenced by gtm::TVector< T >::Dot(), gtm::TVector< T >::GetAnsiRef(), gtm::TVector< T >::GetNorm(), gtm::TVector< T >::Normalize(), gtm::TVector< T >::operator *(), gtm::TVector< T >::operator!(), gtm::TVector< T >::operator!=(), gtm::TVector< T >::operator()(), gtm::TVector< T >::operator+(), gtm::TVector< T >::operator-(), gtm::TVector< T >::operator=(), gtm::TVector< T >::operator==(), gtm::TVector< T >::SetN(), gtm::TVector< T >::TVector(), and gtm::TVector< T >::~TVector().
uint gtm::TVector< T >::_N [private] |
Cardinality.
Definition at line 200 of file vector.h.
Referenced by gtm::TVector< T >::Dot(), gtm::TVector< T >::GetN(), gtm::TVector< T >::GetNorm(), gtm::TVector< T >::Normalize(), gtm::TVector< T >::operator *(), gtm::TVector< T >::operator!(), gtm::TVector< T >::operator!=(), gtm::TVector< T >::operator+(), gtm::TVector< T >::operator-(), gtm::TVector< T >::operator=(), gtm::TVector< T >::operator==(), gtm::TVector< T >::SetN(), and gtm::TVector< T >::TVector().
int gtm::TVector< T >::_type [private] |
Type (ROW_VECTOR/COL_VECTOR).
Definition at line 202 of file vector.h.
Referenced by gtm::TVector< T >::GetType(), gtm::TVector< T >::operator=(), gtm::TVector< T >::operator~(), and gtm::TVector< T >::TVector().
bool gtm::TVector< T >::_myMemory [private] |
Have I created _vector?
Definition at line 204 of file vector.h.
Referenced by gtm::TVector< T >::SetN(), gtm::TVector< T >::TVector(), and gtm::TVector< T >::~TVector().