- if( gdcm::Debug::GetDebugFlag() )
- std::cout << "About to built empty file" << std::endl;
-
- gdcm::File *fileToBuild = gdcm::File::New();
-
- if( gdcm::Debug::GetDebugFlag() )
- std::cout << "Finish to built empty file" << std::endl;
-
- std::ostringstream str;
- str.str("");
- str << nx;
- fileToBuild->InsertEntryString(str.str(),0x0028,0x0011); // Columns
- str.str("");
- str << ny;
- fileToBuild->InsertEntryString(str.str(),0x0028,0x0010); // Rows
-
- 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->InsertEntryString("MONOCHROME2 ",0x0028,0x0004);
- // Other mandatory fields will be set automatically,
- // just before Write(), by FileHelper::CheckMandatoryElements()
-
- if( gdcm::Debug::GetDebugFlag() )
- std::cout << "-------------About to built FileHelper" << std::endl;
-
- gdcm::FileHelper *fh = gdcm::FileHelper::New(fileToBuild);
-
- if( gdcm::Debug::GetDebugFlag() )
- std::cout << "-------------Finish to built FileHelper" << std::endl;
-
- fh->SetImageData(overlayPixelImage,nx*ny);
- fh->SetWriteTypeToDcmExplVR();
-
- str.str("");
- str<<"gdcmOverlay" << ".dcm";
- // Write the current 'overlay' file
-
- if( !fh->Write(str.str()) )
- {
- std::cout << "Failed\n"
- << "File in unwrittable\n";
- fh->Delete();
- if (fileToBuild)
- fileToBuild->Delete();
- delete overlayPixelImage;
-
- return 0;
- }
- else
- {
- std::cout << "File written successfully" << std::endl;
- }
-
- if (f)
- fh->Delete();
- if (fileToBuild)
- fileToBuild->Delete();
+ unsigned int dimXY=dimX*dimY;
+ std::cout << "DimX : "<< dimX <<" DimY : " << dimY
+ << " DimXY : " <<dimXY << std::endl;
+ unsigned char *outputData = new unsigned char[dimXY];
+
+ unsigned char *result=outputData;
+ for (unsigned int i=0;i<(dimXY/8);i++)
+ {
+ 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);
+ f2->InsertEntryString(temp,0x0028,0x0011, "US"); // Columns
+ sprintf(temp,"%d ",dimY);
+ f2->InsertEntryString(temp,0x0028,0x0010, "US"); // Rows
+
+ 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");
+
+
+ // 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;