[vtkusers] vtkImageViewer2 Display problems

zagwin zagwin at gmail.com
Thu May 28 19:38:20 EDT 2015


Hello VTK-Users,

I want to load a dicom image, and display it on a vtkimageviewer2. I found
two problems, and can not fix them. any suggestion will be appreciated!

First, when I ONLY change the vtkImageData scalar value, and set this image
to viewer again. nothing happened in vtkimageviewer2. However, if I generate
a new image with the same scalar values, the viewer will show this new
image.  as coded in the following "ProcessData() function"

Second, when I want to adjust the window/level, it will change drastically,
not slowly.
However, when I use
"image_view->GetInteractorStyle()->RemoveAllObservers();" it works. but I
don't know who really handle the vtkCommand::WindowLevelEvent? And, even it
does adjust the "display", the GetColorWindow/GetColorLevel does NOT give
the "changed" value. 

My codes looks like:
//mainwindow.h
class MainWindow : public QMainWindow
{
    Q_OBJECT
   
public:
    explicit MainWindow(QWidget *parent = 0);
    ~MainWindow();

    typedef signed short   InputPixelType;//Pixel Type
    static const unsigned int InputDimension = 2;//Dimension of image

private slots:
    int DICOMseq();
   void ProcessData();
private:

     vtkSmartPointer<vtkImageViewer2> image_view;
	 vtkSmartPointer<vtkImageData> m_image;
    Ui::MainWindow *ui;
};

//mainwindow.cpp
MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
	ui->setupUi(this);

	//Qt Signal slot    
	connect(ui->actionDICOM_Sequence,SIGNAL(triggered()),this,
SLOT(DICOMseq()));
	connect(ui->actionExit,SIGNAL(triggered()),this, SLOT(close()));
	connect(ui->actionProcess,SIGNAL(triggered()),this, SLOT(ProcessData()));

	image_view = vtkSmartPointer<vtkImageViewer2>::New();

	//set VTK Viewer to QVTKWidget in Qt's UI
	ui->qVTK1->SetRenderWindow(image_view->GetRenderWindow());
	image_view->SetupInteractor(ui->qVTK1->GetRenderWindow()->GetInteractor());
	//image_view->GetInteractorStyle()->RemoveAllObservers();
}

int MainWindow::DICOMseq()
{
	typedef itk::Image< InputPixelType, InputDimension > InputImageType;//Image
Type
	typedef itk::ImageFileReader<InputImageType>   ReaderType;
	ReaderType::Pointer reader = ReaderType::New();
        reader->SetFileName("test.dcm");
	reader->Update();
        
        typedef itk::ImageToVTKImageFilter<InputImageType> ConnectorType;
        ConnectorType::Pointer connector   = ConnectorType::New();
	connector->SetInput( reader->GetOutput() );
        connector->Update();

        m_image = vtkSmartPointer<vtkImageData>::New();
	m_image->DeepCopy(connector->GetOutput());

        image_view->SetInputData(m_image);
	image_view->GetRenderer()->ResetCamera();
	image_view->Render();
}

void MainWindow::ProcessData()
{
	//vtkSmartPointer<vtkImageData> image =
vtkSmartPointer<vtkImageData>::New();
	//image->DeepCopy(m_image.GetPointer());
	//int *dims = image->GetDimensions();
	int *dims = m_image->GetDimensions();

	for(int z = 0; z < dims[2]; z++)
	{
		for (int y = 0; y < dims[1]; y++)
		{
			for (int x = 0; x < dims[0]; x++)
			{
				InputPixelType *pimg =
static_cast<InputPixelType*>(m_image->GetScalarPointer(x,y,z));

				pimg[0] = 255;
			}
		}
	}

	image_view->SetInputData(m_image);
	image_view->GetRenderer()->ResetCamera();
	image_view->Render();
}





--
View this message in context: http://vtk.1045678.n5.nabble.com/vtkImageViewer2-Display-problems-tp5732050.html
Sent from the VTK - Users mailing list archive at Nabble.com.


More information about the vtkusers mailing list