QtDcmManager.cpp
Go to the documentation of this file.
1 /*
2  QtDcm is a C++ Qt based library for communication and conversion of Dicom images.
3  Copyright (C) 2011 Alexandre Abadie <Alexandre.Abadie@univ-rennes1.fr>
4 
5  This library is free software; you can redistribute it and/or
6  modify it under the terms of the GNU Lesser General Public
7  License as published by the Free Software Foundation; either
8  version 2.1 of the License, or (at your option) any later version.
9 
10  This library is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  Lesser General Public License for more details.
14 
15  You should have received a copy of the GNU Lesser General Public
16  License along with this library; if not, write to the Free Software
17  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18 */
19 
20 #define QT_NO_CAST_TO_ASCII
21 
22 #include <algorithm>
23 #include <iostream>
24 #include <limits.h>
25 #include <stdint.h>
26 
27 #include <QMessageBox>
28 #include <QFileDialog>
29 #include <QPointer>
30 
31 #include <QtDcm.h>
32 #include <QtDcmPatient.h>
33 #include <QtDcmStudy.h>
34 #include <QtDcmSerie.h>
35 #include <QtDcmImage.h>
36 #include <QtDcmServer.h>
37 #include <QtDcmPreferences.h>
38 #include <QtDcmFindCallback.h>
39 
40 // For dcm images
41 #include <dcmtk/dcmimgle/dcmimage.h>
42 #include <dcmtk/dcmdata/dcrledrg.h> /* for DcmRLEDecoderRegistration */
43 #include <dcmtk/dcmjpeg/djdecode.h> /* for dcmjpeg decoders */
44 #include <dcmtk/dcmjpeg/dipijpeg.h> /* for dcmimage JPEG plugin */
45 // For color images
46 #include <dcmtk/dcmimage/diregist.h>
47 
48 #include <QtDcmFindScu.h>
49 #include <QtDcmFindDicomdir.h>
50 #include <QtDcmMoveScu.h>
51 #include <QtDcmMoveDicomdir.h>
52 #include <QtDcmConvert.h>
53 #include <QtDcmConvert.h>
54 #include <QtDcmPreviewWidget.h>
55 #include <QtDcmImportWidget.h>
56 #include <QtDcmSerieInfoWidget.h>
57 
58 #include <QtDcmManager.h>
59 
60 namespace {
61  QString dateToString(const QDate & date) {
62  if (date == QDate()) {
63  return "*";
64  }
65 
66  return date.toString("yyyyMMdd");
67  }
68 
69 }
70 
72 {
73 
74 public:
75  QPointer<QtDcm> mainWidget;
76  QString dicomdir;
77  QString outputDir;
79  QDir tempDir;
80  DcmFileFormat dfile;
81  QList<QtDcmPatient> patients;
82  QStringList images;
83  QStringList listImages;
84  QMap<int, QString> mapImages;
85  QStringList seriesToImport;
86  QString serieId;
87  QString patientName;
88  QString patientId;
89  QString patientSex;
90  QString patientBirthDate;
91  QString modality;
92  QDate date1;
93  QDate date2;
94  QString serieDescription;
95  QString studyDescription;
97  QString dcm2nii;
102  QPointer<QTreeWidget> patientsTreeWidget;
103  QPointer<QTreeWidget> studiesTreeWidget;
104  QPointer<QTreeWidget> seriesTreeWidget;
106  QPointer<QtDcmPreviewWidget> previewWidget;
107  QPointer<QtDcmImportWidget> importWidget;
108  QPointer<QtDcmSerieInfoWidget> serieInfoWidget;
111 };
112 
113 QtDcmManager * QtDcmManager::_instance = 0;
114 
115 
117 {
118  if ( _instance == 0 ) {
119  _instance = new QtDcmManager(0);
120  }
121 
122  return _instance;
123 }
124 
126 {
127  if (_instance != 0) {
128  delete _instance;
129  _instance = 0;
130  }
131 }
132 
133 QtDcmManager::QtDcmManager(QObject *parent)
134  : QObject(parent),
135  d ( new QtDcmManagerPrivate )
136 {
137  //Initialization of the private attributes
138  d->useConverter = true;
139  d->mode = PACS;
140  d->dicomdir = "";
141  d->outputDir = "";
142 
143  d->outputdirMode = DIALOG;
144 
145  d->patientName = "*";
146  d->patientId = "*";
147  d->patientBirthDate = "";
148  d->modality = "*";
149  d->serieDescription = "*";
150  d->studyDescription = "*";
151  d->patientSex = "*";
152 
153  d->mainWidget = NULL;
154  d->patientsTreeWidget = NULL;
155  d->studiesTreeWidget = NULL;
156  d->seriesTreeWidget = NULL;
157 
158  d->importWidget = NULL;
159  d->previewWidget = NULL;
160  d->serieInfoWidget = NULL;
161  //Creation of the temporary directories (/tmp/qtdcm and /tmp/qtdcm/logs)
162  this->createTemporaryDirs();
163 }
164 
165 QtDcmManager::~QtDcmManager()
166 {
167  this->deleteTemporaryDirs();
168 
170  delete d;
171 }
172 
174 {
175  d->mainWidget = widget;
176  if ( ! d->mainWidget.isNull() ) {
178  d->mainWidget.data(), &QtDcm::updatePacsComboBox);
179  d->mainWidget->updatePacsComboBox();
180  }
181 }
182 
183 void QtDcmManager::setPatientsTreeWidget ( QTreeWidget * widget )
184 {
185  d->patientsTreeWidget = widget;
186 }
187 
188 void QtDcmManager::setStudiesTreeWidget ( QTreeWidget * widget )
189 {
190  d->studiesTreeWidget = widget;
191 }
192 
193 void QtDcmManager::setSeriesTreeWidget ( QTreeWidget * widget )
194 {
195  d->seriesTreeWidget = widget;
196 }
197 
199 {
200  d->importWidget = widget;
201  QObject::connect ( d->importWidget->importButton, &QPushButton::clicked,
203 }
204 
206 {
207  d->previewWidget = widget;
208 }
209 
211 {
212  d->serieInfoWidget = widget;
213 }
214 
216 {
217  return d->outputdirMode;
218 }
219 
221 {
222  d->outputdirMode = mode;
223 }
224 
226 {
227  if ( d->serieInfoWidget ) {
228  d->serieInfoWidget->elementCountLabel->setText ( "" );
229  d->serieInfoWidget->institutionLabel->setText ( "" );
230  d->serieInfoWidget->operatorLabel->setText ( "" );
231  }
232 }
233 
234 
235 void QtDcmManager::updateSerieInfo ( const QString &eltCount,
236  const QString &institution,
237  const QString &name )
238 {
239  if ( d->serieInfoWidget ) {
240  d->serieInfoWidget->elementCountLabel->setText ( eltCount );
241  d->serieInfoWidget->institutionLabel->setText ( institution );
242  d->serieInfoWidget->operatorLabel->setText ( name );
243  }
244 }
245 
247 {
248  if ( d->previewWidget ) {
249  d->previewWidget->imageLabel->setPixmap ( QPixmap() );
250  }
251 }
252 
253 
254 void QtDcmManager::displayErrorMessage ( const QString &message )
255 {
256  //Instanciate a message from the parent i.e qtdcm
257  QMessageBox msgBox(d->mainWidget);
258  msgBox.setIcon ( QMessageBox::Critical );
259  msgBox.setText ( message );
260  msgBox.exec();
261 }
262 
263 void QtDcmManager::displayMessage ( const QString &info )
264 {
265  //Instanciate a message from the parent i.e qtdcm
266  QMessageBox msgBox ( d->mainWidget );
267  msgBox.setIcon ( QMessageBox::Information );
268  msgBox.setText ( info );
269  msgBox.exec();
270 }
271 
273 {
274  if ( d->mainWidget->pacsComboBox->count() ) {
275  d->seriesToImport.clear();
276  d->mode = PACS;
277 
278  QtDcmFindScu * finder = new QtDcmFindScu ( this );
279  finder->findPatientsScu ( d->patientName, d->patientSex );
280  delete finder;
281  }
282 }
283 
285 {
286  d->seriesToImport.clear();
287 
288  QtDcmFindScu * finder = new QtDcmFindScu ( this );
289  finder->findStudiesScu ( patientName, d->studyDescription, dateToString(d->date1), dateToString(d->date2) );
290  delete finder;
291 }
292 
293 void QtDcmManager::findSeriesScu ( const QString &patientName, const QString &studyUid )
294 {
295  d->seriesToImport.clear();
296 
297  QtDcmFindScu * finder = new QtDcmFindScu ( this );
298  finder->findSeriesScu ( patientName, studyUid, d->studyDescription, d->serieDescription, d->modality );
299  delete finder;
300 }
301 
302 void QtDcmManager::findImagesScu ( const QString &serieInstanceUID )
303 {
304  QtDcmFindScu * finder = new QtDcmFindScu ( this );
305  finder->findImagesScu ( serieInstanceUID );
306  delete finder;
307 }
308 
309 void QtDcmManager::foundPatient ( const QMap<QString, QString> &infosMap )
310 {
311  if ( !d->patientsTreeWidget.isNull() ) {
312  QTreeWidgetItem * patientItem = new QTreeWidgetItem ( d->patientsTreeWidget->invisibleRootItem() );
313  patientItem->setText ( 0, infosMap["Name"] );
314  patientItem->setText ( 1, infosMap["ID"] );
315  patientItem->setText ( 2, QDate::fromString ( infosMap["Birthdate"], "yyyyMMdd" ).toString ( "dd/MM/yyyy" ) );
316  patientItem->setText ( 3, infosMap["Sex"] );
317  }
318 }
319 
320 void QtDcmManager::foundStudy ( const QMap<QString, QString> &infosMap )
321 {
322  if ( !d->studiesTreeWidget.isNull() ) {
323  QTreeWidgetItem * studyItem = new QTreeWidgetItem ( d->studiesTreeWidget->invisibleRootItem() );
324  studyItem->setText ( 0, infosMap["Description"] );
325  studyItem->setText ( 1, QDate::fromString ( infosMap["Date"], "yyyyMMdd" ).toString ( "dd/MM/yyyy" ) );
326  studyItem->setData ( 2, 0, infosMap["UID"] );
327  studyItem->setText ( 2, infosMap["UID"] );
328  studyItem->setData ( 3, 0, infosMap["ID"] );
329  }
330 }
331 
332 void QtDcmManager::foundSerie ( const QMap<QString, QString> &infosMap )
333 {
334  if ( !d->seriesTreeWidget.isNull() ) {
335  QTreeWidgetItem * serieItem = new QTreeWidgetItem ( d->seriesTreeWidget->invisibleRootItem() );
336  serieItem->setText ( 0, infosMap["Description"] );
337  serieItem->setText ( 1, infosMap["Modality"] );
338  serieItem->setText ( 2, QDate::fromString ( infosMap["Date"], "yyyyMMdd" ).toString ( "dd/MM/yyyy" ) );
339  serieItem->setText ( 3, infosMap["ID"] );
340  serieItem->setData ( 4, 0, QVariant ( infosMap["InstanceCount"] ) );
341  serieItem->setData ( 5, 0, QVariant ( infosMap["Institution"] ) );
342  serieItem->setData ( 6, 0, QVariant ( infosMap["Operator"] ) );
343  serieItem->setCheckState ( 0, Qt::Unchecked );
344  }
345 }
346 
347 void QtDcmManager::foundImage ( const QString &image, int number )
348 {
349  d->listImages.append ( image );
350  if ( number ) {
351  d->mapImages.insert ( number, image );
352  }
353 }
354 
356 {
357  if ( d->dicomdir.isEmpty() ) {
358  return;
359  }
360 
361  d->mode = MEDIA;
362 
363  //Load dicomdir in a DCMTK DicomFileFormat object
364  OFCondition status;
365  if ( ! ( status = d->dfile.loadFile ( d->dicomdir.toUtf8().data() ) ).good() ) {
366  return;
367  }
368 
369  this->findPatientsDicomdir();
370 }
371 
373 {
374  d->seriesToImport.clear();
375  QtDcmFindDicomdir * finder = new QtDcmFindDicomdir ( this );
376  finder->setDcmItem ( d->dfile.getDataset() );
377  finder->findPatients();
378  delete finder;
379 }
380 
382 {
383  d->seriesToImport.clear();
384  QtDcmFindDicomdir * finder = new QtDcmFindDicomdir ( this );
385  finder->setDcmItem ( d->dfile.getDataset() );
386  finder->findStudies ( patientName );
387  delete finder;
388 }
389 
391  const QString &studyUID )
392 {
393  d->seriesToImport.clear();
394  QtDcmFindDicomdir * finder = new QtDcmFindDicomdir ( this );
395  finder->setDcmItem ( d->dfile.getDataset() );
396  finder->findSeries ( patientName, studyUID );
397  delete finder;
398 }
399 
400 void QtDcmManager::findImagesDicomdir ( const QString &uid )
401 {
402  QtDcmFindDicomdir * finder = new QtDcmFindDicomdir ( this );
403  finder->setDcmItem ( d->dfile.getDataset() );
404  finder->findImages ( uid );
405  delete finder;
406 }
407 
409 {
410  if ( !d->tempDir.exists() ) {
411  return;
412  }
413 
414  // Uhh
415  qApp->processEvents();
416 
417  switch (d->mode) {
418  case MEDIA:
419  {
420  QtDcmMoveDicomdir * mover = new QtDcmMoveDicomdir ( this );
421  mover->setDcmItem ( d->dfile.getDataset() );
422  mover->setOutputDir ( d->tempDir.absolutePath() );
423  mover->setImportDir ( d->outputDir );
424  mover->setSeries ( d->seriesToImport );
425  connect ( mover, &QtDcmMoveDicomdir::updateProgress,
427  connect ( mover, &QtDcmMoveDicomdir::serieMoved,
429  connect ( mover, &QtDcmMoveDicomdir::finished,
431  connect ( mover, &QtDcmMoveDicomdir::finished,
432  mover, &QtDcmMoveDicomdir::deleteLater);
433  mover->start();
434  }
435  break;
436  case PACS:
437  {
438  QtDcmMoveScu * mover = new QtDcmMoveScu ( this );
439  mover->setOutputDir ( d->tempDir.absolutePath() );
440  mover->setSeries ( d->seriesToImport );
441  mover->setImportDir ( d->outputDir );
442  connect ( mover, &QtDcmMoveScu::updateProgress,
444  connect ( mover, &QtDcmMoveScu::serieMoved,
446  connect ( mover, &QtDcmMoveScu::finished,
448  connect ( mover, &QtDcmMoveScu::finished,
449  mover, &QtDcmMoveScu::deleteLater);
450  mover->start();
451  }
452  break;
453  default:
454  qWarning() << "Move mode not supported";
455  break;
456  }
457 }
458 
459 void QtDcmManager::getPreviewFromSelectedSerie ( const QString &uid, int elementIndex )
460 {
461  if ( !d->tempDir.exists() ) {
462  return;
463  }
464 
465  if ( !d->listImages.size() ) {
466  return;
467  }
468 
469  if ( d->listImages.size() < elementIndex ) {
470  return;
471  }
472 
473  QString imageId = d->listImages[elementIndex];
474 
475  if ( d->mapImages.size() && d->mapImages.contains ( elementIndex ) ) {
476  imageId = d->mapImages[elementIndex];
477  }
478 
479  switch(d->mode) {
480  case MEDIA:
481  {
482  QtDcmMoveDicomdir * mover = new QtDcmMoveDicomdir ( this );
484  mover->setDcmItem ( d->dfile.getDataset() );
485  mover->setOutputDir ( d->tempDir.absolutePath() );
486  mover->setSeries ( QStringList() << uid );
487  mover->setImageId ( imageId );
488  connect(mover, &QtDcmMoveDicomdir::previewSlice ,
490  connect(mover, &QtDcmMoveDicomdir::finished,
491  mover, &QtDcmMoveDicomdir::deleteLater);
492  mover->start();
493  }
494  break;
495  case PACS:
496  {
497  //Check if file has already been moved
498  this->clearPreview();
499  emit gettingPreview();
500 
501  QString modality ( "MR" );
502  if ( d->seriesTreeWidget->currentItem() ) {
503  modality = d->seriesTreeWidget->currentItem()->text ( 1 );
504  }
505 
506  QString filename ( d->tempDir.absolutePath() + "/" + uid + "/" + modality + "." + imageId );
507  if ( QFile ( filename ).exists() ) {
508  makePreview ( filename );
509  }
510  else {
511  QtDcmMoveScu * mover = new QtDcmMoveScu ( this );
512  mover->setMode ( QtDcmMoveScu::PREVIEW );
513  mover->setOutputDir ( d->tempDir.absolutePath() );
514  mover->setSeries ( QStringList() << uid );
515  mover->setImageId ( imageId );
516  connect(mover, &QtDcmMoveScu::previewSlice,
518  connect(mover, &QtDcmMoveScu::finished,
519  mover, &QtDcmMoveScu::deleteLater);
520  mover->start();
521  }
522  }
523  break;
524  default:
525  qWarning() << "Move mode not supported";
526  break;
527  }
528 
529  return;
530 }
531 
532 
534 {
535  if ( this->useExternalConverter() ) { //Use QtDcm convertion tool (ITK or dcm2nii)
536  if ( this->seriesToImportSize() != 0 ) {
537  if ( this->getOutputdirMode() == QtDcmManager::DIALOG ) {
538  QFileDialog dialog( d->mainWidget );
539  dialog.setFileMode ( QFileDialog::Directory );
540  dialog.setOption ( QFileDialog::ShowDirsOnly, true );
541 
542  // Trying to open directly on one of the available drives
543  if (!QDir::drives().isEmpty()) {
544  dialog.setDirectory ( QDir::drives().first().absoluteDir() );
545  }
546 
547  dialog.setWindowTitle ( tr ( "Export directory" ) );
548  QString directory;
549  if ( dialog.exec() ) {
550  directory = dialog.selectedFiles() [0];
551  }
552 
553  if ( !directory.isEmpty() ) { // A file has been chosen
554  // Set the choosen output directory to the manager and launch the conversion process
555  this->setOutputDirectory ( directory );
556  this->moveSelectedSeries();
557  }
558  }
559  else {
560  if ( QDir ( this->outputDirectory() ).exists() ) {
561  this->moveSelectedSeries();
562  }
563  }
564  }
565  }
566  else { //Only copy the dicom files in a temporary directory
567  this->setOutputDirectory ( "" );
568  this->moveSelectedSeries();
569  }
570 }
571 
572 void QtDcmManager::importToDirectory ( const QString &directory )
573 {
574  if ( this->seriesToImportSize() != 0 ) {
575  this->setOutputDirectory ( directory );
576  this->moveSelectedSeries();
577  }
578 }
579 
580 void QtDcmManager::onSerieMoved ( const QString &directory , const QString &serie , int number )
581 {
582  if ( d->useConverter ) {
583  qDebug() << "Starting reconstruction of series" << serie;
584 
585  QtDcmConvert converter( this );
586  converter.setInputDirectory ( directory );
587  converter.setOutputFilename ( serie + ".nii" );
588  converter.setOutputDirectory ( d->outputDir );
589  converter.setTempDirectory ( d->tempDir.absolutePath() );
590  converter.setSerieUID ( serie );
591  converter.convert();
592  qDebug() << "Conversion complete";
593 
594  if ( number == this->seriesToImportSize() - 1 ) {
595  emit importFinished();
596  }
597  }
598 }
599 
601 {
602  if ( d->importWidget ) {
603  d->importWidget->importProgressBar->setValue ( 0 );
604  }
605 }
606 
608 {
609  if ( d->importWidget ) {
610  d->importWidget->importProgressBar->setValue ( i );
611  }
612  qApp->processEvents();
613 }
614 
615 void QtDcmManager::createTemporaryDirs()
616 {
617  //Creation d'un répertoire temporaire pour la série
618  QDir tempDir = QDir ( QDir::tempPath() );
619 
620  //Use Quuid to generate the temporary directory
621  const QString randName = QUuid::createUuid().toString();
622 
623  if ( !tempDir.exists ( "qtdcm" ) )
624  tempDir.mkdir ( "qtdcm" );
625 
626  QDir qtdcmDir = QDir ( QDir::tempPath() + QDir::separator() + "qtdcm" );
627 
628  if ( !qtdcmDir.exists ( randName ) ) {
629  qtdcmDir.mkdir ( randName );
630  }
631 
632  d->tempDir = QDir ( qtdcmDir.absolutePath() + QDir::separator() + randName );
633 }
634 
636 {
637  QDir qtdcmTmpDir(QDir::tempPath() + QDir::separator() + "qtdcm");
638  if(!qtdcmTmpDir.removeRecursively()) {
639  qWarning() << "Cannot remove recursively temporary directory" << qtdcmTmpDir.absolutePath();
640  }
641 }
642 
643 void QtDcmManager::generateCurrentSerieDir()
644 {
645  if ( !d->serieId.isEmpty() ) {
646  d->currentSerieDir = d->tempDir.absolutePath() + QDir::separator() + d->serieId;
647  d->tempDir.mkdir ( d->serieId );
648  }
649 }
650 
651 void QtDcmManager::deleteCurrentSerieDir()
652 {
653  // Suppression des fichiers temporaires
654  const QStringList listFiles = d->currentSerieDir.entryList ( QDir::Files, QDir::Name );
655 
656  for ( int i = 0; i < listFiles.size(); i++ ) {
657  d->currentSerieDir.remove ( listFiles.at ( i ) );
658  }
659 
660  // Suppression du répertoire temporaire
661  if ( !d->tempDir.rmdir ( d->serieId ) ) {
662  qDebug() << tr ( "Probleme lors de la suppression du répertoire temporaire" );
663  }
664 }
665 
666 void QtDcmManager::makePreview ( const QString &filename )
667 {
668  DcmRLEDecoderRegistration::registerCodecs ( OFFalse, OFFalse );
669  DJDecoderRegistration::registerCodecs ( EDC_photometricInterpretation, EUC_default, EPC_default, OFFalse );
670  DcmFileFormat file;
671  file.loadFile ( filename.toLatin1().data() );
672  DcmDataset * dset = file.getDataset();
673  DicomImage* dcimage = new DicomImage ( dset, file.getDataset()->getOriginalXfer(), CIF_MayDetachPixelData );
674 
675 
676  if ( dcimage != NULL ) {
677  dcimage->setNoDisplayFunction();
678  dcimage->hideAllOverlays();
679  dcimage->setNoVoiTransformation();
680 
681  if ( dcimage->getStatus() == EIS_Normal ) {
682  Uint32 *pixelData = ( Uint32 * ) ( dcimage->getOutputData ( 32 /* bits per sample */ ) );
683 
684  if ( pixelData != NULL ) {
685  Uint8 *colored = new Uint8[dcimage->getWidth() * dcimage->getHeight() * 4]; //4 * dcimage->getWidth() * dcimage->getHeight() matrix
686  Uint8 *col = colored;
687  Uint32 *p = pixelData;
688  //get the highest values for RGBA, then use them to scale the pixel luminosity
689  Uint32 p_max = 0;
690 #ifdef WIN32
691  Uint32 p_min = UINT_LEAST32_MAX;
692 #else
693  Uint32 p_min = std::numeric_limits<Uint32>::max();
694 #endif
695 
696  for ( unsigned i = 0; i < dcimage->getWidth(); ++i ) {
697  for ( unsigned j = 0; j < dcimage->getHeight(); ++j, ++p ) {
698  if ( *p > p_max ) {
699  p_max = *p;
700  }
701 
702  if ( *p < p_min ) {
703  p_min = *p;
704  }
705  }
706  }
707 
708  double a = 4294967295.f / ( ( double ) p_max - ( double ) p_min );
709 
710  //re-initialize 'col'
711  p = pixelData;
712  //copy the pixels in our QImage
713 
714  for ( unsigned i = 0; i < dcimage->getWidth(); ++i ) {
715  for ( unsigned j = 0; j < dcimage->getHeight(); ++j, ++p ) {
716  *col = ( Uint8 ) ( ( 255.f / 4294967295.f ) * ( a * ( ( double ) ( *p ) - ( double ) p_min ) ) );
717  ++col;
718  *col = ( Uint8 ) ( ( 255.f / 4294967295.f ) * ( a * ( ( double ) ( *p ) - ( double ) p_min ) ) );
719  ++col;
720  *col = ( Uint8 ) ( ( 255.f / 4294967295.f ) * ( a * ( ( double ) ( *p ) - ( double ) p_min ) ) );
721  ++col;
722  *col = 255;
723  ++col;
724  }
725  }
726 
727  QImage image ( colored, dcimage->getWidth(), dcimage->getHeight(), QImage::Format_ARGB32 );
728 
729  if ( d->previewWidget ) {
730  d->previewWidget->imageLabel->setPixmap ( QPixmap::fromImage ( image.scaled ( 130,130 ), Qt::AutoColor ) );
731  }
732 
733  delete[] colored;
734 
735  }
736  }
737 
738  delete dcimage;
739  }
740 
741  DcmRLEDecoderRegistration::cleanup();
742  DJDecoderRegistration::cleanup();
743 }
744 
745 // Getters and setters
746 QString QtDcmManager::dicomdir() const
747 {
748  return d->dicomdir;
749 }
750 
751 void QtDcmManager::setDicomdir ( const QString &dicomdir )
752 {
753  d->dicomdir = dicomdir;
754  //Load dicomdir in a DCMTK DicomFileFormat object
755  OFCondition status;
756 
757  if ( ! ( status = d->dfile.loadFile ( d->dicomdir.toUtf8().data() ) ).good() ) {
758  return;
759  }
760 }
761 
763 {
764  return d->outputDir;
765 }
766 
767 void QtDcmManager::setOutputDirectory ( const QString &directory )
768 {
769  d->outputDir = directory;
770 }
771 
773 {
774  return d->currentPacs;
775 }
776 
778 {
779  if ( index < QtDcmPreferences::instance()->servers().size() ) {
780  d->currentPacs = QtDcmPreferences::instance()->servers().at ( index );
781  }
782 }
783 
785 {
786  return d->patientName;
787 }
788 
790 {
791  d->patientName = patientName;
792 }
793 
794 QString QtDcmManager::patientId() const
795 {
796  return d->patientId;
797 }
798 
799 void QtDcmManager::setPatientId ( const QString &patientId )
800 {
801  d->patientId = patientId;
802 }
803 
805 {
806  QString birthdate;
807  if ( d->patientsTreeWidget && d->patientsTreeWidget->currentItem() ) {
808  birthdate = d->patientsTreeWidget->currentItem()->data ( 2,0 ).toString();
809  }
810 
811  return birthdate;
812 }
813 
815 {
816  QString sex;
817  if ( d->patientsTreeWidget && d->patientsTreeWidget->currentItem() ) {
818  sex = d->patientsTreeWidget->currentItem()->data ( 3,0 ).toString();
819  }
820 
821  return sex;
822 }
823 
824 QString QtDcmManager::examDate() const
825 {
826  QString examDate;
827  if ( d->studiesTreeWidget && d->studiesTreeWidget->currentItem() ) {
828  examDate = d->studiesTreeWidget->currentItem()->data ( 1,0 ).toString();
829  }
830 
831  return examDate;
832 }
833 
834 void QtDcmManager::setPatientGender ( const QString &sex )
835 {
836  d->patientSex = sex;
837 }
838 
840 {
841  return d->serieDescription;
842 }
843 
845 {
846  d->serieDescription = serieDescription;
847 }
848 
850 {
851  return d->studyDescription;
852 }
853 
855 {
856  d->studyDescription = studyDescription;
857 }
858 
859 void QtDcmManager::setModality ( const QString &modality )
860 {
861  d->modality = modality;
862 }
863 
864 QString QtDcmManager::modality() const
865 {
866  return d->modality;
867 }
868 
869 void QtDcmManager::setStartDate ( const QDate &date )
870 {
871  d->date1 = date;
872 }
873 
875 {
876  return d->date1;
877 }
878 
879 void QtDcmManager::setEndDate ( const QDate &date )
880 {
881  d->date2 = date;
882 }
883 
884 QDate QtDcmManager::endDate() const
885 {
886  return d->date2;
887 }
888 
890 {
891  d->patients.append ( QtDcmPatient() );
892 }
893 
895 {
896  return d->mode;
897 }
898 
899 void QtDcmManager::setListOfImages ( const QStringList &images )
900 {
901  d->images = images;
902 }
903 
904 QList<QString> QtDcmManager::listOfImages() const
905 {
906  return d->listImages;
907 }
908 
910 {
911  d->listImages.clear();
912  d->mapImages.clear();
913 }
914 
915 void QtDcmManager::setSerieId ( const QString &id )
916 {
917  d->serieId = id;
918 }
919 
921 {
922  return d->currentSerieDir.absolutePath();
923 }
924 
925 void QtDcmManager::addSerieToImport ( const QString &uid )
926 {
927  if ( !d->seriesToImport.contains ( uid ) ) {
928  d->seriesToImport.append ( uid );
929  }
930 }
931 
932 void QtDcmManager::removeSerieToImport ( const QString &uid )
933 {
934  if ( d->seriesToImport.contains ( uid ) )
935  d->seriesToImport.removeOne ( uid );
936 }
937 
939 {
940  d->seriesToImport.clear();
941 }
942 
944 {
945  return d->seriesToImport.size();
946 }
947 
949 {
950  return d->useConverter;
951 }
952 
954 {
955  d->useConverter = use;
956 }
957 
QStringList seriesToImport
Map of images (corresponding to listImages) with InstanceNumber tags used as keys.
void findPatientsScu()
Find SCU with Dcmtk code.
QString patientName
Current selected serie UID.
QDir tempDir
Directory containing current serie dicom slice.
void loadDicomdir()
This method read the dicomdir file and populate the patient treewidget.
void findImagesScu(const QString &seriesUID)
void moveSeriesFinished()
void setSeriesTreeWidget(QTreeWidget *widget)
QString serieDescription
Attribute for the end date of the query (usefull for date based queries)
static QtDcmPreferences * instance()
void setPatientsTreeWidget(QTreeWidget *widget)
QStringList images
List that contains patients resulting of a query or read from a CD.
void setSerieDescription(const QString &serieDescription)
Serie description setter.
QPointer< QtDcmImportWidget > importWidget
The pointer to the preview widget.
void findImagesDicomdir(const QString &serieUID)
QPointer< QTreeWidget > studiesTreeWidget
The pointer to the patients tree widget.
void removeSerieToImport(const QString &uid)
void setDcmItem(DcmItem *item)
QString patientSex
Attribute representing the patient id used to query PACS.
void getPreviewFromSelectedSerie(const QString &uid, int elementCount)
QtDcmServer currentPacs() const
QPointer< QtDcmPreviewWidget > previewWidget
The pointer to the series tree widget.
void findPatientsDicomdir()
void displayMessage(const QString &info)
Convenience method that display information message in a QMessageBox window.
QDir currentSerieDir
Output directory for reconstructed serie absolute path.
QString seriesDescription() const
Serie description getter.
void setImportDir(const QString &dir)
QString patientId() const
Patient id getter.
QList< QtDcmPatient > patients
This attribute is usefull for parsing the dicomdir.
QStringList listImages
List of image filename to export from a CD.
void setCurrentPacs(int index)
void previewSlice(const QString &filename)
void findSeriesScu(const QString &patientName, const QString &studyUID)
static QtDcmManager * instance()
QDate startDate() const
Study date getter.
QString patientBirthdate() const
void setSeries(const QStringList &series)
QList< QtDcmServer > servers() const
QtDcm server list getter.
void setListOfImages(const QStringList &images)
QMap< int, QString > mapImages
List of images uid in the current selected serie.
void findSeriesDicomdir(const QString &patientName, const QString &studyDescription)
This class is a representation of a dicom patient.
Definition: QtDcmPatient.h:31
int seriesToImportSize()
void updateProgressBar(int i)
This class is in charge of the different process (dcm2nii), pacs query/retrieve (dcm4chee), temporary directory creation and removing, PACS server settings.
Definition: QtDcmManager.h:44
void setOutputdirMode(QtDcmManager::eOutputdirMode mode)
QtDcmServer currentPacs
Output directory mode DIALOG or CUSTOM.
QString modality
Attribute representing the patient birthdate used to query PACS.
QString dicomdir() const
Return the dicomdir absolute path name.
QString outputDir
Dicomdir absolute file path.
void findPatientsScu(const QString &patientName)
void setSerieUID(const QString &uid)
QDate date2
Attribute for the begin date of the query (usefull for date based queries)
void setStudiesTreeWidget(QTreeWidget *widget)
void setImageId(const QString &id)
void displayErrorMessage(const QString &message)
Convenience method that display error message in a QMessageBox window.
void setPatientId(const QString &patientId)
Patient id setter.
QString studyDescription
Attibute representing the serie description used for query PACS.
void deleteTemporaryDirs()
This method try to delete the temporary directory when closing the QtDcm widget (Doesn&#39;t work for the...
void updateProgress(int i)
void findImages(const QString &seriesUID)
void foundSerie(const QMap< QString, QString > &infosMap)
void updatePacsComboBox()
Updates the PACS list in combo box.
Definition: QtDcm.cpp:141
void previewSlice(const QString &filename)
void setPatientGender(const QString &sex)
void updateSerieInfo(const QString &eltCount, const QString &institution, const QString &name)
QPointer< QtDcm > mainWidget
QList< QString > listOfImages() const
void setInputDirectory(const QString &dir)
void setPatientName(const QString &patientName)
Patient name setter.
void setOutputDirectory(const QString &directory)
Set the output directory.
static void destroy()
void clearSeriesToImport()
QString patientName() const
Patient name getter.
void onSerieMoved(const QString &directory, const QString &uid, int number)
void updateProgress(int i)
void importToDirectory(const QString &directory)
void addSerieToImport(const QString &uid)
void foundPatient(const QMap< QString, QString > &infosMap)
void findImagesScu(const QString &uid)
QString currentSeriesDirectory() const
QPointer< QTreeWidget > seriesTreeWidget
The pointer to the studies tree widget.
void findStudiesScu(const QString &patientName)
void setEndDate(const QDate &date)
Study date setter.
eMoveMode mode() const
Mode getter.
void moveSelectedSeries()
QString modality() const
Study modality getter.
void setStudyDescription(const QString &studyDescription)
Study description setter.
void serieMoved(const QString &directory, const QString &uid, int number)
void setStartDate(const QDate &date)
Study date setter.
QString patientId
Attribute frepresenting the patient name used to query PACS.
QPointer< QtDcmSerieInfoWidget > serieInfoWidget
The pointer to the import widget.
QPointer< QTreeWidget > patientsTreeWidget
Current pacs index in the pacs list.
void setDcmItem(DcmItem *item)
void findStudiesScu(const QString &patientName)
QString outputDirectory() const
Return the output directory where the current serie will be reconstructed.
void setOutputFilename(const QString &fname)
void setSeries(const QStringList &series)
void setUseExternalConverter(bool use)
void setSerieInfoWidget(QtDcmSerieInfoWidget *widget)
void preferencesUpdated()
QString patientGender() const
void importSelectedSeries()
QtDcmManager::eOutputdirMode outputdirMode
Absolute filename of the dcm2nii program.
void findStudies(const QString &patientName)
void setOutputDirectory(const QString &dir)
void makePreview(const QString &filename)
void setMode(eMoveMode mode)
void setImportWidget(QtDcmImportWidget *widget)
DcmFileFormat dfile
Qtdcm temporary directory (/tmp/qtdcm on Unix)
void setSerieId(const QString &id)
QDate endDate() const
Study date getter.
void findSeriesScu(const QString &patientName, const QString &studyUID)
void findSeries(const QString &patientName, const QString &studyUid)
void foundStudy(const QMap< QString, QString > &infosMap)
void clearSerieInfo()
void setImageId(const QString &uid)
void setTempDirectory(const QString &dir)
void setDicomdir(const QString &dicomdir)
Set the dicomdir file name.
This class is a representation of a Dicom PACS server.
Definition: QtDcmServer.h:30
void setModality(const QString &modality)
Study modality setter.
QtDcmManager::eOutputdirMode getOutputdirMode() const
void setPreviewWidget(QtDcmPreviewWidget *widget)
void setMode(eMoveMode eMoveMode)
void foundImage(const QString &image, int number)
QDate date1
Attibute for the modality of the search (MR, US, CT, etc)
void setOutputDir(const QString &dir)
QString serieId
Selected series list in the treview.
QtDcmManager::eMoveMode mode
Attibute representing the study description used for query PACS.
void setOutputDir(const QString &dir)
static void destroy()
QString dcm2nii
Mode that determine the type of media (MEDIA or PACS)
void setImportDir(const QString &dir)
bool useConverter
The pointer to the serie info widget.
bool useExternalConverter() const
void clearPreview()
void clearListOfImages()
void findStudiesDicomdir(const QString &patientName)
void addPatient()
add patient in the list
QString examDate() const
This class contains the widget for managing Dicom data.
Definition: QtDcm.h:36
void setQtDcmWidget(QtDcm *widget)
void serieMoved(const QString &directory, const QString &serie, int number)
QString patientBirthDate
Attribute representing the patient sex used to query PACS.
QString studyDescription() const
Study description getter.