MRaster examples 21.0.0.0
Image Processing Library
Loading...
Searching...
No Matches
lorenz_multi.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_multi.cpp
5 @author Mitch Richling <https://www.mitchr.me>
6 @brief Draw lorenz attractors with different initial conditions.@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 const int XSIZ = 7680/2;
40 const int YSIZ = 4320/2;
41 mjr::ramCanvas1c16b::colorType aColor;
42 aColor.setChans(1);
43 mjr::ramCanvas1c16b theRamCanvas(XSIZ, YSIZ, -19, 19, 3, 47);
44 double x=5.10, y=3.1, z=10.1, xNew, yNew, zNew;
45
46 std::random_device rd;
47 std::mt19937 rEng(rd());
48 std::uniform_real_distribution<double> uniform_dist_double(-15.0, 15.0);
49
50 int numCurves = 100;
51 int numPtsPerCurve = 105000;
52 int numPtsPerCurveToss = 700;
53 double tDelta = 0.00001;
54
55 double a = 10.0;
56 double b = 28.0;
57 double c = 8.0 / 3;
58
59 double p = 1.7;
60
61 /* 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
62 of how an image can have pixel values that are generic "data" as well as color information. */
63 uint64_t maxII = 0;
64 for(int j=0; j<numCurves; j++) {
65 x=0*uniform_dist_double(rEng);
66 //y=uniform_dist_double(rEng);
67 y=30.0*j/(numCurves-1)-15.0;
68 z=30+0*uniform_dist_double(rEng);
69
70 std::cout << "y: " << y << std::endl;
71
72 for(int i=0;i<numPtsPerCurve;i++) {
73 xNew = x + a * (y - x) * tDelta;
74 yNew = y + (x * (b - z) - y) * tDelta;
75 zNew = z + (x * y - c * z) * tDelta;
76 if(i>numPtsPerCurveToss) {
77 theRamCanvas.drawPoint(xNew, zNew, theRamCanvas.getPxColor(xNew, zNew).tfrmAdd(aColor));
78 if(theRamCanvas.getPxColor(xNew, zNew).getC0() > maxII) {
79 maxII = theRamCanvas.getPxColor(xNew, zNew).getC0();
80 }
81 }
82 x=xNew;
83 y=yNew;
84 z=zNew;
85 }
86 }
87 theRamCanvas.writeRAWfile("lorenz_multi.mrw");
88
89 // Root image transform
90 theRamCanvas.applyHomoPixTfrm(&mjr::ramCanvas1c16b::colorType::tfrmStdPow, 1/p);
91 maxII = static_cast<uint64_t>(65535.0 * std::pow(static_cast<double>(maxII) / 65535.0, 1.0 / p));
92
93 // Log image transform
94 // theRamCanvas.applyHomoPixTfrm(&mjr::ramCanvas1c16b::colorType::tfrmLn);
95 // maxII = log(maxII);
96
97 /* 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
98 that we could pass a conversion routine to writeTIFFfile (see sic.cpp for an example of how to do just that). */
99 mjr::ramCanvas3c8b anotherRamCanvas(XSIZ, YSIZ);
100 mjr::ramCanvas3c8b::colorType bColor;
101 for(int yi=0;yi<theRamCanvas.getNumPixY();yi++)
102 for(int xi=0;xi<theRamCanvas.getNumPixX();xi++) {
103 anotherRamCanvas.drawPoint(xi, yi, bColor.cmpRGBcornerDGradiant(static_cast<mjr::ramCanvas3c8b::csIntType>(theRamCanvas.getPxColor(xi, yi).getC0() * 1275 / maxII), "0RYBCW"));
104 if( (anotherRamCanvas.getPxColor(xi, yi).getC0() > 0) && (anotherRamCanvas.getPxColor(xi, yi).getC0() < 255/2) )
105 anotherRamCanvas.getPxColorRefNC(xi, yi).setC0(255/2);
106 }
107
108 anotherRamCanvas.writeTIFFfile("lorenz_multi.tiff");
109
110 std::chrono::duration<double> runTime = std::chrono::system_clock::now() - startTime;
111 std::cout << "Total Runtime " << runTime.count() << " sec" << std::endl;
112
113 return 0;
114}
115/** @endcond */
int main(int argc, char *argv[])