コード例 #1
0
    def Execute(self):
        from vmtk import vmtkscripts
        if self.Surface == None:
            self.PrintError('Error: no Surface.')

        if not self.vmtkRenderer:
            self.vmtkRenderer = vmtkrenderer.vmtkRenderer()
            self.vmtkRenderer.Initialize()
            self.OwnRenderer = 1

        self.vmtkRenderer.RegisterScript(self)

        triangleFilter = vtk.vtkTriangleFilter()
        triangleFilter.SetInputData(self.Surface)
        triangleFilter.Update()

        self.Surface = triangleFilter.GetOutput()

        self.tagviewer = vmtkscripts.vmtkSurfaceViewer()
        self.tagviewer.Surface = self.Surface
        self.tagviewer.vmtkRenderer = self.vmtkRenderer
        self.tagviewer.Representation = 'edges'
        self.tagviewer.Opacity = self.Opacity
        self.tagviewer.Execute()

        self.ContourWidget = vtk.vtkContourWidget()
        self.ContourWidget.SetInteractor(
            self.vmtkRenderer.RenderWindowInteractor)

        rep = vtk.vtkOrientedGlyphContourRepresentation.SafeDownCast(
            self.ContourWidget.GetRepresentation())
        rep.GetLinesProperty().SetColor(1, 0, 0)
        rep.GetLinesProperty().SetLineWidth(4.0)

        pointPlacer = vtk.vtkPolygonalSurfacePointPlacer()
        pointPlacer.AddProp(self.tagviewer.Actor)
        pointPlacer.GetPolys().AddItem(self.Surface)
        rep.SetPointPlacer(pointPlacer)

        self.Interpolator = vtk.vtkPolygonalSurfaceContourLineInterpolator()
        self.Interpolator.GetPolys().AddItem(self.Surface)
        rep.SetLineInterpolator(self.Interpolator)

        self.InputInfo("Building loop ...\n")

        self.vmtkRenderer.AddKeyBinding('space', 'Generate loop',
                                        self.LoopCallback)
        self.vmtkRenderer.AddKeyBinding('d', 'Delete contour',
                                        self.DeleteContourCallback)
        self.vmtkRenderer.AddKeyBinding('i', 'Start/stop contour drawing',
                                        self.InteractCallback)

        self.Display()

        if self.OwnRenderer:
            self.vmtkRenderer.Deallocate()
コード例 #2
0
    def Execute(self):
        from vmtk import vmtkscripts
        if self.Surface == None:
            self.PrintError('Error: no Surface.')

        if not self.vmtkRenderer:
            self.vmtkRenderer = vmtkrenderer.vmtkRenderer()
            self.vmtkRenderer.Initialize()
            self.OwnRenderer = 1

        self.vmtkRenderer.RegisterScript(self) 

        triangleFilter = vtk.vtkTriangleFilter()
        triangleFilter.SetInputData(self.Surface)
        triangleFilter.Update()

        self.Surface = triangleFilter.GetOutput()

        self.tagviewer = vmtkscripts.vmtkSurfaceViewer()
        self.tagviewer.Surface = self.Surface
        self.tagviewer.vmtkRenderer = self.vmtkRenderer
        self.tagviewer.Representation = 'edges'
        self.tagviewer.Opacity = self.Opacity
        self.tagviewer.Execute()

        self.ContourWidget = vtk.vtkContourWidget()
        self.ContourWidget.SetInteractor(self.vmtkRenderer.RenderWindowInteractor)

        rep = vtk.vtkOrientedGlyphContourRepresentation.SafeDownCast(self.ContourWidget.GetRepresentation())
        rep.GetLinesProperty().SetColor(1, 0, 0)
        rep.GetLinesProperty().SetLineWidth(4.0)

        pointPlacer = vtk.vtkPolygonalSurfacePointPlacer()
        pointPlacer.AddProp(self.tagviewer.Actor)
        pointPlacer.GetPolys().AddItem(self.Surface)
        rep.SetPointPlacer(pointPlacer)

        self.Interpolator = vtk.vtkPolygonalSurfaceContourLineInterpolator()
        self.Interpolator.GetPolys().AddItem(self.Surface)
        rep.SetLineInterpolator(self.Interpolator)

        self.InputInfo("Building loop ...\n")

        self.vmtkRenderer.AddKeyBinding('space','Generate loop',self.LoopCallback)
        self.vmtkRenderer.AddKeyBinding('d','Delete contour',self.DeleteContourCallback)
        self.vmtkRenderer.AddKeyBinding('i','Start/stop contour drawing',self.InteractCallback)


        self.Display()


        if self.OwnRenderer:
            self.vmtkRenderer.Deallocate()
コード例 #3
0
def view_surface(surface,
                 opacity=1.0,
                 arrayName='',
                 scalarRange=[0.0, 0.0],
                 colorMap='cooltowarm',
                 numberOfColors=256,
                 legend=0,
                 legendTitle='',
                 grayscale=0,
                 flatInterpolation=0,
                 displayCellData=0,
                 color=[-1.0, -1.0, -1.0],
                 execute=True,
                 **kwargs):

    viewer = vmtkscripts.vmtkSurfaceViewer()
    viewer.Surface = surface

    viewer.Opacity = opacity
    viewer.ArrayName = arrayName
    viewer.ScalarRange = scalarRange
    viewer.ColorMap = colorMap
    viewer.NumberOfColors = numberOfColors
    viewer.Legend = legend
    viewer.LegendTitle = legendTitle
    viewer.Grayscale = grayscale
    viewer.FlatInterpolation = flatInterpolation
    viewer.DisplayCellData = displayCellData
    viewer.Color = color

    set_vmtk_options(viewer, kwargs)

    if execute:
        viewer.Execute()
    else:
        return viewer
コード例 #4
0
    def Execute(self):
        from vmtk import vmtkscripts
        if self.Image == None:
            self.PrintError('Error: no Image.')

        cast = vtk.vtkImageCast()
        cast.SetInputData(self.Image)
        cast.SetOutputScalarTypeToFloat()
        cast.Update()
        self.Image = cast.GetOutput()

        if not self.InitializationImage:
            self.InitializationImage = self.Image

        if not self.FeatureImage:
            if self.LevelSetsType in ["geodesic", "curves"]:
                imageFeatures = vmtkscripts.vmtkImageFeatures()
                imageFeatures.Image = self.Image
                imageFeatures.FeatureImageType = self.FeatureImageType
                imageFeatures.SigmoidRemapping = self.SigmoidRemapping
                imageFeatures.DerivativeSigma = self.FeatureDerivativeSigma
                imageFeatures.UpwindFactor = self.UpwindFactor
                imageFeatures.FWHMRadius = self.FWHMRadius
                imageFeatures.FWHMBackgroundValue = self.FWHMBackgroundValue
                imageFeatures.Execute()
                self.FeatureImage = imageFeatures.FeatureImage
            elif self.LevelSetsType in ["threshold", "laplacian"]:
                self.FeatureImage = self.Image
            else:
                self.PrintError('Unsupported LevelSetsType')

        if self.NumberOfIterations != 0:
            self.LevelSetsInput = self.InitialLevelSets
            self.LevelSetEvolution()
            self.MergeLevelSet()
            return

        if not self.vmtkRenderer:
            self.vmtkRenderer = vmtkscripts.vmtkRenderer()
            self.vmtkRenderer.Initialize()
            self.OwnRenderer = 1

        self.vmtkRenderer.RegisterScript(self)

        self.ImageSeeder = vmtkscripts.vmtkImageSeeder()
        self.ImageSeeder.vmtkRenderer = self.vmtkRenderer
        #self.ImageSeeder.Image = self.Image
        self.ImageSeeder.Image = self.InitializationImage
        self.ImageSeeder.Display = 0
        self.ImageSeeder.Execute()
        ##self.ImageSeeder.Display = 1
        self.ImageSeeder.BuildView()

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

        if self.LevelSets != None:
            self.DisplayLevelSetSurface(self.LevelSets, 0.0)

        self.vmtkImageInitialization = vmtkscripts.vmtkImageInitialization()
        #self.vmtkImageInitialization.Image = self.Image
        self.vmtkImageInitialization.Image = self.InitializationImage
        self.vmtkImageInitialization.vmtkRenderer = self.vmtkRenderer
        self.vmtkImageInitialization.ImageSeeder = self.ImageSeeder
        self.vmtkImageInitialization.SurfaceViewer = self.SurfaceViewer
        self.vmtkImageInitialization.NegateImage = self.NegateForInitialization
        self.vmtkImageInitialization.OwnRenderer = 0

        endSegmentation = 0
        while (endSegmentation == 0):

            if self.InitialLevelSets == None:
                self.vmtkImageInitialization.Execute()
                self.LevelSetsInput = self.vmtkImageInitialization.InitialLevelSets
                #                self.IsoSurfaceValue = self.vmtkImageInitialization.IsoSurfaceValue
                self.vmtkImageInitialization.InitialLevelSets = None
                #                self.vmtkImageInitialization.IsosurfaceValue = 0.0
                self.IsoSurfaceValue = 0.0
            else:
                self.LevelSetsInput = self.InitialLevelSets
                self.InitialLevelSets = None
                self.DisplayLevelSetSurface(self.LevelSetsInput,
                                            self.IsoSurfaceValue)

            endEvolution = False
            while not endEvolution:

                queryString = 'Please input parameters (type return to accept current values, \'e\' to end, \'q\' to quit):\nNumberOfIterations(' + str(
                    self.NumberOfIterations) + ') [PropagationScaling(' + str(
                        self.PropagationScaling) + ') CurvatureScaling(' + str(
                            self.CurvatureScaling
                        ) + ') AdvectionScaling(' + str(
                            self.AdvectionScaling) + ')]: '
                inputString = self.InputText(queryString,
                                             self.EvolutionParametersValidator)

                if inputString == 'q':
                    return
                elif inputString == 'e':
                    endEvolution = True
                elif inputString != '':
                    splitInputString = inputString.strip().split(' ')
                    if len(splitInputString) == 1:
                        self.NumberOfIterations = int(splitInputString[0])
                    elif len(splitInputString) == 4:
                        self.NumberOfIterations = int(splitInputString[0])
                        self.PropagationScaling = float(splitInputString[1])
                        self.CurvatureScaling = float(splitInputString[2])
                        self.AdvectionScaling = float(splitInputString[3])
                    else:
                        self.PrintLog('Wrong number of parameters.')
                        continue

                if endEvolution:
                    break

                self.LevelSetEvolution()
                self.DisplayLevelSetSurface(self.LevelSetsOutput)

                queryString = 'Accept result? (y/n): '
                inputString = self.InputText(queryString, self.YesNoValidator)
                if inputString == 'y':
                    endEvolution = True
                elif inputString == 'n':
                    endEvolution = False

            queryString = 'Merge branch? (y/n): '
            inputString = self.InputText(queryString, self.YesNoValidator)
            if inputString == 'y':
                self.MergeLevelSet()
            elif inputString == 'n':
                pass

            if self.LevelSets != None:
                self.DisplayLevelSetSurface(self.LevelSets)

            queryString = 'Segment another branch? (y/n): '
            inputString = self.InputText(queryString, self.YesNoValidator)
            if inputString == 'y':
                endSegmentation = False
            elif inputString == 'n':
                endSegmentation = True
        if self.OwnRenderer:
            self.vmtkRenderer.Deallocate()
