Branch data Line data Source code
1 : : #include "CubitOctreeCell.hpp"
2 : :
3 : : #include "CubitColor.hpp"
4 : : #include "CubitOctree.hpp"
5 : : #include "CubitOctreeConstants.hpp"
6 : : #include "CubitOctreeNode.hpp"
7 : : #include "CubitPoint.hpp"
8 : : #include "CubitBox.hpp"
9 : : #include "GfxDebug.hpp"
10 : : #include "CubitFacet.hpp"
11 : : #include "CubitFacetEdge.hpp"
12 : : #include "OctreeFacetPointData.hpp"
13 : : #include "OctreeIntersectionData.hpp"
14 : :
15 : : // temporary includes
16 : : #include "CastTo.hpp"
17 : : #include "RefFace.hpp"
18 : : #include "RefFace.hpp"
19 : :
20 : :
21 : :
22 : : /* -------------------- Methods of CubitOctreeCell ----------------- */
23 : :
24 : 0 : CubitOctreeCell::CubitOctreeCell( CubitVector cen, double dim, int level, CubitOctreeCell *parent_cell ){
25 : : static int counter = 0;
26 : : int i, j, k;
27 : :
28 : 0 : leaf = CUBIT_TRUE;
29 : 0 : dimension = dim;
30 [ # # ]: 0 : mCenter = cen;
31 : 0 : depth = level;
32 : 0 : num = counter;
33 : 0 : counter ++;
34 : 0 : parent = parent_cell;
35 : 0 : mark = CUBIT_FALSE;
36 : 0 : visit = CUBIT_FALSE;
37 : :
38 : 0 : color = CUBIT_WHITE_INDEX;
39 : :
40 : : // CubitOctreeNode = new CubitOctreeNode* [2][2][2];
41 : :
42 : 0 : myFacetList = NULL;
43 : :
44 [ # # ]: 0 : for( i = 0; i < 2; i++ ){
45 [ # # ]: 0 : for( j = 0; j < 2; j++ ){
46 [ # # ]: 0 : for( k = 0; k < 2; k++ ){
47 : 0 : cubitOctreeNode[i][j][k] = NULL;
48 : : }
49 : : }
50 : : }
51 : :
52 [ # # ]: 0 : for( i = 0; i < 2; i++ ){
53 [ # # ]: 0 : for( j = 0; j < 2; j++ ){
54 [ # # ]: 0 : for( k = 0; k < 2; k++ ){
55 : 0 : children[i][j][k] = NULL;
56 : : }
57 : : }
58 : : }
59 : :
60 : : //CubitOctree = NULL;
61 : 0 : }
62 : :
63 : 0 : CubitOctreeCell::~CubitOctreeCell(){
64 : :
65 : : int i, j, k;
66 : :
67 [ # # ]: 0 : for( i = 0; i < 2; i++ ){
68 [ # # ]: 0 : for( j = 0; j < 2; j++ ){
69 [ # # ]: 0 : for( k = 0; k < 2; k++ ){
70 [ # # ]: 0 : if( children[i][j][k] != NULL ){
71 [ # # ][ # # ]: 0 : delete children[i][j][k];
72 : : }
73 : : }
74 : : }
75 : : }
76 : :
77 [ # # ]: 0 : int num_elm = octreeFacetPointDataList.size();
78 [ # # ]: 0 : for( i = 0; i < num_elm; i++ ){
79 [ # # ][ # # ]: 0 : delete octreeFacetPointDataList.pop();
[ # # ]
80 : : }
81 : :
82 : : // delete_local_node_matrix();
83 : :
84 : : /*if (myFacetList)
85 : : {
86 : : for (i=0; i < myFacetList->size(); ++i)
87 : : {
88 : : delete myFacetList->get_and_step();
89 : : }
90 : : delete myFacetList;
91 : : }*/ //uncomment later
92 : :
93 [ # # ]: 0 : }
94 : :
95 : 0 : void CubitOctreeCell::display_color_wireframe( CubitOctree *ptr_octree)
96 : : {
97 : :
98 : : //glColor3f( (cubitOctreeNode[0][0][0])->GetsizeColor(X), (cubitOctreeNode[0][0][0])->GetsizeColor(Y), (cubitOctreeNode[0][0][0])->GetsizeColor(Z) );
99 : : //glColor3f( (cubitOctreeNode[1][0][0])->GetsizeColor(X), (cubitOctreeNode[1][0][0])->GetsizeColor(Y), (cubitOctreeNode[1][0][0])->GetsizeColor(Z) );
100 : : // GfxDebug::draw_line( cubitOctreeNode[0][0][0]->x(), cubitOctreeNode[0][0][0]->y(), cubitOctreeNode[0][0][0]->z(), cubitOctreeNode[1][0][0]->x(), cubitOctreeNode[1][0][0]->y(), cubitOctreeNode[1][0][0]->z(), CUBIT_BLUE_INDEX );
101 [ # # ][ # # ]: 0 : if( cubitOctreeNode[0][0][0]->get_color() != CUBIT_GREY_INDEX && cubitOctreeNode[1][0][0]->get_color() != CUBIT_GREY_INDEX ){
102 : : //SkeletonDebug::draw_line( cubitOctreeNode[0][0][0]->get_coord(), ptr_octree->get_scaled_from_wrld_size_grid_node( cubitOctreeNode[0][0][0]->get_size( OCTREE_SIZE_DEFAULT)), cubitOctreeNode[1][0][0]->get_coord(), ptr_octree->get_scaled_from_wrld_size_grid_node( cubitOctreeNode[1][0][0]->get_size( OCTREE_SIZE_DEFAULT)) );
103 : : }
104 : :
105 : :
106 : : //glColor3f( (cubitOctreeNode[0][1][0])->GetsizeColor(X), (cubitOctreeNode[0][1][0])->GetsizeColor(Y), (cubitOctreeNode[0][1][0])->GetsizeColor(Z) );
107 : : //glColor3f( (cubitOctreeNode[1][1][0])->GetsizeColor(X), (cubitOctreeNode[1][1][0])->GetsizeColor(Y), (cubitOctreeNode[1][1][0])->GetsizeColor(Z) );
108 : : //GfxDebug::draw_line( cubitOctreeNode[0][1][0]->x(), cubitOctreeNode[0][1][0]->y(), cubitOctreeNode[0][1][0]->z(),cubitOctreeNode[1][1][0]->x(), cubitOctreeNode[1][1][0]->y(), cubitOctreeNode[1][1][0]->z(), CUBIT_BLUE_INDEX );
109 [ # # ][ # # ]: 0 : if( cubitOctreeNode[0][1][0]->get_color() != CUBIT_GREY_INDEX && cubitOctreeNode[1][1][0]->get_color() != CUBIT_GREY_INDEX ){
110 : : //SkeletonDebug::draw_line( cubitOctreeNode[0][1][0]->get_coord(), ptr_octree->get_scaled_from_wrld_size_grid_node(cubitOctreeNode[0][1][0]->get_size( OCTREE_SIZE_DEFAULT)), cubitOctreeNode[1][1][0]->get_coord(), ptr_octree->get_scaled_from_wrld_size_grid_node(cubitOctreeNode[1][1][0]->get_size( OCTREE_SIZE_DEFAULT)) );
111 : : }
112 : :
113 : : //glColor3f( (cubitOctreeNode[0][0][0])->GetsizeColor(X), (cubitOctreeNode[0][0][0])->GetsizeColor(Y), (cubitOctreeNode[0][0][0])->GetsizeColor(Z) );
114 : : //glColor3f( (cubitOctreeNode[0][1][0])->GetsizeColor(X), (cubitOctreeNode[0][1][0])->GetsizeColor(Y), (cubitOctreeNode[0][1][0])->GetsizeColor(Z) );
115 : : //GfxDebug::draw_line( cubitOctreeNode[0][0][0]->x(), cubitOctreeNode[0][0][0]->y(), cubitOctreeNode[0][0][0]->z(), cubitOctreeNode[0][1][0]->x(), cubitOctreeNode[0][1][0]->y(), cubitOctreeNode[0][1][0]->z(), CUBIT_BLUE_INDEX );
116 [ # # ][ # # ]: 0 : if( cubitOctreeNode[0][0][0]->get_color() != CUBIT_GREY_INDEX && cubitOctreeNode[0][1][0]->get_color() != CUBIT_GREY_INDEX ){
117 : : //SkeletonDebug::draw_line( cubitOctreeNode[0][0][0]->get_coord(), ptr_octree->get_scaled_from_wrld_size_grid_node(cubitOctreeNode[0][0][0]->get_size( OCTREE_SIZE_DEFAULT)), cubitOctreeNode[0][1][0]->get_coord(), ptr_octree->get_scaled_from_wrld_size_grid_node(cubitOctreeNode[0][1][0]->get_size( OCTREE_SIZE_DEFAULT)) );
118 : : }
119 : :
120 : : //glColor3f( (cubitOctreeNode[1][0][0])->GetsizeColor(X), (cubitOctreeNode[1][0][0])->GetsizeColor(Y), (cubitOctreeNode[1][0][0])->GetsizeColor(Z) );
121 : : //glColor3f( (cubitOctreeNode[1][1][0])->GetsizeColor(X), (cubitOctreeNode[1][1][0])->GetsizeColor(Y), (cubitOctreeNode[1][1][0])->GetsizeColor(Z) );
122 : : //GfxDebug::draw_line( cubitOctreeNode[1][0][0]->x(), cubitOctreeNode[1][0][0]->y(), cubitOctreeNode[1][0][0]->z(), cubitOctreeNode[1][1][0]->x(), cubitOctreeNode[1][1][0]->y(), cubitOctreeNode[1][1][0]->z(), CUBIT_BLUE_INDEX );
123 [ # # ][ # # ]: 0 : if( cubitOctreeNode[1][0][0]->get_color() != CUBIT_GREY_INDEX && cubitOctreeNode[1][1][0]->get_color() != CUBIT_GREY_INDEX ){
124 : : //SkeletonDebug::draw_line( cubitOctreeNode[1][0][0]->get_coord(), ptr_octree->get_scaled_from_wrld_size_grid_node(cubitOctreeNode[1][0][0]->get_size( OCTREE_SIZE_DEFAULT)), cubitOctreeNode[1][1][0]->get_coord(), ptr_octree->get_scaled_from_wrld_size_grid_node(cubitOctreeNode[1][1][0]->get_size( OCTREE_SIZE_DEFAULT)) );
125 : : }
126 : :
127 : : //glColor3f( (cubitOctreeNode[0][0][1])->GetsizeColor(X), (cubitOctreeNode[0][0][1])->GetsizeColor(Y), (cubitOctreeNode[0][0][1])->GetsizeColor(Z) );
128 : : //glColor3f( (cubitOctreeNode[1][0][1])->GetsizeColor(X), (cubitOctreeNode[1][0][1])->GetsizeColor(Y), (cubitOctreeNode[1][0][1])->GetsizeColor(Z) );
129 : : //GfxDebug::draw_line( cubitOctreeNode[0][0][1]->x(), cubitOctreeNode[0][0][1]->y(), cubitOctreeNode[0][0][1]->z(), cubitOctreeNode[1][0][1]->x(), cubitOctreeNode[1][0][1]->y(), cubitOctreeNode[1][0][1]->z(), CUBIT_BLUE_INDEX );
130 [ # # ][ # # ]: 0 : if( cubitOctreeNode[0][0][1]->get_color() != CUBIT_GREY_INDEX && cubitOctreeNode[1][0][1]->get_color() != CUBIT_GREY_INDEX ){
131 : : //SkeletonDebug::draw_line( cubitOctreeNode[0][0][1]->get_coord(), ptr_octree->get_scaled_from_wrld_size_grid_node(cubitOctreeNode[0][0][1]->get_size( OCTREE_SIZE_DEFAULT)), cubitOctreeNode[1][0][1]->get_coord(), ptr_octree->get_scaled_from_wrld_size_grid_node(cubitOctreeNode[1][0][1]->get_size( OCTREE_SIZE_DEFAULT)) );
132 : : }
133 : :
134 : : //glColor3f( (cubitOctreeNode[0][1][1])->GetsizeColor(X), (cubitOctreeNode[0][1][1])->GetsizeColor(Y), (cubitOctreeNode[0][1][1])->GetsizeColor(Z) );
135 : : //glColor3f( (cubitOctreeNode[1][1][1])->GetsizeColor(X), (cubitOctreeNode[1][1][1])->GetsizeColor(Y), (cubitOctreeNode[1][1][1])->GetsizeColor(Z) );
136 : : //GfxDebug::draw_line( cubitOctreeNode[0][1][1]->x(), cubitOctreeNode[0][1][1]->y(), cubitOctreeNode[0][1][1]->z(), cubitOctreeNode[1][1][1]->x(), cubitOctreeNode[1][1][1]->y(), cubitOctreeNode[1][1][1]->z(), CUBIT_BLUE_INDEX );
137 [ # # ][ # # ]: 0 : if( cubitOctreeNode[0][1][1]->get_color() != CUBIT_GREY_INDEX && cubitOctreeNode[1][1][1]->get_color() != CUBIT_GREY_INDEX ){
138 : : //SkeletonDebug::draw_line( cubitOctreeNode[0][1][1]->get_coord(), ptr_octree->get_scaled_from_wrld_size_grid_node(cubitOctreeNode[0][1][1]->get_size( OCTREE_SIZE_DEFAULT)), cubitOctreeNode[1][1][1]->get_coord(), ptr_octree->get_scaled_from_wrld_size_grid_node(cubitOctreeNode[1][1][1]->get_size( OCTREE_SIZE_DEFAULT)) );
139 : : }
140 : :
141 : : //glColor3f( (cubitOctreeNode[0][0][1])->GetsizeColor(X), (cubitOctreeNode[0][0][1])->GetsizeColor(Y), (cubitOctreeNode[0][0][1])->GetsizeColor(Z) );
142 : : //glColor3f( (cubitOctreeNode[0][1][1])->GetsizeColor(X), (cubitOctreeNode[0][1][1])->GetsizeColor(Y), (cubitOctreeNode[0][1][1])->GetsizeColor(Z) );
143 : : //GfxDebug::draw_line( cubitOctreeNode[0][0][1]->x(), cubitOctreeNode[0][0][1]->y(), cubitOctreeNode[0][0][1]->z(), cubitOctreeNode[0][1][1]->x(), cubitOctreeNode[0][1][1]->y(), cubitOctreeNode[0][1][1]->z(), CUBIT_BLUE_INDEX );
144 [ # # ][ # # ]: 0 : if( cubitOctreeNode[0][0][1]->get_color() != CUBIT_GREY_INDEX && cubitOctreeNode[0][1][1]->get_color() != CUBIT_GREY_INDEX ){
145 : : //SkeletonDebug::draw_line( cubitOctreeNode[0][0][1]->get_coord(), ptr_octree->get_scaled_from_wrld_size_grid_node(cubitOctreeNode[0][0][1]->get_size( OCTREE_SIZE_DEFAULT)), cubitOctreeNode[0][1][1]->get_coord(), ptr_octree->get_scaled_from_wrld_size_grid_node(cubitOctreeNode[0][1][1]->get_size( OCTREE_SIZE_DEFAULT)) );
146 : : }
147 : :
148 : : //glColor3f( (cubitOctreeNode[1][0][1])->GetsizeColor(X), (cubitOctreeNode[1][0][1])->GetsizeColor(Y), (cubitOctreeNode[1][0][1])->GetsizeColor(Z) );
149 : : //glColor3f( (cubitOctreeNode[1][1][1])->GetsizeColor(X), (cubitOctreeNode[1][1][1])->GetsizeColor(Y), (cubitOctreeNode[1][1][1])->GetsizeColor(Z) );
150 : : //GfxDebug::draw_line( cubitOctreeNode[1][0][1]->x(), cubitOctreeNode[1][0][1]->y(), cubitOctreeNode[1][0][1]->z(), cubitOctreeNode[1][1][1]->x(), cubitOctreeNode[1][1][1]->y(), cubitOctreeNode[1][1][1]->z(), CUBIT_BLUE_INDEX );
151 [ # # ][ # # ]: 0 : if( cubitOctreeNode[1][0][1]->get_color() != CUBIT_GREY_INDEX && cubitOctreeNode[1][1][1]->get_color() != CUBIT_GREY_INDEX ){
152 : : //SkeletonDebug::draw_line( cubitOctreeNode[1][0][1]->get_coord(), ptr_octree->get_scaled_from_wrld_size_grid_node(cubitOctreeNode[1][0][1]->get_size( OCTREE_SIZE_DEFAULT)), cubitOctreeNode[1][1][1]->get_coord(), ptr_octree->get_scaled_from_wrld_size_grid_node(cubitOctreeNode[1][1][1]->get_size( OCTREE_SIZE_DEFAULT)) );
153 : : }
154 : :
155 : : //glColor3f( (cubitOctreeNode[0][0][0])->GetsizeColor(X), (cubitOctreeNode[0][0][0])->GetsizeColor(Y), (cubitOctreeNode[0][0][0])->GetsizeColor(Z) );
156 : : //glColor3f( (cubitOctreeNode[0][0][1])->GetsizeColor(X), (cubitOctreeNode[0][0][1])->GetsizeColor(Y), (cubitOctreeNode[0][0][1])->GetsizeColor(Z) );
157 : : //GfxDebug::draw_line( cubitOctreeNode[0][0][0]->x(), cubitOctreeNode[0][0][0]->y(), cubitOctreeNode[0][0][0]->z(), cubitOctreeNode[0][0][1]->x(), cubitOctreeNode[0][0][1]->y(), cubitOctreeNode[0][0][1]->z(), CUBIT_BLUE_INDEX );
158 [ # # ][ # # ]: 0 : if( cubitOctreeNode[0][0][0]->get_color() != CUBIT_GREY_INDEX && cubitOctreeNode[0][0][1]->get_color() != CUBIT_GREY_INDEX ){
159 : : //SkeletonDebug::draw_line( cubitOctreeNode[0][0][0]->get_coord(), ptr_octree->get_scaled_from_wrld_size_grid_node(cubitOctreeNode[0][0][0]->get_size( OCTREE_SIZE_DEFAULT)), cubitOctreeNode[0][0][1]->get_coord(), ptr_octree->get_scaled_from_wrld_size_grid_node(cubitOctreeNode[0][0][1]->get_size( OCTREE_SIZE_DEFAULT)) );
160 : : }
161 : :
162 : : //glColor3f( (cubitOctreeNode[0][1][0])->GetsizeColor(X), (cubitOctreeNode[0][1][0])->GetsizeColor(Y), (cubitOctreeNode[0][1][0])->GetsizeColor(Z) );
163 : : //glColor3f( (cubitOctreeNode[0][1][1])->GetsizeColor(X), (cubitOctreeNode[0][1][1])->GetsizeColor(Y), (cubitOctreeNode[0][1][1])->GetsizeColor(Z) );
164 : : //GfxDebug::draw_line( cubitOctreeNode[0][1][0]->x(), cubitOctreeNode[0][1][0]->y(), cubitOctreeNode[0][1][0]->z(), cubitOctreeNode[0][1][1]->x(), cubitOctreeNode[0][1][1]->y(), cubitOctreeNode[0][1][1]->z(), CUBIT_BLUE_INDEX );
165 [ # # ][ # # ]: 0 : if( cubitOctreeNode[0][1][0]->get_color() != CUBIT_GREY_INDEX && cubitOctreeNode[0][1][1]->get_color() != CUBIT_GREY_INDEX ){
166 : : //SkeletonDebug::draw_line( cubitOctreeNode[0][0][0]->get_coord(), ptr_octree->get_scaled_from_wrld_size_grid_node(cubitOctreeNode[0][0][0]->get_size( OCTREE_SIZE_DEFAULT)), cubitOctreeNode[0][0][1]->get_coord(), ptr_octree->get_scaled_from_wrld_size_grid_node(cubitOctreeNode[0][0][1]->get_size( OCTREE_SIZE_DEFAULT)) );
167 : : }
168 : :
169 : : //glColor3f( (cubitOctreeNode[1][0][0])->GetsizeColor(X), (cubitOctreeNode[1][0][0])->GetsizeColor(Y), (cubitOctreeNode[1][0][0])->GetsizeColor(Z) );
170 : : //glColor3f( (cubitOctreeNode[1][0][1])->GetsizeColor(X), (cubitOctreeNode[1][0][1])->GetsizeColor(Y), (cubitOctreeNode[1][0][1])->GetsizeColor(Z) );
171 : : //GfxDebug::draw_line( cubitOctreeNode[1][0][0]->x(), cubitOctreeNode[1][0][0]->y(), cubitOctreeNode[1][0][0]->z(), cubitOctreeNode[1][0][1]->x(), cubitOctreeNode[1][0][1]->y(), cubitOctreeNode[1][0][1]->z(), CUBIT_BLUE_INDEX );
172 : : //SkeletonDebug::draw_line( cubitOctreeNode[1][0][0]->get_coord(), cubitOctreeNode[1][0][0]->get_size( OCTREE_SIZE_DEFAULT), cubitOctreeNode[1][0][1]->get_coord(), cubitOctreeNode[1][0][1]->get_size( OCTREE_SIZE_DEFAULT) );
173 [ # # ][ # # ]: 0 : if( cubitOctreeNode[1][0][0]->get_color() != CUBIT_GREY_INDEX && cubitOctreeNode[1][0][1]->get_color() != CUBIT_GREY_INDEX ){
174 : : //SkeletonDebug::draw_line( cubitOctreeNode[0][0][0]->get_coord(), ptr_octree->get_scaled_from_wrld_size_grid_node(cubitOctreeNode[0][0][0]->get_size( OCTREE_SIZE_DEFAULT)), cubitOctreeNode[0][0][1]->get_coord(), ptr_octree->get_scaled_from_wrld_size_grid_node(cubitOctreeNode[0][0][1]->get_size( OCTREE_SIZE_DEFAULT)) );
175 : : }
176 : :
177 : : //glColor3f( (cubitOctreeNode[1][1][0])->GetsizeColor(X), (cubitOctreeNode[1][1][0])->GetsizeColor(Y), (cubitOctreeNode[1][1][0])->GetsizeColor(Z) );
178 : : //glColor3f( (cubitOctreeNode[1][1][1])->GetsizeColor(X), (cubitOctreeNode[1][1][1])->GetsizeColor(Y), (cubitOctreeNode[1][1][1])->GetsizeColor(Z) );
179 : : //GfxDebug::draw_line( cubitOctreeNode[1][1][0]->x(), cubitOctreeNode[1][1][0]->y(), cubitOctreeNode[1][1][0]->z(), cubitOctreeNode[1][1][1]->x(), cubitOctreeNode[1][1][1]->y(), cubitOctreeNode[1][1][1]->z(), CUBIT_BLUE_INDEX );
180 [ # # ][ # # ]: 0 : if( cubitOctreeNode[1][1][0]->get_color() != CUBIT_GREY_INDEX && cubitOctreeNode[1][1][1]->get_color() != CUBIT_GREY_INDEX ){
181 : : //SkeletonDebug::draw_line( cubitOctreeNode[1][1][0]->get_coord(), ptr_octree->get_scaled_from_wrld_size_grid_node(cubitOctreeNode[1][1][0]->get_size( OCTREE_SIZE_DEFAULT)), cubitOctreeNode[1][1][1]->get_coord(), ptr_octree->get_scaled_from_wrld_size_grid_node(cubitOctreeNode[1][1][1]->get_size( OCTREE_SIZE_DEFAULT)) );
182 : : }
183 : :
184 : 0 : }
185 : :
186 : 0 : void CubitOctreeCell::display( CubitOctree *ptr_octree, int opt ){
187 : :
188 : : int i, j, k;
189 : :
190 [ # # ]: 0 : if( is_leaf() == CUBIT_FALSE ){
191 [ # # ]: 0 : for( i = 0; i < 2; i++ ){
192 [ # # ]: 0 : for( j = 0; j < 2; j++ ){
193 [ # # ]: 0 : for( k = 0; k < 2; k++ ){
194 : : //if( children[i][j][k] != NULL ){
195 : 0 : children[i][j][k]->display(ptr_octree, opt);
196 : : //}
197 : : }
198 : : }
199 : : }
200 : : }
201 [ # # ]: 0 : else if (opt == 1)
202 : : {
203 : : // draw all cells in black wireframe mode
204 : : //double corners[3];
205 : : //double half_edge_length = get_dimension()/2.0;
206 : : //CubitVector center = get_center();
207 : : //center.get_xyz(corners);
208 : : //double box[6] = {corners[0]-half_edge_length, corners[1]-half_edge_length, corners[2]-half_edge_length,
209 : : //corners[0]+half_edge_length, corners[1]+half_edge_length, corners[2]+half_edge_length};
210 : : //SVDrawTool::draw_cube(box, CUBIT_BLACK_INDEX, SVDrawTool::WIRE);
211 : 0 : return;
212 : : }
213 [ # # ]: 0 : else if (opt == 2)
214 : : {
215 : : // draw grey and black cells in black wireframe mode
216 : : //(color == CUBIT_GREY_INDEX || color == CUBIT_BLACK_INDEX)
217 : 0 : if (color == CUBIT_BLACK_INDEX)
218 : : {
219 : : //double corners[3];
220 : : //double half_edge_length = get_dimension()/2.0;
221 : : //CubitVector center = get_center();
222 : : //center.get_xyz(corners);
223 : : //double box[6] = {corners[0]-half_edge_length, corners[1]-half_edge_length, corners[2]-half_edge_length,
224 : : //corners[0]+half_edge_length, corners[1]+half_edge_length, corners[2]+half_edge_length};
225 : : //SVDrawTool::draw_cube(box, CUBIT_BLACK_INDEX, SVDrawTool::WIRE);
226 : : }
227 : 0 : return;
228 : : }
229 [ # # ]: 0 : else if (opt == 3)
230 : : {
231 : : // draw grey cells in white smoothshade mode
232 : 0 : if (color == CUBIT_GREY_INDEX)
233 : : {
234 : : //double corners[3];
235 : : //double half_edge_length = get_dimension()/2.0;
236 : : //CubitVector center = get_center();
237 : : //center.get_xyz(corners);
238 : : //double box[6] = {corners[0]-half_edge_length, corners[1]-half_edge_length, corners[2]-half_edge_length,
239 : : //corners[0]+half_edge_length, corners[1]+half_edge_length, corners[2]+half_edge_length};
240 : : //SVDrawTool::draw_cube(box, CUBIT_WHITE_INDEX, SVDrawTool::SHADE);
241 : : //SVDrawTool::draw_cube(box, CUBIT_BLACK_INDEX, SVDrawTool::WIRE);
242 : : }
243 : 0 : return;
244 : : }
245 [ # # ]: 0 : else if (opt == 4)
246 : : {
247 : 0 : if (color != CUBIT_WHITE_INDEX)
248 : : {
249 : : //double corners[3];
250 : : //double half_edge_length = get_dimension()/2.0;
251 : : //CubitVector center = get_center();
252 : : //center.get_xyz(corners);
253 : : //double box[6] = {corners[0]-half_edge_length, corners[1]-half_edge_length, corners[2]-half_edge_length,
254 : : //corners[0]+half_edge_length, corners[1]+half_edge_length, corners[2]+half_edge_length};
255 : : //SVDrawTool::draw_cube(box, CUBIT_WHITE_INDEX, SVDrawTool::SHADE);
256 : : //SVDrawTool::draw_cube(box, CUBIT_BLACK_INDEX, SVDrawTool::WIRE);
257 : : }
258 : 0 : return;
259 : : }
260 [ # # ]: 0 : else if (opt == 5)
261 : : {
262 : : // draw grey and black cells in color wireframe mode
263 [ # # ][ # # ]: 0 : if( color == CUBIT_GREY_INDEX || color == CUBIT_BLACK_INDEX )
264 : 0 : display_color_wireframe(ptr_octree);
265 : 0 : return;
266 : : }
267 : : else
268 [ # # ]: 0 : if( /*color == CUBIT_GREY_INDEX ||*/ color == CUBIT_BLACK_INDEX )
269 : 0 : display_color_wireframe(ptr_octree);
270 : 0 : return;
271 : : }
272 : :
273 : 0 : void CubitOctreeCell::release_octreefacetpointdata( void ){
274 : :
275 : : int i, j, k;
276 : :
277 [ # # ]: 0 : if( is_leaf() == CUBIT_FALSE ){
278 [ # # ]: 0 : for( i = 0; i < 2; i++ ){
279 [ # # ]: 0 : for( j = 0; j < 2; j++ ){
280 [ # # ]: 0 : for( k = 0; k < 2; k++ ){
281 : 0 : children[i][j][k]->release_octreefacetpointdata( );
282 : : }
283 : : }
284 : : }
285 : : }
286 : : else{
287 : 0 : int num_elm = octreeFacetPointDataList.size();
288 [ # # ]: 0 : for( i = 0; i < num_elm; i++ ){
289 [ # # ]: 0 : delete octreeFacetPointDataList.pop();
290 : : }
291 : : }
292 : 0 : }
293 : :
294 : :
295 : :
296 : 0 : void CubitOctreeCell::display_octreefacetpointdata( void ){
297 : :
298 : : int i, j, k;
299 : :
300 [ # # ]: 0 : if( is_leaf() == CUBIT_FALSE ){
301 [ # # ]: 0 : for( i = 0; i < 2; i++ ){
302 [ # # ]: 0 : for( j = 0; j < 2; j++ ){
303 [ # # ]: 0 : for( k = 0; k < 2; k++ ){
304 : 0 : children[i][j][k]->display_octreefacetpointdata( );
305 : : }
306 : : }
307 : : }
308 : : }
309 : : else{
310 [ # # ]: 0 : for( i = 0; i < octreeFacetPointDataList.size(); i++ ){
311 : 0 : octreeFacetPointDataList.get_and_step()->display();
312 : : }
313 : : }
314 : 0 : }
315 : :
316 : 0 : void CubitOctreeCell::set_oct_grid_node( const int i, const int j, const int k, CubitOctreeNode *ptr_node ){
317 : :
318 : 0 : cubitOctreeNode[i][j][k] = ptr_node;
319 : 0 : }
320 : :
321 : 0 : void CubitOctreeCell::set_child( int i, int j, int k, CubitOctreeCell *ptr_child_cell ){
322 : :
323 : 0 : children[i][j][k] = ptr_child_cell;
324 : :
325 : 0 : }
326 : :
327 : 0 : CubitOctreeCell * CubitOctreeCell::get_child( const int i, const int j,const int k ){
328 : :
329 : 0 : return ( children[i][j][k] );
330 : :
331 : : }
332 : :
333 : 0 : CubitOctreeCell * CubitOctreeCell::find_leaf_octree_cell(const CubitVector &point ){
334 : :
335 : : int i, j, k;
336 : :
337 [ # # ]: 0 : if( is_leaf() == CUBIT_TRUE ){
338 : 0 : return this;
339 : : }
340 : : else{
341 : :
342 : 0 : i = j = k = 1;
343 : :
344 [ # # ]: 0 : if( point.x() < mCenter.x() )
345 : 0 : i = 0;
346 : :
347 [ # # ]: 0 : if( point.y() < mCenter.y() )
348 : 0 : j = 0;
349 : :
350 [ # # ]: 0 : if( point.z() < mCenter.z() )
351 : 0 : k = 0;
352 : :
353 [ # # ]: 0 : if (children[i][j][k] == NULL) {return NULL;}
354 : :
355 : 0 : return children[i][j][k]->find_leaf_octree_cell( point );
356 : :
357 : : }
358 : : }
359 : :
360 : 0 : void CubitOctreeCell::distribute_facet_points_among_children( void ){
361 : : int i;
362 : : int l, m, n;
363 : :
364 : : OctreeFacetPointData *ptr_facet_point_data;
365 : :
366 : 0 : octreeFacetPointDataList.reset();
367 : :
368 [ # # ]: 0 : for( i = 0; i < octreeFacetPointDataList.size(); i++ ){
369 : :
370 : 0 : ptr_facet_point_data = octreeFacetPointDataList.get_and_step();
371 : :
372 : 0 : l = m = n = 1;
373 : :
374 [ # # ]: 0 : if( ptr_facet_point_data->x() < mCenter.x() )
375 : 0 : l = 0;
376 : :
377 [ # # ]: 0 : if( ptr_facet_point_data->y() < mCenter.y() )
378 : 0 : m = 0;
379 : :
380 [ # # ]: 0 : if( ptr_facet_point_data->z() < mCenter.z() )
381 : 0 : n = 0;
382 : :
383 : 0 : children[l][m][n]->append_list_item( ptr_facet_point_data );
384 : :
385 : : }
386 : : // Clean the points and face list in the parent cell
387 : 0 : octreeFacetPointDataList.clean_out();
388 : :
389 : 0 : }
390 : :
391 : :
392 : : /*
393 : : bool CubitOctreeCell::append_list_item( RefFace *ptr_Ref_face ){
394 : : facetPointFaceList.push( ptr_Ref_face);
395 : : return CUBIT_TRUE;
396 : : }
397 : : */
398 : 0 : bool CubitOctreeCell::append_list_item( OctreeFacetPointData *ptr_facet_point_data ){
399 : 0 : octreeFacetPointDataList.push( ptr_facet_point_data );
400 : 0 : return CUBIT_TRUE;
401 : : }
402 : :
403 : :
404 : 0 : bool CubitOctreeCell::add_adjacent_unmarked_cells( DLIList< CubitOctreeCell *> &queue ){
405 : : //optimized
406 : : static int i, j, k, l, m, n;
407 : : static CubitOctreeNode *ptr_grid_node;
408 : : static CubitOctreeCell *ptr_cell;
409 [ # # ][ # # ]: 0 : static DLIList<CubitOctreeCell*> temp_list;
[ # # ][ # # ]
410 : :
411 [ # # ]: 0 : for( i = 1; i >= 0; i-- ){
412 [ # # ]: 0 : for( j = 1; j >= 0; j-- ){
413 [ # # ]: 0 : for( k = 1; k >= 0; k-- ){
414 : :
415 : 0 : ptr_grid_node = cubitOctreeNode[i][j][k];
416 : :
417 [ # # ]: 0 : for( l = 0; l < 2; l++ ){
418 [ # # ]: 0 : for( m = 0; m < 2; m++ ){
419 [ # # ]: 0 : for( n = 0; n < 2; n++ ){
420 : :
421 : 0 : ptr_cell = ptr_grid_node->get_adj_cell( l, m, n );
422 : :
423 [ # # ]: 0 : if( ptr_cell != NULL )
424 : : {
425 [ # # ]: 0 : if( ptr_cell->mark == CUBIT_FALSE )
426 : : {
427 : : //queue.append( ptr_cell );
428 : 0 : temp_list.append(ptr_cell);
429 : : // ptr_cell->set_mark( CUBIT_TRUE );
430 : 0 : ptr_cell->mark = CUBIT_TRUE;
431 : :
432 : : }
433 : : }
434 : :
435 : : }
436 : : }
437 : : }
438 : : }
439 : : }
440 : : }
441 : 0 : queue += temp_list;
442 : 0 : temp_list.clean_out();
443 : :
444 : 0 : return CUBIT_TRUE;
445 : : }
446 : :
447 : 0 : bool CubitOctreeCell::is_intersects_box(const CubitBox &box ){
448 : :
449 : : double x_min, x_max, y_min, y_max, z_min, z_max;
450 [ # # ][ # # ]: 0 : CubitVector box_min, box_max;
451 : : int I, II, III, IV;
452 : :
453 : : //GfxDebug::draw_point( center.x(), center.y(), center.z(), CUBIT_RED_INDEX, itoa( num, buffer, 10 ) );
454 : :
455 : : // DEBUG:
456 : : // changed from dimension -> dimenstion_2
457 : 0 : double dimension_2 = dimension / 2.0;
458 [ # # ]: 0 : x_min = mCenter.x() - dimension_2;
459 [ # # ]: 0 : x_max = mCenter.x() + dimension_2;
460 [ # # ]: 0 : y_min = mCenter.y() - dimension_2;
461 [ # # ]: 0 : y_max = mCenter.y() + dimension_2;
462 [ # # ]: 0 : z_min = mCenter.z() - dimension_2;
463 [ # # ]: 0 : z_max = mCenter.z() + dimension_2;
464 : :
465 [ # # ][ # # ]: 0 : box_min = box.minimum();
466 [ # # ][ # # ]: 0 : box_max = box.maximum();
467 : :
468 : : //PRINT_DEBUG_157("Testing: Bbox of facet MIN = [ %2.2lf %2.2lf %2.2lf ] MAX = [ %2.2lf %2.2lf %2.2lf ]\n",box_min.x(), box_min.y(), box_min.z(), box_max.x(), box_max.y(), box_max.z() );
469 : : //PRINT_DEBUG_157("Testing: Cell MIN = [ %2.2lf %2.2lf %2.2lf ] MAX = [ %2.2lf %2.2lf %2.2lf ]\n",x_min, y_min, z_min, x_max, y_max, z_max );
470 : :
471 : : // A represent min of cell and B represent max of cell
472 : : // C represent min of bbox and D represent max of bbox
473 : : // A < C => I
474 : : // B < C => II
475 : : // A < D => III
476 : : // B < D => IV
477 : :
478 : 0 : I = II = III = IV = -1;
479 [ # # ][ # # ]: 0 : if( x_max < box_min.x() ){
480 : 0 : II = 1;
481 : 0 : I = 1;
482 : : }
483 : : else{
484 [ # # ][ # # ]: 0 : if( x_min < box_min.x() ){
485 : 0 : I = 1;
486 : : }
487 : : }
488 : :
489 [ # # ][ # # ]: 0 : if( x_max <= box_max.x() ){
490 : 0 : III = 1;
491 : 0 : IV = 1;
492 : : }
493 : : else{
494 [ # # ][ # # ]: 0 : if( x_min <= box_max.x() ){
495 : 0 : III = 1;
496 : : }
497 : : }
498 : :
499 [ # # ][ # # ]: 0 : if( I * II == 1 && III * IV == 1 && I * III == 1 ){
[ # # ]
500 : : //PRINT_DEBUG_157(" X No Intersection \n");
501 : 0 : return CUBIT_FALSE;
502 : : }
503 : :
504 : :
505 : :
506 : 0 : I = II = III = IV = -1;
507 [ # # ][ # # ]: 0 : if( y_max < box_min.y() ){
508 : 0 : II = 1;
509 : 0 : I = 1;
510 : : }
511 : : else{
512 [ # # ][ # # ]: 0 : if( y_min < box_min.y() ){
513 : 0 : I = 1;
514 : : }
515 : : }
516 : :
517 [ # # ][ # # ]: 0 : if( y_max <= box_max.y() ){
518 : 0 : III = 1;
519 : 0 : IV = 1;
520 : : }
521 : : else{
522 [ # # ][ # # ]: 0 : if( y_min <= box_max.y() ){
523 : 0 : III = 1;
524 : : }
525 : : }
526 : :
527 [ # # ][ # # ]: 0 : if( I * II == 1 && III * IV == 1 && I * III == 1 ){
[ # # ]
528 : : //PRINT_DEBUG_157(" Y No Intersection \n");
529 : 0 : return CUBIT_FALSE;
530 : : }
531 : :
532 : :
533 : 0 : I = II = III = IV = -1;
534 [ # # ][ # # ]: 0 : if( z_max < box_min.z() ){
535 : 0 : II = 1;
536 : 0 : I = 1;
537 : : }
538 : : else{
539 [ # # ][ # # ]: 0 : if( z_min < box_min.z() ){
540 : 0 : I = 1;
541 : : }
542 : : }
543 : :
544 [ # # ][ # # ]: 0 : if( z_max <= box_max.z() ){
545 : 0 : III = 1;
546 : 0 : IV = 1;
547 : : }
548 : : else{
549 [ # # ][ # # ]: 0 : if( z_min <= box_max.z() ){
550 : 0 : III = 1;
551 : : }
552 : : }
553 : :
554 [ # # ][ # # ]: 0 : if( I * II == 1 && III * IV == 1 && I * III == 1 ){
[ # # ]
555 : : //PRINT_DEBUG_157(" Z No Intersection \n");
556 : 0 : return CUBIT_FALSE;
557 : : }
558 : :
559 : : //PRINT_DEBUG_157(" *********************** Intersection ************************* \n");
560 : 0 : return CUBIT_TRUE;
561 : :
562 : : }
563 : :
564 : :
565 : 0 : CubitBoolean CubitOctreeCell::is_facet_point_data_present( const CubitVector &coord ){
566 : :
567 : : OctreeFacetPointData *facet_point_data;
568 : : int i;
569 : :
570 : 0 : octreeFacetPointDataList.reset();
571 [ # # ]: 0 : for( i = 0; i < octreeFacetPointDataList.size(); i++ ){
572 : 0 : facet_point_data = octreeFacetPointDataList.get_and_step();
573 [ # # ][ # # ]: 0 : if( (facet_point_data->coordinates() - coord ).length() < OCTREE_EPSILON ){
[ # # ]
574 : 0 : return CUBIT_TRUE;
575 : : }
576 : : }
577 : 0 : return CUBIT_FALSE;
578 : :
579 : : }
580 : :
581 : 0 : CubitBoolean CubitOctreeCell::is_facet_point_data_present( OctreeFacetPointData *new_facet_point_data ){
582 : :
583 : : OctreeFacetPointData *facet_point_data;
584 : : int i;
585 : :
586 : 0 : octreeFacetPointDataList.reset();
587 [ # # ]: 0 : for( i = 0; i < octreeFacetPointDataList.size(); i++ ){
588 : 0 : facet_point_data = octreeFacetPointDataList.get_and_step();
589 [ # # ]: 0 : if( facet_point_data->id() ==
590 : 0 : new_facet_point_data->id() ){
591 : 0 : return CUBIT_TRUE;
592 : : }
593 : : }
594 : 0 : return CUBIT_FALSE;
595 : :
596 : : }
597 : :
598 : 0 : void CubitOctreeCell::coloring( /*DLIList<CubitOctreeCell *> &grey_cell_list ,*/ DLIList<CubitOctreeCell*> &black_cell_list )
599 : : {
600 : : int i,j,k;
601 : : int grey, black;
602 : :
603 : 0 : grey = FALSE;
604 : 0 : black = TRUE;
605 : :
606 [ # # ]: 0 : if( leaf == CUBIT_TRUE ){
607 : :
608 [ # # ]: 0 : for( i = 0; i < 2; i++ ){
609 [ # # ]: 0 : for( j = 0; j < 2; j++ ){
610 [ # # ]: 0 : for( k = 0; k < 2; k++ ){
611 [ # # ]: 0 : if( cubitOctreeNode[i][j][k]->get_color() != CUBIT_BLACK_INDEX )
612 : : {
613 : 0 : black = FALSE;
614 : : }
615 : : else
616 : : {
617 : 0 : grey = TRUE;
618 : : }
619 : : }
620 : : }
621 : : }
622 : :
623 [ # # ]: 0 : if( black == TRUE )
624 : : {
625 : 0 : color = CUBIT_BLACK_INDEX;
626 [ # # ]: 0 : black_cell_list.append(this);
627 : : }
628 : : else
629 [ # # ]: 0 : if( grey == TRUE ){
630 : 0 : color = CUBIT_GREY_INDEX;
631 : : //grey_cell_list.push( this );
632 : : }
633 : : else
634 : : {
635 : 0 : color = CUBIT_WHITE_INDEX; //constructor
636 : : //return CUBIT_TRUE;
637 : : }
638 : :
639 : : }
640 : : else{
641 [ # # ]: 0 : for( i = 0; i < 2; i++ )
642 : : {
643 [ # # ]: 0 : for( j = 0; j < 2; j++ )
644 : : {
645 [ # # ]: 0 : for( k = 0; k < 2; k++ )
646 : : {
647 : 0 : children[i][j][k]->coloring( /*grey_cell_list,*/ black_cell_list);
648 : : }
649 : : }
650 : : }
651 : : }
652 : :
653 : : //return CUBIT_FALSE;
654 : :
655 : 0 : }
656 : :
657 : :
658 : 0 : CubitBoolean CubitOctreeCell::interpolate_grey_octreecell_node( void ){
659 : :
660 : : float avg_size;
661 : : int counter;
662 : : int i,j,k;
663 : :
664 : 0 : avg_size = 0;
665 : 0 : counter = 0;
666 [ # # ]: 0 : for( i = 0; i < 2; i++ ){
667 [ # # ]: 0 : for( j = 0; j < 2; j++ ){
668 [ # # ]: 0 : for( k = 0; k < 2; k++ ){
669 : : //if( cubitOctreeNode[i][j][k]->get_size( OCTREE_SIZE_DEFAULT ) != 0 && cubitOctreeNode[i][j][k]->get_size( OCTREE_SIZE_DEFAULT ) != CUBIT_DBL_MAX ){
670 : : //if( cubitOctreeNode[i][j][k]->get_size( OCTREE_SIZE_DEFAULT ) != 0.0 ){
671 [ # # ]: 0 : if (cubitOctreeNode[i][j][k]->get_color() == CUBIT_BLACK_INDEX)
672 : : {
673 : 0 : avg_size += cubitOctreeNode[i][j][k]->get_size( OCTREE_SIZE_DEFAULT );
674 : 0 : counter++;
675 : : }
676 : : //}
677 : : }
678 : : }
679 : : }
680 : :
681 [ # # ]: 0 : if( counter == 0 ){
682 : 0 : return CUBIT_FALSE;
683 : : }
684 : :
685 : 0 : avg_size /= counter;
686 : :
687 [ # # ]: 0 : for( i = 0; i < 2; i++ ){
688 [ # # ]: 0 : for( j = 0; j < 2; j++ ){
689 [ # # ]: 0 : for( k = 0; k < 2; k++ ){
690 : : //if( cubitOctreeNode[i][j][k]->get_color() == CUBIT_WHITE_INDEX ){
691 [ # # ]: 0 : if( cubitOctreeNode[i][j][k]->get_color() != CUBIT_BLACK_INDEX ){
692 : : //if( cubitOctreeNode[i][j][k]->get_size( OCTREE_SIZE_DEFAULT ) == 0.0 ){
693 : 0 : cubitOctreeNode[i][j][k]->set_size( avg_size, OCTREE_SIZE_DEFAULT );
694 : : //}
695 : : //else{
696 : : // cubitOctreeNode[i][j][k]->set_size( ( avg_size + cubitOctreeNode[i][j][k]->get_size( OCTREE_SIZE_DEFAULT ) ) / 2.0, OCTREE_SIZE_DEFAULT );
697 : : //}
698 : : }
699 : : //}
700 : : }
701 : : }
702 : : }
703 : :
704 : 0 : return CUBIT_TRUE;
705 : : }
706 : :
707 : : // Trilienar interpolation
708 : : // if number of nodes with zero size exceeds MAX_NUM_ZERO_SIZE_NODES
709 : : // then average size is used instead of zero
710 : : // Even GREY grid nodes are consided
711 : : // If a node has zero size then that node is not considered
712 : : // Therefore color is not important but the size
713 : 0 : double CubitOctreeCell::trilinear_interpolation(const CubitVector &point ){
714 : : double size;
715 : : int i, j, k;
716 [ # # ][ # # ]: 0 : CubitVector center, min_corner, max_corner;
[ # # ]
717 : : double dim, dim_2;
718 : : double Nx[2], Ny[2], Nz[2];
719 : : double size_at_node;
720 : : CubitOctreeNode *ptr_node;
721 : :
722 : : // Find Shape functions at eight grid nodes of a cell
723 [ # # ][ # # ]: 0 : center = get_center();
724 [ # # ]: 0 : dim = get_dimension();
725 : 0 : dim_2 = dimension / 2.0;
726 : :
727 [ # # ][ # # ]: 0 : min_corner.x( center.x() - dim_2 );
728 [ # # ][ # # ]: 0 : min_corner.y( center.y() - dim_2 );
729 [ # # ][ # # ]: 0 : min_corner.z( center.z() - dim_2 );
730 : :
731 [ # # ][ # # ]: 0 : max_corner.x( center.x() + dim_2 );
732 [ # # ][ # # ]: 0 : max_corner.y( center.y() + dim_2 );
733 [ # # ][ # # ]: 0 : max_corner.z( center.z() + dim_2 );
734 : :
735 [ # # ][ # # ]: 0 : Nx[0] = ( max_corner.x() - point.x() ) / dim;
736 [ # # ][ # # ]: 0 : Ny[0] = ( max_corner.y() - point.y() ) / dim;
737 [ # # ][ # # ]: 0 : Nz[0] = ( max_corner.z() - point.z() ) / dim;
738 : :
739 [ # # ][ # # ]: 0 : Nx[1] = ( point.x() - min_corner.x() ) / dim;
740 [ # # ][ # # ]: 0 : Ny[1] = ( point.y() - min_corner.y() ) / dim;
741 [ # # ][ # # ]: 0 : Nz[1] = ( point.z() - min_corner.z() ) / dim;
742 : :
743 : : // Trilinear interpolation
744 : : // if number of nodes with zero size exceeds MAX_NUM_ZERO_SIZE_NODES
745 : : // then average size is used instead of zero
746 : :
747 : :
748 : : // Interpolate using non-zero nodes
749 : 0 : size = 0.0;
750 : :
751 : 0 : int zero_node_counter = 0;
752 : :
753 [ # # ]: 0 : for( i = 0; i < 2; i++ ){
754 [ # # ]: 0 : for( j = 0; j < 2; j++ ){
755 [ # # ]: 0 : for( k = 0; k < 2; k++ ){
756 [ # # ]: 0 : ptr_node = get_octree_grid_node(i, j, k);
757 [ # # ]: 0 : size_at_node = ptr_node->get_size(OCTREE_SIZE_DEFAULT);
758 [ # # ]: 0 : if( size_at_node != 0.0 ){
759 : 0 : size += size_at_node * Nx[i] * Ny[j] * Nz[k];
760 : : }
761 : : else{
762 [ # # ][ # # ]: 0 : if( ptr_node->find_size_using_adj_node() == CUBIT_TRUE ){
763 [ # # ]: 0 : size += ptr_node->get_size( OCTREE_SIZE_DEFAULT ) * Nx[i] * Ny[j] * Nz[k];
764 : : }
765 : : else{
766 : 0 : zero_node_counter ++;
767 : : }
768 : : }
769 : : }
770 : : }
771 : : }
772 : :
773 : : // For interior of volume avg_size will not be calculated
774 : : // as no zero size node exist
775 [ # # ]: 0 : if( zero_node_counter > MAX_NUM_ZERO_SIZE_NODES ){
776 : :
777 : : // Find Average size
778 : 0 : double avg_size = 0.0;
779 : 0 : int counter = 0;
780 : :
781 [ # # ]: 0 : for( i = 0; i < 2; i++ ){
782 [ # # ]: 0 : for( j = 0; j < 2; j++ ){
783 [ # # ]: 0 : for( k = 0; k < 2; k++ ){
784 [ # # ][ # # ]: 0 : size_at_node = get_octree_grid_node(i, j, k)->get_size(OCTREE_SIZE_DEFAULT);
785 [ # # ]: 0 : if( size_at_node != 0.0 ){
786 : 0 : avg_size += size_at_node;
787 : 0 : counter ++;
788 : : }
789 : : }
790 : : }
791 : : }
792 : :
793 [ # # ]: 0 : if( counter > 0 ){
794 : 0 : avg_size /= counter;
795 : :
796 : : // use avg_size instead of zero during tri-linear interpolation
797 : : // only at nodes with zero size
798 [ # # ]: 0 : for( i = 0; i < 2; i++ ){
799 [ # # ]: 0 : for( j = 0; j < 2; j++ ){
800 [ # # ]: 0 : for( k = 0; k < 2; k++ ){
801 [ # # ][ # # ]: 0 : size_at_node = get_octree_grid_node(i, j, k)->get_size(OCTREE_SIZE_DEFAULT);
802 [ # # ]: 0 : if( size_at_node == 0.0 ){
803 : 0 : size += avg_size * Nx[i] * Ny[j] * Nz[k];
804 : : }
805 : : }
806 : : }
807 : : }
808 : :
809 : : }
810 : : else{
811 [ # # ][ # # ]: 0 : PRINT_DEBUG_157(" WARNING: Size of all nodes is zero \n" );
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ]
812 : : //In size at a point default auto size will be used
813 : : // autosize could be based on either average medial radius or
814 : : // steve's autosize function
815 : : }
816 : : }
817 : :
818 : 0 : return size;
819 : : }
820 : :
821 : : // Using Separating Axis Theorem (Eberly)
822 : : // Mostly used Moller's article to implement this code
823 : :
824 : : // returns true if intersection is present
825 : 0 : CubitBoolean CubitOctreeCell::does_facet_intersect_octreecell(CubitFacet *ptr_facet)
826 : : {
827 : : int i;
828 : :
829 [ # # ][ # # ]: 0 : CubitVector v0 = ptr_facet->point(0)->coordinates() - get_center(), v1 = ptr_facet->point(1)->coordinates() - get_center(),
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
830 [ # # ][ # # ]: 0 : v2 = ptr_facet->point(2)->coordinates() - get_center();
[ # # ][ # # ]
831 : :
832 [ # # ][ # # ]: 0 : static CubitVector sep_axes[13];
[ # # ][ # # ]
[ # # ]
833 [ # # ][ # # ]: 0 : sep_axes[0] = ptr_facet->normal();
834 [ # # ][ # # ]: 0 : sep_axes[1] = CubitVector(1,0,0);// note to self: optimize following trivial cross products
835 [ # # ][ # # ]: 0 : sep_axes[2] = CubitVector(0,1,0);
836 [ # # ][ # # ]: 0 : sep_axes[3] = CubitVector(0,0,1);
837 [ # # ][ # # ]: 0 : sep_axes[4] = sep_axes[1]*(v1-v0);
[ # # ]
838 [ # # ][ # # ]: 0 : sep_axes[5] = sep_axes[1]*(v2-v1);
[ # # ]
839 [ # # ][ # # ]: 0 : sep_axes[6] = sep_axes[1]*(v0-v2);
[ # # ]
840 [ # # ][ # # ]: 0 : sep_axes[7] = sep_axes[2]*(v1-v0);
[ # # ]
841 [ # # ][ # # ]: 0 : sep_axes[8] = sep_axes[2]*(v2-v1);
[ # # ]
842 [ # # ][ # # ]: 0 : sep_axes[9] = sep_axes[2]*(v0-v2);
[ # # ]
843 [ # # ][ # # ]: 0 : sep_axes[10] = sep_axes[3]*(v1-v0);
[ # # ]
844 [ # # ][ # # ]: 0 : sep_axes[11] = sep_axes[3]*(v2-v1);
[ # # ]
845 [ # # ][ # # ]: 0 : sep_axes[12] = sep_axes[3]*(v0-v2);
[ # # ]
846 : :
847 [ # # ]: 0 : sep_axes[4].normalize();
848 [ # # ]: 0 : sep_axes[5].normalize();
849 [ # # ]: 0 : sep_axes[6].normalize();
850 [ # # ]: 0 : sep_axes[7].normalize();
851 [ # # ]: 0 : sep_axes[8].normalize();
852 [ # # ]: 0 : sep_axes[9].normalize();
853 [ # # ]: 0 : sep_axes[10].normalize();
854 [ # # ]: 0 : sep_axes[11].normalize();
855 [ # # ]: 0 : sep_axes[12].normalize();
856 : :
857 : : double rad_b, dot1, dot2, dot3, min_t, max_t;
858 [ # # ]: 0 : for (i=0; i < 13; ++i)
859 : : {
860 : :
861 : : // rad_b is the "radius" of the projection of the cell onto the separating axis, centered about the projection of the cell's center
862 : : // min_t and max_t are the extremes of the projection of the triangle onto the separating axis
863 [ # # ][ # # ]: 0 : rad_b = (get_dimension() / 2.0) * (fabs(sep_axes[i].x()) + fabs(sep_axes[i].y()) + fabs(sep_axes[i].z()));
[ # # ][ # # ]
864 [ # # ]: 0 : dot1 = v0%sep_axes[i];
865 [ # # ]: 0 : dot2 = v1%sep_axes[i];
866 [ # # ]: 0 : dot3 = v2%sep_axes[i];
867 : :
868 [ # # ][ # # ]: 0 : min_t = CUBIT_MIN(CUBIT_MIN(dot1,dot2),dot3);
[ # # ]
869 [ # # ][ # # ]: 0 : max_t = CUBIT_MAX(CUBIT_MAX(dot1,dot2),dot3);
[ # # ]
870 : :
871 : : // if the triangle's projection is on either side of the CubitOctree cell's projection, i.e. the projections don't overlap, then the two are disjoint
872 : : //if ( min_t > rad_b || max_t < -rad_b)
873 [ # # ][ # # ]: 0 : if ( (min_t - rad_b) > 1e-6 || (-rad_b -max_t) > 1e-6)
874 : : {
875 : : // found a separating axis so facet and cell do not intersect
876 : 0 : return CUBIT_FALSE;
877 : : }
878 : : }
879 : :
880 : : // OctreeIntersectionData code was here
881 : :
882 : 0 : return CUBIT_TRUE;
883 : : }
884 : :
885 : 0 : void CubitOctreeCell::set_color_and_intersection_datas(CubitFacet *ptr_facet, RefFace *ptr_Ref_face,
886 : : #ifdef USE_octree_BGMESH
887 : : DLIList<CubitOctreeCell*> *greyCellList,
888 : : #endif
889 : : CubitSense surf_sense)
890 : : {
891 : : int i, j, k;
892 [ # # ]: 0 : CubitVector facet_normal = ptr_facet->normal();
893 : : //SVDrawTool::draw_vector(ptr_facet->center(),ptr_facet->center()+ptr_facet->normal(), CUBIT_MAGENTA_INDEX);
894 : : /* if( ptr_facet->is_backwards() ) // Ved: note to self - check this
895 : : {
896 : : facet_normal = facet_normal * -1;
897 : : }*/
898 : :
899 : : // if (!myFacetList) {myFacetList = new DLIList</*CubitFacet*/OctreeIntersectionData*>;} uncomment later
900 : :
901 : : // OctreeIntersectionData(CubitVector normal, int half_space, double len, RefFace *ptr_face, CubitVector closest_point_on_facet, CubitFacet *lp_facet);
902 : :
903 : : /* CubitVector dummy;
904 : : OctreeIntersectionData *new_idata = new OctreeIntersectionData(dummy, 1, 0.0, ptr_Ref_face, dummy, ptr_facet);
905 : : myFacetList->append(new_idata);*/ // uncomment later
906 : :
907 : : /* if (!myFaceList) {myFaceList = new DLIList<RefFace*>;}
908 : : if (!myFaceList->where_is_item(ptr_Ref_face))
909 : : {
910 : : myFaceList->append(ptr_Ref_face);
911 : : }*/
912 : :
913 : : // bool merged = (CAST_TO(ptr_Ref_face, RefFace)->num_parent_ref_entities() == 2);
914 : :
915 [ # # ]: 0 : for (i=0; i < 2; ++i)
916 : : {
917 [ # # ]: 0 : for (j=0; j < 2; ++j)
918 : : {
919 [ # # ]: 0 : for (k=0; k < 2; ++k)
920 : : {
921 [ # # ]: 0 : CubitVector closest_point_on_facet;
922 : : double dist_to_facet;
923 [ # # ][ # # ]: 0 : if (defaultDistanceMetric == CAPSULE_DIST) {dist_to_facet = CubitOctree::capsule_distance_to_facet(cubitOctreeNode[i][j][k]->get_coord(), ptr_facet, closest_point_on_facet);}
924 : : else if (defaultDistanceMetric == PROJECTED_DIST) {dist_to_facet = CubitOctree::capsule_distance_to_facet(cubitOctreeNode[i][j][k]->get_coord(), ptr_facet, closest_point_on_facet, CUBIT_TRUE);}
925 : :
926 : : /*if (dist_to_facet < 0)
927 : : {
928 : : //PRINT_INFO("Invalid distance: %lf !!!!\n", dist_to_facet);
929 : : //SVDrawTool::draw_point(cubitOctreeNode[i][j][k]->get_coord(), CUBIT_MAGENTA_INDEX);
930 : :
931 : : //double test_dist = CubitOctree::capsule_distance_to_facet(cubitOctreeNode[i][j][k]->get_coord(), ptr_facet, closest_point_on_facet);
932 : : }*/
933 : :
934 : : OctreeIntersectionData *idata;
935 : :
936 [ # # ]: 0 : if (/*merged == CUBIT_TRUE*/ surf_sense == CUBIT_UNKNOWN)
937 : : {
938 [ # # ]: 0 : CubitVector temp_facet_normal = facet_normal;
939 : :
940 [ # # ][ # # ]: 0 : if (cubitOctreeNode[i][j][k]->get_halfspace_direction() == OCTREE_NEGATIVE)
941 : : {
942 [ # # ]: 0 : temp_facet_normal *= -1.0;
943 : : }
944 : :
945 : :
946 : : // SVDrawTool::draw_point(cubitOctreeNode[i][j][k]->get_coord(), CUBIT_MAGENTA_INDEX);
947 : :
948 [ # # ][ # # ]: 0 : idata = new OctreeIntersectionData(temp_facet_normal, OCTREE_NEGATIVE, dist_to_facet, ptr_Ref_face, closest_point_on_facet, ptr_facet);
949 [ # # ]: 0 : idata->set_merged(1);
950 : : }
951 : : else
952 : : {
953 [ # # ]: 0 : CubitVector temp_facet_normal = facet_normal;
954 [ # # ]: 0 : CubitBoolean temp_half_space = cubitOctreeNode[i][j][k]->get_halfspace_direction();
955 [ # # ][ # # ]: 0 : if (surf_sense == CUBIT_FORWARD) {temp_facet_normal *= -1.0;}
956 [ # # ]: 0 : else if (surf_sense == CUBIT_REVERSED) {temp_half_space = !temp_half_space;}
957 [ # # ][ # # ]: 0 : idata = new OctreeIntersectionData(temp_facet_normal, temp_half_space, dist_to_facet, ptr_Ref_face, closest_point_on_facet, ptr_facet);
958 : : }
959 : :
960 : : // idata->set_facet_ptr(ptr_facet);
961 : : // idata->set_int_point(closest_point_on_facet);
962 [ # # ]: 0 : cubitOctreeNode[i][j][k]->append_list_item(idata);
963 : : }
964 : : }
965 : : }
966 : :
967 : 0 : color = CUBIT_GREY_INDEX;
968 : :
969 : : #ifdef USE_octree_BGMESH
970 : : if (!visit)
971 : : {
972 : : greyCellList->append(this); // for background mesh generation
973 : : visit = CUBIT_TRUE;
974 : : }
975 : : #endif
976 : :
977 : 0 : }
978 : :
979 : 0 : CubitBoolean CubitOctreeCell::does_contain_positive_and_negative_nodes( void ){
980 : : int i, j, k;
981 : 0 : CubitBoolean positive_space = CUBIT_FALSE;
982 : 0 : CubitBoolean negative_space = CUBIT_FALSE;
983 : :
984 [ # # ]: 0 : for( i = 0; i < 2; i++ ){
985 [ # # ]: 0 : for( j = 0; j < 2; j++ ){
986 [ # # ]: 0 : for( k = 0; k < 2; k++ ){
987 [ # # ]: 0 : if( cubitOctreeNode[i][j][k]->get_halfspace_direction() == OCTREE_POSITIVE )
988 : 0 : positive_space = CUBIT_TRUE;
989 : : else
990 : 0 : negative_space = CUBIT_TRUE;
991 : : }
992 : : }
993 : : }
994 : :
995 [ # # ][ # # ]: 0 : if( positive_space == CUBIT_TRUE && negative_space == CUBIT_TRUE ){
996 : 0 : return CUBIT_TRUE;
997 : : }
998 : : else{
999 : 0 : return CUBIT_FALSE;
1000 : : }
1001 : : }
1002 : :
1003 : 0 : double CubitOctreeCell::inverse_distance_interpolation(const CubitVector &point ){
1004 : : double size;
1005 : 0 : long double denominator=0;
1006 : 0 : long double nominator=0;
1007 : : double weight;
1008 : : long double dist_func;
1009 [ # # ]: 0 : CubitVector node_coord;
1010 : : double dist;
1011 : : int i, j, k;
1012 : 0 : int type = DEFAULT_INVERSE_DISTANCE_SCHEME_INSIDE_CELL;
1013 : :
1014 : :
1015 [ # # ]: 0 : for( i = 0; i < 2; i++ ){
1016 [ # # ]: 0 : for( j = 0; j < 2; j++ ){
1017 [ # # ]: 0 : for( k = 0; k < 2; k++ ){
1018 [ # # ][ # # ]: 0 : if( get_octree_grid_node(i, j, k)->get_size(OCTREE_SIZE_DEFAULT) != 0.0 ){
[ # # ]
1019 [ # # ][ # # ]: 0 : node_coord = get_octree_grid_node(i, j, k)->get_coord();
[ # # ]
1020 : :
1021 [ # # ][ # # ]: 0 : dist = ( node_coord - point ).length();
1022 : :
1023 [ # # ]: 0 : if( dist < OCTREE_EPSILON )
1024 : 0 : dist = OCTREE_EPSILON;
1025 : :
1026 [ # # # # ]: 0 : switch( type ){
1027 : :
1028 : : case INVERSE_LINEAR:
1029 : 0 : dist_func = dist;
1030 : 0 : break;
1031 : :
1032 : : case INVERSE_QUADRATIC:
1033 : 0 : dist_func = dist * dist;
1034 : 0 : break;
1035 : :
1036 : : case INVERSE_CUBIC:
1037 : 0 : dist_func = dist * dist * dist;
1038 : 0 : break;
1039 : :
1040 : : default:
1041 : 0 : dist_func = dist * dist;
1042 : : }
1043 : :
1044 : 0 : denominator += 1.0 / ( dist_func );
1045 : : }
1046 : : }
1047 : : }
1048 : : }
1049 : :
1050 : 0 : size = 0.0;
1051 : :
1052 [ # # ]: 0 : for( i = 0; i < 2; i ++ ){
1053 [ # # ]: 0 : for( j = 0; j < 2; j++ ){
1054 [ # # ]: 0 : for( k = 0; k < 2; k++ ){
1055 [ # # ][ # # ]: 0 : if( get_octree_grid_node(i, j, k)->get_size(OCTREE_SIZE_DEFAULT) != 0.0 ){
[ # # ]
1056 [ # # ][ # # ]: 0 : node_coord = get_octree_grid_node(i,j,k)->get_coord();
[ # # ]
1057 : :
1058 [ # # ][ # # ]: 0 : dist = ( node_coord - point ).length();
1059 : :
1060 [ # # ]: 0 : if( dist < OCTREE_EPSILON )
1061 : 0 : dist = OCTREE_EPSILON;
1062 : :
1063 [ # # # # ]: 0 : switch( type ){
1064 : :
1065 : : case INVERSE_LINEAR:
1066 : 0 : dist_func = dist;
1067 : 0 : break;
1068 : :
1069 : : case INVERSE_QUADRATIC:
1070 : 0 : dist_func = dist * dist;
1071 : 0 : break;
1072 : :
1073 : : case INVERSE_CUBIC:
1074 : 0 : dist_func = dist * dist * dist;
1075 : 0 : break;
1076 : : default:
1077 : 0 : dist_func = dist * dist;
1078 : : }
1079 : :
1080 : 0 : nominator = 1.0 / ( dist_func );
1081 : :
1082 : 0 : weight = nominator / denominator ;
1083 : :
1084 [ # # ][ # # ]: 0 : size += get_octree_grid_node(i,j,k)->get_size( OCTREE_SIZE_DEFAULT ) * weight;
1085 : : //PRINT_DEBUG_157(" size at grid node = %f\n",get_octree_grid_node(i,j,k)->get_size( OCTREE_SIZE_DEFAULT ));
1086 : : }
1087 : : }
1088 : : }
1089 : : }
1090 : :
1091 : 0 : return size;
1092 : : }
1093 : :
1094 : :
1095 : 0 : double CubitOctreeCell::min_distance_interpolation(const CubitVector &point )
1096 : : {
1097 : : double size;
1098 [ # # ]: 0 : CubitVector node_coord;
1099 : : double dist;
1100 : : int i, j, k;
1101 : :
1102 : 0 : double min_dist = CUBIT_DBL_MAX;
1103 : :
1104 : 0 : size = 0.0;
1105 : :
1106 [ # # ]: 0 : for( i = 0; i < 2; i++ ){
1107 [ # # ]: 0 : for( j = 0; j < 2; j++ ){
1108 [ # # ]: 0 : for( k = 0; k < 2; k++ ){
1109 [ # # ][ # # ]: 0 : if( get_octree_grid_node(i, j, k)->get_size(OCTREE_SIZE_DEFAULT) != 0.0 )
[ # # ]
1110 : : {
1111 [ # # ][ # # ]: 0 : node_coord = get_octree_grid_node(i, j, k)->get_coord();
[ # # ]
1112 : :
1113 [ # # ][ # # ]: 0 : dist = ( node_coord - point ).length();
1114 : :
1115 [ # # ]: 0 : if( dist < OCTREE_EPSILON )
1116 : 0 : dist = OCTREE_EPSILON;
1117 : :
1118 [ # # ]: 0 : if( dist < min_dist )
1119 : : {
1120 : 0 : min_dist = dist;
1121 [ # # ][ # # ]: 0 : size = get_octree_grid_node(i,j,k)->get_size( OCTREE_SIZE_DEFAULT );
1122 : : }
1123 : : }
1124 : : }
1125 : : }
1126 : : }
1127 : :
1128 : 0 : return size;
1129 : : }
1130 : :
1131 : :
1132 : :
1133 : 0 : double CubitOctreeCell::min_size_interpolation(const CubitVector &point ){
1134 : :
1135 [ # # ]: 0 : CubitVector node_coord;
1136 : : int i, j, k;
1137 : :
1138 : 0 : double min_size = CUBIT_DBL_MAX;
1139 : : double size;
1140 : :
1141 : :
1142 : :
1143 [ # # ]: 0 : for( i = 0; i < 2; i++ ){
1144 [ # # ]: 0 : for( j = 0; j < 2; j++ ){
1145 [ # # ]: 0 : for( k = 0; k < 2; k++ ){
1146 [ # # ][ # # ]: 0 : if( get_octree_grid_node(i, j, k)->get_size(OCTREE_SIZE_DEFAULT) != 0.0 )
[ # # ]
1147 : : {
1148 [ # # ][ # # ]: 0 : size = get_octree_grid_node(i,j,k)->get_size( OCTREE_SIZE_DEFAULT );
1149 : :
1150 [ # # ]: 0 : if( size < OCTREE_EPSILON )
1151 : 0 : size = OCTREE_EPSILON;
1152 : :
1153 [ # # ]: 0 : if( size < min_size )
1154 : : {
1155 : 0 : min_size = size;
1156 : : }
1157 : : }
1158 : : }
1159 : : }
1160 : : }
1161 : :
1162 : 0 : return min_size;
1163 : : }
1164 : :
1165 : 0 : CubitStatus CubitOctreeCell::find_indices_in_parent( int *index ){
1166 : :
1167 : : int i, j, k;
1168 : :
1169 [ # # ]: 0 : for( i = 0; i < 2; i++ ){
1170 [ # # ]: 0 : for( j = 0; j < 2; j++ ){
1171 [ # # ]: 0 : for( k = 0; k < 2; k++ ){
1172 [ # # ]: 0 : if( parent->get_child( i, j, k )->id() == num ){
1173 : 0 : index[0] = i;
1174 : 0 : index[1] = j;
1175 : 0 : index[2] = k;
1176 : 0 : return CUBIT_SUCCESS;
1177 : : }
1178 : : }
1179 : : }
1180 : : }
1181 : :
1182 : 0 : return CUBIT_FAILURE;
1183 : : }
1184 : :
1185 : :
1186 : : #ifndef NDEBUG
1187 : 0 : void CubitOctreeCell::write_octreecell_sizing_info_file( FILE *pof, DLIList<CubitOctreeCell*> &stack ){
1188 : :
1189 : : int index[3];
1190 : : int i, j, k;
1191 : :
1192 [ # # ]: 0 : if( parent == NULL ){
1193 [ # # ]: 0 : fprintf( pof, "C %d -1 0 0 0 %d\n", num, !leaf );
1194 : : }
1195 : : else{
1196 [ # # ]: 0 : find_indices_in_parent( index );
1197 [ # # ][ # # ]: 0 : fprintf( pof, "C %d %d %d %d %d %d \n", num, parent->id(), index[0], index[1], index[2], !leaf );
1198 : : }
1199 : :
1200 : :
1201 [ # # ]: 0 : fprintf( pof, "V");
1202 [ # # ]: 0 : for( i = 0; i < 2; i++ ){
1203 [ # # ]: 0 : for( j = 0; j < 2; j++ ){
1204 [ # # ]: 0 : for( k = 0; k < 2; k++ ){
1205 [ # # ][ # # ]: 0 : fprintf( pof," %d ", cubitOctreeNode[i][j][k]->get_num() );
1206 : : }
1207 : : }
1208 : : }
1209 [ # # ]: 0 : fprintf( pof, "\n");
1210 : :
1211 [ # # ]: 0 : if( leaf == 0 ){
1212 [ # # ]: 0 : fprintf( pof, "H");
1213 [ # # ]: 0 : for( i = 0; i < 2; i++ ){
1214 [ # # ]: 0 : for( j = 0; j < 2; j++ ){
1215 [ # # ]: 0 : for( k = 0; k < 2; k++ ){
1216 [ # # ][ # # ]: 0 : fprintf( pof," %d ", children[i][j][k]->id() );
1217 [ # # ]: 0 : stack.append( children[i][j][k] );
1218 : : }
1219 : : }
1220 : : }
1221 [ # # ]: 0 : fprintf( pof, "\n");
1222 : : }
1223 : :
1224 [ # # ]: 0 : fprintf( pof, "E\n");
1225 [ + - ][ + - ]: 6540 : }
1226 : : #endif
1227 : :
1228 : :
1229 : : //EOF
1230 : :
|