Mercurial > hg > orthanc-stone
comparison OrthancStone/Sources/Volumes/DicomVolumeImageMPRSlicer.cpp @ 1512:244ad1e4e76a
reorganization of folders
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Tue, 07 Jul 2020 16:21:02 +0200 |
parents | Framework/Volumes/DicomVolumeImageMPRSlicer.cpp@30deba7bc8e2 |
children | 4fb8fdf03314 |
comparison
equal
deleted
inserted
replaced
1511:9dfeee74c1e6 | 1512:244ad1e4e76a |
---|---|
1 /** | |
2 * Stone of Orthanc | |
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics | |
4 * Department, University Hospital of Liege, Belgium | |
5 * Copyright (C) 2017-2020 Osimis S.A., Belgium | |
6 * | |
7 * This program is free software: you can redistribute it and/or | |
8 * modify it under the terms of the GNU Affero General Public License | |
9 * as published by the Free Software Foundation, either version 3 of | |
10 * the License, or (at your option) any later version. | |
11 * | |
12 * This program is distributed in the hope that it will be useful, but | |
13 * WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
15 * Affero General Public License for more details. | |
16 * | |
17 * You should have received a copy of the GNU Affero General Public License | |
18 * along with this program. If not, see <http://www.gnu.org/licenses/>. | |
19 **/ | |
20 | |
21 | |
22 #include "DicomVolumeImageMPRSlicer.h" | |
23 | |
24 #include "../StoneException.h" | |
25 | |
26 #include "../Toolbox/ImageToolbox.h" | |
27 | |
28 #include <OrthancException.h> | |
29 //#include <Images/PngWriter.h> | |
30 #include <Images/JpegWriter.h> | |
31 | |
32 namespace OrthancStone | |
33 { | |
34 void DicomVolumeImageMPRSlicer::Slice::CheckValid() const | |
35 { | |
36 if (!valid_) | |
37 { | |
38 LOG(ERROR) << "DicomVolumeImageMPRSlicer::Slice::CheckValid(): (!valid_)"; | |
39 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls); | |
40 } | |
41 } | |
42 | |
43 | |
44 DicomVolumeImageMPRSlicer::Slice::Slice(const DicomVolumeImage& volume, | |
45 const CoordinateSystem3D& cuttingPlane) : | |
46 volume_(volume), | |
47 revision_(volume_.GetRevision()) | |
48 { | |
49 valid_ = (volume_.HasDicomParameters() && | |
50 volume_.GetGeometry().DetectSlice(projection_, sliceIndex_, cuttingPlane)); | |
51 } | |
52 | |
53 | |
54 VolumeProjection DicomVolumeImageMPRSlicer::Slice::GetProjection() const | |
55 { | |
56 CheckValid(); | |
57 return projection_; | |
58 } | |
59 | |
60 | |
61 unsigned int DicomVolumeImageMPRSlicer::Slice::GetSliceIndex() const | |
62 { | |
63 CheckValid(); | |
64 return sliceIndex_; | |
65 } | |
66 | |
67 | |
68 ISceneLayer* DicomVolumeImageMPRSlicer::Slice::CreateSceneLayer(const ILayerStyleConfigurator* configurator, | |
69 const CoordinateSystem3D& cuttingPlane) | |
70 { | |
71 CheckValid(); | |
72 | |
73 if (configurator == NULL) | |
74 { | |
75 throw Orthanc::OrthancException(Orthanc::ErrorCode_NullPointer, | |
76 "A style configurator is mandatory for textures"); | |
77 } | |
78 | |
79 std::unique_ptr<TextureBaseSceneLayer> texture; | |
80 | |
81 { | |
82 const DicomInstanceParameters& parameters = volume_.GetDicomParameters(); | |
83 ImageBuffer3D::SliceReader reader(volume_.GetPixelData(), projection_, sliceIndex_); | |
84 | |
85 texture.reset(dynamic_cast<TextureBaseSceneLayer*> | |
86 (configurator->CreateTextureFromDicom(reader.GetAccessor(), parameters))); | |
87 } | |
88 | |
89 const CoordinateSystem3D& system = volume_.GetGeometry().GetProjectionGeometry(projection_); | |
90 | |
91 double x0, y0, x1, y1; | |
92 cuttingPlane.ProjectPoint(x0, y0, system.GetOrigin()); | |
93 cuttingPlane.ProjectPoint(x1, y1, system.GetOrigin() + system.GetAxisX()); | |
94 | |
95 { | |
96 double xz, yz; | |
97 cuttingPlane.ProjectPoint(xz, yz, LinearAlgebra::CreateVector(0, 0, 0)); | |
98 texture->SetOrigin(x0 - xz, y0 - yz); | |
99 } | |
100 | |
101 double dx = x1 - x0; | |
102 double dy = y1 - y0; | |
103 if (!LinearAlgebra::IsCloseToZero(dx) || | |
104 !LinearAlgebra::IsCloseToZero(dy)) | |
105 { | |
106 texture->SetAngle(atan2(dy, dx)); | |
107 } | |
108 | |
109 Vector tmp = volume_.GetGeometry().GetVoxelDimensions(projection_); | |
110 texture->SetPixelSpacing(tmp[0], tmp[1]); | |
111 | |
112 return texture.release(); | |
113 } | |
114 | |
115 | |
116 DicomVolumeImageMPRSlicer::~DicomVolumeImageMPRSlicer() | |
117 { | |
118 LOG(TRACE) << "DicomVolumeImageMPRSlicer::~DicomVolumeImageMPRSlicer()"; | |
119 } | |
120 | |
121 IVolumeSlicer::IExtractedSlice* | |
122 DicomVolumeImageMPRSlicer::ExtractSlice(const CoordinateSystem3D& cuttingPlane) | |
123 { | |
124 if (volume_->HasGeometry()) | |
125 { | |
126 return new Slice(*volume_, cuttingPlane); | |
127 } | |
128 else | |
129 { | |
130 return new IVolumeSlicer::InvalidSlice; | |
131 } | |
132 } | |
133 } |