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
32// TODO(RSDK-4553): add thorough documentation to this whole file.
33
34enum class GeometryType { box, sphere, capsule, point };
35
36struct box {
37 double x;
38 double y;
39 double z;
40 friend bool operator==(const box& lhs, const box& rhs);
41};
42struct sphere {
43 double radius;
44 friend bool operator==(const sphere& lhs, const sphere& rhs);
45};
46struct capsule {
47 double radius;
48 double length;
49 friend bool operator==(const capsule& lhs, const capsule& rhs);
50};
51
52typedef boost::variant<struct box, struct sphere, struct capsule> geometry_specifics;
53
55 public:
56 GeometryConfig() = default;
57
58 GeometryConfig(pose, geometry_specifics, Orientation, std::string label);
59 GeometryConfig(pose, geometry_specifics, std::string label);
60
61 double get_theta() const;
62 const pose& get_pose() const;
63 const geometry_specifics& get_geometry_specifics() const;
64 GeometryType get_geometry_type() const;
65 const Orientation& get_orientation() const;
66 const std::string& get_label() const;
67
68 friend bool operator==(const GeometryConfig& lhs, const GeometryConfig& rhs);
69
70 private:
71 pose pose_;
72 geometry_specifics geometry_specifics_;
73 // TODO: if and when RDK makes more explicit use of ox/oy/oz, we should
74 // do the same here
75 Orientation orientation_;
76 std::string label_;
77};
78
79struct geo_point {
80 // TODO it really bugs me that this is not in lat-long but this would break existing
81 // aggregate initializers
82 double longitude, latitude;
83
84 friend bool operator==(const geo_point& lhs, const geo_point& rhs);
85 friend std::ostream& operator<<(std::ostream& os, const geo_point& v);
86};
87
89 geo_point location;
90 std::vector<GeometryConfig> geometries;
91
92 friend bool operator==(const geo_geometry& lhs, const geo_geometry& rhs);
93};
94
95namespace proto_convert_details {
96
97template <>
99 void operator()(const box&, common::v1::RectangularPrism*) const;
100};
101
102template <>
103struct from_proto_impl<common::v1::RectangularPrism> {
104 box operator()(const common::v1::RectangularPrism*) const;
105};
106
107template <>
109 void operator()(const sphere&, common::v1::Sphere*) const;
110};
111
112template <>
113struct from_proto_impl<common::v1::Sphere> {
114 sphere operator()(const common::v1::Sphere*) const;
115};
116
117template <>
119 void operator()(const capsule&, common::v1::Capsule*) const;
120};
121
122template <>
123struct from_proto_impl<common::v1::Capsule> {
124 capsule operator()(const common::v1::Capsule*) const;
125};
126
127template <>
129 void operator()(const GeometryConfig&, common::v1::Geometry*) const;
130};
131
132template <>
133struct from_proto_impl<common::v1::Geometry> {
134 GeometryConfig operator()(const common::v1::Geometry*) const;
135};
136
137template <>
139 void operator()(const geo_point&, common::v1::GeoPoint*) const;
140};
141
142template <>
143struct from_proto_impl<common::v1::GeoPoint> {
144 geo_point operator()(const common::v1::GeoPoint*) const;
145};
146
147template <>
149 void operator()(const geo_geometry&, common::v1::GeoGeometry*) const;
150};
151
152template <>
153struct from_proto_impl<common::v1::GeoGeometry> {
154 geo_geometry operator()(const common::v1::GeoGeometry*) const;
155};
156
157template <>
158struct from_proto_impl<common::v1::GetGeometriesResponse> {
159 std::vector<GeometryConfig> operator()(const common::v1::GetGeometriesResponse*) const;
160};
161
162} // namespace proto_convert_details
163
164} // namespace sdk
165} // namespace viam
Definition geometry.hpp:54
Definition geometry.hpp:36
Definition geometry.hpp:46
Definition geometry.hpp:88
Definition geometry.hpp:79
Definition pose.hpp:30
Definition geometry.hpp:42