MRaster examples 21.0.0.0
Image Processing Library
Loading...
Searching...
No Matches
newton_min_angle.cpp
Go to the documentation of this file.
1// -*- Mode:C++; Coding:us-ascii-unix; fill-column:158 -*-
2/*******************************************************************************************************************************************************.H.S.**/
3/**
4 @file newton_min_angle.cpp
5 @author Mitch Richling <https://www.mitchr.me>
6 @brief Draw a Newton Fractical -- color by orbit distance from roots.@EOL
7 @std C++20
8 @see https://www.mitchr.me/SS/newton/index.html#min_angle
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 We do the standard Newton iterations, but we keep track of the minimum phase angle difference between the three bisectors between the roots. The distances
33 are used to set the r, g, b channels (i.e. distance to root 1/2 bisector is r, root 1/3 bisector is g, and root 2/3 bisector is b).
34*/
35/*******************************************************************************************************************************************************.H.E.**/
36/** @cond exj */
37
38//--------------------------------------------------------------------------------------------------------------------------------------------------------------
39#include "ramCanvas.hpp"
40
41//--------------------------------------------------------------------------------------------------------------------------------------------------------------
42typedef mjr::ramCanvas3c8b rcT; // The Ram Canvas type we will use
43typedef rcT::colorChanType rcccT; // Color Channel Type
44
45//--------------------------------------------------------------------------------------------------------------------------------------------------------------
46int main(void) {
47 std::chrono::time_point<std::chrono::system_clock> startTime = std::chrono::system_clock::now();
48 constexpr int MAXITR = 255;
49 constexpr double ZROEPS = .0001;
50 constexpr int IMGSIZ = 7680;
51 constexpr double ang1 = 0.0;
52 constexpr double ang2 = 2*std::numbers::pi/3;
53 constexpr double ang3 = -2*std::numbers::pi/3;
54 constexpr double ang12 = (ang1+ang2)/2.0;
55 constexpr double ang13 = (ang1+ang3)/2.0;
56 constexpr double ang23 = std::numbers::pi;
57 const double normer = std::log(2*std::numbers::pi/3);
58 std::complex<double> r1( 1.0, sin(ang1));
59 std::complex<double> r2(-0.5, sin(ang2));
60 std::complex<double> r3(-0.5, sin(ang3));
61 rcT theRamCanvas(IMGSIZ, IMGSIZ, -2.15, 1.85, -2.0, 2.0);
62
63# pragma omp parallel for schedule(static,1)
64 for(int y=0;y<theRamCanvas.getNumPixY();y++) {
65 if ((y%100)==0)
66# pragma omp critical
67 std::cout << "line " << y << " of " << IMGSIZ << std::endl;
68 for(int x=0;x<theRamCanvas.getNumPixX();x++) {
69 std::complex<double> z = theRamCanvas.int2real(x, y);
70 double minAngleDelta1 = std::numbers::pi;
71 double minAngleDelta2 = std::numbers::pi;
72 double minAngleDelta3 = std::numbers::pi;
73 for(int count=0; count<MAXITR; count++) {
74 double modz = std::abs(z);
75 if (modz<ZROEPS)
76 break;
77 z = z-(z*z*z-1.0)/(z*z*3.0);
78 double curAngle = std::arg(z);
79 double curAngleDelta1 = std::abs(ang12-curAngle);
80 double curAngleDelta2 = std::abs(ang13-curAngle);
81 double curAngleDelta3 = std::min(std::abs(curAngle-ang23), std::abs(curAngle+ang23));
82 if(curAngleDelta1 < minAngleDelta1) minAngleDelta1 = curAngleDelta1;
83 if(curAngleDelta2 < minAngleDelta2) minAngleDelta2 = curAngleDelta2;
84 if(curAngleDelta3 < minAngleDelta3) minAngleDelta3 = curAngleDelta3;
85 if ((modz<ZROEPS) || (std::abs(z-r1)<ZROEPS) || (std::abs(z-r2)<ZROEPS) || (std::abs(z-r3)<ZROEPS))
86 break;
87 }
88 rcccT r = static_cast<rcccT>(50.0*std::log(minAngleDelta1)/normer);
89 rcccT g = static_cast<rcccT>(50.0*std::log(minAngleDelta2)/normer);
90 rcccT b = static_cast<rcccT>(50.0*std::log(minAngleDelta3)/normer);
91 theRamCanvas.drawPoint(x, y, rcT::colorType(r, g, b));
92 }
93 }
94
95 theRamCanvas.applyHomoPixTfrm(&rcT::colorType::tfrmPow, 0.4);
96 theRamCanvas.writeTIFFfile("newton_min_angle.tiff");
97 std::chrono::duration<double> runTime = std::chrono::system_clock::now() - startTime;
98 std::cout << "Total Runtime " << runTime.count() << " sec" << std::endl;
99}
100/** @endcond */
int main(int argc, char *argv[])