1 #ifndef __creaImageIOTreeNodeComparators_h_INCLUDED__
2 #define __creaImageIOTreeNodeComparators_h_INCLUDED__
20 //=====================================================================
21 /// Abstract definition of a comparator of Node
24 virtual ~Comparator() {}
25 virtual bool operator() (Node* const & x, Node* const & y) = 0;
27 //=====================================================================
31 //=====================================================================
32 /// Abstract Comparator whose order can be reversed
33 struct ComparatorWithOrder : public Comparator
35 ComparatorWithOrder(bool reverse_order = false)
36 : mReverseOrder(reverse_order) {}
37 virtual ~ComparatorWithOrder() {}
40 virtual bool compare(Node* const &, Node* const &) = 0;
42 virtual bool operator() (Node* const & x, Node* const & y)
44 if (mReverseOrder) return this->compare(y,x);
45 return this->compare(x,y);
50 //=====================================================================
54 //=====================================================================
55 /// A Comparator which stores a vector of Comparators and
56 /// which performs lexicographical comparison
57 class LexicographicalComparator : public Comparator
60 LexicographicalComparator(const std::string& name)
62 ~LexicographicalComparator() {}
64 const std::string& GetName() const { return mName; }
65 void SetName(const std::string& s) { mName = s; }
66 void Clear() { mComparator.clear(); }
67 void DeleteComparators()
69 std::vector<Comparator*>::iterator i;
70 for (i =mComparator.begin();
78 void Add(Comparator* c) { mComparator.push_back(c); }
80 bool operator() (Node* const & x, Node * const & y);
84 std::vector<Comparator*> mComparator;
86 //=====================================================================
91 //===================================================================
92 /// Comparator which compares the values of a given Attribute of the Nodes which is decoded as an int value
93 struct IntComparator :
94 public ComparatorWithOrder
96 IntComparator(const std::string& key,
99 ComparatorWithOrder(reverse_order),
102 virtual bool compare(Node* const & x, Node* const & y);
107 //===================================================================
109 //===================================================================
110 /// Comparator which compares the values of a given Attribute of the Nodes which is decoded as an float value
111 struct FloatComparator :
112 public ComparatorWithOrder
114 FloatComparator(const std::string& key,
117 ComparatorWithOrder(reverse_order),
121 virtual bool compare(Node* const & x, Node* const & y);
126 //===================================================================
128 //===================================================================
129 /// Comparator which compares the values of a given Attribute of the Nodes which is decoded as a string value
130 struct StringComparator :
131 public ComparatorWithOrder
133 StringComparator(const std::string& key,
136 ComparatorWithOrder(reverse_order),
140 virtual bool compare(Node* const & x, Node* const & y);
145 //===================================================================
147 //===================================================================
148 #define INT_FIELD_COMP(NAME,FIELD) \
149 struct Node##NAME##Comparator : \
150 public IntComparator \
152 Node##NAME##Comparator(bool o = false) : \
153 IntComparator(FIELD,o) \
156 //==================================================================
158 //===================================================================
159 #define FLOAT_FIELD_COMP(NAME,FIELD) \
160 struct Node##NAME##Comparator : \
161 public FloatComparator \
163 Node##NAME##Comparator(bool o = false) : \
164 FloatComparator(FIELD,o) \
167 //===================================================================
169 //===================================================================
170 #define STRING_FIELD_COMP(NAME,FIELD) \
171 struct Node##NAME##Comparator : \
172 public StringComparator \
174 Node##NAME##Comparator(bool o = false) : \
175 StringComparator(FIELD,o) \
178 //===================================================================
182 //===================================================================
183 // Patient comparators
184 ///Compares the names of the patients
185 STRING_FIELD_COMP(PatientName,"A0010_0010");
186 ///Compares the sex of the patients
187 STRING_FIELD_COMP(PatientSex, "A0010_0040");
188 ///Compares the birthdays of the patients
189 STRING_FIELD_COMP(PatientBirthday, "A0010_0030");
190 //===================================================================
192 //===================================================================
194 ///Compares the dates of the studies
195 STRING_FIELD_COMP(StudyDate,"A0008_0020");
196 ///Compares the description of the studies
197 STRING_FIELD_COMP(StudyDescription,"A0008_1030");
198 //===================================================================
200 //===================================================================
201 // Series comparators
202 ///Compares the modality of the series
203 STRING_FIELD_COMP(Modality,"A0008_0060");
204 ///Compares the description of the series
205 STRING_FIELD_COMP(SeriesDescription,"A0008_103E");
206 ///Compares the date of the series
207 STRING_FIELD_COMP(SeriesDate,"A0008_0021");
208 //===================================================================
210 //===================================================================
212 ///Compares the number of the images
213 INT_FIELD_COMP(ImageNumber,"A0020_0013");
214 ///Compares the location of the images
215 FLOAT_FIELD_COMP(SliceLocation,"A0020_1041");
216 ///Compares the filename of the images
217 STRING_FIELD_COMP(FullFileName,"FullFileName");
218 //===================================================================
221 } // namespace creaImageIO
225 #endif // #ifndef __creaImageIOComparators_h_INCLUDED__