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 * operator[](unsigned int __n)
168  {
169  auto it = begin();
170  auto itend = end();
171 
172  for (unsigned int i = 0; it != itend && i != __n; it++, i++)
173  {
174  }
175  if (it == itend)
176  {
177  return nullptr;
178  }
179  return *it;
180  }
181 
182  ListSizeType
183  NumFiles() const
184  {
185  return m_List.size();
186  }
187 
188  bool
189  AddElementToList(char const * const filename,
190  const float sliceLocation,
191  const int offset,
192  const int XDim,
193  const int YDim,
194  const float XRes,
195  const float YRes,
196  const int imageNumber,
197  const int Key1,
198  const int Key2)
199  {
200  if (m_List.empty())
201  {
202  m_XDim = XDim;
203  m_YDim = YDim;
204  m_XRes = XRes;
205  m_YRes = YRes;
206  m_Key1 = Key1;
207  m_Key2 = Key2;
208  }
209  else if (XDim != m_XDim || YDim != m_YDim)
210  {
211  return false;
212  }
213  else if (Math::NotAlmostEquals(XRes, m_XRes) || Math::NotAlmostEquals(YRes, m_YRes))
214  {
215  return false;
216  }
217  else if (Key1 != m_Key1 || Key2 != m_Key2)
218  {
219  return true;
220  }
221  auto it = begin();
222  auto itend = end();
223  while (it != itend)
224  {
225  if (std::string(filename) == (*it)->GetImageFileName())
226  {
227  return true;
228  }
229  ++it;
230  }
231  m_List.push_back(new IPLFileSortInfo(filename,
232  sliceLocation,
233  offset,
234  0, // echo number
235  imageNumber));
236  return true;
237  }
238 
239  void
240  RemoveElementFromList(const int ElementToRemove)
241  {
242  auto it = m_List.begin();
243  auto itend = m_List.end();
244  int i = 0;
245 
246  for (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:696
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