Beispiel #1
0
    def Execute(self):

        if self.Centerlines == None:
            self.PrintError('Error: No input centerlines.')

        if self.ReferenceSystems == None:
            self.PrintError('Error: No input reference systems.')

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

            self.vmtkRenderer.RegisterScript(self) 

            viewer = vmtkcenterlineviewer.vmtkCenterlineViewer()
            viewer.Centerlines = self.Centerlines
            viewer.CellDataArrayName = self.GroupIdsArrayName
            viewer.vmtkRenderer = self.vmtkRenderer
            viewer.InputText = self.InputText
            viewer.OutputText = self.OutputText
            viewer.PrintError = self.PrintError
            viewer.PringLog = self.PrintLog
            viewer.Display = 0
	    viewer.Execute()
            
            groupIdString = self.InputText("Please input the reference groupId:\n",self.GroupIdValidator)
            self.ReferenceGroupId = int(groupIdString)

        offsetFilter = vtkvmtk.vtkvmtkCenterlineReferenceSystemAttributesOffset()
        offsetFilter.SetInput(self.Centerlines)
        offsetFilter.SetReferenceSystems(self.ReferenceSystems)
        offsetFilter.SetAbscissasArrayName(self.AbscissasArrayName)
        offsetFilter.SetNormalsArrayName(self.NormalsArrayName)
        if not self.ReplaceAttributes:
            offsetFilter.SetOffsetAbscissasArrayName(self.OffsetAbscissasArrayName)
            offsetFilter.SetOffsetNormalsArrayName(self.OffsetNormalsArrayName)
        else:
            offsetFilter.SetOffsetAbscissasArrayName(self.AbscissasArrayName)
            offsetFilter.SetOffsetNormalsArrayName(self.NormalsArrayName)
        offsetFilter.SetGroupIdsArrayName(self.GroupIdsArrayName)
        offsetFilter.SetCenterlineIdsArrayName(self.CenterlineIdsArrayName)
        offsetFilter.SetReferenceSystemsNormalArrayName(self.ReferenceSystemsNormalArrayName)
        offsetFilter.SetReferenceSystemsGroupIdsArrayName(self.GroupIdsArrayName)
        offsetFilter.SetReferenceGroupId(self.ReferenceGroupId)
        offsetFilter.Update()
        
        self.Centerlines = offsetFilter.GetOutput()

        if self.ReferenceGroupId == -1:
            self.ReferenceGroupId = offsetFilter.GetReferenceGroupId()

        if self.Centerlines.GetSource():
            self.Centerlines.GetSource().UnRegisterAllOutputs()

        if self.OwnRenderer:
            self.vmtkRenderer.Deallocate()
    def Execute(self):

        if not self.Centerlines:
            self.PrintError('Error: No input centerlines.')
 
        if not self.GroupIdsArrayName:
            self.PrintError('Error: GroupIdsArrayName not specified.')
     
        if not self.vmtkRenderer:
            self.vmtkRenderer = vmtkrenderer.vmtkRenderer()
            self.vmtkRenderer.Initialize()
            self.OwnRenderer = 1

        self.vmtkRenderer.RegisterScript(self)
        
        groupIdsArray = self.Centerlines.GetCellData().GetArray(self.GroupIdsArrayName)
        groupIds = []
        for i in range(groupIdsArray.GetNumberOfTuples()):
            groupIds.append(int(groupIdsArray.GetComponent(i,0)))
        groupIds.sort()
        uniqueGroupIds = []
        for groupId in groupIds:
            if groupId not in uniqueGroupIds:
                uniqueGroupIds.append(groupId)
 
        labelMap = {}
        
        if not self.Labeling:
        
            viewer = vmtkcenterlineviewer.vmtkCenterlineViewer()
            viewer.Centerlines = self.Centerlines
            viewer.CellDataArrayName = self.GroupIdsArrayName
            viewer.vmtkRenderer = self.vmtkRenderer
            viewer.InputStream = self.InputStream
            viewer.OutputStream = self.OutputStream
            #viewer.InputText = self.InputText
            #viewer.OutputText = self.OutputText
            #viewer.PrintError = self.PrintError
            #viewer.PringLog = self.PrintLog
            viewer.Execute()
           
            ok = False
            while not ok:
                labelString = self.InputText("Please input labels for the following groupIds:\n%s\n" % " ".join([str(groupId) for groupId in uniqueGroupIds]),self.LabelValidator)
                labels = [int(label) for label in labelString.split()]
                if len(labels) == len(uniqueGroupIds):
                    ok = True

            for groupId in uniqueGroupIds:
                labelMap[groupId] = labels[uniqueGroupIds.index(groupId)]

        else:
 
            if len(self.Labeling) != 2 * len(uniqueGroupIds):
                self.PrintError('Error: incorrect labeling specified')

            for i in range(len(self.Labeling)/2):
                groupId = self.Labeling[2*i]
                labelId = self.Labeling[2*i+1]
                if not groupId in uniqueGroupIds:
                    self.PrintError('Error: groupId %d does not exist' % groupId)
                labelMap[groupId] = labelId
 
        labelIdsArray = vtk.vtkIntArray()
        labelIdsArray.SetName(self.LabelIdsArrayName)
        labelIdsArray.SetNumberOfComponents(1)
        labelIdsArray.SetNumberOfTuples(self.Centerlines.GetNumberOfCells())

        groupIdsArray = self.Centerlines.GetCellData().GetArray(self.GroupIdsArrayName)
        
        for i in range(groupIdsArray.GetNumberOfTuples()):
            groupId = int(groupIdsArray.GetComponent(i,0))
            labelIdsArray.SetComponent(i,0,labelMap[groupId])
        
        self.Centerlines.GetCellData().AddArray(labelIdsArray)

        if self.OwnRenderer:
            self.vmtkRenderer.Deallocate()
