def setDataUnit(self, dataUnit, selectedItem = -1):
		"""
		Set the dataunit used for preview. Should be a combined 
					 data unit, the source units of which we can get and read 
					 as ImageData
		"""
		Logging.info("Setting dataunit of PreviewFrame to %s"%str(dataUnit), kw="preview")

		if not dataUnit:
			self.dataUnit = None
			self.z = 0
			self.slice = None
			self.updatePreview()
			self.Refresh()
			return
		
		self.dataUnit = dataUnit
		self.settings = dataUnit.getSettings()
		self.updateColor()
		InteractivePanel.setDataUnit(self, self.dataUnit)
		
		try:
			count = dataUnit.getNumberOfTimepoints()
			x, y, z = dataUnit.getDimensions()
		except Logging.GUIError, ex:
			ex.show()
			return
Exemplo n.º 2
0
    def enable(self, flag):
        """
		Enable/Disable updates
		"""
        InteractivePanel.enable(self, flag)
        if flag:
            self.calculateBuffer()
Exemplo n.º 3
0
    def setDataUnit(self, dataUnit, selectedItem=-1):
        """
		Set the dataunit used for preview. Should be a combined 
					 data unit, the source units of which we can get and read 
					 as ImageData
		"""
        Logging.info("Setting dataunit of PreviewFrame to %s" % str(dataUnit),
                     kw="preview")

        if not dataUnit:
            self.dataUnit = None
            self.z = 0
            self.slice = None
            self.updatePreview()
            self.Refresh()
            return

        self.dataUnit = dataUnit
        self.settings = dataUnit.getSettings()
        self.updateColor()
        InteractivePanel.setDataUnit(self, self.dataUnit)

        try:
            count = dataUnit.getNumberOfTimepoints()
            x, y, z = dataUnit.getDimensions()
        except Logging.GUIError, ex:
            ex.show()
            return
Exemplo n.º 4
0
    def deregister(self):
        """
		Delete all known references because this view mode is to be removed
		"""
        lib.messenger.disconnect(None, "zslice_changed",
                                 self.setPreviewedSlice)
        InteractivePanel.deregister(self)
	def enable(self, flag):
		"""
		Enable/Disable updates
		"""
		InteractivePanel.enable(self, flag)
		if flag:
			self.calculateBuffer()
	def onMouseMotion(self, event):
		"""
		Handle mouse motion event
		"""
		pos = event.GetPosition()
		if self.curPos != pos:
			self.curPos = pos
			InteractivePanel.onMouseMotion(self, event)
			self.getVoxelValue(pos)
		event.Skip()
Exemplo n.º 7
0
    def onMouseMotion(self, event):
        """
		Handle mouse motion event
		"""
        pos = event.GetPosition()
        if self.curPos != pos:
            self.curPos = pos
            InteractivePanel.onMouseMotion(self, event)
            self.getVoxelValue(pos)
        event.Skip()
	def deregister(self):
		"""
		Delete all known references because this view mode is to be removed
		"""
		print "Deregistering previewframe"
		try:
			lib.messenger.disconnect(None, "zslice_changed", self.setPreviewedSlice)
			lib.messenger.disconnect(None, "renew_preview", self.setRenewFlag)
		except:
			pass
		InteractivePanel.deregister(self)
Exemplo n.º 9
0
    def deregister(self):
        """
		Delete all known references because this view mode is to be removed
		"""
        print "Deregistering previewframe"
        try:
            lib.messenger.disconnect(None, "zslice_changed",
                                     self.setPreviewedSlice)
            lib.messenger.disconnect(None, "renew_preview", self.setRenewFlag)
        except:
            pass
        InteractivePanel.deregister(self)
	def onLeftDown(self, event):
		"""
		Handle left mouse button down event
		"""
		InteractivePanel.onLeftDown(self, event)
		event.Skip()
		pos = event.GetPosition()
		voxelInfo = self.getVoxelValue(pos)
		if voxelInfo is not None:
			rx, ry, rz, scalar, rv, gv, bv, r, g, b, alpha = voxelInfo
		else:
			rx, ry, rz = -1, -1, -1
		lib.messenger.send(None, "one_click_center", rx, ry, rz)
