Wednesday, June 13, 2007

Point and Line Plotter in VTK - A simple wrapper class

*Purpose: Beginners of VTK usually create a lot of actors for some primitive geometric objects (e.g. such as some simple points and lines). It is a waste to construct so many high level objects. Instead, we can always group multiple geometric primitives into a single actor. The rendering speed increases a lot when you do so.

I have created two simple wrapper classes to help us do the job. Their names are MyVTKPointPlotter and MyVTKLinePlotter. The classes are not well designed yet, but it works for many cases.

Sample usage:
// In demo.cpp

// Generate some random line and random points to plot
for (....)
{
pointPlotter.PlotPoint(....)
linePlotter.PlotLine(....)
}

// Add actors to the renderer
ren->AddActor(pointPlotter.CreateActor());
ren->AddActor(linePlotter.CreateActor());



(Please first follow the VTK installation guide to build VTK from source)




(P.S.) I haven't update this blog for almost a month. Sorry~

Tuesday, May 01, 2007

How to improve this blog?


The blog lanuches for about a month. The visiting rate is not good. I am busying with other stuff and unable to think of more interesting materials. I think that my materials are not interesting enough. What kind of things I should place here to make fun in VTK?

Thursday, April 19, 2007

Camera model in VTK

*Purpose: There are two wonderful examples to explain the camera model used in the VTK textbook. Unfortunately, they are in tcl scripts and not ready to run using C++. I have made some modifications and ported them to C++.

You can notice that we have only one version of roll (they are the same no matter you are at the camera position or at the focal point)!

(Please first follow the VTK installation guide to build VTK from source)



Sunday, April 15, 2007

Text output in VTK (2D and 3D)

*Purpose: VTK supports both 2D and 3D text rendering. For 2D, it usually uses vtkTextActor. We can control its font, shadow and display position (in 2D screen coordinates). For 3D, many possible options can be used. One favorable option is to use vtkVectorText with vtkLinearExtrusionFilter. It gives high-quality 3D text rendering.

(Please first follow the VTK installation guide to build VTK from source)




There major VTK classes are used in this demo: vtkTextActor, vtkVectorText, vtkLinearExtrusionFilter.

Friday, April 13, 2007

Examples package (ALL in C++)

Learning VTK in C++ may be difficult, because there are few C++ VTK examples with the standard source code package. Instead, it contains many tcl scripts which needs quite a lot of time to convert back to C++ source code.

I have written a converter to help the conversion. Here is the examples package (ALL in C++) that I have been ported. It contains more than 35 c++ examples.

(Please first follow the VTK installation guide to build VTK from source)
Examples package (ALL in C++):


Many examples in this pack need VTK data package. Please download it from http://public.kitware.com/VTK/get-software.php#latest and extract to any folder you preferred.

Then open project_config.h, locate the following source code and make changes

// In project_configure.h

#define VTK_DATA_ROOT "D:\\Users\\Peter\\bin\\VTKData\\Data\\"

// Change it into ...

#define VTK_DATA_ROOT <your VTK Data directory>

VTK: TCL script to C++ source code conversion

I have used C++ and FLTK to write up a simple tcl script to C++ source code converter. The conversion is quite primitive, but it saves me a lot of time to learn VTK.

Here is my test version of vtktcl2cpp converter (binary in Windows):


Features currently supported:

Simple GUI or Command line processing (vtktcl2cpp [in.txt] [out.txt] [header.txt])

Generate header files


Comments are welcomed!

Download VTK data

Besides download VTK source code from the VTK homepage, we can also download the VTK dataset to help us learning VTK.

http://public.kitware.com/VTK/get-software.php#latest

Multiple vtkRenderers

*Purpose: Create simple source objects. Demo the functionalities of multiple renderers.

(Please first follow the VTK installation guide to build VTK from source)





Many standard objects are used in this demo: cone, sphere, cube, disk, cylinder and arrow.

A simple interactive sphere in VTK

*Purpose: Create a simple sphere, users can interact with it.

(Please first follow the VTK installation guide to build VTK from source)






Basic interaction functionalities:

Mouse: zoom, pan, rotate...
'w': wireframe
's': surface rendering
'p': picking - highlight the bounding box of selected object
'+': increase resolution of the sphere
'-': decrease resolution of the sphere
'c': choose a random color for the sphere

Build VTK from source in Visual Studio

Here is the reference document on how to build VTK from source in Visual Studio and configure Visual Studio IDE



After you installed VTK and configure Visual Studio IDE. You can use this minimal project file to test your installation.