MRaster examples 22.0.0.0
Image Processing Library
Loading...
Searching...
No Matches
sic.cpp
Go to the documentation of this file.
1// -*- Mode:C++; Coding:us-ascii-unix; fill-column:158 -*-
2/*******************************************************************************************************************************************************.H.S.**/
3/**
4 @file sic.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 Fractals inspired by the book "Symmetry in Chaos" by Michael Field and Martin Golubitsky.
33
34*/
35/*******************************************************************************************************************************************************.H.E.**/
36/** @cond exj */
37
38//--------------------------------------------------------------------------------------------------------------------------------------------------------------
39#include "ramCanvas.hpp"
40#include "MRMathSTR.hpp"
41
42//--------------------------------------------------------------------------------------------------------------------------------------------------------------
43typedef mjr::ramCanvas3c8b rct;
44typedef rct::colorType ct;
45
46//--------------------------------------------------------------------------------------------------------------------------------------------------------------
47std::vector<std::array<mjr::ramCanvas1c16b::coordFltType, 12>> params {
48 /* lambda alpha beta gamma omega n ipw xmin xmax ymin ymax 1=mean */
49 { 1.375390, -0.4212800, 0.26969, 0.08352, 0.338347, 6, 15.00, -1.30, 1.30, -1.30, 1.30, 1.0}, // 0 |
50 { 1.600230, -1.1340800, -0.17506, 0.67872, 0.049490, 6, 14.00, 0.10, 0.70, 0.43, 0.90, 0.0}, // 1 | WACKY
51 { 1.000890, -0.7678100, 1.89425, -1.13943, -0.688827, 7, 10.00, -0.90, 0.90, -0.90, 0.90, 0.0}, // 2 |
52 {-1.563400, 1.7238200, 0.74440, 0.71874, 0.258907, 3, 8.00, -0.75, 0.75, -0.75, 0.75, 1.0}, // 3 |
53 { 1.361000, -1.8225400, -0.92635, -1.74108, -0.761120, 5, 2.00, -0.70, 0.70, -0.70, 0.70, 1.0}, // 4 |
54 { 1.609310, -1.6924900, 0.85055, 0.26523, -0.716769, 5, 4.00, -0.90, 0.90, -0.90, 0.90, 0.0}, // 5 |
55 { 1.464900, -1.8825700, -1.47205, -0.83559, -0.701477, 4, 3.00, -0.80, 0.80, -0.80, 0.80, 1.0}, // 6 |
56 { 1.622110, -1.0694500, -0.11181, 0.62253, 0.784032, 4, 2.00, -1.20, 1.20, -1.20, 1.20, 1.0}, // 7 |
57 {-1.380150, 0.7472100, 1.17094, 0.05782, -0.574188, 6, 10.00, -1.00, 1.00, -1.00, 1.00, 0.0}, // 8 |
58 { 0.335010, -1.3467500, -0.65137, -0.87848, -1.231490, 5, 10.00, -1.20, 1.20, -1.20, 1.20, 1.0}, // 9 |
59 {-1.496290, 1.8701600, -1.93938, -0.88084, -0.139602, 3, 10.00, -0.55, 0.55, -0.55, 0.55, 1.0}, // 10 |
60 {-1.248610, 1.0816100, -0.50731, 0.97272, -0.853955, 11, 10.00, -1.00, 1.00, -1.00, 1.00, 0.0}, // 11 |
61 {-1.991900, 1.8219100, -0.38273, 0.68143, 0.493416, 11, 10.00, -1.00, 1.00, -1.00, 1.00, 0.0}, // 12 |
62 { 1.694170, -1.2730200, 0.75035, -1.28615, 0.561096, 6, 2.50, -1.10, 1.10, -1.10, 1.10, 1.0}, // 13 |
63 {-0.386753, -0.0610025, -1.02847, 0.78619, -0.984828, 3, 5.00, -1.20, 1.20, -1.20, 1.20, 0.0}, // 14 | special
64 { 0.982876, -1.1125600, 0.500411, -1.44111, -1.008560, 4, 7.00, -0.80, 0.80, -0.80, 0.80, 0.0}, // 15 | special
65 {-1.257170, 0.0390811, 0.13892, -0.87058, 0.023977, 7, 2.60, -1.20, 1.20, -1.20, 1.20, 1.0}, // 16 | Neat
66 { 1.008500, 0.2275230, -0.56604, -0.62146, 0.693161, 5, 3.00, -1.20, 1.20, -1.20, 1.20, 1.0}, // 17 |
67 { 1.618250, -1.6035300, 1.13920, -1.60120, -0.761638, 5, 2.80, -1.00, 1.00, -1.00, 1.00, 0.0}, // 18 |
68 {-0.960670, 0.0834029, 1.01438, 1.05748, -0.599590, 21, 2.60, -1.20, 1.20, -1.20, 1.20, 1.0}, // 19 |
69 { 0.908230, 0.3047990, 1.03560, 0.29872, -0.473521, 7, 3.00, -1.20, 1.20, -1.20, 1.20, 0.0}, // 20 |
70 { 1.873130, -1.2822600, -1.28938, -1.36355, -0.141951, 21, 2.00, -1.10, 1.10, -1.10, 1.10, 1.0}, // 21 | NICE
71 { 1.536250, -0.6547000, -1.43255, -0.24270, 0.128769, 31, 2.50, -1.00, 1.00, -1.00, 1.00, 0.0}, // 22 | NICE
72 {-2.080000, 1.0000000, -0.10000, 0.16700, 0.000000, 7, 4.00, -1.20, 1.20, -1.20, 1.20, 0.0}, // 23 | d7 SIC BOOK
73 {-2.500000, 5.0000000, -1.90000, 1.00000, 0.180000, 5, 2.75, -0.75, 0.75, -0.75, 0.75, 0.0}, // 24 | Z5 SIC BOOK
74 { 2.500000, -2.5000000, 0.00000, 0.90000, 0.000000, 3, 2.75, -1.40, 1.40, -1.40, 1.40, 0.0}, // 25 | D3 SIC BOOK
75 { 2.600000, -2.0000000, 0.00000, -0.50000, 0.000000, 5, 4.75, -1.30, 1.30, -1.30, 1.30, 1.0}, // 26 | D5 SIC BOOK
76};
77
78//--------------------------------------------------------------------------------------------------------------------------------------------------------------
79// This is *identical* to what we did in pickoverPopcorn.cpp -- just way shorter. It is longer still because we don't make
80// this a subclass of ramCanvasTpl::rcConverterHomoBase in order to illustrate how to implement a RC converter from scratch.
81// Also note we didn't need to DIY the color gradient with cmpRGBcornerDGradiant() as this gradient (0RYBCW) is available as
82// a pre-built color scheme: csCCfractal0RYBCW.
83class g2rgb8 {
84 private:
85 mjr::ramCanvas1c16b& attachedRC;
86 int factor;
87 public:
88 g2rgb8(mjr::ramCanvas1c16b& aRC, uint64_t newFactor) : attachedRC(aRC), factor(static_cast<int>(newFactor)) { }
89 inline bool isIntAxOrientationNaturalX() { return attachedRC.isIntAxOrientationNaturalX(); }
90 inline bool isIntAxOrientationNaturalY() { return attachedRC.isIntAxOrientationNaturalY(); }
91 inline mjr::ramCanvas1c16b::coordIntType getNumPixX() { return attachedRC.getNumPixX(); }
92 inline mjr::ramCanvas1c16b::coordIntType getNumPixY() { return attachedRC.getNumPixY(); }
93 typedef mjr::colorRGB8b colorType;
94 inline colorType getPxColorNC(rct::coordIntType x, rct::coordIntType y) {
95 colorType retColor;
96 rct::csIntType tmp = static_cast<rct::csIntType>(attachedRC.getPxColorNC(x, y).getC0() * 1275 / factor);
97 return retColor.cmpRGBcornerDGradiant(tmp, "0RYBCW");
98 }
99};
100
101//--------------------------------------------------------------------------------------------------------------------------------------------------------------
102int main(void) {
103 std::chrono::time_point<std::chrono::system_clock> startTime = std::chrono::system_clock::now();
104 const int BSIZ = 7680/4;
105 mjr::ramCanvas1c16b::colorType aColor;
106 aColor.setChans(1);
107 for(decltype(params.size()) j=0; j<params.size(); ++j) {
108 mjr::ramCanvas1c16b theRamCanvas(BSIZ, BSIZ, params[j][7], params[j][8], params[j][9], params[j][10]);
109 typename mjr::ramCanvas1c16b::coordFltType lambda = params[j][0];
110 typename mjr::ramCanvas1c16b::coordFltType alpha = params[j][1];
111 typename mjr::ramCanvas1c16b::coordFltType beta = params[j][2];
112 typename mjr::ramCanvas1c16b::coordFltType gamma = params[j][3];
113 typename mjr::ramCanvas1c16b::coordFltType w = params[j][4];
114 double ipw = static_cast<double>(params[j][6]);
115 int n = static_cast<int>( params[j][5]);
116 int filter = static_cast<int>( params[j][11]);
117
118 std::complex<typename mjr::ramCanvas1c16b::coordFltType> cplxi (0,1);
119
120 uint64_t maxitr = 10000000000ul;
121
122 std::complex<typename mjr::ramCanvas1c16b::coordFltType> z(.01,.01);
123 uint64_t maxII = 0;
124 for(uint64_t i=0;i<maxitr;i++) {
125 z = (lambda + alpha*z*std::conj(z)+beta*std::pow(z, n).real() + w*cplxi)*z+gamma*std::pow(std::conj(z), n-1);
126 typename mjr::ramCanvas1c16b::coordFltType x=z.real(), y=z.imag();
127 if(i>1000)
128 theRamCanvas.drawPoint(x, y, theRamCanvas.getPxColor(x, y).tfrmAdd(aColor));
129 if(theRamCanvas.getPxColor(x, y).getC0() > maxII) {
130 maxII = theRamCanvas.getPxColor(x, y).getC0();
131 if(maxII > 16384) { // 1/4 of max possible intensity
132 std::cout << "ITER(" << j << "): " << i << " MAXS: " << maxII << " EXIT: Maximum image intensity reached" << std::endl;
133 break;
134 }
135 }
136 if((i % 10000000) == 0)
137 std::cout << "ITER(" << j << "): " << i << " MAXS: " << maxII << std::endl;
138 }
139
140 std::cout << "ITER(" << j << "): " << "Big TIFF" << std::endl;
141 theRamCanvas.writeTIFFfile("sic_" + mjr::math::str::fmt_int(j, 2, '0') + ".tiff");
142
143 // Root image transform
144 std::cout << "ITER(" << j << "): " << "TFRM & SCALE" << std::endl;
145 theRamCanvas.autoHistStrech();
146 //theRamCanvas.applyHomoPixTfrm(&mjr::ramCanvas1c16b::colorType::tfrmLn);
147 theRamCanvas.applyHomoPixTfrm(&mjr::ramCanvas1c16b::colorType::tfrmStdPow, 1/ipw);
148 if(filter)
149 theRamCanvas.scaleDownMean(4);
150 else
151 theRamCanvas.scaleDownMax(4);
152 theRamCanvas.autoHistStrech();
153
154 // Compte new image max intensity
155 std::cout << "ITER(" << j << "): " << "MAX" << std::endl;
156 maxII = 0;
157 for(auto& pixel : theRamCanvas)
158 if(pixel.getC0() > maxII)
159 maxII = pixel.getC0();
160
161 std::cout << "ITER(" << j << "): " << "TIFF" << std::endl;
162 /* Dump the 16-bit grayscale TIFF */
163 theRamCanvas.writeTIFFfile("sicM_" + mjr::math::str::fmt_int(j, 2, '0') + ".tiff");
164 /* Now we would like a false color version (24-bit RGB). We could create a new canvas like this:
165 rct cRamCanvas(theRamCanvas.getNumPixX(), theRamCanvas.getNumPixY());
166 for(mjr::ramCanvas1c16b::coordIntType y=0;y<theRamCanvas.getNumPixY();y++)
167 for(mjr::ramCanvas1c16b::coordIntType x=0;x<theRamCanvas.getNumPixX();x++) {
168 auto ci = static_cast<rct::csIntType>(theRamCanvas.getPxColorRefNC(x, y).getC0() * 1275 / maxII)
169 cRamCanvas.getPxColorRefNC(x, y).cmpRGBcornerDGradiant(ci, "0RYBCW");
170 }
171 cRamCanvas.writeTIFFfile("sicC_" + mjr::math::str::fmt_int(j, 2, '0') + ".tiff");
172 We have a better way. One that dosen't require the RAM to create a brand new canvas. We can use
173 the filter option of writeTIFFfile! */
174 g2rgb8 rcFilt(theRamCanvas, maxII);
175 theRamCanvas.writeTIFFfile("sicCC_" + mjr::math::str::fmt_int(j, 2, '0') + ".tiff", rcFilt, false);
176 }
177 std::chrono::duration<double> runTime = std::chrono::system_clock::now() - startTime;
178 std::cout << "Total Runtime " << runTime.count() << " sec" << std::endl;
179 return 0;
180}
181/** @endcond */
int main(int argc, char *argv[])