1 // Copyright (C) 2007-2008 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
22 // SMESH SMESH : implementaion of SMESH idl descriptions
23 // File : StdMeshers_Quadrangle_2D.cxx
24 // Moved here from SMESH_Quadrangle_2D.cxx
25 // Author : Paul RASCLE, EDF
28 #include "StdMeshers_Quadrangle_2D.hxx"
30 #include "StdMeshers_FaceSide.hxx"
32 #include "SMESH_Gen.hxx"
33 #include "SMESH_Mesh.hxx"
34 #include "SMESH_subMesh.hxx"
35 #include "SMESH_MesherHelper.hxx"
36 #include "SMESH_Block.hxx"
37 #include "SMESH_Comment.hxx"
39 #include "SMDS_MeshElement.hxx"
40 #include "SMDS_MeshNode.hxx"
41 #include "SMDS_EdgePosition.hxx"
42 #include "SMDS_FacePosition.hxx"
44 #include <BRepTools_WireExplorer.hxx>
45 #include <BRep_Tool.hxx>
46 #include <Geom_Surface.hxx>
47 #include <NCollection_DefineArray2.hxx>
48 #include <Precision.hxx>
49 #include <TColStd_SequenceOfReal.hxx>
50 #include <TColgp_SequenceOfXY.hxx>
52 #include <TopTools_ListIteratorOfListOfShape.hxx>
55 #include "utilities.h"
56 #include "Utils_ExceptHandlers.hxx"
58 #ifndef StdMeshers_Array2OfNode_HeaderFile
59 #define StdMeshers_Array2OfNode_HeaderFile
60 typedef const SMDS_MeshNode* SMDS_MeshNodePtr;
61 DEFINE_BASECOLLECTION (StdMeshers_BaseCollectionNodePtr, SMDS_MeshNodePtr)
62 DEFINE_ARRAY2(StdMeshers_Array2OfNode,
63 StdMeshers_BaseCollectionNodePtr, SMDS_MeshNodePtr)
69 typedef SMESH_Comment TComm;
71 //=============================================================================
75 //=============================================================================
77 StdMeshers_Quadrangle_2D::StdMeshers_Quadrangle_2D (int hypId, int studyId, SMESH_Gen* gen)
78 : SMESH_2D_Algo(hypId, studyId, gen)
80 MESSAGE("StdMeshers_Quadrangle_2D::StdMeshers_Quadrangle_2D");
81 _name = "Quadrangle_2D";
82 _shapeType = (1 << TopAbs_FACE);
83 _compatibleHypothesis.push_back("QuadranglePreference");
84 _compatibleHypothesis.push_back("TrianglePreference");
88 //=============================================================================
92 //=============================================================================
94 StdMeshers_Quadrangle_2D::~StdMeshers_Quadrangle_2D()
96 MESSAGE("StdMeshers_Quadrangle_2D::~StdMeshers_Quadrangle_2D");
99 //=============================================================================
103 //=============================================================================
105 bool StdMeshers_Quadrangle_2D::CheckHypothesis
107 const TopoDS_Shape& aShape,
108 SMESH_Hypothesis::Hypothesis_Status& aStatus)
111 aStatus = SMESH_Hypothesis::HYP_OK;
114 const list <const SMESHDS_Hypothesis * >&hyps = GetUsedHypothesis(aMesh, aShape, false);
115 const SMESHDS_Hypothesis *theHyp = 0;
118 theHyp = *hyps.begin();
119 if(strcmp("QuadranglePreference", theHyp->GetName()) == 0) {
120 myQuadranglePreference= true;
121 myTrianglePreference= false;
123 else if(strcmp("TrianglePreference", theHyp->GetName()) == 0){
124 myQuadranglePreference= false;
125 myTrianglePreference= true;
129 myQuadranglePreference = false;
130 myTrianglePreference = false;
135 //=============================================================================
139 //=============================================================================
141 bool StdMeshers_Quadrangle_2D::Compute (SMESH_Mesh& aMesh,
142 const TopoDS_Shape& aShape)// throw (SALOME_Exception)
144 // PAL14921. Enable catching std::bad_alloc and Standard_OutOfMemory outside
145 //Unexpect aCatchSalomeException);
147 SMESHDS_Mesh * meshDS = aMesh.GetMeshDS();
148 aMesh.GetSubMesh(aShape);
150 SMESH_MesherHelper helper(aMesh);
153 _quadraticMesh = myTool->IsQuadraticSubMesh(aShape);
155 FaceQuadStruct *quad = CheckNbEdges( aMesh, aShape );
156 std::auto_ptr<FaceQuadStruct> quadDeleter( quad ); // to delete quad at exit from Compute()
160 if(myQuadranglePreference) {
161 int n1 = quad->side[0]->NbPoints();
162 int n2 = quad->side[1]->NbPoints();
163 int n3 = quad->side[2]->NbPoints();
164 int n4 = quad->side[3]->NbPoints();
165 int nfull = n1+n2+n3+n4;
168 if( nfull==ntmp && ( (n1!=n3) || (n2!=n4) ) ) {
169 // special path for using only quandrangle faces
170 bool ok = ComputeQuadPref(aMesh, aShape, quad);
175 // set normalized grid on unit square in parametric domain
177 if (!SetNormalizedGrid(aMesh, aShape, quad))
180 // --- compute 3D values on points, store points & quadrangles
182 int nbdown = quad->side[0]->NbPoints();
183 int nbup = quad->side[2]->NbPoints();
185 int nbright = quad->side[1]->NbPoints();
186 int nbleft = quad->side[3]->NbPoints();
188 int nbhoriz = Min(nbdown, nbup);
189 int nbvertic = Min(nbright, nbleft);
191 const TopoDS_Face& F = TopoDS::Face(aShape);
192 Handle(Geom_Surface) S = BRep_Tool::Surface(F);
194 // internal mesh nodes
195 int i, j, geomFaceID = meshDS->ShapeToIndex( F );
196 for (i = 1; i < nbhoriz - 1; i++) {
197 for (j = 1; j < nbvertic - 1; j++) {
198 int ij = j * nbhoriz + i;
199 double u = quad->uv_grid[ij].u;
200 double v = quad->uv_grid[ij].v;
201 gp_Pnt P = S->Value(u, v);
202 SMDS_MeshNode * node = meshDS->AddNode(P.X(), P.Y(), P.Z());
203 meshDS->SetNodeOnFace(node, geomFaceID, u, v);
204 quad->uv_grid[ij].node = node;
211 // --.--.--.--.--.-- nbvertic
217 // ---.----.----.--- 0
218 // 0 > > > > > > > > nbhoriz
224 int iup = nbhoriz - 1;
225 if (quad->isEdgeOut[3]) { ilow++; } else { if (quad->isEdgeOut[1]) iup--; }
228 int jup = nbvertic - 1;
229 if (quad->isEdgeOut[0]) { jlow++; } else { if (quad->isEdgeOut[2]) jup--; }
231 // regular quadrangles
232 for (i = ilow; i < iup; i++) {
233 for (j = jlow; j < jup; j++) {
234 const SMDS_MeshNode *a, *b, *c, *d;
235 a = quad->uv_grid[j * nbhoriz + i].node;
236 b = quad->uv_grid[j * nbhoriz + i + 1].node;
237 c = quad->uv_grid[(j + 1) * nbhoriz + i + 1].node;
238 d = quad->uv_grid[(j + 1) * nbhoriz + i].node;
239 SMDS_MeshFace* face = myTool->AddFace(a, b, c, d);
240 meshDS->SetMeshElementOnShape(face, geomFaceID);
244 const vector<UVPtStruct>& uv_e0 = quad->side[0]->GetUVPtStruct(true,0 );
245 const vector<UVPtStruct>& uv_e1 = quad->side[1]->GetUVPtStruct(false,1);
246 const vector<UVPtStruct>& uv_e2 = quad->side[2]->GetUVPtStruct(true,1 );
247 const vector<UVPtStruct>& uv_e3 = quad->side[3]->GetUVPtStruct(false,0);
249 if ( uv_e0.empty() || uv_e1.empty() || uv_e2.empty() || uv_e3.empty() )
250 return error( COMPERR_BAD_INPUT_MESH );
252 double eps = Precision::Confusion();
254 // Boundary quadrangles
256 if (quad->isEdgeOut[0]) {
259 // |___|___|___|___|___|___|
261 // |___|___|___|___|___|___|
263 // |___|___|___|___|___|___| __ first row of the regular grid
264 // . . . . . . . . . __ down edge nodes
266 // >->->->->->->->->->->->-> -- direction of processing
268 int g = 0; // number of last processed node in the regular grid
270 // number of last node of the down edge to be processed
271 int stop = nbdown - 1;
272 // if right edge is out, we will stop at a node, previous to the last one
273 if (quad->isEdgeOut[1]) stop--;
275 // for each node of the down edge find nearest node
276 // in the first row of the regular grid and link them
277 for (i = 0; i < stop; i++) {
278 const SMDS_MeshNode *a, *b, *c, *d;
280 b = uv_e0[i + 1].node;
281 gp_Pnt pb (b->X(), b->Y(), b->Z());
283 // find node c in the regular grid, which will be linked with node b
286 // right bound reached, link with the rightmost node
288 c = quad->uv_grid[nbhoriz + iup].node;
291 // find in the grid node c, nearest to the b
292 double mind = RealLast();
293 for (int k = g; k <= iup; k++) {
295 const SMDS_MeshNode *nk;
296 if (k < ilow) // this can be, if left edge is out
297 nk = uv_e3[1].node; // get node from the left edge
299 nk = quad->uv_grid[nbhoriz + k].node; // get one of middle nodes
301 gp_Pnt pnk (nk->X(), nk->Y(), nk->Z());
302 double dist = pb.Distance(pnk);
303 if (dist < mind - eps) {
313 if (near == g) { // make triangle
314 //SMDS_MeshFace* face = meshDS->AddFace(a, b, c);
315 SMDS_MeshFace* face = myTool->AddFace(a, b, c);
316 meshDS->SetMeshElementOnShape(face, geomFaceID);
318 else { // make quadrangle
322 d = quad->uv_grid[nbhoriz + near - 1].node;
323 //SMDS_MeshFace* face = meshDS->AddFace(a, b, c, d);
325 if(!myTrianglePreference){
326 SMDS_MeshFace* face = myTool->AddFace(a, b, c, d);
327 meshDS->SetMeshElementOnShape(face, geomFaceID);
330 SplitQuad(meshDS, geomFaceID, a, b, c, d);
333 // if node d is not at position g - make additional triangles
335 for (int k = near - 1; k > g; k--) {
336 c = quad->uv_grid[nbhoriz + k].node;
340 d = quad->uv_grid[nbhoriz + k - 1].node;
341 //SMDS_MeshFace* face = meshDS->AddFace(a, c, d);
342 SMDS_MeshFace* face = myTool->AddFace(a, c, d);
343 meshDS->SetMeshElementOnShape(face, geomFaceID);
350 if (quad->isEdgeOut[2]) {
353 // <-<-<-<-<-<-<-<-<-<-<-<-< -- direction of processing
355 // . . . . . . . . . __ up edge nodes
356 // ___ ___ ___ ___ ___ ___ __ first row of the regular grid
358 // |___|___|___|___|___|___|
360 // |___|___|___|___|___|___|
363 int g = nbhoriz - 1; // last processed node in the regular grid
366 // if left edge is out, we will stop at a second node
367 if (quad->isEdgeOut[3]) stop++;
369 // for each node of the up edge find nearest node
370 // in the first row of the regular grid and link them
371 for (i = nbup - 1; i > stop; i--) {
372 const SMDS_MeshNode *a, *b, *c, *d;
374 b = uv_e2[i - 1].node;
375 gp_Pnt pb (b->X(), b->Y(), b->Z());
377 // find node c in the grid, which will be linked with node b
379 if (i == stop + 1) { // left bound reached, link with the leftmost node
380 c = quad->uv_grid[nbhoriz*(nbvertic - 2) + ilow].node;
383 // find node c in the grid, nearest to the b
384 double mind = RealLast();
385 for (int k = g; k >= ilow; k--) {
386 const SMDS_MeshNode *nk;
388 nk = uv_e1[nbright - 2].node;
390 nk = quad->uv_grid[nbhoriz*(nbvertic - 2) + k].node;
391 gp_Pnt pnk (nk->X(), nk->Y(), nk->Z());
392 double dist = pb.Distance(pnk);
393 if (dist < mind - eps) {
403 if (near == g) { // make triangle
404 //SMDS_MeshFace* face = meshDS->AddFace(a, b, c);
405 SMDS_MeshFace* face = myTool->AddFace(a, b, c);
406 meshDS->SetMeshElementOnShape(face, geomFaceID);
408 else { // make quadrangle
410 d = uv_e1[nbright - 2].node;
412 d = quad->uv_grid[nbhoriz*(nbvertic - 2) + near + 1].node;
413 //SMDS_MeshFace* face = meshDS->AddFace(a, b, c, d);
414 if(!myTrianglePreference){
415 SMDS_MeshFace* face = myTool->AddFace(a, b, c, d);
416 meshDS->SetMeshElementOnShape(face, geomFaceID);
419 SplitQuad(meshDS, geomFaceID, a, b, c, d);
422 if (near + 1 < g) { // if d not is at g - make additional triangles
423 for (int k = near + 1; k < g; k++) {
424 c = quad->uv_grid[nbhoriz*(nbvertic - 2) + k].node;
426 d = uv_e1[nbright - 2].node;
428 d = quad->uv_grid[nbhoriz*(nbvertic - 2) + k + 1].node;
429 //SMDS_MeshFace* face = meshDS->AddFace(a, c, d);
430 SMDS_MeshFace* face = myTool->AddFace(a, c, d);
431 meshDS->SetMeshElementOnShape(face, geomFaceID);
440 // right or left boundary quadrangles
441 if (quad->isEdgeOut[1]) {
442 // MESSAGE("right edge is out");
443 int g = 0; // last processed node in the grid
444 int stop = nbright - 1;
445 if (quad->isEdgeOut[2]) stop--;
446 for (i = 0; i < stop; i++) {
447 const SMDS_MeshNode *a, *b, *c, *d;
449 b = uv_e1[i + 1].node;
450 gp_Pnt pb (b->X(), b->Y(), b->Z());
452 // find node c in the grid, nearest to the b
454 if (i == stop - 1) { // up bondary reached
455 c = quad->uv_grid[nbhoriz*(jup + 1) - 2].node;
458 double mind = RealLast();
459 for (int k = g; k <= jup; k++) {
460 const SMDS_MeshNode *nk;
462 nk = uv_e0[nbdown - 2].node;
464 nk = quad->uv_grid[nbhoriz*(k + 1) - 2].node;
465 gp_Pnt pnk (nk->X(), nk->Y(), nk->Z());
466 double dist = pb.Distance(pnk);
467 if (dist < mind - eps) {
477 if (near == g) { // make triangle
478 //SMDS_MeshFace* face = meshDS->AddFace(a, b, c);
479 SMDS_MeshFace* face = myTool->AddFace(a, b, c);
480 meshDS->SetMeshElementOnShape(face, geomFaceID);
482 else { // make quadrangle
484 d = uv_e0[nbdown - 2].node;
486 d = quad->uv_grid[nbhoriz*near - 2].node;
487 //SMDS_MeshFace* face = meshDS->AddFace(a, b, c, d);
489 if(!myTrianglePreference){
490 SMDS_MeshFace* face = myTool->AddFace(a, b, c, d);
491 meshDS->SetMeshElementOnShape(face, geomFaceID);
494 SplitQuad(meshDS, geomFaceID, a, b, c, d);
497 if (near - 1 > g) { // if d not is at g - make additional triangles
498 for (int k = near - 1; k > g; k--) {
499 c = quad->uv_grid[nbhoriz*(k + 1) - 2].node;
501 d = uv_e0[nbdown - 2].node;
503 d = quad->uv_grid[nbhoriz*k - 2].node;
504 //SMDS_MeshFace* face = meshDS->AddFace(a, c, d);
505 SMDS_MeshFace* face = myTool->AddFace(a, c, d);
506 meshDS->SetMeshElementOnShape(face, geomFaceID);
513 if (quad->isEdgeOut[3]) {
514 // MESSAGE("left edge is out");
515 int g = nbvertic - 1; // last processed node in the grid
517 if (quad->isEdgeOut[0]) stop++;
518 for (i = nbleft - 1; i > stop; i--) {
519 const SMDS_MeshNode *a, *b, *c, *d;
521 b = uv_e3[i - 1].node;
522 gp_Pnt pb (b->X(), b->Y(), b->Z());
524 // find node c in the grid, nearest to the b
526 if (i == stop + 1) { // down bondary reached
527 c = quad->uv_grid[nbhoriz*jlow + 1].node;
530 double mind = RealLast();
531 for (int k = g; k >= jlow; k--) {
532 const SMDS_MeshNode *nk;
536 nk = quad->uv_grid[nbhoriz*k + 1].node;
537 gp_Pnt pnk (nk->X(), nk->Y(), nk->Z());
538 double dist = pb.Distance(pnk);
539 if (dist < mind - eps) {
549 if (near == g) { // make triangle
550 //SMDS_MeshFace* face = meshDS->AddFace(a, b, c);
551 SMDS_MeshFace* face = myTool->AddFace(a, b, c);
552 meshDS->SetMeshElementOnShape(face, geomFaceID);
554 else { // make quadrangle
558 d = quad->uv_grid[nbhoriz*(near + 1) + 1].node;
559 //SMDS_MeshFace* face = meshDS->AddFace(a, b, c, d);
560 if(!myTrianglePreference){
561 SMDS_MeshFace* face = myTool->AddFace(a, b, c, d);
562 meshDS->SetMeshElementOnShape(face, geomFaceID);
565 SplitQuad(meshDS, geomFaceID, a, b, c, d);
568 if (near + 1 < g) { // if d not is at g - make additional triangles
569 for (int k = near + 1; k < g; k++) {
570 c = quad->uv_grid[nbhoriz*k + 1].node;
574 d = quad->uv_grid[nbhoriz*(k + 1) + 1].node;
575 //SMDS_MeshFace* face = meshDS->AddFace(a, c, d);
576 SMDS_MeshFace* face = myTool->AddFace(a, c, d);
577 meshDS->SetMeshElementOnShape(face, geomFaceID);
590 //================================================================================
592 * \brief Return true if only two given edges meat at their common vertex
594 //================================================================================
596 static bool twoEdgesMeatAtVertex(const TopoDS_Edge& e1,
597 const TopoDS_Edge& e2,
601 if ( !TopExp::CommonVertex( e1, e2, v ))
603 TopTools_ListIteratorOfListOfShape ancestIt( mesh.GetAncestors( v ));
604 for ( ; ancestIt.More() ; ancestIt.Next() )
605 if ( ancestIt.Value().ShapeType() == TopAbs_EDGE )
606 if ( !e1.IsSame( ancestIt.Value() ) && !e2.IsSame( ancestIt.Value() ))
611 //=============================================================================
615 //=============================================================================
617 FaceQuadStruct* StdMeshers_Quadrangle_2D::CheckNbEdges(SMESH_Mesh & aMesh,
618 const TopoDS_Shape & aShape)
619 //throw(SALOME_Exception)
621 const TopoDS_Face & F = TopoDS::Face(aShape);
622 const bool ignoreMediumNodes = _quadraticMesh;
624 // verify 1 wire only, with 4 edges
626 list< TopoDS_Edge > edges;
627 list< int > nbEdgesInWire;
628 int nbWire = SMESH_Block::GetOrderedEdges (F, V, edges, nbEdgesInWire);
630 error(COMPERR_BAD_SHAPE, TComm("Wrong number of wires: ") << nbWire);
633 FaceQuadStruct* quad = new FaceQuadStruct;
635 quad->side.reserve(nbEdgesInWire.front());
638 list< TopoDS_Edge >::iterator edgeIt = edges.begin();
639 if ( nbEdgesInWire.front() == 4 ) { // exactly 4 edges
640 for ( ; edgeIt != edges.end(); ++edgeIt, nbSides++ )
641 quad->side.push_back( new StdMeshers_FaceSide(F, *edgeIt, &aMesh,
642 nbSides<TOP_SIDE, ignoreMediumNodes));
644 else if ( nbEdgesInWire.front() > 4 ) { // more than 4 edges - try to unite some
645 list< TopoDS_Edge > sideEdges;
646 while ( !edges.empty()) {
648 sideEdges.splice( sideEdges.end(), edges, edges.begin()); // edges.front() -> sideEdges.end()
649 bool sameSide = true;
650 while ( !edges.empty() && sameSide ) {
651 sameSide = SMESH_Algo::IsContinuous( sideEdges.back(), edges.front() );
653 sideEdges.splice( sideEdges.end(), edges, edges.begin());
655 if ( nbSides == 0 ) { // go backward from the first edge
657 while ( !edges.empty() && sameSide ) {
658 sameSide = SMESH_Algo::IsContinuous( sideEdges.front(), edges.back() );
660 sideEdges.splice( sideEdges.begin(), edges, --edges.end());
663 quad->side.push_back( new StdMeshers_FaceSide(F, sideEdges, &aMesh,
664 nbSides<TOP_SIDE, ignoreMediumNodes));
667 // issue 20222. Try to unite only edges shared by two same faces
669 // delete found sides
670 { FaceQuadStruct cleaner( *quad ); }
672 quad->side.reserve(nbEdgesInWire.front());
675 SMESH_Block::GetOrderedEdges (F, V, edges, nbEdgesInWire);
676 while ( !edges.empty()) {
678 sideEdges.splice( sideEdges.end(), edges, edges.begin());
679 bool sameSide = true;
680 while ( !edges.empty() && sameSide ) {
682 SMESH_Algo::IsContinuous( sideEdges.back(), edges.front() ) &&
683 twoEdgesMeatAtVertex( sideEdges.back(), edges.front(), aMesh );
685 sideEdges.splice( sideEdges.end(), edges, edges.begin());
687 if ( nbSides == 0 ) { // go backward from the first edge
689 while ( !edges.empty() && sameSide ) {
691 SMESH_Algo::IsContinuous( sideEdges.front(), edges.back() ) &&
692 twoEdgesMeatAtVertex( sideEdges.front(), edges.back(), aMesh );
694 sideEdges.splice( sideEdges.begin(), edges, --edges.end());
697 quad->side.push_back( new StdMeshers_FaceSide(F, sideEdges, &aMesh,
698 nbSides<TOP_SIDE, ignoreMediumNodes));
705 MESSAGE ( "StdMeshers_Quadrangle_2D. Edge IDs of " << nbSides << " sides:\n" );
706 for ( int i = 0; i < nbSides; ++i ) {
708 for ( int e = 0; e < quad->side[i]->NbEdges(); ++e )
709 MESSAGE ( myTool->GetMeshDS()->ShapeToIndex( quad->side[i]->Edge( e )) << " " );
715 nbSides = nbEdgesInWire.front();
716 error(COMPERR_BAD_SHAPE, TComm("Face must have 4 sides but not ") << nbSides);
724 //=============================================================================
728 //=============================================================================
730 FaceQuadStruct *StdMeshers_Quadrangle_2D::CheckAnd2Dcompute
732 const TopoDS_Shape & aShape,
733 const bool CreateQuadratic) //throw(SALOME_Exception)
735 _quadraticMesh = CreateQuadratic;
737 FaceQuadStruct *quad = CheckNbEdges(aMesh, aShape);
741 // set normalized grid on unit square in parametric domain
742 bool stat = SetNormalizedGrid(aMesh, aShape, quad);
752 //=============================================================================
756 //=============================================================================
758 faceQuadStruct::~faceQuadStruct()
760 for (int i = 0; i < side.size(); i++) {
761 if (side[i]) delete side[i];
763 if (uv_grid) delete [] uv_grid;
767 inline const vector<UVPtStruct>& GetUVPtStructIn(FaceQuadStruct* quad, int i, int nbSeg)
769 bool isXConst = ( i == BOTTOM_SIDE || i == TOP_SIDE );
770 double constValue = ( i == BOTTOM_SIDE || i == LEFT_SIDE ) ? 0 : 1;
773 quad->side[i]->SimulateUVPtStruct(nbSeg,isXConst,constValue) :
774 quad->side[i]->GetUVPtStruct(isXConst,constValue);
778 //=============================================================================
782 //=============================================================================
784 bool StdMeshers_Quadrangle_2D::SetNormalizedGrid (SMESH_Mesh & aMesh,
785 const TopoDS_Shape& aShape,
786 FaceQuadStruct* & quad) //throw (SALOME_Exception)
788 // Algorithme décrit dans "Génération automatique de maillages"
789 // P.L. GEORGE, MASSON, § 6.4.1 p. 84-85
790 // traitement dans le domaine paramétrique 2d u,v
791 // transport - projection sur le carré unité
793 // MESSAGE("StdMeshers_Quadrangle_2D::SetNormalizedGrid");
794 // const TopoDS_Face& F = TopoDS::Face(aShape);
796 // 1 --- find orientation of the 4 edges, by test on extrema
799 // |<----north-2-------^ a3 -------------> a2
801 // west-3 east-1 =right | |
805 // v----south-0--------> a0 -------------> a1
810 // 3 --- 2D normalized values on unit square [0..1][0..1]
812 int nbhoriz = Min(quad->side[0]->NbPoints(), quad->side[2]->NbPoints());
813 int nbvertic = Min(quad->side[1]->NbPoints(), quad->side[3]->NbPoints());
815 quad->isEdgeOut[0] = (quad->side[0]->NbPoints() > quad->side[2]->NbPoints());
816 quad->isEdgeOut[1] = (quad->side[1]->NbPoints() > quad->side[3]->NbPoints());
817 quad->isEdgeOut[2] = (quad->side[2]->NbPoints() > quad->side[0]->NbPoints());
818 quad->isEdgeOut[3] = (quad->side[3]->NbPoints() > quad->side[1]->NbPoints());
820 UVPtStruct *uv_grid = quad->uv_grid = new UVPtStruct[nbvertic * nbhoriz];
822 const vector<UVPtStruct>& uv_e0 = GetUVPtStructIn( quad, 0, nbhoriz - 1 );
823 const vector<UVPtStruct>& uv_e1 = GetUVPtStructIn( quad, 1, nbvertic - 1 );
824 const vector<UVPtStruct>& uv_e2 = GetUVPtStructIn( quad, 2, nbhoriz - 1 );
825 const vector<UVPtStruct>& uv_e3 = GetUVPtStructIn( quad, 3, nbvertic - 1 );
827 if ( uv_e0.empty() || uv_e1.empty() || uv_e2.empty() || uv_e3.empty() )
828 //return error( "Can't find nodes on sides");
829 return error( COMPERR_BAD_INPUT_MESH );
831 // nodes Id on "in" edges
832 if (! quad->isEdgeOut[0]) {
834 for (int i = 0; i < nbhoriz; i++) { // down
835 int ij = j * nbhoriz + i;
836 uv_grid[ij].node = uv_e0[i].node;
839 if (! quad->isEdgeOut[1]) {
841 for (int j = 0; j < nbvertic; j++) { // right
842 int ij = j * nbhoriz + i;
843 uv_grid[ij].node = uv_e1[j].node;
846 if (! quad->isEdgeOut[2]) {
847 int j = nbvertic - 1;
848 for (int i = 0; i < nbhoriz; i++) { // up
849 int ij = j * nbhoriz + i;
850 uv_grid[ij].node = uv_e2[i].node;
853 if (! quad->isEdgeOut[3]) {
855 for (int j = 0; j < nbvertic; j++) { // left
856 int ij = j * nbhoriz + i;
857 uv_grid[ij].node = uv_e3[j].node;
861 // normalized 2d values on grid
862 for (int i = 0; i < nbhoriz; i++)
864 for (int j = 0; j < nbvertic; j++)
866 int ij = j * nbhoriz + i;
867 // --- droite i cste : x = x0 + y(x1-x0)
868 double x0 = uv_e0[i].normParam; // bas - sud
869 double x1 = uv_e2[i].normParam; // haut - nord
870 // --- droite j cste : y = y0 + x(y1-y0)
871 double y0 = uv_e3[j].normParam; // gauche-ouest
872 double y1 = uv_e1[j].normParam; // droite - est
873 // --- intersection : x=x0+(y0+x(y1-y0))(x1-x0)
874 double x = (x0 + y0 * (x1 - x0)) / (1 - (y1 - y0) * (x1 - x0));
875 double y = y0 + x * (y1 - y0);
878 //MESSAGE("-xy-01 "<<x0<<" "<<x1<<" "<<y0<<" "<<y1);
879 //MESSAGE("-xy-norm "<<i<<" "<<j<<" "<<x<<" "<<y);
883 // 4 --- projection on 2d domain (u,v)
884 gp_UV a0( uv_e0.front().u, uv_e0.front().v );
885 gp_UV a1( uv_e0.back().u, uv_e0.back().v );
886 gp_UV a2( uv_e2.back().u, uv_e2.back().v );
887 gp_UV a3( uv_e2.front().u, uv_e2.front().v );
889 for (int i = 0; i < nbhoriz; i++)
891 for (int j = 0; j < nbvertic; j++)
893 int ij = j * nbhoriz + i;
894 double x = uv_grid[ij].x;
895 double y = uv_grid[ij].y;
896 double param_0 = uv_e0[0].normParam + x * (uv_e0.back().normParam - uv_e0[0].normParam); // sud
897 double param_2 = uv_e2[0].normParam + x * (uv_e2.back().normParam - uv_e2[0].normParam); // nord
898 double param_1 = uv_e1[0].normParam + y * (uv_e1.back().normParam - uv_e1[0].normParam); // est
899 double param_3 = uv_e3[0].normParam + y * (uv_e3.back().normParam - uv_e3[0].normParam); // ouest
901 //MESSAGE("params "<<param_0<<" "<<param_1<<" "<<param_2<<" "<<param_3);
902 gp_UV p0 = quad->side[0]->Value2d(param_0).XY();
903 gp_UV p1 = quad->side[1]->Value2d(param_1).XY();
904 gp_UV p2 = quad->side[2]->Value2d(param_2).XY();
905 gp_UV p3 = quad->side[3]->Value2d(param_3).XY();
907 gp_UV uv = (1 - y) * p0 + x * p1 + y * p2 + (1 - x) * p3;
908 uv -= (1 - x) * (1 - y) * a0 + x * (1 - y) * a1 + x * y * a2 + (1 - x) * y * a3;
910 uv_grid[ij].u = uv.X();
911 uv_grid[ij].v = uv.Y();
917 //=======================================================================
918 //function : ShiftQuad
919 //purpose : auxilary function for ComputeQuadPref
920 //=======================================================================
922 static void ShiftQuad(FaceQuadStruct* quad, const int num, bool)
924 StdMeshers_FaceSide* side[4] = { quad->side[0], quad->side[1], quad->side[2], quad->side[3] };
925 for (int i = BOTTOM_SIDE; i < NB_SIDES; ++i ) {
926 int id = ( i + num ) % NB_SIDES;
927 bool wasForward = ( i < TOP_SIDE );
928 bool newForward = ( id < TOP_SIDE );
929 if ( wasForward != newForward )
930 side[ i ]->Reverse();
931 quad->side[ id ] = side[ i ];
935 //=======================================================================
937 //purpose : auxilary function for ComputeQuadPref
938 //=======================================================================
940 static gp_UV CalcUV(double x0, double x1, double y0, double y1,
941 FaceQuadStruct* quad,
942 const gp_UV& a0, const gp_UV& a1,
943 const gp_UV& a2, const gp_UV& a3)
945 const vector<UVPtStruct>& uv_eb = quad->side[0]->GetUVPtStruct(true,0 );
946 const vector<UVPtStruct>& uv_er = quad->side[1]->GetUVPtStruct(false,1);
947 const vector<UVPtStruct>& uv_et = quad->side[2]->GetUVPtStruct(true,1 );
948 const vector<UVPtStruct>& uv_el = quad->side[3]->GetUVPtStruct(false,0);
950 double x = (x0 + y0 * (x1 - x0)) / (1 - (y1 - y0) * (x1 - x0));
951 double y = y0 + x * (y1 - y0);
953 double param_b = uv_eb[0].normParam + x * (uv_eb.back().normParam - uv_eb[0].normParam);
954 double param_t = uv_et[0].normParam + x * (uv_et.back().normParam - uv_et[0].normParam);
955 double param_r = uv_er[0].normParam + y * (uv_er.back().normParam - uv_er[0].normParam);
956 double param_l = uv_el[0].normParam + y * (uv_el.back().normParam - uv_el[0].normParam);
958 gp_UV p0 = quad->side[BOTTOM_SIDE]->Value2d(param_b).XY();
959 gp_UV p1 = quad->side[RIGHT_SIDE ]->Value2d(param_r).XY();
960 gp_UV p2 = quad->side[TOP_SIDE ]->Value2d(param_t).XY();
961 gp_UV p3 = quad->side[LEFT_SIDE ]->Value2d(param_l).XY();
963 gp_UV uv = p0 * (1 - y) + p1 * x + p2 * y + p3 * (1 - x);
965 uv -= (1 - x) * (1 - y) * a0 + x * (1 - y) * a1 + x * y * a2 + (1 - x) * y * a3;
970 //=======================================================================
972 //purpose : auxilary function for ComputeQuadPref
973 //=======================================================================
975 static gp_UV CalcUV2(double x, double y,
976 FaceQuadStruct* quad,
977 const gp_UV& a0, const gp_UV& a1,
978 const gp_UV& a2, const gp_UV& a3)
980 const vector<UVPtStruct>& uv_eb = quad->side[0]->GetUVPtStruct(true,0 );
981 const vector<UVPtStruct>& uv_er = quad->side[1]->GetUVPtStruct(false,1);
982 const vector<UVPtStruct>& uv_et = quad->side[2]->GetUVPtStruct(true,1 );
983 const vector<UVPtStruct>& uv_el = quad->side[3]->GetUVPtStruct(false,0);
985 //double x = (x0 + y0 * (x1 - x0)) / (1 - (y1 - y0) * (x1 - x0));
986 //double y = y0 + x * (y1 - y0);
988 double param_b = uv_eb[0].normParam + x * (uv_eb.back().normParam - uv_eb[0].normParam);
989 double param_t = uv_et[0].normParam + x * (uv_et.back().normParam - uv_et[0].normParam);
990 double param_r = uv_er[0].normParam + y * (uv_er.back().normParam - uv_er[0].normParam);
991 double param_l = uv_el[0].normParam + y * (uv_el.back().normParam - uv_el[0].normParam);
993 gp_UV p0 = quad->side[BOTTOM_SIDE]->Value2d(param_b).XY();
994 gp_UV p1 = quad->side[RIGHT_SIDE ]->Value2d(param_r).XY();
995 gp_UV p2 = quad->side[TOP_SIDE ]->Value2d(param_t).XY();
996 gp_UV p3 = quad->side[LEFT_SIDE ]->Value2d(param_l).XY();
998 gp_UV uv = p0 * (1 - y) + p1 * x + p2 * y + p3 * (1 - x);
1000 uv -= (1 - x) * (1 - y) * a0 + x * (1 - y) * a1 + x * y * a2 + (1 - x) * y * a3;
1006 //=======================================================================
1008 * Create only quandrangle faces
1010 //=======================================================================
1012 bool StdMeshers_Quadrangle_2D::ComputeQuadPref (SMESH_Mesh & aMesh,
1013 const TopoDS_Shape& aShape,
1014 FaceQuadStruct* quad)
1016 // Auxilary key in order to keep old variant
1017 // of meshing after implementation new variant
1018 // for bug 0016220 from Mantis.
1019 bool OldVersion = false;
1021 SMESHDS_Mesh * meshDS = aMesh.GetMeshDS();
1022 const TopoDS_Face& F = TopoDS::Face(aShape);
1023 Handle(Geom_Surface) S = BRep_Tool::Surface(F);
1024 // const TopoDS_Wire& W = BRepTools::OuterWire(F);
1026 // if(W.Orientation()==TopAbs_FORWARD)
1028 //if(WisF) cout<<"W is FORWARD"<<endl;
1029 //else cout<<"W is REVERSED"<<endl;
1030 // bool FisF = (F.Orientation()==TopAbs_FORWARD);
1031 // if(!FisF) WisF = !WisF;
1033 int i,j,geomFaceID = meshDS->ShapeToIndex( F );
1035 int nb = quad->side[0]->NbPoints();
1036 int nr = quad->side[1]->NbPoints();
1037 int nt = quad->side[2]->NbPoints();
1038 int nl = quad->side[3]->NbPoints();
1039 int dh = abs(nb-nt);
1040 int dv = abs(nr-nl);
1044 // it is a base case => not shift quad but me be replacement is need
1045 ShiftQuad(quad,0,WisF);
1048 // we have to shift quad on 2
1049 ShiftQuad(quad,2,WisF);
1054 // we have to shift quad on 1
1055 ShiftQuad(quad,1,WisF);
1058 // we have to shift quad on 3
1059 ShiftQuad(quad,3,WisF);
1063 nb = quad->side[0]->NbPoints();
1064 nr = quad->side[1]->NbPoints();
1065 nt = quad->side[2]->NbPoints();
1066 nl = quad->side[3]->NbPoints();
1069 int nbh = Max(nb,nt);
1070 int nbv = Max(nr,nl);
1074 // ----------- Old version ---------------
1075 // orientation of face and 3 main domain for future faces
1081 // left | | | | rigth
1088 // ----------- New version ---------------
1089 // orientation of face and 3 main domain for future faces
1095 // left |/________\| rigth
1111 const vector<UVPtStruct>& uv_eb = quad->side[0]->GetUVPtStruct(true,0 );
1112 const vector<UVPtStruct>& uv_er = quad->side[1]->GetUVPtStruct(false,1);
1113 const vector<UVPtStruct>& uv_et = quad->side[2]->GetUVPtStruct(true,1 );
1114 const vector<UVPtStruct>& uv_el = quad->side[3]->GetUVPtStruct(false,0);
1116 // arrays for normalized params
1117 //cout<<"Dump B:"<<endl;
1118 TColStd_SequenceOfReal npb, npr, npt, npl;
1119 for(i=0; i<nb; i++) {
1120 npb.Append(uv_eb[i].normParam);
1121 //cout<<"i="<<i<<" par="<<uv_eb[i].normParam<<" npar="<<uv_eb[i].normParam;
1122 //const SMDS_MeshNode* N = uv_eb[i].node;
1123 //cout<<" node("<<N->X()<<","<<N->Y()<<","<<N->Z()<<")"<<endl;
1125 for(i=0; i<nr; i++) {
1126 npr.Append(uv_er[i].normParam);
1128 for(i=0; i<nt; i++) {
1129 npt.Append(uv_et[i].normParam);
1131 for(i=0; i<nl; i++) {
1132 npl.Append(uv_el[i].normParam);
1137 // add some params to right and left after the first param
1140 double dpr = (npr.Value(2) - npr.Value(1))/(dr+1);
1141 for(i=1; i<=dr; i++) {
1142 npr.InsertAfter(1,npr.Value(2)-dpr);
1146 dpr = (npl.Value(2) - npl.Value(1))/(dl+1);
1147 for(i=1; i<=dl; i++) {
1148 npl.InsertAfter(1,npl.Value(2)-dpr);
1152 //for(i=1; i<=npb.Length(); i++) {
1153 // cout<<" "<<npb.Value(i);
1157 gp_XY a0( uv_eb.front().u, uv_eb.front().v );
1158 gp_XY a1( uv_eb.back().u, uv_eb.back().v );
1159 gp_XY a2( uv_et.back().u, uv_et.back().v );
1160 gp_XY a3( uv_et.front().u, uv_et.front().v );
1161 //cout<<" a0("<<a0.X()<<","<<a0.Y()<<")"<<" a1("<<a1.X()<<","<<a1.Y()<<")"
1162 // <<" a2("<<a2.X()<<","<<a2.Y()<<")"<<" a3("<<a3.X()<<","<<a3.Y()<<")"<<endl;
1164 int nnn = Min(nr,nl);
1165 // auxilary sequence of XY for creation nodes
1166 // in the bottom part of central domain
1167 // it's length must be == nbv-nnn-1
1168 TColgp_SequenceOfXY UVL;
1169 TColgp_SequenceOfXY UVR;
1172 // step1: create faces for left domain
1173 StdMeshers_Array2OfNode NodesL(1,dl+1,1,nl);
1175 for(j=1; j<=nl; j++)
1176 NodesL.SetValue(1,j,uv_el[j-1].node);
1179 for(i=1; i<=dl; i++)
1180 NodesL.SetValue(i+1,nl,uv_et[i].node);
1181 // create and add needed nodes
1182 TColgp_SequenceOfXY UVtmp;
1183 for(i=1; i<=dl; i++) {
1184 double x0 = npt.Value(i+1);
1187 double y0 = npl.Value(i+1);
1188 double y1 = npr.Value(i+1);
1189 gp_UV UV = CalcUV(x0, x1, y0, y1, quad, a0, a1, a2, a3);
1190 gp_Pnt P = S->Value(UV.X(),UV.Y());
1191 SMDS_MeshNode * N = meshDS->AddNode(P.X(), P.Y(), P.Z());
1192 meshDS->SetNodeOnFace(N, geomFaceID, UV.X(), UV.Y());
1193 NodesL.SetValue(i+1,1,N);
1194 if(UVL.Length()<nbv-nnn-1) UVL.Append(UV);
1196 for(j=2; j<nl; j++) {
1197 double y0 = npl.Value(dl+j);
1198 double y1 = npr.Value(dl+j);
1199 gp_UV UV = CalcUV(x0, x1, y0, y1, quad, a0, a1, a2, a3);
1200 gp_Pnt P = S->Value(UV.X(),UV.Y());
1201 SMDS_MeshNode* N = meshDS->AddNode(P.X(), P.Y(), P.Z());
1202 meshDS->SetNodeOnFace(N, geomFaceID, UV.X(), UV.Y());
1203 NodesL.SetValue(i+1,j,N);
1204 if( i==dl ) UVtmp.Append(UV);
1207 for(i=1; i<=UVtmp.Length() && UVL.Length()<nbv-nnn-1; i++) {
1208 UVL.Append(UVtmp.Value(i));
1210 //cout<<"Dump NodesL:"<<endl;
1211 //for(i=1; i<=dl+1; i++) {
1213 // for(j=1; j<=nl; j++) {
1214 // cout<<" ("<<NodesL.Value(i,j)->X()<<","<<NodesL.Value(i,j)->Y()<<","<<NodesL.Value(i,j)->Z()<<")";
1219 for(i=1; i<=dl; i++) {
1220 for(j=1; j<nl; j++) {
1223 myTool->AddFace(NodesL.Value(i,j), NodesL.Value(i+1,j),
1224 NodesL.Value(i+1,j+1), NodesL.Value(i,j+1));
1225 meshDS->SetMeshElementOnShape(F, geomFaceID);
1229 myTool->AddFace(NodesL.Value(i,j), NodesL.Value(i,j+1),
1230 NodesL.Value(i+1,j+1), NodesL.Value(i+1,j));
1231 meshDS->SetMeshElementOnShape(F, geomFaceID);
1237 // fill UVL using c2d
1238 for(i=1; i<npl.Length() && UVL.Length()<nbv-nnn-1; i++) {
1239 UVL.Append( gp_UV ( uv_el[i].u, uv_el[i].v ));
1243 // step2: create faces for right domain
1244 StdMeshers_Array2OfNode NodesR(1,dr+1,1,nr);
1246 for(j=1; j<=nr; j++)
1247 NodesR.SetValue(1,j,uv_er[nr-j].node);
1250 for(i=1; i<=dr; i++)
1251 NodesR.SetValue(i+1,1,uv_et[nt-1-i].node);
1252 // create and add needed nodes
1253 TColgp_SequenceOfXY UVtmp;
1254 for(i=1; i<=dr; i++) {
1255 double x0 = npt.Value(nt-i);
1258 double y0 = npl.Value(i+1);
1259 double y1 = npr.Value(i+1);
1260 gp_UV UV = CalcUV(x0, x1, y0, y1, quad, a0, a1, a2, a3);
1261 gp_Pnt P = S->Value(UV.X(),UV.Y());
1262 SMDS_MeshNode * N = meshDS->AddNode(P.X(), P.Y(), P.Z());
1263 meshDS->SetNodeOnFace(N, geomFaceID, UV.X(), UV.Y());
1264 NodesR.SetValue(i+1,nr,N);
1265 if(UVR.Length()<nbv-nnn-1) UVR.Append(UV);
1267 for(j=2; j<nr; j++) {
1268 double y0 = npl.Value(nbv-j+1);
1269 double y1 = npr.Value(nbv-j+1);
1270 gp_UV UV = CalcUV(x0, x1, y0, y1, quad, a0, a1, a2, a3);
1271 gp_Pnt P = S->Value(UV.X(),UV.Y());
1272 SMDS_MeshNode* N = meshDS->AddNode(P.X(), P.Y(), P.Z());
1273 meshDS->SetNodeOnFace(N, geomFaceID, UV.X(), UV.Y());
1274 NodesR.SetValue(i+1,j,N);
1275 if( i==dr ) UVtmp.Prepend(UV);
1278 for(i=1; i<=UVtmp.Length() && UVR.Length()<nbv-nnn-1; i++) {
1279 UVR.Append(UVtmp.Value(i));
1282 for(i=1; i<=dr; i++) {
1283 for(j=1; j<nr; j++) {
1286 myTool->AddFace(NodesR.Value(i,j), NodesR.Value(i+1,j),
1287 NodesR.Value(i+1,j+1), NodesR.Value(i,j+1));
1288 meshDS->SetMeshElementOnShape(F, geomFaceID);
1292 myTool->AddFace(NodesR.Value(i,j), NodesR.Value(i,j+1),
1293 NodesR.Value(i+1,j+1), NodesR.Value(i+1,j));
1294 meshDS->SetMeshElementOnShape(F, geomFaceID);
1300 // fill UVR using c2d
1301 for(i=1; i<npr.Length() && UVR.Length()<nbv-nnn-1; i++) {
1302 UVR.Append( gp_UV( uv_er[i].u, uv_er[i].v ));
1306 // step3: create faces for central domain
1307 StdMeshers_Array2OfNode NodesC(1,nb,1,nbv);
1308 // add first string using NodesL
1309 for(i=1; i<=dl+1; i++)
1310 NodesC.SetValue(1,i,NodesL(i,1));
1311 for(i=2; i<=nl; i++)
1312 NodesC.SetValue(1,dl+i,NodesL(dl+1,i));
1313 // add last string using NodesR
1314 for(i=1; i<=dr+1; i++)
1315 NodesC.SetValue(nb,i,NodesR(i,nr));
1317 NodesC.SetValue(nb,dr+i+1,NodesR(dr+1,nr-i));
1318 // add top nodes (last columns)
1319 for(i=dl+2; i<nbh-dr; i++)
1320 NodesC.SetValue(i-dl,nbv,uv_et[i-1].node);
1321 // add bottom nodes (first columns)
1323 NodesC.SetValue(i,1,uv_eb[i-1].node);
1325 // create and add needed nodes
1326 // add linear layers
1327 for(i=2; i<nb; i++) {
1328 double x0 = npt.Value(dl+i);
1330 for(j=1; j<nnn; j++) {
1331 double y0 = npl.Value(nbv-nnn+j);
1332 double y1 = npr.Value(nbv-nnn+j);
1333 gp_UV UV = CalcUV(x0, x1, y0, y1, quad, a0, a1, a2, a3);
1334 gp_Pnt P = S->Value(UV.X(),UV.Y());
1335 SMDS_MeshNode* N = meshDS->AddNode(P.X(), P.Y(), P.Z());
1336 meshDS->SetNodeOnFace(N, geomFaceID, UV.X(), UV.Y());
1337 NodesC.SetValue(i,nbv-nnn+j,N);
1340 // add diagonal layers
1341 //cout<<"UVL.Length()="<<UVL.Length()<<" UVR.Length()="<<UVR.Length()<<endl;
1342 //cout<<"Dump UVL:"<<endl;
1343 //for(i=1; i<=UVL.Length(); i++) {
1344 // cout<<" ("<<UVL.Value(i).X()<<","<<UVL.Value(i).Y()<<")";
1347 for(i=1; i<nbv-nnn; i++) {
1348 double du = UVR.Value(i).X() - UVL.Value(i).X();
1349 double dv = UVR.Value(i).Y() - UVL.Value(i).Y();
1350 for(j=2; j<nb; j++) {
1351 double u = UVL.Value(i).X() + du*npb.Value(j);
1352 double v = UVL.Value(i).Y() + dv*npb.Value(j);
1353 gp_Pnt P = S->Value(u,v);
1354 SMDS_MeshNode* N = meshDS->AddNode(P.X(), P.Y(), P.Z());
1355 meshDS->SetNodeOnFace(N, geomFaceID, u, v);
1356 NodesC.SetValue(j,i+1,N);
1360 for(i=1; i<nb; i++) {
1361 for(j=1; j<nbv; j++) {
1364 myTool->AddFace(NodesC.Value(i,j), NodesC.Value(i+1,j),
1365 NodesC.Value(i+1,j+1), NodesC.Value(i,j+1));
1366 meshDS->SetMeshElementOnShape(F, geomFaceID);
1370 myTool->AddFace(NodesC.Value(i,j), NodesC.Value(i,j+1),
1371 NodesC.Value(i+1,j+1), NodesC.Value(i+1,j));
1372 meshDS->SetMeshElementOnShape(F, geomFaceID);
1378 else { // New version (!OldVersion)
1379 // step1: create faces for bottom rectangle domain
1380 StdMeshers_Array2OfNode NodesBRD(1,nb,1,nnn-1);
1381 // fill UVL and UVR using c2d
1382 for(j=0; j<nb; j++) {
1383 NodesBRD.SetValue(j+1,1,uv_eb[j].node);
1385 for(i=1; i<nnn-1; i++) {
1386 NodesBRD.SetValue(1,i+1,uv_el[i].node);
1387 NodesBRD.SetValue(nb,i+1,uv_er[i].node);
1388 double du = uv_er[i].u - uv_el[i].u;
1389 double dv = uv_er[i].v - uv_el[i].v;
1390 for(j=2; j<nb; j++) {
1391 double u = uv_el[i].u + du*npb.Value(j);
1392 double v = uv_el[i].v + dv*npb.Value(j);
1393 gp_Pnt P = S->Value(u,v);
1394 SMDS_MeshNode* N = meshDS->AddNode(P.X(), P.Y(), P.Z());
1395 meshDS->SetNodeOnFace(N, geomFaceID, u, v);
1396 NodesBRD.SetValue(j,i+1,N);
1400 for(j=1; j<nnn-1; j++) {
1401 for(i=1; i<nb; i++) {
1404 myTool->AddFace(NodesBRD.Value(i,j), NodesBRD.Value(i+1,j),
1405 NodesBRD.Value(i+1,j+1), NodesBRD.Value(i,j+1));
1406 meshDS->SetMeshElementOnShape(F, geomFaceID);
1410 myTool->AddFace(NodesBRD.Value(i,j), NodesBRD.Value(i,j+1),
1411 NodesBRD.Value(i+1,j+1), NodesBRD.Value(i+1,j));
1412 meshDS->SetMeshElementOnShape(F, geomFaceID);
1417 int drl = abs(nr-nl);
1418 // create faces for region C
1419 StdMeshers_Array2OfNode NodesC(1,nb,1,drl+1+addv);
1420 // add nodes from previous region
1421 for(j=1; j<=nb; j++) {
1422 NodesC.SetValue(j,1,NodesBRD.Value(j,nnn-1));
1424 if( (drl+addv) > 0 ) {
1429 TColgp_SequenceOfXY UVtmp;
1430 double drparam = npr.Value(nr) - npr.Value(nnn-1);
1431 double dlparam = npl.Value(nnn) - npl.Value(nnn-1);
1433 for(i=1; i<=drl; i++) {
1434 // add existed nodes from right edge
1435 NodesC.SetValue(nb,i+1,uv_er[nnn+i-2].node);
1436 //double dtparam = npt.Value(i+1);
1437 y1 = npr.Value(nnn+i-1); // param on right edge
1438 double dpar = (y1 - npr.Value(nnn-1))/drparam;
1439 y0 = npl.Value(nnn-1) + dpar*dlparam; // param on left edge
1440 double dy = y1 - y0;
1441 for(j=1; j<nb; j++) {
1442 double x = npt.Value(i+1) + npb.Value(j)*(1-npt.Value(i+1));
1443 double y = y0 + dy*x;
1444 gp_UV UV = CalcUV2(x, y, quad, a0, a1, a2, a3);
1445 gp_Pnt P = S->Value(UV.X(),UV.Y());
1446 SMDS_MeshNode* N = meshDS->AddNode(P.X(), P.Y(), P.Z());
1447 meshDS->SetNodeOnFace(N, geomFaceID, UV.X(), UV.Y());
1448 NodesC.SetValue(j,i+1,N);
1451 double dy0 = (1-y0)/(addv+1);
1452 double dy1 = (1-y1)/(addv+1);
1453 for(i=1; i<=addv; i++) {
1454 double yy0 = y0 + dy0*i;
1455 double yy1 = y1 + dy1*i;
1456 double dyy = yy1 - yy0;
1457 for(j=1; j<=nb; j++) {
1458 double x = npt.Value(i+1+drl) +
1459 npb.Value(j) * ( npt.Value(nt-i) - npt.Value(i+1+drl) );
1460 double y = yy0 + dyy*x;
1461 gp_UV UV = CalcUV2(x, y, quad, a0, a1, a2, a3);
1462 gp_Pnt P = S->Value(UV.X(),UV.Y());
1463 SMDS_MeshNode* N = meshDS->AddNode(P.X(), P.Y(), P.Z());
1464 meshDS->SetNodeOnFace(N, geomFaceID, UV.X(), UV.Y());
1465 NodesC.SetValue(j,i+drl+1,N);
1472 TColgp_SequenceOfXY UVtmp;
1473 double dlparam = npl.Value(nl) - npl.Value(nnn-1);
1474 double drparam = npr.Value(nnn) - npr.Value(nnn-1);
1475 double y0 = npl.Value(nnn-1);
1476 double y1 = npr.Value(nnn-1);
1477 for(i=1; i<=drl; i++) {
1478 // add existed nodes from right edge
1479 NodesC.SetValue(1,i+1,uv_el[nnn+i-2].node);
1480 y0 = npl.Value(nnn+i-1); // param on left edge
1481 double dpar = (y0 - npl.Value(nnn-1))/dlparam;
1482 y1 = npr.Value(nnn-1) + dpar*drparam; // param on right edge
1483 double dy = y1 - y0;
1484 for(j=2; j<=nb; j++) {
1485 double x = npb.Value(j)*npt.Value(nt-i);
1486 double y = y0 + dy*x;
1487 gp_UV UV = CalcUV2(x, y, quad, a0, a1, a2, a3);
1488 gp_Pnt P = S->Value(UV.X(),UV.Y());
1489 SMDS_MeshNode* N = meshDS->AddNode(P.X(), P.Y(), P.Z());
1490 meshDS->SetNodeOnFace(N, geomFaceID, UV.X(), UV.Y());
1491 NodesC.SetValue(j,i+1,N);
1494 double dy0 = (1-y0)/(addv+1);
1495 double dy1 = (1-y1)/(addv+1);
1496 for(i=1; i<=addv; i++) {
1497 double yy0 = y0 + dy0*i;
1498 double yy1 = y1 + dy1*i;
1499 double dyy = yy1 - yy0;
1500 for(j=1; j<=nb; j++) {
1501 double x = npt.Value(i+1) +
1502 npb.Value(j) * ( npt.Value(nt-i-drl) - npt.Value(i+1) );
1503 double y = yy0 + dyy*x;
1504 gp_UV UV = CalcUV2(x, y, quad, a0, a1, a2, a3);
1505 gp_Pnt P = S->Value(UV.X(),UV.Y());
1506 SMDS_MeshNode* N = meshDS->AddNode(P.X(), P.Y(), P.Z());
1507 meshDS->SetNodeOnFace(N, geomFaceID, UV.X(), UV.Y());
1508 NodesC.SetValue(j,i+drl+1,N);
1513 for(j=1; j<=drl+addv; j++) {
1514 for(i=1; i<nb; i++) {
1517 myTool->AddFace(NodesC.Value(i,j), NodesC.Value(i+1,j),
1518 NodesC.Value(i+1,j+1), NodesC.Value(i,j+1));
1519 meshDS->SetMeshElementOnShape(F, geomFaceID);
1523 myTool->AddFace(NodesC.Value(i,j), NodesC.Value(i,j+1),
1524 NodesC.Value(i+1,j+1), NodesC.Value(i+1,j));
1525 meshDS->SetMeshElementOnShape(F, geomFaceID);
1530 StdMeshers_Array2OfNode NodesLast(1,nt,1,2);
1531 for(i=1; i<=nt; i++) {
1532 NodesLast.SetValue(i,2,uv_et[i-1].node);
1535 for(i=n1; i<drl+addv+1; i++) {
1537 NodesLast.SetValue(nnn,1,NodesC.Value(1,i));
1539 for(i=1; i<=nb; i++) {
1541 NodesLast.SetValue(nnn,1,NodesC.Value(i,drl+addv+1));
1543 for(i=drl+addv; i>=n2; i--) {
1545 NodesLast.SetValue(nnn,1,NodesC.Value(nb,i));
1547 for(i=1; i<nt; i++) {
1550 myTool->AddFace(NodesLast.Value(i,1), NodesLast.Value(i+1,1),
1551 NodesLast.Value(i+1,2), NodesLast.Value(i,2));
1552 meshDS->SetMeshElementOnShape(F, geomFaceID);
1556 myTool->AddFace(NodesLast.Value(i,1), NodesLast.Value(i,2),
1557 NodesLast.Value(i+1,2), NodesLast.Value(i+1,2));
1558 meshDS->SetMeshElementOnShape(F, geomFaceID);
1561 } // if( (drl+addv) > 0 )
1563 } // end new version implementation
1569 //=============================================================================
1570 /*! Split quadrangle in to 2 triangles by smallest diagonal
1573 //=============================================================================
1574 void StdMeshers_Quadrangle_2D::SplitQuad(SMESHDS_Mesh *theMeshDS,
1576 const SMDS_MeshNode* theNode1,
1577 const SMDS_MeshNode* theNode2,
1578 const SMDS_MeshNode* theNode3,
1579 const SMDS_MeshNode* theNode4)
1581 gp_Pnt a(theNode1->X(),theNode1->Y(),theNode1->Z());
1582 gp_Pnt b(theNode2->X(),theNode2->Y(),theNode2->Z());
1583 gp_Pnt c(theNode3->X(),theNode3->Y(),theNode3->Z());
1584 gp_Pnt d(theNode4->X(),theNode4->Y(),theNode4->Z());
1585 SMDS_MeshFace* face;
1586 if(a.Distance(c) > b.Distance(d)){
1587 face = myTool->AddFace(theNode2, theNode4 , theNode1);
1588 theMeshDS->SetMeshElementOnShape(face, theFaceID );
1589 face = myTool->AddFace(theNode2, theNode3, theNode4);
1590 theMeshDS->SetMeshElementOnShape(face, theFaceID );
1594 face = myTool->AddFace(theNode1, theNode2 ,theNode3);
1595 theMeshDS->SetMeshElementOnShape(face, theFaceID );
1596 face = myTool->AddFace(theNode1, theNode3, theNode4);
1597 theMeshDS->SetMeshElementOnShape(face, theFaceID );