コード例 #5
0
ファイル: customscript.py プロジェクト: totocaca/tools
    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
コード例 #6
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()
コード例 #7
0
ファイル: vmtklevelsetsegmentation.py プロジェクト: vmtk/vmtk
    def Execute(self):
        from vmtk import vmtkscripts
        if self.Image == None:
            self.PrintError('Error: no Image.')

        cast = vtk.vtkImageCast()
        cast.SetInputData(self.Image)
        cast.SetOutputScalarTypeToFloat()
        cast.Update()
        self.Image = cast.GetOutput()

        if not self.InitializationImage:
            self.InitializationImage = self.Image

        if not self.FeatureImage:
            if self.LevelSetsType in ["geodesic", "curves"]:
                imageFeatures = vmtkscripts.vmtkImageFeatures()
                imageFeatures.Image = self.Image
                imageFeatures.FeatureImageType = self.FeatureImageType
                imageFeatures.SigmoidRemapping = self.SigmoidRemapping
                imageFeatures.DerivativeSigma = self.FeatureDerivativeSigma
                imageFeatures.UpwindFactor = self.UpwindFactor
                imageFeatures.FWHMRadius = self.FWHMRadius
                imageFeatures.FWHMBackgroundValue = self.FWHMBackgroundValue
                imageFeatures.Execute()
                self.FeatureImage = imageFeatures.FeatureImage
            elif self.LevelSetsType in ["threshold", "laplacian"]:
                self.FeatureImage = self.Image
            else:
                self.PrintError('Unsupported LevelSetsType')

        if self.NumberOfIterations != 0:
            self.LevelSetsInput = self.InitialLevelSets
            self.LevelSetEvolution()
            self.MergeLevelSet()
            return

        if not self.vmtkRenderer:
            self.vmtkRenderer = vmtkscripts.vmtkRenderer()
            self.vmtkRenderer.Initialize()
            self.OwnRenderer = 1
 
        self.vmtkRenderer.RegisterScript(self)  

        self.ImageSeeder = vmtkscripts.vmtkImageSeeder()
        self.ImageSeeder.vmtkRenderer = self.vmtkRenderer
        #self.ImageSeeder.Image = self.Image
        self.ImageSeeder.Image = self.InitializationImage
        self.ImageSeeder.Display = 0
        self.ImageSeeder.Execute()
        ##self.ImageSeeder.Display = 1
        self.ImageSeeder.BuildView()
 
        self.SurfaceViewer = vmtkscripts.vmtkSurfaceViewer()
        self.SurfaceViewer.vmtkRenderer = self.vmtkRenderer
  
        if self.LevelSets != None:
            self.DisplayLevelSetSurface(self.LevelSets,0.0)
  
        self.vmtkImageInitialization = vmtkscripts.vmtkImageInitialization()
        #self.vmtkImageInitialization.Image = self.Image
        self.vmtkImageInitialization.Image = self.InitializationImage
        self.vmtkImageInitialization.vmtkRenderer = self.vmtkRenderer
        self.vmtkImageInitialization.ImageSeeder = self.ImageSeeder
        self.vmtkImageInitialization.SurfaceViewer = self.SurfaceViewer
        self.vmtkImageInitialization.NegateImage = self.NegateForInitialization
        self.vmtkImageInitialization.OwnRenderer = 0
 
        endSegmentation = 0
        while (endSegmentation == 0):
  
            if self.InitialLevelSets == None:
                self.vmtkImageInitialization.Execute()
                self.LevelSetsInput = self.vmtkImageInitialization.InitialLevelSets
