-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.branch_before_remove_octree.cpp
214 lines (150 loc) · 5.86 KB
/
main.branch_before_remove_octree.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
#include "lib/lib.h"
//#include <vtkXMLUnstructuredGrid.h>
//#include <GL/glew.h>
bool Log_Status = true;
bool Write_Mesh = true;
bool Write_Octree = false;
bool Write_Vec3 = true;
bool old = true;
unsigned octreeSHM::Depth = 1; //reserved level 0 for root mesh
int main()
{
float VIEW_ROTX = 0;
float VIEW_ROTZ = 0;
int MAX_DEPTH = 17;
unsigned NEL_Y = 1000+1;
unsigned NEL_X = 10+1; double DX = 1.0;
unsigned NEL_Z = 10+1; double DZ = 1.0;
int t=0;
int tfin = 10;
structuredHexMesh MyCube(NEL_X, NEL_Y, NEL_Z);
//Defining the mesh-surface that will be extruded later
//with SweepFace to create a 3D hexaedral structured-mesh
{
vec3 Surface[NEL_X*NEL_Z];
for (int j=0; j<NEL_Z; j++) {
for (int i=0; i<NEL_X; i++) {
Surface[NEL_X*j+i] = vec3(DX*(double)i, 0.0, DZ*(double)j);
}
}
int vertexNEL = sizeof(Surface)/sizeof(vec3);
//Surface[0].ArithmeticForEach(Surface, NEL_X*NEL_Z , vec3(0.0, 0.0, 2.0), 1);
MyCube.SweepFace(Surface, NEL_X, NEL_Z, NEL_Y-1, 0.016*2.0*PI/(float) (NEL_Y-1), vec3(-100.0,0.0,0.0));
//This command compute cell centers of all cells for the mesh
for(int i=0; i< (int)MyCube.Log_Cells_Max(); i++) {
MyCube.loadVertexId((unsigned) i);
MyCube.CenterC8();
MyCube.Log_Cell();
}
MyCube.Log();
}//end of scope of 2D mesh-surface: Surface
//Defining an cloud of points to test the octree algorithm
const double lowerX{0.0}, upperX{1.0};
const double lowerY{0.0}, upperY{1.0};
const double lowerZ{0.0}, upperZ{1.0};
// double num_randomX = dRandom(lowerX, upperX);
// double num_randomY = dRandom(lowerY, upperY);
// double num_randomZ = dRandom(lowerZ, upperZ);
vec3 Item[100];
for(int i=0; i<100; i++)
{
Item[i] = vec3(dRandom(lowerX,upperX), dRandom(lowerY,upperY), dRandom(lowerZ,upperZ) );
}
int number_of_points = sizeof(Item)/sizeof(vec3);
octreeSHM* OctreeLevel[MAX_DEPTH+1]{nullptr};
// OctreeLevel[0] = (octreeSHM)&MyCube;
//Main loop to run the algorithm. It takes the cloud of points and compute
//what cell of the mesh they belong to slit this cell in octree recursively
while(t++<tfin) {
std::string nameFile = "temp/meshIO_" + std::to_string(t) + ".csv";
std::ofstream meshFileOF;
// Item[0].ArithmeticForEach(Item, number_of_points, vec3(0.01, 0.0, 0.0), 0);
// #include "issues/LocRotForEach.h"
//[Info] Reset to false all entries of subdivions before recompute the insertion points in next step
if(MyCube.Total_Cell_Divided) {
MyCube.Total_Cell_Divided = 0;
for(int i=0; (unsigned) i<MyCube.Log_Cells_Max(); i++) {
*(MyCube.Cell_Divided+i) = false;
}
}
//[Info] Buscando en MyCube los puntos insertados
bool Item_inserted[number_of_points]={false};
for(unsigned id=0; id < MyCube.Log_Cells_Max(); id++) {
if(MyCube.Total_Cell_Divided == MyCube.Log_Cells_Max()) break;
for(int j=0; j<number_of_points; j++) {
if(!Item_inserted[j]) {
if(!MyCube.Cell_Divided[id]) {
MyCube.loadVertexId(id);
if(MyCube.vertexSearchCell(Item[j])) {
Item_inserted[j] = true;
}
}
}
}
}
unsigned thisOctLevel;
//[Info] Creating Octree level 1
thisOctLevel = octreeSHM::Depth;
if(MyCube.Total_Cell_Divided) {
OctreeLevel[thisOctLevel] = new octreeSHM(MyCube.Total_Cell_Divided);
OctreeLevel[thisOctLevel]->setHexMeshElement(MyCube);
//[Info] Buscando en Octree1 los puntos insertados
bool Item_inserted[number_of_points]={false};
for(int k=0; k<(int)OctreeLevel[thisOctLevel]->Log_Cells_Max(); k++) {
if(OctreeLevel[thisOctLevel]->Total_Cell_Divided == OctreeLevel[thisOctLevel]->Log_Cells_Max()) break;
for(int j=0; j<number_of_points; j++) {
if(!Item_inserted[j]) {
if(!OctreeLevel[thisOctLevel]->Cell_Divided[k]) {
OctreeLevel[thisOctLevel]->loadVertexId((unsigned) k, 1);
OctreeLevel[thisOctLevel]->CenterC8();
//std::cout<<"Buscando el punto: " << j << " en Octree 1"<<"Celda: "<< k <<std::endl;
if(OctreeLevel[thisOctLevel]->vertexSearchCell(Item[j])) {
Item_inserted[j] = true;
}
}
}
}
}
}//I want to avoid Nested Invoking Classes
//WHILE LOOP TO CREATE OCTREE MESH
while(octreeSHM::Depth < MAX_DEPTH+1)
{
//[Info] Creating Octree level 1
thisOctLevel = octreeSHM::Depth;
unsigned cells_divided = OctreeLevel[octreeSHM::giveLowerLevelID()]->Total_Cell_Divided;
if(cells_divided) {
OctreeLevel[thisOctLevel] = new octreeSHM(cells_divided);
OctreeLevel[thisOctLevel]->setHexMeshElement(*OctreeLevel[octreeSHM::giveLowerLevelID()]);
//[Info] Buscando en Octree1 los puntos insertados
bool Item_inserted[number_of_points]={false};
for(int k=0; k<(int)OctreeLevel[thisOctLevel]->Log_Cells_Max(); k++) {
if(OctreeLevel[thisOctLevel]->Total_Cell_Divided == OctreeLevel[thisOctLevel]->Log_Cells_Max()) break;
for(int j=0; j<number_of_points; j++) {
if(!Item_inserted[j]) {
if(!OctreeLevel[thisOctLevel]->Cell_Divided[k]) {
OctreeLevel[thisOctLevel]->loadVertexId((unsigned) k, 1);
OctreeLevel[thisOctLevel]->CenterC8();
if(OctreeLevel[thisOctLevel]->vertexSearchCell(Item[j])) {
Item_inserted[j] = true;
}
}
}
}
}
}//I want to avoid Nested Invoking Classes
}
int cells_added{0};
for (int i = (int)octreeSHM::giveLowerLevelID(); i>0; i--) {
cells_added += OctreeLevel[i] -> Log_Cells_Max();
if(Write_Octree) OctreeLevel[i]->WriteMesh(&meshFileOF, nameFile, 2);
delete OctreeLevel[i];
OctreeLevel[i] = nullptr;
}
if(Log_Status) std::cout<<"TIME-STAMP: "<<t<<"/"<<tfin<<"\nCells Added: " << cells_added << std::endl;
if(Write_Mesh) MyCube.WriteMesh(&meshFileOF, nameFile, 0);
if(Write_Vec3){
#include "issues/WriteVec3.h"
}
}
return 0;
}