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