Skip to content

Commit e4e6056

Browse files
committed
added further output and set up the correct way to specify zoom out
1 parent 802dbb3 commit e4e6056

File tree

6 files changed

+66
-46
lines changed

6 files changed

+66
-46
lines changed

default.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
image_width = 1000
2-
image_height = 1000
2+
image_height = 1000
3+
frames = 1

src/bin/main.rs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
use std::time::Instant;
21
use rust_fractal::renderer::FractalRenderer;
32
use clap::{crate_version, crate_name, crate_authors, crate_description, App, Arg};
43
use config::{Config, File};
@@ -40,10 +39,6 @@ fn main() {
4039
};
4140

4241
let mut renderer = FractalRenderer::new(settings);
43-
44-
let time = Instant::now();
45-
46-
renderer.render("output/output".to_owned());
47-
// renderer.render_sequence(2.0);
48-
println!("{:<14}{:>6} ms", "TOTAL", time.elapsed().as_millis());
42+
// renderer.render("output/output".to_owned());
43+
renderer.render();
4944
}

src/math/perturbation.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ pub struct Perturbation {}
77

88
impl Perturbation {
99
pub fn iterate(pixel_data: &mut Vec<PixelData>, reference: &Reference, reference_current_iteration: usize) {
10-
pixel_data.par_chunks_mut(64)
10+
pixel_data.par_chunks_mut(8)
1111
.for_each(|pixel_data| {
1212
for pixel in pixel_data {
1313
let mut scaled_iterations = 0;

src/math/reference.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,7 @@ impl Reference {
3737

3838
// This is if we need to use the extended precision for the reference
3939
if z_fixed.re.abs() < 1e-300 && z_fixed.im.abs() < 1e-300 {
40-
// if true {
41-
println!("found slow at: {}", self.current_iteration);
40+
// println!("found slow at: {}", self.current_iteration);
4241
let mut temp = to_extended(&self.z);
4342
temp.reduce();
4443
self.data.push(

src/math/series_approximation.rs

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use crate::util::{ComplexArbitrary, to_extended, to_fixed};
1+
use crate::util::{ComplexArbitrary, to_extended};
22
use crate::util::complex_extended::ComplexExtended;
33
use crate::math::reference::Reference;
44
use rug::Float;
@@ -10,6 +10,7 @@ pub struct SeriesApproximation {
1010
maximum_iteration: usize,
1111
delta_pixel_square: FloatExtended,
1212
z: ComplexArbitrary,
13+
z_prev: ComplexArbitrary,
1314
c: ComplexArbitrary,
1415
pub order: usize,
1516
coefficients: Vec<ComplexExtended>,
@@ -34,6 +35,7 @@ impl SeriesApproximation {
3435
maximum_iteration,
3536
delta_pixel_square,
3637
z: c.clone(),
38+
z_prev: c.clone(),
3739
c,
3840
order,
3941
coefficients: coefficients.clone(),
@@ -65,16 +67,10 @@ impl SeriesApproximation {
6567

6668
// Can be changed later into a better loop - this function could also return some more information
6769
while self.current_iteration < self.maximum_iteration {
68-
let test = self.z.clone();
70+
self.z_prev = self.z.clone();
6971
self.z.square_mut();
7072
self.z += &self.c;
7173

72-
let z_fixed = to_fixed(&self.z);
73-
74-
if z_fixed.re.abs() < 1e-300 && z_fixed.im.abs() < 1e-300 {
75-
println!("found slow at: {}", self.current_iteration);
76-
}
77-
7874
self.next_coefficients[0] = to_extended(&self.z);
7975
self.next_coefficients[1] = self.coefficients[0] * self.coefficients[1] * 2.0 + add_value;
8076
self.next_coefficients[0].reduce();
@@ -129,7 +125,7 @@ impl SeriesApproximation {
129125

130126
// Check that the error over the derivative is less than the pixel spacing
131127
if relative_error / derivative > self.delta_pixel_square {
132-
self.z = test.clone();
128+
self.z = self.z_prev.clone();
133129
return;
134130
}
135131
}

src/renderer.rs

Lines changed: 55 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use crate::util::{data_export::*, ComplexFixed, ComplexArbitrary, PixelData, complex_extended::ComplexExtended, float_extended::FloatExtended, string_to_extended, extended_to_string};
2-
use crate::math::{SeriesApproximation, Perturbation};
2+
use crate::math::{SeriesApproximation, Perturbation, Reference};
33

44
use std::time::Instant;
55
use std::cmp::{min, max};
@@ -18,18 +18,27 @@ pub struct FractalRenderer {
1818
approximation_order: usize,
1919
glitch_tolerance: f64,
2020
data_export: DataExport,
21+
start_render_time: Instant,
22+
remaining_frames: usize,
23+
zoom_scale_factor: f64,
24+
center_reference: Reference,
2125
}
2226

2327
impl FractalRenderer {
2428
pub fn new(settings: Config) -> Self {
25-
let image_width = settings.get_int("image_width").unwrap() as usize;
26-
let image_height = settings.get_int("image_height").unwrap() as usize;
27-
let maximum_iteration = settings.get_int("iterations").unwrap() as usize;
28-
let initial_zoom = settings.get_str("zoom").unwrap();
29-
let center_real = settings.get_str("real").unwrap();
30-
let center_imag = settings.get_str("imag").unwrap();
31-
let approximation_order = 8;
32-
let glitch_tolerance = 0.01;
29+
// Print out the status information
30+
println!("{:<6}| {:<14}| {:<14}| {:<14}| {:<14}| {:<14}| {:<14}| {:<14}| {:<14}| {:<14}| {:<14}", "Frame", "Zoom", "Approx [ms]", "Skipped [it]", "Reference [ms]", "Packing [ms]", "Iteration [ms]", "Colouring [ms]", "Correct [ms]", "Saving [ms]", "TOTAL [ms]");
31+
32+
let image_width = settings.get_int("image_width").unwrap_or(1000) as usize;
33+
let image_height = settings.get_int("image_height").unwrap_or(1000) as usize;
34+
let maximum_iteration = settings.get_int("iterations").unwrap_or(1000) as usize;
35+
let initial_zoom = settings.get_str("zoom").unwrap_or("1E0".to_string());
36+
let center_real = settings.get_str("real").unwrap_or("-0.75".to_string());
37+
let center_imag = settings.get_str("imag").unwrap_or("0.0".to_string());
38+
let approximation_order = settings.get_int("approximation_order").unwrap_or(0) as usize;
39+
let glitch_tolerance = settings.get_float("glitch_tolerance").unwrap_or(0.01);
40+
let remaining_frames = settings.get_int("frames").unwrap_or(1) as usize;
41+
let zoom_scale_factor = settings.get_float("zoom_scale").unwrap_or(2.0);
3342
let display_glitches = false;
3443

3544
let aspect = image_width as f64 / image_height as f64;
@@ -56,23 +65,42 @@ impl FractalRenderer {
5665
image_height,
5766
aspect,
5867
zoom,
59-
center_location,
68+
center_location: center_location.clone(),
6069
maximum_iteration,
6170
approximation_order: auto_approximation,
6271
glitch_tolerance,
63-
data_export: DataExport::new(image_width, image_height, display_glitches, DataType::BOTH)
72+
data_export: DataExport::new(image_width, image_height, display_glitches, DataType::BOTH),
73+
start_render_time: Instant::now(),
74+
remaining_frames,
75+
zoom_scale_factor,
76+
center_reference: Reference::new(center_location.clone(), center_location, 1, maximum_iteration)
6477
}
6578
}
6679

67-
pub fn render(&mut self, filename: String) {
80+
pub fn render_frame(&mut self, index: usize, filename: String) {
81+
print!("{:<6}", index);
82+
let frame_time = Instant::now();
83+
84+
// If we are on the first frame
85+
// if index == 0 {
86+
// self.center_reference.run();
87+
// println!("{}", self.center_reference.current_iteration);
88+
// }
89+
90+
91+
92+
93+
94+
95+
6896
let delta_pixel = (-2.0 * (4.0 / self.image_height as f64 - 2.0) / self.zoom.mantissa) / self.image_height as f64;
6997

7098
// this should be the delta relative to the image, without the big zoom factor applied.
7199
let delta_top_left = ComplexFixed::new((4.0 / self.image_width as f64 - 2.0) / self.zoom.mantissa * self.aspect as f64, (4.0 / self.image_height as f64 - 2.0) / self.zoom.mantissa);
72100

73101
let time = Instant::now();
74102

75-
println!("{:<7}{:>16}", "Zoom", extended_to_string(self.zoom));
103+
print!("| {:<14}", extended_to_string(self.zoom));
76104

77105
let delta_pixel_extended = FloatExtended::new(delta_pixel, -self.zoom.exponent);
78106

@@ -88,15 +116,15 @@ impl FractalRenderer {
88116

89117
series_approximation.run();
90118

91-
println!("{:<14}{:>6} ms", "Approximation", time.elapsed().as_millis());
92-
println!("{:<10}{:>13} (order {})", "Skipped", series_approximation.current_iteration, series_approximation.order);
119+
print!("| {:<14}", time.elapsed().as_millis());
120+
print!("| {:<14}", series_approximation.current_iteration);
93121

94122
let time = Instant::now();
95123

96124
let mut reference = series_approximation.get_reference(ComplexExtended::new2(0.0, 0.0, 0));
97125
reference.run();
98126

99-
println!("{:<14}{:>6} ms (precision {}, iterations {})", "Reference", time.elapsed().as_millis(), self.center_location.prec().0, reference.current_iteration);
127+
print!("| {:<14}", time.elapsed().as_millis());
100128

101129
let time = Instant::now();
102130

@@ -122,15 +150,15 @@ impl FractalRenderer {
122150
}
123151
}).collect::<Vec<PixelData>>();
124152

125-
println!("{:<14}{:>6} ms", "Packing", time.elapsed().as_millis());
153+
print!("| {:<14}", time.elapsed().as_millis());
126154

127155
let time = Instant::now();
128156
Perturbation::iterate(&mut pixel_data, &reference, reference.current_iteration);
129-
println!("{:<14}{:>6} ms", "Iteration", time.elapsed().as_millis());
157+
print!("| {:<14}", time.elapsed().as_millis());
130158

131159
let time = Instant::now();
132160
self.data_export.export_pixels(&pixel_data, self.maximum_iteration, &reference);
133-
println!("{:<14}{:>6} ms", "Coloring", time.elapsed().as_millis());
161+
print!("| {:<14}", time.elapsed().as_millis());
134162

135163
let time = Instant::now();
136164

@@ -173,20 +201,21 @@ impl FractalRenderer {
173201
});
174202
}
175203

176-
println!("{:<14}{:>6} ms (remaining {})", "Fixing", time.elapsed().as_millis(), pixel_data.len());
204+
print!("| {:<14}", time.elapsed().as_millis());
177205

178206
let time = Instant::now();
179207
self.data_export.save(&filename);
180-
println!("{:<14}{:>6} ms", "Saving", time.elapsed().as_millis());
181-
return;
208+
print!("| {:<14}", time.elapsed().as_millis());
209+
println!("| {:<8} {:<8}", frame_time.elapsed().as_millis(), self.start_render_time.elapsed().as_millis());
182210
}
183211

184-
pub fn render_sequence(&mut self, scale_factor: f64) {
212+
pub fn render(&mut self) {
185213
let mut count = 0;
186-
while self.zoom.to_float() > 0.5 {
187-
self.render(format!("output/keyframe_{:08}", count));
188-
self.zoom.mantissa /= scale_factor;
214+
while self.remaining_frames > 0 && self.zoom.to_float() > 0.5 {
215+
self.render_frame(count, format!("output/keyframe_{:08}", count));
216+
self.zoom.mantissa /= self.zoom_scale_factor;
189217
self.zoom.reduce();
218+
self.remaining_frames -= 1;
190219
count += 1;
191220
}
192221
}

0 commit comments

Comments
 (0)