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