Point Cloud Library (PCL)  1.14.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 
47 namespace openni_wrapper
48 {
49 
50  /**
51  * @brief Image class containing just a reference to image meta data. Thus this class
52  * just provides an interface to fill a RGB or Grayscale image buffer.
53  * @author Suat Gedikli
54  * @date 02.january 2011
55  * @param[in] image_meta_data
56  * @ingroup io
57  */
59  {
60  public:
61  using Ptr = pcl::shared_ptr<Image>;
62  using ConstPtr = pcl::shared_ptr<const Image>;
63 
64  enum Encoding
65  {
68  RGB
69  };
70 
71  /**
72  * @author Suat Gedikli
73  * @brief Constructor
74  * @param[in] image_meta_data the actual image data from the OpenNI driver
75  */
76  inline Image (pcl::shared_ptr<xn::ImageMetaData> image_meta_data) noexcept;
77 
78  /**
79  * @author Suat Gedikli
80  * @brief virtual Destructor that never throws an exception.
81  */
82  inline virtual ~Image () noexcept;
83 
84  /**
85  * @author Suat Gedikli
86  * @param[in] input_width width of input image
87  * @param[in] input_height height of input image
88  * @param[in] output_width width of desired output image
89  * @param[in] output_height height of desired output image
90  * @return whether the resizing is supported or not.
91  */
92  virtual bool isResizingSupported (unsigned input_width, unsigned input_height,
93  unsigned output_width, unsigned output_height) const = 0;
94 
95  /**
96  * @author Suat Gedikli
97  * @brief fills a user given buffer with the RGB values, with an optional nearest-neighbor down sampling and an optional subregion
98  * @param[in] width desired width of output image.
99  * @param[in] height desired height of output image.
100  * @param[in,out] rgb_buffer the output RGB buffer.
101  * @param[in] rgb_line_step optional line step in bytes to allow the output in a rectangular subregion of the output buffer.
102  */
103  virtual void fillRGB (unsigned width, unsigned height, unsigned char* rgb_buffer,
104  unsigned rgb_line_step = 0) const = 0;
105 
106  /**
107  * @author Suat Gedikli
108  * @brief returns the encoding of the native data.
109  * @return encoding
110  */
111  virtual Encoding getEncoding () const = 0;
112 
113  /**
114  * @author Suat Gedikli
115  * @brief fills a user given buffer with the raw values.
116  * @param[in,out] rgb_buffer
117  */
118  inline void
119  fillRaw (unsigned char* rgb_buffer) const noexcept
120  {
121  memcpy (rgb_buffer, image_md_->Data (), image_md_->DataSize ());
122  }
123 
124  /**
125  * @author Suat Gedikli
126  * @brief fills a user given buffer with the gray values, with an optional nearest-neighbor down sampling and an optional subregion
127  * @param[in] width desired width of output image.
128  * @param[in] height desired height of output image.
129  * @param[in,out] gray_buffer the output gray buffer.
130  * @param[in] gray_line_step optional line step in bytes to allow the output in a rectangular subregion of the output buffer.
131  */
132  virtual void fillGrayscale (unsigned width, unsigned height, unsigned char* gray_buffer,
133  unsigned gray_line_step = 0) const = 0;
134 
135  /**
136  * @author Suat Gedikli
137  * @return width of the image
138  */
139  inline unsigned getWidth () const noexcept;
140 
141  /**
142  * @author Suat Gedikli
143  * @return height of the image
144  */
145  inline unsigned getHeight () const noexcept;
146 
147  /**
148  * @author Suat Gedikli
149  * @return frame id of the image.
150  * @note frame ids are ascending, but not necessarily synch'ed with other streams
151  */
152  inline unsigned getFrameID () const noexcept;
153 
154  /**
155  * @author Suat Gedikli
156  * @return the time stamp of the image
157  * @note the time value is not synche'ed with the system time
158  */
159  inline unsigned long getTimeStamp () const noexcept;
160 
161  /**
162  * @author Suat Gedikli
163  * @return the actual data in native OpenNI format.
164  */
165  inline const xn::ImageMetaData& getMetaData () const noexcept;
166 
167  protected:
168  pcl::shared_ptr<xn::ImageMetaData> image_md_;
169  } ;
170 
171  Image::Image (pcl::shared_ptr<xn::ImageMetaData> image_meta_data) noexcept
172  : image_md_ (std::move(image_meta_data))
173  {
174  }
175 
176  Image::~Image () noexcept = default;
177 
178  unsigned
179  Image::getWidth () const noexcept
180  {
181  return image_md_->XRes ();
182  }
183 
184  unsigned
185  Image::getHeight () const noexcept
186  {
187  return image_md_->YRes ();
188  }
189 
190  unsigned
191  Image::getFrameID () const noexcept
192  {
193  return image_md_->FrameID ();
194  }
195 
196  unsigned long
197  Image::getTimeStamp () const noexcept
198  {
199  return static_cast<unsigned long> (image_md_->Timestamp ());
200  }
201 
202  const xn::ImageMetaData&
203  Image::getMetaData () const noexcept
204  {
205  return *image_md_;
206  }
207 } // namespace
208 #endif
Image class containing just a reference to image meta data.
Definition: openni_image.h:59
pcl::shared_ptr< Image > Ptr
Definition: openni_image.h:61
unsigned long getTimeStamp() const noexcept
Definition: openni_image.h:197
pcl::shared_ptr< const Image > ConstPtr
Definition: openni_image.h:62
virtual ~Image() noexcept
virtual Destructor that never throws an exception.
unsigned getFrameID() const noexcept
Definition: openni_image.h:191
unsigned getHeight() const noexcept
Definition: openni_image.h:185
virtual void fillGrayscale(unsigned width, unsigned height, unsigned char *gray_buffer, unsigned gray_line_step=0) const =0
fills a user given buffer with the gray values, with an optional nearest-neighbor down sampling and a...
const xn::ImageMetaData & getMetaData() const noexcept
Definition: openni_image.h:203
Defines functions, macros and traits for allocating and using memory.
#define PCL_EXPORTS
Definition: pcl_macros.h:325