Hi!

I'm experiencing a problem when using osgViewer::InteractiveImageHandler on
multiple osgQt::QWidgetImages.

Currently I'm trying to display a kind of callout for certain geometries
in my application. This callout is a QWidget, which gets displayed using
a osgQt::QWidgetImage. In order to keep the widget facing to screen, I'm
using an osg::AutoTransform node, which is also set to auto-scale the image.
The goal is to have the callout floating next to the geometry at a constant
size, while the user can interact with the content of the image.
Because the geometry that gets the callout can be hidden behind others, I
disabled depth testing for the callout, so that it is placed above everything
else.

So far displaying the QWidget works fine. The problem starts when I try
to use the osgViewer::InteractiveImageHandler. When I set the handler
as event and cull handler for the geometry (created using 
createTexturedQuadGeometry),
I'm able to receive events on the QWidget, but sometimes it seems like
I can "click through" the QWidget when I have two of them stacked above one
another.
What I mean is that if I have two osgQt::QWidgetImages with event handlers
and rotate them so that they overlap, I'm able to click the overlapping part
of the widget in front, but the event gets handles by the widget in the back.
If I rotate them so that the widget order changes from back to front, the
problem persists and gets worse, as now parts of the events go to the
back widget, which should belong to the front widget and parts of the events
are handled correctly.

So my question is, if there is a known problem using 
osgViewer::InteractiveImageHandler
with osgQt::QWidgetImages and osg::AutoTransform and if there is anything
I can try to avoid this.

I already tried things like enabling the depth test again and even checked
the handling in osgViewer::InteractiveImageHandler, were I found that apparently
the intersection test always finds the firstly added widget first.

As maybe I wasn't able to explain this good enough, I'll post some code, based
on Wang Ruis cookbook example, which roughly mimics my setup and has the same
problem.

Code:

#include "QtCore/QtCore"
#include "QtGui/QtGui"
#include "osg/Texture2D"
#include "osg/Geometry"
#include "osg/CullStack"
#include "osg/AutoTransform"
#include "osg/MatrixTransform"
#include "osg/PositionAttitudeTransform"
#include "osgDB/ReadFile"
#include "osgGA/TrackballManipulator"
#include "osgViewer/ViewerEventHandlers"
#include "osgViewer/Viewer"
#include "osgQt/QWidgetImage"

QWidget* createDemoWidget( const QString& movieFile, const QString& title)
{
  QLabel* label = new QLabel;
  QPushButton* playBtn = new QPushButton("Play " + title );
  QPushButton* stopBtn = new QPushButton("Stop " + title );

  QWidget* demo = new QWidget;
  demo->setGeometry( 1, 1, 450, 450 );
  demo->setLayout( new QVBoxLayout );
  demo->layout()->addWidget( label );
  demo->layout()->addWidget( playBtn );
  demo->layout()->addWidget( stopBtn );

  QMovie* movie = new QMovie(movieFile);
  label->setMovie( movie );
  label->setFixedHeight( 400 );
  QObject::connect( playBtn, SIGNAL(clicked()), movie, SLOT(start()) );
  QObject::connect( stopBtn, SIGNAL(clicked()), movie, SLOT(stop()) );
  return demo;
}

osg::Node* createDemoNode(const osg::Vec3& position, const QString& title)
{
  osg::ref_ptr<osgQt::QWidgetImage> widgetImage =
    new osgQt::QWidgetImage( createDemoWidget("./animation.gif", title) );

  osg::ref_ptr<osgViewer::InteractiveImageHandler> handler =
    new osgViewer::InteractiveImageHandler( widgetImage.get() );
  osg::ref_ptr<osg::Texture2D> texture = new osg::Texture2D;
  texture->setImage( widgetImage.get() );

  osg::ref_ptr<osg::Geometry> quad =
    osg::createTexturedQuadGeometry(osg::Vec3(),
                                    
osg::Vec3(widgetImage->getQWidget()->width(),0,0),
                                    
osg::Vec3(0,widgetImage->getQWidget()->height(),0));

  quad->setEventCallback( handler.get() );
  quad->setCullCallback( handler.get() );

  osg::ref_ptr<osg::Geode> geode = new osg::Geode;
  geode->addDrawable(quad.get());
  geode->getOrCreateStateSet()->setTextureAttributeAndModes( 0, texture.get() );
  geode->getOrCreateStateSet()->setMode(GL_LIGHTING, osg::StateAttribute::OFF);
  geode->getOrCreateStateSet()->setMode(GL_DEPTH_TEST, 
osg::StateAttribute::OFF);
  
geode->getOrCreateStateSet()->setRenderingHint(osg::StateSet::TRANSPARENT_BIN);

  osg::ref_ptr<osg::AutoTransform> autoNode = new osg::AutoTransform;
  autoNode->setAutoRotateMode(osg::AutoTransform::ROTATE_TO_SCREEN);
  autoNode->setAutoScaleToScreen(true);
  autoNode->addChild(geode.get());

  osg::ref_ptr<osg::PositionAttitudeTransform> pat = new 
osg::PositionAttitudeTransform;
  pat->setPosition(position);
  pat->addChild(autoNode.get());

  return pat.release();
}


int main( int argc, char** argv )
{
  QApplication app( argc, argv );
  osg::ref_ptr<osg::Group> root = new osg::Group;

  root->addChild( createDemoNode(osg::Vec3(-1.0,0.0,0.0), "Widget 1") );
  root->addChild( createDemoNode(osg::Vec3( 1.0,0.0,0.0), "Widget 2") );

  osgViewer::Viewer viewer;
  viewer.setSceneData( root.get() );
  viewer.setCameraManipulator( new osgGA::TrackballManipulator );
  viewer.addEventHandler( new osgViewer::StatsHandler );

  while ( !viewer.done() )
  {
    QCoreApplication::processEvents( QEventLoop::AllEvents, 100 );
    viewer.frame();
  }
  return 0;
}




I addition, please find attached two images displaying the problem.

1before2.png: The first create widget is placed before the second widget.
Eventhandling works in this case.

2before1.png: Rotating the widgets you can see that while the mouse is placed
on the second widget (no now in front), the button in the first widget (in the 
back) gets the focus.
              
I hope I explained the problem good enough to be understandable. I look forward 
to your suggestions. Thanks in advance!

Regards,
 René

------------------
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=52946#52946




Attachments: 
http://forum.openscenegraph.org//files/1before2_235.png
http://forum.openscenegraph.org//files/2before1_822.png


_______________________________________________
osg-users mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

Reply via email to