Skip to content

Commit

Permalink
zombie-gone:4ba33e2 is merged to master
Browse files Browse the repository at this point in the history
  • Loading branch information
hrani committed Apr 11, 2022
2 parents 8c071cd + 4ba33e2 commit feda79b
Show file tree
Hide file tree
Showing 2 changed files with 230 additions and 41 deletions.
183 changes: 145 additions & 38 deletions python/rdesigneur/moogul.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ class MooView:
rgb = []
viewList = []
consolidatedTitle = ""
colorbarViewIdx = 0 # Which View does the colorbar serve?

def __init__( self, swx = 10, swy = 10, hideAxis = True, title = "view", colormap = 'jet'
):
Expand All @@ -56,7 +57,9 @@ def __init__( self, swx = 10, swy = 10, hideAxis = True, title = "view", colorma
self.colorbar = None
self.valMin = 0.0
self.valMmax = 1.0
self.simTime = 0.0
self.plotFlag_ = True
self.cbox = []

@staticmethod
def replayLoop():
Expand All @@ -68,7 +71,12 @@ def replayLoop():
for view in MooView.viewList:
view.replaySnapshot( idx )
vp.sleep( MooView.viewList[0].sleep )
vp.sleep( 0.5 ) # Pause 0.5 sec between replays
t = time.time() + 0.5
while time.time() < t:
for view in MooView.viewList:
view.rotateFunc()
vp.sleep( MooView.viewList[0].sleep )
#vp.sleep( 0.5 ) # Pause 0.5 sec between replays

def notifySimulationEnd( self ):
if self.viewIdx == 0:
Expand Down Expand Up @@ -98,7 +106,11 @@ def toggleReplay( self ):
def setSleepTime( self ):
idx = int( round( self.sleepSlider.value ) )
self.sleep = sleepTimes[idx]
self.sleepLabel.text = " Frame dt = {:1.3f} sec".format( self.sleep )
self.sleepLabel.text = "Frame dt = {:1.4f} s".format( self.sleep )

def setRotation( self, slider ):
self.doRotation = ( abs( self.rotation ) > 0.005 )
self.rotation = slider.value

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

def raiseMax( self, isDouble = False ):
moov = MooView.viewList[MooView.colorbarViewIdx]
valRange = moov.valMax - moov.valMin
if isDouble:
moov.valMax = moov.valMin + 2 * valRange
else:
moov.valMax = moov.valMin + valRange * 1.1111111111111111111111
return moov.valMax

def lowerMax( self, isDouble = False ):
moov = MooView.viewList[MooView.colorbarViewIdx]
valRange = moov.valMax - moov.valMin
if isDouble:
moov.valMax = moov.valMin + 0.5 * valRange
else:
moov.valMax = moov.valMin + 0.9 * valRange
return moov.valMax

def raiseMin( self, isDouble = False ):
moov = MooView.viewList[MooView.colorbarViewIdx]
valRange = moov.valMax - moov.valMin
if isDouble:
moov.valMin = moov.valMmax - 0.5 * valRange
else:
moov.valMin = moov.valMax - valRange * 0.9
return moov.valMin

def lowerMin( self, isDouble = False ):
moov = MooView.viewList[MooView.colorbarViewIdx]
valRange = moov.valMax - moov.valMin
if isDouble:
moov.valMin = moov.valMax - 2 * valRange
else:
moov.valMin = moov.valMax - valRange * 1.1111111111111111111111
return moov.valMin

def scaleColorbar( self, event ):
loc = event.pos
if loc.y > 6:
idx = MooView.colorbarViewIdx + 1
if idx >= len( MooView.viewList ):
idx = 0
self.selectCbar( idx )
return
if loc.y > 4 and loc.y < 4.7:
ret = self.lowerMax( self.scene.mouse.shift )
self.barMax.text = "{:.3e}".format(ret)
elif loc.y > 4.85 and loc.y < 5.5:
ret = self.raiseMax( self.scene.mouse.shift )
self.barMax.text = "{:.3e}".format(ret)
elif loc.y > -3.25 and loc.y < -2.6:
ret = self.raiseMin( self.scene.mouse.shift )
self.barMin.text = "{:.3e}".format(ret)
elif loc.y > -3.95 and loc.y < -3.45:
ret = self.lowerMin( self.scene.mouse.shift )
self.barMin.text = "{:.3e}".format(ret)
for moov in MooView.viewList:
moov.drawables_[0].updateLimits( moov.valMin, moov.valMax )

def innerColorbar( self, title, bg ):
barWidth = SCALE_SCENE * 1.5
if ( bgLookup(bg).mag < 1 ):
barTextColor = vp.color.white
else:
barTextColor = vp.color.black
self.colorbar = vp.canvas( title = title, width = barWidth, height = self.swy * SCALE_SCENE, background = bgLookup(bg), align = 'left', range = 1, autoscale = False )
#self.colorbar = vp.canvas( title = title, width = barWidth, height = self.swy * SCALE_SCENE, background = vp.color.cyan, align = 'left', range = 1, autoscale = False )
self.colorbar = vp.canvas( title = "Datasets = ", width = barWidth, height = self.swy * SCALE_SCENE, background = bgLookup(bg), align = 'left', range = 1, autoscale = False )
self.colorbar.userzoom = False
self.colorbar.userspin = False
self.colorbar.userpan = False
#self.colorbar.bind( 'keydown', self.scaleColorbar )
self.colorbar.bind( 'click', self.scaleColorbar )
height = 0.10
width = 5
axOrigin = vp.vector( 0, -5.5, 0 )
for idx, rgb in enumerate( self.rgb ):
cbox = vp.box( canvas = self.colorbar, pos = vp.vector( 0, height * (idx - 26), 0), width = width, height = height, color = rgb )
barName = self.title.replace( ' ', '\n' )
barName = self.title.replace( '.', '\n' )
barName = barName.replace( '/', '\n', 1 )
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 )
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 )
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 )
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 )
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 )
self.xAx = vp.cylinder( canvas = self.colorbar, pos = axOrigin, axis = vp.vector( 0.8, 0, 0 ), radius = 0.04, color = vp.color.red )
self.yAx = vp.cylinder( canvas = self.colorbar, pos = axOrigin, axis = vp.vector( 0, 0.8, 0 ), radius = 0.04, color = vp.color.green )
self.zAx = vp.cylinder( canvas = self.colorbar, pos = axOrigin, axis = vp.vector( 0, 0, 0 ), radius = 0.04, color = vp.color.blue )
Expand All @@ -150,12 +223,34 @@ def makeColorbar( self, doOrnaments = True, colorscale = 'jet', bg = 'default' )
title = MooView.consolidatedTitle + "\n"
self.innerColorbar( title, bg )
if doOrnaments:
self.timeLabel = vp.wtext( text = "Time = 0.000 sec", pos = self.colorbar.title_anchor )
self.sleepLabel = vp.wtext( text = " Frame dt = 0.005 sec", pos = self.colorbar.title_anchor )
for idx, mv in enumerate( MooView.viewList ):
chk = vp.checkbox( bind = mv.toggleView, checked = True, text = mv.title + " ", pos = self.colorbar.title_anchor )
chk.idx = idx
self.cbox.append( chk )
self.colorbar.append_to_title("\n")
self.timeLabel = vp.wtext( text = "Time = 0.000 s\n", pos = self.colorbar.title_anchor )
self.sleepLabel = vp.wtext( text = "Frame dt = 0.0050 s", pos = self.colorbar.title_anchor )
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 ) )
self.replayButton = vp.button( text = "Start Replay", pos = self.colorbar.title_anchor, bind=self.toggleReplay, disabled = True )
self.rotateLabel = vp.wtext( text = " Rotation", pos = self.colorbar.title_anchor )
self.rotateSlider = vp.slider( pos = self.colorbar.title_anchor, length = 200, bind=self.setRotation, min = -0.1, max = 0.1, value = 0.0 )
self.colorbar.append_to_title("\n")

