bugfix, extra check, colors and blur
This commit is contained in:
parent
7d46a96a05
commit
1884585a58
4 changed files with 56 additions and 16 deletions
36
Canvas.hpp
36
Canvas.hpp
|
@ -21,6 +21,7 @@
|
|||
#include <vector>
|
||||
#include <iterator>
|
||||
#include <array>
|
||||
#include <numeric>
|
||||
|
||||
template <typename T>
|
||||
class Canvas2D {
|
||||
|
@ -30,6 +31,7 @@ class Canvas2D {
|
|||
|
||||
public:
|
||||
static constexpr size_t dimension = 2;
|
||||
static constexpr bool layered = false;
|
||||
|
||||
Canvas2D(size_t width, size_t height)
|
||||
: storage(height, Row(width, 0))
|
||||
|
@ -47,13 +49,12 @@ public:
|
|||
const size_t width = size<0>();
|
||||
const size_t height = size<1>();
|
||||
|
||||
const size_t c = 0.5*position[0]*width + width*.5;
|
||||
const size_t r = 0.5*position[1]*width + height*.5;
|
||||
const int c = 0.5*position[0]*width + width*.5;
|
||||
const int r = 0.5*position[1]*width + height*.5;
|
||||
|
||||
if(c < width && r < height) {
|
||||
if(0 <= c && c < width && 0 <= r && r < height)
|
||||
storage[r][c]++;
|
||||
}
|
||||
}
|
||||
|
||||
size_t size() const {
|
||||
return size<0>() * size<1>();
|
||||
|
@ -213,6 +214,7 @@ template <typename Canvas>
|
|||
class LayeredCanvas {
|
||||
public:
|
||||
static constexpr size_t dimension = Canvas::dimension;
|
||||
static constexpr bool layered = true;
|
||||
|
||||
LayeredCanvas(size_t width, size_t height, size_t layers)
|
||||
: canvae(layers, Canvas(width, height))
|
||||
|
@ -230,6 +232,10 @@ public:
|
|||
return canvae.size();
|
||||
}
|
||||
|
||||
size_t size() const {
|
||||
return canvae.front().size();
|
||||
}
|
||||
|
||||
template <size_t N>
|
||||
size_t size() const {
|
||||
return canvae.front().size<N>();
|
||||
|
@ -243,4 +249,26 @@ private:
|
|||
std::vector<Canvas> canvae;
|
||||
};
|
||||
|
||||
template <typename C>
|
||||
typename std::enable_if<!C::layered, bool>::type filled(C const & canvas, double threshold) {
|
||||
struct functor {
|
||||
size_t operator()(size_t x, size_t y){
|
||||
if(y > 0) return ++x;
|
||||
else return x;
|
||||
}
|
||||
} f;
|
||||
size_t nonempty_pixels = std::accumulate(canvas.begin(), canvas.end(), 0ul, f);
|
||||
return nonempty_pixels > threshold * canvas.size();
|
||||
}
|
||||
|
||||
template <typename C>
|
||||
typename std::enable_if<C::layered, bool>::type filled(C const & canvas, double threshold) {
|
||||
for (unsigned int l = 0; l < canvas.layers(); ++l) {
|
||||
if (!filled(canvas[l], threshold)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
@ -79,21 +79,21 @@ namespace Tonemappers {
|
|||
: gamma_correctors(n_planes)
|
||||
, gammas()
|
||||
{
|
||||
gammas[0].push_back(1.0);
|
||||
gammas[1].push_back(3.0);
|
||||
gammas[0].push_back(1.3);
|
||||
gammas[1].push_back(2.0);
|
||||
gammas[2].push_back(3.0);
|
||||
|
||||
gammas[0].push_back(3.0);
|
||||
gammas[1].push_back(1.0);
|
||||
gammas[2].push_back(1.0);
|
||||
|
||||
colors[0].push_back(3.0);
|
||||
colors[1].push_back(0.0);
|
||||
colors[2].push_back(0.0);
|
||||
|
||||
colors[0].push_back(0.0);
|
||||
colors[0].push_back(1.5);
|
||||
colors[1].push_back(2.0);
|
||||
colors[2].push_back(3.0);
|
||||
colors[2].push_back(1.0);
|
||||
|
||||
colors[0].push_back(-1.0);
|
||||
colors[1].push_back(-0.5);
|
||||
colors[2].push_back(0.7);
|
||||
}
|
||||
|
||||
template <typename C>
|
||||
|
@ -120,9 +120,12 @@ namespace Tonemappers {
|
|||
double get_value(T const & n, size_t color) const {
|
||||
double ret = 0.0;
|
||||
for (size_t i = 0; i < n.size(); ++i){
|
||||
ret += gamma_correctors[color].get_value(n[i], gammas[color][i]) * colors[color][i];
|
||||
ret += gamma_correctors[i].get_value(n[i], gammas[color][i]) * colors[color][i];
|
||||
}
|
||||
if(std::isnormal(ret))
|
||||
return ret;
|
||||
else
|
||||
return 0.0;
|
||||
}
|
||||
std::vector<GammaCorrector> gamma_correctors;
|
||||
std::array<std::vector<double>, 3> gammas;
|
||||
|
|
2
batch.sh
2
batch.sh
|
@ -1,2 +1,2 @@
|
|||
#!/bin/bash
|
||||
while true; do ./build/Debug/AwesomeAttract0r -P ./render/ -I 20 -W 1280 -H 800 -f attractors/emptyUnravel3D.stf; done
|
||||
while true; do ./build/Release\ with\ Symbols/AwesomeAttract0r -P ./render/ -I 50 -W 1280 -H 800 -f attractors/emptyUnravel3D.stf; done
|
||||
|
|
11
main.cpp
11
main.cpp
|
@ -38,10 +38,14 @@ void render(Attractor & myAttractor, C & canvas, unsigned int iterations){
|
|||
canvas.plot(myAttractor.projector->projectedPoint, 0);
|
||||
double x = rand() / (double) RAND_MAX - 0.5;
|
||||
double y = rand() / (double) RAND_MAX - 0.5;
|
||||
double blur[2] = {myAttractor.projector->projectedPoint[0] + x*0.02, myAttractor.projector->projectedPoint[1] + y*0.02};
|
||||
x *= x*x;
|
||||
y *= y*y;
|
||||
double blur[2] = {myAttractor.projector->projectedPoint[0] + x*0.3, myAttractor.projector->projectedPoint[1] + y*0.3};
|
||||
canvas.plot(blur, 1);
|
||||
}
|
||||
progress.show(j, iterations);
|
||||
if(j == iterations/3) if(!filled(canvas, 0.01)) return;
|
||||
if(j == iterations/3 * 2) if(!filled(canvas, 0.02)) return;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -82,6 +86,11 @@ int main(int argc, char* argv[]) try {
|
|||
render(my_attractor, canvas, iterations);
|
||||
logger.stop();
|
||||
|
||||
if(!filled(canvas, 0.05)){
|
||||
logger.log("The canvas is too empty. Stopping.");
|
||||
return 0;
|
||||
}
|
||||
|
||||
std::string path(filename + ".stf");
|
||||
std::ofstream file(path.c_str());
|
||||
file << my_attractor.stf_output() << std::endl;
|
||||
|
|
Reference in a new issue