1
0

Almond.cpp 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. #include "Almond.h"
  2. #include <QIntValidator>
  3. #include <QFileDialog>
  4. #include <QMessageBox>
  5. #include <QGradient>
  6. #include "benchmarkdialog.h"
  7. #include "gradientchoosedialog.h"
  8. #include <cmath>
  9. Almond::Almond(QWidget *parent) :
  10. QMainWindow(parent),
  11. mandelContext(mnd::initializeContext())
  12. {
  13. ui.setupUi(this);
  14. printf("not yet created!\n");
  15. mw = std::make_unique<MandelWidget>(mandelContext, ui.centralWidget);
  16. //qRegisterMetaType<MandelWidget>("MandelWidget");
  17. printf("created!\n");
  18. ui.verticalLayout_left->addWidget(mw.get());
  19. ui.maxIterations->setValidator(new QIntValidator(1, 1000000000, this));
  20. //ui.verticalLayout_left->addWidget(new MyGLWidget(ui.centralWidget));
  21. //mw->show();
  22. }
  23. void Almond::on_zoom_out_clicked()
  24. {
  25. mw->zoom(2);
  26. }
  27. void Almond::on_zoom_in_clicked()
  28. {
  29. mw->zoom(0.5);
  30. }
  31. void Almond::on_maxIterations_editingFinished()
  32. {
  33. QString text = ui.maxIterations->text();
  34. int maxIter = text.toInt();
  35. mw->setMaxIterations(maxIter);
  36. }
  37. void Almond::on_chooseGradient_clicked()
  38. {
  39. auto response = gcd.exec();
  40. auto gradient = gcd.getGradient();
  41. if (gradient)
  42. mw->setGradient(std::move(*gradient));
  43. }
  44. void Almond::on_exportVideo_clicked()
  45. {
  46. ExportVideoInfo evi;
  47. evi.start = mnd::MandelViewport::standardView();
  48. evi.end = mw->getViewport();
  49. evi.gradient = mw->getGradient();
  50. ExportVideoDialog dialog(this, evi);
  51. //dialog.show();
  52. auto response = dialog.exec();
  53. printf("dialog executed\n"); fflush(stdout);
  54. if (response == 1) {
  55. mnd::MandelInfo mi;
  56. evi = dialog.getExportVideoInfo();
  57. //Video
  58. /*mi.maxIter = dialog.getMaxIterations();
  59. mi.view = mw->getViewport();
  60. mi.bWidth = dialog.getWidth();
  61. mi.bHeight = dialog.getHeight();
  62. mi.view.adjustAspectRatio(mi.bWidth, mi.bHeight);
  63. mnd::Generator& g = mandelContext.getDefaultGenerator();
  64. auto fmap = Bitmap<float>(mi.bWidth, mi.bHeight);
  65. g.generate(mi, fmap.pixels.get());
  66. auto bitmap = fmap.map<RGBColor>([](float i) { return i < 0 ? RGBColor{ 0,0,0 } : RGBColor{ uint8_t(cos(i * 0.015f) * 127 + 127), uint8_t(sin(i * 0.01f) * 127 + 127), uint8_t(i) }; });//uint8_t(::sin(i * 0.01f) * 100 + 100), uint8_t(i) }; });
  67. QImage img((unsigned char*)bitmap.pixels.get(), bitmap.width, bitmap.height, bitmap.width * 3, QImage::Format_RGB888);
  68. img.save(dialog.getPath());*/
  69. }
  70. }
  71. void Almond::on_smooth_stateChanged(int checked)
  72. {
  73. this->mw->setSmoothColoring(checked != Qt::Unchecked);
  74. }
  75. void Almond::on_runBenchmark_clicked()
  76. {
  77. BenchmarkDialog bd(mandelContext, this);
  78. //bd.show();
  79. bd.exec();
  80. }
  81. void Almond::on_exportImage_clicked()
  82. {
  83. ExportImageDialog dialog(this);
  84. //dialog.show();
  85. auto response = dialog.exec();
  86. if (response == 1) {
  87. mnd::MandelInfo mi;
  88. mi.maxIter = dialog.getMaxIterations();
  89. mi.view = mw->getViewport();
  90. mi.bWidth = dialog.getWidth();
  91. mi.bHeight = dialog.getHeight();
  92. mi.view.adjustAspectRatio(mi.bWidth, mi.bHeight);
  93. mnd::Generator& g = mandelContext.getDefaultGenerator(this->mw->getSmoothColoring());
  94. auto fmap = Bitmap<float>(mi.bWidth, mi.bHeight);
  95. g.generate(mi, fmap.pixels.get());
  96. auto bitmap = fmap.map<RGBColor>([&mi, this] (float i) {
  97. return i >= mi.maxIter ? RGBColor{ 0,0,0 } : mw->getGradient().get(i);
  98. });
  99. QImage img((unsigned char*) bitmap.pixels.get(), bitmap.width, bitmap.height, bitmap.width * 3, QImage::Format_RGB888);
  100. img.save(dialog.getPath());
  101. }
  102. }
  103. void Almond::on_resetZoom_clicked()
  104. {
  105. mw->setViewport(mnd::MandelViewport::standardView());
  106. }