19#include "enpose_api.h"
39class Error :
public std::runtime_error {
41 explicit Error(
const std::string& message) : std::runtime_error(message) {}
56 EnposeDeviceInfo* devices =
nullptr;
57 std::size_t count = 0;
58 if (enpose_discover(&devices, &count) != ENPOSE_OK) {
59 throw Error(
"enpose_discover failed");
61 std::vector<DeviceInfo> result;
62 result.reserve(count);
63 for (std::size_t i = 0; i < count; ++i) {
65 devices[i].compatible});
67 enpose_device_info_array_free(devices, count);
80 explicit PoseStream(
const std::string& ip,
bool create_thread =
true)
81 : handle_(enpose_pose_stream_connect(ip.c_str(), create_thread)) {
82 if (handle_ ==
nullptr) {
83 throw Error(
"failed to connect pose stream to " + ip);
92 if (handle_ !=
nullptr) {
93 enpose_pose_stream_free(handle_);
101 : handle_(std::exchange(other.handle_,
nullptr)) {}
104 if (
this != &other) {
105 if (handle_ !=
nullptr) {
106 enpose_pose_stream_free(handle_);
108 handle_ = std::exchange(other.handle_,
nullptr);
120 std::vector<MarkerPose>
receive(
bool block =
false) {
121 EnposeMarkerPose* poses =
nullptr;
122 std::size_t count = 0;
123 if (enpose_pose_stream_receive(handle_, block, &poses, &count) != ENPOSE_OK) {
124 throw Error(
"enpose_pose_stream_receive failed");
126 std::vector<MarkerPose> result(poses, poses + count);
127 enpose_marker_pose_array_free(poses, count);
132 EnposePoseStream* handle_;
Exception thrown by the wrapper when a C call fails.
Definition enpose_api.hpp:39
Error(const std::string &message)
Definition enpose_api.hpp:41
RAII handle to a live pose stream from one device.
Definition enpose_api.hpp:74
PoseStream(const DeviceInfo &device, bool create_thread=true)
Connect to a discovered device.
Definition enpose_api.hpp:88
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:80
PoseStream(PoseStream &&other) noexcept
Definition enpose_api.hpp:100
std::vector< MarkerPose > receive(bool block=false)
Return poses received from the stream.
Definition enpose_api.hpp:120
~PoseStream()
Definition enpose_api.hpp:91
PoseStream & operator=(PoseStream &&other) noexcept
Definition enpose_api.hpp:103
Definition enpose_api.hpp:28
std::vector< DeviceInfo > discover()
Discover Enpose devices on the local network.
Definition enpose_api.hpp:55
::EnposeMarkerPose MarkerPose
Pose of one tracked marker in world coordinates.
Definition enpose_api.hpp:36
One device discovered on the local network.
Definition enpose_api.hpp:45
std::uint32_t serial
Factory serial number.
Definition enpose_api.hpp:47
std::string ip
Device IPv4 address.
Definition enpose_api.hpp:46
bool compatible
True if the device's protocol version matches.
Definition enpose_api.hpp:48