changeset 168:d3aea0af03e1

attempt to fix issue #139
author Sebastien Jodogne <s.jodogne@gmail.com>
date Fri, 12 Jul 2019 12:51:17 +0200
parents 605247fc8758
children de783db2a7c3
files Applications/Dicomizer.cpp Framework/Outputs/DicomPyramidWriter.cpp Framework/Outputs/MultiframeDicomWriter.h
diffstat 3 files changed, 61 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/Applications/Dicomizer.cpp	Fri Jul 12 12:00:31 2019 +0200
+++ b/Applications/Dicomizer.cpp	Fri Jul 12 12:51:17 2019 +0200
@@ -390,6 +390,7 @@
   {
     // Construct tag "Shared Functional Groups Sequence" (5200,9229)
 
+#if 1
     // In the 2 lines below, remember to switch X/Y when going from physical to pixel coordinates!
     float spacingX = volume.GetWidth() / static_cast<float>(source.GetLevelHeight(0));
     float spacingY = volume.GetHeight() / static_cast<float>(source.GetLevelWidth(0));
@@ -420,6 +421,23 @@
     {
       throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError);
     }
+#else
+    std::auto_ptr<DcmItem> item(new DcmItem);
+
+    std::auto_ptr<DcmItem> item3(new DcmItem);
+    OrthancWSI::DicomToolbox::SetStringTag(*item3, DCM_OpticalPathIdentifier, opticalPathId);
+
+    std::auto_ptr<DcmSequenceOfItems> sequence(new DcmSequenceOfItems(DCM_SharedFunctionalGroupsSequence));
+    std::auto_ptr<DcmSequenceOfItems> sequence3(new DcmSequenceOfItems(DCM_OpticalPathIdentificationSequence));
+
+    if (!sequence3->insert(item3.release(), false, false).good() ||
+        !item->insert(sequence3.release(), false, false).good() ||
+        !sequence->insert(item.release(), false, false).good() ||
+        !dataset.insert(sequence.release(), true /* replace */, false).good())
+    {
+      throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError);
+    }
+#endif
   }
 }
 
--- a/Framework/Outputs/DicomPyramidWriter.cpp	Fri Jul 12 12:00:31 2019 +0200
+++ b/Framework/Outputs/DicomPyramidWriter.cpp	Fri Jul 12 12:51:17 2019 +0200
@@ -142,6 +142,44 @@
           (dataset_, GetImageCompression(), GetPixelFormat(), level.width_, level.height_, 
            GetTileWidth(), GetTileHeight(), photometric_);
         writers_[z] = writer;
+
+#if 0
+        {
+          // Fix issue 139: The PixelSpacing information changes at each level
+          // https://bitbucket.org/sjodogne/orthanc/issues/139/orthancwsidicomizer-pixelspacing
+
+          // In the 2 lines below, remember to switch X/Y when going from physical to pixel coordinates!
+          float spacingX = volume_.GetWidth() / static_cast<float>(level.height_);
+          float spacingY = volume_.GetHeight() / static_cast<float>(level.width_);
+
+          std::string spacing = (boost::lexical_cast<std::string>(spacingX) + '\\' +
+                                 boost::lexical_cast<std::string>(spacingY));
+
+          std::auto_ptr<DcmItem> item(new DcmItem);
+
+          std::auto_ptr<DcmItem> item2(new DcmItem);
+          OrthancWSI::DicomToolbox::SetStringTag(*item2, DCM_SliceThickness, 
+                                                 boost::lexical_cast<std::string>(volume_.GetDepth()));
+          OrthancWSI::DicomToolbox::SetStringTag(*item2, DCM_PixelSpacing, spacing);
+
+          std::auto_ptr<DcmSequenceOfItems> sequence2(new DcmSequenceOfItems(DCM_PixelMeasuresSequence));
+          if (!sequence2->insert(item2.release(), false, false).good())
+          {
+            throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError);
+          }
+
+          DcmSequenceOfItems* sequence = NULL;
+          if (!writer->GetSharedTags().findAndGetSequence(DCM_SharedFunctionalGroupsSequence, sequence).good() ||
+              sequence == NULL ||
+              sequence->card() != 1 ||
+              sequence->getItem(0) == NULL ||
+              !sequence->getItem(0)->insert(sequence2.release(), false, false).good())
+          {
+            // This sequence should have been created by "SetupDimension()" in Dicomizer.cpp
+            throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError);
+          }
+        }
+#endif
       }
 
       std::auto_ptr<DcmItem> functionalGroup(CreateFunctionalGroup(writer->GetFramesCount() + 1,
--- a/Framework/Outputs/MultiframeDicomWriter.h	Fri Jul 12 12:00:31 2019 +0200
+++ b/Framework/Outputs/MultiframeDicomWriter.h	Fri Jul 12 12:51:17 2019 +0200
@@ -91,5 +91,10 @@
     {
       return height_;
     }
+
+    DcmDataset& GetSharedTags()
+    {
+      return sharedTags_;
+    }
   };
 }