SlideIO 2.9.0
Open-source library for reading of medical images
Loading...
Searching...
No Matches
levelinfo.hpp
1// This file is part of slideio project.
2// It is subject to the license terms in the LICENSE file found in the top-level directory
3// of this distribution and at http://slideio.com/license.html.
4#pragma once
5#include "slideio/core/slideio_core_def.hpp"
6#include "slideio/base/slideio_structs.hpp"
7#include <cmath>
8
9#if defined(_MSC_VER)
10#pragma warning( push )
11#pragma warning(disable: 4251)
12#endif
13
14namespace slideio
15{
25 class SLIDEIO_CORE_EXPORTS LevelInfo
26 {
27 public:
28 friend std::ostream& operator<<(std::ostream& os, const slideio::LevelInfo& levelInfo)
29 {
30 os << "Level: " << levelInfo.getLevel() << std::endl;
31 os << "Size: " << levelInfo.getSize().width << "x" << levelInfo.getSize().height << std::endl;
32 os << "Scale: " << levelInfo.getScale() << std::endl;
33 os << "Magnification: " << levelInfo.getMagnification() << std::endl;
34 os << "Tile Size: " << levelInfo.getTileSize().width << "x" << levelInfo.getTileSize().height << std::endl;
35 return os;
36 }
37 public:
38 LevelInfo() = default;
39
40 LevelInfo(int level, const Size& size, double scale, double magnification, const Size& tileSize)
41 : m_level(level), m_size(size), m_scale(scale), m_magnification(magnification), m_tileSize(tileSize) {}
42
43 LevelInfo(const LevelInfo& other) {
44 m_level = other.m_level;
45 m_size = other.m_size;
46 m_scale = other.m_scale;
47 m_magnification = other.m_magnification;
48 m_tileSize = other.m_tileSize;
49 }
50
51 LevelInfo& operator=(const LevelInfo& other) {
52 if (this != &other) {
53 m_level = other.m_level;
54 m_size = other.m_size;
55 m_scale = other.m_scale;
56 m_magnification = other.m_magnification;
57 m_tileSize = other.m_tileSize;
58 }
59 return *this;
60 }
61
62 bool operator==(const LevelInfo& other) const {
63 return m_level == other.m_level &&
64 m_size.width == other.m_size.width &&
65 m_size.height == other.m_size.height &&
66 std::fabs(m_scale - other.m_scale) < 1.e-2 &&
67 std::fabs(m_magnification - other.m_magnification) < 1.e-2 &&
68 m_tileSize.width == other.m_tileSize.width &&
69 m_tileSize.height == other.m_tileSize.height;
70 }
71
73 void updateTileCount() const {
74 if (getTileSize().width > 0 && getTileSize().height > 0) {
75 const int tilesX = (getSize().width - 1) / getTileSize().width + 1;
76 const int tilesY = (getSize().height - 1) / getTileSize().height + 1;
77 m_tileCount = tilesX * tilesY;
78 }
79 else {
80 m_tileCount = 1;
81 }
82 }
83
85 int getLevel() const { return m_level; }
86 void setLevel(int level) { m_level = level; }
87
89 Size getSize() const { return m_size; }
90 void setSize(const Size& size) { m_size = size; }
91
96 double getScale() const { return m_scale; }
97 void setScale(double scale) { m_scale = scale; }
98
100 double getMagnification() const { return m_magnification; }
101 void setMagnification(double magnification) { m_magnification = magnification; }
102
104 Size getTileSize() const { return m_tileSize; }
105 void setTileSize(const Size& tileSize) { m_tileSize = tileSize; }
106
111 int getTileCount() const {
112 if (m_tileCount < 1)
113 updateTileCount();
114 return m_tileCount;
115 }
116
118 std::string toString() const;
119
131 Rect getTileRect(int tileIndex) const {
132 Rect tileRect;
133 const int tileCount = getTileCount();
134 if (tileCount > 1) {
135 const int tilesX = (m_size.width - 1) / m_tileSize.width + 1;
136 const int tilesY = (m_size.height - 1) / m_tileSize.height + 1;
137 const int tileY = tileIndex / tilesX;
138 const int tileX = tileIndex % tilesX;
139 tileRect.x = tileX * m_tileSize.width;
140 tileRect.y = tileY * m_tileSize.height;
141 tileRect.width = m_tileSize.width;
142 tileRect.height = m_tileSize.height;
143 }
144 else {
145 tileRect.x = 0;
146 tileRect.y = 0;
147 tileRect.width = m_size.width;
148 tileRect.height = m_size.height;
149 }
150 return tileRect;
151 }
152
153 private:
154 int m_level = 0;
155 Size m_size;
156 double m_scale = 0.0;
157 double m_magnification = 0.0;
158 Size m_tileSize;
159 mutable int m_tileCount = 0;
160 };
161}
162
163#if defined(_MSC_VER)
164#pragma warning( pop )
165#endif
Description of a single level of the internal image pyramid of a scene.
Definition: levelinfo.hpp:26
double getMagnification() const
returns the objective magnification of the level. 0 if the format does not report it.
Definition: levelinfo.hpp:100
void updateTileCount() const
recomputes the cached tile count from the current level and tile size.
Definition: levelinfo.hpp:73
Size getSize() const
returns the size of the level in the pixels of the level.
Definition: levelinfo.hpp:89
Rect getTileRect(int tileIndex) const
returns the rectangle of a tile in the coordinate system of the level.
Definition: levelinfo.hpp:131
double getScale() const
returns the scale of the level relative to level 0.
Definition: levelinfo.hpp:96
int getLevel() const
returns the index of the level. Level 0 is the level of the highest resolution.
Definition: levelinfo.hpp:85
Size getTileSize() const
returns the size of a tile of the level. (0,0) if the level is not tiled.
Definition: levelinfo.hpp:104
int getTileCount() const
returns the number of tiles of the level.
Definition: levelinfo.hpp:111
Definition: exceptions.hpp:15