2 // C++ : Table d'hexaedres (Evol Versions 3)
4 // Copyright (C) 2009-2016 CEA/DEN, EDF R&D
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.
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.
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
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 #include "HexQpattern.hxx"
25 #include "HexVector.hxx"
26 #include "HexVertex.hxx"
27 #include "HexEdge.hxx"
28 #include "HexDiagnostics.hxx"
29 #include "HexDocument.hxx"
30 #include "HexHexa.hxx"
31 #include "HexGlobale.hxx"
38 static bool db = false;
40 // =================================================== Construc QpatQuad
41 QpatQuad::QpatQuad (Quad* elt)
45 for (int nro=0 ; nro<QUAD4 ; ++nro)
46 q_edge [nro] = NOTHING;
48 // =================================================== operator=
49 void QpatQuad::operator= (const QpatQuad& other)
54 for (int nro=0;nro<QUAD4;++nro) q_edge[nro] = other.q_edge[nro];
56 // =================================================== Construc QpatEdge
57 QpatEdge::QpatEdge (Edge* elt)
61 v_amont = v_aval = NOTHING;
63 // =================================================== operator=
64 void QpatEdge::operator= (const QpatEdge& other)
69 v_amont = other.v_amont;
70 v_aval = other.v_aval;
72 // =================================================== Construc QpatVertex
73 QpatVertex::QpatVertex (Vertex* elt)
81 // =================================================== operator=
82 void QpatVertex::operator= (const QpatVertex& other)
89 on_contour = other.on_contour;
90 quad_cible = other.quad_cible;
92 // =================================================== find_quad
93 int find_quad (Quads& table, Vertex* vertex)
95 int nbre = table.size();
96 for (int nro=0 ; nro < nbre ; nro++)
97 if (table[nro]->indexVertex(vertex)>=0)
102 // -----------------------------------------------------------------------
103 // -----------------------------------------------------------------------
104 // -----------------------------------------------------------------------
105 // -----------------------------------------------------------------------
106 // ===================================================== Constructeur
107 Qpattern::Qpattern ()
109 nbr_vertex = nbr_edges = nbr_quads = 0;
111 pos_vertex4 = pos_edge3 = pos_edge4 = NOTHING;
112 for (int nc=0 ; nc<DIM3 ; nc++)
113 origine[nc] = base_i[nc] = base_j[nc] = 0;
118 ux_mini = uy_mini = 0;
119 ux_delta = uy_delta = 1;
121 // ====================================================== setPattern
122 void Qpattern::setPattern (Vertices& contour, Quads& motif)
124 cont_nbnodes = contour.size();
125 Real3 cg, point, pmax;
126 Vertex::anaVertices (contour, point, pmax, cg);
127 for (int nro=0 ; nro<cont_nbnodes ; ++nro)
128 addVertex (contour[nro]);
130 contour[0]->getPoint (origine);
131 contour[1]->getPoint (point);
132 setOrigin (origine, point, cg);
134 double vxmin = pat_vertex[0].v_x;
135 double vymin = pat_vertex[0].v_y;
136 double vxmax = vxmin;
137 double vymax = vymin;
138 for (int np=0 ; np<cont_nbnodes ; ++np)
141 projeter (contour[np], ux, uy);
142 vxmin = std::min (ux, vxmin);
143 vxmax = std::max (ux, vxmax);
144 vymin = std::min (uy, vymin);
145 vymax = std::max (uy, vymax);
150 ux_delta = vxmax-vxmin;
151 uy_delta = vymax-vymin;
153 int nbre = motif.size();
154 for (int nro=0 ; nro<nbre ; ++nro)
155 addQuad (motif[nro]);
157 for (int nro=0 ; nro<cont_nbnodes ; ++nro)
159 contour[nro]->getPoint (point);
160 for (int nc=0 ; nc<DIM3 ; nc++) cg[nc] += point[nc];
161 addVertex (contour[nro]);
164 // ====================================================== setTarget
165 void Qpattern::setTarget (Vertices& contour, Quads& cible)
167 old_contour = contour;
169 for (int nro=0 ; nro<cont_nbnodes ; ++nro)
171 Vertex* vertex = contour[nro];
172 pat_vertex[nro].cible = vertex;
173 pat_vertex[nro].quad_cible = find_quad (cible, vertex);
176 int nbre = cible.size();
178 for (int nro=0 ; nro<nbre ; ++nro)
180 Quad* quad = cible [nro];
181 Hexa* hexa = quad->getParent (0);
182 Quad* oppos = hexa->getOpposedQuad (quad);
184 old_top .push_back (quad);
185 old_bottom.push_back (oppos);
186 old_hexa .push_back (hexa);
192 hexa = oppos->opposedHexa (hexa);
193 oppos = hexa==NULL ? NULL : hexa->getOpposedQuad (oppos);
195 nbr_layers = std::min (prof, nbr_layers);
198 // ====================================================== setOrigin
199 int Qpattern::setOrigin (double* orig, double* p1, double* cg)
201 base_i[1] = base_i[2] = 0;
202 base_j[0] = base_j[2] = 0;
203 base_i[0] = base_j[1] = 1;
205 pat_vertex[0].v_x = pat_vertex[1].v_x = 0;
206 pat_vertex[2].v_x = 1;
207 pat_vertex[0].v_y = 1;
208 pat_vertex[1].v_y = pat_vertex[2].v_y = 0;
210 calc_vecteur (orig, p1, base_i);
211 calc_vecteur (orig, cg, base_j);
212 normer_vecteur (base_i);
213 normer_vecteur (base_j);
215 prod_vectoriel (base_i, base_j, vk);
216 prod_vectoriel (vk, base_i, base_j);
227 // ====================================================== addQuad
228 int Qpattern::addQuad (Quad* elt)
234 for (int nro=0; nro<QUAD4 ; nro++)
236 Edge* edge = elt->getEdge (nro);
237 quad.q_edge [nro] = addEdge (edge);
240 pat_quad.push_back (quad);
244 // ====================================================== addEdge
245 int Qpattern::addEdge (Edge* elt)
247 for (int nro=0; nro<nbr_edges ; nro++)
249 if (elt==pat_edge [nro].refer)
254 edge.v_amont = addVertex (elt->getVertex (V_AMONT));
255 edge.v_aval = addVertex (elt->getVertex (V_AVAL));
257 pat_edge.push_back (edge);
262 // ====================================================== projeter
263 void Qpattern::projeter (Vertex* elt, double& ux, double& uy)
266 elt->getPoint (point);
267 calc_vecteur (origine, point, local);
268 ux = (prod_scalaire (base_i, local) - ux_mini)/ux_delta ;
269 uy = (prod_scalaire (base_j, local) - uy_mini)/uy_delta ;
271 // ====================================================== addVertex
272 int Qpattern::addVertex (Vertex* elt, Vertex* ref)
274 for (int nro=0; nro<nbr_vertex ; nro++)
276 if (elt==pat_vertex [nro].refer)
279 pat_vertex [nro].on_contour = true;
284 QpatVertex vertex (elt);
285 projeter (elt, vertex.v_x, vertex.v_y);
288 printf (" Vertex nro %d : (%g, %g, %g)\t -> (%g, %g)\n",
289 nbr_vertex, elt->getX(), elt->getY(), elt->getZ(),
290 vertex.v_x, vertex.v_y);
291 pat_vertex.push_back (vertex);
295 // ====================================================== getSize
296 void Qpattern::getSize (int& nbq, int& nbed, int& nbv, int& prof)
303 // ====================================================== stepDown
304 void Qpattern::stepDown ()
306 int nbnodes = old_contour.size();
307 for (int nro=0 ; nro<nbnodes ; ++nro)
309 int nq = pat_vertex[nro].quad_cible;
311 Hexa* hexa = old_hexa [nq];
312 Quad* quad = old_top [nq];
313 Vertex* vertex = hexa->opposedVertex (quad, old_contour[nro]);
314 old_contour[nro] = vertex;
317 int nbquads = old_top.size();
318 for (int nq=0 ; nq<nbquads ; ++nq)
320 Quad* oppos = old_bottom[nq];
321 Hexa* hexa = oppos->opposedHexa (old_hexa[nq]);
323 old_top [nq] -> remove ();
324 old_top [nq] = oppos;
325 old_bottom [nq] = hexa==NULL ? NULL : hexa->getOpposedQuad (oppos);
326 old_hexa [nq] = hexa;
329 // ====================================================== anaTarget
330 void Qpattern::anaTarget (double tmin[], double tmax[], double centre[])
332 Vertex::anaVertices (old_contour, tmin, tmax, centre);