Main Page   Groups   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Concepts

itkIPLFileNameList.h

Go to the documentation of this file.
00001 /*=========================================================================
00002   Program:   Insight Segmentation & Registration Toolkit
00003   Module:    $RCSfile: itkIPLFileNameList.h,v $
00004   Language:  C++
00005   Date:      $Date: 2004/11/10 19:22:13 $
00006   Version:   $Revision: 1.7 $
00007 
00008   Copyright (c) Insight Software Consortium. All rights reserved.
00009   See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details.
00010 
00011      This software is distributed WITHOUT ANY WARRANTY; without even 
00012      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
00013      PURPOSE.  See the above copyright notices for more information.
00014 
00015   =========================================================================*/
00016 
00017 #ifndef __IPLFileNameList_H__
00018 #define __IPLFileNameList_H__
00019 
00020 #include "itkMacro.h"
00021 #include "itkObject.h"
00022 #include <stdio.h>
00023 #include <string>
00024 #include <list>
00026 #define IPLSetMacro(name,type) \
00027   virtual void Set##name (const type _arg) \
00028   { \
00029     if (this->m_##name != _arg) \
00030       { \
00031       this->m_##name = _arg; \
00032       } \
00033   } 
00034 
00036 #define IPLGetMacro(name,type) \
00037   virtual type Get##name () \
00038   { \
00039     return this->m_##name; \
00040   }
00041 
00042 namespace itk {
00046   class IPLFileSortInfo
00047   {
00048   public:
00049     IPLFileSortInfo() {
00050       m_SliceLocation = 0;
00051       m_SliceOffset = 0;
00052       m_echoNumber = 0;
00053       m_imageNumber = 0;
00054       m_data = 0;
00055     }
00056     virtual ~IPLFileSortInfo() {
00057     }
00058     IPLFileSortInfo(const char *const filename,float SliceLocation,
00059                  int SliceOffset,int echoNumber,int imageNumber,void *data = 0)
00060     {
00061       m_imageFileName = filename;
00062       m_SliceLocation = SliceLocation;
00063       m_SliceOffset = SliceOffset;
00064       m_echoNumber = echoNumber;
00065       m_imageNumber = imageNumber;
00066       m_data = data;
00067     }
00068       
00069     IPLSetMacro(imageFileName,std::string );
00070     IPLGetMacro(imageFileName,std::string );
00071     IPLSetMacro(SliceLocation,float );
00072     IPLGetMacro(SliceLocation,float );
00073     IPLSetMacro(SliceOffset,int );
00074     IPLGetMacro(SliceOffset,int );
00075     IPLSetMacro(echoNumber,int );
00076     IPLGetMacro(echoNumber,int );
00077     IPLSetMacro(imageNumber,int );
00078     IPLGetMacro(imageNumber,int );
00079     IPLSetMacro(data,void *);
00080     IPLGetMacro(data,const void *);
00081   private:
00082     std::string m_imageFileName;
00083     float m_SliceLocation;
00084     int m_SliceOffset;
00085     int m_echoNumber;
00086     int m_imageNumber;
00087     const void *m_data;
00088   };
00089 
00090 
00094   class IPLFileNameList
00095   {
00096   public:
00097     typedef std::vector<IPLFileSortInfo *> ListType;
00098     typedef ListType::iterator IteratorType;
00099     
00100    enum { SortGlobalAscend = 0,
00101           SortGlobalDescend = 1,
00102           SortByNameAscend = 2,
00103           SortByNameDescend = 3
00104    };
00105     
00106     
00107     IPLFileNameList() 
00108       {
00109       m_XDim = 0;
00110       m_YDim = 0;
00111       m_Key1 = 0;  
00113       m_Key2 = 0;  
00114       m_SortOrder = SortGlobalAscend; 
00115       }
00116     virtual ~IPLFileNameList()
00117     {
00118       IteratorType it = begin();
00119       IteratorType itend = end();
00120       while(it != itend)
00121         {
00122         delete (*it);
00123         it++;
00124         }
00125     }
00126     IteratorType begin() { return m_List.begin(); }
00127     IteratorType end() { return m_List.end(); }
00128     IPLFileSortInfo *operator[](unsigned int __n)
00129     {
00130       IteratorType it = begin();
00131       IteratorType itend= end();
00132       for(unsigned int i = 0; it != itend && i != __n; it++, i++)
00133         ;
00134       if(it == itend)
00135         return 0;
00136       return *it;
00137     }
00138     signed int NumFiles() const {
00139       return m_List.size();
00140     }
00141     bool AddElementToList(char const *const filename, 
00142                                    const float sliceLocation, 
00143                                    const int offset, 
00144                                    const int XDim, 
00145                                    const int YDim, 
00146                                    const int imageNumber, 
00147                                    const int Key1,
00148                                    const int Key2)
00149       {
00150       if(m_List.empty())
00151         {
00152         m_XDim = XDim;
00153         m_YDim = YDim;
00154         m_Key1 = Key1;
00155         m_Key2 = Key2;
00156         }
00157       else if(XDim != m_XDim || YDim != YDim)
00158         {
00159         return false;
00160         }
00161       else if(Key1 != m_Key1 || Key2 != m_Key2)
00162         {
00163         return true;
00164         }
00165       IteratorType it = begin();
00166       IteratorType itend = end();
00167       while(it != itend)
00168         {
00169         if(std::string(filename) == (*it)->GetimageFileName())
00170           return true;
00171         it++;
00172         }
00173       m_List.push_back(new IPLFileSortInfo(filename,
00174                                         sliceLocation,
00175                                         offset,
00176                                         0, // echo number
00177                                         imageNumber));
00178       return true;
00179       }
00180     void RemoveElementFromList(const int ElementToRemove)
00181       {
00182       IteratorType it = m_List.begin();
00183       IteratorType itend = m_List.end();
00184       int i = 0;
00185       for(i = 0; it != itend; i++, it++)
00186         {
00187         if(i != ElementToRemove)
00188           break;
00189         }
00190       if(it == itend)
00191         return;
00192       m_List.erase(it);
00193    }
00194 
00195          
00196     void sortImageList();
00197     void sortImageListAscend();
00198     void sortImageListDescend();
00199 
00200     int GetnumImageInfoStructs() const
00201     {
00202        return m_List.size();
00203     }
00204     IPLSetMacro(XDim,int );
00205     IPLGetMacro(XDim,int );
00206     IPLSetMacro(YDim,int );
00207     IPLGetMacro(YDim,int );
00208     IPLSetMacro(Key1,int );
00209     IPLGetMacro(Key1,int );
00210     IPLSetMacro(Key2,int );
00211     IPLGetMacro(Key2,int );
00212     IPLSetMacro(SortOrder,int );
00213   private:
00214     ListType m_List;
00215     int m_XDim;
00216     int m_YDim;
00217     int m_Key1;  
00219     int m_Key2;  
00220     int m_SortOrder;
00221   };
00222 
00223 }
00224 
00225 #endif                          /* __IPLFileNameList_H__ */

Generated at Wed May 24 23:29:34 2006 for ITK by doxygen 1.3.5 written by Dimitri van Heesch, © 1997-2000