cgma
Curve.hpp
Go to the documentation of this file.
00001 //-------------------------------------------------------------------------
00002 // Filename      : Curve.hpp
00003 //
00004 // Purpose       : 
00005 //
00006 // Special Notes :
00007 //
00008 // Creator       : Xuechen Liu
00009 //
00010 // Creation Date : 08/02/96
00011 //
00012 // Owner         : Malcolm J. Panthaki
00013 //-------------------------------------------------------------------------
00014 
00015 #ifndef CURVE_HPP
00016 #define CURVE_HPP
00017 
00018 // ********** BEGIN STANDARD INCLUDES      **********
00019 // ********** END STANDARD INCLUDES        **********
00020 
00021 // ********** BEGIN CUBIT INCLUDES         **********
00022 #include "CubitDefines.h"
00023 #include "RefEdge.hpp"
00024 
00025 #include "GeometryEntity.hpp"
00026 // ********** END CUBIT INCLUDES           **********
00027 
00028 // ********** BEGIN FORWARD DECLARATIONS   **********
00029 template <class X> class DLIList;
00030 class FacetEvalTool;
00031 class TBPoint;
00032 // ********** END FORWARD DECLARATIONS     **********
00033 
00034 // ********** BEGIN ENUM DEFINITIONS       **********
00035 // ********** END ENUM DEFINITIONS         **********
00036 
00037 class CUBIT_GEOM_EXPORT Curve : public GeometryEntity
00038 {
00039 public :
00040   
00041   Curve();
00042     //- The default constructor
00043   
00044   virtual ~Curve();
00045     //- The destructor  
00046 
00047   typedef TBPoint ChildType;
00048 
00049   virtual CubitSense relative_sense(Curve *other_curve);
00050     //- given another curve, return whether the curves are "aligned" (CUBIT_FORWARD), 
00051     //- oppositely aligned (CUBIT_REVERSED), or inconclusive (CUBIT_UNKNOWN)
00052   
00053   virtual CubitStatus get_point_direction( CubitVector& origin, 
00054                                            CubitVector& direction );
00055     //- Only valid for straight lines
00056     //- Finds the underlying line's origin and direction unit vector
00057     //- Returns CUBIT_FAILURE if curve is not a line
00058   
00059   virtual CubitStatus get_center_radius( CubitVector& center, double& radius ) = 0;
00060     //- Only valid for arcs
00061     //- Finds the underlying arc's center point and radius
00062     //- Returns CUBIT_FAILURE if curve is not an arc
00063   
00064   virtual double length_from_u( double parameter1,
00065                                 double parameter2 ) = 0;
00066     //R double
00067     //R- Returned length value
00068     //I parameter1
00069     //I- The first parameter value
00070     //I parameter2
00071     //I- The second parameter value
00072     //- This function returns the arc length along the Curve starting from
00073     //- the point represented by the parameter1 going to the point represented
00074     //- by parameter2.
00075     //-
00076     //- The sign of the returned length value depends on the order of the parameters passed in.
00077   
00078   virtual double get_arc_length();
00079     //R double
00080     //R- Returned total length value
00081     //- This function returns the arc length along the entire Curve
00082   
00083   virtual double get_arc_length( const CubitVector &point1,
00084                                  const CubitVector &point2 );
00085     //R double
00086     //R- Returned length value
00087     //I point1
00088     //I- The first position value
00089     //I point2
00090     //I- The second position value
00091     //- This function returns the arc length along the Curve starting from
00092     //- the point1 going to point2
00093     //- the length returned is always positive.
00094   
00095   virtual double get_arc_length( const CubitVector &point1,
00096                                  const int which_end );
00097     //R double
00098     //R- Returned length value
00099     //I point1
00100     //I- The first position value
00101     //I which_end
00102     //I- 0 for start, 1 for end
00103     //- This function returns the arc length along the Curve starting from
00104     //- point1 going to either the start or the end
00105     //- the length returned is always positive.
00106   
00107   virtual CubitVector center_point();
00108     //R CubitVector
00109     //R- center point on this edge
00110     //- This function returns the center point on this edge, by
00111     //- arc length
00112   
00113   virtual CubitStatus mid_point(const CubitVector &point1,
00114                                 const CubitVector &point2,
00115                                 CubitVector& mid_point );
00116     //R CubitStatus
00117     //I CubitVector, CubitVector
00118     //I- points between which the mid_point is needed
00119     //O CubitVector
00120     //O- mid point on this edge
00121     //- This function returns the mid point between two points on this
00122     //-edge, by parameter
00123   
00124   virtual CubitStatus mid_point(CubitVector& mid_point);
00125     //R CubitStatus
00126     //O CubitVector
00127     //O- mid point on this edge
00128     //- This function returns the mid point on this edge, by parameter
00129   
00130   virtual CubitStatus position_from_fraction( const double fraction_along_curve,
00131                                               CubitVector &output_position );
00132     //R CubitStatus
00133     //I fraction in parameter space along curve (1/3,2/3,4/5...)
00134     //O- position where percent in parameter space lies.
00135     //-This function takes the given fraction, finds the parameter value,
00136     //-and calculates this position.
00137   
00138   virtual CubitBoolean is_periodic( double& period) = 0;
00139     //R CubitBoolean
00140     //R- CUBIT_TRUE/CUBIT_FALSE
00141     //O period
00142     //O- Returned period value
00143     //- This function determines whether the underlying geometry of the
00144     //- Curve is periodic or not.  Returns CUBIT_TRUE if it is and 
00145     //- CUBIT_FALSE if it is not.
00146     //-
00147     //- If it is periodic, then it returns the period in the input
00148     //- reference variable, "period". This value is set to 0.0 if
00149     //- the Curve is not periodic.
00150   
00151   virtual CubitBoolean get_param_range( double& lower_bound,
00152                                         double& upper_bound ) = 0;
00153     //R CubitBoolean
00154     //R- CUBIT_TRUE/CUBIT_FALSE
00155     //O lower_bound
00156     //O- The lower bound of the parametric range.
00157     //O upper_bound
00158     //O- The upper bound of the parametric range.
00159     //- Returns the lower and upper parametric bounds of the 
00160     //- Curve, based on the extent of the its first underlying entity.
00161     //- The boolean return value indicates whether the Curve is 
00162     //- parametrically defined or not -- returns CUBIT_TRUE if yes and
00163     //- CUBIT_FALSE, otherwise.  If the Curve is not parametrically
00164     //- defined, the values of the upper and lower bounds are
00165     //- undetermined.
00166     //-
00167     //- IMPORTANT NOTE:
00168     //- Note that the lower bound is the parameter value of the start
00169     //- location of the RefEdge that uses this Curve and the upper
00170     //- bound is the parameter value of the end location of the RefEdge
00171     //- that uses this Curve.  This takes into account the sense of the
00172     //- RefEdge with respect to the Curve (which could be REVERSED).
00173     //- Hence, the numerical value of the lower parameter bound could be
00174     //- greater than that of the upper parameter bound.
00175   
00176   virtual CubitStatus get_interior_extrema(DLIList<CubitVector*>& interior_points,
00177                                            CubitSense& return_sense) = 0;
00178     //- Finds the extrema along this RefEdge.  An extremum is defined as
00179     //- a local min or max in the direction of one of the primary axial directions.
00180     //- O-interior_points: list of coordinates where the extrema occur.
00181     //- O-return_sense: Whether the interior extrema are ordered in the
00182     //-                 FORWARD or REVERSED direction of this RefEdge.
00183     //-
00184     //- ***IMPORTANT!!!***
00185     //-    This function dynamically allocates the CubitVectors appended to
00186     //-    interior_points.  It is the responsibility of the calling code to
00187     //-    delete these CubitVectors (or in the case of RefEdge, to make sure
00188     //-    that *it's* calling code knows that it should delete the CubitVectors)!
00189   
00190   virtual CubitStatus closest_point( CubitVector const& location, 
00191                                      CubitVector& closest_location,
00192                                      CubitVector* tangent_ptr = NULL,
00193                                      CubitVector* curvature_ptr = NULL,
00194                                      double *param = NULL) = 0;
00195     //R void
00196     //I location
00197     //I- The point to which the closest point on the Curve is desired.
00198     //O closest_location
00199     //O- The point on the Curve, closest to the input location which
00200     //O- might not be on the Curve.  This is input as a reference 
00201     //O- so that the function can modify its contents.
00202     //O tangent_ptr
00203     //O- The tangent to the Curve (output as a unit vector) at the 
00204     //O- closest_location.
00205     //O curvature_ptr
00206     //O- The curvature of the Curve at the closest_location.
00207     //- This function computes the point on the Curve closest to the input 
00208     //- location.
00209     //-
00210     //- If the tangent and/or curvature is required, then the calling code
00211     //- is responsible for allocating space for the CubitVector(s) and
00212     //- sending in the relevant non-NULL pointers.  If either of these
00213     //- pointers is NULL, the related quantity is not computed.
00214     //-
00215     //- Notes:
00216     //- The tangent direction is always in the positive direction of the 
00217     //- *owning RefEdge*, regardless of the positive direction of the
00218     //- underlying solid model entities, if any.
00219   
00220   virtual CubitStatus closest_point_trimmed( CubitVector const& from_pt,
00221                                              CubitVector& result_pt );
00222     //R CubitStatus
00223     //R- CUBIT_SUCCESS/CUBIT_FAILURE
00224     //I from_pt
00225     //I- The position to evaluate wrt curve.
00226     //I result_pt
00227     //I- The resulting point on the curve.
00228     //- This method finds the closest point to a BOUNDED curve.
00229     //
00230     // Added by Jason Kraftcheck, 07/17/98.
00231     // See also: Curve::closest_point_trimmed(..).
00232 
00233   virtual CubitPointContainment point_containment( const CubitVector &point ) = 0;
00234     //R CubitPointContainment - is the point on bounds of the curve?
00235     //R- CUBIT_PNT_OFF, CUBIT_PNT_ON, CUBIT_PNT_UNKNOWN
00236     //I CubitVector
00237     //I- position to check, known to be on the Curve
00238     // NOTE: POINT MUST LIE ON THE CURVE FOR THIS FUNCTION TO WORK PROPERLY.
00239   
00240   virtual double u_from_position (const CubitVector& input_position) = 0;
00241     //R double
00242     //R- The returned "u" parameter value in local parametric space
00243     //I input_position
00244     //I- The input position for which "u" is to be computed.
00245     //- This function returns the coordinate of a point in the local
00246     //- parametric (u) space that corresponds to the input position in
00247     //- global (world) space.  The input point is first moved to the
00248     //- closest point on the Curve and the parameter value of that
00249     //- point is determined.
00250   
00251   virtual CubitStatus position_from_u (double u_value,
00252                                        CubitVector& output_position) = 0;
00253     //R CubitStatus
00254     //R- CUBIT_SUCCESS/FAILURE
00255     //I u_value
00256     //I- The input u parameter value
00257     //O output_position
00258     //O- The output position
00259     //- This function returns the coordinates of a point in the global
00260     //- (world) space that corresponds to the input parametric position 
00261     //- in the local space.
00262     //-
00263     //- If the input parameter value is not defined for the Curve, then 
00264     //- the input CubitVector is not modified and CUBIT_FAILURE is
00265     //- returned. Otherwise, position is appropriately modified and
00266     //- CUBIT_SUCCESS is returned.
00267     //-
00268     //- If the curve is periodic, the input u_value is first "normalized"
00269     //- to the fundamental period of the Curve before its position
00270     //- in global space is determined.
00271   
00272   virtual double u_from_arc_length ( double root_param,
00273                                      double arc_length ) = 0;
00274     //R double
00275     //R- Returned parameter value
00276     //I root_param
00277     //I- The parameter value of the "root point"
00278     //I arc_length
00279     //I- A distance along the Curve
00280     //- This function returns the parameter value of the point that is
00281     //- "arc_length" away from the root point in the
00282     //- positive sense direction of the owning RefEdge.
00283     //- 
00284     //- A negative value for distance would force the search to go in the 
00285     //- negative (sense) direction of the RefEdge.
00286     //-
00287     //- NOTE:
00288     //- The important assumption that is made in this routine is that
00289     //- the end points of the RefEdge that owns this Curve are the same
00290     //- as the end points of the first solid model entity in the list of 
00291     //- solid model entities associated with this Curve.
00292   
00293   virtual CubitBoolean is_position_on( const CubitVector &test_position ) = 0;
00294     //R CubitBoolean
00295     //R- CUBIT_TRUE/CUBIT_FALSE
00296     //I CubitVector
00297     //I- position, point where we want to test, whether or not it
00298     //- is on the curve.
00299 
00300   virtual GeometryType geometry_type()
00301   {return UNDEFINED_CURVE_TYPE;};
00302   //R GeometryType (enum)
00303   //R- The enumerated type of the geometric representation
00304 
00305   virtual double start_param() = 0;
00306     //R double parameter
00307     //R- start parameter of curve with respect to refEdge.
00308   
00309   virtual double end_param() = 0;
00310     //R double parameter
00311     //R- start parameter of curve with respect to refEdge.
00312 
00313   virtual CubitStatus point_from_arc_length( double root_param,
00314                                              const double arc_length,
00315                                              CubitVector &new_point);
00316 
00317     //R CubitStatus
00318     //R- CUBIT_SUCCESS, CUBIT_FAILURE
00319     //I- root_param-starting parameter for point on curve from which arc_length extends.
00320     //O- new_point, from starting parameter by arc_lenth.
00321   
00322   virtual CubitStatus point_from_arc_length( const CubitVector &root_point,
00323                                              double const arc_length,
00324                                              CubitVector& new_point );
00325     //R void
00326     //R- pointer to void
00327     //I- root_point-point from which arc_length extends.
00328     //O- new_point, from root_point by arc_lenth.
00329   
00330 //=========  Add Code by SRS of Cat,  3/3/99 2:34:50 PM  =========
00331   virtual CubitBoolean is_tolerant(){ return CUBIT_FALSE; };
00332     //- This function is overloaded in the Curve class only.
00333     //- Tolerant edges can get created by the  healer if the
00334     //- edge cannot be healed.
00335 //=========  Code End by SRS of Cat,  3/3/99 2:34:50 PM  =========
00336 
00337     virtual CubitBoolean G1_discontinuous( double u,
00338                                            CubitVector* minus_tangent = NULL,
00339                                            CubitVector* plus_tangent = NULL );
00340         //R CubitBoolean
00341         //R- CUBIT_TRUE/CUBIT_FALSE
00342         //I u
00343         //I- The parameter value on the curve to test at.
00344         //O minus_tanget
00345         //O- The tangent direction on the decreasing-parameter-value 
00346         //O- side of u.  This vector, if passed, will only be changed
00347         //O- when the return value is CUBIT_TRUE.
00348         //O plus_tanget
00349         //O- The tangent direction on the increasing-parameter-value
00350         //O- side of u.  This vector, if passed, will only be changed
00351         //O- when the return value is CUBIT_TRUE.
00352         //- Check for a G1 discontinuity in a curve.  Derived classes should
00353     //- override the function with a more exact implementation.  The
00354     //- default implementation provided in Curve is a simple numeric
00355     //- approximation. 
00356 
00357   //R CubitStatus
00358   //O- true or false if spline is rational or not.
00359   //O- the degree of this spline
00360   //O- the control points
00361   //O- If rational, weight for each control point
00362   //O- the knots
00363   //O- whether the underlying spline is reversed  
00364   virtual CubitStatus get_spline_params( bool &rational,
00365                                          int &degree,
00366                                          DLIList<CubitVector> &cntrl_pts,
00367                                          DLIList<double> &cntrl_pt_weights,
00368                                          DLIList<double> &knots, // There should be order+cntrl_pts.size()-2 knots
00369                                          bool &spline_is_reversed
00370                                        ) const = 0;
00371 
00372   //R CubitStatus
00373   //O- center - ellipse center point
00374   //O- normal - normal of the plane of the ellipse
00375   //O- major_axis - major axis of the ellipse
00376   //O- radius_ratio - ratio of the length of the major to minor axis.
00377   virtual CubitStatus get_ellipse_params( CubitVector &center,
00378                                           CubitVector &normal,
00379                                           CubitVector &major_axis,
00380                                           double &radius_ratio ) const = 0;
00381 
00382 protected: 
00383   
00384 private:
00385 };
00386 
00387 
00388 // ********** BEGIN INLINE FUNCTIONS       **********
00389 inline
00390 double Curve::get_arc_length()
00391 {
00392   return measure();
00393 }
00394 
00395 inline
00396 double Curve::get_arc_length( const CubitVector &point1,
00397                               const CubitVector &point2 )
00398 {
00399   double param1 = u_from_position(point1);
00400   double param2 = u_from_position(point2);
00401   return fabs(length_from_u(param1, param2));
00402 }
00403 
00404 inline
00405 double Curve::get_arc_length( const CubitVector &point1,
00406                               const int which_end )
00407 {
00408   double param1 = u_from_position(point1);
00409   double param2;
00410   if (which_end == 0) param2 = start_param();
00411   else param2 = end_param();
00412   
00413   return fabs(length_from_u(param1, param2));
00414 }
00415 
00416 inline
00417 CubitVector Curve::center_point()
00418 {
00419   double s_param = start_param();
00420   double length = 0.5 * measure();
00421   double param2 = u_from_arc_length(s_param, length);
00422   CubitVector center;
00423   position_from_u(param2, center);
00424   return center;
00425 }
00426 
00427 inline
00428 CubitStatus Curve::mid_point(CubitVector &midpoint)
00429 {
00430   double param1 = 0.5 * (start_param() + end_param());
00431   
00432   return position_from_u(param1, midpoint);
00433 }
00434 
00435 inline
00436 CubitStatus Curve::position_from_fraction( const double fraction_along_curve,
00437                                            CubitVector &output_position )
00438 {
00439   CubitStatus result = CUBIT_FAILURE;
00440   double param_1 = start_param() +
00441     fraction_along_curve * (end_param() - start_param() );
00442   result = position_from_u( param_1, output_position );
00443   return result;
00444 }
00445 
00446 inline
00447 CubitStatus Curve::mid_point(const CubitVector &point1,
00448                              const CubitVector &point2,
00449                              CubitVector& midpoint )
00450 {
00451   double param1 = u_from_position(point1);
00452   double param2 = u_from_position(point2);
00453   param1 = 0.5 * (param1 + param2);
00454   return position_from_u(param1, midpoint);
00455 }
00456 
00457   //R CubitStatus
00458   //I CubitVector, CubitVector
00459   //I- points between which the mid_point is needed
00460   //O CubitVector
00461   //O- mid point on this edge
00462   //- This function returns the mid point between two points on this
00463   //-edge, by parameter
00464 
00465 
00466 
00467 // ********** END INLINE FUNCTIONS         **********
00468 
00469 // ********** BEGIN FRIEND FUNCTIONS       **********
00470 // ********** END FRIEND FUNCTIONS         **********
00471 
00472 // ********** BEGIN EXTERN FUNCTIONS       **********
00473 // ********** END EXTERN FUNCTIONS         **********
00474 
00475 #endif
00476 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines