Mech-Eye API 2.3.3
API reference documentation for Mech-Eye Industrial 3D Camera
Loading...
Searching...
No Matches
MechEyeFrame.hpp
1/*******************************************************************************
2 *BSD 3-Clause License
3 *
4 *Copyright (c) 2016-2024, Mech-Mind Robotics
5 *All rights reserved.
6 *
7 *Redistribution and use in source and binary forms, with or without
8 *modification, are permitted provided that the following conditions are met:
9 *
10 *1. Redistributions of source code must retain the above copyright notice, this
11 * list of conditions and the following disclaimer.
12 *
13 *2. Redistributions in binary form must reproduce the above copyright notice,
14 * this list of conditions and the following disclaimer in the documentation
15 * and/or other materials provided with the distribution.
16 *
17 *3. Neither the name of the copyright holder nor the names of its
18 * contributors may be used to endorse or promote products derived from
19 * this software without specific prior written permission.
20 *
21 *THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22 *AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 *IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
24 *DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
25 *FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 *DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
27 *SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
28 *CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
29 *OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30 *OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 ******************************************************************************/
32
33#pragma once
34#include <cstdint>
35#include <memory>
36#include <vector>
37#include <stdexcept>
38#include "api_global.h"
39#include "MechEyeDataType.h"
40
41namespace mmind {
42namespace api {
43
44template <typename ElementType>
45class Frame;
46
51{
52 float d{0};
53};
54
59{
60 uint8_t b{0};
61 uint8_t g{0};
62 uint8_t r{0};
63};
64
69{
70 float x{0};
71 float y{0};
72 float z{0};
73};
74
79{
80 float x{0};
81 float y{0};
82 float z{0};
83 uint8_t b{0};
84 uint8_t g{0};
85 uint8_t r{0};
86};
87
88typedef Frame<ElementColor> ColorMap;
89
90typedef Frame<ElementDepth> DepthMap;
91
92typedef Frame<ElementPointXYZ> PointXYZMap;
93
94typedef Frame<ElementPointXYZBGR> PointXYZBGRMap;
95
99template <typename ElementType>
100class Frame
101{
102public:
106 Frame() : _width(0), _height(0), _pData(nullptr) {}
111
115 inline uint32_t width() const { return _width; }
116
120 inline uint32_t height() const { return _height; }
121
125 inline bool empty() const { return !_pData; }
126
130 inline const ElementType* data() const { return _pData.get(); }
131
135 inline ElementType* data()
136 {
137 return const_cast<ElementType*>(static_cast<const Frame<ElementType>&>(*this).data());
138 }
139
145 inline const ElementType& operator[](std::size_t n) const
146 {
147 if (n >= _height * _width || !_pData)
148 throw std::out_of_range("invalid subscript");
149 ElementType* data = _pData.get();
150 return data[n];
151 }
152
158 inline ElementType& operator[](std::size_t n)
159 {
160 return const_cast<ElementType&>(static_cast<const Frame<ElementType>&>(*this)[n]);
161 }
162
170 const ElementType& at(uint32_t row, uint32_t col) const
171 {
172 if (row >= _height || col >= _width || !_pData)
173 throw std::out_of_range("invalid subscript");
174 ElementType* data = _pData.get();
175 return data[row * _width + col];
176 }
177
185 ElementType& at(uint32_t row, uint32_t col)
186 {
187 return const_cast<ElementType&>(static_cast<const Frame<ElementType>&>(*this).at(row, col));
188 }
189
196 void resize(uint32_t width, uint32_t height)
197 {
198 if (_width == width && _height == height)
199 return;
200
201 _width = width;
202 _height = height;
203 _pData.reset(new ElementType[_width * _height], [](ElementType* p) { delete[] p; });
204 }
205
209 void release()
210 {
211 _pData.reset();
212 _width = 0;
213 _height = 0;
214 }
215
216private:
217 uint32_t _width;
218 uint32_t _height;
219 std::shared_ptr<ElementType> _pData;
220};
221
223{
224public:
225 LineBatch() : _lineCount(0), _columnCount(0) {}
226 ~LineBatch() {}
227
228 const Frame<float>& depth() const { return _depth; }
229 Frame<float>& depth() { return _depth; }
230
231 const Frame<unsigned char>& intensity() const { return _intensity; }
232 Frame<unsigned char>& intensity() { return _intensity; }
233
234 const Frame<unsigned int>& encoder() const { return _encoder; }
235 Frame<unsigned int>& encoder() { return _encoder; }
236
237 const Frame<long long>& frameId() const { return _frameId; }
238 Frame<long long>& frameId() { return _frameId; }
239
240 void setLineCount(uint32_t lineCount) { _lineCount = lineCount; }
241 uint32_t lineCount() const { return _lineCount; }
242 uint32_t columnCount() const { return _columnCount; }
243
244 float depthAt(uint32_t row, uint32_t col) const { return _depth.at(row, col); }
245 unsigned char intensityAt(uint32_t row, uint32_t col) const { return _intensity.at(row, col); }
246 unsigned int encoderAt(uint32_t row, uint32_t col) const { return _encoder.at(row, col); }
247 long long frameIdAt(uint32_t row, uint32_t col) const { return _frameId.at(row, col); }
248
249 void resize(uint32_t width, uint32_t height)
250 {
251 _columnCount = width;
252 _lineCount = height;
253 _depth.resize(_columnCount, _lineCount);
254 _intensity.resize(_columnCount, _lineCount);
255 _encoder.resize(1, _lineCount);
256 _frameId.resize(1, _lineCount);
257 }
258
259private:
260 Frame<float> _depth;
261 Frame<unsigned char> _intensity;
262 Frame<unsigned int> _encoder;
263 Frame<long long> _frameId;
264 uint32_t _lineCount;
265 uint32_t _columnCount;
266};
267
268} // namespace api
269} // namespace mmind
Definition of data structure in device capturing image.
uint32_t width() const
const ElementType & operator[](std::size_t n) const
uint32_t height() const
void resize(uint32_t width, uint32_t height)
ElementType & at(uint32_t row, uint32_t col)
const ElementType & at(uint32_t row, uint32_t col) const
ElementType * data()
const ElementType * data() const
ElementType & operator[](std::size_t n)
Element in ColorMap.
uint8_t r
Red channel.
uint8_t b
Blue channel.
uint8_t g
Green channel.
Element in DepthMap.
float d
Depth channel, unit: mm.
Element in PointXYZBGRMap.
float y
Y channel, unit: mm.
float x
X channel, unit: mm.
float z
Z channel, unit: mm.
Element in PointXYZMap.
float x
X channel, unit: mm.
float z
Z channel, unit: mm.
float y
Y channel, unit: mm.