Adding sequences to DcmDataset

All other questions regarding DCMTK

Moderator: Moderator Team

Post Reply
Message
Author
nilssoderman
Posts: 2
Joined: Thu, 2004-12-09, 21:11

Adding sequences to DcmDataset

#1 Post by nilssoderman » Thu, 2004-12-09, 21:40

Hello!
I am trying to make a DcmDataset containing sequences. I am reusing some revised code in DcmTK (with error code removed):
Where am I wrong??? Please!

DcmElement * delem = NULL;
DcmSequenceOfItems * dseq = NULL;
DcmItem * ditem = NULL;
DcmItem * dset = NULL;
int idx;
DcmDataset * imageDataSet = new DcmDataset();

bzero ((char*)&request, sizeof ( request ));
bzero ((char*)&response, sizeof ( response ));
//First construct the message to report commit result
request.CommandField = DIMSE_N_EVENT_REPORT_RQ;
request.msg.NEventReportRQ.MessageID = 1; /* M */
sprintf ( request.msg.NEventReportRQ.AffectedSOPClassUID,
"%s", UID_StorageCommitmentPushModelSOPClass ); /* M */
sprintf ( request.msg.NEventReportRQ.AffectedSOPInstanceUID,
"%s", UID_StorageCommitmentPushModelSOPInstance ); /* M */
request.msg.NEventReportRQ.DataSetType = DIMSE_DATASET_NULL; /* M */
request.msg.NEventReportRQ.EventTypeID = 1; /* M */

dset = new DcmItem ();
for ( idx = 0; idx < UIDCount; idx++ )//UIDCount=numberofsequences
{
ditem = new DcmItem ();
if ( ditem )
{
dseq = new DcmSequenceOfItems ( DCM_ReferencedInstanceSequence );
if ( dseq )
{
delem = new DcmUniqueIdentifier ( DCM_ReferencedSOPClassUID );
if ( delem )
{
cond = delem->putOFStringArray ( CommittedImagesArray [ idx ].RefSOPClassUID );}
ditem->insert ( delem, OFTrue /*replaceOld */ );
};
delem = new DcmUniqueIdentifier ( DCM_ReferencedSOPInstanceUID );
if ( delem )
{
cond = delem->putOFStringArray ( CommittedImagesArray [ idx ].RefSOPClassUID );
ditem->insert ( delem, OFTrue /*replaceOld */ );
}
delem = new DcmUnsignedShort ( DCM_FailureReason );
if ( delem )
{
cond = delem->putUint16 ( CommittedImagesArray [ idx ].FailureReason );
ditem->insert ( delem, OFTrue /*replaceOld */ );
}
cond = dseq->insert ( ditem, OFFalse );
cond = dset->insert ( dseq, OFFalse );

}
}
cond = imageDataSet->insert ( ( DcmSequenceOfItems * )dset, OFFalse );
DcmFileFormat * FFormat = new DcmFileFormat ( imageDataSet ) ;
cond =
FFormat->saveFile( "C:/testfile.dcm",
EXS_LittleEndianExplicit,
EET_ExplicitLength,
EGL_recalcGL,
EPD_withoutPadding,
0,
0,
true );

I get an empty file!

Marco Eichelberg
OFFIS DICOM Team
OFFIS DICOM Team
Posts: 1280
Joined: Tue, 2004-11-02, 17:22
Location: Oldenburg, Germany
Contact:

#2 Post by Marco Eichelberg » Mon, 2004-12-13, 10:48

DcmItem *dset must not be casted to DcmSequenceOfElements since a DcmItem is not a sequence. You should directly insert into imageDataSet, i.e. replace all calls to dset->insert by imageDataSet->insert.

nilssoderman
Posts: 2
Joined: Thu, 2004-12-09, 21:11

Danke Schön, Marco.

#3 Post by nilssoderman » Mon, 2004-12-13, 13:56

Thanks for answering me! I thought there were no solution to this when nobody answered...
I tried your suggestion earlier, but when inserting the second, third etc. sequence I get a condition error... And, yes I insert new sequences each time. (I am sorry I did not understand how to put in readable code last time!)

