DiscussionsIssue archiveOCCT:Visualization

Archived issue #0032182

Visualization - add Select3D_SensitiveSphere

Open CASCADEOCCT:Visualizationclosed74 public notes

Search issues

Description

It is proposed implementing Select3D_SensitiveSphere class performing an analytical intersection with an untriangulated sphere defined by it's center and radius.

It will be necessary implementing interfaces for ray/sphere, frustum/sphere and overlapped/nonoverlapped intersection methods (AIS_InteractiveContext::SelectPoint()/SelectRectangle()/SelectPolygon() and SelectMgr_ViewerSelector::AllowOverlapDetection()) - to be covered by new tests.

As a first step, testing could be done by an auxiliary Interactive Object in ViewerTest package - automatic detection of simple sphere geometry within StdSelect::StdSelect_BRepSelectionTool could be considered as next step.

Steps to reproduce

pload MODELING VISUALIZATION

vinit View1 w=1024 h=1024
vclear
# parameter NB defines number of spheres by each coordinate
set NB 10
puts "Creating [expr $NB * $NB * $NB] spheres..."
for {set i 0} {$i < $NB} {incr i} {
  for {set j 0} {$j < $NB} {incr j} {
    for {set k 0} {$k < $NB} {incr k} {
      psphere s$i$j$k 1.
      ttranslate s$i$j$k 3.*$i 3.*$j 3.*$k
      vdisplay -dispMode 1 s$i$j$k 
    }
  }
}
vfit
dchrono cpu restart
vmoveto 512 554
vselect 15 15 1020 1020
vtop
vselect 31 113 730 113 730 816 31 816
vselect 67 134 128 194
vaxo
vmoveto 96 675
vmoveto 176 675
vmoveto 287 675
vmoveto 372 675
vmoveto 454 675
vmoveto 553 675
vmoveto 646 675
vmoveto 734 675
vmoveto 814 675
vmoveto 921 675
dchrono cpu stop counter moveTo

Additional information

According to the results of comparing the performance of the new spherical class
The time spent building a BVH tree to triangulate each sphere was significantly reduced.
Elapsed Time: From 2 minutes 21 seconds to 0.655 seconds (2052.7% speed increase)
CPU user time: From 140.27 seconds to 0.484 seconds (2800% speed increase)

The time taken to intersect with thousands of spheres when detected by the beam also dropped.
Elapsed Time: From 1.55 seconds to 0.448 seconds (246% speed increase)
CPU user time: From 1.25 seconds to 0.146 seconds (756% speed increase)

Performance test scenario:
pload MODELING VISUALIZATION
vinit View1
vdefaults -autoTriang 0
set nb 5000
set lst {}
for {set i 0} {$i < $nb} {incr i} { psphere s$i 1; lappend lst s$i }
for {set i 0} {$i < $nb} {incr i} { ttranslate s$i 0 0 $i }
compound {*}$lst c
incmesh c 0.008
for {set i 0} {$i < $nb} {incr i} { vdisplay -dispMode 1 s$i -noupdate }
vtop
vfit
# delayed BVH building
dchrono t reset; dchrono t start
vmoveto 200 200
dchrono t stop;  dchrono t show
dchrono t reset; dchrono t start
# single pick time (with precomputed BVH)
vmoveto 0 0
vmoveto 200 200
dchrono t stop;  dchrono t show


Public activity

74 archived notes

Participants are labeled by their role within this record.

01Commenter 1
Branch [archived branch] has been created by Participant.

Author: mkrylova
Date: Mon Mar 22

    0032182: Visualization - add Select3D_SensitiveSphere

    - created Select3D_SensitiveSphere class
    - implemented interfaces for intersection methods
    - added tests
02Commenter 3
Branch [archived branch] has been created by Author.

[revision removed]


Detailed log of new commits:

Author: mkrylova
Date: Wed Mar 17 17:38:00 2021 +0300

    0032182: Visualization - add Select3D_SensitiveSphere
    
    - created Select3D_SensitiveSphere class
    - implemented interfaces for intersection methods
    - added tests