Exemplo n.º 11
0
    def onLeftDown(self, event):
        """
		Handle left mouse button down event
		"""
        InteractivePanel.onLeftDown(self, event)
        event.Skip()
        pos = event.GetPosition()
        voxelInfo = self.getVoxelValue(pos)
        if voxelInfo is not None:
            rx, ry, rz, scalar, rv, gv, bv, r, g, b, alpha = voxelInfo
        else:
            rx, ry, rz = -1, -1, -1
        lib.messenger.send(None, "one_click_center", rx, ry, rz)
Exemplo n.º 12
0
    def setDataUnit(self, dataunit):
        """
		Sets the dataunit to display
		"""
        self.dataUnit = dataunit
        if not dataunit:
            return
        self.dims = dataunit.getDimensions()
        self.voxelSize = dataunit.getVoxelSize()
        InteractivePanel.setDataUnit(self, dataunit)
        tp = self.timepoint
        self.timepoint = -1
        self.setTimepoint(tp)
        x, y = self.paintSize
        #self.setScrollbars(x, y)
        self.calculateBuffer()
        self.updatePreview()
	def __init__(self, parent, visualizer, size = (512, 512), **kws):
		"""
		Initialization
		"""
		self.imagedata = None
		self.visualizer = visualizer
		self.bmp = None
		self.bgcolor = (127, 127, 127)
		Logging.info("Size of gallery =", size, kw = "preview")
		self.enabled = 1
		self.slices = []
		self.zoomx = 1
		self.zoomy = 1
		if kws.has_key("slicesize"):
			self.sliceSize = kws["slicesize"]
		else:
			self.sliceSize = (128, 128)
		self.originalSliceSize = self.sliceSize
		
		x, y = size
		self.paintSize = size
		self.reqSize = size
		self.buffer = wx.EmptyBitmap(x, y)
		self.oldBufferDims = None
		self.oldBufferMaxXY = None
		InteractivePanel.__init__(self, parent, size = size, **kws)
		
		self.size = size
		self.sizeChanged = False
		self.rows = 0
		self.cols = 0
		self.scrollsize = 32
		self.scrollTo = None
		self.drawableRects = []
		self.slice = 0
		self.ctf = None
		
		self.interpolation = 0
		
		self.voxelSize = (0, 0, 0)
		self.showTimepoints = 0
		self.timepoint = 0
		self.paintPreview()
		self.Bind(wx.EVT_PAINT, self.OnPaint)
		self.Bind(wx.EVT_SIZE, self.onSize)
		lib.messenger.connect(None, "zslice_changed", self.setPreviewedSlice)
	def setDataUnit(self, dataunit):
		"""
		Sets the dataunit to display
		"""
		self.dataUnit = dataunit
		if not dataunit:
			return
		self.dims = dataunit.getDimensions()
		self.voxelSize = dataunit.getVoxelSize()
		InteractivePanel.setDataUnit(self, dataunit)
		tp = self.timepoint
		self.timepoint = -1
		self.setTimepoint(tp)
		x, y = self.paintSize
		#self.setScrollbars(x, y)
		self.calculateBuffer()
		self.updatePreview()
