]> Creatis software - creaImageIO.git/blob - src/creaImageIOOutputModel.h
#3185 creaImageIO Feature New Normal - Clean code
[creaImageIO.git] / src / creaImageIOOutputModel.h
1 /*
2 # ---------------------------------------------------------------------
3 #
4 # Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image 
5 #                        pour la Santé)
6 # Authors : Eduardo Davila, Frederic Cervenansky, Claire Mouton
7 # Previous Authors : Laurent Guigues, Jean-Pierre Roux
8 # CreaTools website : www.creatis.insa-lyon.fr/site/fr/creatools_accueil
9 #
10 #  This software is governed by the CeCILL-B license under French law and 
11 #  abiding by the rules of distribution of free software. You can  use, 
12 #  modify and/ or redistribute the software under the terms of the CeCILL-B 
13 #  license as circulated by CEA, CNRS and INRIA at the following URL 
14 #  http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html 
15 #  or in the file LICENSE.txt.
16 #
17 #  As a counterpart to the access to the source code and  rights to copy,
18 #  modify and redistribute granted by the license, users are provided only
19 #  with a limited warranty  and the software's author,  the holder of the
20 #  economic rights,  and the successive licensors  have only  limited
21 #  liability. 
22 #
23 #  The fact that you are presently reading this means that you have had
24 #  knowledge of the CeCILL-B license and that you accept its terms.
25 # ------------------------------------------------------------------------
26 */
27
28 #ifndef __creaImageIOoutputModel_h_INCLUDED__
29 #define __creaImageIOoutputModel_h_INCLUDED__
30 #if defined (USE_XERCES)
31 #include <creaImageIOOutputModelParser.h>
32 #endif
33 #if defined(USE_GDCM2)
34 #include <gdcmScanner.h>
35 #endif
36
37 #include <vector>
38 #include <string>
39
40 #define OUTPUTMODEL_TAG_i       ""
41 #define OUTPUTMODEL_TAG_0       "TAG_BEGIN"
42 #define OUTPUTMODEL_TAG_1       "TAG_END"
43 #define OUTPUTMODEL_TAG_2       "TAG_STEP"
44 #define OUTPUTMODEL_TAG_3       "DICOM_TAG"
45 #define OUTPUTMODEL_TAG_4       "ANCHOR"
46 #define OUTPUTMODEL_TAG(i)      OUTPUTMODEL_TAG_ ## i
47
48 namespace creaImageIO
49 {
50
51         class  OutputModel 
52         {
53         public:
54                 OutputModel(){}
55                 virtual ~OutputModel();
56                 double orderFilesWithZspacing(std::vector<std::string> &im);
57
58 #if defined(USE_XERCES)
59                 OutputModel(OutputModelParser *i_outparser);
60         
61                 // Test if we need to check the "dicom" tag if it exists on database
62                 void setDB(const std::string i_db, const std::string i_table);
63
64                 const std::string getTag();
65
66         private:
67
68                 OutputModelParser *m_outparser;
69
70                 // dimensions of output
71                 int dim;
72
73                 // index to indicate if one model is available to perform sorting
74                 bool bmodel;
75                 
76                 // index to indicate of a "DICOM" tag is selected to perform sorting
77                 // not necessary a dicom tag
78                 // for the moment only Gimmick Tag format accepted but should be GDCM2 format or GDCM1.3 too
79                 bool bDicom;
80
81                 // database name
82                 std::string m_dbname;
83                 
84                 std::string m_tag;
85 #if defined(USE_GDCM)
86                 //m_tag1;
87                 template<typename T>
88                 //void getReadValues(const std::vector<std :: string> i_filenames, std::vector<T> &o_val);
89                 double orderFiles(std::vector<std::string> im, std::vector<std::string> &out);
90
91 #endif
92 #if defined(USE_GDCM2)
93                 gdcm::Tag       m_tag2;
94
95                 template<typename T>
96                 void getScanValues(const std::vector<std :: string> i_filenames, const std::string i_stag, std::map<std::string,T> &o_val);
97         
98                 /*template<typename T>
99                 T getTypeTag();*/
100 #endif
101
102                 // the initial value to start sorting
103                 int tag_begin;
104
105                 // the final value to end sorting
106                 int tag_end;
107
108                 // step for the values
109                 int tag_step;
110
111                 // if the sorting is not the same for the set of data, we include another OutputModel
112                 // 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
113                 OutputModel *m_model;
114
115                 // indicates if the sorting tag is present in database or not
116                 bool b_db;
117
118                 std::string m_db;
119
120                 std::string m_table;
121
122                 template<typename T>
123                 void getValues(const std::vector<std::string> i_filenames,const std::string i_tag, std::map< std::string, T> &o_val);
124                 template<typename T>
125                 void getDBValues(const std::vector<std::string> i_filenames, const std::string i_stag, std::map<std::string,T> &o_val);
126
127                 void sort(const std::vector<std::string> i_filenames, std::vector<std::string> &o_sort, int level);
128
129                 bool checkModel(std::map<std::string, std::string> i_model, const std::string i_val);
130 #endif
131         };
132         
133 /*
134          template <class T>
135          class OutputSort
136          {
137          public :
138                  std::map <std::string, T> values;
139                  std::map<std::string, T> tags;
140
141                  void setTag(T i_tag, const std::string name)
142                  {
143                          tags[name] = i_tag;
144                  }
145
146                  void sort (const std::map<std::string, T> i_values, std::vector<std::string> &o_sort)
147                  {
148                         std::map<std::string, T>::const_iterator it_val; 
149                         for(T index = tags[OUTPUTMODEL_TAG(0)]; index <= tags[OUTPUTMODEL_TAG(1)]; index += tags[OUTPUTMODEL_TAG(2)])
150                         {
151                                 //std::map<std::string, T>::const_iterator it_val; 
152                                 for(it_val = i_values.begin();it_val != i_values.end(); it_val++)
153                                 {
154                                         if(it_val->second.c_str()  == index)
155                                         {
156                                                 o_sort.push_back(it_val->first.c_str());
157                                                 break;
158                                         }
159                                 }
160                          }
161                  }
162          };
163 */
164         
165 } // namespace creaImageIO
166 #endif //__creaImageIOoutputModel_h_INCLUDED__