Image Component Library (ICL)
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
PointCloudObjectBase.h
Go to the documentation of this file.
00001 /********************************************************************
00002 **                Image Component Library (ICL)                    **
00003 **                                                                 **
00004 ** Copyright (C) 2006-2013 CITEC, University of Bielefeld          **
00005 **                         Neuroinformatics Group                  **
00006 ** Website: www.iclcv.org and                                      **
00007 **          http://opensource.cit-ec.de/projects/icl               **
00008 **                                                                 **
00009 ** File   : ICLGeom/src/ICLGeom/PointCloudObjectBase.h             **
00010 ** Module : ICLGeom                                                **
00011 ** Authors: Christof Elbrechter, Patrick Nobou                     **
00012 **                                                                 **
00013 **                                                                 **
00014 ** GNU LESSER GENERAL PUBLIC LICENSE                               **
00015 ** This file may be used under the terms of the GNU Lesser General **
00016 ** Public License version 3.0 as published by the                  **
00017 **                                                                 **
00018 ** Free Software Foundation and appearing in the file LICENSE.GPL  **
00019 ** included in the packaging of this file.  Please review the      **
00020 ** following information to ensure the license requirements will   **
00021 ** be met: http://www.gnu.org/licenses/lgpl-3.0.txt                **
00022 **                                                                 **
00023 ** The development of this software was supported by the           **
00024 ** Excellence Cluster EXC 277 Cognitive Interaction Technology.    **
00025 ** The Excellence Cluster EXC 277 is a grant of the Deutsche       **
00026 ** Forschungsgemeinschaft (DFG) in the context of the German       **
00027 ** Excellence Initiative.                                          **
00028 **                                                                 **
00029 ********************************************************************/
00030 
00031 #pragma once
00032 
00033 #include <ICLGeom/SceneObject.h>
00034 #include <ICLGeom/DataSegment.h>
00035 #include <ICLCore/ImgBase.h>
00036 #include <map>
00037 
00038 namespace icl{
00039   namespace geom{
00040   
00042 
00096     class PointCloudObjectBase : public SceneObject{
00097       protected:
00098       
00100       GeomColor m_defaultPointColor;
00101       
00103       std::map<std::string,std::string> m_metaData;
00104       
00106       template<class T, int N>
00107       DataSegment<T,N> &error(const std::string &fname) throw (utils::ICLException){
00108         throw utils::ICLException("static feature "+fname+" is not supported by this PointCloudObjectBase instance");
00109         static DataSegment<T,N> dummy; return dummy;
00110       }
00111   
00113       DataSegmentBase &error_dyn(const std::string &featureName) throw (utils::ICLException){
00114         throw utils::ICLException("dynamic feature "+featureName+" is not supported by this PointCloudObjectBase instance");
00115         static DataSegmentBase dummy; return dummy;
00116       }
00117       
00119       virtual void drawNormalLines();
00120       
00121       bool useDrawNormalLines;
00122       float normalLineLength;
00123       int normalLineGranularity;
00124   
00125       public:
00126   
00128       enum FeatureType {
00130         Intensity,      
00131         Label,          
00132   
00133         BGR,            
00134         BGRA,           
00135         BGRA32s,        
00136   
00137         // 4D vector components
00138         XYZ,            
00139         XYZH,           
00140         Normal,         
00141         RGBA32f,        
00142   
00143         NUM_FEATURES
00144       };
00145   
00147 
00148       PointCloudObjectBase(){
00149         setLockingEnabled(true);
00150         m_defaultPointColor = GeomColor(0,0.5,1,1);
00151         useDrawNormalLines=false;
00152       }
00153   
00155       virtual bool supports(FeatureType t) const = 0;
00156   
00158       virtual bool isOrganized() const = 0;
00159   
00161       virtual utils::Size getSize() const throw (utils::ICLException) = 0;
00162       
00164       virtual int getDim() const = 0;
00165       
00167 
00173       virtual void setSize(const utils::Size &size) = 0;
00174   
00176       inline void setDim(int dim){
00177         setSize(utils::Size(dim,-1));
00178       }
00179   
00181       virtual DataSegment<float,3> selectXYZ(){ return error<float,3>(__FUNCTION__);   }
00182       
00184       virtual DataSegment<float,4> selectXYZH(){ return  error<float,4>(__FUNCTION__);   }
00185       
00187       virtual DataSegment<float,1> selectIntensity(){   return error<float,1>(__FUNCTION__);   }
00188   
00190       virtual DataSegment<icl32s,1> selectLabel(){      return error<icl32s,1>(__FUNCTION__);  }
00191   
00193       virtual DataSegment<icl8u,3> selectBGR(){         return error<icl8u,3>(__FUNCTION__);   }
00194   
00196       virtual DataSegment<icl8u,4> selectBGRA(){        return error<icl8u,4>(__FUNCTION__);   }
00197   
00199       virtual DataSegment<icl32s,1> selectBGRA32s(){    return error<icl32s,1>(__FUNCTION__);   }
00200   
00202 
00203       virtual DataSegment<float,4> selectNormal(){      return error<float,4>(__FUNCTION__);   }
00204   
00206       virtual DataSegment<float,4> selectRGBA32f(){     return error<float,4>(__FUNCTION__);   }
00207 
00209 
00211       virtual DataSegmentBase select(const std::string &featureName) { return error_dyn(featureName); }
00212   
00213       // const select methds
00214 
00216       const DataSegment<float,3> selectXYZ() const { return const_cast<PointCloudObjectBase*>(this)->selectXYZ(); }
00217       
00219       const DataSegment<float,4> selectXYZH() const { return const_cast<PointCloudObjectBase*>(this)->selectXYZH(); }
00220   
00222       const DataSegment<float,1> selectIntensity() const { return const_cast<PointCloudObjectBase*>(this)->selectIntensity(); }
00223       
00225       const DataSegment<icl32s,1> selectLabel() const { return const_cast<PointCloudObjectBase*>(this)->selectLabel(); }
00226 
00228       const DataSegment<icl8u,3> selectBGR() const { return const_cast<PointCloudObjectBase*>(this)->selectBGR(); }
00229 
00231       const DataSegment<icl8u,4> selectBGRA() const { return const_cast<PointCloudObjectBase*>(this)->selectBGRA(); }
00232   
00234       const DataSegment<icl32s,1> selectBGRA32s() const { return const_cast<PointCloudObjectBase*>(this)->selectBGRA32s(); }
00235       
00237       const DataSegment<float,4> selectNormal() const { return const_cast<PointCloudObjectBase*>(this)->selectNormal(); }
00238       
00240       const DataSegment<float,4> selectRGBA32f() const { return const_cast<PointCloudObjectBase*>(this)->selectRGBA32f(); }
00241   
00243       const DataSegmentBase select(const std::string &featureName) const { 
00244         return const_cast<PointCloudObjectBase*>(this)->select(featureName); 
00245       }
00246       
00248 
00249       void setColorsFromImage(const core::ImgBase &image) throw (utils::ICLException);
00250 
00252 
00253       void extractColorsToImage(core::ImgBase &image, bool withAlpha=false) const throw (utils::ICLException);
00254       
00256       void setDefaultVertexColor(const GeomColor &color);
00257 
00259       virtual GeomColor getDefaultVertexColor() const{ return m_defaultPointColor*255; }
00260       
00262       virtual std::vector<std::string> getSupportedDynamicFeatures() const { 
00263         return std::vector<std::string>();
00264       }
00265   
00267 
00273       virtual void customRender();
00274       
00276       void setUseDrawNormalLines(bool use, float lineLength=40, int granularity=4);
00277       
00279       virtual PointCloudObjectBase *copy() const {
00280         return 0;    
00281       }
00282       
00284       virtual void deepCopy(PointCloudObjectBase &dst) const;
00285       
00287       virtual bool equals(const PointCloudObjectBase &dst, 
00288                           bool compareOnlySharedFeatures=false, 
00289                           bool allowDifferentColorTypes=true,
00290                           float tollerance=1.0e-5) const;
00291   
00293       std::map<std::string,std::string> &getMetaData();
00294       
00296       const std::map<std::string,std::string> &getMetaData() const;
00297       
00299       const std::string &getMetaData(const std::string &key) const throw (utils::ICLException);
00300   
00302       bool hasMetaData(const std::string &key) const;
00303       
00305       bool hasAnyMetaData() const;
00306       
00308       void setMetaData(const std::string &key, const std::string &value);
00309       
00311       void clearAllMetaData();
00312   
00314       void clearMetaData(const std::string &key);
00315   
00317       std::vector<std::string> getAllMetaDataEntries() const;
00318     };
00319   
00321     std::ostream &operator<<(std::ostream &s, const PointCloudObjectBase::FeatureType t);
00322   } // namespace geom
00323 }
00324 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines