#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 = 1; for(unsigned int i = 0; i < dimension; ++i) { arraySize *= sizes[i]; } 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(const double* position) { unsigned int index = 0; for(unsigned int i = 0; i < dimension; ++i) { index += (unsigned int)(position[i]*sizes[i] + 0.5*sizes[i])*sizesMultiplied[i]; } if(index < arraySize) { pixelArray[index]++; } } /* I/O functions */ void Raw::output_file(const char* filename) const { std::ofstream outfile(filename, std::ofstream::binary); outfile.write(reinterpret_cast(pixelArray), sizeof(unsigned int)*arraySize); }