<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">2016-05-23 16:28 GMT+02:00 Elvis Stansvik <span dir="ltr"><<a href="mailto:elvis.stansvik@orexplore.com" target="_blank">elvis.stansvik@orexplore.com</a>></span>:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div><div><div><div><div><div><div>I'm trying to use a context view (my goal is to show an XYChart) inside a QVTKRenderWindowInteractor, but I'm struggling to get the initialization of render window / interactor right.<br><br></div>The docs for vtkRenderViewBase (base class for vtkContextView) says:<br><br>"In order to use the view with a QVTKWidget the following code is required to ensure the interactor and render window are initialized properly.<br><br>QVTKWidget *widget = new QVTKWidget;<br>vtkContextView *view = vtkContextView::New();<br>view->SetInteractor(widget->GetInteractor());<br>widget->SetRenderWindow(view->GetRenderWindow());"<br><br></div>but this is about QVTKWidget, the C++ widget class, which is quite different from the Python QVTKRenderWindowInteractor class.<br><br></div>My failed attempt to recreate this initialization sequence when using QVTKRenderWindowInteractor is this:<br><br><br>class TestWidget(QVTKRenderWindowInteractor):<br><br> def __init__(self, parent=None):<br><br> # We need a render window and interactor to pass to<br> # QVTKRenderWindowInteractor constructor.<br> self.renderWindow = vtkRenderWindow()<br> self.interactor = vtkGenericRenderWindowInteractor()<br> self.interactor.SetRenderWindow(self.renderWindow)<br><br> super(TestWidget, self).__init__(<br> parent, rw=self.renderWindow, iren=self.interactor)<br><br> # Create a context view and set it to use the same<br> # interactor as the QVTKRenderWindowInteractor.<br> self.contextView = vtkContextView()<br> self.contextView.SetInteractor(self.interactor)<br><br> # Create chart and add it to the scene of the context view.<br> self.chart = vtkChartXY()<br> self.contextView.GetScene().AddItem(self.chart)<br><br> # Initialize and start.<br> self.Initialize()<br> self.Start()<br><br><br>if __name__ == '__main__':<br><br> app = QApplication(argv)<br><br> widget = TestWidget()<br> widget.show()<br><br> exit(app.exec_())<br><br><br></div>But something goes wrong here, because two windows show up (see attached screenshot). The application also segfaults on exit. Besides, it looks very kludgy to have to do stuff before the call to super() here. Is this really the right way to use the API?<br><br></div>If anyone has worked with QVTKRenderWindowInteractor and vtkContextView, I'd much appriciate some advice.<br></div></div></div></blockquote><div><br></div><div>Inspired by an older post on this subject [1], I was able to get it partly working with:<br><br>class TestWidget(QVTKRenderWindowInteractor):<br><br> def __init__(self, parent=None):<br> super(TestWidget, self).__init__(parent)<br><br> self.contextView = vtkContextView()<br> self.chart = vtkChartXY()<br> self.contextView.GetScene().AddItem(self.chart)<br><br></div><div> # Add renderer of context view to the render window of the widget.<br></div><div> self.GetRenderWindow().AddRenderer(self.contextView.GetRenderer())<br><br> self.Initialize()<br> self.Start()<br><br>The chart is empty here, but I've verified by adding some items to it that it at least shows up correctly, in a single window.<br><br>The problem is that interaction of course doesn't work, and if I also add<br><br></div><div> self.contextView.SetInteractor(self._Iren)<br><br></div><div>to set the interactor of the context view to the vtkGenericRenderWindowInteractor backing the QVTKRenderWindowInteractor, I'm back to the problem with two windows showing up.<br><br></div><div>I need interaction to work, because my goal is to show an opacity function editor item in the chart.<br><br></div><div>Thankful for any and all advice!<br><br></div><div>Elvis<br><br></div><div>[1] <a href="http://www.vtk.org/pipermail/vtkusers/2011-July/068893.html">http://www.vtk.org/pipermail/vtkusers/2011-July/068893.html</a><br> <br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div><div><br></div>Cheers,<br></div>Elvis<br><br></div>
</blockquote></div><br></div></div>