03Commenter 3
Branch [archived branch] has been updated by Participant.

[revision removed]


Detailed log of new commits:

Author: mkrylova
Date: Tue Mar 23 17:05:29 2021 +0300

    # kgv remarks
    - fixed code style
    - added test to check the depth

04Commenter 3
Branch [archived branch] has been created by Participant.

[revision removed]


Detailed log of new commits:

Author: mkrylova
Date: Wed Mar 17 17:38:00 2021 +0300

    0032182: Visualization - add Select3D_SensitiveSphere
    
    - created Select3D_SensitiveSphere class
    - implemented interfaces for intersection methods
    - added tests
05Author
Failing test cases (to be updated or analyzed): v3d bugs bug24606,bug25935
06Commenter 3
Branch [archived branch] has been updated forcibly by Author.

[revision removed]
07Commenter 3
Branch [archived branch] has been updated by Participant.

[revision removed]


Detailed log of new commits:

Author: mkrylova
Date: Tue Mar 30 17:39:22 2021 +0300

    # kgv remarks
    - fixed tests
    - fixed depth calculation

08Commenter 3
Branch [archived branch] has been created by Participant.

[revision removed]


Detailed log of new commits:

Author: mkrylova
Date: Wed Mar 17 17:38:00 2021 +0300

    0032182: Visualization - add Select3D_SensitiveSphere
    
    - created Select3D_SensitiveSphere class
    - implemented interfaces for intersection methods
    - added tests
09Commenter 3
Branch [archived branch] has been updated by Participant.

[revision removed]


Detailed log of new commits:

Author: mkrylova
Date: Wed Mar 31 13:42:39 2021 +0300

    # add checking for a negative value

10Commenter 3
Branch [archived branch] has been created by Participant.

[revision removed]


Detailed log of new commits:

Author: mkrylova
Date: Wed Mar 17 17:38:00 2021 +0300

    0032182: Visualization - add Select3D_SensitiveSphere
    
    - created Select3D_SensitiveSphere class
    - implemented interfaces for intersection methods
    - added tests
11Commenter 3
Branch [archived branch] has been updated by Participant.

[revision removed]


Detailed log of new commits:

Author: mkrylova
Date: Thu Apr 1 19:09:04 2021 +0300

    # fixed depth scale

12Commenter 3
Branch [archived branch] has been created by Participant.

[revision removed]


Detailed log of new commits:

Author: mkrylova
Date: Wed Mar 17 17:38:00 2021 +0300

    0032182: Visualization - add Select3D_SensitiveSphere
    
    - created Select3D_SensitiveSphere class
    - implemented interfaces for intersection methods
    - added tests
13Commenter 3
Branch [archived branch] has been updated forcibly by Participant.

[revision removed]
14Author
SelectMgr_RectangularFrustum::OverlapsSphere() is expected to return surface normal as in case of overlapped triangle:
> thePickResult.SetSurfaceNormal (aTriangleNormal);

But current implement doesn't compute normal.

15Commenter 3
Branch [archived branch] has been updated forcibly by Participant.

[revision removed]
16Commenter 3
Branch [archived branch] has been created by Participant.

[revision removed]


Detailed log of new commits:

Author: mkrylova
Date: Wed Mar 17 17:38:00 2021 +0300

    0032182: Visualization - add Select3D_SensitiveSphere
    
    - created Select3D_SensitiveSphere class
    - implemented interfaces for intersection methods
    - added tests
17Commenter 3
Branch [archived branch] has been updated by Participant.

[revision removed]


Detailed log of new commits:

Author: osa
Date: Fri Apr 30 10:33:32 2021 +0300

    #osa remarks

18Commenter 18
Broken test case:

psphere s 1
vdisplay -dispMode 1 s
box b 3 3 3 1 1 1
vdisplay b -dispMode 1
vfit
vselect 0 0 400 400 -allowoverlap 0 #OK
vselect 0 0 400 400 -allowoverlap 1 #KO (see attached screenshot)

