MRaster examples 22.0.0.0
Image Processing Library
Loading...
Searching...
No Matches
peterdejongEAAO.cpp
Go to the documentation of this file.
1// -*- Mode:C++; Coding:us-ascii-unix; fill-column:158 -*-
2/*******************************************************************************************************************************************************.H.S.**/
3/**
4 @file peterdejongEAAO.cpp
5 @author Mitch Richling <https://www.mitchr.me>
6 @brief Peter de Jong Everywhere All At Once.@EOL
7 @std C++20
8 @copyright
9 @parblock
10 Copyright (c) 2025, 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 Normally when working with the Peter de Jong map we pick a set of parameters (a-h), pick a seed point, and iterate the map a few million times recording all
32 the points the map visits in the plane. We then use this information to color an image -- for example by counting the number of times the map hit each
33 pixel. Not much thought is generally given to the choice of the initial seed point, but it impacts the reaulting image. This approach is used in the
34 example peterdejong.cpp. A write up of this example may be found here:
35
36 https://www.mitchr.me/SS/swirl/index.html
37
38 I called this example "Peter de Jong Everywhere All At Once" because we are using a grid of seed points and simultaneously doing the above process for each
39 pixel in an image. We don't iterate millions of times -- just 8 in this case. Then we colorize the result not by hit count, but by the value of the map at
40 each pixel.
41
42*/
43/*******************************************************************************************************************************************************.H.E.**/
44/** @cond exj */
45
46//--------------------------------------------------------------------------------------------------------------------------------------------------------------
47#include "ramCanvas.hpp"
48#include "MRMathSTR.hpp"
49#include "MRMathIVL.hpp"
50
51//--------------------------------------------------------------------------------------------------------------------------------------------------------------
52int main(void) {
53 std::chrono::time_point<std::chrono::system_clock> startTime = std::chrono::system_clock::now();
54 const int IMXSIZ = 7680/4;
55 const int IMYSIZ = 7680/4;
56
57 const int n = 8;
58 const double a = 1.4;
59 const double b = 2.3;
60 const double c = 2.2;
61 const double d = 1.9;
62 const double e = 1.1;
63 const double f = 2.1;
64 const double g = 1.1;
65 const double h = -2.3;
66
67 mjr::ramCanvas1c64F xcanvas(IMXSIZ, IMYSIZ, -2, 2, -2, 2);
68 mjr::ramCanvas1c64F ycanvas(IMXSIZ, IMYSIZ, -2, 2, -2, 2);
69 for(int itr=0; itr<n; itr++) {
70# pragma omp parallel for schedule(static,1)
71 for(int yi=0;yi<xcanvas.getNumPixY();yi++) {
72 for(int xi=0;xi<xcanvas.getNumPixX();xi++) {
73 double x, y;
74 if (itr == 0) {
75 x = xcanvas.int2realX(xi);
76 y = xcanvas.int2realY(yi);
77 } else {
78 x = xcanvas.getPxColorRefNC(xi, yi).getC0();
79 y = ycanvas.getPxColorRefNC(xi, yi).getC0();
80 double xNew = std::sin(a*y + e) - std::cos(b*x + f);
81 double yNew = std::sin(c*x + g) - std::cos(d*y + h);
82 x = xNew;
83 y = yNew;
84 }
85 xcanvas.drawPoint(xi, yi, x);
86 ycanvas.drawPoint(xi, yi, y);
87 }
88 }
89 std::cout << "ITR(" << itr << "): " << "DONE" << std::endl;
90 }
91 mjr::ramCanvas3c8b p1canvas(IMXSIZ, IMYSIZ);
92 mjr::ramCanvas3c8b p2canvas(IMXSIZ, IMYSIZ);
93 mjr::ramCanvas3c8b p3canvas(IMXSIZ, IMYSIZ);
94 mjr::ramCanvas3c8b p4canvas(IMXSIZ, IMYSIZ);
95# pragma omp parallel for schedule(static,1)
96 for(int yi=0;yi<p1canvas.getNumPixY();yi++) {
97 for(int xi=0;xi<p1canvas.getNumPixX();xi++) {
98 double x = xcanvas.getPxColorRefNC(xi, yi).getC0();
99 double y = ycanvas.getPxColorRefNC(xi, yi).getC0();
100
101 double r = mjr::math::ivl::wrapCO((x+2)/4, 1.0);
102 double g = 0.0;
103 double b = mjr::math::ivl::wrapCO((y+2)/4, 1.0);
104 p1canvas.getPxColorRefNC(xi, yi).setChansRGB_dbl(r, g, b);
105
106 g = mjr::math::ivl::wrapCO((x+y+4)/8, 1.0);
107 p2canvas.getPxColorRefNC(xi, yi).setChansRGB_dbl(r, g, b);
108
109 p3canvas.drawPoint(xi, yi, decltype(p1canvas)::colorType::csPLYgrey::c(g));
110
111 p4canvas.drawPoint(xi, yi, decltype(p1canvas)::colorType::csCColdeFireRamp::c(r*r));
112 }
113 }
114 p1canvas.writeTIFFfile("peterdejongEAAO_00_c1.tiff", mjr::ramCanvasPixelFilter::ScaleDownMean<decltype(p1canvas), 4>(p1canvas));
115 p2canvas.writeTIFFfile("peterdejongEAAO_00_c2.tiff", mjr::ramCanvasPixelFilter::ScaleDownMean<decltype(p2canvas), 4>(p2canvas));
116 p3canvas.writeTIFFfile("peterdejongEAAO_00_c3.tiff", mjr::ramCanvasPixelFilter::ScaleDownMean<decltype(p3canvas), 4>(p3canvas));
117 p4canvas.writeTIFFfile("peterdejongEAAO_00_c4.tiff", mjr::ramCanvasPixelFilter::ScaleDownMean<decltype(p4canvas), 4>(p4canvas));
118
119 std::chrono::duration<double> runTime = std::chrono::system_clock::now() - startTime;
120 std::cout << "Total Runtime " << runTime.count() << " sec" << std::endl;
121 return 0;
122}
123/** @endcond */
124
int main(int argc, char *argv[])