1 // SMESH SMESH : implementaion of SMESH idl descriptions
3 // Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
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.
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
24 // File : StdMeshers_Quadrangle_2D.cxx
25 // Moved here from SMESH_Quadrangle_2D.cxx
26 // Author : Paul RASCLE, EDF
31 #include "StdMeshers_Quadrangle_2D.hxx"
32 #include "SMESH_Gen.hxx"
33 #include "SMESH_Mesh.hxx"
34 #include "SMESH_subMesh.hxx"
36 #include "SMDS_MeshElement.hxx"
37 #include "SMDS_MeshNode.hxx"
38 #include "SMDS_EdgePosition.hxx"
39 #include "SMDS_FacePosition.hxx"
41 #include <BRep_Tool.hxx>
42 #include <BRepTools.hxx>
43 #include <BRepTools_WireExplorer.hxx>
45 #include <Geom_Surface.hxx>
46 #include <Geom_Curve.hxx>
47 #include <Geom2d_Curve.hxx>
48 #include <GeomAdaptor_Curve.hxx>
49 #include <GCPnts_UniformAbscissa.hxx>
52 #include <Precision.hxx>
53 #include <gp_Pnt2d.hxx>
54 #include <TColStd_ListIteratorOfListOfInteger.hxx>
55 #include <TColStd_SequenceOfReal.hxx>
56 #include <TColgp_SequenceOfXY.hxx>
58 #include "utilities.h"
59 #include "Utils_ExceptHandlers.hxx"
61 #ifndef StdMeshers_Array2OfNode_HeaderFile
62 #define StdMeshers_Array2OfNode_HeaderFile
63 typedef const SMDS_MeshNode* SMDS_MeshNodePtr;
64 #include <NCollection_DefineArray2.hxx>
65 DEFINE_BASECOLLECTION (StdMeshers_BaseCollectionNodePtr, SMDS_MeshNodePtr)
66 DEFINE_ARRAY2(StdMeshers_Array2OfNode,
67 StdMeshers_BaseCollectionNodePtr, SMDS_MeshNodePtr)
71 //=============================================================================
75 //=============================================================================
77 StdMeshers_Quadrangle_2D::StdMeshers_Quadrangle_2D (int hypId, int studyId, SMESH_Gen* gen)
78 : SMESH_2D_Algo(hypId, studyId, gen)
80 MESSAGE("StdMeshers_Quadrangle_2D::StdMeshers_Quadrangle_2D");
81 _name = "Quadrangle_2D";
82 _shapeType = (1 << TopAbs_FACE);
83 _compatibleHypothesis.push_back("QuadranglePreference");
87 //=============================================================================
91 //=============================================================================
93 StdMeshers_Quadrangle_2D::~StdMeshers_Quadrangle_2D()
95 MESSAGE("StdMeshers_Quadrangle_2D::~StdMeshers_Quadrangle_2D");
100 //=============================================================================
104 //=============================================================================
106 bool StdMeshers_Quadrangle_2D::CheckHypothesis
108 const TopoDS_Shape& aShape,
109 SMESH_Hypothesis::Hypothesis_Status& aStatus)
112 aStatus = SMESH_Hypothesis::HYP_OK;
114 // there is only one compatible Hypothesis so far
115 const list <const SMESHDS_Hypothesis * >&hyps = GetUsedHypothesis(aMesh, aShape);
116 myQuadranglePreference = hyps.size() > 0;
121 //=============================================================================
125 //=============================================================================
127 bool StdMeshers_Quadrangle_2D::Compute (SMESH_Mesh& aMesh,
128 const TopoDS_Shape& aShape) throw (SALOME_Exception)
130 Unexpect aCatch(SalomeException);
131 //MESSAGE("StdMeshers_Quadrangle_2D::Compute");
132 SMESHDS_Mesh * meshDS = aMesh.GetMeshDS();
133 aMesh.GetSubMesh(aShape);
136 myTool = new SMESH_MesherHelper(aMesh);
137 _quadraticMesh = myTool->IsQuadraticSubMesh(aShape);
139 //FaceQuadStruct *quad = CheckAnd2Dcompute(aMesh, aShape);
140 FaceQuadStruct* quad = CheckNbEdges(aMesh, aShape);
143 delete myTool; myTool = 0;
147 if(myQuadranglePreference) {
148 int n1 = quad->nbPts[0];
149 int n2 = quad->nbPts[1];
150 int n3 = quad->nbPts[2];
151 int n4 = quad->nbPts[3];
152 int nfull = n1+n2+n3+n4;
155 if( nfull==ntmp && ( (n1!=n3) || (n2!=n4) ) ) {
156 // special path for using only quandrangle faces
157 bool ok = ComputeQuadPref(aMesh, aShape, quad);
158 delete myTool; myTool = 0;
163 // set normalized grid on unit square in parametric domain
164 SetNormalizedGrid(aMesh, aShape, quad);
166 delete myTool; myTool = 0;
170 // --- compute 3D values on points, store points & quadrangles
172 int nbdown = quad->nbPts[0];
173 int nbup = quad->nbPts[2];
175 int nbright = quad->nbPts[1];
176 int nbleft = quad->nbPts[3];
178 int nbhoriz = Min(nbdown, nbup);
179 int nbvertic = Min(nbright, nbleft);
181 const TopoDS_Face& F = TopoDS::Face(aShape);
182 Handle(Geom_Surface) S = BRep_Tool::Surface(F);
184 // internal mesh nodes
185 int i, j, geomFaceID = meshDS->ShapeToIndex( F );
186 for (i = 1; i < nbhoriz - 1; i++) {
187 for (j = 1; j < nbvertic - 1; j++) {
188 int ij = j * nbhoriz + i;
189 double u = quad->uv_grid[ij].u;
190 double v = quad->uv_grid[ij].v;
191 gp_Pnt P = S->Value(u, v);
192 SMDS_MeshNode * node = meshDS->AddNode(P.X(), P.Y(), P.Z());
193 meshDS->SetNodeOnFace(node, geomFaceID, u, v);
194 quad->uv_grid[ij].node = node;
201 // --.--.--.--.--.-- nbvertic
207 // ---.----.----.--- 0
208 // 0 > > > > > > > > nbhoriz
214 int iup = nbhoriz - 1;
215 if (quad->isEdgeOut[3]) { ilow++; } else { if (quad->isEdgeOut[1]) iup--; }
218 int jup = nbvertic - 1;
219 if (quad->isEdgeOut[0]) { jlow++; } else { if (quad->isEdgeOut[2]) jup--; }
221 // regular quadrangles
222 for (i = ilow; i < iup; i++) {
223 for (j = jlow; j < jup; j++) {
224 const SMDS_MeshNode *a, *b, *c, *d;
225 a = quad->uv_grid[j * nbhoriz + i].node;
226 b = quad->uv_grid[j * nbhoriz + i + 1].node;
227 c = quad->uv_grid[(j + 1) * nbhoriz + i + 1].node;
228 d = quad->uv_grid[(j + 1) * nbhoriz + i].node;
229 //SMDS_MeshFace * face = meshDS->AddFace(a, b, c, d);
230 SMDS_MeshFace* face = myTool->AddFace(a, b, c, d);
231 meshDS->SetMeshElementOnShape(face, geomFaceID);
235 UVPtStruct *uv_e0 = quad->uv_edges[0];
236 UVPtStruct *uv_e1 = quad->uv_edges[1];
237 UVPtStruct *uv_e2 = quad->uv_edges[2];
238 UVPtStruct *uv_e3 = quad->uv_edges[3];
240 double eps = Precision::Confusion();
242 // Boundary quadrangles
244 if (quad->isEdgeOut[0]) {
247 // |___|___|___|___|___|___|
249 // |___|___|___|___|___|___|
251 // |___|___|___|___|___|___| __ first row of the regular grid
252 // . . . . . . . . . __ down edge nodes
254 // >->->->->->->->->->->->-> -- direction of processing
256 int g = 0; // number of last processed node in the regular grid
258 // number of last node of the down edge to be processed
259 int stop = nbdown - 1;
260 // if right edge is out, we will stop at a node, previous to the last one
261 if (quad->isEdgeOut[1]) stop--;
263 // for each node of the down edge find nearest node
264 // in the first row of the regular grid and link them
265 for (i = 0; i < stop; i++) {
266 const SMDS_MeshNode *a, *b, *c, *d;
268 b = uv_e0[i + 1].node;
269 gp_Pnt pb (b->X(), b->Y(), b->Z());
271 // find node c in the regular grid, which will be linked with node b
274 // right bound reached, link with the rightmost node
276 c = quad->uv_grid[nbhoriz + iup].node;
279 // find in the grid node c, nearest to the b
280 double mind = RealLast();
281 for (int k = g; k <= iup; k++) {
283 const SMDS_MeshNode *nk;
284 if (k < ilow) // this can be, if left edge is out
285 nk = uv_e3[1].node; // get node from the left edge
287 nk = quad->uv_grid[nbhoriz + k].node; // get one of middle nodes
289 gp_Pnt pnk (nk->X(), nk->Y(), nk->Z());
290 double dist = pb.Distance(pnk);
291 if (dist < mind - eps) {
301 if (near == g) { // make triangle
302 //SMDS_MeshFace* face = meshDS->AddFace(a, b, c);
303 SMDS_MeshFace* face = myTool->AddFace(a, b, c);
304 meshDS->SetMeshElementOnShape(face, geomFaceID);
306 else { // make quadrangle
310 d = quad->uv_grid[nbhoriz + near - 1].node;
311 //SMDS_MeshFace* face = meshDS->AddFace(a, b, c, d);
312 SMDS_MeshFace* face = myTool->AddFace(a, b, c, d);
313 meshDS->SetMeshElementOnShape(face, geomFaceID);
315 // if node d is not at position g - make additional triangles
317 for (int k = near - 1; k > g; k--) {
318 c = quad->uv_grid[nbhoriz + k].node;
322 d = quad->uv_grid[nbhoriz + k - 1].node;
323 //SMDS_MeshFace* face = meshDS->AddFace(a, c, d);
324 SMDS_MeshFace* face = myTool->AddFace(a, c, d);
325 meshDS->SetMeshElementOnShape(face, geomFaceID);
332 if (quad->isEdgeOut[2]) {
335 // <-<-<-<-<-<-<-<-<-<-<-<-< -- direction of processing
337 // . . . . . . . . . __ up edge nodes
338 // ___ ___ ___ ___ ___ ___ __ first row of the regular grid
340 // |___|___|___|___|___|___|
342 // |___|___|___|___|___|___|
345 int g = nbhoriz - 1; // last processed node in the regular grid
348 // if left edge is out, we will stop at a second node
349 if (quad->isEdgeOut[3]) stop++;
351 // for each node of the up edge find nearest node
352 // in the first row of the regular grid and link them
353 for (i = nbup - 1; i > stop; i--) {
354 const SMDS_MeshNode *a, *b, *c, *d;
356 b = uv_e2[i - 1].node;
357 gp_Pnt pb (b->X(), b->Y(), b->Z());
359 // find node c in the grid, which will be linked with node b
361 if (i == stop + 1) { // left bound reached, link with the leftmost node
362 c = quad->uv_grid[nbhoriz*(nbvertic - 2) + ilow].node;
365 // find node c in the grid, nearest to the b
366 double mind = RealLast();
367 for (int k = g; k >= ilow; k--) {
368 const SMDS_MeshNode *nk;
370 nk = uv_e1[nbright - 2].node;
372 nk = quad->uv_grid[nbhoriz*(nbvertic - 2) + k].node;
373 gp_Pnt pnk (nk->X(), nk->Y(), nk->Z());
374 double dist = pb.Distance(pnk);
375 if (dist < mind - eps) {
385 if (near == g) { // make triangle
386 //SMDS_MeshFace* face = meshDS->AddFace(a, b, c);
387 SMDS_MeshFace* face = myTool->AddFace(a, b, c);
388 meshDS->SetMeshElementOnShape(face, geomFaceID);
390 else { // make quadrangle
392 d = uv_e1[nbright - 2].node;
394 d = quad->uv_grid[nbhoriz*(nbvertic - 2) + near + 1].node;
395 //SMDS_MeshFace* face = meshDS->AddFace(a, b, c, d);
396 SMDS_MeshFace* face = myTool->AddFace(a, b, c, d);
397 meshDS->SetMeshElementOnShape(face, geomFaceID);
399 if (near + 1 < g) { // if d not is at g - make additional triangles
400 for (int k = near + 1; k < g; k++) {
401 c = quad->uv_grid[nbhoriz*(nbvertic - 2) + k].node;
403 d = uv_e1[nbright - 2].node;
405 d = quad->uv_grid[nbhoriz*(nbvertic - 2) + k + 1].node;
406 //SMDS_MeshFace* face = meshDS->AddFace(a, c, d);
407 SMDS_MeshFace* face = myTool->AddFace(a, c, d);
408 meshDS->SetMeshElementOnShape(face, geomFaceID);
417 // right or left boundary quadrangles
418 if (quad->isEdgeOut[1]) {
419 // MESSAGE("right edge is out");
420 int g = 0; // last processed node in the grid
421 int stop = nbright - 1;
422 if (quad->isEdgeOut[2]) stop--;
423 for (i = 0; i < stop; i++) {
424 const SMDS_MeshNode *a, *b, *c, *d;
426 b = uv_e1[i + 1].node;
427 gp_Pnt pb (b->X(), b->Y(), b->Z());
429 // find node c in the grid, nearest to the b
431 if (i == stop - 1) { // up bondary reached
432 c = quad->uv_grid[nbhoriz*(jup + 1) - 2].node;
435 double mind = RealLast();
436 for (int k = g; k <= jup; k++) {
437 const SMDS_MeshNode *nk;
439 nk = uv_e0[nbdown - 2].node;
441 nk = quad->uv_grid[nbhoriz*(k + 1) - 2].node;
442 gp_Pnt pnk (nk->X(), nk->Y(), nk->Z());
443 double dist = pb.Distance(pnk);
444 if (dist < mind - eps) {
454 if (near == g) { // make triangle
455 //SMDS_MeshFace* face = meshDS->AddFace(a, b, c);
456 SMDS_MeshFace* face = myTool->AddFace(a, b, c);
457 meshDS->SetMeshElementOnShape(face, geomFaceID);
459 else { // make quadrangle
461 d = uv_e0[nbdown - 2].node;
463 d = quad->uv_grid[nbhoriz*near - 2].node;
464 //SMDS_MeshFace* face = meshDS->AddFace(a, b, c, d);
465 SMDS_MeshFace* face = myTool->AddFace(a, b, c, d);
466 meshDS->SetMeshElementOnShape(face, geomFaceID);
468 if (near - 1 > g) { // if d not is at g - make additional triangles
469 for (int k = near - 1; k > g; k--) {
470 c = quad->uv_grid[nbhoriz*(k + 1) - 2].node;
472 d = uv_e0[nbdown - 2].node;
474 d = quad->uv_grid[nbhoriz*k - 2].node;
475 //SMDS_MeshFace* face = meshDS->AddFace(a, c, d);
476 SMDS_MeshFace* face = myTool->AddFace(a, c, d);
477 meshDS->SetMeshElementOnShape(face, geomFaceID);
484 if (quad->isEdgeOut[3]) {
485 // MESSAGE("left edge is out");
486 int g = nbvertic - 1; // last processed node in the grid
488 if (quad->isEdgeOut[0]) stop++;
489 for (i = nbleft - 1; i > stop; i--) {
490 const SMDS_MeshNode *a, *b, *c, *d;
492 b = uv_e3[i - 1].node;
493 gp_Pnt pb (b->X(), b->Y(), b->Z());
495 // find node c in the grid, nearest to the b
497 if (i == stop + 1) { // down bondary reached
498 c = quad->uv_grid[nbhoriz*jlow + 1].node;
501 double mind = RealLast();
502 for (int k = g; k >= jlow; k--) {
503 const SMDS_MeshNode *nk;
507 nk = quad->uv_grid[nbhoriz*k + 1].node;
508 gp_Pnt pnk (nk->X(), nk->Y(), nk->Z());
509 double dist = pb.Distance(pnk);
510 if (dist < mind - eps) {
520 if (near == g) { // make triangle
521 //SMDS_MeshFace* face = meshDS->AddFace(a, b, c);
522 SMDS_MeshFace* face = myTool->AddFace(a, b, c);
523 meshDS->SetMeshElementOnShape(face, geomFaceID);
525 else { // make quadrangle
529 d = quad->uv_grid[nbhoriz*(near + 1) + 1].node;
530 //SMDS_MeshFace* face = meshDS->AddFace(a, b, c, d);
531 SMDS_MeshFace* face = myTool->AddFace(a, b, c, d);
532 meshDS->SetMeshElementOnShape(face, geomFaceID);
534 if (near + 1 < g) { // if d not is at g - make additional triangles
535 for (int k = near + 1; k < g; k++) {
536 c = quad->uv_grid[nbhoriz*k + 1].node;
540 d = quad->uv_grid[nbhoriz*(k + 1) + 1].node;
541 //SMDS_MeshFace* face = meshDS->AddFace(a, c, d);
542 SMDS_MeshFace* face = myTool->AddFace(a, c, d);
543 meshDS->SetMeshElementOnShape(face, geomFaceID);
553 delete myTool; myTool = 0;
560 //=============================================================================
564 //=============================================================================
566 FaceQuadStruct* StdMeshers_Quadrangle_2D::CheckNbEdges(SMESH_Mesh & aMesh,
567 const TopoDS_Shape & aShape)
568 throw(SALOME_Exception)
570 Unexpect aCatch(SalomeException);
572 const TopoDS_Face & F = TopoDS::Face(aShape);
574 // verify 1 wire only, with 4 edges
576 if (NumberOfWires(F) != 1) {
577 INFOS("only 1 wire by face (quadrangles)");
580 const TopoDS_Wire& W = BRepTools::OuterWire(F);
581 BRepTools_WireExplorer wexp (W, F);
583 FaceQuadStruct* quad = new FaceQuadStruct;
584 for (int i = 0; i < 4; i++)
585 quad->uv_edges[i] = 0;
589 for (wexp.Init(W, F); wexp.More(); wexp.Next()) {
590 const TopoDS_Edge& E = wexp.Current();
591 int nb = aMesh.GetSubMesh(E)->GetSubMeshDS()->NbNodes();
593 quad->edge[nbEdges] = E;
594 if(!_quadraticMesh) {
595 quad->nbPts[nbEdges] = nb + 2; // internal points + 2 extrema
599 quad->nbPts[nbEdges] = tmp + 2; // internal not medium points + 2 extrema
606 INFOS("face must have 4 edges /quadrangles");
614 //=============================================================================
618 //=============================================================================
620 FaceQuadStruct *StdMeshers_Quadrangle_2D::CheckAnd2Dcompute
622 const TopoDS_Shape & aShape,
623 const bool CreateQuadratic) throw(SALOME_Exception)
625 Unexpect aCatch(SalomeException);
627 _quadraticMesh = CreateQuadratic;
629 FaceQuadStruct *quad = CheckNbEdges(aMesh, aShape);
633 // set normalized grid on unit square in parametric domain
634 SetNormalizedGrid(aMesh, aShape, quad);
639 //=============================================================================
643 //=============================================================================
645 void StdMeshers_Quadrangle_2D::QuadDelete (FaceQuadStruct * quad)
647 //MESSAGE("StdMeshers_Quadrangle_2D::QuadDelete");
650 for (int i = 0; i < 4; i++)
652 if (quad->uv_edges[i])
653 delete [] quad->uv_edges[i];
654 quad->edge[i].Nullify();
657 delete [] quad->uv_grid;
662 //=============================================================================
666 //=============================================================================
668 void StdMeshers_Quadrangle_2D::SetNormalizedGrid (SMESH_Mesh & aMesh,
669 const TopoDS_Shape& aShape,
670 FaceQuadStruct* quad) throw (SALOME_Exception)
672 Unexpect aCatch(SalomeException);
673 // Algorithme décrit dans "Génération automatique de maillages"
674 // P.L. GEORGE, MASSON, § 6.4.1 p. 84-85
675 // traitement dans le domaine paramétrique 2d u,v
676 // transport - projection sur le carré unité
678 // MESSAGE("StdMeshers_Quadrangle_2D::SetNormalizedGrid");
679 const TopoDS_Face& F = TopoDS::Face(aShape);
681 // 1 --- find orientation of the 4 edges, by test on extrema
684 // |<----north-2-------^ a3 -------------> a2
686 // west-3 east-1 =right | |
690 // v----south-0--------> a0 -------------> a1
695 Handle(Geom2d_Curve) c2d[4];
698 for (int i = 0; i < 4; i++)
700 c2d[i] = BRep_Tool::CurveOnSurface(quad->edge[i], F,
701 quad->first[i], quad->last[i]);
702 pf[i] = c2d[i]->Value(quad->first[i]);
703 pl[i] = c2d[i]->Value(quad->last[i]);
704 quad->isEdgeForward[i] = false;
707 double l0f1 = pl[0].SquareDistance(pf[1]);
708 double l0l1 = pl[0].SquareDistance(pl[1]);
709 double f0f1 = pf[0].SquareDistance(pf[1]);
710 double f0l1 = pf[0].SquareDistance(pl[1]);
711 if ( Min( l0f1, l0l1 ) < Min ( f0f1, f0l1 ))
713 quad->isEdgeForward[0] = true;
715 double tmp = quad->first[0];
716 quad->first[0] = quad->last[0];
718 pf[0] = c2d[0]->Value(quad->first[0]);
719 pl[0] = c2d[0]->Value(quad->last[0]);
721 for (int i = 1; i < 4; i++)
723 l0l1 = pl[i - 1].SquareDistance(pl[i]);
724 l0f1 = pl[i - 1].SquareDistance(pf[i]);
725 quad->isEdgeForward[i] = ( l0f1 < l0l1 );
726 if (!quad->isEdgeForward[i])
728 double tmp = quad->first[i];
729 quad->first[i] = quad->last[i];
731 pf[i] = c2d[i]->Value(quad->first[i]);
732 pl[i] = c2d[i]->Value(quad->last[i]);
736 // 2 --- load 2d edge points (u,v) with orientation and value on unit square
739 for (int i = 0; i < 2; i++)
741 quad->uv_edges[i] = LoadEdgePoints(aMesh, F, quad->edge[i],
742 quad->first[i], quad->last[i]);
743 if (!quad->uv_edges[i]) loadOk = false;
746 for (int i = 2; i < 4; i++)
748 quad->uv_edges[i] = LoadEdgePoints(aMesh, F, quad->edge[i],
749 quad->last[i], quad->first[i]);
750 if (!quad->uv_edges[i]) loadOk = false;
755 INFOS("StdMeshers_Quadrangle_2D::SetNormalizedGrid - LoadEdgePoints failed");
760 // 3 --- 2D normalized values on unit square [0..1][0..1]
762 int nbhoriz = Min(quad->nbPts[0], quad->nbPts[2]);
763 int nbvertic = Min(quad->nbPts[1], quad->nbPts[3]);
765 quad->isEdgeOut[0] = (quad->nbPts[0] > quad->nbPts[2]);
766 quad->isEdgeOut[1] = (quad->nbPts[1] > quad->nbPts[3]);
767 quad->isEdgeOut[2] = (quad->nbPts[2] > quad->nbPts[0]);
768 quad->isEdgeOut[3] = (quad->nbPts[3] > quad->nbPts[1]);
770 quad->uv_grid = new UVPtStruct[nbvertic * nbhoriz];
772 UVPtStruct *uv_grid = quad->uv_grid;
773 UVPtStruct *uv_e0 = quad->uv_edges[0];
774 UVPtStruct *uv_e1 = quad->uv_edges[1];
775 UVPtStruct *uv_e2 = quad->uv_edges[2];
776 UVPtStruct *uv_e3 = quad->uv_edges[3];
778 // nodes Id on "in" edges
779 if (! quad->isEdgeOut[0]) {
781 for (int i = 0; i < nbhoriz; i++) { // down
782 int ij = j * nbhoriz + i;
783 uv_grid[ij].node = uv_e0[i].node;
786 if (! quad->isEdgeOut[1]) {
788 for (int j = 0; j < nbvertic; j++) { // right
789 int ij = j * nbhoriz + i;
790 uv_grid[ij].node = uv_e1[j].node;
793 if (! quad->isEdgeOut[2]) {
794 int j = nbvertic - 1;
795 for (int i = 0; i < nbhoriz; i++) { // up
796 int ij = j * nbhoriz + i;
797 uv_grid[ij].node = uv_e2[i].node;
800 if (! quad->isEdgeOut[3]) {
802 for (int j = 0; j < nbvertic; j++) { // left
803 int ij = j * nbhoriz + i;
804 uv_grid[ij].node = uv_e3[j].node;
808 // falsificate "out" edges
809 if (quad->isEdgeOut[0]) // down
810 uv_e0 = MakeEdgePoints
811 (aMesh, F, quad->edge[0], quad->first[0], quad->last[0], nbhoriz - 1);
812 else if (quad->isEdgeOut[2]) // up
813 uv_e2 = MakeEdgePoints
814 (aMesh, F, quad->edge[2], quad->last[2], quad->first[2], nbhoriz - 1);
816 if (quad->isEdgeOut[1]) // right
817 uv_e1 = MakeEdgePoints
818 (aMesh, F, quad->edge[1], quad->first[1], quad->last[1], nbvertic - 1);
819 else if (quad->isEdgeOut[3]) // left
820 uv_e3 = MakeEdgePoints
821 (aMesh, F, quad->edge[3], quad->last[3], quad->first[3], nbvertic - 1);
823 // normalized 2d values on grid
824 for (int i = 0; i < nbhoriz; i++)
826 for (int j = 0; j < nbvertic; j++)
828 int ij = j * nbhoriz + i;
829 // --- droite i cste : x = x0 + y(x1-x0)
830 double x0 = uv_e0[i].normParam; // bas - sud
831 double x1 = uv_e2[i].normParam; // haut - nord
832 // --- droite j cste : y = y0 + x(y1-y0)
833 double y0 = uv_e3[j].normParam; // gauche-ouest
834 double y1 = uv_e1[j].normParam; // droite - est
835 // --- intersection : x=x0+(y0+x(y1-y0))(x1-x0)
836 double x = (x0 + y0 * (x1 - x0)) / (1 - (y1 - y0) * (x1 - x0));
837 double y = y0 + x * (y1 - y0);
840 //MESSAGE("-xy-01 "<<x0<<" "<<x1<<" "<<y0<<" "<<y1);
841 //MESSAGE("-xy-norm "<<i<<" "<<j<<" "<<x<<" "<<y);
845 // 4 --- projection on 2d domain (u,v)
851 for (int i = 0; i < nbhoriz; i++)
853 for (int j = 0; j < nbvertic; j++)
855 int ij = j * nbhoriz + i;
856 double x = uv_grid[ij].x;
857 double y = uv_grid[ij].y;
858 double param_0 = uv_e0[0].param + x * (uv_e0[nbhoriz - 1].param - uv_e0[0].param); // sud
859 double param_2 = uv_e2[0].param + x * (uv_e2[nbhoriz - 1].param - uv_e2[0].param); // nord
860 double param_1 = uv_e1[0].param + y * (uv_e1[nbvertic - 1].param - uv_e1[0].param); // est
861 double param_3 = uv_e3[0].param + y * (uv_e3[nbvertic - 1].param - uv_e3[0].param); // ouest
863 //MESSAGE("params "<<param_0<<" "<<param_1<<" "<<param_2<<" "<<param_3);
864 gp_Pnt2d p0 = c2d[0]->Value(param_0);
865 gp_Pnt2d p1 = c2d[1]->Value(param_1);
866 gp_Pnt2d p2 = c2d[2]->Value(param_2);
867 gp_Pnt2d p3 = c2d[3]->Value(param_3);
869 double u = (1 - y) * p0.X() + x * p1.X() + y * p2.X() + (1 - x) * p3.X();
870 double v = (1 - y) * p0.Y() + x * p1.Y() + y * p2.Y() + (1 - x) * p3.Y();
872 u -= (1 - x) * (1 - y) * a0.X() + x * (1 - y) * a1.X() +
873 x * y * a2.X() + (1 - x) * y * a3.X();
874 v -= (1 - x) * (1 - y) * a0.Y() + x * (1 - y) * a1.Y() +
875 x * y * a2.Y() + (1 - x) * y * a3.Y();
884 //=======================================================================
885 //function : ShiftQuad
886 //purpose : auxilary function for ComputeQuadPref
887 //=======================================================================
888 static void ShiftQuad(FaceQuadStruct* quad, const int num, bool WisF)
892 for(i=1; i<=num; i++) {
893 int nbPts3 = quad->nbPts[0];
894 quad->nbPts[0] = quad->nbPts[1];
895 quad->nbPts[1] = quad->nbPts[2];
896 quad->nbPts[2] = quad->nbPts[3];
897 quad->nbPts[3] = nbPts3;
898 TopoDS_Edge edge3 = quad->edge[0];
899 quad->edge[0] = quad->edge[1];
900 quad->edge[1] = quad->edge[2];
901 quad->edge[2] = quad->edge[3];
902 quad->edge[3] = edge3;
903 double first3 = quad->first[0];
904 quad->first[0] = quad->first[1];
905 quad->first[1] = quad->first[2];
906 quad->first[2] = quad->first[3];
907 quad->first[3] = first3;
908 double last3 = quad->last[0];
909 quad->last[0] = quad->last[1];
910 quad->last[1] = quad->last[2];
911 quad->last[2] = quad->last[3];
912 quad->last[3] = last3;
913 bool isEdgeForward3 = quad->isEdgeForward[0];
914 quad->isEdgeForward[0] = quad->isEdgeForward[1];
915 quad->isEdgeForward[1] = quad->isEdgeForward[2];
916 quad->isEdgeForward[2] = quad->isEdgeForward[3];
917 quad->isEdgeForward[3] = isEdgeForward3;
918 bool isEdgeOut3 = quad->isEdgeOut[0];
919 quad->isEdgeOut[0] = quad->isEdgeOut[1];
920 quad->isEdgeOut[1] = quad->isEdgeOut[2];
921 quad->isEdgeOut[2] = quad->isEdgeOut[3];
922 quad->isEdgeOut[3] = isEdgeOut3;
923 UVPtStruct* uv_edges3 = quad->uv_edges[0];
924 quad->uv_edges[0] = quad->uv_edges[1];
925 quad->uv_edges[1] = quad->uv_edges[2];
926 quad->uv_edges[2] = quad->uv_edges[3];
927 quad->uv_edges[3] = uv_edges3;
930 // replacement left and right edges
931 int nbPts3 = quad->nbPts[1];
932 quad->nbPts[1] = quad->nbPts[3];
933 quad->nbPts[3] = nbPts3;
934 TopoDS_Edge edge3 = quad->edge[1];
935 quad->edge[1] = quad->edge[3];
936 quad->edge[3] = edge3;
937 double first3 = quad->first[1];
938 quad->first[1] = quad->first[3];
939 quad->first[3] = first3;
940 double last3 = quad->last[1];
941 quad->last[1] = quad->last[2];
942 quad->last[3] = last3;
943 bool isEdgeForward3 = quad->isEdgeForward[1];
944 quad->isEdgeForward[1] = quad->isEdgeForward[3];
945 quad->isEdgeForward[3] = isEdgeForward3;
946 bool isEdgeOut3 = quad->isEdgeOut[1];
947 quad->isEdgeOut[1] = quad->isEdgeOut[3];
948 quad->isEdgeOut[3] = isEdgeOut3;
949 UVPtStruct* uv_edges3 = quad->uv_edges[1];
950 quad->uv_edges[1] = quad->uv_edges[3];
951 quad->uv_edges[3] = uv_edges3;
956 //=======================================================================
958 //purpose : auxilary function for ComputeQuadPref
959 //=======================================================================
960 static gp_XY CalcUV(double x0, double x1, double y0, double y1,
961 FaceQuadStruct* quad,
962 const gp_Pnt2d& a0, const gp_Pnt2d& a1,
963 const gp_Pnt2d& a2, const gp_Pnt2d& a3,
964 const Handle(Geom2d_Curve)& c2db,
965 const Handle(Geom2d_Curve)& c2dr,
966 const Handle(Geom2d_Curve)& c2dt,
967 const Handle(Geom2d_Curve)& c2dl)
969 int nb = quad->nbPts[0];
970 int nr = quad->nbPts[1];
971 int nt = quad->nbPts[2];
972 int nl = quad->nbPts[3];
974 UVPtStruct* uv_eb = quad->uv_edges[0];
975 UVPtStruct* uv_er = quad->uv_edges[1];
976 UVPtStruct* uv_et = quad->uv_edges[2];
977 UVPtStruct* uv_el = quad->uv_edges[3];
979 double x = (x0 + y0 * (x1 - x0)) / (1 - (y1 - y0) * (x1 - x0));
980 double y = y0 + x * (y1 - y0);
982 double param_b = uv_eb[0].param + x * (uv_eb[nb-1].param - uv_eb[0].param);
983 double param_t = uv_et[0].param + x * (uv_et[nt-1].param - uv_et[0].param);
984 double param_r = uv_er[0].param + y * (uv_er[nr-1].param - uv_er[0].param);
985 double param_l = uv_el[0].param + y * (uv_el[nl-1].param - uv_el[0].param);
987 gp_Pnt2d p0 = c2db->Value(param_b);
988 gp_Pnt2d p1 = c2dr->Value(param_r);
989 gp_Pnt2d p2 = c2dt->Value(param_t);
990 gp_Pnt2d p3 = c2dl->Value(param_l);
992 double u = (1 - y) * p0.X() + x * p1.X() + y * p2.X() + (1 - x) * p3.X();
993 double v = (1 - y) * p0.Y() + x * p1.Y() + y * p2.Y() + (1 - x) * p3.Y();
995 u -= (1 - x) * (1 - y) * a0.X() + x * (1 - y) * a1.X() +
996 x * y * a2.X() + (1 - x) * y * a3.X();
997 v -= (1 - x) * (1 - y) * a0.Y() + x * (1 - y) * a1.Y() +
998 x * y * a2.Y() + (1 - x) * y * a3.Y();
1000 //cout<<"x0="<<x0<<" x1="<<x1<<" y0="<<y0<<" y1="<<y1<<endl;
1001 //cout<<"x="<<x<<" y="<<y<<endl;
1002 //cout<<"param_b="<<param_b<<" param_t="<<param_t<<" param_r="<<param_r<<" param_l="<<param_l<<endl;
1003 //cout<<"u="<<u<<" v="<<v<<endl;
1009 //=======================================================================
1010 //function : ComputeQuadPref
1012 //=======================================================================
1014 * Special function for creation only quandrangle faces
1016 bool StdMeshers_Quadrangle_2D::ComputeQuadPref
1017 (SMESH_Mesh & aMesh,
1018 const TopoDS_Shape& aShape,
1019 FaceQuadStruct* quad) throw (SALOME_Exception)
1021 Unexpect aCatch(SalomeException);
1023 SMESHDS_Mesh * meshDS = aMesh.GetMeshDS();
1024 const TopoDS_Face& F = TopoDS::Face(aShape);
1025 Handle(Geom_Surface) S = BRep_Tool::Surface(F);
1026 const TopoDS_Wire& W = BRepTools::OuterWire(F);
1028 if(W.Orientation()==TopAbs_FORWARD)
1030 //if(WisF) cout<<"W is FORWARD"<<endl;
1031 //else cout<<"W is REVERSED"<<endl;
1032 bool FisF = (F.Orientation()==TopAbs_FORWARD);
1033 if(!FisF) WisF = !WisF;
1034 int i,j,geomFaceID = meshDS->ShapeToIndex( F );
1036 int nb = quad->nbPts[0];
1037 int nr = quad->nbPts[1];
1038 int nt = quad->nbPts[2];
1039 int nl = quad->nbPts[3];
1040 int dh = abs(nb-nt);
1041 int dv = abs(nr-nl);
1045 // it is a base case => not shift quad but me be replacement is need
1046 ShiftQuad(quad,0,WisF);
1049 // we have to shift quad on 2
1050 ShiftQuad(quad,2,WisF);
1055 // we have to shift quad on 3
1056 ShiftQuad(quad,3,WisF);
1059 // we have to shift quad on 1
1060 ShiftQuad(quad,1,WisF);
1064 nb = quad->nbPts[0];
1065 nr = quad->nbPts[1];
1066 nt = quad->nbPts[2];
1067 nl = quad->nbPts[3];
1070 int nbh = Max(nb,nt);
1071 int nbv = Max(nr,nl);
1075 // orientation of face and 3 main domain for future faces
1081 // left | | | | rigth
1097 Handle(Geom2d_Curve) c2d[4];
1098 for(i=0; i<4; i++) {
1099 c2d[i] = BRep_Tool::CurveOnSurface(quad->edge[i], F,
1100 quad->first[i], quad->last[i]);
1104 for(i=0; i<2; i++) {
1105 quad->uv_edges[i] = LoadEdgePoints2(aMesh, F, quad->edge[i], false);
1106 if(!quad->uv_edges[i]) loadOk = false;
1108 for(i=2; i<4; i++) {
1109 quad->uv_edges[i] = LoadEdgePoints2(aMesh, F, quad->edge[i], true);
1110 if (!quad->uv_edges[i]) loadOk = false;
1113 INFOS("StdMeshers_Quadrangle_2D::ComputeQuadPref - LoadEdgePoints failed");
1119 UVPtStruct* uv_eb = quad->uv_edges[0];
1120 UVPtStruct* uv_er = quad->uv_edges[1];
1121 UVPtStruct* uv_et = quad->uv_edges[2];
1122 UVPtStruct* uv_el = quad->uv_edges[3];
1124 // arrays for normalized params
1125 //cout<<"Dump B:"<<endl;
1126 TColStd_SequenceOfReal npb, npr, npt, npl;
1127 for(i=0; i<nb; i++) {
1128 npb.Append(uv_eb[i].normParam);
1129 //cout<<"i="<<i<<" par="<<uv_eb[i].param<<" npar="<<uv_eb[i].normParam;
1130 //const SMDS_MeshNode* N = uv_eb[i].node;
1131 //cout<<" node("<<N->X()<<","<<N->Y()<<","<<N->Z()<<")"<<endl;
1133 for(i=0; i<nr; i++) {
1134 npr.Append(uv_er[i].normParam);
1136 for(i=0; i<nt; i++) {
1137 npt.Append(uv_et[i].normParam);
1139 for(i=0; i<nl; i++) {
1140 npl.Append(uv_el[i].normParam);
1143 // we have to add few values of params to right and left
1144 // insert them after first param
1147 double dpr = (npr.Value(2) - npr.Value(1))/(dr+1);
1148 for(i=1; i<=dr; i++) {
1149 npr.InsertAfter(1,npr.Value(2)-dpr);
1153 dpr = (npl.Value(2) - npl.Value(1))/(dl+1);
1154 for(i=1; i<=dl; i++) {
1155 npl.InsertAfter(1,npl.Value(2)-dpr);
1158 //for(i=1; i<=npb.Length(); i++) {
1159 // cout<<" "<<npb.Value(i);
1164 c2d[0]->D0(uv_eb[0].param,a[0]);
1165 c2d[0]->D0(uv_eb[nb-1].param,a[1]);
1166 c2d[2]->D0(uv_et[nt-1].param,a[2]);
1167 c2d[2]->D0(uv_et[0].param,a[3]);
1168 //cout<<" a[0]("<<a[0].X()<<","<<a[0].Y()<<")"<<" a[1]("<<a[1].X()<<","<<a[1].Y()<<")"
1169 // <<" a[2]("<<a[2].X()<<","<<a[2].Y()<<")"<<" a[3]("<<a[3].X()<<","<<a[3].Y()<<")"<<endl;
1171 int nnn = Min(nr,nl);
1172 // auxilary sequence of XY for creation nodes
1173 // in the bottom part of central domain
1174 // it's length must be == nbv-nnn-1
1175 TColgp_SequenceOfXY UVL;
1176 TColgp_SequenceOfXY UVR;
1178 // step1: create faces for left domain
1179 StdMeshers_Array2OfNode NodesL(1,dl+1,1,nl);
1181 for(j=1; j<=nl; j++)
1182 NodesL.SetValue(1,j,uv_el[j-1].node);
1185 for(i=1; i<=dl; i++)
1186 NodesL.SetValue(i+1,nl,uv_et[i].node);
1187 // create and add needed nodes
1188 TColgp_SequenceOfXY UVtmp;
1189 for(i=1; i<=dl; i++) {
1190 double x0 = npt.Value(i+1);
1193 double y0 = npl.Value(i+1);
1194 double y1 = npr.Value(i+1);
1195 gp_XY UV = CalcUV(x0, x1, y0, y1, quad, a[0], a[1], a[2], a[3],
1196 c2d[0], c2d[1], c2d[2], c2d[3]);
1197 gp_Pnt P = S->Value(UV.X(),UV.Y());
1198 SMDS_MeshNode * N = meshDS->AddNode(P.X(), P.Y(), P.Z());
1199 meshDS->SetNodeOnFace(N, geomFaceID, UV.X(), UV.Y());
1200 NodesL.SetValue(i+1,1,N);
1201 if(UVL.Length()<nbv-nnn-1) UVL.Append(UV);
1203 for(j=2; j<nl; j++) {
1204 double y0 = npl.Value(dl+j);
1205 double y1 = npr.Value(dl+j);
1206 gp_XY UV = CalcUV(x0, x1, y0, y1, quad, a[0], a[1], a[2], a[3],
1207 c2d[0], c2d[1], c2d[2], c2d[3]);
1208 gp_Pnt P = S->Value(UV.X(),UV.Y());
1209 SMDS_MeshNode* N = meshDS->AddNode(P.X(), P.Y(), P.Z());
1210 meshDS->SetNodeOnFace(N, geomFaceID, UV.X(), UV.Y());
1211 NodesL.SetValue(i+1,j,N);
1212 if( i==dl ) UVtmp.Append(UV);
1215 for(i=1; i<=UVtmp.Length() && UVL.Length()<nbv-nnn-1; i++) {
1216 UVL.Append(UVtmp.Value(i));
1218 //cout<<"Dump NodesL:"<<endl;
1219 //for(i=1; i<=dl+1; i++) {
1221 // for(j=1; j<=nl; j++) {
1222 // cout<<" ("<<NodesL.Value(i,j)->X()<<","<<NodesL.Value(i,j)->Y()<<","<<NodesL.Value(i,j)->Z()<<")";
1227 for(i=1; i<=dl; i++) {
1228 for(j=1; j<nl; j++) {
1231 myTool->AddFace(NodesL.Value(i,j), NodesL.Value(i+1,j),
1232 NodesL.Value(i+1,j+1), NodesL.Value(i,j+1));
1233 meshDS->SetMeshElementOnShape(F, geomFaceID);
1237 myTool->AddFace(NodesL.Value(i,j), NodesL.Value(i,j+1),
1238 NodesL.Value(i+1,j+1), NodesL.Value(i+1,j));
1239 meshDS->SetMeshElementOnShape(F, geomFaceID);
1245 // fill UVL using c2d
1246 for(i=1; i<npl.Length() && UVL.Length()<nbv-nnn-1; i++) {
1248 c2d[3]->D0(uv_el[i].param,p2d);
1249 UVL.Append(p2d.XY());
1253 // step2: create faces for right domain
1254 StdMeshers_Array2OfNode NodesR(1,dr+1,1,nr);
1256 for(j=1; j<=nr; j++)
1257 NodesR.SetValue(1,j,uv_er[nr-j].node);
1260 for(i=1; i<=dr; i++)
1261 NodesR.SetValue(i+1,1,uv_et[nt-1-i].node);
1262 // create and add needed nodes
1263 TColgp_SequenceOfXY UVtmp;
1264 for(i=1; i<=dr; i++) {
1265 double x0 = npt.Value(nt-i);
1268 double y0 = npl.Value(i+1);
1269 double y1 = npr.Value(i+1);
1270 gp_XY UV = CalcUV(x0, x1, y0, y1, quad, a[0], a[1], a[2], a[3],
1271 c2d[0], c2d[1], c2d[2], c2d[3]);
1272 gp_Pnt P = S->Value(UV.X(),UV.Y());
1273 SMDS_MeshNode * N = meshDS->AddNode(P.X(), P.Y(), P.Z());
1274 meshDS->SetNodeOnFace(N, geomFaceID, UV.X(), UV.Y());
1275 NodesR.SetValue(i+1,nr,N);
1276 if(UVR.Length()<nbv-nnn-1) UVR.Append(UV);
1278 for(j=2; j<nr; j++) {
1279 double y0 = npl.Value(nbv-j+1);
1280 double y1 = npr.Value(nbv-j+1);
1281 gp_XY UV = CalcUV(x0, x1, y0, y1, quad, a[0], a[1], a[2], a[3],
1282 c2d[0], c2d[1], c2d[2], c2d[3]);
1283 gp_Pnt P = S->Value(UV.X(),UV.Y());
1284 SMDS_MeshNode* N = meshDS->AddNode(P.X(), P.Y(), P.Z());
1285 meshDS->SetNodeOnFace(N, geomFaceID, UV.X(), UV.Y());
1286 NodesR.SetValue(i+1,j,N);
1287 if( i==dr ) UVtmp.Prepend(UV);
1290 for(i=1; i<=UVtmp.Length() && UVR.Length()<nbv-nnn-1; i++) {
1291 UVR.Append(UVtmp.Value(i));
1294 for(i=1; i<=dr; i++) {
1295 for(j=1; j<nr; j++) {
1298 myTool->AddFace(NodesR.Value(i,j), NodesR.Value(i+1,j),
1299 NodesR.Value(i+1,j+1), NodesR.Value(i,j+1));
1300 meshDS->SetMeshElementOnShape(F, geomFaceID);
1304 myTool->AddFace(NodesR.Value(i,j), NodesR.Value(i,j+1),
1305 NodesR.Value(i+1,j+1), NodesR.Value(i+1,j));
1306 meshDS->SetMeshElementOnShape(F, geomFaceID);
1312 // fill UVR using c2d
1313 for(i=1; i<npr.Length() && UVR.Length()<nbv-nnn-1; i++) {
1315 c2d[1]->D0(uv_er[i].param,p2d);
1316 UVR.Append(p2d.XY());
1320 // step3: create faces for central domain
1321 StdMeshers_Array2OfNode NodesC(1,nb,1,nbv);
1322 // add first string using NodesL
1323 for(i=1; i<=dl+1; i++)
1324 NodesC.SetValue(1,i,NodesL(i,1));
1325 for(i=2; i<=nl; i++)
1326 NodesC.SetValue(1,dl+i,NodesL(dl+1,i));
1327 // add last string using NodesR
1328 for(i=1; i<=dr+1; i++)
1329 NodesC.SetValue(nb,i,NodesR(i,nr));
1331 NodesC.SetValue(nb,dr+i+1,NodesR(dr+1,nr-i));
1332 // add top nodes (last columns)
1333 for(i=dl+2; i<nbh-dr; i++)
1334 NodesC.SetValue(i-dl,nbv,uv_et[i-1].node);
1335 // add bottom nodes (first columns)
1336 for(i=2; i<nb; i++) {
1337 NodesC.SetValue(i,1,uv_eb[i-1].node);
1339 c2d[0]->D0(uv_eb[i-1].param,p2d);
1341 // create and add needed nodes
1342 // add linear layers
1343 for(i=2; i<nb; i++) {
1344 double x0 = npt.Value(dl+i);
1346 for(j=1; j<nnn; j++) {
1347 double y0 = npl.Value(nbv-nnn+j);
1348 double y1 = npr.Value(nbv-nnn+j);
1349 gp_XY UV = CalcUV(x0, x1, y0, y1, quad, a[0], a[1], a[2], a[3],
1350 c2d[0], c2d[1], c2d[2], c2d[3]);
1351 gp_Pnt P = S->Value(UV.X(),UV.Y());
1352 SMDS_MeshNode* N = meshDS->AddNode(P.X(), P.Y(), P.Z());
1353 meshDS->SetNodeOnFace(N, geomFaceID, UV.X(), UV.Y());
1354 NodesC.SetValue(i,nbv-nnn+j,N);
1357 // add diagonal layers
1358 //cout<<"UVL.Length()="<<UVL.Length()<<" UVR.Length()="<<UVR.Length()<<endl;
1359 //cout<<"Dump UVL:"<<endl;
1360 //for(i=1; i<=UVL.Length(); i++) {
1361 // cout<<" ("<<UVL.Value(i).X()<<","<<UVL.Value(i).Y()<<")";
1364 for(i=1; i<nbv-nnn; i++) {
1365 double du = UVR.Value(i).X() - UVL.Value(i).X();
1366 double dv = UVR.Value(i).Y() - UVL.Value(i).Y();
1367 for(j=2; j<nb; j++) {
1368 double u = UVL.Value(i).X() + du*npb.Value(j);
1369 double v = UVL.Value(i).Y() + dv*npb.Value(j);
1370 gp_Pnt P = S->Value(u,v);
1371 SMDS_MeshNode* N = meshDS->AddNode(P.X(), P.Y(), P.Z());
1372 meshDS->SetNodeOnFace(N, geomFaceID, u, v);
1373 NodesC.SetValue(j,i+1,N);
1377 for(i=1; i<nb; i++) {
1378 for(j=1; j<nbv; j++) {
1381 myTool->AddFace(NodesC.Value(i,j), NodesC.Value(i+1,j),
1382 NodesC.Value(i+1,j+1), NodesC.Value(i,j+1));
1383 meshDS->SetMeshElementOnShape(F, geomFaceID);
1387 myTool->AddFace(NodesC.Value(i,j), NodesC.Value(i,j+1),
1388 NodesC.Value(i+1,j+1), NodesC.Value(i+1,j));
1389 meshDS->SetMeshElementOnShape(F, geomFaceID);
1400 //=============================================================================
1404 //=============================================================================
1405 UVPtStruct* StdMeshers_Quadrangle_2D::LoadEdgePoints2 (SMESH_Mesh & aMesh,
1406 const TopoDS_Face& F,
1407 const TopoDS_Edge& E,
1410 //MESSAGE("StdMeshers_Quadrangle_2D::LoadEdgePoints");
1411 // --- IDNodes of first and last Vertex
1412 TopoDS_Vertex VFirst, VLast;
1413 TopExp::Vertices(E, VFirst, VLast); // corresponds to f and l
1415 ASSERT(!VFirst.IsNull());
1416 SMDS_NodeIteratorPtr lid = aMesh.GetSubMesh(VFirst)->GetSubMeshDS()->GetNodes();
1418 MESSAGE ( "NO NODE BUILT ON VERTEX" );
1421 const SMDS_MeshNode* idFirst = lid->next();
1423 ASSERT(!VLast.IsNull());
1424 lid = aMesh.GetSubMesh(VLast)->GetSubMeshDS()->GetNodes();
1426 MESSAGE ( "NO NODE BUILT ON VERTEX" );
1429 const SMDS_MeshNode* idLast = lid->next();
1431 // --- edge internal IDNodes (relies on good order storage, not checked)
1433 map<double, const SMDS_MeshNode *> params;
1434 SMDS_NodeIteratorPtr ite = aMesh.GetSubMesh(E)->GetSubMeshDS()->GetNodes();
1435 int nbPoints = aMesh.GetSubMesh(E)->GetSubMeshDS()->NbNodes();
1437 if(!_quadraticMesh) {
1438 while(ite->more()) {
1439 const SMDS_MeshNode* node = ite->next();
1440 const SMDS_EdgePosition* epos =
1441 static_cast<const SMDS_EdgePosition*>(node->GetPosition().get());
1442 double param = epos->GetUParameter();
1443 params[param] = node;
1447 vector<const SMDS_MeshNode*> nodes(nbPoints+2);
1449 nodes[nbPoints+1] = idLast;
1450 nbPoints = nbPoints/2;
1452 while(ite->more()) {
1453 const SMDS_MeshNode* node = ite->next();
1455 // check if node is medium
1456 bool IsMedium = false;
1457 SMDS_ElemIteratorPtr itn = node->GetInverseElementIterator();
1458 while (itn->more()) {
1459 const SMDS_MeshElement* elem = itn->next();
1460 if ( elem->GetType() != SMDSAbs_Edge )
1462 if(elem->IsMediumNode(node)) {
1469 const SMDS_EdgePosition* epos =
1470 static_cast<const SMDS_EdgePosition*>(node->GetPosition().get());
1471 double param = epos->GetUParameter();
1472 params[param] = node;
1476 if (nbPoints != params.size()) {
1477 MESSAGE( "BAD NODE ON EDGE POSITIONS" );
1480 UVPtStruct* uvslf = new UVPtStruct[nbPoints + 2];
1483 Handle(Geom2d_Curve) C2d = BRep_Tool::CurveOnSurface(E, F, f, l);
1485 const TopoDS_Wire& W = BRepTools::OuterWire(F);
1486 bool FisF = (F.Orientation()==TopAbs_FORWARD);
1487 bool WisF = (W.Orientation()==TopAbs_FORWARD);
1488 bool isForward = (E.Orientation()==TopAbs_FORWARD);
1489 //if(isForward) cout<<"E is FORWARD"<<endl;
1490 //else cout<<"E is REVERSED"<<endl;
1491 if(!WisF) isForward = !isForward;
1492 if(!FisF) isForward = !isForward;
1493 //bool isForward = !(E.Orientation()==TopAbs_FORWARD);
1494 if(IsReverse) isForward = !isForward;
1500 gp_Pnt2d p = C2d->Value(f); // first point = Vertex Forward
1504 uvslf[0].node = idFirst;
1505 //MESSAGE("__ f "<<f<<" "<<uvslf[0].x <<" "<<uvslf[0].y);
1506 map < double, const SMDS_MeshNode* >::iterator itp = params.begin();
1507 for (int i = 1; i <= nbPoints; i++) { // nbPoints internal
1508 double param = (*itp).first;
1509 gp_Pnt2d p = C2d->Value(param);
1512 uvslf[i].param = param;
1513 uvslf[i].node = (*itp).second;
1514 //MESSAGE("__ "<<i<<" "<<param<<" "<<uvslf[i].x <<" "<<uvslf[i].y);
1517 p = C2d->Value(l); // last point = Vertex Reversed
1518 uvslf[nbPoints + 1].x = p.X();
1519 uvslf[nbPoints + 1].y = p.Y();
1520 uvslf[nbPoints + 1].param = l;
1521 uvslf[nbPoints + 1].node = idLast;
1522 //MESSAGE("__ l "<<l<<" "<<uvslf[nbPoints+1].x <<" "<<uvslf[nbPoints+1].y);
1527 gp_Pnt2d p = C2d->Value(l); // first point = Vertex Reversed
1531 uvslf[0].node = idLast;
1532 //MESSAGE("__ l "<<l<<" "<<uvslf[0].x <<" "<<uvslf[0].y);
1533 map < double, const SMDS_MeshNode* >::reverse_iterator itp = params.rbegin();
1534 for (int j = nbPoints; j >= 1; j--) { // nbPoints internal
1535 double param = (*itp).first;
1536 int i = nbPoints + 1 - j;
1537 gp_Pnt2d p = C2d->Value(param);
1540 uvslf[i].param = param;
1541 uvslf[i].node = (*itp).second;
1542 //MESSAGE("__ "<<i<<" "<<param<<" "<<uvslf[i].x <<" "<<uvslf[i].y);
1545 p = C2d->Value(f); // last point = Vertex Forward
1546 uvslf[nbPoints + 1].x = p.X();
1547 uvslf[nbPoints + 1].y = p.Y();
1548 uvslf[nbPoints + 1].param = f;
1549 uvslf[nbPoints + 1].node = idFirst;
1550 //MESSAGE("__ f "<<f<<" "<<uvslf[nbPoints+1].x <<" "<<uvslf[nbPoints+1].y);
1553 ASSERT(paramin != paramax);
1554 for (int i = 0; i < nbPoints + 2; i++) {
1555 uvslf[i].normParam = (uvslf[i].param - paramin) / (paramax - paramin);
1562 //=============================================================================
1566 //=============================================================================
1567 UVPtStruct* StdMeshers_Quadrangle_2D::LoadEdgePoints (SMESH_Mesh & aMesh,
1568 const TopoDS_Face& F,
1569 const TopoDS_Edge& E,
1570 double first, double last)
1573 //MESSAGE("StdMeshers_Quadrangle_2D::LoadEdgePoints");
1575 // --- IDNodes of first and last Vertex
1577 TopoDS_Vertex VFirst, VLast;
1578 TopExp::Vertices(E, VFirst, VLast); // corresponds to f and l
1580 ASSERT(!VFirst.IsNull());
1581 SMDS_NodeIteratorPtr lid = aMesh.GetSubMesh(VFirst)->GetSubMeshDS()->GetNodes();
1584 MESSAGE ( "NO NODE BUILT ON VERTEX" );
1587 const SMDS_MeshNode* idFirst = lid->next();
1589 ASSERT(!VLast.IsNull());
1590 lid = aMesh.GetSubMesh(VLast)->GetSubMeshDS()->GetNodes();
1593 MESSAGE ( "NO NODE BUILT ON VERTEX" );
1596 const SMDS_MeshNode* idLast = lid->next();
1598 // --- edge internal IDNodes (relies on good order storage, not checked)
1600 // if(_quadraticMesh) {
1601 // fill myNLinkNodeMap
1602 // SMDS_ElemIteratorPtr iter = aMesh.GetSubMesh(E)->GetSubMeshDS()->GetElements();
1603 // while(iter->more()) {
1604 // const SMDS_MeshElement* elem = iter->next();
1605 // SMDS_ElemIteratorPtr nodeIt = elem->nodesIterator();
1606 // const SMDS_MeshNode* n1 = static_cast<const SMDS_MeshNode*>( nodeIt->next() );
1607 // const SMDS_MeshNode* n2 = static_cast<const SMDS_MeshNode*>( nodeIt->next() );
1608 // const SMDS_MeshNode* n3 = static_cast<const SMDS_MeshNode*>( nodeIt->next() );
1609 // NLink link(( n1 < n2 ? n1 : n2 ), ( n1 < n2 ? n2 : n1 ));
1610 // myNLinkNodeMap.insert(NLinkNodeMap::value_type(link,n3));
1611 // myNLinkNodeMap[link] = n3;
1615 map<double, const SMDS_MeshNode *> params;
1616 SMDS_NodeIteratorPtr ite = aMesh.GetSubMesh(E)->GetSubMeshDS()->GetNodes();
1617 int nbPoints = aMesh.GetSubMesh(E)->GetSubMeshDS()->NbNodes();
1619 if(!_quadraticMesh) {
1620 while(ite->more()) {
1621 const SMDS_MeshNode* node = ite->next();
1622 const SMDS_EdgePosition* epos =
1623 static_cast<const SMDS_EdgePosition*>(node->GetPosition().get());
1624 double param = epos->GetUParameter();
1625 params[param] = node;
1629 nbPoints = nbPoints/2;
1630 while(ite->more()) {
1631 const SMDS_MeshNode* node = ite->next();
1632 // check if node is medium
1633 bool IsMedium = false;
1634 SMDS_ElemIteratorPtr itn = node->GetInverseElementIterator();
1635 while (itn->more()) {
1636 const SMDS_MeshElement* elem = itn->next();
1637 if ( elem->GetType() != SMDSAbs_Edge )
1639 if(elem->IsMediumNode(node)) {
1646 const SMDS_EdgePosition* epos =
1647 static_cast<const SMDS_EdgePosition*>(node->GetPosition().get());
1648 double param = epos->GetUParameter();
1649 params[param] = node;
1653 if (nbPoints != params.size()) {
1654 MESSAGE( "BAD NODE ON EDGE POSITIONS" );
1657 UVPtStruct* uvslf = new UVPtStruct[nbPoints + 2];
1660 Handle(Geom2d_Curve) C2d = BRep_Tool::CurveOnSurface(E, F, f, l);
1662 bool isForward = (((l - f) * (last - first)) > 0);
1669 gp_Pnt2d p = C2d->Value(f); // first point = Vertex Forward
1673 uvslf[0].node = idFirst;
1674 //MESSAGE("__ f "<<f<<" "<<uvslf[0].x <<" "<<uvslf[0].y);
1675 map < double, const SMDS_MeshNode* >::iterator itp = params.begin();
1676 for (int i = 1; i <= nbPoints; i++) // nbPoints internal
1678 double param = (*itp).first;
1679 gp_Pnt2d p = C2d->Value(param);
1682 uvslf[i].param = param;
1683 uvslf[i].node = (*itp).second;
1684 //MESSAGE("__ "<<i<<" "<<param<<" "<<uvslf[i].x <<" "<<uvslf[i].y);
1687 p = C2d->Value(l); // last point = Vertex Reversed
1688 uvslf[nbPoints + 1].x = p.X();
1689 uvslf[nbPoints + 1].y = p.Y();
1690 uvslf[nbPoints + 1].param = l;
1691 uvslf[nbPoints + 1].node = idLast;
1692 //MESSAGE("__ l "<<l<<" "<<uvslf[nbPoints+1].x <<" "<<uvslf[nbPoints+1].y);
1697 gp_Pnt2d p = C2d->Value(l); // first point = Vertex Reversed
1701 uvslf[0].node = idLast;
1702 //MESSAGE("__ l "<<l<<" "<<uvslf[0].x <<" "<<uvslf[0].y);
1703 map < double, const SMDS_MeshNode* >::reverse_iterator itp = params.rbegin();
1705 for (int j = nbPoints; j >= 1; j--) // nbPoints internal
1707 double param = (*itp).first;
1708 int i = nbPoints + 1 - j;
1709 gp_Pnt2d p = C2d->Value(param);
1712 uvslf[i].param = param;
1713 uvslf[i].node = (*itp).second;
1714 //MESSAGE("__ "<<i<<" "<<param<<" "<<uvslf[i].x <<" "<<uvslf[i].y);
1717 p = C2d->Value(f); // last point = Vertex Forward
1718 uvslf[nbPoints + 1].x = p.X();
1719 uvslf[nbPoints + 1].y = p.Y();
1720 uvslf[nbPoints + 1].param = f;
1721 uvslf[nbPoints + 1].node = idFirst;
1722 //MESSAGE("__ f "<<f<<" "<<uvslf[nbPoints+1].x <<" "<<uvslf[nbPoints+1].y);
1725 ASSERT(paramin != paramax);
1726 for (int i = 0; i < nbPoints + 2; i++)
1728 uvslf[i].normParam = (uvslf[i].param - paramin) / (paramax - paramin);
1734 //=============================================================================
1738 //=============================================================================
1739 UVPtStruct* StdMeshers_Quadrangle_2D::MakeEdgePoints (SMESH_Mesh & aMesh,
1740 const TopoDS_Face& F,
1741 const TopoDS_Edge& E,
1742 double first, double last,
1745 // MESSAGE("StdMeshers_Quadrangle_2D::MakeEdgePoints");
1747 UVPtStruct* uvslf = new UVPtStruct[nb_segm + 1];
1748 list<double> params;
1750 // --- edge internal points
1752 Handle(Geom_Curve) Curve = BRep_Tool::Curve(E, fi, li);
1753 if (!Curve.IsNull()) {
1755 GeomAdaptor_Curve C3d (Curve);
1756 double length = EdgeLength(E);
1757 double eltSize = length / nb_segm;
1758 GCPnts_UniformAbscissa Discret (C3d, eltSize, fi, li);
1759 if (!Discret.IsDone()) return false;
1760 int NbPoints = Discret.NbPoints();
1761 for (int i = 1; i <= NbPoints; i++) {
1762 double param = Discret.Parameter(i);
1763 params.push_back(param);
1766 catch (Standard_Failure) {
1772 // Edge is a degenerated Edge
1773 BRep_Tool::Range(E, fi, li);
1774 double du = (li - fi) / nb_segm;
1775 for (int i = 1; i <= nb_segm + 1; i++)
1777 double param = fi + (i - 1) * du;
1778 params.push_back(param);
1783 Handle(Geom2d_Curve) C2d = BRep_Tool::CurveOnSurface(E, F, f, l);
1786 bool isForward = (((l - f) * (last - first)) > 0);
1788 list<double>::iterator itU = params.begin();
1789 for (int i = 0; i <= nb_segm; i++) // nbPoints internal
1791 double param = *itU;
1792 gp_Pnt2d p = C2d->Value(param);
1795 uvslf[i].param = param;
1796 uvslf[i].normParam = (param - f) / (l - f);
1800 list<double>::reverse_iterator itU = params.rbegin();
1801 for (int j = nb_segm; j >= 0; j--) // nbPoints internal
1803 double param = *itU;
1804 int i = nb_segm - j;
1805 gp_Pnt2d p = C2d->Value(param);
1808 uvslf[i].param = param;
1809 uvslf[i].normParam = (param - l) / (f - l);
1818 //=============================================================================
1822 //=============================================================================
1824 ostream & StdMeshers_Quadrangle_2D::SaveTo(ostream & save)
1829 //=============================================================================
1833 //=============================================================================
1835 istream & StdMeshers_Quadrangle_2D::LoadFrom(istream & load)
1840 //=============================================================================
1844 //=============================================================================
1846 ostream & operator <<(ostream & save, StdMeshers_Quadrangle_2D & hyp)
1848 return hyp.SaveTo( save );
1851 //=============================================================================
1855 //=============================================================================
1857 istream & operator >>(istream & load, StdMeshers_Quadrangle_2D & hyp)
1859 return hyp.LoadFrom( load );