Subversion Repositories gelsvn

Rev

Rev 631 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 631 Rev 643
Line 25... Line 25...
25
using namespace CGLA;
25
using namespace CGLA;
26
using namespace Util;
26
using namespace Util;
27
 
27
 
28
namespace
28
namespace
29
{
29
{
30
 
30
    
31
	Vec3i vol_dim(64);
31
	Vec3i vol_dim(64);
32
	
32
	
33
		const Mat4x4d fit_bounding_volume(const Vec3d& p0,
33
    const Mat4x4d fit_bounding_volume(const Vec3d& p0,
34
																		const Vec3d& p7,
34
                                      const Vec3d& p7,
35
																		float buf_reg) 
35
                                      float buf_reg)
36
	{
36
	{
37
		Vec3d sz = p7 - p0;
37
		Vec3d sz = p7 - p0;
38
		Vec3i dims = vol_dim;
38
		Vec3i dims = vol_dim;
39
		Vec3d scal_vec = (Vec3d(dims)-Vec3d(2*buf_reg+2))/sz;
39
		Vec3d scal_vec = (Vec3d(dims)-Vec3d(2*buf_reg+2))/sz;
40
		float scal = min(scal_vec[0], min(scal_vec[1],scal_vec[2]));
40
		float scal = min(scal_vec[0], min(scal_vec[1],scal_vec[2]));
Line 42... Line 42...
42
		Mat4x4d m = translation_Mat4x4d(Vec3d(0)+Vec3d(buf_reg+1));
42
		Mat4x4d m = translation_Mat4x4d(Vec3d(0)+Vec3d(buf_reg+1));
43
		m *= scaling_Mat4x4d(Vec3d(scal));
43
		m *= scaling_Mat4x4d(Vec3d(scal));
44
		m *= translation_Mat4x4d(-p0);
44
		m *= translation_Mat4x4d(-p0);
45
		return m;
45
		return m;
46
	}
46
	}
47
 
47
    
48
	bool do_ray_tests = false;
48
	bool do_ray_tests = false;
49
	bool do_obb = true;
49
	bool do_obb = true;
50
	bool do_aabb = false;
50
	bool do_aabb = false;
51
	bool flip_normals = false;
51
	bool flip_normals = false;
52
 
52
    
53
}
53
}
54
 
54
 
55
 
55
 
56
 
56
 
57
template<class BBTree>
57
template<class BBTree>
Line 59... Line 59...
59
{
59
{
60
	BBTree *T;
60
	BBTree *T;
61
	float old_d;
61
	float old_d;
62
	Vec3i old_p;
62
	Vec3i old_p;
63
public:
63
public:
64
 
64
    
65
	DistCompCache(BBTree* _T): T(_T), old_p(-99999) {}
65
	DistCompCache(BBTree* _T): T(_T), old_p(-99999) {}
66
 
66
    
67
	void operator()(const CGLA::Vec3i& pi, float& vox_val)
67
	void operator()(const CGLA::Vec3i& pi, float& vox_val)
68
	{
68
	{
69
		Vec3f p(pi);
69
		Vec3f p(pi);
70
 		if(sqr_length(pi-old_p)==1)
70
 		if(sqr_length(pi-old_p)==1)
71
 				vox_val = T->compute_signed_distance(p,CGLA::sqr(1.001+fabs(old_d)));
71
            vox_val = T->compute_signed_distance(p,CGLA::sqr(1.001+fabs(old_d)));
72
 		else
72
 		else
73
			vox_val = T->compute_signed_distance(p);
73
			vox_val = T->compute_signed_distance(p);
74
		if(flip_normals) vox_val = -vox_val;
74
		if(flip_normals) vox_val = -vox_val;
75
		old_p = pi;
75
		old_p = pi;
76
		old_d = vox_val;		
76
		old_d = vox_val;
77
	}
77
	}
78
};
78
};
79
 
79
 
80
template<class BBTree>
80
template<class BBTree>
81
class DistComp
81
class DistComp
82
{
82
{
83
	BBTree *T;
83
	BBTree *T;
84
public:
84
public:
85
 
85
    
86
	DistComp(BBTree* _T): T(_T) {}
86
	DistComp(BBTree* _T): T(_T) {}
87
 
87
    
88
	void operator()(const CGLA::Vec3i& pi, float& vox_val)
88
	void operator()(const CGLA::Vec3i& pi, float& vox_val)
89
	{
89
	{
90
		Vec3d p(pi);
90
		Vec3d p(pi);
91
		vox_val =  T->compute_signed_distance(p);
91
		vox_val =  T->compute_signed_distance(p);
92
		if(flip_normals) vox_val = -vox_val;
92
		if(flip_normals) vox_val = -vox_val;
Line 96... Line 96...
96
 
96
 
97
template<class BBTree>
97
template<class BBTree>
98
class RayCast
98
class RayCast
99
{
99
{
100
	BBTree *T;
100
	BBTree *T;
101
 
101
    
102
public:
102
public:
103
	
103
	
104
	RayCast(BBTree* _T): T(_T) {}
104
	RayCast(BBTree* _T): T(_T) {}
105
 
105
    
106
	void operator()(const CGLA::Vec3i& pi, float& vox_val)
106
	void operator()(const CGLA::Vec3i& pi, float& vox_val)
107
	{
107
	{
108
		int n = T->intersect_cnt(Vec3f(pi), Vec3f(1,0,0));
108
		int n = T->intersect_cnt(Vec3f(pi), Vec3f(1,0,0));
109
		if(n%2==0)
109
		if(n%2==0)
110
			vox_val=1000;
110
			vox_val=1000;
Line 116... Line 116...
116
 
116
 
117
typedef RGrid<float> RGridf;
117
typedef RGrid<float> RGridf;
118
 
118
 
119
 
119
 
120
int main(int argc, char** argv)
120
int main(int argc, char** argv)
121
{	
121
{
122
	// LOAD OBJ
122
	// LOAD OBJ
123
    Manifold m;
123
    Manifold m;
124
    string fn;
124
    string fn;
125
    if(argc>1)
125
    if(argc>1)
126
	{
126
	{
Line 159... Line 159...
159
	
159
	
160
 	RGridf grid(vol_dim,FLT_MAX);
160
 	RGridf grid(vol_dim,FLT_MAX);
161
	Util::Timer tim;
161
	Util::Timer tim;
162
	
162
	
163
	
163
	
164
	float T_build_obb=0, T_build_aabb=0, T_dist_obb=0, 
164
	float T_build_obb=0, T_build_aabb=0, T_dist_obb=0,
165
		T_dist_aabb=0, T_ray_obb=0, T_ray_aabb=0;
165
    T_dist_aabb=0, T_ray_obb=0, T_ray_aabb=0;
166
	
166
	
167
	if(do_obb)
167
	if(do_obb)
168
	{
168
	{
169
		cout << "Building OBB Tree" << endl;
169
		cout << "Building OBB Tree" << endl;
170
		tim.start();
170
		tim.start();