VTK: Difference between revisions

From KitwarePublic
Jump to navigationJump to search
No edit summary
Line 62: Line 62:
* How do you fit a quadric surface to a set of points?
* How do you fit a quadric surface to a set of points?


==Example Usage (C++)==
These are fully independent, compilable examples. There is significant overlap in the examples, but they are each intended to illustrate a different concept and be fully stand alone compilable.


Please add examples in your areas of expertise!
===System Configuration/General Information===
* [[Which Libraries Do I Link To?]]
* [[Which Header Files Do I Include?]]
* [[Typical CMakeLists.txt file]]
* [[Environment Setup]]
* [[http://scv.bu.edu/documentation/tutorials/VTK/#INTRO A nice tutorial]]
===Preliminaries===
* [[Smart Pointers]]
* [[vtkIdType]]
* [[Casting VTK objects]]
===Wrapping===
* [[VTK/Java Wrapping|Java]]
* [[Python Wrapping FAQ|Python]]
===Simple Operations===
* [[Distance between two points]]
* [[Random number (uniform distribution)]]
* [[Random number (Gaussian distribution)]]
===Input and Output===
====Input====
* [[Read a simple "xyz" file of points]]
* [[Read a plain text file into a polydata]]
* [[Read a delimited file into a polydata]]
* [[Read a VTU file]]
* [[Read an OBJ File]]
* [[Convert a series of DICOM files into a VTI File]]
* [[VRML (WRL)]]
* [[Read DICOM file]]
====Output====
* [[Write a VTU file]]
=== Geometric Objects ===
In this section, the object is created, added to a polydata object, then written to a .vtp file. The file can be opened in Paraview to see the result.
* [[Point]]
* [[Line]]
* [[Add colored lines to a Polydata]]
* [[Plane]]
* [[Triangle (on large point array)]]
* [[Triangle (self contained)]]
* [[Sphere]]
* [[Cube]]
* [[Polygon]]
=== Working with 3D Data (vtkPolyData) ===
* [[Convex hull]]
* [[Check if a point is inside an object]]
* [[Check if a point is inside an object (alternate method)]] - this uses a Delaunay triangulation to compute a volume. This gives more of an "is inside convex hull" effect than an "is inside object"
==== Input/Output (Reading/Writing) ====
* [[Read a .vtp file]]
* [[Write a .vtp file]]
==== Geometry and Topology - Adding Points and Shapes to Polydata ====
A big confusion among VTK beginners is "I added points to my file - why are there no points when I visualize it??". VTK strongly divides GEOMETRY from TOPOLOGY. What most users would think of as "points" are actually "points + vertices" in VTK. The geometry is ALWAYS simply a list of coordinates - the topology represents the connectedness of these coordinates. If no topology at all is specified, then, as far as VTK is aware, there is NOTHING to show. If you want to see points, you must tell VTK that each point is independent of the rest by creating a vertex (a 0-D topology) at each point. The following examples use a triangle to demonstrate a step at a time how to add geometry and topology to polydata.
* [[Triangle - Geometry only]] - Create a polydata consisting of the three corners of a triangle. There is nothing to visualize as there is no topology.
* [[Triangle - Geometry + Vertices]] - Create a polydata consisting of the three corners of a triangle. A vertex is added at each point so there is now 3 "points" for the user to see. This is 0-D topology.
* [[Triangle - Geometry + Lines]] - Create a polydata consisting of three corners of a triangle. A line is added between each point. This is 1-D topology.
* [[Triangle - Geometry + Polygon]] - Create a polydata consisting of three corners of a triangle. A polygon (in this case, a triangle) is added on the three points. This is 2-D topology.
==== Adding Colors to Polydata ====
* [[Colored Points]] - Add three points to a polydata and associate a color with each of them.
* [[Triangle - Colored Points]] - Set the color of each point of a triangle. You will be able to interpolate the colors across the triangle.
* [[Triangle - Solid Color]] - Create a solid colored triangle.
==== Adding Normals to Polydata ====
* [[Add/Get Normals to/from a Cells in a Polydata]]
* [[Add/Get Normals to/from a Points in a Polydata]]
==== Non-standard Data ====
These examples show how to attach your own, nonstandard fields to every point or cell in a polydata.
* [[Add Miscellaneous Data to Points in a Polydata]]
* [[Get Miscellaneous Data from Points in a Polydata]]
* [[Add Miscellaneous Data to Cells in a Polydata]]
* [[Get Miscellaneous Data from Cells in a Polydata]]
==== Point cloud operations ====
* [[Downsample a point cloud]] - remove points so that there are no points within a tolerance of any point.
==== Miscellaneous (Field) Data ====
Three types of data can be stored in a polydata object, PointData, CellData, and FieldData. For PointData, there must be a piece of data associated with each point (e.g. a temperature data array with the temperature at each point). For CellData, there must be a piece of data associated with each cell (e.g. the area of each triangle). For data that does not align with either points or cells, FieldData should be used. This is typically data that describes the dataset as a whole. An example could be the name of the dataset, or the center of mass of the points, etc.
* Using FieldData [[Add Global Miscellaneous Data to a Polydata]]
==== Global Operations on PolyData ====
* [[Extract Normals from a Polydata]]
* [[Get the names of all of the data arrays]]
* [[Determine data types of arrays]]
* [[Embed points into a volume]]
=== Working with Stuctured (grid aligned) 3D Data (vtkImageData) ===
* [[Iterating over a vtkImageData]]
* [[Structured Grid]]
===Utilities===
* [[Color Lookup Table]]
* [[Construct a Table]] - A table is a 2D array of any type of elements. They do not all have to be the same type. This is achieved using vtkVariant.
* [[Delaunay Triangulation (2D)]] - Perform a 2D Delaunay triangulation on a point set.
* [[Constrained Delaunay Triangulation (2D)]] - Perform a 2D Delaunay triangulation on a point set respecting a specified boundary.
* [[Compute eigenvalues and eigenvectors of a symmetric matrix]]
* [[Known Length Array]]
* [[Unknown Length Array]]
* [[Array of Vectors (Known Length)]]
* [[Array of Vectors (Unknown Length)]]
* [[2D Array]]
* [[Custom type 2D Array]]
* [[Determine the type of a VTK variable]]
* [[Screenshot]]
* [[Least Squares]]
* [[Homogeneous Least Squares]]
* [[Quadric Surface Fitting]]
===Graphs===
* [[Construct a graph]]
* [[Minimum spanning tree of a graph]]
* [[Depth First Search iterator]]
* [[Visualize a graph]]
* [[Label vertices and edges]]
* [[Find Connected Components]]
* [[Convert a graph to a PolyData]]
===Data Structures===
* [[KDTree]]
* [[Create a KDTree]]
* [[KDTree - Closest Point]]
* [[KDTree - Closest Point (vtkKDTreePointLocator)]]
* [[KDTree - Closest N Points]]
* [[OBBTree]] - Oriented Bounding Box Tree
* [[Generate a mesh of each level of a KDTree]]
* [[Generate a mesh of each level of an OBBTree]]
===Filters===
* [[Apply a Transformation to Points]]
* [[Landmark Transform]]
* [[Iterative Closest Points (ICP) Transform]]
* [[Triangulate a Terrain Map]]
* [[Create a surface from Unorganized Points]]
* [[Create a surface from Unorganized Points (Gaussian Splat)]]
* [[Create models from labeled volume data (Discrete MarchingCubes)]]
* [[Create cubes from labeled volume data]]
===Visualization===
See [[http://www.cs.uic.edu/~jbell/CS526/Tutorial/Mappers.html this]] for a brief explanation of the VTK terminology of mappers, actors, etc.
* [[Visualize a Sphere]]
* [[Visualize a VTP File]]
* [[Visualize a 2D Set of Points]]
* [[Display coordinate axes]]
* [["Trackball" mode]]
* [[Display text]]
* [[Texture map a plane]]
* [[Texture map a quad]]
* [[Moving an Actor]]
* [[Moving the Camera]]
* [[Multiple Actors]]
* [[A little bit easier rendering]]
* [[Hide an actor]]
* [[Hide all actors]]
===User Interaction===
* [[Handle keypress events]]
* [[Handle mouse events]]
===Selecting in 3D (Picking)===
* [[Plane Picking]]
===Working with Images===
* [[Read/Write JPG]]
* [[Read/Write PNG]]
* [[Display a static image]] - this will display the image, but not allow you to interact with it.
* [[Visualize and interact with an image]]
* [[Select a region of the window]]
===Working with Meshes===
* [[Decimation]] - Reduce the number of triangles in a mesh.
* [[Subdivision]] - Increase the number of triangles in a mesh.
* [[Finding Boundary Edges]] - Find the edges that are used by only one face.
===Using VTK Classes as Member Variables===
* [[Non-SmartPointer Member Variable]]
* [[Non-SmartPointer Template Member Variable]]
* [[SmartPointer Member Variable]]
===Widgets===
* [[Slider]]
===Needed/Missing Examples!===
* vtkVolumeRayCastMapper - any example of raycast/volume rendering


==Example Usage (Python)==
==Example Usage (Python)==

Revision as of 21:49, 19 November 2009

vtk-logo2.jpg
The Visualization ToolKit (VTK) is an open source, freely available software system for 3D computer graphics, image processing, and visualization used by thousands of researchers and developers around the world. VTK consists of a C++ class library, and several interpreted interface layers including Tcl/Tk, Java, and Python. Professional support and products for VTK are provided by Kitware, Inc. (www.kitware.com) VTK supports a wide variety of visualization algorithms including scalar, vector, tensor, texture, and volumetric methods; and advanced modeling techniques such as implicit modelling, polygon reduction, mesh smoothing, cutting, contouring, and Delaunay triangulation. In addition, dozens of imaging algorithms have been directly integrated to allow the user to mix 2D imaging / 3D graphics algorithms and data.


Documentation Improvement

(If you agree with the following, vote for the improvements!!)

In my experience, the single most important factor that influences a users attitude about a software package is its ease of use. VTK provides a phenomenal collection of tools for scientific data processing and visualization. However, if a user has difficulty accessing these tools, their experience with, and therefore opinion of, the software will be less than satisfactory. Documentation is the key element which controls this difficulty level. I propose some improvements to the documentation system here.

Here are some "easy" documentation fixes:

vtkMath

  • Pi, DoubleTwoPi, DoublePi all just say "useful constants. Maybe they could say something like "2 * 3.14159..." or 2 *\pi or something like that?
  • DegreesFromRadians says "Useful constants". This is incorrect. It should explain the conversion along with specify if there are/aren't bound on the input.
  • DoubleDegreesToRadians says "useful constants". This is incorrect.
  • DoubleRadiansToDegrees says "useful constants". This is incorrect.
  • Round(double) says "useful constants". This is incorrect.
  • Floor() has no documentation at all.
  • Outer(double, double, double) says "useful constants". This is incorrect.
  • Norm(double, int) says "useful constants". This is incorrect.
  • Perpendiculars(double, double, double, double) says "useful constants". This is incorrect. x,y,z, and theta must be explained.
  • Outer2D says "useful constants". This is incorrect.
  • Determinant2x2(double, double) says "Useful constants". This is incorrect.
  • LUFactor3x3(double, int) says "useful constants". This is incorrect.
  • LUSolve3x3(double, int,double) says "useful constants". This is incorrect.
  • LinearSolve3x3(double,double,double) says "useful constants". This is incorrect.

The list goes on....

vtkKdTree

  • TimingOff() says "turn ON timing"
  • SetTiming(int) says "turn on timing". It should say "turn on timing and set the interval (of what?) to the input X (the input variable is not named - also a problem).
  • GetTiming says "turn on timing". This is incorrect.
  • GetMinCells() says "turn on timing". This is incorrect.
  • SetNumberOfRegionsOrLess has no documentation.
  • SetNumberOfRegionsOrMore has no documentation.
  • SetFudgeFactor has no documentation.
  • RemoveDataSet says "Turn on timing". This is incorrect.
  • PrintVerboseTree says "Turn on timing"
  • All CreateCellLists functions have no documentation.
  • GetIncludeRegionBoundaryCells/On/Off say "turn on timing". This is incorrect.
  • GetCellLists functions say "turn on timing". This is incorrect.
  • GetRegionContainingCell says "turn on timing". This is incorrect.
  • BuildLocatorFromPoints(vtkPoints) says "turn on timing". This is incorrect.

The list goes on...

vtkLandmarkTransform

  • SetTargetLandmarks/SetSourceLandmarks - both of these have the same description. One should talk about the target only and the other should talk about the source only.
  • GetSource/TargetLandmarks - same description as the Set* methods. This is incorrect.
  • SetModeToRigidBody has the same desciption as SetSourceLandmarks. This is incorrect.
  • SetModeTo* has the same description as SetSourceLandmarks. This is incorrect.
  • GetMTime - says "Get the MTime". What is MTime? Modification time? Maybe "Get the time at which the object was last modified."

vtkDecimatePro

Add this:

The SetTargetReduction function specifies how many triangles should reduced by specifying the percentage ([0,1]) of triangles to be removed. For example, if the mesh contains 100 triangles and SetTargetReduction(.90) is called, after the decimation there will be approximately 10 triangles - a 90% reduction.

Open Questions in VTK

  • Is there an octree class?
  • How do you use vtkHyperOctree?
  • How do you find the intersection of two 3D objects?
  • How do you fit a quadric surface to a set of points?


Example Usage (Python)

Getting Started

Working with PolyData

Documentation To-do List

These are things that we should add to the documentation to make it clear to new users what is going on.

  • vtkCutter - Need to add an image of a mesh and what happens when a vtkCutter is used to cut the mesh.
  • vtkProbeFilter - What is an example of what this can actually be used to do? Provide an image?

Dashboard submissions

Running tests locally

To run all of the tests on your modified source tree, simply type <source lang="text"> ctest </source> in your build directory. This will not submit anything to the dashboard, but it is a good "first test" to simply see, locally, if everything works.

Submitting an experimental build to the dashboard

The idea of this type of submission is simply to have a nice way to view the output of all the tests, and to leave "proof" that you indeed tested the code. This is useful if you then commit your code and it breaks someone else's build - you can then claim you did everything you could :). To run this type of submission, simply type <source lang="text"> make Experimental </source> from your build directory.

Creating a 'Nightly' dashboard submission

It is impossible for developers to test code on every operating system, compiler, and configuration. By creating a dashboard submission, you can help them find bugs that could be affecting many users but are transparent to some developers. The idea is to get the latest source code, compile it, and run a battery of tests - reporting any compile, build, and test errors to a system which very neatly arranges the results (http://www.cdash.org/CDash/index.php?project=VTK).

It is recommended to not use the same build you work with daily for you dashboard submission. If there is a problem with the nightly cvs, your code may not compile the next day!

To get started, create a new directory called /home/username/Dashboards/VTK. It does not actually have to be in this exactly directory, but this path will be used throughout this example to make the ideas concrete. cd to your new directory and run these commands to check out an initial version of VTK and data sets used for testing.

Here is an example cmake dashboard file.

You will probably want to submit a dashboard every night, so you can add a cronjob. Run 'crontab -e' and enter the following command <source lang="text"> 0 1 * * * export DISPLAY=:0.0 ; ctest -S /home/username/Dashboards/VTK/dashboard.cmake -V > /home/username/Dashboards/VTK/dashboard.log 2>&1 </source>

This says "at 1:00 AM, every day, every month, run the dashboard tests and log verbose output to dashboard.log". The DISPLAY variable is set to allow the tests that need an X server to complete successfully.

Developers Corner

  • If you work with Paraview and VTK, the recommended procedure is to use the same source tree for both projects. That is, build Paraview from .../src/Paraview and VTK from .../src/Paraview/VTK.
  • You should use vtkGetObjectMacro and vtkCxxSetObjectMacro to set and get member variables that are custom types. This allows VTK's mechanisms to keep the reference count correct by automatically registering and unregistering your objects. An example using a custom class member variable is here.

Pitfalls

  • When using the Set*Macro's, you must initialize the variable that is being set in the constructor. The Set*Macro does a check to see if the value has changed before changing it (so that it can update the Modified variable), so if the value is uninitialized, this will cause an error in some memory checking tools (such as valgrind).
  • When trying to use an abstract class, such as

<source lang="cpp"> vtkSmartPointer<vtkPointSet> PointSet = vtkSmartPointer<vtkPointSet>::New(); </source> you will see <source lang="text"> error: invalid conversion from 'vtkDataObject*' to 'vtkPointSet*' </source> To fix this, use a subclass instead.

  • You are getting

<source lang="text"> Generic Warning: In /home/doriad/src/ParaView3/VTK/Common/vtkDebugLeaks.cxx, line 296 Deleting unknown object: vtkObject </source> and <source lang="text"> vtkDebugLeaks has detected LEAKS! Class "vtkYourClass" has N instances still around. </source>

This could mean one of two things. Either 1) you are actually doing something wrong by trying to manually delete a smart pointer or the equivalent or 2) You have forgotten to add: <source lang="cpp"> vtkCxxRevisionMacro(vtkYourClass, "$Revision: 1.1 $"); </source> to your .cxx file and

<source lang="cpp"> vtkTypeRevisionMacro(vtkYourClass,vtkObject); </source> to your .h file.

You must do this because vtkDebugLeaks uses the VTK factory mechanism to keep track of references.

User Created Filters

Here are some filters that have been created by users but not added to VTK. They may still benefit many other users. Please contribute your work!


Examples for Developers

Wiki Sandbox

Ranking test

Administrative Topics

Current Projects

External Links

  • IMTEK Mathematica Supplement (IMS), the Open Source IMTEK Mathematica Supplement (IMS) interfaces VTK and generates ParaView batch scripts
  • [1], VTK examples in C# (Visual Studio 5.0 and .NET 2.0)

Development Process

The VTK Community is upgrading its development process. We are doing this in response to the continuing and rapid growth of the toolkit. A VTK Architecture Review Board VTK ARB is being put in place to provide strategic guidance to the community, and individuals are being identified as leaders in various VTK subsystems.

Examples

Examples



VTK: [Welcome | Site Map]