/******************************************************************** ** Image Component Library (ICL) ** ** ** ** Copyright (C) 2006-2013 CITEC, University of Bielefeld ** ** Neuroinformatics Group ** ** Website: www.iclcv.org and ** ** http://opensource.cit-ec.de/projects/icl ** ** ** ** File : ICLGeom/src/ICLGeom/PCLPointCloudObject.cpp ** ** Module : ICLGeom ** ** Authors: Christof Elbrechter, Patrick Nobou ** ** ** ** ** ** GNU LESSER GENERAL PUBLIC LICENSE ** ** This file may be used under the terms of the GNU Lesser General ** ** Public License version 3.0 as published by the ** ** ** ** Free Software Foundation and appearing in the file LICENSE.LGPL ** ** included in the packaging of this file. Please review the ** ** following information to ensure the license requirements will ** ** be met: http://www.gnu.org/licenses/lgpl-3.0.txt ** ** ** ** The development of this software was supported by the ** ** Excellence Cluster EXC 277 Cognitive Interaction Technology. ** ** The Excellence Cluster EXC 277 is a grant of the Deutsche ** ** Forschungsgemeinschaft (DFG) in the context of the German ** ** Excellence Initiative. ** ** ** ********************************************************************/ #include #include using namespace icl::utils; using namespace icl::math; using namespace icl::core; namespace icl{ namespace geom{ template int PCLPointCloudObject::offset(FeatureType) const{ return -1; } template icl8u* PCLPointCloudObject::data() { return (icl8u*)&m_pcl->points[0]; } template inline const icl8u* PCLPointCloudObject::data() const { return const_cast*>(this)->data(); } /// creates a data segment for a given feature type template template inline DataSegment PCLPointCloudObject::createSegment() { ICLASSERT_THROW(supports(t),utils::ICLException("the given feature type " + str(t) + " is not supported by this PCLPointCloudObject")); return DataSegment((T*)(data()+offset(t)),sizeof(Entry), isOrganized() ? m_pcl->width * m_pcl->height : m_pcl->width, isOrganized() ? m_pcl->width : -1); } template void PCLPointCloudObject::deletePCL(){ if(m_ownPCL && m_pcl) delete m_pcl; m_pcl = 0; } #if 0 // see header file for explanation! template PCLPointCloudObject::PCLPointCloudObject(const std::string &filename):m_ownPCL(true){ m_pcl = new pcl::PointCloud; if(filename.length()){ if( pcl::io::loadPCDFile(filename, *m_pcl) == -1){ throw utils::ICLException("unable to load \"pcl\" point cloud file " + filename); } } } #endif template PCLPointCloudObject::PCLPointCloudObject(int width, int height, const PCLPointType &init): m_pcl(new pcl::PointCloud(width,height,init)),m_ownPCL(true){ } template PCLPointCloudObject::PCLPointCloudObject(const PCLPointCloudObject &other) :m_pcl(0),m_ownPCL(true){ *this = other; } template PCLPointCloudObject &PCLPointCloudObject::operator=(const PCLPointCloudObject &other){ deletePCL(); if(!other.isNull()){ setPCL(other.pcl()); } m_metaData = other.m_metaData; return *this; } template PCLPointCloudObject::PCLPointCloudObject(const pcl::PointCloud &cloud) : m_pcl(0) { setPCL(cloud); } template PCLPointCloudObject::PCLPointCloudObject(pcl::PointCloud &cloud, bool deepCopy) : m_pcl(0) { setPCL(cloud, deepCopy); } template PCLPointCloudObject::~PCLPointCloudObject(){ deletePCL(); } template pcl::PointCloud & PCLPointCloudObject::pcl() throw (utils::ICLException){ if(isNull()) throw ICLException("PCLPointCloudObject::pcl(): instance is null"); return *m_pcl; } template const pcl::PointCloud & PCLPointCloudObject::pcl() const throw (utils::ICLException){ return const_cast*>(this)->pcl(); } template void PCLPointCloudObject::setPCL(const pcl::PointCloud &pcl){ deletePCL(); m_pcl = new pcl::PointCloud; pcl::copyPointCloud(pcl, *m_pcl); m_ownPCL = true; } template void PCLPointCloudObject::setPCL(pcl::PointCloud &pcl, bool deepCopy){ ICL_DELETE(m_pcl); if(deepCopy){ setPCL(const_cast &>(pcl)); }else{ m_pcl = &pcl; m_ownPCL = false; } } template bool PCLPointCloudObject::supports(FeatureType t) const{ if(isNull()) throw utils::ICLException("PCLPointCloudObject:supports(t): instance is null"); return (offset(t) >= 0); } template bool PCLPointCloudObject::isOrganized() const { if(isNull()) throw utils::ICLException("PCLPointCloudObject:isOrganized(): instance is null"); return m_pcl->isOrganized(); } template Size PCLPointCloudObject::getSize() const throw (utils::ICLException){ if(isNull()) throw utils::ICLException("PCLPointCloudObject:getSize(): instance is null"); if(!isOrganized()) throw utils::ICLException("PCLPointCloud::getSize(): instance is not 2D-ordered"); return Size(m_pcl->width, m_pcl->height); } template int PCLPointCloudObject::getDim() const{ if(isNull()) throw utils::ICLException("PCLPointCloudObject:getDim(): instance is null"); return isOrganized() ? m_pcl->width * m_pcl->height : m_pcl->width; } template void PCLPointCloudObject::setSize(const Size &size){ if(getSize() == size) return; *this = PCLPointCloudObject(size.width,(size.height == 0) ? -1 : size.height); } template PCLPointCloudObject *PCLPointCloudObject::copy() const { PCLPointCloudObject *p = new PCLPointCloudObject(*this); if(supports(Normal)){ // little hack because pcl does in general not support a 4th-normal component DataSegment n = p->selectNormal(); for(int i=0;i bool PCLPointCloudObject::isNull() const { return !m_pcl; } template DataSegmentBase PCLPointCloudObject::select(const std::string &featureName) { if(isNull()) throw utils::ICLException("PCLPointCloudObject:select(" + featureName + "): instance is null"); if(featureName == "all"){ return DataSegmentBase(data(), sizeof(Entry), getDim(), isOrganized() ? m_pcl->width : -1, depth32f, sizeof(Entry)/sizeof(float)); }else{ return PointCloudObjectBase::error_dyn(featureName); } } /// offset specifications for specific datatypes! template<> int PCLPointCloudObject::offset(PointCloudObjectBase::FeatureType t) const { switch(t){ case XYZ: return 0; default: return -1; } } template<> int PCLPointCloudObject::offset(PointCloudObjectBase::FeatureType t) const { switch(t){ case XYZ: return 0; case Intensity: return 4*sizeof(float); default: return -1; } } template<> int PCLPointCloudObject::offset(PointCloudObjectBase::FeatureType t) const { switch(t){ case XYZ: return 0; case Label: return 4*sizeof(float); default: return -1; } } template<> int PCLPointCloudObject::offset(PointCloudObjectBase::FeatureType t) const { switch(t){ case XYZ: return 0; case BGR: return 4*sizeof(float); default: return -1; // case BGRA: case BGRA32s: is not available because an unused alpha value // could mess up the visualization } } template<> int PCLPointCloudObject::offset(PointCloudObjectBase::FeatureType t) const { switch(t){ case XYZ: return 0; case BGR: case BGRA: case BGRA32s: return 4*sizeof(float); default: return -1; } } template<> int PCLPointCloudObject::offset(PointCloudObjectBase::FeatureType t) const { switch(t){ case XYZ: return 0; case BGR: return 4*sizeof(float); // case BGRA: case BGRA32s: (not defined here) case Label: return 5*sizeof(float); default: return -1; } } template<> int PCLPointCloudObject::offset(PointCloudObjectBase::FeatureType t) const { switch(t){ case XYZ: return 0; case Intensity: return 4*sizeof(float); default: return -1; } } template<> int PCLPointCloudObject::offset(PointCloudObjectBase::FeatureType t) const { switch(t){ case XYZ: return 0; case BGR: return 8*sizeof(float); // case BGRA: case BGRA32s: (not defined here) case Normal: return 4*sizeof(float); default: return -1; } } template<> int PCLPointCloudObject::offset(PointCloudObjectBase::FeatureType t) const { switch(t){ case XYZ: return 0; case Intensity: return 8*sizeof(float); case Normal: return 4*sizeof(float); default: return -1; } } // template<> int PCLPointCloudObject::offset(PointCloudObjectBase::FeatureType t) const { // switch(t){ // case XYZ: return 0; // case Intensity: return 4*sizeof(float); // default: return -1; // } // } // // template<> int PCLPointCloudObject::offset(PointCloudObjectBase::FeatureType t) const { // switch(t){ // case XYZ: return 0; // case Intensity: return 4*sizeof(float); // default: return -1; // } // } // template<> int PCLPointCloudObject::offset(PointCloudObjectBase::FeatureType t) const { // // switch(t){ // case XYZ: return 0; // case Intensity: return DataSegmentBase.stride*sizeof(float); // default: return -1; // } // } #define ICL_IMPLEMENT_FUNCTION(T,N,TYPE) \ template \ DataSegment PCLPointCloudObject::select##TYPE(){ \ return createSegment(); \ } ICL_IMPLEMENT_FUNCTION(float,1,Intensity) ICL_IMPLEMENT_FUNCTION(icl32s,1,Label) ICL_IMPLEMENT_FUNCTION(icl8u,3,BGR) ICL_IMPLEMENT_FUNCTION(icl8u,4,BGRA) ICL_IMPLEMENT_FUNCTION(icl32s,1,BGRA32s) ICL_IMPLEMENT_FUNCTION(float,3,XYZ); ICL_IMPLEMENT_FUNCTION(float,4,XYZH); ICL_IMPLEMENT_FUNCTION(float,4,Normal); ICL_IMPLEMENT_FUNCTION(float,4,RGBA32f); #undef ICL_IMPLEMENT_FUNCTION #define INSTANTIATE_CLASS(T) template class PCLPointCloudObject INSTANTIATE_CLASS(pcl::PointXYZ); INSTANTIATE_CLASS(pcl::PointXYZI); INSTANTIATE_CLASS(pcl::PointXYZL); INSTANTIATE_CLASS(pcl::PointXYZRGB); INSTANTIATE_CLASS(pcl::PointXYZRGBA); INSTANTIATE_CLASS(pcl::PointXYZRGBL); INSTANTIATE_CLASS(pcl::InterestPoint); INSTANTIATE_CLASS(pcl::PointXYZRGBNormal); INSTANTIATE_CLASS(pcl::PointXYZINormal); #undef INSTANTIATE_CLASS } // namespace geom }