19Commenter 3
Branch [archived branch] has been updated forcibly by Participant.

[revision removed]
20Commenter 3
Branch [archived branch] has been created by Participant.

[revision removed]


Detailed log of new commits:

Author: mkrylova
Date: Wed Mar 17 17:38:00 2021 +0300

    0032182: Visualization - add Select3D_SensitiveSphere
    
    - created Select3D_SensitiveSphere class
    - implemented interfaces for intersection methods
    - added tests
21Commenter 21
Analysis, Testing
22Commenter 3
Branch [archived branch] has been updated forcibly by Participant.

[revision removed]
23Commenter 3
Branch [archived branch] has been updated forcibly by Participant.

[revision removed]
24Commenter 3
Branch [archived branch] has been updated forcibly by Participant.

[revision removed]
25Commenter 3
Branch [archived branch] has been created by Participant.

[revision removed]


Detailed log of new commits:

Author: mkrylova
Date: Wed Mar 17 17:38:00 2021 +0300

    0032182: Visualization - add Select3D_SensitiveSphere
    
    - created Select3D_SensitiveSphere class
    - implemented interfaces for intersection methods
    - added tests
26Commenter 26
Solution Implementation, Testing
27Commenter 27
1) Standard_Real aNormVecLen -> const Standard_Real aNormVecLen
Standard_Real aMaxDist -> const Standard_Real aMaxDist
Standard_Real aMinDist -> const Standard_Real aMinDist

2) Move this block to place before its usage
    aMinSumDistance2 += (aCenterProj - aMinDist) * (aCenterProj - aMinDist);
    aMaxSumDistance2 += (aCenterProj - aMaxDist) * (aCenterProj - aMaxDist);

3) This implementation is the same to base one (SelectMgr_BaseIntersector::OverlapsSphere). It is no needs to override it.
//=======================================================================
// function : OverlapsSphere
// purpose :
//=======================================================================
Standard_Boolean SelectMgr_BaseFrustum::OverlapsSphere (const gp_Pnt&,
                                                        const Standard_Real,
                                                        Standard_Boolean*) const
{
  return Standard_False;
}

//=======================================================================
// function : OverlapsSphere
// purpose :
//=======================================================================
Standard_Boolean SelectMgr_BaseFrustum::OverlapsSphere (const gp_Pnt&,
                                                        const Standard_Real,
                                                        const SelectMgr_ViewClipRange&,
                                                        SelectBasics_PickResult& ) const
{
  return Standard_False;
}

4) This code is identical for SelectMgr_TriangularFrustumSet::isCenterInside() and SelectMgr_TriangularFrustumSet::isIntersectSphereBoundaries(). It will be better to move it to some new method (and not duplicate the same code twice) and if it is possible to avoid duplication of these computations (you call both isIntersectSphereBoundaries and isCenterInside).

  // select 3 points of the frustum and build a plane on them
  Standard_Real aMaxDist1 = 0.0, aMaxDist2 = 0.0;
  Standard_Integer anIdx1 = myBoundaryPoints.Lower();
  Standard_Integer anIdx2 = myBoundaryPoints.Lower();
  Standard_Integer anIdx3 = myBoundaryPoints.Lower();
  for (Standard_Integer anIdx = myBoundaryPoints.Lower(); anIdx < myBoundaryPoints.Size() / 2 + myBoundaryPoints.Lower(); anIdx++)
  {
    if (myBoundaryPoints[anIdx1].Distance (myBoundaryPoints[anIdx]) < Precision::Confusion())
    {
      continue;
    }
    else if (aMaxDist1 < myBoundaryPoints[anIdx1].Distance (myBoundaryPoints[anIdx]))
    {
      if (anIdx2 != anIdx3)
      {
        anIdx3 = anIdx2;
        aMaxDist2 = aMaxDist1;
      }
      anIdx2 = anIdx;
      aMaxDist1 = myBoundaryPoints[anIdx1].Distance (myBoundaryPoints[anIdx]);
    }
    else if (aMaxDist2 < myBoundaryPoints[anIdx2].Distance (myBoundaryPoints[anIdx]))
    {
      anIdx3 = anIdx;
      aMaxDist2 = myBoundaryPoints[anIdx2].Distance (myBoundaryPoints[anIdx]);
    }
  }
  gp_Vec aVecPlane1 (myBoundaryPoints[anIdx1], myBoundaryPoints[anIdx2]);
  gp_Vec aVecPlane2 (myBoundaryPoints[anIdx1], myBoundaryPoints[anIdx3]);

  gp_Dir aNorm (aVecPlane1.Crossed (aVecPlane2));
  gp_Pln aPlane (myBoundaryPoints.Value (anIdx1), aNorm);

  // distance from point(x,y,z) to plane(A,B,C,D) d = | Ax + By + Cz + D | / sqrt (A^2 + B^2 + C^2) = aPnt.Dot (Norm) / 1
  gp_Pnt aCenterProj = theCenter.XYZ() - aNorm.XYZ() * theCenter.XYZ().Dot (aNorm.XYZ());

