Commit c2b2904e authored by plgruener's avatar plgruener

add threshold parameter

parent c9e8835f
#include "compute.hpp" #include "compute.hpp"
float compute(float alpha, float beta, aligned_vector<float> seed_x, float compute(float alpha, float beta, aligned_vector<float> seed_x,
aligned_vector<float> seed_y, int num_iterations) { aligned_vector<float> seed_y, int num_iterations, float threshold) {
int num_seeds = seed_x.size(); int num_seeds = seed_x.size();
assert(seed_y.size() == num_seeds); assert(seed_y.size() == num_seeds);
...@@ -13,7 +13,7 @@ float compute(float alpha, float beta, aligned_vector<float> seed_x, ...@@ -13,7 +13,7 @@ float compute(float alpha, float beta, aligned_vector<float> seed_x,
float d = 0.0; float d = 0.0;
for (int i = 0; i < num_iterations && d < 1; i++) { for (int i = 0; i < num_iterations && d < threshold ; i++) {
#pragma omp simd aligned(xp, yp : 64) #pragma omp simd aligned(xp, yp : 64)
for (int s = 0; s < num_seeds; s++) { for (int s = 0; s < num_seeds; s++) {
yp[s] = yp[s] + beta * std::sin(TWO_PI * xp[s]); yp[s] = yp[s] + beta * std::sin(TWO_PI * xp[s]);
......
...@@ -14,5 +14,5 @@ constexpr float PI = 3.141592635; ...@@ -14,5 +14,5 @@ constexpr float PI = 3.141592635;
constexpr float TWO_PI = 6.28318530718; // 2 * PI; constexpr float TWO_PI = 6.28318530718; // 2 * PI;
float compute(float alpha, float beta, aligned_vector<float> seed_x, float compute(float alpha, float beta, aligned_vector<float> seed_x,
aligned_vector<float> seed_y, int num_iterations); aligned_vector<float> seed_y, int num_iterations, float threshold);
#endif #endif
...@@ -19,6 +19,7 @@ int main(int argc, char* argv[]) { ...@@ -19,6 +19,7 @@ int main(int argc, char* argv[]) {
// get arguments from CLI // get arguments from CLI
// these can be input by user // these can be input by user
int num_iterations; int num_iterations;
float threshold;
float alphamin; float alphamin;
float alphamax; float alphamax;
int alpha_num_intervals; int alpha_num_intervals;
...@@ -32,6 +33,7 @@ int main(int argc, char* argv[]) { ...@@ -32,6 +33,7 @@ int main(int argc, char* argv[]) {
desc.add_options() desc.add_options()
("help", "Help message") ("help", "Help message")
("iterations,n", po::value<int>(&num_iterations)->default_value(100), "Number of iterations") ("iterations,n", po::value<int>(&num_iterations)->default_value(100), "Number of iterations")
("threshold,s", po::value<float>(&threshold)->default_value(1), " Threshold above that computation is stopped")
("amin,a", po::value<float>(&alphamin)->default_value(0), " α lower bound") ("amin,a", po::value<float>(&alphamin)->default_value(0), " α lower bound")
("amax,A", po::value<float>(&alphamax)->default_value(1), " α upper bound") ("amax,A", po::value<float>(&alphamax)->default_value(1), " α upper bound")
("alphas,w", po::value<int>(&alpha_num_intervals)->default_value(100), "α resolution/width of image") ("alphas,w", po::value<int>(&alpha_num_intervals)->default_value(100), "α resolution/width of image")
...@@ -114,15 +116,15 @@ int main(int argc, char* argv[]) { ...@@ -114,15 +116,15 @@ int main(int argc, char* argv[]) {
// transform floats into grayscale-colors: // transform floats into grayscale-colors:
for (int i = 0; i < alpha_num_params*beta_num_params; ++i) { for (int i = 0; i < alpha_num_params*beta_num_params; ++i) {
if (buffer[i] > 1) { if (result[i] > threshold) {
colors[i] = 255; colors[i] = 255;
colors_rgb[3*i] = 255; colors_rgb[3*i] = 255;
colors_rgb[3*i+1] = 255; colors_rgb[3*i+1] = 255;
colors_rgb[3*i+2] = 255; colors_rgb[3*i+2] = 255;
} else { } else {
colors[i] = (int) 254 * buffer[i]; colors[i] = (int) 254 * result[i]/threshold;
// RGB color gradient: viridis from matplotlib // RGB color gradient: viridis from matplotlib
int idx = floor(buffer[i]*255); int idx = floor(255*result[i]/threshold);
int r = floor(255*viridis[idx][0]); int r = floor(255*viridis[idx][0]);
int g = floor(255*viridis[idx][1]); int g = floor(255*viridis[idx][1]);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment