]> Creatis software - gdcm.git/blobdiff - Example/ReWrite.cxx
Dicomize Dense files in their 2007 version
[gdcm.git] / Example / ReWrite.cxx
index 8e8836b95a1632b7d340659b9fb12d14f26b24af..b43bfcd8d61132efd3a51bcc3185fcfd33e5ada9 100644 (file)
@@ -3,8 +3,8 @@
   Program:   gdcm
   Module:    $RCSfile: ReWrite.cxx,v $
   Language:  C++
-  Date:      $Date: 2007/03/23 14:59:58 $
-  Version:   $Revision: 1.22 $
+  Date:      $Date: 2007/07/04 10:43:19 $
+  Version:   $Revision: 1.27 $
                                                                                 
   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
   l'Image). All rights reserved. See Doc/License.txt or
@@ -32,23 +32,25 @@ int main(int argc, char *argv[])
    "     (usefull when the file header is not very straight).               ",
    "                                                                        ",
    " usage: ReWrite filein=inputFileName fileout=outputFileName             ", 
-   "       [mode=write mode] [noshadow] [noseq][debug]                      ",
+   "       [mode=write mode] [monochrome1] [noshadow] [noseq][debug]        ",
    "  --> The following line to 'rubout' a burnt-in Patient name            ",
    "       [rubout=xBegin,xEnd,yBegin,yEnd [ruboutvalue=n (<255)] ]         ",
-   "  --> The 2 following lines, to extract a sub image withon some frames  ",
+   "  --> The 2 following lines, to extract a sub image within some frames  ",
    "       [ROI=xBegin,xEnd,yBegin,yEnd]                                    ",
    "       [firstframe=beg] [lastframe=end]                                 ", 
    "                                                                        ",
    "        mode = a (ACR), x (Explicit VR Dicom), r (RAW : only pixels)    ",
+   "        monochrome1 = user wants MONOCHROME1 photom. interp. (0=white)  ",
    "        noshadowseq: user doesn't want to load Private Sequences        ",
    "        noshadow : user doesn't want to load Private groups (odd number)",
    "        noseq    : user doesn't want to load Sequences                  ",
-   "        rgb      : user wants to tranform LUT (if any) to RGB pixels    ",
+   "        rgb      : user wants to transform LUT (if any) to RGB pixels   ",
+   "        warning  : developper wants to run the program in 'warning mode'",
    "        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")) 
    {
@@ -74,22 +76,27 @@ int main(int argc, char *argv[])
 
    const char *mode = am->ArgMgrGetString("mode","X");
 
-   int loadMode = gdcm::LD_ALL;
+   int loadMode = GDCM_NAME_SPACE::LD_ALL;
    if ( am->ArgMgrDefined("noshadowseq") )
-      loadMode |= gdcm::LD_NOSHADOWSEQ;
+      loadMode |= GDCM_NAME_SPACE::LD_NOSHADOWSEQ;
    else 
    {
    if ( am->ArgMgrDefined("noshadow") )
-         loadMode |= gdcm::LD_NOSHADOW;
+         loadMode |= GDCM_NAME_SPACE::LD_NOSHADOW;
       if ( am->ArgMgrDefined("noseq") )
-         loadMode |= gdcm::LD_NOSEQ;
+         loadMode |= GDCM_NAME_SPACE::LD_NOSEQ;
    }
 
    bool rgb = ( 0 != am->ArgMgrDefined("RGB") );
 
+   bool monochrome1 = ( 0 != am->ArgMgrDefined("monochrome1") );
+   
    if (am->ArgMgrDefined("debug"))
-      gdcm::Debug::DebugOn();
-      
+      GDCM_NAME_SPACE::Debug::DebugOn();
+
+   if (am->ArgMgrDefined("warning"))
+      GDCM_NAME_SPACE::Debug::WarningOn();
+            
    bool fail = false;
    int *boundVal;
    int ruboutVal;
@@ -142,11 +149,12 @@ int main(int argc, char *argv[])
 
    // ----------- End Arguments Manager ---------
 
-   gdcm::File *f = gdcm::File::New();
+   GDCM_NAME_SPACE::File *f = GDCM_NAME_SPACE::File::New();
    f->SetLoadMode( loadMode );
+
    f->SetFileName( fileName );
    bool res = f->Load();  
-   if ( !res )
+      if ( !res )
    {
       f->Delete();
       return 0;
@@ -158,9 +166,8 @@ int main(int argc, char *argv[])
        f->Delete();
        return 0;
    }
    
-   gdcm::FileHelper *fh = gdcm::FileHelper::New(f);
+   GDCM_NAME_SPACE::FileHelper *fh = GDCM_NAME_SPACE::FileHelper::New(f);
    void *imageData; 
    int dataSize;
  
@@ -189,7 +196,9 @@ int main(int argc, char *argv[])
    transferSyntaxName = f->GetTransferSyntaxName();
    std::cout << " TransferSyntaxName= [" << transferSyntaxName << "]" 
              << std::endl;
+  
+   if(monochrome1)
+      fh->SetPhotometricInterpretationToMonochrome1();
    
    if (rgb)
    {
@@ -213,7 +222,7 @@ int main(int argc, char *argv[])
    // Since we just ReWrite the image, we know no modification 
    // was performed on the pixels.
    // We don't want this image appears as a 'Secondary Captured image'
-   fh->SetContentType(gdcm::UNMODIFIED_PIXELS_IMAGE);
+   fh->SetContentType(GDCM_NAME_SPACE::UNMODIFIED_PIXELS_IMAGE);
    
 
    /// \todo : think about rubbing out a part of a *multiframe* image!
@@ -308,7 +317,7 @@ int main(int argc, char *argv[])
    } 
    else
    {  
-     roiBoundVal = new int(4);
+     roiBoundVal = new int[4];
      roiBoundVal[0] = 0;
      roiBoundVal[1] = nX-1;
      roiBoundVal[2] = 0;
@@ -321,9 +330,9 @@ int main(int argc, char *argv[])
   if (roi || beg != -1 || end != -1)
   {  
      if (beg == -1)
-      beg = 0;  
+        beg = 0;  
      if (end == -1)
-      end = nZ-1;
+        end = nZ-1;
      
      std::ostringstream str;
      
@@ -344,15 +353,15 @@ int main(int argc, char *argv[])
  
      int lineOffset = roiBoundVal[0]*pixelSize * numberOfScalarComponents;
      
-     for (unsigned int frameNb=beg, frameCount=0; frameNb<=end; frameNb++, frameCount++)
+     for (int frameNb=beg, frameCount=0; frameNb<=end; frameNb++, frameCount++)
      { 
-         for (unsigned int lineNb=roiBoundVal[2], lineCount=0; lineNb<=roiBoundVal[3]; lineNb++, lineCount++)
-         {  
+        for (int lineNb=roiBoundVal[2], lineCount=0; lineNb<=roiBoundVal[3]; lineNb++, lineCount++)
+        {  
             /// \todo increment data pointer, don't multiply so much!
             memcpy( (void *)(destCopy + frameCount*lgrSubFrame + lineCount*lgrSubLine), 
                     (void *)(srcCopy  + frameNb*frameSize + lineNb*lineSize + lineOffset ), 
                     lgrSubLine);
-         }        
+        }        
      }
  
     // Set the image size
@@ -441,3 +450,4 @@ int main(int argc, char *argv[])
    return 0;
 }