# Adding a custom 3D Widget to a ParaView plugin

**URL:** https://discourse.paraview.org/t/adding-a-custom-3d-widget-to-a-paraview-plugin/4647
**Category:** Development
**Created:** [June 22, 2020, 7:36pm UTC](https://discourse.paraview.org/t/adding-a-custom-3d-widget-to-a-paraview-plugin/4647 "2020-06-22T19:36:35Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![coreylee](https://discourse.paraview.org/user_avatar/discourse.paraview.org/coreylee/32/14039_2.png) [@coreylee](https://discourse.paraview.org/u/coreylee)
#### Post date: [June 22, 2020, 7:36pm UTC](https://discourse.paraview.org/t/adding-a-custom-3d-widget-to-a-paraview-plugin/4647/1 "2020-06-22T19:36:36Z")

</div>

Hello,

I am working on a project where I need an interactive widget in a custom plugin within ParaView. My plugin is C++ based (built with CMake) and will be loaded into ParaView (built from source). The end goal here is to use two input datasets where one is used to generate the 3D widget, and then through user interaction of the widget, modify the other dataset. However, I’m not sure where to begin! Are there examples or resources for how to

1. build custom 3D widgets for interacting with the ParaView viewport
2. adding 3D interactive widgets to C++ based plugins
3. initializing widgets with data from an input port within the plugin

Thanks in advance!

---

<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: [June 23, 2020, 1:51am UTC](https://discourse.paraview.org/t/adding-a-custom-3d-widget-to-a-paraview-plugin/4647/2 "2020-06-23T01:51:45Z")

</div>

So widget in the VTK sense, not the Qt sense ?

Definitely not an easy unless you already know about VTK widgets.  
Starting point would be to take a look into the design of existing widgets in VTK.

Modern widgets uses a widget/representation duality. You can take a look at  
`VTK/Interaction/Widgets/vtkLightWidget\Representation`

Once you are implemented your widget, you need to expose it into ParaView: `Remoting/Views/Resources/3dwidgets_remotingviews.xml`  
and  
`Qt/ApplicationComponents/pqLightPropertyWidget.cxx`

All this can be done in a plugin with a design similar to `Examples/Plugins/PropertyWidget`

hth.

---

<div class="post-metadata">

### Author: ![coreylee](https://discourse.paraview.org/user_avatar/discourse.paraview.org/coreylee/32/14039_2.png) [@coreylee](https://discourse.paraview.org/u/coreylee)
#### Post date: [June 23, 2020, 6:45pm UTC](https://discourse.paraview.org/t/adding-a-custom-3d-widget-to-a-paraview-plugin/4647/3 "2020-06-23T18:45:48Z")

</div>

Thank you so much for the quick response! This helps a lot.

In the file [**Qt/ApplicationComponents/pqLightPropertyWidget.cxx**](https://gitlab.kitware.com/paraview/paraview/-/blob/master/Qt/ApplicationComponents/pqLightPropertyWidget.cxx)\ line 33, where does the file `ui_pqLightPropertyWidget.h` get included from?

Edit: forgot the critical `qt5_wrap_ui(ui_srcs pqLightPropertyWidget.ui)` line in the `CMakeLists.txt`

---

<div class="post-metadata">

### Author: ![coreylee](https://discourse.paraview.org/user_avatar/discourse.paraview.org/coreylee/32/14039_2.png) [@coreylee](https://discourse.paraview.org/u/coreylee)
#### Post date: [October 19, 2020, 9:50pm UTC](https://discourse.paraview.org/t/adding-a-custom-3d-widget-to-a-paraview-plugin/4647/4 "2020-10-19T21:50:08Z")

</div>

Alright, so I have what I think is a pretty good handle on creating custom widgets and running them in ParaView. Now the third point on my initial post is where I am held up. Within my filter, I have a `vtkPolyData` coming in on port 1 (I have 2 ports each with their own `vtkPolyData`, but I am focusing on the second one here) which I would like to use to initialize the representation of my widget with.

For ease of illustration, let’s say the `vtkPolyData` on port 1 is just a poly line, and I would like to initialize the customized `vtkPolyLineRepresentation` defining the widget with that poly line.

From what I’ve gathered, the interfacing class `vtk3DWidgetRepresentation` specifically has zero input ports interfacing with the ParaView pipeline. Within my ServerManagerConfiguration xml file, I have this widget representation proxy setup pointing at the default `vtk3DWidgetRepresentation` class:

```auto
 <ProxyGroup name="representations">
   <NewWidgetRepresentationProxy class="vtk3DWidgetRepresentation"
                                 name="MyPolyLineWidgetRepresentation">
    ...
  </NewWidgetRepresentationProxy>

```

And under this configuration, everything runs in paraview, though with the default behavior of an uninitialized poly line widget.

I have tried creating a new class which inherits from `vtk3DWidgetRepresentation` and adding it as such:

```auto
 <ProxyGroup name="representations">
   <NewWidgetRepresentationProxy class="vtkMyPolyLineWidgetRepresentation"
                                 name="MyPolyLineWidgetRepresentation">
     ...
   </NewWidgetRepresentationProxy>

```

where the class `vtkMyPolyLineWidgetRepresentation` is a `vtk3DWidgetRepresentation` but with the constructor asking for two ports instead of zero. this compiles, but immediately crashes in ParaView when the plugin is selected from the Filters menu. It also immediately crashes if `vtkMyPolyLineWidgetRepresentation` is does nothing different, and simply calls the superclass constructor at initialization.

I’m not entirely sure where to go from here. I have investigated with reliance of `vtkSMNewWidgetRepresentationProxy` on `vtk3DWidgetRepresentation`, and I feel like my problem may be something to do with that relationship, but its possible there is also something much deeper I am missing, or something much easier I should be doing.

Thanks in advance for any advice!
