Subversion Repositories gelsvn

Rev

Rev 67 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 67 Rev 72
1
#include <sstream>
1
#include <sstream>
2
#include <fstream>
2
#include <fstream>
3
#include <unistd.h>
3
//#include <unistd.h>
4
 
4
 
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/x3d_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;
20
typedef RGrid<unsigned char> RGridb;
21
 
21
 
22
class VolumeImplicit: public ImplicitFunction
22
class VolumeImplicit: public ImplicitFunction
23
{
23
{
24
		TrilinFilter<RGridb> trifi;
24
		TrilinFilter<RGridb> trifi;
25
		
25
		
26
public:
26
public:
27
		
27
		
28
		VolumeImplicit(const RGridb* g): trifi(g) {}
28
		VolumeImplicit(const RGridb* g): trifi(g) {}
29
		
29
		
30
		float eval(float x,float y,float z) 
30
		float eval(float x,float y,float z) 
31
				{
31
				{
32
						if(trifi.in_domain(Vec3f(x,y,z)))
32
						if(trifi.in_domain(Vec3f(x,y,z)))
33
						{
33
						{
34
								unsigned char v =trifi(Vec3f(x,y,z));
34
								unsigned char v =trifi(Vec3f(x,y,z));
35
								return static_cast<float>(v);
35
								return static_cast<float>(v);
36
						}
36
						}
37
						return 0;
37
						return 0;
38
				}
38
				}
39
};
39
};
40
 
40
 
41
 
41
 
42
 
42
 
43
int main(int argc, char **argv)
43
int main(int argc, char **argv)
44
{
44
{
45
	ArgExtracter ae(argc, argv);
45
	ArgExtracter ae(argc, argv);
46
	float iso = 30;
46
	float iso = 30;
47
	ae.extract("-i", iso);
47
	ae.extract("-i", iso);
48
	int X  = 256;
48
	int X  = 256;
49
	ae.extract("-x", X);
49
	ae.extract("-x", X);
50
	int Y  = 256;
50
	int Y  = 256;
51
	ae.extract("-y", Y);
51
	ae.extract("-y", Y);
52
	int Z  = 256;
52
	int Z  = 256;
53
	ae.extract("-z", Z);
53
	ae.extract("-z", Z);
54
	string file = ae.get_last_arg();
54
	string file = ae.get_last_arg();
55
	
55
	
56
	RGridb grid(Vec3i(X,Y,Z));
56
	RGridb grid(Vec3i(X,Y,Z));
57
	load_raw(file,grid);
57
	load_raw(file,grid);
58
 
58
 
59
	VolumeImplicit vol_imp(&grid);
59
	VolumeImplicit vol_imp(&grid);
60
	Polygonizer pol(&vol_imp, 1.0f/X, iso);	
60
	Polygonizer pol(&vol_imp, 1.0f/X, iso);	
61
	pol.march(0,0,0);
61
	pol.march(0,0,0);
62
 
62
 
63
	vector<int> indices;
63
	vector<int> indices;
64
	vector<Vec3f> verts;
64
	vector<Vec3f> verts;
65
	vector<int> faces;
65
	vector<int> faces;
66
	
66
	
67
 	for(int i=0;i<pol.no_vertices();++i)
67
 	for(int i=0;i<pol.no_vertices();++i)
68
	{
68
	{
69
			verts.push_back(*reinterpret_cast<Vec3f*>(&pol.get_vertex(i)));
69
			verts.push_back(*reinterpret_cast<Vec3f*>(&pol.get_vertex(i)));
70
	}
70
	}
71
 	for(int i=0;i<pol.no_triangles();++i)
71
 	for(int i=0;i<pol.no_triangles();++i)
72
	{
72
	{
73
			faces.push_back(3);
73
			faces.push_back(3);
74
			TRIANGLE f = pol.get_triangle(i);
74
			TRIANGLE f = pol.get_triangle(i);
75
			indices.push_back(f.v0);
75
			indices.push_back(f.v0);
76
			indices.push_back(f.v1);
76
			indices.push_back(f.v1);
77
			indices.push_back(f.v2);
77
			indices.push_back(f.v2);
78
	}
78
	}
79
 
79
 
80
	Manifold m;
80
	Manifold m;
81
	build_manifold(m, 
81
	build_manifold(m, 
82
								 verts.size(), &verts[0], 
82
								 verts.size(), &verts[0], 
83
								 faces.size(), &faces[0], &indices[0]);
83
								 faces.size(), &faces[0], &indices[0]);
84
 	x3d_save("bp.x3d", m);
84
 	x3d_save("bp.x3d", m);
85
	
85
	
86
}
86
}
87
 
87