Program: gdcm
Module: $RCSfile: exOverlaysACR.cxx,v $
Language: C++
- Date: $Date: 2005/05/19 15:47:20 $
- Version: $Revision: 1.3 $
+ 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
#include "gdcmDocEntry.h"
#include <iostream>
- #include <stdio.h>
+#include <stdio.h> // for fseek... FIXME
+#include <stdlib.h> // for atoi
// WARNING :
// unfinished : DO NOT to be used as is !
int main(int argc, char *argv[])
{
- gdcm::File *f1;
+ GDCM_NAME_SPACE::File *f;
- //gdcm::Debug::DebugOn();
+ //GDCM_NAME_SPACE::Debug::DebugOn();
std::cout << "------------------------------------------------" << std::endl;
std::cout << "Gets the 'Overlays' from a full gdcm-readable ACR-NEMA "
//std::cout << argv[1] << std::endl;
- f1 = new gdcm::File( );
+ f = GDCM_NAME_SPACE::File::New( );
- f1->SetLoadMode(NO_SEQ | NO_SHADOW);
- f1->Load( fileName );
+ f->SetLoadMode(GDCM_NAME_SPACE::LD_NOSEQ | GDCM_NAME_SPACE::LD_NOSHADOW);
+ f->SetFileName( fileName );
+ bool res = f->Load();
- if( gdcm::Debug::GetDebugFlag() )
+ if( GDCM_NAME_SPACE::Debug::GetDebugFlag() )
{
std::cout << "---------------------------------------------" << std::endl;
- f1->Print();
+ f->Print();
std::cout << "---------------------------------------------" << std::endl;
}
- if (!f1->IsReadable()) {
+ if (!res) {
std::cout << "Sorry, " << fileName <<" not a gdcm-readable "
<< "DICOM / ACR File"
<<std::endl;
- delete f1;
+ f->Delete();
return 0;
}
std::cout << " ... is readable " << std::endl;
// Check whether image contains Overlays ACR-NEMA style.
// ============================================================
- int bitsAllocated = f1->GetBitsAllocated();
+ int bitsAllocated = f->GetBitsAllocated();
if ( bitsAllocated <= 8 )
{
std::cout << " 8 bits pixel image cannot contain Overlays " << std::endl;
- delete f1;
+ f->Delete();
return 0;
}
- std::string s1 = f1->GetEntryValue(0x6000, 0x0102);
- if (s1 == gdcm::GDCM_UNFOUND)
+ std::string s1 = f->GetEntryString(0x6000, 0x0102);
+ if (s1 == GDCM_NAME_SPACE::GDCM_UNFOUND)
{
std::cout << " Image doesn't contain any Overlay " << std::endl;
- delete f1;
+ f->Delete();
return 0;
}
std::cout << " File is read! " << std::endl;
// Load the pixels in memory.
// ============================================================
- // We don't use a gdcm::FileHelper, since it rubs out
+ // 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 = f1->GetXSize();
- int ny = f1->GetYSize();
+ int nx = f->GetXSize();
+ int ny = f->GetYSize();
std::cout << "Dimensions " << ny << " " <<ny << std::endl;
- gdcm::DocEntry *p = f1->GetDocEntry(f1->GetGrPixel(), f1->GetNumPixel());
+ GDCM_NAME_SPACE::DocEntry *p = f->GetDocEntry(f->GetGrPixel(), f->GetNumPixel());
if (p == 0)
std::cout << "Pixels element not found" << std::endl;
else
if (fp == 0)
{
std::cout << "Unable to open File" << std::endl;
- delete f1;
+ f->Delete();
return 0;
}
else
<< "readable. expected length :" << nx*ny
<< " " << "read length : " << lgt
<< std::endl;
- delete f1;
+ f->Delete();
delete pixels;
return 0;
}
uint16_t overlayLocation;
std::ostringstream str;
std::string strOverlayLocation;
- gdcm::File *fileToBuild = 0;
- gdcm::FileHelper *fh = 0;
+ GDCM_NAME_SPACE::File *fileToBuild = 0;
+ GDCM_NAME_SPACE::FileHelper *fh = 0;
-while ( (strOvlBitPosition = f1->GetEntryValue(currentOvlGroup, 0x0102))
- != gdcm::GDCM_UNFOUND )
-{
+ while ( (strOvlBitPosition = f->GetEntryString(currentOvlGroup, 0x0102))
+ != GDCM_NAME_SPACE::GDCM_UNFOUND )
+ {
- strOverlayLocation = f1->GetEntryValue(currentOvlGroup, 0x0200);
- if ( strOverlayLocation != gdcm::GDCM_UNFOUND )
+ strOverlayLocation = f->GetEntryString(currentOvlGroup, 0x0200);
+ if ( strOverlayLocation != GDCM_NAME_SPACE::GDCM_UNFOUND )
{
overlayLocation = atoi(strOverlayLocation.c_str());
- if ( overlayLocation != f1->GetGrPixel() )
+ if ( overlayLocation != f->GetGrPixel() )
{
std::cout << "Big Trouble : Overlays are NOT in the Pixels Group "
<< std::hex << "(" << overlayLocation << " vs "
- << f1->GetGrPixel() << std::endl;
+ << f->GetGrPixel() << std::endl;
// Actually, here, we should (try to) read the overlay location
// and go on the job.
continue;
std::cout << "Mask :[" <<std::hex << mask << "]" << std::endl;
for (int j=0; j<nx*ny ; j++)
{
- if( gdcm::Debug::GetDebugFlag() )
+ if( GDCM_NAME_SPACE::Debug::GetDebugFlag() )
if (pixels[j] >= 0x1000)// if it contains at least one overlay bit
printf("%d : %04x\n",j, pixels[j]);
else
tabPixels[j] = 128;
}
- if( gdcm::Debug::GetDebugFlag() )
+ if( GDCM_NAME_SPACE::Debug::GetDebugFlag() )
std::cout << "About to built empty file" << std::endl;
- fileToBuild = new gdcm::File();
+ fileToBuild = GDCM_NAME_SPACE::File::New();
- if( gdcm::Debug::GetDebugFlag() )
+ if( GDCM_NAME_SPACE::Debug::GetDebugFlag() )
std::cout << "Finish to built empty file" << std::endl;
str.str("");
str << nx;
- fileToBuild->InsertValEntry(str.str(),0x0028,0x0011); // Columns
+ fileToBuild->InsertEntryString(str.str(),0x0028,0x0011); // Columns
str.str("");
str << ny;
- fileToBuild->InsertValEntry(str.str(),0x0028,0x0010); // Rows
+ fileToBuild->InsertEntryString(str.str(),0x0028,0x0010); // Rows
- fileToBuild->InsertValEntry("8",0x0028,0x0100); // Bits Allocated
- fileToBuild->InsertValEntry("8",0x0028,0x0101); // Bits Stored
- fileToBuild->InsertValEntry("7",0x0028,0x0102); // High Bit
- fileToBuild->InsertValEntry("0",0x0028,0x0103); // Pixel Representation
- fileToBuild->InsertValEntry("1",0x0028,0x0002); // Samples per Pixel
+ 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->InsertValEntry("MONOCHROME2 ",0x0028,0x0004);
+ fileToBuild->InsertEntryString("MONOCHROME2 ",0x0028,0x0004);
// Other mandatory fields will be set automatically,
// just before Write(), by FileHelper::CheckMandatoryElements()
- if( gdcm::Debug::GetDebugFlag() )
+ if( GDCM_NAME_SPACE::Debug::GetDebugFlag() )
std::cout << "-------------About to built FileHelper" << std::endl;
- fh = new gdcm::FileHelper(fileToBuild);
+ fh = GDCM_NAME_SPACE::FileHelper::New(fileToBuild);
- if( gdcm::Debug::GetDebugFlag() )
+ if( GDCM_NAME_SPACE::Debug::GetDebugFlag() )
std::cout << "-------------Finish to built FileHelper" << std::endl;
fh->SetImageData(tabPixels,nx*ny);
{
std::cout << "Failed\n"
<< "File in unwrittable\n";
- delete fh;
+ fh->Delete();
if (fileToBuild)
- delete fileToBuild;
+ fileToBuild->Delete();
delete pixels;
delete tabPixels;
return 0;
i++;
}
- delete f1;
- if (f1)
- delete fh;
+ if (f)
+ fh->Delete();
if (fileToBuild)
- delete fileToBuild;
+ fileToBuild->Delete();
+ f->Delete();
delete pixels;
delete tabPixels;
+
return 0;
}