Vector3.h
1 /*
2  * Medical Image Registration ToolKit (MIRTK)
3  *
4  * Copyright 2008-2015 Imperial College London
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */
18 
19 #ifndef MIRTK_Vector3_H
20 #define MIRTK_Vector3_H
21 
22 namespace mirtk {
23 
24 
25 class Point;
26 
27 
28 /**
29  * 3D vector
30  *
31  * \todo Merge/replace uses of this class with Vector3D
32  */
33 class Vector3
34 {
35 public:
36  // construction
37  Vector3 ();
38  Vector3 (double fScalar);
39  Vector3 (double fX, double fY, double fZ);
40  Vector3 (const double afCoordinate[3]);
41  Vector3 (const Vector3& rkVector);
42  Vector3 (const Point &);
43 
44  // member access
45  // (allows V._x or V(0) or V[0], V._y or V(1) or V[1], V._z or V(2) or or V[2])
46  double _x, _y, _z;
47  double& operator[] (int i);
48  const double& operator[] (int i) const;
49  operator double* ();
50  operator const double* () const;
51 
52  // assignment and comparison
53  Vector3& operator= (const Vector3& rkVector);
54  Vector3& operator= (double fScalar);
55  bool operator== (const Vector3& rkVector) const;
56  bool operator!= (const Vector3& rkVector) const;
57 
58  // arithmetic operations
59  Vector3 operator+ (const Vector3& rkVector) const;
60  Vector3 operator- (const Vector3& rkVector) const;
61  Vector3 operator* (double fScalar) const;
62  Vector3 operator/ (double fScalar) const;
63  Vector3 operator- () const;
64  friend Vector3 operator* (double fScalar, const Vector3& rkVector);
65 
66  // arithmetic updates
67  Vector3& operator+= (const Vector3& rkVector);
68  Vector3& operator-= (const Vector3& rkVector);
69  Vector3& operator*= (double fScalar);
70  Vector3& operator/= (double fScalar);
71 
72  // vector operations
73  double Length () const;
74  double SquaredLength () const;
75  double Dot (const Vector3& rkVector) const;
76  double Normalize (double fTolerance = 1e-06);
77  double Unitize (double fTolerance = 1e-06); ///< \deprecated Use Normalize instead
78  Vector3 Cross (const Vector3& rkVector) const;
79  Vector3 UnitCross (const Vector3& rkVector) const;
80 
81  // Gram-Schmidt orthonormalization.
82  static void Orthonormalize (Vector3 akVector[3]);
83 
84  // Input W must be initialize to a nonzero vector, output is {U,V,W}
85  // an orthonormal basis. A hint is provided about whether or not W
86  // is already unit length.
87  static void GenerateOrthonormalBasis (Vector3& rkU, Vector3& rkV,
88  Vector3& rkW, bool bUnitLengthW = true);
89 
90  // special points
91  static const Vector3 ZERO;
92  static const Vector3 UNIT_X;
93  static const Vector3 UNIT_Y;
94  static const Vector3 UNIT_Z;
95 };
96 
97 
98 } // namespace mirtk
99 
100 #endif // MIRTK_Vector3_H
Definition: IOConfig.h:41
double Unitize(double fTolerance=1e-06)