MRaster examples 22.0.0.0
Image Processing Library
Loading...
Searching...
No Matches
peterdejongM.cpp
Go to the documentation of this file.
1// -*- Mode:C++; Coding:us-ascii-unix; fill-column:158 -*-
2/*******************************************************************************************************************************************************.H.S.**/
3/**
4 @file peterdejongM.cpp
5 @author Mitch Richling <https://www.mitchr.me>
6 @brief Draw a Peter de Jong Attractor Movie.@EOL
7 @std C++20
8 @see https://www.mitchr.me/SS/swirl/index.html
9 @copyright
10 @parblock
11 Copyright (c) 1988-2015, Mitchell Jay Richling <https://www.mitchr.me> All rights reserved.
12
13 Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
14
15 1. Redistributions of source code must retain the above copyright notice, this list of conditions, and the following disclaimer.
16
17 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions, and the following disclaimer in the documentation
18 and/or other materials provided with the distribution.
19
20 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
21 without specific prior written permission.
22
23 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
25 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26 OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 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
28 DAMAGE.
29 @endparblock
30 @filedetails
31
32 Moves the parameters around a simple closed curve in @f$\mathbb{R}^8@f$. Make a GIF like this:
33
34 time convert -delay 1 -loop 0 -dispose previous peterdejongM_???.tiff peterdejongM.gif
35*/
36/*******************************************************************************************************************************************************.H.E.**/
37/** @cond exj */
38
39//--------------------------------------------------------------------------------------------------------------------------------------------------------------
40#include "ramCanvas.hpp"
41#include "MRMathSTR.hpp"
42
43//--------------------------------------------------------------------------------------------------------------------------------------------------------------
44int main(void) {
45 std::chrono::time_point<std::chrono::system_clock> startTime = std::chrono::system_clock::now();
46
47 const int imageSize = 540; // 4320 2160 1080 540 270
48 const unsigned long int maxIters = 300000000ul;
49 const unsigned long int itersTick = 10000000ul;
50 const int numFrames = 24*8; // 512 128 32 16
51 const double a = 1.50503;
52 const double b = -1.44118;
53 const double c = -1.23281;
54 const double d = 1.78607;
55 const double e = 1.709360;
56 const double f = 1.794210;
57 const double g = 1.893750;
58 const double h = -1.38227;
59 const double p = 2.10;
60
61 mjr::ramCanvas1c16b::colorType aColor;
62 aColor.setChans(1);
63
64# pragma omp parallel for schedule(static,1)
65 for(int frame=0; frame<numFrames; frame++) {
66 mjr::ramCanvas1c16b theRamCanvas(imageSize, imageSize, -2, 2, -2, 2);
67 /* Draw the atractor on a 16-bit, greyscale canvas -- the grey level will be an integer represeting the hit count for that pixel. */
68 double x = 1.0;
69 double y = 1.0;
70 mjr::ramCanvas1c16b::colorChanArithSPType maxII = 0;
71 for(mjr::ramCanvas1c16b::colorChanArithSPType i=0;i<maxIters;i++) {
72 double da = 0.07 * cos(frame * 2 * std::numbers::pi / numFrames);
73 double dc = 0.04 * sin(frame * 2 * std::numbers::pi / numFrames);
74 double db = 0.05 * cos(frame * 2 * std::numbers::pi / numFrames);
75 double dd = 0.13 * sin(frame * 2 * std::numbers::pi / numFrames);
76 double de = 0.18 * sin(frame * 2 * std::numbers::pi / numFrames);
77 double dg = 0.05 * cos(frame * 2 * std::numbers::pi / numFrames);
78 double df = 0.09 * sin(frame * 2 * std::numbers::pi / numFrames);
79 double dh = 0.12 * cos(frame * 2 * std::numbers::pi / numFrames);
80 double xNew = sin((a + da)*y + e + de) - cos((b+db)*x + f + df);
81 double yNew = sin((c + dc)*x + g + dg) - cos((d+dd)*y + h + dh);
82 theRamCanvas.drawPoint(x, y, theRamCanvas.getPxColor(x, y).tfrmAdd(aColor));
83 if(theRamCanvas.getPxColor(x, y).getC0() > maxII) {
84 maxII = theRamCanvas.getPxColor(x, y).getC0();
85 if(maxII > 16384) { // 1/4 of max possible intensity
86 std::cout << "FRAME(" << frame << "): " << i << " MAXS: " << maxII << " EXIT: Maximum image intensity reached" << std::endl;
87 break;
88 }
89 }
90 if((i % itersTick) == 0)
91 std::cout << "FRAME(" << frame << "): " << i << " MAXS: " << maxII << std::endl;
92 x=xNew;
93 y=yNew;
94 }
95
96 // Dump a raw image
97 theRamCanvas.writeTIFFfile("peterdejongM_" + mjr::math::str::fmt_int(frame, 3, '0') + ".mrw");
98
99 // Root image transform
100 theRamCanvas.applyHomoPixTfrm(&mjr::ramCanvas1c16b::colorType::tfrmStdPow, 1.0/p);
101 maxII = static_cast<mjr::ramCanvas1c16b::colorChanArithSPType>(65535.0 * pow(static_cast<double>(maxII)/65535.0, 1.0/p));
102
103 /* 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
104 that we could pass a conversion routine to writeTIFFfile (see sic.cpp for an example of how to do just that). */
105 mjr::ramCanvas3c8b anotherRamCanvas(imageSize, imageSize);
106 mjr::ramCanvas3c8b::colorType bColor;
107 for(int yi=0;yi<theRamCanvas.getNumPixY();yi++)
108 for(int xi=0;xi<theRamCanvas.getNumPixX();xi++)
109 anotherRamCanvas.drawPoint(xi, yi, bColor.cmpRGBcornerDGradiant(static_cast<mjr::ramCanvas3c8b::csIntType>(theRamCanvas.getPxColor(xi, yi).getC0() * 1275 / maxII), "0RYBCW"));
110 anotherRamCanvas.writeTIFFfile("peterdejongM_" + mjr::math::str::fmt_int(frame, 3, '0') + ".tiff");
111
112 }
113 std::chrono::duration<double> runTime = std::chrono::system_clock::now() - startTime;
114 std::cout << "Total Runtime " << runTime.count() << " sec" << std::endl;
115 return 0;
116}
117
118
119// mkdir rawpng
120// mkdir mrw
121// mv peter*.mrw mrw
122// for f in mrw/*.mrw(:r:t); do echo $f; if [ ! -e rawpng/$f.png ] ; then convert -depth 16 -size 540x540+100 gray:mrw/$f.mrw -quality 90 rawpng/$f.png; fi; done
123/** @endcond */
int main(int argc, char *argv[])