[vtkusers] Extend Imagestack dynamically

Andreas Klos aklos at outlook.de
Fri Mar 11 05:53:33 EST 2016


 Dear great VTK-Comunity,
I am actually trying to use vtkImageStack to create a imagestack of .png-Images. This seems to be very easy through VTK but it seem to be a bit harder when the Imagestack becomes extended dynamically. I'm working with Qt-plugin for visualstudio and VTK Version 7.0. When an Image is in the folder for visualisation purposes my Qt- GUI emits a Signal and transmit the full filename(path+filename) to a SLOT of my QVTK widget. If the SIGNAL is emitted the first time, my QVTK widget becomes created. The QVTK widget contains a Object of my visualisation pipeline  and executes the visualisation  pipeline through the call of the construtor. Till there, everything seems to work fine. The First Image is represented well. In Addition i should mention that the object of my visualisation pipeline has a method which should extend my imagestack. So if the SIGNAL is emitted again the SLOT of my QVTK widget should call this method. this is also well done. But it seems that the vtkStringArray of my visualisation pipline is not Extended with the new filename. so i can still just visualize the first Image. The Code of my visualisation Pipeline is shown below.

It would be greatful if somebody can help me or give me a hint if i had coded something wrong or if there is a better Approach of how to extend the imagestack dynamically.

HEADER.H-FILE:
#ifndef VTKDATAPROVIDER_H


#define VTKDATAPROVIDER_H



#include "vtkStringArray.h"


#include "vtkSmartPointer.h"


#include "vtkPNGReader.h"


#include "vtkImageSliceMapper.h"


#include "vtkImageSlice.h"


#include "vtkImageStack.h"


#include "vtkRenderer.h"


#include "vtkRenderWindow.h"


#include "vtkRenderWindowInteractor.h"


#include "vtkInteractorStyleImage.h"



class VTKDataProvider


 
 
 
{


 
 
public:


	VTKDataProvider(std::string _firstFilename);


	vtkRenderWindow* getRenderWindow(){ return renderWindow; }


	void setDisplayedSliceNumber(int _sliceNumber);


	void extendImageStackWithFile(std::string _filename);



private:


	vtkSmartPointer<vtkStringArray> filenameArray;


	vtkSmartPointer<vtkPNGReader> pngReader;


	vtkSmartPointer<vtkImageSliceMapper> sliceMapper;


	vtkSmartPointer<vtkImageSlice> imageSlice;


	vtkSmartPointer<vtkImageStack> imageStack;


	vtkSmartPointer<vtkRenderer> renderer;


	vtkSmartPointer<vtkRenderWindow> renderWindow;


	vtkSmartPointer<vtkRenderWindowInteractor> renderWindowInteractor;


	vtkSmartPointer<vtkInteractorStyleImage> interactorStyleImage;



	void readPNGFiles();


	void provideImageStackWithData();


	void addViewPorpToRenderer();


	void prepareRenderWindow();


	void startRender();



	int counter = 0;
 
 
 


};
 
 
SOURCEFILE.CPP-FILE
 
#include "VTKDataProvider.h"



VTKDataProvider::VTKDataProvider(std::string _firstFilename){


	filenameArray = vtkSmartPointer<vtkStringArray>::New();



	filenameArray->SetNumberOfValues(1);


	filenameArray->InsertValue(counter, _firstFilename.c_str());



	pngReader = vtkSmartPointer<vtkPNGReader>::New();


	sliceMapper = vtkSmartPointer<vtkImageSliceMapper>::New();


	imageSlice = vtkSmartPointer<vtkImageSlice>::New();


	imageStack = vtkSmartPointer<vtkImageStack>::New();



	renderer = vtkSmartPointer<vtkRenderer>::New();


	renderWindow = vtkSmartPointer<vtkRenderWindow>::New();


	renderWindowInteractor = vtkSmartPointer<vtkRenderWindowInteractor>::New();


	interactorStyleImage = vtkSmartPointer<vtkInteractorStyleImage>::New();


 
 
 
	


 
 
	readPNGFiles();
 
 
 


}


 
//the reading Operation is performed here


void VTKDataProvider::readPNGFiles(){


	pngReader->SetFileNames(filenameArray);


	pngReader->Update();



	provideImageStackWithData();
 
 
 


}


 
 


void VTKDataProvider::provideImageStackWithData(){


	//sliceMapper->SetInputData(pngReader->GetOutput());


	sliceMapper->SetInputConnection(pngReader->GetOutputPort());


	imageSlice->SetMapper(sliceMapper);


	imageStack->AddImage(imageSlice);


	addViewPorpToRenderer();
 
 
 


}


 
 


void VTKDataProvider::addViewPorpToRenderer(){


	renderer->AddViewProp(imageStack);



	prepareRenderWindow();
 
 
 


}


 
 


void VTKDataProvider::prepareRenderWindow(){


	renderWindow->AddRenderer(renderer);


	renderWindow->SetInteractor(renderWindowInteractor);


	renderWindowInteractor->SetInteractorStyle(interactorStyleImage);


 
 
 
 
	renderWindowInteractor->Initialize();
 
 
 


}


 
 


void VTKDataProvider::startRender(){


	renderWindow->Render();


	renderer->ResetCamera();


	renderWindow->Render();
 
 
 


}


 
//this method is needed to scroll through my QTGUI across the Images in the stack


void VTKDataProvider::setDisplayedSliceNumber(int _sliceNumber){


	sliceMapper->SetSliceNumber(_sliceNumber);


	renderWindow->Render();
 
 
 


}


 
 
 
 
 


 


//This method is called from the SLOT of my QVTK widget and should extend my imagestack
 
void VTKDataProvider::extendImageStackWithFile(std::string _filename){




	filenameArray->InsertValue(counter, _filename.c_str());


	pngReader->SetFileNames(filenameArray);


	pngReader->Update();



	startRender();
 
 
 


}
 		 	   		  
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/vtkusers/attachments/20160311/3c9e0556/attachment-0001.html>


More information about the vtkusers mailing list