ITK  4.6.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 IPLSetMacro(name, type) \
40  virtual void Set##name (const type _arg) \
41  { \
42  if ( this->m_##name != _arg ) \
43  { \
44  this->m_##name = _arg; \
45  } \
46  }
47 
48 
50 #define IPLGetMacro(name, type) \
51  virtual type Get##name () \
52  { \
53  return this->m_##name; \
54  }
55 
56 
57 namespace itk
58 {
63 class IPLFileSortInfo
64 {
65 public:
66  IPLFileSortInfo()
67  {
68  m_SliceLocation = 0;
69  m_SliceOffset = 0;
70  m_EchoNumber = 0;
71  m_ImageNumber = 0;
72  m_Data = ITK_NULLPTR;
73  }
74 
75  IPLFileSortInfo(const char *const filename, float sliceLocation,
76  int sliceOffset, int echoNumber, int imageNumber,
77  void *data = ITK_NULLPTR)
78  {
79  m_ImageFileName = filename;
80  m_SliceLocation = sliceLocation;
81  m_SliceOffset = sliceOffset;
82  m_EchoNumber = echoNumber;
83  m_ImageNumber = imageNumber;
84  m_Data = data;
85  }
86 
87  virtual ~IPLFileSortInfo() {}
88 
89  IPLSetMacro(ImageFileName, std::string);
90  IPLGetMacro(ImageFileName, std::string);
91  IPLSetMacro(SliceLocation, float);
92  IPLGetMacro(SliceLocation, float);
93  IPLSetMacro(SliceOffset, int);
94  IPLGetMacro(SliceOffset, int);
95  IPLSetMacro(EchoNumber, int);
96  IPLGetMacro(EchoNumber, int);
97  IPLSetMacro(ImageNumber, int);
98  IPLGetMacro(ImageNumber, int);
99  IPLSetMacro(Data, void *);
100  IPLGetMacro(Data, const void *);
101 
102 private:
103  std::string m_ImageFileName;
104  float m_SliceLocation;
105  int m_SliceOffset;
106  int m_EchoNumber;
107  int m_ImageNumber;
108  const void *m_Data;
109 };
110 
115 class ITKIOIPL_EXPORT IPLFileNameList
116 {
117 public:
118  typedef std::vector< IPLFileSortInfo * > ListType;
119  typedef ListType::iterator IteratorType;
120  typedef size_t ListSizeType;
121 
122  enum {
123  SortGlobalAscend = 0,
124  SortGlobalDescend = 1,
125  SortByNameAscend = 2,
126  SortByNameDescend = 3
127  };
128 
129  IPLFileNameList()
130  {
131  m_XDim = 0;
132  m_YDim = 0;
133  m_XRes = 0.0;
134  m_YRes = 0.0;
140  m_SortOrder = SortGlobalAscend;
141  }
142 
143  virtual ~IPLFileNameList()
144  {
145  IteratorType it = begin();
146  IteratorType itend = end();
147 
148  while ( it != itend )
149  {
150  delete ( *it );
151  it++;
152  }
153  }
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  IteratorType it = begin();
168  IteratorType itend = end();
169 
170  for ( unsigned int i = 0; it != itend && i != __n; it++, i++ )
171  {}
172  if ( it == itend )
173  {
174  return ITK_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(XRes != m_XRes || YRes != m_YRes)
209  {
210  return false;
211  }
212  else if ( Key1 != m_Key1 || Key2 != m_Key2 )
213  {
214  return true;
215  }
216  IteratorType it = begin();
217  IteratorType itend = end();
218  while ( it != itend )
219  {
220  if ( std::string(filename) == ( *it )->GetImageFileName() )
221  {
222  return true;
223  }
224  it++;
225  }
226  m_List.push_back( new IPLFileSortInfo(filename,
227  sliceLocation,
228  offset,
229  0, // echo number
230  imageNumber) );
231  return true;
232  }
233 
234  void RemoveElementFromList(const int ElementToRemove)
235  {
236  IteratorType it = m_List.begin();
237  IteratorType itend = m_List.end();
238  int i = 0;
239 
240  for ( i = 0; it != itend; i++, it++ )
241  {
242  if ( i != ElementToRemove )
243  {
244  break;
245  }
246  }
247  if ( it == itend )
248  {
249  return;
250  }
251  m_List.erase(it);
252  }
253 
254  void sortImageList();
255 
256  void sortImageListAscend();
257 
258  void sortImageListDescend();
259 
260  ListSizeType GetnumImageInfoStructs() const
261  {
262  return m_List.size();
263  }
264 
265  IPLSetMacro(XDim, int);
266  IPLGetMacro(XDim, int);
267  IPLSetMacro(YDim, int);
268  IPLGetMacro(YDim, int);
269  IPLSetMacro(XRes, float);
270  IPLGetMacro(XRes, float);
271  IPLSetMacro(YRes, float);
272  IPLGetMacro(YRes, float);
273  IPLSetMacro(Key1, int);
274  IPLGetMacro(Key1, int);
275  IPLSetMacro(Key2, int);
276  IPLGetMacro(Key2, int);
277  IPLSetMacro(SortOrder, int);
278 
279 private:
280  ListType m_List;
281  int m_XDim;
282  int m_YDim;
283  float m_XRes;
284  float m_YRes;
#define IPLGetMacro(name, type)
#define IPLSetMacro(name, type)