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