0031668: Visualization - WebGL sample doesn't work on Emscripten 1.39
[occt.git] / src / SelectBasics / SelectBasics_PickResult.hxx
CommitLineData
f751596e 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
0ef04197 19#include <gp_Pnt.hxx>
f751596e 20
17017555 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.
f751596e 23struct SelectBasics_PickResult
24{
25public:
17017555 26 //! Return closest result between two Pick Results according to Depth value.
27 static const SelectBasics_PickResult& Min (const SelectBasics_PickResult& thePickResult1,
28 const SelectBasics_PickResult& thePickResult2)
29 {
30 return thePickResult1.Depth() <= thePickResult2.Depth() ? thePickResult1 : thePickResult2;
31 }
f751596e 32
17017555 33public:
34 //! Empty constructor defining an invalid result.
f751596e 35 SelectBasics_PickResult()
17017555 36 : myObjPickedPnt (RealLast(), 0.0, 0.0),
37 myDepth (RealLast()),
38 myDistToCenter (RealLast()) {}
f751596e 39
17017555 40 //! Constructor with initialization.
41 SelectBasics_PickResult (Standard_Real theDepth,
42 Standard_Real theDistToCenter,
43 const gp_Pnt& theObjPickedPnt)
44 : myObjPickedPnt (theObjPickedPnt),
45 myDepth (theDepth),
f751596e 46 myDistToCenter (theDistToCenter) {}
47
48public:
f751596e 49
17017555 50 //! Return TRUE if result was been defined.
51 Standard_Boolean IsValid() const { return myDepth != RealLast(); }
52
53 //! Reset depth value.
54 void Invalidate()
f751596e 55 {
17017555 56 myDepth = RealLast();
57 myObjPickedPnt = gp_Pnt (RealLast(), 0.0, 0.0);
2615c2d7 58 myNormal.SetValues (0.0f, 0.0f, 0.0f);
f751596e 59 }
60
17017555 61 //! Return depth along picking ray.
62 Standard_Real Depth() const { return myDepth; }
63
64 //! Set depth along picking ray.
65 void SetDepth (Standard_Real theDepth) { myDepth = theDepth; }
66
67 //! Return TRUE if Picked Point lying on detected entity was set.
68 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!
72 const gp_Pnt& PickedPoint() const { return myObjPickedPnt; }
73
74 //! Set picked point.
75 void SetPickedPoint (const gp_Pnt& theObjPickedPnt) { myObjPickedPnt = theObjPickedPnt; }
76
77 //! Return distance to geometry center (auxiliary value for comparing results).
78 Standard_Real DistToGeomCenter() const { return myDistToCenter; }
79
80 //! Set distance to geometry center.
81 void SetDistToGeomCenter (Standard_Real theDistToCenter) { myDistToCenter = theDistToCenter; }
82
2615c2d7 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!
85 const NCollection_Vec3<float>& SurfaceNormal() const { return myNormal; }
86
87 //! Set surface normal at picked point.
88 void SetSurfaceNormal (const NCollection_Vec3<float>& theNormal) { myNormal = theNormal; }
89
90 //! Set surface normal at picked point.
91 void SetSurfaceNormal (const gp_Vec& theNormal)
92 {
93 myNormal.SetValues ((float )theNormal.X(), (float )theNormal.Y(), (float )theNormal.Z());
94 }
95
f751596e 96private:
2615c2d7 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
f751596e 101};
102
103#endif // _SelectBasics_PickResult_HeaderFile