[vtk-developers] Implementing my own camera class and wrapping it to Python
David Gobbi
david.gobbi at gmail.com
Tue Mar 19 13:15:32 EDT 2013
On Tue, Mar 19, 2013 at 10:55 AM, Skotheim , Oystein
<oystein.skotheim at tecnalia.com> wrote:
> Hello. I am trying to use VTK for Augmented Reality. I need to be able
> to manipulate the projection and modelview transform directly, and I
> could not find a convenient way to do it with vtkCamera or
> vtkOpenGLCamera (Is there any way to do it?).
>
> For that reason, I have tried to implement a new camera class:
> vtkOpenCVCalibratedCamera, which basically is a copy of vtkOpenGLCamera
> but it contains functionality for setting the projection and model view
> matrices directly. I have gotten this to work in C++ now.
>
> I would also like to be able to access this from Python. I tried to copy
> vtkOpenCVCalibratedCamera.{cxx,h} into the Rendering directory of the
> VTK source distribution, and then I appended vtkOpenCVCalibrated.cxx to
> the KitOpenGL_SRCS variable in the Rendering/CMakeLists.txt file. I am
> able to compile VTK including the Python wrapper and obtain a vtkpython
> file. However, when I try to import vtk I get the following error:
>
> oystein at prtgb370:~/src/VTK-5.8.0/build/bin$ ./vtkpython
> vtk version 5.8.0
> Python 2.7.3 (default, Aug 1 2012, 05:27:35)
> [GCC 4.6.3] on linux2
> Type "help", "copyright", "credits" or "license" for more information.
> >>> import vtk
> Traceback (most recent call last):
> File "<stdin>", line 1, in <module>
> File
> "/home/oystein/src/VTK-5.8.0/build/Wrapping/Python/vtk/__init__.py",
> line 76, in <module>
> __helper.refine_import_err('hybrid', 'vtkHybridPython', exc)
> File
> "/home/oystein/src/VTK-5.8.0/build/Wrapping/Python/vtk/__helper.py",
> line 32, in refine_import_err
> raise LinkError, str(exc)
> vtk.__helper.LinkError:
> /home/oystein/src/VTK-5.8.0/build/bin/libvtkRenderingPythonD.so.5.8:
> undefined symbol:
> _ZN25vtkOpenCVCalibratedCamera14UpdateViewportEP11vtkRenderer
>
> Do you have any idea why this error is occurring? (My class contains an
> UpdateViewport method both in the header and the implementation file).
As you've guessed, this error occurs when you have declared a method but
have not provided a definition. It also occurs if your LD_LIBRARY_PATH
is set incorrectly, i.e. if you have some old .so files in the path.
> BTW. Is there any way I can add a Python interface to my new class
> without having to recompile the entire VTK? I tried to add a Python
> interface with SWIG, but I am unable e.g. to pass this
> vtkOpenCVCalibratedCamera (in vtk_extensions.pyd) to a vtkRenderer
> (contained in the main vtk Python wrapper). I guess this is not the way
> to do it, but where can I find information about how to wrap my class
> properly for Python?
The file VTK/Wrapping/Python/README_WRAP.txt will provide some basic
information. The VTK wrappers are completely independent of SWIG.
They automatically generate the python interface from your class
header file.
- David
More information about the vtk-developers
mailing list