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 typedef NCollection_Array2<SMDS_MeshNodePtr> StdMeshers_Array2OfNode;
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),
93 myQuadType(QUAD_STANDARD),
96 MESSAGE("StdMeshers_Quadrangle_2D::StdMeshers_Quadrangle_2D");
97 _name = "Quadrangle_2D";
98 _shapeType = (1 << TopAbs_FACE);
99 _compatibleHypothesis.push_back("QuadrangleParams");
100 _compatibleHypothesis.push_back("QuadranglePreference");
101 _compatibleHypothesis.push_back("TrianglePreference");
102 _compatibleHypothesis.push_back("ViscousLayers2D");
105 //=============================================================================
109 //=============================================================================
111 StdMeshers_Quadrangle_2D::~StdMeshers_Quadrangle_2D()
113 MESSAGE("StdMeshers_Quadrangle_2D::~StdMeshers_Quadrangle_2D");
116 //=============================================================================
120 //=============================================================================
122 bool StdMeshers_Quadrangle_2D::CheckHypothesis
124 const TopoDS_Shape& aShape,
125 SMESH_Hypothesis::Hypothesis_Status& aStatus)
128 myQuadType = QUAD_STANDARD;
129 myQuadranglePreference = false;
130 myTrianglePreference = false;
131 myHelper = (SMESH_MesherHelper*)NULL;
136 aStatus = SMESH_Hypothesis::HYP_OK;
138 const list <const SMESHDS_Hypothesis * >& hyps =
139 GetUsedHypothesis(aMesh, aShape, false);
140 const SMESHDS_Hypothesis * aHyp = 0;
142 bool isFirstParams = true;
144 // First assigned hypothesis (if any) is processed now
145 if (hyps.size() > 0) {
147 if (strcmp("QuadrangleParams", aHyp->GetName()) == 0)
149 myParams = (const StdMeshers_QuadrangleParams*)aHyp;
150 myTriaVertexID = myParams->GetTriaVertex();
151 myQuadType = myParams->GetQuadType();
152 if (myQuadType == QUAD_QUADRANGLE_PREF ||
153 myQuadType == QUAD_QUADRANGLE_PREF_REVERSED)
154 myQuadranglePreference = true;
155 else if (myQuadType == QUAD_TRIANGLE_PREF)
156 myTrianglePreference = true;
158 else if (strcmp("QuadranglePreference", aHyp->GetName()) == 0) {
159 isFirstParams = false;
160 myQuadranglePreference = true;
162 else if (strcmp("TrianglePreference", aHyp->GetName()) == 0){
163 isFirstParams = false;
164 myTrianglePreference = true;
167 isFirstParams = false;
171 // Second(last) assigned hypothesis (if any) is processed now
172 if (hyps.size() > 1) {
175 if (strcmp("QuadranglePreference", aHyp->GetName()) == 0) {
176 myQuadranglePreference = true;
177 myTrianglePreference = false;
178 myQuadType = QUAD_STANDARD;
180 else if (strcmp("TrianglePreference", aHyp->GetName()) == 0){
181 myQuadranglePreference = false;
182 myTrianglePreference = true;
183 myQuadType = QUAD_STANDARD;
187 const StdMeshers_QuadrangleParams* aHyp2 =
188 (const StdMeshers_QuadrangleParams*)aHyp;
189 myTriaVertexID = aHyp2->GetTriaVertex();
191 if (!myQuadranglePreference && !myTrianglePreference) { // priority of hypos
192 myQuadType = aHyp2->GetQuadType();
193 if (myQuadType == QUAD_QUADRANGLE_PREF ||
194 myQuadType == QUAD_QUADRANGLE_PREF_REVERSED)
195 myQuadranglePreference = true;
196 else if (myQuadType == QUAD_TRIANGLE_PREF)
197 myTrianglePreference = true;
202 error( StdMeshers_ViscousLayers2D::CheckHypothesis( aMesh, aShape, aStatus ));
204 return aStatus == HYP_OK;
207 //=============================================================================
211 //=============================================================================
213 bool StdMeshers_Quadrangle_2D::Compute (SMESH_Mesh& aMesh,
214 const TopoDS_Shape& aShape)
216 const TopoDS_Face& F = TopoDS::Face(aShape);
217 aMesh.GetSubMesh( F );
219 // do not initialize my fields before this as StdMeshers_ViscousLayers2D
220 // can call Compute() recursively
221 SMESH_ProxyMesh::Ptr proxyMesh = StdMeshers_ViscousLayers2D::Compute( aMesh, F );
225 myProxyMesh = proxyMesh;
227 SMESH_MesherHelper helper (aMesh);
230 _quadraticMesh = myHelper->IsQuadraticSubMesh(aShape);
231 myNeedSmooth = false;
234 FaceQuadStruct::Ptr quad = CheckNbEdges( aMesh, F, /*considerMesh=*/true );
238 myQuadList.push_back( quad );
240 if ( !getEnforcedUV() )
243 updateDegenUV( quad );
245 int n1 = quad->side[0].NbPoints();
246 int n2 = quad->side[1].NbPoints();
247 int n3 = quad->side[2].NbPoints();
248 int n4 = quad->side[3].NbPoints();
250 enum { NOT_COMPUTED = -1, COMPUTE_FAILED = 0, COMPUTE_OK = 1 };
251 int res = NOT_COMPUTED;
252 if (myQuadranglePreference)
254 int nfull = n1+n2+n3+n4;
255 if ((nfull % 2) == 0 && ((n1 != n3) || (n2 != n4)))
257 // special path genarating only quandrangle faces
258 res = computeQuadPref( aMesh, F, quad );
261 else if (myQuadType == QUAD_REDUCED)
265 int n13tmp = n13/2; n13tmp = n13tmp*2;
266 int n24tmp = n24/2; n24tmp = n24tmp*2;
267 if ((n1 == n3 && n2 != n4 && n24tmp == n24) ||
268 (n2 == n4 && n1 != n3 && n13tmp == n13))
270 res = computeReduced( aMesh, F, quad );
274 if ( n1 != n3 && n2 != n4 )
275 error( COMPERR_WARNING,
276 "To use 'Reduced' transition, "
277 "two opposite sides should have same number of segments, "
278 "but actual number of segments is different on all sides. "
279 "'Standard' transion has been used.");
280 else if ( ! ( n1 == n3 && n2 == n4 ))
281 error( COMPERR_WARNING,
282 "To use 'Reduced' transition, "
283 "two opposite sides should have an even difference in number of segments. "
284 "'Standard' transion has been used.");
288 if ( res == NOT_COMPUTED )
290 if ( n1 != n3 || n2 != n4 )
291 res = computeTriangles( aMesh, F, quad );
293 res = computeQuadDominant( aMesh, F );
296 if ( res == COMPUTE_OK && myNeedSmooth )
299 if ( res == COMPUTE_OK )
302 return ( res == COMPUTE_OK );
305 //================================================================================
307 * \brief Compute quadrangles and triangles on the quad
309 //================================================================================
311 bool StdMeshers_Quadrangle_2D::computeTriangles(SMESH_Mesh& aMesh,
312 const TopoDS_Face& aFace,
313 FaceQuadStruct::Ptr quad)
315 int nb = quad->side[0].grid->NbPoints();
316 int nr = quad->side[1].grid->NbPoints();
317 int nt = quad->side[2].grid->NbPoints();
318 int nl = quad->side[3].grid->NbPoints();
320 // rotate the quad to have nbNodeOut sides on TOP [and LEFT]
322 quad->shift( nl > nr ? 3 : 2, true );
324 quad->shift( 1, true );
326 quad->shift( nt > nb ? 0 : 3, true );
328 if ( !setNormalizedGrid( quad ))
331 if ( quad->nbNodeOut( QUAD_TOP_SIDE ))
333 splitQuad( quad, 0, quad->jSize-2 );
335 if ( quad->nbNodeOut( QUAD_BOTTOM_SIDE )) // this should not happen
337 splitQuad( quad, 0, 1 );
339 FaceQuadStruct::Ptr newQuad = myQuadList.back();
340 if ( quad != newQuad ) // split done
342 { // update left side limit till where to make triangles
343 FaceQuadStruct::Ptr botQuad = // a bottom part
344 ( quad->side[ QUAD_LEFT_SIDE ].from == 0 ) ? quad : newQuad;
345 if ( botQuad->nbNodeOut( QUAD_LEFT_SIDE ) > 0 )
346 botQuad->side[ QUAD_LEFT_SIDE ].to += botQuad->nbNodeOut( QUAD_LEFT_SIDE );
347 else if ( botQuad->nbNodeOut( QUAD_RIGHT_SIDE ) > 0 )
348 botQuad->side[ QUAD_RIGHT_SIDE ].to += botQuad->nbNodeOut( QUAD_RIGHT_SIDE );
350 // make quad be a greatest one
351 if ( quad->side[ QUAD_LEFT_SIDE ].NbPoints() == 2 ||
352 quad->side[ QUAD_RIGHT_SIDE ].NbPoints() == 2 )
354 if ( !setNormalizedGrid( quad ))
358 if ( quad->nbNodeOut( QUAD_RIGHT_SIDE ))
360 splitQuad( quad, quad->iSize-2, 0 );
362 if ( quad->nbNodeOut( QUAD_LEFT_SIDE ))
364 splitQuad( quad, 1, 0 );
366 if ( quad->nbNodeOut( QUAD_TOP_SIDE ))
368 newQuad = myQuadList.back();
369 if ( newQuad == quad ) // too narrow to split
371 // update left side limit till where to make triangles
372 quad->side[ QUAD_LEFT_SIDE ].to--;
376 FaceQuadStruct::Ptr leftQuad =
377 ( quad->side[ QUAD_BOTTOM_SIDE ].from == 0 ) ? quad : newQuad;
378 leftQuad->nbNodeOut( QUAD_TOP_SIDE ) = 0;
383 if ( ! computeQuadDominant( aMesh, aFace ))
386 // try to fix zero-area triangles near straight-angle corners
391 //================================================================================
393 * \brief Compute quadrangles and possibly triangles on all quads of myQuadList
395 //================================================================================
397 bool StdMeshers_Quadrangle_2D::computeQuadDominant(SMESH_Mesh& aMesh,
398 const TopoDS_Face& aFace)
400 if ( !addEnforcedNodes() )
403 std::list< FaceQuadStruct::Ptr >::iterator quad = myQuadList.begin();
404 for ( ; quad != myQuadList.end(); ++quad )
405 if ( !computeQuadDominant( aMesh, aFace, *quad ))
411 //================================================================================
413 * \brief Compute quadrangles and possibly triangles
415 //================================================================================
417 bool StdMeshers_Quadrangle_2D::computeQuadDominant(SMESH_Mesh& aMesh,
418 const TopoDS_Face& aFace,
419 FaceQuadStruct::Ptr quad)
421 // --- set normalized grid on unit square in parametric domain
423 if ( !setNormalizedGrid( quad ))
426 // --- create nodes on points, and create quadrangles
428 int nbhoriz = quad->iSize;
429 int nbvertic = quad->jSize;
431 // internal mesh nodes
432 SMESHDS_Mesh * meshDS = aMesh.GetMeshDS();
433 Handle(Geom_Surface) S = BRep_Tool::Surface(aFace);
434 int i,j, geomFaceID = meshDS->ShapeToIndex(aFace);
435 for (i = 1; i < nbhoriz - 1; i++)
436 for (j = 1; j < nbvertic - 1; j++)
438 UVPtStruct& uvPnt = quad->UVPt( i, j );
439 gp_Pnt P = S->Value( uvPnt.u, uvPnt.v );
440 uvPnt.node = meshDS->AddNode(P.X(), P.Y(), P.Z());
441 meshDS->SetNodeOnFace( uvPnt.node, geomFaceID, uvPnt.u, uvPnt.v );
447 // --.--.--.--.--.-- nbvertic
453 // ---.----.----.--- 0
454 // 0 > > > > > > > > nbhoriz
459 int iup = nbhoriz - 1;
460 if (quad->nbNodeOut(3)) { ilow++; } else { if (quad->nbNodeOut(1)) iup--; }
463 int jup = nbvertic - 1;
464 if (quad->nbNodeOut(0)) { jlow++; } else { if (quad->nbNodeOut(2)) jup--; }
466 // regular quadrangles
467 for (i = ilow; i < iup; i++) {
468 for (j = jlow; j < jup; j++) {
469 const SMDS_MeshNode *a, *b, *c, *d;
470 a = quad->uv_grid[ j * nbhoriz + i ].node;
471 b = quad->uv_grid[ j * nbhoriz + i + 1].node;
472 c = quad->uv_grid[(j + 1) * nbhoriz + i + 1].node;
473 d = quad->uv_grid[(j + 1) * nbhoriz + i ].node;
474 SMDS_MeshFace* face = myHelper->AddFace(a, b, c, d);
476 meshDS->SetMeshElementOnShape(face, geomFaceID);
481 // Boundary elements (must always be on an outer boundary of the FACE)
483 const vector<UVPtStruct>& uv_e0 = quad->side[0].grid->GetUVPtStruct();
484 const vector<UVPtStruct>& uv_e1 = quad->side[1].grid->GetUVPtStruct();
485 const vector<UVPtStruct>& uv_e2 = quad->side[2].grid->GetUVPtStruct();
486 const vector<UVPtStruct>& uv_e3 = quad->side[3].grid->GetUVPtStruct();
488 if (uv_e0.empty() || uv_e1.empty() || uv_e2.empty() || uv_e3.empty())
489 return error(COMPERR_BAD_INPUT_MESH);
491 double eps = Precision::Confusion();
493 int nbdown = (int) uv_e0.size();
494 int nbup = (int) uv_e2.size();
495 int nbright = (int) uv_e1.size();
496 int nbleft = (int) uv_e3.size();
498 if (quad->nbNodeOut(0) && nbvertic == 2) // this should not occure
502 // |___|___|___|___|___|___|
504 // |___|___|___|___|___|___|
506 // |___|___|___|___|___|___| __ first row of the regular grid
507 // . . . . . . . . . __ down edge nodes
509 // >->->->->->->->->->->->-> -- direction of processing
511 int g = 0; // number of last processed node in the regular grid
513 // number of last node of the down edge to be processed
514 int stop = nbdown - 1;
515 // if right edge is out, we will stop at a node, previous to the last one
516 //if (quad->nbNodeOut(1)) stop--;
517 if ( quad->nbNodeOut( QUAD_RIGHT_SIDE ))
518 quad->UVPt( nbhoriz-1, 1 ).node = uv_e1[1].node;
519 if ( quad->nbNodeOut( QUAD_LEFT_SIDE ))
520 quad->UVPt( 0, 1 ).node = uv_e3[1].node;
522 // for each node of the down edge find nearest node
523 // in the first row of the regular grid and link them
524 for (i = 0; i < stop; i++) {
525 const SMDS_MeshNode *a, *b, *c, *d;
527 b = uv_e0[i + 1].node;
528 gp_Pnt pb (b->X(), b->Y(), b->Z());
530 // find node c in the regular grid, which will be linked with node b
533 // right bound reached, link with the rightmost node
535 c = quad->uv_grid[nbhoriz + iup].node;
538 // find in the grid node c, nearest to the b
539 double mind = RealLast();
540 for (int k = g; k <= iup; k++) {
542 const SMDS_MeshNode *nk;
543 if (k < ilow) // this can be, if left edge is out
544 nk = uv_e3[1].node; // get node from the left edge
546 nk = quad->uv_grid[nbhoriz + k].node; // get one of middle nodes
548 gp_Pnt pnk (nk->X(), nk->Y(), nk->Z());
549 double dist = pb.Distance(pnk);
550 if (dist < mind - eps) {
560 if (near == g) { // make triangle
561 SMDS_MeshFace* face = myHelper->AddFace(a, b, c);
562 if (face) meshDS->SetMeshElementOnShape(face, geomFaceID);
564 else { // make quadrangle
568 d = quad->uv_grid[nbhoriz + near - 1].node;
569 //SMDS_MeshFace* face = meshDS->AddFace(a, b, c, d);
571 if (!myTrianglePreference){
572 SMDS_MeshFace* face = myHelper->AddFace(a, b, c, d);
573 if (face) meshDS->SetMeshElementOnShape(face, geomFaceID);
576 splitQuadFace(meshDS, geomFaceID, a, b, c, d);
579 // if node d is not at position g - make additional triangles
581 for (int k = near - 1; k > g; k--) {
582 c = quad->uv_grid[nbhoriz + k].node;
586 d = quad->uv_grid[nbhoriz + k - 1].node;
587 SMDS_MeshFace* face = myHelper->AddFace(a, c, d);
588 if (face) meshDS->SetMeshElementOnShape(face, geomFaceID);
595 if (quad->nbNodeOut(2) && nbvertic == 2)
599 // <-<-<-<-<-<-<-<-<-<-<-<-< -- direction of processing
601 // . . . . . . . . . __ up edge nodes
602 // ___ ___ ___ ___ ___ ___ __ first row of the regular grid
604 // |___|___|___|___|___|___|
606 // |___|___|___|___|___|___|
609 int g = nbhoriz - 1; // last processed node in the regular grid
615 if ( quad->side[3].grid->Edge(0).IsNull() ) // left side is simulated one
617 // quad divided at I but not at J, as nbvertic==nbright==2
618 stop++; // we stop at a second node
622 if ( quad->nbNodeOut( QUAD_RIGHT_SIDE ))
623 quad->UVPt( nbhoriz-1, 0 ).node = uv_e1[ nbright-2 ].node;
624 if ( quad->nbNodeOut( QUAD_LEFT_SIDE ))
625 quad->UVPt( 0, 0 ).node = uv_e3[ nbleft-2 ].node;
627 if ( nbright > 2 ) // there was a split at J
628 quad->nbNodeOut( QUAD_LEFT_SIDE ) = 0;
630 const SMDS_MeshNode *a, *b, *c, *d;
632 // avoid creating zero-area triangles near a straight-angle corner
636 c = uv_e1[nbright-2].node;
637 SMESH_TNodeXYZ pa( a ), pb( b ), pc( c );
638 double area = 0.5 * (( pb - pa ) ^ ( pc - pa )).Modulus();
639 if ( Abs( area ) < 1e-20 )
642 d = quad->UVPt( g, nbvertic-2 ).node;
643 if ( myTrianglePreference )
645 if ( SMDS_MeshFace* face = myHelper->AddFace(a, d, c))
646 meshDS->SetMeshElementOnShape(face, geomFaceID);
650 if ( SMDS_MeshFace* face = myHelper->AddFace(a, b, d, c))
652 meshDS->SetMeshElementOnShape(face, geomFaceID);
653 SMESH_ComputeErrorPtr& err = aMesh.GetSubMesh( aFace )->GetComputeError();
654 if ( !err || err->IsOK() || err->myName < COMPERR_WARNING )
656 err.reset( new SMESH_ComputeError( COMPERR_WARNING,
657 "Bad quality quad created"));
658 err->myBadElements.push_back( face );
665 // for each node of the up edge find nearest node
666 // in the first row of the regular grid and link them
667 for ( ; i > stop; i--) {
669 b = uv_e2[i - 1].node;
670 gp_Pnt pb (b->X(), b->Y(), b->Z());
672 // find node c in the grid, which will be linked with node b
674 if (i == stop + 1) { // left bound reached, link with the leftmost node
675 c = quad->uv_grid[nbhoriz*(nbvertic - 2) + ilow].node;
678 // find node c in the grid, nearest to the b
679 double mind = RealLast();
680 for (int k = g; k >= ilow; k--) {
681 const SMDS_MeshNode *nk;
683 nk = uv_e1[nbright - 2].node;
685 nk = quad->uv_grid[nbhoriz*(nbvertic - 2) + k].node;
686 gp_Pnt pnk (nk->X(), nk->Y(), nk->Z());
687 double dist = pb.Distance(pnk);
688 if (dist < mind - eps) {
698 if (near == g) { // make triangle
699 SMDS_MeshFace* face = myHelper->AddFace(a, b, c);
700 if (face) meshDS->SetMeshElementOnShape(face, geomFaceID);
702 else { // make quadrangle
704 d = uv_e1[nbright - 2].node;
706 d = quad->uv_grid[nbhoriz*(nbvertic - 2) + near + 1].node;
707 //SMDS_MeshFace* face = meshDS->AddFace(a, b, c, d);
708 if (!myTrianglePreference){
709 SMDS_MeshFace* face = myHelper->AddFace(a, b, c, d);
710 if (face) meshDS->SetMeshElementOnShape(face, geomFaceID);
713 splitQuadFace(meshDS, geomFaceID, a, b, c, d);
716 if (near + 1 < g) { // if d is not at g - make additional triangles
717 for (int k = near + 1; k < g; k++) {
718 c = quad->uv_grid[nbhoriz*(nbvertic - 2) + k].node;
720 d = uv_e1[nbright - 2].node;
722 d = quad->uv_grid[nbhoriz*(nbvertic - 2) + k + 1].node;
723 SMDS_MeshFace* face = myHelper->AddFace(a, c, d);
724 if (face) meshDS->SetMeshElementOnShape(face, geomFaceID);
733 // right or left boundary quadrangles
734 if (quad->nbNodeOut( QUAD_RIGHT_SIDE ) && nbhoriz == 2) // this should not occure
736 int g = 0; // last processed node in the grid
737 int stop = nbright - 1;
739 if (quad->side[ QUAD_RIGHT_SIDE ].from != i ) i++;
740 if (quad->side[ QUAD_RIGHT_SIDE ].to != stop ) stop--;
741 for ( ; i < stop; i++) {
742 const SMDS_MeshNode *a, *b, *c, *d;
744 b = uv_e1[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) { // up bondary reached
750 c = quad->uv_grid[nbhoriz*(jup + 1) - 2].node;
753 double mind = RealLast();
754 for (int k = g; k <= jup; k++) {
755 const SMDS_MeshNode *nk;
757 nk = uv_e0[nbdown - 2].node;
759 nk = quad->uv_grid[nbhoriz*(k + 1) - 2].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
778 d = uv_e0[nbdown - 2].node;
780 d = quad->uv_grid[nbhoriz*near - 2].node;
781 //SMDS_MeshFace* face = meshDS->AddFace(a, b, c, d);
783 if (!myTrianglePreference){
784 SMDS_MeshFace* face = myHelper->AddFace(a, b, c, d);
785 if (face) meshDS->SetMeshElementOnShape(face, geomFaceID);
788 splitQuadFace(meshDS, geomFaceID, a, b, c, d);
791 if (near - 1 > g) { // if d not is at g - make additional triangles
792 for (int k = near - 1; k > g; k--) {
793 c = quad->uv_grid[nbhoriz*(k + 1) - 2].node;
795 d = uv_e0[nbdown - 2].node;
797 d = quad->uv_grid[nbhoriz*k - 2].node;
798 SMDS_MeshFace* face = myHelper->AddFace(a, c, d);
799 if (face) meshDS->SetMeshElementOnShape(face, geomFaceID);
806 if (quad->nbNodeOut(3) && nbhoriz == 2) {
807 // MESSAGE("left edge is out");
808 int g = nbvertic - 1; // last processed node in the grid
810 i = quad->side[ QUAD_LEFT_SIDE ].to-1; // nbleft - 1;
812 const SMDS_MeshNode *a, *b, *c, *d;
813 // avoid creating zero-area triangles near a straight-angle corner
817 c = quad->UVPt( 1, g ).node;
818 SMESH_TNodeXYZ pa( a ), pb( b ), pc( c );
819 double area = 0.5 * (( pb - pa ) ^ ( pc - pa )).Modulus();
820 if ( Abs( area ) < 1e-20 )
823 d = quad->UVPt( 1, g ).node;
824 if ( myTrianglePreference )
826 if ( SMDS_MeshFace* face = myHelper->AddFace(a, d, c))
827 meshDS->SetMeshElementOnShape(face, geomFaceID);
831 if ( SMDS_MeshFace* face = myHelper->AddFace(a, b, d, c))
833 meshDS->SetMeshElementOnShape(face, geomFaceID);
834 SMESH_ComputeErrorPtr& err = aMesh.GetSubMesh( aFace )->GetComputeError();
835 if ( !err || err->IsOK() || err->myName < COMPERR_WARNING )
837 err.reset( new SMESH_ComputeError( COMPERR_WARNING,
838 "Bad quality quad created"));
839 err->myBadElements.push_back( face );
846 for (; i > stop; i--) // loop on nodes on the left side
849 b = uv_e3[i - 1].node;
850 gp_Pnt pb (b->X(), b->Y(), b->Z());
852 // find node c in the grid, nearest to the b
854 if (i == stop + 1) { // down bondary reached
855 c = quad->uv_grid[nbhoriz*jlow + 1].node;
859 double mind = RealLast();
860 for (int k = g; k >= jlow; k--) {
861 const SMDS_MeshNode *nk;
863 nk = quad->uv_grid[nbhoriz*jup + 1].node; //uv_e2[1].node;
865 nk = quad->uv_grid[nbhoriz*k + 1].node;
866 gp_Pnt pnk (nk->X(), nk->Y(), nk->Z());
867 double dist = pb.Distance(pnk);
868 if (dist < mind - eps) {
878 if (near == g) { // make triangle
879 SMDS_MeshFace* face = myHelper->AddFace(a, b, c);
880 if (face) meshDS->SetMeshElementOnShape(face, geomFaceID);
882 else { // make quadrangle
884 d = quad->uv_grid[nbhoriz*jup + 1].node; //uv_e2[1].node;
886 d = quad->uv_grid[nbhoriz*(near + 1) + 1].node;
887 if (!myTrianglePreference) {
888 SMDS_MeshFace* face = myHelper->AddFace(a, b, c, d);
889 if (face) meshDS->SetMeshElementOnShape(face, geomFaceID);
892 splitQuadFace(meshDS, geomFaceID, a, b, c, d);
895 if (near + 1 < g) { // if d not is at g - make additional triangles
896 for (int k = near + 1; k < g; k++) {
897 c = quad->uv_grid[nbhoriz*k + 1].node;
899 d = quad->uv_grid[nbhoriz*jup + 1].node; //uv_e2[1].node;
901 d = quad->uv_grid[nbhoriz*(k + 1) + 1].node;
902 SMDS_MeshFace* face = myHelper->AddFace(a, c, d);
903 if (face) meshDS->SetMeshElementOnShape(face, geomFaceID);
917 //=============================================================================
921 //=============================================================================
923 bool StdMeshers_Quadrangle_2D::Evaluate(SMESH_Mesh& aMesh,
924 const TopoDS_Shape& aFace,
925 MapShapeNbElems& aResMap)
928 aMesh.GetSubMesh(aFace);
930 std::vector<int> aNbNodes(4);
931 bool IsQuadratic = false;
932 if (!checkNbEdgesForEvaluate(aMesh, aFace, aResMap, aNbNodes, IsQuadratic)) {
933 std::vector<int> aResVec(SMDSEntity_Last);
934 for (int i=SMDSEntity_Node; i<SMDSEntity_Last; i++) aResVec[i] = 0;
935 SMESH_subMesh * sm = aMesh.GetSubMesh(aFace);
936 aResMap.insert(std::make_pair(sm,aResVec));
937 SMESH_ComputeErrorPtr& smError = sm->GetComputeError();
938 smError.reset(new SMESH_ComputeError(COMPERR_ALGO_FAILED,"Submesh can not be evaluated",this));
942 if (myQuadranglePreference) {
943 int n1 = aNbNodes[0];
944 int n2 = aNbNodes[1];
945 int n3 = aNbNodes[2];
946 int n4 = aNbNodes[3];
947 int nfull = n1+n2+n3+n4;
950 if (nfull==ntmp && ((n1!=n3) || (n2!=n4))) {
951 // special path for using only quandrangle faces
952 return evaluateQuadPref(aMesh, aFace, aNbNodes, aResMap, IsQuadratic);
957 int nbdown = aNbNodes[0];
958 int nbup = aNbNodes[2];
960 int nbright = aNbNodes[1];
961 int nbleft = aNbNodes[3];
963 int nbhoriz = Min(nbdown, nbup);
964 int nbvertic = Min(nbright, nbleft);
966 int dh = Max(nbdown, nbup) - nbhoriz;
967 int dv = Max(nbright, nbleft) - nbvertic;
974 int nbNodes = (nbhoriz-2)*(nbvertic-2);
975 //int nbFaces3 = dh + dv + kdh*(nbvertic-1)*2 + kdv*(nbhoriz-1)*2;
976 int nbFaces3 = dh + dv;
977 //if (kdh==1 && kdv==1) nbFaces3 -= 2;
978 //if (dh>0 && dv>0) nbFaces3 -= 2;
979 //int nbFaces4 = (nbhoriz-1-kdh)*(nbvertic-1-kdv);
980 int nbFaces4 = (nbhoriz-1)*(nbvertic-1);
982 std::vector<int> aVec(SMDSEntity_Last);
983 for (int i=SMDSEntity_Node; i<SMDSEntity_Last; i++) aVec[i] = 0;
985 aVec[SMDSEntity_Quad_Triangle] = nbFaces3;
986 aVec[SMDSEntity_Quad_Quadrangle] = nbFaces4;
987 int nbbndedges = nbdown + nbup + nbright + nbleft -4;
988 int nbintedges = (nbFaces4*4 + nbFaces3*3 - nbbndedges) / 2;
989 aVec[SMDSEntity_Node] = nbNodes + nbintedges;
990 if (aNbNodes.size()==5) {
991 aVec[SMDSEntity_Quad_Triangle] = nbFaces3 + aNbNodes[3] -1;
992 aVec[SMDSEntity_Quad_Quadrangle] = nbFaces4 - aNbNodes[3] +1;
996 aVec[SMDSEntity_Node] = nbNodes;
997 aVec[SMDSEntity_Triangle] = nbFaces3;
998 aVec[SMDSEntity_Quadrangle] = nbFaces4;
999 if (aNbNodes.size()==5) {
1000 aVec[SMDSEntity_Triangle] = nbFaces3 + aNbNodes[3] - 1;
1001 aVec[SMDSEntity_Quadrangle] = nbFaces4 - aNbNodes[3] + 1;
1004 SMESH_subMesh * sm = aMesh.GetSubMesh(aFace);
1005 aResMap.insert(std::make_pair(sm,aVec));
1010 //================================================================================
1012 * \brief Return true if the algorithm can mesh this shape
1013 * \param [in] aShape - shape to check
1014 * \param [in] toCheckAll - if true, this check returns OK if all shapes are OK,
1015 * else, returns OK if at least one shape is OK
1017 //================================================================================
1019 bool StdMeshers_Quadrangle_2D::IsApplicable( const TopoDS_Shape & aShape, bool toCheckAll )
1021 int nbFoundFaces = 0;
1022 for (TopExp_Explorer exp( aShape, TopAbs_FACE ); exp.More(); exp.Next(), ++nbFoundFaces )
1024 const TopoDS_Shape& aFace = exp.Current();
1025 int nbWire = SMESH_MesherHelper::Count( aFace, TopAbs_WIRE, false );
1026 if ( nbWire != 1 ) {
1027 if ( toCheckAll ) return false;
1031 int nbNoDegenEdges = 0;
1032 TopExp_Explorer eExp( aFace, TopAbs_EDGE );
1033 for ( ; eExp.More() && nbNoDegenEdges < 3; eExp.Next() ) {
1034 if ( !SMESH_Algo::isDegenerated( TopoDS::Edge( eExp.Current() )))
1037 if ( toCheckAll && nbNoDegenEdges < 3 ) return false;
1038 if ( !toCheckAll && nbNoDegenEdges >= 3 ) return true;
1040 return ( toCheckAll && nbFoundFaces != 0 );
1043 //================================================================================
1045 * \brief Return true if only two given edges meat at their common vertex
1047 //================================================================================
1049 static bool twoEdgesMeatAtVertex(const TopoDS_Edge& e1,
1050 const TopoDS_Edge& e2,
1054 if (!TopExp::CommonVertex(e1, e2, v))
1056 TopTools_ListIteratorOfListOfShape ancestIt(mesh.GetAncestors(v));
1057 for (; ancestIt.More() ; ancestIt.Next())
1058 if (ancestIt.Value().ShapeType() == TopAbs_EDGE)
1059 if (!e1.IsSame(ancestIt.Value()) && !e2.IsSame(ancestIt.Value()))
1064 //=============================================================================
1068 //=============================================================================
1070 FaceQuadStruct::Ptr StdMeshers_Quadrangle_2D::CheckNbEdges(SMESH_Mesh & aMesh,
1071 const TopoDS_Shape & aShape,
1072 const bool considerMesh)
1074 if ( !myQuadList.empty() && myQuadList.front()->face.IsSame( aShape ))
1075 return myQuadList.front();
1077 TopoDS_Face F = TopoDS::Face(aShape);
1078 if ( F.Orientation() >= TopAbs_INTERNAL ) F.Orientation( TopAbs_FORWARD );
1079 const bool ignoreMediumNodes = _quadraticMesh;
1081 // verify 1 wire only
1082 list< TopoDS_Edge > edges;
1083 list< int > nbEdgesInWire;
1084 int nbWire = SMESH_Block::GetOrderedEdges (F, edges, nbEdgesInWire);
1086 error(COMPERR_BAD_SHAPE, TComm("Wrong number of wires: ") << nbWire);
1087 return FaceQuadStruct::Ptr();
1090 // find corner vertices of the quad
1091 vector<TopoDS_Vertex> corners;
1092 int nbDegenEdges, nbSides = getCorners( F, aMesh, edges, corners, nbDegenEdges, considerMesh );
1095 return FaceQuadStruct::Ptr();
1097 FaceQuadStruct::Ptr quad( new FaceQuadStruct );
1098 quad->side.reserve(nbEdgesInWire.front());
1101 list< TopoDS_Edge >::iterator edgeIt = edges.begin();
1102 if ( nbSides == 3 ) // 3 sides and corners[0] is a vertex with myTriaVertexID
1104 for ( int iSide = 0; iSide < 3; ++iSide )
1106 list< TopoDS_Edge > sideEdges;
1107 TopoDS_Vertex nextSideV = corners[( iSide + 1 ) % 3 ];
1108 while ( edgeIt != edges.end() &&
1109 !nextSideV.IsSame( SMESH_MesherHelper::IthVertex( 0, *edgeIt )))
1110 if ( SMESH_Algo::isDegenerated( *edgeIt ))
1113 sideEdges.push_back( *edgeIt++ );
1114 if ( !sideEdges.empty() )
1115 quad->side.push_back( StdMeshers_FaceSide::New(F, sideEdges, &aMesh, iSide < QUAD_TOP_SIDE,
1116 ignoreMediumNodes, myProxyMesh));
1120 const vector<UVPtStruct>& UVPSleft = quad->side[0].GetUVPtStruct(true,0);
1121 /* vector<UVPtStruct>& UVPStop = */quad->side[1].GetUVPtStruct(false,1);
1122 /* vector<UVPtStruct>& UVPSright = */quad->side[2].GetUVPtStruct(true,1);
1123 const SMDS_MeshNode* aNode = UVPSleft[0].node;
1124 gp_Pnt2d aPnt2d = UVPSleft[0].UV();
1125 quad->side.push_back( StdMeshers_FaceSide::New( quad->side[1].grid.get(), aNode, &aPnt2d ));
1126 myNeedSmooth = ( nbDegenEdges > 0 );
1131 myNeedSmooth = ( corners.size() == 4 && nbDegenEdges > 0 );
1132 int iSide = 0, nbUsedDegen = 0, nbLoops = 0;
1133 for ( ; edgeIt != edges.end(); ++nbLoops )
1135 list< TopoDS_Edge > sideEdges;
1136 TopoDS_Vertex nextSideV = corners[( iSide + 1 - nbUsedDegen ) % corners.size() ];
1137 bool nextSideVReached = false;
1140 const TopoDS_Edge& edge = *edgeIt;
1141 nextSideVReached = nextSideV.IsSame( myHelper->IthVertex( 1, edge ));
1142 if ( SMESH_Algo::isDegenerated( edge ))
1144 if ( !myNeedSmooth ) // need to make a side on a degen edge
1146 if ( sideEdges.empty() )
1148 sideEdges.push_back( edge );
1150 nextSideVReached = true;
1160 sideEdges.push_back( edge );
1164 while ( edgeIt != edges.end() && !nextSideVReached );
1166 if ( !sideEdges.empty() )
1168 quad->side.push_back
1169 ( StdMeshers_FaceSide::New( F, sideEdges, &aMesh, iSide < QUAD_TOP_SIDE,
1170 ignoreMediumNodes, myProxyMesh ));
1173 if ( quad->side.size() == 4 )
1177 error(TComm("Bug: infinite loop in StdMeshers_Quadrangle_2D::CheckNbEdges()"));
1182 if ( quad && quad->side.size() != 4 )
1184 error(TComm("Bug: ") << quad->side.size() << " sides found instead of 4");
1193 //=============================================================================
1197 //=============================================================================
1199 bool StdMeshers_Quadrangle_2D::checkNbEdgesForEvaluate(SMESH_Mesh& aMesh,
1200 const TopoDS_Shape & aShape,
1201 MapShapeNbElems& aResMap,
1202 std::vector<int>& aNbNodes,
1206 const TopoDS_Face & F = TopoDS::Face(aShape);
1208 // verify 1 wire only, with 4 edges
1209 list< TopoDS_Edge > edges;
1210 list< int > nbEdgesInWire;
1211 int nbWire = SMESH_Block::GetOrderedEdges (F, edges, nbEdgesInWire);
1219 list< TopoDS_Edge >::iterator edgeIt = edges.begin();
1220 SMESH_subMesh * sm = aMesh.GetSubMesh(*edgeIt);
1221 MapShapeNbElemsItr anIt = aResMap.find(sm);
1222 if (anIt==aResMap.end()) {
1225 std::vector<int> aVec = (*anIt).second;
1226 IsQuadratic = (aVec[SMDSEntity_Quad_Edge] > aVec[SMDSEntity_Edge]);
1227 if (nbEdgesInWire.front() == 3) { // exactly 3 edges
1228 if (myTriaVertexID>0) {
1229 SMESHDS_Mesh* meshDS = aMesh.GetMeshDS();
1230 TopoDS_Vertex V = TopoDS::Vertex(meshDS->IndexToShape(myTriaVertexID));
1232 TopoDS_Edge E1,E2,E3;
1233 for (; edgeIt != edges.end(); ++edgeIt) {
1234 TopoDS_Edge E = TopoDS::Edge(*edgeIt);
1235 TopoDS_Vertex VF, VL;
1236 TopExp::Vertices(E, VF, VL, true);
1239 else if (VL.IsSame(V))
1244 SMESH_subMesh * sm = aMesh.GetSubMesh(E1);
1245 MapShapeNbElemsItr anIt = aResMap.find(sm);
1246 if (anIt==aResMap.end()) return false;
1247 std::vector<int> aVec = (*anIt).second;
1249 aNbNodes[0] = (aVec[SMDSEntity_Node]-1)/2 + 2;
1251 aNbNodes[0] = aVec[SMDSEntity_Node] + 2;
1252 sm = aMesh.GetSubMesh(E2);
1253 anIt = aResMap.find(sm);
1254 if (anIt==aResMap.end()) return false;
1255 aVec = (*anIt).second;
1257 aNbNodes[1] = (aVec[SMDSEntity_Node]-1)/2 + 2;
1259 aNbNodes[1] = aVec[SMDSEntity_Node] + 2;
1260 sm = aMesh.GetSubMesh(E3);
1261 anIt = aResMap.find(sm);
1262 if (anIt==aResMap.end()) return false;
1263 aVec = (*anIt).second;
1265 aNbNodes[2] = (aVec[SMDSEntity_Node]-1)/2 + 2;
1267 aNbNodes[2] = aVec[SMDSEntity_Node] + 2;
1268 aNbNodes[3] = aNbNodes[1];
1274 if (nbEdgesInWire.front() == 4) { // exactly 4 edges
1275 for (; edgeIt != edges.end(); edgeIt++) {
1276 SMESH_subMesh * sm = aMesh.GetSubMesh(*edgeIt);
1277 MapShapeNbElemsItr anIt = aResMap.find(sm);
1278 if (anIt==aResMap.end()) {
1281 std::vector<int> aVec = (*anIt).second;
1283 aNbNodes[nbSides] = (aVec[SMDSEntity_Node]-1)/2 + 2;
1285 aNbNodes[nbSides] = aVec[SMDSEntity_Node] + 2;
1289 else if (nbEdgesInWire.front() > 4) { // more than 4 edges - try to unite some
1290 list< TopoDS_Edge > sideEdges;
1291 while (!edges.empty()) {
1293 sideEdges.splice(sideEdges.end(), edges, edges.begin()); // edges.front() -> sideEdges.end()
1294 bool sameSide = true;
1295 while (!edges.empty() && sameSide) {
1296 sameSide = SMESH_Algo::IsContinuous(sideEdges.back(), edges.front());
1298 sideEdges.splice(sideEdges.end(), edges, edges.begin());
1300 if (nbSides == 0) { // go backward from the first edge
1302 while (!edges.empty() && sameSide) {
1303 sameSide = SMESH_Algo::IsContinuous(sideEdges.front(), edges.back());
1305 sideEdges.splice(sideEdges.begin(), edges, --edges.end());
1308 list<TopoDS_Edge>::iterator ite = sideEdges.begin();
1309 aNbNodes[nbSides] = 1;
1310 for (; ite!=sideEdges.end(); ite++) {
1311 SMESH_subMesh * sm = aMesh.GetSubMesh(*ite);
1312 MapShapeNbElemsItr anIt = aResMap.find(sm);
1313 if (anIt==aResMap.end()) {
1316 std::vector<int> aVec = (*anIt).second;
1318 aNbNodes[nbSides] += (aVec[SMDSEntity_Node]-1)/2 + 1;
1320 aNbNodes[nbSides] += aVec[SMDSEntity_Node] + 1;
1324 // issue 20222. Try to unite only edges shared by two same faces
1327 SMESH_Block::GetOrderedEdges (F, edges, nbEdgesInWire);
1328 while (!edges.empty()) {
1330 sideEdges.splice(sideEdges.end(), edges, edges.begin());
1331 bool sameSide = true;
1332 while (!edges.empty() && sameSide) {
1334 SMESH_Algo::IsContinuous(sideEdges.back(), edges.front()) &&
1335 twoEdgesMeatAtVertex(sideEdges.back(), edges.front(), aMesh);
1337 sideEdges.splice(sideEdges.end(), edges, edges.begin());
1339 if (nbSides == 0) { // go backward from the first edge
1341 while (!edges.empty() && sameSide) {
1343 SMESH_Algo::IsContinuous(sideEdges.front(), edges.back()) &&
1344 twoEdgesMeatAtVertex(sideEdges.front(), edges.back(), aMesh);
1346 sideEdges.splice(sideEdges.begin(), edges, --edges.end());
1349 list<TopoDS_Edge>::iterator ite = sideEdges.begin();
1350 aNbNodes[nbSides] = 1;
1351 for (; ite!=sideEdges.end(); ite++) {
1352 SMESH_subMesh * sm = aMesh.GetSubMesh(*ite);
1353 MapShapeNbElemsItr anIt = aResMap.find(sm);
1354 if (anIt==aResMap.end()) {
1357 std::vector<int> aVec = (*anIt).second;
1359 aNbNodes[nbSides] += (aVec[SMDSEntity_Node]-1)/2 + 1;
1361 aNbNodes[nbSides] += aVec[SMDSEntity_Node] + 1;
1369 nbSides = nbEdgesInWire.front();
1370 error(COMPERR_BAD_SHAPE, TComm("Face must have 4 sides but not ") << nbSides);
1378 //=============================================================================
1382 //=============================================================================
1385 StdMeshers_Quadrangle_2D::CheckAnd2Dcompute (SMESH_Mesh & aMesh,
1386 const TopoDS_Shape & aShape,
1387 const bool CreateQuadratic)
1389 _quadraticMesh = CreateQuadratic;
1391 FaceQuadStruct::Ptr quad = CheckNbEdges(aMesh, aShape);
1394 // set normalized grid on unit square in parametric domain
1395 if ( ! setNormalizedGrid( quad ))
1403 inline const vector<UVPtStruct>& getUVPtStructIn(FaceQuadStruct::Ptr& quad, int i, int nbSeg)
1405 bool isXConst = (i == QUAD_BOTTOM_SIDE || i == QUAD_TOP_SIDE);
1406 double constValue = (i == QUAD_BOTTOM_SIDE || i == QUAD_LEFT_SIDE) ? 0 : 1;
1408 quad->nbNodeOut(i) ?
1409 quad->side[i].grid->SimulateUVPtStruct(nbSeg,isXConst,constValue) :
1410 quad->side[i].grid->GetUVPtStruct (isXConst,constValue);
1412 inline gp_UV calcUV(double x, double y,
1413 const gp_UV& a0,const gp_UV& a1,const gp_UV& a2,const gp_UV& a3,
1414 const gp_UV& p0,const gp_UV& p1,const gp_UV& p2,const gp_UV& p3)
1417 ((1 - y) * p0 + x * p1 + y * p2 + (1 - x) * p3 ) -
1418 ((1 - x) * (1 - y) * a0 + x * (1 - y) * a1 + x * y * a2 + (1 - x) * y * a3);
1422 //=============================================================================
1426 //=============================================================================
1428 bool StdMeshers_Quadrangle_2D::setNormalizedGrid (FaceQuadStruct::Ptr quad)
1430 if ( !quad->uv_grid.empty() )
1433 // Algorithme décrit dans "Génération automatique de maillages"
1434 // P.L. GEORGE, MASSON, § 6.4.1 p. 84-85
1435 // traitement dans le domaine paramétrique 2d u,v
1436 // transport - projection sur le carré unité
1439 // |<----north-2-------^ a3 -------------> a2
1441 // west-3 east-1 =right | |
1445 // v----south-0--------> a0 -------------> a1
1449 const FaceQuadStruct::Side & bSide = quad->side[0];
1450 const FaceQuadStruct::Side & rSide = quad->side[1];
1451 const FaceQuadStruct::Side & tSide = quad->side[2];
1452 const FaceQuadStruct::Side & lSide = quad->side[3];
1454 int nbhoriz = Min( bSide.NbPoints(), tSide.NbPoints() );
1455 int nbvertic = Min( rSide.NbPoints(), lSide.NbPoints() );
1457 if ( myQuadList.size() == 1 )
1459 // all sub-quads must have NO sides with nbNodeOut > 0
1460 quad->nbNodeOut(0) = Max( 0, bSide.grid->NbPoints() - tSide.grid->NbPoints() );
1461 quad->nbNodeOut(1) = Max( 0, rSide.grid->NbPoints() - lSide.grid->NbPoints() );
1462 quad->nbNodeOut(2) = Max( 0, tSide.grid->NbPoints() - bSide.grid->NbPoints() );
1463 quad->nbNodeOut(3) = Max( 0, lSide.grid->NbPoints() - rSide.grid->NbPoints() );
1465 const vector<UVPtStruct>& uv_e0 = bSide.GetUVPtStruct();
1466 const vector<UVPtStruct>& uv_e1 = rSide.GetUVPtStruct();
1467 const vector<UVPtStruct>& uv_e2 = tSide.GetUVPtStruct();
1468 const vector<UVPtStruct>& uv_e3 = lSide.GetUVPtStruct();
1469 if (uv_e0.empty() || uv_e1.empty() || uv_e2.empty() || uv_e3.empty())
1470 //return error("Can't find nodes on sides");
1471 return error(COMPERR_BAD_INPUT_MESH);
1473 quad->uv_grid.resize( nbvertic * nbhoriz );
1474 quad->iSize = nbhoriz;
1475 quad->jSize = nbvertic;
1476 UVPtStruct *uv_grid = & quad->uv_grid[0];
1478 quad->uv_box.Clear();
1480 // copy data of face boundary
1482 FaceQuadStruct::SideIterator sideIter;
1486 const double x0 = bSide.First().normParam;
1487 const double dx = bSide.Last().normParam - bSide.First().normParam;
1488 for ( sideIter.Init( bSide ); sideIter.More(); sideIter.Next() ) {
1489 sideIter.UVPt().x = ( sideIter.UVPt().normParam - x0 ) / dx;
1490 sideIter.UVPt().y = 0.;
1491 uv_grid[ j * nbhoriz + sideIter.Count() ] = sideIter.UVPt();
1492 quad->uv_box.Add( sideIter.UVPt().UV() );
1496 const int i = nbhoriz - 1;
1497 const double y0 = rSide.First().normParam;
1498 const double dy = rSide.Last().normParam - rSide.First().normParam;
1499 sideIter.Init( rSide );
1500 if ( quad->UVPt( i, sideIter.Count() ).node )
1501 sideIter.Next(); // avoid copying from a split emulated side
1502 for ( ; sideIter.More(); sideIter.Next() ) {
1503 sideIter.UVPt().x = 1.;
1504 sideIter.UVPt().y = ( sideIter.UVPt().normParam - y0 ) / dy;
1505 uv_grid[ sideIter.Count() * nbhoriz + i ] = sideIter.UVPt();
1506 quad->uv_box.Add( sideIter.UVPt().UV() );
1510 const int j = nbvertic - 1;
1511 const double x0 = tSide.First().normParam;
1512 const double dx = tSide.Last().normParam - tSide.First().normParam;
1513 int i = 0, nb = nbhoriz;
1514 sideIter.Init( tSide );
1515 if ( quad->UVPt( nb-1, j ).node ) --nb; // avoid copying from a split emulated side
1516 for ( ; i < nb; i++, sideIter.Next()) {
1517 sideIter.UVPt().x = ( sideIter.UVPt().normParam - x0 ) / dx;
1518 sideIter.UVPt().y = 1.;
1519 uv_grid[ j * nbhoriz + i ] = sideIter.UVPt();
1520 quad->uv_box.Add( sideIter.UVPt().UV() );
1525 const double y0 = lSide.First().normParam;
1526 const double dy = lSide.Last().normParam - lSide.First().normParam;
1527 int j = 0, nb = nbvertic;
1528 sideIter.Init( lSide );
1529 if ( quad->UVPt( i, j ).node )
1530 ++j, sideIter.Next(); // avoid copying from a split emulated side
1531 if ( quad->UVPt( i, nb-1 ).node )
1533 for ( ; j < nb; j++, sideIter.Next()) {
1534 sideIter.UVPt().x = 0.;
1535 sideIter.UVPt().y = ( sideIter.UVPt().normParam - y0 ) / dy;
1536 uv_grid[ j * nbhoriz + i ] = sideIter.UVPt();
1537 quad->uv_box.Add( sideIter.UVPt().UV() );
1541 // normalized 2d parameters on grid
1543 for (int i = 1; i < nbhoriz-1; i++)
1545 const double x0 = quad->UVPt( i, 0 ).x;
1546 const double x1 = quad->UVPt( i, nbvertic-1 ).x;
1547 for (int j = 1; j < nbvertic-1; j++)
1549 const double y0 = quad->UVPt( 0, j ).y;
1550 const double y1 = quad->UVPt( nbhoriz-1, j ).y;
1551 // --- intersection : x=x0+(y0+x(y1-y0))(x1-x0)
1552 double x = (x0 + y0 * (x1 - x0)) / (1 - (y1 - y0) * (x1 - x0));
1553 double y = y0 + x * (y1 - y0);
1554 int ij = j * nbhoriz + i;
1557 uv_grid[ij].node = NULL;
1561 // projection on 2d domain (u,v)
1563 gp_UV a0 = quad->UVPt( 0, 0 ).UV();
1564 gp_UV a1 = quad->UVPt( nbhoriz-1, 0 ).UV();
1565 gp_UV a2 = quad->UVPt( nbhoriz-1, nbvertic-1 ).UV();
1566 gp_UV a3 = quad->UVPt( 0, nbvertic-1 ).UV();
1568 for (int i = 1; i < nbhoriz-1; i++)
1570 gp_UV p0 = quad->UVPt( i, 0 ).UV();
1571 gp_UV p2 = quad->UVPt( i, nbvertic-1 ).UV();
1572 for (int j = 1; j < nbvertic-1; j++)
1574 gp_UV p1 = quad->UVPt( nbhoriz-1, j ).UV();
1575 gp_UV p3 = quad->UVPt( 0, j ).UV();
1577 int ij = j * nbhoriz + i;
1578 double x = uv_grid[ij].x;
1579 double y = uv_grid[ij].y;
1581 gp_UV uv = calcUV(x,y, a0,a1,a2,a3, p0,p1,p2,p3);
1583 uv_grid[ij].u = uv.X();
1584 uv_grid[ij].v = uv.Y();
1590 //=======================================================================
1591 //function : ShiftQuad
1592 //purpose : auxilary function for computeQuadPref
1593 //=======================================================================
1595 void StdMeshers_Quadrangle_2D::shiftQuad(FaceQuadStruct::Ptr& quad, const int num )
1597 quad->shift( num, /*ori=*/true, /*keepGrid=*/myQuadList.size() > 1 );
1600 //================================================================================
1602 * \brief Rotate sides of a quad by given nb of quartes
1603 * \param nb - number of rotation quartes
1604 * \param ori - to keep orientation of sides as in an unit quad or not
1605 * \param keepGrid - if \c true Side::grid is not changed, Side::from and Side::to
1606 * are altered instead
1608 //================================================================================
1610 void FaceQuadStruct::shift( size_t nb, bool ori, bool keepGrid )
1612 if ( nb == 0 ) return;
1614 vector< Side > newSides( side.size() );
1615 vector< Side* > sidePtrs( side.size() );
1616 for (int i = QUAD_BOTTOM_SIDE; i < NB_QUAD_SIDES; ++i)
1618 int id = (i + nb) % NB_QUAD_SIDES;
1621 bool wasForward = (i < QUAD_TOP_SIDE);
1622 bool newForward = (id < QUAD_TOP_SIDE);
1623 if ( wasForward != newForward )
1624 side[ i ].Reverse( keepGrid );
1626 newSides[ id ] = side[ i ];
1627 sidePtrs[ i ] = & side[ i ];
1629 // make newSides refer newSides via Side::Contact's
1630 for ( size_t i = 0; i < newSides.size(); ++i )
1632 FaceQuadStruct::Side& ns = newSides[ i ];
1633 for ( size_t iC = 0; iC < ns.contacts.size(); ++iC )
1635 FaceQuadStruct::Side* oSide = ns.contacts[iC].other_side;
1636 vector< Side* >::iterator sIt = std::find( sidePtrs.begin(), sidePtrs.end(), oSide );
1637 if ( sIt != sidePtrs.end() )
1638 ns.contacts[iC].other_side = & newSides[ *sIt - sidePtrs[0] ];
1641 newSides.swap( side );
1646 //=======================================================================
1648 //purpose : auxilary function for computeQuadPref
1649 //=======================================================================
1651 static gp_UV calcUV(double x0, double x1, double y0, double y1,
1652 FaceQuadStruct::Ptr& quad,
1653 const gp_UV& a0, const gp_UV& a1,
1654 const gp_UV& a2, const gp_UV& a3)
1656 double x = (x0 + y0 * (x1 - x0)) / (1 - (y1 - y0) * (x1 - x0));
1657 double y = y0 + x * (y1 - y0);
1659 gp_UV p0 = quad->side[QUAD_BOTTOM_SIDE].grid->Value2d(x).XY();
1660 gp_UV p1 = quad->side[QUAD_RIGHT_SIDE ].grid->Value2d(y).XY();
1661 gp_UV p2 = quad->side[QUAD_TOP_SIDE ].grid->Value2d(x).XY();
1662 gp_UV p3 = quad->side[QUAD_LEFT_SIDE ].grid->Value2d(y).XY();
1664 gp_UV uv = calcUV(x,y, a0,a1,a2,a3, p0,p1,p2,p3);
1669 //=======================================================================
1670 //function : calcUV2
1671 //purpose : auxilary function for computeQuadPref
1672 //=======================================================================
1674 static gp_UV calcUV2(double x, double y,
1675 FaceQuadStruct::Ptr& quad,
1676 const gp_UV& a0, const gp_UV& a1,
1677 const gp_UV& a2, const gp_UV& a3)
1679 gp_UV p0 = quad->side[QUAD_BOTTOM_SIDE].grid->Value2d(x).XY();
1680 gp_UV p1 = quad->side[QUAD_RIGHT_SIDE ].grid->Value2d(y).XY();
1681 gp_UV p2 = quad->side[QUAD_TOP_SIDE ].grid->Value2d(x).XY();
1682 gp_UV p3 = quad->side[QUAD_LEFT_SIDE ].grid->Value2d(y).XY();
1684 gp_UV uv = calcUV(x,y, a0,a1,a2,a3, p0,p1,p2,p3);
1690 //=======================================================================
1692 * Create only quandrangle faces
1694 //=======================================================================
1696 bool StdMeshers_Quadrangle_2D::computeQuadPref (SMESH_Mesh & aMesh,
1697 const TopoDS_Face& aFace,
1698 FaceQuadStruct::Ptr quad)
1700 const bool OldVersion = (myQuadType == QUAD_QUADRANGLE_PREF_REVERSED);
1701 const bool WisF = true;
1703 SMESHDS_Mesh * meshDS = aMesh.GetMeshDS();
1704 Handle(Geom_Surface) S = BRep_Tool::Surface(aFace);
1705 int i,j, geomFaceID = meshDS->ShapeToIndex(aFace);
1707 int nb = quad->side[0].NbPoints();
1708 int nr = quad->side[1].NbPoints();
1709 int nt = quad->side[2].NbPoints();
1710 int nl = quad->side[3].NbPoints();
1711 int dh = abs(nb-nt);
1712 int dv = abs(nr-nl);
1714 if ( myForcedPnts.empty() )
1716 // rotate sides to be as in the picture below and to have
1717 // dh >= dv and nt > nb
1719 shiftQuad( quad, ( nt > nb ) ? 0 : 2 );
1721 shiftQuad( quad, ( nr > nl ) ? 1 : 3 );
1725 // rotate the quad to have nt > nb [and nr > nl]
1727 shiftQuad ( quad, nr > nl ? 1 : 2 );
1729 shiftQuad( quad, nb == nt ? 1 : 0 );
1731 shiftQuad( quad, 3 );
1734 nb = quad->side[0].NbPoints();
1735 nr = quad->side[1].NbPoints();
1736 nt = quad->side[2].NbPoints();
1737 nl = quad->side[3].NbPoints();
1740 int nbh = Max(nb,nt);
1741 int nbv = Max(nr,nl);
1745 // Orientation of face and 3 main domain for future faces
1746 // ----------- Old version ---------------
1752 // left | |__| | rigth
1759 // ----------- New version ---------------
1765 // left |/________\| rigth
1773 const int bfrom = quad->side[0].from;
1774 const int rfrom = quad->side[1].from;
1775 const int tfrom = quad->side[2].from;
1776 const int lfrom = quad->side[3].from;
1778 const vector<UVPtStruct>& uv_eb_vec = quad->side[0].GetUVPtStruct(true,0);
1779 const vector<UVPtStruct>& uv_er_vec = quad->side[1].GetUVPtStruct(false,1);
1780 const vector<UVPtStruct>& uv_et_vec = quad->side[2].GetUVPtStruct(true,1);
1781 const vector<UVPtStruct>& uv_el_vec = quad->side[3].GetUVPtStruct(false,0);
1782 if (uv_eb_vec.empty() ||
1783 uv_er_vec.empty() ||
1784 uv_et_vec.empty() ||
1786 return error(COMPERR_BAD_INPUT_MESH);
1788 FaceQuadStruct::SideIterator uv_eb, uv_er, uv_et, uv_el;
1789 uv_eb.Init( quad->side[0] );
1790 uv_er.Init( quad->side[1] );
1791 uv_et.Init( quad->side[2] );
1792 uv_el.Init( quad->side[3] );
1794 gp_UV a0,a1,a2,a3, p0,p1,p2,p3, uv;
1797 a0 = uv_eb[ 0 ].UV();
1798 a1 = uv_er[ 0 ].UV();
1799 a2 = uv_er[ nr-1 ].UV();
1800 a3 = uv_et[ 0 ].UV();
1802 if ( !myForcedPnts.empty() )
1804 if ( dv != 0 && dh != 0 ) // here myQuadList.size() == 1
1806 const int dmin = Min( dv, dh );
1808 // Make a side separating domains L and Cb
1809 StdMeshers_FaceSidePtr sideLCb;
1810 UVPtStruct p3dom; // a point where 3 domains meat
1812 vector<UVPtStruct> pointsLCb( dmin+1 ); // 1--------1
1813 pointsLCb[0] = uv_eb[0]; // | | |
1814 for ( int i = 1; i <= dmin; ++i ) // | |Ct|
1816 x = uv_et[ i ].normParam; // | |__|
1817 y = uv_er[ i ].normParam; // | / |
1818 p0 = quad->side[0].grid->Value2d( x ).XY(); // | / Cb |dmin
1819 p1 = uv_er[ i ].UV(); // |/ |
1820 p2 = uv_et[ i ].UV(); // 0--------0
1821 p3 = quad->side[3].grid->Value2d( y ).XY();
1822 uv = calcUV( x,y, a0,a1,a2,a3, p0,p1,p2,p3 );
1823 pointsLCb[ i ].u = uv.X();
1824 pointsLCb[ i ].v = uv.Y();
1826 sideLCb = StdMeshers_FaceSide::New( pointsLCb, aFace );
1827 p3dom = pointsLCb.back();
1829 // Make a side separating domains L and Ct
1830 StdMeshers_FaceSidePtr sideLCt;
1832 vector<UVPtStruct> pointsLCt( nl );
1833 pointsLCt[0] = p3dom;
1834 pointsLCt.back() = uv_et[ dmin ];
1835 x = uv_et[ dmin ].normParam;
1836 p0 = quad->side[0].grid->Value2d( x ).XY();
1837 p2 = uv_et[ dmin ].UV();
1838 double y0 = uv_er[ dmin ].normParam;
1839 for ( int i = 1; i < nl-1; ++i )
1841 y = y0 + i / ( nl-1. ) * ( 1. - y0 );
1842 p1 = quad->side[1].grid->Value2d( y ).XY();
1843 p3 = quad->side[3].grid->Value2d( y ).XY();
1844 uv = calcUV( x,y, a0,a1,a2,a3, p0,p1,p2,p3 );
1845 pointsLCt[ i ].u = uv.X();
1846 pointsLCt[ i ].v = uv.Y();
1848 sideLCt = StdMeshers_FaceSide::New( pointsLCt, aFace );
1850 // Make a side separating domains Cb and Ct
1851 StdMeshers_FaceSidePtr sideCbCt;
1853 vector<UVPtStruct> pointsCbCt( nb );
1854 pointsCbCt[0] = p3dom;
1855 pointsCbCt.back() = uv_er[ dmin ];
1856 y = uv_er[ dmin ].normParam;
1857 p1 = uv_er[ dmin ].UV();
1858 p3 = quad->side[3].grid->Value2d( y ).XY();
1859 double x0 = uv_et[ dmin ].normParam;
1860 for ( int i = 1; i < nb-1; ++i )
1862 x = x0 + i / ( nb-1. ) * ( 1. - x0 );
1863 p2 = quad->side[2].grid->Value2d( x ).XY();
1864 p0 = quad->side[0].grid->Value2d( x ).XY();
1865 uv = calcUV( x,y, a0,a1,a2,a3, p0,p1,p2,p3 );
1866 pointsCbCt[ i ].u = uv.X();
1867 pointsCbCt[ i ].v = uv.Y();
1869 sideCbCt = StdMeshers_FaceSide::New( pointsCbCt, aFace );
1872 FaceQuadStruct* qCb = new FaceQuadStruct( quad->face, "Cb" );
1873 myQuadList.push_back( FaceQuadStruct::Ptr( qCb ));
1874 qCb->side.resize(4);
1875 qCb->side[0] = quad->side[0];
1876 qCb->side[1] = quad->side[1];
1877 qCb->side[2] = sideCbCt;
1878 qCb->side[3] = sideLCb;
1879 qCb->side[1].to = dmin+1;
1881 FaceQuadStruct* qL = new FaceQuadStruct( quad->face, "L" );
1882 myQuadList.push_back( FaceQuadStruct::Ptr( qL ));
1884 qL->side[0] = sideLCb;
1885 qL->side[1] = sideLCt;
1886 qL->side[2] = quad->side[2];
1887 qL->side[3] = quad->side[3];
1888 qL->side[2].to = dmin+1;
1889 // Make Ct from the main quad
1890 FaceQuadStruct::Ptr qCt = quad;
1891 qCt->side[0] = sideCbCt;
1892 qCt->side[3] = sideLCt;
1893 qCt->side[1].from = dmin;
1894 qCt->side[2].from = dmin;
1895 qCt->uv_grid.clear();
1899 qCb->side[3].AddContact( dmin, & qCb->side[2], 0 );
1900 qCb->side[3].AddContact( dmin, & qCt->side[3], 0 );
1901 qCt->side[3].AddContact( 0, & qCt->side[0], 0 );
1902 qCt->side[0].AddContact( 0, & qL ->side[0], dmin );
1903 qL ->side[0].AddContact( dmin, & qL ->side[1], 0 );
1904 qL ->side[0].AddContact( dmin, & qCb->side[2], 0 );
1907 return computeQuadDominant( aMesh, aFace );
1909 return computeQuadPref( aMesh, aFace, qCt );
1911 } // if ( dv != 0 && dh != 0 )
1913 const int db = quad->side[0].IsReversed() ? -1 : +1;
1914 const int dr = quad->side[1].IsReversed() ? -1 : +1;
1915 const int dt = quad->side[2].IsReversed() ? -1 : +1;
1916 const int dl = quad->side[3].IsReversed() ? -1 : +1;
1918 // Case dv == 0, here possibly myQuadList.size() > 1
1930 const int lw = dh/2; // lateral width
1934 double lL = quad->side[3].Length();
1935 double lLwL = quad->side[2].Length( tfrom,
1936 tfrom + ( lw ) * dt );
1937 yCbL = lLwL / ( lLwL + lL );
1939 double lR = quad->side[1].Length();
1940 double lLwR = quad->side[2].Length( tfrom + ( lw + nb-1 ) * dt,
1941 tfrom + ( lw + nb-1 + lw ) * dt);
1942 yCbR = lLwR / ( lLwR + lR );
1944 // Make sides separating domains Cb and L and R
1945 StdMeshers_FaceSidePtr sideLCb, sideRCb;
1946 UVPtStruct pTBL, pTBR; // points where 3 domains meat
1948 vector<UVPtStruct> pointsLCb( lw+1 ), pointsRCb( lw+1 );
1949 pointsLCb[0] = uv_eb[ 0 ];
1950 pointsRCb[0] = uv_eb[ nb-1 ];
1951 for ( int i = 1, i2 = nt-2; i <= lw; ++i, --i2 )
1953 x = quad->side[2].Param( i );
1955 p0 = quad->side[0].Value2d( x );
1956 p1 = quad->side[1].Value2d( y );
1957 p2 = uv_et[ i ].UV();
1958 p3 = quad->side[3].Value2d( y );
1959 uv = calcUV( x,y, a0,a1,a2,a3, p0,p1,p2,p3 );
1960 pointsLCb[ i ].u = uv.X();
1961 pointsLCb[ i ].v = uv.Y();
1962 pointsLCb[ i ].x = x;
1964 x = quad->side[2].Param( i2 );
1966 p1 = quad->side[1].Value2d( y );
1967 p0 = quad->side[0].Value2d( x );
1968 p2 = uv_et[ i2 ].UV();
1969 p3 = quad->side[3].Value2d( y );
1970 uv = calcUV( x,y, a0,a1,a2,a3, p0,p1,p2,p3 );
1971 pointsRCb[ i ].u = uv.X();
1972 pointsRCb[ i ].v = uv.Y();
1973 pointsRCb[ i ].x = x;
1975 sideLCb = StdMeshers_FaceSide::New( pointsLCb, aFace );
1976 sideRCb = StdMeshers_FaceSide::New( pointsRCb, aFace );
1977 pTBL = pointsLCb.back();
1978 pTBR = pointsRCb.back();
1980 // Make sides separating domains Ct and L and R
1981 StdMeshers_FaceSidePtr sideLCt, sideRCt;
1983 vector<UVPtStruct> pointsLCt( nl ), pointsRCt( nl );
1984 pointsLCt[0] = pTBL;
1985 pointsLCt.back() = uv_et[ lw ];
1986 pointsRCt[0] = pTBR;
1987 pointsRCt.back() = uv_et[ lw + nb - 1 ];
1989 p0 = quad->side[0].Value2d( x );
1990 p2 = uv_et[ lw ].UV();
1991 int iR = lw + nb - 1;
1993 gp_UV p0R = quad->side[0].Value2d( xR );
1994 gp_UV p2R = uv_et[ iR ].UV();
1995 for ( int i = 1; i < nl-1; ++i )
1997 y = yCbL + ( 1. - yCbL ) * i / (nl-1.);
1998 p1 = quad->side[1].Value2d( y );
1999 p3 = quad->side[3].Value2d( y );
2000 uv = calcUV( x,y, a0,a1,a2,a3, p0,p1,p2,p3 );
2001 pointsLCt[ i ].u = uv.X();
2002 pointsLCt[ i ].v = uv.Y();
2004 y = yCbR + ( 1. - yCbR ) * i / (nl-1.);
2005 p1 = quad->side[1].Value2d( y );
2006 p3 = quad->side[3].Value2d( y );
2007 uv = calcUV( xR,y, a0,a1,a2,a3, p0R,p1,p2R,p3 );
2008 pointsRCt[ i ].u = uv.X();
2009 pointsRCt[ i ].v = uv.Y();
2011 sideLCt = StdMeshers_FaceSide::New( pointsLCt, aFace );
2012 sideRCt = StdMeshers_FaceSide::New( pointsRCt, aFace );
2014 // Make a side separating domains Cb and Ct
2015 StdMeshers_FaceSidePtr sideCbCt;
2017 vector<UVPtStruct> pointsCbCt( nb );
2018 pointsCbCt[0] = pTBL;
2019 pointsCbCt.back() = pTBR;
2020 p1 = quad->side[1].Value2d( yCbR );
2021 p3 = quad->side[3].Value2d( yCbL );
2022 for ( int i = 1; i < nb-1; ++i )
2024 x = quad->side[2].Param( i + lw );
2025 y = yCbL + ( yCbR - yCbL ) * i / (nb-1.);
2026 p2 = uv_et[ i + lw ].UV();
2027 p0 = quad->side[0].Value2d( x );
2028 uv = calcUV( x,y, a0,a1,a2,a3, p0,p1,p2,p3 );
2029 pointsCbCt[ i ].u = uv.X();
2030 pointsCbCt[ i ].v = uv.Y();
2032 sideCbCt = StdMeshers_FaceSide::New( pointsCbCt, aFace );
2035 FaceQuadStruct* qCb = new FaceQuadStruct( quad->face, "Cb" );
2036 myQuadList.push_back( FaceQuadStruct::Ptr( qCb ));
2037 qCb->side.resize(4);
2038 qCb->side[0] = quad->side[0];
2039 qCb->side[1] = sideRCb;
2040 qCb->side[2] = sideCbCt;
2041 qCb->side[3] = sideLCb;
2043 FaceQuadStruct* qL = new FaceQuadStruct( quad->face, "L" );
2044 myQuadList.push_back( FaceQuadStruct::Ptr( qL ));
2046 qL->side[0] = sideLCb;
2047 qL->side[1] = sideLCt;
2048 qL->side[2] = quad->side[2];
2049 qL->side[3] = quad->side[3];
2050 qL->side[2].to = ( lw + 1 ) * dt + tfrom;
2052 FaceQuadStruct* qR = new FaceQuadStruct( quad->face, "R" );
2053 myQuadList.push_back( FaceQuadStruct::Ptr( qR ));
2055 qR->side[0] = sideRCb;
2056 qR->side[0].from = lw;
2057 qR->side[0].to = -1;
2058 qR->side[0].di = -1;
2059 qR->side[1] = quad->side[1];
2060 qR->side[2] = quad->side[2];
2061 qR->side[2].from = ( lw + nb-1 ) * dt + tfrom;
2062 qR->side[3] = sideRCt;
2063 // Make Ct from the main quad
2064 FaceQuadStruct::Ptr qCt = quad;
2065 qCt->side[0] = sideCbCt;
2066 qCt->side[1] = sideRCt;
2067 qCt->side[2].from = ( lw ) * dt + tfrom;
2068 qCt->side[2].to = ( lw + nb ) * dt + tfrom;
2069 qCt->side[3] = sideLCt;
2070 qCt->uv_grid.clear();
2074 qCb->side[3].AddContact( lw, & qCb->side[2], 0 );
2075 qCb->side[3].AddContact( lw, & qCt->side[3], 0 );
2076 qCt->side[3].AddContact( 0, & qCt->side[0], 0 );
2077 qCt->side[0].AddContact( 0, & qL ->side[0], lw );
2078 qL ->side[0].AddContact( lw, & qL ->side[1], 0 );
2079 qL ->side[0].AddContact( lw, & qCb->side[2], 0 );
2081 qCb->side[1].AddContact( lw, & qCb->side[2], nb-1 );
2082 qCb->side[1].AddContact( lw, & qCt->side[1], 0 );
2083 qCt->side[0].AddContact( nb-1, & qCt->side[1], 0 );
2084 qCt->side[0].AddContact( nb-1, & qR ->side[0], lw );
2085 qR ->side[3].AddContact( 0, & qR ->side[0], lw );
2086 qR ->side[3].AddContact( 0, & qCb->side[2], nb-1 );
2088 return computeQuadDominant( aMesh, aFace );
2090 } // if ( !myForcedPnts.empty() )
2101 // arrays for normalized params
2102 TColStd_SequenceOfReal npb, npr, npt, npl;
2103 for (i=0; i<nb; i++) {
2104 npb.Append(uv_eb[i].normParam);
2106 for (i=0; i<nr; i++) {
2107 npr.Append(uv_er[i].normParam);
2109 for (i=0; i<nt; i++) {
2110 npt.Append(uv_et[i].normParam);
2112 for (i=0; i<nl; i++) {
2113 npl.Append(uv_el[i].normParam);
2118 // add some params to right and left after the first param
2121 double dpr = (npr.Value(2) - npr.Value(1))/(dr+1);
2122 for (i=1; i<=dr; i++) {
2123 npr.InsertAfter(1,npr.Value(2)-dpr);
2127 dpr = (npl.Value(2) - npl.Value(1))/(dl+1);
2128 for (i=1; i<=dl; i++) {
2129 npl.InsertAfter(1,npl.Value(2)-dpr);
2133 int nnn = Min(nr,nl);
2134 // auxilary sequence of XY for creation nodes
2135 // in the bottom part of central domain
2136 // Length of UVL and UVR must be == nbv-nnn
2137 TColgp_SequenceOfXY UVL, UVR, UVT;
2140 // step1: create faces for left domain
2141 StdMeshers_Array2OfNode NodesL(1,dl+1,1,nl);
2143 for (j=1; j<=nl; j++)
2144 NodesL.SetValue(1,j,uv_el[j-1].node);
2147 for (i=1; i<=dl; i++)
2148 NodesL.SetValue(i+1,nl,uv_et[i].node);
2149 // create and add needed nodes
2150 TColgp_SequenceOfXY UVtmp;
2151 for (i=1; i<=dl; i++) {
2152 double x0 = npt.Value(i+1);
2155 double y0 = npl.Value(i+1);
2156 double y1 = npr.Value(i+1);
2157 gp_UV UV = calcUV(x0, x1, y0, y1, quad, a0, a1, a2, a3);
2158 gp_Pnt P = S->Value(UV.X(),UV.Y());
2159 SMDS_MeshNode * N = meshDS->AddNode(P.X(), P.Y(), P.Z());
2160 meshDS->SetNodeOnFace(N, geomFaceID, UV.X(), UV.Y());
2161 NodesL.SetValue(i+1,1,N);
2162 if (UVL.Length()<nbv-nnn) UVL.Append(UV);
2164 for (j=2; j<nl; j++) {
2165 double y0 = npl.Value(dl+j);
2166 double y1 = npr.Value(dl+j);
2167 gp_UV UV = calcUV(x0, x1, y0, y1, quad, a0, a1, a2, a3);
2168 gp_Pnt P = S->Value(UV.X(),UV.Y());
2169 SMDS_MeshNode* N = meshDS->AddNode(P.X(), P.Y(), P.Z());
2170 meshDS->SetNodeOnFace(N, geomFaceID, UV.X(), UV.Y());
2171 NodesL.SetValue(i+1,j,N);
2172 if (i==dl) UVtmp.Append(UV);
2175 for (i=1; i<=UVtmp.Length() && UVL.Length()<nbv-nnn; i++) {
2176 UVL.Append(UVtmp.Value(i));
2179 for (i=1; i<=dl; i++) {
2180 for (j=1; j<nl; j++) {
2183 myHelper->AddFace(NodesL.Value(i,j), NodesL.Value(i+1,j),
2184 NodesL.Value(i+1,j+1), NodesL.Value(i,j+1));
2185 if (F) meshDS->SetMeshElementOnShape(F, geomFaceID);
2191 // fill UVL using c2d
2192 for (i=1; i<npl.Length() && UVL.Length()<nbv-nnn; i++) {
2193 UVL.Append(gp_UV (uv_el[i].u, uv_el[i].v));
2197 // step2: create faces for right domain
2198 StdMeshers_Array2OfNode NodesR(1,dr+1,1,nr);
2200 for (j=1; j<=nr; j++)
2201 NodesR.SetValue(1,j,uv_er[nr-j].node);
2204 for (i=1; i<=dr; i++)
2205 NodesR.SetValue(i+1,1,uv_et[nt-1-i].node);
2206 // create and add needed nodes
2207 TColgp_SequenceOfXY UVtmp;
2208 for (i=1; i<=dr; i++) {
2209 double x0 = npt.Value(nt-i);
2212 double y0 = npl.Value(i+1);
2213 double y1 = npr.Value(i+1);
2214 gp_UV UV = calcUV(x0, x1, y0, y1, quad, a0, a1, a2, a3);
2215 gp_Pnt P = S->Value(UV.X(),UV.Y());
2216 SMDS_MeshNode * N = meshDS->AddNode(P.X(), P.Y(), P.Z());
2217 meshDS->SetNodeOnFace(N, geomFaceID, UV.X(), UV.Y());
2218 NodesR.SetValue(i+1,nr,N);
2219 if (UVR.Length()<nbv-nnn) UVR.Append(UV);
2221 for (j=2; j<nr; j++) {
2222 double y0 = npl.Value(nbv-j+1);
2223 double y1 = npr.Value(nbv-j+1);
2224 gp_UV UV = calcUV(x0, x1, y0, y1, quad, a0, a1, a2, a3);
2225 gp_Pnt P = S->Value(UV.X(),UV.Y());
2226 SMDS_MeshNode* N = meshDS->AddNode(P.X(), P.Y(), P.Z());
2227 meshDS->SetNodeOnFace(N, geomFaceID, UV.X(), UV.Y());
2228 NodesR.SetValue(i+1,j,N);
2229 if (i==dr) UVtmp.Prepend(UV);
2232 for (i=1; i<=UVtmp.Length() && UVR.Length()<nbv-nnn; i++) {
2233 UVR.Append(UVtmp.Value(i));
2236 for (i=1; i<=dr; i++) {
2237 for (j=1; j<nr; j++) {
2240 myHelper->AddFace(NodesR.Value(i,j), NodesR.Value(i+1,j),
2241 NodesR.Value(i+1,j+1), NodesR.Value(i,j+1));
2242 if (F) meshDS->SetMeshElementOnShape(F, geomFaceID);
2248 // fill UVR using c2d
2249 for (i=1; i<npr.Length() && UVR.Length()<nbv-nnn; i++) {
2250 UVR.Append(gp_UV(uv_er[i].u, uv_er[i].v));
2254 // step3: create faces for central domain
2255 StdMeshers_Array2OfNode NodesC(1,nb,1,nbv);
2256 // add first line using NodesL
2257 for (i=1; i<=dl+1; i++)
2258 NodesC.SetValue(1,i,NodesL(i,1));
2259 for (i=2; i<=nl; i++)
2260 NodesC.SetValue(1,dl+i,NodesL(dl+1,i));
2261 // add last line using NodesR
2262 for (i=1; i<=dr+1; i++)
2263 NodesC.SetValue(nb,i,NodesR(i,nr));
2264 for (i=1; i<nr; i++)
2265 NodesC.SetValue(nb,dr+i+1,NodesR(dr+1,nr-i));
2266 // add top nodes (last columns)
2267 for (i=dl+2; i<nbh-dr; i++)
2268 NodesC.SetValue(i-dl,nbv,uv_et[i-1].node);
2269 // add bottom nodes (first columns)
2270 for (i=2; i<nb; i++)
2271 NodesC.SetValue(i,1,uv_eb[i-1].node);
2273 // create and add needed nodes
2274 // add linear layers
2275 for (i=2; i<nb; i++) {
2276 double x0 = npt.Value(dl+i);
2278 for (j=1; j<nnn; j++) {
2279 double y0 = npl.Value(nbv-nnn+j);
2280 double y1 = npr.Value(nbv-nnn+j);
2281 gp_UV UV = calcUV(x0, x1, y0, y1, quad, a0, a1, a2, a3);
2282 gp_Pnt P = S->Value(UV.X(),UV.Y());
2283 SMDS_MeshNode* N = meshDS->AddNode(P.X(), P.Y(), P.Z());
2284 meshDS->SetNodeOnFace(N, geomFaceID, UV.X(), UV.Y());
2285 NodesC.SetValue(i,nbv-nnn+j,N);
2290 // add diagonal layers
2291 gp_UV A2 = UVR.Value(nbv-nnn);
2292 gp_UV A3 = UVL.Value(nbv-nnn);
2293 for (i=1; i<nbv-nnn; i++) {
2294 gp_UV p1 = UVR.Value(i);
2295 gp_UV p3 = UVL.Value(i);
2296 double y = i / double(nbv-nnn);
2297 for (j=2; j<nb; j++) {
2298 double x = npb.Value(j);
2299 gp_UV p0( uv_eb[j-1].u, uv_eb[j-1].v );
2300 gp_UV p2 = UVT.Value( j-1 );
2301 gp_UV UV = calcUV(x, y, a0, a1, A2, A3, p0,p1,p2,p3 );
2302 gp_Pnt P = S->Value(UV.X(),UV.Y());
2303 SMDS_MeshNode* N = meshDS->AddNode(P.X(), P.Y(), P.Z());
2304 meshDS->SetNodeOnFace(N, geomFaceID, UV.X(),UV.Y());
2305 NodesC.SetValue(j,i+1,N);
2309 for (i=1; i<nb; i++) {
2310 for (j=1; j<nbv; j++) {
2313 myHelper->AddFace(NodesC.Value(i,j), NodesC.Value(i+1,j),
2314 NodesC.Value(i+1,j+1), NodesC.Value(i,j+1));
2315 if (F) meshDS->SetMeshElementOnShape(F, geomFaceID);
2321 else { // New version (!OldVersion)
2322 // step1: create faces for bottom rectangle domain
2323 StdMeshers_Array2OfNode NodesBRD(1,nb,1,nnn-1);
2324 // fill UVL and UVR using c2d
2325 for (j=0; j<nb; j++) {
2326 NodesBRD.SetValue(j+1,1,uv_eb[j].node);
2328 for (i=1; i<nnn-1; i++) {
2329 NodesBRD.SetValue(1,i+1,uv_el[i].node);
2330 NodesBRD.SetValue(nb,i+1,uv_er[i].node);
2331 for (j=2; j<nb; j++) {
2332 double x = npb.Value(j);
2333 double y = (1-x) * npl.Value(i+1) + x * npr.Value(i+1);
2334 gp_UV UV = calcUV2(x, y, quad, a0, a1, a2, a3);
2335 gp_Pnt P = S->Value(UV.X(),UV.Y());
2336 SMDS_MeshNode* N = meshDS->AddNode(P.X(), P.Y(), P.Z());
2337 meshDS->SetNodeOnFace(N, geomFaceID, UV.X(),UV.Y());
2338 NodesBRD.SetValue(j,i+1,N);
2341 for (j=1; j<nnn-1; j++) {
2342 for (i=1; i<nb; i++) {
2345 myHelper->AddFace(NodesBRD.Value(i,j), NodesBRD.Value(i+1,j),
2346 NodesBRD.Value(i+1,j+1), NodesBRD.Value(i,j+1));
2347 if (F) meshDS->SetMeshElementOnShape(F, geomFaceID);
2351 int drl = abs(nr-nl);
2352 // create faces for region C
2353 StdMeshers_Array2OfNode NodesC(1,nb,1,drl+1+addv);
2354 // add nodes from previous region
2355 for (j=1; j<=nb; j++) {
2356 NodesC.SetValue(j,1,NodesBRD.Value(j,nnn-1));
2358 if ((drl+addv) > 0) {
2363 TColgp_SequenceOfXY UVtmp;
2364 double drparam = npr.Value(nr) - npr.Value(nnn-1);
2365 double dlparam = npl.Value(nnn) - npl.Value(nnn-1);
2367 for (i=1; i<=drl; i++) {
2368 // add existed nodes from right edge
2369 NodesC.SetValue(nb,i+1,uv_er[nnn+i-2].node);
2370 //double dtparam = npt.Value(i+1);
2371 y1 = npr.Value(nnn+i-1); // param on right edge
2372 double dpar = (y1 - npr.Value(nnn-1))/drparam;
2373 y0 = npl.Value(nnn-1) + dpar*dlparam; // param on left edge
2374 double dy = y1 - y0;
2375 for (j=1; j<nb; j++) {
2376 double x = npt.Value(i+1) + npb.Value(j)*(1-npt.Value(i+1));
2377 double y = y0 + dy*x;
2378 gp_UV UV = calcUV2(x, y, quad, a0, a1, a2, a3);
2379 gp_Pnt P = S->Value(UV.X(),UV.Y());
2380 SMDS_MeshNode* N = meshDS->AddNode(P.X(), P.Y(), P.Z());
2381 meshDS->SetNodeOnFace(N, geomFaceID, UV.X(), UV.Y());
2382 NodesC.SetValue(j,i+1,N);
2385 double dy0 = (1-y0)/(addv+1);
2386 double dy1 = (1-y1)/(addv+1);
2387 for (i=1; i<=addv; i++) {
2388 double yy0 = y0 + dy0*i;
2389 double yy1 = y1 + dy1*i;
2390 double dyy = yy1 - yy0;
2391 for (j=1; j<=nb; j++) {
2392 double x = npt.Value(i+1+drl) +
2393 npb.Value(j) * (npt.Value(nt-i) - npt.Value(i+1+drl));
2394 double y = yy0 + dyy*x;
2395 gp_UV UV = calcUV2(x, y, quad, a0, a1, a2, a3);
2396 gp_Pnt P = S->Value(UV.X(),UV.Y());
2397 SMDS_MeshNode* N = meshDS->AddNode(P.X(), P.Y(), P.Z());
2398 meshDS->SetNodeOnFace(N, geomFaceID, UV.X(), UV.Y());
2399 NodesC.SetValue(j,i+drl+1,N);
2406 TColgp_SequenceOfXY UVtmp;
2407 double dlparam = npl.Value(nl) - npl.Value(nnn-1);
2408 double drparam = npr.Value(nnn) - npr.Value(nnn-1);
2409 double y0 = npl.Value(nnn-1);
2410 double y1 = npr.Value(nnn-1);
2411 for (i=1; i<=drl; i++) {
2412 // add existed nodes from right edge
2413 NodesC.SetValue(1,i+1,uv_el[nnn+i-2].node);
2414 y0 = npl.Value(nnn+i-1); // param on left edge
2415 double dpar = (y0 - npl.Value(nnn-1))/dlparam;
2416 y1 = npr.Value(nnn-1) + dpar*drparam; // param on right edge
2417 double dy = y1 - y0;
2418 for (j=2; j<=nb; j++) {
2419 double x = npb.Value(j)*npt.Value(nt-i);
2420 double y = y0 + dy*x;
2421 gp_UV UV = calcUV2(x, y, quad, a0, a1, a2, a3);
2422 gp_Pnt P = S->Value(UV.X(),UV.Y());
2423 SMDS_MeshNode* N = meshDS->AddNode(P.X(), P.Y(), P.Z());
2424 meshDS->SetNodeOnFace(N, geomFaceID, UV.X(), UV.Y());
2425 NodesC.SetValue(j,i+1,N);
2428 double dy0 = (1-y0)/(addv+1);
2429 double dy1 = (1-y1)/(addv+1);
2430 for (i=1; i<=addv; i++) {
2431 double yy0 = y0 + dy0*i;
2432 double yy1 = y1 + dy1*i;
2433 double dyy = yy1 - yy0;
2434 for (j=1; j<=nb; j++) {
2435 double x = npt.Value(i+1) +
2436 npb.Value(j) * (npt.Value(nt-i-drl) - npt.Value(i+1));
2437 double y = yy0 + dyy*x;
2438 gp_UV UV = calcUV2(x, y, quad, a0, a1, a2, a3);
2439 gp_Pnt P = S->Value(UV.X(),UV.Y());
2440 SMDS_MeshNode* N = meshDS->AddNode(P.X(), P.Y(), P.Z());
2441 meshDS->SetNodeOnFace(N, geomFaceID, UV.X(), UV.Y());
2442 NodesC.SetValue(j,i+drl+1,N);
2447 for (j=1; j<=drl+addv; j++) {
2448 for (i=1; i<nb; i++) {
2451 myHelper->AddFace(NodesC.Value(i,j), NodesC.Value(i+1,j),
2452 NodesC.Value(i+1,j+1), NodesC.Value(i,j+1));
2453 if (F) meshDS->SetMeshElementOnShape(F, geomFaceID);
2458 StdMeshers_Array2OfNode NodesLast(1,nt,1,2);
2459 for (i=1; i<=nt; i++) {
2460 NodesLast.SetValue(i,2,uv_et[i-1].node);
2463 for (i=n1; i<drl+addv+1; i++) {
2465 NodesLast.SetValue(nnn,1,NodesC.Value(1,i));
2467 for (i=1; i<=nb; i++) {
2469 NodesLast.SetValue(nnn,1,NodesC.Value(i,drl+addv+1));
2471 for (i=drl+addv; i>=n2; i--) {
2473 NodesLast.SetValue(nnn,1,NodesC.Value(nb,i));
2475 for (i=1; i<nt; i++) {
2478 myHelper->AddFace(NodesLast.Value(i,1), NodesLast.Value(i+1,1),
2479 NodesLast.Value(i+1,2), NodesLast.Value(i,2));
2480 if (F) meshDS->SetMeshElementOnShape(F, geomFaceID);
2483 } // if ((drl+addv) > 0)
2485 } // end new version implementation
2492 //=======================================================================
2494 * Evaluate only quandrangle faces
2496 //=======================================================================
2498 bool StdMeshers_Quadrangle_2D::evaluateQuadPref(SMESH_Mesh & aMesh,
2499 const TopoDS_Shape& aShape,
2500 std::vector<int>& aNbNodes,
2501 MapShapeNbElems& aResMap,
2504 // Auxilary key in order to keep old variant
2505 // of meshing after implementation new variant
2506 // for bug 0016220 from Mantis.
2507 bool OldVersion = false;
2508 if (myQuadType == QUAD_QUADRANGLE_PREF_REVERSED)
2511 const TopoDS_Face& F = TopoDS::Face(aShape);
2512 Handle(Geom_Surface) S = BRep_Tool::Surface(F);
2514 int nb = aNbNodes[0];
2515 int nr = aNbNodes[1];
2516 int nt = aNbNodes[2];
2517 int nl = aNbNodes[3];
2518 int dh = abs(nb-nt);
2519 int dv = abs(nr-nl);
2523 // it is a base case => not shift
2526 // we have to shift on 2
2535 // we have to shift quad on 1
2542 // we have to shift quad on 3
2552 int nbh = Max(nb,nt);
2553 int nbv = Max(nr,nl);
2568 // add some params to right and left after the first param
2575 int nnn = Min(nr,nl);
2580 // step1: create faces for left domain
2582 nbNodes += dl*(nl-1);
2583 nbFaces += dl*(nl-1);
2585 // step2: create faces for right domain
2587 nbNodes += dr*(nr-1);
2588 nbFaces += dr*(nr-1);
2590 // step3: create faces for central domain
2591 nbNodes += (nb-2)*(nnn-1) + (nbv-nnn-1)*(nb-2);
2592 nbFaces += (nb-1)*(nbv-1);
2594 else { // New version (!OldVersion)
2595 nbNodes += (nnn-2)*(nb-2);
2596 nbFaces += (nnn-2)*(nb-1);
2597 int drl = abs(nr-nl);
2598 nbNodes += drl*(nb-1) + addv*nb;
2599 nbFaces += (drl+addv)*(nb-1) + (nt-1);
2600 } // end new version implementation
2602 std::vector<int> aVec(SMDSEntity_Last);
2603 for (int i=SMDSEntity_Node; i<SMDSEntity_Last; i++) aVec[i] = 0;
2605 aVec[SMDSEntity_Quad_Quadrangle] = nbFaces;
2606 aVec[SMDSEntity_Node] = nbNodes + nbFaces*4;
2607 if (aNbNodes.size()==5) {
2608 aVec[SMDSEntity_Quad_Triangle] = aNbNodes[3] - 1;
2609 aVec[SMDSEntity_Quad_Quadrangle] = nbFaces - aNbNodes[3] + 1;
2613 aVec[SMDSEntity_Node] = nbNodes;
2614 aVec[SMDSEntity_Quadrangle] = nbFaces;
2615 if (aNbNodes.size()==5) {
2616 aVec[SMDSEntity_Triangle] = aNbNodes[3] - 1;
2617 aVec[SMDSEntity_Quadrangle] = nbFaces - aNbNodes[3] + 1;
2620 SMESH_subMesh * sm = aMesh.GetSubMesh(aShape);
2621 aResMap.insert(std::make_pair(sm,aVec));
2626 //=============================================================================
2627 /*! Split quadrangle in to 2 triangles by smallest diagonal
2630 //=============================================================================
2632 void StdMeshers_Quadrangle_2D::splitQuadFace(SMESHDS_Mesh * theMeshDS,
2634 const SMDS_MeshNode* theNode1,
2635 const SMDS_MeshNode* theNode2,
2636 const SMDS_MeshNode* theNode3,
2637 const SMDS_MeshNode* theNode4)
2639 SMDS_MeshFace* face;
2640 if ( SMESH_TNodeXYZ( theNode1 ).SquareDistance( theNode3 ) >
2641 SMESH_TNodeXYZ( theNode2 ).SquareDistance( theNode4 ) )
2643 face = myHelper->AddFace(theNode2, theNode4 , theNode1);
2644 if (face) theMeshDS->SetMeshElementOnShape(face, theFaceID);
2645 face = myHelper->AddFace(theNode2, theNode3, theNode4);
2646 if (face) theMeshDS->SetMeshElementOnShape(face, theFaceID);
2650 face = myHelper->AddFace(theNode1, theNode2 ,theNode3);
2651 if (face) theMeshDS->SetMeshElementOnShape(face, theFaceID);
2652 face = myHelper->AddFace(theNode1, theNode3, theNode4);
2653 if (face) theMeshDS->SetMeshElementOnShape(face, theFaceID);
2659 enum uvPos { UV_A0, UV_A1, UV_A2, UV_A3, UV_B, UV_R, UV_T, UV_L, UV_SIZE };
2661 inline SMDS_MeshNode* makeNode( UVPtStruct & uvPt,
2663 FaceQuadStruct::Ptr& quad,
2665 SMESH_MesherHelper* helper,
2666 Handle(Geom_Surface) S)
2668 const vector<UVPtStruct>& uv_eb = quad->side[QUAD_BOTTOM_SIDE].GetUVPtStruct();
2669 const vector<UVPtStruct>& uv_et = quad->side[QUAD_TOP_SIDE ].GetUVPtStruct();
2670 double rBot = ( uv_eb.size() - 1 ) * uvPt.normParam;
2671 double rTop = ( uv_et.size() - 1 ) * uvPt.normParam;
2672 int iBot = int( rBot );
2673 int iTop = int( rTop );
2674 double xBot = uv_eb[ iBot ].normParam + ( rBot - iBot ) * ( uv_eb[ iBot+1 ].normParam - uv_eb[ iBot ].normParam );
2675 double xTop = uv_et[ iTop ].normParam + ( rTop - iTop ) * ( uv_et[ iTop+1 ].normParam - uv_et[ iTop ].normParam );
2676 double x = xBot + y * ( xTop - xBot );
2678 gp_UV uv = calcUV(/*x,y=*/x, y,
2679 /*a0,...=*/UVs[UV_A0], UVs[UV_A1], UVs[UV_A2], UVs[UV_A3],
2680 /*p0=*/quad->side[QUAD_BOTTOM_SIDE].grid->Value2d( x ).XY(),
2682 /*p2=*/quad->side[QUAD_TOP_SIDE ].grid->Value2d( x ).XY(),
2683 /*p3=*/UVs[ UV_L ]);
2684 gp_Pnt P = S->Value( uv.X(), uv.Y() );
2687 return helper->AddNode(P.X(), P.Y(), P.Z(), 0, uv.X(), uv.Y() );
2690 void reduce42( 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)
2700 // add one "HH": nodes a,b,c,d,e and faces 1,2,3,4,5,6
2702 // .-----a-----b i + 1
2713 const SMDS_MeshNode*& Na = next_base[ ++next_base_len ].node;
2715 Na = makeNode( next_base[ next_base_len ], y, quad, UVs, helper, S );
2718 const SMDS_MeshNode*& Nb = next_base[ ++next_base_len ].node;
2720 Nb = makeNode( next_base[ next_base_len ], y, quad, UVs, helper, S );
2723 double u = (curr_base[j + 2].u + next_base[next_base_len - 2].u) / 2.0;
2724 double v = (curr_base[j + 2].v + next_base[next_base_len - 2].v) / 2.0;
2725 gp_Pnt P = S->Value(u,v);
2726 SMDS_MeshNode* Nc = helper->AddNode(P.X(), P.Y(), P.Z(), 0, u, v);
2729 u = (curr_base[j + 2].u + next_base[next_base_len - 1].u) / 2.0;
2730 v = (curr_base[j + 2].v + next_base[next_base_len - 1].v) / 2.0;
2732 SMDS_MeshNode* Nd = helper->AddNode(P.X(), P.Y(), P.Z(), 0, u, v);
2735 u = (curr_base[j + 2].u + next_base[next_base_len].u) / 2.0;
2736 v = (curr_base[j + 2].v + next_base[next_base_len].v) / 2.0;
2738 SMDS_MeshNode* Ne = helper->AddNode(P.X(), P.Y(), P.Z(), 0, u, v);
2741 helper->AddFace(curr_base[j + 0].node,
2742 curr_base[j + 1].node, Nc,
2743 next_base[next_base_len - 2].node);
2745 helper->AddFace(curr_base[j + 1].node,
2746 curr_base[j + 2].node, Nd, Nc);
2748 helper->AddFace(curr_base[j + 2].node,
2749 curr_base[j + 3].node, Ne, Nd);
2751 helper->AddFace(curr_base[j + 3].node,
2752 curr_base[j + 4].node, Nb, Ne);
2754 helper->AddFace(Nc, Nd, Na, next_base[next_base_len - 2].node);
2756 helper->AddFace(Nd, Ne, Nb, Na);
2759 void reduce31( const vector<UVPtStruct>& curr_base,
2760 vector<UVPtStruct>& next_base,
2762 int & next_base_len,
2763 FaceQuadStruct::Ptr& quad,
2766 SMESH_MesherHelper* helper,
2767 Handle(Geom_Surface)& S)
2769 // add one "H": nodes b,c,e and faces 1,2,4,5
2771 // .---------b i + 1
2782 const SMDS_MeshNode*& Nb = next_base[ ++next_base_len ].node;
2784 Nb = makeNode( next_base[ next_base_len ], y, quad, UVs, helper, S );
2787 double u1 = (curr_base[ j ].u + next_base[ next_base_len-1 ].u ) / 2.0;
2788 double u2 = (curr_base[ j+3 ].u + next_base[ next_base_len ].u ) / 2.0;
2789 double u3 = (u2 - u1) / 3.0;
2791 double v1 = (curr_base[ j ].v + next_base[ next_base_len-1 ].v ) / 2.0;
2792 double v2 = (curr_base[ j+3 ].v + next_base[ next_base_len ].v ) / 2.0;
2793 double v3 = (v2 - v1) / 3.0;
2797 gp_Pnt P = S->Value(u,v);
2798 SMDS_MeshNode* Nc = helper->AddNode( P.X(), P.Y(), P.Z(), 0, u, v );
2803 SMDS_MeshNode* Ne = helper->AddNode( P.X(), P.Y(), P.Z(), 0, u, v );
2807 helper->AddFace( curr_base[ j + 0 ].node,
2808 curr_base[ j + 1 ].node,
2810 next_base[ next_base_len - 1 ].node);
2812 helper->AddFace( curr_base[ j + 1 ].node,
2813 curr_base[ j + 2 ].node, Ne, Nc);
2815 helper->AddFace( curr_base[ j + 2 ].node,
2816 curr_base[ j + 3 ].node, Nb, Ne);
2818 helper->AddFace(Nc, Ne, Nb,
2819 next_base[ next_base_len - 1 ].node);
2822 typedef void (* PReduceFunction) ( const vector<UVPtStruct>& curr_base,
2823 vector<UVPtStruct>& next_base,
2825 int & next_base_len,
2826 FaceQuadStruct::Ptr & quad,
2829 SMESH_MesherHelper* helper,
2830 Handle(Geom_Surface)& S);
2834 //=======================================================================
2836 * Implementation of Reduced algorithm (meshing with quadrangles only)
2838 //=======================================================================
2840 bool StdMeshers_Quadrangle_2D::computeReduced (SMESH_Mesh & aMesh,
2841 const TopoDS_Face& aFace,
2842 FaceQuadStruct::Ptr quad)
2844 SMESHDS_Mesh * meshDS = aMesh.GetMeshDS();
2845 Handle(Geom_Surface) S = BRep_Tool::Surface(aFace);
2846 int i,j,geomFaceID = meshDS->ShapeToIndex(aFace);
2848 int nb = quad->side[0].NbPoints(); // bottom
2849 int nr = quad->side[1].NbPoints(); // right
2850 int nt = quad->side[2].NbPoints(); // top
2851 int nl = quad->side[3].NbPoints(); // left
2853 // Simple Reduce 10->8->6->4 (3 steps) Multiple Reduce 10->4 (1 step)
2855 // .-----.-----.-----.-----. .-----.-----.-----.-----.
2856 // | / \ | / \ | | / \ | / \ |
2857 // | / .--.--. \ | | / \ | / \ |
2858 // | / / | \ \ | | / .----.----. \ |
2859 // .---.---.---.---.---.---. | / / \ | / \ \ |
2860 // | / / \ | / \ \ | | / / \ | / \ \ |
2861 // | / / .-.-. \ \ | | / / .---.---. \ \ |
2862 // | / / / | \ \ \ | | / / / \ | / \ \ \ |
2863 // .--.--.--.--.--.--.--.--. | / / / \ | / \ \ \ |
2864 // | / / / \ | / \ \ \ | | / / / .-.-. \ \ \ |
2865 // | / / / .-.-. \ \ \ | | / / / / | \ \ \ \ |
2866 // | / / / / | \ \ \ \ | | / / / / | \ \ \ \ |
2867 // .-.-.-.--.--.--.--.-.-.-. .-.-.-.--.--.--.--.-.-.-.
2869 bool MultipleReduce = false;
2881 else if (nb == nt) {
2882 nr1 = nb; // and == nt
2896 // number of rows and columns
2897 int nrows = nr1 - 1;
2898 int ncol_top = nt1 - 1;
2899 int ncol_bot = nb1 - 1;
2900 // number of rows needed to reduce ncol_bot to ncol_top using simple 3->1 "tree" (see below)
2902 int( ceil( log( double(ncol_bot) / ncol_top) / log( 3.))); // = log x base 3
2903 if ( nrows < nrows_tree31 )
2905 MultipleReduce = true;
2906 error( COMPERR_WARNING,
2907 SMESH_Comment("To use 'Reduced' transition, "
2908 "number of face rows should be at least ")
2909 << nrows_tree31 << ". Actual number of face rows is " << nrows << ". "
2910 "'Quadrangle preference (reversed)' transion has been used.");
2914 if (MultipleReduce) { // == computeQuadPref QUAD_QUADRANGLE_PREF_REVERSED
2915 //==================================================