cgma
CubitOctreeCell.cpp
Go to the documentation of this file.
00001 #include "CubitOctreeCell.hpp"
00002 
00003 #include "CubitColor.hpp"
00004 #include "CubitOctree.hpp"
00005 #include "CubitOctreeConstants.hpp"
00006 #include "CubitOctreeNode.hpp"
00007 #include "CubitPoint.hpp"
00008 #include "CubitBox.hpp" 
00009 #include "GfxDebug.hpp" 
00010 #include "CubitFacet.hpp"
00011 #include "CubitFacetEdge.hpp"
00012 #include "OctreeFacetPointData.hpp"
00013 #include "OctreeIntersectionData.hpp"
00014 
00015 // temporary includes
00016 #include "CastTo.hpp"
00017 #include "RefFace.hpp"
00018 #include "RefFace.hpp"
00019 
00020 
00021 
00022 /* -------------------- Methods of CubitOctreeCell ----------------- */
00023 
00024 CubitOctreeCell::CubitOctreeCell( CubitVector cen, double dim, int level, CubitOctreeCell *parent_cell ){
00025   static int counter = 0; 
00026   int i, j, k; 
00027   
00028   leaf = CUBIT_TRUE;
00029   dimension = dim;
00030   mCenter = cen;
00031   depth = level;
00032   num = counter;
00033   counter ++;
00034   parent = parent_cell; 
00035   mark = CUBIT_FALSE;
00036   visit = CUBIT_FALSE;
00037   
00038   color = CUBIT_WHITE_INDEX;
00039 
00040 //  CubitOctreeNode = new CubitOctreeNode* [2][2][2];
00041 
00042   myFacetList = NULL;
00043   
00044   for( i = 0; i < 2; i++ ){
00045     for( j = 0; j < 2; j++ ){
00046       for( k = 0; k < 2; k++ ){
00047         cubitOctreeNode[i][j][k] = NULL;
00048       }
00049     }
00050   }
00051   
00052   for( i = 0; i < 2; i++ ){
00053     for( j = 0; j < 2; j++ ){
00054       for( k = 0; k < 2; k++ ){
00055         children[i][j][k] = NULL;
00056       }
00057     }
00058   }
00059   
00060     //CubitOctree = NULL;
00061 }
00062 
00063 CubitOctreeCell::~CubitOctreeCell(){
00064   
00065   int i, j, k;
00066   
00067   for( i = 0; i < 2; i++ ){
00068     for( j = 0; j < 2; j++ ){
00069       for( k = 0; k < 2; k++ ){
00070         if( children[i][j][k] != NULL ){
00071           delete children[i][j][k];
00072         }
00073       }
00074     }
00075   }
00076 
00077   int num_elm = octreeFacetPointDataList.size();
00078   for( i = 0; i < num_elm; i++ ){
00079     delete octreeFacetPointDataList.pop(); 
00080   }
00081 
00082     // delete_local_node_matrix();
00083   
00084     /*if (myFacetList)
00085       {
00086       for (i=0; i < myFacetList->size(); ++i)
00087       {
00088       delete myFacetList->get_and_step();
00089       }
00090       delete myFacetList;
00091       }*/ //uncomment later
00092   
00093 }
00094 
00095 void CubitOctreeCell::display_color_wireframe( CubitOctree *ptr_octree)
00096 {
00097     
00098     //glColor3f( (cubitOctreeNode[0][0][0])->GetsizeColor(X), (cubitOctreeNode[0][0][0])->GetsizeColor(Y), (cubitOctreeNode[0][0][0])->GetsizeColor(Z) );
00099     //glColor3f( (cubitOctreeNode[1][0][0])->GetsizeColor(X), (cubitOctreeNode[1][0][0])->GetsizeColor(Y), (cubitOctreeNode[1][0][0])->GetsizeColor(Z) );
00100     // 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 );
00101     if( cubitOctreeNode[0][0][0]->get_color() != CUBIT_GREY_INDEX && cubitOctreeNode[1][0][0]->get_color() != CUBIT_GREY_INDEX ){
00102         //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)) );
00103     }
00104     
00105     
00106     //glColor3f( (cubitOctreeNode[0][1][0])->GetsizeColor(X), (cubitOctreeNode[0][1][0])->GetsizeColor(Y), (cubitOctreeNode[0][1][0])->GetsizeColor(Z) );
00107     //glColor3f( (cubitOctreeNode[1][1][0])->GetsizeColor(X), (cubitOctreeNode[1][1][0])->GetsizeColor(Y), (cubitOctreeNode[1][1][0])->GetsizeColor(Z) );
00108     //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 );
00109     if( cubitOctreeNode[0][1][0]->get_color() != CUBIT_GREY_INDEX && cubitOctreeNode[1][1][0]->get_color() != CUBIT_GREY_INDEX ){
00110         //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)) );
00111     }
00112     
00113     //glColor3f( (cubitOctreeNode[0][0][0])->GetsizeColor(X), (cubitOctreeNode[0][0][0])->GetsizeColor(Y), (cubitOctreeNode[0][0][0])->GetsizeColor(Z) );
00114     //glColor3f( (cubitOctreeNode[0][1][0])->GetsizeColor(X), (cubitOctreeNode[0][1][0])->GetsizeColor(Y), (cubitOctreeNode[0][1][0])->GetsizeColor(Z) );
00115     //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 );
00116     if( cubitOctreeNode[0][0][0]->get_color() != CUBIT_GREY_INDEX && cubitOctreeNode[0][1][0]->get_color() != CUBIT_GREY_INDEX ){
00117         //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)) );
00118     }
00119     
00120     //glColor3f( (cubitOctreeNode[1][0][0])->GetsizeColor(X), (cubitOctreeNode[1][0][0])->GetsizeColor(Y), (cubitOctreeNode[1][0][0])->GetsizeColor(Z) );
00121     //glColor3f( (cubitOctreeNode[1][1][0])->GetsizeColor(X), (cubitOctreeNode[1][1][0])->GetsizeColor(Y), (cubitOctreeNode[1][1][0])->GetsizeColor(Z) );
00122     //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 );
00123     if( cubitOctreeNode[1][0][0]->get_color() != CUBIT_GREY_INDEX && cubitOctreeNode[1][1][0]->get_color() != CUBIT_GREY_INDEX ){
00124         //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)) );
00125     }
00126     
00127     //glColor3f( (cubitOctreeNode[0][0][1])->GetsizeColor(X), (cubitOctreeNode[0][0][1])->GetsizeColor(Y), (cubitOctreeNode[0][0][1])->GetsizeColor(Z) );
00128     //glColor3f( (cubitOctreeNode[1][0][1])->GetsizeColor(X), (cubitOctreeNode[1][0][1])->GetsizeColor(Y), (cubitOctreeNode[1][0][1])->GetsizeColor(Z) );
00129     //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 );
00130     if( cubitOctreeNode[0][0][1]->get_color() != CUBIT_GREY_INDEX && cubitOctreeNode[1][0][1]->get_color() != CUBIT_GREY_INDEX ){
00131         //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)) );
00132     }
00133     
00134     //glColor3f( (cubitOctreeNode[0][1][1])->GetsizeColor(X), (cubitOctreeNode[0][1][1])->GetsizeColor(Y), (cubitOctreeNode[0][1][1])->GetsizeColor(Z) );
00135     //glColor3f( (cubitOctreeNode[1][1][1])->GetsizeColor(X), (cubitOctreeNode[1][1][1])->GetsizeColor(Y), (cubitOctreeNode[1][1][1])->GetsizeColor(Z) );
00136     //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 );
00137     if( cubitOctreeNode[0][1][1]->get_color() != CUBIT_GREY_INDEX && cubitOctreeNode[1][1][1]->get_color() != CUBIT_GREY_INDEX ){
00138         //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)) );
00139     }
00140     
00141     //glColor3f( (cubitOctreeNode[0][0][1])->GetsizeColor(X), (cubitOctreeNode[0][0][1])->GetsizeColor(Y), (cubitOctreeNode[0][0][1])->GetsizeColor(Z) );
00142     //glColor3f( (cubitOctreeNode[0][1][1])->GetsizeColor(X), (cubitOctreeNode[0][1][1])->GetsizeColor(Y), (cubitOctreeNode[0][1][1])->GetsizeColor(Z) );
00143     //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 );
00144     if( cubitOctreeNode[0][0][1]->get_color() != CUBIT_GREY_INDEX && cubitOctreeNode[0][1][1]->get_color() != CUBIT_GREY_INDEX ){
00145         //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)) );
00146     }
00147     
00148     //glColor3f( (cubitOctreeNode[1][0][1])->GetsizeColor(X), (cubitOctreeNode[1][0][1])->GetsizeColor(Y), (cubitOctreeNode[1][0][1])->GetsizeColor(Z) );
00149     //glColor3f( (cubitOctreeNode[1][1][1])->GetsizeColor(X), (cubitOctreeNode[1][1][1])->GetsizeColor(Y), (cubitOctreeNode[1][1][1])->GetsizeColor(Z) );
00150     //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 );
00151     if( cubitOctreeNode[1][0][1]->get_color() != CUBIT_GREY_INDEX && cubitOctreeNode[1][1][1]->get_color() != CUBIT_GREY_INDEX ){
00152         //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)) );
00153     }
00154     
00155     //glColor3f( (cubitOctreeNode[0][0][0])->GetsizeColor(X), (cubitOctreeNode[0][0][0])->GetsizeColor(Y), (cubitOctreeNode[0][0][0])->GetsizeColor(Z) );
00156     //glColor3f( (cubitOctreeNode[0][0][1])->GetsizeColor(X), (cubitOctreeNode[0][0][1])->GetsizeColor(Y), (cubitOctreeNode[0][0][1])->GetsizeColor(Z) );
00157     //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 );
00158     if( cubitOctreeNode[0][0][0]->get_color() != CUBIT_GREY_INDEX && cubitOctreeNode[0][0][1]->get_color() != CUBIT_GREY_INDEX ){
00159         //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)) );
00160     }
00161     
00162     //glColor3f( (cubitOctreeNode[0][1][0])->GetsizeColor(X), (cubitOctreeNode[0][1][0])->GetsizeColor(Y), (cubitOctreeNode[0][1][0])->GetsizeColor(Z) );
00163     //glColor3f( (cubitOctreeNode[0][1][1])->GetsizeColor(X), (cubitOctreeNode[0][1][1])->GetsizeColor(Y), (cubitOctreeNode[0][1][1])->GetsizeColor(Z) );
00164     //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 );
00165     if( cubitOctreeNode[0][1][0]->get_color() != CUBIT_GREY_INDEX && cubitOctreeNode[0][1][1]->get_color() != CUBIT_GREY_INDEX ){
00166         //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)) );
00167     }
00168     
00169     //glColor3f( (cubitOctreeNode[1][0][0])->GetsizeColor(X), (cubitOctreeNode[1][0][0])->GetsizeColor(Y), (cubitOctreeNode[1][0][0])->GetsizeColor(Z) );
00170     //glColor3f( (cubitOctreeNode[1][0][1])->GetsizeColor(X), (cubitOctreeNode[1][0][1])->GetsizeColor(Y), (cubitOctreeNode[1][0][1])->GetsizeColor(Z) );
00171     //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 );
00172     //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) );
00173     if( cubitOctreeNode[1][0][0]->get_color() != CUBIT_GREY_INDEX && cubitOctreeNode[1][0][1]->get_color() != CUBIT_GREY_INDEX ){
00174         //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)) );
00175     }
00176     
00177     //glColor3f( (cubitOctreeNode[1][1][0])->GetsizeColor(X), (cubitOctreeNode[1][1][0])->GetsizeColor(Y), (cubitOctreeNode[1][1][0])->GetsizeColor(Z) );
00178     //glColor3f( (cubitOctreeNode[1][1][1])->GetsizeColor(X), (cubitOctreeNode[1][1][1])->GetsizeColor(Y), (cubitOctreeNode[1][1][1])->GetsizeColor(Z) );
00179     //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 );
00180     if( cubitOctreeNode[1][1][0]->get_color() != CUBIT_GREY_INDEX && cubitOctreeNode[1][1][1]->get_color() != CUBIT_GREY_INDEX ){
00181         //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)) );
00182     }
00183     
00184 }
00185 
00186 void CubitOctreeCell::display( CubitOctree *ptr_octree, int opt ){
00187   
00188   int i, j, k;
00189   
00190   if( is_leaf() == CUBIT_FALSE ){
00191     for( i = 0; i < 2; i++ ){
00192       for( j = 0; j < 2; j++ ){
00193         for( k = 0; k < 2; k++ ){
00194             //if( children[i][j][k] != NULL ){
00195           children[i][j][k]->display(ptr_octree, opt);
00196             //}
00197         }
00198       }
00199     }
00200   }
00201   else if (opt == 1)
00202   {
00203       // draw all cells in black wireframe mode
00204     //double corners[3];
00205     //double half_edge_length = get_dimension()/2.0;
00206     //CubitVector center = get_center();
00207     //center.get_xyz(corners);
00208     //double box[6] = {corners[0]-half_edge_length, corners[1]-half_edge_length, corners[2]-half_edge_length,
00209                     //corners[0]+half_edge_length, corners[1]+half_edge_length, corners[2]+half_edge_length};
00210     //SVDrawTool::draw_cube(box, CUBIT_BLACK_INDEX, SVDrawTool::WIRE);
00211     return;
00212   }
00213   else if (opt == 2)
00214   {
00215       // draw grey and black cells in black wireframe mode
00216       //(color == CUBIT_GREY_INDEX || color == CUBIT_BLACK_INDEX)
00217     if (color == CUBIT_BLACK_INDEX)
00218     {
00219       //double corners[3];
00220       //double half_edge_length = get_dimension()/2.0;
00221       //CubitVector center = get_center();
00222       //center.get_xyz(corners);
00223       //double box[6] = {corners[0]-half_edge_length, corners[1]-half_edge_length, corners[2]-half_edge_length,
00224                       //corners[0]+half_edge_length, corners[1]+half_edge_length, corners[2]+half_edge_length};
00225       //SVDrawTool::draw_cube(box, CUBIT_BLACK_INDEX, SVDrawTool::WIRE);
00226     }
00227     return;
00228   }
00229   else if (opt == 3)
00230   {
00231       // draw grey cells in white smoothshade mode
00232     if (color == CUBIT_GREY_INDEX)
00233     {
00234       //double corners[3];
00235       //double half_edge_length = get_dimension()/2.0;
00236       //CubitVector center = get_center();
00237       //center.get_xyz(corners);
00238       //double box[6] = {corners[0]-half_edge_length, corners[1]-half_edge_length, corners[2]-half_edge_length,
00239                       //corners[0]+half_edge_length, corners[1]+half_edge_length, corners[2]+half_edge_length};
00240       //SVDrawTool::draw_cube(box, CUBIT_WHITE_INDEX, SVDrawTool::SHADE);
00241       //SVDrawTool::draw_cube(box, CUBIT_BLACK_INDEX, SVDrawTool::WIRE);
00242     }
00243     return;
00244   }
00245   else if (opt == 4)
00246   {
00247     if (color != CUBIT_WHITE_INDEX)
00248     {
00249       //double corners[3];
00250       //double half_edge_length = get_dimension()/2.0;
00251       //CubitVector center = get_center();
00252       //center.get_xyz(corners);
00253       //double box[6] = {corners[0]-half_edge_length, corners[1]-half_edge_length, corners[2]-half_edge_length,
00254                       //corners[0]+half_edge_length, corners[1]+half_edge_length, corners[2]+half_edge_length};
00255       //SVDrawTool::draw_cube(box, CUBIT_WHITE_INDEX, SVDrawTool::SHADE);
00256       //SVDrawTool::draw_cube(box, CUBIT_BLACK_INDEX, SVDrawTool::WIRE);
00257     }
00258     return;
00259   }
00260   else if (opt == 5)
00261   {
00262       // draw grey and black cells in color wireframe mode
00263       if( color == CUBIT_GREY_INDEX || color == CUBIT_BLACK_INDEX )
00264           display_color_wireframe(ptr_octree);
00265       return;
00266   }
00267   else
00268     if( /*color == CUBIT_GREY_INDEX ||*/ color == CUBIT_BLACK_INDEX )
00269         display_color_wireframe(ptr_octree);
00270     return;
00271 }
00272 
00273 void CubitOctreeCell::release_octreefacetpointdata( void ){
00274 
00275   int i, j, k;
00276   
00277   if( is_leaf() == CUBIT_FALSE ){
00278     for( i = 0; i < 2; i++ ){
00279       for( j = 0; j < 2; j++ ){
00280         for( k = 0; k < 2; k++ ){
00281           children[i][j][k]->release_octreefacetpointdata( );
00282         }
00283       }
00284     }
00285   }
00286   else{
00287     int num_elm = octreeFacetPointDataList.size();
00288     for( i = 0; i < num_elm; i++ ){
00289       delete octreeFacetPointDataList.pop(); 
00290     }
00291   }
00292 }
00293 
00294  
00295 
00296 void CubitOctreeCell::display_octreefacetpointdata( void ){
00297 
00298   int i, j, k;
00299   
00300   if( is_leaf() == CUBIT_FALSE ){
00301     for( i = 0; i < 2; i++ ){
00302       for( j = 0; j < 2; j++ ){
00303         for( k = 0; k < 2; k++ ){
00304           children[i][j][k]->display_octreefacetpointdata( );
00305         }
00306       }
00307     }
00308   }
00309   else{
00310     for( i = 0; i < octreeFacetPointDataList.size(); i++ ){
00311       octreeFacetPointDataList.get_and_step()->display(); 
00312     }
00313   }
00314 }
00315 
00316 void CubitOctreeCell::set_oct_grid_node( const int i, const int j, const int k, CubitOctreeNode *ptr_node ){
00317   
00318   cubitOctreeNode[i][j][k] = ptr_node;
00319 }
00320 
00321 void CubitOctreeCell::set_child( int i, int j, int k, CubitOctreeCell *ptr_child_cell ){
00322   
00323   children[i][j][k] = ptr_child_cell;
00324   
00325 }
00326 
00327 CubitOctreeCell * CubitOctreeCell::get_child( const int i, const int j,const  int k ){
00328   
00329   return ( children[i][j][k] );
00330   
00331 }
00332 
00333 CubitOctreeCell * CubitOctreeCell::find_leaf_octree_cell(const CubitVector &point ){
00334   
00335   int i, j, k;
00336   
00337   if( is_leaf() == CUBIT_TRUE ){
00338     return this; 
00339   }
00340   else{
00341     
00342     i = j = k = 1;
00343     
00344     if( point.x() < mCenter.x() )
00345       i = 0; 
00346     
00347     if( point.y() < mCenter.y() )
00348       j = 0;
00349     
00350     if( point.z() < mCenter.z() )
00351       k = 0; 
00352 
00353     if (children[i][j][k] == NULL) {return NULL;}
00354     
00355     return children[i][j][k]->find_leaf_octree_cell( point );
00356     
00357   }
00358 }
00359 
00360 void CubitOctreeCell::distribute_facet_points_among_children( void ){
00361   int i;
00362   int l, m, n;
00363   
00364   OctreeFacetPointData *ptr_facet_point_data;
00365   
00366   octreeFacetPointDataList.reset();
00367   
00368   for( i = 0; i < octreeFacetPointDataList.size(); i++ ){
00369     
00370     ptr_facet_point_data = octreeFacetPointDataList.get_and_step();
00371  
00372     l = m = n = 1;
00373     
00374     if( ptr_facet_point_data->x() < mCenter.x() )
00375       l = 0; 
00376     
00377     if( ptr_facet_point_data->y() < mCenter.y() )
00378       m = 0;
00379     
00380     if( ptr_facet_point_data->z() < mCenter.z() )
00381       n = 0; 
00382     
00383     children[l][m][n]->append_list_item( ptr_facet_point_data );
00384     
00385   }
00386     // Clean the points and face list in the parent cell
00387   octreeFacetPointDataList.clean_out();
00388   
00389 }
00390 
00391 
00392 /*
00393   bool CubitOctreeCell::append_list_item( RefFace *ptr_Ref_face ){
00394   facetPointFaceList.push( ptr_Ref_face);
00395   return CUBIT_TRUE;
00396   }
00397 */
00398 bool CubitOctreeCell::append_list_item( OctreeFacetPointData *ptr_facet_point_data ){
00399   octreeFacetPointDataList.push( ptr_facet_point_data );
00400   return CUBIT_TRUE;
00401 }
00402 
00403 
00404 bool CubitOctreeCell::add_adjacent_unmarked_cells( DLIList< CubitOctreeCell *> &queue ){
00405 //optimized  
00406   static int i, j, k, l, m, n;
00407   static CubitOctreeNode *ptr_grid_node;
00408   static CubitOctreeCell *ptr_cell;
00409   static DLIList<CubitOctreeCell*> temp_list;
00410   
00411   for( i = 1; i >= 0; i-- ){
00412     for( j = 1; j >= 0; j-- ){
00413       for( k = 1; k >= 0; k-- ){
00414     
00415         ptr_grid_node = cubitOctreeNode[i][j][k];
00416           
00417         for( l = 0; l < 2; l++ ){
00418           for( m = 0; m < 2; m++ ){
00419             for( n = 0; n < 2; n++ ){
00420 
00421               ptr_cell = ptr_grid_node->get_adj_cell( l, m, n );
00422 
00423               if( ptr_cell != NULL )
00424               {
00425                 if( ptr_cell->mark == CUBIT_FALSE )
00426                 {
00427                     //queue.append( ptr_cell );
00428                   temp_list.append(ptr_cell);
00429                     // ptr_cell->set_mark( CUBIT_TRUE );
00430                   ptr_cell->mark = CUBIT_TRUE;
00431                                   
00432                 }
00433               }
00434               
00435             }
00436           }
00437         }
00438       }
00439     }
00440   }
00441   queue += temp_list;
00442   temp_list.clean_out();
00443   
00444   return CUBIT_TRUE;
00445 }
00446 
00447 bool CubitOctreeCell::is_intersects_box(const CubitBox &box ){
00448   
00449   double x_min, x_max, y_min, y_max, z_min, z_max;
00450   CubitVector box_min, box_max;
00451   int I, II, III, IV;
00452   
00453     //GfxDebug::draw_point( center.x(), center.y(), center.z(), CUBIT_RED_INDEX, itoa( num, buffer, 10 ) );
00454   
00455     // DEBUG:
00456     // changed from dimension -> dimenstion_2 
00457   double dimension_2 = dimension / 2.0;
00458   x_min = mCenter.x() - dimension_2;
00459   x_max = mCenter.x() + dimension_2;
00460   y_min = mCenter.y() - dimension_2;
00461   y_max = mCenter.y() + dimension_2;
00462   z_min = mCenter.z() - dimension_2;
00463   z_max = mCenter.z() + dimension_2;
00464   
00465   box_min = box.minimum();
00466   box_max = box.maximum();
00467   
00468     //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() );
00469     //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 );
00470   
00471     // A represent min of cell and B represent max of cell
00472     // C represent min of bbox and D represent max of bbox
00473     // A < C => I
00474     // B < C => II
00475     // A < D => III
00476     // B < D => IV
00477   
00478   I = II = III = IV = -1;
00479   if( x_max < box_min.x() ){
00480     II = 1; 
00481     I = 1;
00482   }
00483   else{
00484     if( x_min < box_min.x() ){
00485       I = 1;
00486     }
00487   }
00488   
00489   if( x_max <= box_max.x() ){
00490     III = 1;    
00491     IV = 1;
00492   }
00493   else{
00494     if( x_min <= box_max.x() ){
00495       III = 1;
00496     }
00497   }
00498   
00499   if( I * II == 1 && III * IV == 1 && I * III == 1 ){
00500       //PRINT_DEBUG_157(" X No Intersection \n");
00501     return CUBIT_FALSE;
00502   }
00503   
00504   
00505   
00506   I = II = III = IV = -1;
00507   if( y_max < box_min.y() ){
00508     II = 1; 
00509     I = 1;
00510   }
00511   else{
00512     if( y_min < box_min.y() ){
00513       I = 1;
00514     }
00515   }
00516   
00517   if( y_max <= box_max.y() ){
00518     III = 1;    
00519     IV = 1;
00520   }
00521   else{
00522     if( y_min <= box_max.y() ){
00523       III = 1;
00524     }
00525   }
00526   
00527   if( I * II == 1 && III * IV == 1 && I * III == 1 ){
00528       //PRINT_DEBUG_157(" Y No Intersection \n");
00529     return CUBIT_FALSE;
00530   }
00531   
00532   
00533   I = II = III = IV = -1;
00534   if( z_max < box_min.z() ){
00535     II = 1; 
00536     I = 1;
00537   }
00538   else{
00539     if( z_min < box_min.z() ){
00540       I = 1;
00541     }
00542   }
00543   
00544   if( z_max <= box_max.z() ){
00545     III = 1;    
00546     IV = 1;
00547   }
00548   else{
00549     if( z_min <= box_max.z() ){
00550       III = 1;
00551     }
00552   }
00553   
00554   if( I * II == 1 && III * IV == 1 && I * III == 1 ){
00555       //PRINT_DEBUG_157(" Z No Intersection \n");
00556     return CUBIT_FALSE;
00557   }
00558   
00559     //PRINT_DEBUG_157(" *********************** Intersection ************************* \n");
00560   return CUBIT_TRUE;
00561   
00562 }
00563 
00564 
00565 CubitBoolean CubitOctreeCell::is_facet_point_data_present( const CubitVector &coord ){
00566   
00567   OctreeFacetPointData *facet_point_data;
00568   int i;
00569   
00570   octreeFacetPointDataList.reset();
00571   for( i = 0; i < octreeFacetPointDataList.size(); i++ ){
00572     facet_point_data = octreeFacetPointDataList.get_and_step();
00573     if( (facet_point_data->coordinates() - coord ).length() < OCTREE_EPSILON ){
00574       return CUBIT_TRUE;
00575     }
00576   }
00577   return CUBIT_FALSE;
00578   
00579 }
00580 
00581 CubitBoolean CubitOctreeCell::is_facet_point_data_present( OctreeFacetPointData *new_facet_point_data ){
00582   
00583   OctreeFacetPointData *facet_point_data;
00584   int i;
00585   
00586   octreeFacetPointDataList.reset();
00587   for( i = 0; i < octreeFacetPointDataList.size(); i++ ){
00588     facet_point_data = octreeFacetPointDataList.get_and_step();
00589     if( facet_point_data->id() ==
00590         new_facet_point_data->id() ){
00591       return CUBIT_TRUE;
00592     }
00593   }
00594   return CUBIT_FALSE;
00595   
00596 }
00597 
00598 void CubitOctreeCell::coloring( /*DLIList<CubitOctreeCell *> &grey_cell_list ,*/ DLIList<CubitOctreeCell*> &black_cell_list )
00599 {
00600   int i,j,k;
00601   int grey, black;
00602 
00603   grey = FALSE;
00604   black = TRUE;
00605 
00606   if( leaf == CUBIT_TRUE ){
00607 
00608     for( i = 0; i < 2; i++ ){
00609       for( j = 0; j < 2; j++ ){
00610         for( k = 0; k < 2; k++ ){
00611           if( cubitOctreeNode[i][j][k]->get_color() != CUBIT_BLACK_INDEX )
00612           {
00613             black = FALSE;
00614           }
00615           else
00616           {
00617             grey = TRUE;
00618           }
00619         }
00620       }
00621     }
00622 
00623     if( black == TRUE )
00624     {
00625       color = CUBIT_BLACK_INDEX;
00626       black_cell_list.append(this);
00627     }
00628     else
00629       if( grey == TRUE ){
00630       color = CUBIT_GREY_INDEX;
00631       //grey_cell_list.push( this );
00632       }
00633       else
00634       {
00635         color = CUBIT_WHITE_INDEX; //constructor
00636       //return CUBIT_TRUE;
00637       }
00638     
00639   }
00640   else{
00641     for( i = 0; i < 2; i++ )
00642     {
00643       for( j = 0; j < 2; j++ )
00644       {
00645         for( k = 0; k < 2; k++ )
00646         {
00647           children[i][j][k]->coloring( /*grey_cell_list,*/ black_cell_list);
00648         }
00649       }
00650     }
00651   }
00652 
00653   //return CUBIT_FALSE;
00654   
00655 }
00656 
00657 
00658 CubitBoolean CubitOctreeCell::interpolate_grey_octreecell_node( void ){
00659 
00660   float avg_size;
00661   int counter;
00662   int i,j,k;
00663 
00664   avg_size = 0;
00665   counter = 0;
00666   for( i = 0; i < 2; i++ ){
00667     for( j = 0; j < 2; j++ ){
00668       for( k = 0; k < 2; k++ ){
00669           //if( cubitOctreeNode[i][j][k]->get_size( OCTREE_SIZE_DEFAULT ) != 0 && cubitOctreeNode[i][j][k]->get_size( OCTREE_SIZE_DEFAULT ) != CUBIT_DBL_MAX  ){
00670           //if( cubitOctreeNode[i][j][k]->get_size( OCTREE_SIZE_DEFAULT ) != 0.0 ){
00671         if (cubitOctreeNode[i][j][k]->get_color() == CUBIT_BLACK_INDEX)
00672         {
00673           avg_size += cubitOctreeNode[i][j][k]->get_size( OCTREE_SIZE_DEFAULT );
00674           counter++;
00675         }
00676           //}
00677       }
00678     }
00679   }
00680 
00681   if( counter == 0 ){
00682     return CUBIT_FALSE;
00683   } 
00684   
00685   avg_size /= counter;
00686 
00687   for( i = 0; i < 2; i++ ){
00688     for( j = 0; j < 2; j++ ){
00689       for( k = 0; k < 2; k++ ){
00690           //if( cubitOctreeNode[i][j][k]->get_color() == CUBIT_WHITE_INDEX ){
00691         if( cubitOctreeNode[i][j][k]->get_color() != CUBIT_BLACK_INDEX ){
00692             //if( cubitOctreeNode[i][j][k]->get_size( OCTREE_SIZE_DEFAULT ) == 0.0 ){
00693           cubitOctreeNode[i][j][k]->set_size( avg_size, OCTREE_SIZE_DEFAULT );
00694             //}
00695             //else{
00696             // cubitOctreeNode[i][j][k]->set_size( ( avg_size + cubitOctreeNode[i][j][k]->get_size( OCTREE_SIZE_DEFAULT ) ) / 2.0, OCTREE_SIZE_DEFAULT );
00697             //}                 
00698         }
00699           //}
00700       }
00701     }
00702   }
00703 
00704   return CUBIT_TRUE;
00705 }
00706 
00707 // Trilienar interpolation  
00708 // if number of nodes with zero size exceeds  MAX_NUM_ZERO_SIZE_NODES
00709 // then average size is used instead of zero
00710 // Even GREY grid nodes are consided 
00711 // If a node has zero size then that node is not considered
00712 // Therefore color is not important but the size
00713 double CubitOctreeCell::trilinear_interpolation(const CubitVector &point ){
00714   double size;
00715   int i, j, k;
00716   CubitVector center, min_corner, max_corner;
00717   double dim, dim_2;
00718   double Nx[2], Ny[2], Nz[2];
00719   double size_at_node;
00720   CubitOctreeNode *ptr_node;
00721 
00722     // Find Shape functions at eight grid nodes of a cell
00723   center = get_center();
00724   dim = get_dimension();
00725   dim_2  =  dimension / 2.0;
00726         
00727   min_corner.x( center.x() - dim_2 );
00728   min_corner.y( center.y() - dim_2 );
00729   min_corner.z( center.z() - dim_2 );
00730 
00731   max_corner.x( center.x() + dim_2 );
00732   max_corner.y( center.y() + dim_2 );
00733   max_corner.z( center.z() + dim_2 );   
00734             
00735   Nx[0] = ( max_corner.x() - point.x() ) / dim;
00736   Ny[0] = ( max_corner.y() - point.y() ) / dim;
00737   Nz[0] = ( max_corner.z() - point.z() ) / dim;
00738 
00739   Nx[1] = ( point.x() - min_corner.x() ) / dim;
00740   Ny[1] = ( point.y() - min_corner.y() ) / dim;
00741   Nz[1] = ( point.z() - min_corner.z() ) / dim;
00742 
00743     // Trilinear interpolation  
00744     // if number of nodes with zero size exceeds  MAX_NUM_ZERO_SIZE_NODES
00745     // then average size is used instead of zero
00746     
00747         
00748     // Interpolate using non-zero nodes
00749   size = 0.0;
00750 
00751   int zero_node_counter = 0;
00752 
00753   for( i = 0; i < 2; i++ ){
00754     for( j = 0; j < 2; j++ ){
00755       for( k = 0; k < 2; k++ ){
00756         ptr_node = get_octree_grid_node(i, j, k);
00757         size_at_node = ptr_node->get_size(OCTREE_SIZE_DEFAULT);
00758         if( size_at_node != 0.0 ){
00759           size +=  size_at_node * Nx[i] * Ny[j] * Nz[k];                  
00760         }
00761         else{
00762           if( ptr_node->find_size_using_adj_node() == CUBIT_TRUE ){
00763             size += ptr_node->get_size( OCTREE_SIZE_DEFAULT ) * Nx[i] * Ny[j] * Nz[k];
00764           }
00765           else{
00766             zero_node_counter ++;
00767           }
00768         }
00769       }
00770     }
00771   }
00772   
00773     // For interior of volume avg_size will not be calculated
00774     // as no zero size node exist
00775   if( zero_node_counter > MAX_NUM_ZERO_SIZE_NODES ){
00776 
00777       // Find Average size
00778     double avg_size = 0.0;
00779     int counter = 0;
00780 
00781     for( i = 0; i < 2; i++ ){
00782       for( j = 0; j < 2; j++ ){
00783         for( k = 0; k < 2; k++ ){
00784           size_at_node = get_octree_grid_node(i, j, k)->get_size(OCTREE_SIZE_DEFAULT);
00785           if( size_at_node != 0.0 ){
00786             avg_size +=  size_at_node;
00787             counter ++;
00788           }                 
00789         }
00790       }
00791     }
00792 
00793     if( counter > 0 ){
00794       avg_size /= counter;
00795             
00796         // use avg_size instead of zero during tri-linear interpolation
00797         // only at nodes with zero size
00798       for( i = 0; i < 2; i++ ){
00799         for( j = 0; j < 2; j++ ){
00800           for( k = 0; k < 2; k++ ){
00801             size_at_node = get_octree_grid_node(i, j, k)->get_size(OCTREE_SIZE_DEFAULT);
00802             if( size_at_node == 0.0 ){
00803               size +=  avg_size * Nx[i] * Ny[j] * Nz[k];                  
00804             }
00805           }
00806         }
00807       }
00808 
00809     }
00810     else{
00811       PRINT_DEBUG_157(" WARNING: Size of all nodes is zero \n" );
00812         //In size at a point default auto size will be used
00813         // autosize could be based on either average medial radius or
00814         // steve's autosize function
00815     }
00816   }
00817     
00818   return size;
00819 }
00820 
00821   // Using Separating Axis Theorem (Eberly)
00822   // Mostly used Moller's article to implement this code
00823 
00824 // returns true if intersection is present
00825 CubitBoolean CubitOctreeCell::does_facet_intersect_octreecell(CubitFacet *ptr_facet)
00826 {
00827   int i;
00828   
00829   CubitVector v0 = ptr_facet->point(0)->coordinates() - get_center(), v1 = ptr_facet->point(1)->coordinates() - get_center(),
00830       v2 = ptr_facet->point(2)->coordinates() - get_center();
00831 
00832   static CubitVector sep_axes[13];
00833   sep_axes[0] = ptr_facet->normal();
00834   sep_axes[1] = CubitVector(1,0,0);// note to self: optimize following trivial cross products
00835   sep_axes[2] = CubitVector(0,1,0);
00836   sep_axes[3] = CubitVector(0,0,1);
00837   sep_axes[4] = sep_axes[1]*(v1-v0);
00838   sep_axes[5] = sep_axes[1]*(v2-v1);
00839   sep_axes[6] = sep_axes[1]*(v0-v2);
00840   sep_axes[7] = sep_axes[2]*(v1-v0);
00841   sep_axes[8] = sep_axes[2]*(v2-v1);
00842   sep_axes[9] = sep_axes[2]*(v0-v2);
00843   sep_axes[10] = sep_axes[3]*(v1-v0);
00844   sep_axes[11] = sep_axes[3]*(v2-v1);
00845   sep_axes[12] = sep_axes[3]*(v0-v2);
00846 
00847   sep_axes[4].normalize();
00848   sep_axes[5].normalize();
00849   sep_axes[6].normalize();
00850   sep_axes[7].normalize();
00851   sep_axes[8].normalize();
00852   sep_axes[9].normalize();
00853   sep_axes[10].normalize();
00854   sep_axes[11].normalize();
00855   sep_axes[12].normalize();
00856 
00857   double rad_b, dot1, dot2, dot3, min_t, max_t;
00858   for (i=0; i < 13; ++i)
00859   {
00860 
00861       // rad_b is the "radius" of the projection of the cell onto the separating axis, centered about the projection of the cell's center
00862       // min_t and max_t are the extremes of the projection of the triangle onto the separating axis
00863     rad_b = (get_dimension() / 2.0) * (fabs(sep_axes[i].x()) + fabs(sep_axes[i].y()) + fabs(sep_axes[i].z()));
00864     dot1 = v0%sep_axes[i];
00865     dot2 = v1%sep_axes[i];
00866     dot3 = v2%sep_axes[i];
00867   
00868     min_t = CUBIT_MIN(CUBIT_MIN(dot1,dot2),dot3);
00869     max_t = CUBIT_MAX(CUBIT_MAX(dot1,dot2),dot3);
00870 
00871       // 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
00872       //if ( min_t > rad_b || max_t < -rad_b)
00873     if ( (min_t - rad_b) > 1e-6 || (-rad_b -max_t) > 1e-6)
00874     {
00875       // found a separating axis so facet and cell do not intersect
00876       return CUBIT_FALSE;
00877     }
00878   }
00879 
00880     // OctreeIntersectionData code was here
00881 
00882   return CUBIT_TRUE;
00883 }
00884 
00885 void CubitOctreeCell::set_color_and_intersection_datas(CubitFacet *ptr_facet, RefFace *ptr_Ref_face,
00886 #ifdef USE_octree_BGMESH
00887                                                   DLIList<CubitOctreeCell*> *greyCellList,
00888 #endif
00889                                                   CubitSense surf_sense)
00890 {
00891   int i, j, k;
00892   CubitVector facet_normal = ptr_facet->normal();
00893     //SVDrawTool::draw_vector(ptr_facet->center(),ptr_facet->center()+ptr_facet->normal(), CUBIT_MAGENTA_INDEX);
00894 /*  if( ptr_facet->is_backwards() ) // Ved: note to self - check this
00895     {
00896     facet_normal = facet_normal * -1;
00897     }*/
00898 
00899     // if (!myFacetList) {myFacetList = new DLIList</*CubitFacet*/OctreeIntersectionData*>;} uncomment later
00900 
00901 //    OctreeIntersectionData(CubitVector normal, int half_space, double len, RefFace *ptr_face, CubitVector closest_point_on_facet, CubitFacet *lp_facet);
00902 
00903 /*  CubitVector dummy;
00904     OctreeIntersectionData *new_idata = new OctreeIntersectionData(dummy, 1, 0.0, ptr_Ref_face, dummy, ptr_facet);
00905     myFacetList->append(new_idata);*/ // uncomment later
00906 
00907     /* if (!myFaceList) {myFaceList = new DLIList<RefFace*>;}
00908        if (!myFaceList->where_is_item(ptr_Ref_face))
00909        {
00910        myFaceList->append(ptr_Ref_face);
00911        }*/
00912 
00913     // bool merged = (CAST_TO(ptr_Ref_face, RefFace)->num_parent_ref_entities() == 2);
00914 
00915   for (i=0; i < 2; ++i)
00916   {
00917     for (j=0; j < 2; ++j)
00918     {
00919       for (k=0; k < 2; ++k)
00920       {
00921         CubitVector closest_point_on_facet;
00922         double dist_to_facet;
00923         if (defaultDistanceMetric == CAPSULE_DIST) {dist_to_facet = CubitOctree::capsule_distance_to_facet(cubitOctreeNode[i][j][k]->get_coord(), ptr_facet, closest_point_on_facet);}
00924         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);}
00925        
00926           /*if (dist_to_facet < 0)
00927             {
00928               //PRINT_INFO("Invalid distance: %lf !!!!\n", dist_to_facet);
00929                 //SVDrawTool::draw_point(cubitOctreeNode[i][j][k]->get_coord(), CUBIT_MAGENTA_INDEX);
00930           
00931                   //double test_dist = CubitOctree::capsule_distance_to_facet(cubitOctreeNode[i][j][k]->get_coord(), ptr_facet, closest_point_on_facet);
00932                   }*/
00933 
00934         OctreeIntersectionData *idata;
00935         
00936         if (/*merged == CUBIT_TRUE*/ surf_sense == CUBIT_UNKNOWN)
00937         {
00938           CubitVector temp_facet_normal = facet_normal;
00939           
00940           if (cubitOctreeNode[i][j][k]->get_halfspace_direction() == OCTREE_NEGATIVE)
00941           {
00942             temp_facet_normal *= -1.0;
00943           }
00944 
00945           
00946 //          SVDrawTool::draw_point(cubitOctreeNode[i][j][k]->get_coord(), CUBIT_MAGENTA_INDEX);
00947           
00948           idata = new OctreeIntersectionData(temp_facet_normal, OCTREE_NEGATIVE, dist_to_facet, ptr_Ref_face, closest_point_on_facet, ptr_facet);
00949           idata->set_merged(1);
00950         }
00951         else
00952         {
00953           CubitVector temp_facet_normal = facet_normal;
00954           CubitBoolean temp_half_space = cubitOctreeNode[i][j][k]->get_halfspace_direction();
00955           if (surf_sense == CUBIT_FORWARD) {temp_facet_normal *= -1.0;}
00956           else if (surf_sense == CUBIT_REVERSED) {temp_half_space = !temp_half_space;}
00957           idata = new OctreeIntersectionData(temp_facet_normal, temp_half_space, dist_to_facet, ptr_Ref_face, closest_point_on_facet, ptr_facet);
00958         }
00959         
00960 //        idata->set_facet_ptr(ptr_facet);
00961 //        idata->set_int_point(closest_point_on_facet);
00962         cubitOctreeNode[i][j][k]->append_list_item(idata);
00963       }
00964     }
00965   }
00966 
00967   color = CUBIT_GREY_INDEX;
00968   
00969 #ifdef USE_octree_BGMESH
00970   if (!visit)
00971   {
00972     greyCellList->append(this); // for background mesh generation
00973     visit = CUBIT_TRUE;
00974   }
00975 #endif
00976   
00977 }
00978 
00979 CubitBoolean CubitOctreeCell::does_contain_positive_and_negative_nodes( void ){
00980   int i, j, k;
00981   CubitBoolean positive_space = CUBIT_FALSE;
00982   CubitBoolean negative_space = CUBIT_FALSE;
00983  
00984   for( i = 0; i < 2; i++ ){
00985     for( j = 0; j < 2; j++ ){
00986       for( k = 0; k < 2; k++ ){
00987         if( cubitOctreeNode[i][j][k]->get_halfspace_direction() == OCTREE_POSITIVE )
00988           positive_space = CUBIT_TRUE;
00989         else
00990           negative_space = CUBIT_TRUE;
00991       }
00992     }
00993   }
00994 
00995   if( positive_space == CUBIT_TRUE && negative_space == CUBIT_TRUE ){
00996     return CUBIT_TRUE;
00997   }
00998   else{
00999     return CUBIT_FALSE;
01000   }
01001 }
01002 
01003 double CubitOctreeCell::inverse_distance_interpolation(const CubitVector &point ){
01004   double size;
01005   long double denominator=0;
01006   long double nominator=0;
01007   double weight;
01008   long double dist_func;
01009   CubitVector node_coord;
01010   double dist;
01011   int i, j, k;
01012   int type = DEFAULT_INVERSE_DISTANCE_SCHEME_INSIDE_CELL; 
01013   
01014   
01015   for( i = 0; i < 2; i++ ){
01016     for( j = 0; j < 2; j++ ){
01017       for( k = 0; k < 2; k++ ){
01018         if(  get_octree_grid_node(i, j, k)->get_size(OCTREE_SIZE_DEFAULT) != 0.0 ){
01019           node_coord = get_octree_grid_node(i, j, k)->get_coord();
01020             
01021           dist = ( node_coord - point  ).length();
01022             
01023           if( dist < OCTREE_EPSILON )
01024             dist = OCTREE_EPSILON;
01025             
01026           switch( type ){
01027               
01028             case INVERSE_LINEAR:
01029                 dist_func = dist;
01030                 break;
01031               
01032             case INVERSE_QUADRATIC:
01033                 dist_func = dist * dist;
01034                 break;
01035               
01036             case INVERSE_CUBIC:
01037                 dist_func = dist * dist * dist;
01038                 break;
01039               
01040             default:
01041                 dist_func = dist * dist;
01042           }
01043             
01044           denominator += 1.0 / ( dist_func );
01045         }
01046       }
01047     }
01048   }
01049   
01050   size = 0.0;
01051   
01052   for( i = 0; i < 2; i ++ ){
01053     for( j = 0; j < 2; j++ ){
01054       for( k = 0; k < 2; k++ ){
01055         if(  get_octree_grid_node(i, j, k)->get_size(OCTREE_SIZE_DEFAULT) != 0.0 ){
01056           node_coord = get_octree_grid_node(i,j,k)->get_coord();
01057             
01058           dist = ( node_coord - point  ).length();
01059             
01060           if( dist < OCTREE_EPSILON )
01061             dist = OCTREE_EPSILON;
01062             
01063           switch( type ){
01064               
01065             case INVERSE_LINEAR:
01066                 dist_func = dist;
01067                 break;
01068               
01069             case INVERSE_QUADRATIC:
01070                 dist_func = dist * dist;
01071                 break;
01072               
01073             case INVERSE_CUBIC:
01074                 dist_func = dist * dist * dist;
01075                 break;
01076             default:
01077                 dist_func = dist * dist;
01078           }
01079             
01080           nominator = 1.0 / ( dist_func );
01081             
01082           weight = nominator / denominator ;
01083         
01084           size +=  get_octree_grid_node(i,j,k)->get_size( OCTREE_SIZE_DEFAULT ) * weight; 
01085             //PRINT_DEBUG_157(" size at grid node = %f\n",get_octree_grid_node(i,j,k)->get_size( OCTREE_SIZE_DEFAULT ));
01086         }             
01087       }
01088     }
01089   } 
01090 
01091   return size;
01092 }
01093 
01094 
01095 double CubitOctreeCell::min_distance_interpolation(const CubitVector &point )
01096 {
01097   double size;
01098   CubitVector node_coord;
01099   double dist;
01100   int i, j, k;
01101   
01102   double min_dist = CUBIT_DBL_MAX;
01103  
01104   size = 0.0;
01105 
01106   for( i = 0; i < 2; i++ ){
01107     for( j = 0; j < 2; j++ ){
01108       for( k = 0; k < 2; k++ ){
01109         if(  get_octree_grid_node(i, j, k)->get_size(OCTREE_SIZE_DEFAULT) != 0.0 )
01110         {
01111           node_coord = get_octree_grid_node(i, j, k)->get_coord();
01112             
01113           dist = ( node_coord - point  ).length();
01114             
01115           if( dist < OCTREE_EPSILON )
01116             dist = OCTREE_EPSILON;
01117             
01118           if( dist < min_dist )
01119           {
01120             min_dist = dist;
01121             size = get_octree_grid_node(i,j,k)->get_size( OCTREE_SIZE_DEFAULT );
01122           }          
01123         }
01124       }
01125     }
01126   }
01127   
01128   return size;
01129 }
01130 
01131 
01132 
01133 double CubitOctreeCell::min_size_interpolation(const CubitVector &point ){
01134 
01135   CubitVector node_coord;
01136   int i, j, k;
01137   
01138   double min_size = CUBIT_DBL_MAX;
01139   double size;
01140  
01141  
01142 
01143   for( i = 0; i < 2; i++ ){
01144     for( j = 0; j < 2; j++ ){
01145       for( k = 0; k < 2; k++ ){
01146         if(  get_octree_grid_node(i, j, k)->get_size(OCTREE_SIZE_DEFAULT) != 0.0 )
01147         {
01148           size = get_octree_grid_node(i,j,k)->get_size( OCTREE_SIZE_DEFAULT );
01149             
01150           if( size < OCTREE_EPSILON )
01151             size = OCTREE_EPSILON;
01152             
01153           if( size < min_size )
01154           {
01155             min_size = size;            
01156           }          
01157         }
01158       }
01159     }
01160   }
01161   
01162   return min_size;
01163 }
01164 
01165 CubitStatus CubitOctreeCell::find_indices_in_parent( int *index ){
01166 
01167   int i, j, k;
01168     
01169   for( i = 0; i < 2; i++ ){
01170     for( j = 0; j < 2; j++ ){
01171       for( k = 0; k < 2; k++ ){
01172         if( parent->get_child( i, j, k )->id() == num ){
01173           index[0] = i;
01174           index[1] = j;
01175           index[2] = k;
01176           return CUBIT_SUCCESS;
01177         }
01178       }
01179     }
01180   }
01181 
01182   return CUBIT_FAILURE;
01183 }
01184 
01185 
01186 #ifndef NDEBUG
01187 void CubitOctreeCell::write_octreecell_sizing_info_file( FILE *pof, DLIList<CubitOctreeCell*> &stack ){
01188     
01189   int index[3];
01190   int i, j, k;
01191 
01192   if( parent == NULL ){
01193     fprintf( pof, "C %d -1 0 0 0 %d\n", num, !leaf );
01194   }
01195   else{
01196     find_indices_in_parent( index );
01197     fprintf( pof, "C %d %d %d %d %d %d \n", num, parent->id(), index[0], index[1], index[2], !leaf );
01198   }
01199     
01200 
01201   fprintf( pof, "V");
01202   for( i = 0; i < 2; i++ ){
01203     for( j = 0; j < 2; j++ ){
01204       for( k = 0; k < 2; k++ ){
01205         fprintf( pof," %d ", cubitOctreeNode[i][j][k]->get_num() );
01206       }
01207     }
01208   } 
01209   fprintf( pof, "\n");
01210 
01211   if( leaf == 0 ){  
01212     fprintf( pof, "H");
01213     for( i = 0; i < 2; i++ ){
01214       for( j = 0; j < 2; j++ ){
01215         for( k = 0; k < 2; k++ ){
01216           fprintf( pof," %d ", children[i][j][k]->id() );
01217           stack.append( children[i][j][k] );
01218         }
01219       }
01220     }   
01221     fprintf( pof, "\n");
01222   }
01223     
01224   fprintf( pof, "E\n");
01225 }
01226 #endif
01227 
01228 
01229 //EOF
01230 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines