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: 2006/02/05 20:57:46 $
00007   Version:   $Revision: 1.8 $
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     
00106    enum { SortGlobalAscend = 0,
00107           SortGlobalDescend = 1,
00108           SortByNameAscend = 2,
00109           SortByNameDescend = 3
00110    };
00111     
00112     
00113     IPLFileNameList() 
00114       {
00115       m_XDim = 0;
00116       m_YDim = 0;
00121       m_SortOrder = SortGlobalAscend; 
00122       }
00123     virtual ~IPLFileNameList()
00124     {
00125       IteratorType it = begin();
00126       IteratorType itend = end();
00127       while(it != itend)
00128         {
00129         delete (*it);
00130         it++;
00131         }
00132     }
00133     IteratorType begin() { return m_List.begin(); }
00134     IteratorType end() { return m_List.end(); }
00135     IPLFileSortInfo *operator[](unsigned int __n)
00136     {
00137       IteratorType it = begin();
00138       IteratorType itend= end();
00139       for(unsigned int i = 0; it != itend && i != __n; it++, i++)
00140         ;
00141       if(it == itend)
00142         return 0;
00143       return *it;
00144     }
00145     signed int NumFiles() const {
00146       return m_List.size();
00147     }
00148     bool AddElementToList(char const *const filename, 
00149                                    const float sliceLocation, 
00150                                    const int offset, 
00151                                    const int XDim, 
00152                                    const int YDim, 
00153                                    const int imageNumber, 
00154                                    const int Key1,
00155                                    const int Key2)
00156       {
00157       if(m_List.empty())
00158         {
00159         m_XDim = XDim;
00160         m_YDim = YDim;
00161         m_Key1 = Key1;
00162         m_Key2 = Key2;
00163         }
00164       else if(XDim != m_XDim || YDim != YDim)
00165         {
00166         return false;
00167         }
00168       else if(Key1 != m_Key1 || Key2 != m_Key2)
00169         {
00170         return true;
00171         }
00172       IteratorType it = begin();
00173       IteratorType itend = end();
00174       while(it != itend)
00175         {
00176         if(std::string(filename) == (*it)->GetimageFileName())
00177           return true;
00178         it++;
00179         }
00180       m_List.push_back(new IPLFileSortInfo(filename,
00181                                         sliceLocation,
00182                                         offset,
00183                                         0, // echo number
00184                                         imageNumber));
00185       return true;
00186       }
00187     void RemoveElementFromList(const int ElementToRemove)
00188       {
00189       IteratorType it = m_List.begin();
00190       IteratorType itend = m_List.end();
00191       int i = 0;
00192       for(i = 0; it != itend; i++, it++)
00193         {
00194         if(i != ElementToRemove)
00195           break;
00196         }
00197       if(it == itend)
00198         return;
00199       m_List.erase(it);
00200    }
00202 
00203          
00204     void sortImageList();
00205     void sortImageListAscend();
00206     void sortImageListDescend();
00207 
00208     int GetnumImageInfoStructs() const
00209     {
00210        return m_List.size();
00211     }
00212     IPLSetMacro(XDim,int );
00213     IPLGetMacro(XDim,int );
00214     IPLSetMacro(YDim,int );
00215     IPLGetMacro(YDim,int );
00216     IPLSetMacro(Key1,int );
00217     IPLGetMacro(Key1,int );
00218     IPLSetMacro(Key2,int );
00219     IPLGetMacro(Key2,int );
00220     IPLSetMacro(SortOrder,int );
00221   private:
00222     ListType m_List;
00223     int m_XDim;
00224     int m_YDim;
00229     int m_SortOrder;
00230   };
00231 
00232 }
00233 
00234 #endif                          /* __itkIPLFileNameList_h */
00235 

Generated at Sat Sep 2 20:43:57 2006 for ITK by doxygen 1.4.7 written by Dimitri van Heesch, © 1997-2000