diff --git a/Canvas.hpp b/Canvas.hpp index ac6d038..5b9f7ff 100644 --- a/Canvas.hpp +++ b/Canvas.hpp @@ -15,7 +15,7 @@ public: virtual ~Canvas() {}; virtual void clear() = 0; - virtual void plot(const double* normalizedPosition) = 0; + virtual void plot(const double* normalizedPosition, const double* normalizedColor) = 0; virtual void output_file(const char* filename) const = 0; }; diff --git a/Projector.hpp b/Projector.hpp index 6add515..6a0bf01 100644 --- a/Projector.hpp +++ b/Projector.hpp @@ -13,7 +13,7 @@ public: Canvas* canvas; Projector(unsigned int inputDimension, unsigned int outputDimension) : - canvas(0), projector(0), projectedPoint(0), + canvas(0), projector(0), projectedPoint(0), projectedColor(0), inputDimension(inputDimension), outputDimension(outputDimension), ready(true) { try { @@ -23,6 +23,7 @@ public: deallocate(); } std::fill_n(projectedPoint, outputDimension, 0.0); + std::fill_n(projectedColor, 1, 0.0); } virtual ~Projector() { @@ -34,12 +35,12 @@ public: if(ready) { if(canvas != NULL) { - canvas->plot(projectedPoint); + canvas->plot(projectedPoint, projectedColor); } - if(projector != NULL) { - projector->plot(projectedPoint); - } + /*if(projector != NULL) { + projector->plot(projectedPoint, projectedColor); + }*/ } } @@ -49,6 +50,7 @@ protected: Projector* projector; double* projectedPoint; + double* projectedColor; unsigned int inputDimension; unsigned int outputDimension; @@ -60,11 +62,14 @@ protected: private: void allocate() { projectedPoint = new double[outputDimension]; + projectedColor = new double[1]; } void deallocate() { delete[] projectedPoint; projectedPoint = NULL; + delete[] projectedColor; + projectedColor = NULL; } }; diff --git a/batch.sh b/batch.sh index d5ef7f2..3e5d0dd 100755 --- a/batch.sh +++ b/batch.sh @@ -1,2 +1,2 @@ #!/bin/bash -while true; do ./AwesomeAttractor -R -I 100 -W 1024 -H 1024 -v attractors/emptyUnravel3D.stf; done +while true; do ./AwesomeAttractor -P /var/www/render2/ -R -I 2000 -W 1024 -H 1024 -v attractors/emptyUnravel3D.stf; done diff --git a/canvae/PNG.hpp b/canvae/PNG.hpp index 3a56e38..a2e320f 100644 --- a/canvae/PNG.hpp +++ b/canvae/PNG.hpp @@ -4,6 +4,7 @@ #include #include #include +#include #include @@ -26,6 +27,7 @@ public: //int_array = std::make_shared>(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 power_matrix = {{ + 1.0, 1.5, + 2.0, 2.5, + 3.0, 1.5 + }}; + std::array 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); diff --git a/main.cpp b/main.cpp index 44bf13c..fc0c273 100644 --- a/main.cpp +++ b/main.cpp @@ -89,7 +89,7 @@ int main(int argc, char* argv[]) { } Attractor& myAttractor = *my_attractor_ptr; - myAttractor.projector->canvas = new PNG(width, height, 1); + myAttractor.projector->canvas = new PNG(width, height, 2); myAttractor.init_range(); LogInfo("\nRendering\n"); diff --git a/projectors/Normalizer.cpp b/projectors/Normalizer.cpp index b2155e5..6805af0 100644 --- a/projectors/Normalizer.cpp +++ b/projectors/Normalizer.cpp @@ -48,6 +48,7 @@ void Normalizer::project(const double* point) { for(unsigned int i = 0; i < inputDimension; ++i) { projectedPoint[i] = point[i]*factor + offset[i]; } + projectedColor[0] = sin(2.0 * point[2]); if(!ready) { static unsigned int state = 0;