-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMandelConfig.cpp
More file actions
120 lines (93 loc) · 2.47 KB
/
MandelConfig.cpp
File metadata and controls
120 lines (93 loc) · 2.47 KB
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
//
// Created by finea on 8/8/2017.
//
#include "MandelConfig.h"
#include <fstream>
#include <iostream>
unsigned int MandelConfig::getWidth() const
{
return width;
}
unsigned int MandelConfig::getHeight() const
{
return height;
}
double MandelConfig::getXComplexMin() const
{
return xComplexMin;
}
double MandelConfig::getXComplexMax() const
{
return xComplexMax;
}
double MandelConfig::getYComplexMin() const
{
return yComplexMin;
}
double MandelConfig::getYComplexMax() const
{
return yComplexMax;
}
unsigned int MandelConfig::getMaxIterations() const
{
return maxIterations;
}
const std::string& MandelConfig::getFileName() const
{
return fileName;
}
MandelConfig::MandelConfig() :
width( 512 ), height( 512 ),
xComplexMin( -2.0 ), xComplexMax( 0.5 ),
yComplexMin( -1.25 ), yComplexMax( 1.25 ),
maxIterations( 80 ), fileName( "output.ppm" )
{
// Empty
}
MandelConfig::MandelConfig( std::string& filename ) :
width( 0 ), height( 0 ),
xComplexMin( 0.0 ), xComplexMax( 0.0 ),
yComplexMin( 0.0 ), yComplexMax( 0.0 ),
maxIterations( 1 ), fileName( "" )
{
readConfigFile( filename );
validate();
}
MandelConfig::MandelConfig( unsigned int width, unsigned int height,
double xmin, double xmax,
double ymin, double ymax,
unsigned int iterations,
std::string& filename ) :
width( width ), height( height ),
xComplexMin( xmin ), xComplexMax( xmax ),
yComplexMin( ymin ), yComplexMax( ymax ),
maxIterations( iterations ), fileName( filename )
{
validate();
}
void MandelConfig::readConfigFile( std::string& inputFileName )
{
std::ifstream fin( inputFileName );
if ( !fin )
{
std::cout << "Cannot read from file. Exiting now.\n";
exit( EXIT_FAILURE );
}
fin >> width >> height;
fin >> xComplexMin >> xComplexMax;
fin >> yComplexMin >> yComplexMax;
fin >> maxIterations;
fin >> fileName;
fin.close();
}
void MandelConfig::validate()
{
if ( width < 1 ) width = 1;
if ( height < 1 ) height = 1;
if ( xComplexMin < -2.0 ) xComplexMin = -2.0;
if ( xComplexMax > 0.5 ) xComplexMax = 0.5;
if ( yComplexMin < -1.25 ) yComplexMax = -1.25;
if ( yComplexMax > 1.25 ) yComplexMax = 1.25;
if ( maxIterations < 1 ) maxIterations = 1;
if ( fileName.empty()) fileName = "output.ppm";
}