annotate OrthancStone/Sources/Volumes/DicomVolumeImageMPRSlicer.cpp @ 2088:b98d159c7545 dicom-sr

created branch dicom-sr
author Sebastien Jodogne <s.jodogne@gmail.com>
date Tue, 07 Nov 2023 18:12:35 +0100
parents 07964689cb0b
children c23eef785569
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
814
aead999345e0 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1 /**
aead999345e0 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2 * Stone of Orthanc
aead999345e0 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
aead999345e0 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
4 * Department, University Hospital of Liege, Belgium
2077
07964689cb0b upgrade to year 2023
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1871
diff changeset
5 * Copyright (C) 2017-2023 Osimis S.A., Belgium
07964689cb0b upgrade to year 2023
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1871
diff changeset
6 * Copyright (C) 2021-2023 Sebastien Jodogne, ICTEAM UCLouvain, Belgium
814
aead999345e0 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
7 *
aead999345e0 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
8 * This program is free software: you can redistribute it and/or
1598
8563ea5d8ae4 relicensing some files, cf. osimis bm26 and chu agreement on 2020-05-20
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1596
diff changeset
9 * modify it under the terms of the GNU Lesser General Public License
814
aead999345e0 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
10 * as published by the Free Software Foundation, either version 3 of
aead999345e0 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
11 * the License, or (at your option) any later version.
aead999345e0 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
12 *
aead999345e0 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
13 * This program is distributed in the hope that it will be useful, but
aead999345e0 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
1598
8563ea5d8ae4 relicensing some files, cf. osimis bm26 and chu agreement on 2020-05-20
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1596
diff changeset
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
8563ea5d8ae4 relicensing some files, cf. osimis bm26 and chu agreement on 2020-05-20
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1596
diff changeset
16 * Lesser General Public License for more details.
1596
4fb8fdf03314 removed annoying whitespace
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1512
diff changeset
17 *
1598
8563ea5d8ae4 relicensing some files, cf. osimis bm26 and chu agreement on 2020-05-20
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1596
diff changeset
18 * You should have received a copy of the GNU Lesser General Public
8563ea5d8ae4 relicensing some files, cf. osimis bm26 and chu agreement on 2020-05-20
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1596
diff changeset
19 * License along with this program. If not, see
8563ea5d8ae4 relicensing some files, cf. osimis bm26 and chu agreement on 2020-05-20
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1596
diff changeset
20 * <http://www.gnu.org/licenses/>.
814
aead999345e0 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
21 **/
aead999345e0 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
22
aead999345e0 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
23
aead999345e0 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
24 #include "DicomVolumeImageMPRSlicer.h"
aead999345e0 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
25
949
32eaf4929b08 OrthancMultiframeVolumeLoader and OrthancSeriesVolumeProgressiveLoader now implement IGeometryProvider so that the geometry reference can be switched (CT or DOSE, for instance) + VolumeImageGeometry::SetSize renamed to VolumeImageGeometry::SetSizeInVoxels + prevent text layer update if text or properties do not change + a few stream operator<< for debug (Vector, Matrix,...) + fixed memory access aligment issues in ImageBuffer3D::ExtractSagittalSlice + fix for wrong screen Y offset of mpr slices in DicomVolumeImageMPRSlicer.
Benjamin Golinvaux <bgo@osimis.io>
parents: 935
diff changeset
26 #include "../StoneException.h"
32eaf4929b08 OrthancMultiframeVolumeLoader and OrthancSeriesVolumeProgressiveLoader now implement IGeometryProvider so that the geometry reference can be switched (CT or DOSE, for instance) + VolumeImageGeometry::SetSize renamed to VolumeImageGeometry::SetSizeInVoxels + prevent text layer update if text or properties do not change + a few stream operator<< for debug (Vector, Matrix,...) + fixed memory access aligment issues in ImageBuffer3D::ExtractSagittalSlice + fix for wrong screen Y offset of mpr slices in DicomVolumeImageMPRSlicer.
Benjamin Golinvaux <bgo@osimis.io>
parents: 935
diff changeset
27
1287
8e82fdc6200e Heavy (temporary) logging in the path that leads
Benjamin Golinvaux <bgo@osimis.io>
parents: 1270
diff changeset
28 #include "../Toolbox/ImageToolbox.h"
8e82fdc6200e Heavy (temporary) logging in the path that leads
Benjamin Golinvaux <bgo@osimis.io>
parents: 1270
diff changeset
29
1624
59f95b9ea858 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1598
diff changeset
30 #include <Logging.h>
1455
30deba7bc8e2 simplifying include_directories
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1300
diff changeset
31 #include <OrthancException.h>
814
aead999345e0 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
32
aead999345e0 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
33 namespace OrthancStone
aead999345e0 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
34 {
aead999345e0 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
35 void DicomVolumeImageMPRSlicer::Slice::CheckValid() const
aead999345e0 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
36 {
aead999345e0 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
37 if (!valid_)
aead999345e0 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
38 {
956
a7351ad54960 Made IsContextLost automatically set the flag by checking with the emscripten
Benjamin Golinvaux <bgo@osimis.io>
parents: 949
diff changeset
39 LOG(ERROR) << "DicomVolumeImageMPRSlicer::Slice::CheckValid(): (!valid_)";
814
aead999345e0 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
40 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls);
aead999345e0 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
41 }
aead999345e0 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
42 }
aead999345e0 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
43
aead999345e0 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
44
aead999345e0 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
45 DicomVolumeImageMPRSlicer::Slice::Slice(const DicomVolumeImage& volume,
aead999345e0 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
46 const CoordinateSystem3D& cuttingPlane) :
817
68f888812af4 simplification of DicomVolumeImageMPRSlicer::ExtractedSlice
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 814
diff changeset
47 volume_(volume),
68f888812af4 simplification of DicomVolumeImageMPRSlicer::ExtractedSlice
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 814
diff changeset
48 revision_(volume_.GetRevision())
814
aead999345e0 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
49 {
aead999345e0 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
50 valid_ = (volume_.HasDicomParameters() &&
1161
19b1c8caade4 fix sagittal geometry
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1105
diff changeset
51 volume_.GetGeometry().DetectSlice(projection_, sliceIndex_, cuttingPlane));
814
aead999345e0 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
52 }
aead999345e0 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
53
aead999345e0 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
54
aead999345e0 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
55 VolumeProjection DicomVolumeImageMPRSlicer::Slice::GetProjection() const
aead999345e0 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
56 {
aead999345e0 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
57 CheckValid();
aead999345e0 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
58 return projection_;
aead999345e0 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
59 }
aead999345e0 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
60
aead999345e0 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
61
aead999345e0 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
62 unsigned int DicomVolumeImageMPRSlicer::Slice::GetSliceIndex() const
aead999345e0 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
63 {
aead999345e0 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
64 CheckValid();
aead999345e0 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
65 return sliceIndex_;
aead999345e0 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
66 }
817
68f888812af4 simplification of DicomVolumeImageMPRSlicer::ExtractedSlice
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 814
diff changeset
67
814
aead999345e0 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
68
aead999345e0 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
69 ISceneLayer* DicomVolumeImageMPRSlicer::Slice::CreateSceneLayer(const ILayerStyleConfigurator* configurator,
aead999345e0 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
70 const CoordinateSystem3D& cuttingPlane)
aead999345e0 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
71 {
aead999345e0 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
72 CheckValid();
aead999345e0 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
73
aead999345e0 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
74 if (configurator == NULL)
aead999345e0 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
75 {
aead999345e0 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
76 throw Orthanc::OrthancException(Orthanc::ErrorCode_NullPointer,
aead999345e0 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
77 "A style configurator is mandatory for textures");
aead999345e0 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
78 }
aead999345e0 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
79
1298
8a0a62189f46 replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1292
diff changeset
80 std::unique_ptr<TextureBaseSceneLayer> texture;
1105
640feb146fa8 Code formatting (dummyc) + log level (dummyc)
Benjamin Golinvaux <bgo@osimis.io>
parents: 956
diff changeset
81
814
aead999345e0 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
82 {
aead999345e0 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
83 const DicomInstanceParameters& parameters = volume_.GetDicomParameters();
aead999345e0 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
84 ImageBuffer3D::SliceReader reader(volume_.GetPixelData(), projection_, sliceIndex_);
1287
8e82fdc6200e Heavy (temporary) logging in the path that leads
Benjamin Golinvaux <bgo@osimis.io>
parents: 1270
diff changeset
85
814
aead999345e0 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
86 texture.reset(dynamic_cast<TextureBaseSceneLayer*>
aead999345e0 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
87 (configurator->CreateTextureFromDicom(reader.GetAccessor(), parameters)));
1771
f302bbddf94d sync, trying to fix DicomVolumeImageReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1769
diff changeset
88
f302bbddf94d sync, trying to fix DicomVolumeImageReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1769
diff changeset
89 if (texture.get() == NULL)
f302bbddf94d sync, trying to fix DicomVolumeImageReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1769
diff changeset
90 {
f302bbddf94d sync, trying to fix DicomVolumeImageReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1769
diff changeset
91 return NULL;
f302bbddf94d sync, trying to fix DicomVolumeImageReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1769
diff changeset
92 }
814
aead999345e0 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
93 }
949
32eaf4929b08 OrthancMultiframeVolumeLoader and OrthancSeriesVolumeProgressiveLoader now implement IGeometryProvider so that the geometry reference can be switched (CT or DOSE, for instance) + VolumeImageGeometry::SetSize renamed to VolumeImageGeometry::SetSizeInVoxels + prevent text layer update if text or properties do not change + a few stream operator<< for debug (Vector, Matrix,...) + fixed memory access aligment issues in ImageBuffer3D::ExtractSagittalSlice + fix for wrong screen Y offset of mpr slices in DicomVolumeImageMPRSlicer.
Benjamin Golinvaux <bgo@osimis.io>
parents: 935
diff changeset
94
814
aead999345e0 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
95 const CoordinateSystem3D& system = volume_.GetGeometry().GetProjectionGeometry(projection_);
949
32eaf4929b08 OrthancMultiframeVolumeLoader and OrthancSeriesVolumeProgressiveLoader now implement IGeometryProvider so that the geometry reference can be switched (CT or DOSE, for instance) + VolumeImageGeometry::SetSize renamed to VolumeImageGeometry::SetSizeInVoxels + prevent text layer update if text or properties do not change + a few stream operator<< for debug (Vector, Matrix,...) + fixed memory access aligment issues in ImageBuffer3D::ExtractSagittalSlice + fix for wrong screen Y offset of mpr slices in DicomVolumeImageMPRSlicer.
Benjamin Golinvaux <bgo@osimis.io>
parents: 935
diff changeset
96
1768
226718777702 fix DicomVolumeImageMPRSlicer::Slice::CreateSceneLayer() for opposite normals
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1739
diff changeset
97 Vector pixelSpacing = volume_.GetGeometry().GetVoxelDimensions(projection_);
226718777702 fix DicomVolumeImageMPRSlicer::Slice::CreateSceneLayer() for opposite normals
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1739
diff changeset
98
1769
a217140dd41a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1768
diff changeset
99 texture->SetCuttingPlaneTransform(cuttingPlane, system.GetOrigin(),
a217140dd41a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1768
diff changeset
100 system.GetAxisX() * pixelSpacing[0],
a217140dd41a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1768
diff changeset
101 system.GetAxisY() * pixelSpacing[1]);
814
aead999345e0 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
102
aead999345e0 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
103 return texture.release();
aead999345e0 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
104 }
aead999345e0 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
105
aead999345e0 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
106
935
401808e7ff2e Added traces in LoaderCache objects dtors + fuse to prevent dead weak ptrs to be calleds in VisitWdigets (in GuiAdapter.h)
Benjamin Golinvaux <bgo@osimis.io>
parents: 817
diff changeset
107 DicomVolumeImageMPRSlicer::~DicomVolumeImageMPRSlicer()
401808e7ff2e Added traces in LoaderCache objects dtors + fuse to prevent dead weak ptrs to be calleds in VisitWdigets (in GuiAdapter.h)
Benjamin Golinvaux <bgo@osimis.io>
parents: 817
diff changeset
108 {
401808e7ff2e Added traces in LoaderCache objects dtors + fuse to prevent dead weak ptrs to be calleds in VisitWdigets (in GuiAdapter.h)
Benjamin Golinvaux <bgo@osimis.io>
parents: 817
diff changeset
109 LOG(TRACE) << "DicomVolumeImageMPRSlicer::~DicomVolumeImageMPRSlicer()";
401808e7ff2e Added traces in LoaderCache objects dtors + fuse to prevent dead weak ptrs to be calleds in VisitWdigets (in GuiAdapter.h)
Benjamin Golinvaux <bgo@osimis.io>
parents: 817
diff changeset
110 }
401808e7ff2e Added traces in LoaderCache objects dtors + fuse to prevent dead weak ptrs to be calleds in VisitWdigets (in GuiAdapter.h)
Benjamin Golinvaux <bgo@osimis.io>
parents: 817
diff changeset
111
401808e7ff2e Added traces in LoaderCache objects dtors + fuse to prevent dead weak ptrs to be calleds in VisitWdigets (in GuiAdapter.h)
Benjamin Golinvaux <bgo@osimis.io>
parents: 817
diff changeset
112 IVolumeSlicer::IExtractedSlice*
814
aead999345e0 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
113 DicomVolumeImageMPRSlicer::ExtractSlice(const CoordinateSystem3D& cuttingPlane)
aead999345e0 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
114 {
aead999345e0 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
115 if (volume_->HasGeometry())
aead999345e0 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
116 {
aead999345e0 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
117 return new Slice(*volume_, cuttingPlane);
aead999345e0 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
118 }
aead999345e0 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
119 else
aead999345e0 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
120 {
aead999345e0 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
121 return new IVolumeSlicer::InvalidSlice;
aead999345e0 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
122 }
aead999345e0 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
123 }
aead999345e0 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
124 }