-
Notifications
You must be signed in to change notification settings - Fork 0
/
m.c
1194 lines (727 loc) · 29.1 KB
/
m.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
Adam Majewski
console program in c programing language
===============================================================
Structure of a program or how to analyze the program
Creating graphic:
* memory array
* save it to the disk as a pgm file
* convert pgm file to png usnigng Image Magic convert
Algorithms
* interior detection ( speed up computations)
https://mathr.co.uk/blog/2017-05-17_periodicity_scan.html
// find the period of a nucleus within a large box uses Robert P. Munafo's Jordan curve method
int p = m_d_box_period_do(c0, 4.0 * cabs(dc0), maxiters);
if (p > 0)
// refine the nucleus location (uses Newton's method)
if (m_converged == m_d_nucleus(&c0, c0, p, 16))
{
// verify the period with a small box
// if the period is wrong, the size estimates will be way off
as[atoms].period = m_d_box_period_do(c0, 0.001 * cabs(dc0), 2 * p);
if (as[atoms].period > 0)
{
as[atoms].nucleus = c0;
// size of component using algorithm from ibiblio.org M-set e-notes
as[atoms].size = cabs(m_d_size(c0, as[atoms].period));
// size of atom domain using algorithm from an earlier blog post of mine
as[atoms].domain_size = m_d_domain_size(c0, as[atoms].period);
// shape of component (either cardioid or disc) after Dolotin and Morozov (2008 eq. 5.8)
as[atoms].shape = m_d_shape_discriminant(m_d_shape_estimate(c0, as[atoms].period));
atoms++;
==========================================
---------------------------------
indent m.c
default is gnu style
-------------------
c console progam
export OMP_DISPLAY_ENV="TRUE"
gcc d.c -lm -Wall -march=native -fopenmp
time ./a.out > b.txt
gcc m.c -lm -Wall -Wextra -march=native -fopenmp
time ./a.out
time ./a.out >a.txt
./g.sh
============================
gcc m.c -lm -Wall -march=native -fopenmp -pg
gprof ./a.out > p.txt
*/
#include <stdio.h>
#include <stdlib.h> // malloc
#include <string.h> // strcat
#include <math.h> // M_PI; needs -lm also
#include <complex.h> // complex numbers : https://stackoverflow.com/questions/6418807/how-to-work-with-complex-numbers-in-c
#include <stdbool.h>
#include <omp.h> // OpenMP
#define kMax 12 // number of examples, see line 211 plane_examples
// https://sourceforge.net/p/predef/wiki/Standards/
#if defined(__STDC__)
#define PREDEF_STANDARD_C_1989
#if defined(__STDC_VERSION__)
#if (__STDC_VERSION__ >= 199409L)
#define PREDEF_STANDARD_C_1994
#endif
#if (__STDC_VERSION__ >= 199901L)
#define PREDEF_STANDARD_C_1999
#endif
#endif
#endif
/* --------------------------------- global variables and consts ------------------------------------------------------------ */
// each typedef should have different range !!!
/* Representation FunctionType
https://mrob.com/pub/muency/representationfunction.html
function defining relation between data and the image
*/
typedef enum {
LSM =100,
LCM = 101,
DEM = 102,
Unknown = 103,
BD = 104,
MBD = 105,
BET = 106,
Period = 107,
LastIteration = 108,
AtomDomains = 109,
SAC,
DLD,
ND,
NP,
POT,
Blend
} RepresentationFunctionTypeT;
// virtual 2D array and integer ( screen) coordinate
// Indexes of array starts from 0 not 1
//unsigned int ix, iy; // var
static int ixMin = 0; // Indexes of array starts from 0 not 1
static int ixMax; //
static int iWidth; // horizontal dimension of array
static int iyMin = 0; // Indexes of array starts from 0 not 1
static int iyMax; //
static int iHeight = 4000; //
// The size of array has to be a positive constant integer
static int iSize; // = iWidth*iHeight;
// ----------memmory 1D arrays ==================
// unsigned char = for 1 byte ( 8 bit) colors
unsigned char *data;
unsigned char *edge;
// unsigned int i; // var = index of 1D array
//static unsigned int iMin = 0; // Indexes of array starts from 0 not 1
static int iMax; // = i2Dsize-1 =
// The size of array has to be a positive constant integer
// unsigned int i1Dsize ; // = i2Dsize = (iMax -iMin + 1) = ; 1D array with the same size as 2D array
// on the initial plane , before transformation
double DisplayAspectRatio = 1.5 ; // https://en.wikipedia.org/wiki/Aspect_ratio_(image)
const complex double critical_point = 0.0; //
// parameter plane
double xMin ; //-0.05;
double xMax ; //0.75;
double yMin ; //-0.1;
double yMax ; //0.7;
double PixelWidth; // =(CxMax-CxMin)/ixMax;
double PixelHeight; // =(CyMax-CyMin)/iyMax;
double plane_radius;
complex double plane_center;
double zoom;
complex double pseudo_cardioid_center; // nucleus
complex double pseudo_cardioid_cusp; //
complex double pseudo_cardioid_root_half; // common point between pseudocardioid and period*2 componnet
/*
plane : plane_center_x, plane_center_y, plane_radius, period
examples containing islands = minibrots
note that plane_center does not equal to hyperbolic component center
plane radius is adjusted to show only 2 main components of the island
https://mrob.com/pub/muency/mainsequence.html
https://mrob.com/pub/muency/largestislands.html
https://mrob.com/pub/mu-data/largest-islands.txt
*/
double plane_examples[kMax][4] = {
{-0.4, +0.0, 0.8, 1},
{+0.2925755, -0.0149977, 0.00025, 16},
{-1.763, +0.0, 0.016, 3},
{-0.15842, +1.03335, 0.01, 4},
{+0.358431, + 0.643507, 0.006, 5},
{+0.442990, +0.373727, 0.005, 6},
{+0.432259, +0.227315, 0.003, 7},
{+0.404879, +0.146216, 0.002, 8},
{+0.378631, +0.098841, 0.001, 9},
{+0.356854, +0.069659, 0.001, 10},
{+0.339454, +0.050823, 0.001, 11},
{+0.325631, +0.038164, 0.001, 12}
};
const int iterMax_LastIteration = 100000;
const int iterMax_LSM = 1001;
const int iterMax_DEM = 1001;
const int iterMax_BET = 1000;
// EscapeRadius for bailout test
double ER = 2.0;
double ER2;
double ER_DEM = 100.0;
double ER2_DEM;
//double precision= 1.0E-10; // relate with zoom, PixelWidth in setup
int iPixelSpacingBits ; // precision in binary digits or bits
double eps=0.001; // precision
double eps2;
// pixel counters
int iUnknown = 0;
int iInterior = 0;
int iExterior = 0;
/* colors = shades of gray from 0 to 255 */
unsigned char iColorOfExterior = 255;
unsigned char iColorOfInterior = 150;
unsigned char iColorOfPseudoCardioid = 150;
unsigned char iColorOfMainBulb = 150;
unsigned char iColorOfBoundary = 0;
unsigned char iColorOfUnknown = 30;
// https://en.wikibooks.org/wiki/Fractals/Iterations_in_the_complex_plane/qpolynomials
complex double fc( const double complex z , const complex double c ){
return z*z +c;
}
// -----------------------------------from screen to world coordinate ; linear mapping ---------------------------------------
// uses global cons
double Give_x (const int ix)
{
return (xMin + ix * PixelWidth);
}
// uses global cons
double Give_y (const int iy) {
return (yMax - iy * PixelHeight); // reverse y axis
}
complex double Give_c (const int ix, const int iy)
{
double x = Give_x (ix);
double y = Give_y (iy);
return x + y * I;
}
/* ------------------------------------------ functions -------------------------------------------------------------*/
double clamp(double x, double lo, double hi) {
return fmin(fmax(x, lo), hi);
}
//------------------complex numbers -----------------------------------------------------
static inline int sgn(double z) {
if (z > 0) { return 1; }
if (z < 0) { return -1; }
return 0;
}
static inline bool odd(int a) {
return a & 1;
}
static inline bool cisfinite(double _Complex z) {
return isfinite(creal(z)) && isfinite(cimag(z));
}
double cabs2(complex double z) {
return creal(z) * creal(z) + cimag(z) * cimag(z);
}
int SameValue(complex double Z1, complex double Z2)
{
if (cabs2(Z1- Z2) < eps2 )
{return 1; /* true */ }
else return 0; /* false */
}
int escapes(complex double z){
if (cabs2(z) > ER2)
return 1; // escapes
return 0; // not escapes
}
/* ----------- array functions = drawing -------------- */
/* gives position of 2D point (ix,iy) in 1D array ; uses also global variable iWidth */
unsigned int Give_i (const int ix, const int iy)
{
return ix + iy * iWidth;
}
// ***************************************************************************************************************************
// ************************** Last Iteration = Fast Iteration = Interior detection *****************************************
// ****************************************************************************************************************************
// gives last iterate = escape time
// https://en.wikibooks.org/wiki/Fractals/Iterations_in_the_complex_plane/Mandelbrot_set/mandelbrot
//
int give_last_iteration(double complex C )
{
int i=0;
int iMax = iterMax_LastIteration;
// note that we start with c instead of 0, to avoid multiplying the derivative by 0
double complex Z = C; // initial value for iteration Z0
complex double D = 1.0; // derivative with respect to z
for(i=0;i<iMax;i++)
{ if(cabs2(Z) > ER2)
{ return i;} // exterior
if(cabs2(D) < eps2)
{return -i; } // interior
D = 2.0*D*Z; // derivative
Z = Z*Z+C; // iteration of complex quadratic polynomial: z = f(z)
}
iUnknown +=1; // update pixel counters
return 0; // unknown
}
/* show only 2 xomponent of the island : main pseudocardioid and it's main bulb */
unsigned char ComputeColorOf_last_iteration(complex double c){
unsigned char color;
int last_iteration = give_last_iteration(c);
if (last_iteration > 0)
{ color = iColorOfExterior; }
else {
if (last_iteration < 0)
{ color = iColorOfInterior; }
else {color = iColorOfUnknown;} // i ==0
}
return color;
}
// ***************************************************************************************************************************
// ************************** Atom domains *****************************************
// ****************************************************************************************************************************
int atom_domains( double _Complex c, int nMax)
{
double _Complex z = c;
//int nMax = 100;
const double infinity = 1.0 / 0.0;
complex double dc = 0;
double minimum_z2 = infinity; // atom domain
int period = 0;
// iteration
for (int n = 1; n <= nMax; ++n) {
dc = 2 * z * dc + 1;
z = z * z + c;
double z2 = cabs2(z);
if (z2 < minimum_z2) {
minimum_z2 = z2;
period = n;}}
return period;
}
/* show only 2 xomponent of the island : main pseudocardioid and it's main bulb */
unsigned char ComputeColorOf_atom_domains(const int period_of_pseudocardioid, complex double c){
unsigned char color;
int last_iteration = give_last_iteration(c);
int period = atom_domains(c,1);
if (last_iteration > 0)
{ color = iColorOfExterior; }
else {
if (last_iteration < 0)
{
if (period == period_of_pseudocardioid)
{color = iColorOfPseudoCardioid ;}
else { if (period == 2*period_of_pseudocardioid)
{color= iColorOfMainBulb; }
}
}
else {color = iColorOfUnknown;} // i ==0
}
return color;
}
// ***************************************************************************************************************************
// ************************** PER = Period ****************************************************************** ************
// ****************************************************************************************************************************
//****************************************************************
//**************** Box period *************************************
//*****************************************************************
static double cross(double _Complex a, double _Complex b) {
return cimag(a) * creal(b) - creal(a) * cimag(b);
}
static bool crosses_positive_real_axis(double _Complex a, double _Complex b) {
if (sgn(cimag(a)) != sgn(cimag(b))) {
double _Complex d = b - a;
int s = sgn(cimag(d));
int t = sgn(cross(d, a));
return s == t;
}
return false;
}
static bool surrounds_origin(double _Complex a, double _Complex b, double _Complex c, double _Complex d) {
return odd
( crosses_positive_real_axis(a, b)
+ crosses_positive_real_axis(b, c)
+ crosses_positive_real_axis(c, d)
+ crosses_positive_real_axis(d, a)
);
}
typedef struct {
double _Complex c[4];
double _Complex z[4];
int p;
} m_d_box_period ;
m_d_box_period *m_d_box_period_new(double _Complex center, double radius) {
m_d_box_period *box = (m_d_box_period *) malloc(sizeof(*box));
if (! box) {
return 0;
}
box->z[0] = box->c[0] = center + ((-radius) + I * (-radius));
box->z[1] = box->c[1] = center + (( radius) + I * (-radius));
box->z[2] = box->c[2] = center + (( radius) + I * ( radius));
box->z[3] = box->c[3] = center + ((-radius) + I * ( radius));
box->p = 1;
return box;
}
void m_d_box_period_delete(m_d_box_period *box) {
if (box) {
free(box);
}
}
bool m_d_box_period_step(m_d_box_period *box) {
if (! box) {
return false;
}
bool ok = true;
for (int i = 0; i < 4; ++i) {
box->z[i] = box->z[i] * box->z[i] + box->c[i];
ok = ok && cisfinite(box->z[i]);
}
box->p = box->p + 1;
return ok;
}
bool m_d_box_period_have_period(const m_d_box_period *box) {
if (! box) {
return true;
}
return surrounds_origin(box->z[0], box->z[1], box->z[2], box->z[3]);
}
int m_d_box_period_get_period(const m_d_box_period *box) {
if (! box) {
return 0;
}
return box->p;
}
int m_d_box_period_do(double _Complex center, double radius, int maxperiod) {
m_d_box_period *box = m_d_box_period_new(center, radius);
if (! box) {
return 0;
}
int period = 0;
for (int i = 0; i < maxperiod; ++i) {
if (m_d_box_period_have_period(box)) {
period = m_d_box_period_get_period(box);
break;
}
if (! m_d_box_period_step(box)) {
break;
}
}
m_d_box_period_delete(box);
return period;
}
int GivePeriodByIteration (const double complex c ){
// int period = 0;
int iMax = 2000;
int i;
complex double orbit[2001]; // length(orbit) = iMax + 1
complex double z = 0.0; // critical point
// iteration without saving points
for(i=0; i<iMax; ++i)
{
z = fc(z, c);
if (escapes(z) ) {return 0; } // escaping = exterior of M set so break the procedure
} // for(i
// iteration = computing the orbit = fiil the array
orbit[0] = z;
for(i=1; i<iMax+1; ++i)
{
z = fc(z, c);
if ( escapes(z)) {return 0; } // escaping = exterior of M set so break the procedure
orbit[i] = z;
//printf(" i = %d z = %f+%f \n", i, creal(orbit[i]), cimag(orbit[i]));
} // for(i=0
// look for similar points = attractor
// go from the last point of the orbit
//z = orbit[0];
for(i=iMax-1; i>0; --i){
if ( SameValue( z, orbit[i]))
{//printf(" z = %f+%f diff = %e\n", creal(orbit[i]), cimag(orbit[i]), cabs(z - orbit[i]));
return iMax - i;} // period
//else printf(" z = %f+%f diff = %e\n", creal(orbit[i]), cimag(orbit[i]), cabs(z - orbit[i]));
}
return -1; // period not found
}
int GivePeriod(complex double c){
if (cabs2(c)>4.0) {return 0;} // exterior
if (cabs2(1.0 - csqrt(1.0-4.0*c))<=1.0 ) {return 1;} // main cardioid
if (cabs2(4.0*c + 4)<=1.0){return 2;} // period 2 component
int period = GivePeriodByIteration(c);
//period = m_d_box_period_do(c, 0.5, iterMax_LastIteration);
return period; // period not found
}
/* show only 2 component of the island : main pseudocardioid and it's main bulb */
unsigned char ComputeColorOf_Period(const int period_of_pseudocardioid, complex double c){
unsigned char color;
int period = GivePeriod(c);
if (period == period_of_pseudocardioid)
{ color = iColorOfPseudoCardioid ; }
else {
if (period == 2*period_of_pseudocardioid)
{color= iColorOfMainBulb; }
else { color = iColorOfExterior; }
}
return color;
}
// ***********************************************************************************************
// ********************** edge detection usung Sobel filter ***************************************
// ***************************************************************************************************
// from Source to Destination
int ComputeBoundaries(const unsigned char S[], unsigned char D[])
{
int iX,iY; /* indices of 2D virtual array (image) = integer coordinate */
int i; /* index of 1D array */
/* sobel filter */
unsigned char G, Gh, Gv;
// boundaries are in D array ( global var )
// clear D array
memset(D, iColorOfExterior, iSize*sizeof(*D)); //
fprintf(stderr, "\tfind boundaries in S array using Sobel filter\n");
#pragma omp parallel for schedule(dynamic) private(i,iY,iX,Gv,Gh,G) shared(iyMax,ixMax)
for(iY=1;iY<iyMax-1;++iY){
for(iX=1;iX<ixMax-1;++iX){
Gv= S[Give_i(iX-1,iY+1)] + 2*S[Give_i(iX,iY+1)] + S[Give_i(iX-1,iY+1)] - S[Give_i(iX-1,iY-1)] - 2*S[Give_i(iX-1,iY)] - S[Give_i(iX+1,iY-1)];
Gh= S[Give_i(iX+1,iY+1)] + 2*S[Give_i(iX+1,iY)] + S[Give_i(iX-1,iY-1)] - S[Give_i(iX+1,iY-1)] - 2*S[Give_i(iX-1,iY)] - S[Give_i(iX-1,iY-1)];
G = sqrt(Gh*Gh + Gv*Gv);
i= Give_i(iX,iY); /* compute index of 1D array from indices of 2D array */
if (G==0) {D[i]=255;} /* background */
else {D[i]=0;} /* boundary */
}
}
return 0;
}
// copy from Source to Destination
int CopyBoundaries(const unsigned char S[], unsigned char D[])
{
int iX,iY; /* indices of 2D virtual array (image) = integer coordinate */
int i; /* index of 1D array */
fprintf(stderr, "\tcopy boundaries from S array to D array \n");
for(iY=1;iY<iyMax-1;++iY)
for(iX=1;iX<ixMax-1;++iX)
{i= Give_i(iX,iY); if (S[i]==0) D[i]=0;}
return 0;
}
/* ==================================================================================================
============================= Draw functions ===============================================================
=====================================================================================================
*/
unsigned char ComputeColor(const int period_of_pseudocardioid, const RepresentationFunctionTypeT RepresentationFunctionType, const complex double c ){
unsigned char iColor= 0;
switch(RepresentationFunctionType){
case AtomDomains : {iColor = ComputeColorOf_atom_domains(period_of_pseudocardioid, c); break;}
case LastIteration : {iColor = ComputeColorOf_last_iteration(c); break;}
case Period: {iColor = ComputeColorOf_Period(period_of_pseudocardioid, c); break;}
default: {}
}
return iColor;
}
unsigned char GiveColor(const int period, const RepresentationFunctionTypeT RepresentationFunctionType, const int ix, const int iy){
complex double c = Give_c(ix,iy);
unsigned char iColor = ComputeColor(period, RepresentationFunctionType, c);
return iColor;
}
// plots raster point (ix,iy) = computes it's color and save it to the array A
int DrawPoint (const int period, const RepresentationFunctionTypeT RepresentationFunctionType, const int ix, const int iy, unsigned char A[])
{
unsigned char iColor = GiveColor(period, RepresentationFunctionType, ix, iy);
int i = Give_i (ix, iy); /* compute index of 1D array from indices of 2D array */
A[i] = iColor ; //
return 0;
}
// fill array
// uses global var : ...
// scanning complex plane
int DrawImage (const int k, const RepresentationFunctionTypeT RepresentationFunctionType, unsigned char A[])
{
int ix, iy; // pixel coordinate
const int period = (int) plane_examples[k][3];
fprintf(stderr, "compute example image %d RepresentationFunctionType = %d period = %d \n", k, RepresentationFunctionType, period);
// for all pixels of image
#pragma omp parallel for schedule(dynamic,1) private(ix,iy) shared(A, ixMax , iyMax)
// #pragma omp parallel for schedule(dynamic, 1)
for (iy = iyMin; iy <= iyMax; ++iy){
fprintf (stderr, " %d from %d \r", iy, iyMax); //info
for (ix = ixMin; ix <= ixMax; ++ix)
{DrawPoint(period, RepresentationFunctionType, ix, iy, A);} //
}
return 0;
}
// *******************************************************************************************
// ********************************** save A array to pgm file ****************************
// *********************************************************************************************
int SaveImage(const unsigned char A[], const char *shortName )
{
FILE *fp;
const int MaxColorComponentValue = 255; /* color component is coded from 0 to 255 ; it is 8 bit color file */
// https://programmerfish.com/create-output-file-names-using-a-variable-in-c-c/
char fileName[512];
const char* fileType = ".pgm";
sprintf(fileName,"%s%s", shortName, fileType); //
char long_comment[200];
sprintf (long_comment, "one parameter family of complex quadratic polynomial, parameter plane ");
// save image array to the pgm file
fp = fopen (fileName, "wb"); // create new file,give it a name and open it in binary mode
fprintf (fp, "P5\n # %s\n %d %d\n %d\n", long_comment, iWidth, iHeight, MaxColorComponentValue); // write header to the file
size_t rSize = fwrite (A, sizeof(A[0]), iSize, fp); // write whole array with image data bytes to the file in one step
fclose (fp);
// info
if ( rSize == (long unsigned int) iSize)
{
printf ("File %s saved ", fileName);
if (long_comment == NULL || strlen (long_comment) == 0)
printf ("\n");
else { printf (". Comment = %s \n", long_comment); }
}
else {printf("wrote %zu elements out of %u requested\n", rSize, iSize);}
return 0;
}
complex double GiveCenter ()
{
complex double local_center = 0.0;
return local_center;
}
/*
********************************************* info
*/
// *****************************************************************************
//;;;;;;;;;;;;;;;;;;;;;; program setup ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
// **************************************************************************************
// uses global var
// local set up for every example from plane_examples array
int local_setup(const int k){
// read from the array with presettings
plane_radius = plane_examples[k][2];
plane_center = plane_examples[k][0] + I*plane_examples[k][1];
yMin = cimag(plane_center) - plane_radius; //
yMax = cimag(plane_center) + plane_radius; //
xMin = creal(plane_center) - plane_radius*DisplayAspectRatio;
xMax = creal(plane_center) + plane_radius*DisplayAspectRatio;
/* Pixel sizes of the plane */
PixelWidth = (xMax - xMin) / ixMax; // ixMax = (iWidth-1) step between pixels in world coordinate
PixelHeight = (yMax - yMin) / iyMax;
iPixelSpacingBits = -log2( PixelWidth); //
eps = PixelWidth/1000.0; // to see detailes smaller then pixel
zoom = 1.0/plane_radius;
// for cabs2
ER2 = ER*ER;
ER2_DEM = ER_DEM*ER_DEM;
eps2 = eps*eps; // precision
iUnknown = 0; //
return 0;
}
// globa; setup = the same for all pixels
int setup()
{
fprintf (stderr, "setup start\n");
/* 2D array ranges */
iWidth = iHeight * DisplayAspectRatio;
iSize = iWidth * iHeight; // size = number of points in array
iyMax = iHeight - 1; // Indexes of array starts from 0 not 1 so the highest elements of an array is = array_name[size-1].
ixMax = iWidth - 1;
/* 1D array ranges */
// i1Dsize = i2Dsize; // 1D array with the same size as 2D array