diff --git a/src/pe/raytracing/Intersects.h b/src/pe/raytracing/Intersects.h index 90d17f29b52aa97b4417f2a425ad81be0f1d37a7..ae045d6d3fc20e91ab4e0f1a91d8137f0aba38a0 100644 --- a/src/pe/raytracing/Intersects.h +++ b/src/pe/raytracing/Intersects.h @@ -56,6 +56,7 @@ struct IntersectsFunctor }; 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(); Vec3 displacement = ray.getOrigin() - sphere->getPosition(); real_t a = direction * direction; @@ -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 // (no solution for quadratic equation) // with discriminant being 0, sphere only tangentially hits the ray (not enough) - t = real_t(INFINITY); + t = inf; return false; } 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 t1 = (-b + root) / (real_t(2.) * a); // point where the ray leaves the sphere if (t0 < 0 && t1 < 0) { - t = real_t(INFINITY); + t = inf; return false; } 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) { // at least one of the calculated hit points is behind the rays origin if (t1 < 0) { // both of the points are behind the origin (ray does not hit sphere) - t = real_t(INFINITY); + t = inf; return false; } else { // 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) { } 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& origin = ray.getOrigin(); real_t denominator = plane->getNormal() * direction; @@ -105,10 +107,10 @@ inline bool intersects(const PlaneID plane, const Ray& ray, real_t& t) { t = originToIntersection.length(); return true; } else { - t = INFINITY; + t = inf; } } - t = INFINITY; + t = inf; return false; } @@ -127,13 +129,15 @@ inline bool intersects(const BoxID box, const Ray& ray, real_t& t) { const Vec3& invDirection = transformedRay.getInvDirection(); const Vec3& origin = transformedRay.getOrigin(); + real_t inf = std::numeric_limits<real_t>::max(); + real_t txmin, txmax; 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 tymin = (bounds[sign[1]][1] - origin[1]) * invDirection[1]; real_t tymax = (bounds[1-sign[1]][1] - origin[1]) * invDirection[1]; if (tmin > tymax || tymin > tmax) { - t = INFINITY; + t = inf; return false; } if (tymin > tmin) { @@ -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 tzmax = (bounds[1-sign[2]][2] - origin[2]) * invDirection[2]; if (tmin > tzmax || tzmin > tmax) { - t = INFINITY; + t = inf; return false; } if (tzmin > tmin) { @@ -161,7 +165,7 @@ inline bool intersects(const BoxID box, const Ray& ray, real_t& t) { t_ = tmin; } else if (tmax < 0) { // tmin and tmax are smaller than 0 -> box is in rays negative direction - t = INFINITY; + t = inf; return false; } else { // ray origin within box @@ -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& origin = ray.getOrigin(); + real_t inf = std::numeric_limits<real_t>::max(); + real_t txmin, txmax; 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 tymin = (bounds[sign[1]][1] - origin[1]) * invDirection[1]; real_t tymax = (bounds[1-sign[1]][1] - origin[1]) * invDirection[1]; if (tmin > tymax || tymin > tmax) { - t = INFINITY; + t = inf; return false; } if (tymin > tmin) { @@ -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 tzmax = (bounds[1-sign[2]][2] - origin[2]) * invDirection[2]; if (tmin > tzmax || tzmin > tmax) { - t = INFINITY; + t = inf; return false; } if (tzmin > tmin) { @@ -218,7 +224,7 @@ inline bool intersects(const AABB& aabb, const Ray& ray, real_t& t, real_t paddi t_ = tmin; } else if (tmax < 0) { // tmin and tmax are smaller than 0 -> box is in rays negative direction - t = INFINITY; + t = inf; return false; } else { // ray origin within box diff --git a/src/pe/raytracing/Raytracer.cpp b/src/pe/raytracing/Raytracer.cpp index 3e309ac1d179aaa3fad34ee76d6f64bf527a7d12..8f9a5be971aae826d84de22206e334f41e75d946 100644 --- a/src/pe/raytracing/Raytracer.cpp +++ b/src/pe/raytracing/Raytracer.cpp @@ -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 { namespace fs = boost::filesystem; + real_t inf = std::numeric_limits<real_t>::max(); + 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 y = 0; y < pixelsVertical_; y++) { Coordinates c = {x, y}; real_t t = tBuffer.at(c); - if (t > t_max && !realIsIdentical(t, INFINITY)) { + if (t > t_max && !realIsIdentical(t, inf)) { t_max = t; } if (t < t_min) { @@ -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 file (fileName); @@ -156,7 +158,7 @@ void Raytracer::writeTBufferToFile(const std::map<Coordinates, real_t, Coordinat Coordinates c = {x, y}; char r = 0, g = 0, b = 0; real_t t = tBuffer.at(c); - if (realIsIdentical(t, INFINITY)) { + if (realIsIdentical(t, inf)) { r = g = b = (char)0; } else { r = g = b = (char)(240 * (1-(t-t_min)/(t_max-t_min))); diff --git a/src/pe/raytracing/Raytracer.h b/src/pe/raytracing/Raytracer.h index 82e30a452cc15848422ec5c805c5759b0bea68ab..faa7dd3c55ebc7250f5ba9a88aa3e2b2476fbac6 100644 --- a/src/pe/raytracing/Raytracer.h +++ b/src/pe/raytracing/Raytracer.h @@ -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::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; walberla::id_t id_closest; RigidBody* body_closest = NULL; @@ -260,7 +261,7 @@ void Raytracer::rayTrace(const size_t timestep) const { Vec3 direction = (pixelLocation - cameraPosition_).getNormalized(); ray.setDirection(direction); - t_closest = INFINITY; + t_closest = inf; id_closest = 0; body_closest = NULL; for (auto blockIt = forest_->begin(); blockIt != forest_->end(); ++blockIt) { @@ -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 = { x, y }; - if (!realIsIdentical(t_closest, INFINITY) && body_closest != NULL) { + if (!realIsIdentical(t_closest, inf) && body_closest != NULL) { BodyIntersectionInfo intersectionInfo = { x, y,