質問

Background

I'm trying to implement a highly non-linear lens to do lens distortion in Panda3D for a complex projection setup. I want to use this implementation following this approach.

The question

Can I do it in Python (and if so, how, what am I doing wrong) or do I have to do it in C++ (and if so, where do I start)?

Attempts so far

I've tried subclassing Lens, but if I let my subclass call the super constructor (or don't override the constructor at all), I get an error:

>>> from panda3d.core import Lens
>>> class MyLens(Lens):
...    def __init__(self):
...       super(MyLens,self).__init__()
... 
>>> l = MyLens()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "<stdin>", line 3, in __init__
TypeError: Error Can Not Init Constant Class (Lens)

If I don't call the super constructor, the class isinstance(Lens), but not recognized as such by Panda3D code:

fcamNode = Camera('fcam')
flens = MyLens.MyLens()
assert isinstance(flens, Lens)
fcamNode.setLens(flens)

results in TypeError: LensNode.set_lens() argument 1 must be Lens, not MyLens.

If I subclass PerspectiveLens instead, I can call the super constructor and pass instances of my class to setLens(), but none of its overridden methods are ever called and the rendered scene looks like it was rendered with the stock PerspectiveLens.

役に立ちましたか?

解決

That is all coded in C++, i.e. the Lens class is internally a C++ class and all the other classes are also C++ classes which overload the C++ Lens class.

If you overload such Python-wrapped class and pass that object down to some C++ code again, the C++ code wont recognize the Python overwriting.

You might be able to write a C++ Lens superclass which is able to do that, i.e. which implements all possible virtual functions and in all cases, always looks up wether there is a related Python object attribute which can be called. Note that this is likely to be slow.


In C++, you find the definition of Lens here and here.

Take a look at the FisheyeLens here to see what functions you have to overwrite from Lens.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top