diff --git a/libsrc/Itk2DicomConverter.cpp b/libsrc/Itk2DicomConverter.cpp index 098d6c08..694cc9e4 100644 --- a/libsrc/Itk2DicomConverter.cpp +++ b/libsrc/Itk2DicomConverter.cpp @@ -109,6 +109,22 @@ namespace dcmqi { delete pixmsr; } + // Iterate over the files and labels available in each file, create a segment for each label, + // initialize segment frames and add to the document + + OFString seriesInstanceUID, classUID; + set instanceUIDs; + + IODCommonInstanceReferenceModule &commref = segdoc->getCommonInstanceReference(); + OFVector &refseries = commref.getReferencedSeriesItems(); + + IODSeriesAndInstanceReferenceMacro::ReferencedSeriesItem* refseriesItem = new IODSeriesAndInstanceReferenceMacro::ReferencedSeriesItem; + + OFVector &refinstances = refseriesItem->getReferencedInstanceItems(); + + CHECK_COND(dcmDatasets[0]->findAndGetOFString(DCM_SeriesInstanceUID, seriesInstanceUID)); + CHECK_COND(refseriesItem->setSeriesInstanceUID(seriesInstanceUID)); + // Shared FGs: DerivationImageSequence if(!referencesGeometryCheck && dcmDatasets.size() > 1){ FGDerivationImage *fgder = new FGDerivationImage(); @@ -122,26 +138,25 @@ namespace dcmqi { derimgItem->addSourceImageItems(dcmDatasets, CodeSequenceMacro(code_seg.CodeValue,code_seg.CodingSchemeDesignator, code_seg.CodeMeaning), srcimgItems, OFTrue /*skip file errors */); + for(size_t src_image_cnt=0;src_image_cntgetImageSOPInstanceReference(); + OFString instanceUID; + CHECK_COND(instRef.getReferencedSOPClassUID(classUID)); + CHECK_COND(instRef.getReferencedSOPInstanceUID(instanceUID)); + + if(instanceUIDs.find(instanceUID) == instanceUIDs.end()){ + SOPInstanceReferenceMacro *refinstancesItem = new SOPInstanceReferenceMacro(); + CHECK_COND(refinstancesItem->setReferencedSOPClassUID(classUID)); + CHECK_COND(refinstancesItem->setReferencedSOPInstanceUID(instanceUID)); + refinstances.push_back(refinstancesItem); + instanceUIDs.insert(instanceUID); + } + } CHECK_COND(segdoc->addForAllFrames(*fgder)); delete fgder; } - // Iterate over the files and labels available in each file, create a segment for each label, - // initialize segment frames and add to the document - - OFString seriesInstanceUID, classUID; - set instanceUIDs; - - IODCommonInstanceReferenceModule &commref = segdoc->getCommonInstanceReference(); - OFVector &refseries = commref.getReferencedSeriesItems(); - - IODSeriesAndInstanceReferenceMacro::ReferencedSeriesItem* refseriesItem = new IODSeriesAndInstanceReferenceMacro::ReferencedSeriesItem; - - OFVector &refinstances = refseriesItem->getReferencedInstanceItems(); - - CHECK_COND(dcmDatasets[0]->findAndGetOFString(DCM_SeriesInstanceUID, seriesInstanceUID)); - CHECK_COND(refseriesItem->setSeriesInstanceUID(seriesInstanceUID)); - int uidfound = 0, uidnotfound = 0; Uint8 *frameData = new Uint8[frameSize];