[GRASS-dev] Native GRASS support in VTK + Python and Java
Benjamin Ducke
benjamin.ducke at oxfordarch.co.uk
Fri Aug 28 06:02:37 EDT 2009
This is great! Did you consider writing a little plug-on for one
of the VTK viewers, like ParaView or VisIt, to allow direct access
to GRASS data from there?
Cheers,
Ben
Soeren Gebbert wrote:
> Hi,
> JFYI i have implemented a small demo library which connects parts of the
> grass gis library
> with the Visual-Tool-Kit VTK.
> It is called vtkGRASSBridge.
>
> Additionally the VTK Python and Java wrapping mechanism have been
> enabled. So the user can use the
> library from C++, Python and Java.
>
> Features:
> * The library can read and write raster maps row by row, as well as
> regions and the raster history.
> * It can list files of the grass database.
> * It can convert grass raster maps into the vtkImageData format and the
> other way round.
> Missing Features:
> * Full raster support (categories, colors, ..)
> * Imagery support (groups, ...)
> * Full vector support ....
> * ....
>
> You can use every vtkDataSet processing algorithm available in VTK (more
> than 50 i think)
> to process the converted raster map and write it back to the grass
> raster database.
>
> You can use the VTK render functionality to display the raster map.
>
> There are examples and tests in the library showing this functionality
> in Python.
>
> The documentation of the library can be found here:
> http://www-pool.math.tu-berlin.de/~soeren/grass/files/vtkGRASSBridge/doc/html/index.html
>
> The GPL source code is located here:
> http://www-pool.math.tu-berlin.de/~soeren/grass/files/vtkGRASSBridge/vtkGRASSBridge_0.1.tar.gz
>
> Here is a small Python code example to read and write grass raster maps
> in Python (within a grass session):
>
> ##############################################
> #include the VTK and vtkGRASSBridge Python libraries
> from libvtkCommonPython import *
> from libvtkFilteringPython import *
> from libvtkGraphicsPython import *
> from libvtkRenderingPython import *
> from libvtkIOPython import *
> from libvtkImagingPython import *
> from libvtkGRASSBridgeIOPython import *
> from libvtkGRASSBridgeCommonPython import *
>
> #Initiate grass
> init = vtkGRASSInit()
>
> #The region settings
> region = vtkGRASSRegion()
> region.ReadCurrentRegion()
> region.SetCols(10)
> region.SetRows(10)
> region.AdjustRegion()
>
> #Create a new map and write some data into it
> writer = vtkGRASSRasterMapWriter()
> writer.SetMapTypeToCELL()
> writer.SetRegion(region)
> writer.UseUserDefinedRegion()
> writer.OpenMap("test_cell")
>
> #this is the row buffer
> data = vtkIntArray()
> data.SetNumberOfTuples(writer.GetNumberOfCols())
>
> #iterate over each raster cell
> for i in range(writer.GetNumberOfRows()):
> for j in range(writer.GetNumberOfCols()):
> data.SetTuple1(j, i + j + 100)
> writer.PutNextRow(data)
>
> #close the map
> writer.CloseMap()
>
> #now reopen the map for reading
> reader = vtkGRASSRasterMapReader()
> reader.OpenMap("test_cell")
>
> #print the cells to stdout
> print " "
> for i in range(reader.GetNumberOfRows()):
> data = reader.GetRow(i)
> for j in range(reader.GetNumberOfCols()):
> print data.GetTuple1(j),
> print " "
>
> #print the range of the raster map
> val = [0,0]
> reader.GetRange(val);
> print "Range ", val
>
> #print the history
> print reader.GetHistory()
> reader.CloseMap()
>
> #############################################
>
>
> Have fun
> Soeren
>
>
> ------------------------------------------------------------------------
>
> _______________________________________________
> grass-dev mailing list
> grass-dev at lists.osgeo.org
> http://lists.osgeo.org/mailman/listinfo/grass-dev
--
Benjamin Ducke
Senior Applications Support and Development Officer
Oxford Archaeological Unit Limited
Janus House
Osney Mead
OX2 0ES
Oxford, U.K.
Tel: +44 (0)1865 263 800 (switchboard)
Tel: +44 (0)1865 980 758 (direct)
Fax :+44 (0)1865 793 496
benjamin.ducke at oxfordarch.co.uk
------
Files attached to this email may be in ISO 26300 format (OASIS Open Document Format). If you have difficulty opening them, please visit http://iso26300.info for more information.
More information about the grass-dev
mailing list