1 // Copyright (C) 2007-2014 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License, or (at your option) any later version.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 // File : StdMeshers_Quadrangle_2D.cxx
24 // Author : Paul RASCLE, EDF
27 #include "StdMeshers_Quadrangle_2D.hxx"
29 #include "SMDS_EdgePosition.hxx"
30 #include "SMDS_FacePosition.hxx"
31 #include "SMDS_MeshElement.hxx"
32 #include "SMDS_MeshNode.hxx"
33 #include "SMESH_Block.hxx"
34 #include "SMESH_Comment.hxx"
35 #include "SMESH_Gen.hxx"
36 #include "SMESH_HypoFilter.hxx"
37 #include "SMESH_Mesh.hxx"
38 #include "SMESH_MeshAlgos.hxx"
39 #include "SMESH_MesherHelper.hxx"
40 #include "SMESH_subMesh.hxx"
41 #include "StdMeshers_FaceSide.hxx"
42 #include "StdMeshers_QuadrangleParams.hxx"
43 #include "StdMeshers_ViscousLayers2D.hxx"
45 #include <BRepBndLib.hxx>
46 #include <BRepClass_FaceClassifier.hxx>
47 #include <BRep_Tool.hxx>
48 #include <Bnd_Box.hxx>
49 #include <GeomAPI_ProjectPointOnSurf.hxx>
50 #include <Geom_Surface.hxx>
51 #include <NCollection_DefineArray2.hxx>
52 #include <Precision.hxx>
53 #include <Quantity_Parameter.hxx>
54 #include <TColStd_SequenceOfInteger.hxx>
55 #include <TColStd_SequenceOfReal.hxx>
56 #include <TColgp_SequenceOfXY.hxx>
58 #include <TopExp_Explorer.hxx>
59 #include <TopTools_DataMapOfShapeReal.hxx>
60 #include <TopTools_ListIteratorOfListOfShape.hxx>
61 #include <TopTools_MapOfShape.hxx>
64 #include "utilities.h"
65 #include "Utils_ExceptHandlers.hxx"
67 #ifndef StdMeshers_Array2OfNode_HeaderFile
68 #define StdMeshers_Array2OfNode_HeaderFile
69 typedef const SMDS_MeshNode* SMDS_MeshNodePtr;
70 DEFINE_BASECOLLECTION (StdMeshers_BaseCollectionNodePtr, SMDS_MeshNodePtr)
71 DEFINE_ARRAY2(StdMeshers_Array2OfNode,
72 StdMeshers_BaseCollectionNodePtr, SMDS_MeshNodePtr)
78 typedef SMESH_Comment TComm;
80 //=============================================================================
84 //=============================================================================
86 StdMeshers_Quadrangle_2D::StdMeshers_Quadrangle_2D (int hypId, int studyId,
88 : SMESH_2D_Algo(hypId, studyId, gen),
89 myQuadranglePreference(false),
90 myTrianglePreference(false),
95 myQuadType(QUAD_STANDARD),
98 MESSAGE("StdMeshers_Quadrangle_2D::StdMeshers_Quadrangle_2D");
99 _name = "Quadrangle_2D";
100 _shapeType = (1 << TopAbs_FACE);
101 _compatibleHypothesis.push_back("QuadrangleParams");
102 _compatibleHypothesis.push_back("QuadranglePreference");
103 _compatibleHypothesis.push_back("TrianglePreference");
104 _compatibleHypothesis.push_back("ViscousLayers2D");
107 //=============================================================================
111 //=============================================================================
113 StdMeshers_Quadrangle_2D::~StdMeshers_Quadrangle_2D()
115 MESSAGE("StdMeshers_Quadrangle_2D::~StdMeshers_Quadrangle_2D");
118 //=============================================================================
122 //=============================================================================
124 bool StdMeshers_Quadrangle_2D::CheckHypothesis
126 const TopoDS_Shape& aShape,
127 SMESH_Hypothesis::Hypothesis_Status& aStatus)
130 myQuadType = QUAD_STANDARD;
131 myQuadranglePreference = false;
132 myTrianglePreference = false;
133 myHelper = (SMESH_MesherHelper*)NULL;
138 aStatus = SMESH_Hypothesis::HYP_OK;
140 const list <const SMESHDS_Hypothesis * >& hyps =
141 GetUsedHypothesis(aMesh, aShape, false);
142 const SMESHDS_Hypothesis * aHyp = 0;
144 bool isFirstParams = true;
146 // First assigned hypothesis (if any) is processed now
147 if (hyps.size() > 0) {
149 if (strcmp("QuadrangleParams", aHyp->GetName()) == 0)
151 myParams = (const StdMeshers_QuadrangleParams*)aHyp;
152 myTriaVertexID = myParams->GetTriaVertex();
153 myQuadType = myParams->GetQuadType();
154 if (myQuadType == QUAD_QUADRANGLE_PREF ||
155 myQuadType == QUAD_QUADRANGLE_PREF_REVERSED)
156 myQuadranglePreference = true;
157 else if (myQuadType == QUAD_TRIANGLE_PREF)
158 myTrianglePreference = true;
160 else if (strcmp("QuadranglePreference", aHyp->GetName()) == 0) {
161 isFirstParams = false;
162 myQuadranglePreference = true;
164 else if (strcmp("TrianglePreference", aHyp->GetName()) == 0){
165 isFirstParams = false;
166 myTrianglePreference = true;
169 isFirstParams = false;
173 // Second(last) assigned hypothesis (if any) is processed now
174 if (hyps.size() > 1) {
177 if (strcmp("QuadranglePreference", aHyp->GetName()) == 0) {
178 myQuadranglePreference = true;
179 myTrianglePreference = false;
180 myQuadType = QUAD_STANDARD;
182 else if (strcmp("TrianglePreference", aHyp->GetName()) == 0){
183 myQuadranglePreference = false;
184 myTrianglePreference = true;
185 myQuadType = QUAD_STANDARD;
189 const StdMeshers_QuadrangleParams* aHyp2 =
190 (const StdMeshers_QuadrangleParams*)aHyp;
191 myTriaVertexID = aHyp2->GetTriaVertex();
193 if (!myQuadranglePreference && !myTrianglePreference) { // priority of hypos
194 myQuadType = aHyp2->GetQuadType();
195 if (myQuadType == QUAD_QUADRANGLE_PREF ||
196 myQuadType == QUAD_QUADRANGLE_PREF_REVERSED)
197 myQuadranglePreference = true;
198 else if (myQuadType == QUAD_TRIANGLE_PREF)
199 myTrianglePreference = true;
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.");
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
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 );
367 return computeQuadDominant( aMesh, aFace );
370 //================================================================================
372 * \brief Compute quadrangles and possibly triangles on all quads of myQuadList
374 //================================================================================
376 bool StdMeshers_Quadrangle_2D::computeQuadDominant(SMESH_Mesh& aMesh,
377 const TopoDS_Face& aFace)
379 if ( !addEnforcedNodes() )
382 std::list< FaceQuadStruct::Ptr >::iterator quad = myQuadList.begin();
383 for ( ; quad != myQuadList.end(); ++quad )
384 if ( !computeQuadDominant( aMesh, aFace, *quad ))
390 //================================================================================
392 * \brief Compute quadrangles and possibly triangles
394 //================================================================================
396 bool StdMeshers_Quadrangle_2D::computeQuadDominant(SMESH_Mesh& aMesh,
397 const TopoDS_Face& aFace,
398 FaceQuadStruct::Ptr quad)
400 // --- set normalized grid on unit square in parametric domain
402 if ( !setNormalizedGrid( quad ))
405 // --- create nodes on points, and create quadrangles
407 int nbhoriz = quad->iSize;
408 int nbvertic = quad->jSize;
410 // internal mesh nodes
411 SMESHDS_Mesh * meshDS = aMesh.GetMeshDS();
412 Handle(Geom_Surface) S = BRep_Tool::Surface(aFace);
413 int i,j, geomFaceID = meshDS->ShapeToIndex(aFace);
414 for (i = 1; i < nbhoriz - 1; i++)
415 for (j = 1; j < nbvertic - 1; j++)
417 UVPtStruct& uvPnt = quad->UVPt( i, j );
418 gp_Pnt P = S->Value( uvPnt.u, uvPnt.v );
419 uvPnt.node = meshDS->AddNode(P.X(), P.Y(), P.Z());
420 meshDS->SetNodeOnFace( uvPnt.node, geomFaceID, uvPnt.u, uvPnt.v );
426 // --.--.--.--.--.-- nbvertic
432 // ---.----.----.--- 0
433 // 0 > > > > > > > > nbhoriz
438 int iup = nbhoriz - 1;
439 if (quad->nbNodeOut(3)) { ilow++; } else { if (quad->nbNodeOut(1)) iup--; }
442 int jup = nbvertic - 1;
443 if (quad->nbNodeOut(0)) { jlow++; } else { if (quad->nbNodeOut(2)) jup--; }
445 // regular quadrangles
446 for (i = ilow; i < iup; i++) {
447 for (j = jlow; j < jup; j++) {
448 const SMDS_MeshNode *a, *b, *c, *d;
449 a = quad->uv_grid[ j * nbhoriz + i ].node;
450 b = quad->uv_grid[ j * nbhoriz + i + 1].node;
451 c = quad->uv_grid[(j + 1) * nbhoriz + i + 1].node;
452 d = quad->uv_grid[(j + 1) * nbhoriz + i ].node;
453 SMDS_MeshFace* face = myHelper->AddFace(a, b, c, d);
455 meshDS->SetMeshElementOnShape(face, geomFaceID);
460 // Boundary elements (must always be on an outer boundary of the FACE)
462 const vector<UVPtStruct>& uv_e0 = quad->side[0].grid->GetUVPtStruct();
463 const vector<UVPtStruct>& uv_e1 = quad->side[1].grid->GetUVPtStruct();
464 const vector<UVPtStruct>& uv_e2 = quad->side[2].grid->GetUVPtStruct();
465 const vector<UVPtStruct>& uv_e3 = quad->side[3].grid->GetUVPtStruct();
467 if (uv_e0.empty() || uv_e1.empty() || uv_e2.empty() || uv_e3.empty())
468 return error(COMPERR_BAD_INPUT_MESH);
470 double eps = Precision::Confusion();
472 int nbdown = (int) uv_e0.size();
473 int nbup = (int) uv_e2.size();
474 int nbright = (int) uv_e1.size();
475 int nbleft = (int) uv_e3.size();
477 if (quad->nbNodeOut(0) && nbvertic == 2) // this should not occure
481 // |___|___|___|___|___|___|
483 // |___|___|___|___|___|___|
485 // |___|___|___|___|___|___| __ first row of the regular grid
486 // . . . . . . . . . __ down edge nodes
488 // >->->->->->->->->->->->-> -- direction of processing
490 int g = 0; // number of last processed node in the regular grid
492 // number of last node of the down edge to be processed
493 int stop = nbdown - 1;
494 // if right edge is out, we will stop at a node, previous to the last one
495 //if (quad->nbNodeOut(1)) stop--;
496 if ( quad->nbNodeOut( QUAD_RIGHT_SIDE ))
497 quad->UVPt( nbhoriz-1, 1 ).node = uv_e1[1].node;
498 if ( quad->nbNodeOut( QUAD_LEFT_SIDE ))
499 quad->UVPt( 0, 1 ).node = uv_e3[1].node;
501 // for each node of the down edge find nearest node
502 // in the first row of the regular grid and link them
503 for (i = 0; i < stop; i++) {
504 const SMDS_MeshNode *a, *b, *c, *d;
506 b = uv_e0[i + 1].node;
507 gp_Pnt pb (b->X(), b->Y(), b->Z());
509 // find node c in the regular grid, which will be linked with node b
512 // right bound reached, link with the rightmost node
514 c = quad->uv_grid[nbhoriz + iup].node;
517 // find in the grid node c, nearest to the b
518 double mind = RealLast();
519 for (int k = g; k <= iup; k++) {
521 const SMDS_MeshNode *nk;
522 if (k < ilow) // this can be, if left edge is out
523 nk = uv_e3[1].node; // get node from the left edge
525 nk = quad->uv_grid[nbhoriz + k].node; // get one of middle nodes
527 gp_Pnt pnk (nk->X(), nk->Y(), nk->Z());
528 double dist = pb.Distance(pnk);
529 if (dist < mind - eps) {
539 if (near == g) { // make triangle
540 SMDS_MeshFace* face = myHelper->AddFace(a, b, c);
541 if (face) meshDS->SetMeshElementOnShape(face, geomFaceID);
543 else { // make quadrangle
547 d = quad->uv_grid[nbhoriz + near - 1].node;
548 //SMDS_MeshFace* face = meshDS->AddFace(a, b, c, d);
550 if (!myTrianglePreference){
551 SMDS_MeshFace* face = myHelper->AddFace(a, b, c, d);
552 if (face) meshDS->SetMeshElementOnShape(face, geomFaceID);
555 splitQuadFace(meshDS, geomFaceID, a, b, c, d);
558 // if node d is not at position g - make additional triangles
560 for (int k = near - 1; k > g; k--) {
561 c = quad->uv_grid[nbhoriz + k].node;
565 d = quad->uv_grid[nbhoriz + k - 1].node;
566 SMDS_MeshFace* face = myHelper->AddFace(a, c, d);
567 if (face) meshDS->SetMeshElementOnShape(face, geomFaceID);
574 if (quad->nbNodeOut(2) && nbvertic == 2)
578 // <-<-<-<-<-<-<-<-<-<-<-<-< -- direction of processing
580 // . . . . . . . . . __ up edge nodes
581 // ___ ___ ___ ___ ___ ___ __ first row of the regular grid
583 // |___|___|___|___|___|___|
585 // |___|___|___|___|___|___|
588 int g = nbhoriz - 1; // last processed node in the regular grid
594 // if left edge is out, we will stop at a second node
595 //if (quad->nbNodeOut(3)) stop++;
596 if ( quad->nbNodeOut( QUAD_RIGHT_SIDE ))
597 quad->UVPt( nbhoriz-1, 0 ).node = uv_e1[ nbright-2 ].node;
598 if ( quad->nbNodeOut( QUAD_LEFT_SIDE ))
599 quad->UVPt( 0, 0 ).node = uv_e3[ nbleft-2 ].node;
601 // for each node of the up edge find nearest node
602 // in the first row of the regular grid and link them
603 for (i = nbup - 1; i > stop; i--) {
604 const SMDS_MeshNode *a, *b, *c, *d;
606 b = uv_e2[i - 1].node;
607 gp_Pnt pb (b->X(), b->Y(), b->Z());
609 // find node c in the grid, which will be linked with node b
611 if (i == stop + 1) { // left bound reached, link with the leftmost node
612 c = quad->uv_grid[nbhoriz*(nbvertic - 2) + ilow].node;
615 // find node c in the grid, nearest to the b
616 double mind = RealLast();
617 for (int k = g; k >= ilow; k--) {
618 const SMDS_MeshNode *nk;
620 nk = uv_e1[nbright - 2].node;
622 nk = quad->uv_grid[nbhoriz*(nbvertic - 2) + k].node;
623 gp_Pnt pnk (nk->X(), nk->Y(), nk->Z());
624 double dist = pb.Distance(pnk);
625 if (dist < mind - eps) {
635 if (near == g) { // make triangle
636 SMDS_MeshFace* face = myHelper->AddFace(a, b, c);
637 if (face) meshDS->SetMeshElementOnShape(face, geomFaceID);
639 else { // make quadrangle
641 d = uv_e1[nbright - 2].node;
643 d = quad->uv_grid[nbhoriz*(nbvertic - 2) + near + 1].node;
644 //SMDS_MeshFace* face = meshDS->AddFace(a, b, c, d);
645 if (!myTrianglePreference){
646 SMDS_MeshFace* face = myHelper->AddFace(a, b, c, d);
647 if (face) meshDS->SetMeshElementOnShape(face, geomFaceID);
650 splitQuadFace(meshDS, geomFaceID, a, b, c, d);
653 if (near + 1 < g) { // if d is not at g - make additional triangles
654 for (int k = near + 1; k < g; k++) {
655 c = quad->uv_grid[nbhoriz*(nbvertic - 2) + k].node;
657 d = uv_e1[nbright - 2].node;
659 d = quad->uv_grid[nbhoriz*(nbvertic - 2) + k + 1].node;
660 SMDS_MeshFace* face = myHelper->AddFace(a, c, d);
661 if (face) meshDS->SetMeshElementOnShape(face, geomFaceID);
670 // right or left boundary quadrangles
671 if (quad->nbNodeOut( QUAD_RIGHT_SIDE ) && nbhoriz == 2) // this should not occure
673 int g = 0; // last processed node in the grid
674 int stop = nbright - 1;
676 if (quad->side[ QUAD_RIGHT_SIDE ].from != i ) i++;
677 if (quad->side[ QUAD_RIGHT_SIDE ].to != stop ) stop--;
678 for ( ; i < stop; i++) {
679 const SMDS_MeshNode *a, *b, *c, *d;
681 b = uv_e1[i + 1].node;
682 gp_Pnt pb (b->X(), b->Y(), b->Z());
684 // find node c in the grid, nearest to the b
686 if (i == stop - 1) { // up bondary reached
687 c = quad->uv_grid[nbhoriz*(jup + 1) - 2].node;
690 double mind = RealLast();
691 for (int k = g; k <= jup; k++) {
692 const SMDS_MeshNode *nk;
694 nk = uv_e0[nbdown - 2].node;
696 nk = quad->uv_grid[nbhoriz*(k + 1) - 2].node;
697 gp_Pnt pnk (nk->X(), nk->Y(), nk->Z());
698 double dist = pb.Distance(pnk);
699 if (dist < mind - eps) {
709 if (near == g) { // make triangle
710 SMDS_MeshFace* face = myHelper->AddFace(a, b, c);
711 if (face) meshDS->SetMeshElementOnShape(face, geomFaceID);
713 else { // make quadrangle
715 d = uv_e0[nbdown - 2].node;
717 d = quad->uv_grid[nbhoriz*near - 2].node;
718 //SMDS_MeshFace* face = meshDS->AddFace(a, b, c, d);
720 if (!myTrianglePreference){
721 SMDS_MeshFace* face = myHelper->AddFace(a, b, c, d);
722 if (face) meshDS->SetMeshElementOnShape(face, geomFaceID);
725 splitQuadFace(meshDS, geomFaceID, a, b, c, d);
728 if (near - 1 > g) { // if d not is at g - make additional triangles
729 for (int k = near - 1; k > g; k--) {
730 c = quad->uv_grid[nbhoriz*(k + 1) - 2].node;
732 d = uv_e0[nbdown - 2].node;
734 d = quad->uv_grid[nbhoriz*k - 2].node;
735 SMDS_MeshFace* face = myHelper->AddFace(a, c, d);
736 if (face) meshDS->SetMeshElementOnShape(face, geomFaceID);
743 if (quad->nbNodeOut(3) && nbhoriz == 2) {
744 // MESSAGE("left edge is out");
745 int g = nbvertic - 1; // last processed node in the grid
747 i = quad->side[ QUAD_LEFT_SIDE ].to-1; // nbleft - 1;
748 for (; i > stop; i--) {
749 const SMDS_MeshNode *a, *b, *c, *d;
751 b = uv_e3[i - 1].node;
752 gp_Pnt pb (b->X(), b->Y(), b->Z());
754 // find node c in the grid, nearest to the b
756 if (i == stop + 1) { // down bondary reached
757 c = quad->uv_grid[nbhoriz*jlow + 1].node;
760 double mind = RealLast();
761 for (int k = g; k >= jlow; k--) {
762 const SMDS_MeshNode *nk;
766 nk = quad->uv_grid[nbhoriz*k + 1].node;
767 gp_Pnt pnk (nk->X(), nk->Y(), nk->Z());
768 double dist = pb.Distance(pnk);
769 if (dist < mind - eps) {
779 if (near == g) { // make triangle
780 SMDS_MeshFace* face = myHelper->AddFace(a, b, c);
781 if (face) meshDS->SetMeshElementOnShape(face, geomFaceID);
783 else { // make quadrangle
787 d = quad->uv_grid[nbhoriz*(near + 1) + 1].node;
788 //SMDS_MeshFace* face = meshDS->AddFace(a, b, c, d);
789 if (!myTrianglePreference){
790 SMDS_MeshFace* face = myHelper->AddFace(a, b, c, d);
791 if (face) meshDS->SetMeshElementOnShape(face, geomFaceID);
794 splitQuadFace(meshDS, geomFaceID, a, b, c, d);
797 if (near + 1 < g) { // if d not is at g - make additional triangles
798 for (int k = near + 1; k < g; k++) {
799 c = quad->uv_grid[nbhoriz*k + 1].node;
803 d = quad->uv_grid[nbhoriz*(k + 1) + 1].node;
804 SMDS_MeshFace* face = myHelper->AddFace(a, c, d);
805 if (face) meshDS->SetMeshElementOnShape(face, geomFaceID);
819 //=============================================================================
823 //=============================================================================
825 bool StdMeshers_Quadrangle_2D::Evaluate(SMESH_Mesh& aMesh,
826 const TopoDS_Shape& aFace,
827 MapShapeNbElems& aResMap)
830 aMesh.GetSubMesh(aFace);
832 std::vector<int> aNbNodes(4);
833 bool IsQuadratic = false;
834 if (!checkNbEdgesForEvaluate(aMesh, aFace, aResMap, aNbNodes, IsQuadratic)) {
835 std::vector<int> aResVec(SMDSEntity_Last);
836 for (int i=SMDSEntity_Node; i<SMDSEntity_Last; i++) aResVec[i] = 0;
837 SMESH_subMesh * sm = aMesh.GetSubMesh(aFace);
838 aResMap.insert(std::make_pair(sm,aResVec));
839 SMESH_ComputeErrorPtr& smError = sm->GetComputeError();
840 smError.reset(new SMESH_ComputeError(COMPERR_ALGO_FAILED,"Submesh can not be evaluated",this));
844 if (myQuadranglePreference) {
845 int n1 = aNbNodes[0];
846 int n2 = aNbNodes[1];
847 int n3 = aNbNodes[2];
848 int n4 = aNbNodes[3];
849 int nfull = n1+n2+n3+n4;
852 if (nfull==ntmp && ((n1!=n3) || (n2!=n4))) {
853 // special path for using only quandrangle faces
854 return evaluateQuadPref(aMesh, aFace, aNbNodes, aResMap, IsQuadratic);
859 int nbdown = aNbNodes[0];
860 int nbup = aNbNodes[2];
862 int nbright = aNbNodes[1];
863 int nbleft = aNbNodes[3];
865 int nbhoriz = Min(nbdown, nbup);
866 int nbvertic = Min(nbright, nbleft);
868 int dh = Max(nbdown, nbup) - nbhoriz;
869 int dv = Max(nbright, nbleft) - nbvertic;
876 int nbNodes = (nbhoriz-2)*(nbvertic-2);
877 //int nbFaces3 = dh + dv + kdh*(nbvertic-1)*2 + kdv*(nbhoriz-1)*2;
878 int nbFaces3 = dh + dv;
879 //if (kdh==1 && kdv==1) nbFaces3 -= 2;
880 //if (dh>0 && dv>0) nbFaces3 -= 2;
881 //int nbFaces4 = (nbhoriz-1-kdh)*(nbvertic-1-kdv);
882 int nbFaces4 = (nbhoriz-1)*(nbvertic-1);
884 std::vector<int> aVec(SMDSEntity_Last);
885 for (int i=SMDSEntity_Node; i<SMDSEntity_Last; i++) aVec[i] = 0;
887 aVec[SMDSEntity_Quad_Triangle] = nbFaces3;
888 aVec[SMDSEntity_Quad_Quadrangle] = nbFaces4;
889 int nbbndedges = nbdown + nbup + nbright + nbleft -4;
890 int nbintedges = (nbFaces4*4 + nbFaces3*3 - nbbndedges) / 2;
891 aVec[SMDSEntity_Node] = nbNodes + nbintedges;
892 if (aNbNodes.size()==5) {
893 aVec[SMDSEntity_Quad_Triangle] = nbFaces3 + aNbNodes[3] -1;
894 aVec[SMDSEntity_Quad_Quadrangle] = nbFaces4 - aNbNodes[3] +1;
898 aVec[SMDSEntity_Node] = nbNodes;
899 aVec[SMDSEntity_Triangle] = nbFaces3;
900 aVec[SMDSEntity_Quadrangle] = nbFaces4;
901 if (aNbNodes.size()==5) {
902 aVec[SMDSEntity_Triangle] = nbFaces3 + aNbNodes[3] - 1;
903 aVec[SMDSEntity_Quadrangle] = nbFaces4 - aNbNodes[3] + 1;
906 SMESH_subMesh * sm = aMesh.GetSubMesh(aFace);
907 aResMap.insert(std::make_pair(sm,aVec));
912 //================================================================================
914 * \brief Return true if the algorithm can mesh this shape
915 * \param [in] aShape - shape to check
916 * \param [in] toCheckAll - if true, this check returns OK if all shapes are OK,
917 * else, returns OK if at least one shape is OK
919 //================================================================================
921 bool StdMeshers_Quadrangle_2D::IsApplicable( const TopoDS_Shape & aShape, bool toCheckAll )
923 int nbFoundFaces = 0;
924 for (TopExp_Explorer exp( aShape, TopAbs_FACE ); exp.More(); exp.Next(), ++nbFoundFaces )
926 const TopoDS_Shape& aFace = exp.Current();
927 int nbWire = SMESH_MesherHelper::Count( aFace, TopAbs_WIRE, false );
929 if ( toCheckAll ) return false;
933 int nbNoDegenEdges = 0;
934 TopExp_Explorer eExp( aFace, TopAbs_EDGE );
935 for ( ; eExp.More() && nbNoDegenEdges < 3; eExp.Next() ) {
936 if ( !SMESH_Algo::isDegenerated( TopoDS::Edge( eExp.Current() )))
939 if ( toCheckAll && nbNoDegenEdges < 3 ) return false;
940 if ( !toCheckAll && nbNoDegenEdges >= 3 ) return true;
942 return ( toCheckAll && nbFoundFaces != 0 );
945 //================================================================================
947 * \brief Return true if only two given edges meat at their common vertex
949 //================================================================================
951 static bool twoEdgesMeatAtVertex(const TopoDS_Edge& e1,
952 const TopoDS_Edge& e2,
956 if (!TopExp::CommonVertex(e1, e2, v))
958 TopTools_ListIteratorOfListOfShape ancestIt(mesh.GetAncestors(v));
959 for (; ancestIt.More() ; ancestIt.Next())
960 if (ancestIt.Value().ShapeType() == TopAbs_EDGE)
961 if (!e1.IsSame(ancestIt.Value()) && !e2.IsSame(ancestIt.Value()))
966 //=============================================================================
970 //=============================================================================
972 FaceQuadStruct::Ptr StdMeshers_Quadrangle_2D::CheckNbEdges(SMESH_Mesh & aMesh,
973 const TopoDS_Shape & aShape,
974 const bool considerMesh)
976 if ( !myQuadList.empty() && myQuadList.front()->face.IsSame( aShape ))
977 return myQuadList.front();
979 TopoDS_Face F = TopoDS::Face(aShape);
980 if ( F.Orientation() >= TopAbs_INTERNAL ) F.Orientation( TopAbs_FORWARD );
981 const bool ignoreMediumNodes = _quadraticMesh;
983 // verify 1 wire only
984 list< TopoDS_Edge > edges;
985 list< int > nbEdgesInWire;
986 int nbWire = SMESH_Block::GetOrderedEdges (F, edges, nbEdgesInWire);
988 error(COMPERR_BAD_SHAPE, TComm("Wrong number of wires: ") << nbWire);
989 return FaceQuadStruct::Ptr();
992 // find corner vertices of the quad
993 vector<TopoDS_Vertex> corners;
994 int nbDegenEdges, nbSides = getCorners( F, aMesh, edges, corners, nbDegenEdges, considerMesh );
997 return FaceQuadStruct::Ptr();
999 FaceQuadStruct::Ptr quad( new FaceQuadStruct );
1000 quad->side.reserve(nbEdgesInWire.front());
1003 list< TopoDS_Edge >::iterator edgeIt = edges.begin();
1004 if ( nbSides == 3 ) // 3 sides and corners[0] is a vertex with myTriaVertexID
1006 for ( int iSide = 0; iSide < 3; ++iSide )
1008 list< TopoDS_Edge > sideEdges;
1009 TopoDS_Vertex nextSideV = corners[( iSide + 1 ) % 3 ];
1010 while ( edgeIt != edges.end() &&
1011 !nextSideV.IsSame( SMESH_MesherHelper::IthVertex( 0, *edgeIt )))
1012 if ( SMESH_Algo::isDegenerated( *edgeIt ))
1015 sideEdges.push_back( *edgeIt++ );
1016 if ( !sideEdges.empty() )
1017 quad->side.push_back( StdMeshers_FaceSide::New(F, sideEdges, &aMesh, iSide < QUAD_TOP_SIDE,
1018 ignoreMediumNodes, myProxyMesh));
1022 const vector<UVPtStruct>& UVPSleft = quad->side[0].GetUVPtStruct(true,0);
1023 /* vector<UVPtStruct>& UVPStop = */quad->side[1].GetUVPtStruct(false,1);
1024 /* vector<UVPtStruct>& UVPSright = */quad->side[2].GetUVPtStruct(true,1);
1025 const SMDS_MeshNode* aNode = UVPSleft[0].node;
1026 gp_Pnt2d aPnt2d = UVPSleft[0].UV();
1027 quad->side.push_back( StdMeshers_FaceSide::New( quad->side[1].grid.get(), aNode, &aPnt2d ));
1028 myNeedSmooth = ( nbDegenEdges > 0 );
1033 myNeedSmooth = ( corners.size() == 4 && nbDegenEdges > 0 );
1034 int iSide = 0, nbUsedDegen = 0, nbLoops = 0;
1035 for ( ; edgeIt != edges.end(); ++nbLoops )
1037 list< TopoDS_Edge > sideEdges;
1038 TopoDS_Vertex nextSideV = corners[( iSide + 1 - nbUsedDegen ) % corners.size() ];
1039 while ( edgeIt != edges.end() &&
1040 !nextSideV.IsSame( myHelper->IthVertex( 0, *edgeIt )))
1042 if ( SMESH_Algo::isDegenerated( *edgeIt ) )
1046 ++edgeIt; // no side on the degenerated EDGE
1050 if ( sideEdges.empty() )
1053 sideEdges.push_back( *edgeIt++ ); // a degenerated side
1058 break; // do not append a degenerated EDGE to a regular side
1064 sideEdges.push_back( *edgeIt++ );
1067 if ( !sideEdges.empty() )
1069 quad->side.push_back( StdMeshers_FaceSide::New( F, sideEdges, &aMesh, iSide < QUAD_TOP_SIDE,
1070 ignoreMediumNodes, myProxyMesh ));
1073 else if ( !SMESH_Algo::isDegenerated( *edgeIt ) && // closed EDGE
1074 myHelper->IthVertex( 0, *edgeIt ).IsSame( myHelper->IthVertex( 1, *edgeIt )))
1076 quad->side.push_back( StdMeshers_FaceSide::New( F, *edgeIt++, &aMesh, iSide < QUAD_TOP_SIDE,
1077 ignoreMediumNodes, myProxyMesh));
1080 if ( quad->side.size() == 4 )
1084 error(TComm("Bug: infinite loop in StdMeshers_Quadrangle_2D::CheckNbEdges()"));
1089 if ( quad && quad->side.size() != 4 )
1091 error(TComm("Bug: ") << quad->side.size() << " sides found instead of 4");
1100 //=============================================================================
1104 //=============================================================================
1106 bool StdMeshers_Quadrangle_2D::checkNbEdgesForEvaluate(SMESH_Mesh& aMesh,
1107 const TopoDS_Shape & aShape,
1108 MapShapeNbElems& aResMap,
1109 std::vector<int>& aNbNodes,
1113 const TopoDS_Face & F = TopoDS::Face(aShape);
1115 // verify 1 wire only, with 4 edges
1116 list< TopoDS_Edge > edges;
1117 list< int > nbEdgesInWire;
1118 int nbWire = SMESH_Block::GetOrderedEdges (F, edges, nbEdgesInWire);
1126 list< TopoDS_Edge >::iterator edgeIt = edges.begin();
1127 SMESH_subMesh * sm = aMesh.GetSubMesh(*edgeIt);
1128 MapShapeNbElemsItr anIt = aResMap.find(sm);
1129 if (anIt==aResMap.end()) {
1132 std::vector<int> aVec = (*anIt).second;
1133 IsQuadratic = (aVec[SMDSEntity_Quad_Edge] > aVec[SMDSEntity_Edge]);
1134 if (nbEdgesInWire.front() == 3) { // exactly 3 edges
1135 if (myTriaVertexID>0) {
1136 SMESHDS_Mesh* meshDS = aMesh.GetMeshDS();
1137 TopoDS_Vertex V = TopoDS::Vertex(meshDS->IndexToShape(myTriaVertexID));
1139 TopoDS_Edge E1,E2,E3;
1140 for (; edgeIt != edges.end(); ++edgeIt) {
1141 TopoDS_Edge E = TopoDS::Edge(*edgeIt);
1142 TopoDS_Vertex VF, VL;
1143 TopExp::Vertices(E, VF, VL, true);
1146 else if (VL.IsSame(V))
1151 SMESH_subMesh * sm = aMesh.GetSubMesh(E1);
1152 MapShapeNbElemsItr anIt = aResMap.find(sm);
1153 if (anIt==aResMap.end()) return false;
1154 std::vector<int> aVec = (*anIt).second;
1156 aNbNodes[0] = (aVec[SMDSEntity_Node]-1)/2 + 2;
1158 aNbNodes[0] = aVec[SMDSEntity_Node] + 2;
1159 sm = aMesh.GetSubMesh(E2);
1160 anIt = aResMap.find(sm);
1161 if (anIt==aResMap.end()) return false;
1162 aVec = (*anIt).second;
1164 aNbNodes[1] = (aVec[SMDSEntity_Node]-1)/2 + 2;
1166 aNbNodes[1] = aVec[SMDSEntity_Node] + 2;
1167 sm = aMesh.GetSubMesh(E3);
1168 anIt = aResMap.find(sm);
1169 if (anIt==aResMap.end()) return false;
1170 aVec = (*anIt).second;
1172 aNbNodes[2] = (aVec[SMDSEntity_Node]-1)/2 + 2;
1174 aNbNodes[2] = aVec[SMDSEntity_Node] + 2;
1175 aNbNodes[3] = aNbNodes[1];
1181 if (nbEdgesInWire.front() == 4) { // exactly 4 edges
1182 for (; edgeIt != edges.end(); edgeIt++) {
1183 SMESH_subMesh * sm = aMesh.GetSubMesh(*edgeIt);
1184 MapShapeNbElemsItr anIt = aResMap.find(sm);
1185 if (anIt==aResMap.end()) {
1188 std::vector<int> aVec = (*anIt).second;
1190 aNbNodes[nbSides] = (aVec[SMDSEntity_Node]-1)/2 + 2;
1192 aNbNodes[nbSides] = aVec[SMDSEntity_Node] + 2;
1196 else if (nbEdgesInWire.front() > 4) { // more than 4 edges - try to unite some
1197 list< TopoDS_Edge > sideEdges;
1198 while (!edges.empty()) {
1200 sideEdges.splice(sideEdges.end(), edges, edges.begin()); // edges.front() -> sideEdges.end()
1201 bool sameSide = true;
1202 while (!edges.empty() && sameSide) {
1203 sameSide = SMESH_Algo::IsContinuous(sideEdges.back(), edges.front());
1205 sideEdges.splice(sideEdges.end(), edges, edges.begin());
1207 if (nbSides == 0) { // go backward from the first edge
1209 while (!edges.empty() && sameSide) {
1210 sameSide = SMESH_Algo::IsContinuous(sideEdges.front(), edges.back());
1212 sideEdges.splice(sideEdges.begin(), edges, --edges.end());
1215 list<TopoDS_Edge>::iterator ite = sideEdges.begin();
1216 aNbNodes[nbSides] = 1;
1217 for (; ite!=sideEdges.end(); ite++) {
1218 SMESH_subMesh * sm = aMesh.GetSubMesh(*ite);
1219 MapShapeNbElemsItr anIt = aResMap.find(sm);
1220 if (anIt==aResMap.end()) {
1223 std::vector<int> aVec = (*anIt).second;
1225 aNbNodes[nbSides] += (aVec[SMDSEntity_Node]-1)/2 + 1;
1227 aNbNodes[nbSides] += aVec[SMDSEntity_Node] + 1;
1231 // issue 20222. Try to unite only edges shared by two same faces
1234 SMESH_Block::GetOrderedEdges (F, edges, nbEdgesInWire);
1235 while (!edges.empty()) {
1237 sideEdges.splice(sideEdges.end(), edges, edges.begin());
1238 bool sameSide = true;
1239 while (!edges.empty() && sameSide) {
1241 SMESH_Algo::IsContinuous(sideEdges.back(), edges.front()) &&
1242 twoEdgesMeatAtVertex(sideEdges.back(), edges.front(), aMesh);
1244 sideEdges.splice(sideEdges.end(), edges, edges.begin());
1246 if (nbSides == 0) { // go backward from the first edge
1248 while (!edges.empty() && sameSide) {
1250 SMESH_Algo::IsContinuous(sideEdges.front(), edges.back()) &&
1251 twoEdgesMeatAtVertex(sideEdges.front(), edges.back(), aMesh);
1253 sideEdges.splice(sideEdges.begin(), edges, --edges.end());
1256 list<TopoDS_Edge>::iterator ite = sideEdges.begin();
1257 aNbNodes[nbSides] = 1;
1258 for (; ite!=sideEdges.end(); ite++) {
1259 SMESH_subMesh * sm = aMesh.GetSubMesh(*ite);
1260 MapShapeNbElemsItr anIt = aResMap.find(sm);
1261 if (anIt==aResMap.end()) {
1264 std::vector<int> aVec = (*anIt).second;
1266 aNbNodes[nbSides] += (aVec[SMDSEntity_Node]-1)/2 + 1;
1268 aNbNodes[nbSides] += aVec[SMDSEntity_Node] + 1;
1276 nbSides = nbEdgesInWire.front();
1277 error(COMPERR_BAD_SHAPE, TComm("Face must have 4 sides but not ") << nbSides);
1285 //=============================================================================
1289 //=============================================================================
1292 StdMeshers_Quadrangle_2D::CheckAnd2Dcompute (SMESH_Mesh & aMesh,
1293 const TopoDS_Shape & aShape,
1294 const bool CreateQuadratic)
1296 _quadraticMesh = CreateQuadratic;
1298 FaceQuadStruct::Ptr quad = CheckNbEdges(aMesh, aShape);
1301 // set normalized grid on unit square in parametric domain
1302 if ( ! setNormalizedGrid( quad ))
1310 inline const vector<UVPtStruct>& getUVPtStructIn(FaceQuadStruct::Ptr& quad, int i, int nbSeg)
1312 bool isXConst = (i == QUAD_BOTTOM_SIDE || i == QUAD_TOP_SIDE);
1313 double constValue = (i == QUAD_BOTTOM_SIDE || i == QUAD_LEFT_SIDE) ? 0 : 1;
1315 quad->nbNodeOut(i) ?
1316 quad->side[i].grid->SimulateUVPtStruct(nbSeg,isXConst,constValue) :
1317 quad->side[i].grid->GetUVPtStruct (isXConst,constValue);
1319 inline gp_UV calcUV(double x, double y,
1320 const gp_UV& a0,const gp_UV& a1,const gp_UV& a2,const gp_UV& a3,
1321 const gp_UV& p0,const gp_UV& p1,const gp_UV& p2,const gp_UV& p3)
1324 ((1 - y) * p0 + x * p1 + y * p2 + (1 - x) * p3 ) -
1325 ((1 - x) * (1 - y) * a0 + x * (1 - y) * a1 + x * y * a2 + (1 - x) * y * a3);
1329 //=============================================================================
1333 //=============================================================================
1335 bool StdMeshers_Quadrangle_2D::setNormalizedGrid (FaceQuadStruct::Ptr quad)
1337 if ( !quad->uv_grid.empty() )
1340 // Algorithme décrit dans "Génération automatique de maillages"
1341 // P.L. GEORGE, MASSON, § 6.4.1 p. 84-85
1342 // traitement dans le domaine paramétrique 2d u,v
1343 // transport - projection sur le carré unité
1346 // |<----north-2-------^ a3 -------------> a2
1348 // west-3 east-1 =right | |
1352 // v----south-0--------> a0 -------------> a1
1356 const FaceQuadStruct::Side & bSide = quad->side[0];
1357 const FaceQuadStruct::Side & rSide = quad->side[1];
1358 const FaceQuadStruct::Side & tSide = quad->side[2];
1359 const FaceQuadStruct::Side & lSide = quad->side[3];
1361 int nbhoriz = Min( bSide.NbPoints(), tSide.NbPoints() );
1362 int nbvertic = Min( rSide.NbPoints(), lSide.NbPoints() );
1364 if ( myQuadList.size() == 1 )
1366 // all sub-quads must have NO sides with nbNodeOut > 0
1367 quad->nbNodeOut(0) = Max( 0, bSide.grid->NbPoints() - tSide.grid->NbPoints() );
1368 quad->nbNodeOut(1) = Max( 0, rSide.grid->NbPoints() - lSide.grid->NbPoints() );
1369 quad->nbNodeOut(2) = Max( 0, tSide.grid->NbPoints() - bSide.grid->NbPoints() );
1370 quad->nbNodeOut(3) = Max( 0, lSide.grid->NbPoints() - rSide.grid->NbPoints() );
1372 const vector<UVPtStruct>& uv_e0 = bSide.GetUVPtStruct();
1373 const vector<UVPtStruct>& uv_e1 = rSide.GetUVPtStruct();
1374 const vector<UVPtStruct>& uv_e2 = tSide.GetUVPtStruct();
1375 const vector<UVPtStruct>& uv_e3 = lSide.GetUVPtStruct();
1376 if (uv_e0.empty() || uv_e1.empty() || uv_e2.empty() || uv_e3.empty())
1377 //return error("Can't find nodes on sides");
1378 return error(COMPERR_BAD_INPUT_MESH);
1380 quad->uv_grid.resize( nbvertic * nbhoriz );
1381 quad->iSize = nbhoriz;
1382 quad->jSize = nbvertic;
1383 UVPtStruct *uv_grid = & quad->uv_grid[0];
1385 quad->uv_box.Clear();
1387 // copy data of face boundary
1389 FaceQuadStruct::SideIterator sideIter;
1393 const double x0 = bSide.First().normParam;
1394 const double dx = bSide.Last().normParam - bSide.First().normParam;
1395 for ( sideIter.Init( bSide ); sideIter.More(); sideIter.Next() ) {
1396 sideIter.UVPt().x = ( sideIter.UVPt().normParam - x0 ) / dx;
1397 sideIter.UVPt().y = 0.;
1398 uv_grid[ j * nbhoriz + sideIter.Count() ] = sideIter.UVPt();
1399 quad->uv_box.Add( sideIter.UVPt().UV() );
1403 const int i = nbhoriz - 1;
1404 const double y0 = rSide.First().normParam;
1405 const double dy = rSide.Last().normParam - rSide.First().normParam;
1406 sideIter.Init( rSide );
1407 if ( quad->UVPt( i, sideIter.Count() ).node )
1408 sideIter.Next(); // avoid copying from a split emulated side
1409 for ( ; sideIter.More(); sideIter.Next() ) {
1410 sideIter.UVPt().x = 1.;
1411 sideIter.UVPt().y = ( sideIter.UVPt().normParam - y0 ) / dy;
1412 uv_grid[ sideIter.Count() * nbhoriz + i ] = sideIter.UVPt();
1413 quad->uv_box.Add( sideIter.UVPt().UV() );
1417 const int j = nbvertic - 1;
1418 const double x0 = tSide.First().normParam;
1419 const double dx = tSide.Last().normParam - tSide.First().normParam;
1420 int i = 0, nb = nbhoriz;
1421 sideIter.Init( tSide );
1422 if ( quad->UVPt( nb-1, j ).node ) --nb; // avoid copying from a split emulated side
1423 for ( ; i < nb; i++, sideIter.Next()) {
1424 sideIter.UVPt().x = ( sideIter.UVPt().normParam - x0 ) / dx;
1425 sideIter.UVPt().y = 1.;
1426 uv_grid[ j * nbhoriz + i ] = sideIter.UVPt();
1427 quad->uv_box.Add( sideIter.UVPt().UV() );
1432 const double y0 = lSide.First().normParam;
1433 const double dy = lSide.Last().normParam - lSide.First().normParam;
1434 int j = 0, nb = nbvertic;
1435 sideIter.Init( lSide );
1436 if ( quad->UVPt( i, j ).node )
1437 ++j, sideIter.Next(); // avoid copying from a split emulated side
1438 if ( quad->UVPt( i, nb-1 ).node )
1440 for ( ; j < nb; j++, sideIter.Next()) {
1441 sideIter.UVPt().x = 0.;
1442 sideIter.UVPt().y = ( sideIter.UVPt().normParam - y0 ) / dy;
1443 uv_grid[ j * nbhoriz + i ] = sideIter.UVPt();
1444 quad->uv_box.Add( sideIter.UVPt().UV() );
1448 // normalized 2d parameters on grid
1450 for (int i = 1; i < nbhoriz-1; i++)
1452 const double x0 = quad->UVPt( i, 0 ).x;
1453 const double x1 = quad->UVPt( i, nbvertic-1 ).x;
1454 for (int j = 1; j < nbvertic-1; j++)
1456 const double y0 = quad->UVPt( 0, j ).y;
1457 const double y1 = quad->UVPt( nbhoriz-1, j ).y;
1458 // --- intersection : x=x0+(y0+x(y1-y0))(x1-x0)
1459 double x = (x0 + y0 * (x1 - x0)) / (1 - (y1 - y0) * (x1 - x0));
1460 double y = y0 + x * (y1 - y0);
1461 int ij = j * nbhoriz + i;
1464 uv_grid[ij].node = NULL;
1468 // projection on 2d domain (u,v)
1470 gp_UV a0 = quad->UVPt( 0, 0 ).UV();
1471 gp_UV a1 = quad->UVPt( nbhoriz-1, 0 ).UV();
1472 gp_UV a2 = quad->UVPt( nbhoriz-1, nbvertic-1 ).UV();
1473 gp_UV a3 = quad->UVPt( 0, nbvertic-1 ).UV();
1475 for (int i = 1; i < nbhoriz-1; i++)
1477 gp_UV p0 = quad->UVPt( i, 0 ).UV();
1478 gp_UV p2 = quad->UVPt( i, nbvertic-1 ).UV();
1479 for (int j = 1; j < nbvertic-1; j++)
1481 gp_UV p1 = quad->UVPt( nbhoriz-1, j ).UV();
1482 gp_UV p3 = quad->UVPt( 0, j ).UV();
1484 int ij = j * nbhoriz + i;
1485 double x = uv_grid[ij].x;
1486 double y = uv_grid[ij].y;
1488 gp_UV uv = calcUV(x,y, a0,a1,a2,a3, p0,p1,p2,p3);
1490 uv_grid[ij].u = uv.X();
1491 uv_grid[ij].v = uv.Y();
1497 //=======================================================================
1498 //function : ShiftQuad
1499 //purpose : auxilary function for computeQuadPref
1500 //=======================================================================
1502 void StdMeshers_Quadrangle_2D::shiftQuad(FaceQuadStruct::Ptr& quad, const int num )
1504 quad->shift( num, /*ori=*/true, /*keepGrid=*/myQuadList.size() > 1 );
1507 //================================================================================
1509 * \brief Rotate sides of a quad by given nb of quartes
1510 * \param nb - number of rotation quartes
1511 * \param ori - to keep orientation of sides as in an unit quad or not
1512 * \param keepGrid - if \c true Side::grid is not changed, Side::from and Side::to
1513 * are altered instead
1515 //================================================================================
1517 void FaceQuadStruct::shift( size_t nb, bool ori, bool keepGrid )
1519 if ( nb == 0 ) return;
1521 vector< Side > newSides( side.size() );
1522 vector< Side* > sidePtrs( side.size() );
1523 for (int i = QUAD_BOTTOM_SIDE; i < NB_QUAD_SIDES; ++i)
1525 int id = (i + nb) % NB_QUAD_SIDES;
1528 bool wasForward = (i < QUAD_TOP_SIDE);
1529 bool newForward = (id < QUAD_TOP_SIDE);
1530 if ( wasForward != newForward )
1531 side[ i ].Reverse( keepGrid );
1533 newSides[ id ] = side[ i ];
1534 sidePtrs[ i ] = & side[ i ];
1536 // make newSides refer newSides via Side::Contact's
1537 for ( size_t i = 0; i < newSides.size(); ++i )
1539 FaceQuadStruct::Side& ns = newSides[ i ];
1540 for ( size_t iC = 0; iC < ns.contacts.size(); ++iC )
1542 FaceQuadStruct::Side* oSide = ns.contacts[iC].other_side;
1543 vector< Side* >::iterator sIt = std::find( sidePtrs.begin(), sidePtrs.end(), oSide );
1544 if ( sIt != sidePtrs.end() )
1545 ns.contacts[iC].other_side = & newSides[ *sIt - sidePtrs[0] ];
1548 newSides.swap( side );
1553 //=======================================================================
1555 //purpose : auxilary function for computeQuadPref
1556 //=======================================================================
1558 static gp_UV calcUV(double x0, double x1, double y0, double y1,
1559 FaceQuadStruct::Ptr& quad,
1560 const gp_UV& a0, const gp_UV& a1,
1561 const gp_UV& a2, const gp_UV& a3)
1563 double x = (x0 + y0 * (x1 - x0)) / (1 - (y1 - y0) * (x1 - x0));
1564 double y = y0 + x * (y1 - y0);
1566 gp_UV p0 = quad->side[QUAD_BOTTOM_SIDE].grid->Value2d(x).XY();
1567 gp_UV p1 = quad->side[QUAD_RIGHT_SIDE ].grid->Value2d(y).XY();
1568 gp_UV p2 = quad->side[QUAD_TOP_SIDE ].grid->Value2d(x).XY();
1569 gp_UV p3 = quad->side[QUAD_LEFT_SIDE ].grid->Value2d(y).XY();
1571 gp_UV uv = calcUV(x,y, a0,a1,a2,a3, p0,p1,p2,p3);
1576 //=======================================================================
1577 //function : calcUV2
1578 //purpose : auxilary function for computeQuadPref
1579 //=======================================================================
1581 static gp_UV calcUV2(double x, double y,
1582 FaceQuadStruct::Ptr& quad,
1583 const gp_UV& a0, const gp_UV& a1,
1584 const gp_UV& a2, const gp_UV& a3)
1586 gp_UV p0 = quad->side[QUAD_BOTTOM_SIDE].grid->Value2d(x).XY();
1587 gp_UV p1 = quad->side[QUAD_RIGHT_SIDE ].grid->Value2d(y).XY();
1588 gp_UV p2 = quad->side[QUAD_TOP_SIDE ].grid->Value2d(x).XY();
1589 gp_UV p3 = quad->side[QUAD_LEFT_SIDE ].grid->Value2d(y).XY();
1591 gp_UV uv = calcUV(x,y, a0,a1,a2,a3, p0,p1,p2,p3);
1597 //=======================================================================
1599 * Create only quandrangle faces
1601 //=======================================================================
1603 bool StdMeshers_Quadrangle_2D::computeQuadPref (SMESH_Mesh & aMesh,
1604 const TopoDS_Face& aFace,
1605 FaceQuadStruct::Ptr quad)
1607 const bool OldVersion = (myQuadType == QUAD_QUADRANGLE_PREF_REVERSED);
1608 const bool WisF = true;
1610 SMESHDS_Mesh * meshDS = aMesh.GetMeshDS();
1611 Handle(Geom_Surface) S = BRep_Tool::Surface(aFace);
1612 int i,j, geomFaceID = meshDS->ShapeToIndex(aFace);
1614 int nb = quad->side[0].NbPoints();
1615 int nr = quad->side[1].NbPoints();
1616 int nt = quad->side[2].NbPoints();
1617 int nl = quad->side[3].NbPoints();
1618 int dh = abs(nb-nt);
1619 int dv = abs(nr-nl);
1621 if ( myForcedPnts.empty() )
1623 // rotate sides to be as in the picture below and to have
1624 // dh >= dv and nt > nb
1626 shiftQuad( quad, ( nt > nb ) ? 0 : 2 );
1628 shiftQuad( quad, ( nr > nl ) ? 1 : 3 );
1632 // rotate the quad to have nt > nb [and nr > nl]
1634 shiftQuad ( quad, nr > nl ? 1 : 2 );
1636 shiftQuad( quad, nb == nt ? 1 : 0 );
1638 shiftQuad( quad, 3 );
1641 nb = quad->side[0].NbPoints();
1642 nr = quad->side[1].NbPoints();
1643 nt = quad->side[2].NbPoints();
1644 nl = quad->side[3].NbPoints();
1647 int nbh = Max(nb,nt);
1648 int nbv = Max(nr,nl);
1652 // Orientation of face and 3 main domain for future faces
1653 // ----------- Old version ---------------
1659 // left | |__| | rigth
1666 // ----------- New version ---------------
1672 // left |/________\| rigth
1680 const int bfrom = quad->side[0].from;
1681 const int rfrom = quad->side[1].from;
1682 const int tfrom = quad->side[2].from;
1683 const int lfrom = quad->side[3].from;
1685 const vector<UVPtStruct>& uv_eb_vec = quad->side[0].GetUVPtStruct(true,0);
1686 const vector<UVPtStruct>& uv_er_vec = quad->side[1].GetUVPtStruct(false,1);
1687 const vector<UVPtStruct>& uv_et_vec = quad->side[2].GetUVPtStruct(true,1);
1688 const vector<UVPtStruct>& uv_el_vec = quad->side[3].GetUVPtStruct(false,0);
1689 if (uv_eb_vec.empty() ||
1690 uv_er_vec.empty() ||
1691 uv_et_vec.empty() ||
1693 return error(COMPERR_BAD_INPUT_MESH);
1695 FaceQuadStruct::SideIterator uv_eb, uv_er, uv_et, uv_el;
1696 uv_eb.Init( quad->side[0] );
1697 uv_er.Init( quad->side[1] );
1698 uv_et.Init( quad->side[2] );
1699 uv_el.Init( quad->side[3] );
1701 gp_UV a0,a1,a2,a3, p0,p1,p2,p3, uv;
1704 a0 = uv_eb[ 0 ].UV();
1705 a1 = uv_er[ 0 ].UV();
1706 a2 = uv_er[ nr-1 ].UV();
1707 a3 = uv_et[ 0 ].UV();
1709 if ( !myForcedPnts.empty() )
1711 if ( dv != 0 && dh != 0 ) // here myQuadList.size() == 1
1713 const int dmin = Min( dv, dh );
1715 // Make a side separating domains L and Cb
1716 StdMeshers_FaceSidePtr sideLCb;
1717 UVPtStruct p3dom; // a point where 3 domains meat
1719 vector<UVPtStruct> pointsLCb( dmin+1 ); // 1--------1
1720 pointsLCb[0] = uv_eb[0]; // | | |
1721 for ( int i = 1; i <= dmin; ++i ) // | |Ct|
1723 x = uv_et[ i ].normParam; // | |__|
1724 y = uv_er[ i ].normParam; // | / |
1725 p0 = quad->side[0].grid->Value2d( x ).XY(); // | / Cb |dmin
1726 p1 = uv_er[ i ].UV(); // |/ |
1727 p2 = uv_et[ i ].UV(); // 0--------0
1728 p3 = quad->side[3].grid->Value2d( y ).XY();
1729 uv = calcUV( x,y, a0,a1,a2,a3, p0,p1,p2,p3 );
1730 pointsLCb[ i ].u = uv.X();
1731 pointsLCb[ i ].v = uv.Y();
1733 sideLCb = StdMeshers_FaceSide::New( pointsLCb, aFace );
1734 p3dom = pointsLCb.back();
1736 // Make a side separating domains L and Ct
1737 StdMeshers_FaceSidePtr sideLCt;
1739 vector<UVPtStruct> pointsLCt( nl );
1740 pointsLCt[0] = p3dom;
1741 pointsLCt.back() = uv_et[ dmin ];
1742 x = uv_et[ dmin ].normParam;
1743 p0 = quad->side[0].grid->Value2d( x ).XY();
1744 p2 = uv_et[ dmin ].UV();
1745 double y0 = uv_er[ dmin ].normParam;
1746 for ( int i = 1; i < nl-1; ++i )
1748 y = y0 + i / ( nl-1. ) * ( 1. - y0 );
1749 p1 = quad->side[1].grid->Value2d( y ).XY();
1750 p3 = quad->side[3].grid->Value2d( y ).XY();
1751 uv = calcUV( x,y, a0,a1,a2,a3, p0,p1,p2,p3 );
1752 pointsLCt[ i ].u = uv.X();
1753 pointsLCt[ i ].v = uv.Y();
1755 sideLCt = StdMeshers_FaceSide::New( pointsLCt, aFace );
1757 // Make a side separating domains Cb and Ct
1758 StdMeshers_FaceSidePtr sideCbCt;
1760 vector<UVPtStruct> pointsCbCt( nb );
1761 pointsCbCt[0] = p3dom;
1762 pointsCbCt.back() = uv_er[ dmin ];
1763 y = uv_er[ dmin ].normParam;
1764 p1 = uv_er[ dmin ].UV();
1765 p3 = quad->side[3].grid->Value2d( y ).XY();
1766 double x0 = uv_et[ dmin ].normParam;
1767 for ( int i = 1; i < nb-1; ++i )
1769 x = x0 + i / ( nb-1. ) * ( 1. - x0 );
1770 p2 = quad->side[2].grid->Value2d( x ).XY();
1771 p0 = quad->side[0].grid->Value2d( x ).XY();
1772 uv = calcUV( x,y, a0,a1,a2,a3, p0,p1,p2,p3 );
1773 pointsCbCt[ i ].u = uv.X();
1774 pointsCbCt[ i ].v = uv.Y();
1776 sideCbCt = StdMeshers_FaceSide::New( pointsCbCt, aFace );
1779 FaceQuadStruct* qCb = new FaceQuadStruct( quad->face, "Cb" );
1780 myQuadList.push_back( FaceQuadStruct::Ptr( qCb ));
1781 qCb->side.resize(4);
1782 qCb->side[0] = quad->side[0];
1783 qCb->side[1] = quad->side[1];
1784 qCb->side[2] = sideCbCt;
1785 qCb->side[3] = sideLCb;
1786 qCb->side[1].to = dmin+1;
1788 FaceQuadStruct* qL = new FaceQuadStruct( quad->face, "L" );
1789 myQuadList.push_back( FaceQuadStruct::Ptr( qL ));
1791 qL->side[0] = sideLCb;
1792 qL->side[1] = sideLCt;
1793 qL->side[2] = quad->side[2];
1794 qL->side[3] = quad->side[3];
1795 qL->side[2].to = dmin+1;
1796 // Make Ct from the main quad
1797 FaceQuadStruct::Ptr qCt = quad;
1798 qCt->side[0] = sideCbCt;
1799 qCt->side[3] = sideLCt;
1800 qCt->side[1].from = dmin;
1801 qCt->side[2].from = dmin;
1802 qCt->uv_grid.clear();
1806 qCb->side[3].AddContact( dmin, & qCb->side[2], 0 );
1807 qCb->side[3].AddContact( dmin, & qCt->side[3], 0 );
1808 qCt->side[3].AddContact( 0, & qCt->side[0], 0 );
1809 qCt->side[0].AddContact( 0, & qL ->side[0], dmin );
1810 qL ->side[0].AddContact( dmin, & qL ->side[1], 0 );
1811 qL ->side[0].AddContact( dmin, & qCb->side[2], 0 );
1814 return computeQuadDominant( aMesh, aFace );
1816 return computeQuadPref( aMesh, aFace, qCt );
1818 } // if ( dv != 0 && dh != 0 )
1820 const int db = quad->side[0].IsReversed() ? -1 : +1;
1821 const int dr = quad->side[1].IsReversed() ? -1 : +1;
1822 const int dt = quad->side[2].IsReversed() ? -1 : +1;
1823 const int dl = quad->side[3].IsReversed() ? -1 : +1;
1825 // Case dv == 0, here possibly myQuadList.size() > 1
1837 const int lw = dh/2; // lateral width
1841 double lL = quad->side[3].Length();
1842 double lLwL = quad->side[2].Length( tfrom,
1843 tfrom + ( lw ) * dt );
1844 yCbL = lLwL / ( lLwL + lL );
1846 double lR = quad->side[1].Length();
1847 double lLwR = quad->side[2].Length( tfrom + ( lw + nb-1 ) * dt,
1848 tfrom + ( lw + nb-1 + lw ) * dt);
1849 yCbR = lLwR / ( lLwR + lR );
1851 // Make sides separating domains Cb and L and R
1852 StdMeshers_FaceSidePtr sideLCb, sideRCb;
1853 UVPtStruct pTBL, pTBR; // points where 3 domains meat
1855 vector<UVPtStruct> pointsLCb( lw+1 ), pointsRCb( lw+1 );
1856 pointsLCb[0] = uv_eb[ 0 ];
1857 pointsRCb[0] = uv_eb[ nb-1 ];
1858 for ( int i = 1, i2 = nt-2; i <= lw; ++i, --i2 )
1860 x = quad->side[2].Param( i );
1862 p0 = quad->side[0].Value2d( x );
1863 p1 = quad->side[1].Value2d( y );
1864 p2 = uv_et[ i ].UV();
1865 p3 = quad->side[3].Value2d( y );
1866 uv = calcUV( x,y, a0,a1,a2,a3, p0,p1,p2,p3 );
1867 pointsLCb[ i ].u = uv.X();
1868 pointsLCb[ i ].v = uv.Y();
1869 pointsLCb[ i ].x = x;
1871 x = quad->side[2].Param( i2 );
1873 p1 = quad->side[1].Value2d( y );
1874 p0 = quad->side[0].Value2d( x );
1875 p2 = uv_et[ i2 ].UV();
1876 p3 = quad->side[3].Value2d( y );
1877 uv = calcUV( x,y, a0,a1,a2,a3, p0,p1,p2,p3 );
1878 pointsRCb[ i ].u = uv.X();
1879 pointsRCb[ i ].v = uv.Y();
1880 pointsRCb[ i ].x = x;
1882 sideLCb = StdMeshers_FaceSide::New( pointsLCb, aFace );
1883 sideRCb = StdMeshers_FaceSide::New( pointsRCb, aFace );
1884 pTBL = pointsLCb.back();
1885 pTBR = pointsRCb.back();
1887 // Make sides separating domains Ct and L and R
1888 StdMeshers_FaceSidePtr sideLCt, sideRCt;
1890 vector<UVPtStruct> pointsLCt( nl ), pointsRCt( nl );
1891 pointsLCt[0] = pTBL;
1892 pointsLCt.back() = uv_et[ lw ];
1893 pointsRCt[0] = pTBR;
1894 pointsRCt.back() = uv_et[ lw + nb - 1 ];
1896 p0 = quad->side[0].Value2d( x );
1897 p2 = uv_et[ lw ].UV();
1898 int iR = lw + nb - 1;
1900 gp_UV p0R = quad->side[0].Value2d( xR );
1901 gp_UV p2R = uv_et[ iR ].UV();
1902 for ( int i = 1; i < nl-1; ++i )
1904 y = yCbL + ( 1. - yCbL ) * i / (nl-1.);
1905 p1 = quad->side[1].Value2d( y );
1906 p3 = quad->side[3].Value2d( y );
1907 uv = calcUV( x,y, a0,a1,a2,a3, p0,p1,p2,p3 );
1908 pointsLCt[ i ].u = uv.X();
1909 pointsLCt[ i ].v = uv.Y();
1911 y = yCbR + ( 1. - yCbR ) * i / (nl-1.);
1912 p1 = quad->side[1].Value2d( y );
1913 p3 = quad->side[3].Value2d( y );
1914 uv = calcUV( xR,y, a0,a1,a2,a3, p0R,p1,p2R,p3 );
1915 pointsRCt[ i ].u = uv.X();
1916 pointsRCt[ i ].v = uv.Y();
1918 sideLCt = StdMeshers_FaceSide::New( pointsLCt, aFace );
1919 sideRCt = StdMeshers_FaceSide::New( pointsRCt, aFace );
1921 // Make a side separating domains Cb and Ct
1922 StdMeshers_FaceSidePtr sideCbCt;
1924 vector<UVPtStruct> pointsCbCt( nb );
1925 pointsCbCt[0] = pTBL;
1926 pointsCbCt.back() = pTBR;
1927 p1 = quad->side[1].Value2d( yCbR );
1928 p3 = quad->side[3].Value2d( yCbL );
1929 for ( int i = 1; i < nb-1; ++i )
1931 x = quad->side[2].Param( i + lw );
1932 y = yCbL + ( yCbR - yCbL ) * i / (nb-1.);
1933 p2 = uv_et[ i + lw ].UV();
1934 p0 = quad->side[0].Value2d( x );
1935 uv = calcUV( x,y, a0,a1,a2,a3, p0,p1,p2,p3 );
1936 pointsCbCt[ i ].u = uv.X();
1937 pointsCbCt[ i ].v = uv.Y();
1939 sideCbCt = StdMeshers_FaceSide::New( pointsCbCt, aFace );
1942 FaceQuadStruct* qCb = new FaceQuadStruct( quad->face, "Cb" );
1943 myQuadList.push_back( FaceQuadStruct::Ptr( qCb ));
1944 qCb->side.resize(4);
1945 qCb->side[0] = quad->side[0];
1946 qCb->side[1] = sideRCb;
1947 qCb->side[2] = sideCbCt;
1948 qCb->side[3] = sideLCb;
1950 FaceQuadStruct* qL = new FaceQuadStruct( quad->face, "L" );
1951 myQuadList.push_back( FaceQuadStruct::Ptr( qL ));
1953 qL->side[0] = sideLCb;
1954 qL->side[1] = sideLCt;
1955 qL->side[2] = quad->side[2];
1956 qL->side[3] = quad->side[3];
1957 qL->side[2].to = ( lw + 1 ) * dt + tfrom;
1959 FaceQuadStruct* qR = new FaceQuadStruct( quad->face, "R" );
1960 myQuadList.push_back( FaceQuadStruct::Ptr( qR ));
1962 qR->side[0] = sideRCb;
1963 qR->side[0].from = lw;
1964 qR->side[0].to = -1;
1965 qR->side[0].di = -1;
1966 qR->side[1] = quad->side[1];
1967 qR->side[2] = quad->side[2];
1968 qR->side[2].from = ( lw + nb-1 ) * dt + tfrom;
1969 qR->side[3] = sideRCt;
1970 // Make Ct from the main quad
1971 FaceQuadStruct::Ptr qCt = quad;
1972 qCt->side[0] = sideCbCt;
1973 qCt->side[1] = sideRCt;
1974 qCt->side[2].from = ( lw ) * dt + tfrom;
1975 qCt->side[2].to = ( lw + nb ) * dt + tfrom;
1976 qCt->side[3] = sideLCt;
1977 qCt->uv_grid.clear();
1981 qCb->side[3].AddContact( lw, & qCb->side[2], 0 );
1982 qCb->side[3].AddContact( lw, & qCt->side[3], 0 );
1983 qCt->side[3].AddContact( 0, & qCt->side[0], 0 );
1984 qCt->side[0].AddContact( 0, & qL ->side[0], lw );
1985 qL ->side[0].AddContact( lw, & qL ->side[1], 0 );
1986 qL ->side[0].AddContact( lw, & qCb->side[2], 0 );
1988 qCb->side[1].AddContact( lw, & qCb->side[2], nb-1 );
1989 qCb->side[1].AddContact( lw, & qCt->side[1], 0 );
1990 qCt->side[0].AddContact( nb-1, & qCt->side[1], 0 );
1991 qCt->side[0].AddContact( nb-1, & qR ->side[0], lw );
1992 qR ->side[3].AddContact( 0, & qR ->side[0], lw );
1993 qR ->side[3].AddContact( 0, & qCb->side[2], nb-1 );
1995 return computeQuadDominant( aMesh, aFace );
1997 } // if ( !myForcedPnts.empty() )
2008 // arrays for normalized params
2009 TColStd_SequenceOfReal npb, npr, npt, npl;
2010 for (i=0; i<nb; i++) {
2011 npb.Append(uv_eb[i].normParam);
2013 for (i=0; i<nr; i++) {
2014 npr.Append(uv_er[i].normParam);
2016 for (i=0; i<nt; i++) {
2017 npt.Append(uv_et[i].normParam);
2019 for (i=0; i<nl; i++) {
2020 npl.Append(uv_el[i].normParam);
2025 // add some params to right and left after the first param
2028 double dpr = (npr.Value(2) - npr.Value(1))/(dr+1);
2029 for (i=1; i<=dr; i++) {
2030 npr.InsertAfter(1,npr.Value(2)-dpr);
2034 dpr = (npl.Value(2) - npl.Value(1))/(dl+1);
2035 for (i=1; i<=dl; i++) {
2036 npl.InsertAfter(1,npl.Value(2)-dpr);
2040 int nnn = Min(nr,nl);
2041 // auxilary sequence of XY for creation nodes
2042 // in the bottom part of central domain
2043 // Length of UVL and UVR must be == nbv-nnn
2044 TColgp_SequenceOfXY UVL, UVR, UVT;
2047 // step1: create faces for left domain
2048 StdMeshers_Array2OfNode NodesL(1,dl+1,1,nl);
2050 for (j=1; j<=nl; j++)
2051 NodesL.SetValue(1,j,uv_el[j-1].node);
2054 for (i=1; i<=dl; i++)
2055 NodesL.SetValue(i+1,nl,uv_et[i].node);
2056 // create and add needed nodes
2057 TColgp_SequenceOfXY UVtmp;
2058 for (i=1; i<=dl; i++) {
2059 double x0 = npt.Value(i+1);
2062 double y0 = npl.Value(i+1);
2063 double y1 = npr.Value(i+1);
2064 gp_UV UV = calcUV(x0, x1, y0, y1, quad, a0, a1, a2, a3);
2065 gp_Pnt P = S->Value(UV.X(),UV.Y());
2066 SMDS_MeshNode * N = meshDS->AddNode(P.X(), P.Y(), P.Z());
2067 meshDS->SetNodeOnFace(N, geomFaceID, UV.X(), UV.Y());
2068 NodesL.SetValue(i+1,1,N);
2069 if (UVL.Length()<nbv-nnn) UVL.Append(UV);
2071 for (j=2; j<nl; j++) {
2072 double y0 = npl.Value(dl+j);
2073 double y1 = npr.Value(dl+j);
2074 gp_UV UV = calcUV(x0, x1, y0, y1, quad, a0, a1, a2, a3);
2075 gp_Pnt P = S->Value(UV.X(),UV.Y());
2076 SMDS_MeshNode* N = meshDS->AddNode(P.X(), P.Y(), P.Z());
2077 meshDS->SetNodeOnFace(N, geomFaceID, UV.X(), UV.Y());
2078 NodesL.SetValue(i+1,j,N);
2079 if (i==dl) UVtmp.Append(UV);
2082 for (i=1; i<=UVtmp.Length() && UVL.Length()<nbv-nnn; i++) {
2083 UVL.Append(UVtmp.Value(i));
2086 for (i=1; i<=dl; i++) {
2087 for (j=1; j<nl; j++) {
2090 myHelper->AddFace(NodesL.Value(i,j), NodesL.Value(i+1,j),
2091 NodesL.Value(i+1,j+1), NodesL.Value(i,j+1));
2092 if (F) meshDS->SetMeshElementOnShape(F, geomFaceID);
2098 // fill UVL using c2d
2099 for (i=1; i<npl.Length() && UVL.Length()<nbv-nnn; i++) {
2100 UVL.Append(gp_UV (uv_el[i].u, uv_el[i].v));
2104 // step2: create faces for right domain
2105 StdMeshers_Array2OfNode NodesR(1,dr+1,1,nr);
2107 for (j=1; j<=nr; j++)
2108 NodesR.SetValue(1,j,uv_er[nr-j].node);
2111 for (i=1; i<=dr; i++)
2112 NodesR.SetValue(i+1,1,uv_et[nt-1-i].node);
2113 // create and add needed nodes
2114 TColgp_SequenceOfXY UVtmp;
2115 for (i=1; i<=dr; i++) {
2116 double x0 = npt.Value(nt-i);
2119 double y0 = npl.Value(i+1);
2120 double y1 = npr.Value(i+1);
2121 gp_UV UV = calcUV(x0, x1, y0, y1, quad, a0, a1, a2, a3);
2122 gp_Pnt P = S->Value(UV.X(),UV.Y());
2123 SMDS_MeshNode * N = meshDS->AddNode(P.X(), P.Y(), P.Z());
2124 meshDS->SetNodeOnFace(N, geomFaceID, UV.X(), UV.Y());
2125 NodesR.SetValue(i+1,nr,N);
2126 if (UVR.Length()<nbv-nnn) UVR.Append(UV);
2128 for (j=2; j<nr; j++) {
2129 double y0 = npl.Value(nbv-j+1);
2130 double y1 = npr.Value(nbv-j+1);
2131 gp_UV UV = calcUV(x0, x1, y0, y1, quad, a0, a1, a2, a3);
2132 gp_Pnt P = S->Value(UV.X(),UV.Y());
2133 SMDS_MeshNode* N = meshDS->AddNode(P.X(), P.Y(), P.Z());
2134 meshDS->SetNodeOnFace(N, geomFaceID, UV.X(), UV.Y());
2135 NodesR.SetValue(i+1,j,N);
2136 if (i==dr) UVtmp.Prepend(UV);
2139 for (i=1; i<=UVtmp.Length() && UVR.Length()<nbv-nnn; i++) {
2140 UVR.Append(UVtmp.Value(i));
2143 for (i=1; i<=dr; i++) {
2144 for (j=1; j<nr; j++) {
2147 myHelper->AddFace(NodesR.Value(i,j), NodesR.Value(i+1,j),
2148 NodesR.Value(i+1,j+1), NodesR.Value(i,j+1));
2149 if (F) meshDS->SetMeshElementOnShape(F, geomFaceID);
2155 // fill UVR using c2d
2156 for (i=1; i<npr.Length() && UVR.Length()<nbv-nnn; i++) {
2157 UVR.Append(gp_UV(uv_er[i].u, uv_er[i].v));
2161 // step3: create faces for central domain
2162 StdMeshers_Array2OfNode NodesC(1,nb,1,nbv);
2163 // add first line using NodesL
2164 for (i=1; i<=dl+1; i++)
2165 NodesC.SetValue(1,i,NodesL(i,1));
2166 for (i=2; i<=nl; i++)
2167 NodesC.SetValue(1,dl+i,NodesL(dl+1,i));
2168 // add last line using NodesR
2169 for (i=1; i<=dr+1; i++)
2170 NodesC.SetValue(nb,i,NodesR(i,nr));
2171 for (i=1; i<nr; i++)
2172 NodesC.SetValue(nb,dr+i+1,NodesR(dr+1,nr-i));
2173 // add top nodes (last columns)
2174 for (i=dl+2; i<nbh-dr; i++)
2175 NodesC.SetValue(i-dl,nbv,uv_et[i-1].node);
2176 // add bottom nodes (first columns)
2177 for (i=2; i<nb; i++)
2178 NodesC.SetValue(i,1,uv_eb[i-1].node);
2180 // create and add needed nodes
2181 // add linear layers
2182 for (i=2; i<nb; i++) {
2183 double x0 = npt.Value(dl+i);
2185 for (j=1; j<nnn; j++) {
2186 double y0 = npl.Value(nbv-nnn+j);
2187 double y1 = npr.Value(nbv-nnn+j);
2188 gp_UV UV = calcUV(x0, x1, y0, y1, quad, a0, a1, a2, a3);
2189 gp_Pnt P = S->Value(UV.X(),UV.Y());
2190 SMDS_MeshNode* N = meshDS->AddNode(P.X(), P.Y(), P.Z());
2191 meshDS->SetNodeOnFace(N, geomFaceID, UV.X(), UV.Y());
2192 NodesC.SetValue(i,nbv-nnn+j,N);
2197 // add diagonal layers
2198 gp_UV A2 = UVR.Value(nbv-nnn);
2199 gp_UV A3 = UVL.Value(nbv-nnn);
2200 for (i=1; i<nbv-nnn; i++) {
2201 gp_UV p1 = UVR.Value(i);
2202 gp_UV p3 = UVL.Value(i);
2203 double y = i / double(nbv-nnn);
2204 for (j=2; j<nb; j++) {
2205 double x = npb.Value(j);
2206 gp_UV p0( uv_eb[j-1].u, uv_eb[j-1].v );
2207 gp_UV p2 = UVT.Value( j-1 );
2208 gp_UV UV = calcUV(x, y, a0, a1, A2, A3, p0,p1,p2,p3 );
2209 gp_Pnt P = S->Value(UV.X(),UV.Y());
2210 SMDS_MeshNode* N = meshDS->AddNode(P.X(), P.Y(), P.Z());
2211 meshDS->SetNodeOnFace(N, geomFaceID, UV.X(),UV.Y());
2212 NodesC.SetValue(j,i+1,N);
2216 for (i=1; i<nb; i++) {
2217 for (j=1; j<nbv; j++) {
2220 myHelper->AddFace(NodesC.Value(i,j), NodesC.Value(i+1,j),
2221 NodesC.Value(i+1,j+1), NodesC.Value(i,j+1));
2222 if (F) meshDS->SetMeshElementOnShape(F, geomFaceID);
2228 else { // New version (!OldVersion)
2229 // step1: create faces for bottom rectangle domain
2230 StdMeshers_Array2OfNode NodesBRD(1,nb,1,nnn-1);
2231 // fill UVL and UVR using c2d
2232 for (j=0; j<nb; j++) {
2233 NodesBRD.SetValue(j+1,1,uv_eb[j].node);
2235 for (i=1; i<nnn-1; i++) {
2236 NodesBRD.SetValue(1,i+1,uv_el[i].node);
2237 NodesBRD.SetValue(nb,i+1,uv_er[i].node);
2238 for (j=2; j<nb; j++) {
2239 double x = npb.Value(j);
2240 double y = (1-x) * npl.Value(i+1) + x * npr.Value(i+1);
2241 gp_UV UV = calcUV2(x, y, quad, a0, a1, a2, a3);
2242 gp_Pnt P = S->Value(UV.X(),UV.Y());
2243 SMDS_MeshNode* N = meshDS->AddNode(P.X(), P.Y(), P.Z());
2244 meshDS->SetNodeOnFace(N, geomFaceID, UV.X(),UV.Y());
2245 NodesBRD.SetValue(j,i+1,N);
2248 for (j=1; j<nnn-1; j++) {
2249 for (i=1; i<nb; i++) {
2252 myHelper->AddFace(NodesBRD.Value(i,j), NodesBRD.Value(i+1,j),
2253 NodesBRD.Value(i+1,j+1), NodesBRD.Value(i,j+1));
2254 if (F) meshDS->SetMeshElementOnShape(F, geomFaceID);
2258 int drl = abs(nr-nl);
2259 // create faces for region C
2260 StdMeshers_Array2OfNode NodesC(1,nb,1,drl+1+addv);
2261 // add nodes from previous region
2262 for (j=1; j<=nb; j++) {
2263 NodesC.SetValue(j,1,NodesBRD.Value(j,nnn-1));
2265 if ((drl+addv) > 0) {
2270 TColgp_SequenceOfXY UVtmp;
2271 double drparam = npr.Value(nr) - npr.Value(nnn-1);
2272 double dlparam = npl.Value(nnn) - npl.Value(nnn-1);
2274 for (i=1; i<=drl; i++) {
2275 // add existed nodes from right edge
2276 NodesC.SetValue(nb,i+1,uv_er[nnn+i-2].node);
2277 //double dtparam = npt.Value(i+1);
2278 y1 = npr.Value(nnn+i-1); // param on right edge
2279 double dpar = (y1 - npr.Value(nnn-1))/drparam;
2280 y0 = npl.Value(nnn-1) + dpar*dlparam; // param on left edge
2281 double dy = y1 - y0;
2282 for (j=1; j<nb; j++) {
2283 double x = npt.Value(i+1) + npb.Value(j)*(1-npt.Value(i+1));
2284 double y = y0 + dy*x;
2285 gp_UV UV = calcUV2(x, y, quad, a0, a1, a2, a3);
2286 gp_Pnt P = S->Value(UV.X(),UV.Y());
2287 SMDS_MeshNode* N = meshDS->AddNode(P.X(), P.Y(), P.Z());
2288 meshDS->SetNodeOnFace(N, geomFaceID, UV.X(), UV.Y());
2289 NodesC.SetValue(j,i+1,N);
2292 double dy0 = (1-y0)/(addv+1);
2293 double dy1 = (1-y1)/(addv+1);
2294 for (i=1; i<=addv; i++) {
2295 double yy0 = y0 + dy0*i;
2296 double yy1 = y1 + dy1*i;
2297 double dyy = yy1 - yy0;
2298 for (j=1; j<=nb; j++) {
2299 double x = npt.Value(i+1+drl) +
2300 npb.Value(j) * (npt.Value(nt-i) - npt.Value(i+1+drl));
2301 double y = yy0 + dyy*x;
2302 gp_UV UV = calcUV2(x, y, quad, a0, a1, a2, a3);
2303 gp_Pnt P = S->Value(UV.X(),UV.Y());
2304 SMDS_MeshNode* N = meshDS->AddNode(P.X(), P.Y(), P.Z());
2305 meshDS->SetNodeOnFace(N, geomFaceID, UV.X(), UV.Y());
2306 NodesC.SetValue(j,i+drl+1,N);
2313 TColgp_SequenceOfXY UVtmp;
2314 double dlparam = npl.Value(nl) - npl.Value(nnn-1);
2315 double drparam = npr.Value(nnn) - npr.Value(nnn-1);
2316 double y0 = npl.Value(nnn-1);
2317 double y1 = npr.Value(nnn-1);
2318 for (i=1; i<=drl; i++) {
2319 // add existed nodes from right edge
2320 NodesC.SetValue(1,i+1,uv_el[nnn+i-2].node);
2321 y0 = npl.Value(nnn+i-1); // param on left edge
2322 double dpar = (y0 - npl.Value(nnn-1))/dlparam;
2323 y1 = npr.Value(nnn-1) + dpar*drparam; // param on right edge
2324 double dy = y1 - y0;
2325 for (j=2; j<=nb; j++) {
2326 double x = npb.Value(j)*npt.Value(nt-i);
2327 double y = y0 + dy*x;
2328 gp_UV UV = calcUV2(x, y, quad, a0, a1, a2, a3);
2329 gp_Pnt P = S->Value(UV.X(),UV.Y());
2330 SMDS_MeshNode* N = meshDS->AddNode(P.X(), P.Y(), P.Z());
2331 meshDS->SetNodeOnFace(N, geomFaceID, UV.X(), UV.Y());
2332 NodesC.SetValue(j,i+1,N);
2335 double dy0 = (1-y0)/(addv+1);
2336 double dy1 = (1-y1)/(addv+1);
2337 for (i=1; i<=addv; i++) {
2338 double yy0 = y0 + dy0*i;
2339 double yy1 = y1 + dy1*i;
2340 double dyy = yy1 - yy0;
2341 for (j=1; j<=nb; j++) {
2342 double x = npt.Value(i+1) +
2343 npb.Value(j) * (npt.Value(nt-i-drl) - npt.Value(i+1));
2344 double y = yy0 + dyy*x;
2345 gp_UV UV = calcUV2(x, y, quad, a0, a1, a2, a3);
2346 gp_Pnt P = S->Value(UV.X(),UV.Y());
2347 SMDS_MeshNode* N = meshDS->AddNode(P.X(), P.Y(), P.Z());
2348 meshDS->SetNodeOnFace(N, geomFaceID, UV.X(), UV.Y());
2349 NodesC.SetValue(j,i+drl+1,N);
2354 for (j=1; j<=drl+addv; j++) {
2355 for (i=1; i<nb; i++) {
2358 myHelper->AddFace(NodesC.Value(i,j), NodesC.Value(i+1,j),
2359 NodesC.Value(i+1,j+1), NodesC.Value(i,j+1));
2360 if (F) meshDS->SetMeshElementOnShape(F, geomFaceID);
2365 StdMeshers_Array2OfNode NodesLast(1,nt,1,2);
2366 for (i=1; i<=nt; i++) {
2367 NodesLast.SetValue(i,2,uv_et[i-1].node);
2370 for (i=n1; i<drl+addv+1; i++) {
2372 NodesLast.SetValue(nnn,1,NodesC.Value(1,i));
2374 for (i=1; i<=nb; i++) {
2376 NodesLast.SetValue(nnn,1,NodesC.Value(i,drl+addv+1));
2378 for (i=drl+addv; i>=n2; i--) {
2380 NodesLast.SetValue(nnn,1,NodesC.Value(nb,i));
2382 for (i=1; i<nt; i++) {
2385 myHelper->AddFace(NodesLast.Value(i,1), NodesLast.Value(i+1,1),
2386 NodesLast.Value(i+1,2), NodesLast.Value(i,2));
2387 if (F) meshDS->SetMeshElementOnShape(F, geomFaceID);
2390 } // if ((drl+addv) > 0)
2392 } // end new version implementation
2399 //=======================================================================
2401 * Evaluate only quandrangle faces
2403 //=======================================================================
2405 bool StdMeshers_Quadrangle_2D::evaluateQuadPref(SMESH_Mesh & aMesh,
2406 const TopoDS_Shape& aShape,
2407 std::vector<int>& aNbNodes,
2408 MapShapeNbElems& aResMap,
2411 // Auxilary key in order to keep old variant
2412 // of meshing after implementation new variant
2413 // for bug 0016220 from Mantis.
2414 bool OldVersion = false;
2415 if (myQuadType == QUAD_QUADRANGLE_PREF_REVERSED)
2418 const TopoDS_Face& F = TopoDS::Face(aShape);
2419 Handle(Geom_Surface) S = BRep_Tool::Surface(F);
2421 int nb = aNbNodes[0];
2422 int nr = aNbNodes[1];
2423 int nt = aNbNodes[2];
2424 int nl = aNbNodes[3];
2425 int dh = abs(nb-nt);
2426 int dv = abs(nr-nl);
2430 // it is a base case => not shift
2433 // we have to shift on 2
2442 // we have to shift quad on 1
2449 // we have to shift quad on 3
2459 int nbh = Max(nb,nt);
2460 int nbv = Max(nr,nl);
2475 // add some params to right and left after the first param
2482 int nnn = Min(nr,nl);
2487 // step1: create faces for left domain
2489 nbNodes += dl*(nl-1);
2490 nbFaces += dl*(nl-1);
2492 // step2: create faces for right domain
2494 nbNodes += dr*(nr-1);
2495 nbFaces += dr*(nr-1);
2497 // step3: create faces for central domain
2498 nbNodes += (nb-2)*(nnn-1) + (nbv-nnn-1)*(nb-2);
2499 nbFaces += (nb-1)*(nbv-1);
2501 else { // New version (!OldVersion)
2502 nbNodes += (nnn-2)*(nb-2);
2503 nbFaces += (nnn-2)*(nb-1);
2504 int drl = abs(nr-nl);
2505 nbNodes += drl*(nb-1) + addv*nb;
2506 nbFaces += (drl+addv)*(nb-1) + (nt-1);
2507 } // end new version implementation
2509 std::vector<int> aVec(SMDSEntity_Last);
2510 for (int i=SMDSEntity_Node; i<SMDSEntity_Last; i++) aVec[i] = 0;
2512 aVec[SMDSEntity_Quad_Quadrangle] = nbFaces;
2513 aVec[SMDSEntity_Node] = nbNodes + nbFaces*4;
2514 if (aNbNodes.size()==5) {
2515 aVec[SMDSEntity_Quad_Triangle] = aNbNodes[3] - 1;
2516 aVec[SMDSEntity_Quad_Quadrangle] = nbFaces - aNbNodes[3] + 1;
2520 aVec[SMDSEntity_Node] = nbNodes;
2521 aVec[SMDSEntity_Quadrangle] = nbFaces;
2522 if (aNbNodes.size()==5) {
2523 aVec[SMDSEntity_Triangle] = aNbNodes[3] - 1;
2524 aVec[SMDSEntity_Quadrangle] = nbFaces - aNbNodes[3] + 1;
2527 SMESH_subMesh * sm = aMesh.GetSubMesh(aShape);
2528 aResMap.insert(std::make_pair(sm,aVec));
2533 //=============================================================================
2534 /*! Split quadrangle in to 2 triangles by smallest diagonal
2537 //=============================================================================
2539 void StdMeshers_Quadrangle_2D::splitQuadFace(SMESHDS_Mesh * theMeshDS,
2541 const SMDS_MeshNode* theNode1,
2542 const SMDS_MeshNode* theNode2,
2543 const SMDS_MeshNode* theNode3,
2544 const SMDS_MeshNode* theNode4)
2546 SMDS_MeshFace* face;
2547 if ( SMESH_TNodeXYZ( theNode1 ).SquareDistance( theNode3 ) >
2548 SMESH_TNodeXYZ( theNode2 ).SquareDistance( theNode4 ) )
2550 face = myHelper->AddFace(theNode2, theNode4 , theNode1);
2551 if (face) theMeshDS->SetMeshElementOnShape(face, theFaceID);
2552 face = myHelper->AddFace(theNode2, theNode3, theNode4);
2553 if (face) theMeshDS->SetMeshElementOnShape(face, theFaceID);
2557 face = myHelper->AddFace(theNode1, theNode2 ,theNode3);
2558 if (face) theMeshDS->SetMeshElementOnShape(face, theFaceID);
2559 face = myHelper->AddFace(theNode1, theNode3, theNode4);
2560 if (face) theMeshDS->SetMeshElementOnShape(face, theFaceID);
2566 enum uvPos { UV_A0, UV_A1, UV_A2, UV_A3, UV_B, UV_R, UV_T, UV_L, UV_SIZE };
2568 inline SMDS_MeshNode* makeNode( UVPtStruct & uvPt,
2570 FaceQuadStruct::Ptr& quad,
2572 SMESH_MesherHelper* helper,
2573 Handle(Geom_Surface) S)
2575 const vector<UVPtStruct>& uv_eb = quad->side[QUAD_BOTTOM_SIDE].GetUVPtStruct();
2576 const vector<UVPtStruct>& uv_et = quad->side[QUAD_TOP_SIDE ].GetUVPtStruct();
2577 double rBot = ( uv_eb.size() - 1 ) * uvPt.normParam;
2578 double rTop = ( uv_et.size() - 1 ) * uvPt.normParam;
2579 int iBot = int( rBot );
2580 int iTop = int( rTop );
2581 double xBot = uv_eb[ iBot ].normParam + ( rBot - iBot ) * ( uv_eb[ iBot+1 ].normParam - uv_eb[ iBot ].normParam );
2582 double xTop = uv_et[ iTop ].normParam + ( rTop - iTop ) * ( uv_et[ iTop+1 ].normParam - uv_et[ iTop ].normParam );
2583 double x = xBot + y * ( xTop - xBot );
2585 gp_UV uv = calcUV(/*x,y=*/x, y,
2586 /*a0,...=*/UVs[UV_A0], UVs[UV_A1], UVs[UV_A2], UVs[UV_A3],
2587 /*p0=*/quad->side[QUAD_BOTTOM_SIDE].grid->Value2d( x ).XY(),
2589 /*p2=*/quad->side[QUAD_TOP_SIDE ].grid->Value2d( x ).XY(),
2590 /*p3=*/UVs[ UV_L ]);
2591 gp_Pnt P = S->Value( uv.X(), uv.Y() );
2594 return helper->AddNode(P.X(), P.Y(), P.Z(), 0, uv.X(), uv.Y() );
2597 void reduce42( const vector<UVPtStruct>& curr_base,
2598 vector<UVPtStruct>& next_base,
2600 int & next_base_len,
2601 FaceQuadStruct::Ptr& quad,
2604 SMESH_MesherHelper* helper,
2605 Handle(Geom_Surface)& S)
2607 // add one "HH": nodes a,b,c,d,e and faces 1,2,3,4,5,6
2609 // .-----a-----b i + 1
2620 const SMDS_MeshNode*& Na = next_base[ ++next_base_len ].node;
2622 Na = makeNode( next_base[ next_base_len ], y, quad, UVs, helper, S );
2625 const SMDS_MeshNode*& Nb = next_base[ ++next_base_len ].node;
2627 Nb = makeNode( next_base[ next_base_len ], y, quad, UVs, helper, S );
2630 double u = (curr_base[j + 2].u + next_base[next_base_len - 2].u) / 2.0;
2631 double v = (curr_base[j + 2].v + next_base[next_base_len - 2].v) / 2.0;
2632 gp_Pnt P = S->Value(u,v);
2633 SMDS_MeshNode* Nc = helper->AddNode(P.X(), P.Y(), P.Z(), 0, u, v);
2636 u = (curr_base[j + 2].u + next_base[next_base_len - 1].u) / 2.0;
2637 v = (curr_base[j + 2].v + next_base[next_base_len - 1].v) / 2.0;
2639 SMDS_MeshNode* Nd = helper->AddNode(P.X(), P.Y(), P.Z(), 0, u, v);
2642 u = (curr_base[j + 2].u + next_base[next_base_len].u) / 2.0;
2643 v = (curr_base[j + 2].v + next_base[next_base_len].v) / 2.0;
2645 SMDS_MeshNode* Ne = helper->AddNode(P.X(), P.Y(), P.Z(), 0, u, v);
2648 helper->AddFace(curr_base[j + 0].node,
2649 curr_base[j + 1].node, Nc,
2650 next_base[next_base_len - 2].node);
2652 helper->AddFace(curr_base[j + 1].node,
2653 curr_base[j + 2].node, Nd, Nc);
2655 helper->AddFace(curr_base[j + 2].node,
2656 curr_base[j + 3].node, Ne, Nd);
2658 helper->AddFace(curr_base[j + 3].node,
2659 curr_base[j + 4].node, Nb, Ne);
2661 helper->AddFace(Nc, Nd, Na, next_base[next_base_len - 2].node);
2663 helper->AddFace(Nd, Ne, Nb, Na);
2666 void reduce31( const vector<UVPtStruct>& curr_base,
2667 vector<UVPtStruct>& next_base,
2669 int & next_base_len,
2670 FaceQuadStruct::Ptr& quad,
2673 SMESH_MesherHelper* helper,
2674 Handle(Geom_Surface)& S)
2676 // add one "H": nodes b,c,e and faces 1,2,4,5
2678 // .---------b i + 1
2689 const SMDS_MeshNode*& Nb = next_base[ ++next_base_len ].node;
2691 Nb = makeNode( next_base[ next_base_len ], y, quad, UVs, helper, S );
2694 double u1 = (curr_base[ j ].u + next_base[ next_base_len-1 ].u ) / 2.0;
2695 double u2 = (curr_base[ j+3 ].u + next_base[ next_base_len ].u ) / 2.0;
2696 double u3 = (u2 - u1) / 3.0;
2698 double v1 = (curr_base[ j ].v + next_base[ next_base_len-1 ].v ) / 2.0;
2699 double v2 = (curr_base[ j+3 ].v + next_base[ next_base_len ].v ) / 2.0;
2700 double v3 = (v2 - v1) / 3.0;
2704 gp_Pnt P = S->Value(u,v);
2705 SMDS_MeshNode* Nc = helper->AddNode( P.X(), P.Y(), P.Z(), 0, u, v );
2710 SMDS_MeshNode* Ne = helper->AddNode( P.X(), P.Y(), P.Z(), 0, u, v );
2714 helper->AddFace( curr_base[ j + 0 ].node,
2715 curr_base[ j + 1 ].node,
2717 next_base[ next_base_len - 1 ].node);
2719 helper->AddFace( curr_base[ j + 1 ].node,
2720 curr_base[ j + 2 ].node, Ne, Nc);
2722 helper->AddFace( curr_base[ j + 2 ].node,
2723 curr_base[ j + 3 ].node, Nb, Ne);
2725 helper->AddFace(Nc, Ne, Nb,
2726 next_base[ next_base_len - 1 ].node);
2729 typedef void (* PReduceFunction) ( const vector<UVPtStruct>& curr_base,
2730 vector<UVPtStruct>& next_base,
2732 int & next_base_len,
2733 FaceQuadStruct::Ptr & quad,
2736 SMESH_MesherHelper* helper,
2737 Handle(Geom_Surface)& S);
2741 //=======================================================================
2743 * Implementation of Reduced algorithm (meshing with quadrangles only)
2745 //=======================================================================
2747 bool StdMeshers_Quadrangle_2D::computeReduced (SMESH_Mesh & aMesh,
2748 const TopoDS_Face& aFace,
2749 FaceQuadStruct::Ptr quad)
2751 SMESHDS_Mesh * meshDS = aMesh.GetMeshDS();
2752 Handle(Geom_Surface) S = BRep_Tool::Surface(aFace);
2753 int i,j,geomFaceID = meshDS->ShapeToIndex(aFace);
2755 int nb = quad->side[0].NbPoints(); // bottom
2756 int nr = quad->side[1].NbPoints(); // right
2757 int nt = quad->side[2].NbPoints(); // top
2758 int nl = quad->side[3].NbPoints(); // left
2760 // Simple Reduce 10->8->6->4 (3 steps) Multiple Reduce 10->4 (1 step)
2762 // .-----.-----.-----.-----. .-----.-----.-----.-----.
2763 // | / \ | / \ | | / \ | / \ |
2764 // | / .--.--. \ | | / \ | / \ |
2765 // | / / | \ \ | | / .----.----. \ |
2766 // .---.---.---.---.---.---. | / / \ | / \ \ |
2767 // | / / \ | / \ \ | | / / \ | / \ \ |
2768 // | / / .-.-. \ \ | | / / .---.---. \ \ |
2769 // | / / / | \ \ \ | | / / / \ | / \ \ \ |
2770 // .--.--.--.--.--.--.--.--. | / / / \ | / \ \ \ |
2771 // | / / / \ | / \ \ \ | | / / / .-.-. \ \ \ |
2772 // | / / / .-.-. \ \ \ | | / / / / | \ \ \ \ |
2773 // | / / / / | \ \ \ \ | | / / / / | \ \ \ \ |
2774 // .-.-.-.--.--.--.--.-.-.-. .-.-.-.--.--.--.--.-.-.-.
2776 bool MultipleReduce = false;
2788 else if (nb == nt) {
2789 nr1 = nb; // and == nt
2803 // number of rows and columns
2804 int nrows = nr1 - 1;
2805 int ncol_top = nt1 - 1;
2806 int ncol_bot = nb1 - 1;
2807 // number of rows needed to reduce ncol_bot to ncol_top using simple 3->1 "tree" (see below)
2809 int( ceil( log( double(ncol_bot) / ncol_top) / log( 3.))); // = log x base 3
2810 if ( nrows < nrows_tree31 )
2812 MultipleReduce = true;
2813 error( COMPERR_WARNING,
2814 SMESH_Comment("To use 'Reduced' transition, "
2815 "number of face rows should be at least ")
2816 << nrows_tree31 << ". Actual number of face rows is " << nrows << ". "
2817 "'Quadrangle preference (reversed)' transion has been used.");
2821 if (MultipleReduce) { // == computeQuadPref QUAD_QUADRANGLE_PREF_REVERSED
2822 //==================================================
2823 int dh = abs(nb-nt);
2824 int dv = abs(nr-nl);
2828 // it is a base case => not shift quad but may be replacement is need
2832 // we have to shift quad on 2
2838 // we have to shift quad on 1
2842 // we have to shift quad on 3
2847 nb = quad->side[0].NbPoints();
2848 nr = quad->side[1].NbPoints();
2849 nt = quad->side[2].NbPoints();
2850 nl = quad->side[3].NbPoints();
2853 int nbh = Max(nb,nt);
2854 int nbv = Max(nr,nl);
2867 const vector<UVPtStruct>& uv_eb = quad->side[0].GetUVPtStruct(true,0);
2868 const vector<UVPtStruct>& uv_er = quad->side[1].GetUVPtStruct(false,1);
2869 const vector<UVPtStruct>& uv_et = quad->side[2].GetUVPtStruct(true,1);
2870 const vector<UVPtStruct>& uv_el = quad->side[3].GetUVPtStruct(false,0);
2872 if (uv_eb.size() != nb || uv_er.size() != nr || uv_et.size() != nt || uv_el.size() != nl)
2873 return error(COMPERR_BAD_INPUT_MESH);
2875 // arrays for normalized params
2876 TColStd_SequenceOfReal npb, npr, npt, npl;
2877 for (j = 0; j < nb; j++) {
2878 npb.Append(uv_eb[j].normParam);
2880 for (i = 0; i < nr; i++) {
2881 npr.Append(uv_er[i].normParam);
2883 for (j = 0; j < nt; j++) {
2884 npt.Append(uv_et[j].normParam);
2886 for (i = 0; i < nl; i++) {
2887 npl.Append(uv_el[i].normParam);
2891 // orientation of face and 3 main domain for future faces
2897 // left | | | | rigth
2904 // add some params to right and left after the first param
2907 double dpr = (npr.Value(2) - npr.Value(1))/(dr+1);
2908 for (i=1; i<=dr; i++) {
2909 npr.InsertAfter(1,npr.Value(2)-dpr);
2913 dpr = (npl.Value(2) - npl.Value(1))/(dl+1);
2914 for (i=1; i<=dl; i++) {
2915 npl.InsertAfter(1,npl.Value(2)-dpr);
2918 gp_XY a0 (uv_eb.front().u, uv_eb.front().v);
2919 gp_XY a1 (uv_eb.back().u, uv_eb.back().v);
2920 gp_XY a2 (uv_et.back().u, uv_et.back().v);
2921 gp_XY a3 (uv_et.front().u, uv_et.front().v);
2923 int nnn = Min(nr,nl);
2924 // auxilary sequence of XY for creation of nodes
2925 // in the bottom part of central domain
2926 // it's length must be == nbv-nnn-1