-
- GDCM_NAME_SPACE::File *f2;
- f2 = GDCM_NAME_SPACE::File::New( );
- GDCM_NAME_SPACE::FileHelper *fh2 = GDCM_NAME_SPACE::FileHelper::New(f2);
-
- 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.
- // ...
-
- sprintf(outputFileName, "../%s.ovly.%04x.dcm",it->c_str(), ovlyGroup+k);
-
- fh2->SetImageData(outputData,dimXY);
- fh2->WriteDcmExplVR(outputFileName);
-
- std::cout <<"File written successfully [" << outputFileName << "]" <<std::endl;
-
- delete outputData;
- f2->Delete();
- fh2->Delete();
-
- } // end on loop on 60xx
-
+
+ fileToBuild = GDCM_NAME_SPACE::File::New();
+ str.str("");
+ str << nx;
+ fileToBuild->InsertEntryString(str.str(),0x0028,0x0011, "US"); // Columns
+ str.str("");
+ str << ny;
+ fileToBuild->InsertEntryString(str.str(),0x0028,0x0010, "US"); // Rows
+
+ fileToBuild->InsertEntryString("8",0x0028,0x0100, "US"); // Bits Allocated
+ fileToBuild->InsertEntryString("8",0x0028,0x0101, "US"); // Bits Stored
+ fileToBuild->InsertEntryString("7",0x0028,0x0102, "US"); // High Bit
+ fileToBuild->InsertEntryString("0",0x0028,0x0103, "US"); // Pixel Representation
+ fileToBuild->InsertEntryString("1",0x0028,0x0002, "US"); // Samples per Pixel
+ fileToBuild->InsertEntryString("MONOCHROME2 ",0x0028,0x0004, "LO");
+
+ // feel free to add any field (Dicom Data Entry) you like, here.
+ // ...
+ // Other mandatory fields will be set automatically,
+ // just before Write(), by FileHelper::CheckMandatoryElements()
+
+ fh = GDCM_NAME_SPACE::FileHelper::New(fileToBuild);
+
+ fh->SetImageData(outputData,nx*ny);
+ fh->SetWriteTypeToDcmExplVR();
+
+std::ostringstream tmp;
+tmp <<std::hex;
+tmp <<currentOvlGroup;
+
+ str.str("");
+// -> Why doesn't it work ?!?
+ //str << fileName << std::hex << currentOvlGroup << ".dcm" << std::ends;
+
+str << fileName << ".ovly." << tmp.str() << ".dcm" << std::ends;
+
+ // Write the current 'overlay' file
+
+ if( !fh->Write(str.str()) )
+ {
+ std::cout << "Failed\n"
+ << "File [" << str.str() << "] is unwrittable" << std::endl;
+ }
+ else
+ {
+ std::cout << "File written successfully [" << str.str() << "]" << std::endl;
+ }
+
+ } // end on loop on 60xx
+
+ if (f)
+ fh->Delete();
+ if (fileToBuild)
+ fileToBuild->Delete();