00001
00002
00003
00004
00005
00006
00007
00008
00009
00010 #ifndef _mitkVis2Vector2_h
00011 #define _mitkVis2Vector2_h
00012
00013 #include "mitkVisualization2Includes.h"
00014
00015 #include <math.h>
00016
00017 class MITK_VISUALIZATION2_API mitkVis2Vector2
00018 {
00019 public:
00020 float ele[2];
00021 mitkVis2Vector2();
00022 mitkVis2Vector2(const mitkVis2Vector2 &v);
00023 mitkVis2Vector2(float x, float y);
00024 mitkVis2Vector2(float srcVector[2]);
00025 operator float* () { return ele; }
00026 operator const float* () const { return ele; }
00027
00028 mitkVis2Vector2& operator = (const mitkVis2Vector2 &a)
00029 {
00030 ele[0] = a.ele[0];
00031 ele[1] = a.ele[1];
00032 return *this;
00033 }
00034 mitkVis2Vector2& operator *= (float);
00035 mitkVis2Vector2& operator += (const mitkVis2Vector2 &);
00036 mitkVis2Vector2& operator -= (const mitkVis2Vector2 &);
00037
00038 void Normalize();
00039 float Length();
00040 };
00041
00042 inline float operator * (const mitkVis2Vector2& A, const mitkVis2Vector2& B)
00043 {
00044 return A.ele[0]*B.ele[0] + A.ele[1]*B.ele[1];
00045 }
00046
00047 inline mitkVis2Vector2 operator * (const mitkVis2Vector2 &V, float s)
00048 {
00049 mitkVis2Vector2 Res;
00050 Res.ele[0] = V.ele[0] * s;
00051 Res.ele[1] = V.ele[1] * s;
00052 return Res;
00053 }
00054
00055 inline mitkVis2Vector2 operator * (float s, const mitkVis2Vector2 &V)
00056 {
00057 mitkVis2Vector2 Res;
00058 Res.ele[0] = V.ele[0] * s;
00059 Res.ele[1] = V.ele[1] * s;
00060 return Res;
00061 }
00062
00063 inline mitkVis2Vector2& mitkVis2Vector2::operator *= (float s)
00064 {
00065 ele[0] *= s;
00066 ele[1] *= s;
00067 return *this;
00068 }
00069
00070 inline mitkVis2Vector2 operator + (const mitkVis2Vector2& A, const mitkVis2Vector2& B)
00071 {
00072 mitkVis2Vector2 Res;
00073 Res.ele[0] = A.ele[0] + B.ele[0];
00074 Res.ele[1] = A.ele[1] + B.ele[1];
00075 return Res;
00076 }
00077
00078 inline mitkVis2Vector2 operator - (const mitkVis2Vector2& A, const mitkVis2Vector2& B)
00079 {
00080 mitkVis2Vector2 Res;
00081 Res.ele[0] = A.ele[0] - B.ele[0];
00082 Res.ele[1] = A.ele[1] - B.ele[1];
00083 return Res;
00084 }
00085
00086 inline mitkVis2Vector2 operator - (const mitkVis2Vector2& A)
00087 {
00088 mitkVis2Vector2 Res;
00089 Res.ele[0] = - A.ele[0];
00090 Res.ele[1] = - A.ele[1];
00091 return Res;
00092 }
00093
00094 inline mitkVis2Vector2 & mitkVis2Vector2::operator += (const mitkVis2Vector2 &B)
00095 {
00096 ele[0] += B.ele[0];
00097 ele[1] += B.ele[1];
00098 return *this;
00099 }
00100
00101 inline mitkVis2Vector2 & mitkVis2Vector2::operator -= (const mitkVis2Vector2 &B)
00102 {
00103 ele[0] -= B.ele[0];
00104 ele[1] -= B.ele[1];
00105 return *this;
00106 }
00107
00108 inline void mitkVis2Vector2::Normalize()
00109 {
00110 float vecLenInv = 1.0f / sqrtf(ele[0]*ele[0] + ele[1]*ele[1]);
00111 ele[0] *= vecLenInv;
00112 ele[1] *= vecLenInv;
00113 }
00114
00115 inline float mitkVis2Vector2::Length()
00116 {
00117 return sqrtf(ele[0]*ele[0] + ele[1]*ele[1] );
00118 }
00119
00120
00121 #endif