def _get_geom(bem_model, mri_trans, head_trans): surf_names = ['cortex', 'skull', 'scalp'][::-1] # meshes = [] for surf_name, surf in zip(surf_names, bem_model): surf = _convert_bem_surf(surf, mri_trans, head_trans) points, faces, normals = surf['rr'], surf['tris'], surf['nn'] write_tri('%s.tri' % surf_name, points, swap_faces(faces), normals) # mesh = om.Mesh('%s.tri' % surf_name) # mesh = om.Mesh(np.asfortranarray(points), # np.asfortranarray(swap_faces(faces)).astype(np.int64)) # mesh.update() # mesh.setName(surf_name) # meshes.append(mesh) # cortex, skull, scalp = meshes[::-1] cortex = om.Mesh("cortex.tri") cortex.setName("cortex") skull = om.Mesh("skull.tri") skull.setName("skull") scalp = om.Mesh("scalp.tri") scalp.setName("scalp") # cortex = om.Mesh("cortex.1.tri") # cortex.setName("cortex") # skull = om.Mesh("skull.1.tri") # skull.setName("skull") # scalp = om.Mesh("scalp.1.tri") # scalp.setName("scalp") # geom_fname = 'model.geom' # cond_fname = 'model.cond' conductivity = [s['sigma'] for s in bem_model] interfaces = { "interface1": [(cortex, om.OrientedMesh.Normal)], "interface2": [(skull, om.OrientedMesh.Normal)], "interface3": [(scalp, om.OrientedMesh.Normal)] } domains = { "Scalp": ([('interface2', om.SimpleDomain.Outside), ('interface3', om.SimpleDomain.Inside)], conductivity[0]), "Brain": ([('interface1', om.SimpleDomain.Inside)], conductivity[2]), "Air": ([('interface3', om.SimpleDomain.Outside)], 0.0), "Skull": ([('interface2', om.SimpleDomain.Inside), ('interface1', om.SimpleDomain.Outside)], conductivity[1]) } geom = om.make_geometry(interfaces, domains) return geom
def python_mesh(name, path): mesh = om.Mesh(path) mesh_vertices = mesh.geometry().vertices() vertices = np.array([vertex.array() for vertex in mesh_vertices]) mesh_triangles = mesh.triangles() triangles = np.array( [mesh.triangle(triangle).array() for triangle in mesh_triangles]) return vertices, triangles
def test_mesh(name, vertices, triangles, expected_result): try: mesh = om.Mesh(vertices, triangles) mesh.info() except: if expected_result: print("Test", name, "--> Failed") assert False else: print("Test", name, "--> Expected failure") return if not expected_result: print("Test", name, "--> Unexpected success") assert False print("Test", name, "--> Expected success")
def create_om_sources(self): #TODO: Prob. should make file names specifiable """ Take a TVB Connectivity or Cortex object and return an OpenMEEG object that specifies sources, a Matrix object for region level sources or a Mesh object for a cortical surface source. """ if isinstance(self.sources, connectivity_module.Connectivity): sources_file = self._tvb_connectivity_to_txt("sources.txt") om_sources = om.Matrix() elif isinstance(self.sources, Cortex): sources_file = self._tvb_surface_to_tri("sources.tri") om_sources = om.Mesh() else: LOG.error("sources must be either a Connectivity or Cortex.") om_sources.load(sources_file) return om_sources
############################################################################### # Load data subject = 'Head1' cond_file = op.join(data_path, subject, subject + '.cond') geom_file = op.join(data_path, subject, subject + '.geom') source_mesh_file = op.join(data_path, subject, subject + '.tri') dipole_file = op.join(data_path, subject, subject + '.dip') squidsFile = op.join(data_path, subject, subject + '.squids') patches_file = op.join(data_path, subject, subject + '.patches') geom = om.Geometry() geom.read(geom_file, cond_file) mesh = om.Mesh() mesh.load(source_mesh_file) dipoles = om.Matrix() dipoles.load(dipole_file) sensors = om.Sensors() sensors.load(squidsFile) patches = om.Sensors() patches.load(patches_file) ############################################################################### # Compute forward problem (Build Gain Matrices) gauss_order = 3
options, args = parser.parse_args() data_path = options.data_path # Load data subject = "Head1" cond_file = op.join(data_path, subject, subject + ".cond") geom_file = op.join(data_path, subject, subject + ".geom") source_mesh_file = op.join(data_path, subject, subject + ".tri") dipole_file = op.join(data_path, subject, subject + ".dip") squidsFile = op.join(data_path, subject, subject + ".squids") patches_file = op.join(data_path, subject, subject + ".patches") geom = om.Geometry(geom_file, cond_file) mesh = om.Mesh(source_mesh_file) dipoles = om.Matrix() dipoles.load(dipole_file) sensors = om.Sensors() sensors.load(squidsFile) patches = om.Sensors() patches.load(patches_file) # Compute forward problem (Build Gain Matrices) gauss_order = 3 use_adaptive_integration = True dipole_in_cortex = True
bad_vertices = np.array([0.0, 0.0]) test_mesh("6", bad_vertices, triangles, False) bad_triangles = np.array([1, 2, 3]) test_mesh("7", vertices, bad_triangles, False) triangles = np.array([[1, 2, 3], [2, 3, 0]], dtype=np.uint64) test_mesh("8", vertices, triangles, True) triangles = np.array([[1, 2, 3], [2, 3, 0]], dtype=np.int64) test_mesh("9", vertices, triangles, True) # test X -> should be OK # TODO: Does not work if not jls.... data_file = path.join(data_path, "Head1", "Head1.tri") mesh_X = om.Mesh() mesh_X.load(data_file) mesh_X.update() # test Y -> redo with np.array() V_Y = mesh_X.vertices() # T6 = mesh_6.triangles() # mesh_7 = om.Mesh(V6, T6) # mesh_7.info() # TODO # # mesh_6.nb_vertices() == mesh_7.nb_vertices() # mesh_6.nb_triangles() == mesh_7.nb_triangles() # V7 = mesh_6.vertices() # T7 = mesh_6.triangles()
#!/usr/bin/env python import numpy as np import openmeeg as om vertices = np.array([[0.0, 0.0, 0.0], [1.0, 0.0, 0.0], [1.0, 1.0, 0.0], [0.0, 1.0, 0.0]]) triangles = np.array([[1, 2, 3], [2, 3, 0]]) mesh = om.Mesh(vertices, triangles) g = om.Geometry() assert g.check(mesh) g.import_meshes([mesh]) assert not g.check(mesh)
#!/usr/bin/env python import numpy as np import openmeeg as om vertices = np.array([[0.0, 0.0, 0.0], [1.0, 0.0, 0.0], [1.0, 1.0, 0.0], [0.0, 1.0, 0.0]]) triangles = np.array([[1, 2, 3], [2, 3, 0]]) g = om.Geometry() mesh = om.Mesh(vertices, triangles, "test", g) assert mesh.geometry().check(mesh)
[0.5501, 0.2101, -0.34, -0.808998, -0.309019, 0.50003], [0.5501, -0.2101, -0.34, -0.808998, 0.309019, 0.50003], [0.2101, 0.34, -0.5501, -0.309019, -0.50003, 0.808998], [-0.2101, 0.34, -0.5501, 0.309019, -0.50003, 0.808998], [0, 0, -0.68, 0, 0, 1], [-0.2101, -0.34, -0.5501, 0.309019, 0.50003, 0.808998], [0.2101, -0.34, -0.5501, -0.309019, 0.50003, 0.808998], [0.34, -0.5501, -0.2101, -0.50003, 0.808998, 0.309019], [0, -0.68, 0, 0, 1, 0], [0.34, -0.5501, 0.2101, -0.50003, 0.808998, -0.309019], [-0.34, -0.5501, -0.2101, 0.50003, 0.808998, 0.309019], [-0.34, -0.5501, 0.2101, 0.50003, 0.808998, -0.309019], [-0.5501, -0.2101, 0.34, 0.808998, 0.309019, -0.50003], [-0.2101, -0.34, 0.5501, 0.309019, 0.50003, -0.808998], [0.2101, -0.34, 0.5501, -0.309019, 0.50003, -0.808998], [0.68, 0, 0, 1, 0, 0], [-0.5501, -0.2101, -0.34, 0.808998, 0.309019, 0.50003], [-0.5501, 0.2101, -0.34, 0.808998, -0.309019, 0.50003], ]) I = np.array([[1, 3, 4], [2, 4, 5], [10, 3, 5], [21, 4, 5]]) mesh_1 = om.Mesh(V, I) mesh_1.info() # TODO: mesh.read() using numpy arrays # TODO: mesh == [ double ] , [ int ] # mesh = om.Mesh() # mesh.load( fileskel + "tri") # TODO: V = [...] # TODO: I = [...] # TODO: mesh_1 = om.Mesh(V, I)