# HG changeset patch # User Sebastien Jodogne # Date 1505911028 -7200 # Node ID 948f86e61e8380de2e1b4cd9bd43a24dfd0dfb94 # Parent 7665ccbf33dbea4ad49511d8fe7dfddfbb969c2a start of SliceLocationSource diff -r 7665ccbf33db -r 948f86e61e83 Framework/Layers/ILayerSource.h --- a/Framework/Layers/ILayerSource.h Wed Jun 14 15:54:06 2017 +0200 +++ b/Framework/Layers/ILayerSource.h Wed Sep 20 14:37:08 2017 +0200 @@ -55,8 +55,8 @@ // std::auto_ptr virtual void NotifyLayerReady(std::auto_ptr& layer, const ILayerSource& source, - const Slice& slice, - bool isError) = 0; + const Slice& slice, // TODO Shouldn't this be CoordinateSystem3D? Is it necessary given ILayerS::GetLayerSlice()? + bool isError) = 0; // TODO Shouldn't this be separate as NotifyLayerError? }; virtual ~ILayerSource() diff -r 7665ccbf33db -r 948f86e61e83 Framework/Layers/LineLayerRenderer.cpp --- a/Framework/Layers/LineLayerRenderer.cpp Wed Jun 14 15:54:06 2017 +0200 +++ b/Framework/Layers/LineLayerRenderer.cpp Wed Sep 20 14:37:08 2017 +0200 @@ -26,11 +26,13 @@ LineLayerRenderer::LineLayerRenderer(double x1, double y1, double x2, - double y2) : + double y2, + const CoordinateSystem3D& slice) : x1_(x1), y1_(y1), x2_(x2), - y2_(y2) + y2_(y2), + slice_(slice) { RenderStyle style; SetLayerStyle(style); @@ -38,8 +40,7 @@ bool LineLayerRenderer::RenderLayer(CairoContext& context, - const ViewportGeometry& view, - const CoordinateSystem3D& slice) + const ViewportGeometry& view) { if (visible_) { diff -r 7665ccbf33db -r 948f86e61e83 Framework/Layers/LineLayerRenderer.h --- a/Framework/Layers/LineLayerRenderer.h Wed Jun 14 15:54:06 2017 +0200 +++ b/Framework/Layers/LineLayerRenderer.h Wed Sep 20 14:37:08 2017 +0200 @@ -28,25 +28,31 @@ class LineLayerRenderer : public ILayerRenderer { private: - double x1_; - double y1_; - double x2_; - double y2_; - bool visible_; - uint8_t color_[3]; + double x1_; + double y1_; + double x2_; + double y2_; + CoordinateSystem3D slice_; + bool visible_; + uint8_t color_[3]; public: LineLayerRenderer(double x1, double y1, double x2, - double y2); + double y2, + const CoordinateSystem3D& slice); virtual bool RenderLayer(CairoContext& context, - const ViewportGeometry& view, - const CoordinateSystem3D& slice); + const ViewportGeometry& view); virtual void SetLayerStyle(const RenderStyle& style); + virtual const CoordinateSystem3D& GetLayerSlice() + { + return slice_; + } + virtual bool IsFullQuality() { return true; diff -r 7665ccbf33db -r 948f86e61e83 Framework/Widgets/LayerWidget.h --- a/Framework/Widgets/LayerWidget.h Wed Jun 14 15:54:06 2017 +0200 +++ b/Framework/Widgets/LayerWidget.h Wed Sep 20 14:37:08 2017 +0200 @@ -68,10 +68,11 @@ bool isError); void ResetChangedLayers(); - - protected: + + public: virtual Extent2D GetSceneExtent(); + protected: virtual bool RenderScene(CairoContext& context, const ViewportGeometry& view); diff -r 7665ccbf33db -r 948f86e61e83 Framework/Widgets/WorldSceneWidget.h --- a/Framework/Widgets/WorldSceneWidget.h Wed Jun 14 15:54:06 2017 +0200 +++ b/Framework/Widgets/WorldSceneWidget.h Wed Sep 20 14:37:08 2017 +0200 @@ -59,10 +59,10 @@ Observers observers_; IWorldSceneInteractor* interactor_; + public: + virtual Extent2D GetSceneExtent() = 0; protected: - virtual Extent2D GetSceneExtent() = 0; - virtual bool RenderScene(CairoContext& context, const ViewportGeometry& view) = 0; diff -r 7665ccbf33db -r 948f86e61e83 Framework/dev.h --- a/Framework/dev.h Wed Jun 14 15:54:06 2017 +0200 +++ b/Framework/dev.h Wed Sep 20 14:37:08 2017 +0200 @@ -24,6 +24,7 @@ #include "Layers/FrameRenderer.h" #include "Layers/LayerSourceBase.h" #include "Layers/SliceOutlineRenderer.h" +#include "Layers/LineLayerRenderer.h" #include "Widgets/LayerWidget.h" #include "Toolbox/DownloadStack.h" #include "Toolbox/OrthancSlicesLoader.h" @@ -759,4 +760,64 @@ } } }; + + + + class SliceLocationSource : public LayerSourceBase + { + private: + LayerWidget& otherPlane_; + + public: + SliceLocationSource(LayerWidget& otherPlane) : + otherPlane_(otherPlane) + { + NotifyGeometryReady(); + } + + virtual bool GetExtent(std::vector& points, + const CoordinateSystem3D& viewportSlice) + { + return false; + } + + virtual void ScheduleLayerCreation(const CoordinateSystem3D& viewportSlice) + { + Slice reference(viewportSlice, 0.001); + + Vector p, d; + + const CoordinateSystem3D& slice = otherPlane_.GetSlice(); + + // 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 + NotifyLayerReady(NULL, reference, false); + } + else + { + double x1, y1, x2, y2; + viewportSlice.ProjectPoint(x1, y1, p); + viewportSlice.ProjectPoint(x2, y2, p + 1000.0 * d); + + const Extent2D extent = otherPlane_.GetSceneExtent(); + + if (GeometryToolbox::ClipLineToRectangle(x1, y1, x2, y2, + x1, y1, x2, y2, + extent.GetX1(), extent.GetY1(), + extent.GetX2(), extent.GetY2())) + { + NotifyLayerReady(new LineLayerRenderer(x1, y1, x2, y2, slice), reference, false); + } + else + { + // Parallel slices + NotifyLayerReady(NULL, reference, false); + } + } + } + }; }