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.
58 lines
1.3 KiB
58 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 = std::accumulate(sizes, sizes + dimension, multiplies<unsigned int>);
|
|
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<char*>(int_array), sizeof(unsigned int)*width*height*num_colors);
|
|
}
|
|
|