Exemple #1
0
def vmtkcenterlinegeometry(centerlines, smoothing=0, iterations=100):
    """Compute the local geometry of centerlines.

    Args:
        centerlines: Centerlines.
        smoothing (bool): Laplacian smooth centerlines before computing
            geometric variables.
        iterations: Number of smoothing iterations.

    Returns:
        Centerlines with geometric variables defined at each point.
        Pointdata (selection):
            Curvature: Local curvature.
            Torsion: Local torsion.
        Celldata (selection):
            Tortuosity: Tortuosity of each centerline.
            Length: Length of each centerline.

    Note:
        Since the computation of the geometric variables depends on first,
        second and third derivatives of the line coordinates, and since such
        derivatives are approximated using a simple finite difference scheme
        along the line, it is very likely that such derivatives will be affected
        by noise that is not appreciable when looking at the line itself. For
        this reason, it might be necessary to run the Laplacian smoothing filter
        before computing the derivatives and the related quantities.

    """
    clgeometry = vmtkscripts.vmtkCenterlineGeometry()
    clgeometry.Centerlines = centerlines
    clgeometry.LineSmoothing = smoothing
    clgeometry.NumberOfSmoothingIterations = iterations
    clgeometry.Execute()
    return clgeometry.Centerlines
Exemple #2
0
def vmtkcenterlinegeometry(centerlines, smoothing=0, iterations=100):
    """Compute the local geometry of centerlines.

    Args:
        centerlines: Centerlines.
        smoothing (bool): Laplacian smooth centerlines before computing
            geometric variables.
        iterations: Number of smoothing iterations.

    Returns:
        Centerlines with geometric variables defined at each point.
        Pointdata (selection):
            Curvature: Local curvature.
            Torsion: Local torsion.
        Celldata (selection):
            Tortuosity: Tortuosity of each centerline.
            Length: Length of each centerline.

    Note:
        Since the computation of the geometric variables depends on first,
        second and third derivatives of the line coordinates, and since such
        derivatives are approximated using a simple finite difference scheme
        along the line, it is very likely that such derivatives will be affected
        by noise that is not appreciable when looking at the line itself. For
        this reason, it might be necessary to run the Laplacian smoothing filter
        before computing the derivatives and the related quantities.

    """
    clgeometry = vmtkscripts.vmtkCenterlineGeometry()
    clgeometry.Centerlines = centerlines
    clgeometry.LineSmoothing = smoothing
    clgeometry.NumberOfSmoothingIterations = iterations
    clgeometry.Execute()
    return clgeometry.Centerlines
def vmtk_compute_geometric_features(centerlines,
                                    smooth,
                                    outputsmoothed=False,
                                    factor=1.0,
                                    iterations=100):
    """Wrapper for vmtk centerline geometry.

    Args:
        centerlines (vtkPolyData): Line to compute centerline geometry from.
        smooth (bool): Turn on and off smoothing before computing the geometric features.
        outputsmoothed (bool): Turn on and off the smoothed centerline.
        factor (float): Smoothing factor.
        iterations (int): Number of iterations.

    Returns:
        line (vtkPolyData): Line with geometry.
    """
    geometry = vmtkscripts.vmtkCenterlineGeometry()
    geometry.Centerlines = centerlines

    if smooth:
        geometry.LineSmoothing = 1
        geometry.OutputSmoothedLines = outputsmoothed
        geometry.SmoothingFactor = factor
        geometry.NumberOfSmoothingIterations = iterations
    geometry.FernetTangentArrayName = "FernetTangent"
    geometry.FernetNormalArrayName = "FernetNormal"
    geometry.FrenetBinormalArrayName = "FernetBiNormal"
    geometry.CurvatureArrayName = "Curvature"
    geometry.TorsionArrayName = "Torsion"
    geometry.TortuosityArrayName = "Tortuosity"
    geometry.Execute()

    return geometry.Centerlines
