MeshKit
1.0
|
00001 #ifndef GEN_HPP 00002 #define GEN_HPP 00003 00004 #include <iostream> 00005 #include <iomanip> // for setprecision 00006 #include <limits> // for min/max values 00007 #include <assert.h> 00008 #include <math.h> 00009 #include <time.h> 00010 #include <vector> 00011 #include <algorithm> 00012 #include "moab/Core.hpp" 00013 #include "moab/Range.hpp" 00014 #include "moab/AdaptiveKDTree.hpp" // for merging verts 00015 #include "moab/EntityHandle.hpp" 00016 #include "moab/CartVect.hpp" 00017 00018 // SENSE CONVENTIONS 00019 #define SENSE_FORWARD 1 00020 #define SENSE_REVERSE -1 00021 #define SENSE_UNKNOWN 0 00022 00023 00024 // returns a moab interface 00025 moab::Interface *MBI(); 00026 00027 namespace gen { 00028 bool error( const bool error_has_occured, const std::string message="" ); 00029 00031 void moab_printer(moab::ErrorCode error_code); 00032 00033 void print_vertex_cubit( const moab::EntityHandle vertex ); 00034 00035 void print_vertex_coords( const moab::EntityHandle vertex ); 00036 00037 void print_triangles( const moab::Range tris ); 00038 00039 void print_triangle( const moab::EntityHandle triangle, bool print_edges ); 00040 00041 void print_edge( const moab::EntityHandle edge ); 00042 00043 void print_vertex_count( const moab::EntityHandle input_meshset); 00044 00045 void print_range( const moab::Range range ); 00046 00047 void print_range_of_edges( const moab::Range range ); 00048 00049 void print_arc_of_edges( const std::vector<moab::EntityHandle> arc_of_edges ); 00050 00051 void print_arcs( const std::vector < std::vector<moab::EntityHandle> > arcs ); 00052 00053 void print_loop( const std::vector<moab::EntityHandle> loop_of_verts ); 00054 00055 moab::ErrorCode find_closest_vert( const moab::EntityHandle reference_vert, 00056 const std::vector<moab::EntityHandle> arc_of_verts, 00057 unsigned &position, 00058 const double dist_limit ); 00059 00060 moab::ErrorCode find_closest_vert( const double tol, 00061 const moab::EntityHandle reference_vert, 00062 const std::vector<moab::EntityHandle> loop_of_verts, 00063 std::vector<unsigned> &positions, 00064 std::vector<double> &dists); 00065 /* moab::ErrorCode find_closest_vert( const moab::EntityHandle reference_vert, 00066 const std::vector<std::vector<moab::EntityHandle> > loops_of_verts, 00067 unsigned int &loop, unsigned int &position, 00068 double &min_dist); 00069 */ 00070 // Merge the range of vertices. We do not merge by edges (more 00071 // stringent) because we do not want to miss corner vertices. 00072 00075 moab::ErrorCode merge_vertices( moab::Range vertices /* in */, 00076 const double tol /* in */); 00077 //bool &merge_vertices_again /* out */); 00078 00080 moab::ErrorCode squared_dist_between_verts( const moab::EntityHandle v0, 00081 const moab::EntityHandle v1, 00082 double &d); 00084 00085 double dist_between_verts( const moab::CartVect v0, const moab::CartVect v1 ); 00086 moab::ErrorCode dist_between_verts( const moab::EntityHandle v0, const moab::EntityHandle v1, 00087 double &d ); 00088 double dist_between_verts( double coords0[], double coords1[] ); 00089 double dist_between_verts( moab::EntityHandle vert0, moab::EntityHandle vert1 ); 00090 00091 // Return the length of the curve defined by MBEDGEs or ordered MBVERTEXs. 00092 double length( std::vector<moab::EntityHandle> curve ); 00093 00094 // Given a vertex and vector of edges, return the number of edges adjacent to the vertex. 00095 unsigned int n_adj_edges( moab::EntityHandle vert, moab::Range edges ); 00096 00097 // Return true if the edges share a vertex. Does not check for coincident edges. 00098 bool edges_adjacent( moab::EntityHandle edge0, moab::EntityHandle edge1 ); 00099 00100 // get the direction unit vector from one vertex to another vertex 00101 //moab::ErrorCode get_direction( moab::EntityHandle from_vert, moab::EntityHandle to_vert, double dir[] ); 00102 moab::ErrorCode get_direction( const moab::EntityHandle from_vert, const moab::EntityHandle to_vert, 00103 moab::CartVect &dir ); 00104 00105 // from http://www.topcoder.com/tc?module=Static&d1=tutorials&d2=geometry1 00106 double edge_point_dist( const moab::CartVect a, const moab::CartVect b, const moab::CartVect c ); 00107 double edge_point_dist( const moab::EntityHandle endpt0, const moab::EntityHandle endpt1, 00108 const moab::EntityHandle pt ); 00109 double edge_point_dist( const moab::EntityHandle edge, const moab::EntityHandle pt ); 00110 00111 moab::ErrorCode point_curve_min_dist( const std::vector<moab::EntityHandle> curve, 00112 const moab::EntityHandle pt, double &min_dist, 00113 const double max_dist_along_curve ); 00114 moab::ErrorCode point_curve_min_dist( const std::vector<moab::EntityHandle> curve, 00115 const moab::EntityHandle pt, double &min_dist ); 00116 00117 double triangle_area( const moab::CartVect a, const moab::CartVect b, const moab::CartVect c); 00118 moab::ErrorCode triangle_area( const moab::EntityHandle conn[], double &area ); 00119 moab::ErrorCode triangle_area( const moab::EntityHandle triangle, double &area ); 00120 double triangle_area( moab::Range triangles ); 00121 00122 bool triangle_degenerate( const moab::EntityHandle triangle ); 00123 bool triangle_degenerate( const moab::EntityHandle v0, const moab::EntityHandle v1, const moab::EntityHandle v2); 00124 00126 moab::ErrorCode triangle_normals( const moab::Range triangles, std::vector<moab::CartVect> &normals ); 00127 moab::ErrorCode triangle_normal( const moab::EntityHandle triangle, moab::CartVect &normal ); 00128 moab::ErrorCode triangle_normal( const moab::EntityHandle v0, const moab::EntityHandle v1, 00129 const moab::EntityHandle v2, moab::CartVect &normal ); 00130 moab::ErrorCode triangle_normal( const moab::CartVect v0, const moab::CartVect v1, 00131 const moab::CartVect v2, moab::CartVect &normal ); 00132 00133 // Distance between a point and line. The line is defined by two verts. 00134 // We are using a line and not a line segment! 00135 // http://mathworld.wolfram.com/Point-LineDistance3-Dimensional.html 00136 moab::ErrorCode line_point_dist( const moab::EntityHandle line_pt1, const moab::EntityHandle line_pt2, 00137 const moab::EntityHandle pt0, double &dist ); 00138 00139 // Project the point onto the line. Not the line segment! 00140 // Change the coordinates of the pt0 to the projection. 00141 moab::ErrorCode point_line_projection( const moab::EntityHandle line_pt1, 00142 const moab::EntityHandle line_pt2, 00143 const moab::EntityHandle pt0 ); 00144 00145 // Do not change the coords of pt0. Instead return the projected coords. 00146 moab::ErrorCode point_line_projection( const moab::EntityHandle line_pt1, 00147 const moab::EntityHandle line_pt2, 00148 const moab::EntityHandle pt0, 00149 moab::CartVect &projected_coords, 00150 double ¶meter ); 00151 // Get the distance of pt0 from line_pt1 if pt0 is projected. No coords are 00152 // changed in MOAB. 00153 moab::ErrorCode point_line_projection( const moab::EntityHandle line_pt1, 00154 const moab::EntityHandle line_pt2, 00155 const moab::EntityHandle pt0, 00156 double &dist_along_edge ); 00157 00158 moab::ErrorCode ear_clip_polygon( std::vector<moab::EntityHandle> polygon_of_verts, 00159 const moab::CartVect plane_normal_vector, moab::Range &new_tris ); 00160 00161 int geom_id_by_handle( const moab::EntityHandle set); 00162 00164 moab::ErrorCode save_normals( moab::Range tris, moab::Tag normal_tag ); 00165 00166 moab::ErrorCode flip(const moab::EntityHandle tri, const moab::EntityHandle vert0, 00167 const moab::EntityHandle vert2, const moab::EntityHandle surf_set); 00168 00169 00171 moab::ErrorCode ordered_verts_from_ordered_edges( const std::vector<moab::EntityHandle> ordered_edges, 00172 std::vector<moab::EntityHandle> &ordered_verts ); 00175 moab::ErrorCode dist_between_arcs( bool debug, 00176 const std::vector<moab::EntityHandle> arc0, 00177 const std::vector<moab::EntityHandle> arc1, 00178 double &dist ); 00179 00180 // skin edges are a vector of two vertex handles 00181 // Hold edges in an array of handles. 00182 struct edge { 00183 moab::EntityHandle e, v0, v1; 00184 }; 00185 int compare_edge(const void *a, const void *b); 00186 moab::ErrorCode find_skin( moab::Range tris, const int dim, 00187 // std::vector<std::vector<moab::EntityHandle> > &skin_edges, 00188 moab::Range &skin_edges, 00189 const bool ); 00190 //moab::ErrorCode find_skin( const moab::Range tris, const int dim, moab::Range &skin_edges, const bool ); 00191 moab::ErrorCode measure( const moab::EntityHandle set, const moab::Tag geom_tag, double &size, bool debug, bool verbose ); 00192 00193 // Given a curve and surface set, get the relative sense. 00194 // From CGMA/builds/dbg/include/CubitDefines, CUBIT_UNKNOWN=-1, CUBIT_FORWARD=0, CUBIT_REVERSED=1 00195 moab::ErrorCode get_curve_surf_sense( const moab::EntityHandle surf_set, const moab::EntityHandle curve_set, 00196 int &sense, bool debug = false ); 00197 00198 moab::ErrorCode surface_sense( moab::EntityHandle volume, int num_surfaces,const moab::EntityHandle* surfaces,int* senses_out ); 00199 moab::ErrorCode surface_sense( moab::EntityHandle volume, moab::EntityHandle surface, int& sense_out ); 00200 00201 moab::Tag get_tag( const char* name, int size, moab::TagType store,moab::DataType type, const void* def_value, bool create_if_missing); 00202 00203 moab::ErrorCode delete_surface( moab::EntityHandle surf, moab::Tag geom_tag, moab::Range tris, int id, bool debug, bool verbose); 00204 00205 moab::ErrorCode remove_surf_sense_data(moab::EntityHandle del_surf, bool debug); 00206 00207 moab::ErrorCode combine_merged_curve_senses( std::vector<moab::EntityHandle> &curves, moab::Tag merge_tag, bool debug = false) ; 00208 00210 moab::ErrorCode get_sealing_mesh_tags( double &facet_tol, 00211 double &sme_resabs_tol, 00212 moab::Tag &geom_tag, 00213 moab::Tag &id_tag, 00214 moab::Tag &normal_tag, 00215 moab::Tag &merge_tag, 00216 moab::Tag &faceting_tol_tag, 00217 moab::Tag &geometry_resabs_tag, 00218 moab::Tag &size_tag, 00219 moab::Tag &orig_curve_tag); 00220 00222 moab::ErrorCode get_geometry_meshsets( moab::Range geometry_sets[], moab::Tag geom_tag, bool verbose = false); 00223 00226 moab::ErrorCode check_for_geometry_sets(moab::Tag geom_tag, bool verbose); 00227 00228 } 00229 00230 #endif