#                self.IsoSurfaceValue = self.vmtkImageInitialization.IsoSurfaceValue
                self.vmtkImageInitialization.InitialLevelSets = None
#                self.vmtkImageInitialization.IsosurfaceValue = 0.0
                self.IsoSurfaceValue = 0.0
            else:
                self.LevelSetsInput = self.InitialLevelSets
                self.InitialLevelSets = None
                self.DisplayLevelSetSurface(self.LevelSetsInput,self.IsoSurfaceValue)
  
            endEvolution = False
            while not endEvolution:
  
                queryString = 'Please input parameters (type return to accept current values, \'e\' to end, \'q\' to quit):\nNumberOfIterations('+str(self.NumberOfIterations)+') [PropagationScaling('+str(self.PropagationScaling)+') CurvatureScaling('+str(self.CurvatureScaling)+') AdvectionScaling('+str(self.AdvectionScaling)+')]: '
                inputString = self.InputText(queryString,self.EvolutionParametersValidator)
  
                if inputString == 'q':
                    return
                elif inputString == 'e':
                    endEvolution = True
                elif inputString != '':
                    splitInputString = inputString.strip().split(' ')
                    if len(splitInputString) == 1:
                        self.NumberOfIterations = int(splitInputString[0])
                    elif len(splitInputString) == 4:
                        self.NumberOfIterations = int(splitInputString[0])
                        self.PropagationScaling = float(splitInputString[1])
                        self.CurvatureScaling = float(splitInputString[2])
                        self.AdvectionScaling = float(splitInputString[3])
                    else:
                        self.PrintLog('Wrong number of parameters.')
                        continue
  
                if endEvolution:
                    break
  
                self.LevelSetEvolution()
                self.DisplayLevelSetSurface(self.LevelSetsOutput)
  
                queryString = 'Accept result? (y/n): '
                inputString = self.InputText(queryString,self.YesNoValidator)
                if inputString == 'y':
                    endEvolution = True
                elif inputString == 'n':
                    endEvolution = False
  
            queryString = 'Merge branch? (y/n): '
            inputString = self.InputText(queryString,self.YesNoValidator)
            if inputString == 'y':
                self.MergeLevelSet()
            elif inputString == 'n':
                pass
 
            if self.LevelSets != None: 
                self.DisplayLevelSetSurface(self.LevelSets)
  
            queryString = 'Segment another branch? (y/n): '
            inputString = self.InputText(queryString,self.YesNoValidator)
            if inputString == 'y':
                endSegmentation = False
            elif inputString == 'n':
                endSegmentation = True
        if self.OwnRenderer:
            self.vmtkRenderer.Deallocate()
