#include "../Logger.hpp" #include #include #include #include #include #include #include #include "Raw.hpp" Raw::Raw (const unsigned int dimension, const unsigned int* sizes_): Canvas(dimension) { sizes = new unsigned int[dimension]; assert(sizes != NULL); std::copy(sizes_, sizes_ + dimension, sizes); sizesMultiplied = new unsigned int[dimension]; assert(sizesMultiplied != NULL); sizesMultiplied[0] = 1; for ( unsigned int i = 1; i < dimension; ++i ) { sizesMultiplied[i] = sizesMultiplied[i-1]*sizes[i-1]; } arraySize = std::accumulate(sizes, sizes + dimension, multiplies); pixelArray = new unsigned int[arraySize]; assert(pixelArray != NULL); clear(); LogDebug("New RawCanvas of dimension %d\n", dimension); } void Raw::clear() { std::fill_n(pixelArray, arraySize, 0); } void Raw::plot(double * position) { unsigned int index = 0; for ( unsigned int i = 0; i < dimension; ++i ) { index += (position[i]*sizes[i] + 0.5*sizes[i])*sizesMultiplied[i]; } if(index < arraySize) { int_array[index]++; } } /* I/O functions */ void Raw::output_file(const char * filename){ std::ofstream outfile (filename, std::ofstream::binary); outfile.write(reinterpret_cast(int_array), sizeof(unsigned int)*width*height*num_colors); }