Home › Forum › SOFA › Using SOFA › Setting camera position/orientation with SofaPython
Tagged: 64_bits, Plugin_SoftRobots, SOFA_1906, Windows_10
- This topic has 8 replies, 5 voices, and was last updated 3 years, 8 months ago by Scheikl.
-
AuthorPosts
-
16 December 2020 at 01:06 #18031JoshuaBlocked
Hi,
I’m having a bit of trouble figuring out how to modify the camera position/orientation. In the scene below, changing the parameters of the
InteractiveCamera
doesn’t do anything, and the object doesn’t show up at all in theOglViewport
. I assume I’m screwing up something basic and would appreciate any help!from stlib.scene import MainHeader, ContactHeader, Scene from stlib.physics.rigid import Cube import Sofa def createScene(rootNode): scene = Scene(rootNode, plugins=["SofaSparseSolver"]) Cube(rootNode, uniformScale=0.001) rootNode.createObject("InteractiveCamera", name="baseCamera", position="-0.00257779 -0.00358703 0.000986644", orientation="0.588126 -0.212397 -0.213083 0.750727", lookAt=[2.5, 5, 0], distance=100000, minBBox=[-5, 0, -8.66], maxBBox=[10, 10, 8.66], widthViewport=190, heightViewport=552) rootNode.createObject("OglViewport", name="view", screenPosition="0 0", screenSize="250 250", cameraPosition="-0.00257779 -0.00358703 0.000986644", cameraOrientation="0.588126 -0.212397 -0.213083 0.750727")
Thank you very much,
Josh10 January 2021 at 13:14 #18168beichunBlockedI would also like to know any suggestions on this (I’m using SofaPython3)!
14 January 2021 at 09:38 #18210HugoKeymaster14 January 2021 at 12:23 #18217beichunBlockedI found that I have to use the opengl viewer (Sofa.Gui.GUIManager.Init(“MyScene”, “qt)) in order to make the interactiveCamera work.
However, I still cannot set the right camera orientation. I received the following warning:
[WARNING] [InteractiveCamera(camera)] Could not read value for data field orientation: array([0.70710678, 0. , 0. , 0.70710678])
The code I used to set the camera is:
from scipy.spatial.transform import Rotation as R cam_lookAt = [0, 0, 0] cam_orientation = R.from_euler("x", np.pi/2).as_quat() self.root.addObject("InteractiveCamera", name="camera", orientation=cam_orientation, lookAt=cam_lookAt, distance=100, fieldOfView=66, zNear=-10, zFar=55.69)
Any advice?
14 January 2021 at 13:47 #18221jnbrunetModeratorHey @beichun
Indeed, you have to use the Qt viewer since the QGLViewer has its own internal camera.
For your error with the orientation, the data has to be converted to a python list. In your code, simply change
cam_orientation = R.from_euler("x", np.pi/2).as_quat()
tocam_orientation = R.from_euler("x", np.pi/2).as_quat().tolist()
.J-N
15 January 2021 at 07:17 #18233beichunBlockedIt works nicely. Thank you!
I want to ask another question, how do I set the up direction of camera? Although my orientation is correct, the rendered view is upside down.
16 January 2021 at 21:16 #18239HugoKeymaster16 January 2021 at 21:51 #18240ScheiklBlockedHi!
I have a related problem.
I am able to control the internal data of aninteractiveCamera
, but it does nothing to the view itself, even though I made sure I am using the OpenGL view.You can find a video of the behavior here: https://cloud.ipr.kit.edu/s/y2tjFW2Za4CX5p2
The code to set the pose is
def move_cam(camera, pose: Tuple[float, float, float, float]): camera.position.value = pose[:3] camera.orientation.value = pose[3:]
SOFA: v2012_beta
SP3: masterCheers,
Paul16 January 2021 at 22:19 #18241 -
AuthorPosts
- You must be logged in to reply to this topic.