#include "InternalRayCaster.h" #include "VssRay.h" #include "KdTree.h" #include "Preprocessor.h" #define DEBUG_RAYCAST 0 namespace GtpVisibilityPreprocessor { InternalRayCaster::InternalRayCaster(const Preprocessor &preprocessor, KdTree *kdTree): RayCaster(preprocessor), mKdTree(kdTree) { } InternalRayCaster::~InternalRayCaster() { } int InternalRayCaster::CastRay(const SimpleRay &simpleRay, VssRayContainer &vssRays, const AxisAlignedBox3 &box, const bool castDoubleRay, const bool pruneInvalidRays ) { //cout << "internal ray" << endl; static Ray ray; int hits = 0; Intersection hitA(simpleRay.mOrigin), hitB(simpleRay.mOrigin); // inside test for bounding box // enlarge box slightly so the view point fits for sure // AxisAlignedBox3 sbox = box; // sbox.Enlarge(Vector3(-Limits::Small)); // $$ JB moved here from Validate routine if (!box.IsInside(simpleRay.mOrigin)) { return 0; } mPreprocessor.SetupRay(ray, simpleRay.mOrigin, simpleRay.mDirection); ray.mFlags &= ~Ray::CULL_BACKFACES; if (mKdTree->CastRay(ray)) { hitA.mObject = ray.intersections[0].mObject; hitA.mPoint = ray.Extrap(ray.intersections[0].mT); hitA.mNormal = ray.intersections[0].mNormal; // cout << "hita: " << hitA.mPoint << " !obj: " << hitA.mObject << endl; } mPreprocessor.SetupRay(ray, simpleRay.mOrigin, -simpleRay.mDirection); ray.mFlags &= ~Ray::CULL_BACKFACES; if (castDoubleRay && mKdTree->CastRay(ray)) { hitB.mObject = ray.intersections[0].mObject; hitB.mPoint = ray.Extrap(ray.intersections[0].mT); hitB.mNormal = ray.intersections[0].mNormal; } return ProcessRay( simpleRay, hitA, hitB, vssRays, box, castDoubleRay, pruneInvalidRays ); } void InternalRayCaster::CastRays16(const int index, SimpleRayContainer &rays, VssRayContainer &vssRays, const AxisAlignedBox3 &sbox, const bool castDoubleRays, const bool pruneInvalidRays) { const int num = 16; #if DEBUG_RAYCAST Debug<<"C16 "<