Viam C++ SDK current
Loading...
Searching...
No Matches
geometry.hpp
1#pragma once
2
3#include <array>
4#include <string>
5#include <tuple>
6#include <variant>
7
8#include <viam/sdk/common/mesh.hpp>
9#include <viam/sdk/common/pose.hpp>
10#include <viam/sdk/common/proto_convert.hpp>
11#include <viam/sdk/spatialmath/orientation.hpp>
12
13namespace viam {
14namespace common {
15namespace v1 {
16
17class RectangularPrism;
18class Sphere;
19class Capsule;
20
21class Geometry;
22class GetGeometriesResponse;
23
24class GeoPoint;
25class GeoGeometry;
26
27} // namespace v1
28} // namespace common
29} // namespace viam
30
31namespace viam {
32namespace sdk {
33
34enum class GeometryType { box, sphere, capsule, point, mesh };
35
36struct box {
37 double x = 0.0;
38 double y = 0.0;
39 double z = 0.0;
40 friend bool operator==(const box&, const box&) = default;
41};
42struct sphere {
43 double radius = 0.0;
44 friend bool operator==(const sphere&, const sphere&) = default;
45};
46struct capsule {
47 double radius = 0.0;
48 double length = 0.0;
49 friend bool operator==(const capsule&, const capsule&) = default;
50};
51
53using geometry_specifics = std::variant<struct box, struct sphere, struct capsule, mesh>;
54
57 public:
58 GeometryConfig() = default;
59
60 GeometryConfig(pose, geometry_specifics, Orientation, std::string label);
61 GeometryConfig(pose, geometry_specifics, std::string label);
62
63 double get_theta() const;
64
65 const pose& get_pose() const;
66
68 const geometry_specifics& get_geometry_specifics() const;
69
72 GeometryType get_geometry_type() const;
73
74 const Orientation& get_orientation() const;
75
76 const std::string& get_label() const;
77
78 friend bool operator==(const GeometryConfig& lhs, const GeometryConfig& rhs);
79
80 private:
81 pose pose_;
82 geometry_specifics geometry_specifics_;
83 // TODO: if and when RDK makes more explicit use of ox/oy/oz, we should
84 // do the same here
85 Orientation orientation_;
86 std::string label_;
87};
88
89struct geo_point {
90 // TODO it really bugs me that this is not in lat-long but this would break existing
91 // aggregate initializers
92 double longitude = 0.0, latitude = 0.0;
93
94 friend bool operator==(const geo_point&, const geo_point&) = default;
95 friend std::ostream& operator<<(std::ostream& os, const geo_point& v);
96};
97
100 geo_point location;
101 std::vector<GeometryConfig> geometries;
102
103 friend bool operator==(const geo_geometry&, const geo_geometry&) = default;
104};
105
106namespace proto_convert_details {
107
108template <>
110 void operator()(const box&, common::v1::RectangularPrism*) const;
111};
112
113template <>
114struct from_proto_impl<common::v1::RectangularPrism> {
115 box operator()(const common::v1::RectangularPrism*) const;
116};
117
118template <>
120 void operator()(const sphere&, common::v1::Sphere*) const;
121};
122
123template <>
124struct from_proto_impl<common::v1::Sphere> {
125 sphere operator()(const common::v1::Sphere*) const;
126};
127
128template <>
130 void operator()(const capsule&, common::v1::Capsule*) const;
131};
132
133template <>
134struct from_proto_impl<common::v1::Capsule> {
135 capsule operator()(const common::v1::Capsule*) const;
136};
137
138template <>
140 void operator()(const GeometryConfig&, common::v1::Geometry*) const;
141};
142
143template <>
144struct from_proto_impl<common::v1::Geometry> {
145 GeometryConfig operator()(const common::v1::Geometry*) const;
146};
147
148template <>
150 void operator()(const geo_point&, common::v1::GeoPoint*) const;
151};
152
153template <>
154struct from_proto_impl<common::v1::GeoPoint> {
155 geo_point operator()(const common::v1::GeoPoint*) const;
156};
157
158template <>
160 void operator()(const geo_geometry&, common::v1::GeoGeometry*) const;
161};
162
163template <>
164struct from_proto_impl<common::v1::GeoGeometry> {
165 geo_geometry operator()(const common::v1::GeoGeometry*) const;
166};
167
168template <>
169struct from_proto_impl<common::v1::GetGeometriesResponse> {
170 std::vector<GeometryConfig> operator()(const common::v1::GetGeometriesResponse*) const;
171};
172
173} // namespace proto_convert_details
174
175} // namespace sdk
176} // namespace viam
The dimensions of a given geometry and the pose of its center.
Definition geometry.hpp:56
const geometry_specifics & get_geometry_specifics() const
The concrete geometry type stored in this object.
GeometryType get_geometry_type() const
Type enumerator for the return value of get_geometry_specifics.
Definition geometry.hpp:36
Definition geometry.hpp:46
Information describing geometries located at a geo_point.
Definition geometry.hpp:99
Definition geometry.hpp:89
Definition pose.hpp:30
Definition geometry.hpp:42