14namespace Json{
class Value; }
34 [[nodiscard]] MRVIEWER_API
static const std::vector<Color> &
GreenRedColors();
36 MRVIEWER_API
Palette(
const std::vector<Color>& colors );
65 MRVIEWER_API
void draw(
const std::string& windowName,
const ImVec2& pose,
const ImVec2&
size,
bool onlyTopHalf =
false );
72 MRVIEWER_API
void draw( ImDrawList* drawList,
float scaling,
const ImVec2& pos,
const ImVec2&
size,
const Color& labelBgColor,
bool onlyTopHalf =
false )
const;
73 MRVIEWER_API
void draw( ImDrawList* drawList,
float scaling,
const ImVec2& pos,
const ImVec2&
size,
bool onlyTopHalf =
false )
const;
86 MRVIEWER_API
Label(
float val, std::string text );
114 MRVIEWER_API VertColors
getVertColors(
const VertScalars& values,
const VertBitSet& region,
const VertBitSet* valids,
const VertBitSet* validsForStats );
127 valid ? 0.25f : 0.75f
133 [[nodiscard]] MRVIEWER_API
static VertPredicate
predFromBitSet(
const VertBitSet* bits );
139 MRVIEWER_API VertUVCoords
getUVcoords(
const VertScalars & values,
const VertBitSet & region,
const VertPredicate & valids = {},
const VertPredicate & validsForStats = {} );
141 VertUVCoords
getUVcoords(
const VertScalars & values,
const VertBitSet & region,
const VertBitSet * valids,
const VertBitSet * validsForStats =
nullptr )
149 std::vector<float>
ranges = { 0.f, 1.f };
195 MRVIEWER_API
void updateStats(
const VertScalars& values,
const VertBitSet& region,
const VertPredicate& vertPredicate );
228 void setRangeLimits_(
const std::vector<float>& ranges );
230 void updateDiscretizatedColors_();
231 Color getBaseColor_(
float val );
234 const Color& getBackgroundColor_()
const;
238 void setUniformLabels_();
240 void makeUniformLabels_( std::vector<Label>& labels )
const;
243 void setZeroCentredLabels_();
245 void updateCustomLabels_();
247 void sortLabels_( std::vector<Label>& labels )
const;
249 void updateLegendLimits_(
const MinMaxf& limits );
250 void updateLegendLimitIndexes_();
252 std::vector<Label> customLabels_;
253 std::vector<Label> labels_;
254 bool showLabels_ =
false;
259 const char* getAdjustedLabelText_( std::size_t labelIndex,
bool onlyTopHalf, std::string& storage )
const;
262 float getMaxLabelWidth_(
bool onlyTopHalf =
false )
const;
264 struct StyleVariables
267 ImVec2 windowPaddingA;
269 ImVec2 windowPaddingB;
271 float labelToColoredRectSpacing {};
273 float minColoredRectWidth {};
275 StyleVariables getStyleVariables_(
float scaling )
const;
278 MeshTexture texture_;
281 float texStart_ = 0, texEnd_ = 1;
283 Parameters parameters_;
285 bool isWindowOpen_ =
false;
287 bool useCustomLabels_ =
false;
289 int maxLabelCount_ = 0;
291 float prevMaxLabelWidth_ = 0.0f;
293 MinMaxi legendLimitIndexes_ = { 0, 7 };
294 MinMaxf relativeLimits_ = { 0.f, 1.f };
297 Histogram histogram_;
300 Histogram histogramDiscr_;
303 bool enableHistogramDiscr_ =
false;
305 static void resizeCallback_( ImGuiSizeCallbackData* data );
325 std::vector<std::string> names_;
Class to save and load user palette presets.
Definition MRPalette.h:310
static MRVIEWER_API Expected< void > savePreset(const std::string &name, const Palette &palette)
saves given palette to preset with given name
static MRVIEWER_API std::filesystem::path getPalettePresetsFolder()
returns path to presets folder
static MRVIEWER_API bool loadPreset(const std::string &name, Palette &palette)
static MRVIEWER_API const std::vector< std::string > & getPresetNames()
gets names of existing presets
Class to hold one dimension texture with value to UV mapping.
Definition MRPalette.h:27
MRVIEWER_API float getRelativePos(float val) const
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:164
MRVIEWER_API int getMaxLabelCount()
returns maximal label count
const MeshTexture & getTexture() const
Definition MRPalette.h:116
MRVIEWER_API Palette(const std::vector< Color > &colors)
MRVIEWER_API int getNumHistogramBuckets() const
MRVIEWER_API bool loadFromJson(const Json::Value &root)
MRVIEWER_API void setFilterType(FilterType type)
MRVIEWER_API void updateStats(const VertScalars &values, const VertBitSet ®ion, const VertPredicate &vertPredicate)
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:155
MRVIEWER_API std::vector< Label > createUniformLabels() const
MRVIEWER_API void draw(ImDrawList *drawList, float scaling, const ImVec2 &pos, const ImVec2 &size, bool onlyTopHalf=false) const
bool isDiscretizationPercentagesEnabled() const
Definition MRPalette.h:189
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)
MRVIEWER_API void setLegendLimits(const MinMaxf &limits)
set legend limits. if min > max - limits are disabled
float getRangeMin() const
returns minimum value in the palette's range
Definition MRPalette.h:158
bool isHistogramEnabled() const
Definition MRPalette.h:179
void enableDiscretizationPercentages(bool enable)
Definition MRPalette.h:190
MRVIEWER_API void setMaxLabelCount(int val)
sets maximal label count
MRVIEWER_API void setNumHistogramBuckets(int n)
MRVIEWER_API void saveCurrentToJson(Json::Value &root) const
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
MRVIEWER_API void setDiscretizationNumber(int discretization)
MRVIEWER_API Color getColor(float relativeValue) const
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:30
VertUVCoords getUVcoords(const VertScalars &values, const VertBitSet ®ion, const VertBitSet *valids, const VertBitSet *validsForStats=nullptr)
Definition MRPalette.h:141
const Histogram & getHistogramValues()
Definition MRPalette.h:223
MRVIEWER_API void resetLabels()
float getRangeMax() const
returns maximum value in the palette's range
Definition MRPalette.h:161
const Histogram & getDiscrHistogramValues() const
Definition MRPalette.h:225
static const std::vector< Color > & BlueGreenRedColors()
Definition MRPalette.h:31
static MRVIEWER_API VertPredicate predFromBitSet(const VertBitSet *bits)
UVCoord getUVcoord(float val, bool valid=true) const
Definition MRPalette.h:123
MRVIEWER_API void setLabelsVisible(bool visible)
Color getInvalidColor() const
return invalid color
Definition MRPalette.h:109
MRVIEWER_API VertColors getVertColors(const VertScalars &values, const VertBitSet ®ion, const VertBitSet *valids, const VertBitSet *validsForStats)
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 ...
Definition MRCameraOrientationPlugin.h:8
constexpr T sqr(T x) noexcept
squared value
Definition MRMesh/MRMeshFwd.h:753
MinMax< float > MinMaxf
Definition MRMesh/MRMeshFwd.h:411
ImVec2 size(const ViewportRectangle &rect)
Definition MRViewport.h:29
FilterType
Definition MRMesh/MRMeshFwd.h:731
tl::expected< T, E > Expected
Definition MRExpected.h:25
Vector2f UVCoord
Definition MRMesh/MRMeshFwd.h:505
MinMax< int > MinMaxi
Definition MRMesh/MRMeshFwd.h:413
Box given by its min- and max- corners.
Definition MRMesh/MRBox.h:26
Definition MRMesh/MRColor.h:9
static constexpr Color gray() noexcept
Definition MRMesh/MRColor.h:27
Definition MRMeshTexture.h:13
Definition MRPalette.h:202
int numEntries
Definition MRPalette.h:209
bool needsUpdate
Definition MRPalette.h:214
std::vector< int > buckets
Definition MRPalette.h:204
int afterBucket
Definition MRPalette.h:207
MRVIEWER_API void reset()
MRVIEWER_API void finalize()
int maxEntry
Definition MRPalette.h:211
int beforeBucket
Definition MRPalette.h:206
MRVIEWER_API void addValue(float value)
Definition MRPalette.h:77
MRVIEWER_API Label(float val, std::string text)
std::string text
Definition MRPalette.h:79
Definition MRPalette.h:148
std::vector< Color > baseColors
Definition MRPalette.h:150
int discretization
Definition MRPalette.h:152
std::vector< float > ranges
Definition MRPalette.h:149
MinMaxf legendLimits
Definition MRPalette.h:151