1
0

FractalWidgetUtils.cpp 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. #include "FractalWidgetUtils.h"
  2. #include "FractalZoomWidget.h"
  3. CellImage::~CellImage(void)
  4. {
  5. }
  6. ImageClip::ImageClip(std::shared_ptr<ETVImage> tex,
  7. float tx, float ty, float tw, float th) :
  8. etvImage{ std::move(tex) },
  9. tx{ tx }, ty{ ty }, tw{ tw }, th{ th }
  10. {
  11. }
  12. ImageClip::~ImageClip(void)
  13. {
  14. }
  15. void ImageClip::drawRect(float x, float y, float width, float height)
  16. {
  17. etvImage->draw(x, y, width, height, tx, ty, tw, th);
  18. }
  19. ImageClip ImageClip::clip(float x, float y, float w, float h)
  20. {
  21. float tx = this->tx + x * this->tw;
  22. float ty = this->ty + y * this->th;
  23. float tw = this->tw * w;
  24. float th = this->th * h;
  25. return ImageClip{ this->etvImage, tx, ty, tw, th };
  26. }
  27. std::shared_ptr<CellImage> ImageClip::clip(short i, short j)
  28. {
  29. return std::make_shared<ImageClip>(clip(i * 0.5f, j * 0.5f, 0.5f, 0.5f));
  30. }
  31. int ImageClip::getRecalcPriority() const
  32. {
  33. return int(1.0f / tw);
  34. }
  35. QuadImage::QuadImage(std::shared_ptr<CellImage> i00,
  36. std::shared_ptr<CellImage> i01,
  37. std::shared_ptr<CellImage> i10,
  38. std::shared_ptr<CellImage> i11) :
  39. cells{ { std::move(i00), std::move(i01) },
  40. { std::move(i10), std::move(i11) } }
  41. {
  42. }
  43. QuadImage::~QuadImage(void)
  44. {
  45. }
  46. void QuadImage::drawRect(float x, float y, float width, float height)
  47. {
  48. for (int i = 0; i < 2; i++) {
  49. for (int j = 0; j < 2; j++) {
  50. this->cells[i][j]->drawRect(x + i * 0.5f * width,
  51. y + j * 0.5f * height,
  52. width * 0.5f,
  53. height * 0.5f);
  54. }
  55. }
  56. }
  57. std::shared_ptr<CellImage> QuadImage::clip(short i, short j)
  58. {
  59. return cells[i][j];
  60. }
  61. int QuadImage::getRecalcPriority() const
  62. {
  63. return 1;
  64. }
  65. void CalcJob::run(void)
  66. {
  67. auto [absX, absY] = grid->getPositions(i, j);
  68. mnd::Real gw = grid->dpp * FractalZoomWidget::chunkSize;
  69. Bitmap<float> f{ FractalZoomWidget::chunkSize, FractalZoomWidget::chunkSize };
  70. mnd::MandelInfo mi = owner.getMandelInfo();
  71. mi.view.x = absX;
  72. mi.view.y = absY;
  73. mi.view.width = mi.view.height = gw;
  74. mi.bWidth = mi.bHeight = FractalZoomWidget::chunkSize;
  75. try {
  76. generator->generate(mi, f.pixels.get());
  77. emit done(new Bitmap<float>(std::move(f)));
  78. }
  79. catch(std::exception& ex) {
  80. emit failed(ex.what());
  81. }
  82. catch(...) {
  83. emit failed(tr("unknown error"));
  84. }
  85. }
  86. size_t IndexPairHash::operator()(const std::pair<GridIndex, GridIndex>& p) const
  87. {
  88. const auto& [a, b] = p;
  89. size_t truncA = static_cast<size_t>(a);
  90. size_t truncB = static_cast<size_t>(b);
  91. boost::hash_combine(truncA, truncB);
  92. return truncA;
  93. }
  94. size_t IndexTripleHash::operator()(const std::tuple<int, GridIndex, GridIndex>& p) const
  95. {
  96. const auto& [i, a, b] = p;
  97. size_t truncA = static_cast<size_t>(a);
  98. size_t truncB = static_cast<size_t>(b);
  99. boost::hash_combine(truncA, truncB);
  100. boost::hash_combine(truncA, i);
  101. return truncA;
  102. }