Go to the documentation of this file.
56 #include <mesh_msgs/GetVertexColors.h>
57 #include <mesh_msgs/GetMaterials.h>
58 #include <mesh_msgs/GetGeometry.h>
59 #include <mesh_msgs/GetTexture.h>
60 #include <mesh_msgs/GetUUIDs.h>
76 "Geometry Topic",
"", QString::fromStdString(ros::message_traits::datatype<mesh_msgs::MeshGeometryStamped>()),
77 "Geometry topic to subscribe to.",
this, SLOT(
updateTopic()));
109 "Vertex Colors Topic",
"",
110 QString::fromStdString(ros::message_traits::datatype<mesh_msgs::MeshVertexColorsStamped>()),
114 "Name of the Vertex Color Service to request Vertex Colors "
125 "Name of the Matrial Service to request Materials from.",
129 "Name of the Texture Service to request Textures from.",
136 "Select color scale for vertex costs. Mesh will update when new data "
143 "Vertex Costs Topic",
"",
144 QString::fromStdString(ros::message_traits::datatype<mesh_msgs::MeshVertexCostsStamped>()),
148 "Select the type of vertex cost map to be displayed. New types "
149 "will appear here when a new message arrives.",
340 visual->setGeometry(*geometry);
355 visual->setVertexColors(vertexColors);
377 visual->setNormals(vertexNormals);
390 visual->setMaterials(materials, texCoords);
400 visual->addTexture(texture, textureIndex);
409 visual->setFramePosition(position);
410 visual->setFrameOrientation(orientation);
429 bool showFaces =
false;
430 bool showTextures =
false;
431 bool showVertexColors =
false;
432 bool showVertexCosts =
false;
472 showVertexColors =
true;
491 showVertexCosts =
true;
512 ROS_ERROR(
"Mesh display: no visual available, can't draw mesh! (maybe no data has been received yet?)");
702 mesh_msgs::GetUUIDs srv_uuids;
705 std::vector<std::string> uuids = srv_uuids.response.uuids;
707 if (uuids.size() > 0)
709 std::string uuid = uuids[0];
715 mesh_msgs::GetGeometry srv_geometry;
716 srv_geometry.request.uuid = uuid;
720 mesh_msgs::MeshGeometryStamped::ConstPtr geometry =
721 boost::make_shared<const mesh_msgs::MeshGeometryStamped>(srv_geometry.response.mesh_geometry_stamped);
726 ROS_INFO_STREAM(
"Could not load geometry. Waiting for callback to trigger ... ");
732 ROS_INFO(
"No initial data available, waiting for callback to trigger ...");
743 Ogre::Quaternion orientation;
744 Ogre::Vector3 position;
749 ROS_ERROR(
"Error transforming from frame '%s' to frame '%s'", meshMsg->header.frame_id.c_str(),
756 ROS_WARN(
"Received geometry with new UUID!");
765 std::shared_ptr<Geometry>
mesh(std::make_shared<Geometry>());
766 for (
const geometry_msgs::Point& v : meshMsg->mesh_geometry.vertices)
772 mesh->vertices.push_back(vertex);
774 for (
const mesh_msgs::MeshTriangleIndices&
f : meshMsg->mesh_geometry.faces)
780 mesh->faces.push_back(face);
783 setPose(position, orientation);
786 std::vector<Normal> normals;
787 for (
const geometry_msgs::Point& n : meshMsg->mesh_geometry.vertex_normals)
789 Normal normal(n.x, n.y, n.z);
790 normals.push_back(normal);
807 if (colorsStamped->uuid.compare(
m_lastUuid) != 0)
809 ROS_ERROR(
"Received vertex colors, but UUIDs dont match!");
813 std::vector<Color> vertexColors;
814 for (
const std_msgs::ColorRGBA c : colorsStamped->mesh_vertex_colors.vertex_colors)
816 Color color(c.r, c.g, c.b, c.a);
817 vertexColors.push_back(color);
825 if (costsStamped->uuid.compare(
m_lastUuid) != 0)
827 ROS_ERROR(
"Received vertex costs, but UUIDs dont match!");
831 cacheVertexCosts(costsStamped->type, costsStamped->mesh_vertex_costs.costs);
842 mesh_msgs::GetVertexColors srv;
843 srv.request.uuid = uuid;
846 ROS_INFO(
"Successful vertex colors service call!");
847 mesh_msgs::MeshVertexColorsStamped::ConstPtr meshVertexColors =
848 boost::make_shared<const mesh_msgs::MeshVertexColorsStamped>(srv.response.mesh_vertex_colors_stamped);
850 std::vector<Color> vertexColors;
851 for (
const std_msgs::ColorRGBA c : meshVertexColors->mesh_vertex_colors.vertex_colors)
853 Color color(c.r, c.g, c.b, c.a);
854 vertexColors.push_back(color);
861 ROS_INFO(
"Failed vertex colors service call!");
872 mesh_msgs::GetMaterials srv;
873 srv.request.uuid = uuid;
876 ROS_INFO(
"Successful materials service call!");
878 mesh_msgs::MeshMaterialsStamped::ConstPtr meshMaterialsStamped =
879 boost::make_shared<const mesh_msgs::MeshMaterialsStamped>(srv.response.mesh_materials_stamped);
881 std::vector<Material> materials(meshMaterialsStamped->mesh_materials.materials.size());
882 for (
int i = 0; i < meshMaterialsStamped->mesh_materials.materials.size(); i++)
884 const mesh_msgs::MeshMaterial& mat = meshMaterialsStamped->mesh_materials.materials[i];
885 materials[i].textureIndex = mat.texture_index;
886 materials[i].color =
Color(mat.color.r, mat.color.g, mat.color.b, mat.color.a);
888 for (
int i = 0; i < meshMaterialsStamped->mesh_materials.clusters.size(); i++)
890 const mesh_msgs::MeshFaceCluster& clu = meshMaterialsStamped->mesh_materials.clusters[i];
892 uint32_t materialIndex = meshMaterialsStamped->mesh_materials.cluster_materials[i];
893 const mesh_msgs::MeshMaterial& mat = meshMaterialsStamped->mesh_materials.materials[materialIndex];
895 for (uint32_t face_index : clu.face_indices)
897 materials[i].faceIndices.push_back(face_index);
901 std::vector<TexCoords> textureCoords;
902 for (
const mesh_msgs::MeshVertexTexCoords& coord : meshMaterialsStamped->mesh_materials.vertex_tex_coords)
904 textureCoords.push_back(
TexCoords(coord.u, coord.v));
909 for (mesh_msgs::MeshMaterial material : meshMaterialsStamped->mesh_materials.materials)
911 if (material.has_texture)
913 mesh_msgs::GetTexture texSrv;
914 texSrv.request.uuid = uuid;
915 texSrv.request.texture_index = material.texture_index;
918 ROS_INFO(
"Successful texture service call with index %d!", material.texture_index);
919 mesh_msgs::MeshTexture::ConstPtr textureMsg =
920 boost::make_shared<const mesh_msgs::MeshTexture>(texSrv.response.texture);
923 texture.
width = textureMsg->image.width;
924 texture.
height = textureMsg->image.height;
925 texture.
channels = textureMsg->image.step;
927 texture.
data = textureMsg->image.data;
929 addTexture(texture, textureMsg->texture_index);
933 ROS_INFO(
"Failed texture service call with index %d!", material.texture_index);
940 ROS_INFO(
"Failed materials service call!");
952 ROS_INFO_STREAM(
"The cost layer \"" << layer <<
"\" has been updated.");
961 m_costCache.insert(std::pair<std::string, std::vector<float>>(layer, costs));
975 int randomId = (int)((
double)rand() / RAND_MAX * 9998);
std::map< std::string, std::vector< float > > m_costCache
Cache for received vertex cost messages.
rviz::FloatProperty * m_costLowerLimit
Property for setting the lower limit of cost display.
virtual bool getBool() const
ros::ServiceClient m_materialsClient
Client to request the materials.
virtual int getOptionInt()
ros::ServiceClient m_geometryClient
Client to request the geometry.
void updateVertexColorService()
Updates the vertex color service.
void processMessage(const mesh_msgs::MeshGeometryStamped::ConstPtr &meshMsg)
Sets data for trianglemesh_visual and updates the mesh.
rviz::ColorProperty * m_facesColor
Property to set faces color.
virtual void clearOptions()
void addTexture(Texture &texture, uint32_t textureIndex)
Add a texture.
Struct for texture coordinates.
void updateVertexColorsTopic()
Updates the subscribed vertex colors topic.
virtual void queueRender()=0
void setVertexColors(vector< Color > &vertexColors)
Set the vertex colors.
void addVertexCosts(std::string costlayer, vector< float > &vertexCosts)
Adds a vertex costlayer.
void initialServiceCall()
initial service call for UUID & geometry
rviz::RosTopicProperty * m_meshTopic
Property to handle topic for meshMsg.
tf2_ros::MessageFilter< mesh_msgs::MeshGeometryStamped > * m_tfMeshFilter
Messagefilter for meshMsg.
std::shared_ptr< MeshVisual > addNewVisual()
adds a new visual to the ring buffer
rviz::StringProperty * m_materialServiceName
Property to handle service name for materials.
rviz::RosTopicProperty * m_vertexCostsTopic
Property to handle topic for vertex cost maps.
void setGeometry(shared_ptr< Geometry > geometry)
Set the geometry.
MeshDisplay()
Constructor.
~MeshDisplay()
Destructor.
message_filters::Subscriber< mesh_msgs::MeshVertexColorsStamped > m_vertexColorsSubscriber
Subscriber for vertex colors.
void setVertexNormals(vector< Normal > &vertexNormals)
Set the vertex normals.
ServiceClient serviceClient(const std::string &service_name, bool persistent=false, const M_string &header_values=M_string())
virtual int numChildren() const
void updateVertexCostsTopic()
Updates the subscribed vertex costs topic.
ROSCPP_DECL bool validate(const std::string &name, std::string &error)
void updateMaterialAndTextureServices()
Updates the material and texture services.
rviz::FloatProperty * m_normalsAlpha
Property to set the transparency of the normals.
void updateMesh()
Updates the mesh.
void incomingGeometry(const mesh_msgs::MeshGeometryStamped::ConstPtr &meshMsg)
Handler for incoming geometry messages. Validate data and update mesh.
virtual void setStatus(StatusProperty::Level level, const QString &name, const QString &text)
rviz::StringProperty * m_vertexColorServiceName
Property to handle service name for vertexColors.
ros::ServiceClient m_vertexColorClient
Client to request the vertex colors.
#define PLUGINLIB_EXPORT_CLASS(class_type, base_class_type)
rviz::EnumProperty * m_costColorType
Property for selecting the color type for cost display.
virtual float getFloat() const
virtual void addOption(const QString &option, int value=0)
void clearVertexCosts()
Clears the vertex costs.
std::queue< std::shared_ptr< MeshVisual > > m_visuals
Visual data.
rviz::FloatProperty * m_wireframeAlpha
Property to set wireframe transparency.
void updateNormalsSize()
Update the size of the mesh normals.
std::string getStdString()
void swap(T *&arr, size_t i1, size_t i2, size_t n)
void onEnable()
RViz callback on enable.
void onInitialize()
RViz callback on initialize.
void updateWireframe()
Updates the mesh wireframe.
uint32_t m_messagesReceived
Counter for the received messages.
Connection registerCallback(const boost::function< void(P)> &callback)
message_filters::Subscriber< mesh_msgs::MeshVertexCostsStamped > m_vertexCostsSubscriber
Subscriber for vertex costs.
message_filters::Subscriber< mesh_msgs::MeshGeometryStamped > m_meshSubscriber
Subscriber for meshMsg.
rviz::StringProperty * m_textureServiceName
Property to handle service name for textures.
#define ROS_INFO_STREAM(args)
rviz::EnumProperty * m_selectVertexCostMap
Property to select different types of vertex cost maps to be shown.
rviz::FloatProperty * m_facesAlpha
Property to set faces transparency.
virtual FrameManager * getFrameManager() const=0
void setPose(Ogre::Vector3 &position, Ogre::Quaternion &orientation)
Set geometrys pose.
std::string getTopicStd() const
void updateNormalsColor()
Update the color of the mesh normals.
void unsubscribe()
Unsubscribes all topics.
void setMaterials(vector< Material > &materials, vector< TexCoords > &texCoords)
Set the materials and texture coordinates.
void addOptionStd(const std::string &option, int value=0)
void updateTopic()
Updates the subscribed topic.
rviz::BoolProperty * m_costUseCustomLimits
Property for using custom limits for cost display.
bool getTransform(const Header &header, Ogre::Vector3 &position, Ogre::Quaternion &orientation)
DisplayContext * context_
tf2_ros::MessageFilter< mesh_msgs::MeshVertexColorsStamped > * m_tfVertexColorsFilter
Messagefilter for vertex colors.
Display for showing the mesh in different modes.
bool m_ignoreMsgs
if set to true, ignore incoming messages and do not use services to request materials
void registerFilterForTransformStatusCheck(tf2_ros::MessageFilter< M > *filter, Display *display)
ros::ServiceClient m_uuidClient
Client to request the UUID.
rviz::BoolProperty * m_showWireframe
Property to select the wireframe.
bool call(const MReq &req, MRes &resp, const std::string &service_md5sum)
KF_EXPORTS void error(const char *error_string, const char *file, const int line, const char *func="")
void requestMaterials(std::string uuid)
Requests materials from the specified service.
void requestVertexColors(std::string uuid)
Requests vertex colors from the specified service.
rviz::ColorProperty * m_wireframeColor
Property to set wireframe color.
virtual int getInt() const
ros::ServiceClient m_textureClient
Client to request the textures.
rviz::ColorProperty * m_normalsColor
Property to set the color of the normals.
message_filters::Cache< mesh_msgs::MeshVertexCostsStamped > * m_costsSynchronizer
Synchronizer for vertex costs.
void subscribe()
Set the topics to subscribe.
rviz::FloatProperty * m_scalingFactor
Property to set the size of the normals.
void updateVertexCosts()
Update the vertex costs.
message_filters::Cache< mesh_msgs::MeshVertexColorsStamped > * m_colorsSynchronizer
Synchronizer for vertex colors.
rviz::FloatProperty * m_costUpperLimit
Property for setting the upper limit of cost display.
rviz::IntProperty * m_bufferSize
Property to handle buffer size.
void incomingVertexColors(const mesh_msgs::MeshVertexColorsStamped::ConstPtr &colorsStamped)
Handler for incoming vertex color messages. Validate data and update mesh.
void updateNormals()
Update the mesh normals.
rviz::BoolProperty * m_showNormals
Property to select the normals.
std::string m_lastUuid
Uuid of the last received message.
rviz::EnumProperty * m_displayType
Property to select the display type.
void incomingVertexCosts(const mesh_msgs::MeshVertexCostsStamped::ConstPtr &costsStamped)
Handler for incoming vertex cost messages. Validate data and update mesh.
void updateBufferSize()
Updates the buffer size.
void ignoreIncomingMessages()
disables visualization of incoming messages
array< uint32_t, 3 > vertexIndices
std::shared_ptr< MeshVisual > getLatestVisual()
delivers the latest mesh visual
rviz::RosTopicProperty * m_vertexColorsTopic
Property to handle topic for vertex colors.
ros::NodeHandle update_nh_
tf2_ros::MessageFilter< mesh_msgs::MeshVertexCostsStamped > * m_tfVertexCostsFilter
Messagefilter for vertex costs.
Ogre::ColourValue getOgreColor() const
void onDisable()
RViz callback on disable.
void cacheVertexCosts(std::string layer, const std::vector< float > &costs)
Cache function for vertex cost messages.
message_filters::Cache< mesh_msgs::MeshGeometryStamped > * m_meshSynchronizer
Synchronizer for meshMsgs.
rviz::BoolProperty * m_showTexturedFacesOnly
Property to only show textured faces when texturizing is enabled.
rviz_map_plugin
Author(s): Sebastian Pütz
, Kristin Schmidt , Jan Philipp Vogtherr , Malte kleine Piening
autogenerated on Sun Jan 21 2024 04:06:25