vedo icon indicating copy to clipboard operation
vedo copied to clipboard

Animation: inconsistent camera parameters between the play() function and values obtained from typing 'C' key

Open XushanLu opened this issue 2 years ago • 4 comments

Hi @marcomusy,

I've got another issue for you with the Animation class. I observed that the camera parameters from directly printing inside the play function is different from what I obtained by pressing C key with my keyboard.

For example, the following code simply rotates the body 180 degrees along the z-axis. I can print out the camera parameters by adding all the print lines before self.show in the play function in the Animation class:

            if dt > self.eps:
                print(self.camera.GetPosition())
                print(self.camera.GetFocalPoint())
                print(self.camera.GetViewUp())
                print(self.camera.GetClippingRange())
                print(self.camera.GetDistance())
                self.show(interactive=False, resetcam=self.resetcam)

When the rotation finishes, I press C to get camera parameters, and they are different. The last values printed are

(-653227.8500875884, -6233719.241304105, 1505.5680089146688)
(-653227.8500875884, -6233719.241304105, 9.46603775024414)
(0.0, 1.0, 0.0)
(1313.4217270188815, 1729.6674490770752)
1496.1019711644246

and the values obtained by pressing C are

plt.camera.SetPosition( [-555720.156, -6243167.25, 1485.5] ) \n
plt.camera.SetFocalPoint( [-555720.156, -6243167.25, 9.466] )\n
plt.camera.SetViewUp( [0.0, 1.0, 0.0] )
plt.camera.SetDistance( 1476.034 )
plt.camera.SetClippingRange( [1293.555, 1709.299] )

Here is the code I used:

#!/usr/bin/env python3

import numpy as np
from vedo import TetMesh, show, screenshot, settings, Picture, buildLUT, Box, \
    Plotter, Axes
from vedo.applications import Animation

import vtk
import time as tm

from vedo import settings

settings.allowInteraction=True

# Do some settings
settings.useDepthPeeling=False  # Useful to show the axes grid
font_name = 'Theemim'
settings.defaultFont = font_name
settings.multiSamples=8
# settings.useParallelProjection = True # avoid perspective parallax

# Create a TetMesh object form the vtk file
ovoid_tet = TetMesh('final_mesh.1.vtk')
host_tet = ovoid_tet.clone()

# This will get rid of the background Earth unit and air unit in the model
# which leaves us with the central part of the model
ovoid_tet.threshold(name='cell_scalars', above=1, below=1)
host_tet.threshold(name='cell_scalars', above=2, below=2)

# Crop the entire mesh using a Box object (which is considered to be a mesh
# object in vedo)
# First build a Box object with its centers and dimensions
cent = [555700, 6243165, 100]
box = Box(pos=cent, size=(4000, 4000, 3000))
# So, we now cut the TetMesh object with a mesh (that Box object)
# host_tet.cutWithMesh(box, wholeCells=True)
host_tet.cutWithMesh(box, wholeCells=False)

# And we need to convert it to a mesh object for later plotting
ovoid = ovoid_tet.tomesh().lineWidth(1).lineColor('w')
host = host_tet.tomesh(fill=False).lineWidth(1).lineColor('w')

# We need to build a look up table for our color bar, and now it supports
# using category names as labels instead of the numerical values
# This was implemented upon my request
lut_table = [
    # Value, color, alpha, category
    (1.0, 'indianred', 1, 'Ovoid'),
    (1.5, 'lightgray', 1, 'Host'),
]
lut = buildLUT(lut_table)

host.cmap(lut, 'cell_scalars', on='cells')
ovoid.cmap(lut, 'cell_scalars', on='cells')

# Set the camera position
plt = Animation(videoFileName=None, showProgressBar=False)

# size = [3940, 2160]
size = [2560, 1600]
plt.size = size

# # Trying to play with the Animation class
# plt.showProgressBar = True
plt.timeResolution = 0.01  # secs

# Fade in the ore body
plt.fadeIn(ovoid, t=0, duration=0.5)

# Rotate the ovoid body
plt.rotate(ovoid, axis='z', angle=180, t=0.5, duration=2)

plt.play()

Again, here is the data: final_mesh.1.vtk.zip

My plan was to move the camera from the endpoint after the rotation to something else. But it turned out I could not do it possibly because of this inconsistency. Any ideas?

XushanLu avatar Nov 19 '21 19:11 XushanLu

Hi Xushan - this Animation class is pretty old and needs an in-depth revision... I'll only be able to look at this in 1-2 weeks... meanwhile if you are in a hurry I would suggest to modify the camera manually in a loop. Sorry about that and thanks for your feedback, I'll let you know anyways when I get some results on this!

marcomusy avatar Nov 23 '21 12:11 marcomusy

Hi Marco,

I've been doing things by modifying the applications.py file and I've made an animation that serves my need. The only thing I think I actually needed was to make resetcam to be always False for the moveCamera function, and I am now only using that function. It's just adding more camera positions to the movement series but it worked. Please fix this whenever you have time. I am interested to read the source code further down the road to see whether I can help more than just reporting issues. Thanks very much!

XushanLu avatar Nov 23 '21 14:11 XushanLu

sounds good! If you like you can make a push request with your new application.py

marcomusy avatar Nov 24 '21 11:11 marcomusy

Unfortunately, making it False would make other functions stop working although moveCamera does work with that. I think it is related to something deeper in the Plotter.show() function but I am not sure.

XushanLu avatar Nov 24 '21 13:11 XushanLu