# How to get vtkDataSet (cells, points, ...) information from a source in VTK-9?

**URL:** https://discourse.vtk.org/t/how-to-get-vtkdataset-cells-points-information-from-a-source-in-vtk-9/14860
**Category:** Support
**Created:** [November 13, 2024, 1:14am UTC](https://discourse.vtk.org/t/how-to-get-vtkdataset-cells-points-information-from-a-source-in-vtk-9/14860 "2024-11-13T01:14:58Z")
**Posts on this page:** 10
**Page:** 1

<div class="post-metadata">

### Author: ![Tomasso](https://discourse.vtk.org/user_avatar/discourse.vtk.org/tomasso/32/5786_2.png) [@Tomasso](https://discourse.vtk.org/u/Tomasso)
#### Post date: [November 13, 2024, 1:14am UTC](https://discourse.vtk.org/t/how-to-get-vtkdataset-cells-points-information-from-a-source-in-vtk-9/14860/1 "2024-11-13T01:14:58Z")

</div>

I’m writing C++ for VTK-9.3.1. How can an application discover what vtkDataSets are produced by a source, e.g. a third-party subclass of [vtkAbstractPolyDataReader](https://vtk.org/doc/nightly/html/classvtkAbstractPolyDataReader.html)?

In VTK-8 I could get vtkDataSet information from a source by calling its GetOutput() method which returned a [vtkPolyData object](https://vtk.org/doc/nightly/html/classvtkPolyData.html), e.g.:

```auto
vtkDataSet* dataset = source_->GetOutput();
vtkCellData* cellData = dataset->GetCellData();
// How many cells in dataset?
std::cout << "cells: " << cellData->GetNumberOfArrays() << "\n";

```

As of VTK-9, GetOutput() is deprecated in favor of GetOutputPort(), which returns a [vtkAlgorithmOutpu](https://vtk.org/doc/nightly/html/classvtkAlgorithmOutput.html)t object. How do I get the same vtkDataSet information from vtkAlgorithmOutput and/or vtkAbstractPolyDataReader?  
Thanks!

---

<div class="post-metadata">

### Author: ![dgobbi](https://discourse.vtk.org/user_avatar/discourse.vtk.org/dgobbi/32/18_2.png) [@dgobbi](https://discourse.vtk.org/u/dgobbi)
#### Post date: [November 13, 2024, 10:07pm UTC](https://discourse.vtk.org/t/how-to-get-vtkdataset-cells-points-information-from-a-source-in-vtk-9/14860/2 "2024-11-13T22:07:50Z")

</div>

> [@Tomasso](#):
>
> As of VTK-9, GetOutput() is deprecated in favor of GetOutputPort()

GetOutput() is still the best way to get the vtkDataSet, keep using it like you did before. Definitely not deprecated. It’s necessary to call source-\>Update() before GetOutput(), but that was also true previously.

---

<div class="post-metadata">

### Author: ![Tomasso](https://discourse.vtk.org/user_avatar/discourse.vtk.org/tomasso/32/5786_2.png) [@Tomasso](https://discourse.vtk.org/u/Tomasso)
#### Post date: [November 18, 2024, 5:45pm UTC](https://discourse.vtk.org/t/how-to-get-vtkdataset-cells-points-information-from-a-source-in-vtk-9/14860/3 "2024-11-18T17:45:42Z")

</div>

Thanks!  
I’m misunderstanding something though.  
I’ve subclassed vtkAbstractPolyDataReader to TopoGridReader, which includes these members:

```auto
    /// Grid points
    vtkSmartPointer<vtkPoints> gridPoints_;

    /// Delaunay triangle vertices
    vtkSmartPointer<vtkCellArray> gridPolygons_;

```

My TopoGridReader::RequestData() looks like:

```auto
int TopoGridReader::RequestData(vtkInformation* request,
			       vtkInformationVector** inputVector,
			       vtkInformationVector* outputVector) {
  
  vtkInformation* outInfo = outputVector->GetInformationObject(0);
  vtkDataSet* output = vtkDataSet::GetData(outInfo);
 
  vtkPolyData* polyOutput = vtkPolyData::SafeDownCast(output);
  [... populate gridPoints_ and gridPolygons_ …]

  // Save to output points and polygons
  polyOutput->SetPoints(gridPoints_);
  polyOutput->SetPolys(gridPolygons_);

```

Then when building the pipeline, data from TopoGridReader is rendered as I expect it, but TopoGridReader::GetOutput() seems to indicate 0 points and 0 cells:

```auto
gridReader->SetFileName(filename);
gridReader->Update(); // Invokes gridReader->RequestData()

/// DEBUG ////
vtkDataSet* dataset = gridReader_->GetOutput();

vtkCellData* cellData = dataset->GetCellData();
// How many cells in dataset?
qDebug() << "#cells: " << cellData->GetNumberOfArrays();
    
vtkPointData *pointData = dataset->GetPointData();
// How many points in dataset?
qDebug() << "#points: " << pointData->GetNumberOfArrays();

```

The debug output shows 0 cells and 0 points. What am I doing wrong here?

```auto
#cells: 0
#points: 0

```

Thanks!

---

<div class="post-metadata">

### Author: ![dgobbi](https://discourse.vtk.org/user_avatar/discourse.vtk.org/dgobbi/32/18_2.png) [@dgobbi](https://discourse.vtk.org/u/dgobbi)
#### Post date: [November 18, 2024, 7:06pm UTC](https://discourse.vtk.org/t/how-to-get-vtkdataset-cells-points-information-from-a-source-in-vtk-9/14860/4 "2024-11-18T19:06:06Z")

</div>

> [@Tomasso](#):
>
> ```auto
> qDebug() << "#cells: " << cellData->GetNumberOfArrays();
> qDebug() << "#points: " << pointData->GetNumberOfArrays();
> 
> ```

The CellData and PointData aren’t the cells and points, they’re collections of named arrays that hold data values (e.g. colors, temperatures, directions, normals) that are associated with the points. As far as I understand, these arrays are irrelevant to what you are trying to achieve.

If you want to get the points and polys from the output, why not just cast the output to vtkPolyData and call GetPoints() and GetPolys()?

---

<div class="post-metadata">

### Author: ![Tomasso](https://discourse.vtk.org/user_avatar/discourse.vtk.org/tomasso/32/5786_2.png) [@Tomasso](https://discourse.vtk.org/u/Tomasso)
#### Post date: [November 18, 2024, 10:25pm UTC](https://discourse.vtk.org/t/how-to-get-vtkdataset-cells-points-information-from-a-source-in-vtk-9/14860/5 "2024-11-18T22:25:54Z")

</div>

> [@dgobbi](#):
>
> If you want to get the points and polys from the output, why not just cast the output to vtkPolyData and call GetPoints() and GetPolys()?

That works - thanks @dgobbi ! Do you know why VTK provides both [vtkPoints](https://vtk.org/doc/nightly/html/classvtkPoints.html#details) and [vtkPointData](https://vtk.org/doc/nightly/html/classvtkPointData.html#details)? I don’t understand the relation between these classes. Likewise for [vtkCellArray](https://vtk.org/doc/nightly/html/classvtkCellArray.html#details) and [vtkCellData](https://vtk.org/doc/nightly/html/classvtkCellData.html#details). Moreover my TopoGridReader class doesn’t explicitly deal with vtkPointData or vtkCellData - Will this cause problems? What other pieces of VTK need these?

---

<div class="post-metadata">

### Author: ![dgobbi](https://discourse.vtk.org/user_avatar/discourse.vtk.org/dgobbi/32/18_2.png) [@dgobbi](https://discourse.vtk.org/u/dgobbi)
#### Post date: [November 18, 2024, 11:09pm UTC](https://discourse.vtk.org/t/how-to-get-vtkdataset-cells-points-information-from-a-source-in-vtk-9/14860/6 "2024-11-18T23:09:09Z")

</div>

Let’s say you had a data file where each point in the file had a color associated with it. In VTK, the points would go into vtkPoints, the colors would go in vtkPointData. Hopefully that clears up the relationship between vtkPoints and vtkPointData. Of course, VTK can associate a lot more than just colors with the points and cells.

If the authors had called the class vtkPointAttributes or vtkPointProperties, it would be less confusing. But vtkPointData is the name they chose, and we just have to live with that.

If you’re only inserested in geometry and topology, then you don’t need use vtkPointData or vtkCellData.

---

<div class="post-metadata">

### Author: ![Tomasso](https://discourse.vtk.org/user_avatar/discourse.vtk.org/tomasso/32/5786_2.png) [@Tomasso](https://discourse.vtk.org/u/Tomasso)
#### Post date: [November 18, 2024, 11:19pm UTC](https://discourse.vtk.org/t/how-to-get-vtkdataset-cells-points-information-from-a-source-in-vtk-9/14860/7 "2024-11-18T23:19:57Z")

</div>

Ah, I see the distinction - thanks @dgobbi .  
My goal is to understand how data flows between VTK pipeline elements. Now thanks to you I see how I can inspect my TopoGridReader::GetOutput() for vtkPolyData.

A vtkElevationFilter object is next in the pipeline:

```auto
elevFilter->SetInputConnection(gridReader_->GetOutputPort());
elevFilter_->SetScalarRange(low, high); 
// Feed elevFilter output to surfaceMapper   
surfaceMapper->SetInputConnection(elevFilter->GetOutputPort());

```

How can I inspect the output of the vtkElevationFilter? I tried:

```auto
polyData = pipeline->elevFilter_->GetPolyDataOutput();
polys = polyData->GetPolys();
if (polys) {
  qDebug() << "#cells in elevFilter: " << polys->GetNumberOfCells();
}
else {
  qDebug() << "no polys in elevFilter output";
}
    
points = polyData->GetPoints();
if (points) {
  qDebug() << "#points in elevFilter: " << points->GetNumberOfPoints();
}
else {
  qDebug() << "no points in elevFilter output";      
}

```

But the debug output is:

```auto
#cells in elevFilter output: 0
no points in elevFilter output

```

But my VTK app displays the elevation data as I expect, so obviously data is flowing through the pipeline. What am I missing?

---

<div class="post-metadata">

### Author: ![dgobbi](https://discourse.vtk.org/user_avatar/discourse.vtk.org/dgobbi/32/18_2.png) [@dgobbi](https://discourse.vtk.org/u/dgobbi)
#### Post date: [November 18, 2024, 11:45pm UTC](https://discourse.vtk.org/t/how-to-get-vtkdataset-cells-points-information-from-a-source-in-vtk-9/14860/8 "2024-11-18T23:45:29Z")

</div>

Call `pipeline->elevFilter_->Update()` before inspecting the output. When you render the data, it’s the renderer that calls Update().

---

<div class="post-metadata">

### Author: ![Tomasso](https://discourse.vtk.org/user_avatar/discourse.vtk.org/tomasso/32/5786_2.png) [@Tomasso](https://discourse.vtk.org/u/Tomasso)
#### Post date: [November 18, 2024, 11:49pm UTC](https://discourse.vtk.org/t/how-to-get-vtkdataset-cells-points-information-from-a-source-in-vtk-9/14860/9 "2024-11-18T23:49:19Z")

</div>

Thanks, that does it!  
Can you recommend a good up-to-date document describing the VTK pipeline at this level?  
E.g. this Kitware New Pipeline document doesn’t mention the need to call Update() that I can see

---

<div class="post-metadata">

### Author: ![dgobbi](https://discourse.vtk.org/user_avatar/discourse.vtk.org/dgobbi/32/18_2.png) [@dgobbi](https://discourse.vtk.org/u/dgobbi)
#### Post date: [November 19, 2024, 1:03am UTC](https://discourse.vtk.org/t/how-to-get-vtkdataset-cells-points-information-from-a-source-in-vtk-9/14860/10 "2024-11-19T01:03:21Z")

</div>

That PDF doesn’t say anything about how to use the pipeline, it only describes how to write filters for the pipeline and assumes familiarity with vtkDataSet.

I don’t know of any really good documentation, so I’ll just point you here: [Learning - VTK documentation](https://docs.vtk.org/en/latest/learning.html) (though you’ve probably already been there).
