Example #1
0
    def Rich_MS_Copy(self):
        from ooflib.common import color
        OOF.Image.AutoGroup(image="5color:5color")
        self.selectInteriorYellowPoint(operator=Select())
        OOF.Microstructure.Copy(microstructure="5color", name="copy")

        # Make sure that the groups were copied correctly.  This is
        # just like running the AutoGroup test in the copied
        # Microstructure.
        ms = microstructure.getMicrostructure("copy")
        groups = ms.groupNames()
        self.assertEqual(len(groups), 5)
        for groupname in groups:
            for colorname, gname in color_values.items():
                if gname == groupname:
                    self.assertEqual(len(ms.findGroup(groupname)),
                                     color_counts[colorname])
                    break
            else:
                self.fail("Got an unexpected group name: " + groupname)

        # Selection should *not* be copied.
        ps = pixelselection.pixelselectionWhoClass["copy"]
        self.assertEqual(ps.getObject().len(), 0)
        OOF.Microstructure.Delete(microstructure="copy")
Example #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])
Example #3
0
 def TrivialClippedVolume(self):
     ms = microstructure.getMicrostructure('microstructure')
     skel = skeletoncontext.getSkeleton(ms, "skeleton").getObject()
     for plane in planes:
         v0 = skel.clipVSBVol(0, plane)
         v1 = skel.clipVSBVol(0, plane.reversed())
         self.assertAlmostEqual(v0 + v1, 64.)
Example #4
0
def _newactivearea(menuitem, microstructure, name):
    ms_obj = ms_module.getMicrostructure(microstructure)
    new_aa = activearea.ActiveArea(ms_obj.sizeInPixels(), ms_obj.size(),
                                   ms_obj)
    new_aa.rename(name)
    ms_obj.namedActiveAreas.append(new_aa)
    switchboard.notify('stored active areas changed', name)
Example #5
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])
Example #6
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])
Example #7
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])
Example #8
0
 def Copy(self):
     self.select_pixels()
     OOF.ActiveArea.Activate_Selection_Only(microstructure="active")
     OOF.Microstructure.Copy(microstructure="active", name="copy")
     cms = microstructure.getMicrostructure("copy")
     # Initially-copied MS has default active area.
     self.assertEqual(len(cms.activearea.getSelection()), 0)
     OOF.ActiveArea.Copy(microstructure="copy", source="active")
     OOF.ActiveArea.Activate_All(microstructure="active")
     self.assertEqual(len(cms.activearea.getSelection()), 20500)
Example #9
0
 def Copy(self):
     self.select_pixels()
     OOF.ActiveArea.Activate_Selection_Only(microstructure="active")
     OOF.Microstructure.Copy(microstructure="active", name="copy")
     cms = microstructure.getMicrostructure("copy")
     # Initially-copied MS has default active area.
     self.assertEqual(len(cms.activearea.getSelection()), 0)
     OOF.ActiveArea.Copy(microstructure="copy", source="active")
     OOF.ActiveArea.Activate_All(microstructure="active")
     self.assertEqual(len(cms.activearea.getSelection()), 20500)
Example #10
0
 def AddSelection(self):
     OOF.PixelGroup.New(name="test", microstructure="5color")
     ms = microstructure.getMicrostructure("5color")
     OOF.VoxelSelection.Select(source="5color:5color",
                               method=PointSelector(point=iPoint(1, 2, 3),
                                                    operator=Select()))
     OOF.PixelGroup.AddSelection(microstructure="5color", group="test")
     sel_size = self.selectionSize()
     OOF.VoxelSelection.Clear(microstructure="5color")
     group = ms.findGroup("test")
     self.assertEqual(len(group), sel_size)
