# the case of vtkSIArraySelectionProperty and ArraySelectionDomain

**URL:** https://discourse.paraview.org/t/the-case-of-vtksiarrayselectionproperty-and-arrayselectiondomain/1889
**Category:** Development
**Created:** [May 20, 2019, 3:46pm UTC](https://discourse.paraview.org/t/the-case-of-vtksiarrayselectionproperty-and-arrayselectiondomain/1889 "2019-05-20T15:46:38Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![mwestphal](https://discourse.paraview.org/user_avatar/discourse.paraview.org/mwestphal/32/17_2.png) [@mwestphal](https://discourse.paraview.org/u/mwestphal)
#### Post date: [May 20, 2019, 3:46pm UTC](https://discourse.paraview.org/t/the-case-of-vtksiarrayselectionproperty-and-arrayselectiondomain/1889/1 "2019-05-20T15:46:38Z")

</div>

I have a usecase which is very similar to ArraySelectionDomain.

A vtk class define a few named entities. Each of these can be enabled or disabled.  
If these were arrays, I could use ArraySelectionDomain and it will be perfect.

However, they are not arrays, but parameters to the way the data will be generated.  
According to vtkSIArraySelectionProperty:70 and 89, there is no choice but to name my methods in the vtk class `GetNumberOfEntityArrays` and `GetEntityArrayName`

```auto
  vtkObjectBase* reader = this->GetVTKObject();
  if (reader != NULL)
  {
    std::ostringstream aname;
    aname << "GetNumberOf" << this->Command << "Arrays" << ends;

    // Get the number of arrays.
    vtkClientServerStream stream;
    stream << vtkClientServerStream::Invoke << reader << aname.str().c_str()
           << vtkClientServerStream::End;

    this->ProcessMessage(stream);
    stream.Reset();
    int numArrays = 0;
    if (!this->GetLastResult().GetArgument(0, 0, &numArrays))
    {   
      vtkErrorMacro("Error getting number of arrays from reader.");
    }   

    // For each array, get its name and status.
    for (int i = 0; i < numArrays; ++i)
    {   
      std::ostringstream naname;
      naname << "Get" << this->Command << "ArrayName" << ends;

      // Get the array name.
      stream << vtkClientServerStream::Invoke << reader << naname.str().c_str() << i
             << vtkClientServerStream::End;

```

This is not right at all, we can’t put these method in the VTK class, it would not means anything for the average VTK user for these “entities” to be postfixed by “arrays”.

There is a few possibilities :

- add incorectly named methods in VTK
- add a vtkPVMyClass in that will redirect the calls to the correctly named method
- deprecate ArraySelection\* and rename it StringSelection\*, change the generated calls accordingly.
- Actually support repeat\_command and get\_number\_command in information\_property

I would appreciate any inputs on that

---

<div class="post-metadata">

### Author: ![utkarsh.ayachit](https://discourse.paraview.org/user_avatar/discourse.paraview.org/utkarsh.ayachit/32/39_2.png) [@utkarsh.ayachit](https://discourse.paraview.org/u/utkarsh.ayachit)
#### Post date: [May 20, 2019, 4:13pm UTC](https://discourse.paraview.org/t/the-case-of-vtksiarrayselectionproperty-and-arrayselectiondomain/1889/2 "2019-05-20T16:13:40Z")

</div>

I’d recommend using the modern approach of exposing `vtkDataArraySelection` pointer directly. e.g.

```auto
class MyReader : public ..
{
   ...
public:
  vtkDataArraySelection* GetEntitySelection();

  ...
};

```

Then define your property as described in [vtkSIDataArraySelectionProperty](https://kitware.github.io/paraview-docs/nightly/cxx/classvtkSIDataArraySelectionProperty.html) docs.

This is also the pattern encouraged in the [PythonAlgorithm examples](https://gitlab.kitware.com/paraview/paraview/blob/master/Examples/Plugins/PythonAlgorithm/PythonAlgorithmExamples.py#L174-176).

---

<div class="post-metadata">

### Author: ![mwestphal](https://discourse.paraview.org/user_avatar/discourse.paraview.org/mwestphal/32/17_2.png) [@mwestphal](https://discourse.paraview.org/u/mwestphal)
#### Post date: [May 20, 2019, 4:17pm UTC](https://discourse.paraview.org/t/the-case-of-vtksiarrayselectionproperty-and-arrayselectiondomain/1889/3 "2019-05-20T16:17:36Z")

</div>

That’s what I was missing. Thanks @utkarsh.ayachit

I still have to return a “vtkDataArraySelection”, which is not related to arrays at all though, but that’s better anyway.

---

<div class="post-metadata">

### Author: ![utkarsh.ayachit](https://discourse.paraview.org/user_avatar/discourse.paraview.org/utkarsh.ayachit/32/39_2.png) [@utkarsh.ayachit](https://discourse.paraview.org/u/utkarsh.ayachit)
#### Post date: [May 20, 2019, 4:49pm UTC](https://discourse.paraview.org/t/the-case-of-vtksiarrayselectionproperty-and-arrayselectiondomain/1889/4 "2019-05-20T16:49:19Z")

</div>

> [@mwestphal](#):
>
> I still have to return a “vtkDataArraySelection”, which is not related to arrays at all though, but that’s better anyway.

It’s just a poorly named class that has been VTK since ages. It’s designed for exactly your intended purpose.

---

<div class="post-metadata">

### Author: ![mwestphal](https://discourse.paraview.org/user_avatar/discourse.paraview.org/mwestphal/32/17_2.png) [@mwestphal](https://discourse.paraview.org/u/mwestphal)
#### Post date: [May 21, 2019, 12:05pm UTC](https://discourse.paraview.org/t/the-case-of-vtksiarrayselectionproperty-and-arrayselectiondomain/1889/5 "2019-05-21T12:05:39Z")

</div>

@utkarsh.ayachit: May be I’m missing something, but with the GetPointDataArraySelection mechanism, I don’t see where Modified() is supposed to be called when changing the array.

---

<div class="post-metadata">

### Author: ![utkarsh.ayachit](https://discourse.paraview.org/user_avatar/discourse.paraview.org/utkarsh.ayachit/32/39_2.png) [@utkarsh.ayachit](https://discourse.paraview.org/u/utkarsh.ayachit)
#### Post date: [May 21, 2019, 12:31pm UTC](https://discourse.paraview.org/t/the-case-of-vtksiarrayselectionproperty-and-arrayselectiondomain/1889/6 "2019-05-21T12:31:59Z")

</div>

> [@mwestphal](#):
>
> May be I’m missing something, but with the GetPointDataArraySelection mechanism, I don’t see where Modified() is supposed to be called when changing the array.

In your algorithm, you override `GetMTime` and check for the `vtkDataArraySelection`’s MTime and return the max – a pattern that’s oft repeated when a `vtkAlgorithm` has `vtkObject`-subclass instances internally to store information/data.

Another option is what’s done in the [PythonAlgorithm example](https://gitlab.kitware.com/paraview/paraview/blob/master/Examples/Plugins/PythonAlgorithm/PythonAlgorithmExamples.py#L105). You can add a `ModifiedEvent` callback in your algorithm on the `vtkDataArraySelection` instance and call modified on the algorithm explicitly.

---

<div class="post-metadata">

### Author: ![mwestphal](https://discourse.paraview.org/user_avatar/discourse.paraview.org/mwestphal/32/17_2.png) [@mwestphal](https://discourse.paraview.org/u/mwestphal)
#### Post date: [May 21, 2019, 12:41pm UTC](https://discourse.paraview.org/t/the-case-of-vtksiarrayselectionproperty-and-arrayselectiondomain/1889/7 "2019-05-21T12:41:18Z")

</div>

Indeed, thanks !
