Subversion Repositories gelsvn

Rev

Details | Last modification | View Log | RSS feed

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