Code: Select all

  DcmElement             *    delem = NULL;
  DcmSequenceOfItems     *    dseq = NULL;
  DcmItem                *    ditem = NULL;
  int                         idx;
  DcmDataset                * imageDataSet = new DcmDataset();
	char	      		            AppendString [ 256 ];

  sprintf ( AppendString, "Coming into SendEventReport\n" );
  Append2File ( OwnName, AppendString );

  bzero ((char*)&request, sizeof ( request ));
  bzero ((char*)&response, sizeof ( response ));
  //First construct the message to report commit result
  request.CommandField = DIMSE_N_EVENT_REPORT_RQ;
  request.msg.NEventReportRQ.MessageID = 1;    /* M */
  sprintf ( request.msg.NEventReportRQ.AffectedSOPClassUID, 
    "%s", UID_StorageCommitmentPushModelSOPClass );    /* M */
  sprintf ( request.msg.NEventReportRQ.AffectedSOPInstanceUID, 
    "%s", UID_StorageCommitmentPushModelSOPInstance );    /* M */
  request.msg.NEventReportRQ.DataSetType = DIMSE_DATASET_NULL;    /* M */
  request.msg.NEventReportRQ.EventTypeID = 1;    /* M */

  for ( idx = 0; idx < UIDCount; idx++ )
  {
    ditem = new DcmItem ();
    if ( ditem )
    {
      dseq = new DcmSequenceOfItems ( DCM_ReferencedInstanceSequence );
      if ( dseq )
      {
        delem = new DcmUniqueIdentifier ( DCM_ReferencedSOPClassUID );
        if ( delem )
        {
          cond = delem->putOFStringArray ( CommittedImagesArray [ idx ].RefSOPClassUID );
          if ( cond != EC_Normal )
          {
            sprintf ( AppendString, "Error: dcmInsertString: cannot put string\n" );
            Append2File ( OwnName, AppendString );
            return cond;
          }
          ditem->insert ( delem, OFTrue /*replaceOld */  );
        }
        else
          result = EC_MemoryExhausted;
        delem = new DcmUniqueIdentifier ( DCM_ReferencedSOPInstanceUID );
        if ( delem )
        {
          cond = delem->putOFStringArray ( CommittedImagesArray [ idx ].RefSOPClassUID );
          if ( cond != EC_Normal )
          {
            sprintf ( AppendString, "Error: dcmInsertString: cannot put string\n" );
            Append2File ( OwnName, AppendString );
            return cond;
          }
          ditem->insert ( delem, OFTrue /*replaceOld */  );
        }
        else
          result = EC_MemoryExhausted;
        delem = new DcmUnsignedShort ( DCM_FailureReason );
        if ( delem )
        {
          cond = delem->putUint16 ( CommittedImagesArray [ idx ].FailureReason );
          if ( cond != EC_Normal )
          {
            sprintf ( AppendString, "Error: putUint16: cannot put WORD into data stream\n" );
            Append2File ( OwnName, AppendString );
            return cond;
          }
          ditem->insert ( delem, OFTrue /*replaceOld */  );
        }
        else
          result = EC_MemoryExhausted;

                  
        
        if ( result == EC_Normal )
        {
          cond = dseq->insert ( ditem, OFFalse );
          if ( cond != EC_Normal )
          {
            sprintf ( AppendString, "Error: cannot insert data into dataset\n" );
            Append2File ( OwnName, AppendString );
            return cond;
          }
          cond = imageDataSet->insert ( dseq, OFFalse );
          if ( cond != EC_Normal )
          {
            sprintf ( AppendString, "Error: cannot insert data into dataset\n" );
            Append2File ( OwnName, AppendString );
            return cond;
          }
        }
        else
        {
          // out of memory during creation of sequence contents.
          delete                  dseq;
          delete                  ditem;

          result = EC_MemoryExhausted;
        }
      }
      else
      {
        // could allocate item but not sequence. Bail out.
        delete                  ditem;
        result = EC_MemoryExhausted;
      }
    }
    else
      result = EC_MemoryExhausted;
  };//  for ( i = 0; i < UIDCount; i++ )

  DcmFileFormat * FFormat = new DcmFileFormat ( imageDataSet )     ;

  // store file either with meta header or as pure dataset, to analyze for errors
  cond =
    FFormat->saveFile( "C:/testfile.dcm", 
                       EXS_LittleEndianImplicit,
                       EET_ExplicitLength,
                       EGL_recalcGL,
                       EPD_withoutPadding,
                       0,
                       0,
                       true );

Why error second time, not first?? I am wrong, but where?

Marco Eichelberg
OFFIS DICOM Team
OFFIS DICOM Team
Posts: 1280
Joined: Tue, 2004-11-02, 17:22
Location: Oldenburg, Germany
Contact:

#4 Post by Marco Eichelberg » Mon, 2004-12-13, 14:32

You are trying to insert multiple sequences with the same attribute tag! Remember that each tag can exist not more than once in each DICOM dataset (where each sequence item is considered as a different dataset).
If you want to have multiple entries in the ReferencedInstanceSequence, you need to add multiple items into the (single) sequence, not multiple sequences into the main dataset.

Post Reply

Who is online

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