Continuation of closed topic

All other questions regarding DCMTK

Moderator: Moderator Team

Message
Author
Mitmal
Posts: 112
Joined: Mon, 2011-04-18, 19:36
Location: France

#16 Post by Mitmal »

ok, now I have some image information in my file but it's not clear...
my code :

Code: Select all

DcmFileFormat *fileformat = new DcmFileFormat(dataObject);
OFCondition status = fileformat->saveFile(path);
I have some information like the constructor or the series Description Name but the picture is very strange...

I'm looking this example :

Code: Select all

char uid[100];
DcmFileFormat fileformat;
DcmDataset *dataset = fileformat.getDataset();
dataset->putAndInsertString(DCM_SOPClassUID, UID_SecondaryCaptureImageStorage);
dataset->putAndInsertString(DCM_SOPInstanceUID, dcmGenerateUniqueIdentifier(uid, SITE_INSTANCE_UID_ROOT));
dataset->putAndInsertString(DCM_PatientName, "Doe^John");
/* ... */
dataset->putAndInsertUint8Array(DCM_PixelData, pixelData, pixelLength);
OFCondition status = fileformat.saveFile("test.dcm", EXS_LittleEndianExplicit);
if (status.bad())
  cerr << "Error: cannot write DICOM file (" << status.text() << ")" << endl;
And I'm asking if I need to add EXS_LittleEndianExplicit, or if I have to check it on the dcmdataset ???
Respectueusement,
MitMal

Mitmal
Posts: 112
Joined: Mon, 2011-04-18, 19:36
Location: France

#17 Post by Mitmal »

My problem persists, Do not have any idea to help me??
Respectueusement,
MitMal

Roadrunner
Posts: 56
Joined: Mon, 2010-06-14, 16:41

#18 Post by Roadrunner »

And I'm asking if I need to add EXS_LittleEndianExplicit, or if I have to check it on the dcmdataset ???
http://support.dcmtk.org/docs/classDcmD ... dbcfd78d3b
"transfer syntax used to write the data (EXS_Unknown means use current)"
This should tell you everything .... so it depends on what you wanna do. If you want to save the files for a DICOMDIR you should really save the files on EXS_LittleEndianExplicit otherwise leave it as it is - EXS_Unknown = current ... and you always have one from your storescp. ;-)

Frank

Mitmal
Posts: 112
Joined: Mon, 2011-04-18, 19:36
Location: France

#19 Post by Mitmal »

Right, well I did not solve a problem but I bypassed.
In fact, the DICOM file that is saved on my disk after recovery from the PACS is still not displayed correctly with the other viewers (DICOMWork, Intrasence ...), it should miss information in a field.

But my program does not use this information. Since I just look at the image dimensions (height and weight) and some other characteristics (pixelSpacing. ..), and pixelData, so I can use its in my program files anyway.

So here is my code, which suits me, but must have an error:

Code: Select all

