File: vmtklineartoquadratic.py

package info (click to toggle)
vmtk 1.3%2Bdfsg-2.1%2Bdeb9u1
  • links: PTS, VCS
  • area: non-free
  • in suites: stretch
  • size: 8,932 kB
  • sloc: cpp: 82,947; ansic: 31,817; python: 21,462; perl: 381; makefile: 93; ruby: 41; sh: 19
file content (108 lines) | stat: -rw-r--r-- 5,106 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
#!/usr/bin/env python

## Program:   VMTK
## Module:    $RCSfile: vmtklineartoquadratic.py,v $
## Language:  Python
## Date:      $Date: 2005/09/14 09:49:59 $
## Version:   $Revision: 1.7 $

##   Copyright (c) Luca Antiga, David Steinman. All rights reserved.
##   See LICENCE file for details.

##      This software is distributed WITHOUT ANY WARRANTY; without even 
##      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
##      PURPOSE.  See the above copyright notices for more information.


import vtk
import vtkvmtk
import sys

import pypes

vmtklineartoquadratic = 'vmtkLinearToQuadratic'

class vmtkLinearToQuadratic(pypes.pypeScript):

    def __init__(self):

        pypes.pypeScript.__init__(self)
        
        self.Mesh = None
        self.Surface = None
        self.Mode = 'volume'
        self.SubdivisionMethod = 'linear'
        self.NumberOfNodesHexahedra = 27
        self.UseBiquadraticWedge = True
        self.CapSurface = False
        self.CellEntityIdsArrayName = None
        self.ProjectedCellEntityId = 1
        self.JacobianRelaxation = 0
        self.NegativeJacobianTolerance = 0.0
        self.QuadratureOrder = 10

        self.SetScriptName('vmtklineartoquadratic')
        self.SetScriptDoc('convert the elements of a mesh from linear to quadratic')
        self.SetInputMembers([
            ['Mesh','i','vtkUnstructuredGrid',1,'','the input mesh','vmtkmeshreader'],
            ['Surface','r','vtkPolyData',1,'','the reference surface to project nodes onto','vmtksurfacereader'],
            ['Mode','mode','str',1,'["volume","surface"]','kind of elements to work with'],
            ['UseBiquadraticWedge','biquadraticwedge','bool',1,'','if on, convert linear wedges to 18-noded biquadratic quadratic wedges, otherwise use 15-noded quadratic wedges'],
            ['CapSurface','capsurface','bool',1,'','if on, cap the reference surface before projecting'],
            ['CellEntityIdsArrayName','entityidsarray','str',1,'','name of the array where entity ids relative to cells are stored'],
            ['JacobianRelaxation','jacobianrelaxation','bool',1,'','if on, relax projected nodes until Jacobians are all positive'],
            ['ProjectedCellEntityId','projectedid','int',1,'','id of the entity that is to be projected onto the reference surface'],
            ['QuadratureOrder','quadratureorder','int',1,'','quadrature order for checking negative Jacobians'],
            ['NegativeJacobianTolerance','jacobiantolerance','float',1,'','tolerance for the evaluation of negative Jacobians'],
            ['SubdivisionMethod','subdivisionmethod','str',1,'["linear","butterfly"]','subdivision method for surface elements'],
            ['NumberOfNodesHexahedra','hexahedranodes','int',1,'','Output hexahedral element type by # of nodes: 20 or 27 (see vtkQuadraticHexahedron and vtkTriQuadraticHexahedron classes in VTK documentation)']
            ])
        self.SetOutputMembers([
            ['Mesh','o','vtkUnstructuredGrid',1,'','the output mesh','vmtkmeshwriter']])

    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.SetInputData(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.SetInputData(self.Mesh)
        linearToQuadraticFilter.Update()

        self.Mesh = linearToQuadraticFilter.GetOutput()


if __name__=='__main__':

    main = pypes.pypeMain()
    main.Arguments = sys.argv
    main.Execute()