MCPcopy Create free account
hub / github.com/KDE/labplot / generate

Method generate

src/frontend/matrix/MatrixFunctionDialog.cpp:194–264  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

192};
193
194void MatrixFunctionDialog::generate() {
195 WAIT_CURSOR;
196
197 m_matrix->beginMacro(i18n("%1: fill matrix with function values", m_matrix->name()));
198
199 // TODO: data types
200 auto* new_data = static_cast<QVector<QVector<double>>*>(m_matrix->data());
201
202 // check if rows or cols == 1
203 double diff = m_matrix->xEnd() - m_matrix->xStart();
204 double xStep = 0.0;
205 if (m_matrix->columnCount() > 1)
206 xStep = diff / double(m_matrix->columnCount() - 1);
207
208 diff = m_matrix->yEnd() - m_matrix->yStart();
209 double yStep = 0.0;
210 if (m_matrix->rowCount() > 1)
211 yStep = diff / double(m_matrix->rowCount() - 1);
212
213#ifndef NDEBUG
214 QElapsedTimer timer;
215 timer.start();
216#endif
217
218 // TODO: too slow because every parser thread needs an own symbol_table
219 // idea: use pool->maxThreadCount() symbol tables and reuse them?
220 /* double yStart = m_matrix->yStart();
221 const int cols = m_matrix->columnCount();
222 QThreadPool* pool = QThreadPool::globalInstance();
223 int range = ceil(double(cols)/pool->maxThreadCount());
224 DEBUG("Starting" << pool->maxThreadCount() << "threads. cols =" << cols << ": range =" << range);
225
226 for (int i = 0; i < pool->maxThreadCount(); ++i) {
227 const int start = i*range;
228 int end = (i+1)*range;
229 if (end > cols) end = cols;
230 qDebug() << "start/end: " << start << end;
231 const double xStart = m_matrix->xStart() + xStep*start;
232 GenerateValueTask* task = new GenerateValueTask(start, end, new_data, xStart, yStart, xStep, yStep,
233 qPrintable(ui.teEquation->toPlainText()));
234 task->setAutoDelete(false);
235 pool->start(task);
236 }
237 pool->waitForDone();
238 */
239 double x = m_matrix->xStart();
240 double y = m_matrix->yStart();
241 Parsing::parser_var vars[] = {{"x", x}, {"y", y}};
242 Parsing::Parser parser(true);
243 for (int col = 0; col < m_matrix->columnCount(); ++col) {
244 vars[0].value = x;
245 for (int row = 0; row < m_matrix->rowCount(); ++row) {
246 vars[1].value = y;
247 (*new_data)[col][row] = parser.parse_with_vars(qPrintable(ui.teEquation->toPlainText()), vars, 2, qPrintable(QLocale().name()));
248 y += yStep;
249 }
250 y = m_matrix->yStart();
251 x += xStep;

Calls 10

beginMacroMethod · 0.80
parse_with_varsMethod · 0.80
endMacroMethod · 0.80
nameMethod · 0.45
dataMethod · 0.45
columnCountMethod · 0.45
rowCountMethod · 0.45
startMethod · 0.45
setFormulaMethod · 0.45
setDataMethod · 0.45