d7fa57a7 |
1 | // Copyright (c) 2019 OPEN CASCADE SAS |
2 | // |
3 | // This file is part of Open CASCADE Technology software library. |
4 | // |
5 | // This library is free software; you can redistribute it and/or modify it under |
6 | // the terms of the GNU Lesser General Public License version 2.1 as published |
7 | // by the Free Software Foundation, with special exception defined in the file |
8 | // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT |
9 | // distribution for complete text of the license and disclaimer of any warranty. |
10 | // |
11 | // Alternatively, this file may be used under the terms of Open CASCADE |
12 | // commercial license or contractual agreement. |
13 | |
14 | #include <SelectMgr_ViewClipRange.hxx> |
15 | |
d7fa57a7 |
16 | #include <Graphic3d_SequenceOfHClipPlane.hxx> |
17 | |
18 | // ======================================================================= |
19 | // function : AddClippingPlanes |
20 | // purpose : |
21 | // ======================================================================= |
22 | void SelectMgr_ViewClipRange::AddClippingPlanes (const Graphic3d_SequenceOfHClipPlane& thePlanes, |
23 | const gp_Ax1& thePickRay) |
24 | { |
25 | const gp_Dir& aViewRayDir = thePickRay.Direction(); |
26 | const gp_Pnt& aNearPnt = thePickRay.Location(); |
27 | |
28 | Graphic3d_Vec4d aPlaneABCD; |
29 | for (Graphic3d_SequenceOfHClipPlane::Iterator aPlaneIt (thePlanes); aPlaneIt.More(); aPlaneIt.Next()) |
30 | { |
31 | const Handle(Graphic3d_ClipPlane)& aClipPlane = aPlaneIt.Value(); |
32 | if (!aClipPlane->IsOn()) |
33 | { |
34 | continue; |
35 | } |
36 | |
37 | Bnd_Range aSubRange (RealFirst(), RealLast()); |
38 | for (const Graphic3d_ClipPlane* aSubPlaneIter = aClipPlane.get(); aSubPlaneIter != NULL; aSubPlaneIter = aSubPlaneIter->ChainNextPlane().get()) |
39 | { |
40 | const gp_Pln aGeomPlane = aSubPlaneIter->ToPlane(); |
41 | aGeomPlane.Coefficients (aPlaneABCD[0], aPlaneABCD[1], aPlaneABCD[2], aPlaneABCD[3]); |
42 | |
43 | const gp_XYZ& aPlaneDirXYZ = aGeomPlane.Axis().Direction().XYZ(); |
44 | Standard_Real aDotProduct = aViewRayDir.XYZ().Dot (aPlaneDirXYZ); |
45 | Standard_Real aDistance = -aNearPnt.XYZ().Dot (aPlaneDirXYZ) - aPlaneABCD[3]; |
46 | Standard_Real aDistToPln = 0.0; |
47 | |
48 | // check whether the pick line is parallel to clip plane |
49 | if (Abs (aDotProduct) < Precision::Angular()) |
50 | { |
51 | if (aDistance < 0.0) |
52 | { |
53 | continue; |
54 | } |
55 | aDistToPln = RealLast(); |
56 | aDotProduct = 1.0; |
57 | } |
58 | else |
59 | { |
60 | // compute distance to point of pick line intersection with the plane |
61 | const Standard_Real aParam = aDistance / aDotProduct; |
62 | |
63 | const gp_Pnt anIntersectionPnt = aNearPnt.XYZ() + aViewRayDir.XYZ() * aParam; |
64 | aDistToPln = anIntersectionPnt.Distance (aNearPnt); |
65 | if (aParam < 0.0) |
66 | { |
67 | // the plane is "behind" the ray |
68 | aDistToPln = -aDistToPln; |
69 | } |
70 | } |
71 | |
72 | // change depth limits for case of opposite and directed planes |
73 | if (!aClipPlane->IsChain()) |
74 | { |
75 | if (aDotProduct < 0.0) |
76 | { |
77 | ChangeUnclipRange().TrimTo (aDistToPln); |
78 | } |
79 | else |
80 | { |
81 | ChangeUnclipRange().TrimFrom (aDistToPln); |
82 | } |
83 | } |
84 | else |
85 | { |
86 | if (aDotProduct < 0.0) |
87 | { |
88 | aSubRange.TrimFrom (aDistToPln); |
89 | } |
90 | else |
91 | { |
92 | aSubRange.TrimTo (aDistToPln); |
93 | } |
94 | } |
95 | } |
96 | |
97 | if (!aSubRange.IsVoid() |
98 | && aClipPlane->IsChain()) |
99 | { |
100 | AddClipSubRange (aSubRange); |
101 | } |
102 | } |
103 | } |
0904aa63 |
104 | |
105 | // ======================================================================= |
106 | // function : DumpJson |
107 | // purpose : |
108 | // ======================================================================= |
bc73b006 |
109 | void SelectMgr_ViewClipRange::DumpJson (Standard_OStream& theOStream, Standard_Integer theDepth) const |
0904aa63 |
110 | { |
bc73b006 |
111 | OCCT_DUMP_CLASS_BEGIN (theOStream, SelectMgr_ViewClipRange) |
0904aa63 |
112 | |
0904aa63 |
113 | for (size_t aRangeIter = 0; aRangeIter < myClipRanges.size(); ++aRangeIter) |
114 | { |
bc73b006 |
115 | Bnd_Range aClipRange = myClipRanges[aRangeIter]; |
116 | OCCT_DUMP_FIELD_VALUES_DUMPED (theOStream, theDepth, &aClipRange) |
0904aa63 |
117 | } |
bc73b006 |
118 | OCCT_DUMP_FIELD_VALUES_DUMPED (theOStream, theDepth, &myUnclipRange) |
0904aa63 |
119 | } |