Subversion Repositories gelsvn

Rev

Rev 443 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 443 Rev 595
-
 
1
/* ----------------------------------------------------------------------- *
-
 
2
 * This file is part of GEL, http://www.imm.dtu.dk/GEL
-
 
3
 * Copyright (C) the authors and DTU Informatics
-
 
4
 * For license and list of authors, see ../../doc/intro.pdf
-
 
5
 * ----------------------------------------------------------------------- */
-
 
6
 
-
 
7
/**
-
 
8
 * @file BBox.h
-
 
9
 * @brief Bounding box class (ancestor of AABox and OBox)
-
 
10
 */
-
 
11
 
1
#ifndef __GEOMETRY_BBOX_H__
12
#ifndef __GEOMETRY_BBOX_H__
2
#define __GEOMETRY_BBOX_H__
13
#define __GEOMETRY_BBOX_H__
3
 
14
 
4
#include "CGLA/Vec3f.h"
15
#include "CGLA/Vec3f.h"
5
 
16
 
6
#include "Ray.h"
17
#include "Ray.h"
7
 
18
 
8
namespace Geometry 
19
namespace Geometry 
9
{
20
{
10
  struct ISectTri 
21
  struct ISectTri 
11
  {
22
  {
12
    CGLA::Vec3f point0;
23
    CGLA::Vec3f point0;
13
    CGLA::Vec3f point1;
24
    CGLA::Vec3f point1;
14
    CGLA::Vec3f point2;
25
    CGLA::Vec3f point2;
15
    
26
    
16
    CGLA::Vec3f edge0; // Optimization
27
    CGLA::Vec3f edge0; // Optimization
17
    CGLA::Vec3f edge1; // Optimization
28
    CGLA::Vec3f edge1; // Optimization
18
    unsigned int mesh_id;
29
    unsigned int mesh_id;
19
    unsigned int tri_id; // pad to 48 bytes for cache alignment purposes
30
    unsigned int tri_id; // pad to 48 bytes for cache alignment purposes
20
  };
31
  };
21
 
32
 
22
  struct TriAccel
33
  struct TriAccel
23
  {
34
  {
24
    // first 16 byte half cache line
35
    // first 16 byte half cache line
25
    // plane:
36
    // plane:
26
    double n_u;  //!< == normal.u / normal.k
37
    double n_u;  //!< == normal.u / normal.k
27
    double n_v;  //!< == normal.v / normal.k
38
    double n_v;  //!< == normal.v / normal.k
28
    double n_d;  //!< constant of plane equation
39
    double n_d;  //!< constant of plane equation
29
    int k;       // projection dimension
40
    int k;       // projection dimension
30
 
41
 
31
    // second 16 byte half cache line
42
    // second 16 byte half cache line
32
    // line equation for line ac
43
    // line equation for line ac
33
    double b_nu;
44
    double b_nu;
34
    double b_nv;
45
    double b_nv;
35
    double b_d;
46
    double b_d;
36
    unsigned int mesh_id;
47
    unsigned int mesh_id;
37
 
48
 
38
    // third 16 byte half cache line
49
    // third 16 byte half cache line
39
    // line equation for line ab
50
    // line equation for line ab
40
    double c_nu;
51
    double c_nu;
41
    double c_nv;
52
    double c_nv;
42
    double c_d;
53
    double c_d;
43
 
54
 
44
    unsigned int tri_id; // pad to 48 bytes for cache alignment purposes
55
    unsigned int tri_id; // pad to 48 bytes for cache alignment purposes
45
  };
56
  };
46
 
57
 
47
  struct BBox 
58
  struct BBox 
48
  {
59
  {
49
    CGLA::Vec3f min_corner;
60
    CGLA::Vec3f min_corner;
50
    CGLA::Vec3f max_corner;
61
    CGLA::Vec3f max_corner;
51
 
62
 
52
    void intersect_min_max(Ray &ray, double &t_min, double &t_max) const ;
63
    void intersect_min_max(Ray &ray, double &t_min, double &t_max) const ;
53
    bool intersect(Ray &ray);
64
    bool intersect(Ray &ray);
54
    bool ray_triangle(CGLA::Vec3f &ray_start, CGLA::Vec3f &ray_end, ISectTri &tri);
65
    bool ray_triangle(CGLA::Vec3f &ray_start, CGLA::Vec3f &ray_end, ISectTri &tri);
55
    bool intersect_edge_box(CGLA::Vec3f &ray_start, CGLA::Vec3f &ray_end);
66
    bool intersect_edge_box(CGLA::Vec3f &ray_start, CGLA::Vec3f &ray_end);
56
    bool intersect_triangle(ISectTri &tri);
67
    bool intersect_triangle(ISectTri &tri);
57
    bool in_interval(double min_limit, double test_value, double max_limit);
68
    bool in_interval(double min_limit, double test_value, double max_limit);
58
    void compute_bbox(std::vector<ISectTri> &isectmesh);
69
    void compute_bbox(std::vector<ISectTri> &isectmesh);
59
    bool intersect_triangle_left(ISectTri &tri, double plane, int axis);
70
    bool intersect_triangle_left(ISectTri &tri, double plane, int axis);
60
    bool intersect_triangle_right(ISectTri &tri, double plane, int axis);
71
    bool intersect_triangle_right(ISectTri &tri, double plane, int axis);
61
    double area();
72
    double area();
62
  };
73
  };
63
}
74
}
64
 
75
 
65
#endif
76
#endif
66
 
77