예제 #1
0
    def Execute(self):

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

        if self.GenerateCaps == 1:
            if not ((self.Mesh.IsHomogeneous() == 1) &
                    (self.Mesh.GetCellType(0) == 5)):
                self.PrintError(
                    'Error: In order to generate caps, all input mesh elements must be triangles.'
                )
            meshToSurfaceFilter = vtk.vtkGeometryFilter()
            meshToSurfaceFilter.SetInput(self.Mesh)
            meshToSurfaceFilter.Update()
            cap = vtkvmtk.vtkvmtkSimpleCapPolyData()
            cap.SetInput(meshToSurfaceFilter.GetOutput())
            cap.SetCellMarkerArrayName(self.FacetMarkerArrayName)
            cap.Update()
            surfacetomesh = vtkvmtk.vtkvmtkPolyDataToUnstructuredGridFilter()
            surfacetomesh.SetInput(cap.GetOutput())
            surfacetomesh.Update()
            self.Mesh = surfacetomesh.GetOutput()

        tetgen = vtkvmtk.vtkvmtkTetGenWrapper()
        tetgen.SetInput(self.Mesh)
        tetgen.SetPLC(self.PLC)
        tetgen.SetRefine(self.Refine)
        tetgen.SetCoarsen(self.Coarsen)
        tetgen.SetNoBoundarySplit(self.NoBoundarySplit)
        tetgen.SetQuality(self.Quality)
        tetgen.SetMinRatio(self.MinRatio)
        tetgen.SetMinDihedral(self.MinDihedral)
        tetgen.SetMaxDihedral(self.MaxDihedral)
        tetgen.SetVarVolume(self.VarVolume)
        tetgen.SetFixedVolume(self.FixedVolume)
        tetgen.SetMaxVolume(self.MaxVolume)
        tetgen.SetRemoveSliver(self.RemoveSliver)
        tetgen.SetRegionAttrib(self.RegionAttrib)
        tetgen.SetEpsilon(self.Epsilon)
        tetgen.SetNoMerge(self.NoMerge)
        tetgen.SetDetectInter(self.DetectInter)
        tetgen.SetCheckClosure(self.CheckClosure)
        tetgen.SetOrder(self.Order)
        tetgen.SetDoCheck(self.DoCheck)
        tetgen.SetVerbose(self.Verbose)
        tetgen.SetUseSizingFunction(self.UseSizingFunction)
        tetgen.SetCellEntityIdsArrayName(self.CellEntityIdsArrayName)
        tetgen.SetTetrahedronVolumeArrayName(self.TetrahedronVolumeArrayName)
        tetgen.SetSizingFunctionArrayName(self.SizingFunctionArrayName)
        tetgen.SetOutputSurfaceElements(self.OutputSurfaceElements)
        tetgen.SetOutputVolumeElements(self.OutputVolumeElements)
        tetgen.Update()

        self.Mesh = tetgen.GetOutput()

        if self.Mesh.GetSource():
            self.Mesh.GetSource().UnRegisterAllOutputs()
예제 #2
0
    def Execute(self):

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

        if self.GenerateCaps == 1:
            if not ((self.Mesh.IsHomogeneous() == 1) & (self.Mesh.GetCellType(0) == 5)):
                self.PrintError('Error: In order to generate caps, all input mesh elements must be triangles.')
            meshToSurfaceFilter = vtk.vtkGeometryFilter()
            meshToSurfaceFilter.SetInputData(self.Mesh)
            meshToSurfaceFilter.Update()
            cap = vtkvmtk.vtkvmtkSimpleCapPolyData()
            cap.SetInputConnection(meshToSurfaceFilter.GetOutputPort())
            cap.SetCellMarkerArrayName(self.FacetMarkerArrayName)
            cap.Update()
            surfacetomesh = vtkvmtk.vtkvmtkPolyDataToUnstructuredGridFilter()
            surfacetomesh.SetInputConnection(cap.GetOutputPort())
            surfacetomesh.Update()
            self.Mesh = surfacetomesh.GetOutput()

        tetgen = vtkvmtk.vtkvmtkTetGenWrapper()
        tetgen.SetInputData(self.Mesh)
        tetgen.SetPLC(self.PLC)
        tetgen.SetRefine(self.Refine)
        tetgen.SetCoarsen(self.Coarsen)
        tetgen.SetNoBoundarySplit(self.NoBoundarySplit)
        tetgen.SetQuality(self.Quality)
        tetgen.SetMinRatio(self.MinRatio)
        tetgen.SetMinDihedral(self.MinDihedral)
        tetgen.SetMaxDihedral(self.MaxDihedral)
        tetgen.SetVarVolume(self.VarVolume)
        tetgen.SetFixedVolume(self.FixedVolume)
        tetgen.SetMaxVolume(self.MaxVolume)
        tetgen.SetRemoveSliver(self.RemoveSliver)
        tetgen.SetRegionAttrib(self.RegionAttrib)
        tetgen.SetEpsilon(self.Epsilon)
        tetgen.SetNoMerge(self.NoMerge)
        tetgen.SetDetectInter(self.DetectInter)
        tetgen.SetCheckClosure(self.CheckClosure)
        tetgen.SetOrder(self.Order)
        tetgen.SetDoCheck(self.DoCheck)
        tetgen.SetVerbose(self.Verbose)
        tetgen.SetUseSizingFunction(self.UseSizingFunction)
        tetgen.SetCellEntityIdsArrayName(self.CellEntityIdsArrayName)
        tetgen.SetTetrahedronVolumeArrayName(self.TetrahedronVolumeArrayName)
        tetgen.SetSizingFunctionArrayName(self.SizingFunctionArrayName)
        tetgen.SetOutputSurfaceElements(self.OutputSurfaceElements)
        tetgen.SetOutputVolumeElements(self.OutputVolumeElements)
        tetgen.Update()

        self.Mesh = tetgen.GetOutput()
