0025024: BSplCLib::PrepareInsertKnots reports incorrect number of poles
[occt.git] / samples / tcl / spheres.tcl
CommitLineData
4e18052b 1# test performance of display of heavy scene involving multiple interactive
2# objects, on example of 1000 spheres
3
4pload MODELING
5pload VISUALIZATION
6
7vinit View1 w=1024 h=1024
8vclear
9
10# parameter NB defines number of spheres by each coordinate
11set NB 10
12puts "Creating [expr $NB * $NB * $NB] spheres..."
13set slist {}
14for {set i 0} {$i < $NB} {incr i} {
15 for {set j 0} {$j < $NB} {incr j} {
16 for {set k 0} {$k < $NB} {incr k} {
17 psphere s$i$j$k 1.
18 lappend slist s$i$j$k
19 ttranslate s$i$j$k 3.*$i 3.*$j 3.*$k
20 }
21 }
22}
23
24puts "Measuring FPS of display of spheres as separate objects..."
25vaxo
26vsetdispmode 1
27eval vdisplay $slist
28vfit
29
30# measure FPS
31puts [set fps_separate [vfps]]
32vclear
33
34puts "Measuring FPS of display of spheres as single object..."
35eval compound $slist c
36vdisplay c
37
38# measure FPS
39puts [set fps_compound [vfps]]
40vclear
41
42# redisplay individual spheres, trying to avoid unnecessary internal updates
43#vfrustumculling 0 ;# try to disable updates of frustum culling structures
44eval vdisplay -mutable $slist
45
46# auxiliary procedure to make random update of variable
47proc upd {theValueName theDeltaName theTime theToRand} {
48 upvar $theValueName aValue
49 upvar $theDeltaName aDelta
50
51 # set colors to corner spheres
52 if { $theToRand == 1 } {
53 set aValue [expr $aValue + $aDelta * $theTime / 100.0]
54 set aDelta [expr 0.5 * (rand() - 0.5)]
55 return $aValue
56 }
57
58 set aRes [expr $aValue + $aDelta * $theTime / 100.0]
59}
60
61# move corner spheres in cycle
62proc animateSpheres {{theDuration 10.0}} {
63 set nb [expr $::NB - 1]
64
65 # set colors to corner spheres
66 for {set i 0} {$i < $::NB} {incr i $nb} {
67 for {set j 0} {$j < $::NB} {incr j $nb} {
68 for {set k 0} {$k < $::NB} {incr k $nb} {
69# vaspects -noupdate s$i$j$k -setcolor red -setmaterial plastic
70 vaspects -noupdate s$i$j$k -setcolor red
71 set x$i$j$k 0.0
72 set y$i$j$k 0.0
73 set z$i$j$k 0.0
74 set dx$i$j$k 0.0
75 set dy$i$j$k 0.0
76 set dz$i$j$k 0.0
77 }
78 }
79 }
80
81 set aDuration 0.0
82 set aPrevRand 0.0
83 set aTimeFrom [clock clicks -milliseconds]
84 uplevel #0 chrono anAnimTimer reset
85 uplevel #0 chrono anAnimTimer start
86 set toRand 1
87 for {set aFrameIter 1} { $aFrameIter > 0 } {incr aFrameIter} {
88 set aCurrTime [expr [clock clicks -milliseconds] - $aTimeFrom]
89 if { $aCurrTime >= [expr $theDuration * 1000.0] } {
90 puts "Nb Frames: $aFrameIter"
91 puts "Duration: [expr $aCurrTime * 0.001] s"
92 set fps [expr ($aFrameIter - 1) / ($aDuration * 0.001) ]
93 puts "FPS: $fps"
94 uplevel #0 chrono anAnimTimer stop
95 uplevel #0 chrono anAnimTimer show
96 return $fps
97 }
98
99 set aRandTime [expr $aCurrTime - $aPrevRand]
100 if { $aRandTime > 1000 } {
101 set toRand 1
102 set aPrevRand $aCurrTime
103 }
104
105 #puts "PTS: $aCurrTime ms"
106 for {set i 0} {$i < $::NB} {incr i $nb} {
107 for {set j 0} {$j < $::NB} {incr j $nb} {
108 for {set k 0} {$k < $::NB} {incr k $nb} {
109 uplevel #0 vsetlocation -noupdate s$i$j$k [upd x$i$j$k dx$i$j$k $aRandTime $toRand] [upd y$i$j$k dy$i$j$k $aRandTime $toRand] [upd z$i$j$k dz$i$j$k $aRandTime $toRand]
110 }
111 }
112 }
113 uplevel #0 vrepaint
114 set aDuration [expr [clock clicks -milliseconds] - $aTimeFrom]
115 set toRand 0
116
117 # sleep 1 ms allowing the user to interact with the viewer
118 after 1 set waiter 1
119 vwait waiter
120 }
121}
122
123puts "Animating movements of corner spheres (10 sec)..."
124puts "(you can interact with the view during the process)"
125set fps_animation [animateSpheres 10.0]
126
127puts ""
128puts "Performance counters (FPS = \"Frames per second\"):"
129puts ""
130puts "Spheres as separate interactive objects:"
131puts " Actual FPS: [lindex $fps_separate 1]"
132puts " FPS estimate by CPU load: [expr 1000. / [lindex $fps_separate 3]]"
133puts ""
134puts "Spheres as one interactive object (compound):"
135puts " Actual FPS: [lindex $fps_compound 1]"
136puts " FPS estimate by CPU load: [expr 1000. / [lindex $fps_compound 3]]"
137puts ""
138puts "Animation FPS: $fps_animation"
139puts ""
140puts "Scene contains [lindex [trinfo c] 3] triangles"
141puts ""
142puts "Print 'animateSpheres 10.0' to restart animation"