14namespace Json{
class Value; }
37 [[nodiscard]] MRVIEWER_API
static const std::vector<Color> &
GreenRedColors();
39 MRVIEWER_API
Palette(
const std::vector<Color>& colors );
68 MRVIEWER_API
void draw(
const std::string& windowName,
const ImVec2& pose,
const ImVec2&
size,
bool onlyTopHalf =
false );
75 MRVIEWER_API
void draw( ImDrawList* drawList,
float scaling,
const ImVec2& pos,
const ImVec2&
size,
const Color& labelBgColor,
bool onlyTopHalf =
false )
const;
76 MRVIEWER_API
void draw( ImDrawList* drawList,
float scaling,
const ImVec2& pos,
const ImVec2&
size,
bool onlyTopHalf =
false )
const;
117 MRVIEWER_API VertColors
getVertColors(
const VertScalars& values,
const VertBitSet& region,
const VertBitSet* valids,
const VertBitSet* validsForStats );
130 valid ? 0.25f : 0.75f
136 [[nodiscard]] MRVIEWER_API
static VertPredicate
predFromBitSet(
const VertBitSet* bits );
142 MRVIEWER_API VertUVCoords
getUVcoords(
const VertScalars & values,
const VertBitSet & region,
const VertPredicate & valids = {},
const VertPredicate & validsForStats = {} );
144 VertUVCoords
getUVcoords(
const VertScalars & values,
const VertBitSet & region,
const VertBitSet * valids,
const VertBitSet * validsForStats =
nullptr )
152 std::vector<float>
ranges = { 0.f, 1.f };
161 [[nodiscard]]
float getRangeMin()
const {
return parameters_.ranges.front(); }
164 [[nodiscard]]
float getRangeMax()
const {
return parameters_.ranges.back(); }
198 MRVIEWER_API
void updateStats(
const VertScalars& values,
const VertBitSet& region,
const VertPredicate& vertPredicate );
202 MRVIEWER_API std::vector<Label> createUniformLabels()
const;
207 std::vector<int> buckets;
209 int beforeBucket = 0;
217 bool needsUpdate =
true;
219 MRVIEWER_API
void reset();
220 MRVIEWER_API
void addValue(
float value );
222 MRVIEWER_API
void finalize();
226 [[nodiscard]]
const Histogram &getHistogramValues() {
return histogram_; }
228 [[nodiscard]]
const Histogram &getDiscrHistogramValues()
const {
return histogramDiscr_; }
232 MRVIEWER_API
void setDrawDelayFrames(
int numFrames );
235 void setRangeLimits_(
const std::vector<float>& ranges );
237 void updateDiscretizatedColors_();
238 Color getBaseColor_(
float val );
241 const Color& getBackgroundColor_()
const;
245 void setUniformLabels_();
247 void makeUniformLabels_( std::vector<Label>& labels )
const;
250 void setZeroCentredLabels_();
252 void updateCustomLabels_();
254 void sortLabels_( std::vector<Label>& labels )
const;
256 void updateLegendLimits_(
const MinMaxf& limits );
257 void updateLegendLimitIndexes_();
259 std::vector<Label> customLabels_;
260 std::vector<Label> labels_;
261 bool showLabels_ =
false;
266 const char* getAdjustedLabelText_( std::size_t labelIndex,
bool onlyTopHalf, std::string& storage )
const;
269 float getMaxLabelWidth_(
bool onlyTopHalf =
false )
const;
271 struct StyleVariables
274 ImVec2 windowPaddingA;
276 ImVec2 windowPaddingB;
278 float labelToColoredRectSpacing {};
280 float minColoredRectWidth {};
282 StyleVariables getStyleVariables_(
float scaling )
const;
285 MeshTexture texture_;
288 float texStart_ = 0, texEnd_ = 1;
292 bool isWindowOpen_ =
false;
294 bool useCustomLabels_ =
false;
296 int maxLabelCount_ = 0;
298 float prevMaxLabelWidth_ = 0.0f;
300 MinMaxi legendLimitIndexes_ = { 0, 7 };
301 MinMaxf relativeLimits_ = { 0.f, 1.f };
304 Histogram histogram_;
307 Histogram histogramDiscr_;
310 bool enableHistogramDiscr_ =
false;
333 ~PalettePresets() =
default;
335 std::vector<std::string> names_;
339 static PalettePresets& instance_();
Definition MRHistogram.h:13
Class to hold one dimension texture with value to UV mapping.
Definition MRPalette.h:30
VertUVCoords getUVcoords(const VertScalars &values, const VertBitSet ®ion, const VertPredicate &valids={}, const VertPredicate &validsForStats={})
static bool loadPreset(const std::string &name, Palette &palette)
std::string getStringValue(float value) const
returns formated string for this value of palette
float getRangeSq() const
returns minimum squared value, not smaller than all squared values of palette's range
Definition MRPalette.h:167
std::vector< Color > baseColors
range limits for palette
Definition MRPalette.h:153
const MeshTexture & getTexture() const
Definition MRPalette.h:119
constexpr T sqr(T x) noexcept
squared value
Definition MRMeshFwd.h:763
static void resizeCallback_(ImGuiSizeCallbackData *data)
void setMaxLabelCount(int val)
sets maximal label count
void setCustomLabels(const std::vector< Label > &labels)
set labels manually
int discretization
if valid - limit legend range
Definition MRPalette.h:155
MinMax< float > MinMaxf
Definition MRMeshFwd.h:418
void setBaseColors(const std::vector< Color > &colors)
Set base palette colors colors.size() should be more or equal 2 for discrete palette using vector of ...
ImVec2 size(const ViewportRectangle &rect)
Definition MRViewport.h:32
void draw(ImDrawList *drawList, float scaling, const ImVec2 &pos, const ImVec2 &size, bool onlyTopHalf=false) const
void saveCurrentToJson(Json::Value &root) const
Serialize this palette data to JsonValue.
const Parameters & getParameters() const
Definition MRPalette.h:158
void setNumHistogramBuckets(int n)
float value
Definition MRPalette.h:81
bool isDiscretizationPercentagesEnabled() const
Should we maintain the percentages of distances in each discretization step?
Definition MRPalette.h:192
int getDefaultNumHistogramBuckets() const
Returns the recommended argument for setNumHistogramBuckets().
int drawDelayFrames_
Definition MRPalette.h:313
static const std::vector< Color > & GreenRedColors()
simpler palette colors: from green to red
void draw(ImDrawList *drawList, float scaling, const ImVec2 &pos, const ImVec2 &size, const Color &labelBgColor, bool onlyTopHalf=false) const
FilterType
Definition MREnums.h:12
float getRangeMin() const
returns minimum value in the palette's range
Definition MRPalette.h:161
tl::expected< T, E > Expected
Definition MRExpected.h:31
bool isHistogramEnabled() const
Histogram:
Definition MRPalette.h:182
Vector2f UVCoord
Definition MRMeshFwd.h:513
void enableDiscretizationPercentages(bool enable)
Definition MRPalette.h:193
void setFilterType(FilterType type)
set palette type (linear / discrete)
int getNumHistogramBuckets() const
bool loadFromJson(const Json::Value &root)
void setDiscretizationNumber(int discretization)
set number of different colors for discrete palette
Label(float val, std::string text)
void setRangeMinMaxNegPos(float minNeg, float maxNeg, float minPos, float maxPos)
set range limits for palette (need for find color by value) two half palette colors are evenly distri...
MinMax< int > MinMaxi
Definition MRMeshFwd.h:420
static const std::vector< std::string > & getPresetNames()
gets names of existing presets
static Expected< void > savePreset(const std::string &name, const Palette &palette)
saves given palette to preset with given name
static std::filesystem::path getPalettePresetsFolder()
returns path to presets folder
std::vector< float > ranges
Definition MRPalette.h:152
int getMaxLabelCount()
returns maximal label count
VertUVCoords getUVcoords(const VertScalars &values, const VertBitSet ®ion, const VertBitSet *valids, const VertBitSet *validsForStats=nullptr)
Definition MRPalette.h:144
static constexpr Color gray() noexcept
Definition MRColor.h:30
void setRangeMinMax(float min, float max)
set range limits for palette (need for find color by value) all palette colors are evenly distributed...
void draw(const std::string &windowName, const ImVec2 &pose, const ImVec2 &size, bool onlyTopHalf=false)
static const std::vector< Color > DefaultColors
preset palette colors: from blue via green to red
Definition MRPalette.h:33
float getRangeMax() const
returns maximum value in the palette's range
Definition MRPalette.h:164
Color getColor(float relativeValue) const
static const std::vector< Color > & BlueGreenRedColors()
Definition MRPalette.h:34
UVCoord getUVcoord(float val, bool valid=true) const
Definition MRPalette.h:126
std::string text
label position according normal scale (from Min to Max)
Definition MRPalette.h:82
Color getInvalidColor() const
return invalid color
Definition MRPalette.h:112
VertColors getVertColors(const VertScalars &values, const VertBitSet ®ion, const VertBitSet *valids, const VertBitSet *validsForStats)
bool isZero
label text
Definition MRPalette.h:86
void resetLabels()
reset labels to standard view
MinMaxf legendLimits
palette base colors (need for calculate real colors according discretization)
Definition MRPalette.h:154
float getRelativePos(float val) const
get relative position in [0,1], where 0 is for minimum and 1 is for maximum
void setLabelsVisible(bool visible)
set labels visible
void setLegendLimits(const MinMaxf &limits)
set legend limits. if min > max - limits are disabled
Palette(const std::vector< Color > &colors)
static VertPredicate predFromBitSet(const VertBitSet *bits)
only for bindings generation
Definition MRCameraOrientationPlugin.h:8
Definition MRMeshTexture.h:13
base parameters of palette
Definition MRPalette.h:151