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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
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>
51 #include <Precision.hxx>
52 #include <gp_Pnt2d.hxx>
53 #include <TColStd_ListIteratorOfListOfInteger.hxx>
55 #include "utilities.h"
56 #include "Utils_ExceptHandlers.hxx"
59 //=============================================================================
63 //=============================================================================
65 StdMeshers_Quadrangle_2D::StdMeshers_Quadrangle_2D (int hypId, int studyId, SMESH_Gen* gen)
66 : SMESH_2D_Algo(hypId, studyId, gen)
68 MESSAGE("StdMeshers_Quadrangle_2D::StdMeshers_Quadrangle_2D");
69 _name = "Quadrangle_2D";
70 _shapeType = (1 << TopAbs_FACE);
73 //=============================================================================
77 //=============================================================================
79 StdMeshers_Quadrangle_2D::~StdMeshers_Quadrangle_2D()
81 MESSAGE("StdMeshers_Quadrangle_2D::~StdMeshers_Quadrangle_2D");
84 //=============================================================================
88 //=============================================================================
90 bool StdMeshers_Quadrangle_2D::CheckHypothesis
92 const TopoDS_Shape& aShape,
93 SMESH_Hypothesis::Hypothesis_Status& aStatus)
96 aStatus = SMESH_Hypothesis::HYP_OK;
103 //=============================================================================
107 //=============================================================================
109 bool StdMeshers_Quadrangle_2D::Compute (SMESH_Mesh& aMesh,
110 const TopoDS_Shape& aShape) throw (SALOME_Exception)
112 Unexpect aCatch(SalomeException);
113 //MESSAGE("StdMeshers_Quadrangle_2D::Compute");
114 SMESHDS_Mesh * meshDS = aMesh.GetMeshDS();
115 aMesh.GetSubMesh(aShape);
117 FaceQuadStruct *quad = CheckAnd2Dcompute(aMesh, aShape);
121 // --- compute 3D values on points, store points & quadrangles
123 int nbdown = quad->nbPts[0];
124 int nbup = quad->nbPts[2];
126 int nbright = quad->nbPts[1];
127 int nbleft = quad->nbPts[3];
129 int nbhoriz = Min(nbdown, nbup);
130 int nbvertic = Min(nbright, nbleft);
132 const TopoDS_Face& F = TopoDS::Face(aShape);
133 Handle(Geom_Surface) S = BRep_Tool::Surface(F);
135 // internal mesh nodes
136 int i, j, geomFaceID = meshDS->ShapeToIndex( F );
137 for (i = 1; i < nbhoriz - 1; i++) {
138 for (j = 1; j < nbvertic - 1; j++) {
139 int ij = j * nbhoriz + i;
140 double u = quad->uv_grid[ij].u;
141 double v = quad->uv_grid[ij].v;
142 gp_Pnt P = S->Value(u, v);
143 SMDS_MeshNode * node = meshDS->AddNode(P.X(), P.Y(), P.Z());
144 meshDS->SetNodeOnFace(node, geomFaceID, u, v);
145 quad->uv_grid[ij].node = node;
152 // --.--.--.--.--.-- nbvertic
158 // ---.----.----.--- 0
159 // 0 > > > > > > > > nbhoriz
165 int iup = nbhoriz - 1;
166 if (quad->isEdgeOut[3]) { ilow++; } else { if (quad->isEdgeOut[1]) iup--; }
169 int jup = nbvertic - 1;
170 if (quad->isEdgeOut[0]) { jlow++; } else { if (quad->isEdgeOut[2]) jup--; }
172 // regular quadrangles
173 for (i = ilow; i < iup; i++) {
174 for (j = jlow; j < jup; j++) {
175 const SMDS_MeshNode *a, *b, *c, *d;
176 a = quad->uv_grid[j * nbhoriz + i].node;
177 b = quad->uv_grid[j * nbhoriz + i + 1].node;
178 c = quad->uv_grid[(j + 1) * nbhoriz + i + 1].node;
179 d = quad->uv_grid[(j + 1) * nbhoriz + i].node;
180 SMDS_MeshFace * face = meshDS->AddFace(a, b, c, d);
181 meshDS->SetMeshElementOnShape(face, geomFaceID);
185 UVPtStruct *uv_e0 = quad->uv_edges[0];
186 UVPtStruct *uv_e1 = quad->uv_edges[1];
187 UVPtStruct *uv_e2 = quad->uv_edges[2];
188 UVPtStruct *uv_e3 = quad->uv_edges[3];
190 double eps = Precision::Confusion();
192 // Boundary quadrangles
194 if (quad->isEdgeOut[0]) {
197 // |___|___|___|___|___|___|
199 // |___|___|___|___|___|___|
201 // |___|___|___|___|___|___| __ first row of the regular grid
202 // . . . . . . . . . __ down edge nodes
204 // >->->->->->->->->->->->-> -- direction of processing
206 int g = 0; // number of last processed node in the regular grid
208 // number of last node of the down edge to be processed
209 int stop = nbdown - 1;
210 // if right edge is out, we will stop at a node, previous to the last one
211 if (quad->isEdgeOut[1]) stop--;
213 // for each node of the down edge find nearest node
214 // in the first row of the regular grid and link them
215 for (i = 0; i < stop; i++) {
216 const SMDS_MeshNode *a, *b, *c, *d;
218 b = uv_e0[i + 1].node;
219 gp_Pnt pb (b->X(), b->Y(), b->Z());
221 // find node c in the regular grid, which will be linked with node b
224 // right bound reached, link with the rightmost node
226 c = quad->uv_grid[nbhoriz + iup].node;
228 // find in the grid node c, nearest to the b
229 double mind = RealLast();
230 for (int k = g; k <= iup; k++) {
232 const SMDS_MeshNode *nk;
233 if (k < ilow) // this can be, if left edge is out
234 nk = uv_e3[1].node; // get node from the left edge
236 nk = quad->uv_grid[nbhoriz + k].node; // get one of middle nodes
238 gp_Pnt pnk (nk->X(), nk->Y(), nk->Z());
239 double dist = pb.Distance(pnk);
240 if (dist < mind - eps) {
250 if (near == g) { // make triangle
251 SMDS_MeshFace* face = meshDS->AddFace(a, b, c);
252 meshDS->SetMeshElementOnShape(face, geomFaceID);
253 } else { // make quadrangle
257 d = quad->uv_grid[nbhoriz + near - 1].node;
258 SMDS_MeshFace* face = meshDS->AddFace(a, b, c, d);
259 meshDS->SetMeshElementOnShape(face, geomFaceID);
261 // if node d is not at position g - make additional triangles
263 for (int k = near - 1; k > g; k--) {
264 c = quad->uv_grid[nbhoriz + k].node;
268 d = quad->uv_grid[nbhoriz + k - 1].node;
269 SMDS_MeshFace* face = meshDS->AddFace(a, c, d);
270 meshDS->SetMeshElementOnShape(face, geomFaceID);
277 if (quad->isEdgeOut[2]) {
280 // <-<-<-<-<-<-<-<-<-<-<-<-< -- direction of processing
282 // . . . . . . . . . __ up edge nodes
283 // ___ ___ ___ ___ ___ ___ __ first row of the regular grid
285 // |___|___|___|___|___|___|
287 // |___|___|___|___|___|___|
290 int g = nbhoriz - 1; // last processed node in the regular grid
293 // if left edge is out, we will stop at a second node
294 if (quad->isEdgeOut[3]) stop++;
296 // for each node of the up edge find nearest node
297 // in the first row of the regular grid and link them
298 for (i = nbup - 1; i > stop; i--) {
299 const SMDS_MeshNode *a, *b, *c, *d;
301 b = uv_e2[i - 1].node;
302 gp_Pnt pb (b->X(), b->Y(), b->Z());
304 // find node c in the grid, which will be linked with node b
306 if (i == stop + 1) { // left bound reached, link with the leftmost node
307 c = quad->uv_grid[nbhoriz*(nbvertic - 2) + ilow].node;
310 // find node c in the grid, nearest to the b
311 double mind = RealLast();
312 for (int k = g; k >= ilow; k--) {
313 const SMDS_MeshNode *nk;
315 nk = uv_e1[nbright - 2].node;
317 nk = quad->uv_grid[nbhoriz*(nbvertic - 2) + k].node;
318 gp_Pnt pnk (nk->X(), nk->Y(), nk->Z());
319 double dist = pb.Distance(pnk);
320 if (dist < mind - eps) {
330 if (near == g) { // make triangle
331 SMDS_MeshFace* face = meshDS->AddFace(a, b, c);
332 meshDS->SetMeshElementOnShape(face, geomFaceID);
333 } else { // make quadrangle
335 d = uv_e1[nbright - 2].node;
337 d = quad->uv_grid[nbhoriz*(nbvertic - 2) + near + 1].node;
338 SMDS_MeshFace* face = meshDS->AddFace(a, b, c, d);
339 meshDS->SetMeshElementOnShape(face, geomFaceID);
341 if (near + 1 < g) { // if d not is at g - make additional triangles
342 for (int k = near + 1; k < g; k++) {
343 c = quad->uv_grid[nbhoriz*(nbvertic - 2) + k].node;
345 d = uv_e1[nbright - 2].node;
347 d = quad->uv_grid[nbhoriz*(nbvertic - 2) + k + 1].node;
348 SMDS_MeshFace* face = meshDS->AddFace(a, c, d);
349 meshDS->SetMeshElementOnShape(face, geomFaceID);
358 // right or left boundary quadrangles
359 if (quad->isEdgeOut[1]) {
360 // MESSAGE("right edge is out");
361 int g = 0; // last processed node in the grid
362 int stop = nbright - 1;
363 if (quad->isEdgeOut[2]) stop--;
364 for (i = 0; i < stop; i++) {
365 const SMDS_MeshNode *a, *b, *c, *d;
367 b = uv_e1[i + 1].node;
368 gp_Pnt pb (b->X(), b->Y(), b->Z());
370 // find node c in the grid, nearest to the b
372 if (i == stop - 1) { // up bondary reached
373 c = quad->uv_grid[nbhoriz*(jup + 1) - 2].node;
376 double mind = RealLast();
377 for (int k = g; k <= jup; k++) {
378 const SMDS_MeshNode *nk;
380 nk = uv_e0[nbdown - 2].node;
382 nk = quad->uv_grid[nbhoriz*(k + 1) - 2].node;
383 gp_Pnt pnk (nk->X(), nk->Y(), nk->Z());
384 double dist = pb.Distance(pnk);
385 if (dist < mind - eps) {
395 if (near == g) { // make triangle
396 SMDS_MeshFace* face = meshDS->AddFace(a, b, c);
397 meshDS->SetMeshElementOnShape(face, geomFaceID);
398 } else { // make quadrangle
400 d = uv_e0[nbdown - 2].node;
402 d = quad->uv_grid[nbhoriz*near - 2].node;
403 SMDS_MeshFace* face = meshDS->AddFace(a, b, c, d);
404 meshDS->SetMeshElementOnShape(face, geomFaceID);
406 if (near - 1 > g) { // if d not is at g - make additional triangles
407 for (int k = near - 1; k > g; k--) {
408 c = quad->uv_grid[nbhoriz*(k + 1) - 2].node;
410 d = uv_e0[nbdown - 2].node;
412 d = quad->uv_grid[nbhoriz*k - 2].node;
413 SMDS_MeshFace* face = meshDS->AddFace(a, c, d);
414 meshDS->SetMeshElementOnShape(face, geomFaceID);
421 if (quad->isEdgeOut[3]) {
422 // MESSAGE("left edge is out");
423 int g = nbvertic - 1; // last processed node in the grid
425 if (quad->isEdgeOut[0]) stop++;
426 for (i = nbleft - 1; i > stop; i--) {
427 const SMDS_MeshNode *a, *b, *c, *d;
429 b = uv_e3[i - 1].node;
430 gp_Pnt pb (b->X(), b->Y(), b->Z());
432 // find node c in the grid, nearest to the b
434 if (i == stop + 1) { // down bondary reached
435 c = quad->uv_grid[nbhoriz*jlow + 1].node;
438 double mind = RealLast();
439 for (int k = g; k >= jlow; k--) {
440 const SMDS_MeshNode *nk;
444 nk = quad->uv_grid[nbhoriz*k + 1].node;
445 gp_Pnt pnk (nk->X(), nk->Y(), nk->Z());
446 double dist = pb.Distance(pnk);
447 if (dist < mind - eps) {
457 if (near == g) { // make triangle
458 SMDS_MeshFace* face = meshDS->AddFace(a, b, c);
459 meshDS->SetMeshElementOnShape(face, geomFaceID);
460 } else { // make quadrangle
464 d = quad->uv_grid[nbhoriz*(near + 1) + 1].node;
465 SMDS_MeshFace* face = meshDS->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].node;
474 d = quad->uv_grid[nbhoriz*(k + 1) + 1].node;
475 SMDS_MeshFace* face = meshDS->AddFace(a, c, d);
476 meshDS->SetMeshElementOnShape(face, geomFaceID);
490 //=============================================================================
494 //=============================================================================
496 FaceQuadStruct *StdMeshers_Quadrangle_2D::CheckAnd2Dcompute
497 (SMESH_Mesh & aMesh, const TopoDS_Shape & aShape) throw(SALOME_Exception)
499 Unexpect aCatch(SalomeException);
501 const TopoDS_Face & F = TopoDS::Face(aShape);
503 // verify 1 wire only, with 4 edges
505 if (NumberOfWires(F) != 1)
507 INFOS("only 1 wire by face (quadrangles)");
510 const TopoDS_Wire& W = BRepTools::OuterWire(F);
511 BRepTools_WireExplorer wexp (W, F);
513 FaceQuadStruct *quad = new FaceQuadStruct;
514 for (int i = 0; i < 4; i++)
515 quad->uv_edges[i] = 0;
519 for (wexp.Init(W, F); wexp.More(); wexp.Next())
521 const TopoDS_Edge& E = wexp.Current();
522 int nb = aMesh.GetSubMesh(E)->GetSubMeshDS()->NbNodes();
525 quad->edge[nbEdges] = E;
526 quad->nbPts[nbEdges] = nb + 2; // internal points + 2 extrema
533 INFOS("face must have 4 edges /quadrangles");
538 // set normalized grid on unit square in parametric domain
540 SetNormalizedGrid(aMesh, F, quad);
545 //=============================================================================
549 //=============================================================================
551 void StdMeshers_Quadrangle_2D::QuadDelete (FaceQuadStruct * quad)
553 //MESSAGE("StdMeshers_Quadrangle_2D::QuadDelete");
556 for (int i = 0; i < 4; i++)
558 if (quad->uv_edges[i])
559 delete [] quad->uv_edges[i];
560 quad->edge[i].Nullify();
563 delete [] quad->uv_grid;
568 //=============================================================================
572 //=============================================================================
574 void StdMeshers_Quadrangle_2D::SetNormalizedGrid (SMESH_Mesh & aMesh,
575 const TopoDS_Shape& aShape,
576 FaceQuadStruct* quad) throw (SALOME_Exception)
578 Unexpect aCatch(SalomeException);
579 // Algorithme décrit dans "Génération automatique de maillages"
580 // P.L. GEORGE, MASSON, § 6.4.1 p. 84-85
581 // traitement dans le domaine paramétrique 2d u,v
582 // transport - projection sur le carré unité
584 // MESSAGE("StdMeshers_Quadrangle_2D::SetNormalizedGrid");
585 const TopoDS_Face& F = TopoDS::Face(aShape);
587 // 1 --- find orientation of the 4 edges, by test on extrema
590 // |<----north-2-------^ a3 -------------> a2
592 // west-3 east-1 =right | |
596 // v----south-0--------> a0 -------------> a1
601 Handle(Geom2d_Curve) c2d[4];
604 for (int i = 0; i < 4; i++)
606 c2d[i] = BRep_Tool::CurveOnSurface(quad->edge[i], F,
607 quad->first[i], quad->last[i]);
608 pf[i] = c2d[i]->Value(quad->first[i]);
609 pl[i] = c2d[i]->Value(quad->last[i]);
610 quad->isEdgeForward[i] = false;
613 double l0f1 = pl[0].SquareDistance(pf[1]);
614 double l0l1 = pl[0].SquareDistance(pl[1]);
615 double f0f1 = pf[0].SquareDistance(pf[1]);
616 double f0l1 = pf[0].SquareDistance(pl[1]);
617 if ( Min( l0f1, l0l1 ) < Min ( f0f1, f0l1 ))
619 quad->isEdgeForward[0] = true;
621 double tmp = quad->first[0];
622 quad->first[0] = quad->last[0];
624 pf[0] = c2d[0]->Value(quad->first[0]);
625 pl[0] = c2d[0]->Value(quad->last[0]);
627 for (int i = 1; i < 4; i++)
629 l0l1 = pl[i - 1].SquareDistance(pl[i]);
630 l0f1 = pl[i - 1].SquareDistance(pf[i]);
631 quad->isEdgeForward[i] = ( l0f1 < l0l1 );
632 if (!quad->isEdgeForward[i])
634 double tmp = quad->first[i];
635 quad->first[i] = quad->last[i];
637 pf[i] = c2d[i]->Value(quad->first[i]);
638 pl[i] = c2d[i]->Value(quad->last[i]);
642 // 2 --- load 2d edge points (u,v) with orientation and value on unit square
645 for (int i = 0; i < 2; i++)
647 quad->uv_edges[i] = LoadEdgePoints(aMesh, F, quad->edge[i],
648 quad->first[i], quad->last[i]);
649 if (!quad->uv_edges[i]) loadOk = false;
652 for (int i = 2; i < 4; i++)
654 quad->uv_edges[i] = LoadEdgePoints(aMesh, F, quad->edge[i],
655 quad->last[i], quad->first[i]);
656 if (!quad->uv_edges[i]) loadOk = false;
661 INFOS("StdMeshers_Quadrangle_2D::SetNormalizedGrid - LoadEdgePoints failed");
666 // 3 --- 2D normalized values on unit square [0..1][0..1]
668 int nbhoriz = Min(quad->nbPts[0], quad->nbPts[2]);
669 int nbvertic = Min(quad->nbPts[1], quad->nbPts[3]);
671 quad->isEdgeOut[0] = (quad->nbPts[0] > quad->nbPts[2]);
672 quad->isEdgeOut[1] = (quad->nbPts[1] > quad->nbPts[3]);
673 quad->isEdgeOut[2] = (quad->nbPts[2] > quad->nbPts[0]);
674 quad->isEdgeOut[3] = (quad->nbPts[3] > quad->nbPts[1]);
676 quad->uv_grid = new UVPtStruct[nbvertic * nbhoriz];
678 UVPtStruct *uv_grid = quad->uv_grid;
679 UVPtStruct *uv_e0 = quad->uv_edges[0];
680 UVPtStruct *uv_e1 = quad->uv_edges[1];
681 UVPtStruct *uv_e2 = quad->uv_edges[2];
682 UVPtStruct *uv_e3 = quad->uv_edges[3];
684 // nodes Id on "in" edges
685 if (! quad->isEdgeOut[0]) {
687 for (int i = 0; i < nbhoriz; i++) { // down
688 int ij = j * nbhoriz + i;
689 uv_grid[ij].node = uv_e0[i].node;
692 if (! quad->isEdgeOut[1]) {
694 for (int j = 0; j < nbvertic; j++) { // right
695 int ij = j * nbhoriz + i;
696 uv_grid[ij].node = uv_e1[j].node;
699 if (! quad->isEdgeOut[2]) {
700 int j = nbvertic - 1;
701 for (int i = 0; i < nbhoriz; i++) { // up
702 int ij = j * nbhoriz + i;
703 uv_grid[ij].node = uv_e2[i].node;
706 if (! quad->isEdgeOut[3]) {
708 for (int j = 0; j < nbvertic; j++) { // left
709 int ij = j * nbhoriz + i;
710 uv_grid[ij].node = uv_e3[j].node;
714 // falsificate "out" edges
715 if (quad->isEdgeOut[0]) // down
716 uv_e0 = MakeEdgePoints
717 (aMesh, F, quad->edge[0], quad->first[0], quad->last[0], nbhoriz - 1);
718 else if (quad->isEdgeOut[2]) // up
719 uv_e2 = MakeEdgePoints
720 (aMesh, F, quad->edge[2], quad->last[2], quad->first[2], nbhoriz - 1);
722 if (quad->isEdgeOut[1]) // right
723 uv_e1 = MakeEdgePoints
724 (aMesh, F, quad->edge[1], quad->first[1], quad->last[1], nbvertic - 1);
725 else if (quad->isEdgeOut[3]) // left
726 uv_e3 = MakeEdgePoints
727 (aMesh, F, quad->edge[3], quad->last[3], quad->first[3], nbvertic - 1);
729 // normalized 2d values on grid
730 for (int i = 0; i < nbhoriz; i++)
732 for (int j = 0; j < nbvertic; j++)
734 int ij = j * nbhoriz + i;
735 // --- droite i cste : x = x0 + y(x1-x0)
736 double x0 = uv_e0[i].normParam; // bas - sud
737 double x1 = uv_e2[i].normParam; // haut - nord
738 // --- droite j cste : y = y0 + x(y1-y0)
739 double y0 = uv_e3[j].normParam; // gauche-ouest
740 double y1 = uv_e1[j].normParam; // droite - est
741 // --- intersection : x=x0+(y0+x(y1-y0))(x1-x0)
742 double x = (x0 + y0 * (x1 - x0)) / (1 - (y1 - y0) * (x1 - x0));
743 double y = y0 + x * (y1 - y0);
746 //MESSAGE("-xy-01 "<<x0<<" "<<x1<<" "<<y0<<" "<<y1);
747 //MESSAGE("-xy-norm "<<i<<" "<<j<<" "<<x<<" "<<y);
751 // 4 --- projection on 2d domain (u,v)
757 for (int i = 0; i < nbhoriz; i++)
759 for (int j = 0; j < nbvertic; j++)
761 int ij = j * nbhoriz + i;
762 double x = uv_grid[ij].x;
763 double y = uv_grid[ij].y;
764 double param_0 = uv_e0[0].param + x * (uv_e0[nbhoriz - 1].param - uv_e0[0].param); // sud
765 double param_2 = uv_e2[0].param + x * (uv_e2[nbhoriz - 1].param - uv_e2[0].param); // nord
766 double param_1 = uv_e1[0].param + y * (uv_e1[nbvertic - 1].param - uv_e1[0].param); // est
767 double param_3 = uv_e3[0].param + y * (uv_e3[nbvertic - 1].param - uv_e3[0].param); // ouest
769 //MESSAGE("params "<<param_0<<" "<<param_1<<" "<<param_2<<" "<<param_3);
770 gp_Pnt2d p0 = c2d[0]->Value(param_0);
771 gp_Pnt2d p1 = c2d[1]->Value(param_1);
772 gp_Pnt2d p2 = c2d[2]->Value(param_2);
773 gp_Pnt2d p3 = c2d[3]->Value(param_3);
775 double u = (1 - y) * p0.X() + x * p1.X() + y * p2.X() + (1 - x) * p3.X();
776 double v = (1 - y) * p0.Y() + x * p1.Y() + y * p2.Y() + (1 - x) * p3.Y();
778 u -= (1 - x) * (1 - y) * a0.X() + x * (1 - y) * a1.X() +
779 x * y * a2.X() + (1 - x) * y * a3.X();
780 v -= (1 - x) * (1 - y) * a0.Y() + x * (1 - y) * a1.Y() +
781 x * y * a2.Y() + (1 - x) * y * a3.Y();
789 //=============================================================================
793 //=============================================================================
794 UVPtStruct* StdMeshers_Quadrangle_2D::LoadEdgePoints (SMESH_Mesh & aMesh,
795 const TopoDS_Face& F,
796 const TopoDS_Edge& E,
797 double first, double last)
800 //MESSAGE("StdMeshers_Quadrangle_2D::LoadEdgePoints");
802 // --- IDNodes of first and last Vertex
804 TopoDS_Vertex VFirst, VLast;
805 TopExp::Vertices(E, VFirst, VLast); // corresponds to f and l
807 ASSERT(!VFirst.IsNull());
808 SMDS_NodeIteratorPtr lid = aMesh.GetSubMesh(VFirst)->GetSubMeshDS()->GetNodes();
811 MESSAGE ( "NO NODE BUILT ON VERTEX" );
814 const SMDS_MeshNode* idFirst = lid->next();
816 ASSERT(!VLast.IsNull());
817 lid = aMesh.GetSubMesh(VLast)->GetSubMeshDS()->GetNodes();
820 MESSAGE ( "NO NODE BUILT ON VERTEX" );
823 const SMDS_MeshNode* idLast = lid->next();
825 // --- edge internal IDNodes (relies on good order storage, not checked)
827 map<double, const SMDS_MeshNode *> params;
828 SMDS_NodeIteratorPtr ite = aMesh.GetSubMesh(E)->GetSubMeshDS()->GetNodes();
832 const SMDS_MeshNode* node = ite->next();
833 const SMDS_EdgePosition* epos =
834 static_cast<const SMDS_EdgePosition*>(node->GetPosition().get());
835 double param = epos->GetUParameter();
836 params[param] = node;
839 int nbPoints = aMesh.GetSubMesh(E)->GetSubMeshDS()->NbNodes();
840 if (nbPoints != params.size())
842 MESSAGE( "BAD NODE ON EDGE POSITIONS" );
845 UVPtStruct* uvslf = new UVPtStruct[nbPoints + 2];
848 Handle(Geom2d_Curve) C2d = BRep_Tool::CurveOnSurface(E, F, f, l);
850 bool isForward = (((l - f) * (last - first)) > 0);
857 gp_Pnt2d p = C2d->Value(f); // first point = Vertex Forward
861 uvslf[0].node = idFirst;
862 //MESSAGE("__ f "<<f<<" "<<uvslf[0].x <<" "<<uvslf[0].y);
863 map < double, const SMDS_MeshNode* >::iterator itp = params.begin();
864 for (int i = 1; i <= nbPoints; i++) // nbPoints internal
866 double param = (*itp).first;
867 gp_Pnt2d p = C2d->Value(param);
870 uvslf[i].param = param;
871 uvslf[i].node = (*itp).second;
872 //MESSAGE("__ "<<i<<" "<<param<<" "<<uvslf[i].x <<" "<<uvslf[i].y);
875 p = C2d->Value(l); // last point = Vertex Reversed
876 uvslf[nbPoints + 1].x = p.X();
877 uvslf[nbPoints + 1].y = p.Y();
878 uvslf[nbPoints + 1].param = l;
879 uvslf[nbPoints + 1].node = idLast;
880 //MESSAGE("__ l "<<l<<" "<<uvslf[nbPoints+1].x <<" "<<uvslf[nbPoints+1].y);
885 gp_Pnt2d p = C2d->Value(l); // first point = Vertex Reversed
889 uvslf[0].node = idLast;
890 //MESSAGE("__ l "<<l<<" "<<uvslf[0].x <<" "<<uvslf[0].y);
891 map < double, const SMDS_MeshNode* >::reverse_iterator itp = params.rbegin();
893 for (int j = nbPoints; j >= 1; j--) // nbPoints internal
895 double param = (*itp).first;
896 int i = nbPoints + 1 - j;
897 gp_Pnt2d p = C2d->Value(param);
900 uvslf[i].param = param;
901 uvslf[i].node = (*itp).second;
902 //MESSAGE("__ "<<i<<" "<<param<<" "<<uvslf[i].x <<" "<<uvslf[i].y);
905 p = C2d->Value(f); // last point = Vertex Forward
906 uvslf[nbPoints + 1].x = p.X();
907 uvslf[nbPoints + 1].y = p.Y();
908 uvslf[nbPoints + 1].param = f;
909 uvslf[nbPoints + 1].node = idFirst;
910 //MESSAGE("__ f "<<f<<" "<<uvslf[nbPoints+1].x <<" "<<uvslf[nbPoints+1].y);
913 ASSERT(paramin != paramax);
914 for (int i = 0; i < nbPoints + 2; i++)
916 uvslf[i].normParam = (uvslf[i].param - paramin) / (paramax - paramin);
922 //=============================================================================
926 //=============================================================================
927 UVPtStruct* StdMeshers_Quadrangle_2D::MakeEdgePoints (SMESH_Mesh & aMesh,
928 const TopoDS_Face& F,
929 const TopoDS_Edge& E,
930 double first, double last,
933 // MESSAGE("StdMeshers_Quadrangle_2D::MakeEdgePoints");
935 UVPtStruct* uvslf = new UVPtStruct[nb_segm + 1];
938 // --- edge internal points
940 Handle(Geom_Curve) Curve = BRep_Tool::Curve(E, fi, li);
941 if (!Curve.IsNull()) {
943 GeomAdaptor_Curve C3d (Curve);
944 double length = EdgeLength(E);
945 double eltSize = length / nb_segm;
946 GCPnts_UniformAbscissa Discret (C3d, eltSize, fi, li);
947 if (!Discret.IsDone()) return false;
948 int NbPoints = Discret.NbPoints();
949 for (int i = 1; i <= NbPoints; i++) {
950 double param = Discret.Parameter(i);
951 params.push_back(param);
954 catch (Standard_Failure) {
960 // Edge is a degenerated Edge
961 BRep_Tool::Range(E, fi, li);
962 double du = (li - fi) / nb_segm;
963 for (int i = 1; i <= nb_segm + 1; i++)
965 double param = fi + (i - 1) * du;
966 params.push_back(param);
971 Handle(Geom2d_Curve) C2d = BRep_Tool::CurveOnSurface(E, F, f, l);
974 bool isForward = (((l - f) * (last - first)) > 0);
976 list<double>::iterator itU = params.begin();
977 for (int i = 0; i <= nb_segm; i++) // nbPoints internal
980 gp_Pnt2d p = C2d->Value(param);
983 uvslf[i].param = param;
984 uvslf[i].normParam = (param - f) / (l - f);
988 list<double>::reverse_iterator itU = params.rbegin();
989 for (int j = nb_segm; j >= 0; j--) // nbPoints internal
993 gp_Pnt2d p = C2d->Value(param);
996 uvslf[i].param = param;
997 uvslf[i].normParam = (param - l) / (f - l);
1006 //=============================================================================
1010 //=============================================================================
1012 ostream & StdMeshers_Quadrangle_2D::SaveTo(ostream & save)
1017 //=============================================================================
1021 //=============================================================================
1023 istream & StdMeshers_Quadrangle_2D::LoadFrom(istream & load)
1028 //=============================================================================
1032 //=============================================================================
1034 ostream & operator <<(ostream & save, StdMeshers_Quadrangle_2D & hyp)
1036 return hyp.SaveTo( save );
1039 //=============================================================================
1043 //=============================================================================
1045 istream & operator >>(istream & load, StdMeshers_Quadrangle_2D & hyp)
1047 return hyp.LoadFrom( load );