[Insight-users] Displaying DICOM series into QVTKWidget problem

unity csharp developement.unity at gmail.com
Sat Apr 13 17:03:41 EDT 2013


I am trying to read a DICOM series from a folder with ITK and VTK and
display it  into QVTKWiget, initially I tried to visualize the DICOM series
with a slider and I followed the steps that are in this link
http://hxr99.blogspot.com/2013/03/qt-vtk-displaying-dicom-series-using.html
but it does not work, I changed to the "UP" button on the keyboard and
"DOWN" button  but when I click on "UP" the program jumps to the first
image and it crashes, here is my code and print screen of the error :

the code.cpp
vtkqt::vtkqt(QWidget *parent, Qt::WFlags flags)
: QMainWindow(parent, flags)
{
ui.setupUi(this);

this->imageViewerDCMSeriesX= vtkImageViewer2::New();
this->renderer = vtkRenderer::New();
this->Connections = vtkSmartPointer<vtkEventQtSlotConnect>::New();

connect(this->ui.actionOpen, SIGNAL(triggered()), this,
SLOT(slotOpenFolder()));
//connect(this->ui.verticalSlider,SIGNAL(valueChanged(int)), this,
SLOT(setSlice(int))); // the first test
this->Connections->Connect(this->ui.qvtkWidget->GetRenderWindow()->GetInteractor(),
vtkCommand::KeyPressEvent,
  this,
  SLOT(MoveSliceForward()));

}

void vtkqt::slotOpenFolder()

{
QString folderNameDCM = QFileDialog::getExistingDirectory(this,tr("Open DCM
Folder"),QDir::currentPath(),QFileDialog::ShowDirsOnly);

    std::string stdstrFolderNameDCM = folderNameDCM.toUtf8().constData();

    drawDCMSeries(stdstrFolderNameDCM);
}


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());
}

void vtkqt::drawDCMSeries(std::string folderDCM)

{

typedef unsigned short    PixelType;
  const unsigned int      Dimension = 3;
  typedef itk::Image< PixelType, Dimension >         ImageType;

  typedef itk::VTKImageExport<ImageType> ImageExportType;
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->AddSeriesRestriction("0008|0021" );
  nameGenerator->SetDirectory( folderDCM);


    typedef std::vector< std::string >    SeriesIdContainer;
    const SeriesIdContainer & seriesUID = nameGenerator->GetSeriesUIDs();
std::cout << seriesUID.size() << std::endl;
    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();

std::cout << seriesIdentifier.c_str() << std::endl;

    typedef std::vector< std::string >   FileNamesContainer;
    FileNamesContainer fileNames;
    fileNames = nameGenerator->GetFileNames( seriesIdentifier );
    reader->SetFileNames( fileNames );
   try
     {
     reader->Update();
 }
   catch (itk::ExceptionObject &ex)
     {
      std::cout << ex << std::endl;
     }
  //------------------------------------------------------------------------
  // ITK to VTK pipeline connection.
  //------------------------------------------------------------------------

  // Create the itk::VTKImageExport instance and connect it to the
  // itk::CurvatureFlowImageFilter.
  ImageExportType::Pointer exporter = ImageExportType::New();
  exporter->SetInput(reader->GetOutput());


  // Create the vtkImageImport and connect it to the
  // itk::VTKImageExport instance.
  vtkImageImport* importer = vtkImageImport::New();
  ConnectPipelines(exporter, importer);


  //------------------------------------------------------------------------
  // VTK pipeline.
  //------------------------------------------------------------------------

   imageViewerDCMSeriesX->SetInput(importer->GetOutput());
this->SetImageViewer(imageViewerDCMSeriesX);
 imageViewerDCMSeriesX->SetRenderWindow(ui.qvtkWidget->GetRenderWindow());

imageViewerDCMSeriesX->Render();
}


void vtkqt::SetImageViewer(vtkImageViewer2* imageViewer) {
      imageViewerDCMSeriesX = imageViewer;
      _MinSlice = imageViewer->GetSliceMin();
      _MaxSlice = imageViewer->GetSliceMax();
      _Slice = _MinSlice;
      cout << "Slicer: Min = " << _MinSlice << ", Max = " << _MaxSlice <<
std::endl;
   }
void vtkqt::MoveSliceForward() {
 cout << "Slice = " << _Slice << std::endl;
 cout << "Slice max = " << _MaxSlice << std::endl;
      if(_Slice <= _MaxSlice) {
         _Slice += 1;
         cout << "MoveSliceForward::Slice = " << _Slice << std::endl;
         imageViewerDCMSeriesX->SetSlice(_Slice);

         imageViewerDCMSeriesX->Render();
 this->ui.qvtkWidget->update();
      }
   }


if there is also a possibility with this slider will be better
Can Anyone help? I really don't know what I'm missing here!
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.itk.org/pipermail/insight-users/attachments/20130413/928759d0/attachment-0001.htm>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: Captureapp.JPG
Type: image/jpeg
Size: 96724 bytes
Desc: not available
URL: <http://www.itk.org/pipermail/insight-users/attachments/20130413/928759d0/attachment-0001.jpeg>


More information about the Insight-users mailing list