Example #11
0
    def All2x2x2(self):
        ms = microstructure.getMicrostructure('microstructure')
        skel = skeletoncontext.getSkeleton(ms, "skeleton").getObject()
        # The non-trivial combinations of voxels correspond to voxel
        # signatures between 1 and 255.  Signature 0 has no voxels in
        # it, and would be equivalent to the Trivial test, above.
        sigs = range(1, 256)
        for sig in sigs:
            nvox = self.selectSig(sig)
            sigstr = voxelsetboundary.printSig(sig)
            print "Selected voxels:", sigstr, "(sig=%d)" % sig
            self.assertEqual(nvox, self.selectionSize())

            OOF.PixelGroup.AddSelection(microstructure='microstructure',
                                        group='pixelgroup')
            self.assertEqual(ms.nCategories(), 2)  # triggers categorization

            unselectedCat = ms.category(Point(0, 0, 0))
            selectedCat = 1 - unselectedCat
            print "selectedCat=", selectedCat, "unselectedCat=",\
                unselectedCat

            skel.dumpVSB(selectedCat, "selected.dat")
            skel.dumpVSB(unselectedCat, "unselected.dat")
            # ms.dumpVSBLines(selectedCat, "selected_"+sigstr+".lines")
            # ms.dumpVSBLines(unselectedCat, "unselected_"+sigstr+".lines")

            selectedVol = ms.volumeOfCategory(selectedCat)
            unselectedVol = ms.volumeOfCategory(unselectedCat)
            print "selectedVol=", selectedVol, \
                "unselectedVol=", unselectedVol
            print "Checking connectivity for selected voxels, category",\
                selectedCat
            self.assert_(skel.checkVSB(selectedCat))
            print "Checking connectivity for unselected voxels, category",\
                unselectedCat
            self.assert_(skel.checkVSB(unselectedCat))
            self.assertAlmostEqual(selectedVol, nvox)
            self.assertAlmostEqual(unselectedVol, 64 - nvox)
            # Check that the saved VSB graphs are correct
            sigstr = sigstr.replace('|', '-')
            self.assert_(
                file_utils.fp_file_compare(
                    "selected.dat",
                    os.path.join("vsb_data", "selected_" + sigstr + ".dat"),
                    1.e-9))
            self.assert_(
                file_utils.fp_file_compare(
                    "unselected.dat",
                    os.path.join("vsb_data", "unselected_" + sigstr + ".dat"),
                    1.e-9))
            print "-------"
            file_utils.remove("selected.dat")
            file_utils.remove("unselected.dat")
Example #12
0
 def setUp(self):
     global microstructure
     from ooflib.common import microstructure
     from ooflib.common.IO import gfxmanager
     OOF.Microstructure.Create_From_ImageFile(
         filename=os.path.join("ms_data","5color","slice*.tif"),
         microstructure_name="active",
         height=20.0, width=20.0, depth=20.0)
     OOF.Image.AutoGroup(image="active:slice*.tif")
     OOF.Windows.Graphics.New()
     self.ms = microstructure.getMicrostructure("active")
Example #13
0
    def ClippedShape(self):
        # Check that a few carefully selected sets of voxels are
        # clipped properly by a single plane
        sigs = (
            vox000,
            vox111,
            vox000 | vox100,
            vox000 | vox110,
            vox010 | vox100,
            vox000 | vox100 | vox010 | vox111,
        )
        ms = microstructure.getMicrostructure('microstructure')
        skel = skeletoncontext.getSkeleton(ms, "skeleton").getObject()
        for sig in sigs:
            sigstr = voxelsetboundary.printSig(sig)
            print "Selecting voxels", sigstr
            sigstr = sigstr.replace('|', '-')
            nvox = self.selectSig(sig)
            OOF.PixelGroup.AddSelection(microstructure='microstructure',
                                        group='pixelgroup')
            unselectedCat = ms.category(Point(0, 0, 0))
            selectedCat = 1 - unselectedCat
            for i, plane in enumerate(planes):
                # saveClippedVSB writes filename.dat and filename.lines
                skel.saveClippedVSB(selectedCat, plane, 'selected')
                skel.saveClippedVSB(unselectedCat, plane, 'unselected')

                fnamebase = "clipped_%s_p%02d" % (sigstr, i)
                self.assert_(
                    file_utils.fp_file_compare(
                        'selected.dat',
                        os.path.join("vsb_data", 's' + fnamebase + '.dat'),
                        1.e-9))
                self.assert_(
                    file_utils.fp_file_compare(
                        'unselected.dat',
                        os.path.join("vsb_data", 'u' + fnamebase + '.dat'),
                        1.e-9))
                self.assert_(
                    file_utils.fp_file_compare(
                        'selected.lines',
                        os.path.join("vsb_data", 's' + fnamebase + '.lines'),
                        1.e-9))
                self.assert_(
                    file_utils.fp_file_compare(
                        'unselected.lines',
                        os.path.join("vsb_data", 'u' + fnamebase + '.lines'),
                        1.e-9))

                file_utils.remove('selected.dat')
                file_utils.remove('unselected.dat')
                file_utils.remove('selected.lines')
                file_utils.remove('unselected.lines')
Example #14
0
 def AutoGroup(self):
     OOF.Image.AutoGroup(image="5color:5color")
     ms = microstructure.getMicrostructure("5color")
     groups = ms.groupNames()
     self.assertEqual(len(groups), 5)
     for groupname in groups:
         for colorname, gname in color_values.items():
             if gname == groupname:
                 self.assertEqual(len(ms.findGroup(groupname)),
                                  color_counts[colorname])
             break
         else:
             self.fail("Got an unexpected group name: " + groupname)
Example #15
0
 def setUp(self):
     global microstructure
     from ooflib.common import microstructure
     from ooflib.common.IO import gfxmanager
     OOF.Microstructure.Create_From_ImageFile(filename=os.path.join(
         "ms_data", "5color", "slice*.tif"),
                                              microstructure_name="active",
                                              height=20.0,
                                              width=20.0,
                                              depth=20.0)
     OOF.Image.AutoGroup(image="active:slice*.tif")
     OOF.Windows.Graphics.New()
     self.ms = microstructure.getMicrostructure("active")
Example #16
0
 def Copy(self):
     ms = microstructure.getMicrostructure("5color")
     OOF.PixelGroup.New(name="test", microstructure="5color")
     self.select1()
     OOF.PixelGroup.AddSelection(microstructure="5color", group="test")
     group = ms.findGroup("test")
     initial_group_size = len(group)
     OOF.PixelGroup.Copy(microstructure="5color",
                         group="test",
                         name="testcopy")
     OOF.PixelGroup.Delete(microstructure="5color", group="test")
     self.assertEqual(ms.nGroups(), 1)
     group = ms.findGroup("testcopy")
     self.assertEqual(len(group), initial_group_size)
