VTK/Examples

From KitwarePublic
< VTK
Revision as of 11:52, 26 November 2009 by Daviddoria (talk | contribs) (→‎Output)
Jump to navigationJump to search

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

Preliminaries

Wrapping

Simple Operations

Input and Output

Input

Output

  • Write a .vtu file - VTU is an "Unstructured Grid". This format allows for 3D data to be stored.
  • Write a .vtp file - VTP is a "PolyData". This format allows for the most complex geometric objects to be stored.

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.

Working with 3D Data (vtkPolyData)


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

Adding Normals to Polydata

Non-standard Data

These examples show how to attach your own, nonstandard fields to every point or cell in a polydata.

Point cloud operations

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.

Global Operations on PolyData

Working with Stuctured (grid aligned) 3D Data (vtkImageData)

Utilities

Math Operations

Graphs

Data Structures

Filters

Visualization

See [this] for a brief explanation of the VTK terminology of mappers, actors, etc.

User Interaction

Selecting in 3D (Picking)

Working with Images

Working with Meshes

Using VTK Classes as Member Variables

Widgets

Broken Examples (Please fix me!)

  • vtkDistanceToCamera - why aren't the points visible? How to trigger the DistanceToCamera computation?
  • Compass - Which library do you need to link to? What is the compass supposed to do? The only documentation says "set a value by manipulating something". I guess the representation controls the "something", but which representations are possible?
  • Quadric Surface Fitting
  • LU Factorization - how do you get the resulting L and U?
  • Frustum - How do you get the parameters from the camera?

Needed/Missing Examples!

  • vtkApplyColors - How is this different from just adding a Colors array to a vtkDataSet? Example of how to use this.
  • vtkDepthSortPolyData - When would this be used? Example?
  • vtkFrustumCoverageCuller - Doesn't seem to have a property to specify a frustum? What is it for? How to use it?
  • vtkKdTreeSelector - What is this used for? How to use it?
  • vtkSelectionSource - What is this used for? Need example.
  • vtkKMeansStatistics - Is this KMeans clustering? Can you specify a point set (n-D?) to cluster? How to get the cluster IDs after clustering? Example in 3D so we can color the clusters to visualize the result.
  • vtkPCAStatistics - We need an example that takes a set of N-D data and project it into the best M-D space. We should do an example from 2D to 1D so we can visualize the result.
  • vtkPCAAnalysisFilter - What is the difference between this and vtkPCAStatistics? Example?
  • vtkTransposeMatrix - What is this supposed to operate on? There is no vtkMatrix class (yet!) - Example?
  • What is the difference between vtkKdTreePointLocator and vtkKdTree?
  • What does vtkHyperOctree do? Example?

QT widgets

There seems to be no tests to look at for hints on how to use any of these things?

  • vtkQtBarChart
  • vtkQtChartView
  • vtkQtChartWidget
  • vtkQtTreeView
  • vtkQtTableView
  • vtkQtListView
  • vtkQtChartArea

Example Usage (Python)

It would be appreciated if there are any Python VTK experts who could convert any of the above c++ examples to Python!

Getting Started

Working with PolyData