ITK  5.4.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);
43#define IPLSetMacroDefinition(class, name, type) \
44 void class ::Set##name(const type _arg) \
45 { \
46 ITK_GCC_PRAGMA_PUSH \
47 ITK_GCC_SUPPRESS_Wfloat_equal \
48 if (this->m_##name != _arg) \
49 { \
50 this->m_##name = _arg; \
51 } \
52 ITK_GCC_PRAGMA_POP \
53 }
54
56#define IPLGetMacroDeclaration(name, type) virtual type Get##name();
59#define IPLGetMacroDefinition(class, name, type) \
60 type class ::Get##name() { return this->m_##name; }
61
62namespace itk
63{
69class IPLFileSortInfo
70{
71public:
72 IPLFileSortInfo()
73 {
74 m_SliceLocation = 0;
75 m_SliceOffset = 0;
76 m_EchoNumber = 0;
77 m_ImageNumber = 0;
78 m_Data = nullptr;
79 }
80
81 IPLFileSortInfo(const char * const filename,
82 float sliceLocation,
83 int sliceOffset,
84 int echoNumber,
85 int imageNumber,
86 void * data = nullptr)
87 {
88 m_ImageFileName = filename;
89 m_SliceLocation = sliceLocation;
90 m_SliceOffset = sliceOffset;
91 m_EchoNumber = echoNumber;
92 m_ImageNumber = imageNumber;
93 m_Data = data;
94 }
95
96 virtual ~IPLFileSortInfo();
97
98 IPLSetMacroDeclaration(ImageFileName, std::string);
99 IPLGetMacroDeclaration(ImageFileName, std::string);
100 IPLSetMacroDeclaration(SliceLocation, float);
101 IPLGetMacroDeclaration(SliceLocation, float);
102 IPLSetMacroDeclaration(SliceOffset, int);
103 IPLGetMacroDeclaration(SliceOffset, int);
104 IPLSetMacroDeclaration(EchoNumber, int);
105 IPLGetMacroDeclaration(EchoNumber, int);
106 IPLSetMacroDeclaration(ImageNumber, int);
107 IPLGetMacroDeclaration(ImageNumber, int);
108 IPLSetMacroDeclaration(Data, void *);
109 IPLGetMacroDeclaration(Data, const void *);
110
111private:
112 std::string m_ImageFileName{};
113 float m_SliceLocation{};
114 int m_SliceOffset{};
115 int m_EchoNumber{};
116 int m_ImageNumber{};
117 const void * m_Data{};
118};
119
125class ITKIOIPL_EXPORT IPLFileNameList
126{
127public:
128 using ListType = std::vector<IPLFileSortInfo *>;
129 using IteratorType = ListType::iterator;
130 using ListSizeType = size_t;
131
132 enum
133 {
134 SortGlobalAscend = 0,
135 SortGlobalDescend = 1,
136 SortByNameAscend = 2,
137 SortByNameDescend = 3
138 };
139
140 IPLFileNameList()
141 {
142 m_XDim = 0;
143 m_YDim = 0;
144 m_XRes = 0.0;
145 m_YRes = 0.0;
151 m_SortOrder = SortGlobalAscend;
152 }
153
154 virtual ~IPLFileNameList();
155
156 IteratorType
157 begin()
158 {
159 return m_List.begin();
160 }
161
162 IteratorType
163 end()
164 {
165 return m_List.end();
166 }
167
168 IPLFileSortInfo * 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(char const * 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 int i = 0;
246
247 for (i = 0; it != itend; i++, it++)
248 {
249 if (i != ElementToRemove)
250 {
251 break;
252 }
253 }
254 if (it == itend)
255 {
256 return;
257 }
258 m_List.erase(it);
259 }
260
261 void
262 sortImageList();
263
264 void
265 sortImageListAscend();
266
267 void
268 sortImageListDescend();
269
270 ListSizeType
271 GetnumImageInfoStructs() const
272 {
273 return m_List.size();
274 }
275
276 IPLSetMacroDeclaration(XDim, int);
277 IPLGetMacroDeclaration(XDim, int);
278 IPLSetMacroDeclaration(YDim, int);
279 IPLGetMacroDeclaration(YDim, int);
280 IPLSetMacroDeclaration(XRes, float);
281 IPLGetMacroDeclaration(XRes, float);
282 IPLSetMacroDeclaration(YRes, float);
283 IPLGetMacroDeclaration(YRes, float);
284 IPLSetMacroDeclaration(Key1, int);
285 IPLGetMacroDeclaration(Key1, int);
286 IPLSetMacroDeclaration(Key2, int);
287 IPLGetMacroDeclaration(Key2, int);
288 IPLSetMacroDeclaration(SortOrder, int);
289
290private:
291 ListType m_List{};
292 int m_XDim{};
293 int m_YDim{};
294 float m_XRes{};
295 float m_YRes{};
#define IPLSetMacroDeclaration(name, type)
#define IPLGetMacroDeclaration(name, type)
bool NotAlmostEquals(T1 x1, T2 x2)
Definition: itkMath.h:696
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....