+ int sizeX; // Size X of the image
+ int sizeY; // Size Y of the image
+ int sizeZ; // Size Z of the image
+ int components; // Number of components for a pixel
+ int componentSize; // Component size (in bits : 8, 16)
+ int componentUse ; // Component size (in bits)
+ int sign; // Sign of components
+ char writeMode; // Write mode
+ // - 'a' : ACR
+ // - 'e' : Explicit VR
+ // - 'i' : Implicit VR
+} Image;
+
+Image Images [] = {
+ {256, 256, 1, 1, 8, 8, 0, 'a'},
+ {256, 256, 1, 1, 8, 8, 0, 'e'},
+ {256, 256, 1, 1, 8, 8, 0, 'i'},
+
+ {512, 256, 1, 1, 8, 8, 0, 'a'},
+ {512, 256, 1, 1, 8, 8, 0, 'e'},
+ {512, 256, 1, 1, 8, 8, 0, 'i'},
+
+ {256, 512, 1, 1, 8, 8, 0, 'a'},
+ {256, 512, 1, 1, 8, 8, 0, 'e'},
+ {256, 512, 1, 1, 8, 8, 0, 'i'},
+
+ {256, 512, 1, 1, 16, 16, 0, 'a'},
+ {256, 512, 1, 1, 16, 16, 0, 'e'},
+ {256, 512, 1, 1, 16, 16, 0, 'i'},
+ {256, 512, 1, 1, 16, 16, 0, 'a'},
+ {256, 512, 1, 1, 16, 16, 0, 'e'},
+ {256, 512, 1, 1, 16, 16, 0, 'i'},
+
+ {512, 256, 10, 1, 8, 8, 0, 'a'},
+ {512, 256, 10, 1, 8, 8, 0, 'e'},
+ {512, 256, 10, 1, 8, 8, 0, 'i'},
+ {512, 256, 10, 3, 8, 8, 0, 'a'},
+ {512, 256, 10, 3, 8, 8, 0, 'e'},
+ {512, 256, 10, 3, 8, 8, 0, 'i'},
+ {0, 0, 1, 1, 8, 8, 0, 'i'} // to find the end
+};
+
+int WriteSimple(Image &img)
+{
+ std::string fileName = "TestWriteSimple.dcm";
+
+// Step 1 : Create the header of the image
+ std::cout << " 1...";
+ gdcm::File *fileToBuild = new gdcm::File();
+ std::ostringstream str;
+
+ // Set the image size
+ str.str("");
+ str << img.sizeX;
+ fileToBuild->InsertValEntry(str.str(),0x0028,0x0011); // Columns
+
+ str.str("");
+ str << img.sizeY;
+ fileToBuild->InsertValEntry(str.str(),0x0028,0x0010); // Rows
+
+ if(img.sizeZ>1)
+ {
+ str.str("");
+ str << img.sizeZ;
+ fileToBuild->InsertValEntry(str.str(),0x0028,0x0008); // Number of Frames
+ }
+
+ // Set the pixel type
+ str.str("");
+ str << img.componentSize;
+ fileToBuild->InsertValEntry(str.str(),0x0028,0x0100); // Bits Allocated
+
+ str.str("");
+ str << img.componentUse;
+ fileToBuild->InsertValEntry(str.str(),0x0028,0x0101); // Bits Stored
+
+ str.str("");
+ str << img.componentSize - 1;
+ fileToBuild->InsertValEntry(str.str(),0x0028,0x0102); // High Bit
+
+ // Set the pixel representation
+ str.str("");
+ str << img.sign;
+ fileToBuild->InsertValEntry(str.str(),0x0028,0x0103); // Pixel Representation
+
+ // Set the samples per pixel
+ str.str("");
+ str << img.components;
+ fileToBuild->InsertValEntry(str.str(),0x0028,0x0002); // Samples per Pixel
+
+ if( !fileToBuild->IsReadable() )
+ {
+ std::cout << "Failed\n"
+ << " Prepared image isn't readable\n";
+
+ delete fileToBuild;
+ return 1;
+ }
+
+// Step 2 : Create the output image
+ std::cout << "2...";
+ if( img.componentSize%8 > 0 )
+ {
+ img.componentSize += 8-img.componentSize%8;
+ }
+ size_t size = img.sizeX * img.sizeY * img.sizeZ
+ * img.components * img.componentSize / 8;
+ unsigned char *imageData = new unsigned char[size];
+
+ // FIXME : find a better heuristic to create the image
+ unsigned char *tmp = imageData;
+ for(int k=0;k<img.sizeZ;k++)
+ {
+ for(int j=0;j<img.sizeY;j++)
+ {
+ for(int i=0;i<img.sizeX;i++)
+ {
+ for(int c=0;c<img.components;c++)
+ {
+ *tmp = j%256;
+ if( img.componentSize>8 )
+ {
+ *(tmp+1) = j/256;
+ }
+ tmp += img.components/8;
+ }
+ }
+ }
+ }
+
+// Step 3 : Create the file of the image
+ std::cout << "3...";
+ gdcm::FileHelper *file = new gdcm::FileHelper(fileToBuild);
+ file->SetImageData(imageData,size);