Skip to content
Snippets Groups Projects
Commit f0f2c297 authored by Lukas Werner's avatar Lukas Werner Committed by Lukas Werner
Browse files

Replaced INFINITY with numeric_limits::max

parent 9d7bf1e1
Branches
Tags
No related merge requests found
...@@ -56,6 +56,7 @@ struct IntersectsFunctor ...@@ -56,6 +56,7 @@ struct IntersectsFunctor
}; };
inline bool intersects(const SphereID sphere, const Ray& ray, real_t& t) { inline bool intersects(const SphereID sphere, const Ray& ray, real_t& t) {
real_t inf = std::numeric_limits<real_t>::max();
const Vec3& direction = ray.getDirection(); const Vec3& direction = ray.getDirection();
Vec3 displacement = ray.getOrigin() - sphere->getPosition(); Vec3 displacement = ray.getOrigin() - sphere->getPosition();
real_t a = direction * direction; real_t a = direction * direction;
...@@ -66,14 +67,14 @@ inline bool intersects(const SphereID sphere, const Ray& ray, real_t& t) { ...@@ -66,14 +67,14 @@ inline bool intersects(const SphereID sphere, const Ray& ray, real_t& t) {
// with discriminant smaller than 0, sphere is not hit by ray // with discriminant smaller than 0, sphere is not hit by ray
// (no solution for quadratic equation) // (no solution for quadratic equation)
// with discriminant being 0, sphere only tangentially hits the ray (not enough) // with discriminant being 0, sphere only tangentially hits the ray (not enough)
t = real_t(INFINITY); t = inf;
return false; return false;
} }
real_t root = real_t(std::sqrt(discriminant)); real_t root = real_t(std::sqrt(discriminant));
real_t t0 = (-b - root) / (real_t(2.) * a); // point where the ray enters the sphere real_t t0 = (-b - root) / (real_t(2.) * a); // point where the ray enters the sphere
real_t t1 = (-b + root) / (real_t(2.) * a); // point where the ray leaves the sphere real_t t1 = (-b + root) / (real_t(2.) * a); // point where the ray leaves the sphere
if (t0 < 0 && t1 < 0) { if (t0 < 0 && t1 < 0) {
t = real_t(INFINITY); t = inf;
return false; return false;
} }
t = (t0 < t1) ? t0 : t1; // assign the closest hit point to t t = (t0 < t1) ? t0 : t1; // assign the closest hit point to t
...@@ -81,7 +82,7 @@ inline bool intersects(const SphereID sphere, const Ray& ray, real_t& t) { ...@@ -81,7 +82,7 @@ inline bool intersects(const SphereID sphere, const Ray& ray, real_t& t) {
// at least one of the calculated hit points is behind the rays origin // at least one of the calculated hit points is behind the rays origin
if (t1 < 0) { if (t1 < 0) {
// both of the points are behind the origin (ray does not hit sphere) // both of the points are behind the origin (ray does not hit sphere)
t = real_t(INFINITY); t = inf;
return false; return false;
} else { } else {
// one point is hit by the ray (ray is within sphere) // one point is hit by the ray (ray is within sphere)
...@@ -92,6 +93,7 @@ inline bool intersects(const SphereID sphere, const Ray& ray, real_t& t) { ...@@ -92,6 +93,7 @@ inline bool intersects(const SphereID sphere, const Ray& ray, real_t& t) {
} }
inline bool intersects(const PlaneID plane, const Ray& ray, real_t& t) { inline bool intersects(const PlaneID plane, const Ray& ray, real_t& t) {
real_t inf = std::numeric_limits<real_t>::max();
const Vec3& direction = ray.getDirection(); const Vec3& direction = ray.getDirection();
const Vec3& origin = ray.getOrigin(); const Vec3& origin = ray.getOrigin();
real_t denominator = plane->getNormal() * direction; real_t denominator = plane->getNormal() * direction;
...@@ -105,10 +107,10 @@ inline bool intersects(const PlaneID plane, const Ray& ray, real_t& t) { ...@@ -105,10 +107,10 @@ inline bool intersects(const PlaneID plane, const Ray& ray, real_t& t) {
t = originToIntersection.length(); t = originToIntersection.length();
return true; return true;
} else { } else {
t = INFINITY; t = inf;
} }
} }
t = INFINITY; t = inf;
return false; return false;
} }
...@@ -127,13 +129,15 @@ inline bool intersects(const BoxID box, const Ray& ray, real_t& t) { ...@@ -127,13 +129,15 @@ inline bool intersects(const BoxID box, const Ray& ray, real_t& t) {
const Vec3& invDirection = transformedRay.getInvDirection(); const Vec3& invDirection = transformedRay.getInvDirection();
const Vec3& origin = transformedRay.getOrigin(); const Vec3& origin = transformedRay.getOrigin();
real_t inf = std::numeric_limits<real_t>::max();
real_t txmin, txmax; real_t txmin, txmax;
real_t tmin = txmin = (bounds[sign[0]][0] - origin[0]) * invDirection[0]; real_t tmin = txmin = (bounds[sign[0]][0] - origin[0]) * invDirection[0];
real_t tmax = txmax = (bounds[1-sign[0]][0] - origin[0]) * invDirection[0]; real_t tmax = txmax = (bounds[1-sign[0]][0] - origin[0]) * invDirection[0];
real_t tymin = (bounds[sign[1]][1] - origin[1]) * invDirection[1]; real_t tymin = (bounds[sign[1]][1] - origin[1]) * invDirection[1];
real_t tymax = (bounds[1-sign[1]][1] - origin[1]) * invDirection[1]; real_t tymax = (bounds[1-sign[1]][1] - origin[1]) * invDirection[1];
if (tmin > tymax || tymin > tmax) { if (tmin > tymax || tymin > tmax) {
t = INFINITY; t = inf;
return false; return false;
} }
if (tymin > tmin) { if (tymin > tmin) {
...@@ -145,7 +149,7 @@ inline bool intersects(const BoxID box, const Ray& ray, real_t& t) { ...@@ -145,7 +149,7 @@ inline bool intersects(const BoxID box, const Ray& ray, real_t& t) {
real_t tzmin = (bounds[sign[2]][2] - origin[2]) * invDirection[2]; real_t tzmin = (bounds[sign[2]][2] - origin[2]) * invDirection[2];
real_t tzmax = (bounds[1-sign[2]][2] - origin[2]) * invDirection[2]; real_t tzmax = (bounds[1-sign[2]][2] - origin[2]) * invDirection[2];
if (tmin > tzmax || tzmin > tmax) { if (tmin > tzmax || tzmin > tmax) {
t = INFINITY; t = inf;
return false; return false;
} }
if (tzmin > tmin) { if (tzmin > tmin) {
...@@ -161,7 +165,7 @@ inline bool intersects(const BoxID box, const Ray& ray, real_t& t) { ...@@ -161,7 +165,7 @@ inline bool intersects(const BoxID box, const Ray& ray, real_t& t) {
t_ = tmin; t_ = tmin;
} else if (tmax < 0) { } else if (tmax < 0) {
// tmin and tmax are smaller than 0 -> box is in rays negative direction // tmin and tmax are smaller than 0 -> box is in rays negative direction
t = INFINITY; t = inf;
return false; return false;
} else { } else {
// ray origin within box // ray origin within box
...@@ -184,13 +188,15 @@ inline bool intersects(const AABB& aabb, const Ray& ray, real_t& t, real_t paddi ...@@ -184,13 +188,15 @@ inline bool intersects(const AABB& aabb, const Ray& ray, real_t& t, real_t paddi
const Vec3& invDirection = ray.getInvDirection(); const Vec3& invDirection = ray.getInvDirection();
const Vec3& origin = ray.getOrigin(); const Vec3& origin = ray.getOrigin();
real_t inf = std::numeric_limits<real_t>::max();
real_t txmin, txmax; real_t txmin, txmax;
real_t tmin = txmin = (bounds[sign[0]][0] - origin[0]) * invDirection[0]; real_t tmin = txmin = (bounds[sign[0]][0] - origin[0]) * invDirection[0];
real_t tmax = txmax = (bounds[1-sign[0]][0] - origin[0]) * invDirection[0]; real_t tmax = txmax = (bounds[1-sign[0]][0] - origin[0]) * invDirection[0];
real_t tymin = (bounds[sign[1]][1] - origin[1]) * invDirection[1]; real_t tymin = (bounds[sign[1]][1] - origin[1]) * invDirection[1];
real_t tymax = (bounds[1-sign[1]][1] - origin[1]) * invDirection[1]; real_t tymax = (bounds[1-sign[1]][1] - origin[1]) * invDirection[1];
if (tmin > tymax || tymin > tmax) { if (tmin > tymax || tymin > tmax) {
t = INFINITY; t = inf;
return false; return false;
} }
if (tymin > tmin) { if (tymin > tmin) {
...@@ -202,7 +208,7 @@ inline bool intersects(const AABB& aabb, const Ray& ray, real_t& t, real_t paddi ...@@ -202,7 +208,7 @@ inline bool intersects(const AABB& aabb, const Ray& ray, real_t& t, real_t paddi
real_t tzmin = (bounds[sign[2]][2] - origin[2]) * invDirection[2]; real_t tzmin = (bounds[sign[2]][2] - origin[2]) * invDirection[2];
real_t tzmax = (bounds[1-sign[2]][2] - origin[2]) * invDirection[2]; real_t tzmax = (bounds[1-sign[2]][2] - origin[2]) * invDirection[2];
if (tmin > tzmax || tzmin > tmax) { if (tmin > tzmax || tzmin > tmax) {
t = INFINITY; t = inf;
return false; return false;
} }
if (tzmin > tmin) { if (tzmin > tmin) {
...@@ -218,7 +224,7 @@ inline bool intersects(const AABB& aabb, const Ray& ray, real_t& t, real_t paddi ...@@ -218,7 +224,7 @@ inline bool intersects(const AABB& aabb, const Ray& ray, real_t& t, real_t paddi
t_ = tmin; t_ = tmin;
} else if (tmax < 0) { } else if (tmax < 0) {
// tmin and tmax are smaller than 0 -> box is in rays negative direction // tmin and tmax are smaller than 0 -> box is in rays negative direction
t = INFINITY; t = inf;
return false; return false;
} else { } else {
// ray origin within box // ray origin within box
......
...@@ -129,13 +129,15 @@ void Raytracer::writeTBufferToFile(const std::map<Coordinates, real_t, Coordinat ...@@ -129,13 +129,15 @@ void Raytracer::writeTBufferToFile(const std::map<Coordinates, real_t, Coordinat
void Raytracer::writeTBufferToFile(const std::map<Coordinates, real_t, CoordinatesComparator>& tBuffer, const std::string& fileName) const { void Raytracer::writeTBufferToFile(const std::map<Coordinates, real_t, CoordinatesComparator>& tBuffer, const std::string& fileName) const {
namespace fs = boost::filesystem; namespace fs = boost::filesystem;
real_t inf = std::numeric_limits<real_t>::max();
real_t t_max = 1; real_t t_max = 1;
real_t t_min = INFINITY; real_t t_min = inf;
for (size_t x = 0; x < pixelsHorizontal_; x++) { for (size_t x = 0; x < pixelsHorizontal_; x++) {
for (size_t y = 0; y < pixelsVertical_; y++) { for (size_t y = 0; y < pixelsVertical_; y++) {
Coordinates c = {x, y}; Coordinates c = {x, y};
real_t t = tBuffer.at(c); real_t t = tBuffer.at(c);
if (t > t_max && !realIsIdentical(t, INFINITY)) { if (t > t_max && !realIsIdentical(t, inf)) {
t_max = t; t_max = t;
} }
if (t < t_min) { if (t < t_min) {
...@@ -143,7 +145,7 @@ void Raytracer::writeTBufferToFile(const std::map<Coordinates, real_t, Coordinat ...@@ -143,7 +145,7 @@ void Raytracer::writeTBufferToFile(const std::map<Coordinates, real_t, Coordinat
} }
} }
} }
if (realIsIdentical(t_min, INFINITY)) t_min = 0; if (realIsIdentical(t_min, inf)) t_min = 0;
fs::path dir (getTBufferOutputDirectory()); fs::path dir (getTBufferOutputDirectory());
fs::path file (fileName); fs::path file (fileName);
...@@ -156,7 +158,7 @@ void Raytracer::writeTBufferToFile(const std::map<Coordinates, real_t, Coordinat ...@@ -156,7 +158,7 @@ void Raytracer::writeTBufferToFile(const std::map<Coordinates, real_t, Coordinat
Coordinates c = {x, y}; Coordinates c = {x, y};
char r = 0, g = 0, b = 0; char r = 0, g = 0, b = 0;
real_t t = tBuffer.at(c); real_t t = tBuffer.at(c);
if (realIsIdentical(t, INFINITY)) { if (realIsIdentical(t, inf)) {
r = g = b = (char)0; r = g = b = (char)0;
} else { } else {
r = g = b = (char)(240 * (1-(t-t_min)/(t_max-t_min))); r = g = b = (char)(240 * (1-(t-t_min)/(t_max-t_min)));
......
...@@ -247,6 +247,7 @@ void Raytracer::rayTrace(const size_t timestep) const { ...@@ -247,6 +247,7 @@ void Raytracer::rayTrace(const size_t timestep) const {
std::vector<BodyIntersectionInfo> intersections; // contains for each pixel information about an intersection, if existent std::vector<BodyIntersectionInfo> intersections; // contains for each pixel information about an intersection, if existent
std::map<Coordinates, BodyIntersectionInfo, CoordinatesComparator> localPixelIntersectionMap; // contains intersection info indexed by the coordinates of the pixel which was hit std::map<Coordinates, BodyIntersectionInfo, CoordinatesComparator> localPixelIntersectionMap; // contains intersection info indexed by the coordinates of the pixel which was hit
real_t inf = std::numeric_limits<real_t>::max();
real_t t, t_closest; real_t t, t_closest;
walberla::id_t id_closest; walberla::id_t id_closest;
RigidBody* body_closest = NULL; RigidBody* body_closest = NULL;
...@@ -260,7 +261,7 @@ void Raytracer::rayTrace(const size_t timestep) const { ...@@ -260,7 +261,7 @@ void Raytracer::rayTrace(const size_t timestep) const {
Vec3 direction = (pixelLocation - cameraPosition_).getNormalized(); Vec3 direction = (pixelLocation - cameraPosition_).getNormalized();
ray.setDirection(direction); ray.setDirection(direction);
t_closest = INFINITY; t_closest = inf;
id_closest = 0; id_closest = 0;
body_closest = NULL; body_closest = NULL;
for (auto blockIt = forest_->begin(); blockIt != forest_->end(); ++blockIt) { for (auto blockIt = forest_->begin(); blockIt != forest_->end(); ++blockIt) {
...@@ -311,14 +312,14 @@ void Raytracer::rayTrace(const size_t timestep) const { ...@@ -311,14 +312,14 @@ void Raytracer::rayTrace(const size_t timestep) const {
} }
} }
//std::cout << (t_closest != INFINITY ? size_t(t_closest) : 0) << " "; //std::cout << (t_closest != inf ? size_t(t_closest) : 0) << " ";
Coordinates c = { Coordinates c = {
x, x,
y y
}; };
if (!realIsIdentical(t_closest, INFINITY) && body_closest != NULL) { if (!realIsIdentical(t_closest, inf) && body_closest != NULL) {
BodyIntersectionInfo intersectionInfo = { BodyIntersectionInfo intersectionInfo = {
x, x,
y, y,
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment