1 # test performance of display of heavy scene involving multiple interactive
2 # objects, on example of 1000 spheres
4 #Category: Visualization
5 #Title: Display of complex scene and animation
10 vinit View1 w=1024 h=1024
12 vdefaults -autoTriang 0
13 vrenderparams -stats basic
15 # parameter NB defines number of spheres by each coordinate
17 puts "Creating [expr $NB * $NB * $NB] spheres..."
19 for {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} {
24 ttranslate s$i$j$k 3.*$i 3.*$j 3.*$k
28 eval compound $slist c
31 puts "Measuring FPS of display of spheres as separate objects..."
33 eval vdisplay -dispMode 1 $slist
37 puts [set fps_separate [vfps]]
40 puts "Measuring FPS of display of spheres as single object..."
41 vdisplay -dispMode 1 c
44 puts [set fps_compound [vfps]]
47 # redisplay individual spheres, trying to avoid unnecessary internal updates
48 eval vdisplay -dispMode 1 $slist
50 # auxiliary procedure to make random update of variable
51 proc upd {theValueName theDeltaName theTime theToRand} {
52 upvar $theValueName aValue
53 upvar $theDeltaName aDelta
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)]
62 set aRes [expr $aValue + $aDelta * $theTime / 100.0]
65 # move corner spheres in cycle
66 proc animateSpheres {{theDuration 10.0}} {
67 set nb [expr $::NB - 1]
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} {
73 # mark animated spheres mutable for faster updates
74 uplevel #0 vdisplay -dispMode 1 -mutable s$i$j$k
75 # vaspects -noupdate s$i$j$k -setcolor red -setmaterial plastic
76 uplevel #0 vaspects -noupdate s$i$j$k -setcolor red
89 set aTimeFrom [clock clicks -milliseconds]
90 uplevel #0 chrono anAnimTimer reset
91 uplevel #0 chrono anAnimTimer start
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) ]
100 uplevel #0 chrono anAnimTimer stop
101 uplevel #0 chrono anAnimTimer show
105 set aRandTime [expr $aCurrTime - $aPrevRand]
106 if { $aRandTime > 1000 } {
108 set aPrevRand $aCurrTime
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]
120 set aDuration [expr [clock clicks -milliseconds] - $aTimeFrom]
123 # sleep 1 ms allowing the user to interact with the viewer
129 puts "Animating movements of corner spheres (10 sec)..."
130 puts "(you can interact with the view during the process)"
131 set fps_animation [animateSpheres 10.0]
134 puts "Performance counters (FPS = \"Frames per second\"):"
136 puts "Spheres as separate interactive objects:"
137 puts " Actual FPS: [lindex $fps_separate 1]"
138 puts " FPS estimate by CPU load: [expr 1000. / [lindex $fps_separate 3]]"
140 puts "Spheres as one interactive object (compound):"
141 puts " Actual FPS: [lindex $fps_compound 1]"
142 puts " FPS estimate by CPU load: [expr 1000. / [lindex $fps_compound 3]]"
144 puts "Animation FPS: $fps_animation"
146 puts "Scene contains [lindex [trinfo c] 3] triangles"
148 puts "Print 'animateSpheres 10.0' to restart animation"