Go to the documentation of this file.
63 #if defined(WITH_ASSIMP)
64 #include <assimp/Importer.hpp>
65 #include <assimp/postprocess.h>
66 #include <assimp/scene.h>
88 ROS_ERROR(
"Map Display: Geometry requested, but none available!");
110 std::string name = this->
getName().toStdString();
114 m_nh = std::make_shared<ros::NodeHandle>(
"~");
115 m_nh_p = std::make_shared<ros::NodeHandle>(
"~");
155 std::string name = this->
getName().toStdString();
156 std::cout << name <<
": LOAD CONFIG..." << std::endl;
161 std::stringstream ss;
162 ss <<
"rviz_map_plugin/" << name;
164 std::string mesh_file;
165 if(
m_nh_p->getParam(ss.str(), mesh_file))
169 std::cout << name <<
": COULDN'T FOUND MESH TO LOAD" << std::endl;
175 std::cout << name <<
": LOAD CONFIG done." << std::endl;
180 std::string name = this->
getName().toStdString();
181 std::cout << name <<
": updateMap" << std::endl;
195 for (
const auto& vertexCosts :
m_costs)
197 std::vector<float> costs = vertexCosts.second;
202 for (uint32_t i = 0; i <
m_textures.size(); i++)
221 std::string name = this->
getName().toStdString();
237 std::cout << name <<
"! Tried to load same map twice. Skipping and keeping old data" << std::endl;
251 if (!boost::filesystem::exists(mapFile))
258 ROS_INFO_STREAM(
"Map Display: Loading data for map '" << mapFile <<
"'");
262 if (boost::filesystem::extension(mapFile).compare(
".h5") == 0)
264 ROS_INFO(
"Map Display: Load HDF5 map");
268 ROS_INFO(
"Map Display: Load geometry");
273 ROS_INFO(
"Map Display: Load textures");
276 vector<hdf5_map_io::MapImage> textures = map_io.
getTextures();
278 for (
size_t i = 0; i < textures.size(); i++)
281 int textureIndex = std::stoi(textures[i].name);
284 m_textures[textureIndex].width = textures[i].width;
285 m_textures[textureIndex].height = textures[i].height;
286 m_textures[textureIndex].channels = textures[i].channels;
287 m_textures[textureIndex].data = textures[i].data;
288 m_textures[textureIndex].pixelFormat =
"rgb8";
291 ROS_INFO(
"Map Display: Load materials");
294 vector<hdf5_map_io::MapMaterial> materials = map_io.
getMaterials();
297 for (
size_t i = 0; i < materials.size(); i++)
306 if (materials[i].textureIndex == -1)
313 m_materials[i].textureIndex = materials[i].textureIndex;
320 for (
size_t k = 0; k < faceToMaterialIndexArray.size(); k++)
322 m_materials[faceToMaterialIndexArray[k]].faceIndices.push_back(k);
325 ROS_INFO(
"Map Display: Load vertex colors");
331 for (
size_t i = 0; i <
colors.size(); i += 3)
337 ROS_INFO(
"Map Display: Load vertex normals");
343 for (
size_t i = 0; i < normals.size(); i += 3)
345 m_normals.push_back(
Normal(normals[i + 0], normals[i + 1], normals[i + 2]));
348 ROS_INFO(
"Map Display: Load texture coordinates");
354 for (
size_t i = 0; i < texCoords.size(); i += 3)
359 ROS_INFO(
"Map Display: Load clusters");
370 std::stringstream ss;
371 ss << labelGroup <<
"_" << labelObj;
372 std::string label = ss.str();
385 catch (
const hf::DataSpaceException& e)
387 ROS_WARN_STREAM(
"Could not load channel " << costlayer <<
" as a costlayer!");
391 #if defined(WITH_ASSIMP)
394 std::cout <<
"LOADING WITH ASSIMP" << std::endl;
406 io.SetPropertyBool(AI_CONFIG_IMPORT_COLLADA_IGNORE_UP_DIRECTION,
true);
411 const aiScene* ascene = io.ReadFile(mapFile, aiProcess_PreTransformVertices);
413 const aiMesh* amesh = ascene->mMeshes[0];
415 const aiVector3D* ai_vertices = amesh->mVertices;
416 const aiFace* ai_faces = amesh->mFaces;
420 m_geometry->vertices.resize(amesh->mNumVertices);
423 for (
int i = 0; i < amesh->mNumVertices; i++)
425 m_geometry->vertices[i].x = amesh->mVertices[i].x;
426 m_geometry->vertices[i].y = amesh->mVertices[i].y;
427 m_geometry->vertices[i].z = amesh->mVertices[i].z;
430 for (
int i = 0; i < amesh->mNumFaces; i++)
432 m_geometry->faces[i].vertexIndices[0] = amesh->mFaces[i].mIndices[0];
433 m_geometry->faces[i].vertexIndices[1] = amesh->mFaces[i].mIndices[1];
434 m_geometry->faces[i].vertexIndices[2] = amesh->mFaces[i].mIndices[2];
437 #endif // defined(WITH_ASSIMP)
448 ROS_INFO(
"Map Display: Successfully loaded map.");
458 std::string label = cluster.
name;
459 std::vector<uint32_t> faces = cluster.
faces;
466 std::vector<std::string> results;
467 boost::split(results, label, [](
char c) {
return c ==
'_'; });
468 if (results.size() != 2)
std::vector< MapMaterial > getMaterials()
std::vector< std::string > getLabelGroups()
void onDisable()
RViz callback on disable.
std::vector< uint32_t > getMaterialFaceIndices()
void addTexture(Texture &texture, uint32_t textureIndex)
Add a texture.
Struct for texture coordinates.
void setVertexColors(vector< Color > &vertexColors)
Set the vertex colors.
void addVertexCosts(std::string costlayer, vector< float > &vertexCosts)
Adds a vertex costlayer.
void initialize(DisplayContext *context)
rviz::FileProperty * m_mapFilePath
Path to map file.
#define ROS_ERROR_STREAM(args)
std::vector< uint32_t > getFaceIds()
void updateMap()
Update the map, based on the current data state.
std::shared_ptr< ros::NodeHandle > m_nh_p
void setGeometry(shared_ptr< Geometry > geometry)
Set the geometry.
std::vector< std::string > getAllLabelsOfGroup(std::string groupName)
void onEnable()
RViz callback on enable.
vector< Color > m_colors
Colors.
void setVertexNormals(vector< Normal > &vertexNormals)
Set the vertex normals.
shared_ptr< Geometry > getGeometry()
Get the geometry.
virtual void addChild(Property *child, int index=-1)
virtual DisplayFactory * getDisplayFactory() const=0
std::vector< uint32_t > getFaceIdsOfLabel(std::string groupName, std::string labelName)
vector< Texture > m_textures
Textures.
vector< Material > m_materials
Materials.
std::vector< std::string > getCostLayers()
vector< Normal > m_normals
Vertex normals.
Display class for the map plugin.
virtual void setStatus(StatusProperty::Level level, const QString &name, const QString &text)
#define ROS_WARN_STREAM(args)
rviz_map_plugin::MeshDisplay * m_meshDisplay
Subdisplay: MeshDisplay (for showing the mesh)
std::vector< float > getVertexCosts(std::string costlayer)
#define PLUGINLIB_EXPORT_CLASS(class_type, base_class_type)
rviz_map_plugin::ClusterLabelDisplay * m_clusterLabelDisplay
Subdisplay: ClusterLabel (for showing the clusters)
std::string getFilename()
shared_ptr< Geometry > m_geometry
Geometry.
std::vector< float > getVertexNormals()
void clearVertexCosts()
Clears the vertex costs.
std::map< std::string, std::vector< float > > m_costs
std::enable_if<!QtPrivate::FunctionPointer< Func >::IsPointerToMemberFunction, QMetaObject::Connection >::type connect(const QObject *context, Func &&slot, Qt::ConnectionType type=Qt::AutoConnection)
void onEnable()
RViz callback on enable.
PropertyTreeModel * model_
std::vector< float > getVertexTextureCoords()
std::vector< MapImage > getTextures()
rviz::Display * createDisplay(const QString &class_id)
Create a RViz display from it's unique class_id.
void setData(shared_ptr< Geometry > geometry, vector< Cluster > clusters)
Setter for the geometry and cluster data.
void load(const Config &config) override
virtual Display * make(const QString &class_id, QString *error_return=nullptr)
#define ROS_INFO_STREAM(args)
vector< TexCoords > m_texCoords
Texture coordinates.
void setMaterials(vector< Material > &materials, vector< TexCoords > &texCoords)
Set the materials and texture coordinates.
void onEnable()
RViz callback on enable.
void setName(const QString &name) override
virtual void load(const rviz::Config &config)
void onDisable()
RViz callback on disable.
virtual QString getName() const
DisplayContext * context_
void setParent(Property *new_parent)
std::vector< uint8_t > getVertexColors()
Display for showing the mesh in different modes.
std::vector< float > getVertices()
KF_EXPORTS void error(const char *error_string, const char *file, const int line, const char *func="")
void saveLabel(Cluster cluster)
Saves a label to HDF5.
vector< Cluster > m_clusterList
Clusters.
void onInitialize()
RViz callback on initialize.
Master display for the Mesh- and Cluster- subdisplays. THis implementation uses HDF5 as it's data sou...
void ignoreIncomingMessages()
disables visualization of incoming messages
std::shared_ptr< ros::NodeHandle > m_nh
bool loadData()
Read all data from the HDF5 file and save it in the member variables.
void setModel(PropertyTreeModel *model)
void addOrUpdateLabel(std::string groupName, std::string labelName, std::vector< uint32_t > &faceIds)
void mapSetValue(const QString &key, const QVariant &value)
void onDisable()
RViz callback on disable.
std::string m_map_file_loaded
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