[vtkusers] vtk c# ReadDicomSeries images zoomed while scrolled

Yakub Aqib yakub.rouge at gmail.com
Wed Sep 5 06:07:41 EDT 2012


Dear sir/madam

Hi,

I am a new user of VTK ActiViz.Net. I got a serious problem. I have
successfully build an examples (ReadDICOMSeries) by using the Activiz.net
in c# with visual studio and also build the cxx source. But when I run the
program they don't work in the same way. In the cxx program, the slicer
looks working nice, while on the other hand, the c# program seems broken.
When I slice the images in the c# program, it seems being zoomed while I
scroll the mouse wheel. But it is not happened when I use the keyboard
keyUp and keyDown to change the slice.





Here's my c# source code :

===============================================

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Kitware.VTK;
using Kitware.mummy;

using System.Diagnostics;
using System.IO;

namespace Pyramid
{
    public partial class Form1 : Form
    {
        vtkImageViewer2 _ImageViewer;

        int _Slice;
        int _MinSlice;
        int _MaxSlice;

        public Form1()
        {

            InitializeComponent();
        }
        private void ReadDICOMSeries() {
         vtkDICOMImageReader reader = vtkDICOMImageReader.New();
         reader.SetDirectoryName("DICOM");
         reader.Update();


        vtkImageShiftScale shift = vtkImageShiftScale.New();
        shift.SetInputConnection( reader.GetOutputPort() );
        shift.SetShift( 1024);


         _ImageViewer = vtkImageViewer2.New();
         _ImageViewer.SetInputConnection(reader.GetOutputPort());
         _ImageViewer.GetSliceRange(ref _MinSlice, ref _MaxSlice);
         Debug.WriteLine("slices range from : " + _MinSlice.ToString() + "
to " + _MaxSlice.ToString());

         vtkRenderWindow renderWindow = renderWindowControl1.RenderWindow;


         vtkRenderWindowInteractor iren = vtkRenderWindowInteractor.New();

         vtkInteractorStyleImage interactorStyle =
vtkInteractorStyleImage.New();



         iren.MouseWheelForwardEvt += new
vtkObject.vtkObjectEventHandler(interactor_MouseWheelForwardEvt);
         iren.MouseWheelBackwardEvt += new
vtkObject.vtkObjectEventHandler(interactor_MouseWheelBackwardEvt);

         iren.SetInteractorStyle(interactorStyle);

         _ImageViewer.SetupInteractor(iren);
         _ImageViewer.SetRenderWindow(renderWindow);
         _ImageViewer.SetSlice(_MinSlice);
         _ImageViewer.Render();
      }



      private void MoveForwardSlice() {
         Debug.WriteLine(_Slice.ToString());
         if(_Slice < _MaxSlice) {
            _Slice += 1;
            _ImageViewer.SetSlice(_Slice);
            _ImageViewer.Render();
         }

      }


      private void MoveBackwardSlice() {
         Debug.WriteLine(_Slice.ToString());
         if(_Slice > _MinSlice) {
            _Slice -= 1;
            _ImageViewer.SetSlice(_Slice);
            _ImageViewer.Render();
         }
      }



      protected override bool ProcessCmdKey(ref
System.Windows.Forms.Message msg, System.Windows.Forms.Keys keyData) {

         if(keyData == System.Windows.Forms.Keys.Up) {
            MoveForwardSlice();
            return true;
         }
         else if(keyData == System.Windows.Forms.Keys.Down) {
            MoveBackwardSlice();
            return true;
         }

         else if(
               keyData == System.Windows.Forms.Keys.F
            || keyData == System.Windows.Forms.Keys.L
         ) {
            return true;
         }
         return false;
      }



      void interactor_MouseWheelForwardEvt(vtkObject sender,
vtkObjectEventArgs e) {
         MoveForwardSlice();
      }

      void interactor_MouseWheelBackwardEvt(vtkObject sender,
vtkObjectEventArgs e) {
          if (_Slice > _MinSlice)
          {
              MoveBackwardSlice();
          }
     }

        private void Form1_Load(object sender, EventArgs e)
        {

        }


        private void renderWindowControl1_Load_1(object sender, EventArgs e)
        {
            try
            {
                ReadDICOMSeries();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Exception",
MessageBoxButtons.OK);
            }
        }
    }
}


===========================================

I've tried to resolve it in many ways like changing the interactor or
override the interactor. But it's not working. Any suggestion to resolve
this problem please. I hope someone can help me to resolve this problem,
please help me. Thank you very much



Regards,
-- 
Yakub Aqib Bayhaqi
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20120905/956447d4/attachment.htm>


More information about the vtkusers mailing list