def create_gwv_mesh(pial_stl,
                    white_stl,
                    ventricles_stl,
                    output,
                    remove_ventricles=True):

    # Create SVMTk Surfaces from STL files
    pial = svmtk.Surface(pial_stl)
    white = svmtk.Surface(white_stl)
    ventricles = svmtk.Surface(ventricles_stl)
    surfaces = [pial, white, ventricles]

    # Define identifying tags for the different regions
    tags = {"pial": 1, "white": 2, "ventricle": 3}

    # Define the corresponding subdomain map
    smap = svmtk.SubdomainMap()
    smap.add("100", tags["pial"])
    smap.add("110", tags["white"])
    smap.add("111", tags["ventricle"])

    # Mesh and tag the domain from the surfaces and map
    domain = svmtk.Domain(surfaces, smap)
    resolution = 32
    domain.create_mesh(resolution)

    # Remove subdomain with right tag from the domain
    if remove_ventricles:
        domain.remove_subdomain(tags["ventricle"])

    # Save the mesh
    domain.save(output)
Exemple #2
0
 def test_mehsing_domains_with_map(self): 
     surface_1 = SVMTK.Surface() 
     surface_1.make_cube(-1.,-1.,-1.,1.,1.,1.,1) 
     surface_2 = SVMTK.Surface() 
     surface_2.make_cube(-2.,-2.,-2.,2.,2.,2.,1)
     sf= SVMTK.SubdomainMap()
     sf.add("01",3) 
     sf.add("11",2)        
     domain = SVMTK.Domain([surface_1,surface_2],sf)
     domain.create_mesh(1.) 
     self.assertTrue(domain.number_of_cells() >0) 
Exemple #3
0
 def test_get_boundary_and_patches(self): 
     surface_1 = SVMTK.Surface() 
     surface_1.make_cube(-1.,-1.,-1.,1.,1.,1.,1) 
     surface_2 = SVMTK.Surface() 
     surface_2.make_cube(-2.,-2.,-2.,2.,2.,2.,1)
     sf= SVMTK.SubdomainMap()
     sf.add("01",3) 
     sf.add("11",2)     
     domain = SVMTK.Domain([surface_1,surface_2],sf)
     domain.create_mesh(1.) 
     surface = domain.get_boundary(0) 
     self.assertTrue(surface.num_vertices()==77 and surface.num_faces()==137 and surface.num_edges()==219)
     surface = domain.get_boundary(1) 
     self.assertEqual(surface.num_vertices(), 0) 
     surface = domain.get_boundary(3) 
     self.assertTrue(surface.num_vertices()==128 and surface.num_faces()==235 and surface.num_edges()==366) 
     surfaces =  domain.get_boundaries()  
     print(len(surfaces))
     self.assertEqual(len(surfaces),2) 
Exemple #4
0
    def test_slice_subdomains(self):
        slice_ = SVMTK.Slice(SVMTK.Plane_3(0, 0, 1, 0))
        surface1 = SVMTK.Surface()
        surface1.make_cube(-1., -1., -1., 1., 1., 1., 1)
        surface2 = SVMTK.Surface()
        surface2.make_cube(-2., -2., -2., 2., 2., 2., 1)

        sf = SVMTK.SubdomainMap(0)
        sf.add("11", 2)
        sf.add("11", 2)
        slice_ = SVMTK.Slice(SVMTK.Plane_3(0, 0, 1, 0))
        slice_.slice_surfaces([surface1, surface2])

        slice_.create_mesh(1.)
        slice_.add_surface_domains([surface1, surface2])
        self.assertEqual(slice_.number_of_subdomains(), 2)
        slice_.add_surface_domains([surface1, surface2], sf)
        self.assertEqual(slice_.number_of_subdomains(), 1)
        slice_.remove_subdomains(2)
        self.assertEqual(slice_.number_of_subdomains(), 0)
Exemple #5
0
def create_gw_mesh(pial_stl, white_stl, output):
    # Load the surfaces into SVM-Tk and combine in list
    pial = svmtk.Surface(pial_stl)
    white = svmtk.Surface(white_stl)
    surfaces = [pial, white]

    # Create a map for the subdomains with tags
    # 1 for inside the first and outside the second ("10")
    # 2 for inside the first and inside the second ("11")
    smap = svmtk.SubdomainMap()
    smap.add("10", 1)
    smap.add("11", 2)

    # Create a tagged domain from the list of surfaces
    # and the map
    domain = svmtk.Domain(surfaces, smap)

    # Create and save the volume mesh
    resolution = 32
    domain.create_mesh(resolution)
    domain.save(output)
def create_brain_mesh(stls, output, resolution=32, remove_ventricles=True):

    # Load each of the Surfaces
    surfaces = [svmtk.Surface(stl) for stl in stls]

    # Take the union of the left (#3) and right (#4)
    # white surface and put the result into
    # the (former left) white surface
    surfaces[2].union(surfaces[3])

    # ... and drop the right white surface from the list
    surfaces.pop(3)

    # Define identifying tags for the different regions
    tags = {"pial": 1, "white": 2, "ventricle": 3}

    # Label the different regions
    smap = svmtk.SubdomainMap()
    smap.add("1000", tags["pial"])
    smap.add("0100", tags["pial"])
    smap.add("1010", tags["white"])
    smap.add("0110", tags["white"])
    smap.add("1110", tags["white"])
    smap.add("1011", tags["ventricle"])
    smap.add("0111", tags["ventricle"])
    smap.add("1111", tags["ventricle"])

    # Generate mesh at given resolution
    domain = svmtk.Domain(surfaces, smap)
    domain.create_mesh(resolution)

    # Remove ventricles perhaps
    if remove_ventricles:
        domain.remove_subdomain(tags["ventricle"])

    # Save mesh
    domain.save(output)
import SVMTK as svmtk
import time

# Import surfaces, and merge lh/rh white surfaces
ventricles  = svmtk.Surface("surfaces/lh.ventricles.stl") 
lhpial = svmtk.Surface("surfaces/lh.pial.stl") 
rhpial = svmtk.Surface("surfaces/rh.pial.stl")
white = svmtk.Surface("surfaces/lh.white.stl") 
rhwhite = svmtk.Surface("surfaces/rh.white.stl") 
white.union(rhwhite)

surfaces = [lhpial, rhpial, white, ventricles] 

# Create subdomain map
smap = svmtk.SubdomainMap() 
smap.add("1000", 1)
smap.add("0100", 1) 
smap.add("0110", 2)
smap.add("0010", 2)
smap.add("1010", 2)
smap.add("0111", 3)
smap.add("1011", 3)

# Create domain
domain = svmtk.Domain(surfaces, smap)

# Create meshes of increasing resolutions
Ns = [16, 32, 64, 128]
for N in Ns: 
    print("Creating mesh for N=%d" % N)
    t0 = time.time()