zoom function

1,027 views
Skip to first unread message

mhd.bakri

unread,
Nov 18, 2010, 6:27:26 AM11/18/10
to Jzy3d
Hello. I have a few questions to ask about jzy3d. I decided to use it
to develop my final year project. My project is
to visualize MDS in 3 dimensional.

1) how do I make normal zoom, means that all part of the graph
including its axes to come closer to the screen.
2) how do i move the camera, moving left, right, forward and down.

Which part of the code do I need to change? Or can I can just
implement it in my program (by method overridding)?

Im new to Java, thank you.

Martin Pernollet

unread,
Nov 18, 2010, 6:38:44 AM11/18/10
to jz...@googlegroups.com
Hello,

You need to:

1) override org.jzy3d.chart.controllers.mouse.ChartMouseController methods, mainly mouseWheelMoved(...) that is an implementation of MouseWheelListener interface's method. Your implementation should call methods of the View object.

2) look at the available methods in View. The wheel currently uses setScale that only works on Z axe. You will need to call View.setBoundManual(...) and then View.shoot(). I just noticed getBound() is missing, but you can call View.getAxe().getBoxBounds() if you want to know the current bounds of the view.

If you go further with your custom ChartMouseController, that could be great you share it with us.

Regards,
Martin


2010/11/18 mhd.bakri <mhdba...@gmail.com>

mhd.bakri

unread,
Nov 19, 2010, 7:23:02 AM11/19/10
to Jzy3d
Thank you Martin. I will share the code if I got it working.

On Nov 18, 7:38 pm, Martin Pernollet <martin.pernol...@gmail.com>
wrote:
> Hello,
>
> You need to:
>
> 1) override org.jzy3d.chart.controllers.mouse.ChartMouseController methods,
> mainly mouseWheelMoved(...) that is an implementation of MouseWheelListener
> interface's method. Your implementation should call methods of the View
> object.
>
> 2) look at the available methods in View. The wheel currently uses setScale
> that only works on Z axe. You will need to call View.setBoundManual(...) and
> then View.shoot(). I just noticed getBound() is missing, but you can call
> View.getAxe().getBoxBounds() if you want to know the current bounds of the
> view.
>
> If you go further with your custom ChartMouseController, that could be great
> you share it with us.
>
> Regards,
> Martin
>
> 2010/11/18 mhd.bakri <mhdbakr...@gmail.com>

mhd.bakri

unread,
Nov 19, 2010, 10:25:12 AM11/19/10
to Jzy3d
Update:
I got normal zoom to work. I just modify setScale function in View
class.

public void setScale(org.jzy3d.maths.Scale scale, boolean notify){
BoundingBox3d bounds = getBounds();
bounds.setZmin((float)scale.getMin());
bounds.setZmax((float)scale.getMax());
bounds.setXmin((float)scale.getMin());
bounds.setXmax((float)scale.getMax());
bounds.setYmin((float)scale.getMin());
bounds.setYmax((float)scale.getMax());
//setBoundManual(bounds);
if(notify)
shoot();
}

Right now, I'm trying to move camera position when user press arrow
key by using:

chart.getCanvas().addKeyListener(new KeyListener() { ... });

taken from one of the demo. Still no luck.

Martin Pernollet

unread,
Nov 21, 2010, 4:09:41 PM11/21/10
to jz...@googlegroups.com


2010/11/19 mhd.bakri <mhdba...@gmail.com>

Update:
I got normal zoom to work. I just modify setScale function in View
class.

       public void setScale(org.jzy3d.maths.Scale scale, boolean notify){
               BoundingBox3d bounds = getBounds();
               bounds.setZmin((float)scale.getMin());
               bounds.setZmax((float)scale.getMax());
               bounds.setXmin((float)scale.getMin());
               bounds.setXmax((float)scale.getMax());
               bounds.setYmin((float)scale.getMin());
               bounds.setYmax((float)scale.getMax());
               //setBoundManual(bounds);
               if(notify)
                       shoot();
       }


As I told you: "You will need to call View.setBoundManual(...) and then View.shoot(). I just noticed getBound() is missing, but you can call View.getAxe().getBoxBounds() if you want to know the current bounds of the view."

 

Right now, I'm trying to move camera position when user press arrow
key by using:

chart.getCanvas().addKeyListener(new KeyListener() { ... });

taken from one of the demo. Still no luck.

Which demo?

mhd.bakri

unread,
Nov 21, 2010, 7:33:24 PM11/21/10
to Jzy3d


