Class Cube

Nested Relationships

Nested Types

Inheritance Relationships

Base Type

  • public std::enable_shared_from_this< Cube >

Class Documentation

class inexor::vulkan_renderer::world::Cube : public std::enable_shared_from_this<Cube>

Public Types

enum Type

Cube Type.

Values:

enumerator EMPTY
enumerator SOLID
enumerator NORMAL
enumerator OCTANT
enum NeighborAxis

Values:

enumerator X
enumerator Y
enumerator Z
enum NeighborDirection

Values:

enumerator POSITIVE
enumerator NEGATIVE

Public Functions

Cube() = default

Create an empty cube.

Cube(float size, const glm::vec3 &position)

Create an empty cube.

Cube(std::weak_ptr<Cube> parent, std::uint8_t index, float size, const glm::vec3 &position)

Create an empty cube.

Cube(const Cube &rhs) = delete

Use clone() to create an independent copy of a cube.

Cube(Cube &&rhs) noexcept
~Cube() = default
Cube &operator=(Cube rhs)
Cube &operator=(Cube&&) = delete
std::shared_ptr<Cube> operator[](std::size_t idx)

Get child.

std::shared_ptr<const Cube> operator[](std::size_t idx) const

Get child.

std::shared_ptr<Cube> clone() const

Clone a cube, which has no relations to the current one or its children. It will be a root cube.

bool is_root() const noexcept

Is the current cube root.

std::size_t grid_level() const noexcept

At which child level this cube is. root cube = 0

std::size_t count_geometry_cubes() const noexcept

Count the number of Type::SOLID and Type::NORMAL cubes.

inline glm::vec3 center() const noexcept
inline glm::vec3 position() const noexcept
inline std::array<glm::vec3, 2> bounding_box() const
inline float size() const noexcept
void set_type(Type new_type)

Set a new type.

Type type() const noexcept

Get type.

const std::array<std::shared_ptr<Cube>, Cube::SUB_CUBES> &children() const

Get children.

std::array<Indentation, Cube::EDGES> indentations() const noexcept

Get indentations.

void set_indent(std::uint8_t edge_id, Indentation indentation)

Set an indent by the edge id.

void indent(std::uint8_t edge_id, bool positive_direction, std::uint8_t steps)

Indent a specific edge by steps.

Parameters

positive_direction – Indent in positive axis direction.

void rotate(const RotationAxis::Type &axis, int rotations)

Rotate the cube 90° clockwise around the given axis. Repeats with the given rotations.

Parameters
  • axis – Only one index should be one.

  • rotations – Value does not need to be adjusted beforehand. (e.g. mod 4)

void update_polygon_cache() const

TODO: in special cases some polygons have no surface, if completely surrounded by others

Warning

Will update the cache even if it is considered as valid.

void invalidate_polygon_cache() const

Invalidate polygon cache.

std::vector<PolygonCache> polygons(bool update_invalid = false) const

Recursive way to collect all the caches.

Parameters

update_invalid – If true it will update invalid polygon caches.

std::shared_ptr<Cube> neighbor(NeighborAxis axis, NeighborDirection direction)

Get the (face) neighbor of this cube.

Get the (face) neighbor of this cube by using a similar implementation to Samets “OT_GTEQ_FACE_NEIGHBOR(P,I)”.

See

Samet, H. (1989) Neighbor finding in Images Represented by Octrees. Computer Vision, Graphics, and Image Processing. 46 (3), 367-386.

Parameters
  • axis – The axis on which to get the neighboring cube

  • direction – Whether to get the cube which is above or below this cube on the selected axis

Returns

Same-sized neighbor if existent, else larger neighbor if exists, otherwise (i.e. when no neighbor exists) nullptr.

Public Static Attributes

static constexpr std::size_t SUB_CUBES = {8}

Maximum of sub cubes (children)

static constexpr std::size_t EDGES = {12}

Cube edges.

Private Functions

friend void ::swap(Cube &lhs, Cube &rhs) noexcept
void remove_children()

Removes all children recursive.

std::shared_ptr<Cube> root() noexcept

Get the root to this cube.

std::array<glm::vec3, 8> vertices() const noexcept

Get the vertices of this cube. Use only on geometry cubes.

template<int Rotations>
void rotate(const RotationAxis::Type &axis)

Optimized implementations of 90°, 180° and 270° rotations.

Private Members

Type m_type = {Type::EMPTY}
float m_size = {32}
glm::vec3 m_position = {0.0f, 0.0f, 0.0f}
std::weak_ptr<Cube> m_parent = {}

Root cube is empty.

std::uint8_t m_index_in_parent = {}

Index of this in m_parent.m_children; undefined behavior if root.

std::array<Indentation, Cube::EDGES> m_indentations

Indentations, should only be used if it is a geometry cube.

std::array<std::shared_ptr<Cube>, Cube::SUB_CUBES> m_children
mutable PolygonCache m_polygon_cache

Only geometry cube (Type::SOLID and Type::Normal) have a polygon cache.

mutable bool m_polygon_cache_valid = {false}

Friends

friend class io::NXOCParser
struct RotationAxis

IDs of the children and edges which will be swapped to receive the rotation. To achieve a 90 degree rotation the 0th index have to be swapped with the 1st and the 1st with the 2nd, etc.

Public Types

using ChildType = std::array<std::array<std::size_t, 4>, 2>
using EdgeType = std::array<std::array<std::size_t, 4>, 3>
using Type = std::pair<ChildType, EdgeType>

Public Static Attributes

static constexpr Type X = {{{{0, 1, 3, 2}, {4, 5, 7, 6}}}, {{{2, 4, 11, 1}, {5, 7, 8, 10}, {0, 9, 6, 3}}}}

IDs of the children / edges which will be swapped to receive the rotation around X axis.

static constexpr Type Y = {{{{0, 4, 5, 1}, {2, 6, 7, 3}}}, {{{0, 5, 9, 2}, {3, 8, 6, 11}, {1, 10, 7, 4}}}}

IDs of the children / edges which will be swapped to receive the rotation around Y axis.

static constexpr Type Z = {{{{0, 2, 6, 4}, {1, 3, 7, 5}}}, {{{1, 3, 10, 0}, {4, 6, 7, 9}, {2, 11, 8, 5}}}}

IDs of the children / edges which will be swapped to receive the rotation around Z axis.