1
0

Almond.cpp 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  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_pushButton_clicked()
  24. {
  25. ExportImageDialog dialog(this);
  26. //dialog.show();
  27. auto response = dialog.exec();
  28. if (response == 1) {
  29. mnd::MandelInfo mi;
  30. mi.maxIter = dialog.getMaxIterations();
  31. mi.view = mw->getViewport();
  32. mi.bWidth = dialog.getWidth();
  33. mi.bHeight = dialog.getHeight();
  34. mi.view.adjustAspectRatio(mi.bWidth, mi.bHeight);
  35. mnd::Generator& g = mandelContext.getCpuGeneratorFloat();
  36. auto fmap = Bitmap<float>(mi.bWidth, mi.bHeight);
  37. g.generate(mi, fmap.pixels.get());
  38. auto bitmap = fmap.map<RGBColor>([&mi, this] (float i) {
  39. return i >= mi.maxIter ? RGBColor{ 0,0,0 } : mw->getGradient().get(i);
  40. });
  41. QImage img((unsigned char*) bitmap.pixels.get(), bitmap.width, bitmap.height, bitmap.width * 3, QImage::Format_RGB888);
  42. img.save(dialog.getPath());
  43. }
  44. }
  45. void Almond::on_pushButton_2_clicked()
  46. {
  47. BenchmarkDialog bd(mandelContext, this);
  48. //bd.show();
  49. bd.exec();
  50. }
  51. void Almond::on_zoom_out_clicked()
  52. {
  53. mw->zoom(2);
  54. }
  55. void Almond::on_zoom_in_clicked()
  56. {
  57. mw->zoom(0.5);
  58. }
  59. void Almond::on_maxIterations_editingFinished()
  60. {
  61. QString text = ui.maxIterations->text();
  62. int maxIter = text.toInt();
  63. mw->setMaxIterations(maxIter);
  64. }
  65. void Almond::on_chooseGradient_clicked()
  66. {
  67. auto response = gcd.exec();
  68. auto gradient = gcd.getGradient();
  69. if (gradient)
  70. mw->setGradient(std::move(*gradient));
  71. }
  72. void Almond::on_exportVideo_clicked()
  73. {
  74. ExportVideoInfo evi;
  75. evi.start = mnd::MandelViewport::standardView();
  76. evi.end = mw->getViewport();
  77. evi.gradient = mw->getGradient();
  78. ExportVideoDialog dialog(this, evi);
  79. //dialog.show();
  80. auto response = dialog.exec();
  81. printf("dialog executed\n"); fflush(stdout);
  82. if (response == 1) {
  83. mnd::MandelInfo mi;
  84. evi = dialog.getExportVideoInfo();
  85. //Video
  86. /*mi.maxIter = dialog.getMaxIterations();
  87. mi.view = mw->getViewport();
  88. mi.bWidth = dialog.getWidth();
  89. mi.bHeight = dialog.getHeight();
  90. mi.view.adjustAspectRatio(mi.bWidth, mi.bHeight);
  91. mnd::Generator& g = mandelContext.getDefaultGenerator();
  92. auto fmap = Bitmap<float>(mi.bWidth, mi.bHeight);
  93. g.generate(mi, fmap.pixels.get());
  94. 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) }; });
  95. QImage img((unsigned char*)bitmap.pixels.get(), bitmap.width, bitmap.height, bitmap.width * 3, QImage::Format_RGB888);
  96. img.save(dialog.getPath());*/
  97. }
  98. }