]> Creatis software - gdcm.git/blobdiff - Example/exOverlaysDCM.cxx
Temporary comment out of WriteDicomAsJPEGxxx
[gdcm.git] / Example / exOverlaysDCM.cxx
index 02385aad191f1d40e193247dbcf1486677a172bb..8efa49ebca0c18e4462ac5c39558f6729e461676 100755 (executable)
@@ -7,6 +7,8 @@
 #include "gdcmArgMgr.h"
 #include <iostream>
 
+// 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;
@@ -25,15 +27,15 @@ void explodeByte(unsigned char byte, unsigned char* result)
 int main(int argc, char *argv[])
 {
    START_USAGE(usage)
-   " \n exReadOverlays :\n                                                    ",
-   " Extract an overlay image from a secondary capture image                  ",
+   " \n exOverlaysDCM :\n                                                     ",
+   " Extract an overlay image from a DICOM image                              ",
    "          Warning : probably segfaults if no overlay                      ",
-   " usage: WriteOverlayImage filein=inputFileName fileout=outputFileName[debug]",
-   "        debug    : user wants to run the program in 'debug mode'          ",
+   " usage: exOverlaysDCM filein=inputFileName fileout=outputFileName [debug] ",
+   "        debug    : developper wants to run the program in 'debug mode'    ",
    FINISH_USAGE
 
    // ----- Initialize Arguments Manager ------
-   gdcm::ArgMgr *am = new gdcm::ArgMgr(argc, argv);
+   GDCM_NAME_SPACE::ArgMgr *am = new GDCM_NAME_SPACE::ArgMgr(argc, argv);
 
    if (argc == 1 || am->ArgMgrDefined("usage"))
    {
@@ -41,12 +43,31 @@ int main(int argc, char *argv[])
       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 )
@@ -55,8 +76,11 @@ int main(int argc, char *argv[])
       return 0;
    }
    if (am->ArgMgrDefined("debug"))
-      gdcm::Debug::DebugOn();
-
+      GDCM_NAME_SPACE::Debug::DebugOn();
+      
+   if (am->ArgMgrDefined("warning"))
+      GDCM_NAME_SPACE::Debug::WarningOn();
+      
    // if unused Param we give up
    if ( am->ArgMgrPrintUnusedLabels() )
    {
@@ -71,10 +95,10 @@ int main(int argc, char *argv[])
    //   Read the input file.
    // ============================================================
 
-   gdcm::File *f;
+   GDCM_NAME_SPACE::File *f;
 
-   f = gdcm::File::New(  );
-   f->SetLoadMode( gdcm::LD_ALL );
+   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();
@@ -92,7 +116,7 @@ int main(int argc, char *argv[])
    //   Load the Overlays in memory (the first one)
    // ============================================================
 
-   gdcm::DataEntry *e = f->GetDataEntry(0x6000, 0x3000);  
+   GDCM_NAME_SPACE::DataEntry *e = f->GetDataEntry(0x6000, 0x3000);  
    if (e == 0)
    {
       std::cout << " Image doesn't contain any Overlay " << std::endl;
@@ -113,12 +137,14 @@ int main(int argc, char *argv[])
    // ============================================================
    //  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 : "<<dimXY << std::endl;
+   std::cout << "DimX : "<< dimX <<" DimY : " << dimY 
+             << " DimXY : " <<dimXY << std::endl;
    unsigned char *outputData = new unsigned char[dimXY];
 
    unsigned char *result=outputData;
@@ -127,36 +153,41 @@ int main(int argc, char *argv[])
       explodeByte(overlay[i], result);
       result+=8;
    }
-
-
+   
    // ============================================================
    //   Write a new file
    // ============================================================
-
+   GDCM_NAME_SPACE::File *f2;
+   f2 = GDCM_NAME_SPACE::File::New(  );
+   
    char temp[256];
    
    sprintf(temp,"%d ",dimX);
-   f->InsertEntryString(temp,0x0028,0x0011); // Columns
+   f2->InsertEntryString(temp,0x0028,0x0011, "US"); // Columns
    sprintf(temp,"%d ",dimY);
-   f->InsertEntryString(temp,0x0028,0x0010); // Rows
+   f2->InsertEntryString(temp,0x0028,0x0010, "US"); // Rows
 
-   f->InsertEntryString("8",0x0028,0x0100); // Bits Allocated
-   f->InsertEntryString("8",0x0028,0x0101); // Bits Stored
-   f->InsertEntryString("7",0x0028,0x0102); // High Bit
-   f->InsertEntryString("0",0x0028,0x0103); // Pixel Representation
-   f->InsertEntryString("1",0x0028,0x0002); // Samples per Pixel
-   f->InsertEntryString("MONOCHROME2 ",0x0028,0x0004);  
+   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");  
 
-   // We need a gdcm::FileHelper, since we want to load the pixels
-   gdcm::FileHelper *fh = gdcm::FileHelper::New(f);
+
+   // 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();   
+   f->Delete();
+   f2->Delete();  
    fh->Delete();
+   
    return 0;
 }