1 // Created on: 2014-11-14
2 // Created by: Varvara POSKONINA
3 // Copyright (c) 2005-2014 OPEN CASCADE SAS
4 //
5 // This file is part of Open CASCADE Technology software library.
6 //
7 // This library is free software; you can redistribute it and/or modify it under
8 // the terms of the GNU Lesser General Public License version 2.1 as published
9 // by the Free Software Foundation, with special exception defined in the file
10 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
11 // distribution for complete text of the license and disclaimer of any warranty.
12 //
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
15 
16 #ifndef _SelectBasics_PickResult_HeaderFile
17 #define _SelectBasics_PickResult_HeaderFile
18 
19 #include <gp_Pnt.hxx>
20 
21 //! This structure provides unified access to the results of Matches() method in all sensitive entities,
22 //! so that it defines a Depth (distance to the entity along picking ray) and a closest Point on entity.
23 struct SelectBasics_PickResult
24 {
25 public:
26   //! Return closest result between two Pick Results according to Depth value.
MinSelectBasics_PickResult27   static const SelectBasics_PickResult& Min (const SelectBasics_PickResult& thePickResult1,
28                                              const SelectBasics_PickResult& thePickResult2)
29   {
30     return thePickResult1.Depth() <= thePickResult2.Depth() ? thePickResult1 : thePickResult2;
31   }
32 
33 public:
34   //! Empty constructor defining an invalid result.
SelectBasics_PickResultSelectBasics_PickResult35   SelectBasics_PickResult()
36   : myObjPickedPnt (RealLast(), 0.0, 0.0),
37     myDepth (RealLast()),
38     myDistToCenter (RealLast()) {}
39 
40   //! Constructor with initialization.
SelectBasics_PickResultSelectBasics_PickResult41   SelectBasics_PickResult (Standard_Real theDepth,
42                            Standard_Real theDistToCenter,
43                            const gp_Pnt& theObjPickedPnt)
44   : myObjPickedPnt (theObjPickedPnt),
45     myDepth (theDepth),
46     myDistToCenter (theDistToCenter) {}
47 
48 public:
49 
50   //! Return TRUE if result was been defined.
IsValidSelectBasics_PickResult51   Standard_Boolean IsValid() const { return myDepth != RealLast(); }
52 
53   //! Reset depth value.
InvalidateSelectBasics_PickResult54   void Invalidate()
55   {
56     myDepth = RealLast();
57     myObjPickedPnt = gp_Pnt (RealLast(), 0.0, 0.0);
58     myNormal.SetValues (0.0f, 0.0f, 0.0f);
59   }
60 
61   //! Return depth along picking ray.
DepthSelectBasics_PickResult62   Standard_Real Depth() const { return myDepth; }
63 
64   //! Set depth along picking ray.
SetDepthSelectBasics_PickResult65   void SetDepth (Standard_Real theDepth) { myDepth = theDepth; }
66 
67   //! Return TRUE if Picked Point lying on detected entity was set.
HasPickedPointSelectBasics_PickResult68   Standard_Boolean HasPickedPoint() const { return myObjPickedPnt.X() != RealLast(); }
69 
70   //! Return picked point lying on detected entity.
71   //! WARNING! Point is defined in local coordinate system and should be translated into World System before usage!
PickedPointSelectBasics_PickResult72   const gp_Pnt& PickedPoint() const { return myObjPickedPnt; }
73 
74   //! Set picked point.
SetPickedPointSelectBasics_PickResult75   void SetPickedPoint (const gp_Pnt& theObjPickedPnt) { myObjPickedPnt = theObjPickedPnt; }
76 
77   //! Return distance to geometry center (auxiliary value for comparing results).
DistToGeomCenterSelectBasics_PickResult78   Standard_Real DistToGeomCenter() const { return myDistToCenter; }
79 
80   //! Set distance to geometry center.
SetDistToGeomCenterSelectBasics_PickResult81   void SetDistToGeomCenter (Standard_Real theDistToCenter) { myDistToCenter = theDistToCenter; }
82 
83   //! Return (unnormalized) surface normal at picked point or zero vector if undefined.
84   //! WARNING! Normal is defined in local coordinate system and should be translated into World System before usage!
SurfaceNormalSelectBasics_PickResult85   const NCollection_Vec3<float>& SurfaceNormal() const { return myNormal; }
86 
87   //! Set surface normal at picked point.
SetSurfaceNormalSelectBasics_PickResult88   void SetSurfaceNormal (const NCollection_Vec3<float>& theNormal) { myNormal = theNormal; }
89 
90   //! Set surface normal at picked point.
SetSurfaceNormalSelectBasics_PickResult91   void SetSurfaceNormal (const gp_Vec& theNormal)
92   {
93     myNormal.SetValues ((float )theNormal.X(), (float )theNormal.Y(), (float )theNormal.Z());
94   }
95 
96 private:
97   gp_Pnt                  myObjPickedPnt; //!< User-picked selection point onto object
98   NCollection_Vec3<float> myNormal;       //!< surface normal
99   Standard_Real           myDepth;        //!< Depth to detected point
100   Standard_Real           myDistToCenter; //!< Distance from 3d projection user-picked selection point to entity's geometry center
101 };
102 
103 #endif // _SelectBasics_PickResult_HeaderFile
104