<div>Hi, David,</div><div><br></div><div>Continue this thread. Now I upgrade from Activiz for VTK 5.8 to 7.0. And I define the vtkInteractorStyleImage::MouseWheelForwardEvt and MouseWheelBackwardEvt for slice switch. With VTK 5.8, it works but now it doesn't work for 7.0. With VTK 7.0, these 2 event handlers keep the old behavior which zooms in or out. It does not call the function I define to switch the slice number. My code is as follow:</div><div><br></div><div><span class="Apple-tab-span" style="white-space:pre"> </span>private void Display(vtkRenderWindow aRenderWindow, vtkAlgorithmOutput aData)</div><div> {</div><div> if (aData == null)</div><div> return;</div><div> m_imageViewer = vtkImageViewer2.New();</div><div> m_imageViewer.SetInputConnection(aData);</div><div> switch (m_sliceDirection)</div><div> {</div><div> case Direction.AXIAL:</div><div> m_imageViewer.SetSliceOrientationToXY();</div><div> break;</div><div> case Direction.CORONAL:</div><div> m_imageViewer.SetSliceOrientationToYZ();</div><div> break;</div><div> case Direction.SAGITTAL:</div><div> m_imageViewer.SetSliceOrientationToXZ();</div><div> break;</div><div> default:</div><div> break;</div><div> }</div><div><br></div><div> m_imageViewer.GetSliceRange(ref m_minSliceNumber, ref m_maxSliceNumber);</div><div><br></div><div> m_interactorStyle = vtkInteractorStyleImage.New();</div><div> m_moveforward = new vtkObject.vtkObjectEventHandler(interactor_MouseWheelForwardEvt);</div><div> m_movebackward = new vtkObject.vtkObjectEventHandler(interactor_MouseWheelBackwardEvt);</div><div> </div><div> m_interactorStyle.MouseWheelForwardEvt += m_moveforward;</div><div> m_interactorStyle.MouseWheelBackwardEvt += m_movebackward;</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>vtkObject.vtkObjectEventHandler(interactor_MouseWheelBackwardEvt);</div><div> </div><div> aRenderWindow.GetRenderers().InitTraversal();</div><div><br></div><div> m_renderer = aRenderWindow.GetRenderers().GetFirstRenderer();</div><div> m_renderer.SetBackground(0.0, 0.0, 0.0);</div><div><br></div><div> m_imageViewer.SetRenderWindow(aRenderWindow);</div><div> vtkRenderWindowInteractor interactor = aRenderWindow.GetInteractor();</div><div> interactor.SetInteractorStyle(m_interactorStyle);</div><div> </div><div> m_imageViewer.SetupInteractor(interactor);</div><div><br></div><div> m_currentSlice = m_minSliceNumber + (m_maxSliceNumber - m_minSliceNumber) / 2;</div><div> m_imageViewer.SetSlice(m_currentSlice);</div><div><br></div><div> m_imageViewer.Render();</div><div> } <br><br></div><div>Thanks</div><div>Liu Peng</div>
<span>
</span>
<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><br><br><span title="neteasefooter"><p> </p></span>