PeriDyno 1.0.0
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
ImColorbar.cpp
Go to the documentation of this file.
1#include "ImColorbar.h"
2
3// framework
4#include "imgui_extend.h"
5
6namespace dyno
7{
9
11 {
12 this->setName("im_colorbar");
13
14 // mTitle = "Velocity";
15 }
16
18 {
19 // mColorBuffer.clear();
20 }
21
22 void ImColorbar::setCoord(ImVec2 coord)
23 {
24 mCoord = coord;
25 }
26
27 ImVec2 ImColorbar::getCoord() const
28 {
29 return mCoord;
30 }
31
33 {
34 mCol = nullptr;
35 mVal = nullptr;
36 return true;
37 }
38
40 {
41 if (!this->inScalar()->isEmpty())
42 {
43 auto pScalar = this->inScalar()->getData();
44 // bool pFixed = this->varFixed()->getData();
45 bool pFixed = false;
46 float lowLimit = this->varMin()->getData();
47 float upLimit = this->varMax()->getData();
48 float min_v = (pFixed)? lowLimit : m_reduce_real.minimum(pScalar.begin(), pScalar.size());
49 float max_v = (pFixed)? upLimit : m_reduce_real.maximum(pScalar.begin(), pScalar.size());
50
51 mNum = 6 + 1;
52
53 //assert(std::is_same<float, Real>::value);
54
55 float dv = (max_v - min_v) / mNum;
56 if(this->varType()->getData() == ColorTable::Jet)
57 {
58 col[0] = ImGui::ToJetColor(min_v, lowLimit, upLimit);
59 val[0] = min_v;
60 for(int i = 1; i < mNum; ++i)
61 {
62 val[i] = min_v + dv * i;
63 col[i] = ImGui::ToJetColor(val[i], lowLimit, upLimit);
64 }
65 }
66 else if(this->varType()->getData() == ColorTable::Heat)
67 {
68 col[0] = ImGui::ToHeatColor(min_v, lowLimit, upLimit);
69 val[0] = min_v;
70 for(int i = 1; i < mNum; ++i)
71 {
72 val[i] = min_v + dv * i;
73 col[i] = ImGui::ToHeatColor(val[i], lowLimit, upLimit);
74 }
75 }
76 }
77 else
78 {
79 mNum = 1;
81 val[0] = 0.0;
82
83 }
84
85 mCol = col;
86 mVal = val;
87 }
88
90 {
91 auto label = "Right sidebar ImColorBar";
92 ImGui::PushStyleColor(ImGuiCol_WindowBg, ImGui::ExColorsVal[ImGui::ImGuiExColVal_WindowTopBg_1]);
93 ImGui::Begin(label, NULL, /*ImGuiWindowFlags_NoMove |*/ ImGuiWindowFlags_NoTitleBar | /*ImGuiWindowFlags_NoBackground |*/ ImGuiWindowFlags_NoResize | ImGuiWindowFlags_AlwaysAutoResize);
94 ImGui::PopStyleColor();
95 ImGui::Text(this->varFieldName()->getData().c_str());
96 int num_type = 0;
97 if (this->varNumberType()->getData() == NumberTypeSelection::Dec) num_type = 0;
98 if (this->varNumberType()->getData() == NumberTypeSelection::Exp) num_type = 1;
99 ImGui::ColorBar("ColorBar", mVal, mCol, mNum, num_type);
100 ImGui::End();
101 }
102}
#define IMPLEMENT_CLASS(name)
Definition Object.h:79
~ImColorbar() override
Reduction< Real > m_reduce_real
Definition ImColorbar.h:87
float val[6+1]
Definition ImColorbar.h:89
virtual void update()
void setCoord(ImVec2 coord)
ImU32 col[6+1]
Definition ImColorbar.h:90
virtual void paint()
ImVec2 getCoord() const
virtual bool initialize()
void setName(std::string name)
Definition Module.cpp:187
IMGUI_API ImU32 ToJetColor(const float v, const float v_min, const float v_max)
@ ImGuiExColVal_WindowTopBg_1
ImVec4 ExColorsVal[ImGuiExColVal_COUNT]
IMGUI_API bool ColorBar(char *label, float *values, ImU32 *col, int length, int num_type)
IMGUI_API ImU32 ToHeatColor(const float v, const float v_min, const float v_max)
IMGUI_API ImU32 VecToImU(const dyno::Vec3f *v)
This is an implementation of AdditiveCCD based on peridyno.
Definition Array.h:25