[Insight-users] ITK -> VTK -> QT Volume Rendering Problem

circass circass at gmail.com
Mon Jan 4 10:18:45 EST 2010


Hi Cory,
This is error message that it gave when i add renderer on the qvtkwidget in
debug mode.

//Additional information: Attempted to read or write protected memory. This
is often an indication that //other memory is corrupt.

and when i try to compile same code in release mode it gaves me that error.

//Qvtkwidget must construct a qapplication beafore a qpaintdevice

:::::::::::::::::::::::::::::::::::::::::::::::::::::::This is my code
::::::::::::::::::::::::::::::::::::::::::::

template <typename ITK_Exporter, typename VTK_Importer>
void ConnectPipelines(ITK_Exporter exporter, VTK_Importer* importer)
{
 
importer->SetUpdateInformationCallback(exporter->GetUpdateInformationCallback());
 
importer->SetPipelineModifiedCallback(exporter->GetPipelineModifiedCallback());
  importer->SetWholeExtentCallback(exporter->GetWholeExtentCallback());
  importer->SetSpacingCallback(exporter->GetSpacingCallback());
  importer->SetOriginCallback(exporter->GetOriginCallback());
  importer->SetScalarTypeCallback(exporter->GetScalarTypeCallback());
 
importer->SetNumberOfComponentsCallback(exporter->GetNumberOfComponentsCallback());
 
importer->SetPropagateUpdateExtentCallback(exporter->GetPropagateUpdateExtentCallback());
  importer->SetUpdateDataCallback(exporter->GetUpdateDataCallback());
  importer->SetDataExtentCallback(exporter->GetDataExtentCallback());
  importer->SetBufferPointerCallback(exporter->GetBufferPointerCallback());
  importer->SetCallbackUserData(exporter->GetCallbackUserData());
}

template <typename VTK_Exporter, typename ITK_Importer>
void ConnectPipelines(VTK_Exporter* exporter, ITK_Importer importer)
{
 
importer->SetUpdateInformationCallback(exporter->GetUpdateInformationCallback());
 
importer->SetPipelineModifiedCallback(exporter->GetPipelineModifiedCallback());
  importer->SetWholeExtentCallback(exporter->GetWholeExtentCallback());
  importer->SetSpacingCallback(exporter->GetSpacingCallback());
  importer->SetOriginCallback(exporter->GetOriginCallback());
  importer->SetScalarTypeCallback(exporter->GetScalarTypeCallback());
 
importer->SetNumberOfComponentsCallback(exporter->GetNumberOfComponentsCallback());
 
importer->SetPropagateUpdateExtentCallback(exporter->GetPropagateUpdateExtentCallback());
  importer->SetUpdateDataCallback(exporter->GetUpdateDataCallback());
  importer->SetDataExtentCallback(exporter->GetDataExtentCallback());
  importer->SetBufferPointerCallback(exporter->GetBufferPointerCallback());
  importer->SetCallbackUserData(exporter->GetCallbackUserData());
}