Example #17
0
 def AddSelection(self):
     OOF.PixelGroup.New(name="test", microstructure="small.ppm")
     ms = microstructure.getMicrostructure("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.PixelGroup.AddSelection(microstructure="small.ppm", group="test")
     ps = pixelselection.pixelselectionWhoClass['small.ppm']
     sel_size = ps.getObject().len()
     OOF.Graphics_1.Toolbox.Pixel_Select.Clear(source="small.ppm:small.ppm")
     group = ms.findGroup("test")
     self.assertEqual(len(group), sel_size)
Example #18
0
 def setUp(self):
     global materialmanager
     from ooflib.engine import materialmanager
     self.mat_manager = materialmanager.materialmanager
     global material
     from ooflib.SWIG.engine import material
     global microstructure
     from ooflib.common import microstructure
     OOF.Microstructure.Create_From_ImageFile(
         filename=os.path.join("ms_data","5color","slice*.tif"),
         microstructure_name="mat_test", height=20.0,
         width=20.0, depth=20.0)
     OOF.Image.AutoGroup(image="mat_test:slice*.tif")
     self.ms = microstructure.getMicrostructure("mat_test")
Example #19
0
 def Rename(self):
     ms = microstructure.getMicrostructure("5color")
     OOF.PixelGroup.New(name="test", microstructure="5color")
     self.select1()
     OOF.PixelGroup.AddSelection(microstructure="5color", group="test")
     group = ms.findGroup("test")
     initial_group_size = len(group)
     OOF.PixelGroup.Rename(microstructure="5color",
                           group="test",
                           new_name="testrename")
     group = ms.findGroup("testrename")
     self.assertEqual(len(group), initial_group_size)
     # Still only one group.
     self.assertEqual(ms.nGroups(), 1)
     self.assert_(not "test" in ms.groupNames())
Example #20
0
 def AddSelection(self):
     OOF.PixelGroup.New(name="test", microstructure="slice*.tif")
     ms = microstructure.getMicrostructure("slice*.tif")
     OOF.Graphics_1.Toolbox.Pixel_Select.Point(
         source="slice*.tif:slice*.tif",
         points=[Point(15.0, 15.0, 15.0)],
         shift=0,
         ctrl=0)
     OOF.PixelGroup.AddSelection(microstructure="slice*.tif", group="test")
     ps = pixelselection.pixelselectionWhoClass['slice*.tif']
     sel_size = ps.getObject().len()
     OOF.Graphics_1.Toolbox.Pixel_Select.Clear(
         source="slice*.tif:slice*.tif")
     group = ms.findGroup("test")
     self.assertEqual(len(group), sel_size)
Example #21
0
 def AddSelection(self):
     OOF.PixelGroup.New(name="test", microstructure="small.ppm")
     ms = microstructure.getMicrostructure("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.PixelGroup.AddSelection(
         microstructure="small.ppm", group="test")
     ps = pixelselection.pixelselectionWhoClass['small.ppm']
     sel_size = ps.getObject().len()
     OOF.Graphics_1.Toolbox.Pixel_Select.Clear(
         source="small.ppm:small.ppm")
     group = ms.findGroup("test")
     self.assertEqual(len(group), sel_size)
Example #22
0
 def AddSelection(self):
     OOF.PixelGroup.New(name="test", microstructure="slice*.tif")
     ms = microstructure.getMicrostructure("slice*.tif")
     OOF.Graphics_1.Toolbox.Pixel_Select.Point(
         source="slice*.tif:slice*.tif",
         points=[Point(15.0,15.0,15.0)],
         shift=0,ctrl=0)
     OOF.PixelGroup.AddSelection(
         microstructure="slice*.tif", group="test")
     ps = pixelselection.pixelselectionWhoClass['slice*.tif']
     sel_size = ps.getObject().len()
     OOF.Graphics_1.Toolbox.Pixel_Select.Clear(
         source="slice*.tif:slice*.tif")
     group = ms.findGroup("test")
     self.assertEqual(len(group), sel_size)
Example #23
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")
Example #24
0
 def setUp(self):
     global materialmanager
     from ooflib.engine import materialmanager
     self.mat_manager = materialmanager.materialmanager
     global material
     from ooflib.SWIG.engine import material
     global microstructure
     from ooflib.common import microstructure
     OOF.Microstructure.Create_From_ImageFile(
         filename=os.path.join("ms_data", "5color", "slice*.tif"),
         microstructure_name="mat_test",
         height=20.0,
         width=20.0,
         depth=20.0)
     OOF.Image.AutoGroup(image="mat_test:slice*.tif")
     self.ms = microstructure.getMicrostructure("mat_test")
Example #25
0
 def Copy(self):
     ms = microstructure.getMicrostructure("small.ppm")
     OOF.PixelGroup.New(name="test", microstructure="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.PixelGroup.AddSelection(
         microstructure="small.ppm", group="test")
     group = ms.findGroup("test")
     initial_group_size = len(group)
     OOF.PixelGroup.Copy(microstructure="small.ppm",
                         group="test", name="testcopy")
     OOF.PixelGroup.Delete(microstructure="small.ppm", group="test")
     self.assertEqual(ms.nGroups(), 1)
     group = ms.findGroup("testcopy")
     self.assertEqual(len(group), initial_group_size) 
Example #26
0
 def Copy(self):
     ms = microstructure.getMicrostructure("slice*.tif")
     OOF.PixelGroup.New(name="test", microstructure="slice*.tif")
     OOF.Graphics_1.Toolbox.Pixel_Select.Point(
         source="slice*.tif:slice*.tif",
         points=[Point(15.0,15.0,15.0)],
         shift=0,ctrl=0)
     OOF.PixelGroup.AddSelection(
         microstructure="slice*.tif", group="test")
     group = ms.findGroup("test")
     initial_group_size = len(group)
     OOF.PixelGroup.Copy(microstructure="slice*.tif",
                         group="test", name="testcopy")
     OOF.PixelGroup.Delete(microstructure="slice*.tif", group="test")
     self.assertEqual(ms.nGroups(), 1)
     group = ms.findGroup("testcopy")
     self.assertEqual(len(group), initial_group_size) 
Example #27
0
 def Copy(self):
     ms = microstructure.getMicrostructure("small.ppm")
     OOF.PixelGroup.New(name="test", microstructure="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.PixelGroup.AddSelection(
         microstructure="small.ppm", group="test")
     group = ms.findGroup("test")
     initial_group_size = len(group)
     OOF.PixelGroup.Copy(microstructure="small.ppm",
                         group="test", name="testcopy")
     OOF.PixelGroup.Delete(microstructure="small.ppm", group="test")
     self.assertEqual(ms.nGroups(), 1)
     group = ms.findGroup("testcopy")
     self.assertEqual(len(group), initial_group_size) 
Example #28
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")
Example #29
0
 def Copy(self):
     ms = microstructure.getMicrostructure("slice*.tif")
     OOF.PixelGroup.New(name="test", microstructure="slice*.tif")
     OOF.Graphics_1.Toolbox.Pixel_Select.Point(
         source="slice*.tif:slice*.tif",
         points=[Point(15.0, 15.0, 15.0)],
         shift=0,
         ctrl=0)
     OOF.PixelGroup.AddSelection(microstructure="slice*.tif", group="test")
     group = ms.findGroup("test")
     initial_group_size = len(group)
     OOF.PixelGroup.Copy(microstructure="slice*.tif",
                         group="test",
                         name="testcopy")
     OOF.PixelGroup.Delete(microstructure="slice*.tif", group="test")
     self.assertEqual(ms.nGroups(), 1)
     group = ms.findGroup("testcopy")
     self.assertEqual(len(group), initial_group_size)
Example #30
0
 def Rename(self):
     ms = microstructure.getMicrostructure("small.ppm")
     OOF.PixelGroup.New(name="test", microstructure="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.PixelGroup.AddSelection(
         microstructure="small.ppm", group="test")
     group = ms.findGroup("test")
     initial_group_size = len(group)
     OOF.PixelGroup.Rename(microstructure="small.ppm",
                           group="test", new_name="testrename")
     group = ms.findGroup("testrename")
     self.assertEqual(len(group), initial_group_size)
     # Still only one group.
     self.assertEqual(ms.nGroups(), 1)
     self.assert_( not "test" in ms.groupNames())
Example #31
0
 def Rename(self):
     ms = microstructure.getMicrostructure("small.ppm")
     OOF.PixelGroup.New(name="test", microstructure="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.PixelGroup.AddSelection(
         microstructure="small.ppm", group="test")
     group = ms.findGroup("test")
     initial_group_size = len(group)
     OOF.PixelGroup.Rename(microstructure="small.ppm",
                           group="test", new_name="testrename")
     group = ms.findGroup("testrename")
     self.assertEqual(len(group), initial_group_size)
     # Still only one group.
     self.assertEqual(ms.nGroups(), 1)
     self.assert_( not "test" in ms.groupNames())
Example #32
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)
Example #33
0
    def RemoveSelection(self):
        OOF.PixelGroup.New(name="test", microstructure="5color")
        ms = microstructure.getMicrostructure("5color")
        # Select a lot of pixels
        OOF.VoxelSelection.Select(source='5color:5color',
                                  method=ColorSelector(point=iPoint(10, 15, 2),
                                                       range=DeltaRGB(
                                                           delta_red=0.3,
                                                           delta_green=0.3,
                                                           delta_blue=0.3),
                                                       operator=Select()))
        sel_large = self.selectionSize()
        OOF.PixelGroup.AddSelection(microstructure="5color", group="test")
        self.select1()

        sel_small = self.selectionSize()
        OOF.PixelGroup.RemoveSelection(microstructure="5color", group="test")
        OOF.VoxelSelection.Clear(microstructure="5color")
        group = ms.findGroup("test")
        self.assertEqual(len(group), sel_large - sel_small)
