Image Component Library (ICL)
PointCloudObjectBase.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/PointCloudObjectBase.h **
10 ** Module : ICLGeom **
11 ** Authors: Christof Elbrechter, Patrick Nobou, Andre Ueckermann **
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 
33 #include <ICLUtils/CompatMacros.h>
34 #include <ICLUtils/Time.h>
35 #include <ICLGeom/SceneObject.h>
36 #include <ICLCore/DataSegment.h>
37 #include <ICLCore/ImgBase.h>
38 #include <map>
39 
40 namespace icl{
41  namespace geom{
42 
44 
101 
102  protected:
103 
104  static float length(Vec d){
105  float l = sqrt(d[0]*d[0]+d[1]*d[1]+d[2]*d[2]);
106  return l;
107  }
108 
111 
113  std::map<std::string,std::string> m_metaData;
114 
116  template<class T, int N>
117  core::DataSegment<T,N> &error(const std::string &fname) {
118  throw utils::ICLException("static feature "+fname+" is not supported by this PointCloudObjectBase instance");
119  static core::DataSegment<T,N> dummy; return dummy;
120  }
121 
123  core::DataSegmentBase &error_dyn(const std::string &featureName) {
124  throw utils::ICLException("dynamic feature "+featureName+" is not supported by this PointCloudObjectBase instance");
125  static core::DataSegmentBase dummy; return dummy;
126  }
127 
129  virtual void drawNormalLines();
130 
134 
142 
143  //GLuint texName;//
144  //int lastTextureWidth, lastTextureHeight;//
145 
146 
147  public:
148 
150  enum FeatureType {
155 
156  BGR,
159 
160  // 4D vector components
161  XYZ,
165 
166  NUM_FEATURES
167  };
168 
170 
171  PointCloudObjectBase():timestamp(utils::Time::null){
172  setLockingEnabled(true);
173  m_defaultPointColor = GeomColor(0,0.5,1,1);
174  useDrawNormalLines=false;
175  useMasking=false;
176  useTriangulation=false;
177  useTexturing=false;
178  //glGenTextures(1,&texName);//
179  //lastTextureWidth=0;//
180  //lastTextureHeight=0;//
181 
182  }
183 
185  virtual void setTime(const utils::Time &t) { this->timestamp = t; }
186 
188  virtual const utils::Time &getTime() const { return this->timestamp; }
189 
191  virtual bool supports(FeatureType t) const = 0;
192 
194 
195  virtual bool canAddFeature(FeatureType t) const { return false; }
196 
198 
202  virtual void addFeature(FeatureType t) {
203  throw utils::ICLException("unable to add given feature to point cloud");
204  }
205 
207  virtual bool isOrganized() const = 0;
208 
210  virtual utils::Size getSize() const = 0;
211 
213  virtual int getDim() const = 0;
214 
216 
222  virtual void setSize(const utils::Size &size) = 0;
223 
225  inline void setDim(int dim){
226  setSize(utils::Size(dim,-1));
227  }
228 
230  virtual core::DataSegment<float,3> selectXYZ(){ return error<float,3>(__FUNCTION__); }
231 
233  virtual core::DataSegment<float,4> selectXYZH(){ return error<float,4>(__FUNCTION__); }
234 
236  virtual core::DataSegment<float,1> selectIntensity(){ return error<float,1>(__FUNCTION__); }
237 
239  virtual core::DataSegment<float,1> selectDepth(){ return error<float,1>(__FUNCTION__); }
240 
242  virtual core::DataSegment<icl32s,1> selectLabel(){ return error<icl32s,1>(__FUNCTION__); }
243 
245  virtual core::DataSegment<icl8u,3> selectBGR(){ return error<icl8u,3>(__FUNCTION__); }
246 
248  virtual core::DataSegment<icl8u,4> selectBGRA(){ return error<icl8u,4>(__FUNCTION__); }
249 
251  virtual core::DataSegment<icl32s,1> selectBGRA32s(){ return error<icl32s,1>(__FUNCTION__); }
252 
254 
255  virtual core::DataSegment<float,4> selectNormal(){ return error<float,4>(__FUNCTION__); }
256 
258  virtual core::DataSegment<float,4> selectRGBA32f(){ return error<float,4>(__FUNCTION__); }
259 
261 
263  virtual core::DataSegmentBase select(const std::string &featureName) { return error_dyn(featureName); }
264 
265  // const select methds
266 
268  const core::DataSegment<float,3> selectXYZ() const { return const_cast<PointCloudObjectBase*>(this)->selectXYZ(); }
269 
271  const core::DataSegment<float,4> selectXYZH() const { return const_cast<PointCloudObjectBase*>(this)->selectXYZH(); }
272 
274  const core::DataSegment<float,1> selectIntensity() const { return const_cast<PointCloudObjectBase*>(this)->selectIntensity(); }
275 
277  const core::DataSegment<float,1> selectDepth() const { return const_cast<PointCloudObjectBase*>(this)->selectDepth(); }
278 
280  const core::DataSegment<icl32s,1> selectLabel() const { return const_cast<PointCloudObjectBase*>(this)->selectLabel(); }
281 
283  const core::DataSegment<icl8u,3> selectBGR() const { return const_cast<PointCloudObjectBase*>(this)->selectBGR(); }
284 
286  const core::DataSegment<icl8u,4> selectBGRA() const { return const_cast<PointCloudObjectBase*>(this)->selectBGRA(); }
287 
289  const core::DataSegment<icl32s,1> selectBGRA32s() const { return const_cast<PointCloudObjectBase*>(this)->selectBGRA32s(); }
290 
292  const core::DataSegment<float,4> selectNormal() const { return const_cast<PointCloudObjectBase*>(this)->selectNormal(); }
293 
295  const core::DataSegment<float,4> selectRGBA32f() const { return const_cast<PointCloudObjectBase*>(this)->selectRGBA32f(); }
296 
298  const core::DataSegmentBase select(const std::string &featureName) const {
299  return const_cast<PointCloudObjectBase*>(this)->select(featureName);
300  }
301 
303 
304  void setColorsFromImage(const core::ImgBase &image) ;
305 
307 
308  void extractColorsToImage(core::ImgBase &image, bool withAlpha=false) const ;
309 
311  void setDefaultVertexColor(const GeomColor &color);
312 
314  virtual GeomColor getDefaultVertexColor() const{ return m_defaultPointColor*255; }
315 
317  virtual std::vector<std::string> getSupportedDynamicFeatures() const {
318  return std::vector<std::string>();
319  }
320 
322 
328  virtual void customRender();
329 
331  void setUseDrawNormalLines(bool use, float lineLength=40, int granularity=4);
332 
333  // set use masking (0 render, 1 dont render)
334  void setUseMasking(bool use, core::Img8u &mask);
335 
336  //set use triangulation
337  void setUseTriangulation(bool use, float maxDelta=50);
338 
339  //set texturing
340  void setUseTexturing(bool use, core::Img8u &tex, core::DataSegment<float,2> texCoords);
341 
343  virtual PointCloudObjectBase *copy() const {
344  return 0;
345  }
346 
348  virtual void deepCopy(PointCloudObjectBase &dst) const;
349 
351  virtual bool equals(const PointCloudObjectBase &dst,
352  bool compareOnlySharedFeatures=false,
353  bool allowDifferentColorTypes=true,
354  float tollerance=1.0e-5) const;
355 
357  std::map<std::string,std::string> &getMetaData();
358 
360  const std::map<std::string,std::string> &getMetaData() const;
361 
363  const std::string &getMetaData(const std::string &key) const ;
364 
366  bool hasMetaData(const std::string &key) const;
367 
369  bool hasAnyMetaData() const;
370 
372  void setMetaData(const std::string &key, const std::string &value);
373 
375  void clearAllMetaData();
376 
378  void clearMetaData(const std::string &key);
379 
381  std::vector<std::string> getAllMetaDataEntries() const;
382  };
383 
385  ICLGeom_API std::ostream &operator<<(std::ostream &s, const PointCloudObjectBase::FeatureType t);
386  } // namespace geom
387 }
388 
ICLQt_API ImgQ sqrt(const ImgQ &image)
calls sqrt( each pixel)
core::DataSegment< T, N > & error(const std::string &fname)
internally used utility method that throws verbose exceptions
Definition: PointCloudObjectBase.h:117
std::map< std::string, std::string > m_metaData
internal map of meta data
Definition: PointCloudObjectBase.h:113
const core::DataSegment< float, 1 > selectDepth() const
const intensity data
Definition: PointCloudObjectBase.h:277
virtual core::DataSegment< float, 4 > selectRGBA32f()
well known feature RGBA (4 float values, ordred RGBA)
Definition: PointCloudObjectBase.h:258
const core::DataSegment< icl8u, 4 > selectBGRA() const
const rgba data
Definition: PointCloudObjectBase.h:286
undocument this line if you encounter any issues!
Definition: Any.h:37
core::Img8u maskImage
Definition: PointCloudObjectBase.h:136
const core::DataSegmentBase select(const std::string &featureName) const
const dynamic/custom data
Definition: PointCloudObjectBase.h:298
Base class for point cloud data types.
Definition: PointCloudObjectBase.h:98
virtual GeomColor getDefaultVertexColor() const
implements the SceneObject's virtual getter function for this feature
Definition: PointCloudObjectBase.h:314
bool useTexturing
Definition: PointCloudObjectBase.h:139
core::DataSegmentBase & error_dyn(const std::string &featureName)
internally used utility method that throws verbose exceptions
Definition: PointCloudObjectBase.h:123
virtual const utils::Time & getTime() const
returns the current timestamp
Definition: PointCloudObjectBase.h:188
void setDim(int dim)
sets the number of contained points (and enables the unorganized mode)
Definition: PointCloudObjectBase.h:225
#define ICLGeom_API
Definition: CompatMacros.h:179
utils::Time timestamp
timestamp associated with the point cloud
Definition: PointCloudObjectBase.h:100
ICL Time class (taken from the Ice lib)
Definition: Time.h:52
virtual core::DataSegment< icl32s, 1 > selectLabel()
well known feature Intensity (single 32bit int values)
Definition: PointCloudObjectBase.h:242
virtual core::DataSegment< icl8u, 4 > selectBGRA()
well known feature Intensity (four byte vectors ordered BGRA)
Definition: PointCloudObjectBase.h:248
virtual core::DataSegmentBase select(const std::string &featureName)
dynamic feature selection function
Definition: PointCloudObjectBase.h:263
const core::DataSegment< float, 4 > selectNormal() const
const normals data
Definition: PointCloudObjectBase.h:292
PointCloudObjectBase()
Default constructor.
Definition: PointCloudObjectBase.h:171
const core::DataSegment< float, 4 > selectRGBA32f() const
const rgba32f data
Definition: PointCloudObjectBase.h:295
virtual bool canAddFeature(FeatureType t) const
interface function for dynamic Point cloud types that can dynamically add features
Definition: PointCloudObjectBase.h:195
const core::DataSegment< icl8u, 3 > selectBGR() const
const bgr data
Definition: PointCloudObjectBase.h:283
[float x,y,z, padding]
Definition: PointCloudObjectBase.h:161
[uchar b,g,r, alpha]
Definition: PointCloudObjectBase.h:157
virtual std::vector< std::string > getSupportedDynamicFeatures() const
For subclasses that provide Dynamic features, this function must be implemented.
Definition: PointCloudObjectBase.h:317
virtual core::DataSegment< icl8u, 3 > selectBGR()
well known feature Intensity (three byte vectors ordered BGR)
Definition: PointCloudObjectBase.h:245
Abstract data segment class.
Definition: DataSegmentBase.h:99
int normalLineGranularity
Definition: PointCloudObjectBase.h:133
virtual core::DataSegment< float, 3 > selectXYZ()
well know features XYZ (three floats, this feature must usually be available)
Definition: PointCloudObjectBase.h:230
virtual core::DataSegment< float, 4 > selectNormal()
well known feature Normal (4 float values)
Definition: PointCloudObjectBase.h:255
virtual void setTime(const utils::Time &t)
sets the current timestamp
Definition: PointCloudObjectBase.h:185
static float length(Vec d)
Definition: PointCloudObjectBase.h:104
FeatureType
List of well known features.
Definition: PointCloudObjectBase.h:150
virtual core::DataSegment< float, 4 > selectXYZH()
common way to store XYZ-data (4th float define homogeneous part)
Definition: PointCloudObjectBase.h:233
ICLGeom_API std::ostream & operator<<(std::ostream &os, const Camera &cam)
ostream operator (writes camera in XML core::format)
Size class of the ICL.
Definition: Size.h:61
[float nx,ny,nz,curvature]
Definition: PointCloudObjectBase.h:163
const core::DataSegment< float, 1 > selectIntensity() const
const intensity data
Definition: PointCloudObjectBase.h:274
virtual void addFeature(FeatureType t)
interface for adding a feature to an existing point cloud instance
Definition: PointCloudObjectBase.h:202
virtual core::DataSegment< float, 1 > selectIntensity()
well known feature Intensity (single float values)
Definition: PointCloudObjectBase.h:236
bool useDrawNormalLines
Definition: PointCloudObjectBase.h:131
bgra packed as one icl32s
Definition: PointCloudObjectBase.h:158
single float depth value (interpretation suggestion: dist to camera center)
Definition: PointCloudObjectBase.h:154
const core::DataSegment< float, 3 > selectXYZ() const
const xyz data
Definition: PointCloudObjectBase.h:268
GeomColor m_defaultPointColor
default color used to render points that have no color information
Definition: PointCloudObjectBase.h:110
virtual PointCloudObjectBase * copy() const
deep copy interface (needs to be implemented by subclasses)
Definition: PointCloudObjectBase.h:343
core::DataSegment< float, 2 > textureCoordinates
Definition: PointCloudObjectBase.h:141
const core::DataSegment< icl32s, 1 > selectBGRA32s() const
const bgra32s data
Definition: PointCloudObjectBase.h:289
scalar components 4 bytes each!
Definition: PointCloudObjectBase.h:152
core::Color4D32f GeomColor
color for geometry primitives
Definition: GeomDefs.h:45
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
virtual core::DataSegment< float, 1 > selectDepth()
well known feature Depth (single float values)
Definition: PointCloudObjectBase.h:239
single int32 label
Definition: PointCloudObjectBase.h:153
Base class for Exception handling in the ICL.
Definition: Exception.h:42
[uchar b,g,r, padding]
Definition: PointCloudObjectBase.h:156
float maxDeltaValue
Definition: PointCloudObjectBase.h:138
[float r,g,b,a ]
Definition: PointCloudObjectBase.h:164
bool useMasking
Definition: PointCloudObjectBase.h:135
float normalLineLength
Definition: PointCloudObjectBase.h:132
The DataSegment class defines a strided data segment (or 1D or 2D ordred array of vectors)
Definition: DataSegment.h:147
virtual core::DataSegment< icl32s, 1 > selectBGRA32s()
well known feature Intensity (single int value encoding byte-wise BGRA)
Definition: PointCloudObjectBase.h:251
ImgBase is the Image-Interface class that provides save access to underlying Img-template .
Definition: ImgBase.h:131
const core::DataSegment< float, 4 > selectXYZH() const
const xyzh data
Definition: PointCloudObjectBase.h:271
The SceneObject class defines visible objects in scenes or scene graph nodes.
Definition: SceneObject.h:140
bool useTriangulation
Definition: PointCloudObjectBase.h:137
core::Img8u textureImage
Definition: PointCloudObjectBase.h:140
const core::DataSegment< icl32s, 1 > selectLabel() const
const label data
Definition: PointCloudObjectBase.h:280
[float x,y,z, homogenous part]
Definition: PointCloudObjectBase.h:162