2#include "MRViewerFwd.h"
3#include "MRMesh/MRMeshFwd.h"
4#include "MRMesh/MRVector4.h"
5#include "MRMesh/MRMeshTexture.h"
6#include "MRMesh/MRColor.h"
7#include "MRMesh/MRExpected.h"
8#include "MRViewer/MRImGui.h"
9#include "MRMesh/MRBox.h"
10#include "MRMesh/MRVector.h"
14namespace Json{
class Value; }
31 [[nodiscard]]
static const std::vector<Color> & BlueGreenRedColors() {
return DefaultColors; }
34 [[nodiscard]] MRVIEWER_API
static const std::vector<Color> &
GreenRedColors();
36 MRVIEWER_API
Palette(
const std::vector<Color>& colors );
57 MRVIEWER_API
void setDiscretizationNumber(
int discretization );
59 MRVIEWER_API
void setFilterType( FilterType type );
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 );
89 MRVIEWER_API
void resetLabels();
91 MRVIEWER_API
void setCustomLabels(
const std::vector<Label>& labels );
93 MRVIEWER_API
void setLabelsVisible(
bool visible );
98 MRVIEWER_API
bool loadFromJson(
const Json::Value& root );
100 MRVIEWER_API
void saveCurrentToJson( Json::Value& root )
const;
116 const MeshTexture& getTexture()
const {
return texture_; };
119 MRVIEWER_API
float getRelativePos(
float val )
const;
126 ( texEnd_ - texStart_ ) * getRelativePos( val ) + texStart_,
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 )
143 return getUVcoords( values, region, predFromBitSet( valids ), predFromBitSet( validsForStats ) );
149 std::vector<float> ranges = { 0.f, 1.f };
150 std::vector<Color> baseColors;
151 MinMaxf legendLimits;
152 int discretization = 7;
155 [[nodiscard]]
const Parameters& getParameters()
const {
return parameters_; }
158 [[nodiscard]]
float getRangeMin()
const {
return parameters_.ranges.front(); }
161 [[nodiscard]]
float getRangeMax()
const {
return parameters_.ranges.back(); }
179 [[nodiscard]]
bool isHistogramEnabled()
const {
return getNumHistogramBuckets() != 0; }
180 [[nodiscard]] MRVIEWER_API
int getNumHistogramBuckets()
const;
183 MRVIEWER_API
void setNumHistogramBuckets(
int n );
185 [[nodiscard]] MRVIEWER_API
int getDefaultNumHistogramBuckets()
const;
189 [[nodiscard]]
bool isDiscretizationPercentagesEnabled()
const {
return enableHistogramDiscr_; }
190 void enableDiscretizationPercentages(
bool enable ) { histogramDiscr_.reset(); enableHistogramDiscr_ = enable; }
195 MRVIEWER_API
void updateStats(
const VertScalars& values,
const VertBitSet& region,
const VertPredicate& vertPredicate );
204 std::vector<int> buckets;
206 int beforeBucket = 0;
214 bool needsUpdate =
true;
216 MRVIEWER_API
void reset();
217 MRVIEWER_API
void addValue(
float value );
219 MRVIEWER_API
void finalize();
223 [[nodiscard]]
const Histogram &getHistogramValues() {
return histogram_; }
225 [[nodiscard]]
const Histogram &getDiscrHistogramValues()
const {
return histogramDiscr_; }
229 MRVIEWER_API
void setDrawDelayFrames(
int numFrames );
232 void setRangeLimits_(
const std::vector<float>& ranges );
234 void updateDiscretizatedColors_();
235 Color getBaseColor_(
float val );
238 const Color& getBackgroundColor_()
const;
242 void setUniformLabels_();
244 void makeUniformLabels_( std::vector<Label>& labels )
const;
247 void setZeroCentredLabels_();
249 void updateCustomLabels_();
251 void sortLabels_( std::vector<Label>& labels )
const;
253 void updateLegendLimits_(
const MinMaxf& limits );
254 void updateLegendLimitIndexes_();
256 std::vector<Label> customLabels_;
257 std::vector<Label> labels_;
258 bool showLabels_ =
false;
263 const char* getAdjustedLabelText_( std::size_t labelIndex,
bool onlyTopHalf, std::string& storage )
const;
266 float getMaxLabelWidth_(
bool onlyTopHalf =
false )
const;
268 struct StyleVariables
271 ImVec2 windowPaddingA;
273 ImVec2 windowPaddingB;
275 float labelToColoredRectSpacing {};
277 float minColoredRectWidth {};
279 StyleVariables getStyleVariables_(
float scaling )
const;
282 MeshTexture texture_;
285 float texStart_ = 0, texEnd_ = 1;
287 Parameters parameters_;
289 bool isWindowOpen_ =
false;
291 bool useCustomLabels_ =
false;
293 int maxLabelCount_ = 0;
295 float prevMaxLabelWidth_ = 0.0f;
297 MinMaxi legendLimitIndexes_ = { 0, 7 };
298 MinMaxf relativeLimits_ = { 0.f, 1.f };
301 Histogram histogram_;
304 Histogram histogramDiscr_;
307 bool enableHistogramDiscr_ =
false;
310 int drawDelayFrames_ = 0;
312 static void resizeCallback_( ImGuiSizeCallbackData* data );
325 MRVIEWER_API
static Expected<void>
savePreset(
const std::string& name,
const Palette& palette );
332 std::vector<std::string> names_;
Definition MRHistogram.h:10
Definition MRMeshTexture.h:13
Class to save and load user palette presets.
Definition MRPalette.h:317
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 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
MRVIEWER_API void draw(ImDrawList *drawList, float scaling, const ImVec2 &pos, const ImVec2 &size, const Color &labelBgColor, bool onlyTopHalf=false) const
MRVIEWER_API std::vector< Label > createUniformLabels() const
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 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
MRVIEWER_API void setMaxLabelCount(int val)
sets maximal label count
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 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
float getRangeMax() const
returns maximum value in the palette's range
Definition MRPalette.h:161
UVCoord getUVcoord(float val, bool valid=true) const
Definition MRPalette.h:123
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 MRMesh/MRColor.h:9
Definition MRPalette.h:202
Definition MRPalette.h:77
Definition MRPalette.h:148