Example #34
0
def _namedactivearea(menuitem, microstructure, category, active_areas):
    # Get the pixels for this category, and add all the active areas
    # associated with this category to each pixel.
    ms_obj = ms_module.getMicrostructure(microstructure)
    pxls = microstructureIO.getCategoryPixels(microstructure, category)

    px_dict = {}

    for name in active_areas:
        px_dict[name] = []

    for p in pxls:
        aal = activearea.areaListFromPixel(ms_obj, p)
        for name in active_areas:
            aal.add(name)
            px_dict[name].append(p)

    for name in active_areas:
        aa = ms_obj.getNamedActiveArea(name)
        aa.activearea.add_pixels(px_dict[name])
Example #35
0
def _namedactivearea(menuitem, microstructure, category, active_areas):
    # Get the pixels for this category, and add all the active areas
    # associated with this category to each pixel.
    ms_obj = ms_module.getMicrostructure(microstructure)
    pxls = microstructureIO.getCategoryPixels(microstructure, category)

    px_dict = {}

    for name in active_areas:
        px_dict[name] = []

    for p in pxls:
        aal = activearea.areaListFromPixel(ms_obj, p)
        for name in active_areas:
            aal.add(name)
            px_dict[name].append(p)

    for name in active_areas:
        aa = ms_obj.getNamedActiveArea(name)
        aa.activearea.add_pixels(px_dict[name])
    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)
