BasePrimitiveShape.h
Go to the documentation of this file.
1 #ifndef BASEPRIMITIVESHAPE_HEADER
2 #define BASEPRIMITIVESHAPE_HEADER
3 #include "PrimitiveShape.h"
4 #include "ScoreComputer.h"
5 #include <MiscLib/Random.h>
6 #include <GfxTL/MathHelper.h>
7 
8 #ifndef DLL_LINKAGE
9 #define DLL_LINKAGE
10 #endif
11 
13  : public PrimitiveShape
14 {
15 protected:
16  template< class ShapeT >
17  unsigned int ConfidenceTests(unsigned int numTests, float epsilon,
18  float normalThresh, float rms, const PointCloud& pc,
20  {
21  unsigned int numFailures = 0;
22  // estimate shapes
23  const unsigned int numSamples = ShapeT::RequiredSamples;
24  if (numSamples >= indices.size())
25  {
26  return numTests;
27  }
29  for (unsigned int i = 0; i < numTests; ++i)
30  {
31  MiscLib::Vector< size_t > sampleIndices;
32  for (unsigned int j = 0; j < numSamples; ++j)
33  {
34  size_t idx;
35  do
36  {
37  idx = indices[MiscLib::rn_rand() % indices.size()];
38  }
39  while (std::find(sampleIndices.begin(), sampleIndices.end(), idx)
40  != sampleIndices.end());
41  sampleIndices.push_back(idx);
42  }
43  MiscLib::Vector< Vec3f > samples(numSamples << 1);
44  for (unsigned int j = 0; j < numSamples; ++j)
45  {
46  samples[j] = pc[sampleIndices[j]].pos;
47  samples[j + numSamples] = pc[sampleIndices[j]].normal;
48  }
49  ShapeT shape;
50  if (shape.Init(samples))
51  {
52  shapes.push_back(shape);
53  }
54  else
55  {
56  ++numFailures;
57  }
58  }
59 
60  MiscLib::Vector< size_t > scores(shapes.size(), 0);
61  //MiscLib::Vector< float > sse(shapes.size(), 0.f);
62  Vec3f n;
63  for (size_t i = 0; i < indices.size(); ++i)
64  {
65  for (size_t j = 0; j < shapes.size(); ++j)
66  {
67  //float d = shapes[j].Distance(pc[indices[i]].pos);
68  //sse[j] += d * d;
69  float d = shapes[j].DistanceAndNormal(pc[indices[i]].pos, &n);
70  if (d > epsilon)
71  {
72  continue;
73  }
74  float dn = n.dot(pc[indices[i]].normal);
75  if (abs(dn) > normalThresh)
76  {
77  ++scores[j];
78  }
79  }
80  }
81 
82  for (size_t i = 0; i < /*sse.size()*/scores.size(); ++i)
83  {
84  if (scores[i] < .9f * indices.size())
85  //if(abs(std::sqrt(sse[i] / indices.size()) - rms) > 1e-2)
86  {
87  ++numFailures;
88  }
89  }
90 
91  return numFailures;
92  }
93 };
94 
95 #endif
MiscLib::Vector::begin
T * begin()
Definition: Vector.h:460
Vec3f
Definition: basic.h:16
MiscLib::Vector::push_back
void push_back(const T &v)
Definition: Vector.h:346
PrimitiveShape
PrimtiveShape is a shape primitive in conjunction with a parametrization.
Definition: PrimitiveShape.h:32
Point::normal
Vec3f normal
Definition: PointCloud.h:27
BasePrimitiveShape
Definition: BasePrimitiveShape.h:12
MiscLib::Vector< size_t >
MiscLib::Vector::size
size_type size() const
Definition: Vector.h:212
MiscLib::rn_rand
size_t rn_rand()
Definition: Random.h:20
armarx::abs
std::vector< T > abs(const std::vector< T > &v)
Definition: VectorHelpers.h:253
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
MiscLib::Vector::end
T * end()
Definition: Vector.h:470
Point::pos
Vec3f pos
Definition: PointCloud.h:26
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
PointCloud
Definition: PointCloud.h:69
Vec3f::dot
float dot(const Vec3f &v) const
Definition: basic.h:92
Random.h
DLL_LINKAGE
#define DLL_LINKAGE
Definition: basic.h:11
ScoreComputer.h
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
MathHelper.h
shapes
MiscLib::Vector< std::pair< MiscLib::RefCountPtr< PrimitiveShape >, size_t > > shapes
Definition: ReadMe.txt:92
PrimitiveShape.h