cgma
|
00001 //----------------------------------------------------------------------------- 00002 // 00003 // File: CubitFacetEdge.hpp 00004 // 00005 // Purpose: optionally used with the CubitFacet class if information 00006 // is required at the edges of facets 00007 // 00008 // Notes: Note that this class does not contain any private data. 00009 // All data should be defined within the child classes inherited 00010 // from this class. The current Cubit data class that inherits 00011 // from CubitFacetEdge is CubitFacetEdgeData. This is done so that 00012 // other applications using CubitFacetEdges can use their own 00013 // edge data, but take advantage of the CGM/Cubit functionality. 00014 // Please do not add private data to this class; instead add the 00015 // data to the children and access through virtual functions. 00016 // 00017 // Do not create a CubitFacetEdge directly. For example, don't do: 00018 // CubitFacetEdge *cfe = new CubitFacetEdge(...); 00019 // You should instead create the appropriate child class, and 00020 // cast it to a CubitFacetEdge for use. For example: 00021 // CubitFacetEdge *cfe = (CubitFacetEdge *) new CubitFacetEdgeData(...); 00022 // 00023 //----------------------------------------------------------------------------- 00024 00025 #ifndef CUBITFACETEDGE_HPP 00026 #define CUBITFACETEDGE_HPP 00027 00028 // Include for CubitBoolean 00029 #include "CubitDefines.h" 00030 #include "CubitVector.hpp" 00031 #include "DLIList.hpp" 00032 #include "FacetEntity.hpp" 00033 00034 class CubitFacet; 00035 class CubitPoint; 00036 class CubitBox; 00037 00038 class CubitFacetEdge : public FacetEntity 00039 { 00040 private: 00041 00042 protected: 00043 00044 CubitVector controlPoints[3]; 00045 //- bezier points on the edge 00046 00047 int bezierOrder; 00048 //- bezier order 00049 00050 int markedFlag; 00051 //- marked flag 00052 00053 IttyBit isFeature; 00054 //- set if this edge is a feature 00055 00056 CubitBoolean isFlipped; 00057 00058 public: 00059 CubitFacetEdge(); 00060 //- constructors 00061 virtual ~CubitFacetEdge(); 00062 //- destructor 00063 virtual int id() = 0; 00064 virtual void set_id(int /*ent_id*/) {}; 00065 00066 int is_flipped() 00067 { 00068 if(isFlipped) 00069 return 1; 00070 return 0; 00071 } 00072 void is_flipped ( int flipped) 00073 { 00074 if(flipped) 00075 isFlipped = CUBIT_TRUE; 00076 else 00077 isFlipped = CUBIT_FALSE; 00078 } 00079 00080 void toggle_is_flipped() 00081 { 00082 isFlipped = !isFlipped; 00083 } 00084 00085 00086 virtual CubitPoint *point( int index ) = 0; 00087 //- get one of its points 00088 virtual CubitFacet *adj_facet( int index) = 0; 00089 //- get one of its adjacent facets 00090 virtual int bezier_order() {return bezierOrder;}; 00091 virtual int control_points( CubitVector *ctrl_pts ); 00092 //- get the control points (return the order) 00093 virtual CubitVector *control_points() { return controlPoints; }; 00094 virtual void control_points( CubitVector *ctrl_pts, int order ); 00095 //- set the bezier control points on the edge. 00096 //- end points are assumed to be the first and last 00097 //- ctrl pt so they are not passed in. Pass in order-1 00098 //- control points (max order = 4) 00099 virtual CubitStatus control_points( CubitFacet *facet, CubitVector *ctrl_pts ); 00100 //- return the control pons on the edge of a facet based 00101 //- on its edge use direction 00102 virtual void get_control_points( CubitPoint *point_ptr, CubitVector ctrl_pts[3] ); 00103 virtual void set_control_points( CubitPoint *point_ptr, CubitVector ctrl_pts[3] ); 00104 //- get and set control points oriented with respect to the 00105 //- point_ptr (ie. point_ptr is the first control point on the edge) 00106 //- Note: only gets and sets the middle three control points. The 00107 //- other 2 are the edge vertices. 00108 void set_control_points( const double *ctrl_pt_array ); 00109 virtual void set_flag( int my_flag ) {markedFlag = my_flag;}; 00110 virtual int get_flag( ) {return markedFlag;}; 00111 virtual void facets(DLIList<CubitFacet*> &facet_list ) = 0; 00112 virtual void edges(DLIList<CubitFacetEdge*> &edge_list ) = 0; 00113 virtual void points(DLIList<CubitPoint*> &point_list ) = 0; 00114 virtual int num_adj_facets() = 0; 00115 void tris(DLIList<CubitFacet*> &facet_list){ facets(facet_list); } 00116 void tris(int* /*tool_id*/, 00117 DLIList<CubitFacet*> &facet_list){ facets(facet_list); } 00118 00119 00120 //- Implement in the child class if need be. 00121 //- Assertion will occur if not implemented in the child class 00122 virtual void add_facet(CubitFacet * /*facet_ptr*/){ assert(0); } 00123 virtual CubitStatus remove_facet(CubitFacet * /*facet_ptr*/) = 0; 00124 virtual CubitPoint *start_node() = 0; 00125 virtual CubitPoint *end_node() = 0; 00126 virtual void flip() = 0; 00127 00128 virtual int number_tris() { return num_adj_facets(); } 00129 virtual int number_faces() { return 0; } 00130 00131 virtual void marked (int my_flag ) { set_flag(my_flag); } 00132 virtual int marked() { return get_flag(); } 00133 00134 00135 CubitStatus evaluate_position( const CubitVector &start_position, 00136 CubitVector *eval_point, 00137 CubitVector *eval_tangent); 00138 //- find closet point on non-linear edge 00139 CubitStatus evaluate( double &t, 00140 CubitVector *eval_point, 00141 CubitVector *eval_tangent ); 00142 CubitStatus evaluate_single(double &t, 00143 CubitVector *outv); 00144 CubitStatus evaluate_single_tangent(double &t, 00145 CubitVector *outv); 00146 CubitStatus evaluate_2nd_derivative(double &t, 00147 CubitVector *outv); 00148 //- evaluate location -1 < t < 1 00149 CubitStatus closest_point(const CubitVector &point, 00150 CubitVector &closest_point ); 00151 //- return closest point to linear segment 00152 00153 CubitStatus intersect(CubitVector &aa, CubitVector &bb, // end point of segment 00154 CubitVector &norm, // normal of the common plane 00155 CubitVector &qq, // return the intersection point 00156 CubitBoolean &does_intersect ); 00157 // intersect the edge with a segment. Assumes segment and edge 00158 // are on the same plane (project to facet plane first) 00159 00160 void boundary_edge_points( CubitPoint * &pt0, 00161 CubitPoint * &pt1, 00162 int tool_id = 0); 00163 // return oriented points on a boundary facet edge 00164 00165 double dist_to_edge( const CubitVector &this_point, 00166 CubitVector &close_point, 00167 CubitBoolean &outside_edge ); 00168 // return distance from point to an edge 00169 00170 CubitStatus proj_to_line( const CubitVector &this_point, 00171 CubitVector &proj_point ); 00172 // project point to line defined by edge 00173 00174 CubitStatus edge_tangent( const CubitVector &point_on_edge, 00175 CubitVector &tangent ); 00176 // compute tangent vector of edge 00177 CubitStatus edge_curvature( const CubitVector &point_on_edge, 00178 CubitVector &curvature, 00179 CubitFacetEdge *closest_edge ); 00180 // compute curvature vector of edge 00181 double length(); 00182 00183 CubitVector position_from_fraction( double zero_to_one ); 00184 CubitVector center() { return position_from_fraction(0.5); } 00185 00186 // compute and return the edge length 00187 CubitPoint* other_point( CubitPoint *point_ptr ); 00188 // return the other point on the facet edge 00189 00190 void get_parents(DLIList<FacetEntity *> &facet_list); 00191 // return the adjacent facets to edge 00192 00193 CubitFacet *other_facet( CubitFacet *facet_ptr ); 00194 // return the other facet at the edge 00195 00196 CubitFacet *other_facet_on_surf( CubitFacet *facet_ptr ); 00197 // return the other facet at the edge that has the 00198 // same tool id 00199 00200 int num_adj_facets_on_surf( int tool_id ); 00201 // return number of adjacent facets with the indicated 00202 // tool id 00203 00204 CubitFacet *adj_facet_on_surf( int tool_id ); 00205 // return first facet adjacent the edge with the 00206 // indicated tool id 00207 00208 CubitBoolean contains( CubitPoint *point_ptr ); 00209 //- determines if point is contained in edge 00210 00211 void set_as_feature() { isFeature = 1; } 00212 CubitBoolean is_feature( ){return (isFeature ? CUBIT_TRUE : CUBIT_FALSE); } 00213 // set and get the isFeature bit 00214 00215 void debug_draw(int color = -1, int flush = 1, int draw_uv=0); 00216 // debug drawing 00217 00218 CubitPoint *shared_point( CubitFacetEdge *edge_ptr ); 00219 // get the common point 00220 void add_facets( ); 00221 // add this edge to its adjacent facets 00222 00223 CubitBox bounding_box(); 00224 // return the bounding box of the edge 00225 00226 static int intersect_2D_segments( double P0[2], double P1[2], 00227 double P2[2], double P3[2], 00228 double qq[4] ); 00229 static int intersect_intervals( double u0, double u1, 00230 double v0, double v1, 00231 double w[2] ); 00232 static CubitStatus order_edge_list(DLIList<CubitFacetEdge*> &edge_list, 00233 CubitPoint *start_point, 00234 CubitPoint *&end_point); 00235 static CubitPoint *find_start_point_for_edge_list(DLIList<CubitFacetEdge*> edge_list); 00236 00237 double angle_between_facets(); 00238 00239 inline int less_than(CubitFacetEdge*& e1, CubitFacetEdge*& e2) 00240 { 00241 double len1 = e1->length(); 00242 double len2 = e2->length(); 00243 00244 if (len1 == len2) return 0; 00245 return (len1 < len2) ? -1 : 1; 00246 } 00247 00248 }; 00249 00250 inline void CubitFacetEdge::control_points( 00251 CubitVector *ctrl_pts, int order ) 00252 { 00253 assert(order > 0 && order <=4); 00254 bezierOrder = order; 00255 for(int i=0; i<order-1; i++){ 00256 controlPoints[i] = ctrl_pts[i]; 00257 } 00258 } 00259 00260 //====================================================================== 00261 // Function: get_control_points (PUBLIC) 00262 // Description: get control points oriented with respect to the 00263 // point_ptr (ie. point_ptr is the first control point 00264 // on the edge) 00265 // Note: only gets and sets the middle three control points. The 00266 // other 2 are the edge vertices. 00267 // Author: sjowen 00268 // Date: 05/01 00269 //====================================================================== 00270 inline void CubitFacetEdge::get_control_points( CubitPoint *point_ptr, 00271 CubitVector ctrl_pts[3] ) 00272 { 00273 DLIList<CubitPoint*> my_points; 00274 points(my_points); 00275 00276 if (point_ptr == my_points.get()) 00277 { 00278 ctrl_pts[0] = controlPoints[0]; 00279 ctrl_pts[1] = controlPoints[1]; 00280 ctrl_pts[2] = controlPoints[2]; 00281 } 00282 else if(point_ptr == my_points.next()) 00283 { 00284 ctrl_pts[0] = controlPoints[2]; 00285 ctrl_pts[1] = controlPoints[1]; 00286 ctrl_pts[2] = controlPoints[0]; 00287 } 00288 else 00289 { 00290 assert(0); // point_ptr does not match either point 00291 } 00292 } 00293 00294 //====================================================================== 00295 // Function: set_control_points (PUBLIC) 00296 // Description: set control points oriented with respect to the 00297 // point_ptr (ie. point_ptr is the first control point 00298 // on the edge) 00299 // Note: only gets and sets the middle three control points. The 00300 // other 2 are the edge vertices. 00301 // Author: sjowen 00302 // Date: 05/01 00303 //====================================================================== 00304 inline void CubitFacetEdge::set_control_points( CubitPoint *point_ptr, 00305 CubitVector ctrl_pts[3] ) 00306 { 00307 DLIList<CubitPoint*> my_points; 00308 points(my_points); 00309 00310 if (point_ptr == my_points.get()) 00311 { 00312 controlPoints[0] = ctrl_pts[0]; 00313 controlPoints[1] = ctrl_pts[1]; 00314 controlPoints[2] = ctrl_pts[2]; 00315 } 00316 else if(point_ptr == my_points.next()) 00317 { 00318 controlPoints[0] = ctrl_pts[2]; 00319 controlPoints[1] = ctrl_pts[1]; 00320 controlPoints[2] = ctrl_pts[0]; 00321 } 00322 else 00323 { 00324 assert(0); // point_ptr does not match either point 00325 } 00326 } 00327 00328 template <> struct DLIListSorter<CubitFacetEdge*> 00329 { 00330 bool operator()(CubitFacetEdge* a, CubitFacetEdge* b) { return a->id() < b->id(); } 00331 }; 00332 00333 #endif 00334 00335