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

Liu_tj tjlp at netease.com
Sun Feb 28 03:17:45 EST 2016


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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/vtkusers/attachments/20160228/e13dc67b/attachment.html>


More information about the vtkusers mailing list