|
|
@ -4,6 +4,7 @@ |
|
|
|
#include <memory> |
|
|
|
#include <vector> |
|
|
|
#include <cassert> |
|
|
|
#include <array> |
|
|
|
|
|
|
|
#include <png++/png.hpp> |
|
|
|
|
|
|
@ -26,6 +27,7 @@ public: |
|
|
|
|
|
|
|
//int_array = std::make_shared<vstd::vector<unsigned int>>(width*height*num_colors);
|
|
|
|
int_array = new unsigned int[width*height*num_colors]; |
|
|
|
LogInfo("PNG::PNG(): width: %d, height: %d, colors: %d\n", width, height, num_colors); |
|
|
|
|
|
|
|
assert(int_array != nullptr); |
|
|
|
|
|
|
@ -38,7 +40,7 @@ public: |
|
|
|
std::fill_n(int_array, width*height*num_colors, 0); |
|
|
|
} |
|
|
|
|
|
|
|
virtual void plot(const double* normalizedPosition) { |
|
|
|
virtual void plot(const double* normalizedPosition, const double* normalizedColor) { |
|
|
|
const double& x = normalizedPosition[0]; |
|
|
|
const double& y = normalizedPosition[1]; |
|
|
|
|
|
|
@ -47,7 +49,11 @@ public: |
|
|
|
const unsigned int index = x_int + width * y_int; |
|
|
|
|
|
|
|
if(x_int < width && y_int < height) { |
|
|
|
int_array[index]++; |
|
|
|
if(normalizedColor[0] > 0.0){ |
|
|
|
int_array[index]++; |
|
|
|
} else { |
|
|
|
int_array[index + width*height]++; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
@ -57,7 +63,7 @@ public: |
|
|
|
unsigned int* max_int = new unsigned int[num_colors]; |
|
|
|
double* power = new double[num_colors]; |
|
|
|
|
|
|
|
for(unsigned int i = 0; i < num_colors; i++) { |
|
|
|
for(unsigned int i = 0; i < num_colors; ++i) { |
|
|
|
max_int[i] = 0; |
|
|
|
double cumulative = 0; |
|
|
|
unsigned int n = 0; |
|
|
@ -80,9 +86,8 @@ public: |
|
|
|
LogInfo("negative power\n"); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if(n < width) { |
|
|
|
LogInfo("not enough data\n"); |
|
|
|
LogInfo("not enough data in dimension %d\n", i); |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
@ -102,6 +107,16 @@ public: |
|
|
|
// pngFile->settext("Attractor", "Joshua Moerman", "A awesome attractor", "AwesomeAttractor");
|
|
|
|
|
|
|
|
png::image< png::rgb_pixel > image(width, height); |
|
|
|
std::array<double, 6> power_matrix = {{ |
|
|
|
1.0, 1.5, |
|
|
|
2.0, 2.5, |
|
|
|
3.0, 1.5 |
|
|
|
}}; |
|
|
|
std::array<double, 6> output_matrix = {{ |
|
|
|
2.0, 2.0, |
|
|
|
2.0, 1.5, |
|
|
|
2.0, 2.0 |
|
|
|
}}; |
|
|
|
|
|
|
|
for(unsigned int x = 0; x < width; x++) { |
|
|
|
for(unsigned int y = 0; y < height; y++) { |
|
|
@ -110,22 +125,9 @@ public: |
|
|
|
double b = 0.0; |
|
|
|
for(unsigned int c = 0; c < num_colors; c++) { |
|
|
|
const double norm_value = (double)int_array[x + y*width + c*width*height]/max_int[c]; |
|
|
|
switch(c) { |
|
|
|
case 0: { |
|
|
|
r = (pow(norm_value, power[c]))*3.0; |
|
|
|
//break;
|
|
|
|
} |
|
|
|
case 1: { |
|
|
|
g = (pow(norm_value, power[c]*2.0))*3.0; |
|
|
|
//break;
|
|
|
|
} |
|
|
|
case 2: { |
|
|
|
b = (pow(norm_value, power[c]*3.0))*3.0; |
|
|
|
//break;
|
|
|
|
} |
|
|
|
default: |
|
|
|
break; |
|
|
|
} |
|
|
|
r += (pow(norm_value, power[c]*power_matrix[c+0]))*output_matrix[c+0]; |
|
|
|
g += (pow(norm_value, power[c]*power_matrix[c+2]))*output_matrix[c+2]; |
|
|
|
b += (pow(norm_value, power[c]*power_matrix[c+4]))*output_matrix[c+4]; |
|
|
|
} |
|
|
|
// TODO: also clamp is below 0 ?
|
|
|
|
r = std::min(1.0, r); |
|
|
|