Branch data Line data Source code
1 : : #include "CubitOctree.hpp"
2 : : #include "RefFace.hpp"
3 : : #include "CubitOctreeConstants.hpp"
4 : :
5 : : #include "CubitOctreeCell.hpp"
6 : : #include "CubitOctreeNode.hpp"
7 : : #include "CubitFacet.hpp"
8 : : #include "CubitFacetEdge.hpp"
9 : : #include "CubitPoint.hpp"
10 : : #include "CubitPointData.hpp"
11 : : #include "TDOctreeRefFace.hpp"
12 : : #include "FacetDataUtil.hpp"
13 : : #include "CubitOctreeGenerator.hpp"
14 : : #include "OctreeFacetPointData.hpp"
15 : :
16 : :
17 : :
18 : : /* -------------------- Methods of CubitOctree ---------------- */
19 : : // Takes the following parameters
20 : : // min_depth : Minimum depth of the CubitOctree (avoids large cubes).
21 : : // max_depht : Maximum depth of the CubitOctree (restricted by memory).
22 : :
23 [ # # ][ # # ]: 0 : CubitOctree::CubitOctree( CubitOctreeGenerator *lattice_gen ){
[ # # ][ # # ]
24 : :
25 [ # # ]: 0 : CubitOctreeNode::reset_counter();
26 : :
27 : 0 : cubitOctreeGenerator = lattice_gen;
28 : :
29 : :
30 : 0 : maxSizeGridNode = -CUBIT_DBL_MAX;
31 : 0 : minSizeGridNode = CUBIT_DBL_MAX;
32 : :
33 [ # # ]: 0 : CubitVector min_corner;
34 [ # # ]: 0 : CubitVector max_corner;
35 : :
36 [ # # ]: 0 : lattice_gen->get_bounding_box( min_corner, max_corner );
37 : :
38 : : // note (vvyas 7/2005): perturbing bbox unsymmetrically to help avoid degenerate cases
39 : : // in SAT intersection code
40 [ # # ]: 0 : CubitVector min_perturbation(-.0001,-.0002,-.0003);
41 [ # # ]: 0 : CubitVector max_perturbation(.0005,.00012,.00028);
42 : :
43 [ # # ]: 0 : min_corner += min_perturbation;
44 [ # # ]: 0 : max_corner += max_perturbation;
45 : :
46 [ # # ]: 0 : CubitBox bbox(min_corner, max_corner );
47 : :
48 [ # # ]: 0 : double x_range = bbox.x_range();
49 [ # # ]: 0 : double y_range = bbox.y_range();
50 [ # # ]: 0 : double z_range = bbox.z_range();
51 : :
52 : : double max_range;
53 [ # # ]: 0 : max_range = ( x_range > y_range ) ? x_range : y_range;
54 [ # # ]: 0 : max_range = ( z_range > max_range ) ? z_range : max_range;
55 : :
56 [ # # ][ # # ]: 0 : bboxCenter.x(( min_corner.x() + max_corner.x() ) / 2.0);
[ # # ]
57 [ # # ][ # # ]: 0 : bboxCenter.y(( min_corner.y() + max_corner.y() ) / 2.0);
[ # # ]
58 [ # # ][ # # ]: 0 : bboxCenter.z(( min_corner.z() + max_corner.z() ) / 2.0);
[ # # ]
59 : :
60 : 0 : epsilonBBox = max_range / pow(2.0, OCTREE_MAX_DEPTH_OCTREE[OCTREE_TIME_ACCURACY_LEVEL] ) * 0.15;
61 : 0 : bboxDimension = max_range + 2 * epsilonBBox;
62 : :
63 : :
64 [ # # ]: 0 : bboxMaxX = bboxCenter.x() + bboxDimension / 2.0;
65 [ # # ]: 0 : bboxMinX = bboxCenter.x() - bboxDimension / 2.0;
66 [ # # ]: 0 : bboxMaxY = bboxCenter.y() + bboxDimension / 2.0;
67 [ # # ]: 0 : bboxMinY = bboxCenter.y() - bboxDimension / 2.0;
68 [ # # ]: 0 : bboxMaxZ = bboxCenter.z() + bboxDimension / 2.0;
69 [ # # ]: 0 : bboxMinZ = bboxCenter.z() - bboxDimension / 2.0;
70 : :
71 : : // Data structure flags are used to know if a perticualr data structure is already established or not.
72 : :
73 : 0 : statusCubitOctreeColoring = CUBIT_FALSE;
74 : :
75 : 0 : minDepth = OCTREE_MIN_DEPTH_OCTREE[OCTREE_TIME_ACCURACY_LEVEL];
76 : 0 : maxDepth = OCTREE_MAX_DEPTH_OCTREE[OCTREE_TIME_ACCURACY_LEVEL];
77 : :
78 [ # # ]: 0 : root = NULL;
79 : 0 : }
80 : :
81 [ # # ][ # # ]: 0 : CubitOctree::~CubitOctree(){
[ # # ][ # # ]
82 : :
83 [ # # ]: 0 : greyCellList.clean_out();
84 : :
85 [ # # ]: 0 : boundaryWhiteGridNodeList.clean_out();
86 : :
87 : : int i;
88 : : int num_elm;
89 : :
90 : : //PRINT_INFO("BEFORE: Deleted grid nodes \n");
91 : : //system("pause");
92 [ # # ]: 0 : num_elm = gridNodeVector.size();
93 : : CubitOctreeNode *ognode;
94 [ # # ]: 0 : for( i = 0; i < num_elm; i++ ){
95 [ # # ]: 0 : ognode = gridNodeVector.pop();
96 [ # # ][ # # ]: 0 : if (ognode) {delete ognode;}
[ # # ]
97 : : }
98 [ # # ][ # # ]: 0 : for (i=0; i < greyGridNodeVector.size(); ++i)
99 : : {
100 [ # # ][ # # ]: 0 : delete (greyGridNodeVector.get_and_step());
[ # # ]
101 : : }
102 : :
103 : : //PRINT_INFO("AFTER: Deleted grid nodes \n");
104 : : //system("pause");
105 [ # # ][ # # ]: 0 : delete root;
106 : :
107 : : //PRINT_INFO("AFTER: Deleted CubitOctree cells \n");
108 : : // system("pause");
109 [ # # ]: 0 : }
110 : :
111 : :
112 : 0 : double CubitOctree::calculate_depth_based_on_size( double size ){
113 : :
114 : 0 : return ceil( log((double)get_bbox_dimension() / (double)size ) / log(2.0) );
115 : : }
116 : :
117 : :
118 : :
119 : 0 : CubitBoolean CubitOctree::initialize_octree_generation( void ){
120 : :
121 : :
122 : : // Normalize the center and size of the CubitOctree cell
123 : : // bbox dimension is 1.0 with center at 1/2, 1/2, 1/2
124 [ # # ]: 0 : CubitVector norm_center;
125 : 0 : int level = 0;
126 : : int i,j, k, l, m, n;
127 : : double norm_dim;
128 : :
129 : : //norm_center.x(100.0 / 2);
130 : : //norm_center.y(100.0 / 2);
131 : : //norm_center.z(100.0 / 2);
132 : : //norm_dim = 100.0;
133 : :
134 [ # # ]: 0 : norm_center = bboxCenter;
135 : 0 : norm_dim = bboxDimension;
136 : :
137 : : //VERBOSE PRINT_INFO(" BBOX Center = [ %f %f %f ] Dim = %f \n",norm_center.x(), norm_center.y(), norm_center.z(), norm_dim );
138 : :
139 [ # # ][ # # ]: 0 : root = new CubitOctreeCell( norm_center, norm_dim, level, NULL );
[ # # ]
140 [ # # ]: 0 : CubitVector shift;
141 : :
142 : :
143 : :
144 : : CubitOctreeNode *ptr_oct_node[2][2][2];
145 : :
146 [ # # ]: 0 : for( i = 0; i < 2; i++ ){
147 [ # # ]: 0 : for( j = 0; j < 2; j++ ){
148 [ # # ]: 0 : for( k = 0; k < 2; k++ ){
149 [ # # ]: 0 : if( i == 0 )
150 [ # # ]: 0 : shift.x( -norm_dim / 2.0 );
151 : : else
152 [ # # ]: 0 : shift.x( norm_dim / 2.0 );
153 : :
154 [ # # ]: 0 : if( j == 0 )
155 [ # # ]: 0 : shift.y( -norm_dim / 2.0 );
156 : : else
157 [ # # ]: 0 : shift.y( norm_dim / 2.0 );
158 : :
159 [ # # ]: 0 : if( k == 0 )
160 [ # # ]: 0 : shift.z( -norm_dim / 2.0 );
161 : : else
162 [ # # ]: 0 : shift.z( norm_dim / 2.0 );
163 : :
164 : 0 : l = ( i == 1 )?0:1; // fliped 0 -> 1; 1 -> 0
165 : 0 : m = ( j == 1 )?0:1;
166 : 0 : n = ( k == 1 )?0:1;
167 : :
168 [ # # ][ # # ]: 0 : ptr_oct_node[i][j][k] = new CubitOctreeNode( norm_center + shift, root, l, m, n );
[ # # ]
169 [ # # ]: 0 : apd_vector_item( ptr_oct_node[i][j][k] );
170 : : }
171 : : }
172 : : }
173 : :
174 : : // Connecting CubitOctree Grid Nodes
175 : : //- adj_node[0] = O_FRONT Node
176 : : // adj_node[1] = O_BACK Node
177 : : // adj_node[2] = O_RIGHT Node
178 : : // adj_node[3] = O_LEFT Node
179 : : // adj_node[4] = O_TOP Node
180 : : // adj_node[5] = O_BOTTOM Node
181 : :
182 [ # # ]: 0 : for( i = 0; i < 2; i++ ){
183 [ # # ]: 0 : for( j = 0; j < 2; j++ ){
184 [ # # ]: 0 : for( k = 0; k < 2; k++ ){
185 : :
186 [ # # ]: 0 : if( i == 0 ){
187 [ # # ]: 0 : ptr_oct_node[i][j][k]->set_adj_node( O_FRONT, ptr_oct_node[1][j][k] );
188 [ # # ]: 0 : ptr_oct_node[i][j][k]->set_adj_node_distance( O_FRONT, 0 );
189 : : }
190 : : else{
191 [ # # ]: 0 : ptr_oct_node[i][j][k]->set_adj_node( O_BACK, ptr_oct_node[0][j][k] );
192 [ # # ]: 0 : ptr_oct_node[i][j][k]->set_adj_node_distance( O_BACK, 0 );
193 : : }
194 : :
195 [ # # ]: 0 : if( j == 0 ){
196 [ # # ]: 0 : ptr_oct_node[i][j][k]->set_adj_node( O_RIGHT, ptr_oct_node[i][1][k] );
197 [ # # ]: 0 : ptr_oct_node[i][j][k]->set_adj_node_distance( O_RIGHT, 0 );
198 : : }
199 : : else{
200 [ # # ]: 0 : ptr_oct_node[i][j][k]->set_adj_node( O_LEFT, ptr_oct_node[i][0][k] );
201 [ # # ]: 0 : ptr_oct_node[i][j][k]->set_adj_node_distance( O_LEFT, 0 );
202 : : }
203 : :
204 [ # # ]: 0 : if( k == 0 ){
205 [ # # ]: 0 : ptr_oct_node[i][j][k]->set_adj_node( O_TOP, ptr_oct_node[i][j][1] );
206 [ # # ]: 0 : ptr_oct_node[i][j][k]->set_adj_node_distance( O_TOP, 0 );
207 : : }
208 : : else{
209 [ # # ]: 0 : ptr_oct_node[i][j][k]->set_adj_node( O_BOTTOM, ptr_oct_node[i][j][0] );
210 [ # # ]: 0 : ptr_oct_node[i][j][k]->set_adj_node_distance( O_BOTTOM, 0 );
211 : : }
212 : :
213 : : }
214 : : }
215 : : }
216 : :
217 : :
218 : : // Update the nodes of the root
219 [ # # ]: 0 : for( i = 0; i < 2; i++ ){
220 [ # # ]: 0 : for( j = 0; j < 2; j++ ){
221 [ # # ]: 0 : for( k = 0; k < 2; k++ ){
222 [ # # ]: 0 : root->set_oct_grid_node( i, j, k, ptr_oct_node[i][j][k] );
223 : :
224 : : }
225 : : }
226 : : }
227 : :
228 : : //root->display( this );
229 : :
230 : 0 : return CUBIT_TRUE;
231 : : }
232 : :
233 : :
234 : 0 : CubitBoolean CubitOctree::build_octree_till_min_depth( CubitOctreeCell *ptr_cell ){
235 : :
236 : : int i, j, k;
237 : :
238 [ # # ]: 0 : if( ptr_cell->get_depth() < minDepth ){
239 : :
240 : 0 : subdivide_octree_cell( ptr_cell, NULL, minDepth );
241 : :
242 : : // PRINT_INFO(" establish connection between new nodes and pointed old nodes \n");
243 : :
244 : : // Recursively call all the childen
245 [ # # ]: 0 : for( i = 0; i < 2; i++ ){
246 [ # # ]: 0 : for( j = 0; j < 2; j++ ){
247 [ # # ]: 0 : for( k = 0; k < 2; k++ ){
248 : : // PRINT_INFO("Child : %d %d %d \n",i,j,k );
249 : 0 : build_octree_till_min_depth( ptr_cell->get_child(i, j, k) );
250 : : }
251 : : }
252 : : }
253 : :
254 : : // PRINT_INFO(" finished calling all recursively all children \n");
255 : :
256 : : }
257 : 0 : return CUBIT_TRUE;
258 : :
259 : : }
260 : :
261 : :
262 : :
263 : 0 : CubitBoolean CubitOctree::subdivide_octree_based_on_facet_point( OctreeFacetPointData *ptr_facet_point_data, int max_depth ){
264 : :
265 : : CubitOctreeCell *ptr_leaf_cell;
266 : :
267 [ # # ]: 0 : ptr_leaf_cell = root->find_leaf_octree_cell( ptr_facet_point_data->coordinates() );
268 : :
269 : 0 : CubitBoolean result = subdivide_octree_from_leaf_cell( ptr_leaf_cell, ptr_facet_point_data, max_depth );
270 [ # # ]: 0 : if( result == CUBIT_FALSE ){
271 : : // Simillar point exist; delete this facet_point_data
272 [ # # ]: 0 : delete ptr_facet_point_data;
273 : 0 : return CUBIT_FALSE;
274 : : }
275 : :
276 : 0 : return CUBIT_TRUE;
277 : : }
278 : :
279 : :
280 : 0 : CubitBoolean CubitOctree::find_cells_based_on_surface_angle(DLIList<CubitOctreeCell*> &refine_cell_list, DLIList<CubitFacetEdge*> &crease_edges, DLIList<CubitFacet*> &crease_facets,
281 : : RefFace *one, RefFace *two, const CubitBoolean draw_facets, double dihedral_angle_thresh)
282 : : {
283 : : int i, j, k;
284 : :
285 : : CubitFacetEdge *edge;
286 : 0 : CubitBoolean water_tight = CUBIT_FALSE;
287 : :
288 [ # # ]: 0 : DLIList<DLIList<CubitFacet*>*> shell_list;
289 [ # # ][ # # ]: 0 : DLIList<CubitQuadFacet*> dummy;
290 [ # # ][ # # ]: 0 : DLIList<CubitFacet*> mark1, mark2, facets, facet1, facet2, draw_facet_list;
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
291 [ # # ][ # # ]: 0 : DLIList<CubitFacetEdge*> new_edge1, new_edge2;
[ # # ][ # # ]
292 [ # # ][ # # ]: 0 : DLIList<CubitPoint*> new_points;
293 : :
294 : 0 : CubitFacet *temp_facet = NULL;
295 : :
296 [ # # ][ # # ]: 0 : if (one == NULL || two == NULL)
297 : : {
298 : 0 : return CUBIT_FALSE;
299 : : }
300 : :
301 : 0 : dihedral_angle_thresh = cos(dihedral_angle_thresh);
302 : :
303 [ # # ]: 0 : TDOctreeRefFace *td_skl_one = TDOctreeRefFace::get_td(one),
304 [ # # ]: 0 : *td_skl_two = TDOctreeRefFace::get_td(two);
305 : :
306 [ # # ][ # # ]: 0 : if (td_skl_one == NULL || td_skl_two == NULL ||
[ # # ]
307 [ # # ][ # # ]: 0 : td_skl_one->get_ptr_cubit_facet_list() == NULL || td_skl_two->get_ptr_cubit_facet_list() == NULL)
[ # # ][ # # ]
308 : : {
309 [ # # ][ # # ]: 0 : PRINT_DEBUG_157("CubitOctree::find_cells_based_on_surface_angle: null TDs or null facet list ptr\n");
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ]
310 [ # # ][ # # ]: 0 : PRINT_DEBUG_157("RefFace one->id()=%d, td_skl=%p\ntwo->id()=%d, td_skl=%p\n", one->id(), (void*)td_skl_one,
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
311 [ # # ]: 0 : two->id(), (void*)td_skl_two);
312 [ # # ][ # # ]: 0 : PRINT_DEBUG_157("This may happen when one volume sizing function \'steals\'\na surface from an existing sizing function.");
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ]
313 : 0 : return CUBIT_FALSE;
314 : : }
315 : :
316 [ # # ][ # # ]: 0 : if (!td_skl_one->get_create_2dmat() || !td_skl_two->get_create_2dmat()) {return CUBIT_FALSE;}
[ # # ][ # # ]
[ # # ]
317 : :
318 : :
319 [ # # ][ # # ]: 0 : FacetDataUtil::copy_facets(*TDOctreeRefFace::get_td(one)->get_ptr_cubit_facet_list(), facet1, new_points, new_edge1);
[ # # ]
320 [ # # ][ # # ]: 0 : FacetDataUtil::copy_facets(*TDOctreeRefFace::get_td(two)->get_ptr_cubit_facet_list(), facet2, new_points, new_edge2);
[ # # ]
321 : :
322 [ # # ][ # # ]: 0 : for (i=0; i < new_edge1.size(); ++i)
323 : : {
324 [ # # ]: 0 : edge = new_edge1.get_and_step();
325 [ # # ][ # # ]: 0 : if (edge->number_tris() == 1)
326 : : {
327 [ # # ]: 0 : temp_facet = edge->adj_facet(0);
328 [ # # ][ # # ]: 0 : if (!temp_facet->marked())
329 : : {
330 [ # # ][ # # ]: 0 : mark1.append(edge->adj_facet(0));
331 [ # # ]: 0 : temp_facet->marked(CUBIT_TRUE);
332 : : }
333 : : //facets.append(edge->adj_facet(0));
334 : : }
335 : : }
336 : :
337 [ # # ][ # # ]: 0 : for (i=0; i < new_edge2.size(); ++i)
338 : : {
339 [ # # ]: 0 : edge = new_edge2.get_and_step();
340 [ # # ][ # # ]: 0 : if (edge->number_tris() == 1)
341 : : {
342 [ # # ]: 0 : temp_facet = edge->adj_facet(0);
343 [ # # ][ # # ]: 0 : if (!temp_facet->marked())
344 : : {
345 [ # # ][ # # ]: 0 : mark2.append(edge->adj_facet(0));
346 [ # # ]: 0 : temp_facet->marked(CUBIT_TRUE);
347 : : }
348 : : //facets.append(edge->adj_facet(0));
349 : : }
350 : : }
351 : :
352 [ # # ][ # # ]: 0 : for (i=0; i < mark1.size(); ++i)
353 : : {
354 [ # # ][ # # ]: 0 : mark1.get_and_step()->marked(CUBIT_FALSE);
355 : : }
356 : :
357 [ # # ][ # # ]: 0 : for (i=0; i < mark2.size(); ++i)
358 : : {
359 [ # # ][ # # ]: 0 : mark2.get_and_step()->marked(CUBIT_FALSE);
360 : : }
361 : :
362 [ # # ]: 0 : facets += facet1;
363 [ # # ]: 0 : facets += facet2;
364 : :
365 [ # # ]: 0 : facet1.clean_out(); //delete facet1;
366 [ # # ]: 0 : facet2.clean_out(); //delete facet2;
367 [ # # ]: 0 : new_edge1.clean_out(); //delete new_edge1;
368 [ # # ]: 0 : new_edge2.clean_out(); //delete new_edge2;
369 [ # # ]: 0 : new_points.clean_out(); //delete new_points;
370 : :
371 : :
372 [ # # ]: 0 : CubitStatus rv = FacetDataUtil::split_into_shells(/*facet1*/facets, dummy, shell_list, water_tight);
373 [ # # ][ # # ]: 0 : if (!rv || shell_list.size() == 0)
[ # # ][ # # ]
374 : : {
375 [ # # ][ # # ]: 0 : PRINT_DEBUG_157("CubitOctree::find_cells_based_on_surface_angle: could not form shells from facet list!\n");
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ]
376 [ # # ][ # # ]: 0 : PRINT_DEBUG_157("return value was %d, number of shells is %d\n", rv, shell_list.size());
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
377 : : //SVDrawTool::clear_non_retained();
378 : : //SVDrawTool::draw_facets(facets, CUBIT_RED_INDEX);
379 : : //SVDrawTool::mouse_xforms();
380 : 0 : return CUBIT_FALSE;
381 : : }
382 : :
383 : :
384 : : /*
385 : : int num_null_shells = 0;
386 : : for (i=0; i < shell_list.size(); ++i)
387 : : {
388 : : if (shell_list.get_and_step() == NULL)
389 : : {
390 : : ++num_null_shells;
391 : : }
392 : : }
393 : : if (num_null_shells)
394 : : {
395 : : PRINT_INFO("CubitOctree::find_cells_based_on_surface_angle: %d of %d shells formed from facets are NULL!\n", num_null_shells, shell_list.size());
396 : : }
397 : : */
398 : :
399 : : ////////////////
400 [ # # ]: 0 : rv = FacetDataUtil::stitch_facets(shell_list, 1e-4, water_tight, CUBIT_FALSE);
401 [ # # ]: 0 : if (!rv)
402 : : {
403 [ # # ][ # # ]: 0 : PRINT_DEBUG_157("CubitOctree::find_cells_based_on_surface_angle: could not stitch facets!\n");
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ]
404 : : //SVDrawTool::clear_non_retained();
405 : : //SVDrawTool::draw_facets(facets, CUBIT_RED_INDEX);
406 : : //SVDrawTool::mouse_xforms();
407 : 0 : return CUBIT_FALSE;
408 : : }
409 : : ////////////////////
410 : :
411 : : //TDSkeletonCubitFacet::stitch_facets(facet1,facet2);
412 : :
413 [ # # ][ # # ]: 0 : for (i=0; i < mark1.size(); ++i)
414 : : {
415 [ # # ]: 0 : CubitFacet *facet = mark1.get_and_step();
416 : :
417 [ # # ][ # # ]: 0 : if (facet->marked()) {continue;}
418 [ # # ]: 0 : facet->marked(CUBIT_TRUE);
419 : :
420 [ # # ][ # # ]: 0 : for (j=0; j < mark2.size(); ++j)
421 : : {
422 [ # # ]: 0 : for (k=0; k < 3; ++k)
423 : : {
424 [ # # ][ # # ]: 0 : CubitFacet *other = facet->shared_facet(facet->point(k), facet->point((k+1)%3));
[ # # ]
425 [ # # ][ # # ]: 0 : if (other != NULL && other == mark2[j] && !mark2[j]->marked() && (facet->normal() % other->normal() < dihedral_angle_thresh))
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # # #
# # ]
426 : : {
427 : : //crease_edges.append(facet->point(k)->shared_edge(facet->point((k+1)%3)));
428 [ # # ][ # # ]: 0 : find_cell_list_intersecting_line_segment(facet->point(k)->coordinates(), facet->point((k+1)%3)->coordinates(), refine_cell_list);
[ # # ][ # # ]
[ # # ]
429 [ # # ][ # # ]: 0 : mark2[j]->marked(CUBIT_TRUE);
430 : :
431 [ # # ]: 0 : if (draw_facets)
432 : : {
433 [ # # ]: 0 : draw_facet_list.append(facet);
434 [ # # ]: 0 : draw_facet_list.append(other);
435 : : }
436 : : }
437 : : }
438 : : }
439 : : }
440 : :
441 : : if (draw_facets) {
442 : : //SVDrawTool::draw_facets(draw_facet_list, CUBIT_MAGENTA_INDEX);
443 : : }
444 : :
445 [ # # ][ # # ]: 0 : if (refine_cell_list.size() > 0)
446 : : {
447 : : //crease_facets += facets;
448 [ # # ]: 0 : FacetDataUtil::delete_facets(facets);
449 : 0 : return CUBIT_TRUE;
450 : : }
451 : :
452 [ # # ]: 0 : FacetDataUtil::delete_facets(facets);
453 [ # # ]: 0 : return CUBIT_FALSE;
454 : : }
455 : :
456 : 0 : void CubitOctree::refine_cells_to_target_depth(DLIList<CubitOctreeCell*> &refine_cell_list, const int target_depth)
457 : : {
458 : : int i, j, k;
459 : 0 : CubitOctreeCell *current_cell = NULL;
460 : :
461 [ # # ]: 0 : while (refine_cell_list.size() > 0)
462 : : {
463 : 0 : current_cell = refine_cell_list.get();
464 [ # # ]: 0 : if (subdivide_octree_cell(current_cell, NULL, target_depth))
465 : : {
466 [ # # ]: 0 : for (i=0; i < 2; ++i)
467 : : {
468 [ # # ]: 0 : for (j=0; j < 2; ++j)
469 : : {
470 [ # # ]: 0 : for (k=0; k < 2; ++k)
471 : : {
472 [ # # ]: 0 : if (current_cell->get_child(i,j,k) != NULL)
473 : : {
474 [ # # ]: 0 : refine_cell_list.append(current_cell->get_child(i,j,k));
475 : : }
476 : : }
477 : : }
478 : : }
479 : : }
480 : 0 : refine_cell_list.extract();
481 : : }
482 : 0 : }
483 : :
484 : : // Checks for only marked cells and unmarks it if it doesn't interesect
485 : 0 : CubitBoolean CubitOctree::unmark_octree_cells_not_intersecting_with_facet( CubitFacet *ptr_facet, DLIList<CubitOctreeCell *> &CubitOctree_cell_list){
486 : :
487 : : int i;
488 : : CubitOctreeCell *ptr_cell;
489 : :
490 [ # # ]: 0 : for( i = 0; i < CubitOctree_cell_list.size(); i++ ){
491 : 0 : ptr_cell = CubitOctree_cell_list.get_and_step();
492 [ # # ]: 0 : if( ptr_cell->get_mark() == CUBIT_TRUE ){
493 [ # # ]: 0 : if( ptr_cell->does_facet_intersect_octreecell( ptr_facet ) == CUBIT_FALSE ){
494 : 0 : ptr_cell->set_mark( CUBIT_FALSE );
495 : : }
496 : : }
497 : : }
498 : 0 : return CUBIT_TRUE;
499 : : }
500 : :
501 : :
502 : 0 : CubitBoolean CubitOctree::mark_cells_that_intersect_facet_plane( /*CubitFacet *ptr_facet,*/ DLIList<CubitOctreeCell*> &CubitOctree_cell_list )
503 : : {
504 : : int i;
505 : : CubitOctreeCell *ptr_cell;
506 : :
507 [ # # ]: 0 : for( i = 0; i < CubitOctree_cell_list.size(); i++ ){
508 : 0 : ptr_cell = CubitOctree_cell_list.get_and_step();
509 [ # # ]: 0 : if( ptr_cell->does_contain_positive_and_negative_nodes() == CUBIT_TRUE ){
510 : 0 : ptr_cell->set_mark( CUBIT_TRUE );
511 : : }
512 : : }
513 : :
514 : 0 : return CUBIT_TRUE;
515 : : }
516 : :
517 : :
518 : 0 : CubitBoolean CubitOctree::subdivide_octree_from_leaf_cell( CubitOctreeCell *ptr_cell, OctreeFacetPointData *facet_point_data, int max_depth ){
519 : :
520 [ # # ]: 0 : CubitVector cell_center = ptr_cell->get_center();
521 : : int i, j, k;
522 : :
523 [ # # ]: 0 : CubitVector coord;
524 : :
525 : : // Check if any other coord already present in the cell is close to new facet_point_data
526 : : // At the common curves the facet points of adjacent surfaces can come very close to one another
527 : : // Therefore id will not work
528 : :
529 [ # # ][ # # ]: 0 : if( ptr_cell->num_of_facet_point_data() != 0 ){
530 [ # # ][ # # ]: 0 : if( ptr_cell->is_facet_point_data_present( facet_point_data ) ){
531 : 0 : return CUBIT_FALSE;
532 : : }
533 : : }
534 : :
535 : :
536 : : // If CubitOctree cell contains on fact points just insert the point don't subdivide (Ref. PR-CubitOctree property)
537 : : //
538 [ # # ][ # # ]: 0 : if( ptr_cell->num_of_facet_point_data() == 0 || ptr_cell->get_depth() >= max_depth ){
[ # # ][ # # ]
[ # # ]
539 : :
540 [ # # ]: 0 : ptr_cell->append_list_item( facet_point_data );
541 : 0 : return CUBIT_TRUE;
542 : :
543 : : }
544 : :
545 [ # # ][ # # ]: 0 : coord = facet_point_data->coordinates();
546 : 0 : bool outside_tolerance = CUBIT_TRUE;
547 [ # # ]: 0 : DLIList<OctreeFacetPointData*> *fpdata = ptr_cell->get_facet_point_data_list();
548 [ # # ][ # # ]: 0 : for (i=0; i < fpdata->size(); ++i)
549 : : {
550 [ # # ][ # # ]: 0 : if ((fpdata->get_and_step()->coordinates()-coord).length_squared() <= OCTREE_EPSILON * OCTREE_EPSILON)
[ # # ][ # # ]
[ # # ]
551 : : {
552 : 0 : outside_tolerance = CUBIT_FALSE;
553 : : }
554 : : }
555 : :
556 [ # # ]: 0 : if (!outside_tolerance)
557 : : {
558 [ # # ]: 0 : ptr_cell->append_list_item(facet_point_data);
559 : 0 : return CUBIT_TRUE;
560 : :
561 : : }
562 : : else{
563 : :
564 [ # # ]: 0 : subdivide_octree_cell( ptr_cell, NULL, max_depth );
565 : :
566 : :
567 : : // find the leaf cell containing the point
568 : : // call the subdivision recursively from leaf cell containing the point.
569 : 0 : i = j = k = 1;
570 : :
571 [ # # ][ # # ]: 0 : if( coord.x() < cell_center.x() )
[ # # ]
572 : 0 : i = 0;
573 : :
574 [ # # ][ # # ]: 0 : if( coord.y() < cell_center.y() )
[ # # ]
575 : 0 : j = 0;
576 : :
577 [ # # ][ # # ]: 0 : if( coord.z() < cell_center.z() )
[ # # ]
578 : 0 : k = 0;
579 : :
580 [ # # ][ # # ]: 0 : subdivide_octree_from_leaf_cell( ptr_cell->get_child(i, j, k), facet_point_data, max_depth );
581 : :
582 : : }
583 : 0 : return CUBIT_TRUE;
584 : :
585 : : }
586 : :
587 : 0 : CubitBoolean CubitOctree::find_octree_cells_contained_inside_bbox( CubitFacet *ptr_facet, DLIList<CubitOctreeCell*> &CubitOctree_cell_list ){
588 : :
589 : : CubitPoint *p0, *p1, *p2;
590 [ # # ]: 0 : CubitBox facet_bbox;
591 [ # # ][ # # ]: 0 : DLIList<CubitOctreeCell*> queue;
592 [ # # ][ # # ]: 0 : DLIList<CubitOctreeCell*> marked_list;
593 : : CubitOctreeCell *CubitOctree_cell1, *CubitOctree_cell2, *CubitOctree_cell3;
594 : : CubitOctreeCell *ptr_cell;
595 : : CubitBoolean result;
596 : : int i;
597 : :
598 [ # # ]: 0 : queue.clean_out();
599 : :
600 [ # # ][ # # ]: 0 : facet_bbox = ptr_facet->bounding_box();
601 : : //PRINT_DEBUG_157(" BBox min : %f %f %f max : %f %f %f ", facet_bbox.minimum().x(), facet_bbox.minimum().y(), facet_bbox.minimum().z(), facet_bbox.maximum().x(), facet_bbox.maximum().y(), facet_bbox.maximum().z() );
602 : :
603 [ # # ]: 0 : ptr_facet->points( p0, p1, p2 );
604 : :
605 : :
606 [ # # ][ # # ]: 0 : CubitOctree_cell1 = find_octreecell( p0->coordinates() );
607 : : //CubitOctree_cell_list.push( CubitOctree_cell1 );
608 [ # # ]: 0 : queue.push( CubitOctree_cell1 );
609 [ # # ]: 0 : CubitOctree_cell1->set_mark( CUBIT_TRUE );
610 : :
611 [ # # ][ # # ]: 0 : CubitOctree_cell2 = find_octreecell( p1->coordinates() );
612 : : //CubitOctree_cell_list.push( CubitOctree_cell2 );
613 [ # # ][ # # ]: 0 : if( CubitOctree_cell2->get_mark() == CUBIT_FALSE ){
614 [ # # ]: 0 : queue.push( CubitOctree_cell2 );
615 [ # # ]: 0 : CubitOctree_cell2->set_mark( CUBIT_TRUE );
616 : : }
617 : :
618 [ # # ][ # # ]: 0 : CubitOctree_cell3 = find_octreecell( p2->coordinates() );
619 : : //CubitOctree_cell_list.push( CubitOctree_cell3 );
620 [ # # ][ # # ]: 0 : if( CubitOctree_cell3->get_mark() == CUBIT_FALSE ){
621 [ # # ]: 0 : queue.push( CubitOctree_cell3 );
622 [ # # ]: 0 : CubitOctree_cell3->set_mark( CUBIT_TRUE );
623 : : }
624 : :
625 [ # # ][ # # ]: 0 : while( queue.size() > 0 ){
626 : :
627 [ # # ]: 0 : ptr_cell = queue.pop();
628 [ # # ]: 0 : marked_list.push( ptr_cell );
629 : :
630 [ # # ]: 0 : result = ptr_cell->is_intersects_box( facet_bbox );
631 : :
632 [ # # ]: 0 : if( result == CUBIT_TRUE ){
633 [ # # ]: 0 : CubitOctree_cell_list.push( ptr_cell );
634 : : // add adjacent unmarked CubitOctree cells to queue
635 [ # # ]: 0 : ptr_cell->add_adjacent_unmarked_cells( queue );
636 : : }
637 : :
638 : : }
639 : :
640 [ # # ][ # # ]: 0 : for( i = 0; i < marked_list.size(); i++ ){
641 [ # # ]: 0 : ptr_cell = marked_list.get_and_step();
642 [ # # ]: 0 : ptr_cell->set_mark( CUBIT_FALSE );
643 : : //ptr_cell->display(this);
644 : : }
645 : :
646 [ # # ]: 0 : return CUBIT_TRUE;
647 : : }
648 : :
649 : :
650 : 0 : CubitBoolean CubitOctree::mark_positive_and_negative_octree_grid_nodes( CubitFacet *ptr_facet, DLIList<CubitOctreeCell*> &CubitOctree_cell_list, DLIList<CubitOctreeNode *> &CubitOctree_grid_node_list ){
651 : :
652 : : CubitOctreeCell *ptr_cell;
653 : : int i, l, m, n;
654 : : CubitOctreeNode *ptr_grid_node;
655 : :
656 [ # # ]: 0 : for( i = 0; i < CubitOctree_cell_list.size(); i++ ){
657 : 0 : ptr_cell = CubitOctree_cell_list.get_and_step();
658 : :
659 [ # # ]: 0 : for( l = 0; l < 2; l++ ){
660 [ # # ]: 0 : for( m = 0; m < 2; m++ ){
661 [ # # ]: 0 : for( n = 0; n < 2; n++ ){
662 : 0 : ptr_grid_node = ptr_cell->get_octree_grid_node( l, m, n );
663 : :
664 [ # # ]: 0 : if( ptr_grid_node->get_mark() == CUBIT_FALSE ){
665 : 0 : ptr_grid_node->find_half_space( ptr_facet );
666 : 0 : ptr_grid_node->set_mark( CUBIT_TRUE );
667 : 0 : CubitOctree_grid_node_list.push( ptr_grid_node );
668 : : }
669 : : }
670 : : }
671 : : }
672 : : }
673 : :
674 : 0 : return CUBIT_TRUE;
675 : : }
676 : :
677 : :
678 : 0 : CubitBoolean CubitOctree::find_intersection_between_grid_edges_and_facet( CubitOctreeType type, RefFace *ptr_face, CubitFacet *ptr_facet, DLIList<CubitOctreeNode *> &CubitOctree_grid_node_list ){
679 : :
680 : : int i;
681 : : CubitOctreeNode *ptr_grid_node;
682 : :
683 [ # # ]: 0 : for( i = 0; i < CubitOctree_grid_node_list.size(); i++ ){
684 : 0 : ptr_grid_node = CubitOctree_grid_node_list.get_and_step();
685 [ # # ]: 0 : if( ptr_grid_node->get_halfspace_direction() == OCTREE_POSITIVE ){
686 : 0 : ptr_grid_node->find_intersection_with_facet( type, ptr_face, ptr_facet, boundaryWhiteGridNodeList );
687 : : }
688 : : }
689 : :
690 : : // reset all +ve grid nodes to -ve
691 [ # # ]: 0 : for( i = 0; i < CubitOctree_grid_node_list.size(); i++ ){
692 : 0 : ptr_grid_node = CubitOctree_grid_node_list.get_and_step();
693 : 0 : ptr_grid_node->set_mark( CUBIT_FALSE );
694 [ # # ]: 0 : if( ptr_grid_node->get_halfspace_direction() == OCTREE_POSITIVE ){
695 : 0 : ptr_grid_node->set_halfspace_direction( OCTREE_NEGATIVE );
696 : : }
697 : : }
698 : :
699 : 0 : return CUBIT_TRUE;
700 : : }
701 : :
702 : :
703 : 0 : void CubitOctree::gather_initial_grid_nodes_for_smooth_transition( DLIList<CubitOctreeNode*> &queue ){
704 : : int i;
705 : : CubitOctreeNode *ptr_grid_node;
706 : : int depth_difference;
707 : :
708 [ # # ]: 0 : for( i = 0; i < gridNodeVector.size(); i++ ){
709 : 0 : ptr_grid_node = gridNodeVector.get_and_step();
710 : :
711 : 0 : depth_difference = ptr_grid_node->find_min_depth_cell_and_depth_difference();
712 : : // By default mark is maintained CUBIT_FALSE
713 [ # # ]: 0 : if( depth_difference >= 2 ){
714 : 0 : queue.push( ptr_grid_node );
715 : 0 : ptr_grid_node->set_mark( CUBIT_TRUE );
716 : : }
717 : : }
718 : :
719 : 0 : }
720 : :
721 : :
722 : : // Visit every black node and check the depth of the adjacent cells.
723 : : // If the cells differ more than 1 then split the maximum cell.
724 : 0 : CubitBoolean CubitOctree::establish_smooth_transition_of_cells( int max_depth ){
725 : :
726 : : CubitOctreeNode *ptr_grid_node;
727 : : int depth_difference;
728 [ # # ]: 0 : DLIList<CubitOctreeNode *> queue;
729 : :
730 [ # # ]: 0 : gather_initial_grid_nodes_for_smooth_transition( queue );
731 : :
732 [ # # ][ # # ]: 0 : while( queue.size() > 0 ){
733 [ # # ]: 0 : ptr_grid_node = queue.remove();
734 [ # # ]: 0 : ptr_grid_node->set_mark( CUBIT_FALSE );
735 : : // WARNING: Why Cubit Black only
736 : : // if( ptr_grid_node->get_color() == CUBIT_BLACK_INDEX ){
737 [ # # ]: 0 : depth_difference = ptr_grid_node->get_cell_depth_difference();
738 [ # # ]: 0 : if( depth_difference >= 2 ){
739 [ # # ][ # # ]: 0 : subdivide_octree_cell( ptr_grid_node->get_min_depth_cell(), &queue, max_depth );
740 : : }
741 : : //}
742 : : }
743 : :
744 [ # # ]: 0 : return CUBIT_TRUE;
745 : : }
746 : :
747 : 0 : CubitBoolean CubitOctree::subdivide_octree_cell( CubitOctreeCell *ptr_cell, DLIList<CubitOctreeNode*> *ptr_queue, int max_depth ){
748 : :
749 [ # # ][ # # ]: 0 : CubitVector cell_center, shift;
750 : : int new_depth, i, j, k, l, m, n, p, q, r;
751 : : double norm_dim, total_dist, new_half_point;
752 : : CubitOctreeCell *ptr_child_cell;
753 : : CubitOctreeNode *local_node_matrix[3][3][3], *ptr_node, *ptr_new_oct_grid_node;
754 : : CubitBoolean new_node_matrix[3][3][3];
755 : : CubitOctreeCell *ptr_new_cell;
756 : :
757 [ # # ][ # # ]: 0 : if( ptr_cell->get_depth() < max_depth && ptr_cell->is_leaf() )
[ # # ][ # # ]
[ # # ]
758 : : {
759 [ # # ]: 0 : ptr_cell->set_leaf( CUBIT_FALSE );
760 [ # # ]: 0 : norm_dim = ptr_cell->get_dimension();
761 [ # # ]: 0 : new_depth = ptr_cell->get_depth() + 1;
762 [ # # ][ # # ]: 0 : cell_center = ptr_cell->get_center();
763 : : // PRINT_INFO("Num = %d Depth = %d Coord = %2.12e %2.12e %2.12e\n", ptr_cell->get_num(), depth, cell_center.x(), cell_center.y(), cell_center.z() );
764 : :
765 [ # # ]: 0 : for( i = 0; i < 2; i++ ){
766 [ # # ]: 0 : for( j = 0; j < 2; j++ ){
767 [ # # ]: 0 : for( k = 0; k < 2; k++ ){
768 : :
769 [ # # ]: 0 : if( i == 0 )
770 [ # # ]: 0 : shift.x( -norm_dim / 4.0 );
771 : : else
772 [ # # ]: 0 : shift.x( norm_dim / 4.0 );
773 : :
774 [ # # ]: 0 : if( j == 0 )
775 [ # # ]: 0 : shift.y( -norm_dim / 4.0 );
776 : : else
777 [ # # ]: 0 : shift.y( norm_dim / 4.0 );
778 : :
779 [ # # ]: 0 : if( k == 0 )
780 [ # # ]: 0 : shift.z( -norm_dim / 4.0 );
781 : : else
782 [ # # ]: 0 : shift.z( norm_dim / 4.0 );
783 : :
784 : :
785 [ # # ][ # # ]: 0 : ptr_child_cell = new CubitOctreeCell( cell_center + shift, norm_dim / 2.0, new_depth, ptr_cell );
[ # # ]
786 [ # # ]: 0 : ptr_cell->set_child( i, j, k, ptr_child_cell );
787 : :
788 : : }
789 : : }
790 : : }
791 : :
792 : : // PRINT_INFO(" 8 children created \n");
793 : : // Update the wire frame model
794 : :
795 [ # # ]: 0 : for( i = 0; i < 3; i++ ){
796 [ # # ]: 0 : for( j = 0; j < 3; j++ ){
797 [ # # ]: 0 : for( k = 0; k < 3; k++ ){
798 : 0 : new_node_matrix[i][j][k] = CUBIT_FALSE;
799 : : }
800 : : }
801 : : }
802 : :
803 : : // find the eight corner nodes of the local matrix
804 [ # # ]: 0 : for( i = 0; i < 2; i++ ){
805 [ # # ]: 0 : for( j = 0; j < 2; j++ ){
806 [ # # ]: 0 : for( k = 0; k < 2; k++ ){
807 [ # # ]: 0 : if( i == 1 )
808 : 0 : l = 2;
809 : : else
810 : 0 : l = 0;
811 : :
812 [ # # ]: 0 : if( j == 1 )
813 : 0 : m = 2;
814 : : else
815 : 0 : m = 0;
816 : :
817 [ # # ]: 0 : if( k == 1 )
818 : 0 : n = 2;
819 : : else
820 : 0 : n = 0;
821 : :
822 [ # # ]: 0 : local_node_matrix[l][m][n] = ptr_cell->get_octree_grid_node( i, j, k );
823 : : }
824 : : }
825 : : }
826 : :
827 : : // PRINT_INFO(" find 8 corner nodes of local 3 x 3 matrix \n");
828 : :
829 : 0 : new_half_point = 1.0 / pow(2.0, new_depth);
830 : :
831 : : // To find 8
832 : 0 : ptr_node = local_node_matrix[2][0][2];
833 : 0 : total_dist = 0.0;
834 [ # # ]: 0 : while( total_dist < new_half_point ){
835 [ # # ]: 0 : total_dist += 1.0 / pow( 2.0, ptr_node->get_adj_node_distance( O_BOTTOM ) );
836 [ # # ]: 0 : ptr_node = ptr_node->get_adj_node( O_BOTTOM );
837 : : }
838 : :
839 [ # # ]: 0 : if( total_dist == new_half_point ){
840 : 0 : local_node_matrix[2][0][1] = ptr_node;
841 : : }
842 : : else{
843 [ # # ][ # # ]: 0 : ptr_new_oct_grid_node = new CubitOctreeNode( (local_node_matrix[2][0][2])->x(), (local_node_matrix[2][0][2])->y(), (local_node_matrix[2][0][2])->z() - norm_dim /2 );
[ # # ][ # # ]
[ # # ]
844 [ # # ]: 0 : apd_vector_item( ptr_new_oct_grid_node );
845 : 0 : local_node_matrix[2][0][1] = ptr_new_oct_grid_node;
846 : 0 : new_node_matrix[2][0][1] = CUBIT_TRUE;
847 : : }
848 : :
849 : :
850 : : // To find 9
851 : 0 : ptr_node = local_node_matrix[2][2][2];
852 : 0 : total_dist = 0.0;
853 [ # # ]: 0 : while( total_dist < new_half_point ){
854 [ # # ]: 0 : total_dist += 1.0 / pow( 2.0, ptr_node->get_adj_node_distance( O_BOTTOM ) );
855 [ # # ]: 0 : ptr_node = ptr_node->get_adj_node( O_BOTTOM );
856 : : }
857 : :
858 [ # # ]: 0 : if( total_dist == new_half_point ){
859 : 0 : local_node_matrix[2][2][1] = ptr_node;
860 : : }
861 : : else{
862 [ # # ][ # # ]: 0 : ptr_new_oct_grid_node = new CubitOctreeNode( (local_node_matrix[2][2][2])->x(), (local_node_matrix[2][2][2])->y(), (local_node_matrix[2][2][2])->z() - norm_dim /2 );
[ # # ][ # # ]
[ # # ]
863 [ # # ]: 0 : apd_vector_item( ptr_new_oct_grid_node );
864 : 0 : local_node_matrix[2][2][1] = ptr_new_oct_grid_node;
865 : 0 : new_node_matrix[2][2][1] = CUBIT_TRUE;
866 : : }
867 : :
868 : : // To find 10
869 : 0 : ptr_node = local_node_matrix[0][2][2];
870 : 0 : total_dist = 0.0;
871 [ # # ]: 0 : while( total_dist < new_half_point ){
872 [ # # ]: 0 : total_dist += 1.0 / pow( 2.0, ptr_node->get_adj_node_distance( O_BOTTOM ) );
873 [ # # ]: 0 : ptr_node = ptr_node->get_adj_node( O_BOTTOM );
874 : : }
875 : :
876 [ # # ]: 0 : if( total_dist == new_half_point ){
877 : 0 : local_node_matrix[0][2][1] = ptr_node;
878 : : }
879 : : else{
880 [ # # ][ # # ]: 0 : ptr_new_oct_grid_node = new CubitOctreeNode( (local_node_matrix[0][2][2])->x(), (local_node_matrix[0][2][2])->y(), (local_node_matrix[0][2][2])->z() - norm_dim /2 );
[ # # ][ # # ]
[ # # ]
881 [ # # ]: 0 : apd_vector_item( ptr_new_oct_grid_node );
882 : 0 : local_node_matrix[0][2][1] = ptr_new_oct_grid_node;
883 : 0 : new_node_matrix[0][2][1] = CUBIT_TRUE;
884 : : }
885 : :
886 : : // To find 11
887 : 0 : ptr_node = local_node_matrix[0][0][2];
888 : 0 : total_dist = 0.0;
889 [ # # ]: 0 : while( total_dist < new_half_point ){
890 [ # # ]: 0 : total_dist += 1.0 / pow( 2.0, ptr_node->get_adj_node_distance( O_BOTTOM ) );
891 [ # # ]: 0 : ptr_node = ptr_node->get_adj_node( O_BOTTOM );
892 : : }
893 [ # # ]: 0 : if( total_dist == new_half_point ){
894 : 0 : local_node_matrix[0][0][1] = ptr_node;
895 : : }
896 : : else{
897 [ # # ][ # # ]: 0 : ptr_new_oct_grid_node = new CubitOctreeNode( (local_node_matrix[0][0][2])->x(), (local_node_matrix[0][0][2])->y(), (local_node_matrix[0][0][2])->z() - norm_dim /2 );
[ # # ][ # # ]
[ # # ]
898 [ # # ]: 0 : apd_vector_item( ptr_new_oct_grid_node );
899 : 0 : local_node_matrix[0][0][1] = ptr_new_oct_grid_node;
900 : 0 : new_node_matrix[0][0][1] = CUBIT_TRUE;
901 : : }
902 : :
903 : : // To find 12
904 : 0 : ptr_node = local_node_matrix[2][0][2];
905 : 0 : total_dist = 0.0;
906 [ # # ]: 0 : while( total_dist < new_half_point ){
907 [ # # ]: 0 : total_dist += 1.0 / pow( 2.0, ptr_node->get_adj_node_distance( O_RIGHT ) );
908 [ # # ]: 0 : ptr_node = ptr_node->get_adj_node( O_RIGHT );
909 : : }
910 [ # # ]: 0 : if( total_dist == new_half_point ){
911 : 0 : local_node_matrix[2][1][2] = ptr_node;
912 : : }
913 : : else{
914 [ # # ][ # # ]: 0 : ptr_new_oct_grid_node = new CubitOctreeNode( (local_node_matrix[2][0][2])->x(), (local_node_matrix[2][0][2])->y() + norm_dim / 2.0, (local_node_matrix[2][0][2])->z() );
[ # # ][ # # ]
[ # # ]
915 [ # # ]: 0 : apd_vector_item( ptr_new_oct_grid_node );
916 : 0 : local_node_matrix[2][1][2] = ptr_new_oct_grid_node;
917 : 0 : new_node_matrix[2][1][2] = CUBIT_TRUE;
918 : : }
919 : :
920 : :
921 : : // To find 13
922 : 0 : ptr_node = local_node_matrix[2][0][0];
923 : 0 : total_dist = 0.0;
924 [ # # ]: 0 : while( total_dist < new_half_point ){
925 [ # # ]: 0 : total_dist += 1.0 / pow( 2.0, ptr_node->get_adj_node_distance( O_RIGHT ) );
926 [ # # ]: 0 : ptr_node = ptr_node->get_adj_node( O_RIGHT );
927 : : }
928 [ # # ]: 0 : if( total_dist == new_half_point ){
929 : 0 : local_node_matrix[2][1][0] = ptr_node;
930 : : }
931 : : else{
932 [ # # ][ # # ]: 0 : ptr_new_oct_grid_node = new CubitOctreeNode( (local_node_matrix[2][0][0])->x(), (local_node_matrix[2][0][0])->y() + norm_dim / 2.0, (local_node_matrix[2][0][0])->z() );
[ # # ][ # # ]
[ # # ]
933 [ # # ]: 0 : apd_vector_item( ptr_new_oct_grid_node );
934 : 0 : local_node_matrix[2][1][0] = ptr_new_oct_grid_node;
935 : 0 : new_node_matrix[2][1][0] = CUBIT_TRUE;
936 : : }
937 : :
938 : : // To find 14
939 : 0 : ptr_node = local_node_matrix[0][0][0];
940 : 0 : total_dist = 0.0;
941 [ # # ]: 0 : while( total_dist < new_half_point ){
942 [ # # ]: 0 : total_dist += 1.0 / pow( 2.0, ptr_node->get_adj_node_distance( O_RIGHT ) );
943 [ # # ]: 0 : ptr_node = ptr_node->get_adj_node( O_RIGHT );
944 : : }
945 [ # # ]: 0 : if( total_dist == new_half_point ){
946 : 0 : local_node_matrix[0][1][0] = ptr_node;
947 : : }
948 : : else{
949 [ # # ][ # # ]: 0 : ptr_new_oct_grid_node = new CubitOctreeNode( (local_node_matrix[0][0][0])->x(), (local_node_matrix[0][0][0])->y() + norm_dim / 2.0, (local_node_matrix[0][0][0])->z() );
[ # # ][ # # ]
[ # # ]
950 [ # # ]: 0 : apd_vector_item( ptr_new_oct_grid_node );
951 : 0 : local_node_matrix[0][1][0] = ptr_new_oct_grid_node;
952 : 0 : new_node_matrix[0][1][0] = CUBIT_TRUE;
953 : : }
954 : :
955 : :
956 : : // To find 15
957 : 0 : ptr_node = local_node_matrix[0][0][2];
958 : 0 : total_dist = 0.0;
959 [ # # ]: 0 : while( total_dist < new_half_point ){
960 [ # # ]: 0 : total_dist += 1.0 / pow( 2.0, ptr_node->get_adj_node_distance( O_RIGHT ) );
961 [ # # ]: 0 : ptr_node = ptr_node->get_adj_node( O_RIGHT );
962 : : }
963 [ # # ]: 0 : if( total_dist == new_half_point ){
964 : 0 : local_node_matrix[0][1][2] = ptr_node;
965 : : }
966 : : else{
967 [ # # ][ # # ]: 0 : ptr_new_oct_grid_node = new CubitOctreeNode( (local_node_matrix[0][0][2])->x(), (local_node_matrix[0][0][2])->y() + norm_dim / 2.0, (local_node_matrix[0][0][2])->z() );
[ # # ][ # # ]
[ # # ]
968 [ # # ]: 0 : apd_vector_item( ptr_new_oct_grid_node );
969 : 0 : local_node_matrix[0][1][2] = ptr_new_oct_grid_node;
970 : 0 : new_node_matrix[0][1][2] = CUBIT_TRUE;
971 : : }
972 : :
973 : :
974 : : // To find 16
975 : 0 : ptr_node = local_node_matrix[2][0][2];
976 : 0 : total_dist = 0.0;
977 [ # # ]: 0 : while( total_dist < new_half_point ){
978 [ # # ]: 0 : total_dist += 1.0 / pow( 2.0, ptr_node->get_adj_node_distance( O_BACK ) );
979 [ # # ]: 0 : ptr_node = ptr_node->get_adj_node( O_BACK );
980 : : }
981 : :
982 [ # # ]: 0 : if( total_dist == new_half_point ){
983 : 0 : local_node_matrix[1][0][2] = ptr_node;
984 : : }
985 : : else{
986 [ # # ][ # # ]: 0 : ptr_new_oct_grid_node = new CubitOctreeNode( (local_node_matrix[2][0][2])->x() - norm_dim / 2.0, (local_node_matrix[2][0][2])->y(), (local_node_matrix[2][0][2])->z());
[ # # ][ # # ]
[ # # ]
987 [ # # ]: 0 : apd_vector_item( ptr_new_oct_grid_node );
988 : 0 : local_node_matrix[1][0][2] = ptr_new_oct_grid_node;
989 : 0 : new_node_matrix[1][0][2] = CUBIT_TRUE;
990 : : }
991 : :
992 : :
993 : : // To find 17
994 : 0 : ptr_node = local_node_matrix[2][0][0];
995 : 0 : total_dist = 0.0;
996 [ # # ]: 0 : while( total_dist < new_half_point ){
997 [ # # ]: 0 : total_dist += 1.0 / pow( 2.0, ptr_node->get_adj_node_distance( O_BACK ) );
998 [ # # ]: 0 : ptr_node = ptr_node->get_adj_node( O_BACK );
999 : : }
1000 [ # # ]: 0 : if( total_dist == new_half_point ){
1001 : 0 : local_node_matrix[1][0][0] = ptr_node;
1002 : : }
1003 : : else{
1004 [ # # ][ # # ]: 0 : ptr_new_oct_grid_node = new CubitOctreeNode( (local_node_matrix[2][0][0])->x() - norm_dim / 2.0, (local_node_matrix[2][0][0])->y(), (local_node_matrix[2][0][0])->z());
[ # # ][ # # ]
[ # # ]
1005 [ # # ]: 0 : apd_vector_item( ptr_new_oct_grid_node );
1006 : 0 : local_node_matrix[1][0][0] = ptr_new_oct_grid_node;
1007 : 0 : new_node_matrix[1][0][0] = CUBIT_TRUE;
1008 : : }
1009 : :
1010 : :
1011 : : // To find 18
1012 : 0 : ptr_node = local_node_matrix[2][2][0];
1013 : 0 : total_dist = 0.0;
1014 [ # # ]: 0 : while( total_dist < new_half_point ){
1015 [ # # ]: 0 : total_dist += 1.0 / pow( 2.0, ptr_node->get_adj_node_distance( O_BACK ) );
1016 [ # # ]: 0 : ptr_node = ptr_node->get_adj_node( O_BACK );
1017 : : }
1018 [ # # ]: 0 : if( total_dist == new_half_point ){
1019 : 0 : local_node_matrix[1][2][0] = ptr_node;
1020 : : }
1021 : : else{
1022 [ # # ][ # # ]: 0 : ptr_new_oct_grid_node = new CubitOctreeNode( (local_node_matrix[2][2][0])->x() - norm_dim / 2.0, (local_node_matrix[2][2][0])->y(), (local_node_matrix[2][2][0])->z());
[ # # ][ # # ]
[ # # ]
1023 [ # # ]: 0 : apd_vector_item( ptr_new_oct_grid_node );
1024 : 0 : local_node_matrix[1][2][0] = ptr_new_oct_grid_node;
1025 : 0 : new_node_matrix[1][2][0] = CUBIT_TRUE;
1026 : : }
1027 : :
1028 : :
1029 : : // To find 19
1030 : 0 : ptr_node = local_node_matrix[2][2][2];
1031 : 0 : total_dist = 0.0;
1032 [ # # ]: 0 : while( total_dist < new_half_point ){
1033 [ # # ]: 0 : total_dist += 1.0 / pow( 2.0, ptr_node->get_adj_node_distance( O_BACK ) );
1034 [ # # ]: 0 : ptr_node = ptr_node->get_adj_node( O_BACK );
1035 : : }
1036 [ # # ]: 0 : if( total_dist == new_half_point ){
1037 : 0 : local_node_matrix[1][2][2] = ptr_node;
1038 : : }
1039 : : else{
1040 [ # # ][ # # ]: 0 : ptr_new_oct_grid_node = new CubitOctreeNode( (local_node_matrix[2][2][2])->x() - norm_dim / 2.0, (local_node_matrix[2][2][2])->y(), (local_node_matrix[2][2][2])->z());
[ # # ][ # # ]
[ # # ]
1041 [ # # ]: 0 : apd_vector_item( ptr_new_oct_grid_node );
1042 : 0 : local_node_matrix[1][2][2] = ptr_new_oct_grid_node;
1043 : 0 : new_node_matrix[1][2][2] = CUBIT_TRUE;
1044 : : }
1045 : :
1046 : : // PRINT_INFO(" found nodes on edges of local 3 x 3 matrix \n");
1047 : : // To find 20
1048 : 0 : ptr_node = local_node_matrix[2][0][1];
1049 [ # # ][ # # ]: 0 : if( new_node_matrix[2][0][1] == CUBIT_FALSE && ptr_node->get_adj_node( O_RIGHT ) != NULL ){
[ # # ][ # # ]
1050 : :
1051 : 0 : total_dist = 0.0;
1052 [ # # ]: 0 : while( total_dist < new_half_point ){
1053 [ # # ]: 0 : total_dist += 1.0 / pow( 2.0, ptr_node->get_adj_node_distance( O_RIGHT ) );
1054 [ # # ]: 0 : ptr_node = ptr_node->get_adj_node( O_RIGHT );
1055 : : }
1056 [ # # ]: 0 : if( total_dist == new_half_point ){
1057 : 0 : local_node_matrix[2][1][1] = ptr_node;
1058 : : // PRINT_INFO(" old node 20 found \n");
1059 : : }
1060 : : else{
1061 [ # # ][ # # ]: 0 : PRINT_INFO("WARNING: Node not found \n");
[ # # ][ # # ]
1062 : : }
1063 : :
1064 : : }
1065 : : else{
1066 [ # # ][ # # ]: 0 : ptr_new_oct_grid_node = new CubitOctreeNode( (local_node_matrix[2][0][1])->x(), (local_node_matrix[2][0][1])->y() + norm_dim / 2.0, (local_node_matrix[2][0][1])->z());
[ # # ][ # # ]
[ # # ]
1067 [ # # ]: 0 : apd_vector_item( ptr_new_oct_grid_node );
1068 : 0 : local_node_matrix[2][1][1] = ptr_new_oct_grid_node;
1069 : 0 : new_node_matrix[2][1][1] = CUBIT_TRUE;
1070 : : // PRINT_INFO(" new node 20 created \n");
1071 : : }
1072 : :
1073 : :
1074 : :
1075 : : // To find 21
1076 : 0 : ptr_node = local_node_matrix[0][0][1];
1077 [ # # ][ # # ]: 0 : if( new_node_matrix[0][0][1] == CUBIT_FALSE && ptr_node->get_adj_node( O_RIGHT ) != NULL ){
[ # # ][ # # ]
1078 : :
1079 : 0 : total_dist = 0.0;
1080 [ # # ]: 0 : while( total_dist < new_half_point ){
1081 [ # # ]: 0 : total_dist += 1.0 / pow( 2.0, ptr_node->get_adj_node_distance( O_RIGHT ) );
1082 [ # # ]: 0 : ptr_node = ptr_node->get_adj_node( O_RIGHT );
1083 : : }
1084 [ # # ]: 0 : if( total_dist == new_half_point ){
1085 : 0 : local_node_matrix[0][1][1] = ptr_node;
1086 : : // PRINT_INFO(" old node 21 found \n");
1087 : : }
1088 : : else{
1089 [ # # ][ # # ]: 0 : PRINT_INFO("WARNING: Node not found \n");
[ # # ][ # # ]
1090 : : }
1091 : : }
1092 : : else{
1093 [ # # ][ # # ]: 0 : ptr_new_oct_grid_node = new CubitOctreeNode( (local_node_matrix[0][0][1])->x(), (local_node_matrix[0][0][1])->y() + norm_dim / 2.0, (local_node_matrix[0][0][1])->z());
[ # # ][ # # ]
[ # # ]
1094 [ # # ]: 0 : apd_vector_item( ptr_new_oct_grid_node );
1095 : 0 : local_node_matrix[0][1][1] = ptr_new_oct_grid_node;
1096 : 0 : new_node_matrix[0][1][1] = CUBIT_TRUE;
1097 : : // PRINT_INFO(" new node 21 created \n");
1098 : : }
1099 : :
1100 : : // To find 22
1101 : 0 : ptr_node = local_node_matrix[2][0][1];
1102 [ # # ][ # # ]: 0 : if( new_node_matrix[2][0][1] == CUBIT_FALSE && ptr_node->get_adj_node( O_BACK ) != NULL ){
[ # # ][ # # ]
1103 : :
1104 : 0 : total_dist = 0.0;
1105 [ # # ]: 0 : while( total_dist < new_half_point ){
1106 [ # # ]: 0 : total_dist += 1.0 / pow( 2.0, ptr_node->get_adj_node_distance( O_BACK ) );
1107 [ # # ]: 0 : ptr_node = ptr_node->get_adj_node( O_BACK );
1108 : : }
1109 [ # # ]: 0 : if( total_dist == new_half_point ){
1110 : 0 : local_node_matrix[1][0][1] = ptr_node;
1111 : : // PRINT_INFO(" old node 22 found \n");
1112 : : }
1113 : : else{
1114 [ # # ][ # # ]: 0 : PRINT_INFO("WARNING: Node not found \n");
[ # # ][ # # ]
1115 : : }
1116 : : }
1117 : : else{
1118 [ # # ][ # # ]: 0 : ptr_new_oct_grid_node = new CubitOctreeNode( (local_node_matrix[2][0][1])->x() - norm_dim / 2.0, (local_node_matrix[2][0][1])->y(), (local_node_matrix[2][0][1])->z());
[ # # ][ # # ]
[ # # ]
1119 [ # # ]: 0 : apd_vector_item( ptr_new_oct_grid_node );
1120 : 0 : local_node_matrix[1][0][1] = ptr_new_oct_grid_node;
1121 : 0 : new_node_matrix[1][0][1] = CUBIT_TRUE;
1122 : : // PRINT_INFO(" new node 22 created \n");
1123 : : }
1124 : :
1125 : : // To find 23
1126 : 0 : ptr_node = local_node_matrix[2][2][1];
1127 [ # # ][ # # ]: 0 : if( new_node_matrix[2][2][1] == CUBIT_FALSE && ptr_node->get_adj_node( O_BACK ) != NULL ){
[ # # ][ # # ]
1128 : :
1129 : 0 : total_dist = 0.0;
1130 [ # # ]: 0 : while( total_dist < new_half_point ){
1131 [ # # ]: 0 : total_dist += 1.0 / pow( 2.0, ptr_node->get_adj_node_distance( O_BACK ) );
1132 [ # # ]: 0 : ptr_node = ptr_node->get_adj_node( O_BACK );
1133 : : }
1134 [ # # ]: 0 : if( total_dist == new_half_point ){
1135 : 0 : local_node_matrix[1][2][1] = ptr_node;
1136 : : // PRINT_INFO(" old node 23 found \n");
1137 : : }
1138 : : else{
1139 [ # # ][ # # ]: 0 : PRINT_INFO("WARNING: Node not found \n");
[ # # ][ # # ]
1140 : : }
1141 : : }
1142 : : else{
1143 [ # # ][ # # ]: 0 : ptr_new_oct_grid_node = new CubitOctreeNode( (local_node_matrix[2][2][1])->x() - norm_dim / 2.0, (local_node_matrix[2][2][1])->y(), (local_node_matrix[2][2][1])->z());
[ # # ][ # # ]
[ # # ]
1144 [ # # ]: 0 : apd_vector_item( ptr_new_oct_grid_node );
1145 : 0 : local_node_matrix[1][2][1] = ptr_new_oct_grid_node;
1146 : 0 : new_node_matrix[1][2][1] = CUBIT_TRUE;
1147 : : // PRINT_INFO(" new node 23 created \n");
1148 : : }
1149 : :
1150 : : // To find 24
1151 : 0 : ptr_node = local_node_matrix[1][0][0];
1152 [ # # ][ # # ]: 0 : if( new_node_matrix[1][0][0] == CUBIT_FALSE && ptr_node->get_adj_node( O_RIGHT ) != NULL ){
[ # # ][ # # ]
1153 : :
1154 : 0 : total_dist = 0.0;
1155 [ # # ]: 0 : while( total_dist < new_half_point ){
1156 [ # # ]: 0 : total_dist += 1.0 / pow( 2.0, ptr_node->get_adj_node_distance( O_RIGHT ) );
1157 [ # # ]: 0 : ptr_node = ptr_node->get_adj_node( O_RIGHT );
1158 : : }
1159 [ # # ]: 0 : if( total_dist == new_half_point ){
1160 : 0 : local_node_matrix[1][1][0] = ptr_node;
1161 : : // PRINT_INFO(" old node 24 found \n");
1162 : : }
1163 : : else{
1164 [ # # ][ # # ]: 0 : PRINT_INFO("WARNING: Node not found \n");
[ # # ][ # # ]
1165 : : }
1166 : : }
1167 : : else{
1168 [ # # ][ # # ]: 0 : ptr_new_oct_grid_node = new CubitOctreeNode( (local_node_matrix[1][0][0])->x(), (local_node_matrix[1][0][0])->y() + norm_dim / 2.0, (local_node_matrix[1][0][0])->z());
[ # # ][ # # ]
[ # # ]
1169 [ # # ]: 0 : apd_vector_item( ptr_new_oct_grid_node );
1170 : 0 : local_node_matrix[1][1][0] = ptr_new_oct_grid_node;
1171 : 0 : new_node_matrix[1][1][0] = CUBIT_TRUE;
1172 : : // PRINT_INFO(" new node 24 created \n");
1173 : : }
1174 : :
1175 : :
1176 : :
1177 : : // To find 25
1178 : 0 : ptr_node = local_node_matrix[1][0][2];
1179 [ # # ][ # # ]: 0 : if( new_node_matrix[1][0][2] == CUBIT_FALSE && ptr_node->get_adj_node( O_RIGHT ) != NULL ){
[ # # ][ # # ]
1180 : :
1181 : 0 : total_dist = 0.0;
1182 [ # # ]: 0 : while( total_dist < new_half_point ){
1183 [ # # ]: 0 : total_dist += 1.0 / pow( 2.0, ptr_node->get_adj_node_distance( O_RIGHT ) );
1184 [ # # ]: 0 : ptr_node = ptr_node->get_adj_node( O_RIGHT );
1185 : : }
1186 [ # # ]: 0 : if( total_dist == new_half_point ){
1187 : 0 : local_node_matrix[1][1][2] = ptr_node;
1188 : : // PRINT_INFO(" old node 25 found \n");
1189 : : }
1190 : : else{
1191 [ # # ][ # # ]: 0 : PRINT_INFO("WARNING: Node not found \n");
[ # # ][ # # ]
1192 : : }
1193 : : }
1194 : : else{
1195 [ # # ][ # # ]: 0 : ptr_new_oct_grid_node = new CubitOctreeNode( (local_node_matrix[1][0][2])->x(), (local_node_matrix[1][0][2])->y() + norm_dim / 2.0, (local_node_matrix[1][0][2])->z());
[ # # ][ # # ]
[ # # ]
1196 [ # # ]: 0 : apd_vector_item( ptr_new_oct_grid_node );
1197 : 0 : local_node_matrix[1][1][2] = ptr_new_oct_grid_node;
1198 : 0 : new_node_matrix[1][1][2] = CUBIT_TRUE;
1199 : : // PRINT_INFO(" new node 25 created \n");
1200 : : }
1201 : :
1202 : : // PRINT_INFO(" found nodes on faces of local 3 x 3 matrix \n");
1203 : :
1204 : : // To find 26
1205 [ # # ][ # # ]: 0 : ptr_new_oct_grid_node = new CubitOctreeNode( (local_node_matrix[1][1][2])->x(), (local_node_matrix[1][1][2])->y(), (local_node_matrix[1][1][2])->z() - norm_dim / 2.0);
[ # # ][ # # ]
[ # # ]
1206 [ # # ]: 0 : apd_vector_item( ptr_new_oct_grid_node );
1207 : 0 : local_node_matrix[1][1][1] = ptr_new_oct_grid_node;
1208 : 0 : new_node_matrix[1][1][1] = CUBIT_TRUE;
1209 : :
1210 : : // PRINT_INFO(" found nodes at center of local 3 x 3 matrix \n");
1211 : :
1212 : : // update the eight nodes of new eight cells
1213 : :
1214 [ # # ]: 0 : for( i = 0; i < 2; i++ ){
1215 [ # # ]: 0 : for( j = 0; j < 2; j++ ){
1216 [ # # ]: 0 : for( k = 0; k < 2; k++ ){
1217 : :
1218 [ # # ]: 0 : ptr_new_cell = ptr_cell->get_child( i, j, k );
1219 : :
1220 [ # # ]: 0 : for( l = 0; l < 2; l++ ){
1221 [ # # ]: 0 : for( m = 0; m < 2; m++ ){
1222 [ # # ]: 0 : for( n = 0; n < 2; n++ ){
1223 [ # # ]: 0 : ptr_new_cell->set_oct_grid_node( l, m, n, local_node_matrix[i+l][j+m][k+n] );
1224 : :
1225 : 0 : p = ( l == 1 )?0:1; // fliped 0 -> 1; 1 -> 0
1226 : 0 : q = ( m == 1 )?0:1;
1227 : 0 : r = ( n == 1 )?0:1;
1228 : : // update the eight cells of all 27 nodes
1229 [ # # ]: 0 : local_node_matrix[i+l][j+m][k+n]->update_adj_cell( ptr_new_cell, p, q, r );
1230 : : }
1231 : : }
1232 : : }
1233 : : }
1234 : : }
1235 : : }
1236 : :
1237 : : // PRINT_INFO(" updates nodes of the 8 children and visa versa \n");
1238 : :
1239 : : // connnect the new nodes with the old nodes to update the wire frame
1240 : :
1241 [ # # ]: 0 : for( i = 0; i < 3; i++ ){
1242 [ # # ]: 0 : for( j = 0; j < 3; j++ ){
1243 [ # # ]: 0 : for( k = 0; k < 3; k++ ){
1244 [ # # ]: 0 : if( new_node_matrix[i][j][k] == CUBIT_TRUE ){
1245 [ # # ]: 0 : if( i - 1 >= 0 ){
1246 [ # # ]: 0 : local_node_matrix[i][j][k]->set_adj_node( O_BACK, local_node_matrix[i-1][j][k] );
1247 [ # # ]: 0 : local_node_matrix[i][j][k]->set_adj_node_distance( O_BACK, new_depth );
1248 [ # # ]: 0 : local_node_matrix[i-1][j][k]->set_adj_node( O_FRONT, local_node_matrix[i][j][k] );
1249 [ # # ]: 0 : local_node_matrix[i-1][j][k]->set_adj_node_distance( O_FRONT, new_depth );
1250 : : }
1251 [ # # ]: 0 : if( i + 1 <= 2 ){
1252 [ # # ]: 0 : local_node_matrix[i][j][k]->set_adj_node( O_FRONT, local_node_matrix[i+1][j][k] );
1253 [ # # ]: 0 : local_node_matrix[i][j][k]->set_adj_node_distance( O_FRONT, new_depth );
1254 [ # # ]: 0 : local_node_matrix[i+1][j][k]->set_adj_node( O_BACK, local_node_matrix[i][j][k] );
1255 [ # # ]: 0 : local_node_matrix[i+1][j][k]->set_adj_node_distance( O_BACK, new_depth );
1256 : : }
1257 : :
1258 [ # # ]: 0 : if( j - 1 >= 0 ){
1259 [ # # ]: 0 : local_node_matrix[i][j][k]->set_adj_node( O_LEFT, local_node_matrix[i][j-1][k] );
1260 [ # # ]: 0 : local_node_matrix[i][j][k]->set_adj_node_distance( O_LEFT, new_depth );
1261 [ # # ]: 0 : local_node_matrix[i][j-1][k]->set_adj_node( O_RIGHT, local_node_matrix[i][j][k] );
1262 [ # # ]: 0 : local_node_matrix[i][j-1][k]->set_adj_node_distance( O_RIGHT, new_depth );
1263 : : }
1264 [ # # ]: 0 : if( j + 1 <= 2 ){
1265 [ # # ]: 0 : local_node_matrix[i][j][k]->set_adj_node( O_RIGHT, local_node_matrix[i][j+1][k] );
1266 [ # # ]: 0 : local_node_matrix[i][j][k]->set_adj_node_distance( O_RIGHT, new_depth );
1267 [ # # ]: 0 : local_node_matrix[i][j+1][k]->set_adj_node( O_LEFT, local_node_matrix[i][j][k] );
1268 [ # # ]: 0 : local_node_matrix[i][j+1][k]->set_adj_node_distance( O_LEFT, new_depth );
1269 : : }
1270 : :
1271 [ # # ]: 0 : if( k - 1 >= 0 ){
1272 [ # # ]: 0 : local_node_matrix[i][j][k]->set_adj_node( O_BOTTOM, local_node_matrix[i][j][k-1] );
1273 [ # # ]: 0 : local_node_matrix[i][j][k]->set_adj_node_distance( O_BOTTOM, new_depth );
1274 [ # # ]: 0 : local_node_matrix[i][j][k-1]->set_adj_node( O_TOP, local_node_matrix[i][j][k] );
1275 [ # # ]: 0 : local_node_matrix[i][j][k-1]->set_adj_node_distance( O_TOP, new_depth );
1276 : : }
1277 [ # # ]: 0 : if( k + 1 <= 2 ){
1278 [ # # ]: 0 : local_node_matrix[i][j][k]->set_adj_node( O_TOP, local_node_matrix[i][j][k+1] );
1279 [ # # ]: 0 : local_node_matrix[i][j][k]->set_adj_node_distance( O_TOP, new_depth );
1280 [ # # ]: 0 : local_node_matrix[i][j][k+1]->set_adj_node( O_BOTTOM, local_node_matrix[i][j][k] );
1281 [ # # ]: 0 : local_node_matrix[i][j][k+1]->set_adj_node_distance( O_BOTTOM, new_depth );
1282 : : }
1283 : :
1284 : : }
1285 : : }
1286 : : }
1287 : : }
1288 : :
1289 : : // distribute the facet_points and Ref_face among the children
1290 [ # # ]: 0 : ptr_cell->distribute_facet_points_among_children();
1291 : :
1292 : :
1293 : : int depth_difference;
1294 : : // update the depthMaxDepthCell, depthMinDepthCell, cellDepthDifference, and minDepthCell
1295 [ # # ]: 0 : if( ptr_queue != NULL ){
1296 [ # # ]: 0 : for( i = 0; i < 3; i++ ){
1297 [ # # ]: 0 : for( j = 0; j < 3; j++ ){
1298 [ # # ]: 0 : for( k = 0; k < 3; k++ ){
1299 [ # # ]: 0 : depth_difference = local_node_matrix[i][j][k]->find_min_depth_cell_and_depth_difference( );
1300 : : /* RISKY TO OPTIMIZE ANY THING HERE
1301 : : NEEDS CAREFULL STUDY
1302 : : if( new_node_matrix[i][j][k] == CUBIT_TRUE ){
1303 : : // initialize the variables depthMaxDepthCell, depthMinDepthCell, cellDepthDifference, and minDepthCell
1304 : : local_node_matrix[i][j][k]->find_min_depth_cell_and_depth_difference( );
1305 : : }
1306 : : else{
1307 : : // update the variables depthMaxDepthCell, depthMinDepthCell, cellDepthDifference, and minDepthCell
1308 : : max_depth = local_node_matrix[i][j][k]->get_depth_max_depth_cell();
1309 : : min_depth = local_node_matrix[i][j][k]->get_depth_min_depth_cell();
1310 : : if( new_depth < min_depth || new_depth > max_depth )
1311 : :
1312 : : }
1313 : : */
1314 [ # # ][ # # ]: 0 : if( local_node_matrix[i][j][k]->get_mark() == CUBIT_FALSE && depth_difference >= 2 ){
[ # # ][ # # ]
1315 [ # # ]: 0 : ptr_queue->push( local_node_matrix[i][j][k] );
1316 [ # # ]: 0 : local_node_matrix[i][j][k]->set_mark( CUBIT_TRUE );
1317 : : }
1318 : : }
1319 : : }
1320 : : }
1321 : : }
1322 : : // ptr_cell->delete_local_node_matrix();
1323 : 0 : return CUBIT_TRUE;
1324 : : }
1325 : : else{
1326 : 0 : return CUBIT_FALSE;
1327 : : }
1328 : : }
1329 : :
1330 : :
1331 : 0 : void CubitOctree::color_octreecell( void ){
1332 : :
1333 : 0 : root->coloring(/*greyCellList,*/ blackCellList);
1334 : :
1335 : : /* TESTING: Duplicates in grey cell list
1336 : : CubitOctreeCell *ptr_cell;
1337 : : int i;
1338 : : for( i = 0; i < greyCellList.size(); i++ ){
1339 : : ptr_cell = greyCellList.get_and_step();
1340 : : PRINT_INFO("Grey cell ID: %d \n", ptr_cell->id() );
1341 : : }
1342 : : */
1343 : 0 : }
1344 : :
1345 : : // p0 and p1 should be within the root's bbox
1346 : : // note: this is a little sloppy, i'll clean it up when I fix the general neighbor traversal
1347 : 0 : void CubitOctree::find_cell_list_intersecting_line_segment (const CubitVector &p0, const CubitVector &p1, DLIList<CubitOctreeCell*> &cell_list){
1348 : :
1349 : : // plane order is like in enum OctreePosition
1350 : :
1351 [ # # ][ # # ]: 0 : CubitOctreeCell *start = find_octreecell(p0), *end = find_octreecell(p1);
1352 : 0 : CubitOctreeCell *current = start, *previous = NULL;
1353 [ # # ]: 0 : CubitVector curr_pt = p0;
1354 [ # # ][ # # ]: 0 : CubitVector dir = p1-p0, center;
1355 : : //CubitVector ii(1,0,0);
1356 : : //CubitVector jj(0,1,0);
1357 : : //CubitVector kk(0,0,1);
1358 : :
1359 : : int i;
1360 [ # # ]: 0 : dir.normalize();
1361 [ # # ][ # # ]: 0 : double tx=0, ty=0, tz=0, h=0, a = dir.x(), b = dir.y(), c = dir.z();
[ # # ]
1362 : :
1363 : : static unsigned int face_corners[6][4] =
1364 : : {
1365 : : {0,5,6,2},
1366 : : {4,3,1,7},
1367 : : {5,3,7,2},
1368 : : {0,4,1,6},
1369 : : {1,7,2,6},
1370 : : {4,3,5,0}
1371 : : };
1372 : :
1373 : : static unsigned int inwward_cells[6][4][3] =
1374 : : {
1375 : : {{0,0,0},{0,0,1},{1,0,0},{1,0,1}},
1376 : : {{0,1,0},{0,1,1},{1,1,0},{1,1,1}},
1377 : : {{0,1,0},{0,0,0},{1,0,0},{1,1,0}},
1378 : : {{0,1,1},{0,0,1},{1,0,1},{1,1,1}},
1379 : : {{0,0,0},{0,0,1},{0,1,1},{0,1,0}},
1380 : : {{1,0,0},{1,0,1},{1,1,1},{1,1,0}}
1381 : : };
1382 : :
1383 [ # # ]: 0 : while (current != end)
1384 : : {
1385 [ # # ]: 0 : if (current != previous)
1386 : : {
1387 [ # # ]: 0 : cell_list.append(current);
1388 : 0 : previous = current;
1389 : : }
1390 : : // do tn, pick face, march stuff here
1391 [ # # ]: 0 : h = current->get_dimension();
1392 [ # # ][ # # ]: 0 : center = current->get_center();
1393 [ # # ][ # # ]: 0 : if (fabs(a) > CUBIT_DBL_MIN) {tx = h/(2*fabs(a)) - (curr_pt.x() - center.x())/a;}
[ # # ]
1394 : 0 : else {tx = CUBIT_DBL_MAX;}
1395 [ # # ][ # # ]: 0 : if (fabs(b) > CUBIT_DBL_MIN) {ty = h/(2*fabs(b)) - (curr_pt.y() - center.y())/b;}
[ # # ]
1396 : 0 : else {ty = CUBIT_DBL_MAX;}
1397 [ # # ][ # # ]: 0 : if (fabs(c) > CUBIT_DBL_MIN) {tz = h/(2*fabs(c)) - (curr_pt.z() - center.z())/c;}
[ # # ]
1398 : 0 : else {tz = CUBIT_DBL_MAX;}
1399 : :
1400 : 0 : tx = fabs(tx);
1401 : 0 : ty = fabs(ty);
1402 : 0 : tz = fabs(tz);
1403 : :
1404 : 0 : double t = 0.0;
1405 : :
1406 : 0 : OctreePosition int_plane = O_UNSET;
1407 : :
1408 [ # # ][ # # ]: 0 : if (tx <= ty && tx <= tz)
1409 : : {
1410 [ # # ][ # # ]: 0 : if (a > 0) {t = ((center.x() + h/2) - curr_pt.x())/a; int_plane = O_FRONT;}
[ # # ]
1411 [ # # ][ # # ]: 0 : else {t = ((center.x() - h/2) - curr_pt.x())/a; int_plane = O_BACK;}
1412 : : }
1413 : :
1414 [ # # ][ # # ]: 0 : else if (ty <= tx && ty <= tz)
1415 : : {
1416 [ # # ][ # # ]: 0 : if (b > 0) {t = ((center.y() + h/2) - curr_pt.y())/b; int_plane = O_RIGHT;}
[ # # ]
1417 [ # # ][ # # ]: 0 : else {t = ((center.y() - h/2) - curr_pt.y())/b; int_plane = O_LEFT;}
1418 : : }
1419 : :
1420 [ # # ][ # # ]: 0 : else if (tz <= ty && tz <= tx)
1421 : : {
1422 [ # # ][ # # ]: 0 : if (c > 0) {t = ((center.z() + h/2) - curr_pt.z())/c; int_plane = O_TOP;}
[ # # ]
1423 [ # # ][ # # ]: 0 : else {t = ((center.z() - h/2) - curr_pt.z())/c; int_plane = O_BOTTOM;}
1424 : : }
1425 : :
1426 : : // now we have determined the point of intersection on a face of the cell
1427 : : // based on the face, we should now check the grid nodes' adjacent cells and march if necessary to find the next cell to march in
1428 : :
1429 : : CubitOctreeNode* corners[] =
1430 : : {
1431 [ # # ]: 0 : current->get_octree_grid_node(1,0,1),
1432 [ # # ]: 0 : current->get_octree_grid_node(0,1,1),
1433 [ # # ]: 0 : current->get_octree_grid_node(0,0,0),
1434 [ # # ]: 0 : current->get_octree_grid_node(1,1,0),
1435 : :
1436 [ # # ]: 0 : current->get_octree_grid_node(1,1,1),
1437 [ # # ]: 0 : current->get_octree_grid_node(1,0,0),
1438 [ # # ]: 0 : current->get_octree_grid_node(0,0,1),
1439 [ # # ]: 0 : current->get_octree_grid_node(0,1,0),
1440 : 0 : };
1441 : : /*
1442 : : CubitOctreeNode *cADF = current->get_octree_grid_node(1,0,1); //0
1443 : : CubitOctreeNode *cBCF = current->get_octree_grid_node(0,1,1); //1
1444 : : CubitOctreeNode *cCDE = current->get_octree_grid_node(0,0,0); //2
1445 : : CubitOctreeNode *cABE = current->get_octree_grid_node(1,1,0); //3
1446 : :
1447 : : CubitOctreeNode *cABF = current->get_octree_grid_node(1,1,1); //4
1448 : : CubitOctreeNode *cADE = current->get_octree_grid_node(1,0,0); //5
1449 : : CubitOctreeNode *cCDF = current->get_octree_grid_node(0,0,1); //6
1450 : : CubitOctreeNode *cBCE = current->get_octree_grid_node(0,1,0); //7
1451 : : */
1452 : :
1453 : :
1454 : :
1455 : : // each digit is an i,j,k index for the inward cell from a grid node
1456 : :
1457 : 0 : CubitOctreeNode* int_face[4] = {corners[face_corners[int_plane][0]], corners[face_corners[int_plane][1]], corners[face_corners[int_plane][2]], corners[face_corners[int_plane][3]]};
1458 : 0 : unsigned int* cells[4] = {inwward_cells[int_plane][0], inwward_cells[int_plane][1], inwward_cells[int_plane][2], inwward_cells[int_plane][3]};
1459 : :
1460 : : CubitOctreeCell* four_cells[4];
1461 : : //CubitOctreeCell *curr_cell = int_face[0]->get_adj_cell(cells[0][0],cells[0][1],cells[0][2]);
1462 : 0 : bool one_face_neighbor = true;
1463 : : //bool same_depth = true;
1464 : 0 : CubitOctreeCell *compare_to = NULL;
1465 : :
1466 [ # # ]: 0 : for (i=0; i < 4; ++i)
1467 : : {
1468 [ # # ]: 0 : four_cells[i] = int_face[i]->get_adj_cell(cells[i][0],cells[i][1],cells[i][2]);
1469 [ # # ][ # # ]: 0 : if (compare_to == NULL && four_cells[i] != NULL) {compare_to = four_cells[i];}
1470 : : }
1471 : :
1472 [ # # ]: 0 : for (i=0; i < 4; ++i)
1473 : : {
1474 [ # # ]: 0 : if (four_cells[i] == NULL)
1475 : : {
1476 : 0 : one_face_neighbor = false;
1477 : : //same_depth = false;
1478 : 0 : break;
1479 : : }
1480 [ # # ]: 0 : if (four_cells[i] != NULL)
1481 : : {
1482 [ # # ]: 0 : if (four_cells[i] != compare_to) {one_face_neighbor = false;}
1483 : : //if (four_cells[i]->get_depth() != compare_to->get_depth()) {same_depth = false;}
1484 : : }
1485 : : }
1486 : :
1487 [ # # ][ # # ]: 0 : curr_pt += t*dir;
1488 [ # # ]: 0 : if (one_face_neighbor == true)
1489 : : {
1490 : 0 : current = compare_to;//four_cells[0];//curr_cell;.
1491 : : // PRINT_INFO("Found one face neighbor for CubitOctree ray traversal\n");
1492 : : }
1493 : :
1494 : : else
1495 : : {
1496 : : //curr_pt += (t+.0001)*dir;
1497 : 0 : int axes[6] = {1,1,2,2,0,0};
1498 : 0 : int dirs[6] = {-1,1,-1,1,-1,1};
1499 : : double xyz[3];
1500 [ # # ]: 0 : curr_pt.get_xyz(xyz);
1501 : :
1502 [ # # ]: 0 : xyz[axes[int_plane]] += dirs[int_plane] * (get_bbox_dimension()/(2*pow((double)2.0,maxDepth)));
1503 : :
1504 [ # # ]: 0 : CubitVector temp_pt;
1505 [ # # ]: 0 : temp_pt.set(xyz);
1506 : : // SVDrawTool::draw_point(temp_pt, CUBIT_WHITE_INDEX);
1507 : :
1508 [ # # ]: 0 : current = find_octreecell(temp_pt);
1509 : : /* if (current == previous) {
1510 : : PRINT_INFO("Samet method failed!\n");
1511 : : }*/
1512 : :
1513 : : //PRINT_INFO("Did not find one face neighbor for CubitOctree ray traversal, following Samet method\n");
1514 : : }
1515 : : //SVDrawTool::mouse_xforms();
1516 [ # # ]: 0 : if (current == end) {break;}
1517 : :
1518 : : }
1519 [ # # ]: 0 : cell_list.append(end);
1520 : :
1521 : 0 : }
1522 : :
1523 : :
1524 : :
1525 : 0 : CubitOctreeCell *CubitOctree::find_octreecell( const CubitVector &pnt ){
1526 : :
1527 : 0 : return( root->find_leaf_octree_cell( pnt ) );
1528 : :
1529 : : }
1530 : :
1531 : 0 : CubitBoolean CubitOctree::apd_vector_item( CubitOctreeNode *ptr_node ){
1532 : :
1533 : 0 : gridNodeVector.push( ptr_node);
1534 : 0 : return CUBIT_TRUE;
1535 : : }
1536 : :
1537 : :
1538 : 0 : void CubitOctree::find_max_min_size_grid_node_for_scaling( void ){
1539 : : CubitOctreeNode *ptr_grid_node;
1540 : : int i;
1541 : : double size;
1542 : :
1543 [ # # ]: 0 : for( i = 0; i < gridNodeVector.size(); i++ ){
1544 : :
1545 : 0 : ptr_grid_node = gridNodeVector.get_and_step();
1546 [ # # ]: 0 : if (ptr_grid_node)
1547 : : {
1548 : :
1549 : 0 : size = ptr_grid_node->get_size( OCTREE_SIZE_DEFAULT );
1550 : :
1551 [ # # ]: 0 : if( size > 0.0 ){
1552 : : // TESTING
1553 : : //PRINT_DEBUG_157("size = %f\n", size);
1554 : :
1555 [ # # ]: 0 : if( size < minSizeGridNode )
1556 : 0 : minSizeGridNode = size;
1557 : :
1558 [ # # ]: 0 : if( size > maxSizeGridNode )
1559 : 0 : maxSizeGridNode = size;
1560 : : }
1561 : : }
1562 : :
1563 : : }
1564 : :
1565 [ # # ][ # # ]: 0 : PRINT_DEBUG_167("Max Size Grid Node = %f\n", maxSizeGridNode );
[ # # ]
1566 [ # # ][ # # ]: 0 : PRINT_DEBUG_167("Min Size Grid Node = %f\n", minSizeGridNode );
[ # # ]
1567 : 0 : double average_size = (minSizeGridNode + maxSizeGridNode) / 2.0;
1568 : 0 : minSizeGridNode -= .05*average_size;
1569 : 0 : maxSizeGridNode += .05*average_size;
1570 [ # # ][ # # ]: 0 : PRINT_DEBUG_167("For drawing:\n");
[ # # ]
1571 [ # # ][ # # ]: 0 : PRINT_DEBUG_167("Adjusted Max Size Grid Node = %f\n", maxSizeGridNode );
[ # # ]
1572 [ # # ][ # # ]: 0 : PRINT_DEBUG_167("Adjusted Min Size Grid Node = %f\n", minSizeGridNode );
[ # # ]
1573 : :
1574 : : //system("pause");
1575 : :
1576 : 0 : }
1577 : :
1578 : :
1579 : :
1580 : 0 : double CubitOctree::size_at_a_point( const CubitVector &point, int size_type ){
1581 : : //PRINT_DEBUG_116("Entered the SizeAtPoint of SkeletonSizingFunction");
1582 : : static int mode = 1;
1583 : 0 : double size = 0.0;
1584 : :
1585 : : // SVDrawTool::draw_point(point, CUBIT_RED_INDEX);
1586 : :
1587 : :
1588 : 0 : CubitOctreeCell *ptr_cell = find_octreecell( point );
1589 : :
1590 [ # # ]: 0 : if( ptr_cell == NULL )
1591 : : {
1592 : :
1593 [ # # ][ # # ]: 0 : PRINT_INFO("WARNING: Point is outside the solid\n");
1594 : : //exit(1);
1595 [ # # ]: 0 : if( mode == 0 )
1596 : 0 : return size;
1597 : :
1598 : : /*
1599 : : mode = 0;
1600 : :
1601 : : // Search the adjacent cells and find the nearest sizing data
1602 : : CubitVector xyz[6];
1603 : : CubitVector mod_point;
1604 : : int i;
1605 : :
1606 : : for( i = 0; i < 5; i ++ ){
1607 : : xyz[i].x(0.0);
1608 : : xyz[i].y(0.0);
1609 : : xyz[i].z(0.0);
1610 : : }
1611 : :
1612 : : xyz[0].x( grid_size );
1613 : : xyz[1].x( -1 * grid_size );
1614 : : xyz[2].y( grid_size );
1615 : : xyz[3].y( -1 * grid_size );
1616 : : xyz[4].z( grid_size );
1617 : : xyz[5].z( -1 * grid_size );
1618 : :
1619 : : double total_size = 0;
1620 : : int count = 0;
1621 : : double size1;
1622 : :
1623 : : for( i = 0; i < 5; i ++ ){
1624 : : mod_point = point + xyz[i];
1625 : : size1 = size_at_point( mod_point, 0.0 );
1626 : :
1627 : : if( size1 != 0 ){
1628 : : total_size += size1;
1629 : : count++;
1630 : : }
1631 : : }
1632 : :
1633 : : size = total_size / count;
1634 : : if( size == 0.0 ){
1635 : : PRINT_INFO("WARNING: Point is outside the solid can't handle ( size set to average size )\n");
1636 : : size = 0.5;
1637 : : size = 2 * ( min_rad + ( size - 1 ) / (10 - 1) * ( max_rad - min_rad ) ) * grid_size * over_all_reduction_scale;
1638 : : }
1639 : :
1640 : : mode = 1;
1641 : : */
1642 : : }
1643 : : else
1644 : : {
1645 : :
1646 : : switch( DEFAULT_INTERPOLATION_INSIDE_CELL )
1647 : : {
1648 : : case TRILINEAR_INTERPOLATION_INSIDE_CELL:
1649 : : size = ptr_cell->trilinear_interpolation( point );
1650 : : break;
1651 : :
1652 : : case INVERSE_DISTANCE_INTERPOLATION_INSIDE_CELL:
1653 : : size = ptr_cell->inverse_distance_interpolation( point );
1654 : : break;
1655 : :
1656 : : case MIN_DISTANCE_INTERPOLATION_INSIDE_CELL:
1657 : : size = ptr_cell->min_distance_interpolation( point );
1658 : : break;
1659 : :
1660 : : case MIN_SIZE_INTERPOLATION_INSIDE_CELL:
1661 : : size = ptr_cell->min_size_interpolation( point );
1662 : : break;
1663 : :
1664 : : default:
1665 : : #ifndef NDEBUG
1666 : : //PRINT_INFO(" WARNING: Interpolation method inside a cell is not set in SkeletonConstants.hpp\n");
1667 : : #endif
1668 : 0 : size = ptr_cell->trilinear_interpolation( point );
1669 : 0 : break;
1670 : : }
1671 : :
1672 [ # # ]: 0 : if( size_type == SCALED_SIZE )
1673 : : {
1674 : 0 : size = get_scaled_from_wrld_size_grid_node( size );
1675 : :
1676 : : }
1677 : :
1678 : :
1679 : : // if( size_type == MESH_SIZE ){
1680 : : // Do nothing send size for meshing
1681 : : //}
1682 : :
1683 : : }
1684 : : // PRINT_INFO("Size at point <%f,%f,%f> = %f\n", point.x(), point.y(), point.z(), size);
1685 : 0 : return size;
1686 : : }
1687 : :
1688 : :
1689 : 0 : CubitPointContainment CubitOctree::point_containment( CubitVector point, double tolerance )
1690 : : {
1691 : :
1692 : 0 : CubitOctreeCell *ptr_cell = find_octreecell( point );
1693 : :
1694 [ # # ]: 0 : if( ptr_cell == NULL )
1695 : : {
1696 : : // not known and needs full acis/mbg point containment
1697 : 0 : return CUBIT_PNT_BOUNDARY;
1698 : : }
1699 : : else
1700 : : {
1701 [ # # # # ]: 0 : switch( ptr_cell->get_color() )
1702 : : {
1703 : : case CUBIT_BLACK_INDEX:
1704 : 0 : return CUBIT_PNT_INSIDE;
1705 : :
1706 : : case CUBIT_WHITE_INDEX:
1707 : 0 : return CUBIT_PNT_OUTSIDE;
1708 : :
1709 : : case CUBIT_GREY_INDEX:
1710 : 0 : return CUBIT_PNT_BOUNDARY;
1711 : :
1712 : : default:
1713 : 0 : return CUBIT_PNT_BOUNDARY;
1714 : : }
1715 : : }
1716 : : return CUBIT_PNT_BOUNDARY;
1717 : : }
1718 : :
1719 : :
1720 : :
1721 : 0 : double CubitOctree::get_scaled_from_wrld_size_grid_node( double wrld_size ){
1722 : :
1723 : : double scaled_size;
1724 : :
1725 : 0 : scaled_size = 1.0 + ( ( wrld_size - minSizeGridNode ) / ( maxSizeGridNode - minSizeGridNode ) ) * 9.0;
1726 : :
1727 : : //PRINT_DEBUG_157("Scaled Size = %2.10f\n",scaled_size);
1728 : : //PRINT_INFO(" world = %f, scaled = %f\n", wrld_size, scaled_size );
1729 [ # # ]: 0 : if( scaled_size > 10 ){
1730 [ # # ][ # # ]: 0 : PRINT_INFO("Testing ");
1731 : : }
1732 : :
1733 : 0 : return scaled_size;
1734 : : }
1735 : :
1736 : :
1737 : :
1738 : :
1739 : :
1740 : 0 : CubitStatus CubitOctree::circumcenter(CubitVector &a, CubitVector &b, CubitVector &c, CubitVector ¢er, double &radius)
1741 : : {
1742 : :
1743 : : // Use coordinates relative to point `a' of the triangle.
1744 [ # # ]: 0 : CubitVector vec_ba(a, b);
1745 [ # # ]: 0 : CubitVector vec_ca(a, c);
1746 : :
1747 : : // Squares of lengths of the edges incident to `a'.
1748 [ # # ]: 0 : double ba_length = vec_ba.length_squared();
1749 [ # # ]: 0 : double ca_length = vec_ca.length_squared();
1750 : :
1751 : : // Cross product of these edges.
1752 : : // (Take your chances with floating-point roundoff.)
1753 [ # # ]: 0 : CubitVector cross_bc = vec_ba * vec_ca;
1754 : :
1755 : : // Calculate the denominator of the formulae.
1756 [ # # ]: 0 : double denominator = (cross_bc % cross_bc);
1757 [ # # ]: 0 : if (denominator == 0.0) {return CUBIT_FAILURE;}
1758 [ # # ]: 0 : assert(denominator != 0.0); // don't think we need this..
1759 : :
1760 : : // Calculate offset (from `a') of circumcenter.
1761 [ # # ][ # # ]: 0 : center = (ba_length * vec_ca - ca_length * vec_ba) * cross_bc * 0.5;
[ # # ][ # # ]
[ # # ][ # # ]
1762 [ # # ]: 0 : center /= denominator;
1763 : :
1764 : : // radius is length from point `a' to center
1765 [ # # ]: 0 : radius = center.length();
1766 : :
1767 : : // Add point `a' to get global coordinate of center
1768 [ # # ]: 0 : center += a;
1769 : :
1770 : 0 : return CUBIT_SUCCESS;
1771 : : }
1772 : :
1773 : 0 : double CubitOctree::capsule_distance_to_facet(const CubitVector &point, CubitFacet *lp_facet, CubitVector &int_point, CubitBoolean use_projection_only)
1774 : : {
1775 : :
1776 [ # # ]: 0 : CubitVector c = lp_facet->center();
1777 [ # # ]: 0 : CubitVector n = lp_facet->normal();
1778 [ # # ][ # # ]: 0 : double d = (point - c)%n;
1779 [ # # ][ # # ]: 0 : CubitVector proj = point - d*n;
1780 [ # # ][ # # ]: 0 : CubitVector points[3] = {lp_facet->point(0)->coordinates(), lp_facet->point(1)->coordinates(), lp_facet->point(2)->coordinates()};
[ # # ][ # # ]
[ # # ][ # # ]
1781 : :
1782 [ # # ][ # # ]: 0 : if (use_projection_only || CubitOctreeNode::is_intersection_point_contained_inside_facet(proj, points[0], points[1], points[2]))
[ # # ][ # # ]
1783 : : {
1784 [ # # ]: 0 : int_point = proj;
1785 : 0 : return fabs(d);
1786 : : }
1787 : :
1788 : 0 : double dn[3] = {0,0,0};
1789 [ # # ][ # # ]: 0 : CubitVector pn[3];
1790 : 0 : double t = 0;
1791 : : int i;
1792 : :
1793 [ # # ]: 0 : for (i=0; i < 3; ++i)
1794 : : {
1795 [ # # ]: 0 : CubitVector dir = points[(i+1)%3] - points[i];
1796 [ # # ]: 0 : double length = dir.length();
1797 [ # # ]: 0 : dir.normalize();
1798 [ # # ][ # # ]: 0 : t = ((point - points[i])%dir)/length;
1799 [ # # ][ # # ]: 0 : if (t >= 0 && t <= 1)
1800 : : {
1801 [ # # ][ # # ]: 0 : pn[i] = (length*t*dir + points[i]);
[ # # ]
1802 [ # # ][ # # ]: 0 : dn[i] = (point - (t*length*dir + points[i])).length();
[ # # ][ # # ]
1803 : : }
1804 : : else
1805 : : {
1806 [ # # ]: 0 : if (t < 0)
1807 : : {
1808 [ # # ]: 0 : pn[i] = points[i];
1809 [ # # ][ # # ]: 0 : dn[i] = (point - points[i]).length();
1810 : : }
1811 [ # # ]: 0 : else if (t > 1)
1812 : : {
1813 [ # # ]: 0 : pn[i] = points[(i+1)%3];
1814 [ # # ][ # # ]: 0 : dn[i] = (point - points[(i+1)%3]).length();
1815 : : }
1816 : : //else {PRINT_INFO("Hmmm.... t is not within bounds: %f!!!!!!!!!!!!!!!!11\n", t);}
1817 : : }
1818 : : }
1819 : :
1820 [ # # ][ # # ]: 0 : if (dn[0] <= dn[1] && dn[0] <= dn[2]) {int_point = pn[0]; return dn[0];}
[ # # ]
1821 [ # # ][ # # ]: 0 : if (dn[1] <= dn[0] && dn[1] <= dn[2]) {int_point = pn[1]; return dn[1];}
[ # # ]
1822 [ # # ][ # # ]: 0 : if (dn[2] <= dn[1] && dn[2] <= dn[0]) {int_point = pn[2]; return dn[2];}
[ # # ]
1823 : :
1824 : : else
1825 : : {
1826 : : //PRINT_INFO("capsule dist not found!!!!!!!!!!!!!1\n");
1827 : 0 : return -1;
1828 : : }
1829 : : }
1830 : :
1831 : :
1832 : : #ifndef NDEBUG
1833 : 0 : void CubitOctree::write_sizing_info_file( const char *file_name ){
1834 : :
1835 : : int i,j,k;
1836 : : double size;
1837 : :
1838 [ # # ]: 0 : FILE *pof = fopen( file_name, "w" );
1839 [ # # ]: 0 : if( pof == NULL ){
1840 [ # # ][ # # ]: 0 : PRINT_INFO("ERROR: Opening Sizing Output File ");
[ # # ][ # # ]
1841 : 0 : exit(0);
1842 : : }
1843 : :
1844 [ # # ]: 0 : fprintf( pof, "TFD1\n" );
1845 : 0 : int num_of_cells = (int)pow(2.0, maxDepth-1 );
1846 [ # # ]: 0 : fprintf( pof, "%d %d %d\n", num_of_cells, num_of_cells, num_of_cells );
1847 : : //fprintf( pof, "%f %f %f %f %f %f\n", bboxMaxY, bboxMinZ, bboxMinX, bboxMinY, bboxMaxZ, bboxMaxX );
1848 [ # # ]: 0 : fprintf( pof, "%f %f %f %f %f %f\n", bboxMinX, bboxMinY, bboxMinZ, bboxMaxX, bboxMaxY, bboxMaxZ );
1849 : :
1850 : 0 : int l = num_of_cells + 1;
1851 : 0 : int m = num_of_cells + 1;
1852 : 0 : int n = num_of_cells + 1;
1853 [ # # ]: 0 : CubitVector point;
1854 : :
1855 : 0 : double grid_size = fabs( bboxMinY - bboxMaxY ) / num_of_cells;
1856 : :
1857 [ # # ]: 0 : for( k = 0; k < n; k++ )
1858 : : {
1859 [ # # ]: 0 : for( j = 0; j < m; j++ )
1860 : : {
1861 [ # # ]: 0 : for ( i = 0; i < l; i++ )
1862 : : {
1863 [ # # ]: 0 : point.x( bboxMinX + grid_size * i );
1864 [ # # ]: 0 : point.y( bboxMinY + grid_size * j );
1865 [ # # ]: 0 : point.z( bboxMinZ + grid_size * k );
1866 : :
1867 [ # # ]: 0 : size = size_at_a_point( point, OCTREE_SIZE_DEFAULT);
1868 : : fprintf( pof, "%f %f %f %f %f %f %f %f %f %f %f %f\n",
1869 : : 1.0, 0.0, 0.0, size,
1870 : : 0.0, 1.0, 0.0, size,
1871 [ # # ]: 0 : 0.0, 0.0, 1.0, size );
1872 : : }
1873 : : }
1874 : : }
1875 : :
1876 [ # # ]: 0 : fclose( pof );
1877 : 0 : }
1878 : :
1879 : 0 : void CubitOctree::write_matlab_sizing_info_file( const char *file_name ){
1880 : :
1881 : : int i,j,k;
1882 : : double size;
1883 : :
1884 : : CubitOctreeNode *grid_node;
1885 : :
1886 [ # # ][ # # ]: 0 : for (i=0; i < gridNodeVector.size(); ++i)
1887 : : {
1888 [ # # ]: 0 : grid_node = gridNodeVector.get_and_step();
1889 [ # # ][ # # ]: 0 : if (grid_node->get_color() == CUBIT_GREY_INDEX)
1890 : : {
1891 [ # # ]: 0 : grid_node->set_size(0.0, OCTREE_SIZE_DEFAULT);
1892 : : }
1893 : : }
1894 : :
1895 [ # # ]: 0 : FILE *pof = fopen( file_name, "w" );
1896 [ # # ]: 0 : if( pof == NULL ){
1897 [ # # ][ # # ]: 0 : PRINT_INFO("ERROR: Opening Sizing Output File ");
[ # # ][ # # ]
1898 : 0 : exit(0);
1899 : : }
1900 : :
1901 : :
1902 : 0 : int num_of_cells = 50;//(int)pow(2.0, MATLAB_OUTPUT_MAX_DEPTH );
1903 : : //fprintf( pof, "%f %f %f %f %f %f\n", bboxMinX, bboxMinY, bboxMinZ, bboxMaxX, bboxMaxY, bboxMaxZ );
1904 : :
1905 : 0 : int l = num_of_cells + 1;
1906 : 0 : int m = num_of_cells + 1;
1907 : 0 : int n = num_of_cells + 1;
1908 [ # # ]: 0 : CubitVector point;
1909 : :
1910 : 0 : double grid_size = fabs( bboxMinY - bboxMaxY ) / num_of_cells;
1911 : :
1912 [ # # ]: 0 : for( k = 0; k < n; k++ ){
1913 [ # # ]: 0 : for( j = 0; j < m; j++ ){
1914 [ # # ]: 0 : for ( i = 0; i < l; i++ ){
1915 [ # # ]: 0 : point.x( bboxMinX + grid_size * i );
1916 [ # # ]: 0 : point.y( bboxMinY + grid_size * j );
1917 [ # # ]: 0 : point.z( bboxMinZ + grid_size * k );
1918 : :
1919 [ # # ]: 0 : size = size_at_a_point( point, OCTREE_SIZE_DEFAULT);
1920 : :
1921 : : fprintf( pof, "%f %f %f %f\n",
1922 [ # # ][ # # ]: 0 : point.x(), point.y(), point.z(), size );
[ # # ][ # # ]
1923 : :
1924 : : }
1925 : : }
1926 : : }
1927 : :
1928 [ # # ]: 0 : fclose( pof );
1929 : 0 : }
1930 : :
1931 : 0 : void CubitOctree::write_octree_sizing_info_file( const char *file_name ){
1932 : :
1933 : : int i;
1934 : : double size;
1935 : : CubitOctreeNode *ptr_onode;
1936 : 0 : double FACTOR_FOR_BUBBLEMESH = 1 / 1.8; // Based on 20% overlap of bubbles
1937 : :
1938 [ # # ]: 0 : FILE *pof = fopen( file_name, "w" );
1939 [ # # ]: 0 : if( pof == NULL ){
1940 [ # # ][ # # ]: 0 : PRINT_INFO("ERROR: Opening Sizing Output File ");
[ # # ][ # # ]
1941 : 0 : exit(0);
1942 : : }
1943 : :
1944 [ # # ]: 0 : DLIList<CubitOctreeCell*> stack;
1945 : : CubitOctreeCell *ptr_cell;
1946 : :
1947 [ # # ]: 0 : fprintf( pof, "OCT 1\n" );
1948 : : // int num_of_cells = (int)pow(2.0, skeletonProxy->get_max_depth()-1 );
1949 : : fprintf( pof, "B %f %f %f %f %f %f\n",
1950 [ # # ]: 0 : bboxMinX, bboxMinY, bboxMinZ, bboxMaxX, bboxMaxY, bboxMaxZ );
1951 : :
1952 [ # # ]: 0 : gridNodeVector.reset();
1953 [ # # ][ # # ]: 0 : for( i = 0; i < gridNodeVector.size(); i++ ){
1954 [ # # ]: 0 : ptr_onode = gridNodeVector.get_and_step();
1955 [ # # ]: 0 : size = ptr_onode->get_size(OCTREE_SIZE_DEFAULT);
1956 : :
1957 : : fprintf( pof, "V %d %f %f %f %f \n",
1958 : : ptr_onode->get_num(), ptr_onode->x(), ptr_onode->y(),
1959 [ # # ][ # # ]: 0 : ptr_onode->z(), size * FACTOR_FOR_BUBBLEMESH );
[ # # ][ # # ]
[ # # ]
1960 : : }
1961 : :
1962 [ # # ]: 0 : stack.append( root );
1963 : :
1964 [ # # ][ # # ]: 0 : while( stack.size() > 0 ){
1965 [ # # ]: 0 : ptr_cell = stack.remove();
1966 [ # # ]: 0 : ptr_cell->write_octreecell_sizing_info_file( pof, stack );
1967 : : }
1968 : :
1969 [ # # ]: 0 : fprintf( pof, "X\n");
1970 [ # # ][ # # ]: 0 : fclose( pof );
1971 [ + - ][ + - ]: 6540 : }
1972 : :
1973 : : #endif
1974 : :
1975 : :
1976 : :
1977 : : //EOF
|