MeVisLab Toolbox Reference
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.
19 #include "mlLinearAlgebraSystem.h"
20 #include "mlLinearAlgebraDefs.h"
21 #include "mlFloatingPointVector.h"
22 
23 // All declarations of this header will be in the ML_LA_NAMESPACE namespace.
24 ML_LA_START_NAMESPACE
25 
27 template <class DT>
29 {
30 public:
31  union {
32  struct {
34  DT x;
36  DT y;
37  };
39  DT _buffer[2];
40  };
41 };
42 
43 //--------------------------------------------------------------------
45 // This is necessary because we do not known whether vector or
46 // matrix header is included first and we cannot move template
47 // code into C++ file.
48 //--------------------------------------------------------------------
49 template <class DT> class Tvec3;
51 
52 //--------------------------------------------------------------------
54 //--------------------------------------------------------------------
55 template <class DT>
56 class Tvec2 : public FloatingPointVector<DT, 2, Vector2DataContainer<DT> >
57 {
58 public:
59 
62 
64  typedef DT ComponentType;
65 
66  //--------------------------------------------------------------------
69  //--------------------------------------------------------------------
72  inline explicit Tvec2(const DT value=0) : Superclass(value)
73  {
74  }
75 
79  inline Tvec2(const Superclass &v): Superclass(v)
80  {
81  }
82 
84  inline Tvec2(const DT px, const DT py) : 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) : Superclass()
101  {
102  if (normalize){
103  // Homogeneous cast.
104  ML_CHECK_FLOAT_THROW(v[2]);
105  Superclass::_buffer[0] = v[0]/v[2];
106  Superclass::_buffer[1] = v[1]/v[2];
107  }
108  else{
109  // Normal cast.
110  Superclass::_buffer[0] = v[0];
111  Superclass::_buffer[1] = v[1];
112  }
113  }
114 
118  inline Tvec2(const Tvec3<DT>& v, const int axis) : Superclass()
119  {
120  switch (axis) {
121  case 0: Superclass::_buffer[0] = v[1];
122  Superclass::_buffer[1] = v[2]; break;
123  case 1: Superclass::_buffer[0] = v[0];
124  Superclass::_buffer[1] = v[2]; break;
125  default: Superclass::_buffer[0] = v[0];
126  Superclass::_buffer[1] = v[1]; break;
127  }
128  }
130 
133  inline Tvec3<DT> affineVec() const
134  {
135  return Tvec3<DT>(*this, 0);
136  }
137 
140  inline Tvec3<DT> affinePoint() const
141  {
142  return Tvec3<DT>(*this, 1);
143  }
144 
145 }; // end of class *Tvec2<DT>*
146 
147 
148 //-----------------------------------------------------------------------------------
151 //-----------------------------------------------------------------------------------
161 
162 
163 #if ML_DEPRECATED_SINCE(3,5,0)
168 ML_DEPRECATED typedef Tvec2<MLfloat> vecf2;
171 ML_DEPRECATED typedef Tvec2<MLdouble> vecd2;
174 ML_DEPRECATED typedef Tvec2<MLldouble> vecld2;
177 ML_DEPRECATED typedef Tvec2<MLdouble> vec2;
179 
180 #endif
181 
182 
183 ML_LA_END_NAMESPACE
184 
185 #endif //of __mlVector2_H
186 
187 
188 
189 
#define ML_DEPRECATED
Definition: CSOGroup.h:371
Template class for vector arithmetic with floating point data types.
Declaration of float vector type traits:
Definition: mlVector2.h:57
Tvec2(const DT px, const DT py)
Constructor building the vector x (first entry) and y (second entry).
Definition: mlVector2.h:84
Tvec3< DT > affinePoint() const
Builds a homogeneous Tvec3point from *this and return it, i.e.
Definition: mlVector2.h:140
Tvec2(const Superclass &v)
Copy constructor from FloatingPointVector.
Definition: mlVector2.h:79
void assign(const DT px, const DT py)
Sets all components to the passed values.
Definition: mlVector2.h:90
Tvec2(const DT value=0)
Default and value constructor.
Definition: mlVector2.h:72
Tvec2(const Tvec3< DT > &v, const int axis)
Casts v3 to v2.
Definition: mlVector2.h:118
Tvec2(const Tvec3< DT > &v, const bool normalize)
Casts v to Tvec2.
Definition: mlVector2.h:100
Tvec3< DT > affineVec() const
Builds a homogeneous Tvec3vector from *this and return it, i.e.
Definition: mlVector2.h:133
DT ComponentType
A typedef to "export" the type of components.
Definition: mlVector2.h:64
FloatingPointVector< DT, 2, Vector2DataContainer< DT > > Superclass
A typedef as a shorthand for the base class.
Definition: mlVector2.h:61
Forward declarations to resolve header file dependencies.
Definition: mlVector3.h:66
Specialized base class for the FloatingPointVectorDataContainerBase.
Definition: mlVector2.h:29
DT x
X-component of the vector, same as _buffer[0].
Definition: mlVector2.h:34
DT y
Y-component of the vector, same as _buffer[1].
Definition: mlVector2.h:36
#define ML_CHECK_FLOAT_THROW(x)
Tvec2< MLdouble > Vector2d
A vector with 2 components of type double.
Definition: mlVector2.h:155
Tvec2< MLfloat > Vector2f
A vector with 2 components of type float.
Definition: mlVector2.h:153
Tvec2< MLdouble > Vector2
A vector with 2 components of type double.
Definition: mlVector2.h:159
Tvec2< MLldouble > Vector2ld
A vector with 2 components of type long double.
Definition: mlVector2.h:157