-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstats.h
More file actions
105 lines (82 loc) · 2.76 KB
/
Copy pathstats.h
File metadata and controls
105 lines (82 loc) · 2.76 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
/* File: stats.h; Mode: C++; Tab-width: 3; Author: Simon Flannery; */
#ifndef STATS_H
#define STATS_H
#include <time.h>
#include <limits.h>
#include <stdio.h>
class Stats
{
public:
static void Reset(int w, int h)
{
width = w;
height = h;
start_time = time(NULL);
finish_time = 0;
nonshadow_rays = 0;
shadow_rays = 0;
intersections = 0;
return;
}
static void Finish()
{
finish_time = time(NULL);
return;
}
/* Call for each non-shadow ray. */
static void IncrementNonShadowRays()
{
nonshadow_rays++;
return;
}
/* Call for each shadow ray. */
static void IncrementShadowRays()
{
shadow_rays++;
return;
}
/* To be called when each Object primitive's intersect routine is invoked (but not group and transform).
Note that this is a count of the number of times ray-primitive intersections are computed, not the number of times it returns true. */
static void IncrementIntersections()
{
intersections++; /* WARNING: This might overflow. */
return;
}
static void Print()
{
unsigned long long delta_time = finish_time - start_time;
if (delta_time == 0)
{
delta_time = 1;
}
int seconds = (int) (delta_time % 60);
int minutes = (int) ((delta_time / 60) % 60);
int hours = (int) (delta_time / (60 * 60));
unsigned long long total_rays = nonshadow_rays + shadow_rays;
float rays_per_sec = (float) total_rays / (float) delta_time;
float rays_per_pixel = (float) total_rays / (float) (width * height);
float intersections_per_ray = intersections / (float) total_rays;
printf("\n");
printf("********************************************\n");
printf("SCENE RAY TRACE STATISTICS\n");
printf(" Total time: %02d:%02d:%02d\n", hours, minutes, seconds);
printf(" Total pixels: %d (%dx%d)\n", width * height, width, height);
printf(" Total non-shadow rays: %lld\n", nonshadow_rays);
printf(" Total shadow rays: %lld\n", shadow_rays);
printf(" Total intersections: %lld\n", intersections);
printf(" Rays per second: %0.1f\n", rays_per_sec);
printf(" Rays per pixel: %0.1f\n", rays_per_pixel);
printf(" Intersections per ray: %0.1f\n", intersections_per_ray);
printf("********************************************\n");
return;
}
protected:
private:
static int width;
static int height;
static unsigned long long start_time, finish_time;
static unsigned long long nonshadow_rays;
static unsigned long long shadow_rays;
static unsigned long long intersections;
};
#endif