Subversion Repositories gelsvn

Rev

Rev 145 | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

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