Browse Source

bugfix, extra check, colors and blur

master
Joshua Moerman 13 years ago
parent
commit
1884585a58
  1. 36
      Canvas.hpp
  2. 23
      Tonemapper.hpp
  3. 2
      batch.sh
  4. 11
      main.cpp

36
Canvas.hpp

@ -21,6 +21,7 @@
#include <vector> #include <vector>
#include <iterator> #include <iterator>
#include <array> #include <array>
#include <numeric>
template <typename T> template <typename T>
class Canvas2D { class Canvas2D {
@ -30,6 +31,7 @@ class Canvas2D {
public: public:
static constexpr size_t dimension = 2; static constexpr size_t dimension = 2;
static constexpr bool layered = false;
Canvas2D(size_t width, size_t height) Canvas2D(size_t width, size_t height)
: storage(height, Row(width, 0)) : storage(height, Row(width, 0))
@ -47,12 +49,11 @@ public:
const size_t width = size<0>(); const size_t width = size<0>();
const size_t height = size<1>(); const size_t height = size<1>();
const size_t c = 0.5*position[0]*width + width*.5; const int c = 0.5*position[0]*width + width*.5;
const size_t r = 0.5*position[1]*width + height*.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]++; storage[r][c]++;
}
} }
size_t size() const { size_t size() const {
@ -213,6 +214,7 @@ template <typename Canvas>
class LayeredCanvas { class LayeredCanvas {
public: public:
static constexpr size_t dimension = Canvas::dimension; static constexpr size_t dimension = Canvas::dimension;
static constexpr bool layered = true;
LayeredCanvas(size_t width, size_t height, size_t layers) LayeredCanvas(size_t width, size_t height, size_t layers)
: canvae(layers, Canvas(width, height)) : canvae(layers, Canvas(width, height))
@ -230,6 +232,10 @@ public:
return canvae.size(); return canvae.size();
} }
size_t size() const {
return canvae.front().size();
}
template <size_t N> template <size_t N>
size_t size() const { size_t size() const {
return canvae.front().size<N>(); return canvae.front().size<N>();
@ -243,4 +249,26 @@ private:
std::vector<Canvas> canvae; 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 #endif

23
Tonemapper.hpp

@ -79,21 +79,21 @@ namespace Tonemappers {
: gamma_correctors(n_planes) : gamma_correctors(n_planes)
, gammas() , gammas()
{ {
gammas[0].push_back(1.0); gammas[0].push_back(1.3);
gammas[1].push_back(3.0); gammas[1].push_back(2.0);
gammas[2].push_back(3.0); gammas[2].push_back(3.0);
gammas[0].push_back(3.0); gammas[0].push_back(3.0);
gammas[1].push_back(1.0); gammas[1].push_back(1.0);
gammas[2].push_back(1.0); gammas[2].push_back(1.0);
colors[0].push_back(3.0); colors[0].push_back(1.5);
colors[1].push_back(0.0);
colors[2].push_back(0.0);
colors[0].push_back(0.0);
colors[1].push_back(2.0); 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> template <typename C>
@ -120,9 +120,12 @@ namespace Tonemappers {
double get_value(T const & n, size_t color) const { double get_value(T const & n, size_t color) const {
double ret = 0.0; double ret = 0.0;
for (size_t i = 0; i < n.size(); ++i){ 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];
} }
return ret; if(std::isnormal(ret))
return ret;
else
return 0.0;
} }
std::vector<GammaCorrector> gamma_correctors; std::vector<GammaCorrector> gamma_correctors;
std::array<std::vector<double>, 3> gammas; std::array<std::vector<double>, 3> gammas;

2
batch.sh

@ -1,2 +1,2 @@
#!/bin/bash #!/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

@ -38,10 +38,14 @@ void render(Attractor & myAttractor, C & canvas, unsigned int iterations){
canvas.plot(myAttractor.projector->projectedPoint, 0); canvas.plot(myAttractor.projector->projectedPoint, 0);
double x = rand() / (double) RAND_MAX - 0.5; double x = rand() / (double) RAND_MAX - 0.5;
double y = 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); canvas.plot(blur, 1);
} }
progress.show(j, iterations); 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); render(my_attractor, canvas, iterations);
logger.stop(); logger.stop();
if(!filled(canvas, 0.05)){
logger.log("The canvas is too empty. Stopping.");
return 0;
}
std::string path(filename + ".stf"); std::string path(filename + ".stf");
std::ofstream file(path.c_str()); std::ofstream file(path.c_str());
file << my_attractor.stf_output() << std::endl; file << my_attractor.stf_output() << std::endl;