SpherePrimitiveShape.h
Go to the documentation of this file.
1 #ifndef SPHEREPRIMITIVESHAPE_HEADER
2 #define SPHEREPRIMITIVESHAPE_HEADER
3 #include "BitmapPrimitiveShape.h"
4 #include "Sphere.h"
5 #include <GfxTL/AABox.h>
6 #include "LevMarFunc.h"
7 #include <istream>
8 #include <GfxTL/MathHelper.h>
10 #include <GfxTL/Mean.h>
11 #include <GfxTL/Covariance.h>
12 #include <GfxTL/Jacobi.h>
14 
15 #ifndef DLL_LINKAGE
16 #define DLL_LINKAGE
17 #endif
18 
20  : public BitmapPrimitiveShape
21 {
22 public:
24  SpherePrimitiveShape() : m_parametrization(m_sphere) {}
27  size_t Identifier() const;
28  unsigned int RequiredSamples() const
29  {
31  }
32  bool Init(bool binary, std::istream* i);
33  PrimitiveShape* Clone() const;
34  float Distance(const Vec3f& p) const;
35  float SignedDistance(const Vec3f& p) const;
36  float NormalDeviation(const Vec3f& p, const Vec3f& n) const;
37  void DistanceAndNormalDeviation(const Vec3f& p, const Vec3f& n,
38  std::pair< float, float >* dn) const;
39  void Project(const Vec3f& p, Vec3f* pp) const;
40  void Normal(const Vec3f& p, Vec3f* n) const;
41  unsigned int ConfidenceTests(unsigned int numTests, float epsilon,
42  float normalThresh, float rms, const PointCloud& pc,
43  const MiscLib::Vector< size_t >& indices) const;
44  void Description(std::string* s) const;
45  bool Fit(const PointCloud& pc, float epsilon, float normalThresh,
48  PrimitiveShape* LSFit(const PointCloud& pc, float epsilon,
49  float normalThresh,
52  std::pair< size_t, float >* score) const;
54  void Serialize(std::ostream* o, bool binary = true) const;
55  void Deserialize(std::istream* i, bool binary);
56  size_t SerializedSize() const;
57  virtual void Serialize(float* array) const
58  {
59  m_sphere.Serialize(array);
60  }
61  virtual size_t SerializedFloatSize() const
62  {
63  return m_sphere.SerializedFloatSize();
64  }
65 
66  void Transform(float scale, const Vec3f& translate);
67  void Visit(PrimitiveShapeVisitor* visitor) const;
70  MiscLib::Vector< size_t >::const_iterator end, float distThresh,
76  size_t begin, size_t end, float epsilon);
77  bool Similar(float tolerance, const SpherePrimitiveShape& shape) const;
78  const Sphere& Internal() const
79  {
80  return m_sphere;
81  }
82 
83  // implementation of bitmap primitive shape
84  void Parameters(const Vec3f& p,
85  std::pair< float, float >* param) const;
90  MiscLib::Vector< std::pair< float, float > >* bmpParams) const;
95  MiscLib::Vector< std::pair< float, float > >* bmpParams) const;
96  bool InSpace(float u, float v, Vec3f* p, Vec3f* n) const;
97  void BitmapExtent(float epsilon,
99  MiscLib::Vector< std::pair< float, float > >* params,
100  size_t* uextent, size_t* vextent);
101  void InBitmap(const std::pair< float, float >& param,
102  float epsilon, const GfxTL::AABox< GfxTL::Vector2Df >& bbox,
103  size_t uextent, size_t vextent,
104  std::pair< int, int >* inBmp) const;
106  float epsilon, bool* uwrap, bool* vwrap) const;
108  float epsilon, size_t uextent, size_t vextent,
109  MiscLib::Vector< int >* componentImg,
110  MiscLib::Vector< std::pair< int, size_t > >* labels) const;
111  bool InSpace(size_t u, size_t v, float epsilon,
112  const GfxTL::AABox< GfxTL::Vector2Df >& bbox, size_t uextent,
113  size_t vextent, Vec3f* p, Vec3f* n) const;
114 
115 private:
116  template< class IteratorT >
117  void ParametersImpl(IteratorT begin, IteratorT end,
118  MiscLib::Vector< std::pair< float, float > >* bmpParams) const;
119 
120 private:
121  Sphere m_sphere;
122  ParametrizationType m_parametrization;
123 };
124 
125 template< class IteratorT >
126 void SpherePrimitiveShape::ParametersImpl(IteratorT begin, IteratorT end,
127  MiscLib::Vector< std::pair< float, float > >* bmpParams) const
128 {
129  bmpParams->resize(end - begin);
130  size_t j = 0;
131  for (IteratorT i = begin; i != end; ++i, ++j)
132  {
133  m_parametrization.Parameters(*i, &(*bmpParams)[j]);
134  }
135 }
136 
138  : public LevMarFunc< float >
139 {
140 public:
142  : m_sphere(s)
143  {}
144 
145  float operator()(const float* x) const
146  {
147  return m_sphere.SignedDistance(*((const Vec3f*)x));
148  }
149 
150  void operator()(const float* x, float* gradient) const
151  {
152  m_sphere.Normal(*((const Vec3f*)x), (Vec3f*)gradient);
153  }
154 
155 private:
156  Sphere m_sphere;
157 };
158 
159 #endif
GfxTL::IndexedIterator
Definition: IndexedIterator.h:8
Sphere::RequiredSamples
@ RequiredSamples
Definition: Sphere.h:30
LevMarFunc< float >
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
SphereLevMarFunc
Definition: SpherePrimitiveShape.h:137
Sphere.h
Mean.h
Vec3f
Definition: basic.h:16
SpherePrimitiveShape::SpherePrimitiveShape
SpherePrimitiveShape()
Definition: SpherePrimitiveShape.h:24
PrimitiveShape::SignedDistance
virtual float SignedDistance(const Vec3f &p) const =0
SphereLevMarFunc::operator()
void operator()(const float *x, float *gradient) const
Definition: SpherePrimitiveShape.h:150
BitmapPrimitiveShape
Definition: BitmapPrimitiveShape.h:30
SphereLevMarFunc::SphereLevMarFunc
SphereLevMarFunc(const Sphere &s)
Definition: SpherePrimitiveShape.h:141
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
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
PrimitiveShape::Distance
virtual float Distance(const Vec3f &p) const =0
MiscLib::Vector< size_t >
PrimitiveShape::SerializedSize
virtual size_t SerializedSize() const =0
SpherePrimitiveShape::RequiredSamples
unsigned int RequiredSamples() const
Definition: SpherePrimitiveShape.h:28
LevMarFunc.h
MiscLib::Vector< Point >::const_iterator
const typedef Point * const_iterator
Definition: Vector.h:26
LowStretchSphereParametrization.h
PrimitiveShape::Description
virtual void Description(std::string *s) const =0
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
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
PrimitiveShapeVisitor
Definition: PrimitiveShapeVisitor.h:14
PrimitiveShape::OptimizeParametrization
virtual void OptimizeParametrization(const PointCloud &pc, size_t begin, size_t end, float epsilon)
Definition: PrimitiveShape.h:97
LowStretchSphereParametrization
Definition: LowStretchSphereParametrization.h:12
SpherePrimitiveShape::Internal
const Sphere & Internal() const
Definition: SpherePrimitiveShape.h:78
SpherePrimitiveShape
class DLL_LINKAGE SpherePrimitiveShape
Definition: PrimitiveShapeVisitor.h:9
AABox.h
Covariance.h
BitmapPrimitiveShape::Init
bool Init(bool binary, std::istream *i)
Definition: BitmapPrimitiveShape.cpp:28
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
MiscLib::RefCountPtr< PrimitiveShape >
SpherePrimitiveShape::Serialize
virtual void Serialize(float *array) const
Definition: SpherePrimitiveShape.h:57
IndexedIterator.h
PointCloud
Definition: PointCloud.h:69
armarx::ctrlutil::v
double v(double t, double v0, double a0, double j)
Definition: CtrlUtil.h:39
Jacobi.h
BitmapPrimitiveShape::Parameters
virtual void Parameters(const Vec3f &p, std::pair< float, float > *param) const =0
SpherePrimitiveShape::SerializedFloatSize
virtual size_t SerializedFloatSize() const
Definition: SpherePrimitiveShape.h:61
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
SphereLevMarFunc::operator()
float operator()(const float *x) const
Definition: SpherePrimitiveShape.h:145
SpherePrimitiveShape::ParametrizationType
LowStretchSphereParametrization ParametrizationType
Definition: SpherePrimitiveShape.h:23
Sphere
Definition: Sphere.h:27
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
SpherePrimitiveShape
Definition: SpherePrimitiveShape.h:19
MathHelper.h
LowStretchSphereParametrization::Parameters
void Parameters(const Vec3f &p, std::pair< float, float > *param) const
Definition: LowStretchSphereParametrization.h:46
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
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