[1520] | 1 | #include "InternalRayCaster.h"
|
---|
| 2 | #include "VssRay.h"
|
---|
| 3 | #include "KdTree.h"
|
---|
| 4 | #include "Preprocessor.h"
|
---|
| 5 |
|
---|
| 6 | #define DEBUG_RAYCAST 0
|
---|
| 7 |
|
---|
| 8 |
|
---|
| 9 | namespace GtpVisibilityPreprocessor {
|
---|
| 10 |
|
---|
| 11 |
|
---|
| 12 | InternalRayCaster::InternalRayCaster(const Preprocessor &preprocessor, KdTree *kdTree):
|
---|
| 13 | RayCaster(preprocessor), mKdTree(kdTree)
|
---|
| 14 | {
|
---|
| 15 | }
|
---|
| 16 |
|
---|
| 17 |
|
---|
| 18 | InternalRayCaster::~InternalRayCaster()
|
---|
| 19 | {
|
---|
| 20 | }
|
---|
| 21 |
|
---|
| 22 |
|
---|
[1528] | 23 | int InternalRayCaster::CastRay(const SimpleRay &simpleRay,
|
---|
[1520] | 24 | VssRayContainer &vssRays,
|
---|
| 25 | const AxisAlignedBox3 &box,
|
---|
[1528] | 26 | const bool castDoubleRay,
|
---|
| 27 | const bool pruneInvalidRays
|
---|
[1520] | 28 | )
|
---|
| 29 | {
|
---|
[1583] | 30 | //cout << "internal ray" << endl;
|
---|
[1584] | 31 | static Ray ray;
|
---|
[1583] | 32 | int hits = 0;
|
---|
| 33 | Intersection hitA(simpleRay.mOrigin), hitB(simpleRay.mOrigin);
|
---|
| 34 |
|
---|
[1584] | 35 | // inside test for bounding box
|
---|
| 36 | // enlarge box slightly so the view point fits for sure
|
---|
| 37 | // AxisAlignedBox3 sbox = box;
|
---|
| 38 | // sbox.Enlarge(Vector3(-Limits::Small));
|
---|
| 39 | // $$ JB moved here from Validate routine
|
---|
| 40 | if (!box.IsInside(simpleRay.mOrigin)) {
|
---|
| 41 | return 0;
|
---|
| 42 | }
|
---|
| 43 |
|
---|
[1583] | 44 | mPreprocessor.SetupRay(ray, simpleRay.mOrigin, simpleRay.mDirection);
|
---|
| 45 | ray.mFlags &= ~Ray::CULL_BACKFACES;
|
---|
| 46 |
|
---|
| 47 | if (mKdTree->CastRay(ray))
|
---|
[1520] | 48 | {
|
---|
[1583] | 49 | hitA.mObject = ray.intersections[0].mObject;
|
---|
| 50 | hitA.mPoint = ray.Extrap(ray.intersections[0].mT);
|
---|
| 51 | hitA.mNormal = ray.intersections[0].mNormal;
|
---|
| 52 | // cout << "hita: " << hitA.mPoint << " !obj: " << hitA.mObject << endl;
|
---|
[1520] | 53 | }
|
---|
[1583] | 54 |
|
---|
| 55 | mPreprocessor.SetupRay(ray, simpleRay.mOrigin, -simpleRay.mDirection);
|
---|
| 56 | ray.mFlags &= ~Ray::CULL_BACKFACES;
|
---|
| 57 |
|
---|
| 58 | if (castDoubleRay && mKdTree->CastRay(ray))
|
---|
[1520] | 59 | {
|
---|
[1583] | 60 | hitB.mObject = ray.intersections[0].mObject;
|
---|
| 61 | hitB.mPoint = ray.Extrap(ray.intersections[0].mT);
|
---|
| 62 | hitB.mNormal = ray.intersections[0].mNormal;
|
---|
[1520] | 63 | }
|
---|
[1583] | 64 |
|
---|
| 65 | return ProcessRay(
|
---|
| 66 | simpleRay,
|
---|
| 67 | hitA,
|
---|
| 68 | hitB,
|
---|
| 69 | vssRays,
|
---|
| 70 | box,
|
---|
| 71 | castDoubleRay,
|
---|
| 72 | pruneInvalidRays
|
---|
| 73 | );
|
---|
[1520] | 74 | }
|
---|
| 75 |
|
---|
| 76 |
|
---|
[1521] | 77 | void InternalRayCaster::CastRays16(const int index,
|
---|
[1520] | 78 | SimpleRayContainer &rays,
|
---|
| 79 | VssRayContainer &vssRays,
|
---|
| 80 | const AxisAlignedBox3 &sbox,
|
---|
[1528] | 81 | const bool castDoubleRays,
|
---|
| 82 | const bool pruneInvalidRays)
|
---|
[1520] | 83 | {
|
---|
| 84 | const int num = 16;
|
---|
| 85 |
|
---|
| 86 | #if DEBUG_RAYCAST
|
---|
| 87 | Debug<<"C16 "<<flush;
|
---|
| 88 | #endif
|
---|
| 89 |
|
---|
| 90 | // no acceleration for ray bundles implemented right now
|
---|
[1521] | 91 | for (int i=index; i < index + num; i++)
|
---|
[1520] | 92 | {
|
---|
[1528] | 93 | CastRay(rays[i], vssRays, sbox, castDoubleRays, pruneInvalidRays);
|
---|
[1520] | 94 | }
|
---|
| 95 |
|
---|
| 96 | #if DEBUG_RAYCAST
|
---|
| 97 | Debug<<"C16F\n"<<flush;
|
---|
| 98 | #endif
|
---|
| 99 | }
|
---|
| 100 |
|
---|
[1583] | 101 | }
|
---|