cgma
FacetQueryEngine.hpp
Go to the documentation of this file.
00001 //-------------------------------------------------------------------------
00002 // Filename      : FacetQueryEngine.hpp
00003 //
00004 // Purpose       : Facet geometry engine.
00005 //
00006 //                 This class is implemented as a Singleton pattern. Only
00007 //                 one instance is created and it is accessed through the 
00008 //                 {instance()} static member function.
00009 //
00010 // Special Notes :
00011 //
00012 // Creator       : David R. White
00013 //
00014 // Creation Date : 6/29/00
00015 //
00016 //-------------------------------------------------------------------------
00017 
00018 #ifndef FACET_GEOMETRY_ENGINE_HPP
00019 #define FACET_GEOMETRY_ENGINE_HPP
00020 
00021 // ********** BEGIN STANDARD INCLUDES         **********
00022 
00023 #include <typeinfo>
00024 
00025 // ********** END STANDARD INCLUDES           **********
00026 
00027 // ********** BEGIN CUBIT INCLUDES            **********
00028 
00029 #include "CubitFileIOWrapper.hpp"
00030 #include "GeometryQueryEngine.hpp"
00031 
00032 // ********** END CUBIT INCLUDES              **********
00033 
00034 // ********** BEGIN FORWARD DECLARATIONS
00035 class TopologyEntity;
00036 class TopologyBridge;
00037 class RefEntity;
00038 class Body;
00039 class Shell;
00040 class ShellSM;
00041 class Loop;
00042 class Chain;
00043 class CoEdgeSM;
00044 class LoopSM;
00045 class RefVolume;
00046 class RefFace;
00047 class RefEdge;
00048 class RefVertex;
00049 class TBPoint;
00050 class Curve;
00051 class Surface;
00052 class Lump;
00053 class BodySM;
00054 
00055 class GeometryEntity;
00056 class CubitBox;
00057 class CubitString;
00058 
00059 class FacetLump;
00060 class FacetShell;
00061 class FacetLoop;
00062 class FacetSurface;
00063 class FacetBody;
00064 class FacetCoEdge;
00065 class FacetCurve;
00066 class FacetPoint;
00067 
00068 class CubitFacet;
00069 class CubitQuadFacet;
00070 class CubitFacetEdge;
00071 class CubitPoint;
00072 class FacetEntity;
00073 class CurveFacetEvalTool;
00074 class FacetEvalTool;
00075 
00076 // ********** END FORWARD DECLARATIONS        **********
00077 
00078 // ********** BEGIN MACRO DEFINITIONS         **********
00079 // ********** END MACRO DEFINITIONS           **********
00080 
00081 // ********** BEGIN ENUM DEFINITIONS          **********
00082 typedef enum {
00083   CUBIT_FACET_FILE,
00084   AVS_FILE,
00085   CHOLLA_FILE,
00086   FROM_FACET_LIST, 
00087   STL_FILE
00088 } FacetFileFormat;
00089 
00090 // ********** END ENUM DEFINITIONS            **********
00091 
00092 class FacetQueryEngine : public GeometryQueryEngine
00093 {
00094 public:
00095 // ********** BEGIN FRIEND DECLARATIONS        **********
00096   friend class FacetSurface;
00097   
00098 // ********** END FRIEND DECLARATIONS        **********
00099 
00100 //HEADER- Constructor and Destructor
00101   
00102   static FacetQueryEngine* instance();
00103     //- Singleton pattern
00104     //- Controlled access and creation of the sole instance of this class.
00105 
00106   virtual ~FacetQueryEngine();
00107 
00108   static void delete_instance();
00109   
00110   const char* modeler_type()
00111      { return "facet"; }
00112 
00113   int get_major_version();
00114 
00115   int get_minor_version();
00116 
00117   int get_subminor_version();
00118 
00119   CubitString get_engine_version_string();
00120   
00121 //HEADER- RTTI and safe casting functions.
00122   
00123   virtual const std::type_info& entity_type_info() const ;
00124     //R- The geometric modeler type
00125     //- This function returns the type of the geometric modeler.
00126   
00127   virtual CubitBoolean is_solid_modeler_type() const 
00128     {return CUBIT_FALSE;}
00129     //R CubitBoolean
00130     //R- This  is not a solid modeling engine.
00131 //HEADER- Functions for importing and exporting solid models.
00132 
00133   CubitBoolean can_delete_bodies(DLIList<Body*>body_list);
00134   
00135   virtual TBPoint* make_Point( GeometryType point_type,
00136                              CubitVector const& point) const ;
00137   virtual Curve* make_Curve(Curve *) const;
00138   virtual Curve* make_Curve( TBPoint const* ,
00139                              TBPoint const* ,
00140                              RefFace* ,
00141                              CubitVector * ) const;
00142   virtual Curve* make_Curve( GeometryType ,
00143                              TBPoint const* ,
00144                              TBPoint const* ,
00145                              DLIList<CubitVector*>& ,
00146                              RefFace*  ) const;
00147   virtual Curve* make_Curve( GeometryType ,
00148                              TBPoint const* ,
00149                              TBPoint const* ,
00150                              CubitVector const* ,
00151                              CubitSense ) const;
00152   virtual Surface* make_Surface( Surface *,
00153                                  DLIList<Loop*> &,
00154                                  CubitBoolean  ) const;
00155 
00156 
00157   virtual Surface* make_Surface( GeometryType , 
00158                                  DLIList<Curve*>& ,
00159                                  DLIList<Loop*> &,
00160                                  Surface *) const ;
00161   virtual Lump* make_Lump( GeometryType , 
00162                            DLIList<Surface*>&  ) const ;
00163   virtual BodySM* make_BodySM( Surface * ) const;
00164     virtual BodySM* make_BodySM( DLIList<Lump*>&  ) const ;
00165 
00166   Body* copy_body( Body *body_ptr );
00167 
00168   virtual CubitStatus get_graphics( BodySM *bodysm, GMem* g_mem,
00169                          std::vector<Surface*> &surface_to_facets_vector,
00170                          std::vector<TopologyBridge*> &vertex_edge_to_point_vector,
00171                          std::vector<std::pair<TopologyBridge*, std::pair<int,int> > > &facet_edges_on_curves,
00172                          unsigned short normal_tolerance, 
00173                          double distance_tolerance, double max_edge_length ) const;
00174 
00175   virtual CubitStatus get_graphics( Surface* surface_ptr,
00176                                           GMem* gMem,
00177                                           unsigned short normal_tolerance,
00178                                           double distance_tolerance,
00179                                           double max_edge_length ) const;
00180 
00181   virtual CubitStatus get_graphics( Curve* curve_ptr,
00182                                     GMem* gMem,
00183                                     double angle_tolerance=0,
00184                                     double distance_tolerance=0,
00185                                     double max_edge_length=0 ) const;
00186     //R CubitStatus
00187     //R- CUBIT_SUCCESS/CUBIT_FAILURE
00188     //I ref_edge_ptr
00189     //I- The RefEdge for which hoops facetting information will be
00190     //I- gathered.
00191     //O numSteps
00192     //O- The number of points in resulting polyline.
00193     //O gMem
00194     //O- The storage place for edges, involved in facetting.
00195     //I tolerance
00196     //I- The tolerance deviation used when facetting the curve (optional
00197     //I- and currently IGNORED by this engine).
00198     //- This function gathers and outputs edge information for
00199     //- hoops involved in facetting a RefEdge.  If all goes well,
00200     //- CUBIT_SUCCESS is returned.  Otherwise, CUBIT_FAILURE is
00201     //- returned.
00202  
00203   virtual CubitStatus get_isoparametric_points(Surface* ,
00204                                                int &, int &,
00205                                                GMem*&) const;
00206   
00207   virtual CubitStatus get_u_isoparametric_points(Surface* ref_face_ptr,
00208                                                  double v, int &n,
00209                                                  GMem *&gMem) const;
00210   
00211   virtual CubitStatus get_v_isoparametric_points(Surface* ref_face_ptr,
00212                                                  double u, int &n,
00213                                                  GMem *&gMem) const;
00214   
00215   virtual CubitStatus transform_vec_position( 
00216     CubitVector const& ,
00217     BodySM *,
00218     CubitVector & ) const;
00219   
00220   virtual CubitStatus get_intersections( Curve*, CubitVector& point1,
00221                                          CubitVector&,
00222                                          DLIList<CubitVector>& ,
00223                                          CubitBoolean,
00224                                          CubitBoolean );
00225 
00226   virtual CubitStatus get_intersections( Curve* , Curve* ,
00227                                          DLIList<CubitVector>& ,
00228                                          CubitBoolean,
00229                                          CubitBoolean );
00230   virtual CubitStatus get_intersections( Curve* ref_edge1, Curve* ref_edge2,
00231                                          DLIList<CubitVector>& intersection_list,
00232                                          double offset, 
00233                                          CubitBoolean ext_first = CUBIT_TRUE );
00234   virtual CubitStatus get_intersections( Curve* ref_edge, Surface* ref_face,
00235                                         DLIList<CubitVector>& intersection_list,
00236                                         CubitBoolean bounded = CUBIT_FALSE );
00237 
00238   virtual CubitStatus entity_extrema( DLIList<GeometryEntity*> &entity_list, 
00239                                       const CubitVector *dir1, 
00240                                       const CubitVector *dir2,
00241                                       const CubitVector *dir3, 
00242                                       CubitVector &extrema,
00243                                       GeometryEntity *&extrema_entity_ptr );
00244   //- Gets the extrema position along the first given direction. If there 
00245   //- is more than one extrema position, the other directions will be used 
00246   //- to determine a unique position.  Directions 2 and 3 can be NULL.
00247   //- Entities supported include bodies, volumes, surfaces, curves and
00248   //- vertices.  The entity the extrema is found on is also returned.
00249 
00250   virtual CubitStatus entity_entity_distance( GeometryEntity *ref_entity_ptr1,
00251                                               GeometryEntity *ref_entity_ptr2,
00252                                               CubitVector &pos1, CubitVector &pos2,
00253                                               double &distance );
00254   //- Gets the minimum distance between two entities and the closest positions 
00255   //- on those entities. Supports vertices, curves, surfaces, volumes and bodies.
00256 
00257   virtual CubitStatus export_solid_model( DLIList<TopologyBridge*>& bridge_list,
00258                                           const char* file_name,
00259                                           Model_File_Type file_type,
00260                                           const CubitString &cubit_version,
00261                                           ModelExportOptions &export_options );
00262 
00263   virtual CubitStatus export_solid_model( DLIList<TopologyBridge*>& bridge_list,
00264                                           char*& p_buffer,
00265                                           int& n_buffer_size,
00266                                           bool b_export_buffer)
00267 {return CUBIT_FAILURE;}
00268 
00269   virtual CubitStatus save_temp_geom_file( DLIList<TopologyBridge*>& ref_entity_list,
00270                                           const char *file_name,
00271                                           const CubitString &cubit_version,
00272                                           CubitString &created_file,
00273                                           CubitString &created_file_type ); 
00274 
00275  virtual CubitStatus import_solid_model(const char* file_name,
00276                                          Model_File_Type file_type,
00277                                          DLIList<TopologyBridge*>& imported_entities, 
00278                                          ModelImportOptions &import_options );
00279 
00280  virtual CubitStatus import_solid_model(DLIList<TopologyBridge*> &imported_entities,
00281                                         const char* pBuffer,
00282                                         const int n_buffer_size)
00283 {return CUBIT_FAILURE;}
00284 
00285 private:
00286   CubitStatus import_solid_model(FILE *file_ptr,
00287                                  DLIList<TopologyBridge*> &imported_entities );
00288 
00289 public:
00290   virtual void delete_solid_model_entities(DLIList<BodySM*>& body_list) const;
00291     //- Deletes all solid model entities associated with the Bodies in 
00292     //- the input list. 
00293       
00294   virtual CubitStatus delete_solid_model_entities( BodySM* body_ptr ) const;
00295   virtual CubitStatus delete_solid_model_entities(Surface* surf_ptr ) const;
00296   virtual CubitStatus delete_solid_model_entities( Curve* curve_ptr ) const;
00297   virtual CubitStatus delete_solid_model_entities( TBPoint* point_ptr ) const;
00298 
00299   virtual CubitStatus fire_ray( CubitVector &origin,
00300                                 CubitVector &direction,
00301                                 DLIList<TopologyBridge*> &at_entity_list,
00302                                 DLIList<double> &ray_params,
00303                                 int max_hits,
00304                                 double ray_radius,
00305                                 DLIList<TopologyBridge*> *hit_entity_list=0 ) const;
00306     //- Fire a ray at specified entities, returning the parameters (distances)
00307     //- along the ray and optionally the entities hit.  Returned lists are
00308     //- appended to.  Input entities can be any of bodies, volumes, faces,
00309     //- edges or vertices.  Optionally you can specify the maximum number of
00310     //- hits to return (default = 0 = unlimited), and the ray radius to use for
00311     //- intersecting the entities (default = 0.0 = use modeller default).
00312     //- NOTE: returned entities hit might be "hidden" beneath virtual entities.
00313     //-       To resolve to visible entities, use "get_visible_ents_for_hits"
00314     //-       in GeometryQueryTool.
00315 
00316   virtual double get_sme_resabs_tolerance() const; // Gets solid modeler's resolution absolute tolerance
00317   virtual double set_sme_resabs_tolerance( double new_resabs );
00318 
00319   virtual CubitStatus set_int_option( const char* opt_name, int val );
00320   virtual CubitStatus set_dbl_option( const char* opt_name, double val );
00321   virtual CubitStatus set_str_option( const char* opt_name, const char* val );
00322     //- Set solid modeler options
00323 
00324   static CubitStatus make_facets( int *conn, int nfacets,
00325                                   DLIList<CubitQuadFacet *> &facet_list );
00326   static CubitStatus make_facets( int *conn, int nfacets,
00327                                   DLIList<CubitFacet *> &facet_list );
00328     //- create facets from a list of points and connectivity
00329 
00330   CubitStatus ensure_is_ascii_stl_file(FILE * fp, CubitBoolean &is_ascii);
00331   //- returns true in is_ascii if fp points to an ascii stl file
00332 
00333   CubitStatus read_facets_stl_tolerance(   
00334                                               DLIList<CubitFacet *> &tfacet_list,
00335                                               DLIList<CubitPoint *> &point_list,
00336                                               const char * file_name,
00337                                               int &npoints, 
00338                                               int &ntri,
00339                                               long& seek_address,
00340                                               double tolerance);
00341   //- read facets from an stl file and combine vertices within tolerance distance
00342 
00343     CubitStatus read_facets_stl(   
00344                                               DLIList<CubitFacet *> &tfacet_list,
00345                                               DLIList<CubitPoint *> &point_list,
00346                                               const char * file_name,
00347                                               int &npoints, 
00348                                               int &ntri,
00349                                               long& seek_address);
00350   //- read facets from an stl file
00351   
00352   CubitStatus import_facets( const char *file_name, 
00353                              CubitBoolean use_feature_angle, 
00354                              double feature_angle,
00355                              double tolerance,
00356                              int interp_order,
00357                              CubitBoolean smooth_non_manifold,
00358                              CubitBoolean split_surfaces,
00359                              CubitBoolean stitch,
00360                              CubitBoolean improve,
00361                              DLIList <CubitQuadFacet *>&quad_facet_list,
00362                              DLIList <CubitFacet *> &tri_facet_list,
00363                              DLIList<Surface *> &surface_list,
00364                              FacetFileFormat file_format = CUBIT_FACET_FILE );
00365     //- import facets from a file and create a geometry model
00366 
00367   static CubitStatus read_facets( const char * file_name,
00368                                   int *&conn,
00369                                   int &npoints, 
00370                                   int &nquad, int &ntri, 
00371                                   FacetFileFormat file_format = CUBIT_FACET_FILE );
00372   static CubitStatus read_cholla_file( const char *file_name, 
00373                                        double &feature_angle,
00374                                        DLIList<CubitPoint *> &point_list, 
00375                                        DLIList<CubitFacet *> &facet_list);
00376     //- read points and facets from a file
00377 
00378   CubitBoolean is_close(CubitVector &this_point,
00379                         DLIList<CubitFacet *>&facet_list,
00380                         CubitFacet *&lastFacet,
00381                         double tol);
00382     //- determine if one of the facets in the list is within a
00383     //- certain distance of the point.
00384 
00385   static CubitStatus export_facets(DLIList<CubitFacet*> &facet_list,
00386                                   char *filename);
00387     //-  export a list of facets to a facet file for debugging purposes
00388 
00389   CubitStatus gather_all_facet_entities( DLIList<FacetBody*> &facet_bodies,
00390                                          DLIList<FacetLump*> &facet_lumps,
00391                                          DLIList<FacetShell*> &facet_shells,
00392                                          DLIList<FacetSurface*> &facet_surfaces,
00393                                          DLIList<FacetLoop*> &facet_loops,
00394                                          DLIList<FacetCoEdge*> &facet_coedges,
00395                                          DLIList<FacetCurve*> &facet_curves,
00396                                          DLIList<FacetPoint*> &facet_points );
00397 
00398   CubitStatus save_facets( FILE *fp, DLIList<FacetSurface*> facet_surfaces,
00399                                      DLIList<FacetCurve*>   facet_curves, 
00400                                      DLIList<FacetPoint*>   facet_points ); 
00401 
00402   CubitStatus save_eval_tools( FILE *fp, DLIList<FacetSurface*> facet_surfaces,
00403                                          DLIList<FacetCurve*> facet_curves );
00404 
00405   CubitStatus dump_facets( FILE *fp,
00406                            DLIList<CubitFacet *> &facet_list,
00407                            DLIList<CubitFacetEdge *> &edge_list, 
00408                            DLIList<CubitPoint *> &point_list );
00409   CubitStatus gather_facets( DLIList<FacetSurface *> facet_surfaces,
00410                              DLIList<FacetCurve *> facet_curves,
00411                              DLIList<FacetPoint *> facet_points,
00412                              DLIList<CubitFacet *> &facet_list,
00413                              DLIList<CubitFacetEdge *> &edge_list, 
00414                              DLIList<CubitPoint *> &point_list );
00415     //- functions for saving the facet geometry representation to a cubit file
00416   
00417   CubitStatus restore_eval_tools( FILE *fp,
00418                                   unsigned int endian, 
00419                                   int num_facets,
00420                                   int num_edges,
00421                                   int num_points,
00422                                   CubitFacet **facets,     
00423                                   CubitFacetEdge **edges,     
00424                                   CubitPoint **points,
00425                                   int &num_cfet,
00426                                   int &num_fet,
00427                                   CurveFacetEvalTool **&cfeval_tools,
00428                                   FacetEvalTool **&feval_tools );
00429     //- restore facets from CUB file
00430 
00431 CubitStatus create_super_facet_bounding_box(
00432                                 DLIList<BodySM*>& body_list,
00433                                 CubitBox& super_box );
00434 CubitStatus create_facet_bounding_box(
00435                                 BodySM* bodySM,
00436                                 CubitBox& bbox );
00437 
00438   CubitStatus restore_transform( BodySM* body );
00439 
00440   CubitStatus translate( BodySM* body, const CubitVector& offset );
00441   CubitStatus rotate   ( BodySM* body, const CubitVector& axis, double angle );
00442   CubitStatus scale    ( BodySM* body, double factor );
00443   CubitStatus scale    ( BodySM* body, const CubitVector& factors );
00444   CubitStatus reflect  ( BodySM* body, const CubitVector& axis );
00445 
00446   CubitStatus translate( GeometryEntity* ent, const CubitVector& offset );
00447   CubitStatus rotate   ( GeometryEntity* ent, const CubitVector& axis, double degrees );
00448   CubitStatus scale    ( GeometryEntity* ent, double factor );
00449   CubitStatus scale    ( GeometryEntity* ent, const CubitVector& factors );
00450   CubitStatus reflect  ( GeometryEntity* ent, const CubitVector& axis );
00451 
00452   CubitStatus get_connected_patch( DLIList<FacetSurface*>& remaining_surfs,
00453                                    DLIList<FacetSurface*>& output_patch );
00454   virtual CubitBoolean bodies_overlap (BodySM *body_ptr_1,
00455                                        BodySM *body_ptr_2 ) const;
00456   virtual CubitBoolean volumes_overlap (Lump *lump_ptr_1,
00457                                         Lump *lump_ptr_2 ) const;
00458   //R CubitBoolean
00459   //R- CUBIT_TRUE if the two bodies overlap, CUBIT_FALSE if they don't
00460   //R- overlap.  If the bodies are touching the function
00461   //R- should return CUBIT_FALSE.
00462   //I body_ptr_1, body_ptr_2
00463   //I- The two body pointers that are being tested for overlap.
00464   //-  The function uses the intersect call to test if the bodies
00465   //-  are overlaping.  The full intersect Boolean is needed to see if
00466   //-  the bodies actually overlap and don't just touch.
00467 
00468   virtual CubitStatus get_point_containment( DLIList<BodySM*> &bodysm_list,
00469                                      DLIList<CubitVector> &point_list,
00470                                      double tolerance,
00471                                      bool allow_pts_in_multiple_bodies,
00472                                      std::vector< std::pair<BodySM*, std::vector<int> > > &bodysm_to_pt_indices );
00473 
00474 protected:
00475   
00476   FacetQueryEngine();
00477   
00478 private:
00479 
00480   CubitStatus write_topology( FILE *file_ptr, 
00481                               DLIList<FacetBody*> &facet_bodies,
00482                               DLIList<FacetLump*> &facet_lumps,
00483                               DLIList<FacetShell*> &facet_shells,
00484                               DLIList<FacetSurface*> &facet_surfaces,
00485                               DLIList<FacetLoop*> &facet_loops,
00486                               DLIList<FacetCoEdge*> &facet_coedges,
00487                               DLIList<FacetCurve*> &facet_curves,
00488                               DLIList<FacetPoint*> &facet_points );
00489 
00490   CubitStatus restore_topology( FILE *file_ptr, 
00491                                 unsigned int endian, 
00492                                 int num_points,
00493                                 CubitPoint **points_array,
00494                                 int num_cfet,
00495                                 CurveFacetEvalTool **cfev_array,
00496                                 int num_fet,
00497                                 FacetEvalTool **fev_array,
00498                                 DLIList<TopologyBridge*> &imported_entities );
00499 
00500   CubitStatus restore_facets( FILE *file_ptr,
00501                               unsigned int endian, 
00502                               int &num_facets,
00503                               int &num_edges,
00504                               int &num_points,
00505                               CubitPoint**&points_array,
00506                               int &num_cfet,
00507                               int &num_fet,
00508                               CurveFacetEvalTool **&cfet_array,
00509                               FacetEvalTool **&fet_array);
00510 
00511   CubitStatus read_facets( FILE *fp, 
00512                            unsigned int endian, 
00513                            int &num_facets, int &num_edges, int &num_points, 
00514                            CubitFacet **&facets, CubitFacetEdge **&edges,     
00515                            CubitPoint **&points );
00516 
00517   static FacetQueryEngine* instance_;
00518     //- static pointer to unique instance of this class
00519 
00520   static CubitStatus init_hash_points( int num_points );
00521   static CubitStatus add_hash_point( CubitPoint *point_ptr );
00522   static CubitPoint *get_hash_point( int id );
00523   static void delete_hash_points( );
00524   static int get_hash_key( int id );
00525   static CubitStatus get_all_hash_points(DLIList<CubitPoint *> &point_list);
00526   static int hashPointSize;
00527   static DLIList<CubitPoint *> *hashPointArray;
00528     //- hash table functions used for reading the facet file
00529 
00530   static const int FQE_MAJOR_VERSION;
00531   static const int FQE_MINOR_VERSION;
00532   static const int FQE_SUBMINOR_VERSION;
00533 };
00534 
00535 // ********** BEGIN INLINE FUNCTIONS          **********
00536 // ********** END INLINE FUNCTIONS            **********
00537 
00538 // ********** BEGIN FRIEND FUNCTIONS          **********
00539 // ********** END FRIEND FUNCTIONS            **********
00540 
00541 // ********** BEGIN EXTERN FUNCTIONS          **********
00542 // ********** END EXTERN FUNCTIONS            **********
00543 
00544 // ********** BEGIN HELPER CLASS DECLARATIONS **********
00545 // ********** END HELPER CLASS DECLARATIONS   **********
00546 
00547 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines