CylinderPrimitiveShape.h
Go to the documentation of this file.
1#ifndef CYLINDERPRIMITIVESHAPE_HEADER
2#define CYLINDERPRIMITIVESHAPE_HEADER
4#include "Cylinder.h"
5#include "LevMarFunc.h"
6
7#ifndef DLL_LINKAGE
8#define DLL_LINKAGE
9#endif
10
12{
13public:
15 size_t Identifier() const;
16
17 unsigned int
19 {
21 }
22
23 CylinderPrimitiveShape(const Cylinder& cylinder);
24 PrimitiveShape* Clone() const;
25 bool Init(const Vec3f& pointA, const Vec3f& pointB, const Vec3f& normalA, const Vec3f& normalB);
26
27 bool
28 Init(bool binary, std::istream* i)
29 {
30 return BitmapPrimitiveShape::Init(binary, i);
31 }
32
33 float Distance(const Vec3f& p) const;
34 float SignedDistance(const Vec3f& p) const;
35 float NormalDeviation(const Vec3f& p, const Vec3f& n) const;
36 void
37 DistanceAndNormalDeviation(const Vec3f& p, const Vec3f& n, std::pair<float, float>* dn) const;
38 void Project(const Vec3f& p, Vec3f* pp) const;
39 void Normal(const Vec3f& p, Vec3f* n) const;
40 unsigned int ConfidenceTests(unsigned int numTests,
41 float epsilon,
42 float normalThresh,
43 float rms,
44 const PointCloud& pc,
45 const MiscLib::Vector<size_t>& indices) const;
46 void Description(std::string* s) const;
47 bool Fit(const PointCloud& pc,
48 float epsilon,
49 float normalThresh,
53 float epsilon,
54 float normalThresh,
57 std::pair<size_t, float>* score) const;
59 void Serialize(std::ostream* o, bool binary = true) const;
60 size_t SerializedSize() const;
61
62 virtual void
63 Serialize(float* array) const
64 {
65 m_cylinder.Serialize(array);
66 }
67
68 virtual size_t
70 {
71 return m_cylinder.SerializedFloatSize();
72 }
73
74 void Transform(float scale, const Vec3f& translate);
75 void Transform(const GfxTL::MatrixXX<3, 3, float>& rot, const GfxTL::Vector3Df& trans);
76 void Visit(PrimitiveShapeVisitor* visitor) const;
78 const PointCloud& pc,
81 float distThresh,
83 bool Similar(float tolerance, const CylinderPrimitiveShape& shape) const;
84
85 const Cylinder&
86 Internal() const
87 {
88 return m_cylinder;
89 }
90
91 float Height() const;
92 float MinHeight() const;
93 float MaxHeight() const;
94
95 void Parameters(const Vec3f& p, std::pair<float, float>* param) const;
96 void Parameters(
99 MiscLib::Vector<std::pair<float, float>>* bmpParams) const;
102 MiscLib::Vector<std::pair<float, float>>* bmpParams) const;
103 bool InSpace(float u, float v, Vec3f* p, Vec3f* n) const;
104 void BitmapExtent(float epsilon,
106 MiscLib::Vector<std::pair<float, float>>* params,
107 size_t* uextent,
108 size_t* vextent);
109 void InBitmap(const std::pair<float, float>& param,
110 float epsilon,
112 size_t uextent,
113 size_t vextent,
114 std::pair<int, int>* inBmp) const;
116 float epsilon,
117 bool* uwrap,
118 bool* vwrap) const;
120 float epsilon,
121 size_t uextent,
122 size_t vextent,
123 MiscLib::Vector<char>* bmp) const;
124 void SetExtent(const GfxTL::AABox<GfxTL::Vector2Df>& bbox,
125 const MiscLib::Vector<int>& componentsImg,
126 size_t uextent,
127 size_t vextent,
128 float epsilon,
129 int label);
130 bool InSpace(size_t u,
131 size_t v,
132 float epsilon,
134 size_t uextent,
135 size_t vextent,
136 Vec3f* p,
137 Vec3f* n) const;
138
139private:
140 template <class IteratorT>
141 void ParametersImpl(IteratorT begin,
142 IteratorT end,
143 MiscLib::Vector<std::pair<float, float>>* bmpParams) const;
144
145private:
146 Cylinder m_cylinder;
147 bool m_clip;
148 float m_minPhi;
149 float m_maxPhi;
150};
151
152template <class IteratorT>
153void
154CylinderPrimitiveShape::ParametersImpl(IteratorT begin,
155 IteratorT end,
156 MiscLib::Vector<std::pair<float, float>>* bmpParams) const
157{
158 bmpParams->resize(end - begin);
159 size_t j = 0;
160 for (IteratorT i = begin; i != end; ++i, ++j)
161 {
162 m_cylinder.Parameters(*i, &(*bmpParams)[j]);
163 (*bmpParams)[j].second = (*bmpParams)[j].second * m_cylinder.Radius();
164 }
165}
166
168{
169public:
170 CylinderLevMarFunc(const Cylinder& cy) : m_cylinder(cy)
171 {
172 }
173
174 float
175 operator()(const float* x) const
176 {
177 return m_cylinder.SignedDistance(*((const Vec3f*)x));
178 }
179
180 void
181 operator()(const float* x, float* gradient) const
182 {
183 m_cylinder.Normal(*((const Vec3f*)x), (Vec3f*)gradient);
184 }
185
186private:
187 Cylinder m_cylinder;
188};
189
190#endif
class DLL_LINKAGE CylinderPrimitiveShape
#define DLL_LINKAGE
Definition basic.h:12
unsigned int ConfidenceTests(unsigned int numTests, float epsilon, float normalThresh, float rms, const PointCloud &pc, const MiscLib::Vector< size_t > &indices) const
virtual void Parameters(const Vec3f &p, std::pair< float, float > *param) const =0
virtual void WrapBitmap(const GfxTL::AABox< GfxTL::Vector2Df > &bbox, float epsilon, bool *uwrap, bool *vwrap) const =0
virtual void PreWrapBitmap(const GfxTL::AABox< GfxTL::Vector2Df > &bbox, float epsilon, size_t uextent, size_t vextent, MiscLib::Vector< char > *bmp) const
virtual bool InSpace(float u, float v, Vec3f *p, Vec3f *n) const =0
bool Init(bool binary, std::istream *i)
virtual void InBitmap(const std::pair< float, float > &param, float epsilon, const GfxTL::AABox< GfxTL::Vector2Df > &bbox, size_t uextent, size_t vextent, std::pair< int, int > *inBmp) const =0
virtual void BitmapExtent(float epsilon, GfxTL::AABox< GfxTL::Vector2Df > *bbox, MiscLib::Vector< std::pair< float, float > > *params, size_t *uextent, size_t *vextent)=0
void operator()(const float *x, float *gradient) const
CylinderLevMarFunc(const Cylinder &cy)
float operator()(const float *x) const
bool Init(bool binary, std::istream *i)
virtual void Serialize(float *array) const
unsigned int RequiredSamples() const
const Cylinder & Internal() const
virtual size_t SerializedFloatSize() const
@ RequiredSamples
Definition Cylinder.h:32
const Point * const_iterator
Definition Vector.h:25
PrimtiveShape is a shape primitive in conjunction with a parametrization.
virtual size_t SerializedSize() const =0
virtual void Project(const Vec3f &p, Vec3f *pp) const =0
virtual float NormalDeviation(const Vec3f &p, const Vec3f &n) const =0
virtual PrimitiveShape * LSFit(const PointCloud &pc, float epsilon, float normalThresh, MiscLib::Vector< size_t >::const_iterator begin, MiscLib::Vector< size_t >::const_iterator end, std::pair< size_t, float > *score) const =0
virtual void Visit(PrimitiveShapeVisitor *visitor) const =0
virtual void Transform(float scale, const Vec3f &translate)=0
virtual float SignedDistance(const Vec3f &p) const =0
virtual size_t Identifier() const =0
virtual LevMarFunc< float > * SignedDistanceFunc() const =0
virtual void Normal(const Vec3f &p, Vec3f *n) const =0
virtual void SuggestSimplifications(const PointCloud &pc, MiscLib::Vector< size_t >::const_iterator begin, MiscLib::Vector< size_t >::const_iterator end, float distThresh, MiscLib::Vector< MiscLib::RefCountPtr< PrimitiveShape > > *suggestions) const
virtual void Description(std::string *s) const =0
virtual void DistanceAndNormalDeviation(const Vec3f &p, const Vec3f &n, std::pair< float, float > *dn) const =0
virtual float Distance(const Vec3f &p) const =0
virtual void Serialize(std::ostream *o, bool binary=true) const =0
This is the one and only serialization function It stores all the parameters of the shape as well as ...
virtual bool Fit(const PointCloud &pc, float epsilon, float normalThresh, MiscLib::Vector< size_t >::const_iterator begin, MiscLib::Vector< size_t >::const_iterator end)=0
virtual PrimitiveShape * Clone() const =0
Definition basic.h:18
VectorXD< 3, float > Vector3Df
Definition VectorXD.h:718
This file offers overloads of toIce() and fromIce() functions for STL container types.