Enpose API — C++
Enpose 6-DoF tracking API
Loading...
Searching...
No Matches
enpose_api.hpp
1
17#pragma once
18
19#include "enpose_api.h"
20
21#include <cstddef>
22#include <cstdint>
23#include <stdexcept>
24#include <string>
25#include <utility>
26#include <vector>
27
28namespace enpose {
29
49using MarkerPose = ::EnposeMarkerPose;
50
52class Error : public std::runtime_error {
53public:
54 explicit Error(const std::string& message) : std::runtime_error(message) {}
55};
56
58struct DeviceInfo {
59 std::string ip;
60 std::uint32_t serial;
62};
63
68inline std::vector<DeviceInfo> discover() {
69 EnposeDeviceInfo* devices = nullptr;
70 std::size_t count = 0;
71 if (enpose_discover(&devices, &count) != ENPOSE_OK) {
72 throw Error("enpose_discover failed");
73 }
74 std::vector<DeviceInfo> result;
75 result.reserve(count);
76 for (std::size_t i = 0; i < count; ++i) {
77 result.push_back(DeviceInfo{std::string(devices[i].ip), devices[i].serial,
78 devices[i].compatible});
79 }
80 enpose_device_info_array_free(devices, count);
81 return result;
82}
83
88public:
93 explicit PoseStream(const std::string& ip, bool create_thread = true)
94 : handle_(enpose_pose_stream_connect(ip.c_str(), create_thread)) {
95 if (handle_ == nullptr) {
96 throw Error("failed to connect pose stream to " + ip);
97 }
98 }
99
101 explicit PoseStream(const DeviceInfo& device, bool create_thread = true)
102 : PoseStream(device.ip, create_thread) {}
103
105 if (handle_ != nullptr) {
106 enpose_pose_stream_free(handle_);
107 }
108 }
109
110 PoseStream(const PoseStream&) = delete;
111 PoseStream& operator=(const PoseStream&) = delete;
112
113 PoseStream(PoseStream&& other) noexcept
114 : handle_(std::exchange(other.handle_, nullptr)) {}
115
116 PoseStream& operator=(PoseStream&& other) noexcept {
117 if (this != &other) {
118 if (handle_ != nullptr) {
119 enpose_pose_stream_free(handle_);
120 }
121 handle_ = std::exchange(other.handle_, nullptr);
122 }
123 return *this;
124 }
125
133 std::vector<MarkerPose> receive(bool block = false) {
134 EnposeMarkerPose* poses = nullptr;
135 std::size_t count = 0;
136 if (enpose_pose_stream_receive(handle_, block, &poses, &count) != ENPOSE_OK) {
137 throw Error("enpose_pose_stream_receive failed");
138 }
139 std::vector<MarkerPose> result(poses, poses + count);
140 enpose_marker_pose_array_free(poses, count);
141 return result;
142 }
143
144private:
145 EnposePoseStream* handle_;
146};
147
148} // namespace enpose
Exception thrown by the wrapper when a C call fails.
Definition enpose_api.hpp:52
Error(const std::string &message)
Definition enpose_api.hpp:54
RAII handle to a live pose stream from one device.
Definition enpose_api.hpp:87
PoseStream(const DeviceInfo &device, bool create_thread=true)
Connect to a discovered device.
Definition enpose_api.hpp:101
PoseStream(const PoseStream &)=delete
PoseStream & operator=(const PoseStream &)=delete
PoseStream(const std::string &ip, bool create_thread=true)
Connect to the device at ip (an IPv4 string; the Enpose API is IPv4-only).
Definition enpose_api.hpp:93
PoseStream(PoseStream &&other) noexcept
Definition enpose_api.hpp:113
std::vector< MarkerPose > receive(bool block=false)
Return poses received from the stream.
Definition enpose_api.hpp:133
~PoseStream()
Definition enpose_api.hpp:104
PoseStream & operator=(PoseStream &&other) noexcept
Definition enpose_api.hpp:116
Definition enpose_api.hpp:28
std::vector< DeviceInfo > discover()
Discover Enpose devices on the local network.
Definition enpose_api.hpp:68
::EnposeMarkerPose MarkerPose
Pose of one tracked marker in world coordinates.
Definition enpose_api.hpp:49
One device discovered on the local network.
Definition enpose_api.hpp:58
std::uint32_t serial
Factory serial number.
Definition enpose_api.hpp:60
std::string ip
Device IPv4 address.
Definition enpose_api.hpp:59
bool compatible
True if the device's protocol version matches.
Definition enpose_api.hpp:61