OrcaSlicer latest
OrcaSlicer
Loading...
Searching...
No Matches
Slic3r::TextureBake::QuantizedPointMap Class Reference

#include </home/runner/work/OrcaSlicer/OrcaSlicer/src/libslic3r/TextureBake/TextureBakeIndex.hpp>

Collaboration diagram for Slic3r::TextureBake::QuantizedPointMap:

Classes

struct  Cell

Public Member Functions

 QuantizedPointMap (double quant, size_t expected=256)
size_t size () const
bool inserted () const
int get (float x, float y, float z)
int get (const Vec3f &p)
int get_or_set (float x, float y, float z, int value)
int get_or_set (const Vec3f &p, int value)
int get_key (int64_t a, int64_t b, int64_t c)
int get_or_set_key (int64_t a, int64_t b, int64_t c, int value)

Private Member Functions

void alloc (size_t cap)
size_t slot (int64_t qx, int64_t qy, int64_t qz) const
void grow ()

Private Attributes

double m_quant
size_t m_cap = 0
size_t m_mask = 0
size_t m_size = 0
bool m_inserted = false
std::vector< Cell > m_cells

Detailed Description


Class Documentation

◆ Slic3r::TextureBake::QuantizedPointMap::Cell

struct Slic3r::TextureBake::QuantizedPointMap::Cell
Class Members
int64_t qx = 0
int64_t qy = 0
int64_t qz = 0
int32_t val = -1

Constructor & Destructor Documentation

◆ QuantizedPointMap()

Slic3r::TextureBake::QuantizedPointMap::QuantizedPointMap ( double quant,
size_t expected = 256 )
inlineexplicit
41 : m_quant(quant)
42 {
43 size_t cap = 16;
44 const size_t target = std::max<size_t>(16, size_t(std::ceil(double(expected) / 0.6)));
45 while (cap < target)
46 cap *= 2;
47 alloc(cap);
48 }
double m_quant
Definition TextureBakeIndex.hpp:133
void alloc(size_t cap)
Definition TextureBakeIndex.hpp:96

References alloc(), and m_quant.

Here is the call graph for this function:

Member Function Documentation

◆ alloc()

void Slic3r::TextureBake::QuantizedPointMap::alloc ( size_t cap)
inlineprivate
97 {
98 m_cap = cap;
99 m_mask = cap - 1;
100 m_cells.assign(cap, Cell{});
101 }
std::vector< Cell > m_cells
Definition TextureBakeIndex.hpp:136
size_t m_cap
Definition TextureBakeIndex.hpp:134
size_t m_mask
Definition TextureBakeIndex.hpp:134
Definition TextureBakeIndex.hpp:91

References m_cap, m_cells, and m_mask.

Referenced by QuantizedPointMap(), and grow().

Here is the caller graph for this function:

◆ get() [1/2]

int Slic3r::TextureBake::QuantizedPointMap::get ( const Vec3f & p)
inline
59{ return get(p.x(), p.y(), p.z()); }
int get(float x, float y, float z)
Definition TextureBakeIndex.hpp:54

References get().

Referenced by get().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ get() [2/2]

int Slic3r::TextureBake::QuantizedPointMap::get ( float x,
float y,
float z )
inline
55 {
56 return m_cells[slot(grid_round(double(x) * m_quant), grid_round(double(y) * m_quant),
57 grid_round(double(z) * m_quant))].val;
58 }
size_t slot(int64_t qx, int64_t qy, int64_t qz) const
Definition TextureBakeIndex.hpp:103
int64_t grid_round(double v)
Definition TextureBakeIndex.hpp:30

References Slic3r::TextureBake::grid_round(), m_cells, m_quant, and slot().

Here is the call graph for this function:

◆ get_key()

int Slic3r::TextureBake::QuantizedPointMap::get_key ( int64_t a,
int64_t b,
int64_t c )
inline
72{ return m_cells[slot(a, b, c)].val; }

References m_cells, and slot().

Referenced by Slic3r::TextureBake::anonymous_namespace{TextureBakeSubdivide.cpp}::get_midpoint(), and Slic3r::TextureBake::anonymous_namespace{TextureBakeSubdivide.cpp}::subdivide_pass().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ get_or_set() [1/2]

int Slic3r::TextureBake::QuantizedPointMap::get_or_set ( const Vec3f & p,
int value )
inline
68{ return get_or_set(p.x(), p.y(), p.z(), value); }
int get_or_set(float x, float y, float z, int value)
Definition TextureBakeIndex.hpp:63

References get_or_set().

Referenced by get_or_set().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ get_or_set() [2/2]

int Slic3r::TextureBake::QuantizedPointMap::get_or_set ( float x,
float y,
float z,
int value )
inline
64 {
65 return get_or_set_key(grid_round(double(x) * m_quant), grid_round(double(y) * m_quant),
66 grid_round(double(z) * m_quant), value);
67 }
int get_or_set_key(int64_t a, int64_t b, int64_t c, int value)
Definition TextureBakeIndex.hpp:73

References get_or_set_key(), Slic3r::TextureBake::grid_round(), and m_quant.

