Mercurial > hg > orthanc-stone
changeset 1769:a217140dd41a
refactoring
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Wed, 12 May 2021 10:26:13 +0200 |
parents | 226718777702 |
children | 073484e33bee |
files | OrthancStone/Sources/Scene2D/TextureBaseSceneLayer.cpp OrthancStone/Sources/Scene2D/TextureBaseSceneLayer.h OrthancStone/Sources/Volumes/DicomVolumeImageMPRSlicer.cpp |
diffstat | 3 files changed, 50 insertions(+), 30 deletions(-) [+] |
line wrap: on
line diff
--- a/OrthancStone/Sources/Scene2D/TextureBaseSceneLayer.cpp Tue May 11 17:18:39 2021 +0200 +++ b/OrthancStone/Sources/Scene2D/TextureBaseSceneLayer.cpp Wed May 12 10:26:13 2021 +0200 @@ -160,6 +160,44 @@ } + void TextureBaseSceneLayer::SetCuttingPlaneTransform(const CoordinateSystem3D& cuttingPlane, + const Vector& origin, + const Vector& pixelOffsetX, + const Vector& pixelOffsetY) + { + double x0, y0, x1, y1, x2, y2; + cuttingPlane.ProjectPoint(x0, y0, origin); + cuttingPlane.ProjectPoint(x1, y1, origin + pixelOffsetX); + cuttingPlane.ProjectPoint(x2, y2, origin + pixelOffsetY); + + /** + + A = [ a11 a12 ; a21 a22 ] + + (1) A * (0 ; 0) + (b1 ; b2) = (x0 ; y0) + (2) A * (1 ; 0) + (b1 ; b2) = (x1 ; y1) + (3) A * (0 ; 1) + (b1 ; b2) = (x2 ; y2) + + (2-1) A * (1 ; 0) = (x1 - x0 ; y1 - y0) <=> (a11 ; a21) = (x1 - x0 ; y1 - y0) + (3-1) A * (0 ; 1) = (x2 - x0 ; y2 - y0) <=> (a12 ; a22) = (x2 - x0 ; y2 - y0) + + **/ + + Matrix m(3, 3); + m(0, 0) = x1 - x0; // a11 + m(0, 1) = x2 - x0; // a12 + m(0, 2) = x0; // b1 + m(1, 0) = y1 - y0; // a21 + m(1, 1) = y2 - y0; // a22 + m(1, 2) = y0; // b2 + m(2, 0) = 0; + m(2, 1) = 0; + m(2, 2) = 1; + + SetTransform(AffineTransform2D(m)); + } + + AffineTransform2D TextureBaseSceneLayer::GetTransform() const { if (transform_.get() == NULL)
--- a/OrthancStone/Sources/Scene2D/TextureBaseSceneLayer.h Tue May 11 17:18:39 2021 +0200 +++ b/OrthancStone/Sources/Scene2D/TextureBaseSceneLayer.h Wed May 12 10:26:13 2021 +0200 @@ -24,6 +24,7 @@ #include "ISceneLayer.h" #include "../Toolbox/AffineTransform2D.h" +#include "../Toolbox/CoordinateSystem3D.h" #include <Compatibility.h> #include <Images/ImageAccessor.h> @@ -125,6 +126,14 @@ void ClearTransform(); + // Initialize a transform that maps a texture slice in 3D, to a + // cutting plane (the cutting plane should be parallel to the 3D + // slice). The "pixelOffsetX/Y" must take pixel spacing into account. + void SetCuttingPlaneTransform(const CoordinateSystem3D& cuttingPlane, + const Vector& origin, // coordinates of the center of the voxel + const Vector& pixelOffsetX, // 3D offset from (0,0) voxel to (1,0) voxel + const Vector& pixelOffsetY); // 3D offset from (0,0) voxel to (0,1) voxel + AffineTransform2D GetTransform() const; virtual void GetBoundingBox(Extent2D& target) const ORTHANC_OVERRIDE;
--- a/OrthancStone/Sources/Volumes/DicomVolumeImageMPRSlicer.cpp Tue May 11 17:18:39 2021 +0200 +++ b/OrthancStone/Sources/Volumes/DicomVolumeImageMPRSlicer.cpp Wed May 12 10:26:13 2021 +0200 @@ -97,36 +97,9 @@ Vector pixelSpacing = volume_.GetGeometry().GetVoxelDimensions(projection_); - double x0, y0, x1, y1, x2, y2; - cuttingPlane.ProjectPoint(x0, y0, system.GetOrigin()); - cuttingPlane.ProjectPoint(x1, y1, system.GetOrigin() + system.GetAxisX() * pixelSpacing[0]); - cuttingPlane.ProjectPoint(x2, y2, system.GetOrigin() + system.GetAxisY() * pixelSpacing[1]); - - /** - - A = [ a11 a12 ; a21 a22 ] - - (1) A * (0 ; 0) + (b1 ; b2) = (x0 ; y0) - (2) A * (1 ; 0) + (b1 ; b2) = (x1 ; y1) - (3) A * (0 ; 1) + (b1 ; b2) = (x2 ; y2) - - (2-1) A * (1 ; 0) = (x1 - x0 ; y1 - y0) <=> (a11 ; a21) = (x1 - x0 ; y1 - y0) - (3-1) A * (0 ; 1) = (x2 - x0 ; y2 - y0) <=> (a12 ; a22) = (x2 - x0 ; y2 - y0) - - **/ - - Matrix m(3, 3); - m(0, 0) = x1 - x0; // a11 - m(0, 1) = x2 - x0; // a12 - m(0, 2) = x0; // b1 - m(1, 0) = y1 - y0; // a21 - m(1, 1) = y2 - y0; // a22 - m(1, 2) = y0; // b2 - m(2, 0) = 0; - m(2, 1) = 0; - m(2, 2) = 1; - - texture->SetTransform(AffineTransform2D(m)); + texture->SetCuttingPlaneTransform(cuttingPlane, system.GetOrigin(), + system.GetAxisX() * pixelSpacing[0], + system.GetAxisY() * pixelSpacing[1]); return texture.release(); }