ITK  4.2.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 <stdio.h>
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 private:
101  std::string m_ImageFileName;
102  float m_SliceLocation;
103  int m_SliceOffset;
104  int m_EchoNumber;
105  int m_ImageNumber;
106  const void *m_Data;
107 };
108 
113 class ITK_EXPORT IPLFileNameList
114 {
115 public:
116  typedef std::vector< IPLFileSortInfo * > ListType;
117  typedef ListType::iterator IteratorType;
118  typedef size_t ListSizeType;
119 
120  enum {
121  SortGlobalAscend = 0,
122  SortGlobalDescend = 1,
123  SortByNameAscend = 2,
124  SortByNameDescend = 3
125  };
126 
127  IPLFileNameList()
128  {
129  m_XDim = 0;
130  m_YDim = 0;
131  m_XRes = 0.0;
132  m_YRes = 0.0;
138  m_SortOrder = SortGlobalAscend;
139  }
140 
141  virtual ~IPLFileNameList()
142  {
143  IteratorType it = begin();
144  IteratorType itend = end();
145 
146  while ( it != itend )
147  {
148  delete ( *it );
149  it++;
150  }
151  }
152 
153  IteratorType begin()
154  {
155  return m_List.begin();
156  }
157 
158  IteratorType end()
159  {
160  return m_List.end();
161  }
162 
163  IPLFileSortInfo * operator[](unsigned int __n)
164  {
165  IteratorType it = begin();
166  IteratorType itend = end();
167 
168  for ( unsigned int i = 0; it != itend && i != __n; it++, i++ )
169  {}
170  if ( it == itend )
171  {
172  return 0;
173  }
174  return *it;
175  }
176 
177  ListSizeType NumFiles() const
178  {
179  return m_List.size();
180  }
181 
182  bool AddElementToList(char const *const filename,
183  const float sliceLocation,
184  const int offset,
185  const int XDim,
186  const int YDim,
187  const float XRes,
188  const float YRes,
189  const int imageNumber,
190  const int Key1,
191  const int Key2)
192  {
193  if ( m_List.empty() )
194  {
195  m_XDim = XDim;
196  m_YDim = YDim;
197  m_XRes = XRes;
198  m_YRes = YRes;
199  m_Key1 = Key1;
200  m_Key2 = Key2;
201  }
202  else if ( XDim != m_XDim || YDim != m_YDim )
203  {
204  return false;
205  }
206  else if(XRes != m_XRes || YRes != m_YRes)
207  {
208  return false;
209  }
210  else if ( Key1 != m_Key1 || Key2 != m_Key2 )
211  {
212  return true;
213  }
214  IteratorType it = begin();
215  IteratorType itend = end();
216  while ( it != itend )
217  {
218  if ( std::string(filename) == ( *it )->GetImageFileName() )
219  {
220  return true;
221  }
222  it++;
223  }
224  m_List.push_back( new IPLFileSortInfo(filename,
225  sliceLocation,
226  offset,
227  0, // echo number
228  imageNumber) );
229  return true;
230  }
231 
232  void RemoveElementFromList(const int ElementToRemove)
233  {
234  IteratorType it = m_List.begin();
235  IteratorType itend = m_List.end();
236  int i = 0;
237 
238  for ( i = 0; it != itend; i++, it++ )
239  {
240  if ( i != ElementToRemove )
241  {
242  break;
243  }
244  }
245  if ( it == itend )
246  {
247  return;
248  }
249  m_List.erase(it);
250  }
251 
252  void sortImageList();
253 
254  void sortImageListAscend();
255 
256  void sortImageListDescend();
257 
258  ListSizeType GetnumImageInfoStructs() const
259  {
260  return m_List.size();
261  }
262 
263  IPLSetMacro(XDim, int);
264  IPLGetMacro(XDim, int);
265  IPLSetMacro(YDim, int);
266  IPLGetMacro(YDim, int);
267  IPLSetMacro(XRes, float);
268  IPLGetMacro(XRes, float);
269  IPLSetMacro(YRes, float);
270  IPLGetMacro(YRes, float);
271  IPLSetMacro(Key1, int);
272  IPLGetMacro(Key1, int);
273  IPLSetMacro(Key2, int);
274  IPLGetMacro(Key2, int);
275  IPLSetMacro(SortOrder, int);
276 private:
277  ListType m_List;
278  int m_XDim;
279  int m_YDim;
280  float m_XRes;
281  float m_YRes;