mitsuba2
mitsuba2 copied to clipboard
Extract far clip value of a sensor(perspective camera) using python API
❔ other question
Summary
I would like to assign my sensor's far clip value to a variable (maximum distance). I am using a perspective camera and python API for writing my program.
System configuration
- Platform: windows
- Python version: 3.9
- Mitsuba 2 version: latest
- Compiled variants:
-
scalar_rgb
- packet_rgb
-
Description
The required scene is loaded and the sensor(perspective camera) displays the far_clip value as shown in the below figure
But I'am unable to extract it and assign it to a variable.
I do not find any method in the API that returns the far clip value. I also tried to print it from ProjectiveCamera class of the render but I am not able to create an object of that class so unable to use its methods.
Please help me with a python snippet for doing the same.
What I want to do is something like : max_distance = sensor.far_clip() ; so that my max distance value is 100(sensor far_clip value in the above picture)
Steps to reproduce
- python API
- all necessary imports
- load the XML scene by scene = load_file(filename)
- extract the sensor details from the scene by sensor = scene.sensors()[0]
- extract the far clip value from it
Hi @pratheeka171 ,
Looking at test01_create
in src/sensors/tests/test_perspective.py
it looks like sensor.far_clip()
should work. Are you saying that this is broken on your end?
You can access the sensor of a scene like this:
import mitsuba
mitsuba.set_variant("scalar_rgb")
from mitsuba.core import xml
scene = xml.load_file("path/to/my_xml_file.xml")
sensor = scene.sensors()[0]
far_clip = sensor.far_clip()
or you can instanciate your own sensor using xml.load_dict()
:
sensor = xml.load_dict({
"type": "perspective",
"near_clip": 1.0,
"far_clip": 35.0,
"focus_distance": 15.0,
"fov": fov,
"fov_axis": fov_axis,
"shutter_open": s_open,
"shutter_close": s_close,
"to_world": ScalarTransform4f.look_at(
origin=o,
target=t,
up=[0, 1, 0]
),
"film": {
"type": "hdrfilm",
"width": 512,
"height": 256,
}
})
far_clip = sensor.far_clip()
@Speierers I am unable to acess that method as it does not exist for me. I have cloned the latest version of mitsuba2. Please have look at the error I get in the following picture.
I see, this is because sensor
has the type mitsuba.render.Sensor
and not mitsuba.render.ProjectiveCamera
. Ideally you should be able to downcast to that specific type, or pybind11 should be able to do it automatically, but for some reason this is not happening.
I will see what is the best fix for this, but to be honest, this is going to have to wait as we are already busy with other tasks.
In the mean time you can use this hacky solution:
from mitsuba.render import ProjectiveCamera
sensor = scene.sensors()[0]
sensor.__class__ = ProjectiveCamera
far_clip = sensor.far_clip()
I will leave this issue open as a reminder that this needs a proper fix.
@Speierers thank yu for the work around. I will be looking forward for the best fix.