Closed LuigiNixy closed 3 months ago
Hi @LuigiNixy,
ScalarTransform*
and Transform*
types are the scalar and JIT-type counterparts.
| Why there isn't a simple function or a constructor that can convert one type to the other?
From the direction of ScalarTransform
to Transform
there are constructors, with the caveat that the value types have to match .e.g from ScalarTransform3d -> Transform3d
. So you can do something like mi.Transform3f(mi.ScalarTransform3f())
There is however one slight gotcha in all of this. Historically, the Properties
that are provided to a plugin needed to be variant-agnostic. The result is that with regards to scalar transform properties, these are always promoted to double-precision. So in your example props.get('to_world')
is actually of type ScalarTransform4d
and so for instance
self.m_to_world = mi.Transform4f(props.get('to_world', mi.Transform4f()))
won't work because there are no bindings to initialize a Transform4f
from a ScalarTransform4d
. However,
self.m_to_world = mi.Transform4d(props.get('to_world', mi.Transform4d()))
would work and alternatively, intializing your transform from a matrix
self.m_to_world = mi.Transform4f(props.get('to_world', mi.Transform4f()).matrix)
should similarly work.
As a side note, shouldn't m_to_world
from the parent class (Endpoint
) be used instead of re-declaring it in the Python plugin?
Thanks so much @rtabbara. The problem is solved.
Hi, @merlinND. I have tried to use it directly, but it‘s just not there.
Summary
I need to convert type "mi.ScalarTransform4d" to "mi.Transform4f" in my own emitter plugin.
System configuration
System information:
OS: Linux Mint 21.3 CPU: Intel(R) Core(TM) i7-6700 CPU @ 3.40GHz GPU: Quadro P5000 Python: 3.10.12 (main, Jul 29 2024, 16:56:48) [GCC 11.4.0] NVidia driver: 535.161.07 LLVM: 15.0.7
Dr.Jit: 0.4.4 Mitsuba: 3.5.0 Is custom build? True Compiled with: Clang 13.0.1 Variants: scalar_rgb cuda_ad_rgb llvm_ad_rgb scalar_rgb_polarized scalar_mono_polarized cuda_ad_mono_polarized llvm_ad_mono_polarized cuda_mono_polarized llvm_mono_polarized llvm_ad_spectral_polarized cuda_ad_spectral_polarized
Description
I am trying to write an emitter plugin that can emits polarized light. And it begins with the code below:
And I use the python dict to create an instance:
This results in the parameter "to_world" having the type "mi.ScalarTransfrom4f". However, I wish it could be type "mi.Transform4f". Simply changing the type in the dict like below:
will generate the following error:
For in-built emitter plugin, such as the type "spot" emitter, the type of its "to_world" parameter will automatically be cast to "mi.Transform4f". I wonder how that is done so that I can convert the type of the parameter in my own plugin to "mi.Transform4f". Besides, I also want to know more about the differences between the two types, They look like very similar to each other. Why there isn't a simple function or a constructor that can convert one type to the other?
I appreciate anyone that can help.
Steps to reproduce
Just use my code.