30 #include <boost/filesystem.hpp>
31 #include "boost/algorithm/string.hpp"
34 #include <gdcmGlobal.h>
36 #include <gdcmSerieHelper.h>
40 #if defined(USE_GDCM2)
42 #include <gdcmDicts.h>
43 #include <gdcmGlobal.h>
46 #if defined(USE_XERCES)
47 #include <xercesc/dom/DOM.hpp>
48 #include <xercesc/dom/DOMDocument.hpp>
49 #include <xercesc/util/XMLString.hpp>
50 #include <xercesc/util/PlatformUtils.hpp>
51 using namespace xercesc;
58 OutputModel::~OutputModel()
63 double OutputModel::orderFilesWithZspacing(std::vector<std::string> &im)
66 typedef std::vector<GDCM_NAME_SPACE::File* > FileList;
69 GDCM_NAME_SPACE::SerieHelper *sh = GDCM_NAME_SPACE::SerieHelper::New();
70 std::vector<std::string> lstAux;
71 std::vector<std::string>::iterator it;
72 for (it=im.begin(); it!=im.end(); ++it)
75 GDCM_NAME_SPACE::File *f = GDCM_NAME_SPACE::File::New();
80 fileVector.push_back(f);
82 lstAux.push_back(*it);
86 if ((fileVector.size()>1) && (sh->IsCoherent( &fileVector )))
88 sh->OrderFileList(&fileVector);
89 spacing= sh->GetZSpacing();
92 for (i=0; i<fileVector.size(); i++)
94 im.push_back( (fileVector[i])->GetFileName() );
96 for (i=0; i<lstAux.size(); i++)
98 im.push_back( lstAux[i] );
101 std::sort( im.begin(), im.end() );
109 #if defined(USE_GDCM2)
111 double OutputModel::orderFilesWithZspacing(std::vector<std::string> &im)
117 #if defined(USE_XERCES)
119 OutputModel::OutputModel(OutputModelParser *i_outparser) : m_outparser(i_outparser)
134 bool OutputModel::checkModel(std::map<std::string, std::string> i_model,
const std::string i_val)
137 if( i_model.find(i_val) != i_model.end() )
148 void OutputModel::setDB(
const std::string i_db,
const std::string i_table)
155 const std::string OutputModel::getTag()
164 #if defined(USE_GDCM)
165 sprintf(key,
"D%04x_%04x", m_tag1.GetGroup(), m_tag1.GetElement());
167 #if defined(USE_GDCM2)
168 sprintf(key,
"D%04x_%04x", m_tag2.GetGroup(), m_tag2.GetElement());
210 void OutputModel::getDBValues(
const std::vector<std::string> i_filenames,
const std::string i_stag, std::map<std::string , T> &o_val)
224 void OutputModel::getValues(
const std::vector<std::string> i_filenames,
const std::string i_tag, std::map< std::string, T> &o_val)
226 #if defined(USE_GDCM)
227 getReadValues(i_filenames, o_val);
229 #if defined(USE_GDCM2)
230 getScanValues(i_filenames, i_tag,o_val);
234 #if defined(USE_GDCM2)
237 void OutputModel::getScanValues(
const std::vector<std :: string> i_filenames,
const std::string i_stag, std::map<std::string,T> &o_val)
240 sscanf(i_stag.c_str(),
"D%04hx_%04hx ",&gr,&el);
241 gdcm::Tag tag(gr, el);
242 if (!tag.IsIllegal())
244 std::vector<std :: string> names(i_filenames);
249 std::vector<std :: string>::iterator it = names.begin();
250 for(;it != names.end(); it++)
251 boost::algorithm::replace_all((*it),
"\\",
"/");
252 scan.Scan(i_filenames);
254 std::vector<std::string>::const_iterator it_file = i_filenames.begin();
255 for(; it_file != i_filenames.end(); it++)
257 if( scan.GetMapping((*it_file).c_str()).begin() != scan.GetMapping((*it_file).c_str()).end())
259 o_val[(*it)] = scan.GetMapping((*it_file).c_str()).begin()->second;
282 #if defined(USE_GDCM)
283 double OutputModel::orderFiles(std::vector<std::string> im, std::vector<std::string> &out)
286 std::vector<boost::shared_ptr<GDCM_NAME_SPACE::File> > fileVector;
287 std::vector<std::string> lstAux;
288 GDCM_NAME_SPACE::SerieHelper *sh = GDCM_NAME_SPACE::SerieHelper::New();
289 std::vector<std::string>::iterator it = im.begin();
290 for (; it!=im.end(); ++it)
292 GDCM_NAME_SPACE::File *f = GDCM_NAME_SPACE::File::New();
297 fileVector.push_back(f);
301 lstAux.push_back((*it));
304 if ((fileVector.size()>1) && (sh->IsCoherent( &fileVector )))
306 sh->OrderFileList(&fileVector);
307 spacing= sh->GetZSpacing();
310 for (i=0; i<fileVector.size(); i++)
312 out.push_back( (fileVector[i])->GetFileName() );
314 for (i=0; i<lstAux.size(); i++)
316 out.push_back( lstAux[i] );
321 std::sort( im.begin(), im.end() );
328 void OutputModel::sort(
const std::vector<std::string> i_filenames, std::vector<std::string> &o_sort,
int level)
330 #if defined(USE_XERCES)
334 int tag_end = i_filenames.size();
336 std::map<std::string, std::string> model = m_outparser->getLevel(level);
337 std::map<std::string, std::string> values;
341 #if defined (USE_GDCM2)
345 getValues<std::string>(i_filenames, model[
OUTPUTMODEL_TAG(3)], values);
350 OutputSort<std::string> osort;
351 for(
int i = 0; i < 3; i++)
361 getDBValues<std::string>(i_filenames,model[
OUTPUTMODEL_TAG(3)], values);
365 for(
int i = 0; i <i_filenames.size(); i++)
366 values[i_filenames[i]] = i;
367 osort.sort(values,o_sort);
374 for(
int i = 1; i < 4; i++)
386 getDBValues<std::string>(i_filenames,model[
OUTPUTMODEL_TAG(3)], values);
390 getValues<std::string>(i_filenames, model[
OUTPUTMODEL_TAG(3)], values);
395 for(
int i = 0; i <i_filenames.size(); i++)
396 values[i_filenames[i]] = i;
399 for(
int index = tag_begin; index <= tag_end; index += tag_step)
401 std::map<std::string, std::string>::iterator it_val = values.begin();
402 for(;it_val != values.end(); it_val++)
404 if(it_val->second.c_str() )
406 o_sort.push_back(it_val->first.c_str());
415 sort(i_filenames,o_sort,lv);