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>
54 #include <TColStd_SequenceOfReal.hxx>
55 #include <TColgp_SequenceOfXY.hxx>
57 #include "utilities.h"
58 #include "Utils_ExceptHandlers.hxx"
60 #ifndef StdMeshers_Array2OfNode_HeaderFile
61 #define StdMeshers_Array2OfNode_HeaderFile
62 typedef const SMDS_MeshNode* SMDS_MeshNodePtr;
63 #include <NCollection_DefineArray2.hxx>
64 DEFINE_BASECOLLECTION (StdMeshers_BaseCollectionNodePtr, SMDS_MeshNodePtr)
65 DEFINE_ARRAY2(StdMeshers_Array2OfNode,
66 StdMeshers_BaseCollectionNodePtr, SMDS_MeshNodePtr)
70 //=============================================================================
74 //=============================================================================
76 StdMeshers_Quadrangle_2D::StdMeshers_Quadrangle_2D (int hypId, int studyId, SMESH_Gen* gen)
77 : SMESH_2D_Algo(hypId, studyId, gen)
79 MESSAGE("StdMeshers_Quadrangle_2D::StdMeshers_Quadrangle_2D");
80 _name = "Quadrangle_2D";
81 _shapeType = (1 << TopAbs_FACE);
82 _compatibleHypothesis.push_back("QuadranglePreference");
85 //=============================================================================
89 //=============================================================================
91 StdMeshers_Quadrangle_2D::~StdMeshers_Quadrangle_2D()
93 MESSAGE("StdMeshers_Quadrangle_2D::~StdMeshers_Quadrangle_2D");
96 //=============================================================================
100 //=============================================================================
102 bool StdMeshers_Quadrangle_2D::CheckHypothesis
104 const TopoDS_Shape& aShape,
105 SMESH_Hypothesis::Hypothesis_Status& aStatus)
108 aStatus = SMESH_Hypothesis::HYP_OK;
110 // there is only one compatible Hypothesis so far
111 const list <const SMESHDS_Hypothesis * >&hyps = GetUsedHypothesis(aMesh, aShape);
112 myQuadranglePreference = hyps.size() > 0;
117 //=============================================================================
121 //=============================================================================
123 bool StdMeshers_Quadrangle_2D::Compute (SMESH_Mesh& aMesh,
124 const TopoDS_Shape& aShape) throw (SALOME_Exception)
126 Unexpect aCatch(SalomeException);
127 //MESSAGE("StdMeshers_Quadrangle_2D::Compute");
128 SMESHDS_Mesh * meshDS = aMesh.GetMeshDS();
129 aMesh.GetSubMesh(aShape);
131 //FaceQuadStruct *quad = CheckAnd2Dcompute(aMesh, aShape);
132 FaceQuadStruct* quad = CheckNbEdges(aMesh, aShape);
137 if(myQuadranglePreference) {
138 int n1 = quad->nbPts[0];
139 int n2 = quad->nbPts[1];
140 int n3 = quad->nbPts[2];
141 int n4 = quad->nbPts[3];
142 int nfull = n1+n2+n3+n4;
145 if( nfull==ntmp && ( (n1!=n3) || (n2!=n4) ) ) {
146 // special path for using only quandrangle faces
147 return ComputeQuadPref(aMesh, aShape, quad);
151 // set normalized grid on unit square in parametric domain
152 SetNormalizedGrid(aMesh, aShape, quad);
156 // --- compute 3D values on points, store points & quadrangles
158 int nbdown = quad->nbPts[0];
159 int nbup = quad->nbPts[2];
161 int nbright = quad->nbPts[1];
162 int nbleft = quad->nbPts[3];
164 int nbhoriz = Min(nbdown, nbup);
165 int nbvertic = Min(nbright, nbleft);
167 const TopoDS_Face& F = TopoDS::Face(aShape);
168 Handle(Geom_Surface) S = BRep_Tool::Surface(F);
170 // internal mesh nodes
171 int i, j, geomFaceID = meshDS->ShapeToIndex( F );
172 for (i = 1; i < nbhoriz - 1; i++) {
173 for (j = 1; j < nbvertic - 1; j++) {
174 int ij = j * nbhoriz + i;
175 double u = quad->uv_grid[ij].u;
176 double v = quad->uv_grid[ij].v;
177 gp_Pnt P = S->Value(u, v);
178 SMDS_MeshNode * node = meshDS->AddNode(P.X(), P.Y(), P.Z());
179 meshDS->SetNodeOnFace(node, geomFaceID, u, v);
180 quad->uv_grid[ij].node = node;
187 // --.--.--.--.--.-- nbvertic
193 // ---.----.----.--- 0
194 // 0 > > > > > > > > nbhoriz
200 int iup = nbhoriz - 1;
201 if (quad->isEdgeOut[3]) { ilow++; } else { if (quad->isEdgeOut[1]) iup--; }
204 int jup = nbvertic - 1;
205 if (quad->isEdgeOut[0]) { jlow++; } else { if (quad->isEdgeOut[2]) jup--; }
207 // regular quadrangles
208 for (i = ilow; i < iup; i++) {
209 for (j = jlow; j < jup; j++) {
210 const SMDS_MeshNode *a, *b, *c, *d;
211 a = quad->uv_grid[j * nbhoriz + i].node;
212 b = quad->uv_grid[j * nbhoriz + i + 1].node;
213 c = quad->uv_grid[(j + 1) * nbhoriz + i + 1].node;
214 d = quad->uv_grid[(j + 1) * nbhoriz + i].node;
215 SMDS_MeshFace * face = meshDS->AddFace(a, b, c, d);
216 meshDS->SetMeshElementOnShape(face, geomFaceID);
220 UVPtStruct *uv_e0 = quad->uv_edges[0];
221 UVPtStruct *uv_e1 = quad->uv_edges[1];
222 UVPtStruct *uv_e2 = quad->uv_edges[2];
223 UVPtStruct *uv_e3 = quad->uv_edges[3];
225 double eps = Precision::Confusion();
227 // Boundary quadrangles
229 if (quad->isEdgeOut[0]) {
232 // |___|___|___|___|___|___|
234 // |___|___|___|___|___|___|
236 // |___|___|___|___|___|___| __ first row of the regular grid
237 // . . . . . . . . . __ down edge nodes
239 // >->->->->->->->->->->->-> -- direction of processing
241 int g = 0; // number of last processed node in the regular grid
243 // number of last node of the down edge to be processed
244 int stop = nbdown - 1;
245 // if right edge is out, we will stop at a node, previous to the last one
246 if (quad->isEdgeOut[1]) stop--;
248 // for each node of the down edge find nearest node
249 // in the first row of the regular grid and link them
250 for (i = 0; i < stop; i++) {
251 const SMDS_MeshNode *a, *b, *c, *d;
253 b = uv_e0[i + 1].node;
254 gp_Pnt pb (b->X(), b->Y(), b->Z());
256 // find node c in the regular grid, which will be linked with node b
259 // right bound reached, link with the rightmost node
261 c = quad->uv_grid[nbhoriz + iup].node;
263 // find in the grid node c, nearest to the b
264 double mind = RealLast();
265 for (int k = g; k <= iup; k++) {
267 const SMDS_MeshNode *nk;
268 if (k < ilow) // this can be, if left edge is out
269 nk = uv_e3[1].node; // get node from the left edge
271 nk = quad->uv_grid[nbhoriz + k].node; // get one of middle nodes
273 gp_Pnt pnk (nk->X(), nk->Y(), nk->Z());
274 double dist = pb.Distance(pnk);
275 if (dist < mind - eps) {
285 if (near == g) { // make triangle
286 SMDS_MeshFace* face = meshDS->AddFace(a, b, c);
287 meshDS->SetMeshElementOnShape(face, geomFaceID);
288 } else { // make quadrangle
292 d = quad->uv_grid[nbhoriz + near - 1].node;
293 SMDS_MeshFace* face = meshDS->AddFace(a, b, c, d);
294 meshDS->SetMeshElementOnShape(face, geomFaceID);
296 // if node d is not at position g - make additional triangles
298 for (int k = near - 1; k > g; k--) {
299 c = quad->uv_grid[nbhoriz + k].node;
303 d = quad->uv_grid[nbhoriz + k - 1].node;
304 SMDS_MeshFace* face = meshDS->AddFace(a, c, d);
305 meshDS->SetMeshElementOnShape(face, geomFaceID);
312 if (quad->isEdgeOut[2]) {
315 // <-<-<-<-<-<-<-<-<-<-<-<-< -- direction of processing
317 // . . . . . . . . . __ up edge nodes
318 // ___ ___ ___ ___ ___ ___ __ first row of the regular grid
320 // |___|___|___|___|___|___|
322 // |___|___|___|___|___|___|
325 int g = nbhoriz - 1; // last processed node in the regular grid
328 // if left edge is out, we will stop at a second node
329 if (quad->isEdgeOut[3]) stop++;
331 // for each node of the up edge find nearest node
332 // in the first row of the regular grid and link them
333 for (i = nbup - 1; i > stop; i--) {
334 const SMDS_MeshNode *a, *b, *c, *d;
336 b = uv_e2[i - 1].node;
337 gp_Pnt pb (b->X(), b->Y(), b->Z());
339 // find node c in the grid, which will be linked with node b
341 if (i == stop + 1) { // left bound reached, link with the leftmost node
342 c = quad->uv_grid[nbhoriz*(nbvertic - 2) + ilow].node;
345 // find node c in the grid, nearest to the b
346 double mind = RealLast();
347 for (int k = g; k >= ilow; k--) {
348 const SMDS_MeshNode *nk;
350 nk = uv_e1[nbright - 2].node;
352 nk = quad->uv_grid[nbhoriz*(nbvertic - 2) + k].node;
353 gp_Pnt pnk (nk->X(), nk->Y(), nk->Z());
354 double dist = pb.Distance(pnk);
355 if (dist < mind - eps) {
365 if (near == g) { // make triangle
366 SMDS_MeshFace* face = meshDS->AddFace(a, b, c);
367 meshDS->SetMeshElementOnShape(face, geomFaceID);
368 } else { // make quadrangle
370 d = uv_e1[nbright - 2].node;
372 d = quad->uv_grid[nbhoriz*(nbvertic - 2) + near + 1].node;
373 SMDS_MeshFace* face = meshDS->AddFace(a, b, c, d);
374 meshDS->SetMeshElementOnShape(face, geomFaceID);
376 if (near + 1 < g) { // if d not is at g - make additional triangles
377 for (int k = near + 1; k < g; k++) {
378 c = quad->uv_grid[nbhoriz*(nbvertic - 2) + k].node;
380 d = uv_e1[nbright - 2].node;
382 d = quad->uv_grid[nbhoriz*(nbvertic - 2) + k + 1].node;
383 SMDS_MeshFace* face = meshDS->AddFace(a, c, d);
384 meshDS->SetMeshElementOnShape(face, geomFaceID);
393 // right or left boundary quadrangles
394 if (quad->isEdgeOut[1]) {
395 // MESSAGE("right edge is out");
396 int g = 0; // last processed node in the grid
397 int stop = nbright - 1;
398 if (quad->isEdgeOut[2]) stop--;
399 for (i = 0; i < stop; i++) {
400 const SMDS_MeshNode *a, *b, *c, *d;
402 b = uv_e1[i + 1].node;
403 gp_Pnt pb (b->X(), b->Y(), b->Z());
405 // find node c in the grid, nearest to the b
407 if (i == stop - 1) { // up bondary reached
408 c = quad->uv_grid[nbhoriz*(jup + 1) - 2].node;
411 double mind = RealLast();
412 for (int k = g; k <= jup; k++) {
413 const SMDS_MeshNode *nk;
415 nk = uv_e0[nbdown - 2].node;
417 nk = quad->uv_grid[nbhoriz*(k + 1) - 2].node;
418 gp_Pnt pnk (nk->X(), nk->Y(), nk->Z());
419 double dist = pb.Distance(pnk);
420 if (dist < mind - eps) {
430 if (near == g) { // make triangle
431 SMDS_MeshFace* face = meshDS->AddFace(a, b, c);
432 meshDS->SetMeshElementOnShape(face, geomFaceID);
433 } else { // make quadrangle
435 d = uv_e0[nbdown - 2].node;
437 d = quad->uv_grid[nbhoriz*near - 2].node;
438 SMDS_MeshFace* face = meshDS->AddFace(a, b, c, d);
439 meshDS->SetMeshElementOnShape(face, geomFaceID);
441 if (near - 1 > g) { // if d not is at g - make additional triangles
442 for (int k = near - 1; k > g; k--) {
443 c = quad->uv_grid[nbhoriz*(k + 1) - 2].node;
445 d = uv_e0[nbdown - 2].node;
447 d = quad->uv_grid[nbhoriz*k - 2].node;
448 SMDS_MeshFace* face = meshDS->AddFace(a, c, d);
449 meshDS->SetMeshElementOnShape(face, geomFaceID);
456 if (quad->isEdgeOut[3]) {
457 // MESSAGE("left edge is out");
458 int g = nbvertic - 1; // last processed node in the grid
460 if (quad->isEdgeOut[0]) stop++;
461 for (i = nbleft - 1; i > stop; i--) {
462 const SMDS_MeshNode *a, *b, *c, *d;
464 b = uv_e3[i - 1].node;
465 gp_Pnt pb (b->X(), b->Y(), b->Z());
467 // find node c in the grid, nearest to the b
469 if (i == stop + 1) { // down bondary reached
470 c = quad->uv_grid[nbhoriz*jlow + 1].node;
473 double mind = RealLast();
474 for (int k = g; k >= jlow; k--) {
475 const SMDS_MeshNode *nk;
479 nk = quad->uv_grid[nbhoriz*k + 1].node;
480 gp_Pnt pnk (nk->X(), nk->Y(), nk->Z());
481 double dist = pb.Distance(pnk);
482 if (dist < mind - eps) {
492 if (near == g) { // make triangle
493 SMDS_MeshFace* face = meshDS->AddFace(a, b, c);
494 meshDS->SetMeshElementOnShape(face, geomFaceID);
495 } else { // make quadrangle
499 d = quad->uv_grid[nbhoriz*(near + 1) + 1].node;
500 SMDS_MeshFace* face = meshDS->AddFace(a, b, c, d);
501 meshDS->SetMeshElementOnShape(face, geomFaceID);
503 if (near + 1 < g) { // if d not is at g - make additional triangles
504 for (int k = near + 1; k < g; k++) {
505 c = quad->uv_grid[nbhoriz*k + 1].node;
509 d = quad->uv_grid[nbhoriz*(k + 1) + 1].node;
510 SMDS_MeshFace* face = meshDS->AddFace(a, c, d);
511 meshDS->SetMeshElementOnShape(face, geomFaceID);
526 //=============================================================================
530 //=============================================================================
532 FaceQuadStruct* StdMeshers_Quadrangle_2D::CheckNbEdges(SMESH_Mesh & aMesh,
533 const TopoDS_Shape & aShape)
534 throw(SALOME_Exception)
536 Unexpect aCatch(SalomeException);
538 const TopoDS_Face & F = TopoDS::Face(aShape);
540 // verify 1 wire only, with 4 edges
542 if (NumberOfWires(F) != 1) {
543 INFOS("only 1 wire by face (quadrangles)");
546 const TopoDS_Wire& W = BRepTools::OuterWire(F);
547 BRepTools_WireExplorer wexp (W, F);
549 FaceQuadStruct* quad = new FaceQuadStruct;
550 for (int i = 0; i < 4; i++)
551 quad->uv_edges[i] = 0;
555 for (wexp.Init(W, F); wexp.More(); wexp.Next()) {
556 const TopoDS_Edge& E = wexp.Current();
557 int nb = aMesh.GetSubMesh(E)->GetSubMeshDS()->NbNodes();
559 quad->edge[nbEdges] = E;
560 quad->nbPts[nbEdges] = nb + 2; // internal points + 2 extrema
566 INFOS("face must have 4 edges /quadrangles");
575 //=============================================================================
579 //=============================================================================
581 FaceQuadStruct *StdMeshers_Quadrangle_2D::CheckAnd2Dcompute
582 (SMESH_Mesh & aMesh, const TopoDS_Shape & aShape) throw(SALOME_Exception)
584 Unexpect aCatch(SalomeException);
586 FaceQuadStruct *quad = CheckNbEdges(aMesh, aShape);
590 // set normalized grid on unit square in parametric domain
591 SetNormalizedGrid(aMesh, aShape, quad);
596 //=============================================================================
600 //=============================================================================
602 void StdMeshers_Quadrangle_2D::QuadDelete (FaceQuadStruct * quad)
604 //MESSAGE("StdMeshers_Quadrangle_2D::QuadDelete");
607 for (int i = 0; i < 4; i++)
609 if (quad->uv_edges[i])
610 delete [] quad->uv_edges[i];
611 quad->edge[i].Nullify();
614 delete [] quad->uv_grid;
619 //=============================================================================
623 //=============================================================================
625 void StdMeshers_Quadrangle_2D::SetNormalizedGrid (SMESH_Mesh & aMesh,
626 const TopoDS_Shape& aShape,
627 FaceQuadStruct* quad) throw (SALOME_Exception)
629 Unexpect aCatch(SalomeException);
630 // Algorithme décrit dans "Génération automatique de maillages"
631 // P.L. GEORGE, MASSON, § 6.4.1 p. 84-85
632 // traitement dans le domaine paramétrique 2d u,v
633 // transport - projection sur le carré unité
635 // MESSAGE("StdMeshers_Quadrangle_2D::SetNormalizedGrid");
636 const TopoDS_Face& F = TopoDS::Face(aShape);
638 // 1 --- find orientation of the 4 edges, by test on extrema
641 // |<----north-2-------^ a3 -------------> a2
643 // west-3 east-1 =right | |
647 // v----south-0--------> a0 -------------> a1
652 Handle(Geom2d_Curve) c2d[4];
655 for (int i = 0; i < 4; i++)
657 c2d[i] = BRep_Tool::CurveOnSurface(quad->edge[i], F,
658 quad->first[i], quad->last[i]);
659 pf[i] = c2d[i]->Value(quad->first[i]);
660 pl[i] = c2d[i]->Value(quad->last[i]);
661 quad->isEdgeForward[i] = false;
664 double l0f1 = pl[0].SquareDistance(pf[1]);
665 double l0l1 = pl[0].SquareDistance(pl[1]);
666 double f0f1 = pf[0].SquareDistance(pf[1]);
667 double f0l1 = pf[0].SquareDistance(pl[1]);
668 if ( Min( l0f1, l0l1 ) < Min ( f0f1, f0l1 ))
670 quad->isEdgeForward[0] = true;
672 double tmp = quad->first[0];
673 quad->first[0] = quad->last[0];
675 pf[0] = c2d[0]->Value(quad->first[0]);
676 pl[0] = c2d[0]->Value(quad->last[0]);
678 for (int i = 1; i < 4; i++)
680 l0l1 = pl[i - 1].SquareDistance(pl[i]);
681 l0f1 = pl[i - 1].SquareDistance(pf[i]);
682 quad->isEdgeForward[i] = ( l0f1 < l0l1 );
683 if (!quad->isEdgeForward[i])
685 double tmp = quad->first[i];
686 quad->first[i] = quad->last[i];
688 pf[i] = c2d[i]->Value(quad->first[i]);
689 pl[i] = c2d[i]->Value(quad->last[i]);
693 // 2 --- load 2d edge points (u,v) with orientation and value on unit square
696 for (int i = 0; i < 2; i++)
698 quad->uv_edges[i] = LoadEdgePoints(aMesh, F, quad->edge[i],
699 quad->first[i], quad->last[i]);
700 if (!quad->uv_edges[i]) loadOk = false;
703 for (int i = 2; i < 4; i++)
705 quad->uv_edges[i] = LoadEdgePoints(aMesh, F, quad->edge[i],
706 quad->last[i], quad->first[i]);
707 if (!quad->uv_edges[i]) loadOk = false;
712 INFOS("StdMeshers_Quadrangle_2D::SetNormalizedGrid - LoadEdgePoints failed");
717 // 3 --- 2D normalized values on unit square [0..1][0..1]
719 int nbhoriz = Min(quad->nbPts[0], quad->nbPts[2]);
720 int nbvertic = Min(quad->nbPts[1], quad->nbPts[3]);
722 quad->isEdgeOut[0] = (quad->nbPts[0] > quad->nbPts[2]);
723 quad->isEdgeOut[1] = (quad->nbPts[1] > quad->nbPts[3]);
724 quad->isEdgeOut[2] = (quad->nbPts[2] > quad->nbPts[0]);
725 quad->isEdgeOut[3] = (quad->nbPts[3] > quad->nbPts[1]);
727 quad->uv_grid = new UVPtStruct[nbvertic * nbhoriz];
729 UVPtStruct *uv_grid = quad->uv_grid;
730 UVPtStruct *uv_e0 = quad->uv_edges[0];
731 UVPtStruct *uv_e1 = quad->uv_edges[1];
732 UVPtStruct *uv_e2 = quad->uv_edges[2];
733 UVPtStruct *uv_e3 = quad->uv_edges[3];
735 // nodes Id on "in" edges
736 if (! quad->isEdgeOut[0]) {
738 for (int i = 0; i < nbhoriz; i++) { // down
739 int ij = j * nbhoriz + i;
740 uv_grid[ij].node = uv_e0[i].node;
743 if (! quad->isEdgeOut[1]) {
745 for (int j = 0; j < nbvertic; j++) { // right
746 int ij = j * nbhoriz + i;
747 uv_grid[ij].node = uv_e1[j].node;
750 if (! quad->isEdgeOut[2]) {
751 int j = nbvertic - 1;
752 for (int i = 0; i < nbhoriz; i++) { // up
753 int ij = j * nbhoriz + i;
754 uv_grid[ij].node = uv_e2[i].node;
757 if (! quad->isEdgeOut[3]) {
759 for (int j = 0; j < nbvertic; j++) { // left
760 int ij = j * nbhoriz + i;
761 uv_grid[ij].node = uv_e3[j].node;
765 // falsificate "out" edges
766 if (quad->isEdgeOut[0]) // down
767 uv_e0 = MakeEdgePoints
768 (aMesh, F, quad->edge[0], quad->first[0], quad->last[0], nbhoriz - 1);
769 else if (quad->isEdgeOut[2]) // up
770 uv_e2 = MakeEdgePoints
771 (aMesh, F, quad->edge[2], quad->last[2], quad->first[2], nbhoriz - 1);
773 if (quad->isEdgeOut[1]) // right
774 uv_e1 = MakeEdgePoints
775 (aMesh, F, quad->edge[1], quad->first[1], quad->last[1], nbvertic - 1);
776 else if (quad->isEdgeOut[3]) // left
777 uv_e3 = MakeEdgePoints
778 (aMesh, F, quad->edge[3], quad->last[3], quad->first[3], nbvertic - 1);
780 // normalized 2d values on grid
781 for (int i = 0; i < nbhoriz; i++)
783 for (int j = 0; j < nbvertic; j++)
785 int ij = j * nbhoriz + i;
786 // --- droite i cste : x = x0 + y(x1-x0)
787 double x0 = uv_e0[i].normParam; // bas - sud
788 double x1 = uv_e2[i].normParam; // haut - nord
789 // --- droite j cste : y = y0 + x(y1-y0)
790 double y0 = uv_e3[j].normParam; // gauche-ouest
791 double y1 = uv_e1[j].normParam; // droite - est
792 // --- intersection : x=x0+(y0+x(y1-y0))(x1-x0)
793 double x = (x0 + y0 * (x1 - x0)) / (1 - (y1 - y0) * (x1 - x0));
794 double y = y0 + x * (y1 - y0);
797 //MESSAGE("-xy-01 "<<x0<<" "<<x1<<" "<<y0<<" "<<y1);
798 //MESSAGE("-xy-norm "<<i<<" "<<j<<" "<<x<<" "<<y);
802 // 4 --- projection on 2d domain (u,v)
808 for (int i = 0; i < nbhoriz; i++)
810 for (int j = 0; j < nbvertic; j++)
812 int ij = j * nbhoriz + i;
813 double x = uv_grid[ij].x;
814 double y = uv_grid[ij].y;
815 double param_0 = uv_e0[0].param + x * (uv_e0[nbhoriz - 1].param - uv_e0[0].param); // sud
816 double param_2 = uv_e2[0].param + x * (uv_e2[nbhoriz - 1].param - uv_e2[0].param); // nord
817 double param_1 = uv_e1[0].param + y * (uv_e1[nbvertic - 1].param - uv_e1[0].param); // est
818 double param_3 = uv_e3[0].param + y * (uv_e3[nbvertic - 1].param - uv_e3[0].param); // ouest
820 //MESSAGE("params "<<param_0<<" "<<param_1<<" "<<param_2<<" "<<param_3);
821 gp_Pnt2d p0 = c2d[0]->Value(param_0);
822 gp_Pnt2d p1 = c2d[1]->Value(param_1);
823 gp_Pnt2d p2 = c2d[2]->Value(param_2);
824 gp_Pnt2d p3 = c2d[3]->Value(param_3);
826 double u = (1 - y) * p0.X() + x * p1.X() + y * p2.X() + (1 - x) * p3.X();
827 double v = (1 - y) * p0.Y() + x * p1.Y() + y * p2.Y() + (1 - x) * p3.Y();
829 u -= (1 - x) * (1 - y) * a0.X() + x * (1 - y) * a1.X() +
830 x * y * a2.X() + (1 - x) * y * a3.X();
831 v -= (1 - x) * (1 - y) * a0.Y() + x * (1 - y) * a1.Y() +
832 x * y * a2.Y() + (1 - x) * y * a3.Y();
841 //=======================================================================
842 //function : ShiftQuad
843 //purpose : auxilary function for ComputeQuadPref
844 //=======================================================================
845 static void ShiftQuad(FaceQuadStruct* quad, const int num, bool WisF)
849 for(i=1; i<=num; i++) {
850 int nbPts3 = quad->nbPts[0];
851 quad->nbPts[0] = quad->nbPts[1];
852 quad->nbPts[1] = quad->nbPts[2];
853 quad->nbPts[2] = quad->nbPts[3];
854 quad->nbPts[3] = nbPts3;
855 TopoDS_Edge edge3 = quad->edge[0];
856 quad->edge[0] = quad->edge[1];
857 quad->edge[1] = quad->edge[2];
858 quad->edge[2] = quad->edge[3];
859 quad->edge[3] = edge3;
860 double first3 = quad->first[0];
861 quad->first[0] = quad->first[1];
862 quad->first[1] = quad->first[2];
863 quad->first[2] = quad->first[3];
864 quad->first[3] = first3;
865 double last3 = quad->last[0];
866 quad->last[0] = quad->last[1];
867 quad->last[1] = quad->last[2];
868 quad->last[2] = quad->last[3];
869 quad->last[3] = last3;
870 bool isEdgeForward3 = quad->isEdgeForward[0];
871 quad->isEdgeForward[0] = quad->isEdgeForward[1];
872 quad->isEdgeForward[1] = quad->isEdgeForward[2];
873 quad->isEdgeForward[2] = quad->isEdgeForward[3];
874 quad->isEdgeForward[3] = isEdgeForward3;
875 bool isEdgeOut3 = quad->isEdgeOut[0];
876 quad->isEdgeOut[0] = quad->isEdgeOut[1];
877 quad->isEdgeOut[1] = quad->isEdgeOut[2];
878 quad->isEdgeOut[2] = quad->isEdgeOut[3];
879 quad->isEdgeOut[3] = isEdgeOut3;
880 UVPtStruct* uv_edges3 = quad->uv_edges[0];
881 quad->uv_edges[0] = quad->uv_edges[1];
882 quad->uv_edges[1] = quad->uv_edges[2];
883 quad->uv_edges[2] = quad->uv_edges[3];
884 quad->uv_edges[3] = uv_edges3;
887 // replacement left and right edges
888 int nbPts3 = quad->nbPts[1];
889 quad->nbPts[1] = quad->nbPts[3];
890 quad->nbPts[3] = nbPts3;
891 TopoDS_Edge edge3 = quad->edge[1];
892 quad->edge[1] = quad->edge[3];
893 quad->edge[3] = edge3;
894 double first3 = quad->first[1];
895 quad->first[1] = quad->first[3];
896 quad->first[3] = first3;
897 double last3 = quad->last[1];
898 quad->last[1] = quad->last[2];
899 quad->last[3] = last3;
900 bool isEdgeForward3 = quad->isEdgeForward[1];
901 quad->isEdgeForward[1] = quad->isEdgeForward[3];
902 quad->isEdgeForward[3] = isEdgeForward3;
903 bool isEdgeOut3 = quad->isEdgeOut[1];
904 quad->isEdgeOut[1] = quad->isEdgeOut[3];
905 quad->isEdgeOut[3] = isEdgeOut3;
906 UVPtStruct* uv_edges3 = quad->uv_edges[1];
907 quad->uv_edges[1] = quad->uv_edges[3];
908 quad->uv_edges[3] = uv_edges3;
913 //=======================================================================
915 //purpose : auxilary function for ComputeQuadPref
916 //=======================================================================
917 static gp_XY CalcUV(double x0, double x1, double y0, double y1,
918 FaceQuadStruct* quad,
919 const gp_Pnt2d& a0, const gp_Pnt2d& a1,
920 const gp_Pnt2d& a2, const gp_Pnt2d& a3,
921 const Handle(Geom2d_Curve)& c2db,
922 const Handle(Geom2d_Curve)& c2dr,
923 const Handle(Geom2d_Curve)& c2dt,
924 const Handle(Geom2d_Curve)& c2dl)
926 int nb = quad->nbPts[0];
927 int nr = quad->nbPts[1];
928 int nt = quad->nbPts[2];
929 int nl = quad->nbPts[3];
931 UVPtStruct* uv_eb = quad->uv_edges[0];
932 UVPtStruct* uv_er = quad->uv_edges[1];
933 UVPtStruct* uv_et = quad->uv_edges[2];
934 UVPtStruct* uv_el = quad->uv_edges[3];
936 double x = (x0 + y0 * (x1 - x0)) / (1 - (y1 - y0) * (x1 - x0));
937 double y = y0 + x * (y1 - y0);
939 double param_b = uv_eb[0].param + x * (uv_eb[nb-1].param - uv_eb[0].param);
940 double param_t = uv_et[0].param + x * (uv_et[nt-1].param - uv_et[0].param);
941 double param_r = uv_er[0].param + y * (uv_er[nr-1].param - uv_er[0].param);
942 double param_l = uv_el[0].param + y * (uv_el[nl-1].param - uv_el[0].param);
944 gp_Pnt2d p0 = c2db->Value(param_b);
945 gp_Pnt2d p1 = c2dr->Value(param_r);
946 gp_Pnt2d p2 = c2dt->Value(param_t);
947 gp_Pnt2d p3 = c2dl->Value(param_l);
949 double u = (1 - y) * p0.X() + x * p1.X() + y * p2.X() + (1 - x) * p3.X();
950 double v = (1 - y) * p0.Y() + x * p1.Y() + y * p2.Y() + (1 - x) * p3.Y();
952 u -= (1 - x) * (1 - y) * a0.X() + x * (1 - y) * a1.X() +
953 x * y * a2.X() + (1 - x) * y * a3.X();
954 v -= (1 - x) * (1 - y) * a0.Y() + x * (1 - y) * a1.Y() +
955 x * y * a2.Y() + (1 - x) * y * a3.Y();
957 //cout<<"x0="<<x0<<" x1="<<x1<<" y0="<<y0<<" y1="<<y1<<endl;
958 //cout<<"x="<<x<<" y="<<y<<endl;
959 //cout<<"param_b="<<param_b<<" param_t="<<param_t<<" param_r="<<param_r<<" param_l="<<param_l<<endl;
960 //cout<<"u="<<u<<" v="<<v<<endl;
966 //=======================================================================
967 //function : ComputeQuadPref
969 //=======================================================================
971 * Special function for creation only quandrangle faces
973 bool StdMeshers_Quadrangle_2D::ComputeQuadPref
975 const TopoDS_Shape& aShape,
976 FaceQuadStruct* quad) throw (SALOME_Exception)
978 Unexpect aCatch(SalomeException);
980 SMESHDS_Mesh * meshDS = aMesh.GetMeshDS();
981 const TopoDS_Face& F = TopoDS::Face(aShape);
982 Handle(Geom_Surface) S = BRep_Tool::Surface(F);
983 const TopoDS_Wire& W = BRepTools::OuterWire(F);
985 if(W.Orientation()==TopAbs_FORWARD)
987 //if(WisF) cout<<"W is FORWARD"<<endl;
988 //else cout<<"W is REVERSED"<<endl;
989 bool FisF = (F.Orientation()==TopAbs_FORWARD);
990 if(!FisF) WisF = !WisF;
991 int i,j,geomFaceID = meshDS->ShapeToIndex( F );
993 int nb = quad->nbPts[0];
994 int nr = quad->nbPts[1];
995 int nt = quad->nbPts[2];
996 int nl = quad->nbPts[3];
1002 // it is a base case => not shift quad but me be replacement is need
1003 ShiftQuad(quad,0,WisF);
1006 // we have to shift quad on 2
1007 ShiftQuad(quad,2,WisF);
1012 // we have to shift quad on 3
1013 ShiftQuad(quad,3,WisF);
1016 // we have to shift quad on 1
1017 ShiftQuad(quad,1,WisF);
1021 nb = quad->nbPts[0];
1022 nr = quad->nbPts[1];
1023 nt = quad->nbPts[2];
1024 nl = quad->nbPts[3];
1027 int nbh = Max(nb,nt);
1028 int nbv = Max(nr,nl);
1032 // orientation of face and 3 main domain for future faces
1038 // left | | | | rigth
1054 Handle(Geom2d_Curve) c2d[4];
1055 for(i=0; i<4; i++) {
1056 c2d[i] = BRep_Tool::CurveOnSurface(quad->edge[i], F,
1057 quad->first[i], quad->last[i]);
1061 for(i=0; i<2; i++) {
1062 quad->uv_edges[i] = LoadEdgePoints2(aMesh, F, quad->edge[i], false);
1063 if(!quad->uv_edges[i]) loadOk = false;
1065 for(i=2; i<4; i++) {
1066 quad->uv_edges[i] = LoadEdgePoints2(aMesh, F, quad->edge[i], true);
1067 if (!quad->uv_edges[i]) loadOk = false;
1070 INFOS("StdMeshers_Quadrangle_2D::ComputeQuadPref - LoadEdgePoints failed");
1076 UVPtStruct* uv_eb = quad->uv_edges[0];
1077 UVPtStruct* uv_er = quad->uv_edges[1];
1078 UVPtStruct* uv_et = quad->uv_edges[2];
1079 UVPtStruct* uv_el = quad->uv_edges[3];
1081 // arrays for normalized params
1082 //cout<<"Dump B:"<<endl;
1083 TColStd_SequenceOfReal npb, npr, npt, npl;
1084 for(i=0; i<nb; i++) {
1085 npb.Append(uv_eb[i].normParam);
1086 //cout<<"i="<<i<<" par="<<uv_eb[i].param<<" npar="<<uv_eb[i].normParam;
1087 //const SMDS_MeshNode* N = uv_eb[i].node;
1088 //cout<<" node("<<N->X()<<","<<N->Y()<<","<<N->Z()<<")"<<endl;
1090 for(i=0; i<nr; i++) {
1091 npr.Append(uv_er[i].normParam);
1093 for(i=0; i<nt; i++) {
1094 npt.Append(uv_et[i].normParam);
1096 for(i=0; i<nl; i++) {
1097 npl.Append(uv_el[i].normParam);
1100 // we have to add few values of params to right and left
1101 // insert them after first param
1104 double dpr = (npr.Value(2) - npr.Value(1))/(dr+1);
1105 for(i=1; i<=dr; i++) {
1106 npr.InsertAfter(1,npr.Value(2)-dpr);
1110 dpr = (npl.Value(2) - npl.Value(1))/(dl+1);
1111 for(i=1; i<=dl; i++) {
1112 npl.InsertAfter(1,npl.Value(2)-dpr);
1115 //for(i=1; i<=npb.Length(); i++) {
1116 // cout<<" "<<npb.Value(i);
1121 c2d[0]->D0(uv_eb[0].param,a[0]);
1122 c2d[0]->D0(uv_eb[nb-1].param,a[1]);
1123 c2d[2]->D0(uv_et[nt-1].param,a[2]);
1124 c2d[2]->D0(uv_et[0].param,a[3]);
1125 //cout<<" a[0]("<<a[0].X()<<","<<a[0].Y()<<")"<<" a[1]("<<a[1].X()<<","<<a[1].Y()<<")"
1126 // <<" a[2]("<<a[2].X()<<","<<a[2].Y()<<")"<<" a[3]("<<a[3].X()<<","<<a[3].Y()<<")"<<endl;
1128 int nnn = Min(nr,nl);
1129 // auxilary sequence of XY for creation nodes
1130 // in the bottom part of central domain
1131 // it's length must be == nbv-nnn-1
1132 TColgp_SequenceOfXY UVL;
1133 TColgp_SequenceOfXY UVR;
1135 // step1: create faces for left domain
1136 StdMeshers_Array2OfNode NodesL(1,dl+1,1,nl);
1138 for(j=1; j<=nl; j++)
1139 NodesL.SetValue(1,j,uv_el[j-1].node);
1142 for(i=1; i<=dl; i++)
1143 NodesL.SetValue(i+1,nl,uv_et[i].node);
1144 // create and add needed nodes
1145 TColgp_SequenceOfXY UVtmp;
1146 for(i=1; i<=dl; i++) {
1147 double x0 = npt.Value(i+1);
1150 double y0 = npl.Value(i+1);
1151 double y1 = npr.Value(i+1);
1152 gp_XY UV = CalcUV(x0, x1, y0, y1, quad, a[0], a[1], a[2], a[3],
1153 c2d[0], c2d[1], c2d[2], c2d[3]);
1154 gp_Pnt P = S->Value(UV.X(),UV.Y());
1155 SMDS_MeshNode * N = meshDS->AddNode(P.X(), P.Y(), P.Z());
1156 meshDS->SetNodeOnFace(N, geomFaceID, UV.X(), UV.Y());
1157 NodesL.SetValue(i+1,1,N);
1158 if(UVL.Length()<nbv-nnn-1) UVL.Append(UV);
1160 for(j=2; j<nl; j++) {
1161 double y0 = npl.Value(dl+j);
1162 double y1 = npr.Value(dl+j);
1163 gp_XY UV = CalcUV(x0, x1, y0, y1, quad, a[0], a[1], a[2], a[3],
1164 c2d[0], c2d[1], c2d[2], c2d[3]);
1165 gp_Pnt P = S->Value(UV.X(),UV.Y());
1166 SMDS_MeshNode* N = meshDS->AddNode(P.X(), P.Y(), P.Z());
1167 meshDS->SetNodeOnFace(N, geomFaceID, UV.X(), UV.Y());
1168 NodesL.SetValue(i+1,j,N);
1169 if( i==dl ) UVtmp.Append(UV);
1172 for(i=1; i<=UVtmp.Length() && UVL.Length()<nbv-nnn-1; i++) {
1173 UVL.Append(UVtmp.Value(i));
1175 //cout<<"Dump NodesL:"<<endl;
1176 //for(i=1; i<=dl+1; i++) {
1178 // for(j=1; j<=nl; j++) {
1179 // cout<<" ("<<NodesL.Value(i,j)->X()<<","<<NodesL.Value(i,j)->Y()<<","<<NodesL.Value(i,j)->Z()<<")";
1184 for(i=1; i<=dl; i++) {
1185 for(j=1; j<nl; j++) {
1188 meshDS->AddFace(NodesL.Value(i,j), NodesL.Value(i+1,j),
1189 NodesL.Value(i+1,j+1), NodesL.Value(i,j+1));
1190 meshDS->SetMeshElementOnShape(F, geomFaceID);
1194 meshDS->AddFace(NodesL.Value(i,j), NodesL.Value(i,j+1),
1195 NodesL.Value(i+1,j+1), NodesL.Value(i+1,j));
1196 meshDS->SetMeshElementOnShape(F, geomFaceID);
1202 // fill UVL using c2d
1203 for(i=1; i<npl.Length() && UVL.Length()<nbv-nnn-1; i++) {
1205 c2d[3]->D0(uv_el[i].param,p2d);
1206 UVL.Append(p2d.XY());
1210 // step2: create faces for right domain
1211 StdMeshers_Array2OfNode NodesR(1,dr+1,1,nr);
1213 for(j=1; j<=nr; j++)
1214 NodesR.SetValue(1,j,uv_er[nr-j].node);
1217 for(i=1; i<=dr; i++)
1218 NodesR.SetValue(i+1,1,uv_et[nt-1-i].node);
1219 // create and add needed nodes
1220 TColgp_SequenceOfXY UVtmp;
1221 for(i=1; i<=dr; i++) {
1222 double x0 = npt.Value(nt-i);
1225 double y0 = npl.Value(i+1);
1226 double y1 = npr.Value(i+1);
1227 gp_XY UV = CalcUV(x0, x1, y0, y1, quad, a[0], a[1], a[2], a[3],
1228 c2d[0], c2d[1], c2d[2], c2d[3]);
1229 gp_Pnt P = S->Value(UV.X(),UV.Y());
1230 SMDS_MeshNode * N = meshDS->AddNode(P.X(), P.Y(), P.Z());
1231 meshDS->SetNodeOnFace(N, geomFaceID, UV.X(), UV.Y());
1232 NodesR.SetValue(i+1,nr,N);
1233 if(UVR.Length()<nbv-nnn-1) UVR.Append(UV);
1235 for(j=2; j<nr; j++) {
1236 double y0 = npl.Value(nbv-j+1);
1237 double y1 = npr.Value(nbv-j+1);
1238 gp_XY UV = CalcUV(x0, x1, y0, y1, quad, a[0], a[1], a[2], a[3],
1239 c2d[0], c2d[1], c2d[2], c2d[3]);
1240 gp_Pnt P = S->Value(UV.X(),UV.Y());
1241 SMDS_MeshNode* N = meshDS->AddNode(P.X(), P.Y(), P.Z());
1242 meshDS->SetNodeOnFace(N, geomFaceID, UV.X(), UV.Y());
1243 NodesR.SetValue(i+1,j,N);
1244 if( i==dr ) UVtmp.Prepend(UV);
1247 for(i=1; i<=UVtmp.Length() && UVR.Length()<nbv-nnn-1; i++) {
1248 UVR.Append(UVtmp.Value(i));
1251 for(i=1; i<=dr; i++) {
1252 for(j=1; j<nr; j++) {
1255 meshDS->AddFace(NodesR.Value(i,j), NodesR.Value(i+1,j),
1256 NodesR.Value(i+1,j+1), NodesR.Value(i,j+1));
1257 meshDS->SetMeshElementOnShape(F, geomFaceID);
1261 meshDS->AddFace(NodesR.Value(i,j), NodesR.Value(i,j+1),
1262 NodesR.Value(i+1,j+1), NodesR.Value(i+1,j));
1263 meshDS->SetMeshElementOnShape(F, geomFaceID);
1269 // fill UVR using c2d
1270 for(i=1; i<npr.Length() && UVR.Length()<nbv-nnn-1; i++) {
1272 c2d[1]->D0(uv_er[i].param,p2d);
1273 UVR.Append(p2d.XY());
1277 // step3: create faces for central domain
1278 StdMeshers_Array2OfNode NodesC(1,nb,1,nbv);
1279 // add first string using NodesL
1280 for(i=1; i<=dl+1; i++)
1281 NodesC.SetValue(1,i,NodesL(i,1));
1282 for(i=2; i<=nl; i++)
1283 NodesC.SetValue(1,dl+i,NodesL(dl+1,i));
1284 // add last string using NodesR
1285 for(i=1; i<=dr+1; i++)
1286 NodesC.SetValue(nb,i,NodesR(i,nr));
1288 NodesC.SetValue(nb,dr+i+1,NodesR(dr+1,nr-i));
1289 // add top nodes (last columns)
1290 for(i=dl+2; i<nbh-dr; i++)
1291 NodesC.SetValue(i-dl,nbv,uv_et[i-1].node);
1292 // add bottom nodes (first columns)
1293 for(i=2; i<nb; i++) {
1294 NodesC.SetValue(i,1,uv_eb[i-1].node);
1296 c2d[0]->D0(uv_eb[i-1].param,p2d);
1298 // create and add needed nodes
1299 // add linear layers
1300 for(i=2; i<nb; i++) {
1301 double x0 = npt.Value(dl+i);
1303 for(j=1; j<nnn; j++) {
1304 double y0 = npl.Value(nbv-nnn+j);
1305 double y1 = npr.Value(nbv-nnn+j);
1306 gp_XY UV = CalcUV(x0, x1, y0, y1, quad, a[0], a[1], a[2], a[3],
1307 c2d[0], c2d[1], c2d[2], c2d[3]);
1308 gp_Pnt P = S->Value(UV.X(),UV.Y());
1309 SMDS_MeshNode* N = meshDS->AddNode(P.X(), P.Y(), P.Z());
1310 meshDS->SetNodeOnFace(N, geomFaceID, UV.X(), UV.Y());
1311 NodesC.SetValue(i,nbv-nnn+j,N);
1314 // add diagonal layers
1315 //cout<<"UVL.Length()="<<UVL.Length()<<" UVR.Length()="<<UVR.Length()<<endl;
1316 //cout<<"Dump UVL:"<<endl;
1317 //for(i=1; i<=UVL.Length(); i++) {
1318 // cout<<" ("<<UVL.Value(i).X()<<","<<UVL.Value(i).Y()<<")";
1321 for(i=1; i<nbv-nnn; i++) {
1322 double du = UVR.Value(i).X() - UVL.Value(i).X();
1323 double dv = UVR.Value(i).Y() - UVL.Value(i).Y();
1324 for(j=2; j<nb; j++) {
1325 double u = UVL.Value(i).X() + du*npb.Value(j);
1326 double v = UVL.Value(i).Y() + dv*npb.Value(j);
1327 gp_Pnt P = S->Value(u,v);
1328 SMDS_MeshNode* N = meshDS->AddNode(P.X(), P.Y(), P.Z());
1329 meshDS->SetNodeOnFace(N, geomFaceID, u, v);
1330 NodesC.SetValue(j,i+1,N);
1334 for(i=1; i<nb; i++) {
1335 for(j=1; j<nbv; j++) {
1338 meshDS->AddFace(NodesC.Value(i,j), NodesC.Value(i+1,j),
1339 NodesC.Value(i+1,j+1), NodesC.Value(i,j+1));
1340 meshDS->SetMeshElementOnShape(F, geomFaceID);
1344 meshDS->AddFace(NodesC.Value(i,j), NodesC.Value(i,j+1),
1345 NodesC.Value(i+1,j+1), NodesC.Value(i+1,j));
1346 meshDS->SetMeshElementOnShape(F, geomFaceID);
1357 //=============================================================================
1361 //=============================================================================
1362 UVPtStruct* StdMeshers_Quadrangle_2D::LoadEdgePoints2 (SMESH_Mesh & aMesh,
1363 const TopoDS_Face& F,
1364 const TopoDS_Edge& E,
1367 //MESSAGE("StdMeshers_Quadrangle_2D::LoadEdgePoints");
1368 // --- IDNodes of first and last Vertex
1369 TopoDS_Vertex VFirst, VLast;
1370 TopExp::Vertices(E, VFirst, VLast); // corresponds to f and l
1372 ASSERT(!VFirst.IsNull());
1373 SMDS_NodeIteratorPtr lid = aMesh.GetSubMesh(VFirst)->GetSubMeshDS()->GetNodes();
1375 MESSAGE ( "NO NODE BUILT ON VERTEX" );
1378 const SMDS_MeshNode* idFirst = lid->next();
1380 ASSERT(!VLast.IsNull());
1381 lid = aMesh.GetSubMesh(VLast)->GetSubMeshDS()->GetNodes();
1383 MESSAGE ( "NO NODE BUILT ON VERTEX" );
1386 const SMDS_MeshNode* idLast = lid->next();
1388 // --- edge internal IDNodes (relies on good order storage, not checked)
1390 map<double, const SMDS_MeshNode *> params;
1391 SMDS_NodeIteratorPtr ite = aMesh.GetSubMesh(E)->GetSubMeshDS()->GetNodes();
1393 while(ite->more()) {
1394 const SMDS_MeshNode* node = ite->next();
1395 const SMDS_EdgePosition* epos =
1396 static_cast<const SMDS_EdgePosition*>(node->GetPosition().get());
1397 double param = epos->GetUParameter();
1398 params[param] = node;
1401 int nbPoints = aMesh.GetSubMesh(E)->GetSubMeshDS()->NbNodes();
1402 if (nbPoints != params.size()) {
1403 MESSAGE( "BAD NODE ON EDGE POSITIONS" );
1406 UVPtStruct* uvslf = new UVPtStruct[nbPoints + 2];
1409 Handle(Geom2d_Curve) C2d = BRep_Tool::CurveOnSurface(E, F, f, l);
1411 const TopoDS_Wire& W = BRepTools::OuterWire(F);
1412 bool FisF = (F.Orientation()==TopAbs_FORWARD);
1413 bool WisF = (W.Orientation()==TopAbs_FORWARD);
1414 bool isForward = (E.Orientation()==TopAbs_FORWARD);
1415 //if(isForward) cout<<"E is FORWARD"<<endl;
1416 //else cout<<"E is REVERSED"<<endl;
1417 if(!WisF) isForward = !isForward;
1418 if(!FisF) isForward = !isForward;
1419 //bool isForward = !(E.Orientation()==TopAbs_FORWARD);
1420 if(IsReverse) isForward = !isForward;
1426 gp_Pnt2d p = C2d->Value(f); // first point = Vertex Forward
1430 uvslf[0].node = idFirst;
1431 //MESSAGE("__ f "<<f<<" "<<uvslf[0].x <<" "<<uvslf[0].y);
1432 map < double, const SMDS_MeshNode* >::iterator itp = params.begin();
1433 for (int i = 1; i <= nbPoints; i++) { // nbPoints internal
1434 double param = (*itp).first;
1435 gp_Pnt2d p = C2d->Value(param);
1438 uvslf[i].param = param;
1439 uvslf[i].node = (*itp).second;
1440 //MESSAGE("__ "<<i<<" "<<param<<" "<<uvslf[i].x <<" "<<uvslf[i].y);
1443 p = C2d->Value(l); // last point = Vertex Reversed
1444 uvslf[nbPoints + 1].x = p.X();
1445 uvslf[nbPoints + 1].y = p.Y();
1446 uvslf[nbPoints + 1].param = l;
1447 uvslf[nbPoints + 1].node = idLast;
1448 //MESSAGE("__ l "<<l<<" "<<uvslf[nbPoints+1].x <<" "<<uvslf[nbPoints+1].y);
1453 gp_Pnt2d p = C2d->Value(l); // first point = Vertex Reversed
1457 uvslf[0].node = idLast;
1458 //MESSAGE("__ l "<<l<<" "<<uvslf[0].x <<" "<<uvslf[0].y);
1459 map < double, const SMDS_MeshNode* >::reverse_iterator itp = params.rbegin();
1460 for (int j = nbPoints; j >= 1; j--) { // nbPoints internal
1461 double param = (*itp).first;
1462 int i = nbPoints + 1 - j;
1463 gp_Pnt2d p = C2d->Value(param);
1466 uvslf[i].param = param;
1467 uvslf[i].node = (*itp).second;
1468 //MESSAGE("__ "<<i<<" "<<param<<" "<<uvslf[i].x <<" "<<uvslf[i].y);
1471 p = C2d->Value(f); // last point = Vertex Forward
1472 uvslf[nbPoints + 1].x = p.X();
1473 uvslf[nbPoints + 1].y = p.Y();
1474 uvslf[nbPoints + 1].param = f;
1475 uvslf[nbPoints + 1].node = idFirst;
1476 //MESSAGE("__ f "<<f<<" "<<uvslf[nbPoints+1].x <<" "<<uvslf[nbPoints+1].y);
1479 ASSERT(paramin != paramax);
1480 for (int i = 0; i < nbPoints + 2; i++) {
1481 uvslf[i].normParam = (uvslf[i].param - paramin) / (paramax - paramin);
1488 //=============================================================================
1492 //=============================================================================
1493 UVPtStruct* StdMeshers_Quadrangle_2D::LoadEdgePoints (SMESH_Mesh & aMesh,
1494 const TopoDS_Face& F,
1495 const TopoDS_Edge& E,
1496 double first, double last)
1499 //MESSAGE("StdMeshers_Quadrangle_2D::LoadEdgePoints");
1501 // --- IDNodes of first and last Vertex
1503 TopoDS_Vertex VFirst, VLast;
1504 TopExp::Vertices(E, VFirst, VLast); // corresponds to f and l
1506 ASSERT(!VFirst.IsNull());
1507 SMDS_NodeIteratorPtr lid = aMesh.GetSubMesh(VFirst)->GetSubMeshDS()->GetNodes();
1510 MESSAGE ( "NO NODE BUILT ON VERTEX" );
1513 const SMDS_MeshNode* idFirst = lid->next();
1515 ASSERT(!VLast.IsNull());
1516 lid = aMesh.GetSubMesh(VLast)->GetSubMeshDS()->GetNodes();
1519 MESSAGE ( "NO NODE BUILT ON VERTEX" );
1522 const SMDS_MeshNode* idLast = lid->next();
1524 // --- edge internal IDNodes (relies on good order storage, not checked)
1526 map<double, const SMDS_MeshNode *> params;
1527 SMDS_NodeIteratorPtr ite = aMesh.GetSubMesh(E)->GetSubMeshDS()->GetNodes();
1531 const SMDS_MeshNode* node = ite->next();
1532 const SMDS_EdgePosition* epos =
1533 static_cast<const SMDS_EdgePosition*>(node->GetPosition().get());
1534 double param = epos->GetUParameter();
1535 params[param] = node;
1538 int nbPoints = aMesh.GetSubMesh(E)->GetSubMeshDS()->NbNodes();
1539 if (nbPoints != params.size())
1541 MESSAGE( "BAD NODE ON EDGE POSITIONS" );
1544 UVPtStruct* uvslf = new UVPtStruct[nbPoints + 2];
1547 Handle(Geom2d_Curve) C2d = BRep_Tool::CurveOnSurface(E, F, f, l);
1549 bool isForward = (((l - f) * (last - first)) > 0);
1556 gp_Pnt2d p = C2d->Value(f); // first point = Vertex Forward
1560 uvslf[0].node = idFirst;
1561 //MESSAGE("__ f "<<f<<" "<<uvslf[0].x <<" "<<uvslf[0].y);
1562 map < double, const SMDS_MeshNode* >::iterator itp = params.begin();
1563 for (int i = 1; i <= nbPoints; i++) // nbPoints internal
1565 double param = (*itp).first;
1566 gp_Pnt2d p = C2d->Value(param);
1569 uvslf[i].param = param;
1570 uvslf[i].node = (*itp).second;
1571 //MESSAGE("__ "<<i<<" "<<param<<" "<<uvslf[i].x <<" "<<uvslf[i].y);
1574 p = C2d->Value(l); // last point = Vertex Reversed
1575 uvslf[nbPoints + 1].x = p.X();
1576 uvslf[nbPoints + 1].y = p.Y();
1577 uvslf[nbPoints + 1].param = l;
1578 uvslf[nbPoints + 1].node = idLast;
1579 //MESSAGE("__ l "<<l<<" "<<uvslf[nbPoints+1].x <<" "<<uvslf[nbPoints+1].y);
1584 gp_Pnt2d p = C2d->Value(l); // first point = Vertex Reversed
1588 uvslf[0].node = idLast;
1589 //MESSAGE("__ l "<<l<<" "<<uvslf[0].x <<" "<<uvslf[0].y);
1590 map < double, const SMDS_MeshNode* >::reverse_iterator itp = params.rbegin();
1592 for (int j = nbPoints; j >= 1; j--) // nbPoints internal
1594 double param = (*itp).first;
1595 int i = nbPoints + 1 - j;
1596 gp_Pnt2d p = C2d->Value(param);
1599 uvslf[i].param = param;
1600 uvslf[i].node = (*itp).second;
1601 //MESSAGE("__ "<<i<<" "<<param<<" "<<uvslf[i].x <<" "<<uvslf[i].y);
1604 p = C2d->Value(f); // last point = Vertex Forward
1605 uvslf[nbPoints + 1].x = p.X();
1606 uvslf[nbPoints + 1].y = p.Y();
1607 uvslf[nbPoints + 1].param = f;
1608 uvslf[nbPoints + 1].node = idFirst;
1609 //MESSAGE("__ f "<<f<<" "<<uvslf[nbPoints+1].x <<" "<<uvslf[nbPoints+1].y);
1612 ASSERT(paramin != paramax);
1613 for (int i = 0; i < nbPoints + 2; i++)
1615 uvslf[i].normParam = (uvslf[i].param - paramin) / (paramax - paramin);
1621 //=============================================================================
1625 //=============================================================================
1626 UVPtStruct* StdMeshers_Quadrangle_2D::MakeEdgePoints (SMESH_Mesh & aMesh,
1627 const TopoDS_Face& F,
1628 const TopoDS_Edge& E,
1629 double first, double last,
1632 // MESSAGE("StdMeshers_Quadrangle_2D::MakeEdgePoints");
1634 UVPtStruct* uvslf = new UVPtStruct[nb_segm + 1];
1635 list<double> params;
1637 // --- edge internal points
1639 Handle(Geom_Curve) Curve = BRep_Tool::Curve(E, fi, li);
1640 if (!Curve.IsNull()) {
1642 GeomAdaptor_Curve C3d (Curve);
1643 double length = EdgeLength(E);
1644 double eltSize = length / nb_segm;
1645 GCPnts_UniformAbscissa Discret (C3d, eltSize, fi, li);
1646 if (!Discret.IsDone()) return false;
1647 int NbPoints = Discret.NbPoints();
1648 for (int i = 1; i <= NbPoints; i++) {
1649 double param = Discret.Parameter(i);
1650 params.push_back(param);
1653 catch (Standard_Failure) {
1659 // Edge is a degenerated Edge
1660 BRep_Tool::Range(E, fi, li);
1661 double du = (li - fi) / nb_segm;
1662 for (int i = 1; i <= nb_segm + 1; i++)
1664 double param = fi + (i - 1) * du;
1665 params.push_back(param);
1670 Handle(Geom2d_Curve) C2d = BRep_Tool::CurveOnSurface(E, F, f, l);
1673 bool isForward = (((l - f) * (last - first)) > 0);
1675 list<double>::iterator itU = params.begin();
1676 for (int i = 0; i <= nb_segm; i++) // nbPoints internal
1678 double param = *itU;
1679 gp_Pnt2d p = C2d->Value(param);
1682 uvslf[i].param = param;
1683 uvslf[i].normParam = (param - f) / (l - f);
1687 list<double>::reverse_iterator itU = params.rbegin();
1688 for (int j = nb_segm; j >= 0; j--) // nbPoints internal
1690 double param = *itU;
1691 int i = nb_segm - j;
1692 gp_Pnt2d p = C2d->Value(param);
1695 uvslf[i].param = param;
1696 uvslf[i].normParam = (param - l) / (f - l);
1705 //=============================================================================
1709 //=============================================================================
1711 ostream & StdMeshers_Quadrangle_2D::SaveTo(ostream & save)
1716 //=============================================================================
1720 //=============================================================================
1722 istream & StdMeshers_Quadrangle_2D::LoadFrom(istream & load)
1727 //=============================================================================
1731 //=============================================================================
1733 ostream & operator <<(ostream & save, StdMeshers_Quadrangle_2D & hyp)
1735 return hyp.SaveTo( save );
1738 //=============================================================================
1742 //=============================================================================
1744 istream & operator >>(istream & load, StdMeshers_Quadrangle_2D & hyp)
1746 return hyp.LoadFrom( load );