Exemplo n.º 15
0
    def __init__(self, parent, visualizer, size=(512, 512), **kws):
        """
		Initialization
		"""
        self.imagedata = None
        self.visualizer = visualizer
        self.bmp = None
        self.bgcolor = (127, 127, 127)
        Logging.info("Size of gallery =", size, kw="preview")
        self.enabled = 1
        self.slices = []
        self.zoomx = 1
        self.zoomy = 1
        if kws.has_key("slicesize"):
            self.sliceSize = kws["slicesize"]
        else:
            self.sliceSize = (128, 128)
        self.originalSliceSize = self.sliceSize

        x, y = size
        self.paintSize = size
        self.reqSize = size
        self.buffer = wx.EmptyBitmap(x, y)
        self.oldBufferDims = None
        self.oldBufferMaxXY = None
        InteractivePanel.__init__(self, parent, size=size, **kws)

        self.size = size
        self.sizeChanged = False
        self.rows = 0
        self.cols = 0
        self.scrollsize = 32
        self.scrollTo = None
        self.drawableRects = []
        self.slice = 0
        self.ctf = None

        self.interpolation = 0

        self.voxelSize = (0, 0, 0)
        self.showTimepoints = 0
        self.timepoint = 0
        self.paintPreview()
        self.Bind(wx.EVT_PAINT, self.OnPaint)
        self.Bind(wx.EVT_SIZE, self.onSize)
        lib.messenger.connect(None, "zslice_changed", self.setPreviewedSlice)
Exemplo n.º 16
0
    def onSize(self, event):
        """
		Size event handler
		"""
        InteractivePanel.OnSize(self, event)
        self.paintSize = self.GetClientSize()
        self.sizeChanged = True
        if scripting.renderingEnabled:
            self.calculateBuffer()
            self.updatePreview()
Exemplo n.º 17
0
    def onSize(self, event):
        """
		Size event handler
		"""
        if event.GetSize() == self.lastEventSize:
            return
        self.lastEventSize = event.GetSize()

        InteractivePanel.OnSize(self, event)
        self.sizeChanged = 1
        if self.enabled and scripting.renderingEnabled:
            self.calculateBuffer()
            self.updatePreview(renew=0)
        event.Skip()
	def paintPreview(self, clientdc = None):
		"""
		Paints the image to a DC
		"""
		Logging.info("PreviewFrame is enabled=", bool(self.enabled), kw="preview")
		# Don't paint anything if there's going to be a redraw anyway
		if not self.slice and self.graySize == self.paintSize:
			Logging.info("Nothing to draw, returning", kw="preview")
			return
		
		dc = wx.MemoryDC()
		dc.SelectObject(self.buffer)
		dc.BeginDrawing()
		
		dc.SetBackground(wx.Brush(wx.Colour(*self.bgcolor)))
		dc.SetPen(wx.Pen(wx.Colour(*self.bgcolor), 0))
		dc.SetBrush(wx.Brush(wx.Colour(*self.bgcolor)))
		x0, y0 = 0, 0
		w, h = self.buffer.GetWidth(), self.buffer.GetHeight()
		
		dc.DrawRectangle(x0, y0, self.paintSize[0] + x0, self.paintSize[1] + x0)

		if not self.slice or not self.enabled:
			self.graySize = self.paintSize
			self.makeBackgroundBuffer(dc)
			dc.EndDrawing()
			self.repaintHelpers(update = 0)
			return

		bmp = self.slice
		Logging.info("Zoom factor for painting =", self.zoomFactor, kw = "preview")
		if self.zoomFactor != 1 or self.zoomFactor != self.oldZoomFactor:
			self.oldZoomFactor = self.zoomFactor
			if self.interpolation != 0:
				bmp = self.zoomImageWithInterpolation(self.imagedata, self.zoomFactor, self.interpolation, self.z)
			if not self.interpolation or not bmp:
				Logging.info("Using no interpolation",kw="preview")
				img = lib.ImageOperations.scaleImage(self.imagedata, self.zoomFactor, self.z, self.interpolation)
				bmp = lib.ImageOperations.vtkImageDataToWxImage(img)
			w, h = bmp.GetWidth(), bmp.GetHeight()

		if self.zoomx != 1 or self.zoomy != 1:
			w, h = bmp.GetWidth(), bmp.GetHeight()
			w *= self.zoomx
			h *= self.zoomy
			Logging.info("Scaling to ", w, h, kw = "preview")
			bmp.Rescale(w, h)
			self.calculateBuffer()

		bmp = bmp.ConvertToBitmap()
		self.snapshot = bmp
		bw, bh = bmp.GetWidth(), bmp.GetHeight()
		
		tw, th = self.buffer.GetWidth(), self.buffer.GetHeight()
		xoff = (tw - bw) / 2
		yoff = (th - bh) / 2
		x0, y0, w, h = self.GetClientRect()
		
		self.snapshotPos = xoff + x0 * 2, yoff + y0 * 2
		self.snapshotSize = bw, bh

		self.setOffset(xoff, yoff)
		dc.DrawBitmap(bmp, xoff + x0, yoff + y0, True)
		self.drawableRect = (xoff+x0,xoff+x0+bmp.GetWidth(),yoff+y0, yoff+y0+bmp.GetHeight())

		self.bmp = self.buffer
		
		InteractivePanel.paintPreview(self, dc)

		self.makeBackgroundBuffer(dc)
		
		dc.EndDrawing()
		self.repaintHelpers()
