From: frog Date: Wed, 26 Mar 2003 18:38:44 +0000 (+0000) Subject: * src/gdcmHeader[h, cxx] gdcmHeader now has an IsReadable predicate. X-Git-Tag: April2003~5 X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=commitdiff_plain;h=dcbbe0ecd3fe72f4b97aee8ee6145d06063400cb;p=gdcm.git * src/gdcmHeader[h, cxx] gdcmHeader now has an IsReadable predicate. * gdcmPython/demo/test.py changed accordingly. --- Frog --- diff --git a/.cvsignore b/.cvsignore index 04643c47..1326c456 100644 --- a/.cvsignore +++ b/.cvsignore @@ -13,5 +13,5 @@ aclocal.m4 build dist MANIFEST -DCMlib*.tar.gz +gdcm*.tar.gz gdcm.spec diff --git a/ChangeLog b/ChangeLog index e22a8f87..a7d1e2ad 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2003-03-26 Eric Boix + * src/gdcmHeader[h, cxx] gdcmHeader now has an IsReadable predicate. + * gdcmPython/demo/test.py changed accordingly. + 2003-03-25 Eric Boix * gdcmPython/Makefile.am fixed linking against libstdc++ * gdcmPython/_gdcm.so symbolic link to gdcmPython/.libs/pygdcm.so added. diff --git a/gdcmPython/.cvsignore b/gdcmPython/.cvsignore index 11666e7a..0b2b7134 100644 --- a/gdcmPython/.cvsignore +++ b/gdcmPython/.cvsignore @@ -9,3 +9,4 @@ Makefile.in *.la .libs .deps +_gdcm.so diff --git a/gdcmPython/_gdcm.so b/gdcmPython/_gdcm.so deleted file mode 100755 index 8d2325bc..00000000 Binary files a/gdcmPython/_gdcm.so and /dev/null differ diff --git a/gdcmPython/demo/test.py b/gdcmPython/demo/test.py index 935345c1..fa98de2d 100644 --- a/gdcmPython/demo/test.py +++ b/gdcmPython/demo/test.py @@ -1,4 +1,5 @@ from gdcmPython import * +import sys ### Get filename from command line or default it try: @@ -15,6 +16,10 @@ if not os.path.isfile(FileName): ### Build the header element list toRead = gdcmHeader(FileName) +if not toRead.IsReadable(): + print "The ", FileName, " file is not " + print " readable with gdcm. Sorry." + sys.exit() print "##############################################################" print "### Display all the elements and their respective values" diff --git a/src/gdcmHeader.cxx b/src/gdcmHeader.cxx index a16d0693..6a6a277a 100644 --- a/src/gdcmHeader.cxx +++ b/src/gdcmHeader.cxx @@ -714,13 +714,14 @@ void gdcmHeader::LoadElementValue(gdcmElValue * ElVal) { fseek(fp, (long)ElVal->GetOffset(), SEEK_SET); - // Sequences not treated yet ! + // FIXME Sequences not treated yet ! // // Ne faudrait-il pas au contraire trouver immediatement // une maniere 'propre' de traiter les sequences (vr = SQ) // car commencer par les ignorer risque de conduire a qq chose // qui pourrait ne pas etre generalisable - // + // Well, I'm expecting your code !!! + if( vr == "SQ" ) SkipLoad = true; @@ -1415,6 +1416,32 @@ void gdcmHeader::AddAndDefaultElements(void) { NewElVal->SetValue("0"); } +/** + * \ingroup gdcmHeader + * \brief This predicate, based on hopefully reasonnable heuristics, + * decides whether or not the current gdcmHeader was properly parsed + * and contains the mandatory information for being considered as + * a well formed and usable image. + * @return true when gdcmHeader is the one of a reasonable Dicom file, + * false otherwise. + */ +bool gdcmHeader::IsReadable(void) { + if ( GetElValByName("Image Dimensions") != "gdcm::Unfound" + && atoi(GetElValByName("Image Dimensions").c_str()) > 4 ) { + return false; + } + if ( GetElValByName("Bits Allocated") == "gdcm::Unfound" ) + return false; + if ( GetElValByName("Bits Stored") == "gdcm::Unfound" ) + return false; + if ( GetElValByName("High Bit") == "gdcm::Unfound" ) + return false; + if ( GetElValByName("Pixel Representation") == "gdcm::Unfound" ) + return false; + return true; +} + + /** * \ingroup gdcmHeader * \brief Small utility function that creates a new manually crafted diff --git a/src/gdcmHeader.h b/src/gdcmHeader.h index ec1943ba..7aec5e52 100644 --- a/src/gdcmHeader.h +++ b/src/gdcmHeader.h @@ -123,6 +123,7 @@ protected: int anonymize(ostream&); // FIXME : anonymize should be a friend ? public: void LoadElements(void); + bool IsReadable(void); virtual void ParseHeader(bool exception_on_error = false) throw(gdcmFormatError); gdcmHeader(const char *filename, bool exception_on_error = false)