marker_shapes_impl.cpp
Go to the documentation of this file.
1 /*
2  * Copyright 2017 Fraunhofer Institute for Manufacturing Engineering and Automation (IPA)
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9 
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 
18 #include <string>
19 
22 
23 /* BEGIN MarkerShape ********************************************************************************************/
25  const shape_msgs::Mesh& mesh,
26  const geometry_msgs::Pose& pose,
27  const std_msgs::ColorRGBA& col)
28 {
29  this->ptr_fcl_bvh_.reset(new BVH_RSS_t());
30  this->ptr_fcl_bvh_->beginModel();
31  for (shape_msgs::MeshTriangle tri : mesh.triangles)
32  {
33  uint32_t v_idx_1 = tri.vertex_indices.elems[0];
34  uint32_t v_idx_2 = tri.vertex_indices.elems[1];
35  uint32_t v_idx_3 = tri.vertex_indices.elems[2];
36 
37  fcl::Vec3f v1(mesh.vertices[v_idx_1].x, mesh.vertices[v_idx_1].y, mesh.vertices[v_idx_1].z);
38  fcl::Vec3f v2(mesh.vertices[v_idx_2].x, mesh.vertices[v_idx_2].y, mesh.vertices[v_idx_2].z);
39  fcl::Vec3f v3(mesh.vertices[v_idx_3].x, mesh.vertices[v_idx_3].y, mesh.vertices[v_idx_3].z);
40 
41  this->ptr_fcl_bvh_->addTriangle(v1, v2, v3);
42  }
43 
44  this->ptr_fcl_bvh_->endModel();
45  this->ptr_fcl_bvh_->computeLocalAABB();
46 
47  marker_.pose = pose;
48  marker_.color = col;
49 
50  marker_.scale.x = 1.0;
51  marker_.scale.y = 1.0;
52  marker_.scale.z = 1.0;
53  marker_.type = visualization_msgs::Marker::MESH_RESOURCE;
54 
55  marker_.header.frame_id = root_frame;
56  marker_.header.stamp = ros::Time::now();
58  marker_.action = visualization_msgs::Marker::ADD;
60  marker_.mesh_resource = ""; // TODO: Not given in this case: can happen e.g. when moveit_msgs/CollisionObject was given!
61 
62  marker_.lifetime = ros::Duration();
63 }
64 
65 
66 MarkerShape<BVH_RSS_t>::MarkerShape(const std::string& root_frame, const std::string& mesh_resource,
67  double x, double y, double z,
68  double quat_x, double quat_y, double quat_z, double quat_w,
69  double color_r, double color_g, double color_b, double color_a)
70 {
71  this->init(mesh_resource, root_frame, x, y, z, quat_x, quat_y, quat_z, quat_w, color_r, color_g, color_b, color_a);
72 }
73 
74 
75 void MarkerShape<BVH_RSS_t>::init(const std::string& mesh_resource, const std::string& root_frame, double x, double y, double z,
76  double quat_x, double quat_y, double quat_z, double quat_w,
77  double color_r, double color_g, double color_b, double color_a)
78 {
79  MeshParser sp(mesh_resource);
80  this->ptr_fcl_bvh_.reset(new BVH_RSS_t());
81 
82  if (0 != sp.createBVH(this->ptr_fcl_bvh_))
83  {
84  ROS_ERROR("Could not create BVH model!");
85  }
86 
87  marker_.pose.position.x = origin_.position.x = x;
88  marker_.pose.position.y = origin_.position.y = y;
89  marker_.pose.position.z = origin_.position.z = z;
90  marker_.pose.orientation.x = origin_.orientation.x = quat_x;
91  marker_.pose.orientation.y = origin_.orientation.y = quat_y;
92  marker_.pose.orientation.z = origin_.orientation.z = quat_z;
93  marker_.pose.orientation.w = origin_.orientation.w = quat_w;
94 
95  marker_.color.r = color_r;
96  marker_.color.g = color_g;
97  marker_.color.b = color_b;
98  marker_.color.a = color_a;
99 
100  marker_.scale.x = 1.0;
101  marker_.scale.y = 1.0;
102  marker_.scale.z = 1.0;
103  marker_.type = visualization_msgs::Marker::MESH_RESOURCE;
104 
105  marker_.header.frame_id = root_frame;
106  marker_.header.stamp = ros::Time::now();
108  marker_.action = visualization_msgs::Marker::ADD;
110  marker_.mesh_resource = mesh_resource;
111  marker_.mesh_use_embedded_materials = true;
112 
113  marker_.lifetime = ros::Duration();
114 }
115 
116 
117 inline geometry_msgs::Pose MarkerShape<BVH_RSS_t>::getMarkerPose() const
118 {
119  return this->marker_.pose;
120 }
121 
122 
123 inline geometry_msgs::Pose MarkerShape<BVH_RSS_t>::getOriginRelToFrame() const
124 {
125  return this->origin_;
126 }
127 
128 
129 inline uint32_t MarkerShape<BVH_RSS_t>::getId() const
130 {
131  return this->marker_.id;
132 }
133 
134 
135 inline void MarkerShape<BVH_RSS_t>::setColor(double color_r, double color_g, double color_b, double color_a)
136 {
137  marker_.color.r = color_r;
138  marker_.color.g = color_g;
139  marker_.color.b = color_b;
140  marker_.color.a = color_a;
141 }
142 
143 
144 inline void MarkerShape<BVH_RSS_t>::updatePose(const geometry_msgs::Vector3& pos, const geometry_msgs::Quaternion& quat)
145 {
146  marker_.pose.position.x = pos.x;
147  marker_.pose.position.y = pos.y;
148  marker_.pose.position.z = pos.z;
149  marker_.pose.orientation = quat;
150 }
151 
152 
153 inline void MarkerShape<BVH_RSS_t>::updatePose(const geometry_msgs::Pose& pose)
154 {
155  marker_.pose = pose;
156 }
157 
158 
159 inline visualization_msgs::Marker MarkerShape<BVH_RSS_t>::getMarker()
160 {
161  this->marker_.header.stamp = ros::Time::now();
162  return this->marker_;
163 }
164 
165 
166 fcl::CollisionObject MarkerShape<BVH_RSS_t>::getCollisionObject() const
167 {
168  fcl::Transform3f x(fcl::Quaternion3f(this->marker_.pose.orientation.w,
169  this->marker_.pose.orientation.x,
170  this->marker_.pose.orientation.y,
171  this->marker_.pose.orientation.z),
172  fcl::Vec3f(this->marker_.pose.position.x,
173  this->marker_.pose.position.y,
174  this->marker_.pose.position.z));
175 
176  fcl::CollisionObject cobj(this->ptr_fcl_bvh_, x);
177  return cobj;
178 }
179 
180 /* END MarkerShape **********************************************************************************************/
visualization_msgs::Marker marker_
geometry_msgs::Pose getMarkerPose() const
void init(const std::string &root_frame, double x, double y, double z, double quat_x, double quat_y, double quat_z, double quat_w, double color_r, double color_g, double color_b, double color_a)
int8_t createBVH(fcl::BVHModel< T > &bvh)
Definition: parser_base.hpp:79
fcl::BVHModel< fcl::RSS > BVH_RSS_t
void updatePose(const geometry_msgs::Vector3 &pos, const geometry_msgs::Quaternion &quat)
visualization_msgs::Marker getMarker()
static const std::string g_marker_namespace
std::shared_ptr< BVH_RSS_t > ptr_fcl_bvh_
void setColor(double color_r, double color_g, double color_b, double color_a=1.0)
static uint32_t class_ctr_
geometry_msgs::Pose origin_
fcl::CollisionObject getCollisionObject() const
MarkerShape(const std::string &root_frame, T &fcl_object, const geometry_msgs::Pose &pose, const std_msgs::ColorRGBA &col)
static Time now()
geometry_msgs::Pose getOriginRelToFrame() const
#define ROS_ERROR(...)
uint32_t getId() const


cob_obstacle_distance
Author(s): Marco Bezzon
autogenerated on Thu Apr 8 2021 02:39:47