Subversion Repositories gelsvn

Rev

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

Rev 72 Rev 94
Line 5... Line 5...
5
#include "CGLA/Mat2x2f.h"
5
#include "CGLA/Mat2x2f.h"
6
#include "Geometry/Polygonizer.h"
6
#include "Geometry/Polygonizer.h"
7
#include "Geometry/TrilinFilter.h"
7
#include "Geometry/TrilinFilter.h"
8
#include "Geometry/load_raw.h"
8
#include "Geometry/load_raw.h"
9
#include "HMeshUtil/build_manifold.h"
9
#include "HMeshUtil/build_manifold.h"
10
#include "HMeshUtil/x3d_save.h"
10
#include "HMeshUtil/obj_save.h"
11
#include "Util/ArgExtracter.h"
11
#include "Util/ArgExtracter.h"
12
 
12
 
13
using namespace HMesh;
13
using namespace HMesh;
14
using namespace HMeshUtil;
14
using namespace HMeshUtil;
15
using namespace Geometry;
15
using namespace Geometry;
16
using namespace CGLA;
16
using namespace CGLA;
17
using namespace Util;
17
using namespace Util;
18
using namespace std;
18
using namespace std;
19
 
19
 
20
typedef RGrid<unsigned char> RGridb;
-
 
21
 
20
 
-
 
21
/* Create an implicit function: Just union of two spheres */
22
class VolumeImplicit: public ImplicitFunction
22
class TestImplicit: public ImplicitFunction
23
{
23
{
24
		TrilinFilter<RGridb> trifi;
24
		const Vec3f c0, c1;
25
		
-
 
26
public:
25
public:
27
		
26
		
28
		VolumeImplicit(const RGridb* g): trifi(g) {}
27
		TestImplicit(): c0(0,0,0), c1(2,2,2)  {}
29
		
28
		
30
		float eval(float x,float y,float z) 
29
		float eval(float x,float y,float z) 
31
				{
30
				{
32
						if(trifi.in_domain(Vec3f(x,y,z)))
31
						Vec3f p(x,y,z);
33
						{
-
 
34
								unsigned char v =trifi(Vec3f(x,y,z));
-
 
35
								return static_cast<float>(v);
32
						return min(length(p-c0)-2.0f,length(p-c1)-2.0f);
36
						}
-
 
37
						return 0;
-
 
38
				}
33
				}
39
};
34
};
40
 
35
 
41
 
36
 
42
 
-
 
43
int main(int argc, char **argv)
37
int main(int argc, char **argv)
44
{
38
{
45
	ArgExtracter ae(argc, argv);
39
	// Create an implicit.
46
	float iso = 30;
-
 
47
	ae.extract("-i", iso);
40
	TestImplicit imp;
48
	int X  = 256;
-
 
49
	ae.extract("-x", X);
-
 
50
	int Y  = 256;
-
 
51
	ae.extract("-y", Y);
-
 
52
	int Z  = 256;
-
 
53
	ae.extract("-z", Z);
-
 
54
	string file = ae.get_last_arg();
-
 
55
	
41
 
56
	RGridb grid(Vec3i(X,Y,Z));
42
	// Create a polygonizer. Cell side length = 0.1 and go up to 50 cells.
57
	load_raw(file,grid);
43
	Polygonizer pol(&imp, 0.1f, 50);	
58
 
44
 
59
	VolumeImplicit vol_imp(&grid);
-
 
60
	Polygonizer pol(&vol_imp, 1.0f/X, iso);	
45
	// Start polygonizer in vicinity of 1,1,1
61
	pol.march(0,0,0);
46
	pol.march(1,1,1);
62
 
47
 
-
 
48
	// Build HMesh from triangles
63
	vector<int> indices;
49
	vector<int> indices;
64
	vector<Vec3f> verts;
50
	vector<Vec3f> verts;
65
	vector<int> faces;
51
	vector<int> faces;
66
	
52
	
-
 
53
	// Extract vertices
67
 	for(int i=0;i<pol.no_vertices();++i)
54
 	for(int i=0;i<pol.no_vertices();++i)
68
	{
55
	{
69
			verts.push_back(*reinterpret_cast<Vec3f*>(&pol.get_vertex(i)));
56
			verts.push_back(*reinterpret_cast<Vec3f*>(&pol.get_vertex(i)));
70
	}
57
	}
-
 
58
 
-
 
59
	// Extract triangles.
71
 	for(int i=0;i<pol.no_triangles();++i)
60
 	for(int i=0;i<pol.no_triangles();++i)
72
	{
61
	{
73
			faces.push_back(3);
62
			faces.push_back(3);
74
			TRIANGLE f = pol.get_triangle(i);
63
			TRIANGLE f = pol.get_triangle(i);
75
			indices.push_back(f.v0);
64
			indices.push_back(f.v0);
76
			indices.push_back(f.v1);
65
			indices.push_back(f.v1);
77
			indices.push_back(f.v2);
66
			indices.push_back(f.v2);
78
	}
67
	}
79
 
68
	
-
 
69
	// Build manifold
80
	Manifold m;
70
	Manifold m;
81
	build_manifold(m, 
-
 
82
								 verts.size(), &verts[0], 
71
	build_manifold(m, verts.size(), &verts[0], 
83
								 faces.size(), &faces[0], &indices[0]);
72
								 faces.size(), &faces[0], &indices[0]);
-
 
73
 
-
 
74
	// Save as obj file
84
 	x3d_save("bp.x3d", m);
75
 	obj_save("bloomenthal.obj", m);
85
	
76
	
86
}
77
}