scenario_simulator_v2 C++ API
primitive.hpp
Go to the documentation of this file.
1 // Copyright 2015 TIER IV, Inc. All rights reserved.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #ifndef SIMPLE_SENSOR_SIMULATOR__SENSOR_SIMULATION__PRIMITIVES__PRIMITIVE_HPP_
16 #define SIMPLE_SENSOR_SIMULATOR__SENSOR_SIMULATION__PRIMITIVES__PRIMITIVE_HPP_
17 
18 #include <embree4/rtcore.h>
19 
20 #include <algorithm>
22 #include <geometry_msgs/msg/pose.hpp>
23 #include <optional>
24 #include <string>
25 #include <vector>
26 
28 {
29 struct Vertex
30 {
31  float x;
32  float y;
33  float z;
34 };
35 
36 Vertex toVertex(const geometry_msgs::msg::Point & point);
37 std::vector<Vertex> toVertex(const std::vector<geometry_msgs::msg::Point> & points);
38 geometry_msgs::msg::Point toPoint(const Vertex & v);
39 std::vector<geometry_msgs::msg::Point> toPoints(const std::vector<Vertex> & v);
40 
41 struct Triangle
42 {
43  unsigned int v0;
44  unsigned int v1;
45  unsigned int v2;
46 };
47 
48 namespace primitives
49 {
50 class Primitive
51 {
52 public:
53  Primitive(std::string type, const geometry_msgs::msg::Pose & pose);
54  virtual ~Primitive() = default;
56  const geometry_msgs::msg::Pose pose;
57  unsigned int addToScene(RTCDevice device, RTCScene scene);
58  std::vector<Vertex> getVertex() const;
59  std::vector<Triangle> getTriangles() const;
60  std::vector<geometry_msgs::msg::Point> get2DConvexHull() const;
61  std::vector<geometry_msgs::msg::Point> get2DConvexHull(
62  const geometry_msgs::msg::Pose & sensor_pose) const;
63  std::optional<double> getMax(const math::geometry::Axis & axis) const;
64  std::optional<double> getMin(const math::geometry::Axis & axis) const;
65  std::optional<double> getMax(
66  const math::geometry::Axis & axis, const geometry_msgs::msg::Pose & sensor_pose) const;
67  std::optional<double> getMin(
68  const math::geometry::Axis & axis, const geometry_msgs::msg::Pose & sensor_pose) const;
69 
70 protected:
71  std::vector<Vertex> transform() const;
72  std::vector<Vertex> transform(const geometry_msgs::msg::Pose & sensor_pose) const;
73  std::vector<Vertex> vertices_;
74  std::vector<Triangle> triangles_;
75 
76 private:
77  Vertex transform(const Vertex & v) const;
78  Vertex transform(const Vertex & v, const geometry_msgs::msg::Pose & sensor_pose) const;
79 };
80 } // namespace primitives
81 } // namespace simple_sensor_simulator
82 
83 #endif // SIMPLE_SENSOR_SIMULATOR__SENSOR_SIMULATION__PRIMITIVES__PRIMITIVE_HPP_
std::vector< Triangle > triangles_
Definition: primitive.hpp:74
unsigned int addToScene(RTCDevice device, RTCScene scene)
Definition: primitive.cpp:115
std::vector< Vertex > getVertex() const
Definition: primitive.cpp:100
const geometry_msgs::msg::Pose pose
Definition: primitive.hpp:56
Primitive(std::string type, const geometry_msgs::msg::Pose &pose)
Definition: primitive.cpp:67
std::vector< Vertex > transform() const
Definition: primitive.cpp:82
std::vector< geometry_msgs::msg::Point > get2DConvexHull() const
Definition: primitive.cpp:110
const std::string type
Definition: primitive.hpp:55
std::vector< Vertex > vertices_
Definition: primitive.hpp:73
std::vector< Triangle > getTriangles() const
Definition: primitive.cpp:102
std::optional< double > getMax(const math::geometry::Axis &axis) const
Definition: primitive.cpp:138
std::optional< double > getMin(const math::geometry::Axis &axis) const
Definition: primitive.cpp:146
Axis
Definition: polygon.hpp:24
Definition: constants.hpp:19
std::vector< geometry_msgs::msg::Point > toPoints(const std::vector< Vertex > &v)
Definition: primitive.cpp:56
geometry_msgs::msg::Point toPoint(const Vertex &v)
Definition: primitive.cpp:38
Vertex toVertex(const geometry_msgs::msg::Point &point)
Definition: primitive.cpp:29
std::string string
Definition: junit5.hpp:26
Definition: primitive.hpp:42
unsigned int v2
Definition: primitive.hpp:45
unsigned int v0
Definition: primitive.hpp:43
unsigned int v1
Definition: primitive.hpp:44
Definition: primitive.hpp:30
float x
Definition: primitive.hpp:31
float z
Definition: primitive.hpp:33
float y
Definition: primitive.hpp:32