Example #1
0
def newLineByStroking(self, thickness=1, join=0, cap=0, miter=10, dashed=0, dash=None, phase=0):
	"""Apply a stroke style to this PLine.
		
	Returns a new line with this line stroked with a particular style."""
	if (dash):
		stroke = BasicStroke(thickness, join, cap, miter, dash, phase)		
	else:
		stroke = BasicStroke(thickness, join, cap, miter)
	s = LineUtils().lineAsStroked(self, stroke, 1)
	LineUtils().fixClose(s)
	return s
Example #2
0
File: draw.py Project: jggatc/pyj2d
def arc(surface, color, rect, start_angle, stop_angle, width=1):
    """
    Draw arc shape, and returns bounding Rect.
    Argument include surface to draw, color, rect, start_angle, stop_angle.
    Optional width argument of outline.
    """
    if not hasattr(rect, 'width'):
        rect = Rect(rect)
    start_angle = int(start_angle * _rad_deg)
    stop_angle = int(stop_angle * _rad_deg)
    g = surface.createGraphics()
    if hasattr(color, 'a'):
        g.setColor(color)
    else:
        g.setColor(Color(color))
    g.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
                       RenderingHints.VALUE_ANTIALIAS_ON)
    if width:
        g.setStroke(BasicStroke(width))
        g.drawArc(rect.x, rect.y, rect.width - 1, rect.height - 1, start_angle,
                  stop_angle)
    else:
        g.fillArc(rect.x, rect.y, rect.width - 1, rect.height - 1, start_angle,
                  stop_angle)
    g.dispose()
    if not _return_rect:
        return None
    return surface.get_rect().clip(rect)
Example #3
0
File: draw.py Project: jggatc/pyj2d
def line(surface, color, point1, point2, width=1):
    """
    Draw line, and returns bounding Rect.
    Argument include surface to draw, color, point1, point2.
    Optional width argument of line.
    """
    g = surface.createGraphics()
    if hasattr(color, 'a'):
        g.setColor(color)
    else:
        g.setColor(Color(color))
    g.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
                       RenderingHints.VALUE_ANTIALIAS_ON)
    g.setStroke(BasicStroke(width))
    g.drawLine(int(point1[0]), int(point1[1]), int(point2[0]), int(point2[1]))
    g.dispose()
    if not _return_rect:
        return None
    xpts = [pt[0] for pt in (point1, point2)]
    ypts = [pt[1] for pt in (point1, point2)]
    xmin = min(xpts)
    xmax = max(xpts)
    ymin = min(ypts)
    ymax = max(ypts)
    rect = Rect(xmin, ymin, xmax - xmin + 1, ymax - ymin + 1)
    return surface.get_rect().clip(rect)
