forked from gnudles/stereograma
-
Notifications
You must be signed in to change notification settings - Fork 0
/
FormulaGen.cpp
93 lines (81 loc) · 2.29 KB
/
FormulaGen.cpp
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#include "FormulaGen.h"
#include "ui_FormulaGen.h"
#include "exprtk/exprtk.hpp"
#include "stereomaker.h"
#include "mainwindow.h"
typedef exprtk::symbol_table<float> symbol_table_t;
typedef exprtk::expression<float> expression_t;
typedef exprtk::parser<float> parser_t;
FormulaGen::FormulaGen(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::FormulaGen)
{
ui->setupUi(this);
setBasicImageParent(this);
setSaveTitle("Formula Depth Image");
setFolderSettings("depthmaps");
}
FormulaGen::~FormulaGen()
{
delete ui;
}
int FormulaGen::getOutputImageWidth()
{
return ui->widthSpin->value();
}
int FormulaGen::getOutputImageHeight()
{
return ui->heightSpin->value();
}
void FormulaGen::on_generatePb_clicked()
{
int w=getOutputImageWidth();
int h=getOutputImageHeight();
QByteArray formula_ba=ui->formulaPText->toPlainText().toLatin1();
const char* formula_buf=formula_ba.constData();
imdata=QImage(w,h,QImage::Format_RGB32);
float x_s, y_s;
symbol_table_t symbol_table;
symbol_table.add_pi();
symbol_table.add_constant("e", M_E);
symbol_table.add_variable("x", x_s);
symbol_table.add_variable("y", y_s);
expression_t expression;
expression.register_symbol_table(symbol_table);
parser_t::settings_store sstore;
sstore.disable_all_logic_ops();
sstore.disable_all_assignment_ops();
sstore.disable_all_control_structures();
parser_t parser(sstore);
bool compile_valid=parser.compile(formula_buf, expression);
bool ok;
int val;
for (int x=0;x<w;++x)
{
for (int y=0;y<h;++y)
{
x_s = (float)x/w;
y_s = (float)y/h;
val=expression.value()*255.99;
if (std::isnan(val) || std::isinf(val) || val<0)
val=0;
else if (val>255)
val=255;
imdata.setPixel(x,y,0xff000000|(val<<16)|(val<<8)|val);
}
}
//imdata=imdata.convertToFormat(QImage::Format_Indexed8,StereoMaker::getGrayScale());
ui->imageViewArea->setPixmap(QPixmap::fromImage(imdata));
}
void FormulaGen::on_actionSave_Image_triggered()
{
saveAsImage();
}
void FormulaGen::on_actionPush_Image_triggered()
{
((MainWindow*)parentWidget())->setDepthImage(imdata);
}
void FormulaGen::on_actionPush_Image_as_Compose_Pattern_triggered()
{
((MainWindow*)parentWidget())->setComposePattern(imdata);
}