예제 #3
0
    def Execute(self):

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

        linearToQuadraticFilter = None

        if self.Mode == 'volume':
            surface = self.Surface
            if self.Surface and self.CapSurface:
                capper = vtkvmtk.vtkvmtkSimpleCapPolyData()
                capper.SetInput(self.Surface)
                capper.SetCellEntityIdsArrayName('foo')
                capper.Update()
                surface = capper.GetOutput()
            linearToQuadraticFilter = vtkvmtk.vtkvmtkLinearToQuadraticMeshFilter(
            )
            linearToQuadraticFilter.SetReferenceSurface(surface)
            linearToQuadraticFilter.SetUseBiquadraticWedge(
                self.UseBiquadraticWedge)
            linearToQuadraticFilter.SetCellEntityIdsArrayName(
                self.CellEntityIdsArrayName)
            linearToQuadraticFilter.SetJacobianRelaxation(
                self.JacobianRelaxation)
            linearToQuadraticFilter.SetProjectedCellEntityId(
                self.ProjectedCellEntityId)
            linearToQuadraticFilter.SetQuadratureOrder(self.QuadratureOrder)
            linearToQuadraticFilter.SetNegativeJacobianTolerance(
                self.NegativeJacobianTolerance)
            linearToQuadraticFilter.SetNumberOfNodesHexahedra(
                self.NumberOfNodesHexahedra)
        elif self.Mode == 'surface':
            linearToQuadraticFilter = vtkvmtk.vtkvmtkLinearToQuadraticSurfaceMeshFilter(
            )
            if self.SubdivisionMethod == 'linear':
                linearToQuadraticFilter.SetSubdivisionMethodToLinear()
            elif self.SubdivisionMethod == 'butterfly':
                linearToQuadraticFilter.SetSubdivisionMethodToButterfly()
            else:
                self.PrintError('Unsupported subdivision method.')
        else:
            self.PrintError('Unsupported mode.')

        linearToQuadraticFilter.SetInput(self.Mesh)
        linearToQuadraticFilter.Update()

        self.Mesh = linearToQuadraticFilter.GetOutput()

        if self.Mesh.GetSource():
            self.Mesh.GetSource().UnRegisterAllOutputs()
예제 #4
0
    def Execute(self):

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

        linearToQuadraticFilter = None

        if self.Mode == 'volume':
            surface = self.Surface
            if self.Surface and self.CapSurface:
                capper = vtkvmtk.vtkvmtkSimpleCapPolyData()
                capper.SetInput(self.Surface)
                capper.SetCellEntityIdsArrayName('foo') 
                capper.Update()
                surface = capper.GetOutput()
            linearToQuadraticFilter = vtkvmtk.vtkvmtkLinearToQuadraticMeshFilter()
            linearToQuadraticFilter.SetReferenceSurface(surface)
            linearToQuadraticFilter.SetUseBiquadraticWedge(self.UseBiquadraticWedge)
            linearToQuadraticFilter.SetCellEntityIdsArrayName(self.CellEntityIdsArrayName)
            linearToQuadraticFilter.SetJacobianRelaxation(self.JacobianRelaxation)
            linearToQuadraticFilter.SetProjectedCellEntityId(self.ProjectedCellEntityId)
            linearToQuadraticFilter.SetQuadratureOrder(self.QuadratureOrder)
            linearToQuadraticFilter.SetNegativeJacobianTolerance(self.NegativeJacobianTolerance)
            linearToQuadraticFilter.SetNumberOfNodesHexahedra(self.NumberOfNodesHexahedra)
        elif self.Mode == 'surface':
            linearToQuadraticFilter = vtkvmtk.vtkvmtkLinearToQuadraticSurfaceMeshFilter()
            if self.SubdivisionMethod == 'linear':
                linearToQuadraticFilter.SetSubdivisionMethodToLinear()
            elif self.SubdivisionMethod == 'butterfly':
                linearToQuadraticFilter.SetSubdivisionMethodToButterfly()
            else:
                self.PrintError('Unsupported subdivision method.')
        else:
            self.PrintError('Unsupported mode.')

        linearToQuadraticFilter.SetInput(self.Mesh)
        linearToQuadraticFilter.Update()

        self.Mesh = linearToQuadraticFilter.GetOutput()

        if self.Mesh.GetSource():
            self.Mesh.GetSource().UnRegisterAllOutputs()
