[vtkusers] Camera is not updated

Jens Schmidt jens.g.w.schmidt at gmx.de
Tue Aug 18 12:55:27 EDT 2015


Dear Cory,

thank you for your reply! It took some time to identify the problem further.
Please find at the very bottom of this mail a test implementation (java) 
showing the problem. The code creates a simple view showing some spheres 
and two buttons. The first button uses the camera present, the second 
one creates a new camera.
They should behave the same, but don't. I think it is the resetCamera() 
method. Maybe i use it wrong? The relevant code is in the 
selectionListeners for the buttons.

Best regards
Jens


Am 29.07.2015 um 03:48 schrieb Cory Quammen:
> Jens,
>
> Please remember to "reply-all" so that others on the list may benefit 
> from or contribute to the conversation.
>
> Do you have a small code sample that reproduces the issue? This kind 
> of camera manipulation followed by rendering is done all the time (see 
> [1], for example), so I'm not sure what is going on.
>
> Thanks,
> Cory
>
> [1] 
> http://www.vtk.org/gitweb?p=VTK.git;a=blob;f=Examples/Tutorial/Step3/Java/Cone3.java;h=91e003825bca66e275c22658019b6c52ef1afb75;hb=HEAD
>
> On Tue, Jul 28, 2015 at 7:42 AM, Jens Schmidt <jens.g.w.schmidt at gmx.de 
> <mailto:jens.g.w.schmidt at gmx.de>> wrote:
>
>     Cory,
>
>     thx for your reply! Yep called render each time i changed the
>     camera.  But the only time the camera did what i wanted was with
>     the new camera object and setActiveCamera.
>
>     Best regards
>     Jens
>
>
>
>     Am 27.07.2015 um 20:31 schrieb Cory Quammen:
>
>         Jens,
>
>         Did you try calling your render window's Render() member
>         function after
>         changing the camera properties? Rendering updates are not
>         performed
>         automatically when you change just camera properties. This is
>         actually good
>         because it prevents too many renderings when you update more
>         than one
>         camera property.
>
>         HTH,
>         Cory
>
>         On Mon, Jul 27, 2015 at 1:46 PM, Jens Schmidt
>         <jens.g.w.schmidt at gmx.de <mailto:jens.g.w.schmidt at gmx.de>>
>         wrote:
>
>             Hi Everyone!
>
>             VTK rocks, but we knew that allready. ^^ What rocks less
>             is that the
>             camera ist not automatically updated when SetPosition or
>             SetFocalPoint are
>             called.
>             Btw i am using the java wrapping with SWT.
>             VtkAbstractComponent has a
>             reference to the active camera.
>             Using that had no effect, as was using the renderers
>             GetActiveCamera
>             method.
>             In fact i have to create a new vtkCamera, modify that an
>             then pass it to
>             the renderer as new active camera -> tada change on the
>             screen.
>             Did i do something wrong or is that how it is supposed to
>             work?
>
>             Thank you
>             Jens
>             _______________________________________________
>             Powered by www.kitware.com <http://www.kitware.com>
>
>             Visit other Kitware open-source projects at
>             http://www.kitware.com/opensource/opensource.html
>
>             Please keep messages on-topic and check the VTK FAQ at:
>             http://www.vtk.org/Wiki/VTK_FAQ
>
>             Search the list archives at:
>             http://markmail.org/search/?q=vtkusers
>
>             Follow this link to subscribe/unsubscribe:
>             http://public.kitware.com/mailman/listinfo/vtkusers
>
>
>
>
>
>
>
> -- 
> Cory Quammen
> R&D Engineer
> Kitware, Inc.


Code below here:
==============

package CamTest;

import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.vtk.VTKLoader;

import vtk.vtkActor;
import vtk.vtkCamera;
import vtk.vtkPolyDataMapper;
import vtk.vtkSphereSource;
import vtk.rendering.swt.vtkSwtComponent;

public class CamTest {

     class vtkView extends vtkSwtComponent {

         public vtkView(Composite parentComposite) {
             super(parentComposite);
             renderer.SetBackground(0.1, 0.2, 0.4);
             renderer.SetBackground2(1, 1, 1);
             renderer.SetGradientBackground(true);
             vtkSwtComponent.attachOrientationAxes(this);
             update();
         }

         void setCamera(vtkCamera camera) {
             this.camera = camera;
             renderer.SetActiveCamera(camera);
         }

         void addSpheres(int precision, int numberInX, int numberInY, 
int numberInZ) {
             vtkSphereSource source = new vtkSphereSource();
             source.SetRadius(1.);
             source.SetPhiResolution(precision);
             source.SetThetaResolution(precision);

             vtkPolyDataMapper mapper = new vtkPolyDataMapper();
             mapper.SetInputConnection(source.GetOutputPort());
             mapper.Update();

             for (int i = 0; i < numberInX; i++) {
                 for (int j = 0; j < numberInY; j++) {
                     for (int k = 0; k < numberInZ; k++) {
                         vtkActor actor = new vtkActor();
                         actor.SetPosition(4 * i, 4 * j, 4 * k);
                         actor.SetMapper(mapper);
                         actor.GetProperty().BackfaceCullingOn();
                         renderer.AddActor(actor);
                     }
                 }
             }
             update();
             resetCamera();
         }
     }

     private vtkView vtkView;

     private CamTest() {
         VTKLoader loader = new VTKLoader();
         loader.loadAll();

         Display display = new Display();
         Shell shell = new Shell(display);
         shell.setText("CamTest");
         GridLayout layout = new GridLayout(2, false);
         shell.setLayout(layout);

         vtkView = new vtkView(shell);
         GridData data = new GridData(SWT.FILL, SWT.FILL, true, true, 2, 1);
         data.widthHint = 300;
         data.heightHint = 300;
         vtkView.getComponent().setLayoutData(data);

         vtkView.addSpheres(10, 10, 10, 10);

         Button isoButton = new Button(shell, SWT.PUSH);
         isoButton.setText("ISO VIEW");
         isoButton.addSelectionListener(new SelectionAdapter() {
             @Override
             public void widgetSelected(SelectionEvent e) {
                 System.out.println("ISO");
                 vtkCamera camera = vtkView.getActiveCamera();
                 camera.SetPosition(new double[] { 1., 1., 1. });
                 camera.SetViewUp(new double[] { 0., 0., 1. });
                 vtkView.resetCamera();// <-- bad line
                 vtkView.update();
             }
         });

         Button resetButton = new Button(shell, SWT.PUSH);
         resetButton.setText("RESET VIEW");
         resetButton.addSelectionListener(new SelectionAdapter() {
             @Override
             public void widgetSelected(SelectionEvent e) {
                 System.out.println("RESET");
                 vtkCamera newCamera = new vtkCamera();
                 newCamera.SetPosition(new double[] { 1., 1., 1. });
                 newCamera.SetViewUp(new double[] { 0., 0., 1. });
                 vtkView.setCamera(newCamera);
                 vtkView.resetCamera();
                 vtkView.update();
             }
         });

         shell.pack();
         shell.open();

         while (!shell.isDisposed()) {
             if (!display.readAndDispatch()) {
                 display.sleep();
             }
         }
         display.dispose();
     }

     public static void main(String[] args) {
         CamTest camTest = new CamTest();
     }

}

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/vtkusers/attachments/20150818/6f282655/attachment.html>


More information about the vtkusers mailing list