/*** 
Permet de manipuler un ensemble de commandes entrantes et de réagir en conséquence, par exemple \ réponse envoi via DIMSE_sendXXXResponse (). 
Le gestionnaire de la norme ne connaît que la façon de traiter une demande d'écho en appelant handleEchoRequest (). 
*/
OFCondition ScpPerso::handleIncomingCommand(T_DIMSE_Message *msg, const DcmPresentationContextInfo &info)
{
    OFCondition cond;
    switch(msg->CommandField)
    {
		case DIMSE_C_ECHO_RQ :
		{
		// Process C-ECHO request
		cond = handleECHORequest( msg->msg.CEchoRQ, info.presentationContextID );
		break;
		}// ende DIMSE_C_ECHO_RQ

		case DIMSE_C_STORE_RQ:
		{
			T_DIMSE_C_StoreRSP response;
			T_DIMSE_C_StoreRQ request = msg->msg.CStoreRQ;
			DcmDataset *statusDetail = NULL;

			T_ASC_PresentationContextID presID = info.presentationContextID;
			DcmDataset *dataObject = new DcmDataset();

			if (receiveDIMSEDataset(&presID, &dataObject,NULL,NULL).good())
			{
				if (dataObject != NULL)
				{
				//ON COMMENCE PAR DEFINIR LE NOM DU FICHIER QUI SERA STOCKER SUR LE DISQUE DUR
					OFString OFserieName;
					dataObject->findAndGetOFString(DCM_ProtocolName, OFserieName,0, true); if (OFserieName.c_str() == "" || OFserieName.c_str() == "NULL") dataObject->findAndGetOFString(DCM_SeriesDescription, OFserieName,0, true);
					QString serieName = OFserieName.c_str();
				//BVALUE
					bool bValueTrouvee = false;
					bool probAvecBValue = false;
					QString bValue = "";
					QString bValueName = "";
					if ( (serieName.contains(Outils::DIFF,Qt::CaseInsensitive)) && (!(serieName.contains(Outils::DDIFF,Qt::CaseInsensitive))) && (!(serieName.contains(Outils::ADC,Qt::CaseInsensitive))) )
					{
						bValue = getBValue(dataObject, false);
						if (bValue!="") bValueTrouvee = true;
						else 
						{
							bValue = "28011986t";
							probAvecBValue = true;
						}

						//La bValue peut être de deux aspects : *ep_b1000t or 500t
						if(bValue.contains("*ep_"))
						{
							bValueName = bValue.split("_")[1];
						}
						else bValueName = bValue;
											
					//TRAITEMENT MANUELLE POUR LA BVALUE - BESOIN CRUCIALE DE CORRIGER CA !!!!!!!!!!!!
						if ( (!(bValueName.contains("t"))) && (bValueName.contains("0")) && (!(bValueName.contains("1"))) && (!(bValueName.contains("5")))) bValueName = "0";
						else if ( (!(bValueName.contains("t"))) && (bValueName.contains("5")) && (!(bValueName.contains("0"))) && (!(bValueName.contains("1")))) bValueName = "500";
						else if ( (!(bValueName.contains("t"))) && (bValueName.contains("1")) && (!(bValueName.contains("0"))) && (!(bValueName.contains("5")))) bValueName = "1000";


						if (bValueName.startsWith("b")) bValueName.remove(0,1);
						if (!(bValueName.endsWith("t"))) bValueName.append("t");

						bValueName.append("_");
					}
					else bValueName = "";

				//INSTANCE NUMBER
					QString instanceNumber = getInstanceNumber(dataObject);
					if (instanceNumber!="") instanceNumber.append("_");
				
				//SLICE NUMBER
					QString sliceName = "IMAGE";
					
				//NOM DE LA COPIE
					QString copyName = bValueName+""+instanceNumber+""+sliceName;
					
				//E_TransferSyntax - SYNTAXE DE TRANSERT
					//OFString OFwriteXferUID;
					//dataObject->findAndGetOFString(DCM_TransferSyntaxUID, OFwriteXferUID);
					//E_TransferSyntax writeXfer = ;
					//QString add = OFwriteXferUID.c_str();QMessageBox::information(0,"",add);
					// determine the transfer syntax which shall be used to write the information to the file
					//E_TransferSyntax xfer = opt_writeTransferSyntax; if (xfer == EXS_Unknown) xfer = dataObject->getOriginalXfer();
					E_TransferSyntax writeXfer = dataObject->getOriginalXfer();


				//E_EncodingType - TYPE D'ENCODAGE
					OFString OFEncodingType;
					//dataObject->findAndGetOFString(DCM_EncodingType, OFEncodingType,0, true);
					E_EncodingType encodingType = EET_UndefinedLength;

				//E_GrpLenEncoding
					OFString OFgroupLength;
					//dataObject->findAndGetOFString(DCM_GroupeLenght, OFEncodingType,0, true);
					E_GrpLenEncoding groupLength = EGL_recalcGL;

				//E_PaddingEncoding
					OFString OFpadEncoding;
					//dataObject->findAndGetOFString(DCM_paddingEncoding, OFEncodingType,0, true);
					E_PaddingEncoding padEncoding = EPD_withoutPadding;//EPD_noChange;
					
				//padLength
					OFString OFpadLength;
					//dataObject->findAndGetOFString(DCM_paddingEncoding, OFEncodingType,0, true);
					Uint32 padLength = OFstatic_cast(Uint32, 0);//0;
				//subPadLength
					OFString OFsubPadLength;
					//dataObject->findAndGetOFString(DCM_subPadLegth, OFsubPadLength,0, true);
					Uint32 subPadLength = OFstatic_cast(Uint32, 0);//0;

					QString path = MedicTool2::pathLoadedSerie+"/"+copyName;
					/** save object to a DICOM file.
					 *  This method only supports DICOM objects stored as a dataset, i.e. without meta header.
					 *  Use DcmFileFormat::saveFile() to save files with meta header.
					 *  @param fileName name of the file to save
					 *  @param writeXfer transfer syntax used to write the data (EXS_Unknown means use current)
					 *  @param encodingType flag, specifying the encoding with undefined or explicit length
					 *  @param groupLength flag, specifying how to handle the group length tags
					 *  @param padEncoding flag, specifying how to handle the padding tags
					 *  @param padLength number of bytes used for the dataset padding (has to be an even number)
					 *  @param subPadLength number of bytes used for the item padding (has to be an even number)
					 *  @return status, EC_Normal if successful, an error code otherwise
					 */
					//dataObject->saveFile(path+".dcm",EXS_LittleEndianExplicit);//writeXfer,encodingType,groupLength,padEncoding,padLength,subPadLength);

					
					//DcmDataset *dataset = fileformat.getDataset();
					//dataset->putAndInsertString(DCM_SOPClassUID, UID_SecondaryCaptureImageStorage);
					//dataset->putAndInsertString(DCM_SOPInstanceUID, dcmGenerateUniqueIdentifier(uid, SITE_INSTANCE_UID_ROOT));
					//dataset->putAndInsertString(DCM_PatientName, "Doe^John");
					///* ... */
					//dataset->putAndInsertUint8Array(DCM_PixelData, pixelData, pixelLength);
					DcmFileFormat *fileformat = new DcmFileFormat(dataObject);
					OFCondition status = fileformat->saveFile(path, writeXfer, encodingType, groupLength, padEncoding, padLength, (OFTrue) ? EWM_fileformat : EWM_dataset);

					bzero((char*)&response, sizeof(response));
					response.DimseStatus = STATUS_Success;
					response.MessageIDBeingRespondedTo = request.MessageID;
					response.DataSetType = DIMSE_DATASET_NULL;
					strcpy(response.AffectedSOPClassUID, request.AffectedSOPClassUID);
					strcpy(response.AffectedSOPInstanceUID, request.AffectedSOPInstanceUID);
					response.opts = (O_STORE_AFFECTEDSOPCLASSUID | O_STORE_AFFECTEDSOPINSTANCEUID);
					if (request.opts & O_STORE_RQ_BLANK_PADDING) response.opts |= O_STORE_RSP_BLANK_PADDING;
					if (dcmPeerRequiresExactUIDCopy.get()) response.opts |= O_STORE_PEER_REQUIRES_EXACT_UID_COPY;

					OFCondition cond = sendSTOREResponse(presID, request, response, statusDetail);
					/*
					if( cond.bad() ) 
						QMessageBox::information(0,"","Impossible d'envoyer la réponse C-Store");
					else 
						QMessageBox::information(0,"","Response C-STORE envoyée avec succée");
					*/

				}
				else QMessageBox::information(0,"","Pas d'information recue");
			}
			else QMessageBox::information(0,"","Pas de dcmdataset.");
			break;
		}
		default:{
			// We cannot handle this kind of message. Note that the condition will be returned
			// and that the caller is responsible to end the association if desired.
			OFString tempStr;
			DCMNET_ERROR("Cannot handle this kind of DIMSE command (0x" << STD_NAMESPACE hex << STD_NAMESPACE setfill('0') << STD_NAMESPACE setw(4) << OFstatic_cast(unsigned int, msg->CommandField) << ")");
			DCMNET_DEBUG(DIMSE_dumpMessage(tempStr, *msg, DIMSE_INCOMING));
			cond = DIMSE_BADCOMMANDTYPE;
		}// Ende default
	}// Ende case
  return cond;
}
Respectueusement,
MitMal

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest