PlanePrimitiveShape.h
Go to the documentation of this file.
1 #ifndef PLANEPRIMITIVESHAPE_HEADER
2 #define PLANEPRIMITIVESHAPE_HEADER
3 #include "BitmapPrimitiveShape.h"
4 #include "Plane.h"
6 #include <GfxTL/AABox.h>
7 #include <GfxTL/MatrixXX.h>
8 #include <GfxTL/VectorXD.h>
9 #include "LevMarFunc.h"
10 
11 #ifndef DLL_LINKAGE
12 #define DLL_LINKAGE
13 #endif
14 
16  : public BitmapPrimitiveShape
17 {
18 public:
19  PlanePrimitiveShape(const Vec3f& a, const Vec3f& b, const Vec3f& c);
20  PlanePrimitiveShape(const Plane& plane);
21  size_t Identifier() const;
22  unsigned int RequiredSamples() const
23  {
25  }
26  PrimitiveShape* Clone() const;
27  float Distance(const Vec3f& p) const;
28  float SignedDistance(const Vec3f& p) const;
29  float NormalDeviation(const Vec3f& p, const Vec3f& n) const;
30  void DistanceAndNormalDeviation(const Vec3f& p, const Vec3f& n,
31  std::pair< float, float >* dn) const;
32  void Project(const Vec3f& p, Vec3f* pp) const;
33  void Normal(const Vec3f& p, Vec3f* n) const;
34  unsigned int ConfidenceTests(unsigned int numTests, float epsilon,
35  float normalThresh, float rms, const PointCloud& pc,
36  const MiscLib::Vector< size_t >& indices) const;
37  void Description(std::string* s) const;
38  bool Fit(const PointCloud& pc, float epsilon, float normalThresh,
41  PrimitiveShape* LSFit(const PointCloud& pc, float epsilon,
42  float normalThresh,
45  std::pair< size_t, float >* score) const;
47  void Serialize(std::ostream* o, bool binary = true) const;
48  size_t SerializedSize() const;
49  virtual void Serialize(float* array) const
50  {
51  m_plane.Serialize(array);
52  }
53  virtual size_t SerializedFloatSize() const
54  {
55  return m_plane.SerializedFloatSize();
56  }
57  void Transform(float scale, const Vec3f& translate);
59  const GfxTL::Vector3Df& trans);
60  void Visit(PrimitiveShapeVisitor* visitor) const;
61  bool Similar(float tolerance, const PlanePrimitiveShape&) const;
62  const Plane& Internal() const
63  {
64  return m_plane;
65  }
66 
67  void Parameters(const Vec3f& p,
68  std::pair< float, float >* param) const;
73  MiscLib::Vector< std::pair< float, float > >* bmpParams) const;
78  MiscLib::Vector< std::pair< float, float > >* bmpParams) const;
79  bool InSpace(float u, float v, Vec3f* p, Vec3f* n) const;
80  void BitmapExtent(float epsilon,
82  MiscLib::Vector< std::pair< float, float > >* params,
83  size_t* uextent, size_t* vextent);
84  void InBitmap(const std::pair< float, float >& param, float epsilon,
85  const GfxTL::AABox< GfxTL::Vector2Df >& bbox, size_t uextent,
86  size_t vextent, std::pair< int, int >* inBmp) const;
88  float epsilon, bool* uwrap, bool* vwrap) const;
89  void SetExtent(const GfxTL::AABox< GfxTL::Vector2Df >& bbox,
90  const MiscLib::Vector< int >& componentsImg, size_t uextent,
91  size_t vextent, float epsilon, int label);
92  bool InSpace(size_t u, size_t v, float epsilon,
93  const GfxTL::AABox< GfxTL::Vector2Df >& bbox, size_t uextent,
94  size_t vextent, Vec3f* p, Vec3f* n) const;
95 
96 private:
97  template< class IteratorT >
98  void ParametersImpl(IteratorT begin, IteratorT end,
99  MiscLib::Vector< std::pair< float, float > >* bmpParams) const;
100 
101 private:
102  Plane m_plane;
104 };
105 
106 template< class IteratorT >
107 void PlanePrimitiveShape::ParametersImpl(IteratorT begin, IteratorT end,
108  MiscLib::Vector< std::pair< float, float > >* bmpParams) const
109 {
110  bmpParams->resize(end - begin);
111  size_t j = 0;
112  for (IteratorT i = begin; i != end; ++i, ++j)
113  {
114  Vec3f pp = *i - m_plane.getPosition();
115  (*bmpParams)[j].first = pp.dot(m_hcs[0].Data());
116  (*bmpParams)[j].second = pp.dot(m_hcs[1].Data());
117  }
118 }
119 
121  : public LevMarFunc< float >
122 {
123 public:
124  PlaneLevMarFunc(const Plane& plane)
125  {
126  for (unsigned int i = 0; i < 3; ++i)
127  {
128  m_plane[i] = plane.getNormal()[i];
129  }
130  m_plane[3] = plane.SignedDistToOrigin();
131  }
132 
133  float operator()(const float* x) const
134  {
135  return m_plane[0] * x[0] + m_plane[1] * x[1] +
136  m_plane[2] * x[2] - m_plane[3];
137  }
138 
139  void operator()(const float* x, float* gradient) const
140  {
141  for (unsigned int i = 0; i < 3; ++i)
142  {
143  gradient[i] = m_plane[i];
144  }
145  }
146 
147 private:
148  GfxTL::Vector4Df m_plane;
149 };
150 
151 #endif
GfxTL::IndexedIterator
Definition: IndexedIterator.h:8
PlaneLevMarFunc
Definition: PlanePrimitiveShape.h:120
Plane::SignedDistToOrigin
float SignedDistToOrigin() const
Definition: Plane.h:60
GfxTL::HyperplaneCoordinateSystem< float, 3 >
LevMarFunc< float >
GfxTL::VectorXD
Definition: MatrixXX.h:21
PrimitiveShape::Identifier
virtual size_t Identifier() const =0
PlanePrimitiveShape::SerializedFloatSize
virtual size_t SerializedFloatSize() const
Definition: PlanePrimitiveShape.h:53
PrimitiveShape::Project
virtual void Project(const Vec3f &p, Vec3f *pp) const =0
PrimitiveShape::Fit
virtual bool Fit(const PointCloud &pc, float epsilon, float normalThresh, MiscLib::Vector< size_t >::const_iterator begin, MiscLib::Vector< size_t >::const_iterator end)=0
Vec3f
Definition: basic.h:16
PrimitiveShape::SignedDistance
virtual float SignedDistance(const Vec3f &p) const =0
BitmapPrimitiveShape
Definition: BitmapPrimitiveShape.h:30
BitmapPrimitiveShape::InSpace
virtual bool InSpace(float u, float v, Vec3f *p, Vec3f *n) const =0
PrimitiveShape
PrimtiveShape is a shape primitive in conjunction with a parametrization.
Definition: PrimitiveShape.h:32
c
constexpr T c
Definition: UnscentedKalmanFilterTest.cpp:43
PrimitiveShape::Normal
virtual void Normal(const Vec3f &p, Vec3f *n) const =0
PrimitiveShape::NormalDeviation
virtual float NormalDeviation(const Vec3f &p, const Vec3f &n) const =0
PrimitiveShape::LSFit
virtual PrimitiveShape * LSFit(const PointCloud &pc, float epsilon, float normalThresh, MiscLib::Vector< size_t >::const_iterator begin, MiscLib::Vector< size_t >::const_iterator end, std::pair< size_t, float > *score) const =0
GfxTL::MatrixXX
Definition: MatrixXX.h:25
PrimitiveShape::Distance
virtual float Distance(const Vec3f &p) const =0
PlaneLevMarFunc::operator()
void operator()(const float *x, float *gradient) const
Definition: PlanePrimitiveShape.h:139
MiscLib::Vector< size_t >
VectorXD.h
PrimitiveShape::SerializedSize
virtual size_t SerializedSize() const =0
Plane.h
LevMarFunc.h
MiscLib::Vector< Point >::const_iterator
const typedef Point * const_iterator
Definition: Vector.h:26
PrimitiveShape::Description
virtual void Description(std::string *s) const =0
Plane::getPosition
const Vec3f & getPosition() const
Definition: Plane.h:55
armarx::ctrlutil::a
double a(double t, double a0, double j)
Definition: CtrlUtil.h:45
PrimitiveShape::DistanceAndNormalDeviation
virtual void DistanceAndNormalDeviation(const Vec3f &p, const Vec3f &n, std::pair< float, float > *dn) const =0
pcl::graph::indices
pcl::PointIndices::Ptr indices(const PCG &g)
Retrieve the indices of the points of the point cloud stored in a point cloud graph that actually bel...
Definition: point_cloud_graph.h:737
PlanePrimitiveShape
Definition: PlanePrimitiveShape.h:15
PrimitiveShapeVisitor
Definition: PrimitiveShapeVisitor.h:14
PlanePrimitiveShape::Internal
const Plane & Internal() const
Definition: PlanePrimitiveShape.h:62
AABox.h
HyperplaneCoordinateSystem.h
BitmapPrimitiveShape.h
BasePrimitiveShape::ConfidenceTests
unsigned int ConfidenceTests(unsigned int numTests, float epsilon, float normalThresh, float rms, const PointCloud &pc, const MiscLib::Vector< size_t > &indices) const
Definition: BasePrimitiveShape.h:17
MatrixXX.h
PointCloud
Definition: PointCloud.h:69
armarx::ctrlutil::v
double v(double t, double v0, double a0, double j)
Definition: CtrlUtil.h:39
Vec3f::dot
float dot(const Vec3f &v) const
Definition: basic.h:92
Plane::getNormal
const Vec3f & getNormal() const
Definition: Plane.h:51
BitmapPrimitiveShape::Parameters
virtual void Parameters(const Vec3f &p, std::pair< float, float > *param) const =0
PlanePrimitiveShape::RequiredSamples
unsigned int RequiredSamples() const
Definition: PlanePrimitiveShape.h:22
BitmapPrimitiveShape::BitmapExtent
virtual void BitmapExtent(float epsilon, GfxTL::AABox< GfxTL::Vector2Df > *bbox, MiscLib::Vector< std::pair< float, float > > *params, size_t *uextent, size_t *vextent)=0
PlaneLevMarFunc::operator()
float operator()(const float *x) const
Definition: PlanePrimitiveShape.h:133
Plane
Definition: Plane.h:16
DLL_LINKAGE
#define DLL_LINKAGE
Definition: basic.h:11
Plane::RequiredSamples
@ RequiredSamples
Definition: Plane.h:19
BitmapPrimitiveShape::InBitmap
virtual void InBitmap(const std::pair< float, float > &param, float epsilon, const GfxTL::AABox< GfxTL::Vector2Df > &bbox, size_t uextent, size_t vextent, std::pair< int, int > *inBmp) const =0
PrimitiveShape::Transform
virtual void Transform(float scale, const Vec3f &translate)=0
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
PlaneLevMarFunc::PlaneLevMarFunc
PlaneLevMarFunc(const Plane &plane)
Definition: PlanePrimitiveShape.h:124
PrimitiveShape::Serialize
virtual void Serialize(std::ostream *o, bool binary=true) const =0
This is the one and only serialization function It stores all the parameters of the shape as well as ...
armarx::ctrlutil::s
double s(double t, double s0, double v0, double a0, double j)
Definition: CtrlUtil.h:33
IndexIterator
Definition: IndexIterator.h:9
PlanePrimitiveShape::Serialize
virtual void Serialize(float *array) const
Definition: PlanePrimitiveShape.h:49
GfxTL::AABox
Definition: AABox.h:18
PrimitiveShape::SignedDistanceFunc
virtual LevMarFunc< float > * SignedDistanceFunc() const =0
PlanePrimitiveShape
class DLL_LINKAGE PlanePrimitiveShape
Definition: PrimitiveShapeVisitor.h:8
BitmapPrimitiveShape::WrapBitmap
virtual void WrapBitmap(const GfxTL::AABox< GfxTL::Vector2Df > &bbox, float epsilon, bool *uwrap, bool *vwrap) const =0
PrimitiveShape::Clone
virtual PrimitiveShape * Clone() const =0
PrimitiveShape::Visit
virtual void Visit(PrimitiveShapeVisitor *visitor) const =0