OrcaSlicer latest
OrcaSlicer
Loading...
Searching...
No Matches
libvgcode::ColorRange Class Reference

#include </home/runner/work/OrcaSlicer/OrcaSlicer/src/libvgcode/include/ColorRange.hpp>

Collaboration diagram for libvgcode::ColorRange:

Public Member Functions

 ColorRange (EColorRangeType type=EColorRangeType::Linear)
EColorRangeType get_type () const
const Palette & get_palette () const
void set_palette (const Palette &palette)
Color get_color_at (float value) const
const std::array< float, 2 > & get_range () const
std::vector< float > get_values () const
std::size_t size_in_bytes_cpu () const

Static Public Attributes

static const ColorRange DUMMY_COLOR_RANGE = ColorRange()

Private Member Functions

void update (float value)
void reset ()

Private Attributes

EColorRangeType m_type { EColorRangeType::Linear }
Palette m_palette
std::array< float, 2 > m_range { FLT_MAX, -FLT_MAX }
std::size_t m_count { 0 }

Friends

class ViewerImpl

Detailed Description

Constructor & Destructor Documentation

◆ ColorRange()

libvgcode::ColorRange::ColorRange ( EColorRangeType type = EColorRangeType::Linear)
explicit
41: m_type(type)
43{
44}
Palette m_palette
Definition ColorRange.hpp:84
EColorRangeType m_type
Definition ColorRange.hpp:80
static const Palette DEFAULT_RANGES_COLORS
Definition ColorRange.hpp:17

References libvgcode::DEFAULT_RANGES_COLORS, m_palette, and m_type.

Member Function Documentation

◆ get_color_at()

Color libvgcode::ColorRange::get_color_at ( float value) const
63{
64 // Input value scaled to the colors range
65 float global_t = 0.0f;
66 value = std::clamp(value, m_range[0], m_range[1]);
67 const float step = get_step_size(*this);
68 if (step > 0.0f) {
70 if (m_range[0] != 0.0f)
71 global_t = std::log(value / m_range[0]) / step;
72 }
73 else
74 global_t = (value - m_range[0]) / step;
75 }
76
77 const size_t color_max_idx = m_palette.size() - 1;
78
79 // Compute the two colors just below (low) and above (high) the input value
80 const size_t color_low_idx = std::clamp<size_t>(static_cast<size_t>(global_t), 0, color_max_idx);
81 const size_t color_high_idx = std::clamp<size_t>(color_low_idx + 1, 0, color_max_idx);
82
83 // Interpolate between the low and high colors to find exactly which color the input value should get
84 return lerp(m_palette[color_low_idx], m_palette[color_high_idx], global_t - static_cast<float>(color_low_idx));
85}
std::array< float, 2 > m_range
Definition ColorRange.hpp:89
@ Logarithmic
Definition Types.hpp:214
static float get_step_size(const ColorRange &color_range)
Definition ColorRange.cpp:22
Color lerp(const Color &c1, const Color &c2, float t)
Definition Types.cpp:37
void step(Coord &crd, const Dir d, const long n=1)
Definition MarchingSquares.hpp:213

References libvgcode::get_step_size(), libvgcode::lerp(), libvgcode::Logarithmic, m_palette, m_range, and m_type.

Referenced by Slic3r::GUI::GCodeViewer::update_sequential_view_current().

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

◆ get_palette()

const Palette & libvgcode::ColorRange::get_palette ( ) const
52{
53 return m_palette;
54}

References m_palette.

Referenced by libvgcode::get_step_size().

Here is the caller graph for this function:

◆ get_range()

const std::array< float, 2 > & libvgcode::ColorRange::get_range ( ) const
88{
89 return m_range;
90}

References m_range.

Referenced by libvgcode::get_step_size(), and Slic3r::GUI::GCodeViewer::update_sequential_view_current().

Here is the caller graph for this function:

◆ get_type()

