Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 10:04:53

0001 // Created on: 2014-11-14
0002 // Created by: Varvara POSKONINA
0003 // Copyright (c) 2005-2014 OPEN CASCADE SAS
0004 //
0005 // This file is part of Open CASCADE Technology software library.
0006 //
0007 // This library is free software; you can redistribute it and/or modify it under
0008 // the terms of the GNU Lesser General Public License version 2.1 as published
0009 // by the Free Software Foundation, with special exception defined in the file
0010 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
0011 // distribution for complete text of the license and disclaimer of any warranty.
0012 //
0013 // Alternatively, this file may be used under the terms of Open CASCADE
0014 // commercial license or contractual agreement.
0015 
0016 #ifndef _SelectBasics_PickResult_HeaderFile
0017 #define _SelectBasics_PickResult_HeaderFile
0018 
0019 #include <gp_Pnt.hxx>
0020 
0021 //! This structure provides unified access to the results of Matches() method in all sensitive entities,
0022 //! so that it defines a Depth (distance to the entity along picking ray) and a closest Point on entity.
0023 struct SelectBasics_PickResult
0024 {
0025 public:
0026   //! Return closest result between two Pick Results according to Depth value.
0027   static const SelectBasics_PickResult& Min (const SelectBasics_PickResult& thePickResult1,
0028                                              const SelectBasics_PickResult& thePickResult2)
0029   {
0030     return thePickResult1.Depth() <= thePickResult2.Depth() ? thePickResult1 : thePickResult2;
0031   }
0032 
0033 public:
0034   //! Empty constructor defining an invalid result.
0035   SelectBasics_PickResult()
0036   : myObjPickedPnt (RealLast(), 0.0, 0.0),
0037     myDepth (RealLast()),
0038     myDistToCenter (RealLast()) {}
0039 
0040   //! Constructor with initialization.
0041   SelectBasics_PickResult (Standard_Real theDepth,
0042                            Standard_Real theDistToCenter,
0043                            const gp_Pnt& theObjPickedPnt)
0044   : myObjPickedPnt (theObjPickedPnt),
0045     myDepth (theDepth),
0046     myDistToCenter (theDistToCenter) {}
0047 
0048 public:
0049 
0050   //! Return TRUE if result was been defined.
0051   Standard_Boolean IsValid() const { return myDepth != RealLast(); }
0052 
0053   //! Reset depth value.
0054   void Invalidate()
0055   {
0056     myDepth = RealLast();
0057     myObjPickedPnt = gp_Pnt (RealLast(), 0.0, 0.0);
0058     myNormal.SetValues (0.0f, 0.0f, 0.0f);
0059   }
0060 
0061   //! Return depth along picking ray.
0062   Standard_Real Depth() const { return myDepth; }
0063 
0064   //! Set depth along picking ray.
0065   void SetDepth (Standard_Real theDepth) { myDepth = theDepth; }
0066 
0067   //! Return TRUE if Picked Point lying on detected entity was set.
0068   Standard_Boolean HasPickedPoint() const { return myObjPickedPnt.X() != RealLast(); }
0069 
0070   //! Return picked point lying on detected entity.
0071   //! WARNING! Point is defined in local coordinate system and should be translated into World System before usage!
0072   const gp_Pnt& PickedPoint() const { return myObjPickedPnt; }
0073 
0074   //! Set picked point.
0075   void SetPickedPoint (const gp_Pnt& theObjPickedPnt) { myObjPickedPnt = theObjPickedPnt; }
0076 
0077   //! Return distance to geometry center (auxiliary value for comparing results).
0078   Standard_Real DistToGeomCenter() const { return myDistToCenter; }
0079 
0080   //! Set distance to geometry center.
0081   void SetDistToGeomCenter (Standard_Real theDistToCenter) { myDistToCenter = theDistToCenter; }
0082 
0083   //! Return (unnormalized) surface normal at picked point or zero vector if undefined.
0084   //! WARNING! Normal is defined in local coordinate system and should be translated into World System before usage!
0085   const NCollection_Vec3<float>& SurfaceNormal() const { return myNormal; }
0086 
0087   //! Set surface normal at picked point.
0088   void SetSurfaceNormal (const NCollection_Vec3<float>& theNormal) { myNormal = theNormal; }
0089 
0090   //! Set surface normal at picked point.
0091   void SetSurfaceNormal (const gp_Vec& theNormal)
0092   {
0093     myNormal.SetValues ((float )theNormal.X(), (float )theNormal.Y(), (float )theNormal.Z());
0094   }
0095 
0096 private:
0097   gp_Pnt                  myObjPickedPnt; //!< User-picked selection point onto object
0098   NCollection_Vec3<float> myNormal;       //!< surface normal
0099   Standard_Real           myDepth;        //!< Depth to detected point
0100   Standard_Real           myDistToCenter; //!< Distance from 3d projection user-picked selection point to entity's geometry center
0101 };
0102 
0103 #endif // _SelectBasics_PickResult_HeaderFile