Plane.h
Go to the documentation of this file.
1 #ifndef _PLANE_H_
2 #define _PLANE_H_
3 #include <stdio.h>
4 
5 #include <istream>
6 #include <ostream>
7 
8 #include "PointCloud.h"
9 #include "basic.h"
10 #include <GfxTL/Plane.h>
11 #include <MiscLib/NoShrinkVector.h>
12 #include <MiscLib/Vector.h>
13 
14 #ifndef DLL_LINKAGE
15 #define DLL_LINKAGE
16 #endif
17 
19 {
20 public:
21  enum
22  {
23  RequiredSamples = 1
24  };
25 
27  {
28  }
29 
30  Plane(Vec3f p1, Vec3f p2, Vec3f p3);
31  Plane(Vec3f p1, Vec3f normal);
32  virtual ~Plane();
33  bool Init(Vec3f p1, Vec3f p2, Vec3f p3);
34  bool Init(const MiscLib::Vector<Vec3f>& samples);
35  bool InitAverage(const MiscLib::Vector<Vec3f>& samples);
36  bool Init(bool binary, std::istream* i);
37  void Init(FILE* i);
38  void Init(float* array);
39 
40  float
41  getDistance(const Vec3f& pos) const
42  {
43  return abs(m_dist - m_normal.dot(pos));
44  }
45 
46  float
47  Distance(const Vec3f& pos) const
48  {
49  return abs(m_dist - m_normal.dot(pos));
50  }
51 
52  float
53  SignedDistance(const Vec3f& pos) const
54  {
55  return m_normal.dot(pos) - m_dist;
56  }
57 
58  void
59  Normal(const Vec3f&, Vec3f* n) const
60  {
61  *n = m_normal;
62  }
63 
64  float
65  DistanceAndNormal(const Vec3f& pos, Vec3f* n) const
66  {
67  *n = m_normal;
68  return Distance(pos);
69  }
70 
71  const Vec3f&
72  getNormal() const
73  {
74  return m_normal;
75  }
76 
77  const Vec3f&
78  getPosition() const
79  {
80  return m_pos;
81  }
82 
83  bool equals(Plane plane);
84 
85  float
87  {
88  return m_dist;
89  }
90 
91  bool
92  Fit(const PointCloud& pc,
95  {
96  return LeastSquaresFit(pc, begin, end);
97  }
98 
99  bool LeastSquaresFit(const PointCloud& pc,
102  template <class IteratorT>
103  bool LeastSquaresFit(IteratorT begin, IteratorT end);
104  static bool Interpolate(const MiscLib::Vector<Plane>& planes,
105  const MiscLib::Vector<float>& weights,
106  Plane* ip);
107  void Serialize(bool binary, std::ostream* o) const;
108  static size_t SerializedSize();
109  void Serialize(FILE* o) const;
110  void Serialize(float* array) const;
111  static size_t SerializedFloatSize();
112 
113  void Transform(float scale, const Vec3f& translate);
114  float Intersect(const Vec3f& p, const Vec3f& r) const;
115 
116 protected:
119  float m_dist;
120 };
121 
122 template <class IteratorT>
123 bool
124 Plane::LeastSquaresFit(IteratorT begin, IteratorT end)
125 {
128  GfxTL::Mean(begin, end, &mean);
129  pl.Fit(mean, begin, end);
130  *this = Plane(Vec3f(mean.Data()), Vec3f(pl.Normal().Data()));
131  return true;
132 }
133 
134 #endif //_PLANE_H_
Plane::SignedDistToOrigin
float SignedDistToOrigin() const
Definition: Plane.h:86
Plane::Normal
void Normal(const Vec3f &, Vec3f *n) const
Definition: Plane.h:59
GfxTL::VectorXD
Definition: MatrixXX.h:24
GfxTL::Vec3f
VectorXD< 3, float > Vec3f
Definition: VectorXD.h:733
GfxTL::Plane
Definition: Plane.h:14
Vector.h
Vec3f
Definition: basic.h:17
Plane::LeastSquaresFit
bool LeastSquaresFit(const PointCloud &pc, MiscLib::Vector< size_t >::const_iterator begin, MiscLib::Vector< size_t >::const_iterator end)
Definition: Plane.cpp:200
magic_enum::detail::n
constexpr auto n() noexcept
Definition: magic_enum.hpp:418
Plane.h
MiscLib::Vector
Definition: Vector.h:19
GfxTL::Plane::Normal
void Normal(PointType *normal) const
Definition: Plane.hpp:48
Plane::Plane
Plane()
Definition: Plane.h:26
NoShrinkVector.h
Plane::getPosition
const Vec3f & getPosition() const
Definition: Plane.h:78
armarx::abs
std::vector< T > abs(const std::vector< T > &v)
Definition: VectorHelpers.h:281
GfxTL::Mean
void Mean(PointsForwardIt begin, PointsForwardIt end, WeightsForwardIt weights, PointT *mean)
Definition: Mean.h:14
Plane::DistanceAndNormal
float DistanceAndNormal(const Vec3f &pos, Vec3f *n) const
Definition: Plane.h:65
armarx::mean
std::optional< float > mean(const boost::circular_buffer< NameValueMap > &buffer, const std::string &key)
Definition: KinematicUnitGuiPlugin.cpp:1620
Plane::Distance
float Distance(const Vec3f &pos) const
Definition: Plane.h:47
Plane::m_pos
Vec3f m_pos
Definition: Plane.h:118
Plane::Fit
bool Fit(const PointCloud &pc, MiscLib::Vector< size_t >::const_iterator begin, MiscLib::Vector< size_t >::const_iterator end)
Definition: Plane.h:92
PointCloud
Definition: PointCloud.h:85
Plane::m_normal
Vec3f m_normal
Definition: Plane.h:117
Plane::SignedDistance
float SignedDistance(const Vec3f &pos) const
Definition: Plane.h:53
Plane::getNormal
const Vec3f & getNormal() const
Definition: Plane.h:72
basic.h
PointCloud.h
Plane
Definition: Plane.h:18
DLL_LINKAGE
#define DLL_LINKAGE
Definition: basic.h:12
pc
Introduction Thank you for taking interest in our work and downloading this software This library implements the algorithm described in the paper R R R Klein Efficient RANSAC for Point Cloud Shape in Computer Graphics Blackwell June If you use this software you should cite the aforementioned paper in any resulting publication Please send comments or bug reports to Ruwen Roland BUT NOT LIMITED THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY OR CONSEQUENTIAL WHETHER IN STRICT OR EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE Example usage This section shows how to use the library to detect the shapes in a point cloud PointCloud pc
Definition: ReadMe.txt:68
Plane::m_dist
float m_dist
Definition: Plane.h:119
Plane::getDistance
float getDistance(const Vec3f &pos) const
Definition: Plane.h:41
GfxTL::Plane::Fit
bool Fit(const PointType &origin, PointsForwardIt begin, PointsForwardIt end, WeightsForwardIt weights)
Definition: Plane.h:71