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