Hi, David,<br><br>It seems that this issue is solved by adding a private member in the class for the vtkInteractorStyleImage instead of the event handler.<br><div><br>BR,<br></div><br> 在2016-02-28,"David Cole" <DLRdave@aol.com> 写道:
<blockquote id="isReplyContent" style="padding-left:1ex; margin: 0px 0px 0px 0.8ex; BORDER-LEFT: #ccc 1px solid">
-----原始邮件-----<br>
<b>发件人:</b>"David Cole" <DLRdave@aol.com> <br>
<b>发送时间:</b>2016年02月28日 星期日<br>
<b>收件人:</b>"Liu_tj" <tjlp@netease.com><br>
<b>抄送:</b>"vtkusers" <vtkusers@vtk.org><br>
<b>主题:</b>Re: [vtkusers] System throw exceptions while interactoring window with mouse by vtkInteractorStyleImage using ActiViz.NET<br>
<br>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.<br><br>That will keep a C# reference to it so it won't be garbage collected.<br><br>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.<br><br>HTH,<br>David C.<br><br><br>> On Feb 28, 2016, at 3:17 AM, Liu_tj <<a href="mailto:tjlp@netease.com">tjlp@netease.com</a>> wrote:<br>> <br>> Hi, VTK guys,<br>> <br>> 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:<br>> <br>> Unhandled Exception: System.Exception: error: could not get registered type - mteIndex='4294967295' classNameKey='' <br>> <br>> 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.<br>> <br>> Any glue for this issue?<br>> <br>> Below is my user control class:<br>> <br>> public partial class Dicom2DViewer : UserControl<br>> {<br>> public Dicom2DViewer()<br>> {<br>> InitializeComponent();<br>> m_renderwinctrl = this.FindName("renderCtrl") as RenderWindowControl;<br>> if (m_renderwinctrl != null)<br>> m_renderWindow = m_renderwinctrl.RenderWindow;<br>> <br>> //m_imagePlaneWidget = vtkImagePlaneWidget.New();<br>> //m_imagePlaneWidgetFor3D = vtkImagePlaneWidget.New();<br>> }<br>> <br>> public static readonly DependencyProperty DICOMDataProperty =<br>> DependencyProperty.Register("DICOMData", typeof(vtkAlgorithmOutput),<br>> typeof(Dicom2DViewer), new FrameworkPropertyMetadata(null, OnDICOMDataPropertyChanged));<br>> <br>> public vtkAlgorithmOutput DICOMData<br>> {<br>> get { return (vtkAlgorithmOutput)GetValue(DICOMDataProperty); }<br>> set { SetValue(DICOMDataProperty, value); }<br>> }<br>> <br>> private static void OnDICOMDataPropertyChanged(DependencyObject source, DependencyPropertyChangedEventArgs e)<br>> {<br>> Dicom2DViewer dicomViewer = source as Dicom2DViewer;<br>> RenderWindowControl renderWindowCtrl = dicomViewer.renderCtrl;<br>> vtkAlgorithmOutput vtkDICOMOutput = (vtkAlgorithmOutput)e.NewValue;<br>> <br>> dicomViewer.Display(renderWindowCtrl.RenderWindow, vtkDICOMOutput);<br>> }<br>> <br>> private void Display(vtkRenderWindow aRenderWindow, vtkAlgorithmOutput aData)<br>> {<br>> if (aData == null)<br>> return;<br>> <br>> m_imageViewer = vtkImageViewer2.New();<br>> m_imageViewer.SetInputConnection(aData);<br>> m_imageViewer.GetSliceRange(ref m_minSliceNumber, ref m_maxSliceNumber);<br>> <br>> //vtkInteractorStyleImage interactorStyle = vtkInteractorStyleImage.New();<br>> //interactorStyle.MouseWheelForwardEvt += new vtkObject.vtkObjectEventHandler(interactor_MouseWheelForwardEvt);<br>> //interactorStyle.MouseWheelBackwardEvt += new vtkObject.vtkObjectEventHandler(interactor_MouseWheelBackwardEvt);<br>> <br>> //aRenderWindow.GetInteractor().SetInteractorStyle(interactorStyle);<br>> vtkInteractorStyleImage m_interactorStyle = vtkInteractorStyleImage.New();<br>> m_interactorStyle.MouseWheelForwardEvt += new vtkObject.vtkObjectEventHandler(interactor_MouseWheelForwardEvt);<br>> m_interactorStyle.MouseWheelBackwardEvt += new vtkObject.vtkObjectEventHandler(interactor_MouseWheelBackwardEvt);<br>> <br>> aRenderWindow.GetInteractor().SetInteractorStyle(m_interactorStyle);<br>> aRenderWindow.GetRenderers().InitTraversal();<br>> <br>> vtkRenderer ren;<br>> while ((ren = aRenderWindow.GetRenderers().GetNextItem()) != null)<br>> ren.SetBackground(0.0, 0.0, 0.0);<br>> <br>> m_imageViewer.SetRenderWindow(aRenderWindow);<br>> m_imageViewer.SetSlice(m_minSliceNumber);<br>> <br>> switch (m_sliceDirection)<br>> {<br>> case Direction.AXIAL:<br>> m_imageViewer.SetSliceOrientationToXY();<br>> break;<br>> case Direction.CORONAL:<br>> m_imageViewer.SetSliceOrientationToYZ();<br>> break;<br>> case Direction.SAGITTAL:<br>> m_imageViewer.SetSliceOrientationToXZ();<br>> break;<br>> default:<br>> break;<br>> }<br>> <br>> m_imageViewer.Render();<br>> }<br>> <br>> private void interactor_MouseWheelForwardEvt(vtkObject sender, vtkObjectEventArgs e)<br>> {<br>> MoveSlice(1);<br>> }<br>> <br>> void interactor_MouseWheelBackwardEvt(vtkObject sender, vtkObjectEventArgs e)<br>> {<br>> MoveSlice(0);<br>> }<br>> <br>> private void MoveSlice(int direction) //0: move backward; 1: move forward<br>> {<br>> if (direction == 0)<br>> {<br>> if (m_currentSlice > m_minSliceNumber)<br>> {<br>> m_currentSlice -= 1;<br>> m_imageViewer.SetSlice(m_currentSlice);<br>> m_imageViewer.Render();<br>> }<br>> }<br>> else<br>> {<br>> if (m_currentSlice < m_maxSliceNumber)<br>> {<br>> m_currentSlice += 1;<br>> m_imageViewer.SetSlice(m_currentSlice);<br>> m_imageViewer.Render();<br>> }<br>> } <br>> }<br>> <br>> public vtkRenderWindow GetRenderWindow()<br>> {<br>> return m_renderWindow;<br>> }<br>> <br>> public void AddRenderer(vtkRenderer renderer)<br>> {<br>> m_renderWindow.AddRenderer(renderer);<br>> }<br>> <br>> public void SetViewDirection(Direction direction)<br>> {<br>> m_sliceDirection = direction;<br>> }<br>> <br>> private RenderWindowControl m_renderwinctrl = null;<br>> private vtkRenderWindow m_renderWindow = null;<br>> private vtkImageViewer2 m_imageViewer = null;<br>> vtkInteractorStyleImage m_interactorStyle = null;<br>> private Direction m_sliceDirection;<br>> <br>> int m_currentSlice = 0;<br>> int m_minSliceNumber = 0;<br>> int m_maxSliceNumber = 0;<br>> } <br>> <br>> Thanks <br>> Liu Peng<br>> _______________________________________________<br>> Powered by www.kitware.com<br>> <br>> Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html<br>> <br>> Please keep messages on-topic and check the VTK FAQ at: http://www.vtk.org/Wiki/VTK_FAQ<br>> <br>> Search the list archives at: http://markmail.org/search/?q=vtkusers<br>> <br>> Follow this link to subscribe/unsubscribe:<br>> http://public.kitware.com/mailman/listinfo/vtkusers<br></blockquote>