1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
| Examen*
ParserDicom::loadFile(string dirName)
{
// Open directory
DIR* dir = opendir(dirName.c_str());
if (dir == NULL) {
return NULL;
}
// Get examen informations
ExamenParams* params = getInfos(dir, dirName);
if (params == NULL) {
return NULL;
}
// Create struct examen
Volume* img = new Volume(params->width, params->height, params->depth);
Examen* exam = new Examen(img, params);
// Read data
int index = 0;
struct dirent* file;
rewinddir(dir);
string pathDirectory = dirName + PATH_SEPARATOR;
int tabSize = params->width * params->height;
float tab[tabSize];
while ((file = readdir(dir)) != NULL) {
if (strcmp(file->d_name, ".") != 0 &&
strcmp(file->d_name, "..") != 0) {
string fullpath = pathDirectory + file->d_name;
DcmFileFormat dcm;
OFCondition cond = dcm.loadFile(fullpath.c_str());
if (cond.bad()) {
delete img;
delete params;
return NULL;
}
DiDocument* didoc = new DiDocument(fullpath.c_str());
DiMono2Image* dimg = new DiMono2Image(didoc, EIS_Normal);
OFString s;
dcm.getDataset()->findAndGetOFString(DCM_BitsStored, s);
int bitsStored = atoi(s.c_str());
short* slice = (short*) dimg->getOutputData(0, bitsStored, 0);
for(int i=0; i<tabSize; ++i) {
tab[i] = (float) slice[i];
}
img->setSlice(tab, index++);
delete dimg;
delete didoc;
}
}
closedir(dir);
return exam;
} |
Partager