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(
|
---|
24 | const Vector3 &viewPoint,
|
---|
25 | const Vector3 &direction,
|
---|
26 | const float probability,
|
---|
27 | VssRayContainer &vssRays,
|
---|
28 | const AxisAlignedBox3 &box,
|
---|
29 | const bool castDoubleRay
|
---|
30 | )
|
---|
31 | {
|
---|
32 | //cout << "internal ray" << endl;
|
---|
33 | int hits = 0;
|
---|
34 | static Ray ray;
|
---|
35 | Intersectable *objectA = NULL, *objectB = NULL;
|
---|
36 | Vector3 pointA, pointB;
|
---|
37 | Vector3 normalA, normalB;
|
---|
38 |
|
---|
39 | #if 0
|
---|
40 | AxisAlignedBox3 sbox = box;
|
---|
41 | sbox.Enlarge(Vector3(-Limits::Small));
|
---|
42 | if (!sbox.IsInside(viewPoint))
|
---|
43 | return 0;
|
---|
44 | #endif
|
---|
45 |
|
---|
46 | mPreprocessor.SetupRay(ray, viewPoint, direction);
|
---|
47 | ray.mFlags &= ~Ray::CULL_BACKFACES;
|
---|
48 |
|
---|
49 | if (mKdTree->CastRay(ray))
|
---|
50 | {
|
---|
51 | objectA = ray.intersections[0].mObject;
|
---|
52 | pointA = ray.Extrap(ray.intersections[0].mT);
|
---|
53 | normalA = ray.intersections[0].mNormal;
|
---|
54 | }
|
---|
55 |
|
---|
56 | mPreprocessor.SetupRay(ray, viewPoint, -direction);
|
---|
57 | ray.mFlags &= ~Ray::CULL_BACKFACES;
|
---|
58 |
|
---|
59 | if (castDoubleRay && mKdTree->CastRay(ray))
|
---|
60 | {
|
---|
61 | objectB = ray.intersections[0].mObject;
|
---|
62 | pointB = ray.Extrap(ray.intersections[0].mT);
|
---|
63 | normalB = ray.intersections[0].mNormal;
|
---|
64 | }
|
---|
65 |
|
---|
66 | return ProcessRay(
|
---|
67 | viewPoint,
|
---|
68 | direction,
|
---|
69 | objectA, pointA, normalA,
|
---|
70 | objectB, pointB, normalB,
|
---|
71 | probability,
|
---|
72 | vssRays,
|
---|
73 | box
|
---|
74 | );
|
---|
75 | }
|
---|
76 |
|
---|
77 |
|
---|
78 | void InternalRayCaster::CastRays16(
|
---|
79 | const int index,
|
---|
80 | SimpleRayContainer &rays,
|
---|
81 | VssRayContainer &vssRays,
|
---|
82 | const AxisAlignedBox3 &sbox,
|
---|
83 | const bool castDoubleRays)
|
---|
84 | {
|
---|
85 | int i;
|
---|
86 | const int num = 16;
|
---|
87 |
|
---|
88 | #if DEBUG_RAYCAST
|
---|
89 | Debug<<"C16 "<<flush;
|
---|
90 | #endif
|
---|
91 |
|
---|
92 | // no acceleration for ray bundles implemented right now
|
---|
93 | for (i=index; i < index + num; i++)
|
---|
94 | {
|
---|
95 | CastRay(rays[i].mOrigin,
|
---|
96 | rays[i].mDirection,
|
---|
97 | rays[i].mPdf,
|
---|
98 | vssRays,
|
---|
99 | sbox,
|
---|
100 | castDoubleRays);
|
---|
101 | }
|
---|
102 |
|
---|
103 | #if DEBUG_RAYCAST
|
---|
104 | Debug<<"C16F\n"<<flush;
|
---|
105 | #endif
|
---|
106 | }
|
---|
107 |
|
---|
108 | } |
---|