From 74086a8e40bb4708487be0025cd48197dbfbb163 Mon Sep 17 00:00:00 2001 From: jpr Date: Wed, 12 Sep 2007 10:49:15 +0000 Subject: [PATCH] Remove old stuff --- Example/exOverlaysACR.cxx | 305 -------------------------------------- Example/exOverlaysDCM.cxx | 211 -------------------------- 2 files changed, 516 deletions(-) delete mode 100644 Example/exOverlaysACR.cxx delete mode 100755 Example/exOverlaysDCM.cxx diff --git a/Example/exOverlaysACR.cxx b/Example/exOverlaysACR.cxx deleted file mode 100644 index 8ede8c90..00000000 --- a/Example/exOverlaysACR.cxx +++ /dev/null @@ -1,305 +0,0 @@ -/*========================================================================= - - Program: gdcm - Module: $RCSfile: exOverlaysACR.cxx,v $ - Language: C++ - Date: $Date: 2007/05/23 14:18:05 $ - Version: $Revision: 1.11 $ - - Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de - l'Image). All rights reserved. See Doc/License.txt or - http://www.creatis.insa-lyon.fr/Public/Gdcm/License.html for details. - - This software is distributed WITHOUT ANY WARRANTY; without even - the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR - PURPOSE. See the above copyright notices for more information. - -=========================================================================*/ -#include "gdcmFile.h" -#include "gdcmFileHelper.h" -#include "gdcmCommon.h" -#include "gdcmDebug.h" -#include "gdcmDocEntry.h" - -#include -#include // for fseek... FIXME -#include // for atoi - - // WARNING : - // unfinished : DO NOT to be used as is ! - - /* - // 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) - -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) -... -... -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) - */ - -int main(int argc, char *argv[]) -{ - GDCM_NAME_SPACE::File *f; - - //GDCM_NAME_SPACE::Debug::DebugOn(); - - std::cout << "------------------------------------------------" << std::endl; - std::cout << "Gets the 'Overlays' from a full gdcm-readable ACR-NEMA " - << "uncompressed image" << std::endl; - std::cout << "Writes them in DicomV3 files named 'gdcmOverlay-xxx.dcm'" - << std::endl; - std::cout << "(Note : we just have ONE image : " - << "SIEMENS_GBS_III-16-ACR_NEMA_1.acr)" - << std::endl; - std::cout << "------------------------------------------------" << std::endl; - - std::string fileName; - if( argc > 1 ) - fileName = argv[1]; - else - fileName = "SIEMENS_GBS_III-16-ACR_NEMA_1.acr"; - - std::cout << fileName << std::endl; -// ============================================================ -// 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" - <Delete(); - return 0; - } - std::cout << " ... is readable " << std::endl; - -// ============================================================ -// Check whether image contains Overlays ACR-NEMA style. -// ============================================================ - - int bitsAllocated = f->GetBitsAllocated(); - if ( bitsAllocated <= 8 ) - { - std::cout << " 8 bits pixel image cannot contain Overlays " << std::endl; - f->Delete(); - return 0; - } - std::string s1 = f->GetEntryString(0x6000, 0x0102); - if (s1 == GDCM_NAME_SPACE::GDCM_UNFOUND) - { - std::cout << " Image doesn't contain any Overlay " << std::endl; - f->Delete(); - return 0; - } - std::cout << " File is read! " << std::endl; - - -// ============================================================ -// Load the pixels in memory. -// ============================================================ - - // We don't use a GDCM_NAME_SPACE::FileHelper, since it rubs out - // the 'non image' bits of the pixels... - - /// \todo : Previous remark doesn't work if pixels are compressed ! - - int nx = f->GetXSize(); - int ny = f->GetYSize(); - - std::cout << "Dimensions " << ny << " " <GetDocEntry(f->GetGrPixel(), f->GetNumPixel()); - if (p == 0) - std::cout << "Pixels element not found" << std::endl; - else - std::cout << "Pixels element FOUND" << std::endl; - - int offset = (int)(p->GetOffset()); - - std::cout << "Offset " << offset << std::endl; - - FILE *fp = fopen(fileName.c_str(), "r"); - - if (fp == 0) - { - std::cout << "Unable to open File" << std::endl; - f->Delete(); - return 0; - } - else - std::cout << "File open successfully" << std::endl; - - fseek(fp, (long) offset,SEEK_SET); - uint16_t *pixels = new uint16_t[nx*ny]; - size_t lgt = fread(pixels, 1, nx*ny*sizeof( uint16_t) , fp ); - - if ( lgt != (size_t)nx*ny*sizeof( uint16_t) ) - { - std::cout << "Sorry, Pixels of" << fileName << " are not " - << "readable. expected length :" << nx*ny - << " " << "read length : " << lgt - << std::endl; - f->Delete(); - delete pixels; - return 0; - } - else - { - std::cout << "Pixels read as expected : length = " << lgt << std::endl; - } - - -// ============================================================ -// Get each overlay Bit into an image -// ============================================================ - - uint8_t *tabPixels = new uint8_t[nx*ny]; // uint8 is enought to hold 1 bit ! - - uint16_t currentOvlGroup = 0x6000; - 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; - - - while ( (strOvlBitPosition = f->GetEntryString(currentOvlGroup, 0x0102)) - != GDCM_NAME_SPACE::GDCM_UNFOUND ) - { - - strOverlayLocation = f->GetEntryString(currentOvlGroup, 0x0200); - if ( strOverlayLocation != GDCM_NAME_SPACE::GDCM_UNFOUND ) - { - overlayLocation = atoi(strOverlayLocation.c_str()); - if ( overlayLocation != f->GetGrPixel() ) - { - std::cout << "Big Trouble : Overlays are NOT in the Pixels Group " - << std::hex << "(" << overlayLocation << " vs " - << f->GetGrPixel() << std::endl; - // Actually, here, we should (try to) read the overlay location - // and go on the job. - continue; - } - } - ovlBitPosition = atoi(strOvlBitPosition.c_str()); - mask = 1 << ovlBitPosition; - 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; - else - tabPixels[j] = 128; - } - if( GDCM_NAME_SPACE::Debug::GetDebugFlag() ) - std::cout << "About to built empty file" << std::endl; - - 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 - str.str(""); - str << ny; - fileToBuild->InsertEntryString(str.str(),0x0028,0x0010); // 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("MONOCHROME2 ",0x0028,0x0004); - // 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->SetWriteTypeToDcmExplVR(); - - str.str(""); - str<<"gdcmOverlay-"<Write(str.str()) ) - { - std::cout << "Failed\n" - << "File in unwrittable\n"; - fh->Delete(); - if (fileToBuild) - fileToBuild->Delete(); - delete pixels; - delete tabPixels; - return 0; - } - else - { - std::cout << "File written successfully" << std::endl; - } - currentOvlGroup += 2; - i++; - } - - if (f) - fh->Delete(); - if (fileToBuild) - fileToBuild->Delete(); - f->Delete(); - delete pixels; - delete tabPixels; - - return 0; -} - diff --git a/Example/exOverlaysDCM.cxx b/Example/exOverlaysDCM.cxx deleted file mode 100755 index 14d31cc9..00000000 --- a/Example/exOverlaysDCM.cxx +++ /dev/null @@ -1,211 +0,0 @@ -/*========================================================================= - - Program: gdcm - Module: $RCSfile: exOverlaysDCM.cxx,v $ - Language: C++ - Date: $Date: 2007/09/04 13:04:18 $ - Version: $Revision: 1.11 $ - - Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de - l'Image). All rights reserved. See Doc/License.txt or - http://www.creatis.insa-lyon.fr/Public/Gdcm/License.html for details. - - This software is distributed WITHOUT ANY WARRANTY; without even - the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR - 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 "gdcmArgMgr.h" -#include - -// Each BIT of Overlay Data (0x6000,0x3000) corresponds -// to a BYTE of overlay image. -void explodeByte(unsigned char byte, unsigned char* result) -{ - unsigned char mask = 1; - for (int i=0;i<8;i++) - { - if ((byte & mask)==0) - result[i]=0; - else - result[i]=1; - mask<<=1; - } - return; -} - - -int main(int argc, char *argv[]) -{ - START_USAGE(usage) - " \n exOverlaysDCM :\n ", - " Extract an overlay image from a DICOM image ", - " Warning : probably segfaults if no overlay ", - " usage: exOverlaysDCM filein=inputFileName fileout=outputFileName [debug] ", - " debug : developper wants to run the program in 'debug mode' ", - FINISH_USAGE - - // ----- Initialize Arguments Manager ------ - GDCM_NAME_SPACE::ArgMgr *am = new GDCM_NAME_SPACE::ArgMgr(argc, argv); - - if (argc == 1 || am->ArgMgrDefined("usage")) - { - am->ArgMgrUsage(usage); // Display 'usage' - delete am; - return 0; - } - -/* - char *fileName = am->ArgMgrWantString("filein",usage); - if ( fileName == NULL ) - { - delete am; - return 0; - } -*/ - - - const char *fileName = am->ArgMgrGetString("filein"); - const char *dirName = am->ArgMgrGetString("dirin"); - - if ( (fileName == 0 && dirName == 0) || - (fileName != 0 && dirName != 0) ) - { - std::cerr << std::endl - << "Either 'filein=' or 'dirin=' must be present;" - << std::endl << "Not both" << std::endl; - am->ArgMgrUsage(usage); // Display 'usage' - delete am; - return 1; - } - - - char *outputFileName = am->ArgMgrWantString("fileout",usage); - if ( outputFileName == NULL ) - { - delete am; - return 0; - } - if (am->ArgMgrDefined("debug")) - GDCM_NAME_SPACE::Debug::DebugOn(); - - if (am->ArgMgrDefined("warning")) - GDCM_NAME_SPACE::Debug::WarningOn(); - - // if unused Param we give up - if ( am->ArgMgrPrintUnusedLabels() ) - { - am->ArgMgrUsage(usage); - delete am; - return 0; - } - - delete am; // we don't need Argument Manager any longer - - // ============================================================ - // Read the input file. - // ============================================================ - - GDCM_NAME_SPACE::File *f; - - f = GDCM_NAME_SPACE::File::New( ); - f->SetLoadMode( GDCM_NAME_SPACE::LD_ALL ); - f->SetFileName( fileName ); - f->AddForceLoadElement(0x6000,0x3000); // Overlay Data - int res = f->Load(); - - if ( !res ) - { - std::cerr << "Sorry, " << fileName <<" not a gdcm-readable " - << "DICOM / ACR File" <Delete(); - return 0; - } - std::cout << " ... is readable " << std::endl; - - // ============================================================ - // Load the Overlays in memory (the first one) - // ============================================================ - - GDCM_NAME_SPACE::DataEntry *e = f->GetDataEntry(0x6000, 0x3000); - if (e == 0) - { - std::cout << " Image doesn't contain any Overlay " << std::endl; - f->Delete(); - return 0; - } - std::cout << " File is read! " << std::endl; - - uint8_t *overlay = (uint8_t *)(e->GetBinArea()); - if ( overlay == 0 ) - { - std::cerr << "Sorry, Overlays of" << fileName <<" are not " - << " gdcm-readable." << std::endl; - f->Delete(); - return 0; - } - - // ============================================================ - // Image data generation. - // ============================================================ - - - unsigned int dimX= f->GetXSize(); - unsigned int dimY= f->GetYSize(); - - unsigned int dimXY=dimX*dimY; - std::cout << "DimX : "<< dimX <<" DimY : " << dimY - << " DimXY : " <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. - // ... - GDCM_NAME_SPACE::FileHelper *fh = GDCM_NAME_SPACE::FileHelper::New(f2); - - fh->SetImageData(outputData,dimXY); - fh->WriteDcmExplVR(outputFileName); - std::cout <<"End WriteOverlayImage" << std::endl; - - delete outputData; - f->Delete(); - f2->Delete(); - fh->Delete(); - - return 0; -} - -- 2.45.0