RVTK Example: Sources and Filters.
As you can guess building data sets manually from scratch is not much
of a fun. So the special classes were introduced into VTK that make this
task more easy. The sources are used in vtk for data set generation
from a small number of input parameters, and filters generate
output datasets from input datasets. It is hard to classify all
filters and sources available in VTK. Various sources and filters
constitute the major part of VTK code.
To get the way filters and sources can be used we try to elaborate a
little our example and add spheres at vertices of tetrahedra and run
tubes along its edges.
vtkSphereSource()->Sphere
Sphere$SetRadius( 0.05)
Sphere$SetPhiResolution(20)
Sphere$SetThetaResolution(20)
Here is an example of the sphere source - setting the radius of the
sphere and number of meridians and parallels we get a data set with 400
vertices. This shere we will use as a stamp to create four spheres at
the vertices of tetrahedra
vtkGlyph3D() ->Vertices
Vertices$SetInput(model)
Vertices$SetSource(Sphere$GetOutput())
vtkGlyph3D is an example of a filter. SetInput method is uniformly used
by filters to set an input dataset for filter. But note that the
rea;ization of this method for particular filter class may require
different type of input parameter. Also there is no rule of thumb to
determine which part of dataset will be used for generation of output
dataset. I.e. Point- and CellData as well as the geometry of input
dataset may influence the properties of output dataset. To make
things more complicated different classes of filters may have different
number of inputs (and outputs as well). vtkGlyph3D has two inputs -
SetInput determines the position of glyphs and SetSource - theirs
shape. For vtkGlyph3D's method SetScaleModeToScaleByScalar() enables
the scaling of glyphs according to the PointData of input dataset
(in that case Raduis of sphere glyph is an unit length). This is
the default behaviour, the SetScaleModeToDataScalingOff() method is
used to turn this feature off. GetOutput method (as you may guess)
produces an output dataset (here we use it to get an output from Sphere
source). As well as in case with GetInput method the type of return
value is not defined - various filters/sources returns different
descendants of vtkDataSet class.
To build the "tube" part of the data set we will follow the different
routine. To specify the geometry scheme of tubes it is not hard to build
a data set consisting of 6 lines but we use another filter which
extracts tetrahedra edges. One more filter will be applied to convert
the extracted edge lines into tubes:
vtkExtractEdges()->ee
ee$SetInput(model)
vtkTubeFilter()-> Tubes
Tubes$SetInput(ee$GetOutput())
Tubes$SetRadius(.03)
Tubes$SetNumberOfSides(6)
The purpose of the last filter is to merge two parts together
(otherwise we could create the polydata mappers and the actors to render
the individual parts of the model). All filters used before expect
polydata as inputs and return polydata. vtkAppendPolydata filter merges
any number of polygonal data sets together:
vtkAppendPolyData()->mf
mf$AddInput(Vertices$GetOutput())
mf$AddInput(Tubes$GetOutput())
The rendering of resulting dataset is just the same as before:
vtkPolyDataMapper()-> TubeMapper
TubeMapper$SetInput(mf$GetOutput())
vtkActor()->TubeActor
TubeActor$SetMapper(TubeMapper)
TubeActor$GetProperty()$SetOpacity(0.6)
ren$AddActor(TubeActor)
As a last remark (once more) - the way the filters handle input data is
not always very intuitive and some consulting with VTK documentation is
particularly useful (although this is a good thing in general). It is
not obvious which part of input data set will influence the result. For
example (see Volcano demo) vtkWarp filter converts vtkImageData into
Polydata by extracting the point data of vtkImageData and warps the
geometry of the image (rectangular equally spaced grid) by adding
this extaracted data to the Z coordinates of points. As you see in this
case the geometry and the associated data both influence the filter's
result.
<Previous Next>