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