changeset 502:ee33c7d0cda0 laaw

laaw runs correctly on the c++ api
author Sebastien Jodogne <s.jodogne@gmail.com>
date Thu, 18 Jul 2013 09:32:03 +0200
parents ec19da4a1fe7
children 50d9660f960c
files OrthancCppClient/Series.cpp OrthancCppClient/Series.h Resources/Samples/OrthancCppClient/Vtk/main.cpp
diffstat 3 files changed, 58 insertions(+), 16 deletions(-) [+]
line wrap: on
line diff
--- a/OrthancCppClient/Series.cpp	Wed Jul 17 22:31:22 2013 +0200
+++ b/OrthancCppClient/Series.cpp	Thu Jul 18 09:32:03 2013 +0200
@@ -174,13 +174,17 @@
         return true;
       }
 
+      Instance& i1 = GetInstance(0);
+
       for (unsigned int i = 0; i < GetInstanceCount(); i++)
       {
-        if (GetInstance(0).GetTagAsString("Columns") != GetInstance(i).GetTagAsString("Columns") ||
-            GetInstance(0).GetTagAsString("Rows") != GetInstance(i).GetTagAsString("Rows") ||
-            GetInstance(0).GetTagAsString("ImageOrientationPatient") != GetInstance(i).GetTagAsString("ImageOrientationPatient") ||
-            GetInstance(0).GetTagAsString("SliceThickness") != GetInstance(i).GetTagAsString("SliceThickness") ||
-            GetInstance(0).GetTagAsString("PixelSpacing") != GetInstance(i).GetTagAsString("PixelSpacing"))
+        Instance& i2 = GetInstance(1);
+
+        if (std::string(i1.GetTagAsString("Columns")) != std::string(i2.GetTagAsString("Columns")) ||
+            std::string(i1.GetTagAsString("Rows")) != std::string(i2.GetTagAsString("Rows")) ||
+            std::string(i1.GetTagAsString("ImageOrientationPatient")) != std::string(i2.GetTagAsString("ImageOrientationPatient")) ||
+            std::string(i1.GetTagAsString("SliceThickness")) != std::string(i2.GetTagAsString("SliceThickness")) ||
+            std::string(i1.GetTagAsString("PixelSpacing")) != std::string(i2.GetTagAsString("PixelSpacing")))
         {
           return false;
         }              
@@ -229,6 +233,7 @@
     ReadSeries();
     status_ = Status3DImage_NotTested;
     url_ = std::string(connection_.GetOrthancUrl()) + "/series/" + id_;
+    isVoxelSizeRead_ = false;
 
     instances_.SetThreadCount(connection.GetThreadCount());
   }
@@ -274,15 +279,21 @@
       return GetInstance(0).GetTagAsInt("Rows");
   }
 
-  void Series::GetVoxelSize(float& sizeX, float& sizeY, float& sizeZ)
+  void Series::LoadVoxelSize()
   {
+    if (isVoxelSizeRead_)
+    {
+      return;
+    }
+
     Check3DImage();
 
     if (GetInstanceCount() == 0)
     {
-      sizeX = 0;
-      sizeY = 0;
-      sizeZ = 0;
+      // Empty image, use some default value
+      voxelSizeX_ = 1;
+      voxelSizeY_ = 1;
+      voxelSizeZ_ = 1;
     }
     else
     {
@@ -294,15 +305,17 @@
         std::string sy = s.substr(0, pos);
         std::string sx = s.substr(pos + 1);
 
-        sizeX = boost::lexical_cast<float>(sx);
-        sizeY = boost::lexical_cast<float>(sy);
-        sizeZ = GetInstance(0).GetTagAsFloat("SliceThickness");
+        voxelSizeX_ = boost::lexical_cast<float>(sx);
+        voxelSizeY_ = boost::lexical_cast<float>(sy);
+        voxelSizeZ_ = GetInstance(0).GetTagAsFloat("SliceThickness");
       }
       catch (boost::bad_lexical_cast)
       {
         throw Orthanc::OrthancException(Orthanc::ErrorCode_NotImplemented);
       }
     }
+
+    isVoxelSizeRead_ = true;
   }
 
 
@@ -426,4 +439,22 @@
     }
   }
 
+  float Series::GetVoxelSizeX()
+  {
+    LoadVoxelSize();
+    return voxelSizeX_;
+  }
+
+  float Series::GetVoxelSizeY()
+  {
+    LoadVoxelSize();
+    return voxelSizeY_;
+  }
+
+  float Series::GetVoxelSizeZ()
+  {
+    LoadVoxelSize();
+    return voxelSizeZ_;
+  }
+
 }
--- a/OrthancCppClient/Series.h	Wed Jul 17 22:31:22 2013 +0200
+++ b/OrthancCppClient/Series.h	Thu Jul 18 09:32:03 2013 +0200
@@ -56,6 +56,11 @@
     Json::Value series_;
     Orthanc::ArrayFilledByThreads  instances_;
     Status3DImage status_;
+
+    bool isVoxelSizeRead_;
+    float voxelSizeX_;
+    float voxelSizeY_;
+    float voxelSizeZ_;
   
     void Check3DImage();
 
@@ -76,6 +81,8 @@
                      size_t stackStride,
                      Orthanc::ThreadedCommandProcessor::IListener* listener);
 
+    void LoadVoxelSize();  
+
   public:
     Series(const OrthancConnection& connection,
            const char* id);
@@ -105,7 +112,11 @@
 
     uint32_t GetHeight();
 
-    void GetVoxelSize(float& sizeX, float& sizeY, float& sizeZ);  
+    float GetVoxelSizeX();
+
+    float GetVoxelSizeY();
+
+    float GetVoxelSizeZ();
 
     const char* GetMainDicomTag(const char* tag, 
                                 const char* defaultValue) const;
--- a/Resources/Samples/OrthancCppClient/Vtk/main.cpp	Wed Jul 17 22:31:22 2013 +0200
+++ b/Resources/Samples/OrthancCppClient/Vtk/main.cpp	Thu Jul 18 09:32:03 2013 +0200
@@ -88,9 +88,9 @@
                        2 * series.GetWidth(), 2 * series.GetHeight() * series.GetWidth(), listener);
   }
 
-  float sx, sy, sz;
-  series.GetVoxelSize(sx, sy, sz);
-  image->SetSpacing(sx, sy, sz);
+  image->SetSpacing(series.GetVoxelSizeX(), 
+                    series.GetVoxelSizeY(), 
+                    series.GetVoxelSizeZ());
 
 
   /**