]> Creatis software - gdcm.git/blobdiff - src/gdcmFileHelper.cxx
Meta Elements group length (follows previous commit)
[gdcm.git] / src / gdcmFileHelper.cxx
index a25ad858a01fc1e2c524d9a45b17fb8fe52c333d..e91570e2833ee4a2ee654470002d92259bea5621 100644 (file)
@@ -4,8 +4,8 @@
   Module:    $RCSfile: gdcmFileHelper.cxx,v $
   Language:  C++
 
-  Date:      $Date: 2005/07/08 14:36:48 $
-  Version:   $Revision: 1.47 $
+  Date:      $Date: 2005/09/07 08:55:23 $
+  Version:   $Revision: 1.58 $
                                                                                 
   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
   l'Image). All rights reserved. See Doc/License.txt or
 These lines will be moved to the document-to-be 'User's Guide'
 
 // To read an image, user needs a gdcm::File
-gdcm::File *f1 = new gdcm::File(fileName);
+gdcm::File *f = new gdcm::File(fileName);
+// or (advanced) :
+// user may also decide he doesn't want to load some parts of the header
+gdcm::File *f = new gdcm::File();
+f->SetFileName(fileName);
+   f->SetLoadMode(LD_NOSEQ);             // or      
+   f->SetLoadMode(LD_NOSHADOW);          // or
+   f->SetLoadMode(LD_NOSEQ | LD_NOSHADOW); // or
+   f->SetLoadMode(LD_NOSHADOWSEQ);
+f->Load();
+
 // user can now check some values
-std::string v = f1->GetEntryValue(groupNb,ElementNb);
+std::string v = f->GetEntryValue(groupNb,ElementNb);
+
 // to get the pixels, user needs a gdcm::FileHelper
-gdcm::FileHelper *fh1 = new gdcm::FileHelper(f1);
+gdcm::FileHelper *fh = new gdcm::FileHelper(f);
 // user may ask not to convert Palette to RGB
-uint8_t *pixels = fh1->GetImageDataRaw();
-int imageLength = fh1->GetImageDataRawSize();
+uint8_t *pixels = fh->GetImageDataRaw();
+int imageLength = fh->GetImageDataRawSize();
 // He can now use the pixels, create a new image, ...
 uint8_t *userPixels = ...
 
 To re-write the image, user re-uses the gdcm::FileHelper
 
-fh1->SetImageData( userPixels, userPixelsLength);
-fh1->SetTypeToRaw(); // Even if it was possible to convert Palette to RGB
+fh->SetImageData( userPixels, userPixelsLength);
+fh->SetTypeToRaw(); // Even if it was possible to convert Palette to RGB
                      // (WriteMode is set)
  
-fh1->SetWriteTypeToDcmExpl(); // he wants Explicit Value Representation
+fh->SetWriteTypeToDcmExpl(); // he wants Explicit Value Representation
                               // Little Endian is the default
                               // no other value is allowed
                                 (-->SetWriteType(ExplicitVR);)
                                    -->WriteType = ExplicitVR;
-fh1->Write(newFileName);      // overwrites the file, if any
+fh->Write(newFileName);      // overwrites the file, if any
 
 // or :
-fh1->WriteDcmExplVR(newFileName);
+fh->WriteDcmExplVR(newFileName);
 
 
 // ----------------------------- WARNING -------------------------
@@ -89,7 +100,7 @@ fh1->Write(newFileName);
       (checks user given pixels length)
    FileInternal->Write(fileName,WriteType)
    fp = opens file(fileName);
-   ComputeGroup0002Length(writetype);
+   ComputeGroup0002Length( );
    BitsAllocated 12->16
       RemoveEntryNoDestroy(palettes, etc)
       Document::WriteContent(fp, writetype);
@@ -112,6 +123,7 @@ namespace gdcm
  *        Opens (in read only and when possible) an existing file and checks
  *        for DICOM compliance. Returns NULL on failure.
  *        It will be up to the user to load the pixels into memory
+ *        ( GetImageDataSize() + GetImageData() methods)
  * \note  the in-memory representation of all available tags found in
  *        the DICOM header is post-poned to first header information access.
  *        This avoid a double parsing of public part of the header when
@@ -119,7 +131,7 @@ namespace gdcm
  *        seen as a side effect).   
  */
 FileHelper::FileHelper( )
