# Learning VTK, with a 3D graphics geometry mindset

Hi!

I’m struggling to understand both the Textbook and the User’s Guide PDFs, because my knowledge is very heavily 3D CG-focused (you know: mesh data, mesh animation, lighting/materials, etc), and while these two books of course treat 3D graphics concepts, they are considered like second-class citizens, with algorithms being the 1st-class citizen. This somehow makes me struggle to properly understand VTK.

Yes, I need algorithms, because for example I’m going to have scalar fields on a surface and I’m going to need to extract isocontours from them, or I’m going to need to render volumetric data, for example.

But however, in my mind, the 3D computer graphics data comes first. I mean: first I have the meshes, all the geometry that defines the model. Then I apply physical parameters to such geometry. Then I call my FEM analysis code. And later, as the last step in the pipeline, data algorithms are issued for visualization of the results. So, in my pipeline, 3D geometry is the 1st-class citizen, and algorithms are 2nd-class. I think this is what is making me struggle to understand VTK. Other subtleties like the difference between readers and importers make me find more difficulties (yes, I understand a reader reads the data into VTK objects, while the importer makes some sort of a blackbox hiding the actual data, but I don’t get the point on why readers cannot read textures and materials, because VTK does have classes for that).

The key concept here is that I want to directly attach my FEM analysis code to the VTK geometry data. I don’t want the data to be duplicated.

And obviously, many questions come to my mind: How should you create a 3D triangle (and quad) mesh in VTK? Should it be a vtkUnstructuredGrid? Or a vtkPolyData? Should it be a vtkPolyhedron if the mesh must be watertight, non-self intersecting, and manifold? And what class should it be if the mesh will be open instead? Does VTK have functions that can automatically check if a mesh meets the vtkPolyhedron requirements and thus construct a vtkPolyhedron from an arbitrary mesh? Can all these classes have texture coordinates assigned? And how do skinning and morphed mesh animation come into the figure? Can you apply skinning to a vtkPolyhedron? What if a skinning or morphing animation makes the vtkPolyhedron self-intersect? Can it be detected?

As you see, my mind is centered in geometry, geometry, geometry… and won’t consider any data field algorithms for visualization until geometry is clearly defined and established.

So, is there any other book, or tutorial, that could help me to learn VTK by going first into these topics, which are my first goals? (I first need to connect my FEM code to geometry data, and only later I’ll consider data visualization algorithms).

Thanks!!

Cesss

VTK’s main focus has been mostly generating data for scientific/medical/engineering visualization (with special features, like generating meshes from images, streamlines from vector volumes, mixed volumetric and surface rendering, etc.) and this is appropriately reflected in the VTK textbook. In recent years, animation, texture, lighting features have been greatly improved, but these are not described in the textbook.

Since you are already familiar with CG concepts, the VTK textbook should give you a new perspective. You may need to read the book a few times and study VTK examples to develop full understanding of all details. If some questions remain unanswered then you can ask here in the forum.

If you could contribute to the VTK textbook (with proposals for what to change where, write a new CG-focused chapter, etc.) then it would be greatly appreciated.

1 Like

Thanks a lot, Andras. Yes, I think you gave me a very good advice. I believe my post was consequence of getting nervous because the VTK books contents were not “Chapter 1 - The Mesh”, “Chapter 2 - Mesh transformation and operations”, “Chapter 3 - Rendering the Mesh”

But now, more calmed, I began to find examples closer to my needs around page 105 in the User’s Guide. And, just like you said, by looking at examples I think I’ll be understanding things better.

My needs obviously come from a different starting point than VTK´s. It could be argued that I should look at rendering engines instead (like OSG, OGRE, or Godot), but I’m working in FEM research, and I need to visualize FEM results, so VTK is going to be the right choice (not to mention the better compatibility with other FEM tools if I use VTK).

My challenge now is to be preparing an skeleton app ready for the type of models I’ll be working with, and gluing my FEM code to directly access the VTK geometry. I wish to include animated models from the beginning, with skinning and morphing, because I’m going to apply FEM in animated situations, so I’d better have it ready from the beginning.

Yes, if I face questions I’ll ask them here. Thanks!

1 Like

You might consider looking into VTK-based open-source applications that do something similar to what you need and enhance/customize those instead of starting from scratch.

An obvious option would be Paraview, which is very actively developed, utilizes latest VTK features, and has lots of option for FEM mesh visualization, and designed to be customizable/extensible via plugins.

If you need to do highly realistic modeling of human soft tissue deformation (not just skin surface but internal organs, etc.) then you may have a look at Bender2 (based on 3D Slicer, which is also very actively developed, used very widely for medical applications, and also highly customizable/extensible).

1 Like

I didn’t know about Bender2! Thanks a lot for telling! The fact it has BVH motion capture import is also of great help! My use of skinning and morphing is going to be different from Bender2 though, but looking at how things were implemented in Bender2 is going to help a lot. Thanks!!

It would be great if you end up working on Bender2. It may require some work to bring it up to date but it’s a cool system. We have a project that could benefit from it (https://projectweek.na-mic.org/PW31_2019_Boston/Projects/ClubfootCasts/). We’ve been thinking we might end up using Bender2 for this.

It would be great if you end up working on Bender2

I don’t think I’ll work on the same source, because I don’t actually need its features, but just skinning, and morphing (and let’s add BVH import into the wagon). So, it’s going to be more of studying the part of the Bender2 source where it does these things.

If you find some VTK classes in Bender2 useful then you could put them in a VTK remote module (or even send a pull request to merge into VTK proper) to share (or off-load) workload of further development and maintenance of those classes.

Ok

@cesss just curious, did you end up implementing any of this?