Volume::Volume(QWidget *parent, Qt::WFlags flags)
	: QMainWindow(parent, flags)
{
	ui.setupUi(this);
	
	typedef unsigned short    PixelType;
	const unsigned int      Dimension = 3;
	
	typedef itk::OrientedImage< PixelType, Dimension >         ImageType;
	typedef itk::ImageSeriesReader< ImageType >        ReaderType;
	ReaderType::Pointer reader = ReaderType::New();
	typedef itk::GDCMImageIO       ImageIOType;
	ImageIOType::Pointer dicomIO = ImageIOType::New();

	reader->SetImageIO( dicomIO );
	typedef itk::GDCMSeriesFileNames NamesGeneratorType;
	NamesGeneratorType::Pointer nameGenerator = NamesGeneratorType::New();

	nameGenerator->SetUseSeriesDetails( true );
	nameGenerator->SetDirectory(
"C:\\Users\\circass\\Desktop\\YEDEKLERRRR\\MANIX\\CER-CT\\ANGIO CT" );


	typedef std::vector< std::string >    SeriesIdContainer;

	const SeriesIdContainer & seriesUID = nameGenerator->GetSeriesUIDs();

	SeriesIdContainer::const_iterator seriesItr = seriesUID.begin();
	SeriesIdContainer::const_iterator seriesEnd = seriesUID.end();
	while( seriesItr != seriesEnd )
	{
		std::cout << seriesItr->c_str() << std::endl;
		seriesItr++;
	}
	std::string seriesIdentifier;
	seriesIdentifier = seriesUID.begin()->c_str();

	typedef std::vector< std::string >   FileNamesContainer;

	FileNamesContainer fileNames;

	fileNames = nameGenerator->GetFileNames( seriesIdentifier );
	reader->SetFileNames( fileNames );
	typedef itk::VTKImageExport< ImageType > ExportFilterType;
	ExportFilterType::Pointer itkExporter = ExportFilterType::New();
	itkExporter->SetInput( reader->GetOutput() );
	vtkImageImport* vtkImporter = vtkImageImport::New();  
	ConnectPipelines(itkExporter, vtkImporter);

	typedef itk::VTKImageImport< ImageType > ImportFilterType;
	ImportFilterType::Pointer itkImporter = ImportFilterType::New();

	vtkImageExport* vtkExporter = vtkImageExport::New();  
	ConnectPipelines(vtkExporter, itkImporter);

	vtkExporter->SetInput( vtkImporter->GetOutput() );

	reader->Update();

	vtkRenderWindow *renWin = vtkRenderWindow::New();

	vtkPiecewiseFunction* opacityTransferFunction =
vtkPiecewiseFunction::New();

	vtkColorTransferFunction* colorTransferFunction =
vtkColorTransferFunction::New();  
	opacityTransferFunction->AddPoint(0.9,0.1);
	opacityTransferFunction->AddPoint(1255,0);

	vtkVolume* volume = vtkVolume::New();

	vtkVolumeProperty* volumeProperty = vtkVolumeProperty::New(); 

	vtkFixedPointVolumeRayCastMapper* volumeMapperSoftware =
vtkFixedPointVolumeRayCastMapper::New();

	colorTransferFunction->AddRGBPoint(64, 1.0 ,0.0 ,0.0);

	colorTransferFunction->AddRGBPoint(128 ,0.0, 0.0 ,1.0);

	colorTransferFunction->AddRGBPoint(196 ,0.0 ,1.0 ,0.0);

	volumeProperty->SetScalarOpacity(opacityTransferFunction);

	volumeProperty->SetInterpolationTypeToNearest();

	volumeProperty->SetColor(1,colorTransferFunction);

	volumeProperty->ShadeOff(); 

	volumeProperty->SetColor(colorTransferFunction);

	volume->SetProperty(volumeProperty); 

	vtkImporter->Update();

	volumeMapperSoftware->SetInput(vtkImporter->GetOutput());
	
	volumeMapperSoftware->SetSampleDistance(0.1);
	
	volume->SetMapper(volumeMapperSoftware);

	vtkInteractorStyleTrackballCamera * interactorStyle =
vtkInteractorStyleTrackballCamera::New();
	vtkRenderWindowInteractor* iren = vtkRenderWindowInteractor::New();
	vtkRenderer* renderer = vtkRenderer::New();
	
	vtkTextMapper *titleBar = vtkTextMapper::New();
	titleBar->SetInput("3D Human Brain");
	
	vtkActor2D *titleActor = vtkActor2D::New();
	titleActor->SetMapper(titleBar);
	titleActor->SetDisplayPosition(0,200);
	
	vtkTextProperty *tp = vtkTextProperty::New();
	tp->BoldOn();
	tp->SetColor(0.6,0.3,0.8);
	tp->SetFontSize(24);
	tp->SetFontFamilyToArial();
	tp->ShadowOn();
	tp->SetJustificationToCentered();

	titleActor->SetPosition(1650,950);
	titleBar->SetTextProperty(tp);

	vtkScalarBarActor *scalarBar = vtkScalarBarActor::New();

	scalarBar->SetLookupTable(colorTransferFunction);
	scalarBar->SetTitle("Yogunluk");

	renderer->AddViewProp(scalarBar);
	renderer->AddViewProp(titleActor);
	renderer->SetBackground(0,0,0);
	
	//renderer->AddVolume(volume);
	renderer->AddViewProp(volume);
	renderer->ResetCamera();

	//ui.qvtkWidget->GetRenderWindow()->AddRenderer(renderer);
        //When i open this line program crashes and gives me that error:::
//Additional information: Attempted to read or write protected memory. This
is often an indication that //other memory is corrupt.
	renWin->AddRenderer(renderer);
	renWin->SetInteractor(iren);
	renWin->Render();
	iren->SetInteractorStyle(interactorStyle);
	iren->Start();	
}
-- 
View this message in context: http://old.nabble.com/ITK--%3E-VTK--%3E-QT--Volume-Rendering-Problem-tp27009291p27014357.html
Sent from the ITK - Users mailing list archive at Nabble.com.



More information about the Insight-users mailing list