예제 #1
0
파일: mesh.py 프로젝트: ZettaAI/igneous
  def execute(self):
    self._volume = CloudVolume(
      self.layer_path, self.options['mip'], bounded=False,
      parallel=self.options['parallel_download'], 
      fill_missing=self.options['fill_missing']
    )
    self._bounds = Bbox(self.offset, self.shape + self.offset)
    self._bounds = Bbox.clamp(self._bounds, self._volume.bounds)

    self.progress = bool(self.options['progress'])

    self._mesher = zmesh.Mesher(self._volume.resolution)

    # Marching cubes loves its 1vx overlaps.
    # This avoids lines appearing between
    # adjacent chunks.
    data_bounds = self._bounds.clone()
    data_bounds.minpt -= self.options['low_padding']
    data_bounds.maxpt += self.options['high_padding']

    self._mesh_dir = self.get_mesh_dir()

    if self.options['encoding'] == 'draco':
      self.draco_encoding_settings = draco_encoding_settings(
        shape=(self.shape + self.options['low_padding'] + self.options['high_padding']),
        offset=self.offset,
        resolution=self._volume.resolution,
        compression_level=self.options["draco_compression_level"],
        create_metadata=self.options['draco_create_metadata'],
        uses_new_draco_bin_size=False,
      )

    # chunk_position includes the overlap specified by low_padding/high_padding
    # agglomerate, timestamp, stop_layer only applies to graphene volumes, 
    # no-op for precomputed
    data = self._volume.download(
      data_bounds, 
      agglomerate=self.options['agglomerate'], 
      timestamp=self.options['timestamp'], 
      stop_layer=self.options['stop_layer']
    )

    if not np.any(data):
      if self.options['spatial_index']:
        self._upload_spatial_index(self._bounds, {})
      return

    data = self._remove_dust(data, self.options['dust_threshold'])
    data = self._remap(data)

    if self.options['object_ids']:
      data = fastremap.mask_except(data, self.options['object_ids'], in_place=True)

    data, renumbermap = fastremap.renumber(data, in_place=True)
    renumbermap = { v:k for k,v in renumbermap.items() }
    self.compute_meshes(data, renumbermap)
예제 #2
0
def test_ply_import():
    labels = np.zeros( (11,17,19), dtype=np.uint32)
    labels[1:-1, 1:-1, 1:-1] = 1

    mesher = zmesh.Mesher( (4,4,40) )
    mesher.mesh(labels)
    mesh = mesher.get_mesh(1, normals=False)

    plydata = mesh.to_ply()
    mesh2 = zmesh.Mesh.from_ply(plydata)
    
    assert mesh == mesh2
예제 #3
0
def test_obj_import():
    labels = np.zeros( (11,17,19), dtype=np.uint32)
    labels[1:-1, 1:-1, 1:-1] = 1

    mesher = zmesh.Mesher( (4,4,40) )
    mesher.mesh(labels)
    mesh = mesher.get_mesh(1, normals=False)

    obj_str = mesh.to_obj()
    mesh2 = zmesh.Mesh.from_obj(obj_str)
    
    assert mesh == mesh2
예제 #4
0
파일: mesh.py 프로젝트: seung-lab/igneous
    def execute(self):
        self.cv = CloudVolume(
            self.cloudpath,
            mip=self.mip,
            bounded=False,
            fill_missing=self.options['fill_missing'],
            mesh_dir=self.options['mesh_dir'],
        )

        if self.cv.mesh.meta.is_sharded() == False:
            raise ValueError("The mesh sharding parameter must be defined.")

        self.bounds = Bbox(self.offset, self.shape + self.offset)
        self.bounds = Bbox.clamp(self.bounds, self.cv.bounds)

        self.progress = bool(self.options['progress'])

        self.mesher = zmesh.Mesher(self.cv.resolution)

        # Marching cubes needs 1 voxel overlap to properly
        # stitch adjacent meshes.
        # data_bounds = self.bounds.clone()
        # data_bounds.maxpt += self.overlap_vx

        self.mesh_dir = self.get_mesh_dir()
        self.draco_encoding_settings = draco_encoding_settings(
            shape=(self.shape + self.overlap_vx),
            offset=self.offset,
            resolution=self.cv.resolution,
            compression_level=1,
            create_metadata=True,
            uses_new_draco_bin_size=self.cv.meta.uses_new_draco_bin_size,
        )

        chunk_pos = self.cv.meta.point_to_chunk_position(self.bounds.center(),
                                                         mip=self.mip)

        img = mesh_graphene_remap.remap_segmentation(
            self.cv,
            chunk_pos.x,
            chunk_pos.y,
            chunk_pos.z,
            mip=self.mip,
            overlap_vx=self.overlap_vx,
            time_stamp=self.timestamp,
            progress=self.progress,
        )

        if not np.any(img):
            return

        self.upload_meshes(self.compute_meshes(img))
