Subversion Repositories gelsvn

Rev

Rev 595 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
595 jab 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
 
443 jab 12
#ifndef __GEOMETRY_BBOX_H__
13
#define __GEOMETRY_BBOX_H__
304 jab 14
 
601 jab 15
#include "../CGLA/Vec3f.h"
304 jab 16
 
17
#include "Ray.h"
18
 
19
namespace Geometry 
20
{
21
  struct ISectTri 
22
  {
23
    CGLA::Vec3f point0;
24
    CGLA::Vec3f point1;
25
    CGLA::Vec3f point2;
26
 
27
    CGLA::Vec3f edge0; // Optimization
28
    CGLA::Vec3f edge1; // Optimization
29
    unsigned int mesh_id;
30
    unsigned int tri_id; // pad to 48 bytes for cache alignment purposes
31
  };
32
 
33
  struct TriAccel
34
  {
35
    // first 16 byte half cache line
36
    // plane:
37
    double n_u;  //!< == normal.u / normal.k
38
    double n_v;  //!< == normal.v / normal.k
39
    double n_d;  //!< constant of plane equation
40
    int k;       // projection dimension
41
 
42
    // second 16 byte half cache line
43
    // line equation for line ac
44
    double b_nu;
45
    double b_nv;
46
    double b_d;
47
    unsigned int mesh_id;
48
 
49
    // third 16 byte half cache line
50
    // line equation for line ab
51
    double c_nu;
52
    double c_nv;
53
    double c_d;
54
 
55
    unsigned int tri_id; // pad to 48 bytes for cache alignment purposes
56
  };
57
 
58
  struct BBox 
59
  {
60
    CGLA::Vec3f min_corner;
61
    CGLA::Vec3f max_corner;
62
 
63
    void intersect_min_max(Ray &ray, double &t_min, double &t_max) const ;
64
    bool intersect(Ray &ray);
65
    bool ray_triangle(CGLA::Vec3f &ray_start, CGLA::Vec3f &ray_end, ISectTri &tri);
66
    bool intersect_edge_box(CGLA::Vec3f &ray_start, CGLA::Vec3f &ray_end);
67
    bool intersect_triangle(ISectTri &tri);
68
    bool in_interval(double min_limit, double test_value, double max_limit);
69
    void compute_bbox(std::vector<ISectTri> &isectmesh);
70
    bool intersect_triangle_left(ISectTri &tri, double plane, int axis);
71
    bool intersect_triangle_right(ISectTri &tri, double plane, int axis);
72
    double area();
73
  };
74
}
75
 
76
#endif