예제 #1
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
예제 #2
0
 def extract_branches(self, params):
     """ Split and group centerlines along branches. 
     """
     self.logger.info("Split and group centerlines along branches ...");
     branch_extractor = vmtkscripts.vmtkBranchExtractor()
     branch_extractor.Centerlines = self.geometry 
     branch_extractor.Execute()
     self.branch_geometry = branch_extractor.Centerlines
     #print(self.centerlines_branch_geometry)
     self.logger.info("The centerlines branches have been calculated.");
예제 #3
0
def compute(infile, outfile):
    """
    Calls VMTK routine for centerline extraction.

    Parameters
    ----------
    infile : string
        Path to input mesh with open inlet/outlets (.stl format).
    outfile : string
        Path to output centerline (.vtp format).

    Returns
    -------
    None

    """

    # read surface
    centerlineReader = vmtkscripts.vmtkSurfaceReader()
    centerlineReader.InputFileName = infile
    centerlineReader.Execute()

    # centerline
    centerline = vmtkscripts.vmtkCenterlines()
    centerline.Surface = centerlineReader.Surface
    centerline.SeedSelectorName = 'openprofiles'
    centerline.AppendEndPoints = 1
    centerline.Execute()

    # extract branches
    branchExtractor = vmtkscripts.vmtkBranchExtractor()
    branchExtractor.Centerlines = centerline.Centerlines
    branchExtractor.Execute()

    # merge centerlines
    centerlineMerge = vmtkscripts.vmtkCenterlineMerge()
    centerlineMerge.Centerlines = branchExtractor.Centerlines
    centerlineMerge.Execute()

    # write surface
    centerlineWriter = vmtkscripts.vmtkSurfaceWriter()
    centerlineWriter.OutputFileName = outfile
    centerlineWriter.Surface = centerlineMerge.Centerlines
    centerlineWriter.Execute()
예제 #4
0
def vmtk_compute_branch_extractor(centerlines):
    """
    Wrapper for vmtkBranchExtractor.
    Split and group centerlines along branches:

    Args:
        centerlines (vtkPolyData): Line to split into branches.

    Returns:
        vtkPolyData: Split centerline.
    """

    brancher = vmtkscripts.vmtkBranchExtractor()
    brancher.Centerlines = centerlines
    brancher.RadiusArrayName = radiusArrayName
    brancher.Execute()
    centerlines_branched = brancher.Centerlines

    return centerlines_branched
예제 #5
0
파일: vmtklib.py 프로젝트: ajgeers/utils
def vmtkbranchextractor(centerlines):
    """Split centerlines into branches.

    Args:
        centerlines: Centerlines.

    Returns:
        Centerlines split into branches.
        Celldata (selection):
            CenterlineId: Cellid of centerline from which the tract was split.
            TractId: Id identifying each tract along one centerline.
            GroupId: Id of the group to which the tract belongs.
            Blanking: Boolean indicating whether tract belongs to bifurcation.

    """
    extractor = vmtkscripts.vmtkBranchExtractor()
    extractor.Centerlines = centerlines
    extractor.RadiusArrayName = 'MaximumInscribedSphereRadius'
    extractor.Execute()
    return extractor.Centerlines
예제 #6
0
파일: vmtklib.py 프로젝트: sheep-z/utils
def vmtkbranchextractor(centerlines):
    """Split centerlines into branches.

    Args:
        centerlines: Centerlines.

    Returns:
        Centerlines split into branches.
        Celldata (selection):
            CenterlineId: Cellid of centerline from which the tract was split.
            TractId: Id identifying each tract along one centerline.
            GroupId: Id of the group to which the tract belongs.
            Blanking: Boolean indicating whether tract belongs to bifurcation.

    """
    extractor = vmtkscripts.vmtkBranchExtractor()
    extractor.Centerlines = centerlines
    extractor.RadiusArrayName = 'MaximumInscribedSphereRadius'
    extractor.Execute()
    return extractor.Centerlines
예제 #7
0
    def extract_center_lines(self):
        """ Extract the centerlines of a surface.

           The centerline geometry is returned as a vtkPolyData object.
        """
        self.logger.info("---------- Extract Centerlines ---------- ")
        mesh = self.mesh
        surface = mesh.surface
        surface_caps = mesh.surface_caps
        source_centers = []
        source_ids = []
        target_centers = []
        target_ids = []

        ## Get source and target face centers.
        #
        for faceID, face in surface_caps.items():
            self.logger.info(" ")
            self.logger.info("-----  Face ID %d ----- " % int(faceID))
            center = face.get_center()
            ptID, id_center = face.get_id(center)
            if face.source:
                self.logger.info("Source")
                source_centers.extend(center)
                self.graphics.add_sphere(center, [1.0, 0.0, 0.0])
                self.graphics.add_sphere(id_center, [1.0, 0.0, 0.0])
                source_ids.append(ptID)
            else:
                self.logger.info("Target")
                target_centers.extend(center)
                self.graphics.add_sphere(center, [0.0, 1.0, 0.0])
                self.graphics.add_sphere(id_center, [0.0, 1.0, 0.0])
                target_ids.append(ptID)
            self.logger.info("Center ID: %d" % ptID)
            self.logger.info("Center: %s" % str(center))
            self.logger.info("ID Center: %s" % str(id_center))
        #__for faceID in face_ids

        ## Extract centerlines using vmtk.
        #
        self.logger.info(" ")
        self.logger.info("Calculating surface centerlines ...")
        centerlines = vmtkscripts.vmtkCenterlines()
        centerlines.Surface = mesh.surface
        centerlines.AppendEndPoints = 1
        """
        source_ids = [67628]
        target_ids = [67626, 67627 ,67628 ,67629 ,67630 ,67631 ,67632 ,67633]
        surface.GetPoint(source_ids[0], id_center);
        self.graphics.add_sphere(id_center, [1.0,0.0,0.0])
        """

        use_id_list = True

        if use_id_list:
            self.logger.info("Use source and target IDs")
            self.logger.info("Source IDs: %s" % str(source_ids))
            self.logger.info("Target IDs: %s" % str(target_ids))
            centerlines.SeedSelectorName = "idlist"
            centerlines.SourceIds = source_ids
            centerlines.TargetIds = target_ids
        else:
            centerlines.SeedSelectorName = "pointlist"
            centerlines.SourcePoints = source_centers
            centerlines.TargetPoints = target_centers

        centerlines.Execute()
        self.geometry = centerlines.Centerlines
        self.logger.info("The surface centerlines have been calculated.")
        self.graphics.add_graphics_geometry(self.geometry, [0.0, 0.0, 1.0])

        self.logger.info("Split and group centerlines along branches ...")
        branch_extractor = vmtkscripts.vmtkBranchExtractor()
        branch_extractor.Centerlines = self.geometry
        branch_extractor.Execute()
        self.branch_geometry = branch_extractor.Centerlines
        #print(self.centerlines_branch_geometry)
        self.logger.info("The centerlines branches have been calculated.")

        file_name = "branch_geometry.vtp"
        writer = vtk.vtkXMLPolyDataWriter()
        writer.SetFileName(file_name)
        writer.SetInputData(self.branch_geometry)
        writer.Update()
        writer.Write()