Exemplo n.º 19
0
    def OnPaint(self, event):
        """
		Does the actual blitting of the bitmap
		"""

        InteractivePanel.OnPaint(self, event)
	def __init__(self, parent, **kws):
		"""
		Initialize the panel
		"""
		self.graySize = (0, 0)
		self.bgcolor = (127, 127, 127)
		self.maxClientSizeX, self.maxClientSizeY = 512, 512
		self.dataWidth, self.dataHeight = 512 , 512
		self.lastEventSize = None
		self.paintSize = (512, 512)
		self.parent = parent
		self.blackImage = None
		self.finalImage = None
		self.xdiff, self.ydiff = 0, 0
		self.oldZoomFactor = 1
		self.selectedItem = -1
		self.show = {}
		self.rawImages = []
		self.rawImage = None
		
		self.oldx, self.oldy = 0, 0
		self.curPos = (-1,-1)
		Logging.info("kws=", kws, kw = "preview")
		self.fixedSize = kws.get("previewsize", None)
		size = kws.get("previewsize", (1024, 1024))

		self.zoomFactor = kws.get("zoom_factor", 1)
		self.zoomx = kws.get("zoomx", 1)
		self.zoomy = kws.get("zoomy", 1)
		
		self.show["SCROLL"] = kws.get("scrollbars", 0)
		
		self.rgbMode = 0
		self.currentImage = None
		self.currentCt = None
		
		# The preview can be no larger than these
		
		self.dataDimX, self.dataDimY, self.dataDimZ = 0, 0, 0
		self.running = 0

		self.rgb = (255, 255, 0)

		self.timePoint = 0
		
		self.mapToColors = vtk.vtkImageMapToColors()
		self.mapToColors.SetLookupTable(self.currentCt)
		self.mapToColors.SetOutputFormatToRGB()
			
		self.renewNext = 0
		
		self.fitLater = 0
		self.imagedata = None
		self.bmp = None
		self.parent = parent
		self.scroll = 1
		Logging.info("preview panel size=", size, kw = "preview")
		
		x, y = size
		self.buffer = wx.EmptyBitmap(x, y)
		
		if kws.has_key("zoomx"):
			del kws["zoomx"]
		if kws.has_key("zoomy"):
			del kws["zoomy"]
			
		Logging.info("zoom xf=%f, yf=%f" % (self.zoomx, self.zoomy), kw = "preview")

		self.size = size
		self.slice = None
		self.z = 0
		self.zooming = 0
		self.scrollTo = None
		
		InteractivePanel.__init__(self, parent, size = size, bgColor = self.bgcolor, **kws)
		
		self.annotationsEnabled = True
		self.calculateBuffer()
		self.paintSize = self.GetClientSize()
		self.paintPreview()
		
		self.addListener(wx.EVT_RIGHT_DOWN, self.onRightClick)
		
		self.Bind(wx.EVT_SIZE, self.onSize)
		self.Bind(wx.EVT_LEFT_DOWN, self.onLeftDown)
		self.Bind(wx.EVT_MOTION, self.onMouseMotion)
		self.SetHelpText("This window displays the selected dataset slice by slice.")
		
		if not self.show["SCROLL"]:
			Logging.info("Disabling scrollbars", kw="preview")
			self.SetScrollbars(0, 0, 0, 0)
		self.updateAnnotations()
		self.drawableRect = self.GetClientRect()
		lib.messenger.connect(None, "zslice_changed", self.setPreviewedSlice)
		lib.messenger.connect(None, "renew_preview", self.setRenewFlag)
	def deregister(self):
		"""
		Delete all known references because this view mode is to be removed
		"""
		lib.messenger.disconnect(None, "zslice_changed", self.setPreviewedSlice)
		InteractivePanel.deregister(self)
