BitmapPrimitiveShape.h
Go to the documentation of this file.
1 #ifndef BITMAPPRIMITIVESHAPE_HEADER
2 #define BITMAPPRIMITIVESHAPE_HEADER
3 #include "BasePrimitiveShape.h"
4 #include <GfxTL/AABox.h>
5 #include <MiscLib/Vector.h>
6 #include <algorithm>
7 #include <istream>
8 #include <MiscLib/Performance.h>
9 #include <GfxTL/MathHelper.h>
10 #include <GfxTL/IndexedIterator.h>
11 #include "IndexIterator.h"
12 #include <MiscLib/Pair.h>
13 #ifdef DOPARALLEL
14 #include <omp.h>
15 #endif
16 
17 #ifndef DLL_LINKAGE
18 #define DLL_LINKAGE
19 #endif
20 
21 struct BitmapInfo
22 {
27  size_t uextent, vextent;
28 };
29 
31  : public BasePrimitiveShape
32 {
33 public:
34  bool Init(bool binary, std::istream* i);
35  size_t ConnectedComponent(const PointCloud& pc, float epsilon,
36  MiscLib::Vector< size_t >* indices, bool doFiltering = true, float* borderRatio = 0);
37  size_t AllConnectedComponents(const PointCloud& pc, float epsilon, BitmapInfo& bitmapInfo,
39  MiscLib::Vector< std::pair< int, size_t > >& labels, bool doFiltering = true);
40  void TrimmingPolygons(const PointCloud& pc, float epsilon,
41  size_t begin, size_t end,
42  std::deque< ComponentPolygons >* polys) const;
43  void GenerateBitmapPoints(const PointCloud& pc, float epsilon,
44  size_t begin, size_t end, PointCloud* bmpPc) const;
45 
46 public:
47  virtual void Parameters(const Vec3f& p,
48  std::pair< float, float >* param) const = 0;
49  virtual bool InSpace(float u, float v, Vec3f* p, Vec3f* n) const = 0;
54  MiscLib::Vector< std::pair< float, float > >* bmpParams) const = 0;
59  MiscLib::Vector< std::pair< float, float > >* bmpParams) const = 0;
60  virtual void BitmapExtent(float epsilon,
62  MiscLib::Vector< std::pair< float, float > >* params,
63  size_t* uextent, size_t* vextent) = 0;
64  virtual void InBitmap(const std::pair< float, float >& param,
65  float epsilon, const GfxTL::AABox< GfxTL::Vector2Df >& bbox,
66  size_t uextent, size_t vextent,
67  std::pair< int, int >* inBmp) const = 0;
68  virtual void PreWrapBitmap(const GfxTL::AABox< GfxTL::Vector2Df >& bbox,
69  float epsilon, size_t uextent, size_t vextent,
70  MiscLib::Vector< char >* bmp) const;
71  virtual void WrapBitmap(const GfxTL::AABox< GfxTL::Vector2Df >& bbox,
72  float epsilon, bool* uwrap, bool* vwrap) const = 0;
73  virtual void WrapComponents(const GfxTL::AABox< GfxTL::Vector2Df >& bbox,
74  float epsilon, size_t uextent, size_t vextent,
75  MiscLib::Vector< int >* componentImg,
76  MiscLib::Vector< std::pair< int, size_t > >* labels) const;
77  virtual bool InSpace(size_t u, size_t v, float epsilon,
78  const GfxTL::AABox< GfxTL::Vector2Df >& bbox, size_t uextent,
79  size_t vextent, Vec3f* p, Vec3f* n) const = 0;
80  template< class IteratorT >
81  void BuildBitmap(const PointCloud& pc, float* epsilon, IteratorT begin,
82  IteratorT end, MiscLib::Vector< std::pair< float, float > >* params,
84  MiscLib::Vector< char >* bitmap, size_t* uextent, size_t* vextent,
85  MiscLib::Vector< size_t >* bmpIdx) const;
86  template< class IteratorT >
87  void BuildBitmap(const PointCloud& pc, float* epsilon, IteratorT begin,
88  IteratorT end, MiscLib::Vector< std::pair< float, float > >* params,
90  MiscLib::Vector< char >* bitmap, size_t* uextent, size_t* vextent,
91  MiscLib::Vector< size_t >* bmpIdx, size_t border) const;
92  void BuildPolygons(const PointCloud& pc, float epsilon, size_t begin,
93  size_t end, GfxTL::AABox< GfxTL::Vector2Df >* bbox,
94  size_t* uextent, size_t* vextent,
95  std::deque< ComponentPolygons >* polys) const;
96 
97 protected:
99 };
100 
101 template< class IteratorT >
102 void BitmapPrimitiveShape::BuildBitmap(const PointCloud& pc, float* epsilon,
103  IteratorT begin, IteratorT end, MiscLib::Vector< std::pair< float, float > >* params,
105  size_t* uextent, size_t* vextent, MiscLib::Vector< size_t >* bmpIdx) const
106 {
107  int size = end - begin;
108  params->resize(size);
109  // compute parameters and extent
110  Parameters(GfxTL::IndexIterate(begin, pc.begin()),
111  GfxTL::IndexIterate(end, pc.begin()), params);
112  bbox->Min() = GfxTL::Vector2Df(std::numeric_limits< float >::infinity(),
113  std::numeric_limits< float >::infinity());
114  bbox->Max() = -bbox->Min();
115  for (size_t i = 0; i < (size_t)size; ++i)
116  {
117  if ((*params)[i].first < bbox->Min()[0])
118  {
119  bbox->Min()[0] = (*params)[i].first;
120  }
121  if ((*params)[i].first > bbox->Max()[0])
122  {
123  bbox->Max()[0] = (*params)[i].first;
124  }
125  if ((*params)[i].second < bbox->Min()[1])
126  {
127  bbox->Min()[1] = (*params)[i].second;
128  }
129  if ((*params)[i].second > bbox->Max()[1])
130  {
131  bbox->Max()[1] = (*params)[i].second;
132  }
133  }
134  // bbox gives the bounding box in parameter space
135  // we can now set up the bitmap
136  const_cast< BitmapPrimitiveShape* >(this)->BitmapExtent(*epsilon, bbox, params,
137  uextent, vextent);
138  if (*uextent < 2)
139  {
140  *uextent = 2;
141  }
142  if (*vextent < 2)
143  {
144  *vextent = 2;
145  }
146  bitmap->resize((*uextent) * (*vextent));
147  std::fill(bitmap->begin(), bitmap->end(), false);
148  // set all true bits in bitmap
149  bmpIdx->resize(params->size());
150  //#pragma omp parallel for schedule(static)
151  for (int i = 0; i < size; ++i)
152  {
153  std::pair< int, int > bmpParam;
154  InBitmap((*params)[i], *epsilon, *bbox, *uextent, *vextent, &bmpParam);
155  // clamp bitmap coords
156  bmpParam.first = GfxTL::Math< int >::Clamp(bmpParam.first, 0, *uextent - 1);
157  bmpParam.second = GfxTL::Math< int >::Clamp(bmpParam.second, 0, *vextent - 1);
158  (*bitmap)[(*bmpIdx)[i] = bmpParam.first + bmpParam.second * (*uextent)] = true;
159  }
160 }
161 
162 template< class IteratorT >
163 void BitmapPrimitiveShape::BuildBitmap(const PointCloud& pc, float* epsilon,
164  IteratorT begin, IteratorT end, MiscLib::Vector< std::pair< float, float > >* params,
166  size_t* uextent, size_t* vextent, MiscLib::Vector< size_t >* bmpIdx,
167  size_t border) const
168 {
169  params->resize(end - begin);
170  // compute parameters and extent
171  Parameters(pc[*begin].pos, &(*params)[0]);
172  bbox->Min() = bbox->Max() = GfxTL::Vector2Df((*params)[0].first,
173  (*params)[0].second);
174  size_t j = 1;
175  IteratorT i = begin;
176  for (++i; i != end; ++i, ++j)
177  {
178  Parameters(pc[*i].pos, &(*params)[j]);
179  if (bbox->Min()[0] > (*params)[j].first)
180  {
181  bbox->Min()[0] = (*params)[j].first;
182  }
183  else if (bbox->Max()[0] < (*params)[j].first)
184  {
185  bbox->Max()[0] = (*params)[j].first;
186  }
187  if (bbox->Min()[1] > (*params)[j].second)
188  {
189  bbox->Min()[1] = (*params)[j].second;
190  }
191  else if (bbox->Max()[1] < (*params)[j].second)
192  {
193  bbox->Max()[1] = (*params)[j].second;
194  }
195  }
196  // bbox gives the bounding box in parameter space
197  // we can now set up the bitmap
198  const_cast< BitmapPrimitiveShape* >(this)->BitmapExtent(*epsilon, bbox, params,
199  uextent, vextent);
200  if (*uextent < 2)
201  {
202  *uextent = 2;
203  }
204  if (*vextent < 2)
205  {
206  *vextent = 2;
207  }
208  bitmap->resize(((*uextent) + 2 * border) * ((*vextent) + 2 * border));
209  std::fill(bitmap->begin(), bitmap->end(), false);
210  // set all true bits in bitmap
211  bmpIdx->resize(params->size());
212  size_t lineWidth = (*uextent) + 2 * border;
213  for (size_t i = 0; i < params->size(); ++i)
214  {
215  std::pair< int, int > bmpParam;
216  InBitmap((*params)[i], *epsilon, *bbox, *uextent, *vextent, &bmpParam);
217  // clamp bitmap coords
218  bmpParam.first = GfxTL::Math< int >::Clamp(bmpParam.first, 0, *uextent - 1);
219  bmpParam.second = GfxTL::Math< int >::Clamp(bmpParam.second, 0, *vextent - 1);
220  (*bitmap)[(*bmpIdx)[i] = bmpParam.first + border
221  + (bmpParam.second + border) * lineWidth] = true;
222  }
223 }
224 
225 #endif
GfxTL::IndexedIterator
Definition: IndexedIterator.h:8
GfxTL::AABox::Max
Point & Max()
Definition: AABox.hpp:74
MiscLib::Vector::begin
T * begin()
Definition: Vector.h:460
Vector.h
Vec3f
Definition: basic.h:16
Performance.h
BitmapInfo::bbox
GfxTL::AABox< GfxTL::Vector2Df > bbox
Definition: BitmapPrimitiveShape.h:25
MiscLib::Vector::resize
void resize(size_type s, const value_type &v)
Definition: Vector.h:222
PrimitiveShape::ConnectedComponent
virtual size_t ConnectedComponent(const PointCloud &pc, float epsilon, MiscLib::Vector< size_t > *indices, bool doFiltering=true, float *borderRatio=0)=0
BitmapPrimitiveShape
Definition: BitmapPrimitiveShape.h:30
BitmapInfo::params
MiscLib::Vector< std::pair< float, float > > params
Definition: BitmapPrimitiveShape.h:23
PrimitiveShape::TrimmingPolygons
virtual void TrimmingPolygons(const PointCloud &pc, float epsilon, size_t begin, size_t end, std::deque< ComponentPolygons > *polys) const =0
PrimitiveShape::Parameters
virtual void Parameters(const Vec3f &p, std::pair< float, float > *param) const =0
BitmapInfo::bitmap
MiscLib::Vector< char > bitmap
Definition: BitmapPrimitiveShape.h:24
BasePrimitiveShape
Definition: BasePrimitiveShape.h:12
MiscLib::Vector
Definition: Vector.h:19
MiscLib::Vector< Point >::const_iterator
const typedef Point * const_iterator
Definition: Vector.h:26
BitmapInfo
Definition: BitmapPrimitiveShape.h:21
BitmapPrimitiveShape::BuildBitmap
void BuildBitmap(const PointCloud &pc, float *epsilon, IteratorT begin, IteratorT end, MiscLib::Vector< std::pair< float, float > > *params, GfxTL::AABox< GfxTL::Vector2Df > *bbox, MiscLib::Vector< char > *bitmap, size_t *uextent, size_t *vextent, MiscLib::Vector< size_t > *bmpIdx) const
Definition: BitmapPrimitiveShape.h:102
PrimitiveShape::InSpace
virtual bool InSpace(float u, float v, Vec3f *p, Vec3f *n) const =0
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
GfxTL::IndexIterate
IndexedIterator< IndexIteratorT, IteratorT > IndexIterate(IndexIteratorT idxIt, IteratorT it)
Definition: IndexedIterator.h:154
IndexIterator.h
AABox.h
MiscLib::Vector::end
T * end()
Definition: Vector.h:470
BitmapPrimitiveShape::m_extBbox
GfxTL::AABox< GfxTL::Vector2Df > m_extBbox
Definition: BitmapPrimitiveShape.h:98
GfxTL::Math::Clamp
static ScalarT Clamp(ScalarT s, ScalarT bottom, ScalarT top)
Definition: MathHelper.h:36
BitmapInfo::bmpIdx
MiscLib::Vector< size_t > bmpIdx
Definition: BitmapPrimitiveShape.h:26
IndexedIterator.h
PrimitiveShape::GenerateBitmapPoints
virtual void GenerateBitmapPoints(const PointCloud &pc, float epsilon, size_t begin, size_t end, PointCloud *bmpPc) const =0
Pair.h
PointCloud
Definition: PointCloud.h:69
BasePrimitiveShape.h
armarx::ctrlutil::v
double v(double t, double v0, double a0, double j)
Definition: CtrlUtil.h:39
BitmapInfo::vextent
size_t vextent
Definition: BitmapPrimitiveShape.h:27
GfxTL::Vector2Df
VectorXD< 2, float > Vector2Df
Definition: VectorXD.h:674
GfxTL::AABox::Min
Point & Min()
Definition: AABox.hpp:62
BitmapPrimitiveShape::Parameters
virtual void Parameters(const Vec3f &p, std::pair< float, float > *param) const =0
BitmapPrimitiveShape::BitmapExtent
virtual void BitmapExtent(float epsilon, GfxTL::AABox< GfxTL::Vector2Df > *bbox, MiscLib::Vector< std::pair< float, float > > *params, size_t *uextent, size_t *vextent)=0
DLL_LINKAGE
#define DLL_LINKAGE
Definition: basic.h:11
BitmapPrimitiveShape::InBitmap
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
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
MathHelper.h
BitmapInfo::uextent
size_t uextent
Definition: BitmapPrimitiveShape.h:27
IndexIterator
Definition: IndexIterator.h:9
GfxTL::AABox
Definition: AABox.h:18