38 #include <OgreMaterialManager.h>
39 #include <OgreTextureManager.h>
40 #include <OgreTechnique.h>
41 #include <OgreSceneNode.h>
52 Ogre::SceneManager& scene_manager, Ogre::SceneNode& scene_node)
53 : data_(data), scene_manager_(scene_manager), scene_node_(scene_node)
59 unsigned int rows = 1, cols = 1;
69 unsigned int n_swatches = rows * cols;
70 ROS_DEBUG(
"Creating %d swatches", n_swatches);
81 catch (Ogre::RenderingAPIException&)
83 ROS_DEBUG(
"Failed to create %d swatches", n_swatches);
97 std::vector<unsigned char> pixels;
98 unsigned int updated_panels = 0;
104 if (!swatch_bounds.
overlaps(updated_bounds))
continue;
107 unsigned int swatch_width = swatch_bounds.
getWidth(),
108 swatch_height = swatch_bounds.
getHeight();
109 pixels.resize(swatch_width * swatch_height);
111 auto pixel_it = pixels.begin();
116 unsigned int x_min = swatch_bounds.
getMinX();
117 unsigned int y_min = swatch_bounds.
getMinY();
118 unsigned int y_max = swatch_bounds.
getMaxY();
120 for (
unsigned int yy = y_min; yy <= y_max; yy++)
122 int index = yy * width + x_min;
123 std::copy(&
data_[index], &
data_[index + swatch_width], pixel_it);
124 pixel_it += swatch_width;
126 swatch->updateData(pixels);
133 const std::string name = palette.
getName();
139 ROS_DEBUG(
"Palette %s only has %zu colors defined. The rest will be black.",
140 name.c_str(), colors.size());
145 ROS_WARN(
"Palette %s has %zu colors defined...can only use the first %d.",
151 Ogre::DataStreamPtr palette_stream;
152 palette_stream.bind(
new Ogre::MemoryDataStream(&colors[0],
154 static int palette_tex_count = 0;
155 std::stringstream ss;
156 ss <<
"NavGridPaletteTexture" << palette_tex_count++;
158 palettes_[name] = Ogre::TextureManager::getSingleton().loadRawData(ss.str(),
159 Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME,
168 std::string ogre_palette_name =
palettes_[palette_name]->getName();
171 swatch->setTexture(ogre_palette_name, 1);
177 Ogre::SceneBlendType scene_blending;
179 int group = draw_behind ? Ogre::RENDER_QUEUE_4 : Ogre::RENDER_QUEUE_MAIN;
183 scene_blending = Ogre::SBT_TRANSPARENT_ALPHA;
188 scene_blending = Ogre::SBT_REPLACE;
189 depth_write = !draw_behind;
193 class AlphaSetter:
public Ogre::Renderable::Visitor
196 explicit AlphaSetter(
float alpha)
197 : alpha_vec_(alpha, alpha, alpha, alpha)
200 void visit(Ogre::Renderable *rend, ushort lodIndex,
bool isDebug, Ogre::Any *pAny = 0)
205 Ogre::Vector4 alpha_vec_;
208 AlphaSetter alpha_setter(alpha);
211 swatch->updateAlphaRendering(scene_blending, depth_write, group, &alpha_setter);
228 Ogre::Vector3 position;
229 Ogre::Quaternion orientation;