# Path: cloudvolume/exceptions.py
# class MeshDecodeError(ValueError):
#   """Unable to decode a mesh object."""
#   pass
# 
# Path: cloudvolume/lib.py
# def yellow(text):
#   return colorize('yellow', text)
# 
# class Vec(np.ndarray):
#     def __new__(cls, *args, **kwargs):
#       if 'dtype' in kwargs:
#         dtype = kwargs['dtype']
#       elif floating(args):
#         dtype = float
#       else:
#         dtype = int
# 
#       return super(Vec, cls).__new__(cls, shape=(len(args),), buffer=np.array(args).astype(dtype), dtype=dtype)
# 
#     @classmethod
#     def clamp(cls, val, minvec, maxvec):
#       x = np.minimum.reduce([
#         np.maximum.reduce([val,minvec]), 
#         maxvec
#       ])
#       return Vec(*x)
# 
#     def clone(self):
#       return Vec(*self[:], dtype=self.dtype)
# 
#     def null(self):
#         return self.length() <= 10 * np.finfo(np.float32).eps
# 
#     def dot(self, vec):
#       return sum(self * vec)
# 
#     def length2(self):
#         return self.dot(self)
# 
#     def length(self):
#         return math.sqrt(self.dot(self))
# 
#     def rectVolume(self):
#         return reduce(operator.mul, self)
# 
#     def __hash__(self):
#       return int(''.join(map(str, self)))
# 
#     def __repr__(self):
#       values = ",".join([ str(x) for x in self ])
#       return f"Vec({values}, dtype={self.dtype})"


import copy
import re
import struct
import numpy as np
    import DracoPy
      import vtk
from .exceptions import MeshDecodeError
from .lib import yellow, Vec
    eff_faces = face_vector_map(faces)
    eff_faces = np.unique(eff_faces, axis=0)

    # normal_vector_map = np.vectorize(lambda idx: normals[idx])
    # eff_normals = normal_vector_map(uniq_idx)

    return Mesh(eff_verts, eff_faces, None, 
      segid=self.segid,
      encoding_type=copy.deepcopy(self.encoding_type),
      encoding_options=copy.deepcopy(self.encoding_options),
    )

  @classmethod
  def from_precomputed(self, binary, segid=None):
    """
    Mesh from_precomputed(self, binary)

    Decode a Precomputed format mesh from a byte string.
    
    Format:
      uint32        Nv * float32 * 3   uint32 * 3 until end
      Nv            (x,y,z)            (v1,v2,v2)
      N Vertices    Vertices           Faces
    """
    num_vertices = struct.unpack("=I", binary[0:4])[0]
    try:
      # count=-1 means all data in buffer
      vertices = np.frombuffer(binary, dtype=np.float32, count=3*num_vertices, offset=4)
      faces = np.frombuffer(binary, dtype=np.uint32, count=-1, offset=(4 + 12 * num_vertices)) 
    except ValueError:

# Path: cloudvolume/exceptions.py
# class MeshDecodeError(ValueError):
#   """Unable to decode a mesh object."""
#   pass
# 
# Path: cloudvolume/lib.py
# def yellow(text):
#   return colorize('yellow', text)
# 
# class Vec(np.ndarray):
#     def __new__(cls, *args, **kwargs):
#       if 'dtype' in kwargs:
#         dtype = kwargs['dtype']
#       elif floating(args):
#         dtype = float
#       else:
#         dtype = int
# 
#       return super(Vec, cls).__new__(cls, shape=(len(args),), buffer=np.array(args).astype(dtype), dtype=dtype)
# 
#     @classmethod
#     def clamp(cls, val, minvec, maxvec):
#       x = np.minimum.reduce([
#         np.maximum.reduce([val,minvec]), 
#         maxvec
#       ])
#       return Vec(*x)
# 
#     def clone(self):
#       return Vec(*self[:], dtype=self.dtype)
# 
#     def null(self):
#         return self.length() <= 10 * np.finfo(np.float32).eps
# 
#     def dot(self, vec):
#       return sum(self * vec)
# 
#     def length2(self):
#         return self.dot(self)
# 
#     def length(self):
#         return math.sqrt(self.dot(self))
# 
#     def rectVolume(self):
#         return reduce(operator.mul, self)
# 
#     def __hash__(self):
#       return int(''.join(map(str, self)))
# 
#     def __repr__(self):
#       values = ",".join([ str(x) for x in self ])
#       return f"Vec({values}, dtype={self.dtype})"


# Path: cloudvolume/mesh.py
import copy
import re
import struct
import numpy as np
    import DracoPy
      import vtk
from .exceptions import MeshDecodeError
from .lib import yellow, Vec

    eff_faces = face_vector_map(faces)
    eff_faces = np.unique(eff_faces, axis=0)

    # normal_vector_map = np.vectorize(lambda idx: normals[idx])
    # eff_normals = normal_vector_map(uniq_idx)

    return Mesh(eff_verts, eff_faces, None, 
      segid=self.segid,
      encoding_type=copy.deepcopy(self.encoding_type),
      encoding_options=copy.deepcopy(self.encoding_options),
    )

  @classmethod
  def from_precomputed(self, binary, segid=None):
    """
    Mesh from_precomputed(self, binary)

    Decode a Precomputed format mesh from a byte string.
    
    Format:
      uint32        Nv * float32 * 3   uint32 * 3 until end
      Nv            (x,y,z)            (v1,v2,v2)
      N Vertices    Vertices           Faces
    """
    num_vertices = struct.unpack("=I", binary[0:4])[0]
    try:
      # count=-1 means all data in buffer
      vertices = np.frombuffer(binary, dtype=np.float32, count=3*num_vertices, offset=4)
      faces = np.frombuffer(binary, dtype=np.uint32, count=-1, offset=(4 + 12 * num_vertices)) 
    except ValueError:

      raise MeshDecodeError("""