From: eap Date: Wed, 27 Jan 2010 09:00:33 +0000 (+0000) Subject: 0020636: [CEA 379] validation Tepal V2 GHS3DPRL and MEDsplitter and doc X-Git-Tag: V5_1_4a1~4 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=51c4c85434f4025c8bd9b0a5695a2786c2e6ed8b;p=plugins%2Fghs3dprlplugin.git 0020636: [CEA 379] validation Tepal V2 GHS3DPRL and MEDsplitter and doc Added src/tools/facespoints2mesh.py Added src/tools/mesh2facespoints.py --- diff --git a/configure.ac b/configure.ac index ef16664..5812733 100644 --- a/configure.ac +++ b/configure.ac @@ -441,6 +441,7 @@ AC_OUTPUT([ \ src/GHS3DPRLPlugin/Makefile \ src/gui/Makefile \ src/tepal2med/Makefile \ + src/tools/Makefile \ GHS3DPRLPLUGIN_version.h \ Makefile \ ]) diff --git a/src/Makefile.am b/src/Makefile.am index c9002c1..7b7b205 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -25,10 +25,10 @@ include $(top_srcdir)/adm_local/unix/make_common_starter.am -SUBDIRS = GHS3DPRLPlugin +SUBDIRS = GHS3DPRLPlugin tools if GHS3DPRLPLUGIN_ENABLE_GUI SUBDIRS += gui tepal2med endif -DIST_SUBDIRS = GHS3DPRLPlugin gui tepal2med +DIST_SUBDIRS = GHS3DPRLPlugin gui tepal2med tools diff --git a/src/tools/Makefile.am b/src/tools/Makefile.am new file mode 100644 index 0000000..a7d968e --- /dev/null +++ b/src/tools/Makefile.am @@ -0,0 +1,36 @@ +# Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE +# +# Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +# CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 2.1 of the License. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +# +# See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +# +# File : Makefile.in +# Module : GHS3DPRLPLUGIN +# +include $(top_srcdir)/adm_local/unix/make_common_starter.am + + +# Scripts to be installed. +dist_salomescript_DATA= \ + facespoints2mesh.py \ + mesh2facespoints.py + +install-data-hook: + @for f in $(dist_salomescript_DATA) ; do \ + chmod -f a+x $(DESTDIR)$(salomescriptdir)/$$f ; \ + done diff --git a/src/tools/facespoints2mesh.py b/src/tools/facespoints2mesh.py new file mode 100755 index 0000000..2127da3 --- /dev/null +++ b/src/tools/facespoints2mesh.py @@ -0,0 +1,49 @@ +#!/usr/bin/env python +#-*- coding:utf-8 -*- + +""" +these file is using in GHS3DPRL Plugin +to convert input files .faces and .points of Tepal V1 +to input file .mesh of Tepal V2 +assume compatibility GHS3DPRL Plugin Tepal V1 => Tepal V2 +example of use (when Tepal V2): + facespoints2mesh.py GHS3DPRL + tepal2med --casename=GHS3DPRL --number=12 --medname=DOMAIN --launchtepal=no + mesh2facespoints.py DOMAIN +""" + +import os +import sys + +file_fp='GHS3DPRL' +if len(sys.argv)==2: + file_fp=sys.argv[1] + +f1=file_fp+'.points' +f2=file_fp+'.faces' +f3=file_fp+'.mesh' + +fs=open(f1, 'r') +ft=open(f3, 'w') +ft.write('MeshVersionFormatted 1\n') +ft.write('\nDimension\n3\n') +tmp=fs.readline() +nb=int(tmp) +ft.write('\nVertices\n') +ft.write(tmp) +for i in xrange(0,nb): + lig=fs.readline() + ft.write(lig) +fs.close() + +fs=open(f2, 'r') +lig=fs.readline() +nb=int(lig.split()[0]) +ft.write('\nTriangles\n'+lig.split()[0]+'\n') +for i in xrange(0,nb): + lig=fs.readline() + lig=lig.split() + ft.write(lig[1]+' '+lig[2]+' '+lig[3]+' '+lig[4]+'\n') +ft.write('\nEnd\n') +ft.close() +print 'facespoints2mesh creation of file '+f3 diff --git a/src/tools/mesh2facespoints.py b/src/tools/mesh2facespoints.py new file mode 100755 index 0000000..c3df92d --- /dev/null +++ b/src/tools/mesh2facespoints.py @@ -0,0 +1,117 @@ +#!/usr/bin/env python +#-*- coding:utf-8 -*- + +""" +these file is using in GHS3DPRL Plugin +to convert output files .mesh of Tepal V2 +to output files files .faces and .points of Tepal V1 +assume compatibility GHS3DPRL Plugin Tepal V1 => Tepal V2 +example of use (when Tepal V2): + facespoints2mesh.py GHS3DPRL + tepal2med --casename=GHS3DPRL --number=12 --medname=DOMAIN --launchtepal=no + mesh2facespoints.py DOMAIN +""" + +import os +import sys +import glob +import fileinput +import string + +file_m='GHS3DPRL' +if len(sys.argv)==2: + file_m=sys.argv[1] + +def find_cr_or_not(fs,tag): + """find number after tag with cr or sp""" + for line in fs: + if tag+'\n' in line: + #print tag+'' + res=fs.readline() + break + if tag+' ' in line: + #print 'vertices' + res=line.split()[1] + break + res=res.strip("\t\n ") + print tag+' '+res + return res + +def m2fp(f1): + """convert .mesh file to .points and .faces and .noboite""" + print '\nconversion '+f1+' to .points and .faces and .noboite' + #fs=open(f1, 'r') + #fs=fileinput.FileInput(f1,mode='r') #mode not in v2.4.4 + fs=fileinput.FileInput(f1) + (shortname, extension)=os.path.splitext(f1) + f2=shortname+'.points' + print 'creating',f2 + fp=open(f2, 'w') + nb=find_cr_or_not(fs,'Vertices') + np=nb #for .noboite + fp.write(nb+'\n') + for i in xrange(0,int(nb)): + fp.write(fs.readline()) + fp.close() + + f2=shortname+'.faces' + print 'creating',f2 + ff=open(f2, 'w') + nb=find_cr_or_not(fs,'Triangles') + ff.write(nb+' 0\n') + for i in xrange(0,int(nb)): + ff.write('3 '+fs.readline().strip('\t\n ')+' 0 0 0\n') + ff.close() + + ne=find_cr_or_not(fs,'Tetrahedra') + f3=shortname+'.noboite' + fb=open(f3, 'w') + npfixe="0" + fb.write(ne+' '+np+' '+npfixe+' 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n') + for i in xrange(0,int(ne)): + lig=fs.readline().strip('\t\n ') + lig=lig.split() + fb.write(lig[0]+" "+lig[1]+" "+lig[2]+" "+lig[3]+" ") + fb.write('\n') + fs.close() + fs=fileinput.FileInput(shortname+'.points') + nb=fs.readline() #eqal to np + for i in xrange(0,int(nb)): + lig=fs.readline().strip('\t\n ') + lig=lig.split() + fb.write(lig[0]+" "+lig[1]+" "+lig[2]+" ") + fb.write('\n0\n') #subnumber + fs.close() + fb.close() + +def rename_tepal_v1(f1,imax): + """rename files as version v1 of tepal expect""" + (shortname, extension)=os.path.splitext(f1) + fs=os.path.splitext(shortname) + i=int(fs[1].strip('.')) + ff=fs[0]+'.'+str(imax)+'.'+string.zfill(str(i),len(str(imax))) + #noboite en ".32.02.noboite!" + mvcp='mv ' #ou 'cp ' + f2=shortname+'.points' ; f3=ff+os.path.splitext(f2)[1] + print f2,'->',f3 ; os.system(mvcp+f2+' '+f3) + f2=shortname+'.faces' ; f3=ff+os.path.splitext(f2)[1] + print f2,'->',f3 ; os.system(mvcp+f2+' '+f3) + f2=shortname+'.noboite' ; f3=ff+os.path.splitext(f2)[1] + print f2,'->',f3 ; os.system(mvcp+f2+' '+f3) + f2=shortname+'.glo' ; f3=ff+os.path.splitext(f2)[1] + print f2,'->',f3 ; os.system(mvcp+f2+' '+f3) + f2=shortname+'.msg' ; f3=ff+os.path.splitext(f2)[1] + print f2,'->',f3 ; os.system(mvcp+f2+' '+f3) + +def my_test(a): return int(os.path.basename(a).split('.')[1]) + +f0=file_m+'.?????.mesh' +#print f0 +fics=glob.glob(f0) +fics.sort(lambda a, b: cmp(my_test(b), my_test(a))) #tri ordre decroissant +print 'conversion of files:\n',fics + +imax=len(fics) +for f in fics: + m2fp(f) + rename_tepal_v1(f,imax)