2#include "MRViewerFwd.h"
3#include "MRMesh/MRMeshFwd.h"
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;
89 MRVIEWER_API
Label(
float val, std::string text );
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;
290 Parameters parameters_;
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;
335 std::vector<std::string> names_;
Definition MRHistogram.h:13
Class to save and load user palette presets.
Definition MRPalette.h:320
Class to hold one dimension texture with value to UV mapping.
Definition MRPalette.h:30
static MRVIEWER_API Expected< void > savePreset(const std::string &name, const Palette &palette)
saves given palette to preset with given name
MRVIEWER_API float getRelativePos(float val) const
get relative position in [0,1], where 0 is for minimum and 1 is for maximum
MRVIEWER_API void draw(const std::string &windowName, const ImVec2 &pose, const ImVec2 &size, bool onlyTopHalf=false)
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
MRVIEWER_API int getMaxLabelCount()
returns maximal label count
const MeshTexture & getTexture() const
Definition MRPalette.h:119
MRVIEWER_API Palette(const std::vector< Color > &colors)
MRVIEWER_API int getNumHistogramBuckets() const
static MRVIEWER_API std::filesystem::path getPalettePresetsFolder()
returns path to presets folder
MRVIEWER_API bool loadFromJson(const Json::Value &root)
MRVIEWER_API void setFilterType(FilterType type)
set palette type (linear / discrete)
static void resizeCallback_(ImGuiSizeCallbackData *data)
int discretization
if valid - limit legend range
Definition MRPalette.h:155
ImVec2 size(const ViewportRectangle &rect)
Definition MRViewport.h:32
MRVIEWER_API void draw(ImDrawList *drawList, float scaling, const ImVec2 &pos, const ImVec2 &size, const Color &labelBgColor, bool onlyTopHalf=false) const
const Parameters & getParameters() const
Definition MRPalette.h:158
MRVIEWER_API void draw(ImDrawList *drawList, float scaling, const ImVec2 &pos, const ImVec2 &size, bool onlyTopHalf=false) const
bool isDiscretizationPercentagesEnabled() const
Should we maintain the percentages of distances in each discretization step?
Definition MRPalette.h:192
MRVIEWER_API VertUVCoords getUVcoords(const VertScalars &values, const VertBitSet ®ion, const VertPredicate &valids={}, const VertPredicate &validsForStats={})
static MRVIEWER_API const std::vector< Color > & GreenRedColors()
simpler palette colors: from green to red
MRVIEWER_API void setCustomLabels(const std::vector< Label > &labels)
set labels manually
int drawDelayFrames_
Definition MRPalette.h:313
MRVIEWER_API void setLegendLimits(const MinMaxf &limits)
set legend limits. if min > max - limits are disabled
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
void enableDiscretizationPercentages(bool enable)
Definition MRPalette.h:193
MRVIEWER_API void setMaxLabelCount(int val)
sets maximal label count
MRVIEWER_API void setNumHistogramBuckets(int n)
MRVIEWER_API void saveCurrentToJson(Json::Value &root) const
Serialize this palette data to JsonValue.
MRVIEWER_API void setRangeMinMax(float min, float max)
set range limits for palette (need for find color by value) all palette colors are evenly distributed...
MRVIEWER_API int getDefaultNumHistogramBuckets() const
Returns the recommended argument for setNumHistogramBuckets().
MRVIEWER_API void setDiscretizationNumber(int discretization)
set number of different colors for discrete palette
MRVIEWER_API Color getColor(float relativeValue) const
std::vector< float > ranges
Definition MRPalette.h:152
MRVIEWER_API Label(float val, std::string text)
MRVIEWER_API 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...
static MRVIEWER_API const std::vector< Color > DefaultColors
preset palette colors: from blue via green to red
Definition MRPalette.h:33
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
static MRVIEWER_API bool loadPreset(const std::string &name, Palette &palette)
MRVIEWER_API void resetLabels()
reset labels to standard view
float getRangeMax() const
returns maximum value in the palette's range
Definition MRPalette.h:164
static const std::vector< Color > & BlueGreenRedColors()
Definition MRPalette.h:34
static MRVIEWER_API VertPredicate predFromBitSet(const VertBitSet *bits)
UVCoord getUVcoord(float val, bool valid=true) const
Definition MRPalette.h:126
MRVIEWER_API void setLabelsVisible(bool visible)
set labels visible
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
MRVIEWER_API VertColors getVertColors(const VertScalars &values, const VertBitSet ®ion, const VertBitSet *valids, const VertBitSet *validsForStats)
MinMaxf legendLimits
palette base colors (need for calculate real colors according discretization)
Definition MRPalette.h:154
MRVIEWER_API std::string getStringValue(float value) const
returns formated string for this value of palette
MRVIEWER_API 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 ...
static MRVIEWER_API const std::vector< std::string > & getPresetNames()
gets names of existing presets
only for bindings generation
Definition MRCameraOrientationPlugin.h:8
Definition MRMeshTexture.h:13
structure for label
Definition MRPalette.h:80
base parameters of palette
Definition MRPalette.h:151