def selectCbar( self, idx ):
MooView.colorbarViewIdx = idx
moov = MooView.viewList[idx]
view0 = MooView.viewList[0]
view0.barName.text = view0.cbox[idx].text.replace( '.', '\n' )
view0.barName.text = view0.barName.text.replace( '/', '\n', 1 )
view0.barMin.text = "{:.3e}".format(moov.valMin)
view0.barMax.text = "{:.3e}".format(moov.valMax)

def toggleView( self, cbox ):
for d in self.drawables_:
d.setVisible( cbox.checked )
if cbox.checked: # The colorbar is assigned to selected view:
self.selectCbar( cbox.idx )

def pickObj( self ):
obj = self.scene.mouse.pick
if obj == None:
Expand Down Expand Up @@ -236,27 +331,29 @@ def firstDraw( self, mergeDisplays, rotation=0.0, elev=0.0, azim=0.0, center = [
self.doAutoscale()
self.updateAxis()
if self.viewIdx == (MooView.viewIdx-1):
self.graph = vp.graph( title = "Graph", xtitle = "Time (s)", ytitle = " Units here", width = 700, fast=False, align = "left" )
self.graphPlot1 = vp.gcurve( color = vp.color.blue, interval=-1)
#self.graphPlot1.data = [[0,0], [1,1],[2,0],[3,4],[4,0], [5,1]]
#self.graphPlot1.plot( [[0,0], [1,1],[2,0],[3,4],[4,0]] )
MooView.viewList[0].graph = vp.graph( title = "Graph", xtitle = "Time (s)", ytitle = " Units here", width = 700, fast=False, align = "left" )
MooView.viewList[0].graphPlot1 = vp.gcurve( color = vp.color.blue, interval=-1)

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

def updateValues( self, simTime ):
self.simTime = simTime
for i in self.drawables_:
i.updateValues( simTime )
if self.doRotation and abs( self.rotation ) < 2.0 * 3.14 / 3.0:
self.scene.forward = vp.rotate( self.scene.forward, angle = self.rotation, axis = self.scene.up )
self.updateAxis()
self.rotateFunc()
if self.viewIdx == 0:
self.timeLabel.text = "Time = {:7.3f} sec".format( simTime )
self.timeLabel.text = "Time = {:7.3f} s\n".format( simTime )
vp.sleep( self.sleep )

def replaySnapshot( self, idx ):
for i in self.drawables_:
simTime = i.replaySnapshot( idx )
self.rotateFunc()
if self.viewIdx == 0:
self.timeLabel.text = "Time = {:7.3f} sec".format( simTime )
self.timeLabel.text = "Time = {:7.3f} s\n".format( simTime )
self.updateAxis()

def doAutoscale( self ):
Expand Down Expand Up @@ -320,13 +417,15 @@ def moveView(self, event):
self.scene.camera.rotate( angle = -dtheta, axis = camAxis, origin = self.scene.camera.pos )
return
if event.key == "d": # Diameter scaling down
for dbl in self.drawables_:
dbl.diaScale *= 1.0 - self.sensitivity * 4
moov = MooView.viewList[MooView.colorbarViewIdx]
for dbl in moov.drawables_:
dbl.diaScale *= 1.0 - moov.sensitivity * 4
dbl.updateDiameter()
return
if event.key == "D":
for dbl in self.drawables_:
dbl.diaScale *= 1.0 + self.sensitivity * 4
moov = MooView.viewList[MooView.colorbarViewIdx]
for dbl in moov.drawables_:
dbl.diaScale *= 1.0 + moov.sensitivity * 4
dbl.updateDiameter()
return
if event.key == "s": # Scale down sleep time, make it faster.
Expand Down Expand Up @@ -430,6 +529,7 @@ def __init__( self,
self.valMax = valMax
self.segments = []
self.snapshot = []
self.visible = True
#cmap = plt.get_cmap( self.colormap, lut = NUM_CMAP )
#self.rgb = [ list2vec(cmap(i)[0:3]) for i in range( NUM_CMAP ) ]

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

# Have to figure how this will work with multiple update rates.
self.snapshot.append( [simTime, indices] )
self.snapshot.append( [simTime, self.val] )

self.displayValues( indices )

def updateLimits( self, vmin, vmax ):
if self.autoscale:
valMin = min( self.val )
valMax = max( self.val )
else:
valMin = self.valMin = vmin
valMax = self.valMax = vmax
scaleVal = NUM_CMAP * (self.val - valMin) / (valMax - valMin)
indices = np.maximum( np.minimum( scaleVal, NUM_CMAP-0.5), 0.0).astype(int)
self.displayValues( indices )


def displayValues( self, indices ):
for idx, seg in zip( indices, self.segments ):
seg.color = self.rgb[ idx]
Expand All @@ -462,7 +574,9 @@ def displayValues( self, indices ):
def replaySnapshot( self, idx ):
if idx >= len( self.snapshot ):
return 0.0
self.displayValues( self.snapshot[idx][1] )
scaleVal = NUM_CMAP * (self.snapshot[idx][1] - self.valMin) / (self.valMax - self.valMin)
indices = np.maximum( np.minimum( scaleVal, NUM_CMAP-0.5), 0.0).astype(int)
self.displayValues( indices )
return self.snapshot[idx][0] # return frame time

def updateDiameter( self ):
Expand Down Expand Up @@ -495,20 +609,13 @@ def plotHistory( self, path, field, graph, plot ):
graph.title = path + "." + field
dat = [[x,y] for x, y in zip( t, v ) ]
plot.data = dat
#print (dat)
#print( "IN plotHistory, ", len( dat), len( v ) )
#plot.data = [[x,y] for x, y in zip( t, v ) ]
#plot.data = [[x,sin(x)] for x in range( 0.0, 10.0, 0.1 ) ]
'''
fig = plt.figure( 1 )
plt.ion()
plt.title( path + "." + field )
plt.xlabel( "Time (s)" )
plt.ylabel( field + " um, units?" )
plt.plot( t, v )
plt.show( block = False )
fig.canvas.draw()
'''

def setVisible( self, state ):
if self.visible == state:
return
self.visible = state
for s in self.segments:
s.visible = state


#####################################################################
Expand Down
Loading

0 comments on commit feda79b

Please sign in to comment.