-{
+{ 
    FileInternal = new File( );
    SelfHeader = true;
    Initialize();
@@ -131,6 +143,7 @@ FileHelper::FileHelper( )
  *        Opens (in read only and when possible) an existing file and checks
  *        for DICOM compliance. Returns NULL on failure.
  *        It will be up to the user to load the pixels into memory
+ *        ( GetImageDataSize() + GetImageData() methods)
  * \note  the in-memory representation of all available tags found in
  *        the DICOM header is post-poned to first header information access.
  *        This avoid a double parsing of public part of the header when
@@ -143,10 +156,15 @@ FileHelper::FileHelper(File *header)
    FileInternal = header;
    SelfHeader = false;
    Initialize();
+   if ( FileInternal->IsReadable() )
+   {
+      PixelReadConverter->GrabInformationsFromFile( FileInternal );
+   }
 }
 
+#ifndef GDCM_LEGACY_REMOVE
 /**
- * \brief DEPRECATED : use SetFilename() + Load() methods
+ * \brief DEPRECATED : use SetFilename() + SetLoadMode() + Load() methods
  *        Constructor dedicated to deal with the *pixels* area of a ACR/DICOMV3
  *        file (gdcm::File only deals with the ... header)
  *        Opens (in read only and when possible) an existing file and checks
@@ -158,13 +176,21 @@ FileHelper::FileHelper(File *header)
  *        one sets an a posteriori shadow dictionary (efficiency can be
  *        seen as a side effect).   
  * @param filename file to be opened for parsing
+ * @deprecated  use SetFilename() + Load() methods
  */
 FileHelper::FileHelper(std::string const &filename )
 {
-   FileInternal = new File( filename );
+   FileInternal = new File( );
+   FileInternal->SetFileName( filename );
+   FileInternal->Load();
    SelfHeader = true;
    Initialize();
+   if ( FileInternal->IsReadable() )
+   {
+      PixelReadConverter->GrabInformationsFromFile( FileInternal );
+   }
 }
+#endif
 
 /**
  * \brief canonical destructor
@@ -203,7 +229,7 @@ FileHelper::~FileHelper()
  *        WARNING : before using NO_SHADOW, be sure *all* your files
  *        contain accurate values in the 0x0000 element (if any) 
  *        of *each* Shadow Group. The parser will fail if the size is wrong !
- * @param   mode Load mode to be used    
+ * @param   loadMode Load mode to be used    
  */
 void FileHelper::SetLoadMode(int loadMode) 
 { 
@@ -225,7 +251,11 @@ void FileHelper::SetFileName(std::string const &fileName)
  */
 bool FileHelper::Load()
 { 
-   return FileInternal->Load();
+   if ( !FileInternal->Load() )
+      return false;
+
+   PixelReadConverter->GrabInformationsFromFile( FileInternal );
+   return true;
 }
 
 /**
@@ -386,9 +416,11 @@ uint8_t *FileHelper::GetImageDataRaw ()
    return GetRaw();
 }
 
+#ifndef GDCM_LEGACY_REMOVE
 /**
- * \brief
- *          Read the pixels from disk (uncompress if necessary),
+ * \brief   Useless function, since PixelReadConverter forces us 
+ *          copy the Pixels anyway.  
+ *          Reads the pixels from disk (uncompress if necessary),
  *          Transforms YBR pixels, if any, into RGB pixels
  *          Transforms 3 planes R, G, B, if any, into a single RGB Plane
  *          Transforms single Grey plane + 3 Palettes into a RGB Plane   
@@ -443,6 +475,7 @@ size_t FileHelper::GetImageDataIntoVector (void *destination, size_t maxSize)
            PixelReadConverter->GetRawSize() );
    return PixelReadConverter->GetRawSize();
 }
+#endif
 
 /**
  * \brief   Points the internal pointer to the callers inData
@@ -1208,7 +1241,9 @@ void FileHelper::CheckMandatoryElements()
 
    // 'Implementation Version Name'
       ValEntry *e_0002_0013 = CopyValEntry(0x0002,0x0013);
-      e_0002_0013->SetValue("GDCM 1.1");
+      std::string version = "GDCM ";
+      version += Util::GetVersion();
+      e_0002_0013->SetValue(version);
       Archive->Push(e_0002_0013);
 
    //'Source Application Entity Title' Not Mandatory
@@ -1506,17 +1541,14 @@ void FileHelper::RestoreWriteMandatory()
  */
 void FileHelper::Initialize()
 {
+   UserFunction = 0;
+
    WriteMode = WMODE_RAW;
    WriteType = ExplicitVR;
 
    PixelReadConverter  = new PixelReadConvert;
    PixelWriteConverter = new PixelWriteConvert;
    Archive = new DocEntryArchive( FileInternal );
-
-   if ( FileInternal->IsReadable() )
-   {
-      PixelReadConverter->GrabInformationsFromFile( FileInternal );
-   }
 }
 
 /**
@@ -1527,6 +1559,8 @@ void FileHelper::Initialize()
  */ 
 uint8_t *FileHelper::GetRaw()
 {
+   PixelReadConverter->SetUserFunction( UserFunction );
+
    uint8_t *raw = PixelReadConverter->GetRaw();
    if ( ! raw )
    {
@@ -1557,8 +1591,11 @@ void FileHelper::Print(std::ostream &os, std::string const &)
    FileInternal->SetPrintLevel(PrintLevel);
    FileInternal->Print(os);
 
-   PixelReadConverter->SetPrintLevel(PrintLevel);
-   PixelReadConverter->Print(os);
+   if ( FileInternal->IsReadable() )
+   {
+      PixelReadConverter->SetPrintLevel(PrintLevel);
+      PixelReadConverter->Print(os);
+   }
 }
 
 //-----------------------------------------------------------------------------