File: CreateTestSurf.py

package info (click to toggle)
vistrails 2.1.1-1
  • links: PTS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 74,208 kB
  • ctags: 46,250
  • sloc: python: 316,267; xml: 52,512; sql: 3,627; php: 731; sh: 260; makefile: 108
file content (102 lines) | stat: -rw-r--r-- 3,428 bytes parent folder | download
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
############################################################################
##
## Copyright (C) 2006-2007 University of Utah. All rights reserved.
##
## This file is part of VisTrails.
##
## This file may be used under the terms of the GNU General Public
## License version 2.0 as published by the Free Software Foundation
## and appearing in the file LICENSE.GPL included in the packaging of
## this file.  Please review the following to ensure GNU General Public
## Licensing requirements will be met:
## http://www.opensource.org/licenses/gpl-license.php
##
## If you are unsure which license is appropriate for your use (for
## instance, you are interested in developing a commercial derivative
## of VisTrails), please contact us at contact@vistrails.org.
##
## This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
## WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
##
############################################################################
import core.modules
import core.modules.module_registry
from core.modules.vistrails_module import Module, ModuleError
import packages.TetGenBridge
import TetGen
import re
import os

# TetGen output on this mesh. -pqAz
## Statistics:

##   Input points: 149
##   Input facets: 294
##   Input holes: 0
##   Input regions: 0

##   Mesh points: 2184
##   Mesh tetrahedra: 7462
##   Mesh faces: 16726
##   Mesh subfaces: 3604
##   Mesh subsegments: 2037

nodes_exp = re.compile('([\d\-\.]+)\s+([\d\-\.]+)\s+([\d\-\.]+)')
def getTestNodes() :
    nodes = []
    p = "%spackages%sTetGenBridge%s" % (os.sep, os.sep, os.sep)
    f = open('%s%spill.nodes' % (os.getcwd(), p))
    for l in f.readlines() :
        mo = nodes_exp.match(l)
        if mo != None :
            nodes.append((float(mo.group(1)), float(mo.group(2)),
                          float(mo.group(3)))) 
    return nodes

tris_exp = re.compile('(\d+)\s+(\d+)\s+(\d+)')
def getTestTris() :
    tris = []
    p = "%spackages%sTetGenBridge%s" % (os.sep, os.sep, os.sep)
    f = open('%s%spill.tri' % (os.getcwd(), p))
    for l in f.readlines() :
        mo = tris_exp.match(l)
        if mo != None :
            tris.append((int(mo.group(1)), int(mo.group(2)),
                         int(mo.group(3)))) 
    return tris

def addSurfaceInfo(tgio, marker = 0) :
    
    #iterate over nodes and add the points.    
    nodes = getTestNodes()
    sz = len(nodes)
    tgio.pointlist = TetGen.allocate_array(sz * 3)
    tgio.numberofpoints = sz
    idx = 0
    for n in nodes :
        TetGen.set_val(tgio.pointlist, idx * 3, n[0])
        TetGen.set_val(tgio.pointlist, idx * 3 + 1, n[1])
        TetGen.set_val(tgio.pointlist, idx * 3 + 2, n[2])
        idx = idx + 1

    #iterate over faces and add the facets.    
    tris = getTestTris()
    fsz = len(tris)
    tgio.facetlist = TetGen.allocate_facet_array(fsz)
    tgio.numberoffacets = fsz;
    idx = 0
    for t in tris :
        TetGen.add_tri(tgio.facetlist, idx, t[0], t[1], t[2])
        idx = idx + 1
    
class CreateTestSurf(Module):
    def compute(self):
        out  = packages.TetGenBridge.tetgenio_wrapper()
        addSurfaceInfo(out.data, 0)
        self.setResult("tgio out", out)

def initialize(reg):
    reg.add_module(CreateTestSurf)
    reg.add_output_port(CreateTestSurf, "tgio out",
                      (packages.TetGenBridge.tetgenio_wrapper,
                       'output test surface'))