Small source code improvements

This commit is contained in:
Michaël Lemaire 2015-12-16 00:31:07 +01:00
parent aecd3dcdf3
commit c5d73f96a2
8 changed files with 38 additions and 19 deletions

View file

@ -9,6 +9,9 @@ InfiniteCylinder::InfiniteCylinder(const InfiniteRay &axis, double radius) : axi
validate();
}
InfiniteCylinder::~InfiniteCylinder() {
}
int InfiniteCylinder::findRayIntersection(const InfiniteRay &ray, Vector3 *first_intersection,
Vector3 *second_intersection) const {
/*

View file

@ -15,6 +15,7 @@ class BASICSSHARED_EXPORT InfiniteCylinder {
public:
InfiniteCylinder() = default;
InfiniteCylinder(const InfiniteRay &axis, double radius);
virtual ~InfiniteCylinder();
inline const InfiniteRay &getAxis() const {
return axis;

View file

@ -25,7 +25,6 @@ class OpenGLVegetationLayer;
class OpenGLVegetationInstance;
class OpenGLVegetationImpostor;
class OpenGLTerrainChunk;
template <typename Vertex> class VertexArray;
}
}
using namespace paysages::opengl;

View file

@ -1,5 +1,7 @@
#include "GodRaysSampler.h"
#include <cmath>
#include <algorithm>
#include "GodRaysDefinition.h"
#include "AtmosphereDefinition.h"
#include "SoftwareRenderer.h"
@ -13,7 +15,6 @@
#include "TerrainDefinition.h"
#include "CloudsRenderer.h"
#include "Interpolation.h"
#include <cmath>
GodRaysSampler::GodRaysSampler() {
enabled = true;
@ -48,16 +49,14 @@ void GodRaysSampler::prepare(SoftwareRenderer *renderer) {
void GodRaysSampler::reset() {
*bounds = SpaceSegment(Vector3(camera_location->x - max_length, low_altitude, camera_location->z - max_length),
Vector3(camera_location->x + max_length, high_altitude, camera_location->z + max_length));
samples_x = round(bounds->getXDiff() / sampling_step) + 1;
samples_y = round(bounds->getYDiff() / sampling_step) + 1;
samples_z = round(bounds->getZDiff() / sampling_step) + 1;
samples_x = round_to_int(bounds->getXDiff() / sampling_step) + 1;
samples_y = round_to_int(bounds->getYDiff() / sampling_step) + 1;
samples_z = round_to_int(bounds->getZDiff() / sampling_step) + 1;
long n = samples_x * samples_y * samples_z;
auto n = to_size(samples_x * samples_y * samples_z);
delete[] data;
data = new double[n];
for (long i = 0; i < n; i++) {
data[i] = -1.0;
}
fill_n(data, n, -1.0);
}
void GodRaysSampler::setEnabled(bool enabled) {
@ -110,9 +109,9 @@ double GodRaysSampler::getCachedLight(const Vector3 &location) {
double y = location.y - bounds->getStart().y;
double z = location.z - bounds->getStart().z;
int ix = (int)floor(x / sampling_step);
int iy = (int)floor(y / sampling_step);
int iz = (int)floor(z / sampling_step);
int ix = floor_to_int(x / sampling_step);
int iy = floor_to_int(y / sampling_step);
int iz = floor_to_int(z / sampling_step);
// Check cache limits
if (ix < 0 || ix >= samples_x - 1 || iy < 0 || iy >= samples_y - 1 || iz < 0 || iz >= samples_z - 1) {
@ -171,8 +170,8 @@ inline double GodRaysSampler::getCache(int x, int y, int z) {
double *cache = data + z * samples_x * samples_y + y * samples_x + x;
if (*cache < 0.0) {
Vector3 location =
Vector3(bounds->getStart().x + sampling_step * (double)x, bounds->getStart().y + sampling_step * (double)y,
bounds->getStart().z + sampling_step * (double)z);
Vector3(bounds->getStart().x + sampling_step * to_double(x), bounds->getStart().y + sampling_step * to_double(y),
bounds->getStart().z + sampling_step * to_double(z));
double unfiltered_power = getRawLight(location, false).getPower();
if (unfiltered_power == 0.0) {
*cache = 1.0;

View file

@ -2,7 +2,8 @@
#define MUTEX_H
#include "system_global.h"
#include <QMutex>
#include <mutex>
namespace paysages {
namespace system {
@ -10,7 +11,7 @@ namespace system {
/*!
* \brief System mutex
*/
class SYSTEMSHARED_EXPORT Mutex : private QMutex {
class SYSTEMSHARED_EXPORT Mutex : private mutex {
public:
/*!
* \brief Create a new mutex
@ -18,10 +19,10 @@ class SYSTEMSHARED_EXPORT Mutex : private QMutex {
Mutex();
inline void acquire() {
QMutex::lock();
mutex::lock();
}
inline void release() {
QMutex::unlock();
mutex::unlock();
}
};
}

View file

@ -2,6 +2,12 @@
#include <QImage>
PictureWriter::PictureWriter() {
}
PictureWriter::~PictureWriter() {
}
bool PictureWriter::save(const string &filepath, int width, int height) {
QImage result(width, height, QImage::Format_ARGB32);

View file

@ -8,6 +8,9 @@ namespace system {
class SYSTEMSHARED_EXPORT PictureWriter {
public:
PictureWriter();
virtual ~PictureWriter();
/**
* @brief Start saving the picture in a file.
*/

View file

@ -31,11 +31,18 @@ class PictureWriter;
class Time;
class RandomGenerator;
extern RandomGenerator &RandomGeneratorDefault;
extern SYSTEMSHARED_EXPORT RandomGenerator &RandomGeneratorDefault;
}
}
using namespace paysages::system;
using namespace std;
// Some useful casts
#define to_double(_x_) (static_cast<double>(_x_))
#define round_to_int(_x_) (static_cast<int>(round(_x_)))
#define floor_to_int(_x_) (static_cast<int>(floor(_x_)))
#define ceil_to_int(_x_) (static_cast<int>(ceil(_x_)))
#define to_size(_x_) (static_cast<unsigned long>(_x_))
#endif // SYSTEM_GLOBAL_H