MRaster examples 22.0.0.0
Image Processing Library
Loading...
Searching...
No Matches
3da_frac_langford.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_langford.cpp
5 @author Mitch Richling <https://www.mitchr.me>
6 @brief Draw langford 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 Langford attractor. The image represents a rectangle inthe @f$x@f$-@f$z@f$ axis plane of
32 @f$\mathbb{R}^3@f$. We start the IVP problem with initial conditions in this rectangle. The color represents the time required for the solution point to
33 enter a sphere of radius @f$\frac{1}{2}@f$ centered at @f$(0, 0, \frac{3}{4})@f$. This sphere intersects the central "stalk" in the Langford attractor, and
34 the time to hit this sphere is a proxy for the time required for the solution to be "captured by" or "on" the attractor.
35
36 For reference the Langford system is defined by:
37 @f[ \begin{array}{lcl}
38 \frac{dx}{dt} & = & (z - \beta) x - \omega y \\
39 \frac{dy}{dt} & = & \omega x + (z - \beta) y \\
40 \frac{dz}{dt} & = & \lambda + \alpha z - \frac{1}{3}z^3 - (x^2 + y^2) (1 + \rho z) + \epsilon z x^3
41 \end{array} @f]
42
43 Traditional parameter values are:
44
45 @f[ \begin{array}{lcc}
46 \alpha & = & \frac{19}{20} \\
47 \beta & = & \frac{7}{10} \\
48 \lambda & = & \frac{3}{5} \\
49 \omega & = & \frac{7}{2} \\
50 \rho & = & \frac{1}{4} \\
51 \epsilon & = & \frac{1}{10}
52 \end{array} @f]
53
54 We use Euler's method to solve the equations with a @f$\Delta{t}@f$ of 0.001 and a maximum of @f$65536 = 2^{16}@f$ iterations.
55*/
56/*******************************************************************************************************************************************************.H.E.**/
57/** @cond exj */
58
59//--------------------------------------------------------------------------------------------------------------------------------------------------------------
60#include <valarray>
61#include "ramCanvas.hpp"
62#include "MRMathODE.hpp"
63
64typedef mjr::ramCanvas1c16b drc_t;
65typedef mjr::color3c8b oc_t;
66typedef mjr::ramCanvasPixelFilter::FuncHomoTransform<drc_t, oc_t> hpf_t;
67
68//--------------------------------------------------------------------------------------------------------------------------------------------------------------
69std::array<drc_t::coordFltType, 3> eq(std::array<drc_t::coordFltType, 3> const& p) {
70 const drc_t::coordFltType alpha = 0.95;
71 const drc_t::coordFltType beta = 0.7;
72 const drc_t::coordFltType lambda = 0.6;
73 const drc_t::coordFltType omega = 3.5;
74 const drc_t::coordFltType rho = 0.25;
75 const drc_t::coordFltType epsilon = 0.1;
76 return { (p[2] - beta) * p[0] - omega * p[1],
77 omega * p[0] + (p[2] - beta) * p[1],
78 lambda + alpha * p[2] - (p[2]*p[2]*p[2] / 3) - (p[0]*p[0] + p[1]*p[1]) * (1 + rho * p[2]) + epsilon * p[2] * p[0]*p[0]*p[0] };
79}
80
81//--------------------------------------------------------------------------------------------------------------------------------------------------------------
82int main(void) {
83 std::chrono::time_point<std::chrono::system_clock> startTime = std::chrono::system_clock::now();
84 const int XSIZ = 7680/1;
85 const int YSIZ = 7680/1;
86
87 drc_t theRamCanvas(XSIZ, YSIZ, -1.6, 1.6, -0.5, 3);
88
89 const drc_t::colorChanType maxPtsPerCurve = drc_t::colorType::maxChanVal;
90 const drc_t::coordFltType tDelta = 0.005;
91 const drc_t::coordFltType zOff = 0.75;
92 const drc_t::coordFltType inRad = 0.50;
93
94# pragma omp parallel for schedule(static,1)
95 for(drc_t::coordIntType yi=0;yi<theRamCanvas.getNumPixY();yi++) {
96 std::cout << "Line: " << yi << std::endl;
97 for(drc_t::coordIntType xi=0;xi<theRamCanvas.getNumPixX();xi++) {
98 std::array<drc_t::coordFltType, 3> p {theRamCanvas.int2realX(xi), 0.0, theRamCanvas.int2realY(yi)};
99 for(drc_t::colorChanType i=0;i<maxPtsPerCurve;i++) {
100 std::array<drc_t::coordFltType, 3> p_new = mjr::math::vec::sum(p, mjr::math::ode::rk1<drc_t::coordFltType, 3>(p, eq, tDelta));
101 if (mjr::math::vec::dist2sqr(p_new, {0.0, 0.0, zOff}) < inRad*inRad) {
102 theRamCanvas.drawPoint(xi, yi, i);
103 break;
104 }
105 p = p_new;
106 }
107 }
108 }
109 theRamCanvas.writeRAWfile("3da_frac_langford.mrw");
110
111 /* Transform image and write result with color map */
112 theRamCanvas.autoHistStrech();
113 theRamCanvas.writeTIFFfile("3da_frac_langford.tiff", hpf_t(theRamCanvas,[](auto inColor) { return oc_t::csCCfractal0RYBCW::c(inColor.getC0()); }));
114
115 std::chrono::duration<double> runTime = std::chrono::system_clock::now() - startTime;
116 std::cout << "Total Runtime " << runTime.count() << " sec" << std::endl;
117 return 0;
118}
119/** @endcond */
120
int main(int argc, char *argv[])