-
Notifications
You must be signed in to change notification settings - Fork 1
/
sub_surface.cpp
132 lines (106 loc) · 3.15 KB
/
sub_surface.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
//C++ standard Header Files
#include <iostream>
#include <cmath>
#include <ctime>
#include <vector>
#include <sstream>
#include <string>
#include <cstring>
#include <fstream>
#include <cstdlib>
#include <stdio.h>
#include <float.h>
#include <stdlib.h>
#include <algorithm>
#include <map>
#include <assert.h>
#include <system/path.h>
#include <file/nrrd.h>
// VTK#include <vtkFloatArray.h>
#include <vtkPointData.h>
#include <vtkVersion.h>
#include <vtkCellArray.h>
#include <vtkPoints.h>
#include <vtkXMLStructuredGridWriter.h>
#include <vtkStructuredGrid.h>
#include <vtkSmartPointer.h>
#include <vtkImageData.h>
#include <vtkXMLImageDataReader.h>
#include <vtkPoints.h>
#include <vtkMultiPieceDataSet.h>
#include <vtkNew.h>
#include <vtkMultiBlockPLOT3DReader.h>
#include <vtkMultiBlockDataSet.h>
#include <vtkXMLPolyDataReader.h>
#include <vtkPolyData.h>
#include <vtkFloatArray.h>
#include <vtkCellArray.h>
#include <vtkQuad.h>
#include "VectorMatrix.h"
int dim[3]={150, 70, 36}; // -1 from the original sizes
const int xstart=40, xend=120;
const int ystart=0, yend=61;
void run(char *list_fname)
{
//char list_filename[1024];
//sprintf(list_filename, "%s/list", DATA_PATH);
FILE *fp = fopen(list_fname, "rt");
char s[1024];
fgets(s, 1024, fp);
int files = atoi(s);
int i;
FILE *fout = fopen("out.raw", "wb");
for (i=0; i<files; i++)
{
fgets(s, 1024, fp);
char fname[1024];
sscanf(s, "%s", fname);
// load with vtk
vtkNew<vtkXMLPolyDataReader> reader;
reader->SetFileName(fname);
reader->UpdateInformation();
reader->Update();
// get data
vtkSmartPointer<vtkPolyData> data = reader->GetOutput() ;
vtkFloatArray* dvt_ary = vtkFloatArray::SafeDownCast(
data->GetPointData()->GetArray("d_tangent_vel")
);
if (dvt_ary==NULL) {
printf("cannot get d_tangent_vel\n");
exit(1);
}
float *p = (float *)dvt_ary->GetVoidPointer(0);
int n = data->GetNumberOfPoints();
// output
vtkNew<vtkPolyData> poly;
vtkNew<vtkFloatArray> out_dvt_ary ;
vtkNew<vtkQuad> out_cell_ary;
vtkNew<vtkPoints> out_points;
out_dvt_ary->
int x,y,b;
for (b=0; b<36; b++)
for (y=ystart ;y<yend && y<dim[1]; y++)
for (x=xstart; x<xend && x<dim[0]; x++)
{
int idx = x+dim[0]*(y+dim[1]*b);
double *pt = data->GetPoint(idx);
out_points->InsertNextPoint(pt);
out_dvt_ary->InsertNextTuple(p[idx])
}
//printf("n=%d\n", n);
// fwrite(p, n, sizeof(float), fout);
printf("i=%d, count=%d\n", i, out_ary.size());
fwrite(&out_ary[0], out_ary.size(), sizeof(float), fout);
}
write_nrrd_3d("out.nrrd", "out.raw", xend-xstart, (dim[1])*dim[2], files, "float");
fclose(fout);
fclose(fp);
}
int main(int argc, char **argv)
{
printf("usage: sub_surface surface.dvt.list \n");
printf("Output: sub.surface.dvt.#.vtp \n");
char *filename = argv[1];
// load data
run(filename);
}