2 # ---------------------------------------------------------------------
4 # Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image
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
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.
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
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 # ------------------------------------------------------------------------
29 #ifndef __creaImageIOTreeNodeComparators_h_INCLUDED__
30 #define __creaImageIOTreeNodeComparators_h_INCLUDED__
48 //=====================================================================
49 /// Abstract definition of a comparator of Node
52 virtual ~Comparator() {}
53 virtual bool operator() (Node* const & x, Node* const & y) = 0;
55 //=====================================================================
59 //=====================================================================
60 /// Abstract Comparator whose order can be reversed
61 struct ComparatorWithOrder : public Comparator
63 ComparatorWithOrder(bool reverse_order = false)
64 : mReverseOrder(reverse_order) {}
65 virtual ~ComparatorWithOrder() {}
68 virtual bool compare(Node* const &, Node* const &) = 0;
70 virtual bool operator() (Node* const & x, Node* const & y)
72 if (mReverseOrder) return this->compare(y,x);
73 return this->compare(x,y);
78 //=====================================================================
82 //=====================================================================
83 /// A Comparator which stores a vector of Comparators and
84 /// which performs lexicographical comparison
85 class LexicographicalComparator : public Comparator
88 LexicographicalComparator(const std::string& name)
90 ~LexicographicalComparator() {}
92 const std::string& GetName() const { return mName; }
93 void SetName(const std::string& s) { mName = s; }
94 void Clear() { mComparator.clear(); }
95 void DeleteComparators()
97 std::vector<Comparator*>::iterator i;
98 for (i =mComparator.begin();
106 void Add(Comparator* c) { mComparator.push_back(c); }
108 bool operator() (Node* const & x, Node * const & y);
112 std::vector<Comparator*> mComparator;
114 //=====================================================================
119 //===================================================================
120 /// Comparator which compares the values of a given Attribute of the Nodes which is decoded as an int value
121 struct IntComparator :
122 public ComparatorWithOrder
124 IntComparator(const std::string& key,
127 ComparatorWithOrder(reverse_order),
130 virtual bool compare(Node* const & x, Node* const & y);
135 //===================================================================
137 //===================================================================
138 /// Comparator which compares the values of a given Attribute of the Nodes which is decoded as an float value
139 struct FloatComparator :
140 public ComparatorWithOrder
142 FloatComparator(const std::string& key,
145 ComparatorWithOrder(reverse_order),
149 virtual bool compare(Node* const & x, Node* const & y);
154 //===================================================================
156 //===================================================================
157 /// Comparator which compares the values of a given Attribute of the Nodes which is decoded as a string value
158 struct StringComparator :
159 public ComparatorWithOrder
161 StringComparator(const std::string& key,
164 ComparatorWithOrder(reverse_order),
168 virtual bool compare(Node* const & x, Node* const & y);
173 //===================================================================
175 //===================================================================
176 #define INT_FIELD_COMP(NAME,FIELD) \
177 struct Node##NAME##Comparator : \
178 public IntComparator \
180 Node##NAME##Comparator(bool o = false) : \
181 IntComparator(FIELD,o) \
184 //==================================================================
186 //===================================================================
187 #define FLOAT_FIELD_COMP(NAME,FIELD) \
188 struct Node##NAME##Comparator : \
189 public FloatComparator \
191 Node##NAME##Comparator(bool o = false) : \
192 FloatComparator(FIELD,o) \
195 //===================================================================
197 //===================================================================
198 #define STRING_FIELD_COMP(NAME,FIELD) \
199 struct Node##NAME##Comparator : \
200 public StringComparator \
202 Node##NAME##Comparator(bool o = false) : \
203 StringComparator(FIELD,o) \
206 //===================================================================
210 //===================================================================
211 // Patient comparators
212 ///Compares the names of the patients
213 STRING_FIELD_COMP(PatientName,"A0010_0010");
214 ///Compares the sex of the patients
215 STRING_FIELD_COMP(PatientSex, "A0010_0040");
216 ///Compares the birthdays of the patients
217 STRING_FIELD_COMP(PatientBirthday, "A0010_0030");
218 //===================================================================
220 //===================================================================
222 ///Compares the dates of the studies
223 STRING_FIELD_COMP(StudyDate,"A0008_0020");
224 ///Compares the description of the studies
225 STRING_FIELD_COMP(StudyDescription,"A0008_1030");
226 //===================================================================
228 //===================================================================
229 // Series comparators
230 ///Compares the modality of the series
231 STRING_FIELD_COMP(Modality,"A0008_0060");
232 ///Compares the description of the series
233 STRING_FIELD_COMP(SeriesDescription,"A0008_103E");
234 ///Compares the date of the series
235 STRING_FIELD_COMP(SeriesDate,"A0008_0021");
236 //===================================================================
238 //===================================================================
240 ///Compares the number of the images
241 INT_FIELD_COMP(ImageNumber,"A0020_0013");
242 ///Compares the location of the images
243 FLOAT_FIELD_COMP(SliceLocation,"A0020_1041");
244 ///Compares the filename of the images
245 STRING_FIELD_COMP(FullFileName,"FullFileName");
246 //===================================================================
249 } // namespace creaImageIO
253 #endif // #ifndef __creaImageIOComparators_h_INCLUDED__