AliceVision
Photogrammetric Computer Vision Framework
Point4d.hpp
1 // This file is part of the AliceVision project.
2 // Copyright (c) 2017 AliceVision contributors.
3 // This Source Code Form is subject to the terms of the Mozilla Public License,
4 // v. 2.0. If a copy of the MPL was not distributed with this file,
5 // You can obtain one at https://mozilla.org/MPL/2.0/.
6 
7 #pragma once
8 
9 #include <ostream>
10 
11 namespace aliceVision {
12 
13 class Point4d
14 {
15  public:
16  union
17  {
18  struct
19  {
20  float x, y, z, w;
21  };
22  float m[4];
23  };
24 
25  Point4d()
26  {
27  x = 0.0;
28  y = 0.0;
29  z = 0.0;
30  w = 0.0;
31  }
32 
33  Point4d(const float _x, const float _y, const float _z, const float _w)
34  {
35  x = _x;
36  y = _y;
37  z = _z;
38  w = _w;
39  }
40 
41  inline Point4d& operator=(const Point4d& param)
42  {
43  x = param.x;
44  y = param.y;
45  z = param.z;
46  w = param.w;
47  return *this;
48  }
49 
50  inline bool operator==(const Point4d& param) const { return (x == param.x) && (y == param.y) && (z == param.z) && (w == param.w); }
51 
52  inline Point4d operator-(const Point4d& _p) const { return Point4d(x - _p.x, y - _p.y, z - _p.z, w - _p.w); }
53 
54  inline Point4d operator-() const { return Point4d(-x, -y, -z, -w); }
55 
56  inline Point4d operator+(const Point4d& _p) const { return Point4d(x + _p.x, y + _p.y, z + _p.z, w + _p.w); }
57 
58  inline Point4d operator*(const float d) const { return Point4d(x * d, y * d, z * d, w * d); }
59 
60  inline Point4d operator/(const float d) const { return Point4d(x / d, y / d, z / d, w / d); }
61 
62  inline Point4d normalize() const
63  {
64  float d = sqrt(x * x + y * y + z * z + w * w);
65  return Point4d(x / d, y / d, z / d, w / d);
66  }
67 
68  inline float size() const
69  {
70  float d = x * x + y * y + z * z + w * w;
71  if (d == 0.0f)
72  return 0.0f;
73  return sqrt(d);
74  }
75 
76  friend float dot(const Point4d& p1, const Point4d& p2) { return p1.x * p2.x + p1.y * p2.y + p1.z * p2.z + p1.w * p2.w; }
77 
78  friend Point4d proj(Point4d& e, Point4d& a) { return e * (dot(e, a) / dot(e, e)); }
79 };
80 
81 inline std::ostream& operator<<(std::ostream& stream, const Point4d& p)
82 {
83  stream << p.x << "," << p.y << "," << p.z << "," << p.w;
84  return stream;
85 }
86 
87 } // namespace aliceVision
aliceVision
Definition: checkerDetector.cpp:32
aliceVision::Point4d
Definition: Point4d.hpp:13