コード例 #1
0
def Read_and_Smooth(path_reader,
                    path_writer,
                    coeff_smooth=0.001,
                    nb_iterations=50):

    #READ THE SURFACE
    print(" ---> Reading Marching-Cube surface")
    myReader = vmtkscripts.vmtkSurfaceReader()
    myReader.InputFileName = path_reader
    myReader.Format = 'stl'
    myReader.Execute()

    #SMOOTH THE SURFACE
    print(" ---> Smoothing surface with coeff {} and {} ierations".format(
        coeff_smooth, nb_iterations))
    mySmoother = vmtkscripts.vmtkSurfaceSmoothing()
    mySmoother.Surface = myReader.Surface
    mySmoother.PassBand = coeff_smooth
    mySmoother.NumberOfIterations = nb_iterations
    mySmoother.Execute()

    #WRITE TO STL FILE
    print(" ---> Writing results to STL file ")
    myWriter = vmtkscripts.vmtkSurfaceWriter()
    myWriter.Surface = mySmoother.Surface
    myWriter.OutputFileName = path_writer
    myWriter.Format = 'stl'
    myWriter.Execute()
コード例 #2
0
def vmtksurfacesmoothing(surface, iterations=100, method='taubin'):
    smoother = vmtkscripts.vmtkSurfaceSmoothing()
    smoother.Surface = surface
    smoother.Method = method
    smoother.NumberOfIterations = iterations
    smoother.PassBand = 0.1
    smoother.Execute()
    return smoother.Surface
コード例 #3
0
def Add_extension(path_reader,
                  path_writer,
                  extension_ratio=10,
                  target_edge_length=0.7,
                  nb_iterations=5):

    myReader = vmtkscripts.vmtkSurfaceReader()
    myReader.InputFileName = path_reader
    myReader.Format = 'stl'
    myReader.Execute()

    myCenterline = vmtkscripts.vmtkCenterlines()
    myCenterline.Surface = myReader.Surface
    myCenterline.SeedSelectorName = 'openprofiles'
    myCenterline.Execute()

    myExtension = vmtkscripts.vmtkFlowExtensions()
    myExtension.Surface = myReader.Surface
    myExtension.Centerlines = myCenterline.Centerlines
    myExtension.AdaptiveExtensionLength = 1
    myExtension.AdaptiveExtensionRadius = 1
    myExtension.ExtensionMode = "boundarynormal"
    myExtension.ExtensionRatio = extension_ratio
    myExtension.Interactive = 0
    myExtension.Execute()

    mySmoother = vmtkscripts.vmtkSurfaceSmoothing()
    mySmoother.Surface = myExtension.Surface
    mySmoother.PassBand = 0.3
    mySmoother.NumberOfIterations = 5
    mySmoother.Execute()

    myRemesh = vmtkscripts.vmtkSurfaceRemeshing()
    myRemesh.Surface = mySmoother.Surface
    myRemesh.ElementSizeMode = 'edgelength'
    myRemesh.TargetEdgeLength = target_edge_length
    myRemesh.NumberOfIterations = nb_iterations
    myRemesh.Execute()

    myWriter = vmtkscripts.vmtkSurfaceWriter()
    myWriter.Surface = myRemesh.Surface
    myWriter.OutputFileName = path_writer
    myWriter.Format = 'stl'
    myWriter.Execute()
コード例 #4
0
ファイル: vmtk_wrapper.py プロジェクト: cauchyturing/morphMan
def vmtk_smooth_surface(surface,
                        method,
                        iterations=800,
                        passband=1.0,
                        relaxation=0.01,
                        normalize_coordinates=True,
                        smooth_boundary=True):
    """Wrapper for a vmtksurfacesmoothing.

    Args:
        smooth_boundary (bool): Toggle allow change of position of boundary points
        normalize_coordinates (bool): Normalization of coordinates prior to filtering,
            minimize spurious translation effects (Taubin only)
        surface (vtkPolyData): Input surface to be smoothed.
        method (str): Smoothing method.
        iterations (int): Number of iterations.
        passband (float): The passband for Taubin smoothing.
        relaxation (float): The relaxation for laplace smoothing.

    Returns:
        surface (vtkPolyData): The smoothed surface.

    """
    smoother = vmtkscripts.vmtkSurfaceSmoothing()
    smoother.Surface = surface
    smoother.NumberOfIterations = iterations

    if method == "laplace":
        smoother.RelaxationFactor = relaxation
    elif method == "taubin":
        smoother.PassBand = passband

    if not normalize_coordinates:
        smoother.NormalizeCoordinates = 0
    if not smooth_boundary:
        smoother.BoundarySmoothing = 0

    smoother.Method = method
    smoother.Execute()
    surface = smoother.Surface

    return surface