EColorRangeType libvgcode::ColorRange::get_type ( ) const
47{
48 return m_type;
49}

References m_type.

Referenced by libvgcode::get_step_size().

Here is the caller graph for this function:

◆ get_values()

std::vector< float > libvgcode::ColorRange::get_values ( ) const
93{
94 std::vector<float> ret;
95
96 if (m_count == 1) {
97 // single item use case
98 ret.emplace_back(m_range[0]);
99 }
100 else if (m_count == 2) {
101 // two items use case
102 ret.emplace_back(m_range[0]);
103 ret.emplace_back(m_range[1]);
104 }
105 else {
106 const float step_size = get_step_size(*this);
107 for (size_t i = 0; i < m_palette.size(); ++i) {
108 float value = 0.0f;
109 switch (m_type)
110 {
111 default:
112 case EColorRangeType::Linear: { value = m_range[0] + static_cast<float>(i) * step_size; break; }
113 case EColorRangeType::Logarithmic: { value = ::exp(::log(m_range[0]) + static_cast<float>(i) * step_size); break; }
114 }
115 ret.emplace_back(value);
116 }
117 }
118
119 return ret;
120}
std::size_t m_count
Definition ColorRange.hpp:93
@ Linear
Definition Types.hpp:213

References libvgcode::get_step_size(), libvgcode::Linear, libvgcode::Logarithmic, m_count, m_palette, m_range, and m_type.

Referenced by Slic3r::GUI::GCodeViewer::update_sequential_view_current().

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

◆ reset()

void libvgcode::ColorRange::reset ( )
private
138{
139 m_range = { FLT_MAX, -FLT_MAX };
140 m_count = 0;
141}

References m_count, and m_range.

◆ set_palette()

void libvgcode::ColorRange::set_palette ( const Palette & palette)
57{
58 if (palette.size() > 1)
59 m_palette = palette;
60}

References m_palette.

◆ size_in_bytes_cpu()

size_t libvgcode::ColorRange::size_in_bytes_cpu ( ) const
123{
124 size_t ret = STDVEC_MEMSIZE(m_palette, Color);
125 return ret;
126}
#define STDVEC_MEMSIZE(NAME, TYPE)
|/ Copyright (c) Prusa Research 2023 Enrico Turri @enricoturri1966 |/ |/ libvgcode is released under ...
Definition Utils.hpp:15
std::array< uint8_t, 3 > Color
Definition Types.hpp:59

References m_palette, and STDVEC_MEMSIZE.

◆ update()

void libvgcode::ColorRange::update ( float value)
private
129{
130 if (value != m_range[0] && value != m_range[1])
131 ++m_count;
132
133 m_range[0] = std::min(m_range[0], value);
134 m_range[1] = std::max(m_range[1], value);
135}

References m_count, and m_range.

◆ ViewerImpl

friend class ViewerImpl
friend

References ViewerImpl.

Referenced by ViewerImpl.

Member Data Documentation

◆ DUMMY_COLOR_RANGE

const ColorRange libvgcode::ColorRange::DUMMY_COLOR_RANGE = ColorRange()
static

◆ m_count

std::size_t libvgcode::ColorRange::m_count { 0 }
private
93{ 0 };

Referenced by get_values(), reset(), and update().

◆ m_palette

Palette libvgcode::ColorRange::m_palette
private

◆ m_range

std::array<float, 2> libvgcode::ColorRange::m_range { FLT_MAX, -FLT_MAX }
private
89{ FLT_MAX, -FLT_MAX };

Referenced by get_color_at(), get_range(), get_values(), reset(), and update().

◆ m_type

EColorRangeType libvgcode::ColorRange::m_type { EColorRangeType::Linear }
private

The documentation for this class was generated from the following files:
  • /home/runner/work/OrcaSlicer/OrcaSlicer/src/libvgcode/include/ColorRange.hpp
  • /home/runner/work/OrcaSlicer/OrcaSlicer/src/libvgcode/src/ColorRange.cpp