MRaster examples 21.0.0.0
Image Processing Library
Loading...
Searching...
No Matches
cplxColor.cpp
Go to the documentation of this file.
1// -*- Mode:C++; Coding:us-ascii-unix; fill-column:158 -*-
2/*******************************************************************************************************************************************************.H.S.**/
3/**
4 @file cplxColor.cpp
5 @author Mitch Richling <https://www.mitchr.me>
6 @brief draw complex function plots@EOL
7 @keywords
8 @std C++20
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//--------------------------------------------------------------------------------------------------------------------------------------------------------------
38using cplx = std::complex<double>;
39using ct_t = mjr::ramCanvas3c8b::colorType;
40
41//--------------------------------------------------------------------------------------------------------------------------------------------------------------
42cplx f(cplx z);
43
44//--------------------------------------------------------------------------------------------------------------------------------------------------------------
45int main(void) {
46 std::chrono::time_point<std::chrono::system_clock> startTime = std::chrono::system_clock::now();
47 const double ar = 16/9.0; // Aspect ratio
48 const int hdLevel = 4; // 1=FHD/2 2=FHD, 4=4k, 8=8k
49 mjr::ramCanvas3c8b theRamCanvas(960*hdLevel, 540*hdLevel, -2.2*ar, 2.2*ar, -2.2, 2.2);
50 ct_t aColor;
51
52 for(int y=0;y<theRamCanvas.getNumPixY();y++) {
53 if (0==(y % (hdLevel*20)))
54 std::cout << "LINE: " << y << " of " << (540*hdLevel) << std::endl;
55 for(int x=0;x<theRamCanvas.getNumPixX();x++) {
56 cplx fz = f(cplx(theRamCanvas.int2realX(x), theRamCanvas.int2realY(y)));
57
58 // We can use built in 2D color schemes in multiple diffrent ways.
59 //
60 // aColor = ct_t::cs2dRichardson<10.0, 10.0, 2.0, 1>::c(std::real(fz), std::imag(fz));
61 // aColor = ct_t::cs2dRichardson<10.0, 10.0, 2.0, 1>::c(fz);
62 //
63 // ct_t::cs2dRichardson<10.0, 10.0, 2.0, 1>::c(aColor, fz);
64 // ct_t::cs2dRichardson<10.0, 10.0, 2.0, 1>::c(aColor, std::real(fz), std::imag(fz));
65 //
66 // aColor.csSet<ct_t::cs2dRichardson<10.0, 10.0, 2.0, 1>>(fz);
67 // aColor.csSet<ct_t::cs2dRichardson<10.0, 10.0, 2.0, 1>>(std::real(fz), std::imag(fz));
68
69 // // Schemes designed for coloring complex functions
70 // aColor.csSet<ct_t::cs2dRichardson< 10.0, 10.0, 10.0, 1>>(fz);
71 // aColor.csSet<ct_t::cs2dThallerHSL< 10.0, 10.0, 10.0, 1>>(fz);
72 // aColor.csSet<ct_t::cs2dThallerHSV< 10.0, 10.0, 10.0, 1>>(fz);
73 // aColor.csSet<ct_t::cs2dThallerHSVm<10.0, 10.0, 10.0, 1>>(fz);
74
75 // A common choice for color scheme is ct_t::csCColdeRainbow:
76 //aColor.csSet<ct_t::cs2dIdxPalArg<ct_t::csCColdeRainbow, 3, 10.0, 10.0, 2.0, 1>>(fz);
77
78 aColor.csSet<ct_t::cs2dIdxPalArg<ct_t::csCColdeRainbow, 3, 5.0, 20.0, 2.0, 1>>(fz);
79
80 // Variable sized pallets can be used with an adapter
81 //aColor.csSet<ct_t::cs2dIdxPalArg<ct_t::csVarToFixed_tpl<ct_t::csCBPiYG, 11>, 3, 10.0, 10.0, 2.0, 1>>(fz);
82
83 // Most variable sized pallets can be also be used directly as a continious pallet
84 //aColor.csSet<ct_t::cs2dFltPalArg<ct_t::csCBPiYG, 3, 10.0, 10.0, 2.0, 1>>(fz);
85
86 // We can use cs2dFltPalArg for continious color pallets
87 // aColor.csSet<ct_t::cs2dFltPalArg<ct_t::csPLYviridis, 3, 10.0, 10.0, 2.0, 1>>(fz);
88
89 theRamCanvas.drawPoint(x, y, aColor);
90 }
91 }
92 theRamCanvas.writeTIFFfile("cplxColor.tiff");
93 std::chrono::duration<double> runTime = std::chrono::system_clock::now() - startTime;
94 std::cout << "Total Runtime " << runTime.count() << " sec" << std::endl;
95}
96
97//--------------------------------------------------------------------------------------------------------------------------------------------------------------
98cplx f(cplx z) {
99 try {
100
101 return 1.0/(z+1.0) + 1.0/(z-1.0);
102
103 // z=z*cplx(1.5);
104 // return ((z-2.0)*(z-2.0)*(z+cplx(1,-2))*(z+cplx(2,2))/(z*z*z));
105
106 // z=z/cplx(5.5);
107 // return (std::sin(cplx(1)/z));
108
109 // z=z/cplx(2.3);
110 // for(int i=0; i<20; i++)
111 // z = z*z-cplx(0.75, 0.2);
112 // return z;
113
114 // z=(z*cplx(0, 1)+cplx(1.8, 0))*cplx(0.6, 0);
115 // for(int i=0; i<3; i++)
116 // z = (std::sin(std::exp(z)) - cplx(1))/(std::cos(z*z) - cplx(2.0)*z*z + z + cplx(1));
117 // return z;
118
119 //return (std::sin(z) - cplx(1))/(z*z*z - cplx(0.5)*z*z + z + cplx(1));
120
121 // return (std::sin(std::exp(z)) - cplx(1))/(std::cos(z*z) - cplx(2.0)*z*z + z + cplx(1));
122
123 // return (z - cplx(1))/(z*z*z - cplx(0.5)*z*z + z + cplx(1));
124
125 // return z;
126
127 //// Eisenstein series E4
128 // cplx f = 0.0;
129 // cplx zp = z;
130 // for(int n=1; n<20; n++) {
131 // f += static_cast<double>(n*n*n)*zp/(1.0-zp);
132 // zp *= z;
133 // }
134 // f *= 240;
135 // f += 1;
136 // return f;
137
138 //// Eisenstein series E6
139 // cplx f = 0.0;
140 // cplx zp = z;
141 // for(int n=1; n<20; n++) {
142 // f += static_cast<double>(n*n*n*n*n)*zp/(1.0-zp);
143 // zp *= z;
144 // }
145 // f *= 504.0;
146 // f = 1.0 - f;
147 // return f;
148
149 // //// Eisenstein series G6
150 // cplx f = 0.0;
151 // for(int n=1; n<10; n++)
152 // for(int m=1; m<10; m++) {
153 // cplx d = 1.0/std::pow(static_cast<double>(m) + static_cast<double>(n) * z, 6.0);
154 // f += d;
155 // if (std::abs(d) < 0.00001) break;
156 // }
157 // return f;
158
159 } catch(...) {
160 std::cout << "Something went wrong!!" << std::endl;
161 return 0;
162 }
163}
164
165
166
167/** @endcond */
int main(int argc, char *argv[])