parameters: (volume, colorarray=None)
return_statement: return Mesh(vertices, faces, colors)
docstring: Create a mesh from a voxel grid/volume.
  
          :param volume: volume
          :type volume: numpy.ndarray
          :param colorarray: color info preserved in voxelization step
          :type colorarray: numpy.ndarray
          :return: mesh
          :rtype: Mesh
docstring_summary: Create a mesh from a voxel grid/volume.
docstring_tokens: Create a mesh from a voxel grid / volume .
function: def from_volume(volume, colorarray=None):
          """
          Create a mesh from a voxel grid/volume.
  
          :param volume: volume
          :type volume: numpy.ndarray
          :param colorarray: color info preserved in voxelization step
          :type colorarray: numpy.ndarray
          :return: mesh
          :rtype: Mesh
          """
  
          vertices = []
          faces = []
          colors = []
  
          xx, yy, zz = np.where(volume > 0.5)
          face_ids = volume[:][np.where(volume > 0.5)]
          face_ids = face_ids.astype('int32')
          if type(colorarray) != None.__class__:
              num_faces = len(colorarray) #number of inital mesh faces should be equal to the color array length
              face_ids[face_ids == num_faces] = 0 #set changed face 0 back to zero
  
          for i in range(len(xx)):
              v000 = (yy[i], xx[i], zz[i])                # 0
              v001 = (yy[i], xx[i], zz[i] + 1)            # 1
              v010 = (yy[i], xx[i] + 1, zz[i])            # 2
              v011 = (yy[i], xx[i] + 1, zz[i] + 1)        # 3
              v100 = (yy[i] + 1, xx[i], zz[i])            # 4
              v101 = (yy[i] + 1, xx[i], zz[i] + 1)        # 5
              v110 = (yy[i] + 1, xx[i] + 1, zz[i])        # 6
              v111 = (yy[i] + 1, xx[i] + 1, zz[i] + 1)    # 7
  
              n = len(vertices)
              f1 = [n + 0, n + 2, n + 4]
              f2 = [n + 4, n + 2, n + 6]
              f3 = [n + 1, n + 3, n + 5]
              f4 = [n + 5, n + 3, n + 7]
              f5 = [n + 0, n + 1, n + 2]
              f6 = [n + 1, n + 3, n + 2]
              f7 = [n + 4, n + 5, n + 7]
              f8 = [n + 4, n + 7, n + 6]
              f9 = [n + 4, n + 0, n + 1]
              f10 = [n + 4, n + 5, n + 1]
              f11 = [n + 2, n + 3, n + 6]
              f12 = [n + 3, n + 7, n + 6]
  
              vertices.append(v000)
              vertices.append(v001)
              vertices.append(v010)
              vertices.append(v011)
              vertices.append(v100)
              vertices.append(v101)
              vertices.append(v110)
              vertices.append(v111)
  
              faces.append(f1)
              faces.append(f2)
              faces.append(f3)
              faces.append(f4)
              faces.append(f5)
              faces.append(f6)
              faces.append(f7)
              faces.append(f8)
              faces.append(f9)
              faces.append(f10)
              faces.append(f11)
              faces.append(f12)
              
              if type(colorarray) != None.__class__:
                  c = colorarray[face_ids[i]]
                  for i in range(12): #apply same color for all 12 triangles of the cube
                      colors.append(c)
              
          return Mesh(vertices, faces, colors)
function_tokens: def from_volume ( volume , colorarray = None ) : vertices = [ ] faces = [ ] colors = [ ] xx , yy , zz = np . where ( volume > 0.5 ) face_ids = volume [ : ] [ np . where ( volume > 0.5 ) ] face_ids = face_ids . astype ( 'int32' ) if type ( colorarray ) != None . __class__ : num_faces = len ( colorarray ) #number of inital mesh faces should be equal to the color array length face_ids [ face_ids == num_faces ] = 0 #set changed face 0 back to zero for i in range ( len ( xx ) ) : v000 = ( yy [ i ] , xx [ i ] , zz [ i ] ) # 0 v001 = ( yy [ i ] , xx [ i ] , zz [ i ] + 1 ) # 1 v010 = ( yy [ i ] , xx [ i ] + 1 , zz [ i ] ) # 2 v011 = ( yy [ i ] , xx [ i ] + 1 , zz [ i ] + 1 ) # 3 v100 = ( yy [ i ] + 1 , xx [ i ] , zz [ i ] ) # 4 v101 = ( yy [ i ] + 1 , xx [ i ] , zz [ i ] + 1 ) # 5 v110 = ( yy [ i ] + 1 , xx [ i ] + 1 , zz [ i ] ) # 6 v111 = ( yy [ i ] + 1 , xx [ i ] + 1 , zz [ i ] + 1 ) # 7 n = len ( vertices ) f1 = [ n + 0 , n + 2 , n + 4 ] f2 = [ n + 4 , n + 2 , n + 6 ] f3 = [ n + 1 , n + 3 , n + 5 ] f4 = [ n + 5 , n + 3 , n + 7 ] f5 = [ n + 0 , n + 1 , n + 2 ] f6 = [ n + 1 , n + 3 , n + 2 ] f7 = [ n + 4 , n + 5 , n + 7 ] f8 = [ n + 4 , n + 7 , n + 6 ] f9 = [ n + 4 , n + 0 , n + 1 ] f10 = [ n + 4 , n + 5 , n + 1 ] f11 = [ n + 2 , n + 3 , n + 6 ] f12 = [ n + 3 , n + 7 , n + 6 ] vertices . append ( v000 ) vertices . append ( v001 ) vertices . append ( v010 ) vertices . append ( v011 ) vertices . append ( v100 ) vertices . append ( v101 ) vertices . append ( v110 ) vertices . append ( v111 ) faces . append ( f1 ) faces . append ( f2 ) faces . append ( f3 ) faces . append ( f4 ) faces . append ( f5 ) faces . append ( f6 ) faces . append ( f7 ) faces . append ( f8 ) faces . append ( f9 ) faces . append ( f10 ) faces . append ( f11 ) faces . append ( f12 ) if type ( colorarray ) != None . __class__ : c = colorarray [ face_ids [ i ] ] for i in range ( 12 ) : #apply same color for all 12 triangles of the cube colors . append ( c ) return Mesh ( vertices , faces , colors )