1 // SMESH SMESH : implementaion of SMESH idl descriptions
3 // Copyright (C) 2003 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
24 // File : StdMeshers_Quadrangle_2D.cxx
25 // Moved here from SMESH_Quadrangle_2D.cxx
26 // Author : Paul RASCLE, EDF
30 #include "StdMeshers_Quadrangle_2D.hxx"
32 #include "StdMeshers_FaceSide.hxx"
34 #include "SMESH_Gen.hxx"
35 #include "SMESH_Mesh.hxx"
36 #include "SMESH_subMesh.hxx"
37 #include "SMESH_MesherHelper.hxx"
38 #include "SMESH_Block.hxx"
39 #include "SMESH_Comment.hxx"
41 #include "SMDS_MeshElement.hxx"
42 #include "SMDS_MeshNode.hxx"
43 #include "SMDS_EdgePosition.hxx"
44 #include "SMDS_FacePosition.hxx"
46 #include <BRepTools.hxx>
47 #include <BRepTools_WireExplorer.hxx>
48 #include <BRep_Tool.hxx>
49 #include <Geom_Surface.hxx>
50 #include <NCollection_DefineArray2.hxx>
51 #include <Precision.hxx>
52 #include <TColStd_SequenceOfReal.hxx>
53 #include <TColgp_SequenceOfXY.hxx>
57 #include "utilities.h"
58 #include "Utils_ExceptHandlers.hxx"
60 #ifndef StdMeshers_Array2OfNode_HeaderFile
61 #define StdMeshers_Array2OfNode_HeaderFile
62 typedef const SMDS_MeshNode* SMDS_MeshNodePtr;
63 DEFINE_BASECOLLECTION (StdMeshers_BaseCollectionNodePtr, SMDS_MeshNodePtr)
64 DEFINE_ARRAY2(StdMeshers_Array2OfNode,
65 StdMeshers_BaseCollectionNodePtr, SMDS_MeshNodePtr)
71 typedef SMESH_Comment TComm;
73 //=============================================================================
77 //=============================================================================
79 StdMeshers_Quadrangle_2D::StdMeshers_Quadrangle_2D (int hypId, int studyId, SMESH_Gen* gen)
80 : SMESH_2D_Algo(hypId, studyId, gen)
82 MESSAGE("StdMeshers_Quadrangle_2D::StdMeshers_Quadrangle_2D");
83 _name = "Quadrangle_2D";
84 _shapeType = (1 << TopAbs_FACE);
85 _compatibleHypothesis.push_back("QuadranglePreference");
86 _compatibleHypothesis.push_back("TrianglePreference");
90 //=============================================================================
94 //=============================================================================
96 StdMeshers_Quadrangle_2D::~StdMeshers_Quadrangle_2D()
98 MESSAGE("StdMeshers_Quadrangle_2D::~StdMeshers_Quadrangle_2D");
101 //=============================================================================
105 //=============================================================================
107 bool StdMeshers_Quadrangle_2D::CheckHypothesis
109 const TopoDS_Shape& aShape,
110 SMESH_Hypothesis::Hypothesis_Status& aStatus)
113 aStatus = SMESH_Hypothesis::HYP_OK;
116 const list <const SMESHDS_Hypothesis * >&hyps = GetUsedHypothesis(aMesh, aShape, false);
117 const SMESHDS_Hypothesis *theHyp = 0;
120 theHyp = *hyps.begin();
121 if(strcmp("QuadranglePreference", theHyp->GetName()) == 0) {
122 myQuadranglePreference= true;
123 myTrianglePreference= false;
125 else if(strcmp("TrianglePreference", theHyp->GetName()) == 0){
126 myQuadranglePreference= false;
127 myTrianglePreference= true;
131 myQuadranglePreference = false;
132 myTrianglePreference = false;
137 //=============================================================================
141 //=============================================================================
143 bool StdMeshers_Quadrangle_2D::Compute (SMESH_Mesh& aMesh,
144 const TopoDS_Shape& aShape)// throw (SALOME_Exception)
146 // PAL14921. Enable catching std::bad_alloc and Standard_OutOfMemory outside
147 //Unexpect aCatchSalomeException);
149 SMESHDS_Mesh * meshDS = aMesh.GetMeshDS();
150 aMesh.GetSubMesh(aShape);
152 SMESH_MesherHelper helper(aMesh);
155 _quadraticMesh = myTool->IsQuadraticSubMesh(aShape);
157 FaceQuadStruct *quad = CheckNbEdges( aMesh, aShape );
158 std::auto_ptr<FaceQuadStruct> quadDeleter( quad ); // to delete quad at exit from Compute()
162 if(myQuadranglePreference) {
163 int n1 = quad->side[0]->NbPoints();
164 int n2 = quad->side[1]->NbPoints();
165 int n3 = quad->side[2]->NbPoints();
166 int n4 = quad->side[3]->NbPoints();
167 int nfull = n1+n2+n3+n4;
170 if( nfull==ntmp && ( (n1!=n3) || (n2!=n4) ) ) {
171 // special path for using only quandrangle faces
172 bool ok = ComputeQuadPref(aMesh, aShape, quad);
177 // set normalized grid on unit square in parametric domain
179 if (!SetNormalizedGrid(aMesh, aShape, quad))
182 // --- compute 3D values on points, store points & quadrangles
184 int nbdown = quad->side[0]->NbPoints();
185 int nbup = quad->side[2]->NbPoints();
187 int nbright = quad->side[1]->NbPoints();
188 int nbleft = quad->side[3]->NbPoints();
190 int nbhoriz = Min(nbdown, nbup);
191 int nbvertic = Min(nbright, nbleft);
193 const TopoDS_Face& F = TopoDS::Face(aShape);
194 Handle(Geom_Surface) S = BRep_Tool::Surface(F);
196 // internal mesh nodes
197 int i, j, geomFaceID = meshDS->ShapeToIndex( F );
198 for (i = 1; i < nbhoriz - 1; i++) {
199 for (j = 1; j < nbvertic - 1; j++) {
200 int ij = j * nbhoriz + i;
201 double u = quad->uv_grid[ij].u;
202 double v = quad->uv_grid[ij].v;
203 gp_Pnt P = S->Value(u, v);
204 SMDS_MeshNode * node = meshDS->AddNode(P.X(), P.Y(), P.Z());
205 meshDS->SetNodeOnFace(node, geomFaceID, u, v);
206 quad->uv_grid[ij].node = node;
213 // --.--.--.--.--.-- nbvertic
219 // ---.----.----.--- 0
220 // 0 > > > > > > > > nbhoriz
226 int iup = nbhoriz - 1;
227 if (quad->isEdgeOut[3]) { ilow++; } else { if (quad->isEdgeOut[1]) iup--; }
230 int jup = nbvertic - 1;
231 if (quad->isEdgeOut[0]) { jlow++; } else { if (quad->isEdgeOut[2]) jup--; }
233 // regular quadrangles
234 for (i = ilow; i < iup; i++) {
235 for (j = jlow; j < jup; j++) {
236 const SMDS_MeshNode *a, *b, *c, *d;
237 a = quad->uv_grid[j * nbhoriz + i].node;
238 b = quad->uv_grid[j * nbhoriz + i + 1].node;
239 c = quad->uv_grid[(j + 1) * nbhoriz + i + 1].node;
240 d = quad->uv_grid[(j + 1) * nbhoriz + i].node;
241 SMDS_MeshFace* face = myTool->AddFace(a, b, c, d);
242 meshDS->SetMeshElementOnShape(face, geomFaceID);
246 const vector<UVPtStruct>& uv_e0 = quad->side[0]->GetUVPtStruct(true,0 );
247 const vector<UVPtStruct>& uv_e1 = quad->side[1]->GetUVPtStruct(false,1);
248 const vector<UVPtStruct>& uv_e2 = quad->side[2]->GetUVPtStruct(true,1 );
249 const vector<UVPtStruct>& uv_e3 = quad->side[3]->GetUVPtStruct(false,0);
251 if ( uv_e0.empty() || uv_e1.empty() || uv_e2.empty() || uv_e3.empty() )
252 return error( COMPERR_BAD_INPUT_MESH );
254 double eps = Precision::Confusion();
256 // Boundary quadrangles
258 if (quad->isEdgeOut[0]) {
261 // |___|___|___|___|___|___|
263 // |___|___|___|___|___|___|
265 // |___|___|___|___|___|___| __ first row of the regular grid
266 // . . . . . . . . . __ down edge nodes
268 // >->->->->->->->->->->->-> -- direction of processing
270 int g = 0; // number of last processed node in the regular grid
272 // number of last node of the down edge to be processed
273 int stop = nbdown - 1;
274 // if right edge is out, we will stop at a node, previous to the last one
275 if (quad->isEdgeOut[1]) stop--;
277 // for each node of the down edge find nearest node
278 // in the first row of the regular grid and link them
279 for (i = 0; i < stop; i++) {
280 const SMDS_MeshNode *a, *b, *c, *d;
282 b = uv_e0[i + 1].node;
283 gp_Pnt pb (b->X(), b->Y(), b->Z());
285 // find node c in the regular grid, which will be linked with node b
288 // right bound reached, link with the rightmost node
290 c = quad->uv_grid[nbhoriz + iup].node;
293 // find in the grid node c, nearest to the b
294 double mind = RealLast();
295 for (int k = g; k <= iup; k++) {
297 const SMDS_MeshNode *nk;
298 if (k < ilow) // this can be, if left edge is out
299 nk = uv_e3[1].node; // get node from the left edge
301 nk = quad->uv_grid[nbhoriz + k].node; // get one of middle nodes
303 gp_Pnt pnk (nk->X(), nk->Y(), nk->Z());
304 double dist = pb.Distance(pnk);
305 if (dist < mind - eps) {
315 if (near == g) { // make triangle
316 //SMDS_MeshFace* face = meshDS->AddFace(a, b, c);
317 SMDS_MeshFace* face = myTool->AddFace(a, b, c);
318 meshDS->SetMeshElementOnShape(face, geomFaceID);
320 else { // make quadrangle
324 d = quad->uv_grid[nbhoriz + near - 1].node;
325 //SMDS_MeshFace* face = meshDS->AddFace(a, b, c, d);
327 if(!myTrianglePreference){
328 SMDS_MeshFace* face = myTool->AddFace(a, b, c, d);
329 meshDS->SetMeshElementOnShape(face, geomFaceID);
332 SplitQuad(meshDS, geomFaceID, a, b, c, d);
335 // if node d is not at position g - make additional triangles
337 for (int k = near - 1; k > g; k--) {
338 c = quad->uv_grid[nbhoriz + k].node;
342 d = quad->uv_grid[nbhoriz + k - 1].node;
343 //SMDS_MeshFace* face = meshDS->AddFace(a, c, d);
344 SMDS_MeshFace* face = myTool->AddFace(a, c, d);
345 meshDS->SetMeshElementOnShape(face, geomFaceID);
352 if (quad->isEdgeOut[2]) {
355 // <-<-<-<-<-<-<-<-<-<-<-<-< -- direction of processing
357 // . . . . . . . . . __ up edge nodes
358 // ___ ___ ___ ___ ___ ___ __ first row of the regular grid
360 // |___|___|___|___|___|___|
362 // |___|___|___|___|___|___|
365 int g = nbhoriz - 1; // last processed node in the regular grid
368 // if left edge is out, we will stop at a second node
369 if (quad->isEdgeOut[3]) stop++;
371 // for each node of the up edge find nearest node
372 // in the first row of the regular grid and link them
373 for (i = nbup - 1; i > stop; i--) {
374 const SMDS_MeshNode *a, *b, *c, *d;
376 b = uv_e2[i - 1].node;
377 gp_Pnt pb (b->X(), b->Y(), b->Z());
379 // find node c in the grid, which will be linked with node b
381 if (i == stop + 1) { // left bound reached, link with the leftmost node
382 c = quad->uv_grid[nbhoriz*(nbvertic - 2) + ilow].node;
385 // find node c in the grid, nearest to the b
386 double mind = RealLast();
387 for (int k = g; k >= ilow; k--) {
388 const SMDS_MeshNode *nk;
390 nk = uv_e1[nbright - 2].node;
392 nk = quad->uv_grid[nbhoriz*(nbvertic - 2) + k].node;
393 gp_Pnt pnk (nk->X(), nk->Y(), nk->Z());
394 double dist = pb.Distance(pnk);
395 if (dist < mind - eps) {
405 if (near == g) { // make triangle
406 //SMDS_MeshFace* face = meshDS->AddFace(a, b, c);
407 SMDS_MeshFace* face = myTool->AddFace(a, b, c);
408 meshDS->SetMeshElementOnShape(face, geomFaceID);
410 else { // make quadrangle
412 d = uv_e1[nbright - 2].node;
414 d = quad->uv_grid[nbhoriz*(nbvertic - 2) + near + 1].node;
415 //SMDS_MeshFace* face = meshDS->AddFace(a, b, c, d);
416 if(!myTrianglePreference){
417 SMDS_MeshFace* face = myTool->AddFace(a, b, c, d);
418 meshDS->SetMeshElementOnShape(face, geomFaceID);
421 SplitQuad(meshDS, geomFaceID, a, b, c, d);
424 if (near + 1 < g) { // if d not is at g - make additional triangles
425 for (int k = near + 1; k < g; k++) {
426 c = quad->uv_grid[nbhoriz*(nbvertic - 2) + k].node;
428 d = uv_e1[nbright - 2].node;
430 d = quad->uv_grid[nbhoriz*(nbvertic - 2) + k + 1].node;
431 //SMDS_MeshFace* face = meshDS->AddFace(a, c, d);
432 SMDS_MeshFace* face = myTool->AddFace(a, c, d);
433 meshDS->SetMeshElementOnShape(face, geomFaceID);
442 // right or left boundary quadrangles
443 if (quad->isEdgeOut[1]) {
444 // MESSAGE("right edge is out");
445 int g = 0; // last processed node in the grid
446 int stop = nbright - 1;
447 if (quad->isEdgeOut[2]) stop--;
448 for (i = 0; i < stop; i++) {
449 const SMDS_MeshNode *a, *b, *c, *d;
451 b = uv_e1[i + 1].node;
452 gp_Pnt pb (b->X(), b->Y(), b->Z());
454 // find node c in the grid, nearest to the b
456 if (i == stop - 1) { // up bondary reached
457 c = quad->uv_grid[nbhoriz*(jup + 1) - 2].node;
460 double mind = RealLast();
461 for (int k = g; k <= jup; k++) {
462 const SMDS_MeshNode *nk;
464 nk = uv_e0[nbdown - 2].node;
466 nk = quad->uv_grid[nbhoriz*(k + 1) - 2].node;
467 gp_Pnt pnk (nk->X(), nk->Y(), nk->Z());
468 double dist = pb.Distance(pnk);
469 if (dist < mind - eps) {
479 if (near == g) { // make triangle
480 //SMDS_MeshFace* face = meshDS->AddFace(a, b, c);
481 SMDS_MeshFace* face = myTool->AddFace(a, b, c);
482 meshDS->SetMeshElementOnShape(face, geomFaceID);
484 else { // make quadrangle
486 d = uv_e0[nbdown - 2].node;
488 d = quad->uv_grid[nbhoriz*near - 2].node;
489 //SMDS_MeshFace* face = meshDS->AddFace(a, b, c, d);
491 if(!myTrianglePreference){
492 SMDS_MeshFace* face = myTool->AddFace(a, b, c, d);
493 meshDS->SetMeshElementOnShape(face, geomFaceID);
496 SplitQuad(meshDS, geomFaceID, a, b, c, d);
499 if (near - 1 > g) { // if d not is at g - make additional triangles
500 for (int k = near - 1; k > g; k--) {
501 c = quad->uv_grid[nbhoriz*(k + 1) - 2].node;
503 d = uv_e0[nbdown - 2].node;
505 d = quad->uv_grid[nbhoriz*k - 2].node;
506 //SMDS_MeshFace* face = meshDS->AddFace(a, c, d);
507 SMDS_MeshFace* face = myTool->AddFace(a, c, d);
508 meshDS->SetMeshElementOnShape(face, geomFaceID);
515 if (quad->isEdgeOut[3]) {
516 // MESSAGE("left edge is out");
517 int g = nbvertic - 1; // last processed node in the grid
519 if (quad->isEdgeOut[0]) stop++;
520 for (i = nbleft - 1; i > stop; i--) {
521 const SMDS_MeshNode *a, *b, *c, *d;
523 b = uv_e3[i - 1].node;
524 gp_Pnt pb (b->X(), b->Y(), b->Z());
526 // find node c in the grid, nearest to the b
528 if (i == stop + 1) { // down bondary reached
529 c = quad->uv_grid[nbhoriz*jlow + 1].node;
532 double mind = RealLast();
533 for (int k = g; k >= jlow; k--) {
534 const SMDS_MeshNode *nk;
538 nk = quad->uv_grid[nbhoriz*k + 1].node;
539 gp_Pnt pnk (nk->X(), nk->Y(), nk->Z());
540 double dist = pb.Distance(pnk);
541 if (dist < mind - eps) {
551 if (near == g) { // make triangle
552 //SMDS_MeshFace* face = meshDS->AddFace(a, b, c);
553 SMDS_MeshFace* face = myTool->AddFace(a, b, c);
554 meshDS->SetMeshElementOnShape(face, geomFaceID);
556 else { // make quadrangle
560 d = quad->uv_grid[nbhoriz*(near + 1) + 1].node;
561 //SMDS_MeshFace* face = meshDS->AddFace(a, b, c, d);
562 if(!myTrianglePreference){
563 SMDS_MeshFace* face = myTool->AddFace(a, b, c, d);
564 meshDS->SetMeshElementOnShape(face, geomFaceID);
567 SplitQuad(meshDS, geomFaceID, a, b, c, d);
570 if (near + 1 < g) { // if d not is at g - make additional triangles
571 for (int k = near + 1; k < g; k++) {
572 c = quad->uv_grid[nbhoriz*k + 1].node;
576 d = quad->uv_grid[nbhoriz*(k + 1) + 1].node;
577 //SMDS_MeshFace* face = meshDS->AddFace(a, c, d);
578 SMDS_MeshFace* face = myTool->AddFace(a, c, d);
579 meshDS->SetMeshElementOnShape(face, geomFaceID);
592 //=============================================================================
596 //=============================================================================
598 FaceQuadStruct* StdMeshers_Quadrangle_2D::CheckNbEdges(SMESH_Mesh & aMesh,
599 const TopoDS_Shape & aShape)
600 //throw(SALOME_Exception)
602 const TopoDS_Face & F = TopoDS::Face(aShape);
603 const bool ignoreMediumNodes = _quadraticMesh;
605 // verify 1 wire only, with 4 edges
607 list< TopoDS_Edge > edges;
608 list< int > nbEdgesInWire;
609 int nbWire = SMESH_Block::GetOrderedEdges (F, V, edges, nbEdgesInWire);
611 error(COMPERR_BAD_SHAPE, TComm("Wrong number of wires: ") << nbWire);
614 FaceQuadStruct* quad = new FaceQuadStruct;
616 quad->side.reserve(nbEdgesInWire.front());
619 list< TopoDS_Edge >::iterator edgeIt = edges.begin();
620 if ( nbEdgesInWire.front() == 4 ) { // exactly 4 edges
621 for ( ; edgeIt != edges.end(); ++edgeIt, nbSides++ )
622 quad->side.push_back( new StdMeshers_FaceSide(F, *edgeIt, &aMesh,
623 nbSides<TOP_SIDE, ignoreMediumNodes));
625 else if ( nbEdgesInWire.front() > 4 ) { // more than 4 edges - try to unite some
626 list< TopoDS_Edge > sideEdges;
627 while ( !edges.empty()) {
629 sideEdges.splice( sideEdges.end(), edges, edges.begin()); // edges.front() -> sideEdges.end()
630 bool sameSide = true;
631 while ( !edges.empty() && sameSide ) {
632 sameSide = SMESH_Algo::IsContinuous( sideEdges.back(), edges.front() );
634 sideEdges.splice( sideEdges.end(), edges, edges.begin());
636 if ( nbSides == 0 ) { // go backward from the first edge
638 while ( !edges.empty() && sameSide ) {
639 sameSide = SMESH_Algo::IsContinuous( sideEdges.front(), edges.back() );
641 sideEdges.splice( sideEdges.begin(), edges, --edges.end());
644 quad->side.push_back( new StdMeshers_FaceSide(F, sideEdges, &aMesh,
645 nbSides<TOP_SIDE, ignoreMediumNodes));
651 MESSAGE ( "StdMeshers_Quadrangle_2D. Edge IDs of " << nbSides << " sides:\n" );
652 for ( int i = 0; i < nbSides; ++i ) {
654 for ( int e = 0; e < quad->side[i]->NbEdges(); ++e )
655 MESSAGE ( myTool->GetMeshDS()->ShapeToIndex( quad->side[i]->Edge( e )) << " " );
661 nbSides = nbEdgesInWire.front();
662 error(COMPERR_BAD_SHAPE, TComm("Face must have 4 sides but not ") << nbSides);
670 //=============================================================================
674 //=============================================================================
676 FaceQuadStruct *StdMeshers_Quadrangle_2D::CheckAnd2Dcompute
678 const TopoDS_Shape & aShape,
679 const bool CreateQuadratic) //throw(SALOME_Exception)
681 _quadraticMesh = CreateQuadratic;
683 FaceQuadStruct *quad = CheckNbEdges(aMesh, aShape);
687 // set normalized grid on unit square in parametric domain
688 bool stat = SetNormalizedGrid(aMesh, aShape, quad);
698 //=============================================================================
702 //=============================================================================
704 faceQuadStruct::~faceQuadStruct()
706 for (int i = 0; i < side.size(); i++) {
707 if (side[i]) delete side[i];
709 if (uv_grid) delete [] uv_grid;
713 inline const vector<UVPtStruct>& GetUVPtStructIn(FaceQuadStruct* quad, int i, int nbSeg)
715 bool isXConst = ( i == BOTTOM_SIDE || i == TOP_SIDE );
716 double constValue = ( i == BOTTOM_SIDE || i == LEFT_SIDE ) ? 0 : 1;
719 quad->side[i]->SimulateUVPtStruct(nbSeg,isXConst,constValue) :
720 quad->side[i]->GetUVPtStruct(isXConst,constValue);
724 //=============================================================================
728 //=============================================================================
730 bool StdMeshers_Quadrangle_2D::SetNormalizedGrid (SMESH_Mesh & aMesh,
731 const TopoDS_Shape& aShape,
732 FaceQuadStruct* & quad) //throw (SALOME_Exception)
734 // Algorithme décrit dans "Génération automatique de maillages"
735 // P.L. GEORGE, MASSON, § 6.4.1 p. 84-85
736 // traitement dans le domaine paramétrique 2d u,v
737 // transport - projection sur le carré unité
739 // MESSAGE("StdMeshers_Quadrangle_2D::SetNormalizedGrid");
740 // const TopoDS_Face& F = TopoDS::Face(aShape);
742 // 1 --- find orientation of the 4 edges, by test on extrema
745 // |<----north-2-------^ a3 -------------> a2
747 // west-3 east-1 =right | |
751 // v----south-0--------> a0 -------------> a1
756 // 3 --- 2D normalized values on unit square [0..1][0..1]
758 int nbhoriz = Min(quad->side[0]->NbPoints(), quad->side[2]->NbPoints());
759 int nbvertic = Min(quad->side[1]->NbPoints(), quad->side[3]->NbPoints());
761 quad->isEdgeOut[0] = (quad->side[0]->NbPoints() > quad->side[2]->NbPoints());
762 quad->isEdgeOut[1] = (quad->side[1]->NbPoints() > quad->side[3]->NbPoints());
763 quad->isEdgeOut[2] = (quad->side[2]->NbPoints() > quad->side[0]->NbPoints());
764 quad->isEdgeOut[3] = (quad->side[3]->NbPoints() > quad->side[1]->NbPoints());
766 UVPtStruct *uv_grid = quad->uv_grid = new UVPtStruct[nbvertic * nbhoriz];
768 const vector<UVPtStruct>& uv_e0 = GetUVPtStructIn( quad, 0, nbhoriz - 1 );
769 const vector<UVPtStruct>& uv_e1 = GetUVPtStructIn( quad, 1, nbvertic - 1 );
770 const vector<UVPtStruct>& uv_e2 = GetUVPtStructIn( quad, 2, nbhoriz - 1 );
771 const vector<UVPtStruct>& uv_e3 = GetUVPtStructIn( quad, 3, nbvertic - 1 );
773 if ( uv_e0.empty() || uv_e1.empty() || uv_e2.empty() || uv_e3.empty() )
774 //return error( "Can't find nodes on sides");
775 return error( COMPERR_BAD_INPUT_MESH );
777 // nodes Id on "in" edges
778 if (! quad->isEdgeOut[0]) {
780 for (int i = 0; i < nbhoriz; i++) { // down
781 int ij = j * nbhoriz + i;
782 uv_grid[ij].node = uv_e0[i].node;
785 if (! quad->isEdgeOut[1]) {
787 for (int j = 0; j < nbvertic; j++) { // right
788 int ij = j * nbhoriz + i;
789 uv_grid[ij].node = uv_e1[j].node;
792 if (! quad->isEdgeOut[2]) {
793 int j = nbvertic - 1;
794 for (int i = 0; i < nbhoriz; i++) { // up
795 int ij = j * nbhoriz + i;
796 uv_grid[ij].node = uv_e2[i].node;
799 if (! quad->isEdgeOut[3]) {
801 for (int j = 0; j < nbvertic; j++) { // left
802 int ij = j * nbhoriz + i;
803 uv_grid[ij].node = uv_e3[j].node;
807 // normalized 2d values on grid
808 for (int i = 0; i < nbhoriz; i++)
810 for (int j = 0; j < nbvertic; j++)
812 int ij = j * nbhoriz + i;
813 // --- droite i cste : x = x0 + y(x1-x0)
814 double x0 = uv_e0[i].normParam; // bas - sud
815 double x1 = uv_e2[i].normParam; // haut - nord
816 // --- droite j cste : y = y0 + x(y1-y0)
817 double y0 = uv_e3[j].normParam; // gauche-ouest
818 double y1 = uv_e1[j].normParam; // droite - est
819 // --- intersection : x=x0+(y0+x(y1-y0))(x1-x0)
820 double x = (x0 + y0 * (x1 - x0)) / (1 - (y1 - y0) * (x1 - x0));
821 double y = y0 + x * (y1 - y0);
824 //MESSAGE("-xy-01 "<<x0<<" "<<x1<<" "<<y0<<" "<<y1);
825 //MESSAGE("-xy-norm "<<i<<" "<<j<<" "<<x<<" "<<y);
829 // 4 --- projection on 2d domain (u,v)
830 gp_UV a0( uv_e0.front().u, uv_e0.front().v );
831 gp_UV a1( uv_e0.back().u, uv_e0.back().v );
832 gp_UV a2( uv_e2.back().u, uv_e2.back().v );
833 gp_UV a3( uv_e2.front().u, uv_e2.front().v );
835 for (int i = 0; i < nbhoriz; i++)
837 for (int j = 0; j < nbvertic; j++)
839 int ij = j * nbhoriz + i;
840 double x = uv_grid[ij].x;
841 double y = uv_grid[ij].y;
842 double param_0 = uv_e0[0].normParam + x * (uv_e0.back().normParam - uv_e0[0].normParam); // sud
843 double param_2 = uv_e2[0].normParam + x * (uv_e2.back().normParam - uv_e2[0].normParam); // nord
844 double param_1 = uv_e1[0].normParam + y * (uv_e1.back().normParam - uv_e1[0].normParam); // est
845 double param_3 = uv_e3[0].normParam + y * (uv_e3.back().normParam - uv_e3[0].normParam); // ouest
847 //MESSAGE("params "<<param_0<<" "<<param_1<<" "<<param_2<<" "<<param_3);
848 gp_UV p0 = quad->side[0]->Value2d(param_0).XY();
849 gp_UV p1 = quad->side[1]->Value2d(param_1).XY();
850 gp_UV p2 = quad->side[2]->Value2d(param_2).XY();
851 gp_UV p3 = quad->side[3]->Value2d(param_3).XY();
853 gp_UV uv = (1 - y) * p0 + x * p1 + y * p2 + (1 - x) * p3;
854 uv -= (1 - x) * (1 - y) * a0 + x * (1 - y) * a1 + x * y * a2 + (1 - x) * y * a3;
856 uv_grid[ij].u = uv.X();
857 uv_grid[ij].v = uv.Y();
863 //=======================================================================
864 //function : ShiftQuad
865 //purpose : auxilary function for ComputeQuadPref
866 //=======================================================================
868 static void ShiftQuad(FaceQuadStruct* quad, const int num, bool)
870 StdMeshers_FaceSide* side[4] = { quad->side[0], quad->side[1], quad->side[2], quad->side[3] };
871 for (int i = BOTTOM_SIDE; i < NB_SIDES; ++i ) {
872 int id = ( i + num ) % NB_SIDES;
873 bool wasForward = ( i < TOP_SIDE );
874 bool newForward = ( id < TOP_SIDE );
875 if ( wasForward != newForward )
876 side[ i ]->Reverse();
877 quad->side[ id ] = side[ i ];
881 //=======================================================================
883 //purpose : auxilary function for ComputeQuadPref
884 //=======================================================================
886 static gp_UV CalcUV(double x0, double x1, double y0, double y1,
887 FaceQuadStruct* quad,
888 const gp_UV& a0, const gp_UV& a1,
889 const gp_UV& a2, const gp_UV& a3)
891 const vector<UVPtStruct>& uv_eb = quad->side[0]->GetUVPtStruct(true,0 );
892 const vector<UVPtStruct>& uv_er = quad->side[1]->GetUVPtStruct(false,1);
893 const vector<UVPtStruct>& uv_et = quad->side[2]->GetUVPtStruct(true,1 );
894 const vector<UVPtStruct>& uv_el = quad->side[3]->GetUVPtStruct(false,0);
896 double x = (x0 + y0 * (x1 - x0)) / (1 - (y1 - y0) * (x1 - x0));
897 double y = y0 + x * (y1 - y0);
899 double param_b = uv_eb[0].normParam + x * (uv_eb.back().normParam - uv_eb[0].normParam);
900 double param_t = uv_et[0].normParam + x * (uv_et.back().normParam - uv_et[0].normParam);
901 double param_r = uv_er[0].normParam + y * (uv_er.back().normParam - uv_er[0].normParam);
902 double param_l = uv_el[0].normParam + y * (uv_el.back().normParam - uv_el[0].normParam);
904 gp_UV p0 = quad->side[BOTTOM_SIDE]->Value2d(param_b).XY();
905 gp_UV p1 = quad->side[RIGHT_SIDE ]->Value2d(param_r).XY();
906 gp_UV p2 = quad->side[TOP_SIDE ]->Value2d(param_t).XY();
907 gp_UV p3 = quad->side[LEFT_SIDE ]->Value2d(param_l).XY();
909 gp_UV uv = p0 * (1 - y) + p1 * x + p2 * y + p3 * (1 - x);
911 uv -= (1 - x) * (1 - y) * a0 + x * (1 - y) * a1 + x * y * a2 + (1 - x) * y * a3;
917 //=======================================================================
919 //purpose : auxilary function for ComputeQuadPref
920 //=======================================================================
922 static gp_UV CalcUV2(double x, double y,
923 FaceQuadStruct* quad,
924 const gp_UV& a0, const gp_UV& a1,
925 const gp_UV& a2, const gp_UV& a3)
927 const vector<UVPtStruct>& uv_eb = quad->side[0]->GetUVPtStruct(true,0 );
928 const vector<UVPtStruct>& uv_er = quad->side[1]->GetUVPtStruct(false,1);
929 const vector<UVPtStruct>& uv_et = quad->side[2]->GetUVPtStruct(true,1 );
930 const vector<UVPtStruct>& uv_el = quad->side[3]->GetUVPtStruct(false,0);
932 //double x = (x0 + y0 * (x1 - x0)) / (1 - (y1 - y0) * (x1 - x0));
933 //double y = y0 + x * (y1 - y0);
935 double param_b = uv_eb[0].normParam + x * (uv_eb.back().normParam - uv_eb[0].normParam);
936 double param_t = uv_et[0].normParam + x * (uv_et.back().normParam - uv_et[0].normParam);
937 double param_r = uv_er[0].normParam + y * (uv_er.back().normParam - uv_er[0].normParam);
938 double param_l = uv_el[0].normParam + y * (uv_el.back().normParam - uv_el[0].normParam);
940 gp_UV p0 = quad->side[BOTTOM_SIDE]->Value2d(param_b).XY();
941 gp_UV p1 = quad->side[RIGHT_SIDE ]->Value2d(param_r).XY();
942 gp_UV p2 = quad->side[TOP_SIDE ]->Value2d(param_t).XY();
943 gp_UV p3 = quad->side[LEFT_SIDE ]->Value2d(param_l).XY();
945 gp_UV uv = p0 * (1 - y) + p1 * x + p2 * y + p3 * (1 - x);
947 uv -= (1 - x) * (1 - y) * a0 + x * (1 - y) * a1 + x * y * a2 + (1 - x) * y * a3;
952 //=======================================================================
954 * Create only quandrangle faces
956 //=======================================================================
958 bool StdMeshers_Quadrangle_2D::ComputeQuadPref (SMESH_Mesh & aMesh,
959 const TopoDS_Shape& aShape,
960 FaceQuadStruct* quad)
962 // Auxilary key in order to keep old variant
963 // of meshing after implementation new variant
964 // for bug 0016220 from Mantis.
965 bool OldVersion = false;
967 SMESHDS_Mesh * meshDS = aMesh.GetMeshDS();
968 const TopoDS_Face& F = TopoDS::Face(aShape);
969 Handle(Geom_Surface) S = BRep_Tool::Surface(F);
970 // const TopoDS_Wire& W = BRepTools::OuterWire(F);
972 // if(W.Orientation()==TopAbs_FORWARD)
974 //if(WisF) cout<<"W is FORWARD"<<endl;
975 //else cout<<"W is REVERSED"<<endl;
976 // bool FisF = (F.Orientation()==TopAbs_FORWARD);
977 // if(!FisF) WisF = !WisF;
979 int i,j,geomFaceID = meshDS->ShapeToIndex( F );
981 int nb = quad->side[0]->NbPoints();
982 int nr = quad->side[1]->NbPoints();
983 int nt = quad->side[2]->NbPoints();
984 int nl = quad->side[3]->NbPoints();
990 // it is a base case => not shift quad but me be replacement is need
991 ShiftQuad(quad,0,WisF);
994 // we have to shift quad on 2
995 ShiftQuad(quad,2,WisF);
1000 // we have to shift quad on 1
1001 ShiftQuad(quad,1,WisF);
1004 // we have to shift quad on 3
1005 ShiftQuad(quad,3,WisF);
1009 nb = quad->side[0]->NbPoints();
1010 nr = quad->side[1]->NbPoints();
1011 nt = quad->side[2]->NbPoints();
1012 nl = quad->side[3]->NbPoints();
1015 int nbh = Max(nb,nt);
1016 int nbv = Max(nr,nl);
1020 // ----------- Old version ---------------
1021 // orientation of face and 3 main domain for future faces
1027 // left | | | | rigth
1034 // ----------- New version ---------------
1035 // orientation of face and 3 main domain for future faces
1041 // left |/________\| rigth
1057 const vector<UVPtStruct>& uv_eb = quad->side[0]->GetUVPtStruct(true,0 );
1058 const vector<UVPtStruct>& uv_er = quad->side[1]->GetUVPtStruct(false,1);
1059 const vector<UVPtStruct>& uv_et = quad->side[2]->GetUVPtStruct(true,1 );
1060 const vector<UVPtStruct>& uv_el = quad->side[3]->GetUVPtStruct(false,0);
1062 // arrays for normalized params
1063 //cout<<"Dump B:"<<endl;
1064 TColStd_SequenceOfReal npb, npr, npt, npl;
1065 for(i=0; i<nb; i++) {
1066 npb.Append(uv_eb[i].normParam);
1067 //cout<<"i="<<i<<" par="<<uv_eb[i].normParam<<" npar="<<uv_eb[i].normParam;
1068 //const SMDS_MeshNode* N = uv_eb[i].node;
1069 //cout<<" node("<<N->X()<<","<<N->Y()<<","<<N->Z()<<")"<<endl;
1071 for(i=0; i<nr; i++) {
1072 npr.Append(uv_er[i].normParam);
1074 for(i=0; i<nt; i++) {
1075 npt.Append(uv_et[i].normParam);
1077 for(i=0; i<nl; i++) {
1078 npl.Append(uv_el[i].normParam);
1083 // add some params to right and left after the first param
1086 double dpr = (npr.Value(2) - npr.Value(1))/(dr+1);
1087 for(i=1; i<=dr; i++) {
1088 npr.InsertAfter(1,npr.Value(2)-dpr);
1092 dpr = (npl.Value(2) - npl.Value(1))/(dl+1);
1093 for(i=1; i<=dl; i++) {
1094 npl.InsertAfter(1,npl.Value(2)-dpr);
1098 //for(i=1; i<=npb.Length(); i++) {
1099 // cout<<" "<<npb.Value(i);
1103 gp_XY a0( uv_eb.front().u, uv_eb.front().v );
1104 gp_XY a1( uv_eb.back().u, uv_eb.back().v );
1105 gp_XY a2( uv_et.back().u, uv_et.back().v );
1106 gp_XY a3( uv_et.front().u, uv_et.front().v );
1107 //cout<<" a0("<<a0.X()<<","<<a0.Y()<<")"<<" a1("<<a1.X()<<","<<a1.Y()<<")"
1108 // <<" a2("<<a2.X()<<","<<a2.Y()<<")"<<" a3("<<a3.X()<<","<<a3.Y()<<")"<<endl;
1110 int nnn = Min(nr,nl);
1111 // auxilary sequence of XY for creation nodes
1112 // in the bottom part of central domain
1113 // it's length must be == nbv-nnn-1
1114 TColgp_SequenceOfXY UVL;
1115 TColgp_SequenceOfXY UVR;
1118 // step1: create faces for left domain
1119 StdMeshers_Array2OfNode NodesL(1,dl+1,1,nl);
1121 for(j=1; j<=nl; j++)
1122 NodesL.SetValue(1,j,uv_el[j-1].node);
1125 for(i=1; i<=dl; i++)
1126 NodesL.SetValue(i+1,nl,uv_et[i].node);
1127 // create and add needed nodes
1128 TColgp_SequenceOfXY UVtmp;
1129 for(i=1; i<=dl; i++) {
1130 double x0 = npt.Value(i+1);
1133 double y0 = npl.Value(i+1);
1134 double y1 = npr.Value(i+1);
1135 gp_UV UV = CalcUV(x0, x1, y0, y1, quad, a0, a1, a2, a3);
1136 gp_Pnt P = S->Value(UV.X(),UV.Y());
1137 SMDS_MeshNode * N = meshDS->AddNode(P.X(), P.Y(), P.Z());
1138 meshDS->SetNodeOnFace(N, geomFaceID, UV.X(), UV.Y());
1139 NodesL.SetValue(i+1,1,N);
1140 if(UVL.Length()<nbv-nnn-1) UVL.Append(UV);
1142 for(j=2; j<nl; j++) {
1143 double y0 = npl.Value(dl+j);
1144 double y1 = npr.Value(dl+j);
1145 gp_UV UV = CalcUV(x0, x1, y0, y1, quad, a0, a1, a2, a3);
1146 gp_Pnt P = S->Value(UV.X(),UV.Y());
1147 SMDS_MeshNode* N = meshDS->AddNode(P.X(), P.Y(), P.Z());
1148 meshDS->SetNodeOnFace(N, geomFaceID, UV.X(), UV.Y());
1149 NodesL.SetValue(i+1,j,N);
1150 if( i==dl ) UVtmp.Append(UV);
1153 for(i=1; i<=UVtmp.Length() && UVL.Length()<nbv-nnn-1; i++) {
1154 UVL.Append(UVtmp.Value(i));
1156 //cout<<"Dump NodesL:"<<endl;
1157 //for(i=1; i<=dl+1; i++) {
1159 // for(j=1; j<=nl; j++) {
1160 // cout<<" ("<<NodesL.Value(i,j)->X()<<","<<NodesL.Value(i,j)->Y()<<","<<NodesL.Value(i,j)->Z()<<")";
1165 for(i=1; i<=dl; i++) {
1166 for(j=1; j<nl; j++) {
1169 myTool->AddFace(NodesL.Value(i,j), NodesL.Value(i+1,j),
1170 NodesL.Value(i+1,j+1), NodesL.Value(i,j+1));
1171 meshDS->SetMeshElementOnShape(F, geomFaceID);
1175 myTool->AddFace(NodesL.Value(i,j), NodesL.Value(i,j+1),
1176 NodesL.Value(i+1,j+1), NodesL.Value(i+1,j));
1177 meshDS->SetMeshElementOnShape(F, geomFaceID);
1183 // fill UVL using c2d
1184 for(i=1; i<npl.Length() && UVL.Length()<nbv-nnn-1; i++) {
1185 UVL.Append( gp_UV ( uv_el[i].u, uv_el[i].v ));
1189 // step2: create faces for right domain
1190 StdMeshers_Array2OfNode NodesR(1,dr+1,1,nr);
1192 for(j=1; j<=nr; j++)
1193 NodesR.SetValue(1,j,uv_er[nr-j].node);
1196 for(i=1; i<=dr; i++)
1197 NodesR.SetValue(i+1,1,uv_et[nt-1-i].node);
1198 // create and add needed nodes
1199 TColgp_SequenceOfXY UVtmp;
1200 for(i=1; i<=dr; i++) {
1201 double x0 = npt.Value(nt-i);
1204 double y0 = npl.Value(i+1);
1205 double y1 = npr.Value(i+1);
1206 gp_UV UV = CalcUV(x0, x1, y0, y1, quad, a0, a1, a2, a3);
1207 gp_Pnt P = S->Value(UV.X(),UV.Y());
1208 SMDS_MeshNode * N = meshDS->AddNode(P.X(), P.Y(), P.Z());
1209 meshDS->SetNodeOnFace(N, geomFaceID, UV.X(), UV.Y());
1210 NodesR.SetValue(i+1,nr,N);
1211 if(UVR.Length()<nbv-nnn-1) UVR.Append(UV);
1213 for(j=2; j<nr; j++) {
1214 double y0 = npl.Value(nbv-j+1);
1215 double y1 = npr.Value(nbv-j+1);
1216 gp_UV UV = CalcUV(x0, x1, y0, y1, quad, a0, a1, a2, a3);
1217 gp_Pnt P = S->Value(UV.X(),UV.Y());
1218 SMDS_MeshNode* N = meshDS->AddNode(P.X(), P.Y(), P.Z());
1219 meshDS->SetNodeOnFace(N, geomFaceID, UV.X(), UV.Y());
1220 NodesR.SetValue(i+1,j,N);
1221 if( i==dr ) UVtmp.Prepend(UV);
1224 for(i=1; i<=UVtmp.Length() && UVR.Length()<nbv-nnn-1; i++) {
1225 UVR.Append(UVtmp.Value(i));
1228 for(i=1; i<=dr; i++) {
1229 for(j=1; j<nr; j++) {
1232 myTool->AddFace(NodesR.Value(i,j), NodesR.Value(i+1,j),
1233 NodesR.Value(i+1,j+1), NodesR.Value(i,j+1));
1234 meshDS->SetMeshElementOnShape(F, geomFaceID);
1238 myTool->AddFace(NodesR.Value(i,j), NodesR.Value(i,j+1),
1239 NodesR.Value(i+1,j+1), NodesR.Value(i+1,j));
1240 meshDS->SetMeshElementOnShape(F, geomFaceID);
1246 // fill UVR using c2d
1247 for(i=1; i<npr.Length() && UVR.Length()<nbv-nnn-1; i++) {
1248 UVR.Append( gp_UV( uv_er[i].u, uv_er[i].v ));
1252 // step3: create faces for central domain
1253 StdMeshers_Array2OfNode NodesC(1,nb,1,nbv);
1254 // add first string using NodesL
1255 for(i=1; i<=dl+1; i++)
1256 NodesC.SetValue(1,i,NodesL(i,1));
1257 for(i=2; i<=nl; i++)
1258 NodesC.SetValue(1,dl+i,NodesL(dl+1,i));
1259 // add last string using NodesR
1260 for(i=1; i<=dr+1; i++)
1261 NodesC.SetValue(nb,i,NodesR(i,nr));
1263 NodesC.SetValue(nb,dr+i+1,NodesR(dr+1,nr-i));
1264 // add top nodes (last columns)
1265 for(i=dl+2; i<nbh-dr; i++)
1266 NodesC.SetValue(i-dl,nbv,uv_et[i-1].node);
1267 // add bottom nodes (first columns)
1269 NodesC.SetValue(i,1,uv_eb[i-1].node);
1271 // create and add needed nodes
1272 // add linear layers
1273 for(i=2; i<nb; i++) {
1274 double x0 = npt.Value(dl+i);
1276 for(j=1; j<nnn; j++) {
1277 double y0 = npl.Value(nbv-nnn+j);
1278 double y1 = npr.Value(nbv-nnn+j);
1279 gp_UV UV = CalcUV(x0, x1, y0, y1, quad, a0, a1, a2, a3);
1280 gp_Pnt P = S->Value(UV.X(),UV.Y());
1281 SMDS_MeshNode* N = meshDS->AddNode(P.X(), P.Y(), P.Z());
1282 meshDS->SetNodeOnFace(N, geomFaceID, UV.X(), UV.Y());
1283 NodesC.SetValue(i,nbv-nnn+j,N);
1286 // add diagonal layers
1287 //cout<<"UVL.Length()="<<UVL.Length()<<" UVR.Length()="<<UVR.Length()<<endl;
1288 //cout<<"Dump UVL:"<<endl;
1289 //for(i=1; i<=UVL.Length(); i++) {
1290 // cout<<" ("<<UVL.Value(i).X()<<","<<UVL.Value(i).Y()<<")";
1293 for(i=1; i<nbv-nnn; i++) {
1294 double du = UVR.Value(i).X() - UVL.Value(i).X();
1295 double dv = UVR.Value(i).Y() - UVL.Value(i).Y();
1296 for(j=2; j<nb; j++) {
1297 double u = UVL.Value(i).X() + du*npb.Value(j);
1298 double v = UVL.Value(i).Y() + dv*npb.Value(j);
1299 gp_Pnt P = S->Value(u,v);
1300 SMDS_MeshNode* N = meshDS->AddNode(P.X(), P.Y(), P.Z());
1301 meshDS->SetNodeOnFace(N, geomFaceID, u, v);
1302 NodesC.SetValue(j,i+1,N);
1306 for(i=1; i<nb; i++) {
1307 for(j=1; j<nbv; j++) {
1310 myTool->AddFace(NodesC.Value(i,j), NodesC.Value(i+1,j),
1311 NodesC.Value(i+1,j+1), NodesC.Value(i,j+1));
1312 meshDS->SetMeshElementOnShape(F, geomFaceID);
1316 myTool->AddFace(NodesC.Value(i,j), NodesC.Value(i,j+1),
1317 NodesC.Value(i+1,j+1), NodesC.Value(i+1,j));
1318 meshDS->SetMeshElementOnShape(F, geomFaceID);
1324 else { // New version (!OldVersion)
1325 // step1: create faces for bottom rectangle domain
1326 StdMeshers_Array2OfNode NodesBRD(1,nb,1,nnn-1);
1327 // fill UVL and UVR using c2d
1328 for(j=0; j<nb; j++) {
1329 NodesBRD.SetValue(j+1,1,uv_eb[j].node);
1331 for(i=1; i<nnn-1; i++) {
1332 NodesBRD.SetValue(1,i+1,uv_el[i].node);
1333 NodesBRD.SetValue(nb,i+1,uv_er[i].node);
1334 double du = uv_er[i].u - uv_el[i].u;
1335 double dv = uv_er[i].v - uv_el[i].v;
1336 for(j=2; j<nb; j++) {
1337 double u = uv_el[i].u + du*npb.Value(j);
1338 double v = uv_el[i].v + dv*npb.Value(j);
1339 gp_Pnt P = S->Value(u,v);
1340 SMDS_MeshNode* N = meshDS->AddNode(P.X(), P.Y(), P.Z());
1341 meshDS->SetNodeOnFace(N, geomFaceID, u, v);
1342 NodesBRD.SetValue(j,i+1,N);
1346 for(j=1; j<nnn-1; j++) {
1347 for(i=1; i<nb; i++) {
1350 myTool->AddFace(NodesBRD.Value(i,j), NodesBRD.Value(i+1,j),
1351 NodesBRD.Value(i+1,j+1), NodesBRD.Value(i,j+1));
1352 meshDS->SetMeshElementOnShape(F, geomFaceID);
1356 myTool->AddFace(NodesBRD.Value(i,j), NodesBRD.Value(i,j+1),
1357 NodesBRD.Value(i+1,j+1), NodesBRD.Value(i+1,j));
1358 meshDS->SetMeshElementOnShape(F, geomFaceID);
1363 int drl = abs(nr-nl);
1364 // create faces for region C
1365 StdMeshers_Array2OfNode NodesC(1,nb,1,drl+1+addv);
1366 // add nodes from previous region
1367 for(j=1; j<=nb; j++) {
1368 NodesC.SetValue(j,1,NodesBRD.Value(j,nnn-1));
1370 if( (drl+addv) > 0 ) {
1375 TColgp_SequenceOfXY UVtmp;
1376 double drparam = npr.Value(nr) - npr.Value(nnn-1);
1377 double dlparam = npl.Value(nnn) - npl.Value(nnn-1);
1379 for(i=1; i<=drl; i++) {
1380 // add existed nodes from right edge
1381 NodesC.SetValue(nb,i+1,uv_er[nnn+i-2].node);
1382 //double dtparam = npt.Value(i+1);
1383 y1 = npr.Value(nnn+i-1); // param on right edge
1384 double dpar = (y1 - npr.Value(nnn-1))/drparam;
1385 y0 = npl.Value(nnn-1) + dpar*dlparam; // param on left edge
1386 double dy = y1 - y0;
1387 for(j=1; j<nb; j++) {
1388 double x = npt.Value(i+1) + npb.Value(j)*(1-npt.Value(i+1));
1389 double y = y0 + dy*x;
1390 gp_UV UV = CalcUV2(x, y, quad, a0, a1, a2, a3);
1391 gp_Pnt P = S->Value(UV.X(),UV.Y());
1392 SMDS_MeshNode* N = meshDS->AddNode(P.X(), P.Y(), P.Z());
1393 meshDS->SetNodeOnFace(N, geomFaceID, UV.X(), UV.Y());
1394 NodesC.SetValue(j,i+1,N);
1397 double dy0 = (1-y0)/(addv+1);
1398 double dy1 = (1-y1)/(addv+1);
1399 for(i=1; i<=addv; i++) {
1400 double yy0 = y0 + dy0*i;
1401 double yy1 = y1 + dy1*i;
1402 double dyy = yy1 - yy0;
1403 for(j=1; j<=nb; j++) {
1404 double x = npt.Value(i+1+drl) +
1405 npb.Value(j) * ( npt.Value(nt-i) - npt.Value(i+1+drl) );
1406 double y = yy0 + dyy*x;
1407 gp_UV UV = CalcUV2(x, y, quad, a0, a1, a2, a3);
1408 gp_Pnt P = S->Value(UV.X(),UV.Y());
1409 SMDS_MeshNode* N = meshDS->AddNode(P.X(), P.Y(), P.Z());
1410 meshDS->SetNodeOnFace(N, geomFaceID, UV.X(), UV.Y());
1411 NodesC.SetValue(j,i+drl+1,N);
1418 TColgp_SequenceOfXY UVtmp;
1419 double dlparam = npl.Value(nl) - npl.Value(nnn-1);
1420 double drparam = npr.Value(nnn) - npr.Value(nnn-1);
1421 double y0 = npl.Value(nnn-1);
1422 double y1 = npr.Value(nnn-1);
1423 for(i=1; i<=drl; i++) {
1424 // add existed nodes from right edge
1425 NodesC.SetValue(1,i+1,uv_el[nnn+i-2].node);
1426 y0 = npl.Value(nnn+i-1); // param on left edge
1427 double dpar = (y0 - npl.Value(nnn-1))/dlparam;
1428 y1 = npr.Value(nnn-1) + dpar*drparam; // param on right edge
1429 double dy = y1 - y0;
1430 for(j=2; j<=nb; j++) {
1431 double x = npb.Value(j)*npt.Value(nt-i);
1432 double y = y0 + dy*x;
1433 gp_UV UV = CalcUV2(x, y, quad, a0, a1, a2, a3);
1434 gp_Pnt P = S->Value(UV.X(),UV.Y());
1435 SMDS_MeshNode* N = meshDS->AddNode(P.X(), P.Y(), P.Z());
1436 meshDS->SetNodeOnFace(N, geomFaceID, UV.X(), UV.Y());
1437 NodesC.SetValue(j,i+1,N);
1440 double dy0 = (1-y0)/(addv+1);
1441 double dy1 = (1-y1)/(addv+1);
1442 for(i=1; i<=addv; i++) {
1443 double yy0 = y0 + dy0*i;
1444 double yy1 = y1 + dy1*i;
1445 double dyy = yy1 - yy0;
1446 for(j=1; j<=nb; j++) {
1447 double x = npt.Value(i+1) +
1448 npb.Value(j) * ( npt.Value(nt-i-drl) - npt.Value(i+1) );
1449 double y = yy0 + dyy*x;
1450 gp_UV UV = CalcUV2(x, y, quad, a0, a1, a2, a3);
1451 gp_Pnt P = S->Value(UV.X(),UV.Y());
1452 SMDS_MeshNode* N = meshDS->AddNode(P.X(), P.Y(), P.Z());
1453 meshDS->SetNodeOnFace(N, geomFaceID, UV.X(), UV.Y());
1454 NodesC.SetValue(j,i+drl+1,N);
1459 for(j=1; j<=drl+addv; j++) {
1460 for(i=1; i<nb; i++) {
1463 myTool->AddFace(NodesC.Value(i,j), NodesC.Value(i+1,j),
1464 NodesC.Value(i+1,j+1), NodesC.Value(i,j+1));
1465 meshDS->SetMeshElementOnShape(F, geomFaceID);
1469 myTool->AddFace(NodesC.Value(i,j), NodesC.Value(i,j+1),
1470 NodesC.Value(i+1,j+1), NodesC.Value(i+1,j));
1471 meshDS->SetMeshElementOnShape(F, geomFaceID);
1476 StdMeshers_Array2OfNode NodesLast(1,nt,1,2);
1477 for(i=1; i<=nt; i++) {
1478 NodesLast.SetValue(i,2,uv_et[i-1].node);
1481 for(i=n1; i<drl+addv+1; i++) {
1483 NodesLast.SetValue(nnn,1,NodesC.Value(1,i));
1485 for(i=1; i<=nb; i++) {
1487 NodesLast.SetValue(nnn,1,NodesC.Value(i,drl+addv+1));
1489 for(i=drl+addv; i>=n2; i--) {
1491 NodesLast.SetValue(nnn,1,NodesC.Value(nb,i));
1493 for(i=1; i<nt; i++) {
1496 myTool->AddFace(NodesLast.Value(i,1), NodesLast.Value(i+1,1),
1497 NodesLast.Value(i+1,2), NodesLast.Value(i,2));
1498 meshDS->SetMeshElementOnShape(F, geomFaceID);
1502 myTool->AddFace(NodesLast.Value(i,1), NodesLast.Value(i,2),
1503 NodesLast.Value(i+1,2), NodesLast.Value(i+1,2));
1504 meshDS->SetMeshElementOnShape(F, geomFaceID);
1507 } // if( (drl+addv) > 0 )
1509 } // end new version implementation
1515 //=============================================================================
1516 /*! Split quadrangle in to 2 triangles by smallest diagonal
1519 //=============================================================================
1520 void StdMeshers_Quadrangle_2D::SplitQuad(SMESHDS_Mesh *theMeshDS,
1522 const SMDS_MeshNode* theNode1,
1523 const SMDS_MeshNode* theNode2,
1524 const SMDS_MeshNode* theNode3,
1525 const SMDS_MeshNode* theNode4)
1527 gp_Pnt a(theNode1->X(),theNode1->Y(),theNode1->Z());
1528 gp_Pnt b(theNode2->X(),theNode2->Y(),theNode2->Z());
1529 gp_Pnt c(theNode3->X(),theNode3->Y(),theNode3->Z());
1530 gp_Pnt d(theNode4->X(),theNode4->Y(),theNode4->Z());
1531 SMDS_MeshFace* face;
1532 if(a.Distance(c) > b.Distance(d)){
1533 face = myTool->AddFace(theNode2, theNode4, theNode1);
1534 theMeshDS->SetMeshElementOnShape(face, theFaceID );
1535 face = myTool->AddFace(theNode2, theNode3, theNode4);
1536 theMeshDS->SetMeshElementOnShape(face, theFaceID );
1540 face = myTool->AddFace(theNode1, theNode2 ,theNode3);
1541 theMeshDS->SetMeshElementOnShape(face, theFaceID );
1542 face = myTool->AddFace(theNode1, theNode3, theNode4);
1543 theMeshDS->SetMeshElementOnShape(face, theFaceID );