1 // Copyright (c) 2019 OPEN CASCADE SAS
3 // This file is part of Open CASCADE Technology software library.
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.
11 // Alternatively, this file may be used under the terms of Open CASCADE
12 // commercial license or contractual agreement.
14 #include <SelectMgr_ViewClipRange.hxx>
17 #include <Graphic3d_SequenceOfHClipPlane.hxx>
19 // =======================================================================
20 // function : AddClippingPlanes
22 // =======================================================================
23 void SelectMgr_ViewClipRange::AddClippingPlanes (const Graphic3d_SequenceOfHClipPlane& thePlanes,
24 const gp_Ax1& thePickRay)
26 const gp_Dir& aViewRayDir = thePickRay.Direction();
27 const gp_Pnt& aNearPnt = thePickRay.Location();
29 Graphic3d_Vec4d aPlaneABCD;
30 for (Graphic3d_SequenceOfHClipPlane::Iterator aPlaneIt (thePlanes); aPlaneIt.More(); aPlaneIt.Next())
32 const Handle(Graphic3d_ClipPlane)& aClipPlane = aPlaneIt.Value();
33 if (!aClipPlane->IsOn())
38 Bnd_Range aSubRange (RealFirst(), RealLast());
39 for (const Graphic3d_ClipPlane* aSubPlaneIter = aClipPlane.get(); aSubPlaneIter != NULL; aSubPlaneIter = aSubPlaneIter->ChainNextPlane().get())
41 const gp_Pln aGeomPlane = aSubPlaneIter->ToPlane();
42 aGeomPlane.Coefficients (aPlaneABCD[0], aPlaneABCD[1], aPlaneABCD[2], aPlaneABCD[3]);
44 const gp_XYZ& aPlaneDirXYZ = aGeomPlane.Axis().Direction().XYZ();
45 Standard_Real aDotProduct = aViewRayDir.XYZ().Dot (aPlaneDirXYZ);
46 Standard_Real aDistance = -aNearPnt.XYZ().Dot (aPlaneDirXYZ) - aPlaneABCD[3];
47 Standard_Real aDistToPln = 0.0;
49 // check whether the pick line is parallel to clip plane
50 if (Abs (aDotProduct) < Precision::Angular())
56 aDistToPln = RealLast();
61 // compute distance to point of pick line intersection with the plane
62 const Standard_Real aParam = aDistance / aDotProduct;
64 const gp_Pnt anIntersectionPnt = aNearPnt.XYZ() + aViewRayDir.XYZ() * aParam;
65 aDistToPln = anIntersectionPnt.Distance (aNearPnt);
68 // the plane is "behind" the ray
69 aDistToPln = -aDistToPln;
73 // change depth limits for case of opposite and directed planes
74 if (!aClipPlane->IsChain())
76 if (aDotProduct < 0.0)
78 ChangeUnclipRange().TrimTo (aDistToPln);
82 ChangeUnclipRange().TrimFrom (aDistToPln);
87 if (aDotProduct < 0.0)
89 aSubRange.TrimFrom (aDistToPln);
93 aSubRange.TrimTo (aDistToPln);
98 if (!aSubRange.IsVoid()
99 && aClipPlane->IsChain())
101 AddClipSubRange (aSubRange);
106 // =======================================================================
107 // function : DumpJson
109 // =======================================================================
110 void SelectMgr_ViewClipRange::DumpJson (Standard_OStream& theOStream, Standard_Integer theDepth) const
112 OCCT_DUMP_CLASS_BEGIN (theOStream, SelectMgr_ViewClipRange)
114 for (size_t aRangeIter = 0; aRangeIter < myClipRanges.size(); ++aRangeIter)
116 Bnd_Range aClipRange = myClipRanges[aRangeIter];
117 OCCT_DUMP_FIELD_VALUES_DUMPED (theOStream, theDepth, &aClipRange)
119 OCCT_DUMP_FIELD_VALUES_DUMPED (theOStream, theDepth, &myUnclipRange)