Image Component Library (ICL)
Primitive3DFilter.h
Go to the documentation of this file.
1 /********************************************************************
2 ** Image Component Library (ICL) **
3 ** **
4 ** Copyright (C) 2006-2013 CITEC, University of Bielefeld **
5 ** Neuroinformatics Group **
6 ** Website: www.iclcv.org and **
7 ** http://opensource.cit-ec.de/projects/icl **
8 ** **
9 ** File : ICLGeom/src/ICLGeom/Primitive3DFilter.h **
10 ** Module : ICLGeom **
11 ** Authors: Lukas Twardon **
12 ** **
13 ** **
14 ** GNU LESSER GENERAL PUBLIC LICENSE **
15 ** This file may be used under the terms of the GNU Lesser General **
16 ** Public License version 3.0 as published by the **
17 ** **
18 ** Free Software Foundation and appearing in the file LICENSE.LGPL **
19 ** included in the packaging of this file. Please review the **
20 ** following information to ensure the license requirements will **
21 ** be met: http://www.gnu.org/licenses/lgpl-3.0.txt **
22 ** **
23 ** The development of this software was supported by the **
24 ** Excellence Cluster EXC 277 Cognitive Interaction Technology. **
25 ** The Excellence Cluster EXC 277 is a grant of the Deutsche **
26 ** Forschungsgemeinschaft (DFG) in the context of the German **
27 ** Excellence Initiative. **
28 ** **
29 ********************************************************************/
30 
31 #pragma once
32 
34 #include <ICLGeom/SceneObject.h>
35 
36 #ifdef ICL_HAVE_OPENCL
37 #include "ICLUtils/CLProgram.h"
38 #endif
39 
40 namespace icl{
41  namespace geom{
42 
45 
46  public:
47 
53  };
54 
56  struct Quaternion {
57 
59 
64  Quaternion(const math::Vec3 &v, const float w, bool givenInAxisAngle = false) {
65  if(givenInAxisAngle) {
66  math::Vec3 vn = v.normalized();
67  float s = sin(w/2.0);
68  this->v[0] = vn[0] * s;
69  this->v[1] = vn[1] * s;
70  this->v[2] = vn[2] * s;
71  this->w = cos(w/2.0);
72  if(vn.length() <= 0.0001)
73  this->w = 1;
74  } else {
75  this->v = v;
76  this->w = w;
77  }
78  }
79 
81  const Quaternion operator*(const Quaternion &q) {
82  Quaternion res(q);
83  res.w = w*q.w - v[0]*q.v[0] - v[1]*q.v[1] - v[2]*q.v[2];
84  res.v[0] = w*q.v[0] + v[0]*q.w + v[1]*q.v[2] - v[2]*q.v[1];
85  res.v[1] = w*q.v[1] - v[0]*q.v[2] + v[1]*q.w + v[2]*q.v[0];
86  res.v[2] = w*q.v[2] + v[0]*q.v[1] - v[1]*q.v[0] + v[2]*q.w;
87  return res;
88  }
89 
91  Quaternion conj() const {
92  Quaternion res(*this);
93  res.v *= -1;
94  return res;
95  }
96 
99  float x = v[0];
100  float y = v[1];
101  float z = v[2];
102  float xx = x*x;
103  float yy = y*y;
104  float zz = z*z;
105  return math::Mat4 (1-2*yy-2*zz, 2*x*y-2*w*z, 2*x*z+2*w*y, 0,
106  2*x*y+2*w*z, 1-2*xx-2*zz, 2*y*z-2*w*x, 0,
107  2*x*z-2*w*y, 2*y*z+2*w*x, 1-2*xx-2*yy, 0,
108  0,0,0,1);
109  }
110 
112 
117  Quaternion qIn(vIn, 0);
118  Quaternion qOut = qIn * this->conj();
119  qOut = (*this) * qOut;
120  return qOut.v;
121  }
122 
125 
127  float w;
128 
129  };
130 
132  struct Primitive3D {
133 
136  const Vec &scale, unsigned long timestamp, const std::string &description = "") :
138 
139  }
140 
142  void toSceneObject(SceneObject *object, uint32_t slices = 15, GeomColor const &color = geom_white(100));
143 
146 
149 
152 
155 
157  unsigned long timestamp;
158 
160  std::string description;
161 
163  unsigned char groupBit;
164 
165  };
166 
168  struct FilterAction {
169 
172 
174  FilterAction(std::vector<unsigned char> formula) : formula(formula) {}
175 
176  virtual ~FilterAction() {}
177 
179 
185  virtual void performAction(PointCloudObjectBase &pcObj, std::vector<unsigned char> &actionMap,
186  std::vector<unsigned char> &groupMap, core::Img32f *depthImage) = 0;
187 
192  std::vector<unsigned char> formula;
193 
194  };
195 
198 
200  RemoveAction(std::vector<unsigned char> formula) : FilterAction(formula) {}
201 
202  virtual ~RemoveAction() {}
203 
204  void performAction(PointCloudObjectBase &pcObj, std::vector<unsigned char> &actionMap,
205  std::vector<unsigned char> &groupMap, core::Img32f *depthImage);
206 
207  };
208 
211 
213  SetposAction(std::vector<unsigned char> formula, float x, float y, float z) : FilterAction(formula), x(x), y(y), z(z) {}
214 
215  virtual ~SetposAction() {}
216 
217  void performAction(PointCloudObjectBase &pcObj, std::vector<unsigned char> &actionMap,
218  std::vector<unsigned char> &groupMap, core::Img32f *depthImage);
219 
221  float x;
222  float y;
223  float z;
224 
225  };
226 
229 
231  ColorAction(std::vector<unsigned char> formula, float r, float g, float b, float a) : FilterAction(formula), r(r), g(g), b(b), a(a) {}
232 
233  virtual ~ColorAction() {}
234 
235  void performAction(PointCloudObjectBase &pcObj, std::vector<unsigned char> &actionMap,
236  std::vector<unsigned char> &groupMap, core::Img32f *depthImage);
237 
239  float r;
240  float g;
241  float b;
242  float a;
243 
244  };
245 
248 
250  LabelAction(std::vector<unsigned char> formula, icl32s value) : FilterAction(formula), value(value) {}
251 
252  virtual ~LabelAction() {}
253 
254  void performAction(PointCloudObjectBase &pcObj, std::vector<unsigned char> &actionMap,
255  std::vector<unsigned char> &groupMap, core::Img32f *depthImage);
256 
259 
260  };
261 
264 
266  IntensityAction(std::vector<unsigned char> formula, float value) : FilterAction(formula), value(value) {}
267 
268  virtual ~IntensityAction() {}
269 
270  void performAction(PointCloudObjectBase &pcObj, std::vector<unsigned char> &actionMap,
271  std::vector<unsigned char> &groupMap, core::Img32f *depthImage);
272 
274  float value;
275 
276  };
277 
280 
282  FilterDepthImgAction(std::vector<unsigned char> formula, float value) : FilterAction(formula), value(value) {}
283 
285 
286  void performAction(PointCloudObjectBase &pcObj, std::vector<unsigned char> &actionMap,
287  std::vector<unsigned char> &groupMap, core::Img32f *depthImage);
288 
290  float value;
291 
292  };
293 
295  struct FilterConfig {
296 
298 
301  FilterConfig(const std::string &filename);
302 
304  std::map<std::string, unsigned char> mapGroupIdToBit;
305 
307  std::map<std::string, unsigned char> mapRegexToBit;
308 
310  std::map<unsigned char, float> mapGroupBitToPadding;
311 
313  std::vector<utils::SmartPtr<FilterAction> > filterActions;
314 
315  };
316 
319 
321  virtual ~Primitive3DFilter() {}
322 
325  this->config = config;
326  }
327 
329 
334  void apply(const std::vector<Primitive3D> &primitives, PointCloudObjectBase &pcObj, core::Img32f *depthImage = 0);
335 
336  private:
337 
338  #ifdef ICL_HAVE_OPENCL
343  #endif
344 
345  static const char *KERNEL_CODE;
347 
348  };
349 
350  } // namespace geom
351 }
float z
Definition: Primitive3DFilter.h:223
void performAction(PointCloudObjectBase &pcObj, std::vector< unsigned char > &actionMap, std::vector< unsigned char > &groupMap, core::Img32f *depthImage)
perform the actual filter action
virtual ~FilterAction()
Definition: Primitive3DFilter.h:176
static const char * KERNEL_CODE
Definition: Primitive3DFilter.h:345
FilterDepthImgAction(std::vector< unsigned char > formula, float value)
Constructor.
Definition: Primitive3DFilter.h:282
void performAction(PointCloudObjectBase &pcObj, std::vector< unsigned char > &actionMap, std::vector< unsigned char > &groupMap, core::Img32f *depthImage)
perform the actual filter action
FixedMatrix< icl32f, 4, 4 > Mat4
typedef for 4x4 fixed matrices
Definition: HomogeneousMath.h:49
setpos action
Definition: Primitive3DFilter.h:210
undocument this line if you encounter any issues!
Definition: Any.h:37
float w
scalar part
Definition: Primitive3DFilter.h:127
Base class for point cloud data types.
Definition: PointCloudObjectBase.h:98
float a
Definition: Primitive3DFilter.h:242
std::vector< unsigned char > formula
Definition: Primitive3DFilter.h:192
float b
Definition: Primitive3DFilter.h:241
virtual ~Primitive3DFilter()
Destructor.
Definition: Primitive3DFilter.h:321
Quaternion(const math::Vec3 &v, const float w, bool givenInAxisAngle=false)
Constructor.
Definition: Primitive3DFilter.h:64
Vec scale
scale (e.g., [2r 2r 2r] for a sphere with radius r)
Definition: Primitive3DFilter.h:154
std::string description
string describing the object (e.g., a robot link)
Definition: Primitive3DFilter.h:160
Definition: Primitive3DFilter.h:51
Wrapper for an OpenCL Kernel.
Definition: CLKernel.h:72
ColorAction(std::vector< unsigned char > formula, float r, float g, float b, float a)
Constructor.
Definition: Primitive3DFilter.h:231
Primitive3DFilter(const FilterConfig &config)
Constructor.
GeomColor geom_white(float alpha=255)
inline utililty function to create a white color instance
Definition: GeomDefs.h:48
utils::CLKernel kernelCreateGroupMap
Definition: Primitive3DFilter.h:341
unsigned long timestamp
timestamp of creation
Definition: Primitive3DFilter.h:157
FixedMatrix< T, COLS, ROWS > normalized(T norm=2) const
create a normalized version of this matrix
Definition: FixedMatrix.h:850
FilterAction()
Default constructor.
Definition: Primitive3DFilter.h:171
quaternion describing the orientation of the primitive
Definition: Primitive3DFilter.h:56
Quaternion conj() const
complex conjugate
Definition: Primitive3DFilter.h:91
utils::CLProgram program
Definition: Primitive3DFilter.h:339
float value
value
Definition: Primitive3DFilter.h:290
float r
parameters
Definition: Primitive3DFilter.h:239
utils::CLKernel kernelCreateActionMap
Definition: Primitive3DFilter.h:342
std::map< unsigned char, float > mapGroupBitToPadding
map groupBit to padding
Definition: Primitive3DFilter.h:310
IntensityAction(std::vector< unsigned char > formula, float value)
Constructor.
Definition: Primitive3DFilter.h:266
PrimitiveType type
the type of primitive
Definition: Primitive3DFilter.h:145
utils::CLBuffer formulabuffer
Definition: Primitive3DFilter.h:340
void performAction(PointCloudObjectBase &pcObj, std::vector< unsigned char > &actionMap, std::vector< unsigned char > &groupMap, core::Img32f *depthImage)
perform the actual filter action
unsigned char groupBit
internal group id (see PrimitiveGroup)
Definition: Primitive3DFilter.h:163
filterdepthimg action
Definition: Primitive3DFilter.h:279
virtual ~ColorAction()
Definition: Primitive3DFilter.h:233
intensity action
Definition: Primitive3DFilter.h:263
Ipp32s icl32s
32bit signed integer type for the ICL
Definition: BasicTypes.h:58
RemoveAction(std::vector< unsigned char > formula)
Constructor.
Definition: Primitive3DFilter.h:200
void performAction(PointCloudObjectBase &pcObj, std::vector< unsigned char > &actionMap, std::vector< unsigned char > &groupMap, core::Img32f *depthImage)
perform the actual filter action
a general filter action
Definition: Primitive3DFilter.h:168
void performAction(PointCloudObjectBase &pcObj, std::vector< unsigned char > &actionMap, std::vector< unsigned char > &groupMap, core::Img32f *depthImage)
perform the actual filter action
icl32s value
value
Definition: Primitive3DFilter.h:258
Wrapper for an OpenCL Buffer.
Definition: CLBuffer.h:52
float g
Definition: Primitive3DFilter.h:240
const Quaternion operator *(const Quaternion &q)
Hamilton product.
Definition: Primitive3DFilter.h:81
SetposAction(std::vector< unsigned char > formula, float x, float y, float z)
Constructor.
Definition: Primitive3DFilter.h:213
double length(T norm=2) const
Calculates the length of the matrix data vector.
Definition: FixedMatrix.h:835
FilterConfig(const std::string &filename)
Constructor.
Class for filtering point clouds according to a set of primitives and a filter configuration.
Definition: Primitive3DFilter.h:44
float x
parameters
Definition: Primitive3DFilter.h:221
Definition: Primitive3DFilter.h:52
color action
Definition: Primitive3DFilter.h:228
FilterConfig config
Definition: Primitive3DFilter.h:346
utils::CLBuffer groupmapbuffer
Definition: Primitive3DFilter.h:340
PrimitiveType
the primitive type
Definition: Primitive3DFilter.h:49
void toSceneObject(SceneObject *object, uint32_t slices=15, GeomColor const &color=geom_white(100))
renders this 3D primitive into the scene object (by adding a child object to SceneObject *object)
void apply(const std::vector< Primitive3D > &primitives, PointCloudObjectBase &pcObj, core::Img32f *depthImage=0)
applies the filter operation to the given point cloud
FilterAction(std::vector< unsigned char > formula)
Constructor.
Definition: Primitive3DFilter.h:174
math::Mat4 getTransformationMatrix()
convert to transformation matrix
Definition: Primitive3DFilter.h:98
ICLQt_API void color(float r, float g=-1, float b=-1, float alpha=255)
sets the current color to given r,g,b,alpha value
remove action
Definition: Primitive3DFilter.h:197
float value
value
Definition: Primitive3DFilter.h:274
Primitive3D(const PrimitiveType &type, const Vec &position, const Quaternion &orientation, const Vec &scale, unsigned long timestamp, const std::string &description="")
Constructor.
Definition: Primitive3DFilter.h:135
std::map< std::string, unsigned char > mapGroupIdToBit
map primitive group id to internal groupBit
Definition: Primitive3DFilter.h:304
Quaternion orientation
orientation of the primitive
Definition: Primitive3DFilter.h:151
math::Vec3 v
vector part
Definition: Primitive3DFilter.h:124
utils::CLBuffer actionmapbuffer
Definition: Primitive3DFilter.h:340
float y
Definition: Primitive3DFilter.h:222
virtual ~SetposAction()
Definition: Primitive3DFilter.h:215
virtual void performAction(PointCloudObjectBase &pcObj, std::vector< unsigned char > &actionMap, std::vector< unsigned char > &groupMap, core::Img32f *depthImage)=0
perform the actual filter action
utils::CLBuffer pcbuffer
Definition: Primitive3DFilter.h:340
void performAction(PointCloudObjectBase &pcObj, std::vector< unsigned char > &actionMap, std::vector< unsigned char > &groupMap, core::Img32f *depthImage)
perform the actual filter action
filter config
Definition: Primitive3DFilter.h:295
Definition: Primitive3DFilter.h:50
void setConfig(const FilterConfig &config)
set filter config
Definition: Primitive3DFilter.h:324
std::map< std::string, unsigned char > mapRegexToBit
map regular expression (matching the primitive description) to internal groupBit
Definition: Primitive3DFilter.h:307
math::Vec3 rotateVector(const math::Vec3 &vIn)
rotate a given vector according to the quaternion
Definition: Primitive3DFilter.h:116
virtual ~RemoveAction()
Definition: Primitive3DFilter.h:202
virtual ~IntensityAction()
Definition: Primitive3DFilter.h:268
Vec position
position of the primitive center
Definition: Primitive3DFilter.h:148
std::vector< utils::SmartPtr< FilterAction > > filterActions
all filter actions to be performed
Definition: Primitive3DFilter.h:313
virtual ~LabelAction()
Definition: Primitive3DFilter.h:252
Main class for OpenCL based accelleration.
Definition: CLProgram.h:259
virtual ~FilterDepthImgAction()
Definition: Primitive3DFilter.h:284
The SceneObject class defines visible objects in scenes or scene graph nodes.
Definition: SceneObject.h:140
label action
Definition: Primitive3DFilter.h:247
a primitive
Definition: Primitive3DFilter.h:132
LabelAction(std::vector< unsigned char > formula, icl32s value)
Constructor.
Definition: Primitive3DFilter.h:250