On Nov 22, 5:09 am, Martin Pernollet <martin.pernol...@gmail.com>
wrote:
> 2010/11/19 mhd.bakri <mhdbakr...@gmail.com>
>
>
>
>
>
>
>
>
>
> > Update:
> > I got normal zoom to work. I just modify setScale function in View
> > class.
>
> >        public void setScale(org.jzy3d.maths.Scale scale, boolean notify){
> >                BoundingBox3d bounds = getBounds();
> >                bounds.setZmin((float)scale.getMin());
> >                bounds.setZmax((float)scale.getMax());
> >                bounds.setXmin((float)scale.getMin());
> >                bounds.setXmax((float)scale.getMax());
> >                bounds.setYmin((float)scale.getMin());
> >                bounds.setYmax((float)scale.getMax());
> >                //setBoundManual(bounds);
> >                if(notify)
> >                        shoot();
> >        }
>
> As I told you: "*You will need to call View.setBoundManual(...) and then
> View.shoot(). I just noticed getBound() is missing, but you can call
> View.getAxe().getBoxBounds() if you want to know the current bounds of the
> view.*"
>
>

I moved the zoom function into mouseWheelMoved in
ChartMouseController. The zoom function worked.
But, if I call setBoundManual(..), the zoom will break. Only objects
in the graph will zoom, the axes size remain the same.

/** Compute zoom */
public void mouseWheelMoved(MouseWheelEvent e) {
if(threadController!=null)
threadController.stop();

float factor = 1 + (e.getWheelRotation()/10.0f);
//zoom(factor);

Scale currScale = View.current().getScale();
double range = currScale.getMax() - currScale.getMin();

if(range<=0)
return;

double center = (currScale.getMax() + currScale.getMin())/2;
double min = center + (currScale.getMin()-center) * (factor);
double max = center + (currScale.getMax()-center) * (factor);
Scale scale = null;
if(min<max) {
scale = new org.jzy3d.maths.Scale(min, max);
}
else{
if(factor<1) // forbid to have min = max if we zoom in
scale = new org.jzy3d.maths.Scale(center, center);
}
BoundingBox3d bounds = View.current().getBounds();
bounds.setZmin((float)scale.getMin());
bounds.setZmax((float)scale.getMax());
bounds.setYmin((float)scale.getMin());
bounds.setYmax((float)scale.getMax());
bounds.setXmin((float)scale.getMin());
bounds.setXmax((float)scale.getMax());
//View.current().setBoundManual(bounds); can't use this
//View.current().updateBounds();
View.current().shoot();
}
>
> > Right now, I'm trying to move camera position when user press arrow
> > key by using:
>
> > chart.getCanvas().addKeyListener(new KeyListener() { ... });
>
> > taken from one of the demo. Still no luck.
>
> Which demo?

Interactive scatterplot demo, to react when user press a key. The
keylistener is working.
How do I move the camera position(left, right, up and down), is it the
'Coord3d target' in camera object?

Thank you.

Martin Pernollet

unread,
Nov 22, 2010, 8:20:08 AM11/22/10
to jz...@googlegroups.com
1) Yes the box remain the same size but should change range (does it?). This is due to "squarification" that makes the scene stand into a cube, whatever the X, Y, Z ranges are. The layout section in the wiki doc explain how to desactivate squarification.
2) Use org.jzy3d.chart.controllers.keyboard.ChartKeyController, as explained in the Controller section in the wiki. Key & mouse controller allow the camera to rotate around the cube center, but not to pan. Here is the behaviour of the Key controller:

public void keyPressed(KeyEvent e) {
     // rotation
     if(!e.isShiftDown()){
     Coord2d move = new Coord2d();
     float offset = 0.1f;
     switch(e.getKeyCode()){
     case KeyEvent.VK_DOWN:
     move.y = move.y - offset; rotate( move ); break;
     case KeyEvent.VK_UP:
     move.y = move.y + offset; rotate( move ); break;
     case KeyEvent.VK_LEFT:
     move.x = move.x - offset; rotate( move ); break;
     case KeyEvent.VK_RIGHT:
     move.x = move.x + offset; rotate( move ); break;
     default:
     break;
     }
     }
     // zoom
     else{    
     switch(e.getKeyCode()){
     // shift
     case KeyEvent.VK_DOWN:
     shift( 0.1f ); break;
     case KeyEvent.VK_UP:
     shift( -0.1f ); break;
     // zoom
     case KeyEvent.VK_LEFT:
     zoom( 0.9f ); break;
     case KeyEvent.VK_RIGHT:
     zoom( 1.1f ); break;
     default:
     break;
     }
     }
    }



2010/11/22 mhd.bakri <mhdba...@gmail.com>

mhd.bakri

