ed
msg_conversions.h
Go to the documentation of this file.
1 #ifndef ED_HELPERS_MSG_CONVERSIONS_H_
2 #define ED_HELPERS_MSG_CONVERSIONS_H_
3 
4 #include "ed_msgs/EntityInfo.h"
5 #include "ed/entity.h"
6 
7 #include "geolib/Shape.h"
8 #include "geolib/Box.h"
10 #include "geolib/datatypes.h"
12 
14 
15 #include <shape_msgs/SolidPrimitive.h>
16 
17 namespace ed {
18 
19 // ------------------------------ TO ROS ------------------------------
20 
26 void convert(const geo::ShapeConstPtr shape, ed_msgs::SubVolume& sub_Volume)
27 {
28  geo::Vector3 min = shape->getBoundingBox().getMin();
29  geo::Vector3 max = shape->getBoundingBox().getMax();
30 
31  geo::Vector3 pos = (min + max)/2;
32  geo::Vector3 size = max - min;
33 
34  geo::convert(pos, sub_Volume.center_point.point);
35 
36  shape_msgs::SolidPrimitive solid;
37  sub_Volume.geometry.type = sub_Volume.geometry.BOX;
38  sub_Volume.geometry.dimensions.resize(3, 0);
39  sub_Volume.geometry.dimensions[solid.BOX_X] = size.x;
40  sub_Volume.geometry.dimensions[solid.BOX_Y] = size.y;
41  sub_Volume.geometry.dimensions[solid.BOX_Z] = size.z;
42 }
43 
49 void convert(const ed::Entity& e, ed_msgs::EntityInfo& msg) {
50  msg.id = e.id().str();
51  msg.type = e.type();
52 
53  msg.types.resize(0);
54  for(std::set<std::string>::const_iterator it = e.types().begin(); it != e.types().end(); ++it)
55  msg.types.push_back(*it);
56 
57  msg.existence_probability = e.existenceProbability();
58 
59  // Convex hull
60  const ed::ConvexHull& convex_hull = e.convexHull();
61  if (!convex_hull.points.empty())
62  {
63  msg.z_min = convex_hull.z_min;
64  msg.z_max = convex_hull.z_max;
65 
66  msg.convex_hull.resize(convex_hull.points.size());
67  for(unsigned int i = 0; i < msg.convex_hull.size(); ++i)
68  {
69  msg.convex_hull[i].x = convex_hull.points[i].x;
70  msg.convex_hull[i].y = convex_hull.points[i].y;
71  msg.convex_hull[i].z = 0;
72  }
73  }
74  else
75  {
76  msg.convex_hull.resize(0);
77  msg.z_min = 0;
78  msg.z_max = 0;
79  }
80 
81  msg.has_shape = (e.visual() != nullptr);
82  msg.has_pose = e.has_pose();
83  if (e.has_pose())
84  {
85  geo::convert(e.pose(), msg.pose);
86  }
87 
88  msg.last_update_time = ros::Time(e.lastUpdateTimestamp());
89 
90  if (!e.data().empty())
91  {
94  emitter.emit(e.data(), ss);
95 
96  msg.data = ss.str();
97  }
98  else
99  {
100  msg.data = "";
101  }
102 
103  if (!e.volumes().empty())
104  {
105  for (std::map<std::string, geo::ShapeConstPtr>::const_iterator it = e.volumes().begin(); it != e.volumes().end(); ++it)
106  {
107  ed_msgs::Volume volume;
108  volume.name = it->first;
109 
110  geo::CompositeShapeConstPtr composite = std::dynamic_pointer_cast<const geo::CompositeShape>(it->second);
111  if (composite)
112  {
113  const std::vector<std::pair<geo::ShapePtr, geo::Transform> >& shapes = composite->getShapes();
114  for (std::vector<std::pair<geo::ShapePtr, geo::Transform> >::const_iterator it2 = shapes.begin();
115  it2 != shapes.end(); ++it2)
116  {
117  geo::ShapePtr shape_tr(new geo::Shape());
118  shape_tr->setMesh(it2->first->getMesh().getTransformed(it2->second.inverse()));
119 
120  ed_msgs::SubVolume sub_volume;
121  convert(shape_tr, sub_volume);
122  sub_volume.center_point.header.frame_id = e.id().str();
123  volume.subvolumes.push_back(sub_volume);
124  }
125  }
126  else
127  {
128  ed_msgs::SubVolume sub_volume;
129  convert(it->second, sub_volume);
130  volume.subvolumes.push_back(sub_volume);
131  }
132  msg.volumes.push_back(volume);
133  }
134  }
135  else
136  {
137  msg.volumes.resize(0);
138  }
139 
140  // Flags
141  msg.flags.resize(0);
142  for(std::set<std::string>::const_iterator it = e.flags().begin(); it != e.flags().end(); ++it)
143  msg.flags.push_back(*it);
144 }
145 
146 // ------------------------------ FROM ROS ------------------------------
147 
148 }
149 
150 #endif
datatypes.h
ed::Entity::has_pose
bool has_pose() const
Definition: entity.h:115
std::string::resize
T resize(T... args)
ed::ConvexHull::z_min
float z_min
Definition: convex_hull.h:16
std::shared_ptr
ed::Entity::lastUpdateTimestamp
double lastUpdateTimestamp() const
Definition: entity.h:220
ed::ConvexHull
Definition: convex_hull.h:11
entity.h
std::pair
std::vector
tue::config::YAMLEmitter
Shape.h
std::stringstream
ed::Entity::convexHull
const ConvexHull & convexHull() const
Definition: entity.h:75
ed::Entity::data
const tue::config::DataConstPointer & data() const
Definition: entity.h:117
std::string::push_back
T push_back(T... args)
ed::Entity::flags
const std::set< std::string > & flags() const
Definition: entity.h:228
ed::Entity::type
const TYPE & type() const
Definition: entity.h:40
tue::config::DataConstPointer::empty
bool empty() const
ed::Entity
Definition: entity.h:30
ed::convert
void convert(const geo::ShapeConstPtr shape, ed_msgs::SubVolume &sub_Volume)
converting geo::ShapeConstPtr to ed_msgs::SubVolume message
Definition: msg_conversions.h:26
ed::Entity::pose
const geo::Pose3D & pose() const
Definition: entity.h:97
CompositeShape.h
geo::Vector3
yaml_emitter.h
std::map
geo::convert
void convert(const geo::DepthCamera &cam_model, sensor_msgs::CameraInfo &msg)
ed::Entity::existenceProbability
double existenceProbability() const
Definition: entity.h:216
tue::config::YAMLEmitter::emit
void emit(const tue::config::DataConstPointer &cfg, std::ostream &out, const std::string &indent="")
std::vector::begin
T begin(T... args)
ed::Entity::types
const std::set< TYPE > & types() const
Definition: entity.h:43
ed
Definition: convex_hull.h:8
std::stringstream::str
T str(T... args)
Box.h
std::vector::end
T end(T... args)
ed::Entity::id
const UUID & id() const
Definition: entity.h:38
ed::ConvexHull::z_max
float z_max
Definition: convex_hull.h:16
ed::Entity::volumes
const std::map< std::string, geo::ShapeConstPtr > & volumes() const
Definition: entity.h:65
ed::Entity::visual
geo::ShapeConstPtr visual() const
Definition: entity.h:58
std::set
ed::UUID::str
const std::string & str() const
Definition: uuid.h:27
msg_conversions.h
geo::Shape
ed::ConvexHull::points
std::vector< geo::Vec2f > points
Definition: convex_hull.h:13