Subversion Repositories gelsvn

Rev

Rev 595 | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

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