MRaster examples 21.0.0.0
Image Processing Library
Loading...
Searching...
No Matches
sprott2d.cpp
Go to the documentation of this file.
1// -*- Mode:C++; Coding:us-ascii-unix; fill-column:158 -*-
2/*******************************************************************************************************************************************************.H.S.**/
3/**
4 @file sprott2d.cpp
5 @author Mitch Richling <https://www.mitchr.me>
6 @brief Draw a sprott Attractor.@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 Inspired by http://paulbourke.net/fractals/starjulia/
32*/
33/*******************************************************************************************************************************************************.H.E.**/
34/** @cond exj */
35
36//--------------------------------------------------------------------------------------------------------------------------------------------------------------
37#include "ramCanvas.hpp"
38
39//--------------------------------------------------------------------------------------------------------------------------------------------------------------
40int main(void) {
41 std::chrono::time_point<std::chrono::system_clock> startTime = std::chrono::system_clock::now();
42 const int BSIZ = 7680/8;
43 mjr::ramCanvas1c16b::colorType aColor;
44 aColor.setChans(1);
45 mjr::ramCanvas1c16b theRamCanvas(BSIZ, BSIZ, -1, 1, -1, 1);
46 double x=0.0, y=0.0, xNew, yNew;
47
48 double a[12] = {-0.6599, -0.2, 1.1, 0.2, -0.81, 0.61, -0.7, 0.71, 0.7, 0.28, 0.19, 0.89};
49 double p = 1.7;
50
51 /* 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
52 of how an image can have pixel values that are generic "data" as well as color information. */
53 uint64_t maxII = 0;
54 for(uint64_t i=0;i<1000000000ul;i++) {
55
56 xNew = a[0] + a[1]*x + a[2]*x*x + a[3]*x*y + a[4]*y + a[5]*y*y;
57 yNew = a[6] + a[7]*x + a[8]*x*x + a[9]*x*y + a[10]*y + a[11]*y*y;
58 theRamCanvas.drawPoint(xNew, yNew, theRamCanvas.getPxColor(xNew, yNew).tfrmAdd(aColor));
59 if(theRamCanvas.getPxColor(xNew, yNew).getC0() > maxII) {
60 maxII = theRamCanvas.getPxColor(xNew, yNew).getC0();
61 if(maxII > 16384) { // 1/4 of max possible intensity
62 std::cout << "ITER(): " << i << " MAXS: " << maxII << " EXIT: Maximum image intensity reached" << std::endl;
63 break;
64 }
65 }
66 if((i % 10000000) == 0)
67 std::cout << "ITER: " << i << " MAXS: " << maxII << std::endl;
68 x=xNew;
69 y=yNew;
70 }
71
72 theRamCanvas.writeRAWfile("sprott2d.mrw");
73
74 // Root image transform
75 theRamCanvas.applyHomoPixTfrm(&mjr::ramCanvas1c16b::colorType::tfrmStdPow, 1/p);
76 maxII = static_cast<uint64_t>(65535.0 * std::pow(static_cast<double>(maxII)/65535.0, 1/p));
77
78 // Log image transform
79 // theRamCanvas.applyHomoPixTfrm(&mjr::ramCanvas1c16b::colorType::tfrmLn);
80 // maxII = log(maxII);
81
82 /* 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
83 that we could pass a conversion routine to writeTIFFfile (see sic.cpp for an example of how to do just that). */
84 mjr::ramCanvas3c8b anotherRamCanvas(BSIZ, BSIZ);
85 mjr::ramCanvas3c8b::colorType bColor;
86 for(int yi=0;yi<theRamCanvas.getNumPixY();yi++)
87 for(int xi=0;xi<theRamCanvas.getNumPixX();xi++)
88 anotherRamCanvas.drawPoint(xi, yi, bColor.cmpRGBcornerDGradiant(static_cast<mjr::ramCanvas3c8b::csIntType>(theRamCanvas.getPxColor(xi, yi).getC0() * 1275 / maxII), "0RYBCW"));
89
90 anotherRamCanvas.writeTIFFfile("sprott2d.tiff");
91 std::chrono::duration<double> runTime = std::chrono::system_clock::now() - startTime;
92 std::cout << "Total Runtime " << runTime.count() << " sec" << std::endl;
93 return 0;
94}
95/** @endcond */
int main(int argc, char *argv[])