MRaster examples 22.0.0.0
Image Processing Library
Loading...
Searching...
No Matches
simone_attractor.cpp
Go to the documentation of this file.
1// -*- Mode:C++; Coding:us-ascii-unix; fill-column:158 -*-
2/*******************************************************************************************************************************************************.H.S.**/
3/**
4 @file simone_attractor.cpp
5 @author Mitch Richling <https://www.mitchr.me>
6 @brief Draw fractals inspired by the book Symmetry in Chaos.@EOL
7 @std C++20
8 @see https://www.mitchr.me/SS/sic/index.html
9 @copyright
10 @parblock
11 Copyright (c) 1988-2015, Mitchell Jay Richling <https://www.mitchr.me> All rights reserved.
12
13 Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
14
15 1. Redistributions of source code must retain the above copyright notice, this list of conditions, and the following disclaimer.
16
17 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions, and the following disclaimer in the documentation
18 and/or other materials provided with the distribution.
19
20 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
21 without specific prior written permission.
22
23 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
25 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26 OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 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
28 DAMAGE.
29 @endparblock
30 @filedetails
31
32 I came across the Simone Attractor on Paul Bourke's web site (http://www.paulbourke.net/fractals/simone_orbits/). Apparently it's based on, or inspired by,
33 work done by Simone Conradi; however, the web page provides no references. The governing iteration is as follows:
34
35 @f[ \begin{eqnarray}
36 x_{n+1} & = & \sin(x^2_n - y^2_n+a) \\
37 y_{n+1} & = & \cos(2 x_n y_n+b) \\
38 \end{eqnarray} @f]
39
40*/
41/*******************************************************************************************************************************************************.H.E.**/
42/** @cond exj */
43
44//--------------------------------------------------------------------------------------------------------------------------------------------------------------
45#include "ramCanvas.hpp"
46#include "MRMathSTR.hpp"
47
48//--------------------------------------------------------------------------------------------------------------------------------------------------------------
49std::vector<std::array<mjr::ramCanvas1c16b::coordFltType, 5>> params {
50 /* a b maxitr */
51 { 0.432882, -1.570796, 10000000}, // 00
52 { 0.536566, 1.570796, 10000000}, // 01
53 { 0.690363, 0.995086, 10000000}, // 02
54 { 0.517835, 1.680190, 10000000}, // 03
55 { 0.565480, 1.062950, 10000000}, // 04
56 { 0.546562, 1.135860, 10000000}, // 05
57 { 0.456968, 1.837620, 10000000}, // 06
58 { 0.484075, 1.234150, 10000000}, // 07
59 { 0.491253, 1.127530, 10000000}, // 08
60 { 0.443006, 1.747070, 10000000}, // 09
61 { 0.490425, 1.223740, 10000000}, // 10
62 { 0.464411, 1.909230, 10000000}, // 11
63 { 0.486090, 1.139340, 10000000}, // 12
64 { 0.448678, 1.075730, 10000000}, // 13
65 { 0.465456, 1.154130, 10000000}, // 14
66 { 0.375753, 1.877880, 10000000}, // 15
67 { 0.351747, 1.345850, 10000000}, // 16
68 { 0.375383, 1.495300, 10000000}, // 17
69 { 0.378139, 1.323700, 10000000}, // 18
70 { 0.407792, 1.786880, 10000000}, // 19
71 { 0.381058, 1.749780, 10000000}, // 20
72 { 0.422341, 1.361320, 10000000}, // 21
73 { 0.720252, -1.100380, 10000000}, // 22
74 { 0.382110, -1.012590, 10000000}, // 23
75 { 0.404479, -1.626160, 10000000}, // 24
76 { 0.442941, -1.453160, 10000000}, // 25
77 { 0.458452, -1.380980, 10000000}, // 26
78 { 0.064952, -0.775113, 10000000}, // 27
79 { -0.068023, -0.802403, 10000000}, // 28
80 { 0.254331, -0.762604, 10000000}, // 29
81 { -0.223881, -0.714717, 10000000}, // 30
82 { -0.537199, -0.809482, 10000000}, // 31
83 { -0.528728, -0.864537, 10000000}, // 32
84 { -0.783708, -1.135120, 10000000}, // 33
85 { -0.629771, -0.964981, 10000000}, // 34
86 { -0.557026, -0.844882, 10000000}, // 35
87 { -0.501792, -0.675246, 10000000}, // 36
88 { 0.032832, -0.709609, 10000000}, // 37
89 { 0.519031, -1.436470, 10000000}, // 38
90 { 0.037161, 1.936070, 10000000}, // 39
91};
92
93//--------------------------------------------------------------------------------------------------------------------------------------------------------------
94int main(void) {
95 std::chrono::time_point<std::chrono::system_clock> startTime = std::chrono::system_clock::now();
96 const int BSIZ = 7680/1;
97
98# pragma omp parallel for schedule(static,1)
99 for(decltype(params.size()) j=0; j<params.size(); ++j) {
100 mjr::ramCanvas1c16b theRamCanvas(BSIZ, BSIZ, -1.0, 1.0, -1.0, 1.0);
101 decltype(theRamCanvas)::coordFltType a = params[j][0];
102 decltype(theRamCanvas)::coordFltType b = params[j][1];
103 uint64_t maxitr = static_cast<uint64_t>(params[j][2]);
104
105 decltype(theRamCanvas)::coordFltType xn = 0;
106 decltype(theRamCanvas)::coordFltType yn = 0;
107 for(uint64_t i=0;i<maxitr;i++) {
108 decltype(theRamCanvas)::coordFltType tmp = std::sin(xn*xn-yn*yn+a);
109 yn = std::cos(2*xn*yn+b);
110 xn = tmp;
111 if(i>1000) {
112 decltype(theRamCanvas)::coordIntType ix = theRamCanvas.real2intX(xn);
113 decltype(theRamCanvas)::coordIntType iy = theRamCanvas.real2intY(yn);
114 if (theRamCanvas.isOnCanvas(ix, iy))
115 theRamCanvas.getPxColorRefNC(ix, iy).tfrmAdd(1);
116 }
117 if((i % 10000000) == 0)
118# pragma omp critical
119 std::cout << "ITER(" << j << "): " << i << std::endl;
120 }
121 theRamCanvas.autoHistStrech();
122 theRamCanvas.applyHomoPixTfrm(&decltype(theRamCanvas)::colorType::tfrmPow, 1/4.0);
123 theRamCanvas.rotate90CW();
124 theRamCanvas.scaleDownMean(4);
125 theRamCanvas.autoHistStrech();
126# pragma omp critical
127 std::cout << "ITER(" << j << "): " << "DONE" << std::endl;
128 theRamCanvas.writeTIFFfile("simone_attractor_" + mjr::math::str::fmt_int(j, 2, '0') + ".tiff",
129 mjr::ramCanvasPixelFilter::ColorSchemeOnChan<decltype(theRamCanvas),
130 mjr::color3c8b,
131 mjr::color3c8b::csCColdeFireRamp>(theRamCanvas));
132
133 }
134 std::chrono::duration<double> runTime = std::chrono::system_clock::now() - startTime;
135 std::cout << "Total Runtime " << runTime.count() << " sec" << std::endl;
136 return 0;
137}
138/** @endcond */
int main(int argc, char *argv[])