[vtkusers] vtkRenderWindowInteractor.start() crashes in C# application using Activiz

David Cole DLRdave at aol.com
Tue Mar 1 10:59:41 EST 2016


When using ActiViz .NET, you typically don't need to create your own
interactor object. The render window control contains a RenderWindow,
an Interactor and an InteractorStyle that are all connected to each
other by default. Interactor.Start starts a windows event loop, and is
used by standalone programs not using a UI framework. When you're
using a UI framework, you don't need to call it.

Just remove your instantiation of the interactor, and do not call
Start. If you are using a Windows Forms application to display your
render window control, just show the form, and let the Windows Forms
framework handle your event loop.


HTH,
David C.


On Tue, Mar 1, 2016 at 10:32 AM, Liu_tj <tjlp at netease.com> wrote:
> Hi, VTK guys,
>
> I use Activiz 5.8 Open Source edition to display Axial, Sagittal and Coronal
> view for DICOM series in WPF application. In the XAML, I add a button and a
> vtkRenderWindowControl component. And a method ShowImagePlaneWidget() is
> defined. I just want to click the button then ShowImagePlaneWidget() is
> called, the DICOM series is loaded and displayed. But it does not work and
> the application crashes at vtkRenderWindowInteractor.start().
>
> However, the DICOM can be displayed if ShowImagePlaneWidget() is called in
> the Window_Load event handler.
>
> What happens? How to fix it? I am working this issue for some time.
>
> Below is my code:
>
> private void Window_Loaded(object sender, RoutedEventArgs e)
>         {
>            ShowImagePlaneWidget();
>         }
>
>         private void btnLoad_Click(object sender, RoutedEventArgs e)
>         {
>            ShowImagePlaneWidget();
>         }
>         private void ShowImagePlaneWidget()
>         {
>             vtkImagePlaneWidget m_imagePlaneWidgetX =
> vtkImagePlaneWidget.New();
>             vtkImagePlaneWidget m_imagePlaneWidgetY =
> vtkImagePlaneWidget.New();
>             vtkImagePlaneWidget m_imagePlaneWidgetZ =
> vtkImagePlaneWidget.New();
>             vtkRenderWindowInteractor m_interactor =
> vtkRenderWindowInteractor.New();
>
>             vtkRenderWindow aRenderWindow = renderctrl.RenderWindow;
>
>             vtkDICOMImageReader reader = vtkDICOMImageReader.New();
>
> reader.SetDirectoryName(@"C:\Personal\code\ReadDICOMSeries\build\Debug\IMG\Dental_Lossy_Compressed");
>             reader.Update();
>
>             int[] dims = new int[3];
>             dims = reader.GetOutput().GetDimensions();
>
>             vtkImageCast readerImageCast = vtkImageCast.New();
>             readerImageCast.SetInput((vtkDataObject)reader.GetOutput());
>             //readerImageCast.SetOutputScalarTypeToUnsignedChar();
>             readerImageCast.ClampOverflowOn();
>             readerImageCast.Update();
>
>             m_interactor.SetRenderWindow(aRenderWindow);
>             vtkRenderer renderer =
> aRenderWindow.GetRenderers().GetFirstRenderer();
>
>             vtkCellPicker picker = vtkCellPicker.New();
>             picker.SetTolerance(0.005);
>             //m_imagePlaneWidgetX.DebugOn();
>             m_imagePlaneWidgetX.SetDefaultRenderer(renderer);
>             PrepareImagePlaneWidget(m_imagePlaneWidgetX,
> readerImageCast.GetOutput(), m_interactor, picker, dims, Direction.CORONAL);
>             vtkRenderWindowInteractor tmpint =
> m_imagePlaneWidgetX.GetInteractor();
>             PrepareImagePlaneWidget(m_imagePlaneWidgetY,
> readerImageCast.GetOutput(), m_interactor, picker, dims,
> Direction.SAGITTAL);
>             PrepareImagePlaneWidget(m_imagePlaneWidgetZ,
> readerImageCast.GetOutput(), m_interactor, picker, dims, Direction.AXIAL);
>
>             m_interactor.Initialize();
>             m_interactor.Start();
>             aRenderWindow.Render();
>             return;
>         }
>
>         private void PrepareImagePlaneWidget(vtkImagePlaneWidget
> planeWidget, vtkImageData data, vtkRenderWindowInteractor interactor,
> vtkCellPicker picker, int[] dimensions, Direction direction)
>         {
>             planeWidget.SetInteractor(interactor);
>
>             planeWidget.SetPicker(picker);
>             planeWidget.RestrictPlaneToVolumeOn();
>
>             planeWidget.DisplayTextOn();
>             planeWidget.TextureInterpolateOff();
>             planeWidget.SetResliceInterpolateToLinear();
>
>             planeWidget.SetInput(data);
>
>             switch (direction)
>             {
>                 case Direction.AXIAL:
>                     planeWidget.SetKeyPressActivationValue((sbyte)'z');
>                     planeWidget.SetPlaneOrientationToZAxes();
>                     planeWidget.GetPlaneProperty().SetColor(0.0, 0.0, 1.0);
>                     break;
>                 case Direction.CORONAL:
>                     planeWidget.SetKeyPressActivationValue((sbyte)'x');
>                     planeWidget.SetPlaneOrientationToXAxes();
>                     planeWidget.GetPlaneProperty().SetColor(1.0, 0.0, 0.0);
>                     break;
>                 case Direction.SAGITTAL:
>                     planeWidget.SetKeyPressActivationValue((sbyte)'y');
>                     planeWidget.SetPlaneOrientationToYAxes();
>                     planeWidget.GetPlaneProperty().SetColor(0.0, 1.0, 0.0);
>                     break;
>             }
>             planeWidget.SetSliceIndex(dimensions[(int)direction] / 2);
>             planeWidget.GetTexturePlaneProperty().SetOpacity(1);
>
>
>             planeWidget.On();
>             planeWidget.InteractionOn();
>         }
>
> Thanks
> Liu Peng
>
>
>
>
>
> _______________________________________________
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at
> http://www.kitware.com/opensource/opensource.html
>
> Please keep messages on-topic and check the VTK FAQ at:
> http://www.vtk.org/Wiki/VTK_FAQ
>
> Search the list archives at: http://markmail.org/search/?q=vtkusers
>
> Follow this link to subscribe/unsubscribe:
> http://public.kitware.com/mailman/listinfo/vtkusers
>


More information about the vtkusers mailing list