-
Notifications
You must be signed in to change notification settings - Fork 0
/
draw.cpp
175 lines (127 loc) · 4.67 KB
/
draw.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
#include"main.h"
#include"sim_pars.h"
extern sim_pars simu;
void draw(Triangulation& T, const std::string file_name , const bool setup ) {
if (setup) {
cout << "draw on step "<< simu.current_step() << endl;
std::stringstream mkdir;
std::stringstream dirname;
dirname << simu.current_step();
mkdir << "mkdir -p " << dirname.str();
cout << "running : " << mkdir.str() << endl;
system(mkdir.str().c_str());
std::stringstream cp_cfg;
cp_cfg << "cp -f simu.cfg " << dirname.str();
system(cp_cfg.str().c_str());
}
std::stringstream namefile;
namefile << simu.current_step() << '/' << file_name;
cout << "writing on file : " << namefile.str() << endl;
std::ofstream main_data;
main_data.open(namefile.str().c_str() );
for(F_v_it vit=T.vertices_begin();
vit != T.vertices_end();
vit++) {
Periodic_point pp=T.periodic_point(vit);
Point p=T.point(pp);
#include"printout.h"
}
main_data << endl;
main_data.close();
}
void draw_vtk(Triangulation& Tp ) {
std::stringstream vtkfile;
vtkfile << simu.current_step() << '/' << "points.vtu";
cout << "writing on file : " << vtkfile.str() << endl;
//
// write_c2t3_to_vtk_xml_file.h
//
// Created by David Bernstein on 5/1/13.
//
std::ofstream vtk_file(vtkfile.str().c_str() );
// header
vtk_file << "<VTKFile type=\"UnstructuredGrid\" ";
vtk_file << "version=\"0.1\" ";
vtk_file << "byte_order=\"BigEndian\">" << std::endl;
int indent_size = 2;
std::string indent_unit(indent_size, ' ');
std::string indent = indent_unit;
vtk_file << indent + "<UnstructuredGrid>" << std::endl;
int num_vertices = Tp.number_of_vertices();
int num_cells = Tp.number_of_faces();
indent += indent_unit;
vtk_file << indent + "<Piece NumberOfPoints=\"" << num_vertices << "\" ";
vtk_file << "NumberOfCells=\"" << num_cells << "\">" << std::endl;
// Write vertices
indent += indent_unit;
vtk_file << indent + "<Points>" << std::endl;
indent += indent_unit;
vtk_file << indent;
vtk_file << "<DataArray type=\"Float32\" NumberOfComponents=\"3\" Format=\"ascii\">" << std::endl;
std::map<Point, int> V;
int i=0;
indent += indent_unit;
for (F_v_it it=Tp.finite_vertices_begin(); it != Tp.finite_vertices_end(); ++it)
{
vtk_file << indent;
vtk_file << it->point().x() << " " << it->point().y() << " " << 0 << std::endl;
V[it->point()] = i;
++i;
}
indent.erase(indent.length()-indent_size, indent_size);
vtk_file << indent + "</DataArray>" << std::endl;
indent.erase(indent.length()-indent_size, indent_size);
vtk_file << indent + "</Points>" << std::endl;
// Write tetrahedra
vtk_file << indent << "<Cells>" << std::endl;
indent += indent_unit;
vtk_file << indent;
vtk_file << "<DataArray type=\"Int32\" Name=\"connectivity\" Format=\"ascii\">";
vtk_file << std::endl;
indent += indent_unit;
F_f_it it;
for (it = Tp.finite_faces_begin(); it != Tp.finite_faces_end(); ++it)
{
vtk_file << indent;
vtk_file << V[it->vertex(0)->point()] << " ";
vtk_file << V[it->vertex(1)->point()] << " ";
vtk_file << V[it->vertex(2)->point()] << " " << std::endl;
}
indent.erase(indent.length()-indent_size, indent_size);
vtk_file << indent + "</DataArray>" << std::endl;
// offsets
// every element is a three node triangle so all offsets are multiples of 3
vtk_file << indent;
vtk_file << "<DataArray type=\"Int32\" Name=\"offsets\" Format=\"ascii\">";
vtk_file << std::endl;
i = 3;
indent += indent_unit;
for (int j = 0; j < num_cells; ++j)
{
vtk_file << indent << i << std::endl;
i += 3;
}
indent.erase(indent.length()-indent_size, indent_size);
vtk_file << indent + "</DataArray>" << std::endl;
// cell types (type 5 is a three node triangle)
vtk_file << indent;
vtk_file << "<DataArray type=\"Int32\" Name=\"types\" Format=\"ascii\">";
vtk_file << std::endl;
indent += indent_unit;
for (int j = 0; j < num_cells; ++j)
{
vtk_file << indent << "5" << std::endl;
}
indent.erase(indent.length()-indent_size, indent_size);
vtk_file << indent + "</DataArray>" << std::endl;
indent.erase(indent.length()-indent_size, indent_size);
vtk_file << indent + "</Cells>" << std::endl;
indent.erase(indent.length()-indent_size, indent_size);
vtk_file << indent + "</Piece>" << std::endl;
indent.erase(indent.length()-indent_size, indent_size);
vtk_file << indent + "</UnstructuredGrid>" << std::endl;
indent.erase(indent.length()-indent_size, indent_size);
vtk_file << "</VTKFile>" << std::endl;
vtk_file.close();
return;
}