15 #include <QProgressDialog> 16 #include <vtkImageData.h> 17 #include <ctkDICOMDatabase.h> 18 #include <ctkDICOMIndexer.h> 22 #include "cxDicomConverter.h" 23 #include "cxDicomImageReader.h" 27 #include "dcmtk/config/osconfig.h" 28 #include "dcmtk/oflog/nullap.h" 42 if(QFileInfo(filename).isDir())
51 QStringList files = dir.entryList(QDir::NoDotAndDotDot | QDir::AllEntries);
52 for(
int i = 0; i < files.size(); ++i)
54 QString fullPath = dirname+
"/"+files[i];
57 else if(checkSubDirs && QFileInfo(fullPath).isDir())
68 if(QFileInfo(filename).isDir())
74 bool opened = file.open(QIODevice::ReadOnly);
79 bool success = file.seek(0x80);
87 int numReadChar = file.peek(buf,
sizeof(buf));
88 if (numReadChar !=
sizeof(buf))
93 if (buf[0] !=
'D' || buf[1] !=
'I' || buf[2] !=
'C' || buf[3] !=
'M')
109 return this->
readInto(boost::dynamic_pointer_cast<Image>(data), filename);
119 image->setVtkImageData(raw);
134 std::vector<DataPtr> retval;
135 std::vector<ImagePtr> images =
importSeries(filename,
false);
137 for(
int i = 0; i < images.size(); ++i)
138 retval.push_back(images[i]);
146 bool readBestSeries =
true;
147 std::vector<ImagePtr> images =
importSeries(filename, readBestSeries);
148 return images[0]->getBaseVtkImageData();
166 CX_LOG_INFO() <<
"stopQtMessages while reading DICOM files";
170 database->openDatabase(
":memory:");
172 QFileInfo dir = QFileInfo(fileName);
173 QString folder = dir.absolutePath();
177 QProgressDialog progress(
"Reading DICOM series...",
"Cancel", 0, 0);
178 progress.setWindowModality(Qt::WindowModal);
179 progress.setMinimumDuration(0);
180 progress.setValue(0);
184 progress.setLabelText(
"Reading DICOM series...");
185 progress.setMaximum(dicomFolders.size());
187 for(
int i = 0; i < dicomFolders.size(); ++i)
189 progress.setValue(i);
190 if (progress.wasCanceled())
195 std::vector<ImagePtr> retval;
201 database->closeDatabase();
205 CX_LOG_INFO() <<
"DICOM files read - startQtMessages";
212 CX_LOG_INFO() <<
"Finding all subfolders in: " << folder;
215 progress.setLabelText(
"Searcing all subdirectories for DICOM series: "+folder);
216 progress.setMaximum(subDirs.size());
218 for(
int i = 0; i < subDirs.size(); ++i)
220 progress.setValue(i);
221 if (progress.wasCanceled())
224 retval << subDirs[i];
231 if(!QFileInfo(folder).isDir())
232 return QStringList();
234 QStringList allSubDirs;
237 QStringList files = dir.entryList(QDir::NoDotAndDotDot | QDir::Dirs);
238 for(
int i = 0; i < files.size(); ++i)
240 QString fullPath = folder+
"/"+files[i];
242 allSubDirs << subDirs;
244 allSubDirs << folder;
251 QSharedPointer<ctkDICOMIndexer> DICOMIndexer = QSharedPointer<ctkDICOMIndexer> (
new ctkDICOMIndexer);
252 std::cout.setstate(std::ios_base::failbit);
253 DICOMIndexer->addDirectory(*database,folder,
"");
268 dcmtk::log4cplus::SharedAppenderPtr nullapp(
new dcmtk::log4cplus::NullAppender());
270 dcmtk::log4cplus::Logger log = dcmtk::log4cplus::Logger::getRoot();
271 log.removeAllAppenders();
272 log.addAppender(nullapp);
277 std::vector<ImagePtr> retval;
285 retval.push_back(convertedImage);
293 progress.setLabelText(
"Converting DICOM series...");
294 progress.setMaximum(allSeriesUid.size());
299 std::vector<ImagePtr> retval;
300 for(
int i = 0; i < allSeriesUid.size(); ++i)
302 progress.setValue(i);
303 if (progress.wasCanceled())
308 retval.push_back(convertedImage);
310 reportError(QString(
"Failed to convert DICOM series %1").arg(allSeriesUid[i]));
319 QStringList patients = database->patients();
320 for(
int pNr = 0; pNr < patients.size(); ++pNr)
322 QString patient = patients[pNr];
324 QStringList studies = database->studiesForPatient(patient);
326 for(
int sNr = 0; sNr < studies.size(); ++sNr)
328 QString study = studies[sNr];
329 series << database->seriesForStudy(study);
342 for(
int seriesNr = 0; seriesNr < series.size(); ++seriesNr)
344 QString serie = series[seriesNr];
345 QStringList files = database->filesForSeries(serie);
347 if(numFiles < files.size())
349 numFiles = files.size();
virtual vtkImageDataPtr loadVtkImageData(QString filename)
void reportError(QString msg)
QStringList findAllSubfoldersWithDicomFiles(QString folder, QProgressDialog &progress)
std::vector< ImagePtr > importSeries(QString fileName, bool readBestSeries)
bool canReadFile(QString filename)
QString canWriteDataType() const
DICOMReader(PatientModelServicePtr patientModelService)
virtual bool canRead(const QString &type, const QString &filename)
Simple check if file is a DICOM file. DICOM files can have several different endings (...
boost::shared_ptr< class Image > ImagePtr
void setDicomDatabase(ctkDICOMDatabase *database)
bool canWrite(const QString &type, const QString &filename) const
boost::shared_ptr< class Data > DataPtr
ImagePtr convertToImage(QString seriesUid)
std::vector< ImagePtr > importAllSeries(ctkDICOMDatabasePtr database, QProgressDialog &progress)
virtual QString canReadDataType() const
virtual DataPtr read(const QString &uid, const QString &filename)
virtual bool readInto(DataPtr data, QString path)
QStringList findAllSubDirs(QString folder)
boost::shared_ptr< class PatientModelService > PatientModelServicePtr
static QString getTypeName()
void addFolderToDicomDatabase(ctkDICOMDatabasePtr database, QString folder)
QString getBestDICOMSeries(ctkDICOMDatabasePtr database)
QStringList getAllDICOMSeries(ctkDICOMDatabasePtr database)
QSharedPointer< class ctkDICOMDatabase > ctkDICOMDatabasePtr
std::vector< ImagePtr > importBestSeries(ctkDICOMDatabasePtr database)
bool canReadDir(QString dirname, bool checkSubDirs)
Namespace for all CustusX production code.