Selection convert to 2D not very Efficient

Forums: 

Hi OCC Visualization Team,

I found that the selection in OCC is in 2D graphic space, so when switch selection mode or change the view camera, the AIS_Shape will use
void StdSelect_ViewerSelector3d::Convert (const Handle(SelectMgr_Selection)& theSel)
to convert the object world coordinate from 3d to 2d space, there are lots of matrix computation involved, and also need space to store the 2d data in the
Select3D_SensitiveEntity .

I think it could generate these sensitive entities 2d data when the mouse move over a shape's bounding box, then generate the sensitive entities 2d data by the selection mode(vertex, edge, face, .etc.) according to the TopoDS_Shape dynamically. This could reduce the conversion(matrix computation) time.

Personal opinion, if wrong, please correct me.

Best Regards,
Xing

Kirill Gavrilov's picture

Hi Xing,

you can track the record #24623 in bugtracker.

In new design selection is performed directly in 3D space (camera rotation no more involves any re-projection) and optimized by efficient BVH structures.

Complete redesign of entire selection mechanisms in OCCT (including public API) is a drawback. Within intermediate tests work-in-progress patch dramatically improves selection performance of big data sets.

Shing Liu's picture

Wow! That's wonderful!

I am looking forward to it.

Sergey Anikin's picture

Hello eryar,

I guess you decided to have a look at the detection algorithm code because of some performance issues. Thus if you have some test cases that could be used to illustrate the performance problem, feel free to share them so that we use them for the new approach benchmarking.

Best regards,
Sergey

Shing Liu's picture

Hi Sergey,

Yeah, I am learning the Visualization module now.
I want to understand the detection algorithm, because of there is a fascinating function for the interactive with the model objects, such as the dragger in the OpenSceneGraph:

Figure 1. Dragger in OpenSceneGraph


Figure 2. Model Editor

You can transform(translate/rotate) the model by moving the mouse on the handler and then drag the handler directly, this is very convenient for model transformation.

When I have the good test cases about performance problem, I will share here.

Best regards,
Xing

Shing Liu's picture

I found AIS_Manipulator to do this in OCCT-7.1.0.
It is great!

AIS_Manipulator

Shing Liu's picture

Hello Sergey,

I wrote a simple Tcl script for the Draw Test Harness to test the performance of switch selection mode, the Tcl script list as follows:


#
# Test Active Selection Mode performance of occ.
#
# Shing Liu(eryar@163.com)
# 2015-03-06 18:02
#

pload ALL

# build a simple scene filled with boxes, cylinders and spheres.
box b 1 2 3

pcylinder c 1 2
ttranslate c 0 0 10

psphere s 1
ttranslate s 0 0 20

set N 10

# array shapes.
set k 0
for {set i 0} {$i < $N} {incr i} {
for {set j 0} {$j < $N} {incr j} {
tcopy b b$k
tcopy c c$k
tcopy s s$k

ttranslate b$k $i*5 $j*5 0.0
ttranslate c$k $i*5 $j*5 0.0
ttranslate s$k $i*5 $j*5 0.0

vdisplay b$k c$k s$k

incr k
}
}

# set display mode to shading.
vsetdispmode 1
vfit

# show system info.
dversion
meminfo
vglinfo

# activates selection mode for all shapes.
puts "active selection mode: vertex"
puts "------------------------------------------"
chrono t1 start
vsetam 1
chrono t1 show
puts "------------------------------------------"

puts "active selection mode: edge"
puts "------------------------------------------"
chrono t2 start
vsetam 2
chrono t2 show
puts "------------------------------------------"

puts "active selection mode: face"
puts "------------------------------------------"
chrono t3 start
vsetam 4
chrono t3 show
puts "------------------------------------------"

From the Tcl Script, I build a simple scene filled with boxes, cylinders and spheres, there total number is 300, and output the time consuming when change selection mode, here is my output:

Draw[1]> source test.tcl
active selection mode: vertex
------------------------------------------
Elapsed time: 0 Hours 0 Minutes 1.7083635909 Seconds
CPU user time: 1.7004109 seconds
CPU system time: 0 seconds
------------------------------------------
active selection mode: edge
------------------------------------------
Elapsed time: 0 Hours 0 Minutes 3.31749469514 Seconds
CPU user time: 3.3228213 seconds
CPU system time: 0 seconds
------------------------------------------
active selection mode: face
------------------------------------------
Elapsed time: 0 Hours 0 Minutes 5.0015310459 Seconds
CPU user time: 4.9764319 seconds
CPU system time: 0 seconds
------------------------------------------
Draw[2]>

Hope the output result will helpful to you.

Best Regards,
Shing Liu

Sergey Anikin's picture

Hello Shing,

Thank you a lot for sharing your test!
Below you can find the results shown by your script in our environment for both the old and the new detection algorithms.

System characteristics:
CPU: Intel Core i5-2400 @ 3.10 GHz
RAM: 16Gb
GPU: NVIDIA GTS450
OS: Windows 7 64-bit

New selection results:

active selection mode: vertex
------------------------------------------
Elapsed time: 0 Hours 0 Minutes 0.0229926067987 Seconds
CPU user time: 0.0312002 seconds
CPU system time: 0 seconds
------------------------------------------
active selection mode: edge
------------------------------------------
Elapsed time: 0 Hours 0 Minutes 0.0357466508867 Seconds
CPU user time: 0.0312002 seconds
CPU system time: 0 seconds
------------------------------------------
active selection mode: face
------------------------------------------
Elapsed time: 0 Hours 0 Minutes 0.0414224037668 Seconds
CPU user time: 0.0468003 seconds
CPU system time: 0 seconds
------------------------------------------

Old selection results:

active selection mode: vertex
------------------------------------------
Elapsed time: 0 Hours 0 Minutes 0.326342507382 Seconds
CPU user time: 0.3276021 seconds
CPU system time: 0 seconds
------------------------------------------
active selection mode: edge
------------------------------------------
Elapsed time: 0 Hours 0 Minutes 0.614150566631 Seconds
CPU user time: 0.624004 seconds
CPU system time: 0 seconds
------------------------------------------
active selection mode: face
------------------------------------------
Elapsed time: 0 Hours 0 Minutes 0.891087432916 Seconds
CPU user time: 0.8892057 seconds
CPU system time: 0 seconds
------------------------------------------

This should give a rough idea regarding performance gain.

Best regards,
Sergey

Shing Liu's picture

Hello Sergey,

The New selection results seems much more fast than the old ones.
How about the result of change the shape number N to 100 or more?

PS:
But how to switch to use the new selection algorithm in occ6.8.0?

Best Regards,
Shing

Kirill Gavrilov's picture

Hello Eryar,

But how to switch to use the new selection algorithm in occ6.8.0?

these improvements are subject of re-designed selection algorithm.

You might look at it in branch CR24623_1 of occt repository,
and should be expected in next OCCT release 6.8.1.

Shing Liu's picture

Hello kgv,

Thanks for your reply, I get it.