source: GTP/trunk/Lib/Vis/Preprocessing/src/InternalRayCaster.cpp @ 1521

Revision 1521, 2.2 KB checked in by mattausch, 18 years ago (diff)
Line 
1#include "InternalRayCaster.h"
2#include "VssRay.h"
3#include "KdTree.h"
4#include "Preprocessor.h"
5
6#define DEBUG_RAYCAST 0
7
8
9namespace GtpVisibilityPreprocessor {
10
11
12InternalRayCaster::InternalRayCaster(const Preprocessor &preprocessor, KdTree *kdTree):
13RayCaster(preprocessor), mKdTree(kdTree)
14{
15}
16
17
18InternalRayCaster::~InternalRayCaster()
19{
20}
21
22
23int InternalRayCaster::CastRay(const Vector3 &viewPoint,
24                                                           const Vector3 &direction,
25                                                           const float probability,
26                                                           VssRayContainer &vssRays,
27                                                           const AxisAlignedBox3 &box,
28                                                           const bool castDoubleRay
29                                                           )
30{
31        //cout << "internal ray" << endl;
32        int hits = 0;
33        static Ray ray;
34        Intersectable *objectA = NULL, *objectB = NULL;
35        Vector3 pointA, pointB;
36        Vector3 normalA, normalB;
37
38#if 0
39        AxisAlignedBox3 sbox = box;
40        sbox.Enlarge(Vector3(-Limits::Small));
41        if (!sbox.IsInside(viewPoint))
42                return 0;
43#endif
44
45        mPreprocessor.SetupRay(ray, viewPoint, direction);
46        ray.mFlags &= ~Ray::CULL_BACKFACES;
47
48        if (mKdTree->CastRay(ray))
49        {
50                objectA = ray.intersections[0].mObject;
51                pointA = ray.Extrap(ray.intersections[0].mT);
52                normalA = ray.intersections[0].mNormal;
53        }
54       
55        mPreprocessor.SetupRay(ray, viewPoint, -direction);
56        ray.mFlags &= ~Ray::CULL_BACKFACES;
57
58        if (castDoubleRay && mKdTree->CastRay(ray))
59        {
60                objectB = ray.intersections[0].mObject;
61                pointB = ray.Extrap(ray.intersections[0].mT);
62                normalB = ray.intersections[0].mNormal;
63        }
64       
65        return ProcessRay(
66                viewPoint,
67                direction,
68                objectA, pointA, normalA,
69                objectB, pointB, normalB,
70                probability,
71                vssRays,
72                box
73                );
74}
75
76
77void InternalRayCaster::CastRays16(const int index,
78                                                                   SimpleRayContainer &rays,
79                                                                   VssRayContainer &vssRays,
80                                                                   const AxisAlignedBox3 &sbox,
81                                                                   const bool castDoubleRays)
82{
83        const int num = 16;
84
85#if DEBUG_RAYCAST
86        Debug<<"C16 "<<flush;
87#endif
88
89        // no acceleration for ray bundles implemented right now
90        for (int i=index; i < index + num; i++)
91        {
92                CastRay(rays[i].mOrigin,
93                        rays[i].mDirection,
94                        rays[i].mPdf,
95                        vssRays,
96                        sbox,
97                        castDoubleRays);
98        }
99
100#if DEBUG_RAYCAST
101        Debug<<"C16F\n"<<flush;
102#endif
103}
104
105}
Note: See TracBrowser for help on using the repository browser.