CVB++ 14.1
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
13CVB_BEGIN_INLINE_NS
14
16
18class Plane3D final
19{
20public:
22
25 Plane3D() noexcept = default;
26
28
35 Plane3D(double nx, double ny, double nz, double distanceToOrigin) noexcept
36 : normal_{nx, ny, nz}, distanceToOrigin_{distanceToOrigin}
37 {
38 }
39
41
46 Plane3D(Point3D<double> normal, double distanceToOrigin) noexcept
47 : normal_{normal}, distanceToOrigin_{distanceToOrigin}
48 {
49 }
50
52
56 Point3D<double> Normal() const noexcept { return normal_; }
57
59
63 void SetNormal(Point3D<double> normal) noexcept { normal_ = normal; }
64
66
70 double DistanceToOrigin() const noexcept { return distanceToOrigin_; }
71
73
77 void SetDistanceToOrigin(double distanceToOrigin) noexcept { distanceToOrigin_ = distanceToOrigin; }
78
80
85 double DistanceToPoint(const Point3D<double> &pt) const noexcept { return DistanceToPoint(pt.X(), pt.Y(), pt.Z()); }
86
88
95 double DistanceToPoint(double x, double y, double z) const noexcept
96 {
97 auto normal = normal_ / normal_.Length();
98 return std::abs(normal.X() * x + normal.Y() * y + normal.Z() * z - distanceToOrigin_);
99 }
100
103
118 {
119 return Internal::DoResCallValueOut<AffineMatrix3D>([&](AffineMatrix3D& value)
120 {
121 auto valueData = reinterpret_cast<CExports::CVC3DTransformation*>(&value);
122
123 return CVB_CALL_CAPI(CVC3DAlignToXYPlane(*reinterpret_cast<const CExports::CVC3DPlane*>(this),
124 *valueData));
125 });
126
127 }
128
129private:
130 Point3D<double> normal_{0.0, 0.0, 0.0};
131 double distanceToOrigin_ = 0.0;
132};
133
134CVB_END_INLINE_NS
135}
Affine transformation for 3D containing a transformation matrix and a translation vector.
Definition: affine_matrix_3d.hpp:97
A plane in 3D space in Hessian normal form.
Definition: plane_3d.hpp:19
Plane3D(Point3D< double > normal, double distanceToOrigin) noexcept
Creates a new Plane3D object.
Definition: plane_3d.hpp:46
double DistanceToPoint(const Point3D< double > &pt) const noexcept
Calculates the distance to the point pt.
Definition: plane_3d.hpp:85
double DistanceToPoint(double x, double y, double z) const noexcept
Calculates the distance to the point pt.
Definition: plane_3d.hpp:95
double DistanceToOrigin() const noexcept
Gets the distance to the origin in point units.
Definition: plane_3d.hpp:70
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:77
Point3D< double > Normal() const noexcept
Gets the normal vector of the plane.
Definition: plane_3d.hpp:56
AffineMatrix3D AlignToXYPlane()
Calculates a rigid body transformation that maps the plane into the xy plane of the global coordinate...
Definition: plane_3d.hpp:117
void SetNormal(Point3D< double > normal) noexcept
Sets the normal vector of the plane.
Definition: plane_3d.hpp:63
T Length() const noexcept
Gets the length of this point.
Definition: point_3d.hpp:140
Root namespace for the Image Manager interface.
Definition: c_barcode.h:24