ConePrimitiveShape.h
Go to the documentation of this file.
1 #ifndef CONEPRIMITIVESHAPE_HEADER
2 #define CONEPRIMITIVESHAPE_HEADER
3 #include "BitmapPrimitiveShape.h"
4 #include "Cone.h"
5 #include "LevMarFunc.h"
6 
7 #ifndef DLL_LINKAGE
8 #define DLL_LINKAGE
9 #endif
10 
12  : public BitmapPrimitiveShape
13 {
14 public:
15  size_t Identifier() const;
16  unsigned int RequiredSamples() const
17  {
18  return Cone::RequiredSamples;
19  }
20  ConePrimitiveShape(const Cone& cone);
21  PrimitiveShape* Clone() const;
22  float Distance(const Vec3f& p) const;
23  float SignedDistance(const Vec3f& p) const;
24  float NormalDeviation(const Vec3f& p, const Vec3f& n) const;
25  void DistanceAndNormalDeviation(const Vec3f& p,
26  const Vec3f& n, std::pair< float, float >* dn) const;
27  void Project(const Vec3f& p, Vec3f* pp) const;
28  void Normal(const Vec3f& p, Vec3f* n) const;
29  unsigned int ConfidenceTests(unsigned int numTests, float epsilon,
30  float normalThresh, float rms, const PointCloud& pc,
31  const MiscLib::Vector< size_t >& indices) const;
32  void Description(std::string* s) const;
33  bool Fit(const PointCloud& pc, float epsilon, float normalThresh,
36  PrimitiveShape* LSFit(const PointCloud& pc, float epsilon,
37  float normalThresh,
40  std::pair< size_t, float >* score) const;
42  void Serialize(std::ostream* o, bool binary = true) const;
43  size_t SerializedSize() const;
44  virtual void Serialize(float* array) const
45  {
46  m_cone.Serialize(array);
47  }
48  virtual size_t SerializedFloatSize() const
49  {
50  return m_cone.SerializedFloatSize();
51  }
52  void Transform(float scale, const Vec3f& translate);
54  const GfxTL::Vector3Df& trans);
55  void Visit(PrimitiveShapeVisitor* visitor) const;
58  MiscLib::Vector< size_t >::const_iterator end, float distThresh,
60  bool Similar(float tolerance, const ConePrimitiveShape& shape) const;
61  const Cone& Internal() const
62  {
63  return m_cone;
64  }
65 
66  void Parameters(const Vec3f& p,
67  std::pair< float, float >* param) const;
72  MiscLib::Vector< std::pair< float, float > >* bmpParams) const;
77  MiscLib::Vector< std::pair< float, float > >* bmpParams) const;
78  bool InSpace(float u, float v, Vec3f* p, Vec3f* n) const;
79  void BitmapExtent(float epsilon,
81  MiscLib::Vector< std::pair< float, float > >* params,
82  size_t* uextent, size_t* vextent);
83  void InBitmap(const std::pair< float, float >& param, float epsilon,
84  const GfxTL::AABox< GfxTL::Vector2Df >& bbox, size_t uextent,
85  size_t vextent, std::pair< int, int >* inBmp) const;
87  float epsilon, size_t uextent, size_t vextent,
88  MiscLib::Vector< char >* bmp) const;
90  float epsilon, bool* uwrap, bool* vwrap) const;
92  float epsilon, size_t uextent, size_t vextent,
93  MiscLib::Vector< int >* componentImg,
94  MiscLib::Vector< std::pair< int, size_t > >* labels) const;
95  void SetExtent(const GfxTL::AABox< GfxTL::Vector2Df >& bbox,
96  const MiscLib::Vector< int >& componentsImg, size_t uextent,
97  size_t vextent, float epsilon, int label);
98  void SetExtent(const GfxTL::AABox< GfxTL::Vector2Df >& bbox);
99  bool InSpace(size_t u, size_t v, float epsilon,
100  const GfxTL::AABox< GfxTL::Vector2Df >& bbox, size_t uextent,
101  size_t vextent, Vec3f* p, Vec3f* n) const;
102 
103 private:
104  template< class IteratorT >
105  void ParametersImpl(IteratorT begin, IteratorT end,
106  MiscLib::Vector< std::pair< float, float > >* bmpParams) const;
107 
108 private:
109  Cone m_cone;
110 };
111 
112 template< class IteratorT >
113 void ConePrimitiveShape::ParametersImpl(IteratorT begin, IteratorT end,
114  MiscLib::Vector< std::pair< float, float > >* bmpParams) const
115 {
116  bmpParams->resize(end - begin);
117  size_t j = 0;
118  for (IteratorT i = begin; i != end; ++i, ++j)
119  {
120  m_cone.Parameters(*i, &(*bmpParams)[j]);
121  }
122  if (m_cone.Angle() < float(M_PI / 4)) // angle of cone less than 45 degrees
123  {
124  for (size_t j = 0; j < bmpParams->size(); ++j)
125  {
126  float r = m_cone.RadiusAtLength((*bmpParams)[j].first);
127  // convert to arc length and centralize
128  (*bmpParams)[j].second = ((*bmpParams)[j].second - float(M_PI)) * r;
129  }
130  }
131  else
132  {
133  for (size_t j = 0; j < bmpParams->size(); ++j)
134  {
135  float l = (*bmpParams)[j].first;
136  (*bmpParams)[j].first = std::sin((*bmpParams)[j].second) * l;
137  (*bmpParams)[j].second = std::cos((*bmpParams)[j].second) * l;
138  }
139  }
140 }
141 
143  : public LevMarFunc< float >
144 {
145 public:
147  : m_cone(c)
148  {}
149 
150  float operator()(const float* x) const
151  {
152  return m_cone.SignedDistance(*((const Vec3f*)x));
153  }
154 
155  void operator()(const float* x, float* gradient) const
156  {
157  m_cone.Normal(*((const Vec3f*)x), (Vec3f*)gradient);
158  }
159 
160 private:
161  Cone m_cone;
162 };
163 
164 #endif
GfxTL::IndexedIterator
Definition: IndexedIterator.h:8
LevMarFunc< float >
GfxTL::VectorXD
Definition: MatrixXX.h:21
PrimitiveShape::Identifier
virtual size_t Identifier() const =0
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
BitmapPrimitiveShape::PreWrapBitmap
virtual void PreWrapBitmap(const GfxTL::AABox< GfxTL::Vector2Df > &bbox, float epsilon, size_t uextent, size_t vextent, MiscLib::Vector< char > *bmp) const
Definition: BitmapPrimitiveShape.cpp:12
Cone::RequiredSamples
@ RequiredSamples
Definition: Cone.h:32
ConePrimitiveShape
Definition: ConePrimitiveShape.h:11
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
c
constexpr T c
Definition: UnscentedKalmanFilterTest.cpp:43
PrimitiveShape
PrimtiveShape is a shape primitive in conjunction with a parametrization.
Definition: PrimitiveShape.h:32
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
MiscLib::Vector< size_t >
PrimitiveShape::SerializedSize
virtual size_t SerializedSize() const =0
ConePrimitiveShape
class DLL_LINKAGE ConePrimitiveShape
Definition: PrimitiveShapeVisitor.h:11
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
ConePrimitiveShape::Internal
const Cone & Internal() const
Definition: ConePrimitiveShape.h:61
PrimitiveShape::SuggestSimplifications
virtual void SuggestSimplifications(const PointCloud &pc, MiscLib::Vector< size_t >::const_iterator begin, MiscLib::Vector< size_t >::const_iterator end, float distThresh, MiscLib::Vector< MiscLib::RefCountPtr< PrimitiveShape > > *suggestions) const
Definition: PrimitiveShape.h:93
PrimitiveShape::DistanceAndNormalDeviation
virtual void DistanceAndNormalDeviation(const Vec3f &p, const Vec3f &n, std::pair< float, float > *dn) const =0
M_PI
#define M_PI
Definition: MathTools.h:17
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
ConeLevMarFunc::operator()
void operator()(const float *x, float *gradient) const
Definition: ConePrimitiveShape.h:155
Cone
Definition: Cone.h:22
PrimitiveShapeVisitor
Definition: PrimitiveShapeVisitor.h:14
Cone.h
ConeLevMarFunc::operator()
float operator()(const float *x) const
Definition: ConePrimitiveShape.h:150
Cone::Parameters
void Parameters(const Vec3f &p, std::pair< float, float > *param) const
Definition: Cone.cpp:463
Cone::Angle
float Angle() const
Definition: Cone.h:351
ConeLevMarFunc
Definition: ConePrimitiveShape.h:142
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
Cone::RadiusAtLength
float RadiusAtLength(float length) const
Definition: Cone.h:371
MiscLib::RefCountPtr< PrimitiveShape >
ConePrimitiveShape::Serialize
virtual void Serialize(float *array) const
Definition: ConePrimitiveShape.h:44
PointCloud
Definition: PointCloud.h:69
ConePrimitiveShape::SerializedFloatSize
virtual size_t SerializedFloatSize() const
Definition: ConePrimitiveShape.h:48
armarx::ctrlutil::v
double v(double t, double v0, double a0, double j)
Definition: CtrlUtil.h:39
float
#define float
Definition: 16_Level.h:22
BitmapPrimitiveShape::Parameters
virtual void Parameters(const Vec3f &p, std::pair< float, float > *param) const =0
ConeLevMarFunc::ConeLevMarFunc
ConeLevMarFunc(const Cone &c)
Definition: ConePrimitiveShape.h:146
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
DLL_LINKAGE
#define DLL_LINKAGE
Definition: basic.h:11
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
BitmapPrimitiveShape::WrapComponents
virtual void WrapComponents(const GfxTL::AABox< GfxTL::Vector2Df > &bbox, float epsilon, size_t uextent, size_t vextent, MiscLib::Vector< int > *componentImg, MiscLib::Vector< std::pair< int, size_t > > *labels) const
Definition: BitmapPrimitiveShape.cpp:19
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
GfxTL::AABox
Definition: AABox.h:18
PrimitiveShape::SignedDistanceFunc
virtual LevMarFunc< float > * SignedDistanceFunc() const =0
ConePrimitiveShape::RequiredSamples
unsigned int RequiredSamples() const
Definition: ConePrimitiveShape.h:16
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