5) Remove SelectMgr_TriangularFrustumSet:: from header file

Standard_EXPORT Standard_Boolean SelectMgr_TriangularFrustumSet::isIntersectSphereBoundaries
Standard_EXPORT Standard_Boolean SelectMgr_TriangularFrustumSet:: isCenterInside
28Commenter 28
Add implementation of ::OverlapsSphere for SelectMgr_AxisIntersector (intersection of sphere with geometry axis) and check test vselect/axis/A1 after it.
29Commenter 29
Solution elaboration, Testing
30Commenter 3
Branch [archived branch] has been updated forcibly by Participant.

[revision removed]
31Commenter 3
Branch [archived branch] has been created by Participant.

[revision removed]


Detailed log of new commits:

Author: mkrylova
Date: Wed Mar 17 17:38:00 2021 +0300

    0032182: Visualization - add Select3D_SensitiveSphere
    
    - created Select3D_SensitiveSphere class
    - implemented interfaces for intersection methods
    - added tests
32Commenter 3
Branch [archived branch] has been updated by Participant.

[revision removed]


Detailed log of new commits:

Author: mkrylova
Date: Thu Jun 3 16:55:45 2021 +0300

    # added axis test group in grids.list

33Commenter 3
Branch [archived branch] has been created by Participant.

[revision removed]


Detailed log of new commits:

Author: mkrylova
Date: Wed Mar 17 17:38:00 2021 +0300

    0032182: Visualization - add Select3D_SensitiveSphere
    
    - created Select3D_SensitiveSphere class
    - implemented interfaces for intersection methods
    - added tests
34Commenter 34
Solution implementation, Testing
35Commenter 35
Testing
36Commenter 3
Branch [archived branch] has been updated forcibly by Participant.

[revision removed]
37Commenter 3
Branch [archived branch] has been updated by Participant.

[revision removed]


Detailed log of new commits:

Author: mkrylova
Date: Mon Jun 7 16:11:08 2021 +0300

    # fixed normals

38Commenter 3
Branch [archived branch] has been created by Participant.

[revision removed]


Detailed log of new commits:

Author: mkrylova
Date: Wed Mar 17 17:38:00 2021 +0300

    0032182: Visualization - add Select3D_SensitiveSphere
    
    - created Select3D_SensitiveSphere class
    - implemented interfaces for intersection methods
    - added tests
    
    # fixed normals
39Commenter 39
Testing
40Commenter 40
41Commenter 41
Patch is ready to review:
  - OCCT: CR32182_11
42Commenter 42
Testing
43Commenter 3
Branch [archived branch] has been updated by Author.

[revision removed]


Detailed log of new commits:

Author: Author
Date: Fri Jun 11 10:31:02 2021 +0300

    # cosmetics and rebase fixes

