6 #include <ram_display/DeleteTrajectory.h> 7 #include <ram_display/DisplayTrajectory.h> 8 #include <ram_display/UpdateMeshColor.h> 9 #include <ram_display/UpdateSelection.h> 10 #include <ram_msgs/AdditiveManufacturingTrajectory.h> 11 #include <ram_utils/GetTool.h> 14 #include <std_msgs/ColorRGBA.h> 42 size_t last_index = full_path.find_last_of(
"/");
43 std::string file_name = full_path.substr(last_index + 1, full_path.size());
45 last_index = file_name.find_last_of(
"\\");
46 file_name = file_name.substr(last_index + 1, file_name.size());
48 last_index = file_name.find_last_of(
".");
49 if (last_index == std::string::npos)
52 return file_name.substr(last_index + 1, file_name.size());
57 std_msgs::ColorRGBA rvalue;
212 const double tolerance)
215 Eigen::Vector3d current_p(Eigen::Vector3d::Identity());
217 for (
unsigned i(0); i < pose_index; ++i)
220 Eigen::Vector3d p(Eigen::Vector3d::Identity());
223 if ((current_p - p).norm() < tolerance)
232 const std::vector<std_msgs::ColorRGBA> &
colors,
235 if (a_points.size() != b_points.size())
237 ROS_ERROR_STREAM(
"Skipping path because " << a_points.size() <<
" different from " << b_points.size());
241 if (a_points.size() != colors.size())
243 ROS_ERROR_STREAM(
"Skipping path because " << a_points.size() <<
" different from " << colors.size());
248 for (
unsigned i(0); i < a_points.size(); ++i)
249 rvt_trajectory->publishCylinder(a_points[i], b_points[i], colors[i], radius,
"Cylinders");
255 const std::string frame_id =
"base",
256 const std::string mesh_file_name =
"")
258 visualization_msgs::Marker mesh_marker;
259 mesh_marker.pose.orientation.w = 1;
261 if (mesh_file_name.empty())
263 mesh_marker.header.frame_id = frame_id;
265 mesh_marker.ns =
"mesh";
267 mesh_marker.type = visualization_msgs::Marker::MESH_RESOURCE;
268 mesh_marker.action = visualization_msgs::Marker::DELETE;
272 mesh_marker.header.frame_id = frame_id;
274 mesh_marker.ns =
"mesh";
276 mesh_marker.type = visualization_msgs::Marker::MESH_RESOURCE;
277 mesh_marker.action = visualization_msgs::Marker::ADD;
278 mesh_marker.pose.position.x = 0;
279 mesh_marker.pose.position.y = 0;
280 mesh_marker.pose.position.z = 0;
281 mesh_marker.scale.x = 1;
282 mesh_marker.scale.y = 1;
283 mesh_marker.scale.z = 1;
284 mesh_marker.color = color;
285 mesh_marker.mesh_resource =
"file:///" + mesh_file_name;
286 mesh_marker.frame_locked =
true;
296 std_msgs::ColorRGBA color;
309 return "Trajectory is empty";
313 return "color_mode must be between 0 and 3. color_mode = " + std::to_string(
display_params.color_mode);
316 return "display_mode must be between 0 and 3. display_mode = " + std::to_string(
display_params.display_mode);
319 return "wire_size cannot be zero/negative. wire_size = " + std::to_string(
display_params.wire_size);
322 return "cylinder_size cannot be zero/negative. cylinder_size = " + std::to_string(
display_params.cylinder_size);
325 return "axis_size cannot be zero/negative. axis_size = " + std::to_string(
display_params.axis_size);
328 return "labels_size cannot be zero/negative. labels_size = " + std::to_string(
display_params.labels_size);
333 return "first_layer must be less than last_layer";
335 unsigned highest_level(
additive_traj.poses.front().layer_level);
338 if (ram_pose.layer_level > highest_level)
339 highest_level = ram_pose.layer_level;
343 return "Cannot display this range of layers, last layer do not exist in the trajectory.\n" 344 "Try with a lower \"Last layer\" value.";
350 if (!strcasecmp(file_extension.c_str(),
"yaml") || !strcasecmp(file_extension.c_str(),
"yml"))
352 std_msgs::ColorRGBA color;
355 else if (!strcasecmp(file_extension.c_str(),
"obj") ||
356 !strcasecmp(file_extension.c_str(),
"ply") ||
357 !strcasecmp(file_extension.c_str(),
"stl"))
364 std::vector<std_msgs::ColorRGBA> colors_vector;
365 std::map<double, std_msgs::ColorRGBA> color_map;
372 unsigned maximum_level(0);
374 if (pose.layer_level > maximum_level)
375 maximum_level = pose.layer_level;
377 std::vector<unsigned> pose_index_within_layer_count(maximum_level + 1);
378 std::fill(pose_index_within_layer_count.begin(), pose_index_within_layer_count.end(), 0);
383 Eigen::Affine3d pose_affine(Eigen::Affine3d::Identity());
384 Eigen::Affine3d previous_pose_affine(Eigen::Affine3d::Identity());
385 unsigned previous_i(0);
392 previous_pose_affine = pose_affine;
394 path.push_back(pose_affine);
395 path_positions.push_back(pose_affine.translation());
398 if (i != 0 && previous_i + 1 == i)
400 b_points.push_back(pose_affine.translation());
401 a_points.push_back(previous_pose_affine.translation());
418 if (color_map.find(
additive_traj.poses[i].params.speed) == color_map.end())
420 colors_vector.push_back(color_map[
additive_traj.poses[i].params.speed]);
442 double z_text_offset = 1e-4;
448 Eigen::Affine3d upper_pose(pose_affine);
449 upper_pose.translate(Eigen::Vector3d(0, 0, z_text_offset));
452 double label_tol = (0.5e-3);
456 label_color = rviz_visual_tools::colors::DARK_GREY;
457 upper_pose.translate(Eigen::Vector3d(0, 0, label_tol / 2.0));
460 geometry_msgs::Vector3 scale_vector;
468 rvt_trajectory->publishText(upper_pose, std::string(std::to_string(i)), label_color, scale_vector,
false);
475 scale_vector,
false);
482 scale_vector,
false);
488 std::string(std::to_string(pose_index_within_layer_count[
additive_traj.poses[i].layer_level]++)),
489 label_color, scale_vector,
false);
497 return "Cannot get tool, service does not exist";
500 ram_utils::GetTool srv;
501 if (!get_tool_client.
call(srv))
502 return "Cannot get tool, call to service failed";
504 Eigen::Affine3d
tool;
506 for (
auto &pose : path)
513 std::vector<geometry_msgs::Point> a_points_geom, b_points_geom;
514 for (Eigen::Vector3d point : a_points)
516 geometry_msgs::Point p;
520 a_points_geom.push_back(p);
522 for (Eigen::Vector3d point : b_points)
524 geometry_msgs::Point p;
528 b_points_geom.push_back(p);
531 geometry_msgs::Vector3 scale_vector;
536 rvt_trajectory->publishLines(a_points_geom, b_points_geom, colors_vector, scale_vector);
566 ram_display::DisplayTrajectory::Response &res)
575 ram_display::DeleteTrajectory::Response &)
592 std_msgs::ColorRGBA color;
601 geometry_msgs::Vector3 size;
616 for (
auto ram_pose :
selection.selected_poses)
618 geometry_msgs::Pose geometry_pose;
619 geometry_pose.position = ram_pose.pose.position;
620 geometry_pose.orientation.w = 1;
629 ram_display::UpdateSelection::Response &)
638 ram_display::UpdateMeshColor::Response &)
656 std::string trajectory_marker_topic, selection_marker_topic;
657 nh.
param<std::string>(
"ram/display/trajectory_marker_topic", trajectory_marker_topic,
"/rvt_trajectory");
658 nh.
param<std::string>(
"ram/display/selection_marker_topic", selection_marker_topic,
"/rvt_selection");
659 get_tool_client = nh.
serviceClient<ram_utils::GetTool>(
"ram/get_tool");
672 mesh_pub = nh.
advertise<visualization_msgs::Marker>(
"ram/display/mesh", 1,
true);
683 rvt_selection->enableFrameLocking();
687 rvt_selection->loadMarkerPub(
false,
true);
ServiceClient serviceClient(const std::string &service_name, bool persistent=false, const M_string &header_values=M_string())
std::string trajectory_frame
std::recursive_mutex trajectory_mutex
ros::ServiceClient get_tool_client
bool updateMeshColorCallback(ram_display::UpdateMeshColor::Request &req, ram_display::UpdateMeshColor::Response &)
void trajectoryCallback(const ram_msgs::AdditiveManufacturingTrajectory::ConstPtr &msg)
std::string fileExtension(const std::string full_path)
std::recursive_mutex selection_params_mutex
void publish(const boost::shared_ptr< M > &message) const
std::vector< Eigen::Affine3d, Eigen::aligned_allocator< Eigen::Affine3d > > vector_Affine3d
std::vector< Eigen::Vector3d, Eigen::aligned_allocator< Eigen::Vector3d > > vector_Vector3d
Subscriber subscribe(const std::string &topic, uint32_t queue_size, void(T::*fp)(M), T *obj, const TransportHints &transport_hints=TransportHints())
ram_msgs::AdditiveManufacturingTrajectory additive_traj
void poseMsgToEigen(const geometry_msgs::Pose &m, Eigen::Affine3d &e)
std::unique_ptr< ros::NodeHandle > nh
ROSCPP_DECL void init(int &argc, char **argv, const std::string &name, uint32_t options=0)
bool call(MReq &req, MRes &res)
ServiceServer advertiseService(const std::string &service, bool(T::*srv_func)(MReq &, MRes &), T *obj)
bool closeToPose(const unsigned pose_index, const double tolerance)
bool displayTrajectoryCallback(ram_display::DisplayTrajectory::Request &req, ram_display::DisplayTrajectory::Response &res)
bool waitForExistence(ros::Duration timeout=ros::Duration(-1))
bool param(const std::string ¶m_name, T ¶m_val, const T &default_val) const
bool publishCylinders(const EigenSTL::vector_Vector3d &a_points, const EigenSTL::vector_Vector3d &b_points, const std::vector< std_msgs::ColorRGBA > &colors, double radius)
void pointMsgToEigen(const geometry_msgs::Point &m, Eigen::Vector3d &e)
bool deleteTrajectoryCallback(ram_display::DeleteTrajectory::Request &, ram_display::DeleteTrajectory::Response &)
Publisher advertise(const std::string &topic, uint32_t queue_size, bool latch=false)
std::recursive_mutex display_params_mutex
std_msgs::ColorRGBA intToColor(const unsigned int color)
bool updateSelection(bool display=true)
uint32_t getNumSubscribers() const
bool updateSelectionCallback(ram_display::UpdateSelection::Request &req, ram_display::UpdateSelection::Response &)
ram_display::DisplayTrajectory::Request display_params
void displayMesh(const std_msgs::ColorRGBA color, const std::string frame_id="base", const std::string mesh_file_name="")
rviz_visual_tools::RvizVisualToolsPtr rvt_trajectory
std::string getTopic() const
int main(int argc, char **argv)
#define ROS_ERROR_STREAM(args)
std::string displayTrajectory()
ram_display::UpdateSelection::Request selection
ROSCPP_DECL void waitForShutdown()
rviz_visual_tools::RvizVisualToolsPtr rvt_selection