Subversion Repositories gelsvn

Rev

Rev 309 | Rev 382 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 309 Rev 341
Line 11... Line 11...
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
 
-
 
17
#include "HMesh/obj_load.h"
16
#include "HMesh/x3d_load.h"
18
#include "HMesh/x3d_load.h"
17
#include "HMesh/x3d_save.h"
19
#include "HMesh/x3d_save.h"
18
 
20
 
19
using namespace std;
21
using namespace std;
20
using namespace HMesh;
22
using namespace HMesh;
Line 120... Line 122...
120
{	
122
{	
121
	// LOAD OBJ
123
	// LOAD OBJ
122
    Manifold m;
124
    Manifold m;
123
    if(argc>1)
125
    if(argc>1)
124
	{
126
	{
125
	  ArgExtracter ae(argc, argv);
127
		ArgExtracter ae(argc, argv);
126
 
128
		
127
	  do_aabb = ae.extract("-A");
129
		do_aabb = ae.extract("-A");
128
	  do_ray_tests = ae.extract("-R");
130
		do_ray_tests = ae.extract("-R");
129
	  flip_normals = ae.extract("-f");
131
		flip_normals = ae.extract("-f");
-
 
132
		string file = ae.get_last_arg();
-
 
133
		if(file.substr(file.length()-4,file.length())==".obj")
-
 
134
		{
-
 
135
			obj_load(file, m);
130
 
136
		}
-
 
137
		else
131
	  x3d_load(ae.get_last_arg(), m);
138
			x3d_load(file, m);
132
	}
139
	}
133
    else
140
    else
134
	{
141
	{
135
	  string fn("../../data/bunny-little.x3d");
142
		string fn("../../data/bunny-little.x3d");
136
	  x3d_load(fn, m);
143
		x3d_load(fn, m);
137
	}
144
	}
138
 
145
	
139
	if(!m.is_valid())
146
	if(!m.is_valid())
140
		{
147
	{
141
			cout << "Not a valid manifold" << endl;
148
		cout << "Not a valid manifold" << endl;
142
			exit(0);
149
		exit(0);
143
		}
150
	}
144
	triangulate(m);
151
	triangulate(m);
145
 
152
	
146
	Vec3f p0,p7;
153
	Vec3f p0,p7;
147
	m.get_bbox(p0, p7);
154
	m.get_bbox(p0, p7);
148
 
155
	
149
	Mat4x4f T = fit_bounding_volume(p0,p7,3);
156
	Mat4x4f T = fit_bounding_volume(p0,p7,3);
150
 
157
	
151
	for(VertexIter v = m.vertices_begin(); v != m.vertices_end(); ++v)
158
	for(VertexIter v = m.vertices_begin(); v != m.vertices_end(); ++v)
152
			v->pos = T.mul_3D_point(v->pos);
159
		v->pos = T.mul_3D_point(v->pos);
153
	
160
	
154
	
161
	
155
 	RGridf grid(vol_dim,FLT_MAX);
162
 	RGridf grid(vol_dim,FLT_MAX);
156
	Util::Timer tim;
163
	Util::Timer tim;
157
 
164
	
158
 
165
	
159
	float T_build_obb=0, T_build_aabb=0, T_dist_obb=0, 
166
	float T_build_obb=0, T_build_aabb=0, T_dist_obb=0, 
160
		T_dist_aabb=0, T_ray_obb=0, T_ray_aabb=0;
167
		T_dist_aabb=0, T_ray_obb=0, T_ray_aabb=0;
161
 
168
	
162
	if(do_obb)
169
	if(do_obb)
163
	{
170
	{
164
		tim.start();
171
		tim.start();
165
		OBBTree obb_tree;
172
		OBBTree obb_tree;
166
		build_OBBTree(m, obb_tree);
173
		build_OBBTree(m, obb_tree);
Line 170... Line 177...
170
		DistCompCache<OBBTree> dist(&obb_tree);
177
		DistCompCache<OBBTree> dist(&obb_tree);
171
		for_each_voxel(grid, dist);
178
		for_each_voxel(grid, dist);
172
		T_dist_obb = tim.get_secs();
179
		T_dist_obb = tim.get_secs();
173
		
180
		
174
		save_raw_float("obb_dist.raw", grid);
181
		save_raw_float("obb_dist.raw", grid);
175
 
182
		
176
		if(do_ray_tests)
183
		if(do_ray_tests)
177
			{
184
		{
178
				tim.start();
185
			tim.start();
179
				RayCast<OBBTree> ray(&obb_tree);
186
			RayCast<OBBTree> ray(&obb_tree);
180
				for_each_voxel(grid, ray);
187
			for_each_voxel(grid, ray);
181
				T_ray_obb = tim.get_secs();
188
			T_ray_obb = tim.get_secs();
182
				
189
			
183
				save_raw_float("obb_ray.raw", grid);
190
			save_raw_float("obb_ray.raw", grid);
184
			}
191
		}
185
	}
192
	}
186
 
193
	
187
	if(do_aabb)
194
	if(do_aabb)
188
	{
195
	{
189
		tim.start();
196
		tim.start();
190
		AABBTree aabb_tree;
197
		AABBTree aabb_tree;
191
		build_AABBTree(m, aabb_tree);
198
		build_AABBTree(m, aabb_tree);
Line 195... Line 202...
195
		DistCompCache<AABBTree> dist(&aabb_tree);
202
		DistCompCache<AABBTree> dist(&aabb_tree);
196
		for_each_voxel(grid, dist);
203
		for_each_voxel(grid, dist);
197
		T_dist_aabb = tim.get_secs();
204
		T_dist_aabb = tim.get_secs();
198
		
205
		
199
		save_raw_float("aabb_dist.raw", grid);
206
		save_raw_float("aabb_dist.raw", grid);
200
 
-
 
201
		if(do_ray_tests)
-
 
202
			{
-
 
203
				tim.start();
-
 
204
				RayCast<AABBTree> ray(&aabb_tree);
-
 
205
				for_each_voxel(grid, ray);
-
 
206
				T_ray_aabb = tim.get_secs();
-
 
207
		
207
		
-
 
208
		if(do_ray_tests)
-
 
209
		{
-
 
210
			tim.start();
-
 
211
			RayCast<AABBTree> ray(&aabb_tree);
-
 
212
			for_each_voxel(grid, ray);
-
 
213
			T_ray_aabb = tim.get_secs();
-
 
214
			
208
				save_raw_float("aabb_ray.raw", grid);
215
			save_raw_float("aabb_ray.raw", grid);
209
			}
216
		}
210
	}
217
	}
211
	cout.width(10);
218
	cout.width(10);
212
	cout << "Poly";
219
	cout << "Poly";
213
	cout.width(11);
220
	cout.width(11);
214
	cout <<"build_obb";
221
	cout <<"build_obb";
Line 221... Line 228...
221
	cout.width(10);
228
	cout.width(10);
222
	cout << "ray_obb" ;
229
	cout << "ray_obb" ;
223
	cout.width(10);
230
	cout.width(10);
224
	cout << "ray_aabb";
231
	cout << "ray_aabb";
225
	cout << endl;
232
	cout << endl;
226
 
233
	
227
	cout.precision(4);
234
	cout.precision(4);
228
	cout.width(10);
235
	cout.width(10);
229
	cout << m.no_faces() << " ";
236
	cout << m.no_faces() << " ";
230
	cout.width(10);
237
	cout.width(10);
231
	cout << T_build_obb;
238
	cout << T_build_obb;