MeVisLab Toolbox Reference
mlVector4.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_VECTOR4_H
14#define ML_VECTOR4_H
15
17
18// Include system independent file and project settings.
20#include "mlLinearAlgebraDefs.h"
21
23#include "mlVector2.h"
24#include "mlVector3.h"
25#include "mlMatrix3.h"
26#include "mlMatrix4.h"
27
28#include <mlErrorOutput.h>
29
30// All declarations of this header will be in the ML_LA_NAMESPACE namespace.
32
33//--------------------------------------------------------------------
35// This is necessary because we do not known whether vector or
36// matrix header is included first and we cannot move template
37// code into C++ file.
38//--------------------------------------------------------------------
39template <class DT> class Tvec2;
40template <class DT> class Tvec3;
41template <class DT> class Tmat3;
42template <class DT> class Tmat4;
44
45//--------------------------------------------------------------------
47//--------------------------------------------------------------------
48template <class DT>
49class Tvec4 : public FloatingPointVector<DT,4>
50{
51public:
52
55
57 typedef DT ComponentType;
58
59 //--------------------------------------------------------------------
62 //--------------------------------------------------------------------
64 inline explicit Tvec4(const DT value=0) : Superclass(value)
65 {
66 }
67
71 inline Tvec4(const Superclass &v): Superclass(v)
72 {
73 }
74
77 inline Tvec4(const DT x, const DT y, const DT z, const DT w)
78 {
79 Superclass::_buffer[0] = x;
80 Superclass::_buffer[1] = y;
81 Superclass::_buffer[2] = z;
82 Superclass::_buffer[3] = w;
83 }
84
86 inline Tvec4(const Tvec2<DT>& v, const DT z, const DT w)
87 {
88 Superclass::_buffer[0] = v[0];
89 Superclass::_buffer[1] = v[1];
90 Superclass::_buffer[2] = z;
91 Superclass::_buffer[3] = w;
92 }
93
95 inline Tvec4(const Tvec3<DT>& v, const DT w)
96 {
97 Superclass::_buffer[0] = v[0];
98 Superclass::_buffer[1] = v[1];
99 Superclass::_buffer[2] = v[2];
100 Superclass::_buffer[3] = w;
101 }
102
104 inline void assign(const DT x, const DT y, const DT z, const DT c)
105 {
106 Superclass::_buffer[0] = x;
107 Superclass::_buffer[1] = y;
108 Superclass::_buffer[2] = z;
109 Superclass::_buffer[3] = c;
110 }
111
117 {
118 const DT lastComp = Superclass::_buffer[3];
119
121 const DT div = static_cast<DT>(1) / lastComp;
122 return Tvec4<DT>(Superclass::_buffer[0] * div,
123 Superclass::_buffer[1] * div,
124 Superclass::_buffer[2] * div, 1);
125 }
127};
128
130#define _ML_VEC4_RC(i) a[i][0]*v[0] + a[i][1]*v[1] + a[i][2]*v[2] + a[i][3]*v[3]
131//-----------------------------------------------------------------------------------
133//-----------------------------------------------------------------------------------
134template <class DT>
135inline Tvec4<DT> operator*(const Tmat4<DT>& a, const Tvec4<DT>& v)
136{
138}
139#undef _ML_VEC4_RC
140
141//-----------------------------------------------------------------------------------
143//-----------------------------------------------------------------------------------
144template <class DT>
145inline Tvec4<DT> operator*(const Tvec4<DT>& v, const Tmat4<DT>& a)
146{
147 return a.transpose() * v;
148}
149
150
151//-----------------------------------------------------------------------------------
154//-----------------------------------------------------------------------------------
164
166
167#endif //of __mlVector4_H
168
169
170
Template class for vector arithmetic with floating point data types.
A four by four matrix class consisting of 4 row vectors.
Definition mlMatrix4.h:36
Tmat4< DT > transpose() const
Returns the transposed *this.
Definition mlMatrix4.h:572
Declaration of float vector type traits:
Definition mlVector2.h:57
Forward declarations to resolve header file dependencies.
Definition mlVector3.h:66
Forward declarations to resolve header file dependencies.
Definition mlVector4.h:50
Tvec4(const DT value=0)
Default and value constructor. Sets all entries to a user given value.
Definition mlVector4.h:64
FloatingPointVector< DT, 4 > Superclass
A typedef as a shorthand for the base class.
Definition mlVector4.h:54
void assign(const DT x, const DT y, const DT z, const DT c)
Sets all components to the passed values.
Definition mlVector4.h:104
Tvec4(const Tvec2< DT > &v, const DT z, const DT w)
Casts Vector2 to Tvec4. Sets last two entries are given by z and w.
Definition mlVector4.h:86
Tvec4< DT > divideByLastComp() const
Divides all vector components by its last component and returns it as Tvec4 which then has a 1 as las...
Definition mlVector4.h:116
Tvec4(const DT x, const DT y, const DT z, const DT w)
Builds the vector from the scalars x, y, z and w to the components 0 to 3, respectively.
Definition mlVector4.h:77
Tvec4(const Tvec3< DT > &v, const DT w)
Casts Vector3 to Tvec4. Sets last entry to the passed value w.
Definition mlVector4.h:95
DT ComponentType
A typedef to "export" the type of components.
Definition mlVector4.h:57
Tvec4(const Superclass &v)
Copy constructor from FloatingPointVector.
Definition mlVector4.h:71
#define ML_CHECK_FLOAT_THROW(x)
Target mlrange_cast(Source arg)
Generic version of checked ML casts.
#define _ML_VEC4_RC(i)
Internal helper macro for tMat4 with Tvec4 multiplications. Do not use.
Definition mlVector4.h:130
T operator*(const FloatingPointVector< T, size, DataContainer > &a, const FloatingPointVector< T, size, DataContainer > &b)
Dot product, returns a.dot(b).