Difference between revisions of "GRASS and VTK"

From GRASS-Wiki
Jump to: navigation, search
(New bridge from Soeren Gebbert, http://lists.osgeo.org/pipermail/grass-dev/2009-September/046368.html)
 
(+Import of VTK into GRASS)
Line 36: Line 36:
 
writer.Write()
 
writer.Write()
 
</source>
 
</source>
 +
 +
=== Import of VTK data into GRASS ===
 +
 +
Implemented in the VTK-GRASS-Bridge:
 +
 +
* http://code.google.com/p/vtk-grass-bridge/source/browse/trunk/IO/vtkGRASSRasterImageWriter.h
 +
* http://code.google.com/p/vtk-grass-bridge/source/browse/trunk/IO/vtkGRASSVectorPolyDataWriter.h
 +
* http://code.google.com/p/vtk-grass-bridge/source/browse/trunk/IO/vtkGRASSRaster3dImageWriter.h
  
 
== Links ==
 
== Links ==

Revision as of 10:34, 18 January 2012

vtkGRASSBrige provides a VTK/C++ interface to most of the GRASS GIS raster and vector C library functions. Its using an intuitive class structure to hide the complexity of the GRASS libraries.

Additionally, the vtkGRASSBridge provides access to GRASS C library functions for Python and Java, using the VTK wrapper.

Reader to convert GRASS datasets (raster, vector) into VTK datasets are provided for raster and vector data. All vtkImage- and vtkPolyDataAlgorithms can be used to process GRASS raster and vector data. vtkImages can be directly written as GRASS raster maps into a GRASS location.

This library can be used to build comprehensive 3d visualisation of GRASS GIS data with Java, Python and C++, as well as base for complex multithreaded image and vector filter to process GRASS GIS datasets i.e: as backend for WPS server.

Using vtkGRASSBridge in Python

Here a small Python example to triangulate vector points from the North Carolina demo data set with the VTK delaunay filter class:

# The purpose of this example is
# to read a grass vector map without topology information
# into the VTK poly data format and processing that map with vtkDelaunay2D.
# The processed data is written as VTK XML file to the file system

# Init grass variables
init = vtkGRASSInit()

# Now build the pipeline
# read the vector map without creating topology
reader = vtkGRASSVectorPolyDataReader() # The reader does not need
topology information
reader.SetVectorName("elev_lid792_randpts")

# Setup the delaunay triangulation
delaunay = vtkDelaunay2D()
delaunay.SetInputConnection(reader.GetOutputPort())

# write the data as XML with base64 encoding
writer = vtkXMLPolyDataWriter()
writer.SetFileName("/tmp/test.vtk")
writer.SetInputConnection(delaunay.GetOutputPort())
writer.Write()

Import of VTK data into GRASS

Implemented in the VTK-GRASS-Bridge:

Links