Exemplo n.º 22
0
    def __init__(self, parent, **kws):
        """
		Initialize the panel
		"""
        self.graySize = (0, 0)
        self.bgcolor = (127, 127, 127)
        self.maxClientSizeX, self.maxClientSizeY = 512, 512
        self.dataWidth, self.dataHeight = 512, 512
        self.lastEventSize = None
        self.paintSize = (512, 512)
        self.parent = parent
        self.blackImage = None
        self.finalImage = None
        self.xdiff, self.ydiff = 0, 0
        self.oldZoomFactor = 1
        self.selectedItem = -1
        self.show = {}
        self.rawImages = []
        self.rawImage = None

        self.oldx, self.oldy = 0, 0
        self.curPos = (-1, -1)
        Logging.info("kws=", kws, kw="preview")
        self.fixedSize = kws.get("previewsize", None)
        size = kws.get("previewsize", (1024, 1024))

        self.zoomFactor = kws.get("zoom_factor", 1)
        self.zoomx = kws.get("zoomx", 1)
        self.zoomy = kws.get("zoomy", 1)

        self.show["SCROLL"] = kws.get("scrollbars", 0)

        self.rgbMode = 0
        self.currentImage = None
        self.currentCt = None

        # The preview can be no larger than these

        self.dataDimX, self.dataDimY, self.dataDimZ = 0, 0, 0
        self.running = 0

        self.rgb = (255, 255, 0)

        self.timePoint = 0

        self.mapToColors = vtk.vtkImageMapToColors()
        self.mapToColors.SetLookupTable(self.currentCt)
        self.mapToColors.SetOutputFormatToRGB()

        self.renewNext = 0

        self.fitLater = 0
        self.imagedata = None
        self.bmp = None
        self.parent = parent
        self.scroll = 1
        Logging.info("preview panel size=", size, kw="preview")

        x, y = size
        self.buffer = wx.EmptyBitmap(x, y)

        if kws.has_key("zoomx"):
            del kws["zoomx"]
        if kws.has_key("zoomy"):
            del kws["zoomy"]

        Logging.info("zoom xf=%f, yf=%f" % (self.zoomx, self.zoomy),
                     kw="preview")

        self.size = size
        self.slice = None
        self.z = 0
        self.zooming = 0
        self.scrollTo = None

        InteractivePanel.__init__(self,
                                  parent,
                                  size=size,
                                  bgColor=self.bgcolor,
                                  **kws)

        self.annotationsEnabled = True
        self.calculateBuffer()
        self.paintSize = self.GetClientSize()
        self.paintPreview()

        self.addListener(wx.EVT_RIGHT_DOWN, self.onRightClick)

        self.Bind(wx.EVT_SIZE, self.onSize)
        self.Bind(wx.EVT_LEFT_DOWN, self.onLeftDown)
        self.Bind(wx.EVT_MOTION, self.onMouseMotion)
        self.SetHelpText(
            "This window displays the selected dataset slice by slice.")

        if not self.show["SCROLL"]:
            Logging.info("Disabling scrollbars", kw="preview")
            self.SetScrollbars(0, 0, 0, 0)
        self.updateAnnotations()
        self.drawableRect = self.GetClientRect()
        lib.messenger.connect(None, "zslice_changed", self.setPreviewedSlice)
        lib.messenger.connect(None, "renew_preview", self.setRenewFlag)
