-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmainwindow_funcs.cpp
More file actions
51 lines (43 loc) · 1.62 KB
/
mainwindow_funcs.cpp
File metadata and controls
51 lines (43 loc) · 1.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#include "mainwindow.h"
#include "material.h"
#include "ui_mainwindow.h"
MainWindow::MainWindow() : QMainWindow()
{
ui_.setupUi(this);
generateFunction(Test2DFunctions::AckleyFunction);
dataEntity_ = ui_.TestingWidget->addData2D("2D Function");
dataEntity_->setData(x_, y_, values_);
ui_.TestingWidget->zAxis()->setEnabled(true);
ui_.TestingWidget->zAxis()->setType(Mildred::AxisEntity::AxisType::Vertical);
//ui_.TestingWidget->yAxis()->setType(Mildred::AxisEntity::AxisType::Depth);
ui_.TestingWidget->showAllData();
};
// Generate specified function
void MainWindow::generateFunction(Test2DFunctions function)
{
// Initialise the data and calculate the delta
// Data, all bounded to [-5,5] in x and y
const auto axisMin = -50.0, axisMax = 50.0, delta = (axisMax - axisMin) / (nPoints_ - 1);
x_.reserve(nPoints_);
x_.clear();
values_.reserve(nPoints_ * nPoints_);
values_.clear();
// Generate x axis and duplicate as y
for (auto n = 0; n <= nPoints_; ++n)
x_.push_back(n * delta);
y_ = x_;
switch (function)
{
case (Test2DFunctions::AckleyFunction):
/*
* Ackley's Function
* f(x,y) = -20.0 * exp(-0.2 * sqrt(0.5 * (x^2 + y^2))) - exp(0.5 * (cos(2 * M_PI * x) + cos(2 * M_PI * y))) + e +
* 20
*/
for (const auto x : x_)
for (const auto y : y_)
values_.push_back(-20.0 * exp(-0.2 * sqrt(0.5 * (x * x + y * y))) -
exp(0.5 * (cos(2 * M_PI * x) + cos(2 * M_PI * y))) + M_E + 20);
break;
}
}