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