[vtkusers] question about implementing my own image pan

Jonathan Morra jonmorra at gmail.com
Thu Oct 14 18:24:55 EDT 2010


I'm attempting to implement my own image pan in Java, and think that I am
very close, but not quite there yet.  I have a vtkImageViewer2, and the
following Java code

        vtkCamera camera =
panel.getImageViewer().GetRenderer().GetActiveCamera();

        double xChange = e.getX() - lastPoint[0];
        double yChange = e.getY() - lastPoint[1];
        startPoint(e);

        double[] position = camera.GetPosition();
        double[] focalPoint = camera.GetFocalPoint();
        switch (panel.getOrientation()) {
            case OrthoPanel.ORIENTATION_XY:
                position[0] += xChange;
                position[1] += yChange;
                focalPoint[0] += xChange;
                focalPoint[1] += yChange;
                break;
            case OrthoPanel.ORIENTATION_XZ:
                position[0] -= xChange;
                position[2] -= yChange;
                focalPoint[0] -= xChange;
                focalPoint[2] -= yChange;
                break;
            case OrthoPanel.ORIENTATION_YZ:
                position[1] += xChange;
                position[2] -= yChange;
                focalPoint[1] += xChange;
                focalPoint[2] -= yChange;
        }
        camera.SetPosition(position);
        camera.SetFocalPoint(focalPoint);
        panel.getImageViewer().Render();

Where lastPoint[] is the last point that the mouse was at, and the
startPoint(e) method updates the lastPoint array.  This code does pan the
image in the direction that the mouse moves, however the amount that is
panned per mouse movement is wrong, and it seems to be affected by the image
zoom (ie an image that is zoomed in very far pans too fast and an image that
is zoomed way out pans too slowly).  Does anyone have any idea why this is
or how to fix it.  My guess is that I have to multiply the xChange and
yChange by some scale factor that's a function of the zoom, but I can't seem
to figure it out.

Thanks
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20101014/73b06e9f/attachment.htm>


More information about the vtkusers mailing list