Example #4
0
 def render(self, text, antialias, color, background=None):
     """
     Render text onto surface.
     Arguments:
     text to render (string)
     antialias of text (bool)
     color of text (R,G,B)
     background color (R,G,B)
     """
     w,h = self.size(text)
     surf = surface.Surface((w,h), BufferedImage.TYPE_INT_ARGB)
     g2d = surf.createGraphics()
     if background:
         R,G,B = background
         g2d.setColor(Color(R,G,B))
         g2d.fillRect(0,0,w,h)
     g2d.setFont(self.font)
     if antialias:
         g2d.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON)
     R,G,B = color
     g2d.setColor(Color(R,G,B))
     g2d.drawString(text,2,h//1.25+2)
     if self.underline:
         g2d.setStroke(BasicStroke(1))
         g2d.drawLine(2,h-4,w-3,h-4)
     g2d.dispose()
     return surf
Example #5
0
 def render(self, text, antialias, color, background=None):
     """
     Render text onto surface.
     Arguments:
     text to render (string)
     antialias of text (bool)
     color of text (R,G,B)
     background color (R,G,B)
     """
     w, h = self.size(text)
     surf = surface.Surface((w, h), BufferedImage.TYPE_INT_ARGB)
     g2d = surf.createGraphics()
     if background:
         g2d.setColor(Color(background))  #0.23
         g2d.fillRect(0, 0, w, h)
     g2d.setFont(self.font)
     if antialias:
         g2d.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING,
                              RenderingHints.VALUE_TEXT_ANTIALIAS_ON)
     g2d.setColor(Color(color))  #0.23
     g2d.drawString(text, 0,
                    (h // 2) + (self.fontMetrics.getAscent() // 2))  #0.22
     if self.underline:
         g2d.setStroke(BasicStroke(1))
         g2d.drawLine(0, h - 1, w - 1, h - 1)  #0.22
     g2d.dispose()
     return surf
Example #6
0
 def arc(self, surface, color, rect, start_angle, stop_angle, width=1):
     """
     Draw arc shape, and returns bounding Rect.
     Argument include surface to draw, color, rect, start_angle, stop_angle.
     Optional width argument of outline.
     """
     try:
         x, y, w, h = rect.x, rect.y, rect.width, rect.height
     except AttributeError:
         try:
             x, y, w, h = rect
         except ValueError:
             x, y = rect[0]
             w, h = rect[1]
         rect = Rect(x, y, w, h)
     start_angle = int(start_angle * self.rad_deg)
     stop_angle = int(stop_angle * self.rad_deg)
     x -= w // 8
     y -= h // 8
     g = surface.createGraphics()
     R, G, B = color
     g.setColor(Color(R, G, B))
     if width:
         g.setStroke(BasicStroke(width))
         g.drawArc(x, y, w, h, start_angle, stop_angle)
     else:
         g.fillArc(x, y, w, h, start_angle, stop_angle)
     g.dispose()
     return rect
Example #7
0
 def rect(self, surface, color, rect, width=0):
     """
     Draw rectangle shape, and returns bounding Rect.
     Argument include surface to draw, color, Rect.
     Optional width argument of outline, which defaults to 0 for filled shape.
     """
     try:
         x, y, w, h = rect.x, rect.y, rect.width, rect.height
     except AttributeError:
         try:
             x, y, w, h = rect
         except ValueError:
             x, y = rect[0]
             w, h = rect[1]
         rect = Rect(x, y, w, h)
     g = surface.createGraphics()
     R, G, B = color
     g.setColor(Color(R, G, B))  # *tuple unpack jythonc error
     if width:
         g.setStroke(BasicStroke(width))
         g.drawRect(x, y, w, h)
     else:
         g.fillRect(x, y, w, h)
     g.dispose()
     return rect
Example #8
0
 def lines(self, surface, color, closed, pointlist, width=1):
     """
     Draw interconnected lines, and returns Rect bound.
     Argument include surface to draw, color, closed, and pointlist.
     Optional width argument of line.
     """
     xpoints = [p[0] for p in pointlist]
     ypoints = [p[1] for p in pointlist]
     if closed:
         xpoint, ypoint = xpoints[0], ypoints[0]
         xpoints.append(xpoint)
         ypoints.append(ypoint)
     npoints = len(xpoints)
     g = surface.createGraphics()
     R, G, B = color
     g.setColor(Color(R, G, B))
     g.setStroke(BasicStroke(width))
     g.drawPolyline(xpoints, ypoints, npoints)
     g.dispose()
     xmin = min(xpoints)
     xmax = max(xpoints)
     ymin = min(ypoints)
     ymax = max(ypoints)
     w = xmax - xmin
     h = ymax - ymin
     return Rect(xmin, ymin, w, h)
Example #9
0
	def show(self, at=None, blending=1, decor=1, name=None, extents=None, scale = None):
		if (not at): at = self.defaultPosition
		r1 = extents or self.image().getExtents()
		line = PLine().moveTo(at[0]+r1.x, at[1]+r1.y)
		line.containsImages=1
		self.blending = blending
		line.image_v=self
		line.imageDrawScale_v = scale or self.defaultScale
		getSelf().lines.add(line)
		if (decor):
			rOuter = PLine().rect(Rect(at[0]+r1.x, at[1]+r1.y, r1.w, r1.h))
			rInner = PLine().rect(Rect(at[0],at[1],r1.w+2*r1.x,r1.h+2*r1.y))
			rOuter.color=Vector4(0,0,0,0.5)
			rInner.color=Vector4(0,0,0,0.5)
			rOuter.derived=1
			rInner.derived=1
			rOuter.thickness=0.5
			rInner.thickness=0.5
			rOuter.strokeType = BasicStroke(0.5, 1, 1, 1, (10,10),0)
			getSelf().lines.add(rOuter)
			getSelf().lines.add(rInner)
			if (name):
				annotation = PLine().moveTo(at[0]+(r1.w+2*r1.x)/2,at[1]+r1.h+16)
				annotation.containsText=1
				annotation.text_v = name
				annotation.font_v = Font("Gill Sans", 0, 14)
				annotation.derived=1
				annotation.color_v=Vector4(0,0,0,0.15)
				getSelf().lines.add(annotation)
Example #10
0
File: draw.py Project: jggatc/pyj2d
def lines(surface, color, closed, pointlist, width=1):
    """
    Draw interconnected lines, and returns Rect bound.
    Argument include surface to draw, color, closed, and pointlist.
    Optional width argument of line.
    """
    xpoints = [int(p[0]) for p in pointlist]
    ypoints = [int(p[1]) for p in pointlist]
    if closed:
        xpoint, ypoint = xpoints[0], ypoints[0]
        xpoints.append(xpoint)
        ypoints.append(ypoint)
    npoints = len(xpoints)
    g = surface.createGraphics()
    if hasattr(color, 'a'):
        g.setColor(color)
    else:
        g.setColor(Color(color))
    g.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
                       RenderingHints.VALUE_ANTIALIAS_ON)
    g.setStroke(BasicStroke(width))
    g.drawPolyline(xpoints, ypoints, npoints)
    g.dispose()
    if not _return_rect:
        return None
    xmin = min(xpoints)
    xmax = max(xpoints)
    ymin = min(ypoints)
    ymax = max(ypoints)
    rect = Rect(xmin, ymin, xmax - xmin + 1, ymax - ymin + 1)
    return surface.get_rect().clip(rect)
Example #11
0
File: draw.py Project: jggatc/pyj2d
def polygon(surface, color, pointlist, width=0):
    """
    Draw polygon shape, and returns bounding Rect.
    Argument include surface to draw, color, and pointlist.
    Optional width argument of outline, which defaults to 0 for filled shape.
    """
    g = surface.createGraphics()
    if hasattr(color, 'a'):
        g.setColor(color)
    else:
        g.setColor(Color(color))
    g.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
                       RenderingHints.VALUE_ANTIALIAS_ON)
    xpts = [int(pt[0]) for pt in pointlist]
    ypts = [int(pt[1]) for pt in pointlist]
    npts = len(pointlist)
    if width:
        g.setStroke(BasicStroke(width))
        g.drawPolygon(xpts, ypts, npts)
    else:
        g.fillPolygon(xpts, ypts, npts)
    g.dispose()
    if not _return_rect:
        return None
    xmin = min(xpts)
    xmax = max(xpts)
    ymin = min(ypts)
    ymax = max(ypts)
    rect = Rect(xmin, ymin, xmax - xmin + 1, ymax - ymin + 1)
    return surface.get_rect().clip(rect)
