You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
61 lines
1.3 KiB
61 lines
1.3 KiB
#include "../Logger.hpp"
|
|
#include <fstream>
|
|
#include <cmath>
|
|
#include <cstdlib>
|
|
#include <cassert>
|
|
#include <algorithm>
|
|
#include <numeric>
|
|
#include <functional>
|
|
|
|
#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<char*>(pixelArray), sizeof(unsigned int)*arraySize);
|
|
}
|
|
|