MeVisLab Toolbox Reference
Loading...
Searching...
No Matches
mlVector2.h
Go to the documentation of this file.
1/*************************************************************************************
2**
3** Copyright 2007, MeVis Medical Solutions AG
4**
5** The user may use this file in accordance with the license agreement provided with
6** the Software or, alternatively, in accordance with the terms contained in a
7** written agreement between the user and MeVis Medical Solutions AG.
8**
9** For further information use the contact form at https://www.mevislab.de/contact
10**
11**************************************************************************************/
12
13#ifndef ML_VECTOR2_H
14#define ML_VECTOR2_H
15
17
18// Include system independent file and project settings.
20#include "mlLinearAlgebraDefs.h"
22
23// All declarations of this header will be in the ML_LA_NAMESPACE namespace.
25
27template <class DT> class Vector2DataContainer
28{
29public:
30 union
31 {
32 struct
33 {
35 DT x;
37 DT y;
38 };
40 DT _buffer[2];
41 };
42};
43
44//--------------------------------------------------------------------
46// This is necessary, because we do not know whether vector or
47// matrix header is included first and we cannot move template
48// code into the C++ file.
49//--------------------------------------------------------------------
50template <class DT> class Tvec3;
52
53//--------------------------------------------------------------------
55//--------------------------------------------------------------------
56template <class DT> class Tvec2 : public FloatingPointVector<DT, 2, Vector2DataContainer<DT>>
57{
58public:
61
63 typedef DT ComponentType;
64
65 //--------------------------------------------------------------------
68 //--------------------------------------------------------------------
71 inline explicit Tvec2(const DT value = 0)
72 : Superclass(value)
73 {}
74
78 inline Tvec2(const Superclass& v)
79 : Superclass(v)
80 {}
81
83 inline Tvec2(const DT px, const DT py)
84 : Superclass()
85 {
86 assign(px, py);
87 }
88
90 inline void assign(const DT px, const DT py)
91 {
92 Superclass::_buffer[0] = px;
93 Superclass::_buffer[1] = py;
94 }
95
100 inline Tvec2(const Tvec3<DT>& v, const bool normalize)
101 : Superclass()
102 {
103 if (normalize) {
104 // Homogeneous cast.
106 Superclass::_buffer[0] = v[0] / v[2];
107 Superclass::_buffer[1] = v[1] / v[2];
108 }
109 else {
110 // Normal cast.
111 Superclass::_buffer[0] = v[0];
112 Superclass::_buffer[1] = v[1];
113 }
114 }
115
119 inline Tvec2(const Tvec3<DT>& v, const int axis)
120 : Superclass()
121 {
122 switch (axis) {
123 case 0:
124 Superclass::_buffer[0] = v[1];
125 Superclass::_buffer[1] = v[2];
126 break;
127 case 1:
128 Superclass::_buffer[0] = v[0];
129 Superclass::_buffer[1] = v[2];
130 break;
131 default:
132 Superclass::_buffer[0] = v[0];
133 Superclass::_buffer[1] = v[1];
134 break;
135 }
136 }
138
141 inline Tvec3<DT> affineVec() const
142 {
143 return Tvec3<DT>(*this, 0);
144 }
145
148 inline Tvec3<DT> affinePoint() const
149 {
150 return Tvec3<DT>(*this, 1);
151 }
152
153}; // end of class *Tvec2<DT>*
154
155
156//-----------------------------------------------------------------------------------
159//-----------------------------------------------------------------------------------
169
171
172#endif // of __mlVector2_H
Template class for vector arithmetic with floating point datatypes.
Declaration of float vector type traits.
Definition mlVector2.h:57
Tvec2(const DT px, const DT py)
Constructor building the vector px and py.
Definition mlVector2.h:83
Tvec2(const Superclass &v)
Copy constructor from FloatingPointVector.
Definition mlVector2.h:78
Tvec3< DT > affinePoint() const
Builds a homogeneous Tvec3point from *this and returns it, i.e., leaves all components unchanged and ...
Definition mlVector2.h:148
void assign(const DT px, const DT py)
Sets all components to the passed values.
Definition mlVector2.h:90
Tvec3< DT > affineVec() const
Builds a homogeneous Tvec3vector from *this and returns it, i.e., leaves all components unchanged and...
Definition mlVector2.h:141
Tvec2(const DT value=0)
Default and value constructor.
Definition mlVector2.h:71
Tvec2(const Tvec3< DT > &v, const int axis)
Casts v3 to v2.
Definition mlVector2.h:119
Tvec2(const Tvec3< DT > &v, const bool normalize)
Casts v to Tvec2.
Definition mlVector2.h:100
DT ComponentType
A typedef to 'export' the type of components.
Definition mlVector2.h:63
FloatingPointVector< DT, 2, Vector2DataContainer< DT > > Superclass
A typedef as a shorthand for the base class.
Definition mlVector2.h:60
Forward declarations to resolve header file dependencies.
Definition mlVector3.h:66
Specialized base class for the FloatingPointVectorDataContainerBase.
Definition mlVector2.h:28
DT x
X-component of the vector, same as _buffer[0].
Definition mlVector2.h:35
DT y
Y-component of the vector, same as _buffer[1].
Definition mlVector2.h:37
#define ML_CHECK_FLOAT_THROW(x)
Target mlrange_cast(Source arg)
Generic version of checked ML casts.