Example #12
0
    def strokeWith(self,
                   thickness=1,
                   join=0,
                   cap=0,
                   miter=10,
                   dashed=0,
                   dash=None,
                   phase=0):
        """Apply a stroke style to this PLine.
		
		This method replaces the contents of this PLine with the line stroked with a particular style."""
        if (dash):
            stroke = BasicStroke(thickness, join, cap, miter, dash, phase)
        else:
            stroke = BasicStroke(thickness, join, cap, miter)
        self.__dict__["line"] = self.maybeFix(LineUtils().lineAsStroked(
            self.__dict__["line"], stroke, 0))
        return self
Example #13
0
 def drawingContextDrawSolidLine(self, x1, y1, x2, y2, width, color):
     window, gc = self.drawingContext
     theColor = delphi_to_gdk_color(window, color)
     gc.color = theColor
     #gc.set_fill(gtk.gdk.SOLID)
     #gc.set_line_attributes(width, gtk.gdk.LINE_SOLID, gtk.gdk.CAP_BUTT, gtk.gdk.JOIN_MITER)
     #gc.drawLine(x1, y1, x2, y2)
     line = Line2D.Double(x1, y1, x2, y2)
     gc.setStroke(BasicStroke(width))
     gc.draw(line)
	def draw(self, graphics):
		sz = self.__element.getActualSize()
		prevPaint = graphics.getPaint()
		prevStroke = graphics.getStroke()
		current = self.__element.pushLocalToRootGraphicsTransform(graphics)
		graphics.setPaint(Color(0.0, 0.3, 0.6, 0.5))
		graphics.setStroke(BasicStroke(2.0))
		graphics.draw(Rectangle2D.Double(1.0, 1.0, sz.x - 2.0, sz.y - 2.0))
		graphics.setPaint(prevPaint)
		graphics.setStroke(prevStroke)
		self.__element.popGraphicsTransform(graphics, current)
