[vtkusers] Adding a vtkTextActor during a EndPickEvent callback command hangs the renderer (Visual Studio 2012)

ROUET, Jean Michel jean-michel.rouet at philips.com
Fri Dec 7 09:37:24 EST 2012


Hi,

Anybody with visual studio 2012 around ?
I have a text example, derived from Cone5.cxx which crashes/hangs when a vtkTextActor is added to the scene during a pick callback.
Can anybody confirm this behavior behavior before I submit it as a bug ?

Best regards,
Jean-Michel


// First include the required header files for the VTK classes we are using.
#include "vtkConeSource.h"
#include "vtkPolyDataMapper.h"
#include "vtkRenderWindow.h"
#include "vtkRenderWindowInteractor.h"
#include "vtkCamera.h"
#include "vtkActor.h"
#include "vtkRenderer.h"
#include "vtkInteractorStyleTrackballCamera.h"
#include "vtkCallbackCommand.h"
#include "vtkCellPicker.h"
#include "vtkTextActor.h"
#include "vtkTextProperty.h"

// -----------------------------------------------------------------------
// define a callbackcommand subclass to react to picking events.
// here we simply add a vtkTextActor to the scene when the user picks
// the cone object, and remove it when the user picks outside of it.
//
class myPickCallbackCommand : public vtkCommand
{
private:
         vtkRenderer*                                mRenderer;
         vtkRenderWindowInteractor*         mRenderWindowInteractor;
         vtkTextActor*                               mTextActor;
public:
         static myPickCallbackCommand *New() { return new myPickCallbackCommand; }
         myPickCallbackCommand() : mRenderer(0x0), mRenderWindowInteractor(0x0), mTextActor(0x0) {}
         virtual void Execute(vtkObject *caller, unsigned long eid, void*)
         {
                 if( eid != vtkCommand::EndPickEvent ) return;
                 if( !mRenderer || !mRenderWindowInteractor ) return;
                 vtkCellPicker *picker = reinterpret_cast<vtkCellPicker*>(caller);
                 vtkProp* picked = picker->GetViewProp();
                 if ( picked != NULL )
                 {
                          cout << "Picked: " << endl;
                          if(mTextActor == NULL)
                          {
                                   std::cout << "adding a text actor" << std::endl;
                                   mTextActor = vtkTextActor::New();
                                   mTextActor->SetInput("this is a test");
                                   mTextActor->SetDisplayPosition(0.2,0.2);
                                   mRenderer->AddActor2D( mTextActor );
                                   mTextActor->Delete();
                          }
                 }
                 else
                 {
                          cout << "nothing picked\n";
                          if(mTextActor != NULL)
                          {
                                   mRenderer->RemoveActor2D(mTextActor);
                                   mTextActor = NULL;
                          }
                 }
                 mRenderWindowInteractor->Render();
         }
         void SetRenderer(vtkRenderer* ren) { this->mRenderer = ren; }
         void SetRenderWindowInteractor(vtkRenderWindowInteractor* iren)       { this->mRenderWindowInteractor = iren; }
};
int main()
{
  vtkConeSource *cone = vtkConeSource::New();
  cone->SetHeight( 3.0 );
  cone->SetRadius( 1.0 );
  cone->SetResolution( 10 );

  vtkPolyDataMapper *coneMapper = vtkPolyDataMapper::New();
  coneMapper->SetInputConnection( cone->GetOutputPort() );
  vtkActor *coneActor = vtkActor::New();
  coneActor->SetMapper( coneMapper );
  vtkRenderer *ren1= vtkRenderer::New();
  ren1->AddActor( coneActor );
  ren1->SetBackground( 0.1, 0.2, 0.4 );
  vtkRenderWindow *renWin = vtkRenderWindow::New();
  renWin->AddRenderer( ren1 );
  renWin->SetSize( 300, 300 );
  vtkRenderWindowInteractor *iren = vtkRenderWindowInteractor::New();
  iren->SetRenderWindow(renWin);
  vtkInteractorStyleTrackballCamera *style = vtkInteractorStyleTrackballCamera::New();
  iren->SetInteractorStyle(style);
  // add a cell picker with pickCallbackFunction;
  vtkCellPicker*    cellpicker = vtkCellPicker::New();
  cellpicker->SetTolerance(0.1);
  cellpicker->PickFromListOff();
  iren->SetPicker(cellpicker);
  myPickCallbackCommand* pickercbc = myPickCallbackCommand::New();
  pickercbc->SetRenderer(ren1);
  pickercbc->SetRenderWindowInteractor(iren);
  cellpicker->AddObserver(vtkCommand::EndPickEvent,pickercbc);
  pickercbc->Delete();

  iren->Initialize();
  iren->Start();

  cellpicker->Delete();
  cone->Delete();
  coneMapper->Delete();
  coneActor->Delete();
  ren1->Delete();
  renWin->Delete();
  iren->Delete();
  style->Delete();
  return 0;
}



________________________________
The information contained in this message may be confidential and legally protected under applicable law. The message is intended solely for the addressee(s). If you are not the intended recipient, you are hereby notified that any use, forwarding, dissemination, or reproduction of this message is strictly prohibited and may be unlawful. If you are not the intended recipient, please contact the sender by return e-mail and destroy all copies of the original message.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20121207/b5e47d25/attachment.htm>


More information about the vtkusers mailing list