MRaster examples 21.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
42//--------------------------------------------------------------------------------------------------------------------------------------------------------------
43int main(void) {
44 std::chrono::time_point<std::chrono::system_clock> startTime = std::chrono::system_clock::now();
45
46 const int imageSize = 540; // 4320 2160 1080 540 270
47 const unsigned long int maxIters = 300000000ul;
48 const unsigned long int itersTick = 10000000ul;
49 const int numFrames = 24*8; // 512 128 32 16
50 const double a = 1.50503;
51 const double b = -1.44118;
52 const double c = -1.23281;
53 const double d = 1.78607;
54 const double e = 1.709360;
55 const double f = 1.794210;
56 const double g = 1.893750;
57 const double h = -1.38227;
58 const double p = 2.10;
59
60 mjr::ramCanvas1c16b::colorType aColor;
61 aColor.setChans(1);
62
63# pragma omp parallel for schedule(static,1)
64 for(int frame=0; frame<numFrames; frame++) {
65 mjr::ramCanvas1c16b theRamCanvas(imageSize, imageSize, -2, 2, -2, 2);
66 /* Draw the atractor on a 16-bit, greyscale canvas -- the grey level will be an integer represeting the hit count for that pixel. */
67 double x = 1.0;
68 double y = 1.0;
69 mjr::ramCanvas1c16b::colorChanArithSPType maxII = 0;
70 for(mjr::ramCanvas1c16b::colorChanArithSPType i=0;i<maxIters;i++) {
71 double da = 0.07 * cos(frame * 2 * std::numbers::pi / numFrames);
72 double dc = 0.04 * sin(frame * 2 * std::numbers::pi / numFrames);
73 double db = 0.05 * cos(frame * 2 * std::numbers::pi / numFrames);
74 double dd = 0.13 * sin(frame * 2 * std::numbers::pi / numFrames);
75 double de = 0.18 * sin(frame * 2 * std::numbers::pi / numFrames);
76 double dg = 0.05 * cos(frame * 2 * std::numbers::pi / numFrames);
77 double df = 0.09 * sin(frame * 2 * std::numbers::pi / numFrames);
78 double dh = 0.12 * cos(frame * 2 * std::numbers::pi / numFrames);
79 double xNew = sin((a + da)*y + e + de) - cos((b+db)*x + f + df);
80 double yNew = sin((c + dc)*x + g + dg) - cos((d+dd)*y + h + dh);
81 theRamCanvas.drawPoint(x, y, theRamCanvas.getPxColor(x, y).tfrmAdd(aColor));
82 if(theRamCanvas.getPxColor(x, y).getC0() > maxII) {
83 maxII = theRamCanvas.getPxColor(x, y).getC0();
84 if(maxII > 16384) { // 1/4 of max possible intensity
85 std::cout << "FRAME(" << frame << "): " << i << " MAXS: " << maxII << " EXIT: Maximum image intensity reached" << std::endl;
86 break;
87 }
88 }
89 if((i % itersTick) == 0)
90 std::cout << "FRAME(" << frame << "): " << i << " MAXS: " << maxII << std::endl;
91 x=xNew;
92 y=yNew;
93 }
94
95 // Dump a raw image
96 theRamCanvas.writeTIFFfile("peterdejongM_" + mjr::math::str::fmt_int(frame, 3, '0') + ".mrw");
97
98 // Root image transform
99 theRamCanvas.applyHomoPixTfrm(&mjr::ramCanvas1c16b::colorType::tfrmStdPow, 1.0/p);
100 maxII = static_cast<mjr::ramCanvas1c16b::colorChanArithSPType>(65535.0 * pow(static_cast<double>(maxII)/65535.0, 1.0/p));
101
102 /* 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
103 that we could pass a conversion routine to writeTIFFfile (see sic.cpp for an example of how to do just that). */
104 mjr::ramCanvas3c8b anotherRamCanvas(imageSize, imageSize);
105 mjr::ramCanvas3c8b::colorType bColor;
106 for(int yi=0;yi<theRamCanvas.getNumPixY();yi++)
107 for(int xi=0;xi<theRamCanvas.getNumPixX();xi++)
108 anotherRamCanvas.drawPoint(xi, yi, bColor.cmpRGBcornerDGradiant(static_cast<mjr::ramCanvas3c8b::csIntType>(theRamCanvas.getPxColor(xi, yi).getC0() * 1275 / maxII), "0RYBCW"));
109 anotherRamCanvas.writeTIFFfile("peterdejongM_" + mjr::math::str::fmt_int(frame, 3, '0') + ".tiff");
110
111 }
112 std::chrono::duration<double> runTime = std::chrono::system_clock::now() - startTime;
113 std::cout << "Total Runtime " << runTime.count() << " sec" << std::endl;
114 return 0;
115}
116
117
118// mkdir rawpng
119// mkdir mrw
120// mv peter*.mrw mrw
121// 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
122/** @endcond */
int main(int argc, char *argv[])