MRaster examples 22.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,2025, 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_dist.tiff Maximum iteration count for all oribts that hit the pixel
36 * mandelbrot_orbits_color Colorized version using the above images as color channels after a power transform:
37
38 magick \‍( mandelbrot_orbits_dst_h.tiff -evaluate Pow 0.8 \‍) \‍( mandelbrot_orbits_out_h.tiff -evaluate Pow 0.6 \‍) \‍( mandelbrot_orbits_in_h.tiff -evaluate Pow 0.8 \‍) -combine combined.jpg
39*/
40/*******************************************************************************************************************************************************.H.E.**/
41/** @cond exj */
42
43//--------------------------------------------------------------------------------------------------------------------------------------------------------------
44#include "ramCanvas.hpp"
45
46typedef mjr::ramCanvas1c16b rcct;
47typedef mjr::ramCanvas3c8b rcrt;
48//typedef mjr::ramCanvas3c16b rcrt;
49//--------------------------------------------------------------------------------------------------------------------------------------------------------------
50int main(void) {
51 std::chrono::time_point<std::chrono::system_clock> startTime = std::chrono::system_clock::now();
52 const int SCALE = 8;
53 const int CSIZE = 1024*2*SCALE;
54 const int MAXITR = 256*4;
55 rcct inhRamCanvas (CSIZE, CSIZE, -2.0, 1.0, -1.5, 1.5);
56 rcct outhRamCanvas(CSIZE, CSIZE, -2.0, 1.0, -1.5, 1.5);
57 rcct distRamCanvas(CSIZE, CSIZE, -2.0, 1.0, -1.5, 1.5);
58 std::complex<double>* theOrbit = new std::complex<rcct::coordFltType>[MAXITR+1];
59
60 for(rcct::coordIntType y=0;y<inhRamCanvas.getNumPixY();y++) {
61 if((y%(inhRamCanvas.getNumPixY()/16))==0)
62 std::cout << "LINE: " << y << "/" << inhRamCanvas.getNumPixY() << std::endl;
63 for(rcct::coordIntType x=0;x<inhRamCanvas.getNumPixX();x++) {
64 std::complex<rcct::coordFltType> c(inhRamCanvas.int2realX(x), inhRamCanvas.int2realY(y));
65 std::complex<rcct::coordFltType> z(c);
66 for(rcct::colorChanType count=0; ; count++) {
67 z = z * z + c;
68 theOrbit[count] = z;
69 if(std::abs(z)>2.0) {
70 for(rcct::colorChanType i=0; i<=count; i++) {
71 outhRamCanvas.incPxChan(theOrbit[i]);
72 distRamCanvas.tformPixel(theOrbit[i], [i](auto& c) { c.tfrmMax(i); });
73 }
74 break;
75 } else if(count>=(MAXITR-1)) {
76 for(rcct::colorChanType i=0; i<=count; i++)
77 inhRamCanvas.incPxChan(theOrbit[i]);
78 break;
79 }
80 }
81 }
82 }
83
84 // Dump out our "data" images
85 distRamCanvas.scaleDownMean(SCALE);
86 distRamCanvas.autoHistStrech();
87 distRamCanvas.rotate90CW();
88 distRamCanvas.writeTIFFfile("mandelbrot_orbits_dst_h.tiff");
89 outhRamCanvas.scaleDownMean(SCALE);
90 outhRamCanvas.autoHistStrech();
91 outhRamCanvas.rotate90CW();
92 outhRamCanvas.writeTIFFfile("mandelbrot_orbits_out_h.tiff");
93 inhRamCanvas.scaleDownMean(SCALE);
94 inhRamCanvas.autoHistStrech();
95 inhRamCanvas.rotate90CW();
96 inhRamCanvas.writeTIFFfile("mandelbrot_orbits_in_h.tiff");
97
98 // Construct an 8-bit RGB image
99 rcrt theRamCanvas(distRamCanvas.getNumPixX(), distRamCanvas.getNumPixY());
100 theRamCanvas.colorizeIntCanvas([&distRamCanvas, &outhRamCanvas, &inhRamCanvas](auto x, auto y) { return rcrt::colorType(static_cast<rcrt::colorChanType>(distRamCanvas.getPxColor(x, y).tfrmPow(0.8).getChan(0)/256),
101 static_cast<rcrt::colorChanType>(outhRamCanvas.getPxColor(x, y).tfrmPow(0.6).getChan(0)/256),
102 static_cast<rcrt::colorChanType>( inhRamCanvas.getPxColor(x, y).tfrmPow(0.8).getChan(0)/256)); });
103
104 theRamCanvas.writeTIFFfile("mandelbrot_orbits_color.tiff");
105
106 std::chrono::duration<double> runTime = std::chrono::system_clock::now() - startTime;
107 std::cout << "Total Runtime " << runTime.count() << " sec" << std::endl;
108}
109/** @endcond */
int main(int argc, char *argv[])