Skip to content

Commit

Permalink
Added additional abstraction around OpenNI wrapper data types.
Browse files Browse the repository at this point in the history
This should allow switching between OpenNI 1/2 wrappers.
  • Loading branch information
kwaegel committed Aug 29, 2013
1 parent 2a8c00c commit 1ce09fc
Show file tree
Hide file tree
Showing 7 changed files with 68 additions and 11 deletions.
16 changes: 8 additions & 8 deletions cuda/io/src/debayering.cu
Original file line number Diff line number Diff line change
Expand Up @@ -254,8 +254,8 @@ namespace pcl
//pcl::ScopeTime t ("computeBilinear");
typename Storage<unsigned char>::type bayer_data (bayer_image->getWidth () * bayer_image->getHeight ());
// thrust::device_vector<unsigned char> bayer_data (bayer_image->getWidth () * bayer_image->getHeight ());
thrust::copy ((unsigned char*)(bayer_image->getMetaData().Data()),
(unsigned char*)(bayer_image->getMetaData().Data() + bayer_image->getMetaData().DataSize()),
thrust::copy ((unsigned char*)(bayer_image->getData()),
(unsigned char*)(bayer_image->getData()) + bayer_image->getDataSize(),
bayer_data.begin ());
// thrust::device_vector<int> indices(bayer_image->getWidth () * bayer_image->getHeight ());
// thrust::sequence (indices.begin(), indices.end() );
Expand All @@ -273,10 +273,10 @@ namespace pcl
template<template <typename> class Storage>
void YUV2RGB<Storage>::compute (const boost::shared_ptr<openni_wrapper::Image>& yuv_image, RGBImageType& rgb_image) const
{
typename Storage<unsigned char>::type yuv_data (yuv_image->getMetaData().DataSize());
thrust::copy ((unsigned char*)(yuv_image->getMetaData().Data()),
(unsigned char*)(yuv_image->getMetaData().Data() + yuv_image->getMetaData().DataSize()),
yuv_data.begin ());
typename Storage<unsigned char>::type yuv_data (yuv_image->getDataSize());
thrust::copy ((const unsigned char*)( yuv_image->getData() ),
(const unsigned char*)( yuv_image->getData()) + yuv_image->getDataSize(),
yuv_data.begin() );
thrust::counting_iterator<int> first (0);
thrust::transform (first,
first + (int)(yuv_image->getWidth () * yuv_image->getHeight ()),
Expand Down Expand Up @@ -312,8 +312,8 @@ namespace pcl
//pcl::ScopeTime t ("computeBilinear");
typename Storage<unsigned char>::type bayer_data (bayer_image->getWidth () * bayer_image->getHeight ());
// thrust::device_vector<unsigned char> bayer_data (bayer_image->getWidth () * bayer_image->getHeight ());
thrust::copy ((unsigned char*)(bayer_image->getMetaData().Data()),
(unsigned char*)(bayer_image->getMetaData().Data() + bayer_image->getMetaData().DataSize()),
thrust::copy ((unsigned char*)(bayer_image->getData()),
(unsigned char*)(bayer_image->getData()) + bayer_image->getDataSize(),
bayer_data.begin ());

thrust::counting_iterator<int> first (0);
Expand Down
2 changes: 1 addition & 1 deletion cuda/io/src/disparity_to_cloud.cu
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ DisparityToCloud::compute (const boost::shared_ptr<openni_wrapper::DepthImage>&

// Copy the depth data and the RGB data on the card
typename Storage<float>::type depth (output->width * output->height);
unsigned short* depth_buffer = (unsigned short*)depth_image->getDepthMetaData ().Data ();
unsigned short* depth_buffer = (unsigned short*)depth_image->getData ();

if (downsample)
{
Expand Down
2 changes: 1 addition & 1 deletion gpu/kinfu/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ set(SUBSYS_DEPS common visualization io gpu_containers geometry search)
set(build FALSE)

# OpenNI found?
if(NOT OPENNI_FOUND OR NOT BUILD_OPENNI)
if((NOT OPENNI_FOUND OR NOT BUILD_OPENNI) AND (NOT OPENNI2_FOUND OR NOT BUILD_OPENNI2))
set(DEFAULT FALSE)
set(REASON "OpenNI was not found or was disabled by the user.")
else()
Expand Down
18 changes: 18 additions & 0 deletions io/include/pcl/io/openni2_camera/openni_image.h
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,12 @@ namespace openni_wrapper
*/
inline const openni::VideoFrameRef& getMetaData () const throw ();

// Get a const pointer to the raw depth buffer
inline const void* getData();

// Data buffer size in bytes
inline int getDataSize();

protected:
openni::VideoFrameRef image_md_; // This is already a reference, so we don't need another pointer wrapper.
} ;
Expand All @@ -175,6 +181,18 @@ namespace openni_wrapper

Image::~Image () throw () { }

const void*
Image::getData()
{
return image_md_.getData();
}

int
Image::getDataSize()
{
return image_md_.getDataSize();
}

unsigned
Image::getWidth () const throw ()
{
Expand Down
8 changes: 8 additions & 0 deletions io/include/pcl/io/openni2_camera/openni_image_depth.h
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,14 @@ namespace openni_wrapper
inline unsigned long
getTimeStamp () const throw ();

// Get a const pointer to the raw depth buffer
inline const void*
getData() { return depth_md_.getData(); }

// Data buffer size in bytes
inline int
getDataSize() { return depth_md_.getDataSize(); }

protected:
openni::VideoFrameRef depth_md_;
float baseline_;
Expand Down
28 changes: 27 additions & 1 deletion io/include/pcl/io/openni_camera/openni_depth_image.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,15 @@ namespace openni_wrapper
*/
inline const xn::DepthMetaData&
getDepthMetaData () const throw ();

/** \brief method to access the raw internal data structure from OpenNI. If the data is accessed just read-only, then this method is faster than a fillXXX method
* \return a pointer to the actual depth data buffer.
*/
inline const void*
getData () const throw ();

inline int
getDataSize () const throw ();

/** \brief fills a user given block of memory with the disparity values with additional nearest-neighbor down-scaling.
* \param[in] width the width of the desired disparity image.
Expand Down Expand Up @@ -176,6 +185,18 @@ namespace openni_wrapper
{
return *depth_md_;
}

const void*
DepthImage::getData () const throw ()
{
return depth_md_->Data();
}

int
DepthImage::getDataSize () const throw ()
{
return depth_md_->DataSize();
}

float
DepthImage::getBaseline () const throw ()
Expand Down Expand Up @@ -226,4 +247,9 @@ namespace openni_wrapper
}
} // namespace
#endif
#endif //__OPENNI_DEPTH_IMAGE
#elif HAVE_OPENNI2
// Passthrough to openni2_wrapper
#include <pcl/io/openni2_camera/openni_image_depth.h>
//typedef openni_wrapper::DepthImage openni2_wrapper::DepthImage;

#endif //__OPENNI_DEPTH_IMAGE__
5 changes: 5 additions & 0 deletions io/include/pcl/io/openni_camera/openni_image.h
Original file line number Diff line number Diff line change
Expand Up @@ -206,4 +206,9 @@ namespace openni_wrapper
}
} // namespace
#endif
#elif HAVE_OPENNI2
// Passthrough to openni2_wrapper
#include <pcl/io/openni2_camera/openni_image.h>
//typedef openni_wrapper::Image openni2_wrapper::Image;

#endif //__OPENNI_IMAGE__

0 comments on commit 1ce09fc

Please sign in to comment.