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 |
|
---|
23 | int InternalRayCaster::CastRay(const SimpleRay &simpleRay,
|
---|
24 | VssRayContainer &vssRays,
|
---|
25 | const AxisAlignedBox3 &box,
|
---|
26 | const bool castDoubleRay,
|
---|
27 | const bool pruneInvalidRays
|
---|
28 | )
|
---|
29 | {
|
---|
30 | //cout << "internal ray" << endl;
|
---|
31 | static Ray ray;
|
---|
32 | int hits = 0;
|
---|
33 | Intersection hitA(simpleRay.mOrigin), hitB(simpleRay.mOrigin);
|
---|
34 |
|
---|
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 |
|
---|
44 | mPreprocessor.SetupRay(ray, simpleRay.mOrigin, simpleRay.mDirection);
|
---|
45 | ray.mFlags &= ~Ray::CULL_BACKFACES;
|
---|
46 |
|
---|
47 | if (mKdTree->CastRay(ray))
|
---|
48 | {
|
---|
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;
|
---|
53 | }
|
---|
54 |
|
---|
55 | mPreprocessor.SetupRay(ray, simpleRay.mOrigin, -simpleRay.mDirection);
|
---|
56 | ray.mFlags &= ~Ray::CULL_BACKFACES;
|
---|
57 |
|
---|
58 | if (castDoubleRay && mKdTree->CastRay(ray))
|
---|
59 | {
|
---|
60 | hitB.mObject = ray.intersections[0].mObject;
|
---|
61 | hitB.mPoint = ray.Extrap(ray.intersections[0].mT);
|
---|
62 | hitB.mNormal = ray.intersections[0].mNormal;
|
---|
63 | }
|
---|
64 |
|
---|
65 | return ProcessRay(
|
---|
66 | simpleRay,
|
---|
67 | hitA,
|
---|
68 | hitB,
|
---|
69 | vssRays,
|
---|
70 | box,
|
---|
71 | castDoubleRay,
|
---|
72 | pruneInvalidRays
|
---|
73 | );
|
---|
74 | }
|
---|
75 |
|
---|
76 |
|
---|
77 | void InternalRayCaster::CastRays16(const int index,
|
---|
78 | SimpleRayContainer &rays,
|
---|
79 | VssRayContainer &vssRays,
|
---|
80 | const AxisAlignedBox3 &sbox,
|
---|
81 | const bool castDoubleRays,
|
---|
82 | const bool pruneInvalidRays)
|
---|
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
|
---|
91 | for (int i=index; i < index + num; i++)
|
---|
92 | {
|
---|
93 | CastRay(rays[i], vssRays, sbox, castDoubleRays, pruneInvalidRays);
|
---|
94 | }
|
---|
95 |
|
---|
96 | #if DEBUG_RAYCAST
|
---|
97 | Debug<<"C16F\n"<<flush;
|
---|
98 | #endif
|
---|
99 | }
|
---|
100 |
|
---|
101 | }
|
---|