MRaster examples 22.0.0.0
Image Processing Library
Loading...
Searching...
No Matches
3da_frac_lorenz.cpp
Go to the documentation of this file.
1// -*- Mode:C++; Coding:us-ascii-unix; fill-column:158 -*-
2/*******************************************************************************************************************************************************.H.S.**/
3/**
4 @file 3da_frac_lorenz.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 @filedetails
30
31 This code generates a fractal-like image from the Lorenz system. The image represents a rectangle in @f$\mathbb{R}^3@f$ parallel to the @f$x@f$-@f$z@f$
32 plane, and hitting the @f$y@f$ axis at @f$1.51@f$. We start the IVP problem with initial conditions in this rectangle. The color represents the time
33 required for the @f$x@f$ value to change sign.
34
35 For reference the Lorenz system is defined by:
36 @f[ \begin{array}{lcl}
37 \frac{dx}{dt} & = & a(y-x) \\
38 \frac{dy}{dt} & = & x(b-z)-y \\
39 \frac{dz}{dt} & = & xy-cz
40 \end{array} @f]
41
42 Traditional parameter values are:
43
44 @f[ \begin{array}{lcc}
45 a & = & 10 \\
46 b & = & 28 \\
47 c & = & \frac{8}{3}
48 \end{array} @f]
49
50*/
51/*******************************************************************************************************************************************************.H.E.**/
52/** @cond exj */
53
54//--------------------------------------------------------------------------------------------------------------------------------------------------------------
55#include <functional> /* STL funcs C++98 */
56
57#include "ramCanvas.hpp"
58#include "MRMathSFUN.hpp"
59#include "MRMathODE.hpp"
60
61typedef mjr::ramCanvas1c16b drc_t;
62typedef mjr::color3c8b oc_t;
63typedef mjr::ramCanvasPixelFilter::FuncHomoTransform<drc_t, oc_t> hpf_t;
64
65//--------------------------------------------------------------------------------------------------------------------------------------------------------------
66std::array<drc_t::coordFltType, 3> eq(std::array<drc_t::coordFltType, 3> const& p) {
67 const drc_t::coordFltType a = 10.0;
68 const drc_t::coordFltType b = 28.0;
69 const drc_t::coordFltType c = 8.0 / 3;
70 return {a * (p[1] - p[0]),
71 p[0] * (b - p[2]) - p[1],
72 p[0] * p[1] - c * p[2]};
73}
74
75//--------------------------------------------------------------------------------------------------------------------------------------------------------------
76int main(void) {
77 std::chrono::time_point<std::chrono::system_clock> startTime = std::chrono::system_clock::now();
78 const int XSIZ = 7680/1;
79 const int YSIZ = 4320/1;
80
81 drc_t theRamCanvas(XSIZ, YSIZ, -200, 200, 10, 40);
82
83 const drc_t::colorChanType maxPtsPerCurve = drc_t::colorType::maxChanVal;
84 const drc_t::coordFltType tDelta = 0.01;
85
86# pragma omp parallel for schedule(static,1)
87 for(drc_t::coordIntType yi=0;yi<theRamCanvas.getNumPixY();yi++) {
88 std::cout << "Line: " << yi << std::endl;
89 for(drc_t::coordIntType xi=0;xi<theRamCanvas.getNumPixX();xi++) {
90 std::array<drc_t::coordFltType, 3> p {theRamCanvas.int2realX(xi), 1.51, theRamCanvas.int2realY(yi) };
91 int s = mjr::math::sfun::sgn(p[0]);
92 for(drc_t::colorChanType i=0;i<maxPtsPerCurve;i++) {
93 std::array<drc_t::coordFltType, 3> p_new = mjr::math::vec::sum(p, mjr::math::ode::rk4<drc_t::coordFltType, 3>(p, eq, tDelta));
94 if (mjr::math::sfun::sgn(p[0]) != s) {
95 theRamCanvas.drawPoint(xi, yi, i*10);
96 break;
97 }
98 p = p_new;
99 }
100 }
101 }
102 theRamCanvas.writeRAWfile("3da_frac_lorenz.mrw");
103
104 /* Write with color map */
105 theRamCanvas.writeTIFFfile("3da_frac_lorenz.tiff", hpf_t(theRamCanvas,[](auto inColor) { return oc_t::csCCfractal0RYBCW::c(inColor.getC0()); }));
106
107 std::chrono::duration<double> runTime = std::chrono::system_clock::now() - startTime;
108 std::cout << "Total Runtime " << runTime.count() << " sec" << std::endl;
109 return 0;
110}
111/** @endcond */
112
int main(int argc, char *argv[])