Image Component Library (ICL)
|
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.LGPL ** 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 <ICLUtils/CompatMacros.h> 00034 #include <ICLUtils/Time.h> 00035 #include <ICLGeom/SceneObject.h> 00036 #include <ICLCore/DataSegment.h> 00037 #include <ICLCore/ImgBase.h> 00038 #include <map> 00039 00040 namespace icl{ 00041 namespace geom{ 00042 00044 00098 class ICLGeom_API PointCloudObjectBase : public SceneObject{ 00100 utils::Time timestamp; 00101 00102 protected: 00103 00105 GeomColor m_defaultPointColor; 00106 00108 std::map<std::string,std::string> m_metaData; 00109 00111 template<class T, int N> 00112 core::DataSegment<T,N> &error(const std::string &fname) throw (utils::ICLException){ 00113 throw utils::ICLException("static feature "+fname+" is not supported by this PointCloudObjectBase instance"); 00114 static core::DataSegment<T,N> dummy; return dummy; 00115 } 00116 00118 core::DataSegmentBase &error_dyn(const std::string &featureName) throw (utils::ICLException){ 00119 throw utils::ICLException("dynamic feature "+featureName+" is not supported by this PointCloudObjectBase instance"); 00120 static core::DataSegmentBase dummy; return dummy; 00121 } 00122 00124 virtual void drawNormalLines(); 00125 00126 bool useDrawNormalLines; 00127 float normalLineLength; 00128 int normalLineGranularity; 00129 00130 public: 00131 00133 enum FeatureType { 00135 Intensity, 00136 Label, 00137 00138 BGR, 00139 BGRA, 00140 BGRA32s, 00141 00142 // 4D vector components 00143 XYZ, 00144 XYZH, 00145 Normal, 00146 RGBA32f, 00147 00148 NUM_FEATURES 00149 }; 00150 00152 00153 PointCloudObjectBase():timestamp(utils::Time::null){ 00154 setLockingEnabled(true); 00155 m_defaultPointColor = GeomColor(0,0.5,1,1); 00156 useDrawNormalLines=false; 00157 } 00158 00160 virtual void setTime(const utils::Time &t) { this->timestamp = t; } 00161 00163 virtual const utils::Time &getTime() const { return this->timestamp; } 00164 00166 virtual bool supports(FeatureType t) const = 0; 00167 00169 00170 virtual bool canAddFeature(FeatureType t) const { return false; } 00171 00173 00177 virtual void addFeature(FeatureType t) throw (utils::ICLException){ 00178 throw utils::ICLException("unable to add given feature to point cloud"); 00179 } 00180 00182 virtual bool isOrganized() const = 0; 00183 00185 virtual utils::Size getSize() const throw (utils::ICLException) = 0; 00186 00188 virtual int getDim() const = 0; 00189 00191 00197 virtual void setSize(const utils::Size &size) = 0; 00198 00200 inline void setDim(int dim){ 00201 setSize(utils::Size(dim,-1)); 00202 } 00203 00205 virtual core::DataSegment<float,3> selectXYZ(){ return error<float,3>(__FUNCTION__); } 00206 00208 virtual core::DataSegment<float,4> selectXYZH(){ return error<float,4>(__FUNCTION__); } 00209 00211 virtual core::DataSegment<float,1> selectIntensity(){ return error<float,1>(__FUNCTION__); } 00212 00214 virtual core::DataSegment<icl32s,1> selectLabel(){ return error<icl32s,1>(__FUNCTION__); } 00215 00217 virtual core::DataSegment<icl8u,3> selectBGR(){ return error<icl8u,3>(__FUNCTION__); } 00218 00220 virtual core::DataSegment<icl8u,4> selectBGRA(){ return error<icl8u,4>(__FUNCTION__); } 00221 00223 virtual core::DataSegment<icl32s,1> selectBGRA32s(){ return error<icl32s,1>(__FUNCTION__); } 00224 00226 00227 virtual core::DataSegment<float,4> selectNormal(){ return error<float,4>(__FUNCTION__); } 00228 00230 virtual core::DataSegment<float,4> selectRGBA32f(){ return error<float,4>(__FUNCTION__); } 00231 00233 00235 virtual core::DataSegmentBase select(const std::string &featureName) { return error_dyn(featureName); } 00236 00237 // const select methds 00238 00240 const core::DataSegment<float,3> selectXYZ() const { return const_cast<PointCloudObjectBase*>(this)->selectXYZ(); } 00241 00243 const core::DataSegment<float,4> selectXYZH() const { return const_cast<PointCloudObjectBase*>(this)->selectXYZH(); } 00244 00246 const core::DataSegment<float,1> selectIntensity() const { return const_cast<PointCloudObjectBase*>(this)->selectIntensity(); } 00247 00249 const core::DataSegment<icl32s,1> selectLabel() const { return const_cast<PointCloudObjectBase*>(this)->selectLabel(); } 00250 00252 const core::DataSegment<icl8u,3> selectBGR() const { return const_cast<PointCloudObjectBase*>(this)->selectBGR(); } 00253 00255 const core::DataSegment<icl8u,4> selectBGRA() const { return const_cast<PointCloudObjectBase*>(this)->selectBGRA(); } 00256 00258 const core::DataSegment<icl32s,1> selectBGRA32s() const { return const_cast<PointCloudObjectBase*>(this)->selectBGRA32s(); } 00259 00261 const core::DataSegment<float,4> selectNormal() const { return const_cast<PointCloudObjectBase*>(this)->selectNormal(); } 00262 00264 const core::DataSegment<float,4> selectRGBA32f() const { return const_cast<PointCloudObjectBase*>(this)->selectRGBA32f(); } 00265 00267 const core::DataSegmentBase select(const std::string &featureName) const { 00268 return const_cast<PointCloudObjectBase*>(this)->select(featureName); 00269 } 00270 00272 00273 void setColorsFromImage(const core::ImgBase &image) throw (utils::ICLException); 00274 00276 00277 void extractColorsToImage(core::ImgBase &image, bool withAlpha=false) const throw (utils::ICLException); 00278 00280 void setDefaultVertexColor(const GeomColor &color); 00281 00283 virtual GeomColor getDefaultVertexColor() const{ return m_defaultPointColor*255; } 00284 00286 virtual std::vector<std::string> getSupportedDynamicFeatures() const { 00287 return std::vector<std::string>(); 00288 } 00289 00291 00297 virtual void customRender(); 00298 00300 void setUseDrawNormalLines(bool use, float lineLength=40, int granularity=4); 00301 00303 virtual PointCloudObjectBase *copy() const { 00304 return 0; 00305 } 00306 00308 virtual void deepCopy(PointCloudObjectBase &dst) const; 00309 00311 virtual bool equals(const PointCloudObjectBase &dst, 00312 bool compareOnlySharedFeatures=false, 00313 bool allowDifferentColorTypes=true, 00314 float tollerance=1.0e-5) const; 00315 00317 std::map<std::string,std::string> &getMetaData(); 00318 00320 const std::map<std::string,std::string> &getMetaData() const; 00321 00323 const std::string &getMetaData(const std::string &key) const throw (utils::ICLException); 00324 00326 bool hasMetaData(const std::string &key) const; 00327 00329 bool hasAnyMetaData() const; 00330 00332 void setMetaData(const std::string &key, const std::string &value); 00333 00335 void clearAllMetaData(); 00336 00338 void clearMetaData(const std::string &key); 00339 00341 std::vector<std::string> getAllMetaDataEntries() const; 00342 }; 00343 00345 ICLGeom_API std::ostream &operator<<(std::ostream &s, const PointCloudObjectBase::FeatureType t); 00346 } // namespace geom 00347 } 00348