I would like to create a method which generate a DICOMDIR file with the directory in parameter.
I have the code below :
Code: Select all
bool writeDICOMDIR(const char* dir)
{
// Variables
OFBool opt_write = OFTrue;
OFBool opt_append = OFFalse;
OFBool opt_update = OFFalse;
OFBool opt_recurse = OFFalse;
E_EncodingType opt_enctype = EET_ExplicitLength;
E_GrpLenEncoding opt_glenc = EGL_withoutGL;
const char *opt_output = DEFAULT_DICOMDIR_NAME;
const char *opt_fileset = DEFAULT_FILESETID;
const char *opt_descriptor = NULL;
const char *opt_charset = DEFAULT_DESCRIPTOR_CHARSET;
const char *opt_directory = "";
const char *opt_pattern = "";
DicomDirInterface::E_ApplicationProfile opt_profile = DicomDirInterface::AP_GeneralPurpose;
bool isOK = false;
// register global decompression codecs (no verbose/debug mode set)
DcmRLEDecoderRegistration::registerCodecs();
DJDecoderRegistration::registerCodecs();
/* DICOMDIR interface (checks for JPEG/RLE availability) */
DicomDirInterface ddir;
ddir.enableMapFilenamesMode(OFFalse); // --keep-filenames
opt_recurse = OFTrue; // --recurse
opt_directory = ".";
ddir.enableAbortMode(OFTrue); // --abort-inconsist-file
ddir.disableTransferSyntaxCheck(); // --no-xfer-check
ddir.disableBackupMode(); // --no-backup
// --enable-new-vr
dcmEnableUnknownVRGeneration.set(OFTrue);
dcmEnableUnlimitedTextVRGeneration.set(OFTrue);
///////////////////////////////////////////////
opt_glenc = EGL_withoutGL; // --group-length-remove
opt_enctype = EET_ExplicitLength; // --length-explicit
/* Create list of input files */
OFList<OFString> fileNames;
OFString pathname = dir;
//const char *param = NULL;
if (opt_recurse)
{
unsigned int iNbAddedFiles = OFStandard::searchDirectoryRecursively(pathname, fileNames, opt_pattern, opt_directory);
std::cout << "Number of files : " << iNbAddedFiles << std::endl;
}
// BUILD_DCMGPDIR_AS_DCMMKDIR : add image support to DICOMDIR class
//DicomDirImageImplementation imagePlugin;
//ddir.addImageSupport(&imagePlugin);
OFCondition result;
/* create new general purpose DICOMDIR, append to or update existing one */
if (opt_append)
result = ddir.appendToDicomDir(opt_profile, opt_output);
else if (opt_update)
result = ddir.updateDicomDir(opt_profile, opt_output);
else
result = ddir.createNewDicomDir(opt_profile, opt_output, opt_fileset);
if (result.good())
{
/* set fileset descriptor and character set */
result = ddir.setFilesetDescriptor(opt_descriptor, opt_charset);
if (result.good())
{
/* collect 'bad' files */
OFList<OFString> badFiles;
unsigned int goodFiles = 0;
OFListIterator(OFString) iter = fileNames.begin();
OFListIterator(OFString) last = fileNames.end();
/* iterate over all input filenames */
while (iter != last && result.good())
{
/* add files to the DICOMDIR */
result = ddir.addDicomFile((*iter).c_str(), opt_directory);
if (result.bad())
{
badFiles.push_back(*iter);
if (!ddir.abortMode())
/* ignore inconsistent file, just warn (already done inside "ddir") */
result = EC_Normal;
}
else
++goodFiles;
++iter;
}
/* evaluate result of file checking/adding procedure */
if (goodFiles == 0)
result = EC_IllegalCall;
else
{
if (!badFiles.empty())
{
iter = badFiles.begin();
last = badFiles.end();
while (iter != last)
++iter;
}
}
/* write DICOMDIR file */
if (result.good() && opt_write)
{
result = ddir.writeDicomDir(opt_enctype, opt_glenc);
if (result.good())
isOK = true;
}
}
}
// deregister global decompression codecs
DcmRLEDecoderRegistration::cleanup();
DJDecoderRegistration::cleanup();
return isOK;
}
Thanks,