ITK  4.1.0
Insight Segmentation and Registration Toolkit
itkIPLFileNameList.h
Go to the documentation of this file.
00001 /*=========================================================================
00002  *
00003  *  Copyright Insight Software Consortium
00004  *
00005  *  Licensed under the Apache License, Version 2.0 (the "License");
00006  *  you may not use this file except in compliance with the License.
00007  *  You may obtain a copy of the License at
00008  *
00009  *         http://www.apache.org/licenses/LICENSE-2.0.txt
00010  *
00011  *  Unless required by applicable law or agreed to in writing, software
00012  *  distributed under the License is distributed on an "AS IS" BASIS,
00013  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00014  *  See the License for the specific language governing permissions and
00015  *  limitations under the License.
00016  *
00017  *=========================================================================*/
00018 /*=========================================================================
00019  *
00020  *  Portions of this file are subject to the VTK Toolkit Version 3 copyright.
00021  *
00022  *  Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
00023  *
00024  *  For complete copyright, license and disclaimer of warranty information
00025  *  please refer to the NOTICE file at the top of the ITK source tree.
00026  *
00027  *=========================================================================*/
00028 #ifndef __itkIPLFileNameList_h
00029 #define __itkIPLFileNameList_h
00030 
00031 #include "itkMacro.h"
00032 #include "itkObject.h"
00033 
00034 #include <stdio.h>
00035 #include <string>
00036 #include <list>
00038 #define IPLSetMacro(name, type)              \
00039   virtual void Set##name (const type _arg) \
00040     {                                        \
00041     if ( this->m_##name != _arg )          \
00042       {                                      \
00043       this->m_##name = _arg;               \
00044       }                                      \
00045     }
00046 
00047 
00049 #define IPLGetMacro(name, type) \
00050   virtual type Get##name ()   \
00051     {                           \
00052     return this->m_##name;    \
00053     }
00054 
00055 
00056 namespace itk
00057 {
00062 class IPLFileSortInfo
00063 {
00064 public:
00065   IPLFileSortInfo()
00066   {
00067     m_SliceLocation = 0;
00068     m_SliceOffset = 0;
00069     m_EchoNumber = 0;
00070     m_ImageNumber = 0;
00071     m_Data = 0;
00072   }
00073 
00074   IPLFileSortInfo(const char *const filename, float sliceLocation,
00075                   int sliceOffset, int echoNumber, int imageNumber,
00076                   void *data = 0)
00077   {
00078     m_ImageFileName = filename;
00079     m_SliceLocation = sliceLocation;
00080     m_SliceOffset = sliceOffset;
00081     m_EchoNumber = echoNumber;
00082     m_ImageNumber = imageNumber;
00083     m_Data = data;
00084   }
00085 
00086   virtual ~IPLFileSortInfo() {}
00087 
00088   IPLSetMacro(ImageFileName, std::string);
00089   IPLGetMacro(ImageFileName, std::string);
00090   IPLSetMacro(SliceLocation, float);
00091   IPLGetMacro(SliceLocation, float);
00092   IPLSetMacro(SliceOffset, int);
00093   IPLGetMacro(SliceOffset, int);
00094   IPLSetMacro(EchoNumber, int);
00095   IPLGetMacro(EchoNumber, int);
00096   IPLSetMacro(ImageNumber, int);
00097   IPLGetMacro(ImageNumber, int);
00098   IPLSetMacro(Data, void *);
00099   IPLGetMacro(Data, const void *);
00100 private:
00101   std::string m_ImageFileName;
00102   float       m_SliceLocation;
00103   int         m_SliceOffset;
00104   int         m_EchoNumber;
00105   int         m_ImageNumber;
00106   const void *m_Data;
00107 };
00108 
00113 class ITK_EXPORT IPLFileNameList
00114 {
00115 public:
00116   typedef std::vector< IPLFileSortInfo * > ListType;
00117   typedef ListType::iterator               IteratorType;
00118   typedef size_t                           ListSizeType;
00119 
00120   enum {
00121     SortGlobalAscend = 0,
00122     SortGlobalDescend = 1,
00123     SortByNameAscend = 2,
00124     SortByNameDescend = 3
00125     };
00126 
00127   IPLFileNameList()
00128   {
00129     m_XDim = 0;
00130     m_YDim = 0;
00131     m_XRes = 0.0;
00132     m_YRes = 0.0;
00138     m_SortOrder = SortGlobalAscend;
00139   }
00140 
00141   virtual ~IPLFileNameList()
00142   {
00143     IteratorType it = begin();
00144     IteratorType itend = end();
00145 
00146     while ( it != itend )
00147       {
00148       delete ( *it );
00149       it++;
00150       }
00151   }
00152 
00153   IteratorType begin()
00154   {
00155     return m_List.begin();
00156   }
00157 
00158   IteratorType end()
00159   {
00160     return m_List.end();
00161   }
00162 
00163   IPLFileSortInfo * operator[](unsigned int __n)
00164   {
00165     IteratorType it = begin();
00166     IteratorType itend = end();
00167 
00168     for ( unsigned int i = 0; it != itend && i != __n; it++, i++ )
00169         {}
00170     if ( it == itend )
00171       {
00172       return 0;
00173       }
00174     return *it;
00175   }
00176 
00177   ListSizeType NumFiles() const
00178   {
00179     return m_List.size();
00180   }
00181 
00182   bool AddElementToList(char const *const filename,
00183                         const float sliceLocation,
00184                         const int offset,
00185                         const int XDim,
00186                         const int YDim,
00187                         const float XRes,
00188                         const float YRes,
00189                         const int imageNumber,
00190                         const int Key1,
00191                         const int Key2)
00192   {
00193     if ( m_List.empty() )
00194       {
00195       m_XDim = XDim;
00196       m_YDim = YDim;
00197       m_XRes = XRes;
00198       m_YRes = YRes;
00199       m_Key1 = Key1;
00200       m_Key2 = Key2;
00201       }
00202     else if ( XDim != m_XDim || YDim != m_YDim )
00203       {
00204       return false;
00205       }
00206     else if(XRes != m_XRes || YRes != m_YRes)
00207       {
00208       return false;
00209       }
00210     else if ( Key1 != m_Key1 || Key2 != m_Key2 )
00211       {
00212       return true;
00213       }
00214     IteratorType it = begin();
00215     IteratorType itend = end();
00216     while ( it != itend )
00217       {
00218       if ( std::string(filename) == ( *it )->GetImageFileName() )
00219         {
00220         return true;
00221         }
00222       it++;
00223       }
00224     m_List.push_back( new IPLFileSortInfo(filename,
00225                                           sliceLocation,
00226                                           offset,
00227                                           0, // echo number
00228                                           imageNumber) );
00229     return true;
00230   }
00231 
00232   void RemoveElementFromList(const int ElementToRemove)
00233   {
00234     IteratorType it = m_List.begin();
00235     IteratorType itend = m_List.end();
00236     int          i = 0;
00237 
00238     for ( i = 0; it != itend; i++, it++ )
00239       {
00240       if ( i != ElementToRemove )
00241         {
00242         break;
00243         }
00244       }
00245     if ( it == itend )
00246       {
00247       return;
00248       }
00249     m_List.erase(it);
00250   }
00251 
00252   void sortImageList();
00253 
00254   void sortImageListAscend();
00255 
00256   void sortImageListDescend();
00257 
00258   ListSizeType GetnumImageInfoStructs() const
00259   {
00260     return m_List.size();
00261   }
00262 
00263   IPLSetMacro(XDim, int);
00264   IPLGetMacro(XDim, int);
00265   IPLSetMacro(YDim, int);
00266   IPLGetMacro(YDim, int);
00267   IPLSetMacro(XRes, float);
00268   IPLGetMacro(XRes, float);
00269   IPLSetMacro(YRes, float);
00270   IPLGetMacro(YRes, float);
00271   IPLSetMacro(Key1, int);
00272   IPLGetMacro(Key1, int);
00273   IPLSetMacro(Key2, int);
00274   IPLGetMacro(Key2, int);
00275   IPLSetMacro(SortOrder, int);
00276 private:
00277   ListType m_List;
00278   int      m_XDim;
00279   int      m_YDim;
00280   float    m_XRes;
00281   float    m_YRes;