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 Triangle.h
-
 
9
 * @brief Triangle class for use with bbox hierarchies.
-
 
10
 */
-
 
11
 
1
#ifndef __GEOMETRY_TRIANGLE_H
12
#ifndef __GEOMETRY_TRIANGLE_H
2
#define __GEOMETRY_TRIANGLE_H
13
#define __GEOMETRY_TRIANGLE_H
3
 
14
 
4
#include "CGLA/Vec2f.h"
15
#include "CGLA/Vec2f.h"
5
#include "CGLA/Vec3f.h"
16
#include "CGLA/Vec3f.h"
6
#include "CGLA/Mat3x3f.h"
17
#include "CGLA/Mat3x3f.h"
7
 
18
 
8
#define COMPUTE_SIGN
-
 
9
 
-
 
10
namespace Geometry
19
namespace Geometry
11
{
20
{
12
 
21
 
13
class Triangle
22
class Triangle
14
{
23
{
15
	CGLA::Vec3f vert[3];
24
	CGLA::Vec3f vert[3];
16
	CGLA::Vec3f edge[3];
25
	CGLA::Vec3f edge[3];
17
 
26
 
18
#ifdef COMPUTE_SIGN
-
 
19
	CGLA::Vec3f vert_norm[3];
27
	CGLA::Vec3f vert_norm[3];
20
	CGLA::Vec3f edge_norm[3];
28
	CGLA::Vec3f edge_norm[3];
21
#endif
-
 
22
	CGLA::Vec3f face_norm;
29
	CGLA::Vec3f face_norm;
23
 
30
 
24
	CGLA::Vec3f tri_plane_edge_norm[3];
31
	CGLA::Vec3f tri_plane_edge_norm[3];
25
	float edge_len[3];
32
	float edge_len[3];
26
	
33
	
27
 public:
34
 public:
28
 
35
 
29
	Triangle() {}
36
	Triangle() {}
30
	
37
	
31
	Triangle(const CGLA::Vec3f& _v0, 
38
	Triangle(const CGLA::Vec3f& _v0, 
32
					 const CGLA::Vec3f& _v1, 
39
					 const CGLA::Vec3f& _v1, 
33
					 const CGLA::Vec3f& _v2,
40
					 const CGLA::Vec3f& _v2,
34
 
41
 
35
					 const CGLA::Vec3f& _vn0,
42
					 const CGLA::Vec3f& _vn0,
36
					 const CGLA::Vec3f& _vn1,
43
					 const CGLA::Vec3f& _vn1,
37
					 const CGLA::Vec3f& _vn2,
44
					 const CGLA::Vec3f& _vn2,
38
 
45
 
39
					 const CGLA::Vec3f& _en0,
46
					 const CGLA::Vec3f& _en0,
40
					 const CGLA::Vec3f& _en1,
47
					 const CGLA::Vec3f& _en1,
41
					 const CGLA::Vec3f& _en2);
48
					 const CGLA::Vec3f& _en2);
42
 
49
 
43
	bool intersect(const CGLA::Vec3f&, const CGLA::Vec3f&, float&) const;
50
	bool intersect(const CGLA::Vec3f&, const CGLA::Vec3f&, float&) const;
44
 
51
 
45
	const CGLA::Vec3f get_pmin() const 
52
	const CGLA::Vec3f get_pmin() const 
46
	{
53
	{
47
		return v_min(vert[0],v_min(vert[1],vert[2]));
54
		return v_min(vert[0],v_min(vert[1],vert[2]));
48
	}
55
	}
49
 
56
 
50
	const CGLA::Vec3f get_pmax() const 
57
	const CGLA::Vec3f get_pmax() const 
51
	{
58
	{
52
		return v_max(vert[0],v_max(vert[1],vert[2]));
59
		return v_max(vert[0],v_max(vert[1],vert[2]));
53
	}
60
	}
54
 
61
 
55
	const CGLA::Vec3f centre() const
62
	const CGLA::Vec3f centre() const
56
		{
63
		{
57
			return (vert[0]+vert[1]+vert[2])/3.0f;
64
			return (vert[0]+vert[1]+vert[2])/3.0f;
58
		}
65
		}
59
 
66
 
60
	const float area() const 
67
	const float area() const 
61
		{
68
		{
62
			return 0.5 * (cross(edge[0],-edge[2])).length();
69
			return 0.5 * (cross(edge[0],-edge[2])).length();
63
		}
70
		}
64
 
71
 
65
	const CGLA::Vec3f get_centre() const 
72
	const CGLA::Vec3f get_centre() const 
66
	{
73
	{
67
		CGLA::Vec3f pmin = get_pmin();
74
		CGLA::Vec3f pmin = get_pmin();
68
		CGLA::Vec3f pmax = get_pmax();
75
		CGLA::Vec3f pmax = get_pmax();
69
		return (pmax-pmin)/2.0f+pmin;
76
		return (pmax-pmin)/2.0f+pmin;
70
	}
77
	}
71
 
78
 
72
	bool signed_distance(const CGLA::Vec3f& p, float& sq_dist, float& sgn) const;
79
	bool signed_distance(const CGLA::Vec3f& p, float& sq_dist, float& sgn) const;
73
 
80
 
74
	CGLA::Vec3f get_v0() const {return vert[0];}
81
	CGLA::Vec3f get_v0() const {return vert[0];}
75
	CGLA::Vec3f get_v1() const {return vert[1];}
82
	CGLA::Vec3f get_v1() const {return vert[1];}
76
	CGLA::Vec3f get_v2() const {return vert[2];}
83
	CGLA::Vec3f get_v2() const {return vert[2];}
77
 
84
 
78
	const CGLA::Vec3f& get_edge(int i) const {return edge[i];}
85
	const CGLA::Vec3f& get_edge(int i) const {return edge[i];}
79
 
86
 
80
	const CGLA::Vec3f& get_face_norm() const {return face_norm;}
87
	const CGLA::Vec3f& get_face_norm() const {return face_norm;}
81
	
88
	
82
};	
89
};	
83
 
90
 
84
}
91
}
85
#endif
92
#endif
86
 
93