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 
00003   Program:   Insight Segmentation & Registration Toolkit
00004   Module:    $RCSfile: itkIPLFileNameList.h,v $
00005   Language:  C++
00006   Date:      $Date: 2007/01/04 16:46:32 $
00007   Version:   $Revision: 1.9 $
00008 
00009   Copyright (c) Insight Software Consortium. All rights reserved.
00010   See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details.
00011 
00012   Portions of this code are covered under the VTK copyright.
00013   See VTKCopyright.txt or http://www.kitware.com/VTKCopyright.htm for details.
00014 
00015      This software is distributed WITHOUT ANY WARRANTY; without even 
00016      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
00017      PURPOSE.  See the above copyright notices for more information.
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       m_SliceLocation = 0;
00057       m_SliceOffset = 0;
00058       m_echoNumber = 0;
00059       m_imageNumber = 0;
00060       m_data = 0;
00061     }
00062     virtual ~IPLFileSortInfo() {
00063     }
00064     IPLFileSortInfo(const char *const filename,float SliceLocation,
00065                  int SliceOffset,int echoNumber,int imageNumber,void *data = 0)
00066     {
00067       m_imageFileName = filename;
00068       m_SliceLocation = SliceLocation;
00069       m_SliceOffset = SliceOffset;
00070       m_echoNumber = echoNumber;
00071       m_imageNumber = imageNumber;
00072       m_data = data;
00073     }
00074       
00075     IPLSetMacro(imageFileName,std::string );
00076     IPLGetMacro(imageFileName,std::string );
00077     IPLSetMacro(SliceLocation,float );
00078     IPLGetMacro(SliceLocation,float );
00079     IPLSetMacro(SliceOffset,int );
00080     IPLGetMacro(SliceOffset,int );
00081     IPLSetMacro(echoNumber,int );
00082     IPLGetMacro(echoNumber,int );
00083     IPLSetMacro(imageNumber,int );
00084     IPLGetMacro(imageNumber,int );
00085     IPLSetMacro(data,void *);
00086     IPLGetMacro(data,const void *);
00087   private:
00088     std::string m_imageFileName;
00089     float m_SliceLocation;
00090     int m_SliceOffset;
00091     int m_echoNumber;
00092     int m_imageNumber;
00093     const void *m_data;
00094   };
00095 
00096 
00100   class IPLFileNameList
00101   {
00102   public:
00103     typedef std::vector<IPLFileSortInfo *> ListType;
00104     typedef ListType::iterator IteratorType;
00105     typedef size_t             ListSizeType;
00106     
00107    enum { SortGlobalAscend = 0,
00108           SortGlobalDescend = 1,
00109           SortByNameAscend = 2,
00110           SortByNameDescend = 3
00111    };
00112     
00113     
00114     IPLFileNameList() 
00115       {
00116       m_XDim = 0;
00117       m_YDim = 0;
00122       m_SortOrder = SortGlobalAscend; 
00123       }
00124     virtual ~IPLFileNameList()
00125     {
00126       IteratorType it = begin();
00127       IteratorType itend = end();
00128       while(it != itend)
00129         {
00130         delete (*it);
00131         it++;
00132         }
00133     }
00134     IteratorType begin() { return m_List.begin(); }
00135     IteratorType end() { return m_List.end(); }
00136     IPLFileSortInfo *operator[](unsigned int __n)
00137     {
00138       IteratorType it = begin();
00139       IteratorType itend= end();
00140       for(unsigned int i = 0; it != itend && i != __n; it++, i++)
00141         ;
00142       if(it == itend)
00143         return 0;
00144       return *it;
00145     }
00146     ListSizeType NumFiles() const {
00147       return m_List.size();
00148     }
00149     bool AddElementToList(char const *const filename, 
00150                                    const float sliceLocation, 
00151                                    const int offset, 
00152                                    const int XDim, 
00153                                    const int YDim, 
00154                                    const int imageNumber, 
00155                                    const int Key1,
00156                                    const int Key2)
00157       {
00158       if(m_List.empty())
00159         {
00160         m_XDim = XDim;
00161         m_YDim = YDim;
00162         m_Key1 = Key1;
00163         m_Key2 = Key2;
00164         }
00165       else if(XDim != m_XDim || YDim != YDim)
00166         {
00167         return false;
00168         }
00169       else if(Key1 != m_Key1 || Key2 != m_Key2)
00170         {
00171         return true;
00172         }
00173       IteratorType it = begin();
00174       IteratorType itend = end();
00175       while(it != itend)
00176         {
00177         if(std::string(filename) == (*it)->GetimageFileName())
00178           return true;
00179         it++;
00180         }
00181       m_List.push_back(new IPLFileSortInfo(filename,
00182                                         sliceLocation,
00183                                         offset,
00184                                         0, // echo number
00185                                         imageNumber));
00186       return true;
00187       }
00188     void RemoveElementFromList(const int ElementToRemove)
00189       {
00190       IteratorType it = m_List.begin();
00191       IteratorType itend = m_List.end();
00192       int i = 0;
00193       for(i = 0; it != itend; i++, it++)
00194         {
00195         if(i != ElementToRemove)
00196           break;
00197         }
00198       if(it == itend)
00199         return;
00200       m_List.erase(it);
00201    }
00203 
00204          
00205     void sortImageList();
00206     void sortImageListAscend();
00207     void sortImageListDescend();
00208 
00209     ListSizeType GetnumImageInfoStructs() const
00210     {
00211        return m_List.size();
00212     }
00213     IPLSetMacro(XDim,int );
00214     IPLGetMacro(XDim,int );
00215     IPLSetMacro(YDim,int );
00216     IPLGetMacro(YDim,int );
00217     IPLSetMacro(Key1,int );
00218     IPLGetMacro(Key1,int );
00219     IPLSetMacro(Key2,int );
00220     IPLGetMacro(Key2,int );
00221     IPLSetMacro(SortOrder,int );
00222   private:
00223     ListType m_List;
00224     int m_XDim;
00225     int m_YDim;
00230     int m_SortOrder;
00231   };
00232 
00233 }
00234 
00235 #endif                          /* __itkIPLFileNameList_h */
00236 

Generated at Mon Mar 12 01:23:02 2007 for ITK by doxygen 1.5.1 written by Dimitri van Heesch, © 1997-2000