19#include "enpose_api.h"
52class Error :
public std::runtime_error {
54 explicit Error(
const std::string& message) : std::runtime_error(message) {}
69 EnposeDeviceInfo* devices =
nullptr;
70 std::size_t count = 0;
71 if (enpose_discover(&devices, &count) != ENPOSE_OK) {
72 throw Error(
"enpose_discover failed");
74 std::vector<DeviceInfo> result;
75 result.reserve(count);
76 for (std::size_t i = 0; i < count; ++i) {
78 devices[i].compatible});
80 enpose_device_info_array_free(devices, count);
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);
105 if (handle_ !=
nullptr) {
106 enpose_pose_stream_free(handle_);
114 : handle_(std::exchange(other.handle_,
nullptr)) {}
117 if (
this != &other) {
118 if (handle_ !=
nullptr) {
119 enpose_pose_stream_free(handle_);
121 handle_ = std::exchange(other.handle_,
nullptr);
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");
139 std::vector<MarkerPose> result(poses, poses + count);
140 enpose_marker_pose_array_free(poses, count);
145 EnposePoseStream* handle_;
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