Example #37
0
 def ClippedVolume(self):
     ms = microstructure.getMicrostructure('microstructure')
     skel = skeletoncontext.getSkeleton(ms, "skeleton").getObject()
     sigs = range(1, 256)
     #sigs = (105,)
     for sig in sigs:
         print "voxels=%s" % voxelsetboundary.printSig(sig)
         nvox = self.selectSig(sig)
         OOF.PixelGroup.AddSelection(microstructure='microstructure',
                                     group='pixelgroup')
         unselectedCat = ms.category(Point(0, 0, 0))
         selectedCat = 1 - unselectedCat
         for plane in planes:
             print "plane=%s" % plane
             v00 = skel.clipVSBVol(selectedCat, plane)
             v10 = skel.clipVSBVol(unselectedCat, plane)
             opposite = plane.reversed()
             v01 = skel.clipVSBVol(selectedCat, opposite)
             v11 = skel.clipVSBVol(unselectedCat, opposite)
             self.assertAlmostEqual(nvox, v00 + v01)
             self.assertAlmostEqual(64 - nvox, v10 + v11)
             self.assertAlmostEqual(v00 + v01 + v10 + v11, 64)
Example #38
0
 def ms(self):
     # We can't just set a data member self.ms in setUp, because it
     # would hold a reference to the microstructure and would make
     # the memorychecks fail.
     return microstructure.getMicrostructure("active")
Example #39
0
 def Trivial(self):
     ms = microstructure.getMicrostructure("microstructure")
     self.assertEqual(ms.nCategories(), 1)
     vol = ms.volumeOfCategory(0)
     self.assertEqual(vol, 64)
Example #40
0
 def Delete(self):
     OOF.PixelGroup.New(name="test", microstructure="small.ppm")
     ms = microstructure.getMicrostructure("small.ppm")
     OOF.PixelGroup.Delete(microstructure="small.ppm", group="test")
     groups = ms.groupNames()
     self.assertEqual(len(groups),0)
Example #41
0
 def New(self):
     OOF.PixelGroup.New(name="test", microstructure="small.ppm")
     ms = microstructure.getMicrostructure("small.ppm")
     groups = ms.groupNames()
     self.assertEqual(len(groups),1)
     self.assert_("test" in groups)
Example #42
0
 def ms(self):
     # setUp used to set self.ms to the microstructure.  Making
     # self.ms a function prevents the Unittest object from holding
     # a reference to the microstructure, which would mess up the
     # memorycheck tests.
     return microstructure.getMicrostructure("mat_test")
Example #43
0
def _newactivearea(menuitem, microstructure, name):
    ms_obj = ms_module.getMicrostructure(microstructure)
    new_aa = activearea.ActiveArea(ms_obj.sizeInPixels(), ms_obj.size(), ms_obj)
    ms_obj.namedActiveAreas.append(activearea.NamedActiveArea(name, new_aa))
    switchboard.notify("stored active areas changed", name)
Example #44
0
 def ms(self):
     # We can't just set a data member self.ms in setUp, because it
     # would hold a reference to the microstructure and would make
     # the memorychecks fail.
     return microstructure.getMicrostructure("active")
Example #45
0
 def New(self):
     OOF.PixelGroup.New(name="test", microstructure="small.ppm")
     ms = microstructure.getMicrostructure("small.ppm")
     groups = ms.groupNames()
     self.assertEqual(len(groups),1)
     self.assert_("test" in groups)
Example #46
0
 def Delete(self):
     OOF.PixelGroup.New(name="test", microstructure="small.ppm")
     ms = microstructure.getMicrostructure("small.ppm")
     OOF.PixelGroup.Delete(microstructure="small.ppm", group="test")
     groups = ms.groupNames()
     self.assertEqual(len(groups),0)
Example #47
0
 def ms(self):
     # setUp used to set self.ms to the microstructure.  Making
     # self.ms a function prevents the Unittest object from holding
     # a reference to the microstructure, which would mess up the
     # memorycheck tests.
     return microstructure.getMicrostructure("mat_test")
Example #48
0
 def getMS(self):
     return microstructure.getMicrostructure("active")