# How to get full cell types array with new VTK 9.6 API

**URL:** https://discourse.vtk.org/t/how-to-get-full-cell-types-array-with-new-vtk-9-6-api/16106
**Category:** Development
**Tags:** python
**Created:** [October 22, 2025, 2:44pm UTC](https://discourse.vtk.org/t/how-to-get-full-cell-types-array-with-new-vtk-9-6-api/16106 "2025-10-22T14:44:32Z")
**Posts on this page:** 17
**Page:** 1

<div class="post-metadata">

### Author: ![user27182](https://discourse.vtk.org/user_avatar/discourse.vtk.org/user27182/32/10104_2.png) [@user27182](https://discourse.vtk.org/u/user27182)
#### Post date: [October 22, 2025, 2:44pm UTC](https://discourse.vtk.org/t/how-to-get-full-cell-types-array-with-new-vtk-9-6-api/16106/1 "2025-10-22T14:44:32Z")

</div>

`GetCellTypesArray` is recently deprecated. Using the latest python dev wheels:

```py
>>> import vtk
>>> grid = vtk.vtkUnstructuredGrid()
>>> array = grid.GetCellTypesArray()
DeprecationWarning: Call to deprecated method GetCellTypesArray. (Use GetCellTypes() instead) -- Deprecated since version 9.6.0.

```

As per the warning, let’s try `GetCellTypes` instead:

```py
>>> cell_types = vtk.vtkCellTypes()
>>> grid.GetCellTypes(cell_types)
DeprecationWarning: Call to deprecated method GetCellTypes. (Use GetDistinctCellTypes(vtkCellTypes* types) instead.) -- Deprecated since version 9.6.0.

```

As per the warning, this means I should now use `GetDistinctCellTypes`.  
But, this returns an array with _unique_ cell types, rather than an array with _all_ cell types.  
Am I missing something? How can I use the new, non-deprecated API to get the original array that was returned by `GetCellTypesArray`? Or is it no longer possible to do this in VTK 9.6?

---

<div class="post-metadata">

### Author: ![mwestphal](https://discourse.vtk.org/user_avatar/discourse.vtk.org/mwestphal/32/19_2.png) [@mwestphal](https://discourse.vtk.org/u/mwestphal)
#### Post date: [October 23, 2025, 7:22am UTC](https://discourse.vtk.org/t/how-to-get-full-cell-types-array-with-new-vtk-9-6-api/16106/2 "2025-10-23T07:22:55Z")

</div>

@spyridon97 is this related/fixed by [https://gitlab.kitware.com/vtk/vtk/-/merge\_requests/12549](https://gitlab.kitware.com/vtk/vtk/-/merge_requests/12549) ?

---

<div class="post-metadata">

### Author: ![spyridon97](https://discourse.vtk.org/user_avatar/discourse.vtk.org/spyridon97/32/7069_2.png) [@spyridon97](https://discourse.vtk.org/u/spyridon97)
#### Post date: [October 23, 2025, 7:55am UTC](https://discourse.vtk.org/t/how-to-get-full-cell-types-array-with-new-vtk-9-6-api/16106/3 "2025-10-23T07:55:34Z")

</div>

yes

---

<div class="post-metadata">

### Author: ![spyridon97](https://discourse.vtk.org/user_avatar/discourse.vtk.org/spyridon97/32/7069_2.png) [@spyridon97](https://discourse.vtk.org/u/spyridon97)
#### Post date: [October 23, 2025, 8:03am UTC](https://discourse.vtk.org/t/how-to-get-full-cell-types-array-with-new-vtk-9-6-api/16106/4 "2025-10-23T08:03:10Z")

</div>

Fix was just merged. Tomorrow’s nightly wheel should have the fix.

---

<div class="post-metadata">

### Author: ![mwestphal](https://discourse.vtk.org/user_avatar/discourse.vtk.org/mwestphal/32/19_2.png) [@mwestphal](https://discourse.vtk.org/u/mwestphal)
#### Post date: [October 23, 2025, 8:05am UTC](https://discourse.vtk.org/t/how-to-get-full-cell-types-array-with-new-vtk-9-6-api/16106/5 "2025-10-23T08:05:05Z")

</div>

A reminder that wheels are weekly generated and sometimes fails to generate 🙂

---

<div class="post-metadata">

### Author: ![spyridon97](https://discourse.vtk.org/user_avatar/discourse.vtk.org/spyridon97/32/7069_2.png) [@spyridon97](https://discourse.vtk.org/u/spyridon97)
#### Post date: [October 23, 2025, 8:08am UTC](https://discourse.vtk.org/t/how-to-get-full-cell-types-array-with-new-vtk-9-6-api/16106/6 "2025-10-23T08:08:19Z")

</div>

Mistakes were made 😛

---

<div class="post-metadata">

### Author: ![user27182](https://discourse.vtk.org/user_avatar/discourse.vtk.org/user27182/32/10104_2.png) [@user27182](https://discourse.vtk.org/u/user27182)
#### Post date: [October 23, 2025, 3:42pm UTC](https://discourse.vtk.org/t/how-to-get-full-cell-types-array-with-new-vtk-9-6-api/16106/7 "2025-10-23T15:42:58Z")

</div>

Thanks for the quick fix! Just to clarify: `GetCellTypesArray` is _not_ being deprecated?

---

<div class="post-metadata">

### Author: ![spyridon97](https://discourse.vtk.org/user_avatar/discourse.vtk.org/spyridon97/32/7069_2.png) [@spyridon97](https://discourse.vtk.org/u/spyridon97)
#### Post date: [October 23, 2025, 3:49pm UTC](https://discourse.vtk.org/t/how-to-get-full-cell-types-array-with-new-vtk-9-6-api/16106/8 "2025-10-23T15:49:20Z")

</div>

It is. In place of vtkDataArray\* GetCellTypes().

---

<div class="post-metadata">

### Author: ![user27182](https://discourse.vtk.org/user_avatar/discourse.vtk.org/user27182/32/10104_2.png) [@user27182](https://discourse.vtk.org/u/user27182)
#### Post date: [October 23, 2025, 4:47pm UTC](https://discourse.vtk.org/t/how-to-get-full-cell-types-array-with-new-vtk-9-6-api/16106/9 "2025-10-23T16:47:04Z")

</div>

Ah ok, so `GetCellTypesArray` is deprecated, but `GetCellTypes` is not.Thanks!

---

<div class="post-metadata">

### Author: ![spyridon97](https://discourse.vtk.org/user_avatar/discourse.vtk.org/spyridon97/32/7069_2.png) [@spyridon97](https://discourse.vtk.org/u/spyridon97)
#### Post date: [October 23, 2025, 4:49pm UTC](https://discourse.vtk.org/t/how-to-get-full-cell-types-array-with-new-vtk-9-6-api/16106/10 "2025-10-23T16:49:16Z")

</div>

```cpp
  /**
   * Get a list of types of cells in a dataset. The list consists of an array
   * of types (not necessarily in any order), with a single entry per type.
   * For example a dataset with 5 triangles, 3 lines, and 100 hexahedra would
   * result in a list of three entries, corresponding to the types VTK_TRIANGLE,
   * VTK_LINE, and VTK_HEXAHEDRON. This override implements an optimization that
   * recomputes cell types only when the types of cells may have changed.
   *
   * THIS METHOD IS THREAD SAFE IF FIRST CALLED FROM A SINGLE THREAD AND
   * THE DATASET IS NOT MODIFIED
   */
  void GetDistinctCellTypes(vtkCellTypes* types) override;
  VTK_DEPRECATED_IN_9_6_0("Use GetDistinctCellTypes(vtkCellTypes* types) instead.")
  void GetCellTypes(vtkCellTypes* types) override { this->GetDistinctCellTypes(types); }
  ///@}

  /**
   * Get a list of types of cells in a dataset. The list consists of an array
   * of types (not necessarily in any order), with a single entry per type.
   * For example a dataset with 5 triangles, 3 lines, and 100 hexahedra would
   * result in a list of three entries, corresponding to the types VTK_TRIANGLE,
   * VTK_LINE, and VTK_HEXAHEDRON. This override implements an optimization that
   * recomputes cell types only when the types of cells may have changed.
   * This method never returns `nullptr`.
   *
   * THIS METHOD IS THREAD SAFE IF FIRST CALLED FROM A SINGLE THREAD AND
   * THE DATASET IS NOT MODIFIED
   */
  vtkUnsignedCharArray* GetDistinctCellTypesArray();

  ///@{
  /**
   * Get the array of all cell types in the grid. Each single-component
   * tuple in the array at an index that corresponds to the type of the cell
   * with the same index. To get an array of only the distinct cell types in
   * the dataset, use GetDistinctCellTypes().
   */
  vtkDataArray* GetCellTypes() { return this->Types; }
  VTK_DEPRECATED_IN_9_6_0("Use GetCellTypes() instead")
  vtkUnsignedCharArray* GetCellTypesArray();
  ///@}
...

```

---

<div class="post-metadata">

### Author: ![user27182](https://discourse.vtk.org/user_avatar/discourse.vtk.org/user27182/32/10104_2.png) [@user27182](https://discourse.vtk.org/u/user27182)
#### Post date: [October 23, 2025, 5:49pm UTC](https://discourse.vtk.org/t/how-to-get-full-cell-types-array-with-new-vtk-9-6-api/16106/11 "2025-10-23T17:49:06Z")

</div>

Got it, I think I understand now. Not used to working with C overloads. So `GetCellTypes` _is_ deprecated, but only for the version where the getter mutates the input and returns nothing. We should use `GetCellTypes` with no args instead, which returns the cell types directly. And I think. the bug is that this version of `GetCellTypes` was missing, but has been fixed/added?

I’m just thinking out loud, no need reply to this or add to it. I’ll wait for the new dev wheels and let you know if I’m still having issues with the new API. Thanks again!

---

<div class="post-metadata">

### Author: ![spyridon97](https://discourse.vtk.org/user_avatar/discourse.vtk.org/spyridon97/32/7069_2.png) [@spyridon97](https://discourse.vtk.org/u/spyridon97)
#### Post date: [October 23, 2025, 5:50pm UTC](https://discourse.vtk.org/t/how-to-get-full-cell-types-array-with-new-vtk-9-6-api/16106/12 "2025-10-23T17:50:32Z")

</div>

You got that right!

---

<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: [October 23, 2025, 6:14pm UTC](https://discourse.vtk.org/t/how-to-get-full-cell-types-array-with-new-vtk-9-6-api/16106/13 "2025-10-23T18:14:54Z")

</div>

> [@spyridon97](#):
>
> `vtkUnsignedCharArray* GetDistinctCellTypesArray();`  
> `vtkDataArray* GetCellTypes();`

You explain in the docs why `vtkDataArray` is used for `GetCellTypes()`, but I’m still not sure how well this will work for C++ users.

> **[Documentation/release/dev/vtkDataSet-GetCellTypes-updates.md](https://gitlab.kitware.com/vtk/vtk/-/blob/05975cd/Documentation/release/dev/vtkDataSet-GetCellTypes-updates.md)**
> 
> `vtkUnstructuredGrid`’s method `vtkUnsignedCharArray* GetCellTypesArray()` has been deprecated in favor of `vtkDataArray* GetCellTypes()`, which can be used to get the correct type as follows:
> 
> `auto cellTypes = vtkConstantUnsignedCharArray::FastDownCast(input->GetCellTypes())`  
> `auto cellTypes = vtkUnsignedCharArray::FastDownCast(input->GetCellTypes())`
> 
> This was done to enable storing the cell types of meshes with only 1 cell type as `vtkConstantUnsignedCharArray` instead of `vtkUnsignedCharArray`, which saves memory.

All the user knows about `CellTypes` is that it is a `vtkDataArray`, there seems to be no guarantee that it is either `vtkConstantUnsignedCharArray` or `vtkUnsignedCharArray`. So are you suggesting that users try various downcasts an then eventually fall back on the `vtkDataArray` interface? I’m imagining code like the following, which seems fairly tedious:

```c++
void myfunc(vtkUnstructedGrid* input)
{
  auto* cellTypes1 = vtkConstantUnsignedCharArray::FastDownCast(input->GetCellTypes());
  if (cellTypes1 != nullptr)
  {
    // code for when the cell type array is vtkConstantUnsignedCharArray
    return;
  }
  auto* cellTypes2 = vtkUnsignedCharArray::FastDownCast(input->GetCellTypes());
  if (cellTypes2 != nullptr)
  {
    // code for when the cell type array is vtkUnsignedCharArray
    return;
  }
  auto* cellTypes = input->GetCellTypes();
  // code for when we're not sure of the array type
  return;
}

```

Am I misunderstanding how the downcasts will actually be used?

---

<div class="post-metadata">

### Author: ![spyridon97](https://discourse.vtk.org/user_avatar/discourse.vtk.org/spyridon97/32/7069_2.png) [@spyridon97](https://discourse.vtk.org/u/spyridon97)
#### Post date: [October 23, 2025, 6:24pm UTC](https://discourse.vtk.org/t/how-to-get-full-cell-types-array-with-new-vtk-9-6-api/16106/14 "2025-10-23T18:24:01Z")

</div>

There are several solutions

1. Use `vtkDataArray::GetComponent(id, 0);`
2. Use `vtkDataArray::GetTuple1(id);`
3. Use `auto range = vtk::DataArrayValueRange<1. unsigned char>(cellTypes);` and `auto cellType = range[id];`
4. Dispatch with `vtkUnstructuredGrid::CellTypesArrays` and use `auto range = vtk::DataArrayValueRange<1>(cellTypes);` and `auto cellType = range[id];`

The most efficient is 4, then 1 and 3 are next (equal), and then 2.

---

<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: [October 23, 2025, 6:47pm UTC](https://discourse.vtk.org/t/how-to-get-full-cell-types-array-with-new-vtk-9-6-api/16106/15 "2025-10-23T18:47:39Z")

</div>

Is there a solution #5 that uses `FastDownCast`? You mention `FastDownCast` very prominently in the release note.

---

<div class="post-metadata">

### Author: ![spyridon97](https://discourse.vtk.org/user_avatar/discourse.vtk.org/spyridon97/32/7069_2.png) [@spyridon97](https://discourse.vtk.org/u/spyridon97)
#### Post date: [October 23, 2025, 6:55pm UTC](https://discourse.vtk.org/t/how-to-get-full-cell-types-array-with-new-vtk-9-6-api/16106/16 "2025-10-23T18:55:41Z")

</div>

I mean sure you can use

```auto
1. `auto cellTypes = vtkConstantUnsignedCharArray::FastDownCast(input->GetCellTypes())`
2. `auto cellTypes = vtkUnsignedCharArray::FastDownCast(input->GetCellTypes())`

```

if you already know what it is, but i would not suggest it when you only need to access 1-2 cell type values. I would only suggest it when iterating all cell types.

---

<div class="post-metadata">

### Author: ![mwestphal](https://discourse.vtk.org/user_avatar/discourse.vtk.org/mwestphal/32/19_2.png) [@mwestphal](https://discourse.vtk.org/u/mwestphal)
#### Post date: [October 24, 2025, 6:54am UTC](https://discourse.vtk.org/t/how-to-get-full-cell-types-array-with-new-vtk-9-6-api/16106/17 "2025-10-24T06:54:07Z")

</div>

`vtkDataArray::GetVariantValue` also works and is very usefull if you know the type of the data but not the type of the array.
