Ejemplo n.º 1
0
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)
Ejemplo n.º 2
0
 def test_domainmeshing_with_borders(self):
     surface = SVMTK.Surface()
     surface.make_cube(0.0,0.0,0.0,1.0,1.0,1.0,1)
     domain = SVMTK.Domain(surface)
     domain.add_sharp_border_edges(surface)
     domain.create_mesh(1.)
     self.assertTrue(domain.number_of_curves() > 0) 
Ejemplo n.º 3
0
 def test_two_domains(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) 
     domain = SVMTK.Domain([surface_1,surface_2])
     self.assertEqual(domain.number_of_surfaces(),2)
Ejemplo n.º 4
0
   def test_domain_with_polyline_meshing(self):
       surface = SVMTK.Surface();
       surface.make_sphere(0.0,0.0,0.0,3.0,1.0)
       domain = SVMTK.Domain(surface)
 
       line0 = [SVMTK.Point_3(0,0,0.0), SVMTK.Point_3(0,1.0,1.0)] 
       domain.add_feature( line0)
       domain.create_mesh(1.)
       self.assertTrue(domain.number_of_curves() >0) 
Ejemplo n.º 5
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) 
Ejemplo n.º 6
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) 
Ejemplo n.º 7
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)
Ejemplo n.º 8
0
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)
Ejemplo n.º 9
0
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()
    domain.create_mesh(N) 
    domain.remove_subdomain([3]) 
    domain.save("brain_%d.mesh" % N)
    t1 = time.time()
    print("Done! That took %g sec" % (t1-t0))
Ejemplo n.º 10
0
 def test_mesh_perturb(self):
     surface_1 = SVMTK.Surface() 
     surface_1.make_cube(-1.,-1.,-1.,1.,1.,1.,1) 
     domain = SVMTK.Domain(surface_1)
     domain.create_mesh(1)
     domain.perturb() 
Ejemplo n.º 11
0
 def test_mesh_excude(self):
     surface_1 = SVMTK.Surface() 
     surface_1.make_cube(-1.,-1.,-1.,1.,1.,1.,1) 
     domain = SVMTK.Domain(surface_1)
     domain.create_mesh(1)
     domain.exude() 
Ejemplo n.º 12
0
 def test_mesh_lloyd(self):
     surface_1 = SVMTK.Surface() 
     surface_1.make_cube(-1.,-1.,-1.,1.,1.,1.,1) 
     domain = SVMTK.Domain(surface_1)
     domain.create_mesh(1)
     domain.lloyd()        
Ejemplo n.º 13
0
 def test_single_domain(self):
     surface_1 = SVMTK.Surface() 
     surface_1.make_cube(-1.,-1.,-1.,1.,1.,1.,1) 
     domain = SVMTK.Domain(surface_1) 
     self.assertEqual(domain.number_of_surfaces(),1)
Ejemplo n.º 14
0
 def test_domain_meshing(self):
     surface_1 = SVMTK.Surface() 
     surface_1.make_cube(-1.,-1.,-1.,1.,1.,1.,1) 
     domain = SVMTK.Domain(surface_1)
     domain.create_mesh(1)
     self.assertTrue(domain.number_of_cells() >0) 
import SVMTK as svm


def chair_function(x, y, z):
    x2 = x * x
    y2 = y * y
    z2 = z * z
    x4 = x2 * x2
    y4 = y2 * y2
    z4 = z2 * z2
    return x4 - 1.2 * x2 * y2 + 3.6 * x2 * z2 - 7.50 * x2 + y4 + 3.6 * y2 * z2 - 7.50 * y2 + .2 * z4 - 7.50 * z2 + 64.0625 - 16.0 * z * y2 + 16.0 * x2 * z


if __name__ == "__main__":

    surf = svm.Surface()

    surf.implicit_surface(chair_function, 6.0, 30, 0.1, 0.1)

    surf.save("chair.off")

    maker = svm.Domain(surf)

    maker.create_mesh(20)

    maker.save("chair.mesh")