Salome HOME
df950af88973f0f6500fc3d5bf530a3cd0a98a61
[plugins/ghs3dprlplugin.git] / src / tools / facespoints2mesh.py
1 #!/usr/bin/env python3
2 #  -*- coding: utf-8 -*-
3 # Copyright (C) 2007-2023  CEA, EDF
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 these file is using in GHS3DPRL Plugin
23 to convert input files .faces and .points of Tepal V1
24 to input file .mesh of Tepal V2
25 assume compatibility GHS3DPRL Plugin Tepal V1 => Tepal V2
26 example of use (when Tepal V2):
27   facespoints2mesh.py GHS3DPRL
28   tepal2med --casename=GHS3DPRL --number=12 --medname=DOMAIN --launchtepal=no
29   mesh2facespoints.py DOMAIN
30 """
31
32 import codecs
33 import sys
34
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 with codecs.open(f3, 'w') as ft:
45     with codecs.open(f1, 'r') as fs:
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 range(nb):
53             lig = fs.readline()
54             ft.write(lig)
55     with codecs.open(f2, 'r') as fs:
56         lig = fs.readline()
57         nb = int(lig.split()[0])
58         ft.write('\nTriangles\n' + lig.split()[0] + '\n')
59         for i in range(nb):
60             lig = fs.readline()
61             lig = lig.split()
62             ft.write(lig[1] + ' ' + lig[2] + ' ' + lig[3] + ' ' + lig[4] + '\n')
63         ft.write('\nEnd\n')
64
65 print('facespoints2mesh creation of file ' + f3)