Exemple #4
0
def ExtractGeometry(centerlines):

    #centerlines=EquispacedSpline(centerlines.Centerlines,0.05) # every 0.5mm
    centerlineResampling = vmtkscripts.vmtkCenterlineResampling()
    centerlineResampling.Centerlines = centerlines.Centerlines
    centerlineResampling.Length = 0.05
    centerlineResampling.Execute()

    centerlineGeometry = vmtkscripts.vmtkCenterlineGeometry()
    centerlineGeometry.Centerlines = centerlineResampling.Centerlines
    centerlineGeometry.SmoothingFactor = 0.4
    centerlineGeometry.FrenetTangentArrayName = 'FrenetTangent'
    centerlineGeometry.FrenetNormalArrayName = 'FrenetNormal'
    centerlineGeometry.FrenetBinormalArrayName = 'FrenetBinormal'
    centerlineGeometry.Execute()

    centerlineAttributes = vmtkscripts.vmtkCenterlineAttributes()
    centerlineAttributes.Centerlines = centerlineGeometry.Centerlines
    centerlineAttributes.Execute()

    branchExtractor = vmtkscripts.vmtkBranchExtractor()
    branchExtractor.Centerlines = centerlineAttributes.Centerlines
    branchExtractor.GroupIdsArrayName = 'GroupIds'
    branchExtractor.RadiusArrayName = 'MaximumInscribedSphereRadius'
    branchExtractor.CenterlineIdsArrayName = 'CenterlineIds'
    branchExtractor.BlankingArrayName = 'Blanking'
    branchExtractor.Execute()

    return branchExtractor
def vmtkcenterlinegeometry(centerline):
    computer = vmtkscripts.vmtkCenterlineGeometry()
    computer.Centerlines = centerline
    computer.Execute()
    return computer.Centerlines
    poly_data = read_polydata(infile)
    x_list = []
    y_list = []
    z_list = []
    for i in range(poly_data.GetNumberOfPoints()):
        x_list.append(float(poly_data.GetPoints().GetPoint(i)[0]))
        y_list.append(float(poly_data.GetPoints().GetPoint(i)[1]))
        z_list.append(float(poly_data.GetPoints().GetPoint(i)[2]))

    return [np.mean(x_list), np.mean(y_list), np.mean(z_list)]


################################################################################
centerline_data = read_polydata(centerline_file)
#calculate Frenet tangential vector
centergeometry = vmtkscripts.vmtkCenterlineGeometry()
centergeometry.Centerlines = centerline_data
centergeometry.Execute()
centerline_data = centergeometry.Centerlines
write_polydata(centerline_data, centerline_file)

num_pts = centerline_data.GetNumberOfPoints()
print "Number of Points:", centerline_data.GetNumberOfPoints()

print "Number of arrays:", centerline_data.GetCellData().GetNumberOfArrays()

num_cells = centerline_data.GetNumberOfCells()
print "Number of Cells:", centerline_data.GetNumberOfCells()

###read cell data, for each cell (line), the lists record its centerline id (n lines starting from the inlet to outlets), blanking (0 non bifurcation, 1 bifurcation),
###group ids (vessels are splitted into single segments/branches and a bifurcation region,
    centerlineDistance.Centerlines = centerline.Centerlines
    centerlineDistance.DistanceToCenterlinesArrayName = 'DistanceToCenterlines'
    centerlineDistance.UseRadiusInformation = 1
    centerlineDistance.Execute()
    surface = centerlineDistance.Surface

    # VTP writer - centerline distance
    vtp_writer.SetFileName(path.join(ofile_mesh + "_centerline-distance.vtp"))
    vtp_writer.SetInputData(surface)
    vtp_writer.Update()
    vtp_writer.Write()

if CenterlineMesh:

    ### Centerline geometry data ###
    centerline_geo = vmtkscripts.vmtkCenterlineGeometry()
    centerline_geo.Centerlines = centerline.Centerlines
    # if NonConstThickness:
    #     centerline_geo.Centerlines = centerline2.Centerlines
    centerline_geo.CenterlinesOutputFileName = path.join(ofile_mesh +
                                                         "_centerline_geo.vtp")
    centerline_geo.Execute()

    # Convert to numpy array(s)
    centerline_geo_vmtktoNumpy = vmtkscripts.vmtkCenterlinesToNumpy()
    centerline_geo_vmtktoNumpy.Centerlines = centerline_geo.Centerlines
    centerline_geo_vmtktoNumpy.Execute()

    # Centerline points coords
    centerline_points = centerline_geo_vmtktoNumpy.ArrayDict["Points"]
    np.save(path.join(ofile_mesh + "_centerline_points.npy"),