1 // Copyright (C) 2007-2012 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 // File : StdMeshers_Quadrangle_2D.cxx
24 // Author : Paul RASCLE, EDF
27 #include "StdMeshers_Quadrangle_2D.hxx"
29 #include "SMDS_EdgePosition.hxx"
30 #include "SMDS_FacePosition.hxx"
31 #include "SMDS_MeshElement.hxx"
32 #include "SMDS_MeshNode.hxx"
33 #include "SMESH_Block.hxx"
34 #include "SMESH_Comment.hxx"
35 #include "SMESH_Gen.hxx"
36 #include "SMESH_Mesh.hxx"
37 #include "SMESH_MesherHelper.hxx"
38 #include "SMESH_subMesh.hxx"
39 #include "StdMeshers_FaceSide.hxx"
40 #include "StdMeshers_QuadrangleParams.hxx"
41 #include "StdMeshers_ViscousLayers2D.hxx"
43 #include <BRep_Tool.hxx>
44 #include <Geom_Surface.hxx>
45 #include <NCollection_DefineArray2.hxx>
46 #include <Precision.hxx>
47 #include <TColStd_SequenceOfReal.hxx>
48 #include <TColStd_SequenceOfInteger.hxx>
49 #include <TColgp_SequenceOfXY.hxx>
51 #include <TopExp_Explorer.hxx>
52 #include <TopTools_ListIteratorOfListOfShape.hxx>
53 #include <TopTools_MapOfShape.hxx>
56 #include "utilities.h"
57 #include "Utils_ExceptHandlers.hxx"
59 #ifndef StdMeshers_Array2OfNode_HeaderFile
60 #define StdMeshers_Array2OfNode_HeaderFile
61 typedef const SMDS_MeshNode* SMDS_MeshNodePtr;
62 DEFINE_BASECOLLECTION (StdMeshers_BaseCollectionNodePtr, SMDS_MeshNodePtr)
63 DEFINE_ARRAY2(StdMeshers_Array2OfNode,
64 StdMeshers_BaseCollectionNodePtr, SMDS_MeshNodePtr)
70 typedef SMESH_Comment TComm;
72 //=============================================================================
76 //=============================================================================
78 StdMeshers_Quadrangle_2D::StdMeshers_Quadrangle_2D (int hypId, int studyId,
80 : SMESH_2D_Algo(hypId, studyId, gen),
83 MESSAGE("StdMeshers_Quadrangle_2D::StdMeshers_Quadrangle_2D");
84 _name = "Quadrangle_2D";
85 _shapeType = (1 << TopAbs_FACE);
86 _compatibleHypothesis.push_back("QuadrangleParams");
87 _compatibleHypothesis.push_back("QuadranglePreference");
88 _compatibleHypothesis.push_back("TrianglePreference");
89 _compatibleHypothesis.push_back("ViscousLayers2D");
92 //=============================================================================
96 //=============================================================================
98 StdMeshers_Quadrangle_2D::~StdMeshers_Quadrangle_2D()
100 MESSAGE("StdMeshers_Quadrangle_2D::~StdMeshers_Quadrangle_2D");
103 //=============================================================================
107 //=============================================================================
109 bool StdMeshers_Quadrangle_2D::CheckHypothesis
111 const TopoDS_Shape& aShape,
112 SMESH_Hypothesis::Hypothesis_Status& aStatus)
115 aStatus = SMESH_Hypothesis::HYP_OK;
117 const list <const SMESHDS_Hypothesis * >& hyps =
118 GetUsedHypothesis(aMesh, aShape, false);
119 const SMESHDS_Hypothesis * aHyp = 0;
122 myQuadType = QUAD_STANDARD;
123 myQuadranglePreference = false;
124 myTrianglePreference = false;
126 bool isFirstParams = true;
128 // First assigned hypothesis (if any) is processed now
129 if (hyps.size() > 0) {
131 if (strcmp("QuadrangleParams", aHyp->GetName()) == 0) {
132 const StdMeshers_QuadrangleParams* aHyp1 =
133 (const StdMeshers_QuadrangleParams*)aHyp;
134 myTriaVertexID = aHyp1->GetTriaVertex();
135 myQuadType = aHyp1->GetQuadType();
136 if (myQuadType == QUAD_QUADRANGLE_PREF ||
137 myQuadType == QUAD_QUADRANGLE_PREF_REVERSED)
138 myQuadranglePreference = true;
139 else if (myQuadType == QUAD_TRIANGLE_PREF)
140 myTrianglePreference = true;
142 else if (strcmp("QuadranglePreference", aHyp->GetName()) == 0) {
143 isFirstParams = false;
144 myQuadranglePreference = true;
146 else if (strcmp("TrianglePreference", aHyp->GetName()) == 0){
147 isFirstParams = false;
148 myTrianglePreference = true;
151 isFirstParams = false;
155 // Second(last) assigned hypothesis (if any) is processed now
156 if (hyps.size() > 1) {
159 if (strcmp("QuadranglePreference", aHyp->GetName()) == 0) {
160 myQuadranglePreference = true;
161 myTrianglePreference = false;
162 myQuadType = QUAD_STANDARD;
164 else if (strcmp("TrianglePreference", aHyp->GetName()) == 0){
165 myQuadranglePreference = false;
166 myTrianglePreference = true;
167 myQuadType = QUAD_STANDARD;
171 const StdMeshers_QuadrangleParams* aHyp2 =
172 (const StdMeshers_QuadrangleParams*)aHyp;
173 myTriaVertexID = aHyp2->GetTriaVertex();
175 if (!myQuadranglePreference && !myTrianglePreference) { // priority of hypos
176 myQuadType = aHyp2->GetQuadType();
177 if (myQuadType == QUAD_QUADRANGLE_PREF ||
178 myQuadType == QUAD_QUADRANGLE_PREF_REVERSED)
179 myQuadranglePreference = true;
180 else if (myQuadType == QUAD_TRIANGLE_PREF)
181 myTrianglePreference = true;
189 //=============================================================================
193 //=============================================================================
195 bool StdMeshers_Quadrangle_2D::Compute (SMESH_Mesh& aMesh,
196 const TopoDS_Shape& aShape)
198 const TopoDS_Face& F = TopoDS::Face(aShape);
199 Handle(Geom_Surface) S = BRep_Tool::Surface(F);
201 SMESHDS_Mesh * meshDS = aMesh.GetMeshDS();
202 aMesh.GetSubMesh(aShape);
204 SMESH_MesherHelper helper (aMesh);
207 myProxyMesh = StdMeshers_ViscousLayers2D::Compute( aMesh, F );
211 _quadraticMesh = myHelper->IsQuadraticSubMesh(aShape);
212 myNeedSmooth = false;
214 FaceQuadStruct *quad = CheckNbEdges(aMesh, aShape);
215 std::auto_ptr<FaceQuadStruct> quadDeleter (quad); // to delete quad at exit from Compute()
219 if (myQuadranglePreference) {
220 int n1 = quad->side[0]->NbPoints();
221 int n2 = quad->side[1]->NbPoints();
222 int n3 = quad->side[2]->NbPoints();
223 int n4 = quad->side[3]->NbPoints();
224 int nfull = n1+n2+n3+n4;
227 if (nfull == ntmp && ((n1 != n3) || (n2 != n4))) {
228 // special path for using only quandrangle faces
229 bool ok = ComputeQuadPref(aMesh, aShape, quad);
230 if ( ok && myNeedSmooth )
235 else if (myQuadType == QUAD_REDUCED) {
236 int n1 = quad->side[0]->NbPoints();
237 int n2 = quad->side[1]->NbPoints();
238 int n3 = quad->side[2]->NbPoints();
239 int n4 = quad->side[3]->NbPoints();
242 int n13tmp = n13/2; n13tmp = n13tmp*2;
243 int n24tmp = n24/2; n24tmp = n24tmp*2;
244 if ((n1 == n3 && n2 != n4 && n24tmp == n24) ||
245 (n2 == n4 && n1 != n3 && n13tmp == n13)) {
246 bool ok = ComputeReduced(aMesh, aShape, quad);
247 if ( ok && myNeedSmooth )
253 // set normalized grid on unit square in parametric domain
255 if (!SetNormalizedGrid(aMesh, aShape, quad))
258 // --- compute 3D values on points, store points & quadrangles
260 int nbdown = quad->side[0]->NbPoints();
261 int nbup = quad->side[2]->NbPoints();
263 int nbright = quad->side[1]->NbPoints();
264 int nbleft = quad->side[3]->NbPoints();
266 int nbhoriz = Min(nbdown, nbup);
267 int nbvertic = Min(nbright, nbleft);
269 // internal mesh nodes
270 int i, j, geomFaceID = meshDS->ShapeToIndex(F);
271 for (i = 1; i < nbhoriz - 1; i++) {
272 for (j = 1; j < nbvertic - 1; j++) {
273 int ij = j * nbhoriz + i;
274 double u = quad->uv_grid[ij].u;
275 double v = quad->uv_grid[ij].v;
276 gp_Pnt P = S->Value(u, v);
277 SMDS_MeshNode * node = meshDS->AddNode(P.X(), P.Y(), P.Z());
278 meshDS->SetNodeOnFace(node, geomFaceID, u, v);
279 quad->uv_grid[ij].node = node;
286 // --.--.--.--.--.-- nbvertic
292 // ---.----.----.--- 0
293 // 0 > > > > > > > > nbhoriz
299 int iup = nbhoriz - 1;
300 if (quad->isEdgeOut[3]) { ilow++; } else { if (quad->isEdgeOut[1]) iup--; }
303 int jup = nbvertic - 1;
304 if (quad->isEdgeOut[0]) { jlow++; } else { if (quad->isEdgeOut[2]) jup--; }
306 // regular quadrangles
307 for (i = ilow; i < iup; i++) {
308 for (j = jlow; j < jup; j++) {
309 const SMDS_MeshNode *a, *b, *c, *d;
310 a = quad->uv_grid[j * nbhoriz + i ].node;
311 b = quad->uv_grid[j * nbhoriz + i + 1].node;
312 c = quad->uv_grid[(j + 1) * nbhoriz + i + 1].node;
313 d = quad->uv_grid[(j + 1) * nbhoriz + i ].node;
314 SMDS_MeshFace* face = myHelper->AddFace(a, b, c, d);
316 meshDS->SetMeshElementOnShape(face, geomFaceID);
321 const vector<UVPtStruct>& uv_e0 = quad->side[0]->GetUVPtStruct(true,0);
322 const vector<UVPtStruct>& uv_e1 = quad->side[1]->GetUVPtStruct(false,1);
323 const vector<UVPtStruct>& uv_e2 = quad->side[2]->GetUVPtStruct(true,1);
324 const vector<UVPtStruct>& uv_e3 = quad->side[3]->GetUVPtStruct(false,0);
326 if (uv_e0.empty() || uv_e1.empty() || uv_e2.empty() || uv_e3.empty())
327 return error(COMPERR_BAD_INPUT_MESH);
329 double eps = Precision::Confusion();
331 // Boundary quadrangles
333 if (quad->isEdgeOut[0]) {
336 // |___|___|___|___|___|___|
338 // |___|___|___|___|___|___|
340 // |___|___|___|___|___|___| __ first row of the regular grid
341 // . . . . . . . . . __ down edge nodes
343 // >->->->->->->->->->->->-> -- direction of processing
345 int g = 0; // number of last processed node in the regular grid
347 // number of last node of the down edge to be processed
348 int stop = nbdown - 1;
349 // if right edge is out, we will stop at a node, previous to the last one
350 if (quad->isEdgeOut[1]) stop--;
352 // for each node of the down edge find nearest node
353 // in the first row of the regular grid and link them
354 for (i = 0; i < stop; i++) {
355 const SMDS_MeshNode *a, *b, *c, *d;
357 b = uv_e0[i + 1].node;
358 gp_Pnt pb (b->X(), b->Y(), b->Z());
360 // find node c in the regular grid, which will be linked with node b
363 // right bound reached, link with the rightmost node
365 c = quad->uv_grid[nbhoriz + iup].node;
368 // find in the grid node c, nearest to the b
369 double mind = RealLast();
370 for (int k = g; k <= iup; k++) {
372 const SMDS_MeshNode *nk;
373 if (k < ilow) // this can be, if left edge is out
374 nk = uv_e3[1].node; // get node from the left edge
376 nk = quad->uv_grid[nbhoriz + k].node; // get one of middle nodes
378 gp_Pnt pnk (nk->X(), nk->Y(), nk->Z());
379 double dist = pb.Distance(pnk);
380 if (dist < mind - eps) {
390 if (near == g) { // make triangle
391 SMDS_MeshFace* face = myHelper->AddFace(a, b, c);
392 if (face) meshDS->SetMeshElementOnShape(face, geomFaceID);
394 else { // make quadrangle
398 d = quad->uv_grid[nbhoriz + near - 1].node;
399 //SMDS_MeshFace* face = meshDS->AddFace(a, b, c, d);
401 if (!myTrianglePreference){
402 SMDS_MeshFace* face = myHelper->AddFace(a, b, c, d);
403 if (face) meshDS->SetMeshElementOnShape(face, geomFaceID);
406 SplitQuad(meshDS, geomFaceID, a, b, c, d);
409 // if node d is not at position g - make additional triangles
411 for (int k = near - 1; k > g; k--) {
412 c = quad->uv_grid[nbhoriz + k].node;
416 d = quad->uv_grid[nbhoriz + k - 1].node;
417 SMDS_MeshFace* face = myHelper->AddFace(a, c, d);
418 if (face) meshDS->SetMeshElementOnShape(face, geomFaceID);
425 if (quad->isEdgeOut[2]) {
428 // <-<-<-<-<-<-<-<-<-<-<-<-< -- direction of processing
430 // . . . . . . . . . __ up edge nodes
431 // ___ ___ ___ ___ ___ ___ __ first row of the regular grid
433 // |___|___|___|___|___|___|
435 // |___|___|___|___|___|___|
438 int g = nbhoriz - 1; // last processed node in the regular grid
441 // if left edge is out, we will stop at a second node
442 if (quad->isEdgeOut[3]) stop++;
444 // for each node of the up edge find nearest node
445 // in the first row of the regular grid and link them
446 for (i = nbup - 1; i > stop; i--) {
447 const SMDS_MeshNode *a, *b, *c, *d;
449 b = uv_e2[i - 1].node;
450 gp_Pnt pb (b->X(), b->Y(), b->Z());
452 // find node c in the grid, which will be linked with node b
454 if (i == stop + 1) { // left bound reached, link with the leftmost node
455 c = quad->uv_grid[nbhoriz*(nbvertic - 2) + ilow].node;
458 // find node c in the grid, nearest to the b
459 double mind = RealLast();
460 for (int k = g; k >= ilow; k--) {
461 const SMDS_MeshNode *nk;
463 nk = uv_e1[nbright - 2].node;
465 nk = quad->uv_grid[nbhoriz*(nbvertic - 2) + k].node;
466 gp_Pnt pnk (nk->X(), nk->Y(), nk->Z());
467 double dist = pb.Distance(pnk);
468 if (dist < mind - eps) {
478 if (near == g) { // make triangle
479 SMDS_MeshFace* face = myHelper->AddFace(a, b, c);
480 if (face) meshDS->SetMeshElementOnShape(face, geomFaceID);
482 else { // make quadrangle
484 d = uv_e1[nbright - 2].node;
486 d = quad->uv_grid[nbhoriz*(nbvertic - 2) + near + 1].node;
487 //SMDS_MeshFace* face = meshDS->AddFace(a, b, c, d);
488 if (!myTrianglePreference){
489 SMDS_MeshFace* face = myHelper->AddFace(a, b, c, d);
490 if (face) meshDS->SetMeshElementOnShape(face, geomFaceID);
493 SplitQuad(meshDS, geomFaceID, a, b, c, d);
496 if (near + 1 < g) { // if d not is at g - make additional triangles
497 for (int k = near + 1; k < g; k++) {
498 c = quad->uv_grid[nbhoriz*(nbvertic - 2) + k].node;
500 d = uv_e1[nbright - 2].node;
502 d = quad->uv_grid[nbhoriz*(nbvertic - 2) + k + 1].node;
503 SMDS_MeshFace* face = myHelper->AddFace(a, c, d);
504 if (face) meshDS->SetMeshElementOnShape(face, geomFaceID);
513 // right or left boundary quadrangles
514 if (quad->isEdgeOut[1]) {
515 // MESSAGE("right edge is out");
516 int g = 0; // last processed node in the grid
517 int stop = nbright - 1;
518 if (quad->isEdgeOut[2]) stop--;
519 for (i = 0; i < stop; i++) {
520 const SMDS_MeshNode *a, *b, *c, *d;
522 b = uv_e1[i + 1].node;
523 gp_Pnt pb (b->X(), b->Y(), b->Z());
525 // find node c in the grid, nearest to the b
527 if (i == stop - 1) { // up bondary reached
528 c = quad->uv_grid[nbhoriz*(jup + 1) - 2].node;
531 double mind = RealLast();
532 for (int k = g; k <= jup; k++) {
533 const SMDS_MeshNode *nk;
535 nk = uv_e0[nbdown - 2].node;
537 nk = quad->uv_grid[nbhoriz*(k + 1) - 2].node;
538 gp_Pnt pnk (nk->X(), nk->Y(), nk->Z());
539 double dist = pb.Distance(pnk);
540 if (dist < mind - eps) {
550 if (near == g) { // make triangle
551 SMDS_MeshFace* face = myHelper->AddFace(a, b, c);
552 if (face) meshDS->SetMeshElementOnShape(face, geomFaceID);
554 else { // make quadrangle
556 d = uv_e0[nbdown - 2].node;
558 d = quad->uv_grid[nbhoriz*near - 2].node;
559 //SMDS_MeshFace* face = meshDS->AddFace(a, b, c, d);
561 if (!myTrianglePreference){
562 SMDS_MeshFace* face = myHelper->AddFace(a, b, c, d);
563 if (face) meshDS->SetMeshElementOnShape(face, geomFaceID);
566 SplitQuad(meshDS, geomFaceID, a, b, c, d);
569 if (near - 1 > g) { // if d not is at g - make additional triangles
570 for (int k = near - 1; k > g; k--) {
571 c = quad->uv_grid[nbhoriz*(k + 1) - 2].node;
573 d = uv_e0[nbdown - 2].node;
575 d = quad->uv_grid[nbhoriz*k - 2].node;
576 SMDS_MeshFace* face = myHelper->AddFace(a, c, d);
577 if (face) meshDS->SetMeshElementOnShape(face, geomFaceID);
584 if (quad->isEdgeOut[3]) {
585 // MESSAGE("left edge is out");
586 int g = nbvertic - 1; // last processed node in the grid
588 if (quad->isEdgeOut[0]) stop++;
589 for (i = nbleft - 1; i > stop; i--) {
590 const SMDS_MeshNode *a, *b, *c, *d;
592 b = uv_e3[i - 1].node;
593 gp_Pnt pb (b->X(), b->Y(), b->Z());
595 // find node c in the grid, nearest to the b
597 if (i == stop + 1) { // down bondary reached
598 c = quad->uv_grid[nbhoriz*jlow + 1].node;
601 double mind = RealLast();
602 for (int k = g; k >= jlow; k--) {
603 const SMDS_MeshNode *nk;
607 nk = quad->uv_grid[nbhoriz*k + 1].node;
608 gp_Pnt pnk (nk->X(), nk->Y(), nk->Z());
609 double dist = pb.Distance(pnk);
610 if (dist < mind - eps) {
620 if (near == g) { // make triangle
621 SMDS_MeshFace* face = myHelper->AddFace(a, b, c);
622 if (face) meshDS->SetMeshElementOnShape(face, geomFaceID);
624 else { // make quadrangle
628 d = quad->uv_grid[nbhoriz*(near + 1) + 1].node;
629 //SMDS_MeshFace* face = meshDS->AddFace(a, b, c, d);
630 if (!myTrianglePreference){
631 SMDS_MeshFace* face = myHelper->AddFace(a, b, c, d);
632 if (face) meshDS->SetMeshElementOnShape(face, geomFaceID);
635 SplitQuad(meshDS, geomFaceID, a, b, c, d);
638 if (near + 1 < g) { // if d not is at g - make additional triangles
639 for (int k = near + 1; k < g; k++) {
640 c = quad->uv_grid[nbhoriz*k + 1].node;
644 d = quad->uv_grid[nbhoriz*(k + 1) + 1].node;
645 SMDS_MeshFace* face = myHelper->AddFace(a, c, d);
646 if (face) meshDS->SetMeshElementOnShape(face, geomFaceID);
663 //=============================================================================
667 //=============================================================================
669 bool StdMeshers_Quadrangle_2D::Evaluate(SMESH_Mesh& aMesh,
670 const TopoDS_Shape& aShape,
671 MapShapeNbElems& aResMap)
674 aMesh.GetSubMesh(aShape);
676 std::vector<int> aNbNodes(4);
677 bool IsQuadratic = false;
678 if (!CheckNbEdgesForEvaluate(aMesh, aShape, aResMap, aNbNodes, IsQuadratic)) {
679 std::vector<int> aResVec(SMDSEntity_Last);
680 for (int i=SMDSEntity_Node; i<SMDSEntity_Last; i++) aResVec[i] = 0;
681 SMESH_subMesh * sm = aMesh.GetSubMesh(aShape);
682 aResMap.insert(std::make_pair(sm,aResVec));
683 SMESH_ComputeErrorPtr& smError = sm->GetComputeError();
684 smError.reset(new SMESH_ComputeError(COMPERR_ALGO_FAILED,"Submesh can not be evaluated",this));
688 if (myQuadranglePreference) {
689 int n1 = aNbNodes[0];
690 int n2 = aNbNodes[1];
691 int n3 = aNbNodes[2];
692 int n4 = aNbNodes[3];
693 int nfull = n1+n2+n3+n4;
696 if (nfull==ntmp && ((n1!=n3) || (n2!=n4))) {
697 // special path for using only quandrangle faces
698 return EvaluateQuadPref(aMesh, aShape, aNbNodes, aResMap, IsQuadratic);
703 int nbdown = aNbNodes[0];
704 int nbup = aNbNodes[2];
706 int nbright = aNbNodes[1];
707 int nbleft = aNbNodes[3];
709 int nbhoriz = Min(nbdown, nbup);
710 int nbvertic = Min(nbright, nbleft);
712 int dh = Max(nbdown, nbup) - nbhoriz;
713 int dv = Max(nbright, nbleft) - nbvertic;
720 int nbNodes = (nbhoriz-2)*(nbvertic-2);
721 //int nbFaces3 = dh + dv + kdh*(nbvertic-1)*2 + kdv*(nbhoriz-1)*2;
722 int nbFaces3 = dh + dv;
723 //if (kdh==1 && kdv==1) nbFaces3 -= 2;
724 //if (dh>0 && dv>0) nbFaces3 -= 2;
725 //int nbFaces4 = (nbhoriz-1-kdh)*(nbvertic-1-kdv);
726 int nbFaces4 = (nbhoriz-1)*(nbvertic-1);
728 std::vector<int> aVec(SMDSEntity_Last);
729 for (int i=SMDSEntity_Node; i<SMDSEntity_Last; i++) aVec[i] = 0;
731 aVec[SMDSEntity_Quad_Triangle] = nbFaces3;
732 aVec[SMDSEntity_Quad_Quadrangle] = nbFaces4;
733 int nbbndedges = nbdown + nbup + nbright + nbleft -4;
734 int nbintedges = (nbFaces4*4 + nbFaces3*3 - nbbndedges) / 2;
735 aVec[SMDSEntity_Node] = nbNodes + nbintedges;
736 if (aNbNodes.size()==5) {
737 aVec[SMDSEntity_Quad_Triangle] = nbFaces3 + aNbNodes[3] -1;
738 aVec[SMDSEntity_Quad_Quadrangle] = nbFaces4 - aNbNodes[3] +1;
742 aVec[SMDSEntity_Node] = nbNodes;
743 aVec[SMDSEntity_Triangle] = nbFaces3;
744 aVec[SMDSEntity_Quadrangle] = nbFaces4;
745 if (aNbNodes.size()==5) {
746 aVec[SMDSEntity_Triangle] = nbFaces3 + aNbNodes[3] - 1;
747 aVec[SMDSEntity_Quadrangle] = nbFaces4 - aNbNodes[3] + 1;
750 SMESH_subMesh * sm = aMesh.GetSubMesh(aShape);
751 aResMap.insert(std::make_pair(sm,aVec));
757 //================================================================================
759 * \brief Return true if only two given edges meat at their common vertex
761 //================================================================================
763 static bool twoEdgesMeatAtVertex(const TopoDS_Edge& e1,
764 const TopoDS_Edge& e2,
768 if (!TopExp::CommonVertex(e1, e2, v))
770 TopTools_ListIteratorOfListOfShape ancestIt(mesh.GetAncestors(v));
771 for (; ancestIt.More() ; ancestIt.Next())
772 if (ancestIt.Value().ShapeType() == TopAbs_EDGE)
773 if (!e1.IsSame(ancestIt.Value()) && !e2.IsSame(ancestIt.Value()))
778 //=============================================================================
782 //=============================================================================
784 FaceQuadStruct* StdMeshers_Quadrangle_2D::CheckNbEdges(SMESH_Mesh & aMesh,
785 const TopoDS_Shape & aShape)
786 //throw(SALOME_Exception)
788 TopoDS_Face F = TopoDS::Face(aShape);
789 if ( F.Orientation() >= TopAbs_INTERNAL ) F.Orientation( TopAbs_FORWARD );
790 const bool ignoreMediumNodes = _quadraticMesh;
792 // verify 1 wire only, with 4 edges
794 list< TopoDS_Edge > edges;
795 list< int > nbEdgesInWire;
796 int nbWire = SMESH_Block::GetOrderedEdges (F, V, edges, nbEdgesInWire);
798 error(COMPERR_BAD_SHAPE, TComm("Wrong number of wires: ") << nbWire);
801 FaceQuadStruct* quad = new FaceQuadStruct;
803 quad->side.reserve(nbEdgesInWire.front());
807 list< TopoDS_Edge >::iterator edgeIt = edges.begin();
808 if (nbEdgesInWire.front() == 3) // exactly 3 edges
810 SMESH_Comment comment;
811 SMESHDS_Mesh* meshDS = aMesh.GetMeshDS();
812 if (myTriaVertexID == -1)
814 comment << "No Base vertex parameter provided for a trilateral geometrical face";
818 TopoDS_Vertex V = TopoDS::Vertex(meshDS->IndexToShape(myTriaVertexID));
820 TopoDS_Edge E1,E2,E3;
821 for (; edgeIt != edges.end(); ++edgeIt) {
822 TopoDS_Edge E = *edgeIt;
823 TopoDS_Vertex VF, VL;
824 TopExp::Vertices(E, VF, VL, true);
827 else if (VL.IsSame(V))
832 if (!E1.IsNull() && !E2.IsNull() && !E3.IsNull())
834 if ( myProxyMesh->GetProxySubMesh( E1 ) ||
835 myProxyMesh->GetProxySubMesh( E2 ) ||
836 myProxyMesh->GetProxySubMesh( E3 ) )
838 quad->side.push_back(new StdMeshers_FaceSide(F, E1, &aMesh, true,
839 ignoreMediumNodes, myProxyMesh));
840 quad->side.push_back(new StdMeshers_FaceSide(F, E2, &aMesh, true,
841 ignoreMediumNodes, myProxyMesh));
842 quad->side.push_back(new StdMeshers_FaceSide(F, E3, &aMesh, false,
843 ignoreMediumNodes, myProxyMesh));
844 const vector<UVPtStruct>& UVPSleft = quad->side[0]->GetUVPtStruct(true,0);
845 /* vector<UVPtStruct>& UVPStop = */quad->side[1]->GetUVPtStruct(false,1);
846 /* vector<UVPtStruct>& UVPSright = */quad->side[2]->GetUVPtStruct(true,1);
847 const SMDS_MeshNode* aNode = UVPSleft[0].node;
848 gp_Pnt2d aPnt2d(UVPSleft[0].u, UVPSleft[0].v);
849 quad->side.push_back(new StdMeshers_FaceSide(aNode, aPnt2d, quad->side[1]));
853 comment << "Invalid Base vertex parameter: " << myTriaVertexID << " is not among [";
854 TopTools_MapOfShape vMap;
855 for (TopExp_Explorer v(aShape, TopAbs_VERTEX); v.More(); v.Next())
856 if (vMap.Add(v.Current()))
857 comment << meshDS->ShapeToIndex(v.Current()) << (vMap.Extent()==3 ? "]" : ", ");
863 else if (nbEdgesInWire.front() == 4) // exactly 4 edges
865 for (; edgeIt != edges.end(); ++edgeIt, nbSides++)
866 quad->side.push_back(new StdMeshers_FaceSide(F, *edgeIt, &aMesh, nbSides < TOP_SIDE,
867 ignoreMediumNodes, myProxyMesh));
869 else if (nbEdgesInWire.front() > 4) // more than 4 edges - try to unite some
871 list< TopoDS_Edge > sideEdges;
872 vector< int > degenSides;
873 while (!edges.empty()) {
875 sideEdges.splice(sideEdges.end(), edges, edges.begin()); // edges.front() -> sideEdges.end()
876 bool sameSide = true;
877 while (!edges.empty() && sameSide) {
878 sameSide = SMESH_Algo::IsContinuous(sideEdges.back(), edges.front());
880 sideEdges.splice(sideEdges.end(), edges, edges.begin());
882 if (nbSides == 0) { // go backward from the first edge
884 while (!edges.empty() && sameSide) {
885 sameSide = SMESH_Algo::IsContinuous(sideEdges.front(), edges.back());
887 sideEdges.splice(sideEdges.begin(), edges, --edges.end());
890 if ( sideEdges.size() == 1 && BRep_Tool::Degenerated( sideEdges.front() ))
891 degenSides.push_back( nbSides );
893 quad->side.push_back(new StdMeshers_FaceSide(F, sideEdges, &aMesh, nbSides < TOP_SIDE,
894 ignoreMediumNodes, myProxyMesh));
897 if ( !degenSides.empty() && nbSides - degenSides.size() == 4 )
900 for ( unsigned i = TOP_SIDE; i < quad->side.size(); ++i )
901 quad->side[i]->Reverse();
903 for ( int i = degenSides.size()-1; i > -1; --i )
905 StdMeshers_FaceSide* degenSide = quad->side[ degenSides[ i ]];
907 quad->side.erase( quad->side.begin() + degenSides[ i ] );
909 for ( unsigned i = TOP_SIDE; i < quad->side.size(); ++i )
910 quad->side[i]->Reverse();
912 nbSides -= degenSides.size();
914 // issue 20222. Try to unite only edges shared by two same faces
916 // delete found sides
917 { FaceQuadStruct cleaner(*quad); }
919 quad->side.reserve(nbEdgesInWire.front());
922 SMESH_Block::GetOrderedEdges (F, V, edges, nbEdgesInWire);
923 while (!edges.empty()) {
925 sideEdges.splice(sideEdges.end(), edges, edges.begin());
926 bool sameSide = true;
927 while (!edges.empty() && sameSide) {
929 SMESH_Algo::IsContinuous(sideEdges.back(), edges.front()) &&
930 twoEdgesMeatAtVertex(sideEdges.back(), edges.front(), aMesh);
932 sideEdges.splice(sideEdges.end(), edges, edges.begin());
934 if (nbSides == 0) { // go backward from the first edge
936 while (!edges.empty() && sameSide) {
938 SMESH_Algo::IsContinuous(sideEdges.front(), edges.back()) &&
939 twoEdgesMeatAtVertex(sideEdges.front(), edges.back(), aMesh);
941 sideEdges.splice(sideEdges.begin(), edges, --edges.end());
944 quad->side.push_back(new StdMeshers_FaceSide(F, sideEdges, &aMesh,
946 ignoreMediumNodes, myProxyMesh));
953 MESSAGE ("StdMeshers_Quadrangle_2D. Edge IDs of " << nbSides << " sides:\n");
954 for (int i = 0; i < nbSides; ++i) {
956 for (int e = 0; e < quad->side[i]->NbEdges(); ++e)
957 MESSAGE (myHelper->GetMeshDS()->ShapeToIndex(quad->side[i]->Edge(e)) << " ");
963 nbSides = nbEdgesInWire.front();
964 error(COMPERR_BAD_SHAPE, TComm("Face must have 4 sides but not ") << nbSides);
973 //=============================================================================
977 //=============================================================================
979 bool StdMeshers_Quadrangle_2D::CheckNbEdgesForEvaluate(SMESH_Mesh& aMesh,
980 const TopoDS_Shape & aShape,
981 MapShapeNbElems& aResMap,
982 std::vector<int>& aNbNodes,
986 const TopoDS_Face & F = TopoDS::Face(aShape);
988 // verify 1 wire only, with 4 edges
990 list< TopoDS_Edge > edges;
991 list< int > nbEdgesInWire;
992 int nbWire = SMESH_Block::GetOrderedEdges (F, V, edges, nbEdgesInWire);
1000 list< TopoDS_Edge >::iterator edgeIt = edges.begin();
1001 SMESH_subMesh * sm = aMesh.GetSubMesh(*edgeIt);
1002 MapShapeNbElemsItr anIt = aResMap.find(sm);
1003 if (anIt==aResMap.end()) {
1006 std::vector<int> aVec = (*anIt).second;
1007 IsQuadratic = (aVec[SMDSEntity_Quad_Edge] > aVec[SMDSEntity_Edge]);
1008 if (nbEdgesInWire.front() == 3) { // exactly 3 edges
1009 if (myTriaVertexID>0) {
1010 SMESHDS_Mesh* meshDS = aMesh.GetMeshDS();
1011 TopoDS_Vertex V = TopoDS::Vertex(meshDS->IndexToShape(myTriaVertexID));
1013 TopoDS_Edge E1,E2,E3;
1014 for (; edgeIt != edges.end(); ++edgeIt) {
1015 TopoDS_Edge E = TopoDS::Edge(*edgeIt);
1016 TopoDS_Vertex VF, VL;
1017 TopExp::Vertices(E, VF, VL, true);
1020 else if (VL.IsSame(V))
1025 SMESH_subMesh * sm = aMesh.GetSubMesh(E1);
1026 MapShapeNbElemsItr anIt = aResMap.find(sm);
1027 if (anIt==aResMap.end()) return false;
1028 std::vector<int> aVec = (*anIt).second;
1030 aNbNodes[0] = (aVec[SMDSEntity_Node]-1)/2 + 2;
1032 aNbNodes[0] = aVec[SMDSEntity_Node] + 2;
1033 sm = aMesh.GetSubMesh(E2);
1034 anIt = aResMap.find(sm);
1035 if (anIt==aResMap.end()) return false;
1036 aVec = (*anIt).second;
1038 aNbNodes[1] = (aVec[SMDSEntity_Node]-1)/2 + 2;
1040 aNbNodes[1] = aVec[SMDSEntity_Node] + 2;
1041 sm = aMesh.GetSubMesh(E3);
1042 anIt = aResMap.find(sm);
1043 if (anIt==aResMap.end()) return false;
1044 aVec = (*anIt).second;
1046 aNbNodes[2] = (aVec[SMDSEntity_Node]-1)/2 + 2;
1048 aNbNodes[2] = aVec[SMDSEntity_Node] + 2;
1049 aNbNodes[3] = aNbNodes[1];
1055 if (nbEdgesInWire.front() == 4) { // exactly 4 edges
1056 for (; edgeIt != edges.end(); edgeIt++) {
1057 SMESH_subMesh * sm = aMesh.GetSubMesh(*edgeIt);
1058 MapShapeNbElemsItr anIt = aResMap.find(sm);
1059 if (anIt==aResMap.end()) {
1062 std::vector<int> aVec = (*anIt).second;
1064 aNbNodes[nbSides] = (aVec[SMDSEntity_Node]-1)/2 + 2;
1066 aNbNodes[nbSides] = aVec[SMDSEntity_Node] + 2;
1070 else if (nbEdgesInWire.front() > 4) { // more than 4 edges - try to unite some
1071 list< TopoDS_Edge > sideEdges;
1072 while (!edges.empty()) {
1074 sideEdges.splice(sideEdges.end(), edges, edges.begin()); // edges.front() -> sideEdges.end()
1075 bool sameSide = true;
1076 while (!edges.empty() && sameSide) {
1077 sameSide = SMESH_Algo::IsContinuous(sideEdges.back(), edges.front());
1079 sideEdges.splice(sideEdges.end(), edges, edges.begin());
1081 if (nbSides == 0) { // go backward from the first edge
1083 while (!edges.empty() && sameSide) {
1084 sameSide = SMESH_Algo::IsContinuous(sideEdges.front(), edges.back());
1086 sideEdges.splice(sideEdges.begin(), edges, --edges.end());
1089 list<TopoDS_Edge>::iterator ite = sideEdges.begin();
1090 aNbNodes[nbSides] = 1;
1091 for (; ite!=sideEdges.end(); ite++) {
1092 SMESH_subMesh * sm = aMesh.GetSubMesh(*ite);
1093 MapShapeNbElemsItr anIt = aResMap.find(sm);
1094 if (anIt==aResMap.end()) {
1097 std::vector<int> aVec = (*anIt).second;
1099 aNbNodes[nbSides] += (aVec[SMDSEntity_Node]-1)/2 + 1;
1101 aNbNodes[nbSides] += aVec[SMDSEntity_Node] + 1;
1105 // issue 20222. Try to unite only edges shared by two same faces
1108 SMESH_Block::GetOrderedEdges (F, V, edges, nbEdgesInWire);
1109 while (!edges.empty()) {
1111 sideEdges.splice(sideEdges.end(), edges, edges.begin());
1112 bool sameSide = true;
1113 while (!edges.empty() && sameSide) {
1115 SMESH_Algo::IsContinuous(sideEdges.back(), edges.front()) &&
1116 twoEdgesMeatAtVertex(sideEdges.back(), edges.front(), aMesh);
1118 sideEdges.splice(sideEdges.end(), edges, edges.begin());
1120 if (nbSides == 0) { // go backward from the first edge
1122 while (!edges.empty() && sameSide) {
1124 SMESH_Algo::IsContinuous(sideEdges.front(), edges.back()) &&
1125 twoEdgesMeatAtVertex(sideEdges.front(), edges.back(), aMesh);
1127 sideEdges.splice(sideEdges.begin(), edges, --edges.end());
1130 list<TopoDS_Edge>::iterator ite = sideEdges.begin();
1131 aNbNodes[nbSides] = 1;
1132 for (; ite!=sideEdges.end(); ite++) {
1133 SMESH_subMesh * sm = aMesh.GetSubMesh(*ite);
1134 MapShapeNbElemsItr anIt = aResMap.find(sm);
1135 if (anIt==aResMap.end()) {
1138 std::vector<int> aVec = (*anIt).second;
1140 aNbNodes[nbSides] += (aVec[SMDSEntity_Node]-1)/2 + 1;
1142 aNbNodes[nbSides] += aVec[SMDSEntity_Node] + 1;
1150 nbSides = nbEdgesInWire.front();
1151 error(COMPERR_BAD_SHAPE, TComm("Face must have 4 sides but not ") << nbSides);
1159 //=============================================================================
1163 //=============================================================================
1165 FaceQuadStruct *StdMeshers_Quadrangle_2D::CheckAnd2Dcompute
1166 (SMESH_Mesh & aMesh,
1167 const TopoDS_Shape & aShape,
1168 const bool CreateQuadratic) //throw(SALOME_Exception)
1170 _quadraticMesh = CreateQuadratic;
1172 FaceQuadStruct *quad = CheckNbEdges(aMesh, aShape);
1174 if (!quad) return 0;
1176 // set normalized grid on unit square in parametric domain
1177 bool stat = SetNormalizedGrid(aMesh, aShape, quad);
1179 if (quad) delete quad;
1186 //=============================================================================
1190 //=============================================================================
1192 faceQuadStruct::~faceQuadStruct()
1194 for (int i = 0; i < side.size(); i++) {
1195 if (side[i]) delete side[i];
1197 if (uv_grid) delete [] uv_grid;
1201 inline const vector<UVPtStruct>& GetUVPtStructIn(FaceQuadStruct* quad, int i, int nbSeg)
1203 bool isXConst = (i == BOTTOM_SIDE || i == TOP_SIDE);
1204 double constValue = (i == BOTTOM_SIDE || i == LEFT_SIDE) ? 0 : 1;
1206 quad->isEdgeOut[i] ?
1207 quad->side[i]->SimulateUVPtStruct(nbSeg,isXConst,constValue) :
1208 quad->side[i]->GetUVPtStruct(isXConst,constValue);
1210 inline gp_UV CalcUV(double x, double y,
1211 const gp_UV& a0,const gp_UV& a1,const gp_UV& a2,const gp_UV& a3,
1212 const gp_UV& p0,const gp_UV& p1,const gp_UV& p2,const gp_UV& p3)
1215 ((1 - y) * p0 + x * p1 + y * p2 + (1 - x) * p3 ) -
1216 ((1 - x) * (1 - y) * a0 + x * (1 - y) * a1 + x * y * a2 + (1 - x) * y * a3);
1220 //=============================================================================
1224 //=============================================================================
1226 bool StdMeshers_Quadrangle_2D::SetNormalizedGrid (SMESH_Mesh & aMesh,
1227 const TopoDS_Shape& aShape,
1228 FaceQuadStruct* & quad) //throw (SALOME_Exception)
1230 // Algorithme décrit dans "Génération automatique de maillages"
1231 // P.L. GEORGE, MASSON, § 6.4.1 p. 84-85
1232 // traitement dans le domaine paramétrique 2d u,v
1233 // transport - projection sur le carré unité
1235 // MESSAGE("StdMeshers_Quadrangle_2D::SetNormalizedGrid");
1236 // const TopoDS_Face& F = TopoDS::Face(aShape);
1238 // 1 --- find orientation of the 4 edges, by test on extrema
1241 // |<----north-2-------^ a3 -------------> a2
1243 // west-3 east-1 =right | |
1247 // v----south-0--------> a0 -------------> a1
1252 // 3 --- 2D normalized values on unit square [0..1][0..1]
1254 int nbhoriz = Min(quad->side[0]->NbPoints(), quad->side[2]->NbPoints());
1255 int nbvertic = Min(quad->side[1]->NbPoints(), quad->side[3]->NbPoints());
1257 quad->isEdgeOut[0] = (quad->side[0]->NbPoints() > quad->side[2]->NbPoints());
1258 quad->isEdgeOut[1] = (quad->side[1]->NbPoints() > quad->side[3]->NbPoints());
1259 quad->isEdgeOut[2] = (quad->side[2]->NbPoints() > quad->side[0]->NbPoints());
1260 quad->isEdgeOut[3] = (quad->side[3]->NbPoints() > quad->side[1]->NbPoints());
1262 UVPtStruct *uv_grid = quad->uv_grid = new UVPtStruct[nbvertic * nbhoriz];
1264 const vector<UVPtStruct>& uv_e0 = GetUVPtStructIn(quad, 0, nbhoriz - 1);
1265 const vector<UVPtStruct>& uv_e1 = GetUVPtStructIn(quad, 1, nbvertic - 1);
1266 const vector<UVPtStruct>& uv_e2 = GetUVPtStructIn(quad, 2, nbhoriz - 1);
1267 const vector<UVPtStruct>& uv_e3 = GetUVPtStructIn(quad, 3, nbvertic - 1);
1269 if (uv_e0.empty() || uv_e1.empty() || uv_e2.empty() || uv_e3.empty())
1270 //return error("Can't find nodes on sides");
1271 return error(COMPERR_BAD_INPUT_MESH);
1274 UpdateDegenUV( quad );
1276 // copy data of face boundary
1277 /*if (! quad->isEdgeOut[0])*/ {
1279 for (int i = 0; i < nbhoriz; i++) // down
1280 uv_grid[ j * nbhoriz + i ] = uv_e0[i];
1282 /*if (! quad->isEdgeOut[1])*/ {
1283 const int i = nbhoriz - 1;
1284 for (int j = 0; j < nbvertic; j++) // right
1285 uv_grid[ j * nbhoriz + i ] = uv_e1[j];
1287 /*if (! quad->isEdgeOut[2])*/ {
1288 const int j = nbvertic - 1;
1289 for (int i = 0; i < nbhoriz; i++) // up
1290 uv_grid[ j * nbhoriz + i ] = uv_e2[i];
1292 /*if (! quad->isEdgeOut[3])*/ {
1294 for (int j = 0; j < nbvertic; j++) // left
1295 uv_grid[ j * nbhoriz + i ] = uv_e3[j];
1298 // normalized 2d parameters on grid
1299 for (int i = 0; i < nbhoriz; i++) {
1300 for (int j = 0; j < nbvertic; j++) {
1301 int ij = j * nbhoriz + i;
1302 // --- droite i cste : x = x0 + y(x1-x0)
1303 double x0 = uv_e0[i].normParam; // bas - sud
1304 double x1 = uv_e2[i].normParam; // haut - nord
1305 // --- droite j cste : y = y0 + x(y1-y0)
1306 double y0 = uv_e3[j].normParam; // gauche-ouest
1307 double y1 = uv_e1[j].normParam; // droite - est
1308 // --- intersection : x=x0+(y0+x(y1-y0))(x1-x0)
1309 double x = (x0 + y0 * (x1 - x0)) / (1 - (y1 - y0) * (x1 - x0));
1310 double y = y0 + x * (y1 - y0);
1313 //MESSAGE("-xy-01 "<<x0<<" "<<x1<<" "<<y0<<" "<<y1);
1314 //MESSAGE("-xy-norm "<<i<<" "<<j<<" "<<x<<" "<<y);
1318 // 4 --- projection on 2d domain (u,v)
1319 gp_UV a0 (uv_e0.front().u, uv_e0.front().v);
1320 gp_UV a1 (uv_e0.back().u, uv_e0.back().v );
1321 gp_UV a2 (uv_e2.back().u, uv_e2.back().v );
1322 gp_UV a3 (uv_e2.front().u, uv_e2.front().v);
1324 for (int i = 0; i < nbhoriz; i++)
1326 gp_UV p0( uv_e0[i].u, uv_e0[i].v );
1327 gp_UV p2( uv_e2[i].u, uv_e2[i].v );
1328 for (int j = 0; j < nbvertic; j++)
1330 gp_UV p1( uv_e1[j].u, uv_e1[j].v );
1331 gp_UV p3( uv_e3[j].u, uv_e3[j].v );
1333 int ij = j * nbhoriz + i;
1334 double x = uv_grid[ij].x;
1335 double y = uv_grid[ij].y;
1337 gp_UV uv = CalcUV(x,y, a0,a1,a2,a3, p0,p1,p2,p3);
1339 uv_grid[ij].u = uv.X();
1340 uv_grid[ij].v = uv.Y();
1346 //=======================================================================
1347 //function : ShiftQuad
1348 //purpose : auxilary function for ComputeQuadPref
1349 //=======================================================================
1351 static void ShiftQuad(FaceQuadStruct* quad, const int num, bool)
1353 StdMeshers_FaceSide* side[4] = { quad->side[0], quad->side[1],
1354 quad->side[2], quad->side[3] };
1355 for (int i = BOTTOM_SIDE; i < NB_SIDES; ++i) {
1356 int id = (i + num) % NB_SIDES;
1357 bool wasForward = (i < TOP_SIDE);
1358 bool newForward = (id < TOP_SIDE);
1359 if (wasForward != newForward)
1360 side[ i ]->Reverse();
1361 quad->side[ id ] = side[ i ];
1365 //=======================================================================
1367 //purpose : auxilary function for ComputeQuadPref
1368 //=======================================================================
1370 static gp_UV CalcUV(double x0, double x1, double y0, double y1,
1371 FaceQuadStruct* quad,
1372 const gp_UV& a0, const gp_UV& a1,
1373 const gp_UV& a2, const gp_UV& a3)
1375 // const vector<UVPtStruct>& uv_eb = quad->side[0]->GetUVPtStruct(true,0);
1376 // const vector<UVPtStruct>& uv_er = quad->side[1]->GetUVPtStruct(false,1);
1377 // const vector<UVPtStruct>& uv_et = quad->side[2]->GetUVPtStruct(true,1);
1378 // const vector<UVPtStruct>& uv_el = quad->side[3]->GetUVPtStruct(false,0);
1380 double x = (x0 + y0 * (x1 - x0)) / (1 - (y1 - y0) * (x1 - x0));
1381 double y = y0 + x * (y1 - y0);
1383 gp_UV p0 = quad->side[BOTTOM_SIDE]->Value2d(x).XY();
1384 gp_UV p1 = quad->side[RIGHT_SIDE ]->Value2d(y).XY();
1385 gp_UV p2 = quad->side[TOP_SIDE ]->Value2d(x).XY();
1386 gp_UV p3 = quad->side[LEFT_SIDE ]->Value2d(y).XY();
1388 gp_UV uv = CalcUV(x,y, a0,a1,a2,a3, p0,p1,p2,p3);
1393 //=======================================================================
1394 //function : CalcUV2
1395 //purpose : auxilary function for ComputeQuadPref
1396 //=======================================================================
1398 static gp_UV CalcUV2(double x, double y,
1399 FaceQuadStruct* quad,
1400 const gp_UV& a0, const gp_UV& a1,
1401 const gp_UV& a2, const gp_UV& a3)
1403 gp_UV p0 = quad->side[BOTTOM_SIDE]->Value2d(x).XY();
1404 gp_UV p1 = quad->side[RIGHT_SIDE ]->Value2d(y).XY();
1405 gp_UV p2 = quad->side[TOP_SIDE ]->Value2d(x).XY();
1406 gp_UV p3 = quad->side[LEFT_SIDE ]->Value2d(y).XY();
1408 gp_UV uv = CalcUV(x,y, a0,a1,a2,a3, p0,p1,p2,p3);
1414 //=======================================================================
1416 * Create only quandrangle faces
1418 //=======================================================================
1420 bool StdMeshers_Quadrangle_2D::ComputeQuadPref (SMESH_Mesh & aMesh,
1421 const TopoDS_Shape& aShape,
1422 FaceQuadStruct* quad)
1424 // Auxilary key in order to keep old variant
1425 // of meshing after implementation new variant
1426 // for bug 0016220 from Mantis.
1427 bool OldVersion = false;
1428 if (myQuadType == QUAD_QUADRANGLE_PREF_REVERSED)
1431 SMESHDS_Mesh * meshDS = aMesh.GetMeshDS();
1432 const TopoDS_Face& F = TopoDS::Face(aShape);
1433 Handle(Geom_Surface) S = BRep_Tool::Surface(F);
1435 int i,j,geomFaceID = meshDS->ShapeToIndex(F);
1437 int nb = quad->side[0]->NbPoints();
1438 int nr = quad->side[1]->NbPoints();
1439 int nt = quad->side[2]->NbPoints();
1440 int nl = quad->side[3]->NbPoints();
1441 int dh = abs(nb-nt);
1442 int dv = abs(nr-nl);
1446 // it is a base case => not shift quad but me be replacement is need
1447 ShiftQuad(quad,0,WisF);
1450 // we have to shift quad on 2
1451 ShiftQuad(quad,2,WisF);
1456 // we have to shift quad on 1
1457 ShiftQuad(quad,1,WisF);
1460 // we have to shift quad on 3
1461 ShiftQuad(quad,3,WisF);
1465 nb = quad->side[0]->NbPoints();
1466 nr = quad->side[1]->NbPoints();
1467 nt = quad->side[2]->NbPoints();
1468 nl = quad->side[3]->NbPoints();
1471 int nbh = Max(nb,nt);
1472 int nbv = Max(nr,nl);
1476 // ----------- Old version ---------------
1477 // orientation of face and 3 main domain for future faces
1483 // left | | | | rigth
1490 // ----------- New version ---------------
1491 // orientation of face and 3 main domain for future faces
1497 // left |/________\| rigth
1513 const vector<UVPtStruct>& uv_eb = quad->side[0]->GetUVPtStruct(true,0);
1514 const vector<UVPtStruct>& uv_er = quad->side[1]->GetUVPtStruct(false,1);
1515 const vector<UVPtStruct>& uv_et = quad->side[2]->GetUVPtStruct(true,1);
1516 const vector<UVPtStruct>& uv_el = quad->side[3]->GetUVPtStruct(false,0);
1518 if (uv_eb.size() != nb || uv_er.size() != nr || uv_et.size() != nt || uv_el.size() != nl)
1519 return error(COMPERR_BAD_INPUT_MESH);
1522 UpdateDegenUV( quad );
1524 // arrays for normalized params
1525 //cout<<"Dump B:"<<endl;
1526 TColStd_SequenceOfReal npb, npr, npt, npl;
1527 for (i=0; i<nb; i++) {
1528 npb.Append(uv_eb[i].normParam);
1529 //cout<<"i="<<i<<" par="<<uv_eb[i].normParam<<" npar="<<uv_eb[i].normParam;
1530 //const SMDS_MeshNode* N = uv_eb[i].node;
1531 //cout<<" node("<<N->X()<<","<<N->Y()<<","<<N->Z()<<")"<<endl;
1533 for (i=0; i<nr; i++) {
1534 npr.Append(uv_er[i].normParam);
1536 for (i=0; i<nt; i++) {
1537 npt.Append(uv_et[i].normParam);
1539 for (i=0; i<nl; i++) {
1540 npl.Append(uv_el[i].normParam);
1545 // add some params to right and left after the first param
1548 double dpr = (npr.Value(2) - npr.Value(1))/(dr+1);
1549 for (i=1; i<=dr; i++) {
1550 npr.InsertAfter(1,npr.Value(2)-dpr);
1554 dpr = (npl.Value(2) - npl.Value(1))/(dl+1);
1555 for (i=1; i<=dl; i++) {
1556 npl.InsertAfter(1,npl.Value(2)-dpr);
1560 //for (i=1; i<=npb.Length(); i++) {
1561 // cout<<" "<<npb.Value(i);
1565 gp_XY a0(uv_eb.front().u, uv_eb.front().v);
1566 gp_XY a1(uv_eb.back().u, uv_eb.back().v);
1567 gp_XY a2(uv_et.back().u, uv_et.back().v);
1568 gp_XY a3(uv_et.front().u, uv_et.front().v);
1569 //cout<<" a0("<<a0.X()<<","<<a0.Y()<<")"<<" a1("<<a1.X()<<","<<a1.Y()<<")"
1570 // <<" a2("<<a2.X()<<","<<a2.Y()<<")"<<" a3("<<a3.X()<<","<<a3.Y()<<")"<<endl;
1572 int nnn = Min(nr,nl);
1573 // auxilary sequence of XY for creation nodes
1574 // in the bottom part of central domain
1575 // Length of UVL and UVR must be == nbv-nnn
1576 TColgp_SequenceOfXY UVL, UVR, UVT;
1579 // step1: create faces for left domain
1580 StdMeshers_Array2OfNode NodesL(1,dl+1,1,nl);
1582 for (j=1; j<=nl; j++)
1583 NodesL.SetValue(1,j,uv_el[j-1].node);
1586 for (i=1; i<=dl; i++)
1587 NodesL.SetValue(i+1,nl,uv_et[i].node);
1588 // create and add needed nodes
1589 TColgp_SequenceOfXY UVtmp;
1590 for (i=1; i<=dl; i++) {
1591 double x0 = npt.Value(i+1);
1594 double y0 = npl.Value(i+1);
1595 double y1 = npr.Value(i+1);
1596 gp_UV UV = CalcUV(x0, x1, y0, y1, quad, a0, a1, a2, a3);
1597 gp_Pnt P = S->Value(UV.X(),UV.Y());
1598 SMDS_MeshNode * N = meshDS->AddNode(P.X(), P.Y(), P.Z());
1599 meshDS->SetNodeOnFace(N, geomFaceID, UV.X(), UV.Y());
1600 NodesL.SetValue(i+1,1,N);
1601 if (UVL.Length()<nbv-nnn) UVL.Append(UV);
1603 for (j=2; j<nl; j++) {
1604 double y0 = npl.Value(dl+j);
1605 double y1 = npr.Value(dl+j);
1606 gp_UV UV = CalcUV(x0, x1, y0, y1, quad, a0, a1, a2, a3);
1607 gp_Pnt P = S->Value(UV.X(),UV.Y());
1608 SMDS_MeshNode* N = meshDS->AddNode(P.X(), P.Y(), P.Z());
1609 meshDS->SetNodeOnFace(N, geomFaceID, UV.X(), UV.Y());
1610 NodesL.SetValue(i+1,j,N);
1611 if (i==dl) UVtmp.Append(UV);
1614 for (i=1; i<=UVtmp.Length() && UVL.Length()<nbv-nnn; i++) {
1615 UVL.Append(UVtmp.Value(i));
1617 //cout<<"Dump NodesL:"<<endl;
1618 //for (i=1; i<=dl+1; i++) {
1620 // for (j=1; j<=nl; j++) {
1621 // cout<<" ("<<NodesL.Value(i,j)->X()<<","<<NodesL.Value(i,j)->Y()<<","<<NodesL.Value(i,j)->Z()<<")";
1626 for (i=1; i<=dl; i++) {
1627 for (j=1; j<nl; j++) {
1630 myHelper->AddFace(NodesL.Value(i,j), NodesL.Value(i+1,j),
1631 NodesL.Value(i+1,j+1), NodesL.Value(i,j+1));
1632 if (F) meshDS->SetMeshElementOnShape(F, geomFaceID);
1636 myHelper->AddFace(NodesL.Value(i,j), NodesL.Value(i,j+1),
1637 NodesL.Value(i+1,j+1), NodesL.Value(i+1,j));
1638 if (F) meshDS->SetMeshElementOnShape(F, geomFaceID);
1644 // fill UVL using c2d
1645 for (i=1; i<npl.Length() && UVL.Length()<nbv-nnn; i++) {
1646 UVL.Append(gp_UV (uv_el[i].u, uv_el[i].v));
1650 // step2: create faces for right domain
1651 StdMeshers_Array2OfNode NodesR(1,dr+1,1,nr);
1653 for (j=1; j<=nr; j++)
1654 NodesR.SetValue(1,j,uv_er[nr-j].node);
1657 for (i=1; i<=dr; i++)
1658 NodesR.SetValue(i+1,1,uv_et[nt-1-i].node);
1659 // create and add needed nodes
1660 TColgp_SequenceOfXY UVtmp;
1661 for (i=1; i<=dr; i++) {
1662 double x0 = npt.Value(nt-i);
1665 double y0 = npl.Value(i+1);
1666 double y1 = npr.Value(i+1);
1667 gp_UV UV = CalcUV(x0, x1, y0, y1, quad, a0, a1, a2, a3);
1668 gp_Pnt P = S->Value(UV.X(),UV.Y());
1669 SMDS_MeshNode * N = meshDS->AddNode(P.X(), P.Y(), P.Z());
1670 meshDS->SetNodeOnFace(N, geomFaceID, UV.X(), UV.Y());
1671 NodesR.SetValue(i+1,nr,N);
1672 if (UVR.Length()<nbv-nnn) UVR.Append(UV);
1674 for (j=2; j<nr; j++) {
1675 double y0 = npl.Value(nbv-j+1);
1676 double y1 = npr.Value(nbv-j+1);
1677 gp_UV UV = CalcUV(x0, x1, y0, y1, quad, a0, a1, a2, a3);
1678 gp_Pnt P = S->Value(UV.X(),UV.Y());
1679 SMDS_MeshNode* N = meshDS->AddNode(P.X(), P.Y(), P.Z());
1680 meshDS->SetNodeOnFace(N, geomFaceID, UV.X(), UV.Y());
1681 NodesR.SetValue(i+1,j,N);
1682 if (i==dr) UVtmp.Prepend(UV);
1685 for (i=1; i<=UVtmp.Length() && UVR.Length()<nbv-nnn; i++) {
1686 UVR.Append(UVtmp.Value(i));
1689 for (i=1; i<=dr; i++) {
1690 for (j=1; j<nr; j++) {
1693 myHelper->AddFace(NodesR.Value(i,j), NodesR.Value(i+1,j),
1694 NodesR.Value(i+1,j+1), NodesR.Value(i,j+1));
1695 if (F) meshDS->SetMeshElementOnShape(F, geomFaceID);
1699 myHelper->AddFace(NodesR.Value(i,j), NodesR.Value(i,j+1),
1700 NodesR.Value(i+1,j+1), NodesR.Value(i+1,j));
1701 if (F) meshDS->SetMeshElementOnShape(F, geomFaceID);
1707 // fill UVR using c2d
1708 for (i=1; i<npr.Length() && UVR.Length()<nbv-nnn; i++) {
1709 UVR.Append(gp_UV(uv_er[i].u, uv_er[i].v));
1713 // step3: create faces for central domain
1714 StdMeshers_Array2OfNode NodesC(1,nb,1,nbv);
1715 // add first line using NodesL
1716 for (i=1; i<=dl+1; i++)
1717 NodesC.SetValue(1,i,NodesL(i,1));
1718 for (i=2; i<=nl; i++)
1719 NodesC.SetValue(1,dl+i,NodesL(dl+1,i));
1720 // add last line using NodesR
1721 for (i=1; i<=dr+1; i++)
1722 NodesC.SetValue(nb,i,NodesR(i,nr));
1723 for (i=1; i<nr; i++)
1724 NodesC.SetValue(nb,dr+i+1,NodesR(dr+1,nr-i));
1725 // add top nodes (last columns)
1726 for (i=dl+2; i<nbh-dr; i++)
1727 NodesC.SetValue(i-dl,nbv,uv_et[i-1].node);
1728 // add bottom nodes (first columns)
1729 for (i=2; i<nb; i++)
1730 NodesC.SetValue(i,1,uv_eb[i-1].node);
1732 // create and add needed nodes
1733 // add linear layers
1734 for (i=2; i<nb; i++) {
1735 double x0 = npt.Value(dl+i);
1737 for (j=1; j<nnn; j++) {
1738 double y0 = npl.Value(nbv-nnn+j);
1739 double y1 = npr.Value(nbv-nnn+j);
1740 gp_UV UV = CalcUV(x0, x1, y0, y1, quad, a0, a1, a2, a3);
1741 gp_Pnt P = S->Value(UV.X(),UV.Y());
1742 SMDS_MeshNode* N = meshDS->AddNode(P.X(), P.Y(), P.Z());
1743 meshDS->SetNodeOnFace(N, geomFaceID, UV.X(), UV.Y());
1744 NodesC.SetValue(i,nbv-nnn+j,N);
1749 // add diagonal layers
1750 //cout<<"UVL.Length()="<<UVL.Length()<<" UVR.Length()="<<UVR.Length()<<endl;
1751 //cout<<"Dump UVL:"<<endl;
1752 //for (i=1; i<=UVL.Length(); i++) {
1753 // cout<<" ("<<UVL.Value(i).X()<<","<<UVL.Value(i).Y()<<")";
1756 gp_UV A2 = UVR.Value(nbv-nnn);
1757 gp_UV A3 = UVL.Value(nbv-nnn);
1758 for (i=1; i<nbv-nnn; i++) {
1759 gp_UV p1 = UVR.Value(i);
1760 gp_UV p3 = UVL.Value(i);
1761 double y = i / double(nbv-nnn);
1762 for (j=2; j<nb; j++) {
1763 double x = npb.Value(j);
1764 gp_UV p0( uv_eb[j-1].u, uv_eb[j-1].v );
1765 gp_UV p2 = UVT.Value( j-1 );
1766 gp_UV UV = CalcUV(x, y, a0, a1, A2, A3, p0,p1,p2,p3 );
1767 gp_Pnt P = S->Value(UV.X(),UV.Y());
1768 SMDS_MeshNode* N = meshDS->AddNode(P.X(), P.Y(), P.Z());
1769 meshDS->SetNodeOnFace(N, geomFaceID, UV.X(),UV.Y());
1770 NodesC.SetValue(j,i+1,N);
1774 for (i=1; i<nb; i++) {
1775 for (j=1; j<nbv; j++) {
1778 myHelper->AddFace(NodesC.Value(i,j), NodesC.Value(i+1,j),
1779 NodesC.Value(i+1,j+1), NodesC.Value(i,j+1));
1780 if (F) meshDS->SetMeshElementOnShape(F, geomFaceID);
1784 myHelper->AddFace(NodesC.Value(i,j), NodesC.Value(i,j+1),
1785 NodesC.Value(i+1,j+1), NodesC.Value(i+1,j));
1786 if (F) meshDS->SetMeshElementOnShape(F, geomFaceID);
1792 else { // New version (!OldVersion)
1793 // step1: create faces for bottom rectangle domain
1794 StdMeshers_Array2OfNode NodesBRD(1,nb,1,nnn-1);
1795 // fill UVL and UVR using c2d
1796 for (j=0; j<nb; j++) {
1797 NodesBRD.SetValue(j+1,1,uv_eb[j].node);
1799 for (i=1; i<nnn-1; i++) {
1800 NodesBRD.SetValue(1,i+1,uv_el[i].node);
1801 NodesBRD.SetValue(nb,i+1,uv_er[i].node);
1802 for (j=2; j<nb; j++) {
1803 double x = npb.Value(j);
1804 double y = (1-x) * npl.Value(i+1) + x * npr.Value(i+1);
1805 gp_UV UV = CalcUV2(x, y, quad, a0, a1, a2, a3);
1806 gp_Pnt P = S->Value(UV.X(),UV.Y());
1807 SMDS_MeshNode* N = meshDS->AddNode(P.X(), P.Y(), P.Z());
1808 meshDS->SetNodeOnFace(N, geomFaceID, UV.X(),UV.Y());
1809 NodesBRD.SetValue(j,i+1,N);
1812 for (j=1; j<nnn-1; j++) {
1813 for (i=1; i<nb; i++) {
1816 myHelper->AddFace(NodesBRD.Value(i,j), NodesBRD.Value(i+1,j),
1817 NodesBRD.Value(i+1,j+1), NodesBRD.Value(i,j+1));
1818 if (F) meshDS->SetMeshElementOnShape(F, geomFaceID);
1822 myHelper->AddFace(NodesBRD.Value(i,j), NodesBRD.Value(i,j+1),
1823 NodesBRD.Value(i+1,j+1), NodesBRD.Value(i+1,j));
1824 if (F) meshDS->SetMeshElementOnShape(F, geomFaceID);
1828 int drl = abs(nr-nl);
1829 // create faces for region C
1830 StdMeshers_Array2OfNode NodesC(1,nb,1,drl+1+addv);
1831 // add nodes from previous region
1832 for (j=1; j<=nb; j++) {
1833 NodesC.SetValue(j,1,NodesBRD.Value(j,nnn-1));
1835 if ((drl+addv) > 0) {
1840 TColgp_SequenceOfXY UVtmp;
1841 double drparam = npr.Value(nr) - npr.Value(nnn-1);
1842 double dlparam = npl.Value(nnn) - npl.Value(nnn-1);
1844 for (i=1; i<=drl; i++) {
1845 // add existed nodes from right edge
1846 NodesC.SetValue(nb,i+1,uv_er[nnn+i-2].node);
1847 //double dtparam = npt.Value(i+1);
1848 y1 = npr.Value(nnn+i-1); // param on right edge
1849 double dpar = (y1 - npr.Value(nnn-1))/drparam;
1850 y0 = npl.Value(nnn-1) + dpar*dlparam; // param on left edge
1851 double dy = y1 - y0;
1852 for (j=1; j<nb; j++) {
1853 double x = npt.Value(i+1) + npb.Value(j)*(1-npt.Value(i+1));
1854 double y = y0 + dy*x;
1855 gp_UV UV = CalcUV2(x, y, quad, a0, a1, a2, a3);
1856 gp_Pnt P = S->Value(UV.X(),UV.Y());
1857 SMDS_MeshNode* N = meshDS->AddNode(P.X(), P.Y(), P.Z());
1858 meshDS->SetNodeOnFace(N, geomFaceID, UV.X(), UV.Y());
1859 NodesC.SetValue(j,i+1,N);
1862 double dy0 = (1-y0)/(addv+1);
1863 double dy1 = (1-y1)/(addv+1);
1864 for (i=1; i<=addv; i++) {
1865 double yy0 = y0 + dy0*i;
1866 double yy1 = y1 + dy1*i;
1867 double dyy = yy1 - yy0;
1868 for (j=1; j<=nb; j++) {
1869 double x = npt.Value(i+1+drl) +
1870 npb.Value(j) * (npt.Value(nt-i) - npt.Value(i+1+drl));
1871 double y = yy0 + dyy*x;
1872 gp_UV UV = CalcUV2(x, y, quad, a0, a1, a2, a3);
1873 gp_Pnt P = S->Value(UV.X(),UV.Y());
1874 SMDS_MeshNode* N = meshDS->AddNode(P.X(), P.Y(), P.Z());
1875 meshDS->SetNodeOnFace(N, geomFaceID, UV.X(), UV.Y());
1876 NodesC.SetValue(j,i+drl+1,N);
1883 TColgp_SequenceOfXY UVtmp;
1884 double dlparam = npl.Value(nl) - npl.Value(nnn-1);
1885 double drparam = npr.Value(nnn) - npr.Value(nnn-1);
1886 double y0 = npl.Value(nnn-1);
1887 double y1 = npr.Value(nnn-1);
1888 for (i=1; i<=drl; i++) {
1889 // add existed nodes from right edge
1890 NodesC.SetValue(1,i+1,uv_el[nnn+i-2].node);
1891 y0 = npl.Value(nnn+i-1); // param on left edge
1892 double dpar = (y0 - npl.Value(nnn-1))/dlparam;
1893 y1 = npr.Value(nnn-1) + dpar*drparam; // param on right edge
1894 double dy = y1 - y0;
1895 for (j=2; j<=nb; j++) {
1896 double x = npb.Value(j)*npt.Value(nt-i);
1897 double y = y0 + dy*x;
1898 gp_UV UV = CalcUV2(x, y, quad, a0, a1, a2, a3);
1899 gp_Pnt P = S->Value(UV.X(),UV.Y());
1900 SMDS_MeshNode* N = meshDS->AddNode(P.X(), P.Y(), P.Z());
1901 meshDS->SetNodeOnFace(N, geomFaceID, UV.X(), UV.Y());
1902 NodesC.SetValue(j,i+1,N);
1905 double dy0 = (1-y0)/(addv+1);
1906 double dy1 = (1-y1)/(addv+1);
1907 for (i=1; i<=addv; i++) {
1908 double yy0 = y0 + dy0*i;
1909 double yy1 = y1 + dy1*i;
1910 double dyy = yy1 - yy0;
1911 for (j=1; j<=nb; j++) {
1912 double x = npt.Value(i+1) +
1913 npb.Value(j) * (npt.Value(nt-i-drl) - npt.Value(i+1));
1914 double y = yy0 + dyy*x;
1915 gp_UV UV = CalcUV2(x, y, quad, a0, a1, a2, a3);
1916 gp_Pnt P = S->Value(UV.X(),UV.Y());
1917 SMDS_MeshNode* N = meshDS->AddNode(P.X(), P.Y(), P.Z());
1918 meshDS->SetNodeOnFace(N, geomFaceID, UV.X(), UV.Y());
1919 NodesC.SetValue(j,i+drl+1,N);
1924 for (j=1; j<=drl+addv; j++) {
1925 for (i=1; i<nb; i++) {
1928 myHelper->AddFace(NodesC.Value(i,j), NodesC.Value(i+1,j),
1929 NodesC.Value(i+1,j+1), NodesC.Value(i,j+1));
1930 if (F) meshDS->SetMeshElementOnShape(F, geomFaceID);
1934 myHelper->AddFace(NodesC.Value(i,j), NodesC.Value(i,j+1),
1935 NodesC.Value(i+1,j+1), NodesC.Value(i+1,j));
1936 if (F) meshDS->SetMeshElementOnShape(F, geomFaceID);
1941 StdMeshers_Array2OfNode NodesLast(1,nt,1,2);
1942 for (i=1; i<=nt; i++) {
1943 NodesLast.SetValue(i,2,uv_et[i-1].node);
1946 for (i=n1; i<drl+addv+1; i++) {
1948 NodesLast.SetValue(nnn,1,NodesC.Value(1,i));
1950 for (i=1; i<=nb; i++) {
1952 NodesLast.SetValue(nnn,1,NodesC.Value(i,drl+addv+1));
1954 for (i=drl+addv; i>=n2; i--) {
1956 NodesLast.SetValue(nnn,1,NodesC.Value(nb,i));
1958 for (i=1; i<nt; i++) {
1961 myHelper->AddFace(NodesLast.Value(i,1), NodesLast.Value(i+1,1),
1962 NodesLast.Value(i+1,2), NodesLast.Value(i,2));
1963 if (F) meshDS->SetMeshElementOnShape(F, geomFaceID);
1967 myHelper->AddFace(NodesLast.Value(i,1), NodesLast.Value(i,2),
1968 NodesLast.Value(i+1,2), NodesLast.Value(i+1,2));
1969 if (F) meshDS->SetMeshElementOnShape(F, geomFaceID);
1972 } // if ((drl+addv) > 0)
1974 } // end new version implementation
1981 //=======================================================================
1983 * Evaluate only quandrangle faces
1985 //=======================================================================
1987 bool StdMeshers_Quadrangle_2D::EvaluateQuadPref(SMESH_Mesh & aMesh,
1988 const TopoDS_Shape& aShape,
1989 std::vector<int>& aNbNodes,
1990 MapShapeNbElems& aResMap,
1993 // Auxilary key in order to keep old variant
1994 // of meshing after implementation new variant
1995 // for bug 0016220 from Mantis.
1996 bool OldVersion = false;
1997 if (myQuadType == QUAD_QUADRANGLE_PREF_REVERSED)
2000 const TopoDS_Face& F = TopoDS::Face(aShape);
2001 Handle(Geom_Surface) S = BRep_Tool::Surface(F);
2003 int nb = aNbNodes[0];
2004 int nr = aNbNodes[1];
2005 int nt = aNbNodes[2];
2006 int nl = aNbNodes[3];
2007 int dh = abs(nb-nt);
2008 int dv = abs(nr-nl);
2012 // it is a base case => not shift
2015 // we have to shift on 2
2024 // we have to shift quad on 1
2031 // we have to shift quad on 3
2041 int nbh = Max(nb,nt);
2042 int nbv = Max(nr,nl);
2057 // add some params to right and left after the first param
2064 int nnn = Min(nr,nl);
2069 // step1: create faces for left domain
2071 nbNodes += dl*(nl-1);
2072 nbFaces += dl*(nl-1);
2074 // step2: create faces for right domain
2076 nbNodes += dr*(nr-1);
2077 nbFaces += dr*(nr-1);
2079 // step3: create faces for central domain
2080 nbNodes += (nb-2)*(nnn-1) + (nbv-nnn-1)*(nb-2);
2081 nbFaces += (nb-1)*(nbv-1);
2083 else { // New version (!OldVersion)
2084 nbNodes += (nnn-2)*(nb-2);
2085 nbFaces += (nnn-2)*(nb-1);
2086 int drl = abs(nr-nl);
2087 nbNodes += drl*(nb-1) + addv*nb;
2088 nbFaces += (drl+addv)*(nb-1) + (nt-1);
2089 } // end new version implementation
2091 std::vector<int> aVec(SMDSEntity_Last);
2092 for (int i=SMDSEntity_Node; i<SMDSEntity_Last; i++) aVec[i] = 0;
2094 aVec[SMDSEntity_Quad_Quadrangle] = nbFaces;
2095 aVec[SMDSEntity_Node] = nbNodes + nbFaces*4;
2096 if (aNbNodes.size()==5) {
2097 aVec[SMDSEntity_Quad_Triangle] = aNbNodes[3] - 1;
2098 aVec[SMDSEntity_Quad_Quadrangle] = nbFaces - aNbNodes[3] + 1;
2102 aVec[SMDSEntity_Node] = nbNodes;
2103 aVec[SMDSEntity_Quadrangle] = nbFaces;
2104 if (aNbNodes.size()==5) {
2105 aVec[SMDSEntity_Triangle] = aNbNodes[3] - 1;
2106 aVec[SMDSEntity_Quadrangle] = nbFaces - aNbNodes[3] + 1;
2109 SMESH_subMesh * sm = aMesh.GetSubMesh(aShape);
2110 aResMap.insert(std::make_pair(sm,aVec));
2116 //=============================================================================
2117 /*! Split quadrangle in to 2 triangles by smallest diagonal
2120 //=============================================================================
2121 void StdMeshers_Quadrangle_2D::SplitQuad(SMESHDS_Mesh *theMeshDS,
2123 const SMDS_MeshNode* theNode1,
2124 const SMDS_MeshNode* theNode2,
2125 const SMDS_MeshNode* theNode3,
2126 const SMDS_MeshNode* theNode4)
2128 gp_Pnt a(theNode1->X(),theNode1->Y(),theNode1->Z());
2129 gp_Pnt b(theNode2->X(),theNode2->Y(),theNode2->Z());
2130 gp_Pnt c(theNode3->X(),theNode3->Y(),theNode3->Z());
2131 gp_Pnt d(theNode4->X(),theNode4->Y(),theNode4->Z());
2132 SMDS_MeshFace* face;
2133 if (a.Distance(c) > b.Distance(d)){
2134 face = myHelper->AddFace(theNode2, theNode4 , theNode1);
2135 if (face) theMeshDS->SetMeshElementOnShape(face, theFaceID);
2136 face = myHelper->AddFace(theNode2, theNode3, theNode4);
2137 if (face) theMeshDS->SetMeshElementOnShape(face, theFaceID);
2141 face = myHelper->AddFace(theNode1, theNode2 ,theNode3);
2142 if (face) theMeshDS->SetMeshElementOnShape(face, theFaceID);
2143 face = myHelper->AddFace(theNode1, theNode3, theNode4);
2144 if (face) theMeshDS->SetMeshElementOnShape(face, theFaceID);
2150 enum uvPos { UV_A0, UV_A1, UV_A2, UV_A3, UV_B, UV_R, UV_T, UV_L, UV_SIZE };
2152 inline SMDS_MeshNode* makeNode( UVPtStruct & uvPt,
2154 FaceQuadStruct* quad,
2156 SMESH_MesherHelper* helper,
2157 Handle(Geom_Surface) S)
2159 const vector<UVPtStruct>& uv_eb = quad->side[BOTTOM_SIDE]->GetUVPtStruct();
2160 const vector<UVPtStruct>& uv_et = quad->side[TOP_SIDE ]->GetUVPtStruct();
2161 double rBot = ( uv_eb.size() - 1 ) * uvPt.normParam;
2162 double rTop = ( uv_et.size() - 1 ) * uvPt.normParam;
2163 int iBot = int( rBot );
2164 int iTop = int( rTop );
2165 double xBot = uv_eb[ iBot ].normParam + ( rBot - iBot ) * ( uv_eb[ iBot+1 ].normParam - uv_eb[ iBot ].normParam );
2166 double xTop = uv_et[ iTop ].normParam + ( rTop - iTop ) * ( uv_et[ iTop+1 ].normParam - uv_et[ iTop ].normParam );
2167 double x = xBot + y * ( xTop - xBot );
2169 gp_UV uv = CalcUV(/*x,y=*/x, y,
2170 /*a0,...=*/UVs[UV_A0], UVs[UV_A1], UVs[UV_A2], UVs[UV_A3],
2171 /*p0=*/quad->side[BOTTOM_SIDE]->Value2d( x ).XY(),
2173 /*p2=*/quad->side[TOP_SIDE ]->Value2d( x ).XY(),
2174 /*p3=*/UVs[ UV_L ]);
2175 gp_Pnt P = S->Value( uv.X(), uv.Y() );
2178 return helper->AddNode(P.X(), P.Y(), P.Z(), 0, uv.X(), uv.Y() );
2181 void reduce42( const vector<UVPtStruct>& curr_base,
2182 vector<UVPtStruct>& next_base,
2184 int & next_base_len,
2185 FaceQuadStruct* quad,
2188 SMESH_MesherHelper* helper,
2189 Handle(Geom_Surface)& S)
2191 // add one "HH": nodes a,b,c,d,e and faces 1,2,3,4,5,6
2193 // .-----a-----b i + 1
2204 const SMDS_MeshNode*& Na = next_base[ ++next_base_len ].node;
2206 Na = makeNode( next_base[ next_base_len ], y, quad, UVs, helper, S );
2209 const SMDS_MeshNode*& Nb = next_base[ ++next_base_len ].node;
2211 Nb = makeNode( next_base[ next_base_len ], y, quad, UVs, helper, S );
2214 double u = (curr_base[j + 2].u + next_base[next_base_len - 2].u) / 2.0;
2215 double v = (curr_base[j + 2].v + next_base[next_base_len - 2].v) / 2.0;
2216 gp_Pnt P = S->Value(u,v);
2217 SMDS_MeshNode* Nc = helper->AddNode(P.X(), P.Y(), P.Z(), 0, u, v);
2220 u = (curr_base[j + 2].u + next_base[next_base_len - 1].u) / 2.0;
2221 v = (curr_base[j + 2].v + next_base[next_base_len - 1].v) / 2.0;
2223 SMDS_MeshNode* Nd = helper->AddNode(P.X(), P.Y(), P.Z(), 0, u, v);
2226 u = (curr_base[j + 2].u + next_base[next_base_len].u) / 2.0;
2227 v = (curr_base[j + 2].v + next_base[next_base_len].v) / 2.0;
2229 SMDS_MeshNode* Ne = helper->AddNode(P.X(), P.Y(), P.Z(), 0, u, v);
2232 helper->AddFace(curr_base[j + 0].node,
2233 curr_base[j + 1].node, Nc,
2234 next_base[next_base_len - 2].node);
2236 helper->AddFace(curr_base[j + 1].node,
2237 curr_base[j + 2].node, Nd, Nc);
2239 helper->AddFace(curr_base[j + 2].node,
2240 curr_base[j + 3].node, Ne, Nd);
2242 helper->AddFace(curr_base[j + 3].node,
2243 curr_base[j + 4].node, Nb, Ne);
2245 helper->AddFace(Nc, Nd, Na, next_base[next_base_len - 2].node);
2247 helper->AddFace(Nd, Ne, Nb, Na);
2250 void reduce31( const vector<UVPtStruct>& curr_base,
2251 vector<UVPtStruct>& next_base,
2253 int & next_base_len,
2254 FaceQuadStruct* quad,
2257 SMESH_MesherHelper* helper,
2258 Handle(Geom_Surface)& S)
2260 // add one "H": nodes b,c,e and faces 1,2,4,5
2262 // .---------b i + 1
2273 const SMDS_MeshNode*& Nb = next_base[ ++next_base_len ].node;
2275 Nb = makeNode( next_base[ next_base_len ], y, quad, UVs, helper, S );
2278 double u1 = (curr_base[ j ].u + next_base[ next_base_len-1 ].u ) / 2.0;
2279 double u2 = (curr_base[ j+3 ].u + next_base[ next_base_len ].u ) / 2.0;
2280 double u3 = (u2 - u1) / 3.0;
2282 double v1 = (curr_base[ j ].v + next_base[ next_base_len-1 ].v ) / 2.0;
2283 double v2 = (curr_base[ j+3 ].v + next_base[ next_base_len ].v ) / 2.0;
2284 double v3 = (v2 - v1) / 3.0;
2288 gp_Pnt P = S->Value(u,v);
2289 SMDS_MeshNode* Nc = helper->AddNode( P.X(), P.Y(), P.Z(), 0, u, v );
2294 SMDS_MeshNode* Ne = helper->AddNode( P.X(), P.Y(), P.Z(), 0, u, v );
2298 helper->AddFace( curr_base[ j + 0 ].node,
2299 curr_base[ j + 1 ].node,
2301 next_base[ next_base_len - 1 ].node);
2303 helper->AddFace( curr_base[ j + 1 ].node,
2304 curr_base[ j + 2 ].node, Ne, Nc);
2306 helper->AddFace( curr_base[ j + 2 ].node,
2307 curr_base[ j + 3 ].node, Nb, Ne);
2309 helper->AddFace(Nc, Ne, Nb,
2310 next_base[ next_base_len - 1 ].node);
2313 typedef void (* PReduceFunction) ( const vector<UVPtStruct>& curr_base,
2314 vector<UVPtStruct>& next_base,
2316 int & next_base_len,
2317 FaceQuadStruct* quad,
2320 SMESH_MesherHelper* helper,
2321 Handle(Geom_Surface)& S);
2325 //=======================================================================
2327 * Implementation of Reduced algorithm (meshing with quadrangles only)
2329 //=======================================================================
2330 bool StdMeshers_Quadrangle_2D::ComputeReduced (SMESH_Mesh & aMesh,
2331 const TopoDS_Shape& aShape,
2332 FaceQuadStruct* quad)
2334 SMESHDS_Mesh * meshDS = aMesh.GetMeshDS();
2335 const TopoDS_Face& F = TopoDS::Face(aShape);
2336 Handle(Geom_Surface) S = BRep_Tool::Surface(F);
2337 int i,j,geomFaceID = meshDS->ShapeToIndex(F);
2339 int nb = quad->side[0]->NbPoints();
2340 int nr = quad->side[1]->NbPoints();
2341 int nt = quad->side[2]->NbPoints();
2342 int nl = quad->side[3]->NbPoints();
2344 // Simple Reduce 10->8->6->4 (3 steps) Multiple Reduce 10->4 (1 step)
2346 // .-----.-----.-----.-----. .-----.-----.-----.-----.
2347 // | / \ | / \ | | / \ | / \ |
2348 // | / .--.--. \ | | / \ | / \ |
2349 // | / / | \ \ | | / .----.----. \ |
2350 // .---.---.---.---.---.---. | / / \ | / \ \ |
2351 // | / / \ | / \ \ | | / / \ | / \ \ |
2352 // | / / .-.-. \ \ | | / / .---.---. \ \ |
2353 // | / / / | \ \ \ | | / / / \ | / \ \ \ |
2354 // .--.--.--.--.--.--.--.--. | / / / \ | / \ \ \ |
2355 // | / / / \ | / \ \ \ | | / / / .-.-. \ \ \ |
2356 // | / / / .-.-. \ \ \ | | / / / / | \ \ \ \ |
2357 // | / / / / | \ \ \ \ | | / / / / | \ \ \ \ |
2358 // .-.-.-.--.--.--.--.-.-.-. .-.-.-.--.--.--.--.-.-.-.
2360 bool MultipleReduce = false;
2372 else if (nb == nt) {
2373 nr1 = nb; // and == nt
2387 // number of rows and columns
2388 int nrows = nr1 - 1;
2389 int ncol_top = nt1 - 1;
2390 int ncol_bot = nb1 - 1;
2391 // number of rows needed to reduce ncol_bot to ncol_top using simple 3->1 "tree" (see below)
2392 int nrows_tree31 = int( log( (double)(ncol_bot / ncol_top) ) / log((double) 3 )); // = log x base 3
2393 if ( nrows < nrows_tree31 )
2394 MultipleReduce = true;
2397 if (MultipleReduce) { // == ComputeQuadPref QUAD_QUADRANGLE_PREF_REVERSED
2398 //==================================================
2399 int dh = abs(nb-nt);
2400 int dv = abs(nr-nl);
2404 // it is a base case => not shift quad but may be replacement is need
2405 ShiftQuad(quad,0,true);
2408 // we have to shift quad on 2
2409 ShiftQuad(quad,2,true);
2414 // we have to shift quad on 1
2415 ShiftQuad(quad,1,true);
2418 // we have to shift quad on 3
2419 ShiftQuad(quad,3,true);
2423 nb = quad->side[0]->NbPoints();
2424 nr = quad->side[1]->NbPoints();
2425 nt = quad->side[2]->NbPoints();
2426 nl = quad->side[3]->NbPoints();
2429 int nbh = Max(nb,nt);
2430 int nbv = Max(nr,nl);
2443 const vector<UVPtStruct>& uv_eb = quad->side[0]->GetUVPtStruct(true,0);
2444 const vector<UVPtStruct>& uv_er = quad->side[1]->GetUVPtStruct(false,1);
2445 const vector<UVPtStruct>& uv_et = quad->side[2]->GetUVPtStruct(true,1);
2446 const vector<UVPtStruct>& uv_el = quad->side[3]->GetUVPtStruct(false,0);
2448 if (uv_eb.size() != nb || uv_er.size() != nr || uv_et.size() != nt || uv_el.size() != nl)
2449 return error(COMPERR_BAD_INPUT_MESH);
2452 UpdateDegenUV( quad );
2454 // arrays for normalized params
2455 TColStd_SequenceOfReal npb, npr, npt, npl;
2456 for (j = 0; j < nb; j++) {
2457 npb.Append(uv_eb[j].normParam);
2459 for (i = 0; i < nr; i++) {
2460 npr.Append(uv_er[i].normParam);
2462 for (j = 0; j < nt; j++) {
2463 npt.Append(uv_et[j].normParam);
2465 for (i = 0; i < nl; i++) {
2466 npl.Append(uv_el[i].normParam);
2470 // orientation of face and 3 main domain for future faces
2476 // left | | | | rigth
2483 // add some params to right and left after the first param
2486 double dpr = (npr.Value(2) - npr.Value(1))/(dr+1);
2487 for (i=1; i<=dr; i++) {
2488 npr.InsertAfter(1,npr.Value(2)-dpr);
2492 dpr = (npl.Value(2) - npl.Value(1))/(dl+1);
2493 for (i=1; i<=dl; i++) {
2494 npl.InsertAfter(1,npl.Value(2)-dpr);
2497 gp_XY a0 (uv_eb.front().u, uv_eb.front().v);
2498 gp_XY a1 (uv_eb.back().u, uv_eb.back().v);
2499 gp_XY a2 (uv_et.back().u, uv_et.back().v);
2500 gp_XY a3 (uv_et.front().u, uv_et.front().v);
2502 int nnn = Min(nr,nl);
2503 // auxilary sequence of XY for creation of nodes
2504 // in the bottom part of central domain
2505 // it's length must be == nbv-nnn-1
2506 TColgp_SequenceOfXY UVL;
2507 TColgp_SequenceOfXY UVR;
2508 //==================================================
2510 // step1: create faces for left domain
2511 StdMeshers_Array2OfNode NodesL(1,dl+1,1,nl);
2513 for (j=1; j<=nl; j++)
2514 NodesL.SetValue(1,j,uv_el[j-1].node);
2517 for (i=1; i<=dl; i++)
2518 NodesL.SetValue(i+1,nl,uv_et[i].node);
2519 // create and add needed nodes
2520 TColgp_SequenceOfXY UVtmp;
2521 for (i=1; i<=dl; i++) {
2522 double x0 = npt.Value(i+1);
2525 double y0 = npl.Value(i+1);
2526 double y1 = npr.Value(i+1);
2527 gp_UV UV = CalcUV(x0, x1, y0, y1, quad, a0, a1, a2, a3);
2528 gp_Pnt P = S->Value(UV.X(),UV.Y());
2529 SMDS_MeshNode * N = meshDS->AddNode(P.X(), P.Y(), P.Z());
2530 meshDS->SetNodeOnFace(N, geomFaceID, UV.X(), UV.Y());
2531 NodesL.SetValue(i+1,1,N);
2532 if (UVL.Length()<nbv-nnn-1) UVL.Append(UV);
2534 for (j=2; j<nl; j++) {
2535 double y0 = npl.Value(dl+j);
2536 double y1 = npr.Value(dl+j);
2537 gp_UV UV = CalcUV(x0, x1, y0, y1, quad, a0, a1, a2, a3);
2538 gp_Pnt P = S->Value(UV.X(),UV.Y());
2539 SMDS_MeshNode* N = meshDS->AddNode(P.X(), P.Y(), P.Z());
2540 meshDS->SetNodeOnFace(N, geomFaceID, UV.X(), UV.Y());
2541 NodesL.SetValue(i+1,j,N);
2542 if (i==dl) UVtmp.Append(UV);
2545 for (i=1; i<=UVtmp.Length() && UVL.Length()<nbv-nnn-1; i++) {
2546 UVL.Append(UVtmp.Value(i));
2549 for (i=1; i<=dl; i++) {
2550 for (j=1; j<nl; j++) {
2552 myHelper->AddFace(NodesL.Value(i,j), NodesL.Value(i+1,j),
2553 NodesL.Value(i+1,j+1), NodesL.Value(i,j+1));
2554 if (F) meshDS->SetMeshElementOnShape(F, geomFaceID);
2559 // fill UVL using c2d
2560 for (i=1; i<npl.Length() && UVL.Length()<nbv-nnn-1; i++) {
2561 UVL.Append(gp_UV (uv_el[i].u, uv_el[i].v));
2565 // step2: create faces for right domain
2566 StdMeshers_Array2OfNode NodesR(1,dr+1,1,nr);
2568 for (j=1; j<=nr; j++)
2569 NodesR.SetValue(1,j,uv_er[nr-j].node);
2572 for (i=1; i<=dr; i++)
2573 NodesR.SetValue(i+1,1,uv_et[nt-1-i].node);
2574 // create and add needed nodes
2575 TColgp_SequenceOfXY UVtmp;
2576 for (i=1; i<=dr; i++) {
2577 double x0 = npt.Value(nt-i);
2580 double y0 = npl.Value(i+1);
2581 double y1 = npr.Value(i+1);
2582 gp_UV UV = CalcUV(x0, x1, y0, y1, quad, a0, a1, a2, a3);
2583 gp_Pnt P = S->Value(UV.X(),UV.Y());
2584 SMDS_MeshNode * N = meshDS->AddNode(P.X(), P.Y(), P.Z());
2585 meshDS->SetNodeOnFace(N, geomFaceID, UV.X(), UV.Y());
2586 NodesR.SetValue(i+1,nr,N);
2587 if (UVR.Length()<nbv-nnn-1) UVR.Append(UV);
2589 for (j=2; j<nr; j++) {
2590 double y0 = npl.Value(nbv-j+1);
2591 double y1 = npr.Value(nbv-j+1);
2592 gp_UV UV = CalcUV(x0, x1, y0, y1, quad, a0, a1, a2, a3);
2593 gp_Pnt P = S->Value(UV.X(),UV.Y());
2594 SMDS_MeshNode* N = meshDS->AddNode(P.X(), P.Y(), P.Z());
2595 meshDS->SetNodeOnFace(N, geomFaceID, UV.X(), UV.Y());
2596 NodesR.SetValue(i+1,j,N);
2597 if (i==dr) UVtmp.Prepend(UV);
2600 for (i=1; i<=UVtmp.Length() && UVR.Length()<nbv-nnn-1; i++) {
2601 UVR.Append(UVtmp.Value(i));
2604 for (i=1; i<=dr; i++) {
2605 for (j=1; j<nr; j++) {
2607 myHelper->AddFace(NodesR.Value(i,j), NodesR.Value(i+1,j),
2608 NodesR.Value(i+1,j+1), NodesR.Value(i,j+1));
2609 if (F) meshDS->SetMeshElementOnShape(F, geomFaceID);
2614 // fill UVR using c2d
2615 for (i=1; i<npr.Length() && UVR.Length()<nbv-nnn-1; i++) {
2616 UVR.Append(gp_UV(uv_er[i].u, uv_er[i].v));
2620 // step3: create faces for central domain
2621 StdMeshers_Array2OfNode NodesC(1,nb,1,nbv);
2622 // add first line using NodesL
2623 for (i=1; i<=dl+1; i++)
2624 NodesC.SetValue(1,i,NodesL(i,1));
2625 for (i=2; i<=nl; i++)
2626 NodesC.SetValue(1,dl+i,NodesL(dl+1,i));
2627 // add last line using NodesR
2628 for (i=1; i<=dr+1; i++)
2629 NodesC.SetValue(nb,i,NodesR(i,nr));
2630 for (i=1; i<nr; i++)
2631 NodesC.SetValue(nb,dr+i+1,NodesR(dr+1,nr-i));
2632 // add top nodes (last columns)
2633 for (i=dl+2; i<nbh-dr; i++)
2634 NodesC.SetValue(i-dl,nbv,uv_et[i-1].node);
2635 // add bottom nodes (first columns)
2636 for (i=2; i<nb; i++)
2637 NodesC.SetValue(i,1,uv_eb[i-1].node);
2639 // create and add needed nodes
2640 // add linear layers
2641 for (i=2; i<nb; i++) {
2642 double x0 = npt.Value(dl+i);
2644 for (j=1; j<nnn; j++) {
2645 double y0 = npl.Value(nbv-nnn+j);
2646 double y1 = npr.Value(nbv-nnn+j);
2647 gp_UV UV = CalcUV(x0, x1, y0, y1, quad, a0, a1, a2, a3);
2648 gp_Pnt P = S->Value(UV.X(),UV.Y());
2649 SMDS_MeshNode* N = meshDS->AddNode(P.X(), P.Y(), P.Z());
2650 meshDS->SetNodeOnFace(N, geomFaceID, UV.X(), UV.Y());
2651 NodesC.SetValue(i,nbv-nnn+j,N);
2654 // add diagonal layers
2655 for (i=1; i<nbv-nnn; i++) {
2656 double du = UVR.Value(i).X() - UVL.Value(i).X();
2657 double dv = UVR.Value(i).Y() - UVL.Value(i).Y();
2658 for (j=2; j<nb; j++) {
2659 double u = UVL.Value(i).X() + du*npb.Value(j);
2660 double v = UVL.Value(i).Y() + dv*npb.Value(j);
2661 gp_Pnt P = S->Value(u,v);
2662 SMDS_MeshNode* N = meshDS->AddNode(P.X(), P.Y(), P.Z());
2663 meshDS->SetNodeOnFace(N, geomFaceID, u, v);
2664 NodesC.SetValue(j,i+1,N);
2668 for (i=1; i<nb; i++) {
2669 for (j=1; j<nbv; j++) {
2671 myHelper->AddFace(NodesC.Value(i,j), NodesC.Value(i+1,j),
2672 NodesC.Value(i+1,j+1), NodesC.Value(i,j+1));
2673 if (F) meshDS->SetMeshElementOnShape(F, geomFaceID);
2677 } // end Multiple Reduce implementation
2678 else { // Simple Reduce (!MultipleReduce)
2679 //=========================================================
2682 // it is a base case => not shift quad
2683 //ShiftQuad(quad,0,true);
2686 // we have to shift quad on 2
2687 ShiftQuad(quad,2,true);
2692 // we have to shift quad on 1
2693 ShiftQuad(quad,1,true);
2696 // we have to shift quad on 3
2697 ShiftQuad(quad,3,true);
2701 nb = quad->side[0]->NbPoints();
2702 nr = quad->side[1]->NbPoints();
2703 nt = quad->side[2]->NbPoints();
2704 nl = quad->side[3]->NbPoints();
2706 // number of rows and columns
2707 int nrows = nr - 1; // and also == nl - 1
2708 int ncol_top = nt - 1;
2709 int ncol_bot = nb - 1;
2710 int npair_top = ncol_top / 2;
2711 // maximum number of bottom elements for "linear" simple reduce 4->2
2712 int max_lin42 = ncol_top + npair_top * 2 * nrows;
2713 // maximum number of bottom elements for "linear" simple reduce 3->1
2714 int max_lin31 = ncol_top + ncol_top * 2 * nrows;
2715 // maximum number of bottom elements for "tree" simple reduce 4->2
2717 // number of rows needed to reduce ncol_bot to ncol_top using simple 4->2 "tree"
2718 int nrows_tree42 = int( log( (double)(ncol_bot / ncol_top) )/log((double)2) ); // needed to avoid overflow at pow(2) while computing max_tree42
2719 if (nrows_tree42 < nrows) {
2720 max_tree42 = npair_top * pow(2.0, nrows + 1);
2721 if ( ncol_top > npair_top * 2 ) {
2722 int delta = ncol_bot - max_tree42;
2723 for (int irow = 1; irow < nrows; irow++) {
2724 int nfour = delta / 4;
2727 if (delta <= (ncol_top - npair_top * 2))
2728 max_tree42 = ncol_bot;
2731 // maximum number of bottom elements for "tree" simple reduce 3->1
2732 //int max_tree31 = ncol_top * pow(3.0, nrows);
2733 bool is_lin_31 = false;
2734 bool is_lin_42 = false;
2735 bool is_tree_31 = false;
2736 bool is_tree_42 = false;
2737 int max_lin = max_lin42;
2738 if (ncol_bot > max_lin42) {
2739 if (ncol_bot <= max_lin31) {
2741 max_lin = max_lin31;
2745 // if ncol_bot is a 3*n or not 2*n
2746 if ((ncol_bot/3)*3 == ncol_bot || (ncol_bot/2)*2 != ncol_bot) {
2748 max_lin = max_lin31;
2754 if (ncol_bot > max_lin) { // not "linear"
2755 is_tree_31 = (ncol_bot > max_tree42);
2756 if (ncol_bot <= max_tree42) {
2757 if ((ncol_bot/3)*3 == ncol_bot || (ncol_bot/2)*2 != ncol_bot) {
2766 const vector<UVPtStruct>& uv_eb = quad->side[0]->GetUVPtStruct(true,0);
2767 const vector<UVPtStruct>& uv_er = quad->side[1]->GetUVPtStruct(false,1);
2768 const vector<UVPtStruct>& uv_et = quad->side[2]->GetUVPtStruct(true,1);
2769 const vector<UVPtStruct>& uv_el = quad->side[3]->GetUVPtStruct(false,0);
2771 if (uv_eb.size() != nb || uv_er.size() != nr || uv_et.size() != nt || uv_el.size() != nl)
2772 return error(COMPERR_BAD_INPUT_MESH);
2774 myHelper->SetElementsOnShape( true );
2776 gp_UV uv[ UV_SIZE ];
2777 uv[ UV_A0 ].SetCoord( uv_eb.front().u, uv_eb.front().v);
2778 uv[ UV_A1 ].SetCoord( uv_eb.back().u, uv_eb.back().v );
2779 uv[ UV_A2 ].SetCoord( uv_et.back().u, uv_et.back().v );
2780 uv[ UV_A3 ].SetCoord( uv_et.front().u, uv_et.front().v);
2782 vector<UVPtStruct> curr_base = uv_eb, next_base;
2784 UVPtStruct nullUVPtStruct; nullUVPtStruct.node = 0;
2786 int curr_base_len = nb;
2787 int next_base_len = 0;
2790 { // ------------------------------------------------------------------
2791 // New algorithm implemented by request of IPAL22856
2792 // "2D quadrangle mesher of reduced type works wrong"
2793 // http://bugtracker.opencascade.com/show_bug.cgi?id=22856
2795 // the algorithm is following: all reduces are centred in horizontal
2796 // direction and are distributed among all rows
2798 if (ncol_bot > max_tree42) {
2802 if ((ncol_top/3)*3 == ncol_top ) {
2810 const int col_top_size = is_lin_42 ? 2 : 1;
2811 const int col_base_size = is_lin_42 ? 4 : 3;
2813 // Compute nb of "columns" (like in "linear" simple reducing) in all rows
2815 vector<int> nb_col_by_row;
2817 int delta_all = nb - nt;
2818 int delta_one_col = nrows * 2;
2819 int nb_col = delta_all / delta_one_col;
2820 int remainder = delta_all - nb_col * delta_one_col;
2821 if (remainder > 0) {
2824 if ( nb_col * col_top_size >= nt ) // == "tree" reducing situation
2826 // top row is full (all elements reduced), add "columns" one by one
2827 // in rows below until all bottom elements are reduced
2828 nb_col = ( nt - 1 ) / col_top_size;
2829 nb_col_by_row.resize( nrows, nb_col );
2830 int nbrows_not_full = nrows - 1;
2831 int cur_top_size = nt - 1;
2832 remainder = delta_all - nb_col * delta_one_col;
2833 while ( remainder > 0 )
2835 delta_one_col = nbrows_not_full * 2;
2836 int nb_col_add = remainder / delta_one_col;
2837 cur_top_size += 2 * nb_col_by_row[ nbrows_not_full ];
2838 int nb_col_free = cur_top_size / col_top_size - nb_col_by_row[ nbrows_not_full-1 ];
2839 if ( nb_col_add > nb_col_free )
2840 nb_col_add = nb_col_free;
2841 for ( int irow = 0; irow < nbrows_not_full; ++irow )
2842 nb_col_by_row[ irow ] += nb_col_add;
2844 remainder -= nb_col_add * delta_one_col;
2847 else // == "linear" reducing situation
2849 nb_col_by_row.resize( nrows, nb_col );
2851 for ( int irow = remainder / 2; irow < nrows; ++irow )
2852 nb_col_by_row[ irow ]--;
2857 PReduceFunction reduceFunction = & ( is_lin_42 ? reduce42 : reduce31 );
2859 const int reduce_grp_size = is_lin_42 ? 4 : 3;
2861 for (i = 1; i < nr; i++) // layer by layer
2863 nb_col = nb_col_by_row[ i-1 ];
2864 int nb_next = curr_base_len - nb_col * 2;
2865 if (nb_next < nt) nb_next = nt;
2867 const double y = uv_el[ i ].normParam;
2869 if ( i + 1 == nr ) // top
2876 next_base.resize( nb_next, nullUVPtStruct );
2877 next_base.front() = uv_el[i];
2878 next_base.back() = uv_er[i];
2880 // compute normalized param u
2881 double du = 1. / ( nb_next - 1 );
2882 next_base[0].normParam = 0.;
2883 for ( j = 1; j < nb_next; ++j )
2884 next_base[j].normParam = next_base[j-1].normParam + du;
2886 uv[ UV_L ].SetCoord( next_base.front().u, next_base.front().v );
2887 uv[ UV_R ].SetCoord( next_base.back().u, next_base.back().v );
2889 int free_left = ( curr_base_len - 1 - nb_col * col_base_size ) / 2;
2890 int free_middle = curr_base_len - 1 - nb_col * col_base_size - 2 * free_left;
2892 // not reduced left elements
2893 for (j = 0; j < free_left; j++)
2896 const SMDS_MeshNode*& Nf = next_base[++next_base_len].node;
2898 Nf = makeNode( next_base[ next_base_len ], y, quad, uv, myHelper, S );
2900 myHelper->AddFace(curr_base[ j ].node,
2901 curr_base[ j+1 ].node,
2903 next_base[ next_base_len-1 ].node);
2906 for (int icol = 1; icol <= nb_col; icol++)
2909 reduceFunction( curr_base, next_base, j, next_base_len, quad, uv, y, myHelper, S );
2911 j += reduce_grp_size;
2913 // elements in the middle of "columns" added for symmetry
2914 if ( free_middle > 0 && ( nb_col % 2 == 0 ) && icol == nb_col / 2 )
2916 for (int imiddle = 1; imiddle <= free_middle; imiddle++) {
2917 // f (i + 1, j + imiddle)
2918 const SMDS_MeshNode*& Nf = next_base[++next_base_len].node;
2920 Nf = makeNode( next_base[ next_base_len ], y, quad, uv, myHelper, S );
2922 myHelper->AddFace(curr_base[ j-1+imiddle ].node,
2923 curr_base[ j +imiddle ].node,
2925 next_base[ next_base_len-1 ].node);
2931 // not reduced right elements
2932 for (; j < curr_base_len-1; j++) {
2934 const SMDS_MeshNode*& Nf = next_base[++next_base_len].node;
2936 Nf = makeNode( next_base[ next_base_len ], y, quad, uv, myHelper, S );
2938 myHelper->AddFace(curr_base[ j ].node,
2939 curr_base[ j+1 ].node,
2941 next_base[ next_base_len-1 ].node);
2944 curr_base_len = next_base_len + 1;
2946 curr_base.swap( next_base );
2950 else if ( is_tree_42 || is_tree_31 )
2952 // "tree" simple reduce "42": 2->4->8->16->32->...
2954 // .-------------------------------.-------------------------------. nr
2956 // | \ .---------------.---------------. / |
2958 // .---------------.---------------.---------------.---------------.
2959 // | \ | / | \ | / |
2960 // | \ .-------.-------. / | \ .-------.-------. / |
2961 // | | | | | | | | |
2962 // .-------.-------.-------.-------.-------.-------.-------.-------. i
2963 // |\ | /|\ | /|\ | /|\ | /|
2964 // | \.---.---./ | \.---.---./ | \.---.---./ | \.---.---./ |
2965 // | | | | | | | | | | | | | | | | |
2966 // .---.---.---.---.---.---.---.---.---.---.---.---.---.---.---.---.
2967 // |\ | /|\ | /|\ | /|\ | /|\ | /|\ | /|\ | /|\ | /|
2968 // | .-.-. | .-.-. | .-.-. | .-.-. | .-.-. | .-.-. | .-.-. | .-.-. |
2969 // | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
2970 // .-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-. 1
2973 // "tree" simple reduce "31": 1->3->9->27->...
2975 // .-----------------------------------------------------. nr
2977 // | .-----------------. |
2979 // .-----------------.-----------------.-----------------.
2980 // | \ / | \ / | \ / |
2981 // | .-----. | .-----. | .-----. | i
2982 // | | | | | | | | | |
2983 // .-----.-----.-----.-----.-----.-----.-----.-----.-----.
2984 // |\ /|\ /|\ /|\ /|\ /|\ /|\ /|\ /|\ /|
2985 // | .-. | .-. | .-. | .-. | .-. | .-. | .-. | .-. | .-. |
2986 // | | | | | | | | | | | | | | | | | | | | | | | | | | | |
2987 // .-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-. 1
2990 PReduceFunction reduceFunction = & ( is_tree_42 ? reduce42 : reduce31 );
2992 const int reduce_grp_size = is_tree_42 ? 4 : 3;
2994 for (i = 1; i < nr; i++) // layer by layer
2996 // to stop reducing, if number of nodes reaches nt
2997 int delta = curr_base_len - nt;
2999 // to calculate normalized parameter, we must know number of points in next layer
3000 int nb_reduce_groups = (curr_base_len - 1) / reduce_grp_size;
3001 int nb_next = nb_reduce_groups * (reduce_grp_size-2) + (curr_base_len - nb_reduce_groups*reduce_grp_size);
3002 if (nb_next < nt) nb_next = nt;
3004 const double y = uv_el[ i ].normParam;
3006 if ( i + 1 == nr ) // top
3013 next_base.resize( nb_next, nullUVPtStruct );
3014 next_base.front() = uv_el[i];
3015 next_base.back() = uv_er[i];
3017 // compute normalized param u
3018 double du = 1. / ( nb_next - 1 );
3019 next_base[0].normParam = 0.;
3020 for ( j = 1; j < nb_next; ++j )
3021 next_base[j].normParam = next_base[j-1].normParam + du;
3023 uv[ UV_L ].SetCoord( next_base.front().u, next_base.front().v );
3024 uv[ UV_R ].SetCoord( next_base.back().u, next_base.back().v );
3026 for (j = 0; j+reduce_grp_size < curr_base_len && delta > 0; j+=reduce_grp_size, delta-=2)
3028 reduceFunction( curr_base, next_base, j, next_base_len, quad, uv, y, myHelper, S );
3031 // not reduced side elements (if any)
3032 for (; j < curr_base_len-1; j++)
3035 const SMDS_MeshNode*& Nf = next_base[++next_base_len].node;
3037 Nf = makeNode( next_base[ next_base_len ], y, quad, uv, myHelper, S );
3039 myHelper->AddFace(curr_base[ j ].node,
3040 curr_base[ j+1 ].node,
3042 next_base[ next_base_len-1 ].node);
3044 curr_base_len = next_base_len + 1;
3046 curr_base.swap( next_base );
3048 } // end "tree" simple reduce
3050 else if ( is_lin_42 || is_lin_31 ) {
3051 // "linear" simple reduce "31": 2->6->10->14
3053 // .-----------------------------.-----------------------------. nr
3055 // | .---------. | .---------. |
3057 // .---------.---------.---------.---------.---------.---------.
3058 // | / \ / \ | / \ / \ |
3059 // | / .-----. \ | / .-----. \ | i
3060 // | / | | \ | / | | \ |
3061 // .-----.-----.-----.-----.-----.-----.-----.-----.-----.-----.
3062 // | / / \ / \ \ | / / \ / \ \ |
3063 // | / / .-. \ \ | / / .-. \ \ |
3064 // | / / / \ \ \ | / / / \ \ \ |
3065 // .--.----.---.-----.---.-----.-.--.----.---.-----.---.-----.-. 1
3068 // "linear" simple reduce "42": 4->8->12->16
3070 // .---------------.---------------.---------------.---------------. nr
3071 // | \ | / | \ | / |
3072 // | \ .-------.-------. / | \ .-------.-------. / |
3073 // | | | | | | | | |
3074 // .-------.-------.-------.-------.-------.-------.-------.-------.
3075 // | / \ | / \ | / \ | / \ |
3076 // | / \.----.----./ \ | / \.----.----./ \ | i
3077 // | / | | | \ | / | | | \ |
3078 // .-----.----.----.----.----.-----.-----.----.----.----.----.-----.
3079 // | / / \ | / \ \ | / / \ | / \ \ |
3080 // | / / .-.-. \ \ | / / .-.-. \ \ |
3081 // | / / / | \ \ \ | / / / | \ \ \ |
3082 // .---.---.---.---.---.---.---.---.---.---.---.---.---.---.---.---. 1
3085 // nt = 5, nb = 7, nr = 4
3086 //int delta_all = 2;
3087 //int delta_one_col = 6;
3089 //int remainder = 2;
3090 //if (remainder > 0) nb_col++;
3092 //int free_left = 1;
3094 //int free_middle = 4;
3096 int delta_all = nb - nt;
3097 int delta_one_col = (nr - 1) * 2;
3098 int nb_col = delta_all / delta_one_col;
3099 int remainder = delta_all - nb_col * delta_one_col;
3100 if (remainder > 0) {
3103 const int col_top_size = is_lin_42 ? 2 : 1;
3104 int free_left = ((nt - 1) - nb_col * col_top_size) / 2;
3105 free_left += nr - 2;
3106 int free_middle = (nr - 2) * 2;
3107 if (remainder > 0 && nb_col == 1) {
3108 int nb_rows_short_col = remainder / 2;
3109 int nb_rows_thrown = (nr - 1) - nb_rows_short_col;
3110 free_left -= nb_rows_thrown;
3113 // nt = 5, nb = 17, nr = 4
3114 //int delta_all = 12;
3115 //int delta_one_col = 6;
3117 //int remainder = 0;
3118 //int free_left = 2;
3119 //int free_middle = 4;
3121 PReduceFunction reduceFunction = & ( is_lin_42 ? reduce42 : reduce31 );
3123 const int reduce_grp_size = is_lin_42 ? 4 : 3;
3125 for (i = 1; i < nr; i++, free_middle -= 2, free_left -= 1) // layer by layer
3127 // to calculate normalized parameter, we must know number of points in next layer
3128 int nb_next = curr_base_len - nb_col * 2;
3129 if (remainder > 0 && i > remainder / 2)
3130 // take into account short "column"
3132 if (nb_next < nt) nb_next = nt;
3134 const double y = uv_el[ i ].normParam;
3136 if ( i + 1 == nr ) // top
3143 next_base.resize( nb_next, nullUVPtStruct );
3144 next_base.front() = uv_el[i];
3145 next_base.back() = uv_er[i];
3147 // compute normalized param u
3148 double du = 1. / ( nb_next - 1 );
3149 next_base[0].normParam = 0.;
3150 for ( j = 1; j < nb_next; ++j )
3151 next_base[j].normParam = next_base[j-1].normParam + du;
3153 uv[ UV_L ].SetCoord( next_base.front().u, next_base.front().v );
3154 uv[ UV_R ].SetCoord( next_base.back().u, next_base.back().v );
3156 // not reduced left elements
3157 for (j = 0; j < free_left; j++)
3160 const SMDS_MeshNode*& Nf = next_base[++next_base_len].node;
3162 Nf = makeNode( next_base[ next_base_len ], y, quad, uv, myHelper, S );
3164 myHelper->AddFace(curr_base[ j ].node,
3165 curr_base[ j+1 ].node,
3167 next_base[ next_base_len-1 ].node);
3170 for (int icol = 1; icol <= nb_col; icol++) {
3172 if (remainder > 0 && icol == nb_col && i > remainder / 2)
3173 // stop short "column"
3177 reduceFunction( curr_base, next_base, j, next_base_len, quad, uv, y, myHelper, S );
3179 j += reduce_grp_size;
3181 // not reduced middle elements
3182 if (icol < nb_col) {
3183 if (remainder > 0 && icol == nb_col - 1 && i > remainder / 2)
3184 // pass middle elements before stopped short "column"
3187 int free_add = free_middle;
3188 if (remainder > 0 && icol == nb_col - 1)
3189 // next "column" is short
3190 free_add -= (nr - 1) - (remainder / 2);
3192 for (int imiddle = 1; imiddle <= free_add; imiddle++) {
3193 // f (i + 1, j + imiddle)
3194 const SMDS_MeshNode*& Nf = next_base[++next_base_len].node;
3196 Nf = makeNode( next_base[ next_base_len ], y, quad, uv, myHelper, S );
3198 myHelper->AddFace(curr_base[ j-1+imiddle ].node,
3199 curr_base[ j +imiddle ].node,
3201 next_base[ next_base_len-1 ].node);
3207 // not reduced right elements
3208 for (; j < curr_base_len-1; j++) {
3210 const SMDS_MeshNode*& Nf = next_base[++next_base_len].node;
3212 Nf = makeNode( next_base[ next_base_len ], y, quad, uv, myHelper, S );
3214 myHelper->AddFace(curr_base[ j ].node,
3215 curr_base[ j+1 ].node,
3217 next_base[ next_base_len-1 ].node);
3220 curr_base_len = next_base_len + 1;
3222 curr_base.swap( next_base );
3225 } // end "linear" simple reduce
3230 } // end Simple Reduce implementation
3236 //================================================================================
3237 namespace // data for smoothing
3240 // --------------------------------------------------------------------------------
3242 * \brief Structure used to check validity of node position after smoothing.
3243 * It holds two nodes connected to a smoothed node and belonging to
3250 TTriangle( TSmoothNode* n1=0, TSmoothNode* n2=0 ): _n1(n1), _n2(n2) {}
3252 inline bool IsForward( gp_UV uv ) const;
3254 // --------------------------------------------------------------------------------
3256 * \brief Data of a smoothed node
3261 vector< TTriangle > _triangles; // if empty, then node is not movable
3263 // --------------------------------------------------------------------------------
3264 inline bool TTriangle::IsForward( gp_UV uv ) const
3266 gp_Vec2d v1( uv, _n1->_uv ), v2( uv, _n2->_uv );
3272 //================================================================================
3274 * \brief Set UV of nodes on degenerated VERTEXes in the middle of degenerated EDGE
3276 * WARNING: this method must be called AFTER retrieving UVPtStruct's from quad
3278 //================================================================================
3280 void StdMeshers_Quadrangle_2D::UpdateDegenUV(FaceQuadStruct* quad)
3282 for ( unsigned i = 0; i < quad->side.size(); ++i )
3284 StdMeshers_FaceSide* side = quad->side[i];
3285 const vector<UVPtStruct>& uvVec = side->GetUVPtStruct();
3287 // find which end of the side is on degenerated shape
3289 if ( myHelper->IsDegenShape( uvVec[0].node->getshapeId() ))
3291 else if ( myHelper->IsDegenShape( uvVec.back().node->getshapeId() ))
3292 degenInd = uvVec.size() - 1;
3296 // find another side sharing the degenerated shape
3297 bool isPrev = ( degenInd == 0 );
3298 if ( i >= TOP_SIDE )
3300 int i2 = ( isPrev ? ( i + 3 ) : ( i + 1 )) % 4;
3301 StdMeshers_FaceSide* side2 = quad->side[ i2 ];
3302 const vector<UVPtStruct>& uvVec2 = side2->GetUVPtStruct();
3304 if ( uvVec[ degenInd ].node == uvVec2[0].node )
3306 else if ( uvVec[ degenInd ].node == uvVec2.back().node )
3307 degenInd2 = uvVec2.size() - 1;
3309 throw SALOME_Exception( LOCALIZED( "Logical error" ));
3311 // move UV in the middle
3312 uvPtStruct& uv1 = const_cast<uvPtStruct&>( uvVec [ degenInd ]);
3313 uvPtStruct& uv2 = const_cast<uvPtStruct&>( uvVec2[ degenInd2 ]);
3314 uv1.u = uv2.u = 0.5 * ( uv1.u + uv2.u );
3315 uv1.v = uv2.v = 0.5 * ( uv1.v + uv2.v );
3319 //================================================================================
3321 * \brief Perform smoothing of 2D elements on a FACE with ignored degenerated EDGE
3323 //================================================================================
3325 void StdMeshers_Quadrangle_2D::Smooth (FaceQuadStruct* quad)
3327 if ( !myNeedSmooth ) return;
3329 // Get nodes to smooth
3331 typedef map< const SMDS_MeshNode*, TSmoothNode, TIDCompare > TNo2SmooNoMap;
3332 TNo2SmooNoMap smooNoMap;
3334 const TopoDS_Face& geomFace = TopoDS::Face( myHelper->GetSubShape() );
3335 SMESHDS_Mesh* meshDS = myHelper->GetMeshDS();
3336 SMESHDS_SubMesh* fSubMesh = meshDS->MeshElements( geomFace );
3337 SMDS_NodeIteratorPtr nIt = fSubMesh->GetNodes();
3338 while ( nIt->more() ) // loop on nodes bound to a FACE
3340 const SMDS_MeshNode* node = nIt->next();
3341 TSmoothNode & sNode = smooNoMap[ node ];
3342 sNode._uv = myHelper->GetNodeUV( geomFace, node );
3344 // set sNode._triangles
3345 SMDS_ElemIteratorPtr fIt = node->GetInverseElementIterator( SMDSAbs_Face );
3346 while ( fIt->more() )
3348 const SMDS_MeshElement* face = fIt->next();
3349 const int nbN = face->NbCornerNodes();
3350 const int nInd = face->GetNodeIndex( node );
3351 const int prevInd = myHelper->WrapIndex( nInd - 1, nbN );
3352 const int nextInd = myHelper->WrapIndex( nInd + 1, nbN );
3353 const SMDS_MeshNode* prevNode = face->GetNode( prevInd );
3354 const SMDS_MeshNode* nextNode = face->GetNode( nextInd );
3355 sNode._triangles.push_back( TTriangle( & smooNoMap[ prevNode ],
3356 & smooNoMap[ nextNode ]));
3359 // set _uv of smooth nodes on FACE boundary
3360 for ( unsigned i = 0; i < quad->side.size(); ++i )
3362 const vector<UVPtStruct>& uvVec = quad->side[i]->GetUVPtStruct();
3363 for ( unsigned j = 0; j < uvVec.size(); ++j )
3365 TSmoothNode & sNode = smooNoMap[ uvVec[j].node ];
3366 sNode._uv.SetCoord( uvVec[j].u, uvVec[j].v );
3370 // define refernce orientation in 2D
3371 TNo2SmooNoMap::iterator n2sn = smooNoMap.begin();
3372 for ( ; n2sn != smooNoMap.end(); ++n2sn )
3373 if ( !n2sn->second._triangles.empty() )
3375 if ( n2sn == smooNoMap.end() ) return;
3376 const TSmoothNode & sampleNode = n2sn->second;
3377 const bool refForward = ( sampleNode._triangles[0].IsForward( sampleNode._uv ));
3381 for ( int iLoop = 0; iLoop < 5; ++iLoop )
3383 for ( n2sn = smooNoMap.begin(); n2sn != smooNoMap.end(); ++n2sn )
3385 TSmoothNode& sNode = n2sn->second;
3386 if ( sNode._triangles.empty() )
3387 continue; // not movable node
3391 for ( unsigned i = 0; i < sNode._triangles.size(); ++i )
3392 newUV += sNode._triangles[i]._n1->_uv;
3393 newUV /= sNode._triangles.size();
3395 // check validity of the newUV
3396 bool isValid = true;
3397 for ( unsigned i = 0; i < sNode._triangles.size() && isValid; ++i )
3398 isValid = ( sNode._triangles[i].IsForward( newUV ) == refForward );
3405 // Set new XYZ to the smoothed nodes
3407 Handle(Geom_Surface) surface = BRep_Tool::Surface( geomFace );
3409 for ( n2sn = smooNoMap.begin(); n2sn != smooNoMap.end(); ++n2sn )
3411 TSmoothNode& sNode = n2sn->second;
3412 if ( sNode._triangles.empty() )
3413 continue; // not movable node
3415 SMDS_MeshNode* node = const_cast< SMDS_MeshNode*>( n2sn->first );
3416 gp_Pnt xyz = surface->Value( sNode._uv.X(), sNode._uv.Y() );
3417 meshDS->MoveNode( node, xyz.X(), xyz.Y(), xyz.Z() );
3420 node->SetPosition( SMDS_PositionPtr( new SMDS_FacePosition( sNode._uv.X(), sNode._uv.Y() )));
3423 // Move medium nodes in quadratic mesh
3424 if ( _quadraticMesh )
3426 const TLinkNodeMap& links = myHelper->GetTLinkNodeMap();
3427 TLinkNodeMap::const_iterator linkIt = links.begin();
3428 for ( ; linkIt != links.end(); ++linkIt )
3430 const SMESH_TLink& link = linkIt->first;
3431 SMDS_MeshNode* node = const_cast< SMDS_MeshNode*>( linkIt->second );
3433 if ( node->getshapeId() != myHelper->GetSubShapeID() )
3434 continue; // medium node is on EDGE or VERTEX
3436 gp_XY uv1 = myHelper->GetNodeUV( geomFace, link.node1(), node );
3437 gp_XY uv2 = myHelper->GetNodeUV( geomFace, link.node2(), node );
3439 gp_XY uv = myHelper->GetMiddleUV( surface, uv1, uv2 );
3440 node->SetPosition( SMDS_PositionPtr( new SMDS_FacePosition( uv.X(), uv.Y() )));
3442 gp_Pnt xyz = surface->Value( uv.X(), uv.Y() );
3443 meshDS->MoveNode( node, xyz.X(), xyz.Y(), xyz.Z() );