[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 | {
|
---|
| 30 | //cout << "internal ray" << endl;
|
---|
| 31 | int hits = 0;
|
---|
| 32 | static Ray ray;
|
---|
[1528] | 33 | Intersection hitA(simpleRay.mOrigin), hitB(simpleRay.mOrigin);
|
---|
| 34 |
|
---|
| 35 | mPreprocessor.SetupRay(ray, simpleRay.mOrigin, simpleRay.mDirection);
|
---|
[1520] | 36 | ray.mFlags &= ~Ray::CULL_BACKFACES;
|
---|
| 37 |
|
---|
| 38 | if (mKdTree->CastRay(ray))
|
---|
| 39 | {
|
---|
[1528] | 40 | hitA.mObject = ray.intersections[0].mObject;
|
---|
| 41 | hitA.mPoint = ray.Extrap(ray.intersections[0].mT);
|
---|
| 42 | hitA.mNormal = ray.intersections[0].mNormal;
|
---|
[1551] | 43 | // cout << "hita: " << hitA.mPoint << " !obj: " << hitA.mObject << endl;
|
---|
[1520] | 44 | }
|
---|
| 45 |
|
---|
[1528] | 46 | mPreprocessor.SetupRay(ray, simpleRay.mOrigin, -simpleRay.mDirection);
|
---|
[1520] | 47 | ray.mFlags &= ~Ray::CULL_BACKFACES;
|
---|
| 48 |
|
---|
| 49 | if (castDoubleRay && mKdTree->CastRay(ray))
|
---|
| 50 | {
|
---|
[1528] | 51 | hitB.mObject = ray.intersections[0].mObject;
|
---|
| 52 | hitB.mPoint = ray.Extrap(ray.intersections[0].mT);
|
---|
| 53 | hitB.mNormal = ray.intersections[0].mNormal;
|
---|
[1520] | 54 | }
|
---|
[1528] | 55 |
|
---|
[1520] | 56 | return ProcessRay(
|
---|
[1528] | 57 | simpleRay,
|
---|
| 58 | hitA,
|
---|
| 59 | hitB,
|
---|
| 60 | vssRays,
|
---|
| 61 | box,
|
---|
| 62 | castDoubleRay,
|
---|
| 63 | pruneInvalidRays
|
---|
[1520] | 64 | );
|
---|
| 65 | }
|
---|
| 66 |
|
---|
| 67 |
|
---|
[1521] | 68 | void InternalRayCaster::CastRays16(const int index,
|
---|
[1520] | 69 | SimpleRayContainer &rays,
|
---|
| 70 | VssRayContainer &vssRays,
|
---|
| 71 | const AxisAlignedBox3 &sbox,
|
---|
[1528] | 72 | const bool castDoubleRays,
|
---|
| 73 | const bool pruneInvalidRays)
|
---|
[1520] | 74 | {
|
---|
| 75 | const int num = 16;
|
---|
| 76 |
|
---|
| 77 | #if DEBUG_RAYCAST
|
---|
| 78 | Debug<<"C16 "<<flush;
|
---|
| 79 | #endif
|
---|
| 80 |
|
---|
| 81 | // no acceleration for ray bundles implemented right now
|
---|
[1521] | 82 | for (int i=index; i < index + num; i++)
|
---|
[1520] | 83 | {
|
---|
[1528] | 84 | CastRay(rays[i], vssRays, sbox, castDoubleRays, pruneInvalidRays);
|
---|
[1520] | 85 | }
|
---|
| 86 |
|
---|
| 87 | #if DEBUG_RAYCAST
|
---|
| 88 | Debug<<"C16F\n"<<flush;
|
---|
| 89 | #endif
|
---|
| 90 | }
|
---|
| 91 |
|
---|
| 92 | } |
---|