[Insight-users] ITK -> VTK -> QT Volume Rendering Problem
Cory Quammen
cquammen at cs.unc.edu
Tue Jan 5 11:59:08 EST 2010
A couple of things:
I don't think you need this portion of the code:
typedef itk::VTKImageImport< ImageType > ImportFilterType;
ImportFilterType::Pointer itkImporter = ImportFilterType::New();
vtkImageExport* vtkExporter = vtkImageExport::New();
ConnectPipelines(vtkExporter, itkImporter);
vtkExporter->SetInput( vtkImporter->GetOutput() );
All this does is reimport your image into ITK from the VTK image, but
you already have the original ITK image. This shouldn't be causing a
problem, unless your image is large and having 3 copies of it in
memory causes a crash.
Are you making sure to comment out the last 5 lines
(renWin->AddRenderer(renderer); etc.) when you uncomment the line
//ui.qvtkWidget->GetRenderWindow()->AddRenderer(renderer);?
These look like leftovers from a non-Qt example program. They
shouldn't be necessary. If you don't uncomment them, I'm not sure what
to expect, but it may be causing the problem you are having.
Cory
On Mon, Jan 4, 2010 at 10:18 AM, circass <circass at gmail.com> wrote:
>
> 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.
>
> _____________________________________
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at
> http://www.kitware.com/opensource/opensource.html
>
> Kitware offers ITK Training Courses, for more information visit:
> http://www.kitware.com/products/protraining.html
>
> Please keep messages on-topic and check the ITK FAQ at:
> http://www.itk.org/Wiki/ITK_FAQ
>
> Follow this link to subscribe/unsubscribe:
> http://www.itk.org/mailman/listinfo/insight-users
>
--
Cory Quammen
Center for Computer Integrated Systems for Microscopy and Manipulation (CISMM)
Department of Computer Science
University of North Carolina at Chapel Hill
http://www.cs.unc.edu/~cquammen
More information about the Insight-users
mailing list