X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=src%2FgdcmFileHelper.cxx;h=e91570e2833ee4a2ee654470002d92259bea5621;hb=fa8fa610de8d935491343df2d8a543ff6fdb6e69;hp=0aeffd71d5ad91a34246d8ccd7b6e4ddfbffcf74;hpb=9ca0e4bb2208be93bebf21d0c5d75c8018e7605a;p=gdcm.git diff --git a/src/gdcmFileHelper.cxx b/src/gdcmFileHelper.cxx index 0aeffd71..e91570e2 100644 --- a/src/gdcmFileHelper.cxx +++ b/src/gdcmFileHelper.cxx @@ -4,8 +4,8 @@ Module: $RCSfile: gdcmFileHelper.cxx,v $ Language: C++ - Date: $Date: 2005/06/24 10:55:59 $ - Version: $Revision: 1.46 $ + 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 @@ -42,32 +42,43 @@ 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,16 @@ FileHelper::FileHelper(File *header) FileInternal = header; SelfHeader = false; Initialize(); + if ( FileInternal->IsReadable() ) + { + PixelReadConverter->GrabInformationsFromFile( FileInternal ); + } } +#ifndef GDCM_LEGACY_REMOVE /** - * \brief Constructor dedicated to deal with the *pixels* area of a ACR/DICOMV3 + * \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 * for DICOM compliance. Returns NULL on failure. @@ -157,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 @@ -194,6 +221,43 @@ FileHelper::~FileHelper() //----------------------------------------------------------------------------- // Public + +/** + * \brief Sets the LoadMode of the internal gdcm::File as a boolean string. + * NO_SEQ, NO_SHADOW, NO_SHADOWSEQ + *... (nothing more, right now) + * 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 loadMode Load mode to be used + */ +void FileHelper::SetLoadMode(int loadMode) +{ + GetFile()->SetLoadMode( loadMode ); +} +/** + * \brief Sets the LoadMode of the internal gdcm::File + * @param fileName name of the file to be open + */ +void FileHelper::SetFileName(std::string const &fileName) +{ + FileInternal->SetFileName( fileName ); +} + +/** + * \brief Loader + * @return false if file cannot be open or no swap info was found, + * or no tag was found. + */ +bool FileHelper::Load() +{ + if ( !FileInternal->Load() ) + return false; + + PixelReadConverter->GrabInformationsFromFile( FileInternal ); + return true; +} + /** * \brief Accesses an existing DocEntry (i.e. a Dicom Element) * through it's (group, element) and modifies it's content with @@ -352,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 @@ -409,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 @@ -1174,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 @@ -1472,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 ); - } } /** @@ -1493,6 +1559,8 @@ void FileHelper::Initialize() */ uint8_t *FileHelper::GetRaw() { + PixelReadConverter->SetUserFunction( UserFunction ); + uint8_t *raw = PixelReadConverter->GetRaw(); if ( ! raw ) { @@ -1523,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); + } } //-----------------------------------------------------------------------------