-
Notifications
You must be signed in to change notification settings - Fork 4
/
project.cpp
executable file
·218 lines (184 loc) · 6.5 KB
/
project.cpp
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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
#include "project.h"
#include "parameters.h"
#include "gpuInit.h"
#include "rtsENVI.h"
#include <fstream>
#include <stdio.h>
#include <string.h>
extern parameterStruct P;
void gpuComputeMetric(unsigned int m);
void LoadData(string filename)
{
enviHeaderStruct header;
if(!enviLoadf(header, &P.cpuData, filename))
{
cout<<"Error loading ENVI file."<<endl;
return;
}
P.dim = vector3D<unsigned int>(header.samples, header.lines, header.bands);
P.filename = filename;
P.currentX = P.dim.x/2;
P.currentY = P.dim.y/2;
gpuUploadData(&P.gpuData, P.cpuData, P.dim.x, P.dim.y, P.dim.z);
//create a buffer for the spatial window
gpuCreateRenderBuffer(P.gpu_glBuffer, P.gpu_cudaResource, P.dim.x, P.dim.y);
}
loadStatus LoadProject(string filename)
{
//open the project file as text
ifstream infile(filename.c_str());
string line, token;
string strData;
int intData;
int m = -1; //metric counter
int t = -1; //tf counter
//make sure that this is a valid project file
char prjTest[8];
infile.getline(prjTest, 8);
cout<<prjTest<<endl;
if(strcmp(prjTest, "SPECVIS") != 0)
return loadStatusInvalidProject;
enum inputType {typeMetric, typeTF};
inputType inType;
while(!infile.eof())
{
//read a line from the project file
getline(infile, line);
//if the line is a comment, continue on to the next one
if(line[0] == '#') continue;
//create another stream to perform conversion between data types
stringstream convert(line);
//grab the line token
convert>>token;
//if the line specifies the data file, load it
if(token.find("data") != string::npos){
convert>>strData;
LoadData(strData);
}
//if the line specifies a metric
if(token.find("metric") != string::npos){
inType = typeMetric;
//create a new metric
metricStruct newMetric;
//get the metric type
convert>>strData;
if(token.find("mean") != string::npos)
newMetric.type = metricMean;
if(token.find("centroid") != string::npos)
newMetric.type = metricCentroid;
//get the metric band and bandwidth
convert>>newMetric.band;
convert>>newMetric.bandwidth;
P.metricList.push_back(newMetric);
m++; //increment the metric counter
}
//if the line specifies a transfer function
if(token.find("transferfunc") != string::npos){
inType = typeTF;
//create a new metric
transferFuncStruct newTF;
//get the metric type
convert>>strData;
if(token.find("constant") != string::npos)
newTF.type = tfConstant;
if(token.find("gaussian") != string::npos)
newTF.type = tfGaussian;
if(token.find("linearup") != string::npos)
newTF.type = tfLinearUp;
if(token.find("lineardown") != string::npos)
newTF.type = tfLinearDown;
//get the metric band and bandwidth
convert>>newTF.tfMin;
convert>>newTF.tfMax;
convert>>newTF.sourceMetric;
convert>>newTF.r;
convert>>newTF.g;
convert>>newTF.b;
P.tfList.push_back(newTF);
P.selectedTF = 0;
t++; //increment the metric counter
}
//add a name to the current metric
if(token.find("name") != string::npos)
{
if(inType == typeMetric)
convert>>P.metricList[m].name;
else
convert>>P.tfList[t].name;
}
//add baseline points
if(token.find("baseline") != string::npos)
while(!convert.eof())
{
convert>>intData;
P.metricList[m].baselinePoints.push_back(intData);
}
//get a reference parameter
if(token.find("reference") != string::npos)
{
convert>>P.metricList[m].reference;
convert>>P.metricList[m].refEpsilon;
}
token = "";
}
//compute every metric so that you can work with TFs and referenced metrics without problems
for(unsigned int m = 0; m<P.metricList.size(); m++)
gpuComputeMetric(m);
return loadStatusOK;
}
void SaveProject(string filename)
{
//create a project file
ofstream outfile(filename.c_str());
//output the verification string indicating that the file is a SpecVis project
outfile<<"SPECVIS"<<endl;
//output the data filename
outfile<<"#Data file"<<endl;
outfile<<"data "<<P.filename;
//output each metric
unsigned int nMetrics = P.metricList.size();
for(unsigned int m=0; m<nMetrics; m++){
//output the token
outfile<<endl<<"metric ";
//output the metric type
if(P.metricList[m].type == metricMean)
outfile<<"mean ";
if(P.metricList[m].type == metricCentroid)
outfile<<"centroid ";
//output the band and bandwidth
outfile<<P.metricList[m].band<<" "<<P.metricList[m].bandwidth;
//output the metric name
if(P.metricList[m].name.length())
outfile<<endl<<" name "<<P.metricList[m].name;
//output any metric baseline points
unsigned int nBasePts = P.metricList[m].baselinePoints.size();
if(nBasePts > 0)
outfile<<endl<<" baseline";
for(unsigned int b=0; b<nBasePts; b++)
outfile<<" "<<P.metricList[m].baselinePoints[b];
//output any reference metric
if(P.metricList[m].reference > -1)
outfile<<endl<<" reference "<<P.metricList[m].reference<<" "<<P.metricList[m].refEpsilon;
}
//output each transfer function
unsigned int nTF = P.tfList.size();
for(unsigned int tf=0; tf<nTF; tf++){
//output the token
outfile<<endl<<"transferfunc ";
//output the metric type
if(P.tfList[tf].type == tfConstant)
outfile<<"constant ";
if(P.tfList[tf].type == tfGaussian)
outfile<<"gaussian ";
if(P.tfList[tf].type == tfLinearDown)
outfile<<"lineardown ";
if(P.tfList[tf].type == tfLinearUp)
outfile<<"linearup ";
//output the band and bandwidth
outfile<<P.tfList[tf].tfMin<<" "<<P.tfList[tf].tfMax<<" "<<P.tfList[tf].sourceMetric<<" "<<P.tfList[tf].r<<" "<<P.tfList[tf].g<<" "<<P.tfList[tf].b;
//output the metric name
if(P.metricList[tf].name.length())
outfile<<endl<<" name "<<P.tfList[tf].name;
}
outfile.close();
}