Almond.cpp 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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. QGradient qg;
  68. GradientChooseDialog gcd;
  69. auto response = gcd.exec();
  70. }
  71. void Almond::on_exportVideo_clicked()
  72. {
  73. ExportVideoInfo evi;
  74. evi.start = mnd::MandelViewport::standardView();
  75. evi.end = mw->getViewport();
  76. evi.gradient = mw->getGradient();
  77. ExportVideoDialog dialog(this, evi);
  78. //dialog.show();
  79. auto response = dialog.exec();
  80. printf("dialog executed\n"); fflush(stdout);
  81. if (response == 1) {
  82. mnd::MandelInfo mi;
  83. evi = dialog.getExportVideoInfo();
  84. //Video
  85. /*mi.maxIter = dialog.getMaxIterations();
  86. mi.view = mw->getViewport();
  87. mi.bWidth = dialog.getWidth();
  88. mi.bHeight = dialog.getHeight();
  89. mi.view.adjustAspectRatio(mi.bWidth, mi.bHeight);
  90. mnd::Generator& g = mandelContext.getDefaultGenerator();
  91. auto fmap = Bitmap<float>(mi.bWidth, mi.bHeight);
  92. g.generate(mi, fmap.pixels.get());
  93. 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) }; });
  94. QImage img((unsigned char*)bitmap.pixels.get(), bitmap.width, bitmap.height, bitmap.width * 3, QImage::Format_RGB888);
  95. img.save(dialog.getPath());*/
  96. }
  97. }