Subversion Repositories gelsvn

Rev

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

Rev 459 Rev 596
Line 1... Line 1...
1
#include <iostream>
1
#include <iostream>
2
 
2
 
3
#include "Util/Timer.h"
3
#include <Util/Timer.h>
4
#include "Util/ArgExtracter.h"
4
#include <Util/ArgExtracter.h>
5
 
5
 
6
#include "CGLA/Mat4x4f.h"
6
#include <CGLA/Mat4x4d.h>
7
 
7
 
8
 
-
 
9
#include "Geometry/RGrid.h"
8
#include <Geometry/RGrid.h>
-
 
9
#include <Geometry/HGrid.h>
10
#include "Geometry/save_raw.h"
10
#include <Geometry/save_raw.h>
11
#include "Geometry/GridAlgorithm.h"
11
#include <Geometry/GridAlgorithm.h>
12
#include "Geometry/build_bbtree.h"
12
#include <Geometry/build_bbtree.h>
13
#include "Geometry/AABox.h"
13
#include <Geometry/AABox.h>
14
 
14
 
15
#include "HMesh/triangulate.h"
15
#include <HMesh/triangulate.h>
-
 
16
#include <HMesh/Manifold.h>
16
 
17
 
17
#include "HMesh/load.h"
18
#include <HMesh/load.h>
18
#include "HMesh/x3d_load.h"
19
#include <HMesh/x3d_load.h>
19
#include "HMesh/x3d_save.h"
20
#include <HMesh/x3d_save.h>
20
 
21
 
21
using namespace std;
22
using namespace std;
22
using namespace HMesh;
23
using namespace HMesh;
23
using namespace Geometry;
24
using namespace Geometry;
24
using namespace CGLA;
25
using namespace CGLA;
Line 27... Line 28...
27
namespace
28
namespace
28
{
29
{
29
 
30
 
30
	Vec3i vol_dim(64);
31
	Vec3i vol_dim(64);
31
	
32
	
32
		const Mat4x4f fit_bounding_volume(const Vec3f& p0,
33
		const Mat4x4d fit_bounding_volume(const Vec3d& p0,
33
																		const Vec3f& p7,
34
																		const Vec3d& p7,
34
																		float buf_reg) 
35
																		float buf_reg) 
35
	{
36
	{
36
		Vec3f sz = p7 - p0;
37
		Vec3d sz = p7 - p0;
37
		Vec3i dims = vol_dim;
38
		Vec3i dims = vol_dim;
38
		Vec3f scal_vec = (Vec3f(dims)-Vec3f(2*buf_reg+2))/sz;
39
		Vec3d scal_vec = (Vec3d(dims)-Vec3d(2*buf_reg+2))/sz;
39
		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]));
40
		
41
		
41
		Mat4x4f m = translation_Mat4x4f(Vec3f(0)+Vec3f(buf_reg+1));
42
		Mat4x4d m = translation_Mat4x4d(Vec3d(0)+Vec3d(buf_reg+1));
42
		m *= scaling_Mat4x4f(Vec3f(scal));
43
		m *= scaling_Mat4x4d(Vec3d(scal));
43
		m *= translation_Mat4x4f(-p0);
44
		m *= translation_Mat4x4d(-p0);
44
		return m;
45
		return m;
45
	}
46
	}
46
 
47
 
47
	bool do_ray_tests = false;
48
	bool do_ray_tests = false;
48
	bool do_obb = true;
49
	bool do_obb = true;
Line 84... Line 85...
84
 
85
 
85
	DistComp(BBTree* _T): T(_T) {}
86
	DistComp(BBTree* _T): T(_T) {}
86
 
87
 
87
	void operator()(const CGLA::Vec3i& pi, float& vox_val)
88
	void operator()(const CGLA::Vec3i& pi, float& vox_val)
88
	{
89
	{
89
		Vec3f p(pi);
90
		Vec3d p(pi);
90
		vox_val =  T->compute_signed_distance(p);
91
		vox_val =  T->compute_signed_distance(p);
91
		if(flip_normals) vox_val = -vox_val;
92
		if(flip_normals) vox_val = -vox_val;
92
	}
93
	}
93
};
94
};
94
 
95
 
Line 124... Line 125...
124
	{
125
	{
125
		ArgExtracter ae(argc, argv);
126
		ArgExtracter ae(argc, argv);
126
		
127
		
127
		do_aabb = ae.extract("-A");
128
		do_aabb = ae.extract("-A");
128
		do_obb = ae.extract("-O");
129
		do_obb = ae.extract("-O");
129
		ae.extract("-X", vol_dim[0]);
130
		ae.extract("-x", vol_dim[0]);
130
		ae.extract("-Y", vol_dim[1]);
131
		ae.extract("-y", vol_dim[1]);
131
		ae.extract("-Z", vol_dim[2]);
132
		ae.extract("-z", vol_dim[2]);
132
		do_ray_tests = ae.extract("-R");
133
		do_ray_tests = ae.extract("-R");
133
		flip_normals = ae.extract("-f");
134
		flip_normals = ae.extract("-f");
134
		string file = ae.get_last_arg();
135
		string file = ae.get_last_arg();
-
 
136
        
-
 
137
        cout << "loading " << file << "... " << flush; 
135
		load(file, m);
138
		load(file, m);
-
 
139
        cout << " done" << endl;
136
	}
140
	}
137
    else
141
    else
138
	{
142
	{
139
		string fn("../../data/bunny-little.x3d");
143
		string fn("../../data/bunny-little.x3d");
140
		x3d_load(fn, m);
144
		x3d_load(fn, m);
141
	}
145
	}
142
	cout << "Volume dimensions " << vol_dim << endl;
146
	cout << "Volume dimensions " << vol_dim << endl;
143
	if(!m.is_valid())
147
	if(!valid(m))
144
	{
148
	{
145
		cout << "Not a valid manifold" << endl;
149
		cout << "Not a valid manifold" << endl;
146
		exit(0);
150
		exit(0);
147
	}
151
	}
148
	triangulate(m);
152
	triangulate_by_edge_face_split(m);
149
	
153
	
150
	Vec3f p0,p7;
154
	Vec3d p0, p7;
151
	m.get_bbox(p0, p7);
155
	bbox(m, p0, p7);
152
	
156
	
153
	Mat4x4f T = fit_bounding_volume(p0,p7,3);
157
	Mat4x4d T = fit_bounding_volume(p0,p7,10);
-
 
158
    
-
 
159
    cout << "Transformation " << T << endl;
154
	
160
	
155
	for(VertexIter v = m.vertices_begin(); v != m.vertices_end(); ++v)
161
	for(VertexIDIterator v = m.vertices_begin(); v != m.vertices_end(); ++v)
156
		v->pos = T.mul_3D_point(v->pos);
162
		m.pos(*v) = T.mul_3D_point(m.pos(*v));
157
	
163
	
158
	
164
	
159
 	RGridf grid(vol_dim,FLT_MAX);
165
 	RGridf grid(vol_dim,FLT_MAX);
160
	Util::Timer tim;
166
	Util::Timer tim;
161
	
167