PlanePrimitiveShape.cpp
Go to the documentation of this file.
1 #include "PlanePrimitiveShape.h"
2 #include "ScoreComputer.h"
4 #include <GfxTL/NullClass.h>
5 #include <limits>
6 #include <iostream>
7 #include <fstream>
8 #include <sstream>
9 #include <iomanip>
10 #include <MiscLib/Performance.h>
12 
14  const Vec3f& c)
15  : m_plane(a, b, c)
16 {
17  m_hcs.FromNormal(m_plane.getNormal());
18 }
19 
21  : m_plane(plane)
22 {
23  m_hcs.FromNormal(m_plane.getNormal());
24 }
25 
27 {
28  return 0;
29 }
30 
32 {
33  return new PlanePrimitiveShape(*this);
34 }
35 
36 float PlanePrimitiveShape::Distance(const Vec3f& p) const
37 {
38  return m_plane.getDistance(p);
39 }
40 
42 {
43  return m_plane.SignedDistance(p);
44 }
45 
47  const Vec3f& n) const
48 {
49  return m_plane.getNormal().dot(n);
50 }
51 
53  const Vec3f& p, const Vec3f& n, std::pair< float, float >* dn) const
54 {
55  dn->first = m_plane.getDistance(p);
56  dn->second = m_plane.getNormal().dot(n);
57 }
58 
59 void PlanePrimitiveShape::Project(const Vec3f& p, Vec3f* pp) const
60 {
61  *pp = p - ((m_plane.getNormal().dot(p - m_plane.getPosition()))
62  * m_plane.getNormal());
63 }
64 
65 void PlanePrimitiveShape::Normal(const Vec3f& p, Vec3f* n) const
66 {
67  *n = m_plane.getNormal();
68 }
69 
70 unsigned int PlanePrimitiveShape::ConfidenceTests(unsigned int numTests,
71  float epsilon, float normalThresh, float rms, const PointCloud& pc,
73 {
74  return BasePrimitiveShape::ConfidenceTests< Plane >(numTests, epsilon,
75  normalThresh, rms, pc, indices);
76 }
77 
78 void PlanePrimitiveShape::Description(std::string* s) const
79 {
80  *s = "Plane";
81 }
82 
83 bool PlanePrimitiveShape::Fit(const PointCloud& pc, float epsilon,
84  float normalThresh, MiscLib::Vector< size_t >::const_iterator begin,
86 {
87  Plane fit = m_plane;
88  //if(fit.LeastSquaresFit(pc, begin, end))
89  if (fit.LeastSquaresFit(pc, begin, end))
90  {
91  m_plane = fit;
92  m_hcs.FromNormal(m_plane.getNormal());
93  return true;
94  }
95  return false;
96 }
97 
99  float normalThresh, MiscLib::Vector< size_t >::const_iterator begin,
101  std::pair< size_t, float >* score) const
102 {
103  Plane fit = m_plane;
104  if (fit.LeastSquaresFit(pc, begin, end))
105  {
106  score->first = -1;
107  return new PlanePrimitiveShape(fit);
108  }
109  score->first = 0;
110  return NULL;
111 }
112 
113 void PlanePrimitiveShape::Serialize(std::ostream* o, bool binary) const
114 {
115  if (binary)
116  {
117  const char id = 0;
118  (*o) << id;
119  }
120  else
121  {
122  (*o) << "0" << " ";
123  }
124  m_plane.Serialize(binary, o);
125  if (!binary)
126  {
127  *o << std::endl;
128  }
129 }
130 
132 {
133  return m_plane.SerializedSize() + 1;
134 }
135 
136 void PlanePrimitiveShape::Transform(float scale, const Vec3f& translate)
137 {
138  m_plane.Transform(scale, translate);
139 }
140 
142  const GfxTL::Vector3Df& trans)
143 {
144  GfxTL::Vector3Df transNormal = rot * GfxTL::Vector3Df(
145  m_plane.getNormal());
146  GfxTL::Vector3Df transOrigin = rot * GfxTL::Vector3Df(
147  m_plane.getPosition()) + trans;
148  m_plane = Plane(Vec3f(transOrigin.Data()), Vec3f(transNormal.Data()));
149  m_hcs[0] = rot * m_hcs[0];
150  m_hcs[1] = rot * m_hcs[1];
151 }
152 
154 {
155  visitor->Visit(*this);
156 }
157 
159 {
160  return true; // planes are always similar!
161 }
162 
164 {
165  return new PlaneLevMarFunc(m_plane);
166 }
167 
169  std::pair< float, float >* param) const
170 {
171  Vec3f pp = p - m_plane.getPosition();
172  param->first = pp.dot(m_hcs[0].Data());
173  param->second = pp.dot(m_hcs[1].Data());
174 }
175 
181  MiscLib::Vector< std::pair< float, float > >* bmpParams) const
182 {
183  ParametersImpl(begin, end, bmpParams);
184 }
185 
191  MiscLib::Vector< std::pair< float, float > >* bmpParams) const
192 {
193  ParametersImpl(begin, end, bmpParams);
194 }
195 
198  MiscLib::Vector< std::pair< float, float > >* params,
199  size_t* uextent, size_t* vextent)
200 {
201  *uextent = size_t(std::ceil((bbox->Max()[0] - bbox->Min()[0]) / epsilon)) + 1;
202  *vextent = size_t(std::ceil((bbox->Max()[1] - bbox->Min()[1]) / epsilon)) + 1;
203 }
204 
205 void PlanePrimitiveShape::InBitmap(const std::pair< float, float >& param,
206  float epsilon, const GfxTL::AABox< GfxTL::Vector2Df >& bbox, size_t,
207  size_t, std::pair< int, int >* inBmp) const
208 {
209  inBmp->first = std::floor((param.first - bbox.Min()[0]) / epsilon);
210  inBmp->second = std::floor((param.second - bbox.Min()[1]) / epsilon);
211 }
213  const GfxTL::AABox< GfxTL::Vector2Df >& bbox, float epsilon, bool* uwrap,
214  bool* vwrap) const
215 {
216  *uwrap = false;
217  *vwrap = false;
218 }
219 
222  size_t, size_t, float, int)
223 {}
224 
225 bool PlanePrimitiveShape::InSpace(float u, float v, Vec3f* p, Vec3f* n) const
226 {
227  *p = m_plane.getPosition() + Vec3f((u * m_hcs[0] + v * m_hcs[1]).Data());
228  *n = m_plane.getNormal();
229  return true;
230 }
231 
232 bool PlanePrimitiveShape::InSpace(size_t u, size_t v, float epsilon,
233  const GfxTL::AABox< GfxTL::Vector2Df >& bbox, size_t uextent,
234  size_t vextent, Vec3f* p, Vec3f* n) const
235 {
236  *p = Vec3f(((bbox.Min()[0] + epsilon * (float(u) + .5f)) * m_hcs[0] +
237  (bbox.Min()[1] + epsilon * (float(v) + .5f)) * m_hcs[1]).Data()) +
238  m_plane.getPosition();
239  *n = m_plane.getNormal();
240  return true;
241 }
GfxTL::IndexedIterator
Definition: IndexedIterator.h:8
PlaneLevMarFunc
Definition: PlanePrimitiveShape.h:120
PrimitiveShapeVisitor::Visit
virtual void Visit(const PlanePrimitiveShape &plane)=0
LevMarFunc< float >
GfxTL::VectorXD
Definition: MatrixXX.h:21
PlanePrimitiveShape::Clone
PrimitiveShape * Clone() const
Definition: PlanePrimitiveShape.cpp:31
PlanePrimitiveShape::Description
void Description(std::string *s) const
Definition: PlanePrimitiveShape.cpp:78
GfxTL::AABox::Max
Point & Max()
Definition: AABox.hpp:74
totalTime_planeConnected
MiscLib::performance_t totalTime_planeConnected
PlanePrimitiveShape::Distance
float Distance(const Vec3f &p) const
Definition: PlanePrimitiveShape.cpp:36
PlanePrimitiveShape::NormalDeviation
float NormalDeviation(const Vec3f &p, const Vec3f &n) const
Definition: PlanePrimitiveShape.cpp:46
PlanePrimitiveShape.h
PlanePrimitiveShape::WrapBitmap
void WrapBitmap(const GfxTL::AABox< GfxTL::Vector2Df > &bbox, float epsilon, bool *uwrap, bool *vwrap) const
Definition: PlanePrimitiveShape.cpp:212
Vec3f
Definition: basic.h:16
Performance.h
PlanePrimitiveShape::DistanceAndNormalDeviation
void DistanceAndNormalDeviation(const Vec3f &p, const Vec3f &n, std::pair< float, float > *dn) const
Definition: PlanePrimitiveShape.cpp:52
PlanePrimitiveShape::Normal
void Normal(const Vec3f &p, Vec3f *n) const
Definition: PlanePrimitiveShape.cpp:65
PlanePrimitiveShape::Fit
bool Fit(const PointCloud &pc, float epsilon, float normalThresh, MiscLib::Vector< size_t >::const_iterator begin, MiscLib::Vector< size_t >::const_iterator end)
Definition: PlanePrimitiveShape.cpp:83
Plane::LeastSquaresFit
bool LeastSquaresFit(const PointCloud &pc, MiscLib::Vector< size_t >::const_iterator begin, MiscLib::Vector< size_t >::const_iterator end)
Definition: Plane.cpp:179
PlanePrimitiveShape::Project
void Project(const Vec3f &p, Vec3f *pp) const
Definition: PlanePrimitiveShape.cpp:59
PlanePrimitiveShape::ConfidenceTests
unsigned int ConfidenceTests(unsigned int numTests, float epsilon, float normalThresh, float rms, const PointCloud &pc, const MiscLib::Vector< size_t > &indices) const
Definition: PlanePrimitiveShape.cpp:70
Plane::Transform
void Transform(float scale, const Vec3f &translate)
Definition: Plane.cpp:266
PrimitiveShape
PrimtiveShape is a shape primitive in conjunction with a parametrization.
Definition: PrimitiveShape.h:32
c
constexpr T c
Definition: UnscentedKalmanFilterTest.cpp:43
PlanePrimitiveShape::Serialize
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 ...
Definition: PlanePrimitiveShape.cpp:113
GfxTL::MatrixXX
Definition: MatrixXX.h:25
MiscLib::Vector< size_t >
PlanePrimitiveShape::SetExtent
void SetExtent(const GfxTL::AABox< GfxTL::Vector2Df > &bbox, const MiscLib::Vector< int > &componentsImg, size_t uextent, size_t vextent, float epsilon, int label)
Definition: PlanePrimitiveShape.cpp:220
PrimitiveShapeVisitor.h
PlanePrimitiveShape::InBitmap
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
Definition: PlanePrimitiveShape.cpp:205
Plane::SerializedSize
static size_t SerializedSize()
Definition: Plane.cpp:236
MiscLib::Vector< Point >::const_iterator
const typedef Point * const_iterator
Definition: Vector.h:26
GfxTL::Vector3Df
VectorXD< 3, float > Vector3Df
Definition: VectorXD.h:676
PlanePrimitiveShape::SignedDistanceFunc
LevMarFunc< float > * SignedDistanceFunc() const
Definition: PlanePrimitiveShape.cpp:163
PlanePrimitiveShape::SerializedSize
size_t SerializedSize() const
Definition: PlanePrimitiveShape.cpp:131
Plane::getPosition
const Vec3f & getPosition() const
Definition: Plane.h:55
armarx::ctrlutil::a
double a(double t, double a0, double j)
Definition: CtrlUtil.h:45
pcl::graph::indices
pcl::PointIndices::Ptr indices(const PCG &g)
Retrieve the indices of the points of the point cloud stored in a point cloud graph that actually bel...
Definition: point_cloud_graph.h:737
PlanePrimitiveShape::Transform
void Transform(float scale, const Vec3f &translate)
Definition: PlanePrimitiveShape.cpp:136
PlanePrimitiveShape
Definition: PlanePrimitiveShape.h:15
PrimitiveShapeVisitor
Definition: PrimitiveShapeVisitor.h:14
MiscLib::performance_t
clock_t performance_t
Definition: Performance.h:27
PlanePrimitiveShape::PlanePrimitiveShape
PlanePrimitiveShape(const Vec3f &a, const Vec3f &b, const Vec3f &c)
Definition: PlanePrimitiveShape.cpp:13
PlanePrimitiveShape::LSFit
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
Definition: PlanePrimitiveShape.cpp:98
PlanePrimitiveShape::Identifier
size_t Identifier() const
Definition: PlanePrimitiveShape.cpp:26
PlanePrimitiveShape::BitmapExtent
void BitmapExtent(float epsilon, GfxTL::AABox< GfxTL::Vector2Df > *bbox, MiscLib::Vector< std::pair< float, float > > *params, size_t *uextent, size_t *vextent)
Definition: PlanePrimitiveShape.cpp:196
PointCloud
Definition: PointCloud.h:69
armarx::ctrlutil::v
double v(double t, double v0, double a0, double j)
Definition: CtrlUtil.h:39
Vec3f::dot
float dot(const Vec3f &v) const
Definition: basic.h:92
Plane::SignedDistance
float SignedDistance(const Vec3f &pos) const
Definition: Plane.h:38
Plane::getNormal
const Vec3f & getNormal() const
Definition: Plane.h:51
Plane::Serialize
void Serialize(bool binary, std::ostream *o) const
Definition: Plane.cpp:203
GfxTL::AABox::Min
Point & Min()
Definition: AABox.hpp:62
PlanePrimitiveShape::Similar
bool Similar(float tolerance, const PlanePrimitiveShape &) const
Definition: PlanePrimitiveShape.cpp:158
NullClass.h
Plane
Definition: Plane.h:16
ScoreComputer.h
GfxTL::Vec3f
VectorXD< 3, float > Vec3f
Definition: VectorXD.h:691
PlanePrimitiveShape::SignedDistance
float SignedDistance(const Vec3f &p) const
Definition: PlanePrimitiveShape.cpp:41
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
PlanePrimitiveShape::InSpace
bool InSpace(float u, float v, Vec3f *p, Vec3f *n) const
Definition: PlanePrimitiveShape.cpp:225
PlanePrimitiveShape::Parameters
void Parameters(const Vec3f &p, std::pair< float, float > *param) const
Definition: PlanePrimitiveShape.cpp:168
PlanePrimitiveShape::Visit
void Visit(PrimitiveShapeVisitor *visitor) const
Definition: PlanePrimitiveShape.cpp:153
Plane::getDistance
float getDistance(const Vec3f &pos) const
Definition: Plane.h:30
armarx::ctrlutil::s
double s(double t, double s0, double v0, double a0, double j)
Definition: CtrlUtil.h:33
IndexIterator
Definition: IndexIterator.h:9
GfxTL::AABox
Definition: AABox.h:18