MRaster examples 21.0.0.0
Image Processing Library
Loading...
Searching...
No Matches
newton_z6.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_z6.cpp
5 @author Mitch Richling <https://www.mitchr.me>
6 @brief Draw a Newton Fractical for @f$ z^6 @f$.@EOL
7 @std C++20
8 @see https://www.mitchr.me/SS/newton/index.html#z6
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*/
31/*******************************************************************************************************************************************************.H.E.**/
32/** @cond exj */
33
34//--------------------------------------------------------------------------------------------------------------------------------------------------------------
35#include "ramCanvas.hpp"
36
37//--------------------------------------------------------------------------------------------------------------------------------------------------------------
38typedef mjr::ramCanvas3c8b rcT; // The Ram Canvas type we will use
39
40//--------------------------------------------------------------------------------------------------------------------------------------------------------------
41int main(void) {
42 std::chrono::time_point<std::chrono::system_clock> startTime = std::chrono::system_clock::now();
43 constexpr int COLMAG = 25;
44 constexpr rcT::coordIntType IMGSIZ = 7680;
45 constexpr int MAXITR = 155;
46 constexpr rcT::coordFltType ZROEPS = 1.0e-5;
47 constexpr rcT::cplxFltType r1( 1.0, 0.0);
48 constexpr rcT::cplxFltType r2(-0.5, std::sin(2.0*std::numbers::pi/3.0));
49 constexpr rcT::cplxFltType r3(-0.5, -std::sin(2.0*std::numbers::pi/3.0));
50 constexpr rcT::cplxFltType r4(-1.0, 0.0);
51 constexpr rcT::cplxFltType r5( 0.5, std::sin(2.0*std::numbers::pi/3.0));
52 constexpr rcT::cplxFltType r6( 0.5, -std::sin(2.0*std::numbers::pi/3.0));
53
54 rcT theRamCanvas(IMGSIZ, IMGSIZ, -1.20, 1.20, -1.20, 1.20);
55
56# pragma omp parallel for schedule(static,1)
57 for(rcT::coordIntType y=0;y<theRamCanvas.getNumPixY();y++) {
58 for(rcT::coordIntType x=0;x<theRamCanvas.getNumPixX();x++) {
59 rcT::cplxFltType z = theRamCanvas.int2real(x, y);
60 for(int count=0; count<MAXITR; count++) {
61 if(std::abs(z-r1) <= ZROEPS) {
62 theRamCanvas.drawPoint(x, y, rcT::colorType::csCCu0R::c(255-count*COLMAG)); break;
63 } else if(std::abs(z-r2) <= ZROEPS) {
64 theRamCanvas.drawPoint(x, y, rcT::colorType::csCCu0G::c(255-count*COLMAG)); break;
65 } else if(std::abs(z-r3) <= ZROEPS) {
66 theRamCanvas.drawPoint(x, y, rcT::colorType::csCCu0B::c(255-count*COLMAG)); break;
67 } else if(std::abs(z-r4) <= ZROEPS) {
68 theRamCanvas.drawPoint(x, y, rcT::colorType::csCCu0M::c(255-count*COLMAG)); break;
69 } else if(std::abs(z-r5) <= ZROEPS) {
70 theRamCanvas.drawPoint(x, y, rcT::colorType::csCCu0C::c(255-count*COLMAG)); break;
71 } else if(std::abs(z-r6) <= ZROEPS) {
72 theRamCanvas.drawPoint(x, y, rcT::colorType::csCCu0Y::c(255-count*COLMAG)); break;
73 } else if(std::abs(z) <= ZROEPS) {
74 break;
75 }
76 rcT::cplxFltType tmp = pow(z, 5);
77 z = z-(tmp*z-1.0)/(6.0*tmp);
78 }
79 }
80 }
81 /* The biggest reason homogeneous transforms are in the library is to support color scale correction. */
82 theRamCanvas.applyHomoPixTfrm(&rcT::colorType::tfrmLinearGreyLevelScale, 255.0 / 155, 0.0);
83 theRamCanvas.autoHistStrech();
84 theRamCanvas.writeTIFFfile("newton_z6.tiff");
85 std::chrono::duration<double> runTime = std::chrono::system_clock::now() - startTime;
86 std::cout << "Total Runtime " << runTime.count() << " sec" << std::endl;
87}
88/** @endcond */
int main(int argc, char *argv[])