Astra SDK  v2.1.3
Depth.hpp
1 // This file is part of the Orbbec Astra SDK [https://orbbec3d.com]
2 // Copyright (c) 2015-2017 Orbbec 3D
3 //
4 // Licensed under the Apache License, Version 2.0 (the "License");
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
7 //
8 // http://www.apache.org/licenses/LICENSE-2.0
9 //
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
15 //
16 // Be excellent to each other.
17 #ifndef ASTRA_DEPTH_HPP
18 #define ASTRA_DEPTH_HPP
19 
20 #include <astra_core/astra_core.hpp>
21 #include <astra/capi/astra_ctypes.h>
22 #include <astra/capi/streams/depth_capi.h>
23 #include <astra/streams/Image.hpp>
24 #include <astra/Vector.hpp>
25 
26 namespace astra {
27 
40  {
41  public:
46  : depthStream_(depthStream)
47  { }
48 
53  {
54  this->depthStream_ = rhs.depthStream_;
55  }
56 
61  {
62  this->depthStream_ = rhs.depthStream_;
63  return *this;
64  }
65 
73  {
74  float worldX, worldY, worldZ;
75  astra_convert_depth_to_world(depthStream_,
76  depthPosition.x,
77  depthPosition.y,
78  depthPosition.z,
79  &worldX, &worldY, &worldZ);
80 
81  return Vector3f(worldX, worldY, worldZ);
82  }
83 
91  {
92  float depthX, depthY, depthZ;
93  astra_convert_world_to_depth(depthStream_,
94  worldPosition.x,
95  worldPosition.y,
96  worldPosition.z,
97  &depthX, &depthY, &depthZ);
98 
99  return Vector3f(depthX, depthY, depthZ);
100  }
101 
112  void convert_depth_to_world(float depthX, float depthY, float depthZ,
113  float& worldX, float& worldY, float& worldZ) const
114  {
115  astra_convert_depth_to_world(depthStream_, depthX, depthY, depthZ,
116  &worldX, &worldY, &worldZ);
117  }
118 
129  void convert_world_to_depth(float worldX, float worldY, float worldZ,
130  float& depthX, float& depthY, float& depthZ) const
131  {
132  astra_convert_world_to_depth(depthStream_,
133  worldX, worldY, worldZ,
134  &depthX, &depthY, &depthZ);
135  }
136 
137  private:
138  astra_depthstream_t depthStream_;
139  };
140 
146  class DepthStream : public ImageStream
147  {
148  public:
149  explicit DepthStream(astra_streamconnection_t connection)
150  : ImageStream(connection),
151  depthStream_(reinterpret_cast<astra_depthstream_t>(connection)),
152  coordinateMapper_(reinterpret_cast<astra_depthstream_t>(connection))
153  { }
154 
155  static const astra_stream_type_t id = ASTRA_STREAM_DEPTH;
156 
163  {
165  astra_depthstream_get_depth_to_world_data(depthStream_, &data);
166 
167  return data;
168  }
169 
175  bool registration_enabled() const
176  {
177  bool enabled = false;
178  astra_depthstream_get_registration(depthStream_, &enabled);
179 
180  return enabled;
181  }
182 
188  void enable_registration(bool enable)
189  {
190  astra_depthstream_set_registration(depthStream_, enable);
191  }
192 
199  {
201  }
202 
209  {
210  int mode = 0;
212  return mode;
213  }
214 
221  void serial_number(char* serialnumber, uint32_t length) const
222  {
223  astra_depthstream_get_serialnumber(depthStream_, serialnumber, length);
224  }
225 
231  std::string serial_number() const
232  {
233  char serialNumber[ASTRA_SERIAL_NUMBER_MAX];
234  astra_depthstream_get_serialnumber(depthStream_, serialNumber, sizeof(serialNumber) / sizeof(char));
235  return std::string(serialNumber);
236  }
237 
243  std::uint32_t chip_id() const
244  {
245  uint32_t chip_id;
246  astra_depthstream_get_chip_id(depthStream_, &chip_id);
247  return chip_id;
248  }
249 
255  void start_record(std::string filename)
256  {
257  astra_depthstream_start_record(depthStream_, filename.c_str());
258  }
259 
263  void stop_record()
264  {
265  astra_depthstream_stop_record(depthStream_);
266  }
267 
273  const CoordinateMapper& coordinateMapper() const { return coordinateMapper_; };
274 
275  private:
276  astra_depthstream_t depthStream_;
277  CoordinateMapper coordinateMapper_;
278  };
279 
280 
286  class DepthFrame : public ImageFrame<int16_t, ASTRA_STREAM_DEPTH>
287  {
288  public:
290  : ImageFrame(frame, ASTRA_PIXEL_FORMAT_DEPTH_MM)
291  {}
292 
293  };
295 }
296 
297 #endif /* ASTRA_DEPTH_HPP */
CoordinateMapper
Definition: Depth.hpp:40
Vector3f convert_world_to_depth(Vector3f worldPosition) const
convert depth coor to world coor
Definition: Depth.hpp:90
CoordinateMapper operator=(const CoordinateMapper &rhs)
copy Constructs
Definition: Depth.hpp:60
void convert_depth_to_world(float depthX, float depthY, float depthZ, float &worldX, float &worldY, float &worldZ) const
convert depth coor to world coor
Definition: Depth.hpp:112
void convert_world_to_depth(float worldX, float worldY, float worldZ, float &depthX, float &depthY, float &depthZ) const
convert world coor to depth coor
Definition: Depth.hpp:129
CoordinateMapper(const CoordinateMapper &rhs)
copy Constructs
Definition: Depth.hpp:52
astra::Vector3f convert_depth_to_world(astra::Vector3f depthPosition) const
convert depth coor to world coor
Definition: Depth.hpp:72
CoordinateMapper(astra_depthstream_t depthStream)
Constructs
Definition: Depth.hpp:45
A Depth Frame
Definition: Depth.hpp:287
A Depth Stream
Definition: Depth.hpp:147
int get_d2c_resolution()
get depth to color resolution if device supports.
Definition: Depth.hpp:208
void enable_registration(bool enable)
enable registration
Definition: Depth.hpp:188
std::string serial_number() const
get serial number
Definition: Depth.hpp:231
void start_record(std::string filename)
start record oni file.
Definition: Depth.hpp:255
const CoordinateMapper & coordinateMapper() const
get Coordinate Mapper
Definition: Depth.hpp:273
std::uint32_t chip_id() const
get chip id
Definition: Depth.hpp:243
bool registration_enabled() const
return is registration enabled
Definition: Depth.hpp:175
void stop_record()
stop record oni file.
Definition: Depth.hpp:263
void serial_number(char *serialnumber, uint32_t length) const
get serial number
Definition: Depth.hpp:221
void set_d2c_resolution(int mode)
set depth to color resolution if device supports.
Definition: Depth.hpp:198
astra_conversion_cache_t depth_to_world_data() const
get world conversion
Definition: Depth.hpp:162
Basic Image Frame
Definition: Image.hpp:397
ImageFrame(astra_imageframe_t frame, astra_pixel_format_t expected_format)
Default constructs
Definition: Image.hpp:405
basic Image Stream
Definition: Image.hpp:271
ImageStreamMode mode() const
get current image mode
Definition: Image.hpp:368
ASTRA_API_EX astra_status_t astra_depthstream_set_d2c_resolution(astra_depthstream_t depthStream, int mode)
ASTRA_API_EX astra_status_t astra_depthstream_get_d2c_resolution(astra_depthstream_t depthStream, int *mode)
Definition: stream_types.h:37
Definition: astra_plugin.h:24
Represents a float 3d vector
Definition: Vector3f.hpp:30
Definition: depth_types.h:23