the case of vtkSIArraySelectionProperty and ArraySelectionDomain

(Mathieu Westphal (Kitware)) #1

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

  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

(Utkarsh Ayachit) #2

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

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

  ...
};

Then define your property as described in vtkSIDataArraySelectionProperty docs.

This is also the pattern encouraged in the PythonAlgorithm examples.

1 Like
(Mathieu Westphal (Kitware)) #3

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.

(Utkarsh Ayachit) #4

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

1 Like
(Mathieu Westphal (Kitware)) #5

@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.

(Utkarsh Ayachit) #6

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. You can add a ModifiedEvent callback in your algorithm on the vtkDataArraySelection instance and call modified on the algorithm explicitly.

(Mathieu Westphal (Kitware)) #7

Indeed, thanks !