Example #15
0
    def zaxis(self, **kwargs):
        """
        Set z axis of the axes.

        :param color: (*Color*) Color of the z axis. Default is 'black'.
        :param shift: (*int) z axis shif along horizontal direction. Units is pixel. Default is 0.
        """
        visible = kwargs.pop('visible', None)
        shift = kwargs.pop('shift', None)
        color = kwargs.pop('color', None)
        if not color is None:
            color = plotutil.getcolor(color)
        linewidth = kwargs.pop('linewidth', None)
        linestyle = kwargs.pop('linestyle', None)
        tickline = kwargs.pop('tickline', None)
        tickline = kwargs.pop('tickvisible', tickline)
        tickwidth = kwargs.pop('tickwidth', None)
        ticklabel = kwargs.pop('ticklabel', None)
        minortick = kwargs.pop('minortick', False)
        minorticknum = kwargs.pop('minorticknum', 5)
        tickin = kwargs.pop('tickin', True)
        axistype = kwargs.pop('axistype', None)
        tickfontname = kwargs.pop('tickfontname', 'Arial')
        tickfontsize = kwargs.pop('tickfontsize', 14)
        tickbold = kwargs.pop('tickbold', False)
        if tickbold:
            font = Font(tickfontname, Font.BOLD, tickfontsize)
        else:
            font = Font(tickfontname, Font.PLAIN, tickfontsize)
        axislist = []
        axislist.append(self.axes.getZAxis())
        for axis in axislist:
            if not visible is None:
                axis.setVisible(visible)
            if not shift is None:
                axis.setShift(shift)
            if not color is None:
                axis.setColor_All(color)
            if not linewidth is None:
                axis.setLineWidth(linewidth)
            if not linestyle is None:
                axis.setLineStyle(linestyle)
            if not tickline is None:
                axis.setDrawTickLine(tickline)
            if not tickwidth is None:
                stroke = BasicStroke(tickwidth)
                axis.setTickStroke(stroke)
            if not ticklabel is None:
                axis.setDrawTickLabel(ticklabel)
            axis.setMinorTickVisible(minortick)
            axis.setMinorTickNum(minorticknum)
            axis.setInsideTick(tickin)
            axis.setTickLabelFont(font)
Example #16
0
def __Once_paint(inside, g, bounds):
    if (not getattr(getSelf(), inside.name + "_")): return
    g = g.create()
    g.setPaint(
        GradientPaint(bounds.x, bounds.y, Color(0.4, 0.4, 0.4, 0.8), bounds.x,
                      bounds.y + bounds.h, Color(0.3, 0.3, 0.3, 0.5)))
    g.fillRect(int(bounds.x), int(bounds.y), int(bounds.w - 15), int(bounds.h))
    g.setColor(Color(1, 1, 1, 0.1))
    g.setStroke(BasicStroke())
    g.clipRect(int(bounds.x), int(bounds.y), int(bounds.w - 15), int(bounds.h))
    for n in range(-20, bounds.w, 10):
        g.drawLine(int(bounds.x + n), int(bounds.y + 1),
                   int(bounds.x + 20 + n), int(bounds.y + bounds.h - 3))
Example #17
0
 def circle(self, surface, color, position, radius, width=0):
     """
     Draw circular shape, and returns bounding Rect.
     Argument include surface to draw, color, position and radius.
     Optional width argument of outline, which defaults to 0 for filled shape.
     """
     x, y = position
     w, h = 2*radius, 2*radius
     g = surface.createGraphics()
     g.setColor(Color(color))    #0.23
     if width:
         g.setStroke(BasicStroke(width))
         g.drawOval(x-radius, y-radius, w, h)
     else:
         g.fillOval(x-radius, y-radius, w, h)
     g.dispose()
     return Rect(x,y,w,h)
Example #18
0
File: draw.py Project: jggatc/pyj2d
def rect(surface, color, rect, width=0):
    """
    Draw rectangle shape, and returns bounding Rect.
    Argument include surface to draw, color, Rect.
    Optional width argument of outline, which defaults to 0 for filled shape.
    """
    if not hasattr(rect, 'width'):
        rect = Rect(rect)
    g = surface.createGraphics()
    if hasattr(color, 'a'):
        g.setColor(color)
    else:
        g.setColor(Color(color))
    if width:
        g.setStroke(BasicStroke(width))
        g.drawRect(rect.x, rect.y, rect.width, rect.height)
    else:
        g.fillRect(rect.x, rect.y, rect.width, rect.height)
    g.dispose()
    if not _return_rect:
        return None
    return surface.get_rect().clip(rect)
Example #19
0
 def line(self, surface, color, point1, point2, width=1):
     """
     Draw line, and returns bounding Rect.
     Argument include surface to draw, color, point1, point2.
     Optional width argument of line.
     """
     p1x, p1y = point1
     p2x, p2y = point2
     g = surface.createGraphics()
     g.setColor(Color(color))    #0.23
     g.setStroke(BasicStroke(width))
     g.drawLine(p1x,p1y,p2x,p2y)
     g.dispose()
     xpts = [pt[0] for pt in (point1,point2)]
     ypts = [pt[1] for pt in (point1,point2)]
     xmin = min(xpts)
     xmax = max(xpts)
     ymin = min(ypts)
     ymax = max(ypts)
     w = xmax-xmin
     h = ymax-ymin
     return Rect(xmin, ymin, w, h)
