[vtk-developers] Retrieving data from UnstructuredGrid
Joachim Pouderoux
joachim.pouderoux at kitware.com
Sat Jan 3 19:06:48 EST 2015
Hi,
Not sure to understand what your are doing.
Do you want to use the VTK library to read those VTU files and process
them with it or are you writing an external VTU file reader?
If your are dealing with VTK, the vtkXMLUnstructuredGridReader will
produce an vtkUnstructuredGrid object to hold the unstructured grid.
From it you will be able to retrieve all the information you might need
(geometry, topology as long as point and cell data arrays). To access
the point data from a vtkDataSet (vtkUnstructuredGrid is a derived
class), call ugrid->GetPointData(), you will get a vtkPointData object
which inherits from vtkDataSetAttributes. From it you will be able to
retrieve all attached point data arrays - see class documentation
http://www.vtk.org/doc/nightly/html/classvtkPointData.html.
ex:
vtkDataArray* array =
ugrid->GetPointData()->GetArray("myscalararrayname"); // to retrieve
the data array from its name
vtkDataArray* array = ugrid->GetPointData()->GetScalars(); // to
retrieve the data array tagged as being the active scalar
vtkFloatArray* farray = vtkFloatArray::SafeDownCast(array); // data
array is an abstract class, you might want to use the real type class
for fastest access: eg: float
Hope it helps.
Joachim
On 03/01/2015 03:51, Nicholas Yue wrote:
> Hi,
>
> Using the sample data from VTKData as an example
>
> <?xml version="1.0"?>
> <VTKFile type="UnstructuredGrid" version="0.1"
> byte_order="LittleEndian" compressor="vtkZLibDataCompressor">
> <UnstructuredGrid>
> <Piece NumberOfPoints="22" NumberOfCells="3">
> <PointData Scalars="scalars">
> <DataArray type="Float32" Name="scalars" format="ascii">
> 1 1 1 1 0 0 0 0 0 0
> 1 1 1 0 0 0
> 1 1 1 0 0 0
> </DataArray>
> </PointData>
> <CellData>
> </CellData>
> <Points>
> <DataArray type="Float32" NumberOfComponents="3" format="ascii">
> 0 0 0
>
> I have written initial code to load the unstructured grid file.
>
> How should I go about extracting the PointData Scalars from the
> unstructured grid ?
>
> Eventually, my *.vtu file will have velocity (vector), density
> (scalar) and other additional PointData (file will be binary due to size)
>
> Which CXX example is helpful in understanding PointData extraction
> from unstructured grid ?
>
> Cheers
>
More information about the vtk-developers
mailing list