VTK Data Sources

"Sources" are quite simply the source of data flowing through the visualization pipeline. There are basically two types of sources: Readers, which read data out of files in a wide variety of formats, and Independant Sources, which generate data flow based on input parameters. ( E.g. a cone source, which generates information describing a cone, given its radius and height. ) In general, any VTK component that does not receive a flow of data from some other VTK component can be considered a source.

See pages 151 and 275 of the VTK users guide for a long list of useful VTK readers and sources. Some of the ones that were used in this tutorial's sample programs are discussed here:

Readers:

Readers read data out of input files, given the input filename, and in some cases some additional parameters. The important readers encountered this term included:

	// A texture map source:
	textureReader = vtkJPEGReader::New( );
	textureReader->SetFileName( "canyon_rgb.jpg" );
	// C++ code:
 elevReader = vtkImageReader::New();
	elevReader->SetFileName( "canyon_elev.raw" );
	elevReader->SetDataExtent( 0, 1023, 0, 511, 0, 0 );
	elevReader->SetDataScalarTypeToUnsignedChar( );
	elevReader->Update( ); // Needed to generate contour scale !

#TCL Code, from the volume viewer example:
vtkImageReader ImageReader
	ImageReader SetFileName Female.raw
	ImageReader SetDataScalarTypeToUnsignedShort
	ImageReader SetDataByteOrder 0
	ImageReader SetFileDimensionality 3
	ImageReader SetDataOrigin 0 0 0 
	ImageReader SetDataSpacing 1 1 1 
	ImageReader SetDataExtent 0 255 0 255 0 576
	ImageReader SetNumberOfScalarComponents 1
vtkStructuredGridReader tempReader
	tempReader SetFileName $inputFile
	tempReader SetScalarsName AirTemp

Independant Sources:

These sources are capable of generating data independantly, ( i.e. without reading from files ), given proper input parameters. Sources exist for geometrical objects, math functions, generating points, textures, movies, 3-D text, and even a polygonal model of the Earth.

# Example code from the volume viewer example
# Create transfer mapping scalar value to opacity
vtkPiecewiseFunction opacityTransferFunction
    # PARAMETERS ARE SET IN THE APPLYRAYSETTINGS FUNCTION, NOT HERE!
    #opacityTransferFunction AddPoint  $RaySkinLevel \
	#[ expr [ expr 100.0 - $RaySkinTransparency ] / 100.0 ]
    #opacityTransferFunction AddPoint  $RayBoneLevel 1.0
    opacityTransferFunction ClampingOff
# Create transfer mapping scalar gradient to opacity multiplier
    vtkPiecewiseFunction opacityGradientTransferFunction
	opacityGradientTransferFunction AddPoint 0 0
	opacityGradientTransferFunction AddPoint 5 0
	opacityGradientTransferFunction AddPoint 20 1
	opacityGradientTransferFunction ClampingOn
# Example code from the volume viewer example
# Create transfer mapping scalar value to color
vtkColorTransferFunction colorTransferFunction
    # PARAMETERS ARE SET IN THE APPLYRAYSETTINGS FUNCTION, NOT HERE!
    #colorTransferFunction AddRGBPoint $RaySkinLevel 1 0 0
    #colorTransferFunction AddRGBPoint $RayBoneLevel 0 1 0
# Example code from the volume viewer example
# The property describes how the data will look
vtkVolumeProperty volumeProperty
    volumeProperty SetColor colorTransferFunction
    volumeProperty SetScalarOpacity opacityTransferFunction
    #volumeProperty SetGradientOpacity opacityGradientTransferFunction
    volumeProperty ShadeOn
    volumeProperty SetAmbient 0.1
    volumeProperty SetDiffuse 0.8
    volumeProperty SetSpecular 0.1
    volumeProperty SetSpecularPower 20
    volumeProperty SetInterpolationTypeToLinear
    #volumeProperty SetInterpolationTypeToNearest
# Example code from the volume viewer example
vtkVolumeRayCastCompositeFunction  compositeFunction
   
# Example code from the volume viewer example
vtkVolumeRayCastMIPFunction mipFunction
	mipFunction SetMaximizeMethodToOpacity
# Example code from the volume viewer example
vtkBoxWidget box
	box SetInteractor outlineInteractor
	box SetInput [ outlineExtractor GetOutput ]
	box PlaceWidget -75 250 -75 275 400 650
	box RotationEnabledOff
	box On
#
# Then the pipeline for the hedgehog layer  ########
#
vtkStructuredGridReader windReader
	windReader SetFileName $inputFile
	windReader SetVectorsName WindVector
	windReader Update
vtkExtractGrid windExtractor
	windExtractor SetInput [ windReader GetOutput ]
	windExtractor SetVOI 0 100 0 100 $day $day
	windExtractor Update
vtkHedgeHog hedge
	hedge SetInput [ windExtractor GetOutput ]
	hedge SetVectorModeToUseVector
vtkConeSource hedgeCone
	hedgeCone SetRadius 0.0005
	hedgeCone SetHeight 0.002
vtkGlyph3D hedgeGlyphs
	hedgeGlyphs SetSource [ hedgeCone GetOutput ]
	hedgeGlyphs SetInput [ windExtractor GetOutput ]
vtkPolyDataMapper hedgeMapper
	hedgeMapper SetInput [ hedgeGlyphs GetOutput ]
vtkActor hedgeActor
	hedgeActor SetMapper hedgeMapper
	[ hedgeActor GetProperty ] SetOpacity [ expr $hedgeOpacity / 100.0 ]
ren1 AddActor hedgeActor
  
vtkCubeSource cube
	cube SetXLength 0.1
	cube SetYLength 0.1
	cube SetZLength 1.0
vtkProgrammableGlyphFilter glypher1
	glypher1 SetInput [ humidityExtractor GetOutput ]
	glypher1 SetSource [ cube GetOutput ]
	glypher1 SetColorModeToColorByInput
	glypher1 SetGlyphMethod humidityProc1
proc humidityProc1 { } {
	set ptID [ glypher1 GetPointId ]
	precipExtractor Update
	eval set height [[[[ precipExtractor GetOutput ] GetPointData ] GetScalars ] GetComponent $ptID 0 ]
	puts [[[[ humidityExtractor GetOutput ] GetPointData ] GetScalars ] GetComponent $ptID 0 ]
	cube SetZLength $height
	set xyz [ glypher1 GetPoint ]
	set x [ lindex $xyz 0 ]
	set y [ lindex $xyz 1 ]
	set z [ expr $height / 2.0 ]
	cube SetCenter $x $y $z
}
# First the pipeline for the map layer  ###########
# ( Parameters set for ICNstations.jpg.  See below. )
vtkPlaneSource mapPlane
	mapPlane SetResolution 1 1
	mapPlane SetOrigin -91.63 36.95 -0.01
	mapPlane SetPoint1 -87.41 36.95 -0.01
	mapPlane SetPoint2 -91.63 42.65 -0.01
vtkPolyDataMapper mapMapper
	mapMapper SetInput [ mapPlane GetOutput ]
vtkJPEGReader mapReader
	mapReader SetFileName $mapFilename
vtkTexture mapTexture
	mapTexture SetInput [ mapReader GetOutput ]
vtkActor mapActor
	mapActor SetMapper mapMapper
	mapActor SetTexture mapTexture
	[ mapActor GetProperty ] SetOpacity [ expr $mapOpacity / 100.0 ]
ren1 AddActor mapActor