SLProject  4.2.000
A platform independent 3D computer graphics framework for desktop OS, Android, iOS and online in web browsers
SLRaySamples2D Class Reference

Class for 2D disk sample points. More...

#include <SLRaySamples2D.h>

Public Member Functions

 SLRaySamples2D ()
 
 ~SLRaySamples2D ()
 
void samples (SLuint x, SLuint y, SLbool evenlyDistributed=true)
 Resets the sample point array by the sqrt of the no. of samples. More...
 
void point (SLuint x, SLuint y, SLVec2f point)
 
SLuint samplesX ()
 
SLuint samplesY ()
 
SLuint samples ()
 
SLVec2f point (SLuint x, SLuint y)
 
SLuint sizeInBytes ()
 

Private Member Functions

void distribConcentric (SLbool evenlyDistributed)
 
SLVec2f mapSquareToDisc (SLfloat x, SLfloat y)
 

Private Attributes

SLuint _samplesX
 No. of samples in x direction. More...
 
SLuint _samplesY
 No. of samples in y direction. More...
 
SLuint _samples
 No. of samples = samplesX x samplesY. More...
 
SLVVec2f _points
 samplepoints for distributed tracing More...
 

Detailed Description

Class for 2D disk sample points.

Definition at line 18 of file SLRaySamples2D.h.

Constructor & Destructor Documentation

◆ SLRaySamples2D()

SLRaySamples2D::SLRaySamples2D ( )
inline

Definition at line 21 of file SLRaySamples2D.h.

21 { samples(1, 1); }
SLuint samples()

◆ ~SLRaySamples2D()

SLRaySamples2D::~SLRaySamples2D ( )
inline

Definition at line 22 of file SLRaySamples2D.h.

22 {}

Member Function Documentation

◆ distribConcentric()

void SLRaySamples2D::distribConcentric ( SLbool  evenlyDistributed)
private

Makes concentric 2D-samples points within a circle of certain radius. With the parameter evenlyDistributed=false will the samplepoints be denser towards the center.

Definition at line 31 of file SLRaySamples2D.cpp.

32 {
33  if (_points.size())
34  {
35  SLfloat halfDeltaPhi = Utils::TWOPI / _samplesY * 0.5f;
36  SLfloat phi, r, last_r = 1.0f;
37 
38  // Loop over radius r and angle phi
39  for (SLint iR = (SLint)_samplesX - 1; iR >= 0; --iR)
40  {
41  r = ((SLfloat)iR) / _samplesX;
42  if (evenlyDistributed) r = sqrt(r);
43  r += (last_r - r) * 0.5f;
44 
45  // every 2nd circle is rotated by have delta phi for better distribution
46  SLfloat iModPhi = (iR % 2) * halfDeltaPhi;
47  for (SLint iPhi = (SLint)_samplesY - 1; iPhi >= 0; --iPhi)
48  {
49  phi = Utils::TWOPI * ((SLfloat)iPhi) / _samplesY + iModPhi;
50  point((SLuint)iR, (SLuint)iPhi, SLVec2f(r * cos(phi), r * sin(phi)));
51  }
52  last_r = r;
53  }
54  }
55 }
float SLfloat
Definition: SL.h:173
unsigned int SLuint
Definition: SL.h:171
int SLint
Definition: SL.h:170
SLVec2< SLfloat > SLVec2f
Definition: SLVec2.h:141
SLVVec2f _points
samplepoints for distributed tracing
SLuint _samplesX
No. of samples in x direction.
void point(SLuint x, SLuint y, SLVec2f point)
SLuint _samplesY
No. of samples in y direction.
static const float TWOPI
Definition: Utils.h:240

◆ mapSquareToDisc()

SLVec2f SLRaySamples2D::mapSquareToDisc ( SLfloat  x,
SLfloat  y 
)
private

Concentric mapping of a x,y-position Code taken from Peter Shirley out of "Realistic Ray Tracing"

Definition at line 60 of file SLRaySamples2D.cpp.

62 {
63  SLfloat phi, r, u, v;
64  SLfloat a = 2 * x - 1;
65  SLfloat b = 2 * y - 1;
66 
67  if (a > -b)
68  {
69  if (a > b)
70  {
71  r = a;
72  phi = (Utils::PI / 4) * (b / a);
73  }
74  else
75  {
76  r = b;
77  phi = (Utils::PI / 4) * (2 - a / b);
78  }
79  }
80  else
81  {
82  if (a < b)
83  {
84  r = -a;
85  phi = (Utils::PI / 4) * (4 + b / a);
86  }
87  else
88  {
89  r = -b;
90  if (b != 0)
91  {
92  phi = (Utils::PI / 4) * (6 - a / b);
93  }
94  else
95  phi = 0;
96  }
97  }
98  u = r * cos(phi);
99  v = r * sin(phi);
100  return SLVec2f(u, v);
101 }
static const float PI
Definition: Utils.h:237

◆ point() [1/2]

SLVec2f SLRaySamples2D::point ( SLuint  x,
SLuint  y 
)
inline

Definition at line 34 of file SLRaySamples2D.h.

34 { return _points[x * _samplesY + y]; }

◆ point() [2/2]

void SLRaySamples2D::point ( SLuint  x,
SLuint  y,
SLVec2f  point 
)
inline

Definition at line 26 of file SLRaySamples2D.h.

27  {
28  _points[x * _samplesY + y].set(point);
29  }

◆ samples() [1/2]

SLuint SLRaySamples2D::samples ( )
inline

Definition at line 33 of file SLRaySamples2D.h.

33 { return _samples; }
SLuint _samples
No. of samples = samplesX x samplesY.

◆ samples() [2/2]

void SLRaySamples2D::samples ( SLuint  x,
SLuint  y,
SLbool  evenlyDistributed = true 
)

Resets the sample point array by the sqrt of the no. of samples.

Definition at line 16 of file SLRaySamples2D.cpp.

17 {
18  assert(x > 0 && y > 0);
19  _samplesX = x;
20  _samplesY = y;
21  _samples = x * y;
22  _points.resize(_samples);
23  if (_samples > 1) distribConcentric(evenlyDistributed);
24 }
void distribConcentric(SLbool evenlyDistributed)

◆ samplesX()

SLuint SLRaySamples2D::samplesX ( )
inline

Definition at line 31 of file SLRaySamples2D.h.

31 { return _samplesX; }

◆ samplesY()

SLuint SLRaySamples2D::samplesY ( )
inline

Definition at line 32 of file SLRaySamples2D.h.

32 { return _samplesY; }

◆ sizeInBytes()

SLuint SLRaySamples2D::sizeInBytes ( )
inline

Definition at line 35 of file SLRaySamples2D.h.

35 { return (SLuint)(_points.size() * sizeof(SLVec2f)); }

Member Data Documentation

◆ _points

SLVVec2f SLRaySamples2D::_points
private

samplepoints for distributed tracing

Definition at line 44 of file SLRaySamples2D.h.

◆ _samples

SLuint SLRaySamples2D::_samples
private

No. of samples = samplesX x samplesY.

Definition at line 43 of file SLRaySamples2D.h.

◆ _samplesX

SLuint SLRaySamples2D::_samplesX
private

No. of samples in x direction.

Definition at line 41 of file SLRaySamples2D.h.

◆ _samplesY

SLuint SLRaySamples2D::_samplesY
private

No. of samples in y direction.

Definition at line 42 of file SLRaySamples2D.h.


The documentation for this class was generated from the following files: