Mesh Oriented datABase  (version 5.4.1)
Array-based unstructured mesh datastructure
FBEngine.hpp
Go to the documentation of this file.
00001 #ifndef FBENGINE_HPP_
00002 #define FBENGINE_HPP_
00003 #include <cstdlib>
00004 
00005 #include <vector>
00006 #include <map>
00007 
00008 #include "moab/Types.hpp"
00009 #include "moab/Interface.hpp"
00010 #include "moab/Range.hpp"
00011 #include "moab/CartVect.hpp"
00012 
00013 namespace moab
00014 {
00015 class GeomTopoTool;
00016 
00017 // some forward declarations
00018 class SmoothFace;
00019 class SmoothCurve;
00020 
00021 /*
00022  *  Facet Based engine class for mesh-based geometry
00023  */
00024 class FBEngine
00025 {
00026   public:
00027     FBEngine( Interface* impl, GeomTopoTool* geomTopoTool = NULL, const bool smooth = false );
00028 
00029     ~FBEngine();
00030 
00031     ErrorCode Init();
00032 
00033     ErrorCode getRootSet( EntityHandle* root_set );
00034 
00035     ErrorCode getNumEntSets( EntityHandle set, int num_hops, int* all_sets );
00036 
00037     ErrorCode createEntSet( int isList, EntityHandle* pSet );
00038 
00039     ErrorCode addEntSet( EntityHandle entity_set_to_add, EntityHandle entity_set_handle );
00040 
00041     ErrorCode getEntities( EntityHandle root_set, int ent_type, Range& gentities );
00042 
00043     ErrorCode addEntArrToSet( const Range& entities, EntityHandle set );
00044 
00045     ErrorCode getNumOfType( EntityHandle set, int ent_type, int* pNum );
00046 
00047     ErrorCode getEntType( EntityHandle gent, int* type );
00048 
00049     ErrorCode getEntBoundBox( EntityHandle this_gent,
00050                               double* x0,
00051                               double* y0,
00052                               double* z0,
00053                               double* x1,
00054                               double* y1,
00055                               double* z1 );
00056     ErrorCode getEntClosestPt( EntityHandle this_gent,
00057                                double x,
00058                                double y,
00059                                double z,
00060                                double* x1,
00061                                double* y1,
00062                                double* y3 );
00063 
00064     ErrorCode getVtxCoord( EntityHandle this_gent, double* x0, double* y0, double* z0 );
00065 
00066     ErrorCode gsubtract( EntityHandle entity_set_1, EntityHandle entity_set_2, EntityHandle result_entity_set );
00067 
00068     ErrorCode getEntNrmlXYZ( EntityHandle entity_handle,
00069                              double x,
00070                              double y,
00071                              double z,
00072                              double* nrml_i,
00073                              double* nrml_j,
00074                              double* nrml_k );
00075 
00076     ErrorCode getPntRayIntsct( double x,
00077                                double y,
00078                                double z,
00079                                double dir_x,
00080                                double dir_y,
00081                                double dir_z,
00082                                std::vector< EntityHandle >& intersect_entity_handles,
00083                                /* int storage_order,*/
00084                                std::vector< double >& intersect_coords,
00085                                std::vector< double >& param_coords );
00086 
00087     // some new methods, that are needed
00088 
00089     ErrorCode createTag( const char* tag_name, int tag_num_type_values, int tag_type, Tag& tag_handle_out );
00090 
00091     Interface* moab_instance()
00092     {
00093         return _mbImpl;
00094     }
00095 
00096     ErrorCode getArrData( const moab::EntityHandle* entity_handles,
00097                           int entity_handles_size,
00098                           Tag tag_handle,
00099                           void* tag_values_out );
00100 
00101     ErrorCode setArrData( const EntityHandle* entity_handles,
00102                           int entity_handles_size,
00103                           Tag tag_handle,
00104                           const void* tag_values );
00105 
00106     ErrorCode getEntAdj( EntityHandle handle, int type_requested, Range& adjEnts );
00107 
00108     ErrorCode getEgFcSense( EntityHandle mbedge, EntityHandle mbface, int& sense );
00109 
00110     ErrorCode measure( const EntityHandle* moab_entities, int entities_size, double* measures );
00111 
00112     // to do
00113     ErrorCode getEntNrmlSense( EntityHandle face, EntityHandle region, int& sense );
00114 
00115     ErrorCode getEgEvalXYZ( EntityHandle edge,
00116                             double x,
00117                             double y,
00118                             double z,
00119                             double& on_x,
00120                             double& on_y,
00121                             double& on_z,
00122                             double& tngt_i,
00123                             double& tngt_j,
00124                             double& tngt_k,
00125                             double& cvtr_i,
00126                             double& cvtr_j,
00127                             double& cvtr_k );
00128     ErrorCode getFcEvalXYZ( EntityHandle face,
00129                             double x,
00130                             double y,
00131                             double z,
00132                             double& on_x,
00133                             double& on_y,
00134                             double& on_z,
00135                             double& nrml_i,
00136                             double& nrml_j,
00137                             double& nrml_k,
00138                             double& cvtr1_i,
00139                             double& cvtr1_j,
00140                             double& cvtr1_k,
00141                             double& cvtr2_i,
00142                             double& cvtr2_j,
00143                             double& cvtr2_k );
00144 
00145     ErrorCode getEgVtxSense( EntityHandle edge, EntityHandle vtx1, EntityHandle vtx2, int& sense );
00146 
00147     ErrorCode getEntURange( EntityHandle edge, double& u_min, double& u_max );
00148 
00149     ErrorCode getEntUtoXYZ( EntityHandle edge, double u, double& x, double& y, double& z );
00150 
00151     ErrorCode getEntTgntU( EntityHandle edge, double u, double& i, double& j, double& k );
00152 
00153     ErrorCode isEntAdj( EntityHandle entity1, EntityHandle entity2, bool& adjacent_out );
00154 
00155     ErrorCode split_surface_with_direction( EntityHandle face,
00156                                             std::vector< double >& xyz,
00157                                             double* direction,
00158                                             int closed,
00159                                             double min_dot,
00160                                             EntityHandle& oNewFace );
00161     // these new points will be on edges or triangles, if in interior of triangles
00162     ErrorCode split_surface( EntityHandle face,
00163                              std::vector< EntityHandle >& chainedEdges,
00164                              std::vector< EntityHandle >& splittingNodes,
00165                              EntityHandle& newFace );
00166 
00167     ErrorCode split_edge_at_point( EntityHandle edge, CartVect& point, EntityHandle& new_edge );
00168 
00169     ErrorCode split_edge_at_mesh_node( EntityHandle edge, EntityHandle node, EntityHandle& new_edge );
00170 
00171     ErrorCode split_bedge_at_new_mesh_node( EntityHandle b_edge,
00172                                             EntityHandle atNode,
00173                                             EntityHandle brokenEdge,
00174                                             EntityHandle& new_edge );
00175     // helper for cleaning the stuff
00176     // will be called if the topology is modified
00177     void clean();
00178 
00179     void delete_smooth_tags();
00180 
00181     // access to the geom topo tool
00182     // be careful what you do with it
00183     GeomTopoTool* get_gtt()
00184     {
00185         return this->_my_geomTopoTool;
00186     }
00187 
00188     ErrorCode create_volume_with_direction( EntityHandle newFace1,
00189                                             EntityHandle newFace2,
00190                                             double* direction,
00191                                             EntityHandle& volume );
00192 
00193     // get nodes from edge in order
00194     ErrorCode get_nodes_from_edge( EntityHandle gedge, std::vector< EntityHandle >& nodes );
00195 
00196     ErrorCode weave_lateral_face_from_edges( EntityHandle bEdge,
00197                                              EntityHandle tEdge,
00198                                              double* direction,
00199                                              EntityHandle& newLatFace );
00200 
00201     // chain "chain"-able edges
00202     // this could be useful if there are too many points / edges in the splitting
00203     // polyline
00204     // 2 edges are "chain"-able if
00205     /*
00206      *  1. they have the same adjacent faces
00207      *  2. their orientation is such as the end of one is the start of the other
00208      *  3. at meeting point, their tangents make an angle smaller then something
00209      *   (cos(angle) > cos (max_angle) = min_dot)
00210      */
00211     ErrorCode chain_edges( double min_dot );
00212 
00213     // 2 edges will be chained, along with modification of the topology
00214     ErrorCode chain_two_edges( EntityHandle edge, EntityHandle next_edge );
00215 
00216     ErrorCode get_vert_edges( EntityHandle edge, EntityHandle& v1, EntityHandle& v2 );
00217 
00218     void set_smooth()
00219     {
00220         _smooth = true;
00221     }
00222 
00223   private:
00224     ErrorCode initializeSmoothing();
00225 
00226     ErrorCode getAdjacentEntities( const EntityHandle from, const int to_dim, Range& adj_ents );
00227 
00228     ErrorCode compute_intersection_points( EntityHandle& face,
00229                                            EntityHandle from,
00230                                            EntityHandle to,
00231                                            CartVect& Dir,
00232                                            std::vector< CartVect >& points,
00233                                            std::vector< EntityHandle >& entities,
00234                                            std::vector< EntityHandle >& triangles );
00235 
00236     ErrorCode BreakTriangle( EntityHandle tri,
00237                              EntityHandle e1,
00238                              EntityHandle e3,
00239                              EntityHandle n1,
00240                              EntityHandle n2,
00241                              EntityHandle n3 );  // nodesAlongPolyline are on entities!
00242 
00243     ErrorCode BreakTriangle2( EntityHandle tri,
00244                               EntityHandle e1,
00245                               EntityHandle e2,
00246                               EntityHandle n1,
00247                               EntityHandle n2 );  // nodesAlongPolyline are on entities!
00248 
00249     void print_debug_triangle( EntityHandle triangle );
00250 
00251     ErrorCode create_new_gedge( std::vector< EntityHandle >& nodesAlongPolyline, EntityHandle& new_geo_edge );
00252 
00253     // used for splitting surfaces
00254     ErrorCode separate( EntityHandle face, std::vector< EntityHandle >& chainedEdges, Range& first, Range& second );
00255 
00256     ErrorCode smooth_new_intx_points( EntityHandle face, std::vector< EntityHandle >& chainedEdges );
00257 
00258     // having a node, split boundary along that node
00259     ErrorCode split_boundary( EntityHandle face, EntityHandle atNode );
00260 
00261     // see if the node is already part of a vertex set, do not create another one
00262     bool find_vertex_set_for_node( EntityHandle iNode, EntityHandle& oVertexSet );
00263 
00264     // if the splitting edge is not a loop, the original boundary edges will belong to
00265     // either original face, or new face
00266     // only the new geo edge (splitting) will be part of both, with the
00267     // orientation already decided
00268     //
00269     ErrorCode redistribute_boundary_edges_to_faces( EntityHandle face,
00270                                                     EntityHandle newFace,
00271                                                     std::vector< EntityHandle >& chainedEdges );
00272 
00273     // used as a way to isolate the faces after splitting
00274     ErrorCode set_neumann_tags( EntityHandle face, EntityHandle newFace );
00275 
00276     // split the quads if needed; it will create a new gtt, which will
00277     // contain triangles instead of quads
00278     ErrorCode split_quads();
00279 
00280     ErrorCode boundary_nodes_on_face( EntityHandle face, std::vector< EntityHandle >& boundary_nodes );
00281 
00282     ErrorCode boundary_mesh_edges_on_face( EntityHandle face, Range& boundary_mesh_edges );
00283 
00284     // used for splitting an edge
00285     ErrorCode split_internal_edge( EntityHandle& edge, EntityHandle& newVertex );
00286     // triangle split
00287     ErrorCode divide_triangle( EntityHandle triangle, EntityHandle& newVertex );
00288     Interface* _mbImpl;
00289 
00290     // this will be used during volume creation
00291     ErrorCode set_default_neumann_tags();
00292 
00293     ErrorCode chain_able_edge( EntityHandle edge, double min_dot, EntityHandle& next_edge, bool& chainable );
00294 
00295     GeomTopoTool* _my_geomTopoTool;
00296     bool _t_created;
00297     bool _smooth;
00298     bool _initialized;
00299     // these are initial ranges, that should not change during geometry gimmicks
00300     // those that are added are changing gtt ranges, but they are not yet "smoothed"
00301     // when new geometry is created, these ranges are not yet updated
00302     Range _my_gsets[5];
00303     // these are used only for smooth evaluations
00304     // these smooth faces and edges will be initialized after reading the file
00305     // the maps keep the link between EH in moab (geom sets) and
00306     //   their corresponding smooth counterparts
00307     std::map< EntityHandle, SmoothFace* > _faces;
00308     std::map< EntityHandle, SmoothCurve* > _edges;
00309     SmoothFace** _smthFace;
00310     SmoothCurve** _smthCurve;
00311 
00312     Range _piercedTriangles;  // triangles to delete
00313     Range _newTriangles;
00314     Range _piercedEdges;                                  // edges to delete
00315     std::map< EntityHandle, EntityHandle > _brokenEdges;  // this is a map between splitting nodes and edges that
00316     // are broken on the boundary, by the polyline; the edges will be deleted in the end
00317     // new edges?
00318 };
00319 
00320 }  // namespace moab
00321 #endif /* FBENGINE_HPP_ */
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines