[ros-users] Dynamic Texture Loading in RVIZ, Dynamic Textures using OGRE

Osiloke Emoekpere osiloke_e at skuuled.com
Fri Apr 2 21:35:46 UTC 2010


Hi,
*@josh ->* thanks for your reply and sorry for the caps
Sorry if i appeared to come out strong, i was only trying to highlight the
part i wanted
to focus on (did not know i was offending anyone).  The caps thing was of no
relevance to the
tone of "my voice".

i really like the operating system and i'm in the process of loving it.

Anyway, I did use ros_image_texture class at first then just created a
dynamic texture using a tutorial from ogre
but my problem was not creating the texture, it was applying the texture to
the marker object. I'm sure i did
something wrong. Anyway this is the flow of processes in my system:

I have a node which listens for obstacle detection information  and camera
information

When an obstacle is detected,via a service, that node uses the dimensions
received to crop the most recent image from the camera
and stores a marker and an image tagged with the position of that obstacle
in a hash map.

After that, the new marker is sent to rviz as an IMAGE PLANE

RVIZ receives the marker draws it and then sends a request to the image
processor worker thread (i modified rviz a little) like so

*line 388 in map_display.cpp*
if (marker)
  {
  *//ROS_DEBUG("Calling get_obstacle_image: %ld , %s", (long
int)message->id,message->ns.c_str());*
*  if(message->type == visualization_msgs::Marker::IMPLANE)*
* **  {*
* **  m_pQueue->AddJob(ImageJob(ImageJob::eID_THREAD_JOB, ptr_response,
MarkerID(message->ns,message->id)));*
* **  ROS_INFO("Pulling image");*
* **  }*

    marker->setMessage(message);

    if (message->lifetime.toSec() > 0.0001f)
    {
      markers_with_expiration_.insert(marker);
    }

    causeRender();
  }

The image processor requests the image from the obstacle detector node and
converts it to an ogre image (All this thread does is convert a sensor image
to an ogreimage)

When this is done, the image processor raises an event which alerts RVIZ
that there is a new image.
*Response received in rviz via*
*line 482 in marker_display.cpp*
void MarkerDisplay::AddPendingEvent(const ImageJob::tCOMMANDS& cmd, const
Ogre::TexturePtr&  arg,rviz::MarkerID sArg, int iArg)
{
 //
  M_Namespace::iterator ns_it = namespaces_.find(sArg.first);
  if (ns_it == namespaces_.end())
  {
  return;
  }

  if (!ns_it->second.enabled)
  {
    return;
  }


  MarkerBasePtr marker;

  M_IDToMarker::iterator it = markers_.find( sArg );
  if ( it != markers_.end() )
  {
    marker = it->second;

  }
  if(marker)
  {
ROS_INFO("data %s",arg->getName().c_str());
*marker->assignTexture(arg);*
*  *//cause render to effect changes to marker object
***             causeRender();*

  }
}

RVIZ takes that image and applies to the marker it corresponds to (it is a
shape marker)

like so
in shape_marker.cpp
The dummy image is created when shape_marker is created in the constructor

std::stringstream ss;
ss << "SHAPETEX-h" << name;
texName = ss.str();
empty_image_.load("no_image.png",
Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
* **// Create the texture*
*     ** **texture_ = Ogre::TextureManager::getSingleton().createManual(*
* **texName, // name*
* **Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME,*
* **Ogre::TEX_TYPE_2D,      // type*
* **256, 256,         // width & height*
* **0,                // number of mipmaps*
* **empty_image_.getFormat(),     // pixel format*
* **Ogre::TU_DYNAMIC_WRITE_ONLY_DISCARDABLE);      // usage; should be
TU_DYNAMIC_WRITE_ONLY_DISCARDABLE for*

In order to load the image into the texture and then apply it to the shapes
material,
i do the following

PLEASE NOTE:
I also tried the blitfromemory to copy the image data to the texture
(resulted in some garbled results and later caused a seg error)


void ShapeMarker::setTexture(const Ogre::Image &img)
{
        //I first deleted the existing texture if there was any
if (!texture_.isNull())
  {
  Ogre::TextureManager::getSingleton().remove((Ogre::ResourcePtr&)texture_);
  texture_.setNull();
}
texture_ = Ogre::TextureManager::getSingleton().loadImage(texName,
Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME,img);
       //Then loaded the texture like so
       //texture_(new Ogre::Texture());
textured_=true;
        /// Testing. Apply Texture to Shape, i may be wrong here
Ogre::TexturePtr text_or(tex); //i thought copying it makes a difference
Ogre::MaterialPtr material_ = *shape_->getMaterial();//get material of
already existing shape*
material_->getTechnique(0)->getPass(0)->removeAllTextureUnitStates();
material_->getTechnique(0)->getPass(0)->createTextureUnitState(text_or->getName());
ROS_INFO("Texture Applied %s", text_or->getName().c_str());
}

So these where the steps i took to try and create my system
Any input and criticisms would be highly appreciated.

Thanks in anticipation of your help
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.ros.org/pipermail/ros-users/attachments/20100402/2491e9de/attachment-0003.html>


More information about the ros-users mailing list