annotate Framework/Inputs/OpenSlidePyramid.cpp @ 279:77afef2cf64b

automated extraction of the imaged volume if using OpenSlide
author Sebastien Jodogne <s.jodogne@gmail.com>
date Wed, 12 Jul 2023 18:06:34 +0200
parents 20a730889ae2
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 "OpenSlidePyramid.h"
4a7a53257c7d initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
25
199
a1c265cb2174 replacing deprecated std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 192
diff changeset
26 #include <Compatibility.h> // For std::unique_ptr
192
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 175
diff changeset
27 #include <Images/ImageProcessing.h>
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 175
diff changeset
28 #include <OrthancException.h>
279
77afef2cf64b automated extraction of the imaged volume if using OpenSlide
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 254
diff changeset
29 #include <SerializationToolbox.h>
192
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 175
diff changeset
30 #include <Logging.h>
140
a0f9a3df1110 resort to Orthanc framework
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 115
diff changeset
31
a0f9a3df1110 resort to Orthanc framework
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 115
diff changeset
32 #include <memory>
0
4a7a53257c7d initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
33
4a7a53257c7d initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
34 namespace OrthancWSI
4a7a53257c7d initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
35 {
4a7a53257c7d initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
36 void OpenSlidePyramid::ReadRegion(Orthanc::ImageAccessor& target,
4a7a53257c7d initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
37 unsigned int level,
4a7a53257c7d initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
38 unsigned int x,
4a7a53257c7d initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
39 unsigned int y)
4a7a53257c7d initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
40 {
199
a1c265cb2174 replacing deprecated std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 192
diff changeset
41 std::unique_ptr<Orthanc::ImageAccessor> source(image_.ReadRegion(level, x, y, target.GetWidth(), target.GetHeight()));
0
4a7a53257c7d initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
42 Orthanc::ImageProcessing::Convert(target, *source);
4a7a53257c7d initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
43 }
4a7a53257c7d initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
44
4a7a53257c7d initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
45
4a7a53257c7d initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
46 OpenSlidePyramid::OpenSlidePyramid(const std::string& path,
4a7a53257c7d initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
47 unsigned int tileWidth,
4a7a53257c7d initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
48 unsigned int tileHeight) :
4a7a53257c7d initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
49 image_(path),
4a7a53257c7d initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
50 tileWidth_(tileWidth),
4a7a53257c7d initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
51 tileHeight_(tileHeight)
4a7a53257c7d initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
52 {
4a7a53257c7d initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
53 }
279
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 bool OpenSlidePyramid::LookupImagedVolumeSize(float& width,
77afef2cf64b automated extraction of the imaged volume if using OpenSlide
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 254
diff changeset
57 float& height) 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 std::string s;
77afef2cf64b automated extraction of the imaged volume if using OpenSlide
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 254
diff changeset
60 double mppx;
77afef2cf64b automated extraction of the imaged volume if using OpenSlide
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 254
diff changeset
61 double mppy;
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 if (image_.LookupProperty(s, "openslide.mpp-x") &&
77afef2cf64b automated extraction of the imaged volume if using OpenSlide
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 254
diff changeset
64 Orthanc::SerializationToolbox::ParseDouble(mppx, s) &&
77afef2cf64b automated extraction of the imaged volume if using OpenSlide
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 254
diff changeset
65 image_.LookupProperty(s, "openslide.mpp-y") &&
77afef2cf64b automated extraction of the imaged volume if using OpenSlide
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 254
diff changeset
66 Orthanc::SerializationToolbox::ParseDouble(mppy, s))
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 // In the 2 lines below, remember to switch X/Y when going from physical to pixel coordinates!
77afef2cf64b automated extraction of the imaged volume if using OpenSlide
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 254
diff changeset
69 width = mppy / 1000.0 * static_cast<double>(image_.GetLevelHeight(0));
77afef2cf64b automated extraction of the imaged volume if using OpenSlide
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 254
diff changeset
70 height = mppx / 1000.0 * static_cast<double>(image_.GetLevelWidth(0));
77afef2cf64b automated extraction of the imaged volume if using OpenSlide
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 254
diff changeset
71 return true;
77afef2cf64b automated extraction of the imaged volume if using OpenSlide
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 254
diff changeset
72 }
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 return false;
77afef2cf64b automated extraction of the imaged volume if using OpenSlide
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 254
diff changeset
76 }
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 }