[vtkusers] vtkRenderWindowInteractor.start() crashes in C# application using Activiz
Liu_tj
tjlp at netease.com
Wed Mar 2 22:00:54 EST 2016
Hi,David,
Before I call SetInteractor() or SetInteractorStyle(), do I need to explicitly call some specific functions to release the current interactor or interactorStyle? Or just let .NET framework to GC it automatically.
Thanks
Liu Peng
在2016-03-02,"David Cole" <DLRdave at aol.com> 写道: -----原始邮件-----
发件人:"David Cole" <DLRdave at aol.com>
发送时间:2016年03月2日 星期三
收件人:"Liu_tj" <tjlp at netease.com>
主题:Re: Re: [vtkusers] vtkRenderWindowInteractor.start() crashes in C# application using Activiz
Sure. If you want to use your own interactor, just instantiate it and
call SetInteractor on the render window. And if you want your own
style, instantiate it and call SetInteractorStyle.
ActiViz is really just a thin C# wrapper around VTK, so all the usual
VTK stuff applies.
HTH,
David C.
On Tue, Mar 1, 2016 at 8:52 PM, Liu_tj <tjlp at netease.com> wrote:
> Hi, David,
>
> Thanks. You are right. After I remove the instantiation of the interactor,
> the code works.
>
> So, if the render window control contains Interactor and InteractorStyle,
> what kind of Interactor and interactorStyle it uses? Can we specify them by
> ourself if the default Interactor and InteractorStyle can't meet our
> requirement?
>
> Thanks
> Liu Peng
>
> 在2016-03-01,"David Cole" <DLRdave at aol.com> 写道:
>
> -----原始邮件-----
> 发件人:"David Cole" <DLRdave at aol.com>
> 发送时间:2016年03月1日 星期二
> 收件人:"Liu_tj" <tjlp at netease.com>
> 抄送:"vtkusers" <vtkusers at vtk.org>
> 主题:Re: [vtkusers] vtkRenderWindowInteractor.start() crashes in C#
> application using Activiz
>
> 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
>>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/vtkusers/attachments/20160303/ed6ffabf/attachment.html>
More information about the vtkusers
mailing list