예제 #5
0
    def Execute(self):

        if self.Surface == None:
            self.PrintError('Error: No input surface.')

#        cleaner = vtk.vtkCleanPolyData()
#        cleaner.SetInput(self.Surface)
#        cleaner.Update()
#
#        triangleFilter = vtk.vtkTriangleFilter()
#        triangleFilter.SetInput(cleaner.GetOutput())
#        triangleFilter.Update()
#
#        self.Surface = triangleFilter.GetOutput()

        boundaryIds = vtk.vtkIdList()

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

            self.vmtkRenderer.RegisterScript(self)

            boundaryExtractor = vtkvmtk.vtkvmtkPolyDataBoundaryExtractor()
            boundaryExtractor.SetInputData(self.Surface)
            boundaryExtractor.Update()

            boundaries = boundaryExtractor.GetOutput()
            numberOfBoundaries = boundaries.GetNumberOfCells()
            seedPoints = vtk.vtkPoints()
            for i in range(numberOfBoundaries):
                barycenter = [0.0, 0.0, 0.0]
                vtkvmtk.vtkvmtkBoundaryReferenceSystems.ComputeBoundaryBarycenter(boundaries.GetCell(i).GetPoints(),barycenter)
                seedPoints.InsertNextPoint(barycenter)
            seedPolyData = vtk.vtkPolyData()
            seedPolyData.SetPoints(seedPoints)
            labelsMapper = vtk.vtkLabeledDataMapper();
            labelsMapper.SetInputData(seedPolyData)
            labelsMapper.SetLabelModeToLabelIds()
            labelsActor = vtk.vtkActor2D()
            labelsActor.SetMapper(labelsMapper)

            self.vmtkRenderer.Renderer.AddActor(labelsActor)

            surfaceMapper = vtk.vtkPolyDataMapper()
            surfaceMapper.SetInputData(self.Surface)
            surfaceMapper.ScalarVisibilityOff()
            surfaceActor = vtk.vtkActor()
            surfaceActor.SetMapper(surfaceMapper)
            surfaceActor.GetProperty().SetOpacity(0.25)

            self.vmtkRenderer.Renderer.AddActor(surfaceActor)

            #self.vmtkRenderer.Render()
            #self.vmtkRenderer.Renderer.RemoveActor(labelsActor)
            #self.vmtkRenderer.Renderer.RemoveActor(surfaceActor)

            ok = False
            while not ok:
                labelString = self.InputText("Please input boundary ids: ",self.LabelValidator)
                labels = [int(label) for label in labelString.split()]
                ok = True
                for label in labels:
                    if label not in range(numberOfBoundaries):
                        ok = False

            for label in labels:
                boundaryIds.InsertNextId(label)

        if self.Method == 'simple':
            capper = vtkvmtk.vtkvmtkSimpleCapPolyData()
            capper.SetInputData(self.Surface)

        elif self.Method == 'centerpoint':
            capper = vtkvmtk.vtkvmtkCapPolyData()
            capper.SetInputData(self.Surface)
            capper.SetDisplacement(0.0)
            capper.SetInPlaneDisplacement(0.0)

        elif self.Method == 'smooth':
            triangle = vtk.vtkTriangleFilter()
            triangle.SetInputData(self.Surface)
            triangle.PassLinesOff()
            triangle.PassVertsOff()
            triangle.Update()
            capper = vtkvmtk.vtkvmtkSmoothCapPolyData()
            capper.SetInputConnection(triangle.GetOutputPort())
            capper.SetConstraintFactor(self.ConstraintFactor)
            capper.SetNumberOfRings(self.NumberOfRings)

        elif self.Method == 'annular':
            capper = vtkvmtk.vtkvmtkAnnularCapPolyData()
            capper.SetInputData(self.Surface)

        elif self.Method == 'concaveannular':
            import vtkvmtkcontrib
            capper = vtkvmtkcontrib.vtkvmtkConcaveAnnularCapPolyData()
            capper.SetInputData(self.Surface)

        if self.Interactive:
            capper.SetBoundaryIds(boundaryIds)
        capper.SetCellEntityIdsArrayName(self.CellEntityIdsArrayName)
        capper.SetCellEntityIdOffset(self.CellEntityIdOffset)
        capper.Update()
        self.Surface = capper.GetOutput()

        if self.TriangleOutput == 1:
            triangle = vtk.vtkTriangleFilter()
            triangle.SetInputData(self.Surface)
            triangle.PassLinesOff()
            triangle.PassVertsOff()
            triangle.Update()
            self.Surface = triangle.GetOutput()

        normals = vtk.vtkPolyDataNormals()
        normals.SetInputData(self.Surface)
        normals.AutoOrientNormalsOn()
        normals.SplittingOff()
        normals.ConsistencyOn()
        normals.Update()
        self.Surface = normals.GetOutput()