Almond.cpp 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. #include "Almond.h"
  2. #include <QIntValidator>
  3. #include <QFileDialog>
  4. #include <QMessageBox>
  5. #include <QGradient>
  6. #include "benchmarkdialog.h"
  7. #include <cmath>
  8. Almond::Almond(QWidget *parent) :
  9. QMainWindow(parent),
  10. mandelContext(mnd::initializeContext())
  11. {
  12. ui.setupUi(this);
  13. printf("not yet created!\n");
  14. mw = std::make_unique<MandelWidget>(mandelContext, ui.centralWidget);
  15. //qRegisterMetaType<MandelWidget>("MandelWidget");
  16. printf("created!\n");
  17. ui.verticalLayout_left->addWidget(mw.get());
  18. ui.maxIterations->setValidator(new QIntValidator(1, 1000000000, this));
  19. //ui.verticalLayout_left->addWidget(new MyGLWidget(ui.centralWidget));
  20. //mw->show();
  21. }
  22. void Almond::on_pushButton_clicked()
  23. {
  24. ExportImageDialog dialog(this);
  25. //dialog.show();
  26. auto response = dialog.exec();
  27. if (response == 1) {
  28. mnd::MandelInfo mi;
  29. mi.maxIter = dialog.getMaxIterations();
  30. mi.view = mw->getViewport();
  31. mi.bWidth = dialog.getWidth();
  32. mi.bHeight = dialog.getHeight();
  33. mi.view.adjustAspectRatio(mi.bWidth, mi.bHeight);
  34. mnd::Generator& g = mandelContext.getDefaultGenerator();
  35. auto fmap = Bitmap<float>(mi.bWidth, mi.bHeight);
  36. g.generate(mi, fmap.pixels.get());
  37. 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) }; });
  38. QImage img((unsigned char*)bitmap.pixels.get(), bitmap.width, bitmap.height, bitmap.width * 3, QImage::Format_RGB888);
  39. img.save(dialog.getPath());
  40. }
  41. }
  42. void Almond::on_pushButton_2_clicked()
  43. {
  44. BenchmarkDialog bd(mandelContext, this);
  45. //bd.show();
  46. bd.exec();
  47. }
  48. void Almond::on_zoom_out_clicked()
  49. {
  50. mw->zoom(2);
  51. }
  52. void Almond::on_zoom_in_clicked()
  53. {
  54. mw->zoom(0.5);
  55. }
  56. void Almond::on_maxIterations_editingFinished()
  57. {
  58. QString text = ui.maxIterations->text();
  59. int maxIter = text.toInt();
  60. mw->setMaxIterations(maxIter);
  61. }
  62. void Almond::on_chooseGradient_clicked()
  63. {
  64. QGradient qg;
  65. }
  66. void Almond::on_exportVideo_clicked()
  67. {
  68. ExportVideoInfo evi;
  69. evi.start = mnd::MandelViewport::standardView();
  70. evi.end = mw->getViewport();
  71. ExportVideoDialog dialog(this, evi);
  72. //dialog.show();
  73. auto response = dialog.exec();
  74. printf("dialog executed\n"); fflush(stdout);
  75. if (response == 1) {
  76. mnd::MandelInfo mi;
  77. evi = dialog.getExportVideoInfo();
  78. //Video
  79. /*mi.maxIter = dialog.getMaxIterations();
  80. mi.view = mw->getViewport();
  81. mi.bWidth = dialog.getWidth();
  82. mi.bHeight = dialog.getHeight();
  83. mi.view.adjustAspectRatio(mi.bWidth, mi.bHeight);
  84. mnd::Generator& g = mandelContext.getDefaultGenerator();
  85. auto fmap = Bitmap<float>(mi.bWidth, mi.bHeight);
  86. g.generate(mi, fmap.pixels.get());
  87. 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) }; });
  88. QImage img((unsigned char*)bitmap.pixels.get(), bitmap.width, bitmap.height, bitmap.width * 3, QImage::Format_RGB888);
  89. img.save(dialog.getPath());*/
  90. }
  91. }