Browse Source

some style issues and some line feeds

master
Joshua Moerman 14 years ago
parent
commit
d75712816e
  1. 40
      canvae/PNG.cpp
  2. 8
      canvae/PNG.hpp
  3. 14
      canvae/Raw.cpp
  4. 12
      canvae/Raw.hpp

40
canvae/PNG.cpp

@ -22,12 +22,12 @@ PNG::PNG(unsigned int width, unsigned int height, unsigned int num_colors):
} }
void PNG::clear() { void PNG::clear() {
for ( unsigned int i = 0; i < width*height*num_colors; i++ ) { for(unsigned int i = 0; i < width*height*num_colors; i++) {
int_array[i] = 0; int_array[i] = 0;
} }
} }
void PNG::plot(double * position) { void PNG::plot(double* position) {
const double& x = position[0]; const double& x = position[0];
const double& y = position[1]; const double& y = position[1];
@ -44,61 +44,61 @@ void PNG::plot(double * position) {
I/O functions I/O functions
*/ */
void PNG::output_file(const char * filename){ void PNG::output_file(const char* filename) {
unsigned int * max_int = new unsigned int[num_colors]; unsigned int* max_int = new unsigned int[num_colors];
double * power = new double[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; max_int[i] = 0;
double cumulative = 0; double cumulative = 0;
unsigned int n = 0; unsigned int n = 0;
for ( unsigned int j = 0; j < width*height; j++) { for(unsigned int j = 0; j < width*height; j++) {
if ( max_int[i] < int_array[j+i*width*height] ) { if(max_int[i] < int_array[j+i*width*height]) {
max_int[i] = int_array[j+i*width*height]; max_int[i] = int_array[j+i*width*height];
} }
if ( int_array[j+i*width*height] ) { if(int_array[j+i*width*height]) {
cumulative += int_array[j+i*width*height]; cumulative += int_array[j+i*width*height];
n++; n++;
} }
} }
if ( n > 100 ) { if(n > 100) {
const double average = cumulative / (double)n; const double average = cumulative / (double)n;
power[i] = -2.5/log(average/(double)max_int[i]); power[i] = -2.5/log(average/(double)max_int[i]);
if ( power[i] < 0 ) if(power[i] < 0)
power[i] = 1; power[i] = 1;
} else { } else {
power[i] = 1; power[i] = 1;
} }
if ( n <= 10 ) { if(n <= 10) {
LogInfo("not enough data\n"); LogInfo("not enough data\n");
} }
} }
const double vibrancy = 2.0; const double vibrancy = 2.0;
double averagePower = 0; double averagePower = 0;
for ( unsigned int i = 0; i < num_colors; i++ ) { for(unsigned int i = 0; i < num_colors; i++) {
averagePower += power[i]; averagePower += power[i];
} }
averagePower /= (double)num_colors; averagePower /= (double)num_colors;
for ( unsigned int i = 0; i < num_colors; i++ ) { for(unsigned int i = 0; i < num_colors; i++) {
power[i] = vibrancy*power[i] + (1.0 - vibrancy)*averagePower; power[i] = vibrancy*power[i] + (1.0 - vibrancy)*averagePower;
} }
pngwriter * pngFile = new pngwriter(width, height, 0.0, filename); pngwriter* pngFile = new pngwriter(width, height, 0.0, filename);
pngFile->setcompressionlevel(9); pngFile->setcompressionlevel(9);
pngFile->settext("Attractor", "Joshua Moerman", "A awesome attractor", "AwesomeAttractor"); pngFile->settext("Attractor", "Joshua Moerman", "A awesome attractor", "AwesomeAttractor");
for ( unsigned int x = 0; x < width; x++ ) { for(unsigned int x = 0; x < width; x++) {
for ( unsigned int y = 0; y < height; y++ ) { for(unsigned int y = 0; y < height; y++) {
double r = 0.0; double r = 0.0;
double g = 0.0; double g = 0.0;
double b = 0.0; double b = 0.0;
for ( unsigned int c = 0; c < num_colors; c++ ) { 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]; const double norm_value = (double)int_array[x + y*width + c*width*height]/max_int[c];
switch(c){ switch(c) {
case 0: { case 0: {
r = (pow(norm_value, power[c]))*3.5; r = (pow(norm_value, power[c]))*3.5;
break; break;
@ -127,7 +127,7 @@ void PNG::output_file(const char * filename){
LogInfo("Writing %s\n", filename); LogInfo("Writing %s\n", filename);
std::ofstream file(filename); std::ofstream file(filename);
if ( !file ) { if(!file) {
LogError("Couldn't write to file"); LogError("Couldn't write to file");
} }
pngFile->close(); pngFile->close();

8
canvae/PNG.hpp

@ -8,17 +8,17 @@ class PNG : public Canvas {
unsigned int height; unsigned int height;
unsigned int num_colors; unsigned int num_colors;
unsigned int * int_array; unsigned int* int_array;
public: public:
double v; double v;
PNG (unsigned int width, unsigned int height, unsigned int num_colors = 1); PNG(unsigned int width, unsigned int height, unsigned int num_colors = 1);
virtual void clear(); virtual void clear();
virtual void plot (const double * normalizedPosition); virtual void plot(const double* normalizedPosition);
virtual void output_file (const char * filename) const; virtual void output_file(const char* filename) const;
}; };

14
canvae/Raw.cpp

@ -10,7 +10,7 @@
#include "Raw.hpp" #include "Raw.hpp"
Raw::Raw (const unsigned int dimension, const unsigned int* sizes_): Raw::Raw(const unsigned int dimension, const unsigned int* sizes_):
Canvas(dimension) { Canvas(dimension) {
sizes = new unsigned int[dimension]; sizes = new unsigned int[dimension];
@ -20,12 +20,12 @@ Raw::Raw (const unsigned int dimension, const unsigned int* sizes_):
sizesMultiplied = new unsigned int[dimension]; sizesMultiplied = new unsigned int[dimension];
assert(sizesMultiplied != NULL); assert(sizesMultiplied != NULL);
sizesMultiplied[0] = 1; sizesMultiplied[0] = 1;
for ( unsigned int i = 1; i < dimension; ++i ) { for(unsigned int i = 1; i < dimension; ++i) {
sizesMultiplied[i] = sizesMultiplied[i-1]*sizes[i-1]; sizesMultiplied[i] = sizesMultiplied[i-1]*sizes[i-1];
} }
arraySize = 1; arraySize = 1;
for ( unsigned int i = 0; i < dimension; ++i ) { for(unsigned int i = 0; i < dimension; ++i) {
arraySize *= sizes[i]; arraySize *= sizes[i];
} }
pixelArray = new unsigned int[arraySize]; pixelArray = new unsigned int[arraySize];
@ -40,9 +40,9 @@ void Raw::clear() {
std::fill_n(pixelArray, arraySize, 0); std::fill_n(pixelArray, arraySize, 0);
} }
void Raw::plot(const double * position) { void Raw::plot(const double* position) {
unsigned int index = 0; unsigned int index = 0;
for ( unsigned int i = 0; i < dimension; ++i ) { for(unsigned int i = 0; i < dimension; ++i) {
index += (unsigned int)(position[i]*sizes[i] + 0.5*sizes[i])*sizesMultiplied[i]; index += (unsigned int)(position[i]*sizes[i] + 0.5*sizes[i])*sizesMultiplied[i];
} }
@ -55,7 +55,7 @@ void Raw::plot(const double * position) {
I/O functions I/O functions
*/ */
void Raw::output_file(const char * filename) const{ void Raw::output_file(const char* filename) const {
std::ofstream outfile (filename, std::ofstream::binary); std::ofstream outfile(filename, std::ofstream::binary);
outfile.write(reinterpret_cast<char*>(pixelArray), sizeof(unsigned int)*arraySize); outfile.write(reinterpret_cast<char*>(pixelArray), sizeof(unsigned int)*arraySize);
} }

12
canvae/Raw.hpp

@ -4,18 +4,18 @@
#include "../Canvas.hpp" #include "../Canvas.hpp"
class Raw : public Canvas { class Raw : public Canvas {
unsigned int * sizes; unsigned int* sizes;
unsigned int * sizesMultiplied; unsigned int* sizesMultiplied;
unsigned int * pixelArray; unsigned int* pixelArray;
unsigned int arraySize; unsigned int arraySize;
public: public:
Raw (const unsigned int dimension, const unsigned int* sizes); Raw(const unsigned int dimension, const unsigned int* sizes);
virtual void clear(); virtual void clear();
virtual void plot (const double * normalizedPosition); virtual void plot(const double* normalizedPosition);
virtual void output_file (const char * filename) const; virtual void output_file(const char* filename) const;
}; };