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 SMDS_MeshFace* face = myTool->AddFace(a, b, c);
333 meshDS->SetMeshElementOnShape(face, geomFaceID);
334 face = myTool->AddFace(a, c, d);
335 meshDS->SetMeshElementOnShape(face, geomFaceID);
338 // if node d is not at position g - make additional triangles
340 for (int k = near - 1; k > g; k--) {
341 c = quad->uv_grid[nbhoriz + k].node;
345 d = quad->uv_grid[nbhoriz + k - 1].node;
346 //SMDS_MeshFace* face = meshDS->AddFace(a, c, d);
347 SMDS_MeshFace* face = myTool->AddFace(a, c, d);
348 meshDS->SetMeshElementOnShape(face, geomFaceID);
355 if (quad->isEdgeOut[2]) {
358 // <-<-<-<-<-<-<-<-<-<-<-<-< -- direction of processing
360 // . . . . . . . . . __ up edge nodes
361 // ___ ___ ___ ___ ___ ___ __ first row of the regular grid
363 // |___|___|___|___|___|___|
365 // |___|___|___|___|___|___|
368 int g = nbhoriz - 1; // last processed node in the regular grid
371 // if left edge is out, we will stop at a second node
372 if (quad->isEdgeOut[3]) stop++;
374 // for each node of the up edge find nearest node
375 // in the first row of the regular grid and link them
376 for (i = nbup - 1; i > stop; i--) {
377 const SMDS_MeshNode *a, *b, *c, *d;
379 b = uv_e2[i - 1].node;
380 gp_Pnt pb (b->X(), b->Y(), b->Z());
382 // find node c in the grid, which will be linked with node b
384 if (i == stop + 1) { // left bound reached, link with the leftmost node
385 c = quad->uv_grid[nbhoriz*(nbvertic - 2) + ilow].node;
388 // find node c in the grid, nearest to the b
389 double mind = RealLast();
390 for (int k = g; k >= ilow; k--) {
391 const SMDS_MeshNode *nk;
393 nk = uv_e1[nbright - 2].node;
395 nk = quad->uv_grid[nbhoriz*(nbvertic - 2) + k].node;
396 gp_Pnt pnk (nk->X(), nk->Y(), nk->Z());
397 double dist = pb.Distance(pnk);
398 if (dist < mind - eps) {
408 if (near == g) { // make triangle
409 //SMDS_MeshFace* face = meshDS->AddFace(a, b, c);
410 SMDS_MeshFace* face = myTool->AddFace(a, b, c);
411 meshDS->SetMeshElementOnShape(face, geomFaceID);
413 else { // make quadrangle
415 d = uv_e1[nbright - 2].node;
417 d = quad->uv_grid[nbhoriz*(nbvertic - 2) + near + 1].node;
418 //SMDS_MeshFace* face = meshDS->AddFace(a, b, c, d);
419 if(!myTrianglePreference){
420 SMDS_MeshFace* face = myTool->AddFace(a, b, c, d);
421 meshDS->SetMeshElementOnShape(face, geomFaceID);
424 SMDS_MeshFace* face = myTool->AddFace(a, b, c);
425 meshDS->SetMeshElementOnShape(face, geomFaceID);
426 face = myTool->AddFace(a, c, d);
427 meshDS->SetMeshElementOnShape(face, geomFaceID);
430 if (near + 1 < g) { // if d not is at g - make additional triangles
431 for (int k = near + 1; k < g; k++) {
432 c = quad->uv_grid[nbhoriz*(nbvertic - 2) + k].node;
434 d = uv_e1[nbright - 2].node;
436 d = quad->uv_grid[nbhoriz*(nbvertic - 2) + k + 1].node;
437 //SMDS_MeshFace* face = meshDS->AddFace(a, c, d);
438 SMDS_MeshFace* face = myTool->AddFace(a, c, d);
439 meshDS->SetMeshElementOnShape(face, geomFaceID);
448 // right or left boundary quadrangles
449 if (quad->isEdgeOut[1]) {
450 // MESSAGE("right edge is out");
451 int g = 0; // last processed node in the grid
452 int stop = nbright - 1;
453 if (quad->isEdgeOut[2]) stop--;
454 for (i = 0; i < stop; i++) {
455 const SMDS_MeshNode *a, *b, *c, *d;
457 b = uv_e1[i + 1].node;
458 gp_Pnt pb (b->X(), b->Y(), b->Z());
460 // find node c in the grid, nearest to the b
462 if (i == stop - 1) { // up bondary reached
463 c = quad->uv_grid[nbhoriz*(jup + 1) - 2].node;
466 double mind = RealLast();
467 for (int k = g; k <= jup; k++) {
468 const SMDS_MeshNode *nk;
470 nk = uv_e0[nbdown - 2].node;
472 nk = quad->uv_grid[nbhoriz*(k + 1) - 2].node;
473 gp_Pnt pnk (nk->X(), nk->Y(), nk->Z());
474 double dist = pb.Distance(pnk);
475 if (dist < mind - eps) {
485 if (near == g) { // make triangle
486 //SMDS_MeshFace* face = meshDS->AddFace(a, b, c);
487 SMDS_MeshFace* face = myTool->AddFace(a, b, c);
488 meshDS->SetMeshElementOnShape(face, geomFaceID);
490 else { // make quadrangle
492 d = uv_e0[nbdown - 2].node;
494 d = quad->uv_grid[nbhoriz*near - 2].node;
495 //SMDS_MeshFace* face = meshDS->AddFace(a, b, c, d);
497 if(!myTrianglePreference){
498 SMDS_MeshFace* face = myTool->AddFace(a, b, c, d);
499 meshDS->SetMeshElementOnShape(face, geomFaceID);
502 SMDS_MeshFace* face = myTool->AddFace(a, b, c);
503 meshDS->SetMeshElementOnShape(face, geomFaceID);
504 face = myTool->AddFace(a, c, d);
505 meshDS->SetMeshElementOnShape(face, geomFaceID);
508 if (near - 1 > g) { // if d not is at g - make additional triangles
509 for (int k = near - 1; k > g; k--) {
510 c = quad->uv_grid[nbhoriz*(k + 1) - 2].node;
512 d = uv_e0[nbdown - 2].node;
514 d = quad->uv_grid[nbhoriz*k - 2].node;
515 //SMDS_MeshFace* face = meshDS->AddFace(a, c, d);
516 SMDS_MeshFace* face = myTool->AddFace(a, c, d);
517 meshDS->SetMeshElementOnShape(face, geomFaceID);
524 if (quad->isEdgeOut[3]) {
525 // MESSAGE("left edge is out");
526 int g = nbvertic - 1; // last processed node in the grid
528 if (quad->isEdgeOut[0]) stop++;
529 for (i = nbleft - 1; i > stop; i--) {
530 const SMDS_MeshNode *a, *b, *c, *d;
532 b = uv_e3[i - 1].node;
533 gp_Pnt pb (b->X(), b->Y(), b->Z());
535 // find node c in the grid, nearest to the b
537 if (i == stop + 1) { // down bondary reached
538 c = quad->uv_grid[nbhoriz*jlow + 1].node;
541 double mind = RealLast();
542 for (int k = g; k >= jlow; k--) {
543 const SMDS_MeshNode *nk;
547 nk = quad->uv_grid[nbhoriz*k + 1].node;
548 gp_Pnt pnk (nk->X(), nk->Y(), nk->Z());
549 double dist = pb.Distance(pnk);
550 if (dist < mind - eps) {
560 if (near == g) { // make triangle
561 //SMDS_MeshFace* face = meshDS->AddFace(a, b, c);
562 SMDS_MeshFace* face = myTool->AddFace(a, b, c);
563 meshDS->SetMeshElementOnShape(face, geomFaceID);
565 else { // make quadrangle
569 d = quad->uv_grid[nbhoriz*(near + 1) + 1].node;
570 //SMDS_MeshFace* face = meshDS->AddFace(a, b, c, d);
571 if(!myTrianglePreference){
572 SMDS_MeshFace* face = myTool->AddFace(a, b, c, d);
573 meshDS->SetMeshElementOnShape(face, geomFaceID);
576 SMDS_MeshFace* face = myTool->AddFace(a, b, c);
577 meshDS->SetMeshElementOnShape(face, geomFaceID);
578 face = myTool->AddFace(a, c, d);
579 meshDS->SetMeshElementOnShape(face, geomFaceID);
582 if (near + 1 < g) { // if d not is at g - make additional triangles
583 for (int k = near + 1; k < g; k++) {
584 c = quad->uv_grid[nbhoriz*k + 1].node;
588 d = quad->uv_grid[nbhoriz*(k + 1) + 1].node;
589 //SMDS_MeshFace* face = meshDS->AddFace(a, c, d);
590 SMDS_MeshFace* face = myTool->AddFace(a, c, d);
591 meshDS->SetMeshElementOnShape(face, geomFaceID);
604 //=============================================================================
608 //=============================================================================
610 FaceQuadStruct* StdMeshers_Quadrangle_2D::CheckNbEdges(SMESH_Mesh & aMesh,
611 const TopoDS_Shape & aShape)
612 //throw(SALOME_Exception)
614 const TopoDS_Face & F = TopoDS::Face(aShape);
615 const bool ignoreMediumNodes = _quadraticMesh;
617 // verify 1 wire only, with 4 edges
619 list< TopoDS_Edge > edges;
620 list< int > nbEdgesInWire;
621 int nbWire = SMESH_Block::GetOrderedEdges (F, V, edges, nbEdgesInWire);
623 error(COMPERR_BAD_SHAPE, TComm("Wrong number of wires: ") << nbWire);
626 FaceQuadStruct* quad = new FaceQuadStruct;
628 quad->side.reserve(nbEdgesInWire.front());
631 list< TopoDS_Edge >::iterator edgeIt = edges.begin();
632 if ( nbEdgesInWire.front() == 4 ) { // exactly 4 edges
633 for ( ; edgeIt != edges.end(); ++edgeIt, nbSides++ )
634 quad->side.push_back( new StdMeshers_FaceSide(F, *edgeIt, &aMesh,
635 nbSides<TOP_SIDE, ignoreMediumNodes));
637 else if ( nbEdgesInWire.front() > 4 ) { // more than 4 edges - try to unite some
638 list< TopoDS_Edge > sideEdges;
639 while ( !edges.empty()) {
641 sideEdges.splice( sideEdges.end(), edges, edges.begin()); // edges.front() -> sideEdges.end()
642 bool sameSide = true;
643 while ( !edges.empty() && sameSide ) {
644 sameSide = SMESH_Algo::IsContinuous( sideEdges.back(), edges.front() );
646 sideEdges.splice( sideEdges.end(), edges, edges.begin());
648 if ( nbSides == 0 ) { // go backward from the first edge
650 while ( !edges.empty() && sameSide ) {
651 sameSide = SMESH_Algo::IsContinuous( sideEdges.front(), edges.back() );
653 sideEdges.splice( sideEdges.begin(), edges, --edges.end());
656 quad->side.push_back( new StdMeshers_FaceSide(F, sideEdges, &aMesh,
657 nbSides<TOP_SIDE, ignoreMediumNodes));
663 MESSAGE ( "StdMeshers_Quadrangle_2D. Edge IDs of " << nbSides << " sides:\n" );
664 for ( int i = 0; i < nbSides; ++i ) {
666 for ( int e = 0; e < quad->side[i]->NbEdges(); ++e )
667 MESSAGE ( myTool->GetMeshDS()->ShapeToIndex( quad->side[i]->Edge( e )) << " " );
673 nbSides = nbEdgesInWire.front();
674 error(COMPERR_BAD_SHAPE, TComm("Face must have 4 sides but not ") << nbSides);
682 //=============================================================================
686 //=============================================================================
688 FaceQuadStruct *StdMeshers_Quadrangle_2D::CheckAnd2Dcompute
690 const TopoDS_Shape & aShape,
691 const bool CreateQuadratic) //throw(SALOME_Exception)
693 _quadraticMesh = CreateQuadratic;
695 FaceQuadStruct *quad = CheckNbEdges(aMesh, aShape);
699 // set normalized grid on unit square in parametric domain
700 bool stat = SetNormalizedGrid(aMesh, aShape, quad);
710 //=============================================================================
714 //=============================================================================
716 faceQuadStruct::~faceQuadStruct()
718 for (int i = 0; i < side.size(); i++) {
719 if (side[i]) delete side[i];
721 if (uv_grid) delete [] uv_grid;
725 inline const vector<UVPtStruct>& GetUVPtStructIn(FaceQuadStruct* quad, int i, int nbSeg)
727 bool isXConst = ( i == BOTTOM_SIDE || i == TOP_SIDE );
728 double constValue = ( i == BOTTOM_SIDE || i == LEFT_SIDE ) ? 0 : 1;
731 quad->side[i]->SimulateUVPtStruct(nbSeg,isXConst,constValue) :
732 quad->side[i]->GetUVPtStruct(isXConst,constValue);
736 //=============================================================================
740 //=============================================================================
742 bool StdMeshers_Quadrangle_2D::SetNormalizedGrid (SMESH_Mesh & aMesh,
743 const TopoDS_Shape& aShape,
744 FaceQuadStruct* & quad) //throw (SALOME_Exception)
746 // Algorithme décrit dans "Génération automatique de maillages"
747 // P.L. GEORGE, MASSON, § 6.4.1 p. 84-85
748 // traitement dans le domaine paramétrique 2d u,v
749 // transport - projection sur le carré unité
751 // MESSAGE("StdMeshers_Quadrangle_2D::SetNormalizedGrid");
752 // const TopoDS_Face& F = TopoDS::Face(aShape);
754 // 1 --- find orientation of the 4 edges, by test on extrema
757 // |<----north-2-------^ a3 -------------> a2
759 // west-3 east-1 =right | |
763 // v----south-0--------> a0 -------------> a1
768 // 3 --- 2D normalized values on unit square [0..1][0..1]
770 int nbhoriz = Min(quad->side[0]->NbPoints(), quad->side[2]->NbPoints());
771 int nbvertic = Min(quad->side[1]->NbPoints(), quad->side[3]->NbPoints());
773 quad->isEdgeOut[0] = (quad->side[0]->NbPoints() > quad->side[2]->NbPoints());
774 quad->isEdgeOut[1] = (quad->side[1]->NbPoints() > quad->side[3]->NbPoints());
775 quad->isEdgeOut[2] = (quad->side[2]->NbPoints() > quad->side[0]->NbPoints());
776 quad->isEdgeOut[3] = (quad->side[3]->NbPoints() > quad->side[1]->NbPoints());
778 UVPtStruct *uv_grid = quad->uv_grid = new UVPtStruct[nbvertic * nbhoriz];
780 const vector<UVPtStruct>& uv_e0 = GetUVPtStructIn( quad, 0, nbhoriz - 1 );
781 const vector<UVPtStruct>& uv_e1 = GetUVPtStructIn( quad, 1, nbvertic - 1 );
782 const vector<UVPtStruct>& uv_e2 = GetUVPtStructIn( quad, 2, nbhoriz - 1 );
783 const vector<UVPtStruct>& uv_e3 = GetUVPtStructIn( quad, 3, nbvertic - 1 );
785 if ( uv_e0.empty() || uv_e1.empty() || uv_e2.empty() || uv_e3.empty() )
786 //return error( "Can't find nodes on sides");
787 return error( COMPERR_BAD_INPUT_MESH );
789 // nodes Id on "in" edges
790 if (! quad->isEdgeOut[0]) {
792 for (int i = 0; i < nbhoriz; i++) { // down
793 int ij = j * nbhoriz + i;
794 uv_grid[ij].node = uv_e0[i].node;
797 if (! quad->isEdgeOut[1]) {
799 for (int j = 0; j < nbvertic; j++) { // right
800 int ij = j * nbhoriz + i;
801 uv_grid[ij].node = uv_e1[j].node;
804 if (! quad->isEdgeOut[2]) {
805 int j = nbvertic - 1;
806 for (int i = 0; i < nbhoriz; i++) { // up
807 int ij = j * nbhoriz + i;
808 uv_grid[ij].node = uv_e2[i].node;
811 if (! quad->isEdgeOut[3]) {
813 for (int j = 0; j < nbvertic; j++) { // left
814 int ij = j * nbhoriz + i;
815 uv_grid[ij].node = uv_e3[j].node;
819 // normalized 2d values on grid
820 for (int i = 0; i < nbhoriz; i++)
822 for (int j = 0; j < nbvertic; j++)
824 int ij = j * nbhoriz + i;
825 // --- droite i cste : x = x0 + y(x1-x0)
826 double x0 = uv_e0[i].normParam; // bas - sud
827 double x1 = uv_e2[i].normParam; // haut - nord
828 // --- droite j cste : y = y0 + x(y1-y0)
829 double y0 = uv_e3[j].normParam; // gauche-ouest
830 double y1 = uv_e1[j].normParam; // droite - est
831 // --- intersection : x=x0+(y0+x(y1-y0))(x1-x0)
832 double x = (x0 + y0 * (x1 - x0)) / (1 - (y1 - y0) * (x1 - x0));
833 double y = y0 + x * (y1 - y0);
836 //MESSAGE("-xy-01 "<<x0<<" "<<x1<<" "<<y0<<" "<<y1);
837 //MESSAGE("-xy-norm "<<i<<" "<<j<<" "<<x<<" "<<y);
841 // 4 --- projection on 2d domain (u,v)
842 gp_UV a0( uv_e0.front().u, uv_e0.front().v );
843 gp_UV a1( uv_e0.back().u, uv_e0.back().v );
844 gp_UV a2( uv_e2.back().u, uv_e2.back().v );
845 gp_UV a3( uv_e2.front().u, uv_e2.front().v );
847 for (int i = 0; i < nbhoriz; i++)
849 for (int j = 0; j < nbvertic; j++)
851 int ij = j * nbhoriz + i;
852 double x = uv_grid[ij].x;
853 double y = uv_grid[ij].y;
854 double param_0 = uv_e0[0].normParam + x * (uv_e0.back().normParam - uv_e0[0].normParam); // sud
855 double param_2 = uv_e2[0].normParam + x * (uv_e2.back().normParam - uv_e2[0].normParam); // nord
856 double param_1 = uv_e1[0].normParam + y * (uv_e1.back().normParam - uv_e1[0].normParam); // est
857 double param_3 = uv_e3[0].normParam + y * (uv_e3.back().normParam - uv_e3[0].normParam); // ouest
859 //MESSAGE("params "<<param_0<<" "<<param_1<<" "<<param_2<<" "<<param_3);
860 gp_UV p0 = quad->side[0]->Value2d(param_0).XY();
861 gp_UV p1 = quad->side[1]->Value2d(param_1).XY();
862 gp_UV p2 = quad->side[2]->Value2d(param_2).XY();
863 gp_UV p3 = quad->side[3]->Value2d(param_3).XY();
865 gp_UV uv = (1 - y) * p0 + x * p1 + y * p2 + (1 - x) * p3;
866 uv -= (1 - x) * (1 - y) * a0 + x * (1 - y) * a1 + x * y * a2 + (1 - x) * y * a3;
868 uv_grid[ij].u = uv.X();
869 uv_grid[ij].v = uv.Y();
875 //=======================================================================
876 //function : ShiftQuad
877 //purpose : auxilary function for ComputeQuadPref
878 //=======================================================================
880 static void ShiftQuad(FaceQuadStruct* quad, const int num, bool)
882 StdMeshers_FaceSide* side[4] = { quad->side[0], quad->side[1], quad->side[2], quad->side[3] };
883 for (int i = BOTTOM_SIDE; i < NB_SIDES; ++i ) {
884 int id = ( i + num ) % NB_SIDES;
885 bool wasForward = ( i < TOP_SIDE );
886 bool newForward = ( id < TOP_SIDE );
887 if ( wasForward != newForward )
888 side[ i ]->Reverse();
889 quad->side[ id ] = side[ i ];
893 //=======================================================================
895 //purpose : auxilary function for ComputeQuadPref
896 //=======================================================================
898 static gp_UV CalcUV(double x0, double x1, double y0, double y1,
899 FaceQuadStruct* quad,
900 const gp_UV& a0, const gp_UV& a1,
901 const gp_UV& a2, const gp_UV& a3)
903 const vector<UVPtStruct>& uv_eb = quad->side[0]->GetUVPtStruct(true,0 );
904 const vector<UVPtStruct>& uv_er = quad->side[1]->GetUVPtStruct(false,1);
905 const vector<UVPtStruct>& uv_et = quad->side[2]->GetUVPtStruct(true,1 );
906 const vector<UVPtStruct>& uv_el = quad->side[3]->GetUVPtStruct(false,0);
908 double x = (x0 + y0 * (x1 - x0)) / (1 - (y1 - y0) * (x1 - x0));
909 double y = y0 + x * (y1 - y0);
911 double param_b = uv_eb[0].normParam + x * (uv_eb.back().normParam - uv_eb[0].normParam);
912 double param_t = uv_et[0].normParam + x * (uv_et.back().normParam - uv_et[0].normParam);
913 double param_r = uv_er[0].normParam + y * (uv_er.back().normParam - uv_er[0].normParam);
914 double param_l = uv_el[0].normParam + y * (uv_el.back().normParam - uv_el[0].normParam);
916 gp_UV p0 = quad->side[BOTTOM_SIDE]->Value2d(param_b).XY();
917 gp_UV p1 = quad->side[RIGHT_SIDE ]->Value2d(param_r).XY();
918 gp_UV p2 = quad->side[TOP_SIDE ]->Value2d(param_t).XY();
919 gp_UV p3 = quad->side[LEFT_SIDE ]->Value2d(param_l).XY();
921 gp_UV uv = p0 * (1 - y) + p1 * x + p2 * y + p3 * (1 - x);
923 uv -= (1 - x) * (1 - y) * a0 + x * (1 - y) * a1 + x * y * a2 + (1 - x) * y * a3;
929 //=======================================================================
931 //purpose : auxilary function for ComputeQuadPref
932 //=======================================================================
934 static gp_UV CalcUV2(double x, double y,
935 FaceQuadStruct* quad,
936 const gp_UV& a0, const gp_UV& a1,
937 const gp_UV& a2, const gp_UV& a3)
939 const vector<UVPtStruct>& uv_eb = quad->side[0]->GetUVPtStruct(true,0 );
940 const vector<UVPtStruct>& uv_er = quad->side[1]->GetUVPtStruct(false,1);
941 const vector<UVPtStruct>& uv_et = quad->side[2]->GetUVPtStruct(true,1 );
942 const vector<UVPtStruct>& uv_el = quad->side[3]->GetUVPtStruct(false,0);
944 //double x = (x0 + y0 * (x1 - x0)) / (1 - (y1 - y0) * (x1 - x0));
945 //double y = y0 + x * (y1 - y0);
947 double param_b = uv_eb[0].normParam + x * (uv_eb.back().normParam - uv_eb[0].normParam);
948 double param_t = uv_et[0].normParam + x * (uv_et.back().normParam - uv_et[0].normParam);
949 double param_r = uv_er[0].normParam + y * (uv_er.back().normParam - uv_er[0].normParam);
950 double param_l = uv_el[0].normParam + y * (uv_el.back().normParam - uv_el[0].normParam);
952 gp_UV p0 = quad->side[BOTTOM_SIDE]->Value2d(param_b).XY();
953 gp_UV p1 = quad->side[RIGHT_SIDE ]->Value2d(param_r).XY();
954 gp_UV p2 = quad->side[TOP_SIDE ]->Value2d(param_t).XY();
955 gp_UV p3 = quad->side[LEFT_SIDE ]->Value2d(param_l).XY();
957 gp_UV uv = p0 * (1 - y) + p1 * x + p2 * y + p3 * (1 - x);
959 uv -= (1 - x) * (1 - y) * a0 + x * (1 - y) * a1 + x * y * a2 + (1 - x) * y * a3;
964 //=======================================================================
966 * Create only quandrangle faces
968 //=======================================================================
970 bool StdMeshers_Quadrangle_2D::ComputeQuadPref (SMESH_Mesh & aMesh,
971 const TopoDS_Shape& aShape,
972 FaceQuadStruct* quad)
974 // Auxilary key in order to keep old variant
975 // of meshing after implementation new variant
976 // for bug 0016220 from Mantis.
977 bool OldVersion = false;
979 SMESHDS_Mesh * meshDS = aMesh.GetMeshDS();
980 const TopoDS_Face& F = TopoDS::Face(aShape);
981 Handle(Geom_Surface) S = BRep_Tool::Surface(F);
982 // const TopoDS_Wire& W = BRepTools::OuterWire(F);
984 // if(W.Orientation()==TopAbs_FORWARD)
986 //if(WisF) cout<<"W is FORWARD"<<endl;
987 //else cout<<"W is REVERSED"<<endl;
988 // bool FisF = (F.Orientation()==TopAbs_FORWARD);
989 // if(!FisF) WisF = !WisF;
991 int i,j,geomFaceID = meshDS->ShapeToIndex( F );
993 int nb = quad->side[0]->NbPoints();
994 int nr = quad->side[1]->NbPoints();
995 int nt = quad->side[2]->NbPoints();
996 int nl = quad->side[3]->NbPoints();
1002 // it is a base case => not shift quad but me be replacement is need
1003 ShiftQuad(quad,0,WisF);
1006 // we have to shift quad on 2
1007 ShiftQuad(quad,2,WisF);
1012 // we have to shift quad on 1
1013 ShiftQuad(quad,1,WisF);
1016 // we have to shift quad on 3
1017 ShiftQuad(quad,3,WisF);
1021 nb = quad->side[0]->NbPoints();
1022 nr = quad->side[1]->NbPoints();
1023 nt = quad->side[2]->NbPoints();
1024 nl = quad->side[3]->NbPoints();
1027 int nbh = Max(nb,nt);
1028 int nbv = Max(nr,nl);
1032 // ----------- Old version ---------------
1033 // orientation of face and 3 main domain for future faces
1039 // left | | | | rigth
1046 // ----------- New version ---------------
1047 // orientation of face and 3 main domain for future faces
1053 // left |/________\| rigth
1069 const vector<UVPtStruct>& uv_eb = quad->side[0]->GetUVPtStruct(true,0 );
1070 const vector<UVPtStruct>& uv_er = quad->side[1]->GetUVPtStruct(false,1);
1071 const vector<UVPtStruct>& uv_et = quad->side[2]->GetUVPtStruct(true,1 );
1072 const vector<UVPtStruct>& uv_el = quad->side[3]->GetUVPtStruct(false,0);
1074 // arrays for normalized params
1075 //cout<<"Dump B:"<<endl;
1076 TColStd_SequenceOfReal npb, npr, npt, npl;
1077 for(i=0; i<nb; i++) {
1078 npb.Append(uv_eb[i].normParam);
1079 //cout<<"i="<<i<<" par="<<uv_eb[i].normParam<<" npar="<<uv_eb[i].normParam;
1080 //const SMDS_MeshNode* N = uv_eb[i].node;
1081 //cout<<" node("<<N->X()<<","<<N->Y()<<","<<N->Z()<<")"<<endl;
1083 for(i=0; i<nr; i++) {
1084 npr.Append(uv_er[i].normParam);
1086 for(i=0; i<nt; i++) {
1087 npt.Append(uv_et[i].normParam);
1089 for(i=0; i<nl; i++) {
1090 npl.Append(uv_el[i].normParam);
1095 // add some params to right and left after the first param
1098 double dpr = (npr.Value(2) - npr.Value(1))/(dr+1);
1099 for(i=1; i<=dr; i++) {
1100 npr.InsertAfter(1,npr.Value(2)-dpr);
1104 dpr = (npl.Value(2) - npl.Value(1))/(dl+1);
1105 for(i=1; i<=dl; i++) {
1106 npl.InsertAfter(1,npl.Value(2)-dpr);
1110 //for(i=1; i<=npb.Length(); i++) {
1111 // cout<<" "<<npb.Value(i);
1115 gp_XY a0( uv_eb.front().u, uv_eb.front().v );
1116 gp_XY a1( uv_eb.back().u, uv_eb.back().v );
1117 gp_XY a2( uv_et.back().u, uv_et.back().v );
1118 gp_XY a3( uv_et.front().u, uv_et.front().v );
1119 //cout<<" a0("<<a0.X()<<","<<a0.Y()<<")"<<" a1("<<a1.X()<<","<<a1.Y()<<")"
1120 // <<" a2("<<a2.X()<<","<<a2.Y()<<")"<<" a3("<<a3.X()<<","<<a3.Y()<<")"<<endl;
1122 int nnn = Min(nr,nl);
1123 // auxilary sequence of XY for creation nodes
1124 // in the bottom part of central domain
1125 // it's length must be == nbv-nnn-1
1126 TColgp_SequenceOfXY UVL;
1127 TColgp_SequenceOfXY UVR;
1130 // step1: create faces for left domain
1131 StdMeshers_Array2OfNode NodesL(1,dl+1,1,nl);
1133 for(j=1; j<=nl; j++)
1134 NodesL.SetValue(1,j,uv_el[j-1].node);
1137 for(i=1; i<=dl; i++)
1138 NodesL.SetValue(i+1,nl,uv_et[i].node);
1139 // create and add needed nodes
1140 TColgp_SequenceOfXY UVtmp;
1141 for(i=1; i<=dl; i++) {
1142 double x0 = npt.Value(i+1);
1145 double y0 = npl.Value(i+1);
1146 double y1 = npr.Value(i+1);
1147 gp_UV UV = CalcUV(x0, x1, y0, y1, quad, a0, a1, a2, a3);
1148 gp_Pnt P = S->Value(UV.X(),UV.Y());
1149 SMDS_MeshNode * N = meshDS->AddNode(P.X(), P.Y(), P.Z());
1150 meshDS->SetNodeOnFace(N, geomFaceID, UV.X(), UV.Y());
1151 NodesL.SetValue(i+1,1,N);
1152 if(UVL.Length()<nbv-nnn-1) UVL.Append(UV);
1154 for(j=2; j<nl; j++) {
1155 double y0 = npl.Value(dl+j);
1156 double y1 = npr.Value(dl+j);
1157 gp_UV UV = CalcUV(x0, x1, y0, y1, quad, a0, a1, a2, a3);
1158 gp_Pnt P = S->Value(UV.X(),UV.Y());
1159 SMDS_MeshNode* N = meshDS->AddNode(P.X(), P.Y(), P.Z());
1160 meshDS->SetNodeOnFace(N, geomFaceID, UV.X(), UV.Y());
1161 NodesL.SetValue(i+1,j,N);
1162 if( i==dl ) UVtmp.Append(UV);
1165 for(i=1; i<=UVtmp.Length() && UVL.Length()<nbv-nnn-1; i++) {
1166 UVL.Append(UVtmp.Value(i));
1168 //cout<<"Dump NodesL:"<<endl;
1169 //for(i=1; i<=dl+1; i++) {
1171 // for(j=1; j<=nl; j++) {
1172 // cout<<" ("<<NodesL.Value(i,j)->X()<<","<<NodesL.Value(i,j)->Y()<<","<<NodesL.Value(i,j)->Z()<<")";
1177 for(i=1; i<=dl; i++) {
1178 for(j=1; j<nl; j++) {
1181 myTool->AddFace(NodesL.Value(i,j), NodesL.Value(i+1,j),
1182 NodesL.Value(i+1,j+1), NodesL.Value(i,j+1));
1183 meshDS->SetMeshElementOnShape(F, geomFaceID);
1187 myTool->AddFace(NodesL.Value(i,j), NodesL.Value(i,j+1),
1188 NodesL.Value(i+1,j+1), NodesL.Value(i+1,j));
1189 meshDS->SetMeshElementOnShape(F, geomFaceID);
1195 // fill UVL using c2d
1196 for(i=1; i<npl.Length() && UVL.Length()<nbv-nnn-1; i++) {
1197 UVL.Append( gp_UV ( uv_el[i].u, uv_el[i].v ));
1201 // step2: create faces for right domain
1202 StdMeshers_Array2OfNode NodesR(1,dr+1,1,nr);
1204 for(j=1; j<=nr; j++)
1205 NodesR.SetValue(1,j,uv_er[nr-j].node);
1208 for(i=1; i<=dr; i++)
1209 NodesR.SetValue(i+1,1,uv_et[nt-1-i].node);
1210 // create and add needed nodes
1211 TColgp_SequenceOfXY UVtmp;
1212 for(i=1; i<=dr; i++) {
1213 double x0 = npt.Value(nt-i);
1216 double y0 = npl.Value(i+1);
1217 double y1 = npr.Value(i+1);
1218 gp_UV UV = CalcUV(x0, x1, y0, y1, quad, a0, a1, a2, a3);
1219 gp_Pnt P = S->Value(UV.X(),UV.Y());
1220 SMDS_MeshNode * N = meshDS->AddNode(P.X(), P.Y(), P.Z());
1221 meshDS->SetNodeOnFace(N, geomFaceID, UV.X(), UV.Y());
1222 NodesR.SetValue(i+1,nr,N);
1223 if(UVR.Length()<nbv-nnn-1) UVR.Append(UV);
1225 for(j=2; j<nr; j++) {
1226 double y0 = npl.Value(nbv-j+1);
1227 double y1 = npr.Value(nbv-j+1);
1228 gp_UV UV = CalcUV(x0, x1, y0, y1, quad, a0, a1, a2, a3);
1229 gp_Pnt P = S->Value(UV.X(),UV.Y());
1230 SMDS_MeshNode* N = meshDS->AddNode(P.X(), P.Y(), P.Z());
1231 meshDS->SetNodeOnFace(N, geomFaceID, UV.X(), UV.Y());
1232 NodesR.SetValue(i+1,j,N);
1233 if( i==dr ) UVtmp.Prepend(UV);
1236 for(i=1; i<=UVtmp.Length() && UVR.Length()<nbv-nnn-1; i++) {
1237 UVR.Append(UVtmp.Value(i));
1240 for(i=1; i<=dr; i++) {
1241 for(j=1; j<nr; j++) {
1244 myTool->AddFace(NodesR.Value(i,j), NodesR.Value(i+1,j),
1245 NodesR.Value(i+1,j+1), NodesR.Value(i,j+1));
1246 meshDS->SetMeshElementOnShape(F, geomFaceID);
1250 myTool->AddFace(NodesR.Value(i,j), NodesR.Value(i,j+1),
1251 NodesR.Value(i+1,j+1), NodesR.Value(i+1,j));
1252 meshDS->SetMeshElementOnShape(F, geomFaceID);
1258 // fill UVR using c2d
1259 for(i=1; i<npr.Length() && UVR.Length()<nbv-nnn-1; i++) {
1260 UVR.Append( gp_UV( uv_er[i].u, uv_er[i].v ));
1264 // step3: create faces for central domain
1265 StdMeshers_Array2OfNode NodesC(1,nb,1,nbv);
1266 // add first string using NodesL
1267 for(i=1; i<=dl+1; i++)
1268 NodesC.SetValue(1,i,NodesL(i,1));
1269 for(i=2; i<=nl; i++)
1270 NodesC.SetValue(1,dl+i,NodesL(dl+1,i));
1271 // add last string using NodesR
1272 for(i=1; i<=dr+1; i++)
1273 NodesC.SetValue(nb,i,NodesR(i,nr));
1275 NodesC.SetValue(nb,dr+i+1,NodesR(dr+1,nr-i));
1276 // add top nodes (last columns)
1277 for(i=dl+2; i<nbh-dr; i++)
1278 NodesC.SetValue(i-dl,nbv,uv_et[i-1].node);
1279 // add bottom nodes (first columns)
1281 NodesC.SetValue(i,1,uv_eb[i-1].node);
1283 // create and add needed nodes
1284 // add linear layers
1285 for(i=2; i<nb; i++) {
1286 double x0 = npt.Value(dl+i);
1288 for(j=1; j<nnn; j++) {
1289 double y0 = npl.Value(nbv-nnn+j);
1290 double y1 = npr.Value(nbv-nnn+j);
1291 gp_UV UV = CalcUV(x0, x1, y0, y1, quad, a0, a1, a2, a3);
1292 gp_Pnt P = S->Value(UV.X(),UV.Y());
1293 SMDS_MeshNode* N = meshDS->AddNode(P.X(), P.Y(), P.Z());
1294 meshDS->SetNodeOnFace(N, geomFaceID, UV.X(), UV.Y());
1295 NodesC.SetValue(i,nbv-nnn+j,N);
1298 // add diagonal layers
1299 //cout<<"UVL.Length()="<<UVL.Length()<<" UVR.Length()="<<UVR.Length()<<endl;
1300 //cout<<"Dump UVL:"<<endl;
1301 //for(i=1; i<=UVL.Length(); i++) {
1302 // cout<<" ("<<UVL.Value(i).X()<<","<<UVL.Value(i).Y()<<")";
1305 for(i=1; i<nbv-nnn; i++) {
1306 double du = UVR.Value(i).X() - UVL.Value(i).X();
1307 double dv = UVR.Value(i).Y() - UVL.Value(i).Y();
1308 for(j=2; j<nb; j++) {
1309 double u = UVL.Value(i).X() + du*npb.Value(j);
1310 double v = UVL.Value(i).Y() + dv*npb.Value(j);
1311 gp_Pnt P = S->Value(u,v);
1312 SMDS_MeshNode* N = meshDS->AddNode(P.X(), P.Y(), P.Z());
1313 meshDS->SetNodeOnFace(N, geomFaceID, u, v);
1314 NodesC.SetValue(j,i+1,N);
1318 for(i=1; i<nb; i++) {
1319 for(j=1; j<nbv; j++) {
1322 myTool->AddFace(NodesC.Value(i,j), NodesC.Value(i+1,j),
1323 NodesC.Value(i+1,j+1), NodesC.Value(i,j+1));
1324 meshDS->SetMeshElementOnShape(F, geomFaceID);
1328 myTool->AddFace(NodesC.Value(i,j), NodesC.Value(i,j+1),
1329 NodesC.Value(i+1,j+1), NodesC.Value(i+1,j));
1330 meshDS->SetMeshElementOnShape(F, geomFaceID);
1336 else { // New version (!OldVersion)
1337 // step1: create faces for bottom rectangle domain
1338 StdMeshers_Array2OfNode NodesBRD(1,nb,1,nnn-1);
1339 // fill UVL and UVR using c2d
1340 for(j=0; j<nb; j++) {
1341 NodesBRD.SetValue(j+1,1,uv_eb[j].node);
1343 for(i=1; i<nnn-1; i++) {
1344 NodesBRD.SetValue(1,i+1,uv_el[i].node);
1345 NodesBRD.SetValue(nb,i+1,uv_er[i].node);
1346 double du = uv_er[i].u - uv_el[i].u;
1347 double dv = uv_er[i].v - uv_el[i].v;
1348 for(j=2; j<nb; j++) {
1349 double u = uv_el[i].u + du*npb.Value(j);
1350 double v = uv_el[i].v + dv*npb.Value(j);
1351 gp_Pnt P = S->Value(u,v);
1352 SMDS_MeshNode* N = meshDS->AddNode(P.X(), P.Y(), P.Z());
1353 meshDS->SetNodeOnFace(N, geomFaceID, u, v);
1354 NodesBRD.SetValue(j,i+1,N);
1358 for(j=1; j<nnn-1; j++) {
1359 for(i=1; i<nb; i++) {
1362 myTool->AddFace(NodesBRD.Value(i,j), NodesBRD.Value(i+1,j),
1363 NodesBRD.Value(i+1,j+1), NodesBRD.Value(i,j+1));
1364 meshDS->SetMeshElementOnShape(F, geomFaceID);
1368 myTool->AddFace(NodesBRD.Value(i,j), NodesBRD.Value(i,j+1),
1369 NodesBRD.Value(i+1,j+1), NodesBRD.Value(i+1,j));
1370 meshDS->SetMeshElementOnShape(F, geomFaceID);
1375 int drl = abs(nr-nl);
1376 // create faces for region C
1377 StdMeshers_Array2OfNode NodesC(1,nb,1,drl+1+addv);
1378 // add nodes from previous region
1379 for(j=1; j<=nb; j++) {
1380 NodesC.SetValue(j,1,NodesBRD.Value(j,nnn-1));
1382 if( (drl+addv) > 0 ) {
1387 TColgp_SequenceOfXY UVtmp;
1388 double drparam = npr.Value(nr) - npr.Value(nnn-1);
1389 double dlparam = npl.Value(nnn) - npl.Value(nnn-1);
1391 for(i=1; i<=drl; i++) {
1392 // add existed nodes from right edge
1393 NodesC.SetValue(nb,i+1,uv_er[nnn+i-2].node);
1394 //double dtparam = npt.Value(i+1);
1395 y1 = npr.Value(nnn+i-1); // param on right edge
1396 double dpar = (y1 - npr.Value(nnn-1))/drparam;
1397 y0 = npl.Value(nnn-1) + dpar*dlparam; // param on left edge
1398 double dy = y1 - y0;
1399 for(j=1; j<nb; j++) {
1400 double x = npt.Value(i+1) + npb.Value(j)*(1-npt.Value(i+1));
1401 double y = y0 + dy*x;
1402 gp_UV UV = CalcUV2(x, y, quad, a0, a1, a2, a3);
1403 gp_Pnt P = S->Value(UV.X(),UV.Y());
1404 SMDS_MeshNode* N = meshDS->AddNode(P.X(), P.Y(), P.Z());
1405 meshDS->SetNodeOnFace(N, geomFaceID, UV.X(), UV.Y());
1406 NodesC.SetValue(j,i+1,N);
1409 double dy0 = (1-y0)/(addv+1);
1410 double dy1 = (1-y1)/(addv+1);
1411 for(i=1; i<=addv; i++) {
1412 double yy0 = y0 + dy0*i;
1413 double yy1 = y1 + dy1*i;
1414 double dyy = yy1 - yy0;
1415 for(j=1; j<=nb; j++) {
1416 double x = npt.Value(i+1+drl) +
1417 npb.Value(j) * ( npt.Value(nt-i) - npt.Value(i+1+drl) );
1418 double y = yy0 + dyy*x;
1419 gp_UV UV = CalcUV2(x, y, quad, a0, a1, a2, a3);
1420 gp_Pnt P = S->Value(UV.X(),UV.Y());
1421 SMDS_MeshNode* N = meshDS->AddNode(P.X(), P.Y(), P.Z());
1422 meshDS->SetNodeOnFace(N, geomFaceID, UV.X(), UV.Y());
1423 NodesC.SetValue(j,i+drl+1,N);
1430 TColgp_SequenceOfXY UVtmp;
1431 double dlparam = npl.Value(nl) - npl.Value(nnn-1);
1432 double drparam = npr.Value(nnn) - npr.Value(nnn-1);
1433 double y0 = npl.Value(nnn-1);
1434 double y1 = npr.Value(nnn-1);
1435 for(i=1; i<=drl; i++) {
1436 // add existed nodes from right edge
1437 NodesC.SetValue(1,i+1,uv_el[nnn+i-2].node);
1438 y0 = npl.Value(nnn+i-1); // param on left edge
1439 double dpar = (y0 - npl.Value(nnn-1))/dlparam;
1440 y1 = npr.Value(nnn-1) + dpar*drparam; // param on right edge
1441 double dy = y1 - y0;
1442 for(j=2; j<=nb; j++) {
1443 double x = npb.Value(j)*npt.Value(nt-i);
1444 double y = y0 + dy*x;
1445 gp_UV UV = CalcUV2(x, y, quad, a0, a1, a2, a3);
1446 gp_Pnt P = S->Value(UV.X(),UV.Y());
1447 SMDS_MeshNode* N = meshDS->AddNode(P.X(), P.Y(), P.Z());
1448 meshDS->SetNodeOnFace(N, geomFaceID, UV.X(), UV.Y());
1449 NodesC.SetValue(j,i+1,N);
1452 double dy0 = (1-y0)/(addv+1);
1453 double dy1 = (1-y1)/(addv+1);
1454 for(i=1; i<=addv; i++) {
1455 double yy0 = y0 + dy0*i;
1456 double yy1 = y1 + dy1*i;
1457 double dyy = yy1 - yy0;
1458 for(j=1; j<=nb; j++) {
1459 double x = npt.Value(i+1) +
1460 npb.Value(j) * ( npt.Value(nt-i-drl) - npt.Value(i+1) );
1461 double y = yy0 + dyy*x;
1462 gp_UV UV = CalcUV2(x, y, quad, a0, a1, a2, a3);
1463 gp_Pnt P = S->Value(UV.X(),UV.Y());
1464 SMDS_MeshNode* N = meshDS->AddNode(P.X(), P.Y(), P.Z());
1465 meshDS->SetNodeOnFace(N, geomFaceID, UV.X(), UV.Y());
1466 NodesC.SetValue(j,i+drl+1,N);
1471 for(j=1; j<=drl+addv; j++) {
1472 for(i=1; i<nb; i++) {
1475 myTool->AddFace(NodesC.Value(i,j), NodesC.Value(i+1,j),
1476 NodesC.Value(i+1,j+1), NodesC.Value(i,j+1));
1477 meshDS->SetMeshElementOnShape(F, geomFaceID);
1481 myTool->AddFace(NodesC.Value(i,j), NodesC.Value(i,j+1),
1482 NodesC.Value(i+1,j+1), NodesC.Value(i+1,j));
1483 meshDS->SetMeshElementOnShape(F, geomFaceID);
1488 StdMeshers_Array2OfNode NodesLast(1,nt,1,2);
1489 for(i=1; i<=nt; i++) {
1490 NodesLast.SetValue(i,2,uv_et[i-1].node);
1493 for(i=n1; i<drl+addv+1; i++) {
1495 NodesLast.SetValue(nnn,1,NodesC.Value(1,i));
1497 for(i=1; i<=nb; i++) {
1499 NodesLast.SetValue(nnn,1,NodesC.Value(i,drl+addv+1));
1501 for(i=drl+addv; i>=n2; i--) {
1503 NodesLast.SetValue(nnn,1,NodesC.Value(nb,i));
1505 for(i=1; i<nt; i++) {
1508 myTool->AddFace(NodesLast.Value(i,1), NodesLast.Value(i+1,1),
1509 NodesLast.Value(i+1,2), NodesLast.Value(i,2));
1510 meshDS->SetMeshElementOnShape(F, geomFaceID);
1514 myTool->AddFace(NodesLast.Value(i,1), NodesLast.Value(i,2),
1515 NodesLast.Value(i+1,2), NodesLast.Value(i+1,2));
1516 meshDS->SetMeshElementOnShape(F, geomFaceID);
1519 } // if( (drl+addv) > 0 )
1521 } // end new version implementation