30 #include <boost/bind/bind.hpp>
32 #include <OgreManualObject.h>
33 #include <OgreMaterialManager.h>
34 #include <OgreSceneManager.h>
35 #include <OgreSceneNode.h>
36 #include <OgreTextureManager.h>
37 #include <OgreTechnique.h>
38 #include <OgreSharedPtr.h>
68 void visit(Ogre::Renderable* rend,
71 Ogre::Any* =
nullptr)
override
87 : parent_(parent), manual_object_(nullptr), x_(x), y_(y), width_(width), height_(height)
90 static int material_count = 0;
92 ss <<
"MapMaterial" << material_count++;
93 material_ = Ogre::MaterialManager::getSingleton().getByName(
"rviz/Indexed8BitImage");
97 material_->getTechnique(0)->setLightingEnabled(
false);
99 material_->setCullingMode(Ogre::CULL_NONE);
102 static int map_count = 0;
103 std::stringstream ss2;
104 ss2 <<
"MapObject" << map_count++;
107 static int node_count = 0;
108 std::stringstream ss3;
109 ss3 <<
"NodeObject" << node_count++;
154 scene_node_->setPosition(x * resolution, y * resolution, 0);
155 scene_node_->setScale(width * resolution, height * resolution, 1.0);
175 material_->setSceneBlending(sceneBlending);
176 material_->setDepthWriteEnabled(depthWrite);
186 unsigned char* pixels =
new unsigned char[pixels_size];
187 memset(pixels, 255, pixels_size);
188 unsigned char* ptr = pixels;
192 for (
unsigned int yy =
y_; yy <
y_ +
height_; yy++)
194 int index = yy * fw +
x_;
195 int pixels_to_copy = std::min((
int)
width_, N - index);
197 ptr += pixels_to_copy;
198 if (index + pixels_to_copy >= N)
202 Ogre::DataStreamPtr pixel_stream;
203 pixel_stream.bind(
new Ogre::MemoryDataStream(pixels, pixels_size));
207 Ogre::TextureManager::getSingleton().remove(
texture_->getName());
211 static int tex_count = 0;
212 std::stringstream ss;
213 ss <<
"MapTexture" << tex_count++;
214 texture_ = Ogre::TextureManager::getSingleton().loadRawData(
215 ss.str(), Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, pixel_stream,
width_,
height_,
216 Ogre::PF_L8, Ogre::TEX_TYPE_2D, 0);
223 :
Display(), loaded_(false), map_updated_(false), resolution_(0.0
f), width_(0), height_(0)
226 "Topic",
"", QString::fromStdString(ros::message_traits::datatype<nav_msgs::OccupancyGrid>()),
242 "Draw Behind",
false,
243 "Rendering option, controls whether or not the map is always drawn behind everything else.",
this,
247 new FloatProperty(
"Resolution", 0,
"Resolution of the map. (not editable)",
this);
258 "Position of the bottom left corner of the map, in meters. (not editable)",
263 "Orientation of the map. (not editable)",
this);
270 new BoolProperty(
"Use Timestamp",
false,
"Use map header timestamp when transforming",
this,
278 for (
unsigned i = 0; i <
swatches.size(); i++)
287 unsigned char* palette = OGRE_ALLOC_T(
unsigned char, 256 * 4, Ogre::MEMCATEGORY_GENERAL);
288 unsigned char* palette_ptr = palette;
290 for (
int i = 0; i <= 100; i++)
292 unsigned char v = 255 - (255 * i) / 100;
296 *palette_ptr++ = 255;
299 for (
int i = 101; i <= 127; i++)
302 *palette_ptr++ = 255;
304 *palette_ptr++ = 255;
307 for (
int i = 128; i <= 254; i++)
309 *palette_ptr++ = 255;
310 *palette_ptr++ = (255 * (i - 128)) / (254 - 128);
312 *palette_ptr++ = 255;
315 *palette_ptr++ = 0x70;
316 *palette_ptr++ = 0x89;
317 *palette_ptr++ = 0x86;
318 *palette_ptr++ = 255;
325 unsigned char* palette = OGRE_ALLOC_T(
unsigned char, 256 * 4, Ogre::MEMCATEGORY_GENERAL);
326 unsigned char* palette_ptr = palette;
335 for (
int i = 1; i <= 98; i++)
337 unsigned char v = (255 * i) / 100;
340 *palette_ptr++ = 255 - v;
341 *palette_ptr++ = 255;
345 *palette_ptr++ = 255;
346 *palette_ptr++ = 255;
347 *palette_ptr++ = 255;
349 *palette_ptr++ = 255;
351 *palette_ptr++ = 255;
352 *palette_ptr++ = 255;
354 for (
int i = 101; i <= 127; i++)
357 *palette_ptr++ = 255;
359 *palette_ptr++ = 255;
362 for (
int i = 128; i <= 254; i++)
364 *palette_ptr++ = 255;
365 *palette_ptr++ = (255 * (i - 128)) / (254 - 128);
367 *palette_ptr++ = 255;
370 *palette_ptr++ = 0x70;
371 *palette_ptr++ = 0x89;
372 *palette_ptr++ = 0x86;
373 *palette_ptr++ = 255;
380 unsigned char* palette = OGRE_ALLOC_T(
unsigned char, 256 * 4, Ogre::MEMCATEGORY_GENERAL);
381 unsigned char* palette_ptr = palette;
383 for (
int i = 0; i < 256; i++)
388 *palette_ptr++ = 255;
396 Ogre::DataStreamPtr palette_stream;
397 palette_stream.bind(
new Ogre::MemoryDataStream(palette_bytes, 256 * 4,
true));
399 static int palette_tex_count = 0;
400 std::stringstream ss;
401 ss <<
"MapPaletteTexture" << palette_tex_count++;
402 return Ogre::TextureManager::getSingleton().loadRawData(
403 ss.str(), Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, palette_stream, 256, 1,
404 Ogre::PF_BYTE_RGBA, Ogre::TEX_TYPE_1D, 0);
479 Ogre::SceneBlendType sceneBlending;
484 sceneBlending = Ogre::SBT_TRANSPARENT_ALPHA;
489 sceneBlending = Ogre::SBT_REPLACE;
495 for (
unsigned i = 0; i <
swatches.size(); i++)
497 swatches[i]->updateAlpha(sceneBlending, depthWrite, &alpha_setter);
507 for (
unsigned i = 0; i <
swatches.size(); i++)
508 swatches[i]->material_->setDepthWriteEnabled(!draw_under);
511 int group = draw_under ? Ogre::RENDER_QUEUE_4 : Ogre::RENDER_QUEUE_MAIN;
512 for (
unsigned i = 0; i <
swatches.size(); i++)
515 swatches[i]->manual_object_->setRenderQueueGroup(group);
535 for (
unsigned i = 0; i <
swatches.size(); i++)
538 swatches[i]->manual_object_->setVisible(
false);
540 if (!
swatches[i]->texture_.isNull())
542 Ogre::TextureManager::getSingleton().remove(
swatches[i]->texture_->getName());
584 for (
size_t y = 0; y <
update->height; y++)
602 for (
int i = 0; i < 4; i++)
604 ROS_INFO(
"Creating %d swatches", n_swatches);
605 for (
unsigned i = 0; i <
swatches.size(); i++)
614 for (
int i = 0; i < n_swatches; i++)
617 if (width - x - sw >= sw)
622 if (height - y - sh >= sh)
640 catch (Ogre::RenderingAPIException&)
642 ROS_WARN(
"Failed to create %d swatches", n_swatches);
662 "Message contained invalid floating point values (nans or infs)");
669 "Map received on topic '%s' contains unnormalized quaternions. "
670 "This warning will only be output once but may be true for others; "
671 "enable DEBUG messages for ros.rviz.quaternions to see more details.",
673 ROS_DEBUG_NAMED(
"quaternions",
"Map received on topic '%s' contains unnormalized quaternions.",
679 std::stringstream ss;
705 Ogre::Quaternion orientation;
714 bool map_status_set =
false;
715 if (width * height !=
static_cast<int>(
current_map_.data.size()))
717 std::stringstream ss;
718 ss <<
"Data size doesn't match width*height: width = " << width <<
", height = " << height
721 map_status_set =
true;
724 for (
size_t i = 0; i <
swatches.size(); i++)
728 Ogre::Pass* pass =
swatches[i]->material_->getTechnique(0)->getPass(0);
729 Ogre::TextureUnitState* tex_unit =
nullptr;
730 if (pass->getNumTextureUnitStates() > 0)
732 tex_unit = pass->getTextureUnitState(0);
736 tex_unit = pass->createTextureUnitState();
739 tex_unit->setTextureName(
swatches[i]->texture_->getName());
740 tex_unit->setTextureFiltering(Ogre::TFO_NONE);
741 swatches[i]->manual_object_->setVisible(
true);
764 for (
unsigned i = 0; i <
swatches.size(); i++)
766 Ogre::Pass* pass =
swatches[i]->material_->getTechnique(0)->getPass(0);
767 Ogre::TextureUnitState* palette_tex_unit =
nullptr;
768 if (pass->getNumTextureUnitStates() > 1)
770 palette_tex_unit = pass->getTextureUnitState(1);
774 palette_tex_unit = pass->createTextureUnitState();
777 palette_tex_unit->setTextureFiltering(Ogre::TFO_NONE);
797 Ogre::Vector3 position;
798 Ogre::Quaternion orientation;
804 ROS_DEBUG(
"Error transforming map '%s' from frame '%s' to frame '%s'", qPrintable(
getName()),
808 "No transform from [" + QString::fromStdString(
frame_) +
"] to [" +
fixed_frame_ +
"]");