コード例 #8
0
    branchMetrics.ComputeAngularMetric = 0
    branchMetrics.Execute()

    surfaceWriter = vmtkscripts.vmtkSurfaceWriter()
    surfaceWriter.Surface = branchMetrics.Surface
    surfaceWriter.Format = 'vtkxml'
    surfaceWriter.Mode = 'ascii'
    surfaceWriter.OutputinputSurface = fname1
    surfaceWriter.Execute()
    surfaceWriter = vmtkscripts.vmtkSurfaceWriter()
    surfaceWriter.Format = 'vtkxml'
    surfaceWriter.Surface = branchClipper.Centerlines
    surfaceWriter.Mode = 'ascii'
    surfaceWriter.OutputinputSurface = fname2
    surfaceWriter.Execute()

    for diameter in diameters:
        outputName = fname1.split('.') + str(diameter) + 'mm.vtp'
        vessel = VesselTruncation()
        vessel.SetInputSurface(branchMetrics.Surface)
        vessel.SetInputCenterlines(branchClipper.Centerlines)
        vessel.SetDiameter(diameter)
        vessel.SetOutputinputSurface(outputName)
        vessel.Update()
        vessel.Write()
        vessel.GetVolume()

vmtksurfaceviewer = vmtkscripts.vmtkSurfaceViewer()
vmtksurfaceviewer.Surface = vessel.GetOutput()
vmtksurfaceviewer.Execute()
コード例 #9
0
    def Execute(self):
        from vmtk import vmtkscripts
        if self.Image == None:
            self.PrintError('Error: no Image.')

        cast = vtk.vtkImageCast()
        cast.SetInputData(self.Image)
        cast.SetOutputScalarTypeToFloat()
        cast.Update()
        self.Image = cast.GetOutput()

        if self.NegateImage:
            scalarRange = self.Image.GetScalarRange()
            negate = vtk.vtkImageMathematics()
            negate.SetInputData(self.Image)
            negate.SetOperationToMultiplyByK()
            negate.SetConstantK(-1.0)
            negate.Update()
            shiftScale = vtk.vtkImageShiftScale()
            shiftScale.SetInputConnection(negate.GetOutputPort())
            shiftScale.SetShift(scalarRange[1] + scalarRange[0])
            shiftScale.SetOutputScalarTypeToFloat()
            shiftScale.Update()
            self.Image = shiftScale.GetOutput()

        if self.Interactive:
            if not self.vmtkRenderer:
                self.vmtkRenderer = vmtkscripts.vmtkRenderer()
                self.vmtkRenderer.Initialize()
                self.OwnRenderer = 1

            self.vmtkRenderer.RegisterScript(self)

            if not self.ImageSeeder:
                self.ImageSeeder = vmtkscripts.vmtkImageSeeder()
                self.ImageSeeder.vmtkRenderer = self.vmtkRenderer
                self.ImageSeeder.Image = self.Image
                self.ImageSeeder.Display = 0
                self.ImageSeeder.Execute()
                ##self.ImageSeeder.Display = 1
                self.ImageSeeder.BuildView()

            if not self.SurfaceViewer:
                self.SurfaceViewer = vmtkscripts.vmtkSurfaceViewer()
                self.SurfaceViewer.vmtkRenderer = self.vmtkRenderer

            initializationMethods = {
                '0': self.CollidingFrontsInitialize,
                '1': self.FastMarchingInitialize,
                '2': self.ThresholdInitialize,
                '3': self.IsosurfaceInitialize,
                '4': self.SeedInitialize
            }

            endInitialization = False
            while not endInitialization:
                queryString = 'Please choose initialization type: \n 0: colliding fronts;\n 1: fast marching;\n 2: threshold;\n 3: isosurface;\n 4: seed\n '
                initializationType = self.InputText(
                    queryString, self.InitializationTypeValidator)
                initializationMethods[initializationType]()
                self.DisplayLevelSetSurface(self.InitialLevelSets)
                queryString = 'Accept initialization? (y/n): '
                inputString = self.InputText(queryString, self.YesNoValidator)
                if inputString == 'y':
                    self.MergeLevelSets()
                    self.DisplayLevelSetSurface(self.MergedInitialLevelSets)
                queryString = 'Initialize another branch? (y/n): '
                inputString = self.InputText(queryString, self.YesNoValidator)
                if inputString == 'y':
                    endInitialization = False
                elif inputString == 'n':
                    endInitialization = True

            self.InitialLevelSets = self.MergedInitialLevelSets
            self.MergedInitialLevelSets = None

        else:
            if self.Method == "collidingfronts":
                self.CollidingFrontsInitialize()
            elif self.Method == "fastmarching":
                self.FastMarchingInitialize()
            elif self.Method == "threshold":
                self.ThresholdInitialize()
            elif self.Method == "isosurface":
                self.IsosurfaceInitialize()
            elif self.Method == "seeds":
                self.SeedInitialize()

        if self.OwnRenderer:
            self.vmtkRenderer.Deallocate()
