Browse Source

hacked colors in, just for fnu

master
Joshua Moerman 13 years ago
parent
commit
ce9950b0b3
  1. 2
      Canvas.hpp
  2. 15
      Projector.hpp
  3. 2
      batch.sh
  4. 44
      canvae/PNG.hpp
  5. 2
      main.cpp
  6. 1
      projectors/Normalizer.cpp

2
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;
};

15
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;
}
};

2
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

44
canvae/PNG.hpp

@ -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);

2
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");

1
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;