Point Cloud Library (PCL) 1.12.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/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
46namespace 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
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 ()
86 {}
87
88 /**
89 * @param[in] input_width width of input image
90 * @param[in] input_height height of input image
91 * @param[in] output_width width of desired output image
92 * @param[in] output_height height of desired output image
93 * @return whether the resizing is supported or not.
94 */
95 virtual bool
96 isResizingSupported (unsigned input_width, unsigned input_height,
97 unsigned output_width, unsigned output_height) const = 0;
98
99 /**
100 * @brief fills a user given buffer with the RGB values, with an optional nearest-neighbor down sampling and an optional subregion
101 * @param[in] width desired width of output image.
102 * @param[in] height desired height of output image.
103 * @param[in,out] rgb_buffer the output RGB buffer.
104 * @param[in] rgb_line_step optional line step in bytes to allow the output in a rectangular subregion of the output buffer.
105 */
106 virtual void
107 fillRGB (unsigned width, unsigned height, unsigned char* rgb_buffer, unsigned rgb_line_step = 0) const = 0;
108
109 /**
110 * @brief returns the encoding of the native data.
111 * @return encoding
112 */
113 virtual Encoding
114 getEncoding () const = 0;
115
116 /**
117 * @brief fills a user given buffer with the raw values.
118 * @param[in,out] rgb_buffer
119 */
120 virtual void
121 fillRaw (unsigned char* rgb_buffer) const
122 {
123 memcpy (rgb_buffer, wrapper_->getData (), wrapper_->getDataSize ());
124 }
125
126 /**
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
134 fillGrayscale (unsigned width, unsigned height, unsigned char* gray_buffer,
135 unsigned gray_line_step = 0) const = 0;
136
137 /**
138 * @return width of the image
139 */
140 unsigned
141 getWidth () const
142 {
143 return (wrapper_->getWidth ());
144 }
145
146 /**
147 * @return height of the image
148 */
149 unsigned
150 getHeight () const
151 {
152 return (wrapper_->getHeight ());
153 }
154
155 /**
156 * @return frame id of the image.
157 * @note frame ids are ascending, but not necessarily synchronized with other streams
158 */
159 unsigned
160 getFrameID () const
161 {
162 return (wrapper_->getFrameID ());
163 }
164
165 /**
166 * @return the timestamp of the image
167 * @note the time value is not synchronized with the system time
168 */
169 std::uint64_t
171 {
172 return (wrapper_->getTimestamp ());
173 }
174
175
176 /**
177 * @return the timestamp of the image
178 * @note the time value *is* synchronized with the system time.
179 */
180 Timestamp
182 {
183 return (timestamp_);
184 }
185
186 // Get a const pointer to the raw depth buffer
187 const void*
189 {
190 return (wrapper_->getData ());
191 }
192
193 // Data buffer size in bytes
194 int
195 getDataSize () const
196 {
197 return (wrapper_->getDataSize ());
198 }
199
200 // Size of each row, including any padding
201 inline unsigned
202 getStep() const
203 {
204 return (getDataSize() / getHeight());
205 }
206
207 protected:
210 };
211
212 } // namespace
213}
214
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:181
unsigned getWidth() const
Definition: image.h:141
Timestamp timestamp_
Definition: image.h:209
@ 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:160
unsigned getStep() const
Definition: image.h:202
shared_ptr< const Image > ConstPtr
Definition: image.h:60
unsigned getHeight() const
Definition: image.h:150
std::uint64_t getTimestamp() const
Definition: image.h:170
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:208
std::chrono::high_resolution_clock::time_point Timestamp
Definition: image.h:63
virtual ~Image()
virtual Destructor that never throws an exception.
Definition: image.h:85
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...
const void * getData()
Definition: image.h:188
std::chrono::high_resolution_clock Clock
Definition: image.h:62
int getDataSize() const
Definition: image.h:195
virtual void fillRaw(unsigned char *rgb_buffer) const
fills a user given buffer with the raw values.
Definition: image.h:121
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.