Mercurial > hg > orthanc-wsi
annotate Framework/ImagedVolumeParameters.cpp @ 295:92b88fa3e631
back to mainline
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Thu, 13 Jul 2023 18:18:21 +0200 |
parents | 5fe243cef6e9 |
children | 7020852a8fa9 |
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 | |
254 | 5 * Copyright (C) 2017-2023 Osimis S.A., Belgium |
6 * Copyright (C) 2021-2023 Sebastien Jodogne, ICTEAM UCLouvain, Belgium | |
0 | 7 * |
8 * This program is free software: you can redistribute it and/or | |
9 * modify it under the terms of the GNU Affero General Public License | |
10 * as published by the Free Software Foundation, either version 3 of | |
11 * the License, or (at your option) any later version. | |
12 * | |
13 * This program is distributed in the hope that it will be useful, but | |
14 * WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
16 * Affero General Public License for more details. | |
17 * | |
18 * You should have received a copy of the GNU Affero General Public License | |
19 * along with this program. If not, see <http://www.gnu.org/licenses/>. | |
20 **/ | |
21 | |
22 | |
16
7a88c614be04
preparing for precompiled headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
0
diff
changeset
|
23 #include "PrecompiledHeadersWSI.h" |
0 | 24 #include "ImagedVolumeParameters.h" |
25 | |
192 | 26 #include <OrthancException.h> |
0 | 27 |
28 namespace OrthancWSI | |
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 | 32 hasHeight_(false), |
33 width_(0), | |
34 height_(0), | |
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 | 37 depth_(1), |
38 offsetX_(20), | |
39 offsetY_(40) | |
40 { | |
0 | 41 } |
42 | |
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 | 70 void ImagedVolumeParameters::SetWidth(float width) |
71 { | |
72 if (width <= 0) | |
73 { | |
74 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange); | |
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 | 81 } |
82 | |
83 | |
84 void ImagedVolumeParameters::SetHeight(float height) | |
85 { | |
86 if (height <= 0) | |
87 { | |
88 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange); | |
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 | 95 } |
96 | |
97 | |
98 void ImagedVolumeParameters::SetDepth(float depth) | |
99 { | |
100 if (depth <= 0) | |
101 { | |
102 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange); | |
103 } | |
104 | |
105 depth_ = depth; | |
106 } | |
107 | |
108 | |
109 void ImagedVolumeParameters::GetLocation(float& physicalX, | |
110 float& physicalY, | |
111 unsigned int imageX, | |
112 unsigned int imageY, | |
113 unsigned int totalWidth, | |
114 unsigned int totalHeight) const | |
115 { | |
116 if (imageX >= totalWidth || | |
117 imageY >= totalHeight) | |
118 { | |
119 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange); | |
120 } | |
121 | |
122 // WARNING: The physical X/Y axes are switched wrt. the image X/Y | |
123 physicalX = offsetX_ - GetHeight() * static_cast<float>(imageX) / static_cast<float>(totalWidth); | |
124 physicalY = offsetY_ - GetWidth() * static_cast<float>(imageY) / static_cast<float>(totalHeight); | |
125 } | |
126 } |