MRaster examples 22.0.0.0
Image Processing Library
Loading...
Searching...
No Matches
peterdejong.cpp
Go to the documentation of this file.
1// -*- Mode:C++; Coding:us-ascii-unix; fill-column:158 -*-
2/*******************************************************************************************************************************************************.H.S.**/
3/**
4 @file peterdejong.cpp
5 @author Mitch Richling <https://www.mitchr.me>
6 @brief Draw a Peter de Jong Attractor.@EOL
7 @std C++20
8 @see https://www.mitchr.me/SS/swirl/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*/
31/*******************************************************************************************************************************************************.H.E.**/
32/** @cond exj */
33
34//--------------------------------------------------------------------------------------------------------------------------------------------------------------
35#include "ramCanvas.hpp"
36#include "MRMathSTR.hpp"
37
38//--------------------------------------------------------------------------------------------------------------------------------------------------------------
39std::vector<std::array<double, 9>> params {
40 /* a b c d e f g h p */
41 { -1.68661, -1.99168, 1.71743, -1.64958, 0.299086, -1.293460, -0.054505, -1.73135, 2.00}, // 0 128822725
42 { 1.50503, -1.44118, -1.23281, 1.78607, 1.709360, 1.794210, 1.893750, -1.38227, 2.10}, // 1 101379662
43 { 1.81390, 1.30705, -1.94400, -1.48629, 0.242144, 0.075625, -0.480636, -0.18518, 1.75}, // 2 139794084
44 { -1.93281, 1.23020, -1.95848, -1.34156, -0.357486, -0.541028, 0.627957, -1.06337, 2.00}, // 3 118791871
45 { 1.96082, -1.85272, -1.86495, -1.58137, -0.545130, -1.883680, -0.839783, -1.95953, 2.00}, // 4 102197049
46 { 1.89361, -1.81593, -1.28357, 1.75597, -1.109410, -1.820460, -0.068557, 1.12429, 2.00}, // 5 107124786
47 { -1.76096, -1.68857, -1.33290, 1.98759, -1.104940, 1.947970, -1.414330, 1.31909, 2.00}, // 6 85670760
48 { -1.80149, -1.95335, 1.89633, 1.41626, -1.047470, 0.446659, -0.148925, -1.66114, 1.75}, // 7 224359045
49 { -1.76161, 1.60748, 1.85472, -1.99701, -0.700920, 0.280207, 0.202521, -1.49941, 1.75}, // 8 168582830
50 { -1.88084, -1.93071, 1.85293, 1.87725, -1.941150, -0.449833, 1.273380, 1.73451, 1.75}, // 9 230803868
51 { 1.81220, -1.66034, -1.77919, 1.81528, -1.256080, -1.517980, -1.055310, 1.76863, 1.75}, // 10 170641984
52 { -1.90207, -1.56841, -1.59079, -1.71636, -1.586460, 1.792950, -1.161890, -1.14366, 1.50}, // 11 255341851
53 { 1.79278, -1.85710, 1.79287, 1.80201, -1.984930, 1.783520, 1.413990, -1.64555, 2.00}, // 12 82935309
54 { -1.76690, 1.99947, -1.90106, -1.77759, 0.643333, 1.904950, -1.890230, 0.46540, 2.00}, // 13 56604946
55 { -1.91813, -1.79012, -1.62624, 1.90787, 0.571077, 1.646480, 1.357700, 0.12230, 1.75}, // 14 215417412
56 { -1.92361, 1.79491, -1.95131, -1.64915, -1.204090, -1.681380, 1.620420, 1.86234, 1.75}, // 15 252292873
57 { 1.67219, -1.66621, -1.82146, 1.89902, -0.842709, 1.419750, 0.696557, -0.81644, 1.75}, // 16 111744614
58 { -2.20000, -1.97000, 2.20200, -2.30000, 0.000000, 0.000000, 0.000000, 0.00000, 1.75}
59};
60
61//--------------------------------------------------------------------------------------------------------------------------------------------------------------
62int main(void) {
63 std::chrono::time_point<std::chrono::system_clock> startTime = std::chrono::system_clock::now();
64 const int BSIZ = 7680/4;
65 for(decltype(params.size()) j=0; j<params.size(); ++j) {
66 mjr::ramCanvas1c16b theRamCanvas(BSIZ, BSIZ, -2, 2, -2, 2);
67
68 double a = params[j][0];
69 double b = params[j][1];
70 double c = params[j][2];
71 double d = params[j][3];
72 double e = params[j][4];
73 double f = params[j][5];
74 double g = params[j][6];
75 double h = params[j][7];
76 double p = params[j][8];
77
78 /* Draw the atractor on a 16-bit, greyscale canvas -- the grey level will be an integer represeting the hit count for that pixel. This is a good example
79 of how an image can have pixel values that are generic "data" as well as color information. */
80 double x = 1.0;
81 double y = 1.0;
82 uint64_t maxII = 0;
83 for(uint64_t i=0;i<10000000000ul;i++) {
84 double xNew = std::sin(a*y + e) - std::cos(b*x + f);
85 double yNew = std::sin(c*x + g) - std::cos(d*y + h);
86 theRamCanvas.incPxChan(x, y);
87 if(theRamCanvas.getPxColor(x, y).getC0() > maxII) {
88 maxII = theRamCanvas.getPxColor(x, y).getC0();
89 if(maxII > 16384) { // 1/4 of max possible intensity
90 std::cout << "ITER(" << j << "): " << i << " MAXS: " << maxII << " EXIT: Maximum image intensity reached" << std::endl;
91 break;
92 }
93 }
94 if((i % 10000000) == 0)
95 std::cout << "ITER(" << j << "): " << i << " MAXS: " << maxII << std::endl;
96 x=xNew;
97 y=yNew;
98 }
99
100 theRamCanvas.writeRAWfile("peterdejong_" + mjr::math::str::fmt_int(j, 2, '0') + ".mrw");
101
102 // Root image transform
103 theRamCanvas.applyHomoPixTfrm(&mjr::ramCanvas1c16b::colorType::tfrmStdPow, 1.0/p);
104 maxII = static_cast<uint64_t>(65535.0 * pow(static_cast<double>(maxII)/65535.0, 1/p));
105
106 // Log image transform
107 // theRamCanvas.applyHomoPixTfrm(&mjr::ramCanvas1c16b::colorType::tfrmLn);
108 // maxII = log(maxII);
109
110 /* Create a new image based on an integer color scale -- this one is 24-bit RGB color. This isn't the most efficient technique from a RAM perspective in
111 that we could pass a conversion routine to writeTIFFfile (see sic.cpp for an example of how to do just that). */
112 mjr::ramCanvas3c8b anotherRamCanvas(BSIZ, BSIZ);
113 mjr::ramCanvas3c8b::colorType bColor;
114 for(int yi=0;yi<theRamCanvas.getNumPixY();yi++)
115 for(int xi=0;xi<theRamCanvas.getNumPixX();xi++)
116 anotherRamCanvas.drawPoint(xi, yi, bColor.cmpRGBcornerDGradiant(static_cast<mjr::ramCanvas3c8b::csIntType>(theRamCanvas.getPxColor(xi, yi).getC0() * 1275 / maxII), "0RYBCW"));
117
118 anotherRamCanvas.writeTIFFfile("peterdejong_" + mjr::math::str::fmt_int(j, 2, '0') + ".tiff");
119 }
120 std::chrono::duration<double> runTime = std::chrono::system_clock::now() - startTime;
121 std::cout << "Total Runtime " << runTime.count() << " sec" << std::endl;
122 return 0;
123}
124/** @endcond */
int main(int argc, char *argv[])