annotate Framework/ImagedVolumeParameters.cpp @ 285:463982c161b3 iiif

closing branch iiif
author Sebastien Jodogne <s.jodogne@gmail.com>
date Wed, 12 Jul 2023 21:23:25 +0200
parents 77afef2cf64b
children 5fe243cef6e9
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),
77afef2cf64b automated extraction of the imaged volume if using OpenSlide
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 254
diff changeset
32 hasHeight_(false)
0
4a7a53257c7d initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
33 {
279
77afef2cf64b automated extraction of the imaged volume if using OpenSlide
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 254
diff changeset
34 // Typical parameters for a specimen, in millimeters
0
4a7a53257c7d initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
35 depth_ = 1;
4a7a53257c7d initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
36 offsetX_ = 20;
4a7a53257c7d initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
37 offsetY_ = 40;
4a7a53257c7d initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
38 }
4a7a53257c7d initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
39
4a7a53257c7d initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
40
279
77afef2cf64b automated extraction of the imaged volume if using OpenSlide
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 254
diff changeset
41 float ImagedVolumeParameters::GetWidth() const
77afef2cf64b automated extraction of the imaged volume if using OpenSlide
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 254
diff changeset
42 {
77afef2cf64b automated extraction of the imaged volume if using OpenSlide
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 254
diff changeset
43 if (hasWidth_)
77afef2cf64b automated extraction of the imaged volume if using OpenSlide
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 254
diff changeset
44 {
77afef2cf64b automated extraction of the imaged volume if using OpenSlide
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 254
diff changeset
45 return width_;
77afef2cf64b automated extraction of the imaged volume if using OpenSlide
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 254
diff changeset
46 }
77afef2cf64b automated extraction of the imaged volume if using OpenSlide
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 254
diff changeset
47 else
77afef2cf64b automated extraction of the imaged volume if using OpenSlide
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 254
diff changeset
48 {
77afef2cf64b automated extraction of the imaged volume if using OpenSlide
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 254
diff changeset
49 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
50 }
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
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 float ImagedVolumeParameters::GetHeight() const
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 if (hasHeight_)
77afef2cf64b automated extraction of the imaged volume if using OpenSlide
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 254
diff changeset
57 {
77afef2cf64b automated extraction of the imaged volume if using OpenSlide
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 254
diff changeset
58 return height_;
77afef2cf64b automated extraction of the imaged volume if using OpenSlide
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 254
diff changeset
59 }
77afef2cf64b automated extraction of the imaged volume if using OpenSlide
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 254
diff changeset
60 else
77afef2cf64b automated extraction of the imaged volume if using OpenSlide
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 254
diff changeset
61 {
77afef2cf64b automated extraction of the imaged volume if using OpenSlide
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 254
diff changeset
62 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
63 }
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
77afef2cf64b automated extraction of the imaged volume if using OpenSlide
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 254
diff changeset
66
0
4a7a53257c7d initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
67 void ImagedVolumeParameters::SetWidth(float width)
4a7a53257c7d initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
68 {
4a7a53257c7d initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
69 if (width <= 0)
4a7a53257c7d initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
70 {
4a7a53257c7d initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
71 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange);
4a7a53257c7d initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
72 }
279
77afef2cf64b automated extraction of the imaged volume if using OpenSlide
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 254
diff changeset
73 else
77afef2cf64b automated extraction of the imaged volume if using OpenSlide
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 254
diff changeset
74 {
77afef2cf64b automated extraction of the imaged volume if using OpenSlide
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 254
diff changeset
75 width_ = width;
77afef2cf64b automated extraction of the imaged volume if using OpenSlide
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 254
diff changeset
76 hasWidth_ = true;
77afef2cf64b automated extraction of the imaged volume if using OpenSlide
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 254
diff changeset
77 }
0
4a7a53257c7d initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
78 }
4a7a53257c7d initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
79
4a7a53257c7d initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
80
4a7a53257c7d initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
81 void ImagedVolumeParameters::SetHeight(float height)
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 if (height <= 0)
4a7a53257c7d initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
84 {
4a7a53257c7d initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
85 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange);
4a7a53257c7d initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
86 }
279
77afef2cf64b automated extraction of the imaged volume if using OpenSlide
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 254
diff changeset
87 else
77afef2cf64b automated extraction of the imaged volume if using OpenSlide
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 254
diff changeset
88 {
77afef2cf64b automated extraction of the imaged volume if using OpenSlide
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 254
diff changeset
89 height_ = height;
77afef2cf64b automated extraction of the imaged volume if using OpenSlide
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 254
diff changeset
90 hasHeight_ = true;
77afef2cf64b automated extraction of the imaged volume if using OpenSlide
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 254
diff changeset
91 }
0
4a7a53257c7d initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
92 }
4a7a53257c7d initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
93
4a7a53257c7d initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
94
4a7a53257c7d initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
95 void ImagedVolumeParameters::SetDepth(float depth)
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 if (depth <= 0)
4a7a53257c7d initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
98 {
4a7a53257c7d initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
99 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange);
4a7a53257c7d initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
100 }
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 depth_ = depth;
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
4a7a53257c7d initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
106 void ImagedVolumeParameters::GetLocation(float& physicalX,
4a7a53257c7d initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
107 float& physicalY,
4a7a53257c7d initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
108 unsigned int imageX,
4a7a53257c7d initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
109 unsigned int imageY,
4a7a53257c7d initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
110 unsigned int totalWidth,
4a7a53257c7d initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
111 unsigned int totalHeight) const
4a7a53257c7d initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
112 {
4a7a53257c7d initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
113 if (imageX >= totalWidth ||
4a7a53257c7d initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
114 imageY >= totalHeight)
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 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange);
4a7a53257c7d initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
117 }
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 // 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
120 physicalX = offsetX_ - GetHeight() * static_cast<float>(imageX) / static_cast<float>(totalWidth);
4a7a53257c7d initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
121 physicalY = offsetY_ - GetWidth() * static_cast<float>(imageY) / static_cast<float>(totalHeight);
4a7a53257c7d initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
122 }
4a7a53257c7d initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
123 }