Point Cloud Library (PCL)  1.11.0
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/io/boost.h>
40 #include <pcl/io/image_metadata_wrapper.h>
41 #include <pcl/memory.h>
42 #include <pcl/pcl_config.h>
43 #include <pcl/pcl_macros.h>
44 
45 #include <chrono>
46 
47 namespace pcl
48 {
49  namespace io
50  {
51 
52  /**
53  * @brief Image interface class providing an interface to fill a RGB or Grayscale image buffer.
54  * @param[in] image_metadata
55  * @ingroup io
56  */
58  {
59  public:
60  using Ptr = shared_ptr<Image>;
61  using ConstPtr = shared_ptr<const Image>;
62 
63  using Clock = std::chrono::high_resolution_clock;
64  using Timestamp = std::chrono::high_resolution_clock::time_point;
65 
66  enum Encoding
67  {
71  };
72 
73  Image (FrameWrapper::Ptr image_metadata)
74  : wrapper_ (std::move(image_metadata))
75  , timestamp_ (Clock::now ())
76  {}
77 
78  Image (FrameWrapper::Ptr image_metadata, Timestamp time)
79  : wrapper_ (std::move(image_metadata))
80  , timestamp_ (time)
81  {}
82 
83  /**
84  * @brief virtual Destructor that never throws an exception.
85  */
86  inline virtual ~Image ()
87  {}
88 
89  /**
90  * @param[in] input_width width of input image
91  * @param[in] input_height height of input image
92  * @param[in] output_width width of desired output image
93  * @param[in] output_height height of desired output image
94  * @return whether the resizing is supported or not.
95  */
96  virtual bool
97  isResizingSupported (unsigned input_width, unsigned input_height,
98  unsigned output_width, unsigned output_height) const = 0;
99 
100  /**
101  * @brief fills a user given buffer with the RGB values, with an optional nearest-neighbor down sampling and an optional subregion
102  * @param[in] width desired width of output image.
103  * @param[in] height desired height of output image.
104  * @param[in,out] rgb_buffer the output RGB buffer.
105  * @param[in] rgb_line_step optional line step in bytes to allow the output in a rectangular subregion of the output buffer.
106  */
107  virtual void
108  fillRGB (unsigned width, unsigned height, unsigned char* rgb_buffer, unsigned rgb_line_step = 0) const = 0;
109 
110  /**
111  * @brief returns the encoding of the native data.
112  * @return encoding
113  */
114  virtual Encoding
115  getEncoding () const = 0;
116 
117  /**
118  * @brief fills a user given buffer with the raw values.
119  * @param[in,out] rgb_buffer
120  */
121  virtual void
122  fillRaw (unsigned char* rgb_buffer) const
123  {
124  memcpy (rgb_buffer, wrapper_->getData (), wrapper_->getDataSize ());
125  }
126 
127  /**
128  * @brief fills a user given buffer with the gray values, with an optional nearest-neighbor down sampling and an optional subregion
129  * @param[in] width desired width of output image.
130  * @param[in] height desired height of output image.
131  * @param[in,out] gray_buffer the output gray buffer.
132  * @param[in] gray_line_step optional line step in bytes to allow the output in a rectangular subregion of the output buffer.
133  */
134  virtual void
135  fillGrayscale (unsigned width, unsigned height, unsigned char* gray_buffer,
136  unsigned gray_line_step = 0) const = 0;
137 
138  /**
139  * @return width of the image
140  */
141  unsigned
142  getWidth () const
143  {
144  return (wrapper_->getWidth ());
145  }
146 
147  /**
148  * @return height of the image
149  */
150  unsigned
151  getHeight () const
152  {
153  return (wrapper_->getHeight ());
154  }
155 
156  /**
157  * @return frame id of the image.
158  * @note frame ids are ascending, but not necessarily synchronized with other streams
159  */
160  unsigned
161  getFrameID () const
162  {
163  return (wrapper_->getFrameID ());
164  }
165 
166  /**
167  * @return the timestamp of the image
168  * @note the time value is not synchronized with the system time
169  */
171  getTimestamp () const
172  {
173  return (wrapper_->getTimestamp ());
174  }
175 
176 
177  /**
178  * @return the timestamp of the image
179  * @note the time value *is* synchronized with the system time.
180  */
181  Timestamp
183  {
184  return (timestamp_);
185  }
186 
187  // Get a const pointer to the raw depth buffer
188  const void*
190  {
191  return (wrapper_->getData ());
192  }
193 
194  // Data buffer size in bytes
195  int
196  getDataSize () const
197  {
198  return (wrapper_->getDataSize ());
199  }
200 
201  // Size of each row, including any padding
202  inline unsigned
203  getStep() const
204  {
205  return (getDataSize() / getHeight());
206  }
207 
208  protected:
211  };
212 
213  } // namespace
214 }
215 
pcl_macros.h
Defines all the PCL and non-PCL macros used.
pcl
Definition: convolution.h:46
pcl::io::Image::getDataSize
int getDataSize() const
Definition: image.h:196
pcl::io::Image::getStep
unsigned getStep() const
Definition: image.h:203
pcl::io::Image::getData
const void * getData()
Definition: image.h:189
pcl::io::Image::BAYER_GRBG
@ BAYER_GRBG
Definition: image.h:68
pcl::io::Image::Image
Image(FrameWrapper::Ptr image_metadata)
Definition: image.h:73
pcl::io::FrameWrapper::Ptr
shared_ptr< FrameWrapper > Ptr
Definition: image_metadata_wrapper.h:56
pcl::io::Image::fillRaw
virtual void fillRaw(unsigned char *rgb_buffer) const
fills a user given buffer with the raw values.
Definition: image.h:122
pcl::io::Image::getSystemTimestamp
Timestamp getSystemTimestamp() const
Definition: image.h:182
pcl::io::Image::Timestamp
std::chrono::high_resolution_clock::time_point Timestamp
Definition: image.h:64
pcl::io::Image::Image
Image(FrameWrapper::Ptr image_metadata, Timestamp time)
Definition: image.h:78
pcl::io::Image::getFrameID
unsigned getFrameID() const
Definition: image.h:161
pcl::io::Image::Ptr
shared_ptr< Image > Ptr
Definition: image.h:60
pcl::RGB
A structure representing RGB color information.
Definition: point_types.hpp:345
pcl::io::Image
Image interface class providing an interface to fill a RGB or Grayscale image buffer.
Definition: image.h:57
pcl::io::Image::getHeight
unsigned getHeight() const
Definition: image.h:151
pcl::io::Image::Clock
std::chrono::high_resolution_clock Clock
Definition: image.h:63
pcl::io::Image::~Image
virtual ~Image()
virtual Destructor that never throws an exception.
Definition: image.h:86
pcl::io::Image::YUV422
@ YUV422
Definition: image.h:69
pcl::io::Image::Encoding
Encoding
Definition: image.h:66
pcl::io::Image::wrapper_
FrameWrapper::Ptr wrapper_
Definition: image.h:209
pcl::io::Image::timestamp_
Timestamp timestamp_
Definition: image.h:210
pcl::io::Image::ConstPtr
shared_ptr< const Image > ConstPtr
Definition: image.h:61
pcl::io::Image::getWidth
unsigned getWidth() const
Definition: image.h:142
pcl::io::Image::getTimestamp
std::uint64_t getTimestamp() const
Definition: image.h:171
memory.h
Defines functions, macros and traits for allocating and using memory.
PCL_EXPORTS
#define PCL_EXPORTS
Definition: pcl_macros.h:331
pcl::uint64_t
std::uint64_t uint64_t
Definition: types.h:60