Problem DICOMDIR generation

All other questions regarding DCMTK

Moderator: Moderator Team

Post Reply
Message
Author
Mercusyo
Posts: 34
Joined: Mon, 2011-10-31, 15:22

Problem DICOMDIR generation

#1 Post by Mercusyo »

Hello,

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;
}
But, the code don't work, I have the message "component too large (max 8 characters) in filename ... :?:

Thanks,

J. Riesmeier
DCMTK Developer
Posts: 2504
Joined: Tue, 2011-05-03, 14:38
Location: Oldenburg, Germany
Contact:

Re: Problem DICOMDIR generation

#2 Post by J. Riesmeier »

But, the code don't work, I have the message "component too large (max 8 characters) in filename .
I haven't checked your source code, but the error message should be clear: You cannot add DICOM files with filenames/directories that consist of more than 8 characters. This is clearly specified in the DICOM standard!

Mercusyo
Posts: 34
Joined: Mon, 2011-10-31, 15:22

Re: Problem DICOMDIR generation

#3 Post by Mercusyo »

I haven't checked your source code, but the error message should be clear: You cannot add DICOM files with filenames/directories that consist of more than 8 characters. This is clearly specified in the DICOM standard!
Ok, thank you for your reply. It was just a question. But, there is no solution if the files are more than 8 characters :?: Actually, I have files with ".dcm" extensions ... Therefore, I must remove extensions :?:

Thanks!

J. Riesmeier
DCMTK Developer
Posts: 2504
Joined: Tue, 2011-05-03, 14:38
Location: Oldenburg, Germany
Contact:

Re: Problem DICOMDIR generation

#4 Post by J. Riesmeier »

Yes, you have to rename the files before creating the DICOMDIR.

Mercusyo
Posts: 34
Joined: Mon, 2011-10-31, 15:22

Re: Problem DICOMDIR generation

#5 Post by Mercusyo »

Thank you for your help. My code work now but if all the dicom files are in the same directory.
I realised a second test, I have several dicom files, (without extension), in different directories :
- D:\test\0058\0001 0002 0003 etc
- D:\test\0062\0001 0002 etc
I would like to create the DICOMDIR file for all the dicom files, (in the 2 directories), and I have the error "component too large (max 8 characters) ..." followed by the directory. I tested with the binary "dcmmkdir.exe", and i have the same error ...
So is it possible ?
Thanks

Mercusyo
Posts: 34
Joined: Mon, 2011-10-31, 15:22

Re: Problem DICOMDIR generation

#6 Post by Mercusyo »

Another question : all the files and directories are more 8 characters :?:

J. Riesmeier
DCMTK Developer
Posts: 2504
Joined: Tue, 2011-05-03, 14:38
Location: Oldenburg, Germany
Contact:

Re: Problem DICOMDIR generation

#7 Post by J. Riesmeier »

Could you please tell me how your directory/file structure actually is? The one from your previous posting ("D:\test\0058\0001") looks ok to me. Of course, you cannot pass the absolute path "D:\" to the addDicomFile() method. This is why there is an optional "directory" parameter for this method.

Mercusyo
Posts: 34
Joined: Mon, 2011-10-31, 15:22

Re: Problem DICOMDIR generation

#8 Post by Mercusyo »

Thank you for your answer. For example, I have several folders like :

D:\dcm\IRM PROSTATE_\00101_SURVprostT2
D:\dcm\IRM PROSTATE_\00301_C_T2-AX
D:\dcm\IRM PROSTATE_\00401_@C_T2-CORO
...

Thanks

Mercusyo
Posts: 34
Joined: Mon, 2011-10-31, 15:22

Re: Problem DICOMDIR generation

#9 Post by Mercusyo »

If I understand, I have to create some folders, (on 8 characters), with the dicom files renamed on 8 characters :?:

J. Riesmeier
DCMTK Developer
Posts: 2504
Joined: Tue, 2011-05-03, 14:38
Location: Oldenburg, Germany
Contact:

Re: Problem DICOMDIR generation

#10 Post by J. Riesmeier »

Right, and also the choice of characters is limited to A-Z, 0-9 and the underscore (_).

Mercusyo
Posts: 34
Joined: Mon, 2011-10-31, 15:22

Re: Problem DICOMDIR generation

#11 Post by Mercusyo »

Ok thank you. It works fine with this recommandation :D

Post Reply

Who is online

Users browsing this forum: Bing [Bot] and 1 guest