]> Creatis software - creaImageIO.git/blob - src/creaImageIOOutputModel.h
*** empty log message ***
[creaImageIO.git] / src / creaImageIOOutputModel.h
1 #ifndef __creaImageIOoutputModel_h_INCLUDED__
2 #define __creaImageIOoutputModel_h_INCLUDED__
3 #if defined (USE_XERCES)
4 #include <creaImageIOOutputModelParser.h>
5 #endif
6 #if defined(USE_GDCM2)
7 #include <gdcmScanner.h>
8 #endif
9
10
11 #define OUTPUTMODEL_TAG_i       ""
12 #define OUTPUTMODEL_TAG_0       "TAG_BEGIN"
13 #define OUTPUTMODEL_TAG_1       "TAG_END"
14 #define OUTPUTMODEL_TAG_2       "TAG_STEP"
15 #define OUTPUTMODEL_TAG_3       "DICOM_TAG"
16 #define OUTPUTMODEL_TAG_4       "ANCHOR"
17 #define OUTPUTMODEL_TAG(i)      OUTPUTMODEL_TAG_ ## i
18
19
20
21
22 namespace creaImageIO
23 {
24         class  OutputModel 
25         {
26         public:
27                 OutputModel(){}
28                 virtual ~OutputModel();
29                 double orderFilesWithZspacing(std::vector<std::string> &im);
30
31 #if defined(USE_XERCES)
32                 OutputModel(OutputModelParser *i_outparser);
33
34                 
35
36         
37                 // Test if we need to check the "dicom" tag if it exists on database
38                 void setDB(const std::string i_db, const std::string i_table);
39
40                 const std::string getTag();
41
42         
43         private:
44
45                 OutputModelParser *m_outparser;
46
47                 // dimensions of output
48                 int dim;
49
50                 // index to indicate if one model is available to perform sorting
51                 bool bmodel;
52                 
53                 // index to indicate of a "DICOM" tag is selected to perform sorting
54                 // not necessary a dicom tag
55                 // for the moment only Gimmick Tag format accepted but should be GDCM2 format or GDCM1.3 too
56                 bool bDicom;
57
58                 // database name
59                 std::string m_dbname;
60                 
61                 std::string m_tag;
62 #if defined(USE_GDCM)
63                 //m_tag1;
64                 template<typename T>
65                 //void getReadValues(const std::vector<std :: string> i_filenames, std::vector<T> &o_val);
66                 double orderFiles(std::vector<std::string> im, std::vector<std::string> &out);
67
68 #endif
69 #if defined(USE_GDCM2)
70                 gdcm::Tag       m_tag2;
71
72                 template<typename T>
73                 void getScanValues(const std::vector<std :: string> i_filenames, const std::string i_stag, std::map<std::string,T> &o_val);
74         
75                 /*template<typename T>
76                 T getTypeTag();*/
77 #endif
78
79                 // the initial value to start sorting
80                 int tag_begin;
81
82                 // the final value to end sorting
83                 int tag_end;
84
85                 // step for the values
86                 int tag_step;
87
88                 // if the sorting is not the same for the set of data, we include another OutputModel
89                 // ex : if we want a step = 20 for the 100 first values, next a step = 10 for the next 100 and step = 1 for the lastest value
90                 OutputModel *m_model;
91
92                 // indicates if the sorting tag is present in database or not
93                 bool b_db;
94
95                 std::string m_db;
96
97                 std::string m_table;
98
99                 template<typename T>
100                 void getValues(const std::vector<std::string> i_filenames,const std::string i_tag, std::map< std::string, T> &o_val);
101                 template<typename T>
102                 void getDBValues(const std::vector<std::string> i_filenames, const std::string i_stag, std::map<std::string,T> &o_val);
103
104                 void sort(const std::vector<std::string> i_filenames, std::vector<std::string> &o_sort, int level);
105
106                 bool checkModel(std::map<std::string, std::string> i_model, const std::string i_val);
107 #endif
108         };
109                  template <class T>
110          class OutputSort
111          {
112          public :
113                  std::map <std::string, T> values;
114                  std::map<std::string, T> tags;
115
116                  void setTag(T i_tag, const std::string name)
117                  {
118                          tags[name] = i_tag;
119                  }
120
121                  void sort (const std::map<std::string, T> i_values, std::vector<std::string> &o_sort)
122                  {
123                          for(T index = tags[OUTPUTMODEL_TAG(0)]; index <= tags[OUTPUTMODEL_TAG(1)]; index += tags[OUTPUTMODEL_TAG(2)])
124                         {
125                                 std::map<std::string, T>::const_iterator it_val = i_values.begin();
126                                 for(;it_val != values.end(); it_val++)
127                                 {
128                                         if(it_val->second.c_str()  == index)
129                                         {
130                                                 o_sort.push_back(it_val->first.c_str());
131                                                 break;
132                                         }
133                                 }
134                          }
135                  }
136          };
137 } // namespace creaImageIO
138 #endif //__creaImageIOoutputModel_h_INCLUDED__