本文整理汇总了Python中volumina.layerstack.LayerStackModel.append方法的典型用法代码示例。如果您正苦于以下问题:Python LayerStackModel.append方法的具体用法?Python LayerStackModel.append怎么用?Python LayerStackModel.append使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类volumina.layerstack.LayerStackModel
的用法示例。
在下文中一共展示了LayerStackModel.append方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: createWidget
# 需要导入模块: from volumina.layerstack import LayerStackModel [as 别名]
# 或者: from volumina.layerstack.LayerStackModel import append [as 别名]
def createWidget(self, parent):
model = LayerStackModel()
o1 = Layer()
o1.name = "Fancy Layer"
o1.opacity = 0.5
model.append(o1)
o2 = Layer()
o2.name = "Some other Layer"
o2.opacity = 0.25
model.append(o2)
o3 = Layer()
o3.name = "Invisible Layer"
o3.opacity = 0.15
o3.visible = False
model.append(o3)
o4 = Layer()
o4.name = "Fancy Layer II"
o4.opacity = 0.95
model.append(o4)
o5 = Layer()
o5.name = "Fancy Layer III"
o5.opacity = 0.65
model.append(o5)
view = LayerWidget(parent, model)
view.updateGeometry()
return view
示例2: testNonEmptyLayerStackModel
# 需要导入模块: from volumina.layerstack import LayerStackModel [as 别名]
# 或者: from volumina.layerstack.LayerStackModel import append [as 别名]
def testNonEmptyLayerStackModel( self ):
lsm = LayerStackModel()
lsm.append(self.layer1)
lsm.append(self.layer2)
lsm.append(self.layer3)
ip = ImagePump( lsm, SliceProjection() )
self.assertEqual( len(lsm), 3 )
self.assertEqual( len(ip.stackedImageSources), 3 )
self.assertEqual( len(ip.syncedSliceSources), 3 )
self.assertEqual( len(ip.stackedImageSources.getRegisteredLayers()), 3 )
for layer in lsm:
self.assertTrue( ip.stackedImageSources.isRegistered(layer) )
lsm.deleteSelected()
self.assertEqual( len(lsm), 2 )
self.assertEqual( len(ip.stackedImageSources), 2 )
self.assertEqual( len(ip.syncedSliceSources), 2 )
self.assertEqual( len(ip.stackedImageSources.getRegisteredLayers()), 2 )
for layer in lsm:
self.assertTrue( ip.stackedImageSources.isRegistered(layer) )
lsm.clear()
self.assertEqual( len(lsm), 0 )
self.assertEqual( len(ip.stackedImageSources), 0 )
self.assertEqual( len(ip.syncedSliceSources), 0 )
self.assertEqual( len(ip.stackedImageSources.getRegisteredLayers()), 0 )
示例3: testAddingAndRemoving
# 需要导入模块: from volumina.layerstack import LayerStackModel [as 别名]
# 或者: from volumina.layerstack.LayerStackModel import append [as 别名]
def testAddingAndRemoving( self ):
lsm = LayerStackModel()
self.assertEqual(len(lsm), 0)
lsm.append(self.l1)
self.assertEqual(len(lsm), 1)
self.assertEqual(lsm[0].name, self.l1.name )
lsm.append(self.l2)
self.assertEqual(len(lsm), 2)
self.assertEqual(lsm[0].name, self.l2.name )
self.assertEqual(lsm[1].name, self.l1.name )
lsm.insert(1, self.l3)
self.assertEqual(len(lsm), 3)
self.assertEqual(lsm[0].name, self.l2.name )
self.assertEqual(lsm[1].name, self.l3.name )
self.assertEqual(lsm[2].name, self.l1.name )
lsm.selectRow( 0 )
lsm.deleteSelected()
self.assertEqual(len(lsm), 2)
self.assertEqual(lsm[0].name, self.l3.name )
self.assertEqual(lsm[1].name, self.l1.name )
lsm.clear()
self.assertEqual(len(lsm), 0)
示例4: ImageScene2D_LazyTest
# 需要导入模块: from volumina.layerstack import LayerStackModel [as 别名]
# 或者: from volumina.layerstack.LayerStackModel import append [as 别名]
class ImageScene2D_LazyTest(ut.TestCase):
def setUp(self):
self.layerstack = LayerStackModel()
self.sims = StackedImageSources(self.layerstack)
self.g = Graph()
self.op = OpLazy(self.g)
self.ds = LazyflowSource(self.op.Output)
self.ss = SliceSource(self.ds, projectionAlongTZC)
self.layer = GrayscaleLayer(self.ds, normalize=False)
self.layerstack.append(self.layer)
self.ims = imsfac.createImageSource(self.layer, [self.ss])
self.sims.register(self.layer, self.ims)
self.scene = ImageScene2D(PositionModel(), (0, 0, 0), preemptive_fetch_number=0)
self.scene.setCacheSize(1)
self.scene.stackedImageSources = self.sims
self.scene.dataShape = (30, 30)
def renderScene(self, s, exportFilename=None, joinRendering=True):
img = QImage(30, 30, QImage.Format_ARGB32_Premultiplied)
img.fill(Qt.white)
p = QPainter(img)
s.render(p) # trigger a rendering of the whole scene
if joinRendering:
# wait for all the data to arrive
s.joinRenderingAllTiles(viewport_only=False) # There is no viewport!
# finally, render everything
s.render(p)
p.end()
if exportFilename is not None:
img.save(exportFilename)
return byte_view(img)
def testLazy(self):
for i in range(3):
self.op.setConstant(i)
aimg = self.renderScene(self.scene, "/tmp/a_%03d.png" % i)
assert numpy.all(aimg[:, :, 0] == i), "!= %d, [0,0,0]=%d" % (i, aimg[0, 0, 0])
self.op.setConstant(42)
self.op.setDelay(1)
aimg = self.renderScene(self.scene, joinRendering=False, exportFilename="/tmp/x_%03d.png" % i)
# this should be "i", not 255 (the default background for the imagescene)
assert numpy.all(aimg[:, :, 0] == i), "!= %d, [0,0,0]=%d" % (i, aimg[0, 0, 0])
# Now give the scene time to update before we change it again...
self.scene.joinRenderingAllTiles(viewport_only=False)
示例5: testAddingAndRemovingLayers
# 需要导入模块: from volumina.layerstack import LayerStackModel [as 别名]
# 或者: from volumina.layerstack.LayerStackModel import append [as 别名]
def testAddingAndRemovingLayers( self ):
lsm = LayerStackModel()
sims = StackedImageSources( lsm )
ims_view = sims.viewImageSources()
self.assertEqual(len(lsm), 0)
self.assertEqual(len(sims), 0)
self.assertEqual(len(ims_view), 0)
lsm.append(self.layer1)
lsm.append(self.layer2)
sims.register(self.layer1, self.ims1)
sims.register(self.layer2, self.ims2)
self.assertEqual(sims.isRegistered(self.layer1), True)
self.assertEqual(sims.isRegistered(self.layer2), True)
self.assertEqual(len(lsm), 2)
self.assertEqual(len(sims), 2)
self.assertEqual(len(ims_view), 2)
self.assertEqual(ims_view[0], self.ims2)
self.assertEqual(ims_view[1], self.ims1)
lsm.append(self.layer3)
self.assertEqual(len(lsm), 3)
self.assertEqual(len(sims), 2)
self.assertEqual(len(ims_view), 2)
self.assertEqual(ims_view[0], self.ims2)
self.assertEqual(ims_view[1], self.ims1)
self.assertEqual(sims.isRegistered(self.layer1), True)
self.assertEqual(sims.isRegistered(self.layer2), True)
lsm.selectRow(1) # layer2
lsm.deleteSelected()
self.assertEqual(len(lsm), 2)
self.assertEqual(len(sims), 1)
self.assertEqual(len(ims_view), 1)
self.assertEqual(ims_view[0], self.ims1)
self.assertEqual(sims.isRegistered(self.layer1), True)
self.assertEqual(sims.isRegistered(self.layer2), False)
lsm.selectRow(0) # layer3
lsm.deleteSelected()
self.assertEqual(len(lsm), 1)
self.assertEqual(len(sims), 1)
self.assertEqual(len(ims_view), 1)
self.assertEqual(ims_view[0], self.ims1)
self.assertEqual(sims.isRegistered(self.layer1), True)
self.assertEqual(sims.isRegistered(self.layer2), False)
sims.deregister(self.layer1)
self.assertEqual(len(lsm), 1)
self.assertEqual(len(sims), 0)
self.assertEqual(len(ims_view), 0)
self.assertEqual(sims.isRegistered(self.layer1), False)
self.assertEqual(sims.isRegistered(self.layer2), False)
示例6: testRegisterAndDeregister
# 需要导入模块: from volumina.layerstack import LayerStackModel [as 别名]
# 或者: from volumina.layerstack.LayerStackModel import append [as 别名]
def testRegisterAndDeregister( self ):
lsm = LayerStackModel()
sims = StackedImageSources( lsm )
self.assertEqual( len(lsm), 0 )
self.assertEqual( len(sims), 0 )
lsm.append(self.layer1)
lsm.append(self.layer2)
lsm.append(self.layer3)
self.assertEqual( lsm.layerIndex(self.layer1), 2 )
self.assertEqual( lsm.layerIndex(self.layer2), 1 )
self.assertEqual( lsm.layerIndex(self.layer3), 0 )
self.assertEqual( len(lsm), 3 )
self.assertEqual( len(sims), 0 )
self.assertFalse(sims.isRegistered(self.layer2))
sims.register( self.layer2, self.ims2 )
self.assertTrue(sims.isRegistered(self.layer2))
self.assertEqual( len(sims), 1 )
self.assertEqual( sims.getImageSource(0), self.ims2 )
sims.register( self.layer1, self.ims1 )
sims.register( self.layer3, self.ims3 )
sims.deregister( self.layer2 )
self.assertTrue( sims.isRegistered( self.layer1 ))
self.assertFalse( sims.isRegistered( self.layer2 ))
self.assertTrue( sims.isRegistered( self.layer3 ))
self.assertEqual( len(lsm), 3 )
self.assertEqual( len(sims), 2 )
self.assertEqual( sims.getImageSource(0), self.ims3 )
self.assertEqual( sims.getImageSource(1), self.ims1 )
for i,v in enumerate(sims):
if i == 0:
self.assertEqual(len(v), 3)
self.assertEqual(v[0], self.layer3.visible)
self.assertEqual(v[1], self.layer3.opacity)
self.assertEqual(v[2], self.ims3)
elif i == 1:
self.assertEqual(len(v), 3)
self.assertEqual(v[0], self.layer1.visible)
self.assertEqual(v[1], self.layer1.opacity)
self.assertEqual(v[2], self.ims1)
else:
raise Exception("unexpected index")
sims.deregister( self.layer1 )
sims.deregister( self.layer3 )
self.assertEqual( len(lsm), 3 )
self.assertEqual( len(sims), 0 )
lsm.clear()
示例7: createWidget
# 需要导入模块: from volumina.layerstack import LayerStackModel [as 别名]
# 或者: from volumina.layerstack.LayerStackModel import append [as 别名]
def createWidget(self, parent):
a = (numpy.random.random((1,100,200,300,1))*255).astype(numpy.uint8)
source = ArraySource(a)
layerstack = LayerStackModel()
layerstack.append( GrayscaleLayer( source ) )
editor = VolumeEditor(layerstack, labelsink=None, parent=self)
widget = VolumeEditorWidget(parent=parent)
if not _has_lazyflow:
widget.setEnabled(False)
widget.init(editor)
editor.dataShape = a.shape
return widget
示例8: testMovingLayers
# 需要导入模块: from volumina.layerstack import LayerStackModel [as 别名]
# 或者: from volumina.layerstack.LayerStackModel import append [as 别名]
def testMovingLayers( self ):
lsm = LayerStackModel()
lsm.append(self.l1)
lsm.append(self.l2)
lsm.append(self.l3)
lsm.selectRow(1)
self.assertEqual(len(lsm),3)
self.assertEqual(lsm[0].name, self.l3.name )
self.assertEqual(lsm[1].name, self.l2.name )
self.assertEqual(lsm[2].name, self.l1.name )
self.assertEqual(lsm.selectedRow(), 1)
lsm.moveSelectedDown()
self.assertEqual(lsm.selectedRow(), 2)
self.assertEqual(len(lsm),3)
self.assertEqual(lsm[0].name, self.l3.name )
self.assertEqual(lsm[1].name, self.l1.name )
self.assertEqual(lsm[2].name, self.l2.name )
lsm.selectRow(1)
lsm.moveSelectedUp()
self.assertEqual(lsm.selectedRow(), 0)
self.assertEqual(len(lsm),3)
self.assertEqual(lsm[0].name, self.l1.name )
self.assertEqual(lsm[1].name, self.l3.name )
self.assertEqual(lsm[2].name, self.l2.name )
# moving topmost layer up => nothing should happen
lsm.selectRow(0)
self.assertEqual(lsm.selectedRow(), 0)
self.assertEqual(lsm[0].name, self.l1.name )
self.assertEqual(lsm[1].name, self.l3.name )
self.assertEqual(lsm[2].name, self.l2.name )
lsm.moveSelectedUp()
self.assertEqual(lsm.selectedRow(), 0)
self.assertEqual(lsm[0].name, self.l1.name )
self.assertEqual(lsm[1].name, self.l3.name )
self.assertEqual(lsm[2].name, self.l2.name )
# moving bottommost layer down => nothing should happen
lsm.selectRow(2)
self.assertEqual(lsm.selectedRow(), 2)
self.assertEqual(lsm[0].name, self.l1.name )
self.assertEqual(lsm[1].name, self.l3.name )
self.assertEqual(lsm[2].name, self.l2.name )
lsm.moveSelectedDown()
self.assertEqual(lsm.selectedRow(), 2)
self.assertEqual(lsm[0].name, self.l1.name )
self.assertEqual(lsm[1].name, self.l3.name )
self.assertEqual(lsm[2].name, self.l2.name )
示例9: ImageScene2DTest
# 需要导入模块: from volumina.layerstack import LayerStackModel [as 别名]
# 或者: from volumina.layerstack.LayerStackModel import append [as 别名]
class ImageScene2DTest( ut.TestCase ):
def setUp( self ):
self.app = QApplication([], False)
self.layerstack = LayerStackModel()
self.sims = StackedImageSources( self.layerstack )
self.GRAY = 201
self.ds = ConstantSource(self.GRAY)
self.layer = GrayscaleLayer( self.ds )
self.layerstack.append(self.layer)
self.ims = imsfac.createImageSource( self.layer, [self.ds] )
self.sims.register(self.layer, self.ims)
self.scene = ImageScene2D(self.app)
self.scene.stackedImageSources = self.sims
self.scene.sceneShape = (310,290)
def renderScene( self, s):
img = QImage(310,290,QImage.Format_ARGB32_Premultiplied)
p = QPainter(img)
s.render(p)
s.joinRendering()
s.render(p)
p.end()
return byte_view(img)
def testBasicImageRenderingCapability( self ):
import time
aimg = self.renderScene(self.scene)
self.assertTrue(np.all(aimg[:,:,0:3] == self.GRAY))
self.assertTrue(np.all(aimg[:,:,3] == 255))
@ut.skipIf(os.getenv('TRAVIS'), 'fails on TRAVIS CI due to unknown reasons')
def testToggleVisibilityOfOneLayer( self ):
aimg = self.renderScene(self.scene)
self.assertTrue(np.all(aimg[:,:,0:3] == self.GRAY))
self.assertTrue(np.all(aimg[:,:,3] == 255))
self.layer.visible = False
aimg = self.renderScene(self.scene)
self.assertTrue(np.all(aimg[:,:,0:3] == 255)) # all white
self.assertTrue(np.all(aimg[:,:,3] == 255))
self.layer.visible = True
aimg = self.renderScene(self.scene)
self.assertTrue(np.all(aimg[:,:,0:3] == self.GRAY))
self.assertTrue(np.all(aimg[:,:,3] == 255))
示例10: Main
# 需要导入模块: from volumina.layerstack import LayerStackModel [as 别名]
# 或者: from volumina.layerstack.LayerStackModel import append [as 别名]
class Main(QMainWindow):
def __init__(self, useGL, argv):
QMainWindow.__init__(self)
self.initUic()
def initUic(self):
self.g=g=Graph()
#get the absolute path of the 'ilastik' module
uic.loadUi("designerElements/MainWindow.ui", self)
self.actionQuit.triggered.connect(qApp.quit)
def toggleDebugPatches(show):
self.editor.showDebugPatches = show
self.actionShowDebugPatches.toggled.connect(toggleDebugPatches)
self.layerstack = LayerStackModel()
readerNew=op.OpH5ReaderBigDataset(g)
readerNew.inputs["Filenames"].setValue(["scripts/CB_compressed_XY.h5","scripts/CB_compressed_XZ.h5","scripts/CB_compressed_YZ.h5"])
readerNew.inputs["hdf5Path"].setValue("volume/data")
datasrc = LazyflowSource(readerNew.outputs["Output"])
layer1 = GrayscaleLayer( datasrc )
layer1.name = "Big Data"
self.layerstack.append(layer1)
shape=readerNew.outputs["Output"].meta.shape
print shape
self.editor = VolumeEditor(shape, self.layerstack)
#self.editor.setDrawingEnabled(False)
self.volumeEditorWidget.init(self.editor)
model = self.editor.layerStack
self.layerWidget.init(model)
self.UpButton.clicked.connect(model.moveSelectedUp)
model.canMoveSelectedUp.connect(self.UpButton.setEnabled)
self.DownButton.clicked.connect(model.moveSelectedDown)
model.canMoveSelectedDown.connect(self.DownButton.setEnabled)
self.DeleteButton.clicked.connect(model.deleteSelected)
model.canDeleteSelected.connect(self.DeleteButton.setEnabled)
示例11: testFirstFullyOpaque
# 需要导入模块: from volumina.layerstack import LayerStackModel [as 别名]
# 或者: from volumina.layerstack.LayerStackModel import append [as 别名]
def testFirstFullyOpaque( self ):
lsm = LayerStackModel()
sims = StackedImageSources( lsm )
self.assertEqual(sims.firstFullyOpaque(), None)
lsm.append(self.layer1)
lsm.append(self.layer2)
lsm.append(self.layer3)
self.assertEqual( lsm.layerIndex(self.layer1), 2 )
self.assertEqual( lsm.layerIndex(self.layer2), 1 )
self.assertEqual( lsm.layerIndex(self.layer3), 0 )
sims.register(self.layer1, self.ims1)
sims.register(self.layer2, self.ims2)
sims.register(self.layer3, self.ims3)
self.assertEqual(sims.firstFullyOpaque(), 0)
lsm.clear()
sims = StackedImageSources( lsm )
lsm.append(self.layer2)
lsm.append(self.layer3)
lsm.append(self.layer1)
self.assertEqual( lsm.layerIndex(self.layer1), 0 )
self.assertEqual( lsm.layerIndex(self.layer2), 2 )
self.assertEqual( lsm.layerIndex(self.layer3), 1 )
sims.register(self.layer1, self.ims1)
sims.register(self.layer2, self.ims2)
sims.register(self.layer3, self.ims3)
self.assertEqual(sims.firstFullyOpaque(), 1)
lsm.clear()
sims = StackedImageSources( lsm )
lsm.append(self.layer2)
lsm.append(self.layer1)
self.assertEqual( lsm.layerIndex(self.layer1), 0 )
self.assertEqual( lsm.layerIndex(self.layer2), 1 )
sims.register(self.layer1, self.ims1)
sims.register(self.layer2, self.ims2)
self.assertEqual(sims.firstFullyOpaque(), None)
lsm.clear()
示例12: DirtyPropagationTest
# 需要导入模块: from volumina.layerstack import LayerStackModel [as 别名]
# 或者: from volumina.layerstack.LayerStackModel import append [as 别名]
class DirtyPropagationTest( ut.TestCase ):
def setUp( self ):
dataShape = (1, 900, 400, 10, 1) # t,x,y,z,c
data = np.indices(dataShape)[3] # Data is labeled according to z-index
self.ds1 = ArraySource( data )
self.CONSTANT = 13
self.ds2 = ConstantSource( self.CONSTANT )
self.layer1 = GrayscaleLayer( self.ds1 )
self.layer1.visible = True
self.layer1.opacity = 1.0
self.layer2 = GrayscaleLayer( self.ds2 )
self.lsm = LayerStackModel()
self.pump = ImagePump( self.lsm, SliceProjection() )
def testEverythingDirtyPropagation( self ):
self.lsm.append(self.layer2)
tiling = Tiling((900,400), blockSize=100)
tp = TileProvider(tiling, self.pump.stackedImageSources)
try:
tp.requestRefresh(QRectF(100,100,200,200))
tp.join()
tiles = tp.getTiles(QRectF(100,100,200,200))
for tile in tiles:
aimg = byte_view(tile.qimg)
self.assertTrue(np.all(aimg[:,:,0:3] == self.CONSTANT))
self.assertTrue(np.all(aimg[:,:,3] == 255))
NEW_CONSTANT = self.CONSTANT+1
self.ds2.constant = NEW_CONSTANT
tp.requestRefresh(QRectF(100,100,200,200))
tp.join()
tiles = tp.getTiles(QRectF(100,100,200,200))
for tile in tiles:
aimg = byte_view(tile.qimg)
self.assertTrue(np.all(aimg[:,:,0:3] == NEW_CONSTANT))
self.assertTrue(np.all(aimg[:,:,3] == 255))
finally:
tp.notifyThreadsToStop()
tp.joinThreads()
def testOutOfViewDirtyPropagation( self ):
self.lsm.append(self.layer1)
tiling = Tiling((900,400), blockSize=100)
tp = TileProvider(tiling, self.pump.stackedImageSources)
try:
# Navigate down to the second z-slice
self.pump.syncedSliceSources.through = [0,1,0]
tp.requestRefresh(QRectF(100,100,200,200))
tp.join()
# Sanity check: Do we see the right data on the second slice? (should be all 1s)
tiles = tp.getTiles(QRectF(100,100,200,200))
for tile in tiles:
aimg = byte_view(tile.qimg)
self.assertTrue(np.all(aimg[:,:,0:3] == 1))
self.assertTrue(np.all(aimg[:,:,3] == 255))
# Navigate down to the third z-slice
self.pump.syncedSliceSources.through = [0,2,0]
tp.requestRefresh(QRectF(100,100,200,200))
tp.join()
# Sanity check: Do we see the right data on the third slice?(should be all 2s)
tiles = tp.getTiles(QRectF(100,100,200,200))
for tile in tiles:
aimg = byte_view(tile.qimg)
self.assertTrue(np.all(aimg[:,:,0:3] == 2))
self.assertTrue(np.all(aimg[:,:,3] == 255))
# Navigate back up to the second z-slice
self.pump.syncedSliceSources.through = [0,1,0]
tp.requestRefresh(QRectF(100,100,200,200))
tp.join()
for tile in tiles:
aimg = byte_view(tile.qimg)
self.assertTrue(np.all(aimg[:,:,0:3] == 1))
self.assertTrue(np.all(aimg[:,:,3] == 255))
# Change some of the data in the (out-of-view) third z-slice
slicing = (slice(None), slice(100,300), slice(100,300), slice(2,3), slice(None))
slicing = tuple(slicing)
self.ds1._array[slicing] = 99
self.ds1.setDirty( slicing )
# Navigate back down to the third z-slice
self.pump.syncedSliceSources.through = [0,2,0]
tp.requestRefresh(QRectF(100,100,200,200))
tp.join()
# Even though the data was out-of-view when it was changed, it should still have new values.
# If dirtiness wasn't propagated correctly, the cache's old values will be used.
# (For example, this fails if you comment out the call to setDirty, above.)
tiles = tp.getTiles(QRectF(100,100,200,200))
for tile in tiles:
aimg = byte_view(tile.qimg)
#.........这里部分代码省略.........
示例13: QApplication
# 需要导入模块: from volumina.layerstack import LayerStackModel [as 别名]
# 或者: from volumina.layerstack.LayerStackModel import append [as 别名]
import signal
signal.signal(signal.SIGINT, signal.SIG_DFL)
import sys, numpy
from PyQt4.QtGui import QApplication, QPushButton, QHBoxLayout, QVBoxLayout
from volumina.pixelpipeline.datasources import ArraySource
app = QApplication(sys.argv)
model = LayerStackModel()
o1 = Layer()
o1.name = "Fancy Layer"
o1.opacity = 0.5
model.append(o1)
o2 = Layer()
o2.name = "Some other Layer"
o2.opacity = 0.25
model.append(o2)
o3 = Layer()
o3.name = "Invisible Layer"
o3.opacity = 0.15
o3.visible = False
model.append(o3)
o4 = Layer()
o4.name = "Fancy Layer II"
o4.opacity = 0.95
示例14: Viewer
# 需要导入模块: from volumina.layerstack import LayerStackModel [as 别名]
# 或者: from volumina.layerstack.LayerStackModel import append [as 别名]
class Viewer(QMainWindow):
"""High-level API to view multi-dimensional arrays.
Properties:
title -- window title
"""
def __init__(self, parent=None):
QMainWindow.__init__(self, parent)
uiDirectory = os.path.split(volumina.__file__)[0]
if uiDirectory == '':
uiDirectory = '.'
loadUi(uiDirectory + '/viewer.ui', self)
self._dataShape = None
self._viewerInitialized = False
self.editor = None
self.viewingWidget = None
self.actionQuit.triggered.connect(qApp.quit)
#when connecting in renderScreenshot to a partial(...) function,
#we need to remember the created function to be able to disconnect
#to it later
self._renderScreenshotDisconnect = None
self.initLayerstackModel()
self.actionCurrentView = QAction(QIcon(), "Only for selected view", self.menuView)
f = self.actionCurrentView.font()
f.setBold(True)
self.actionCurrentView.setFont(f)
self.editor = VolumeEditor(self.layerstack)
#make sure the layer stack widget, which is the right widget
#managed by the splitter self.splitter shows up correctly
#TODO: find a proper way of doing this within the designer
def adjustSplitter():
s = self.splitter.sizes()
s = [int(0.66*s[0]), s[0]-int(0.66*s[0])]
self.splitter.setSizes(s)
QTimer.singleShot(0, adjustSplitter)
def initLayerstackModel(self):
self.layerstack = LayerStackModel()
self.layerWidget.init(self.layerstack)
model = self.layerstack
self.UpButton.clicked.connect(model.moveSelectedUp)
model.canMoveSelectedUp.connect(self.UpButton.setEnabled)
self.DownButton.clicked.connect(model.moveSelectedDown)
model.canMoveSelectedDown.connect(self.DownButton.setEnabled)
self.DeleteButton.clicked.connect(model.deleteSelected)
model.canDeleteSelected.connect(self.DeleteButton.setEnabled)
@property
def dataShape(self):
return self._dataShape
@dataShape.setter
def dataShape(self, s):
if s is None:
return
assert len(s) == 5
self._dataShape = s
self.editor.dataShape = s
if not self._viewerInitialized:
self._viewerInitialized = True
self.viewer.init(self.editor)
#make sure the data shape is correctly set
#(some signal/slot connections may be set up in the above init)
self.editor.dataShape = s
#if its 2D, maximize the corresponding window
if len([i for i in list(self.dataShape)[1:4] if i == 1]) == 1:
viewAxis = [i for i in range(1,4) if self.dataShape[i] != 1][0] - 1
self.viewer.quadview.switchMinMax(viewAxis)
def addGrayscaleLayer(self, a, name=None, direct=False):
source,self.dataShape = createDataSource(a,True)
layer = GrayscaleLayer(source, direct=direct)
if name:
layer.name = name
self.layerstack.append(layer)
return layer
def addAlphaModulatedLayer(self, a, name=None):
source,self.dataShape = createDataSource(a,True)
layer = AlphaModulatedLayer(source)
if name:
layer.name = name
self.layerstack.append(layer)
return layer
def addRGBALayer(self, a, name=None):
source,self.dataShape = createDataSource(a,True)
layer = RGBALayer(source[0],source[1],source[2])
if name:
layer.name = name
self.layerstack.append(layer)
return layer
#.........这里部分代码省略.........
示例15: Viewer
# 需要导入模块: from volumina.layerstack import LayerStackModel [as 别名]
# 或者: from volumina.layerstack.LayerStackModel import append [as 别名]
#.........这里部分代码省略.........
#
# create layer
#
if display == 'grayscale':
if interpretChannelsAs == None:
source = Source(a)
type_info = numpy.iinfo(a.dtype)
if type_info.min < 0:
print "WARNING: datatype is not bound to semi-positive values"
layer = GrayscaleLayer(source, range=(0, type_info.max))
elif interpretChannelsAs == "RGB":
if aSlices is not None:
layer = RGBALayer(LazyflowSource(aSlices[0]), LazyflowSource(aSlices[1]), LazyflowSource(aSlices[2]))
else:
assert len(a.shape) == 3
layer = RGBALayer(Source(a[:,:,0]), Source(a[:,:,1]), Source(a[:,:,2]))
elif display == 'randomcolors':
if a.dtype != numpy.uint8:
print "layer '%s': implicit conversion from %s to uint8" \
% (name, a.dtype)
if a.dtype == numpy.uint32:
a = a.astype(numpy.uint8)
else:
raise RuntimeError("unhandled dtype=%r" % a.dtype)
source = Source(a)
layer = ColortableLayer(source, self._randomColors())
else:
raise RuntimeError("unhandled type of overlay")
layer.name = name
layer.opacity = opacity
layer.visible = visible
self.layerstack.append(layer)
return layer
def removeLayer(self, layer):
"""Remove layer either by given 'Layer' object
(as returned by self.addLayer), or by it's name string
(as given to the name parameter in self.addLayer)"""
if isinstance(layer, Layer):
idx = self.layerstack.layerIndex(layer)
self.layerstack.removeRows(idx, 1)
else:
idx = [i for i in range(len(self.layerstack)) if \
self.layerstack.data(self.layerstack.index(i)).name == layer]
if len(idx) > 1:
raise RuntimeError("Trying to remove layer '%s', whose name is"
"ambigous as it refers to %d layers" % len(idx))
return False
self.layerstack.removeRows(idx[0], 1)
return True
@property
def title(self):
"""Get the window title"""
return self.windowTitle()
@title.setter
def title(self, t):
"""Set the window title"""
self.setWindowTitle(t)