# HG changeset patch # User Sebastien Jodogne # Date 1610381544 -3600 # Node ID 02cb86d079661aaee98be5ffc1336581a8551052 # Parent 1e864138f0dae891cf5ab137cdc303bea1e03bc0 Allow images without "Per frame functional groups sequence" tag (0x5200,0x9230) diff -r 1e864138f0da -r 02cb86d07966 Framework/Inputs/DicomPyramidInstance.cpp --- a/Framework/Inputs/DicomPyramidInstance.cpp Wed Jan 06 18:10:07 2021 +0100 +++ b/Framework/Inputs/DicomPyramidInstance.cpp Mon Jan 11 17:12:24 2021 +0100 @@ -173,57 +173,85 @@ } size_t countFrames; - if (!reader.GetDataset().GetSequenceSize(countFrames, OrthancStone::DicomPath(DICOM_TAG_PER_FRAME_FUNCTIONAL_GROUPS_SEQUENCE))) - { - throw Orthanc::OrthancException(Orthanc::ErrorCode_BadFileFormat); - } - - if (countFrames != tmp) - { - LOG(ERROR) << "Mismatch between the number of frames in instance: " << instanceId; - throw Orthanc::OrthancException(Orthanc::ErrorCode_BadFileFormat); - } - - frames_.resize(countFrames); - - for (size_t i = 0; i < countFrames; i++) + if (reader.GetDataset().GetSequenceSize(countFrames, OrthancStone::DicomPath(DICOM_TAG_PER_FRAME_FUNCTIONAL_GROUPS_SEQUENCE))) { - DicomPath pathX(DICOM_TAG_PER_FRAME_FUNCTIONAL_GROUPS_SEQUENCE, i, - DICOM_TAG_PLANE_POSITION_SLIDE_SEQUENCE, 0, - DICOM_TAG_COLUMN_POSITION_IN_TOTAL_IMAGE_PIXEL_MATRIX); - - DicomPath pathY(DICOM_TAG_PER_FRAME_FUNCTIONAL_GROUPS_SEQUENCE, i, - DICOM_TAG_PLANE_POSITION_SLIDE_SEQUENCE, 0, - DICOM_TAG_ROW_POSITION_IN_TOTAL_IMAGE_PIXEL_MATRIX); - - int xx, yy; - if (!reader.GetIntegerValue(xx, pathX) || - !reader.GetIntegerValue(yy, pathY)) + if (countFrames != tmp) { - throw Orthanc::OrthancException(Orthanc::ErrorCode_InexistentTag); - } - - // "-1", because coordinates are shifted by 1 in DICOM - xx -= 1; - yy -= 1; - - unsigned int x = static_cast(xx); - unsigned int y = static_cast(yy); - - if (xx < 0 || - yy < 0 || - x % tileWidth_ != 0 || - y % tileHeight_ != 0 || - x >= totalWidth_ || - y >= totalHeight_) - { - LOG(ERROR) << "Frame " << i << " with unexpected tile location (" - << x << "," << y << ") in instance: " << instanceId; + LOG(ERROR) << "Mismatch between the number of frames in instance: " << instanceId; throw Orthanc::OrthancException(Orthanc::ErrorCode_BadFileFormat); } - frames_[i].first = x / tileWidth_; - frames_[i].second = y / tileHeight_; + frames_.resize(countFrames); + + for (size_t i = 0; i < countFrames; i++) + { + DicomPath pathX(DICOM_TAG_PER_FRAME_FUNCTIONAL_GROUPS_SEQUENCE, i, + DICOM_TAG_PLANE_POSITION_SLIDE_SEQUENCE, 0, + DICOM_TAG_COLUMN_POSITION_IN_TOTAL_IMAGE_PIXEL_MATRIX); + + DicomPath pathY(DICOM_TAG_PER_FRAME_FUNCTIONAL_GROUPS_SEQUENCE, i, + DICOM_TAG_PLANE_POSITION_SLIDE_SEQUENCE, 0, + DICOM_TAG_ROW_POSITION_IN_TOTAL_IMAGE_PIXEL_MATRIX); + + int xx, yy; + if (!reader.GetIntegerValue(xx, pathX) || + !reader.GetIntegerValue(yy, pathY)) + { + throw Orthanc::OrthancException(Orthanc::ErrorCode_InexistentTag); + } + + // "-1", because coordinates are shifted by 1 in DICOM + xx -= 1; + yy -= 1; + + unsigned int x = static_cast(xx); + unsigned int y = static_cast(yy); + + if (xx < 0 || + yy < 0 || + x % tileWidth_ != 0 || + y % tileHeight_ != 0 || + x >= totalWidth_ || + y >= totalHeight_) + { + LOG(ERROR) << "Frame " << i << " with unexpected tile location (" + << x << "," << y << ") in instance: " << instanceId; + throw Orthanc::OrthancException(Orthanc::ErrorCode_BadFileFormat); + } + + frames_[i].first = x / tileWidth_; + frames_[i].second = y / tileHeight_; + } + } + else + { + // No "Per frame functional groups sequence" tag. Assume regular grid. + frames_.resize(tmp); + + // Compute "ceiling(totalWidth_ / tileWidth_) + unsigned int w = totalWidth_ / tileWidth_; + if (totalWidth_ % tileWidth_ != 0) + { + w += 1; + } + + unsigned int h = totalHeight_ / tileHeight_; + if (totalHeight_ % tileHeight_ != 0) + { + h += 1; + } + + if (w * h != tmp) + { + LOG(ERROR) << "Mismatch between the number of frames in instance: " << instanceId; + throw Orthanc::OrthancException(Orthanc::ErrorCode_BadFileFormat); + } + + for (size_t i = 0; i < frames_.size(); i++) + { + frames_[i].first = i % w; + frames_[i].second = i / w; + } } } diff -r 1e864138f0da -r 02cb86d07966 NEWS --- a/NEWS Wed Jan 06 18:10:07 2021 +0100 +++ b/NEWS Mon Jan 11 17:12:24 2021 +0100 @@ -1,6 +1,7 @@ Pending changes in the mainline =============================== +* Allow images without "Per frame functional groups sequence" tag (0x5200,0x9230) * Support of dynamic linking against the system-wide Orthanc framework library