-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathreader.cpp
More file actions
263 lines (210 loc) · 6.95 KB
/
reader.cpp
File metadata and controls
263 lines (210 loc) · 6.95 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
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
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
#include "reader.h"
#include <cstdio>
#include <fstream>
#include <string>
#include "rawloader.h"
#include "transferfunction.h"
#include "transferfunction1d.h"
namespace vr
{
double* ReadVolvisRaw(std::string volfilename, size_t bytes_per_value, int w, int h, int d)
{
double* scalar_values = NULL;
IRAWLoader rawLoader = IRAWLoader(volfilename, bytes_per_value, w*h*d, bytes_per_value);
//GLushort - 16 bits
if (bytes_per_value == sizeof(unsigned short))
{
scalar_values = new double[w*h*d];
unsigned short *b = new unsigned short[w*h*d];
memcpy(b, rawLoader.GetData(), sizeof(unsigned short)*w*h*d);
for (int i = 0; i < w*h*d; i++)
{
scalar_values[i] = (double)b[i];
}
// TODO: NORMALIZE
delete[] b;
}
//GLubyte - 8 bits
else if (bytes_per_value == sizeof(unsigned char))
{
scalar_values = new double[w*h*d];
unsigned char *b = new unsigned char[w*h*d];
memcpy(b, rawLoader.GetData(), sizeof(unsigned char)*w*h*d);
for (int i = 0; i < w*h*d; i++)
scalar_values[i] = (double)b[i];
// TODO: NORMALIZE
delete[] b;
}
return scalar_values;
}
Volume* ReadRawFile(std::string filepath)
{
Volume* ret = NULL;
printf("Started -> Read Volume From .raw File\n");
printf(" - File .raw Path: %s\n", filepath.c_str());
std::ifstream file(filepath.c_str());
if (file.is_open())
{
int foundinit = filepath.find_last_of('\\');
std::string filename = filepath.substr(foundinit + 1);
printf(" - File .raw: %s\n", filename.c_str());
int foundfp = filename.find_last_of('.');
filename = filename.substr(0, foundfp);
int foundsizes = filename.find_last_of('.');
std::string t_filesizes = filename.substr(foundsizes + 1,
filename.size() - foundsizes);
filename = filename.substr(0, filename.find_last_of('.'));
int foundbytesize = filename.find_last_of('.');
std::string t_filebytesize = filename.substr(foundbytesize + 1,
filename.size() - foundbytesize);
int fw, fh, fd;
int bytesize;
// Read the Volume Sizes
int foundd = t_filesizes.find_last_of('x');
fd = atoi(t_filesizes.substr(foundd + 1,
t_filesizes.size() - foundd).c_str());
t_filesizes = t_filesizes.substr(0, t_filesizes.find_last_of('x'));
int foundh = t_filesizes.find_last_of('x');
fh = atoi(t_filesizes.substr(foundh + 1,
t_filesizes.size() - foundh).c_str());
t_filesizes = t_filesizes.substr(0, t_filesizes.find_last_of('x'));
int foundw = t_filesizes.find_last_of('x');
fw = atoi(t_filesizes.substr(foundw + 1,
t_filesizes.size() - foundw).c_str());
// Byte Size
bytesize = atoi(t_filebytesize.c_str());
double* scalar_values = ReadVolvisRaw(filepath, (size_t)bytesize, fw, fh, fd);
ret = new Volume(fw, fh, fd, scalar_values, GetStorageSizeType((size_t)bytesize));
ret->SetName(filepath);
printf(" - Volume Name : %s\n", filepath.c_str());
printf(" - Volume Size : [%d, %d, %d]\n", fw, fh, fd);
printf(" - Volume Byte Size: %d\n", bytesize);
file.close();
printf("Finished -> Read Volume From .raw File\n");
}
else
printf("Finished -> Error on opening .raw file\n");
return ret;
}
Volume* ReadSynFile (std::string filename)
{
Volume* ret = NULL;
printf("Started -> Read Volume From .syn File\n");
printf(" - File .syn Path: %s\n", filename.c_str());
std::string fileifstream = "";
fileifstream.append(filename);
std::ifstream file(fileifstream.c_str());
if (file.is_open())
{
int width, height, depth;
file >> width >> height >> depth;
std::cout << " - Volume Size: [" << width << ", " << height << ", " << depth << "]" << std::endl;
ret = new Volume(width, height, depth);
int new_data = 0;
while (file >> new_data)
{
if (new_data == 1)
{
int x0, y0, z0, x1, y1, z1, v;
file >> x0 >> y0 >> z0 >> x1 >> y1 >> z1 >> v;
for (int x = x0; x < x1; x++)
{
for (int y = y0; y < y1; y++)
{
for (int z = z0; z < z1; z++)
{
ret->SetSampleVolume(x, y, z, (double)v);
}
}
}
}
else
{
int xt, yt, zt, v;
file >> xt >> yt >> zt >> v;
ret->SetSampleVolume(xt, yt, zt, (double)v);
}
}
printf("lqc: Finished -> Read Volume From .syn File\n");
}
else
printf("lqc: Finished -> Error on opening .syn file\n");
return ret;
}
TransferFunction* ReadTransferFunction(std::string file)
{
TransferFunction* ret = NULL;
int found = file.find_last_of('.');
std::string extension = file.substr(found + 1);
printf("---------Reading Transfer Function----------\n");
printf(" - File: %s\n", file.c_str());
if (extension.compare("tf1d") == 0)
ret = ReadTransferFunction_tf1d(file);
//else if (extension.compare("tf1dnorm") == 0)
// ret = ReadTransferFunction_tf1dnorm(file);
//else if (extension.compare ("tfg1d") == 0)
// ret = ReadTransferFunction_tfg1d (file);
//else if (extension.compare ("tfgersa") == 0)
// ret = ReadTransferFunction_tfgersa (file);
printf("--------------------------------------------\n");
return ret;
}
TransferFunction* ReadTransferFunction_tf1d(std::string file)
{
std::ifstream myfile(file);
if (myfile.is_open())
{
std::string interpolation;
std::getline(myfile, interpolation);
printf(" - Interpolation: %s\n", interpolation.c_str());
TransferFunction1D* tf = NULL;
int init;
myfile >> init;
if (init == 2)
{
int max_density;
myfile >> max_density;
int extuse;
myfile >> extuse;
tf = new TransferFunction1D(max_density);
tf->SetExtinctionCoefficientInput(extuse == 1);
}
else if (init == 1)
{
int max_density;
myfile >> max_density;
tf = new TransferFunction1D(max_density);
}
else
{
tf = new TransferFunction1D();
}
int cpt_rgb_size;
myfile >> cpt_rgb_size;
double r, g, b, a;
int isovalue;
for (int i = 0; i < cpt_rgb_size; i++)
{
myfile >> r >> g >> b >> isovalue;
tf->AddRGBControlPoint(TransferControlPoint(r, g, b, isovalue));
}
int cpt_alpha_size;
myfile >> cpt_alpha_size;
for (int i = 0; i < cpt_alpha_size; i++)
{
myfile >> a >> isovalue;
tf->AddAlphaControlPoint(TransferControlPoint(a, isovalue));
}
myfile.close();
if (interpolation.compare("linear") == 0)
tf->m_interpolation_type = TFInterpolationType::LINEAR;
else if (interpolation.compare("cubic") == 0)
tf->m_interpolation_type = TFInterpolationType::CUBIC;
int foundname = file.find_last_of('\\');
std::string tfname = file.substr(foundname + 1);
tf->SetName(file);
return tf;
}
return NULL;
}
}