RansacShapeDetector.h
Go to the documentation of this file.
1 #ifndef RANSACSHAPEDETECTOR_HEADER
2 #define RANSACSHAPEDETECTOR_HEADER
3 #include "PointCloud.h"
5 #include <MiscLib/Vector.h>
7 #include <utility>
8 #include "Candidate.h"
9 #include <MiscLib/RefCountPtr.h>
10 #include "Octree.h"
11 #include <GfxTL/NullClass.h>
13 #include <chrono>
14 
15 #ifndef DLL_LINKAGE
16 #define DLL_LINKAGE
17 #endif
18 
20 {
21 public:
22  struct Options
23  {
24  static constexpr auto invalidRuntime = std::numeric_limits<std::chrono::milliseconds::rep>::max();
26  : m_epsilon(0.01f)
27  , m_normalThresh(0.95f)
28  , m_minSupport(100)
29  , m_bitmapEpsilon(0.01f)
30  , m_fitting(LS_FITTING)
31  , m_probability(0.001f)
32  , m_maxruntime(invalidRuntime)
33  {}
34  float m_epsilon;
36  unsigned int m_minSupport;
38  enum { NO_FITTING, LS_FITTING } m_fitting;
40  std::chrono::milliseconds m_maxruntime;
41  };
43  RansacShapeDetector(const Options& options);
44  virtual ~RansacShapeDetector();
46  size_t Detect(PointCloud& pc, size_t begin, size_t end,
48  void AutoAcceptSize(size_t s)
49  {
50  m_autoAcceptSize = s;
51  }
52  size_t AutoAcceptSize() const
53  {
54  return m_autoAcceptSize;
55  }
56  const Options& GetOptions() const
57  {
58  return m_options;
59  }
60 
61 private:
62  typedef MiscLib::Vector< PrimitiveShapeConstructor* > ConstructorsType;
63  typedef MiscLib::NoShrinkVector< Candidate > CandidatesType;
64  bool DrawSamplesStratified(const IndexedOctreeType& oct,
65  size_t numSamples, size_t depth,
66  const MiscLib::Vector< int >& shapeIndex,
68  const IndexedOctreeType::CellType** node) const;
69  PrimitiveShape* Fit(bool allowDifferentShapes,
70  const PrimitiveShape& initialShape, const PointCloud& pc,
73  std::pair< size_t, float >* score) const;
74  float CandidateFailureProbability(float candidateSize,
75  float numberOfPoints, float drawnCandidates, float levels) const
76  {
77  return std::min(std::pow(1.f - candidateSize
78  / (numberOfPoints * levels * (1 << (m_reqSamples - 1))),
79  drawnCandidates), 1.f);
80  }
81  float UpdateAcceptedFailureProbability(
82  float currentFailureProbability, size_t numTries) const
83  {
84  //currentFailureProbability *= 1.1f;//1.61;/*powf(1.05, 1<<numTries);*/ //1.1f;
85  if (currentFailureProbability > 1.f)
86  {
87  currentFailureProbability = 1.f;
88  }
89  return currentFailureProbability;
90  }
91  template< class ScoreVisitorT >
92  void GenerateCandidates(
93  const IndexedOctreeType& globalOctTree,
95  const PointCloud& pc, ScoreVisitorT& scoreVisitor,
96  size_t currentSize, size_t numInvalid,
97  const MiscLib::Vector< double >& sampleLevelProbSum,
98  size_t* drawnCandidates,
99  MiscLib::Vector< std::pair< float, size_t > >* sampleLevelScores,
100  float* bestExpectedValue,
101  CandidatesType* candidates) const;
102  template< class ScoreVisitorT >
103  bool FindBestCandidate(CandidatesType& candidates,
105  const PointCloud& pc, ScoreVisitorT& scoreVisitor,
106  size_t currentSize, size_t drawnCandidates,
107  size_t numInvalid, size_t minSize, float numLevels,
108  float* maxForgottenCandidate, float* candidateFailProb) const;
109  size_t StatBucket(float score) const;
110  void UpdateLevelWeights(float factor,
111  const MiscLib::Vector< std::pair< float, size_t > >& levelScores,
112  MiscLib::Vector< double >* sampleLevelProbability) const;
113 private:
114  ConstructorsType m_constructors;
115  Options m_options;
116  size_t m_maxCandTries;
117  size_t m_reqSamples;
118  size_t m_autoAcceptSize;
119 };
120 
121 #endif
PrimitiveShapeConstructor.h
Vector.h
RansacShapeDetector::GetOptions
const Options & GetOptions() const
Definition: RansacShapeDetector.h:56
PrimitiveShape
PrimtiveShape is a shape primitive in conjunction with a parametrization.
Definition: PrimitiveShape.h:32
c
constexpr T c
Definition: UnscentedKalmanFilterTest.cpp:43
RansacShapeDetector::Options::m_bitmapEpsilon
float m_bitmapEpsilon
Definition: RansacShapeDetector.h:37
RansacShapeDetector::AutoAcceptSize
void AutoAcceptSize(size_t s)
Definition: RansacShapeDetector.h:48
m_normalThresh
ransacOptions m_normalThresh
Definition: ReadMe.txt:79
MiscLib::Vector
Definition: Vector.h:19
PrimitiveShapeConstructor
Definition: PrimitiveShapeConstructor.h:22
RansacShapeDetector::Options::m_normalThresh
float m_normalThresh
Definition: RansacShapeDetector.h:35
MiscLib::NoShrinkVector
Definition: NoShrinkVector.h:17
NoShrinkVector.h
RefCountPtr.h
RansacShapeDetector
Definition: RansacShapeDetector.h:19
m_minSupport
ransacOptions m_minSupport
Definition: ReadMe.txt:80
ImmediateTreeDataKernels.h
RansacShapeDetector::Options
Definition: RansacShapeDetector.h:22
RansacShapeDetector::Options::NO_FITTING
@ NO_FITTING
Definition: RansacShapeDetector.h:38
max
T max(T t1, T t2)
Definition: gdiam.h:48
MiscLib::RefCountPtr< PrimitiveShape >
RansacShapeDetector::Options::m_probability
float m_probability
Definition: RansacShapeDetector.h:39
PointCloud
Definition: PointCloud.h:69
RansacShapeDetector::Options::m_minSupport
unsigned int m_minSupport
Definition: RansacShapeDetector.h:36
m_probability
ransacOptoins m_probability
Definition: ReadMe.txt:81
GfxTL::AACubeTreeCell
Definition: AACubeTree.h:14
m_bitmapEpsilon
ransacOptions m_bitmapEpsilon
Definition: ReadMe.txt:77
RansacShapeDetector::Options::m_maxruntime
std::chrono::milliseconds m_maxruntime
Definition: RansacShapeDetector.h:40
RansacShapeDetector::Options::m_epsilon
float m_epsilon
Definition: RansacShapeDetector.h:34
NullClass.h
RansacShapeDetector::AutoAcceptSize
size_t AutoAcceptSize() const
Definition: RansacShapeDetector.h:52
PointCloud.h
DLL_LINKAGE
#define DLL_LINKAGE
Definition: basic.h:11
Octree.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
min
T min(T t1, T t2)
Definition: gdiam.h:42
Candidate.h
RansacShapeDetector::Options::Options
Options()
Definition: RansacShapeDetector.h:25
shapes
MiscLib::Vector< std::pair< MiscLib::RefCountPtr< PrimitiveShape >, size_t > > shapes
Definition: ReadMe.txt:92
m_epsilon
ransacOptions m_epsilon
Definition: ReadMe.txt:75
armarx::ctrlutil::s
double s(double t, double s0, double v0, double a0, double j)
Definition: CtrlUtil.h:33
Add
detector Add(new PlanePrimitiveShapeConstructor())
GfxTL::AACubeTree
Definition: AACubeTree.h:287