MRaster examples 21.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::colorType aColor;
44 aColor.setChans(1);
45 mjr::ramCanvas1c16b theRamCanvas(XSIZ, YSIZ, -19, 19, 3, 47);
46
47 double distToGo = 80000.0; /* How long should the curve be? */
48
49 double idealJumpDist = 0.12; /* Size of the spheres to use */
50
51 double maxMovDelta = idealJumpDist / 2.0; /* The maximum delta for the function. */
52 double minMovDelta = idealJumpDist / 6.0; /* The minimum delta for the function. */
53
54
55 double minTdelta = 0.000001; /* Minimum value for tDelta */
56 double maxTdelta = 0.01; /* Maximum value for tDelta */
57 double tDeltaZeroThresh = 0.00000001; /* Episolon ball for zero. */
58 double maxNumBisect = 10; /* Max bisections on tDelta. */
59
60 /* Initial conditions, and constants. */
61 double a = 10;
62 double b = 28;
63 double c = 8.0 / 3;
64
65 double curMaxTdelta, curMinTdelta, tDelta, dist, Xdelta, Ydelta, Zdelta, movDelta;
66 int numBisect, doneBisecting;
67
68 for(int i=0; i<10; i++) {
69 double x = 0.0;
70 double y = i - 5.2;
71 double z = 25;
72
73 std::cout << "y: " << y << std::endl;
74
75 /* Solve the equations..... */
76 tDelta = maxTdelta;
77 dist = 0.0;
78 while (dist < distToGo) {
79 /* Take a big step up to minimize the number of balls. */
80 tDelta = (maxTdelta + tDelta) / 2;
81 if (tDelta > maxTdelta) {
82 tDelta = maxTdelta;
83 }
84 curMaxTdelta = maxTdelta;
85 curMinTdelta = minTdelta;
86 /* Bisect t delta until we have done it too much or until we have a good value for t delta. */
87 numBisect = 0;
88 doneBisecting = 0;
89 while (!(doneBisecting)) {
90 numBisect++;
91 Xdelta = a * (y - x) * tDelta;
92 Ydelta = (x * (b - z) - y) * tDelta;
93 Zdelta = (x * y - c * z) * tDelta;
94 movDelta = sqrt (fabs (Xdelta * Xdelta + Ydelta * Ydelta + Zdelta * Zdelta));
95 if (numBisect > maxNumBisect) {
96 doneBisecting = 1;
97 } else {
98 if (movDelta > maxMovDelta) {
99 if (fabs (tDelta - curMinTdelta) < tDeltaZeroThresh) {
100 doneBisecting = 1;
101 } else {
102 curMaxTdelta = tDelta;
103 tDelta = (tDelta + curMinTdelta) / 2;
104 if (tDelta < minTdelta) {
105 tDelta = minTdelta;
106 }
107 }
108 } else if (movDelta < minMovDelta) {
109 if (fabs (tDelta - curMaxTdelta) < tDeltaZeroThresh) {
110 doneBisecting = 1;
111 } else {
112 curMinTdelta = tDelta;
113 tDelta = (curMaxTdelta + tDelta) / 2;
114 if (tDelta > maxTdelta) {
115 tDelta = maxTdelta;
116 }
117 }
118 } else {
119 doneBisecting = 1;
120 }
121 }
122 }
123 dist += movDelta;
124 x = x + Xdelta;
125 y = y + Ydelta;
126 z = z + Zdelta;
127 theRamCanvas.drawPoint(x, z, theRamCanvas.getPxColor(x, z).tfrmAdd(aColor));
128
129 if(theRamCanvas.getPxColor(x, z).getC0() > maxII)
130 maxII = theRamCanvas.getPxColor(x, z).getC0();
131 }
132 }
133
134 theRamCanvas.writeRAWfile("lorenz_fuz.mrw");
135
136 // Root image transform
137 theRamCanvas.applyHomoPixTfrm(&mjr::ramCanvas1c16b::colorType::tfrmStdPow, 1.0 / p);
138 maxII = static_cast<uint64_t>(65535.0 * std::pow(static_cast<double>(maxII) / 65535.0, 1.0 / p));
139
140 // Log image transform
141 // theRamCanvas.applyHomoPixTfrm(&mjr::ramCanvas1c16b::colorType::tfrmLn);
142 // maxII = log(maxII);
143
144 /* 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
145 that we could pass a conversion routine to writeTIFFfile (see sic.cpp for an example of how to do just that). */
146 mjr::ramCanvas3c8b anotherRamCanvas(XSIZ, YSIZ);
147 mjr::ramCanvas3c8b::colorType bColor;
148 for(int yi=0;yi<theRamCanvas.getNumPixY();yi++)
149 for(int xi=0;xi<theRamCanvas.getNumPixX();xi++) {
150 anotherRamCanvas.drawPoint(xi, yi, bColor.cmpRGBcornerDGradiant(static_cast<mjr::ramCanvas3c8b::csIntType>(theRamCanvas.getPxColor(xi, yi).getC0() * 1275 / maxII), "0RYBCW"));
151 if( (anotherRamCanvas.getPxColor(xi, yi).getC0() > 0) && (anotherRamCanvas.getPxColor(xi, yi).getC0() < 255) )
152 anotherRamCanvas.getPxColorRefNC(xi, yi).setC0(255);
153 }
154
155 anotherRamCanvas.writeTIFFfile("lorenz_fuz.tiff");
156
157 std::chrono::duration<double> runTime = std::chrono::system_clock::now() - startTime;
158 std::cout << "Total Runtime " << runTime.count() << " sec" << std::endl;
159
160 return 0;
161}
162/** @endcond */
int main(int argc, char *argv[])