ITK  5.0.0
Insight Segmentation and Registration Toolkit
itkIPLFileNameList.h
Go to the documentation of this file.
1 /*=========================================================================
2  *
3  * Copyright Insight Software Consortium
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) \
41  virtual void Set##name (const type _arg);
42 
43 
44 #define IPLSetMacroDefinition(class, name, type) \
45  void class::Set##name (const type _arg) \
46  { \
47 CLANG_PRAGMA_PUSH \
48 CLANG_SUPPRESS_Wfloat_equal \
49  if ( this->m_##name != _arg ) \
50 CLANG_PRAGMA_POP \
51  { \
52  this->m_##name = _arg; \
53  } \
54  }
55 
57 #define IPLGetMacroDeclaration(name, type) \
58  virtual type Get##name ();
59 
60 
61 #define IPLGetMacroDefinition(class, name, type) \
62  type class::Get##name () \
63  { \
64  return this->m_##name; \
65  }
66 
67 namespace itk
68 {
73 class IPLFileSortInfo
74 {
75 public:
76  IPLFileSortInfo()
77  {
78  m_SliceLocation = 0;
79  m_SliceOffset = 0;
80  m_EchoNumber = 0;
81  m_ImageNumber = 0;
82  m_Data = nullptr;
83  }
84 
85  IPLFileSortInfo(const char *const filename, float sliceLocation,
86  int sliceOffset, int echoNumber, int imageNumber,
87  void *data = nullptr)
88  {
89  m_ImageFileName = filename;
90  m_SliceLocation = sliceLocation;
91  m_SliceOffset = sliceOffset;
92  m_EchoNumber = echoNumber;
93  m_ImageNumber = imageNumber;
94  m_Data = data;
95  }
96 
97  virtual ~IPLFileSortInfo();
98 
99  IPLSetMacroDeclaration(ImageFileName, std::string);
100  IPLGetMacroDeclaration(ImageFileName, std::string);
101  IPLSetMacroDeclaration(SliceLocation, float);
102  IPLGetMacroDeclaration(SliceLocation, float);
103  IPLSetMacroDeclaration(SliceOffset, int);
104  IPLGetMacroDeclaration(SliceOffset, int);
105  IPLSetMacroDeclaration(EchoNumber, int);
106  IPLGetMacroDeclaration(EchoNumber, int);
107  IPLSetMacroDeclaration(ImageNumber, int);
108  IPLGetMacroDeclaration(ImageNumber, int);
109  IPLSetMacroDeclaration(Data, void *);
110  IPLGetMacroDeclaration(Data, const void *);
111 
112 private:
113  std::string m_ImageFileName;
114  float m_SliceLocation;
115  int m_SliceOffset;
116  int m_EchoNumber;
117  int m_ImageNumber;
118  const void *m_Data;
119 };
120 
125 class ITKIOIPL_EXPORT IPLFileNameList
126 {
127 public:
128  using ListType = std::vector< IPLFileSortInfo * >;
129  using IteratorType = ListType::iterator;
130  using ListSizeType = size_t;
131 
132  enum {
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 begin()
156  {
157  return m_List.begin();
158  }
159 
160  IteratorType end()
161  {
162  return m_List.end();
163  }
164 
165  IPLFileSortInfo * operator[](unsigned int __n)
166  {
167  auto it = begin();
168  auto itend = end();
169 
170  for ( unsigned int i = 0; it != itend && i != __n; it++, i++ )
171  {}
172  if ( it == itend )
173  {
174  return nullptr;
175  }
176  return *it;
177  }
178 
179  ListSizeType NumFiles() const
180  {
181  return m_List.size();
182  }
183 
184  bool AddElementToList(char const *const filename,
185  const float sliceLocation,
186  const int offset,
187  const int XDim,
188  const int YDim,
189  const float XRes,
190  const float YRes,
191  const int imageNumber,
192  const int Key1,
193  const int Key2)
194  {
195  if ( m_List.empty() )
196  {
197  m_XDim = XDim;
198  m_YDim = YDim;
199  m_XRes = XRes;
200  m_YRes = YRes;
201  m_Key1 = Key1;
202  m_Key2 = Key2;
203  }
204  else if ( XDim != m_XDim || YDim != m_YDim )
205  {
206  return false;
207  }
208  else if(Math::NotAlmostEquals( XRes, m_XRes ) ||
209  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 RemoveElementFromList(const int ElementToRemove)
236  {
237  auto it = m_List.begin();
238  auto itend = m_List.end();
239  int i = 0;
240 
241  for ( i = 0; it != itend; i++, it++ )
242  {
243  if ( i != ElementToRemove )
244  {
245  break;
246  }
247  }
248  if ( it == itend )
249  {
250  return;
251  }
252  m_List.erase(it);
253  }
254 
255  void sortImageList();
256 
257  void sortImageListAscend();
258 
259  void sortImageListDescend();
260 
261  ListSizeType GetnumImageInfoStructs() const
262  {
263  return m_List.size();
264  }
265 
266  IPLSetMacroDeclaration(XDim, int);
267  IPLGetMacroDeclaration(XDim, int);
268  IPLSetMacroDeclaration(YDim, int);
269  IPLGetMacroDeclaration(YDim, int);
270  IPLSetMacroDeclaration(XRes, float);
271  IPLGetMacroDeclaration(XRes, float);
272  IPLSetMacroDeclaration(YRes, float);
273  IPLGetMacroDeclaration(YRes, float);
274  IPLSetMacroDeclaration(Key1, int);
275  IPLGetMacroDeclaration(Key1, int);
276  IPLSetMacroDeclaration(Key2, int);
277  IPLGetMacroDeclaration(Key2, int);
278  IPLSetMacroDeclaration(SortOrder, int);
279 
280 private:
281  ListType m_List;
282  int m_XDim;
283  int m_YDim;
284  float m_XRes;
285  float m_YRes;
#define IPLSetMacroDeclaration(name, type)
#define IPLGetMacroDeclaration(name, type)
bool NotAlmostEquals(T1 x1, T2 x2)
Definition: itkMath.h:677