annotate Framework/ImagedVolumeParameters.cpp @ 291:5fe243cef6e9

cppcheck
author Sebastien Jodogne <s.jodogne@gmail.com>
date Thu, 13 Jul 2023 16:57:27 +0200
parents 77afef2cf64b
children 7020852a8fa9
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
4a7a53257c7d initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1 /**
4a7a53257c7d initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2 * Orthanc - A Lightweight, RESTful DICOM Store
4a7a53257c7d initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
4a7a53257c7d initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
4 * Department, University Hospital of Liege, Belgium
254
20a730889ae2 upgrade to 2023
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 242
diff changeset
5 * Copyright (C) 2017-2023 Osimis S.A., Belgium
20a730889ae2 upgrade to 2023
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 242
diff changeset
6 * Copyright (C) 2021-2023 Sebastien Jodogne, ICTEAM UCLouvain, Belgium
0
4a7a53257c7d initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
7 *
4a7a53257c7d initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
8 * This program is free software: you can redistribute it and/or
4a7a53257c7d initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
9 * modify it under the terms of the GNU Affero General Public License
4a7a53257c7d initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
10 * as published by the Free Software Foundation, either version 3 of
4a7a53257c7d initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
11 * the License, or (at your option) any later version.
4a7a53257c7d initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
12 *
4a7a53257c7d initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
13 * This program is distributed in the hope that it will be useful, but
4a7a53257c7d initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
4a7a53257c7d initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
4a7a53257c7d initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
16 * Affero General Public License for more details.
4a7a53257c7d initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
17 *
4a7a53257c7d initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
18 * You should have received a copy of the GNU Affero General Public License
4a7a53257c7d initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
19 * along with this program. If not, see <http://www.gnu.org/licenses/>.
4a7a53257c7d initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
20 **/
4a7a53257c7d initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
21
4a7a53257c7d initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
22
16
7a88c614be04 preparing for precompiled headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 0
diff changeset
23 #include "PrecompiledHeadersWSI.h"
0
4a7a53257c7d initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
24 #include "ImagedVolumeParameters.h"
4a7a53257c7d initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
25
192
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 175
diff changeset
26 #include <OrthancException.h>
0
4a7a53257c7d initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
27
4a7a53257c7d initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
28 namespace OrthancWSI
4a7a53257c7d initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
29 {
279
77afef2cf64b automated extraction of the imaged volume if using OpenSlide
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 254
diff changeset
30 ImagedVolumeParameters::ImagedVolumeParameters() :
77afef2cf64b automated extraction of the imaged volume if using OpenSlide
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 254
diff changeset
31 hasWidth_(false),
291
5fe243cef6e9 cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 279
diff changeset
32 hasHeight_(false),
5fe243cef6e9 cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 279
diff changeset
33 width_(0),
5fe243cef6e9 cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 279
diff changeset
34 height_(0),
5fe243cef6e9 cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 279
diff changeset
35
279
77afef2cf64b automated extraction of the imaged volume if using OpenSlide
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 254
diff changeset
36 // Typical parameters for a specimen, in millimeters
291
5fe243cef6e9 cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 279
diff changeset
37 depth_(1),
5fe243cef6e9 cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 279
diff changeset
38 offsetX_(20),
5fe243cef6e9 cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 279
diff changeset
39 offsetY_(40)
5fe243cef6e9 cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 279
diff changeset
40 {
0
4a7a53257c7d initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
41 }
4a7a53257c7d initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
42
4a7a53257c7d initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
43
279
77afef2cf64b automated extraction of the imaged volume if using OpenSlide
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 254
diff changeset
44 float ImagedVolumeParameters::GetWidth() const
77afef2cf64b automated extraction of the imaged volume if using OpenSlide
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 254
diff changeset
45 {
77afef2cf64b automated extraction of the imaged volume if using OpenSlide
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 254
diff changeset
46 if (hasWidth_)
77afef2cf64b automated extraction of the imaged volume if using OpenSlide
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 254
diff changeset
47 {
77afef2cf64b automated extraction of the imaged volume if using OpenSlide
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 254
diff changeset
48 return width_;
77afef2cf64b automated extraction of the imaged volume if using OpenSlide
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 254
diff changeset
49 }
77afef2cf64b automated extraction of the imaged volume if using OpenSlide
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 254
diff changeset
50 else
77afef2cf64b automated extraction of the imaged volume if using OpenSlide
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 254
diff changeset
51 {
77afef2cf64b automated extraction of the imaged volume if using OpenSlide
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 254
diff changeset
52 return 15; // Typical width of a specimen
77afef2cf64b automated extraction of the imaged volume if using OpenSlide
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 254
diff changeset
53 }
77afef2cf64b automated extraction of the imaged volume if using OpenSlide
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 254
diff changeset
54 }
77afef2cf64b automated extraction of the imaged volume if using OpenSlide
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 254
diff changeset
55
77afef2cf64b automated extraction of the imaged volume if using OpenSlide
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 254
diff changeset
56
77afef2cf64b automated extraction of the imaged volume if using OpenSlide
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 254
diff changeset
57 float ImagedVolumeParameters::GetHeight() const
77afef2cf64b automated extraction of the imaged volume if using OpenSlide
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 254
diff changeset
58 {
77afef2cf64b automated extraction of the imaged volume if using OpenSlide
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 254
diff changeset
59 if (hasHeight_)
77afef2cf64b automated extraction of the imaged volume if using OpenSlide
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 254
diff changeset
60 {
77afef2cf64b automated extraction of the imaged volume if using OpenSlide
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 254
diff changeset
61 return height_;
77afef2cf64b automated extraction of the imaged volume if using OpenSlide
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 254
diff changeset
62 }
77afef2cf64b automated extraction of the imaged volume if using OpenSlide
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 254
diff changeset
63 else
77afef2cf64b automated extraction of the imaged volume if using OpenSlide
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 254
diff changeset
64 {
77afef2cf64b automated extraction of the imaged volume if using OpenSlide
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 254
diff changeset
65 return 15; // Typical height of a specimen
77afef2cf64b automated extraction of the imaged volume if using OpenSlide
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 254
diff changeset
66 }
77afef2cf64b automated extraction of the imaged volume if using OpenSlide
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 254
diff changeset
67 }
77afef2cf64b automated extraction of the imaged volume if using OpenSlide
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 254
diff changeset
68
77afef2cf64b automated extraction of the imaged volume if using OpenSlide
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 254
diff changeset
69
0
4a7a53257c7d initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
70 void ImagedVolumeParameters::SetWidth(float width)
4a7a53257c7d initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
71 {
4a7a53257c7d initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
72 if (width <= 0)
4a7a53257c7d initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
73 {
4a7a53257c7d initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
74 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange);
4a7a53257c7d initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
75 }
279
77afef2cf64b automated extraction of the imaged volume if using OpenSlide
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 254
diff changeset
76 else
77afef2cf64b automated extraction of the imaged volume if using OpenSlide
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 254
diff changeset
77 {
77afef2cf64b automated extraction of the imaged volume if using OpenSlide
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 254
diff changeset
78 width_ = width;
77afef2cf64b automated extraction of the imaged volume if using OpenSlide
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 254
diff changeset
79 hasWidth_ = true;
77afef2cf64b automated extraction of the imaged volume if using OpenSlide
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 254
diff changeset
80 }
0
4a7a53257c7d initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
81 }
4a7a53257c7d initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
82
4a7a53257c7d initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
83
4a7a53257c7d initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
84 void ImagedVolumeParameters::SetHeight(float height)
4a7a53257c7d initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
85 {
4a7a53257c7d initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
86 if (height <= 0)
4a7a53257c7d initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
87 {
4a7a53257c7d initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
88 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange);
4a7a53257c7d initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
89 }
279
77afef2cf64b automated extraction of the imaged volume if using OpenSlide
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 254
diff changeset
90 else
77afef2cf64b automated extraction of the imaged volume if using OpenSlide
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 254
diff changeset
91 {
77afef2cf64b automated extraction of the imaged volume if using OpenSlide
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 254
diff changeset
92 height_ = height;
77afef2cf64b automated extraction of the imaged volume if using OpenSlide
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 254
diff changeset
93 hasHeight_ = true;
77afef2cf64b automated extraction of the imaged volume if using OpenSlide
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 254
diff changeset
94 }
0
4a7a53257c7d initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
95 }
4a7a53257c7d initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
96
4a7a53257c7d initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
97
4a7a53257c7d initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
98 void ImagedVolumeParameters::SetDepth(float depth)
4a7a53257c7d initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
99 {
4a7a53257c7d initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
100 if (depth <= 0)
4a7a53257c7d initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
101 {
4a7a53257c7d initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
102 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange);
4a7a53257c7d initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
103 }
4a7a53257c7d initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
104
4a7a53257c7d initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
105 depth_ = depth;
4a7a53257c7d initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
106 }
4a7a53257c7d initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
107
4a7a53257c7d initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
108
4a7a53257c7d initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
109 void ImagedVolumeParameters::GetLocation(float& physicalX,
4a7a53257c7d initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
110 float& physicalY,
4a7a53257c7d initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
111 unsigned int imageX,
4a7a53257c7d initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
112 unsigned int imageY,
4a7a53257c7d initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
113 unsigned int totalWidth,
4a7a53257c7d initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
114 unsigned int totalHeight) const
4a7a53257c7d initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
115 {
4a7a53257c7d initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
116 if (imageX >= totalWidth ||
4a7a53257c7d initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
117 imageY >= totalHeight)
4a7a53257c7d initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
118 {
4a7a53257c7d initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
119 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange);
4a7a53257c7d initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
120 }
4a7a53257c7d initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
121
4a7a53257c7d initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
122 // WARNING: The physical X/Y axes are switched wrt. the image X/Y
4a7a53257c7d initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
123 physicalX = offsetX_ - GetHeight() * static_cast<float>(imageX) / static_cast<float>(totalWidth);
4a7a53257c7d initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
124 physicalY = offsetY_ - GetWidth() * static_cast<float>(imageY) / static_cast<float>(totalHeight);
4a7a53257c7d initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
125 }
4a7a53257c7d initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
126 }