Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifndef __itkIPLFileNameList_h
00021 #define __itkIPLFileNameList_h
00022
00023 #include "itkMacro.h"
00024 #include "itkObject.h"
00025
00026 #include <stdio.h>
00027 #include <string>
00028 #include <list>
00030 #define IPLSetMacro(name,type) \
00031 virtual void Set##name (const type _arg) \
00032 { \
00033 if (this->m_##name != _arg) \
00034 { \
00035 this->m_##name = _arg; \
00036 } \
00037 }
00038
00039
00041 #define IPLGetMacro(name,type) \
00042 virtual type Get##name () \
00043 { \
00044 return this->m_##name; \
00045 }
00046
00047
00048 namespace itk {
00052 class IPLFileSortInfo
00053 {
00054 public:
00055 IPLFileSortInfo()
00056 {
00057 m_SliceLocation = 0;
00058 m_SliceOffset = 0;
00059 m_EchoNumber = 0;
00060 m_ImageNumber = 0;
00061 m_Data = 0;
00062 }
00063
00064 IPLFileSortInfo(const char *const filename,float sliceLocation,
00065 int sliceOffset,int echoNumber,int imageNumber,
00066 void *data = 0)
00067 {
00068 m_ImageFileName = filename;
00069 m_SliceLocation = sliceLocation;
00070 m_SliceOffset = sliceOffset;
00071 m_EchoNumber = echoNumber;
00072 m_ImageNumber = imageNumber;
00073 m_Data = data;
00074 }
00075 virtual ~IPLFileSortInfo() {}
00076
00077 IPLSetMacro(ImageFileName,std::string );
00078 IPLGetMacro(ImageFileName,std::string );
00079 IPLSetMacro(SliceLocation,float );
00080 IPLGetMacro(SliceLocation,float );
00081 IPLSetMacro(SliceOffset,int );
00082 IPLGetMacro(SliceOffset,int );
00083 IPLSetMacro(EchoNumber,int );
00084 IPLGetMacro(EchoNumber,int );
00085 IPLSetMacro(ImageNumber,int );
00086 IPLGetMacro(ImageNumber,int );
00087 IPLSetMacro(Data,void *);
00088 IPLGetMacro(Data,const void *);
00089 private:
00090 std::string m_ImageFileName;
00091 float m_SliceLocation;
00092 int m_SliceOffset;
00093 int m_EchoNumber;
00094 int m_ImageNumber;
00095 const void *m_Data;
00096 };
00097
00101 class IPLFileNameList
00102 {
00103 public:
00104 typedef std::vector<IPLFileSortInfo *> ListType;
00105 typedef ListType::iterator IteratorType;
00106 typedef size_t ListSizeType;
00107
00108 enum
00109 {
00110 SortGlobalAscend = 0,
00111 SortGlobalDescend = 1,
00112 SortByNameAscend = 2,
00113 SortByNameDescend = 3
00114 };
00115
00116 IPLFileNameList()
00117 {
00118 m_XDim = 0;
00119 m_YDim = 0;
00124 m_SortOrder = SortGlobalAscend;
00125 }
00126
00127 virtual ~IPLFileNameList()
00128 {
00129 IteratorType it = begin();
00130 IteratorType itend = end();
00131 while(it != itend)
00132 {
00133 delete (*it);
00134 it++;
00135 }
00136 }
00137
00138 IteratorType begin()
00139 {
00140 return m_List.begin();
00141 }
00142
00143 IteratorType end()
00144 {
00145 return m_List.end();
00146 }
00147
00148 IPLFileSortInfo *operator[](unsigned int __n)
00149 {
00150 IteratorType it = begin();
00151 IteratorType itend= end();
00152 for(unsigned int i = 0; it != itend && i != __n; it++, i++)
00153 {
00154 }
00155 if(it == itend)
00156 {
00157 return 0;
00158 }
00159 return *it;
00160 }
00161
00162 ListSizeType NumFiles() const
00163 {
00164 return m_List.size();
00165 }
00166
00167 bool AddElementToList(char const *const filename,
00168 const float sliceLocation,
00169 const int offset,
00170 const int XDim,
00171 const int YDim,
00172 const int imageNumber,
00173 const int Key1,
00174 const int Key2)
00175 {
00176 if(m_List.empty())
00177 {
00178 m_XDim = XDim;
00179 m_YDim = YDim;
00180 m_Key1 = Key1;
00181 m_Key2 = Key2;
00182 }
00183 else if(XDim != m_XDim || YDim != YDim)
00184 {
00185 return false;
00186 }
00187 else if(Key1 != m_Key1 || Key2 != m_Key2)
00188 {
00189 return true;
00190 }
00191 IteratorType it = begin();
00192 IteratorType itend = end();
00193 while(it != itend)
00194 {
00195 if(std::string(filename) == (*it)->GetImageFileName())
00196 {
00197 return true;
00198 }
00199 it++;
00200 }
00201 m_List.push_back(new IPLFileSortInfo(filename,
00202 sliceLocation,
00203 offset,
00204 0,
00205 imageNumber));
00206 return true;
00207 }
00208
00209 void RemoveElementFromList(const int ElementToRemove)
00210 {
00211 IteratorType it = m_List.begin();
00212 IteratorType itend = m_List.end();
00213 int i = 0;
00214 for(i = 0; it != itend; i++, it++)
00215 {
00216 if(i != ElementToRemove)
00217 {
00218 break;
00219 }
00220 }
00221 if(it == itend)
00222 {
00223 return;
00224 }
00225 m_List.erase(it);
00226 }
00227
00228 void sortImageList();
00229 void sortImageListAscend();
00230 void sortImageListDescend();
00231
00232 ListSizeType GetnumImageInfoStructs() const
00233 {
00234 return m_List.size();
00235 }
00236
00237 IPLSetMacro(XDim,int );
00238 IPLGetMacro(XDim,int );
00239 IPLSetMacro(YDim,int );
00240 IPLGetMacro(YDim,int );
00241 IPLSetMacro(Key1,int );
00242 IPLGetMacro(Key1,int );
00243 IPLSetMacro(Key2,int );
00244 IPLGetMacro(Key2,int );
00245 IPLSetMacro(SortOrder,int );
00246 private:
00247 ListType m_List;
00248 int m_XDim;
00249 int m_YDim;
00255 int m_SortOrder;
00256 };
00257
00258 }
00259 #endif
00260