Example #20
0
 def polygon(self, surface, color, pointlist, width=0):
     """
     Draw polygon shape, and returns bounding Rect.
     Argument include surface to draw, color, and pointlist.
     Optional width argument of outline, which defaults to 0 for filled shape.
     """
     g = surface.createGraphics()
     g.setColor(Color(color))    #0.23
     xpts = [pt[0] for pt in pointlist]
     ypts = [pt[1] for pt in pointlist]
     npts = len(pointlist)
     xmin = min(xpts)
     xmax = max(xpts)
     ymin = min(ypts)
     ymax = max(ypts)
     if width:
         g.setStroke(BasicStroke(width))
         g.drawPolygon(xpts,ypts,npts)
     else:
         g.fillPolygon(xpts,ypts,npts)
     g.dispose()
     return Rect(xmin,ymin,xmax-xmin+1,ymax-ymin+1)
Example #21
0
File: draw.py Project: jggatc/pyj2d
def circle(surface, color, position, radius, width=0):
    """
    Draw circular shape, and returns bounding Rect.
    Argument include surface to draw, color, position and radius.
    Optional width argument of outline, which defaults to 0 for filled shape.
    """
    rect = Rect(position[0] - radius, position[1] - radius, 2 * radius,
                2 * radius)
    g = surface.createGraphics()
    if hasattr(color, 'a'):
        g.setColor(color)
    else:
        g.setColor(Color(color))
    g.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
                       RenderingHints.VALUE_ANTIALIAS_ON)
    if width:
        g.setStroke(BasicStroke(width))
        g.drawOval(rect.x, rect.y, rect.width, rect.height)
    else:
        g.fillOval(rect.x, rect.y, rect.width, rect.height)
    g.dispose()
    if not _return_rect:
        return None
    return surface.get_rect().clip(rect)
Example #22
0
def setTheme(chart):
    """ Takes a JFreeChart as argument and sets its rendering style to sensible defaults.
      See javadoc at http://jfree.org/jfreechart/api/javadoc/index.html """
    plot = chart.getPlot()
    r = plot.getRenderer()
    r.setBarPainter(StandardXYBarPainter())
    r.setSeriesOutlinePaint(0, Color.lightGray)
    r.setShadowVisible(False)
    r.setDrawBarOutline(False)
    gridStroke = BasicStroke(1.0, BasicStroke.CAP_ROUND,
                             BasicStroke.JOIN_ROUND, 1.0, (2.0, 1.0), 0.0)
    plot.setRangeGridlineStroke(gridStroke)
    plot.setDomainGridlineStroke(gridStroke)
    plot.setBackgroundPaint(Color(235, 235, 235))
    plot.setRangeGridlinePaint(Color.white)
    plot.setDomainGridlinePaint(Color.white)
    plot.setOutlineVisible(False)
    plot.getDomainAxis().setAxisLineVisible(False)
    plot.getRangeAxis().setAxisLineVisible(False)
    plot.getDomainAxis().setLabelPaint(Color.gray)
    plot.getRangeAxis().setLabelPaint(Color.gray)
    plot.getDomainAxis().setTickLabelPaint(Color.gray)
    plot.getRangeAxis().setTickLabelPaint(Color.gray)
    chart.getTitle().setPaint(Color.gray)
Example #23
0
from BritefuryJ.LSpace.Interactor import HoverElementInteractor, ClickElementInteractor

from BritefuryJ.Graphics import SolidBorder, FilledOutlinePainter

from BritefuryJ.Pres.Primitive import Label, FlowGrid
from BritefuryJ.Pres.UI import Section, SectionHeading3, ControlsRow

from BritefuryJ.Controls import Button

from LarchTools.PythonTools.GUIEditor.Properties import GUICProp, GUIEdProp
from LarchTools.PythonTools.GUIEditor.SidePanel import showSidePanel, hideSidePanel
from LarchTools.PythonTools.GUIEditor.Target import GUIEditorTarget, GUITargetListener
from LarchTools.PythonTools.GUIEditor.CurrentComponentEditor import currentComponentEditor


componentHighlighter = ElementHighlighter(FilledOutlinePainter(Color(0.0, 0.8, 0.0, 0.125), Color(0.0, 0.8, 0.0, 0.25), BasicStroke(1.0)))

