Almond.cpp 3.8 KB

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