PeriDyno 1.0.0
Loading...
Searching...
No Matches
ImChart.cpp
Go to the documentation of this file.
1#include "ImChart.h"
2
3// framework
4#include "imgui_extend.h"
5#include "imgui.h"
6
7namespace dyno
8{
10
12 {
13 this->setName("im_chart");
14
15 auto callback = std::make_shared<FCallBackFunc>(std::bind(&ImChart::varChange, this));
16
17 this->varInputMode()->attach(callback);
18 this->varCount()->attach(callback);
19 this->varFixHeight()->attach(callback);
20 this->varMax()->attach(callback);
21 this->varMin()->attach(callback);
22 this->inFrameNumber()->attach(callback);
23 this->varOutputFile()->attach(callback);
24 this->varChange();
25 this->varCount()->setRange(-50000,50000);
26 this->inFrameNumber()->tagOptional(false);
27
28 isOut = this->varOutputFile()->getValue();
29
30
31 }
32
34 {
35 // mColorBuffer.clear();
36 }
37
39 {
40 if (this->varInputMode()->getValue()==ImChart::InputMode::Array)
41 {
42 //this->inValue()->demoteInput();
43 this->inArray()->tagOptional(true);
44 auto mSinks = this->inArray()->getSinks();
45 if (mSinks.size())
46 {
47 for (auto it : mSinks)
48 {
49 this->inArray()->disconnect(it);
50 }
51 }
52 }
53 else if(this->varInputMode()->getValue() == ImChart::InputMode::Var)
54 {
55 //this->inArray()->demoteInput();
56
57 this->inValue()->tagOptional(true);
58 auto mSinks = this->inValue()->getSinks();
59 if (mSinks.size())
60 {
61 for (auto it : mSinks)
62 {
63 this->inValue()->disconnect(it);
64 }
65 }
66 }
67
68
69 bool pFixed = this->varFixHeight()->getValue();
70 float lowLimit = this->varMin()->getData();
71 float upLimit = this->varMax()->getData();
72
73 if (this->varCount()->getValue() >= 1)
74 count = this->varCount()->getValue();
75
76
77 if (!this->inArray()->isEmpty() && this->varInputMode()->getValue() == InputMode::Array)
78 {
79 auto& pArray = this->inArray()->getData();
80 if (pFixed)
81 {
82#ifdef CUDA_BACKEND
83 lowLimit = m_reduce_real.minimum(pArray.begin(), pArray.size());
84 upLimit = m_reduce_real.maximum(pArray.begin(), pArray.size());
85#endif // CUDA_BACKEND
86
87#ifdef VK_BACKEND
88 //TODO: VkReduce does not support yet
89#endif // VK_BACKEND
90 }
91
92 }
93 this->min = lowLimit;
94 this->max = upLimit;
95
96 //set data;
97
98
99 //
100 if (this->varInputMode()->getValue() == ImChart::InputMode::Array)
101 {
102 drawArray();
103 }
104 else if (this->varInputMode()->getValue() == ImChart::InputMode::Var)
105 {
106 drawValue();
107 }
108
109
110
111 if (isOut)
112 this->outputTxt();
113 //
114
115 }
116
117 void ImChart::setCoord(ImVec2 coord)
118 {
119 mCoord = coord;
120 }
121
122 ImVec2 ImChart::getCoord() const
123 {
124 return mCoord;
125 }
126
128 {
129 return true;
130 }
131
133 {
134
135 }
136
138 {
139 //std::string labelName = "Label";//+this->varTitle()->getValue()
140 char* label = "Label";
141 ImGui::PushStyleColor(ImGuiCol_WindowBg, ImGui::ExColorsVal[ImGui::ImGuiExColVal_WindowTopBg_1]);
142 ImGui::Begin(label, NULL, /*ImGuiWindowFlags_NoMove |*/ ImGuiWindowFlags_NoTitleBar | /*ImGuiWindowFlags_NoBackground |*/ ImGuiWindowFlags_NoResize | ImGuiWindowFlags_AlwaysAutoResize);
143 ImGui::PopStyleColor();
144
145 std::string checklabel = "Output_" + this->varTitle()->getValue();
146
147 ImGui::Checkbox(checklabel.data(), &isOut);
148
149 printf("isout : %d \n",int(isOut));
150
151 char overlay[2] = " ";
152 ImGui::PlotLines(this->varTitle()->getValue().c_str(), valuePtr, count, 0, overlay, min, max, ImVec2(0, 80.0f));
153 ImGui::End();
154
155 //printf("c_array %d, d_array %d\n",c_Value.size(),d_Value.size());
156 }
157
159 {
160 if (!this->inArray()->isEmpty())
161 {
162 d_Value = this->inArray()->getData();
163 c_Value.assign(d_Value);
164 }
165
166 if (this->varCount()->getValue() >= 1)
167 {
168 count = this->varCount()->getValue();
169 valueVec = c_Value.handle();
170
171 if (valueVec->size() < count)
172 {
173 int temp = count - valueVec->size();
174 for (size_t i = 0; i < temp; i++)
175 {
176 valueVec->push_back(min);
177 }
178 }
179 //else if (c_Value.size() > count)
180 //{
181 // for (size_t i = 0; i < valueVec->size() - count; i++)
182 // {
183 // valueVec->erase(valueVec->end()-1);
184 // }
185 //}
186 }
187 else
188 {
189 count = c_Value.size();
190 //if (count >= 50000)
191 // count = 50000;
192 }
193
194
195 if (c_Value.size())
196 {
197 valuePtr = &c_Value[0];
198 }
199
200 }
201
203 {
204 if (this->varInputMode()->getValue() == InputMode::Var && !this->inValue()->isEmpty())
205 {
206 valueVec = c_Value.handle();
207 if (this->varCount()->getValue() >= 1 && valueVec->size())
208 valueVec->erase(valueVec->begin());
209 c_Value.pushBack(this->inValue()->getValue());
210 }
211
212 if (this->varCount()->getValue() >= 1)
213 {
214 count = this->varCount()->getValue();
215
216 if (valueVec->size() < count)
217 {
218 int temp = count - valueVec->size();
219 for (size_t i = 0; i < temp; i++)
220 {
221 valueVec->push_back(min);
222 }
223 }
224 else if (c_Value.size() > count)
225 {
226 int temp = valueVec->size();
227
228 for (size_t i = 0; i < temp; i++)
229 {
230 valueVec->erase(valueVec->end()-1);
231 }
232 }
233 }
234 else
235 {
236 if (c_Value.size())
237 count = c_Value.size();
238 else
239 count = 10;
240
241 }
242
243
244 if (c_Value.size())
245 {
246 valuePtr = &c_Value[0];
247 }
248
249
250 }
251
253 {
254
255 int out_number = this->inFrameNumber()->getValue();
256
257 std::stringstream ss; ss << out_number;
258 std::string filename = this->varOutputPath()->getData() + "_" + this->varTitle()->getValue() + ss.str() + this->file_postfix;//
259 std::ofstream output(filename.c_str(), std::ios::out);
260
261 if (!output.is_open())
262 {
263 printf("------OutputTxt: open file failed \n");
264 return;
265 }
266
267 std::cout << "------Writer Action!------ " << std::endl;
268
269
270 output << "x" << "," << "y" << std::endl;
271
272 for (uint i = 0; i < count; i++) {
273 output << i+1 << "," << c_Value[i] << std::endl;
274 }
275
276 output.close();
277
278
279 return;
280
281 }
282
283}
#define IMPLEMENT_CLASS(name)
Definition Object.h:79
DArray< Real > d_Value
Definition ImChart.h:85
void outputTxt()
Definition ImChart.cpp:252
virtual bool initialize()
Definition ImChart.cpp:127
virtual void paint()
Definition ImChart.cpp:137
float max
Definition ImChart.h:79
Real * valuePtr
Definition ImChart.h:81
CArray< Real > c_Value
Definition ImChart.h:83
float min
Definition ImChart.h:78
ImVec2 getCoord() const
Definition ImChart.cpp:122
virtual void update()
Definition ImChart.cpp:132
ImVec2 mCoord
Definition ImChart.h:68
~ImChart() override
Definition ImChart.cpp:33
void setCoord(ImVec2 coord)
Definition ImChart.cpp:117
void drawValue()
Definition ImChart.cpp:202
std::vector< Real > * valueVec
Definition ImChart.h:84
std::string file_postfix
Definition ImChart.h:92
void varChange()
Definition ImChart.cpp:38
void drawArray()
Definition ImChart.cpp:158
void setName(std::string name)
Definition Module.cpp:187
@ ImGuiExColVal_WindowTopBg_1
ImVec4 ExColorsVal[ImGuiExColVal_COUNT]
This is an implementation of AdditiveCCD based on peridyno.
Definition Array.h:25
unsigned int uint
Definition VkProgram.h:14