[vtkusers] VTK Pipeline

Xavius xavierelf at gmail.com
Tue Oct 25 04:24:44 EDT 2011


Hi all!
I have some problems with pipeline organization. I use VTK for volume
rendering of DICOM-based images. I can't understand when should I delete
initial data, because of double memory allocation.
Here is abstract scheme of my app:


class LoadThread {
private:
	gdcm::Directory::FilenameType	 m_dir;
	vtkImageData									*m_imageData;

public:
	void setDir(gdcm::Directory::FilenameType	&dir) { m_dir = dir; }
	void setImageData(vtkImageData *aImageData) { m_imageData = aImageData;}

	void run() {
		vtkGDCMImageReader				*reader					= vtkGDCMImageReader::New();
		vtkImageChangeInformation	*changedReader	=
vtkImageChangeInformation::New();
		vtkImageChangeInformation	*changedReader2	=
vtkImageChangeInformation::New();
		vtkImageFlip							*flip1					= vtkImageFlip::New();
		vtkImageFlip							*flip2					= vtkImageFlip::New();
		vtkImageFlip							*flip3					= vtkImageFlip::New();
		gdcm::IPPSorter	sorter;
		gdcm::Directory dir;
			
		uint nfiles = dir.Load(m_dir, false);
		gdcm::Directory::FilenamesType dcmFileNames = dir.GetFilenames();
		
		// Sorting filenames
		// ...
		sorter.Sort(unsortedFileNames);
		// ...
		
		// Reading DICOM images
		reader->SetFileNames(sortedFileArray);
		reader->ReleaseDataFlagOn();
		reader->Update();
		
		// Set spacing
		changedReader->SetInput(reader->GetOutput());
		// ...
		changedReader->Update();
		
		// Setup right orientation
		// flip1 or/and flip2 or/and flip3 -> m_imageData
		
		// Setup origin
		changedReader2->SetInput(m_imageData);
		// ...
		changedReader2->Update();
		
		m_imageData->ReleaseData();
		m_imageData->DeepCopy(changedReader2->GetOutput());
	}
}

MainThread {
private:
	LoadThread 																				*m_loadThread;
	vtkImageData 																			*m_volumeData;
	vtkSmartPointer<vtkVolume>												 m_volume;
	vtkSmartPointer<vtkFixedPointVolumeRayCastMapper>	 m_mapper;
	vtkSmartPointer<vtkRenderer>											 m_renderer;
public:
	MainThread() {
		prepareRenderWindow();
	}
	void loadDICOMData(void) {
		gdcm::Directory::FilenameType	 dir = ...; // Directory retrieving omitted
		if (m_volumeData) {
			m_volumeData->Delete();
		}
		m_imageData = vtkImageData::New();
		m_loadThread = new LoadThread;
		m_loadThread->setDir(dir);
		m_loadThread->setImageData(m_volumeData);
		m_loadThread->start();
	}
	
	void onThreadFininshed(void) {
		render();
	}
	
	void render(void) {
		renewRenWin();
		
		m_mapper->SetBlendModeToComposite();
		m_mapper->SetInput(m_volumeData);
		
		m_volume->SetProperty(volumeProperty); // Some volume properties
		m_volume->SetMapper(m_mapper);
		
		m_renderer->RemoveAllViewProps();
		m_renderer->AddVolume(m_volume);
		
		m_renderer->ResetCamera(m_volume->GetBounds());
		
		someWidget->update();
	}
	
	void prepareRenderWindow(void) {
		vtkRenderWindow						*renWin	= vtkRenderWindow::New();
		vtkRenderWindowInteractor	*iren		= vtkRenderWindowInteractor::New();
		m_renderer	= vtkRenderer::New();
		m_renderer->SetBackground(0.5, 0.5, 0.5);
		someWidget->setRenderWindow(renWin);
		renWin->SetInteractor(iren);
		iren->SetRenderWindow(renWin);
		renWin->AddRenderer(m_renderer);
		renWin->Delete();
		iren->Inintialize();
		iren->Delete();
	}

	void renewRenWin(void) {
		if (m_volume)			m_volume->Delete();
		if (m_mapper)			m_mapper->Delete();
		m_volume			= vtkVolume::New();					
		m_mapper			= vtkFixedPointVolumeRayCastMapper::New();
		m_mapper->ReleaseDataFlagOn();
	}
}

Please point me my mistakes.

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



More information about the vtkusers mailing list