[vtkusers] vtkRenderWindowInteractor.start() crashes in C# application using Activiz
Liu_tj
tjlp at netease.com
Tue Mar 1 10:32:57 EST 2016
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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/vtkusers/attachments/20160301/94d8174f/attachment.html>
More information about the vtkusers
mailing list