<div class="gmail_quote">On Fri, Dec 11, 2009 at 7:35 PM, pof <span dir="ltr"><<a href="mailto:jd379252@gmail.com">jd379252@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
Hi,<br>
I'm using a vtkInteractorStyleTerrain, and I would like to use the mousewheel to do some zoom in/out towards the scene focal point, actually pretty much like what is obtained using a 'L' keypress.<br>
I've tried to change the mousewheelfactor with SetMouseWheelFactor(2), but still nothing happen at rendering (i.e. the camera does not move).<br>
I 've obviously missed something. Does anybody has an idea ?<br>
Thanks<br>
Pof<br><br></blockquote><div class="gmail_quote"><br></div><div class="gmail_quote">You can subclass the interactor and change any behaviors you like. Here, you'd be interested in OnMouseWheelForward and OnMouseWheelBackward</div>
<div class="gmail_quote"><br></div><div class="gmail_quote">Here is a demo:</div><div class="gmail_quote"><br></div><div class="gmail_quote"><div class="gmail_quote">#include <vtkSmartPointer.h></div><div class="gmail_quote">
#include <vtkPolyDataMapper.h></div><div class="gmail_quote">#include <vtkActor.h></div><div class="gmail_quote">#include <vtkRenderWindow.h></div><div class="gmail_quote">#include <vtkRenderer.h></div>
<div class="gmail_quote">#include <vtkRenderWindowInteractor.h></div><div class="gmail_quote">#include <vtkPolyData.h></div><div class="gmail_quote">#include <vtkSphereSource.h></div><div class="gmail_quote">
#include <vtkInteractorStyleTerrain.h></div><div class="gmail_quote">#include <vtkObjectFactory.h></div><div class="gmail_quote"><br></div><div class="gmail_quote">class MyInteractorStyle : public vtkInteractorStyleTerrain</div>
<div class="gmail_quote">{</div><div class="gmail_quote"> public:</div><div class="gmail_quote"> static MyInteractorStyle* New();</div><div class="gmail_quote"> </div><div class="gmail_quote"> virtual void OnMouseWheelForward() </div>
<div class="gmail_quote"> {</div><div class="gmail_quote"> cout << "Wheel forward" << endl;</div><div class="gmail_quote"> </div><div class="gmail_quote"> vtkRenderWindowInteractor *rwi = this->Interactor;</div>
<div class="gmail_quote"> </div><div class="gmail_quote"> this->FindPokedRenderer(rwi->GetEventPosition()[0],</div><div class="gmail_quote"> rwi->GetEventPosition()[1]);</div>
<div class="gmail_quote"> this->CreateLatLong();</div><div class="gmail_quote"> if (this->LatLongLines) </div><div class="gmail_quote"> {</div><div class="gmail_quote"> this->LatLongLinesOff();</div>
<div class="gmail_quote"> }</div><div class="gmail_quote"> else </div><div class="gmail_quote"> {</div><div class="gmail_quote"> double bounds[6];</div><div class="gmail_quote"> this->CurrentRenderer->ComputeVisiblePropBounds( bounds );</div>
<div class="gmail_quote"> double radius = sqrt((bounds[1]-bounds[0])*(bounds[1]-bounds[0]) +</div><div class="gmail_quote"> (bounds[3]-bounds[2])*(bounds[3]-bounds[2]) +</div><div class="gmail_quote">
(bounds[5]-bounds[4])*(bounds[5]-bounds[4])) /2.0;</div><div class="gmail_quote"> this->LatLongSphere->SetRadius( radius );</div><div class="gmail_quote"> this->LatLongSphere->SetCenter((bounds[0]+bounds[1])/2.0,</div>
<div class="gmail_quote"> (bounds[2]+bounds[3])/2.0,</div><div class="gmail_quote"> (bounds[4]+bounds[5])/2.0); </div><div class="gmail_quote">
this->LatLongLinesOn();</div><div class="gmail_quote"> }</div><div class="gmail_quote"> this->SelectRepresentation();</div><div class="gmail_quote"> rwi->Render();</div><div class="gmail_quote">
</div><div class="gmail_quote"> // forward events</div><div class="gmail_quote"> vtkInteractorStyleTerrain::OnMouseWheelForward();</div><div class="gmail_quote"> }</div><div class="gmail_quote"> </div>
<div class="gmail_quote"> virtual void OnMouseWheelBackward() </div><div class="gmail_quote"> {</div><div class="gmail_quote"> cout << "Wheel backward" << endl;</div><div class="gmail_quote">
</div><div class="gmail_quote"> // forward events</div><div class="gmail_quote"> vtkInteractorStyleTerrain::OnMouseWheelBackward();</div><div class="gmail_quote"> }</div><div class="gmail_quote"> </div><div class="gmail_quote">
};</div><div class="gmail_quote">vtkStandardNewMacro(MyInteractorStyle);</div><div class="gmail_quote"><br></div><div class="gmail_quote">int main (int argc, char *argv[])</div><div class="gmail_quote">{</div><div class="gmail_quote">
<br></div><div class="gmail_quote"> vtkSmartPointer<vtkSphereSource> sphereSource = </div><div class="gmail_quote"> vtkSmartPointer<vtkSphereSource>::New();</div><div class="gmail_quote"> sphereSource->Update();</div>
<div class="gmail_quote"> </div><div class="gmail_quote"> //create a mapper and actor</div><div class="gmail_quote"> vtkSmartPointer<vtkPolyDataMapper> mapper = </div><div class="gmail_quote"> vtkSmartPointer<vtkPolyDataMapper>::New();</div>
<div class="gmail_quote"> mapper->SetInputConnection(sphereSource->GetOutputPort());</div><div class="gmail_quote"><br></div><div class="gmail_quote"> vtkSmartPointer<vtkActor> actor = </div><div class="gmail_quote">
vtkSmartPointer<vtkActor>::New();</div><div class="gmail_quote"> actor->SetMapper(mapper);</div><div class="gmail_quote"><br></div><div class="gmail_quote"> // a renderer and render window</div><div class="gmail_quote">
vtkSmartPointer<vtkRenderer> renderer = </div><div class="gmail_quote"> vtkSmartPointer<vtkRenderer>::New();</div><div class="gmail_quote"> vtkSmartPointer<vtkRenderWindow> renderWindow = </div><div class="gmail_quote">
vtkSmartPointer<vtkRenderWindow>::New();</div><div class="gmail_quote"> renderWindow->AddRenderer(renderer);</div><div class="gmail_quote"><br></div><div class="gmail_quote"> // an interactor</div><div class="gmail_quote">
vtkSmartPointer<vtkRenderWindowInteractor> renderWindowInteractor = </div><div class="gmail_quote"> vtkSmartPointer<vtkRenderWindowInteractor>::New();</div><div class="gmail_quote"> renderWindowInteractor->SetRenderWindow(renderWindow);</div>
<div class="gmail_quote"><br></div><div class="gmail_quote"> // add the actors to the scene</div><div class="gmail_quote"> renderer->AddActor(actor);</div><div class="gmail_quote"> renderer->SetBackground(1,1,1); // Background color white</div>
<div class="gmail_quote"> </div><div class="gmail_quote"> renderWindow->Render();</div><div class="gmail_quote"><br></div><div class="gmail_quote"> // vtkSmartPointer<vtkInteractorStyleTerrain> style = </div><div class="gmail_quote">
// vtkSmartPointer<vtkInteractorStyleTerrain>::New();</div><div class="gmail_quote"> </div><div class="gmail_quote"> vtkSmartPointer<MyInteractorStyle> style = </div><div class="gmail_quote"> vtkSmartPointer<MyInteractorStyle>::New();</div>
<div class="gmail_quote"> </div><div class="gmail_quote"> renderWindowInteractor->SetInteractorStyle( style );</div><div class="gmail_quote"> </div><div class="gmail_quote"> renderWindowInteractor->Start();</div>
<div class="gmail_quote"> </div><div class="gmail_quote"> return EXIT_SUCCESS;</div><div class="gmail_quote">}</div></div><br clear="all">Thanks,<br><br><div>David </div></div>