Salome HOME
Move Hex_defines.hxx to the list of the headers.
[modules/hexablock.git] / src / HEXABLOCK / HexAnaQuads.hxx
1
2 // class : Analyse des quadrangles avant construction
3
4 // Copyright (C) 2009-2013  CEA/DEN, EDF R&D
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.
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 #ifndef __ANA_QUADS_H
23 #define __ANA_QUADS_H
24
25 #include "Hex_defines.hxx"
26 #include "HexQuad.hxx"
27 // #include "HexEdge.hxx"
28
29 BEGIN_NAMESPACE_HEXA
30
31 class HEXABLOCKENGINE_EXPORT AnaQuads
32 {
33 public:
34     AnaQuads (Quad* q1, Quad* q2, Quad* q3=NULL, Quad* q4=NULL, Quad* q5=NULL);
35
36 public:
37     enum {MaxQuads=5};
38     int    status;
39     int    nbr_quads;
40     int    nbr_aretes;
41     Quad*  tab_quads  [MaxQuads];
42     int    inter_nbre [MaxQuads];
43     int    inter_edge [MaxQuads][MaxQuads]; // L'arete commune des 2 quads
44     int    inter_quad [MaxQuads][QUAD4];    // Le quad touchant la ieme arete
45 };
46 // ----------------------------------------------- Inlining
47 // ========================================================== Constructeur
48 inline AnaQuads::AnaQuads (Quad* q0, Quad* q1, Quad* q2, Quad* q3, Quad* q4)
49 {
50    nbr_quads  = 2;
51    nbr_aretes = 0;
52    status     = HOK;
53
54    for (int nquad=0 ; nquad < MaxQuads ; nquad++)
55        {
56        tab_quads  [nquad] = NULL;
57        inter_nbre [nquad] = 0;
58        for (int nro=0 ; nro < QUAD4 ; nro++)
59            inter_quad [nquad][nro] = NOTHING;
60        for (int nro=0 ; nro < MaxQuads ; nro++)
61            inter_edge [nquad][nro] = NOTHING;
62        }
63
64    tab_quads [0] = q0;
65    tab_quads [1] = q1;
66    tab_quads [2] = q2;
67    tab_quads [3] = q3;
68    tab_quads [4] = q4;
69
70    if      (q4 != NULL) nbr_quads = 5;
71    else if (q3 != NULL) nbr_quads = 4;
72    else if (q2 != NULL) nbr_quads = 3;
73    else                 nbr_quads = 2;
74
75    for (int nquad1=0 ; nquad1 < nbr_quads ; nquad1++)
76        {
77        if (tab_quads[nquad1]==NULL || tab_quads[nquad1]->isDeleted())
78           {
79           status = HERR;
80           return;
81           }
82        for (int nquad2=0 ; nquad2 < nquad1 ; nquad2++)
83            {
84            if (tab_quads[nquad1]==tab_quads[nquad2]) 
85               {
86               status = HERR;
87               return;
88               }
89            int nedge2 = 0;
90            int nedge1 = tab_quads[nquad1]->inter (tab_quads[nquad2], nedge2) ;
91            if (nedge1 != NOTHING)
92               {
93               inter_edge [nquad1] [nquad2] = nedge1;
94               inter_quad [nquad1] [nedge1] = nquad2;
95
96               inter_edge [nquad2] [nquad1] = nedge2;
97               inter_quad [nquad2] [nedge2] = nquad1;
98
99               inter_nbre [nquad1]++;
100               inter_nbre [nquad2]++;
101               nbr_aretes++;
102               }
103            }
104        }
105 }
106 // ============================================================== distance
107 inline double distance (Vertex* v1, Vertex* v2)
108 {
109    double vx   = v1->getX () - v2->getX ();
110    double vy   = v1->getY () - v2->getY ();
111    double vz   = v1->getZ () - v2->getZ ();
112    double dist = sqrt (vx*vx + vy*vy + vz*vz);
113    return dist;
114 }
115 END_NAMESPACE_HEXA
116 #endif