1
0
mirror of https://git.dev.opencascade.org/repos/occt.git synced 2025-08-14 13:30:48 +03:00

0025098: Visualization, Select3D_SensitiveCurve - fix computation of the depth

Draw Harness, add option -entities to command vstate.
Within new option command displays information about detection entities.
This commit is contained in:
vro
2014-09-12 15:11:53 +04:00
committed by bugmaster
parent c19dd45ee0
commit 8e7c8ccf3a
14 changed files with 288 additions and 26 deletions

View File

@@ -36,10 +36,11 @@ uses
Curve from Geom,
Array1OfPnt from TColgp,
Array1OfPnt2d from TColgp,
HArray1OfPnt from TColgp,
HArray1OfPnt from TColgp,
Box2d from Bnd,
Location from TopLoc,
SensitiveEntity from Select3D
Location from TopLoc,
SensitiveEntity from Select3D,
XYZ from gp
raises
ConstructionError from Standard,
@@ -120,6 +121,17 @@ is
---Level: Public
---Purpose: Returns the copy of this
ComputeDepth(me;
thePickLine : Lin from gp;
theP1 : XYZ from gp;
theP2 : XYZ from gp;
theDepth : out Real from Standard)
---Purpose: Computes the depth by means of intersection of
-- a segment of the curve defined by <theP1, theP2> and
-- the eye-line <thePickLine>.
returns Boolean from Standard
is protected;
fields
mylastseg : Integer from Standard;
myCurve : Curve from Geom;

View File

@@ -20,7 +20,7 @@
#include <Precision.hxx>
#include <ElCLib.hxx>
#include <CSLib_Class2d.hxx>
#include <Extrema_ExtElC.hxx>
//==================================================
// Function: Creation
@@ -187,20 +187,43 @@ void Select3D_SensitiveCurve::Dump(Standard_OStream& S,const Standard_Boolean Fu
Standard_Real Select3D_SensitiveCurve::ComputeDepth (const gp_Lin& thePickLine,
const Standard_Integer theSegment) const
{
Standard_Real aDepth = Precision::Infinite();
if (theSegment == 0)
{
return Precision::Infinite();
return aDepth;
}
// In case if theSegment and theSegment + 1 are not valid
// the depth will be infinite
if (theSegment >= mypolyg.Size())
{
return Precision::Infinite();
return aDepth;
}
gp_XYZ aCDG = mypolyg.Pnt (theSegment);
// Check depth of a line forward within the curve.
if (theSegment + 1 < mypolyg.Size())
{
gp_XYZ aCDG1 = mypolyg.Pnt (theSegment + 1);
if (ComputeDepth(thePickLine, aCDG, aCDG1, aDepth))
{
return aDepth;
}
}
// Check depth of a line backward within the curve.
if (theSegment - 1 >= 0)
{
gp_XYZ aCDG1 = mypolyg.Pnt (theSegment - 1);
if (ComputeDepth(thePickLine, aCDG, aCDG1, aDepth))
{
return aDepth;
}
}
// Calculate the depth in the middle point of
// a next (forward) segment of the curve.
if (theSegment + 1 < mypolyg.Size())
{
aCDG += mypolyg.Pnt(theSegment + 1);
@@ -244,3 +267,48 @@ Handle(Select3D_SensitiveEntity) Select3D_SensitiveCurve::GetConnected(const Top
return aNewEntity;
}
//=======================================================================
//function : ComputeDepth()
//purpose : Computes the depth by means of intersection of
// a segment of the curve defined by <theP1, theP2> and
// the eye-line <thePickLine>.
//=======================================================================
Standard_Boolean Select3D_SensitiveCurve::ComputeDepth(const gp_Lin& thePickLine,
const gp_XYZ& theP1,
const gp_XYZ& theP2,
Standard_Real& theDepth) const
{
// The segment may have null length.
gp_XYZ aVec = theP2 - theP1;
Standard_Real aLength = aVec.Modulus();
if (aLength <= gp::Resolution())
{
theDepth = ElCLib::Parameter(thePickLine, theP1);
return Standard_True;
}
// Compute an intersection point of the segment-line and the eye-line.
gp_Lin aLine (theP1, aVec);
Extrema_ExtElC anExtrema(aLine, thePickLine, Precision::Angular());
if (anExtrema.IsDone() && !anExtrema.IsParallel() )
{
// Iterator on solutions (intersection points).
for (Standard_Integer i = 1; i <= anExtrema.NbExt(); i++)
{
// Get the intersection point.
Extrema_POnCurv aPointOnLine1, aPointOnLine2;
anExtrema.Points(i, aPointOnLine1, aPointOnLine2);
// Check bounds: the point of intersection should lie within the segment.
if (aPointOnLine1.Parameter() > 0.0 && aPointOnLine1.Parameter() < aLength)
{
theDepth = ElCLib::Parameter(thePickLine, aPointOnLine1.Value());
return Standard_True;
}
}
}
return Standard_False;
}