def create_surface(self): """ Create a dummy surface entity. :return: (Algorithm Identifier, stored Surface entity) """ operation, algo_id, storage_path = self.__create_operation() surface = CorticalSurface(storage_path=storage_path) surface.vertices = numpy.array( [[-10, 0, 0], [0, 0, -10], [10, 0, 0], [0, 10, 0]], dtype=float) surface.triangles = numpy.array( [[0, 1, 2], [0, 1, 3], [1, 2, 3], [0, 2, 3]], dtype=int) surface.number_of_triangles = 4 surface.number_of_vertices = 4 surface.triangle_normals = numpy.ones((4, 3)) surface.vertex_normals = numpy.ones((4, 3)) surface.zero_based_triangles = True adapter_instance = StoreAdapter([surface]) OperationService().initiate_prelaunch(operation, adapter_instance, {}) return algo_id, surface
def create_surface(self): """ Create a dummy surface entity. :returns: (Algorithm Identifier, stored Surface entity) """ operation, algo_id, storage_path = self.__create_operation() surface = CorticalSurface(storage_path=storage_path) surface.vertices = numpy.array([[-10, 0, 0], [0, 0, -10], [10, 0, 0], [0, 10, 0]], dtype=float) surface.triangles = numpy.array([[0, 1, 2], [0, 1, 3], [1, 2, 3], [0, 2, 3]], dtype=int) surface.number_of_triangles = 4 surface.number_of_vertices = 4 surface.triangle_normals = numpy.ones((4, 3)) surface.vertex_normals = numpy.ones((4, 3)) surface.zero_based_triangles = True surface.validate() adapter_instance = StoreAdapter([surface]) OperationService().initiate_prelaunch(operation, adapter_instance, {}) return algo_id, surface
def launch(self, uploaded, surface_type, zero_based_triangles = False): """ Execute import operations: unpack ZIP and build Surface object as result. """ if uploaded is None: raise LaunchException ("Please select ZIP file which contains data to import") self.logger.debug("Start to import surface: '%s' from file: %s"%(surface_type, uploaded)) try: files = FilesHelper().unpack_zip(uploaded, self.storage_path) except IOError: exception_str = "Did not find the specified ZIP at %s" % uploaded raise LaunchException(exception_str) vertices = [] normals = [] triangles = [] for file_name in files: if file_name.lower().find(self.VERTICES_TOKEN) >= 0: vertices.append(file_name) continue if file_name.lower().find(self.NORMALS_TOKEN) >= 0: normals.append(file_name) continue if file_name.lower().find(self.TRIANGLES_TOKEN) >= 0: triangles.append(file_name) # Now detect and instantiate correct surface type self.logger.debug("Create surface instance") if surface_type == CORTICAL: surface = CorticalSurface() elif surface_type == INNER_SKULL: surface = BrainSkull() elif surface_type == OUTER_SKULL: surface = SkullSkin() elif surface_type == OUTER_SKIN: surface = SkinAir() elif surface_type == EEG_CAP: surface = EEGCap() elif surface_type == FACE: surface = FaceSurface() else: exception_str = "Could not determine surface type (selected option %s)" % surface_type raise LaunchException(exception_str) surface.storage_path = self.storage_path all_vertices, all_normals, all_triangles = self._process_files(vertices, normals, triangles) FilesHelper.remove_files(files, True) surface.zero_based_triangles = zero_based_triangles surface.vertices = all_vertices surface.vertex_normals = all_normals if zero_based_triangles: surface.triangles = all_triangles else : surface.triangles = all_triangles - 1 surface.triangle_normals = None # Now check if the triangles of the surface are valid triangles_min_vertex = numpy.amin(surface.triangles) if triangles_min_vertex < 0: if triangles_min_vertex == -1 and not zero_based_triangles: raise RuntimeError("Triangles contain a negative vertex index. Maybe you have a ZERO based surface.") else: raise RuntimeError("Your triangles contain a negative vertex index: %d" %triangles_min_vertex) no_of_vertices = len(surface.vertices) triangles_max_vertex = numpy.amax(surface.triangles) if triangles_max_vertex >= no_of_vertices: if triangles_max_vertex == no_of_vertices and zero_based_triangles: raise RuntimeError("Your triangles contain an invalid vertex index: %d. \ Maybe your surface is NOT ZERO Based."%triangles_max_vertex) else: raise RuntimeError("Your triangles contain an invalid vertex index: %d." %triangles_max_vertex) self.logger.debug("Surface ready to be stored") return surface