Jump to content

VTK in DelphiVCL or DelphiFMX

Recommended Posts

Hi all.
Recently I've been using VTK to manage 3D Views.
Unfortunately, I've found only info on how to use it with QT Pyside6 with QVTKRenderWindowInteractor.

I will hope to use DelphiVCL (my first choice) or DelphiFMX + VTK.
Do you have any idea on how to use VTK in a TForm or any other Windows-based window object?


Share this post

Link to post

I don't know VTK, but I don't think that is a revolutionary approach to "surface" drawing. In the web nothing about Pascal, Delphi or FPC related is available.

Surely it's needed a handle to a graphic window. And should be a function that assign this.


Start from here. If there is something about "C" or "MFC" sample, will be available usefull info.

Share this post

Link to post

I have not heard of VTK and decided to take a peak. The documentation references examples using MFC and C++ Builder. However, the Win32 folder is no longer present in the Examples\GUI folder in their git repo. Searching the history of the repo, the C++ Builder examples were removed five years ago. I suspect getting support for using VTK in Delphi will be challenging, since the group stopped supporting C++ Builder years ago. That said, the old code is available via git history. For example, vtkBorlandRenderWindow.cpp. This snippet is from GetRenderWindow:


    // Stuff the renderwindow into our window
    FRenderWindow = vtkWin32OpenGLRenderWindow::New();
    FRenderWindow->AddObserver( vtkCommand::AbortCheckEvent, FAbortCallback);

Without a deep dive into the source, it appears VTK is using OpenGL for rendering and setting the OpenGL's window parent to a form.


If I wanted to use VTK from Delphi, I would attempt:

  1. Use a supported open source C++ compiler to build the C++ source to either OBJ or LIB. There are multiple OBJ file formats. Delphi can link with OMF86 or COFF for 32-bit and ELF or COFF for 64-bit. See Link object file (Delphi) for more details.
  2. Translate the VTK headers to Pascal, which will be a challenge. From what little I have read, VTK appears to use features only available in newer versions of C++. There are some open source projects for converting headers, although they may not be able to convert the VTK headers. The second one specifically does not convert C++ headers. I included it because it uses libclang, which I suspect would provide a better translation for the "pure C" portions of headers.
    1. https://github.com/yunkot/HeaderParser
    2. https://github.com/neslib/Chet
    3. There are others. Search engines are your friends. ;) Well, most of the time.
  3. Another alternative is Python4Delphi, since VTK can be used from Python and appears to actively support use from Python. An advantage of this approach is the ability to "prototype" using standalone Python and then incorporate into a Delphi app via Python4Delphi. You have likely seen Pyscripter's posts in this forum.
    1. https://github.com/pyscripter/python4delphi

Share this post

Link to post

Yes, maybe I explained myself wrongly.
I am using Python + VTK + QT.
VTK is a very good Python library for working with 3D scenes.
QT is terrible for me and I love DelphiVCL e DelphiFMX UI for Python.
Unfortunately, to do the rest of the interface, I had to switch from Python4Delphi (DelphiVCL or DelphiFMX) to QT precisely because

there is a lack of coverage to OpenGL in them, and however, found no way to integrate VTK to DelphiVCL/DelphiFM.

So I was asking if anyone had already done this or could point me to how to create a VTK component that would appear in an area

of a Python DelphiVCL TForm, as in the example in the picture below.




Share this post

Link to post
2 hours ago, shineworld said:

I am using Python + VTK + QT.

LOL, I miss we are in a P4D section, sorry. I cannot help you , I never used Python4Delphi.

Share this post

Link to post
2 hours ago, DelphiUdIT said:

LOL, I miss we are in a P4D section, sorry.

Same LOL here. My first reply would have been much shorter had I paid attention to the forum. One of the dangers of reading from Recent Activity, I suppose. :classic_wink:

Share this post

Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now