コード例 #5
0
ファイル: vmtklib.py プロジェクト: ajgeers/utils
def vmtksurfacesmoothing(surface, iterations=100, method='taubin'):
    """Smooth a surface.

    Args:
        surface: Surface mesh.
        iterations: Number of smoothing iterations.
        method ('taubin', 'laplace'): Taubin's volume-preserving or a Laplacian
            smoothing filter.

    Returns:
        Smoothed surface.

    """
    smoother = vmtkscripts.vmtkSurfaceSmoothing()
    smoother.Surface = surface
    smoother.Method = method
    smoother.NumberOfIterations = iterations
    smoother.PassBand = 0.1
    smoother.Execute()
    return smoother.Surface
コード例 #6
0
ファイル: vmtklib.py プロジェクト: sheep-z/utils
def vmtksurfacesmoothing(surface, iterations=100, method='taubin'):
    """Smooth a surface.

    Args:
        surface: Surface mesh.
        iterations: Number of smoothing iterations.
        method ('taubin', 'laplace'): Taubin's volume-preserving or a Laplacian
            smoothing filter.

    Returns:
        Smoothed surface.

    """
    smoother = vmtkscripts.vmtkSurfaceSmoothing()
    smoother.Surface = surface
    smoother.Method = method
    smoother.NumberOfIterations = iterations
    smoother.PassBand = 0.1
    smoother.Execute()
    return smoother.Surface