class ComponentHighlightInteractor (HoverElementInteractor, ClickElementInteractor):
	def __init__(self, component, componentElement):
		self.__component = component
		self.__componentElement = componentElement

	def pointerEnter(self, element, event):
		componentHighlighter.highlight(self.__componentElement)

	def pointerLeave(self, element, event):
		componentHighlighter.unhighlight(self.__componentElement)


	def testClickEvent(self, element, event):
		return event.button == 1
Example #24
0
from BritefuryJ.Pres.UI import Section, SectionHeading2
from BritefuryJ.StyleSheet import StyleSheet

from BritefuryJ.Graphics import FilledOutlinePainter

from Britefury.Config import Configuration
from Britefury.Config.UserConfig import loadUserConfig, saveUserConfig
from Britefury.Config.ConfigurationPage import ConfigurationPage




_pathsConfigFilename = 'paths'


_itemHoverHighlightStyle = StyleSheet.style( Primitive.hoverBackground( FilledOutlinePainter( Color( 0.8, 0.825, 0.9 ), Color( 0.125, 0.341, 0.574 ), BasicStroke( 1.0 ) ) ) )




class PathsConfigurationPage (ConfigurationPage):
	def __init__(self):
		super( PathsConfigurationPage, self ).__init__()
		self._pluginPaths = []
		self._libraryPaths = []
		self._incr = IncrementalValueMonitor()
	
	
	def __getstate__(self):
		state = super( PathsConfigurationPage, self ).__getstate__()
		state['pluginPaths'] = self._pluginPaths
