Point Cloud Library (PCL)  1.10.1-dev
openni_image.h
1 /*
2  * Software License Agreement (BSD License)
3  *
4  * Copyright (c) 2011 Willow Garage, Inc.
5  *
6  * All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  *
12  * * Redistributions of source code must retain the above copyright
13  * notice, this list of conditions and the following disclaimer.
14  * * Redistributions in binary form must reproduce the above
15  * copyright notice, this list of conditions and the following
16  * disclaimer in the documentation and/or other materials provided
17  * with the distribution.
18  * * Neither the name of the copyright holder(s) nor the names of its
19  * contributors may be used to endorse or promote products derived
20  * from this software without specific prior written permission.
21  *
22  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
25  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
26  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
27  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
28  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
29  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
30  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
32  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
33  * POSSIBILITY OF SUCH DAMAGE.
34  *
35  */
36 
37 #pragma once
38 
39 #include <pcl/pcl_config.h>
40 #include <pcl/memory.h>
41 #ifdef HAVE_OPENNI
42 
43 #include <pcl/pcl_exports.h>
44 #include "openni.h"
45 #include "openni_exception.h"
46 #include <pcl/io/boost.h>
47 
48 namespace openni_wrapper
49 {
50 
51  /**
52  * @brief Image class containing just a reference to image meta data. Thus this class
53  * just provides an interface to fill a RGB or Grayscale image buffer.
54  * @author Suat Gedikli
55  * @date 02.january 2011
56  * @param[in] image_meta_data
57  * @ingroup io
58  */
60  {
61  public:
64 
65  enum Encoding
66  {
69  RGB
70  };
71 
72  /**
73  * @author Suat Gedikli
74  * @brief Constructor
75  * @param[in] image_meta_data the actual image data from the OpenNI driver
76  */
77  inline Image (pcl::shared_ptr<xn::ImageMetaData> image_meta_data) noexcept;
78 
79  /**
80  * @author Suat Gedikli
81  * @brief virtual Destructor that never throws an exception.
82  */
83  inline virtual ~Image () noexcept;
84 
85  /**
86  * @author Suat Gedikli
87  * @param[in] input_width width of input image
88  * @param[in] input_height height of input image
89  * @param[in] output_width width of desired output image
90  * @param[in] output_height height of desired output image
91  * @return whether the resizing is supported or not.
92  */
93  virtual bool isResizingSupported (unsigned input_width, unsigned input_height,
94  unsigned output_width, unsigned output_height) const = 0;
95 
96  /**
97  * @author Suat Gedikli
98  * @brief fills a user given buffer with the RGB values, with an optional nearest-neighbor down sampling and an optional subregion
99  * @param[in] width desired width of output image.
100  * @param[in] height desired height of output image.
101  * @param[in,out] rgb_buffer the output RGB buffer.
102  * @param[in] rgb_line_step optional line step in bytes to allow the output in a rectangular subregion of the output buffer.
103  */
104  virtual void fillRGB (unsigned width, unsigned height, unsigned char* rgb_buffer,
105  unsigned rgb_line_step = 0) const = 0;
106 
107  /**
108  * @author Suat Gedikli
109  * @brief returns the encoding of the native data.
110  * @return encoding
111  */
112  virtual Encoding getEncoding () const = 0;
113 
114  /**
115  * @author Suat Gedikli
116  * @brief fills a user given buffer with the raw values.
117  * @param[in,out] rgb_buffer
118  */
119  inline void
120  fillRaw (unsigned char* rgb_buffer) const throw ()
121  {
122  memcpy (rgb_buffer, image_md_->Data (), image_md_->DataSize ());
123  }
124 
125  /**
126  * @author Suat Gedikli
127  * @brief fills a user given buffer with the gray values, with an optional nearest-neighbor down sampling and an optional subregion
128  * @param[in] width desired width of output image.
129  * @param[in] height desired height of output image.
130  * @param[in,out] gray_buffer the output gray buffer.
131  * @param[in] gray_line_step optional line step in bytes to allow the output in a rectangular subregion of the output buffer.
132  */
133  virtual void fillGrayscale (unsigned width, unsigned height, unsigned char* gray_buffer,
134  unsigned gray_line_step = 0) const = 0;
135 
136  /**
137  * @author Suat Gedikli
138  * @return width of the image
139  */
140  inline unsigned getWidth () const throw ();
141 
142  /**
143  * @author Suat Gedikli
144  * @return height of the image
145  */
146  inline unsigned getHeight () const throw ();
147 
148  /**
149  * @author Suat Gedikli
150  * @return frame id of the image.
151  * @note frame ids are ascending, but not necessarily synch'ed with other streams
152  */
153  inline unsigned getFrameID () const throw ();
154 
155  /**
156  * @author Suat Gedikli
157  * @return the time stamp of the image
158  * @note the time value is not synche'ed with the system time
159  */
160  inline unsigned long getTimeStamp () const throw ();
161 
162  /**
163  * @author Suat Gedikli
164  * @return the actual data in native OpenNI format.
165  */
166  inline const xn::ImageMetaData& getMetaData () const throw ();
167 
168  protected:
170  } ;
171 
173  : image_md_ (std::move(image_meta_data))
174  {
175  }
176 
177  Image::~Image () noexcept { }
178 
179  unsigned
180  Image::getWidth () const throw ()
181  {
182  return image_md_->XRes ();
183  }
184 
185  unsigned
186  Image::getHeight () const throw ()
187  {
188  return image_md_->YRes ();
189  }
190 
191  unsigned
192  Image::getFrameID () const throw ()
193  {
194  return image_md_->FrameID ();
195  }
196 
197  unsigned long
198  Image::getTimeStamp () const throw ()
199  {
200  return static_cast<unsigned long> (image_md_->Timestamp ());
201  }
202 
203  const xn::ImageMetaData&
204  Image::getMetaData () const throw ()
205  {
206  return *image_md_;
207  }
208 } // namespace
209 #endif
unsigned getHeight() const
Definition: openni_image.h:186
Defines functions, macros and traits for allocating and using memory.
const xn::ImageMetaData & getMetaData() const
Definition: openni_image.h:204
pcl::shared_ptr< xn::ImageMetaData > image_md_
Definition: openni_image.h:169
Image class containing just a reference to image meta data.
Definition: openni_image.h:59
unsigned getWidth() const
Definition: openni_image.h:180
Image(pcl::shared_ptr< xn::ImageMetaData > image_meta_data) noexcept
Constructor.
Definition: openni_image.h:172
virtual ~Image() noexcept
virtual Destructor that never throws an exception.
Definition: openni_image.h:177
pcl::shared_ptr< const Image > ConstPtr
Definition: openni_image.h:63
pcl::shared_ptr< Image > Ptr
Definition: openni_image.h:62
unsigned long getTimeStamp() const
Definition: openni_image.h:198
boost::shared_ptr< T > shared_ptr
Alias for boost::shared_ptr.
Definition: memory.h:81
#define PCL_EXPORTS
Definition: pcl_macros.h:276
unsigned getFrameID() const
Definition: openni_image.h:192