Salome HOME
Copyright update 2020
[modules/smesh.git] / src / Tools / blocFissure / gmu / elimineExtremitesPipe.py
1 # -*- coding: utf-8 -*-
2 # Copyright (C) 2014-2020  EDF R&D
3 #
4 # This library is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU Lesser General Public
6 # License as published by the Free Software Foundation; either
7 # version 2.1 of the License, or (at your option) any later version.
8 #
9 # This library is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12 # Lesser General Public License for more details.
13 #
14 # You should have received a copy of the GNU Lesser General Public
15 # License along with this library; if not, write to the Free Software
16 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
17 #
18 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 #
20
21 import logging
22
23 from .geomsmesh import geompy
24 from .whichSideVertex import whichSideVertex
25
26 def elimineExtremitesPipe(ptEdgeFond, facesDefaut, centres, gptsdisks, nbsegCercle):
27   """
28   recherche des points en trop (externes au volume à remailler)
29   - on associe chaque extrémité du pipe à une face filling 
30   - on part des disques aux extrémités du pipe
31   - pour chaque disque, on prend les vertices de géométrie,
32     on marque leur position relative à la face.
33   - on s'arrete quand tous les noeuds sont dedans
34   """
35   
36   logging.info('start')
37
38   pt0 = centres[0]
39   pt1 = centres[-1]
40   idFillingFromBout = [None, None]                 # contiendra l'index du filling pour les extrémités 0 et 1
41   nbFacesFilling = len(ptEdgeFond)
42   for ifil in range(nbFacesFilling):
43     for ipt, pt in enumerate(ptEdgeFond[ifil]): # il y a un ou deux points débouchant sur cette face
44       if geompy.MinDistance(pt,pt0) < geompy.MinDistance(pt,pt1): # TODO: trouver plus fiable pour les cas tordus...
45         idFillingFromBout[0] = ifil
46       else: 
47         idFillingFromBout[1] = ifil
48   logging.debug("association bouts du pipe - faces de filling: %s", idFillingFromBout)
49      
50   logging.debug("recherche des disques de noeuds complètement internes")
51   idisklim = [] # indices des premier et dernier disques internes
52   idiskout = [] # indices des premier et dernier disques externes
53   for bout in range(2):
54     if bout == 0:
55       idisk = -1
56       inc = 1
57       numout = -1
58     else:
59       idisk = len(gptsdisks)
60       inc = -1
61       numout = len(gptsdisks)
62     inside = False
63     outside = True
64     while not inside:
65       idisk = idisk + inc
66       logging.debug("examen disque %s", idisk)
67       gptdsk = gptsdisks[idisk]
68       inside = True
69       for k in range(nbsegCercle):
70         points = gptdsk[k]
71         for j, pt in enumerate(points):
72           side = whichSideVertex(facesDefaut[idFillingFromBout[bout]], pt)
73           if side < 0:
74             if outside: # premier point detecté dedans
75               outside = False
76               numout = idisk -inc # le disque précédent était dehors
77           else:
78             inside = False # ce point est dehors              
79         if not inside and not outside:
80           break
81     idisklim.append(idisk)  # premier et dernier disques internes
82     idiskout.append(numout) # premier et dernier disques externes
83     
84   return (idFillingFromBout, idisklim, idiskout)