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