[vtkusers] Replace Volume in render window

Xavius xavierelf at gmail.com
Fri Oct 7 07:49:27 EDT 2011


Hi all!
I have a trouble with VTK. I can't understand what is necessary to do to
replace current volume.
I've tried many things but without success. There's no troubles with a
single volume, but when I try to load another volume I face problems...

Below I post code, I think should work, but it doesn't...
Please help me to understand VTK!

// This method called when thread, that load DICOM image series finished
void MainWindow::onThreadFinished(void) {
	if (m_reader)
		m_reader->Delete();
	m_reader = m_itkLoadThread->getReader();

	render();
}

// Volume constructing
void MainWindow::render(void) {
	ExportFilterType::Pointer					itkExporter	= ExportFilterType::New();
	vtkSmartPointer<vtkImageImport>				vtkImporter	= vtkImageImport::New();
	vtkSmartPointer<vtkVolume>					volume		= vtkVolume::New();
	vtkSmartPointer<vtkVolumeTextureMapper3D>	mapper		=
vtkVolumeTextureMapper3D::New();

	itkExporter->SetInput(m_reader->GetOutput());
	itkExporter->Update();
	ConnectPipelines(itkExporter, vtkImporter);
	vtkImporter->Update();

	mapper->SetBlendModeToComposite();
	mapper->SetInput(vtkImporter->GetOutput());
	volume->SetProperty(m_volumeProperty);
	volume->SetMapper(mapper);

	changeVolume(volume);
	if (!m_eventLoopStarted) {
		m_iren->Start();
		m_eventLoopStarted = !m_eventLoopStarted;
	}
}

// Replacing an old volume for a new one
void MainWindow::changeVolume(vtkProp *aProp) {
	m_renderer->RemoveAllViewProps();
	m_renderer->AddVolume(aProp);
	vtkWidget->GetRenderWindow()->Render();
}

// Method called from constructor. Setting up render window.
void MainWindow::prepareRenderWindow(void) {
	vtkSmartPointer<vtkRenderWindow>					renWin		=
vtkWidget->GetRenderWindow();
	vtkSmartPointer<vtkInteractorStyleTrackballCamera>	irenStyle	=
vtkInteractorStyleTrackballCamera::New();
	m_iren		= vtkRenderWindowInteractor::New();
	m_renderer	= vtkRenderer::New();

	// Prepare Render Window
	renWin->AddRenderer(m_renderer);
	renWin->SetInteractor(m_iren);

	// Prepare Render Window Interactor
	m_iren->SetInteractorStyle(irenStyle);
	irenStyle->SetDefaultRenderer(m_renderer);
	m_iren->SetRenderWindow(renWin);

	// Prepare Renderer
	m_renderer->SetBackground(0.5, 0.5, 0.5);
	m_renderer->ResetCamera();

	renWin->Render();
}

--
View this message in context: http://vtk.1045678.n5.nabble.com/Replace-Volume-in-render-window-tp4879789p4879789.html
Sent from the VTK - Users mailing list archive at Nabble.com.



More information about the vtkusers mailing list