annotate Framework/Toolbox/DicomInstanceParameters.cpp @ 1054:3c9529edf5fd

fixing WebAssemblyViewport
author Sebastien Jodogne <s.jodogne@gmail.com>
date Thu, 10 Oct 2019 15:55:54 +0200
parents dd8ff977aaf2
children 5a18e6a395bc
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
746
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1 /**
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2 * Stone of Orthanc
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
4 * Department, University Hospital of Liege, Belgium
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
5 * Copyright (C) 2017-2019 Osimis S.A., Belgium
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
6 *
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
7 * This program is free software: you can redistribute it and/or
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
8 * modify it under the terms of the GNU Affero General Public License
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
9 * as published by the Free Software Foundation, either version 3 of
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
10 * the License, or (at your option) any later version.
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
11 *
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
12 * This program is distributed in the hope that it will be useful, but
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
15 * Affero General Public License for more details.
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
16 *
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
17 * You should have received a copy of the GNU Affero General Public License
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
19 **/
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
20
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
21
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
22 #include "DicomInstanceParameters.h"
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
23
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
24 #include "../Scene2D/ColorTextureSceneLayer.h"
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
25 #include "../Scene2D/FloatTextureSceneLayer.h"
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
26 #include "../Toolbox/GeometryToolbox.h"
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
27
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
28 #include <Core/Images/Image.h>
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
29 #include <Core/Images/ImageProcessing.h>
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
30 #include <Core/Logging.h>
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
31 #include <Core/OrthancException.h>
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
32 #include <Core/Toolbox.h>
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
33
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
34
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
35 namespace OrthancStone
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
36 {
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
37 void DicomInstanceParameters::Data::ComputeDoseOffsets(const Orthanc::DicomMap& dicom)
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
38 {
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
39 // http://dicom.nema.org/medical/Dicom/2016a/output/chtml/part03/sect_C.8.8.3.2.html
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
40
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
41 {
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
42 std::string increment;
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
43
994
1f74bc3459ba fix build due to rename in Orthanc::DicomMap
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 980
diff changeset
44 if (dicom.LookupStringValue(increment, Orthanc::DICOM_TAG_FRAME_INCREMENT_POINTER, false))
746
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
45 {
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
46 Orthanc::Toolbox::ToUpperCase(increment);
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: 768
diff changeset
47 if (increment != "3004,000C") // This is the "Grid Frame Offset Vector" tag (DICOM_TAG_GRID_FRAME_OFFSET_VECTOR)
746
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
48 {
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
49 LOG(ERROR) << "RT-DOSE: Bad value for the \"FrameIncrementPointer\" tag";
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
50 return;
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
51 }
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
52 }
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
53 }
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
54
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
55 if (!LinearAlgebra::ParseVector(frameOffsets_, dicom, Orthanc::DICOM_TAG_GRID_FRAME_OFFSET_VECTOR) ||
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
56 frameOffsets_.size() < imageInformation_.GetNumberOfFrames())
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
57 {
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
58 LOG(ERROR) << "RT-DOSE: No information about the 3D location of some slice(s)";
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
59 frameOffsets_.clear();
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
60 }
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
61 else
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
62 {
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
63 if (frameOffsets_.size() >= 2)
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
64 {
762
26f4345e771e creation of OrthancMultiframeVolumeLoader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 757
diff changeset
65 thickness_ = std::abs(frameOffsets_[1] - frameOffsets_[0]);
746
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
66 }
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
67 }
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
68 }
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
69
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
70
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
71 DicomInstanceParameters::Data::Data(const Orthanc::DicomMap& dicom) :
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
72 imageInformation_(dicom)
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
73 {
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
74 if (imageInformation_.GetNumberOfFrames() <= 0)
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
75 {
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
76 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadFileFormat);
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
77 }
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
78
994
1f74bc3459ba fix build due to rename in Orthanc::DicomMap
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 980
diff changeset
79 if (!dicom.LookupStringValue(studyInstanceUid_, Orthanc::DICOM_TAG_STUDY_INSTANCE_UID, false) ||
1f74bc3459ba fix build due to rename in Orthanc::DicomMap
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 980
diff changeset
80 !dicom.LookupStringValue(seriesInstanceUid_, Orthanc::DICOM_TAG_SERIES_INSTANCE_UID, false) ||
1f74bc3459ba fix build due to rename in Orthanc::DicomMap
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 980
diff changeset
81 !dicom.LookupStringValue(sopInstanceUid_, Orthanc::DICOM_TAG_SOP_INSTANCE_UID, false))
746
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
82 {
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
83 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadFileFormat);
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
84 }
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
85
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
86 std::string s;
994
1f74bc3459ba fix build due to rename in Orthanc::DicomMap
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 980
diff changeset
87 if (!dicom.LookupStringValue(s, Orthanc::DICOM_TAG_SOP_CLASS_UID, false))
746
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
88 {
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
89 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadFileFormat);
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
90 }
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
91 else
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
92 {
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
93 sopClassUid_ = StringToSopClassUid(s);
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
94 }
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
95
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
96 if (!dicom.ParseDouble(thickness_, Orthanc::DICOM_TAG_SLICE_THICKNESS))
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
97 {
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
98 thickness_ = 100.0 * std::numeric_limits<double>::epsilon();
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
99 }
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
100
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
101 GeometryToolbox::GetPixelSpacing(pixelSpacingX_, pixelSpacingY_, dicom);
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
102
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
103 std::string position, orientation;
994
1f74bc3459ba fix build due to rename in Orthanc::DicomMap
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 980
diff changeset
104 if (dicom.LookupStringValue(position, Orthanc::DICOM_TAG_IMAGE_POSITION_PATIENT, false) &&
1f74bc3459ba fix build due to rename in Orthanc::DicomMap
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 980
diff changeset
105 dicom.LookupStringValue(orientation, Orthanc::DICOM_TAG_IMAGE_ORIENTATION_PATIENT, false))
746
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
106 {
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
107 geometry_ = CoordinateSystem3D(position, orientation);
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
108 }
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
109
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
110 if (sopClassUid_ == SopClassUid_RTDose)
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
111 {
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
112 ComputeDoseOffsets(dicom);
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
113 }
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
114
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
115 isColor_ = (imageInformation_.GetPhotometricInterpretation() != Orthanc::PhotometricInterpretation_Monochrome1 &&
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
116 imageInformation_.GetPhotometricInterpretation() != Orthanc::PhotometricInterpretation_Monochrome2);
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
117
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
118 double doseGridScaling;
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
119
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
120 if (dicom.ParseDouble(rescaleIntercept_, Orthanc::DICOM_TAG_RESCALE_INTERCEPT) &&
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
121 dicom.ParseDouble(rescaleSlope_, Orthanc::DICOM_TAG_RESCALE_SLOPE))
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
122 {
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
123 hasRescale_ = true;
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
124 }
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
125 else if (dicom.ParseDouble(doseGridScaling, Orthanc::DICOM_TAG_DOSE_GRID_SCALING))
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
126 {
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
127 hasRescale_ = true;
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
128 rescaleIntercept_ = 0;
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
129 rescaleSlope_ = doseGridScaling;
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
130 }
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
131 else
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
132 {
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
133 hasRescale_ = false;
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
134 }
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
135
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
136 Vector c, w;
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
137 if (LinearAlgebra::ParseVector(c, dicom, Orthanc::DICOM_TAG_WINDOW_CENTER) &&
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
138 LinearAlgebra::ParseVector(w, dicom, Orthanc::DICOM_TAG_WINDOW_WIDTH) &&
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
139 c.size() > 0 &&
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
140 w.size() > 0)
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
141 {
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
142 hasDefaultWindowing_ = true;
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
143 defaultWindowingCenter_ = static_cast<float>(c[0]);
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
144 defaultWindowingWidth_ = static_cast<float>(w[0]);
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
145 }
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
146 else
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
147 {
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
148 hasDefaultWindowing_ = false;
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
149 }
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
150
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
151 if (sopClassUid_ == SopClassUid_RTDose)
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
152 {
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
153 switch (imageInformation_.GetBitsStored())
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
154 {
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
155 case 16:
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
156 expectedPixelFormat_ = Orthanc::PixelFormat_Grayscale16;
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
157 break;
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
158
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
159 case 32:
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
160 expectedPixelFormat_ = Orthanc::PixelFormat_Grayscale32;
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
161 break;
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
162
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
163 default:
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
164 throw Orthanc::OrthancException(Orthanc::ErrorCode_NotImplemented);
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
165 }
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
166 }
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
167 else if (isColor_)
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
168 {
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
169 expectedPixelFormat_ = Orthanc::PixelFormat_RGB24;
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
170 }
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
171 else if (imageInformation_.IsSigned())
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
172 {
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
173 expectedPixelFormat_ = Orthanc::PixelFormat_SignedGrayscale16;
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
174 }
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
175 else
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
176 {
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
177 expectedPixelFormat_ = Orthanc::PixelFormat_Grayscale16;
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
178 }
980
8e497a4e3d96 DicomInstanceParameters::GetIndexInSeries()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 956
diff changeset
179
8e497a4e3d96 DicomInstanceParameters::GetIndexInSeries()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 956
diff changeset
180 // This computes the "IndexInSeries" metadata from Orthanc (check
8e497a4e3d96 DicomInstanceParameters::GetIndexInSeries()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 956
diff changeset
181 // out "Orthanc::ServerIndex::Store()")
8e497a4e3d96 DicomInstanceParameters::GetIndexInSeries()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 956
diff changeset
182 hasIndexInSeries_ = (
8e497a4e3d96 DicomInstanceParameters::GetIndexInSeries()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 956
diff changeset
183 dicom.ParseUnsignedInteger32(indexInSeries_, Orthanc::DICOM_TAG_INSTANCE_NUMBER) ||
8e497a4e3d96 DicomInstanceParameters::GetIndexInSeries()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 956
diff changeset
184 dicom.ParseUnsignedInteger32(indexInSeries_, Orthanc::DICOM_TAG_IMAGE_INDEX));
746
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
185 }
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
186
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
187
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
188 CoordinateSystem3D DicomInstanceParameters::Data::GetFrameGeometry(unsigned int frame) const
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
189 {
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
190 if (frame == 0)
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
191 {
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
192 return geometry_;
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
193 }
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
194 else if (frame >= imageInformation_.GetNumberOfFrames())
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
195 {
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
196 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange);
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
197 }
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
198 else if (sopClassUid_ == SopClassUid_RTDose)
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
199 {
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
200 if (frame >= frameOffsets_.size())
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
201 {
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
202 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError);
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
203 }
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
204
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
205 return CoordinateSystem3D(
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
206 geometry_.GetOrigin() + frameOffsets_[frame] * geometry_.GetNormal(),
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
207 geometry_.GetAxisX(),
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
208 geometry_.GetAxisY());
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
209 }
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
210 else
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
211 {
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
212 throw Orthanc::OrthancException(Orthanc::ErrorCode_NotImplemented);
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
213 }
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
214 }
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
215
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
216
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
217 bool DicomInstanceParameters::Data::IsPlaneWithinSlice(unsigned int frame,
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
218 const CoordinateSystem3D& plane) const
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
219 {
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
220 if (frame >= imageInformation_.GetNumberOfFrames())
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
221 {
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
222 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange);
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
223 }
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
224
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
225 CoordinateSystem3D tmp = geometry_;
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
226
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
227 if (frame != 0)
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
228 {
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
229 tmp = GetFrameGeometry(frame);
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
230 }
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
231
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
232 double distance;
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
233
757
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 746
diff changeset
234 return (CoordinateSystem3D::ComputeDistance(distance, tmp, plane) &&
746
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
235 distance <= thickness_ / 2.0);
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
236 }
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
237
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
238
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
239 void DicomInstanceParameters::Data::ApplyRescale(Orthanc::ImageAccessor& image,
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
240 bool useDouble) const
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
241 {
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
242 if (image.GetFormat() != Orthanc::PixelFormat_Float32)
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
243 {
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
244 throw Orthanc::OrthancException(Orthanc::ErrorCode_IncompatibleImageFormat);
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
245 }
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
246
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
247 if (hasRescale_)
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
248 {
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
249 const unsigned int width = image.GetWidth();
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
250 const unsigned int height = image.GetHeight();
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
251
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
252 for (unsigned int y = 0; y < height; y++)
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
253 {
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
254 float* p = reinterpret_cast<float*>(image.GetRow(y));
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
255
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
256 if (useDouble)
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
257 {
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
258 // Slower, accurate implementation using double
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
259 for (unsigned int x = 0; x < width; x++, p++)
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
260 {
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
261 double value = static_cast<double>(*p);
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
262 *p = static_cast<float>(value * rescaleSlope_ + rescaleIntercept_);
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
263 }
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
264 }
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
265 else
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
266 {
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
267 // Fast, approximate implementation using float
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
268 for (unsigned int x = 0; x < width; x++, p++)
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
269 {
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
270 *p = (*p) * static_cast<float>(rescaleSlope_) + static_cast<float>(rescaleIntercept_);
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
271 }
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
272 }
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
273 }
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
274 }
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
275 }
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
276
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
277 double DicomInstanceParameters::GetRescaleIntercept() const
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
278 {
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
279 if (data_.hasRescale_)
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
280 {
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
281 return data_.rescaleIntercept_;
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
282 }
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
283 else
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
284 {
956
a7351ad54960 Made IsContextLost automatically set the flag by checking with the emscripten
Benjamin Golinvaux <bgo@osimis.io>
parents: 949
diff changeset
285 LOG(ERROR) << "DicomInstanceParameters::GetRescaleIntercept(): !data_.hasRescale_";
746
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
286 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls);
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
287 }
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
288 }
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
289
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
290
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
291 double DicomInstanceParameters::GetRescaleSlope() const
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
292 {
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
293 if (data_.hasRescale_)
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
294 {
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
295 return data_.rescaleSlope_;
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
296 }
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
297 else
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
298 {
956
a7351ad54960 Made IsContextLost automatically set the flag by checking with the emscripten
Benjamin Golinvaux <bgo@osimis.io>
parents: 949
diff changeset
299 LOG(ERROR) << "DicomInstanceParameters::GetRescaleSlope(): !data_.hasRescale_";
746
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
300 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls);
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
301 }
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
302 }
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
303
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
304
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
305 float DicomInstanceParameters::GetDefaultWindowingCenter() const
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
306 {
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
307 if (data_.hasDefaultWindowing_)
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
308 {
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
309 return data_.defaultWindowingCenter_;
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
310 }
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
311 else
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
312 {
956
a7351ad54960 Made IsContextLost automatically set the flag by checking with the emscripten
Benjamin Golinvaux <bgo@osimis.io>
parents: 949
diff changeset
313 LOG(ERROR) << "DicomInstanceParameters::GetDefaultWindowingCenter(): !data_.hasRescale_";
746
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
314 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls);
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
315 }
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
316 }
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
317
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
318
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
319 float DicomInstanceParameters::GetDefaultWindowingWidth() const
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
320 {
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
321 if (data_.hasDefaultWindowing_)
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
322 {
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
323 return data_.defaultWindowingWidth_;
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
324 }
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
325 else
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
326 {
956
a7351ad54960 Made IsContextLost automatically set the flag by checking with the emscripten
Benjamin Golinvaux <bgo@osimis.io>
parents: 949
diff changeset
327 LOG(ERROR) << "DicomInstanceParameters::GetDefaultWindowingWidth(): !data_.hasRescale_";
746
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
328 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls);
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
329 }
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
330 }
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
331
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
332
768
55411e7da2f7 LookupTableTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 762
diff changeset
333 Orthanc::ImageAccessor* DicomInstanceParameters::ConvertToFloat(const Orthanc::ImageAccessor& pixelData) const
55411e7da2f7 LookupTableTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 762
diff changeset
334 {
55411e7da2f7 LookupTableTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 762
diff changeset
335 std::auto_ptr<Orthanc::Image> converted(new Orthanc::Image(Orthanc::PixelFormat_Float32,
55411e7da2f7 LookupTableTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 762
diff changeset
336 pixelData.GetWidth(),
55411e7da2f7 LookupTableTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 762
diff changeset
337 pixelData.GetHeight(),
55411e7da2f7 LookupTableTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 762
diff changeset
338 false));
55411e7da2f7 LookupTableTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 762
diff changeset
339 Orthanc::ImageProcessing::Convert(*converted, pixelData);
55411e7da2f7 LookupTableTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 762
diff changeset
340
55411e7da2f7 LookupTableTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 762
diff changeset
341 // Correct rescale slope/intercept if need be
1026
a416ce923b60 fix for ie11
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 994
diff changeset
342 //data_.ApplyRescale(*converted, (pixelData.GetFormat() == Orthanc::PixelFormat_Grayscale32));
1027
dd8ff977aaf2 remove wrong comment
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1026
diff changeset
343 data_.ApplyRescale(*converted, false);
768
55411e7da2f7 LookupTableTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 762
diff changeset
344
55411e7da2f7 LookupTableTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 762
diff changeset
345 return converted.release();
55411e7da2f7 LookupTableTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 762
diff changeset
346 }
55411e7da2f7 LookupTableTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 762
diff changeset
347
55411e7da2f7 LookupTableTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 762
diff changeset
348
55411e7da2f7 LookupTableTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 762
diff changeset
349 TextureBaseSceneLayer* DicomInstanceParameters::CreateTexture
55411e7da2f7 LookupTableTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 762
diff changeset
350 (const Orthanc::ImageAccessor& pixelData) const
746
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
351 {
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
352 assert(sizeof(float) == 4);
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
353
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
354 Orthanc::PixelFormat sourceFormat = pixelData.GetFormat();
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
355
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
356 if (sourceFormat != GetExpectedPixelFormat())
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
357 {
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
358 throw Orthanc::OrthancException(Orthanc::ErrorCode_IncompatibleImageFormat);
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
359 }
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
360
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
361 if (sourceFormat == Orthanc::PixelFormat_RGB24)
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
362 {
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
363 // This is the case of a color image. No conversion has to be done.
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
364 return new ColorTextureSceneLayer(pixelData);
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
365 }
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
366 else
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
367 {
768
55411e7da2f7 LookupTableTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 762
diff changeset
368 // This is the case of a grayscale frame. Convert it to Float32.
55411e7da2f7 LookupTableTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 762
diff changeset
369 std::auto_ptr<FloatTextureSceneLayer> texture;
746
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
370
768
55411e7da2f7 LookupTableTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 762
diff changeset
371 if (pixelData.GetFormat() == Orthanc::PixelFormat_Float32)
746
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
372 {
768
55411e7da2f7 LookupTableTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 762
diff changeset
373 texture.reset(new FloatTextureSceneLayer(pixelData));
55411e7da2f7 LookupTableTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 762
diff changeset
374 }
55411e7da2f7 LookupTableTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 762
diff changeset
375 else
55411e7da2f7 LookupTableTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 762
diff changeset
376 {
55411e7da2f7 LookupTableTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 762
diff changeset
377 std::auto_ptr<Orthanc::ImageAccessor> converted(ConvertToFloat(pixelData));
746
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
378 texture.reset(new FloatTextureSceneLayer(*converted));
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
379 }
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
380
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
381 if (data_.hasDefaultWindowing_)
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
382 {
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
383 texture->SetCustomWindowing(data_.defaultWindowingCenter_,
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
384 data_.defaultWindowingWidth_);
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
385 }
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
386
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
387 return texture.release();
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
388 }
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
389 }
768
55411e7da2f7 LookupTableTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 762
diff changeset
390
55411e7da2f7 LookupTableTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 762
diff changeset
391
55411e7da2f7 LookupTableTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 762
diff changeset
392 LookupTableTextureSceneLayer* DicomInstanceParameters::CreateLookupTableTexture
55411e7da2f7 LookupTableTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 762
diff changeset
393 (const Orthanc::ImageAccessor& pixelData) const
55411e7da2f7 LookupTableTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 762
diff changeset
394 {
55411e7da2f7 LookupTableTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 762
diff changeset
395 std::auto_ptr<FloatTextureSceneLayer> texture;
55411e7da2f7 LookupTableTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 762
diff changeset
396
55411e7da2f7 LookupTableTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 762
diff changeset
397 if (pixelData.GetFormat() == Orthanc::PixelFormat_Float32)
55411e7da2f7 LookupTableTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 762
diff changeset
398 {
55411e7da2f7 LookupTableTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 762
diff changeset
399 return new LookupTableTextureSceneLayer(pixelData);
55411e7da2f7 LookupTableTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 762
diff changeset
400 }
55411e7da2f7 LookupTableTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 762
diff changeset
401 else
55411e7da2f7 LookupTableTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 762
diff changeset
402 {
55411e7da2f7 LookupTableTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 762
diff changeset
403 std::auto_ptr<Orthanc::ImageAccessor> converted(ConvertToFloat(pixelData));
55411e7da2f7 LookupTableTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 762
diff changeset
404 return new LookupTableTextureSceneLayer(*converted);
55411e7da2f7 LookupTableTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 762
diff changeset
405 }
55411e7da2f7 LookupTableTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 762
diff changeset
406 }
980
8e497a4e3d96 DicomInstanceParameters::GetIndexInSeries()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 956
diff changeset
407
8e497a4e3d96 DicomInstanceParameters::GetIndexInSeries()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 956
diff changeset
408
8e497a4e3d96 DicomInstanceParameters::GetIndexInSeries()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 956
diff changeset
409 unsigned int DicomInstanceParameters::GetIndexInSeries() const
8e497a4e3d96 DicomInstanceParameters::GetIndexInSeries()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 956
diff changeset
410 {
8e497a4e3d96 DicomInstanceParameters::GetIndexInSeries()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 956
diff changeset
411 if (data_.hasIndexInSeries_)
8e497a4e3d96 DicomInstanceParameters::GetIndexInSeries()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 956
diff changeset
412 {
8e497a4e3d96 DicomInstanceParameters::GetIndexInSeries()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 956
diff changeset
413 return data_.indexInSeries_;
8e497a4e3d96 DicomInstanceParameters::GetIndexInSeries()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 956
diff changeset
414 }
8e497a4e3d96 DicomInstanceParameters::GetIndexInSeries()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 956
diff changeset
415 else
8e497a4e3d96 DicomInstanceParameters::GetIndexInSeries()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 956
diff changeset
416 {
8e497a4e3d96 DicomInstanceParameters::GetIndexInSeries()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 956
diff changeset
417 LOG(ERROR) << "DicomInstanceParameters::GetIndexInSeries(): !data_.hasIndexInSeries_";
8e497a4e3d96 DicomInstanceParameters::GetIndexInSeries()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 956
diff changeset
418 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls);
8e497a4e3d96 DicomInstanceParameters::GetIndexInSeries()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 956
diff changeset
419 }
8e497a4e3d96 DicomInstanceParameters::GetIndexInSeries()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 956
diff changeset
420 }
746
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
421 }