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