44Author
Maria, could you please re-check handling theInside==NULL argument within SelectMgr_RectangularFrustum::OverlapsSphere()?
45Commenter 3
Branch [archived branch] has been updated forcibly by Participant.

[revision removed]
46Commenter 3
Branch [archived branch] has been created by Participant.

[revision removed]


Detailed log of new commits:

Author: mkrylova
Date: Wed Mar 17 17:38:00 2021 +0300

    0032182: Visualization - add Select3D_SensitiveSphere
    
    - created Select3D_SensitiveSphere class
    - implemented interfaces for intersection methods
    - added tests
47Commenter 48
Solution implementation, Testing
48Commenter 3
Branch [archived branch] has been updated forcibly by Participant.

[revision removed]
49Commenter 50
50Commenter 51
Patch is ready to review:
  - OCCT: CR32182_12
51Commenter 1
52Commenter 3
Branch [archived branch] has been updated forcibly by Participant.

[revision removed]
53Commenter 3
Branch [archived branch] has been updated by Participant.

[revision removed]


Detailed log of new commits:

Author: mkrylova
Date: Mon Jun 21 14:56:01 2021 +0300

    # kgv remarks

54Commenter 3
Branch [archived branch] has been created by Participant.

[revision removed]


Detailed log of new commits:

Author: mkrylova
Date: Wed Mar 17 17:38:00 2021 +0300

    0032182: Visualization - add Select3D_SensitiveSphere
    
    - created Select3D_SensitiveSphere class
    - implemented interfaces for intersection methods
    - added tests
55Commenter 56
Testing
56Commenter 3
Branch [archived branch] has been updated forcibly by Participant.

[revision removed]
57Commenter 58
58Commenter 59
Patch is ready to review:
  - OCCT: CR32182_13
59Commenter 60
Testing
60Commenter 1
Combination -
OCCT branch : [archived branch]
master SHA - [revision removed]
[revision removed]
Products branch : [archived branch] SHA - [revision removed]
was compiled on Linux, MacOS and Windows platforms and tested in optimize mode.

Number of compiler warnings:
No new/fixed warnings

Regressions/Differences/Improvements:
No regressions/differences

CPU differences:
Debian80-64:
OCCT
Total CPU difference: 17457.040000000452 / 17401.81000000044 [+0.32%]
Products
Total CPU difference: 11511.540000000101 / 11508.180000000091 [+0.03%]
Windows-64-VC14:
OCCT
Total CPU difference: 19236.53125 / 19191.4375 [+0.23%]
Products
Total CPU difference: 12832.328125 / 12883.6875 [-0.40%]


Image differences :
No differences that require special attention

Memory differences :
No differences that require special attention
61Commenter 3
Branch [archived branch] has been deleted by Participant.

[revision removed]
62Commenter 3
Branch [archived branch] has been deleted by Participant.

[revision removed]
63Commenter 3
Branch [archived branch] has been deleted by Participant.

[revision removed]
64Commenter 3
Branch [archived branch] has been deleted by Participant.

[revision removed]
65Commenter 3
Branch [archived branch] has been deleted by Participant.

[revision removed]
66Commenter 3
Branch [archived branch] has been deleted by Participant.

[revision removed]
67Commenter 3
Branch [archived branch] has been deleted by Participant.

[revision removed]
68Commenter 3
Branch [archived branch] has been deleted by Participant.

[revision removed]
69Commenter 3
Branch [archived branch] has been deleted by Participant.

[revision removed]
70Commenter 3
Branch [archived branch] has been deleted by Participant.

[revision removed]
71Commenter 3
Branch [archived branch] has been deleted by Participant.

[revision removed]
72Commenter 3
Branch [archived branch] has been deleted by Participant.

[revision removed]
73Commenter 3
Branch [archived branch] has been deleted by Participant.

[revision removed]
74Commenter 3
Branch [archived branch] has been deleted by Participant.

[revision removed]

Related records