PlanePrimitiveShape.cpp
Go to the documentation of this file.
2
3#include <fstream>
4#include <iomanip>
5#include <iostream>
6#include <limits>
7#include <sstream>
8
10#include "ScoreComputer.h"
11#include <GfxTL/NullClass.h>
12#include <MiscLib/Performance.h>
14
16 m_plane(a, b, c)
17{
18 m_hcs.FromNormal(m_plane.getNormal());
19}
20
21PlanePrimitiveShape::PlanePrimitiveShape(const Plane& plane) : m_plane(plane)
22{
23 m_hcs.FromNormal(m_plane.getNormal());
24}
25
26size_t
28{
29 return 0;
30}
31
34{
35 return new PlanePrimitiveShape(*this);
36}
37
38float
40{
41 return m_plane.getDistance(p);
42}
43
44float
46{
47 return m_plane.SignedDistance(p);
48}
49
50float
52{
53 return m_plane.getNormal().dot(n);
54}
55
56void
58 const Vec3f& n,
59 std::pair<float, float>* dn) const
60{
61 dn->first = m_plane.getDistance(p);
62 dn->second = m_plane.getNormal().dot(n);
63}
64
65void
67{
68 *pp = p - ((m_plane.getNormal().dot(p - m_plane.getPosition())) * m_plane.getNormal());
69}
70
71void
73{
74 *n = m_plane.getNormal();
75}
76
77unsigned int
79 float epsilon,
80 float normalThresh,
81 float rms,
82 const PointCloud& pc,
83 const MiscLib::Vector<size_t>& indices) const
84{
86 numTests, epsilon, normalThresh, rms, pc, indices);
87}
88
89void
91{
92 *s = "Plane";
93}
94
95bool
97 float epsilon,
98 float normalThresh,
101{
102 Plane fit = m_plane;
103 //if(fit.LeastSquaresFit(pc, begin, end))
104 if (fit.LeastSquaresFit(pc, begin, end))
105 {
106 m_plane = fit;
107 m_hcs.FromNormal(m_plane.getNormal());
108 return true;
109 }
110 return false;
111}
112
115 float epsilon,
116 float normalThresh,
119 std::pair<size_t, float>* score) const
120{
121 Plane fit = m_plane;
122 if (fit.LeastSquaresFit(pc, begin, end))
123 {
124 score->first = -1;
125 return new PlanePrimitiveShape(fit);
126 }
127 score->first = 0;
128 return NULL;
129}
130
131void
132PlanePrimitiveShape::Serialize(std::ostream* o, bool binary) const
133{
134 if (binary)
135 {
136 const char id = 0;
137 (*o) << id;
138 }
139 else
140 {
141 (*o) << "0"
142 << " ";
143 }
144 m_plane.Serialize(binary, o);
145 if (!binary)
146 {
147 *o << std::endl;
148 }
149}
150
151size_t
153{
154 return m_plane.SerializedSize() + 1;
155}
156
157void
158PlanePrimitiveShape::Transform(float scale, const Vec3f& translate)
159{
160 m_plane.Transform(scale, translate);
161}
162
163void
165 const GfxTL::Vector3Df& trans)
166{
167 GfxTL::Vector3Df transNormal = rot * GfxTL::Vector3Df(m_plane.getNormal());
168 GfxTL::Vector3Df transOrigin = rot * GfxTL::Vector3Df(m_plane.getPosition()) + trans;
169 m_plane = Plane(Vec3f(transOrigin.Data()), Vec3f(transNormal.Data()));
170 m_hcs[0] = rot * m_hcs[0];
171 m_hcs[1] = rot * m_hcs[1];
172}
173
174void
176{
177 visitor->Visit(*this);
178}
179
180bool
182{
183 return true; // planes are always similar!
184}
185
188{
189 return new PlaneLevMarFunc(m_plane);
190}
191
192void
193PlanePrimitiveShape::Parameters(const Vec3f& p, std::pair<float, float>* param) const
194{
195 Vec3f pp = p - m_plane.getPosition();
196 param->first = pp.dot(m_hcs[0].Data());
197 param->second = pp.dot(m_hcs[1].Data());
198}
199
200void
208
209void
213 MiscLib::Vector<std::pair<float, float>>* bmpParams) const
214{
215 ParametersImpl(begin, end, bmpParams);
216}
217
218void
221 MiscLib::Vector<std::pair<float, float>>* params,
222 size_t* uextent,
223 size_t* vextent)
224{
225 *uextent = size_t(std::ceil((bbox->Max()[0] - bbox->Min()[0]) / epsilon)) + 1;
226 *vextent = size_t(std::ceil((bbox->Max()[1] - bbox->Min()[1]) / epsilon)) + 1;
227}
228
229void
230PlanePrimitiveShape::InBitmap(const std::pair<float, float>& param,
231 float epsilon,
233 size_t,
234 size_t,
235 std::pair<int, int>* inBmp) const
236{
237 inBmp->first = std::floor((param.first - bbox.Min()[0]) / epsilon);
238 inBmp->second = std::floor((param.second - bbox.Min()[1]) / epsilon);
239}
240
241void
243 float epsilon,
244 bool* uwrap,
245 bool* vwrap) const
246{
247 *uwrap = false;
248 *vwrap = false;
249}
250
251void
254 size_t,
255 size_t,
256 float,
257 int)
258{
259}
260
261bool
262PlanePrimitiveShape::InSpace(float u, float v, Vec3f* p, Vec3f* n) const
263{
264 *p = m_plane.getPosition() + Vec3f((u * m_hcs[0] + v * m_hcs[1]).Data());
265 *n = m_plane.getNormal();
266 return true;
267}
268
269bool
271 size_t v,
272 float epsilon,
274 size_t uextent,
275 size_t vextent,
276 Vec3f* p,
277 Vec3f* n) const
278{
279 *p = Vec3f(((bbox.Min()[0] + epsilon * (float(u) + .5f)) * m_hcs[0] +
280 (bbox.Min()[1] + epsilon * (float(v) + .5f)) * m_hcs[1])
281 .Data()) +
282 m_plane.getPosition();
283 *n = m_plane.getNormal();
284 return true;
285}
MiscLib::performance_t totalTime_planeConnected
class DLL_LINKAGE PlanePrimitiveShape
constexpr T c
unsigned int ConfidenceTests(unsigned int numTests, float epsilon, float normalThresh, float rms, const PointCloud &pc, const MiscLib::Vector< size_t > &indices) const
Point & Min()
Definition AABox.hpp:68
Point & Max()
Definition AABox.hpp:82
const Point * const_iterator
Definition Vector.h:25
void DistanceAndNormalDeviation(const Vec3f &p, const Vec3f &n, std::pair< float, float > *dn) const
unsigned int ConfidenceTests(unsigned int numTests, float epsilon, float normalThresh, float rms, const PointCloud &pc, const MiscLib::Vector< size_t > &indices) const
float SignedDistance(const Vec3f &p) const
float NormalDeviation(const Vec3f &p, const Vec3f &n) const
bool Similar(float tolerance, const PlanePrimitiveShape &) const
PrimitiveShape * Clone() const
void Normal(const Vec3f &p, Vec3f *n) const
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
void Transform(float scale, const Vec3f &translate)
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
void Visit(PrimitiveShapeVisitor *visitor) const
void Project(const Vec3f &p, Vec3f *pp) const
LevMarFunc< float > * SignedDistanceFunc() const
bool Fit(const PointCloud &pc, float epsilon, float normalThresh, MiscLib::Vector< size_t >::const_iterator begin, MiscLib::Vector< size_t >::const_iterator end)
void SetExtent(const GfxTL::AABox< GfxTL::Vector2Df > &bbox, const MiscLib::Vector< int > &componentsImg, size_t uextent, size_t vextent, float epsilon, int label)
void WrapBitmap(const GfxTL::AABox< GfxTL::Vector2Df > &bbox, float epsilon, bool *uwrap, bool *vwrap) const
float Distance(const Vec3f &p) const
void Serialize(std::ostream *o, bool binary=true) const
This is the one and only serialization function It stores all the parameters of the shape as well as ...
PlanePrimitiveShape(const Vec3f &a, const Vec3f &b, const Vec3f &c)
void BitmapExtent(float epsilon, GfxTL::AABox< GfxTL::Vector2Df > *bbox, MiscLib::Vector< std::pair< float, float > > *params, size_t *uextent, size_t *vextent)
void Description(std::string *s) const
void Parameters(const Vec3f &p, std::pair< float, float > *param) const
bool InSpace(float u, float v, Vec3f *p, Vec3f *n) const
Definition Plane.h:19
bool LeastSquaresFit(const PointCloud &pc, MiscLib::Vector< size_t >::const_iterator begin, MiscLib::Vector< size_t >::const_iterator end)
Definition Plane.cpp:200
virtual void Visit(const PlanePrimitiveShape &plane)=0
PrimtiveShape is a shape primitive in conjunction with a parametrization.
Definition basic.h:18
float dot(const Vec3f &v) const
Definition basic.h:104
VectorXD< 3, float > Vector3Df
Definition VectorXD.h:718
clock_t performance_t
Definition Performance.h:31
double dot(const Point &x, const Point &y)
Definition point.hpp:57