Exemplo n.º 23
0
    def paintPreview(self, clientdc=None):
        """
		Paints the image to a DC
		"""
        Logging.info("PreviewFrame is enabled=",
                     bool(self.enabled),
                     kw="preview")
        # Don't paint anything if there's going to be a redraw anyway
        if not self.slice and self.graySize == self.paintSize:
            Logging.info("Nothing to draw, returning", kw="preview")
            return

        dc = wx.MemoryDC()
        dc.SelectObject(self.buffer)
        dc.BeginDrawing()

        dc.SetBackground(wx.Brush(wx.Colour(*self.bgcolor)))
        dc.SetPen(wx.Pen(wx.Colour(*self.bgcolor), 0))
        dc.SetBrush(wx.Brush(wx.Colour(*self.bgcolor)))
        x0, y0 = 0, 0
        w, h = self.buffer.GetWidth(), self.buffer.GetHeight()

        dc.DrawRectangle(x0, y0, self.paintSize[0] + x0,
                         self.paintSize[1] + x0)

        if not self.slice or not self.enabled:
            self.graySize = self.paintSize
            self.makeBackgroundBuffer(dc)
            dc.EndDrawing()
            self.repaintHelpers(update=0)
            return

        bmp = self.slice
        Logging.info("Zoom factor for painting =",
                     self.zoomFactor,
                     kw="preview")
        if self.zoomFactor != 1 or self.zoomFactor != self.oldZoomFactor:
            self.oldZoomFactor = self.zoomFactor
            if self.interpolation != 0:
                bmp = self.zoomImageWithInterpolation(self.imagedata,
                                                      self.zoomFactor,
                                                      self.interpolation,
                                                      self.z)
            if not self.interpolation or not bmp:
                Logging.info("Using no interpolation", kw="preview")
                img = lib.ImageOperations.scaleImage(self.imagedata,
                                                     self.zoomFactor, self.z,
                                                     self.interpolation)
                bmp = lib.ImageOperations.vtkImageDataToWxImage(img)
            w, h = bmp.GetWidth(), bmp.GetHeight()

        if self.zoomx != 1 or self.zoomy != 1:
            w, h = bmp.GetWidth(), bmp.GetHeight()
            w *= self.zoomx
            h *= self.zoomy
            Logging.info("Scaling to ", w, h, kw="preview")
            bmp.Rescale(w, h)
            self.calculateBuffer()

        bmp = bmp.ConvertToBitmap()
        self.snapshot = bmp
        bw, bh = bmp.GetWidth(), bmp.GetHeight()

        tw, th = self.buffer.GetWidth(), self.buffer.GetHeight()
        xoff = (tw - bw) / 2
        yoff = (th - bh) / 2
        x0, y0, w, h = self.GetClientRect()

        self.snapshotPos = xoff + x0 * 2, yoff + y0 * 2
        self.snapshotSize = bw, bh

        self.setOffset(xoff, yoff)
        dc.DrawBitmap(bmp, xoff + x0, yoff + y0, True)
        self.drawableRect = (xoff + x0, xoff + x0 + bmp.GetWidth(), yoff + y0,
                             yoff + y0 + bmp.GetHeight())

        self.bmp = self.buffer

        InteractivePanel.paintPreview(self, dc)

        self.makeBackgroundBuffer(dc)

        dc.EndDrawing()
        self.repaintHelpers()