Set size of StringVectorProperty list at loading of state file


(Patrick Laurin) #1

Hello,

I’ve been working on a ParaView plugin very recently. In the XML definition, I used the following widget:

  <StringVectorProperty name="ParameterNames"
                        command="SetParameterNames"
                        clean_command="ResetParameterNamesToDefault"
                        information_property="ParameterNameInfo"
                        number_of_elements_per_command="1"
                        repeat_command="1"
                        use_index="1"
                        panel_widget="list" >
  </StringVectorProperty>
  
  <StringVectorProperty command="GetDefaultParameterNames"
                        information_only="1"
                        name="ParameterNameInfo"
                        si_class="vtkSIDataArrayProperty" >
  </StringVectorProperty>

When I instantiate the filter, its RequestInformation triggers. The RequestInformation extracts a field array containing a string that tells what size the StringVectorProperty must be and what it must contain. The property is then instantly populated.

Now, if I save that state file, disconnect and load the state, when RequestInformation triggers, the field array that must be read is absent, not something I would expect.

The only workaround I’ve found is to store the NumberOfParameters inside an XML property set with panel_visibility=“never” and populate the property inside RequestData. Any hints?

Thank you very much,
Patrick Laurin


(Utkarsh Ayachit) #2

Are you saying that in RequestInformation, you are accessing your input dataset and doing stuff with it? If that’s the case, that’s indeed incorrect. VTK filters cannot expect that their input datasets will be valid when RequestInformation is called. When you’re doing this one filter at a time in the ParaView UI, each new filter gets created and updated and hence you end up with an acceptable dataset in the input in RequestInformation. That won’t be the case generally.

I’ve recommend the VTK pipeline primer series of blogs for more details on the VTK pipeline.


(Patrick Laurin) #3

Thank you for your prompt response, Utkarsh. I wasn’t too sure about that. I will read that documentation and adapt.

edit: Propagating new metadata keys downstream seems to be the solution.

Thanks,
Patrick Laurin


(Patrick Laurin) #4

In my source header (ReaderClass.h), I have defined the following key:
static vtkInformationIntegerKey* NUMBER_OF_IND_COORDINATES();

Then, I set that key into my output vtkInformation like this:

vtkInformation *outInfo0 = outputVector->GetInformationObject(0);
outInfo0->Set(ReaderClass::NUMBER_OF_IND_COORDINATES(), 9);

When I connect a filter onto that output, I can’t retrieve the key that has been stored:

vtkInformation *inInfo0 = inputVector[0]->GetInformationObject(0);
std::cout << "Int value: " << inInfo0->Get(ReaderClass::NUMBER_OF_IND_COORDINATES()) << std::endl;

Printing inInfo0 gives me the usual keys but not mine.

Am I missing something?

EDIT: Ok, I managed to do it by adding the following line: request->Append(vtkExecutive::KEYS_TO_COPY(), ReaderClass::NUMBER_OF_IND_COORDINATES());

Thanks,
Patrick Laurin


(Utkarsh Ayachit) #5

Cool! KEYS_TO_COPY() is indeed the way to add custom key. Glad it’s working.