-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.cpp
More file actions
152 lines (110 loc) · 3.1 KB
/
main.cpp
File metadata and controls
152 lines (110 loc) · 3.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
#include <iostream>
#include <fstream>
#include <cstring>
extern "C"
{
#include <tourtre.h>
}
#include "Data.h"
#include "Mesh.h"
#include <unistd.h>
using std::cin;
using std::cout;
using std::clog;
using std::cerr;
using std::endl;
double value ( size_t v, void * d ) {
Mesh * mesh = reinterpret_cast<Mesh*>(d);
return mesh->data[v];
}
size_t neighbors ( size_t v, size_t * nbrs, void * d ) {
Mesh * mesh = static_cast<Mesh*>(d);
static std::vector<size_t> nbrsBuf;
nbrsBuf.clear();
mesh->getNeighbors(v,nbrsBuf);
for (uint i = 0; i < nbrsBuf.size(); i++) {
nbrs[i] = nbrsBuf[i];
}
return nbrsBuf.size();
}
void outputTree( std::ofstream & out, ctBranch * b ) {
out << "(" << b->extremum << ' ' << b->saddle ;
for ( ctBranch * c = b->children.head; c != NULL; c = c->nextChild ){
out << " ";
outputTree( out, c );
}
out << ")";
}
int main( int argc, char ** argv ) {
int errflg = 0;
int c;
//command line parameters
char filename[1024] = "";
char outfile[1024] = "";
#if USE_ZLIB
char switches[256] = "i:o:";
#else
char switches[256] = "i:o:";
#endif
while ( ( c = getopt( argc, argv, switches ) ) != EOF ) {
switch ( c ) {
case 'i': {
strcpy(filename,optarg);
break;
}
case 'o': {
strcpy(outfile,optarg);
break;
}
case '?':
errflg++;
}
}
if ( errflg || filename[0] == '\0') {
clog << "usage: " << argv[0] << " <flags> " << endl << endl;
clog << "flags" << endl;
clog << "\t -i < filename > : filename" << endl;
clog << "\t -o < filename > : filename" << endl;
clog << endl;
clog << "Filename must be of the form <name>.<i>x<j>x<k>.<type>" << endl;
clog << "i,j,k are the dimensions. type is one of uint8, uint16, float or double." << endl << endl;
clog << "eg, \" turtle.128x256x512.float \" is a file with 128 x 256 x 512 floats." << endl;
clog << "i dimension varies the FASTEST (in C that looks like \"array[k][j][i]\")" << endl;
clog << "Data is read directly into memory -- ENDIANESS IS YOUR RESPONSIBILITY." << endl;
return(1);
}
char prefix[1024];
//Load data
Data data;
bool compress;
if (!data.load( filename, prefix, &compress )) {
cerr << "Failed to load data" << std::endl;
exit(1);
}
//Create mesh
Mesh mesh(data);
std::vector<size_t> totalOrder;
mesh.createGraph( totalOrder ); //this just sorts the vertices according to data.less()
unsigned long hello=32343;
//init libtourtre
ctContext * ctx = ct_init(
data.totalSize, //numVertices
&(totalOrder.front()), //totalOrder. Take the address of the front of an stl vector, which is the same as a C array
&value,
&neighbors,
&mesh //data for callbacks. The global functions less, value and neighbors are just wrappers which call mesh->getNeighbors, etc
);
//create contour tree
ct_sweepAndMerge( ctx );
ctBranch * root = ct_decompose( ctx );
//create branch decomposition
ctBranch ** map = ct_branchMap(ctx);
ct_cleanup( ctx );
//output tree
std::ofstream out(outfile,std::ios::out);
if (out) {
outputTree( out, root);
} else {
cerr << "couldn't open output file " << outfile << endl;
}
}