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