Debian Codegraph @

plugins/core/Standard/qRANSAC_SD/extern/RANSAC_SD/CylinderPrimitiveShape.h

raw
1 #ifndef CYLINDERPRIMITIVESHAPE_HEADER
2 #define CYLINDERPRIMITIVESHAPE_HEADER
3 #include "BitmapPrimitiveShape.h"
4 #include "Cylinder.h"
5 #include "LevMarFunc.h"
6
7 #ifndef DLL_LINKAGE
8 #define DLL_LINKAGE
9 #endif
10
11 class DLL_LINKAGE CylinderPrimitiveShape
12 : public BitmapPrimitiveShape
13 {
14 public:
15 CylinderPrimitiveShape();
16 size_t Identifier() const;
17 unsigned int RequiredSamples() const { return Cylinder::RequiredSamples; }
18 CylinderPrimitiveShape(const Cylinder &cylinder, float minRadius = -std::numeric_limits<float>::infinity(), float maxRadius = std::numeric_limits<float>::infinity(), float maxLength = std::numeric_limits<float>::infinity());
19 PrimitiveShape *Clone() const;
20 bool Init(const Vec3f &pointA, const Vec3f &pointB,
21 const Vec3f &normalA, const Vec3f &normalB);
22 bool Init(bool binary, std::istream *i) { return BitmapPrimitiveShape::Init(binary, i); }
23 float Distance(const Vec3f &p) const;
24 float SignedDistance(const Vec3f &p) const;
25 float NormalDeviation(const Vec3f &p, const Vec3f &n) const;
26 void DistanceAndNormalDeviation(const Vec3f &p,
27 const Vec3f &n, std::pair< float, float > *dn) const;
28 void Project(const Vec3f &p, Vec3f *pp) const;
29 void Normal(const Vec3f &p, Vec3f *n) const;
30 unsigned int ConfidenceTests(unsigned int numTests, float epsilon,
31 float normalThresh, float rms, const PointCloud &pc,
32 const MiscLib::Vector< size_t > &indices) const;
33 void Description(std::string *s) const;
34 bool Fit(const PointCloud &pc, float epsilon, float normalThresh,
35 MiscLib::Vector< size_t >::const_iterator begin,
36 MiscLib::Vector< size_t >::const_iterator end);
37 PrimitiveShape *LSFit(const PointCloud &pc, float epsilon,
38 float normalThresh,
39 MiscLib::Vector< size_t >::const_iterator begin,
40 MiscLib::Vector< size_t >::const_iterator end,
41 std::pair< size_t, float > *score) const;
42 LevMarFunc< float > *SignedDistanceFunc() const;
43 void Serialize(std::ostream *o, bool binary = true) const;
44 size_t SerializedSize() const;
45 virtual void Serialize(float* array) const {m_cylinder.Serialize(array);}
46 virtual size_t SerializedFloatSize() const {return m_cylinder.SerializedFloatSize();}
47 void Transform(float scale, const Vec3f &translate);
48 void Transform(const GfxTL::MatrixXX< 3, 3, float > &rot,
49 const GfxTL::Vector3Df &trans);
50 void Visit(PrimitiveShapeVisitor *visitor) const;
51 void SuggestSimplifications(const PointCloud &pc,
52 MiscLib::Vector< size_t >::const_iterator begin,
53 MiscLib::Vector< size_t >::const_iterator end, float distThresh,
54 MiscLib::Vector< MiscLib::RefCountPtr< PrimitiveShape > > *suggestions) const;
55 bool Similar(float tolerance,
56 const CylinderPrimitiveShape &shape) const;
57 const Cylinder &Internal() const { return m_cylinder; }
58 float Height() const;
59 float MinHeight() const;
60 float MaxHeight() const;
61
62 void Parameters(const Vec3f &p,
63 std::pair< float, float > *param) const;
64 void Parameters(GfxTL::IndexedIterator< MiscLib::Vector< size_t >::iterator,
65 PointCloud::const_iterator > begin,
66 GfxTL::IndexedIterator< MiscLib::Vector< size_t >::iterator,
67 PointCloud::const_iterator > end,
68 MiscLib::Vector< std::pair< float, float > > *bmpParams) const;
69 void Parameters(GfxTL::IndexedIterator< IndexIterator,
70 PointCloud::const_iterator > begin,
71 GfxTL::IndexedIterator< IndexIterator,
72 PointCloud::const_iterator > end,
73 MiscLib::Vector< std::pair< float, float > > *bmpParams) const;
74 bool InSpace(float u, float v, Vec3f *p, Vec3f *n) const;
75 void BitmapExtent(float epsilon,
76 GfxTL::AABox< GfxTL::Vector2Df > *bbox,
77 MiscLib::Vector< std::pair< float, float > > *params,
78 size_t *uextent, size_t *vextent);
79 void InBitmap(const std::pair< float, float > &param, float epsilon,
80 const GfxTL::AABox< GfxTL::Vector2Df > &bbox, size_t uextent,
81 size_t vextent, std::pair< int, int > *inBmp) const;
82 void WrapBitmap(const GfxTL::AABox< GfxTL::Vector2Df > &bbox,
83 float epsilon, bool *uwrap, bool *vwrap) const;
84 void PreWrapBitmap(const GfxTL::AABox< GfxTL::Vector2Df > &bbox,
85 float epsilon, size_t uextent, size_t vextent,
86 MiscLib::Vector< char > *bmp) const;
87 void SetExtent(const GfxTL::AABox< GfxTL::Vector2Df > &bbox,
88 const MiscLib::Vector< int > &componentsImg, size_t uextent,
89 size_t vextent, float epsilon, int label);
90 bool InSpace(size_t u, size_t v, float epsilon,
91 const GfxTL::AABox< GfxTL::Vector2Df > &bbox, size_t uextent,
92 size_t vextent, Vec3f *p, Vec3f *n) const;
93 bool CheckGeneratedShapeWithinLimits(const PointCloud& pc,
94 MiscLib::Vector< size_t >::const_iterator begin,
95 MiscLib::Vector< size_t >::const_iterator end) override
96 {
97 if (m_cylinder.Radius() <= m_maxRadius && Height() <= m_maxLength)
98 {
99 return true;
100 }
101 return false;
102 }
103 private:
104 template< class IteratorT >
105 void ParametersImpl(IteratorT begin, IteratorT end,
106 MiscLib::Vector< std::pair< float, float > > *bmpParams) const;
107
108 private:
109 Cylinder m_cylinder;
110 bool m_clip;
111 float m_minPhi;
112 float m_maxPhi;
113 float m_minRadius;
114 float m_maxRadius;
115 float m_maxLength;
116 };
117
118 template< class IteratorT >
119 void CylinderPrimitiveShape::ParametersImpl(IteratorT begin, IteratorT end,
120 MiscLib::Vector< std::pair< float, float > > *bmpParams) const
121 {
122 bmpParams->resize(end - begin);
123 size_t j = 0;
124 for(IteratorT i = begin; i != end; ++i, ++j)
125 {
126 m_cylinder.Parameters(*i, &(*bmpParams)[j]);
127 (*bmpParams)[j].second = (*bmpParams)[j].second * m_cylinder.Radius();
128 }
129 }
130
131 class DLL_LINKAGE CylinderLevMarFunc
132 : public LevMarFunc< float >
133 {
134 public:
135 CylinderLevMarFunc(const Cylinder &cy)
136 : m_cylinder(cy)
137 {}
138
139 float operator()(const float *x) const
140 {
141 return m_cylinder.SignedDistance(*((const Vec3f *)x));
142 }
143
144 void operator()(const float *x, float *gradient) const
145 {
146 m_cylinder.Normal(*((const Vec3f *)x), (Vec3f *)gradient);
147 }
148
149 private:
150 Cylinder m_cylinder;
151 };
152
153 #endif