RansacShapeDetector.h
Go to the documentation of this file.
1#ifndef RANSACSHAPEDETECTOR_HEADER
2#define RANSACSHAPEDETECTOR_HEADER
3#include <chrono>
4#include <utility>
5
6#include "Candidate.h"
7#include "Octree.h"
8#include "PointCloud.h"
11#include <GfxTL/NullClass.h>
13#include <MiscLib/RefCountPtr.h>
14#include <MiscLib/Vector.h>
15
16#ifndef DLL_LINKAGE
17#define DLL_LINKAGE
18#endif
19
21{
22public:
23 struct Options
24 {
25 static constexpr auto invalidRuntime =
26 std::numeric_limits<std::chrono::milliseconds::rep>::max();
27
29 m_epsilon(0.01f),
30 m_normalThresh(0.95f),
31 m_minSupport(100),
32 m_bitmapEpsilon(0.01f),
34 m_probability(0.001f),
36 {
37 }
38
39 float m_epsilon;
41 unsigned int m_minSupport;
43
44 enum
45 {
48 } m_fitting;
49
51 std::chrono::milliseconds m_maxruntime;
52 };
53
55 RansacShapeDetector(const Options& options);
56 virtual ~RansacShapeDetector();
58 size_t Detect(PointCloud& pc,
59 size_t begin,
60 size_t end,
61 MiscLib::Vector<std::pair<MiscLib::RefCountPtr<PrimitiveShape>, size_t>>* shapes);
62
63 void
65 {
66 m_autoAcceptSize = s;
67 }
68
69 size_t
71 {
72 return m_autoAcceptSize;
73 }
74
75 const Options&
76 GetOptions() const
77 {
78 return m_options;
79 }
80
81private:
82 typedef MiscLib::Vector<PrimitiveShapeConstructor*> ConstructorsType;
83 typedef MiscLib::NoShrinkVector<Candidate> CandidatesType;
84 bool DrawSamplesStratified(const IndexedOctreeType& oct,
85 size_t numSamples,
86 size_t depth,
87 const MiscLib::Vector<int>& shapeIndex,
89 const IndexedOctreeType::CellType** node) const;
90 PrimitiveShape* Fit(bool allowDifferentShapes,
91 const PrimitiveShape& initialShape,
92 const PointCloud& pc,
95 std::pair<size_t, float>* score) const;
96
97 float
98 CandidateFailureProbability(float candidateSize,
99 float numberOfPoints,
100 float drawnCandidates,
101 float levels) const
102 {
103 return std::min(
104 std::pow(1.f - candidateSize / (numberOfPoints * levels * (1 << (m_reqSamples - 1))),
105 drawnCandidates),
106 1.f);
107 }
108
109 float
110 UpdateAcceptedFailureProbability(float currentFailureProbability, size_t numTries) const
111 {
112 //currentFailureProbability *= 1.1f;//1.61;/*powf(1.05, 1<<numTries);*/ //1.1f;
113 if (currentFailureProbability > 1.f)
114 {
115 currentFailureProbability = 1.f;
116 }
117 return currentFailureProbability;
118 }
119 template <class ScoreVisitorT>
120 void GenerateCandidates(const IndexedOctreeType& globalOctTree,
121 const MiscLib::Vector<ImmediateOctreeType*>& octrees,
122 const PointCloud& pc,
123 ScoreVisitorT& scoreVisitor,
124 size_t currentSize,
125 size_t numInvalid,
126 const MiscLib::Vector<double>& sampleLevelProbSum,
127 size_t* drawnCandidates,
128 MiscLib::Vector<std::pair<float, size_t>>* sampleLevelScores,
129 float* bestExpectedValue,
130 CandidatesType* candidates) const;
131 template <class ScoreVisitorT>
132 bool FindBestCandidate(CandidatesType& candidates,
133 const MiscLib::Vector<ImmediateOctreeType*>& octrees,
134 const PointCloud& pc,
135 ScoreVisitorT& scoreVisitor,
136 size_t currentSize,
137 size_t drawnCandidates,
138 size_t numInvalid,
139 size_t minSize,
140 float numLevels,
141 float* maxForgottenCandidate,
142 float* candidateFailProb) const;
143 size_t StatBucket(float score) const;
144 void UpdateLevelWeights(float factor,
145 const MiscLib::Vector<std::pair<float, size_t>>& levelScores,
146 MiscLib::Vector<double>* sampleLevelProbability) const;
147
148private:
149 ConstructorsType m_constructors;
150 Options m_options;
151 size_t m_maxCandTries;
152 size_t m_reqSamples;
153 size_t m_autoAcceptSize;
154};
155
156#endif
GfxTL::AACubeTree< 3, ScoreAACubeTreeStrategy< 3, RebuildAACubeTreeStrategy< GfxTL::BucketSizeMaxLevelSubdivisionTreeStrategy< GfxTL::CellLevelTreeStrategy< GfxTL::CellCenterAACubeTreeStrategy< 3, GfxTL::BaseAACubeTreeStrategy< GfxTL::CellRangeDataTreeStrategy< GfxTL::NullTreeStrategy, GfxTL::IteratedIndexedIteratorTreeDataKernel< MiscLib::Vector< size_t >::iterator, PointCloud::const_iterator > > > > > > > > > IndexedOctreeType
Definition Octree.h:44
constexpr T c
#define DLL_LINKAGE
Definition basic.h:12
AACubeTreeCell< DimT, typename ScoreAACubeTreeStrategy< 3, RebuildAACubeTreeStrategy< GfxTL::BucketSizeMaxLevelSubdivisionTreeStrategy< GfxTL::CellLevelTreeStrategy< GfxTL::CellCenterAACubeTreeStrategy< 3, GfxTL::BaseAACubeTreeStrategy< GfxTL::CellRangeDataTreeStrategy< GfxTL::NullTreeStrategy, GfxTL::IteratedIndexedIteratorTreeDataKernel< MiscLib::Vector< size_t >::iterator, PointCloud::const_iterator > > > > > > > >::CellData > CellType
Definition AACubeTree.h:345
PrimtiveShape is a shape primitive in conjunction with a parametrization.
size_t Detect(PointCloud &pc, size_t begin, size_t end, MiscLib::Vector< std::pair< MiscLib::RefCountPtr< PrimitiveShape >, size_t > > *shapes)
const Options & GetOptions() const
void Add(PrimitiveShapeConstructor *c)
size_t AutoAcceptSize() const
void AutoAcceptSize(size_t s)
std::chrono::milliseconds m_maxruntime
enum RansacShapeDetector::Options::@242245311172336022067310002031335311314376306036 m_fitting
static constexpr auto invalidRuntime