# vtkMultiThreshold strange API

**URL:** <https://discourse.vtk.org/t/vtkmultithreshold-strange-api/510>\
**Category:** Development\
**Created:** [March 17, 2019, 10:27pm UTC](https://discourse.vtk.org/t/vtkmultithreshold-strange-api/510 "2019-03-17T22:27:56Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![lorensen](https://discourse.vtk.org/user_avatar/discourse.vtk.org/lorensen/32/20_2.png) [@lorensen](https://discourse.vtk.org/u/lorensen)\
**Post date:** [March 17, 2019, 10:27pm UTC](https://discourse.vtk.org/t/vtkmultithreshold-strange-api/510/1 "2019-03-17T22:27:56Z")

</div>

Folks and @dcthomp

First, [vtkMultiThreshold](https://vtk.org/doc/nightly/html/classvtkMultiThreshold.html#details) is a very interesting and useful class. I notice the only place it is used in vtk is in its [unit test](https://gitlab.kitware.com/vtk/vtk/blob/master/Filters/General/Testing/Cxx/UnitTestMultiThreshold.cxx)

I decided to write an example: [CellsInsideObject](https://lorensen.github.io/VTKExamples/site/Cxx/PolyData/CellsInsideObject/)

The filter documentation says “This multiblock dataset contains a vtkUnstructuredGrid for each thresholded subset you request.”.

But the multiblock dataset contains a multiblock dataset that contains a vtkUnstructuredGrid.

To access the unstructured grid I would expect to do this:  
mapper1-\>SetInputData(  
vtkUnstructuredGrid::SafeDownCast(vtkMultiBlockDataSet::SafeDownCast(threshold-\>GetOutput()-\>GetBlock(0)));

but have to do this:

mapper1-\>SetInputData(  
vtkUnstructuredGrid::SafeDownCast(vtkMultiBlockDataSet::SafeDownCast(threshold-\>GetOutput()-\>GetBlock(0))-\>GetBlock(0)));

Is the current API correct? It does not seem to be the way other multiblock datasets are accessed. If it is correct, I think the documentation should be changed to be more clear.

Bill

---

<div class="post-metadata">

**Author:** ![dcthomp](https://discourse.vtk.org/user_avatar/discourse.vtk.org/dcthomp/32/60_2.png) [@dcthomp](https://discourse.vtk.org/u/dcthomp)\
**Post date:** [March 18, 2019, 1:19am UTC](https://discourse.vtk.org/t/vtkmultithreshold-strange-api/510/2 "2019-03-18T01:19:29Z")

</div>

> [@lorensen](#):
>
> First, [vtkMultiThreshold](https://vtk.org/doc/nightly/html/classvtkMultiThreshold.html#details) is a very interesting and useful class. I notice the only place it is used in vtk is in its [unit test](https://gitlab.kitware.com/vtk/vtk/blob/master/Filters/General/Testing/Cxx/UnitTestMultiThreshold.cxx)

I originally wrote and used it in the LS-Dyna reader, which has changed significantly since then.

As far as why the unstructured grids aren’t in the top-level multiblock, I believe that is because the class allows you to output results from multiple clauses of the parse tree that the expression is decomposed in before execution; each clause has a multiblock in the top level multiblock. It has been a while since I looked at it… if you think there is a better interface, I am happy for ideas to improve it, especially if it gets used some more.

---

<div class="post-metadata">

**Author:** ![lorensen](https://discourse.vtk.org/user_avatar/discourse.vtk.org/lorensen/32/20_2.png) [@lorensen](https://discourse.vtk.org/u/lorensen)\
**Post date:** [March 18, 2019, 4:55am UTC](https://discourse.vtk.org/t/vtkmultithreshold-strange-api/510/3 "2019-03-18T04:55:36Z")

</div>

David,

Sounds like the current API was designed to address more complex logic. I think it’s fine to leave as is.

I’ll try to exercise more of it. I think itis a valuable class, but underused.

Bill

---

<div class="post-metadata">

**Author:** ![lorensen](https://discourse.vtk.org/user_avatar/discourse.vtk.org/lorensen/32/20_2.png) [@lorensen](https://discourse.vtk.org/u/lorensen)\
**Post date:** [March 21, 2019, 5:19am UTC](https://discourse.vtk.org/t/vtkmultithreshold-strange-api/510/4 "2019-03-21T05:19:22Z")

</div>

David,  
This is an interesting class that seems to be underused as far as I see.  
I added an example to the [VTKExamples Project](https://lorensen.github.io/VTKExamples/site/)

The Code and CMakeLists.txt file are [here](https://lorensen.github.io/VTKExamples/site/Cxx/PolyData/CellsInsideObject/)  
it produces this image

![](https://discourse.vtk.org/uploads/default/original/1X/cf9a1471f661b91381ffc23c029ca944f0fba0ea.png)

Check it out if you have a chance.

Bill

---

<div class="post-metadata">

**Author:** ![dcthomp](https://discourse.vtk.org/user_avatar/discourse.vtk.org/dcthomp/32/60_2.png) [@dcthomp](https://discourse.vtk.org/u/dcthomp)\
**Post date:** [March 21, 2019, 1:55pm UTC](https://discourse.vtk.org/t/vtkmultithreshold-strange-api/510/5 "2019-03-21T13:55:01Z")

</div>

@lorensen That’s a pretty moo-ving example! I always wanted to write a vtkMultiClip filter as well to do webcuts of datasets.

I looked at the multi-threshold source and the nested multiblocks exist to handle parallel (multi-piece) data. The filter assumes the input data is split into pieces; each top-level output will be a multiblock with numPieces children and only the currently requested piece will be a non-empty grid. I am not sure this is the right way to do things but do recall that I had to do something when reading LS-Dyna files in parallel.
