MRaster examples 21.0.0.0
Image Processing Library
Loading...
Searching...
No Matches
mandelbrot_orbits.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_orbits.cpp
5 @author Mitch Richling <https://www.mitchr.me>
6 @brief Mandelbrot orbits.@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 Explores the orbits of the iteration
32
33 * mandelbrot_orbits_out_h.tiff Point histogram of exterior point orbits
34 * mandelbrot_orbits_in_h.tiff Point histogram of interior point orbits
35 * mandelbrot_orbits_m.tiff The mandelbrot set
36 * mandelbrot_orbits_in_c.tiff Where interior points converged
37
38*/
39/*******************************************************************************************************************************************************.H.E.**/
40/** @cond exj */
41
42//--------------------------------------------------------------------------------------------------------------------------------------------------------------
43#include "ramCanvas.hpp"
44
45//--------------------------------------------------------------------------------------------------------------------------------------------------------------
46/** Reasons iteration may stop */
47enum class whyStopMO { OUTSET, //!< Not in set (|z|>2)
48 MAXCOUNT //!< Maximum iteration reached
49 };
50
51//--------------------------------------------------------------------------------------------------------------------------------------------------------------
52int main(void) {
53 std::chrono::time_point<std::chrono::system_clock> startTime = std::chrono::system_clock::now();
54 const int CSIZE = 1080*2;
55 const int SCALE = 4;
56 const int MAXITR = 2048;
57 mjr::ramCanvas1c16b inhRamCanvas (CSIZE*SCALE, CSIZE*SCALE, -2.0, 1.0, -1.5, 1.5);
58 mjr::ramCanvas1c16b incRamCanvas (CSIZE*SCALE, CSIZE*SCALE, -2.0, 1.0, -1.5, 1.5);
59 mjr::ramCanvas1c16b outhRamCanvas(CSIZE*SCALE, CSIZE*SCALE, -2.0, 1.0, -1.5, 1.5);
60 mjr::ramCanvas1c8b mRamCanvas (CSIZE*SCALE, CSIZE*SCALE, -2.0, 1.0, -1.5, 1.5);
61 std::complex<double>* theOrbit = new std::complex<double>[MAXITR+1];
62
63 for(int y=0;y<inhRamCanvas.getNumPixY();y++) {
64 if((y%((CSIZE*SCALE)/10))==0)
65 std::cout << "LINE: " << y << "/" << (CSIZE*SCALE) << std::endl;
66 for(int x=0;x<inhRamCanvas.getNumPixX();x++) {
67 //std::cout << x << " " << y << std::endl;
68 whyStopMO why;
69 std::complex<double> z;
70 int count;
71 double cr = inhRamCanvas.int2realX(x);
72 double ci = inhRamCanvas.int2realY(y);
73 std::complex<double> c(cr, ci);
74 z=c;
75 for(count=0; ; count++) {
76 z = z * z + c;
77 theOrbit[count] = z;
78 if(count>=(MAXITR-1)) {
79 why = whyStopMO::MAXCOUNT;
80 break;
81 }
82 if(std::abs(z)>2.0) {
83 why = whyStopMO::OUTSET;
84 break;
85 }
86 }
87
88 if(why == whyStopMO::MAXCOUNT) {
89 mRamCanvas.drawPoint(x, y, "white");
90 incRamCanvas.drawPoint(std::real(z), std::imag(z), "white");
91 }
92 for(int i=0; i<(count-1); i++) {
93 int cri = inhRamCanvas.real2intX(std::real(theOrbit[i]));
94 int cii = inhRamCanvas.real2intY(std::imag(theOrbit[i]));
95 if( !(inhRamCanvas.isCliped(cri, cii))) {
96 if(why == whyStopMO::OUTSET) {
97 outhRamCanvas.getPxColorRefNC(cri, cii).tfrmAdd(1);
98 } else {
99 inhRamCanvas.getPxColorRefNC(cri, cii).tfrmAdd(1);
100 }
101 }
102 }
103 }
104 }
105 outhRamCanvas.scaleDownMean(SCALE);
106 outhRamCanvas.autoHistStrech();
107 outhRamCanvas.writeTIFFfile("mandelbrot_orbits_out_h.tiff");
108 inhRamCanvas.scaleDownMean(SCALE);
109 inhRamCanvas.autoHistStrech();
110 inhRamCanvas.writeTIFFfile("mandelbrot_orbits_in_h.tiff");
111 mRamCanvas.scaleDownMax(SCALE);
112 mRamCanvas.writeTIFFfile("mandelbrot_orbits_m.tiff");
113 incRamCanvas.scaleDownMax(SCALE);
114 incRamCanvas.writeTIFFfile("mandelbrot_orbits_in_c.tiff");
115 std::chrono::duration<double> runTime = std::chrono::system_clock::now() - startTime;
116 std::cout << "Total Runtime " << runTime.count() << " sec" << std::endl;
117}
118/** @endcond */
int main(int argc, char *argv[])