supereight
Loading...
Searching...
No Matches
key_util.hpp
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2016-2019 Emanuele Vespa
3 * SPDX-FileCopyrightText: 2021-2023 Smart Robotics Lab, Imperial College London, Technical University of Munich
4 * SPDX-FileCopyrightText: 2021-2023 Nils Funk
5 * SPDX-FileCopyrightText: 2021-2023 Sotiris Papatheodorou
6 * SPDX-License-Identifier: BSD-3-Clause
7 */
8
9#ifndef SE_KEY_UTIL_HPP
10#define SE_KEY_UTIL_HPP
11
12#include <algorithm>
15#include <se/supereight_config.hpp> // Required for the SE_TBB macro
16
17namespace se {
18
19#define NUM_DIM 3
20#define SCALE_OFFSET 5
21#define KEY_SCALE_LIMIT 19
22
38constexpr uint64_t CODE_MASK[] = {0x1ffffffffffffff,
39 0x1fffffffffffff8,
40 0x1ffffffffffffc0,
41 0x1fffffffffffe00,
42 0x1fffffffffff000,
43 0x1ffffffffff8000,
44 0x1fffffffffc0000,
45 0x1ffffffffe00000,
46 0x1ffffffff000000,
47 0x1fffffff8000000,
48 0x1ffffffc0000000,
49 0x1fffffe00000000,
50 0x1fffff000000000,
51 0x1ffff8000000000,
52 0x1fffc0000000000,
53 0x1ffe00000000000,
54 0x1ff000000000000,
55 0x1f8000000000000,
56 0x1c0000000000000};
57
58constexpr uint64_t SCALE_MASK = 0x1F;
59
60namespace keyops {
61
69
76inline bool is_valid(const Eigen::Vector3i& coord);
77
85inline se::code_t expand(unsigned long long value);
86
95
109inline bool encode_key(const Eigen::Vector3i& coord, const se::scale_t scale, se::key_t& key);
110
123inline se::key_t encode_key(const Eigen::Vector3i& coord, const se::scale_t scale);
124
138inline bool encode_key(const se::key_t code, const se::scale_t scale, se::key_t& key);
139
152inline se::key_t encode_key(const se::key_t code, const se::scale_t scale);
153
161inline void decode_key(const se::key_t key, Eigen::Vector3i& coord, scale_t& scale);
162
169inline void encode_code(const Eigen::Vector3i& coord, se::code_t& code);
170
177inline se::code_t encode_code(const Eigen::Vector3i& coord);
178
185inline void decode_code(const se::code_t code, Eigen::Vector3i& coord);
186
187
188
197inline idx_t code_to_child_idx(const se::code_t code, const scale_t scale);
198
207
215inline Eigen::Vector3i key_to_coord(const se::key_t key);
216
225
235inline bool key_at_scale(const se::key_t key, const se::scale_t scale, se::key_t& key_at_scale);
236
247
255
266inline se::key_t block_key(const se::key_t key, const se::scale_t max_block_scale);
267
278inline se::code_t block_code(const se::key_t key, const se::scale_t max_block_scale);
279
292
305
315
319template<Sort = Sort::SmallToLarge>
320inline void sort_keys(std::vector<se::key_t>& keys);
321
329template<>
330inline void sort_keys<Sort::SmallToLarge>(std::vector<se::key_t>& keys);
331
339template<>
340inline void sort_keys<Sort::LargeToSmall>(std::vector<se::key_t>& keys);
341
348template<se::Safe SafeB>
349inline void unique_keys(const std::vector<se::key_t>& keys, std::vector<se::key_t>& unique_keys);
350
357template<se::Safe SafeB>
358inline void unique_codes(const std::vector<se::key_t>& keys, std::vector<se::key_t>& unique_keys);
359
368template<se::Safe SafeB>
369inline void unique_allocation(const std::vector<se::key_t>& keys,
370 const scale_t max_block_scale,
371 std::vector<se::key_t>& unique_keys);
372
382template<se::Safe SafeB>
383inline void unique_at_scale(const std::vector<se::key_t>& keys,
384 const se::scale_t scale,
385 std::vector<se::key_t>& unique_keys);
386
394inline void face_neighbours(const se::key_t key, std::array<se::key_t, 6> face_neighbour_keys);
395
403inline void neighbours(const se::key_t key, std::array<se::key_t, 26> neighbour_keys);
404
412inline void siblings(const se::key_t key, std::array<se::key_t, 8> sibling_keys);
413
414} // namespace keyops
415} // namespace se
416
417#include "impl/key_util_impl.hpp"
418
419#endif // SE_KEY_UTIL_HPP
Definition image.hpp:19
#define KEY_SCALE_LIMIT
Definition key_util.hpp:21
se::code_t block_code(const se::key_t key, const se::scale_t max_block_scale)
Removes the voxel position detail within a block from a code.
void sort_keys< Sort::LargeToSmall >(std::vector< se::key_t > &keys)
Sorts the keys from largest to smallest.
se::key_t compact(uint64_t value)
Compresses a value E.g.
void face_neighbours(const se::key_t key, std::array< se::key_t, 6 > face_neighbour_keys)
TODO: 6-connectivity + centre.
bool key_at_scale(const se::key_t key, const se::scale_t scale, se::key_t &key_at_scale)
For a given key, change the key scale and reduce detail from Morton code up to given the scale.
void unique_keys(const std::vector< se::key_t > &keys, std::vector< se::key_t > &unique_keys)
Filter keys based on the whole key (i.e.
Eigen::Vector3i key_to_coord(const se::key_t key)
Reduce a key to only its Morton code.
void unique_allocation(const std::vector< se::key_t > &keys, const scale_t max_block_scale, std::vector< se::key_t > &unique_keys)
Filter keys based on unique allocation.
void siblings(const se::key_t key, std::array< se::key_t, 8 > sibling_keys)
TODO: 4 siblings (includes key)
void parent_to_child_key(const se::key_t parent_key, const se::code_t code_at_scale, se::key_t &child_key)
Compute the child key for a given parent key and child index.
bool is_child(const se::key_t parent_key, const se::key_t child_key)
Verify if a key is a child of a different key.
se::key_t block_key(const se::key_t key, const se::scale_t max_block_scale)
Removes the voxel position detail within a block from a key while maintainig the scale information.
void sort_keys< Sort::SmallToLarge >(std::vector< se::key_t > &keys)
Sorts the keys from smallest to largest.
bool is_siblings(const se::key_t sibling_1_key, const se::key_t sibling_2_key)
Verify if two keys encode sibling nodes/voxels.
void unique_at_scale(const std::vector< se::key_t > &keys, const se::scale_t scale, std::vector< se::key_t > &unique_keys)
Filter keys at a given scale.
bool encode_key(const Eigen::Vector3i &coord, const se::scale_t scale, se::key_t &key)
Encodes given coordinates and scale in a key.
void sort_keys(std::vector< se::key_t > &keys)
Sorting template.
se::code_t expand(unsigned long long value)
Expands a value that can be expressed by <= 19 bits E.g.
idx_t code_to_child_idx(const se::code_t code, const scale_t scale)
Extracts the child index from a Morton code for a given scale.
scale_t key_to_scale(const se::key_t key)
Reduce a key to only its scale.
void neighbours(const se::key_t key, std::array< se::key_t, 26 > neighbour_keys)
TODO: 26-connectivity.
se::code_t key_to_code(const se::key_t key)
Reduce a key to only its Morton code.
void parent_key(const se::key_t key, se::key_t &parent_key)
Compute the direct parent key for a given key.
void unique_codes(const std::vector< se::key_t > &keys, std::vector< se::key_t > &unique_keys)
Filter keys based on their code and keep the key with the smallest scale.
bool code_at_scale(const se::key_t key, const se::scale_t scale, se::code_t &code_at_scale)
For a given key, reduce detail from Morton code up to given a scale.
void encode_code(const Eigen::Vector3i &coord, se::code_t &code)
Compute the Morton code for given x,y,z coordinates.
void decode_code(const se::code_t code, Eigen::Vector3i &coord)
Compute the x,y,z coordinates for a given Morton code.
void decode_key(const se::key_t key, Eigen::Vector3i &coord, scale_t &scale)
Extracts the 3D coordinates and scale from a given key.
bool is_valid(const se::key_t key, const se::scale_t limit=KEY_SCALE_LIMIT)
Verify if a key is valid.
Helper wrapper to allocate and de-allocate octants in the octree.
Definition bounded_vector.hpp:14
uint64_t code_t
The type of the Morton code.
Definition type_util.hpp:44
unsigned int idx_t
Child or voxel index type.
Definition type_util.hpp:47
constexpr uint64_t CODE_MASK[]
The code mask for a given scale.
Definition key_util.hpp:38
constexpr uint64_t SCALE_MASK
11 111
Definition key_util.hpp:58
uint64_t scale_t
The type of the scale in the morton code.
Definition type_util.hpp:45
uint64_t key_t
key = 1 bit buffer + 57 bits of morton code + 6 bits of scale information The maxium scale is limited...
Definition type_util.hpp:43