cgma
CubitOctree.hpp
Go to the documentation of this file.
00001 //-------------------------------------------------------------------------
00002 // Filename      : CubitOctree.hpp
00003 //CubitOctree
00004 // Purpose       : CubitOctree model of the input solids/surfaces is generated. 
00005 //                 
00006 //
00007 // Creator       : William Roshan Quadros
00008 //
00009 // Creation Date :  09/01/2013
00010 //
00011 // Owner         : 
00012 //-------------------------------------------------------------------------
00013 #ifndef CUBITOCTREE_H
00014 #define CUBITOCTREE_H
00015 
00016 #include "CubitVector.hpp"
00017 #include "CubitOctreeConstants.hpp"
00018 #include "DLIList.hpp"
00019 #include "CubitDefines.h"
00020 
00021 
00022 class RefVolume;
00023 class RefVolume;
00024 class RefFace;
00025 class RefEdge;
00026 class RefVertex;
00027 
00028 
00029 class CubitOctreeNode;
00030 class CubitOctreeCell;
00031 class FaceAdjacency;
00032 class VertexFaceIncident;
00033 class CubitFacet;
00034 class CubitFacetEdge;
00035 class FacetEntity;
00036 class CubitPoint;
00037 class CubitBox;
00038 class TDSkeletonCubitPoint;
00039 class CubitOctreeGenerator;
00040 class OctreeFacetPointData;
00041 
00042 
00043 // Generation of CubitOctree model of the CAD model:
00044 // Graphics Facets are used to detect curvature changes in surface and curves.
00045 // Vertices and Centroid of the Facets are used to generate the CubitOctree.
00046 // Bounding Box of the facets, Edge Length etc can be used.
00047 // Each Cell is made to contain only one point.
00048 
00049 class CubitOctree
00050 {
00051   
00052 public:
00053      
00054   CubitOctree( CubitOctreeGenerator *lattice_gen );
00055     //- Constructor
00056   
00057   virtual ~CubitOctree();
00058     //- Distructor
00059 
00060   void release_memory( void );
00061     //- clears the memory for assembly
00062 
00063   inline int get_max_depth( void){ return maxDepth;}
00064   inline int get_min_depth( void){ return minDepth;}
00065   inline void set_max_depth( int max_depth ) { maxDepth = max_depth; }
00066   inline void set_min_depth( int min_depth ) { minDepth = min_depth; }
00067   
00068   inline DLIList<CubitOctreeNode*> *get_whitenodelist( void ){ return &boundaryWhiteGridNodeList; }
00069 
00070   inline DLIList<CubitOctreeCell*> *get_greycelllist( void ){ return &greyCellList; }
00071   
00072   inline DLIList<CubitOctreeCell*> *get_blackcelllist() {return &blackCellList;}
00073 
00074   inline DLIList<CubitOctreeNode*> *get_gridnodevector( void ){ return &gridNodeVector; }
00075 
00076   inline void set_status_octree_coloring( CubitBoolean type ){ statusCubitOctreeColoring = type; }
00077   
00078   // Methods related to CubitOctree Generation 
00079   inline CubitOctreeCell *get_root( void ){ return root; }
00080 
00081   void color_octreecell( void );
00082   //- NOTE: during CubitOctree generation only the points at the facets are marked white and black
00083   //- during mat generation whole interior points are colored BLACK and the later the cells' are colored
00084   //- Identifies boundary (GREY), interior (BLACK) and exterior cells (WHITE)
00085   
00086   
00087   CubitOctreeCell *find_octreecell( const CubitVector &pnt );
00088   //- Returns a cell containing point pnt
00089   
00090   CubitBoolean initialize_octree_generation( void );
00091   //- Initializes the root cell which is equal to bbox
00092   
00093   CubitBoolean build_octree_till_min_depth( CubitOctreeCell *ptr_cell );
00094   //- Builds the CubitOctree till the minimum depth
00095   
00096   CubitBoolean subdivide_octree_cell( CubitOctreeCell *ptr_cell, DLIList<CubitOctreeNode*> *ptr_queue, int max_depth);
00097   //- subdivides the cell
00098   
00099   CubitBoolean subdivide_octree_based_on_facet_point( OctreeFacetPointData *ptr_facet_point_data, int max_depth );
00100   //- use the facet center and vertices to subdivide the CubitOctree
00101   
00102   double size_at_a_point( const CubitVector &point, int size_type );
00103 
00104   CubitPointContainment point_containment( CubitVector tmp_vec, double tolerance );
00105   
00106   
00107   inline double get_max_size_grid_node( void ){ return maxSizeGridNode; }
00108   //- Returns maximum size
00109   
00110   inline double get_min_size_grid_node( void ) const{ return minSizeGridNode; }
00111   //- Returns minimum size
00112   
00113   void display( const int mode, int opt = 0 );
00114   //- Display of CubitOctree
00115   
00116   
00117   // For better 3D medial resolution near adjacent surfaces with a large dihedral angle (outward normals) between them,
00118   // CubitOctree cells intersecting with the shared curve can be refined to the maximum allowable depth.
00119   // First call find_cells... to build the list of cells to refine, then call refine_cells_to_target_depth on them
00120   CubitBoolean find_cells_based_on_surface_angle(DLIList<CubitOctreeCell*> &refine_cell_list, DLIList<CubitFacetEdge*> &crease_edges,
00121                                                  DLIList<CubitFacet*> &crease_facets, RefFace *one, RefFace *two,
00122                                                  const CubitBoolean draw_facets=CUBIT_FALSE, double dihedral_angle_thresh=CUBIT_PI/2.0);
00123   
00124   
00125   CubitBoolean find_octree_cells_contained_inside_bbox( CubitFacet *ptr_facet, DLIList<CubitOctreeCell*> &CubitOctree_cell_list );
00126   
00127   //- output: CubitOctree cells which intersect with the bbox are stored in CubitOctree_cell_list
00128   
00129   CubitBoolean mark_positive_and_negative_octree_grid_nodes( CubitFacet *ptr_facet, DLIList<CubitOctreeCell*> &CubitOctree_cell_list, DLIList< CubitOctreeNode *> &CubitOctree_grid_node_list );
00130   
00131   //- output: the nodes of cells that intersect with the bbox are stored in octee_cell_list
00132   
00133   CubitBoolean find_intersection_between_grid_edges_and_facet( CubitOctreeType type, RefFace *ptr_face, CubitFacet *ptr_facet, DLIList<CubitOctreeNode *> &CubitOctree_grid_node_list  );
00134   //- finds intersection between line segment (edge ) incident at every grid_node contained inside bbox and triangle ( facet)
00135   
00136   
00137   void find_cell_list_intersecting_line_segment(const CubitVector &p0, const CubitVector &p1, DLIList<CubitOctreeCell*> &cell_list);
00138   //- returns the list of CubitOctree cells intersecting with line segment defined by end points
00139   
00140   double get_scaled_from_wrld_size_grid_node( double wrld_size );
00141 
00142   
00143   static double capsule_distance_to_facet(const CubitVector &point, CubitFacet *lp_facet, CubitVector &int_point, CubitBoolean use_projection_only = CUBIT_FALSE);
00144   
00145   CubitBoolean establish_smooth_transition_of_cells( int max_depth ); 
00146 
00147 private:
00148   
00149   inline CubitBoolean apd_vector_item( CubitOctreeNode *ptr_grid_node );
00150     //- appends the ptr_grid_node in the CubitOctreeNodeList
00151   
00152   double calculate_depth_based_on_size( double size );
00153 
00154   inline double get_bbox_dimension( void ){ return bboxDimension; }
00155 
00156   
00157   
00158   void refine_cells_to_target_depth(DLIList<CubitOctreeCell*> &refine_cell_list, const int target_depth);
00159 
00160     // To optimize intersection between facet and CubitOctree cells, all the cells not intersecting with the plance containing facet are removed
00161     // The nodes are marked with +ve or -ve half space info before calling this function
00162   CubitBoolean mark_cells_that_intersect_facet_plane( /*CubitFacet *ptr_facet,*/ DLIList<CubitOctreeCell*> &CubitOctree_cell_list );
00163   
00164     // Stores the CubitOctree cells intersecting with the facet
00165   CubitBoolean unmark_octree_cells_not_intersecting_with_facet( CubitFacet *ptr_facet, DLIList<CubitOctreeCell *> &CubitOctree_cell_list );
00166 
00167     //- CubitOctree is subdivided till skeleton max depth if size or scope of source entity is less than the dimention of
00168     //- the cell containing it.
00169 
00170   CubitBoolean subdivide_octree_from_leaf_cell( CubitOctreeCell *ptr_cell, OctreeFacetPointData *ptr_facet_point_data, int max_depth );
00171  
00172     //- subdivides the CubitOctree starting from ptr_cell such that the ptr_new_point is contained in a uniue cell
00173     //- if the maxDepth is not reached.
00174 
00175   void gather_initial_grid_nodes_for_smooth_transition( DLIList<CubitOctreeNode *> &queue );
00176     //- queue hold potential nodes which has more than or equal to 2 cell depth difference
00177  
00178   
00179     //- establishes smooth transition by keeping adjacent cells differing by 1 level
00180   
00181     //CubitBoolean find_intersection_between_octree_and_facets( DLIList<CubitOctreeNode *> &queue_for_mat_generation );
00182     //- Finds the intersection between the CubitOctree line segments and the facets
00183 
00184   void reset_internal_node_size( float value, int type );
00185     //- Resets the node size with value  
00186     
00187   void find_radius_at_boundary_node( void );
00188     
00189  
00190 
00191   void find_max_min_size_grid_node_for_scaling( void );
00192     //- Finds maximum and minimum size used for scaling.
00193 
00194 
00195   
00196    static CubitStatus circumcenter(CubitVector &a, CubitVector &b, CubitVector &c, CubitVector &center, double &radius);
00197     /*  
00198         void build_boundary_white_node_list( void );
00199           //- Uses grey CubitOctrees to find white boundary grid nodes;
00200           */
00201 
00202 
00203   void prepare_for_background_mesh();
00204     // performs necessary actions on CubitOctree to make way for background mesh
00205 
00206 #ifndef NDEBUG 
00207 
00208   void write_sizing_info_file( const char *file_name );
00209     //- Writes sizing function at grid nodes to a file
00210 
00211   void write_octree_sizing_info_file( const char *file_name );
00212     //- Writes sizing function stored in the CubitOctree on to a file.
00213 
00214   void write_matlab_sizing_info_file( const char *file_name );
00215     //- Writes sizing function stored in the CubitOctree for visualization in matlab
00216 
00217 #endif
00218   
00219 private:
00220     
00221   CubitBoolean statusCubitOctreeColoring;
00222   
00223 
00224     //- Maximum and minimum radius of source points and grid node
00225     //- this is used in scaling the source points between 1 and 10 for display purpose
00226         
00227   double bboxMinY; // minY
00228   double bboxMaxY; // maxY
00229   double bboxMaxZ; // maxZ
00230   double bboxMinZ; // minZ 
00231   double bboxMaxX; // maxX 
00232   double bboxMinX; // minX
00233     //- Limits of the bounding box of the volume
00234  
00235   CubitOctreeCell *root;
00236     //- Root of the CubitOctree
00237   
00238   CubitVector bboxCenter;
00239     //- Center of the bounding box
00240   
00241   double bboxDimension;
00242     //- Dimension of the bounding box
00243   
00244   double epsilonBBox;
00245     //- Actual bounding box is enlarged by epsilon_bbox in all directions
00246    
00247   DLIList<CubitOctreeCell *> greyCellList;
00248     //- List of boundary CubitOctrees
00249 
00250   DLIList<CubitOctreeCell*> blackCellList;
00251     //- List of internal CubitOctree cells
00252   
00253   DLIList<CubitOctreeNode *> boundaryWhiteGridNodeList;
00254     //- List of white nodes of grey cells
00255   
00256   DLIList <CubitOctreeNode *> gridNodeVector;
00257     //- Grid Nodes of CubitOctree
00258 
00259   DLIList <CubitOctreeNode*> greyGridNodeVector;
00260   
00261     
00262   CubitOctreeGenerator *cubitOctreeGenerator;
00263 
00264 
00265   double maxSizeGridNode;
00266   double minSizeGridNode;
00267   
00268   int minDepth;
00269   int maxDepth;
00270 
00271 };
00272 
00273 #endif
00274     
00275 //EOF
00276 
00277 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines