Mech-Eye API 2.5.1
API reference documentation for Mech-Eye Industrial 3D Camera
Loading...
Searching...
No Matches
MechEyeFrame.hpp
Go to the documentation of this file.
1/*******************************************************************************
2 *BSD 3-Clause License
3 *
4 *Copyright (c) 2016-2025, Mech-Mind Robotics Technologies Co., Ltd.
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
89
91
93
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) {}
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.
Definition MechEyeFrame.hpp:101
const ElementType & operator[](std::size_t n) const
Definition MechEyeFrame.hpp:145
void release()
Definition MechEyeFrame.hpp:209
~Frame()
Definition MechEyeFrame.hpp:110
ElementType * data()
Definition MechEyeFrame.hpp:135
const ElementType * data() const
Definition MechEyeFrame.hpp:130
uint32_t height() const
Definition MechEyeFrame.hpp:120
const ElementType & at(uint32_t row, uint32_t col) const
Definition MechEyeFrame.hpp:170
ElementType & at(uint32_t row, uint32_t col)
Definition MechEyeFrame.hpp:185
uint32_t width() const
Definition MechEyeFrame.hpp:115
bool empty() const
Definition MechEyeFrame.hpp:125
ElementType & operator[](std::size_t n)
Definition MechEyeFrame.hpp:158
Frame()
Definition MechEyeFrame.hpp:106
void resize(uint32_t width, uint32_t height)
Definition MechEyeFrame.hpp:196
Definition MechEyeFrame.hpp:223
long long frameIdAt(uint32_t row, uint32_t col) const
Definition MechEyeFrame.hpp:247
float depthAt(uint32_t row, uint32_t col) const
Definition MechEyeFrame.hpp:244
const Frame< long long > & frameId() const
Definition MechEyeFrame.hpp:237
~LineBatch()
Definition MechEyeFrame.hpp:226
const Frame< unsigned char > & intensity() const
Definition MechEyeFrame.hpp:231
const Frame< unsigned int > & encoder() const
Definition MechEyeFrame.hpp:234
Frame< long long > & frameId()
Definition MechEyeFrame.hpp:238
Frame< unsigned int > & encoder()
Definition MechEyeFrame.hpp:235
LineBatch()
Definition MechEyeFrame.hpp:225
uint32_t lineCount() const
Definition MechEyeFrame.hpp:241
const Frame< float > & depth() const
Definition MechEyeFrame.hpp:228
void setLineCount(uint32_t lineCount)
Definition MechEyeFrame.hpp:240
Frame< float > & depth()
Definition MechEyeFrame.hpp:229
unsigned char intensityAt(uint32_t row, uint32_t col) const
Definition MechEyeFrame.hpp:245
unsigned int encoderAt(uint32_t row, uint32_t col) const
Definition MechEyeFrame.hpp:246
uint32_t columnCount() const
Definition MechEyeFrame.hpp:242
Frame< unsigned char > & intensity()
Definition MechEyeFrame.hpp:232
void resize(uint32_t width, uint32_t height)
Definition MechEyeFrame.hpp:249
Frame< ElementColor > ColorMap
Definition MechEyeFrame.hpp:88
Frame< ElementDepth > DepthMap
Definition MechEyeFrame.hpp:90
Frame< ElementPointXYZBGR > PointXYZBGRMap
Definition MechEyeFrame.hpp:94
Frame< ElementPointXYZ > PointXYZMap
Definition MechEyeFrame.hpp:92
Definition Camera.h:45
Element in ColorMap.
Definition MechEyeFrame.hpp:59
uint8_t g
Green channel.
Definition MechEyeFrame.hpp:61
uint8_t b
Blue channel.
Definition MechEyeFrame.hpp:60
uint8_t r
Red channel.
Definition MechEyeFrame.hpp:62
Element in DepthMap.
Definition MechEyeFrame.hpp:51
float d
Depth channel, unit: mm.
Definition MechEyeFrame.hpp:52
Element in PointXYZBGRMap.
Definition MechEyeFrame.hpp:79
uint8_t g
Green channel.
Definition MechEyeFrame.hpp:84
uint8_t b
Blue channel.
Definition MechEyeFrame.hpp:83
uint8_t r
Red channel.
Definition MechEyeFrame.hpp:85
float y
Y channel, unit: mm.
Definition MechEyeFrame.hpp:81
float x
X channel, unit: mm.
Definition MechEyeFrame.hpp:80
float z
Z channel, unit: mm.
Definition MechEyeFrame.hpp:82
Element in PointXYZMap.
Definition MechEyeFrame.hpp:69
float y
Y channel, unit: mm.
Definition MechEyeFrame.hpp:71
float x
X channel, unit: mm.
Definition MechEyeFrame.hpp:70
float z
Z channel, unit: mm.
Definition MechEyeFrame.hpp:72