Salome HOME
Updated copyright comment
[modules/hexablock.git] / src / HEXABLOCK / HexDocument_skin.cxx
1
2 // C++ : Reordonnancement des faces
3
4 // Copyright (C) 2009-2024  CEA, EDF
5 //
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License, or (at your option) any later version.
10 //
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 // Lesser General Public License for more details.
15 //
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
19 //
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22
23 #include "HexDocument.hxx"
24
25 #include "HexVertex.hxx"
26 #include "HexEdge.hxx"
27 #include "HexQuad.hxx"
28 #include "HexHexa.hxx"
29
30 #include <queue>
31
32 BEGIN_NAMESPACE_HEXA
33 // ----------------------------------------------------------------------
34 struct OrientedQuad 
35      {
36      Quad* quad;
37      Vertex* v1;
38      Vertex* v2;
39      };
40
41 void propagateOrientation (std::queue <OrientedQuad> &queue_quads, Quad* orig);
42 void makeSkin (Quad* orig);
43
44 // ========================================================= reorderFaces
45 // ==== Ordonner les faces externes
46 void Document::reorderQuads ()
47 {
48    majReferences ();
49    EltBase* elt = NULL;
50
51    for (elt = doc_first_elt[EL_QUAD]->next (); elt!=NULL; elt = elt->next())
52        if (elt!=NULL && elt->isHere())
53           {
54           Quad* quad = static_cast <Quad*> (elt);
55           if (quad->getNbrParents()==1) quad->setOrientation (Q_UNDEFINED);
56           else                          quad->setOrientation (Q_INSIDE);
57           }
58
59    for (elt = doc_first_elt[EL_HEXA]->next (); elt!=NULL; elt = elt->next())
60        if (elt!=NULL && elt->isHere())
61           {
62           Hexa* hexa = static_cast <Hexa*> (elt);
63           for (int nq=0; nq<HQ_MAXI ; nq++)
64               {
65               Quad* quad = hexa->getQuad (nq);
66               if (quad->getOrientation()==Q_UNDEFINED)
67                  makeSkin (quad);
68               }
69           }
70
71    for (elt = doc_first_elt[EL_QUAD]->next (); elt!=NULL; elt = elt->next())
72        if (elt!=NULL && elt->isHere())
73           {
74           Quad* quad = static_cast <Quad*> (elt);
75           quad->reorienter ();
76           }
77 }
78 // ========================================================= makeSkin
79 void makeSkin (Quad* orig)
80 {
81    OrientedQuad triplet;
82    std::queue <OrientedQuad> queue_quads;
83
84    orig->setOrientation();  // Q_DIRECT=1, Q_INVERSE=2 
85    propagateOrientation (queue_quads, orig);
86    
87    while (NOT queue_quads.empty ())
88       {
89       triplet = queue_quads.front ();
90       queue_quads.pop ();
91       int n1 = triplet.quad->indexVertex (triplet.v1);
92       int n2 = triplet.quad->indexVertex (triplet.v2);
93       int sens = Q_WAITING;
94       if (n2 == (n1+1) MODULO QUAD4)
95           sens = Q_DIRECT;
96       else if (n1 == (n2+1) MODULO QUAD4)
97           sens = Q_INVERSE;
98       else 
99           printf (" **************** Orientation face impossible\n");
100
101       triplet.quad->setOrientation (sens);
102       propagateOrientation (queue_quads, triplet.quad);
103       }
104 }
105 // ==================================================== propagateOrientation
106 void propagateOrientation (std::queue <OrientedQuad> &queue_quads, Quad* orig)
107 {
108    OrientedQuad triplet;
109                 // Q_DIRECT : le sens des vertex est l'exterieur 
110    int sens = orig->getOrientation();  // Q_DIRECT=1, Q_INVERSE=2 
111
112    for (int ned=0; ned<QUAD4 ; ned++)
113        {
114        triplet.v1 = orig->getVertex ( ned );
115        triplet.v2 = orig->getVertex ((ned+1) MODULO QUAD4);
116        if (sens==Q_DIRECT)
117           {
118           Vertex* v3 = triplet.v1;
119           triplet.v1 = triplet.v2;
120           triplet.v2 = v3;
121           }
122        Edge* edge = orig->getEdge (ned);
123        int nbp    = edge->getNbrParents ();
124        for (int np=0; np<nbp ; np++)
125            {
126            triplet.quad = edge->getParent (np); 
127            if (triplet.quad->getOrientation ()==Q_UNDEFINED)
128               {
129               triplet.quad->setOrientation (Q_WAITING);
130               queue_quads.push (triplet);
131               }
132            }
133        }
134 }
135 END_NAMESPACE_HEXA