[Paraview-developers] Servermanager XML: Displaying a list of strings along with selection

Girish Ramesh rgirish28 at gmail.com
Mon Aug 18 11:13:33 EDT 2014


There is an additional feature I am interested in, which is using the
panel_widget="list" option for listing the strings. It again causes a
segfault when change it within the XML. Thanks for the help.

Regards,
Girish


On 18 August 2014 16:44, Girish Ramesh <rgirish28 at gmail.com> wrote:

> Thanks Utkarsh. I was also making the mistake of not allocating the memory
> for a SmartPointer as I was changing the code from vtkNew and forgot to
> adapt it. I've changed it now and it works finally! Thanks a lot guys. I'll
> probably add some documentation for this as there is nothing mentioned in
> the Wiki that is close to this at all.
>
> Regards,
> Girish
>
>
> On 18 August 2014 16:26, Utkarsh Ayachit <utkarsh.ayachit at kitware.com>
> wrote:
>
>> Girish,
>>
>> GetCPOList() is incorrect. You cannot return references to variables
>> that go out of scope at the end of the method. Just as a hack, mark
>> the labels variable as static and it will work. You should change the
>> code to make Labels an
>> member variable of the class and return that.
>>
>> Utkarsh
>>
>> On Mon, Aug 18, 2014 at 10:19 AM, Girish Ramesh <rgirish28 at gmail.com>
>> wrote:
>> > Well, I did try with a vtkSmartPointer but it didn't work either. Still
>> > segfaulting. This is the code state at the moment and I can't figure out
>> > why! It is definitely the problem of this bit as the rest of the plugin
>> is
>> > compiling and running without segfaulting. So, I hope you can help me.
>> > Thanks.
>> >
>> > XML:
>> >
>> >  <StringVectorProperty
>> >        name="CPOList"
>> >        label="CPOList"
>> >        command="SetCPOList"
>> >        number_of_elements_per_
>> > command="1"
>> >        information_property="CPOListInfo"
>> >
>> >        panel_visibility="default">
>> >        <StringListDomain name="array_list">
>> >         <RequiredProperties>
>> >         <Property function="ArrayList"
>> >                 name="CPOListInfo"/>
>> >         </RequiredProperties>
>> >         </StringListDomain>
>> >
>> >         <Documentation>
>> >           This property helps select the CPO.
>> >         </Documentation>
>> >      </StringVectorProperty>
>> >
>> >      <StringVectorProperty
>> >        name="CPOListInfo"
>> >        label="CPOListInfo"
>> >        command="GetCPOList"
>> >        information_only="1" >
>> >      <StringArrayHelper />
>> >      </StringVectorProperty>
>> >
>> >
>> > C++:
>> >
>> >
>> > vtkStringArray* ReadUALGrid::GetCPOList(){
>> >
>> >
>> >   vtkSmartPointer<vtkStringArray> labels;
>> >
>> >
>> >
>> >   labels->InsertNextValue("hello");
>> >   labels->InsertNextValue("world");
>> >
>> >
>> >   return labels;
>> >
>> > }
>> >
>> > void ReadUALGrid::SetCPOList(const char* name)
>> >
>> > {
>> >
>> > }
>> >
>> >
>> >
>> >
>> > On 18 August 2014 15:49, Cory Quammen <cory.quammen at kitware.com> wrote:
>> >>
>> >> The biggest problem is that vtkNew will decrement the reference count
>> >> when you go out of scope in GetCPOList(), so it will be garbage
>> >> collected and anything using the return value may cause a crash. For
>> >> your quick proof-of-concept work, use a vtkSmartPointer instead, or
>> >> even just a raw pointer.
>> >>
>> >> Also, SetCPOList takes an int, but shouldn't it take a char* or const
>> >> char*?
>> >>
>> >> Cory
>> >>
>> >> On Mon, Aug 18, 2014 at 9:42 AM, Girish Ramesh <rgirish28 at gmail.com>
>> >> wrote:
>> >> > Sorry but I'm still getting a seg fault and I'm not sure why. This is
>> >> > the
>> >> > relevant code within the plugin. Thanks.
>> >> >
>> >> > XML:
>> >> >
>> >> >  <StringVectorProperty
>> >> >        name="CPOList"
>> >> >        label="CPOList"
>> >> >        command="SetCPOList"
>> >> >        number_of_elements_per_command="1"
>> >> >        information_property="CPOListInfo"
>> >> >
>> >> >        panel_visibility="default">
>> >> >        <StringListDomain name="array_list">
>> >> >         <RequiredProperties>
>> >> >         <Property function="ArrayList"
>> >> >                 name="CPOListInfo"/>
>> >> >         </RequiredProperties>
>> >> >         </StringListDomain>
>> >> >
>> >> >         <Documentation>
>> >> >           This property helps select the CPO.
>> >> >         </Documentation>
>> >> >      </StringVectorProperty>
>> >> >
>> >> >      <StringVectorProperty
>> >> >        name="CPOListInfo"
>> >> >        label="CPOListInfo"
>> >> >        command="GetCPOList"
>> >> >        information_only="1" >
>> >> >      <StringArrayHelper />
>> >> >      </StringVectorProperty>
>> >> >
>> >> > C++:
>> >> >
>> >> > vtkStringArray* ReadUALGrid::GetCPOList(){
>> >> >
>> >> >
>> >> >   vtkNew<vtkStringArray> labels;
>> >> >
>> >> >
>> >> >   labels->InsertNextValue("hello");
>> >> >   labels->InsertNextValue("world");
>> >> >
>> >> >
>> >> >   return labels.GetPointer();
>> >> >
>> >> > }
>> >> >
>> >> > void ReadUALGrid::SetCPOList(int index)
>> >> >
>> >> > {
>> >> >
>> >> > }
>> >> >
>> >> >
>> >> > I'm just using a random vtkStringArray for testing, but it still
>> >> > segfaults.
>> >> > Thank you for the help.
>> >> >
>> >> > Regards,
>> >> > Girish
>> >> >
>> >> >
>> >> >
>> >> >
>> >> > On 18 August 2014 15:31, Girish Ramesh <rgirish28 at gmail.com> wrote:
>> >> >>
>> >> >> Thank you very much Cory for your help. I guess the forum shall be
>> >> >> peppered with any more problems I have!
>> >> >>
>> >> >> Regards,
>> >> >> Girish
>> >> >>
>> >> >>
>> >> >> On 18 August 2014 15:29, Cory Quammen <cory.quammen at kitware.com>
>> wrote:
>> >> >>>
>> >> >>> Girish,
>> >> >>>
>> >> >>> Unfortunately, there isn't much documentation about the server
>> manager
>> >> >>> XMLs. Finding something that looks like what you are trying to do
>> in
>> >> >>> the UI and then tracking it down in the XML is currently the best
>> way.
>> >> >>>
>> >> >>> Thanks,
>> >> >>> Cory
>> >> >>>
>> >> >>> On Mon, Aug 18, 2014 at 9:25 AM, Girish Ramesh <
>> rgirish28 at gmail.com>
>> >> >>> wrote:
>> >> >>> > Dear Cory,
>> >> >>> >
>> >> >>> > Thank you very much. Your hints were very helpful. Option 2 was
>> what
>> >> >>> > I
>> >> >>> > was
>> >> >>> > looking for, but I didn't use the StringListDomain in the second
>> >> >>> > property to
>> >> >>> > connect the information. So my plugin was seg faulting repeatedly
>> >> >>> > even
>> >> >>> > though I thought my logic was correct. Also, is there any
>> resource
>> >> >>> > to
>> >> >>> > find
>> >> >>> > more about servermanager xmls and how to connect the different
>> >> >>> > classes
>> >> >>> > together or is the only option to look at examples. Sorry for the
>> >> >>> > trouble
>> >> >>> > :)Thanks again!
>> >> >>> >
>> >> >>> > Regards,
>> >> >>> > Girish
>> >> >>> >
>> >> >>> >
>> >> >>> >
>> >> >>> >
>> >> >>> > On 18 August 2014 15:16, Cory Quammen <cory.quammen at kitware.com>
>> >> >>> > wrote:
>> >> >>> >>
>> >> >>> >> Girish,
>> >> >>> >>
>> >> >>> >> Is the list of strings fixed, or can it vary depending on the
>> file?
>> >> >>> >> There are three things you can do depending on what you need:
>> >> >>> >>
>> >> >>> >> 1). If you have a fixed set of strings, you can use an
>> >> >>> >> IntVectorProperty, and set its domain as a list of strings with
>> an
>> >> >>> >> associated integer, i.e., an enumeration.
>> >> >>> >>
>> >> >>> >> <IntVectorProperty command="SetVariableType"
>> >> >>> >>                    default_values="0"
>> >> >>> >>                    name="VariableType"
>> >> >>> >>                    number_of_elements="1">
>> >> >>> >>   <EnumerationDomain name="enum">
>> >> >>> >>     <Entry text="Variable 1"
>> >> >>> >>            value="0" />
>> >> >>> >>     <Entry text="Variable 2"
>> >> >>> >>            value="1" />
>> >> >>> >>     <Entry text="Variable 3"
>> >> >>> >>            value="2" />
>> >> >>> >>   </EnumerationDomain>
>> >> >>> >> </IntVectorProperty>
>> >> >>> >>
>> >> >>> >> This generates a combo box in the UI, and only one element can
>> be
>> >> >>> >> selected at a time. It will expect your reader to have methods
>> with
>> >> >>> >> the signature
>> >> >>> >>
>> >> >>> >> virtual void SetVariableType(int i);
>> >> >>> >> virtual int GetVariableType();
>> >> >>> >>
>> >> >>> >> Within your reader, you can use this enumeration value to do
>> >> >>> >> whatever
>> >> >>> >> you'd like.
>> >> >>> >>
>> >> >>> >> 2). If you just have a list of strings generated in your reader
>> and
>> >> >>> >> want to enable the selection of one, you can use a
>> >> >>> >> StringVectorProperty with a StringListDomain, e.g.
>> >> >>> >>
>> >> >>> >> <StringVectorProperty command="GetAllDimensions"
>> >> >>> >>                       information_only="1"
>> >> >>> >>                       name="DimensionInfo">
>> >> >>> >>   <StringArrayHelper />
>> >> >>> >> </StringVectorProperty>
>> >> >>> >> <StringVectorProperty animatelable="0"
>> >> >>> >>                       command="SetDimensions"
>> >> >>> >>                       name="Dimensions"
>> >> >>> >>                       number_of_elements="1"
>> >> >>> >>                       panel_visibility="default">
>> >> >>> >>   <StringListDomain name="array_list">
>> >> >>> >>     <RequiredProperties>
>> >> >>> >>       <Property function="ArrayList"
>> >> >>> >>                 name="DimensionInfo" />
>> >> >>> >>     </RequiredProperties>
>> >> >>> >>   </StringListDomain>
>> >> >>> >> </StringVectorProperty>
>> >> >>> >>
>> >> >>> >> The first property here is an "information-only" property.
>> ParaView
>> >> >>> >> will invoke the method "GetAllDimensions" in your reader which
>> >> >>> >> should
>> >> >>> >> return a vtkStringArray. The second property is responsible for
>> >> >>> >> displaying the string array as a combobox, and invokes the
>> method
>> >> >>> >> "SetDimensions" with the value selected in the combobox. You
>> need
>> >> >>> >> the
>> >> >>> >> StringListDomain in the second property to connect the
>> >> >>> >> information-only property to the second property.
>> >> >>> >>
>> >> >>> >> 3). If you need to populate the list depending on what is in the
>> >> >>> >> file
>> >> >>> >> and be able to select/deselect list entries (e.g., to pick which
>> >> >>> >> variables are loaded from the file), then see the XML file
>> >> >>> >>
>> >> >>> >>
>> >> >>> >>
>> >> >>> >>
>> ParaView/ParaViewCore/ServerManager/SMApplication/Resources/readers.xml
>> >> >>> >>
>> >> >>> >> and search for the SourceProxy named "FlashReaderCore". You'll
>> find
>> >> >>> >> this XML property definition:
>> >> >>> >>
>> >> >>> >>       <!--  Array Selection GUI Component -->
>> >> >>> >>       <StringVectorProperty information_only="1"
>> >> >>> >>                             name="CellArrayInfo">
>> >> >>> >>         <ArraySelectionInformationHelper attribute_name="Cell"
>> />
>> >> >>> >>       </StringVectorProperty>
>> >> >>> >>       <StringVectorProperty command="SetCellArrayStatus"
>> >> >>> >>                             element_types="2 0"
>> >> >>> >>                             information_property="CellArrayInfo"
>> >> >>> >>                             label="Cell Arrays"
>> >> >>> >>                             name="CellArrayStatus"
>> >> >>> >>                             number_of_elements="0"
>> >> >>> >>                             number_of_elements_per_command="2"
>> >> >>> >>                             repeat_command="1">
>> >> >>> >>         <ArraySelectionDomain name="array_list">
>> >> >>> >>           <RequiredProperties>
>> >> >>> >>             <Property function="ArrayList"
>> >> >>> >>                       name="CellArrayInfo" />
>> >> >>> >>           </RequiredProperties>
>> >> >>> >>         </ArraySelectionDomain>
>> >> >>> >>         <Documentation>This property lists which cell-centered
>> >> >>> >> arrays
>> >> >>> >> to
>> >> >>> >>         read.</Documentation>
>> >> >>> >>       </StringVectorProperty>
>> >> >>> >>       <StringVectorProperty information_only="1"
>> >> >>> >>                             name="PointArrayInfo">
>> >> >>> >>         <ArraySelectionInformationHelper attribute_name="Point"
>> />
>> >> >>> >>       </StringVectorProperty>
>> >> >>> >>
>> >> >>> >> This XML is responsible for showing in the GUI the list of
>> >> >>> >> cell-associated arrays. In the vtkAMRFlashReader, there are a
>> >> >>> >> number
>> >> >>> >> of
>> >> >>> >> methods that are defined to make this work. (These are actually
>> >> >>> >> defined in vtkAMRFlashReader's parent class, vtkAMRBaseReader.h)
>> >> >>> >>
>> >> >>> >>   // Description:
>> >> >>> >>   // Get the data array selection tables used to configure which
>> >> >>> >> data
>> >> >>> >>   // arrays are loaded by the reader.
>> >> >>> >>   vtkGetObjectMacro(CellDataArraySelection,
>> vtkDataArraySelection);
>> >> >>> >>
>> >> >>> >>   // Description:
>> >> >>> >>   // Get the number of point or cell arrays available in the
>> input.
>> >> >>> >>   int GetNumberOfCellArrays();
>> >> >>> >>
>> >> >>> >>   // Description:
>> >> >>> >>   // Get the name of the point or cell array with the given
>> index
>> >> >>> >> in
>> >> >>> >>   // the input.
>> >> >>> >>   const char* GetCellArrayName(int index);
>> >> >>> >>
>> >> >>> >>   // Description:
>> >> >>> >>   // Get/Set whether the point or cell array with the given
>> name is
>> >> >>> >> to
>> >> >>> >>   // be read.
>> >> >>> >>   int GetCellArrayStatus(const char* name);
>> >> >>> >>   void SetCellArrayStatus(const char* name, int status);
>> >> >>> >>
>> >> >>> >> The first method listed above might not be necessary in your
>> >> >>> >> reader;
>> >> >>> >> I'm not sure. The rest are necessary.
>> >> >>> >>
>> >> >>> >> Note in this XML and method definitions that "Cell" is the name
>> of
>> >> >>> >> the
>> >> >>> >> given to the association of array the reader can load. You can
>> >> >>> >> replace
>> >> >>> >> all occurrences of "Cell" with whatever name is more appropriate
>> >> >>> >> for
>> >> >>> >> your needs.
>> >> >>> >>
>> >> >>> >> I hope that helps,
>> >> >>> >> Cory
>> >> >>> >>
>> >> >>> >> On Mon, Aug 18, 2014 at 5:46 AM, Girish Ramesh
>> >> >>> >> <rgirish28 at gmail.com>
>> >> >>> >> wrote:
>> >> >>> >> > Hi,
>> >> >>> >> >
>> >> >>> >> > I have been breaking my head over this problem for a while
>> now as
>> >> >>> >> > there
>> >> >>> >> > are
>> >> >>> >> > no servermanager xml explanations anywhere. So, what I want to
>> >> >>> >> > accomplish is
>> >> >>> >> > populate a GUI list with a vtkStringArray and be able to
>> select
>> >> >>> >> > strings
>> >> >>> >> > within the list in order to fill a variable . Can someone
>> please
>> >> >>> >> > help me
>> >> >>> >> > or
>> >> >>> >> > point me in the right direction in this task? I am writing my
>> own
>> >> >>> >> > plugin
>> >> >>> >> > reader as you may have understood, but I'm stuck at this point
>> >> >>> >> > for a
>> >> >>> >> > while.
>> >> >>> >> > Thanks.
>> >> >>> >> >
>> >> >>> >> > Regards,
>> >> >>> >> > Girish
>> >> >>> >> >
>> >> >>> >> > _______________________________________________
>> >> >>> >> > Paraview-developers mailing list
>> >> >>> >> > Paraview-developers at paraview.org
>> >> >>> >> >
>> http://public.kitware.com/mailman/listinfo/paraview-developers
>> >> >>> >> >
>> >> >>> >
>> >> >>> >
>> >> >>
>> >> >>
>> >> >
>> >
>> >
>> >
>> > _______________________________________________
>> > Paraview-developers mailing list
>> > Paraview-developers at paraview.org
>> > http://public.kitware.com/mailman/listinfo/paraview-developers
>> >
>>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/paraview-developers/attachments/20140818/1335987a/attachment-0001.html>


More information about the Paraview-developers mailing list