cgma
CubitPoint.hpp
Go to the documentation of this file.
00001 //-----------------------------------------------------------------------------
00002 //
00003 //  File: CubitPoint.hpp
00004 //
00005 //  Purpose:  Point Class used for mesh based geometry and other tools.  It is
00006 //            primarily used in conjuction with CubitFacet and CubitFacetEdge 
00007 //            classes.
00008 //
00009 //  Notes:    Note that this class does not contain any private data.
00010 //            All data should be defined within the child classes inherited
00011 //            from this class.  The current Cubit data class that inherits
00012 //            from CubitPoint is CubitPointData.  This is done so that 
00013 //            other applications using CubitPoints can use their own
00014 //            point data, but take advantage of the CGM/Cubit functionality.
00015 //            Please do not add private data to this class; instead add the
00016 //            data to the children and access through virtual functions.
00017 // 
00018 //            Do not create a CubitPoint directly.  For example, don't do: 
00019 //              CubitPoint *cp = new CubitPoint(...);
00020 //            You should instead create the appropriate child class, and 
00021 //            cast it to a CubitPoint for use.  For example:
00022 //              CubitPoint *cp = (CubitPoint *) new CubitPointData(...);
00023 //                        
00024 //-----------------------------------------------------------------------------
00025 
00026 #ifndef CUBITPOINT_HPP
00027 #define CUBITPOINT_HPP
00028 
00029 // Include for CubitBoolean
00030 #include "CubitDefines.h"
00031 #include "CubitVector.hpp"
00032 #include "DLIList.hpp"
00033 #include "MemoryManager.hpp"
00034 #include "ToolDataUser.hpp"
00035 #include "CubitMatrix.hpp"
00036 #include "FacetEntity.hpp"
00037 class CubitFacet;
00038 class CubitQuadFacet;
00039 class CubitFacetEdge;
00040 class CubitPoint;
00041 class CubitTransformMatrix;
00042 class Surface;
00043 class CubitBox;
00044 
00045 class CubitPoint : public FacetEntity
00046 {
00047 private:
00048 
00049   static double boxTol;
00050 
00051 protected:
00052 
00053   int markedFlag;
00054     //-generic marking flag.
00055 
00056   CubitVector *surfNormal;
00057     //- The normalized surface normal (if required)
00058 
00059   double dCoef;
00060     //- D coeficient in tangent plane equation Ax+By+Cz+D=0
00061     //- where A,B,C is surfNormal
00062 
00063   double uVal, vVal, sizeVal;
00064     //- parametric location of point
00065 
00066   CubitVector *surfU, *surfV;
00067     //- Orthogonal surface tangent vectors at the point
00068 
00069   double *coefVector;
00070     //- coefficients for quadric surface approximation
00071 
00072   IttyBit isFeature;
00073     //- set if this point is a feature
00074 
00075 public:
00076 
00077   CubitPoint();
00078   virtual ~CubitPoint();
00079 
00080   virtual int id() = 0; 
00081   virtual void set_id( int ) {};
00082 
00083   virtual double x() = 0;
00084   virtual double y() = 0;
00085   virtual double z() = 0;
00086   virtual void set( const CubitVector &pos ) = 0;
00087 
00088   virtual void marked(int marked) {markedFlag = marked;};
00089   virtual int marked() {return markedFlag;};
00090       
00091   virtual CubitVector coordinates() const = 0;
00092   virtual void coordinates(double point_array[3]) = 0;
00093   
00094   virtual void add_facet( CubitFacet *facet) = 0;
00095   virtual void remove_facet( CubitFacet *facet) = 0;
00096   virtual int num_adj_facets() = 0;
00097 
00098   virtual void facets( DLIList<CubitFacet*> &facet_list ) = 0;
00099   virtual void edges( DLIList<CubitFacetEdge*> &edge_list ) = 0;
00100   virtual void points( DLIList<CubitPoint*> &point_list ) = 0;
00101 
00102   virtual void tris( DLIList<CubitFacet*> &facet_list ) { facets(facet_list); }
00103 
00104   virtual void normal( CubitVector &surf_norm );
00105   virtual CubitVector normal();
00106   virtual CubitVector* normal_ptr();
00107   
00108   virtual void set_normal( CubitVector &surf_norm );
00109   virtual void reset_normal( );
00110 
00111   virtual void d_coef( const double d_coefficient ) {dCoef = d_coefficient;};
00112   virtual double d_coef() {return dCoef;};
00113 
00114   virtual double u() { return uVal; };
00115   virtual double v() { return vVal; };
00116   virtual double size() {return sizeVal; };
00117   virtual void set_uv( double u, double v ) { uVal = u; vVal = v; };
00118   virtual void set_uvs(double u, double v, double s) {uVal = u; vVal = v; sizeVal = s; }
00119     //- get and set the u-v coordinates (careful with internal boundaries - see TDFacetBoundarPoint)
00120   virtual CubitStatus get_uv( CubitFacet *facet, double &u, double &v );
00121   virtual CubitStatus get_uvs( CubitFacet *facet, double &u, double &v, double &s);
00122     //- return the u-v coords with respect to the surface that the facet is on
00123   
00124   virtual void du( CubitVector &duvec );
00125   virtual CubitVector du();
00126 
00127   virtual void dv( CubitVector &dvvec );
00128   virtual CubitVector dv();
00129 
00130   virtual double *coef_vector( );
00131   virtual void coef_vector( const CubitMatrix& coef );
00132 
00133   virtual CubitStatus merge_points( CubitPoint *cp, CubitBoolean keep_point = CUBIT_FALSE );
00134 
00135   void shared_facets( CubitPoint* other_point, 
00136                       CubitFacet*& facet1, 
00137                       CubitFacet*& facet2 );
00138 
00139   void shared_facets( CubitPoint* other_point, 
00140                       DLIList<CubitFacet*>& result_list );
00141 
00142   CubitFacetEdge *shared_edge( CubitPoint* other_point );
00143 
00144   
00145   void adjacent_points( CubitPoint **adj_points,
00146                         int &num_adj_points );
00147   void adjacent_points( DLIList<CubitPoint*>& result_list );
00148     //- return array of points sharing adjacent facets
00149 
00150   CubitBox bounding_box();
00151     //-return a box around this point
00152 
00153   void facets_on_surf( int surf_id, DLIList<CubitFacet *> &facet_list,
00154                        CubitBoolean &on_internal_boundary );
00155     //- return facets adjacent this point that are on the given surface
00156     //- surf_id is the FacetEvalTool ToolID
00157 
00158   CubitVector normal( CubitFacet *facet_ptr );
00159   CubitVector normal( CubitQuadFacet *qfacet_ptr );
00160   CubitVector normal( CubitFacetEdge *edge_ptr );
00161     //- return normal with respect to the facet and edge
00162 
00163   CubitVector tangent( CubitFacetEdge *edge_ptr, double mindot );
00164     //- return tangent with respect to the edge
00165   void next_feature_edges( CubitFacetEdge *this_edge_ptr,
00166                            DLIList <CubitFacetEdge *> feature_edge_list );
00167     //- given a facet boundary edge and this point, get a list
00168     //- of the next fetaure edges at this point
00169 
00170   CubitVector project_to_tangent_plane( CubitVector &pt );
00171     //- Project a point to the tangent plane defined at the CubitPoint
00172 
00173   void transform_to_local( CubitVector &glob_vec,
00174                            CubitVector &loc_vec );
00175   void transform_to_global( CubitVector &loc_vec,
00176                             CubitVector &glob_vec );
00177     //- transform a point between local and global system
00178 
00179   void define_tangent_vectors();
00180     //- set up the tangent vectors at the point for quadratic interpolation
00181 
00182   void get_parents( DLIList<FacetEntity*> &facet_list );
00183 
00184   void debug_draw( int color = -1, int flush = 1, int draw_uv=0 );
00185     // debug drawing
00186 
00187   void compute_avg_normal();
00188     //- compute the avg normal at this point based on adjacent facets
00189 
00190   CubitFacetEdge *get_edge( CubitPoint *other_point );
00191     //- return the edge between two points if one exists
00192 
00193   void transform(CubitTransformMatrix &tfmat);
00194   void rotate_normal(CubitTransformMatrix &rotmat);
00195     //- apply transformations to the point
00196     
00197   CubitStatus check_inverted_facets( const CubitVector& new_position );
00198     //- Check if moving this CubitPoint to the passed position
00199     //- will invert any adjacent facets.  Returns true if no facets
00200     //- will be inverted, false if one or more facets will be 
00201     //- inerted when the point is moved.
00202 
00203   void set_as_feature() { isFeature = 1; }
00204   CubitBoolean is_feature( ){return (isFeature ? CUBIT_TRUE : CUBIT_FALSE); }
00205     // set and get the isFeature bit
00206 
00207   static void set_box_tol( double tol ) {boxTol = tol;}
00208 };
00209 
00210 inline void CubitPoint::coef_vector(const CubitMatrix &input_matrix) 
00211 {
00212   if (!coefVector) coefVector = new double[5];
00213   for (int i=0; i<5; i++) {
00214     coefVector[i] = input_matrix.get(i,0);
00215   }
00216 }
00217 
00218 inline void CubitPoint::normal( CubitVector &surf_norm )
00219 {
00220   if(!surfNormal) surfNormal = new CubitVector (surf_norm);
00221   else *surfNormal = surf_norm;
00222 }
00223 
00224 inline CubitVector CubitPoint::normal()
00225 {
00226   if (surfNormal==NULL) compute_avg_normal();
00227   return *surfNormal;
00228 }
00229 
00230 inline CubitVector* CubitPoint::normal_ptr()
00231 {
00232   return surfNormal;
00233 }
00234 
00235 inline void CubitPoint::set_normal( CubitVector &surf_norm )
00236 {
00237   *surfNormal = surf_norm;
00238 }
00239 
00240 inline void CubitPoint::reset_normal()
00241 {
00242   compute_avg_normal();
00243 }
00244 
00245 inline void CubitPoint::du( CubitVector &duvec )
00246 {
00247   if(!surfU) surfU = new CubitVector (duvec);
00248   else *surfU = duvec;
00249 }
00250 
00251 inline void CubitPoint::dv( CubitVector &dvvec )
00252 {
00253   if(!surfV) surfV = new CubitVector (dvvec);
00254   else *surfV = dvvec;
00255 }
00256 
00257 inline CubitVector CubitPoint::du()
00258 {
00259   assert(surfU != NULL);
00260   return *surfU;
00261 }
00262 
00263 inline CubitVector CubitPoint::dv()
00264 {
00265   assert(surfV != NULL);
00266   return *surfV;
00267 }
00268 
00269 inline double *CubitPoint::coef_vector( )
00270 {
00271   assert (coefVector != NULL);
00272   return coefVector;
00273 }
00274 
00275 class CubitPointComparator {
00276 public: 
00277   bool operator () (CubitPoint * a, CubitPoint * b) const
00278   {
00279     return ( a->x() < b->x() ) || (a->x()==b->x() && a->y()<b->y()) || (a->x() == b->x() && a->y()==b->y() && a->z() < b->z() );
00280   }
00281 };
00282 
00283 template <> struct DLIListSorter<CubitPoint*>
00284 {
00285   bool operator()(CubitPoint* a, CubitPoint* b) { return a->id() < b->id(); }
00286 };
00287 
00288 
00289 #endif
00290 
00291 
00292 
00293 
00294 
00295 
00296 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines