<table cellspacing="0" cellpadding="0" border="0" ><tr><td valign="top" style="font: inherit;">Hello everyone<br>In one of the examples given in vtk (cone2) i am
trying to use mouse interatcively to create some events for eg. if i do right click on mouse the
cone should stop rotating. How do i do it in vtk. <br> <br>Thank you<br>Frency Varghese<br>Here is the code<br><br>#include "vtkConeSource.h"<br>#include "vtkPolyDataMapper.h"<br>#include "vtkRenderWindow.h"<br>#include "vtkCommand.h"<br>#include "vtkCamera.h"<br>#include "vtkActor.h"<br>#include "vtkRenderer.h"<br><br>// Callback for the interaction<br>class vtkMyCallback : public vtkCommand<br>{<br>public:<br> static vtkMyCallback *New()<br> { return new vtkMyCallback; }<br> virtual void Execute(vtkObject *caller, unsigned long, void*)<br> {<br> vtkRenderer *renderer = reinterpret_cast<vtkRenderer*>(caller);<br> cout <<
renderer->GetActiveCamera()->GetPosition()[0] << " "<br> << renderer->GetActiveCamera()->GetPosition()[1] << " "<br> << renderer->GetActiveCamera()->GetPosition()[2] << "\n";<br> }<br>};<br><br>int main()<br>{<br> //<br> // The pipeline creation is documented in Step1<br> //<br> vtkConeSource *cone = vtkConeSource::New();<br> cone->SetHeight( 3.0 );<br> cone->SetRadius( 1.0 );<br> cone->SetResolution( 10 );<br><br> vtkPolyDataMapper *coneMapper = vtkPolyDataMapper::New();<br> coneMapper->SetInputConnection( cone->GetOutputPort() );<br> vtkActor *coneActor = vtkActor::New();<br> coneActor->SetMapper( coneMapper );<br><br> vtkRenderer *ren1= vtkRenderer::New();<br>
ren1->AddActor( coneActor );<br> ren1->SetBackground( 0.1, 0.2, 0.4 );<br> ren1->ResetCamera();<br><br> vtkRenderWindow *renWin = vtkRenderWindow::New();<br> renWin->AddRenderer( ren1 );<br> renWin->SetSize( 300, 300 );<br><br> // Here is where we setup the observer, we do a new and ren1 will<br> // eventually free the observer<br> vtkMyCallback *mo1 = vtkMyCallback::New();<br> ren1->AddObserver(vtkCommand::StartEvent,mo1);<br> mo1->Delete();<br><br> //<br> // now we loop over 360 degrees and render the cone each time<br> //<br> int i;<br> for (i = 0; i < 360; ++i)<br> {<br> // render the image<br> renWin->Render();<br> // rotate the active camera by one degree<br> ren1->GetActiveCamera()->Azimuth( 1 );<br> }<br><br>
//<br> // Free up any objects we created<br> //<br> cone->Delete();<br> coneMapper->Delete();<br> coneActor->Delete();<br> ren1->Delete();<br> renWin->Delete();<br><br> return 0;<br>}<br><br></td></tr></table><br>