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);
128 ROS_DEBUG(
"Updated %d/%zu panels", updated_panels, swatches_.size());
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;
std::string current_palette_
bool overlaps(const GenericBounds< unsigned int > &other) const
unsigned int getMinX() const
unsigned int getMinY() const
std::map< std::string, bool > palette_transparency_
std::vector< nav_core2::UIntBounds > divideBounds(const nav_core2::UIntBounds &original_bounds, unsigned int n_cols, unsigned int n_rows)
void updateInfo(const nav_grid::NavGridInfo &info)
Update the location/shape of the grid.
static const unsigned int NUM_CHANNELS
OgrePanel(nav_grid::VectorNavGrid< unsigned char > &data, Ogre::SceneManager &scene_manager, Ogre::SceneNode &scene_node)
virtual std::vector< color_util::ColorRGBA24 > getColors() const =0
The actual definition of the colors.
static const unsigned int NUM_COLORS
std::shared_ptr< PartialOgrePanel > Ptr
std::string getFrameId() const
virtual bool hasTransparency() const
See if the palette has any transparent colors.
Ogre::SceneManager & scene_manager_
nav_grid::VectorNavGrid< unsigned char > & data_
void clear()
Clear the panel from the visualization by making it invisible.
Several reusable pieces for displaying polygons.
bool transform(const Header &header, const geometry_msgs::Pose &pose, Ogre::Vector3 &position, Ogre::Quaternion &orientation)
void addPalette(const NavGridPalette &palette)
Add a palette with the given name.
geometry_msgs::Pose getOrigin3D(const nav_grid::NavGridInfo &info)
std::map< std::string, Ogre::TexturePtr > palettes_
unsigned int getWidth() const
NavGridInfo getInfo() const
Ogre::SceneNode & scene_node_
bool transformMap(rviz::FrameManager &fm)
Move the map to its proper position and orientation.
unsigned int getHeight() const
nav_core2::UIntBounds getFullUIntBounds(const nav_grid::NavGridInfo &info)
void updateData(const nav_core2::UIntBounds &updated_bounds)
Update the panel data within the given bounds.
void updateAlpha(float alpha, bool draw_behind)
Sets the alpha/draw_behind properties.
virtual std::string getName() const =0
Unique descriptive name for this particular palette.
std::vector< PartialOgrePanel::Ptr > swatches_
unsigned int getWidth() const
void setPalette(const std::string &palette_name)
Set the palette to use.
A simple datastructure representing a palette of up to 256 24-bit colors.
unsigned int getMaxY() const