annotate OrthancStone/Sources/Deprecated/Radiography/RadiographyDicomLayer.cpp @ 1556:8898f8f755c8

typo
author Sebastien Jodogne <s.jodogne@gmail.com>
date Tue, 18 Aug 2020 11:58:47 +0200
parents 244ad1e4e76a
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
430
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
1 /**
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
2 * Stone of Orthanc
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
4 * Department, University Hospital of Liege, Belgium
1280
1c7ae79c426d fix copyright years
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1272
diff changeset
5 * Copyright (C) 2017-2020 Osimis S.A., Belgium
430
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
6 *
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
7 * This program is free software: you can redistribute it and/or
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
8 * modify it under the terms of the GNU Affero General Public License
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
9 * as published by the Free Software Foundation, either version 3 of
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
10 * the License, or (at your option) any later version.
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
11 *
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
12 * This program is distributed in the hope that it will be useful, but
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
15 * Affero General Public License for more details.
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
16 *
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
17 * You should have received a copy of the GNU Affero General Public License
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
19 **/
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
20
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
21
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
22 #include "RadiographyDicomLayer.h"
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
23
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
24 #include "RadiographyScene.h"
732
c35e98d22764 move Deprecated classes to a separate folder
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 714
diff changeset
25 #include "../Deprecated/Toolbox/DicomFrameConverter.h"
1455
30deba7bc8e2 simplifying include_directories
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1398
diff changeset
26 #include "../Toolbox/ImageGeometry.h"
430
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
27
1455
30deba7bc8e2 simplifying include_directories
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1398
diff changeset
28 #include <OrthancException.h>
30deba7bc8e2 simplifying include_directories
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1398
diff changeset
29 #include <Images/Image.h>
30deba7bc8e2 simplifying include_directories
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1398
diff changeset
30 #include <Images/ImageProcessing.h>
30deba7bc8e2 simplifying include_directories
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1398
diff changeset
31 #include <DicomDatasetReader.h>
430
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
32
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
33 static OrthancPlugins::DicomTag ConvertTag(const Orthanc::DicomTag& tag)
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
34 {
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
35 return OrthancPlugins::DicomTag(tag.GetGroup(), tag.GetElement());
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
36 }
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
37
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
38 namespace OrthancStone
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
39 {
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
40
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
41 void RadiographyDicomLayer::ApplyConverter()
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
42 {
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
43 if (source_.get() != NULL &&
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
44 converter_.get() != NULL)
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
45 {
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
46 converted_.reset(converter_->ConvertFrame(*source_));
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
47 }
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
48 }
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
49
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
50
1066
b537002f83a9 removing broker from deprecated classes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 739
diff changeset
51 RadiographyDicomLayer::RadiographyDicomLayer(const RadiographyScene& scene) :
b537002f83a9 removing broker from deprecated classes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 739
diff changeset
52 RadiographyLayer(scene)
655
1e26bb5f2a02 Fixed truncating conversion warnings + fixed deletion of incomplete type
Benjamin Golinvaux <bgo@osimis.io>
parents: 649
diff changeset
53 {
1e26bb5f2a02 Fixed truncating conversion warnings + fixed deletion of incomplete type
Benjamin Golinvaux <bgo@osimis.io>
parents: 649
diff changeset
54
1e26bb5f2a02 Fixed truncating conversion warnings + fixed deletion of incomplete type
Benjamin Golinvaux <bgo@osimis.io>
parents: 649
diff changeset
55 }
1e26bb5f2a02 Fixed truncating conversion warnings + fixed deletion of incomplete type
Benjamin Golinvaux <bgo@osimis.io>
parents: 649
diff changeset
56
430
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
57 void RadiographyDicomLayer::SetDicomTags(const OrthancPlugins::FullOrthancDataset& dataset)
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
58 {
714
d2c0e347ddc2 deprecating DicomFrameConverter
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 655
diff changeset
59 converter_.reset(new Deprecated::DicomFrameConverter);
430
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
60 converter_->ReadParameters(dataset);
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
61 ApplyConverter();
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
62
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
63 std::string tmp;
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
64 Vector pixelSpacing;
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
65
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
66 if (dataset.GetStringValue(tmp, ConvertTag(Orthanc::DICOM_TAG_PIXEL_SPACING)) &&
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
67 LinearAlgebra::ParseVector(pixelSpacing, tmp) &&
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
68 pixelSpacing.size() == 2)
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
69 {
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
70 SetPixelSpacing(pixelSpacing[0], pixelSpacing[1]);
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
71 }
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
72
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
73 OrthancPlugins::DicomDatasetReader reader(dataset);
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
74
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
75 unsigned int width, height;
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
76 if (!reader.GetUnsignedIntegerValue(width, ConvertTag(Orthanc::DICOM_TAG_COLUMNS)) ||
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
77 !reader.GetUnsignedIntegerValue(height, ConvertTag(Orthanc::DICOM_TAG_ROWS)))
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
78 {
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
79 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadFileFormat);
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
80 }
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
81 else
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
82 {
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
83 SetSize(width, height);
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
84 }
432
4eb96c6b4e96 improved handling of MONOCHROME1, background and invertion
am@osimis.io
parents: 430
diff changeset
85
4eb96c6b4e96 improved handling of MONOCHROME1, background and invertion
am@osimis.io
parents: 430
diff changeset
86 if (dataset.GetStringValue(tmp, ConvertTag(Orthanc::DICOM_TAG_PHOTOMETRIC_INTERPRETATION)))
4eb96c6b4e96 improved handling of MONOCHROME1, background and invertion
am@osimis.io
parents: 430
diff changeset
87 {
4eb96c6b4e96 improved handling of MONOCHROME1, background and invertion
am@osimis.io
parents: 430
diff changeset
88 if (tmp == "MONOCHROME1")
4eb96c6b4e96 improved handling of MONOCHROME1, background and invertion
am@osimis.io
parents: 430
diff changeset
89 {
739
be9c1530d40a deprecating enum SliceImageQuality
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 732
diff changeset
90 SetPreferredPhotomotricDisplayMode(RadiographyPhotometricDisplayMode_Monochrome1);
432
4eb96c6b4e96 improved handling of MONOCHROME1, background and invertion
am@osimis.io
parents: 430
diff changeset
91 }
4eb96c6b4e96 improved handling of MONOCHROME1, background and invertion
am@osimis.io
parents: 430
diff changeset
92 else if (tmp == "MONOCHROME2")
4eb96c6b4e96 improved handling of MONOCHROME1, background and invertion
am@osimis.io
parents: 430
diff changeset
93 {
739
be9c1530d40a deprecating enum SliceImageQuality
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 732
diff changeset
94 SetPreferredPhotomotricDisplayMode(RadiographyPhotometricDisplayMode_Monochrome2);
432
4eb96c6b4e96 improved handling of MONOCHROME1, background and invertion
am@osimis.io
parents: 430
diff changeset
95 }
4eb96c6b4e96 improved handling of MONOCHROME1, background and invertion
am@osimis.io
parents: 430
diff changeset
96 }
430
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
97 }
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
98
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
99 void RadiographyDicomLayer::SetSourceImage(Orthanc::ImageAccessor* image) // Takes ownership
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
100 {
1298
8a0a62189f46 replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1280
diff changeset
101 std::unique_ptr<Orthanc::ImageAccessor> raii(image);
430
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
102
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
103 if (image == NULL)
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
104 {
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
105 throw Orthanc::OrthancException(Orthanc::ErrorCode_NullPointer);
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
106 }
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
107
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
108 SetSize(image->GetWidth(), image->GetHeight());
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
109
1298
8a0a62189f46 replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1280
diff changeset
110 #if __cplusplus < 201103L
1330
a72c2c9af49a minimal option for GetSceneExtent, especially for masks
Alain Mazy <alain@mazy.be>
parents: 1298
diff changeset
111 source_.reset(raii.release());
1298
8a0a62189f46 replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1280
diff changeset
112 #else
1330
a72c2c9af49a minimal option for GetSceneExtent, especially for masks
Alain Mazy <alain@mazy.be>
parents: 1298
diff changeset
113 source_ = std::move(raii);
1298
8a0a62189f46 replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1280
diff changeset
114 #endif
8a0a62189f46 replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1280
diff changeset
115
430
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
116 ApplyConverter();
503
77e0eb83ff63 layers are now Observable and emitting LayerEdited messages
amazy
parents: 432
diff changeset
117
623
42dadae61fa9 renamed IObservable::EmitMessage() as BroadcastMessage()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 503
diff changeset
118 BroadcastMessage(RadiographyLayer::LayerEditedMessage(*this));
430
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
119 }
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
120
1272
a989c7d46b9a options to avoid multiple LayerEditedMessage
Alain Mazy <alain@mazy.be>
parents: 1201
diff changeset
121 void RadiographyDicomLayer::SetSourceImage(Orthanc::ImageAccessor* image, double newPixelSpacingX, double newPixelSpacingY, bool emitLayerEditedEvent) // Takes ownership
1118
35e798b16b65 RadiographyDicomLayer: allow replacing low res image by high res image
Alain Mazy <alain@mazy.be>
parents: 739
diff changeset
122 {
1298
8a0a62189f46 replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1280
diff changeset
123 std::unique_ptr<Orthanc::ImageAccessor> raii(image);
1118
35e798b16b65 RadiographyDicomLayer: allow replacing low res image by high res image
Alain Mazy <alain@mazy.be>
parents: 739
diff changeset
124
35e798b16b65 RadiographyDicomLayer: allow replacing low res image by high res image
Alain Mazy <alain@mazy.be>
parents: 739
diff changeset
125 if (image == NULL)
35e798b16b65 RadiographyDicomLayer: allow replacing low res image by high res image
Alain Mazy <alain@mazy.be>
parents: 739
diff changeset
126 {
35e798b16b65 RadiographyDicomLayer: allow replacing low res image by high res image
Alain Mazy <alain@mazy.be>
parents: 739
diff changeset
127 throw Orthanc::OrthancException(Orthanc::ErrorCode_NullPointer);
35e798b16b65 RadiographyDicomLayer: allow replacing low res image by high res image
Alain Mazy <alain@mazy.be>
parents: 739
diff changeset
128 }
35e798b16b65 RadiographyDicomLayer: allow replacing low res image by high res image
Alain Mazy <alain@mazy.be>
parents: 739
diff changeset
129
1272
a989c7d46b9a options to avoid multiple LayerEditedMessage
Alain Mazy <alain@mazy.be>
parents: 1201
diff changeset
130 SetSize(image->GetWidth(), image->GetHeight(), false);
1118
35e798b16b65 RadiographyDicomLayer: allow replacing low res image by high res image
Alain Mazy <alain@mazy.be>
parents: 739
diff changeset
131
1298
8a0a62189f46 replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1280
diff changeset
132 #if __cplusplus < 201103L
8a0a62189f46 replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1280
diff changeset
133 source_.reset(raii.release());
8a0a62189f46 replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1280
diff changeset
134 #else
8a0a62189f46 replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1280
diff changeset
135 source_ = std::move(raii);
8a0a62189f46 replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1280
diff changeset
136 #endif
8a0a62189f46 replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1280
diff changeset
137
1118
35e798b16b65 RadiographyDicomLayer: allow replacing low res image by high res image
Alain Mazy <alain@mazy.be>
parents: 739
diff changeset
138 ApplyConverter();
35e798b16b65 RadiographyDicomLayer: allow replacing low res image by high res image
Alain Mazy <alain@mazy.be>
parents: 739
diff changeset
139
35e798b16b65 RadiographyDicomLayer: allow replacing low res image by high res image
Alain Mazy <alain@mazy.be>
parents: 739
diff changeset
140 SetPixelSpacing(newPixelSpacingX, newPixelSpacingY, false);
35e798b16b65 RadiographyDicomLayer: allow replacing low res image by high res image
Alain Mazy <alain@mazy.be>
parents: 739
diff changeset
141
1272
a989c7d46b9a options to avoid multiple LayerEditedMessage
Alain Mazy <alain@mazy.be>
parents: 1201
diff changeset
142 if (emitLayerEditedEvent)
a989c7d46b9a options to avoid multiple LayerEditedMessage
Alain Mazy <alain@mazy.be>
parents: 1201
diff changeset
143 {
a989c7d46b9a options to avoid multiple LayerEditedMessage
Alain Mazy <alain@mazy.be>
parents: 1201
diff changeset
144 BroadcastMessage(RadiographyLayer::LayerEditedMessage(*this));
a989c7d46b9a options to avoid multiple LayerEditedMessage
Alain Mazy <alain@mazy.be>
parents: 1201
diff changeset
145 }
1118
35e798b16b65 RadiographyDicomLayer: allow replacing low res image by high res image
Alain Mazy <alain@mazy.be>
parents: 739
diff changeset
146 }
35e798b16b65 RadiographyDicomLayer: allow replacing low res image by high res image
Alain Mazy <alain@mazy.be>
parents: 739
diff changeset
147
649
f1bfe3d1759f Moved RadiographyDicomLayer::SetDicomFrameConverter to cpp file to prevent
Benjamin Golinvaux <bgo@osimis.io>
parents: 623
diff changeset
148
714
d2c0e347ddc2 deprecating DicomFrameConverter
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 655
diff changeset
149 void RadiographyDicomLayer::SetDicomFrameConverter(Deprecated::DicomFrameConverter* converter)
649
f1bfe3d1759f Moved RadiographyDicomLayer::SetDicomFrameConverter to cpp file to prevent
Benjamin Golinvaux <bgo@osimis.io>
parents: 623
diff changeset
150 {
f1bfe3d1759f Moved RadiographyDicomLayer::SetDicomFrameConverter to cpp file to prevent
Benjamin Golinvaux <bgo@osimis.io>
parents: 623
diff changeset
151 converter_.reset(converter);
f1bfe3d1759f Moved RadiographyDicomLayer::SetDicomFrameConverter to cpp file to prevent
Benjamin Golinvaux <bgo@osimis.io>
parents: 623
diff changeset
152 }
f1bfe3d1759f Moved RadiographyDicomLayer::SetDicomFrameConverter to cpp file to prevent
Benjamin Golinvaux <bgo@osimis.io>
parents: 623
diff changeset
153
430
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
154 void RadiographyDicomLayer::Render(Orthanc::ImageAccessor& buffer,
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
155 const AffineTransform2D& viewTransform,
1196
a5f2a6b04a31 RadiographyScene: windowing is now only applied to the Dicom layer
Alain Mazy <alain@mazy.be>
parents: 1118
diff changeset
156 ImageInterpolation interpolation,
a5f2a6b04a31 RadiographyScene: windowing is now only applied to the Dicom layer
Alain Mazy <alain@mazy.be>
parents: 1118
diff changeset
157 float windowCenter,
a5f2a6b04a31 RadiographyScene: windowing is now only applied to the Dicom layer
Alain Mazy <alain@mazy.be>
parents: 1118
diff changeset
158 float windowWidth,
a5f2a6b04a31 RadiographyScene: windowing is now only applied to the Dicom layer
Alain Mazy <alain@mazy.be>
parents: 1118
diff changeset
159 bool applyWindowing) const
430
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
160 {
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
161 if (converted_.get() != NULL)
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
162 {
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
163 if (converted_->GetFormat() != Orthanc::PixelFormat_Float32)
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
164 {
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
165 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError);
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
166 }
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
167
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
168 unsigned int cropX, cropY, cropWidth, cropHeight;
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
169 GetCrop(cropX, cropY, cropWidth, cropHeight);
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
170
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
171 AffineTransform2D t = AffineTransform2D::Combine(
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
172 viewTransform, GetTransform(),
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
173 AffineTransform2D::CreateOffset(cropX, cropY));
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
174
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
175 Orthanc::ImageAccessor cropped;
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
176 converted_->GetRegion(cropped, cropX, cropY, cropWidth, cropHeight);
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
177
1201
ab958fd99b07 RadiographyScene fixes
Alain Mazy <alain@mazy.be>
parents: 1196
diff changeset
178 unsigned int x1, y1, x2, y2;
ab958fd99b07 RadiographyScene fixes
Alain Mazy <alain@mazy.be>
parents: 1196
diff changeset
179 if (!OrthancStone::GetProjectiveTransformExtent(x1, y1, x2, y2,
ab958fd99b07 RadiographyScene fixes
Alain Mazy <alain@mazy.be>
parents: 1196
diff changeset
180 t.GetHomogeneousMatrix(),
ab958fd99b07 RadiographyScene fixes
Alain Mazy <alain@mazy.be>
parents: 1196
diff changeset
181 cropped.GetWidth(),
ab958fd99b07 RadiographyScene fixes
Alain Mazy <alain@mazy.be>
parents: 1196
diff changeset
182 cropped.GetHeight(),
ab958fd99b07 RadiographyScene fixes
Alain Mazy <alain@mazy.be>
parents: 1196
diff changeset
183 buffer.GetWidth(),
ab958fd99b07 RadiographyScene fixes
Alain Mazy <alain@mazy.be>
parents: 1196
diff changeset
184 buffer.GetHeight()))
ab958fd99b07 RadiographyScene fixes
Alain Mazy <alain@mazy.be>
parents: 1196
diff changeset
185 {
ab958fd99b07 RadiographyScene fixes
Alain Mazy <alain@mazy.be>
parents: 1196
diff changeset
186 return; // layer is outside the buffer
ab958fd99b07 RadiographyScene fixes
Alain Mazy <alain@mazy.be>
parents: 1196
diff changeset
187 }
ab958fd99b07 RadiographyScene fixes
Alain Mazy <alain@mazy.be>
parents: 1196
diff changeset
188
430
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
189 t.Apply(buffer, cropped, interpolation, false);
1196
a5f2a6b04a31 RadiographyScene: windowing is now only applied to the Dicom layer
Alain Mazy <alain@mazy.be>
parents: 1118
diff changeset
190
a5f2a6b04a31 RadiographyScene: windowing is now only applied to the Dicom layer
Alain Mazy <alain@mazy.be>
parents: 1118
diff changeset
191 if (applyWindowing)
a5f2a6b04a31 RadiographyScene: windowing is now only applied to the Dicom layer
Alain Mazy <alain@mazy.be>
parents: 1118
diff changeset
192 {
a5f2a6b04a31 RadiographyScene: windowing is now only applied to the Dicom layer
Alain Mazy <alain@mazy.be>
parents: 1118
diff changeset
193 // apply windowing but stay in the range [0.0, 65535.0]
a5f2a6b04a31 RadiographyScene: windowing is now only applied to the Dicom layer
Alain Mazy <alain@mazy.be>
parents: 1118
diff changeset
194 float w0 = windowCenter - windowWidth / 2.0f;
a5f2a6b04a31 RadiographyScene: windowing is now only applied to the Dicom layer
Alain Mazy <alain@mazy.be>
parents: 1118
diff changeset
195 float w1 = windowCenter + windowWidth / 2.0f;
a5f2a6b04a31 RadiographyScene: windowing is now only applied to the Dicom layer
Alain Mazy <alain@mazy.be>
parents: 1118
diff changeset
196
a5f2a6b04a31 RadiographyScene: windowing is now only applied to the Dicom layer
Alain Mazy <alain@mazy.be>
parents: 1118
diff changeset
197 if (windowWidth >= 0.001f) // Avoid division by zero at (*)
a5f2a6b04a31 RadiographyScene: windowing is now only applied to the Dicom layer
Alain Mazy <alain@mazy.be>
parents: 1118
diff changeset
198 {
a5f2a6b04a31 RadiographyScene: windowing is now only applied to the Dicom layer
Alain Mazy <alain@mazy.be>
parents: 1118
diff changeset
199 float scaling = 1.0f / (w1 - w0) * 65535.0f;
a5f2a6b04a31 RadiographyScene: windowing is now only applied to the Dicom layer
Alain Mazy <alain@mazy.be>
parents: 1118
diff changeset
200 for (unsigned int y = y1; y <= y2; y++)
a5f2a6b04a31 RadiographyScene: windowing is now only applied to the Dicom layer
Alain Mazy <alain@mazy.be>
parents: 1118
diff changeset
201 {
a5f2a6b04a31 RadiographyScene: windowing is now only applied to the Dicom layer
Alain Mazy <alain@mazy.be>
parents: 1118
diff changeset
202 float* p = reinterpret_cast<float*>(buffer.GetRow(y)) + x1;
a5f2a6b04a31 RadiographyScene: windowing is now only applied to the Dicom layer
Alain Mazy <alain@mazy.be>
parents: 1118
diff changeset
203
a5f2a6b04a31 RadiographyScene: windowing is now only applied to the Dicom layer
Alain Mazy <alain@mazy.be>
parents: 1118
diff changeset
204 for (unsigned int x = x1; x <= x2; x++, p++)
a5f2a6b04a31 RadiographyScene: windowing is now only applied to the Dicom layer
Alain Mazy <alain@mazy.be>
parents: 1118
diff changeset
205 {
a5f2a6b04a31 RadiographyScene: windowing is now only applied to the Dicom layer
Alain Mazy <alain@mazy.be>
parents: 1118
diff changeset
206 if (*p >= w1)
a5f2a6b04a31 RadiographyScene: windowing is now only applied to the Dicom layer
Alain Mazy <alain@mazy.be>
parents: 1118
diff changeset
207 {
a5f2a6b04a31 RadiographyScene: windowing is now only applied to the Dicom layer
Alain Mazy <alain@mazy.be>
parents: 1118
diff changeset
208 *p = 65535.0;
a5f2a6b04a31 RadiographyScene: windowing is now only applied to the Dicom layer
Alain Mazy <alain@mazy.be>
parents: 1118
diff changeset
209 }
a5f2a6b04a31 RadiographyScene: windowing is now only applied to the Dicom layer
Alain Mazy <alain@mazy.be>
parents: 1118
diff changeset
210 else if (*p <= w0)
a5f2a6b04a31 RadiographyScene: windowing is now only applied to the Dicom layer
Alain Mazy <alain@mazy.be>
parents: 1118
diff changeset
211 {
a5f2a6b04a31 RadiographyScene: windowing is now only applied to the Dicom layer
Alain Mazy <alain@mazy.be>
parents: 1118
diff changeset
212 *p = 0;
a5f2a6b04a31 RadiographyScene: windowing is now only applied to the Dicom layer
Alain Mazy <alain@mazy.be>
parents: 1118
diff changeset
213 }
a5f2a6b04a31 RadiographyScene: windowing is now only applied to the Dicom layer
Alain Mazy <alain@mazy.be>
parents: 1118
diff changeset
214 else
a5f2a6b04a31 RadiographyScene: windowing is now only applied to the Dicom layer
Alain Mazy <alain@mazy.be>
parents: 1118
diff changeset
215 {
a5f2a6b04a31 RadiographyScene: windowing is now only applied to the Dicom layer
Alain Mazy <alain@mazy.be>
parents: 1118
diff changeset
216 // https://en.wikipedia.org/wiki/Linear_interpolation
a5f2a6b04a31 RadiographyScene: windowing is now only applied to the Dicom layer
Alain Mazy <alain@mazy.be>
parents: 1118
diff changeset
217 *p = scaling * (*p - w0); // (*)
a5f2a6b04a31 RadiographyScene: windowing is now only applied to the Dicom layer
Alain Mazy <alain@mazy.be>
parents: 1118
diff changeset
218 }
a5f2a6b04a31 RadiographyScene: windowing is now only applied to the Dicom layer
Alain Mazy <alain@mazy.be>
parents: 1118
diff changeset
219 }
a5f2a6b04a31 RadiographyScene: windowing is now only applied to the Dicom layer
Alain Mazy <alain@mazy.be>
parents: 1118
diff changeset
220 }
a5f2a6b04a31 RadiographyScene: windowing is now only applied to the Dicom layer
Alain Mazy <alain@mazy.be>
parents: 1118
diff changeset
221 }
a5f2a6b04a31 RadiographyScene: windowing is now only applied to the Dicom layer
Alain Mazy <alain@mazy.be>
parents: 1118
diff changeset
222 }
a5f2a6b04a31 RadiographyScene: windowing is now only applied to the Dicom layer
Alain Mazy <alain@mazy.be>
parents: 1118
diff changeset
223
430
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
224 }
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
225 }
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
226
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
227
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
228 bool RadiographyDicomLayer::GetDefaultWindowing(float& center,
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
229 float& width) const
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
230 {
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
231 if (converter_.get() != NULL &&
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
232 converter_->HasDefaultWindow())
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
233 {
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
234 center = static_cast<float>(converter_->GetDefaultWindowCenter());
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
235 width = static_cast<float>(converter_->GetDefaultWindowWidth());
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
236 return true;
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
237 }
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
238 else
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
239 {
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
240 return false;
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
241 }
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
242 }
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
243
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
244
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
245 bool RadiographyDicomLayer::GetRange(float& minValue,
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
246 float& maxValue) const
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
247 {
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
248 if (converted_.get() != NULL)
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
249 {
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
250 if (converted_->GetFormat() != Orthanc::PixelFormat_Float32)
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
251 {
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
252 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError);
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
253 }
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
254
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
255 Orthanc::ImageProcessing::GetMinMaxFloatValue(minValue, maxValue, *converted_);
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
256 return true;
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
257 }
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
258 else
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
259 {
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
260 return false;
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
261 }
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
262 }
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
263
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
264 }