ITK  6.0.0
Insight Toolkit
itkIPLFileNameList.h
Go to the documentation of this file.
1 /*=========================================================================
2  *
3  * Copyright NumFOCUS
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * https://www.apache.org/licenses/LICENSE-2.0.txt
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  *=========================================================================*/
18 /*=========================================================================
19  *
20  * Portions of this file are subject to the VTK Toolkit Version 3 copyright.
21  *
22  * Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
23  *
24  * For complete copyright, license and disclaimer of warranty information
25  * please refer to the NOTICE file at the top of the ITK source tree.
26  *
27  *=========================================================================*/
28 #ifndef itkIPLFileNameList_h
29 #define itkIPLFileNameList_h
30 #include "ITKIOIPLExport.h"
31 
32 #include "itkMath.h"
33 #include "itkMacro.h"
34 #include "itkObject.h"
35 
36 #include <cstdio>
37 #include <string>
38 #include <list>
40 #define IPLSetMacroDeclaration(name, type) virtual void Set##name(const type _arg)
41 
42 #define IPLSetMacroDefinition(class, name, type) \
43  void class ::Set##name(const type _arg) \
44  { \
45  ITK_GCC_PRAGMA_PUSH \
46  ITK_GCC_SUPPRESS_Wfloat_equal \
47  if (this->m_##name != _arg) \
48  { \
49  this->m_##name = _arg; \
50  } \
51  ITK_GCC_PRAGMA_POP \
52  } \
53  ITK_MACROEND_NOOP_STATEMENT
54 
56 #define IPLGetMacroDeclaration(name, type) virtual type Get##name()
57 
58 #define IPLGetMacroDefinition(class, name, type) \
59  type class ::Get##name() { return this->m_##name; } \
60  ITK_MACROEND_NOOP_STATEMENT
61 namespace itk
62 {
68 class IPLFileSortInfo
69 {
70 public:
71  IPLFileSortInfo()
72  {
73  m_SliceLocation = 0;
74  m_SliceOffset = 0;
75  m_EchoNumber = 0;
76  m_ImageNumber = 0;
77  m_Data = nullptr;
78  }
79 
80  IPLFileSortInfo(const char * const filename,
81  float sliceLocation,
82  int sliceOffset,
83  int echoNumber,
84  int imageNumber,
85  void * data = nullptr)
86  {
87  m_ImageFileName = filename;
88  m_SliceLocation = sliceLocation;
89  m_SliceOffset = sliceOffset;
90  m_EchoNumber = echoNumber;
91  m_ImageNumber = imageNumber;
92  m_Data = data;
93  }
94 
95  virtual ~IPLFileSortInfo();
96 
97  IPLSetMacroDeclaration(ImageFileName, std::string);
98  IPLGetMacroDeclaration(ImageFileName, std::string);
99  IPLSetMacroDeclaration(SliceLocation, float);
100  IPLGetMacroDeclaration(SliceLocation, float);
101  IPLSetMacroDeclaration(SliceOffset, int);
102  IPLGetMacroDeclaration(SliceOffset, int);
103  IPLSetMacroDeclaration(EchoNumber, int);
104  IPLGetMacroDeclaration(EchoNumber, int);
105  IPLSetMacroDeclaration(ImageNumber, int);
106  IPLGetMacroDeclaration(ImageNumber, int);
107  IPLSetMacroDeclaration(Data, void *);
108  IPLGetMacroDeclaration(Data, const void *);
109 
110 private:
111  std::string m_ImageFileName{};
112  float m_SliceLocation{};
113  int m_SliceOffset{};
114  int m_EchoNumber{};
115  int m_ImageNumber{};
116  const void * m_Data{};
117 };
118 
124 class ITKIOIPL_EXPORT IPLFileNameList
125 {
126 public:
127  using ListType = std::vector<IPLFileSortInfo *>;
128  using IteratorType = ListType::iterator;
129  using ListSizeType = size_t;
130 
131  enum
132  {
133  SortGlobalAscend = 0,
134  SortGlobalDescend = 1,
135  SortByNameAscend = 2,
136  SortByNameDescend = 3
137  };
138 
139  IPLFileNameList()
140  {
141  m_XDim = 0;
142  m_YDim = 0;
143  m_XRes = 0.0;
144  m_YRes = 0.0;
150  m_SortOrder = SortGlobalAscend;
151  }
152 
153  virtual ~IPLFileNameList();
154 
155  IteratorType
156  begin()
157  {
158  return m_List.begin();
159  }
160 
161  IteratorType
162  end()
163  {
164  return m_List.end();
165  }
166 
167  IPLFileSortInfo *
168  operator[](unsigned int __n)
169  {
170  auto it = begin();
171  auto itend = end();
172 
173  for (unsigned int i = 0; it != itend && i != __n; it++, i++)
174  {
175  }
176  if (it == itend)
177  {
178  return nullptr;
179  }
180  return *it;
181  }
182 
183  ListSizeType
184  NumFiles() const
185  {
186  return m_List.size();
187  }
188 
189  bool
190  AddElementToList(const char * const filename,
191  const float sliceLocation,
192  const int offset,
193  const int XDim,
194  const int YDim,
195  const float XRes,
196  const float YRes,
197  const int imageNumber,
198  const int Key1,
199  const int Key2)
200  {
201  if (m_List.empty())
202  {
203  m_XDim = XDim;
204  m_YDim = YDim;
205  m_XRes = XRes;
206  m_YRes = YRes;
207  m_Key1 = Key1;
208  m_Key2 = Key2;
209  }
210  else if (XDim != m_XDim || YDim != m_YDim)
211  {
212  return false;
213  }
214  else if (Math::NotAlmostEquals(XRes, m_XRes) || Math::NotAlmostEquals(YRes, m_YRes))
215  {
216  return false;
217  }
218  else if (Key1 != m_Key1 || Key2 != m_Key2)
219  {
220  return true;
221  }
222  auto it = begin();
223  auto itend = end();
224  while (it != itend)
225  {
226  if (std::string(filename) == (*it)->GetImageFileName())
227  {
228  return true;
229  }
230  ++it;
231  }
232  m_List.push_back(new IPLFileSortInfo(filename,
233  sliceLocation,
234  offset,
235  0, // echo number
236  imageNumber));
237  return true;
238  }
239 
240  void
241  RemoveElementFromList(const int ElementToRemove)
242  {
243  auto it = m_List.begin();
244  auto itend = m_List.end();
245 
246  for (int i = 0; it != itend; i++, it++)
247  {
248  if (i != ElementToRemove)
249  {
250  break;
251  }
252  }
253  if (it == itend)
254  {
255  return;
256  }
257  m_List.erase(it);
258  }
259 
260  void
261  sortImageList();
262 
263  void
264  sortImageListAscend();
265 
266  void
267  sortImageListDescend();
268 
269  ListSizeType
270  GetnumImageInfoStructs() const
271  {
272  return m_List.size();
273  }
274 
275  IPLSetMacroDeclaration(XDim, int);
276  IPLGetMacroDeclaration(XDim, int);
277  IPLSetMacroDeclaration(YDim, int);
278  IPLGetMacroDeclaration(YDim, int);
279  IPLSetMacroDeclaration(XRes, float);
280  IPLGetMacroDeclaration(XRes, float);
281  IPLSetMacroDeclaration(YRes, float);
282  IPLGetMacroDeclaration(YRes, float);
283  IPLSetMacroDeclaration(Key1, int);
284  IPLGetMacroDeclaration(Key1, int);
285  IPLSetMacroDeclaration(Key2, int);
286  IPLGetMacroDeclaration(Key2, int);
287  IPLSetMacroDeclaration(SortOrder, int);
288 
289 private:
290  ListType m_List{};
291  int m_XDim{};
292  int m_YDim{};
293  float m_XRes{};
294  float m_YRes{};
IPLGetMacroDeclaration
#define IPLGetMacroDeclaration(name, type)
Definition: itkIPLFileNameList.h:56
itkMacro.h
itk::Math::NotAlmostEquals
bool NotAlmostEquals(T1 x1, T2 x2)
Definition: itkMath.h:692
IPLSetMacroDeclaration
#define IPLSetMacroDeclaration(name, type)
Definition: itkIPLFileNameList.h:40
itkObject.h
itk
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
Definition: itkAnatomicalOrientation.h:29
itkMath.h