#include "RayCaster.h" #include "VssRay.h" #include "Ray.h" #include "Preprocessor.h" #include "ViewCellsManager.h" namespace GtpVisibilityPreprocessor { #define DEBUG_RAYCAST 0 #define EXACT_BOX_CLIPPING 0 RayCaster::RayCaster(const Preprocessor &preprocessor): mPreprocessor(preprocessor) { } RayCaster::~RayCaster() { } VssRay *RayCaster::CastRay(const SimpleRay &simpleRay, const AxisAlignedBox3 &box) //const bool castDoubleRay) { // note: make no sense otherwise const bool castDoubleRay = false; VssRayContainer rays; CastRay(simpleRay, rays, box, castDoubleRay); if (!rays.empty()) return rays.back(); else return NULL; } bool RayCaster::ClipToViewSpaceBox(const Vector3 &origin, const Vector3 &termination, Vector3 &clippedOrigin, Vector3 &clippedTermination) { Ray ray(origin, termination - origin, Ray::LINE_SEGMENT); ray.Precompute(); float tmin, tmax; if ((!mPreprocessor.mViewCellsManager-> GetViewSpaceBox().ComputeMinMaxT(ray, &tmin, &tmax)) || tmin>=tmax ) return false; if (tmin >= 1.0f || tmax <=0.0f) return false; if (tmin > 0.0f) clippedOrigin = ray.Extrap(tmin); else clippedOrigin = origin; if (tmax < 1.0f) clippedTermination = ray.Extrap(tmax); else clippedTermination = termination; return true; } /** Checks if ray is valid, (e.g., not in empty view space or outside the view space) */ bool RayCaster::ValidateRay(const Vector3 &origin, const Vector3 &direction, const AxisAlignedBox3 &box, Intersection &hit) { if (!hit.mObject) { // compute intersection with the scene bounding box #if EXACT_BOX_CLIPPING static Ray ray; mPreprocessor.SetupRay(ray, origin, direction); float tmin, tmax; if (box.ComputeMinMaxT(ray, &tmin, &tmax) && (tmin < tmax)) { hit.mPoint = ray.Extrap(tmax); } else { // cout<<" invalid hp "<= -Limits::Small) { hit.mObject = NULL; return false; } } } return true; } int RayCaster::ProcessRay(const SimpleRay &simpleRay, Intersection &hitA, Intersection &hitB, VssRayContainer &vssRays, const AxisAlignedBox3 &box, const bool castDoubleRay, const bool pruneInvalidRays) { int hits = 0; #if DEBUG_RAYCAST static int id=0; Debug<<"PRA "<mFlags |= VssRay::Valid; vssRay->mDistribution = simpleRay.mDistribution; vssRays.push_back(vssRay); ++ hits; //cout << "vssray 1: " << *vssRay << " " << vssRay->mTermination - vssRay->mOrigin << endl; } #if DEBUG_RAYCAST Debug<<"PR3"<mFlags |= VssRay::Valid; vssRay->mDistribution = simpleRay.mDistribution; vssRays.push_back(vssRay); ++ hits; //cout << "vssray 2: " << *vssRay << endl; } #if DEBUG_RAYCAST Debug<<"PR4"<