Example #25
0
def measure(stack, cells, nuclei):
    time = [ (t-1)*cal.frameInterval for t in range(T+1) ]
    cellValues0 = [ 0.0 for t in range(T+1) ]
    cellValues1 = [ 0.0 for t in range(T+1) ]
    cellAreas0 = [ 0.0 for t in range(T+1) ]
    cellAreas1 = [ 0.0 for t in range(T+1) ]
    nucleusValues0 = [ 0.0 for t in range(T+1) ]
    nucleusValues1 = [ 0.0 for t in range(T+1) ]
    nucleusAreas0 = [ 0.0 for t in range(T+1) ]
    nucleusAreas1 = [ 0.0 for t in range(T+1) ]
    nonNucleusValues0 = [ 0.0 for t in range(T+1) ]
    nonNucleusValues1 = [ 0.0 for t in range(T+1) ]

    for t in range(1,T+1):
        ip = stack.getProcessor(t)

        if cells[t] is None:
            continue


        #subtract background Z from all intensity Z measurements
        if cells [t] is None:
            print("Nocellsfound" + str(t))
        bothCells = ShapeRoi(cells[t][0]).or(ShapeRoi(cells[t][1]))
        backRoi = ShapeRoi(Rectangle(0,0,imp.getWidth(),imp.getHeight())).not( bothCells )


        ip.setRoi(backRoi)
        backMean = ip.getStatistics().mean

        ip.setRoi( cells[t][0] )
        stats0 = ip.getStatistics()
        cellValues0[t] = stats0.mean - backMean
        cellAreas0[t] = stats0.area * cal.pixelWidth * cal.pixelHeight
        nuc0 = None
        for nuc in nuclei[t]:
            rect = nuc.getBounds()
            nx = int(rect.x+(rect.width/2.0))
            ny = int(rect.y+(rect.height/2.0))
            if cells[t][0].contains(nx,ny):
                nuc0 = nuc
                break
        if nuc0 is not None:
            ip.setRoi( nuc0 )
            nucStats0 = ip.getStatistics()
            nucleusValues0[t] = nucStats0.mean - backMean
            nucleusAreas0[t] = nucStats0.area * cal.pixelWidth * cal.pixelHeight
            nuc0.setPosition(0,0,t)
            nuc0.setStrokeColor(Color.CYAN)
            ol.add(nuc0)
            nonnucRoi0 = ShapeRoi(cells[t][0]).not( ShapeRoi(nuc0) )
            ip.setRoi( nonnucRoi0 )
            nonNucleusValues0[t] = ip.getStatistics().mean - backMean

        ip.setRoi( cells[t][1] )
        stats1 = ip.getStatistics()
        cellValues1[t] = stats1.mean - backMean
        cellAreas1[t] = stats1.area * cal.pixelWidth * cal.pixelHeight
        nuc1 = None
        for nuc in nuclei[t]:
            rect = nuc.getBounds()
            nx = int(rect.x+(rect.width/2.0))
            ny = int(rect.y+(rect.height/2.0))
            if cells[t][1].contains(nx,ny):
                nuc1 = nuc
                break
        if nuc1 is not None:
            ip.setRoi( nuc1 )
            nucStats1 = ip.getStatistics()
            nucleusValues1[t] = nucStats1.mean - backMean
            nucleusAreas1[t] = nucStats1.area * cal.pixelWidth * cal.pixelHeight
            nuc1.setPosition(0,0,t)
            nuc1.setStrokeColor(Color.CYAN)
            ol.add(nuc1)
            nonnucRoi1 = ShapeRoi(cells[t][1]).not( ShapeRoi(nuc1) )
            ip.setRoi( nonnucRoi1 )
            nonNucleusValues1[t] = ip.getStatistics().mean - backMean

    rt = ResultsTable()
    rt.showRowNumbers(False)
    for t in range(1,T+1):
        rt.setValue("Time ("+cal.getTimeUnit()+")", t-1, IJ.d2s(time[t],1))
        areaRatio = cellAreas0[t] / cellAreas1[t] if cellAreas0[t]>0 and cellAreas1[t]>0 else 0.0
        rt.setValue("Cell 0:Cell 1 Area Ratio", t-1, areaRatio)

        nucleusRatio = nucleusValues0[t] / nucleusValues1[t] if nucleusValues0[t]>0 and nucleusValues1[t]>0 else 0.0
        rt.setValue("Cell 0:Cell 1 Nucleus Ratio", t-1, nucleusRatio)
        nonNucleusRatio = nonNucleusValues0[t] / nonNucleusValues1[t] if nonNucleusValues0[t]>0 and nonNucleusValues1[t]>0 else 0.0
        rt.setValue("Cell 0:Cell 1 Non-Nucleus Ratio", t-1, nonNucleusRatio)

        nnnRatio0 = nucleusValues0[t] / nonNucleusValues0[t] if nucleusValues0[t]>0 and nonNucleusValues0[t]>0 else 0.0
        rt.setValue("Cell 0 Nucleus:Non-Nucleus Ratio", t-1, nnnRatio0)
        nnnRatio1 = nucleusValues1[t] / nonNucleusValues1[t] if nucleusValues1[t]>0 and nonNucleusValues1[t]>0 else 0.0
        rt.setValue("Cell 1 Nucleus:Non-Nucleus Ratio", t-1, nnnRatio1)

        rt.setValue("Cell 0 (red) Area ("+cal.getUnit()+u"\u00b2"+")", t-1, cellAreas0[t])
        rt.setValue("Cell 0 Nucleus Area ("+cal.getUnit()+u"\u00b2"+")", t-1, nucleusAreas0[t])
        rt.setValue("Cell 0 All", t-1, cellValues0[t])
        rt.setValue("Cell 0 Nucleus", t-1, nucleusValues0[t])
        rt.setValue("Cell 0 Non-Nucleus", t-1, nonNucleusValues0[t])
        rt.setValue("Cell 1 (green) Area ("+cal.getUnit()+u"\u00b2"+")", t-1, cellAreas1[t])
        rt.setValue("Cell 1 Nucleus Area ("+cal.getUnit()+u"\u00b2"+")", t-1, nucleusAreas1[t])
        rt.setValue("Cell 1 All", t-1, cellValues1[t])
        rt.setValue("Cell 1 Nucleus", t-1, nucleusValues1[t])
        rt.setValue("Cell 1 Non-Nucleus", t-1, nonNucleusValues1[t])
    rt.show(imp.getTitle()+"-Results")

    dataset = DefaultXYDataset()
    dataset.addSeries( "Cell 0", [time[1:], cellValues0[1:]] )
    dataset.addSeries( "Cell 1", [time[1:], cellValues1[1:]] )
    dataset.addSeries( "Nucleus 0", [time[1:], nucleusValues0[1:]] )
    dataset.addSeries( "Nucleus 1", [time[1:], nucleusValues1[1:]] )
    dataset.addSeries( "Non-Nucleus 0", [time[1:], nonNucleusValues0[1:]] )
    dataset.addSeries( "Non-Nucleus 1", [time[1:], nonNucleusValues1[1:]] )

    chart = ChartFactory.createScatterPlot( imp.getTitle(), "Time ("+cal.getTimeUnit()+")", "Intensity Z", dataset, PlotOrientation.VERTICAL, True,True,False )
    plot = chart.getPlot()

    plot.setBackgroundPaint(Color(64, 128, 255))
    plot.setDomainGridlinePaint(Color.BLACK)
    plot.setRangeGridlinePaint(Color.BLACK)

    renderer = plot.getRenderer()
    legend = LegendItemCollection()
    shapeR = 2.0
    nucShape = Ellipse2D.Float(-shapeR,-shapeR,shapeR*2,shapeR*2)
    nonNucShape = Path2D.Float()
    nonNucShape.moveTo(-shapeR,-shapeR)
    nonNucShape.lineTo(shapeR,shapeR)
    nonNucShape.moveTo(shapeR,-shapeR)
    nonNucShape.lineTo(-shapeR,shapeR)
    for s in range(dataset.getSeriesCount()):

        if s == 0:
            renderer.setSeriesLinesVisible(s, True)
            renderer.setSeriesShapesVisible(s, False)
            renderer.setSeriesStroke(s, BasicStroke(1))
            renderer.setSeriesPaint(s, Color.RED)
            legend.add( LegendItem("Cell 0", Color.RED) )
        elif s == 1:
            renderer.setSeriesLinesVisible(s, True)
            renderer.setSeriesShapesVisible(s, False)
            renderer.setSeriesStroke(s, BasicStroke(1))
            renderer.setSeriesPaint(s, Color.GREEN)
            legend.add( LegendItem("Cell 1", Color.GREEN) )
        elif s == 2:
            renderer.setSeriesLinesVisible(s, False)
            renderer.setSeriesShapesVisible(s, True)
            renderer.setSeriesShape(s, nucShape)
            renderer.setSeriesPaint(s, Color.RED)
        elif s == 3:
            renderer.setSeriesLinesVisible(s, False)
            renderer.setSeriesShapesVisible(s, True)
            renderer.setSeriesShape(s, nucShape)
            renderer.setSeriesPaint(s, Color.GREEN)
        elif s == 4:
            renderer.setSeriesLinesVisible(s, False)
            renderer.setSeriesShapesVisible(s, True)
            renderer.setSeriesShape(s, nonNucShape)
            renderer.setSeriesPaint(s, Color.RED)
        elif s == 5:
            renderer.setSeriesLinesVisible(s, False)
            renderer.setSeriesShapesVisible(s, True)
            renderer.setSeriesShape(s, nonNucShape)
            renderer.setSeriesPaint(s, Color.GREEN)


    plot.setFixedLegendItems(legend)

    frame = ChartFrame(imp.getTitle()+" Z-Normalised Intensity", chart)
    frame.pack()
    frame.setSize( Dimension(800, 800) )
    frame.setLocationRelativeTo(None)
    frame.setVisible(True)
