44#include "ramCanvas.hpp"
46enum class pixelStateEnum {UNKNOWN,
58 std::chrono::time_point<std::chrono::system_clock> startTime = std::chrono::system_clock::now();
59 constexpr int IMXSIZ = 7680;
60 constexpr int IMYSIZ = 7680;
61 constexpr double DISTTH = 0.0002;
62 constexpr int MAXITR2 = 2048;
63 constexpr double MAXZSQ2 = 10000.0;
64 constexpr int MAXITR1 = 2048;
65 constexpr double MAXZSQ1 = 4.0;
66 constexpr double ZROEPS = 1.0e-5;
67 mjr::ramCanvas3c8b theRamCanvas(IMXSIZ, IMYSIZ, -1.9, 0.5, -1.2, 1.2);
69# pragma omp parallel for schedule(static,1)
70 for(
int y=0; y<theRamCanvas.getNumPixY(); y++) {
71 for(
int x=0; x<theRamCanvas.getNumPixX(); x++) {
72 pixelStateEnum pixelState = pixelStateEnum::UNKNOWN;
73 std::complex<double> c = theRamCanvas.int2real(x, y);
74 double p = std::abs(c-0.25);
75 if(std::abs(c+1.0) < 0.25) {
76 pixelState = pixelStateEnum::P2BULB;
77 }
else if(std::real(c) < p-2.0*p*p+0.25) {
78 pixelState = pixelStateEnum::P1BULB;
80 std::complex<double> der(0, 0), z(0, 0);
83 while(pixelState == pixelStateEnum::UNKNOWN) {
84 der = 2.0 * z * der + 1.0;
86 if (std::norm(z) > MAXZSQ1) {
87 pixelState = pixelStateEnum::ESCAPED;
88 }
else if (count > MAXITR1) {
89 pixelState = pixelStateEnum::MAXITR1;
94 while(pixelState == pixelStateEnum::ESCAPED) {
95 der = 2.0 * z * der + 1.0;
97 double absz = std::abs(z);
99 double der_mag = std::abs(der);
100 if(der_mag > ZROEPS) {
101 double dist = 2.0*std::log(absz)*absz/der_mag;
103 pixelState = pixelStateEnum::ESCAPED_BUT_CLOSE;
105 pixelState = pixelStateEnum::ESCAPED_BUT_FAR;
108 pixelState = pixelStateEnum::ESCAPED_UNKNOWN;
110 }
else if (count > MAXITR2) {
111 pixelState = pixelStateEnum::MAXITR2;
118 case pixelStateEnum::P2BULB: theRamCanvas.drawPoint(x, y,
"magenta");
break;
119 case pixelStateEnum::P1BULB: theRamCanvas.drawPoint(x, y,
"red");
break;
120 case pixelStateEnum::MAXITR1: theRamCanvas.drawPoint(x, y,
"cyan");
break;
121 case pixelStateEnum::ESCAPED_BUT_CLOSE: theRamCanvas.drawPoint(x, y,
"blue");
break;
122 case pixelStateEnum::ESCAPED_BUT_FAR: theRamCanvas.drawPoint(x, y,
"yellow");
break;
123 case pixelStateEnum::ESCAPED_UNKNOWN: theRamCanvas.drawPoint(x, y,
"white");
break;
124 case pixelStateEnum::MAXITR2: theRamCanvas.drawPoint(x, y,
"green");
break;
125 default: theRamCanvas.drawPoint(x, y,
"black");
break;
129 theRamCanvas.writeTIFFfile(
"mandelbrot_distance.tiff");
130 std::chrono::duration<double> runTime = std::chrono::system_clock::now() - startTime;
131 std::cout <<
"Total Runtime " << runTime.count() <<
" sec" << std::endl;
int main(int argc, char *argv[])