<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 &quot;UP&quot; button on the keyboard and &quot;DOWN&quot; button  but when I click on &quot;UP&quot; 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-&gt;imageViewerDCMSeriesX= vtkImageViewer2::New();</div><div><span class="" style="white-space:pre">        </span>this-&gt;renderer = vtkRenderer::New();</div>
<div><span class="" style="white-space:pre">        </span>this-&gt;Connections = vtkSmartPointer&lt;vtkEventQtSlotConnect&gt;::New();</div><div><br></div><div><span class="" style="white-space:pre">        </span>connect(this-&gt;ui.actionOpen, SIGNAL(triggered()), this, SLOT(slotOpenFolder()));</div>
<div><span class="" style="white-space:pre">        </span>//connect(this-&gt;ui.verticalSlider,SIGNAL(valueChanged(int)), this, SLOT(setSlice(int))); // the first test </div><div><span class="" style="white-space:pre">        </span>this-&gt;Connections-&gt;Connect(this-&gt;ui.qvtkWidget-&gt;GetRenderWindow()-&gt;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(&quot;Open DCM Folder&quot;),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 &lt;typename ITK_Exporter, typename VTK_Importer&gt;</div>
<div>void ConnectPipelines(ITK_Exporter exporter, VTK_Importer* importer)</div><div>{</div><div>  importer-&gt;SetUpdateInformationCallback(exporter-&gt;GetUpdateInformationCallback());</div><div>  importer-&gt;SetPipelineModifiedCallback(exporter-&gt;GetPipelineModifiedCallback());</div>
<div>  importer-&gt;SetWholeExtentCallback(exporter-&gt;GetWholeExtentCallback());</div><div>  importer-&gt;SetSpacingCallback(exporter-&gt;GetSpacingCallback());</div><div>  importer-&gt;SetOriginCallback(exporter-&gt;GetOriginCallback());</div>
<div>  importer-&gt;SetScalarTypeCallback(exporter-&gt;GetScalarTypeCallback());</div><div>  importer-&gt;SetNumberOfComponentsCallback(exporter-&gt;GetNumberOfComponentsCallback());</div><div>  importer-&gt;SetPropagateUpdateExtentCallback(exporter-&gt;GetPropagateUpdateExtentCallback());</div>
<div>  importer-&gt;SetUpdateDataCallback(exporter-&gt;GetUpdateDataCallback());</div><div>  importer-&gt;SetDataExtentCallback(exporter-&gt;GetDataExtentCallback());</div><div>  importer-&gt;SetBufferPointerCallback(exporter-&gt;GetBufferPointerCallback());</div>
<div>  importer-&gt;SetCallbackUserData(exporter-&gt;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&lt; PixelType, Dimension &gt;         ImageType;</div><div><br></div><div>  typedef itk::VTKImageExport&lt;ImageType&gt; ImageExportType; </div>
<div>typedef itk::ImageSeriesReader&lt; ImageType &gt;        ReaderType;</div><div>  ReaderType::Pointer reader = ReaderType::New();</div><div> typedef itk::GDCMImageIO       ImageIOType;</div><div>  ImageIOType::Pointer dicomIO = ImageIOType::New();    </div>
<div>  reader-&gt;SetImageIO( dicomIO );</div><div>  typedef itk::GDCMSeriesFileNames NamesGeneratorType;</div><div>  NamesGeneratorType::Pointer nameGenerator = NamesGeneratorType::New();</div><div>  nameGenerator-&gt;SetUseSeriesDetails( true );</div>
<div>  nameGenerator-&gt;AddSeriesRestriction(&quot;0008|0021&quot; );  </div><div>  nameGenerator-&gt;SetDirectory( folderDCM);</div><div> </div><div>   </div><div>    typedef std::vector&lt; std::string &gt;    SeriesIdContainer;    </div>
<div>    const SeriesIdContainer &amp; seriesUID = nameGenerator-&gt;GetSeriesUIDs();   </div><div><span class="" style="white-space:pre">        </span>std::cout &lt;&lt; seriesUID.size() &lt;&lt; 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 &lt;&lt; seriesItr-&gt;c_str() &lt;&lt; std::endl;</div><div>
      seriesItr++;</div><div>    }</div><div>    std::string seriesIdentifier;</div><div><br></div><div>     </div><div>     </div><div>      seriesIdentifier = seriesUID.begin()-&gt;c_str();</div><div>        </div><div>
<span class="" style="white-space:pre">        </span>std::cout &lt;&lt; seriesIdentifier.c_str() &lt;&lt; std::endl;</div><div><br></div><div>    typedef std::vector&lt; std::string &gt;   FileNamesContainer;</div><div>    FileNamesContainer fileNames; </div>
<div>    fileNames = nameGenerator-&gt;GetFileNames( seriesIdentifier ); </div><div>    reader-&gt;SetFileNames( fileNames );</div><div>   try</div><div>     {</div><div>     reader-&gt;Update();</div><div><span class="" style="white-space:pre">        </span> }</div>
<div>   catch (itk::ExceptionObject &amp;ex)</div><div>     {</div><div>      std::cout &lt;&lt; ex &lt;&lt; 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-&gt;SetInput(reader-&gt;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-&gt;SetInput(importer-&gt;GetOutput());</div><div>this-&gt;SetImageViewer(imageViewerDCMSeriesX);</div>
<div> imageViewerDCMSeriesX-&gt;SetRenderWindow(ui.qvtkWidget-&gt;GetRenderWindow());</div><div><br></div><div>imageViewerDCMSeriesX-&gt;Render(); </div><div>}</div><div><br></div><div><br></div><div>void vtkqt::SetImageViewer(vtkImageViewer2* imageViewer) {</div>
<div>      imageViewerDCMSeriesX = imageViewer;</div><div>      _MinSlice = imageViewer-&gt;GetSliceMin();</div><div>      _MaxSlice = imageViewer-&gt;GetSliceMax();</div><div>      _Slice = _MinSlice;</div><div>      cout &lt;&lt; &quot;Slicer: Min = &quot; &lt;&lt; _MinSlice &lt;&lt; &quot;, Max = &quot; &lt;&lt; _MaxSlice &lt;&lt; std::endl;</div>
<div>   }</div><div>void vtkqt::MoveSliceForward() {</div><div><span class="" style="white-space:pre">        </span> cout &lt;&lt; &quot;Slice = &quot; &lt;&lt; _Slice &lt;&lt; std::endl;</div><div><span class="" style="white-space:pre">        </span> cout &lt;&lt; &quot;Slice max = &quot; &lt;&lt; _MaxSlice &lt;&lt; std::endl;</div>
<div>      if(_Slice &lt;= _MaxSlice) {</div><div>         _Slice += 1;</div><div>         cout &lt;&lt; &quot;MoveSliceForward::Slice = &quot; &lt;&lt; _Slice &lt;&lt; std::endl;</div><div>         imageViewerDCMSeriesX-&gt;SetSlice(_Slice);</div>
<div>      </div><div>         imageViewerDCMSeriesX-&gt;Render();</div><div><span class="" style="white-space:pre">                </span> this-&gt;ui.qvtkWidget-&gt;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&#39;t know what I&#39;m missing here! </div><div><br></div></div>