File: fileloader.cpp

package info (click to toggle)
aeskulap 0.2.2b1%2Bgit20161206-1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 3,840 kB
  • ctags: 1,302
  • sloc: cpp: 8,894; sh: 5,551; ansic: 685; makefile: 317; xml: 25
file content (126 lines) | stat: -rw-r--r-- 3,506 bytes parent folder | download | duplicates (4)
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
/*
    Aeskulap ImagePool - DICOM abstraction library
    Copyright (C) 2005  Alexander Pipelka

    This library is free software; you can redistribute it and/or
    modify it under the terms of the GNU Library General Public
    License as published by the Free Software Foundation; either
    version 2 of the License, or (at your option) any later version.

    This library is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    Library General Public License for more details.

    You should have received a copy of the GNU Library General Public
    License along with this library; if not, write to the Free
    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA

    Alexander Pipelka
*/

#include <gtkmm.h>

#include "dcmtk/dcmdata/dcfilefo.h"
#include "dcmtk/dcmdata/dcdeftag.h"

#include "imagepool.h"
#include "fileloader.h"

namespace ImagePool {

bool FileLoader::load(const std::list< Glib::ustring >& filelist) {
	if(busy() || filelist.size() == 0) {
		return false;
	}

	m_filelist = new std::list< Glib::ustring >(filelist);

	m_cache.clear();
	prescan_files(m_filelist);

	if(m_cache.size() == 0) {
		return false;
	}

	start();

	return true;
}

void FileLoader::prescan_files(std::list< Glib::ustring >* filelist) {
	OFString studyinstanceuid;
	std::list< Glib::ustring >::iterator i = filelist->begin();
	unsigned int curr = 0;
	unsigned int max = filelist->size();

	for(; i != filelist->end(); i++) {

		signal_prescan_progress((double)(++curr) / (double)max);

		DcmFileFormat dfile;
		OFCondition cond = dfile.loadFile(
							(*i).c_str(),
							EXS_Unknown,
							EGL_noChange,
							DCM_MaxReadLength);

/*
    OFCondition findAndGetOFString(const DcmTagKey &tagKey,
                                   OFString &value,
                                   const unsigned long pos = 0,
                                   const OFBool searchIntoSub = OFFalse);
*/
        // OFCondition status = dfile.getDataset()->findAndGetOFString(DCM_StudyInstanceUID, studyinstanceuid);
		if(cond.good() && dfile.getDataset()->findAndGetOFString(DCM_StudyInstanceUID, studyinstanceuid).good()) {
			OFString seriesinstanceuid;
			dfile.getDataset()->findAndGetOFString(DCM_SeriesInstanceUID, seriesinstanceuid);

			std::string studyUID;
			std::string seriesUID;

			studyUID = studyinstanceuid.c_str();
			seriesUID = seriesinstanceuid.c_str();

			m_cache[studyUID].m_instancecount++;
			m_cache[studyUID].m_seriesuid.insert(seriesUID);
			m_cache[studyUID].m_seriescount = m_cache[studyUID].m_seriesuid.size();
		}
	}
}

bool FileLoader::run() {
	std::list< Glib::ustring >* filelist = m_filelist;
	std::list< Glib::ustring >::iterator i = filelist->begin();
	OFString studyinstanceuid;

	for(; i != filelist->end(); i++) {
		DcmFileFormat dfile;

		OFCondition cond = dfile.loadFile(
							(*i).c_str(),
							EXS_Unknown,
							EGL_noChange,
							DCM_MaxReadLength);

		if(!cond.good()) {
			std::cout << "unable to open file[" << *i << "]: " << cond.text() << std::endl;
		}
		else {
			dfile.loadAllDataIntoMemory();
			std::cout << "opened file:" << (*i) << std::endl;

			DcmDataset* dset = dfile.getDataset();
			if(dset->findAndGetOFString(DCM_StudyInstanceUID, studyinstanceuid).good()) {
				add_image(dset);
			}
		}
	}

	delete filelist;
	m_filelist = NULL;

	return true;
}

} // namespace ImagePool