<div dir="ltr"><div>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 <a href="http://hxr99.blogspot.com/2013/03/qt-vtk-displaying-dicom-series-using.html">http://hxr99.blogspot.com/2013/03/qt-vtk-displaying-dicom-series-using.html</a> 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 :</div>
<div><br></div><div>the code.cpp</div><div>vtkqt::vtkqt(QWidget *parent, Qt::WFlags flags)</div><div><span class="" style="white-space:pre">        </span>: QMainWindow(parent, flags)</div><div>{</div><div><span class="" style="white-space:pre">        </span>ui.setupUi(this);</div>
<div><br></div><div><span class="" style="white-space:pre">        </span>this->imageViewerDCMSeriesX= vtkImageViewer2::New();</div><div><span class="" style="white-space:pre">        </span>this->renderer = vtkRenderer::New();</div>
<div><span class="" style="white-space:pre">        </span>this->Connections = vtkSmartPointer<vtkEventQtSlotConnect>::New();</div><div><br></div><div><span class="" style="white-space:pre">        </span>connect(this->ui.actionOpen, SIGNAL(triggered()), this, SLOT(slotOpenFolder()));</div>
<div><span class="" style="white-space:pre">        </span>//connect(this->ui.verticalSlider,SIGNAL(valueChanged(int)), this, SLOT(setSlice(int))); // the first test </div><div><span class="" style="white-space:pre">        </span>this->Connections->Connect(this->ui.qvtkWidget->GetRenderWindow()->GetInteractor(),</div>
<div><span class="" style="white-space:pre">                </span>vtkCommand::KeyPressEvent,</div><div> this,</div><div> SLOT(MoveSliceForward()));</div><div><br></div><div>}</div><div><br></div><div>void vtkqt::slotOpenFolder()</div>
<div><br></div><div>{</div><div><span class="" style="white-space:pre">        </span>QString folderNameDCM = QFileDialog::getExistingDirectory(this,tr("Open DCM Folder"),QDir::currentPath(),QFileDialog::ShowDirsOnly);</div>
<div><br></div><div> std::string stdstrFolderNameDCM = folderNameDCM.toUtf8().constData();</div><div><br></div><div> drawDCMSeries(stdstrFolderNameDCM);</div><div>}</div><div><br></div><div><br></div><div>template <typename ITK_Exporter, typename VTK_Importer></div>
<div>void ConnectPipelines(ITK_Exporter exporter, VTK_Importer* importer)</div><div>{</div><div> importer->SetUpdateInformationCallback(exporter->GetUpdateInformationCallback());</div><div> importer->SetPipelineModifiedCallback(exporter->GetPipelineModifiedCallback());</div>
<div> importer->SetWholeExtentCallback(exporter->GetWholeExtentCallback());</div><div> importer->SetSpacingCallback(exporter->GetSpacingCallback());</div><div> importer->SetOriginCallback(exporter->GetOriginCallback());</div>
<div> importer->SetScalarTypeCallback(exporter->GetScalarTypeCallback());</div><div> importer->SetNumberOfComponentsCallback(exporter->GetNumberOfComponentsCallback());</div><div> importer->SetPropagateUpdateExtentCallback(exporter->GetPropagateUpdateExtentCallback());</div>
<div> importer->SetUpdateDataCallback(exporter->GetUpdateDataCallback());</div><div> importer->SetDataExtentCallback(exporter->GetDataExtentCallback());</div><div> importer->SetBufferPointerCallback(exporter->GetBufferPointerCallback());</div>
<div> importer->SetCallbackUserData(exporter->GetCallbackUserData());</div><div>}</div><div><br></div><div>void vtkqt::drawDCMSeries(std::string folderDCM)</div><div><br></div><div>{</div><div><br></div><div><span class="" style="white-space:pre">        </span>typedef unsigned short PixelType;</div>
<div> const unsigned int Dimension = 3;</div><div> typedef itk::Image< PixelType, Dimension > ImageType;</div><div><br></div><div> typedef itk::VTKImageExport<ImageType> ImageExportType; </div>
<div>typedef itk::ImageSeriesReader< ImageType > ReaderType;</div><div> ReaderType::Pointer reader = ReaderType::New();</div><div> typedef itk::GDCMImageIO ImageIOType;</div><div> ImageIOType::Pointer dicomIO = ImageIOType::New(); </div>
<div> reader->SetImageIO( dicomIO );</div><div> typedef itk::GDCMSeriesFileNames NamesGeneratorType;</div><div> NamesGeneratorType::Pointer nameGenerator = NamesGeneratorType::New();</div><div> nameGenerator->SetUseSeriesDetails( true );</div>
<div> nameGenerator->AddSeriesRestriction("0008|0021" ); </div><div> nameGenerator->SetDirectory( folderDCM);</div><div> </div><div> </div><div> typedef std::vector< std::string > SeriesIdContainer; </div>
<div> const SeriesIdContainer & seriesUID = nameGenerator->GetSeriesUIDs(); </div><div><span class="" style="white-space:pre">        </span>std::cout << seriesUID.size() << std::endl;</div><div> SeriesIdContainer::const_iterator seriesItr = seriesUID.begin();</div>
<div> SeriesIdContainer::const_iterator seriesEnd = seriesUID.end();</div><div> while( seriesItr != seriesEnd )</div><div> {</div><div> std::cout << seriesItr->c_str() << std::endl;</div><div>
seriesItr++;</div><div> }</div><div> std::string seriesIdentifier;</div><div><br></div><div> </div><div> </div><div> seriesIdentifier = seriesUID.begin()->c_str();</div><div> </div><div>
<span class="" style="white-space:pre">        </span>std::cout << seriesIdentifier.c_str() << std::endl;</div><div><br></div><div> typedef std::vector< std::string > FileNamesContainer;</div><div> FileNamesContainer fileNames; </div>
<div> fileNames = nameGenerator->GetFileNames( seriesIdentifier ); </div><div> reader->SetFileNames( fileNames );</div><div> try</div><div> {</div><div> reader->Update();</div><div><span class="" style="white-space:pre">        </span> }</div>
<div> catch (itk::ExceptionObject &ex)</div><div> {</div><div> std::cout << ex << std::endl;</div><div> }</div><div> //------------------------------------------------------------------------</div>
<div> // ITK to VTK pipeline connection.</div><div> //------------------------------------------------------------------------</div><div> </div><div> // Create the itk::VTKImageExport instance and connect it to the</div>
<div> // itk::CurvatureFlowImageFilter.</div><div> ImageExportType::Pointer exporter = ImageExportType::New();</div><div> exporter->SetInput(reader->GetOutput());</div><div> </div><div> </div><div> // Create the vtkImageImport and connect it to the</div>
<div> // itk::VTKImageExport instance.</div><div> vtkImageImport* importer = vtkImageImport::New(); </div><div> ConnectPipelines(exporter, importer);</div><div> </div><div> </div><div> //------------------------------------------------------------------------</div>
<div> // VTK pipeline.</div><div> //------------------------------------------------------------------------</div><div> </div><div> imageViewerDCMSeriesX->SetInput(importer->GetOutput());</div><div>this->SetImageViewer(imageViewerDCMSeriesX);</div>
<div> imageViewerDCMSeriesX->SetRenderWindow(ui.qvtkWidget->GetRenderWindow());</div><div><br></div><div>imageViewerDCMSeriesX->Render(); </div><div>}</div><div><br></div><div><br></div><div>void vtkqt::SetImageViewer(vtkImageViewer2* imageViewer) {</div>
<div> imageViewerDCMSeriesX = imageViewer;</div><div> _MinSlice = imageViewer->GetSliceMin();</div><div> _MaxSlice = imageViewer->GetSliceMax();</div><div> _Slice = _MinSlice;</div><div> cout << "Slicer: Min = " << _MinSlice << ", Max = " << _MaxSlice << std::endl;</div>
<div> }</div><div>void vtkqt::MoveSliceForward() {</div><div><span class="" style="white-space:pre">        </span> cout << "Slice = " << _Slice << std::endl;</div><div><span class="" style="white-space:pre">        </span> cout << "Slice max = " << _MaxSlice << std::endl;</div>
<div> if(_Slice <= _MaxSlice) {</div><div> _Slice += 1;</div><div> cout << "MoveSliceForward::Slice = " << _Slice << std::endl;</div><div> imageViewerDCMSeriesX->SetSlice(_Slice);</div>
<div> </div><div> imageViewerDCMSeriesX->Render();</div><div><span class="" style="white-space:pre">                </span> this->ui.qvtkWidget->update();</div><div> }</div><div> }</div><div><br></div><div>
<br></div><div>if there is also a possibility with this slider will be better</div><div>Can Anyone help? I really don't know what I'm missing here! </div><div><br></div></div>