gdcmSerieHelper.h

Go to the documentation of this file.
00001 /*=========================================================================
00002                                                                                 
00003   Program:   gdcm
00004   Module:    $RCSfile: gdcmSerieHelper.h,v $
00005   Language:  C++
00006   Date:      $Date: 2007/08/22 16:14:04 $
00007   Version:   $Revision: 1.44 $
00008                                                                                 
00009   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
00010   l'Image). All rights reserved. See Doc/License.txt or
00011   http://www.creatis.insa-lyon.fr/Public/Gdcm/License.html for details.
00012                                                                                 
00013      This software is distributed WITHOUT ANY WARRANTY; without even
00014      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
00015      PURPOSE.  See the above copyright notices for more information.
00016                                                                                 
00017 =========================================================================*/
00018 
00019 #ifndef _GDCMSERIEHELPER_H_
00020 #define _GDCMSERIEHELPER_H_
00021 
00022 #include "gdcmRefCounter.h"
00023 #include "gdcmTagKey.h" 
00024 #include "gdcmDebug.h"  // for LEGACY
00025 
00026 #include "gdcmDicomDirSerie.h"
00027  
00028 #include <vector>
00029 #include <iostream>
00030 #include <map>
00031 
00032 namespace GDCM_NAME_SPACE 
00033 {
00034 class File;
00035 
00036    typedef std::vector<File* > FileList;
00037 #ifndef GDCM_LEGACY_REMOVE
00038 typedef std::vector<File* > GdcmFileList;
00039 #endif
00040 
00045    typedef std::map<std::string, FileList *> XCoherentFileSetmap;
00046 
00047    typedef bool (*BOOL_FUNCTION_PFILE_PFILE_POINTER)(File *, File *);
00048 
00049 //-----------------------------------------------------------------------------
00063 class GDCM_EXPORT SerieHelper  : public RefCounter
00064 {
00065    gdcmTypeMacro(SerieHelper);
00066    
00067 public:
00071    typedef std::map<std::string, FileList *> SingleSerieUIDFileSetmap;
00072 
00073    typedef std::vector<File* > FileVector;
00074 
00076     static SerieHelper *New() {return new SerieHelper();}
00077      
00078    virtual ~SerieHelper();
00079    void Print(std::ostream &os = std::cout, std::string const &indent = "" );
00080 
00082    void AddFileName(std::string const &filename);
00083    bool AddFile(File *header);
00084  //  GDCM_LEGACY(bool AddGdcmFile(File* header))
00085 
00086    void SetDirectory(std::string const &dir, bool recursive=false);
00087    void SetDicomDirSerie(DicomDirSerie *se);
00088       
00089    bool IsCoherent(FileList *fileSet);
00090    void OrderFileList(FileList *fileSet);
00091    void Clear() { ClearAll(); }
00092 
00097    const FileList &GetFileList()
00098                            { return *SingleSerieUIDFileSetHT.begin()->second; }
00099   
00100  //  GDCM_LEGACY(   FileList *GetFirstCoherentFileList()  )
00101  //  GDCM_LEGACY(   FileList *GetNextCoherentFileList()   )
00102  //  GDCM_LEGACY(   FileList *GetCoherentFileList(std::string serieUID)  )
00103 
00104    FileList *GetFirstSingleSerieUIDFileSet();
00105    FileList *GetNextSingleSerieUIDFileSet();
00106    FileList *GetSingleSerieUIDFileSet(std::string serieUID);
00108    std::string GetCurrentSerieUIDFileSetUID()
00109                              { return  (*ItFileSetHt).first; }
00110      
00116    double GetZSpacing() { return ZSpacing; }
00117    
00123    void AddRestriction(TagKey const &key);
00124    void AddRestriction(TagKey const &key, std::string const &value, int op);
00125    void AddRestriction(uint16_t group, uint16_t elem, std::string const &value,
00126                                                                     int op);
00127 
00131    void SetUseSeriesDetails( bool useSeriesDetails )
00132      {
00133      m_UseSeriesDetails = useSeriesDetails;
00134      }
00135    bool GetUseSeriesDetails()
00136      {
00137      return m_UseSeriesDetails;
00138      }
00147    void CreateDefaultUniqueSeriesIdentifier();
00148 
00149    void AddSeriesDetail(uint16_t group, uint16_t elem, bool convert);
00150 
00151    std::string CreateUserDefinedFileIdentifier( File * inFile );
00152 
00154    //         uses the SeriesUID.   If UseSeriesDetails(true) has been called,
00155    //         then additional identifying information is used.
00156    std::string CreateUniqueSeriesIdentifier( File * inFile );
00157  
00167    void SetLoadMode (int mode) { LoadMode = mode; }
00168    
00173    void SetDropDuplicatePositions (bool drop) { DropDuplicatePositions = drop; }   
00174 
00176    void SetSortOrderToDirect()  { DirectOrder = true;  }
00177 
00179    void SetSortOrderToReverse() { DirectOrder = false; }
00180 
00182    void SetUserLessThanFunction( BOOL_FUNCTION_PFILE_PFILE_POINTER userFunc ) 
00183                         { UserLessThanFunction = userFunc; }  
00184 
00185    XCoherentFileSetmap SplitOnOrientation(FileList *fileSet); 
00186    XCoherentFileSetmap SplitOnPosition(FileList *fileSet); 
00187    XCoherentFileSetmap SplitOnTagValue(FileList *fileSet,
00188                                                uint16_t group, uint16_t element);
00189 protected :
00190    SerieHelper();
00191    
00192 private:
00193    void ClearAll();
00194    bool UserOrdering(FileList *fileSet);
00195    bool ImagePositionPatientOrdering(FileList *fileSet);
00196    bool ImageNumberOrdering(FileList *fileSet);
00197    bool FileNameOrdering(FileList *fileSet);
00198    
00199    static bool ImageNumberLessThan(File *file1, File *file2);
00200    static bool ImageNumberGreaterThan(File *file1, File *file2);
00201    static bool FileNameLessThan(File *file1, File *file2);
00202    static bool FileNameGreaterThan(File *file1, File *file2);
00203 
00204 //Attributes:
00205    
00206    SingleSerieUIDFileSetmap SingleSerieUIDFileSetHT;
00207    SingleSerieUIDFileSetmap::iterator ItFileSetHt;
00208 
00209 #ifndef GDCM_LEGACY_REMOVE
00210    typedef std::pair<TagKey, std::string> Rule;
00211    typedef std::vector<Rule> SerieRestrictions;
00212    SerieRestrictions Restrictions;
00213 #endif
00214 
00215    // New style for (extented) Rules
00216    typedef struct {
00217       uint16_t group;
00218       uint16_t elem;
00219       std::string value;
00220       int op;
00221    } ExRule;
00222    typedef std::vector<ExRule> SerieExRestrictions;
00223    SerieExRestrictions ExRestrictions;
00224    SerieExRestrictions ExRefine;
00225 
00226    typedef struct {
00227       uint16_t group;
00228       uint16_t elem;
00229       bool convert;
00230    } ExDetail;
00231    typedef std::vector<ExDetail> SeriesExDetails; 
00232    SeriesExDetails ExDetails;
00233     
00234    
00239    int LoadMode;
00240 
00243    bool DirectOrder;
00244 
00247    BOOL_FUNCTION_PFILE_PFILE_POINTER UserLessThanFunction;
00248 
00249    bool DropDuplicatePositions;
00250 
00251    void Sort(FileList *fileList, bool (*pt2Func)( File *file1, File *file2) );
00252 
00253    bool m_UseSeriesDetails;
00259    double ZSpacing; 
00260 };
00261 
00262 } // end namespace gdcm
00263 
00264 //-----------------------------------------------------------------------------
00265 #endif

Generated on Fri Aug 24 12:59:32 2007 for gdcm by  doxygen 1.4.6