From 019e0490da94a39fb0934ad94f5b8825f7537144 Mon Sep 17 00:00:00 2001 From: jpr Date: Fri, 14 Sep 2007 08:23:34 +0000 Subject: [PATCH] Unify exExtractOverlaysACR an exExtractOverlaysDCM codes --- Example/ReWrite.cxx | 74 ++++---- Example/exExtractOverlaysACR.cxx | 190 +++++++++------------ Example/exExtractOverlaysDCM.cxx | 281 ++++++++++++++----------------- 3 files changed, 249 insertions(+), 296 deletions(-) diff --git a/Example/ReWrite.cxx b/Example/ReWrite.cxx index 48de526d..ebf50a24 100644 --- a/Example/ReWrite.cxx +++ b/Example/ReWrite.cxx @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: ReWrite.cxx,v $ Language: C++ - Date: $Date: 2007/09/04 13:06:12 $ - Version: $Revision: 1.32 $ + Date: $Date: 2007/09/14 08:23:34 $ + Version: $Revision: 1.33 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -315,43 +315,43 @@ int main(int argc, char *argv[]) case 'R' : case 'r' : - // Writting a Raw File, + // Writting a Raw File, std::cout << "WriteRaw" << std::endl; fh->WriteRawData(outputFileName); break; case 'J' : case 'j' : - // writting a DICOM Jpeg Lossless + // writting a DICOM Jpeg Lossless // from a full gdcm readable File std::cout << "WriteDCM Jpeg Lossless" << std::endl; fh->SetWriteTypeToJPEG(); break; case '2' : - // writting a DICOM Jpeg 2000 + // writting a DICOM Jpeg 2000 // from a full gdcm readable File std::cout << "WriteDCM Jpeg 2000" << std::endl; fh->SetWriteTypeToJPEG2000(); - break; - + break; + // Just for fun : // Write a 'Video inverse' version of the file. - // *Not* described, on purpose, in the USAGE + // *Not* described, on purpose, in the USAGE case 'V' : case 'v' : if ( fh->GetFile()->GetBitsAllocated() == 8) { std::cout << "videoinv for 8 bits" << std::endl; - for (int i=0; i this is no longer really 'ReWrite' !) int subImDimX = nX; - int subImDimY = nY; + int subImDimY = nY; if (roi) - { + { if (roiBoundVal[0]<0 || roiBoundVal[0]>=nX) { std::cout << "xBegin out of bounds; 'roi' ignored" << std::endl; @@ -385,27 +384,27 @@ int main(int argc, char *argv[]) if (roiBoundVal[0] > roiBoundVal[1]) { std::cout << "xBegin greater than xEnd; 'roi' ignored" << std::endl; - fail = true; + fail = true; } if (roiBoundVal[2]<0 || roiBoundVal[2]>=nY) - { + { std::cout << "yBegin out of bounds; 'roi' ignored" << std::endl; - fail = true; + fail = true; } if (roiBoundVal[3]<0 || roiBoundVal[3]>=nY) - { + { std::cout << "yEnd out of bounds; 'roi' ignored" << std::endl; - fail = true; + fail = true; } if (roiBoundVal[2] > roiBoundVal[3]) - { + { std::cout << "yBegin greater than yEnd; 'roi' ignored" << std::endl; - fail = true; - } - } + fail = true; + } + } else - { + { roiBoundVal = new int[4]; roiBoundVal[0] = 0; roiBoundVal[1] = nX-1; @@ -413,32 +412,32 @@ int main(int argc, char *argv[]) roiBoundVal[3] = nY-1; } - subImDimX = roiBoundVal[1]-roiBoundVal[0]+1; - subImDimY = roiBoundVal[3]-roiBoundVal[2]+1; - + subImDimX = roiBoundVal[1]-roiBoundVal[0]+1; + subImDimY = roiBoundVal[3]-roiBoundVal[2]+1; + if (roi || beg != -1 || end != -1) - { + { if (beg == -1) beg = 0; if (end == -1) end = nZ-1; - + std::ostringstream str; - + // Set the data that will be *actually* written. int pixelSize = fh->GetFile()->GetPixelSize(); size_t lgrSubLine = subImDimX* pixelSize * numberOfScalarComponents; size_t lgrSubFrame = subImDimY*lgrSubLine; - ; + int lgrSubImage = (end-beg+1) * lgrSubFrame; - + uint8_t * subImage = new uint8_t[lgrSubImage]; - + uint8_t * srcCopy = (uint8_t *) imageData; uint8_t * destCopy = subImage; int lineSize = nX*pixelSize*numberOfScalarComponents; - int frameSize = nY*lineSize; + int frameSize = nY*lineSize; int lineOffset = roiBoundVal[0]*pixelSize * numberOfScalarComponents; @@ -450,7 +449,7 @@ int main(int argc, char *argv[]) memcpy( (void *)(destCopy + frameCount*lgrSubFrame + lineCount*lgrSubLine), (void *)(srcCopy + frameNb*frameSize + lineNb*lineSize + lineOffset ), lgrSubLine); - } + } } // Set the image size @@ -478,7 +477,10 @@ int main(int argc, char *argv[]) //----------------------------------- Write, now! --------------------------------- if (mode[0] != 'R' && mode[0] != 'r') - fh->Write(outputFileName); + res = fh->Write(outputFileName); + + if(!res) + std::cout <<"Fail to write [" << outputFileName << "]" <Delete(); fh->Delete(); diff --git a/Example/exExtractOverlaysACR.cxx b/Example/exExtractOverlaysACR.cxx index c992b01a..72f478f9 100644 --- a/Example/exExtractOverlaysACR.cxx +++ b/Example/exExtractOverlaysACR.cxx @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: exExtractOverlaysACR.cxx,v $ Language: C++ - Date: $Date: 2007/09/12 10:43:47 $ - Version: $Revision: 1.1 $ + Date: $Date: 2007/09/14 08:23:34 $ + Version: $Revision: 1.2 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -20,50 +20,47 @@ #include "gdcmCommon.h" #include "gdcmDebug.h" #include "gdcmDocEntry.h" +#include "gdcmArgMgr.h" + #include -#include // for fseek... FIXME #include // for atoi -#include "gdcmArgMgr.h" - - // WARNING : - // unfinished : DO NOT to be used as is ! + /* SIEMENS_GBS_III-16-ACR_NEMA_1.acr - /* // Example (sorry, we've got no more than this one ...) -V 0028|0010[US] [Rows] [256] x(100) -V 0028|0011[US] [Columns] [256] x(100) -V 0028|0030[DS] [Pixel Spacing] [01.56\1.56] -V 0028|0100[US] [Bits Allocated] [16] x(10) -V 0028|0101[US] [Bits Stored] [12] x(c) -V 0028|0102[US] [High Bit] [11] x(b) -V 0028|0103[US] [Pixel Representation] [0] x(0) +0028|0010[US] [Rows] [256] x(100) +0028|0011[US] [Columns] [256] x(100) +0028|0030[DS] [Pixel Spacing] [01.56\1.56] +0028|0100[US] [Bits Allocated] [16] x(10) +0028|0101[US] [Bits Stored] [12] x(c) +0028|0102[US] [High Bit] [11] x(b) +0028|0103[US] [Pixel Representation] [0] x(0) -V 6000|0000[UL] [Group Length] [96] x(60) -V 6000|0010[US] [Rows] [256] x(100) -V 6000|0011[US] [Columns] [256] x(100) -V 6000|0040[CS] [Overlay Type] [R ] -V 6000|0050[SS] [Overlay Origin] [23601\8241] x(5c31) -V 6000|0100[US] [Overlay Bits Allocated] [16] x(10) -V 6000|0102[US] [Overlay Bit Position] [12] x(c) +6000|0000[UL] [Group Length] [96] x(60) +6000|0010[US] [Rows] [256] x(100) +6000|0011[US] [Columns] [256] x(100) +6000|0040[CS] [Overlay Type] [R ] +6000|0050[SS] [Overlay Origin] [23601\8241] x(5c31) +6000|0100[US] [Overlay Bits Allocated] [16] x(10) +6000|0102[US] [Overlay Bit Position] [12] x(c) ... ... -V 6006|0000[UL] [Group Length] [96] x(60) -V 6006|0010[US] [Rows] [256] x(100) -V 6006|0011[US] [Columns] [256] x(100) -V 6006|0040[CS] [Overlay Type] [R ] -V 6006|0050[SS] [Overlay Origin] [23601\8241] x(5c31) -V 6006|0100[US] [Overlay Bits Allocated] [16] x(10) -V 6006|0102[US] [Overlay Bit Position] [15] x(f) +6006|0000[UL] [Group Length] [96] x(60) +6006|0010[US] [Rows] [256] x(100) +6006|0011[US] [Columns] [256] x(100) +6006|0040[CS] [Overlay Type] [R ] +6006|0050[SS] [Overlay Origin] [23601\8241] x(5c31) +6006|0100[US] [Overlay Bits Allocated] [16] x(10) +6006|0102[US] [Overlay Bit Position] [15] x(f) */ int main(int argc, char *argv[]) -{ +{ START_USAGE(usage) " \n exExtractOverlaysACR :\n ", " Extract ACR-NEMA style overlays from an image ", - " usage: exExtractOverlaysACR filein=inputDirectoryName [debug] ", + " usage: exExtractOverlaysACR filein=inputFileName [debug] ", " debug : developper wants to run the program in 'debug mode' ", FINISH_USAGE @@ -77,10 +74,8 @@ int main(int argc, char *argv[]) delete am; return 0; } - - // "SIEMENS_GBS_III-16-ACR_NEMA_1.acr" - - const char *fileName = am->ArgMgrWantString("filein", usage); + + const char *fileName = am->ArgMgrWantString("filein", usage); if (am->ArgMgrDefined("debug")) GDCM_NAME_SPACE::Debug::DebugOn(); @@ -98,30 +93,21 @@ int main(int argc, char *argv[]) delete am; // we don't need Argument Manager any longer + // ========================== Now, we can do the job! ================ - // ========================== Now, we can do the job! ================ - GDCM_NAME_SPACE::File *f; - // ============================================================ // Read the input image. // ============================================================ - //std::cout << argv[1] << std::endl; - f = GDCM_NAME_SPACE::File::New( ); f->SetLoadMode(GDCM_NAME_SPACE::LD_NOSEQ | GDCM_NAME_SPACE::LD_NOSHADOW); f->SetFileName( fileName ); bool res = f->Load(); - if( GDCM_NAME_SPACE::Debug::GetDebugFlag() ) - { - std::cout << "---------------------------------------------" << std::endl; - f->Print(); - std::cout << "---------------------------------------------" << std::endl; - } + if (!res) { std::cout << "Sorry, " << fileName <<" not a gdcm-readable " << "DICOM / ACR File" @@ -129,7 +115,7 @@ int main(int argc, char *argv[]) f->Delete(); return 0; } - std::cout << " ... is readable " << std::endl; + std::cout << fileName << " ... is readable " << std::endl; // ============================================================ // Check whether image contains Overlays ACR-NEMA style. @@ -149,56 +135,57 @@ int main(int argc, char *argv[]) f->Delete(); return 0; } - std::cout << " File is read! " << std::endl; + std::cout << fileName << " is read! " << std::endl; // ============================================================ // Load the pixels in memory. // ============================================================ - int nx = f->GetXSize(); - int ny = f->GetYSize(); - GDCM_NAME_SPACE::FileHelper *fh1 = GDCM_NAME_SPACE::FileHelper::New(f); fh1->SetKeepOverlays(true); uint16_t *pixels = (uint16_t *)fh1->GetImageDataRaw(); int lgt = fh1->GetImageDataRawSize(); - + if( GDCM_NAME_SPACE::Debug::GetDebugFlag() ) - std::cout << "Pixels read as expected : length = " << lgt << std::endl; - + std::cout << "Pixels read as expected : length = " << lgt << std::endl; + // ============================================================ // Prepare the stuff // ============================================================ - - uint8_t *tabPixels = new uint8_t[nx*ny]; // uint8 is enought to hold 1 bit ! - - uint16_t currentOvlGroup = 0x6000; + + unsigned int nx = f->GetXSize(); + unsigned int ny = f->GetYSize(); + unsigned int nxy=nx*ny; + uint16_t currentOvlGroup; + int i; + + std::ostringstream str; + + uint8_t *outputData = new uint8_t[nxy]; // uint8 is enought to hold 1 bit ! + std::string strOvlBitPosition; int ovlBitPosition; uint16_t mask; - int i = 0; uint16_t overlayLocation; - std::ostringstream str; - std::string strOverlayLocation; - + GDCM_NAME_SPACE::File *fileToBuild = 0; GDCM_NAME_SPACE::FileHelper *fh = 0; // ============================================================ -// Get each overlay Bit into an image +// Get each overlay Bit into the image // ============================================================ - for(i=0, currentOvlGroup=0x6000; i<32; i+=2 ,currentOvlGroup+=2) + for(i=0, currentOvlGroup=0x6000; i<32; i+=2 ,currentOvlGroup+=2) { if ( (strOvlBitPosition = f->GetEntryString(currentOvlGroup, 0x0102)) == GDCM_NAME_SPACE::GDCM_UNFOUND ) continue; - - if( GDCM_NAME_SPACE::Debug::GetDebugFlag() ) - std::cout << "Current Overlay Group " << std::hex << currentOvlGroup + + if( GDCM_NAME_SPACE::Debug::GetWarningFlag() ) + std::cout << "Current Overlay Group " << std::hex << currentOvlGroup << " OvlBitPosition " << strOvlBitPosition << std::endl; - + strOverlayLocation = f->GetEntryString(currentOvlGroup, 0x0200); if ( strOverlayLocation != GDCM_NAME_SPACE::GDCM_UNFOUND ) { @@ -213,56 +200,54 @@ int main(int argc, char *argv[]) continue; } } + + // ============================================================ + // DICOM Overlay Image data generation + // ============================================================ + ovlBitPosition = atoi(strOvlBitPosition.c_str()); mask = 1 << ovlBitPosition; - - if( GDCM_NAME_SPACE::Debug::GetDebugFlag() ) - std::cout << "Mask :[" <= 0x1000)// if it contains at least one overlay bit printf("%d : %04x\n",j, pixels[j]); if ( (pixels[j] & mask) == 0 ) - tabPixels[j] = 0; + outputData[j] = 0; else - tabPixels[j] = 128; + outputData[j] = 128; } - if( GDCM_NAME_SPACE::Debug::GetDebugFlag() ) - std::cout << "About to built empty file" << std::endl; + // ============================================================ + // Write a new file + // ============================================================ fileToBuild = GDCM_NAME_SPACE::File::New(); - - if( GDCM_NAME_SPACE::Debug::GetDebugFlag() ) - std::cout << "Finish to built empty file" << std::endl; - str.str(""); str << nx; - fileToBuild->InsertEntryString(str.str(),0x0028,0x0011); // Columns + fileToBuild->InsertEntryString(str.str(),0x0028,0x0011, "US"); // Columns str.str(""); str << ny; - fileToBuild->InsertEntryString(str.str(),0x0028,0x0010); // Rows + fileToBuild->InsertEntryString(str.str(),0x0028,0x0010, "US"); // Rows - fileToBuild->InsertEntryString("8",0x0028,0x0100); // Bits Allocated - fileToBuild->InsertEntryString("8",0x0028,0x0101); // Bits Stored - fileToBuild->InsertEntryString("7",0x0028,0x0102); // High Bit - fileToBuild->InsertEntryString("0",0x0028,0x0103); // Pixel Representation - fileToBuild->InsertEntryString("1",0x0028,0x0002); // Samples per Pixel + fileToBuild->InsertEntryString("8",0x0028,0x0100, "US"); // Bits Allocated + fileToBuild->InsertEntryString("8",0x0028,0x0101, "US"); // Bits Stored + fileToBuild->InsertEntryString("7",0x0028,0x0102, "US"); // High Bit + fileToBuild->InsertEntryString("0",0x0028,0x0103, "US"); // Pixel Representation + fileToBuild->InsertEntryString("1",0x0028,0x0002, "US"); // Samples per Pixel + fileToBuild->InsertEntryString("MONOCHROME2 ",0x0028,0x0004, "LO"); - fileToBuild->InsertEntryString("MONOCHROME2 ",0x0028,0x0004); + // feel free to add any field (Dicom Data Entry) you like, here. + // ... // Other mandatory fields will be set automatically, // just before Write(), by FileHelper::CheckMandatoryElements() - if( GDCM_NAME_SPACE::Debug::GetDebugFlag() ) - std::cout << "-------------About to built FileHelper" << std::endl; - fh = GDCM_NAME_SPACE::FileHelper::New(fileToBuild); - if( GDCM_NAME_SPACE::Debug::GetDebugFlag() ) - std::cout << "-------------Finish to built FileHelper" << std::endl; - - fh->SetImageData(tabPixels,nx*ny); + fh->SetImageData(outputData,nx*ny); fh->SetWriteTypeToDcmExplVR(); std::ostringstream tmp; @@ -281,28 +266,21 @@ str << fileName << ".ovly." << tmp.str() << ".dcm" << std::ends; { std::cout << "Failed\n" << "File [" << str.str() << "] is unwrittable" << std::endl; - /* - fh->Delete(); - if (fileToBuild) - fileToBuild->Delete(); - delete pixels; - delete tabPixels; - return 0; - */ } else { std::cout << "File written successfully [" << str.str() << "]" << std::endl; } - } - + + } // end on loop on 60xx + if (f) fh->Delete(); if (fileToBuild) fileToBuild->Delete(); f->Delete(); delete pixels; - delete tabPixels; + delete outputData; return 0; } diff --git a/Example/exExtractOverlaysDCM.cxx b/Example/exExtractOverlaysDCM.cxx index 6e10dbcf..b9082011 100755 --- a/Example/exExtractOverlaysDCM.cxx +++ b/Example/exExtractOverlaysDCM.cxx @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: exExtractOverlaysDCM.cxx,v $ Language: C++ - Date: $Date: 2007/09/12 10:43:47 $ - Version: $Revision: 1.1 $ + Date: $Date: 2007/09/14 08:23:34 $ + Version: $Revision: 1.2 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -15,16 +15,14 @@ PURPOSE. See the above copyright notices for more information. =========================================================================*/ - - #include "gdcmFile.h" #include "gdcmFileHelper.h" #include "gdcmCommon.h" #include "gdcmDebug.h" #include "gdcmDataEntry.h" #include "gdcmDirList.h" - #include "gdcmArgMgr.h" + #include // Each BIT of Overlay Data (0x6000,0x3000) corresponds @@ -43,14 +41,12 @@ void explodeByte(unsigned char byte, unsigned char* result) return; } - int main(int argc, char *argv[]) { START_USAGE(usage) " \n ExtractOverlays :\n ", - " Extract overlay images from all DICOM image within a directory ", - " Warning : probably segfaults if no overlay ", - " usage: ExtractOverlays dirin=inputDirectoryName [debug] ", + " Extract DICOM style overlays from an image ", + " usage: exExtractOverlaysDCM filein=inputFileName [debug] ", " debug : developper wants to run the program in 'debug mode' ", FINISH_USAGE @@ -64,8 +60,8 @@ int main(int argc, char *argv[]) delete am; return 0; } - - const char *dirIn = am->ArgMgrWantString("dirin", usage); + + const char *fileName = am->ArgMgrWantString("filein", usage); if (am->ArgMgrDefined("debug")) GDCM_NAME_SPACE::Debug::DebugOn(); @@ -83,41 +79,15 @@ int main(int argc, char *argv[]) delete am; // we don't need Argument Manager any longer - // ========================== Now, we can do the job! ================ - - // ======================== more checking on the params ============== - - if ( ! GDCM_NAME_SPACE::DirList::IsDirectory(dirIn) ) - { - std::cout << "KO : [" << dirIn << "] is not a Directory." << std::endl; - return 0; - - } - - char outputFileName[1024]; // Hope it's enough for a file name! - GDCM_NAME_SPACE::File *f; - - GDCM_NAME_SPACE::DirList dirList(dirIn,true); // gets (recursively) the file list - GDCM_NAME_SPACE::DirListType fileList = dirList.GetFilenames(); - for( GDCM_NAME_SPACE::DirListType::iterator it = fileList.begin(); - it != fileList.end(); - ++it ) - { - // Just to see *all* the file names: - // std::cout << "file [" << it->c_str() << "]" << std::endl; - - // Read the input file. - - if( GDCM_NAME_SPACE::Debug::GetWarningFlag() ) - std::cerr << "Deal with [" << it->c_str() - << "] File" <SetLoadMode( GDCM_NAME_SPACE::LD_ALL ); - f->SetFileName( it->c_str() ); +// ============================================================ +// Read the input image. +// ============================================================ + + f = GDCM_NAME_SPACE::File::New( ); f->AddForceLoadElement(0x6000,0x3000); // Overlay Data f->AddForceLoadElement(0x6002,0x3000); @@ -135,139 +105,142 @@ int main(int argc, char *argv[]) f->AddForceLoadElement(0x601a,0x3000); f->AddForceLoadElement(0x601c,0x3000); f->AddForceLoadElement(0x601e,0x3000); // Hope it's enought : Dicom says 60xx ... - - int res = f->Load(); - if ( !res ) - { - std::cerr << "Sorry, " << it->c_str() <<" not a gdcm-readable " - << "DICOM / ACR File" <Delete(); - continue; + f->SetLoadMode(GDCM_NAME_SPACE::LD_NOSEQ | GDCM_NAME_SPACE::LD_NOSHADOW); + f->SetFileName( fileName ); + bool res = f->Load(); + + if (!res) { + std::cout << "Sorry, " << fileName <<" not a gdcm-readable " + << "DICOM / ACR File" + <Delete(); + return 0; } + std::cout << fileName << " ... is readable " << std::endl; - if( GDCM_NAME_SPACE::Debug::GetWarningFlag() ) - std::cout << " ... is readable " << std::endl; +// ============================================================ +// Check whether image contains Overlays DICOM style. +// ============================================================ - // ============================================================ - // Load Overlay info in memory - // ============================================================ + unsigned int nx = f->GetXSize(); + unsigned int ny = f->GetYSize(); + unsigned int nxy=nx*ny; + uint16_t currentOvlGroup; + int i; -/// \todo : deal with *each* overlay Data Element (not only the first one!) + std::ostringstream str; - uint16_t ovlyGroup = 0x6000; - - for (int k=0; k<32; k+=2) - { - - GDCM_NAME_SPACE::DataEntry *e10 = f->GetDataEntry(ovlyGroup+k, 0x0010); // nb Row Ovly - if (e10 == 0) - { - if( GDCM_NAME_SPACE::Debug::GetWarningFlag() ) - std::cout << " Image doesn't contain Overlay on " <GetXSize(); - unsigned int dimY= f->GetYSize(); - unsigned int dimXY=dimX*dimY; + GDCM_NAME_SPACE::File *fileToBuild = 0; + GDCM_NAME_SPACE::FileHelper *fh = 0; - unsigned char *outputData = new unsigned char[dimXY]; - - - GDCM_NAME_SPACE::DataEntry *e = f->GetDataEntry(ovlyGroup+k, 0x3000); - if (e == 0) +// ============================================================ +// Get each overlay +// ============================================================ + for(i=0, currentOvlGroup=0x6000; i<32; i+=2 ,currentOvlGroup+=2) { - if( GDCM_NAME_SPACE::Debug::GetWarningFlag() ) - std::cout << " Image doesn't contain DICOM Overlay Data " <GetImageDataRaw(); - - if (pixelData == 0) + GDCM_NAME_SPACE::DataEntry *e10 = f->GetDataEntry(currentOvlGroup, 0x0010); // nb Row Ovly + if (e10 == 0) { - std::cerr << "Sorry, Pixel Data of [" << it->c_str() <<"] are not " - << " gdcm-readable." << std::endl; - continue; - } - - } - else - { - uint8_t *overlay = (uint8_t *)(e->GetBinArea()); - if ( overlay == 0 ) + if( GDCM_NAME_SPACE::Debug::GetWarningFlag() ) + std::cout << " Image doesn't contain Overlay on " <GetDataEntry(currentOvlGroup, 0x3000); + if (e == 0) { - std::cerr << "Sorry, Overlays of [" << it->c_str() <<"] are not " - << " gdcm-readable." << std::endl; - continue; + if( GDCM_NAME_SPACE::Debug::GetWarningFlag() ) + std::cout << " Image doesn't contain DICOM Overlay Data " <GetBinArea()); + if ( overlay == 0 ) + { + std::cerr << "Sorry, Overlays of [" << fileName << "] are not " + << " gdcm-readable." << std::endl; + continue; + } + if( GDCM_NAME_SPACE::Debug::GetWarningFlag() ) + std::cout << " Overlay on group [" << std::hex << currentOvlGroup<< "] is read! " << std::endl; + // ============================================================ // DICOM Overlay Image data generation - // ============================================================ - + // ============================================================ - unsigned char *result=outputData; - for (unsigned int i=0;i<(dimXY/8);i++) - { - explodeByte(overlay[i], result); - result+=8; + unsigned char *result=outputData; + for (unsigned int i=0;i<(nxy/8);i++) + { + explodeByte(overlay[i], result); + result+=8; + } } - } // ============================================================ // Write a new file // ============================================================ - - GDCM_NAME_SPACE::File *f2; - f2 = GDCM_NAME_SPACE::File::New( ); - GDCM_NAME_SPACE::FileHelper *fh2 = GDCM_NAME_SPACE::FileHelper::New(f2); - - char temp[256]; - - sprintf(temp,"%d ",dimX); - f2->InsertEntryString(temp,0x0028,0x0011, "US"); // Columns - sprintf(temp,"%d ",dimY); - f2->InsertEntryString(temp,0x0028,0x0010, "US"); // Rows - f2->InsertEntryString("8",0x0028,0x0100, "US"); // Bits Allocated - f2->InsertEntryString("8",0x0028,0x0101, "US"); // Bits Stored - f2->InsertEntryString("7",0x0028,0x0102, "US"); // High Bit - f2->InsertEntryString("0",0x0028,0x0103, "US"); // Pixel Representation - f2->InsertEntryString("1",0x0028,0x0002, "US"); // Samples per Pixel - f2->InsertEntryString("MONOCHROME2 ",0x0028,0x0004, "LO"); - - // feel free to add any field (Dicom Data Entry) you like, here. - // ... - - sprintf(outputFileName, "../%s.ovly.%04x.dcm",it->c_str(), ovlyGroup+k); - - fh2->SetImageData(outputData,dimXY); - fh2->WriteDcmExplVR(outputFileName); - - std::cout <<"File written successfully [" << outputFileName << "]" <Delete(); - fh2->Delete(); - - } // end on loop on 60xx - + + fileToBuild = GDCM_NAME_SPACE::File::New(); + str.str(""); + str << nx; + fileToBuild->InsertEntryString(str.str(),0x0028,0x0011, "US"); // Columns + str.str(""); + str << ny; + fileToBuild->InsertEntryString(str.str(),0x0028,0x0010, "US"); // Rows + + fileToBuild->InsertEntryString("8",0x0028,0x0100, "US"); // Bits Allocated + fileToBuild->InsertEntryString("8",0x0028,0x0101, "US"); // Bits Stored + fileToBuild->InsertEntryString("7",0x0028,0x0102, "US"); // High Bit + fileToBuild->InsertEntryString("0",0x0028,0x0103, "US"); // Pixel Representation + fileToBuild->InsertEntryString("1",0x0028,0x0002, "US"); // Samples per Pixel + fileToBuild->InsertEntryString("MONOCHROME2 ",0x0028,0x0004, "LO"); + + // feel free to add any field (Dicom Data Entry) you like, here. + // ... + // Other mandatory fields will be set automatically, + // just before Write(), by FileHelper::CheckMandatoryElements() + + fh = GDCM_NAME_SPACE::FileHelper::New(fileToBuild); + + fh->SetImageData(outputData,nx*ny); + fh->SetWriteTypeToDcmExplVR(); + +std::ostringstream tmp; +tmp < Why doesn't it work ?!? + //str << fileName << std::hex << currentOvlGroup << ".dcm" << std::ends; + +str << fileName << ".ovly." << tmp.str() << ".dcm" << std::ends; + + // Write the current 'overlay' file + + if( !fh->Write(str.str()) ) + { + std::cout << "Failed\n" + << "File [" << str.str() << "] is unwrittable" << std::endl; + } + else + { + std::cout << "File written successfully [" << str.str() << "]" << std::endl; + } + + } // end on loop on 60xx + + if (f) + fh->Delete(); + if (fileToBuild) + fileToBuild->Delete(); f->Delete(); - -} // end of loop on files ( DirListType::iterator ) - return 0; } -- 2.45.1