<div class="gmail_quote">On Fri, Dec 11, 2009 at 7:35 PM, pof <span dir="ltr">&lt;<a href="mailto:jd379252@gmail.com">jd379252@gmail.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
Hi,<br>
I&#39;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 &#39;L&#39; keypress.<br>
I&#39;ve tried to change the mousewheelfactor with SetMouseWheelFactor(2), but still nothing happen at rendering (i.e. the camera does not move).<br>
I &#39;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&#39;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 &lt;vtkSmartPointer.h&gt;</div><div class="gmail_quote">
#include &lt;vtkPolyDataMapper.h&gt;</div><div class="gmail_quote">#include &lt;vtkActor.h&gt;</div><div class="gmail_quote">#include &lt;vtkRenderWindow.h&gt;</div><div class="gmail_quote">#include &lt;vtkRenderer.h&gt;</div>
<div class="gmail_quote">#include &lt;vtkRenderWindowInteractor.h&gt;</div><div class="gmail_quote">#include &lt;vtkPolyData.h&gt;</div><div class="gmail_quote">#include &lt;vtkSphereSource.h&gt;</div><div class="gmail_quote">
#include &lt;vtkInteractorStyleTerrain.h&gt;</div><div class="gmail_quote">#include &lt;vtkObjectFactory.h&gt;</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 &lt;&lt; &quot;Wheel forward&quot; &lt;&lt; endl;</div><div class="gmail_quote"> </div><div class="gmail_quote">        vtkRenderWindowInteractor *rwi = this-&gt;Interactor;</div>
<div class="gmail_quote">        </div><div class="gmail_quote">      this-&gt;FindPokedRenderer(rwi-&gt;GetEventPosition()[0],</div><div class="gmail_quote">                              rwi-&gt;GetEventPosition()[1]);</div>
<div class="gmail_quote">      this-&gt;CreateLatLong();</div><div class="gmail_quote">      if (this-&gt;LatLongLines) </div><div class="gmail_quote">        {</div><div class="gmail_quote">        this-&gt;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-&gt;CurrentRenderer-&gt;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-&gt;LatLongSphere-&gt;SetRadius( radius );</div><div class="gmail_quote">        this-&gt;LatLongSphere-&gt;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-&gt;LatLongLinesOn();</div><div class="gmail_quote">        }</div><div class="gmail_quote">      this-&gt;SelectRepresentation();</div><div class="gmail_quote">      rwi-&gt;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 &lt;&lt; &quot;Wheel backward&quot; &lt;&lt; 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&lt;vtkSphereSource&gt; sphereSource = </div><div class="gmail_quote">      vtkSmartPointer&lt;vtkSphereSource&gt;::New();</div><div class="gmail_quote">  sphereSource-&gt;Update();</div>
<div class="gmail_quote">  </div><div class="gmail_quote">  //create a mapper and actor</div><div class="gmail_quote">  vtkSmartPointer&lt;vtkPolyDataMapper&gt; mapper = </div><div class="gmail_quote">      vtkSmartPointer&lt;vtkPolyDataMapper&gt;::New();</div>
<div class="gmail_quote">  mapper-&gt;SetInputConnection(sphereSource-&gt;GetOutputPort());</div><div class="gmail_quote"><br></div><div class="gmail_quote">  vtkSmartPointer&lt;vtkActor&gt; actor = </div><div class="gmail_quote">
      vtkSmartPointer&lt;vtkActor&gt;::New();</div><div class="gmail_quote">  actor-&gt;SetMapper(mapper);</div><div class="gmail_quote"><br></div><div class="gmail_quote">  // a renderer and render window</div><div class="gmail_quote">
  vtkSmartPointer&lt;vtkRenderer&gt; renderer = </div><div class="gmail_quote">      vtkSmartPointer&lt;vtkRenderer&gt;::New();</div><div class="gmail_quote">  vtkSmartPointer&lt;vtkRenderWindow&gt; renderWindow = </div><div class="gmail_quote">
      vtkSmartPointer&lt;vtkRenderWindow&gt;::New();</div><div class="gmail_quote">  renderWindow-&gt;AddRenderer(renderer);</div><div class="gmail_quote"><br></div><div class="gmail_quote">  // an interactor</div><div class="gmail_quote">
  vtkSmartPointer&lt;vtkRenderWindowInteractor&gt; renderWindowInteractor = </div><div class="gmail_quote">      vtkSmartPointer&lt;vtkRenderWindowInteractor&gt;::New();</div><div class="gmail_quote">  renderWindowInteractor-&gt;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-&gt;AddActor(actor);</div><div class="gmail_quote">  renderer-&gt;SetBackground(1,1,1); // Background color white</div>
<div class="gmail_quote">  </div><div class="gmail_quote">  renderWindow-&gt;Render();</div><div class="gmail_quote"><br></div><div class="gmail_quote"> // vtkSmartPointer&lt;vtkInteractorStyleTerrain&gt; style = </div><div class="gmail_quote">
   //   vtkSmartPointer&lt;vtkInteractorStyleTerrain&gt;::New();</div><div class="gmail_quote">  </div><div class="gmail_quote">  vtkSmartPointer&lt;MyInteractorStyle&gt; style = </div><div class="gmail_quote">    vtkSmartPointer&lt;MyInteractorStyle&gt;::New();</div>
<div class="gmail_quote"> </div><div class="gmail_quote">  renderWindowInteractor-&gt;SetInteractorStyle( style );</div><div class="gmail_quote">  </div><div class="gmail_quote">  renderWindowInteractor-&gt;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>