Salome HOME
8eeb7b1b1e4e0dcfc6233782a52cbe7361e107f8
[plugins/ghs3dprlplugin.git] / src / tools / facespoints2mesh.py
1 #!/usr/bin/env python
2 #  -*- coding: utf-8 -*-
3 # Copyright (C) 2007-2016  CEA/DEN, EDF R&D
4 #
5 # This library is free software; you can redistribute it and/or
6 # modify it under the terms of the GNU Lesser General Public
7 # License as published by the Free Software Foundation; either
8 # version 2.1 of the License, or (at your option) any later version.
9 #
10 # This library is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13 # Lesser General Public License for more details.
14 #
15 # You should have received a copy of the GNU Lesser General Public
16 # License along with this library; if not, write to the Free Software
17 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
18 #
19 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 #
21
22 """
23 these file is using in GHS3DPRL Plugin
24 to convert input files .faces and .points of Tepal V1
25 to input file .mesh of Tepal V2
26 assume compatibility GHS3DPRL Plugin Tepal V1 => Tepal V2
27 example of use (when Tepal V2):
28   facespoints2mesh.py GHS3DPRL
29   tepal2med --casename=GHS3DPRL --number=12 --medname=DOMAIN --launchtepal=no
30   mesh2facespoints.py DOMAIN
31 """
32
33 import os
34 import sys
35
36 file_fp='GHS3DPRL'
37 if len(sys.argv)==2:
38    file_fp=sys.argv[1]
39
40 f1=file_fp+'.points'
41 f2=file_fp+'.faces'
42 f3=file_fp+'.mesh'
43
44 fs=open(f1, 'r')
45 ft=open(f3, 'w')
46 ft.write('MeshVersionFormatted 1\n')
47 ft.write('\nDimension\n3\n')
48 tmp=fs.readline()
49 nb=int(tmp)
50 ft.write('\nVertices\n')
51 ft.write(tmp)
52 for i in xrange(0,nb):
53   lig=fs.readline()
54   ft.write(lig)
55 fs.close()
56
57 fs=open(f2, 'r')
58 lig=fs.readline()
59 nb=int(lig.split()[0])
60 ft.write('\nTriangles\n'+lig.split()[0]+'\n')
61 for i in xrange(0,nb):
62   lig=fs.readline()
63   lig=lig.split()
64   ft.write(lig[1]+' '+lig[2]+' '+lig[3]+' '+lig[4]+'\n')
65 ft.write('\nEnd\n')
66 ft.close()
67 print 'facespoints2mesh creation of file '+f3