Referenced by Slic3r::TextureBake::apply_displacement(), Slic3r::BakeStageRecorder::capture(), Slic3r::TextureBake::count_edge_defects(), Slic3r::TextureBake::decimate(), Slic3r::TextureBake::flip_edges_to_height(), Slic3r::TextureBake::anonymous_namespace{TextureBakeSubdivide.cpp}::get_midpoint(), Slic3r::TextureBake::regularize_mesh(), Slic3r::TextureBake::relocate_to_contours(), Slic3r::TextureBake::resolve_t_junctions(), Slic3r::TextureBake::snap_bottom_to_flat(), Slic3r::TextureBake::to_indexed(), Slic3r::TextureBake::to_indexed_fast(), Slic3r::TextureBake::to_indexed_triangle_set(), and Slic3r::TextureBake::weld_vertices().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ get_or_set_key()

int Slic3r::TextureBake::QuantizedPointMap::get_or_set_key ( int64_t a,
int64_t b,
int64_t c,
int value )
inline
74 {
75 const size_t i = slot(a, b, c);
76 Cell &cell = m_cells[i];
77 if (cell.val != -1) {
78 m_inserted = false;
79 return cell.val;
80 }
81 cell.qx = a; cell.qy = b; cell.qz = c;
82 cell.val = value;
83 m_inserted = true;
84 if (++m_size > size_t(double(m_cap) * 0.7))
85 grow();
86 return value;
87 }
void grow()
Definition TextureBakeIndex.hpp:124
bool m_inserted
Definition TextureBakeIndex.hpp:135
size_t m_size
Definition TextureBakeIndex.hpp:134

References grow(), m_cap, m_cells, m_inserted, m_size, Slic3r::TextureBake::QuantizedPointMap::Cell::qx, Slic3r::TextureBake::QuantizedPointMap::Cell::qy, Slic3r::TextureBake::QuantizedPointMap::Cell::qz, slot(), and Slic3r::TextureBake::QuantizedPointMap::Cell::val.

Referenced by Slic3r::TextureBake::decimate(), Slic3r::TextureBake::anonymous_namespace{TextureBakeSubdivide.cpp}::get_midpoint(), get_or_set(), Slic3r::TextureBake::regularize_mesh(), and Slic3r::TextureBake::anonymous_namespace{TextureBakeSubdivide.cpp}::subdivide_pass().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ grow()

void Slic3r::TextureBake::QuantizedPointMap::grow ( )
inlineprivate
125 {
126 std::vector<Cell> old = std::move(m_cells);
127 alloc(m_cap * 2);
128 for (const Cell &c : old)
129 if (c.val != -1)
130 m_cells[slot(c.qx, c.qy, c.qz)] = c;
131 }

References alloc(), m_cap, m_cells, and slot().

Referenced by get_or_set_key().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ inserted()

◆ size()

size_t Slic3r::TextureBake::QuantizedPointMap::size ( ) const
inline
50{ return m_size; }

References m_size.

Referenced by Slic3r::TextureBake::anonymous_namespace{TextureBakeSubdivide.cpp}::subdivide_pass().

Here is the caller graph for this function:

◆ slot()

size_t Slic3r::TextureBake::QuantizedPointMap::slot ( int64_t qx,
int64_t qy,
int64_t qz ) const
inlineprivate
104 {
105 // Unsigned multiplies: the signed versions overflowed on nearly every key, which is undefined
106 // behaviour. The resulting bits are identical on every target OrcaSlicer builds for.
107 //
108 // A stronger 64-bit finalizer was tried and measured no faster - the probing that shows up in a
109 // profile is subdivide's parallel mark count, spread over every core, not long probe chains.
110 uint32_t h = (uint32_t(qx) * 0x9E3779B1u) ^ (uint32_t(qy) * 0x85EBCA77u) ^ (uint32_t(qz) * 0xC2B2AE3Du);
111 h ^= h >> 15;
112 size_t i = size_t(h) & m_mask;
113 // Equality is checked against the stored 64-bit keys, so truncating to 32 bits for the hash
114 // costs collisions at worst, never a wrong answer.
115 while (m_cells[i].val != -1) {
116 const Cell &c = m_cells[i];
117 if (c.qx == qx && c.qy == qy && c.qz == qz)
118 return i;
119 i = (i + 1) & m_mask;
120 }
121 return i;
122 }

References m_cells, m_mask, Slic3r::TextureBake::QuantizedPointMap::Cell::qx, Slic3r::TextureBake::QuantizedPointMap::Cell::qy, and Slic3r::TextureBake::QuantizedPointMap::Cell::qz.

Referenced by get(), get_key(), get_or_set_key(), and grow().

Here is the caller graph for this function:

Member Data Documentation

◆ m_cap

size_t Slic3r::TextureBake::QuantizedPointMap::m_cap = 0
private

Referenced by alloc(), get_or_set_key(), and grow().

◆ m_cells

std::vector<Cell> Slic3r::TextureBake::QuantizedPointMap::m_cells
private

◆ m_inserted

bool Slic3r::TextureBake::QuantizedPointMap::m_inserted = false
private

Referenced by get_or_set_key(), and inserted().

◆ m_mask

size_t Slic3r::TextureBake::QuantizedPointMap::m_mask = 0
private

Referenced by alloc(), and slot().

◆ m_quant

double Slic3r::TextureBake::QuantizedPointMap::m_quant
private

Referenced by QuantizedPointMap(), get(), and get_or_set().

◆ m_size

size_t Slic3r::TextureBake::QuantizedPointMap::m_size = 0
private

Referenced by get_or_set_key(), and size().


The documentation for this class was generated from the following file: