]> Creatis software - gdcm.git/blobdiff - Example/WriteDicomSimple.cxx
Looping 10000000 times should be enought
[gdcm.git] / Example / WriteDicomSimple.cxx
index f5b4e273d29058f53daa67f706be7d19c4634459..ab83ac19fdb65e12d13cf32aed1f2387e3396b2a 100644 (file)
@@ -3,8 +3,8 @@
   Program:   gdcm
   Module:    $RCSfile: WriteDicomSimple.cxx,v $
   Language:  C++
-  Date:      $Date: 2005/01/25 15:44:22 $
-  Version:   $Revision: 1.10 $
+  Date:      $Date: 2005/10/25 14:52:27 $
+  Version:   $Revision: 1.15 $
                                                                                 
   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
   l'Image). All rights reserved. See Doc/License.txt or
@@ -24,7 +24,7 @@
  */
 #include "gdcmFile.h"
 #include "gdcmFileHelper.h"
-
 #include <iostream>
 #include <sstream>
 
@@ -39,7 +39,7 @@
 #define COLOR_WINDOW    256
 #define COLOR_LEVEL     128
 
-int main(int argc, charargv[])
+int main(int argc, char *argv[])
 {
    if (argc < 3) 
    {
@@ -57,52 +57,52 @@ int main(int argc, char* argv[])
 
 
 // Step 1 : Create the header of the image
-   gdcm::File *header = new gdcm::File();
+   gdcm::File *header = gdcm::File::New();
    std::ostringstream str;
 
    // Set the image size
    str.str("");
    str << SIZE_X;
-   header->InsertValEntry(str.str(),0x0028,0x0011); // Columns
+   header->InsertEntryString(str.str(),0x0028,0x0011); // Columns
 
    str.str("");
    str << SIZE_Y;
-   header->InsertValEntry(str.str(),0x0028,0x0010); // Rows
+   header->InsertEntryString(str.str(),0x0028,0x0010); // Rows
 
    // Set the pixel type
    str.str("");
    str << COMPONENT_SIZE * 8;
-   header->InsertValEntry(str.str(),0x0028,0x0100); // Bits Allocated
-   header->InsertValEntry(str.str(),0x0028,0x0101); // Bits Stored
+   header->InsertEntryString(str.str(),0x0028,0x0100); // Bits Allocated
+   header->InsertEntryString(str.str(),0x0028,0x0101); // Bits Stored
 
    str.str("");
-   str << COMPONENT_SIZE * 8 - 1;
-   header->InsertValEntry(str.str(),0x0028,0x0102); // High Bit
+   str << ( COMPONENT_SIZE * 8 ) - 1;
+   header->InsertEntryString(str.str(),0x0028,0x0102); // High Bit
 
    // Set the pixel representation
    str.str("");
    str << "0"; // Unsigned
-   header->InsertValEntry(str.str(),0x0028,0x0103); // Pixel Representation
+   header->InsertEntryString(str.str(),0x0028,0x0103); // Pixel Representation
 
    // Set the samples per pixel
    str.str("");
    str << COMPONENT;
-   header->InsertValEntry(str.str(),0x0028,0x0002); // Samples per Pixel
+   header->InsertEntryString(str.str(),0x0028,0x0002); // Samples per Pixel
 
    // Set the Window / Level
    str.str("");
    str << COLOR_WINDOW;
-   header->InsertValEntry(str.str(),0x0028,0x1051); // Window Width
+   header->InsertEntryString(str.str(),0x0028,0x1051); // Window Width
    str.str("");
    str << COLOR_LEVEL;
-   header->InsertValEntry(str.str(),0x0028,0x1050); // Window Center
+   header->InsertEntryString(str.str(),0x0028,0x1050); // Window Center
 
    if( !header->IsReadable() )
    {
       std::cerr << "-------------------------------\n"
                 << "Error while creating the file\n"
                 << "This file is considered to be not readable\n";
-
+      header->Delete();
       return 1;
    }
 
@@ -117,14 +117,14 @@ int main(int argc, char* argv[])
       {
          for(int c=0;c<COMPONENT;c++)
          {
-            *tmp = j;
+            *tmp = (unsigned char)j;
             tmp += COMPONENT_SIZE; 
          }
       }
    }
 
 // Step 3 : Create the file of the image
-   gdcm::FileHelper *file = new gdcm::FileHelper(header);
+   gdcm::FileHelper *file = gdcm::FileHelper::New(header);
    file->SetImageData(imageData,size);
 
 // Step 4 : Set the writting mode and write the image
@@ -162,18 +162,17 @@ int main(int argc, char* argv[])
                    << "File :" << fileName << std::endl;
 
          delete[] imageData;
-         delete file;
-         delete header;
+         file->Delete();
+         header->Delete();
          return 0;
 
       default :
          std::cout << "-------------------------------\n"
                    << "Write mode undefined...\n"
                    << "No file written\n";
-
          delete[] imageData;
-         delete file;
-         delete header;
+         file->Delete();
+         header->Delete();
          return 1;
    }
 
@@ -185,8 +184,8 @@ int main(int argc, char* argv[])
    }
 
    delete[] imageData;
-   delete file;
-   delete header;
+   file->Delete();
+   header->Delete();
 
    return 0;
 }