MRaster examples 21.0.0.0
Image Processing Library
Loading...
Searching...
No Matches
mandelbrot_bm_cplx_hyper.cpp
Go to the documentation of this file.
1// -*- Mode:C++; Coding:us-ascii-unix; fill-column:158 -*-
2/*******************************************************************************************************************************************************.H.S.**/
3/**
4 @file mandelbrot_bm_cplx_hyper.cpp
5 @author Mitch Richling <https://www.mitchr.me>
6 @brief Benchmark drawing a mandelbrot set using the C++ complex type and excluding hypocycloids.@EOL
7 @std C++20
8 @copyright
9 @parblock
10 Copyright (c) 1988-2015, Mitchell Jay Richling <https://www.mitchr.me> All rights reserved.
11
12 Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
13
14 1. Redistributions of source code must retain the above copyright notice, this list of conditions, and the following disclaimer.
15
16 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions, and the following disclaimer in the documentation
17 and/or other materials provided with the distribution.
18
19 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software
20 without specific prior written permission.
21
22 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
24 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25 OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26 LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
27 DAMAGE.
28 @endparblock
29 @filedetails
30
31 Basic benchmark. Uses complex numbers. Has several algorithmic optimizations.
32
33 Depending upon what region is being drawn, the distribution of points satisfying the various optimization conditions will change. Each optimization has a
34 cost in execution, and if that cost is higher than the benefits on the region then it should be avoided -- this is especially true with CYCORLIM. For this
35 reason the set of boolean variables determining what optimizations to use should be tuned for the region. In addition, CYCORLIM cost is dominated by
36 LASTMAX. For large, zoomed out images this optimization breaks even at about LASTMAX=4. For zoomed in images with a significant space covered by a period
37 N bulb, setting LASTMAX to something larger than N can provide a significant speedup.
38
39 | doBOUND | doPERIOD1 | doPERIOD2 | doREFLCT | doCYCORLIM | LASTMAX | Speed Up |
40 |---------+-----------+-----------+----------+------------+---------+----------|
41 | true | - | - | - | - | - | N/A |
42 | true | true | - | - | - | - | 3.0x |
43 | true | true | true | - | - | - | 4.6x |
44 | true | true | true | true | - | - | 5.6x |
45 | true | true | true | true | true | 4 | 5.8x |
46
47 Note doREFLCT should be implemented differently for cases where symmetry is known in advance. In these cases we can simply avoid iterating over
48 the symmetric points at all instead of testing to see if we are on a symmetric point.
49*/
50/*******************************************************************************************************************************************************.H.E.**/
51/** @cond exj */
52
53//--------------------------------------------------------------------------------------------------------------------------------------------------------------
54#include "ramCanvas.hpp"
55
56//--------------------------------------------------------------------------------------------------------------------------------------------------------------
57int main(void) {
58 std::chrono::time_point<std::chrono::system_clock> startTime = std::chrono::system_clock::now();
59 const int NUMITR = 1024;
60 const int CSIZE = 7680;
61 const int LASTMAX = 4;
62 mjr::ramCanvas3c8b theRamCanvas(CSIZE, CSIZE, -2.2, 0.8, -1.5, 1.5);
63 theRamCanvas.clrCanvasToBlack();
64
65 long int countPERIOD1 = 0;
66 long int countPERIOD2 = 0;
67 long int countMAXCOUNT = 0;
68 long int countBOUND = 0;
69 long int countCYCORLIM = 0;
70 long int countREFLCT = 0;
71
72 bool doPERIOD1 = true;
73 bool doPERIOD2 = true;
74 bool doBOUND = true;
75 bool doCYCORLIM = true;
76 bool doREFLCT = true;
77
78 bool doStatusPrint = false;
79
80 std::vector<std::complex<double>> lastZs(LASTMAX);
81 for(int y=0;y<theRamCanvas.getNumPixY();y++) {
82 for(int x=0;x<theRamCanvas.getNumPixX();x++) {
83 int count;
84 double cr = theRamCanvas.int2realX(x);
85 double ci = theRamCanvas.int2realY(y);
86 std::complex<double> c(cr, ci), z(0, 0);
87 double p = std::abs(c-0.25);
88 if(doPERIOD1 && (cr <= p-2.0*p*p+0.25)) {
89 theRamCanvas.drawPoint(x, y, "blue");
90 countPERIOD1++;
91 } else {
92 if(doPERIOD2 && (std::abs(c+1.0) <= 0.25)) {
93 theRamCanvas.drawPoint(x, y, "green");
94 countPERIOD2++;
95 } else {
96 if(doREFLCT && (!(theRamCanvas.getPxColor(std::conj(c)).isBlack()))) {
97 //theRamCanvas.drawPoint(x, y, "magenta");
98 theRamCanvas.drawPoint(x, y, theRamCanvas.getPxColor(std::conj(c)));
99 countREFLCT++;
100 } else {
101 for(count=0; ; count++) {
102 z = z * z + c;
103
104 if(count>=NUMITR) {
105 theRamCanvas.drawPoint(x, y, "white");
106 countMAXCOUNT++;
107 break;
108 }
109 if(doBOUND && (std::norm(z)>4.0)) {
110 //theRamCanvas.drawPoint(x, y, "red");
111 theRamCanvas.drawPoint(x, y, mjr::ramCanvas3c8b::colorType(static_cast<mjr::ramCanvas3c8b::colorChanType>((5*count+50)%256), 0, 0));
112 countBOUND++;
113 break;
114 }
115 if(doCYCORLIM && (count>LASTMAX) && std::any_of(lastZs.begin(), lastZs.end(), [&z](std::complex<double> zl){return std::abs(zl-z)<0.0001;}) ) {
116 theRamCanvas.drawPoint(x, y, "yellow");
117 //theRamCanvas.drawPoint(x, y, mjr::ramCanvas3c8b::colorType((5*count+50)%256, (count+50)%256, 0));
118 countCYCORLIM++;
119 break;
120 }
121 lastZs[count%LASTMAX] = z;
122 }
123 }
124 }
125 }
126 }
127
128 if( doStatusPrint && (((y%(CSIZE/32))==0) || (y==(CSIZE-1))) ) {
129 std::cout << "LINE: " << y << "/" << CSIZE << std::endl;
130 std::cout << " countPERIOD1: " << countPERIOD1 << std::endl;
131 std::cout << " countPERIOD2: " << countPERIOD2 << std::endl;
132 std::cout << " countMAXCOUNT: " << countMAXCOUNT << std::endl;
133 std::cout << " countBOUND: " << countBOUND << std::endl;
134 std::cout << " countCYCORLIM: " << countCYCORLIM << std::endl;
135 std::cout << " countREFLCT: " << countREFLCT << std::endl;
136 }
137 }
138 theRamCanvas.writeTIFFfile("mandelbrot_bm_cplx_hyper.tiff");
139 std::chrono::duration<double> runTime = std::chrono::system_clock::now() - startTime;
140 std::cout << "Total Runtime " << runTime.count() << " sec" << std::endl;
141}
142/** @endcond */
int main(int argc, char *argv[])