ITK  4.8.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 "itkMacro.h"
33 #include "itkObject.h"
34 
35 #include <cstdio>
36 #include <string>
37 #include <list>
39 #define IPLSetMacroDeclaration(name, type) \
40  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  if ( this->m_##name != _arg ) \
47  { \
48  this->m_##name = _arg; \
49  } \
50  }
51 
53 #define IPLGetMacroDeclaration(name, type) \
54  virtual type Get##name ();
55 
56 
57 #define IPLGetMacroDefinition(class, name, type) \
58  type class::Get##name () \
59  { \
60  return this->m_##name; \
61  }
62 
63 namespace itk
64 {
69 class IPLFileSortInfo
70 {
71 public:
72  IPLFileSortInfo()
73  {
74  m_SliceLocation = 0;
75  m_SliceOffset = 0;
76  m_EchoNumber = 0;
77  m_ImageNumber = 0;
78  m_Data = ITK_NULLPTR;
79  }
80 
81  IPLFileSortInfo(const char *const filename, float sliceLocation,
82  int sliceOffset, int echoNumber, int imageNumber,
83  void *data = ITK_NULLPTR)
84  {
85  m_ImageFileName = filename;
86  m_SliceLocation = sliceLocation;
87  m_SliceOffset = sliceOffset;
88  m_EchoNumber = echoNumber;
89  m_ImageNumber = imageNumber;
90  m_Data = data;
91  }
92 
93  virtual ~IPLFileSortInfo();
94 
95  IPLSetMacroDeclaration(ImageFileName, std::string);
96  IPLGetMacroDeclaration(ImageFileName, std::string);
97  IPLSetMacroDeclaration(SliceLocation, float);
98  IPLGetMacroDeclaration(SliceLocation, float);
99  IPLSetMacroDeclaration(SliceOffset, int);
100  IPLGetMacroDeclaration(SliceOffset, int);
101  IPLSetMacroDeclaration(EchoNumber, int);
102  IPLGetMacroDeclaration(EchoNumber, int);
103  IPLSetMacroDeclaration(ImageNumber, int);
104  IPLGetMacroDeclaration(ImageNumber, int);
105  IPLSetMacroDeclaration(Data, void *);
106  IPLGetMacroDeclaration(Data, const void *);
107 
108 private:
109  std::string m_ImageFileName;
110  float m_SliceLocation;
111  int m_SliceOffset;
112  int m_EchoNumber;
113  int m_ImageNumber;
114  const void *m_Data;
115 };
116 
121 class ITKIOIPL_EXPORT IPLFileNameList
122 {
123 public:
124  typedef std::vector< IPLFileSortInfo * > ListType;
125  typedef ListType::iterator IteratorType;
126  typedef size_t ListSizeType;
127 
128  enum {
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 begin()
152  {
153  return m_List.begin();
154  }
155 
156  IteratorType end()
157  {
158  return m_List.end();
159  }
160 
161  IPLFileSortInfo * operator[](unsigned int __n)
162  {
163  IteratorType it = begin();
164  IteratorType itend = end();
165 
166  for ( unsigned int i = 0; it != itend && i != __n; it++, i++ )
167  {}
168  if ( it == itend )
169  {
170  return ITK_NULLPTR;
171  }
172  return *it;
173  }
174 
175  ListSizeType NumFiles() const
176  {
177  return m_List.size();
178  }
179 
180  bool AddElementToList(char const *const filename,
181  const float sliceLocation,
182  const int offset,
183  const int XDim,
184  const int YDim,
185  const float XRes,
186  const float YRes,
187  const int imageNumber,
188  const int Key1,
189  const int Key2)
190  {
191  if ( m_List.empty() )
192  {
193  m_XDim = XDim;
194  m_YDim = YDim;
195  m_XRes = XRes;
196  m_YRes = YRes;
197  m_Key1 = Key1;
198  m_Key2 = Key2;
199  }
200  else if ( XDim != m_XDim || YDim != m_YDim )
201  {
202  return false;
203  }
204  else if(XRes != m_XRes || YRes != m_YRes)
205  {
206  return false;
207  }
208  else if ( Key1 != m_Key1 || Key2 != m_Key2 )
209  {
210  return true;
211  }
212  IteratorType it = begin();
213  IteratorType itend = end();
214  while ( it != itend )
215  {
216  if ( std::string(filename) == ( *it )->GetImageFileName() )
217  {
218  return true;
219  }
220  it++;
221  }
222  m_List.push_back( new IPLFileSortInfo(filename,
223  sliceLocation,
224  offset,
225  0, // echo number
226  imageNumber) );
227  return true;
228  }
229 
230  void RemoveElementFromList(const int ElementToRemove)
231  {
232  IteratorType it = m_List.begin();
233  IteratorType itend = m_List.end();
234  int i = 0;
235 
236  for ( i = 0; it != itend; i++, it++ )
237  {
238  if ( i != ElementToRemove )
239  {
240  break;
241  }
242  }
243  if ( it == itend )
244  {
245  return;
246  }
247  m_List.erase(it);
248  }
249 
250  void sortImageList();
251 
252  void sortImageListAscend();
253 
254  void sortImageListDescend();
255 
256  ListSizeType GetnumImageInfoStructs() const
257  {
258  return m_List.size();
259  }
260 
261  IPLSetMacroDeclaration(XDim, int);
262  IPLGetMacroDeclaration(XDim, int);
263  IPLSetMacroDeclaration(YDim, int);
264  IPLGetMacroDeclaration(YDim, int);
265  IPLSetMacroDeclaration(XRes, float);
266  IPLGetMacroDeclaration(XRes, float);
267  IPLSetMacroDeclaration(YRes, float);
268  IPLGetMacroDeclaration(YRes, float);
269  IPLSetMacroDeclaration(Key1, int);
270  IPLGetMacroDeclaration(Key1, int);
271  IPLSetMacroDeclaration(Key2, int);
272  IPLGetMacroDeclaration(Key2, int);
273  IPLSetMacroDeclaration(SortOrder, int);
274 
275 private:
276  ListType m_List;
277  int m_XDim;
278  int m_YDim;
279  float m_XRes;
280  float m_YRes;
#define IPLSetMacroDeclaration(name, type)
#define IPLGetMacroDeclaration(name, type)