opennurbs_plane.h
Go to the documentation of this file.
00001 /* $NoKeywords: $ */
00002 /*
00003 //
00004 // Copyright (c) 1993-2012 Robert McNeel & Associates. All rights reserved.
00005 // OpenNURBS, Rhinoceros, and Rhino3D are registered trademarks of Robert
00006 // McNeel & Associates.
00007 //
00008 // THIS SOFTWARE IS PROVIDED "AS IS" WITHOUT EXPRESS OR IMPLIED WARRANTY.
00009 // ALL IMPLIED WARRANTIES OF FITNESS FOR ANY PARTICULAR PURPOSE AND OF
00010 // MERCHANTABILITY ARE HEREBY DISCLAIMED.
00011 //                              
00012 // For complete openNURBS copyright information see <http://www.opennurbs.org>.
00013 //
00015 */
00016 
00017 #if !defined(ON_PLANE_INC_)
00018 #define ON_PLANE_INC_
00019 
00020 class ON_CLASS ON_Plane
00021 {
00022 public:
00023 
00024   /*
00025   Description:
00026     The default constructor creates a plane
00027     with orgin=(0,0,0), xaxis=(1,0,0), yaxis=(0,1,0)
00028     zaxis=(0,0,1), and equation=(0,0,1,0).
00029   */
00030   ON_Plane();
00031 
00032   /*
00033   Description:
00034     Construct a plane from a point and normal vector.
00035   Parameters:
00036     origin - [in] point on the plane
00037     normal - [in] non-zero normal to the plane
00038   Remarks:
00039     origin = point, zaxis = unitized normal, xaxis
00040     xaxis set with xaxis.PerpindicularTo(zaxis).
00041   See Also:
00042     ON_Plane::CreateFromNormal
00043   */
00044   ON_Plane(
00045     const ON_3dPoint& origin,
00046     const ON_3dVector& normal
00047     );
00048 
00049   /*
00050   Description:
00051     Construct a plane from a point, and two vectors in
00052     the plane.
00053   Parameters:
00054     origin - [in] point on the plane
00055     x_dir - [in] non-zero vector in the plane that
00056         determines the xaxis direction.
00057     y_dir - [in] non-zero vector not parallel to x_dir
00058         that is used to determine the yaxis direction.
00059         y_dir does not have to be perpendicular to x_dir.
00060   */
00061   ON_Plane(
00062     const ON_3dPoint& origin,
00063     const ON_3dVector& x_dir,
00064     const ON_3dVector& y_dir
00065     );
00066 
00067   /*
00068   Description:
00069     Construct a plane from three non-colinear points.
00070   Parameters:
00071     origin - [in] point on the plane
00072     x_point - [in] second point in the plane.
00073         The xaxis will be parallel to x_point-origin.
00074     y_point - [in] third point on the plane that is
00075         not colinear with the first two points.
00076         yaxis*(y_point-origin) will be > 0.
00077   */
00078   ON_Plane(
00079     const ON_3dPoint& origin,
00080     const ON_3dPoint& x_point,
00081     const ON_3dPoint& y_point
00082     );
00083 
00084   /*
00085   Description:
00086     Construct a plane from an equation.
00087   Parameters:
00088     equation - [in] an array of 4 doubles with
00089        one of equation[0], equation[1], or equation[2]
00090        being non-zero.
00091   */
00092   ON_Plane(
00093     const double equation[4]
00094     );
00095 
00096   ~ON_Plane();
00097 
00098   bool operator==(const ON_Plane&) const;
00099   bool operator!=(const ON_Plane&) const;
00100 
00101   /*
00102   Description:
00103     Create a plane from a point and normal vector.
00104   Parameters:
00105     origin - [in] point on the plane
00106     normal - [in] non-zero normal to the plane
00107   Remarks:
00108     origin = point, zaxis = unitized normal, xaxis
00109     xaxis set with xaxis.PerpindicularTo(zaxis).
00110   Returns:
00111     true if valid plane is created.
00112   */
00113   bool CreateFromNormal(
00114     const ON_3dPoint& origin,
00115     const ON_3dVector& normal
00116     );
00117 
00118   /*
00119   Description:
00120     Construct a plane from a point, and two vectors in
00121     the plane.
00122   Parameters:
00123     origin - [in] point on the plane
00124     x_dir - [in] non-zero vector in the plane that
00125         determines the xaxis direction.
00126     y_dir - [in] non-zero vector not parallel to x_dir
00127         that is used to determine the yaxis direction.
00128         y_dir does not have to be perpendicular to x_dir.
00129   Returns:
00130     true if valid plane is created.
00131   */
00132   bool CreateFromFrame(
00133     const ON_3dPoint& origin,
00134     const ON_3dVector& x_dir,
00135     const ON_3dVector& y_dir
00136     );
00137 
00138   /*
00139   Description:
00140     Construct a plane from three non-colinear points.
00141   Parameters:
00142     origin - [in] point on the plane
00143     point_on_x - [in] second point in the plane.
00144         The xaxis will be parallel to x_point-origin.
00145     point_on - [in] third point on the plane that is
00146         not colinear with the first two points.
00147         yaxis*(y_point-origin) will be > 0.
00148   Returns:
00149     true if valid plane is created.
00150   */
00151   bool CreateFromPoints(
00152     const ON_3dPoint& origin,
00153     const ON_3dPoint& point_on_x,
00154     const ON_3dPoint& point_on
00155     );
00156 
00157   /*
00158   Description:
00159     Construct a plane from an equation.
00160   Parameters:
00161     equation - [in] an array of 4 doubles with
00162        one of equation[0], equation[1], or equation[2]
00163        being non-zero.
00164   Remarks:
00165     points on the plane will satisfy 
00166     x*equation[0] +y*equation[1] + z*equation[2] + equation[3] = 0
00167   Returns:
00168     true if valid plane is created.
00169   */
00170   bool CreateFromEquation( 
00171     const double equation[4]
00172     );
00173 
00174   /*
00175   Description:
00176     Test plane to see if it is valid.
00177   Returns:
00178     true if all fields contain reasonable
00179     information and equation jibes with point and zaxis.
00180   */
00181   bool IsValid() const;
00182 
00183   /*
00184   Returns:
00185     Plane origin.
00186   */
00187   const ON_3dPoint& Origin() const;
00188 
00189   /*
00190   Returns:
00191     Plane unit x-axis.
00192   */
00193   const ON_3dVector& Xaxis() const;
00194 
00195   /*
00196   Returns:
00197     Plane unit y-axis.
00198   */
00199   const ON_3dVector& Yaxis() const;
00200 
00201   /*
00202   Returns:
00203     Plane unit normal.
00204   */
00205   const ON_3dVector& Normal() const;
00206 
00207 
00208   /*
00209   Description:
00210     Set the origin and update the plane equation
00211   Parameters:
00212     origin - [in] the new origin
00213   */
00214   void SetOrigin( const ON_3dPoint& origin );
00215   
00216   /*
00217   Description:
00218     Evaluate a point on the plane
00219   Parameters:
00220     u - [in]
00221     v - [in] evaulation parameters
00222   Returns:
00223     plane.origin + u*plane.xaxis + v*plane.yaxis
00224   */
00225   ON_3dPoint PointAt(
00226     double u,
00227     double v
00228     ) const;
00229 
00230   /*
00231   Description:
00232     Evaluate a point on the plane
00233   Parameters:
00234     u - [in]
00235     v - [in] evaluation parameters
00236     w - [in] elevation parameter
00237   Returns:
00238     plane.origin + u*plane.xaxis + v*plane.yaxis + z*plane.zaxis
00239   */
00240   ON_3dPoint PointAt(
00241     double u,
00242     double v,
00243     double w
00244     ) const;
00245 
00246   /*
00247   Description:
00248     Get an isoparameteric line on the plane.
00249   Parameters:
00250     dir - [in] direction of iso-parametric line
00251         0: first parameter varies and second parameter is constant
00252            e.g., line(t) = plane(t,c)
00253         1: first parameter is constant and second parameter varies
00254            e.g., line(t) = plane(c,t)
00255     c - [in] value of constant parameter 
00256   Returns:
00257     iso-parametric line
00258   */
00259   ON_Line IsoLine(
00260          int dir,
00261          double c
00262          ) const;
00263 
00264   /*
00265   Description:
00266     Get signed distance from the plane to a point.
00267   Parameters:
00268     point - [in]
00269   Returns:
00270     Signed distance from a point to a plane.
00271   Remarks:
00272     If the point is on the plane, the distance is 0.
00273     If the point is above the plane, the distance is > 0.
00274     If the point is below the plane the distance is < 0.
00275     The zaxis determines the plane's orientation.
00276   */
00277   double DistanceTo( 
00278         const ON_3dPoint& point
00279         ) const;
00280 
00281 
00282   bool GetDistanceToBoundingBox(
00283            //returns false if plane has zero length normal
00284                                    const ON_BoundingBox&, // Box
00285 
00286            //output
00287                                    double* min,    // min signed dist from plane to box 
00288            double* max     //max signed dist from plane to box
00289            ) const;
00290 
00291   /*
00292   Description:
00293     Update the plane equation based on the current values
00294     of the origin and zaxis.
00295   Returns:
00296     true if successful.  false if zaxis is zero.
00297   Remarks:
00298     If you modify a plane's origin or zaxis, call UpdateEquation()
00299     to set equation[]. 
00300   */
00301   bool UpdateEquation();
00302 
00303   /*
00304   Description:
00305     Get point on plane that is closest to a given point.
00306   Parameters:
00307     world_point - [in] 3d point
00308     u - [out] 
00309     v - [out] The point ON_Plane::PointAt(*u,*v) is the point
00310               on the plane that is closest to world_point.
00311   Returns:
00312     true if successful.
00313   */
00314   bool ClosestPointTo( 
00315          ON_3dPoint world_point,
00316          double* u,
00317          double* v
00318          ) const;
00319 
00320   /*
00321   Description:
00322     Get point on plane that is closest to a given point.
00323   Parameters:
00324     point - [in]
00325   Returns:
00326     A 3d point on the plane that is closest to world_point.
00327   */
00328   ON_3dPoint ClosestPointTo( 
00329          ON_3dPoint point
00330          ) const;
00331 
00332   // For intersections see ON_Intersect();
00333 
00334   /*
00335   Description:
00336     Transform plane.
00337   Parameters:
00338     xform - [in] transformation to apply to plane
00339   Returns:
00340     true if successful
00341   */
00342   bool Transform( 
00343         const ON_Xform& xform
00344         );
00345 
00346   /*
00347   Description:
00348     Transform a plane by swapping coordinates.
00349   Parameters:
00350     i - [in]
00351     j - [in] indices of coordinates to swap.
00352         0 = x coordinate, 1 = y coordinate, 2 = z coordinate.
00353   Returns:
00354     true if successful.
00355   */
00356   bool SwapCoordinates(
00357         int i,
00358         int j
00359         );
00360 
00361   /*
00362   Description:
00363     Rotate a plane about its origin.
00364   Parameters:
00365     sin_angle - [in] sine of rotation angle
00366     cos_angle - [in] cosine of rotation angle
00367     axis - [in] axis of rotation
00368   Returns:
00369     true if successful
00370   */
00371   bool Rotate(
00372         double sin_angle,
00373         double cos_angle,
00374         const ON_3dVector& axis
00375         );
00376 
00377   /*
00378   Description:
00379     Rotate a plane about its origin.
00380   Parameters:
00381     angle - [in] rotation angle in radians
00382     axis - [in] axis of rotation
00383   Returns:
00384     true if successful
00385   */
00386   bool Rotate(
00387         double angle,
00388         const ON_3dVector& axis
00389         );
00390 
00391   /*
00392   Description:
00393     Rotate a plane about a point.
00394   Parameters:
00395     sin_angle - [in] sine of rotation angle
00396     cos_angle - [in] cosine of rotation angle
00397     axis - [in] axis of rotation
00398     center - [in] center of rotation
00399   Returns:
00400     true if successful
00401   */
00402   bool Rotate(
00403         double sin_angle,
00404         double cos_angle,
00405         const ON_3dVector& axis,
00406         const ON_3dPoint&  center
00407         );
00408 
00409   /*
00410   Description:
00411     Rotate a plane about a point.
00412   Parameters:
00413     angle - [in] rotation angle in radians
00414     axis - [in] axis of rotation
00415     center - [in] center of rotation
00416   Returns:
00417     true if successful
00418   */
00419   bool Rotate(
00420         double angle,
00421         const ON_3dVector& axis,
00422         const ON_3dPoint& center
00423         );
00424 
00425   /*
00426   Description:
00427     Translate a plane.
00428   Parameters:
00429     delta - [in] translation vector
00430   Returns:
00431     true if successful
00432   */
00433   bool Translate(
00434         const ON_3dVector&  delta
00435         );
00436 
00437   /*
00438   Description:
00439     Flip plane orientation by swapping x and y axes,
00440     reversing the zaxis, and updating the equation.
00441   Returns:
00442     true if successful
00443   */
00444   bool Flip();
00445 
00446 // world plane coordinate system ON_Plane(ON_origin, ON_xaxis, ON_yaxis); 
00447         const static
00448         ON_Plane World_xy;      
00449 
00450 public:
00451   // origin of plane
00452   ON_3dPoint  origin;
00453 
00454   // unit X axis of plane
00455   ON_3dVector xaxis;
00456 
00457   // unit Y axis of plane
00458   ON_3dVector yaxis;
00459 
00460   // unit Z axis of plane
00461   ON_3dVector zaxis;
00462 
00463   // equation of plane
00464   ON_PlaneEquation plane_equation;
00465   //double equation[4];
00466 };
00467 
00468 class ON_CLASS ON_ClippingPlaneInfo
00469 {
00470 public:
00471   // C++ defaults for construction, destruction, copy construction
00472   // and operator= work fine.
00473 
00474   // A point is visible if m_plane_equation.ValueAt(point) <= 0.
00475   // (This is the opposite convention from what OpenGL uses.)
00476   ON_PlaneEquation m_plane_equation;
00477   ON_UUID m_plane_id;
00478   bool m_bEnabled;
00479 
00480   void Default();
00481   bool Write( ON_BinaryArchive& ) const;
00482   bool Read( ON_BinaryArchive& );
00483 };
00484 
00485 class ON_CLASS ON_ClippingPlane
00486 {
00487 public:
00488   ON_ClippingPlane();
00489   ~ON_ClippingPlane();
00490 
00491   void Default();
00492 
00493   ON_Plane m_plane;
00494   ON_UuidList m_viewport_ids; //ids of viewports that this clipping plane "clips"
00495   ON_UUID m_plane_id;
00496   bool m_bEnabled; // true if this clipping plane is active
00497 
00498   ON_ClippingPlaneInfo ClippingPlaneInfo() const;
00499 
00500   bool Read( class ON_BinaryArchive& );
00501   bool Write( class ON_BinaryArchive& ) const;
00502 };
00503 
00504 
00505 #if defined(ON_DLL_TEMPLATE)
00506 
00507 // This stuff is here because of a limitation in the way Microsoft
00508 // handles templates and DLLs.  See Microsoft's knowledge base 
00509 // article ID Q168958 for details.
00510 #pragma warning( push )
00511 #pragma warning( disable : 4231 )
00512 ON_DLL_TEMPLATE template class ON_CLASS ON_SimpleArray<ON_Plane>;
00513 ON_DLL_TEMPLATE template class ON_CLASS ON_ClassArray<ON_ClippingPlane>;
00514 ON_DLL_TEMPLATE template class ON_CLASS ON_SimpleArray<ON_ClippingPlaneInfo>;
00515 #pragma warning( pop )
00516 
00517 #endif
00518 
00519 extern ON_EXTERN_DECL const ON_Plane ON_xy_plane;
00520 extern ON_EXTERN_DECL const ON_Plane ON_yz_plane;
00521 extern ON_EXTERN_DECL const ON_Plane ON_zx_plane;
00522 
00523 /*
00524 Description:
00525   Get a convex hull of a set of 3d points.
00526 Parameters:
00527   points - [in]
00528     List of points.  This function can handle tens of points
00529     but is too slow for hundreds of points.
00530   hull -[out]
00531     Equations of the sides of the convex hull are appended to
00532     this list.  
00533     A point P is inside the hull if hull[i].ValueAt(P) <= 0 for
00534     every plane equation.
00535 Returns:
00536   Number of equations appended to hull[] array.
00537   If 0, then the points are coincident or colinear.
00538   If 2, then the points are coplanar and the returned
00539   planes are parallel.
00540   If >= 4, then the points are in a 3d convex hull.
00541 */
00542 ON_DECL
00543 int ON_Get3dConvexHull( 
00544           const ON_SimpleArray<ON_3dPoint> & points, 
00545           ON_SimpleArray<ON_PlaneEquation> & hull 
00546           );
00547 
00548 #endif


pcl
Author(s): Open Perception
autogenerated on Wed Aug 26 2015 15:27:02