Skip to content

Commit feda79b

Browse files
committed
zombie-gone:4ba33e2 is merged to master
2 parents 8c071cd + 4ba33e2 commit feda79b

File tree

2 files changed

+230
-41
lines changed

2 files changed

+230
-41
lines changed

python/rdesigneur/moogul.py

Lines changed: 145 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ class MooView:
3939
rgb = []
4040
viewList = []
4141
consolidatedTitle = ""
42+
colorbarViewIdx = 0 # Which View does the colorbar serve?
4243

4344
def __init__( self, swx = 10, swy = 10, hideAxis = True, title = "view", colormap = 'jet'
4445
):
@@ -56,7 +57,9 @@ def __init__( self, swx = 10, swy = 10, hideAxis = True, title = "view", colorma
5657
self.colorbar = None
5758
self.valMin = 0.0
5859
self.valMmax = 1.0
60+
self.simTime = 0.0
5961
self.plotFlag_ = True
62+
self.cbox = []
6063

6164
@staticmethod
6265
def replayLoop():
@@ -68,7 +71,12 @@ def replayLoop():
6871
for view in MooView.viewList:
6972
view.replaySnapshot( idx )
7073
vp.sleep( MooView.viewList[0].sleep )
71-
vp.sleep( 0.5 ) # Pause 0.5 sec between replays
74+
t = time.time() + 0.5
75+
while time.time() < t:
76+
for view in MooView.viewList:
77+
view.rotateFunc()
78+
vp.sleep( MooView.viewList[0].sleep )
79+
#vp.sleep( 0.5 ) # Pause 0.5 sec between replays
7280

7381
def notifySimulationEnd( self ):
7482
if self.viewIdx == 0:
@@ -98,7 +106,11 @@ def toggleReplay( self ):
98106
def setSleepTime( self ):
99107
idx = int( round( self.sleepSlider.value ) )
100108
self.sleep = sleepTimes[idx]
101-
self.sleepLabel.text = " Frame dt = {:1.3f} sec".format( self.sleep )
109+
self.sleepLabel.text = "Frame dt = {:1.4f} s".format( self.sleep )
110+
111+
def setRotation( self, slider ):
112+
self.doRotation = ( abs( self.rotation ) > 0.005 )
113+
self.rotation = slider.value
102114

103115
def updateAxis( self ):
104116
if not self.colorbar:
@@ -119,26 +131,87 @@ def updateAxis( self ):
119131
self.zAx.axis = vp.vector( z.dot( right ), z.dot( up ), 0.0 )
120132
self.axisLength.text = "{:.2f} <i>u</i>m".format( dx * 1e6*self.scene.range * self.colorbar.width / self.scene.width )
121133

134+
def raiseMax( self, isDouble = False ):
135+
moov = MooView.viewList[MooView.colorbarViewIdx]
136+
valRange = moov.valMax - moov.valMin
137+
if isDouble:
138+
moov.valMax = moov.valMin + 2 * valRange
139+
else:
140+
moov.valMax = moov.valMin + valRange * 1.1111111111111111111111
141+
return moov.valMax
142+
143+
def lowerMax( self, isDouble = False ):
144+
moov = MooView.viewList[MooView.colorbarViewIdx]
145+
valRange = moov.valMax - moov.valMin
146+
if isDouble:
147+
moov.valMax = moov.valMin + 0.5 * valRange
148+
else:
149+
moov.valMax = moov.valMin + 0.9 * valRange
150+
return moov.valMax
151+
152+
def raiseMin( self, isDouble = False ):
153+
moov = MooView.viewList[MooView.colorbarViewIdx]
154+
valRange = moov.valMax - moov.valMin
155+
if isDouble:
156+
moov.valMin = moov.valMmax - 0.5 * valRange
157+
else:
158+
moov.valMin = moov.valMax - valRange * 0.9
159+
return moov.valMin
160+
161+
def lowerMin( self, isDouble = False ):
162+
moov = MooView.viewList[MooView.colorbarViewIdx]
163+
valRange = moov.valMax - moov.valMin
164+
if isDouble:
165+
moov.valMin = moov.valMax - 2 * valRange
166+
else:
167+
moov.valMin = moov.valMax - valRange * 1.1111111111111111111111
168+
return moov.valMin
169+
170+
def scaleColorbar( self, event ):
171+
loc = event.pos
172+
if loc.y > 6:
173+
idx = MooView.colorbarViewIdx + 1
174+
if idx >= len( MooView.viewList ):
175+
idx = 0
176+
self.selectCbar( idx )
177+
return
178+
if loc.y > 4 and loc.y < 4.7:
179+
ret = self.lowerMax( self.scene.mouse.shift )
180+
self.barMax.text = "{:.3e}".format(ret)
181+
elif loc.y > 4.85 and loc.y < 5.5:
182+
ret = self.raiseMax( self.scene.mouse.shift )
183+
self.barMax.text = "{:.3e}".format(ret)
184+
elif loc.y > -3.25 and loc.y < -2.6:
185+
ret = self.raiseMin( self.scene.mouse.shift )
186+
self.barMin.text = "{:.3e}".format(ret)
187+
elif loc.y > -3.95 and loc.y < -3.45:
188+
ret = self.lowerMin( self.scene.mouse.shift )
189+
self.barMin.text = "{:.3e}".format(ret)
190+
for moov in MooView.viewList:
191+
moov.drawables_[0].updateLimits( moov.valMin, moov.valMax )
192+
122193
def innerColorbar( self, title, bg ):
123194
barWidth = SCALE_SCENE * 1.5
124195
if ( bgLookup(bg).mag < 1 ):
125196
barTextColor = vp.color.white
126197
else:
127198
barTextColor = vp.color.black
128-
self.colorbar = vp.canvas( title = title, width = barWidth, height = self.swy * SCALE_SCENE, background = bgLookup(bg), align = 'left', range = 1, autoscale = False )
129-
#self.colorbar = vp.canvas( title = title, width = barWidth, height = self.swy * SCALE_SCENE, background = vp.color.cyan, align = 'left', range = 1, autoscale = False )
199+
self.colorbar = vp.canvas( title = "Datasets = ", width = barWidth, height = self.swy * SCALE_SCENE, background = bgLookup(bg), align = 'left', range = 1, autoscale = False )
130200
self.colorbar.userzoom = False
131201
self.colorbar.userspin = False
132202
self.colorbar.userpan = False
203+
#self.colorbar.bind( 'keydown', self.scaleColorbar )
204+
self.colorbar.bind( 'click', self.scaleColorbar )
133205
height = 0.10
134206
width = 5
135207
axOrigin = vp.vector( 0, -5.5, 0 )
136208
for idx, rgb in enumerate( self.rgb ):
137209
cbox = vp.box( canvas = self.colorbar, pos = vp.vector( 0, height * (idx - 26), 0), width = width, height = height, color = rgb )
138-
barName = self.title.replace( ' ', '\n' )
210+
barName = self.title.replace( '.', '\n' )
211+
barName = barName.replace( '/', '\n', 1 )
139212
self.barName = vp.label( canvas = self.colorbar, align = 'left', pixel_pos = True, pos = vp.vector( 2, (self.swy - 0.32) * SCALE_SCENE, 0), text = barName, height = 15, color = barTextColor, box = False, opacity = 0 )
140-
self.barMin = vp.label( canvas = self.colorbar, align = 'center', pixel_pos = True, pos = vp.vector( barWidth/2, self.swy * SCALE_SCENE * 0.22, 0), text = "{:.3f}".format(self.valMin), height = 12, color = barTextColor, box = False, opacity = 0 )
141-
self.barMax = vp.label( canvas = self.colorbar, align = 'center', pixel_pos = True, pos = vp.vector( barWidth/2, (self.swy - 1.2) * SCALE_SCENE, 0), text = "{:.3f}".format(self.valMax), height = 12, color = barTextColor, box = False, opacity = 0 )
213+
self.barMin = vp.label( canvas = self.colorbar, align = 'center', pixel_pos = True, pos = vp.vector( barWidth/2, self.swy * SCALE_SCENE * 0.22, 0), text = "{:.3e}".format(self.valMin), height = 12, color = barTextColor, box = False, opacity = 0 )
214+
self.barMax = vp.label( canvas = self.colorbar, align = 'center', pixel_pos = True, pos = vp.vector( barWidth/2, (self.swy - 1.2) * SCALE_SCENE, 0), text = "{:.3e}".format(self.valMax), height = 12, color = barTextColor, box = False, opacity = 0 )
142215
self.xAx = vp.cylinder( canvas = self.colorbar, pos = axOrigin, axis = vp.vector( 0.8, 0, 0 ), radius = 0.04, color = vp.color.red )
143216
self.yAx = vp.cylinder( canvas = self.colorbar, pos = axOrigin, axis = vp.vector( 0, 0.8, 0 ), radius = 0.04, color = vp.color.green )
144217
self.zAx = vp.cylinder( canvas = self.colorbar, pos = axOrigin, axis = vp.vector( 0, 0, 0 ), radius = 0.04, color = vp.color.blue )
@@ -150,12 +223,34 @@ def makeColorbar( self, doOrnaments = True, colorscale = 'jet', bg = 'default' )
150223
title = MooView.consolidatedTitle + "\n"
151224
self.innerColorbar( title, bg )
152225
if doOrnaments:
153-
self.timeLabel = vp.wtext( text = "Time = 0.000 sec", pos = self.colorbar.title_anchor )
154-
self.sleepLabel = vp.wtext( text = " Frame dt = 0.005 sec", pos = self.colorbar.title_anchor )
226+
for idx, mv in enumerate( MooView.viewList ):
227+
chk = vp.checkbox( bind = mv.toggleView, checked = True, text = mv.title + " ", pos = self.colorbar.title_anchor )
228+
chk.idx = idx
229+
self.cbox.append( chk )
230+
self.colorbar.append_to_title("\n")
231+
self.timeLabel = vp.wtext( text = "Time = 0.000 s\n", pos = self.colorbar.title_anchor )
232+
self.sleepLabel = vp.wtext( text = "Frame dt = 0.0050 s", pos = self.colorbar.title_anchor )
155233
self.sleepSlider = vp.slider( pos = self.colorbar.title_anchor, length = 200, bind = self.setSleepTime, min = 0, max = len( sleepTimes ) -1, value = min( len( sleepTimes ), 2 ) )
156234
self.replayButton = vp.button( text = "Start Replay", pos = self.colorbar.title_anchor, bind=self.toggleReplay, disabled = True )
235+
self.rotateLabel = vp.wtext( text = " Rotation", pos = self.colorbar.title_anchor )
236+
self.rotateSlider = vp.slider( pos = self.colorbar.title_anchor, length = 200, bind=self.setRotation, min = -0.1, max = 0.1, value = 0.0 )
157237
self.colorbar.append_to_title("\n")
158238

239+
def selectCbar( self, idx ):
240+
MooView.colorbarViewIdx = idx
241+
moov = MooView.viewList[idx]
242+
view0 = MooView.viewList[0]
243+
view0.barName.text = view0.cbox[idx].text.replace( '.', '\n' )
244+
view0.barName.text = view0.barName.text.replace( '/', '\n', 1 )
245+
view0.barMin.text = "{:.3e}".format(moov.valMin)
246+
view0.barMax.text = "{:.3e}".format(moov.valMax)
247+
248+
def toggleView( self, cbox ):
249+
for d in self.drawables_:
250+
d.setVisible( cbox.checked )
251+
if cbox.checked: # The colorbar is assigned to selected view:
252+
self.selectCbar( cbox.idx )
253+
159254
def pickObj( self ):
160255
obj = self.scene.mouse.pick
161256
if obj == None:
@@ -236,27 +331,29 @@ def firstDraw( self, mergeDisplays, rotation=0.0, elev=0.0, azim=0.0, center = [
236331
self.doAutoscale()
237332
self.updateAxis()
238333
if self.viewIdx == (MooView.viewIdx-1):
239-
self.graph = vp.graph( title = "Graph", xtitle = "Time (s)", ytitle = " Units here", width = 700, fast=False, align = "left" )
240-
self.graphPlot1 = vp.gcurve( color = vp.color.blue, interval=-1)
241-
#self.graphPlot1.data = [[0,0], [1,1],[2,0],[3,4],[4,0], [5,1]]
242-
#self.graphPlot1.plot( [[0,0], [1,1],[2,0],[3,4],[4,0]] )
334+
MooView.viewList[0].graph = vp.graph( title = "Graph", xtitle = "Time (s)", ytitle = " Units here", width = 700, fast=False, align = "left" )
335+
MooView.viewList[0].graphPlot1 = vp.gcurve( color = vp.color.blue, interval=-1)
243336

337+
def rotateFunc(self ):
338+
if self.doRotation and abs( self.rotation ) < 2.0 * 3.14 / 3.0:
339+
self.scene.forward = vp.rotate( self.scene.forward, angle = self.rotation, axis = self.scene.up )
340+
self.updateAxis()
244341

245342
def updateValues( self, simTime ):
343+
self.simTime = simTime
246344
for i in self.drawables_:
247345
i.updateValues( simTime )
248-
if self.doRotation and abs( self.rotation ) < 2.0 * 3.14 / 3.0:
249-
self.scene.forward = vp.rotate( self.scene.forward, angle = self.rotation, axis = self.scene.up )
250-
self.updateAxis()
346+
self.rotateFunc()
251347
if self.viewIdx == 0:
252-
self.timeLabel.text = "Time = {:7.3f} sec".format( simTime )
348+
self.timeLabel.text = "Time = {:7.3f} s\n".format( simTime )
253349
vp.sleep( self.sleep )
254350

255351
def replaySnapshot( self, idx ):
256352
for i in self.drawables_:
257353
simTime = i.replaySnapshot( idx )
354+
self.rotateFunc()
258355
if self.viewIdx == 0:
259-
self.timeLabel.text = "Time = {:7.3f} sec".format( simTime )
356+
self.timeLabel.text = "Time = {:7.3f} s\n".format( simTime )
260357
self.updateAxis()
261358

262359
def doAutoscale( self ):
@@ -320,13 +417,15 @@ def moveView(self, event):
320417
self.scene.camera.rotate( angle = -dtheta, axis = camAxis, origin = self.scene.camera.pos )
321418
return
322419
if event.key == "d": # Diameter scaling down
323-
for dbl in self.drawables_:
324-
dbl.diaScale *= 1.0 - self.sensitivity * 4
420+
moov = MooView.viewList[MooView.colorbarViewIdx]
421+
for dbl in moov.drawables_:
422+
dbl.diaScale *= 1.0 - moov.sensitivity * 4
325423
dbl.updateDiameter()
326424
return
327425
if event.key == "D":
328-
for dbl in self.drawables_:
329-
dbl.diaScale *= 1.0 + self.sensitivity * 4
426+
moov = MooView.viewList[MooView.colorbarViewIdx]
427+
for dbl in moov.drawables_:
428+
dbl.diaScale *= 1.0 + moov.sensitivity * 4
330429
dbl.updateDiameter()
331430
return
332431
if event.key == "s": # Scale down sleep time, make it faster.
@@ -430,6 +529,7 @@ def __init__( self,
430529
self.valMax = valMax
431530
self.segments = []
432531
self.snapshot = []
532+
self.visible = True
433533
#cmap = plt.get_cmap( self.colormap, lut = NUM_CMAP )
434534
#self.rgb = [ list2vec(cmap(i)[0:3]) for i in range( NUM_CMAP ) ]
435535

@@ -450,10 +550,22 @@ def updateValues( self, simTime ):
450550
indices = np.maximum( np.minimum( scaleVal, NUM_CMAP-0.5), 0.0).astype(int)
451551

452552
# Have to figure how this will work with multiple update rates.
453-
self.snapshot.append( [simTime, indices] )
553+
self.snapshot.append( [simTime, self.val] )
554+
555+
self.displayValues( indices )
454556

557+
def updateLimits( self, vmin, vmax ):
558+
if self.autoscale:
559+
valMin = min( self.val )
560+
valMax = max( self.val )
561+
else:
562+
valMin = self.valMin = vmin
563+
valMax = self.valMax = vmax
564+
scaleVal = NUM_CMAP * (self.val - valMin) / (valMax - valMin)
565+
indices = np.maximum( np.minimum( scaleVal, NUM_CMAP-0.5), 0.0).astype(int)
455566
self.displayValues( indices )
456567

568+
457569
def displayValues( self, indices ):
458570
for idx, seg in zip( indices, self.segments ):
459571
seg.color = self.rgb[ idx]
@@ -462,7 +574,9 @@ def displayValues( self, indices ):
462574
def replaySnapshot( self, idx ):
463575
if idx >= len( self.snapshot ):
464576
return 0.0
465-
self.displayValues( self.snapshot[idx][1] )
577+
scaleVal = NUM_CMAP * (self.snapshot[idx][1] - self.valMin) / (self.valMax - self.valMin)
578+
indices = np.maximum( np.minimum( scaleVal, NUM_CMAP-0.5), 0.0).astype(int)
579+
self.displayValues( indices )
466580
return self.snapshot[idx][0] # return frame time
467581

468582
def updateDiameter( self ):
@@ -495,20 +609,13 @@ def plotHistory( self, path, field, graph, plot ):
495609
graph.title = path + "." + field
496610
dat = [[x,y] for x, y in zip( t, v ) ]
497611
plot.data = dat
498-
#print (dat)
499-
#print( "IN plotHistory, ", len( dat), len( v ) )
500-
#plot.data = [[x,y] for x, y in zip( t, v ) ]
501-
#plot.data = [[x,sin(x)] for x in range( 0.0, 10.0, 0.1 ) ]
502-
'''
503-
fig = plt.figure( 1 )
504-
plt.ion()
505-
plt.title( path + "." + field )
506-
plt.xlabel( "Time (s)" )
507-
plt.ylabel( field + " um, units?" )
508-
plt.plot( t, v )
509-
plt.show( block = False )
510-
fig.canvas.draw()
511-
'''
612+
613+
def setVisible( self, state ):
614+
if self.visible == state:
615+
return
616+
self.visible = state
617+
for s in self.segments:
618+
s.visible = state
512619

513620

514621
#####################################################################

0 commit comments

Comments
 (0)