예제 #5
0
def mesh_seg(seg, voxel_offset, voxel_res, segid=None):

    if segid is not None:
        seg = seg == segid

    mesher = zmesh.Mesher((1, 1, 1))
    mesher.mesh(np.swapaxes(seg, 0, 2))
    mesh_id = mesher.ids()[0]
    mesh = mesher.get_mesh(mesh_id, normals=False,
                           simplification_factor=0,
                           max_simplification_error=0)
    mesh.vertices = (mesh.vertices + voxel_offset) * voxel_res
    mesher.erase(mesh_id)
    mesher.clear()
    return {"vertices": mesh.vertices, "faces": mesh.faces.reshape(-1, 3),
            "num_vertices": len(mesh.vertices)}
예제 #6
0
def test_executes():
  for dtype in (np.uint32, np.uint64):
    labels = np.zeros( (11,17,19), dtype=dtype)
    labels[1:-1, 1:-1, 1:-1] = 1

    mesher = zmesh.Mesher( (4,4,40) )
    mesher.mesh(labels)

    mesh = mesher.get_mesh(1, normals=False)
    assert len(mesh.vertices) > 0
    assert len(mesh.faces) > 0
    assert mesh.normals is None

    mesh = mesher.get_mesh(1, normals=True)
    assert len(mesh.vertices) > 0
    assert len(mesh.faces) > 0
    assert len(mesh.normals) > 0
예제 #7
0
def test_precomputed():
  for dtype in (np.uint32, np.uint64):
    labels = np.zeros( (11,17,19), dtype=dtype)
    labels[1:-1, 1:-1, 1:-1] = 1

    mesher = zmesh.Mesher( (4,4,40) )
    mesher.mesh(labels)
    mesh = mesher.get_mesh(1, normals=False)

    precomputed_mesh = mesh.to_precomputed()
    reconstituted = zmesh.Mesh.from_precomputed(precomputed_mesh)
    assert reconstituted == mesh

    mesh = mesher.get_mesh(1, normals=True)

    precomputed_mesh = mesh.to_precomputed()
    reconstituted = zmesh.Mesh.from_precomputed(precomputed_mesh)
    assert reconstituted != mesh # Precomputed doesn't preserve normals
예제 #8
0
def test_simplify():
  for dtype in (np.uint32, np.uint64):
    labels = np.zeros( (11,17,19), dtype=dtype)
    labels[1:-1, 1:-1, 1:-1] = 1

    mesher = zmesh.Mesher( (4,4,40) )
    mesher.mesh(labels)

    mesh = mesher.get_mesh(1, normals=False)
    Nv = len(mesh.vertices)
    Nf = len(mesh.faces)
    
    mesh = mesher.simplify(mesh, reduction_factor=10, max_error=40)
    assert len(mesh) > 0
    assert len(mesh) < Nv 
    assert mesh.faces.shape[0] < Nf
    assert mesh.normals is None or mesh.normals.size == 0

    mesh = mesher.simplify(mesh, reduction_factor=10, max_error=40, compute_normals=True)
    assert len(mesh) > 0
    assert len(mesh) < Nv 
    assert mesh.faces.shape[0] < Nf
    assert mesh.normals.size > 0
예제 #9
0
import numpy as np
import zmesh

labels = np.zeros( (50, 50, 50), dtype=np.uint32)
labels[1:-1, 1:-1, 1:-1] = 1

mesher = zmesh.Mesher( (1,1,1) )
mesher.mesh(labels)
mesh = mesher.get_mesh(1, normals=False, simplification_factor=0, max_simplification_error=100)

print(mesh)

with open('wow.obj', 'bw') as f:
  f.write(mesh.to_obj())

with open('wow.ply', 'bw') as f:
  f.write(mesh.to_ply())

예제 #10
0
import numpy as np
import zmesh

labels = np.zeros( (50, 50, 50), dtype=np.uint32)
labels[1:-1, 1:-1, 1:-1] = 1

mesher = zmesh.Mesher( (3.141, 1, 1) )
mesher.mesh(labels)
mesh = mesher.get_mesh(1, normals=False, simplification_factor=100, max_simplification_error=100)

print(mesh)

with open('wow.obj', 'bw') as f:
  f.write(mesh.to_obj())

with open('wow.ply', 'bw') as f:
  f.write(mesh.to_ply())