1 // Copyright (C) 2007-2014 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 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, or (at your option) any later version.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 // File : StdMeshers_Quadrangle_2D.cxx
24 // Author : Paul RASCLE, EDF
27 #include "StdMeshers_Quadrangle_2D.hxx"
29 #include "SMDS_EdgePosition.hxx"
30 #include "SMDS_FacePosition.hxx"
31 #include "SMDS_MeshElement.hxx"
32 #include "SMDS_MeshNode.hxx"
33 #include "SMESH_Block.hxx"
34 #include "SMESH_Comment.hxx"
35 #include "SMESH_Gen.hxx"
36 #include "SMESH_HypoFilter.hxx"
37 #include "SMESH_Mesh.hxx"
38 #include "SMESH_MeshAlgos.hxx"
39 #include "SMESH_MesherHelper.hxx"
40 #include "SMESH_subMesh.hxx"
41 #include "StdMeshers_FaceSide.hxx"
42 #include "StdMeshers_QuadrangleParams.hxx"
43 #include "StdMeshers_ViscousLayers2D.hxx"
45 #include <BRepBndLib.hxx>
46 #include <BRepClass_FaceClassifier.hxx>
47 #include <BRep_Tool.hxx>
48 #include <Bnd_Box.hxx>
49 #include <GeomAPI_ProjectPointOnSurf.hxx>
50 #include <Geom_Surface.hxx>
51 #include <NCollection_DefineArray2.hxx>
52 #include <Precision.hxx>
53 #include <Quantity_Parameter.hxx>
54 #include <TColStd_SequenceOfInteger.hxx>
55 #include <TColStd_SequenceOfReal.hxx>
56 #include <TColgp_SequenceOfXY.hxx>
58 #include <TopExp_Explorer.hxx>
59 #include <TopTools_DataMapOfShapeReal.hxx>
60 #include <TopTools_ListIteratorOfListOfShape.hxx>
61 #include <TopTools_MapOfShape.hxx>
64 #include "utilities.h"
65 #include "Utils_ExceptHandlers.hxx"
67 #ifndef StdMeshers_Array2OfNode_HeaderFile
68 #define StdMeshers_Array2OfNode_HeaderFile
69 typedef const SMDS_MeshNode* SMDS_MeshNodePtr;
70 DEFINE_BASECOLLECTION (StdMeshers_BaseCollectionNodePtr, SMDS_MeshNodePtr)
71 DEFINE_ARRAY2(StdMeshers_Array2OfNode,
72 StdMeshers_BaseCollectionNodePtr, SMDS_MeshNodePtr)
78 typedef SMESH_Comment TComm;
80 //=============================================================================
84 //=============================================================================
86 StdMeshers_Quadrangle_2D::StdMeshers_Quadrangle_2D (int hypId, int studyId,
88 : SMESH_2D_Algo(hypId, studyId, gen),
89 myQuadranglePreference(false),
90 myTrianglePreference(false),
94 myQuadType(QUAD_STANDARD),
97 MESSAGE("StdMeshers_Quadrangle_2D::StdMeshers_Quadrangle_2D");
98 _name = "Quadrangle_2D";
99 _shapeType = (1 << TopAbs_FACE);
100 _compatibleHypothesis.push_back("QuadrangleParams");
101 _compatibleHypothesis.push_back("QuadranglePreference");
102 _compatibleHypothesis.push_back("TrianglePreference");
103 _compatibleHypothesis.push_back("ViscousLayers2D");
106 //=============================================================================
110 //=============================================================================
112 StdMeshers_Quadrangle_2D::~StdMeshers_Quadrangle_2D()
114 MESSAGE("StdMeshers_Quadrangle_2D::~StdMeshers_Quadrangle_2D");
117 //=============================================================================
121 //=============================================================================
123 bool StdMeshers_Quadrangle_2D::CheckHypothesis
125 const TopoDS_Shape& aShape,
126 SMESH_Hypothesis::Hypothesis_Status& aStatus)
129 myQuadType = QUAD_STANDARD;
130 myQuadranglePreference = false;
131 myTrianglePreference = false;
132 myHelper = (SMESH_MesherHelper*)NULL;
137 aStatus = SMESH_Hypothesis::HYP_OK;
139 const list <const SMESHDS_Hypothesis * >& hyps =
140 GetUsedHypothesis(aMesh, aShape, false);
141 const SMESHDS_Hypothesis * aHyp = 0;
143 bool isFirstParams = true;
145 // First assigned hypothesis (if any) is processed now
146 if (hyps.size() > 0) {
148 if (strcmp("QuadrangleParams", aHyp->GetName()) == 0)
150 myParams = (const StdMeshers_QuadrangleParams*)aHyp;
151 myTriaVertexID = myParams->GetTriaVertex();
152 myQuadType = myParams->GetQuadType();
153 if (myQuadType == QUAD_QUADRANGLE_PREF ||
154 myQuadType == QUAD_QUADRANGLE_PREF_REVERSED)
155 myQuadranglePreference = true;
156 else if (myQuadType == QUAD_TRIANGLE_PREF)
157 myTrianglePreference = true;
159 else if (strcmp("QuadranglePreference", aHyp->GetName()) == 0) {
160 isFirstParams = false;
161 myQuadranglePreference = true;
163 else if (strcmp("TrianglePreference", aHyp->GetName()) == 0){
164 isFirstParams = false;
165 myTrianglePreference = true;
168 isFirstParams = false;
172 // Second(last) assigned hypothesis (if any) is processed now
173 if (hyps.size() > 1) {
176 if (strcmp("QuadranglePreference", aHyp->GetName()) == 0) {
177 myQuadranglePreference = true;
178 myTrianglePreference = false;
179 myQuadType = QUAD_STANDARD;
181 else if (strcmp("TrianglePreference", aHyp->GetName()) == 0){
182 myQuadranglePreference = false;
183 myTrianglePreference = true;
184 myQuadType = QUAD_STANDARD;
188 const StdMeshers_QuadrangleParams* aHyp2 =
189 (const StdMeshers_QuadrangleParams*)aHyp;
190 myTriaVertexID = aHyp2->GetTriaVertex();
192 if (!myQuadranglePreference && !myTrianglePreference) { // priority of hypos
193 myQuadType = aHyp2->GetQuadType();
194 if (myQuadType == QUAD_QUADRANGLE_PREF ||
195 myQuadType == QUAD_QUADRANGLE_PREF_REVERSED)
196 myQuadranglePreference = true;
197 else if (myQuadType == QUAD_TRIANGLE_PREF)
198 myTrianglePreference = true;
206 //=============================================================================
210 //=============================================================================
212 bool StdMeshers_Quadrangle_2D::Compute (SMESH_Mesh& aMesh,
213 const TopoDS_Shape& aShape)
215 const TopoDS_Face& F = TopoDS::Face(aShape);
216 aMesh.GetSubMesh( F );
218 // do not initialize my fields before this as StdMeshers_ViscousLayers2D
219 // can call Compute() recursively
220 SMESH_ProxyMesh::Ptr proxyMesh = StdMeshers_ViscousLayers2D::Compute( aMesh, F );
224 myProxyMesh = proxyMesh;
226 SMESH_MesherHelper helper (aMesh);
229 _quadraticMesh = myHelper->IsQuadraticSubMesh(aShape);
230 myNeedSmooth = false;
232 FaceQuadStruct::Ptr quad = CheckNbEdges( aMesh, F, /*considerMesh=*/true );
236 myQuadList.push_back( quad );
238 if ( !getEnforcedUV() )
241 updateDegenUV( quad );
243 int n1 = quad->side[0].NbPoints();
244 int n2 = quad->side[1].NbPoints();
245 int n3 = quad->side[2].NbPoints();
246 int n4 = quad->side[3].NbPoints();
248 enum { NOT_COMPUTED = -1, COMPUTE_FAILED = 0, COMPUTE_OK = 1 };
249 int res = NOT_COMPUTED;
250 if (myQuadranglePreference)
252 int nfull = n1+n2+n3+n4;
253 if ((nfull % 2) == 0 && ((n1 != n3) || (n2 != n4)))
255 // special path genarating only quandrangle faces
256 res = computeQuadPref( aMesh, F, quad );
259 else if (myQuadType == QUAD_REDUCED)
263 int n13tmp = n13/2; n13tmp = n13tmp*2;
264 int n24tmp = n24/2; n24tmp = n24tmp*2;
265 if ((n1 == n3 && n2 != n4 && n24tmp == n24) ||
266 (n2 == n4 && n1 != n3 && n13tmp == n13))
268 res = computeReduced( aMesh, F, quad );
272 if ( n1 != n3 && n2 != n4 )
273 error( COMPERR_WARNING,
274 "To use 'Reduced' transition, "
275 "two opposite sides should have same number of segments, "
276 "but actual number of segments is different on all sides. "
277 "'Standard' transion has been used.");
279 error( COMPERR_WARNING,
280 "To use 'Reduced' transition, "
281 "two opposite sides should have an even difference in number of segments. "
282 "'Standard' transion has been used.");
286 if ( res == NOT_COMPUTED )
288 if ( n1 != n3 || n2 != n4 )
289 res = computeTriangles( aMesh, F, quad );
291 res = computeQuadDominant( aMesh, F );
294 if ( res == COMPUTE_OK && myNeedSmooth )
297 return ( res == COMPUTE_OK );
300 //================================================================================
302 * \brief Compute quadrangles and triangles on the quad
304 //================================================================================
306 bool StdMeshers_Quadrangle_2D::computeTriangles(SMESH_Mesh& aMesh,
307 const TopoDS_Face& aFace,
308 FaceQuadStruct::Ptr quad)
310 int nb = quad->side[0].grid->NbPoints();
311 int nr = quad->side[1].grid->NbPoints();
312 int nt = quad->side[2].grid->NbPoints();
313 int nl = quad->side[3].grid->NbPoints();
315 // rotate the quad to have nbNodeOut sides on TOP [and LEFT]
317 quad->shift( nl > nr ? 3 : 2, true );
319 quad->shift( 1, true );
321 quad->shift( nt > nb ? 0 : 3, true );
323 if ( !setNormalizedGrid( quad ))
326 if ( quad->nbNodeOut( QUAD_TOP_SIDE ))
328 splitQuad( quad, 0, quad->jSize-2 );
330 if ( quad->nbNodeOut( QUAD_BOTTOM_SIDE )) // this should not happen
332 splitQuad( quad, 0, 1 );
334 FaceQuadStruct::Ptr newQuad = myQuadList.back();
335 if ( quad != newQuad ) // split done
338 FaceQuadStruct::Ptr botQuad = // a bottom part
339 ( quad->side[ QUAD_LEFT_SIDE ].from == 0 ) ? quad : newQuad;
340 if ( botQuad->nbNodeOut( QUAD_LEFT_SIDE ) > 0 )
341 botQuad->side[ QUAD_LEFT_SIDE ].to += botQuad->nbNodeOut( QUAD_LEFT_SIDE );
342 else if ( botQuad->nbNodeOut( QUAD_RIGHT_SIDE ) > 0 )
343 botQuad->side[ QUAD_RIGHT_SIDE ].to += botQuad->nbNodeOut( QUAD_RIGHT_SIDE );
345 // make quad be a greatest one
346 if ( quad->side[ QUAD_LEFT_SIDE ].NbPoints() == 2 ||
347 quad->side[ QUAD_RIGHT_SIDE ].NbPoints() == 2 )
349 if ( !setNormalizedGrid( quad ))
353 if ( quad->nbNodeOut( QUAD_RIGHT_SIDE ))
355 splitQuad( quad, quad->iSize-2, 0 );
357 if ( quad->nbNodeOut( QUAD_LEFT_SIDE ))
359 splitQuad( quad, 1, 0 );
362 return computeQuadDominant( aMesh, aFace );
365 //================================================================================
367 * \brief Compute quadrangles and possibly triangles on all quads of myQuadList
369 //================================================================================
371 bool StdMeshers_Quadrangle_2D::computeQuadDominant(SMESH_Mesh& aMesh,
372 const TopoDS_Face& aFace)
374 if ( !addEnforcedNodes() )
377 std::list< FaceQuadStruct::Ptr >::iterator quad = myQuadList.begin();
378 for ( ; quad != myQuadList.end(); ++quad )
379 if ( !computeQuadDominant( aMesh, aFace, *quad ))
385 //================================================================================
387 * \brief Compute quadrangles and possibly triangles
389 //================================================================================
391 bool StdMeshers_Quadrangle_2D::computeQuadDominant(SMESH_Mesh& aMesh,
392 const TopoDS_Face& aFace,
393 FaceQuadStruct::Ptr quad)
395 // --- set normalized grid on unit square in parametric domain
397 if ( !setNormalizedGrid( quad ))
400 // --- create nodes on points, and create quadrangles
402 int nbhoriz = quad->iSize;
403 int nbvertic = quad->jSize;
405 // internal mesh nodes
406 SMESHDS_Mesh * meshDS = aMesh.GetMeshDS();
407 Handle(Geom_Surface) S = BRep_Tool::Surface(aFace);
408 int i,j, geomFaceID = meshDS->ShapeToIndex(aFace);
409 for (i = 1; i < nbhoriz - 1; i++)
410 for (j = 1; j < nbvertic - 1; j++)
412 UVPtStruct& uvPnt = quad->UVPt( i, j );
413 gp_Pnt P = S->Value( uvPnt.u, uvPnt.v );
414 uvPnt.node = meshDS->AddNode(P.X(), P.Y(), P.Z());
415 meshDS->SetNodeOnFace( uvPnt.node, geomFaceID, uvPnt.u, uvPnt.v );
421 // --.--.--.--.--.-- nbvertic
427 // ---.----.----.--- 0
428 // 0 > > > > > > > > nbhoriz
433 int iup = nbhoriz - 1;
434 if (quad->nbNodeOut(3)) { ilow++; } else { if (quad->nbNodeOut(1)) iup--; }
437 int jup = nbvertic - 1;
438 if (quad->nbNodeOut(0)) { jlow++; } else { if (quad->nbNodeOut(2)) jup--; }
440 // regular quadrangles
441 for (i = ilow; i < iup; i++) {
442 for (j = jlow; j < jup; j++) {
443 const SMDS_MeshNode *a, *b, *c, *d;
444 a = quad->uv_grid[ j * nbhoriz + i ].node;
445 b = quad->uv_grid[ j * nbhoriz + i + 1].node;
446 c = quad->uv_grid[(j + 1) * nbhoriz + i + 1].node;
447 d = quad->uv_grid[(j + 1) * nbhoriz + i ].node;
448 SMDS_MeshFace* face = myHelper->AddFace(a, b, c, d);
450 meshDS->SetMeshElementOnShape(face, geomFaceID);
455 // Boundary elements (must always be on an outer boundary of the FACE)
457 const vector<UVPtStruct>& uv_e0 = quad->side[0].grid->GetUVPtStruct();
458 const vector<UVPtStruct>& uv_e1 = quad->side[1].grid->GetUVPtStruct();
459 const vector<UVPtStruct>& uv_e2 = quad->side[2].grid->GetUVPtStruct();
460 const vector<UVPtStruct>& uv_e3 = quad->side[3].grid->GetUVPtStruct();
462 if (uv_e0.empty() || uv_e1.empty() || uv_e2.empty() || uv_e3.empty())
463 return error(COMPERR_BAD_INPUT_MESH);
465 double eps = Precision::Confusion();
467 int nbdown = (int) uv_e0.size();
468 int nbup = (int) uv_e2.size();
469 int nbright = (int) uv_e1.size();
470 int nbleft = (int) uv_e3.size();
472 if (quad->nbNodeOut(0) && nbvertic == 2) // this should not occure
476 // |___|___|___|___|___|___|
478 // |___|___|___|___|___|___|
480 // |___|___|___|___|___|___| __ first row of the regular grid
481 // . . . . . . . . . __ down edge nodes
483 // >->->->->->->->->->->->-> -- direction of processing
485 int g = 0; // number of last processed node in the regular grid
487 // number of last node of the down edge to be processed
488 int stop = nbdown - 1;
489 // if right edge is out, we will stop at a node, previous to the last one
490 //if (quad->nbNodeOut(1)) stop--;
491 if ( quad->nbNodeOut( QUAD_RIGHT_SIDE ))
492 quad->UVPt( nbhoriz-1, 1 ).node = uv_e1[1].node;
493 if ( quad->nbNodeOut( QUAD_LEFT_SIDE ))
494 quad->UVPt( 0, 1 ).node = uv_e3[1].node;
496 // for each node of the down edge find nearest node
497 // in the first row of the regular grid and link them
498 for (i = 0; i < stop; i++) {
499 const SMDS_MeshNode *a, *b, *c, *d;
501 b = uv_e0[i + 1].node;
502 gp_Pnt pb (b->X(), b->Y(), b->Z());
504 // find node c in the regular grid, which will be linked with node b
507 // right bound reached, link with the rightmost node
509 c = quad->uv_grid[nbhoriz + iup].node;
512 // find in the grid node c, nearest to the b
513 double mind = RealLast();
514 for (int k = g; k <= iup; k++) {
516 const SMDS_MeshNode *nk;
517 if (k < ilow) // this can be, if left edge is out
518 nk = uv_e3[1].node; // get node from the left edge
520 nk = quad->uv_grid[nbhoriz + k].node; // get one of middle nodes
522 gp_Pnt pnk (nk->X(), nk->Y(), nk->Z());
523 double dist = pb.Distance(pnk);
524 if (dist < mind - eps) {
534 if (near == g) { // make triangle
535 SMDS_MeshFace* face = myHelper->AddFace(a, b, c);
536 if (face) meshDS->SetMeshElementOnShape(face, geomFaceID);
538 else { // make quadrangle
542 d = quad->uv_grid[nbhoriz + near - 1].node;
543 //SMDS_MeshFace* face = meshDS->AddFace(a, b, c, d);
545 if (!myTrianglePreference){
546 SMDS_MeshFace* face = myHelper->AddFace(a, b, c, d);
547 if (face) meshDS->SetMeshElementOnShape(face, geomFaceID);
550 splitQuadFace(meshDS, geomFaceID, a, b, c, d);
553 // if node d is not at position g - make additional triangles
555 for (int k = near - 1; k > g; k--) {
556 c = quad->uv_grid[nbhoriz + k].node;
560 d = quad->uv_grid[nbhoriz + k - 1].node;
561 SMDS_MeshFace* face = myHelper->AddFace(a, c, d);
562 if (face) meshDS->SetMeshElementOnShape(face, geomFaceID);
569 if (quad->nbNodeOut(2) && nbvertic == 2)
573 // <-<-<-<-<-<-<-<-<-<-<-<-< -- direction of processing
575 // . . . . . . . . . __ up edge nodes
576 // ___ ___ ___ ___ ___ ___ __ first row of the regular grid
578 // |___|___|___|___|___|___|
580 // |___|___|___|___|___|___|
583 int g = nbhoriz - 1; // last processed node in the regular grid
589 // if left edge is out, we will stop at a second node
590 //if (quad->nbNodeOut(3)) stop++;
591 if ( quad->nbNodeOut( QUAD_RIGHT_SIDE ))
592 quad->UVPt( nbhoriz-1, 0 ).node = uv_e1[ nbright-2 ].node;
593 if ( quad->nbNodeOut( QUAD_LEFT_SIDE ))
594 quad->UVPt( 0, 0 ).node = uv_e3[ nbleft-2 ].node;
596 // for each node of the up edge find nearest node
597 // in the first row of the regular grid and link them
598 for (i = nbup - 1; i > stop; i--) {
599 const SMDS_MeshNode *a, *b, *c, *d;
601 b = uv_e2[i - 1].node;
602 gp_Pnt pb (b->X(), b->Y(), b->Z());
604 // find node c in the grid, which will be linked with node b
606 if (i == stop + 1) { // left bound reached, link with the leftmost node
607 c = quad->uv_grid[nbhoriz*(nbvertic - 2) + ilow].node;
610 // find node c in the grid, nearest to the b
611 double mind = RealLast();
612 for (int k = g; k >= ilow; k--) {
613 const SMDS_MeshNode *nk;
615 nk = uv_e1[nbright - 2].node;
617 nk = quad->uv_grid[nbhoriz*(nbvertic - 2) + k].node;
618 gp_Pnt pnk (nk->X(), nk->Y(), nk->Z());
619 double dist = pb.Distance(pnk);
620 if (dist < mind - eps) {
630 if (near == g) { // make triangle
631 SMDS_MeshFace* face = myHelper->AddFace(a, b, c);
632 if (face) meshDS->SetMeshElementOnShape(face, geomFaceID);
634 else { // make quadrangle
636 d = uv_e1[nbright - 2].node;
638 d = quad->uv_grid[nbhoriz*(nbvertic - 2) + near + 1].node;
639 //SMDS_MeshFace* face = meshDS->AddFace(a, b, c, d);
640 if (!myTrianglePreference){
641 SMDS_MeshFace* face = myHelper->AddFace(a, b, c, d);
642 if (face) meshDS->SetMeshElementOnShape(face, geomFaceID);
645 splitQuadFace(meshDS, geomFaceID, a, b, c, d);
648 if (near + 1 < g) { // if d is not at g - make additional triangles
649 for (int k = near + 1; k < g; k++) {
650 c = quad->uv_grid[nbhoriz*(nbvertic - 2) + k].node;
652 d = uv_e1[nbright - 2].node;
654 d = quad->uv_grid[nbhoriz*(nbvertic - 2) + k + 1].node;
655 SMDS_MeshFace* face = myHelper->AddFace(a, c, d);
656 if (face) meshDS->SetMeshElementOnShape(face, geomFaceID);
665 // right or left boundary quadrangles
666 if (quad->nbNodeOut( QUAD_RIGHT_SIDE ) && nbhoriz == 2) // this should not occure
668 int g = 0; // last processed node in the grid
669 int stop = nbright - 1;
671 if (quad->side[ QUAD_RIGHT_SIDE ].from != i ) i++;
672 if (quad->side[ QUAD_RIGHT_SIDE ].to != stop ) stop--;
673 for ( ; i < stop; i++) {
674 const SMDS_MeshNode *a, *b, *c, *d;
676 b = uv_e1[i + 1].node;
677 gp_Pnt pb (b->X(), b->Y(), b->Z());
679 // find node c in the grid, nearest to the b
681 if (i == stop - 1) { // up bondary reached
682 c = quad->uv_grid[nbhoriz*(jup + 1) - 2].node;
685 double mind = RealLast();
686 for (int k = g; k <= jup; k++) {
687 const SMDS_MeshNode *nk;
689 nk = uv_e0[nbdown - 2].node;
691 nk = quad->uv_grid[nbhoriz*(k + 1) - 2].node;
692 gp_Pnt pnk (nk->X(), nk->Y(), nk->Z());
693 double dist = pb.Distance(pnk);
694 if (dist < mind - eps) {
704 if (near == g) { // make triangle
705 SMDS_MeshFace* face = myHelper->AddFace(a, b, c);
706 if (face) meshDS->SetMeshElementOnShape(face, geomFaceID);
708 else { // make quadrangle
710 d = uv_e0[nbdown - 2].node;
712 d = quad->uv_grid[nbhoriz*near - 2].node;
713 //SMDS_MeshFace* face = meshDS->AddFace(a, b, c, d);
715 if (!myTrianglePreference){
716 SMDS_MeshFace* face = myHelper->AddFace(a, b, c, d);
717 if (face) meshDS->SetMeshElementOnShape(face, geomFaceID);
720 splitQuadFace(meshDS, geomFaceID, a, b, c, d);
723 if (near - 1 > g) { // if d not is at g - make additional triangles
724 for (int k = near - 1; k > g; k--) {
725 c = quad->uv_grid[nbhoriz*(k + 1) - 2].node;
727 d = uv_e0[nbdown - 2].node;
729 d = quad->uv_grid[nbhoriz*k - 2].node;
730 SMDS_MeshFace* face = myHelper->AddFace(a, c, d);
731 if (face) meshDS->SetMeshElementOnShape(face, geomFaceID);
738 if (quad->nbNodeOut(3) && nbhoriz == 2) {
739 // MESSAGE("left edge is out");
740 int g = nbvertic - 1; // last processed node in the grid
742 i = quad->side[ QUAD_LEFT_SIDE ].to-1; // nbleft - 1;
743 for (; i > stop; i--) {
744 const SMDS_MeshNode *a, *b, *c, *d;
746 b = uv_e3[i - 1].node;
747 gp_Pnt pb (b->X(), b->Y(), b->Z());
749 // find node c in the grid, nearest to the b
751 if (i == stop + 1) { // down bondary reached
752 c = quad->uv_grid[nbhoriz*jlow + 1].node;
755 double mind = RealLast();
756 for (int k = g; k >= jlow; k--) {
757 const SMDS_MeshNode *nk;
761 nk = quad->uv_grid[nbhoriz*k + 1].node;
762 gp_Pnt pnk (nk->X(), nk->Y(), nk->Z());
763 double dist = pb.Distance(pnk);
764 if (dist < mind - eps) {
774 if (near == g) { // make triangle
775 SMDS_MeshFace* face = myHelper->AddFace(a, b, c);
776 if (face) meshDS->SetMeshElementOnShape(face, geomFaceID);
778 else { // make quadrangle
782 d = quad->uv_grid[nbhoriz*(near + 1) + 1].node;
783 //SMDS_MeshFace* face = meshDS->AddFace(a, b, c, d);
784 if (!myTrianglePreference){
785 SMDS_MeshFace* face = myHelper->AddFace(a, b, c, d);
786 if (face) meshDS->SetMeshElementOnShape(face, geomFaceID);
789 splitQuadFace(meshDS, geomFaceID, a, b, c, d);
792 if (near + 1 < g) { // if d not is at g - make additional triangles
793 for (int k = near + 1; k < g; k++) {
794 c = quad->uv_grid[nbhoriz*k + 1].node;
798 d = quad->uv_grid[nbhoriz*(k + 1) + 1].node;
799 SMDS_MeshFace* face = myHelper->AddFace(a, c, d);
800 if (face) meshDS->SetMeshElementOnShape(face, geomFaceID);
814 //=============================================================================
818 //=============================================================================
820 bool StdMeshers_Quadrangle_2D::Evaluate(SMESH_Mesh& aMesh,
821 const TopoDS_Shape& aFace,
822 MapShapeNbElems& aResMap)
825 aMesh.GetSubMesh(aFace);
827 std::vector<int> aNbNodes(4);
828 bool IsQuadratic = false;
829 if (!checkNbEdgesForEvaluate(aMesh, aFace, aResMap, aNbNodes, IsQuadratic)) {
830 std::vector<int> aResVec(SMDSEntity_Last);
831 for (int i=SMDSEntity_Node; i<SMDSEntity_Last; i++) aResVec[i] = 0;
832 SMESH_subMesh * sm = aMesh.GetSubMesh(aFace);
833 aResMap.insert(std::make_pair(sm,aResVec));
834 SMESH_ComputeErrorPtr& smError = sm->GetComputeError();
835 smError.reset(new SMESH_ComputeError(COMPERR_ALGO_FAILED,"Submesh can not be evaluated",this));
839 if (myQuadranglePreference) {
840 int n1 = aNbNodes[0];
841 int n2 = aNbNodes[1];
842 int n3 = aNbNodes[2];
843 int n4 = aNbNodes[3];
844 int nfull = n1+n2+n3+n4;
847 if (nfull==ntmp && ((n1!=n3) || (n2!=n4))) {
848 // special path for using only quandrangle faces
849 return evaluateQuadPref(aMesh, aFace, aNbNodes, aResMap, IsQuadratic);
854 int nbdown = aNbNodes[0];
855 int nbup = aNbNodes[2];
857 int nbright = aNbNodes[1];
858 int nbleft = aNbNodes[3];
860 int nbhoriz = Min(nbdown, nbup);
861 int nbvertic = Min(nbright, nbleft);
863 int dh = Max(nbdown, nbup) - nbhoriz;
864 int dv = Max(nbright, nbleft) - nbvertic;
871 int nbNodes = (nbhoriz-2)*(nbvertic-2);
872 //int nbFaces3 = dh + dv + kdh*(nbvertic-1)*2 + kdv*(nbhoriz-1)*2;
873 int nbFaces3 = dh + dv;
874 //if (kdh==1 && kdv==1) nbFaces3 -= 2;
875 //if (dh>0 && dv>0) nbFaces3 -= 2;
876 //int nbFaces4 = (nbhoriz-1-kdh)*(nbvertic-1-kdv);
877 int nbFaces4 = (nbhoriz-1)*(nbvertic-1);
879 std::vector<int> aVec(SMDSEntity_Last);
880 for (int i=SMDSEntity_Node; i<SMDSEntity_Last; i++) aVec[i] = 0;
882 aVec[SMDSEntity_Quad_Triangle] = nbFaces3;
883 aVec[SMDSEntity_Quad_Quadrangle] = nbFaces4;
884 int nbbndedges = nbdown + nbup + nbright + nbleft -4;
885 int nbintedges = (nbFaces4*4 + nbFaces3*3 - nbbndedges) / 2;
886 aVec[SMDSEntity_Node] = nbNodes + nbintedges;
887 if (aNbNodes.size()==5) {
888 aVec[SMDSEntity_Quad_Triangle] = nbFaces3 + aNbNodes[3] -1;
889 aVec[SMDSEntity_Quad_Quadrangle] = nbFaces4 - aNbNodes[3] +1;
893 aVec[SMDSEntity_Node] = nbNodes;
894 aVec[SMDSEntity_Triangle] = nbFaces3;
895 aVec[SMDSEntity_Quadrangle] = nbFaces4;
896 if (aNbNodes.size()==5) {
897 aVec[SMDSEntity_Triangle] = nbFaces3 + aNbNodes[3] - 1;
898 aVec[SMDSEntity_Quadrangle] = nbFaces4 - aNbNodes[3] + 1;
901 SMESH_subMesh * sm = aMesh.GetSubMesh(aFace);
902 aResMap.insert(std::make_pair(sm,aVec));
907 //================================================================================
909 * \brief Return true if applied compute mesh on this shape
911 //================================================================================
913 bool StdMeshers_Quadrangle_2D::IsApplicable( const TopoDS_Shape & aShape, bool toCheckAll )
915 int nbFoundFaces = 0;
916 for (TopExp_Explorer exp( aShape, TopAbs_FACE ); exp.More(); exp.Next(), ++nbFoundFaces ){
917 TopoDS_Face aFace = TopoDS::Face(exp.Current());
918 if ( aFace.Orientation() >= TopAbs_INTERNAL ) aFace.Orientation( TopAbs_FORWARD );
920 list< TopoDS_Edge > aWire;
921 list< int > nbEdgesInWire;
922 int nbWire = SMESH_Block::GetOrderedEdges (aFace, aWire, nbEdgesInWire);
924 int nbNoDegenEdges = 0;
925 list<TopoDS_Edge>::iterator edge = aWire.begin();
926 for ( ; edge != aWire.end(); ++edge ){
927 if ( !SMESH_Algo::isDegenerated( *edge ))
930 if( toCheckAll && (nbWire != 1 || nbNoDegenEdges <= 3 ) ) return false;
931 if( !toCheckAll && nbWire == 1 && nbNoDegenEdges > 3 ) return true;
933 if( toCheckAll && nbFoundFaces != 0) return true;
937 //================================================================================
939 * \brief Return true if only two given edges meat at their common vertex
941 //================================================================================
943 static bool twoEdgesMeatAtVertex(const TopoDS_Edge& e1,
944 const TopoDS_Edge& e2,
948 if (!TopExp::CommonVertex(e1, e2, v))
950 TopTools_ListIteratorOfListOfShape ancestIt(mesh.GetAncestors(v));
951 for (; ancestIt.More() ; ancestIt.Next())
952 if (ancestIt.Value().ShapeType() == TopAbs_EDGE)
953 if (!e1.IsSame(ancestIt.Value()) && !e2.IsSame(ancestIt.Value()))
958 //=============================================================================
962 //=============================================================================
964 FaceQuadStruct::Ptr StdMeshers_Quadrangle_2D::CheckNbEdges(SMESH_Mesh & aMesh,
965 const TopoDS_Shape & aShape,
966 const bool considerMesh)
968 if ( !myQuadList.empty() && myQuadList.front()->face.IsSame( aShape ))
969 return myQuadList.front();
971 TopoDS_Face F = TopoDS::Face(aShape);
972 if ( F.Orientation() >= TopAbs_INTERNAL ) F.Orientation( TopAbs_FORWARD );
973 const bool ignoreMediumNodes = _quadraticMesh;
975 // verify 1 wire only, with 4 edges
976 list< TopoDS_Edge > edges;
977 list< int > nbEdgesInWire;
978 int nbWire = SMESH_Block::GetOrderedEdges (F, edges, nbEdgesInWire);
980 error(COMPERR_BAD_SHAPE, TComm("Wrong number of wires: ") << nbWire);
981 return FaceQuadStruct::Ptr();
984 // find corner vertices of the quad
985 vector<TopoDS_Vertex> corners;
986 int nbDegenEdges, nbSides = getCorners( F, aMesh, edges, corners, nbDegenEdges, considerMesh );
989 return FaceQuadStruct::Ptr();
991 FaceQuadStruct::Ptr quad( new FaceQuadStruct );
992 quad->side.reserve(nbEdgesInWire.front());
995 list< TopoDS_Edge >::iterator edgeIt = edges.begin();
996 if ( nbSides == 3 ) // 3 sides and corners[0] is a vertex with myTriaVertexID
998 for ( int iSide = 0; iSide < 3; ++iSide )
1000 list< TopoDS_Edge > sideEdges;
1001 TopoDS_Vertex nextSideV = corners[( iSide + 1 ) % 3 ];
1002 while ( edgeIt != edges.end() &&
1003 !nextSideV.IsSame( SMESH_MesherHelper::IthVertex( 0, *edgeIt )))
1004 if ( SMESH_Algo::isDegenerated( *edgeIt ))
1007 sideEdges.push_back( *edgeIt++ );
1008 if ( !sideEdges.empty() )
1009 quad->side.push_back( StdMeshers_FaceSide::New(F, sideEdges, &aMesh, iSide < QUAD_TOP_SIDE,
1010 ignoreMediumNodes, myProxyMesh));
1014 const vector<UVPtStruct>& UVPSleft = quad->side[0].GetUVPtStruct(true,0);
1015 /* vector<UVPtStruct>& UVPStop = */quad->side[1].GetUVPtStruct(false,1);
1016 /* vector<UVPtStruct>& UVPSright = */quad->side[2].GetUVPtStruct(true,1);
1017 const SMDS_MeshNode* aNode = UVPSleft[0].node;
1018 gp_Pnt2d aPnt2d = UVPSleft[0].UV();
1019 quad->side.push_back( StdMeshers_FaceSide::New( quad->side[1].grid.get(), aNode, &aPnt2d ));
1020 myNeedSmooth = ( nbDegenEdges > 0 );
1025 myNeedSmooth = ( corners.size() == 4 && nbDegenEdges > 0 );
1026 int iSide = 0, nbUsedDegen = 0, nbLoops = 0;
1027 for ( ; edgeIt != edges.end(); ++nbLoops )
1029 list< TopoDS_Edge > sideEdges;
1030 TopoDS_Vertex nextSideV = corners[( iSide + 1 - nbUsedDegen ) % corners.size() ];
1031 while ( edgeIt != edges.end() &&
1032 !nextSideV.IsSame( myHelper->IthVertex( 0, *edgeIt )))
1034 if ( SMESH_Algo::isDegenerated( *edgeIt ) )
1038 ++edgeIt; // no side on the degenerated EDGE
1042 if ( sideEdges.empty() )
1045 sideEdges.push_back( *edgeIt++ ); // a degenerated side
1050 break; // do not append a degenerated EDGE to a regular side
1056 sideEdges.push_back( *edgeIt++ );
1059 if ( !sideEdges.empty() )
1061 quad->side.push_back( StdMeshers_FaceSide::New( F, sideEdges, &aMesh, iSide < QUAD_TOP_SIDE,
1062 ignoreMediumNodes, myProxyMesh ));
1065 else if ( !SMESH_Algo::isDegenerated( *edgeIt ) && // closed EDGE
1066 myHelper->IthVertex( 0, *edgeIt ).IsSame( myHelper->IthVertex( 1, *edgeIt )))
1068 quad->side.push_back( StdMeshers_FaceSide::New( F, *edgeIt++, &aMesh, iSide < QUAD_TOP_SIDE,
1069 ignoreMediumNodes, myProxyMesh));
1072 if ( quad->side.size() == 4 )
1076 error(TComm("Bug: infinite loop in StdMeshers_Quadrangle_2D::CheckNbEdges()"));
1081 if ( quad && quad->side.size() != 4 )
1083 error(TComm("Bug: ") << quad->side.size() << " sides found instead of 4");
1092 //=============================================================================
1096 //=============================================================================
1098 bool StdMeshers_Quadrangle_2D::checkNbEdgesForEvaluate(SMESH_Mesh& aMesh,
1099 const TopoDS_Shape & aShape,
1100 MapShapeNbElems& aResMap,
1101 std::vector<int>& aNbNodes,
1105 const TopoDS_Face & F = TopoDS::Face(aShape);
1107 // verify 1 wire only, with 4 edges
1108 list< TopoDS_Edge > edges;
1109 list< int > nbEdgesInWire;
1110 int nbWire = SMESH_Block::GetOrderedEdges (F, edges, nbEdgesInWire);
1118 list< TopoDS_Edge >::iterator edgeIt = edges.begin();
1119 SMESH_subMesh * sm = aMesh.GetSubMesh(*edgeIt);
1120 MapShapeNbElemsItr anIt = aResMap.find(sm);
1121 if (anIt==aResMap.end()) {
1124 std::vector<int> aVec = (*anIt).second;
1125 IsQuadratic = (aVec[SMDSEntity_Quad_Edge] > aVec[SMDSEntity_Edge]);
1126 if (nbEdgesInWire.front() == 3) { // exactly 3 edges
1127 if (myTriaVertexID>0) {
1128 SMESHDS_Mesh* meshDS = aMesh.GetMeshDS();
1129 TopoDS_Vertex V = TopoDS::Vertex(meshDS->IndexToShape(myTriaVertexID));
1131 TopoDS_Edge E1,E2,E3;
1132 for (; edgeIt != edges.end(); ++edgeIt) {
1133 TopoDS_Edge E = TopoDS::Edge(*edgeIt);
1134 TopoDS_Vertex VF, VL;
1135 TopExp::Vertices(E, VF, VL, true);
1138 else if (VL.IsSame(V))
1143 SMESH_subMesh * sm = aMesh.GetSubMesh(E1);
1144 MapShapeNbElemsItr anIt = aResMap.find(sm);
1145 if (anIt==aResMap.end()) return false;
1146 std::vector<int> aVec = (*anIt).second;
1148 aNbNodes[0] = (aVec[SMDSEntity_Node]-1)/2 + 2;
1150 aNbNodes[0] = aVec[SMDSEntity_Node] + 2;
1151 sm = aMesh.GetSubMesh(E2);
1152 anIt = aResMap.find(sm);
1153 if (anIt==aResMap.end()) return false;
1154 aVec = (*anIt).second;
1156 aNbNodes[1] = (aVec[SMDSEntity_Node]-1)/2 + 2;
1158 aNbNodes[1] = aVec[SMDSEntity_Node] + 2;
1159 sm = aMesh.GetSubMesh(E3);
1160 anIt = aResMap.find(sm);
1161 if (anIt==aResMap.end()) return false;
1162 aVec = (*anIt).second;
1164 aNbNodes[2] = (aVec[SMDSEntity_Node]-1)/2 + 2;
1166 aNbNodes[2] = aVec[SMDSEntity_Node] + 2;
1167 aNbNodes[3] = aNbNodes[1];
1173 if (nbEdgesInWire.front() == 4) { // exactly 4 edges
1174 for (; edgeIt != edges.end(); edgeIt++) {
1175 SMESH_subMesh * sm = aMesh.GetSubMesh(*edgeIt);
1176 MapShapeNbElemsItr anIt = aResMap.find(sm);
1177 if (anIt==aResMap.end()) {
1180 std::vector<int> aVec = (*anIt).second;
1182 aNbNodes[nbSides] = (aVec[SMDSEntity_Node]-1)/2 + 2;
1184 aNbNodes[nbSides] = aVec[SMDSEntity_Node] + 2;
1188 else if (nbEdgesInWire.front() > 4) { // more than 4 edges - try to unite some
1189 list< TopoDS_Edge > sideEdges;
1190 while (!edges.empty()) {
1192 sideEdges.splice(sideEdges.end(), edges, edges.begin()); // edges.front() -> sideEdges.end()
1193 bool sameSide = true;
1194 while (!edges.empty() && sameSide) {
1195 sameSide = SMESH_Algo::IsContinuous(sideEdges.back(), edges.front());
1197 sideEdges.splice(sideEdges.end(), edges, edges.begin());
1199 if (nbSides == 0) { // go backward from the first edge
1201 while (!edges.empty() && sameSide) {
1202 sameSide = SMESH_Algo::IsContinuous(sideEdges.front(), edges.back());
1204 sideEdges.splice(sideEdges.begin(), edges, --edges.end());
1207 list<TopoDS_Edge>::iterator ite = sideEdges.begin();
1208 aNbNodes[nbSides] = 1;
1209 for (; ite!=sideEdges.end(); ite++) {
1210 SMESH_subMesh * sm = aMesh.GetSubMesh(*ite);
1211 MapShapeNbElemsItr anIt = aResMap.find(sm);
1212 if (anIt==aResMap.end()) {
1215 std::vector<int> aVec = (*anIt).second;
1217 aNbNodes[nbSides] += (aVec[SMDSEntity_Node]-1)/2 + 1;
1219 aNbNodes[nbSides] += aVec[SMDSEntity_Node] + 1;
1223 // issue 20222. Try to unite only edges shared by two same faces
1226 SMESH_Block::GetOrderedEdges (F, edges, nbEdgesInWire);
1227 while (!edges.empty()) {
1229 sideEdges.splice(sideEdges.end(), edges, edges.begin());
1230 bool sameSide = true;
1231 while (!edges.empty() && sameSide) {
1233 SMESH_Algo::IsContinuous(sideEdges.back(), edges.front()) &&
1234 twoEdgesMeatAtVertex(sideEdges.back(), edges.front(), aMesh);
1236 sideEdges.splice(sideEdges.end(), edges, edges.begin());
1238 if (nbSides == 0) { // go backward from the first edge
1240 while (!edges.empty() && sameSide) {
1242 SMESH_Algo::IsContinuous(sideEdges.front(), edges.back()) &&
1243 twoEdgesMeatAtVertex(sideEdges.front(), edges.back(), aMesh);
1245 sideEdges.splice(sideEdges.begin(), edges, --edges.end());
1248 list<TopoDS_Edge>::iterator ite = sideEdges.begin();
1249 aNbNodes[nbSides] = 1;
1250 for (; ite!=sideEdges.end(); ite++) {
1251 SMESH_subMesh * sm = aMesh.GetSubMesh(*ite);
1252 MapShapeNbElemsItr anIt = aResMap.find(sm);
1253 if (anIt==aResMap.end()) {
1256 std::vector<int> aVec = (*anIt).second;
1258 aNbNodes[nbSides] += (aVec[SMDSEntity_Node]-1)/2 + 1;
1260 aNbNodes[nbSides] += aVec[SMDSEntity_Node] + 1;
1268 nbSides = nbEdgesInWire.front();
1269 error(COMPERR_BAD_SHAPE, TComm("Face must have 4 sides but not ") << nbSides);
1277 //=============================================================================
1281 //=============================================================================
1284 StdMeshers_Quadrangle_2D::CheckAnd2Dcompute (SMESH_Mesh & aMesh,
1285 const TopoDS_Shape & aShape,
1286 const bool CreateQuadratic)
1288 _quadraticMesh = CreateQuadratic;
1290 FaceQuadStruct::Ptr quad = CheckNbEdges(aMesh, aShape);
1293 // set normalized grid on unit square in parametric domain
1294 if ( ! setNormalizedGrid( quad ))
1302 inline const vector<UVPtStruct>& getUVPtStructIn(FaceQuadStruct::Ptr& quad, int i, int nbSeg)
1304 bool isXConst = (i == QUAD_BOTTOM_SIDE || i == QUAD_TOP_SIDE);
1305 double constValue = (i == QUAD_BOTTOM_SIDE || i == QUAD_LEFT_SIDE) ? 0 : 1;
1307 quad->nbNodeOut(i) ?
1308 quad->side[i].grid->SimulateUVPtStruct(nbSeg,isXConst,constValue) :
1309 quad->side[i].grid->GetUVPtStruct (isXConst,constValue);
1311 inline gp_UV calcUV(double x, double y,
1312 const gp_UV& a0,const gp_UV& a1,const gp_UV& a2,const gp_UV& a3,
1313 const gp_UV& p0,const gp_UV& p1,const gp_UV& p2,const gp_UV& p3)
1316 ((1 - y) * p0 + x * p1 + y * p2 + (1 - x) * p3 ) -
1317 ((1 - x) * (1 - y) * a0 + x * (1 - y) * a1 + x * y * a2 + (1 - x) * y * a3);
1321 //=============================================================================
1325 //=============================================================================
1327 bool StdMeshers_Quadrangle_2D::setNormalizedGrid (FaceQuadStruct::Ptr quad)
1329 if ( !quad->uv_grid.empty() )
1332 // Algorithme décrit dans "Génération automatique de maillages"
1333 // P.L. GEORGE, MASSON, § 6.4.1 p. 84-85
1334 // traitement dans le domaine paramétrique 2d u,v
1335 // transport - projection sur le carré unité
1338 // |<----north-2-------^ a3 -------------> a2
1340 // west-3 east-1 =right | |
1344 // v----south-0--------> a0 -------------> a1
1348 const FaceQuadStruct::Side & bSide = quad->side[0];
1349 const FaceQuadStruct::Side & rSide = quad->side[1];
1350 const FaceQuadStruct::Side & tSide = quad->side[2];
1351 const FaceQuadStruct::Side & lSide = quad->side[3];
1353 int nbhoriz = Min( bSide.NbPoints(), tSide.NbPoints() );
1354 int nbvertic = Min( rSide.NbPoints(), lSide.NbPoints() );
1356 if ( myQuadList.size() == 1 )
1358 // all sub-quads must have NO sides with nbNodeOut > 0
1359 quad->nbNodeOut(0) = Max( 0, bSide.grid->NbPoints() - tSide.grid->NbPoints() );
1360 quad->nbNodeOut(1) = Max( 0, rSide.grid->NbPoints() - lSide.grid->NbPoints() );
1361 quad->nbNodeOut(2) = Max( 0, tSide.grid->NbPoints() - bSide.grid->NbPoints() );
1362 quad->nbNodeOut(3) = Max( 0, lSide.grid->NbPoints() - rSide.grid->NbPoints() );
1364 const vector<UVPtStruct>& uv_e0 = bSide.GetUVPtStruct();
1365 const vector<UVPtStruct>& uv_e1 = rSide.GetUVPtStruct();
1366 const vector<UVPtStruct>& uv_e2 = tSide.GetUVPtStruct();
1367 const vector<UVPtStruct>& uv_e3 = lSide.GetUVPtStruct();
1368 if (uv_e0.empty() || uv_e1.empty() || uv_e2.empty() || uv_e3.empty())
1369 //return error("Can't find nodes on sides");
1370 return error(COMPERR_BAD_INPUT_MESH);
1372 quad->uv_grid.resize( nbvertic * nbhoriz );
1373 quad->iSize = nbhoriz;
1374 quad->jSize = nbvertic;
1375 UVPtStruct *uv_grid = & quad->uv_grid[0];
1377 quad->uv_box.Clear();
1379 // copy data of face boundary
1381 FaceQuadStruct::SideIterator sideIter;
1385 const double x0 = bSide.First().normParam;
1386 const double dx = bSide.Last().normParam - bSide.First().normParam;
1387 for ( sideIter.Init( bSide ); sideIter.More(); sideIter.Next() ) {
1388 sideIter.UVPt().x = ( sideIter.UVPt().normParam - x0 ) / dx;
1389 sideIter.UVPt().y = 0.;
1390 uv_grid[ j * nbhoriz + sideIter.Count() ] = sideIter.UVPt();
1391 quad->uv_box.Add( sideIter.UVPt().UV() );
1395 const int i = nbhoriz - 1;
1396 const double y0 = rSide.First().normParam;
1397 const double dy = rSide.Last().normParam - rSide.First().normParam;
1398 sideIter.Init( rSide );
1399 if ( quad->UVPt( i, sideIter.Count() ).node )
1400 sideIter.Next(); // avoid copying from a split emulated side
1401 for ( ; sideIter.More(); sideIter.Next() ) {
1402 sideIter.UVPt().x = 1.;
1403 sideIter.UVPt().y = ( sideIter.UVPt().normParam - y0 ) / dy;
1404 uv_grid[ sideIter.Count() * nbhoriz + i ] = sideIter.UVPt();
1405 quad->uv_box.Add( sideIter.UVPt().UV() );
1409 const int j = nbvertic - 1;
1410 const double x0 = tSide.First().normParam;
1411 const double dx = tSide.Last().normParam - tSide.First().normParam;
1412 int i = 0, nb = nbhoriz;
1413 sideIter.Init( tSide );
1414 if ( quad->UVPt( nb-1, j ).node ) --nb; // avoid copying from a split emulated side
1415 for ( ; i < nb; i++, sideIter.Next()) {
1416 sideIter.UVPt().x = ( sideIter.UVPt().normParam - x0 ) / dx;
1417 sideIter.UVPt().y = 1.;
1418 uv_grid[ j * nbhoriz + i ] = sideIter.UVPt();
1419 quad->uv_box.Add( sideIter.UVPt().UV() );
1424 const double y0 = lSide.First().normParam;
1425 const double dy = lSide.Last().normParam - lSide.First().normParam;
1426 int j = 0, nb = nbvertic;
1427 sideIter.Init( lSide );
1428 if ( quad->UVPt( i, j ).node )
1429 ++j, sideIter.Next(); // avoid copying from a split emulated side
1430 if ( quad->UVPt( i, nb-1 ).node )
1432 for ( ; j < nb; j++, sideIter.Next()) {
1433 sideIter.UVPt().x = 0.;
1434 sideIter.UVPt().y = ( sideIter.UVPt().normParam - y0 ) / dy;
1435 uv_grid[ j * nbhoriz + i ] = sideIter.UVPt();
1436 quad->uv_box.Add( sideIter.UVPt().UV() );
1440 // normalized 2d parameters on grid
1442 for (int i = 1; i < nbhoriz-1; i++)
1444 const double x0 = quad->UVPt( i, 0 ).x;
1445 const double x1 = quad->UVPt( i, nbvertic-1 ).x;
1446 for (int j = 1; j < nbvertic-1; j++)
1448 const double y0 = quad->UVPt( 0, j ).y;
1449 const double y1 = quad->UVPt( nbhoriz-1, j ).y;
1450 // --- intersection : x=x0+(y0+x(y1-y0))(x1-x0)
1451 double x = (x0 + y0 * (x1 - x0)) / (1 - (y1 - y0) * (x1 - x0));
1452 double y = y0 + x * (y1 - y0);
1453 int ij = j * nbhoriz + i;
1456 uv_grid[ij].node = NULL;
1460 // projection on 2d domain (u,v)
1462 gp_UV a0 = quad->UVPt( 0, 0 ).UV();
1463 gp_UV a1 = quad->UVPt( nbhoriz-1, 0 ).UV();
1464 gp_UV a2 = quad->UVPt( nbhoriz-1, nbvertic-1 ).UV();
1465 gp_UV a3 = quad->UVPt( 0, nbvertic-1 ).UV();
1467 for (int i = 1; i < nbhoriz-1; i++)
1469 gp_UV p0 = quad->UVPt( i, 0 ).UV();
1470 gp_UV p2 = quad->UVPt( i, nbvertic-1 ).UV();
1471 for (int j = 1; j < nbvertic-1; j++)
1473 gp_UV p1 = quad->UVPt( nbhoriz-1, j ).UV();
1474 gp_UV p3 = quad->UVPt( 0, j ).UV();
1476 int ij = j * nbhoriz + i;
1477 double x = uv_grid[ij].x;
1478 double y = uv_grid[ij].y;
1480 gp_UV uv = calcUV(x,y, a0,a1,a2,a3, p0,p1,p2,p3);
1482 uv_grid[ij].u = uv.X();
1483 uv_grid[ij].v = uv.Y();
1489 //=======================================================================
1490 //function : ShiftQuad
1491 //purpose : auxilary function for computeQuadPref
1492 //=======================================================================
1494 void StdMeshers_Quadrangle_2D::shiftQuad(FaceQuadStruct::Ptr& quad, const int num )
1496 quad->shift( num, /*ori=*/true, /*keepGrid=*/myQuadList.size() > 1 );
1499 //================================================================================
1501 * \brief Rotate sides of a quad by given nb of quartes
1502 * \param nb - number of rotation quartes
1503 * \param ori - to keep orientation of sides as in an unit quad or not
1504 * \param keepGrid - if \c true Side::grid is not changed, Side::from and Side::to
1505 * are altered instead
1507 //================================================================================
1509 void FaceQuadStruct::shift( size_t nb, bool ori, bool keepGrid )
1511 if ( nb == 0 ) return;
1513 vector< Side > newSides( side.size() );
1514 vector< Side* > sidePtrs( side.size() );
1515 for (int i = QUAD_BOTTOM_SIDE; i < NB_QUAD_SIDES; ++i)
1517 int id = (i + nb) % NB_QUAD_SIDES;
1520 bool wasForward = (i < QUAD_TOP_SIDE);
1521 bool newForward = (id < QUAD_TOP_SIDE);
1522 if ( wasForward != newForward )
1523 side[ i ].Reverse( keepGrid );
1525 newSides[ id ] = side[ i ];
1526 sidePtrs[ i ] = & side[ i ];
1528 // make newSides refer newSides via Side::Contact's
1529 for ( size_t i = 0; i < newSides.size(); ++i )
1531 FaceQuadStruct::Side& ns = newSides[ i ];
1532 for ( size_t iC = 0; iC < ns.contacts.size(); ++iC )
1534 FaceQuadStruct::Side* oSide = ns.contacts[iC].other_side;
1535 vector< Side* >::iterator sIt = std::find( sidePtrs.begin(), sidePtrs.end(), oSide );
1536 if ( sIt != sidePtrs.end() )
1537 ns.contacts[iC].other_side = & newSides[ *sIt - sidePtrs[0] ];
1540 newSides.swap( side );
1545 //=======================================================================
1547 //purpose : auxilary function for computeQuadPref
1548 //=======================================================================
1550 static gp_UV calcUV(double x0, double x1, double y0, double y1,
1551 FaceQuadStruct::Ptr& quad,
1552 const gp_UV& a0, const gp_UV& a1,
1553 const gp_UV& a2, const gp_UV& a3)
1555 double x = (x0 + y0 * (x1 - x0)) / (1 - (y1 - y0) * (x1 - x0));
1556 double y = y0 + x * (y1 - y0);
1558 gp_UV p0 = quad->side[QUAD_BOTTOM_SIDE].grid->Value2d(x).XY();
1559 gp_UV p1 = quad->side[QUAD_RIGHT_SIDE ].grid->Value2d(y).XY();
1560 gp_UV p2 = quad->side[QUAD_TOP_SIDE ].grid->Value2d(x).XY();
1561 gp_UV p3 = quad->side[QUAD_LEFT_SIDE ].grid->Value2d(y).XY();
1563 gp_UV uv = calcUV(x,y, a0,a1,a2,a3, p0,p1,p2,p3);
1568 //=======================================================================
1569 //function : calcUV2
1570 //purpose : auxilary function for computeQuadPref
1571 //=======================================================================
1573 static gp_UV calcUV2(double x, double y,
1574 FaceQuadStruct::Ptr& quad,
1575 const gp_UV& a0, const gp_UV& a1,
1576 const gp_UV& a2, const gp_UV& a3)
1578 gp_UV p0 = quad->side[QUAD_BOTTOM_SIDE].grid->Value2d(x).XY();
1579 gp_UV p1 = quad->side[QUAD_RIGHT_SIDE ].grid->Value2d(y).XY();
1580 gp_UV p2 = quad->side[QUAD_TOP_SIDE ].grid->Value2d(x).XY();
1581 gp_UV p3 = quad->side[QUAD_LEFT_SIDE ].grid->Value2d(y).XY();
1583 gp_UV uv = calcUV(x,y, a0,a1,a2,a3, p0,p1,p2,p3);
1589 //=======================================================================
1591 * Create only quandrangle faces
1593 //=======================================================================
1595 bool StdMeshers_Quadrangle_2D::computeQuadPref (SMESH_Mesh & aMesh,
1596 const TopoDS_Face& aFace,
1597 FaceQuadStruct::Ptr quad)
1599 const bool OldVersion = (myQuadType == QUAD_QUADRANGLE_PREF_REVERSED);
1600 const bool WisF = true;
1602 SMESHDS_Mesh * meshDS = aMesh.GetMeshDS();
1603 Handle(Geom_Surface) S = BRep_Tool::Surface(aFace);
1604 int i,j, geomFaceID = meshDS->ShapeToIndex(aFace);
1606 int nb = quad->side[0].NbPoints();
1607 int nr = quad->side[1].NbPoints();
1608 int nt = quad->side[2].NbPoints();
1609 int nl = quad->side[3].NbPoints();
1610 int dh = abs(nb-nt);
1611 int dv = abs(nr-nl);
1613 if ( myForcedPnts.empty() )
1615 // rotate sides to be as in the picture below and to have
1616 // dh >= dv and nt > nb
1618 shiftQuad( quad, ( nt > nb ) ? 0 : 2 );
1620 shiftQuad( quad, ( nr > nl ) ? 1 : 3 );
1624 // rotate the quad to have nt > nb [and nr > nl]
1626 shiftQuad ( quad, nr > nl ? 1 : 2 );
1628 shiftQuad( quad, nb == nt ? 1 : 0 );
1630 shiftQuad( quad, 3 );
1633 nb = quad->side[0].NbPoints();
1634 nr = quad->side[1].NbPoints();
1635 nt = quad->side[2].NbPoints();
1636 nl = quad->side[3].NbPoints();
1639 int nbh = Max(nb,nt);
1640 int nbv = Max(nr,nl);
1644 // Orientation of face and 3 main domain for future faces
1645 // ----------- Old version ---------------
1651 // left | |__| | rigth
1658 // ----------- New version ---------------
1664 // left |/________\| rigth
1672 const int bfrom = quad->side[0].from;
1673 const int rfrom = quad->side[1].from;
1674 const int tfrom = quad->side[2].from;
1675 const int lfrom = quad->side[3].from;
1677 const vector<UVPtStruct>& uv_eb_vec = quad->side[0].GetUVPtStruct(true,0);
1678 const vector<UVPtStruct>& uv_er_vec = quad->side[1].GetUVPtStruct(false,1);
1679 const vector<UVPtStruct>& uv_et_vec = quad->side[2].GetUVPtStruct(true,1);
1680 const vector<UVPtStruct>& uv_el_vec = quad->side[3].GetUVPtStruct(false,0);
1681 if (uv_eb_vec.empty() ||
1682 uv_er_vec.empty() ||
1683 uv_et_vec.empty() ||
1685 return error(COMPERR_BAD_INPUT_MESH);
1687 FaceQuadStruct::SideIterator uv_eb, uv_er, uv_et, uv_el;
1688 uv_eb.Init( quad->side[0] );
1689 uv_er.Init( quad->side[1] );
1690 uv_et.Init( quad->side[2] );
1691 uv_el.Init( quad->side[3] );
1693 gp_UV a0,a1,a2,a3, p0,p1,p2,p3, uv;
1696 a0 = uv_eb[ 0 ].UV();
1697 a1 = uv_er[ 0 ].UV();
1698 a2 = uv_er[ nr-1 ].UV();
1699 a3 = uv_et[ 0 ].UV();
1701 if ( !myForcedPnts.empty() )
1703 if ( dv != 0 && dh != 0 ) // here myQuadList.size() == 1
1705 const int dmin = Min( dv, dh );
1707 // Make a side separating domains L and Cb
1708 StdMeshers_FaceSidePtr sideLCb;
1709 UVPtStruct p3dom; // a point where 3 domains meat
1711 vector<UVPtStruct> pointsLCb( dmin+1 ); // 1--------1
1712 pointsLCb[0] = uv_eb[0]; // | | |
1713 for ( int i = 1; i <= dmin; ++i ) // | |Ct|
1715 x = uv_et[ i ].normParam; // | |__|
1716 y = uv_er[ i ].normParam; // | / |
1717 p0 = quad->side[0].grid->Value2d( x ).XY(); // | / Cb |dmin
1718 p1 = uv_er[ i ].UV(); // |/ |
1719 p2 = uv_et[ i ].UV(); // 0--------0
1720 p3 = quad->side[3].grid->Value2d( y ).XY();
1721 uv = calcUV( x,y, a0,a1,a2,a3, p0,p1,p2,p3 );
1722 pointsLCb[ i ].u = uv.X();
1723 pointsLCb[ i ].v = uv.Y();
1725 sideLCb = StdMeshers_FaceSide::New( pointsLCb, aFace );
1726 p3dom = pointsLCb.back();
1728 // Make a side separating domains L and Ct
1729 StdMeshers_FaceSidePtr sideLCt;
1731 vector<UVPtStruct> pointsLCt( nl );
1732 pointsLCt[0] = p3dom;
1733 pointsLCt.back() = uv_et[ dmin ];
1734 x = uv_et[ dmin ].normParam;
1735 p0 = quad->side[0].grid->Value2d( x ).XY();
1736 p2 = uv_et[ dmin ].UV();
1737 double y0 = uv_er[ dmin ].normParam;
1738 for ( int i = 1; i < nl-1; ++i )
1740 y = y0 + i / ( nl-1. ) * ( 1. - y0 );
1741 p1 = quad->side[1].grid->Value2d( y ).XY();
1742 p3 = quad->side[3].grid->Value2d( y ).XY();
1743 uv = calcUV( x,y, a0,a1,a2,a3, p0,p1,p2,p3 );
1744 pointsLCt[ i ].u = uv.X();
1745 pointsLCt[ i ].v = uv.Y();
1747 sideLCt = StdMeshers_FaceSide::New( pointsLCt, aFace );
1749 // Make a side separating domains Cb and Ct
1750 StdMeshers_FaceSidePtr sideCbCt;
1752 vector<UVPtStruct> pointsCbCt( nb );
1753 pointsCbCt[0] = p3dom;
1754 pointsCbCt.back() = uv_er[ dmin ];
1755 y = uv_er[ dmin ].normParam;
1756 p1 = uv_er[ dmin ].UV();
1757 p3 = quad->side[3].grid->Value2d( y ).XY();
1758 double x0 = uv_et[ dmin ].normParam;
1759 for ( int i = 1; i < nb-1; ++i )
1761 x = x0 + i / ( nb-1. ) * ( 1. - x0 );
1762 p2 = quad->side[2].grid->Value2d( x ).XY();
1763 p0 = quad->side[0].grid->Value2d( x ).XY();
1764 uv = calcUV( x,y, a0,a1,a2,a3, p0,p1,p2,p3 );
1765 pointsCbCt[ i ].u = uv.X();
1766 pointsCbCt[ i ].v = uv.Y();
1768 sideCbCt = StdMeshers_FaceSide::New( pointsCbCt, aFace );
1771 FaceQuadStruct* qCb = new FaceQuadStruct( quad->face, "Cb" );
1772 myQuadList.push_back( FaceQuadStruct::Ptr( qCb ));
1773 qCb->side.resize(4);
1774 qCb->side[0] = quad->side[0];
1775 qCb->side[1] = quad->side[1];
1776 qCb->side[2] = sideCbCt;
1777 qCb->side[3] = sideLCb;
1778 qCb->side[1].to = dmin+1;
1780 FaceQuadStruct* qL = new FaceQuadStruct( quad->face, "L" );
1781 myQuadList.push_back( FaceQuadStruct::Ptr( qL ));
1783 qL->side[0] = sideLCb;
1784 qL->side[1] = sideLCt;
1785 qL->side[2] = quad->side[2];
1786 qL->side[3] = quad->side[3];
1787 qL->side[2].to = dmin+1;
1788 // Make Ct from the main quad
1789 FaceQuadStruct::Ptr qCt = quad;
1790 qCt->side[0] = sideCbCt;
1791 qCt->side[3] = sideLCt;
1792 qCt->side[1].from = dmin;
1793 qCt->side[2].from = dmin;
1794 qCt->uv_grid.clear();
1798 qCb->side[3].AddContact( dmin, & qCb->side[2], 0 );
1799 qCb->side[3].AddContact( dmin, & qCt->side[3], 0 );
1800 qCt->side[3].AddContact( 0, & qCt->side[0], 0 );
1801 qCt->side[0].AddContact( 0, & qL ->side[0], dmin );
1802 qL ->side[0].AddContact( dmin, & qL ->side[1], 0 );
1803 qL ->side[0].AddContact( dmin, & qCb->side[2], 0 );
1806 return computeQuadDominant( aMesh, aFace );
1808 return computeQuadPref( aMesh, aFace, qCt );
1810 } // if ( dv != 0 && dh != 0 )
1812 const int db = quad->side[0].IsReversed() ? -1 : +1;
1813 const int dr = quad->side[1].IsReversed() ? -1 : +1;
1814 const int dt = quad->side[2].IsReversed() ? -1 : +1;
1815 const int dl = quad->side[3].IsReversed() ? -1 : +1;
1817 // Case dv == 0, here possibly myQuadList.size() > 1
1829 const int lw = dh/2; // lateral width
1833 double lL = quad->side[3].Length();
1834 double lLwL = quad->side[2].Length( tfrom,
1835 tfrom + ( lw ) * dt );
1836 yCbL = lLwL / ( lLwL + lL );
1838 double lR = quad->side[1].Length();
1839 double lLwR = quad->side[2].Length( tfrom + ( lw + nb-1 ) * dt,
1840 tfrom + ( lw + nb-1 + lw ) * dt);
1841 yCbR = lLwR / ( lLwR + lR );
1843 // Make sides separating domains Cb and L and R
1844 StdMeshers_FaceSidePtr sideLCb, sideRCb;
1845 UVPtStruct pTBL, pTBR; // points where 3 domains meat
1847 vector<UVPtStruct> pointsLCb( lw+1 ), pointsRCb( lw+1 );
1848 pointsLCb[0] = uv_eb[ 0 ];
1849 pointsRCb[0] = uv_eb[ nb-1 ];
1850 for ( int i = 1, i2 = nt-2; i <= lw; ++i, --i2 )
1852 x = quad->side[2].Param( i );
1854 p0 = quad->side[0].Value2d( x );
1855 p1 = quad->side[1].Value2d( y );
1856 p2 = uv_et[ i ].UV();
1857 p3 = quad->side[3].Value2d( y );
1858 uv = calcUV( x,y, a0,a1,a2,a3, p0,p1,p2,p3 );
1859 pointsLCb[ i ].u = uv.X();
1860 pointsLCb[ i ].v = uv.Y();
1861 pointsLCb[ i ].x = x;
1863 x = quad->side[2].Param( i2 );
1865 p1 = quad->side[1].Value2d( y );
1866 p0 = quad->side[0].Value2d( x );
1867 p2 = uv_et[ i2 ].UV();
1868 p3 = quad->side[3].Value2d( y );
1869 uv = calcUV( x,y, a0,a1,a2,a3, p0,p1,p2,p3 );
1870 pointsRCb[ i ].u = uv.X();
1871 pointsRCb[ i ].v = uv.Y();
1872 pointsRCb[ i ].x = x;
1874 sideLCb = StdMeshers_FaceSide::New( pointsLCb, aFace );
1875 sideRCb = StdMeshers_FaceSide::New( pointsRCb, aFace );
1876 pTBL = pointsLCb.back();
1877 pTBR = pointsRCb.back();
1879 // Make sides separating domains Ct and L and R
1880 StdMeshers_FaceSidePtr sideLCt, sideRCt;
1882 vector<UVPtStruct> pointsLCt( nl ), pointsRCt( nl );
1883 pointsLCt[0] = pTBL;
1884 pointsLCt.back() = uv_et[ lw ];
1885 pointsRCt[0] = pTBR;
1886 pointsRCt.back() = uv_et[ lw + nb - 1 ];
1888 p0 = quad->side[0].Value2d( x );
1889 p2 = uv_et[ lw ].UV();
1890 int iR = lw + nb - 1;
1892 gp_UV p0R = quad->side[0].Value2d( xR );
1893 gp_UV p2R = uv_et[ iR ].UV();
1894 for ( int i = 1; i < nl-1; ++i )
1896 y = yCbL + ( 1. - yCbL ) * i / (nl-1.);
1897 p1 = quad->side[1].Value2d( y );
1898 p3 = quad->side[3].Value2d( y );
1899 uv = calcUV( x,y, a0,a1,a2,a3, p0,p1,p2,p3 );
1900 pointsLCt[ i ].u = uv.X();
1901 pointsLCt[ i ].v = uv.Y();
1903 y = yCbR + ( 1. - yCbR ) * i / (nl-1.);
1904 p1 = quad->side[1].Value2d( y );
1905 p3 = quad->side[3].Value2d( y );
1906 uv = calcUV( xR,y, a0,a1,a2,a3, p0R,p1,p2R,p3 );
1907 pointsRCt[ i ].u = uv.X();
1908 pointsRCt[ i ].v = uv.Y();
1910 sideLCt = StdMeshers_FaceSide::New( pointsLCt, aFace );
1911 sideRCt = StdMeshers_FaceSide::New( pointsRCt, aFace );
1913 // Make a side separating domains Cb and Ct
1914 StdMeshers_FaceSidePtr sideCbCt;
1916 vector<UVPtStruct> pointsCbCt( nb );
1917 pointsCbCt[0] = pTBL;
1918 pointsCbCt.back() = pTBR;
1919 p1 = quad->side[1].Value2d( yCbR );
1920 p3 = quad->side[3].Value2d( yCbL );
1921 for ( int i = 1; i < nb-1; ++i )
1923 x = quad->side[2].Param( i + lw );
1924 y = yCbL + ( yCbR - yCbL ) * i / (nb-1.);
1925 p2 = uv_et[ i + lw ].UV();
1926 p0 = quad->side[0].Value2d( x );
1927 uv = calcUV( x,y, a0,a1,a2,a3, p0,p1,p2,p3 );
1928 pointsCbCt[ i ].u = uv.X();
1929 pointsCbCt[ i ].v = uv.Y();
1931 sideCbCt = StdMeshers_FaceSide::New( pointsCbCt, aFace );
1934 FaceQuadStruct* qCb = new FaceQuadStruct( quad->face, "Cb" );
1935 myQuadList.push_back( FaceQuadStruct::Ptr( qCb ));
1936 qCb->side.resize(4);
1937 qCb->side[0] = quad->side[0];
1938 qCb->side[1] = sideRCb;
1939 qCb->side[2] = sideCbCt;
1940 qCb->side[3] = sideLCb;
1942 FaceQuadStruct* qL = new FaceQuadStruct( quad->face, "L" );
1943 myQuadList.push_back( FaceQuadStruct::Ptr( qL ));
1945 qL->side[0] = sideLCb;
1946 qL->side[1] = sideLCt;
1947 qL->side[2] = quad->side[2];
1948 qL->side[3] = quad->side[3];
1949 qL->side[2].to = ( lw + 1 ) * dt + tfrom;
1951 FaceQuadStruct* qR = new FaceQuadStruct( quad->face, "R" );
1952 myQuadList.push_back( FaceQuadStruct::Ptr( qR ));
1954 qR->side[0] = sideRCb;
1955 qR->side[0].from = lw;
1956 qR->side[0].to = -1;
1957 qR->side[0].di = -1;
1958 qR->side[1] = quad->side[1];
1959 qR->side[2] = quad->side[2];
1960 qR->side[2].from = ( lw + nb-1 ) * dt + tfrom;
1961 qR->side[3] = sideRCt;
1962 // Make Ct from the main quad
1963 FaceQuadStruct::Ptr qCt = quad;
1964 qCt->side[0] = sideCbCt;
1965 qCt->side[1] = sideRCt;
1966 qCt->side[2].from = ( lw ) * dt + tfrom;
1967 qCt->side[2].to = ( lw + nb ) * dt + tfrom;
1968 qCt->side[3] = sideLCt;
1969 qCt->uv_grid.clear();
1973 qCb->side[3].AddContact( lw, & qCb->side[2], 0 );
1974 qCb->side[3].AddContact( lw, & qCt->side[3], 0 );
1975 qCt->side[3].AddContact( 0, & qCt->side[0], 0 );
1976 qCt->side[0].AddContact( 0, & qL ->side[0], lw );
1977 qL ->side[0].AddContact( lw, & qL ->side[1], 0 );
1978 qL ->side[0].AddContact( lw, & qCb->side[2], 0 );
1980 qCb->side[1].AddContact( lw, & qCb->side[2], nb-1 );
1981 qCb->side[1].AddContact( lw, & qCt->side[1], 0 );
1982 qCt->side[0].AddContact( nb-1, & qCt->side[1], 0 );
1983 qCt->side[0].AddContact( nb-1, & qR ->side[0], lw );
1984 qR ->side[3].AddContact( 0, & qR ->side[0], lw );
1985 qR ->side[3].AddContact( 0, & qCb->side[2], nb-1 );
1987 return computeQuadDominant( aMesh, aFace );
1989 } // if ( !myForcedPnts.empty() )
2000 // arrays for normalized params
2001 TColStd_SequenceOfReal npb, npr, npt, npl;
2002 for (i=0; i<nb; i++) {
2003 npb.Append(uv_eb[i].normParam);
2005 for (i=0; i<nr; i++) {
2006 npr.Append(uv_er[i].normParam);
2008 for (i=0; i<nt; i++) {
2009 npt.Append(uv_et[i].normParam);
2011 for (i=0; i<nl; i++) {
2012 npl.Append(uv_el[i].normParam);
2017 // add some params to right and left after the first param
2020 double dpr = (npr.Value(2) - npr.Value(1))/(dr+1);
2021 for (i=1; i<=dr; i++) {
2022 npr.InsertAfter(1,npr.Value(2)-dpr);
2026 dpr = (npl.Value(2) - npl.Value(1))/(dl+1);
2027 for (i=1; i<=dl; i++) {
2028 npl.InsertAfter(1,npl.Value(2)-dpr);
2032 int nnn = Min(nr,nl);
2033 // auxilary sequence of XY for creation nodes
2034 // in the bottom part of central domain
2035 // Length of UVL and UVR must be == nbv-nnn
2036 TColgp_SequenceOfXY UVL, UVR, UVT;
2039 // step1: create faces for left domain
2040 StdMeshers_Array2OfNode NodesL(1,dl+1,1,nl);
2042 for (j=1; j<=nl; j++)
2043 NodesL.SetValue(1,j,uv_el[j-1].node);
2046 for (i=1; i<=dl; i++)
2047 NodesL.SetValue(i+1,nl,uv_et[i].node);
2048 // create and add needed nodes
2049 TColgp_SequenceOfXY UVtmp;
2050 for (i=1; i<=dl; i++) {
2051 double x0 = npt.Value(i+1);
2054 double y0 = npl.Value(i+1);
2055 double y1 = npr.Value(i+1);
2056 gp_UV UV = calcUV(x0, x1, y0, y1, quad, a0, a1, a2, a3);
2057 gp_Pnt P = S->Value(UV.X(),UV.Y());
2058 SMDS_MeshNode * N = meshDS->AddNode(P.X(), P.Y(), P.Z());
2059 meshDS->SetNodeOnFace(N, geomFaceID, UV.X(), UV.Y());
2060 NodesL.SetValue(i+1,1,N);
2061 if (UVL.Length()<nbv-nnn) UVL.Append(UV);
2063 for (j=2; j<nl; j++) {
2064 double y0 = npl.Value(dl+j);
2065 double y1 = npr.Value(dl+j);
2066 gp_UV UV = calcUV(x0, x1, y0, y1, quad, a0, a1, a2, a3);
2067 gp_Pnt P = S->Value(UV.X(),UV.Y());
2068 SMDS_MeshNode* N = meshDS->AddNode(P.X(), P.Y(), P.Z());
2069 meshDS->SetNodeOnFace(N, geomFaceID, UV.X(), UV.Y());
2070 NodesL.SetValue(i+1,j,N);
2071 if (i==dl) UVtmp.Append(UV);
2074 for (i=1; i<=UVtmp.Length() && UVL.Length()<nbv-nnn; i++) {
2075 UVL.Append(UVtmp.Value(i));
2078 for (i=1; i<=dl; i++) {
2079 for (j=1; j<nl; j++) {
2082 myHelper->AddFace(NodesL.Value(i,j), NodesL.Value(i+1,j),
2083 NodesL.Value(i+1,j+1), NodesL.Value(i,j+1));
2084 if (F) meshDS->SetMeshElementOnShape(F, geomFaceID);
2090 // fill UVL using c2d
2091 for (i=1; i<npl.Length() && UVL.Length()<nbv-nnn; i++) {
2092 UVL.Append(gp_UV (uv_el[i].u, uv_el[i].v));
2096 // step2: create faces for right domain
2097 StdMeshers_Array2OfNode NodesR(1,dr+1,1,nr);
2099 for (j=1; j<=nr; j++)
2100 NodesR.SetValue(1,j,uv_er[nr-j].node);
2103 for (i=1; i<=dr; i++)
2104 NodesR.SetValue(i+1,1,uv_et[nt-1-i].node);
2105 // create and add needed nodes
2106 TColgp_SequenceOfXY UVtmp;
2107 for (i=1; i<=dr; i++) {
2108 double x0 = npt.Value(nt-i);
2111 double y0 = npl.Value(i+1);
2112 double y1 = npr.Value(i+1);
2113 gp_UV UV = calcUV(x0, x1, y0, y1, quad, a0, a1, a2, a3);
2114 gp_Pnt P = S->Value(UV.X(),UV.Y());
2115 SMDS_MeshNode * N = meshDS->AddNode(P.X(), P.Y(), P.Z());
2116 meshDS->SetNodeOnFace(N, geomFaceID, UV.X(), UV.Y());
2117 NodesR.SetValue(i+1,nr,N);
2118 if (UVR.Length()<nbv-nnn) UVR.Append(UV);
2120 for (j=2; j<nr; j++) {
2121 double y0 = npl.Value(nbv-j+1);
2122 double y1 = npr.Value(nbv-j+1);
2123 gp_UV UV = calcUV(x0, x1, y0, y1, quad, a0, a1, a2, a3);
2124 gp_Pnt P = S->Value(UV.X(),UV.Y());
2125 SMDS_MeshNode* N = meshDS->AddNode(P.X(), P.Y(), P.Z());
2126 meshDS->SetNodeOnFace(N, geomFaceID, UV.X(), UV.Y());
2127 NodesR.SetValue(i+1,j,N);
2128 if (i==dr) UVtmp.Prepend(UV);
2131 for (i=1; i<=UVtmp.Length() && UVR.Length()<nbv-nnn; i++) {
2132 UVR.Append(UVtmp.Value(i));
2135 for (i=1; i<=dr; i++) {
2136 for (j=1; j<nr; j++) {
2139 myHelper->AddFace(NodesR.Value(i,j), NodesR.Value(i+1,j),
2140 NodesR.Value(i+1,j+1), NodesR.Value(i,j+1));
2141 if (F) meshDS->SetMeshElementOnShape(F, geomFaceID);
2147 // fill UVR using c2d
2148 for (i=1; i<npr.Length() && UVR.Length()<nbv-nnn; i++) {
2149 UVR.Append(gp_UV(uv_er[i].u, uv_er[i].v));
2153 // step3: create faces for central domain
2154 StdMeshers_Array2OfNode NodesC(1,nb,1,nbv);
2155 // add first line using NodesL
2156 for (i=1; i<=dl+1; i++)
2157 NodesC.SetValue(1,i,NodesL(i,1));
2158 for (i=2; i<=nl; i++)
2159 NodesC.SetValue(1,dl+i,NodesL(dl+1,i));
2160 // add last line using NodesR
2161 for (i=1; i<=dr+1; i++)
2162 NodesC.SetValue(nb,i,NodesR(i,nr));
2163 for (i=1; i<nr; i++)
2164 NodesC.SetValue(nb,dr+i+1,NodesR(dr+1,nr-i));
2165 // add top nodes (last columns)
2166 for (i=dl+2; i<nbh-dr; i++)
2167 NodesC.SetValue(i-dl,nbv,uv_et[i-1].node);
2168 // add bottom nodes (first columns)
2169 for (i=2; i<nb; i++)
2170 NodesC.SetValue(i,1,uv_eb[i-1].node);
2172 // create and add needed nodes
2173 // add linear layers
2174 for (i=2; i<nb; i++) {
2175 double x0 = npt.Value(dl+i);
2177 for (j=1; j<nnn; j++) {
2178 double y0 = npl.Value(nbv-nnn+j);
2179 double y1 = npr.Value(nbv-nnn+j);
2180 gp_UV UV = calcUV(x0, x1, y0, y1, quad, a0, a1, a2, a3);
2181 gp_Pnt P = S->Value(UV.X(),UV.Y());
2182 SMDS_MeshNode* N = meshDS->AddNode(P.X(), P.Y(), P.Z());
2183 meshDS->SetNodeOnFace(N, geomFaceID, UV.X(), UV.Y());
2184 NodesC.SetValue(i,nbv-nnn+j,N);
2189 // add diagonal layers
2190 gp_UV A2 = UVR.Value(nbv-nnn);
2191 gp_UV A3 = UVL.Value(nbv-nnn);
2192 for (i=1; i<nbv-nnn; i++) {
2193 gp_UV p1 = UVR.Value(i);
2194 gp_UV p3 = UVL.Value(i);
2195 double y = i / double(nbv-nnn);
2196 for (j=2; j<nb; j++) {
2197 double x = npb.Value(j);
2198 gp_UV p0( uv_eb[j-1].u, uv_eb[j-1].v );
2199 gp_UV p2 = UVT.Value( j-1 );
2200 gp_UV UV = calcUV(x, y, a0, a1, A2, A3, p0,p1,p2,p3 );
2201 gp_Pnt P = S->Value(UV.X(),UV.Y());
2202 SMDS_MeshNode* N = meshDS->AddNode(P.X(), P.Y(), P.Z());
2203 meshDS->SetNodeOnFace(N, geomFaceID, UV.X(),UV.Y());
2204 NodesC.SetValue(j,i+1,N);
2208 for (i=1; i<nb; i++) {
2209 for (j=1; j<nbv; j++) {
2212 myHelper->AddFace(NodesC.Value(i,j), NodesC.Value(i+1,j),
2213 NodesC.Value(i+1,j+1), NodesC.Value(i,j+1));
2214 if (F) meshDS->SetMeshElementOnShape(F, geomFaceID);
2220 else { // New version (!OldVersion)
2221 // step1: create faces for bottom rectangle domain
2222 StdMeshers_Array2OfNode NodesBRD(1,nb,1,nnn-1);
2223 // fill UVL and UVR using c2d
2224 for (j=0; j<nb; j++) {
2225 NodesBRD.SetValue(j+1,1,uv_eb[j].node);
2227 for (i=1; i<nnn-1; i++) {
2228 NodesBRD.SetValue(1,i+1,uv_el[i].node);
2229 NodesBRD.SetValue(nb,i+1,uv_er[i].node);
2230 for (j=2; j<nb; j++) {
2231 double x = npb.Value(j);
2232 double y = (1-x) * npl.Value(i+1) + x * npr.Value(i+1);
2233 gp_UV UV = calcUV2(x, y, quad, a0, a1, a2, a3);
2234 gp_Pnt P = S->Value(UV.X(),UV.Y());
2235 SMDS_MeshNode* N = meshDS->AddNode(P.X(), P.Y(), P.Z());
2236 meshDS->SetNodeOnFace(N, geomFaceID, UV.X(),UV.Y());
2237 NodesBRD.SetValue(j,i+1,N);
2240 for (j=1; j<nnn-1; j++) {
2241 for (i=1; i<nb; i++) {
2244 myHelper->AddFace(NodesBRD.Value(i,j), NodesBRD.Value(i+1,j),
2245 NodesBRD.Value(i+1,j+1), NodesBRD.Value(i,j+1));
2246 if (F) meshDS->SetMeshElementOnShape(F, geomFaceID);
2250 int drl = abs(nr-nl);
2251 // create faces for region C
2252 StdMeshers_Array2OfNode NodesC(1,nb,1,drl+1+addv);
2253 // add nodes from previous region
2254 for (j=1; j<=nb; j++) {
2255 NodesC.SetValue(j,1,NodesBRD.Value(j,nnn-1));
2257 if ((drl+addv) > 0) {
2262 TColgp_SequenceOfXY UVtmp;
2263 double drparam = npr.Value(nr) - npr.Value(nnn-1);
2264 double dlparam = npl.Value(nnn) - npl.Value(nnn-1);
2266 for (i=1; i<=drl; i++) {
2267 // add existed nodes from right edge
2268 NodesC.SetValue(nb,i+1,uv_er[nnn+i-2].node);
2269 //double dtparam = npt.Value(i+1);
2270 y1 = npr.Value(nnn+i-1); // param on right edge
2271 double dpar = (y1 - npr.Value(nnn-1))/drparam;
2272 y0 = npl.Value(nnn-1) + dpar*dlparam; // param on left edge
2273 double dy = y1 - y0;
2274 for (j=1; j<nb; j++) {
2275 double x = npt.Value(i+1) + npb.Value(j)*(1-npt.Value(i+1));
2276 double y = y0 + dy*x;
2277 gp_UV UV = calcUV2(x, y, quad, a0, a1, a2, a3);
2278 gp_Pnt P = S->Value(UV.X(),UV.Y());
2279 SMDS_MeshNode* N = meshDS->AddNode(P.X(), P.Y(), P.Z());
2280 meshDS->SetNodeOnFace(N, geomFaceID, UV.X(), UV.Y());
2281 NodesC.SetValue(j,i+1,N);
2284 double dy0 = (1-y0)/(addv+1);
2285 double dy1 = (1-y1)/(addv+1);
2286 for (i=1; i<=addv; i++) {
2287 double yy0 = y0 + dy0*i;
2288 double yy1 = y1 + dy1*i;
2289 double dyy = yy1 - yy0;
2290 for (j=1; j<=nb; j++) {
2291 double x = npt.Value(i+1+drl) +
2292 npb.Value(j) * (npt.Value(nt-i) - npt.Value(i+1+drl));
2293 double y = yy0 + dyy*x;
2294 gp_UV UV = calcUV2(x, y, quad, a0, a1, a2, a3);
2295 gp_Pnt P = S->Value(UV.X(),UV.Y());
2296 SMDS_MeshNode* N = meshDS->AddNode(P.X(), P.Y(), P.Z());
2297 meshDS->SetNodeOnFace(N, geomFaceID, UV.X(), UV.Y());
2298 NodesC.SetValue(j,i+drl+1,N);
2305 TColgp_SequenceOfXY UVtmp;
2306 double dlparam = npl.Value(nl) - npl.Value(nnn-1);
2307 double drparam = npr.Value(nnn) - npr.Value(nnn-1);
2308 double y0 = npl.Value(nnn-1);
2309 double y1 = npr.Value(nnn-1);
2310 for (i=1; i<=drl; i++) {
2311 // add existed nodes from right edge
2312 NodesC.SetValue(1,i+1,uv_el[nnn+i-2].node);
2313 y0 = npl.Value(nnn+i-1); // param on left edge
2314 double dpar = (y0 - npl.Value(nnn-1))/dlparam;
2315 y1 = npr.Value(nnn-1) + dpar*drparam; // param on right edge
2316 double dy = y1 - y0;
2317 for (j=2; j<=nb; j++) {
2318 double x = npb.Value(j)*npt.Value(nt-i);
2319 double y = y0 + dy*x;
2320 gp_UV UV = calcUV2(x, y, quad, a0, a1, a2, a3);
2321 gp_Pnt P = S->Value(UV.X(),UV.Y());
2322 SMDS_MeshNode* N = meshDS->AddNode(P.X(), P.Y(), P.Z());
2323 meshDS->SetNodeOnFace(N, geomFaceID, UV.X(), UV.Y());
2324 NodesC.SetValue(j,i+1,N);
2327 double dy0 = (1-y0)/(addv+1);
2328 double dy1 = (1-y1)/(addv+1);
2329 for (i=1; i<=addv; i++) {
2330 double yy0 = y0 + dy0*i;
2331 double yy1 = y1 + dy1*i;
2332 double dyy = yy1 - yy0;
2333 for (j=1; j<=nb; j++) {
2334 double x = npt.Value(i+1) +
2335 npb.Value(j) * (npt.Value(nt-i-drl) - npt.Value(i+1));
2336 double y = yy0 + dyy*x;
2337 gp_UV UV = calcUV2(x, y, quad, a0, a1, a2, a3);
2338 gp_Pnt P = S->Value(UV.X(),UV.Y());
2339 SMDS_MeshNode* N = meshDS->AddNode(P.X(), P.Y(), P.Z());
2340 meshDS->SetNodeOnFace(N, geomFaceID, UV.X(), UV.Y());
2341 NodesC.SetValue(j,i+drl+1,N);
2346 for (j=1; j<=drl+addv; j++) {
2347 for (i=1; i<nb; i++) {
2350 myHelper->AddFace(NodesC.Value(i,j), NodesC.Value(i+1,j),
2351 NodesC.Value(i+1,j+1), NodesC.Value(i,j+1));
2352 if (F) meshDS->SetMeshElementOnShape(F, geomFaceID);
2357 StdMeshers_Array2OfNode NodesLast(1,nt,1,2);
2358 for (i=1; i<=nt; i++) {
2359 NodesLast.SetValue(i,2,uv_et[i-1].node);
2362 for (i=n1; i<drl+addv+1; i++) {
2364 NodesLast.SetValue(nnn,1,NodesC.Value(1,i));
2366 for (i=1; i<=nb; i++) {
2368 NodesLast.SetValue(nnn,1,NodesC.Value(i,drl+addv+1));
2370 for (i=drl+addv; i>=n2; i--) {
2372 NodesLast.SetValue(nnn,1,NodesC.Value(nb,i));
2374 for (i=1; i<nt; i++) {
2377 myHelper->AddFace(NodesLast.Value(i,1), NodesLast.Value(i+1,1),
2378 NodesLast.Value(i+1,2), NodesLast.Value(i,2));
2379 if (F) meshDS->SetMeshElementOnShape(F, geomFaceID);
2382 } // if ((drl+addv) > 0)
2384 } // end new version implementation
2391 //=======================================================================
2393 * Evaluate only quandrangle faces
2395 //=======================================================================
2397 bool StdMeshers_Quadrangle_2D::evaluateQuadPref(SMESH_Mesh & aMesh,
2398 const TopoDS_Shape& aShape,
2399 std::vector<int>& aNbNodes,
2400 MapShapeNbElems& aResMap,
2403 // Auxilary key in order to keep old variant
2404 // of meshing after implementation new variant
2405 // for bug 0016220 from Mantis.
2406 bool OldVersion = false;
2407 if (myQuadType == QUAD_QUADRANGLE_PREF_REVERSED)
2410 const TopoDS_Face& F = TopoDS::Face(aShape);
2411 Handle(Geom_Surface) S = BRep_Tool::Surface(F);
2413 int nb = aNbNodes[0];
2414 int nr = aNbNodes[1];
2415 int nt = aNbNodes[2];
2416 int nl = aNbNodes[3];
2417 int dh = abs(nb-nt);
2418 int dv = abs(nr-nl);
2422 // it is a base case => not shift
2425 // we have to shift on 2
2434 // we have to shift quad on 1
2441 // we have to shift quad on 3
2451 int nbh = Max(nb,nt);
2452 int nbv = Max(nr,nl);
2467 // add some params to right and left after the first param
2474 int nnn = Min(nr,nl);
2479 // step1: create faces for left domain
2481 nbNodes += dl*(nl-1);
2482 nbFaces += dl*(nl-1);
2484 // step2: create faces for right domain
2486 nbNodes += dr*(nr-1);
2487 nbFaces += dr*(nr-1);
2489 // step3: create faces for central domain
2490 nbNodes += (nb-2)*(nnn-1) + (nbv-nnn-1)*(nb-2);
2491 nbFaces += (nb-1)*(nbv-1);
2493 else { // New version (!OldVersion)
2494 nbNodes += (nnn-2)*(nb-2);
2495 nbFaces += (nnn-2)*(nb-1);
2496 int drl = abs(nr-nl);
2497 nbNodes += drl*(nb-1) + addv*nb;
2498 nbFaces += (drl+addv)*(nb-1) + (nt-1);
2499 } // end new version implementation
2501 std::vector<int> aVec(SMDSEntity_Last);
2502 for (int i=SMDSEntity_Node; i<SMDSEntity_Last; i++) aVec[i] = 0;
2504 aVec[SMDSEntity_Quad_Quadrangle] = nbFaces;
2505 aVec[SMDSEntity_Node] = nbNodes + nbFaces*4;
2506 if (aNbNodes.size()==5) {
2507 aVec[SMDSEntity_Quad_Triangle] = aNbNodes[3] - 1;
2508 aVec[SMDSEntity_Quad_Quadrangle] = nbFaces - aNbNodes[3] + 1;
2512 aVec[SMDSEntity_Node] = nbNodes;
2513 aVec[SMDSEntity_Quadrangle] = nbFaces;
2514 if (aNbNodes.size()==5) {
2515 aVec[SMDSEntity_Triangle] = aNbNodes[3] - 1;
2516 aVec[SMDSEntity_Quadrangle] = nbFaces - aNbNodes[3] + 1;
2519 SMESH_subMesh * sm = aMesh.GetSubMesh(aShape);
2520 aResMap.insert(std::make_pair(sm,aVec));
2525 //=============================================================================
2526 /*! Split quadrangle in to 2 triangles by smallest diagonal
2529 //=============================================================================
2531 void StdMeshers_Quadrangle_2D::splitQuadFace(SMESHDS_Mesh * theMeshDS,
2533 const SMDS_MeshNode* theNode1,
2534 const SMDS_MeshNode* theNode2,
2535 const SMDS_MeshNode* theNode3,
2536 const SMDS_MeshNode* theNode4)
2538 SMDS_MeshFace* face;
2539 if ( SMESH_TNodeXYZ( theNode1 ).SquareDistance( theNode3 ) >
2540 SMESH_TNodeXYZ( theNode2 ).SquareDistance( theNode4 ) )
2542 face = myHelper->AddFace(theNode2, theNode4 , theNode1);
2543 if (face) theMeshDS->SetMeshElementOnShape(face, theFaceID);
2544 face = myHelper->AddFace(theNode2, theNode3, theNode4);
2545 if (face) theMeshDS->SetMeshElementOnShape(face, theFaceID);
2549 face = myHelper->AddFace(theNode1, theNode2 ,theNode3);
2550 if (face) theMeshDS->SetMeshElementOnShape(face, theFaceID);
2551 face = myHelper->AddFace(theNode1, theNode3, theNode4);
2552 if (face) theMeshDS->SetMeshElementOnShape(face, theFaceID);
2558 enum uvPos { UV_A0, UV_A1, UV_A2, UV_A3, UV_B, UV_R, UV_T, UV_L, UV_SIZE };
2560 inline SMDS_MeshNode* makeNode( UVPtStruct & uvPt,
2562 FaceQuadStruct::Ptr& quad,
2564 SMESH_MesherHelper* helper,
2565 Handle(Geom_Surface) S)
2567 const vector<UVPtStruct>& uv_eb = quad->side[QUAD_BOTTOM_SIDE].GetUVPtStruct();
2568 const vector<UVPtStruct>& uv_et = quad->side[QUAD_TOP_SIDE ].GetUVPtStruct();
2569 double rBot = ( uv_eb.size() - 1 ) * uvPt.normParam;
2570 double rTop = ( uv_et.size() - 1 ) * uvPt.normParam;
2571 int iBot = int( rBot );
2572 int iTop = int( rTop );
2573 double xBot = uv_eb[ iBot ].normParam + ( rBot - iBot ) * ( uv_eb[ iBot+1 ].normParam - uv_eb[ iBot ].normParam );
2574 double xTop = uv_et[ iTop ].normParam + ( rTop - iTop ) * ( uv_et[ iTop+1 ].normParam - uv_et[ iTop ].normParam );
2575 double x = xBot + y * ( xTop - xBot );
2577 gp_UV uv = calcUV(/*x,y=*/x, y,
2578 /*a0,...=*/UVs[UV_A0], UVs[UV_A1], UVs[UV_A2], UVs[UV_A3],
2579 /*p0=*/quad->side[QUAD_BOTTOM_SIDE].grid->Value2d( x ).XY(),
2581 /*p2=*/quad->side[QUAD_TOP_SIDE ].grid->Value2d( x ).XY(),
2582 /*p3=*/UVs[ UV_L ]);
2583 gp_Pnt P = S->Value( uv.X(), uv.Y() );
2586 return helper->AddNode(P.X(), P.Y(), P.Z(), 0, uv.X(), uv.Y() );
2589 void reduce42( const vector<UVPtStruct>& curr_base,
2590 vector<UVPtStruct>& next_base,
2592 int & next_base_len,
2593 FaceQuadStruct::Ptr& quad,
2596 SMESH_MesherHelper* helper,
2597 Handle(Geom_Surface)& S)
2599 // add one "HH": nodes a,b,c,d,e and faces 1,2,3,4,5,6
2601 // .-----a-----b i + 1
2612 const SMDS_MeshNode*& Na = next_base[ ++next_base_len ].node;
2614 Na = makeNode( next_base[ next_base_len ], y, quad, UVs, helper, S );
2617 const SMDS_MeshNode*& Nb = next_base[ ++next_base_len ].node;
2619 Nb = makeNode( next_base[ next_base_len ], y, quad, UVs, helper, S );
2622 double u = (curr_base[j + 2].u + next_base[next_base_len - 2].u) / 2.0;
2623 double v = (curr_base[j + 2].v + next_base[next_base_len - 2].v) / 2.0;
2624 gp_Pnt P = S->Value(u,v);
2625 SMDS_MeshNode* Nc = helper->AddNode(P.X(), P.Y(), P.Z(), 0, u, v);
2628 u = (curr_base[j + 2].u + next_base[next_base_len - 1].u) / 2.0;
2629 v = (curr_base[j + 2].v + next_base[next_base_len - 1].v) / 2.0;
2631 SMDS_MeshNode* Nd = helper->AddNode(P.X(), P.Y(), P.Z(), 0, u, v);
2634 u = (curr_base[j + 2].u + next_base[next_base_len].u) / 2.0;
2635 v = (curr_base[j + 2].v + next_base[next_base_len].v) / 2.0;
2637 SMDS_MeshNode* Ne = helper->AddNode(P.X(), P.Y(), P.Z(), 0, u, v);
2640 helper->AddFace(curr_base[j + 0].node,
2641 curr_base[j + 1].node, Nc,
2642 next_base[next_base_len - 2].node);
2644 helper->AddFace(curr_base[j + 1].node,
2645 curr_base[j + 2].node, Nd, Nc);
2647 helper->AddFace(curr_base[j + 2].node,
2648 curr_base[j + 3].node, Ne, Nd);
2650 helper->AddFace(curr_base[j + 3].node,
2651 curr_base[j + 4].node, Nb, Ne);
2653 helper->AddFace(Nc, Nd, Na, next_base[next_base_len - 2].node);
2655 helper->AddFace(Nd, Ne, Nb, Na);
2658 void reduce31( const vector<UVPtStruct>& curr_base,
2659 vector<UVPtStruct>& next_base,
2661 int & next_base_len,
2662 FaceQuadStruct::Ptr& quad,
2665 SMESH_MesherHelper* helper,
2666 Handle(Geom_Surface)& S)
2668 // add one "H": nodes b,c,e and faces 1,2,4,5
2670 // .---------b i + 1
2681 const SMDS_MeshNode*& Nb = next_base[ ++next_base_len ].node;
2683 Nb = makeNode( next_base[ next_base_len ], y, quad, UVs, helper, S );
2686 double u1 = (curr_base[ j ].u + next_base[ next_base_len-1 ].u ) / 2.0;
2687 double u2 = (curr_base[ j+3 ].u + next_base[ next_base_len ].u ) / 2.0;
2688 double u3 = (u2 - u1) / 3.0;
2690 double v1 = (curr_base[ j ].v + next_base[ next_base_len-1 ].v ) / 2.0;
2691 double v2 = (curr_base[ j+3 ].v + next_base[ next_base_len ].v ) / 2.0;
2692 double v3 = (v2 - v1) / 3.0;
2696 gp_Pnt P = S->Value(u,v);
2697 SMDS_MeshNode* Nc = helper->AddNode( P.X(), P.Y(), P.Z(), 0, u, v );
2702 SMDS_MeshNode* Ne = helper->AddNode( P.X(), P.Y(), P.Z(), 0, u, v );
2706 helper->AddFace( curr_base[ j + 0 ].node,
2707 curr_base[ j + 1 ].node,
2709 next_base[ next_base_len - 1 ].node);
2711 helper->AddFace( curr_base[ j + 1 ].node,
2712 curr_base[ j + 2 ].node, Ne, Nc);
2714 helper->AddFace( curr_base[ j + 2 ].node,
2715 curr_base[ j + 3 ].node, Nb, Ne);
2717 helper->AddFace(Nc, Ne, Nb,
2718 next_base[ next_base_len - 1 ].node);
2721 typedef void (* PReduceFunction) ( const vector<UVPtStruct>& curr_base,
2722 vector<UVPtStruct>& next_base,
2724 int & next_base_len,
2725 FaceQuadStruct::Ptr & quad,
2728 SMESH_MesherHelper* helper,
2729 Handle(Geom_Surface)& S);
2733 //=======================================================================
2735 * Implementation of Reduced algorithm (meshing with quadrangles only)
2737 //=======================================================================
2739 bool StdMeshers_Quadrangle_2D::computeReduced (SMESH_Mesh & aMesh,
2740 const TopoDS_Face& aFace,
2741 FaceQuadStruct::Ptr quad)
2743 SMESHDS_Mesh * meshDS = aMesh.GetMeshDS();
2744 Handle(Geom_Surface) S = BRep_Tool::Surface(aFace);
2745 int i,j,geomFaceID = meshDS->ShapeToIndex(aFace);
2747 int nb = quad->side[0].NbPoints(); // bottom
2748 int nr = quad->side[1].NbPoints(); // right
2749 int nt = quad->side[2].NbPoints(); // top
2750 int nl = quad->side[3].NbPoints(); // left
2752 // Simple Reduce 10->8->6->4 (3 steps) Multiple Reduce 10->4 (1 step)
2754 // .-----.-----.-----.-----. .-----.-----.-----.-----.
2755 // | / \ | / \ | | / \ | / \ |
2756 // | / .--.--. \ | | / \ | / \ |
2757 // | / / | \ \ | | / .----.----. \ |
2758 // .---.---.---.---.---.---. | / / \ | / \ \ |
2759 // | / / \ | / \ \ | | / / \ | / \ \ |
2760 // | / / .-.-. \ \ | | / / .---.---. \ \ |
2761 // | / / / | \ \ \ | | / / / \ | / \ \ \ |
2762 // .--.--.--.--.--.--.--.--. | / / / \ | / \ \ \ |
2763 // | / / / \ | / \ \ \ | | / / / .-.-. \ \ \ |
2764 // | / / / .-.-. \ \ \ | | / / / / | \ \ \ \ |
2765 // | / / / / | \ \ \ \ | | / / / / | \ \ \ \ |
2766 // .-.-.-.--.--.--.--.-.-.-. .-.-.-.--.--.--.--.-.-.-.
2768 bool MultipleReduce = false;
2780 else if (nb == nt) {
2781 nr1 = nb; // and == nt
2795 // number of rows and columns
2796 int nrows = nr1 - 1;
2797 int ncol_top = nt1 - 1;
2798 int ncol_bot = nb1 - 1;
2799 // number of rows needed to reduce ncol_bot to ncol_top using simple 3->1 "tree" (see below)
2801 int( ceil( log( double(ncol_bot) / ncol_top) / log( 3.))); // = log x base 3
2802 if ( nrows < nrows_tree31 )
2804 MultipleReduce = true;
2805 error( COMPERR_WARNING,
2806 SMESH_Comment("To use 'Reduced' transition, "
2807 "number of face rows should be at least ")
2808 << nrows_tree31 << ". Actual number of face rows is " << nrows << ". "
2809 "'Quadrangle preference (reversed)' transion has been used.");
2813 if (MultipleReduce) { // == computeQuadPref QUAD_QUADRANGLE_PREF_REVERSED
2814 //==================================================
2815 int dh = abs(nb-nt);
2816 int dv = abs(nr-nl);
2820 // it is a base case => not shift quad but may be replacement is need
2824 // we have to shift quad on 2
2830 // we have to shift quad on 1
2834 // we have to shift quad on 3
2839 nb = quad->side[0].NbPoints();
2840 nr = quad->side[1].NbPoints();
2841 nt = quad->side[2].NbPoints();
2842 nl = quad->side[3].NbPoints();
2845 int nbh = Max(nb,nt);
2846 int nbv = Max(nr,nl);
2859 const vector<UVPtStruct>& uv_eb = quad->side[0].GetUVPtStruct(true,0);
2860 const vector<UVPtStruct>& uv_er = quad->side[1].GetUVPtStruct(false,1);
2861 const vector<UVPtStruct>& uv_et = quad->side[2].GetUVPtStruct(true,1);
2862 const vector<UVPtStruct>& uv_el = quad->side[3].GetUVPtStruct(false,0);
2864 if (uv_eb.size() != nb || uv_er.size() != nr || uv_et.size() != nt || uv_el.size() != nl)
2865 return error(COMPERR_BAD_INPUT_MESH);
2867 // arrays for normalized params
2868 TColStd_SequenceOfReal npb, npr, npt, npl;
2869 for (j = 0; j < nb; j++) {
2870 npb.Append(uv_eb[j].normParam);
2872 for (i = 0; i < nr; i++) {
2873 npr.Append(uv_er[i].normParam);
2875 for (j = 0; j < nt; j++) {
2876 npt.Append(uv_et[j].normParam);
2878 for (i = 0; i < nl; i++) {
2879 npl.Append(uv_el[i].normParam);
2883 // orientation of face and 3 main domain for future faces
2889 // left | | | | rigth
2896 // add some params to right and left after the first param
2899 double dpr = (npr.Value(2) - npr.Value(1))/(dr+1);
2900 for (i=1; i<=dr; i++) {
2901 npr.InsertAfter(1,npr.Value(2)-dpr);
2905 dpr = (npl.Value(2) - npl.Value(1))/(dl+1);
2906 for (i=1; i<=dl; i++) {
2907 npl.InsertAfter(1,npl.Value(2)-dpr);
2910 gp_XY a0 (uv_eb.front().u, uv_eb.front().v);
2911 gp_XY a1 (uv_eb.back().u, uv_eb.back().v);
2912 gp_XY a2 (uv_et.back().u, uv_et.back().v);
2913 gp_XY a3 (uv_et.front().u, uv_et.front().v);
2915 int nnn = Min(nr,nl);
2916 // auxilary sequence of XY for creation of nodes
2917 // in the bottom part of central domain
2918 // it's length must be == nbv-nnn-1
2919 TColgp_SequenceOfXY UVL;
2920 TColgp_SequenceOfXY UVR;
2921 //==================================================
2923 // step1: create faces for left domain
2924 StdMeshers_Array2OfNode NodesL(1,dl+1,1,nl);
2926 for (j=1; j<=nl; j++)
2927 NodesL.SetValue(1,j,uv_el[j-1].node);
2930 for (i=1; i<=dl; i++)
2931 NodesL.SetValue(i+1,nl,uv_et[i].node);
2932 // create and add needed nodes
2933 TColgp_SequenceOfXY UVtmp;
2934 for (i=1; i<=dl; i++) {
2935 double x0 = npt.Value(i+1);
2938 double y0 = npl.Value(i+1);
2939 double y1 = npr.Value(i+1);
2940 gp_UV UV = calcUV(x0, x1, y0, y1, quad, a0, a1, a2, a3);
2941 gp_Pnt P = S->Value(UV.X(),UV.Y());
2942 SMDS_MeshNode * N = meshDS->AddNode(P.X(), P.Y(), P.Z());
2943 meshDS->SetNodeOnFace(N, geomFaceID, UV.X(), UV.Y());
2944 NodesL.SetValue(i+1,1,N);
2945 if (UVL.Length()<nbv-nnn-1) UVL.Append(UV);
2947 for (j=2; j<nl; j++) {
2948 double y0 = npl.Value(dl+j);
2949 double y1 = npr.Value(dl+j);
2950 gp_UV UV = calcUV(x0, x1, y0, y1, quad, a0, a1, a2, a3);
2951 gp_Pnt P = S->Value(UV.X(),UV.Y());
2952 SMDS_MeshNode* N = meshDS->AddNode(P.X(), P.Y(), P.Z());
2953 meshDS->SetNodeOnFace(N, geomFaceID, UV.X(), UV.Y());
2954 NodesL.SetValue(i+1,j,N);
2955 if (i==dl) UVtmp.Append(UV);
2958 for (i=1; i<=UVtmp.Length() && UVL.Length()<nbv-nnn-1; i++) {
2959 UVL.Append(UVtmp.Value(i));
2962 for (i=1; i<=dl; i++) {
2963 for (j=1; j<nl; j++) {
2965 myHelper->AddFace(NodesL.Value(i,j), NodesL.Value(i+1,j),
2966 NodesL.Value(i+1,j+1), NodesL.Value(i,j+1));
2967 if (F) meshDS->SetMeshElementOnShape(F, geomFaceID);
2972 // fill UVL using c2d
2973 for (i=1; i<npl.Length() && UVL.Length()<nbv-nnn-1; i++) {
2974 UVL.Append(gp_UV (uv_el[i].u, uv_el[i].v));
2978 // step2: create faces for right domain
2979 StdMeshers_Array2OfNode NodesR(1,dr+1,1,nr);
2981 for (j=1; j<=nr; j++)
2982 NodesR.SetValue(1,j,uv_er[nr-j].node);
2985 for (i=1; i<=dr; i++)
2986 NodesR.SetValue(i+1,1,uv_et[nt-1-i].node);
2987 // create and add needed nodes
2988 TColgp_SequenceOfXY UVtmp;
2989 for (i=1; i<=dr; i++) {
2990 double x0 = npt.Value(nt-i);
2993 double y0 = npl.Value(i+1);
2994 double y1 = npr.Value(i+1);
2995 gp_UV UV = calcUV(x0, x1, y0, y1, quad, a0, a1, a2, a3);
2996 gp_Pnt P = S->Value(UV.X(),UV.Y());
2997 SMDS_MeshNode * N = meshDS->AddNode(P.X(), P.Y(), P.Z());
2998 meshDS->SetNodeOnFace(N, geomFaceID, UV.X(), UV.Y());
2999 NodesR.SetValue(i+1,nr,N);
3000 if (UVR.Length()<nbv-nnn-1) UVR.Append(UV);
3002 for (j=2; j<nr; j++) {
3003 double y0 = npl.Value(nbv-j+1);
3004 double y1 = npr.Value(nbv-j+1);
3005 gp_UV UV = calcUV(x0, x1, y0, y1, quad, a0, a1, a2, a3);
3006 gp_Pnt P = S->Value(UV.X(),UV.Y());
3007 SMDS_MeshNode* N = meshDS->AddNode(P.X(), P.Y(), P.Z());
3008 meshDS->SetNodeOnFace(N, geomFaceID, UV.X(), UV.Y());
3009 NodesR.SetValue(i+1,j,N);
3010 if (i==dr) UVtmp.Prepend(UV);
3013 for (i=1; i<=UVtmp.Length() && UVR.Length()<nbv-nnn-1; i++) {
3014 UVR.Append(UVtmp.Value(i));
3017 for (i=1; i<=dr; i++) {
3018 for (j=1; j<nr; j++) {
3020 myHelper->AddFace(NodesR.Value(i,j), NodesR.Value(i+1,j),
3021 NodesR.Value(i+1,j+1), NodesR.Value(i,j+1));
3022 if (F) meshDS->SetMeshElementOnShape(F, geomFaceID);
3027 // fill UVR using c2d
3028 for (i=1; i<npr.Length() && UVR.Length()<nbv-nnn-1; i++) {
3029 UVR.Append(gp_UV(uv_er[i].u, uv_er[i].v));
3033 // step3: create faces for central domain
3034 StdMeshers_Array2OfNode NodesC(1,nb,1,nbv);
3035 // add first line using NodesL
3036 for (i=1; i<=dl+1; i++)
3037 NodesC.SetValue(1,i,NodesL(i,1));
3038 for (i=2; i<=nl; i++)
3039 NodesC.SetValue(1,dl+i,NodesL(dl+1,i));
3040 // add last line using NodesR
3041 for (i=1; i<=dr+1; i++)
3042 NodesC.SetValue(nb,i,NodesR(i,nr));
3043 for (i=1; i<nr; i++)
3044 NodesC.SetValue(nb,dr+i+1,NodesR(dr+1,nr-i));
3045 // add top nodes (last columns)
3046 for (i=dl+2; i<nbh-dr; i++)
3047 NodesC.SetValue(i-dl,nbv,uv_et[i-1].node);
3048 // add bottom nodes (first columns)
3049 for (i=2; i<nb; i++)
3050 NodesC.SetValue(i,1,uv_eb[i-1].node);
3052 // create and add needed nodes
3053 // add linear layers
3054 for (i=2; i<nb; i++) {
3055 double x0 = npt.Value(dl+i);
3057 for (j=1; j<nnn; j++) {
3058 double y0 = npl.Value(nbv-nnn+j);
3059 double y1 = npr.Value(nbv-nnn+j);
3060 gp_UV UV = calcUV(x0, x1, y0, y1, quad, a0, a1, a2, a3);
3061 gp_Pnt P = S->Value(UV.X(),UV.Y());
3062 SMDS_MeshNode* N = meshDS->AddNode(P.X(), P.Y(), P.Z());
3063 meshDS->SetNodeOnFace(N, geomFaceID, UV.X(), UV.Y());
3064 NodesC.SetValue(i,nbv-nnn+j,N);
3067 // add diagonal layers
3068 for (i=1; i<nbv-nnn; i++) {
3069 double du = UVR.Value(i).X() - UVL.Value(i).X();
3070 double dv = UVR.Value(i).Y() - UVL.Value(i).Y();
3071 for (j=2; j<nb; j++) {
3072 double u = UVL.Value(i).X() + du*npb.Value(j);
3073 double v = UVL.Value(i).Y() + dv*npb.Value(j);
3074 gp_Pnt P = S->Value(u,v);
3075 SMDS_MeshNode* N = meshDS->AddNode(P.X(), P.Y(), P.Z());
3076 meshDS->SetNodeOnFace(N, geomFaceID, u, v);
3077 NodesC.SetValue(j,i+1,N);
3081 for (i=1; i<nb; i++) {
3082 for (j=1; j<nbv; j++) {
3084 myHelper->AddFace(NodesC.Value(i,j), NodesC.Value(i+1,j),
3085 NodesC.Value(i+1,j+1), NodesC.Value(i,j+1));
3086 if (F) meshDS->SetMeshElementOnShape(F, geomFaceID);
3089 } // end Multiple Reduce implementation
3090 else { // Simple Reduce (!MultipleReduce)
3091 //=========================================================
3094 // it is a base case => not shift quad
3095 //shiftQuad(quad,0,true);
3098 // we have to shift quad on 2
3104 // we have to shift quad on 1
3108 // we have to shift quad on 3
3113 nb = quad->side[0].NbPoints();
3114 nr = quad->side[1].NbPoints();
3115 nt = quad->side[2].NbPoints();
3116 nl = quad->side[3].NbPoints();
3118 // number of rows and columns
3119 int nrows = nr - 1; // and also == nl - 1
3120 int ncol_top = nt - 1;
3121 int ncol_bot = nb - 1;
3122 int npair_top = ncol_top / 2;
3123 // maximum number of bottom elements for "linear" simple reduce 4->2
3124 int max_lin42 = ncol_top + npair_top * 2 * nrows;
3125 // maximum number of bottom elements for "linear" simple reduce 3->1
3126 int max_lin31 = ncol_top + ncol_top * 2 * nrows;
3127 // maximum number of bottom elements for "tree" simple reduce 4->2
3129 // number of rows needed to reduce ncol_bot to ncol_top using simple 4->2 "tree"
3130 int nrows_tree42 = int( log( (double)(ncol_bot / ncol_top) )/log((double)2) ); // needed to avoid overflow at pow(2) while computing max_tree42
3131 if (nrows_tree42 < nrows) {
3132 max_tree42 = npair_top * pow(2.0, nrows + 1);
3133 if ( ncol_top > npair_top * 2 ) {
3134 int delta = ncol_bot - max_tree42;
3135 for (int irow = 1; irow < nrows; irow++) {
3136 int nfour = delta / 4;
3139 if (delta <= (ncol_top - npair_top * 2))
3140 max_tree42 = ncol_bot;
3143 // maximum number of bottom elements for "tree" simple reduce 3->1
3144 //int max_tree31 = ncol_top * pow(3.0, nrows);
3145 bool is_lin_31 = false;
3146 bool is_lin_42 = false;
3147 bool is_tree_31 = false;
3148 bool is_tree_42 = false;
3149 int max_lin = max_lin42;
3150 if (ncol_bot > max_lin42) {
3151 if (ncol_bot <= max_lin31) {
3153 max_lin = max_lin31;
3157 // if ncol_bot is a 3*n or not 2*n
3158 if ((ncol_bot/3)*3 == ncol_bot || (ncol_bot/2)*2 != ncol_bot) {
3160 max_lin = max_lin31;
3166 if (ncol_bot > max_lin) { // not "linear"
3167 is_tree_31 = (ncol_bot > max_tree42);
3168 if (ncol_bot <= max_tree42) {
3169 if ((ncol_bot/3)*3 == ncol_bot || (ncol_bot/2)*2 != ncol_bot) {
3178 const vector<UVPtStruct>& uv_eb = quad->side[0].GetUVPtStruct(true,0);
3179 const vector<UVPtStruct>& uv_er = quad->side[1].GetUVPtStruct(false,1);
3180 const vector<UVPtStruct>& uv_et = quad->side[2].GetUVPtStruct(true,1);
3181 const vector<UVPtStruct>& uv_el = quad->side[3].GetUVPtStruct(false,0);
3183 if (uv_eb.size() != nb || uv_er.size() != nr || uv_et.size() != nt || uv_el.size() != nl)
3184 return error(COMPERR_BAD_INPUT_MESH);
3186 myHelper->SetElementsOnShape( true );
3188 gp_UV uv[ UV_SIZE ];
3189 uv[ UV_A0 ].SetCoord( uv_eb.front().u, uv_eb.front().v);
3190 uv[ UV_A1 ].SetCoord( uv_eb.back().u, uv_eb.back().v );
3191 uv[ UV_A2 ].SetCoord( uv_et.back().u, uv_et.back().v );
3192 uv[ UV_A3 ].SetCoord( uv_et.front().u, uv_et.front().v);
3194 vector<UVPtStruct> curr_base = uv_eb, next_base;
3196 UVPtStruct nullUVPtStruct; nullUVPtStruct.node = 0;
3198 int curr_base_len = nb;
3199 int next_base_len = 0;
3202 { // ------------------------------------------------------------------
3203 // New algorithm implemented by request of IPAL22856
3204 // "2D quadrangle mesher of reduced type works wrong"
3205 // http://bugtracker.opencascade.com/show_bug.cgi?id=22856
3207 // the algorithm is following: all reduces are centred in horizontal
3208 // direction and are distributed among all rows
3210 if (ncol_bot > max_tree42) {
3214 if ((ncol_top/3)*3 == ncol_top ) {
3222 const int col_top_size = is_lin_42 ? 2 : 1;
3223 const int col_base_size = is_lin_42 ? 4 : 3;
3225 // Compute nb of "columns" (like in "linear" simple reducing) in all rows
3227 vector<int> nb_col_by_row;
3229 int delta_all = nb - nt;
3230 int delta_one_col = nrows * 2;
3231 int nb_col = delta_all / delta_one_col;
3232 int remainder = delta_all - nb_col * delta_one_col;
3233 if (remainder > 0) {
3236 if ( nb_col * col_top_size >= nt ) // == "tree" reducing situation
3238 // top row is full (all elements reduced), add "columns" one by one
3239 // in rows below until all bottom elements are reduced
3240 nb_col = ( nt - 1 ) / col_top_size;
3241 nb_col_by_row.resize( nrows, nb_col );
3242 int nbrows_not_full = nrows - 1;
3243 int cur_top_size = nt - 1;
3244 remainder = delta_all - nb_col * delta_one_col;
3245 while ( remainder > 0 )
3247 delta_one_col = nbrows_not_full * 2;
3248 int nb_col_add = remainder / delta_one_col;
3249 cur_top_size += 2 * nb_col_by_row[ nbrows_not_full ];
3250 int nb_col_free = cur_top_size / col_top_size - nb_col_by_row[ nbrows_not_full-1 ];
3251 if ( nb_col_add > nb_col_free )
3252 nb_col_add = nb_col_free;
3253 for ( int irow = 0; irow < nbrows_not_full; ++irow )
3254 nb_col_by_row[ irow ] += nb_col_add;
3256 remainder -= nb_col_add * delta_one_col;
3259 else // == "linear" reducing situation
3261 nb_col_by_row.resize( nrows, nb_col );
3263 for ( int irow = remainder / 2; irow < nrows; ++irow )
3264 nb_col_by_row[ irow ]--;
3269 PReduceFunction reduceFunction = & ( is_lin_42 ? reduce42 : reduce31 );
3271 const int reduce_grp_size = is_lin_42 ? 4 : 3;
3273 for (i = 1; i < nr; i++) // layer by layer
3275 nb_col = nb_col_by_row[ i-1 ];
3276 int nb_next = curr_base_len - nb_col * 2;
3277 if (nb_next < nt) nb_next = nt;
3279 const double y = uv_el[ i ].normParam;
3281 if ( i + 1 == nr ) // top
3288 next_base.resize( nb_next, nullUVPtStruct );
3289 next_base.front() = uv_el[i];
3290 next_base.back() = uv_er[i];
3292 // compute normalized param u
3293 double du = 1. / ( nb_next - 1 );
3294 next_base[0].normParam = 0.;
3295 for ( j = 1; j < nb_next; ++j )
3296 next_base[j].normParam = next_base[j-1].normParam + du;
3298 uv[ UV_L ].SetCoord( next_base.front().u, next_base.front().v );
3299 uv[ UV_R ].SetCoord( next_base.back().u, next_base.back().v );
3301 int free_left = ( curr_base_len - 1 - nb_col * col_base_size ) / 2;
3302 int free_middle = curr_base_len - 1 - nb_col * col_base_size - 2 * free_left;
3304 // not reduced left elements
3305 for (j = 0; j < free_left; j++)
3308 const SMDS_MeshNode*& Nf = next_base[++next_base_len].node;
3310 Nf = makeNode( next_base[ next_base_len ], y, quad, uv, myHelper, S );
3312 myHelper->AddFace(curr_base[ j ].node,
3313 curr_base[ j+1 ].node,
3315 next_base[ next_base_len-1 ].node);
3318 for (int icol = 1; icol <= nb_col; icol++)
3321 reduceFunction( curr_base, next_base, j, next_base_len, quad, uv, y, myHelper, S );
3323 j += reduce_grp_size;
3325 // elements in the middle of "columns" added for symmetry
3326 if ( free_middle > 0 && ( nb_col % 2 == 0 ) && icol == nb_col / 2 )
3328 for (int imiddle = 1; imiddle <= free_middle; imiddle++) {
3329 // f (i + 1, j + imiddle)
3330 const SMDS_MeshNode*& Nf = next_base[++next_base_len].node;
3332 Nf = makeNode( next_base[ next_base_len ], y, quad, uv, myHelper, S );
3334 myHelper->AddFace(curr_base[ j-1+imiddle ].node,
3335 curr_base[ j +imiddle ].node,
3337 next_base[ next_base_len-1 ].node);
3343 // not reduced right elements
3344 for (; j < curr_base_len-1; j++) {
3346 const SMDS_MeshNode*& Nf = next_base[++next_base_len].node;
3348 Nf = makeNode( next_base[ next_base_len ], y, quad, uv, myHelper, S );
3350 myHelper->AddFace(curr_base[ j ].node,
3351 curr_base[ j+1 ].node,
3353 next_base[ next_base_len-1 ].node);
3356 curr_base_len = next_base_len + 1;
3358 curr_base.swap( next_base );
3362 else if ( is_tree_42 || is_tree_31 )
3364 // "tree" simple reduce "42": 2->4->8->16->32->...
3366 // .-------------------------------.-------------------------------. nr
3368 // | \ .---------------.---------------. / |
3370 // .---------------.---------------.---------------.---------------.
3371 // | \ | / | \ | / |
3372 // | \ .-------.-------. / | \ .-------.-------. / |
3373 // | | | | | | | | |
3374 // .-------.-------.-------.-------.-------.-------.-------.-------. i
3375 // |\ | /|\ | /|\ | /|\ | /|
3376 // | \.---.---./ | \.---.---./ | \.---.---./ | \.---.---./ |
3377 // | | | | | | | | | | | | | | | | |
3378 // .---.---.---.---.---.---.---.---.---.---.---.---.---.---.---.---.
3379 // |\ | /|\ | /|\ | /|\ | /|\ | /|\ | /|\ | /|\ | /|
3380 // | .-.-. | .-.-. | .-.-. | .-.-. | .-.-. | .-.-. | .-.-. | .-.-. |
3381 // | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
3382 // .-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-. 1
3385 // "tree" simple reduce "31": 1->3->9->27->...
3387 // .-----------------------------------------------------. nr
3389 // | .-----------------. |
3391 // .-----------------.-----------------.-----------------.
3392 // | \ / | \ / | \ / |
3393 // | .-----. | .-----. | .-----. | i
3394 // | | | | | | | | | |
3395 // .-----.-----.-----.-----.-----.-----.-----.-----.-----.
3396 // |\ /|\ /|\ /|\ /|\ /|\ /|\ /|\ /|\ /|
3397 // | .-. | .-. | .-. | .-. | .-. | .-. | .-. | .-. | .-. |
3398 // | | | | | | | | | | | | | | | | | | | | | | | | | | | |
3399 // .-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-. 1
3402 PReduceFunction reduceFunction = & ( is_tree_42 ? reduce42 : reduce31 );
3404 const int reduce_grp_size = is_tree_42 ? 4 : 3;
3406 for (i = 1; i < nr; i++) // layer by layer
3408 // to stop reducing, if number of nodes reaches nt
3409 int delta = curr_base_len - nt;
3411 // to calculate normalized parameter, we must know number of points in next layer
3412 int nb_reduce_groups = (curr_base_len - 1) / reduce_grp_size;
3413 int nb_next = nb_reduce_groups * (reduce_grp_size-2) + (curr_base_len - nb_reduce_groups*reduce_grp_size);
3414 if (nb_next < nt) nb_next = nt;
3416 const double y = uv_el[ i ].normParam;
3418 if ( i + 1 == nr ) // top
3425 next_base.resize( nb_next, nullUVPtStruct );
3426 next_base.front() = uv_el[i];
3427 next_base.back() = uv_er[i];
3429 // compute normalized param u
3430 double du = 1. / ( nb_next - 1 );
3431 next_base[0].normParam = 0.;
3432 for ( j = 1; j < nb_next; ++j )
3433 next_base[j].normParam = next_base[j-1].normParam + du;
3435 uv[ UV_L ].SetCoord( next_base.front().u, next_base.front().v );
3436 uv[ UV_R ].SetCoord( next_base.back().u, next_base.back().v );
3438 for (j = 0; j+reduce_grp_size < curr_base_len && delta > 0; j+=reduce_grp_size, delta-=2)
3440 reduceFunction( curr_base, next_base, j, next_base_len, quad, uv, y, myHelper, S );
3443 // not reduced side elements (if any)
3444 for (; j < curr_base_len-1; j++)
3447 const SMDS_MeshNode*& Nf = next_base[++next_base_len].node;
3449 Nf = makeNode( next_base[ next_base_len ], y, quad, uv, myHelper, S );
3451 myHelper->AddFace(curr_base[ j ].node,
3452 curr_base[ j+1 ].node,
3454 next_base[ next_base_len-1 ].node);
3456 curr_base_len = next_base_len + 1;
3458 curr_base.swap( next_base );
3460 } // end "tree" simple reduce
3462 else if ( is_lin_42 || is_lin_31 ) {
3463 // "linear" simple reduce "31": 2->6->10->14
3465 // .-----------------------------.-----------------------------. nr
3467 // | .---------. | .---------. |
3469 // .---------.---------.---------.---------.---------.---------.
3470 // | / \ / \ | / \ / \ |
3471 // | / .-----. \ | / .-----. \ | i
3472 // | / | | \ | / | | \ |
3473 // .-----.-----.-----.-----.-----.-----.-----.-----.-----.-----.
3474 // | / / \ / \ \ | / / \ / \ \ |
3475 // | / / .-. \ \ | / / .-. \ \ |
3476 // | / / / \ \ \ | / / / \ \ \ |
3477 // .--.----.---.-----.---.-----.-.--.----.---.-----.---.-----.-. 1
3480 // "linear" simple reduce "42": 4->8->12->16
3482 // .---------------.---------------.---------------.---------------. nr
3483 // | \ | / | \ | / |
3484 // | \ .-------.-------. / | \ .-------.-------. / |
3485 // | | | | | | | | |
3486 // .-------.-------.-------.-------.-------.-------.-------.-------.
3487 // | / \ | / \ | / \ | / \ |
3488 // | / \.----.----./ \ | / \.----.----./ \ | i
3489 // | / | | | \ | / | | | \ |
3490 // .-----.----.----.----.----.-----.-----.----.----.----.----.-----.
3491 // | / / \ | / \ \ | / / \ | / \ \ |
3492 // | / / .-.-. \ \ | / / .-.-. \ \ |
3493 // | / / / | \ \ \ | / / / | \ \ \ |
3494 // .---.---.---.---.---.---.---.---.---.---.---.---.---.---.---.---. 1
3497 // nt = 5, nb = 7, nr = 4
3498 //int delta_all = 2;
3499 //int delta_one_col = 6;
3501 //int remainder = 2;
3502 //if (remainder > 0) nb_col++;
3504 //int free_left = 1;
3506 //int free_middle = 4;
3508 int delta_all = nb - nt;
3509 int delta_one_col = (nr - 1) * 2;
3510 int nb_col = delta_all / delta_one_col;
3511 int remainder = delta_all - nb_col * delta_one_col;
3512 if (remainder > 0) {
3515 const int col_top_size = is_lin_42 ? 2 : 1;
3516 int free_left = ((nt - 1) - nb_col * col_top_size) / 2;
3517 free_left += nr - 2;
3518 int free_middle = (nr - 2) * 2;
3519 if (remainder > 0 && nb_col == 1) {
3520 int nb_rows_short_col = remainder / 2;
3521 int nb_rows_thrown = (nr - 1) - nb_rows_short_col;
3522 free_left -= nb_rows_thrown;
3525 // nt = 5, nb = 17, nr = 4
3526 //int delta_all = 12;
3527 //int delta_one_col = 6;
3529 //int remainder = 0;
3530 //int free_left = 2;
3531 //int free_middle = 4;
3533 PReduceFunction reduceFunction = & ( is_lin_42 ? reduce42 : reduce31 );
3535 const int reduce_grp_size = is_lin_42 ? 4 : 3;
3537 for (i = 1; i < nr; i++, free_middle -= 2, free_left -= 1) // layer by layer
3539 // to calculate normalized parameter, we must know number of points in next layer
3540 int nb_next = curr_base_len - nb_col * 2;
3541 if (remainder > 0 && i > remainder / 2)
3542 // take into account short "column"
3544 if (nb_next < nt) nb_next = nt;
3546 const double y = uv_el[ i ].normParam;
3548 if ( i + 1 == nr ) // top
3555 next_base.resize( nb_next, nullUVPtStruct );
3556 next_base.front() = uv_el[i];
3557 next_base.back() = uv_er[i];
3559 // compute normalized param u
3560 double du = 1. / ( nb_next - 1 );
3561 next_base[0].normParam = 0.;
3562 for ( j = 1; j < nb_next; ++j )
3563 next_base[j].normParam = next_base[j-1].normParam + du;
3565 uv[ UV_L ].SetCoord( next_base.front().u, next_base.front().v );
3566 uv[ UV_R ].SetCoord( next_base.back().u, next_base.back().v );
3568 // not reduced left elements
3569 for (j = 0; j < free_left; j++)
3572 const SMDS_MeshNode*& Nf = next_base[++next_base_len].node;
3574 Nf = makeNode( next_base[ next_base_len ], y, quad, uv, myHelper, S );
3576 myHelper->AddFace(curr_base[ j ].node,
3577 curr_base[ j+1 ].node,
3579 next_base[ next_base_len-1 ].node);
3582 for (int icol = 1; icol <= nb_col; icol++) {
3584 if (remainder > 0 && icol == nb_col && i > remainder / 2)
3585 // stop short "column"
3589 reduceFunction( curr_base, next_base, j, next_base_len, quad, uv, y, myHelper, S );
3591 j += reduce_grp_size;
3593 // not reduced middle elements
3594 if (icol < nb_col) {
3595 if (remainder > 0 && icol == nb_col - 1 && i > remainder / 2)
3596 // pass middle elements before stopped short "column"
3599 int free_add = free_middle;
3600 if (remainder > 0 && icol == nb_col - 1)
3601 // next "column" is short
3602 free_add -= (nr - 1) - (remainder / 2);
3604 for (int imiddle = 1; imiddle <= free_add; imiddle++) {
3605 // f (i + 1, j + imiddle)
3606 const SMDS_MeshNode*& Nf = next_base[++next_base_len].node;
3608 Nf = makeNode( next_base[ next_base_len ], y, quad, uv, myHelper, S );
3610 myHelper->AddFace(curr_base[ j-1+imiddle ].node,
3611 curr_base[ j +imiddle ].node,
3613 next_base[ next_base_len-1 ].node);
3619 // not reduced right elements
3620 for (; j < curr_base_len-1; j++) {
3622 const SMDS_MeshNode*& Nf = next_base[++next_base_len].node;
3624 Nf = makeNode( next_base[ next_base_len ], y, quad, uv, myHelper, S );
3626 myHelper->AddFace(curr_base[ j ].node,
3627 curr_base[ j+1 ].node,
3629 next_base[ next_base_len-1 ].node);
3632 curr_base_len = next_base_len + 1;
3634 curr_base.swap( next_base );
3637 } // end "linear" simple reduce
3642 } // end Simple Reduce implementation
3648 //================================================================================
3649 namespace // data for smoothing
3652 // --------------------------------------------------------------------------------
3654 * \brief Structure used to check validity of node position after smoothing.
3655 * It holds two nodes connected to a smoothed node and belonging to
3662 TTriangle( TSmoothNode* n1=0, TSmoothNode* n2=0 ): _n1(n1), _n2(n2) {}
3664 inline bool IsForward( gp_UV uv ) const;
3666 // --------------------------------------------------------------------------------
3668 * \brief Data of a smoothed node
3674 vector< TTriangle > _triangles; // if empty, then node is not movable
3676 // --------------------------------------------------------------------------------
3677 inline bool TTriangle::IsForward( gp_UV uv ) const
3679 gp_Vec2d v1( uv, _n1->_uv ), v2( uv, _n2->_uv );
3685 //================================================================================
3687 * \brief Set UV of nodes on degenerated VERTEXes in the middle of degenerated EDGE
3689 * WARNING: this method must be called AFTER retrieving UVPtStruct's from quad
3691 //================================================================================
3693 void StdMeshers_Quadrangle_2D::updateDegenUV(FaceQuadStruct::Ptr quad)
3697 // Set UV of nodes on degenerated VERTEXes in the middle of degenerated EDGE
3698 // --------------------------------------------------------------------------
3699 for ( unsigned i = 0; i < quad->side.size(); ++i )
3701 const vector<UVPtStruct>& uvVec = quad->side[i].GetUVPtStruct();
3703 // find which end of the side is on degenerated shape
3705 if ( myHelper->IsDegenShape( uvVec[0].node->getshapeId() ))
3707 else if ( myHelper->IsDegenShape( uvVec.back().node->getshapeId() ))
3708 degenInd = uvVec.size() - 1;
3712 // find another side sharing the degenerated shape
3713 bool isPrev = ( degenInd == 0 );
3714 if ( i >= QUAD_TOP_SIDE )
3716 int i2 = ( isPrev ? ( i + 3 ) : ( i + 1 )) % 4;
3717 const vector<UVPtStruct>& uvVec2 = quad->side[ i2 ].GetUVPtStruct();
3719 if ( uvVec[ degenInd ].node == uvVec2.front().node )
3721 else if ( uvVec[ degenInd ].node == uvVec2.back().node )
3722 degenInd2 = uvVec2.size() - 1;
3724 throw SALOME_Exception( LOCALIZED( "Logical error" ));
3726 // move UV in the middle
3727 uvPtStruct& uv1 = const_cast<uvPtStruct&>( uvVec [ degenInd ]);
3728 uvPtStruct& uv2 = const_cast<uvPtStruct&>( uvVec2[ degenInd2 ]);
3729 uv1.u = uv2.u = 0.5 * ( uv1.u + uv2.u );
3730 uv1.v = uv2.v = 0.5 * ( uv1.v + uv2.v );
3733 else if ( quad->side.size() == 4 && myQuadType == QUAD_STANDARD)
3735 // Set number of nodes on a degenerated side to be same as on an opposite side
3736 // ----------------------------------------------------------------------------
3737 for ( unsigned i = 0; i < quad->side.size(); ++i )
3739 StdMeshers_FaceSidePtr degSide = quad->side[i];
3740 if ( !myHelper->IsDegenShape( degSide->EdgeID(0) ))
3742 StdMeshers_FaceSidePtr oppSide = quad->side[( i+2 ) % quad->side.size() ];
3743 if ( degSide->NbSegments() == oppSide->NbSegments() )
3746 // make new side data
3747 const vector<UVPtStruct>& uvVecDegOld = degSide->GetUVPtStruct();
3748 const SMDS_MeshNode* n = uvVecDegOld[0].node;
3749 Handle(Geom2d_Curve) c2d = degSide->Curve2d(0);
3750 double f = degSide->FirstU(0), l = degSide->LastU(0);
3751 gp_Pnt2d p1 = uvVecDegOld.front().UV();
3752 gp_Pnt2d p2 = uvVecDegOld.back().UV();
3754 quad->side[i] = StdMeshers_FaceSide::New( oppSide.get(), n, &p1, &p2, c2d, f, l );
3758 //================================================================================
3760 * \brief Perform smoothing of 2D elements on a FACE with ignored degenerated EDGE
3762 //================================================================================
3764 void StdMeshers_Quadrangle_2D::smooth (FaceQuadStruct::Ptr quad)
3766 if ( !myNeedSmooth ) return;
3768 // Get nodes to smooth
3770 // TODO: do not smooth fixed nodes
3772 typedef map< const SMDS_MeshNode*, TSmoothNode, TIDCompare > TNo2SmooNoMap;
3773 TNo2SmooNoMap smooNoMap;
3775 const TopoDS_Face& geomFace = TopoDS::Face( myHelper->GetSubShape() );
3776 Handle(Geom_Surface) surface = BRep_Tool::Surface( geomFace );
3777 double U1, U2, V1, V2;
3778 surface->Bounds(U1, U2, V1, V2);
3779 GeomAPI_ProjectPointOnSurf proj;
3780 proj.Init( surface, U1, U2, V1, V2, BRep_Tool::Tolerance( geomFace ) );
3782 SMESHDS_Mesh* meshDS = myHelper->GetMeshDS();
3783 SMESHDS_SubMesh* fSubMesh = meshDS->MeshElements( geomFace );
3784 SMDS_NodeIteratorPtr nIt = fSubMesh->GetNodes();
3785 while ( nIt->more() ) // loop on nodes bound to a FACE
3787 const SMDS_MeshNode* node = nIt->next();
3788 TSmoothNode & sNode = smooNoMap[ node ];
3789 sNode._uv = myHelper->GetNodeUV( geomFace, node );
3790 sNode._xyz = SMESH_TNodeXYZ( node );
3792 // set sNode._triangles
3793 SMDS_ElemIteratorPtr fIt = node->GetInverseElementIterator( SMDSAbs_Face );
3794 while ( fIt->more() )
3796 const SMDS_MeshElement* face = fIt->next();
3797 const int nbN = face->NbCornerNodes();
3798 const int nInd = face->GetNodeIndex( node );
3799 const int prevInd = myHelper->WrapIndex( nInd - 1, nbN );
3800 const int nextInd = myHelper->WrapIndex( nInd + 1, nbN );
3801 const SMDS_MeshNode* prevNode = face->GetNode( prevInd );
3802 const SMDS_MeshNode* nextNode = face->GetNode( nextInd );
3803 sNode._triangles.push_back( TTriangle( & smooNoMap[ prevNode ],
3804 & smooNoMap[ nextNode ]));
3807 // set _uv of smooth nodes on FACE boundary
3808 for ( unsigned i = 0; i < quad->side.size(); ++i )
3810 const vector<UVPtStruct>& uvVec = quad->side[i].GetUVPtStruct();
3811 for ( unsigned j = 0; j < uvVec.size(); ++j )
3813 TSmoothNode & sNode = smooNoMap[ uvVec[j].node ];
3814 sNode._uv = uvVec[j].UV();
3815 sNode._xyz = SMESH_TNodeXYZ( uvVec[j].node );
3819 // define refernce orientation in 2D
3820 TNo2SmooNoMap::iterator n2sn = smooNoMap.begin();
3821 for ( ; n2sn != smooNoMap.end(); ++n2sn )
3822 if ( !n2sn->second._triangles.empty() )
3824 if ( n2sn == smooNoMap.end() ) return;
3825 const TSmoothNode & sampleNode = n2sn->second;
3826 const bool refForward = ( sampleNode._triangles[0].IsForward( sampleNode._uv ));
3830 for ( int iLoop = 0; iLoop < 5; ++iLoop )
3832 for ( n2sn = smooNoMap.begin(); n2sn != smooNoMap.end(); ++n2sn )
3834 TSmoothNode& sNode = n2sn->second;
3835 if ( sNode._triangles.empty() )
3836 continue; // not movable node
3839 bool isValid = false;
3840 bool use3D = ( iLoop > 2 ); // 3 loops in 2D and 2, in 3D
3844 // compute a new XYZ
3845 gp_XYZ newXYZ (0,0,0);
3846 for ( unsigned i = 0; i < sNode._triangles.size(); ++i )
3847 newXYZ += sNode._triangles[i]._n1->_xyz;
3848 newXYZ /= sNode._triangles.size();
3850 // compute a new UV by projection
3851 proj.Perform( newXYZ );
3852 isValid = ( proj.IsDone() && proj.NbPoints() > 0 );
3855 // check validity of the newUV
3856 Quantity_Parameter u,v;
3857 proj.LowerDistanceParameters( u, v );
3858 newUV.SetCoord( u, v );
3859 for ( unsigned i = 0; i < sNode._triangles.size() && isValid; ++i )
3860 isValid = ( sNode._triangles[i].IsForward( newUV ) == refForward );
3865 // compute a new UV by averaging
3866 newUV.SetCoord(0.,0.);
3867 for ( unsigned i = 0; i < sNode._triangles.size(); ++i )
3868 newUV += sNode._triangles[i]._n1->_uv;
3869 newUV /= sNode._triangles.size();
3871 // check validity of the newUV
3873 for ( unsigned i = 0; i < sNode._triangles.size() && isValid; ++i )
3874 isValid = ( sNode._triangles[i].IsForward( newUV ) == refForward );
3879 sNode._xyz = surface->Value( newUV.X(), newUV.Y() ).XYZ();
3884 // Set new XYZ to the smoothed nodes
3886 for ( n2sn = smooNoMap.begin(); n2sn != smooNoMap.end(); ++n2sn )
3888 TSmoothNode& sNode = n2sn->second;
3889 if ( sNode._triangles.empty() )
3890 continue; // not movable node
3892 SMDS_MeshNode* node = const_cast< SMDS_MeshNode*>( n2sn->first );
3893 gp_Pnt xyz = surface->Value( sNode._uv.X(), sNode._uv.Y() );
3894 meshDS->MoveNode( node, xyz.X(), xyz.Y(), xyz.Z() );
3897 node->SetPosition( SMDS_PositionPtr( new SMDS_FacePosition( sNode._uv.X(), sNode._uv.Y() )));
3900 // Move medium nodes in quadratic mesh
3901 if ( _quadraticMesh )
3903 const TLinkNodeMap& links = myHelper->GetTLinkNodeMap();
3904 TLinkNodeMap::const_iterator linkIt = links.begin();
3905 for ( ; linkIt != links.end(); ++linkIt )
3907 const SMESH_TLink& link = linkIt->first;
3908 SMDS_MeshNode* node = const_cast< SMDS_MeshNode*>( linkIt->second );
3910 if ( node->getshapeId() != myHelper->GetSubShapeID() )
3911 continue; // medium node is on EDGE or VERTEX
3913 gp_XY uv1 = myHelper->GetNodeUV( geomFace, link.node1(), node );
3914 gp_XY uv2 = myHelper->GetNodeUV( geomFace, link.node2(), node );
3916 gp_XY uv = myHelper->GetMiddleUV( surface, uv1, uv2 );
3917 node->SetPosition( SMDS_PositionPtr( new SMDS_FacePosition( uv.X(), uv.Y() )));
3919 gp_Pnt xyz = surface->Value( uv.X(), uv.Y() );
3920 meshDS->MoveNode( node, xyz.X(), xyz.Y(), xyz.Z() );
3925 /*//================================================================================
3927 * \brief Finds vertices at the most sharp face corners
3928 * \param [in] theFace - the FACE
3929 * \param [in,out] theWire - the ordered edges of the face. It can be modified to
3930 * have the first VERTEX of the first EDGE in \a vertices
3931 * \param [out] theVertices - the found corner vertices in the order corresponding to
3932 * the order of EDGEs in \a theWire
3933 * \param [out] theNbDegenEdges - nb of degenerated EDGEs in theFace
3934 * \param [in] theConsiderMesh - if \c true, only meshed VERTEXes are considered
3935 * as possible corners
3936 * \return int - number of quad sides found: 0, 3 or 4
3938 //================================================================================
3940 int StdMeshers_Quadrangle_2D::getCorners(const TopoDS_Face& theFace,
3941 SMESH_Mesh & theMesh,
3942 std::list<TopoDS_Edge>& theWire,
3943 std::vector<TopoDS_Vertex>& theVertices,
3944 int & theNbDegenEdges,
3945 const bool theConsiderMesh)
3947 theNbDegenEdges = 0;
3949 SMESH_MesherHelper helper( theMesh );
3951 // sort theVertices by angle
3952 multimap<double, TopoDS_Vertex> vertexByAngle;
3953 TopTools_DataMapOfShapeReal angleByVertex;
3954 TopoDS_Edge prevE = theWire.back();
3955 if ( SMESH_Algo::isDegenerated( prevE ))
3957 list<TopoDS_Edge>::reverse_iterator edge = ++theWire.rbegin();
3958 while ( SMESH_Algo::isDegenerated( *edge ))
3960 if ( edge == theWire.rend() )
3964 list<TopoDS_Edge>::iterator edge = theWire.begin();
3965 for ( ; edge != theWire.end(); ++edge )
3967 if ( SMESH_Algo::isDegenerated( *edge ))
3972 TopoDS_Vertex v = helper.IthVertex( 0, *edge );
3973 if ( !theConsiderMesh || SMESH_Algo::VertexNode( v, helper.GetMeshDS() ))
3975 double angle = SMESH_MesherHelper::GetAngle( prevE, *edge, theFace );
3976 vertexByAngle.insert( make_pair( angle, v ));
3977 angleByVertex.Bind( v, angle );
3982 // find out required nb of corners (3 or 4)
3984 TopoDS_Shape triaVertex = helper.GetMeshDS()->IndexToShape( myTriaVertexID );
3985 if ( !triaVertex.IsNull() &&
3986 triaVertex.ShapeType() == TopAbs_VERTEX &&
3987 helper.IsSubShape( triaVertex, theFace ) &&
3988 ( vertexByAngle.size() != 4 || vertexByAngle.begin()->first < 5 * M_PI/180. ))
3991 triaVertex.Nullify();
3993 // check nb of available corners
3994 if ( nbCorners == 3 )
3996 if ( vertexByAngle.size() < 3 )
3997 return error(COMPERR_BAD_SHAPE,
3998 TComm("Face must have 3 sides but not ") << vertexByAngle.size() );
4002 if ( vertexByAngle.size() == 3 && theNbDegenEdges == 0 )
4004 if ( myTriaVertexID < 1 )
4005 return error(COMPERR_BAD_PARMETERS,
4006 "No Base vertex provided for a trilateral geometrical face");
4008 TComm comment("Invalid Base vertex: ");
4009 comment << myTriaVertexID << " its ID is not among [ ";
4010 multimap<double, TopoDS_Vertex>::iterator a2v = vertexByAngle.begin();
4011 comment << helper.GetMeshDS()->ShapeToIndex( a2v->second ) << ", "; a2v++;
4012 comment << helper.GetMeshDS()->ShapeToIndex( a2v->second ) << ", "; a2v++;
4013 comment << helper.GetMeshDS()->ShapeToIndex( a2v->second ) << " ]";
4014 return error(COMPERR_BAD_PARMETERS, comment );
4016 if ( vertexByAngle.size() + ( theNbDegenEdges > 0 ) < 4 &&
4017 vertexByAngle.size() + theNbDegenEdges != 4 )
4018 return error(COMPERR_BAD_SHAPE,
4019 TComm("Face must have 4 sides but not ") << vertexByAngle.size() );
4022 // put all corner vertices in a map
4023 TopTools_MapOfShape vMap;
4024 if ( nbCorners == 3 )
4025 vMap.Add( triaVertex );
4026 multimap<double, TopoDS_Vertex>::reverse_iterator a2v = vertexByAngle.rbegin();
4027 for ( ; a2v != vertexByAngle.rend() && vMap.Extent() < nbCorners; ++a2v )
4028 vMap.Add( (*a2v).second );
4030 // check if there are possible variations in choosing corners
4031 bool isThereVariants = false;
4032 if ( vertexByAngle.size() > nbCorners )
4034 double lostAngle = a2v->first;
4035 double lastAngle = ( --a2v, a2v->first );
4036 isThereVariants = ( lostAngle * 1.1 >= lastAngle );
4039 // make theWire begin from a corner vertex or triaVertex
4040 if ( nbCorners == 3 )
4041 while ( !triaVertex.IsSame( ( helper.IthVertex( 0, theWire.front() ))) ||
4042 SMESH_Algo::isDegenerated( theWire.front() ))
4043 theWire.splice( theWire.end(), theWire, theWire.begin() );
4045 while ( !vMap.Contains( helper.IthVertex( 0, theWire.front() )) ||
4046 SMESH_Algo::isDegenerated( theWire.front() ))
4047 theWire.splice( theWire.end(), theWire, theWire.begin() );
4049 // fill the result vector and prepare for its refinement
4050 theVertices.clear();
4051 vector< double > angles;
4052 vector< TopoDS_Edge > edgeVec;
4053 vector< int > cornerInd, nbSeg;
4054 angles.reserve( vertexByAngle.size() );
4055 edgeVec.reserve( vertexByAngle.size() );
4056 nbSeg.reserve( vertexByAngle.size() );
4057 cornerInd.reserve( nbCorners );
4058 for ( edge = theWire.begin(); edge != theWire.end(); ++edge )
4060 if ( SMESH_Algo::isDegenerated( *edge ))
4062 TopoDS_Vertex v = helper.IthVertex( 0, *edge );
4063 bool isCorner = vMap.Contains( v );
4066 theVertices.push_back( v );
4067 cornerInd.push_back( angles.size() );
4069 angles.push_back( angleByVertex.IsBound( v ) ? angleByVertex( v ) : -M_PI );
4070 edgeVec.push_back( *edge );
4071 if ( theConsiderMesh && isThereVariants )
4073 if ( SMESHDS_SubMesh* sm = helper.GetMeshDS()->MeshElements( *edge ))
4074 nbSeg.push_back( sm->NbNodes() + 1 );
4076 nbSeg.push_back( 0 );
4080 // refine the result vector - make sides elual by length if
4081 // there are several equal angles
4082 if ( isThereVariants )
4084 if ( nbCorners == 3 )
4085 angles[0] = 2 * M_PI; // not to move the base triangle VERTEX
4087 set< int > refinedCorners;
4088 for ( size_t iC = 0; iC < cornerInd.size(); ++iC )
4090 int iV = cornerInd[iC];
4091 if ( !refinedCorners.insert( iV ).second )
4093 list< int > equalVertices;
4094 equalVertices.push_back( iV );
4095 int nbC[2] = { 0, 0 };
4096 // find equal angles backward and forward from the iV-th corner vertex
4097 for ( int isFwd = 0; isFwd < 2; ++isFwd )
4099 int dV = isFwd ? +1 : -1;
4100 int iCNext = helper.WrapIndex( iC + dV, cornerInd.size() );
4101 int iVNext = helper.WrapIndex( iV + dV, angles.size() );
4102 while ( iVNext != iV )
4104 bool equal = Abs( angles[iV] - angles[iVNext] ) < 0.1 * angles[iV];
4106 equalVertices.insert( isFwd ? equalVertices.end() : equalVertices.begin(), iVNext );
4107 if ( iVNext == cornerInd[ iCNext ])
4112 refinedCorners.insert( cornerInd[ iCNext ] );
4113 iCNext = helper.WrapIndex( iCNext + dV, cornerInd.size() );
4115 iVNext = helper.WrapIndex( iVNext + dV, angles.size() );
4118 // move corners to make sides equal by length
4119 int nbEqualV = equalVertices.size();
4120 int nbExcessV = nbEqualV - ( 1 + nbC[0] + nbC[1] );
4121 if ( nbExcessV > 0 )
4123 // calculate normalized length of each side enclosed between neighbor equalVertices
4124 vector< double > curLengths;
4125 double totalLen = 0;
4126 vector< int > evVec( equalVertices.begin(), equalVertices.end() );
4128 int iE = cornerInd[ helper.WrapIndex( iC - nbC[0] - 1, cornerInd.size() )];
4129 int iEEnd = cornerInd[ helper.WrapIndex( iC + nbC[1] + 1, cornerInd.size() )];
4130 while ( curLengths.size() < nbEqualV + 1 )
4132 curLengths.push_back( totalLen );
4134 curLengths.back() += SMESH_Algo::EdgeLength( edgeVec[ iE ]);
4135 iE = helper.WrapIndex( iE + 1, edgeVec.size());
4136 if ( iEV < evVec.size() && iE == evVec[ iEV++ ] )
4139 while( iE != iEEnd );
4140 totalLen = curLengths.back();
4142 curLengths.resize( equalVertices.size() );
4143 for ( size_t iS = 0; iS < curLengths.size(); ++iS )
4144 curLengths[ iS ] /= totalLen;
4146 // find equalVertices most close to the ideal sub-division of all sides
4148 int iCorner = helper.WrapIndex( iC - nbC[0], cornerInd.size() );
4149 int nbSides = 2 + nbC[0] + nbC[1];
4150 for ( int iS = 1; iS < nbSides; ++iS, ++iBestEV )
4152 double idealLen = iS / double( nbSides );
4153 double d, bestDist = 1.;
4154 for ( iEV = iBestEV; iEV < curLengths.size(); ++iEV )
4155 if (( d = Abs( idealLen - curLengths[ iEV ])) < bestDist )
4160 if ( iBestEV > iS-1 + nbExcessV )
4161 iBestEV = iS-1 + nbExcessV;
4162 theVertices[ iCorner ] = helper.IthVertex( 0, edgeVec[ evVec[ iBestEV ]]);
4163 iCorner = helper.WrapIndex( iCorner + 1, cornerInd.size() );
4172 //================================================================================
4174 * \brief Constructor of a side of quad
4176 //================================================================================
4178 FaceQuadStruct::Side::Side(StdMeshers_FaceSidePtr theGrid)
4179 : grid(theGrid), nbNodeOut(0), from(0), to(theGrid ? theGrid->NbPoints() : 0 ), di(1)
4183 //=============================================================================
4185 * \brief Constructor of a quad
4187 //=============================================================================
4189 FaceQuadStruct::FaceQuadStruct(const TopoDS_Face& F, const std::string& theName)
4190 : face( F ), name( theName )
4195 //================================================================================
4197 * \brief Fills myForcedPnts
4199 //================================================================================
4201 bool StdMeshers_Quadrangle_2D::getEnforcedUV()
4203 myForcedPnts.clear();
4204 if ( !myParams ) return true; // missing hypothesis
4206 std::vector< TopoDS_Shape > shapes;
4207 std::vector< gp_Pnt > points;
4208 myParams->GetEnforcedNodes( shapes, points );
4210 TopTools_IndexedMapOfShape vMap;
4211 for ( size_t i = 0; i < shapes.size(); ++i )
4212 if ( !shapes[i].IsNull() )
4213 TopExp::MapShapes( shapes[i], TopAbs_VERTEX, vMap );
4215 size_t nbPoints = points.size();
4216 for ( int i = 1; i <= vMap.Extent(); ++i )
4217 points.push_back( BRep_Tool::Pnt( TopoDS::Vertex( vMap( i ))));
4219 // find out if all points must be in the FACE, which is so if
4220 // myParams is a local hypothesis on the FACE being meshed
4221 bool isStrictCheck = false;
4223 SMESH_HypoFilter paramFilter( SMESH_HypoFilter::Is( myParams ));
4224 TopoDS_Shape assignedTo;
4225 if ( myHelper->GetMesh()->GetHypothesis( myHelper->GetSubShape(),
4229 isStrictCheck = ( assignedTo.IsSame( myHelper->GetSubShape() ));
4232 multimap< double, ForcedPoint > sortedFP; // sort points by distance from EDGEs
4234 Standard_Real u1,u2,v1,v2;
4235 const TopoDS_Face& face = TopoDS::Face( myHelper->GetSubShape() );
4236 const double tol = BRep_Tool::Tolerance( face );
4237 Handle(Geom_Surface) surf = BRep_Tool::Surface( face );
4238 surf->Bounds( u1,u2,v1,v2 );
4239 GeomAPI_ProjectPointOnSurf project;
4240 project.Init(surf, u1,u2, v1,v2, tol );
4242 BRepBndLib::Add( face, bbox );
4243 double farTol = 0.01 * sqrt( bbox.SquareExtent() );
4245 for ( size_t iP = 0; iP < points.size(); ++iP )
4247 project.Perform( points[ iP ]);
4248 if ( !project.IsDone() )
4250 if ( isStrictCheck && iP < nbPoints )
4252 (TComm("Projection of an enforced point to the face failed - (")
4253 << points[ iP ].X() << ", "<< points[ iP ].Y() << ", "<< points[ iP ].Z() << " )");
4256 if ( project.LowerDistance() > farTol )
4258 if ( isStrictCheck && iP < nbPoints )
4260 (COMPERR_BAD_PARMETERS, TComm("An enforced point is too far from the face, dist = ")
4261 << project.LowerDistance() << " - ("
4262 << points[ iP ].X() << ", "<< points[ iP ].Y() << ", "<< points[ iP ].Z() << " )");
4265 Quantity_Parameter u, v;
4266 project.LowerDistanceParameters(u, v);
4267 gp_Pnt2d uv( u, v );
4268 BRepClass_FaceClassifier clsf ( face, uv, tol );
4269 switch ( clsf.State() ) {
4272 double edgeDist = ( Min( Abs( u - u1 ), Abs( u - u2 )) +
4273 Min( Abs( v - v1 ), Abs( v - v2 )));
4276 fp.xyz = points[ iP ].XYZ();
4277 if ( iP >= nbPoints )
4278 fp.vertex = TopoDS::Vertex( vMap( iP - nbPoints + 1 ));
4280 sortedFP.insert( make_pair( edgeDist, fp ));
4285 if ( isStrictCheck && iP < nbPoints )
4287 (COMPERR_BAD_PARMETERS, TComm("An enforced point is out of the face boundary - ")
4288 << points[ iP ].X() << ", "<< points[ iP ].Y() << ", "<< points[ iP ].Z() << " )");
4293 if ( isStrictCheck && iP < nbPoints )
4295 (COMPERR_BAD_PARMETERS, TComm("An enforced point is on the face boundary - ")
4296 << points[ iP ].X() << ", "<< points[ iP ].Y() << ", "<< points[ iP ].Z() << " )");
4301 if ( isStrictCheck && iP < nbPoints )
4303 (TComm("Classification of an enforced point ralative to the face boundary failed - ")
4304 << points[ iP ].X() << ", "<< points[ iP ].Y() << ", "<< points[ iP ].Z() << " )");
4309 multimap< double, ForcedPoint >::iterator d2uv = sortedFP.begin();
4310 for ( ; d2uv != sortedFP.end(); ++d2uv )
4311 myForcedPnts.push_back( (*d2uv).second );
4316 //================================================================================
4318 * \brief Splits quads by adding points of enforced nodes and create nodes on
4319 * the sides shared by quads
4321 //================================================================================
4323 bool StdMeshers_Quadrangle_2D::addEnforcedNodes()
4325 // if ( myForcedPnts.empty() )
4328 // make a map of quads sharing a side
4329 map< StdMeshers_FaceSidePtr, vector< FaceQuadStruct::Ptr > > quadsBySide;
4330 list< FaceQuadStruct::Ptr >::iterator quadIt = myQuadList.begin();
4331 for ( ; quadIt != myQuadList.end(); ++quadIt )
4332 for ( size_t iSide = 0; iSide < (*quadIt)->side.size(); ++iSide )
4334 if ( !setNormalizedGrid( *quadIt ))
4336 quadsBySide[ (*quadIt)->side[iSide] ].push_back( *quadIt );
4339 SMESH_Mesh* mesh = myHelper->GetMesh();
4340 SMESHDS_Mesh* meshDS = myHelper->GetMeshDS();
4341 const TopoDS_Face& face = TopoDS::Face( myHelper->GetSubShape() );
4342 Handle(Geom_Surface) surf = BRep_Tool::Surface( face );
4344 for ( size_t iFP = 0; iFP < myForcedPnts.size(); ++iFP )
4346 bool isNodeEnforced = false;
4348 // look for a quad enclosing a enforced point
4349 for ( quadIt = myQuadList.begin(); quadIt != myQuadList.end(); ++quadIt )
4351 FaceQuadStruct::Ptr quad = *quadIt;
4352 if ( !setNormalizedGrid( *quadIt ))
4355 if ( !quad->findCell( myForcedPnts[ iFP ], i, j ))
4358 // a grid cell is found, select a node of the cell to move
4359 // to the enforced point to and to split the quad at
4360 multimap< double, pair< int, int > > ijByDist;
4361 for ( int di = 0; di < 2; ++di )
4362 for ( int dj = 0; dj < 2; ++dj )
4364 double dist2 = ( myForcedPnts[ iFP ].uv - quad->UVPt( i+di,j+dj ).UV() ).SquareModulus();
4365 ijByDist.insert( make_pair( dist2, make_pair( di,dj )));
4367 // try all nodes starting from the closest one
4368 set< FaceQuadStruct::Ptr > changedQuads;
4369 multimap< double, pair< int, int > >::iterator d2ij = ijByDist.begin();
4370 for ( ; !isNodeEnforced && d2ij != ijByDist.end(); ++d2ij )
4372 int di = d2ij->second.first;
4373 int dj = d2ij->second.second;
4375 // check if a node is at a side
4377 if ( dj== 0 && j == 0 )
4378 iSide = QUAD_BOTTOM_SIDE;
4379 else if ( dj == 1 && j+2 == quad->jSize )
4380 iSide = QUAD_TOP_SIDE;
4381 else if ( di == 0 && i == 0 )
4382 iSide = QUAD_LEFT_SIDE;
4383 else if ( di == 1 && i+2 == quad->iSize )
4384 iSide = QUAD_RIGHT_SIDE;
4386 if ( iSide > -1 ) // ----- node is at a side
4388 FaceQuadStruct::Side& side = quad->side[ iSide ];
4389 // check if this node can be moved
4390 if ( quadsBySide[ side ].size() < 2 )
4391 continue; // its a face boundary -> can't move the node
4393 int quadNodeIndex = ( iSide % 2 ) ? j : i;
4394 int sideNodeIndex = side.ToSideIndex( quadNodeIndex );
4395 if ( side.IsForced( sideNodeIndex ))
4397 // the node is already moved to another enforced point
4398 isNodeEnforced = quad->isEqual( myForcedPnts[ iFP ], i, j );
4401 // make a node of a side forced
4402 vector<UVPtStruct>& points = (vector<UVPtStruct>&) side.GetUVPtStruct();
4403 points[ sideNodeIndex ].u = myForcedPnts[ iFP ].U();
4404 points[ sideNodeIndex ].v = myForcedPnts[ iFP ].V();
4406 updateSideUV( side, sideNodeIndex, quadsBySide );
4408 // update adjacent sides
4409 set< StdMeshers_FaceSidePtr > updatedSides;
4410 updatedSides.insert( side );
4411 for ( size_t i = 0; i < side.contacts.size(); ++i )
4412 if ( side.contacts[i].point == sideNodeIndex )
4414 const vector< FaceQuadStruct::Ptr >& adjQuads =
4415 quadsBySide[ *side.contacts[i].other_side ];
4416 if ( adjQuads.size() > 1 &&
4417 updatedSides.insert( * side.contacts[i].other_side ).second )
4419 updateSideUV( *side.contacts[i].other_side,
4420 side.contacts[i].other_point,
4423 changedQuads.insert( adjQuads.begin(), adjQuads.end() );
4425 const vector< FaceQuadStruct::Ptr >& adjQuads = quadsBySide[ side ];
4426 changedQuads.insert( adjQuads.begin(), adjQuads.end() );
4428 isNodeEnforced = true;
4430 else // ------------------ node is inside the quad
4434 // make a new side passing through IJ node and split the quad
4435 int indForced, iNewSide;
4436 if ( quad->iSize < quad->jSize ) // split vertically
4438 quad->updateUV( myForcedPnts[ iFP ].uv, i, j, /*isVert=*/true );
4440 iNewSide = splitQuad( quad, i, 0 );
4444 quad->updateUV( myForcedPnts[ iFP ].uv, i, j, /*isVert=*/false );
4446 iNewSide = splitQuad( quad, 0, j );
4448 FaceQuadStruct::Ptr newQuad = myQuadList.back();
4449 FaceQuadStruct::Side& newSide = newQuad->side[ iNewSide ];
4451 newSide.forced_nodes.insert( indForced );
4452 quad->side[( iNewSide+2 ) % 4 ].forced_nodes.insert( indForced );
4454 quadsBySide[ newSide ].push_back( quad );
4455 quadsBySide[ newQuad->side[0] ].push_back( newQuad );
4456 quadsBySide[ newQuad->side[1] ].push_back( newQuad );
4457 quadsBySide[ newQuad->side[2] ].push_back( newQuad );
4458 quadsBySide[ newQuad->side[3] ].push_back( newQuad );
4460 isNodeEnforced = true;
4462 } // end of "node is inside the quad"
4464 } // loop on nodes of the cell
4466 // remove out-of-date uv grid of changedQuads
4467 set< FaceQuadStruct::Ptr >::iterator qIt = changedQuads.begin();
4468 for ( ; qIt != changedQuads.end(); ++qIt )
4469 (*qIt)->uv_grid.clear();
4471 if ( isNodeEnforced )
4476 if ( !isNodeEnforced )
4478 if ( !myForcedPnts[ iFP ].vertex.IsNull() )
4479 return error(TComm("Unable to move any node to vertex #")
4480 <<myHelper->GetMeshDS()->ShapeToIndex( myForcedPnts[ iFP ].vertex ));
4482 return error(TComm("Unable to move any node to point ( ")
4483 << myForcedPnts[iFP].xyz.X() << ", "
4484 << myForcedPnts[iFP].xyz.Y() << ", "
4485 << myForcedPnts[iFP].xyz.Z() << " )");
4488 } // loop on enforced points
4490 // Compute nodes on all sides, where not yet present
4492 for ( quadIt = myQuadList.begin(); quadIt != myQuadList.end(); ++quadIt )
4494 FaceQuadStruct::Ptr quad = *quadIt;
4495 for ( int iSide = 0; iSide < 4; ++iSide )
4497 FaceQuadStruct::Side & side = quad->side[ iSide ];
4498 if ( side.nbNodeOut > 0 )
4499 continue; // emulated side
4500 vector< FaceQuadStruct::Ptr >& quadVec = quadsBySide[ side ];
4501 if ( quadVec.size() <= 1 )
4502 continue; // outer side
4504 bool missedNodesOnSide = false;
4505 const vector<UVPtStruct>& points = side.grid->GetUVPtStruct();
4506 for ( size_t iC = 0; iC < side.contacts.size(); ++iC )
4508 const vector<UVPtStruct>& oGrid = side.contacts[iC].other_side->grid->GetUVPtStruct();
4509 const UVPtStruct& uvPt = points[ side.contacts[iC].point ];
4510 if ( side.contacts[iC].other_point >= oGrid.size() ||
4511 side.contacts[iC].point >= points.size() )
4512 throw SALOME_Exception( "StdMeshers_Quadrangle_2D::addEnforcedNodes(): wrong contact" );
4513 if ( oGrid[ side.contacts[iC].other_point ].node )
4514 (( UVPtStruct& ) uvPt).node = oGrid[ side.contacts[iC].other_point ].node;
4516 for ( size_t iP = 0; iP < points.size(); ++iP )
4517 if ( !points[ iP ].node )
4519 UVPtStruct& uvPnt = ( UVPtStruct& ) points[ iP ];
4520 gp_Pnt P = surf->Value( uvPnt.u, uvPnt.v );
4521 uvPnt.node = meshDS->AddNode(P.X(), P.Y(), P.Z());
4522 meshDS->SetNodeOnFace( uvPnt.node, myHelper->GetSubShapeID(), uvPnt.u, uvPnt.v );
4523 missedNodesOnSide = true;
4525 if ( missedNodesOnSide )
4527 // clear uv_grid where nodes are missing
4528 for ( size_t iQ = 0; iQ < quadVec.size(); ++iQ )
4529 quadVec[ iQ ]->uv_grid.clear();
4537 //================================================================================
4539 * \brief Splits a quad at I or J. Returns an index of a new side in the new quad
4541 //================================================================================
4543 int StdMeshers_Quadrangle_2D::splitQuad(FaceQuadStruct::Ptr quad, int I, int J)
4545 FaceQuadStruct* newQuad = new FaceQuadStruct( quad->face );
4546 myQuadList.push_back( FaceQuadStruct::Ptr( newQuad ));
4548 vector<UVPtStruct> points;
4551 points.reserve( quad->jSize );
4552 for ( int jP = 0; jP < quad->jSize; ++jP )
4553 points.push_back( quad->UVPt( I, jP ));
4555 newQuad->side.resize( 4 );
4556 newQuad->side[ QUAD_BOTTOM_SIDE ] = quad->side[ QUAD_BOTTOM_SIDE ];
4557 newQuad->side[ QUAD_RIGHT_SIDE ] = quad->side[ QUAD_RIGHT_SIDE ];
4558 newQuad->side[ QUAD_TOP_SIDE ] = quad->side[ QUAD_TOP_SIDE ];
4559 newQuad->side[ QUAD_LEFT_SIDE ] = StdMeshers_FaceSide::New( points, quad->face );
4561 FaceQuadStruct::Side& newSide = newQuad->side[ QUAD_LEFT_SIDE ];
4562 FaceQuadStruct::Side& newSide2 = quad->side [ QUAD_RIGHT_SIDE ];
4564 quad->side[ QUAD_RIGHT_SIDE ] = newSide;
4566 int iBot = quad->side[ QUAD_BOTTOM_SIDE ].ToSideIndex( I );
4567 int iTop = quad->side[ QUAD_TOP_SIDE ].ToSideIndex( I );
4569 newSide.AddContact ( 0, & quad->side[ QUAD_BOTTOM_SIDE ], iBot );
4570 newSide2.AddContact( 0, & quad->side[ QUAD_BOTTOM_SIDE ], iBot );
4571 newSide.AddContact ( quad->jSize - 1, & quad->side[ QUAD_TOP_SIDE ], iTop );
4572 newSide2.AddContact( quad->jSize - 1, & quad->side[ QUAD_TOP_SIDE ], iTop );
4573 // cout << "Contact: L " << &newSide << " "<< newSide.NbPoints()
4574 // << " R " << &newSide2 << " "<< newSide2.NbPoints()
4575 // << " B " << &quad->side[ QUAD_BOTTOM_SIDE ] << " "<< quad->side[ QUAD_BOTTOM_SIDE].NbPoints()
4576 // << " T " << &quad->side[ QUAD_TOP_SIDE ] << " "<< quad->side[ QUAD_TOP_SIDE].NbPoints()<< endl;
4578 newQuad->side[ QUAD_BOTTOM_SIDE ].from = iBot;
4579 newQuad->side[ QUAD_TOP_SIDE ].from = iTop;
4580 newQuad->name = ( TComm("Right of I=") << I );
4582 quad->side[ QUAD_BOTTOM_SIDE ].to = iBot + 1;
4583 quad->side[ QUAD_TOP_SIDE ].to = iTop + 1;
4584 quad->uv_grid.clear();
4586 return QUAD_LEFT_SIDE;
4588 else if ( J > 0 ) //// split horizontally, a new quad is below an old one
4590 points.reserve( quad->iSize );
4591 for ( int iP = 0; iP < quad->iSize; ++iP )
4592 points.push_back( quad->UVPt( iP, J ));
4594 newQuad->side.resize( 4 );
4595 newQuad->side[ QUAD_BOTTOM_SIDE ] = quad->side[ QUAD_BOTTOM_SIDE ];
4596 newQuad->side[ QUAD_RIGHT_SIDE ] = quad->side[ QUAD_RIGHT_SIDE ];
4597 newQuad->side[ QUAD_TOP_SIDE ] = StdMeshers_FaceSide::New( points, quad->face );
4598 newQuad->side[ QUAD_LEFT_SIDE ] = quad->side[ QUAD_LEFT_SIDE ];
4600 FaceQuadStruct::Side& newSide = newQuad->side[ QUAD_TOP_SIDE ];
4601 FaceQuadStruct::Side& newSide2 = quad->side [ QUAD_BOTTOM_SIDE ];
4603 quad->side[ QUAD_BOTTOM_SIDE ] = newSide;
4605 int iLft = quad->side[ QUAD_LEFT_SIDE ].ToSideIndex( J );
4606 int iRgt = quad->side[ QUAD_RIGHT_SIDE ].ToSideIndex( J );
4608 newSide.AddContact ( 0, & quad->side[ QUAD_LEFT_SIDE ], iLft );
4609 newSide2.AddContact( 0, & quad->side[ QUAD_LEFT_SIDE ], iLft );
4610 newSide.AddContact ( quad->iSize - 1, & quad->side[ QUAD_RIGHT_SIDE ], iRgt );
4611 newSide2.AddContact( quad->iSize - 1, & quad->side[ QUAD_RIGHT_SIDE ], iRgt );
4612 // cout << "Contact: T " << &newSide << " "<< newSide.NbPoints()
4613 // << " B " << &newSide2 << " "<< newSide2.NbPoints()
4614 // << " L " << &quad->side[ QUAD_LEFT_SIDE ] << " "<< quad->side[ QUAD_LEFT_SIDE].NbPoints()
4615 // << " R " << &quad->side[ QUAD_RIGHT_SIDE ] << " "<< quad->side[ QUAD_RIGHT_SIDE].NbPoints()<< endl;
4617 newQuad->side[ QUAD_RIGHT_SIDE ].to = iRgt+1;
4618 newQuad->side[ QUAD_LEFT_SIDE ].to = iLft+1;
4619 newQuad->name = ( TComm("Below J=") << J );
4621 quad->side[ QUAD_RIGHT_SIDE ].from = iRgt;
4622 quad->side[ QUAD_LEFT_SIDE ].from = iLft;
4623 quad->uv_grid.clear();
4625 return QUAD_TOP_SIDE;
4629 //================================================================================
4631 * \brief Updates UV of a side after moving its node
4633 //================================================================================
4635 void StdMeshers_Quadrangle_2D::updateSideUV( FaceQuadStruct::Side& side,
4637 const TQuadsBySide& quadsBySide,
4642 side.forced_nodes.insert( iForced );
4644 // update parts of the side before and after iForced
4646 set<int>::iterator iIt = side.forced_nodes.upper_bound( iForced );
4647 int iEnd = Min( side.NbPoints()-1, ( iIt == side.forced_nodes.end() ) ? int(1e7) : *iIt );
4648 if ( iForced + 1 < iEnd )
4649 updateSideUV( side, iForced, quadsBySide, &iEnd );
4651 iIt = side.forced_nodes.lower_bound( iForced );
4652 int iBeg = Max( 0, ( iIt == side.forced_nodes.begin() ) ? 0 : *--iIt );
4653 if ( iForced - 1 > iBeg )
4654 updateSideUV( side, iForced, quadsBySide, &iBeg );
4659 const int iFrom = Min ( iForced, *iNext );
4660 const int iTo = Max ( iForced, *iNext ) + 1;
4661 const int sideSize = iTo - iFrom;
4663 vector<UVPtStruct> points[4]; // side points of a temporary quad
4665 // from the quads get grid points adjacent to the side
4666 // to make two sides of a temporary quad
4667 vector< FaceQuadStruct::Ptr > quads = quadsBySide.find( side )->second; // copy!
4668 for ( int is2nd = 0; is2nd < 2; ++is2nd )
4670 points[ is2nd ].reserve( sideSize );
4672 while ( points[is2nd].size() < sideSize )
4674 int iCur = iFrom + points[is2nd].size() - int( !points[is2nd].empty() );
4676 // look for a quad adjacent to iCur-th point of the side
4677 for ( size_t iQ = 0; iQ < quads.size(); ++iQ )
4679 FaceQuadStruct::Ptr q = quads[ iQ ];
4683 for ( iS = 0; iS < q->side.size(); ++iS )
4684 if ( side.grid == q->side[ iS ].grid )
4687 if ( !q->side[ iS ].IsReversed() )
4688 isOut = ( q->side[ iS ].from > iCur || q->side[ iS ].to-1 <= iCur );
4690 isOut = ( q->side[ iS ].to >= iCur || q->side[ iS ].from <= iCur );
4693 if ( !setNormalizedGrid( q ))
4696 // found - copy points
4698 if ( iS % 2 ) // right or left
4700 i = ( iS == QUAD_LEFT_SIDE ) ? 1 : q->iSize-2;
4701 j = q->side[ iS ].ToQuadIndex( iCur );
4703 dj = ( q->side[ iS ].IsReversed() ) ? -1 : +1;
4704 nb = ( q->side[ iS ].IsReversed() ) ? j+1 : q->jSize-j;
4706 else // bottom or top
4708 i = q->side[ iS ].ToQuadIndex( iCur );
4709 j = ( iS == QUAD_BOTTOM_SIDE ) ? 1 : q->jSize-2;
4710 di = ( q->side[ iS ].IsReversed() ) ? -1 : +1;
4712 nb = ( q->side[ iS ].IsReversed() ) ? i+1 : q->iSize-i;
4714 if ( !points[is2nd].empty() )
4716 gp_UV lastUV = points[is2nd].back().UV();
4717 gp_UV quadUV = q->UVPt( i, j ).UV();
4718 if ( ( lastUV - quadUV ).SquareModulus() > 1e-10 )
4719 continue; // quad is on the other side of the side
4720 i += di; j += dj; --nb;
4722 for ( ; nb > 0 ; --nb )
4724 points[ is2nd ].push_back( q->UVPt( i, j ));
4725 if ( points[is2nd].size() >= sideSize )
4729 quads[ iQ ].reset(); // not to use this quad anymore
4731 if ( points[is2nd].size() >= sideSize )
4735 if ( nbLoops++ > quads.size() )
4736 throw SALOME_Exception( "StdMeshers_Quadrangle_2D::updateSideUV() bug: infinite loop" );
4738 } // while ( points[is2nd].size() < sideSize )
4739 } // two loops to fill points[0] and points[1]
4741 // points for other pair of opposite sides of the temporary quad
4743 enum { L,R,B,T }; // side index of points[]
4745 points[B].push_back( points[L].front() );
4746 points[B].push_back( side.GetUVPtStruct()[ iFrom ]);
4747 points[B].push_back( points[R].front() );
4749 points[T].push_back( points[L].back() );
4750 points[T].push_back( side.GetUVPtStruct()[ iTo-1 ]);
4751 points[T].push_back( points[R].back() );
4753 // make the temporary quad
4754 FaceQuadStruct::Ptr tmpQuad
4755 ( new FaceQuadStruct( TopoDS::Face( myHelper->GetSubShape() ), "tmpQuad"));
4756 tmpQuad->side.push_back( StdMeshers_FaceSide::New( points[B] )); // bottom
4757 tmpQuad->side.push_back( StdMeshers_FaceSide::New( points[R] )); // right
4758 tmpQuad->side.push_back( StdMeshers_FaceSide::New( points[T] ));
4759 tmpQuad->side.push_back( StdMeshers_FaceSide::New( points[L] ));
4761 // compute new UV of the side
4762 setNormalizedGrid( tmpQuad );
4763 gp_UV uv = tmpQuad->UVPt(1,0).UV();
4764 tmpQuad->updateUV( uv, 1,0, /*isVertical=*/true );
4766 // update UV of the side
4767 vector<UVPtStruct>& sidePoints = (vector<UVPtStruct>&) side.GetUVPtStruct();
4768 for ( int i = iFrom; i < iTo; ++i )
4770 const uvPtStruct& uvPt = tmpQuad->UVPt( 1, i-iFrom );
4771 sidePoints[ i ].u = uvPt.u;
4772 sidePoints[ i ].v = uvPt.v;
4776 //================================================================================
4778 * \brief Finds indices of a grid quad enclosing the given enforced UV
4780 //================================================================================
4782 bool FaceQuadStruct::findCell( const gp_XY& UV, int & I, int & J )
4784 // setNormalizedGrid() must be called before!
4785 if ( uv_box.IsOut( UV ))
4788 // find an approximate position
4789 double x = 0.5, y = 0.5;
4790 gp_XY t0 = UVPt( iSize - 1, 0 ).UV();
4791 gp_XY t1 = UVPt( 0, jSize - 1 ).UV();
4792 gp_XY t2 = UVPt( 0, 0 ).UV();
4793 SMESH_MeshAlgos::GetBarycentricCoords( UV, t0, t1, t2, x, y );
4794 x = Min( 1., Max( 0., x ));
4795 y = Min( 1., Max( 0., y ));
4797 // precise the position
4798 normPa2IJ( x,y, I,J );
4799 if ( !isNear( UV, I,J ))
4801 // look for the most close IJ by traversing uv_grid in the middle
4802 double dist2, minDist2 = ( UV - UVPt( I,J ).UV() ).SquareModulus();
4803 for ( int isU = 0; isU < 2; ++isU )
4805 int ind1 = isU ? 0 : iSize / 2;
4806 int ind2 = isU ? jSize / 2 : 0;
4807 int di1 = isU ? Max( 2, iSize / 20 ) : 0;
4808 int di2 = isU ? 0 : Max( 2, jSize / 20 );
4809 int i,nb = isU ? iSize / di1 : jSize / di2;
4810 for ( i = 0; i < nb; ++i, ind1 += di1, ind2 += di2 )
4811 if (( dist2 = ( UV - UVPt( ind1,ind2 ).UV() ).SquareModulus() ) < minDist2 )
4815 if ( isNear( UV, I,J ))
4817 minDist2 = ( UV - UVPt( I,J ).UV() ).SquareModulus();
4820 if ( !isNear( UV, I,J, Max( iSize, jSize ) /2 ))
4826 //================================================================================
4828 * \brief Find indices (i,j) of a point in uv_grid by normalized parameters (x,y)
4830 //================================================================================
4832 void FaceQuadStruct::normPa2IJ(double X, double Y, int & I, int & J )
4835 I = Min( int ( iSize * X ), iSize - 2 );
4836 J = Min( int ( jSize * Y ), jSize - 2 );
4842 while ( X <= UVPt( I,J ).x && I != 0 )
4844 while ( X > UVPt( I+1,J ).x && I+2 < iSize )
4846 while ( Y <= UVPt( I,J ).y && J != 0 )
4848 while ( Y > UVPt( I,J+1 ).y && J+2 < jSize )
4850 } while ( oldI != I || oldJ != J );
4853 //================================================================================
4855 * \brief Looks for UV in quads around a given (I,J) and precise (I,J)
4857 //================================================================================
4859 bool FaceQuadStruct::isNear( const gp_XY& UV, int & I, int & J, int nbLoops )
4861 if ( I+1 >= iSize ) I = iSize - 2;
4862 if ( J+1 >= jSize ) J = jSize - 2;
4865 gp_XY uvI, uvJ, uv0, uv1;
4866 for ( int iLoop = 0; iLoop < nbLoops; ++iLoop )
4868 int oldI = I, oldJ = J;
4870 uvI = UVPt( I+1, J ).UV();
4871 uvJ = UVPt( I, J+1 ).UV();
4872 uv0 = UVPt( I, J ).UV();
4873 SMESH_MeshAlgos::GetBarycentricCoords( UV, uvI, uvJ, uv0, bcI, bcJ );
4874 if ( bcI >= 0. && bcJ >= 0. && bcI + bcJ <= 1.)
4877 if ( I > 0 && bcI < 0. ) --I;
4878 if ( I+2 < iSize && bcI > 1. ) ++I;
4879 if ( J > 0 && bcJ < 0. ) --J;
4880 if ( J+2 < jSize && bcJ > 1. ) ++J;
4882 uv1 = UVPt( I+1,J+1).UV();
4883 if ( I != oldI || J != oldJ )
4885 uvI = UVPt( I+1, J ).UV();
4886 uvJ = UVPt( I, J+1 ).UV();
4888 SMESH_MeshAlgos::GetBarycentricCoords( UV, uvI, uvJ, uv1, bcI, bcJ );
4889 if ( bcI >= 0. && bcJ >= 0. && bcI + bcJ <= 1.)
4892 if ( I > 0 && bcI > 1. ) --I;
4893 if ( I+2 < iSize && bcI < 0. ) ++I;
4894 if ( J > 0 && bcJ > 1. ) --J;
4895 if ( J+2 < jSize && bcJ < 0. ) ++J;
4897 if ( I == oldI && J == oldJ )
4900 if ( iLoop+1 == nbLoops )
4902 uvI = UVPt( I+1, J ).UV();
4903 uvJ = UVPt( I, J+1 ).UV();
4904 uv0 = UVPt( I, J ).UV();
4905 SMESH_MeshAlgos::GetBarycentricCoords( UV, uvI, uvJ, uv0, bcI, bcJ );
4906 if ( bcI >= 0. && bcJ >= 0. && bcI + bcJ <= 1.)
4909 uv1 = UVPt( I+1,J+1).UV();
4910 SMESH_MeshAlgos::GetBarycentricCoords( UV, uvI, uvJ, uv1, bcI, bcJ );
4911 if ( bcI >= 0. && bcJ >= 0. && bcI + bcJ <= 1.)
4918 //================================================================================
4920 * \brief Checks if a given UV is equal to a given grid point
4922 //================================================================================
4924 bool FaceQuadStruct::isEqual( const gp_XY& UV, int I, int J )
4926 TopLoc_Location loc;
4927 Handle(Geom_Surface) surf = BRep_Tool::Surface( face, loc );
4928 gp_Pnt p1 = surf->Value( UV.X(), UV.Y() );
4929 gp_Pnt p2 = surf->Value( UVPt( I,J ).u, UVPt( I,J ).v );
4931 double dist2 = 1e100;
4932 for ( int di = -1; di < 2; di += 2 )
4935 if ( i < 0 || i+1 >= iSize ) continue;
4936 for ( int dj = -1; dj < 2; dj += 2 )
4939 if ( j < 0 || j+1 >= jSize ) continue;
4942 p2.SquareDistance( surf->Value( UVPt( i,j ).u, UVPt( i,j ).v )));
4945 double tol2 = dist2 / 1000.;
4946 return p1.SquareDistance( p2 ) < tol2;
4949 //================================================================================
4951 * \brief Recompute UV of grid points around a moved point in one direction
4953 //================================================================================
4955 void FaceQuadStruct::updateUV( const gp_XY& UV, int I, int J, bool isVertical )
4957 UVPt( I, J ).u = UV.X();
4958 UVPt( I, J ).v = UV.Y();
4963 if ( J+1 < jSize-1 )
4965 gp_UV a0 = UVPt( 0, J ).UV();
4966 gp_UV a1 = UVPt( iSize-1, J ).UV();
4967 gp_UV a2 = UVPt( iSize-1, jSize-1 ).UV();
4968 gp_UV a3 = UVPt( 0, jSize-1 ).UV();
4970 gp_UV p0 = UVPt( I, J ).UV();
4971 gp_UV p2 = UVPt( I, jSize-1 ).UV();
4972 const double y0 = UVPt( I, J ).y, dy = 1. - y0;
4973 for (int j = J+1; j < jSize-1; j++)
4975 gp_UV p1 = UVPt( iSize-1, j ).UV();
4976 gp_UV p3 = UVPt( 0, j ).UV();
4978 UVPtStruct& uvPt = UVPt( I, j );
4979 gp_UV uv = calcUV( uvPt.x, ( uvPt.y - y0 ) / dy, a0,a1,a2,a3, p0,p1,p2,p3);
4987 gp_UV a0 = UVPt( 0, 0 ).UV();
4988 gp_UV a1 = UVPt( iSize-1, 0 ).UV();
4989 gp_UV a2 = UVPt( iSize-1, J ).UV();
4990 gp_UV a3 = UVPt( 0, J ).UV();
4992 gp_UV p0 = UVPt( I, 0 ).UV();
4993 gp_UV p2 = UVPt( I, J ).UV();
4994 const double y0 = 0., dy = UVPt( I, J ).y - y0;
4995 for (int j = 1; j < J; j++)
4997 gp_UV p1 = UVPt( iSize-1, j ).UV();
4998 gp_UV p3 = UVPt( 0, j ).UV();
5000 UVPtStruct& uvPt = UVPt( I, j );
5001 gp_UV uv = calcUV( uvPt.x, ( uvPt.y - y0 ) / dy, a0,a1,a2,a3, p0,p1,p2,p3);
5007 else // horizontally
5012 gp_UV a0 = UVPt( 0, 0 ).UV();
5013 gp_UV a1 = UVPt( I, 0 ).UV();
5014 gp_UV a2 = UVPt( I, jSize-1 ).UV();
5015 gp_UV a3 = UVPt( 0, jSize-1 ).UV();
5017 gp_UV p1 = UVPt( I, J ).UV();
5018 gp_UV p3 = UVPt( 0, J ).UV();
5019 const double x0 = 0., dx = UVPt( I, J ).x - x0;
5020 for (int i = 1; i < I; i++)
5022 gp_UV p0 = UVPt( i, 0 ).UV();
5023 gp_UV p2 = UVPt( i, jSize-1 ).UV();
5025 UVPtStruct& uvPt = UVPt( i, J );
5026 gp_UV uv = calcUV(( uvPt.x - x0 ) / dx , uvPt.y, a0,a1,a2,a3, p0,p1,p2,p3);
5032 if ( I+1 < iSize-1 )
5034 gp_UV a0 = UVPt( I, 0 ).UV();
5035 gp_UV a1 = UVPt( iSize-1, 0 ).UV();
5036 gp_UV a2 = UVPt( iSize-1, jSize-1 ).UV();
5037 gp_UV a3 = UVPt( I, jSize-1 ).UV();
5039 gp_UV p1 = UVPt( iSize-1, J ).UV();
5040 gp_UV p3 = UVPt( I, J ).UV();
5041 const double x0 = UVPt( I, J ).x, dx = 1. - x0;
5042 for (int i = I+1; i < iSize-1; i++)
5044 gp_UV p0 = UVPt( i, 0 ).UV();
5045 gp_UV p2 = UVPt( i, jSize-1 ).UV();
5047 UVPtStruct& uvPt = UVPt( i, J );
5048 gp_UV uv = calcUV(( uvPt.x - x0 ) / dx , uvPt.y, a0,a1,a2,a3, p0,p1,p2,p3);
5056 //================================================================================
5058 * \brief Side copying
5060 //================================================================================
5062 FaceQuadStruct::Side& FaceQuadStruct::Side::operator=(const Side& otherSide)
5064 grid = otherSide.grid;
5065 from = otherSide.from;
5068 forced_nodes = otherSide.forced_nodes;
5069 contacts = otherSide.contacts;
5070 nbNodeOut = otherSide.nbNodeOut;
5072 for ( size_t iC = 0; iC < contacts.size(); ++iC )
5074 FaceQuadStruct::Side* oSide = contacts[iC].other_side;
5075 for ( size_t iOC = 0; iOC < oSide->contacts.size(); ++iOC )
5076 if ( oSide->contacts[iOC].other_side == & otherSide )
5078 // cout << "SHIFT old " << &otherSide << " " << otherSide.NbPoints()
5079 // << " -> new " << this << " " << this->NbPoints() << endl;
5080 oSide->contacts[iOC].other_side = this;
5085 //================================================================================
5087 * \brief Converts node index of a quad to node index of this side
5089 //================================================================================
5091 int FaceQuadStruct::Side::ToSideIndex( int quadNodeIndex ) const
5093 return from + di * quadNodeIndex;
5096 //================================================================================
5098 * \brief Converts node index of this side to node index of a quad
5100 //================================================================================
5102 int FaceQuadStruct::Side::ToQuadIndex( int sideNodeIndex ) const
5104 return ( sideNodeIndex - from ) * di;
5107 //================================================================================
5109 * \brief Reverse the side
5111 //================================================================================
5113 bool FaceQuadStruct::Side::Reverse(bool keepGrid)
5121 std::swap( from, to );
5131 //================================================================================
5133 * \brief Checks if a node is enforced
5134 * \param [in] nodeIndex - an index of a node in a size
5135 * \return bool - \c true if the node is forced
5137 //================================================================================
5139 bool FaceQuadStruct::Side::IsForced( int nodeIndex ) const
5141 if ( nodeIndex < 0 || nodeIndex >= grid->NbPoints() )
5142 throw SALOME_Exception( " FaceQuadStruct::Side::IsForced(): wrong index" );
5144 if ( forced_nodes.count( nodeIndex ) )
5147 for ( size_t i = 0; i < this->contacts.size(); ++i )
5148 if ( contacts[ i ].point == nodeIndex &&
5149 contacts[ i ].other_side->forced_nodes.count( contacts[ i ].other_point ))
5155 //================================================================================
5157 * \brief Sets up a contact between this and another side
5159 //================================================================================
5161 void FaceQuadStruct::Side::AddContact( int ip, Side* side, int iop )
5163 if ( ip >= GetUVPtStruct().size() ||
5164 iop >= side->GetUVPtStruct().size() )
5165 throw SALOME_Exception( "FaceQuadStruct::Side::AddContact(): wrong point" );
5167 contacts.resize( contacts.size() + 1 );
5168 Contact& c = contacts.back();
5170 c.other_side = side;
5171 c.other_point = iop;
5174 side->contacts.resize( side->contacts.size() + 1 );
5175 Contact& c = side->contacts.back();
5177 c.other_side = this;
5182 //================================================================================
5184 * \brief Returns a normalized parameter of a point indexed within a quadrangle
5186 //================================================================================
5188 double FaceQuadStruct::Side::Param( int i ) const
5190 const vector<UVPtStruct>& points = GetUVPtStruct();
5191 return (( points[ from + i * di ].normParam - points[ from ].normParam ) /
5192 ( points[ to - 1 * di ].normParam - points[ from ].normParam ));
5195 //================================================================================
5197 * \brief Returns UV by a parameter normalized within a quadrangle
5199 //================================================================================
5201 gp_XY FaceQuadStruct::Side::Value2d( double x ) const
5203 const vector<UVPtStruct>& points = GetUVPtStruct();
5204 double u = ( points[ from ].normParam +
5205 x * ( points[ to-di ].normParam - points[ from ].normParam ));
5206 return grid->Value2d( u ).XY();
5209 //================================================================================
5211 * \brief Returns side length
5213 //================================================================================
5215 double FaceQuadStruct::Side::Length(int theFrom, int theTo) const
5217 if ( IsReversed() != ( theTo < theFrom ))
5218 std::swap( theTo, theFrom );
5220 const vector<UVPtStruct>& points = GetUVPtStruct();
5222 if ( theFrom == theTo && theTo == -1 )
5223 r = Abs( First().normParam -
5224 Last ().normParam );
5225 else if ( IsReversed() )
5226 r = Abs( points[ Max( to, theTo+1 ) ].normParam -
5227 points[ Min( from, theFrom ) ].normParam );
5229 r = Abs( points[ Min( to, theTo-1 ) ].normParam -
5230 points[ Max( from, theFrom ) ].normParam );
5231 return r * grid->Length();