Example #26
0

_linkDragSource = ObjectDndHandler.DragSource(LinkSubjectDrag,
                                              _dragSourceCreateLink)

_controlsStyle = StyleSheet.style(Controls.bClosePopupOnActivate(True))
_projectIndexNameStyle = StyleSheet.style(
    Primitive.foreground(Color(0.25, 0.35, 0.5)), Primitive.fontSize(16),
    Primitive.fontFace(Primitive.lightFontName))
_packageNameStyle = StyleSheet.style(
    Primitive.foreground(Color(0.0, 0.0, 0.5)), Primitive.fontSize(14),
    Primitive.fontFace(Primitive.lightFontName))
_itemHoverHighlightStyle = StyleSheet.style(
    Primitive.hoverBackground(
        FilledOutlinePainter(Color(0.8, 0.825, 0.9),
                             Color(0.125, 0.341, 0.574), BasicStroke(1.0))))
_pythonPackageNameStyle = StyleSheet.style(
    Primitive.foreground(Color(0.0, 0.0, 0.5)))
_pythonPackageNameNotSetStyle = StyleSheet.style(
    Primitive.foreground(Color(0.5, 0.0, 0.0)))
_pythonPackageNameNotSetCommentStyle = StyleSheet.style(
    Primitive.foreground(Color(0.2, 0.2, 0.2)), Primitive.fontItalic(True))

_frontPageNoteBorder = SolidBorder(1.0, 1.0, 3.0, 3.0, Color(0.0, 1.0, 0.0),
                                   Color(0.85, 0.95, 0.85))
_frontPageNoteStyle = StyleSheet.style(
    Primitive.foreground(Color(0.0, 0.5, 0.0)), Primitive.fontSize(10))
_startupPageNoteBorder = SolidBorder(1.0, 1.0, 3.0, 3.0, Color(0.75, 0.5, 1.0),
                                     Color(0.925, 0.9, 0.95))
_startupPageNoteStyle = StyleSheet.style(
    Primitive.foreground(Color(0.25, 0.0, 0.5)), Primitive.fontSize(10))