HighMap library (C++)
Loading...
Searching...
No Matches
uv_tile.hpp
Go to the documentation of this file.
1/* Copyright (c) 2025 Otto Link. Distributed under the terms of the GNU General
2 Public License. The full license is in the file LICENSE, distributed with
3 this software. */
4
12#pragma once
13#include <cstdint>
14#include <string>
15
16#include <glm/vec2.hpp>
17#include <glm/vec4.hpp>
18
19#include "highmap/algebra.hpp"
21
22namespace hmap
23{
24
25struct TileKey
26{
27 int tx = 0;
28 int ty = 0;
29
30 bool operator==(const TileKey &other) const
31 {
32 return tx == other.tx && ty == other.ty;
33 }
34
35 unsigned int hash() const
36 {
37 return (static_cast<uint64_t>(tx) << 32) | (static_cast<uint32_t>(ty));
38 }
39};
40
45struct UvTile
46{
49 glm::ivec2 shape;
50 glm::ivec4 halo;
51 glm::ivec2 global_shape;
52 glm::ivec2 tile_shape;
53 glm::ivec2 tile_grid;
54
55 UvTile(const TileKey &key = {},
56 const UvRect &uv_rect = UvRect::unit(),
57 const glm::ivec2 &shape = {0, 0},
58 const glm::ivec4 &halo = {0, 0, 0, 0},
59 const glm::ivec2 &global_shape = {0, 0},
60 const glm::ivec2 &tile_shape = {0, 0},
61 const glm::ivec2 &tile_grid = {1, 1});
62
63 UvTile(const UvRect &uv)
64 : uv_rect(uv),
65 shape({0, 0}),
66 halo({0, 0, 0, 0}),
67 global_shape({0, 0}),
68 tile_shape({0, 0}),
69 tile_grid({1, 1})
70 {
71 }
72
73 static const UvTile &unit();
74 static const UvTile &dummy();
75
76 UvRect core_uv_rect() const;
77
78 glm::vec2 cell_uv_center(int i, int j) const
79 {
80 return cell_center(i, j);
81 }
82 glm::vec2 cell_uv_corner(int i, int j) const
83 {
84 return cell_corner(i, j);
85 }
86 glm::vec2 cell_center(int i, int j) const;
87 glm::vec2 cell_corner(int i, int j) const;
88 bool contains_global(int gx, int gy) const;
89 bool contains_global_core(int gx, int gy) const;
90 glm::ivec2 global_offset() const;
91 glm::ivec2 global_to_local(int gx, int gy) const;
92 std::string info_string(int indent = 0) const;
93
94 bool is_valid() const
95 {
96 return shape.x > 0 && shape.y > 0;
97 }
98
99 bool is_empty() const
100 {
101 return shape.x <= 0 || shape.y <= 0;
102 }
103
104 bool is_bottom_border() const;
105 bool is_left_border() const;
106 bool is_right_border() const;
107 bool is_top_border() const;
108 std::string key_as_string() const;
109 int linear_index() const;
110 glm::ivec2 local_to_global(int lx, int ly) const;
111};
112
113} // namespace hmap
Header file defining basic vector and matrix manipulation classes.
Definition opencv.hpp:20
UvTile UvTile
Definition communicator_interface.hpp:49
Definition uv_tile.hpp:26
int ty
Definition uv_tile.hpp:28
bool operator==(const TileKey &other) const
Definition uv_tile.hpp:30
unsigned int hash() const
Definition uv_tile.hpp:35
int tx
Definition uv_tile.hpp:27
Axis-aligned rectangle in normalized [0, 1]^2 domain/UV space.
Definition uv_rect.hpp:30
static constexpr UvRect unit()
Definition uv_rect.hpp:46
glm::ivec2 shape
Number of cells in tile (incl. halo).
Definition uv_tile.hpp:49
UvTile(const UvRect &uv)
Definition uv_tile.hpp:63
glm::vec2 cell_center(int i, int j) const
Definition uv_tile.cpp:42
bool is_valid() const
Definition uv_tile.hpp:94
glm::ivec2 global_to_local(int gx, int gy) const
Definition uv_tile.cpp:84
glm::ivec2 tile_grid
Number of tiles along (x, y).
Definition uv_tile.hpp:53
UvRect uv_rect
UV sub-rectangle [u_min, u_max] x [v_min, v_max].
Definition uv_tile.hpp:48
UvTile(const TileKey &key={}, const UvRect &uv_rect=UvRect::unit(), const glm::ivec2 &shape={0, 0}, const glm::ivec4 &halo={0, 0, 0, 0}, const glm::ivec2 &global_shape={0, 0}, const glm::ivec2 &tile_shape={0, 0}, const glm::ivec2 &tile_grid={1, 1})
Definition uv_tile.cpp:14
static const UvTile & dummy()
Definition uv_tile.cpp:37
bool contains_global(int gx, int gy) const
Definition uv_tile.cpp:60
bool is_empty() const
Definition uv_tile.hpp:99
bool is_left_border() const
Definition uv_tile.cpp:142
glm::vec2 cell_uv_corner(int i, int j) const
Definition uv_tile.hpp:82
bool contains_global_core(int gx, int gy) const
Definition uv_tile.cpp:68
std::string key_as_string() const
Definition uv_tile.cpp:147
glm::ivec2 global_shape
Total domain shape (nx, ny).
Definition uv_tile.hpp:51
int linear_index() const
Definition uv_tile.cpp:152
glm::vec2 cell_corner(int i, int j) const
Definition uv_tile.cpp:53
glm::ivec2 global_offset() const
Definition uv_tile.cpp:76
bool is_right_border() const
Definition uv_tile.cpp:127
TileKey key
Tile grid coordinates (tx, ty).
Definition uv_tile.hpp:47
bool is_bottom_border() const
Definition uv_tile.cpp:137
bool is_top_border() const
Definition uv_tile.cpp:132
UvRect core_uv_rect() const
Definition uv_tile.cpp:116
glm::ivec2 local_to_global(int lx, int ly) const
Definition uv_tile.cpp:157
static const UvTile & unit()
Definition uv_tile.cpp:31
glm::ivec4 halo
Halo cells: (left, right, bottom, top).
Definition uv_tile.hpp:50
glm::vec2 cell_uv_center(int i, int j) const
Definition uv_tile.hpp:78
std::string info_string(int indent=0) const
Definition uv_tile.cpp:91
glm::ivec2 tile_shape
Nominal tile shape (excluding halo).
Definition uv_tile.hpp:52
Normalized domain/UV rectangle [u_min, u_max] x [v_min, v_max].