예제 #8
0
    def Execute(self):
        print("Compute VC orientation")
        self.ctrliner = vmtkscripts.vmtkCenterlines()
        self.ctrliner.Surface = self.Surface
        self.ctrliner.Execute()
        self.Centerlines = self.ctrliner.Centerlines
        cc = self.Centerlines

        ptCoord = []

        for c in xrange(cc.GetNumberOfPoints()):
            ptCoord.append(cc.GetPoints().GetPoint(c))

        ptCoord = np.array(ptCoord)
        datamean = ptCoord.mean(axis=0)
        uu, dd, vv = np.linalg.svd(ptCoord - datamean)
        # vector of the general direction of the VC
        # print(vv[0], datamean, datamean+10*vv[0])
        VCvect = vv[0]

        if self.ComputeCenterlines:
            # print(self.Surface)
            self.ctrliner = vmtkscripts.vmtkCenterlines()
            self.ctrliner.Surface = self.Surface
            # self.ctrliner.SeedSelector = 'openprofiles'
            self.ctrliner.Execute()
            self.Centerlines = self.ctrliner.Centerlines
            # self.Surface = self.Centerlines
        else:
            self.Centerlines = self.Surface

        # if self.Centerlines == None:
        #     self.PrintError('DUMBASS')

        self.vmtkReader = vmtkscripts.vmtkSurfaceReader()

        self.vmtkRenderer = vmtkscripts.vmtkRenderer()
        self.vmtkRenderer.Initialize()
        self.SurfaceViewer = vmtkscripts.vmtkSurfaceViewer()

        # self.Surface = self.Centerlines
        self.SurfaceViewer.Surface = self.Surface
        self.SurfaceViewer.Execute()

        self.myattr = vmtkscripts.vmtkCenterlineAttributes()
        self.myattr.Centerlines = self.Centerlines
        self.myattr.Execute()

        self.mybranchextractor = vmtkscripts.vmtkBranchExtractor()
        self.mybranchextractor.Centerlines = self.myattr.Centerlines
        self.mybranchextractor.RadiusArrayName = self.RadiusArrayName
        self.mybranchextractor.Execute()

        self.ctrl = self.mybranchextractor.Centerlines

        self.mywriter = vmtkscripts.vmtkSurfaceWriter()
        self.mywriter.Surface = self.mybranchextractor.Centerlines
        self.mywriter.OutputFileName = '/home/florian/liverSim/morpho_analysis/test_surf_open_small_ctrlTESTbranc1.vtp'
        self.mywriter.Execute()

        self.mybifref = vmtkscripts.vmtkBifurcationReferenceSystems()
        self.mybifref.Centerlines = self.ctrl
        self.mybifref.RadiusArrayName = self.RadiusArrayName
        self.mybifref.BlankingArrayName = self.BlankingArrayName
        self.mybifref.GroupIdsArrayName = self.GroupIdsArrayName
        self.mybifref.CenterlineIdsArrayName = self.CenterlineIdsArrayName
        self.mybifref.TractIdsArrayName = self.TractIdsArrayName
        self.mybifref.Execute()

        self.myvect = vmtkscripts.vmtkBifurcationVectors()
        self.myvect.Centerlines = self.ctrl
        self.myvect.ReferenceSystems = self.mybifref.ReferenceSystems
        self.myvect.RadiusArrayName = self.RadiusArrayName
        self.myvect.BlankingArrayName = self.BlankingArrayName
        self.myvect.GroupIdsArrayName = self.GroupIdsArrayName
        self.myvect.TractIdsArrayName = self.TractIdsArrayName
        self.myvect.CenterlineIdsArrayName = self.CenterlineIdsArrayName
        self.myvect.ReferenceSystemsNormalArrayName = self.mybifref.ReferenceSystemsNormalArrayName
        self.myvect.ReferenceSystemsUpNormalArrayName = self.mybifref.ReferenceSystemsUpNormalArrayName
        self.myvect.Execute()

        '''TEMP'''
        self.mywriter = vmtkscripts.vmtkSurfaceWriter()
        self.mywriter.Surface = self.myvect.BifurcationVectors
        self.mywriter.OutputFileName = '/home/florian/liverSim/morpho_analysis/test_surf_open_small_bifvect.vtp'
        self.mywriter.Execute()

        self.mywriter.Surface = self.ctrl
        self.mywriter.OutputFileName = '/home/florian/liverSim/morpho_analysis/test_surf_open_small_ctrl.vtp'
        self.mywriter.Execute()
        '''/TEMP'''



        self.numpytator = vmtksurfacetonumpy.vmtkSurfaceToNumpy()
        self.numpytator.Surface = self.myvect.BifurcationVectors
        self.numpytator.Execute()
        vectData = self.numpytator.ArrayDict.values()

        cprint(figlet_format('Results!', font='bubble'))
        print('\n InPlaneBifurcationVectors angle:')
        print(np.degrees(self.angle_between(vectData[0]["InPlaneBifurcationVectors"][1, :],
                                            vectData[0]["InPlaneBifurcationVectors"][2, :])))
        # print('\n OutOfPlaneBifurcationVectors angle:')
        # print(np.degrees(self.angle_between(vectData[0]["OutOfPlaneBifurcationVectors"][1, :],
        #                                     vectData[0]["OutOfPlaneBifurcationVectors"][2, :])))
        print('\n bifurcation angle with the VC:')
        print(np.degrees(self.angle_between(vectData[0]["OutOfPlaneBifurcationVectors"][0, :],
                                            VCvect)))
        '''
        weighted average vector between the vectors pointing from the second 
        to the first reference point on each centerline
        '''
        print('\n global direction of the birfurcation:')
        print(vectData[0]["BifurcationVectors"][0, :])
        '''
        the origin of the bifurcation is defined as the barycenter of the four reference points
         weighted by the surface of the maximum inscribed sphere defined on the reference points. 
         The reason of the weighting is that small branches have less impact on the position of 
         the bifurcation origin
        '''
        print('\n Origin of the bifurcation:')
        print(vectData[1][0])
        pass
예제 #9
0
args = "vmtksurfacereader -ifile " + surfaceFile
myPype = pypes.PypeRun(args)
mySurface = myPype.GetScriptObject('vmtksurfacereader', '0').Surface

myctrl = vmtkscripts.vmtkCenterlines()
myctrl.Surface = mySurface
myctrl.SeedSelectorName = 'openprofiles'
# myctrl.Centerlines = centerlinesFile
myctrl.Execute()

myattr = vmtkscripts.vmtkCenterlineAttributes()
myattr.Centerlines = myctrl.Centerlines
myattr.Execute()

mybranchextractor = vmtkscripts.vmtkBranchExtractor()
mybranchextractor.Centerlines = myattr.Centerlines
mybranchextractor.RadiusArrayName = 'MaximumInscribedSphereRadius'
mybranchextractor.Execute()

# mywriter = vmtkscripts.vmtkSurfaceWriter()
# mywriter.Surface = mybranchextractor.Centerlines
# mywriter.OutputFileName = centerlinesFileName
# mywriter.Execute()

mybifref = vmtkscripts.vmtkBoundaryReferenceSystems()
mybifref.Surface = mybranchextractor.Centerlines
mybifref.Execute()

# mywriter = vmtkscripts.vmtkSurfaceWriter()
# mywriter.Surface = mybifref.Centerlines
예제 #10
0
def vmtkbranchextractor(centerline):
    extractor = vmtkscripts.vmtkBranchExtractor()
    extractor.Centerlines = centerline
    extractor.RadiusArrayName = 'MaximumInscribedSphereRadius'
    extractor.Execute()
    return extractor.Centerlines
예제 #11
0
def vmtkbranchextractor(centerline):
    extractor = vmtkscripts.vmtkBranchExtractor()
    extractor.Centerlines = centerline
    extractor.RadiusArrayName = 'MaximumInscribedSphereRadius'
    extractor.Execute()
    return extractor.Centerlines