1 // Copyright (C) 2007-2010 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 // SMESH SMESH : implementaion of SMESH idl descriptions
24 // File : StdMeshers_Quadrangle_2D.cxx
25 // Moved here from SMESH_Quadrangle_2D.cxx
26 // Author : Paul RASCLE, EDF
29 #include "StdMeshers_Quadrangle_2D.hxx"
31 #include "StdMeshers_FaceSide.hxx"
33 #include "StdMeshers_QuadrangleParams.hxx"
35 #include "SMESH_Gen.hxx"
36 #include "SMESH_Mesh.hxx"
37 #include "SMESH_subMesh.hxx"
38 #include "SMESH_MesherHelper.hxx"
39 #include "SMESH_Block.hxx"
40 #include "SMESH_Comment.hxx"
42 #include "SMDS_MeshElement.hxx"
43 #include "SMDS_MeshNode.hxx"
44 #include "SMDS_EdgePosition.hxx"
45 #include "SMDS_FacePosition.hxx"
47 #include <BRep_Tool.hxx>
48 #include <Geom_Surface.hxx>
49 #include <NCollection_DefineArray2.hxx>
50 #include <Precision.hxx>
51 #include <TColStd_SequenceOfReal.hxx>
52 #include <TColgp_SequenceOfXY.hxx>
54 #include <TopExp_Explorer.hxx>
55 #include <TopTools_ListIteratorOfListOfShape.hxx>
56 #include <TopTools_MapOfShape.hxx>
59 #include "utilities.h"
60 #include "Utils_ExceptHandlers.hxx"
62 #ifndef StdMeshers_Array2OfNode_HeaderFile
63 #define StdMeshers_Array2OfNode_HeaderFile
64 typedef const SMDS_MeshNode* SMDS_MeshNodePtr;
65 DEFINE_BASECOLLECTION (StdMeshers_BaseCollectionNodePtr, SMDS_MeshNodePtr)
66 DEFINE_ARRAY2(StdMeshers_Array2OfNode,
67 StdMeshers_BaseCollectionNodePtr, SMDS_MeshNodePtr)
73 typedef SMESH_Comment TComm;
75 //=============================================================================
79 //=============================================================================
81 StdMeshers_Quadrangle_2D::StdMeshers_Quadrangle_2D (int hypId, int studyId,
83 : SMESH_2D_Algo(hypId, studyId, gen)
85 MESSAGE("StdMeshers_Quadrangle_2D::StdMeshers_Quadrangle_2D");
86 _name = "Quadrangle_2D";
87 _shapeType = (1 << TopAbs_FACE);
88 _compatibleHypothesis.push_back("QuadrangleParams");
89 _compatibleHypothesis.push_back("QuadranglePreference");
90 _compatibleHypothesis.push_back("TrianglePreference");
94 //=============================================================================
98 //=============================================================================
100 StdMeshers_Quadrangle_2D::~StdMeshers_Quadrangle_2D()
102 MESSAGE("StdMeshers_Quadrangle_2D::~StdMeshers_Quadrangle_2D");
105 //=============================================================================
109 //=============================================================================
111 bool StdMeshers_Quadrangle_2D::CheckHypothesis
113 const TopoDS_Shape& aShape,
114 SMESH_Hypothesis::Hypothesis_Status& aStatus)
117 aStatus = SMESH_Hypothesis::HYP_OK;
119 const list <const SMESHDS_Hypothesis * >&hyps =
120 GetUsedHypothesis(aMesh, aShape, false);
121 const SMESHDS_Hypothesis *theHyp = 0;
123 if( hyps.size() == 1 ) {
125 theHyp = hyps.front();
126 if(strcmp("QuadrangleParams", theHyp->GetName()) == 0) {
127 const StdMeshers_QuadrangleParams* theHyp1 =
128 (const StdMeshers_QuadrangleParams*)theHyp;
129 myTriaVertexID = theHyp1->GetTriaVertex();
130 myQuadranglePreference= false;
131 myTrianglePreference= false;
133 if(strcmp("QuadranglePreference", theHyp->GetName()) == 0) {
134 myQuadranglePreference= true;
135 myTrianglePreference= false;
138 else if(strcmp("TrianglePreference", theHyp->GetName()) == 0){
139 myQuadranglePreference= false;
140 myTrianglePreference= true;
145 else if( hyps.size() > 1 ) {
146 theHyp = hyps.front();
147 if(strcmp("QuadrangleParams", theHyp->GetName()) == 0) {
148 const StdMeshers_QuadrangleParams* theHyp1 =
149 (const StdMeshers_QuadrangleParams*)theHyp;
150 myTriaVertexID = theHyp1->GetTriaVertex();
151 theHyp = hyps.back();
152 if(strcmp("QuadranglePreference", theHyp->GetName()) == 0) {
153 myQuadranglePreference= true;
154 myTrianglePreference= false;
156 else if(strcmp("TrianglePreference", theHyp->GetName()) == 0){
157 myQuadranglePreference= false;
158 myTrianglePreference= true;
162 if(strcmp("QuadranglePreference", theHyp->GetName()) == 0) {
163 myQuadranglePreference= true;
164 myTrianglePreference= false;
166 else if(strcmp("TrianglePreference", theHyp->GetName()) == 0){
167 myQuadranglePreference= false;
168 myTrianglePreference= true;
170 const StdMeshers_QuadrangleParams* theHyp2 =
171 (const StdMeshers_QuadrangleParams*)hyps.back();
172 myTriaVertexID = theHyp2->GetTriaVertex();
177 myQuadranglePreference = false;
178 myTrianglePreference = false;
185 //=============================================================================
189 //=============================================================================
191 bool StdMeshers_Quadrangle_2D::Compute (SMESH_Mesh& aMesh,
192 const TopoDS_Shape& aShape)// throw (SALOME_Exception)
194 // PAL14921. Enable catching std::bad_alloc and Standard_OutOfMemory outside
195 //Unexpect aCatchSalomeException);
197 SMESHDS_Mesh * meshDS = aMesh.GetMeshDS();
198 aMesh.GetSubMesh(aShape);
200 SMESH_MesherHelper helper(aMesh);
203 _quadraticMesh = myTool->IsQuadraticSubMesh(aShape);
205 FaceQuadStruct *quad = CheckNbEdges( aMesh, aShape );
206 std::auto_ptr<FaceQuadStruct> quadDeleter( quad ); // to delete quad at exit from Compute()
210 if(myQuadranglePreference) {
211 int n1 = quad->side[0]->NbPoints();
212 int n2 = quad->side[1]->NbPoints();
213 int n3 = quad->side[2]->NbPoints();
214 int n4 = quad->side[3]->NbPoints();
215 int nfull = n1+n2+n3+n4;
218 if( nfull==ntmp && ( (n1!=n3) || (n2!=n4) ) ) {
219 // special path for using only quandrangle faces
220 bool ok = ComputeQuadPref(aMesh, aShape, quad);
225 // set normalized grid on unit square in parametric domain
227 if (!SetNormalizedGrid(aMesh, aShape, quad))
230 // --- compute 3D values on points, store points & quadrangles
232 int nbdown = quad->side[0]->NbPoints();
233 int nbup = quad->side[2]->NbPoints();
235 int nbright = quad->side[1]->NbPoints();
236 int nbleft = quad->side[3]->NbPoints();
238 int nbhoriz = Min(nbdown, nbup);
239 int nbvertic = Min(nbright, nbleft);
241 const TopoDS_Face& F = TopoDS::Face(aShape);
242 Handle(Geom_Surface) S = BRep_Tool::Surface(F);
244 // internal mesh nodes
245 int i, j, geomFaceID = meshDS->ShapeToIndex( F );
246 for (i = 1; i < nbhoriz - 1; i++) {
247 for (j = 1; j < nbvertic - 1; j++) {
248 int ij = j * nbhoriz + i;
249 double u = quad->uv_grid[ij].u;
250 double v = quad->uv_grid[ij].v;
251 gp_Pnt P = S->Value(u, v);
252 SMDS_MeshNode * node = meshDS->AddNode(P.X(), P.Y(), P.Z());
253 meshDS->SetNodeOnFace(node, geomFaceID, u, v);
254 quad->uv_grid[ij].node = node;
261 // --.--.--.--.--.-- nbvertic
267 // ---.----.----.--- 0
268 // 0 > > > > > > > > nbhoriz
274 int iup = nbhoriz - 1;
275 if (quad->isEdgeOut[3]) { ilow++; } else { if (quad->isEdgeOut[1]) iup--; }
278 int jup = nbvertic - 1;
279 if (quad->isEdgeOut[0]) { jlow++; } else { if (quad->isEdgeOut[2]) jup--; }
281 // regular quadrangles
282 for (i = ilow; i < iup; i++) {
283 for (j = jlow; j < jup; j++) {
284 const SMDS_MeshNode *a, *b, *c, *d;
285 a = quad->uv_grid[j * nbhoriz + i].node;
286 b = quad->uv_grid[j * nbhoriz + i + 1].node;
287 c = quad->uv_grid[(j + 1) * nbhoriz + i + 1].node;
288 d = quad->uv_grid[(j + 1) * nbhoriz + i].node;
289 SMDS_MeshFace* face = myTool->AddFace(a, b, c, d);
291 meshDS->SetMeshElementOnShape(face, geomFaceID);
296 const vector<UVPtStruct>& uv_e0 = quad->side[0]->GetUVPtStruct(true,0 );
297 const vector<UVPtStruct>& uv_e1 = quad->side[1]->GetUVPtStruct(false,1);
298 const vector<UVPtStruct>& uv_e2 = quad->side[2]->GetUVPtStruct(true,1 );
299 const vector<UVPtStruct>& uv_e3 = quad->side[3]->GetUVPtStruct(false,0);
301 if ( uv_e0.empty() || uv_e1.empty() || uv_e2.empty() || uv_e3.empty() )
302 return error( COMPERR_BAD_INPUT_MESH );
304 double eps = Precision::Confusion();
306 // Boundary quadrangles
308 if (quad->isEdgeOut[0]) {
311 // |___|___|___|___|___|___|
313 // |___|___|___|___|___|___|
315 // |___|___|___|___|___|___| __ first row of the regular grid
316 // . . . . . . . . . __ down edge nodes
318 // >->->->->->->->->->->->-> -- direction of processing
320 int g = 0; // number of last processed node in the regular grid
322 // number of last node of the down edge to be processed
323 int stop = nbdown - 1;
324 // if right edge is out, we will stop at a node, previous to the last one
325 if (quad->isEdgeOut[1]) stop--;
327 // for each node of the down edge find nearest node
328 // in the first row of the regular grid and link them
329 for (i = 0; i < stop; i++) {
330 const SMDS_MeshNode *a, *b, *c, *d;
332 b = uv_e0[i + 1].node;
333 gp_Pnt pb (b->X(), b->Y(), b->Z());
335 // find node c in the regular grid, which will be linked with node b
338 // right bound reached, link with the rightmost node
340 c = quad->uv_grid[nbhoriz + iup].node;
343 // find in the grid node c, nearest to the b
344 double mind = RealLast();
345 for (int k = g; k <= iup; k++) {
347 const SMDS_MeshNode *nk;
348 if (k < ilow) // this can be, if left edge is out
349 nk = uv_e3[1].node; // get node from the left edge
351 nk = quad->uv_grid[nbhoriz + k].node; // get one of middle nodes
353 gp_Pnt pnk (nk->X(), nk->Y(), nk->Z());
354 double dist = pb.Distance(pnk);
355 if (dist < mind - eps) {
365 if (near == g) { // make triangle
366 SMDS_MeshFace* face = myTool->AddFace(a, b, c);
367 if(face) meshDS->SetMeshElementOnShape(face, geomFaceID);
369 else { // make quadrangle
373 d = quad->uv_grid[nbhoriz + near - 1].node;
374 //SMDS_MeshFace* face = meshDS->AddFace(a, b, c, d);
376 if(!myTrianglePreference){
377 SMDS_MeshFace* face = myTool->AddFace(a, b, c, d);
378 if(face) meshDS->SetMeshElementOnShape(face, geomFaceID);
381 SplitQuad(meshDS, geomFaceID, a, b, c, d);
384 // if node d is not at position g - make additional triangles
386 for (int k = near - 1; k > g; k--) {
387 c = quad->uv_grid[nbhoriz + k].node;
391 d = quad->uv_grid[nbhoriz + k - 1].node;
392 SMDS_MeshFace* face = myTool->AddFace(a, c, d);
393 if(face) meshDS->SetMeshElementOnShape(face, geomFaceID);
400 if (quad->isEdgeOut[2]) {
403 // <-<-<-<-<-<-<-<-<-<-<-<-< -- direction of processing
405 // . . . . . . . . . __ up edge nodes
406 // ___ ___ ___ ___ ___ ___ __ first row of the regular grid
408 // |___|___|___|___|___|___|
410 // |___|___|___|___|___|___|
413 int g = nbhoriz - 1; // last processed node in the regular grid
416 // if left edge is out, we will stop at a second node
417 if (quad->isEdgeOut[3]) stop++;
419 // for each node of the up edge find nearest node
420 // in the first row of the regular grid and link them
421 for (i = nbup - 1; i > stop; i--) {
422 const SMDS_MeshNode *a, *b, *c, *d;
424 b = uv_e2[i - 1].node;
425 gp_Pnt pb (b->X(), b->Y(), b->Z());
427 // find node c in the grid, which will be linked with node b
429 if (i == stop + 1) { // left bound reached, link with the leftmost node
430 c = quad->uv_grid[nbhoriz*(nbvertic - 2) + ilow].node;
433 // find node c in the grid, nearest to the b
434 double mind = RealLast();
435 for (int k = g; k >= ilow; k--) {
436 const SMDS_MeshNode *nk;
438 nk = uv_e1[nbright - 2].node;
440 nk = quad->uv_grid[nbhoriz*(nbvertic - 2) + k].node;
441 gp_Pnt pnk (nk->X(), nk->Y(), nk->Z());
442 double dist = pb.Distance(pnk);
443 if (dist < mind - eps) {
453 if (near == g) { // make triangle
454 SMDS_MeshFace* face = myTool->AddFace(a, b, c);
455 if(face) meshDS->SetMeshElementOnShape(face, geomFaceID);
457 else { // make quadrangle
459 d = uv_e1[nbright - 2].node;
461 d = quad->uv_grid[nbhoriz*(nbvertic - 2) + near + 1].node;
462 //SMDS_MeshFace* face = meshDS->AddFace(a, b, c, d);
463 if(!myTrianglePreference){
464 SMDS_MeshFace* face = myTool->AddFace(a, b, c, d);
465 if(face) meshDS->SetMeshElementOnShape(face, geomFaceID);
468 SplitQuad(meshDS, geomFaceID, a, b, c, d);
471 if (near + 1 < g) { // if d not is at g - make additional triangles
472 for (int k = near + 1; k < g; k++) {
473 c = quad->uv_grid[nbhoriz*(nbvertic - 2) + k].node;
475 d = uv_e1[nbright - 2].node;
477 d = quad->uv_grid[nbhoriz*(nbvertic - 2) + k + 1].node;
478 SMDS_MeshFace* face = myTool->AddFace(a, c, d);
479 if(face) meshDS->SetMeshElementOnShape(face, geomFaceID);
488 // right or left boundary quadrangles
489 if (quad->isEdgeOut[1]) {
490 // MESSAGE("right edge is out");
491 int g = 0; // last processed node in the grid
492 int stop = nbright - 1;
493 if (quad->isEdgeOut[2]) stop--;
494 for (i = 0; i < stop; i++) {
495 const SMDS_MeshNode *a, *b, *c, *d;
497 b = uv_e1[i + 1].node;
498 gp_Pnt pb (b->X(), b->Y(), b->Z());
500 // find node c in the grid, nearest to the b
502 if (i == stop - 1) { // up bondary reached
503 c = quad->uv_grid[nbhoriz*(jup + 1) - 2].node;
506 double mind = RealLast();
507 for (int k = g; k <= jup; k++) {
508 const SMDS_MeshNode *nk;
510 nk = uv_e0[nbdown - 2].node;
512 nk = quad->uv_grid[nbhoriz*(k + 1) - 2].node;
513 gp_Pnt pnk (nk->X(), nk->Y(), nk->Z());
514 double dist = pb.Distance(pnk);
515 if (dist < mind - eps) {
525 if (near == g) { // make triangle
526 SMDS_MeshFace* face = myTool->AddFace(a, b, c);
527 if(face) meshDS->SetMeshElementOnShape(face, geomFaceID);
529 else { // make quadrangle
531 d = uv_e0[nbdown - 2].node;
533 d = quad->uv_grid[nbhoriz*near - 2].node;
534 //SMDS_MeshFace* face = meshDS->AddFace(a, b, c, d);
536 if(!myTrianglePreference){
537 SMDS_MeshFace* face = myTool->AddFace(a, b, c, d);
538 if(face) meshDS->SetMeshElementOnShape(face, geomFaceID);
541 SplitQuad(meshDS, geomFaceID, a, b, c, d);
544 if (near - 1 > g) { // if d not is at g - make additional triangles
545 for (int k = near - 1; k > g; k--) {
546 c = quad->uv_grid[nbhoriz*(k + 1) - 2].node;
548 d = uv_e0[nbdown - 2].node;
550 d = quad->uv_grid[nbhoriz*k - 2].node;
551 SMDS_MeshFace* face = myTool->AddFace(a, c, d);
552 if(face) meshDS->SetMeshElementOnShape(face, geomFaceID);
559 if (quad->isEdgeOut[3]) {
560 // MESSAGE("left edge is out");
561 int g = nbvertic - 1; // last processed node in the grid
563 if (quad->isEdgeOut[0]) stop++;
564 for (i = nbleft - 1; i > stop; i--) {
565 const SMDS_MeshNode *a, *b, *c, *d;
567 b = uv_e3[i - 1].node;
568 gp_Pnt pb (b->X(), b->Y(), b->Z());
570 // find node c in the grid, nearest to the b
572 if (i == stop + 1) { // down bondary reached
573 c = quad->uv_grid[nbhoriz*jlow + 1].node;
576 double mind = RealLast();
577 for (int k = g; k >= jlow; k--) {
578 const SMDS_MeshNode *nk;
582 nk = quad->uv_grid[nbhoriz*k + 1].node;
583 gp_Pnt pnk (nk->X(), nk->Y(), nk->Z());
584 double dist = pb.Distance(pnk);
585 if (dist < mind - eps) {
595 if (near == g) { // make triangle
596 SMDS_MeshFace* face = myTool->AddFace(a, b, c);
597 if(face) meshDS->SetMeshElementOnShape(face, geomFaceID);
599 else { // make quadrangle
603 d = quad->uv_grid[nbhoriz*(near + 1) + 1].node;
604 //SMDS_MeshFace* face = meshDS->AddFace(a, b, c, d);
605 if(!myTrianglePreference){
606 SMDS_MeshFace* face = myTool->AddFace(a, b, c, d);
607 if(face) meshDS->SetMeshElementOnShape(face, geomFaceID);
610 SplitQuad(meshDS, geomFaceID, a, b, c, d);
613 if (near + 1 < g) { // if d not is at g - make additional triangles
614 for (int k = near + 1; k < g; k++) {
615 c = quad->uv_grid[nbhoriz*k + 1].node;
619 d = quad->uv_grid[nbhoriz*(k + 1) + 1].node;
620 SMDS_MeshFace* face = myTool->AddFace(a, c, d);
621 if(face) meshDS->SetMeshElementOnShape(face, geomFaceID);
635 //=============================================================================
639 //=============================================================================
641 bool StdMeshers_Quadrangle_2D::Evaluate(SMESH_Mesh& aMesh,
642 const TopoDS_Shape& aShape,
643 MapShapeNbElems& aResMap)
646 aMesh.GetSubMesh(aShape);
648 std::vector<int> aNbNodes(4);
649 bool IsQuadratic = false;
650 if( !CheckNbEdgesForEvaluate( aMesh, aShape, aResMap, aNbNodes, IsQuadratic ) ) {
651 std::vector<int> aResVec(SMDSEntity_Last);
652 for(int i=SMDSEntity_Node; i<SMDSEntity_Last; i++) aResVec[i] = 0;
653 SMESH_subMesh * sm = aMesh.GetSubMesh(aShape);
654 aResMap.insert(std::make_pair(sm,aResVec));
655 SMESH_ComputeErrorPtr& smError = sm->GetComputeError();
656 smError.reset( new SMESH_ComputeError(COMPERR_ALGO_FAILED,"Submesh can not be evaluated",this));
660 if(myQuadranglePreference) {
661 int n1 = aNbNodes[0];
662 int n2 = aNbNodes[1];
663 int n3 = aNbNodes[2];
664 int n4 = aNbNodes[3];
665 int nfull = n1+n2+n3+n4;
668 if( nfull==ntmp && ( (n1!=n3) || (n2!=n4) ) ) {
669 // special path for using only quandrangle faces
670 return EvaluateQuadPref(aMesh, aShape, aNbNodes, aResMap, IsQuadratic);
675 int nbdown = aNbNodes[0];
676 int nbup = aNbNodes[2];
678 int nbright = aNbNodes[1];
679 int nbleft = aNbNodes[3];
681 int nbhoriz = Min(nbdown, nbup);
682 int nbvertic = Min(nbright, nbleft);
684 int dh = Max(nbdown, nbup) - nbhoriz;
685 int dv = Max(nbright, nbleft) - nbvertic;
692 int nbNodes = (nbhoriz-2)*(nbvertic-2);
693 //int nbFaces3 = dh + dv + kdh*(nbvertic-1)*2 + kdv*(nbhoriz-1)*2;
694 int nbFaces3 = dh + dv;
695 //if( kdh==1 && kdv==1 ) nbFaces3 -= 2;
696 //if( dh>0 && dv>0 ) nbFaces3 -= 2;
697 //int nbFaces4 = (nbhoriz-1-kdh)*(nbvertic-1-kdv);
698 int nbFaces4 = (nbhoriz-1)*(nbvertic-1);
700 std::vector<int> aVec(SMDSEntity_Last);
701 for(int i=SMDSEntity_Node; i<SMDSEntity_Last; i++) aVec[i] = 0;
703 aVec[SMDSEntity_Quad_Triangle] = nbFaces3;
704 aVec[SMDSEntity_Quad_Quadrangle] = nbFaces4;
705 int nbbndedges = nbdown + nbup + nbright + nbleft -4;
706 int nbintedges = ( nbFaces4*4 + nbFaces3*3 - nbbndedges ) / 2;
707 aVec[SMDSEntity_Node] = nbNodes + nbintedges;
708 if( aNbNodes.size()==5 ) {
709 aVec[SMDSEntity_Quad_Triangle] = nbFaces3 + aNbNodes[3] -1;
710 aVec[SMDSEntity_Quad_Quadrangle] = nbFaces4 - aNbNodes[3] +1;
714 aVec[SMDSEntity_Node] = nbNodes;
715 aVec[SMDSEntity_Triangle] = nbFaces3;
716 aVec[SMDSEntity_Quadrangle] = nbFaces4;
717 if( aNbNodes.size()==5 ) {
718 aVec[SMDSEntity_Triangle] = nbFaces3 + aNbNodes[3] - 1;
719 aVec[SMDSEntity_Quadrangle] = nbFaces4 - aNbNodes[3] + 1;
722 SMESH_subMesh * sm = aMesh.GetSubMesh(aShape);
723 aResMap.insert(std::make_pair(sm,aVec));
729 //================================================================================
731 * \brief Return true if only two given edges meat at their common vertex
733 //================================================================================
735 static bool twoEdgesMeatAtVertex(const TopoDS_Edge& e1,
736 const TopoDS_Edge& e2,
740 if ( !TopExp::CommonVertex( e1, e2, v ))
742 TopTools_ListIteratorOfListOfShape ancestIt( mesh.GetAncestors( v ));
743 for ( ; ancestIt.More() ; ancestIt.Next() )
744 if ( ancestIt.Value().ShapeType() == TopAbs_EDGE )
745 if ( !e1.IsSame( ancestIt.Value() ) && !e2.IsSame( ancestIt.Value() ))
750 //=============================================================================
754 //=============================================================================
756 FaceQuadStruct* StdMeshers_Quadrangle_2D::CheckNbEdges(SMESH_Mesh & aMesh,
757 const TopoDS_Shape & aShape)
758 //throw(SALOME_Exception)
760 TopoDS_Face F = TopoDS::Face(aShape);
761 if ( F.Orientation() >= TopAbs_INTERNAL ) F.Orientation( TopAbs_FORWARD );
762 const bool ignoreMediumNodes = _quadraticMesh;
764 // verify 1 wire only, with 4 edges
766 list< TopoDS_Edge > edges;
767 list< int > nbEdgesInWire;
768 int nbWire = SMESH_Block::GetOrderedEdges (F, V, edges, nbEdgesInWire);
770 error(COMPERR_BAD_SHAPE, TComm("Wrong number of wires: ") << nbWire);
773 FaceQuadStruct* quad = new FaceQuadStruct;
775 quad->side.reserve(nbEdgesInWire.front());
778 list< TopoDS_Edge >::iterator edgeIt = edges.begin();
779 if ( nbEdgesInWire.front() == 3 ) // exactly 3 edges
781 SMESH_Comment comment;
782 SMESHDS_Mesh* meshDS = aMesh.GetMeshDS();
783 if ( myTriaVertexID == -1)
785 comment << "No Base vertex parameter provided for a trilateral geometrical face";
789 TopoDS_Vertex V = TopoDS::Vertex(meshDS->IndexToShape(myTriaVertexID));
791 TopoDS_Edge E1,E2,E3;
792 for(; edgeIt != edges.end(); ++edgeIt) {
793 TopoDS_Edge E = *edgeIt;
794 TopoDS_Vertex VF, VL;
795 TopExp::Vertices(E, VF, VL, true);
798 else if( VL.IsSame(V) )
803 if ( !E1.IsNull() && !E2.IsNull() && !E3.IsNull() )
805 quad->side.push_back( new StdMeshers_FaceSide(F, E1, &aMesh, true, ignoreMediumNodes));
806 quad->side.push_back( new StdMeshers_FaceSide(F, E2, &aMesh, true, ignoreMediumNodes));
807 quad->side.push_back( new StdMeshers_FaceSide(F, E3, &aMesh, false,ignoreMediumNodes));
808 const vector<UVPtStruct>& UVPSleft = quad->side[0]->GetUVPtStruct(true,0);
809 /* vector<UVPtStruct>& UVPStop = */quad->side[1]->GetUVPtStruct(false,1);
810 /* vector<UVPtStruct>& UVPSright = */quad->side[2]->GetUVPtStruct(true,1);
811 const SMDS_MeshNode* aNode = UVPSleft[0].node;
812 gp_Pnt2d aPnt2d( UVPSleft[0].u, UVPSleft[0].v );
813 quad->side.push_back( new StdMeshers_FaceSide(aNode, aPnt2d, quad->side[1]));
817 comment << "Invalid Base vertex parameter: " << myTriaVertexID << " is not among [";
818 TopTools_MapOfShape vMap;
819 for ( TopExp_Explorer v( aShape, TopAbs_VERTEX ); v.More(); v.Next())
820 if ( vMap.Add( v.Current() ))
821 comment << meshDS->ShapeToIndex( v.Current() ) << ( vMap.Extent()==3 ? "]" : ", ");
827 else if ( nbEdgesInWire.front() == 4 ) { // exactly 4 edges
828 for ( ; edgeIt != edges.end(); ++edgeIt, nbSides++ )
829 quad->side.push_back( new StdMeshers_FaceSide(F, *edgeIt, &aMesh,
830 nbSides<TOP_SIDE, ignoreMediumNodes));
832 else if ( nbEdgesInWire.front() > 4 ) { // more than 4 edges - try to unite some
833 list< TopoDS_Edge > sideEdges;
834 while ( !edges.empty()) {
836 sideEdges.splice( sideEdges.end(), edges, edges.begin()); // edges.front() -> sideEdges.end()
837 bool sameSide = true;
838 while ( !edges.empty() && sameSide ) {
839 sameSide = SMESH_Algo::IsContinuous( sideEdges.back(), edges.front() );
841 sideEdges.splice( sideEdges.end(), edges, edges.begin());
843 if ( nbSides == 0 ) { // go backward from the first edge
845 while ( !edges.empty() && sameSide ) {
846 sameSide = SMESH_Algo::IsContinuous( sideEdges.front(), edges.back() );
848 sideEdges.splice( sideEdges.begin(), edges, --edges.end());
851 quad->side.push_back( new StdMeshers_FaceSide(F, sideEdges, &aMesh,
852 nbSides<TOP_SIDE, ignoreMediumNodes));
855 // issue 20222. Try to unite only edges shared by two same faces
857 // delete found sides
858 { FaceQuadStruct cleaner( *quad ); }
860 quad->side.reserve(nbEdgesInWire.front());
863 SMESH_Block::GetOrderedEdges (F, V, edges, nbEdgesInWire);
864 while ( !edges.empty()) {
866 sideEdges.splice( sideEdges.end(), edges, edges.begin());
867 bool sameSide = true;
868 while ( !edges.empty() && sameSide ) {
870 SMESH_Algo::IsContinuous( sideEdges.back(), edges.front() ) &&
871 twoEdgesMeatAtVertex( sideEdges.back(), edges.front(), aMesh );
873 sideEdges.splice( sideEdges.end(), edges, edges.begin());
875 if ( nbSides == 0 ) { // go backward from the first edge
877 while ( !edges.empty() && sameSide ) {
879 SMESH_Algo::IsContinuous( sideEdges.front(), edges.back() ) &&
880 twoEdgesMeatAtVertex( sideEdges.front(), edges.back(), aMesh );
882 sideEdges.splice( sideEdges.begin(), edges, --edges.end());
885 quad->side.push_back( new StdMeshers_FaceSide(F, sideEdges, &aMesh,
886 nbSides<TOP_SIDE, ignoreMediumNodes));
893 MESSAGE ( "StdMeshers_Quadrangle_2D. Edge IDs of " << nbSides << " sides:\n" );
894 for ( int i = 0; i < nbSides; ++i ) {
896 for ( int e = 0; e < quad->side[i]->NbEdges(); ++e )
897 MESSAGE ( myTool->GetMeshDS()->ShapeToIndex( quad->side[i]->Edge( e )) << " " );
903 nbSides = nbEdgesInWire.front();
904 error(COMPERR_BAD_SHAPE, TComm("Face must have 4 sides but not ") << nbSides);
913 //=============================================================================
917 //=============================================================================
919 bool StdMeshers_Quadrangle_2D::CheckNbEdgesForEvaluate(SMESH_Mesh& aMesh,
920 const TopoDS_Shape & aShape,
921 MapShapeNbElems& aResMap,
922 std::vector<int>& aNbNodes,
926 const TopoDS_Face & F = TopoDS::Face(aShape);
928 // verify 1 wire only, with 4 edges
930 list< TopoDS_Edge > edges;
931 list< int > nbEdgesInWire;
932 int nbWire = SMESH_Block::GetOrderedEdges (F, V, edges, nbEdgesInWire);
940 list< TopoDS_Edge >::iterator edgeIt = edges.begin();
941 SMESH_subMesh * sm = aMesh.GetSubMesh( *edgeIt );
942 MapShapeNbElemsItr anIt = aResMap.find(sm);
943 if(anIt==aResMap.end()) {
946 std::vector<int> aVec = (*anIt).second;
947 IsQuadratic = (aVec[SMDSEntity_Quad_Edge] > aVec[SMDSEntity_Edge]);
948 if ( nbEdgesInWire.front() == 3 ) { // exactly 3 edges
949 if(myTriaVertexID>0) {
950 SMESHDS_Mesh* meshDS = aMesh.GetMeshDS();
951 TopoDS_Vertex V = TopoDS::Vertex(meshDS->IndexToShape(myTriaVertexID));
953 TopoDS_Edge E1,E2,E3;
954 for(; edgeIt != edges.end(); ++edgeIt) {
955 TopoDS_Edge E = TopoDS::Edge(*edgeIt);
956 TopoDS_Vertex VF, VL;
957 TopExp::Vertices(E, VF, VL, true);
960 else if( VL.IsSame(V) )
965 SMESH_subMesh * sm = aMesh.GetSubMesh(E1);
966 MapShapeNbElemsItr anIt = aResMap.find(sm);
967 if(anIt==aResMap.end()) return false;
968 std::vector<int> aVec = (*anIt).second;
970 aNbNodes[0] = (aVec[SMDSEntity_Node]-1)/2 + 2;
972 aNbNodes[0] = aVec[SMDSEntity_Node] + 2;
973 sm = aMesh.GetSubMesh(E2);
974 anIt = aResMap.find(sm);
975 if(anIt==aResMap.end()) return false;
976 aVec = (*anIt).second;
978 aNbNodes[1] = (aVec[SMDSEntity_Node]-1)/2 + 2;
980 aNbNodes[1] = aVec[SMDSEntity_Node] + 2;
981 sm = aMesh.GetSubMesh(E3);
982 anIt = aResMap.find(sm);
983 if(anIt==aResMap.end()) return false;
984 aVec = (*anIt).second;
986 aNbNodes[2] = (aVec[SMDSEntity_Node]-1)/2 + 2;
988 aNbNodes[2] = aVec[SMDSEntity_Node] + 2;
989 aNbNodes[3] = aNbNodes[1];
995 if ( nbEdgesInWire.front() == 4 ) { // exactly 4 edges
996 for(; edgeIt != edges.end(); edgeIt++) {
997 SMESH_subMesh * sm = aMesh.GetSubMesh( *edgeIt );
998 MapShapeNbElemsItr anIt = aResMap.find(sm);
999 if(anIt==aResMap.end()) {
1002 std::vector<int> aVec = (*anIt).second;
1004 aNbNodes[nbSides] = (aVec[SMDSEntity_Node]-1)/2 + 2;
1006 aNbNodes[nbSides] = aVec[SMDSEntity_Node] + 2;
1010 else if ( nbEdgesInWire.front() > 4 ) { // more than 4 edges - try to unite some
1011 list< TopoDS_Edge > sideEdges;
1012 while ( !edges.empty()) {
1014 sideEdges.splice( sideEdges.end(), edges, edges.begin()); // edges.front() -> sideEdges.end()
1015 bool sameSide = true;
1016 while ( !edges.empty() && sameSide ) {
1017 sameSide = SMESH_Algo::IsContinuous( sideEdges.back(), edges.front() );
1019 sideEdges.splice( sideEdges.end(), edges, edges.begin());
1021 if ( nbSides == 0 ) { // go backward from the first edge
1023 while ( !edges.empty() && sameSide ) {
1024 sameSide = SMESH_Algo::IsContinuous( sideEdges.front(), edges.back() );
1026 sideEdges.splice( sideEdges.begin(), edges, --edges.end());
1029 list<TopoDS_Edge>::iterator ite = sideEdges.begin();
1030 aNbNodes[nbSides] = 1;
1031 for(; ite!=sideEdges.end(); ite++) {
1032 SMESH_subMesh * sm = aMesh.GetSubMesh( *ite );
1033 MapShapeNbElemsItr anIt = aResMap.find(sm);
1034 if(anIt==aResMap.end()) {
1037 std::vector<int> aVec = (*anIt).second;
1039 aNbNodes[nbSides] += (aVec[SMDSEntity_Node]-1)/2 + 1;
1041 aNbNodes[nbSides] += aVec[SMDSEntity_Node] + 1;
1045 // issue 20222. Try to unite only edges shared by two same faces
1048 SMESH_Block::GetOrderedEdges (F, V, edges, nbEdgesInWire);
1049 while ( !edges.empty()) {
1051 sideEdges.splice( sideEdges.end(), edges, edges.begin());
1052 bool sameSide = true;
1053 while ( !edges.empty() && sameSide ) {
1055 SMESH_Algo::IsContinuous( sideEdges.back(), edges.front() ) &&
1056 twoEdgesMeatAtVertex( sideEdges.back(), edges.front(), aMesh );
1058 sideEdges.splice( sideEdges.end(), edges, edges.begin());
1060 if ( nbSides == 0 ) { // go backward from the first edge
1062 while ( !edges.empty() && sameSide ) {
1064 SMESH_Algo::IsContinuous( sideEdges.front(), edges.back() ) &&
1065 twoEdgesMeatAtVertex( sideEdges.front(), edges.back(), aMesh );
1067 sideEdges.splice( sideEdges.begin(), edges, --edges.end());
1070 list<TopoDS_Edge>::iterator ite = sideEdges.begin();
1071 aNbNodes[nbSides] = 1;
1072 for(; ite!=sideEdges.end(); ite++) {
1073 SMESH_subMesh * sm = aMesh.GetSubMesh( *ite );
1074 MapShapeNbElemsItr anIt = aResMap.find(sm);
1075 if(anIt==aResMap.end()) {
1078 std::vector<int> aVec = (*anIt).second;
1080 aNbNodes[nbSides] += (aVec[SMDSEntity_Node]-1)/2 + 1;
1082 aNbNodes[nbSides] += aVec[SMDSEntity_Node] + 1;
1090 nbSides = nbEdgesInWire.front();
1091 error(COMPERR_BAD_SHAPE, TComm("Face must have 4 sides but not ") << nbSides);
1099 //=============================================================================
1103 //=============================================================================
1105 FaceQuadStruct *StdMeshers_Quadrangle_2D::CheckAnd2Dcompute
1106 (SMESH_Mesh & aMesh,
1107 const TopoDS_Shape & aShape,
1108 const bool CreateQuadratic) //throw(SALOME_Exception)
1110 _quadraticMesh = CreateQuadratic;
1112 FaceQuadStruct *quad = CheckNbEdges(aMesh, aShape);
1116 // set normalized grid on unit square in parametric domain
1117 bool stat = SetNormalizedGrid(aMesh, aShape, quad);
1127 //=============================================================================
1131 //=============================================================================
1133 faceQuadStruct::~faceQuadStruct()
1135 for (int i = 0; i < side.size(); i++) {
1136 if (side[i]) delete side[i];
1138 if (uv_grid) delete [] uv_grid;
1142 inline const vector<UVPtStruct>& GetUVPtStructIn(FaceQuadStruct* quad, int i, int nbSeg)
1144 bool isXConst = ( i == BOTTOM_SIDE || i == TOP_SIDE );
1145 double constValue = ( i == BOTTOM_SIDE || i == LEFT_SIDE ) ? 0 : 1;
1147 quad->isEdgeOut[i] ?
1148 quad->side[i]->SimulateUVPtStruct(nbSeg,isXConst,constValue) :
1149 quad->side[i]->GetUVPtStruct(isXConst,constValue);
1153 //=============================================================================
1157 //=============================================================================
1159 bool StdMeshers_Quadrangle_2D::SetNormalizedGrid (SMESH_Mesh & aMesh,
1160 const TopoDS_Shape& aShape,
1161 FaceQuadStruct* & quad) //throw (SALOME_Exception)
1163 // Algorithme décrit dans "Génération automatique de maillages"
1164 // P.L. GEORGE, MASSON, § 6.4.1 p. 84-85
1165 // traitement dans le domaine paramétrique 2d u,v
1166 // transport - projection sur le carré unité
1168 // MESSAGE("StdMeshers_Quadrangle_2D::SetNormalizedGrid");
1169 // const TopoDS_Face& F = TopoDS::Face(aShape);
1171 // 1 --- find orientation of the 4 edges, by test on extrema
1174 // |<----north-2-------^ a3 -------------> a2
1176 // west-3 east-1 =right | |
1180 // v----south-0--------> a0 -------------> a1
1185 // 3 --- 2D normalized values on unit square [0..1][0..1]
1187 int nbhoriz = Min(quad->side[0]->NbPoints(), quad->side[2]->NbPoints());
1188 int nbvertic = Min(quad->side[1]->NbPoints(), quad->side[3]->NbPoints());
1190 quad->isEdgeOut[0] = (quad->side[0]->NbPoints() > quad->side[2]->NbPoints());
1191 quad->isEdgeOut[1] = (quad->side[1]->NbPoints() > quad->side[3]->NbPoints());
1192 quad->isEdgeOut[2] = (quad->side[2]->NbPoints() > quad->side[0]->NbPoints());
1193 quad->isEdgeOut[3] = (quad->side[3]->NbPoints() > quad->side[1]->NbPoints());
1195 UVPtStruct *uv_grid = quad->uv_grid = new UVPtStruct[nbvertic * nbhoriz];
1197 const vector<UVPtStruct>& uv_e0 = GetUVPtStructIn( quad, 0, nbhoriz - 1 );
1198 const vector<UVPtStruct>& uv_e1 = GetUVPtStructIn( quad, 1, nbvertic - 1 );
1199 const vector<UVPtStruct>& uv_e2 = GetUVPtStructIn( quad, 2, nbhoriz - 1 );
1200 const vector<UVPtStruct>& uv_e3 = GetUVPtStructIn( quad, 3, nbvertic - 1 );
1202 if ( uv_e0.empty() || uv_e1.empty() || uv_e2.empty() || uv_e3.empty() )
1203 //return error( "Can't find nodes on sides");
1204 return error( COMPERR_BAD_INPUT_MESH );
1206 // nodes Id on "in" edges
1207 if (! quad->isEdgeOut[0]) {
1209 for (int i = 0; i < nbhoriz; i++) { // down
1210 int ij = j * nbhoriz + i;
1211 uv_grid[ij].node = uv_e0[i].node;
1214 if (! quad->isEdgeOut[1]) {
1215 int i = nbhoriz - 1;
1216 for (int j = 0; j < nbvertic; j++) { // right
1217 int ij = j * nbhoriz + i;
1218 uv_grid[ij].node = uv_e1[j].node;
1221 if (! quad->isEdgeOut[2]) {
1222 int j = nbvertic - 1;
1223 for (int i = 0; i < nbhoriz; i++) { // up
1224 int ij = j * nbhoriz + i;
1225 uv_grid[ij].node = uv_e2[i].node;
1228 if (! quad->isEdgeOut[3]) {
1230 for (int j = 0; j < nbvertic; j++) { // left
1231 int ij = j * nbhoriz + i;
1232 uv_grid[ij].node = uv_e3[j].node;
1236 // normalized 2d values on grid
1237 for (int i = 0; i < nbhoriz; i++) {
1238 for (int j = 0; j < nbvertic; j++) {
1239 int ij = j * nbhoriz + i;
1240 // --- droite i cste : x = x0 + y(x1-x0)
1241 double x0 = uv_e0[i].normParam; // bas - sud
1242 double x1 = uv_e2[i].normParam; // haut - nord
1243 // --- droite j cste : y = y0 + x(y1-y0)
1244 double y0 = uv_e3[j].normParam; // gauche-ouest
1245 double y1 = uv_e1[j].normParam; // droite - est
1246 // --- intersection : x=x0+(y0+x(y1-y0))(x1-x0)
1247 double x = (x0 + y0 * (x1 - x0)) / (1 - (y1 - y0) * (x1 - x0));
1248 double y = y0 + x * (y1 - y0);
1251 //MESSAGE("-xy-01 "<<x0<<" "<<x1<<" "<<y0<<" "<<y1);
1252 //MESSAGE("-xy-norm "<<i<<" "<<j<<" "<<x<<" "<<y);
1256 // 4 --- projection on 2d domain (u,v)
1257 gp_UV a0( uv_e0.front().u, uv_e0.front().v );
1258 gp_UV a1( uv_e0.back().u, uv_e0.back().v );
1259 gp_UV a2( uv_e2.back().u, uv_e2.back().v );
1260 gp_UV a3( uv_e2.front().u, uv_e2.front().v );
1262 for (int i = 0; i < nbhoriz; i++) {
1263 for (int j = 0; j < nbvertic; j++) {
1264 int ij = j * nbhoriz + i;
1265 double x = uv_grid[ij].x;
1266 double y = uv_grid[ij].y;
1267 double param_0 = uv_e0[0].normParam + x * (uv_e0.back().normParam - uv_e0[0].normParam); // sud
1268 double param_2 = uv_e2[0].normParam + x * (uv_e2.back().normParam - uv_e2[0].normParam); // nord
1269 double param_1 = uv_e1[0].normParam + y * (uv_e1.back().normParam - uv_e1[0].normParam); // est
1270 double param_3 = uv_e3[0].normParam + y * (uv_e3.back().normParam - uv_e3[0].normParam); // ouest
1272 //MESSAGE("params "<<param_0<<" "<<param_1<<" "<<param_2<<" "<<param_3);
1273 gp_UV p0 = quad->side[0]->Value2d(param_0).XY();
1274 gp_UV p1 = quad->side[1]->Value2d(param_1).XY();
1275 gp_UV p2 = quad->side[2]->Value2d(param_2).XY();
1276 gp_UV p3 = quad->side[3]->Value2d(param_3).XY();
1278 gp_UV uv = (1 - y) * p0 + x * p1 + y * p2 + (1 - x) * p3;
1279 uv -= (1 - x) * (1 - y) * a0 + x * (1 - y) * a1 + x * y * a2 + (1 - x) * y * a3;
1281 uv_grid[ij].u = uv.X();
1282 uv_grid[ij].v = uv.Y();
1288 //=======================================================================
1289 //function : ShiftQuad
1290 //purpose : auxilary function for ComputeQuadPref
1291 //=======================================================================
1293 static void ShiftQuad(FaceQuadStruct* quad, const int num, bool)
1295 StdMeshers_FaceSide* side[4] = { quad->side[0], quad->side[1], quad->side[2], quad->side[3] };
1296 for (int i = BOTTOM_SIDE; i < NB_SIDES; ++i ) {
1297 int id = ( i + num ) % NB_SIDES;
1298 bool wasForward = ( i < TOP_SIDE );
1299 bool newForward = ( id < TOP_SIDE );
1300 if ( wasForward != newForward )
1301 side[ i ]->Reverse();
1302 quad->side[ id ] = side[ i ];
1306 //=======================================================================
1308 //purpose : auxilary function for ComputeQuadPref
1309 //=======================================================================
1311 static gp_UV CalcUV(double x0, double x1, double y0, double y1,
1312 FaceQuadStruct* quad,
1313 const gp_UV& a0, const gp_UV& a1,
1314 const gp_UV& a2, const gp_UV& a3)
1316 const vector<UVPtStruct>& uv_eb = quad->side[0]->GetUVPtStruct(true,0 );
1317 const vector<UVPtStruct>& uv_er = quad->side[1]->GetUVPtStruct(false,1);
1318 const vector<UVPtStruct>& uv_et = quad->side[2]->GetUVPtStruct(true,1 );
1319 const vector<UVPtStruct>& uv_el = quad->side[3]->GetUVPtStruct(false,0);
1321 double x = (x0 + y0 * (x1 - x0)) / (1 - (y1 - y0) * (x1 - x0));
1322 double y = y0 + x * (y1 - y0);
1324 double param_b = uv_eb[0].normParam + x * (uv_eb.back().normParam - uv_eb[0].normParam);
1325 double param_t = uv_et[0].normParam + x * (uv_et.back().normParam - uv_et[0].normParam);
1326 double param_r = uv_er[0].normParam + y * (uv_er.back().normParam - uv_er[0].normParam);
1327 double param_l = uv_el[0].normParam + y * (uv_el.back().normParam - uv_el[0].normParam);
1329 gp_UV p0 = quad->side[BOTTOM_SIDE]->Value2d(param_b).XY();
1330 gp_UV p1 = quad->side[RIGHT_SIDE ]->Value2d(param_r).XY();
1331 gp_UV p2 = quad->side[TOP_SIDE ]->Value2d(param_t).XY();
1332 gp_UV p3 = quad->side[LEFT_SIDE ]->Value2d(param_l).XY();
1334 gp_UV uv = p0 * (1 - y) + p1 * x + p2 * y + p3 * (1 - x);
1336 uv -= (1 - x) * (1 - y) * a0 + x * (1 - y) * a1 + x * y * a2 + (1 - x) * y * a3;
1341 //=======================================================================
1342 //function : CalcUV2
1343 //purpose : auxilary function for ComputeQuadPref
1344 //=======================================================================
1346 static gp_UV CalcUV2(double x, double y,
1347 FaceQuadStruct* quad,
1348 const gp_UV& a0, const gp_UV& a1,
1349 const gp_UV& a2, const gp_UV& a3)
1351 const vector<UVPtStruct>& uv_eb = quad->side[0]->GetUVPtStruct(true,0 );
1352 const vector<UVPtStruct>& uv_er = quad->side[1]->GetUVPtStruct(false,1);
1353 const vector<UVPtStruct>& uv_et = quad->side[2]->GetUVPtStruct(true,1 );
1354 const vector<UVPtStruct>& uv_el = quad->side[3]->GetUVPtStruct(false,0);
1356 //double x = (x0 + y0 * (x1 - x0)) / (1 - (y1 - y0) * (x1 - x0));
1357 //double y = y0 + x * (y1 - y0);
1359 double param_b = uv_eb[0].normParam + x * (uv_eb.back().normParam - uv_eb[0].normParam);
1360 double param_t = uv_et[0].normParam + x * (uv_et.back().normParam - uv_et[0].normParam);
1361 double param_r = uv_er[0].normParam + y * (uv_er.back().normParam - uv_er[0].normParam);
1362 double param_l = uv_el[0].normParam + y * (uv_el.back().normParam - uv_el[0].normParam);
1364 gp_UV p0 = quad->side[BOTTOM_SIDE]->Value2d(param_b).XY();
1365 gp_UV p1 = quad->side[RIGHT_SIDE ]->Value2d(param_r).XY();
1366 gp_UV p2 = quad->side[TOP_SIDE ]->Value2d(param_t).XY();
1367 gp_UV p3 = quad->side[LEFT_SIDE ]->Value2d(param_l).XY();
1369 gp_UV uv = p0 * (1 - y) + p1 * x + p2 * y + p3 * (1 - x);
1371 uv -= (1 - x) * (1 - y) * a0 + x * (1 - y) * a1 + x * y * a2 + (1 - x) * y * a3;
1377 //=======================================================================
1379 * Create only quandrangle faces
1381 //=======================================================================
1383 bool StdMeshers_Quadrangle_2D::ComputeQuadPref (SMESH_Mesh & aMesh,
1384 const TopoDS_Shape& aShape,
1385 FaceQuadStruct* quad)
1387 // Auxilary key in order to keep old variant
1388 // of meshing after implementation new variant
1389 // for bug 0016220 from Mantis.
1390 bool OldVersion = false;
1392 SMESHDS_Mesh * meshDS = aMesh.GetMeshDS();
1393 const TopoDS_Face& F = TopoDS::Face(aShape);
1394 Handle(Geom_Surface) S = BRep_Tool::Surface(F);
1395 // const TopoDS_Wire& W = BRepTools::OuterWire(F);
1397 // if(W.Orientation()==TopAbs_FORWARD)
1399 //if(WisF) cout<<"W is FORWARD"<<endl;
1400 //else cout<<"W is REVERSED"<<endl;
1401 // bool FisF = (F.Orientation()==TopAbs_FORWARD);
1402 // if(!FisF) WisF = !WisF;
1404 int i,j,geomFaceID = meshDS->ShapeToIndex( F );
1406 int nb = quad->side[0]->NbPoints();
1407 int nr = quad->side[1]->NbPoints();
1408 int nt = quad->side[2]->NbPoints();
1409 int nl = quad->side[3]->NbPoints();
1410 int dh = abs(nb-nt);
1411 int dv = abs(nr-nl);
1415 // it is a base case => not shift quad but me be replacement is need
1416 ShiftQuad(quad,0,WisF);
1419 // we have to shift quad on 2
1420 ShiftQuad(quad,2,WisF);
1425 // we have to shift quad on 1
1426 ShiftQuad(quad,1,WisF);
1429 // we have to shift quad on 3
1430 ShiftQuad(quad,3,WisF);
1434 nb = quad->side[0]->NbPoints();
1435 nr = quad->side[1]->NbPoints();
1436 nt = quad->side[2]->NbPoints();
1437 nl = quad->side[3]->NbPoints();
1440 int nbh = Max(nb,nt);
1441 int nbv = Max(nr,nl);
1445 // ----------- Old version ---------------
1446 // orientation of face and 3 main domain for future faces
1452 // left | | | | rigth
1459 // ----------- New version ---------------
1460 // orientation of face and 3 main domain for future faces
1466 // left |/________\| rigth
1482 const vector<UVPtStruct>& uv_eb = quad->side[0]->GetUVPtStruct(true,0 );
1483 const vector<UVPtStruct>& uv_er = quad->side[1]->GetUVPtStruct(false,1);
1484 const vector<UVPtStruct>& uv_et = quad->side[2]->GetUVPtStruct(true,1 );
1485 const vector<UVPtStruct>& uv_el = quad->side[3]->GetUVPtStruct(false,0);
1487 if ( uv_eb.size() != nb || uv_er.size() != nr || uv_et.size() != nt || uv_el.size() != nl )
1488 return error( COMPERR_BAD_INPUT_MESH );
1490 // arrays for normalized params
1491 //cout<<"Dump B:"<<endl;
1492 TColStd_SequenceOfReal npb, npr, npt, npl;
1493 for(i=0; i<nb; i++) {
1494 npb.Append(uv_eb[i].normParam);
1495 //cout<<"i="<<i<<" par="<<uv_eb[i].normParam<<" npar="<<uv_eb[i].normParam;
1496 //const SMDS_MeshNode* N = uv_eb[i].node;
1497 //cout<<" node("<<N->X()<<","<<N->Y()<<","<<N->Z()<<")"<<endl;
1499 for(i=0; i<nr; i++) {
1500 npr.Append(uv_er[i].normParam);
1502 for(i=0; i<nt; i++) {
1503 npt.Append(uv_et[i].normParam);
1505 for(i=0; i<nl; i++) {
1506 npl.Append(uv_el[i].normParam);
1511 // add some params to right and left after the first param
1514 double dpr = (npr.Value(2) - npr.Value(1))/(dr+1);
1515 for(i=1; i<=dr; i++) {
1516 npr.InsertAfter(1,npr.Value(2)-dpr);
1520 dpr = (npl.Value(2) - npl.Value(1))/(dl+1);
1521 for(i=1; i<=dl; i++) {
1522 npl.InsertAfter(1,npl.Value(2)-dpr);
1526 //for(i=1; i<=npb.Length(); i++) {
1527 // cout<<" "<<npb.Value(i);
1531 gp_XY a0( uv_eb.front().u, uv_eb.front().v );
1532 gp_XY a1( uv_eb.back().u, uv_eb.back().v );
1533 gp_XY a2( uv_et.back().u, uv_et.back().v );
1534 gp_XY a3( uv_et.front().u, uv_et.front().v );
1535 //cout<<" a0("<<a0.X()<<","<<a0.Y()<<")"<<" a1("<<a1.X()<<","<<a1.Y()<<")"
1536 // <<" a2("<<a2.X()<<","<<a2.Y()<<")"<<" a3("<<a3.X()<<","<<a3.Y()<<")"<<endl;
1538 int nnn = Min(nr,nl);
1539 // auxilary sequence of XY for creation nodes
1540 // in the bottom part of central domain
1541 // it's length must be == nbv-nnn-1
1542 TColgp_SequenceOfXY UVL;
1543 TColgp_SequenceOfXY UVR;
1546 // step1: create faces for left domain
1547 StdMeshers_Array2OfNode NodesL(1,dl+1,1,nl);
1549 for(j=1; j<=nl; j++)
1550 NodesL.SetValue(1,j,uv_el[j-1].node);
1553 for(i=1; i<=dl; i++)
1554 NodesL.SetValue(i+1,nl,uv_et[i].node);
1555 // create and add needed nodes
1556 TColgp_SequenceOfXY UVtmp;
1557 for(i=1; i<=dl; i++) {
1558 double x0 = npt.Value(i+1);
1561 double y0 = npl.Value(i+1);
1562 double y1 = npr.Value(i+1);
1563 gp_UV UV = CalcUV(x0, x1, y0, y1, quad, a0, a1, a2, a3);
1564 gp_Pnt P = S->Value(UV.X(),UV.Y());
1565 SMDS_MeshNode * N = meshDS->AddNode(P.X(), P.Y(), P.Z());
1566 meshDS->SetNodeOnFace(N, geomFaceID, UV.X(), UV.Y());
1567 NodesL.SetValue(i+1,1,N);
1568 if(UVL.Length()<nbv-nnn-1) UVL.Append(UV);
1570 for(j=2; j<nl; j++) {
1571 double y0 = npl.Value(dl+j);
1572 double y1 = npr.Value(dl+j);
1573 gp_UV UV = CalcUV(x0, x1, y0, y1, quad, a0, a1, a2, a3);
1574 gp_Pnt P = S->Value(UV.X(),UV.Y());
1575 SMDS_MeshNode* N = meshDS->AddNode(P.X(), P.Y(), P.Z());
1576 meshDS->SetNodeOnFace(N, geomFaceID, UV.X(), UV.Y());
1577 NodesL.SetValue(i+1,j,N);
1578 if( i==dl ) UVtmp.Append(UV);
1581 for(i=1; i<=UVtmp.Length() && UVL.Length()<nbv-nnn-1; i++) {
1582 UVL.Append(UVtmp.Value(i));
1584 //cout<<"Dump NodesL:"<<endl;
1585 //for(i=1; i<=dl+1; i++) {
1587 // for(j=1; j<=nl; j++) {
1588 // cout<<" ("<<NodesL.Value(i,j)->X()<<","<<NodesL.Value(i,j)->Y()<<","<<NodesL.Value(i,j)->Z()<<")";
1593 for(i=1; i<=dl; i++) {
1594 for(j=1; j<nl; j++) {
1597 myTool->AddFace(NodesL.Value(i,j), NodesL.Value(i+1,j),
1598 NodesL.Value(i+1,j+1), NodesL.Value(i,j+1));
1599 if(F) meshDS->SetMeshElementOnShape(F, geomFaceID);
1603 myTool->AddFace(NodesL.Value(i,j), NodesL.Value(i,j+1),
1604 NodesL.Value(i+1,j+1), NodesL.Value(i+1,j));
1605 if(F) meshDS->SetMeshElementOnShape(F, geomFaceID);
1611 // fill UVL using c2d
1612 for(i=1; i<npl.Length() && UVL.Length()<nbv-nnn-1; i++) {
1613 UVL.Append( gp_UV ( uv_el[i].u, uv_el[i].v ));
1617 // step2: create faces for right domain
1618 StdMeshers_Array2OfNode NodesR(1,dr+1,1,nr);
1620 for(j=1; j<=nr; j++)
1621 NodesR.SetValue(1,j,uv_er[nr-j].node);
1624 for(i=1; i<=dr; i++)
1625 NodesR.SetValue(i+1,1,uv_et[nt-1-i].node);
1626 // create and add needed nodes
1627 TColgp_SequenceOfXY UVtmp;
1628 for(i=1; i<=dr; i++) {
1629 double x0 = npt.Value(nt-i);
1632 double y0 = npl.Value(i+1);
1633 double y1 = npr.Value(i+1);
1634 gp_UV UV = CalcUV(x0, x1, y0, y1, quad, a0, a1, a2, a3);
1635 gp_Pnt P = S->Value(UV.X(),UV.Y());
1636 SMDS_MeshNode * N = meshDS->AddNode(P.X(), P.Y(), P.Z());
1637 meshDS->SetNodeOnFace(N, geomFaceID, UV.X(), UV.Y());
1638 NodesR.SetValue(i+1,nr,N);
1639 if(UVR.Length()<nbv-nnn-1) UVR.Append(UV);
1641 for(j=2; j<nr; j++) {
1642 double y0 = npl.Value(nbv-j+1);
1643 double y1 = npr.Value(nbv-j+1);
1644 gp_UV UV = CalcUV(x0, x1, y0, y1, quad, a0, a1, a2, a3);
1645 gp_Pnt P = S->Value(UV.X(),UV.Y());
1646 SMDS_MeshNode* N = meshDS->AddNode(P.X(), P.Y(), P.Z());
1647 meshDS->SetNodeOnFace(N, geomFaceID, UV.X(), UV.Y());
1648 NodesR.SetValue(i+1,j,N);
1649 if( i==dr ) UVtmp.Prepend(UV);
1652 for(i=1; i<=UVtmp.Length() && UVR.Length()<nbv-nnn-1; i++) {
1653 UVR.Append(UVtmp.Value(i));
1656 for(i=1; i<=dr; i++) {
1657 for(j=1; j<nr; j++) {
1660 myTool->AddFace(NodesR.Value(i,j), NodesR.Value(i+1,j),
1661 NodesR.Value(i+1,j+1), NodesR.Value(i,j+1));
1662 if(F) meshDS->SetMeshElementOnShape(F, geomFaceID);
1666 myTool->AddFace(NodesR.Value(i,j), NodesR.Value(i,j+1),
1667 NodesR.Value(i+1,j+1), NodesR.Value(i+1,j));
1668 if(F) meshDS->SetMeshElementOnShape(F, geomFaceID);
1674 // fill UVR using c2d
1675 for(i=1; i<npr.Length() && UVR.Length()<nbv-nnn-1; i++) {
1676 UVR.Append( gp_UV( uv_er[i].u, uv_er[i].v ));
1680 // step3: create faces for central domain
1681 StdMeshers_Array2OfNode NodesC(1,nb,1,nbv);
1682 // add first string using NodesL
1683 for(i=1; i<=dl+1; i++)
1684 NodesC.SetValue(1,i,NodesL(i,1));
1685 for(i=2; i<=nl; i++)
1686 NodesC.SetValue(1,dl+i,NodesL(dl+1,i));
1687 // add last string using NodesR
1688 for(i=1; i<=dr+1; i++)
1689 NodesC.SetValue(nb,i,NodesR(i,nr));
1691 NodesC.SetValue(nb,dr+i+1,NodesR(dr+1,nr-i));
1692 // add top nodes (last columns)
1693 for(i=dl+2; i<nbh-dr; i++)
1694 NodesC.SetValue(i-dl,nbv,uv_et[i-1].node);
1695 // add bottom nodes (first columns)
1697 NodesC.SetValue(i,1,uv_eb[i-1].node);
1699 // create and add needed nodes
1700 // add linear layers
1701 for(i=2; i<nb; i++) {
1702 double x0 = npt.Value(dl+i);
1704 for(j=1; j<nnn; j++) {
1705 double y0 = npl.Value(nbv-nnn+j);
1706 double y1 = npr.Value(nbv-nnn+j);
1707 gp_UV UV = CalcUV(x0, x1, y0, y1, quad, a0, a1, a2, a3);
1708 gp_Pnt P = S->Value(UV.X(),UV.Y());
1709 SMDS_MeshNode* N = meshDS->AddNode(P.X(), P.Y(), P.Z());
1710 meshDS->SetNodeOnFace(N, geomFaceID, UV.X(), UV.Y());
1711 NodesC.SetValue(i,nbv-nnn+j,N);
1714 // add diagonal layers
1715 //cout<<"UVL.Length()="<<UVL.Length()<<" UVR.Length()="<<UVR.Length()<<endl;
1716 //cout<<"Dump UVL:"<<endl;
1717 //for(i=1; i<=UVL.Length(); i++) {
1718 // cout<<" ("<<UVL.Value(i).X()<<","<<UVL.Value(i).Y()<<")";
1721 for(i=1; i<nbv-nnn; i++) {
1722 double du = UVR.Value(i).X() - UVL.Value(i).X();
1723 double dv = UVR.Value(i).Y() - UVL.Value(i).Y();
1724 for(j=2; j<nb; j++) {
1725 double u = UVL.Value(i).X() + du*npb.Value(j);
1726 double v = UVL.Value(i).Y() + dv*npb.Value(j);
1727 gp_Pnt P = S->Value(u,v);
1728 SMDS_MeshNode* N = meshDS->AddNode(P.X(), P.Y(), P.Z());
1729 meshDS->SetNodeOnFace(N, geomFaceID, u, v);
1730 NodesC.SetValue(j,i+1,N);
1734 for(i=1; i<nb; i++) {
1735 for(j=1; j<nbv; j++) {
1738 myTool->AddFace(NodesC.Value(i,j), NodesC.Value(i+1,j),
1739 NodesC.Value(i+1,j+1), NodesC.Value(i,j+1));
1740 if(F) meshDS->SetMeshElementOnShape(F, geomFaceID);
1744 myTool->AddFace(NodesC.Value(i,j), NodesC.Value(i,j+1),
1745 NodesC.Value(i+1,j+1), NodesC.Value(i+1,j));
1746 if(F) meshDS->SetMeshElementOnShape(F, geomFaceID);
1752 else { // New version (!OldVersion)
1753 // step1: create faces for bottom rectangle domain
1754 StdMeshers_Array2OfNode NodesBRD(1,nb,1,nnn-1);
1755 // fill UVL and UVR using c2d
1756 for(j=0; j<nb; j++) {
1757 NodesBRD.SetValue(j+1,1,uv_eb[j].node);
1759 for(i=1; i<nnn-1; i++) {
1760 NodesBRD.SetValue(1,i+1,uv_el[i].node);
1761 NodesBRD.SetValue(nb,i+1,uv_er[i].node);
1762 double du = uv_er[i].u - uv_el[i].u;
1763 double dv = uv_er[i].v - uv_el[i].v;
1764 for(j=2; j<nb; j++) {
1765 double u = uv_el[i].u + du*npb.Value(j);
1766 double v = uv_el[i].v + dv*npb.Value(j);
1767 gp_Pnt P = S->Value(u,v);
1768 SMDS_MeshNode* N = meshDS->AddNode(P.X(), P.Y(), P.Z());
1769 meshDS->SetNodeOnFace(N, geomFaceID, u, v);
1770 NodesBRD.SetValue(j,i+1,N);
1775 for(j=1; j<nnn-1; j++) {
1776 for(i=1; i<nb; i++) {
1780 myTool->AddFace(NodesBRD.Value(i,j), NodesBRD.Value(i+1,j),
1781 NodesBRD.Value(i+1,j+1), NodesBRD.Value(i,j+1));
1782 if(F) meshDS->SetMeshElementOnShape(F, geomFaceID);
1786 myTool->AddFace(NodesBRD.Value(i,j), NodesBRD.Value(i,j+1),
1787 NodesBRD.Value(i+1,j+1), NodesBRD.Value(i+1,j));
1788 if(F) meshDS->SetMeshElementOnShape(F, geomFaceID);
1792 int drl = abs(nr-nl);
1793 // create faces for region C
1794 StdMeshers_Array2OfNode NodesC(1,nb,1,drl+1+addv);
1795 // add nodes from previous region
1796 for(j=1; j<=nb; j++) {
1797 NodesC.SetValue(j,1,NodesBRD.Value(j,nnn-1));
1799 if( (drl+addv) > 0 ) {
1804 TColgp_SequenceOfXY UVtmp;
1805 double drparam = npr.Value(nr) - npr.Value(nnn-1);
1806 double dlparam = npl.Value(nnn) - npl.Value(nnn-1);
1808 for(i=1; i<=drl; i++) {
1809 // add existed nodes from right edge
1810 NodesC.SetValue(nb,i+1,uv_er[nnn+i-2].node);
1811 //double dtparam = npt.Value(i+1);
1812 y1 = npr.Value(nnn+i-1); // param on right edge
1813 double dpar = (y1 - npr.Value(nnn-1))/drparam;
1814 y0 = npl.Value(nnn-1) + dpar*dlparam; // param on left edge
1815 double dy = y1 - y0;
1816 for(j=1; j<nb; j++) {
1817 double x = npt.Value(i+1) + npb.Value(j)*(1-npt.Value(i+1));
1818 double y = y0 + dy*x;
1819 gp_UV UV = CalcUV2(x, y, quad, a0, a1, a2, a3);
1820 gp_Pnt P = S->Value(UV.X(),UV.Y());
1821 SMDS_MeshNode* N = meshDS->AddNode(P.X(), P.Y(), P.Z());
1822 meshDS->SetNodeOnFace(N, geomFaceID, UV.X(), UV.Y());
1823 NodesC.SetValue(j,i+1,N);
1826 double dy0 = (1-y0)/(addv+1);
1827 double dy1 = (1-y1)/(addv+1);
1828 for(i=1; i<=addv; i++) {
1829 double yy0 = y0 + dy0*i;
1830 double yy1 = y1 + dy1*i;
1831 double dyy = yy1 - yy0;
1832 for(j=1; j<=nb; j++) {
1833 double x = npt.Value(i+1+drl) +
1834 npb.Value(j) * ( npt.Value(nt-i) - npt.Value(i+1+drl) );
1835 double y = yy0 + dyy*x;
1836 gp_UV UV = CalcUV2(x, y, quad, a0, a1, a2, a3);
1837 gp_Pnt P = S->Value(UV.X(),UV.Y());
1838 SMDS_MeshNode* N = meshDS->AddNode(P.X(), P.Y(), P.Z());
1839 meshDS->SetNodeOnFace(N, geomFaceID, UV.X(), UV.Y());
1840 NodesC.SetValue(j,i+drl+1,N);
1847 TColgp_SequenceOfXY UVtmp;
1848 double dlparam = npl.Value(nl) - npl.Value(nnn-1);
1849 double drparam = npr.Value(nnn) - npr.Value(nnn-1);
1850 double y0 = npl.Value(nnn-1);
1851 double y1 = npr.Value(nnn-1);
1852 for(i=1; i<=drl; i++) {
1853 // add existed nodes from right edge
1854 NodesC.SetValue(1,i+1,uv_el[nnn+i-2].node);
1855 y0 = npl.Value(nnn+i-1); // param on left edge
1856 double dpar = (y0 - npl.Value(nnn-1))/dlparam;
1857 y1 = npr.Value(nnn-1) + dpar*drparam; // param on right edge
1858 double dy = y1 - y0;
1859 for(j=2; j<=nb; j++) {
1860 double x = npb.Value(j)*npt.Value(nt-i);
1861 double y = y0 + dy*x;
1862 gp_UV UV = CalcUV2(x, y, quad, a0, a1, a2, a3);
1863 gp_Pnt P = S->Value(UV.X(),UV.Y());
1864 SMDS_MeshNode* N = meshDS->AddNode(P.X(), P.Y(), P.Z());
1865 meshDS->SetNodeOnFace(N, geomFaceID, UV.X(), UV.Y());
1866 NodesC.SetValue(j,i+1,N);
1869 double dy0 = (1-y0)/(addv+1);
1870 double dy1 = (1-y1)/(addv+1);
1871 for(i=1; i<=addv; i++) {
1872 double yy0 = y0 + dy0*i;
1873 double yy1 = y1 + dy1*i;
1874 double dyy = yy1 - yy0;
1875 for(j=1; j<=nb; j++) {
1876 double x = npt.Value(i+1) +
1877 npb.Value(j) * ( npt.Value(nt-i-drl) - npt.Value(i+1) );
1878 double y = yy0 + dyy*x;
1879 gp_UV UV = CalcUV2(x, y, quad, a0, a1, a2, a3);
1880 gp_Pnt P = S->Value(UV.X(),UV.Y());
1881 SMDS_MeshNode* N = meshDS->AddNode(P.X(), P.Y(), P.Z());
1882 meshDS->SetNodeOnFace(N, geomFaceID, UV.X(), UV.Y());
1883 NodesC.SetValue(j,i+drl+1,N);
1888 for(j=1; j<=drl+addv; j++) {
1889 for(i=1; i<nb; i++) {
1893 myTool->AddFace(NodesC.Value(i,j), NodesC.Value(i+1,j),
1894 NodesC.Value(i+1,j+1), NodesC.Value(i,j+1));
1895 if(F) meshDS->SetMeshElementOnShape(F, geomFaceID);
1899 myTool->AddFace(NodesC.Value(i,j), NodesC.Value(i,j+1),
1900 NodesC.Value(i+1,j+1), NodesC.Value(i+1,j));
1901 if(F) meshDS->SetMeshElementOnShape(F, geomFaceID);
1906 StdMeshers_Array2OfNode NodesLast(1,nt,1,2);
1907 for(i=1; i<=nt; i++) {
1908 NodesLast.SetValue(i,2,uv_et[i-1].node);
1911 for(i=n1; i<drl+addv+1; i++) {
1913 NodesLast.SetValue(nnn,1,NodesC.Value(1,i));
1915 for(i=1; i<=nb; i++) {
1917 NodesLast.SetValue(nnn,1,NodesC.Value(i,drl+addv+1));
1919 for(i=drl+addv; i>=n2; i--) {
1921 NodesLast.SetValue(nnn,1,NodesC.Value(nb,i));
1923 for(i=1; i<nt; i++) {
1927 myTool->AddFace(NodesLast.Value(i,1), NodesLast.Value(i+1,1),
1928 NodesLast.Value(i+1,2), NodesLast.Value(i,2));
1929 if(F) meshDS->SetMeshElementOnShape(F, geomFaceID);
1933 myTool->AddFace(NodesLast.Value(i,1), NodesLast.Value(i,2),
1934 NodesLast.Value(i+1,2), NodesLast.Value(i+1,2));
1935 if(F) meshDS->SetMeshElementOnShape(F, geomFaceID);
1938 } // if( (drl+addv) > 0 )
1940 } // end new version implementation
1947 //=======================================================================
1949 * Evaluate only quandrangle faces
1951 //=======================================================================
1953 bool StdMeshers_Quadrangle_2D::EvaluateQuadPref(SMESH_Mesh & aMesh,
1954 const TopoDS_Shape& aShape,
1955 std::vector<int>& aNbNodes,
1956 MapShapeNbElems& aResMap,
1959 // Auxilary key in order to keep old variant
1960 // of meshing after implementation new variant
1961 // for bug 0016220 from Mantis.
1962 bool OldVersion = false;
1964 const TopoDS_Face& F = TopoDS::Face(aShape);
1965 Handle(Geom_Surface) S = BRep_Tool::Surface(F);
1967 int nb = aNbNodes[0];
1968 int nr = aNbNodes[1];
1969 int nt = aNbNodes[2];
1970 int nl = aNbNodes[3];
1971 int dh = abs(nb-nt);
1972 int dv = abs(nr-nl);
1976 // it is a base case => not shift
1979 // we have to shift on 2
1988 // we have to shift quad on 1
1995 // we have to shift quad on 3
2005 int nbh = Max(nb,nt);
2006 int nbv = Max(nr,nl);
2021 // add some params to right and left after the first param
2028 int nnn = Min(nr,nl);
2033 // step1: create faces for left domain
2035 nbNodes += dl*(nl-1);
2036 nbFaces += dl*(nl-1);
2038 // step2: create faces for right domain
2040 nbNodes += dr*(nr-1);
2041 nbFaces += dr*(nr-1);
2043 // step3: create faces for central domain
2044 nbNodes += (nb-2)*(nnn-1) + (nbv-nnn-1)*(nb-2);
2045 nbFaces += (nb-1)*(nbv-1);
2047 else { // New version (!OldVersion)
2048 nbNodes += (nnn-2)*(nb-2);
2049 nbFaces += (nnn-2)*(nb-1);
2050 int drl = abs(nr-nl);
2051 nbNodes += drl*(nb-1) + addv*nb;
2052 nbFaces += (drl+addv)*(nb-1) + (nt-1);
2053 } // end new version implementation
2055 std::vector<int> aVec(SMDSEntity_Last);
2056 for(int i=SMDSEntity_Node; i<SMDSEntity_Last; i++) aVec[i] = 0;
2058 aVec[SMDSEntity_Quad_Quadrangle] = nbFaces;
2059 aVec[SMDSEntity_Node] = nbNodes + nbFaces*4;
2060 if( aNbNodes.size()==5 ) {
2061 aVec[SMDSEntity_Quad_Triangle] = aNbNodes[3] - 1;
2062 aVec[SMDSEntity_Quad_Quadrangle] = nbFaces - aNbNodes[3] + 1;
2066 aVec[SMDSEntity_Node] = nbNodes;
2067 aVec[SMDSEntity_Quadrangle] = nbFaces;
2068 if( aNbNodes.size()==5 ) {
2069 aVec[SMDSEntity_Triangle] = aNbNodes[3] - 1;
2070 aVec[SMDSEntity_Quadrangle] = nbFaces - aNbNodes[3] + 1;
2073 SMESH_subMesh * sm = aMesh.GetSubMesh(aShape);
2074 aResMap.insert(std::make_pair(sm,aVec));
2080 //=============================================================================
2081 /*! Split quadrangle in to 2 triangles by smallest diagonal
2084 //=============================================================================
2085 void StdMeshers_Quadrangle_2D::SplitQuad(SMESHDS_Mesh *theMeshDS,
2087 const SMDS_MeshNode* theNode1,
2088 const SMDS_MeshNode* theNode2,
2089 const SMDS_MeshNode* theNode3,
2090 const SMDS_MeshNode* theNode4)
2092 gp_Pnt a(theNode1->X(),theNode1->Y(),theNode1->Z());
2093 gp_Pnt b(theNode2->X(),theNode2->Y(),theNode2->Z());
2094 gp_Pnt c(theNode3->X(),theNode3->Y(),theNode3->Z());
2095 gp_Pnt d(theNode4->X(),theNode4->Y(),theNode4->Z());
2096 SMDS_MeshFace* face;
2097 if(a.Distance(c) > b.Distance(d)){
2098 face = myTool->AddFace(theNode2, theNode4 , theNode1);
2099 if(face) theMeshDS->SetMeshElementOnShape(face, theFaceID );
2100 face = myTool->AddFace(theNode2, theNode3, theNode4);
2101 if(face) theMeshDS->SetMeshElementOnShape(face, theFaceID );
2105 face = myTool->AddFace(theNode1, theNode2 ,theNode3);
2106 if(face) theMeshDS->SetMeshElementOnShape(face, theFaceID );
2107 face = myTool->AddFace(theNode1, theNode3, theNode4);
2108 if(face) theMeshDS->SetMeshElementOnShape(face, theFaceID );