summaryrefslogtreecommitdiff
path: root/src/geometry.h
blob: 2b5eacbbdfd6d7cb39a53320256f437a3129cb07 (plain)
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
#ifndef __GEOMETRY_H__
#define __GEOMETRY_H__

struct Material
{
    float *refractive_index;
    float *absorption_length;
    float *scattering_length;
    unsigned int n;
    float step;
    float wavelength0;
};

struct Surface
{
    float *detect;
    float *absorb;
    float *reflect_diffuse;
    float *reflect_specular;
    unsigned int n;
    float step;
    float wavelength0;
};

struct Triangle
{
    float3 v0, v1, v2;
};

struct Geometry
{
    float3 *vertices;
    uint3 *triangles;
    unsigned int *material_codes;
    unsigned int *colors;
    float3 *lower_bounds;
    float3 *upper_bounds;
    unsigned int *node_map;
    unsigned int *node_map_end;
    Material **materials;
    Surface **surfaces;
    unsigned int start_node;
    unsigned int first_node;
};

__device__ Triangle
get_triangle(Geometry *geometry, const unsigned int &i)
{
    uint3 triangle_data = geometry->triangles[i];

    Triangle triangle;
    triangle.v0 = geometry->vertices[triangle_data.x];
    triangle.v1 = geometry->vertices[triangle_data.y];
    triangle.v2 = geometry->vertices[triangle_data.z];

    return triangle;
}

template <class T>
__device__ float
interp_property(T *m, const float &x, const float *fp)
{
    if (x < m->wavelength0)
	return fp[0];

    if (x > (m->wavelength0 + (m->n-1)*m->step))
	return fp[m->n-1];

    int jl = (x-m->wavelength0)/m->step;

    return fp[jl] + (x-(m->wavelength0 + jl*m->step))*(fp[jl+1]-fp[jl])/m->step;
}

#endif