3D Widgets

From ParaQ Wiki
Revision as of 13:40, 21 April 2006 by Berk (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigationJump to search

Adding a (new style) 3D widget to SM requires writing 3 XML proxy definitions. Here is an example:

  • Widget: The widget takes care of event handling and passing the right events to the representation. This is only instantiated on the client:
 
    <Proxy name="SliderWidget" class="vtkSliderWidget">
      <ProxyProperty name="Representation"
         command="SetRepresentation">
        <ProxyGroupDomain name="groups">
          <Group name="props" />
        </ProxyGroupDomain>
      </ProxyProperty>
      <IntVectorProperty name="Enabled" 
                         command="SetEnabled"
                         number_of_elements="1"
                         default_values="0">
        <BooleanDomain/>
      </IntVectorProperty>
    </Proxy>

Here, the Enabled property is required.

  • Representation: Representation contains the actual geometry that is rendered and that is used for picking
    <Proxy name="SliderRepresentation3D" class="vtkSliderRepresentation3D">
      <IntVectorProperty
        name="Visibility"
        command="SetVisibility"
        number_of_elements="1"
        default_values="1"
        animateable="1">
        <BooleanDomain name="bool" />
      </IntVectorProperty>

     <DoubleVectorProperty 
        name="Value"
        command="SetValue"
        number_of_elements="1"
        information_property="ValueInfo"
        default_values="0">
        <DoubleRangeDomain name="range"/>
     </DoubleVectorProperty>

     <DoubleVectorProperty 
        name="ValueInfo"
        command="GetValue"
        information_only="1">
        <SimpleDoubleInformationHelper/>
     </DoubleVectorProperty>

      <DoubleVectorProperty
        name="Point1"
        command="SetPoint1InWorldCoordinates"
        number_of_elements="3"
        default_values="-1.0 0.0 0.0">
        <DoubleRangeDomain name="range"/>
      </DoubleVectorProperty>

      <DoubleVectorProperty
        name="Point2"
        command="SetPoint2InWorldCoordinates"
        number_of_elements="3"
        default_values="1.0 0.0 0.0">
        <DoubleRangeDomain name="range"/>
      </DoubleVectorProperty>

     <DoubleVectorProperty 
        name="MinimumValue"
        command="SetMinimumValue"
        number_of_elements="1"
        default_values="0">
        <DoubleRangeDomain name="range"/>
     </DoubleVectorProperty>

     <DoubleVectorProperty 
        name="MaximumValue"
        command="SetMaximumValue"
        number_of_elements="1"
        default_values="1">
        <DoubleRangeDomain name="range"/>
     </DoubleVectorProperty>
    </Proxy>

The Visibility property is required.

  • Finally:
    <New3DWidgetProxy name="SliderRepresentation">
      <SubProxy>
        <Proxy name="Prop"
          proxygroup="props" proxyname="SliderRepresentation3D">
        </Proxy>
        <ExposedProperties>
          <Property name="Visibility" />
          <Property name="ValueInfo" />
          <Property name="Value" />
          <Property name="Point1" />
          <Property name="Point2" />
          <Property name="MinimumValue" />
          <Property name="MaximumValue" />
        </ExposedProperties>
      </SubProxy>

      <SubProxy>
        <Proxy name="Widget"
          proxygroup="3d_widgets" proxyname="SliderWidget">
        </Proxy>
        <ExposedProperties>
          <Property name="Enabled" />
        </ExposedProperties>
      </SubProxy>
    </New3DWidgetProxy>
    <!-- End of displays group -->
  </ProxyGroup>

The vtkSMNew3DWidgetProxy class takes care of managing the 3d widgets. It has to have 2 sub-proxies: Prop and Widget. These two must correspond to a vtkWidgetRepresentation and vtkAbstractWidget (like the two examples above). The Visibility and Enabled properties must be enabled. Once added to the render module, a vtkSMNew3DWidgetProxy object manages the widget and the representation. If a user interaction causes a change to the representation it manages, it updates the corresponding property. For this, one or more pairs of properties have to exist in the representation. For example:

    <Proxy name="SliderRepresentation3D" class="vtkSliderRepresentation3D">
     ...
     <DoubleVectorProperty 
        name="Value"
        command="SetValue"
        number_of_elements="1"
        information_property="ValueInfo"
        default_values="0">
        <DoubleRangeDomain name="range"/>
     </DoubleVectorProperty>

     <DoubleVectorProperty 
        name="ValueInfo"
        command="GetValue"
        information_only="1">
        <SimpleDoubleInformationHelper/>
     </DoubleVectorProperty>
     ...
   </Proxy>

Here, ValueInfo is responsible of getting Value from the (client-side) representation. Value and ValueInfo are linked (by the proxy at creation) so this change will be automatically reflected to the Value property. All the GUI has to do is to listen to the PropertyModifiedEvent and grab changes from the Value property. The GUI can also set the Value directly (make sure to call render afterwards otherwise the widget won't change). Any property pair defined liked this is automatically linked by the proxy at creation. All properties are updated when a EndInteractionEvent is invoked by the widget.