コード例 #7
0
    def Execute(self):
        # Error handling
        if self.Surface == None:
            self.PrintError(
                'Error: no input surface was supplied, ensure file exists, ensure correct environment'
            )

        # Allocate a renderer and label own renderer in use to prevent multiple renderers from being used
        if not self.vmtkRenderer:
            self.vmtkRenderer = vmtkrenderer.vmtkRenderer()
            self.vmtkRenderer.Initialize()
            self.OwnRenderer = 1

        self.vmtkRenderer.RegisterScript(self)

        # Render and build view of the input surface
        self.SurfaceViewer = vmtkscripts.vmtkSurfaceViewer()
        self.SurfaceViewer.vmtkRenderer = self.vmtkRenderer

        self.SurfaceViewer.Surface = self.Surface
        self.SurfaceViewer.BuildView()

        # Test question in render window
        #queryStr = 'Is this the question you wanted to see? '
        #inputStr = self.YesNoInput(queryStr, self.YesNoValidator)

        # Surface smoothing, try defaults first then take user input if not adequate
        acceptableResult = 0
        response = 0
        while acceptableResult == 0:
            if response == 0:
                self.SurfaceSmoothing = vmtkscripts.vmtkSurfaceSmoothing()
                self.SurfaceSmoothing.NumberOfIterations = 100
                self.PassBand = 0.001
            elif response == 1:
                self.SurfaceViewer.Surface = self.Surface
                self.SurfaceViewer.BuildView()
                self.SurfaceSmoothing = vmtkscripts.vmtkSurfaceSmoothing()

                #Take passband from user
                queryStr = 'Please enter value for pass band (0.001 - 0.1): '
                self.SurfaceSmoothing.PassBand = float(
                    self.InputText(queryStr, self.PassBandValidator))

                #Take number of iterations from user
                queryStr = 'Please enter number of iterations (1-999): '
                self.SurfaceSmoothing.NumberOfIterations = int(
                    self.InputText(queryStr, self.IterationValidator))

            self.SurfaceSmoothing.Surface = self.Surface
            self.SurfaceSmoothing.Execute()
            self.SurfaceViewer.Surface = self.SurfaceSmoothing.Surface
            self.SurfaceViewer.BuildView()

            # Accept or reject result of smoothing surface
            queryStr = 'Accept result of smoothing?(y/n): '
            if (self.YesNoInput(queryStr, self.YesNoValidator)):
                acceptableResult = 1
                self.Surface = self.SurfaceSmoothing.Surface
            else:
                acceptableResult = 0
                response = 1

        # Surface clipping
        # The only issue here is that 2 renderers get built 2/2 the structure of vmtkSurfaceClipper
        # Issue to be revisited later
        acceptableResult = 0
        while acceptableResult == 0:

            self.SurfaceClipper = vmtkscripts.vmtkSurfaceClipper()
            self.SurfaceClipper.Surface = self.Surface
            self.SurfaceClipper.Execute()

            self.SurfaceViewer.Surface = self.SurfaceClipper.Surface
            self.SurfaceViewer.BuildView()

            queryStr = 'Accept result of clipping?(y/n): '
            if (self.YesNoInput(queryStr, self.YesNoValidator)):
                acceptableResult = 1
                self.Surface = self.SurfaceClipper.Surface
            else:
                acceptableResult = 0

            self.SurfaceViewer.Surface = self.SurfaceClipper.Surface
            self.SurfaceViewer.BuildView()

        # Create centerlines based off the acceptable clipped surface
        centerliner = vmtkscripts.vmtkCenterlines()
        centerliner.Surface = self.Surface
        centerliner.SeedSelectorName = 'openprofiles'
        centerliner.Execute()

        self.Centerlines = centerliner.Centerlines

        # Add flow extensions until user has acceptable result
        acceptableResult = 0
        response = 0
        while (acceptableResult == 0):

            self.FlowExtensions = vmtkscripts.vmtkFlowExtensions()
            self.FlowExtensions.Surface = self.Surface
            self.FlowExtensions.Centerlines = self.Centerlines
            self.FlowExtensions.AdaptiveExtensionLength = 1
            #self.FlowExtensions.CenterlineNormalEstimationDistanceRatio = 1
            self.FlowExtensions.Interactive = 0

            # Take user extension ratio if response to acceptable outcome question
            # Default extension ratio is 10
            if (response == 0):
                self.FlowExtensions.ExtensionRatio = 10
            elif (response == 1):
                #Take extension ratio from user
                queryStr = 'Please enter value for pass band; default is 20 (min/max 1-50): '
                self.FlowExtensions.ExtensionRatio = float(
                    self.InputText(queryStr, self.ExtensionRatioValidator))

            self.FlowExtensions.Execute()

            self.SurfaceViewer.Surface = self.FlowExtensions.Surface
            self.SurfaceViewer.BuildView()

            queryStr = 'Accept flow extensions?(y/n): '
            if (self.YesNoInput(queryStr, self.YesNoValidator)):
                acceptableResult = 1
                self.Surface = self.FlowExtensions.Surface
            else:
                acceptableResult = 0
                response = 1

        # self.SurfaceViewer.BuildView()

        # Deallocate renderer
        if self.OwnRenderer:
            self.vmtkRenderer.Deallocate()
コード例 #8
0
            self.SurfaceViewer.Surface = self.Surface
            self.SurfaceViewer.BuildView()

            queryStr = 'Accept results of level set and marching cubes? (y/n): '
            if(self.YesNoInput(queryStr, self.YesNoValidator)):
                acceptableResult = 1
            else:
                acceptableResult = 0


        # Surface smoothing, try defaults first then take user input if not adequate
        acceptableResult = 0
        response = 0
        while acceptableResult == 0:
            if response == 0:
                self.SurfaceSmoothing = vmtkscripts.vmtkSurfaceSmoothing()
                self.SurfaceSmoothing.NumberOfIterations = 50
                self.PassBand = 0.01
            elif response == 1:
                self.SurfaceViewer.Surface = self.Surface
                self.SurfaceViewer.BuildView()
                self.SurfaceSmoothing = vmtkscripts.vmtkSurfaceSmoothing()
       
                #Take passband from user
                queryStr = 'Please enter value for pass band [default = 0.01] (0.001 - 0.1): '
                self.SurfaceSmoothing.PassBand = float(self.InputText(queryStr, self.PassBandValidator))
             
                #Take number of iterations from user
                queryStr = 'Please enter number of iterations [default = 50] (1-999): '
                self.SurfaceSmoothing.NumberOfIterations = int(self.InputText(queryStr, self.IterationValidator))