source: GTP/trunk/Lib/Vis/Preprocessing/src/SamplingStrategy.cpp @ 1297

Revision 1297, 3.9 KB checked in by mattausch, 18 years ago (diff)
Line 
1#include "SamplingStrategy.h"
2#include "Ray.h"
3#include "Intersectable.h"
4#include "Preprocessor.h"
5#include "ViewCellsManager.h"
6#include "AxisAlignedBox3.h"
7
8
9namespace GtpVisibilityPreprocessor {
10
11
12/*********************************************************************/
13/*            Individual sampling strategies implementation          */
14/*********************************************************************/
15
16
17bool ObjectBasedDistribution::GenerateSample(SimpleRay &ray) const
18{
19        Vector3 origin, direction;
20
21        mPreprocessor.mViewCellsManager->GetViewPoint(origin);
22
23        Vector3 point;
24        Vector3 normal;
25         
26        const int i = (int)RandomValue(0, float((int)mPreprocessor.mObjects.size() - 1));
27
28        Intersectable *object = mPreprocessor.mObjects[i];
29
30        object->GetRandomSurfacePoint(point, normal);
31        direction = point - origin;
32
33        // $$ jb the pdf is yet not correct for all sampling methods!
34        const float c = Magnitude(direction);
35
36        if (c <= Limits::Small)
37                return false;
38
39        // $$ jb the pdf is yet not correct for all sampling methods!
40        const float pdf = 1.0f;
41       
42        direction *= 1.0f / c;
43        ray = SimpleRay(origin, direction, pdf);
44
45        return true;
46}
47
48
49bool ObjectDirectionBasedDistribution::GenerateSample(SimpleRay &ray) const
50{       
51        Vector3 origin, direction;
52
53    const int i = (int)RandomValue(0, (Real)((int)mPreprocessor.mObjects.size() - 1));
54
55        Intersectable *object = mPreprocessor.mObjects[i];
56       
57        Vector3 normal;
58       
59        object->GetRandomSurfacePoint(origin, normal);
60        direction = UniformRandomVector(normal);
61       
62        origin += 0.1f * direction;
63
64        const float c = Magnitude(direction);
65
66        if (c <= Limits::Small)
67                return false;
68       
69        // $$ jb the pdf is yet not correct for all sampling methods!
70        const float pdf = 1.0f;
71       
72        direction *= 1.0f / c;
73        ray = SimpleRay(origin, direction, pdf);
74
75        return true;
76}
77
78
79bool DirectionBasedDistribution::GenerateSample(SimpleRay &ray) const
80{       
81        Vector3 origin, direction;
82        mPreprocessor.mViewCellsManager->GetViewPoint(origin);
83         
84        direction = UniformRandomVector();
85
86        const float c = Magnitude(direction);
87
88        if (c <= Limits::Small)
89                return false;
90
91        const float pdf = 1.0f;
92
93        direction *= 1.0f / c;
94        ray = SimpleRay(origin, direction, pdf);
95
96        return true;
97}
98
99
100bool DirectionBoxBasedDistribution::GenerateSample(SimpleRay &ray) const
101{
102        Vector3 origin, direction;
103        mPreprocessor.mViewCellsManager->GetViewPoint(origin);
104
105        const float alpha = RandomValue(0.0f, 2.0f * (float)M_PI);
106        const float beta = RandomValue((float)-M_PI * 0.5f, (float)M_PI * 0.5f);
107       
108        direction = VssRay::GetDirection(alpha, beta);
109       
110        const float c = Magnitude(direction);
111
112        if (c <= Limits::Small)
113                return false;
114
115        const float pdf = 1.0f;
116
117        direction *= 1.0f / c;
118        ray = SimpleRay(origin, direction, pdf);
119
120        return true;
121}
122
123
124bool SpatialBoxBasedDistribution::GenerateSample(SimpleRay &ray) const
125{
126        Vector3 origin, direction;
127
128        mPreprocessor.mViewCellsManager->GetViewPoint(origin);
129        direction = mPreprocessor.mKdTree->GetBox().GetRandomPoint() - origin;
130       
131        const float c = Magnitude(direction);
132
133        if (c <= Limits::Small)
134                return false;
135
136        const float pdf = 1.0f;
137
138        direction *= 1.0f / c;
139        ray = SimpleRay(origin, direction, pdf);
140
141        return true;
142}
143
144/*
145bool ObjectsInteriorDistribution::GenerateSample(SimpleRay &ray) const
146{
147        Vector3 origin, direction;
148
149        // get random object
150        const int i = RandomValue(0, mPreprocessor.mObjects.size() - 1);
151
152        const Intersectable *obj = mPreprocessor.mObjects[i];
153
154        // note: if we load the polygons as meshes,
155        // asymtotically every second sample is lost!
156        origin = obj->GetBox().GetRandomPoint();
157
158        // uniformly distributed direction
159        direction = UniformRandomVector();
160
161        const float c = Magnitude(direction);
162
163        if (c <= Limits::Small)
164                return false;
165
166        const float pdf = 1.0f;
167
168        direction *= 1.0f / c;
169        ray = SimpleRay(origin, direction, pdf);
170
171        return true;
172}*/
173
174}
Note: See TracBrowser for help on using the repository browser.