RVTK  Example: Pipeline and Data Storage Objects (DataArrays)

Well... The idea of VTK is to organize processing pipeline from one end of which data is pumped down and at another end we get a graphical output (on screen or file - doesn't matter).
Processing pipeline looks like:
data arrays -> data model->(SetInput) mapper-> (SetMapper) actor->(AddActor) renderer->(AddRenderer) renderWindow->(SetRenderWindow) WindowInteractor
Although nodes in this diagramm doesn't correspond to real VTK class, the values in parenthesis are the methods (of class pointed to by arrows) you should use to create processing pipeline.
What the diagramm means? First of all you have an R data you want to visualize. You need to put it into VTK data storage objects. VTK does not use standard C-arrays (contiguous memory chunks of variable size) to store large ampunts of data. Instead VTK wraps C-arrays into specialized objects (descendants of vtkDataArray abstarct class) for this purpose. The inheritance diagramm is shown above. For each basic C-type, in VTK there is a corresponding DataArray class. Data arrays is just a two-dimensional matrices stored row-wise (i.e. tuples). DataArrays object provide an unified interface for accessing individual components of matrix, the rows (tuples) or the array itself as a whole. RVTK nonetheless provides standard "[]<-" and "[]" notation to manipulate the content of vtkDataArray descendants. For example:
vtkDoubleArray()->p
p[]<-cbind(c(0.705, -0.705, -0.705, -0.705),c( 0, 1, -0.5, -0.5),c( 0, 0, 0.8660254, -0.8660254))
p[,1]
vtkIdTypeArray()->f
f[]<-c(3,3,2,1,3,0,1,2,3,0,2,3,3,0,3,1)

Because DataArrays are an intermediate step before putting R-matrices into VTK pipeline, RVTK provides a number of functions ( DoubleArray(R.matrix) , IntArray(...) ) which create and initialize DataArray instance in one run. It usually saves you an effort of creating temporary variable.
Several DataArrays of different types but with the same number of tuples (rows) can be bundled together into vtkFieldData object. vtkFieldData provides an interface for accessing individual arrays by an index or name assigned to them or to work with all array components as a whole (for example GetNumberOfComponents returns the the sum of all arays' row lengths). It would look exactly  like R's data.frame if data.frame allows having vectors as data.frame's component.

Next>