Plane.h
Go to the documentation of this file.
1 #ifndef _PLANE_H_
2 #define _PLANE_H_
3 #include "basic.h"
4 #include <MiscLib/Vector.h>
5 #include "PointCloud.h"
6 #include <ostream>
7 #include <istream>
8 #include <stdio.h>
10 #include <GfxTL/Plane.h>
11 
12 #ifndef DLL_LINKAGE
13 #define DLL_LINKAGE
14 #endif
15 
17 {
18 public:
19  enum { RequiredSamples = 1 };
20  Plane() {}
21  Plane(Vec3f p1, Vec3f p2, Vec3f p3);
22  Plane(Vec3f p1, Vec3f normal);
23  virtual ~Plane();
24  bool Init(Vec3f p1, Vec3f p2, Vec3f p3);
25  bool Init(const MiscLib::Vector< Vec3f >& samples);
26  bool InitAverage(const MiscLib::Vector< Vec3f >& samples);
27  bool Init(bool binary, std::istream* i);
28  void Init(FILE* i);
29  void Init(float* array);
30  float getDistance(const Vec3f& pos) const
31  {
32  return abs(m_dist - m_normal.dot(pos));
33  }
34  float Distance(const Vec3f& pos) const
35  {
36  return abs(m_dist - m_normal.dot(pos));
37  }
38  float SignedDistance(const Vec3f& pos) const
39  {
40  return m_normal.dot(pos) - m_dist;
41  }
42  void Normal(const Vec3f&, Vec3f* n) const
43  {
44  *n = m_normal;
45  }
46  float DistanceAndNormal(const Vec3f& pos, Vec3f* n) const
47  {
48  *n = m_normal;
49  return Distance(pos);
50  }
51  const Vec3f& getNormal() const
52  {
53  return m_normal;
54  }
55  const Vec3f& getPosition() const
56  {
57  return m_pos;
58  }
59  bool equals(Plane plane);
60  float SignedDistToOrigin() const
61  {
62  return m_dist;
63  }
64  bool Fit(const PointCloud& pc,
67  {
68  return LeastSquaresFit(pc, begin, end);
69  }
70  bool LeastSquaresFit(const PointCloud& pc,
73  template< class IteratorT >
74  bool LeastSquaresFit(IteratorT begin, IteratorT end);
75  static bool Interpolate(const MiscLib::Vector< Plane >& planes,
76  const MiscLib::Vector< float >& weights, Plane* ip);
77  void Serialize(bool binary, std::ostream* o) const;
78  static size_t SerializedSize();
79  void Serialize(FILE* o) const;
80  void Serialize(float* array) const;
81  static size_t SerializedFloatSize();
82 
83  void Transform(float scale, const Vec3f& translate);
84  float Intersect(const Vec3f& p, const Vec3f& r) const;
85 
86 protected:
89  float m_dist;
90 };
91 
92 template< class IteratorT >
93 bool Plane::LeastSquaresFit(IteratorT begin, IteratorT end)
94 {
97  GfxTL::Mean(begin, end, &mean);
98  pl.Fit(mean, begin, end);
99  *this = Plane(Vec3f(mean.Data()), Vec3f(pl.Normal().Data()));
100  return true;
101 }
102 
103 #endif //_PLANE_H_
Plane::SignedDistToOrigin
float SignedDistToOrigin() const
Definition: Plane.h:60
Plane::Normal
void Normal(const Vec3f &, Vec3f *n) const
Definition: Plane.h:42
GfxTL::VectorXD
Definition: MatrixXX.h:21
GfxTL::Plane
Definition: Plane.h:14
Vector.h
Vec3f
Definition: basic.h:16
Plane::LeastSquaresFit
bool LeastSquaresFit(const PointCloud &pc, MiscLib::Vector< size_t >::const_iterator begin, MiscLib::Vector< size_t >::const_iterator end)
Definition: Plane.cpp:179
Plane.h
MiscLib::Vector
Definition: Vector.h:19
GfxTL::Plane::Normal
void Normal(PointType *normal) const
Definition: Plane.hpp:44
Plane::Plane
Plane()
Definition: Plane.h:20
NoShrinkVector.h
Plane::getPosition
const Vec3f & getPosition() const
Definition: Plane.h:55
armarx::abs
std::vector< T > abs(const std::vector< T > &v)
Definition: VectorHelpers.h:253
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:46
armarx::mean
std::optional< float > mean(const boost::circular_buffer< NameValueMap > &buffer, const std::string &key)
Definition: KinematicUnitGuiPlugin.cpp:1615
Plane::Distance
float Distance(const Vec3f &pos) const
Definition: Plane.h:34
Plane::m_pos
Vec3f m_pos
Definition: Plane.h:88
Plane::Fit
bool Fit(const PointCloud &pc, MiscLib::Vector< size_t >::const_iterator begin, MiscLib::Vector< size_t >::const_iterator end)
Definition: Plane.h:64
PointCloud
Definition: PointCloud.h:69
Plane::m_normal
Vec3f m_normal
Definition: Plane.h:87
Plane::SignedDistance
float SignedDistance(const Vec3f &pos) const
Definition: Plane.h:38
Plane::getNormal
const Vec3f & getNormal() const
Definition: Plane.h:51
basic.h
PointCloud.h
Plane
Definition: Plane.h:16
DLL_LINKAGE
#define DLL_LINKAGE
Definition: basic.h:11
GfxTL::Vec3f
VectorXD< 3, float > Vec3f
Definition: VectorXD.h:691
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:89
Plane::getDistance
float getDistance(const Vec3f &pos) const
Definition: Plane.h:30
GfxTL::Plane::Fit
bool Fit(const PointType &origin, PointsForwardIt begin, PointsForwardIt end, WeightsForwardIt weights)
Definition: Plane.h:64