Author Topic: viewport  (Read 103 times)

Kevin

  • Newbie
  • *
  • Posts: 25
viewport
« on: April 17, 2018, 06:17:45 AM »
Hello Dr.Stukowski and OVITO users,

I am trying to output a movie in python scripting. I found there are three parameters I can adjust, but have struggled to really understand what the parameters actually do. Three parameters are as follows:
1. fov
2. camera_pos
3. camera_dir

Could anyone help me adjust the parameters so that I can mimic the 'Perspective' viewport as in GUI? (see attached image)

- Kyu

Alexander Stukowski

  • Administrator
  • Sr. Member
  • *****
  • Posts: 369
Re: viewport
« Reply #1 on: April 17, 2018, 07:34:35 AM »
Dear Kyu,

I'm not really sure how to define these parameters better than how it is already done in the Python docs:

http://ovito.org/manual/python/modules/ovito_vis.html#ovito.vis.Viewport

These parameters control the position of the virtual camera relative to the dataset, the direction it is taking the picture, and the focal length of the camera.

In any case it is definitely a good idea to check out the Adjust View dialog in the graphical version of OVITO, see:

http://ovito.org/manual/viewports.adjust_view_dialog.html

If you open this dialog for a viewport, it will show you the current values for these three parameters ("View position" corresponds to 'camera_pos', "View direction" corresponds to 'camera_dir', and "View angle" to the FOV (field of view) value). Note that the dialog displays the FOV angle in degrees, while in a Python script you would have to use radians.

-Alex

Kevin

  • Newbie
  • *
  • Posts: 25
Re: viewport
« Reply #2 on: April 18, 2018, 11:08:24 PM »
Thank you so much.
This was exactly what I was looking for.
I can't believe I missed that part of the documentation, and only focused on scripting documentation.
Thanks again.

- Kyu

Kevin

  • Newbie
  • *
  • Posts: 25
Re: viewport
« Reply #3 on: April 19, 2018, 12:42:29 AM »
I actually have an additional question.

Is there a way to access how how GUI version of OVITO's 'Perspective' viewport calculates its 'View position', 'View direction', and 'View angle' ?

Thank you,
Kyu

Alexander Stukowski

  • Administrator
  • Sr. Member
  • *****
  • Posts: 369
Re: viewport
« Reply #4 on: April 19, 2018, 09:05:28 AM »
I'm not sure how you mean that. Normally, Ovito doesn't "compute" these values. The user controls them when moving the viewport camera using the mouse. The only function that computes a new camera position is the "zoom all" function, which is automatically invoked after importing a new dataset in order fully show it.

You can invoke this function from Python too, see the Viewport.zoom_all() method.

Note that this function only translates the virtual camera until all objects in the scene become fully visible. The viewing direction and the FOV angle are not changed by the function.

Kevin

  • Newbie
  • *
  • Posts: 25
Re: viewport
« Reply #5 on: April 25, 2018, 06:04:43 PM »
Yes, zoom_all was what I meant to say. I should have clarified a little more when I asked the question. Thanks for clarifying.

I will report what I did wrong as follows in case other users encounter similar mistake:

So, zoom_all() has to be used after setting the viewing direction and the FOV angle.
1. set up viewing direction and FOV angle
2. zoom_all()

I used in the reverse order;
1. zoom_all()  #this sets up viewing position so that all system is viewed in current viewing direction and FOV angle.
2. set up viewing direction and FOV angle  #changing viewing direction and FOV angle here would result in previously set viewing position in step 1 obsolete.

Thanks again,
-Kyu