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