[1520] | 1 | #include "RayCaster.h"
|
---|
| 2 | #include "VssRay.h"
|
---|
| 3 | #include "Ray.h"
|
---|
| 4 | #include "Preprocessor.h"
|
---|
| 5 |
|
---|
| 6 |
|
---|
| 7 | namespace GtpVisibilityPreprocessor {
|
---|
| 8 |
|
---|
| 9 |
|
---|
| 10 | #define DEBUG_RAYCAST 0
|
---|
| 11 |
|
---|
| 12 |
|
---|
| 13 | RayCaster::RayCaster(const Preprocessor &preprocessor):
|
---|
| 14 | mPreprocessor(preprocessor)
|
---|
| 15 | {
|
---|
| 16 | }
|
---|
| 17 |
|
---|
| 18 |
|
---|
[1521] | 19 | RayCaster::~RayCaster()
|
---|
| 20 | {
|
---|
| 21 | }
|
---|
| 22 |
|
---|
| 23 |
|
---|
| 24 | VssRay *RayCaster::CastSingleRay(const Vector3 &viewPoint,
|
---|
| 25 | const Vector3 &direction,
|
---|
| 26 | const float probability,
|
---|
| 27 | const AxisAlignedBox3 &box)
|
---|
| 28 | {
|
---|
| 29 | VssRayContainer rays;
|
---|
| 30 | CastRay(viewPoint, direction, probability, rays, box, false);
|
---|
| 31 |
|
---|
| 32 | if (!rays.empty())
|
---|
| 33 | return rays.back();
|
---|
[1522] | 34 | else
|
---|
| 35 | return NULL;
|
---|
[1521] | 36 | }
|
---|
| 37 |
|
---|
| 38 |
|
---|
[1520] | 39 | int RayCaster::ProcessRay(const Vector3 &viewPoint,
|
---|
| 40 | const Vector3 &direction,
|
---|
| 41 | Intersectable *objectA,
|
---|
| 42 | Vector3 &pointA,
|
---|
| 43 | const Vector3 &normalA,
|
---|
| 44 | Intersectable *objectB,
|
---|
| 45 | Vector3 &pointB,
|
---|
| 46 | const Vector3 &normalB,
|
---|
| 47 | const float probability,
|
---|
| 48 | VssRayContainer &vssRays,
|
---|
| 49 | const AxisAlignedBox3 &box
|
---|
| 50 | )
|
---|
| 51 | {
|
---|
| 52 | int hits = 0;
|
---|
| 53 | #if DEBUG_RAYCAST
|
---|
| 54 | Debug<<"PR ";
|
---|
| 55 | #endif
|
---|
| 56 | if (objectA == NULL && objectB == NULL)
|
---|
| 57 | return 0;
|
---|
| 58 |
|
---|
| 59 | AxisAlignedBox3 sbox = box;
|
---|
| 60 | sbox.Enlarge(Vector3(-Limits::Small));
|
---|
| 61 |
|
---|
| 62 | if (!sbox.IsInside(viewPoint))
|
---|
| 63 | return 0;
|
---|
| 64 |
|
---|
| 65 | if (objectA == NULL) {
|
---|
| 66 | // compute intersection with the scene bounding box
|
---|
| 67 | static Ray ray;
|
---|
| 68 | mPreprocessor.SetupRay(ray, viewPoint, direction);
|
---|
| 69 |
|
---|
| 70 | float tmin, tmax;
|
---|
| 71 | if (box.ComputeMinMaxT(ray, &tmin, &tmax) && tmin < tmax)
|
---|
| 72 | pointA = ray.Extrap(tmax);
|
---|
| 73 | else
|
---|
| 74 | return 0;
|
---|
| 75 | } else {
|
---|
| 76 | if (mPreprocessor.mDetectEmptyViewSpace)
|
---|
| 77 | if (DotProd(normalA, direction) >= 0) {
|
---|
| 78 | // discard the sample
|
---|
| 79 | return 0;
|
---|
| 80 | }
|
---|
| 81 | }
|
---|
| 82 |
|
---|
| 83 | if (objectB == NULL) {
|
---|
| 84 | // compute intersection with the scene bounding box
|
---|
| 85 | static Ray ray;
|
---|
| 86 | mPreprocessor.SetupRay(ray, viewPoint, -direction);
|
---|
| 87 |
|
---|
| 88 | float tmin, tmax;
|
---|
| 89 | if (box.ComputeMinMaxT(ray, &tmin, &tmax) && tmin < tmax)
|
---|
| 90 | pointB = ray.Extrap(tmax);
|
---|
| 91 | else
|
---|
| 92 | return 0;
|
---|
| 93 | } else {
|
---|
| 94 | if (mPreprocessor.mDetectEmptyViewSpace)
|
---|
| 95 | if (DotProd(normalB, direction) <= 0) {
|
---|
| 96 | // discard the sample
|
---|
| 97 | return 0;
|
---|
| 98 | }
|
---|
| 99 | }
|
---|
| 100 |
|
---|
| 101 | VssRay *vssRay = NULL;
|
---|
| 102 | bool validSample = (objectA != objectB);
|
---|
| 103 | if (validSample) {
|
---|
| 104 | if (objectA) {
|
---|
| 105 | vssRay = new VssRay(
|
---|
| 106 | pointB,
|
---|
| 107 | pointA,
|
---|
| 108 | objectB,
|
---|
| 109 | objectA,
|
---|
| 110 | mPreprocessor.mPass,
|
---|
| 111 | probability
|
---|
| 112 | );
|
---|
| 113 |
|
---|
| 114 | vssRays.push_back(vssRay);
|
---|
| 115 | hits ++;
|
---|
| 116 | }
|
---|
| 117 |
|
---|
| 118 | if (objectB) {
|
---|
| 119 | vssRay = new VssRay(
|
---|
| 120 | pointA,
|
---|
| 121 | pointB,
|
---|
| 122 | objectA,
|
---|
| 123 | objectB,
|
---|
| 124 | mPreprocessor.mPass,
|
---|
| 125 | probability
|
---|
| 126 | );
|
---|
| 127 |
|
---|
| 128 | vssRays.push_back(vssRay);
|
---|
| 129 | hits ++;
|
---|
| 130 | }
|
---|
| 131 | }
|
---|
| 132 |
|
---|
| 133 | return hits;
|
---|
| 134 | }
|
---|
| 135 |
|
---|
| 136 | } |
---|