cgv
Loading...
Searching...
No Matches
device_color_scale.h
1#pragma once
2
3#include <cstdint>
4
5#include <cgv/media/color_scale.h>
6#include <cgv/media/transfer_function.h>
7#include <cgv/type/bool32_t.h>
8
9#include "lib_begin.h"
10
11namespace cgv {
12namespace render {
13
15enum class DeviceColorScaleSampleMode : uint8_t {
16 kContinuous = 0,
17 kDiscrete = 1
18};
19
21enum class DeviceColorScaleMappingOptions : uint8_t {
22 kNone = 0,
23 kClamped = 1,
24 kDiverging = 2
25};
26
28 using T = std::underlying_type_t<DeviceColorScaleMappingOptions>;
29 return static_cast<DeviceColorScaleMappingOptions>(static_cast<T>(lhs) | static_cast<T>(rhs));
30}
31
33 lhs = lhs | rhs;
34 return lhs;
35}
36
43 static constexpr size_t k_max_indexed_color_count = 255;
44 vec2 domain = { 0.0f, 1.0f };
45 rgba8 unknown_color = { 0, 0, 0, 255 };
46 float midpoint = 0.5f;
47 float exponent = 1.0f;
48 float log_base = 1.0f;
49 float log_midpoint = 0.5f;
50 float log_lower_bound = 0.0f;
51 float log_upper_bound = 1.0f;
52 float log_sign = 1.0f;
55 uint16_t transform = 0;
56 DeviceColorScaleMappingOptions mapping_options = DeviceColorScaleMappingOptions::kNone;
57 DeviceColorScaleSampleMode sample_mode = DeviceColorScaleSampleMode::kContinuous;
58 int32_t indexed_color_count = 0;
59};
60
62class CGV_API device_color_scale {
63public:
67 device_color_scale_arguments get_arguments() const;
68
72 cgv::data::time_point get_modified_time() const {
73 return get_color_scale()->get_modified_time();
74 }
75
85 std::vector<cgv::rgba> get_texture_data(size_t texture_resolution) const;
86
87private:
91 virtual const cgv::media::color_scale* get_color_scale() const = 0;
92
99 virtual void update_color_scale_specific_arguments(device_color_scale_arguments& out_uniforms) const = 0;
100};
101
105template<typename T>
107public:
109 device_color_scale_storage() : color_scale(std::make_shared<T>()) {}
110
114 device_color_scale_storage(std::shared_ptr<T> color_scale) : color_scale(color_scale) {}
115
117 std::shared_ptr<T> color_scale;
118
119private:
121 const cgv::media::color_scale* get_color_scale() const override {
122 return color_scale.get();
123 };
124};
125
127class CGV_API device_continuous_color_scale : public device_color_scale_storage<cgv::media::continuous_color_scale> {
129
130public:
131 using base::base;
132
133private:
135 void update_color_scale_specific_arguments(device_color_scale_arguments& out_arguments) const override;
136};
137
139class CGV_API device_discrete_color_scale : public device_color_scale_storage<cgv::media::discrete_color_scale> {
141
142public:
143 using base::base;
144
145private:
147 void update_color_scale_specific_arguments(device_color_scale_arguments& out_arguments) const override;
148};
149
151class CGV_API device_transfer_function : public device_color_scale_storage<cgv::media::transfer_function> {
153
154public:
155 using base::base;
156
157private:
159 void update_color_scale_specific_arguments(device_color_scale_arguments& out_arguments) const override {
160 // Transfer function uses the default arguments.
161 }
162};
163
164} // namespace render
165} // namespace cgv
166
167#include <cgv/config/lib_end.h>
base class for all classes that can be registered with support for dynamic properties (see also secti...
Definition base.h:75
Base class defining an interface for color scales.
Definition color_scale.h:22
Base class template that provides a pointer to a concrete color scale implementation.
device_color_scale_storage(std::shared_ptr< T > color_scale)
Construct using the given color scale pointer.
std::shared_ptr< T > color_scale
The underlying host-side color scale.
device_color_scale_storage()
Construct using an default-constructed color scale of type T.
Base class defining an interface for using color scales on the graphics device, e....
cgv::data::time_point get_modified_time() const
Get the time point of the last modification of this object.
Implementation of a device_color_scale that wraps cgv::media::continuous_color_scale.
Implementation of a device_color_scale that wraps cgv::media::discrete_color_scale.
Implementation of a device_color_scale that wraps cgv::media::transfer_function.
DeviceColorScaleSampleMode
Sample mode of the device color scale.
DeviceColorScaleMappingOptions
Flags that represent boolean mapping options of the color scales.
this header is dependency free
Definition print.h:11
Color scale arguments as used by the graphics device or shader program.
uint16_t transform
The next three fields "transform, mapping_options and sample_mode" take up 4 bytes in total.