15 #include <vtkImageData.h> 16 #include <ctkDICOMDatabase.h> 17 #include <ctkDICOMIndexer.h> 21 #include "cxDicomConverter.h" 22 #include "cxDicomImageReader.h" 36 QString fileType = QFileInfo(filename).suffix();
38 bool opened = file.open(QIODevice::ReadOnly);
41 bool success = file.seek(0x80);
49 int numReadChar = file.peek(buf,
sizeof(buf));
50 if (numReadChar !=
sizeof(buf))
55 if (buf[0] !=
'D' || buf[1] !=
'I' || buf[2] !=
'C' || buf[3] !=
'M')
71 return this->
readInto(boost::dynamic_pointer_cast<Image>(data), filename);
81 image->setVtkImageData(raw);
96 std::vector<DataPtr> retval;
100 retval.push_back(image);
108 return image->getBaseVtkImageData();
129 database->openDatabase(
":memory:");
132 QFileInfo dir = QFileInfo(fileName);
133 QString folder = dir.absolutePath();
135 QSharedPointer<ctkDICOMIndexer> DICOMIndexer = QSharedPointer<ctkDICOMIndexer> (
new ctkDICOMIndexer);
136 DICOMIndexer->addDirectory(*database,folder,
"");
143 reportError(QString(
"Failed to convert DICOM series %1").arg(seriesUid));
145 database->closeDatabase();
146 return convertedImage;
154 QStringList patients = database->patients();
155 for(
int pNr = 0; pNr < patients.size(); ++pNr)
157 QString patient = patients[pNr];
158 CX_LOG_DEBUG() <<
"Got " << patients.size() <<
" DICOM patients.";
159 QStringList studies = database->studiesForPatient(patient);
160 CX_LOG_DEBUG() <<
"Got " << studies.size() <<
" DICOM studies for patient " << patient;
161 for(
int sNr = 0; sNr < studies.size(); ++sNr)
163 QString study = studies[sNr];
164 QStringList series = database->seriesForStudy(study);
165 CX_LOG_DEBUG() <<
"Got " << series.size() <<
" DICOM series for study " << study;
166 for(
int seriesNr = 0; seriesNr < series.size(); ++seriesNr)
168 QString serie = series[seriesNr];
169 QStringList files = database->filesForSeries(serie);
170 CX_LOG_DEBUG() <<
"Got " << files.size() <<
" DICOM files for series " << serie;
171 if(numFiles < files.size())
173 numFiles = files.size();
175 CX_LOG_DEBUG() <<
"Selecting patient " << patient <<
" study " << study
176 <<
" series " << serie <<
" with " << numFiles <<
" files";
178 CX_LOG_DEBUG() <<
"Found longer series: Patient " << patient <<
" study " << study
179 <<
" series " << serie <<
" with " << numFiles <<
" files";
virtual vtkImageDataPtr loadVtkImageData(QString filename)
void reportError(QString msg)
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)
virtual QString canReadDataType() const
virtual DataPtr read(const QString &uid, const QString &filename)
virtual bool readInto(DataPtr data, QString path)
boost::shared_ptr< class PatientModelService > PatientModelServicePtr
static QString getTypeName()
ImagePtr importSeries(QString fileName)
QString getBestDICOMSeries(ctkDICOMDatabasePtr database)
QSharedPointer< class ctkDICOMDatabase > ctkDICOMDatabasePtr
Namespace for all CustusX production code.