[vtkusers] System throw exceptions while interactoring window with mouse by vtkInteractorStyleImage using ActiViz.NET

David Cole DLRdave at aol.com
Sun Feb 28 09:27:57 EST 2016


Rather than doing += new and directly adding an event handler, save a pointer to the return value of new in each case as a C# member variable (which has scope at least as long as you want to be receiving the events...), and then do += with that variable.

That will keep a C# reference to it so it won't be garbage collected.

That will help, although I didn't analyze your whole code snippet thoroughly, so there may be more to do after that. But that should be your first step.

HTH,
David C.


> On Feb 28, 2016, at 3:17 AM, Liu_tj <tjlp at netease.com> wrote:
> 
> Hi, VTK guys,
> 
> At present I am ActiViz.NET 5.8.0 OpenSource Edition (x86) and Visual Studio 2015 C# to define a WPF user control for display DICOM series. I created event handlers for vtkInteractorStyleImage to handle mouse wheel forwared and mouse backward to switch the DICOM image. The application can display the image, when I forward or backward the mouse wheel, I get the system exception:
> 
> Unhandled Exception:  System.Exception: error: could not get registered type - mteIndex='4294967295' classNameKey='' 
> 
> I read the thread http://vtk.1045678.n5.nabble.com/ActiViz-NET-reports-unhandled-Exception-while-interacting-window-with-Mouse-td5720046.html, but I have no idea how to fix it.
> 
> Any glue for this issue?
> 
> Below is my user control class:
> 
> public partial class Dicom2DViewer : UserControl
>     {
>         public Dicom2DViewer()
>         {
>             InitializeComponent();
>             m_renderwinctrl = this.FindName("renderCtrl") as RenderWindowControl;
>             if (m_renderwinctrl != null)
>                 m_renderWindow = m_renderwinctrl.RenderWindow;
> 
>             //m_imagePlaneWidget = vtkImagePlaneWidget.New();
>             //m_imagePlaneWidgetFor3D = vtkImagePlaneWidget.New();
>         }
> 
>         public static readonly DependencyProperty DICOMDataProperty =
>              DependencyProperty.Register("DICOMData", typeof(vtkAlgorithmOutput),
>              typeof(Dicom2DViewer), new FrameworkPropertyMetadata(null, OnDICOMDataPropertyChanged));
> 
>         public vtkAlgorithmOutput DICOMData
>         {
>             get { return (vtkAlgorithmOutput)GetValue(DICOMDataProperty); }
>             set { SetValue(DICOMDataProperty, value); }
>         }
> 
>         private static void OnDICOMDataPropertyChanged(DependencyObject source, DependencyPropertyChangedEventArgs e)
>         {
>             Dicom2DViewer dicomViewer = source as Dicom2DViewer;
>             RenderWindowControl renderWindowCtrl = dicomViewer.renderCtrl;
>             vtkAlgorithmOutput vtkDICOMOutput = (vtkAlgorithmOutput)e.NewValue;
> 
>             dicomViewer.Display(renderWindowCtrl.RenderWindow, vtkDICOMOutput);
>         }
> 
>         private void Display(vtkRenderWindow aRenderWindow, vtkAlgorithmOutput aData)
>         {
>             if (aData == null)
>                 return;
> 
>             m_imageViewer = vtkImageViewer2.New();
>             m_imageViewer.SetInputConnection(aData);
>             m_imageViewer.GetSliceRange(ref m_minSliceNumber, ref m_maxSliceNumber);
> 
>             //vtkInteractorStyleImage interactorStyle = vtkInteractorStyleImage.New();
>             //interactorStyle.MouseWheelForwardEvt += new vtkObject.vtkObjectEventHandler(interactor_MouseWheelForwardEvt);
>             //interactorStyle.MouseWheelBackwardEvt += new vtkObject.vtkObjectEventHandler(interactor_MouseWheelBackwardEvt);
> 
>             //aRenderWindow.GetInteractor().SetInteractorStyle(interactorStyle);
>             vtkInteractorStyleImage m_interactorStyle = vtkInteractorStyleImage.New();
>             m_interactorStyle.MouseWheelForwardEvt += new vtkObject.vtkObjectEventHandler(interactor_MouseWheelForwardEvt);
>             m_interactorStyle.MouseWheelBackwardEvt += new vtkObject.vtkObjectEventHandler(interactor_MouseWheelBackwardEvt);
> 
>             aRenderWindow.GetInteractor().SetInteractorStyle(m_interactorStyle);
>             aRenderWindow.GetRenderers().InitTraversal();
> 
>             vtkRenderer ren;
>             while ((ren = aRenderWindow.GetRenderers().GetNextItem()) != null)
>                 ren.SetBackground(0.0, 0.0, 0.0);
> 
>             m_imageViewer.SetRenderWindow(aRenderWindow);
>             m_imageViewer.SetSlice(m_minSliceNumber);
> 
>             switch (m_sliceDirection)
>             {
>                 case Direction.AXIAL:
>                     m_imageViewer.SetSliceOrientationToXY();
>                     break;
>                 case Direction.CORONAL:
>                     m_imageViewer.SetSliceOrientationToYZ();
>                     break;
>                 case Direction.SAGITTAL:
>                     m_imageViewer.SetSliceOrientationToXZ();
>                     break;
>                 default:
>                     break;
>             }
> 
>             m_imageViewer.Render();
>         }
> 
>         private void interactor_MouseWheelForwardEvt(vtkObject sender, vtkObjectEventArgs e)
>         {
>             MoveSlice(1);
>         }
> 
>         void interactor_MouseWheelBackwardEvt(vtkObject sender, vtkObjectEventArgs e)
>         {
>             MoveSlice(0);
>         }
> 
>         private void MoveSlice(int direction) //0: move backward; 1: move forward
>         {
>             if (direction == 0)
>             {
>                 if (m_currentSlice > m_minSliceNumber)
>                 {
>                     m_currentSlice -= 1;
>                     m_imageViewer.SetSlice(m_currentSlice);
>                     m_imageViewer.Render();
>                 }
>             }
>             else
>             {
>                 if (m_currentSlice < m_maxSliceNumber)
>                 {
>                     m_currentSlice += 1;
>                     m_imageViewer.SetSlice(m_currentSlice);
>                     m_imageViewer.Render();
>                 }
>             }            
>         }
> 
>         public vtkRenderWindow GetRenderWindow()
>         {
>             return m_renderWindow;
>         }
> 
>         public void AddRenderer(vtkRenderer renderer)
>         {
>             m_renderWindow.AddRenderer(renderer);
>         }
> 
>         public void SetViewDirection(Direction direction)
>         {
>             m_sliceDirection = direction;
>         }
> 
>         private RenderWindowControl m_renderwinctrl = null;
>         private vtkRenderWindow m_renderWindow = null;
>         private vtkImageViewer2 m_imageViewer = null;
>         vtkInteractorStyleImage m_interactorStyle = null;
>         private Direction m_sliceDirection;
> 
>         int m_currentSlice = 0;
>         int m_minSliceNumber = 0;
>         int m_maxSliceNumber = 0;
>     }  
> 
> 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