textured_mesh_visual.cpp
Go to the documentation of this file.
1 #include "textured_mesh_visual.h"
2 
3 #include <OGRE/OgreSubEntity.h>
4 #include <OGRE/OgreRenderOperation.h>
5 #include <OGRE/OgreTextureManager.h>
6 #include <OGRE/OgreHardwarePixelBuffer.h>
7 #include <OGRE/OgrePixelFormat.h>
8 
9 // #include <rviz/display_context.h>
10 // #include <rviz/frame_manager.h>
11 
12 #include <limits>
13 #include <stdint.h>
14 
15 
16 
17 namespace rviz_mesh_plugin
18 {
19 
20  Ogre::ColourValue getRainbowColor(float value)
21  {
22  float r = 0.0f;
23  float g = 0.0f;
24  float b = 0.0f;
25 
26  value = std::min(value, 1.0f);
27  value = std::max(value, 0.0f);
28 
29  float h = value * 5.0f + 1.0f;
30  int i = floor(h);
31  float f = h - i;
32  if ( !(i&1) ) f = 1 - f; // if i is even
33  float n = 1 - f;
34 
35  if (i <= 1) r = n, g = 0, b = 1;
36  else if (i == 2) r = 0, g = n, b = 1;
37  else if (i == 3) r = 0, g = 1, b = n;
38  else if (i == 4) r = n, g = 1, b = 0;
39  else if (i >= 5) r = 1, g = n, b = 0;
40 
41  return Ogre::ColourValue(r, g, b, 1.0f);
42  }
43 
45  rviz::DisplayContext* context,
46  size_t displayID,
47  size_t meshID,
48  size_t randomID)
49  : m_displayContext(context),
50  m_prefix(displayID),
51  m_postfix(meshID),
52  m_random(randomID),
53  m_vertex_normals_enabled(false),
54  m_vertex_colors_enabled(false),
55  m_materials_enabled(false),
56  m_texture_coords_enabled(false),
57  m_normalsScalingFactor(1)
58  {
59 
60  ROS_INFO("Creating TexturedMeshVisual %lu_TexturedMesh_%lu_%lu",m_prefix, m_postfix, m_random);
61 
62  // get or create the scene node
63  Ogre::SceneManager* sceneManager = m_displayContext->getSceneManager();
64  Ogre::SceneNode* rootNode = sceneManager->getRootSceneNode();
65 
66  std::stringstream strstream;
67  strstream << "TexturedMeshScene" << m_random;
68  std::string sceneId = strstream.str();
69  if (sceneManager->hasSceneNode(sceneId))
70  {
71  //ROS_INFO("Attaching to scene: %s", sceneId);
72  m_sceneNode = (Ogre::SceneNode*)(rootNode->getChild(sceneId));
73  }
74  else
75  {
76  //ROS_INFO("Creating new scene: %s", sceneId);
77  m_sceneNode = rootNode->createChildSceneNode(sceneId);
78  }
79 
80  // create manual objects and attach them to the scene node
81  std::stringstream sstm;
82  sstm << m_prefix << "_TriangleMesh_" << m_postfix << "_" << m_random;
83  m_mesh = sceneManager->createManualObject(sstm.str());
84  m_mesh->setDynamic(false);
85  m_sceneNode->attachObject(m_mesh);
86 
87  std::stringstream sstmNormals;
88  sstmNormals << m_prefix << "_Normals_" << m_postfix << "_" << m_random;
89  m_normals = sceneManager->createManualObject(sstmNormals.str());
90  m_normals->setDynamic(false);
91  m_sceneNode->attachObject(m_normals);
92 
93  std::stringstream sstmTexturedMesh;
94  sstmTexturedMesh << m_prefix << "_TexturedMesh_" << m_postfix << "_" << m_random;
95  m_texturedMesh = sceneManager->createManualObject(sstmTexturedMesh.str());
96  m_texturedMesh->setDynamic(false);
97  m_sceneNode->attachObject(m_texturedMesh);
98 
99  std::stringstream sstmNoTexCluMesh;
100  sstmNoTexCluMesh << m_prefix << "_NoTexCluMesh_" << m_postfix << "_" << m_random;
101  m_noTexCluMesh = sceneManager->createManualObject(sstmNoTexCluMesh.str());
102  m_noTexCluMesh->setDynamic(false);
103  m_sceneNode->attachObject(m_noTexCluMesh);
104 
105  std::stringstream sstmVertexCostsMesh;
106  sstmVertexCostsMesh << m_prefix << "_VertexCostsMesh_" << m_postfix << "_" << m_random;
107  m_vertexCostsMesh = sceneManager->createManualObject(sstmVertexCostsMesh.str());
108  m_vertexCostsMesh->setDynamic(false);
109  m_sceneNode->attachObject(m_vertexCostsMesh);
110  }
111 
113  {
114  ROS_INFO("Destroying TexturedMeshVisual %lu_TexturedMesh_%lu_%lu",m_prefix, m_postfix, m_random);
115 
116  reset();
117 
118  std::stringstream sstm;
119  sstm << m_prefix << "_TriangleMesh_" << m_postfix << "_" << m_random;
120  m_displayContext->getSceneManager()->destroyManualObject(sstm.str());
121 
122  std::stringstream sstmNormals;
123  sstmNormals << m_prefix << "_Normals_" << m_postfix << "_" << m_random;
124  m_displayContext->getSceneManager()->destroyManualObject(sstmNormals.str());
125 
126  std::stringstream sstmTexturedMesh;
127  sstmTexturedMesh << m_prefix << "_TexturedMesh_" << m_postfix << "_" << m_random;
128  m_displayContext->getSceneManager()->destroyManualObject(sstmTexturedMesh.str());
129 
130  std::stringstream sstmNoTexCluMesh;
131  sstmNoTexCluMesh << m_prefix << "_NoTexCluMesh_" << m_postfix << "_" << m_random;
132  m_displayContext->getSceneManager()->destroyManualObject(sstmNoTexCluMesh.str());
133 
134  std::stringstream sstmVertexCostsMesh;
135  sstmVertexCostsMesh << m_prefix << "_VertexCostsMesh_" << m_postfix << "_" << m_random;
136  m_displayContext->getSceneManager()->destroyManualObject(sstmVertexCostsMesh.str());
137 
138  m_displayContext->getSceneManager()->destroySceneNode(m_sceneNode);
139  sstm.str("");
140  sstm.flush();
141  }
142 
144  {
145 
146  ROS_INFO("Resetting TexturedMeshVisual %lu_TexturedMesh_%lu_%lu",m_prefix, m_postfix, m_random);
147 
148 
149  std::stringstream sstm;
150 
151  sstm << m_prefix << "_TexturedMesh_" << m_postfix << "_" << m_random << "GeneralMaterial_";
152  Ogre::MaterialManager::getSingleton().unload(sstm.str());
153  Ogre::MaterialManager::getSingleton().remove(sstm.str());
154  sstm.str("");
155  sstm.clear();
156 
158  {
159  sstm << m_prefix << "_TexturedMesh_" << m_postfix << "_" << m_random << "Material_" << 1;
160  Ogre::MaterialManager::getSingleton().unload(sstm.str());
161  Ogre::MaterialManager::getSingleton().remove(sstm.str());
162  sstm.str("");
163  sstm.clear();
164  }
165 
166  sstm << m_prefix << "_TexturedMesh_" << m_postfix << "_" << m_random << "NormalMaterial";
167  Ogre::MaterialManager::getSingleton().unload(sstm.str());
168  Ogre::MaterialManager::getSingleton().remove(sstm.str());
169  sstm.str("");
170  sstm.clear();
171 
172  for (Ogre::MaterialPtr textureMaterial : m_textureMaterials)
173  {
174  Ogre::MaterialManager::getSingleton().unload(textureMaterial->getName());
175  Ogre::MaterialManager::getSingleton().remove(textureMaterial->getName());
176  }
177 
178  if (!m_noTexCluMaterial.isNull())
179  {
180  Ogre::MaterialManager::getSingleton().unload(m_noTexCluMaterial->getName());
181  Ogre::MaterialManager::getSingleton().remove(m_noTexCluMaterial->getName());
182  }
183 
184  if (!m_vertexCostMaterial.isNull())
185  {
186  Ogre::MaterialManager::getSingleton().unload(m_vertexCostMaterial->getName());
187  Ogre::MaterialManager::getSingleton().remove(m_vertexCostMaterial->getName());
188  }
189 
190  m_mesh->clear();
191  m_normals->clear();
192  m_texturedMesh->clear();
193  m_noTexCluMesh->clear();
194  m_vertexCostsMesh->clear();
195  sstm.str("");
196  sstm.flush();
197 
198  m_meshGeneralMaterial.setNull();
199  m_normalMaterial.setNull();
200  m_noTexCluMaterial.setNull();
201  m_textureMaterials.clear();
202  m_vertexCostMaterial.setNull();
203 
204  m_images.clear();
205 
206  m_meshUuid = "";
207  m_vertexColorsUuid = "";
208  m_vertexCostsUuid = "";
209  m_materialsUuid = "";
210 
211  m_vertex_colors_enabled = false;
212  m_materials_enabled = false;
213  m_texture_coords_enabled = false;
214  m_textures_enabled = false;
215  m_vertex_costs_enabled = false;
216  }
217 
219  Ogre::Pass* pass,
220  Ogre::ColourValue wireframeColor,
221  float wireframeAlpha
222  )
223  {
224  pass->setAmbient(
225  Ogre::ColourValue(
226  wireframeColor.r,
227  wireframeColor.g,
228  wireframeColor.b,
229  wireframeAlpha
230  )
231  );
232  pass->setDiffuse(
233  Ogre::ColourValue(
234  wireframeColor.r,
235  wireframeColor.g,
236  wireframeColor.b,
237  wireframeAlpha
238  )
239  );
240 
241  if (wireframeAlpha < 1.0)
242  {
243  pass->setSceneBlending(Ogre::SBT_TRANSPARENT_ALPHA);
244  pass->setDepthWriteEnabled(true);
245  }
246  pass->setPolygonMode(Ogre::PM_WIREFRAME);
247  pass->setCullingMode(Ogre::CULL_NONE);
248  }
249 
251  Ogre::Pass* pass,
252  Ogre::ColourValue facesColor,
253  float facesAlpha,
254  bool useVertexColors
255  )
256  {
257 
258  pass->setDiffuse(
259  Ogre::ColourValue(
260  facesColor.r,
261  facesColor.g,
262  facesColor.b,
263  facesAlpha
264  )
265  );
266  pass->setSelfIllumination(facesColor.r, facesColor.g, facesColor.b);
267 
268 
269  if (useVertexColors)
270  {
271  pass->setLightingEnabled(false);
272  pass->setDepthWriteEnabled(true);
273  }
274  else if (facesAlpha < 1.0)
275  {
276  pass->setSceneBlending(Ogre::SBT_TRANSPARENT_ALPHA);
277  pass->setDepthWriteEnabled(false);
278  }
279  pass->setPolygonMode(Ogre::PM_SOLID);
280  pass->setCullingMode(Ogre::CULL_NONE);
281  }
282 
284  Ogre::Pass* pass,
285  Ogre::ColourValue normalsColor,
286  float normalsAlpha
287  )
288  {
289 
290  pass->setSelfIllumination(normalsColor.r, normalsColor.g, normalsColor.b);
291  pass->setDiffuse(
292  Ogre::ColourValue(
293  normalsColor.r,
294  normalsColor.g,
295  normalsColor.b,
296  normalsAlpha
297  )
298  );
299  if (normalsAlpha < 1.0)
300  {
301  pass->setSceneBlending(Ogre::SBT_TRANSPARENT_ALPHA);
302  pass->setDepthWriteEnabled(true);
303  }
304  pass->setPolygonMode(Ogre::PM_SOLID);
305  pass->setCullingMode(Ogre::CULL_NONE);
306  }
307 
309  bool showWireframe,
310  Ogre::ColourValue wireframeColor,
311  float wireframeAlpha,
312  bool showFaces,
313  Ogre::ColourValue facesColor,
314  float facesAlpha,
315  bool useVertexColors,
316  bool showVertexCosts,
317  bool showTextures,
318  bool showTexturedFacesOnly,
319  bool showNormals,
320  Ogre::ColourValue normalsColor,
321  float normalsAlpha,
322  float normalsScalingFactor
323  )
324  {
325  // remove all passes
326  if (!m_meshGeneralMaterial.isNull())
327  {
328  m_meshGeneralMaterial->getTechnique(0)->removeAllPasses();
329  }
330 
331  if (!m_normalMaterial.isNull())
332  {
333  m_normalMaterial->getTechnique(0)->removeAllPasses();
334  }
335 
336  m_texturedMesh->setVisible(false);
337  m_noTexCluMesh->setVisible(false);
338  m_vertexCostsMesh->setVisible(false);
339 
340  // if the material exists and the textures are not enabled
341  // we can use the general mesh with the m_meshGeneralMaterial
342  if (!m_meshGeneralMaterial.isNull() && !showTextures && !showVertexCosts)
343  {
344  Ogre::Technique* tech = m_meshGeneralMaterial->getTechnique(0);
345 
346  if (showFaces)
347  {
348  this->showFaces(tech->createPass(), facesColor, facesAlpha, useVertexColors);
349  }
350  }
351 
352  // if there are vertex costs and the vertex cost are enabled
353  // the mesh with the colors calculated from vertex costs is made visible
354  if (m_vertex_costs_enabled && showVertexCosts)
355  {
356  m_vertexCostsMesh->setVisible(true);
357  }
358 
359  // if there are materials or textures the mesh with texture coordinates that
360  // uses the material and texture materials is made visible
362  {
363  m_texturedMesh->setVisible(true);
364  m_noTexCluMesh->setVisible(!showTexturedFacesOnly); // TODO: dynamisch
365  }
366 
367  if (showWireframe)
368  {
369  Ogre::Technique* tech = m_meshGeneralMaterial->getTechnique(0);
370  this->showWireframe(tech->createPass(), wireframeColor, wireframeAlpha);
371  }
372 
373  if (!m_normalMaterial.isNull())
374  {
375  if (showNormals)
376  {
377  Ogre::Technique* tech = m_normalMaterial->getTechnique(0);
378  this->showNormals(tech->createPass(), normalsColor, normalsAlpha);
379  updateNormals(normalsScalingFactor);
380  }
381  }
382  }
383 
384 void TexturedMeshVisual::updateNormals(float ScalingFactor)
385 {
386  Ogre::VertexData* vertexData;
387  const Ogre::VertexElement* vertexElement;
388  Ogre::HardwareVertexBufferSharedPtr vertexBuffer;
389  unsigned char* vertexChar;
390  float* vertexFloat;
391 
392  vertexData = m_normals->getSection(0)->getRenderOperation()->vertexData;
393  vertexElement = vertexData->vertexDeclaration->findElementBySemantic(Ogre::VES_POSITION);
394  vertexBuffer = vertexData->vertexBufferBinding->getBuffer(vertexElement->getSource());
395  vertexChar = static_cast<unsigned char*>(vertexBuffer->lock(Ogre::HardwareBuffer::HBL_READ_ONLY));
396 
397  size_t halfVertexCount = vertexData->vertexCount / 2;
398  Ogre::Vector3* vertices = new Ogre::Vector3[halfVertexCount];
399  Ogre::Vector3* normals = new Ogre::Vector3[halfVertexCount];
400 
401  for (
402  size_t i = 0, vIndex = 0, nIndex = 0;
403  i < vertexData->vertexCount;
404  i++, vertexChar += vertexBuffer->getVertexSize()
405  )
406  {
407  vertexElement->baseVertexPointerToElement(vertexChar, &vertexFloat);
408  Ogre::Vector3 tempVector(vertexFloat[0], vertexFloat[1], vertexFloat[2]);
409 
410  if (i % 2 == 0)
411  {
412  vertices[vIndex] = tempVector;
413  vIndex++;
414  }
415  else
416  {
417  normals[nIndex] = (tempVector - vertices[nIndex]) / m_normalsScalingFactor;
418  nIndex++;
419  }
420  }
421  vertexBuffer->unlock();
422 
423  m_normals->beginUpdate(0);
424  for (size_t i = 0; i < halfVertexCount; i++)
425  {
426  m_normals->position(vertices[i].x, vertices[i].y, vertices[i].z);
427  m_normals->position(
428  vertices[i].x + ScalingFactor * normals[i].x,
429  vertices[i].y + ScalingFactor * normals[i].y,
430  vertices[i].z + ScalingFactor * normals[i].z
431  );
432  }
433  m_normals->end();
434  delete [] vertices;
435  delete [] normals;
436  m_normalsScalingFactor = ScalingFactor;
437 }
438 
439 void TexturedMeshVisual::enteringGeneralTriangleMesh(const mesh_msgs::MeshGeometry& mesh)
440 {
441  std::stringstream sstm;
442 
443  sstm << m_prefix << "_TexturedMesh_" << m_postfix << "_" << m_random << "GeneralMaterial_";
444 
446  Ogre::MaterialManager::getSingleton().create(
447  sstm.str(),
448  Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME,
449  true
450  );
451 
452  // start entering data
453  m_mesh->clear();
454  m_mesh->begin(sstm.str(), Ogre::RenderOperation::OT_TRIANGLE_LIST);
455 
456  // write vertices
457  // write vertex normals(if enabled)
458  for (size_t i = 0; i < mesh.vertices.size(); i++)
459  {
460  // write vertices
461  m_mesh->position(
462  mesh.vertices[i].x,
463  mesh.vertices[i].y,
464  mesh.vertices[i].z
465  );
466 
467  // write vertex normals, if enabled
469  {
470  m_mesh->normal(
471  mesh.vertex_normals[i].x,
472  mesh.vertex_normals[i].y,
473  mesh.vertex_normals[i].z
474  );
475  }
476  }
477 
478  // write triangles
479  for (size_t i = 0; i < mesh.faces.size(); i++)
480  {
481  m_mesh->triangle(
482  mesh.faces[i].vertex_indices[0],
483  mesh.faces[i].vertex_indices[1],
484  mesh.faces[i].vertex_indices[2]
485  );
486  }
487 
488  // finish entering data
489  m_mesh->end();
490 
491 }
492 
494  const mesh_msgs::MeshGeometry& mesh,
495  const mesh_msgs::MeshVertexColors& vertexColors)
496 {
497  if (m_meshGeneralMaterial.isNull())
498  {
499  std::stringstream sstm;
500  sstm << m_prefix << "_TexturedMesh_" << m_postfix << "_" << m_random << "GeneralMaterial_";
501 
503  Ogre::MaterialManager::getSingleton().create(
504  sstm.str(),
505  Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME,
506  true
507  );
508  }
509 
510  // start entering data
511  m_mesh->clear();
512  m_mesh->begin(m_meshGeneralMaterial->getName(), Ogre::RenderOperation::OT_TRIANGLE_LIST);
513 
514  // write vertices
515  // write vertex colors
516  // write vertex normals(if enabled)
517  for (size_t i = 0; i < mesh.vertices.size(); i++)
518  {
519  // write vertices
520  m_mesh->position(mesh.vertices[i].x, mesh.vertices[i].y, mesh.vertices[i].z);
521 
522  // write vertex colors
523  m_mesh->colour(
524  vertexColors.vertex_colors[i].r,
525  vertexColors.vertex_colors[i].g,
526  vertexColors.vertex_colors[i].b,
527  vertexColors.vertex_colors[i].a
528  );
529 
530  // write vertex normals, if enabled
532  {
533  m_mesh->normal(
534  mesh.vertex_normals[i].x,
535  mesh.vertex_normals[i].y,
536  mesh.vertex_normals[i].z
537  );
538  }
539  }
540 
541  // write triangles
542  for (size_t i = 0; i < mesh.faces.size(); i++)
543  {
544  m_mesh->triangle(
545  mesh.faces[i].vertex_indices[0],
546  mesh.faces[i].vertex_indices[1],
547  mesh.faces[i].vertex_indices[2]
548  );
549  }
550 
551  // finish entering data
552  m_mesh->end();
553 
554 }
555 
557  const mesh_msgs::MeshGeometry& mesh,
558  const mesh_msgs::MeshVertexCosts& vertexCosts,
559  int costColorType
560 )
561 {
562 
563  // Calculate maximum value for vertex costs
564  float maxCost = std::numeric_limits<float>::min();
565  float minCost = std::numeric_limits<float>::max();
566  for (float cost : vertexCosts.costs)
567  {
568  if(std::isfinite(cost) && cost > maxCost) maxCost = cost;
569  if(std::isfinite(cost) && cost < minCost) minCost = cost;
570  }
571 
572  enteringTriangleMeshWithVertexCosts(mesh, vertexCosts, costColorType, minCost, maxCost);
573 }
574 
576  const mesh_msgs::MeshGeometry& mesh,
577  const mesh_msgs::MeshVertexCosts& vertexCosts,
578  int costColorType,
579  float minCost,
580  float maxCost
581 )
582 {
583  float range = maxCost - minCost;
584  if (range <= 0)
585  {
586  ROS_ERROR("Illegal vertex cost limits!");
587  return;
588  }
589 
590  if (m_vertexCostMaterial.isNull())
591  {
592  std::stringstream sstm;
593  sstm << m_prefix << "_TexturedMesh_" << m_postfix << "_" << m_random << "VertexCostMaterial_";
594 
596  Ogre::MaterialManager::getSingleton().create(
597  sstm.str(),
598  Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME,
599  true
600  );
601 
602  Ogre::Pass* pass = m_vertexCostMaterial->getTechnique(0)->getPass(0);
603  pass->setCullingMode(Ogre::CULL_NONE);
604  pass->setLightingEnabled(false);
605 
606  // start entering data
607  m_vertexCostsMesh->clear();
608  m_vertexCostsMesh->begin(m_vertexCostMaterial->getName(), Ogre::RenderOperation::OT_TRIANGLE_LIST);
609  }
610  else
611  {
612  // start updating data
613  m_vertexCostsMesh->beginUpdate(0);
614  }
615 
616  // write vertices
617  // write vertex colors
618  // write vertex normals(if enabled)
619  for (size_t i = 0; i < mesh.vertices.size(); i++)
620  {
621  // write vertices
622  m_vertexCostsMesh->position(mesh.vertices[i].x, mesh.vertices[i].y, mesh.vertices[i].z);
623 
624  // write vertex colors that are calculated from the cost values
625  float normalizedCost = (vertexCosts.costs[i] - minCost) / range;
626  m_vertexCostsMesh->colour(calculateColorFromCost(normalizedCost, costColorType));
627 
628  // write vertex normals, if enabled
630  {
631  m_vertexCostsMesh->normal(
632  mesh.vertex_normals[i].x,
633  mesh.vertex_normals[i].y,
634  mesh.vertex_normals[i].z
635  );
636  }
637  }
638 
639  // write triangles
640  for (size_t i = 0; i < mesh.faces.size(); i++)
641  {
642  m_vertexCostsMesh->triangle(
643  mesh.faces[i].vertex_indices[0],
644  mesh.faces[i].vertex_indices[1],
645  mesh.faces[i].vertex_indices[2]
646  );
647  }
648 
649  // finish entering data
650  m_vertexCostsMesh->end();
651 
652 }
653 
655  const mesh_msgs::MeshGeometry& mesh,
656  const mesh_msgs::MeshMaterials& meshMaterials
657 )
658 {
659  size_t clusterCounter = meshMaterials.clusters.size();
660  size_t materialCounter = meshMaterials.materials.size();
661  size_t textureIndex = 0;
662 
663  std::stringstream sstm;
664  sstm << m_prefix << "_TexturedMesh_" << m_postfix << "_" << m_random << "NoTexCluMaterial_";
665  m_noTexCluMaterial = Ogre::MaterialManager::getSingleton().create(
666  sstm.str(),
667  Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME,
668  true
669  );
670 
671  Ogre::Pass* pass = m_noTexCluMaterial->getTechnique(0)->getPass(0);
672  pass->setCullingMode(Ogre::CULL_NONE);
673  pass->setLightingEnabled(false);
674 
675  // start entering data
676  m_noTexCluMesh->clear();
677  m_noTexCluMesh->begin(m_noTexCluMaterial->getName(), Ogre::RenderOperation::OT_TRIANGLE_LIST);
678 
679  size_t noTexCluVertexCount = 0;
680 
681  for (size_t clusterIndex = 0; clusterIndex < clusterCounter; clusterIndex++)
682  {
683 
684  mesh_msgs::MeshFaceCluster cluster = meshMaterials.clusters[clusterIndex];
685 
686  uint32_t materialIndex = meshMaterials.cluster_materials[clusterIndex];
687  mesh_msgs::MeshMaterial material = meshMaterials.materials[materialIndex];
688  bool hasTexture = material.has_texture;
689 
690 
691  // if the material has a texture, create an ogre texture and load the image
692  if (hasTexture)
693  {
694  std::stringstream sstm;
695  sstm << m_prefix << "_TexturedMesh_" << m_postfix << "_" << m_random << "TextureMaterial_" << textureIndex;
696  m_textureMaterials.push_back(
697  Ogre::MaterialManager::getSingleton().create(
698  sstm.str(),
699  Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME,
700  true
701  )
702  );
703 
704  // set some rendering options for textured clusters
705  Ogre::Pass* pass = m_textureMaterials[textureIndex]->getTechnique(0)->getPass(0);
706  // pass->setTextureFiltering(Ogre::TFO_NONE);
707  pass->setCullingMode(Ogre::CULL_NONE);
708  pass->setLightingEnabled(false);
709 
710  // check if image was already loaded
711  // this is the case if the vector of images doesn't contain this element yet or
712  // if the image was only default constructed, in which case its width will be 0
713  if (m_images.size() < textureIndex + 1 || m_images[textureIndex].getWidth() == 0)
714  {
715  ROS_INFO("Texture with index %lu not loaded yet", textureIndex);
716  }
717  else
718  {
719  loadImageIntoTextureMaterial(textureIndex);
720  }
721  }
722 
723 
724  if (hasTexture)
725  {
726  // start entering data
727  m_texturedMesh->clear();
728  m_texturedMesh->begin(m_textureMaterials[textureIndex]->getName(), Ogre::RenderOperation::OT_TRIANGLE_LIST);
729  textureIndex++;
730 
731  // write vertices for each triangle
732  // write texture coordinates
733  // write vertex normals (if enabled)
734 
735  size_t triangleVertexCount = 0;
736  for (size_t i = 0; i < cluster.face_indices.size(); i++)
737  {
738  uint32_t faceIndex = cluster.face_indices[i];
739  // write three triangle vertices
740  for (size_t j = 0; j < 3; j++)
741  {
742  int vertexIndex = mesh.faces[faceIndex].vertex_indices[j];
743  // write vertex positions
744  m_texturedMesh->position(
745  mesh.vertices[vertexIndex].x,
746  mesh.vertices[vertexIndex].y,
747  mesh.vertices[vertexIndex].z
748  );
749  // write texture coordinates
750  m_texturedMesh->textureCoord(
751  meshMaterials.vertex_tex_coords[vertexIndex].u,
752  1 - meshMaterials.vertex_tex_coords[vertexIndex].v
753  );
754 
755  // write vertex normals, if enabled
757  {
758  m_texturedMesh->normal(
759  mesh.vertex_normals[vertexIndex].x,
760  mesh.vertex_normals[vertexIndex].y,
761  mesh.vertex_normals[vertexIndex].z
762  );
763  }
764  }
765  // write the three triangle vertex indices
766  m_texturedMesh->triangle(
767  triangleVertexCount,
768  triangleVertexCount + 1,
769  triangleVertexCount + 2
770  );
771  triangleVertexCount += 3;
772  }
773 
774  // finish entering data
775  m_texturedMesh->end();
776 
777  }
778  else
779  {
780  // write vertices for each triangle to enable a coloring for each triangle
781  // write triangle colors as vertex colours
782  // write vertex normals (if enabled)
783 
784  size_t triangleVertexCount = 0;
785  for (size_t i = 0; i < cluster.face_indices.size(); i++)
786  {
787  uint32_t faceIndex = cluster.face_indices[i];
788  // write three triangle vertices
789  for (size_t j = 0; j < 3; j++)
790  {
791  int vertexIndex = mesh.faces[faceIndex].vertex_indices[j];
792  // write vertex positions
793  m_noTexCluMesh->position(
794  mesh.vertices[vertexIndex].x,
795  mesh.vertices[vertexIndex].y,
796  mesh.vertices[vertexIndex].z
797  );
798 
799  // write triangle colors
800  m_noTexCluMesh->colour(
801  material.color.r,
802  material.color.g,
803  material.color.b,
804  material.color.a
805  );
806 
807  // write vertex normals, if enabled
809  {
810  m_noTexCluMesh->normal(
811  mesh.vertex_normals[vertexIndex].x,
812  mesh.vertex_normals[vertexIndex].y,
813  mesh.vertex_normals[vertexIndex].z
814  );
815  }
816  }
817  // write the three triangle vertex indices
818  m_noTexCluMesh->triangle(
819  noTexCluVertexCount,
820  noTexCluVertexCount + 1,
821  noTexCluVertexCount + 2
822  );
823  noTexCluVertexCount += 3;
824  }
825 
826  }
827  }
828 
829  m_noTexCluMesh->end();
830 }
831 
832 void TexturedMeshVisual::enteringNormals(const mesh_msgs::MeshGeometry& mesh)
833 {
834 
836  {
837  return;
838  }
839 
840  std::stringstream sstm;
841  sstm << m_prefix << "_TexturedMesh_" << m_postfix << "_" << m_random << "NormalMaterial";
842  m_normalMaterial = Ogre::MaterialManager::getSingleton().create(
843  sstm.str(),
844  Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME,
845  true
846  );
847 
848  // Create pointNormals
849  m_normals->clear();
850  m_normals->begin(sstm.str(), Ogre::RenderOperation::OT_LINE_LIST);
851 
852  // Vertices
853  for (size_t i = 0; i < mesh.vertex_normals.size(); i++)
854  {
855  m_normals->position(mesh.vertices[i].x, mesh.vertices[i].y, mesh.vertices[i].z);
856  m_normals->position(
857  mesh.vertices[i].x + m_normalsScalingFactor * mesh.vertex_normals[i].x,
858  mesh.vertices[i].y + m_normalsScalingFactor * mesh.vertex_normals[i].y,
859  mesh.vertices[i].z + m_normalsScalingFactor * mesh.vertex_normals[i].z
860  );
861  // add line to index buffer
862  m_normals->index(2 * i);
863  m_normals->index(2 * i + 1);
864  }
865  m_normals->end();
866 
867 }
868 
869 bool TexturedMeshVisual::setGeometry(const mesh_msgs::MeshGeometryStamped::ConstPtr& meshMsg)
870 {
871  reset();
872 
873  // for a better legibility of the code
874  const mesh_msgs::MeshGeometry& mesh = meshMsg->mesh_geometry;
875  m_meshMsg = meshMsg->mesh_geometry;
876  m_meshUuid = meshMsg->uuid;
877 
878  // default: vertex colors are optional and therefore disabled
879  m_vertex_colors_enabled = false;
880 
881  // default: textures and texture_coords are optional and therefore disabled
882  m_textures_enabled = false;
883  m_texture_coords_enabled = false;
884 
885  // default: vertex normals are optional and therefore disabled
886  m_vertex_normals_enabled = false;
887 
888  // default: vertex costs are optional and therefore disabled
889  m_vertex_costs_enabled = false;
890 
891  // check if there are enough vertices given
892  if (mesh.vertices.size() < 3)
893  {
894  ROS_WARN("Received not enough vertices, can't create mesh!");
895  return false;
896  }
897 
898  // defines the buffer sizes
899  int vertex_count = mesh.vertices.size();
900  int index_count = mesh.faces.size() * 3;
901 
902 
903  // vertex normals
904  // check if there are vertex normals for each vertex
905  if (mesh.vertex_normals.size() == mesh.vertices.size())
906  {
907  ROS_INFO("Received %lu vertex normals.", mesh.vertex_normals.size());
909  }
910  else if (mesh.vertex_normals.size() > 0)
911  {
912  ROS_WARN("Received not as much vertex normals as vertices, ignoring vertex normals!");
913  }
914 
915  // avoid memory reallocation
916  m_mesh->estimateVertexCount(vertex_count);
917  m_mesh->estimateIndexCount(index_count);
918  m_normals->estimateVertexCount(mesh.vertices.size() * 2);
919  m_normals->estimateIndexCount(mesh.vertices.size() * 2);
920  // m_texturedMesh->estimateVertexCount(vertex_count * 3);
921  // m_texturedMesh->estimateIndexCount(index_count);
922 
923  // entering a general triangle mesh into the internal buffer
925 
926  // entering the normals into the internal buffer
928  {
929  enteringNormals(mesh);
930  }
931 
932  return true;
933 }
934 
935 bool TexturedMeshVisual::setVertexColors(const mesh_msgs::MeshVertexColorsStamped::ConstPtr& vertexColorsMsg)
936 {
937  //check if these MeshVertexColors belong to the current mesh and were not already loaded
938  if(m_meshUuid != vertexColorsMsg->uuid)
939  {
940  ROS_WARN("Can't add vertex colors, uuids do not match.");
941  return false;
942  }
943  // check if the vertex colors for this mesh were already set
944  if(m_vertexColorsUuid == vertexColorsMsg->uuid)
945  {
946  ROS_WARN("Can't add vertex colors, already received vertex colors for this mesh.");
947  return false;
948  }
949 
950  const mesh_msgs::MeshVertexColors vertexColors = vertexColorsMsg->mesh_vertex_colors;
951 
952  // check if there are vertex colors for each vertex
953  if (vertexColors.vertex_colors.size() == m_meshMsg.vertices.size())
954  {
955  ROS_INFO("Received %lu vertex colors.", vertexColors.vertex_colors.size());
957  }
958  else
959  {
960  ROS_WARN("Received not as much vertex colors as vertices, ignoring the vertex colors!");
961  return false;
962  }
963 
964  enteringColoredTriangleMesh(m_meshMsg, vertexColors);
965 
966  m_vertexColorsUuid = vertexColorsMsg->uuid;
967 
968  return true;
969 }
970 
972  const mesh_msgs::MeshVertexCostsStamped::ConstPtr& vertexCostsMsg,
973  int costColorType
974 )
975 {
976  //check if these MeshVertexCosts belong to the current mesh and were not already loaded
977  if(m_meshUuid != vertexCostsMsg->uuid)
978  {
979  ROS_WARN("Can't add vertex costs, uuids do not match.");
980  return false;
981  }
982 
983  const mesh_msgs::MeshVertexCosts vertexCosts = vertexCostsMsg->mesh_vertex_costs;
984 
985  // check if there are vertex costs for each vertex
986  if (vertexCosts.costs.size() == m_meshMsg.vertices.size())
987  {
988  ROS_INFO("Received %lu vertex costs.", vertexCosts.costs.size());
989  m_vertex_costs_enabled = true;
990  }
991  else
992  {
993  ROS_WARN("Received not as much vertex costs as vertices, ignoring the vertex costs!");
994  return false;
995  }
996 
997  enteringTriangleMeshWithVertexCosts(m_meshMsg, vertexCosts, costColorType);
998 
999  m_vertexCostsUuid = vertexCostsMsg->uuid;
1000 
1001  return true;
1002 }
1003 
1005  const mesh_msgs::MeshVertexCostsStamped::ConstPtr& vertexCostsMsg,
1006  int costColorType,
1007  float minCost,
1008  float maxCost
1009 )
1010 {
1011  //check if these MeshVertexCosts belong to the current mesh and were not already loaded
1012  if(m_meshUuid != vertexCostsMsg->uuid)
1013  {
1014  ROS_WARN("Can't add vertex costs, uuids do not match.");
1015  return false;
1016  }
1017 
1018  const mesh_msgs::MeshVertexCosts vertexCosts = vertexCostsMsg->mesh_vertex_costs;
1019 
1020  // check if there are vertex costs for each vertex
1021  if (vertexCosts.costs.size() == m_meshMsg.vertices.size())
1022  {
1023  ROS_INFO("Received %lu vertex costs.", vertexCosts.costs.size());
1024  m_vertex_costs_enabled = true;
1025  }
1026  else
1027  {
1028  ROS_WARN("Received not as much vertex costs as vertices, ignoring the vertex costs!");
1029  return false;
1030  }
1031 
1032  enteringTriangleMeshWithVertexCosts(m_meshMsg, vertexCosts, costColorType, minCost, maxCost);
1033 
1034  m_vertexCostsUuid = vertexCostsMsg->uuid;
1035 
1036  return true;
1037 }
1038 
1039 bool TexturedMeshVisual::setMaterials(const mesh_msgs::MeshMaterialsStamped::ConstPtr& materialMsg)
1040 {
1041  //check if these MeshMaterials belong to the current mesh and were not already loaded
1042  if(m_meshUuid != materialMsg->uuid)
1043  {
1044  ROS_WARN("Can't add materials, uuids do not match.");
1045  return false;
1046  }
1047  //check if the MeshMaterials were already set for this mesh
1048  if(m_materialsUuid == materialMsg->uuid)
1049  {
1050  ROS_WARN("Can't add materials, already received materials for this mesh.");
1051  return false;
1052  }
1053 
1054  mesh_msgs::MeshMaterials meshMaterials = materialMsg->mesh_materials;
1055 
1056  // check if there is a material index for each cluster
1057  if (meshMaterials.clusters.size() == meshMaterials.cluster_materials.size())
1058  {
1059  ROS_INFO("Received %lu clusters.", meshMaterials.clusters.size());
1060  m_materials_enabled = true; // enable textures
1061  }
1062  else
1063  {
1064  ROS_WARN("Received unmatching numbers of clusters and material indices, ignoring materials!");
1065  return false;
1066  }
1067 
1068  // texture coords
1069  // check if there are texture coords for each vertex
1070  if (meshMaterials.vertex_tex_coords.size() == m_meshMsg.vertices.size())
1071  {
1072  ROS_INFO("Received %lu texture coords.", meshMaterials.vertex_tex_coords.size());
1073  m_texture_coords_enabled = true; // enable texture coords
1074  m_textures_enabled = true;
1075  }
1076  else if (meshMaterials.vertex_tex_coords.size() > 0)
1077  {
1078  ROS_WARN("Received not as much texture coords as vertices, ignoring texture coords!");
1079  }
1080 
1081  enteringTexturedTriangleMesh(m_meshMsg, meshMaterials);
1082 
1083  m_materialsUuid = materialMsg->uuid;
1084 
1085  return true;
1086 }
1087 
1088 bool TexturedMeshVisual::addTexture(const mesh_msgs::MeshTexture::ConstPtr& textureMsg)
1089 {
1090  if(m_meshUuid != textureMsg->uuid || m_materialsUuid != textureMsg->uuid)
1091  {
1092  ROS_WARN("Can't add texture, uuids do not match.");
1093  return false;
1094  }
1095 
1096  size_t textureIndex = textureMsg->texture_index;
1097 
1098  uint32_t width = textureMsg->image.width;
1099  uint32_t height = textureMsg->image.height;
1100  uint32_t step = textureMsg->image.step;
1101  std::vector<uint8_t> data = textureMsg->image.data;
1102 
1103  uint32_t dataSize = height * step;
1104 
1105  uchar* imageData = new uchar[dataSize];
1106  std::memcpy(imageData, &data[0], dataSize);
1107 
1108  Ogre::PixelFormat pixelFormat = getOgrePixelFormatFromRosString(textureMsg->image.encoding);
1109 
1110  Ogre::Image image = Ogre::Image();
1111  // image.loadDynamicImage(&data[0], width, height, 1, pixelFormat, false);
1112  image.loadDynamicImage(imageData, width, height, 1, pixelFormat, false);
1113  m_images.insert(m_images.begin() + textureIndex, image);
1114 
1115  delete imageData;
1116 
1117  if (m_textureMaterials.size() >= textureIndex + 1)
1118  {
1119  loadImageIntoTextureMaterial(textureIndex);
1120  return true;
1121  }
1122  else
1123  {
1124  ROS_WARN("Can't load image into texture material, material does not exist!");
1125  return false;
1126  }
1127 
1128 }
1129 
1130 Ogre::PixelFormat TexturedMeshVisual::getOgrePixelFormatFromRosString(std::string encoding)
1131 {
1132  if (encoding == "rgba8")
1133  {
1134  return Ogre::PF_BYTE_RGBA;
1135  }
1136  else if (encoding == "rgb8")
1137  {
1138  return Ogre::PF_BYTE_RGB;
1139  }
1140 
1141  ROS_WARN("Unknown texture encoding! Using Ogre::PF_UNKNOWN");
1142  return Ogre::PF_UNKNOWN;
1143 }
1144 
1146 {
1147  std::stringstream textureNameStream;
1148  textureNameStream << m_prefix << "_Texture" << textureIndex << "_" << m_postfix << "_" << m_random;
1149 
1150  Ogre::TexturePtr texturePtr = Ogre::TextureManager::getSingleton().createManual(
1151  textureNameStream.str(),
1152  Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME,
1153  Ogre::TEX_TYPE_2D,
1154  m_images[textureIndex].getWidth(),
1155  m_images[textureIndex].getHeight(),
1156  0,
1157  m_images[textureIndex].getFormat()
1158  );
1159 
1160  texturePtr->loadImage(m_images[textureIndex]);
1161 
1162  Ogre::Pass* pass = m_textureMaterials[textureIndex]->getTechnique(0)->getPass(0);
1163  pass->removeAllTextureUnitStates();
1164  pass->createTextureUnitState()->addFrameTextureName(textureNameStream.str());
1165 }
1166 
1167 Ogre::ColourValue TexturedMeshVisual::calculateColorFromCost(float cost, int costColorType)
1168 {
1169  Ogre::ColourValue color;
1170 
1171  switch (costColorType)
1172  {
1173  case 0: // rainbow
1174  return getRainbowColor(cost);
1175  case 1: // red green
1176  // calculate a color that is green for 0, yellow for 0.5 and red for 1
1177  color.r = cost * 2;
1178  color.r = color.r > 1.0f ? 1.0f : color.r;
1179  color.g = (1.0f - cost) * 2;
1180  color.g = color.g > 1.0f ? 1.0f : color.g;
1181  color.b = 0.0f;
1182  color.a = 1.0;
1183  return color;
1184  default:
1185  break;
1186  }
1187  // default
1188  return getRainbowColor(cost);
1189 
1190 }
1191 
1192 void TexturedMeshVisual::setFramePosition(const Ogre::Vector3& position)
1193 {
1194  m_sceneNode->setPosition(position);
1195 }
1196 
1197 void TexturedMeshVisual::setFrameOrientation(const Ogre::Quaternion& orientation)
1198 {
1199  m_sceneNode->setOrientation(orientation);
1200 }
1201 
1202 } // end namespace rviz_mesh_plugin
rviz_mesh_plugin::TexturedMeshVisual::enteringTriangleMeshWithVertexCosts
void enteringTriangleMeshWithVertexCosts(const mesh_msgs::MeshGeometry &mesh, const mesh_msgs::MeshVertexCosts &vertexCosts, int costColorType)
Definition: textured_mesh_visual.cpp:556
rviz_mesh_plugin::TexturedMeshVisual::reset
void reset()
Clears whole stored data.
Definition: textured_mesh_visual.cpp:143
rviz_mesh_plugin::TexturedMeshVisual::m_noTexCluMaterial
Ogre::MaterialPtr m_noTexCluMaterial
The materials of the not textured clusters.
Definition: textured_mesh_visual.h:294
rviz_mesh_plugin::TexturedMeshVisual::m_meshUuid
std::string m_meshUuid
Uuid of the currently shown vertex colors.
Definition: textured_mesh_visual.h:309
rviz_mesh_plugin::TexturedMeshVisual::m_materials_enabled
bool m_materials_enabled
Definition: textured_mesh_visual.h:244
rviz_mesh_plugin::TexturedMeshVisual::~TexturedMeshVisual
virtual ~TexturedMeshVisual()
Destructor.
Definition: textured_mesh_visual.cpp:112
rviz_mesh_plugin::TexturedMeshVisual::m_vertex_costs_enabled
bool m_vertex_costs_enabled
Definition: textured_mesh_visual.h:243
rviz_mesh_plugin::TexturedMeshVisual::m_sceneNode
Ogre::SceneNode * m_sceneNode
Ogre Scenenode.
Definition: textured_mesh_visual.h:249
rviz_mesh_plugin::TexturedMeshVisual::m_normals
Ogre::ManualObject * m_normals
The manual object to display normals.
Definition: textured_mesh_visual.h:267
rviz_mesh_plugin::TexturedMeshVisual::m_materialsUuid
std::string m_materialsUuid
Uuid of the currently shown materials.
Definition: textured_mesh_visual.h:318
getName
ROSCONSOLE_CONSOLE_IMPL_DECL std::string getName(void *handle)
rviz_mesh_plugin::TexturedMeshVisual::updateNormals
void updateNormals(float scallingFactor)
Updates the size of the normals dynamically.
Definition: textured_mesh_visual.cpp:384
rviz_mesh_plugin::TexturedMeshVisual::getOgrePixelFormatFromRosString
Ogre::PixelFormat getOgrePixelFormatFromRosString(std::string encoding)
Definition: textured_mesh_visual.cpp:1130
step
unsigned int step
rviz_mesh_plugin::TexturedMeshVisual::setFrameOrientation
void setFrameOrientation(const Ogre::Quaternion &orientation)
Sets the orientation of the coordinate frame the message refers to.
Definition: textured_mesh_visual.cpp:1197
rviz_mesh_plugin::TexturedMeshVisual::m_random
size_t m_random
Random ID of the created mesh.
Definition: textured_mesh_visual.h:261
rviz_mesh_plugin::TexturedMeshVisual::m_postfix
size_t m_postfix
Second ID of the created mesh.
Definition: textured_mesh_visual.h:258
rviz::DisplayContext::getSceneManager
virtual Ogre::SceneManager * getSceneManager() const=0
rviz_mesh_plugin::TexturedMeshVisual::enteringNormals
void enteringNormals(const mesh_msgs::MeshGeometry &mesh)
Definition: textured_mesh_visual.cpp:832
f
f
rviz_mesh_plugin::TexturedMeshVisual::m_meshMsg
mesh_msgs::MeshGeometry m_meshMsg
Triangle Mesh contained in the given message.
Definition: textured_mesh_visual.h:306
rviz_mesh_plugin::TexturedMeshVisual::m_images
std::vector< Ogre::Image > m_images
Definition: textured_mesh_visual.h:279
rviz_mesh_plugin::TexturedMeshVisual::m_textures_enabled
bool m_textures_enabled
Definition: textured_mesh_visual.h:246
rviz_mesh_plugin::TexturedMeshVisual::m_displayContext
rviz::DisplayContext * m_displayContext
The context that contains the display information.
Definition: textured_mesh_visual.h:252
rviz_mesh_plugin::TexturedMeshVisual::m_vertexCostsMesh
Ogre::ManualObject * m_vertexCostsMesh
The manual object to display the mesh with vertex costs.
Definition: textured_mesh_visual.h:270
rviz_mesh_plugin::TexturedMeshVisual::showWireframe
void showWireframe(Ogre::Pass *pass, Ogre::ColourValue wireframeColor, float wireframeAlpha)
Enables the wireframe.
Definition: textured_mesh_visual.cpp:218
rviz_mesh_plugin::TexturedMeshVisual::loadImageIntoTextureMaterial
void loadImageIntoTextureMaterial(size_t textureIndex)
Definition: textured_mesh_visual.cpp:1145
rviz_mesh_plugin::TexturedMeshVisual::m_texture_coords_enabled
bool m_texture_coords_enabled
Definition: textured_mesh_visual.h:245
rviz_mesh_plugin::TexturedMeshVisual::m_vertex_normals_enabled
bool m_vertex_normals_enabled
Definition: textured_mesh_visual.h:241
rviz_mesh_plugin::TexturedMeshVisual::m_meshGeneralMaterial
Ogre::MaterialPtr m_meshGeneralMaterial
The material for the general mesh.
Definition: textured_mesh_visual.h:285
rviz_mesh_plugin::TexturedMeshVisual::showNormals
void showNormals(Ogre::Pass *pass, Ogre::ColourValue normalsColor, float normalsAlpha)
Definition: textured_mesh_visual.cpp:283
rviz_mesh_plugin::TexturedMeshVisual::updateMaterial
void updateMaterial(bool showWireframe, Ogre::ColourValue wireframeColor, float wireframeAlpha, bool showFaces, Ogre::ColourValue facesColor, float facesAlpha, bool useVertexColors, bool showVertexCosts, bool showTextures, bool showTexturedFacesOnly, bool showNormals, Ogre::ColourValue normalsColor, float normalsAlpha, float normalsScallingFactor)
Updates the visible parts of the mesh depending on input from the rviz display.
Definition: textured_mesh_visual.cpp:308
rviz_mesh_plugin::TexturedMeshVisual::m_vertexColorsUuid
std::string m_vertexColorsUuid
Uuid of the currently shown vertex colors.
Definition: textured_mesh_visual.h:312
rviz_mesh_plugin::TexturedMeshVisual::setMaterials
bool setMaterials(const mesh_msgs::MeshMaterialsStamped::ConstPtr &materialMsg)
Extracts data from the ros-messages and creates a textured mesh.
Definition: textured_mesh_visual.cpp:1039
rviz_mesh_plugin::getRainbowColor
Ogre::ColourValue getRainbowColor(float value)
Definition: textured_mesh_visual.cpp:20
rviz_mesh_plugin::TexturedMeshVisual::m_vertexCostMaterial
Ogre::MaterialPtr m_vertexCostMaterial
The material of the mesh with vertex costs.
Definition: textured_mesh_visual.h:297
rviz_mesh_plugin::TexturedMeshVisual::m_normalsScalingFactor
float m_normalsScalingFactor
Factor the normal-size is multiplied with.
Definition: textured_mesh_visual.h:303
ROS_WARN
#define ROS_WARN(...)
rviz_mesh_plugin::TexturedMeshVisual::addTexture
bool addTexture(const mesh_msgs::MeshTexture::ConstPtr &textureMsg)
Extracts data from the ros-messages and adds textures to the textured mesh.
Definition: textured_mesh_visual.cpp:1088
rviz_mesh_plugin::TexturedMeshVisual::m_normalMaterial
Ogre::MaterialPtr m_normalMaterial
The material of the normals.
Definition: textured_mesh_visual.h:291
rviz::DisplayContext
rviz_mesh_plugin::TexturedMeshVisual::m_vertex_colors_enabled
bool m_vertex_colors_enabled
Definition: textured_mesh_visual.h:242
rviz_mesh_plugin::TexturedMeshVisual::enteringGeneralTriangleMesh
void enteringGeneralTriangleMesh(const mesh_msgs::MeshGeometry &mesh)
Definition: textured_mesh_visual.cpp:439
rviz_mesh_plugin::TexturedMeshVisual::enteringColoredTriangleMesh
void enteringColoredTriangleMesh(const mesh_msgs::MeshGeometry &mesh, const mesh_msgs::MeshVertexColors &vertexColors)
Definition: textured_mesh_visual.cpp:493
rviz_mesh_plugin::TexturedMeshVisual::showTextures
void showTextures(Ogre::Pass *pass)
rviz_mesh_plugin::TexturedMeshVisual::setVertexCosts
bool setVertexCosts(const mesh_msgs::MeshVertexCostsStamped::ConstPtr &vertexCostsMsg, int costColorType)
Extracts data from the ros-messages and creates a colored mesh with colors calculated from vertex cos...
Definition: textured_mesh_visual.cpp:971
rviz_mesh_plugin::TexturedMeshVisual::m_vertexCostsUuid
std::string m_vertexCostsUuid
Uuid of the currently shown vertex costs.
Definition: textured_mesh_visual.h:315
rviz_mesh_plugin::TexturedMeshVisual::showFaces
void showFaces(Ogre::Pass *pass, Ogre::ColourValue facesColor, float facesAlpha, bool useVertexColors)
Definition: textured_mesh_visual.cpp:250
rviz_mesh_plugin::TexturedMeshVisual::setFramePosition
void setFramePosition(const Ogre::Vector3 &position)
Sets the pose of the coordinate frame the message refers to.
Definition: textured_mesh_visual.cpp:1192
rviz_mesh_plugin
Definition: face_selection_tool.h:117
rviz_mesh_plugin::TexturedMeshVisual::m_mesh
Ogre::ManualObject * m_mesh
The mesh-object to display.
Definition: textured_mesh_visual.h:264
rviz_mesh_plugin::TexturedMeshVisual::TexturedMeshVisual
TexturedMeshVisual(rviz::DisplayContext *context, size_t displayID, size_t meshID, size_t randomID)
Constructor.
Definition: textured_mesh_visual.cpp:44
ROS_ERROR
#define ROS_ERROR(...)
textured_mesh_visual.h
rviz_mesh_plugin::TexturedMeshVisual::calculateColorFromCost
Ogre::ColourValue calculateColorFromCost(float cost, int costColorType)
Calculates a color for a given cost value using a spectrum from red to green.
Definition: textured_mesh_visual.cpp:1167
rviz_mesh_plugin::TexturedMeshVisual::m_textureMaterials
std::vector< Ogre::MaterialPtr > m_textureMaterials
The materials of the textures.
Definition: textured_mesh_visual.h:300
rviz_mesh_plugin::TexturedMeshVisual::enteringTexturedTriangleMesh
void enteringTexturedTriangleMesh(const mesh_msgs::MeshGeometry &mesh, const mesh_msgs::MeshMaterials &meshMaterials)
Definition: textured_mesh_visual.cpp:654
ROS_INFO
#define ROS_INFO(...)
rviz_mesh_plugin::TexturedMeshVisual::setGeometry
bool setGeometry(const mesh_msgs::MeshGeometryStamped::ConstPtr &meshMsg)
Extracts data from the ros-messages and creates meshes.
Definition: textured_mesh_visual.cpp:869
rviz_mesh_plugin::TexturedMeshVisual::m_texturedMesh
Ogre::ManualObject * m_texturedMesh
The manual object to display the textured mesh.
Definition: textured_mesh_visual.h:273
rviz_mesh_plugin::TexturedMeshVisual::m_noTexCluMesh
Ogre::ManualObject * m_noTexCluMesh
The manual object to display the not textured parts of the textured mesh.
Definition: textured_mesh_visual.h:276
rviz_mesh_plugin::TexturedMeshVisual::setVertexColors
bool setVertexColors(const mesh_msgs::MeshVertexColorsStamped::ConstPtr &vertexColorsMsg)
Extracts data from the ros-messages and creates a colored mesh.
Definition: textured_mesh_visual.cpp:935
rviz_mesh_plugin::TexturedMeshVisual::m_prefix
size_t m_prefix
First ID of the created mesh.
Definition: textured_mesh_visual.h:255


rviz_mesh_plugin
Author(s): Sebastian Pütz , Henning Deeken , Marcel Mrozinski , Kristin Schmidt , Jan Philipp Vogtherr
autogenerated on Fri Feb 12 2021 04:03:57