Example #1
0
def vtk_marching_cube_multi(vtkLabel, bg_id, smooth=None, band=None):
    """
    Use the VTK marching cube to create isosrufaces for all classes excluding the background

    Args:
        labels: vtk image contraining the label map
        bg_id: id number of background class
        smooth: smoothing iteration
    Returns:
        mesh: vtk PolyData of the surface mesh
    """
    from vtk.util.numpy_support import vtk_to_numpy
    ids = np.unique(vtk_to_numpy(vtkLabel.GetPointData().GetScalars()))
    ids = np.delete(ids, np.where(ids==bg_id))

    #smooth the label map
    #vtkLabel = utils.gaussianSmoothImage(vtkLabel, 2.)

    contour = vtk.vtkDiscreteMarchingCubes()
    contour.SetInputData(vtkLabel)
    for index, i in enumerate(ids):
        print("Setting iso-contour value: ", i)
        contour.SetValue(index, i)
    contour.Update()
    mesh = contour.GetOutput()

    if smooth is not None:
        if band is not None:
            mesh = utils.windowed_sinc_smooth_vtk_polydata(mesh, smooth, band)
        else:
            mesh = utils.smooth_vtk_polydata(mesh, smooth)

    return mesh
Example #2
0
def vtk_marching_cube_union(vtkLabel, bg_id, smooth=True):
    """
    Use the VTK marching cube to create isosrufaces for all classes excluding the background

    Args:
        labels: vtk image contraining the label map
        bg_id: id number of background class
        smooth: whether to smooth
    Returns:
        model: vtk PolyData of the surface mesh
    """
    from vtk.util.numpy_support import vtk_to_numpy
    ids = np.unique(vtk_to_numpy(vtkLabel.GetPointData().GetScalars()))
    ids = np.delete(ids, np.where(ids==bg_id))
    
    model = vtk.vtkPolyData()
    from utils import boolean_vtk_polydata
    for index, i in enumerate(ids):
        mesh = vtk_marching_cube(vtkLabel, i, False)
        if model.GetNumberOfCells()==0:
            model.ShallowCopy(mesh)
        print("Processing iso-contour value: ", i)
        model = boolean_vtk_polydata(model, mesh, 'union')
        
    if smooth:
        model = utils.smooth_vtk_polydata(model)

    return model
Example #3
0
    def process_wall(self, la_cutter, la_plane, aa_cutter, aa_plane):
        if self.wall_processed:
            print("Left ventricle wall has been processed!")
            return
        # cut with la and aorta cutter:
        self.poly = utils.cut_polydata_with_another(self.poly, la_cutter,
                                                    la_plane)
        self.poly = utils.cut_polydata_with_another(self.poly, aa_cutter,
                                                    aa_plane)
        #fill small cutting artifacts:
        self.poly = utils.fill_hole(self.poly, size=15.)
        #improve valve opening geometry
        id_lists, boundaries = utils.get_point_ids_on_boundaries(self.poly)
        for idx, (ids, boundary) in enumerate(zip(id_lists, boundaries)):
            boundary = utils.smooth_vtk_polyline(boundary, 5)
            self.poly = utils.project_opening_to_fit_plane(
                self.poly, ids, boundary.GetPoints(), self.edge_size)
            # Remove the free cells and update the point lists
            self.poly, id_lists[idx] = utils.remove_free_cells(
                self.poly, [idx for sub_l in id_lists for idx in sub_l])
        self.poly = utils.smooth_vtk_polydata(utils.clean_polydata(
            self.poly, 0.),
                                              iteration=50)

        self.wall_processed = True
        return
Example #4
0
def vtk_continuous_marching_cube(vtkLabel, tol, smooth=None, band=None):
    """
    Use the VTK marching cube implementation to create the surface mesh

    Args:
        vtkLabel: vtk structured array containing the label map
        tol: threshold value for iso-surface
        smooth: smoothing iterations
    Returns:
        mesh: vtk PolyData of the surface mesh
    """
    contour = vtk.vtkMarchingCubes()
    contour.SetInputData(vtkLabel)
    contour.SetValue(0, tol)
    contour.Update()

    mesh = contour.GetOutput()

    if smooth is not None:
        if band is not None:
            mesh = utils.windowed_sinc_smooth_vtk_polydata(mesh, smooth, band)
        else:
            mesh = utils.smooth_vtk_polydata(mesh, smooth)
    return mesh