annotate Framework/Toolbox/DicomInstanceParameters.cpp @ 981:c20dbaab360c

Ability to cope with empty "Referenced SOP Instance UID" (dicom path (3006,0039)[i] / (0x3006, 0x0040)[0] / (0x3006, 0x0016)[0] / (0x0008, 0x1155)) + better logs + code formating
author Benjamin Golinvaux <bgo@osimis.io>
date Fri, 06 Sep 2019 09:38:18 +0200
parents a7351ad54960
children 8e497a4e3d96
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
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
44 if (dicom.CopyToString(increment, Orthanc::DICOM_TAG_FRAME_INCREMENT_POINTER, false))
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
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
79 if (!dicom.CopyToString(studyInstanceUid_, Orthanc::DICOM_TAG_STUDY_INSTANCE_UID, false) ||
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
80 !dicom.CopyToString(seriesInstanceUid_, Orthanc::DICOM_TAG_SERIES_INSTANCE_UID, false) ||
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
81 !dicom.CopyToString(sopInstanceUid_, Orthanc::DICOM_TAG_SOP_INSTANCE_UID, false))
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;
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
87 if (!dicom.CopyToString(s, Orthanc::DICOM_TAG_SOP_CLASS_UID, false))
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;
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
104 if (dicom.CopyToString(position, Orthanc::DICOM_TAG_IMAGE_POSITION_PATIENT, false) &&
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
105 dicom.CopyToString(orientation, Orthanc::DICOM_TAG_IMAGE_ORIENTATION_PATIENT, false))
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 }
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
179 }
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
180
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
181
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
182 CoordinateSystem3D DicomInstanceParameters::Data::GetFrameGeometry(unsigned int frame) const
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
183 {
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
184 if (frame == 0)
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
185 {
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
186 return geometry_;
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
187 }
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
188 else if (frame >= imageInformation_.GetNumberOfFrames())
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
189 {
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
190 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange);
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
191 }
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
192 else if (sopClassUid_ == SopClassUid_RTDose)
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
193 {
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
194 if (frame >= frameOffsets_.size())
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_InternalError);
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
197 }
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
198
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
199 return CoordinateSystem3D(
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
200 geometry_.GetOrigin() + frameOffsets_[frame] * geometry_.GetNormal(),
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
201 geometry_.GetAxisX(),
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
202 geometry_.GetAxisY());
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
203 }
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
204 else
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
205 {
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
206 throw Orthanc::OrthancException(Orthanc::ErrorCode_NotImplemented);
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
207 }
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
208 }
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
209
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
210
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
211 bool DicomInstanceParameters::Data::IsPlaneWithinSlice(unsigned int frame,
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
212 const CoordinateSystem3D& plane) const
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
213 {
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
214 if (frame >= imageInformation_.GetNumberOfFrames())
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
215 {
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
216 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange);
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
217 }
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
218
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
219 CoordinateSystem3D tmp = geometry_;
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
220
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
221 if (frame != 0)
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
222 {
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
223 tmp = GetFrameGeometry(frame);
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
224 }
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
225
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
226 double distance;
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
227
757
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 746
diff changeset
228 return (CoordinateSystem3D::ComputeDistance(distance, tmp, plane) &&
746
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
229 distance <= thickness_ / 2.0);
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
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
233 void DicomInstanceParameters::Data::ApplyRescale(Orthanc::ImageAccessor& image,
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
234 bool useDouble) const
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
235 {
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
236 if (image.GetFormat() != Orthanc::PixelFormat_Float32)
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
237 {
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
238 throw Orthanc::OrthancException(Orthanc::ErrorCode_IncompatibleImageFormat);
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
239 }
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
240
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
241 if (hasRescale_)
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
242 {
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
243 const unsigned int width = image.GetWidth();
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
244 const unsigned int height = image.GetHeight();
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
245
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
246 for (unsigned int y = 0; y < height; y++)
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
247 {
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
248 float* p = reinterpret_cast<float*>(image.GetRow(y));
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
249
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
250 if (useDouble)
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
251 {
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
252 // Slower, accurate implementation using double
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
253 for (unsigned int x = 0; x < width; x++, p++)
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
254 {
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
255 double value = static_cast<double>(*p);
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
256 *p = static_cast<float>(value * rescaleSlope_ + rescaleIntercept_);
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
257 }
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
258 }
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
259 else
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
260 {
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
261 // Fast, approximate implementation using float
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
262 for (unsigned int x = 0; x < width; x++, p++)
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
263 {
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
264 *p = (*p) * static_cast<float>(rescaleSlope_) + static_cast<float>(rescaleIntercept_);
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
265 }
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
266 }
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
267 }
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
268 }
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
269 }
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
270
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
271 double DicomInstanceParameters::GetRescaleIntercept() const
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
272 {
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
273 if (data_.hasRescale_)
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
274 {
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
275 return data_.rescaleIntercept_;
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
276 }
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
277 else
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
278 {
956
a7351ad54960 Made IsContextLost automatically set the flag by checking with the emscripten
Benjamin Golinvaux <bgo@osimis.io>
parents: 949
diff changeset
279 LOG(ERROR) << "DicomInstanceParameters::GetRescaleIntercept(): !data_.hasRescale_";
746
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
280 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls);
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
281 }
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
282 }
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
283
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
284
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
285 double DicomInstanceParameters::GetRescaleSlope() const
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
286 {
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
287 if (data_.hasRescale_)
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
288 {
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
289 return data_.rescaleSlope_;
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
290 }
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
291 else
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
292 {
956
a7351ad54960 Made IsContextLost automatically set the flag by checking with the emscripten
Benjamin Golinvaux <bgo@osimis.io>
parents: 949
diff changeset
293 LOG(ERROR) << "DicomInstanceParameters::GetRescaleSlope(): !data_.hasRescale_";
746
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
294 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls);
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
295 }
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
296 }
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
297
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
298
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
299 float DicomInstanceParameters::GetDefaultWindowingCenter() const
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
300 {
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
301 if (data_.hasDefaultWindowing_)
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
302 {
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
303 return data_.defaultWindowingCenter_;
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
304 }
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
305 else
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
306 {
956
a7351ad54960 Made IsContextLost automatically set the flag by checking with the emscripten
Benjamin Golinvaux <bgo@osimis.io>
parents: 949
diff changeset
307 LOG(ERROR) << "DicomInstanceParameters::GetDefaultWindowingCenter(): !data_.hasRescale_";
746
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
308 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls);
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
309 }
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
310 }
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
311
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
312
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
313 float DicomInstanceParameters::GetDefaultWindowingWidth() const
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
314 {
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
315 if (data_.hasDefaultWindowing_)
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
316 {
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
317 return data_.defaultWindowingWidth_;
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
318 }
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
319 else
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
320 {
956
a7351ad54960 Made IsContextLost automatically set the flag by checking with the emscripten
Benjamin Golinvaux <bgo@osimis.io>
parents: 949
diff changeset
321 LOG(ERROR) << "DicomInstanceParameters::GetDefaultWindowingWidth(): !data_.hasRescale_";
746
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
322 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls);
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
323 }
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
324 }
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
325
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
326
768
55411e7da2f7 LookupTableTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 762
diff changeset
327 Orthanc::ImageAccessor* DicomInstanceParameters::ConvertToFloat(const Orthanc::ImageAccessor& pixelData) const
55411e7da2f7 LookupTableTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 762
diff changeset
328 {
55411e7da2f7 LookupTableTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 762
diff changeset
329 std::auto_ptr<Orthanc::Image> converted(new Orthanc::Image(Orthanc::PixelFormat_Float32,
55411e7da2f7 LookupTableTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 762
diff changeset
330 pixelData.GetWidth(),
55411e7da2f7 LookupTableTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 762
diff changeset
331 pixelData.GetHeight(),
55411e7da2f7 LookupTableTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 762
diff changeset
332 false));
55411e7da2f7 LookupTableTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 762
diff changeset
333 Orthanc::ImageProcessing::Convert(*converted, pixelData);
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 // Correct rescale slope/intercept if need be
55411e7da2f7 LookupTableTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 762
diff changeset
336 data_.ApplyRescale(*converted, (pixelData.GetFormat() == Orthanc::PixelFormat_Grayscale32));
55411e7da2f7 LookupTableTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 762
diff changeset
337
55411e7da2f7 LookupTableTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 762
diff changeset
338 return converted.release();
55411e7da2f7 LookupTableTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 762
diff changeset
339 }
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
55411e7da2f7 LookupTableTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 762
diff changeset
342
55411e7da2f7 LookupTableTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 762
diff changeset
343 TextureBaseSceneLayer* DicomInstanceParameters::CreateTexture
55411e7da2f7 LookupTableTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 762
diff changeset
344 (const Orthanc::ImageAccessor& pixelData) const
746
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
345 {
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
346 assert(sizeof(float) == 4);
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
347
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
348 Orthanc::PixelFormat sourceFormat = pixelData.GetFormat();
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
349
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
350 if (sourceFormat != GetExpectedPixelFormat())
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
351 {
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
352 throw Orthanc::OrthancException(Orthanc::ErrorCode_IncompatibleImageFormat);
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
353 }
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
354
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
355 if (sourceFormat == Orthanc::PixelFormat_RGB24)
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
356 {
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
357 // 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
358 return new ColorTextureSceneLayer(pixelData);
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
359 }
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
360 else
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
361 {
768
55411e7da2f7 LookupTableTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 762
diff changeset
362 // This is the case of a grayscale frame. Convert it to Float32.
55411e7da2f7 LookupTableTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 762
diff changeset
363 std::auto_ptr<FloatTextureSceneLayer> texture;
746
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
364
768
55411e7da2f7 LookupTableTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 762
diff changeset
365 if (pixelData.GetFormat() == Orthanc::PixelFormat_Float32)
746
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
366 {
768
55411e7da2f7 LookupTableTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 762
diff changeset
367 texture.reset(new FloatTextureSceneLayer(pixelData));
55411e7da2f7 LookupTableTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 762
diff changeset
368 }
55411e7da2f7 LookupTableTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 762
diff changeset
369 else
55411e7da2f7 LookupTableTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 762
diff changeset
370 {
55411e7da2f7 LookupTableTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 762
diff changeset
371 std::auto_ptr<Orthanc::ImageAccessor> converted(ConvertToFloat(pixelData));
746
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
372 texture.reset(new FloatTextureSceneLayer(*converted));
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
373 }
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
374
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
375 if (data_.hasDefaultWindowing_)
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
376 {
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
377 texture->SetCustomWindowing(data_.defaultWindowingCenter_,
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
378 data_.defaultWindowingWidth_);
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 return texture.release();
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
382 }
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
383 }
768
55411e7da2f7 LookupTableTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 762
diff changeset
384
55411e7da2f7 LookupTableTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 762
diff changeset
385
55411e7da2f7 LookupTableTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 762
diff changeset
386 LookupTableTextureSceneLayer* DicomInstanceParameters::CreateLookupTableTexture
55411e7da2f7 LookupTableTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 762
diff changeset
387 (const Orthanc::ImageAccessor& pixelData) const
55411e7da2f7 LookupTableTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 762
diff changeset
388 {
55411e7da2f7 LookupTableTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 762
diff changeset
389 std::auto_ptr<FloatTextureSceneLayer> texture;
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 if (pixelData.GetFormat() == Orthanc::PixelFormat_Float32)
55411e7da2f7 LookupTableTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 762
diff changeset
392 {
55411e7da2f7 LookupTableTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 762
diff changeset
393 return new LookupTableTextureSceneLayer(pixelData);
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 else
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 std::auto_ptr<Orthanc::ImageAccessor> converted(ConvertToFloat(pixelData));
55411e7da2f7 LookupTableTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 762
diff changeset
398 return new LookupTableTextureSceneLayer(*converted);
55411e7da2f7 LookupTableTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 762
diff changeset
399 }
55411e7da2f7 LookupTableTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 762
diff changeset
400 }
746
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
401 }