Salome HOME
simplification
[modules/smesh.git] / src / Tools / blocFissure / gmu / elimineExtremitesPipe.py
1 # -*- coding: utf-8 -*-
2 # Copyright (C) 2014-2021  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 """Recherche des points en trop (externes au volume à remailler)"""
21
22 import logging
23
24 from .geomsmesh import geompy
25 from .whichSideVertex import whichSideVertex
26
27 def elimineExtremitesPipe(ptEdgeFond, facesDefaut, centres, gptsdisks, nbsegCercle):
28   """Recherche des points en trop (externes au volume à remailler)
29
30   - on associe chaque extrémité du pipe à une face filling
31   - on part des disques aux extrémités du pipe
32   - pour chaque disque, on prend les vertices de géométrie,
33     on marque leur position relative à la face.
34   - on s'arrete quand tous les noeuds sont dedans
35   """
36
37   logging.info('start')
38
39   point_0 = centres[0]
40   point_1 = centres[-1]
41   idFillingFromBout = [None, None]                 # contiendra l'index du filling pour les extrémités 0 et 1
42   nbFacesFilling = len(ptEdgeFond)
43   for ifil in range(nbFacesFilling):
44     for point in ptEdgeFond[ifil]: # il y a un ou deux points débouchant sur cette face
45       if geompy.MinDistance(point,point_0) < geompy.MinDistance(point,point_1): # TODO: trouver plus fiable pour les cas tordus...
46         idFillingFromBout[0] = ifil
47       else:
48         idFillingFromBout[1] = ifil
49   logging.debug("association bouts du pipe - faces de filling: %s", idFillingFromBout)
50
51   logging.debug("recherche des disques de noeuds complètement internes")
52   idisklim = list() # indices des premier et dernier disques internes
53   idiskout = list() # indices des premier et dernier disques externes
54   for bout in range(2):
55
56     if bout == 0:
57       idisk = -1
58       inc = 1
59       numout = -1
60     else:
61       idisk = len(gptsdisks)
62       inc = -1
63       numout = len(gptsdisks)
64
65     inside = False
66     outside = True
67     while not inside:
68       idisk += inc
69       logging.debug("examen disque %s", idisk)
70       gptdsk = gptsdisks[idisk]
71       inside = True
72       for n_seg in range(nbsegCercle):
73         points = gptdsk[n_seg]
74         for point in points:
75           side = whichSideVertex(facesDefaut[idFillingFromBout[bout]], point)
76           if side < 0:
77             if outside: # premier point detecté dedans
78               outside = False
79               numout = idisk -inc # le disque précédent était dehors
80           else:
81             inside = False # ce point est dehors
82         if not inside and not outside:
83           break
84
85     idisklim.append(idisk)  # premier et dernier disques internes
86     idiskout.append(numout) # premier et dernier disques externes
87
88   return (idFillingFromBout, idisklim, idiskout)