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:
64 virtual ~device_color_scale() = default;
65
69 device_color_scale_arguments get_arguments() const;
70
74 cgv::data::time_point get_modified_time() const {
75 return get_color_scale()->get_modified_time();
76 }
77
87 std::vector<cgv::rgba> get_texture_data(size_t texture_resolution) const;
88
89private:
93 virtual const cgv::media::color_scale* get_color_scale() const = 0;
94
101 virtual void update_color_scale_specific_arguments(device_color_scale_arguments& out_uniforms) const = 0;
102};
103
107template<typename T>
109public:
111 device_color_scale_storage() : color_scale(std::make_shared<T>()) {}
112
116 device_color_scale_storage(std::shared_ptr<T> color_scale) : color_scale(color_scale) {}
117
119 std::shared_ptr<T> color_scale;
120
121private:
123 const cgv::media::color_scale* get_color_scale() const override {
124 return color_scale.get();
125 };
126};
127
129class CGV_API device_continuous_color_scale : public device_color_scale_storage<cgv::media::continuous_color_scale> {
131
132public:
133 using base::base;
134
135private:
137 void update_color_scale_specific_arguments(device_color_scale_arguments& out_arguments) const override;
138};
139
141class CGV_API device_discrete_color_scale : public device_color_scale_storage<cgv::media::discrete_color_scale> {
143
144public:
145 using base::base;
146
147private:
149 void update_color_scale_specific_arguments(device_color_scale_arguments& out_arguments) const override;
150};
151
153class CGV_API device_transfer_function : public device_color_scale_storage<cgv::media::transfer_function> {
155
156public:
157 using base::base;
158
159private:
161 void update_color_scale_specific_arguments(device_color_scale_arguments& out_arguments) const override {
162 // Transfer function uses the default arguments.
163 }
164};
165
166} // namespace render
167} // namespace cgv
168
169#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.