MeVisLab Toolbox Reference
Loading...
Searching...
No Matches
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 know whether vector or
36// matrix header is included first and we cannot move template
37// code into the 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> class Tvec4 : public FloatingPointVector<DT, 4>
49{
50public:
53
55 typedef DT ComponentType;
56
57 //--------------------------------------------------------------------
60 //--------------------------------------------------------------------
62 inline explicit Tvec4(const DT value = 0)
63 : Superclass(value)
64 {}
65
69 inline Tvec4(const Superclass& v)
70 : Superclass(v)
71 {}
72
75 inline Tvec4(const DT x, const DT y, const DT z, const DT w)
76 {
77 Superclass::_buffer[0] = x;
78 Superclass::_buffer[1] = y;
79 Superclass::_buffer[2] = z;
80 Superclass::_buffer[3] = w;
81 }
82
84 inline Tvec4(const Tvec2<DT>& v, const DT z, const DT w)
85 {
86 Superclass::_buffer[0] = v[0];
87 Superclass::_buffer[1] = v[1];
88 Superclass::_buffer[2] = z;
89 Superclass::_buffer[3] = w;
90 }
91
93 inline Tvec4(const Tvec3<DT>& v, const DT w)
94 {
95 Superclass::_buffer[0] = v[0];
96 Superclass::_buffer[1] = v[1];
97 Superclass::_buffer[2] = v[2];
98 Superclass::_buffer[3] = w;
99 }
100
102 inline void assign(const DT x, const DT y, const DT z, const DT c)
103 {
104 Superclass::_buffer[0] = x;
105 Superclass::_buffer[1] = y;
106 Superclass::_buffer[2] = z;
107 Superclass::_buffer[3] = c;
108 }
109
115 {
116 const DT lastComp = Superclass::_buffer[3];
117
119 const DT div = static_cast<DT>(1) / lastComp;
120 return Tvec4<DT>(Superclass::_buffer[0] * div, Superclass::_buffer[1] * div, Superclass::_buffer[2] * div, 1);
121 }
123};
124
126#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]
127//-----------------------------------------------------------------------------------
129//-----------------------------------------------------------------------------------
130template <class DT> inline Tvec4<DT> operator*(const Tmat4<DT>& a, const Tvec4<DT>& v)
131{
133}
134#undef _ML_VEC4_RC
135
136//-----------------------------------------------------------------------------------
138//-----------------------------------------------------------------------------------
139template <class DT> inline Tvec4<DT> operator*(const Tvec4<DT>& v, const Tmat4<DT>& a)
140{
141 return a.transpose() * v;
142}
143
144
145//-----------------------------------------------------------------------------------
148//-----------------------------------------------------------------------------------
158
160
161#endif // of __mlVector4_H
Template class for vector arithmetic with floating point datatypes.
A 4x4 matrix class consisting of four row vectors.
Definition mlMatrix4.h:35
Tmat4< DT > transpose() const
Returns the transposed *this.
Definition mlMatrix4.h:598
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:49
Tvec4(const DT value=0)
Default and value constructor. Sets all entries to a user given value.
Definition mlVector4.h:62
void assign(const DT x, const DT y, const DT z, const DT c)
Sets all components to the passed values.
Definition mlVector4.h:102
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:84
Tvec4< DT > divideByLastComp() const
Divides all vector components by its last component and returns it as Tvec4, which then has a 1 as la...
Definition mlVector4.h:114
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:75
FloatingPointVector< DT, 4 > Superclass
A typedef as a shorthand for the base class.
Definition mlVector4.h:52
Tvec4(const Tvec3< DT > &v, const DT w)
Casts Vector3 to Tvec4. Sets last entry to the passed value w.
Definition mlVector4.h:93
DT ComponentType
A typedef to 'export' the type of components.
Definition mlVector4.h:55
Tvec4(const Superclass &v)
Copy constructor from FloatingPointVector.
Definition mlVector4.h:69
#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:126
T operator*(const FloatingPointVector< T, size, DataContainer > &a, const FloatingPointVector< T, size, DataContainer > &b)
Dot product, returns a.dot(b).