CVB++ 15.0
plane_3d.hpp
1#pragma once
2
3#include <cmath>
4
5#include "global.hpp"
6
7#include "point_3d.hpp"
8#include "affine_matrix_3d.hpp"
9
10namespace Cvb
11{
12
13 CVB_BEGIN_INLINE_NS
14
16
18 class Plane3D final
19 {
20 public:
22
25 Plane3D() noexcept = default;
26
28
35 Plane3D(double nx, double ny, double nz, double distanceToOrigin) noexcept
36 : normal_{nx, ny, nz}
37 , distanceToOrigin_{distanceToOrigin}
38 {
39 }
40
42
47 Plane3D(Point3D<double> normal, double distanceToOrigin) noexcept
48 : normal_{normal}
49 , distanceToOrigin_{distanceToOrigin}
50 {
51 }
52
54
58 Point3D<double> Normal() const noexcept
59 {
60 return normal_;
61 }
62
64
68 void SetNormal(Point3D<double> normal) noexcept
69 {
70 normal_ = normal;
71 }
72
74
78 double DistanceToOrigin() const noexcept
79 {
80 return distanceToOrigin_;
81 }
82
84
88 void SetDistanceToOrigin(double distanceToOrigin) noexcept
89 {
90 distanceToOrigin_ = distanceToOrigin;
91 }
92
94
99 double DistanceToPoint(const Point3D<double> &pt) const noexcept
100 {
101 return DistanceToPoint(pt.X(), pt.Y(), pt.Z());
102 }
103
105
112 double DistanceToPoint(double x, double y, double z) const noexcept
113 {
114 auto normal = normal_ / normal_.Length();
115 return std::abs(normal.X() * x + normal.Y() * y + normal.Z() * z - distanceToOrigin_);
116 }
117
120
135 {
136 return Internal::DoResCallValueOut<AffineMatrix3D>([&](AffineMatrix3D &value) {
137 auto valueData = reinterpret_cast<CExports::CVC3DTransformation *>(&value);
138
139 return CVB_CALL_CAPI(CVC3DAlignToXYPlane(*reinterpret_cast<const CExports::CVC3DPlane *>(this), *valueData));
140 });
141 }
142
144
149 bool operator==(const Plane3D &plane) const noexcept
150 {
151 return (normal_ == plane.normal_ && distanceToOrigin_ == plane.distanceToOrigin_);
152 }
153
155
160 bool operator!=(const Plane3D &plane) const noexcept
161 {
162 return !(*this == plane);
163 }
164
165 private:
166 Point3D<double> normal_{0.0, 0.0, 0.0};
167 double distanceToOrigin_ = 0.0;
168 };
169
170 CVB_END_INLINE_NS
171} // namespace Cvb
Affine transformation for 3D containing a transformation matrix and a translation vector.
Definition affine_matrix_3d.hpp:140
Plane3D(Point3D< double > normal, double distanceToOrigin) noexcept
Creates a new Plane3D object.
Definition plane_3d.hpp:47
double DistanceToPoint(const Point3D< double > &pt) const noexcept
Calculates the distance to the point pt.
Definition plane_3d.hpp:99
double DistanceToPoint(double x, double y, double z) const noexcept
Calculates the distance to the point pt.
Definition plane_3d.hpp:112
double DistanceToOrigin() const noexcept
Gets the distance to the origin in point units.
Definition plane_3d.hpp:78
bool operator==(const Plane3D &plane) const noexcept
Compares to an other plane.
Definition plane_3d.hpp:149
bool operator!=(const Plane3D &plane) const noexcept
Compares to an other plane.
Definition plane_3d.hpp:160
Plane3D() noexcept=default
Creates a default plane at (0, 0, 0, 0).
void SetDistanceToOrigin(double distanceToOrigin) noexcept
Sets the distance to the origin in point units.
Definition plane_3d.hpp:88
Point3D< double > Normal() const noexcept
Gets the normal vector of the plane.
Definition plane_3d.hpp:58
AffineMatrix3D AlignToXYPlane()
Calculates a rigid body transformation that maps the plane into the xy plane of the global coordinate...
Definition plane_3d.hpp:134
void SetNormal(Point3D< double > normal) noexcept
Sets the normal vector of the plane.
Definition plane_3d.hpp:68
Multi-purpose 3D vector class.
Definition point_3d.hpp:22
Root namespace for the Image Manager interface.
Definition c_bayer_to_rgb.h:17