/
fractal.cpp
1169 lines (860 loc) · 29.5 KB
/
fractal.cpp
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
#include <math.h>
#include <syslog.h>
#include <qpainter.h>
#include <qmenubar.h>
#include <qstatusbar.h>
#include <qapplication.h>
#include <qfiledialog.h>
#include <qmessagebox.h>
#include <qpopupmenu.h>
#include <qcstring.h>
#include <qtextbrowser.h>
#include <qwhatsthis.h>
#include "fractal.h"
#include "mpi.h"
#include "helpwindow.h"
#include "computation.h"
const double zoomFactor = 0.25;
//the following values specify the minimum size of the image
//values smaller than these values will cause the image size to be too small
const int minImageWidth = 100;
const int minImageHeight = 100;
//the following values specify the maximum size of the image
//if the values fall beyond these range, then only part of the image will be displayed
const int maxImageWidth = 1016;
const int maxImageHeight = 605;
//the width, height, depth and number of color of the image
const int DefaultImageWidth = 500;
const int DefaultImageHeight = 500;
const int imageDepth = 32;
const int imageNumOfColors = 512;
// The values to be taken by the type of fractal selected
const int MANDEL_TYPE1 = 0;
const int MANDEL_TYPE2 = 1;
const int MANDEL_TYPE3 = 2;
const int MANDEL_TYPE4 = 3;
const int MANDEL_TYPE5 = 4;
const int JULIA_TYPE1 = 5;
const int JULIA_TYPE2 = 6;
const int JULIA_TYPE3 = 7;
const int JULIA_TYPE4 = 8;
const int JULIA_TYPE5 = 9;
/*const double JULIA1_CONS_X = -0.74;
const double JULIA1_CONS_Y = 0.1;*/
const double JULIA1_CONS_X = -0.835;
const double JULIA1_CONS_Y = -0.2321;
const double JULIA2_CONS_X = -1.25;
const double JULIA2_CONS_Y = 0;
const double JULIA3_CONS_X = -0.7543;
const double JULIA3_CONS_Y = 0.113;
/*const double JULIA4_CONS_X = -0.122561;
const double JULIA4_CONS_Y = 0.744862;*/
const double JULIA4_CONS_X = -0.70176;
const double JULIA4_CONS_Y = -0.3842;
/*const double JULIA5_CONS_X = 0.11;
const double JULIA5_CONS_Y = 0.66;*/
const double JULIA5_CONS_X = 0.285;
const double JULIA5_CONS_Y = 0.013;
int root = 0;
int my_rank;
int my_size;
int oneProcess;
int startProcess;
int endProcess;
int count;
int i , j;
int onePixel;
int theColor;
int A[ 816000 ];
int B[ 816000 ];
int counter = 0;
int theCounter = 0;
int indexSize;
int check = 0;
Fractal::Fractal(QWidget *parent , const char *name , int wFlags)
: MainForm(parent,name,wFlags)
{
Computation c;
// put the "What's This" button on the Help menu
Help->insertItem( "What's &This", this, SLOT(whatsThis()), SHIFT+Key_F1 );
// puts the "What's This" icon on the toolbar
QWhatsThis::whatsThisButton( fileToolBar );
// Find out process rank
MPI_Comm_rank (MPI_COMM_WORLD, &my_rank);
// Find out number of processes
MPI_Comm_size (MPI_COMM_WORLD, &my_size);
setImageWidth( DefaultImageWidth );
setImageHeight( DefaultImageHeight );
filename = QString::null;
m_filename = QString::null;
// get the height of the menu bar and the tool bar
menuToolHeight = MenuBar -> height() + fileToolBar -> height();
// get the height of the status bar
// statusHeight = statusBar() -> height();
// the following values are the top-left coordnate of the screen where the fractal
// is going to be displayed
topLeftX = 1;
topLeftY = menuToolHeight + 4;
// (x,y) is the top - left coordinate of the image to be displayed.
x = topLeftX;
y = topLeftY;
// (sx, sy) specifies the top-left point in pixmap that is to be drawn
// (0,0) is the default
sx = 0;
sy = 0;
// (sw, sh) specifies the size of the pixmap that is to be drawn
// The default, (-1, -1), means all the way to the bottom right of the pixmap
sw = -1;
sh = -1;
for (int i = 0; i < ColormapSize; ++i)
{
colormap[i] = c.rgbFromWaveLength(380.0 + (i * 400.0 / ColormapSize));
}
// getting the default values for minimum and maximum x and y
typeT = data.getType(); // the default fractal, mandelbrot or julia
minimumX = data.getMinX(); // Leftmost Real point
maximumX = data.getMaxX(); // Rightmost Real point of plane to be displayed
minimumY = data.getMinY(); // Lowermost Imaginary point
maximumY = data.getMaxY(); // Uppermost Imaginary point
resize(data.getWidth() , data.getHeight() + 87 );
// Create a QLabel to display normal & permanent messages
status = new QLabel( statusBar() );
status->setFrameStyle( QFrame::WinPanel | QFrame::Sunken );
status->setFixedHeight( fontMetrics().height() + 4 );
status->setFixedWidth( width() );
theMessage.sprintf( "Number of nodes = %d " , my_size );
status->setText( theMessage );
saveCount = 0;
QString defaultFileName = "Untitled.xml";
QString titleBar = QString( "Phr@X - A Parallel Fractal Explorer - [ %1 ]" ).arg( defaultFileName );
setCaption( titleBar );
} // constructor
/******************************************/
void Fractal::updateStatus( QString moremsg )
{
status->clear();
theMessage.sprintf("Number of nodes = %d " , my_size );
theMessage += moremsg;
status->setText( theMessage );
} // updateStatus( QString moremsg )
/******************************************/
void Fractal::setImageWidth( int w )
{
imageWidth = w;
} // setImageWidth()
/******************************************/
void Fractal::setImageHeight( int h )
{
imageHeight = h;
} // setImageWidth()
/******************************************/
int Fractal::getImageWidth()
{
return imageWidth;
} // getImageWidth
/******************************************/
int Fractal::getImageHeight()
{
return imageHeight;
} // getImageWidth
/******************************************/
void Fractal::resizeEvent( QResizeEvent * e )
{
/*setImageWidth( width() );
setImageHeight( height() - 80 );
render( data.getType() , data.getMinX() , data.getMaxX() , data.getMinY() , data.getMaxY() );*/
} // resizeEvent()
/******************************************/
void Fractal::save( QString f )
{
int theType;
double minx,maxx,miny,maxy;
int i;
theType = data.getType();
minx = data.getMinX();
maxx = data.getMaxX();
miny = data.getMinY();
maxy = data.getMaxY();
check = 0;
FILE *fpt;
fpt = fopen( f , "w" );
fprintf(fpt,"<fractal>");
fprintf(fpt,"\n <type>%d</type>", theType );
fprintf(fpt,"\n <x>");
fprintf(fpt,"\n <minx>%f</minx>",minx);
fprintf(fpt,"\n <maxx>%f</maxx>",maxx);
fprintf(fpt,"\n </x>");
fprintf(fpt,"\n <y>");
fprintf(fpt,"\n <miny>%f</miny>",miny);
fprintf(fpt,"\n <maxy>%f</maxy>",maxy);
fprintf(fpt,"\n </y>");
fprintf(fpt,"\n</fractal>");
fclose(fpt);
} // save()
/******************************************/
void Fractal::fileSave()
{
updateStatus("");
if( saveCount == 0 )
{
QString fileName = QFileDialog::getSaveFileName(
QString::null, "(*.xml)", this,
"file save as", "Fractal -- File Save" );
if ( !fileName.isEmpty() )
{
fileName.append(".xml");
// the caption that appears on the title bar
// fileName also includes the path of the file
QString titleBar = QString( "A Parallel Fractal Explorer - [ %1 ]" ).arg( fileName );
int answer = 0;
if ( QFile::exists( fileName ) )
answer = QMessageBox::warning(
this, "Fractal -- Overwrite File",
QString( "Overwrite\n\'%1\'?" ).
arg( fileName ),
"&Yes", "&No", QString::null, 1, -1 );
if ( answer == 0 )
{
m_filename = fileName;
// updateRecentFiles( filename );
save( m_filename );
setCaption( titleBar );
saveCount++;
return;
} // if
} // if
// statusBar()->message( "Saving abandoned", 2000 );
updateStatus( " | Saving abandonned" );
}
else
{
save( m_filename );
// updateStatus("Save");
}
} // save()
/******************************************/
void Fractal::fileSaveAs()
{
updateStatus("");
QString fileName = QFileDialog::getSaveFileName(
QString::null, "(*.xml)", this,
"file save as", "Fractal -- File Save As" );
// the caption that appears on the title bar
// fileName also includes the path of the file
QString titleBar = QString( "A Parallel Fractal Explorer - [ %1 ]" ).arg( fileName );
if ( !fileName.isEmpty() )
{
fileName.append(".xml");
int answer = 0;
if ( QFile::exists( fileName ) )
answer = QMessageBox::warning(
this, "Fractal -- Overwrite File",
QString( "Overwrite\n\'%1\'?" ).
arg( fileName ),
"&Yes", "&No", QString::null, 1, -1 );
if ( answer == 0 )
{
m_filename = fileName;
// updateRecentFiles( filename );
save( m_filename );
setCaption( titleBar );
return;
} // if
} // if
// statusBar()->message( "Saving abandoned", 2000 );
updateStatus(" | Saving abandonned");
} // fileSaveAs()
/******************************************/
void Fractal::fileOpen()
{
updateStatus("");
// displays only XML files in the dialog box
QString fn = QFileDialog::getOpenFileName( QString::null, "XML Files (*.xml)", this );
if ( !fn.isEmpty() )
load( fn );
else
updateStatus(" | Loading aborted");
// update();
} // fileOpen()
/******************************************/
void Fractal::load( QString fileName)
{
int t,h,w;
double miniX,maxiX,miniY,maxiY;
QFile xmlFile( fileName );
QXmlInputSource source( &xmlFile );
QXmlSimpleReader reader;
reader.setContentHandler( &handler );
reader.parse( source );
// set the minimum x & y and maximum x & y according to the values in the
// xml file
handler.setValues();
// once the values are set we get the values from the class
t = handler.getType();
// if the type isn't between 0 and 9 inclusive (suppose the user tried changing the parameter)
// the application will load the default fractaal
if( ( t != 0 ) && ( t != 1 ) && ( t != 2 ) && ( t != 3 ) && ( t != 4 ) && ( t != 5 ) && ( t != 6 ) && ( t != 7 ) && ( t != 8 ) && ( t != 9 ) )
{
static QMessageBox* error = new QMessageBox( "Error", "File has been modified with wrong parameters. \n" "The default fractal will be loaded instead." , QMessageBox::Information, 1, 0, 0, this, 0, FALSE );
error->setButtonText( 1, "Ok" );
error->show();
data.setDefaultData( MANDEL_TYPE1 );
mandel1Action->setOn( TRUE );
update();
render( data.getType() , data.getHeight() , data.getWidth() , data.getDefaultMinX() , data.getDefaultMaxX() , data.getDefaultMinY() , data.getDefaultMaxY() );
} // if
else
{
h = data.getHeight();
w = data.getWidth();
miniX = handler.getMinX();
maxiX = handler.getMaxX();
miniY = handler.getMinY();
maxiY = handler.getMaxY();
// according to the image we load (i.e. whether the image is mandelbrot or julia)
// we check the appropriate action in Fractal -> Select Fractal
if( t == MANDEL_TYPE1 )
mandel1Action->setOn( TRUE );
if( t == MANDEL_TYPE2)
mandel2Action->setOn( TRUE );
if( t == MANDEL_TYPE3)
mandel3Action->setOn( TRUE );
if( t == MANDEL_TYPE4)
mandel4Action->setOn( TRUE );
if( t == MANDEL_TYPE5)
mandel5Action->setOn( TRUE );
if( t == JULIA_TYPE1)
julia1Action->setOn( TRUE );
if( t == JULIA_TYPE2 )
julia2Action->setOn( TRUE );
if( t == JULIA_TYPE3 )
julia3Action->setOn( TRUE );
if( t == JULIA_TYPE4 )
julia4Action->setOn( TRUE );
if( t == JULIA_TYPE5 )
julia5Action->setOn( TRUE );
// now we set the data in the metadata class (the class which stores the minimum
// and maximum values of x & y)
data.setMetaData( t , h , w , miniX , maxiX , miniY , maxiY);
update();
render( t , h , w , miniX , maxiX , miniY , maxiY );
} // else
check = 0;
} // load()
/******************************************/
void Fractal::fileSaveJPEG()
{
updateStatus("");
const char* fmt = "JPEG";
QString savefilename = QFileDialog::getSaveFileName(QString::null, "JPEG Image (.jpeg)",
this, filename);
savefilename.append( ".jpeg" );
// saving a JPEG image with 75 % quality level
image.save( savefilename , "JPEG" , 75 );
if ( !savefilename.isEmpty() )
if ( !pixmap.save( savefilename, fmt ) )
QMessageBox::warning( this, "Save failed", "Error saving file" );
} // savePNG()
/******************************************/
void Fractal::fileSavePNG()
{
updateStatus("");
const char* fmt = "PNG";
QString savefilename = QFileDialog::getSaveFileName(QString::null, "PNG Image (.png)",
this, filename);
savefilename.append( ".png" );
// saving a PNG image with the default quality level i.e. 100 %
image.save( savefilename , "PNG" , -1 );
if ( !savefilename.isEmpty() )
if ( !pixmap.save( savefilename, fmt ) )
QMessageBox::warning( this, "Save failed", "Error saving file" );
} // savePNG()
/********************************************************************************************/
void Fractal::closeEvent( QCloseEvent * ce )
{
/* QApplication::exit(0);
MPI_Finalize();*/
double Coordinates[ 4 ];
int TypeDimension[ 4 ];
int root = 0;
int count = 4;
Coordinates[ 0 ] = Coordinates[ 1 ] = Coordinates[ 2 ] = Coordinates[ 3 ] = 0.1;
TypeDimension[ 0 ] = TypeDimension[ 1 ] = TypeDimension[ 2 ] = TypeDimension[ 3 ] = 1;
if(check == 1)
{
/* static QMessageBox* error = new QMessageBox( "Error", "File has been modified with wrong parameters. \n" "The default fractal will be loaded instead." , QMessageBox::Information, 1, 0, 0, this, 0, FALSE );*/
switch( QMessageBox::information( this, "Save Changes", // caption of message box
"Do you want to save the changes before exiting?", // text
"&Save", "&Discard", "Cancel", // the 3 buttons
0, 2 ) ) // 7th parameter is the default button. Here it is 0 i.e. the first button
// 8th parameter is the escape button. Here 2 means "Cancel"
{
case 0:
fileSave();
ce->accept();
MPI_Bcast( Coordinates , count , MPI_DOUBLE , root , MPI_COMM_WORLD );
MPI_Bcast( TypeDimension , 4 , MPI_INT , root , MPI_COMM_WORLD );
break;
case 1:
ce->accept();
MPI_Bcast( Coordinates , count , MPI_DOUBLE , root , MPI_COMM_WORLD );
MPI_Bcast( TypeDimension , 4 , MPI_INT , root , MPI_COMM_WORLD );
break;
case 2:
default: // just for sanity
ce->ignore();
break;
} // switch
}
else
{
ce->accept();
MPI_Bcast( Coordinates , count , MPI_DOUBLE , root , MPI_COMM_WORLD );
MPI_Bcast( TypeDimension , 4 , MPI_INT , root , MPI_COMM_WORLD );
}
syslog(LOG_DEBUG,"Closing Phr@X from master");
} // closeEvent( QCloseEvent * )
/********************************************************************************************/
void Fractal::selectType( QAction * action )
{
updateStatus("");
int theType = 0;
check = 0;
if( action == mandel1Action )
{
theType = MANDEL_TYPE1;
mandel1Action->setOn( TRUE );
} // if
if( action == mandel2Action )
{
theType = MANDEL_TYPE2;
mandel2Action->setOn( TRUE );
} // if
if( action == mandel3Action )
{
theType = MANDEL_TYPE3;
mandel3Action->setOn( TRUE );
} // if
if( action == mandel4Action )
{
theType = MANDEL_TYPE4;
mandel4Action->setOn( TRUE );
} // if
if( action == mandel5Action )
{
theType = MANDEL_TYPE5;
mandel5Action->setOn( TRUE );
} // if
if( action ==julia1Action )
{
theType = JULIA_TYPE1;
julia1Action->setOn( TRUE );
} // if
if( action ==julia2Action )
{
theType = JULIA_TYPE2;
julia2Action->setOn( TRUE );
} // if
if( action ==julia3Action )
{
theType = JULIA_TYPE3;
julia3Action->setOn( TRUE );
} // if
if( action ==julia4Action )
{
theType = JULIA_TYPE4;
julia4Action->setOn( TRUE );
} // if
if( action ==julia5Action )
{
theType = JULIA_TYPE5;
julia5Action->setOn( TRUE );
} // if
data.setDefaultData( theType );
render( data.getType() , data.getHeight() , data.getWidth() , data.getMinX() , data.getMaxX() , data.getMinY() , data.getMaxY() );
update();
} // selectType()
/******************************************/
/*
* At any point in time if the user wants to go back to the initial fractal,
*he just have to click the reset button
*/
void Fractal::fractalReset()
{
check = 0;
updateStatus("");
if( data.getType() == MANDEL_TYPE1 ) // if the fractal being zoomed is the mandelbrot set
{
data.setDefaultData( MANDEL_TYPE1 ); // set the type to mandelbrot
} // if
if( data.getType() == MANDEL_TYPE2 )
{
data.setDefaultData( MANDEL_TYPE2 );
} // if
if( data.getType() == MANDEL_TYPE3 )
{
data.setDefaultData( MANDEL_TYPE3 );
} // if
if( data.getType() == MANDEL_TYPE4 )
{
data.setDefaultData( MANDEL_TYPE4 );
} // if
if( data.getType() == MANDEL_TYPE5 )
{
data.setDefaultData( MANDEL_TYPE5 );
} // if
if( data.getType() == JULIA_TYPE1 ) // if julia set
{
data.setDefaultData( JULIA_TYPE1 );
} // if
if( data.getType() == JULIA_TYPE2 ) // if julia set
{
data.setDefaultData( JULIA_TYPE2 );
} // if
if( data.getType() == JULIA_TYPE3 ) // if julia set
{
data.setDefaultData( JULIA_TYPE3 );
} // if
if( data.getType() == JULIA_TYPE4 ) // if julia set
{
data.setDefaultData( JULIA_TYPE4 );
} // if
if( data.getType() == JULIA_TYPE5 ) // if julia set
{
data.setDefaultData( JULIA_TYPE5 );
} // if
// printf( "\ndefault minimum x = %f " , data.getDefaultMinX() );
// render the fractal with all the initial values
render( data.getType() , data.getHeight() , data.getWidth() , data.getDefaultMinX() , data.getDefaultMaxX() , data.getDefaultMinY() , data.getDefaultMaxY() );
update();
} // fractalReset()
/******************************************/
void Fractal::quickHelp()
{
updateStatus("");
static QMessageBox* about = new QMessageBox( "Phr@X Quick Help",
"<h3>How To Use Phr@X</h3>"
"<ul>"
"<li> To Zoom In, Left Click."
"<li> To Zoom Out, Right Click."
"</ul>", QMessageBox::Information, 1, 0, 0, this, 0, FALSE );
about->setButtonText( 1, "Ok" );
about->show();
} // quickHelp()
/******************************************/
void Fractal::about()
{
updateStatus("");
static QMessageBox* about = new QMessageBox( "Phr@X",
"<h3>About</h3>"
"<p>Copyright (C) 2005-2006 Imtiaz Ellaheebuksh and another student.<\p>"
"<p><b><i>Phr@X</i></b> is licensed to you under the terms of the GNU General Public License. See http://www.gnu.org/.</p>"
, QMessageBox::Information, 1, 0, 0, this, 0, FALSE );
about->setButtonText( 1, "Ok" );
about->show();
} // about()
/******************************************/
/*
* This function displays a help page that tells the user how to use Phr@X, and @ the same time it
* gives the new users an introduction to fractals
*/
void Fractal::aboutPhrax()
{
updateStatus("");
static QMessageBox* about = new QMessageBox( "Phr@X",
"<h3>About Phr@X</h3>"
"<p><b><i>Phr@X</i></b> is a free software to explore fractals using parallel processing.</p><p><b><i>Phr@X</i></b> has been developed using the Qt Toolkit. See http://www.trolltech.com for more information on Qt.</p>"
, QMessageBox::Information, 1, 0, 0, this, 0, FALSE );
about->setButtonText( 1, "Ok" );
about->show();
} // aboutPhrax()
/******************************************/
void Fractal::helpContents()
{
updateStatus("");
QString home = QDir( "./PhraX-Help/home.htm" ).absPath();
// QString home = QDir( "/usr/share/doc/doxygen-1.4.2/html/index.html" ).absPath();
HelpWindow *help = new HelpWindow(home, ".", 0, "help viewer");
help->showMaximized();
} // helpContents()
/******************************************/
void Fractal::paintEvent(QPaintEvent * e)
{
// provides a 2D drawable surface
QPainter painter( this );
// paint the rectangle black
painter.fillRect( rect() , Qt::black );
painter.drawPixmap( x , y , pixmap , sx , sy , sw , sh );
}
/******************************************/
void Fractal::mousePressEvent(QMouseEvent *event)
{
if (event->button() == Qt::LeftButton)
{
// get the mouse position
lastDragPosx = event->x();
lastDragPosy = event->y();
check = 1;
int typeT = data.getType();
double xxmin = data.getMinX();
double xxmax = data.getMaxX();
double yymin = data.getMinY();
double yymax = data.getMaxY();
double rangeX;
double rangeY;
double scaleX;
double scaleY;
double distanceMaxx;
double distanceMaxy;
double maxSectionX;
double maxSectionY;
double minSectionX;
double minSectionY;
// specify the distance between minimum x and maximum x
rangeX = xxmax - xxmin;
// specify the distance between minimum y and maximum y
rangeY = yymax - yymin;
// converting the screen coordinate (in pixels) to plane coordinate
double Zx = ( rangeX / data.getWidth() ) * lastDragPosx + xxmin;
double Zy = yymax - ( rangeY / data.getHeight() ) * lastDragPosy;
// decrease the range by the zoom factor
scaleX = zoomFactor * rangeX;
scaleY = zoomFactor * rangeY;
// distance between the mouse position (in plane coordinate) and maximum x
distanceMaxx = xxmax - Zx;
// distance between the mouse position (in plane coordinate) and maximum y
distanceMaxy = yymax - Zy;
maxSectionX = ( distanceMaxx / rangeX ) * scaleX;
maxSectionY = ( distanceMaxy / rangeY ) * scaleY;
minSectionX = scaleX - maxSectionX;
minSectionY = scaleY - maxSectionY;
xxmin = xxmin + minSectionX;
xxmax = xxmax - maxSectionX;
yymin = yymin + minSectionY;
yymax = yymax - maxSectionY;
int h = data.getHeight();
int w = data.getWidth();
data.setMetaData( typeT , h , w , xxmin,xxmax,yymin,yymax);
render(typeT , h , w , xxmin,xxmax,yymin,yymax);
updateStatus("");
/*
Plane view
xxmin xxmax
---------------------------------------------------------
| |
|<------- Zx ----------> <---- distanceMaxx ---------->|
|-----------------------/\------------------------------|
| | |
| | |
| mouse position |
| |
| |
| |
---------------------------------------------------------
<----------------------- rangeX------------------------->
yymin ----------------------------------------- /\
| /\ | |
| | | |
| Zy | |
| | | |
| \/ | |
| <------ mouse position | rangeY
| /\ | |
| | | |
| | | |
| distanceMaxY | |
| | | |
| | | |
| \/ | \/
yymax -----------------------------------------
*/
} // if zoom in
if (event->button() == Qt::RightButton)
{
// get the mouse position
lastDragPosx = event->x();
lastDragPosy = event->y();
check = 1;
int typeT = data.getType();
double xxmin = data.getMinX();
double xxmax = data.getMaxX();
double yymin = data.getMinY();
double yymax = data.getMaxY();
double rangeX;
double rangeY;
double scaleX;
double scaleY;
double distanceMaxx;
double distanceMaxy;
double maxSectionX;
double maxSectionY;
double minSectionX;
double minSectionY;
// specify the distance between minimum x and maximum x
rangeX = xxmax - xxmin;
// specify the distance between minimum y and maximum y
rangeY = yymax - yymin;
// converting the screen coordinate (in pixels) to plane coordinate
double Zx = ( rangeX / data.getWidth() ) * lastDragPosx + xxmin;
double Zy = yymax - ( rangeY / data.getHeight() ) * lastDragPosy;
// decrease the range by the zoom factor
scaleX = zoomFactor * rangeX;
scaleY = zoomFactor * rangeY;
// distance between the mouse position (in plane coordinate) and maximum x
distanceMaxx = xxmax - Zx;
// distance between the mouse position (in plane coordinate) and maximum y
distanceMaxy = yymax - Zy;
maxSectionX = ( distanceMaxx / rangeX ) * scaleX;
maxSectionY = ( distanceMaxy / rangeY ) * scaleY;
minSectionX = scaleX - maxSectionX;
minSectionY = scaleY - maxSectionY;
xxmin = xxmin - minSectionX;
xxmax = xxmax + maxSectionX;
yymin = yymin - minSectionY;
yymax = yymax + maxSectionY;
int h = data.getHeight();
int w = data.getWidth();
data.setMetaData( typeT , h , w , xxmin,xxmax,yymin,yymax);
render(typeT , h , w , xxmin,xxmax,yymin,yymax);
updateStatus("");
} // if zoom out
} // mousePressEvent()
/******************************************/
/*
uint Fractal::rgbFromWaveLength(double wave)
{
double r = 0.0;
double g = 0.0;
double b = 0.0;
if (wave >= 380.0 && wave <= 440.0) {
r = -1.0 * (wave - 440.0) / (440.0 - 380.0);
b = 1.0;
} else if (wave >= 440.0 && wave <= 490.0) {
g = (wave - 440.0) / (490.0 - 440.0);
b = 1.0;