cgma
CubitFacet.hpp
Go to the documentation of this file.
00001 //----------------------------------------------------------------------------- 
00002 // 
00003 //  File: CubitFacet.hpp 
00004 // 
00005 //  Purpose:  Facet Class used for mesh based geometry and other tools. 
00006 // 
00007 //  Notes:    A facet is a triangle used for defining surfaces. The 
00008 //            default construction is a linear representation, although 
00009 //            b-spline control points can be defined to represent a 
00010 //            higher order triangular b-spline patch. There is also  
00011 //            support for quad facets by using the CubitQuadFacet 
00012 // 
00013 //            Note that the main private data components (ie. points, edges) 
00014 //            are not contained in this class. 
00015 //            This data should be defined within the child classes inherited 
00016 //            from this class.  The current Cubit data class that inherits 
00017 //            from CubitFacet is CubitFacetData.  This is done so that  
00018 //            other applications using CubitFacets can use their own 
00019 //            facet data, but take advantage of the CGM/Cubit functionality. 
00020 //            Please do not add private data to this class unless it is only 
00021 //            applicable to Cubit algorithms; instead add the 
00022 //            data to the children and access through virtual functions. 
00023 //  
00024 //            Do not create a CubitFacet directly.  For example, don't do:  
00025 //              CubitFacet *cf = new CubitFacet(...); 
00026 //            You should instead create the appropriate child class, and  
00027 //            cast it to a CubitFacet for use.  For example: 
00028 //              CubitFacet *cf = (CubitFacet *) new CubitFacetData(...); 
00029 //                         
00030 //----------------------------------------------------------------------------- 
00031  
00032 #ifndef CUBITFACET_HPP 
00033 #define CUBITFACET_HPP 
00034  
00035 #include "CubitDefines.h" 
00036 #include "MemoryManager.hpp" 
00037 #include "DLIList.hpp" 
00038 #include "CubitBox.hpp" 
00039 #include "FacetEntity.hpp" 
00040 #include "CubitVector.hpp" 
00041 #include "CubitPlane.hpp" 
00042  
00043 class CubitFacetEdge; 
00044 class CubitPoint; 
00045  
00046 class CubitFacet : public FacetEntity 
00047 { 
00048 public: 
00049   static const int point_edge_conn[30][2]; 
00050   static const int point_facet_conn[16][3]; 
00051   static const double my_points[15][3]; 
00052  
00053 protected: 
00054  
00055   CubitPlane *cachedPlane; 
00056     //- cached plane for this facet 
00057  
00058   CubitBox bBox; 
00059     //- The bounding box for the facet 
00060  
00061   double facetWeight; 
00062     //- for interpolation 
00063  
00064   CubitVector *patchCtrlPts; 
00065     //- control points for triangular bezier batch 
00066  
00067   int markedFlag; 
00068     //- generic marker for list sorting.  Assume 0. Users must clean after use. 
00069  
00070   int isFlat; 
00071     //- facet is flat 
00072  
00073   int isBackwards; 
00074     //- facet is oriented backwards wrt. orientation of surface 
00075  
00076   int toolID; 
00077     //- id of facet eval tool 
00078  
00079 public: 
00080   CubitFacet(); 
00081  
00082 //------------------------------------------------------------------------ 
00083 // The following functions are pure virtual and must be  
00084 // implemented in the child class (ie. CubitFacetData or equivalent) 
00085  
00086   virtual ~CubitFacet(); 
00087  
00088   CubitVector normal();  
00089     //- Returns the normal to this facet. 
00090 
00091   CubitVector update_normal( void );
00092   //- update the plane and return the new normal
00093 
00094 
00095   const CubitBox& bounding_box() {return bBox;}; 
00096   void bounding_box( CubitBox &box ) 
00097   { bBox = box; } 
00098   void reset_bounding_box(); 
00099     //- returns/sets the bounding box of the facet 
00100  
00101   void weight(double facweight) { facetWeight = facweight; } 
00102   double weight() { return facetWeight; } 
00103     //- get/set weight 
00104  
00105   void get_control_points( CubitVector points[6] ); 
00106   void set_control_points( CubitVector points[6] ); 
00107   void set_control_points( const double *pt_array );
00108   CubitVector *control_points() {return patchCtrlPts;};
00109     //- get and set the bezier patch internal control points 
00110  
00111   int eval_order() 
00112     { return (patchCtrlPts == NULL) ? 0 : 4; } 
00113     //- return the evaluation order of the facet.  Currently only 
00114     //- order 0 (linear) and 4 (b-spline patch) are implemented 
00115      
00116   virtual CubitPoint* point( int index ) = 0; 
00117     //Get the point at the specified index. 
00118     //asserts that the index is in range, for a 
00119     //triangle, 0 <= index <= 2. 
00120  
00121   void marked(int mark) {markedFlag = mark;}; 
00122   int marked() {return markedFlag;}; 
00123     //- generic marking functions. 
00124  
00125   int is_flat(); 
00126   void is_flat(int flat) {isFlat = flat;}; 
00127     //- get/set isFlat 
00128      
00129   const CubitPlane& plane(); 
00130   void plane(CubitPlane &this_plane); 
00131   void update_plane();  
00132     //- Cache and return the plane containing this triangle.  
00133  
00134   int is_backwards() {return isBackwards;}; 
00135   void is_backwards( int flipped ) { isBackwards = flipped; } 
00136     //- return whether the facet was reoriented 
00137  
00138   virtual int id() = 0; 
00139   virtual void set_id( int ii ) = 0; 
00140   int tool_id(){return toolID;} 
00141   void set_tool_id(int tool_id){toolID = tool_id;} 
00142        
00143   virtual CubitFacetEdge *edge( int index ) = 0; 
00144   virtual void edge( CubitFacetEdge *the_edge, int index ) = 0; 
00145     //- get and set edge pointers 
00146  
00147   virtual void edge_use( int direction, int index ) = 0; 
00148   virtual int edge_use( int index ) = 0; 
00149     //- get and set the edge uses.  Direction is 1 or -1 based 
00150     //- upon the orientation of the edge with respect to a CCW orientation 
00151     //- of the facet 
00152  
00153   virtual void flip() = 0; 
00154     //- reorient the facet 
00155  
00156 //--------------------------------------------------------------------- 
00157 //  The following virtual functions are optional.  Implement them 
00158 //  based upon the application's need.  If they are called without 
00159 //  being implemented, an assertion will occur. 
00160  
00161   virtual int sense(int /*index*/){ assert(0); return -1;}
00162   //- Gives the direction of the edge given the edge index
00163 
00164   virtual CubitPoint* split_edge( CubitPoint* edge_pt1,  
00165                                   CubitPoint* edge_pt2, 
00166                                   const CubitVector& position ); 
00167     //R CubitPoint 
00168     //R- The new CubitPoint created. 
00169     //I edge_pt1, edge_pt2 
00170     //I- The end points of an edge of this triangle. 
00171     //I position 
00172     //I- The position at which to split the edge. 
00173     //- Split an edge on this triangle and the other triangle 
00174     //- sharing the edge, if it exists. 
00175     //- 
00176     //- Note:  No check is done on the location of the split 
00177     //-        position. 
00178      
00179   virtual CubitPoint* insert_point( const CubitVector& position, 
00180                                     CubitFacet*& new_tri1, 
00181                                     CubitFacet*& new_tri2 ); 
00182     //R CubitPoint 
00183     //R- The new CubitPoint created. 
00184     //I position 
00185     //I- The position at which to insert a point in the triangle. 
00186     //O new_facet1, new_facet2 
00187     //O- The two new facets created. 
00188     //- Insert a point in the interior of this triangle. 
00189     //- 
00190     //- Note:  No check is done on the location of the split 
00191     //-        position. 
00192  
00193   virtual CubitStatus closest_point( const CubitVector &point,  
00194                                      CubitVector &closest_point); 
00195     //- Sets the closest point on the plane defined by  
00196     //- this facet to the point in space. 
00197     //- If the normal length to the facet is 0, it will return CUBIT_FAILURE. 
00198  
00199 //---------------------------------------------------------------------- 
00200 // The following functions access the data in a child class 
00201  
00202   CubitVector center(); 
00203     //- Returns the center of the facet. 
00204  
00205   void debug_draw(int color=-1, int flush_it = 1, int draw_uv=0); 
00206     //- draws the current facet. 
00207  
00208   CubitStatus closest_point_trimmed( const CubitVector &point,  
00209                                      CubitVector &closest_point, 
00210                                      CubitPoint *&next_edge_p1,  
00211                                      CubitPoint *&next_edge_p2 ); 
00212     //- returns the closest point on this facet to the point in space. 
00213     //- If the point is not in the facet, then the edge to which it was closest 
00214     //- will be set and returned.  Other wise they will be "NULLED". 
00215  
00216   void get_edge_1( CubitPoint *&p1, CubitPoint *&p2 ) 
00217     { p1 = point(0); p2 = point(1);} 
00218   void get_edge_2( CubitPoint *&p1, CubitPoint *&p2 ) 
00219     { p1 = point(1); p2 = point(2);} 
00220   void get_edge_3( CubitPoint *&p1, CubitPoint *&p2 ) 
00221     { p1 = point(2); p2 = point(0);} 
00222     //- Get the points that define the three edges of the facet. 
00223   void get_edge_pts( int index, CubitPoint *&p1, CubitPoint *&p2 ); 
00224     //- get the points that define an edge 
00225     //- The index of the edge corresponds to the point index on 
00226     //- the facet opposite the edge 
00227  
00228   CubitFacetEdge *edge_from_pts( CubitPoint *p1, CubitPoint *p2, int &index ); 
00229     //- return the edge pointer based on its end points 
00230   int edge_index( CubitPoint *p1, CubitPoint *p2, int &sense ); 
00231   int edge_index( CubitFacetEdge *edge ); 
00232     //- return the index of the edge on the facet 
00233   int point_index( CubitPoint *pt ); 
00234     //- return the index of the point on the facet 
00235      
00236   void opposite_edge( CubitPoint* point,  
00237                       CubitPoint*& p1, CubitPoint*& p2 ); 
00238     //- Get the edge on the triangle opposite of the passed point. 
00239     //- p1 and p2 will be passed back as NULL if point is not a 
00240     //- point on this triangle. 
00241 
00242   
00243   CubitPoint *opposite_point( CubitFacetEdge *edge );
00244   //- returns the opposite point of input edge.  Input edge should be incident on facet. 
00245   //- If input edge is not incident on facet then any of the one point can be returned
00246  
00247   
00248   void points( CubitPoint *&p0, CubitPoint *&p1, CubitPoint *&p2 ) 
00249     { p0 = point(0); p1 = point(1); p2 = point(2); }
00250   void points( CubitPoint *pts[3] )
00251     { pts[0] = point(0); pts[1] = point(1); pts[2] = point(2); }
00252   void tri_nodes( CubitPoint *&p0, CubitPoint *&p1, CubitPoint *&p2 )
00253     { points( p0, p1, p2); } 
00254   void points(DLIList<CubitPoint*> &point_list ) 
00255     { for ( int i = 0; i < 3; i++ ) 
00256       point_list.append(point(i)); 
00257     } 
00258   void facets(DLIList<CubitFacet*> &facet_list ) 
00259     { facet_list.append( this ); } 
00260   void edges(DLIList<CubitFacetEdge*> &edge_list ) 
00261     { for ( int i = 0; i < 3; i++ ) 
00262       edge_list.append(edge(i)); 
00263     } 
00264  
00265   CubitBoolean contains(CubitPoint *p1); 
00266     //- Returns TRUE/FALSE if the point defines this facet. 
00267 
00268   CubitFacetEdge* shared_edge( CubitFacet *cubit_facet );
00269  
00270   CubitFacet* shared_facet( CubitPoint *p1, CubitPoint *p2 ); 
00271     //- Returns the "other" facet attached to this edge. (if  
00272     //- there is one., other wise returns NULL). 
00273   void shared_facets( CubitPoint *p1, CubitPoint *p2, 
00274                       DLIList <CubitFacet *> &adj_facet_list); 
00275     //- Returns all adjacent facets to this edge (not including 
00276     //- this facet) 
00277   
00278   CubitFacet *adjacent( int &index, int *tool_data )  
00279     //- Returns all adjacent facets to this edge index(not including 
00280     //- this facet) 
00281   {
00282         //convert MESHING TRI edge index to GEOMETRY FACET edge index
00283         index = (index+2)%3;
00284         CubitPoint *p1, *p2; 
00285    
00286         get_edge_pts( index, p1, p2 ); 
00287         return shared_facet_on_surf( p1, p2, *tool_data ); 
00288   } 
00289 
00290   CubitPoint* next_node(CubitPoint *current_point)
00291   {
00292     int index = point_index(current_point);
00293     return point((index+1)%3);
00294   }
00295     //- return the adjacent triangle at the edge index 
00296   CubitFacet* shared_facet_on_surf( CubitPoint *p1, CubitPoint *p2, int tool_id ); 
00297     //- same as above except also matches tool_id with toolID 
00298  
00299   double min_diagonal(); 
00300     //- Returns the length of the minimum diagonal of the triangle. 
00301    
00302   double angle( CubitPoint *pt ); 
00303     //- return the angle (radians) at one of the points on the facet 
00304  
00305   void update_bezier_bounding_box( ); 
00306     //- Update the facet bounding box based on its control polygon 
00307  
00308   CubitFacetEdge *prev_edge( CubitFacetEdge *edge ); 
00309   CubitFacetEdge *next_edge( CubitFacetEdge *edge ); 
00310     //- return the prvious or next edge on the facet 
00311   
00312   int other_index( CubitPoint* pt1, CubitPoint* pt2 ); 
00313  
00314   CubitStatus evaluate_position( const CubitVector &start_position, 
00315                                  CubitVector *eval_point, 
00316                                  CubitVector *eval_normal = NULL );   
00317  
00318   CubitStatus evaluate( CubitVector &areacoord,  
00319                         CubitVector *eval_point, 
00320                         CubitVector *eval_normal = NULL );  
00321  
00322   void get_parents(DLIList<FacetEntity *> &){}; 
00323     // dummy for this class 
00324  
00325   CubitFacetEdge *next_edge_at_point( CubitFacetEdge *edge_ptr, 
00326                                       CubitPoint *point_ptr ); 
00327     // return the next edge on the triangle at the point 
00328  
00329   CubitStatus get_edge_control_points( CubitVector P[3][5] ); 
00330     // get the control points on the facet edges 
00331  
00332   double area(); 
00333     // return the area of the facet 
00334 
00335   double aspect_ratio();
00336 
00337 
00338   CubitStatus init_patch(  );
00339     // computes the interior control points for the facet and
00340     // stores them with the facet.  Assumes edge control points
00341     // have already been computed
00342 
00343   void add_edge(CubitFacetEdge *edge);
00344    //- add an existing edge to a facet
00345 
00346   void unlink_from_children( void );
00347  
00348 }; 
00349  
00350 inline void CubitFacet::plane(CubitPlane &this_plane)  
00351 { 
00352   this_plane = plane(); 
00353 } 
00354 
00355 template <> struct DLIListSorter<CubitFacet*>
00356 {
00357   bool operator()(CubitFacet* a, CubitFacet* b) { return a->id() < b->id(); }
00358 };
00359 
00360 #endif 
00361 
00362 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines