11 #include <visualization_msgs/Marker.h> 14 #include <fanuc_grinding_publish_meshfile/PublishMeshfileService.h> 17 #include <pcl/point_cloud.h> 18 #include <pcl/io/ply_io.h> 19 #include <pcl/io/vtk_lib_io.h> 20 #include <pcl/PolygonMesh.h> 35 bool publishMeshFile(fanuc_grinding_publish_meshfile::PublishMeshfileService::Request &req,
36 fanuc_grinding_publish_meshfile::PublishMeshfileService::Response &res)
38 if (req.ColorA <= 0.1)
39 ROS_WARN_STREAM(
"publishMeshFile: Alpha is set to 0, mesh will be invisible!");
41 pcl::PolygonMesh mesh;
42 if (boost::filesystem::path (req.MeshName).extension () ==
".ply")
44 if (pcl::io::loadPLYFile(req.MeshName, mesh))
52 pcl::io::loadPolygonFile(req.MeshName, mesh);
55 visualization_msgs::Marker marker;
56 if(mesh.polygons.size() == 0)
58 ROS_WARN_STREAM(
"publishMeshFile: There is no polygon in file, publishing a point cloud");
59 *pub = node->advertise<sensor_msgs::PointCloud2>(req.MarkerName, 1,
true);
60 mesh.cloud.header.frame_id =
"base_link";
61 pub->publish(mesh.cloud);
65 *pub = node->advertise<visualization_msgs::Marker>(req.MarkerName, 1,
true);
67 marker.header.frame_id =
"base_link";
71 marker.type = visualization_msgs::Marker::MESH_RESOURCE;
72 marker.action = visualization_msgs::Marker::ADD;
73 marker.pose.position.x = req.PosX;
74 marker.pose.position.y = req.PosY;
75 marker.pose.position.z = req.PosZ;
76 marker.pose.orientation.x = req.RotX;
77 marker.pose.orientation.y = req.RotY;
78 marker.pose.orientation.z = req.RotZ;
79 marker.pose.orientation.w = req.RotW;
83 marker.color.a = req.ColorA;
84 marker.color.r = req.ColorR;
85 marker.color.g = req.ColorG;
86 marker.color.b = req.ColorB;
89 marker.mesh_resource =
"file://" + req.MeshName;
93 while (pub->getNumSubscribers() < 1)
95 ROS_WARN_STREAM(
"publishMeshFile: No subscriber to the marker: " + req.MarkerName);
96 if (!req.WaitForSubscriber)
101 res.ReturnStatus =
true;
102 res.ReturnMessage = req.MarkerName +
" published";
106 int main(
int argc,
char **argv)
108 ros::init(argc, argv,
"publish_meshfile");
int main(int argc, char **argv)
bool publishMeshFile(fanuc_grinding_publish_meshfile::PublishMeshfileService::Request &req, fanuc_grinding_publish_meshfile::PublishMeshfileService::Response &res)
boost::shared_ptr< ros::Publisher > pub
ROSCPP_DECL void init(int &argc, char **argv, const std::string &name, uint32_t options=0)
boost::shared_ptr< ros::NodeHandle > node
pcl::PointCloud< PointXYZ > PointCloudXYZ
#define ROS_WARN_STREAM(args)
#define ROS_ERROR_STREAM(args)