some style issues and some line feeds
This commit is contained in:
parent
3d4e11ddea
commit
d75712816e
4 changed files with 53 additions and 53 deletions
|
@ -22,12 +22,12 @@ PNG::PNG(unsigned int width, unsigned int height, unsigned int num_colors):
|
|||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
void PNG::plot(double * position) {
|
||||
void PNG::plot(double* position) {
|
||||
const double& x = position[0];
|
||||
const double& y = position[1];
|
||||
|
||||
|
@ -44,61 +44,61 @@ void PNG::plot(double * position) {
|
|||
I/O functions
|
||||
*/
|
||||
|
||||
void PNG::output_file(const char * filename){
|
||||
unsigned int * max_int = new unsigned int[num_colors];
|
||||
double * power = new double[num_colors];
|
||||
void PNG::output_file(const char* filename) {
|
||||
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;
|
||||
|
||||
for ( unsigned int j = 0; j < width*height; j++) {
|
||||
if ( max_int[i] < int_array[j+i*width*height] ) {
|
||||
for(unsigned int j = 0; j < width*height; j++) {
|
||||
if(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];
|
||||
n++;
|
||||
}
|
||||
}
|
||||
|
||||
if ( n > 100 ) {
|
||||
if(n > 100) {
|
||||
const double average = cumulative / (double)n;
|
||||
power[i] = -2.5/log(average/(double)max_int[i]);
|
||||
if ( power[i] < 0 )
|
||||
if(power[i] < 0)
|
||||
power[i] = 1;
|
||||
} else {
|
||||
power[i] = 1;
|
||||
}
|
||||
|
||||
if ( n <= 10 ) {
|
||||
if(n <= 10) {
|
||||
LogInfo("not enough data\n");
|
||||
}
|
||||
}
|
||||
|
||||
const double vibrancy = 2.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 /= (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;
|
||||
}
|
||||
|
||||
pngwriter * pngFile = new pngwriter(width, height, 0.0, filename);
|
||||
pngwriter* pngFile = new pngwriter(width, height, 0.0, filename);
|
||||
pngFile->setcompressionlevel(9);
|
||||
pngFile->settext("Attractor", "Joshua Moerman", "A awesome attractor", "AwesomeAttractor");
|
||||
|
||||
for ( unsigned int x = 0; x < width; x++ ) {
|
||||
for ( unsigned int y = 0; y < height; y++ ) {
|
||||
for(unsigned int x = 0; x < width; x++) {
|
||||
for(unsigned int y = 0; y < height; y++) {
|
||||
double r = 0.0;
|
||||
double g = 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];
|
||||
switch(c){
|
||||
switch(c) {
|
||||
case 0: {
|
||||
r = (pow(norm_value, power[c]))*3.5;
|
||||
break;
|
||||
|
@ -127,7 +127,7 @@ void PNG::output_file(const char * filename){
|
|||
LogInfo("Writing %s\n", filename);
|
||||
|
||||
std::ofstream file(filename);
|
||||
if ( !file ) {
|
||||
if(!file) {
|
||||
LogError("Couldn't write to file");
|
||||
}
|
||||
pngFile->close();
|
||||
|
|
|
@ -8,17 +8,17 @@ class PNG : public Canvas {
|
|||
unsigned int height;
|
||||
unsigned int num_colors;
|
||||
|
||||
unsigned int * int_array;
|
||||
unsigned int* int_array;
|
||||
|
||||
public:
|
||||
|
||||
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 plot (const double * normalizedPosition);
|
||||
virtual void output_file (const char * filename) const;
|
||||
virtual void plot(const double* normalizedPosition);
|
||||
virtual void output_file(const char* filename) const;
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -10,7 +10,7 @@
|
|||
#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) {
|
||||
|
||||
sizes = new unsigned int[dimension];
|
||||
|
@ -20,12 +20,12 @@ Raw::Raw (const unsigned int dimension, const unsigned int* sizes_):
|
|||
sizesMultiplied = new unsigned int[dimension];
|
||||
assert(sizesMultiplied != NULL);
|
||||
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];
|
||||
}
|
||||
|
||||
arraySize = 1;
|
||||
for ( unsigned int i = 0; i < dimension; ++i ) {
|
||||
for(unsigned int i = 0; i < dimension; ++i) {
|
||||
arraySize *= sizes[i];
|
||||
}
|
||||
pixelArray = new unsigned int[arraySize];
|
||||
|
@ -40,9 +40,9 @@ void Raw::clear() {
|
|||
std::fill_n(pixelArray, arraySize, 0);
|
||||
}
|
||||
|
||||
void Raw::plot(const double * position) {
|
||||
void Raw::plot(const double* position) {
|
||||
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];
|
||||
}
|
||||
|
||||
|
@ -55,7 +55,7 @@ void Raw::plot(const double * position) {
|
|||
I/O functions
|
||||
*/
|
||||
|
||||
void Raw::output_file(const char * filename) const{
|
||||
std::ofstream outfile (filename, std::ofstream::binary);
|
||||
void Raw::output_file(const char* filename) const {
|
||||
std::ofstream outfile(filename, std::ofstream::binary);
|
||||
outfile.write(reinterpret_cast<char*>(pixelArray), sizeof(unsigned int)*arraySize);
|
||||
}
|
||||
|
|
|
@ -4,18 +4,18 @@
|
|||
#include "../Canvas.hpp"
|
||||
|
||||
class Raw : public Canvas {
|
||||
unsigned int * sizes;
|
||||
unsigned int * sizesMultiplied;
|
||||
unsigned int * pixelArray;
|
||||
unsigned int* sizes;
|
||||
unsigned int* sizesMultiplied;
|
||||
unsigned int* pixelArray;
|
||||
unsigned int arraySize;
|
||||
|
||||
public:
|
||||
|
||||
Raw (const unsigned int dimension, const unsigned int* sizes);
|
||||
Raw(const unsigned int dimension, const unsigned int* sizes);
|
||||
|
||||
virtual void clear();
|
||||
virtual void plot (const double * normalizedPosition);
|
||||
virtual void output_file (const char * filename) const;
|
||||
virtual void plot(const double* normalizedPosition);
|
||||
virtual void output_file(const char* filename) const;
|
||||
};
|
||||
|
||||
|
||||
|
|
Reference in a new issue