1 // Copyright (C) 2007-2013 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.
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 <BRepClass_FaceClassifier.hxx>
46 #include <BRep_Tool.hxx>
47 #include <GeomAPI_ProjectPointOnSurf.hxx>
48 #include <Geom_Surface.hxx>
49 #include <NCollection_DefineArray2.hxx>
50 #include <Precision.hxx>
51 #include <Quantity_Parameter.hxx>
52 #include <TColStd_SequenceOfInteger.hxx>
53 #include <TColStd_SequenceOfReal.hxx>
54 #include <TColgp_SequenceOfXY.hxx>
56 #include <TopExp_Explorer.hxx>
57 #include <TopTools_DataMapOfShapeReal.hxx>
58 #include <TopTools_ListIteratorOfListOfShape.hxx>
59 #include <TopTools_MapOfShape.hxx>
62 #include "utilities.h"
63 #include "Utils_ExceptHandlers.hxx"
65 #ifndef StdMeshers_Array2OfNode_HeaderFile
66 #define StdMeshers_Array2OfNode_HeaderFile
67 typedef const SMDS_MeshNode* SMDS_MeshNodePtr;
68 DEFINE_BASECOLLECTION (StdMeshers_BaseCollectionNodePtr, SMDS_MeshNodePtr)
69 DEFINE_ARRAY2(StdMeshers_Array2OfNode,
70 StdMeshers_BaseCollectionNodePtr, SMDS_MeshNodePtr)
76 typedef SMESH_Comment TComm;
78 //=============================================================================
82 //=============================================================================
84 StdMeshers_Quadrangle_2D::StdMeshers_Quadrangle_2D (int hypId, int studyId,
86 : SMESH_2D_Algo(hypId, studyId, gen),
87 myQuadranglePreference(false),
88 myTrianglePreference(false),
92 myQuadType(QUAD_STANDARD),
95 MESSAGE("StdMeshers_Quadrangle_2D::StdMeshers_Quadrangle_2D");
96 _name = "Quadrangle_2D";
97 _shapeType = (1 << TopAbs_FACE);
98 _compatibleHypothesis.push_back("QuadrangleParams");
99 _compatibleHypothesis.push_back("QuadranglePreference");
100 _compatibleHypothesis.push_back("TrianglePreference");
101 _compatibleHypothesis.push_back("ViscousLayers2D");
104 //=============================================================================
108 //=============================================================================
110 StdMeshers_Quadrangle_2D::~StdMeshers_Quadrangle_2D()
112 MESSAGE("StdMeshers_Quadrangle_2D::~StdMeshers_Quadrangle_2D");
115 //=============================================================================
119 //=============================================================================
121 bool StdMeshers_Quadrangle_2D::CheckHypothesis
123 const TopoDS_Shape& aShape,
124 SMESH_Hypothesis::Hypothesis_Status& aStatus)
127 myQuadType = QUAD_STANDARD;
128 myQuadranglePreference = false;
129 myTrianglePreference = false;
130 myHelper = (SMESH_MesherHelper*)NULL;
135 aStatus = SMESH_Hypothesis::HYP_OK;
137 const list <const SMESHDS_Hypothesis * >& hyps =
138 GetUsedHypothesis(aMesh, aShape, false);
139 const SMESHDS_Hypothesis * aHyp = 0;
141 bool isFirstParams = true;
143 // First assigned hypothesis (if any) is processed now
144 if (hyps.size() > 0) {
146 if (strcmp("QuadrangleParams", aHyp->GetName()) == 0)
148 myParams = (const StdMeshers_QuadrangleParams*)aHyp;
149 myTriaVertexID = myParams->GetTriaVertex();
150 myQuadType = myParams->GetQuadType();
151 if (myQuadType == QUAD_QUADRANGLE_PREF ||
152 myQuadType == QUAD_QUADRANGLE_PREF_REVERSED)
153 myQuadranglePreference = true;
154 else if (myQuadType == QUAD_TRIANGLE_PREF)
155 myTrianglePreference = true;
157 else if (strcmp("QuadranglePreference", aHyp->GetName()) == 0) {
158 isFirstParams = false;
159 myQuadranglePreference = true;
161 else if (strcmp("TrianglePreference", aHyp->GetName()) == 0){
162 isFirstParams = false;
163 myTrianglePreference = true;
166 isFirstParams = false;
170 // Second(last) assigned hypothesis (if any) is processed now
171 if (hyps.size() > 1) {
174 if (strcmp("QuadranglePreference", aHyp->GetName()) == 0) {
175 myQuadranglePreference = true;
176 myTrianglePreference = false;
177 myQuadType = QUAD_STANDARD;
179 else if (strcmp("TrianglePreference", aHyp->GetName()) == 0){
180 myQuadranglePreference = false;
181 myTrianglePreference = true;
182 myQuadType = QUAD_STANDARD;
186 const StdMeshers_QuadrangleParams* aHyp2 =
187 (const StdMeshers_QuadrangleParams*)aHyp;
188 myTriaVertexID = aHyp2->GetTriaVertex();
190 if (!myQuadranglePreference && !myTrianglePreference) { // priority of hypos
191 myQuadType = aHyp2->GetQuadType();
192 if (myQuadType == QUAD_QUADRANGLE_PREF ||
193 myQuadType == QUAD_QUADRANGLE_PREF_REVERSED)
194 myQuadranglePreference = true;
195 else if (myQuadType == QUAD_TRIANGLE_PREF)
196 myTrianglePreference = true;
204 //=============================================================================
208 //=============================================================================
210 bool StdMeshers_Quadrangle_2D::Compute (SMESH_Mesh& aMesh,
211 const TopoDS_Shape& aShape)
213 const TopoDS_Face& F = TopoDS::Face(aShape);
214 aMesh.GetSubMesh( F );
216 // do not initialize my fields before this as StdMeshers_ViscousLayers2D
217 // can call Compute() recursively
218 SMESH_ProxyMesh::Ptr proxyMesh = StdMeshers_ViscousLayers2D::Compute( aMesh, F );
222 myProxyMesh = proxyMesh;
224 SMESH_MesherHelper helper (aMesh);
227 _quadraticMesh = myHelper->IsQuadraticSubMesh(aShape);
228 myNeedSmooth = false;
230 FaceQuadStruct::Ptr quad = CheckNbEdges( aMesh, F, /*considerMesh=*/true );
234 myQuadList.push_back( quad );
236 if ( !getEnforcedUV() )
239 updateDegenUV( quad );
241 int n1 = quad->side[0].NbPoints();
242 int n2 = quad->side[1].NbPoints();
243 int n3 = quad->side[2].NbPoints();
244 int n4 = quad->side[3].NbPoints();
246 enum { NOT_COMPUTED = -1, COMPUTE_FAILED = 0, COMPUTE_OK = 1 };
247 int res = NOT_COMPUTED;
248 if (myQuadranglePreference)
250 int nfull = n1+n2+n3+n4;
251 if ((nfull % 2) == 0 && ((n1 != n3) || (n2 != n4)))
253 // special path genarating only quandrangle faces
254 res = computeQuadPref( aMesh, F, quad );
257 else if (myQuadType == QUAD_REDUCED)
261 int n13tmp = n13/2; n13tmp = n13tmp*2;
262 int n24tmp = n24/2; n24tmp = n24tmp*2;
263 if ((n1 == n3 && n2 != n4 && n24tmp == n24) ||
264 (n2 == n4 && n1 != n3 && n13tmp == n13))
266 res = computeReduced( aMesh, F, quad );
270 if ( n1 != n3 && n2 != n4 )
271 error( COMPERR_WARNING,
272 "To use 'Reduced' transition, "
273 "two opposite sides should have same number of segments, "
274 "but actual number of segments is different on all sides. "
275 "'Standard' transion has been used.");
277 error( COMPERR_WARNING,
278 "To use 'Reduced' transition, "
279 "two opposite sides should have an even difference in number of segments. "
280 "'Standard' transion has been used.");
284 if ( res == NOT_COMPUTED )
286 if ( n1 != n3 || n2 != n4 )
287 res = computeTriangles( aMesh, F, quad );
289 res = computeQuadDominant( aMesh, F );
292 if ( res == COMPUTE_OK && myNeedSmooth )
295 return ( res == COMPUTE_OK );
298 //================================================================================
300 * \brief Compute quadrangles and triangles on the quad
302 //================================================================================
304 bool StdMeshers_Quadrangle_2D::computeTriangles(SMESH_Mesh& aMesh,
305 const TopoDS_Face& aFace,
306 FaceQuadStruct::Ptr quad)
308 int nb = quad->side[0].grid->NbPoints();
309 int nr = quad->side[1].grid->NbPoints();
310 int nt = quad->side[2].grid->NbPoints();
311 int nl = quad->side[3].grid->NbPoints();
313 // rotate the quad to have nbNodeOut sides on TOP [and LEFT]
315 quad->shift( nl > nr ? 3 : 2, true );
317 quad->shift( 1, true );
319 quad->shift( nt > nb ? 0 : 3, true );
321 if ( !setNormalizedGrid( quad ))
324 if ( quad->nbNodeOut( QUAD_TOP_SIDE ))
326 splitQuad( quad, 0, quad->jSize-2 );
328 if ( quad->nbNodeOut( QUAD_BOTTOM_SIDE )) // this should not happen
330 splitQuad( quad, 0, 1 );
332 FaceQuadStruct::Ptr newQuad = myQuadList.back();
333 if ( quad != newQuad ) // split done
336 FaceQuadStruct::Ptr botQuad = // a bottom part
337 ( quad->side[ QUAD_LEFT_SIDE ].from == 0 ) ? quad : newQuad;
338 if ( botQuad->nbNodeOut( QUAD_LEFT_SIDE ) > 0 )
339 botQuad->side[ QUAD_LEFT_SIDE ].to += botQuad->nbNodeOut( QUAD_LEFT_SIDE );
340 else if ( botQuad->nbNodeOut( QUAD_RIGHT_SIDE ) > 0 )
341 botQuad->side[ QUAD_RIGHT_SIDE ].to += botQuad->nbNodeOut( QUAD_RIGHT_SIDE );
343 // make quad be a greatest one
344 if ( quad->side[ QUAD_LEFT_SIDE ].NbPoints() == 2 ||
345 quad->side[ QUAD_RIGHT_SIDE ].NbPoints() == 2 )
347 if ( !setNormalizedGrid( quad ))
351 if ( quad->nbNodeOut( QUAD_RIGHT_SIDE ))
353 splitQuad( quad, quad->iSize-2, 0 );
355 if ( quad->nbNodeOut( QUAD_LEFT_SIDE ))
357 splitQuad( quad, 1, 0 );
360 return computeQuadDominant( aMesh, aFace );
363 //================================================================================
365 * \brief Compute quadrangles and possibly triangles on all quads of myQuadList
367 //================================================================================
369 bool StdMeshers_Quadrangle_2D::computeQuadDominant(SMESH_Mesh& aMesh,
370 const TopoDS_Face& aFace)
372 if ( !addEnforcedNodes() )
375 std::list< FaceQuadStruct::Ptr >::iterator quad = myQuadList.begin();
376 for ( ; quad != myQuadList.end(); ++quad )
377 if ( !computeQuadDominant( aMesh, aFace, *quad ))
383 //================================================================================
385 * \brief Compute quadrangles and possibly triangles
387 //================================================================================
389 bool StdMeshers_Quadrangle_2D::computeQuadDominant(SMESH_Mesh& aMesh,
390 const TopoDS_Face& aFace,
391 FaceQuadStruct::Ptr quad)
393 // --- set normalized grid on unit square in parametric domain
395 if ( !setNormalizedGrid( quad ))
398 // --- create nodes on points, and create quadrangles
400 int nbhoriz = quad->iSize;
401 int nbvertic = quad->jSize;
403 // internal mesh nodes
404 SMESHDS_Mesh * meshDS = aMesh.GetMeshDS();
405 Handle(Geom_Surface) S = BRep_Tool::Surface(aFace);
406 int i,j, geomFaceID = meshDS->ShapeToIndex(aFace);
407 for (i = 1; i < nbhoriz - 1; i++)
408 for (j = 1; j < nbvertic - 1; j++)
410 UVPtStruct& uvPnt = quad->UVPt( i, j );
411 gp_Pnt P = S->Value( uvPnt.u, uvPnt.v );
412 uvPnt.node = meshDS->AddNode(P.X(), P.Y(), P.Z());
413 meshDS->SetNodeOnFace( uvPnt.node, geomFaceID, uvPnt.u, uvPnt.v );
419 // --.--.--.--.--.-- nbvertic
425 // ---.----.----.--- 0
426 // 0 > > > > > > > > nbhoriz
431 int iup = nbhoriz - 1;
432 if (quad->nbNodeOut(3)) { ilow++; } else { if (quad->nbNodeOut(1)) iup--; }
435 int jup = nbvertic - 1;
436 if (quad->nbNodeOut(0)) { jlow++; } else { if (quad->nbNodeOut(2)) jup--; }
438 // regular quadrangles
439 for (i = ilow; i < iup; i++) {
440 for (j = jlow; j < jup; j++) {
441 const SMDS_MeshNode *a, *b, *c, *d;
442 a = quad->uv_grid[ j * nbhoriz + i ].node;
443 b = quad->uv_grid[ j * nbhoriz + i + 1].node;
444 c = quad->uv_grid[(j + 1) * nbhoriz + i + 1].node;
445 d = quad->uv_grid[(j + 1) * nbhoriz + i ].node;
446 SMDS_MeshFace* face = myHelper->AddFace(a, b, c, d);
448 meshDS->SetMeshElementOnShape(face, geomFaceID);
453 // Boundary elements (must always be on an outer boundary of the FACE)
455 const vector<UVPtStruct>& uv_e0 = quad->side[0].grid->GetUVPtStruct();
456 const vector<UVPtStruct>& uv_e1 = quad->side[1].grid->GetUVPtStruct();
457 const vector<UVPtStruct>& uv_e2 = quad->side[2].grid->GetUVPtStruct();
458 const vector<UVPtStruct>& uv_e3 = quad->side[3].grid->GetUVPtStruct();
460 if (uv_e0.empty() || uv_e1.empty() || uv_e2.empty() || uv_e3.empty())
461 return error(COMPERR_BAD_INPUT_MESH);
463 double eps = Precision::Confusion();
465 int nbdown = (int) uv_e0.size();
466 int nbup = (int) uv_e2.size();
467 int nbright = (int) uv_e1.size();
468 int nbleft = (int) uv_e3.size();
470 if (quad->nbNodeOut(0) && nbvertic == 2) // this should not occure
474 // |___|___|___|___|___|___|
476 // |___|___|___|___|___|___|
478 // |___|___|___|___|___|___| __ first row of the regular grid
479 // . . . . . . . . . __ down edge nodes
481 // >->->->->->->->->->->->-> -- direction of processing
483 int g = 0; // number of last processed node in the regular grid
485 // number of last node of the down edge to be processed
486 int stop = nbdown - 1;
487 // if right edge is out, we will stop at a node, previous to the last one
488 //if (quad->nbNodeOut(1)) stop--;
489 if ( quad->nbNodeOut( QUAD_RIGHT_SIDE ))
490 quad->UVPt( nbhoriz-1, 1 ).node = uv_e1[1].node;
491 if ( quad->nbNodeOut( QUAD_LEFT_SIDE ))
492 quad->UVPt( 0, 1 ).node = uv_e3[1].node;
494 // for each node of the down edge find nearest node
495 // in the first row of the regular grid and link them
496 for (i = 0; i < stop; i++) {
497 const SMDS_MeshNode *a, *b, *c, *d;
499 b = uv_e0[i + 1].node;
500 gp_Pnt pb (b->X(), b->Y(), b->Z());
502 // find node c in the regular grid, which will be linked with node b
505 // right bound reached, link with the rightmost node
507 c = quad->uv_grid[nbhoriz + iup].node;
510 // find in the grid node c, nearest to the b
511 double mind = RealLast();
512 for (int k = g; k <= iup; k++) {
514 const SMDS_MeshNode *nk;
515 if (k < ilow) // this can be, if left edge is out
516 nk = uv_e3[1].node; // get node from the left edge
518 nk = quad->uv_grid[nbhoriz + k].node; // get one of middle nodes
520 gp_Pnt pnk (nk->X(), nk->Y(), nk->Z());
521 double dist = pb.Distance(pnk);
522 if (dist < mind - eps) {
532 if (near == g) { // make triangle
533 SMDS_MeshFace* face = myHelper->AddFace(a, b, c);
534 if (face) meshDS->SetMeshElementOnShape(face, geomFaceID);
536 else { // make quadrangle
540 d = quad->uv_grid[nbhoriz + near - 1].node;
541 //SMDS_MeshFace* face = meshDS->AddFace(a, b, c, d);
543 if (!myTrianglePreference){
544 SMDS_MeshFace* face = myHelper->AddFace(a, b, c, d);
545 if (face) meshDS->SetMeshElementOnShape(face, geomFaceID);
548 splitQuadFace(meshDS, geomFaceID, a, b, c, d);
551 // if node d is not at position g - make additional triangles
553 for (int k = near - 1; k > g; k--) {
554 c = quad->uv_grid[nbhoriz + k].node;
558 d = quad->uv_grid[nbhoriz + k - 1].node;
559 SMDS_MeshFace* face = myHelper->AddFace(a, c, d);
560 if (face) meshDS->SetMeshElementOnShape(face, geomFaceID);
567 if (quad->nbNodeOut(2) && nbvertic == 2)
571 // <-<-<-<-<-<-<-<-<-<-<-<-< -- direction of processing
573 // . . . . . . . . . __ up edge nodes
574 // ___ ___ ___ ___ ___ ___ __ first row of the regular grid
576 // |___|___|___|___|___|___|
578 // |___|___|___|___|___|___|
581 int g = nbhoriz - 1; // last processed node in the regular grid
587 // if left edge is out, we will stop at a second node
588 //if (quad->nbNodeOut(3)) stop++;
589 if ( quad->nbNodeOut( QUAD_RIGHT_SIDE ))
590 quad->UVPt( nbhoriz-1, 0 ).node = uv_e1[ nbright-2 ].node;
591 if ( quad->nbNodeOut( QUAD_LEFT_SIDE ))
592 quad->UVPt( 0, 0 ).node = uv_e3[ nbleft-2 ].node;
594 // for each node of the up edge find nearest node
595 // in the first row of the regular grid and link them
596 for (i = nbup - 1; i > stop; i--) {
597 const SMDS_MeshNode *a, *b, *c, *d;
599 b = uv_e2[i - 1].node;
600 gp_Pnt pb (b->X(), b->Y(), b->Z());
602 // find node c in the grid, which will be linked with node b
604 if (i == stop + 1) { // left bound reached, link with the leftmost node
605 c = quad->uv_grid[nbhoriz*(nbvertic - 2) + ilow].node;
608 // find node c in the grid, nearest to the b
609 double mind = RealLast();
610 for (int k = g; k >= ilow; k--) {
611 const SMDS_MeshNode *nk;
613 nk = uv_e1[nbright - 2].node;
615 nk = quad->uv_grid[nbhoriz*(nbvertic - 2) + k].node;
616 gp_Pnt pnk (nk->X(), nk->Y(), nk->Z());
617 double dist = pb.Distance(pnk);
618 if (dist < mind - eps) {
628 if (near == g) { // make triangle
629 SMDS_MeshFace* face = myHelper->AddFace(a, b, c);
630 if (face) meshDS->SetMeshElementOnShape(face, geomFaceID);
632 else { // make quadrangle
634 d = uv_e1[nbright - 2].node;
636 d = quad->uv_grid[nbhoriz*(nbvertic - 2) + near + 1].node;
637 //SMDS_MeshFace* face = meshDS->AddFace(a, b, c, d);
638 if (!myTrianglePreference){
639 SMDS_MeshFace* face = myHelper->AddFace(a, b, c, d);
640 if (face) meshDS->SetMeshElementOnShape(face, geomFaceID);
643 splitQuadFace(meshDS, geomFaceID, a, b, c, d);
646 if (near + 1 < g) { // if d is not at g - make additional triangles
647 for (int k = near + 1; k < g; k++) {
648 c = quad->uv_grid[nbhoriz*(nbvertic - 2) + k].node;
650 d = uv_e1[nbright - 2].node;
652 d = quad->uv_grid[nbhoriz*(nbvertic - 2) + k + 1].node;
653 SMDS_MeshFace* face = myHelper->AddFace(a, c, d);
654 if (face) meshDS->SetMeshElementOnShape(face, geomFaceID);
663 // right or left boundary quadrangles
664 if (quad->nbNodeOut( QUAD_RIGHT_SIDE ) && nbhoriz == 2) // this should not occure
666 int g = 0; // last processed node in the grid
667 int stop = nbright - 1;
669 if (quad->side[ QUAD_RIGHT_SIDE ].from != i ) i++;
670 if (quad->side[ QUAD_RIGHT_SIDE ].to != stop ) stop--;
671 for ( ; i < stop; i++) {
672 const SMDS_MeshNode *a, *b, *c, *d;
674 b = uv_e1[i + 1].node;
675 gp_Pnt pb (b->X(), b->Y(), b->Z());
677 // find node c in the grid, nearest to the b
679 if (i == stop - 1) { // up bondary reached
680 c = quad->uv_grid[nbhoriz*(jup + 1) - 2].node;
683 double mind = RealLast();
684 for (int k = g; k <= jup; k++) {
685 const SMDS_MeshNode *nk;
687 nk = uv_e0[nbdown - 2].node;
689 nk = quad->uv_grid[nbhoriz*(k + 1) - 2].node;
690 gp_Pnt pnk (nk->X(), nk->Y(), nk->Z());
691 double dist = pb.Distance(pnk);
692 if (dist < mind - eps) {
702 if (near == g) { // make triangle
703 SMDS_MeshFace* face = myHelper->AddFace(a, b, c);
704 if (face) meshDS->SetMeshElementOnShape(face, geomFaceID);
706 else { // make quadrangle
708 d = uv_e0[nbdown - 2].node;
710 d = quad->uv_grid[nbhoriz*near - 2].node;
711 //SMDS_MeshFace* face = meshDS->AddFace(a, b, c, d);
713 if (!myTrianglePreference){
714 SMDS_MeshFace* face = myHelper->AddFace(a, b, c, d);
715 if (face) meshDS->SetMeshElementOnShape(face, geomFaceID);
718 splitQuadFace(meshDS, geomFaceID, a, b, c, d);
721 if (near - 1 > g) { // if d not is at g - make additional triangles
722 for (int k = near - 1; k > g; k--) {
723 c = quad->uv_grid[nbhoriz*(k + 1) - 2].node;
725 d = uv_e0[nbdown - 2].node;
727 d = quad->uv_grid[nbhoriz*k - 2].node;
728 SMDS_MeshFace* face = myHelper->AddFace(a, c, d);
729 if (face) meshDS->SetMeshElementOnShape(face, geomFaceID);
736 if (quad->nbNodeOut(3) && nbhoriz == 2) {
737 // MESSAGE("left edge is out");
738 int g = nbvertic - 1; // last processed node in the grid
740 i = quad->side[ QUAD_LEFT_SIDE ].to-1; // nbleft - 1;
741 for (; i > stop; i--) {
742 const SMDS_MeshNode *a, *b, *c, *d;
744 b = uv_e3[i - 1].node;
745 gp_Pnt pb (b->X(), b->Y(), b->Z());
747 // find node c in the grid, nearest to the b
749 if (i == stop + 1) { // down bondary reached
750 c = quad->uv_grid[nbhoriz*jlow + 1].node;
753 double mind = RealLast();
754 for (int k = g; k >= jlow; k--) {
755 const SMDS_MeshNode *nk;
759 nk = quad->uv_grid[nbhoriz*k + 1].node;
760 gp_Pnt pnk (nk->X(), nk->Y(), nk->Z());
761 double dist = pb.Distance(pnk);
762 if (dist < mind - eps) {
772 if (near == g) { // make triangle
773 SMDS_MeshFace* face = myHelper->AddFace(a, b, c);
774 if (face) meshDS->SetMeshElementOnShape(face, geomFaceID);
776 else { // make quadrangle
780 d = quad->uv_grid[nbhoriz*(near + 1) + 1].node;
781 //SMDS_MeshFace* face = meshDS->AddFace(a, b, c, d);
782 if (!myTrianglePreference){
783 SMDS_MeshFace* face = myHelper->AddFace(a, b, c, d);
784 if (face) meshDS->SetMeshElementOnShape(face, geomFaceID);
787 splitQuadFace(meshDS, geomFaceID, a, b, c, d);
790 if (near + 1 < g) { // if d not is at g - make additional triangles
791 for (int k = near + 1; k < g; k++) {
792 c = quad->uv_grid[nbhoriz*k + 1].node;
796 d = quad->uv_grid[nbhoriz*(k + 1) + 1].node;
797 SMDS_MeshFace* face = myHelper->AddFace(a, c, d);
798 if (face) meshDS->SetMeshElementOnShape(face, geomFaceID);
812 //=============================================================================
816 //=============================================================================
818 bool StdMeshers_Quadrangle_2D::Evaluate(SMESH_Mesh& aMesh,
819 const TopoDS_Shape& aFace,
820 MapShapeNbElems& aResMap)
823 aMesh.GetSubMesh(aFace);
825 std::vector<int> aNbNodes(4);
826 bool IsQuadratic = false;
827 if (!checkNbEdgesForEvaluate(aMesh, aFace, aResMap, aNbNodes, IsQuadratic)) {
828 std::vector<int> aResVec(SMDSEntity_Last);
829 for (int i=SMDSEntity_Node; i<SMDSEntity_Last; i++) aResVec[i] = 0;
830 SMESH_subMesh * sm = aMesh.GetSubMesh(aFace);
831 aResMap.insert(std::make_pair(sm,aResVec));
832 SMESH_ComputeErrorPtr& smError = sm->GetComputeError();
833 smError.reset(new SMESH_ComputeError(COMPERR_ALGO_FAILED,"Submesh can not be evaluated",this));
837 if (myQuadranglePreference) {
838 int n1 = aNbNodes[0];
839 int n2 = aNbNodes[1];
840 int n3 = aNbNodes[2];
841 int n4 = aNbNodes[3];
842 int nfull = n1+n2+n3+n4;
845 if (nfull==ntmp && ((n1!=n3) || (n2!=n4))) {
846 // special path for using only quandrangle faces
847 return evaluateQuadPref(aMesh, aFace, aNbNodes, aResMap, IsQuadratic);
852 int nbdown = aNbNodes[0];
853 int nbup = aNbNodes[2];
855 int nbright = aNbNodes[1];
856 int nbleft = aNbNodes[3];
858 int nbhoriz = Min(nbdown, nbup);
859 int nbvertic = Min(nbright, nbleft);
861 int dh = Max(nbdown, nbup) - nbhoriz;
862 int dv = Max(nbright, nbleft) - nbvertic;
869 int nbNodes = (nbhoriz-2)*(nbvertic-2);
870 //int nbFaces3 = dh + dv + kdh*(nbvertic-1)*2 + kdv*(nbhoriz-1)*2;
871 int nbFaces3 = dh + dv;
872 //if (kdh==1 && kdv==1) nbFaces3 -= 2;
873 //if (dh>0 && dv>0) nbFaces3 -= 2;
874 //int nbFaces4 = (nbhoriz-1-kdh)*(nbvertic-1-kdv);
875 int nbFaces4 = (nbhoriz-1)*(nbvertic-1);
877 std::vector<int> aVec(SMDSEntity_Last);
878 for (int i=SMDSEntity_Node; i<SMDSEntity_Last; i++) aVec[i] = 0;
880 aVec[SMDSEntity_Quad_Triangle] = nbFaces3;
881 aVec[SMDSEntity_Quad_Quadrangle] = nbFaces4;
882 int nbbndedges = nbdown + nbup + nbright + nbleft -4;
883 int nbintedges = (nbFaces4*4 + nbFaces3*3 - nbbndedges) / 2;
884 aVec[SMDSEntity_Node] = nbNodes + nbintedges;
885 if (aNbNodes.size()==5) {
886 aVec[SMDSEntity_Quad_Triangle] = nbFaces3 + aNbNodes[3] -1;
887 aVec[SMDSEntity_Quad_Quadrangle] = nbFaces4 - aNbNodes[3] +1;
891 aVec[SMDSEntity_Node] = nbNodes;
892 aVec[SMDSEntity_Triangle] = nbFaces3;
893 aVec[SMDSEntity_Quadrangle] = nbFaces4;
894 if (aNbNodes.size()==5) {
895 aVec[SMDSEntity_Triangle] = nbFaces3 + aNbNodes[3] - 1;
896 aVec[SMDSEntity_Quadrangle] = nbFaces4 - aNbNodes[3] + 1;
899 SMESH_subMesh * sm = aMesh.GetSubMesh(aFace);
900 aResMap.insert(std::make_pair(sm,aVec));
906 //================================================================================
908 * \brief Return true if only two given edges meat at their common vertex
910 //================================================================================
912 static bool twoEdgesMeatAtVertex(const TopoDS_Edge& e1,
913 const TopoDS_Edge& e2,
917 if (!TopExp::CommonVertex(e1, e2, v))
919 TopTools_ListIteratorOfListOfShape ancestIt(mesh.GetAncestors(v));
920 for (; ancestIt.More() ; ancestIt.Next())
921 if (ancestIt.Value().ShapeType() == TopAbs_EDGE)
922 if (!e1.IsSame(ancestIt.Value()) && !e2.IsSame(ancestIt.Value()))
927 //=============================================================================
931 //=============================================================================
933 FaceQuadStruct::Ptr StdMeshers_Quadrangle_2D::CheckNbEdges(SMESH_Mesh & aMesh,
934 const TopoDS_Shape & aShape,
935 const bool considerMesh)
937 if ( !myQuadList.empty() && myQuadList.front()->face.IsSame( aShape ))
938 return myQuadList.front();
940 TopoDS_Face F = TopoDS::Face(aShape);
941 if ( F.Orientation() >= TopAbs_INTERNAL ) F.Orientation( TopAbs_FORWARD );
942 const bool ignoreMediumNodes = _quadraticMesh;
944 // verify 1 wire only, with 4 edges
945 list< TopoDS_Edge > edges;
946 list< int > nbEdgesInWire;
947 int nbWire = SMESH_Block::GetOrderedEdges (F, edges, nbEdgesInWire);
949 error(COMPERR_BAD_SHAPE, TComm("Wrong number of wires: ") << nbWire);
950 return FaceQuadStruct::Ptr();
953 // find corner vertices of the quad
954 vector<TopoDS_Vertex> corners;
955 int nbDegenEdges, nbSides = getCorners( F, aMesh, edges, corners, nbDegenEdges, considerMesh );
958 return FaceQuadStruct::Ptr();
960 FaceQuadStruct::Ptr quad( new FaceQuadStruct );
961 quad->side.reserve(nbEdgesInWire.front());
964 list< TopoDS_Edge >::iterator edgeIt = edges.begin();
965 if ( nbSides == 3 ) // 3 sides and corners[0] is a vertex with myTriaVertexID
967 for ( int iSide = 0; iSide < 3; ++iSide )
969 list< TopoDS_Edge > sideEdges;
970 TopoDS_Vertex nextSideV = corners[( iSide + 1 ) % 3 ];
971 while ( edgeIt != edges.end() &&
972 !nextSideV.IsSame( SMESH_MesherHelper::IthVertex( 0, *edgeIt )))
973 if ( SMESH_Algo::isDegenerated( *edgeIt ))
976 sideEdges.push_back( *edgeIt++ );
977 if ( !sideEdges.empty() )
978 quad->side.push_back( StdMeshers_FaceSide::New(F, sideEdges, &aMesh, iSide < QUAD_TOP_SIDE,
979 ignoreMediumNodes, myProxyMesh));
983 const vector<UVPtStruct>& UVPSleft = quad->side[0].GetUVPtStruct(true,0);
984 /* vector<UVPtStruct>& UVPStop = */quad->side[1].GetUVPtStruct(false,1);
985 /* vector<UVPtStruct>& UVPSright = */quad->side[2].GetUVPtStruct(true,1);
986 const SMDS_MeshNode* aNode = UVPSleft[0].node;
987 gp_Pnt2d aPnt2d = UVPSleft[0].UV();
988 quad->side.push_back( StdMeshers_FaceSide::New( quad->side[1].grid.get(), aNode, &aPnt2d ));
989 myNeedSmooth = ( nbDegenEdges > 0 );
994 myNeedSmooth = ( corners.size() == 4 && nbDegenEdges > 0 );
995 int iSide = 0, nbUsedDegen = 0, nbLoops = 0;
996 for ( ; edgeIt != edges.end(); ++nbLoops )
998 list< TopoDS_Edge > sideEdges;
999 TopoDS_Vertex nextSideV = corners[( iSide + 1 - nbUsedDegen ) % corners.size() ];
1000 while ( edgeIt != edges.end() &&
1001 !nextSideV.IsSame( myHelper->IthVertex( 0, *edgeIt )))
1003 if ( SMESH_Algo::isDegenerated( *edgeIt ) )
1007 ++edgeIt; // no side on the degenerated EDGE
1011 if ( sideEdges.empty() )
1014 sideEdges.push_back( *edgeIt++ ); // a degenerated side
1019 break; // do not append a degenerated EDGE to a regular side
1025 sideEdges.push_back( *edgeIt++ );
1028 if ( !sideEdges.empty() )
1030 quad->side.push_back( StdMeshers_FaceSide::New( F, sideEdges, &aMesh, iSide < QUAD_TOP_SIDE,
1031 ignoreMediumNodes, myProxyMesh ));
1034 else if ( !SMESH_Algo::isDegenerated( *edgeIt ) && // closed EDGE
1035 myHelper->IthVertex( 0, *edgeIt ).IsSame( myHelper->IthVertex( 1, *edgeIt )))
1037 quad->side.push_back( StdMeshers_FaceSide::New( F, *edgeIt++, &aMesh, iSide < QUAD_TOP_SIDE,
1038 ignoreMediumNodes, myProxyMesh));
1041 if ( quad->side.size() == 4 )
1045 error(TComm("Bug: infinite loop in StdMeshers_Quadrangle_2D::CheckNbEdges()"));
1050 if ( quad && quad->side.size() != 4 )
1052 error(TComm("Bug: ") << quad->side.size() << " sides found instead of 4");
1061 //=============================================================================
1065 //=============================================================================
1067 bool StdMeshers_Quadrangle_2D::checkNbEdgesForEvaluate(SMESH_Mesh& aMesh,
1068 const TopoDS_Shape & aShape,
1069 MapShapeNbElems& aResMap,
1070 std::vector<int>& aNbNodes,
1074 const TopoDS_Face & F = TopoDS::Face(aShape);
1076 // verify 1 wire only, with 4 edges
1077 list< TopoDS_Edge > edges;
1078 list< int > nbEdgesInWire;
1079 int nbWire = SMESH_Block::GetOrderedEdges (F, edges, nbEdgesInWire);
1087 list< TopoDS_Edge >::iterator edgeIt = edges.begin();
1088 SMESH_subMesh * sm = aMesh.GetSubMesh(*edgeIt);
1089 MapShapeNbElemsItr anIt = aResMap.find(sm);
1090 if (anIt==aResMap.end()) {
1093 std::vector<int> aVec = (*anIt).second;
1094 IsQuadratic = (aVec[SMDSEntity_Quad_Edge] > aVec[SMDSEntity_Edge]);
1095 if (nbEdgesInWire.front() == 3) { // exactly 3 edges
1096 if (myTriaVertexID>0) {
1097 SMESHDS_Mesh* meshDS = aMesh.GetMeshDS();
1098 TopoDS_Vertex V = TopoDS::Vertex(meshDS->IndexToShape(myTriaVertexID));
1100 TopoDS_Edge E1,E2,E3;
1101 for (; edgeIt != edges.end(); ++edgeIt) {
1102 TopoDS_Edge E = TopoDS::Edge(*edgeIt);
1103 TopoDS_Vertex VF, VL;
1104 TopExp::Vertices(E, VF, VL, true);
1107 else if (VL.IsSame(V))
1112 SMESH_subMesh * sm = aMesh.GetSubMesh(E1);
1113 MapShapeNbElemsItr anIt = aResMap.find(sm);
1114 if (anIt==aResMap.end()) return false;
1115 std::vector<int> aVec = (*anIt).second;
1117 aNbNodes[0] = (aVec[SMDSEntity_Node]-1)/2 + 2;
1119 aNbNodes[0] = aVec[SMDSEntity_Node] + 2;
1120 sm = aMesh.GetSubMesh(E2);
1121 anIt = aResMap.find(sm);
1122 if (anIt==aResMap.end()) return false;
1123 aVec = (*anIt).second;
1125 aNbNodes[1] = (aVec[SMDSEntity_Node]-1)/2 + 2;
1127 aNbNodes[1] = aVec[SMDSEntity_Node] + 2;
1128 sm = aMesh.GetSubMesh(E3);
1129 anIt = aResMap.find(sm);
1130 if (anIt==aResMap.end()) return false;
1131 aVec = (*anIt).second;
1133 aNbNodes[2] = (aVec[SMDSEntity_Node]-1)/2 + 2;
1135 aNbNodes[2] = aVec[SMDSEntity_Node] + 2;
1136 aNbNodes[3] = aNbNodes[1];
1142 if (nbEdgesInWire.front() == 4) { // exactly 4 edges
1143 for (; edgeIt != edges.end(); edgeIt++) {
1144 SMESH_subMesh * sm = aMesh.GetSubMesh(*edgeIt);
1145 MapShapeNbElemsItr anIt = aResMap.find(sm);
1146 if (anIt==aResMap.end()) {
1149 std::vector<int> aVec = (*anIt).second;
1151 aNbNodes[nbSides] = (aVec[SMDSEntity_Node]-1)/2 + 2;
1153 aNbNodes[nbSides] = aVec[SMDSEntity_Node] + 2;
1157 else if (nbEdgesInWire.front() > 4) { // more than 4 edges - try to unite some
1158 list< TopoDS_Edge > sideEdges;
1159 while (!edges.empty()) {
1161 sideEdges.splice(sideEdges.end(), edges, edges.begin()); // edges.front() -> sideEdges.end()
1162 bool sameSide = true;
1163 while (!edges.empty() && sameSide) {
1164 sameSide = SMESH_Algo::IsContinuous(sideEdges.back(), edges.front());
1166 sideEdges.splice(sideEdges.end(), edges, edges.begin());
1168 if (nbSides == 0) { // go backward from the first edge
1170 while (!edges.empty() && sameSide) {
1171 sameSide = SMESH_Algo::IsContinuous(sideEdges.front(), edges.back());
1173 sideEdges.splice(sideEdges.begin(), edges, --edges.end());
1176 list<TopoDS_Edge>::iterator ite = sideEdges.begin();
1177 aNbNodes[nbSides] = 1;
1178 for (; ite!=sideEdges.end(); ite++) {
1179 SMESH_subMesh * sm = aMesh.GetSubMesh(*ite);
1180 MapShapeNbElemsItr anIt = aResMap.find(sm);
1181 if (anIt==aResMap.end()) {
1184 std::vector<int> aVec = (*anIt).second;
1186 aNbNodes[nbSides] += (aVec[SMDSEntity_Node]-1)/2 + 1;
1188 aNbNodes[nbSides] += aVec[SMDSEntity_Node] + 1;
1192 // issue 20222. Try to unite only edges shared by two same faces
1195 SMESH_Block::GetOrderedEdges (F, edges, nbEdgesInWire);
1196 while (!edges.empty()) {
1198 sideEdges.splice(sideEdges.end(), edges, edges.begin());
1199 bool sameSide = true;
1200 while (!edges.empty() && sameSide) {
1202 SMESH_Algo::IsContinuous(sideEdges.back(), edges.front()) &&
1203 twoEdgesMeatAtVertex(sideEdges.back(), edges.front(), aMesh);
1205 sideEdges.splice(sideEdges.end(), edges, edges.begin());
1207 if (nbSides == 0) { // go backward from the first edge
1209 while (!edges.empty() && sameSide) {
1211 SMESH_Algo::IsContinuous(sideEdges.front(), edges.back()) &&
1212 twoEdgesMeatAtVertex(sideEdges.front(), edges.back(), aMesh);
1214 sideEdges.splice(sideEdges.begin(), edges, --edges.end());
1217 list<TopoDS_Edge>::iterator ite = sideEdges.begin();
1218 aNbNodes[nbSides] = 1;
1219 for (; ite!=sideEdges.end(); ite++) {
1220 SMESH_subMesh * sm = aMesh.GetSubMesh(*ite);
1221 MapShapeNbElemsItr anIt = aResMap.find(sm);
1222 if (anIt==aResMap.end()) {
1225 std::vector<int> aVec = (*anIt).second;
1227 aNbNodes[nbSides] += (aVec[SMDSEntity_Node]-1)/2 + 1;
1229 aNbNodes[nbSides] += aVec[SMDSEntity_Node] + 1;
1237 nbSides = nbEdgesInWire.front();
1238 error(COMPERR_BAD_SHAPE, TComm("Face must have 4 sides but not ") << nbSides);
1246 //=============================================================================
1250 //=============================================================================
1253 StdMeshers_Quadrangle_2D::CheckAnd2Dcompute (SMESH_Mesh & aMesh,
1254 const TopoDS_Shape & aShape,
1255 const bool CreateQuadratic)
1257 _quadraticMesh = CreateQuadratic;
1259 FaceQuadStruct::Ptr quad = CheckNbEdges(aMesh, aShape);
1262 // set normalized grid on unit square in parametric domain
1263 if ( ! setNormalizedGrid( quad ))
1271 inline const vector<UVPtStruct>& getUVPtStructIn(FaceQuadStruct::Ptr& quad, int i, int nbSeg)
1273 bool isXConst = (i == QUAD_BOTTOM_SIDE || i == QUAD_TOP_SIDE);
1274 double constValue = (i == QUAD_BOTTOM_SIDE || i == QUAD_LEFT_SIDE) ? 0 : 1;
1276 quad->nbNodeOut(i) ?
1277 quad->side[i].grid->SimulateUVPtStruct(nbSeg,isXConst,constValue) :
1278 quad->side[i].grid->GetUVPtStruct (isXConst,constValue);
1280 inline gp_UV calcUV(double x, double y,
1281 const gp_UV& a0,const gp_UV& a1,const gp_UV& a2,const gp_UV& a3,
1282 const gp_UV& p0,const gp_UV& p1,const gp_UV& p2,const gp_UV& p3)
1285 ((1 - y) * p0 + x * p1 + y * p2 + (1 - x) * p3 ) -
1286 ((1 - x) * (1 - y) * a0 + x * (1 - y) * a1 + x * y * a2 + (1 - x) * y * a3);
1290 //=============================================================================
1294 //=============================================================================
1296 bool StdMeshers_Quadrangle_2D::setNormalizedGrid (FaceQuadStruct::Ptr quad)
1298 if ( !quad->uv_grid.empty() )
1301 // Algorithme décrit dans "Génération automatique de maillages"
1302 // P.L. GEORGE, MASSON, § 6.4.1 p. 84-85
1303 // traitement dans le domaine paramétrique 2d u,v
1304 // transport - projection sur le carré unité
1307 // |<----north-2-------^ a3 -------------> a2
1309 // west-3 east-1 =right | |
1313 // v----south-0--------> a0 -------------> a1
1317 const FaceQuadStruct::Side & bSide = quad->side[0];
1318 const FaceQuadStruct::Side & rSide = quad->side[1];
1319 const FaceQuadStruct::Side & tSide = quad->side[2];
1320 const FaceQuadStruct::Side & lSide = quad->side[3];
1322 int nbhoriz = Min( bSide.NbPoints(), tSide.NbPoints() );
1323 int nbvertic = Min( rSide.NbPoints(), lSide.NbPoints() );
1325 if ( myQuadList.size() == 1 )
1327 // all sub-quads must have NO sides with nbNodeOut > 0
1328 quad->nbNodeOut(0) = Max( 0, bSide.grid->NbPoints() - tSide.grid->NbPoints() );
1329 quad->nbNodeOut(1) = Max( 0, rSide.grid->NbPoints() - lSide.grid->NbPoints() );
1330 quad->nbNodeOut(2) = Max( 0, tSide.grid->NbPoints() - bSide.grid->NbPoints() );
1331 quad->nbNodeOut(3) = Max( 0, lSide.grid->NbPoints() - rSide.grid->NbPoints() );
1333 const vector<UVPtStruct>& uv_e0 = bSide.GetUVPtStruct();
1334 const vector<UVPtStruct>& uv_e1 = rSide.GetUVPtStruct();
1335 const vector<UVPtStruct>& uv_e2 = tSide.GetUVPtStruct();
1336 const vector<UVPtStruct>& uv_e3 = lSide.GetUVPtStruct();
1337 if (uv_e0.empty() || uv_e1.empty() || uv_e2.empty() || uv_e3.empty())
1338 //return error("Can't find nodes on sides");
1339 return error(COMPERR_BAD_INPUT_MESH);
1341 quad->uv_grid.resize( nbvertic * nbhoriz );
1342 quad->iSize = nbhoriz;
1343 quad->jSize = nbvertic;
1344 UVPtStruct *uv_grid = & quad->uv_grid[0];
1346 quad->uv_box.Clear();
1348 // copy data of face boundary
1350 FaceQuadStruct::SideIterator sideIter;
1354 const double x0 = bSide.First().normParam;
1355 const double dx = bSide.Last().normParam - bSide.First().normParam;
1356 for ( sideIter.Init( bSide ); sideIter.More(); sideIter.Next() ) {
1357 sideIter.UVPt().x = ( sideIter.UVPt().normParam - x0 ) / dx;
1358 sideIter.UVPt().y = 0.;
1359 uv_grid[ j * nbhoriz + sideIter.Count() ] = sideIter.UVPt();
1360 quad->uv_box.Add( sideIter.UVPt().UV() );
1364 const int i = nbhoriz - 1;
1365 const double y0 = rSide.First().normParam;
1366 const double dy = rSide.Last().normParam - rSide.First().normParam;
1367 sideIter.Init( rSide );
1368 if ( quad->UVPt( i, sideIter.Count() ).node )
1369 sideIter.Next(); // avoid copying from a split emulated side
1370 for ( ; sideIter.More(); sideIter.Next() ) {
1371 sideIter.UVPt().x = 1.;
1372 sideIter.UVPt().y = ( sideIter.UVPt().normParam - y0 ) / dy;
1373 uv_grid[ sideIter.Count() * nbhoriz + i ] = sideIter.UVPt();
1374 quad->uv_box.Add( sideIter.UVPt().UV() );
1378 const int j = nbvertic - 1;
1379 const double x0 = tSide.First().normParam;
1380 const double dx = tSide.Last().normParam - tSide.First().normParam;
1381 int i = 0, nb = nbhoriz;
1382 sideIter.Init( tSide );
1383 if ( quad->UVPt( nb-1, j ).node ) --nb; // avoid copying from a split emulated side
1384 for ( ; i < nb; i++, sideIter.Next()) {
1385 sideIter.UVPt().x = ( sideIter.UVPt().normParam - x0 ) / dx;
1386 sideIter.UVPt().y = 1.;
1387 uv_grid[ j * nbhoriz + i ] = sideIter.UVPt();
1388 quad->uv_box.Add( sideIter.UVPt().UV() );
1393 const double y0 = lSide.First().normParam;
1394 const double dy = lSide.Last().normParam - lSide.First().normParam;
1395 int j = 0, nb = nbvertic;
1396 sideIter.Init( lSide );
1397 if ( quad->UVPt( i, j ).node )
1398 ++j, sideIter.Next(); // avoid copying from a split emulated side
1399 if ( quad->UVPt( i, nb-1 ).node )
1401 for ( ; j < nb; j++, sideIter.Next()) {
1402 sideIter.UVPt().x = 0.;
1403 sideIter.UVPt().y = ( sideIter.UVPt().normParam - y0 ) / dy;
1404 uv_grid[ j * nbhoriz + i ] = sideIter.UVPt();
1405 quad->uv_box.Add( sideIter.UVPt().UV() );
1409 // normalized 2d parameters on grid
1411 for (int i = 1; i < nbhoriz-1; i++)
1413 const double x0 = quad->UVPt( i, 0 ).x;
1414 const double x1 = quad->UVPt( i, nbvertic-1 ).x;
1415 for (int j = 1; j < nbvertic-1; j++)
1417 const double y0 = quad->UVPt( 0, j ).y;
1418 const double y1 = quad->UVPt( nbhoriz-1, j ).y;
1419 // --- intersection : x=x0+(y0+x(y1-y0))(x1-x0)
1420 double x = (x0 + y0 * (x1 - x0)) / (1 - (y1 - y0) * (x1 - x0));
1421 double y = y0 + x * (y1 - y0);
1422 int ij = j * nbhoriz + i;
1425 uv_grid[ij].node = NULL;
1429 // projection on 2d domain (u,v)
1431 gp_UV a0 = quad->UVPt( 0, 0 ).UV();
1432 gp_UV a1 = quad->UVPt( nbhoriz-1, 0 ).UV();
1433 gp_UV a2 = quad->UVPt( nbhoriz-1, nbvertic-1 ).UV();
1434 gp_UV a3 = quad->UVPt( 0, nbvertic-1 ).UV();
1436 for (int i = 1; i < nbhoriz-1; i++)
1438 gp_UV p0 = quad->UVPt( i, 0 ).UV();
1439 gp_UV p2 = quad->UVPt( i, nbvertic-1 ).UV();
1440 for (int j = 1; j < nbvertic-1; j++)
1442 gp_UV p1 = quad->UVPt( nbhoriz-1, j ).UV();
1443 gp_UV p3 = quad->UVPt( 0, j ).UV();
1445 int ij = j * nbhoriz + i;
1446 double x = uv_grid[ij].x;
1447 double y = uv_grid[ij].y;
1449 gp_UV uv = calcUV(x,y, a0,a1,a2,a3, p0,p1,p2,p3);
1451 uv_grid[ij].u = uv.X();
1452 uv_grid[ij].v = uv.Y();
1458 //=======================================================================
1459 //function : ShiftQuad
1460 //purpose : auxilary function for computeQuadPref
1461 //=======================================================================
1463 void StdMeshers_Quadrangle_2D::shiftQuad(FaceQuadStruct::Ptr& quad, const int num )
1465 quad->shift( num, /*ori=*/true, /*keepGrid=*/myQuadList.size() > 1 );
1468 //================================================================================
1470 * \brief Rotate sides of a quad by given nb of quartes
1471 * \param nb - number of rotation quartes
1472 * \param ori - to keep orientation of sides as in an unit quad or not
1473 * \param keepGrid - if \c true Side::grid is not changed, Side::from and Side::to
1474 * are altered instead
1476 //================================================================================
1478 void FaceQuadStruct::shift( size_t nb, bool ori, bool keepGrid )
1480 if ( nb == 0 ) return;
1482 vector< Side > newSides( side.size() );
1483 vector< Side* > sidePtrs( side.size() );
1484 for (int i = QUAD_BOTTOM_SIDE; i < NB_QUAD_SIDES; ++i)
1486 int id = (i + nb) % NB_QUAD_SIDES;
1489 bool wasForward = (i < QUAD_TOP_SIDE);
1490 bool newForward = (id < QUAD_TOP_SIDE);
1491 if ( wasForward != newForward )
1492 side[ i ].Reverse( keepGrid );
1494 newSides[ id ] = side[ i ];
1495 sidePtrs[ i ] = & side[ i ];
1497 // make newSides refer newSides via Side::Contact's
1498 for ( size_t i = 0; i < newSides.size(); ++i )
1500 FaceQuadStruct::Side& ns = newSides[ i ];
1501 for ( size_t iC = 0; iC < ns.contacts.size(); ++iC )
1503 FaceQuadStruct::Side* oSide = ns.contacts[iC].other_side;
1504 vector< Side* >::iterator sIt = std::find( sidePtrs.begin(), sidePtrs.end(), oSide );
1505 if ( sIt != sidePtrs.end() )
1506 ns.contacts[iC].other_side = & newSides[ *sIt - sidePtrs[0] ];
1509 newSides.swap( side );
1514 //=======================================================================
1516 //purpose : auxilary function for computeQuadPref
1517 //=======================================================================
1519 static gp_UV calcUV(double x0, double x1, double y0, double y1,
1520 FaceQuadStruct::Ptr& quad,
1521 const gp_UV& a0, const gp_UV& a1,
1522 const gp_UV& a2, const gp_UV& a3)
1524 double x = (x0 + y0 * (x1 - x0)) / (1 - (y1 - y0) * (x1 - x0));
1525 double y = y0 + x * (y1 - y0);
1527 gp_UV p0 = quad->side[QUAD_BOTTOM_SIDE].grid->Value2d(x).XY();
1528 gp_UV p1 = quad->side[QUAD_RIGHT_SIDE ].grid->Value2d(y).XY();
1529 gp_UV p2 = quad->side[QUAD_TOP_SIDE ].grid->Value2d(x).XY();
1530 gp_UV p3 = quad->side[QUAD_LEFT_SIDE ].grid->Value2d(y).XY();
1532 gp_UV uv = calcUV(x,y, a0,a1,a2,a3, p0,p1,p2,p3);
1537 //=======================================================================
1538 //function : calcUV2
1539 //purpose : auxilary function for computeQuadPref
1540 //=======================================================================
1542 static gp_UV calcUV2(double x, double y,
1543 FaceQuadStruct::Ptr& quad,
1544 const gp_UV& a0, const gp_UV& a1,
1545 const gp_UV& a2, const gp_UV& a3)
1547 gp_UV p0 = quad->side[QUAD_BOTTOM_SIDE].grid->Value2d(x).XY();
1548 gp_UV p1 = quad->side[QUAD_RIGHT_SIDE ].grid->Value2d(y).XY();
1549 gp_UV p2 = quad->side[QUAD_TOP_SIDE ].grid->Value2d(x).XY();
1550 gp_UV p3 = quad->side[QUAD_LEFT_SIDE ].grid->Value2d(y).XY();
1552 gp_UV uv = calcUV(x,y, a0,a1,a2,a3, p0,p1,p2,p3);
1558 //=======================================================================
1560 * Create only quandrangle faces
1562 //=======================================================================
1564 bool StdMeshers_Quadrangle_2D::computeQuadPref (SMESH_Mesh & aMesh,
1565 const TopoDS_Face& aFace,
1566 FaceQuadStruct::Ptr quad)
1568 const bool OldVersion = (myQuadType == QUAD_QUADRANGLE_PREF_REVERSED);
1569 const bool WisF = true;
1571 SMESHDS_Mesh * meshDS = aMesh.GetMeshDS();
1572 Handle(Geom_Surface) S = BRep_Tool::Surface(aFace);
1573 int i,j, geomFaceID = meshDS->ShapeToIndex(aFace);
1575 int nb = quad->side[0].NbPoints();
1576 int nr = quad->side[1].NbPoints();
1577 int nt = quad->side[2].NbPoints();
1578 int nl = quad->side[3].NbPoints();
1579 int dh = abs(nb-nt);
1580 int dv = abs(nr-nl);
1582 if ( myForcedPnts.empty() )
1584 // rotate sides to be as in the picture below and to have
1585 // dh >= dv and nt > nb
1587 shiftQuad( quad, ( nt > nb ) ? 0 : 2 );
1589 shiftQuad( quad, ( nr > nl ) ? 1 : 3 );
1593 // rotate the quad to have nt > nb [and nr > nl]
1595 shiftQuad ( quad, nr > nl ? 1 : 2 );
1597 shiftQuad( quad, nb == nt ? 1 : 0 );
1599 shiftQuad( quad, 3 );
1602 nb = quad->side[0].NbPoints();
1603 nr = quad->side[1].NbPoints();
1604 nt = quad->side[2].NbPoints();
1605 nl = quad->side[3].NbPoints();
1608 int nbh = Max(nb,nt);
1609 int nbv = Max(nr,nl);
1613 // Orientation of face and 3 main domain for future faces
1614 // ----------- Old version ---------------
1620 // left | |__| | rigth
1627 // ----------- New version ---------------
1633 // left |/________\| rigth
1641 const int bfrom = quad->side[0].from;
1642 const int rfrom = quad->side[1].from;
1643 const int tfrom = quad->side[2].from;
1644 const int lfrom = quad->side[3].from;
1646 const vector<UVPtStruct>& uv_eb_vec = quad->side[0].GetUVPtStruct(true,0);
1647 const vector<UVPtStruct>& uv_er_vec = quad->side[1].GetUVPtStruct(false,1);
1648 const vector<UVPtStruct>& uv_et_vec = quad->side[2].GetUVPtStruct(true,1);
1649 const vector<UVPtStruct>& uv_el_vec = quad->side[3].GetUVPtStruct(false,0);
1650 if (uv_eb_vec.empty() ||
1651 uv_er_vec.empty() ||
1652 uv_et_vec.empty() ||
1654 return error(COMPERR_BAD_INPUT_MESH);
1656 FaceQuadStruct::SideIterator uv_eb, uv_er, uv_et, uv_el;
1657 uv_eb.Init( quad->side[0] );
1658 uv_er.Init( quad->side[1] );
1659 uv_et.Init( quad->side[2] );
1660 uv_el.Init( quad->side[3] );
1662 gp_UV a0,a1,a2,a3, p0,p1,p2,p3, uv;
1665 a0 = uv_eb[ 0 ].UV();
1666 a1 = uv_er[ 0 ].UV();
1667 a2 = uv_er[ nr-1 ].UV();
1668 a3 = uv_et[ 0 ].UV();
1670 if ( !myForcedPnts.empty() )
1672 if ( dv != 0 && dh != 0 ) // here myQuadList.size() == 1
1674 const int dmin = Min( dv, dh );
1676 // Make a side separating domains L and Cb
1677 StdMeshers_FaceSidePtr sideLCb;
1678 UVPtStruct p3dom; // a point where 3 domains meat
1680 vector<UVPtStruct> pointsLCb( dmin+1 ); // 1--------1
1681 pointsLCb[0] = uv_eb[0]; // | | |
1682 for ( int i = 1; i <= dmin; ++i ) // | |Ct|
1684 x = uv_et[ i ].normParam; // | |__|
1685 y = uv_er[ i ].normParam; // | / |
1686 p0 = quad->side[0].grid->Value2d( x ).XY(); // | / Cb |dmin
1687 p1 = uv_er[ i ].UV(); // |/ |
1688 p2 = uv_et[ i ].UV(); // 0--------0
1689 p3 = quad->side[3].grid->Value2d( y ).XY();
1690 uv = calcUV( x,y, a0,a1,a2,a3, p0,p1,p2,p3 );
1691 pointsLCb[ i ].u = uv.X();
1692 pointsLCb[ i ].v = uv.Y();
1694 sideLCb = StdMeshers_FaceSide::New( pointsLCb, aFace );
1695 p3dom = pointsLCb.back();
1697 // Make a side separating domains L and Ct
1698 StdMeshers_FaceSidePtr sideLCt;
1700 vector<UVPtStruct> pointsLCt( nl );
1701 pointsLCt[0] = p3dom;
1702 pointsLCt.back() = uv_et[ dmin ];
1703 x = uv_et[ dmin ].normParam;
1704 p0 = quad->side[0].grid->Value2d( x ).XY();
1705 p2 = uv_et[ dmin ].UV();
1706 double y0 = uv_er[ dmin ].normParam;
1707 for ( int i = 1; i < nl-1; ++i )
1709 y = y0 + i / ( nl-1. ) * ( 1. - y0 );
1710 p1 = quad->side[1].grid->Value2d( y ).XY();
1711 p3 = quad->side[3].grid->Value2d( y ).XY();
1712 uv = calcUV( x,y, a0,a1,a2,a3, p0,p1,p2,p3 );
1713 pointsLCt[ i ].u = uv.X();
1714 pointsLCt[ i ].v = uv.Y();
1716 sideLCt = StdMeshers_FaceSide::New( pointsLCt, aFace );
1718 // Make a side separating domains Cb and Ct
1719 StdMeshers_FaceSidePtr sideCbCt;
1721 vector<UVPtStruct> pointsCbCt( nb );
1722 pointsCbCt[0] = p3dom;
1723 pointsCbCt.back() = uv_er[ dmin ];
1724 y = uv_er[ dmin ].normParam;
1725 p1 = uv_er[ dmin ].UV();
1726 p3 = quad->side[3].grid->Value2d( y ).XY();
1727 double x0 = uv_et[ dmin ].normParam;
1728 for ( int i = 1; i < nb-1; ++i )
1730 x = x0 + i / ( nb-1. ) * ( 1. - x0 );
1731 p2 = quad->side[2].grid->Value2d( x ).XY();
1732 p0 = quad->side[0].grid->Value2d( x ).XY();
1733 uv = calcUV( x,y, a0,a1,a2,a3, p0,p1,p2,p3 );
1734 pointsCbCt[ i ].u = uv.X();
1735 pointsCbCt[ i ].v = uv.Y();
1737 sideCbCt = StdMeshers_FaceSide::New( pointsCbCt, aFace );
1740 FaceQuadStruct* qCb = new FaceQuadStruct( quad->face, "Cb" );
1741 myQuadList.push_back( FaceQuadStruct::Ptr( qCb ));
1742 qCb->side.resize(4);
1743 qCb->side[0] = quad->side[0];
1744 qCb->side[1] = quad->side[1];
1745 qCb->side[2] = sideCbCt;
1746 qCb->side[3] = sideLCb;
1747 qCb->side[1].to = dmin+1;
1749 FaceQuadStruct* qL = new FaceQuadStruct( quad->face, "L" );
1750 myQuadList.push_back( FaceQuadStruct::Ptr( qL ));
1752 qL->side[0] = sideLCb;
1753 qL->side[1] = sideLCt;
1754 qL->side[2] = quad->side[2];
1755 qL->side[3] = quad->side[3];
1756 qL->side[2].to = dmin+1;
1757 // Make Ct from the main quad
1758 FaceQuadStruct::Ptr qCt = quad;
1759 qCt->side[0] = sideCbCt;
1760 qCt->side[3] = sideLCt;
1761 qCt->side[1].from = dmin;
1762 qCt->side[2].from = dmin;
1763 qCt->uv_grid.clear();
1767 qCb->side[3].AddContact( dmin, & qCb->side[2], 0 );
1768 qCb->side[3].AddContact( dmin, & qCt->side[3], 0 );
1769 qCt->side[3].AddContact( 0, & qCt->side[0], 0 );
1770 qCt->side[0].AddContact( 0, & qL ->side[0], dmin );
1771 qL ->side[0].AddContact( dmin, & qL ->side[1], 0 );
1772 qL ->side[0].AddContact( dmin, & qCb->side[2], 0 );
1775 return computeQuadDominant( aMesh, aFace );
1777 return computeQuadPref( aMesh, aFace, qCt );
1779 } // if ( dv != 0 && dh != 0 )
1781 const int db = quad->side[0].IsReversed() ? -1 : +1;
1782 const int dr = quad->side[1].IsReversed() ? -1 : +1;
1783 const int dt = quad->side[2].IsReversed() ? -1 : +1;
1784 const int dl = quad->side[3].IsReversed() ? -1 : +1;
1786 // Case dv == 0, here possibly myQuadList.size() > 1
1798 const int lw = dh/2; // lateral width
1802 double lL = quad->side[3].Length();
1803 double lLwL = quad->side[2].Length( tfrom,
1804 tfrom + ( lw ) * dt );
1805 yCbL = lLwL / ( lLwL + lL );
1807 double lR = quad->side[1].Length();
1808 double lLwR = quad->side[2].Length( tfrom + ( lw + nb-1 ) * dt,
1809 tfrom + ( lw + nb-1 + lw ) * dt);
1810 yCbR = lLwR / ( lLwR + lR );
1812 // Make sides separating domains Cb and L and R
1813 StdMeshers_FaceSidePtr sideLCb, sideRCb;
1814 UVPtStruct pTBL, pTBR; // points where 3 domains meat
1816 vector<UVPtStruct> pointsLCb( lw+1 ), pointsRCb( lw+1 );
1817 pointsLCb[0] = uv_eb[ 0 ];
1818 pointsRCb[0] = uv_eb[ nb-1 ];
1819 for ( int i = 1, i2 = nt-2; i <= lw; ++i, --i2 )
1821 x = quad->side[2].Param( i );
1823 p0 = quad->side[0].Value2d( x );
1824 p1 = quad->side[1].Value2d( y );
1825 p2 = uv_et[ i ].UV();
1826 p3 = quad->side[3].Value2d( y );
1827 uv = calcUV( x,y, a0,a1,a2,a3, p0,p1,p2,p3 );
1828 pointsLCb[ i ].u = uv.X();
1829 pointsLCb[ i ].v = uv.Y();
1830 pointsLCb[ i ].x = x;
1832 x = quad->side[2].Param( i2 );
1834 p1 = quad->side[1].Value2d( y );
1835 p0 = quad->side[0].Value2d( x );
1836 p2 = uv_et[ i2 ].UV();
1837 p3 = quad->side[3].Value2d( y );
1838 uv = calcUV( x,y, a0,a1,a2,a3, p0,p1,p2,p3 );
1839 pointsRCb[ i ].u = uv.X();
1840 pointsRCb[ i ].v = uv.Y();
1841 pointsRCb[ i ].x = x;
1843 sideLCb = StdMeshers_FaceSide::New( pointsLCb, aFace );
1844 sideRCb = StdMeshers_FaceSide::New( pointsRCb, aFace );
1845 pTBL = pointsLCb.back();
1846 pTBR = pointsRCb.back();
1848 // Make sides separating domains Ct and L and R
1849 StdMeshers_FaceSidePtr sideLCt, sideRCt;
1851 vector<UVPtStruct> pointsLCt( nl ), pointsRCt( nl );
1852 pointsLCt[0] = pTBL;
1853 pointsLCt.back() = uv_et[ lw ];
1854 pointsRCt[0] = pTBR;
1855 pointsRCt.back() = uv_et[ lw + nb - 1 ];
1857 p0 = quad->side[0].Value2d( x );
1858 p2 = uv_et[ lw ].UV();
1859 int iR = lw + nb - 1;
1861 gp_UV p0R = quad->side[0].Value2d( xR );
1862 gp_UV p2R = uv_et[ iR ].UV();
1863 for ( int i = 1; i < nl-1; ++i )
1865 y = yCbL + ( 1. - yCbL ) * i / (nl-1.);
1866 p1 = quad->side[1].Value2d( y );
1867 p3 = quad->side[3].Value2d( y );
1868 uv = calcUV( x,y, a0,a1,a2,a3, p0,p1,p2,p3 );
1869 pointsLCt[ i ].u = uv.X();
1870 pointsLCt[ i ].v = uv.Y();
1872 y = yCbR + ( 1. - yCbR ) * i / (nl-1.);
1873 p1 = quad->side[1].Value2d( y );
1874 p3 = quad->side[3].Value2d( y );
1875 uv = calcUV( xR,y, a0,a1,a2,a3, p0R,p1,p2R,p3 );
1876 pointsRCt[ i ].u = uv.X();
1877 pointsRCt[ i ].v = uv.Y();
1879 sideLCt = StdMeshers_FaceSide::New( pointsLCt, aFace );
1880 sideRCt = StdMeshers_FaceSide::New( pointsRCt, aFace );
1882 // Make a side separating domains Cb and Ct
1883 StdMeshers_FaceSidePtr sideCbCt;
1885 vector<UVPtStruct> pointsCbCt( nb );
1886 pointsCbCt[0] = pTBL;
1887 pointsCbCt.back() = pTBR;
1888 p1 = quad->side[1].Value2d( yCbR );
1889 p3 = quad->side[3].Value2d( yCbL );
1890 for ( int i = 1; i < nb-1; ++i )
1892 x = quad->side[2].Param( i + lw );
1893 y = yCbL + ( yCbR - yCbL ) * i / (nb-1.);
1894 p2 = uv_et[ i + lw ].UV();
1895 p0 = quad->side[0].Value2d( x );
1896 uv = calcUV( x,y, a0,a1,a2,a3, p0,p1,p2,p3 );
1897 pointsCbCt[ i ].u = uv.X();
1898 pointsCbCt[ i ].v = uv.Y();
1900 sideCbCt = StdMeshers_FaceSide::New( pointsCbCt, aFace );
1903 FaceQuadStruct* qCb = new FaceQuadStruct( quad->face, "Cb" );
1904 myQuadList.push_back( FaceQuadStruct::Ptr( qCb ));
1905 qCb->side.resize(4);
1906 qCb->side[0] = quad->side[0];
1907 qCb->side[1] = sideRCb;
1908 qCb->side[2] = sideCbCt;
1909 qCb->side[3] = sideLCb;
1911 FaceQuadStruct* qL = new FaceQuadStruct( quad->face, "L" );
1912 myQuadList.push_back( FaceQuadStruct::Ptr( qL ));
1914 qL->side[0] = sideLCb;
1915 qL->side[1] = sideLCt;
1916 qL->side[2] = quad->side[2];
1917 qL->side[3] = quad->side[3];
1918 qL->side[2].to = ( lw + 1 ) * dt + tfrom;
1920 FaceQuadStruct* qR = new FaceQuadStruct( quad->face, "R" );
1921 myQuadList.push_back( FaceQuadStruct::Ptr( qR ));
1923 qR->side[0] = sideRCb;
1924 qR->side[0].from = lw;
1925 qR->side[0].to = -1;
1926 qR->side[0].di = -1;
1927 qR->side[1] = quad->side[1];
1928 qR->side[2] = quad->side[2];
1929 qR->side[2].from = ( lw + nb-1 ) * dt + tfrom;
1930 qR->side[3] = sideRCt;
1931 // Make Ct from the main quad
1932 FaceQuadStruct::Ptr qCt = quad;
1933 qCt->side[0] = sideCbCt;
1934 qCt->side[1] = sideRCt;
1935 qCt->side[2].from = ( lw ) * dt + tfrom;
1936 qCt->side[2].to = ( lw + nb ) * dt + tfrom;
1937 qCt->side[3] = sideLCt;
1938 qCt->uv_grid.clear();
1942 qCb->side[3].AddContact( lw, & qCb->side[2], 0 );
1943 qCb->side[3].AddContact( lw, & qCt->side[3], 0 );
1944 qCt->side[3].AddContact( 0, & qCt->side[0], 0 );
1945 qCt->side[0].AddContact( 0, & qL ->side[0], lw );
1946 qL ->side[0].AddContact( lw, & qL ->side[1], 0 );
1947 qL ->side[0].AddContact( lw, & qCb->side[2], 0 );
1949 qCb->side[1].AddContact( lw, & qCb->side[2], nb-1 );
1950 qCb->side[1].AddContact( lw, & qCt->side[1], 0 );
1951 qCt->side[0].AddContact( nb-1, & qCt->side[1], 0 );
1952 qCt->side[0].AddContact( nb-1, & qR ->side[0], lw );
1953 qR ->side[3].AddContact( 0, & qR ->side[0], lw );
1954 qR ->side[3].AddContact( 0, & qCb->side[2], nb-1 );
1956 return computeQuadDominant( aMesh, aFace );
1958 } // if ( !myForcedPnts.empty() )
1969 // arrays for normalized params
1970 TColStd_SequenceOfReal npb, npr, npt, npl;
1971 for (i=0; i<nb; i++) {
1972 npb.Append(uv_eb[i].normParam);
1974 for (i=0; i<nr; i++) {
1975 npr.Append(uv_er[i].normParam);
1977 for (i=0; i<nt; i++) {
1978 npt.Append(uv_et[i].normParam);
1980 for (i=0; i<nl; i++) {
1981 npl.Append(uv_el[i].normParam);
1986 // add some params to right and left after the first param
1989 double dpr = (npr.Value(2) - npr.Value(1))/(dr+1);
1990 for (i=1; i<=dr; i++) {
1991 npr.InsertAfter(1,npr.Value(2)-dpr);
1995 dpr = (npl.Value(2) - npl.Value(1))/(dl+1);
1996 for (i=1; i<=dl; i++) {
1997 npl.InsertAfter(1,npl.Value(2)-dpr);
2001 int nnn = Min(nr,nl);
2002 // auxilary sequence of XY for creation nodes
2003 // in the bottom part of central domain
2004 // Length of UVL and UVR must be == nbv-nnn
2005 TColgp_SequenceOfXY UVL, UVR, UVT;
2008 // step1: create faces for left domain
2009 StdMeshers_Array2OfNode NodesL(1,dl+1,1,nl);
2011 for (j=1; j<=nl; j++)
2012 NodesL.SetValue(1,j,uv_el[j-1].node);
2015 for (i=1; i<=dl; i++)
2016 NodesL.SetValue(i+1,nl,uv_et[i].node);
2017 // create and add needed nodes
2018 TColgp_SequenceOfXY UVtmp;
2019 for (i=1; i<=dl; i++) {
2020 double x0 = npt.Value(i+1);
2023 double y0 = npl.Value(i+1);
2024 double y1 = npr.Value(i+1);
2025 gp_UV UV = calcUV(x0, x1, y0, y1, quad, a0, a1, a2, a3);
2026 gp_Pnt P = S->Value(UV.X(),UV.Y());
2027 SMDS_MeshNode * N = meshDS->AddNode(P.X(), P.Y(), P.Z());
2028 meshDS->SetNodeOnFace(N, geomFaceID, UV.X(), UV.Y());
2029 NodesL.SetValue(i+1,1,N);
2030 if (UVL.Length()<nbv-nnn) UVL.Append(UV);
2032 for (j=2; j<nl; j++) {
2033 double y0 = npl.Value(dl+j);
2034 double y1 = npr.Value(dl+j);
2035 gp_UV UV = calcUV(x0, x1, y0, y1, quad, a0, a1, a2, a3);
2036 gp_Pnt P = S->Value(UV.X(),UV.Y());
2037 SMDS_MeshNode* N = meshDS->AddNode(P.X(), P.Y(), P.Z());
2038 meshDS->SetNodeOnFace(N, geomFaceID, UV.X(), UV.Y());
2039 NodesL.SetValue(i+1,j,N);
2040 if (i==dl) UVtmp.Append(UV);
2043 for (i=1; i<=UVtmp.Length() && UVL.Length()<nbv-nnn; i++) {
2044 UVL.Append(UVtmp.Value(i));
2047 for (i=1; i<=dl; i++) {
2048 for (j=1; j<nl; j++) {
2051 myHelper->AddFace(NodesL.Value(i,j), NodesL.Value(i+1,j),
2052 NodesL.Value(i+1,j+1), NodesL.Value(i,j+1));
2053 if (F) meshDS->SetMeshElementOnShape(F, geomFaceID);
2059 // fill UVL using c2d
2060 for (i=1; i<npl.Length() && UVL.Length()<nbv-nnn; i++) {
2061 UVL.Append(gp_UV (uv_el[i].u, uv_el[i].v));
2065 // step2: create faces for right domain
2066 StdMeshers_Array2OfNode NodesR(1,dr+1,1,nr);
2068 for (j=1; j<=nr; j++)
2069 NodesR.SetValue(1,j,uv_er[nr-j].node);
2072 for (i=1; i<=dr; i++)
2073 NodesR.SetValue(i+1,1,uv_et[nt-1-i].node);
2074 // create and add needed nodes
2075 TColgp_SequenceOfXY UVtmp;
2076 for (i=1; i<=dr; i++) {
2077 double x0 = npt.Value(nt-i);
2080 double y0 = npl.Value(i+1);
2081 double y1 = npr.Value(i+1);
2082 gp_UV UV = calcUV(x0, x1, y0, y1, quad, a0, a1, a2, a3);
2083 gp_Pnt P = S->Value(UV.X(),UV.Y());
2084 SMDS_MeshNode * N = meshDS->AddNode(P.X(), P.Y(), P.Z());
2085 meshDS->SetNodeOnFace(N, geomFaceID, UV.X(), UV.Y());
2086 NodesR.SetValue(i+1,nr,N);
2087 if (UVR.Length()<nbv-nnn) UVR.Append(UV);
2089 for (j=2; j<nr; j++) {
2090 double y0 = npl.Value(nbv-j+1);
2091 double y1 = npr.Value(nbv-j+1);
2092 gp_UV UV = calcUV(x0, x1, y0, y1, quad, a0, a1, a2, a3);
2093 gp_Pnt P = S->Value(UV.X(),UV.Y());
2094 SMDS_MeshNode* N = meshDS->AddNode(P.X(), P.Y(), P.Z());
2095 meshDS->SetNodeOnFace(N, geomFaceID, UV.X(), UV.Y());
2096 NodesR.SetValue(i+1,j,N);
2097 if (i==dr) UVtmp.Prepend(UV);
2100 for (i=1; i<=UVtmp.Length() && UVR.Length()<nbv-nnn; i++) {
2101 UVR.Append(UVtmp.Value(i));
2104 for (i=1; i<=dr; i++) {
2105 for (j=1; j<nr; j++) {
2108 myHelper->AddFace(NodesR.Value(i,j), NodesR.Value(i+1,j),
2109 NodesR.Value(i+1,j+1), NodesR.Value(i,j+1));
2110 if (F) meshDS->SetMeshElementOnShape(F, geomFaceID);
2116 // fill UVR using c2d
2117 for (i=1; i<npr.Length() && UVR.Length()<nbv-nnn; i++) {
2118 UVR.Append(gp_UV(uv_er[i].u, uv_er[i].v));
2122 // step3: create faces for central domain
2123 StdMeshers_Array2OfNode NodesC(1,nb,1,nbv);
2124 // add first line using NodesL
2125 for (i=1; i<=dl+1; i++)
2126 NodesC.SetValue(1,i,NodesL(i,1));
2127 for (i=2; i<=nl; i++)
2128 NodesC.SetValue(1,dl+i,NodesL(dl+1,i));
2129 // add last line using NodesR
2130 for (i=1; i<=dr+1; i++)
2131 NodesC.SetValue(nb,i,NodesR(i,nr));
2132 for (i=1; i<nr; i++)
2133 NodesC.SetValue(nb,dr+i+1,NodesR(dr+1,nr-i));
2134 // add top nodes (last columns)
2135 for (i=dl+2; i<nbh-dr; i++)
2136 NodesC.SetValue(i-dl,nbv,uv_et[i-1].node);
2137 // add bottom nodes (first columns)
2138 for (i=2; i<nb; i++)
2139 NodesC.SetValue(i,1,uv_eb[i-1].node);
2141 // create and add needed nodes
2142 // add linear layers
2143 for (i=2; i<nb; i++) {
2144 double x0 = npt.Value(dl+i);
2146 for (j=1; j<nnn; j++) {
2147 double y0 = npl.Value(nbv-nnn+j);
2148 double y1 = npr.Value(nbv-nnn+j);
2149 gp_UV UV = calcUV(x0, x1, y0, y1, quad, a0, a1, a2, a3);
2150 gp_Pnt P = S->Value(UV.X(),UV.Y());
2151 SMDS_MeshNode* N = meshDS->AddNode(P.X(), P.Y(), P.Z());
2152 meshDS->SetNodeOnFace(N, geomFaceID, UV.X(), UV.Y());
2153 NodesC.SetValue(i,nbv-nnn+j,N);
2158 // add diagonal layers
2159 gp_UV A2 = UVR.Value(nbv-nnn);
2160 gp_UV A3 = UVL.Value(nbv-nnn);
2161 for (i=1; i<nbv-nnn; i++) {
2162 gp_UV p1 = UVR.Value(i);
2163 gp_UV p3 = UVL.Value(i);
2164 double y = i / double(nbv-nnn);
2165 for (j=2; j<nb; j++) {
2166 double x = npb.Value(j);
2167 gp_UV p0( uv_eb[j-1].u, uv_eb[j-1].v );
2168 gp_UV p2 = UVT.Value( j-1 );
2169 gp_UV UV = calcUV(x, y, a0, a1, A2, A3, p0,p1,p2,p3 );
2170 gp_Pnt P = S->Value(UV.X(),UV.Y());
2171 SMDS_MeshNode* N = meshDS->AddNode(P.X(), P.Y(), P.Z());
2172 meshDS->SetNodeOnFace(N, geomFaceID, UV.X(),UV.Y());
2173 NodesC.SetValue(j,i+1,N);
2177 for (i=1; i<nb; i++) {
2178 for (j=1; j<nbv; j++) {
2181 myHelper->AddFace(NodesC.Value(i,j), NodesC.Value(i+1,j),
2182 NodesC.Value(i+1,j+1), NodesC.Value(i,j+1));
2183 if (F) meshDS->SetMeshElementOnShape(F, geomFaceID);
2189 else { // New version (!OldVersion)
2190 // step1: create faces for bottom rectangle domain
2191 StdMeshers_Array2OfNode NodesBRD(1,nb,1,nnn-1);
2192 // fill UVL and UVR using c2d
2193 for (j=0; j<nb; j++) {
2194 NodesBRD.SetValue(j+1,1,uv_eb[j].node);
2196 for (i=1; i<nnn-1; i++) {
2197 NodesBRD.SetValue(1,i+1,uv_el[i].node);
2198 NodesBRD.SetValue(nb,i+1,uv_er[i].node);
2199 for (j=2; j<nb; j++) {
2200 double x = npb.Value(j);
2201 double y = (1-x) * npl.Value(i+1) + x * npr.Value(i+1);
2202 gp_UV UV = calcUV2(x, y, quad, a0, a1, a2, a3);
2203 gp_Pnt P = S->Value(UV.X(),UV.Y());
2204 SMDS_MeshNode* N = meshDS->AddNode(P.X(), P.Y(), P.Z());
2205 meshDS->SetNodeOnFace(N, geomFaceID, UV.X(),UV.Y());
2206 NodesBRD.SetValue(j,i+1,N);
2209 for (j=1; j<nnn-1; j++) {
2210 for (i=1; i<nb; i++) {
2213 myHelper->AddFace(NodesBRD.Value(i,j), NodesBRD.Value(i+1,j),
2214 NodesBRD.Value(i+1,j+1), NodesBRD.Value(i,j+1));
2215 if (F) meshDS->SetMeshElementOnShape(F, geomFaceID);
2219 int drl = abs(nr-nl);
2220 // create faces for region C
2221 StdMeshers_Array2OfNode NodesC(1,nb,1,drl+1+addv);
2222 // add nodes from previous region
2223 for (j=1; j<=nb; j++) {
2224 NodesC.SetValue(j,1,NodesBRD.Value(j,nnn-1));
2226 if ((drl+addv) > 0) {
2231 TColgp_SequenceOfXY UVtmp;
2232 double drparam = npr.Value(nr) - npr.Value(nnn-1);
2233 double dlparam = npl.Value(nnn) - npl.Value(nnn-1);
2235 for (i=1; i<=drl; i++) {
2236 // add existed nodes from right edge
2237 NodesC.SetValue(nb,i+1,uv_er[nnn+i-2].node);
2238 //double dtparam = npt.Value(i+1);
2239 y1 = npr.Value(nnn+i-1); // param on right edge
2240 double dpar = (y1 - npr.Value(nnn-1))/drparam;
2241 y0 = npl.Value(nnn-1) + dpar*dlparam; // param on left edge
2242 double dy = y1 - y0;
2243 for (j=1; j<nb; j++) {
2244 double x = npt.Value(i+1) + npb.Value(j)*(1-npt.Value(i+1));
2245 double y = y0 + dy*x;
2246 gp_UV UV = calcUV2(x, y, quad, a0, a1, a2, a3);
2247 gp_Pnt P = S->Value(UV.X(),UV.Y());
2248 SMDS_MeshNode* N = meshDS->AddNode(P.X(), P.Y(), P.Z());
2249 meshDS->SetNodeOnFace(N, geomFaceID, UV.X(), UV.Y());
2250 NodesC.SetValue(j,i+1,N);
2253 double dy0 = (1-y0)/(addv+1);
2254 double dy1 = (1-y1)/(addv+1);
2255 for (i=1; i<=addv; i++) {
2256 double yy0 = y0 + dy0*i;
2257 double yy1 = y1 + dy1*i;
2258 double dyy = yy1 - yy0;
2259 for (j=1; j<=nb; j++) {
2260 double x = npt.Value(i+1+drl) +
2261 npb.Value(j) * (npt.Value(nt-i) - npt.Value(i+1+drl));
2262 double y = yy0 + dyy*x;
2263 gp_UV UV = calcUV2(x, y, quad, a0, a1, a2, a3);
2264 gp_Pnt P = S->Value(UV.X(),UV.Y());
2265 SMDS_MeshNode* N = meshDS->AddNode(P.X(), P.Y(), P.Z());
2266 meshDS->SetNodeOnFace(N, geomFaceID, UV.X(), UV.Y());
2267 NodesC.SetValue(j,i+drl+1,N);
2274 TColgp_SequenceOfXY UVtmp;
2275 double dlparam = npl.Value(nl) - npl.Value(nnn-1);
2276 double drparam = npr.Value(nnn) - npr.Value(nnn-1);
2277 double y0 = npl.Value(nnn-1);
2278 double y1 = npr.Value(nnn-1);
2279 for (i=1; i<=drl; i++) {
2280 // add existed nodes from right edge
2281 NodesC.SetValue(1,i+1,uv_el[nnn+i-2].node);
2282 y0 = npl.Value(nnn+i-1); // param on left edge
2283 double dpar = (y0 - npl.Value(nnn-1))/dlparam;
2284 y1 = npr.Value(nnn-1) + dpar*drparam; // param on right edge
2285 double dy = y1 - y0;
2286 for (j=2; j<=nb; j++) {
2287 double x = npb.Value(j)*npt.Value(nt-i);
2288 double y = y0 + dy*x;
2289 gp_UV UV = calcUV2(x, y, quad, a0, a1, a2, a3);
2290 gp_Pnt P = S->Value(UV.X(),UV.Y());
2291 SMDS_MeshNode* N = meshDS->AddNode(P.X(), P.Y(), P.Z());
2292 meshDS->SetNodeOnFace(N, geomFaceID, UV.X(), UV.Y());
2293 NodesC.SetValue(j,i+1,N);
2296 double dy0 = (1-y0)/(addv+1);
2297 double dy1 = (1-y1)/(addv+1);
2298 for (i=1; i<=addv; i++) {
2299 double yy0 = y0 + dy0*i;
2300 double yy1 = y1 + dy1*i;
2301 double dyy = yy1 - yy0;
2302 for (j=1; j<=nb; j++) {
2303 double x = npt.Value(i+1) +
2304 npb.Value(j) * (npt.Value(nt-i-drl) - npt.Value(i+1));
2305 double y = yy0 + dyy*x;
2306 gp_UV UV = calcUV2(x, y, quad, a0, a1, a2, a3);
2307 gp_Pnt P = S->Value(UV.X(),UV.Y());
2308 SMDS_MeshNode* N = meshDS->AddNode(P.X(), P.Y(), P.Z());
2309 meshDS->SetNodeOnFace(N, geomFaceID, UV.X(), UV.Y());
2310 NodesC.SetValue(j,i+drl+1,N);
2315 for (j=1; j<=drl+addv; j++) {
2316 for (i=1; i<nb; i++) {
2319 myHelper->AddFace(NodesC.Value(i,j), NodesC.Value(i+1,j),
2320 NodesC.Value(i+1,j+1), NodesC.Value(i,j+1));
2321 if (F) meshDS->SetMeshElementOnShape(F, geomFaceID);
2326 StdMeshers_Array2OfNode NodesLast(1,nt,1,2);
2327 for (i=1; i<=nt; i++) {
2328 NodesLast.SetValue(i,2,uv_et[i-1].node);
2331 for (i=n1; i<drl+addv+1; i++) {
2333 NodesLast.SetValue(nnn,1,NodesC.Value(1,i));
2335 for (i=1; i<=nb; i++) {
2337 NodesLast.SetValue(nnn,1,NodesC.Value(i,drl+addv+1));
2339 for (i=drl+addv; i>=n2; i--) {
2341 NodesLast.SetValue(nnn,1,NodesC.Value(nb,i));
2343 for (i=1; i<nt; i++) {
2346 myHelper->AddFace(NodesLast.Value(i,1), NodesLast.Value(i+1,1),
2347 NodesLast.Value(i+1,2), NodesLast.Value(i,2));
2348 if (F) meshDS->SetMeshElementOnShape(F, geomFaceID);
2351 } // if ((drl+addv) > 0)
2353 } // end new version implementation
2360 //=======================================================================
2362 * Evaluate only quandrangle faces
2364 //=======================================================================
2366 bool StdMeshers_Quadrangle_2D::evaluateQuadPref(SMESH_Mesh & aMesh,
2367 const TopoDS_Shape& aShape,
2368 std::vector<int>& aNbNodes,
2369 MapShapeNbElems& aResMap,
2372 // Auxilary key in order to keep old variant
2373 // of meshing after implementation new variant
2374 // for bug 0016220 from Mantis.
2375 bool OldVersion = false;
2376 if (myQuadType == QUAD_QUADRANGLE_PREF_REVERSED)
2379 const TopoDS_Face& F = TopoDS::Face(aShape);
2380 Handle(Geom_Surface) S = BRep_Tool::Surface(F);
2382 int nb = aNbNodes[0];
2383 int nr = aNbNodes[1];
2384 int nt = aNbNodes[2];
2385 int nl = aNbNodes[3];
2386 int dh = abs(nb-nt);
2387 int dv = abs(nr-nl);
2391 // it is a base case => not shift
2394 // we have to shift on 2
2403 // we have to shift quad on 1
2410 // we have to shift quad on 3
2420 int nbh = Max(nb,nt);
2421 int nbv = Max(nr,nl);
2436 // add some params to right and left after the first param
2443 int nnn = Min(nr,nl);
2448 // step1: create faces for left domain
2450 nbNodes += dl*(nl-1);
2451 nbFaces += dl*(nl-1);
2453 // step2: create faces for right domain
2455 nbNodes += dr*(nr-1);
2456 nbFaces += dr*(nr-1);
2458 // step3: create faces for central domain
2459 nbNodes += (nb-2)*(nnn-1) + (nbv-nnn-1)*(nb-2);
2460 nbFaces += (nb-1)*(nbv-1);
2462 else { // New version (!OldVersion)
2463 nbNodes += (nnn-2)*(nb-2);
2464 nbFaces += (nnn-2)*(nb-1);
2465 int drl = abs(nr-nl);
2466 nbNodes += drl*(nb-1) + addv*nb;
2467 nbFaces += (drl+addv)*(nb-1) + (nt-1);
2468 } // end new version implementation
2470 std::vector<int> aVec(SMDSEntity_Last);
2471 for (int i=SMDSEntity_Node; i<SMDSEntity_Last; i++) aVec[i] = 0;
2473 aVec[SMDSEntity_Quad_Quadrangle] = nbFaces;
2474 aVec[SMDSEntity_Node] = nbNodes + nbFaces*4;
2475 if (aNbNodes.size()==5) {
2476 aVec[SMDSEntity_Quad_Triangle] = aNbNodes[3] - 1;
2477 aVec[SMDSEntity_Quad_Quadrangle] = nbFaces - aNbNodes[3] + 1;
2481 aVec[SMDSEntity_Node] = nbNodes;
2482 aVec[SMDSEntity_Quadrangle] = nbFaces;
2483 if (aNbNodes.size()==5) {
2484 aVec[SMDSEntity_Triangle] = aNbNodes[3] - 1;
2485 aVec[SMDSEntity_Quadrangle] = nbFaces - aNbNodes[3] + 1;
2488 SMESH_subMesh * sm = aMesh.GetSubMesh(aShape);
2489 aResMap.insert(std::make_pair(sm,aVec));
2494 //=============================================================================
2495 /*! Split quadrangle in to 2 triangles by smallest diagonal
2498 //=============================================================================
2500 void StdMeshers_Quadrangle_2D::splitQuadFace(SMESHDS_Mesh * theMeshDS,
2502 const SMDS_MeshNode* theNode1,
2503 const SMDS_MeshNode* theNode2,
2504 const SMDS_MeshNode* theNode3,
2505 const SMDS_MeshNode* theNode4)
2507 SMDS_MeshFace* face;
2508 if ( SMESH_TNodeXYZ( theNode1 ).SquareDistance( theNode3 ) >
2509 SMESH_TNodeXYZ( theNode2 ).SquareDistance( theNode4 ) )
2511 face = myHelper->AddFace(theNode2, theNode4 , theNode1);
2512 if (face) theMeshDS->SetMeshElementOnShape(face, theFaceID);
2513 face = myHelper->AddFace(theNode2, theNode3, theNode4);
2514 if (face) theMeshDS->SetMeshElementOnShape(face, theFaceID);
2518 face = myHelper->AddFace(theNode1, theNode2 ,theNode3);
2519 if (face) theMeshDS->SetMeshElementOnShape(face, theFaceID);
2520 face = myHelper->AddFace(theNode1, theNode3, theNode4);
2521 if (face) theMeshDS->SetMeshElementOnShape(face, theFaceID);
2527 enum uvPos { UV_A0, UV_A1, UV_A2, UV_A3, UV_B, UV_R, UV_T, UV_L, UV_SIZE };
2529 inline SMDS_MeshNode* makeNode( UVPtStruct & uvPt,
2531 FaceQuadStruct::Ptr& quad,
2533 SMESH_MesherHelper* helper,
2534 Handle(Geom_Surface) S)
2536 const vector<UVPtStruct>& uv_eb = quad->side[QUAD_BOTTOM_SIDE].GetUVPtStruct();
2537 const vector<UVPtStruct>& uv_et = quad->side[QUAD_TOP_SIDE ].GetUVPtStruct();
2538 double rBot = ( uv_eb.size() - 1 ) * uvPt.normParam;
2539 double rTop = ( uv_et.size() - 1 ) * uvPt.normParam;
2540 int iBot = int( rBot );
2541 int iTop = int( rTop );
2542 double xBot = uv_eb[ iBot ].normParam + ( rBot - iBot ) * ( uv_eb[ iBot+1 ].normParam - uv_eb[ iBot ].normParam );
2543 double xTop = uv_et[ iTop ].normParam + ( rTop - iTop ) * ( uv_et[ iTop+1 ].normParam - uv_et[ iTop ].normParam );
2544 double x = xBot + y * ( xTop - xBot );
2546 gp_UV uv = calcUV(/*x,y=*/x, y,
2547 /*a0,...=*/UVs[UV_A0], UVs[UV_A1], UVs[UV_A2], UVs[UV_A3],
2548 /*p0=*/quad->side[QUAD_BOTTOM_SIDE].grid->Value2d( x ).XY(),
2550 /*p2=*/quad->side[QUAD_TOP_SIDE ].grid->Value2d( x ).XY(),
2551 /*p3=*/UVs[ UV_L ]);
2552 gp_Pnt P = S->Value( uv.X(), uv.Y() );
2555 return helper->AddNode(P.X(), P.Y(), P.Z(), 0, uv.X(), uv.Y() );
2558 void reduce42( const vector<UVPtStruct>& curr_base,
2559 vector<UVPtStruct>& next_base,
2561 int & next_base_len,
2562 FaceQuadStruct::Ptr& quad,
2565 SMESH_MesherHelper* helper,
2566 Handle(Geom_Surface)& S)
2568 // add one "HH": nodes a,b,c,d,e and faces 1,2,3,4,5,6
2570 // .-----a-----b i + 1
2581 const SMDS_MeshNode*& Na = next_base[ ++next_base_len ].node;
2583 Na = makeNode( next_base[ next_base_len ], y, quad, UVs, helper, S );
2586 const SMDS_MeshNode*& Nb = next_base[ ++next_base_len ].node;
2588 Nb = makeNode( next_base[ next_base_len ], y, quad, UVs, helper, S );
2591 double u = (curr_base[j + 2].u + next_base[next_base_len - 2].u) / 2.0;
2592 double v = (curr_base[j + 2].v + next_base[next_base_len - 2].v) / 2.0;
2593 gp_Pnt P = S->Value(u,v);
2594 SMDS_MeshNode* Nc = helper->AddNode(P.X(), P.Y(), P.Z(), 0, u, v);
2597 u = (curr_base[j + 2].u + next_base[next_base_len - 1].u) / 2.0;
2598 v = (curr_base[j + 2].v + next_base[next_base_len - 1].v) / 2.0;
2600 SMDS_MeshNode* Nd = helper->AddNode(P.X(), P.Y(), P.Z(), 0, u, v);
2603 u = (curr_base[j + 2].u + next_base[next_base_len].u) / 2.0;
2604 v = (curr_base[j + 2].v + next_base[next_base_len].v) / 2.0;
2606 SMDS_MeshNode* Ne = helper->AddNode(P.X(), P.Y(), P.Z(), 0, u, v);
2609 helper->AddFace(curr_base[j + 0].node,
2610 curr_base[j + 1].node, Nc,
2611 next_base[next_base_len - 2].node);
2613 helper->AddFace(curr_base[j + 1].node,
2614 curr_base[j + 2].node, Nd, Nc);
2616 helper->AddFace(curr_base[j + 2].node,
2617 curr_base[j + 3].node, Ne, Nd);
2619 helper->AddFace(curr_base[j + 3].node,
2620 curr_base[j + 4].node, Nb, Ne);
2622 helper->AddFace(Nc, Nd, Na, next_base[next_base_len - 2].node);
2624 helper->AddFace(Nd, Ne, Nb, Na);
2627 void reduce31( const vector<UVPtStruct>& curr_base,
2628 vector<UVPtStruct>& next_base,
2630 int & next_base_len,
2631 FaceQuadStruct::Ptr& quad,
2634 SMESH_MesherHelper* helper,
2635 Handle(Geom_Surface)& S)
2637 // add one "H": nodes b,c,e and faces 1,2,4,5
2639 // .---------b i + 1
2650 const SMDS_MeshNode*& Nb = next_base[ ++next_base_len ].node;
2652 Nb = makeNode( next_base[ next_base_len ], y, quad, UVs, helper, S );
2655 double u1 = (curr_base[ j ].u + next_base[ next_base_len-1 ].u ) / 2.0;
2656 double u2 = (curr_base[ j+3 ].u + next_base[ next_base_len ].u ) / 2.0;
2657 double u3 = (u2 - u1) / 3.0;
2659 double v1 = (curr_base[ j ].v + next_base[ next_base_len-1 ].v ) / 2.0;
2660 double v2 = (curr_base[ j+3 ].v + next_base[ next_base_len ].v ) / 2.0;
2661 double v3 = (v2 - v1) / 3.0;
2665 gp_Pnt P = S->Value(u,v);
2666 SMDS_MeshNode* Nc = helper->AddNode( P.X(), P.Y(), P.Z(), 0, u, v );
2671 SMDS_MeshNode* Ne = helper->AddNode( P.X(), P.Y(), P.Z(), 0, u, v );
2675 helper->AddFace( curr_base[ j + 0 ].node,
2676 curr_base[ j + 1 ].node,
2678 next_base[ next_base_len - 1 ].node);
2680 helper->AddFace( curr_base[ j + 1 ].node,
2681 curr_base[ j + 2 ].node, Ne, Nc);
2683 helper->AddFace( curr_base[ j + 2 ].node,
2684 curr_base[ j + 3 ].node, Nb, Ne);
2686 helper->AddFace(Nc, Ne, Nb,
2687 next_base[ next_base_len - 1 ].node);
2690 typedef void (* PReduceFunction) ( const vector<UVPtStruct>& curr_base,
2691 vector<UVPtStruct>& next_base,
2693 int & next_base_len,
2694 FaceQuadStruct::Ptr & quad,
2697 SMESH_MesherHelper* helper,
2698 Handle(Geom_Surface)& S);
2702 //=======================================================================
2704 * Implementation of Reduced algorithm (meshing with quadrangles only)
2706 //=======================================================================
2708 bool StdMeshers_Quadrangle_2D::computeReduced (SMESH_Mesh & aMesh,
2709 const TopoDS_Face& aFace,
2710 FaceQuadStruct::Ptr quad)
2712 SMESHDS_Mesh * meshDS = aMesh.GetMeshDS();
2713 Handle(Geom_Surface) S = BRep_Tool::Surface(aFace);
2714 int i,j,geomFaceID = meshDS->ShapeToIndex(aFace);
2716 int nb = quad->side[0].NbPoints(); // bottom
2717 int nr = quad->side[1].NbPoints(); // right
2718 int nt = quad->side[2].NbPoints(); // top
2719 int nl = quad->side[3].NbPoints(); // left
2721 // Simple Reduce 10->8->6->4 (3 steps) Multiple Reduce 10->4 (1 step)
2723 // .-----.-----.-----.-----. .-----.-----.-----.-----.
2724 // | / \ | / \ | | / \ | / \ |
2725 // | / .--.--. \ | | / \ | / \ |
2726 // | / / | \ \ | | / .----.----. \ |
2727 // .---.---.---.---.---.---. | / / \ | / \ \ |
2728 // | / / \ | / \ \ | | / / \ | / \ \ |
2729 // | / / .-.-. \ \ | | / / .---.---. \ \ |
2730 // | / / / | \ \ \ | | / / / \ | / \ \ \ |
2731 // .--.--.--.--.--.--.--.--. | / / / \ | / \ \ \ |
2732 // | / / / \ | / \ \ \ | | / / / .-.-. \ \ \ |
2733 // | / / / .-.-. \ \ \ | | / / / / | \ \ \ \ |
2734 // | / / / / | \ \ \ \ | | / / / / | \ \ \ \ |
2735 // .-.-.-.--.--.--.--.-.-.-. .-.-.-.--.--.--.--.-.-.-.
2737 bool MultipleReduce = false;
2749 else if (nb == nt) {
2750 nr1 = nb; // and == nt
2764 // number of rows and columns
2765 int nrows = nr1 - 1;
2766 int ncol_top = nt1 - 1;
2767 int ncol_bot = nb1 - 1;
2768 // number of rows needed to reduce ncol_bot to ncol_top using simple 3->1 "tree" (see below)
2770 int( ceil( log( double(ncol_bot) / ncol_top) / log( 3.))); // = log x base 3
2771 if ( nrows < nrows_tree31 )
2773 MultipleReduce = true;
2774 error( COMPERR_WARNING,
2775 SMESH_Comment("To use 'Reduced' transition, "
2776 "number of face rows should be at least ")
2777 << nrows_tree31 << ". Actual number of face rows is " << nrows << ". "
2778 "'Quadrangle preference (reversed)' transion has been used.");
2782 if (MultipleReduce) { // == computeQuadPref QUAD_QUADRANGLE_PREF_REVERSED
2783 //==================================================
2784 int dh = abs(nb-nt);
2785 int dv = abs(nr-nl);
2789 // it is a base case => not shift quad but may be replacement is need
2793 // we have to shift quad on 2
2799 // we have to shift quad on 1
2803 // we have to shift quad on 3
2808 nb = quad->side[0].NbPoints();
2809 nr = quad->side[1].NbPoints();
2810 nt = quad->side[2].NbPoints();
2811 nl = quad->side[3].NbPoints();
2814 int nbh = Max(nb,nt);
2815 int nbv = Max(nr,nl);
2828 const vector<UVPtStruct>& uv_eb = quad->side[0].GetUVPtStruct(true,0);
2829 const vector<UVPtStruct>& uv_er = quad->side[1].GetUVPtStruct(false,1);
2830 const vector<UVPtStruct>& uv_et = quad->side[2].GetUVPtStruct(true,1);
2831 const vector<UVPtStruct>& uv_el = quad->side[3].GetUVPtStruct(false,0);
2833 if (uv_eb.size() != nb || uv_er.size() != nr || uv_et.size() != nt || uv_el.size() != nl)
2834 return error(COMPERR_BAD_INPUT_MESH);
2836 // arrays for normalized params
2837 TColStd_SequenceOfReal npb, npr, npt, npl;
2838 for (j = 0; j < nb; j++) {
2839 npb.Append(uv_eb[j].normParam);
2841 for (i = 0; i < nr; i++) {
2842 npr.Append(uv_er[i].normParam);
2844 for (j = 0; j < nt; j++) {
2845 npt.Append(uv_et[j].normParam);
2847 for (i = 0; i < nl; i++) {
2848 npl.Append(uv_el[i].normParam);
2852 // orientation of face and 3 main domain for future faces
2858 // left | | | | rigth
2865 // add some params to right and left after the first param
2868 double dpr = (npr.Value(2) - npr.Value(1))/(dr+1);
2869 for (i=1; i<=dr; i++) {
2870 npr.InsertAfter(1,npr.Value(2)-dpr);
2874 dpr = (npl.Value(2) - npl.Value(1))/(dl+1);
2875 for (i=1; i<=dl; i++) {
2876 npl.InsertAfter(1,npl.Value(2)-dpr);
2879 gp_XY a0 (uv_eb.front().u, uv_eb.front().v);
2880 gp_XY a1 (uv_eb.back().u, uv_eb.back().v);
2881 gp_XY a2 (uv_et.back().u, uv_et.back().v);
2882 gp_XY a3 (uv_et.front().u, uv_et.front().v);
2884 int nnn = Min(nr,nl);
2885 // auxilary sequence of XY for creation of nodes
2886 // in the bottom part of central domain
2887 // it's length must be == nbv-nnn-1
2888 TColgp_SequenceOfXY UVL;
2889 TColgp_SequenceOfXY UVR;
2890 //==================================================
2892 // step1: create faces for left domain
2893 StdMeshers_Array2OfNode NodesL(1,dl+1,1,nl);
2895 for (j=1; j<=nl; j++)
2896 NodesL.SetValue(1,j,uv_el[j-1].node);
2899 for (i=1; i<=dl; i++)
2900 NodesL.SetValue(i+1,nl,uv_et[i].node);
2901 // create and add needed nodes
2902 TColgp_SequenceOfXY UVtmp;
2903 for (i=1; i<=dl; i++) {
2904 double x0 = npt.Value(i+1);
2907 double y0 = npl.Value(i+1);
2908 double y1 = npr.Value(i+1);
2909 gp_UV UV = calcUV(x0, x1, y0, y1, quad, a0, a1, a2, a3);
2910 gp_Pnt P = S->Value(UV.X(),UV.Y());
2911 SMDS_MeshNode * N = meshDS->AddNode(P.X(), P.Y(), P.Z());
2912 meshDS->SetNodeOnFace(N, geomFaceID, UV.X(), UV.Y());
2913 NodesL.SetValue(i+1,1,N);
2914 if (UVL.Length()<nbv-nnn-1) UVL.Append(UV);
2916 for (j=2; j<nl; j++) {
2917 double y0 = npl.Value(dl+j);
2918 double y1 = npr.Value(dl+j);
2919 gp_UV UV = calcUV(x0, x1, y0, y1, quad, a0, a1, a2, a3);
2920 gp_Pnt P = S->Value(UV.X(),UV.Y());
2921 SMDS_MeshNode* N = meshDS->AddNode(P.X(), P.Y(), P.Z());
2922 meshDS->SetNodeOnFace(N, geomFaceID, UV.X(), UV.Y());
2923 NodesL.SetValue(i+1,j,N);
2924 if (i==dl) UVtmp.Append(UV);
2927 for (i=1; i<=UVtmp.Length() && UVL.Length()<nbv-nnn-1; i++) {
2928 UVL.Append(UVtmp.Value(i));
2931 for (i=1; i<=dl; i++) {
2932 for (j=1; j<nl; j++) {
2934 myHelper->AddFace(NodesL.Value(i,j), NodesL.Value(i+1,j),
2935 NodesL.Value(i+1,j+1), NodesL.Value(i,j+1));
2936 if (F) meshDS->SetMeshElementOnShape(F, geomFaceID);
2941 // fill UVL using c2d
2942 for (i=1; i<npl.Length() && UVL.Length()<nbv-nnn-1; i++) {
2943 UVL.Append(gp_UV (uv_el[i].u, uv_el[i].v));
2947 // step2: create faces for right domain
2948 StdMeshers_Array2OfNode NodesR(1,dr+1,1,nr);
2950 for (j=1; j<=nr; j++)
2951 NodesR.SetValue(1,j,uv_er[nr-j].node);
2954 for (i=1; i<=dr; i++)
2955 NodesR.SetValue(i+1,1,uv_et[nt-1-i].node);
2956 // create and add needed nodes
2957 TColgp_SequenceOfXY UVtmp;
2958 for (i=1; i<=dr; i++) {
2959 double x0 = npt.Value(nt-i);
2962 double y0 = npl.Value(i+1);
2963 double y1 = npr.Value(i+1);
2964 gp_UV UV = calcUV(x0, x1, y0, y1, quad, a0, a1, a2, a3);
2965 gp_Pnt P = S->Value(UV.X(),UV.Y());
2966 SMDS_MeshNode * N = meshDS->AddNode(P.X(), P.Y(), P.Z());
2967 meshDS->SetNodeOnFace(N, geomFaceID, UV.X(), UV.Y());
2968 NodesR.SetValue(i+1,nr,N);
2969 if (UVR.Length()<nbv-nnn-1) UVR.Append(UV);
2971 for (j=2; j<nr; j++) {
2972 double y0 = npl.Value(nbv-j+1);
2973 double y1 = npr.Value(nbv-j+1);
2974 gp_UV UV = calcUV(x0, x1, y0, y1, quad, a0, a1, a2, a3);
2975 gp_Pnt P = S->Value(UV.X(),UV.Y());
2976 SMDS_MeshNode* N = meshDS->AddNode(P.X(), P.Y(), P.Z());
2977 meshDS->SetNodeOnFace(N, geomFaceID, UV.X(), UV.Y());
2978 NodesR.SetValue(i+1,j,N);
2979 if (i==dr) UVtmp.Prepend(UV);
2982 for (i=1; i<=UVtmp.Length() && UVR.Length()<nbv-nnn-1; i++) {
2983 UVR.Append(UVtmp.Value(i));
2986 for (i=1; i<=dr; i++) {
2987 for (j=1; j<nr; j++) {
2989 myHelper->AddFace(NodesR.Value(i,j), NodesR.Value(i+1,j),
2990 NodesR.Value(i+1,j+1), NodesR.Value(i,j+1));
2991 if (F) meshDS->SetMeshElementOnShape(F, geomFaceID);
2996 // fill UVR using c2d
2997 for (i=1; i<npr.Length() && UVR.Length()<nbv-nnn-1; i++) {
2998 UVR.Append(gp_UV(uv_er[i].u, uv_er[i].v));
3002 // step3: create faces for central domain
3003 StdMeshers_Array2OfNode NodesC(1,nb,1,nbv);
3004 // add first line using NodesL
3005 for (i=1; i<=dl+1; i++)
3006 NodesC.SetValue(1,i,NodesL(i,1));
3007 for (i=2; i<=nl; i++)
3008 NodesC.SetValue(1,dl+i,NodesL(dl+1,i));
3009 // add last line using NodesR
3010 for (i=1; i<=dr+1; i++)
3011 NodesC.SetValue(nb,i,NodesR(i,nr));
3012 for (i=1; i<nr; i++)
3013 NodesC.SetValue(nb,dr+i+1,NodesR(dr+1,nr-i));
3014 // add top nodes (last columns)
3015 for (i=dl+2; i<nbh-dr; i++)
3016 NodesC.SetValue(i-dl,nbv,uv_et[i-1].node);
3017 // add bottom nodes (first columns)
3018 for (i=2; i<nb; i++)
3019 NodesC.SetValue(i,1,uv_eb[i-1].node);
3021 // create and add needed nodes
3022 // add linear layers
3023 for (i=2; i<nb; i++) {
3024 double x0 = npt.Value(dl+i);
3026 for (j=1; j<nnn; j++) {
3027 double y0 = npl.Value(nbv-nnn+j);
3028 double y1 = npr.Value(nbv-nnn+j);
3029 gp_UV UV = calcUV(x0, x1, y0, y1, quad, a0, a1, a2, a3);
3030 gp_Pnt P = S->Value(UV.X(),UV.Y());
3031 SMDS_MeshNode* N = meshDS->AddNode(P.X(), P.Y(), P.Z());
3032 meshDS->SetNodeOnFace(N, geomFaceID, UV.X(), UV.Y());
3033 NodesC.SetValue(i,nbv-nnn+j,N);
3036 // add diagonal layers
3037 for (i=1; i<nbv-nnn; i++) {
3038 double du = UVR.Value(i).X() - UVL.Value(i).X();
3039 double dv = UVR.Value(i).Y() - UVL.Value(i).Y();
3040 for (j=2; j<nb; j++) {
3041 double u = UVL.Value(i).X() + du*npb.Value(j);
3042 double v = UVL.Value(i).Y() + dv*npb.Value(j);
3043 gp_Pnt P = S->Value(u,v);
3044 SMDS_MeshNode* N = meshDS->AddNode(P.X(), P.Y(), P.Z());
3045 meshDS->SetNodeOnFace(N, geomFaceID, u, v);
3046 NodesC.SetValue(j,i+1,N);
3050 for (i=1; i<nb; i++) {
3051 for (j=1; j<nbv; j++) {
3053 myHelper->AddFace(NodesC.Value(i,j), NodesC.Value(i+1,j),
3054 NodesC.Value(i+1,j+1), NodesC.Value(i,j+1));
3055 if (F) meshDS->SetMeshElementOnShape(F, geomFaceID);
3058 } // end Multiple Reduce implementation
3059 else { // Simple Reduce (!MultipleReduce)
3060 //=========================================================
3063 // it is a base case => not shift quad
3064 //shiftQuad(quad,0,true);
3067 // we have to shift quad on 2
3073 // we have to shift quad on 1
3077 // we have to shift quad on 3
3082 nb = quad->side[0].NbPoints();
3083 nr = quad->side[1].NbPoints();
3084 nt = quad->side[2].NbPoints();
3085 nl = quad->side[3].NbPoints();
3087 // number of rows and columns
3088 int nrows = nr - 1; // and also == nl - 1
3089 int ncol_top = nt - 1;
3090 int ncol_bot = nb - 1;
3091 int npair_top = ncol_top / 2;
3092 // maximum number of bottom elements for "linear" simple reduce 4->2
3093 int max_lin42 = ncol_top + npair_top * 2 * nrows;
3094 // maximum number of bottom elements for "linear" simple reduce 3->1
3095 int max_lin31 = ncol_top + ncol_top * 2 * nrows;
3096 // maximum number of bottom elements for "tree" simple reduce 4->2
3098 // number of rows needed to reduce ncol_bot to ncol_top using simple 4->2 "tree"
3099 int nrows_tree42 = int( log( (double)(ncol_bot / ncol_top) )/log((double)2) ); // needed to avoid overflow at pow(2) while computing max_tree42
3100 if (nrows_tree42 < nrows) {
3101 max_tree42 = npair_top * pow(2.0, nrows + 1);
3102 if ( ncol_top > npair_top * 2 ) {
3103 int delta = ncol_bot - max_tree42;
3104 for (int irow = 1; irow < nrows; irow++) {
3105 int nfour = delta / 4;
3108 if (delta <= (ncol_top - npair_top * 2))
3109 max_tree42 = ncol_bot;
3112 // maximum number of bottom elements for "tree" simple reduce 3->1
3113 //int max_tree31 = ncol_top * pow(3.0, nrows);
3114 bool is_lin_31 = false;
3115 bool is_lin_42 = false;
3116 bool is_tree_31 = false;
3117 bool is_tree_42 = false;
3118 int max_lin = max_lin42;
3119 if (ncol_bot > max_lin42) {
3120 if (ncol_bot <= max_lin31) {
3122 max_lin = max_lin31;
3126 // if ncol_bot is a 3*n or not 2*n
3127 if ((ncol_bot/3)*3 == ncol_bot || (ncol_bot/2)*2 != ncol_bot) {
3129 max_lin = max_lin31;
3135 if (ncol_bot > max_lin) { // not "linear"
3136 is_tree_31 = (ncol_bot > max_tree42);
3137 if (ncol_bot <= max_tree42) {
3138 if ((ncol_bot/3)*3 == ncol_bot || (ncol_bot/2)*2 != ncol_bot) {
3147 const vector<UVPtStruct>& uv_eb = quad->side[0].GetUVPtStruct(true,0);
3148 const vector<UVPtStruct>& uv_er = quad->side[1].GetUVPtStruct(false,1);
3149 const vector<UVPtStruct>& uv_et = quad->side[2].GetUVPtStruct(true,1);
3150 const vector<UVPtStruct>& uv_el = quad->side[3].GetUVPtStruct(false,0);
3152 if (uv_eb.size() != nb || uv_er.size() != nr || uv_et.size() != nt || uv_el.size() != nl)
3153 return error(COMPERR_BAD_INPUT_MESH);
3155 myHelper->SetElementsOnShape( true );
3157 gp_UV uv[ UV_SIZE ];
3158 uv[ UV_A0 ].SetCoord( uv_eb.front().u, uv_eb.front().v);
3159 uv[ UV_A1 ].SetCoord( uv_eb.back().u, uv_eb.back().v );
3160 uv[ UV_A2 ].SetCoord( uv_et.back().u, uv_et.back().v );
3161 uv[ UV_A3 ].SetCoord( uv_et.front().u, uv_et.front().v);
3163 vector<UVPtStruct> curr_base = uv_eb, next_base;
3165 UVPtStruct nullUVPtStruct; nullUVPtStruct.node = 0;
3167 int curr_base_len = nb;
3168 int next_base_len = 0;
3171 { // ------------------------------------------------------------------
3172 // New algorithm implemented by request of IPAL22856
3173 // "2D quadrangle mesher of reduced type works wrong"
3174 // http://bugtracker.opencascade.com/show_bug.cgi?id=22856
3176 // the algorithm is following: all reduces are centred in horizontal
3177 // direction and are distributed among all rows
3179 if (ncol_bot > max_tree42) {
3183 if ((ncol_top/3)*3 == ncol_top ) {
3191 const int col_top_size = is_lin_42 ? 2 : 1;
3192 const int col_base_size = is_lin_42 ? 4 : 3;
3194 // Compute nb of "columns" (like in "linear" simple reducing) in all rows
3196 vector<int> nb_col_by_row;
3198 int delta_all = nb - nt;
3199 int delta_one_col = nrows * 2;
3200 int nb_col = delta_all / delta_one_col;
3201 int remainder = delta_all - nb_col * delta_one_col;
3202 if (remainder > 0) {
3205 if ( nb_col * col_top_size >= nt ) // == "tree" reducing situation
3207 // top row is full (all elements reduced), add "columns" one by one
3208 // in rows below until all bottom elements are reduced
3209 nb_col = ( nt - 1 ) / col_top_size;
3210 nb_col_by_row.resize( nrows, nb_col );
3211 int nbrows_not_full = nrows - 1;
3212 int cur_top_size = nt - 1;
3213 remainder = delta_all - nb_col * delta_one_col;
3214 while ( remainder > 0 )
3216 delta_one_col = nbrows_not_full * 2;
3217 int nb_col_add = remainder / delta_one_col;
3218 cur_top_size += 2 * nb_col_by_row[ nbrows_not_full ];
3219 int nb_col_free = cur_top_size / col_top_size - nb_col_by_row[ nbrows_not_full-1 ];
3220 if ( nb_col_add > nb_col_free )
3221 nb_col_add = nb_col_free;
3222 for ( int irow = 0; irow < nbrows_not_full; ++irow )
3223 nb_col_by_row[ irow ] += nb_col_add;
3225 remainder -= nb_col_add * delta_one_col;
3228 else // == "linear" reducing situation
3230 nb_col_by_row.resize( nrows, nb_col );
3232 for ( int irow = remainder / 2; irow < nrows; ++irow )
3233 nb_col_by_row[ irow ]--;
3238 PReduceFunction reduceFunction = & ( is_lin_42 ? reduce42 : reduce31 );
3240 const int reduce_grp_size = is_lin_42 ? 4 : 3;
3242 for (i = 1; i < nr; i++) // layer by layer
3244 nb_col = nb_col_by_row[ i-1 ];
3245 int nb_next = curr_base_len - nb_col * 2;
3246 if (nb_next < nt) nb_next = nt;
3248 const double y = uv_el[ i ].normParam;
3250 if ( i + 1 == nr ) // top
3257 next_base.resize( nb_next, nullUVPtStruct );
3258 next_base.front() = uv_el[i];
3259 next_base.back() = uv_er[i];
3261 // compute normalized param u
3262 double du = 1. / ( nb_next - 1 );
3263 next_base[0].normParam = 0.;
3264 for ( j = 1; j < nb_next; ++j )
3265 next_base[j].normParam = next_base[j-1].normParam + du;
3267 uv[ UV_L ].SetCoord( next_base.front().u, next_base.front().v );
3268 uv[ UV_R ].SetCoord( next_base.back().u, next_base.back().v );
3270 int free_left = ( curr_base_len - 1 - nb_col * col_base_size ) / 2;
3271 int free_middle = curr_base_len - 1 - nb_col * col_base_size - 2 * free_left;
3273 // not reduced left elements
3274 for (j = 0; j < free_left; j++)
3277 const SMDS_MeshNode*& Nf = next_base[++next_base_len].node;
3279 Nf = makeNode( next_base[ next_base_len ], y, quad, uv, myHelper, S );
3281 myHelper->AddFace(curr_base[ j ].node,
3282 curr_base[ j+1 ].node,
3284 next_base[ next_base_len-1 ].node);
3287 for (int icol = 1; icol <= nb_col; icol++)
3290 reduceFunction( curr_base, next_base, j, next_base_len, quad, uv, y, myHelper, S );
3292 j += reduce_grp_size;
3294 // elements in the middle of "columns" added for symmetry
3295 if ( free_middle > 0 && ( nb_col % 2 == 0 ) && icol == nb_col / 2 )
3297 for (int imiddle = 1; imiddle <= free_middle; imiddle++) {
3298 // f (i + 1, j + imiddle)
3299 const SMDS_MeshNode*& Nf = next_base[++next_base_len].node;
3301 Nf = makeNode( next_base[ next_base_len ], y, quad, uv, myHelper, S );
3303 myHelper->AddFace(curr_base[ j-1+imiddle ].node,
3304 curr_base[ j +imiddle ].node,
3306 next_base[ next_base_len-1 ].node);
3312 // not reduced right elements
3313 for (; j < curr_base_len-1; j++) {
3315 const SMDS_MeshNode*& Nf = next_base[++next_base_len].node;
3317 Nf = makeNode( next_base[ next_base_len ], y, quad, uv, myHelper, S );
3319 myHelper->AddFace(curr_base[ j ].node,
3320 curr_base[ j+1 ].node,
3322 next_base[ next_base_len-1 ].node);
3325 curr_base_len = next_base_len + 1;
3327 curr_base.swap( next_base );