changeset 392:d87fe075d31b

to graveyard
author Sebastien Jodogne <s.jodogne@gmail.com>
date Fri, 09 Nov 2018 17:59:35 +0100
parents 021480604c92
children e7a494bdd956
files Applications/Samples/SingleFrameEditorApplication.h Framework/Layers/ReferenceLineFactory.cpp Framework/Layers/ReferenceLineFactory.h Framework/Toolbox/LinearAlgebra.cpp Resources/CMake/OrthancStoneConfiguration.cmake Resources/Graveyard/ReferenceLineFactory.cpp Resources/Graveyard/ReferenceLineFactory.h
diffstat 7 files changed, 256 insertions(+), 248 deletions(-) [+]
line wrap: on
line diff
--- a/Applications/Samples/SingleFrameEditorApplication.h	Fri Nov 09 17:41:46 2018 +0100
+++ b/Applications/Samples/SingleFrameEditorApplication.h	Fri Nov 09 17:59:35 2018 +0100
@@ -47,37 +47,6 @@
 
 namespace OrthancStone
 {
-  static Matrix CreateOffsetMatrix(double dx,
-                                   double dy)
-  {
-    Matrix m = LinearAlgebra::IdentityMatrix(3);
-    m(0, 2) = dx;
-    m(1, 2) = dy;
-    return m;
-  }
-      
-
-  static Matrix CreateScalingMatrix(double sx,
-                                    double sy)
-  {
-    Matrix m = LinearAlgebra::IdentityMatrix(3);
-    m(0, 0) = sx;
-    m(1, 1) = sy;
-    return m;
-  }
-      
-
-  static Matrix CreateRotationMatrix(double angle)
-  {
-    Matrix m;
-    const double v[] = { cos(angle), -sin(angle), 0,
-                         sin(angle), cos(angle), 0,
-                         0, 0, 1 };
-    LinearAlgebra::FillMatrix(m, 3, 3, v);
-    return m;
-  }
-      
-
   class BitmapStack :
     public IObserver,
     public IObservable
@@ -835,6 +804,37 @@
     
 
   private:
+    static Matrix CreateOffsetMatrix(double dx,
+                                     double dy)
+    {
+      Matrix m = LinearAlgebra::IdentityMatrix(3);
+      m(0, 2) = dx;
+      m(1, 2) = dy;
+      return m;
+    }
+      
+
+    static Matrix CreateScalingMatrix(double sx,
+                                      double sy)
+    {
+      Matrix m = LinearAlgebra::IdentityMatrix(3);
+      m(0, 0) = sx;
+      m(1, 1) = sy;
+      return m;
+    }
+      
+
+    static Matrix CreateRotationMatrix(double angle)
+    {
+      Matrix m;
+      const double v[] = { cos(angle), -sin(angle), 0,
+                           sin(angle), cos(angle), 0,
+                           0, 0, 1 };
+      LinearAlgebra::FillMatrix(m, 3, 3, v);
+      return m;
+    }
+      
+
     class DicomBitmap : public Bitmap
     {
     private:
--- a/Framework/Layers/ReferenceLineFactory.cpp	Fri Nov 09 17:41:46 2018 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,137 +0,0 @@
-/**
- * Stone of Orthanc
- * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
- * Department, University Hospital of Liege, Belgium
- * Copyright (C) 2017-2018 Osimis S.A., Belgium
- *
- * This program is free software: you can redistribute it and/or
- * modify it under the terms of the GNU Affero General Public License
- * as published by the Free Software Foundation, either version 3 of
- * the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Affero General Public License for more details.
- * 
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- **/
-
-
-#include "ReferenceLineFactory.h"
-
-#include "LineLayerRenderer.h"
-
-namespace OrthancStone
-{
-  ReferenceLineFactory::ReferenceLineFactory(SliceViewerWidget& owner,
-                                             SliceViewerWidget& sibling) :
-    owner_(owner),
-    sibling_(sibling),
-    hasLayerIndex_(false)
-  {
-    style_.SetColor(0, 255, 0);
-    slice_ = sibling.GetSlice();
-    sibling_.Register(*this);
-  }
-
-
-  void ReferenceLineFactory::NotifySliceChange(const SliceViewerWidget& source,
-                                               const SliceGeometry& slice)
-  {
-    if (&source == &sibling_)
-    {
-      SetSlice(slice);
-    }
-  }
-
-
-  void ReferenceLineFactory::SetLayerIndex(size_t layerIndex)
-  {
-    hasLayerIndex_ = true;
-    layerIndex_ = layerIndex;
-  }
-
-
-  void ReferenceLineFactory::SetStyle(const RenderStyle& style)
-  {
-    style_ = style;
-  }
-
-
-  RenderStyle ReferenceLineFactory::GetRenderStyle()
-  {
-    return style_;
-  }
-
-
-  void ReferenceLineFactory::SetSlice(const SliceGeometry& slice)
-  {
-    slice_ = slice;
-
-    if (hasLayerIndex_)
-    {
-      owner_.InvalidateLayer(layerIndex_);
-    }
-  }
-
-
-  ILayerRenderer* ReferenceLineFactory::CreateLayerRenderer(const SliceGeometry& viewportSlice)
-  {
-    Vector p, d;
-
-    // Compute the line of intersection between the two slices
-    if (!GeometryToolbox::IntersectTwoPlanes(p, d, 
-                                             slice_.GetOrigin(), slice_.GetNormal(),
-                                             viewportSlice.GetOrigin(), viewportSlice.GetNormal()))
-    {
-      // The two slice are parallel, don't try and display the intersection
-      return NULL;
-    }
-
-    double x1, y1, x2, y2;
-    viewportSlice.ProjectPoint(x1, y1, p);
-    viewportSlice.ProjectPoint(x2, y2, p + 1000.0 * d);
-
-    double sx1, sy1, sx2, sy2;
-    owner_.GetView().GetSceneExtent(sx1, sy1, sx2, sy2);
-        
-    if (GeometryToolbox::ClipLineToRectangle(x1, y1, x2, y2, 
-                                             x1, y1, x2, y2,
-                                             sx1, sy1, sx2, sy2))
-    {
-      std::auto_ptr<ILayerRenderer> layer(new LineLayerRenderer(x1, y1, x2, y2));
-      layer->SetLayerStyle(style_);
-      return layer.release();
-    }
-    else
-    {
-      // Parallel slices
-      return NULL;
-    }
-  }
-
-
-  ISliceableVolume& ReferenceLineFactory::GetSourceVolume() const
-  {
-    throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError);
-  }
-
-
-  void ReferenceLineFactory::Configure(SliceViewerWidget& a,
-                                       SliceViewerWidget& b)
-  {
-    {
-      size_t layerIndex;
-      ILayerRendererFactory& factory = a.AddLayer(layerIndex, new ReferenceLineFactory(a, b));
-      dynamic_cast<ReferenceLineFactory&>(factory).SetLayerIndex(layerIndex);
-    }
-
-    {
-      size_t layerIndex;
-      ILayerRendererFactory& factory = b.AddLayer(layerIndex, new ReferenceLineFactory(b, a));
-      dynamic_cast<ReferenceLineFactory&>(factory).SetLayerIndex(layerIndex);
-    }
-  }
-}
--- a/Framework/Layers/ReferenceLineFactory.h	Fri Nov 09 17:41:46 2018 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,77 +0,0 @@
-/**
- * Stone of Orthanc
- * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
- * Department, University Hospital of Liege, Belgium
- * Copyright (C) 2017-2018 Osimis S.A., Belgium
- *
- * This program is free software: you can redistribute it and/or
- * modify it under the terms of the GNU Affero General Public License
- * as published by the Free Software Foundation, either version 3 of
- * the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Affero General Public License for more details.
- * 
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- **/
-
-
-#pragma once
-
-#include "../Widgets/SliceViewerWidget.h"
-
-namespace OrthancStone
-{
-  class ReferenceLineFactory : 
-    public ILayerRendererFactory,
-    public SliceViewerWidget::ISliceObserver
-  {
-  private:
-    SliceViewerWidget&   owner_;
-    SliceViewerWidget&   sibling_;
-    SliceGeometry        slice_;
-    RenderStyle          style_;
-    bool                 hasLayerIndex_;
-    size_t               layerIndex_;
-
-      
-  public:
-    ReferenceLineFactory(SliceViewerWidget& owner,
-                         SliceViewerWidget& sibling);
-
-    virtual void NotifySliceChange(const SliceViewerWidget& source,
-                                   const SliceGeometry& slice);
-
-    void SetLayerIndex(size_t layerIndex);
-
-    void SetStyle(const RenderStyle& style);
-
-    RenderStyle GetRenderStyle();
-
-    void SetSlice(const SliceGeometry& slice);
-
-    virtual bool GetExtent(double& x1,
-                           double& y1,
-                           double& x2,
-                           double& y2,
-                           const SliceGeometry& viewportSlice)
-    {
-      return false;
-    }
-
-    virtual ILayerRenderer* CreateLayerRenderer(const SliceGeometry& viewportSlice);
-
-    virtual bool HasSourceVolume() const
-    {
-      return false;
-    }
-
-    virtual ISliceableVolume& GetSourceVolume() const;
-
-    static void Configure(SliceViewerWidget& a,
-                          SliceViewerWidget& b);
-  };
-}
--- a/Framework/Toolbox/LinearAlgebra.cpp	Fri Nov 09 17:41:46 2018 +0100
+++ b/Framework/Toolbox/LinearAlgebra.cpp	Fri Nov 09 17:59:35 2018 +0100
@@ -206,9 +206,15 @@
     {
       // https://en.wikipedia.org/wiki/Orthogonal_matrix
 
+      if (q.size1() != q.size2())
+      {
+        LOG(ERROR) << "An orthogonal matrix must be squared";
+        throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange);
+      }
+
       using namespace boost::numeric::ublas;
 
-      const Matrix check = prod(trans(q), q) - identity_matrix<double>(3);
+      const Matrix check = prod(trans(q), q) - identity_matrix<double>(q.size1());
 
       type_traits<double>::real_type norm = norm_inf(check);
 
@@ -522,7 +528,10 @@
     void CreateSkewSymmetric(Matrix& s,
                              const Vector& v)
     {
-      assert(v.size() == 3);
+      if (v.size() != 3)
+      {
+        throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange);
+      }
 
       s.resize(3, 3);
       s(0,0) = 0;
--- a/Resources/CMake/OrthancStoneConfiguration.cmake	Fri Nov 09 17:41:46 2018 +0100
+++ b/Resources/CMake/OrthancStoneConfiguration.cmake	Fri Nov 09 17:59:35 2018 +0100
@@ -233,7 +233,6 @@
 
 list(APPEND ORTHANC_STONE_SOURCES
   #${ORTHANC_STONE_ROOT}/Framework/Layers/SeriesFrameRendererFactory.cpp
-  #${ORTHANC_STONE_ROOT}/Framework/Layers/ReferenceLineFactory.cpp
   #${ORTHANC_STONE_ROOT}/Framework/Layers/SingleFrameRendererFactory.cpp
 
   ${ORTHANC_STONE_ROOT}/Framework/Layers/CircleMeasureTracker.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Resources/Graveyard/ReferenceLineFactory.cpp	Fri Nov 09 17:59:35 2018 +0100
@@ -0,0 +1,137 @@
+/**
+ * Stone of Orthanc
+ * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
+ * Department, University Hospital of Liege, Belgium
+ * Copyright (C) 2017-2018 Osimis S.A., Belgium
+ *
+ * This program is free software: you can redistribute it and/or
+ * modify it under the terms of the GNU Affero General Public License
+ * as published by the Free Software Foundation, either version 3 of
+ * the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Affero General Public License for more details.
+ * 
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ **/
+
+
+#include "ReferenceLineFactory.h"
+
+#include "LineLayerRenderer.h"
+
+namespace OrthancStone
+{
+  ReferenceLineFactory::ReferenceLineFactory(SliceViewerWidget& owner,
+                                             SliceViewerWidget& sibling) :
+    owner_(owner),
+    sibling_(sibling),
+    hasLayerIndex_(false)
+  {
+    style_.SetColor(0, 255, 0);
+    slice_ = sibling.GetSlice();
+    sibling_.Register(*this);
+  }
+
+
+  void ReferenceLineFactory::NotifySliceChange(const SliceViewerWidget& source,
+                                               const SliceGeometry& slice)
+  {
+    if (&source == &sibling_)
+    {
+      SetSlice(slice);
+    }
+  }
+
+
+  void ReferenceLineFactory::SetLayerIndex(size_t layerIndex)
+  {
+    hasLayerIndex_ = true;
+    layerIndex_ = layerIndex;
+  }
+
+
+  void ReferenceLineFactory::SetStyle(const RenderStyle& style)
+  {
+    style_ = style;
+  }
+
+
+  RenderStyle ReferenceLineFactory::GetRenderStyle()
+  {
+    return style_;
+  }
+
+
+  void ReferenceLineFactory::SetSlice(const SliceGeometry& slice)
+  {
+    slice_ = slice;
+
+    if (hasLayerIndex_)
+    {
+      owner_.InvalidateLayer(layerIndex_);
+    }
+  }
+
+
+  ILayerRenderer* ReferenceLineFactory::CreateLayerRenderer(const SliceGeometry& viewportSlice)
+  {
+    Vector p, d;
+
+    // Compute the line of intersection between the two slices
+    if (!GeometryToolbox::IntersectTwoPlanes(p, d, 
+                                             slice_.GetOrigin(), slice_.GetNormal(),
+                                             viewportSlice.GetOrigin(), viewportSlice.GetNormal()))
+    {
+      // The two slice are parallel, don't try and display the intersection
+      return NULL;
+    }
+
+    double x1, y1, x2, y2;
+    viewportSlice.ProjectPoint(x1, y1, p);
+    viewportSlice.ProjectPoint(x2, y2, p + 1000.0 * d);
+
+    double sx1, sy1, sx2, sy2;
+    owner_.GetView().GetSceneExtent(sx1, sy1, sx2, sy2);
+        
+    if (GeometryToolbox::ClipLineToRectangle(x1, y1, x2, y2, 
+                                             x1, y1, x2, y2,
+                                             sx1, sy1, sx2, sy2))
+    {
+      std::auto_ptr<ILayerRenderer> layer(new LineLayerRenderer(x1, y1, x2, y2));
+      layer->SetLayerStyle(style_);
+      return layer.release();
+    }
+    else
+    {
+      // Parallel slices
+      return NULL;
+    }
+  }
+
+
+  ISliceableVolume& ReferenceLineFactory::GetSourceVolume() const
+  {
+    throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError);
+  }
+
+
+  void ReferenceLineFactory::Configure(SliceViewerWidget& a,
+                                       SliceViewerWidget& b)
+  {
+    {
+      size_t layerIndex;
+      ILayerRendererFactory& factory = a.AddLayer(layerIndex, new ReferenceLineFactory(a, b));
+      dynamic_cast<ReferenceLineFactory&>(factory).SetLayerIndex(layerIndex);
+    }
+
+    {
+      size_t layerIndex;
+      ILayerRendererFactory& factory = b.AddLayer(layerIndex, new ReferenceLineFactory(b, a));
+      dynamic_cast<ReferenceLineFactory&>(factory).SetLayerIndex(layerIndex);
+    }
+  }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Resources/Graveyard/ReferenceLineFactory.h	Fri Nov 09 17:59:35 2018 +0100
@@ -0,0 +1,77 @@
+/**
+ * Stone of Orthanc
+ * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
+ * Department, University Hospital of Liege, Belgium
+ * Copyright (C) 2017-2018 Osimis S.A., Belgium
+ *
+ * This program is free software: you can redistribute it and/or
+ * modify it under the terms of the GNU Affero General Public License
+ * as published by the Free Software Foundation, either version 3 of
+ * the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Affero General Public License for more details.
+ * 
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ **/
+
+
+#pragma once
+
+#include "../Widgets/SliceViewerWidget.h"
+
+namespace OrthancStone
+{
+  class ReferenceLineFactory : 
+    public ILayerRendererFactory,
+    public SliceViewerWidget::ISliceObserver
+  {
+  private:
+    SliceViewerWidget&   owner_;
+    SliceViewerWidget&   sibling_;
+    SliceGeometry        slice_;
+    RenderStyle          style_;
+    bool                 hasLayerIndex_;
+    size_t               layerIndex_;
+
+      
+  public:
+    ReferenceLineFactory(SliceViewerWidget& owner,
+                         SliceViewerWidget& sibling);
+
+    virtual void NotifySliceChange(const SliceViewerWidget& source,
+                                   const SliceGeometry& slice);
+
+    void SetLayerIndex(size_t layerIndex);
+
+    void SetStyle(const RenderStyle& style);
+
+    RenderStyle GetRenderStyle();
+
+    void SetSlice(const SliceGeometry& slice);
+
+    virtual bool GetExtent(double& x1,
+                           double& y1,
+                           double& x2,
+                           double& y2,
+                           const SliceGeometry& viewportSlice)
+    {
+      return false;
+    }
+
+    virtual ILayerRenderer* CreateLayerRenderer(const SliceGeometry& viewportSlice);
+
+    virtual bool HasSourceVolume() const
+    {
+      return false;
+    }
+
+    virtual ISliceableVolume& GetSourceVolume() const;
+
+    static void Configure(SliceViewerWidget& a,
+                          SliceViewerWidget& b);
+  };
+}