MRaster examples 22.0.0.0
Image Processing Library
Loading...
Searching...
No Matches
lorenz_fuz.cpp
Go to the documentation of this file.
1// -*- Mode:C++; Coding:us-ascii-unix; fill-column:158 -*-
2/*******************************************************************************************************************************************************.H.S.**/
3/**
4 @file lorenz_fuz.cpp
5 @author Mitch Richling <https://www.mitchr.me>
6 @brief Draw a Lorenz Attractor histogram.@EOL
7 @std C++20
8 @copyright
9 @parblock
10 Copyright (c) 1988-2015, Mitchell Jay Richling <https://www.mitchr.me> All rights reserved.
11
12 Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
13
14 1. Redistributions of source code must retain the above copyright notice, this list of conditions, and the following disclaimer.
15
16 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions, and the following disclaimer in the documentation
17 and/or other materials provided with the distribution.
18
19 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
20 without specific prior written permission.
21
22 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
24 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25 OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26 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
27 DAMAGE.
28 @endparblock
29*/
30/*******************************************************************************************************************************************************.H.E.**/
31/** @cond exj */
32
33//--------------------------------------------------------------------------------------------------------------------------------------------------------------
34#include "ramCanvas.hpp"
35
36//--------------------------------------------------------------------------------------------------------------------------------------------------------------
37int main(void) {
38 std::chrono::time_point<std::chrono::system_clock> startTime = std::chrono::system_clock::now();
39 double p = 1.75;
40 const int XSIZ = 7680/1;
41 const int YSIZ = 4320/1;
42 uint64_t maxII = 0;
43 mjr::ramCanvas1c16b theRamCanvas(XSIZ, YSIZ, -19, 19, 3, 47);
44
45 double distToGo = 80000.0; /* How long should the curve be? */
46
47 double idealJumpDist = 0.12; /* Size of the spheres to use */
48
49 double maxMovDelta = idealJumpDist / 2.0; /* The maximum delta for the function. */
50 double minMovDelta = idealJumpDist / 6.0; /* The minimum delta for the function. */
51
52
53 double minTdelta = 0.000001; /* Minimum value for tDelta */
54 double maxTdelta = 0.01; /* Maximum value for tDelta */
55 double tDeltaZeroThresh = 0.00000001; /* Episolon ball for zero. */
56 double maxNumBisect = 10; /* Max bisections on tDelta. */
57
58 /* Initial conditions, and constants. */
59 double a = 10;
60 double b = 28;
61 double c = 8.0 / 3;
62
63 double curMaxTdelta, curMinTdelta, tDelta, dist, Xdelta, Ydelta, Zdelta, movDelta;
64 int numBisect, doneBisecting;
65
66 for(int i=0; i<10; i++) {
67 double x = 0.0;
68 double y = i - 5.2;
69 double z = 25;
70
71 std::cout << "y: " << y << std::endl;
72
73 /* Solve the equations..... */
74 tDelta = maxTdelta;
75 dist = 0.0;
76 while (dist < distToGo) {
77 /* Take a big step up to minimize the number of balls. */
78 tDelta = (maxTdelta + tDelta) / 2;
79 if (tDelta > maxTdelta) {
80 tDelta = maxTdelta;
81 }
82 curMaxTdelta = maxTdelta;
83 curMinTdelta = minTdelta;
84 /* Bisect t delta until we have done it too much or until we have a good value for t delta. */
85 numBisect = 0;
86 doneBisecting = 0;
87 while (!(doneBisecting)) {
88 numBisect++;
89 Xdelta = a * (y - x) * tDelta;
90 Ydelta = (x * (b - z) - y) * tDelta;
91 Zdelta = (x * y - c * z) * tDelta;
92 movDelta = sqrt (fabs (Xdelta * Xdelta + Ydelta * Ydelta + Zdelta * Zdelta));
93 if (numBisect > maxNumBisect) {
94 doneBisecting = 1;
95 } else {
96 if (movDelta > maxMovDelta) {
97 if (fabs (tDelta - curMinTdelta) < tDeltaZeroThresh) {
98 doneBisecting = 1;
99 } else {
100 curMaxTdelta = tDelta;
101 tDelta = (tDelta + curMinTdelta) / 2;
102 if (tDelta < minTdelta) {
103 tDelta = minTdelta;
104 }
105 }
106 } else if (movDelta < minMovDelta) {
107 if (fabs (tDelta - curMaxTdelta) < tDeltaZeroThresh) {
108 doneBisecting = 1;
109 } else {
110 curMinTdelta = tDelta;
111 tDelta = (curMaxTdelta + tDelta) / 2;
112 if (tDelta > maxTdelta) {
113 tDelta = maxTdelta;
114 }
115 }
116 } else {
117 doneBisecting = 1;
118 }
119 }
120 }
121 dist += movDelta;
122 x = x + Xdelta;
123 y = y + Ydelta;
124 z = z + Zdelta;
125 theRamCanvas.incPxChan(x, z);
126
127 if(theRamCanvas.getPxColor(x, z).getC0() > maxII)
128 maxII = theRamCanvas.getPxColor(x, z).getC0();
129 }
130 }
131
132 theRamCanvas.writeRAWfile("lorenz_fuz.mrw");
133
134 // Root image transform
135 theRamCanvas.applyHomoPixTfrm(&mjr::ramCanvas1c16b::colorType::tfrmStdPow, 1.0 / p);
136 maxII = static_cast<uint64_t>(65535.0 * std::pow(static_cast<double>(maxII) / 65535.0, 1.0 / p));
137
138 // Log image transform
139 // theRamCanvas.applyHomoPixTfrm(&mjr::ramCanvas1c16b::colorType::tfrmLn);
140 // maxII = log(maxII);
141
142 /* 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
143 that we could pass a conversion routine to writeTIFFfile (see sic.cpp for an example of how to do just that). */
144 mjr::ramCanvas3c8b anotherRamCanvas(XSIZ, YSIZ);
145 mjr::ramCanvas3c8b::colorType bColor;
146 for(int yi=0;yi<theRamCanvas.getNumPixY();yi++)
147 for(int xi=0;xi<theRamCanvas.getNumPixX();xi++) {
148 anotherRamCanvas.drawPoint(xi, yi, bColor.cmpRGBcornerDGradiant(static_cast<mjr::ramCanvas3c8b::csIntType>(theRamCanvas.getPxColor(xi, yi).getC0() * 1275 / maxII), "0RYBCW"));
149 if( (anotherRamCanvas.getPxColor(xi, yi).getC0() > 0) && (anotherRamCanvas.getPxColor(xi, yi).getC0() < 255) )
150 anotherRamCanvas.getPxColorRefNC(xi, yi).setC0(255);
151 }
152
153 anotherRamCanvas.writeTIFFfile("lorenz_fuz.tiff");
154
155 std::chrono::duration<double> runTime = std::chrono::system_clock::now() - startTime;
156 std::cout << "Total Runtime " << runTime.count() << " sec" << std::endl;
157
158 return 0;
159}
160/** @endcond */
int main(int argc, char *argv[])