cgma
FacetDataUtil.hpp
Go to the documentation of this file.
00001 //- Class:       FacetDataUtil
00002 //- Description: static library of general functions for querying and/or modifying
00003 //-              facet entities
00004 //- Owner:       Steve Owen
00005 //- Checked by:
00006 //- Version:
00007 
00008 #ifndef __FACETDATAUTIL__
00009 #define __FACETDATAUTIL__
00010 
00011 #include "DLIList.hpp"
00012 #include "RTree.hpp"
00013 
00014 class CubitPoint;
00015 class CubitFacet;
00016 class CubitFacetEdge;
00017 class CubitQuadFacet;
00018 class FacetEntity;
00019 class CubitVector;
00020 class CubitBox;
00021 
00022 class FacetDataUtil
00023 {
00024 public:
00025   // get edges from a facet list that are common to "count" facets
00026   // For example, passing in:
00027   //   count = 1 returns the boundary edges of a set of facets
00028   //   count = 2 returns the interior, manifold edges of a set of facets
00029   //   count = n>2 returns non-manifold edges shared by n facets
00030   //
00031   static void edges_by_count(DLIList<CubitFacet*> &facets,
00032                                            unsigned int count,
00033                                            DLIList<CubitFacetEdge*> &edges);
00034 
00035   // get an ordered list of points and edges around the boundary of a set of facets
00036   // The output "chain" consists of point - edge - point - edge - ... around the
00037   // boundary of the input facets.  Having the ordered points as well as the edges
00038   // helps provides sense information for the bounding edges.
00039   static void ordered_point_edge_bdry(DLIList<CubitFacet*> &facets,
00040                                       DLIList<FacetEntity*> &point_edge_chain);
00041 
00042   // given an ordered point - edge boundary and a start and end point on the boundary,
00043   // return the point - edge chain between the two points, inclusive.
00044   static CubitStatus partial_chain(DLIList<FacetEntity*> &point_edge_chain,
00045                                    FacetEntity* point1,
00046                                    FacetEntity* point2,
00047                                    DLIList<FacetEntity*> &chain_between);
00048 
00049   // given a set of facets, get the unique list of points used to define the facets.
00050   static void get_facet_points(DLIList<CubitFacet*> &cubit_facets,
00051                                DLIList<CubitPoint*> &facet_points);
00052 
00053   // given a set of facets, return an unordered list of points at its boundary
00054   static void get_boundary_points(DLIList<CubitFacet*> &facet_list,
00055                                   DLIList<CubitPoint*> &point_list);
00056 
00057   // return an unordered list of edges at the boundary of a set of facets
00058   static void get_boundary_edges(DLIList<CubitFacet*> &facet_list,
00059                                  DLIList<CubitFacetEdge*> &edge_list);
00060 
00061   // get the unique set of points from a facet list
00062   static void get_points( DLIList<CubitFacet*> &facet_list,
00063                           DLIList<CubitPoint*> &point_list);
00064 
00065   // make a complete copy of facets and points
00066   static void copy_facets(DLIList<CubitFacet*> &old_facet_list,
00067                           DLIList<CubitFacet*> &new_facet_list,
00068                           DLIList<CubitPoint*> &new_point_list,
00069                           DLIList<CubitFacetEdge*> &new_edge_list );
00070 
00071   // populates the edge list from the list of facets - creates the
00072   // edges if necessary
00073   static void get_edges( DLIList<CubitFacet *> &facet_list,
00074                          DLIList<CubitFacetEdge *> &edge_list );
00075 
00076   // compute the quality of a triangle defined by three vertices
00077   static double quality(CubitVector &c1, CubitVector &c2, CubitVector &c3,
00078                               CubitVector &surf_normal);
00079 
00080   // collapse edges that are shorter than 10% of the average edge length
00081   static CubitStatus collapse_short_edges( DLIList<CubitFacet*> &facet_list,
00082                                            CubitBoolean non_manifold_only );
00083 
00084   static void check(DLIList<CubitFacetEdge *> &edge_list,
00085                     DLIList<CubitFacet *> &facet_list);
00086 
00087   static void draw_edge( CubitFacetEdge *edge );
00088 
00089   static int edge_compare(CubitFacetEdge *&ea, CubitFacetEdge *&eb);
00090 
00091   // for triangulated, manifold, non-self-intersecting polyhedra
00092   static CubitStatus is_point_in_polyhedron(DLIList<CubitFacet *> &tfacet_list,
00093                                      CubitVector &point_coords,
00094                                      CubitPointContainment &is_point_in);
00095 
00096   //  can return CUBIT_FAILURE if triangles are very thin
00097   //  used by is_point_in_polyhedron()
00098   static CubitStatus pt_in_tri_2d(double xpt, double ypt,
00099                        double x0, double y0,
00100                double x1, double y1,
00101                double x2, double y2,
00102                CubitPointContainment &is_point_in);
00103 
00104 
00105   //  Returns a normalized ray always pointing in the (+++) direction.
00106   //  used by is_point_in_polyhedron()
00107   static void random_positive_ray(CubitVector& ray);
00108 
00109   //  used by is_point_in_polyhedron()
00110   static bool ray_intersects_boundingbox(CubitVector& point, CubitVector& ray, const CubitBox& bbox);
00111 
00112   // write a facet list to a facet file
00113   static CubitStatus write_facets( const char *file_name,
00114                                    DLIList<CubitFacet *> &facet_list);
00115 
00116   // group facets into continuous lists
00117   static CubitStatus split_into_shells( DLIList<CubitFacet *> &tfacet_list,
00118                                  DLIList<CubitQuadFacet *> &qfacet_list,
00119                                  DLIList<DLIList<CubitFacet *> *> &shell_list,
00120                                  CubitBoolean &is_water_tight);
00121 
00122   // attempt to stitch up the model to make water-tight
00123   static CubitStatus stitch_facets( DLIList<DLIList<CubitFacet *> *> &shell_list,
00124                              double tol, CubitBoolean &is_water_tight,
00125                              CubitBoolean write_results = CUBIT_TRUE);
00126 
00127   // delete a list of facets and their child facet entities
00128   static void delete_facets(DLIList<DLIList<CubitFacet*>*> &shell_list);
00129   static void delete_facets(DLIList<CubitFacet*> &facet_list);
00130   static void delete_facet(CubitFacet *facet_ptr);
00131   static void destruct_facet_no_delete(CubitFacet *facet_ptr);
00132   
00133 
00134   // determine intersection of a segment with a facet
00135   // returns CUBIT_PNT_UNKNOWN: if segment is in plane of facet
00136   //         CUBIT_PNT_OUTSIDE: if segment does not intersect
00137   //         CUBIT_PNT_INSIDE: if segment intersects inside facet
00138   //         CUBIT_PNT_BOUNDARY: if segment intersects a vertex or edge
00139   static CubitPointContainment intersect_facet(CubitVector &start, CubitVector &end,
00140                                                CubitFacet *facet_ptr,
00141                                                CubitVector &qq,
00142                                                CubitVector &ac,
00143                                                CubitBoolean bound = CUBIT_TRUE);
00144 
00145    //  get axis-aligned bounding box of list of points
00146   static CubitStatus get_bbox_of_points(DLIList<CubitPoint*>& point_list, CubitBox& bbox);
00147 
00148   //  get square of distance from point to closest point on a line segment;
00149   //  returns closest point.
00150   static CubitVector squared_distance_to_segment(CubitVector &p, 
00151                                                   CubitVector &p0, 
00152                                                   CubitVector &p1,
00153                                                   double &distance2);
00154 
00155   //  Get the intersection of the line defined by point1 and point2 with
00156   //  bbox.  Returns 0,1 or 2 for the number of intersections.  A line
00157   //  in one of the planes of the box will return 0.
00158   static int get_bbox_intersections(CubitVector& point1,
00159                                     CubitVector& point2,
00160                                     const CubitBox& bbox,
00161                                     CubitVector& intersection_1,
00162                                     CubitVector& intersection_2);
00163   
00164   // mark facets and their children
00165   static void mark_facets( DLIList<FacetEntity *> &facet_list, int mark_value );
00166   
00167   // used with stitch_facets to merge points that are coincident
00168   static CubitStatus merge_coincident_vertices( DLIList<DLIList<CubitFacet *> *> &shell_list,
00169                                          double tol,
00170                                          int &mpmerge,
00171                                          int &nemerge,
00172                                          DLIList<CubitPoint *> &unmerged_points);  
00173 
00174   static CubitStatus merge_coincident_vertices( DLIList<CubitPoint*> &points );
00175   
00176   // used with stitch_facets to merge two points together that have already been
00177   // determined to be coincident.  Also handles their adjacent edges
00178   static CubitStatus merge_points( CubitPoint *pt0, CubitPoint *pt1, int &nemerge, 
00179                                     RTree<CubitFacetEdge*> *r_tree=NULL);
00180 
00181   static CubitStatus find_facet(  DLIList<CubitFacet *> temp_split_facets, 
00182                                   CubitPoint *pnt0, 
00183                                   CubitPoint *pnt1, 
00184                                   DLIList<CubitFacet *> &select_facets );
00185 
00186 
00187 private:
00188 
00189  // used with split_into_shells to group facets
00190   static CubitStatus get_adj_facets_on_shell( CubitFacet *start_facet_ptr,
00191                                        DLIList<CubitFacet *> *shell_ptr,
00192                                        CubitBoolean &is_water_tight,
00193                                        int mydebug );
00194 
00195   // used with stitch_facets to merge points that are colinear with edges
00196   static CubitStatus merge_colinear_vertices( DLIList<DLIList<CubitFacet *> *> &shell_list,
00197                                          double tol,
00198                                          DLIList<CubitPoint *> &merge_points,
00199                                          int &mpmerge,
00200                                          int &nemerge,
00201                                          int &nnomerge);
00202 
00203 
00204 };
00205 
00206 #endif
00207 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines