Exemplo n.º 1
0
    def __call__(self,x):
        lowdx = int(math.floor(x*float(self.listlen-1)))

        if lowdx<=0:
            return color.RGBColor(self.redlist[0],
                                  self.greenlist[0],
                                  self.bluelist[0])

        if lowdx>=(self.listlen-1):
            return color.RGBColor(self.redlist[-1], 
                                  self.greenlist[-1],
                                  self.bluelist[-1])
        frac = x*self.listlen-lowdx
        
        rl = self.redlist[lowdx]
        rh = self.redlist[lowdx+1]

        gl = self.greenlist[lowdx]
        gh = self.greenlist[lowdx+1]
        
        bl = self.bluelist[lowdx]
        bh = self.bluelist[lowdx+1]

        return color.RGBColor(rl+frac*(rh-rl), 
                              gl+frac*(gh-gl),
                              bl+frac*(bh-bl))
Exemplo n.º 2
0
    def AutoGroup(self):
        from ooflib.common import color
        def colordiff(c1,c2):
            return (c1.red-c2.red)**2 + \
                   (c1.green-c2.green)**2 + \
                   (c1.blue-c2.blue)**2
        # Dictionary of nearest pure colors and sizes of the
        # corresponding groups, which will not have exactly this
        # color, but will be closer to it than to any other color (in
        # colordiff measure).
        expected_sizes = {color.magenta : 2404,
                          color.RGBColor(1.0,1.0,1.0) : 4781,
                          color.RGBColor(0.0,0.0,0.0) : 2585,
                          color.blue : 2947,
                          color.green : 4795,
                          color.cyan : 1001,
                          color.yellow : 3617,
                          color.red : 370 }

        OOF.Image.AutoGroup(image="small.ppm:small.ppm")
        ms = microstructure.getMicrostructure("small.ppm")
        groups = ms.groupNames()
        self.assertEqual(len(groups), 8)
        for name in groups:
#             rgb = eval(name)
            rgb = color.rgb_from_hex(name)
            key = None
            diff = None
            for c in expected_sizes.keys():
                cdiff = colordiff(rgb,c)
                if (diff is None) or (cdiff < diff):
                    key = c
                    diff = cdiff
            self.assertEqual(len(ms.findGroup(name)), expected_sizes[key])
Exemplo n.º 3
0
    def Rich_MS_Copy(self):
        from ooflib.common import color
        OOF.Image.AutoGroup(image="small.ppm:small.ppm")
        OOF.Graphics_1.Toolbox.Pixel_Select.Circle(
            source="small.ppm:small.ppm",
            points=[Point(66.0, 55.0), Point(87.6, 41.8)],
            shift=0,
            ctrl=0)
        OOF.Microstructure.Copy(microstructure="small.ppm", name="copy")

        # Essentially a re-run of the autogroup test.
        def colordiff(c1, c2):
            return (c1.red-c2.red)**2 + \
                   (c1.green-c2.green)**2 + \
                   (c1.blue-c2.blue)**2

        # Dictionary of nearest pure colors and sizes of the
        # corresponding groups, which will not have exactly this
        # color, but will be closer to it than to any other color (in
        # colordiff measure).
        expected_sizes = {
            color.magenta: 2404,
            color.RGBColor(1.0, 1.0, 1.0): 4781,
            color.RGBColor(0.0, 0.0, 0.0): 2585,
            color.blue: 2947,
            color.green: 4795,
            color.cyan: 1001,
            color.yellow: 3617,
            color.red: 370
        }
        ms = microstructure.getMicrostructure("copy")
        groups = ms.groupNames()
        self.assertEqual(len(groups), 8)
        for name in groups:
            #            rgb = eval(name)
            rgb = color.rgb_from_hex(name)
            key = None
            diff = None
            for c in expected_sizes.keys():
                cdiff = colordiff(rgb, c)
                if (diff is None) or (cdiff < diff):
                    key = c
                    diff = cdiff
            self.assertEqual(len(ms.findGroup(name)), expected_sizes[key])
        ps = pixelselection.pixelselectionWhoClass["copy"]
        # Selection should *not* be copied.
        self.assertEqual(ps.getObject().len(), 0)
        OOF.Microstructure.Delete(microstructure="copy")
Exemplo n.º 4
0
    def AutoGroup(self):
        from ooflib.common import color

        def colordiff(c1, c2):
            return (c1.red-c2.red)**2 + \
                   (c1.green-c2.green)**2 + \
                   (c1.blue-c2.blue)**2

        # Dictionary of nearest pure colors and sizes of the
        # corresponding groups, which will not have exactly this
        # color, but will be closer to it than to any other color (in
        # colordiff measure).
        expected_sizes = {
            color.RGBColor(1.0, 1.0, 1.0): 2385,
            color.blue: 1205,
            color.green: 1020,
            color.yellow: 2313,
            color.red: 1077
        }

        OOF.Image.AutoGroup(image="slice*.tif:slice*.tif")
        ms = microstructure.getMicrostructure("slice*.tif")
        groups = ms.groupNames()
        self.assertEqual(len(groups), 5)
        for name in groups:
            rgb = eval(name)
            key = None
            diff = None
            for c in expected_sizes.keys():
                cdiff = colordiff(rgb, c)
                if (diff is None) or (cdiff < diff):
                    key = c
                    diff = cdiff
            self.assertEqual(len(ms.findGroup(name)), expected_sizes[key])
Exemplo n.º 5
0
 def Load(self):
     OOF.Microstructure.New(name="load_test",
                            width=100,
                            height=100,
                            depth=100,
                            width_in_pixels=100,
                            height_in_pixels=100,
                            depth_in_pixels=100)
     OOF.File.Load.Image(filenames=ThreeDImageDirectory(
         directory=reference_file("ms_data",
                                  "jpeg"), sort=NumericalOrder()),
                         microstructure="load_test",
                         height=automatic,
                         width=automatic,
                         depth=automatic)
     ms = getMicrostructure("load_test")
     ms_images = ms.imageNames()
     self.assertEqual(len(ms_images), 1)
     self.assert_("jpeg" in ms_images)
     # Check a few pixel values
     im = imagecontext.imageContexts['load_test:jpeg'].getObject()
     self.assertEqual(
         im[primitives.iPoint(0, 0, 0)],
         color.RGBColor(0.054901960784313725, 0.996078431372549,
                        0.9921568627450981))
     self.assertNotEqual(im[primitives.iPoint(0, 0, 0)],
                         color.RGBColor(0.054901960, 0.0, 0.99215686))
     # This voxel is selected in Direct_Pixel_Selection.Color in
     # pixel_test.py on Mac but not Linux.  Apparently Mac and
     # Linux use different jpeg libraries which decompress images
     # differently. WTF?
     ## TODO: Check that problem is avoided if vtk on Mac is
     ## compiled with USE_SYSTEM_JPEG=OFF
     self.assertEqual(
         im[primitives.iPoint(16, 9, 99)],
         # Linux value
         color.RGBColor(0.3058823529411765, 0.9921568627450981,
                        0.7215686274509804)
         # Mac value
         # color.RGBColor(
         #     0.2901960784313726,
         #     1.0,
         #     0.7372549019607844)
     )
Exemplo n.º 6
0
    def Rich_Load(self):
        OOF.File.Load.Data(filename=reference_file("ms_data", "rich_ms"))
        ms = microstructure.getMicrostructure("rich")
        group = ms.findGroup("test")
        self.assertEqual(len(group), 2000)

        colorgroups = ms.groupNames()
        colorgroups.remove("test")

        from ooflib.common import color

        def colordiff(c1, c2):
            return (c1.red-c2.red)**2 + \
                   (c1.green-c2.green)**2 + \
                   (c1.blue-c2.blue)**2

        # This is a reprise of the AutoGroup test in pixel_test.
        expected_sizes = {
            color.magenta: 2404,
            color.RGBColor(1.0, 1.0, 1.0): 4781,
            color.RGBColor(0.0, 0.0, 0.0): 2585,
            color.blue: 2947,
            color.green: 4795,
            color.cyan: 1001,
            color.yellow: 3617,
            color.red: 370
        }

        for name in colorgroups:
            rgb = color.rgb_from_hex(name)
            key = None
            diff = None
            for c in expected_sizes.keys():
                cdiff = colordiff(rgb, c)
                if (diff is None) or (cdiff < diff):
                    key = c
                    diff = cdiff
            self.assertEqual(len(ms.findGroup(name)), expected_sizes[key])

        # Find the "act1" stored active area, and check the size.
        act1 = ms.getNamedActiveArea("act1")
        self.assertEqual(len(act1.activearea.members()), 19872)
Exemplo n.º 7
0
    def __getitem__(self, idx):
##         num_components = self.image.GetNumberOfScalarComponents()
##         if num_components == 1:
##             return color.Gray(self.image.GetScalarComponentAsFloat(idx[0],idx[1],idx[2],0)/255)
##         elif num_components == 3 or num_components == 4:

        # Don't return the alpha channel since we just use it for
        # manipulating the visualization of materials, selected
        # regions, active areas, etc.
        return color.RGBColor(
            self.image.GetScalarComponentAsFloat(idx[0],idx[1],idx[2],0)/255,
            self.image.GetScalarComponentAsFloat(idx[0],idx[1],idx[2],1)/255,
            self.image.GetScalarComponentAsFloat(idx[0],idx[1],idx[2],2)/255)
Exemplo n.º 8
0
        self.size = size
        display.DisplayMethod.__init__(self)

    def draw(self, gfxwindow, device):
        skel = self.who().resolve(gfxwindow)
        device.set_lineColor(self.color)
        device.set_lineWidth(self.size)
        for node in skel.pinnednodes.retrieve():
            device.draw_dot(node.position())

    def getTimeStamp(self, gfxwindow):
        return max(self.timestamp,
                   self.who().resolve(gfxwindow).pinnednodes.timestamp)


defaultPinNodeColor = color.RGBColor(0.93, 0.93, 0.0)
defaultPinNodeSize = 2


def _setPinNodeParams(menuitem, color, size):
    global defaultPinNodeColor
    global defaultPinNodeSize
    defaultPinNodeColor = color
    defaultPinNodeSize = size


pinnodeparams = [
    color.ColorParameter('color',
                         defaultPinNodeColor,
                         tip="Color for the pinned nodes."),
    parameter.IntRangeParameter('size', (0, 10),
Exemplo n.º 9
0
        if obj is not None:
            return self.getObject().getBounds()


##################

pixelselectionWhoClass = whoville.WhoDoUndoClass(
    'Pixel Selection',
    instanceClass=PixelSelectionContext,
    ordering=999,
    secret=0,
    proxyClasses=['<top microstructure>'])

###################

defaultPixelSelectionColor = color.RGBColor(1.0, 0.22, 0.09)
defaultTintOpacity = 0.9


def _setDefaultPixelSelectionParams(menuitem, color, tintOpacity):
    global defaultPixelSelectionColor
    global defaultTintOpacity
    defaultPixelSelectionColor = color
    defaultTintOpacity = tintopacity


colorparams = [
    color.ColorParameter('color',
                         defaultPixelSelectionColor,
                         tip='Color of selected pixels.'),
    parameter.FloatRangeParameter('tintOpacity', (0., 1., 0.01),
Exemplo n.º 10
0
        if toolbox.querier and toolbox.peeker:
            return max(self.timestamp, gfxwindow.displayTimeChanged,
                       toolbox.querier.getTimeStamp(),
                       toolbox.peeker.getTimeStamp())
        elif toolbox.querier and not toolbox.peeker:
            return max(self.timestamp, gfxwindow.displayTimeChanged,
                       toolbox.querier.getTimeStamp())
        else:
            return self.timestamp


# This object should be created via the registration, and not
# directly via the initializer, because the registration creation
# method gives it a timestamp.

defaultQueryColor = color.RGBColor(0.0, 0.5, 1.0)
defaultPeekColor = color.RGBColor(1.0, 0.5, 0.5)
defaultNodeSize = 3
defaultElementWidth = 2
if config.dimension() == 2:
    widthRange = (0, 10)
# In vtk, line widths of 0 cause errors
elif config.dimension() == 3:
    widthRange = (1, 10)


def _setMeshInfoParams(menuitem, query_color, peek_color, node_size,
                       element_width):
    global defaultQueryColor
    global defaultPeekColor
    global defaultNodeSize
Exemplo n.º 11
0
            ms.drawVoxelSetBoundary(self.canvaslayer, self.category)

    def whoChanged(self):
        return True  # call setParams


if debug.debug:
    registeredclass.Registration(
        "VoxelSetBdy",
        display.DisplayMethod,
        VoxelSetBdyDisplay,
        ordering=1000,
        layerordering=display.Linear,
        params=[
            parameter.IntParameter("category", 0),
            color.ColorParameter('color', color.RGBColor(0, 0.7, 0.3)),
            parameter.IntRangeParameter('line_width', (1, 10), 4)
        ],
        whoclasses=('Microstructure', ),
        tip="Display boundary loops of voxel categories")

# class Normal(enum.EnumClass("Positive", "Negative", "Any")):
#     pass

# class Direction(enum.EnumClass("X", "Y", "Z", "All")):
#     pass

# dirDict = {Direction("X") : 0,
#            Direction("Y") : 1,
#            Direction("Z") : 2,
#            Direction("All") : -1}
Exemplo n.º 12
0
                else:
                    sublayer.clear()

    def meshDataChangedCB(self, meshctxt):
        if meshctxt is self.who().resolve(self.gfxwindow):
            self.queryCB()
            toolbox = self.gfxwindow.getToolboxByName("Mesh_Info")
            for mode in toolbox.allPeekModes():
                self.peekCB(mode)


# This object should be created via the registration, and not
# directly via the initializer, because the registration creation
# method gives it a timestamp.

defaultQueryColor = color.RGBColor(0.0, 0.4, 0.85)
defaultPeekColor = color.RGBColor(0.9, 0.5, 0.5)
if config.dimension() == 2:
    widthRange = (0, 10)
    defaultNodeSize = 3
    defaultLineWidth = 2
elif config.dimension() == 3:
    widthRange = (1, 20)  # In vtk, line widths of 0 cause errors
    defaultNodeSize = 10
    defaultLineWidth = 4


def _setMeshInfoParams(menuitem, query_color, peek_color, node_size,
                       line_width):
    global defaultQueryColor
    global defaultPeekColor
Exemplo n.º 13
0
        display.DisplayMethod.__init__(self)

    def draw(self, gfxwindow, device):
        toolbox = gfxwindow.getToolboxByName("Move_Nodes")
        node = toolbox.selectednode.node()
        if node and toolbox.selectednode.visible:
            device.set_lineColor(self.color)
            device.set_lineWidth(self.size)
            device.draw_dot(node.position())

    def getTimeStamp(self, gfxwindow):
        toolbox = gfxwindow.getToolboxByName("Move_Nodes")
        return max(self.timestamp, toolbox.selectednode.getTimeStamp())


defaultMoveNodeColor = color.RGBColor(1.0, 0.5, 0.5)
defaultMoveNodeSize = 3


def _setDefaultMoveNodeParams(menuitem, color, size):
    global defaultMoveNodeSize
    global defaultMoveNodeColor
    defaultMoveNodeColor = color
    defaultMoveNodeSize = size


movenodeparams = [
    color.ColorParameter('color',
                         defaultMoveNodeColor,
                         tip="Color for the to-be-moved node."),
    parameter.IntRangeParameter('size', (0, 10),
Exemplo n.º 14
0
 def __call__(self, x):
     if x < 0.33:
         return color.RGBColor(x/0.33, 0, 0)
     if x < 0.67:
         return color.RGBColor(1, (x-0.33)/0.34, 0)
     return color.RGBColor(1, 1, (x-0.67)/0.33)
Exemplo n.º 15
0
 def __call__(self,x):
     return color.RGBColor(1.0, 0.86667*math.sqrt(x), 0.0)
Exemplo n.º 16
0
        ## LOCK in display.py
        cskeletonselectable.rebuildLayerCells(
            skelctxt.getObject(), self.canvaslayer,
            selection.currentSelectionTracker())

    def destroy(self, destroy_canvaslayer):
        map(switchboard.removeCallback, self.tbcallbacks)
        display.DisplayMethod.destroy(self, destroy_canvaslayer)


#=--=##=--=##=--=##=--=##=--=##=--=##=--=##=--=##=--=##=--=##=--=##=--=##=--=#

# The default opacity for selected elements is 1.0, because if it's
# less than that they (sometimes) don't show up when superimposed on
# an opaque image.
defaultSelectedElementColor = color.RGBColor(0.88, 0.14, 0.07)
defaultSelectedElementOpacity = 0.7


class SkeletonElementSelectionDisplay(SkeletonSelectionDisplay):
    def __init__(self, color, opacity):
        self.color = color
        self.opacity = opacity
        SkeletonSelectionDisplay.__init__(
            self, skeletonselmodebase.getMode("Element"))

    def newLayer(self):
        self.setupSignals()
        return canvaslayers.SimpleFilledCellLayer(self.gfxwindow.oofcanvas,
                                                  "SkeletonSelectedElement")
Exemplo n.º 17
0
                    gridPoints = skel.getObject().getPoints()
                    grid = vtk.vtkUnstructuredGrid()
                    grid.Allocate(numsegs, numsegs)
                    grid.SetPoints(gridPoints)
                    for s in skel.segmentselection.retrieve():
                        line = s.getVtkLine()
                        grid.InsertNextCell(line.GetCellType(),
                                            line.GetPointIds())
                    device.draw_unstructuredgrid(grid)

    def getTimeStamp(self, gfxwindow):
        return max(self.timestamp,
                   self.who().resolve(gfxwindow).segmentselection.timestamp)


defaultSegSelColor = color.RGBColor(0.13, 0.93, 0.25)
defaultSegSelWidth = 2


def _setSegSelParams(menuitme, color, line_width):
    global defaultSegSelColor
    global defaultSegSelWidth
    defaultSegSelColor = color
    defaultSegSelWidth = line_width


segselparams = [
    color.ColorParameter('color',
                         defaultSegSelColor,
                         tip="Color for the selected segments."),
    parameter.IntRangeParameter('line_width', (0, 10),
Exemplo n.º 18
0
    def drawNode(self, device, node, which="query"):
        device.set_lineColor(self.colors[which])
        device.set_lineWidth(self.node_size)
        device.draw_dot(node.position())

    def getTimeStamp(self, gfxwindow):
        toolbox = gfxwindow.getToolboxByName("Skeleton_Info")
        return max(self.timestamp, toolbox.timestamp)


# This object should be created via the registration, and not
# directly via the initializer, because the registration creation
# method gives it a timestamp.

defaultSkelInfoQueryColor = color.RGBColor(0.0, 0.5, 1.0)
defaultSkelInfoPeekColor = color.RGBColor(1.0, 0.5, 0.5)
defaultSkelInfoNodeSize = 3
defaultSkelInfoElemWidth = 3
defaultSkelInfoSgmtWidth = 3
if config.dimension() == 2:
    widthRange = (0, 10)
# In vtk, line widths of 0 cause errors
elif config.dimension() == 3:
    widthRange = (1, 10)


def _setSkelInfoParams(menuitem, query_color, peek_color, node_size,
                       element_width, segment_width):
    global defaultSkelInfoQueryColor
    global defaultSkelInfoPeekColor
Exemplo n.º 19
0
            retr = skel.nodeselection.retrieve().copy()
            size = len(retr)
            for node in retr:
                device.draw_dot(node.position())


##            for n in range(size):
## debug.fmsg("during drawing dot")
##                device.draw_dot(retr[n].position())
## debug.fmsg("::after drawing dot")

    def getTimeStamp(self, gfxwindow):
        return max(self.timestamp,
                   self.who().resolve(gfxwindow).nodeselection.timestamp)

defaultNodeSelColor = color.RGBColor(0.07, 0.09, 0.96)
defaultNodeSelSize = 2


def _setNodeSelParams(menuitem, color, size):
    global defaultNodeSelColor
    global defaultNodeSelSize
    defaultNodeSelColor = color
    defaultNodeSelSize = size


nodeselparams = [
    color.ColorParameter('color',
                         defaultNodeSelColor,
                         tip="Color for the selected nodes."),
    parameter.IntRangeParameter('size', (0, 10),
Exemplo n.º 20
0
                                                e.getPointIds())
                        device.draw_filled_unstructuredgrid(grid)

            finally:
                skel.elementselection.end_reading()

    def getTimeStamp(self, gfxwindow):
        return max(self.timestamp,
                   self.who().resolve(gfxwindow).elementselection.timestamp)


# This object should be created via the registration, and not
# directly via the initializer, because the registration creation
# method gives it a timestamp.

defaultSelectedElementColor = color.RGBColor(0.88, 0.14, 0.07)
defaultSelectedElementOpacity = 0.6


def _setSelectedElementParams(menuitem, color, opacity):
    global defaultSelectedElementColor
    global defaultSelectedElementOpacity
    defaultSelectedElementColor = color
    defaultSelectedElementOpacity = opacity


selectedElementParams = [
    color.ColorParameter('color',
                         defaultSelectedElementColor,
                         tip="Color for the selected elements."),
    parameter.FloatRangeParameter('opacity', (0., 1., 0.01),
Exemplo n.º 21
0
        display.DisplayMethod,
        InterfaceElementDisplay,
        ordering=10,
        layerordering=display.SemiLinear,
        params=meshdispparams + [
            meshparameters.MeshEdgeBdyParameterExtra(
                'boundary',
                placeholder.every.IDstring,
                tip='Only display edges on this boundary or interface.'),
            materialparameter.InterfaceAnyMaterialParameter(
                'material',
                materialparameter.InterfaceAnyMaterialParameter.extranames[0],
                tip="Only display edges with this material assigned to them."),
            ## TODO: Add settable defaults
            color.ColorParameter('color',
                                 color.RGBColor(0.5, 0.3, 0.5),
                                 tip=parameter.emptyTipString),
            IntRangeParameter(
                'width', widthRange, defaultMeshWidth + 2, tip="Line width.")
        ],
        whoclasses=('Mesh', ),
        tip="Highlight the edgements (1-D elements) on the Mesh.")

######################


class MaterialDisplay:
    def draw(self, gfxwindow, device):
        device.comment("Material Color")
        if config.dimension() == 2:
            themesh = self.who().resolve(gfxwindow)
Exemplo n.º 22
0
            self.updatePinned(skelctxt)
        else:
            self.canvaslayer.clear()
        return True

    def updatePinned(self, skelctxt):
        cskeletonselectable.rebuildLayerCells(
            skelctxt.getObject(), self.canvaslayer,
            skelctxt.pinnednodes.currentSelectionTracker())

    def setParams(self):
        self.canvaslayer.set_color(self.color)
        self.canvaslayer.set_pointSize(self.size)


defaultPinNodeColor = color.RGBColor(1., 0.65, 0.0)
defaultPinNodeSize = 7


def _setPinNodeParams(menuitem, color, size):
    global defaultPinNodeColor
    global defaultPinNodeSize
    defaultPinNodeColor = color
    defaultPinNodeSize = size


pinnodeparams = [
    color.ColorParameter('color',
                         defaultPinNodeColor,
                         tip="Color for the pinned nodes."),
    parameter.IntRangeParameter('size', (0, 10),