コード例 #10
0
ファイル: vmtkimageinitialization.py プロジェクト: vmtk/vmtk
    def Execute(self):
        from vmtk import vmtkscripts
        if self.Image == None:
            self.PrintError('Error: no Image.')

        cast = vtk.vtkImageCast()
        cast.SetInputData(self.Image)
        cast.SetOutputScalarTypeToFloat()
        cast.Update()
        self.Image = cast.GetOutput()

        if self.NegateImage:
            scalarRange = self.Image.GetScalarRange()
            negate = vtk.vtkImageMathematics()
            negate.SetInputData(self.Image)
            negate.SetOperationToMultiplyByK()
            negate.SetConstantK(-1.0)
            negate.Update()
            shiftScale = vtk.vtkImageShiftScale()
            shiftScale.SetInputConnection(negate.GetOutputPort())
            shiftScale.SetShift(scalarRange[1]+scalarRange[0])
            shiftScale.SetOutputScalarTypeToFloat()
            shiftScale.Update()
            self.Image = shiftScale.GetOutput()

        if self.Interactive:
            if not self.vmtkRenderer:
                self.vmtkRenderer = vmtkscripts.vmtkRenderer()
                self.vmtkRenderer.Initialize()
                self.OwnRenderer = 1

            self.vmtkRenderer.RegisterScript(self) 
 
            if not self.ImageSeeder: 
                self.ImageSeeder = vmtkscripts.vmtkImageSeeder()
                self.ImageSeeder.vmtkRenderer = self.vmtkRenderer
                self.ImageSeeder.Image = self.Image
                self.ImageSeeder.Display = 0
                self.ImageSeeder.Execute()
                ##self.ImageSeeder.Display = 1
                self.ImageSeeder.BuildView()
  
            if not self.SurfaceViewer:
                self.SurfaceViewer = vmtkscripts.vmtkSurfaceViewer()
                self.SurfaceViewer.vmtkRenderer = self.vmtkRenderer
  
            initializationMethods = {
                                '0': self.CollidingFrontsInitialize,
                                '1': self.FastMarchingInitialize,
                                '2': self.ThresholdInitialize,
                                '3': self.IsosurfaceInitialize,
                                '4': self.SeedInitialize
                                }
  
            endInitialization = False
            while not endInitialization:
                queryString = 'Please choose initialization type: \n 0: colliding fronts;\n 1: fast marching;\n 2: threshold;\n 3: isosurface;\n 4: seed\n '
                initializationType = self.InputText(queryString,self.InitializationTypeValidator)
                initializationMethods[initializationType]()
                self.DisplayLevelSetSurface(self.InitialLevelSets)
                queryString = 'Accept initialization? (y/n): '
                inputString = self.InputText(queryString,self.YesNoValidator)
                if inputString == 'y':
                    self.MergeLevelSets()
                    self.DisplayLevelSetSurface(self.MergedInitialLevelSets)
                queryString = 'Initialize another branch? (y/n): '
                inputString = self.InputText(queryString,self.YesNoValidator)
                if inputString == 'y':
                    endInitialization = False
                elif inputString == 'n':
                    endInitialization = True

            self.InitialLevelSets = self.MergedInitialLevelSets
            self.MergedInitialLevelSets = None

        else:
            if self.Method == "collidingfronts":
                self.CollidingFrontsInitialize()
            elif self.Method == "fastmarching":
                self.FastMarchingInitialize()
            elif self.Method == "threshold":
                self.ThresholdInitialize()
            elif self.Method == "isosurface":
                self.IsosurfaceInitialize()
            elif self.Method == "seeds":
                self.SeedInitialize()

        if self.OwnRenderer:
            self.vmtkRenderer.Deallocate()
コード例 #11
0
        acceptableResult = 0
        while acceptableResult == 0:
            
            self.Surface = None

            self.LevelSetSegmentation = vmtkscripts.vmtkLevelSetSegmentation()
            self.LevelSetSegmentation.Image = self.Image
            self.LevelSetSegmentation.Execute()
            self.Image = self.LevelSetSegmentation.Image

            self.MarchingCubes = vmtkscripts.vmtkMarchingCubes()
            self.MarchingCubes.Image = self.Image
            self.MarchingCubes.Execute()
            self.Surface = self.MarchingCubes.Surface

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

            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