Beispiel #3
0
    def Execute(self):

        if not self.Surface:
            self.PrintError("Error: No input surface.")

        if not self.Centerlines:
            self.PrintError("Error: No input centerlines.")

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

        if self.Interactive:

            viewer = vmtkcenterlineviewer.vmtkCenterlineViewer()
            viewer.Centerlines = self.Centerlines
            viewer.CellDataArrayName = self.GroupIdsArrayName
            viewer.vmtkRenderer = self.vmtkRenderer
            viewer.InputText = self.InputText
            viewer.OutputText = self.OutputText
            viewer.PrintError = self.PrintError
            viewer.PringLog = self.PrintLog
            viewer.Execute()

            groupIdsString = self.InputText("Please input groupIds to clip:\n", self.GroupIdsValidator)
            self.GroupIds = [int(groupId) for groupId in groupIdsString.split()]

        clipper = vtkvmtk.vtkvmtkPolyDataCenterlineGroupsClipper()
        clipper.SetInput(self.Surface)
        clipper.SetCenterlines(self.Centerlines)
        clipper.SetCenterlineGroupIdsArrayName(self.GroupIdsArrayName)
        clipper.SetGroupIdsArrayName(self.GroupIdsArrayName)
        clipper.SetCenterlineRadiusArrayName(self.RadiusArrayName)
        clipper.SetBlankingArrayName(self.BlankingArrayName)
        clipper.SetCutoffRadiusFactor(self.CutoffRadiusFactor)
        clipper.SetClipValue(self.ClipValue)
        clipper.SetUseRadiusInformation(self.UseRadiusInformation)
        if self.GroupIds:
            groupIds = vtk.vtkIdList()
            for groupId in self.GroupIds:
                groupIds.InsertNextId(groupId)
            clipper.SetCenterlineGroupIds(groupIds)
            clipper.ClipAllCenterlineGroupIdsOff()
        else:
            clipper.ClipAllCenterlineGroupIdsOn()
        if not self.InsideOut:
            clipper.GenerateClippedOutputOff()
        else:
            clipper.GenerateClippedOutputOn()
        clipper.Update()

        if not self.InsideOut:
            self.Surface = clipper.GetOutput()
        else:
            self.Surface = clipper.GetClippedOutput()

        if self.Surface:
            if self.Surface.GetSource():
                self.Surface.GetSource().UnRegisterAllOutputs()

        if self.Centerlines.GetSource():
            self.Centerlines.GetSource().UnRegisterAllOutputs()

        if self.OwnRenderer:
            self.vmtkRenderer.Deallocate()
Beispiel #4
0
    def Execute(self):

        if not self.Mesh:
            self.PrintError('Error: No input mesh.')

        if not self.Centerlines:
            self.PrintError('Error: No input centerlines.')

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

        if self.Interactive:

            viewer = vmtkcenterlineviewer.vmtkCenterlineViewer()
            viewer.Centerlines = self.Centerlines
            viewer.CellDataArrayName = self.GroupIdsArrayName
            viewer.vmtkRenderer = self.vmtkRenderer
            viewer.InputText = self.InputText
            viewer.OutputText = self.OutputText
            viewer.PrintError = self.PrintError
            viewer.PringLog = self.PrintLog
            viewer.Execute()

            groupIdsString = self.InputText("Please input groupIds to clip:\n",
                                            self.GroupIdsValidator)
            self.GroupIds = [
                int(groupId) for groupId in groupIdsString.split()
            ]

        clipper = vtkvmtk.vtkvmtkUnstructuredGridCenterlineGroupsClipper()
        clipper.SetInput(self.Mesh)
        clipper.SetCenterlines(self.Centerlines)
        clipper.SetCenterlineGroupIdsArrayName(self.GroupIdsArrayName)
        clipper.SetGroupIdsArrayName(self.GroupIdsArrayName)
        clipper.SetCenterlineRadiusArrayName(self.RadiusArrayName)
        clipper.SetBlankingArrayName(self.BlankingArrayName)
        clipper.SetCutoffRadiusFactor(self.CutoffRadiusFactor)
        clipper.SetClipValue(self.ClipValue)
        clipper.SetUseRadiusInformation(self.UseRadiusInformation)
        if self.GroupIds:
            groupIds = vtk.vtkIdList()
            for groupId in self.GroupIds:
                groupIds.InsertNextId(groupId)
            clipper.SetCenterlineGroupIds(groupIds)
            clipper.ClipAllCenterlineGroupIdsOff()
        else:
            clipper.ClipAllCenterlineGroupIdsOn()
        if not self.InsideOut:
            clipper.GenerateClippedOutputOff()
        else:
            clipper.GenerateClippedOutputOn()
        clipper.Update()

        if not self.InsideOut:
            self.Mesh = clipper.GetOutput()
        else:
            self.Mesh = clipper.GetClippedOutput()

        if self.Mesh:
            if self.Mesh.GetSource():
                self.Mesh.GetSource().UnRegisterAllOutputs()

        if self.Centerlines.GetSource():
            self.Centerlines.GetSource().UnRegisterAllOutputs()

        if self.OwnRenderer:
            self.vmtkRenderer.Deallocate()