code: def matrix_to_marching_cubes(matrix, pitch, origin):
      
      from skimage import measure
      from .base import Trimesh
  
      matrix = np.asanyarray(matrix, dtype=np.bool)
  
      rev_matrix = np.logical_not(matrix)  # Takes set about 0.
      # Add in padding so marching cubes can function properly with
      # voxels on edge of AABB
      pad_width = 1
      rev_matrix = np.pad(rev_matrix,
                          pad_width=(pad_width),
                          mode='constant',
                          constant_values=(1))
  
      # pick between old and new API
      if hasattr(measure, 'marching_cubes_lewiner'):
          func = measure.marching_cubes_lewiner
      else:
          func = measure.marching_cubes
  
      # Run marching cubes.
      meshed = func(volume=rev_matrix,
                    level=.5,  # it is a boolean voxel grid
                    spacing=(pitch,
                             pitch,
                             pitch))
  
      # allow results from either marching cubes function in skimage
      # binaries available for python 3.3 and 3.4 appear to use the classic
      # method
      if len(meshed) == 2:
          log.warning('using old marching cubes, may not be watertight!')
          vertices, faces = meshed
          normals = None
      elif len(meshed) == 4:
          vertices, faces, normals, vals = meshed
  
      # Return to the origin, add in the pad_width
      vertices = np.subtract(np.add(vertices, origin), pad_width * pitch)
      # create the mesh
      mesh = Trimesh(vertices=vertices,
                     faces=faces,
                     vertex_normals=normals)
      return mesh
docs: Convert an (n,m,p) matrix into a mesh, using marching_cubes.
  
      Parameters
      -----------
      matrix: (n,m,p) bool, voxel matrix
      pitch: float, what pitch was the voxel matrix computed with
      origin: (3,) float, what is the origin of the voxel matrix
  
      Returns
      ----------
      mesh: Trimesh object, generated by meshing voxels using
                            the marching cubes algorithm in skimage