Subversion Repositories gelsvn

Rev

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

Rev 365 Rev 393
1
#include "CGLA/Mat4x4f.h"
1
#include "CGLA/Mat4x4f.h"
2
#include "Util/ArgExtracter.h"
2
#include "Util/ArgExtracter.h"
3
#include "Geometry/RGrid.h"
3
#include "Geometry/RGrid.h"
4
#include "Geometry/load_raw.h"
4
#include "Geometry/load_raw.h"
5
#include "Geometry/save_raw.h"
5
#include "Geometry/save_raw.h"
6
#include "HMesh/obj_save.h"
6
#include "HMesh/obj_save.h"
7
#include "HMesh/x3d_save.h"
7
#include "HMesh/x3d_save.h"
8
#include "HMesh/caps_and_needles.h"
8
#include "HMesh/caps_and_needles.h"
9
#include "HMesh/volume_polygonize.h"
9
#include "HMesh/volume_polygonize.h"
10
#include "HMesh/triangulate.h"
10
#include "HMesh/triangulate.h"
11
 
11
 
12
using namespace CGLA;
12
using namespace CGLA;
13
using namespace Util;
13
using namespace Util;
14
using namespace HMesh;
14
using namespace HMesh;
15
using namespace std;
15
using namespace std;
16
using namespace Geometry;
16
using namespace Geometry;
17
 
17
 
18
bool cuberille;
18
bool cuberille;
19
float iso = 40; 
19
float iso = 40; 
20
string file;
20
string file;
21
string ofile;
21
string ofile;
22
 
22
 
23
template<class T>
23
template<class T>
24
void do_everything(RGrid<T> grid)
24
void do_everything(RGrid<T> grid)
25
{
25
{
26
 		cout << "loading <" << file << ">" << endl;
26
 		cout << "loading <" << file << ">" << endl;
27
 		load_raw(file,grid);
27
 		load_raw(file,grid);
28
		
28
		
29
		cout << "Polygonizing, iso = " << iso << endl;
29
		cout << "Polygonizing, iso = " << iso << endl;
30
		Manifold mani;
30
		Manifold mani;
31
 
31
 
32
		if(cuberille)
32
		if(cuberille)
33
				cuberille_polygonize(grid, mani, iso, true);
33
				cuberille_polygonize(grid, mani, iso, true);
34
		else
34
		else
35
				mc_polygonize(grid, mani, iso);
35
				mc_polygonize(grid, mani, iso);
36
 
36
 
37
		cout << "Triangulating" << endl;
37
		cout << "Triangulating" << endl;
38
		shortest_edge_triangulate(mani);
38
		shortest_edge_triangulate(mani);
39
 
39
 
40
		cout << "Saving" << endl;
40
		cout << "Saving" << endl;
41
		obj_save(ofile, mani);
41
		obj_save(ofile, mani);
42
}
42
}
43
 
43
 
44
int main(int argc, char**argv)
44
int main(int argc, char**argv)
45
{
45
{
46
		ArgExtracter ae(argc, argv);
46
		ArgExtracter ae(argc, argv);
47
 
47
 
48
		if(ae.no_remaining_args() == 1 || ae.extract("-h"))
48
		if(ae.no_remaining_args() == 1 || ae.extract("-h"))
49
		{
49
		{
50
				cout << "Usage: volpoly [-C] [-i <iso>] [-x <X>] [-y <Y>] [-z <Z>] " 
50
				cout << "Usage: volpoly [-C] [-i <iso>] [-x <X>] [-y <Y>] [-z <Z>] " 
51
						 << "[-S|-f|-U|-b] raw-volume-file" << endl;
51
						 << "[-S|-f|-U|-b] raw-volume-file" << endl;
52
				cout << "where -C implies that the cuberille method rather than\n"
52
				cout << "where -C implies that the cuberille method rather than\n"
53
						 << "marching cubes should be used. -S -f -U -b indicate that\n"
53
						 << "marching cubes should be used. -S -f -U -b indicate that\n"
54
						 << "the volume is in short, float, unsigned short or unsigned\n"
54
						 << "the volume is in short, float, unsigned short or unsigned\n"
55
						 << "byte format" << endl;
55
						 << "byte format" << endl;
56
				exit(0);
56
				exit(0);
57
		}
57
		}
58
 
58
 
59
		cuberille = ae.extract("-C");
59
		cuberille = ae.extract("-C");
60
		ae.extract("-i", iso);
60
		ae.extract("-i", iso);
61
		int X  = 128;
61
		int X  = 128;
62
		ae.extract("-x", X);
62
		ae.extract("-x", X);
63
		int Y  = 128;
63
		int Y  = 128;
64
		ae.extract("-y", Y);
64
		ae.extract("-y", Y);
65
		int Z  = 62;
65
		int Z  = 62;
66
		ae.extract("-z", Z);
66
		ae.extract("-z", Z);
67
		
67
		
68
		ofile = "isosurf.obj";
68
		ofile = "isosurf.obj";
69
		ae.extract("-o", ofile);
69
		ae.extract("-o", ofile);
70
		file = ae.get_last_arg();
70
		file = ae.get_last_arg();
71
 
71
 
72
		if(ae.extract("-S"))
72
		if(ae.extract("-S"))
73
		{
73
		{
74
				cout << "Data type = short" << endl;
74
				cout << "Data type = short" << endl;
75
				RGrid<short> grid(Vec3i(X,Y,Z));
75
				RGrid<short> grid(Vec3i(X,Y,Z));
76
				do_everything(grid);
76
				do_everything(grid);
77
		}
77
		}
78
		else if(ae.extract("-f"))
78
		else if(ae.extract("-f"))
79
		{
79
		{
80
				cout << "Data type = float" << endl;
80
				cout << "Data type = float" << endl;
81
				RGrid<float> grid(Vec3i(X,Y,Z));
81
				RGrid<float> grid(Vec3i(X,Y,Z));
82
				do_everything(grid);
82
				do_everything(grid);
83
		}
83
		}
84
		else if(ae.extract("-U"))
84
		else if(ae.extract("-U"))
85
		{
85
		{
86
				cout << "Data type = unsigned short" << endl;
86
				cout << "Data type = unsigned short" << endl;
87
				RGrid<unsigned short> grid(Vec3i(X,Y,Z));
87
				RGrid<unsigned short> grid(Vec3i(X,Y,Z));
88
				do_everything(grid);
88
				do_everything(grid);
89
		}
89
		}
90
		else 
90
		else 
91
		{
91
		{
92
				cout << "Data type = unsigned char" << endl;
92
				cout << "Data type = unsigned char" << endl;
93
				RGrid<unsigned char> grid(Vec3i(X,Y,Z));
93
				RGrid<unsigned char> grid(Vec3i(X,Y,Z));
94
				do_everything(grid);
94
				do_everything(grid);
95
		}
95
		}
96
}
96
}
97
 
97