ITK  5.2.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  * http://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 
43 #define IPLSetMacroDefinition(class, name, type) \
44  void class ::Set##name(const type _arg) \
45  { \
46  CLANG_PRAGMA_PUSH \
47  CLANG_SUPPRESS_Wfloat_equal if (this->m_##name != _arg) CLANG_PRAGMA_POP { this->m_##name = _arg; } \
48  }
49 
51 #define IPLGetMacroDeclaration(name, type) virtual type Get##name();
52 
53 
54 #define IPLGetMacroDefinition(class, name, type) \
55  type class ::Get##name() { return this->m_##name; }
56 
57 namespace itk
58 {
64 class IPLFileSortInfo
65 {
66 public:
67  IPLFileSortInfo()
68  {
69  m_SliceLocation = 0;
70  m_SliceOffset = 0;
71  m_EchoNumber = 0;
72  m_ImageNumber = 0;
73  m_Data = nullptr;
74  }
75 
76  IPLFileSortInfo(const char * const filename,
77  float sliceLocation,
78  int sliceOffset,
79  int echoNumber,
80  int imageNumber,
81  void * data = nullptr)
82  {
83  m_ImageFileName = filename;
84  m_SliceLocation = sliceLocation;
85  m_SliceOffset = sliceOffset;
86  m_EchoNumber = echoNumber;
87  m_ImageNumber = imageNumber;
88  m_Data = data;
89  }
90 
91  virtual ~IPLFileSortInfo();
92 
93  IPLSetMacroDeclaration(ImageFileName, std::string);
94  IPLGetMacroDeclaration(ImageFileName, std::string);
95  IPLSetMacroDeclaration(SliceLocation, float);
96  IPLGetMacroDeclaration(SliceLocation, float);
97  IPLSetMacroDeclaration(SliceOffset, int);
98  IPLGetMacroDeclaration(SliceOffset, int);
99  IPLSetMacroDeclaration(EchoNumber, int);
100  IPLGetMacroDeclaration(EchoNumber, int);
101  IPLSetMacroDeclaration(ImageNumber, int);
102  IPLGetMacroDeclaration(ImageNumber, int);
103  IPLSetMacroDeclaration(Data, void *);
104  IPLGetMacroDeclaration(Data, const void *);
105 
106 private:
107  std::string m_ImageFileName;
108  float m_SliceLocation;
109  int m_SliceOffset;
110  int m_EchoNumber;
111  int m_ImageNumber;
112  const void * m_Data;
113 };
114 
120 class ITKIOIPL_EXPORT IPLFileNameList
121 {
122 public:
123  using ListType = std::vector<IPLFileSortInfo *>;
124  using IteratorType = ListType::iterator;
125  using ListSizeType = size_t;
126 
127  enum
128  {
129  SortGlobalAscend = 0,
130  SortGlobalDescend = 1,
131  SortByNameAscend = 2,
132  SortByNameDescend = 3
133  };
134 
135  IPLFileNameList()
136  {
137  m_XDim = 0;
138  m_YDim = 0;
139  m_XRes = 0.0;
140  m_YRes = 0.0;
146  m_SortOrder = SortGlobalAscend;
147  }
148 
149  virtual ~IPLFileNameList();
150 
151  IteratorType
152  begin()
153  {
154  return m_List.begin();
155  }
156 
157  IteratorType
158  end()
159  {
160  return m_List.end();
161  }
162 
163  IPLFileSortInfo * operator[](unsigned int __n)
164  {
165  auto it = begin();
166  auto itend = end();
167 
168  for (unsigned int i = 0; it != itend && i != __n; it++, i++)
169  {
170  }
171  if (it == itend)
172  {
173  return nullptr;
174  }
175  return *it;
176  }
177 
178  ListSizeType
179  NumFiles() const
180  {
181  return m_List.size();
182  }
183 
184  bool
185  AddElementToList(char const * const filename,
186  const float sliceLocation,
187  const int offset,
188  const int XDim,
189  const int YDim,
190  const float XRes,
191  const float YRes,
192  const int imageNumber,
193  const int Key1,
194  const int Key2)
195  {
196  if (m_List.empty())
197  {
198  m_XDim = XDim;
199  m_YDim = YDim;
200  m_XRes = XRes;
201  m_YRes = YRes;
202  m_Key1 = Key1;
203  m_Key2 = Key2;
204  }
205  else if (XDim != m_XDim || YDim != m_YDim)
206  {
207  return false;
208  }
209  else if (Math::NotAlmostEquals(XRes, m_XRes) || Math::NotAlmostEquals(YRes, m_YRes))
210  {
211  return false;
212  }
213  else if (Key1 != m_Key1 || Key2 != m_Key2)
214  {
215  return true;
216  }
217  auto it = begin();
218  auto itend = end();
219  while (it != itend)
220  {
221  if (std::string(filename) == (*it)->GetImageFileName())
222  {
223  return true;
224  }
225  it++;
226  }
227  m_List.push_back(new IPLFileSortInfo(filename,
228  sliceLocation,
229  offset,
230  0, // echo number
231  imageNumber));
232  return true;
233  }
234 
235  void
236  RemoveElementFromList(const int ElementToRemove)
237  {
238  auto it = m_List.begin();
239  auto itend = m_List.end();
240  int i = 0;
241 
242  for (i = 0; it != itend; i++, it++)
243  {
244  if (i != ElementToRemove)
245  {
246  break;
247  }
248  }
249  if (it == itend)
250  {
251  return;
252  }
253  m_List.erase(it);
254  }
255 
256  void
257  sortImageList();
258 
259  void
260  sortImageListAscend();
261 
262  void
263  sortImageListDescend();
264 
265  ListSizeType
266  GetnumImageInfoStructs() const
267  {
268  return m_List.size();
269  }
270 
271  IPLSetMacroDeclaration(XDim, int);
272  IPLGetMacroDeclaration(XDim, int);
273  IPLSetMacroDeclaration(YDim, int);
274  IPLGetMacroDeclaration(YDim, int);
275  IPLSetMacroDeclaration(XRes, float);
276  IPLGetMacroDeclaration(XRes, float);
277  IPLSetMacroDeclaration(YRes, float);
278  IPLGetMacroDeclaration(YRes, float);
279  IPLSetMacroDeclaration(Key1, int);
280  IPLGetMacroDeclaration(Key1, int);
281  IPLSetMacroDeclaration(Key2, int);
282  IPLGetMacroDeclaration(Key2, int);
283  IPLSetMacroDeclaration(SortOrder, int);
284 
285 private:
286  ListType m_List;
287  int m_XDim;
288  int m_YDim;
289  float m_XRes;
290  float m_YRes;
IPLGetMacroDeclaration
#define IPLGetMacroDeclaration(name, type)
Definition: itkIPLFileNameList.h:51
itkMacro.h
itk::Math::NotAlmostEquals
bool NotAlmostEquals(T1 x1, T2 x2)
Definition: itkMath.h:693
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: itkAnnulusOperator.h:24
itkMath.h