unread,
Nov 22, 2010, 9:25:58 AM11/22/10
to Jzy3d
thank you.

which variable do I need to change to move the camera focus?

On Nov 22, 9:20 pm, Martin Pernollet <martin.pernol...@gmail.com>
wrote:
> 1) Yes the box remain the same size but should change range (does it?). This
> is due to "squarification" that makes the scene stand into a cube, whatever
> the X, Y, Z ranges are. The layout section in the wiki doc explain how to
> desactivate squarification.
> 2) Use org.jzy3d.chart.controllers.keyboard.ChartKeyController, as explained
> in the Controller section in the wiki. Key & mouse controller allow the
> camera to *rotate* around the cube center, but not to *pan*. Here is the
> 2010/11/22 mhd.bakri <mhdbakr...@gmail.com>

Martin Pernollet

unread,
Nov 22, 2010, 6:23:36 PM11/22/10
to jz...@googlegroups.com
chart.getView().getCamera.setTarget(Coord3d)
You can also edit the viewpoint with camera.get/setEye()
Martin

2010/11/22 mhd.bakri <mhdba...@gmail.com>

mhd.bakri

unread,
Nov 27, 2010, 7:26:52 AM11/27/10
to Jzy3d
there is no effect after I change the value of Coord3d target in
camera object using chart.getView().getCamera.setTarget(Coord3d).
The value of 'target' will be reset back to its original value.

Sorry for the late reply.

On Nov 23, 7:23 am, Martin Pernollet <martin.pernol...@gmail.com>
wrote:
> chart.getView().getCamera.setTarget(Coord3d)
> You can also edit the viewpoint with camera.get/setEye()
> Martin
>
> 2010/11/22 mhd.bakri <mhdbakr...@gmail.com>

Martin Pernollet

unread,
Nov 27, 2010, 7:47:14 AM11/27/10
to jzy3d
I can help if you provide a simple sample code that show exactly what you are trying to do.

2010/11/27 mhd.bakri <mhdba...@gmail.com>

mhd.bakri

unread,
Nov 27, 2010, 9:45:50 PM11/27/10
to Jzy3d
@Override
public void keyPressed(KeyEvent e) {
// rotation
Coord3d target = chart.getView().getCamera().getTarget();
float offset = 0.1f;
switch(e.getKeyCode()){
case KeyEvent.VK_DOWN:
System.out.println(chart.getView().getCamera().toString());
target.y = target.y - offset;
System.out.println(chart.getView().getCamera().toString());
break;
case KeyEvent.VK_UP:
target.y = target.y + offset;
case KeyEvent.VK_LEFT:
target.x = target.x - offset;
case KeyEvent.VK_RIGHT:
target.x = target.x + offset;
default:
break;
}

}

the output:
//1st key pressed
(Camera) lookFrom = {536.14734, 720.0, 1160.0} lookTo = {285.0,
285.0, 290.0} topToward = {0.0, 0.0, 1.0}
(Camera) lookFrom = {536.14734, 720.0, 1160.0} lookTo = {285.0,
284.9, 290.0} topToward = {0.0, 0.0, 1.0}
//2nd key pressed
(Camera) lookFrom = {536.14734, 720.0, 1160.0} lookTo = {285.0,
285.0, 290.0} topToward = {0.0, 0.0, 1.0}
(Camera) lookFrom = {536.14734, 720.0, 1160.0} lookTo = {285.0,
284.9, 290.0} topToward = {0.0, 0.0, 1.0}

I press the 'DOWN' key 2 times without moving the camera. As you can
see, the value in lookTo/target is reset back to its original value.

On Nov 27, 8:47 pm, Martin Pernollet <martin.pernol...@gmail.com>
wrote:
> I can help if you provide a simple sample code that show exactly what you
> are trying to do.
>
> 2010/11/27 mhd.bakri <mhdbakr...@gmail.com>

Klemen Zhivko

unread,
Nov 12, 2014, 8:39:52 AM11/12/14
to jz...@googlegroups.com
Is it possible to prevent zoom all after adding new drawable to graph?

Dne nedelja, 28. november 2010 03:45:50 UTC+1 je oseba mhd.bakri napisala:

Martin Pernollet

unread,
Nov 12, 2014, 9:51:38 AM11/12/14
to Jzy3d
Switch view to non - automatic zoom mode (setBoundsManual or a similar name)

--
Vous recevez ce message, car vous êtes abonné au groupe Google Groupes "Jzy3d".
Pour vous désabonner de ce groupe et ne plus recevoir d'e-mails le concernant, envoyez un e-mail à l'adresse jzy3d+un...@googlegroups.com.
Pour obtenir davantage d'options, consultez la page https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages