1 // Copyright (C) 2007-2014 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, or (at your option) any later version.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 // File : StdMeshers_Prism_3D.cxx
25 // Created : Fri Oct 20 11:37:07 2006
26 // Author : Edward AGAPOV (eap)
28 #include "StdMeshers_Prism_3D.hxx"
30 #include "SMDS_EdgePosition.hxx"
31 #include "SMDS_VolumeOfNodes.hxx"
32 #include "SMDS_VolumeTool.hxx"
33 #include "SMESH_Comment.hxx"
34 #include "SMESH_Gen.hxx"
35 #include "SMESH_HypoFilter.hxx"
36 #include "SMESH_MesherHelper.hxx"
37 #include "StdMeshers_FaceSide.hxx"
38 #include "StdMeshers_ProjectionSource1D.hxx"
39 #include "StdMeshers_ProjectionSource2D.hxx"
40 #include "StdMeshers_ProjectionUtils.hxx"
41 #include "StdMeshers_Projection_1D.hxx"
42 #include "StdMeshers_Projection_1D2D.hxx"
43 #include "StdMeshers_Quadrangle_2D.hxx"
45 #include "utilities.h"
47 #include <BRepAdaptor_CompCurve.hxx>
48 #include <BRep_Tool.hxx>
49 #include <Bnd_B3d.hxx>
50 #include <Geom2dAdaptor_Curve.hxx>
51 #include <Geom2d_Line.hxx>
52 #include <GeomLib_IsPlanarSurface.hxx>
53 #include <Geom_Curve.hxx>
55 #include <TopExp_Explorer.hxx>
56 #include <TopTools_ListIteratorOfListOfShape.hxx>
57 #include <TopTools_ListOfShape.hxx>
58 #include <TopTools_MapOfShape.hxx>
59 #include <TopTools_SequenceOfShape.hxx>
68 #define RETURN_BAD_RESULT(msg) { MESSAGE(")-: Error: " << msg); return false; }
69 #define gpXYZ(n) SMESH_TNodeXYZ(n)
72 #define DBGOUT(msg) //cout << msg << endl;
73 #define SHOWYXZ(msg, xyz) \
74 // { gp_Pnt p (xyz); \
75 // cout << msg << " ("<< p.X() << "; " <<p.Y() << "; " <<p.Z() << ") " <<endl; }
78 #define SHOWYXZ(msg, xyz)
81 namespace NSProjUtils = StdMeshers_ProjectionUtils;
83 typedef SMESH_Comment TCom;
85 enum { ID_BOT_FACE = SMESH_Block::ID_Fxy0,
86 ID_TOP_FACE = SMESH_Block::ID_Fxy1,
87 BOTTOM_EDGE = 0, TOP_EDGE, V0_EDGE, V1_EDGE, // edge IDs in face
88 NB_WALL_FACES = 4 }; //
92 //=======================================================================
94 * \brief Quadrangle algorithm
96 struct TQuadrangleAlgo : public StdMeshers_Quadrangle_2D
98 TQuadrangleAlgo(int studyId, SMESH_Gen* gen)
99 : StdMeshers_Quadrangle_2D( gen->GetANewId(), studyId, gen)
102 static StdMeshers_Quadrangle_2D* instance( SMESH_Algo* fatherAlgo,
103 SMESH_MesherHelper* helper=0)
105 static TQuadrangleAlgo* algo = new TQuadrangleAlgo( fatherAlgo->GetStudyId(),
106 fatherAlgo->GetGen() );
109 algo->myProxyMesh->GetMesh() != helper->GetMesh() )
110 algo->myProxyMesh.reset( new SMESH_ProxyMesh( *helper->GetMesh() ));
112 algo->myQuadList.clear();
115 algo->_quadraticMesh = helper->GetIsQuadratic();
120 //=======================================================================
122 * \brief Algorithm projecting 1D mesh
124 struct TProjction1dAlgo : public StdMeshers_Projection_1D
126 StdMeshers_ProjectionSource1D myHyp;
128 TProjction1dAlgo(int studyId, SMESH_Gen* gen)
129 : StdMeshers_Projection_1D( gen->GetANewId(), studyId, gen),
130 myHyp( gen->GetANewId(), studyId, gen)
132 StdMeshers_Projection_1D::_sourceHypo = & myHyp;
134 static TProjction1dAlgo* instance( SMESH_Algo* fatherAlgo )
136 static TProjction1dAlgo* algo = new TProjction1dAlgo( fatherAlgo->GetStudyId(),
137 fatherAlgo->GetGen() );
141 //=======================================================================
143 * \brief Algorithm projecting 2D mesh
145 struct TProjction2dAlgo : public StdMeshers_Projection_1D2D
147 StdMeshers_ProjectionSource2D myHyp;
149 TProjction2dAlgo(int studyId, SMESH_Gen* gen)
150 : StdMeshers_Projection_1D2D( gen->GetANewId(), studyId, gen),
151 myHyp( gen->GetANewId(), studyId, gen)
153 StdMeshers_Projection_2D::_sourceHypo = & myHyp;
155 static TProjction2dAlgo* instance( SMESH_Algo* fatherAlgo )
157 static TProjction2dAlgo* algo = new TProjction2dAlgo( fatherAlgo->GetStudyId(),
158 fatherAlgo->GetGen() );
161 const NSProjUtils::TNodeNodeMap& GetNodesMap()
163 return _src2tgtNodes;
166 //=======================================================================
168 * \brief Returns already computed EDGEs
170 void getPrecomputedEdges( SMESH_MesherHelper& theHelper,
171 const TopoDS_Shape& theShape,
172 vector< TopoDS_Edge >& theEdges)
176 SMESHDS_Mesh* meshDS = theHelper.GetMeshDS();
179 TopTools_IndexedMapOfShape edges;
180 TopExp::MapShapes( theShape, TopAbs_EDGE, edges );
181 for ( int iE = 1; iE <= edges.Extent(); ++iE )
183 const TopoDS_Shape edge = edges( iE );
184 if (( ! ( sm = meshDS->MeshElements( edge ))) ||
185 ( sm->NbElements() == 0 ))
188 // there must not be FACEs meshed with triangles and sharing a computed EDGE
189 // as the precomputed EDGEs are used for propagation other to 'vertical' EDGEs
190 bool faceFound = false;
191 PShapeIteratorPtr faceIt =
192 theHelper.GetAncestors( edge, *theHelper.GetMesh(), TopAbs_FACE );
193 while ( const TopoDS_Shape* face = faceIt->next() )
195 if (( sm = meshDS->MeshElements( *face )) &&
196 ( sm->NbElements() > 0 ) &&
197 ( !theHelper.IsSameElemGeometry( sm, SMDSGeom_QUADRANGLE ) ))
203 theEdges.push_back( TopoDS::Edge( edge ));
207 //================================================================================
209 * \brief Make \a botE be the BOTTOM_SIDE of \a quad.
210 * Return false if the BOTTOM_SIDE is composite
212 //================================================================================
214 bool setBottomEdge( const TopoDS_Edge& botE,
215 FaceQuadStruct::Ptr& quad,
216 const TopoDS_Shape& face)
218 quad->side[ QUAD_TOP_SIDE ].grid->Reverse();
219 quad->side[ QUAD_LEFT_SIDE ].grid->Reverse();
221 bool isComposite = false;
222 for ( size_t i = 0; i < quad->side.size(); ++i )
224 StdMeshers_FaceSidePtr quadSide = quad->side[i];
225 for ( int iE = 0; iE < quadSide->NbEdges(); ++iE )
226 if ( botE.IsSame( quadSide->Edge( iE )))
228 if ( quadSide->NbEdges() > 1 )
229 isComposite = true; //return false;
231 i = quad->side.size(); // to quit from the outer loop
235 if ( edgeIndex != QUAD_BOTTOM_SIDE )
236 quad->shift( quad->side.size() - edgeIndex, /*keepUnitOri=*/false );
238 quad->face = TopoDS::Face( face );
243 //================================================================================
245 * \brief Return iterator pointing to node column for the given parameter
246 * \param columnsMap - node column map
247 * \param parameter - parameter
248 * \retval TParam2ColumnMap::iterator - result
250 * it returns closest left column
252 //================================================================================
254 TParam2ColumnIt getColumn( const TParam2ColumnMap* columnsMap,
255 const double parameter )
257 TParam2ColumnIt u_col = columnsMap->upper_bound( parameter );
258 if ( u_col != columnsMap->begin() )
260 return u_col; // return left column
263 //================================================================================
265 * \brief Return nodes around given parameter and a ratio
266 * \param column - node column
267 * \param param - parameter
268 * \param node1 - lower node
269 * \param node2 - upper node
270 * \retval double - ratio
272 //================================================================================
274 double getRAndNodes( const TNodeColumn* column,
276 const SMDS_MeshNode* & node1,
277 const SMDS_MeshNode* & node2)
279 if ( param >= 1.0 || column->size() == 1) {
280 node1 = node2 = column->back();
284 int i = int( param * ( column->size() - 1 ));
285 double u0 = double( i )/ double( column->size() - 1 );
286 double r = ( param - u0 ) * ( column->size() - 1 );
288 node1 = (*column)[ i ];
289 node2 = (*column)[ i + 1];
293 //================================================================================
295 * \brief Compute boundary parameters of face parts
296 * \param nbParts - nb of parts to split columns into
297 * \param columnsMap - node columns of the face to split
298 * \param params - computed parameters
300 //================================================================================
302 void splitParams( const int nbParts,
303 const TParam2ColumnMap* columnsMap,
304 vector< double > & params)
307 params.reserve( nbParts + 1 );
308 TParam2ColumnIt last_par_col = --columnsMap->end();
309 double par = columnsMap->begin()->first; // 0.
310 double parLast = last_par_col->first;
311 params.push_back( par );
312 for ( int i = 0; i < nbParts - 1; ++ i )
314 double partSize = ( parLast - par ) / double ( nbParts - i );
315 TParam2ColumnIt par_col = getColumn( columnsMap, par + partSize );
316 if ( par_col->first == par ) {
318 if ( par_col == last_par_col ) {
319 while ( i < nbParts - 1 )
320 params.push_back( par + partSize * i++ );
324 par = par_col->first;
325 params.push_back( par );
327 params.push_back( parLast ); // 1.
330 //================================================================================
332 * \brief Return coordinate system for z-th layer of nodes
334 //================================================================================
336 gp_Ax2 getLayerCoordSys(const int z,
337 const vector< const TNodeColumn* >& columns,
340 // gravity center of a layer
343 for ( int i = 0; i < columns.size(); ++i )
345 O += gpXYZ( (*columns[ i ])[ z ]);
346 if ( vertexCol < 0 &&
347 columns[ i ]->front()->GetPosition()->GetTypeOfPosition() == SMDS_TOP_VERTEX )
354 int iPrev = columns.size()-1;
355 for ( int i = 0; i < columns.size(); ++i )
357 gp_Vec v1( O, gpXYZ( (*columns[ iPrev ])[ z ]));
358 gp_Vec v2( O, gpXYZ( (*columns[ i ] )[ z ]));
363 if ( vertexCol >= 0 )
365 O = gpXYZ( (*columns[ vertexCol ])[ z ]);
367 if ( xColumn < 0 || xColumn >= columns.size() )
369 // select a column for X dir
371 for ( int i = 0; i < columns.size(); ++i )
373 double dist = ( O - gpXYZ((*columns[ i ])[ z ])).SquareModulus();
374 if ( dist > maxDist )
383 gp_Vec X( O, gpXYZ( (*columns[ xColumn ])[ z ]));
385 return gp_Ax2( O, Z, X);
388 //================================================================================
390 * \brief Removes submeshes that are or can be meshed with regular grid from given list
391 * \retval int - nb of removed submeshes
393 //================================================================================
395 int removeQuasiQuads(list< SMESH_subMesh* >& notQuadSubMesh,
396 SMESH_MesherHelper* helper,
397 StdMeshers_Quadrangle_2D* quadAlgo)
400 //SMESHDS_Mesh* mesh = notQuadSubMesh.front()->GetFather()->GetMeshDS();
401 list< SMESH_subMesh* >::iterator smIt = notQuadSubMesh.begin();
402 while ( smIt != notQuadSubMesh.end() )
404 SMESH_subMesh* faceSm = *smIt;
405 SMESHDS_SubMesh* faceSmDS = faceSm->GetSubMeshDS();
406 int nbQuads = faceSmDS ? faceSmDS->NbElements() : 0;
409 toRemove = helper->IsStructured( faceSm );
411 toRemove = quadAlgo->CheckNbEdges( *helper->GetMesh(),
412 faceSm->GetSubShape() );
413 nbRemoved += toRemove;
415 smIt = notQuadSubMesh.erase( smIt );
423 //================================================================================
425 * \brief Return and angle between two EDGEs
426 * \return double - the angle normalized so that
433 //================================================================================
435 // double normAngle(const TopoDS_Edge & E1, const TopoDS_Edge & E2, const TopoDS_Face & F)
437 // return SMESH_MesherHelper::GetAngle( E1, E2, F ) / ( 0.5 * M_PI );
440 //================================================================================
442 * Consider continuous straight EDGES as one side - mark them to unite
444 //================================================================================
446 int countNbSides( const Prism_3D::TPrismTopo & thePrism,
447 vector<int> & nbUnitePerEdge,
448 vector< double > & edgeLength)
450 int nbEdges = thePrism.myNbEdgesInWires.front(); // nb outer edges
451 int nbSides = nbEdges;
454 list< TopoDS_Edge >::const_iterator edgeIt = thePrism.myBottomEdges.begin();
455 std::advance( edgeIt, nbEdges-1 );
456 TopoDS_Edge prevE = *edgeIt;
457 // bool isPrevStraight = SMESH_Algo::IsStraight( prevE );
458 int iPrev = nbEdges - 1;
460 int iUnite = -1; // the first of united EDGEs
462 // analyse angles between EDGEs
464 vector< bool > isCorner( nbEdges );
465 edgeIt = thePrism.myBottomEdges.begin();
466 for ( int iE = 0; iE < nbEdges; ++iE, ++edgeIt )
468 const TopoDS_Edge& curE = *edgeIt;
469 edgeLength[ iE ] = SMESH_Algo::EdgeLength( curE );
471 // double normAngle = normAngle( prevE, curE, thePrism.myBottom );
472 // isCorner[ iE ] = false;
473 // if ( normAngle < 2.0 )
475 // if ( normAngle < 0.001 ) // straight or obtuse angle
477 // // unite EDGEs in order not to put a corner of the unit quadrangle at this VERTEX
480 // nbUnitePerEdge[ iUnite ]++;
481 // nbUnitePerEdge[ iE ] = -1;
486 // isCorner[ iE ] = true;
496 // define which of corners to put on a side of the unit quadrangle
498 // edgeIt = thePrism.myBottomEdges.begin();
499 // for ( int iE = 0; iE < nbEdges; ++iE, ++edgeIt )
501 // const TopoDS_Edge& curE = *edgeIt;
502 // edgeLength[ iE ] = SMESH_Algo::EdgeLength( curE );
504 // const bool isCurStraight = SMESH_Algo::IsStraight( curE );
505 // if ( isPrevStraight && isCurStraight && SMESH_Algo::IsContinuous( prevE, curE ))
509 // nbUnitePerEdge[ iUnite ]++;
510 // nbUnitePerEdge[ iE ] = -1;
518 // isPrevStraight = isCurStraight;
525 void pointsToPython(const std::vector<gp_XYZ>& p)
528 for ( int i = SMESH_Block::ID_V000; i < p.size(); ++i )
530 cout << "mesh.AddNode( " << p[i].X() << ", "<< p[i].Y() << ", "<< p[i].Z() << ") # " << i <<" " ;
531 SMESH_Block::DumpShapeID( i, cout ) << endl;
537 //=======================================================================
538 //function : StdMeshers_Prism_3D
540 //=======================================================================
542 StdMeshers_Prism_3D::StdMeshers_Prism_3D(int hypId, int studyId, SMESH_Gen* gen)
543 :SMESH_3D_Algo(hypId, studyId, gen)
546 _shapeType = (1 << TopAbs_SOLID); // 1 bit per shape type
547 _onlyUnaryInput = false; // mesh all SOLIDs at once
548 _requireDiscreteBoundary = false; // mesh FACEs and EDGEs by myself
549 _supportSubmeshes = true; // "source" FACE must be meshed by other algo
550 _neededLowerHyps[ 1 ] = true; // suppress warning on hiding a global 1D algo
551 _neededLowerHyps[ 2 ] = true; // suppress warning on hiding a global 2D algo
553 //myProjectTriangles = false;
554 mySetErrorToSM = true; // to pass an error to a sub-mesh of a current solid or not
557 //================================================================================
561 //================================================================================
563 StdMeshers_Prism_3D::~StdMeshers_Prism_3D()
566 //=======================================================================
567 //function : CheckHypothesis
569 //=======================================================================
571 bool StdMeshers_Prism_3D::CheckHypothesis(SMESH_Mesh& aMesh,
572 const TopoDS_Shape& aShape,
573 SMESH_Hypothesis::Hypothesis_Status& aStatus)
575 // Check shape geometry
577 aStatus = SMESH_Hypothesis::HYP_BAD_GEOMETRY;
579 // find not quadrangle faces
580 list< TopoDS_Shape > notQuadFaces;
581 int nbEdge, nbWire, nbFace = 0;
582 TopExp_Explorer exp( aShape, TopAbs_FACE );
583 for ( ; exp.More(); exp.Next() ) {
585 const TopoDS_Shape& face = exp.Current();
586 nbEdge = NSProjUtils::Count( face, TopAbs_EDGE, 0 );
587 nbWire = NSProjUtils::Count( face, TopAbs_WIRE, 0 );
588 if ( nbEdge!= 4 || nbWire!= 1 ) {
589 if ( !notQuadFaces.empty() ) {
590 if ( NSProjUtils::Count( notQuadFaces.back(), TopAbs_EDGE, 0 ) != nbEdge ||
591 NSProjUtils::Count( notQuadFaces.back(), TopAbs_WIRE, 0 ) != nbWire )
592 RETURN_BAD_RESULT("Different not quad faces");
594 notQuadFaces.push_back( face );
597 if ( !notQuadFaces.empty() )
599 if ( notQuadFaces.size() != 2 )
600 RETURN_BAD_RESULT("Bad nb not quad faces: " << notQuadFaces.size());
602 // check total nb faces
603 nbEdge = NSProjUtils::Count( notQuadFaces.back(), TopAbs_EDGE, 0 );
604 if ( nbFace != nbEdge + 2 )
605 RETURN_BAD_RESULT("Bad nb of faces: " << nbFace << " but must be " << nbEdge + 2);
609 aStatus = SMESH_Hypothesis::HYP_OK;
613 //=======================================================================
615 //purpose : Compute mesh on a COMPOUND of SOLIDs
616 //=======================================================================
618 bool StdMeshers_Prism_3D::Compute(SMESH_Mesh& theMesh, const TopoDS_Shape& theShape)
620 SMESH_MesherHelper helper( theMesh );
623 int nbSolids = helper.Count( theShape, TopAbs_SOLID, /*skipSame=*/false );
627 TopTools_IndexedDataMapOfShapeListOfShape faceToSolids;
628 TopExp::MapShapesAndAncestors( theShape, TopAbs_FACE, TopAbs_SOLID, faceToSolids );
630 // look for meshed FACEs ("source" FACEs) that must be prism bottoms
631 list< TopoDS_Face > meshedFaces, notQuadMeshedFaces, notQuadFaces;
632 const bool meshHasQuads = ( theMesh.NbQuadrangles() > 0 );
633 //StdMeshers_Quadrangle_2D* quadAlgo = TQuadrangleAlgo::instance( this );
634 for ( int iF = 1; iF <= faceToSolids.Extent(); ++iF )
636 const TopoDS_Face& face = TopoDS::Face( faceToSolids.FindKey( iF ));
637 SMESH_subMesh* faceSM = theMesh.GetSubMesh( face );
638 if ( !faceSM->IsEmpty() )
640 if ( !meshHasQuads ||
641 !helper.IsSameElemGeometry( faceSM->GetSubMeshDS(), SMDSGeom_QUADRANGLE ) ||
642 !helper.IsStructured( faceSM )
644 notQuadMeshedFaces.push_front( face );
645 else if ( myHelper->Count( face, TopAbs_EDGE, /*ignoreSame=*/false ) != 4 )
646 meshedFaces.push_front( face );
648 meshedFaces.push_back( face );
650 // not add not quadrilateral FACE as we can't compute it
651 // else if ( !quadAlgo->CheckNbEdges( theMesh, face ))
652 // // not add not quadrilateral FACE as it can be a prism side
653 // // else if ( myHelper->Count( face, TopAbs_EDGE, /*ignoreSame=*/false ) != 4 )
655 // notQuadFaces.push_back( face );
658 // notQuadFaces are of medium priority, put them before ordinary meshed faces
659 meshedFaces.splice( meshedFaces.begin(), notQuadFaces );
660 // notQuadMeshedFaces are of highest priority, put them before notQuadFaces
661 meshedFaces.splice( meshedFaces.begin(), notQuadMeshedFaces );
663 Prism_3D::TPrismTopo prism;
665 bool selectBottom = meshedFaces.empty();
669 TopoDS_Shape solid = TopExp_Explorer( theShape, TopAbs_SOLID ).Current();
670 if ( !meshedFaces.empty() )
671 prism.myBottom = meshedFaces.front();
672 return ( initPrism( prism, solid, selectBottom ) &&
676 // find propagation chains from already computed EDGEs
677 vector< TopoDS_Edge > computedEdges;
678 getPrecomputedEdges( helper, theShape, computedEdges );
679 myPropagChains = new TopTools_IndexedMapOfShape[ computedEdges.size() + 1 ];
680 SMESHUtils::ArrayDeleter< TopTools_IndexedMapOfShape > pcDel( myPropagChains );
681 for ( size_t i = 0, nb = 0; i < computedEdges.size(); ++i )
683 StdMeshers_ProjectionUtils::GetPropagationEdge( &theMesh, TopoDS_Edge(),
684 computedEdges[i], myPropagChains + nb );
685 if ( myPropagChains[ nb ].Extent() < 2 ) // an empty map is a termination sign
686 myPropagChains[ nb ].Clear();
691 TopTools_MapOfShape meshedSolids;
692 list< Prism_3D::TPrismTopo > meshedPrism;
693 list< TopoDS_Face > suspectSourceFaces;
694 TopTools_ListIteratorOfListOfShape solidIt;
696 while ( meshedSolids.Extent() < nbSolids )
698 if ( _computeCanceled )
699 return toSM( error( SMESH_ComputeError::New(COMPERR_CANCELED)));
701 // compute prisms having avident computed source FACE
702 while ( !meshedFaces.empty() )
704 TopoDS_Face face = meshedFaces.front();
705 meshedFaces.pop_front();
706 TopTools_ListOfShape& solidList = faceToSolids.ChangeFromKey( face );
707 while ( !solidList.IsEmpty() )
709 TopoDS_Shape solid = solidList.First();
710 solidList.RemoveFirst();
711 if ( meshedSolids.Add( solid ))
714 prism.myBottom = face;
715 if ( !initPrism( prism, solid, selectBottom ) ||
719 SMESHDS_SubMesh* smDS = theMesh.GetMeshDS()->MeshElements( prism.myTop );
720 if ( !myHelper->IsSameElemGeometry( smDS, SMDSGeom_QUADRANGLE ))
722 meshedFaces.push_front( prism.myTop );
726 suspectSourceFaces.push_back( prism.myTop );
728 meshedPrism.push_back( prism );
732 if ( meshedSolids.Extent() == nbSolids )
735 // below in the loop we try to find source FACEs somehow
737 // project mesh from source FACEs of computed prisms to
738 // prisms sharing wall FACEs
739 list< Prism_3D::TPrismTopo >::iterator prismIt = meshedPrism.begin();
740 for ( ; prismIt != meshedPrism.end(); ++prismIt )
742 for ( size_t iW = 0; iW < prismIt->myWallQuads.size(); ++iW )
744 Prism_3D::TQuadList::iterator wQuad = prismIt->myWallQuads[iW].begin();
745 for ( ; wQuad != prismIt->myWallQuads[iW].end(); ++ wQuad )
747 const TopoDS_Face& wFace = (*wQuad)->face;
748 TopTools_ListOfShape& solidList = faceToSolids.ChangeFromKey( wFace );
749 solidIt.Initialize( solidList );
750 while ( solidIt.More() )
752 const TopoDS_Shape& solid = solidIt.Value();
753 if ( meshedSolids.Contains( solid )) {
754 solidList.Remove( solidIt );
755 continue; // already computed prism
757 if ( myHelper->IsBlock( solid )) {
759 continue; // too trivial
761 // find a source FACE of the SOLID: it's a FACE sharing a bottom EDGE with wFace
762 const TopoDS_Edge& wEdge = (*wQuad)->side[ QUAD_TOP_SIDE ].grid->Edge(0);
763 PShapeIteratorPtr faceIt = myHelper->GetAncestors( wEdge, *myHelper->GetMesh(),
765 while ( const TopoDS_Shape* f = faceIt->next() )
767 const TopoDS_Face& candidateF = TopoDS::Face( *f );
768 if ( candidateF.IsSame( wFace )) continue;
769 // select a source FACE: prismIt->myBottom or prismIt->myTop
770 TopoDS_Face sourceF = prismIt->myBottom;
771 for ( TopExp_Explorer v( prismIt->myTop, TopAbs_VERTEX ); v.More(); v.Next() )
772 if ( myHelper->IsSubShape( v.Current(), candidateF )) {
773 sourceF = prismIt->myTop;
777 prism.myBottom = candidateF;
778 mySetErrorToSM = false;
779 if ( !myHelper->IsSubShape( candidateF, prismIt->myShape3D ) &&
780 myHelper ->IsSubShape( candidateF, solid ) &&
781 !myHelper->GetMesh()->GetSubMesh( candidateF )->IsMeshComputed() &&
782 initPrism( prism, solid, /*selectBottom=*/false ) &&
783 !myHelper->GetMesh()->GetSubMesh( prism.myTop )->IsMeshComputed() &&
784 !myHelper->GetMesh()->GetSubMesh( prism.myBottom )->IsMeshComputed() &&
785 project2dMesh( sourceF, prism.myBottom ))
787 mySetErrorToSM = true;
788 if ( !compute( prism ))
790 SMESHDS_SubMesh* smDS = theMesh.GetMeshDS()->MeshElements( prism.myTop );
791 if ( !myHelper->IsSameElemGeometry( smDS, SMDSGeom_QUADRANGLE ))
793 meshedFaces.push_front( prism.myTop );
794 meshedFaces.push_front( prism.myBottom );
795 selectBottom = false;
797 meshedPrism.push_back( prism );
798 meshedSolids.Add( solid );
802 mySetErrorToSM = true;
804 if ( meshedSolids.Contains( solid ))
805 solidList.Remove( solidIt );
811 if ( !meshedFaces.empty() )
812 break; // to compute prisms with avident sources
815 if ( meshedFaces.empty() )
817 meshedFaces.splice( meshedFaces.end(), suspectSourceFaces );
821 // find FACEs with local 1D hyps, which has to be computed by now,
822 // or at least any computed FACEs
823 if ( meshedFaces.empty() )
826 for ( int iF = 1; iF <= faceToSolids.Extent(); ++iF )
828 const TopoDS_Face& face = TopoDS::Face( faceToSolids.FindKey( iF ));
829 const TopTools_ListOfShape& solidList = faceToSolids.FindFromKey( face );
830 if ( solidList.IsEmpty() ) continue;
831 SMESH_subMesh* faceSM = theMesh.GetSubMesh( face );
832 if ( !faceSM->IsEmpty() )
834 int nbFaces = faceSM->GetSubMeshDS()->NbElements();
835 if ( prevNbFaces < nbFaces )
837 if ( !meshedFaces.empty() ) meshedFaces.pop_back();
838 meshedFaces.push_back( face ); // lower priority
840 prevNbFaces = nbFaces;
845 bool allSubMeComputed = true;
846 SMESH_subMeshIteratorPtr smIt = faceSM->getDependsOnIterator(false,true);
847 while ( smIt->more() && allSubMeComputed )
848 allSubMeComputed = smIt->next()->IsMeshComputed();
849 if ( allSubMeComputed )
851 faceSM->ComputeStateEngine( SMESH_subMesh::COMPUTE );
852 if ( !faceSM->IsEmpty() ) {
853 meshedFaces.push_front( face ); // higher priority
858 faceSM->ComputeStateEngine( SMESH_subMesh::CHECK_COMPUTE_STATE );
866 // TODO. there are other ways to find out the source FACE:
867 // propagation, topological similarity, ect.
869 // simply try to mesh all not meshed SOLIDs
870 if ( meshedFaces.empty() )
872 for ( TopExp_Explorer solid( theShape, TopAbs_SOLID ); solid.More(); solid.Next() )
874 mySetErrorToSM = false;
876 if ( !meshedSolids.Contains( solid.Current() ) &&
877 initPrism( prism, solid.Current() ))
879 mySetErrorToSM = true;
880 if ( !compute( prism ))
882 meshedFaces.push_front( prism.myTop );
883 meshedFaces.push_front( prism.myBottom );
884 meshedPrism.push_back( prism );
885 meshedSolids.Add( solid.Current() );
888 mySetErrorToSM = true;
892 if ( meshedFaces.empty() ) // set same error to 10 not-computed solids
894 SMESH_ComputeErrorPtr err = SMESH_ComputeError::New
895 ( COMPERR_BAD_INPUT_MESH, "No meshed source face found", this );
897 const int maxNbErrors = 10; // limit nb errors not to overload the Compute dialog
898 TopExp_Explorer solid( theShape, TopAbs_SOLID );
899 for ( int i = 0; ( i < maxNbErrors && solid.More() ); ++i, solid.Next() )
900 if ( !meshedSolids.Contains( solid.Current() ))
902 SMESH_subMesh* sm = theMesh.GetSubMesh( solid.Current() );
903 sm->GetComputeError() = err;
911 //================================================================================
913 * \brief Find wall faces by bottom edges
915 //================================================================================
917 bool StdMeshers_Prism_3D::getWallFaces( Prism_3D::TPrismTopo & thePrism,
918 const int totalNbFaces)
920 thePrism.myWallQuads.clear();
922 SMESH_Mesh* mesh = myHelper->GetMesh();
924 StdMeshers_Quadrangle_2D* quadAlgo = TQuadrangleAlgo::instance( this, myHelper );
926 TopTools_MapOfShape faceMap;
927 TopTools_IndexedDataMapOfShapeListOfShape edgeToFaces;
928 TopExp::MapShapesAndAncestors( thePrism.myShape3D,
929 TopAbs_EDGE, TopAbs_FACE, edgeToFaces );
931 // ------------------------------
932 // Get the 1st row of wall FACEs
933 // ------------------------------
935 list< TopoDS_Edge >::iterator edge = thePrism.myBottomEdges.begin();
936 std::list< int >::iterator nbE = thePrism.myNbEdgesInWires.begin();
939 while ( edge != thePrism.myBottomEdges.end() )
942 if ( BRep_Tool::Curve( *edge, f,l ).IsNull() )
944 edge = thePrism.myBottomEdges.erase( edge );
950 TopTools_ListIteratorOfListOfShape faceIt( edgeToFaces.FindFromKey( *edge ));
951 for ( ; faceIt.More(); faceIt.Next() )
953 const TopoDS_Face& face = TopoDS::Face( faceIt.Value() );
954 if ( !thePrism.myBottom.IsSame( face ))
956 Prism_3D::TQuadList quadList( 1, quadAlgo->CheckNbEdges( *mesh, face ));
957 if ( !quadList.back() )
958 return toSM( error(TCom("Side face #") << shapeID( face )
959 << " not meshable with quadrangles"));
960 bool isCompositeBase = ! setBottomEdge( *edge, quadList.back(), face );
961 if ( isCompositeBase )
963 // it's OK if all EDGEs of the bottom side belongs to the bottom FACE
964 StdMeshers_FaceSidePtr botSide = quadList.back()->side[ QUAD_BOTTOM_SIDE ];
965 for ( int iE = 0; iE < botSide->NbEdges(); ++iE )
966 if ( !myHelper->IsSubShape( botSide->Edge(iE), thePrism.myBottom ))
967 return toSM( error(TCom("Composite 'horizontal' edges are not supported")));
969 if ( faceMap.Add( face ))
970 thePrism.myWallQuads.push_back( quadList );
983 // -------------------------
984 // Find the rest wall FACEs
985 // -------------------------
987 // Compose a vector of indixes of right neighbour FACE for each wall FACE
988 // that is not so evident in case of several WIREs in the bottom FACE
989 thePrism.myRightQuadIndex.clear();
990 for ( size_t i = 0; i < thePrism.myWallQuads.size(); ++i )
991 thePrism.myRightQuadIndex.push_back( i+1 );
992 list< int >::iterator nbEinW = thePrism.myNbEdgesInWires.begin();
993 for ( int iLeft = 0; nbEinW != thePrism.myNbEdgesInWires.end(); ++nbEinW )
995 thePrism.myRightQuadIndex[ iLeft + *nbEinW - 1 ] = iLeft; // 1st EDGE index of a current WIRE
999 while ( totalNbFaces - faceMap.Extent() > 2 )
1001 // find wall FACEs adjacent to each of wallQuads by the right side EDGE
1004 nbKnownFaces = faceMap.Extent();
1005 StdMeshers_FaceSidePtr rightSide, topSide; // sides of the quad
1006 for ( size_t i = 0; i < thePrism.myWallQuads.size(); ++i )
1008 rightSide = thePrism.myWallQuads[i].back()->side[ QUAD_RIGHT_SIDE ];
1009 for ( int iE = 0; iE < rightSide->NbEdges(); ++iE ) // rightSide can be composite
1011 const TopoDS_Edge & rightE = rightSide->Edge( iE );
1012 TopTools_ListIteratorOfListOfShape face( edgeToFaces.FindFromKey( rightE ));
1013 for ( ; face.More(); face.Next() )
1014 if ( faceMap.Add( face.Value() ))
1016 // a new wall FACE encountered, store it in thePrism.myWallQuads
1017 const int iRight = thePrism.myRightQuadIndex[i];
1018 topSide = thePrism.myWallQuads[ iRight ].back()->side[ QUAD_TOP_SIDE ];
1019 const TopoDS_Edge& newBotE = topSide->Edge(0);
1020 const TopoDS_Shape& newWallF = face.Value();
1021 thePrism.myWallQuads[ iRight ].push_back( quadAlgo->CheckNbEdges( *mesh, newWallF ));
1022 if ( !thePrism.myWallQuads[ iRight ].back() )
1023 return toSM( error(TCom("Side face #") << shapeID( newWallF ) <<
1024 " not meshable with quadrangles"));
1025 if ( ! setBottomEdge( newBotE, thePrism.myWallQuads[ iRight ].back(), newWallF ))
1026 return toSM( error(TCom("Composite 'horizontal' edges are not supported")));
1030 } while ( nbKnownFaces != faceMap.Extent() );
1032 // find wall FACEs adjacent to each of thePrism.myWallQuads by the top side EDGE
1033 if ( totalNbFaces - faceMap.Extent() > 2 )
1035 const int nbFoundWalls = faceMap.Extent();
1036 for ( size_t i = 0; i < thePrism.myWallQuads.size(); ++i )
1038 StdMeshers_FaceSidePtr topSide = thePrism.myWallQuads[i].back()->side[ QUAD_TOP_SIDE ];
1039 const TopoDS_Edge & topE = topSide->Edge( 0 );
1040 if ( topSide->NbEdges() > 1 )
1041 return toSM( error(COMPERR_BAD_SHAPE, TCom("Side face #") <<
1042 shapeID( thePrism.myWallQuads[i].back()->face )
1043 << " has a composite top edge"));
1044 TopTools_ListIteratorOfListOfShape faceIt( edgeToFaces.FindFromKey( topE ));
1045 for ( ; faceIt.More(); faceIt.Next() )
1046 if ( faceMap.Add( faceIt.Value() ))
1048 // a new wall FACE encountered, store it in wallQuads
1049 thePrism.myWallQuads[ i ].push_back( quadAlgo->CheckNbEdges( *mesh, faceIt.Value() ));
1050 if ( !thePrism.myWallQuads[ i ].back() )
1051 return toSM( error(TCom("Side face #") << shapeID( faceIt.Value() ) <<
1052 " not meshable with quadrangles"));
1053 if ( ! setBottomEdge( topE, thePrism.myWallQuads[ i ].back(), faceIt.Value() ))
1054 return toSM( error(TCom("Composite 'horizontal' edges are not supported")));
1055 if ( totalNbFaces - faceMap.Extent() == 2 )
1057 i = thePrism.myWallQuads.size(); // to quit from the outer loop
1062 if ( nbFoundWalls == faceMap.Extent() )
1063 return toSM( error("Failed to find wall faces"));
1066 } // while ( totalNbFaces - faceMap.Extent() > 2 )
1068 // ------------------
1069 // Find the top FACE
1070 // ------------------
1072 if ( thePrism.myTop.IsNull() )
1074 // now only top and bottom FACEs are not in the faceMap
1075 faceMap.Add( thePrism.myBottom );
1076 for ( TopExp_Explorer f( thePrism.myShape3D, TopAbs_FACE );f.More(); f.Next() )
1077 if ( !faceMap.Contains( f.Current() )) {
1078 thePrism.myTop = TopoDS::Face( f.Current() );
1081 if ( thePrism.myTop.IsNull() )
1082 return toSM( error("Top face not found"));
1085 // Check that the top FACE shares all the top EDGEs
1086 for ( size_t i = 0; i < thePrism.myWallQuads.size(); ++i )
1088 StdMeshers_FaceSidePtr topSide = thePrism.myWallQuads[i].back()->side[ QUAD_TOP_SIDE ];
1089 const TopoDS_Edge & topE = topSide->Edge( 0 );
1090 if ( !myHelper->IsSubShape( topE, thePrism.myTop ))
1091 return toSM( error( TCom("Wrong source face: #") << shapeID( thePrism.myBottom )));
1097 //=======================================================================
1098 //function : compute
1099 //purpose : Compute mesh on a SOLID
1100 //=======================================================================
1102 bool StdMeshers_Prism_3D::compute(const Prism_3D::TPrismTopo& thePrism)
1104 myHelper->IsQuadraticSubMesh( thePrism.myShape3D );
1105 if ( _computeCanceled )
1106 return toSM( error( SMESH_ComputeError::New(COMPERR_CANCELED)));
1108 // Assure the bottom is meshed
1109 SMESH_subMesh * botSM = myHelper->GetMesh()->GetSubMesh( thePrism.myBottom );
1110 if (( botSM->IsEmpty() ) &&
1111 ( ! botSM->GetAlgo() ||
1112 ! _gen->Compute( *botSM->GetFather(), botSM->GetSubShape(), /*shapeOnly=*/true )))
1113 return error( COMPERR_BAD_INPUT_MESH,
1114 TCom( "No mesher defined to compute the face #")
1115 << shapeID( thePrism.myBottom ));
1117 // Make all side FACEs of thePrism meshed with quads
1118 if ( !computeWalls( thePrism ))
1121 // Analyse mesh and geometry to find all block sub-shapes and submeshes
1122 // (after fixing IPAL52499 myBlock is used as a holder of boundary nodes
1123 // and for 2D projection in hard cases where StdMeshers_Projection_2D fails;
1124 // location of internal nodes is usually computed by StdMeshers_Sweeper)
1125 if ( !myBlock.Init( myHelper, thePrism ))
1126 return toSM( error( myBlock.GetError()));
1128 SMESHDS_Mesh* meshDS = myHelper->GetMeshDS();
1130 int volumeID = meshDS->ShapeToIndex( thePrism.myShape3D );
1132 // Try to get gp_Trsf to get all nodes from bottom ones
1133 vector<gp_Trsf> trsf;
1134 gp_Trsf bottomToTopTrsf;
1135 // if ( !myBlock.GetLayersTransformation( trsf, thePrism ))
1137 // else if ( !trsf.empty() )
1138 // bottomToTopTrsf = trsf.back();
1140 // To compute coordinates of a node inside a block, it is necessary to know
1141 // 1. normalized parameters of the node by which
1142 // 2. coordinates of node projections on all block sub-shapes are computed
1144 // So we fill projections on vertices at once as they are same for all nodes
1145 myShapeXYZ.resize( myBlock.NbSubShapes() );
1146 for ( int iV = SMESH_Block::ID_FirstV; iV < SMESH_Block::ID_FirstE; ++iV ) {
1147 myBlock.VertexPoint( iV, myShapeXYZ[ iV ]);
1148 SHOWYXZ("V point " <<iV << " ", myShapeXYZ[ iV ]);
1151 // Projections on the top and bottom faces are taken from nodes existing
1152 // on these faces; find correspondence between bottom and top nodes
1154 myBotToColumnMap.clear();
1155 if ( !assocOrProjBottom2Top( bottomToTopTrsf, thePrism ) ) // it also fills myBotToColumnMap
1159 // Create nodes inside the block
1161 // use transformation (issue 0020680, IPAL0052499)
1162 StdMeshers_Sweeper sweeper;
1164 bool allowHighBndError;
1168 // load boundary nodes into sweeper
1170 list< TopoDS_Edge >::const_iterator edge = thePrism.myBottomEdges.begin();
1171 for ( ; edge != thePrism.myBottomEdges.end(); ++edge )
1173 int edgeID = meshDS->ShapeToIndex( *edge );
1174 TParam2ColumnMap* u2col = const_cast<TParam2ColumnMap*>
1175 ( myBlock.GetParam2ColumnMap( edgeID, dummy ));
1176 TParam2ColumnMap::iterator u2colIt = u2col->begin();
1177 for ( ; u2colIt != u2col->end(); ++u2colIt )
1178 sweeper.myBndColumns.push_back( & u2colIt->second );
1180 // load node columns inside the bottom face
1181 TNode2ColumnMap::iterator bot_column = myBotToColumnMap.begin();
1182 for ( ; bot_column != myBotToColumnMap.end(); ++bot_column )
1183 sweeper.myIntColumns.push_back( & bot_column->second );
1185 tol = getSweepTolerance( thePrism );
1186 allowHighBndError = !isSimpleBottom( thePrism );
1189 if ( !myUseBlock && sweeper.ComputeNodes( *myHelper, tol, allowHighBndError ))
1192 else // use block approach
1194 // loop on nodes inside the bottom face
1195 Prism_3D::TNode prevBNode;
1196 TNode2ColumnMap::iterator bot_column = myBotToColumnMap.begin();
1197 for ( ; bot_column != myBotToColumnMap.end(); ++bot_column )
1199 const Prism_3D::TNode& tBotNode = bot_column->first; // bottom TNode
1200 if ( tBotNode.GetPositionType() != SMDS_TOP_FACE )
1201 continue; // node is not inside the FACE
1203 // column nodes; middle part of the column are zero pointers
1204 TNodeColumn& column = bot_column->second;
1206 gp_XYZ botParams, topParams;
1207 if ( !tBotNode.HasParams() )
1209 // compute bottom node parameters
1210 gp_XYZ paramHint(-1,-1,-1);
1211 if ( prevBNode.IsNeighbor( tBotNode ))
1212 paramHint = prevBNode.GetParams();
1213 if ( !myBlock.ComputeParameters( tBotNode.GetCoords(), tBotNode.ChangeParams(),
1214 ID_BOT_FACE, paramHint ))
1215 return toSM( error(TCom("Can't compute normalized parameters for node ")
1216 << tBotNode.myNode->GetID() << " on the face #"
1217 << myBlock.SubMesh( ID_BOT_FACE )->GetId() ));
1218 prevBNode = tBotNode;
1220 botParams = topParams = tBotNode.GetParams();
1221 topParams.SetZ( 1 );
1223 // compute top node parameters
1224 if ( column.size() > 2 ) {
1225 gp_Pnt topCoords = gpXYZ( column.back() );
1226 if ( !myBlock.ComputeParameters( topCoords, topParams, ID_TOP_FACE, topParams ))
1227 return toSM( error(TCom("Can't compute normalized parameters ")
1228 << "for node " << column.back()->GetID()
1229 << " on the face #"<< column.back()->getshapeId() ));
1232 else // top nodes are created by projection using parameters
1234 botParams = topParams = tBotNode.GetParams();
1235 topParams.SetZ( 1 );
1238 myShapeXYZ[ ID_BOT_FACE ] = tBotNode.GetCoords();
1239 myShapeXYZ[ ID_TOP_FACE ] = gpXYZ( column.back() );
1242 TNodeColumn::iterator columnNodes = column.begin();
1243 for ( int z = 0; columnNodes != column.end(); ++columnNodes, ++z)
1245 const SMDS_MeshNode* & node = *columnNodes;
1246 if ( node ) continue; // skip bottom or top node
1248 // params of a node to create
1249 double rz = (double) z / (double) ( column.size() - 1 );
1250 gp_XYZ params = botParams * ( 1 - rz ) + topParams * rz;
1252 // set coords on all faces and nodes
1253 const int nbSideFaces = 4;
1254 int sideFaceIDs[nbSideFaces] = { SMESH_Block::ID_Fx0z,
1255 SMESH_Block::ID_Fx1z,
1256 SMESH_Block::ID_F0yz,
1257 SMESH_Block::ID_F1yz };
1258 for ( int iF = 0; iF < nbSideFaces; ++iF )
1259 if ( !setFaceAndEdgesXYZ( sideFaceIDs[ iF ], params, z ))
1262 // compute coords for a new node
1264 if ( !SMESH_Block::ShellPoint( params, myShapeXYZ, coords ))
1265 return toSM( error("Can't compute coordinates by normalized parameters"));
1267 // if ( !meshDS->MeshElements( volumeID ) ||
1268 // meshDS->MeshElements( volumeID )->NbNodes() == 0 )
1269 // pointsToPython(myShapeXYZ);
1270 SHOWYXZ("TOPFacePoint ",myShapeXYZ[ ID_TOP_FACE]);
1271 SHOWYXZ("BOT Node "<< tBotNode.myNode->GetID(),gpXYZ(tBotNode.myNode));
1272 SHOWYXZ("ShellPoint ",coords);
1275 node = meshDS->AddNode( coords.X(), coords.Y(), coords.Z() );
1276 meshDS->SetNodeInVolume( node, volumeID );
1278 if ( _computeCanceled )
1281 } // loop on bottom nodes
1286 SMESHDS_SubMesh* smDS = myBlock.SubMeshDS( ID_BOT_FACE );
1287 if ( !smDS ) return toSM( error(COMPERR_BAD_INPUT_MESH, "Null submesh"));
1289 // loop on bottom mesh faces
1290 SMDS_ElemIteratorPtr faceIt = smDS->GetElements();
1291 while ( faceIt->more() )
1293 const SMDS_MeshElement* face = faceIt->next();
1294 if ( !face || face->GetType() != SMDSAbs_Face )
1297 // find node columns for each node
1298 int nbNodes = face->NbCornerNodes();
1299 vector< const TNodeColumn* > columns( nbNodes );
1300 for ( int i = 0; i < nbNodes; ++i )
1302 const SMDS_MeshNode* n = face->GetNode( i );
1303 if ( n->GetPosition()->GetTypeOfPosition() == SMDS_TOP_FACE ) {
1304 TNode2ColumnMap::iterator bot_column = myBotToColumnMap.find( n );
1305 if ( bot_column == myBotToColumnMap.end() )
1306 return toSM( error(TCom("No nodes found above node ") << n->GetID() ));
1307 columns[ i ] = & bot_column->second;
1310 columns[ i ] = myBlock.GetNodeColumn( n );
1311 if ( !columns[ i ] )
1312 return toSM( error(TCom("No side nodes found above node ") << n->GetID() ));
1316 AddPrisms( columns, myHelper );
1318 } // loop on bottom mesh faces
1321 myBotToColumnMap.clear();
1327 //=======================================================================
1328 //function : computeWalls
1329 //purpose : Compute 2D mesh on walls FACEs of a prism
1330 //=======================================================================
1332 bool StdMeshers_Prism_3D::computeWalls(const Prism_3D::TPrismTopo& thePrism)
1334 SMESH_Mesh* mesh = myHelper->GetMesh();
1335 SMESHDS_Mesh* meshDS = myHelper->GetMeshDS();
1336 DBGOUT( endl << "COMPUTE Prism " << meshDS->ShapeToIndex( thePrism.myShape3D ));
1338 TProjction1dAlgo* projector1D = TProjction1dAlgo::instance( this );
1339 StdMeshers_Quadrangle_2D* quadAlgo = TQuadrangleAlgo::instance( this, myHelper );
1341 // SMESH_HypoFilter hyp1dFilter( SMESH_HypoFilter::IsAlgo(),/*not=*/true);
1342 // hyp1dFilter.And( SMESH_HypoFilter::HasDim( 1 ));
1343 // hyp1dFilter.And( SMESH_HypoFilter::IsMoreLocalThan( thePrism.myShape3D, *mesh ));
1345 // Discretize equally 'vertical' EDGEs
1346 // -----------------------------------
1347 // find source FACE sides for projection: either already computed ones or
1348 // the 'most composite' ones
1349 const size_t nbWalls = thePrism.myWallQuads.size();
1350 vector< int > wgt( nbWalls, 0 ); // "weight" of a wall
1351 for ( size_t iW = 0; iW != nbWalls; ++iW )
1353 Prism_3D::TQuadList::const_iterator quad = thePrism.myWallQuads[iW].begin();
1354 for ( ; quad != thePrism.myWallQuads[iW].end(); ++quad )
1356 StdMeshers_FaceSidePtr lftSide = (*quad)->side[ QUAD_LEFT_SIDE ];
1357 for ( int i = 0; i < lftSide->NbEdges(); ++i )
1360 const TopoDS_Edge& E = lftSide->Edge(i);
1361 if ( mesh->GetSubMesh( E )->IsMeshComputed() )
1364 wgt[ myHelper->WrapIndex( iW+1, nbWalls)] += 10;
1365 wgt[ myHelper->WrapIndex( iW-1, nbWalls)] += 10;
1367 // else if ( mesh->GetHypothesis( E, hyp1dFilter, true )) // local hypothesis!
1371 // in quadratic mesh, pass ignoreMediumNodes to quad sides
1372 if ( myHelper->GetIsQuadratic() )
1374 quad = thePrism.myWallQuads[iW].begin();
1375 for ( ; quad != thePrism.myWallQuads[iW].end(); ++quad )
1376 for ( int i = 0; i < NB_QUAD_SIDES; ++i )
1377 (*quad)->side[ i ].grid->SetIgnoreMediumNodes( true );
1380 multimap< int, int > wgt2quad;
1381 for ( size_t iW = 0; iW != nbWalls; ++iW )
1382 wgt2quad.insert( make_pair( wgt[ iW ], iW ));
1384 // Project 'vertical' EDGEs, from left to right
1385 multimap< int, int >::reverse_iterator w2q = wgt2quad.rbegin();
1386 for ( ; w2q != wgt2quad.rend(); ++w2q )
1388 const int iW = w2q->second;
1389 const Prism_3D::TQuadList& quads = thePrism.myWallQuads[ iW ];
1390 Prism_3D::TQuadList::const_iterator quad = quads.begin();
1391 for ( ; quad != quads.end(); ++quad )
1393 StdMeshers_FaceSidePtr rgtSide = (*quad)->side[ QUAD_RIGHT_SIDE ]; // tgt
1394 StdMeshers_FaceSidePtr lftSide = (*quad)->side[ QUAD_LEFT_SIDE ]; // src
1395 bool swapLeftRight = ( lftSide->NbSegments( /*update=*/true ) == 0 &&
1396 rgtSide->NbSegments( /*update=*/true ) > 0 );
1397 if ( swapLeftRight )
1398 std::swap( lftSide, rgtSide );
1400 // assure that all the source (left) EDGEs are meshed
1401 int nbSrcSegments = 0;
1402 for ( int i = 0; i < lftSide->NbEdges(); ++i )
1404 const TopoDS_Edge& srcE = lftSide->Edge(i);
1405 SMESH_subMesh* srcSM = mesh->GetSubMesh( srcE );
1406 if ( !srcSM->IsMeshComputed() ) {
1407 DBGOUT( "COMPUTE V edge " << srcSM->GetId() );
1408 TopoDS_Edge prpgSrcE = findPropagationSource( srcE );
1409 if ( !prpgSrcE.IsNull() ) {
1410 srcSM->ComputeSubMeshStateEngine( SMESH_subMesh::COMPUTE );
1411 projector1D->myHyp.SetSourceEdge( prpgSrcE );
1412 projector1D->Compute( *mesh, srcE );
1413 srcSM->ComputeStateEngine( SMESH_subMesh::CHECK_COMPUTE_STATE );
1416 srcSM->ComputeSubMeshStateEngine( SMESH_subMesh::COMPUTE );
1417 srcSM->ComputeStateEngine ( SMESH_subMesh::COMPUTE );
1419 if ( !srcSM->IsMeshComputed() )
1420 return toSM( error( "Can't compute 1D mesh" ));
1422 nbSrcSegments += srcSM->GetSubMeshDS()->NbElements();
1424 // check target EDGEs
1425 int nbTgtMeshed = 0, nbTgtSegments = 0;
1426 vector< bool > isTgtEdgeComputed( rgtSide->NbEdges() );
1427 for ( int i = 0; i < rgtSide->NbEdges(); ++i )
1429 const TopoDS_Edge& tgtE = rgtSide->Edge(i);
1430 SMESH_subMesh* tgtSM = mesh->GetSubMesh( tgtE );
1431 if ( !( isTgtEdgeComputed[ i ] = tgtSM->IsMeshComputed() )) {
1432 tgtSM->ComputeSubMeshStateEngine( SMESH_subMesh::COMPUTE );
1433 tgtSM->ComputeStateEngine ( SMESH_subMesh::COMPUTE );
1435 if ( tgtSM->IsMeshComputed() ) {
1437 nbTgtSegments += tgtSM->GetSubMeshDS()->NbElements();
1440 if ( rgtSide->NbEdges() == nbTgtMeshed ) // all tgt EDGEs meshed
1442 if ( nbTgtSegments != nbSrcSegments )
1444 bool badMeshRemoved = false;
1445 // remove just computed segments
1446 for ( int i = 0; i < rgtSide->NbEdges(); ++i )
1447 if ( !isTgtEdgeComputed[ i ])
1449 const TopoDS_Edge& tgtE = rgtSide->Edge(i);
1450 SMESH_subMesh* tgtSM = mesh->GetSubMesh( tgtE );
1451 tgtSM->ComputeStateEngine( SMESH_subMesh::CLEAN );
1452 badMeshRemoved = true;
1455 if ( !badMeshRemoved )
1457 for ( int i = 0; i < lftSide->NbEdges(); ++i )
1458 addBadInputElements( meshDS->MeshElements( lftSide->Edge( i )));
1459 for ( int i = 0; i < rgtSide->NbEdges(); ++i )
1460 addBadInputElements( meshDS->MeshElements( rgtSide->Edge( i )));
1461 return toSM( error( TCom("Different nb of segment on logically vertical edges #")
1462 << shapeID( lftSide->Edge(0) ) << " and #"
1463 << shapeID( rgtSide->Edge(0) ) << ": "
1464 << nbSrcSegments << " != " << nbTgtSegments ));
1467 else // if ( nbTgtSegments == nbSrcSegments )
1472 // Compute 'vertical projection'
1473 if ( nbTgtMeshed == 0 )
1475 // compute nodes on target VERTEXes
1476 const UVPtStructVec& srcNodeStr = lftSide->GetUVPtStruct();
1477 if ( srcNodeStr.size() == 0 )
1478 return toSM( error( TCom("Invalid node positions on edge #") <<
1479 shapeID( lftSide->Edge(0) )));
1480 vector< SMDS_MeshNode* > newNodes( srcNodeStr.size() );
1481 for ( int is2ndV = 0; is2ndV < 2; ++is2ndV )
1483 const TopoDS_Edge& E = rgtSide->Edge( is2ndV ? rgtSide->NbEdges()-1 : 0 );
1484 TopoDS_Vertex v = myHelper->IthVertex( is2ndV, E );
1485 mesh->GetSubMesh( v )->ComputeStateEngine( SMESH_subMesh::COMPUTE );
1486 const SMDS_MeshNode* n = SMESH_Algo::VertexNode( v, meshDS );
1487 newNodes[ is2ndV ? 0 : newNodes.size()-1 ] = (SMDS_MeshNode*) n;
1490 // compute nodes on target EDGEs
1491 DBGOUT( "COMPUTE V edge (proj) " << shapeID( lftSide->Edge(0)));
1492 rgtSide->Reverse(); // direct it same as the lftSide
1493 myHelper->SetElementsOnShape( false ); // myHelper holds the prism shape
1494 TopoDS_Edge tgtEdge;
1495 for ( size_t iN = 1; iN < srcNodeStr.size()-1; ++iN ) // add nodes
1497 gp_Pnt p = rgtSide->Value3d ( srcNodeStr[ iN ].normParam );
1498 double u = rgtSide->Parameter( srcNodeStr[ iN ].normParam, tgtEdge );
1499 newNodes[ iN ] = meshDS->AddNode( p.X(), p.Y(), p.Z() );
1500 meshDS->SetNodeOnEdge( newNodes[ iN ], tgtEdge, u );
1502 for ( size_t iN = 1; iN < srcNodeStr.size(); ++iN ) // add segments
1504 // find an EDGE to set a new segment
1505 std::pair<int, TopAbs_ShapeEnum> id2type =
1506 myHelper->GetMediumPos( newNodes[ iN-1 ], newNodes[ iN ] );
1507 if ( id2type.second != TopAbs_EDGE )
1509 // new nodes are on different EDGEs; put one of them on VERTEX
1510 const int edgeIndex = rgtSide->EdgeIndex( srcNodeStr[ iN-1 ].normParam );
1511 const double vertexParam = rgtSide->LastParameter( edgeIndex );
1512 TopoDS_Vertex vertex = rgtSide->LastVertex( edgeIndex );
1513 const SMDS_MeshNode* vn = SMESH_Algo::VertexNode( vertex, meshDS );
1514 const gp_Pnt p = BRep_Tool::Pnt( vertex );
1515 const int isPrev = ( Abs( srcNodeStr[ iN-1 ].normParam - vertexParam ) <
1516 Abs( srcNodeStr[ iN ].normParam - vertexParam ));
1517 meshDS->UnSetNodeOnShape( newNodes[ iN-isPrev ] );
1518 meshDS->SetNodeOnVertex ( newNodes[ iN-isPrev ], vertex );
1519 meshDS->MoveNode ( newNodes[ iN-isPrev ], p.X(), p.Y(), p.Z() );
1520 id2type.first = newNodes[ iN-(1-isPrev) ]->getshapeId();
1523 SMESH_MeshEditor::TListOfListOfNodes lln( 1, list< const SMDS_MeshNode* >() );
1524 lln.back().push_back ( vn );
1525 lln.back().push_front( newNodes[ iN-isPrev ] ); // to keep
1526 SMESH_MeshEditor( mesh ).MergeNodes( lln );
1529 SMDS_MeshElement* newEdge = myHelper->AddEdge( newNodes[ iN-1 ], newNodes[ iN ] );
1530 meshDS->SetMeshElementOnShape( newEdge, id2type.first );
1532 myHelper->SetElementsOnShape( true );
1533 for ( int i = 0; i < rgtSide->NbEdges(); ++i ) // update state of sub-meshes
1535 const TopoDS_Edge& E = rgtSide->Edge( i );
1536 SMESH_subMesh* tgtSM = mesh->GetSubMesh( E );
1537 tgtSM->ComputeStateEngine( SMESH_subMesh::CHECK_COMPUTE_STATE );
1540 // to continue projection from the just computed side as a source
1541 if ( !swapLeftRight && rgtSide->NbEdges() > 1 && w2q->second == iW )
1543 std::pair<int,int> wgt2quadKeyVal( w2q->first + 1, thePrism.myRightQuadIndex[ iW ]);
1544 wgt2quad.insert( wgt2quadKeyVal ); // it will be skipped by ++w2q
1545 wgt2quad.insert( wgt2quadKeyVal );
1546 w2q = wgt2quad.rbegin();
1551 // HOPE assigned hypotheses are OK, so that equal nb of segments will be generated
1552 //return toSM( error("Partial projection not implemented"));
1554 } // loop on quads of a composite wall side
1555 } // loop on the ordered wall sides
1559 for ( size_t iW = 0; iW != thePrism.myWallQuads.size(); ++iW )
1561 Prism_3D::TQuadList::const_iterator quad = thePrism.myWallQuads[iW].begin();
1562 for ( ; quad != thePrism.myWallQuads[iW].end(); ++quad )
1564 const TopoDS_Face& face = (*quad)->face;
1565 SMESH_subMesh* fSM = mesh->GetSubMesh( face );
1566 if ( ! fSM->IsMeshComputed() )
1568 // Top EDGEs must be projections from the bottom ones
1569 // to compute stuctured quad mesh on wall FACEs
1570 // ---------------------------------------------------
1571 const TopoDS_Edge& botE = (*quad)->side[ QUAD_BOTTOM_SIDE ].grid->Edge(0);
1572 const TopoDS_Edge& topE = (*quad)->side[ QUAD_TOP_SIDE ].grid->Edge(0);
1573 SMESH_subMesh* botSM = mesh->GetSubMesh( botE );
1574 SMESH_subMesh* topSM = mesh->GetSubMesh( topE );
1575 SMESH_subMesh* srcSM = botSM;
1576 SMESH_subMesh* tgtSM = topSM;
1577 srcSM->ComputeStateEngine( SMESH_subMesh::CHECK_COMPUTE_STATE );
1578 tgtSM->ComputeStateEngine( SMESH_subMesh::CHECK_COMPUTE_STATE );
1579 if ( !srcSM->IsMeshComputed() && tgtSM->IsMeshComputed() )
1580 std::swap( srcSM, tgtSM );
1582 if ( !srcSM->IsMeshComputed() )
1584 DBGOUT( "COMPUTE H edge " << srcSM->GetId());
1585 srcSM->ComputeSubMeshStateEngine( SMESH_subMesh::COMPUTE ); // nodes on VERTEXes
1586 srcSM->ComputeStateEngine( SMESH_subMesh::COMPUTE ); // segments on the EDGE
1589 if ( tgtSM->IsMeshComputed() &&
1590 tgtSM->GetSubMeshDS()->NbNodes() != srcSM->GetSubMeshDS()->NbNodes() )
1592 // the top EDGE is computed differently than the bottom one,
1593 // try to clear a wrong mesh
1594 bool isAdjFaceMeshed = false;
1595 PShapeIteratorPtr fIt = myHelper->GetAncestors( tgtSM->GetSubShape(),
1596 *mesh, TopAbs_FACE );
1597 while ( const TopoDS_Shape* f = fIt->next() )
1598 if (( isAdjFaceMeshed = mesh->GetSubMesh( *f )->IsMeshComputed() ))
1600 if ( isAdjFaceMeshed )
1601 return toSM( error( TCom("Different nb of segment on logically horizontal edges #")
1602 << shapeID( botE ) << " and #"
1603 << shapeID( topE ) << ": "
1604 << tgtSM->GetSubMeshDS()->NbElements() << " != "
1605 << srcSM->GetSubMeshDS()->NbElements() ));
1606 tgtSM->ComputeStateEngine( SMESH_subMesh::CLEAN );
1608 if ( !tgtSM->IsMeshComputed() )
1610 // compute nodes on VERTEXes
1611 SMESH_subMeshIteratorPtr smIt = tgtSM->getDependsOnIterator(/*includeSelf=*/false);
1612 while ( smIt->more() )
1613 smIt->next()->ComputeStateEngine( SMESH_subMesh::COMPUTE );
1615 DBGOUT( "COMPUTE H edge (proj) " << tgtSM->GetId());
1616 projector1D->myHyp.SetSourceEdge( TopoDS::Edge( srcSM->GetSubShape() ));
1617 projector1D->InitComputeError();
1618 bool ok = projector1D->Compute( *mesh, tgtSM->GetSubShape() );
1621 SMESH_ComputeErrorPtr err = projector1D->GetComputeError();
1622 if ( err->IsOK() ) err->myName = COMPERR_ALGO_FAILED;
1623 tgtSM->GetComputeError() = err;
1627 tgtSM->ComputeStateEngine( SMESH_subMesh::CHECK_COMPUTE_STATE );
1630 // Compute quad mesh on wall FACEs
1631 // -------------------------------
1633 // make all EDGES meshed
1634 fSM->ComputeSubMeshStateEngine( SMESH_subMesh::COMPUTE );
1635 if ( !fSM->SubMeshesComputed() )
1636 return toSM( error( COMPERR_BAD_INPUT_MESH,
1637 "Not all edges have valid algorithm and hypothesis"));
1639 quadAlgo->InitComputeError();
1640 DBGOUT( "COMPUTE Quad face " << fSM->GetId());
1641 bool ok = quadAlgo->Compute( *mesh, face );
1642 fSM->GetComputeError() = quadAlgo->GetComputeError();
1645 fSM->ComputeStateEngine( SMESH_subMesh::CHECK_COMPUTE_STATE );
1647 if ( myHelper->GetIsQuadratic() )
1649 // fill myHelper with medium nodes built by quadAlgo
1650 SMDS_ElemIteratorPtr fIt = fSM->GetSubMeshDS()->GetElements();
1651 while ( fIt->more() )
1652 myHelper->AddTLinks( dynamic_cast<const SMDS_MeshFace*>( fIt->next() ));
1660 //=======================================================================
1662 * \brief Returns a source EDGE of propagation to a given EDGE
1664 //=======================================================================
1666 TopoDS_Edge StdMeshers_Prism_3D::findPropagationSource( const TopoDS_Edge& E )
1668 if ( myPropagChains )
1669 for ( size_t i = 0; !myPropagChains[i].IsEmpty(); ++i )
1670 if ( myPropagChains[i].Contains( E ))
1671 return TopoDS::Edge( myPropagChains[i].FindKey( 1 ));
1673 return TopoDS_Edge();
1676 //=======================================================================
1677 //function : Evaluate
1679 //=======================================================================
1681 bool StdMeshers_Prism_3D::Evaluate(SMESH_Mesh& theMesh,
1682 const TopoDS_Shape& theShape,
1683 MapShapeNbElems& aResMap)
1685 if ( theShape.ShapeType() == TopAbs_COMPOUND )
1688 for ( TopoDS_Iterator it( theShape ); it.More(); it.Next() )
1689 ok &= Evaluate( theMesh, it.Value(), aResMap );
1692 SMESH_MesherHelper helper( theMesh );
1694 myHelper->SetSubShape( theShape );
1696 // find face contains only triangles
1697 vector < SMESH_subMesh * >meshFaces;
1698 TopTools_SequenceOfShape aFaces;
1699 int NumBase = 0, i = 0, NbQFs = 0;
1700 for (TopExp_Explorer exp(theShape, TopAbs_FACE); exp.More(); exp.Next()) {
1702 aFaces.Append(exp.Current());
1703 SMESH_subMesh *aSubMesh = theMesh.GetSubMesh(exp.Current());
1704 meshFaces.push_back(aSubMesh);
1705 MapShapeNbElemsItr anIt = aResMap.find(meshFaces[i-1]);
1706 if( anIt==aResMap.end() )
1707 return toSM( error( "Submesh can not be evaluated"));
1709 std::vector<int> aVec = (*anIt).second;
1710 int nbtri = Max(aVec[SMDSEntity_Triangle],aVec[SMDSEntity_Quad_Triangle]);
1711 int nbqua = Max(aVec[SMDSEntity_Quadrangle],aVec[SMDSEntity_Quad_Quadrangle]);
1712 if( nbtri==0 && nbqua>0 ) {
1721 std::vector<int> aResVec(SMDSEntity_Last);
1722 for(int i=SMDSEntity_Node; i<SMDSEntity_Last; i++) aResVec[i] = 0;
1723 SMESH_subMesh * sm = theMesh.GetSubMesh(theShape);
1724 aResMap.insert(std::make_pair(sm,aResVec));
1725 return toSM( error( "Submesh can not be evaluated" ));
1728 if(NumBase==0) NumBase = 1; // only quads => set 1 faces as base
1730 // find number of 1d elems for base face
1732 TopTools_MapOfShape Edges1;
1733 for (TopExp_Explorer exp(aFaces.Value(NumBase), TopAbs_EDGE); exp.More(); exp.Next()) {
1734 Edges1.Add(exp.Current());
1735 SMESH_subMesh *sm = theMesh.GetSubMesh(exp.Current());
1737 MapShapeNbElemsItr anIt = aResMap.find(sm);
1738 if( anIt == aResMap.end() ) continue;
1739 std::vector<int> aVec = (*anIt).second;
1740 nb1d += Max(aVec[SMDSEntity_Edge],aVec[SMDSEntity_Quad_Edge]);
1743 // find face opposite to base face
1745 for(i=1; i<=6; i++) {
1746 if(i==NumBase) continue;
1747 bool IsOpposite = true;
1748 for(TopExp_Explorer exp(aFaces.Value(i), TopAbs_EDGE); exp.More(); exp.Next()) {
1749 if( Edges1.Contains(exp.Current()) ) {
1759 // find number of 2d elems on side faces
1761 for(i=1; i<=6; i++) {
1762 if( i==OppNum || i==NumBase ) continue;
1763 MapShapeNbElemsItr anIt = aResMap.find( meshFaces[i-1] );
1764 if( anIt == aResMap.end() ) continue;
1765 std::vector<int> aVec = (*anIt).second;
1766 nb2d += Max(aVec[SMDSEntity_Quadrangle],aVec[SMDSEntity_Quad_Quadrangle]);
1769 MapShapeNbElemsItr anIt = aResMap.find( meshFaces[NumBase-1] );
1770 std::vector<int> aVec = (*anIt).second;
1771 bool IsQuadratic = (aVec[SMDSEntity_Quad_Triangle]>aVec[SMDSEntity_Triangle]) ||
1772 (aVec[SMDSEntity_Quad_Quadrangle]>aVec[SMDSEntity_Quadrangle]);
1773 int nb2d_face0_3 = Max(aVec[SMDSEntity_Triangle],aVec[SMDSEntity_Quad_Triangle]);
1774 int nb2d_face0_4 = Max(aVec[SMDSEntity_Quadrangle],aVec[SMDSEntity_Quad_Quadrangle]);
1775 int nb0d_face0 = aVec[SMDSEntity_Node];
1776 int nb1d_face0_int = ( nb2d_face0_3*3 + nb2d_face0_4*4 - nb1d ) / 2;
1778 std::vector<int> aResVec(SMDSEntity_Last);
1779 for(int i=SMDSEntity_Node; i<SMDSEntity_Last; i++) aResVec[i] = 0;
1781 aResVec[SMDSEntity_Quad_Penta] = nb2d_face0_3 * ( nb2d/nb1d );
1782 aResVec[SMDSEntity_Quad_Hexa] = nb2d_face0_4 * ( nb2d/nb1d );
1783 aResVec[SMDSEntity_Node] = nb0d_face0 * ( 2*nb2d/nb1d - 1 ) - nb1d_face0_int * nb2d/nb1d;
1786 aResVec[SMDSEntity_Node] = nb0d_face0 * ( nb2d/nb1d - 1 );
1787 aResVec[SMDSEntity_Penta] = nb2d_face0_3 * ( nb2d/nb1d );
1788 aResVec[SMDSEntity_Hexa] = nb2d_face0_4 * ( nb2d/nb1d );
1790 SMESH_subMesh * sm = theMesh.GetSubMesh(theShape);
1791 aResMap.insert(std::make_pair(sm,aResVec));
1796 //================================================================================
1798 * \brief Create prisms
1799 * \param columns - columns of nodes generated from nodes of a mesh face
1800 * \param helper - helper initialized by mesh and shape to add prisms to
1802 //================================================================================
1804 void StdMeshers_Prism_3D::AddPrisms( vector<const TNodeColumn*> & columns,
1805 SMESH_MesherHelper* helper)
1807 int nbNodes = columns.size();
1808 int nbZ = columns[0]->size();
1809 if ( nbZ < 2 ) return;
1811 // find out orientation
1812 bool isForward = true;
1813 SMDS_VolumeTool vTool;
1815 switch ( nbNodes ) {
1817 SMDS_VolumeOfNodes tmpPenta ( (*columns[0])[z-1], // bottom
1820 (*columns[0])[z], // top
1823 vTool.Set( &tmpPenta );
1824 isForward = vTool.IsForward();
1828 SMDS_VolumeOfNodes tmpHex( (*columns[0])[z-1], (*columns[1])[z-1], // bottom
1829 (*columns[2])[z-1], (*columns[3])[z-1],
1830 (*columns[0])[z], (*columns[1])[z], // top
1831 (*columns[2])[z], (*columns[3])[z] );
1832 vTool.Set( &tmpHex );
1833 isForward = vTool.IsForward();
1837 const int di = (nbNodes+1) / 3;
1838 SMDS_VolumeOfNodes tmpVol ( (*columns[0] )[z-1],
1839 (*columns[di] )[z-1],
1840 (*columns[2*di])[z-1],
1843 (*columns[2*di])[z] );
1844 vTool.Set( &tmpVol );
1845 isForward = vTool.IsForward();
1848 // vertical loop on columns
1850 helper->SetElementsOnShape( true );
1852 switch ( nbNodes ) {
1854 case 3: { // ---------- pentahedra
1855 const int i1 = isForward ? 1 : 2;
1856 const int i2 = isForward ? 2 : 1;
1857 for ( z = 1; z < nbZ; ++z )
1858 helper->AddVolume( (*columns[0 ])[z-1], // bottom
1859 (*columns[i1])[z-1],
1860 (*columns[i2])[z-1],
1861 (*columns[0 ])[z], // top
1863 (*columns[i2])[z] );
1866 case 4: { // ---------- hexahedra
1867 const int i1 = isForward ? 1 : 3;
1868 const int i3 = isForward ? 3 : 1;
1869 for ( z = 1; z < nbZ; ++z )
1870 helper->AddVolume( (*columns[0])[z-1], (*columns[i1])[z-1], // bottom
1871 (*columns[2])[z-1], (*columns[i3])[z-1],
1872 (*columns[0])[z], (*columns[i1])[z], // top
1873 (*columns[2])[z], (*columns[i3])[z] );
1876 case 6: { // ---------- octahedra
1877 const int iBase1 = isForward ? -1 : 0;
1878 const int iBase2 = isForward ? 0 :-1;
1879 for ( z = 1; z < nbZ; ++z )
1880 helper->AddVolume( (*columns[0])[z+iBase1], (*columns[1])[z+iBase1], // bottom or top
1881 (*columns[2])[z+iBase1], (*columns[3])[z+iBase1],
1882 (*columns[4])[z+iBase1], (*columns[5])[z+iBase1],
1883 (*columns[0])[z+iBase2], (*columns[1])[z+iBase2], // top or bottom
1884 (*columns[2])[z+iBase2], (*columns[3])[z+iBase2],
1885 (*columns[4])[z+iBase2], (*columns[5])[z+iBase2] );
1888 default: // ---------- polyhedra
1889 vector<int> quantities( 2 + nbNodes, 4 );
1890 quantities[0] = quantities[1] = nbNodes;
1891 columns.resize( nbNodes + 1 );
1892 columns[ nbNodes ] = columns[ 0 ];
1893 const int i1 = isForward ? 1 : 3;
1894 const int i3 = isForward ? 3 : 1;
1895 const int iBase1 = isForward ? -1 : 0;
1896 const int iBase2 = isForward ? 0 :-1;
1897 vector<const SMDS_MeshNode*> nodes( 2*nbNodes + 4*nbNodes);
1898 for ( z = 1; z < nbZ; ++z )
1900 for ( int i = 0; i < nbNodes; ++i ) {
1901 nodes[ i ] = (*columns[ i ])[z+iBase1]; // bottom or top
1902 nodes[ 2*nbNodes-i-1 ] = (*columns[ i ])[z+iBase2]; // top or bottom
1904 int di = 2*nbNodes + 4*i;
1905 nodes[ di+0 ] = (*columns[i ])[z ];
1906 nodes[ di+i1] = (*columns[i+1])[z ];
1907 nodes[ di+2 ] = (*columns[i+1])[z-1];
1908 nodes[ di+i3] = (*columns[i ])[z-1];
1910 helper->AddPolyhedralVolume( nodes, quantities );
1913 } // switch ( nbNodes )
1916 //================================================================================
1918 * \brief Find correspondence between bottom and top nodes
1919 * If elements on the bottom and top faces are topologically different,
1920 * and projection is possible and allowed, perform the projection
1921 * \retval bool - is a success or not
1923 //================================================================================
1925 bool StdMeshers_Prism_3D::assocOrProjBottom2Top( const gp_Trsf & bottomToTopTrsf,
1926 const Prism_3D::TPrismTopo& thePrism)
1928 SMESH_subMesh * botSM = myHelper->GetMesh()->GetSubMesh( thePrism.myBottom );
1929 SMESH_subMesh * topSM = myHelper->GetMesh()->GetSubMesh( thePrism.myTop );
1931 SMESHDS_SubMesh * botSMDS = botSM->GetSubMeshDS();
1932 SMESHDS_SubMesh * topSMDS = topSM->GetSubMeshDS();
1934 if ( !botSMDS || botSMDS->NbElements() == 0 )
1936 _gen->Compute( *myHelper->GetMesh(), botSM->GetSubShape(), /*aShapeOnly=*/true );
1937 botSMDS = botSM->GetSubMeshDS();
1938 if ( !botSMDS || botSMDS->NbElements() == 0 )
1939 return toSM( error(TCom("No elements on face #") << botSM->GetId() ));
1942 bool needProject = !topSM->IsMeshComputed();
1943 if ( !needProject &&
1944 (botSMDS->NbElements() != topSMDS->NbElements() ||
1945 botSMDS->NbNodes() != topSMDS->NbNodes()))
1947 MESSAGE("nb elem bot " << botSMDS->NbElements() <<
1948 " top " << ( topSMDS ? topSMDS->NbElements() : 0 ));
1949 MESSAGE("nb node bot " << botSMDS->NbNodes() <<
1950 " top " << ( topSMDS ? topSMDS->NbNodes() : 0 ));
1951 return toSM( error(TCom("Mesh on faces #") << botSM->GetId()
1952 <<" and #"<< topSM->GetId() << " seems different" ));
1955 if ( 0/*needProject && !myProjectTriangles*/ )
1956 return toSM( error(TCom("Mesh on faces #") << botSM->GetId()
1957 <<" and #"<< topSM->GetId() << " seems different" ));
1958 ///RETURN_BAD_RESULT("Need to project but not allowed");
1960 NSProjUtils::TNodeNodeMap n2nMap;
1961 const NSProjUtils::TNodeNodeMap* n2nMapPtr = & n2nMap;
1964 if ( !projectBottomToTop( bottomToTopTrsf, thePrism ))
1966 n2nMapPtr = & TProjction2dAlgo::instance( this )->GetNodesMap();
1969 if ( !n2nMapPtr || n2nMapPtr->size() < botSMDS->NbNodes() )
1971 // associate top and bottom faces
1972 NSProjUtils::TShapeShapeMap shape2ShapeMap;
1973 const bool sameTopo =
1974 NSProjUtils::FindSubShapeAssociation( thePrism.myBottom, myHelper->GetMesh(),
1975 thePrism.myTop, myHelper->GetMesh(),
1978 for ( size_t iQ = 0; iQ < thePrism.myWallQuads.size(); ++iQ )
1980 const Prism_3D::TQuadList& quadList = thePrism.myWallQuads[iQ];
1981 StdMeshers_FaceSidePtr botSide = quadList.front()->side[ QUAD_BOTTOM_SIDE ];
1982 StdMeshers_FaceSidePtr topSide = quadList.back ()->side[ QUAD_TOP_SIDE ];
1983 if ( botSide->NbEdges() == topSide->NbEdges() )
1985 for ( int iE = 0; iE < botSide->NbEdges(); ++iE )
1987 NSProjUtils::InsertAssociation( botSide->Edge( iE ),
1988 topSide->Edge( iE ), shape2ShapeMap );
1989 NSProjUtils::InsertAssociation( myHelper->IthVertex( 0, botSide->Edge( iE )),
1990 myHelper->IthVertex( 0, topSide->Edge( iE )),
1996 TopoDS_Vertex vb, vt;
1997 StdMeshers_FaceSidePtr sideB, sideT;
1998 vb = myHelper->IthVertex( 0, botSide->Edge( 0 ));
1999 vt = myHelper->IthVertex( 0, topSide->Edge( 0 ));
2000 sideB = quadList.front()->side[ QUAD_LEFT_SIDE ];
2001 sideT = quadList.back ()->side[ QUAD_LEFT_SIDE ];
2002 if ( vb.IsSame( sideB->FirstVertex() ) &&
2003 vt.IsSame( sideT->LastVertex() ))
2005 NSProjUtils::InsertAssociation( botSide->Edge( 0 ),
2006 topSide->Edge( 0 ), shape2ShapeMap );
2007 NSProjUtils::InsertAssociation( vb, vt, shape2ShapeMap );
2009 vb = myHelper->IthVertex( 1, botSide->Edge( botSide->NbEdges()-1 ));
2010 vt = myHelper->IthVertex( 1, topSide->Edge( topSide->NbEdges()-1 ));
2011 sideB = quadList.front()->side[ QUAD_RIGHT_SIDE ];
2012 sideT = quadList.back ()->side[ QUAD_RIGHT_SIDE ];
2013 if ( vb.IsSame( sideB->FirstVertex() ) &&
2014 vt.IsSame( sideT->LastVertex() ))
2016 NSProjUtils::InsertAssociation( botSide->Edge( botSide->NbEdges()-1 ),
2017 topSide->Edge( topSide->NbEdges()-1 ),
2019 NSProjUtils::InsertAssociation( vb, vt, shape2ShapeMap );
2024 // Find matching nodes of top and bottom faces
2025 n2nMapPtr = & n2nMap;
2026 if ( ! NSProjUtils::FindMatchingNodesOnFaces( thePrism.myBottom, myHelper->GetMesh(),
2027 thePrism.myTop, myHelper->GetMesh(),
2028 shape2ShapeMap, n2nMap ))
2031 return toSM( error(TCom("Mesh on faces #") << botSM->GetId()
2032 <<" and #"<< topSM->GetId() << " seems different" ));
2034 return toSM( error(TCom("Topology of faces #") << botSM->GetId()
2035 <<" and #"<< topSM->GetId() << " seems different" ));
2039 // Fill myBotToColumnMap
2041 int zSize = myBlock.VerticalSize();
2042 TNodeNodeMap::const_iterator bN_tN = n2nMapPtr->begin();
2043 for ( ; bN_tN != n2nMapPtr->end(); ++bN_tN )
2045 const SMDS_MeshNode* botNode = bN_tN->first;
2046 const SMDS_MeshNode* topNode = bN_tN->second;
2047 if ( botNode->GetPosition()->GetTypeOfPosition() != SMDS_TOP_FACE )
2048 continue; // wall columns are contained in myBlock
2049 // create node column
2050 Prism_3D::TNode bN( botNode );
2051 TNode2ColumnMap::iterator bN_col =
2052 myBotToColumnMap.insert( make_pair ( bN, TNodeColumn() )).first;
2053 TNodeColumn & column = bN_col->second;
2054 column.resize( zSize );
2055 column.front() = botNode;
2056 column.back() = topNode;
2061 //================================================================================
2063 * \brief Remove faces from the top face and re-create them by projection from the bottom
2064 * \retval bool - a success or not
2066 //================================================================================
2068 bool StdMeshers_Prism_3D::projectBottomToTop( const gp_Trsf & bottomToTopTrsf,
2069 const Prism_3D::TPrismTopo& thePrism )
2071 if ( project2dMesh( thePrism.myBottom, thePrism.myTop ))
2075 NSProjUtils::TNodeNodeMap& n2nMap =
2076 (NSProjUtils::TNodeNodeMap&) TProjction2dAlgo::instance( this )->GetNodesMap();
2081 SMESHDS_Mesh* meshDS = myHelper->GetMeshDS();
2082 SMESH_subMesh * botSM = myHelper->GetMesh()->GetSubMesh( thePrism.myBottom );
2083 SMESH_subMesh * topSM = myHelper->GetMesh()->GetSubMesh( thePrism.myTop );
2085 SMESHDS_SubMesh * botSMDS = botSM->GetSubMeshDS();
2086 SMESHDS_SubMesh * topSMDS = topSM->GetSubMeshDS();
2088 if ( topSMDS && topSMDS->NbElements() > 0 )
2090 //topSM->ComputeStateEngine( SMESH_subMesh::CLEAN ); -- avoid propagation of events
2091 for ( SMDS_ElemIteratorPtr eIt = topSMDS->GetElements(); eIt->more(); )
2092 meshDS->RemoveFreeElement( eIt->next(), topSMDS, /*fromGroups=*/false );
2093 for ( SMDS_NodeIteratorPtr nIt = topSMDS->GetNodes(); nIt->more(); )
2094 meshDS->RemoveFreeNode( nIt->next(), topSMDS, /*fromGroups=*/false );
2097 const TopoDS_Face& botFace = thePrism.myBottom; // oriented within
2098 const TopoDS_Face& topFace = thePrism.myTop; // the 3D SHAPE
2099 int topFaceID = meshDS->ShapeToIndex( thePrism.myTop );
2101 SMESH_MesherHelper botHelper( *myHelper->GetMesh() );
2102 botHelper.SetSubShape( botFace );
2103 botHelper.ToFixNodeParameters( true );
2105 SMESH_MesherHelper topHelper( *myHelper->GetMesh() );
2106 topHelper.SetSubShape( topFace );
2107 topHelper.ToFixNodeParameters( true );
2108 double distXYZ[4], fixTol = 10 * topHelper.MaxTolerance( topFace );
2110 // Fill myBotToColumnMap
2112 int zSize = myBlock.VerticalSize();
2113 Prism_3D::TNode prevTNode;
2114 SMDS_NodeIteratorPtr nIt = botSMDS->GetNodes();
2115 while ( nIt->more() )
2117 const SMDS_MeshNode* botNode = nIt->next();
2118 const SMDS_MeshNode* topNode = 0;
2119 if ( botNode->GetPosition()->GetTypeOfPosition() != SMDS_TOP_FACE )
2120 continue; // strange
2122 Prism_3D::TNode bN( botNode );
2123 if ( bottomToTopTrsf.Form() == gp_Identity )
2125 // compute bottom node params
2126 gp_XYZ paramHint(-1,-1,-1);
2127 if ( prevTNode.IsNeighbor( bN ))
2129 paramHint = prevTNode.GetParams();
2130 // double tol = 1e-2 * ( prevTNode.GetCoords() - bN.GetCoords() ).Modulus();
2131 // myBlock.SetTolerance( Min( myBlock.GetTolerance(), tol ));
2133 if ( !myBlock.ComputeParameters( bN.GetCoords(), bN.ChangeParams(),
2134 ID_BOT_FACE, paramHint ))
2135 return toSM( error(TCom("Can't compute normalized parameters for node ")
2136 << botNode->GetID() << " on the face #"<< botSM->GetId() ));
2138 // compute top node coords
2139 gp_XYZ topXYZ; gp_XY topUV;
2140 if ( !myBlock.FacePoint( ID_TOP_FACE, bN.GetParams(), topXYZ ) ||
2141 !myBlock.FaceUV ( ID_TOP_FACE, bN.GetParams(), topUV ))
2142 return toSM( error(TCom("Can't compute coordinates "
2143 "by normalized parameters on the face #")<< topSM->GetId() ));
2144 topNode = meshDS->AddNode( topXYZ.X(),topXYZ.Y(),topXYZ.Z() );
2145 meshDS->SetNodeOnFace( topNode, topFaceID, topUV.X(), topUV.Y() );
2147 else // use bottomToTopTrsf
2149 gp_XYZ coords = bN.GetCoords();
2150 bottomToTopTrsf.Transforms( coords );
2151 topNode = meshDS->AddNode( coords.X(), coords.Y(), coords.Z() );
2152 gp_XY topUV = botHelper.GetNodeUV( botFace, botNode, 0, &checkUV );
2153 meshDS->SetNodeOnFace( topNode, topFaceID, topUV.X(), topUV.Y() );
2155 if ( topHelper.CheckNodeUV( topFace, topNode, topUV, fixTol, /*force=*/false, distXYZ ) &&
2156 distXYZ[0] > fixTol && distXYZ[0] < fixTol * 1e+3 )
2157 meshDS->MoveNode( topNode, distXYZ[1], distXYZ[2], distXYZ[3] ); // transform can be inaccurate
2159 // create node column
2160 TNode2ColumnMap::iterator bN_col =
2161 myBotToColumnMap.insert( make_pair ( bN, TNodeColumn() )).first;
2162 TNodeColumn & column = bN_col->second;
2163 column.resize( zSize );
2164 column.front() = botNode;
2165 column.back() = topNode;
2167 n2nMap.insert( n2nMap.end(), make_pair( botNode, topNode ));
2169 if ( _computeCanceled )
2170 return toSM( error( SMESH_ComputeError::New(COMPERR_CANCELED)));
2175 const bool oldSetElemsOnShape = myHelper->SetElementsOnShape( false );
2177 // care of orientation;
2178 // if the bottom faces is orienetd OK then top faces must be reversed
2179 bool reverseTop = true;
2180 if ( myHelper->NbAncestors( botFace, *myBlock.Mesh(), TopAbs_SOLID ) > 1 )
2181 reverseTop = ! myHelper->IsReversedSubMesh( botFace );
2182 int iFrw, iRev, *iPtr = &( reverseTop ? iRev : iFrw );
2184 // loop on bottom mesh faces
2185 SMDS_ElemIteratorPtr faceIt = botSMDS->GetElements();
2186 vector< const SMDS_MeshNode* > nodes;
2187 while ( faceIt->more() )
2189 const SMDS_MeshElement* face = faceIt->next();
2190 if ( !face || face->GetType() != SMDSAbs_Face )
2193 // find top node in columns for each bottom node
2194 int nbNodes = face->NbCornerNodes();
2195 nodes.resize( nbNodes );
2196 for ( iFrw = 0, iRev = nbNodes-1; iFrw < nbNodes; ++iFrw, --iRev )
2198 const SMDS_MeshNode* n = face->GetNode( *iPtr );
2199 if ( n->GetPosition()->GetTypeOfPosition() == SMDS_TOP_FACE ) {
2200 TNode2ColumnMap::iterator bot_column = myBotToColumnMap.find( n );
2201 if ( bot_column == myBotToColumnMap.end() )
2202 return toSM( error(TCom("No nodes found above node ") << n->GetID() ));
2203 nodes[ iFrw ] = bot_column->second.back();
2206 const TNodeColumn* column = myBlock.GetNodeColumn( n );
2208 return toSM( error(TCom("No side nodes found above node ") << n->GetID() ));
2209 nodes[ iFrw ] = column->back();
2212 SMDS_MeshElement* newFace = 0;
2213 switch ( nbNodes ) {
2216 newFace = myHelper->AddFace(nodes[0], nodes[1], nodes[2]);
2220 newFace = myHelper->AddFace( nodes[0], nodes[1], nodes[2], nodes[3] );
2224 newFace = meshDS->AddPolygonalFace( nodes );
2227 meshDS->SetMeshElementOnShape( newFace, topFaceID );
2230 myHelper->SetElementsOnShape( oldSetElemsOnShape );
2232 // Check the projected mesh
2234 if ( thePrism.myNbEdgesInWires.size() > 1 && // there are holes
2235 topHelper.IsDistorted2D( topSM, /*checkUV=*/false ))
2237 SMESH_MeshEditor editor( topHelper.GetMesh() );
2239 // smooth in 2D or 3D?
2240 TopLoc_Location loc;
2241 Handle(Geom_Surface) surface = BRep_Tool::Surface( topFace, loc );
2242 bool isPlanar = GeomLib_IsPlanarSurface( surface ).IsPlanar();
2244 bool isFixed = false;
2245 set<const SMDS_MeshNode*> fixedNodes;
2246 for ( int iAttemp = 0; !isFixed && iAttemp < 10; ++iAttemp )
2248 TIDSortedElemSet faces;
2249 for ( faceIt = topSMDS->GetElements(); faceIt->more(); )
2250 faces.insert( faces.end(), faceIt->next() );
2252 SMESH_MeshEditor::SmoothMethod algo =
2253 iAttemp ? SMESH_MeshEditor::CENTROIDAL : SMESH_MeshEditor::LAPLACIAN;
2256 editor.Smooth( faces, fixedNodes, algo, /*nbIterations=*/ 10,
2257 /*theTgtAspectRatio=*/1.0, /*the2D=*/!isPlanar);
2259 isFixed = !topHelper.IsDistorted2D( topSM, /*checkUV=*/true );
2262 return toSM( error( TCom("Projection from face #") << botSM->GetId()
2263 << " to face #" << topSM->GetId()
2264 << " failed: inverted elements created"));
2270 //=======================================================================
2271 //function : getSweepTolerance
2272 //purpose : Compute tolerance to pass to StdMeshers_Sweeper
2273 //=======================================================================
2275 double StdMeshers_Prism_3D::getSweepTolerance( const Prism_3D::TPrismTopo& thePrism )
2277 SMESHDS_Mesh* meshDS = myHelper->GetMeshDS();
2278 SMESHDS_SubMesh * sm[2] = { meshDS->MeshElements( thePrism.myBottom ),
2279 meshDS->MeshElements( thePrism.myTop ) };
2280 double minDist = 1e100;
2282 vector< SMESH_TNodeXYZ > nodes;
2283 for ( int iSM = 0; iSM < 2; ++iSM )
2285 if ( !sm[ iSM ]) continue;
2287 SMDS_ElemIteratorPtr fIt = sm[ iSM ]->GetElements();
2288 while ( fIt->more() )
2290 const SMDS_MeshElement* face = fIt->next();
2291 const int nbNodes = face->NbCornerNodes();
2292 SMDS_ElemIteratorPtr nIt = face->nodesIterator();
2294 nodes.resize( nbNodes + 1 );
2295 for ( int iN = 0; iN < nbNodes; ++iN )
2296 nodes[ iN ] = nIt->next();
2297 nodes.back() = nodes[0];
2301 for ( int iN = 0; iN < nbNodes; ++iN )
2303 if ( nodes[ iN ]._node->GetPosition()->GetDim() < 2 &&
2304 nodes[ iN+1 ]._node->GetPosition()->GetDim() < 2 )
2306 // it's a boundary link; measure distance of other
2307 // nodes to this link
2308 gp_XYZ linkDir = nodes[ iN ] - nodes[ iN+1 ];
2309 double linkLen = linkDir.Modulus();
2310 bool isDegen = ( linkLen < numeric_limits<double>::min() );
2311 if ( !isDegen ) linkDir /= linkLen;
2312 for ( int iN2 = 0; iN2 < nbNodes; ++iN2 ) // loop on other nodes
2314 if ( nodes[ iN2 ] == nodes[ iN ] ||
2315 nodes[ iN2 ] == nodes[ iN+1 ]) continue;
2318 dist2 = ( nodes[ iN ] - nodes[ iN2 ]).SquareModulus();
2322 dist2 = linkDir.CrossSquareMagnitude( nodes[ iN ] - nodes[ iN2 ]);
2324 if ( dist2 > numeric_limits<double>::min() )
2325 minDist = Min ( minDist, dist2 );
2328 // measure length link
2329 else if ( nodes[ iN ]._node < nodes[ iN+1 ]._node ) // not to measure same link twice
2331 dist2 = ( nodes[ iN ] - nodes[ iN+1 ]).SquareModulus();
2332 if ( dist2 > numeric_limits<double>::min() )
2333 minDist = Min ( minDist, dist2 );
2338 return 0.1 * Sqrt ( minDist );
2341 //=======================================================================
2342 //function : isSimpleQuad
2343 //purpose : check if the bottom FACE is meshable with nice qudrangles,
2344 // if so the block aproach can work rather fast.
2345 // This is a temporary mean caused by problems in StdMeshers_Sweeper
2346 //=======================================================================
2348 bool StdMeshers_Prism_3D::isSimpleBottom( const Prism_3D::TPrismTopo& thePrism )
2350 // analyse angles between edges
2351 double nbConcaveAng = 0, nbConvexAng = 0;
2352 TopoDS_Face reverseBottom = TopoDS::Face( thePrism.myBottom.Reversed() ); // see initPrism()
2353 TopoDS_Vertex commonV;
2354 const list< TopoDS_Edge >& botEdges = thePrism.myBottomEdges;
2355 list< TopoDS_Edge >::const_iterator edge = botEdges.begin();
2356 for ( ; edge != botEdges.end(); ++edge )
2358 if ( SMESH_Algo::isDegenerated( *edge ))
2360 TopoDS_Edge e1 = *edge++;
2361 TopoDS_Edge e2 = ( edge == botEdges.end() ? botEdges.front() : *edge );
2362 if ( ! TopExp::CommonVertex( e1, e2, commonV ))
2364 e2 = botEdges.front();
2365 if ( ! TopExp::CommonVertex( e1, e2, commonV ))
2368 double angle = myHelper->GetAngle( e1, e2, reverseBottom, commonV );
2369 if ( angle < -5 * M_PI/180 )
2370 if ( ++nbConcaveAng > 1 )
2372 if ( angle > 85 * M_PI/180 )
2373 if ( ++nbConvexAng > 4 )
2379 //=======================================================================
2380 //function : project2dMesh
2381 //purpose : Project mesh faces from a source FACE of one prism (theSrcFace)
2382 // to a source FACE of another prism (theTgtFace)
2383 //=======================================================================
2385 bool StdMeshers_Prism_3D::project2dMesh(const TopoDS_Face& theSrcFace,
2386 const TopoDS_Face& theTgtFace)
2388 TProjction2dAlgo* projector2D = TProjction2dAlgo::instance( this );
2389 projector2D->myHyp.SetSourceFace( theSrcFace );
2390 bool ok = projector2D->Compute( *myHelper->GetMesh(), theTgtFace );
2392 SMESH_subMesh* tgtSM = myHelper->GetMesh()->GetSubMesh( theTgtFace );
2393 if ( !ok && tgtSM->GetSubMeshDS() ) {
2394 //tgtSM->ComputeStateEngine( SMESH_subMesh::CLEAN ); -- avoid propagation of events
2395 SMESHDS_Mesh* meshDS = myHelper->GetMeshDS();
2396 SMESHDS_SubMesh* tgtSMDS = tgtSM->GetSubMeshDS();
2397 for ( SMDS_ElemIteratorPtr eIt = tgtSMDS->GetElements(); eIt->more(); )
2398 meshDS->RemoveFreeElement( eIt->next(), tgtSMDS, /*fromGroups=*/false );
2399 for ( SMDS_NodeIteratorPtr nIt = tgtSMDS->GetNodes(); nIt->more(); )
2400 meshDS->RemoveFreeNode( nIt->next(), tgtSMDS, /*fromGroups=*/false );
2402 tgtSM->ComputeStateEngine ( SMESH_subMesh::CHECK_COMPUTE_STATE );
2403 tgtSM->ComputeSubMeshStateEngine( SMESH_subMesh::CHECK_COMPUTE_STATE );
2408 //================================================================================
2410 * \brief Set projection coordinates of a node to a face and it's sub-shapes
2411 * \param faceID - the face given by in-block ID
2412 * \param params - node normalized parameters
2413 * \retval bool - is a success
2415 //================================================================================
2417 bool StdMeshers_Prism_3D::setFaceAndEdgesXYZ( const int faceID, const gp_XYZ& params, int z )
2419 // find base and top edges of the face
2420 enum { BASE = 0, TOP, LEFT, RIGHT };
2421 vector< int > edgeVec; // 0-base, 1-top
2422 SMESH_Block::GetFaceEdgesIDs( faceID, edgeVec );
2424 myBlock.EdgePoint( edgeVec[ BASE ], params, myShapeXYZ[ edgeVec[ BASE ]]);
2425 myBlock.EdgePoint( edgeVec[ TOP ], params, myShapeXYZ[ edgeVec[ TOP ]]);
2427 SHOWYXZ("\nparams ", params);
2428 SHOWYXZ("TOP is " <<edgeVec[ TOP ], myShapeXYZ[ edgeVec[ TOP]]);
2429 SHOWYXZ("BASE is "<<edgeVec[ BASE], myShapeXYZ[ edgeVec[ BASE]]);
2431 if ( faceID == SMESH_Block::ID_Fx0z || faceID == SMESH_Block::ID_Fx1z )
2433 myBlock.EdgePoint( edgeVec[ LEFT ], params, myShapeXYZ[ edgeVec[ LEFT ]]);
2434 myBlock.EdgePoint( edgeVec[ RIGHT ], params, myShapeXYZ[ edgeVec[ RIGHT ]]);
2436 SHOWYXZ("VER "<<edgeVec[ LEFT], myShapeXYZ[ edgeVec[ LEFT]]);
2437 SHOWYXZ("VER "<<edgeVec[ RIGHT], myShapeXYZ[ edgeVec[ RIGHT]]);
2439 myBlock.FacePoint( faceID, params, myShapeXYZ[ faceID ]);
2440 SHOWYXZ("FacePoint "<<faceID, myShapeXYZ[ faceID]);
2445 //=======================================================================
2447 //purpose : If (!isOK), sets the error to a sub-mesh of a current SOLID
2448 //=======================================================================
2450 bool StdMeshers_Prism_3D::toSM( bool isOK )
2452 if ( mySetErrorToSM &&
2455 !myHelper->GetSubShape().IsNull() &&
2456 myHelper->GetSubShape().ShapeType() == TopAbs_SOLID)
2458 SMESH_subMesh* sm = myHelper->GetMesh()->GetSubMesh( myHelper->GetSubShape() );
2459 sm->GetComputeError() = this->GetComputeError();
2460 // clear error in order not to return it twice
2461 _error = COMPERR_OK;
2467 //=======================================================================
2468 //function : shapeID
2469 //purpose : Return index of a shape
2470 //=======================================================================
2472 int StdMeshers_Prism_3D::shapeID( const TopoDS_Shape& S )
2474 if ( S.IsNull() ) return 0;
2475 if ( !myHelper ) return -3;
2476 return myHelper->GetMeshDS()->ShapeToIndex( S );
2479 namespace // utils used by StdMeshers_Prism_3D::IsApplicable()
2481 struct EdgeWithNeighbors
2485 EdgeWithNeighbors(const TopoDS_Edge& E, int iE, int nbE, int shift = 0 ):
2487 _iL( SMESH_MesherHelper::WrapIndex( iE-1, nbE ) + shift ),
2488 _iR( SMESH_MesherHelper::WrapIndex( iE+1, nbE ) + shift )
2491 EdgeWithNeighbors() {}
2496 TopTools_IndexedMapOfShape *_faces; // pointer because its copy constructor is private
2497 TopoDS_Edge _topEdge;
2498 vector< EdgeWithNeighbors >*_edges;
2500 vector< bool > _isCheckedEdge;
2501 int _nbCheckedEdges; // nb of EDGEs whose location is defined
2502 PrismSide *_leftSide;
2503 PrismSide *_rightSide;
2504 const TopoDS_Edge& Edge( int i ) const
2506 return (*_edges)[ i ]._edge;
2508 int FindEdge( const TopoDS_Edge& E ) const
2510 for ( size_t i = 0; i < _edges->size(); ++i )
2511 if ( E.IsSame( Edge( i ))) return i;
2514 bool IsSideFace( const TopoDS_Shape& face ) const
2516 if ( _faces->Contains( face )) // avoid returning true for a prism top FACE
2517 return ( !_face.IsNull() || !( face.IsSame( _faces->FindKey( _faces->Extent() ))));
2521 //--------------------------------------------------------------------------------
2523 * \brief Return ordered edges of a face
2525 bool getEdges( const TopoDS_Face& face,
2526 vector< EdgeWithNeighbors > & edges,
2527 const bool noHolesAllowed)
2529 list< TopoDS_Edge > ee;
2530 list< int > nbEdgesInWires;
2531 int nbW = SMESH_Block::GetOrderedEdges( face, ee, nbEdgesInWires );
2532 if ( nbW > 1 && noHolesAllowed )
2536 list< TopoDS_Edge >::iterator e = ee.begin();
2537 list< int >::iterator nbE = nbEdgesInWires.begin();
2538 for ( ; nbE != nbEdgesInWires.end(); ++nbE )
2539 for ( iE = 0; iE < *nbE; ++e, ++iE )
2540 if ( SMESH_Algo::isDegenerated( *e ))
2548 e->Orientation( TopAbs_FORWARD ); // for operator==() to work
2553 for ( nbE = nbEdgesInWires.begin(); nbE != nbEdgesInWires.end(); ++nbE )
2555 for ( iE = 0; iE < *nbE; ++e, ++iE )
2556 edges.push_back( EdgeWithNeighbors( *e, iE, *nbE, nbTot ));
2559 return edges.size();
2561 //--------------------------------------------------------------------------------
2563 * \brief Return another faces sharing an edge
2565 const TopoDS_Shape & getAnotherFace( const TopoDS_Face& face,
2566 const TopoDS_Edge& edge,
2567 TopTools_IndexedDataMapOfShapeListOfShape& facesOfEdge)
2569 TopTools_ListIteratorOfListOfShape faceIt( facesOfEdge.FindFromKey( edge ));
2570 for ( ; faceIt.More(); faceIt.Next() )
2571 if ( !face.IsSame( faceIt.Value() ))
2572 return faceIt.Value();
2577 //================================================================================
2579 * \brief Return true if the algorithm can mesh this shape
2580 * \param [in] aShape - shape to check
2581 * \param [in] toCheckAll - if true, this check returns OK if all shapes are OK,
2582 * else, returns OK if at least one shape is OK
2584 //================================================================================
2586 bool StdMeshers_Prism_3D::IsApplicable(const TopoDS_Shape & shape, bool toCheckAll)
2588 TopExp_Explorer sExp( shape, TopAbs_SOLID );
2592 for ( ; sExp.More(); sExp.Next() )
2596 TopExp_Explorer shExp( sExp.Current(), TopAbs_SHELL );
2597 if ( shExp.More() ) {
2598 shell = shExp.Current();
2603 if ( shell.IsNull() ) {
2604 if ( toCheckAll ) return false;
2608 TopTools_IndexedMapOfShape allFaces;
2609 TopExp::MapShapes( shell, TopAbs_FACE, allFaces );
2610 if ( allFaces.Extent() < 3 ) {
2611 if ( toCheckAll ) return false;
2615 if ( allFaces.Extent() == 6 )
2617 TopTools_IndexedMapOfOrientedShape map;
2618 bool isBox = SMESH_Block::FindBlockShapes( TopoDS::Shell( shell ),
2619 TopoDS_Vertex(), TopoDS_Vertex(), map );
2621 if ( !toCheckAll ) return true;
2626 TopTools_IndexedMapOfShape allShapes;
2627 TopExp::MapShapes( shape, allShapes );
2630 TopTools_IndexedDataMapOfShapeListOfShape facesOfEdge;
2631 TopTools_ListIteratorOfListOfShape faceIt;
2632 TopExp::MapShapesAndAncestors( sExp.Current(), TopAbs_EDGE, TopAbs_FACE , facesOfEdge );
2633 if ( facesOfEdge.IsEmpty() ) {
2634 if ( toCheckAll ) return false;
2638 typedef vector< EdgeWithNeighbors > TEdgeWithNeighborsVec;
2639 vector< TEdgeWithNeighborsVec > faceEdgesVec( allFaces.Extent() + 1 );
2640 TopTools_IndexedMapOfShape* facesOfSide = new TopTools_IndexedMapOfShape[ faceEdgesVec.size() ];
2641 SMESHUtils::ArrayDeleter<TopTools_IndexedMapOfShape> delFacesOfSide( facesOfSide );
2643 // try to use each face as a bottom one
2644 bool prismDetected = false;
2645 for ( int iF = 1; iF < allFaces.Extent() && !prismDetected; ++iF )
2647 const TopoDS_Face& botF = TopoDS::Face( allFaces( iF ));
2649 TEdgeWithNeighborsVec& botEdges = faceEdgesVec[ iF ];
2650 if ( botEdges.empty() )
2651 if ( !getEdges( botF, botEdges, /*noHoles=*/false ))
2653 if ( allFaces.Extent()-1 <= (int) botEdges.size() )
2654 continue; // all faces are adjacent to botF - no top FACE
2656 // init data of side FACEs
2657 vector< PrismSide > sides( botEdges.size() );
2658 for ( int iS = 0; iS < botEdges.size(); ++iS )
2660 sides[ iS ]._topEdge = botEdges[ iS ]._edge;
2661 sides[ iS ]._face = botF;
2662 sides[ iS ]._leftSide = & sides[ botEdges[ iS ]._iR ];
2663 sides[ iS ]._rightSide = & sides[ botEdges[ iS ]._iL ];
2664 sides[ iS ]._faces = & facesOfSide[ iS ];
2665 sides[ iS ]._faces->Clear();
2668 bool isOK = true; // ok for a current botF
2669 bool isAdvanced = true; // is new data found in a current loop
2670 int nbFoundSideFaces = 0;
2671 for ( int iLoop = 0; isOK && isAdvanced; ++iLoop )
2674 for ( size_t iS = 0; iS < sides.size() && isOK; ++iS )
2676 PrismSide& side = sides[ iS ];
2677 if ( side._face.IsNull() )
2678 continue; // probably the prism top face is the last of side._faces
2680 if ( side._topEdge.IsNull() )
2682 // find vertical EDGEs --- EGDEs shared with neighbor side FACEs
2683 for ( int is2nd = 0; is2nd < 2 && isOK; ++is2nd ) // 2 adjacent neighbors
2685 int di = is2nd ? 1 : -1;
2686 const PrismSide* adjSide = is2nd ? side._rightSide : side._leftSide;
2687 for ( size_t i = 1; i < side._edges->size(); ++i )
2689 int iE = SMESH_MesherHelper::WrapIndex( i*di + side._iBotEdge, side._edges->size());
2690 if ( side._isCheckedEdge[ iE ] ) continue;
2691 const TopoDS_Edge& vertE = side.Edge( iE );
2692 const TopoDS_Shape& neighborF = getAnotherFace( side._face, vertE, facesOfEdge );
2693 bool isEdgeShared = adjSide->IsSideFace( neighborF );
2697 side._isCheckedEdge[ iE ] = true;
2698 side._nbCheckedEdges++;
2699 int nbNotCheckedE = side._edges->size() - side._nbCheckedEdges;
2700 if ( nbNotCheckedE == 1 )
2705 if ( i == 1 && iLoop == 0 ) isOK = false;
2711 int nbNotCheckedE = side._edges->size() - side._nbCheckedEdges;
2712 if ( nbNotCheckedE == 1 )
2714 vector<bool>::iterator ii = std::find( side._isCheckedEdge.begin(),
2715 side._isCheckedEdge.end(), false );
2716 if ( ii != side._isCheckedEdge.end() )
2718 size_t iE = std::distance( side._isCheckedEdge.begin(), ii );
2719 side._topEdge = side.Edge( iE );
2722 isOK = ( nbNotCheckedE >= 1 );
2724 else //if ( !side._topEdge.IsNull() )
2726 // get a next face of a side
2727 const TopoDS_Shape& f = getAnotherFace( side._face, side._topEdge, facesOfEdge );
2728 side._faces->Add( f );
2730 if ( f.IsSame( side._face ) || // _topEdge is a seam
2731 SMESH_MesherHelper::Count( f, TopAbs_WIRE, false ) != 1 )
2735 else if ( side._leftSide != & side ) // not closed side face
2737 if ( side._leftSide->_faces->Contains( f ))
2739 stop = true; // probably f is the prism top face
2740 side._leftSide->_face.Nullify();
2741 side._leftSide->_topEdge.Nullify();
2743 if ( side._rightSide->_faces->Contains( f ))
2745 stop = true; // probably f is the prism top face
2746 side._rightSide->_face.Nullify();
2747 side._rightSide->_topEdge.Nullify();
2752 side._face.Nullify();
2753 side._topEdge.Nullify();
2756 side._face = TopoDS::Face( f );
2757 int faceID = allFaces.FindIndex( side._face );
2758 side._edges = & faceEdgesVec[ faceID ];
2759 if ( side._edges->empty() )
2760 if ( !getEdges( side._face, * side._edges, /*noHoles=*/true ))
2762 const int nbE = side._edges->size();
2767 side._iBotEdge = side.FindEdge( side._topEdge );
2768 side._isCheckedEdge.clear();
2769 side._isCheckedEdge.resize( nbE, false );
2770 side._isCheckedEdge[ side._iBotEdge ] = true;
2771 side._nbCheckedEdges = 1; // bottom EDGE is known
2773 side._topEdge.Nullify();
2774 isOK = ( !side._edges->empty() || side._faces->Extent() > 1 );
2776 } //if ( !side._topEdge.IsNull() )
2778 } // loop on prism sides
2780 if ( nbFoundSideFaces > allFaces.Extent() )
2784 if ( iLoop > allFaces.Extent() * 10 )
2788 cerr << "BUG: infinite loop in StdMeshers_Prism_3D::IsApplicable()" << endl;
2791 } // while isAdvanced
2793 if ( isOK && sides[0]._faces->Extent() > 1 )
2795 const int nbFaces = sides[0]._faces->Extent();
2796 if ( botEdges.size() == 1 ) // cylinder
2798 prismDetected = ( nbFaces == allFaces.Extent()-1 );
2802 const TopoDS_Shape& topFace = sides[0]._faces->FindKey( nbFaces );
2804 for ( iS = 1; iS < sides.size(); ++iS )
2805 if ( !sides[ iS ]._faces->Contains( topFace ))
2807 prismDetected = ( iS == sides.size() );
2810 } // loop on allFaces
2812 if ( !prismDetected && toCheckAll ) return false;
2813 if ( prismDetected && !toCheckAll ) return true;
2822 //================================================================================
2824 * \brief Return true if this node and other one belong to one face
2826 //================================================================================
2828 bool Prism_3D::TNode::IsNeighbor( const Prism_3D::TNode& other ) const
2830 if ( !other.myNode || !myNode ) return false;
2832 SMDS_ElemIteratorPtr fIt = other.myNode->GetInverseElementIterator(SMDSAbs_Face);
2833 while ( fIt->more() )
2834 if ( fIt->next()->GetNodeIndex( myNode ) >= 0 )
2839 //================================================================================
2841 * \brief Prism initialization
2843 //================================================================================
2845 void TPrismTopo::Clear()
2847 myShape3D.Nullify();
2850 myWallQuads.clear();
2851 myBottomEdges.clear();
2852 myNbEdgesInWires.clear();
2853 myWallQuads.clear();
2856 //================================================================================
2858 * \brief Set upside-down
2860 //================================================================================
2862 void TPrismTopo::SetUpsideDown()
2864 std::swap( myBottom, myTop );
2865 myBottomEdges.clear();
2866 std::reverse( myBottomEdges.begin(), myBottomEdges.end() );
2867 for ( size_t i = 0; i < myWallQuads.size(); ++i )
2869 myWallQuads[i].reverse();
2870 TQuadList::iterator q = myWallQuads[i].begin();
2871 for ( ; q != myWallQuads[i].end(); ++q )
2873 (*q)->shift( 2, /*keepUnitOri=*/true );
2875 myBottomEdges.push_back( myWallQuads[i].front()->side[ QUAD_BOTTOM_SIDE ].grid->Edge(0) );
2879 } // namespace Prism_3D
2881 //================================================================================
2883 * \brief Constructor. Initialization is needed
2885 //================================================================================
2887 StdMeshers_PrismAsBlock::StdMeshers_PrismAsBlock()
2892 StdMeshers_PrismAsBlock::~StdMeshers_PrismAsBlock()
2896 void StdMeshers_PrismAsBlock::Clear()
2899 myShapeIDMap.Clear();
2903 delete mySide; mySide = 0;
2905 myParam2ColumnMaps.clear();
2906 myShapeIndex2ColumnMap.clear();
2909 //=======================================================================
2910 //function : initPrism
2911 //purpose : Analyse shape geometry and mesh.
2912 // If there are triangles on one of faces, it becomes 'bottom'.
2913 // thePrism.myBottom can be already set up.
2914 //=======================================================================
2916 bool StdMeshers_Prism_3D::initPrism(Prism_3D::TPrismTopo& thePrism,
2917 const TopoDS_Shape& theShape3D,
2918 const bool selectBottom)
2920 myHelper->SetSubShape( theShape3D );
2922 SMESH_subMesh* mainSubMesh = myHelper->GetMesh()->GetSubMeshContaining( theShape3D );
2923 if ( !mainSubMesh ) return toSM( error(COMPERR_BAD_INPUT_MESH,"Null submesh of shape3D"));
2925 // detect not-quad FACE sub-meshes of the 3D SHAPE
2926 list< SMESH_subMesh* > notQuadGeomSubMesh;
2927 list< SMESH_subMesh* > notQuadElemSubMesh;
2928 list< SMESH_subMesh* > meshedSubMesh;
2931 SMESH_subMesh* anyFaceSM = 0;
2932 SMESH_subMeshIteratorPtr smIt = mainSubMesh->getDependsOnIterator(false,true);
2933 while ( smIt->more() )
2935 SMESH_subMesh* sm = smIt->next();
2936 const TopoDS_Shape& face = sm->GetSubShape();
2937 if ( face.ShapeType() > TopAbs_FACE ) break;
2938 else if ( face.ShapeType() < TopAbs_FACE ) continue;
2942 // is quadrangle FACE?
2943 list< TopoDS_Edge > orderedEdges;
2944 list< int > nbEdgesInWires;
2945 int nbWires = SMESH_Block::GetOrderedEdges( TopoDS::Face( face ), orderedEdges,
2947 if ( nbWires != 1 || nbEdgesInWires.front() != 4 )
2948 notQuadGeomSubMesh.push_back( sm );
2950 // look for a not structured sub-mesh
2951 if ( !sm->IsEmpty() )
2953 meshedSubMesh.push_back( sm );
2954 if ( !myHelper->IsSameElemGeometry( sm->GetSubMeshDS(), SMDSGeom_QUADRANGLE ) ||
2955 !myHelper->IsStructured ( sm ))
2956 notQuadElemSubMesh.push_back( sm );
2960 int nbNotQuadMeshed = notQuadElemSubMesh.size();
2961 int nbNotQuad = notQuadGeomSubMesh.size();
2962 bool hasNotQuad = ( nbNotQuad || nbNotQuadMeshed );
2965 if ( nbNotQuadMeshed > 2 )
2967 return toSM( error(COMPERR_BAD_INPUT_MESH,
2968 TCom("More than 2 faces with not quadrangle elements: ")
2969 <<nbNotQuadMeshed));
2971 if ( nbNotQuad > 2 || !thePrism.myBottom.IsNull() )
2973 // Issue 0020843 - one of side FACEs is quasi-quadrilateral (not 4 EDGEs).
2974 // Remove from notQuadGeomSubMesh faces meshed with regular grid
2975 int nbQuasiQuads = removeQuasiQuads( notQuadGeomSubMesh, myHelper,
2976 TQuadrangleAlgo::instance(this,myHelper) );
2977 nbNotQuad -= nbQuasiQuads;
2978 if ( nbNotQuad > 2 )
2979 return toSM( error(COMPERR_BAD_SHAPE,
2980 TCom("More than 2 not quadrilateral faces: ") <<nbNotQuad));
2981 hasNotQuad = ( nbNotQuad || nbNotQuadMeshed );
2984 // Analyse mesh and topology of FACEs: choose the bottom sub-mesh.
2985 // If there are not quadrangle FACEs, they are top and bottom ones.
2986 // Not quadrangle FACEs must be only on top and bottom.
2988 SMESH_subMesh * botSM = 0;
2989 SMESH_subMesh * topSM = 0;
2991 if ( hasNotQuad ) // can choose a bottom FACE
2993 if ( nbNotQuadMeshed > 0 ) botSM = notQuadElemSubMesh.front();
2994 else botSM = notQuadGeomSubMesh.front();
2995 if ( nbNotQuadMeshed > 1 ) topSM = notQuadElemSubMesh.back();
2996 else if ( nbNotQuad > 1 ) topSM = notQuadGeomSubMesh.back();
2998 if ( topSM == botSM ) {
2999 if ( nbNotQuadMeshed > 1 ) topSM = notQuadElemSubMesh.front();
3000 else topSM = notQuadGeomSubMesh.front();
3003 // detect mesh triangles on wall FACEs
3004 if ( nbNotQuad == 2 && nbNotQuadMeshed > 0 ) {
3006 if ( nbNotQuadMeshed == 1 )
3007 ok = ( find( notQuadGeomSubMesh.begin(),
3008 notQuadGeomSubMesh.end(), botSM ) != notQuadGeomSubMesh.end() );
3010 ok = ( notQuadGeomSubMesh == notQuadElemSubMesh );
3012 return toSM( error(COMPERR_BAD_INPUT_MESH,
3013 "Side face meshed with not quadrangle elements"));
3017 thePrism.myNotQuadOnTop = ( nbNotQuadMeshed > 1 );
3019 // use thePrism.myBottom
3020 if ( !thePrism.myBottom.IsNull() )
3022 if ( botSM ) { // <-- not quad geom or mesh on botSM
3023 if ( ! botSM->GetSubShape().IsSame( thePrism.myBottom )) {
3024 std::swap( botSM, topSM );
3025 if ( !botSM || ! botSM->GetSubShape().IsSame( thePrism.myBottom )) {
3026 if ( !selectBottom )
3027 return toSM( error( COMPERR_BAD_INPUT_MESH,
3028 "Incompatible non-structured sub-meshes"));
3029 std::swap( botSM, topSM );
3030 thePrism.myBottom = TopoDS::Face( botSM->GetSubShape() );
3034 else if ( !selectBottom ) {
3035 botSM = myHelper->GetMesh()->GetSubMesh( thePrism.myBottom );
3038 if ( !botSM ) // find a proper bottom
3040 bool savedSetErrorToSM = mySetErrorToSM;
3041 mySetErrorToSM = false; // ingore errors in initPrism()
3043 // search among meshed FACEs
3044 list< SMESH_subMesh* >::iterator sm = meshedSubMesh.begin();
3045 for ( ; !botSM && sm != meshedSubMesh.end(); ++sm )
3049 thePrism.myBottom = TopoDS::Face( botSM->GetSubShape() );
3050 if ( !initPrism( thePrism, theShape3D, /*selectBottom=*/false ))
3053 // search among all FACEs
3054 for ( TopExp_Explorer f( theShape3D, TopAbs_FACE ); !botSM && f.More(); f.Next() )
3056 int minNbFaces = 2 + myHelper->Count( f.Current(), TopAbs_EDGE, false);
3057 if ( nbFaces < minNbFaces) continue;
3059 thePrism.myBottom = TopoDS::Face( f.Current() );
3060 botSM = myHelper->GetMesh()->GetSubMesh( thePrism.myBottom );
3061 if ( !initPrism( thePrism, theShape3D, /*selectBottom=*/false ))
3064 mySetErrorToSM = savedSetErrorToSM;
3065 return botSM ? true : toSM( error( COMPERR_BAD_SHAPE ));
3068 // find vertex 000 - the one with smallest coordinates (for easy DEBUG :-)
3070 double minVal = DBL_MAX, minX, val;
3071 for ( TopExp_Explorer exp( botSM->GetSubShape(), TopAbs_VERTEX );
3072 exp.More(); exp.Next() )
3074 const TopoDS_Vertex& v = TopoDS::Vertex( exp.Current() );
3075 gp_Pnt P = BRep_Tool::Pnt( v );
3076 val = P.X() + P.Y() + P.Z();
3077 if ( val < minVal || ( val == minVal && P.X() < minX )) {
3084 thePrism.myShape3D = theShape3D;
3085 if ( thePrism.myBottom.IsNull() )
3086 thePrism.myBottom = TopoDS::Face( botSM->GetSubShape() );
3087 thePrism.myBottom.Orientation( myHelper->GetSubShapeOri( theShape3D, thePrism.myBottom ));
3088 thePrism.myTop. Orientation( myHelper->GetSubShapeOri( theShape3D, thePrism.myTop ));
3090 // Get ordered bottom edges
3091 TopoDS_Face reverseBottom = // to have order of top EDGEs as in the top FACE
3092 TopoDS::Face( thePrism.myBottom.Reversed() );
3093 SMESH_Block::GetOrderedEdges( reverseBottom,
3094 thePrism.myBottomEdges,
3095 thePrism.myNbEdgesInWires, V000 );
3097 // Get Wall faces corresponding to the ordered bottom edges and the top FACE
3098 if ( !getWallFaces( thePrism, nbFaces )) // it also sets thePrism.myTop
3099 return false; //toSM( error(COMPERR_BAD_SHAPE, "Can't find side faces"));
3103 if ( !thePrism.myTop.IsSame( topSM->GetSubShape() ))
3105 (notQuadGeomSubMesh.empty() ? COMPERR_BAD_INPUT_MESH : COMPERR_BAD_SHAPE,
3106 "Non-quadrilateral faces are not opposite"));
3108 // check that the found top and bottom FACEs are opposite
3109 list< TopoDS_Edge >::iterator edge = thePrism.myBottomEdges.begin();
3110 for ( ; edge != thePrism.myBottomEdges.end(); ++edge )
3111 if ( myHelper->IsSubShape( *edge, thePrism.myTop ))
3113 (notQuadGeomSubMesh.empty() ? COMPERR_BAD_INPUT_MESH : COMPERR_BAD_SHAPE,
3114 "Non-quadrilateral faces are not opposite"));
3117 if ( thePrism.myBottomEdges.size() > thePrism.myWallQuads.size() )
3119 // composite bottom sides => set thePrism upside-down
3120 thePrism.SetUpsideDown();
3126 //================================================================================
3128 * \brief Initialization.
3129 * \param helper - helper loaded with mesh and 3D shape
3130 * \param thePrism - a prism data
3131 * \retval bool - false if a mesh or a shape are KO
3133 //================================================================================
3135 bool StdMeshers_PrismAsBlock::Init(SMESH_MesherHelper* helper,
3136 const Prism_3D::TPrismTopo& thePrism)
3139 SMESHDS_Mesh* meshDS = myHelper->GetMeshDS();
3140 SMESH_Mesh* mesh = myHelper->GetMesh();
3143 delete mySide; mySide = 0;
3145 vector< TSideFace* > sideFaces( NB_WALL_FACES, 0 );
3146 vector< pair< double, double> > params( NB_WALL_FACES );
3147 mySide = new TSideFace( *mesh, sideFaces, params );
3150 SMESH_Block::init();
3151 myShapeIDMap.Clear();
3152 myShapeIndex2ColumnMap.clear();
3154 int wallFaceIds[ NB_WALL_FACES ] = { // to walk around a block
3155 SMESH_Block::ID_Fx0z, SMESH_Block::ID_F1yz,
3156 SMESH_Block::ID_Fx1z, SMESH_Block::ID_F0yz
3159 myError = SMESH_ComputeError::New();
3161 myNotQuadOnTop = thePrism.myNotQuadOnTop;
3163 // Find columns of wall nodes and calculate edges' lengths
3164 // --------------------------------------------------------
3166 myParam2ColumnMaps.clear();
3167 myParam2ColumnMaps.resize( thePrism.myBottomEdges.size() ); // total nb edges
3169 size_t iE, nbEdges = thePrism.myNbEdgesInWires.front(); // nb outer edges
3170 vector< double > edgeLength( nbEdges );
3171 multimap< double, int > len2edgeMap;
3173 // for each EDGE: either split into several parts, or join with several next EDGEs
3174 vector<int> nbSplitPerEdge( nbEdges, 0 );
3175 vector<int> nbUnitePerEdge( nbEdges, 0 ); // -1 means "joined to a previous"
3177 // consider continuous straight EDGEs as one side
3178 const int nbSides = countNbSides( thePrism, nbUnitePerEdge, edgeLength );
3180 list< TopoDS_Edge >::const_iterator edgeIt = thePrism.myBottomEdges.begin();
3181 for ( iE = 0; iE < nbEdges; ++iE, ++edgeIt )
3183 TParam2ColumnMap & faceColumns = myParam2ColumnMaps[ iE ];
3185 Prism_3D::TQuadList::const_iterator quad = thePrism.myWallQuads[ iE ].begin();
3186 for ( ; quad != thePrism.myWallQuads[ iE ].end(); ++quad )
3188 const TopoDS_Edge& quadBot = (*quad)->side[ QUAD_BOTTOM_SIDE ].grid->Edge( 0 );
3189 if ( !myHelper->LoadNodeColumns( faceColumns, (*quad)->face, quadBot, meshDS ))
3190 return error(COMPERR_BAD_INPUT_MESH, TCom("Can't find regular quadrangle mesh ")
3191 << "on a side face #" << MeshDS()->ShapeToIndex( (*quad)->face ));
3193 SHOWYXZ("\np1 F " <<iE, gpXYZ(faceColumns.begin()->second.front() ));
3194 SHOWYXZ("p2 F " <<iE, gpXYZ(faceColumns.rbegin()->second.front() ));
3195 SHOWYXZ("V First "<<iE, BRep_Tool::Pnt( TopExp::FirstVertex(*edgeIt,true )));
3197 if ( nbSides < NB_WALL_FACES ) // fill map used to split faces
3198 len2edgeMap.insert( make_pair( edgeLength[ iE ], iE )); // sort edges by length
3200 // Load columns of internal edges (forming holes)
3201 // and fill map ShapeIndex to TParam2ColumnMap for them
3202 for ( ; edgeIt != thePrism.myBottomEdges.end() ; ++edgeIt, ++iE )
3204 TParam2ColumnMap & faceColumns = myParam2ColumnMaps[ iE ];
3206 Prism_3D::TQuadList::const_iterator quad = thePrism.myWallQuads[ iE ].begin();
3207 for ( ; quad != thePrism.myWallQuads[ iE ].end(); ++quad )
3209 const TopoDS_Edge& quadBot = (*quad)->side[ QUAD_BOTTOM_SIDE ].grid->Edge( 0 );
3210 if ( !myHelper->LoadNodeColumns( faceColumns, (*quad)->face, quadBot, meshDS ))
3211 return error(COMPERR_BAD_INPUT_MESH, TCom("Can't find regular quadrangle mesh ")
3212 << "on a side face #" << MeshDS()->ShapeToIndex( (*quad)->face ));
3215 int id = MeshDS()->ShapeToIndex( *edgeIt );
3216 bool isForward = true; // meaningless for intenal wires
3217 myShapeIndex2ColumnMap[ id ] = make_pair( & faceColumns, isForward );
3218 // columns for vertices
3220 const SMDS_MeshNode* n0 = faceColumns.begin()->second.front();
3221 id = n0->getshapeId();
3222 myShapeIndex2ColumnMap[ id ] = make_pair( & faceColumns, isForward );
3224 const SMDS_MeshNode* n1 = faceColumns.rbegin()->second.front();
3225 id = n1->getshapeId();
3226 myShapeIndex2ColumnMap[ id ] = make_pair( & faceColumns, isForward );
3228 // SHOWYXZ("\np1 F " <<iE, gpXYZ(faceColumns.begin()->second.front() ));
3229 // SHOWYXZ("p2 F " <<iE, gpXYZ(faceColumns.rbegin()->second.front() ));
3230 // SHOWYXZ("V First "<<iE, BRep_Tool::Pnt( TopExp::FirstVertex(*edgeIt,true )));
3233 // Create 4 wall faces of a block
3234 // -------------------------------
3236 if ( nbSides <= NB_WALL_FACES ) // ************* Split faces if necessary
3238 if ( nbSides != NB_WALL_FACES ) // define how to split
3240 if ( len2edgeMap.size() != nbEdges )
3241 RETURN_BAD_RESULT("Uniqueness of edge lengths not assured");
3243 multimap< double, int >::reverse_iterator maxLen_i = len2edgeMap.rbegin();
3244 multimap< double, int >::reverse_iterator midLen_i = ++len2edgeMap.rbegin();
3246 double maxLen = maxLen_i->first;
3247 double midLen = ( len2edgeMap.size() == 1 ) ? 0 : midLen_i->first;
3248 switch ( nbEdges ) {
3249 case 1: // 0-th edge is split into 4 parts
3250 nbSplitPerEdge[ 0 ] = 4;
3252 case 2: // either the longest edge is split into 3 parts, or both edges into halves
3253 if ( maxLen / 3 > midLen / 2 ) {
3254 nbSplitPerEdge[ maxLen_i->second ] = 3;
3257 nbSplitPerEdge[ maxLen_i->second ] = 2;
3258 nbSplitPerEdge[ midLen_i->second ] = 2;
3263 // split longest into 3 parts
3264 nbSplitPerEdge[ maxLen_i->second ] = 3;
3266 // split longest into halves
3267 nbSplitPerEdge[ maxLen_i->second ] = 2;
3271 else // **************************** Unite faces
3273 int nbExraFaces = nbSides - 4; // nb of faces to fuse
3274 for ( iE = 0; iE < nbEdges; ++iE )
3276 if ( nbUnitePerEdge[ iE ] < 0 )
3278 // look for already united faces
3279 for ( int i = iE; i < iE + nbExraFaces; ++i )
3281 if ( nbUnitePerEdge[ i ] > 0 ) // a side including nbUnitePerEdge[i]+1 edge
3282 nbExraFaces += nbUnitePerEdge[ i ];
3283 nbUnitePerEdge[ i ] = -1;
3285 nbUnitePerEdge[ iE ] = nbExraFaces;
3290 // Create TSideFace's
3292 list< TopoDS_Edge >::const_iterator botE = thePrism.myBottomEdges.begin();
3293 for ( iE = 0; iE < nbEdges; ++iE, ++botE )
3295 TFaceQuadStructPtr quad = thePrism.myWallQuads[ iE ].front();
3296 const int nbSplit = nbSplitPerEdge[ iE ];
3297 const int nbExraFaces = nbUnitePerEdge[ iE ] + 1;
3298 if ( nbSplit > 0 ) // split
3300 vector< double > params;
3301 splitParams( nbSplit, &myParam2ColumnMaps[ iE ], params );
3302 const bool isForward =
3303 StdMeshers_PrismAsBlock::IsForwardEdge( myHelper->GetMeshDS(),
3304 myParam2ColumnMaps[iE],
3305 *botE, SMESH_Block::ID_Fx0z );
3306 for ( int i = 0; i < nbSplit; ++i ) {
3307 double f = ( isForward ? params[ i ] : params[ nbSplit - i-1 ]);
3308 double l = ( isForward ? params[ i+1 ] : params[ nbSplit - i ]);
3309 TSideFace* comp = new TSideFace( *mesh, wallFaceIds[ iSide ],
3310 thePrism.myWallQuads[ iE ], *botE,
3311 &myParam2ColumnMaps[ iE ], f, l );
3312 mySide->SetComponent( iSide++, comp );
3315 else if ( nbExraFaces > 1 ) // unite
3317 double u0 = 0, sumLen = 0;
3318 for ( int i = iE; i < iE + nbExraFaces; ++i )
3319 sumLen += edgeLength[ i ];
3321 vector< TSideFace* > components( nbExraFaces );
3322 vector< pair< double, double> > params( nbExraFaces );
3323 bool endReached = false;
3324 for ( int i = 0; i < nbExraFaces; ++i, ++botE, ++iE )
3326 if ( iE == nbEdges )
3329 botE = thePrism.myBottomEdges.begin();
3332 components[ i ] = new TSideFace( *mesh, wallFaceIds[ iSide ],
3333 thePrism.myWallQuads[ iE ], *botE,
3334 &myParam2ColumnMaps[ iE ]);
3335 double u1 = u0 + edgeLength[ iE ] / sumLen;
3336 params[ i ] = make_pair( u0 , u1 );
3339 TSideFace* comp = new TSideFace( *mesh, components, params );
3340 mySide->SetComponent( iSide++, comp );
3343 --iE; // for increment in an external loop on iE
3346 else if ( nbExraFaces < 0 ) // skip already united face
3351 TSideFace* comp = new TSideFace( *mesh, wallFaceIds[ iSide ],
3352 thePrism.myWallQuads[ iE ], *botE,
3353 &myParam2ColumnMaps[ iE ]);
3354 mySide->SetComponent( iSide++, comp );
3359 // Fill geometry fields of SMESH_Block
3360 // ------------------------------------
3362 vector< int > botEdgeIdVec;
3363 SMESH_Block::GetFaceEdgesIDs( ID_BOT_FACE, botEdgeIdVec );
3365 bool isForward[NB_WALL_FACES] = { true, true, true, true };
3366 Adaptor2d_Curve2d* botPcurves[NB_WALL_FACES];
3367 Adaptor2d_Curve2d* topPcurves[NB_WALL_FACES];
3369 for ( int iF = 0; iF < NB_WALL_FACES; ++iF )
3371 TSideFace * sideFace = mySide->GetComponent( iF );
3373 RETURN_BAD_RESULT("NULL TSideFace");
3374 int fID = sideFace->FaceID(); // in-block ID
3376 // fill myShapeIDMap
3377 if ( sideFace->InsertSubShapes( myShapeIDMap ) != 8 &&
3378 !sideFace->IsComplex())
3379 MESSAGE( ": Warning : InsertSubShapes() < 8 on side " << iF );
3381 // side faces geometry
3382 Adaptor2d_Curve2d* pcurves[NB_WALL_FACES];
3383 if ( !sideFace->GetPCurves( pcurves ))
3384 RETURN_BAD_RESULT("TSideFace::GetPCurves() failed");
3386 SMESH_Block::TFace& tFace = myFace[ fID - ID_FirstF ];
3387 tFace.Set( fID, sideFace->Surface(), pcurves, isForward );
3389 SHOWYXZ( endl<<"F "<< iF << " id " << fID << " FRW " << sideFace->IsForward(), sideFace->Value(0,0));
3390 // edges 3D geometry
3391 vector< int > edgeIdVec;
3392 SMESH_Block::GetFaceEdgesIDs( fID, edgeIdVec );
3393 for ( int isMax = 0; isMax < 2; ++isMax ) {
3395 int eID = edgeIdVec[ isMax ];
3396 SMESH_Block::TEdge& tEdge = myEdge[ eID - ID_FirstE ];
3397 tEdge.Set( eID, sideFace->HorizCurve(isMax), true);
3398 SHOWYXZ(eID<<" HOR"<<isMax<<"(0)", sideFace->HorizCurve(isMax)->Value(0));
3399 SHOWYXZ(eID<<" HOR"<<isMax<<"(1)", sideFace->HorizCurve(isMax)->Value(1));
3402 int eID = edgeIdVec[ isMax+2 ];
3403 SMESH_Block::TEdge& tEdge = myEdge[ eID - ID_FirstE ];
3404 tEdge.Set( eID, sideFace->VertiCurve(isMax), true);
3405 SHOWYXZ(eID<<" VER"<<isMax<<"(0)", sideFace->VertiCurve(isMax)->Value(0));
3406 SHOWYXZ(eID<<" VER"<<isMax<<"(1)", sideFace->VertiCurve(isMax)->Value(1));
3409 vector< int > vertexIdVec;
3410 SMESH_Block::GetEdgeVertexIDs( eID, vertexIdVec );
3411 myPnt[ vertexIdVec[0] - ID_FirstV ] = tEdge.GetCurve()->Value(0).XYZ();
3412 myPnt[ vertexIdVec[1] - ID_FirstV ] = tEdge.GetCurve()->Value(1).XYZ();
3415 // pcurves on horizontal faces
3416 for ( iE = 0; iE < NB_WALL_FACES; ++iE ) {
3417 if ( edgeIdVec[ BOTTOM_EDGE ] == botEdgeIdVec[ iE ] ) {
3418 botPcurves[ iE ] = sideFace->HorizPCurve( false, thePrism.myBottom );
3419 topPcurves[ iE ] = sideFace->HorizPCurve( true, thePrism.myTop );
3423 //sideFace->dumpNodes( 4 ); // debug
3425 // horizontal faces geometry
3427 SMESH_Block::TFace& tFace = myFace[ ID_BOT_FACE - ID_FirstF ];
3428 tFace.Set( ID_BOT_FACE, new BRepAdaptor_Surface( thePrism.myBottom ), botPcurves, isForward );
3429 SMESH_Block::Insert( thePrism.myBottom, ID_BOT_FACE, myShapeIDMap );
3432 SMESH_Block::TFace& tFace = myFace[ ID_TOP_FACE - ID_FirstF ];
3433 tFace.Set( ID_TOP_FACE, new BRepAdaptor_Surface( thePrism.myTop ), topPcurves, isForward );
3434 SMESH_Block::Insert( thePrism.myTop, ID_TOP_FACE, myShapeIDMap );
3436 //faceGridToPythonDump( SMESH_Block::ID_Fxy0, 50 );
3437 //faceGridToPythonDump( SMESH_Block::ID_Fxy1 );
3439 // Fill map ShapeIndex to TParam2ColumnMap
3440 // ----------------------------------------
3442 list< TSideFace* > fList;
3443 list< TSideFace* >::iterator fListIt;
3444 fList.push_back( mySide );
3445 for ( fListIt = fList.begin(); fListIt != fList.end(); ++fListIt)
3447 int nb = (*fListIt)->NbComponents();
3448 for ( int i = 0; i < nb; ++i ) {
3449 if ( TSideFace* comp = (*fListIt)->GetComponent( i ))
3450 fList.push_back( comp );
3452 if ( TParam2ColumnMap* cols = (*fListIt)->GetColumns()) {
3453 // columns for a base edge
3454 int id = MeshDS()->ShapeToIndex( (*fListIt)->BaseEdge() );
3455 bool isForward = (*fListIt)->IsForward();
3456 myShapeIndex2ColumnMap[ id ] = make_pair( cols, isForward );
3458 // columns for vertices
3459 const SMDS_MeshNode* n0 = cols->begin()->second.front();
3460 id = n0->getshapeId();
3461 myShapeIndex2ColumnMap[ id ] = make_pair( cols, isForward );
3463 const SMDS_MeshNode* n1 = cols->rbegin()->second.front();
3464 id = n1->getshapeId();
3465 myShapeIndex2ColumnMap[ id ] = make_pair( cols, !isForward );
3469 // #define SHOWYXZ(msg, xyz) { \
3470 // gp_Pnt p (xyz); \
3471 // cout << msg << " ("<< p.X() << "; " <<p.Y() << "; " <<p.Z() << ") " <<endl; \
3473 // double _u[]={ 0.1, 0.1, 0.9, 0.9 };
3474 // double _v[]={ 0.1, 0.9, 0.1, 0.9 };
3475 // for ( int z = 0; z < 2; ++z )
3476 // for ( int i = 0; i < 4; ++i )
3478 // //gp_XYZ testPar(0.25, 0.25, 0), testCoord;
3479 // int iFace = (z ? ID_TOP_FACE : ID_BOT_FACE);
3480 // gp_XYZ testPar(_u[i], _v[i], z), testCoord;
3481 // if ( !FacePoint( iFace, testPar, testCoord ))
3482 // RETURN_BAD_RESULT("TEST FacePoint() FAILED");
3483 // SHOWYXZ("IN TEST PARAM" , testPar);
3484 // SHOWYXZ("OUT TEST CORD" , testCoord);
3485 // if ( !ComputeParameters( testCoord, testPar , iFace))
3486 // RETURN_BAD_RESULT("TEST ComputeParameters() FAILED");
3487 // SHOWYXZ("OUT TEST PARAM" , testPar);
3492 //================================================================================
3494 * \brief Return pointer to column of nodes
3495 * \param node - bottom node from which the returned column goes up
3496 * \retval const TNodeColumn* - the found column
3498 //================================================================================
3500 const TNodeColumn* StdMeshers_PrismAsBlock::GetNodeColumn(const SMDS_MeshNode* node) const
3502 int sID = node->getshapeId();
3504 map<int, pair< TParam2ColumnMap*, bool > >::const_iterator col_frw =
3505 myShapeIndex2ColumnMap.find( sID );
3506 if ( col_frw != myShapeIndex2ColumnMap.end() ) {
3507 const TParam2ColumnMap* cols = col_frw->second.first;
3508 TParam2ColumnIt u_col = cols->begin();
3509 for ( ; u_col != cols->end(); ++u_col )
3510 if ( u_col->second[ 0 ] == node )
3511 return & u_col->second;
3516 //=======================================================================
3517 //function : GetLayersTransformation
3518 //purpose : Return transformations to get coordinates of nodes of each layer
3519 // by nodes of the bottom. Layer is a set of nodes at a certain step
3520 // from bottom to top.
3521 // Transformation to get top node from bottom ones is computed
3522 // only if the top FACE is not meshed.
3523 //=======================================================================
3525 bool StdMeshers_PrismAsBlock::GetLayersTransformation(vector<gp_Trsf> & trsf,
3526 const Prism_3D::TPrismTopo& prism) const
3528 const bool itTopMeshed = !SubMesh( ID_BOT_FACE )->IsEmpty();
3529 const int zSize = VerticalSize();
3530 if ( zSize < 3 && !itTopMeshed ) return true;
3531 trsf.resize( zSize - 1 );
3533 // Select some node columns by which we will define coordinate system of layers
3535 vector< const TNodeColumn* > columns;
3538 list< TopoDS_Edge >::const_iterator edgeIt = prism.myBottomEdges.begin();
3539 for ( int iE = 0; iE < prism.myNbEdgesInWires.front(); ++iE, ++edgeIt )
3541 if ( SMESH_Algo::isDegenerated( *edgeIt )) continue;
3542 const TParam2ColumnMap* u2colMap =
3543 GetParam2ColumnMap( MeshDS()->ShapeToIndex( *edgeIt ), isReverse );
3544 if ( !u2colMap ) return false;
3545 double f = u2colMap->begin()->first, l = u2colMap->rbegin()->first;
3546 //isReverse = ( edgeIt->Orientation() == TopAbs_REVERSED );
3547 //if ( isReverse ) swap ( f, l ); -- u2colMap takes orientation into account
3548 const int nbCol = 5;
3549 for ( int i = 0; i < nbCol; ++i )
3551 double u = f + i/double(nbCol) * ( l - f );
3552 const TNodeColumn* col = & getColumn( u2colMap, u )->second;
3553 if ( columns.empty() || col != columns.back() )
3554 columns.push_back( col );
3559 // Find tolerance to check transformations
3564 for ( int i = 0; i < columns.size(); ++i )
3565 bndBox.Add( gpXYZ( columns[i]->front() ));
3566 tol2 = bndBox.SquareExtent() * 1e-5;
3569 // Compute transformations
3572 gp_Trsf fromCsZ, toCs0;
3573 gp_Ax3 cs0 = getLayerCoordSys(0, columns, xCol );
3574 //double dist0 = cs0.Location().Distance( gpXYZ( (*columns[0])[0]));
3575 toCs0.SetTransformation( cs0 );
3576 for ( int z = 1; z < zSize; ++z )
3578 gp_Ax3 csZ = getLayerCoordSys(z, columns, xCol );
3579 //double distZ = csZ.Location().Distance( gpXYZ( (*columns[0])[z]));
3580 fromCsZ.SetTransformation( csZ );
3582 gp_Trsf& t = trsf[ z-1 ];
3583 t = fromCsZ * toCs0;
3584 //t.SetScaleFactor( distZ/dist0 ); - it does not work properly, wrong base point
3586 // check a transformation
3587 for ( int i = 0; i < columns.size(); ++i )
3589 gp_Pnt p0 = gpXYZ( (*columns[i])[0] );
3590 gp_Pnt pz = gpXYZ( (*columns[i])[z] );
3591 t.Transforms( p0.ChangeCoord() );
3592 if ( p0.SquareDistance( pz ) > tol2 )
3595 return ( z == zSize - 1 ); // OK if fails only botton->top trsf
3602 //================================================================================
3604 * \brief Check curve orientation of a bootom edge
3605 * \param meshDS - mesh DS
3606 * \param columnsMap - node columns map of side face
3607 * \param bottomEdge - the bootom edge
3608 * \param sideFaceID - side face in-block ID
3609 * \retval bool - true if orientation coinside with in-block forward orientation
3611 //================================================================================
3613 bool StdMeshers_PrismAsBlock::IsForwardEdge(SMESHDS_Mesh* meshDS,
3614 const TParam2ColumnMap& columnsMap,
3615 const TopoDS_Edge & bottomEdge,
3616 const int sideFaceID)
3618 bool isForward = false;
3619 if ( SMESH_MesherHelper::IsClosedEdge( bottomEdge ))
3621 isForward = ( bottomEdge.Orientation() == TopAbs_FORWARD );
3625 const TNodeColumn& firstCol = columnsMap.begin()->second;
3626 const SMDS_MeshNode* bottomNode = firstCol[0];
3627 TopoDS_Shape firstVertex = SMESH_MesherHelper::GetSubShapeByNode( bottomNode, meshDS );
3628 isForward = ( firstVertex.IsSame( TopExp::FirstVertex( bottomEdge, true )));
3630 // on 2 of 4 sides first vertex is end
3631 if ( sideFaceID == ID_Fx1z || sideFaceID == ID_F0yz )
3632 isForward = !isForward;
3636 //=======================================================================
3637 //function : faceGridToPythonDump
3638 //purpose : Prints a script creating a normal grid on the prism side
3639 //=======================================================================
3641 void StdMeshers_PrismAsBlock::faceGridToPythonDump(const SMESH_Block::TShapeID face,
3645 gp_XYZ pOnF[6] = { gp_XYZ(0,0,0), gp_XYZ(0,0,1),
3646 gp_XYZ(0,0,0), gp_XYZ(0,1,0),
3647 gp_XYZ(0,0,0), gp_XYZ(1,0,0) };
3649 cout << "mesh = smesh.Mesh( 'Face " << face << "')" << endl;
3650 SMESH_Block::TFace& f = myFace[ face - ID_FirstF ];
3651 gp_XYZ params = pOnF[ face - ID_FirstF ];
3652 //const int nb = 10; // nb face rows
3653 for ( int j = 0; j <= nb; ++j )
3655 params.SetCoord( f.GetVInd(), double( j )/ nb );
3656 for ( int i = 0; i <= nb; ++i )
3658 params.SetCoord( f.GetUInd(), double( i )/ nb );
3659 gp_XYZ p = f.Point( params );
3660 gp_XY uv = f.GetUV( params );
3661 cout << "mesh.AddNode( " << p.X() << ", " << p.Y() << ", " << p.Z() << " )"
3662 << " # " << 1 + i + j * ( nb + 1 )
3663 << " ( " << i << ", " << j << " ) "
3664 << " UV( " << uv.X() << ", " << uv.Y() << " )" << endl;
3665 ShellPoint( params, p2 );
3666 double dist = ( p2 - p ).Modulus();
3668 cout << "#### dist from ShellPoint " << dist
3669 << " (" << p2.X() << ", " << p2.Y() << ", " << p2.Z() << " ) " << endl;
3672 for ( int j = 0; j < nb; ++j )
3673 for ( int i = 0; i < nb; ++i )
3675 int n = 1 + i + j * ( nb + 1 );
3676 cout << "mesh.AddFace([ "
3677 << n << ", " << n+1 << ", "
3678 << n+nb+2 << ", " << n+nb+1 << "]) " << endl;
3684 //================================================================================
3686 * \brief Constructor
3687 * \param faceID - in-block ID
3688 * \param face - geom FACE
3689 * \param baseEdge - EDGE proreply oriented in the bottom EDGE !!!
3690 * \param columnsMap - map of node columns
3691 * \param first - first normalized param
3692 * \param last - last normalized param
3694 //================================================================================
3696 StdMeshers_PrismAsBlock::TSideFace::TSideFace(SMESH_Mesh& mesh,
3698 const Prism_3D::TQuadList& quadList,
3699 const TopoDS_Edge& baseEdge,
3700 TParam2ColumnMap* columnsMap,
3704 myParamToColumnMap( columnsMap ),
3707 myParams.resize( 1 );
3708 myParams[ 0 ] = make_pair( first, last );
3709 mySurface = PSurface( new BRepAdaptor_Surface( quadList.front()->face ));
3710 myBaseEdge = baseEdge;
3711 myIsForward = StdMeshers_PrismAsBlock::IsForwardEdge( myHelper.GetMeshDS(),
3712 *myParamToColumnMap,
3714 myHelper.SetSubShape( quadList.front()->face );
3716 if ( quadList.size() > 1 ) // side is vertically composite
3718 // fill myShapeID2Surf map to enable finding a right surface by any sub-shape ID
3720 SMESHDS_Mesh* meshDS = myHelper.GetMeshDS();
3722 TopTools_IndexedDataMapOfShapeListOfShape subToFaces;
3723 Prism_3D::TQuadList::const_iterator quad = quadList.begin();
3724 for ( ; quad != quadList.end(); ++quad )
3726 const TopoDS_Face& face = (*quad)->face;
3727 TopExp::MapShapesAndAncestors( face, TopAbs_VERTEX, TopAbs_FACE, subToFaces );
3728 TopExp::MapShapesAndAncestors( face, TopAbs_EDGE, TopAbs_FACE, subToFaces );
3729 myShapeID2Surf.insert( make_pair( meshDS->ShapeToIndex( face ),
3730 PSurface( new BRepAdaptor_Surface( face ))));
3732 for ( int i = 1; i <= subToFaces.Extent(); ++i )
3734 const TopoDS_Shape& sub = subToFaces.FindKey( i );
3735 TopTools_ListOfShape& faces = subToFaces( i );
3736 int subID = meshDS->ShapeToIndex( sub );
3737 int faceID = meshDS->ShapeToIndex( faces.First() );
3738 myShapeID2Surf.insert ( make_pair( subID, myShapeID2Surf[ faceID ]));
3743 //================================================================================
3745 * \brief Constructor of a complex side face
3747 //================================================================================
3749 StdMeshers_PrismAsBlock::TSideFace::
3750 TSideFace(SMESH_Mesh& mesh,
3751 const vector< TSideFace* >& components,
3752 const vector< pair< double, double> > & params)
3753 :myID( components[0] ? components[0]->myID : 0 ),
3754 myParamToColumnMap( 0 ),
3756 myIsForward( true ),
3757 myComponents( components ),
3760 if ( myID == ID_Fx1z || myID == ID_F0yz )
3762 // reverse components
3763 std::reverse( myComponents.begin(), myComponents.end() );
3764 std::reverse( myParams.begin(), myParams.end() );
3765 for ( size_t i = 0; i < myParams.size(); ++i )
3767 const double f = myParams[i].first;
3768 const double l = myParams[i].second;
3769 myParams[i] = make_pair( 1. - l, 1. - f );
3773 //================================================================================
3775 * \brief Copy constructor
3776 * \param other - other side
3778 //================================================================================
3780 StdMeshers_PrismAsBlock::TSideFace::TSideFace( const TSideFace& other ):
3781 myID ( other.myID ),
3782 myParamToColumnMap ( other.myParamToColumnMap ),
3783 mySurface ( other.mySurface ),
3784 myBaseEdge ( other.myBaseEdge ),
3785 myShapeID2Surf ( other.myShapeID2Surf ),
3786 myParams ( other.myParams ),
3787 myIsForward ( other.myIsForward ),
3788 myComponents ( other.myComponents.size() ),
3789 myHelper ( *other.myHelper.GetMesh() )
3791 for (int i = 0 ; i < myComponents.size(); ++i )
3792 myComponents[ i ] = new TSideFace( *other.myComponents[ i ]);
3795 //================================================================================
3797 * \brief Deletes myComponents
3799 //================================================================================
3801 StdMeshers_PrismAsBlock::TSideFace::~TSideFace()
3803 for (int i = 0 ; i < myComponents.size(); ++i )
3804 if ( myComponents[ i ] )
3805 delete myComponents[ i ];
3808 //================================================================================
3810 * \brief Return geometry of the vertical curve
3811 * \param isMax - true means curve located closer to (1,1,1) block point
3812 * \retval Adaptor3d_Curve* - curve adaptor
3814 //================================================================================
3816 Adaptor3d_Curve* StdMeshers_PrismAsBlock::TSideFace::VertiCurve(const bool isMax) const
3818 if ( !myComponents.empty() ) {
3820 return myComponents.back()->VertiCurve(isMax);
3822 return myComponents.front()->VertiCurve(isMax);
3824 double f = myParams[0].first, l = myParams[0].second;
3825 if ( !myIsForward ) std::swap( f, l );
3826 return new TVerticalEdgeAdaptor( myParamToColumnMap, isMax ? l : f );
3829 //================================================================================
3831 * \brief Return geometry of the top or bottom curve
3833 * \retval Adaptor3d_Curve* -
3835 //================================================================================
3837 Adaptor3d_Curve* StdMeshers_PrismAsBlock::TSideFace::HorizCurve(const bool isTop) const
3839 return new THorizontalEdgeAdaptor( this, isTop );
3842 //================================================================================
3844 * \brief Return pcurves
3845 * \param pcurv - array of 4 pcurves
3846 * \retval bool - is a success
3848 //================================================================================
3850 bool StdMeshers_PrismAsBlock::TSideFace::GetPCurves(Adaptor2d_Curve2d* pcurv[4]) const
3852 int iEdge[ 4 ] = { BOTTOM_EDGE, TOP_EDGE, V0_EDGE, V1_EDGE };
3854 for ( int i = 0 ; i < 4 ; ++i ) {
3855 Handle(Geom2d_Line) line;
3856 switch ( iEdge[ i ] ) {
3858 line = new Geom2d_Line( gp_Pnt2d( 0, 1 ), gp::DX2d() ); break;
3860 line = new Geom2d_Line( gp::Origin2d(), gp::DX2d() ); break;
3862 line = new Geom2d_Line( gp::Origin2d(), gp::DY2d() ); break;
3864 line = new Geom2d_Line( gp_Pnt2d( 1, 0 ), gp::DY2d() ); break;
3866 pcurv[ i ] = new Geom2dAdaptor_Curve( line, 0, 1 );
3871 //================================================================================
3873 * \brief Returns geometry of pcurve on a horizontal face
3874 * \param isTop - is top or bottom face
3875 * \param horFace - a horizontal face
3876 * \retval Adaptor2d_Curve2d* - curve adaptor
3878 //================================================================================
3881 StdMeshers_PrismAsBlock::TSideFace::HorizPCurve(const bool isTop,
3882 const TopoDS_Face& horFace) const
3884 return new TPCurveOnHorFaceAdaptor( this, isTop, horFace );
3887 //================================================================================
3889 * \brief Return a component corresponding to parameter
3890 * \param U - parameter along a horizontal size
3891 * \param localU - parameter along a horizontal size of a component
3892 * \retval TSideFace* - found component
3894 //================================================================================
3896 StdMeshers_PrismAsBlock::TSideFace*
3897 StdMeshers_PrismAsBlock::TSideFace::GetComponent(const double U,double & localU) const
3900 if ( myComponents.empty() )
3901 return const_cast<TSideFace*>( this );
3904 for ( i = 0; i < myComponents.size(); ++i )
3905 if ( U < myParams[ i ].second )
3907 if ( i >= myComponents.size() )
3908 i = myComponents.size() - 1;
3910 double f = myParams[ i ].first, l = myParams[ i ].second;
3911 localU = ( U - f ) / ( l - f );
3912 return myComponents[ i ];
3915 //================================================================================
3917 * \brief Find node columns for a parameter
3918 * \param U - parameter along a horizontal edge
3919 * \param col1 - the 1st found column
3920 * \param col2 - the 2nd found column
3921 * \retval r - normalized position of U between the found columns
3923 //================================================================================
3925 double StdMeshers_PrismAsBlock::TSideFace::GetColumns(const double U,
3926 TParam2ColumnIt & col1,
3927 TParam2ColumnIt & col2) const
3929 double u = U, r = 0;
3930 if ( !myComponents.empty() ) {
3931 TSideFace * comp = GetComponent(U,u);
3932 return comp->GetColumns( u, col1, col2 );
3937 double f = myParams[0].first, l = myParams[0].second;
3938 u = f + u * ( l - f );
3940 col1 = col2 = getColumn( myParamToColumnMap, u );
3941 if ( ++col2 == myParamToColumnMap->end() ) {
3946 double uf = col1->first;
3947 double ul = col2->first;
3948 r = ( u - uf ) / ( ul - uf );
3953 //================================================================================
3955 * \brief Return all nodes at a given height together with their normalized parameters
3956 * \param [in] Z - the height of interest
3957 * \param [out] nodes - map of parameter to node
3959 //================================================================================
3961 void StdMeshers_PrismAsBlock::
3962 TSideFace::GetNodesAtZ(const int Z,
3963 map<double, const SMDS_MeshNode* >& nodes ) const
3965 if ( !myComponents.empty() )
3968 for ( size_t i = 0; i < myComponents.size(); ++i )
3970 map<double, const SMDS_MeshNode* > nn;
3971 myComponents[i]->GetNodesAtZ( Z, nn );
3972 map<double, const SMDS_MeshNode* >::iterator u2n = nn.begin();
3973 if ( !nodes.empty() && nodes.rbegin()->second == u2n->second )
3975 const double uRange = myParams[i].second - myParams[i].first;
3976 for ( ; u2n != nn.end(); ++u2n )
3977 nodes.insert( nodes.end(), make_pair( u0 + uRange * u2n->first, u2n->second ));
3983 double f = myParams[0].first, l = myParams[0].second;
3986 const double uRange = l - f;
3987 if ( Abs( uRange ) < std::numeric_limits<double>::min() )
3989 TParam2ColumnIt u2col = getColumn( myParamToColumnMap, myParams[0].first + 1e-3 );
3990 for ( ; u2col != myParamToColumnMap->end(); ++u2col )
3991 if ( u2col->first > myParams[0].second + 1e-9 )
3994 nodes.insert( nodes.end(),
3995 make_pair( ( u2col->first - f ) / uRange, u2col->second[ Z ] ));
3999 //================================================================================
4001 * \brief Return coordinates by normalized params
4002 * \param U - horizontal param
4003 * \param V - vertical param
4004 * \retval gp_Pnt - result point
4006 //================================================================================
4008 gp_Pnt StdMeshers_PrismAsBlock::TSideFace::Value(const Standard_Real U,
4009 const Standard_Real V) const
4011 if ( !myComponents.empty() ) {
4013 TSideFace * comp = GetComponent(U,u);
4014 return comp->Value( u, V );
4017 TParam2ColumnIt u_col1, u_col2;
4018 double vR, hR = GetColumns( U, u_col1, u_col2 );
4020 const SMDS_MeshNode* nn[4];
4022 // BEGIN issue 0020680: Bad cell created by Radial prism in center of torus
4023 // Workaround for a wrongly located point returned by mySurface.Value() for
4024 // UV located near boundary of BSpline surface.
4025 // To bypass the problem, we take point from 3D curve of EDGE.
4026 // It solves pb of the bloc_fiss_new.py
4027 const double tol = 1e-3;
4028 if ( V < tol || V+tol >= 1. )
4030 nn[0] = V < tol ? u_col1->second.front() : u_col1->second.back();
4031 nn[2] = V < tol ? u_col2->second.front() : u_col2->second.back();
4039 TopoDS_Shape s = myHelper.GetSubShapeByNode( nn[0], myHelper.GetMeshDS() );
4040 if ( s.ShapeType() != TopAbs_EDGE )
4041 s = myHelper.GetSubShapeByNode( nn[2], myHelper.GetMeshDS() );
4042 if ( !s.IsNull() && s.ShapeType() == TopAbs_EDGE )
4043 edge = TopoDS::Edge( s );
4045 if ( !edge.IsNull() )
4047 double u1 = myHelper.GetNodeU( edge, nn[0], nn[2] );
4048 double u3 = myHelper.GetNodeU( edge, nn[2], nn[0] );
4049 double u = u1 * ( 1 - hR ) + u3 * hR;
4050 TopLoc_Location loc; double f,l;
4051 Handle(Geom_Curve) curve = BRep_Tool::Curve( edge,loc,f,l );
4052 return curve->Value( u ).Transformed( loc );
4055 // END issue 0020680: Bad cell created by Radial prism in center of torus
4057 vR = getRAndNodes( & u_col1->second, V, nn[0], nn[1] );
4058 vR = getRAndNodes( & u_col2->second, V, nn[2], nn[3] );
4060 if ( !myShapeID2Surf.empty() ) // side is vertically composite
4062 // find a FACE on which the 4 nodes lie
4063 TSideFace* me = (TSideFace*) this;
4064 int notFaceID1 = 0, notFaceID2 = 0;
4065 for ( int i = 0; i < 4; ++i )
4066 if ( nn[i]->GetPosition()->GetTypeOfPosition() == SMDS_TOP_FACE ) // node on FACE
4068 me->mySurface = me->myShapeID2Surf[ nn[i]->getshapeId() ];
4072 else if ( notFaceID1 == 0 ) // node on EDGE or VERTEX
4074 me->mySurface = me->myShapeID2Surf[ nn[i]->getshapeId() ];
4075 notFaceID1 = nn[i]->getshapeId();
4077 else if ( notFaceID1 != nn[i]->getshapeId() ) // node on other EDGE or VERTEX
4079 if ( mySurface != me->myShapeID2Surf[ nn[i]->getshapeId() ])
4080 notFaceID2 = nn[i]->getshapeId();
4082 if ( notFaceID2 ) // no nodes of FACE and nodes are on different FACEs
4084 SMESHDS_Mesh* meshDS = myHelper.GetMeshDS();
4085 TopoDS_Shape face = myHelper.GetCommonAncestor( meshDS->IndexToShape( notFaceID1 ),
4086 meshDS->IndexToShape( notFaceID2 ),
4087 *myHelper.GetMesh(),
4089 if ( face.IsNull() )
4090 throw SALOME_Exception("StdMeshers_PrismAsBlock::TSideFace::Value() face.IsNull()");
4091 int faceID = meshDS->ShapeToIndex( face );
4092 me->mySurface = me->myShapeID2Surf[ faceID ];
4094 throw SALOME_Exception("StdMeshers_PrismAsBlock::TSideFace::Value() !mySurface");
4097 ((TSideFace*) this)->myHelper.SetSubShape( mySurface->Face() );
4099 gp_XY uv1 = myHelper.GetNodeUV( mySurface->Face(), nn[0], nn[2]);
4100 gp_XY uv2 = myHelper.GetNodeUV( mySurface->Face(), nn[1], nn[3]);
4101 gp_XY uv12 = uv1 * ( 1 - vR ) + uv2 * vR;
4103 gp_XY uv3 = myHelper.GetNodeUV( mySurface->Face(), nn[2], nn[0]);
4104 gp_XY uv4 = myHelper.GetNodeUV( mySurface->Face(), nn[3], nn[1]);
4105 gp_XY uv34 = uv3 * ( 1 - vR ) + uv4 * vR;
4107 gp_XY uv = uv12 * ( 1 - hR ) + uv34 * hR;
4109 gp_Pnt p = mySurface->Value( uv.X(), uv.Y() );
4114 //================================================================================
4116 * \brief Return boundary edge
4117 * \param edge - edge index
4118 * \retval TopoDS_Edge - found edge
4120 //================================================================================
4122 TopoDS_Edge StdMeshers_PrismAsBlock::TSideFace::GetEdge(const int iEdge) const
4124 if ( !myComponents.empty() ) {
4126 case V0_EDGE : return myComponents.front()->GetEdge( iEdge );
4127 case V1_EDGE : return myComponents.back() ->GetEdge( iEdge );
4128 default: return TopoDS_Edge();
4132 const SMDS_MeshNode* node = 0;
4133 SMESHDS_Mesh * meshDS = myHelper.GetMesh()->GetMeshDS();
4134 TNodeColumn* column;
4139 column = & (( ++myParamToColumnMap->begin())->second );
4140 node = ( iEdge == TOP_EDGE ) ? column->back() : column->front();
4141 edge = myHelper.GetSubShapeByNode ( node, meshDS );
4142 if ( edge.ShapeType() == TopAbs_VERTEX ) {
4143 column = & ( myParamToColumnMap->begin()->second );
4144 node = ( iEdge == TOP_EDGE ) ? column->back() : column->front();
4149 bool back = ( iEdge == V1_EDGE );
4150 if ( !myIsForward ) back = !back;
4152 column = & ( myParamToColumnMap->rbegin()->second );
4154 column = & ( myParamToColumnMap->begin()->second );
4155 if ( column->size() > 0 )
4156 edge = myHelper.GetSubShapeByNode( (*column)[ 1 ], meshDS );
4157 if ( edge.IsNull() || edge.ShapeType() == TopAbs_VERTEX )
4158 node = column->front();
4163 if ( !edge.IsNull() && edge.ShapeType() == TopAbs_EDGE )
4164 return TopoDS::Edge( edge );
4166 // find edge by 2 vertices
4167 TopoDS_Shape V1 = edge;
4168 TopoDS_Shape V2 = myHelper.GetSubShapeByNode( node, meshDS );
4169 if ( !V2.IsNull() && V2.ShapeType() == TopAbs_VERTEX && !V2.IsSame( V1 ))
4171 TopoDS_Shape ancestor = myHelper.GetCommonAncestor( V1, V2, *myHelper.GetMesh(), TopAbs_EDGE);
4172 if ( !ancestor.IsNull() )
4173 return TopoDS::Edge( ancestor );
4175 return TopoDS_Edge();
4178 //================================================================================
4180 * \brief Fill block sub-shapes
4181 * \param shapeMap - map to fill in
4182 * \retval int - nb inserted sub-shapes
4184 //================================================================================
4186 int StdMeshers_PrismAsBlock::TSideFace::InsertSubShapes(TBlockShapes& shapeMap) const
4191 vector< int > edgeIdVec;
4192 SMESH_Block::GetFaceEdgesIDs( myID, edgeIdVec );
4194 for ( int i = BOTTOM_EDGE; i <=V1_EDGE ; ++i ) {
4195 TopoDS_Edge e = GetEdge( i );
4196 if ( !e.IsNull() ) {
4197 nbInserted += SMESH_Block::Insert( e, edgeIdVec[ i ], shapeMap);
4201 // Insert corner vertices
4203 TParam2ColumnIt col1, col2 ;
4204 vector< int > vertIdVec;
4207 SMESH_Block::GetEdgeVertexIDs( edgeIdVec[ V0_EDGE ], vertIdVec);
4208 GetColumns(0, col1, col2 );
4209 const SMDS_MeshNode* node0 = col1->second.front();
4210 const SMDS_MeshNode* node1 = col1->second.back();
4211 TopoDS_Shape v0 = myHelper.GetSubShapeByNode( node0, myHelper.GetMeshDS());
4212 TopoDS_Shape v1 = myHelper.GetSubShapeByNode( node1, myHelper.GetMeshDS());
4213 if ( v0.ShapeType() == TopAbs_VERTEX ) {
4214 nbInserted += SMESH_Block::Insert( v0, vertIdVec[ 0 ], shapeMap);
4216 if ( v1.ShapeType() == TopAbs_VERTEX ) {
4217 nbInserted += SMESH_Block::Insert( v1, vertIdVec[ 1 ], shapeMap);
4221 SMESH_Block::GetEdgeVertexIDs( edgeIdVec[ V1_EDGE ], vertIdVec);
4222 GetColumns(1, col1, col2 );
4223 node0 = col2->second.front();
4224 node1 = col2->second.back();
4225 v0 = myHelper.GetSubShapeByNode( node0, myHelper.GetMeshDS());
4226 v1 = myHelper.GetSubShapeByNode( node1, myHelper.GetMeshDS());
4227 if ( v0.ShapeType() == TopAbs_VERTEX ) {
4228 nbInserted += SMESH_Block::Insert( v0, vertIdVec[ 0 ], shapeMap);
4230 if ( v1.ShapeType() == TopAbs_VERTEX ) {
4231 nbInserted += SMESH_Block::Insert( v1, vertIdVec[ 1 ], shapeMap);
4234 // TopoDS_Vertex V0, V1, Vcom;
4235 // TopExp::Vertices( myBaseEdge, V0, V1, true );
4236 // if ( !myIsForward ) std::swap( V0, V1 );
4238 // // bottom vertex IDs
4239 // SMESH_Block::GetEdgeVertexIDs( edgeIdVec[ _u0 ], vertIdVec);
4240 // SMESH_Block::Insert( V0, vertIdVec[ 0 ], shapeMap);
4241 // SMESH_Block::Insert( V1, vertIdVec[ 1 ], shapeMap);
4243 // TopoDS_Edge sideEdge = GetEdge( V0_EDGE );
4244 // if ( sideEdge.IsNull() || !TopExp::CommonVertex( botEdge, sideEdge, Vcom ))
4247 // // insert one side edge
4249 // if ( Vcom.IsSame( V0 )) edgeID = edgeIdVec[ _v0 ];
4250 // else edgeID = edgeIdVec[ _v1 ];
4251 // SMESH_Block::Insert( sideEdge, edgeID, shapeMap);
4253 // // top vertex of the side edge
4254 // SMESH_Block::GetEdgeVertexIDs( edgeID, vertIdVec);
4255 // TopoDS_Vertex Vtop = TopExp::FirstVertex( sideEdge );
4256 // if ( Vcom.IsSame( Vtop ))
4257 // Vtop = TopExp::LastVertex( sideEdge );
4258 // SMESH_Block::Insert( Vtop, vertIdVec[ 1 ], shapeMap);
4260 // // other side edge
4261 // sideEdge = GetEdge( V1_EDGE );
4262 // if ( sideEdge.IsNull() )
4264 // if ( edgeID = edgeIdVec[ _v1 ]) edgeID = edgeIdVec[ _v0 ];
4265 // else edgeID = edgeIdVec[ _v1 ];
4266 // SMESH_Block::Insert( sideEdge, edgeID, shapeMap);
4269 // TopoDS_Edge topEdge = GetEdge( TOP_EDGE );
4270 // SMESH_Block::Insert( topEdge, edgeIdVec[ _u1 ], shapeMap);
4272 // // top vertex of the other side edge
4273 // if ( !TopExp::CommonVertex( topEdge, sideEdge, Vcom ))
4275 // SMESH_Block::GetEdgeVertexIDs( edgeID, vertIdVec );
4276 // SMESH_Block::Insert( Vcom, vertIdVec[ 1 ], shapeMap);
4281 //================================================================================
4283 * \brief Dump ids of nodes of sides
4285 //================================================================================
4287 void StdMeshers_PrismAsBlock::TSideFace::dumpNodes(int nbNodes) const
4290 cout << endl << "NODES OF FACE "; SMESH_Block::DumpShapeID( myID, cout ) << endl;
4291 THorizontalEdgeAdaptor* hSize0 = (THorizontalEdgeAdaptor*) HorizCurve(0);
4292 cout << "Horiz side 0: "; hSize0->dumpNodes(nbNodes); cout << endl;
4293 THorizontalEdgeAdaptor* hSize1 = (THorizontalEdgeAdaptor*) HorizCurve(1);
4294 cout << "Horiz side 1: "; hSize1->dumpNodes(nbNodes); cout << endl;
4295 TVerticalEdgeAdaptor* vSide0 = (TVerticalEdgeAdaptor*) VertiCurve(0);
4296 cout << "Verti side 0: "; vSide0->dumpNodes(nbNodes); cout << endl;
4297 TVerticalEdgeAdaptor* vSide1 = (TVerticalEdgeAdaptor*) VertiCurve(1);
4298 cout << "Verti side 1: "; vSide1->dumpNodes(nbNodes); cout << endl;
4299 delete hSize0; delete hSize1; delete vSide0; delete vSide1;
4303 //================================================================================
4305 * \brief Creates TVerticalEdgeAdaptor
4306 * \param columnsMap - node column map
4307 * \param parameter - normalized parameter
4309 //================================================================================
4311 StdMeshers_PrismAsBlock::TVerticalEdgeAdaptor::
4312 TVerticalEdgeAdaptor( const TParam2ColumnMap* columnsMap, const double parameter)
4314 myNodeColumn = & getColumn( columnsMap, parameter )->second;
4317 //================================================================================
4319 * \brief Return coordinates for the given normalized parameter
4320 * \param U - normalized parameter
4321 * \retval gp_Pnt - coordinates
4323 //================================================================================
4325 gp_Pnt StdMeshers_PrismAsBlock::TVerticalEdgeAdaptor::Value(const Standard_Real U) const
4327 const SMDS_MeshNode* n1;
4328 const SMDS_MeshNode* n2;
4329 double r = getRAndNodes( myNodeColumn, U, n1, n2 );
4330 return gpXYZ(n1) * ( 1 - r ) + gpXYZ(n2) * r;
4333 //================================================================================
4335 * \brief Dump ids of nodes
4337 //================================================================================
4339 void StdMeshers_PrismAsBlock::TVerticalEdgeAdaptor::dumpNodes(int nbNodes) const
4342 for ( int i = 0; i < nbNodes && i < myNodeColumn->size(); ++i )
4343 cout << (*myNodeColumn)[i]->GetID() << " ";
4344 if ( nbNodes < myNodeColumn->size() )
4345 cout << myNodeColumn->back()->GetID();
4349 //================================================================================
4351 * \brief Return coordinates for the given normalized parameter
4352 * \param U - normalized parameter
4353 * \retval gp_Pnt - coordinates
4355 //================================================================================
4357 gp_Pnt StdMeshers_PrismAsBlock::THorizontalEdgeAdaptor::Value(const Standard_Real U) const
4359 return mySide->TSideFace::Value( U, myV );
4362 //================================================================================
4364 * \brief Dump ids of <nbNodes> first nodes and the last one
4366 //================================================================================
4368 void StdMeshers_PrismAsBlock::THorizontalEdgeAdaptor::dumpNodes(int nbNodes) const
4371 // Not bedugged code. Last node is sometimes incorrect
4372 const TSideFace* side = mySide;
4374 if ( mySide->IsComplex() )
4375 side = mySide->GetComponent(0,u);
4377 TParam2ColumnIt col, col2;
4378 TParam2ColumnMap* u2cols = side->GetColumns();
4379 side->GetColumns( u , col, col2 );
4381 int j, i = myV ? mySide->ColumnHeight()-1 : 0;
4383 const SMDS_MeshNode* n = 0;
4384 const SMDS_MeshNode* lastN
4385 = side->IsForward() ? u2cols->rbegin()->second[ i ] : u2cols->begin()->second[ i ];
4386 for ( j = 0; j < nbNodes && n != lastN; ++j )
4388 n = col->second[ i ];
4389 cout << n->GetID() << " ";
4390 if ( side->IsForward() )
4398 if ( mySide->IsComplex() )
4399 side = mySide->GetComponent(1,u);
4401 side->GetColumns( u , col, col2 );
4402 if ( n != col->second[ i ] )
4403 cout << col->second[ i ]->GetID();
4407 //================================================================================
4409 * \brief Costructor of TPCurveOnHorFaceAdaptor fills its map of
4410 * normalized parameter to node UV on a horizontal face
4411 * \param [in] sideFace - lateral prism side
4412 * \param [in] isTop - is \a horFace top or bottom of the prism
4413 * \param [in] horFace - top or bottom face of the prism
4415 //================================================================================
4417 StdMeshers_PrismAsBlock::
4418 TPCurveOnHorFaceAdaptor::TPCurveOnHorFaceAdaptor( const TSideFace* sideFace,
4420 const TopoDS_Face& horFace)
4422 if ( sideFace && !horFace.IsNull() )
4424 //cout << "\n\t FACE " << sideFace->FaceID() << endl;
4425 const int Z = isTop ? sideFace->ColumnHeight() - 1 : 0;
4426 map<double, const SMDS_MeshNode* > u2nodes;
4427 sideFace->GetNodesAtZ( Z, u2nodes );
4428 if ( u2nodes.empty() )
4431 SMESH_MesherHelper helper( *sideFace->GetMesh() );
4432 helper.SetSubShape( horFace );
4437 Handle(Geom2d_Curve) C2d;
4439 const double tol = 10 * helper.MaxTolerance( horFace );
4440 const SMDS_MeshNode* prevNode = u2nodes.rbegin()->second;
4442 map<double, const SMDS_MeshNode* >::iterator u2n = u2nodes.begin();
4443 for ( ; u2n != u2nodes.end(); ++u2n )
4445 const SMDS_MeshNode* n = u2n->second;
4447 if ( n->GetPosition()->GetTypeOfPosition() == SMDS_TOP_EDGE )
4449 if ( n->getshapeId() != edgeID )
4452 edgeID = n->getshapeId();
4453 TopoDS_Shape S = helper.GetSubShapeByNode( n, helper.GetMeshDS() );
4454 if ( !S.IsNull() && S.ShapeType() == TopAbs_EDGE )
4456 C2d = BRep_Tool::CurveOnSurface( TopoDS::Edge( S ), horFace, f,l );
4459 if ( !C2d.IsNull() )
4461 double u = static_cast< const SMDS_EdgePosition* >( n->GetPosition() )->GetUParameter();
4462 if ( f <= u && u <= l )
4464 uv = C2d->Value( u ).XY();
4465 okUV = helper.CheckNodeUV( horFace, n, uv, tol );
4470 uv = helper.GetNodeUV( horFace, n, prevNode, &okUV );
4472 myUVmap.insert( myUVmap.end(), make_pair( u2n->first, uv ));
4473 // cout << n->getshapeId() << " N " << n->GetID()
4474 // << " \t" << uv.X() << ", " << uv.Y() << " \t" << u2n->first << endl;
4481 //================================================================================
4483 * \brief Return UV on pcurve for the given normalized parameter
4484 * \param U - normalized parameter
4485 * \retval gp_Pnt - coordinates
4487 //================================================================================
4489 gp_Pnt2d StdMeshers_PrismAsBlock::TPCurveOnHorFaceAdaptor::Value(const Standard_Real U) const
4491 map< double, gp_XY >::const_iterator i1 = myUVmap.upper_bound( U );
4493 if ( i1 == myUVmap.end() )
4494 return myUVmap.empty() ? gp_XY(0,0) : myUVmap.rbegin()->second;
4496 if ( i1 == myUVmap.begin() )
4497 return (*i1).second;
4499 map< double, gp_XY >::const_iterator i2 = i1--;
4501 double r = ( U - i1->first ) / ( i2->first - i1->first );
4502 return i1->second * ( 1 - r ) + i2->second * r;
4505 //================================================================================
4507 * \brief Projects internal nodes using transformation found by boundary nodes
4509 //================================================================================
4511 bool StdMeshers_Sweeper::projectIntPoints(const vector< gp_XYZ >& fromBndPoints,
4512 const vector< gp_XYZ >& toBndPoints,
4513 const vector< gp_XYZ >& fromIntPoints,
4514 vector< gp_XYZ >& toIntPoints,
4515 NSProjUtils::TrsfFinder3D& trsf,
4516 vector< gp_XYZ > * bndError)
4518 // find transformation
4519 if ( trsf.IsIdentity() && !trsf.Solve( fromBndPoints, toBndPoints ))
4522 // compute internal points using the found trsf
4523 for ( size_t iP = 0; iP < fromIntPoints.size(); ++iP )
4525 toIntPoints[ iP ] = trsf.Transform( fromIntPoints[ iP ]);
4528 // compute boundary error
4531 bndError->resize( fromBndPoints.size() );
4533 for ( size_t iP = 0; iP < fromBndPoints.size(); ++iP )
4535 fromTrsf = trsf.Transform( fromBndPoints[ iP ] );
4536 (*bndError)[ iP ] = toBndPoints[ iP ] - fromTrsf;
4542 //================================================================================
4544 * \brief Add boundary error to ineternal points
4546 //================================================================================
4548 void StdMeshers_Sweeper::applyBoundaryError(const vector< gp_XYZ >& bndPoints,
4549 const vector< gp_XYZ >& bndError1,
4550 const vector< gp_XYZ >& bndError2,
4552 vector< gp_XYZ >& intPoints,
4553 vector< double >& int2BndDist)
4555 // fix each internal point
4556 const double eps = 1e-100;
4557 for ( size_t iP = 0; iP < intPoints.size(); ++iP )
4559 gp_XYZ & intPnt = intPoints[ iP ];
4561 // compute distance from intPnt to each boundary node
4562 double int2BndDistSum = 0;
4563 for ( size_t iBnd = 0; iBnd < bndPoints.size(); ++iBnd )
4565 int2BndDist[ iBnd ] = 1 / (( intPnt - bndPoints[ iBnd ]).SquareModulus() + eps );
4566 int2BndDistSum += int2BndDist[ iBnd ];
4570 for ( size_t iBnd = 0; iBnd < bndPoints.size(); ++iBnd )
4572 intPnt += bndError1[ iBnd ] * ( 1 - r ) * int2BndDist[ iBnd ] / int2BndDistSum;
4573 intPnt += bndError2[ iBnd ] * r * int2BndDist[ iBnd ] / int2BndDistSum;
4578 //================================================================================
4580 * \brief Creates internal nodes of the prism
4582 //================================================================================
4584 bool StdMeshers_Sweeper::ComputeNodes( SMESH_MesherHelper& helper,
4586 const bool allowHighBndError)
4588 const size_t zSize = myBndColumns[0]->size();
4589 const size_t zSrc = 0, zTgt = zSize-1;
4590 if ( zSize < 3 ) return true;
4592 vector< vector< gp_XYZ > > intPntsOfLayer( zSize ); // node coodinates to compute
4593 // set coordinates of src and tgt nodes
4594 for ( size_t z = 0; z < intPntsOfLayer.size(); ++z )
4595 intPntsOfLayer[ z ].resize( myIntColumns.size() );
4596 for ( size_t iP = 0; iP < myIntColumns.size(); ++iP )
4598 intPntsOfLayer[ zSrc ][ iP ] = intPoint( iP, zSrc );
4599 intPntsOfLayer[ zTgt ][ iP ] = intPoint( iP, zTgt );
4602 // compute coordinates of internal nodes by projecting (transfroming) src and tgt
4603 // nodes towards the central layer
4605 vector< NSProjUtils::TrsfFinder3D > trsfOfLayer( zSize );
4606 vector< vector< gp_XYZ > > bndError( zSize );
4608 // boundary points used to compute an affine transformation from a layer to a next one
4609 vector< gp_XYZ > fromSrcBndPnts( myBndColumns.size() ), fromTgtBndPnts( myBndColumns.size() );
4610 vector< gp_XYZ > toSrcBndPnts ( myBndColumns.size() ), toTgtBndPnts ( myBndColumns.size() );
4611 for ( size_t iP = 0; iP < myBndColumns.size(); ++iP )
4613 fromSrcBndPnts[ iP ] = bndPoint( iP, zSrc );
4614 fromTgtBndPnts[ iP ] = bndPoint( iP, zTgt );
4617 size_t zS = zSrc + 1;
4618 size_t zT = zTgt - 1;
4619 for ( ; zS < zT; ++zS, --zT ) // vertical loop on layers
4621 for ( size_t iP = 0; iP < myBndColumns.size(); ++iP )
4623 toSrcBndPnts[ iP ] = bndPoint( iP, zS );
4624 toTgtBndPnts[ iP ] = bndPoint( iP, zT );
4626 if (! projectIntPoints( fromSrcBndPnts, toSrcBndPnts,
4627 intPntsOfLayer[ zS-1 ], intPntsOfLayer[ zS ],
4628 trsfOfLayer [ zS-1 ], & bndError[ zS-1 ]))
4630 if (! projectIntPoints( fromTgtBndPnts, toTgtBndPnts,
4631 intPntsOfLayer[ zT+1 ], intPntsOfLayer[ zT ],
4632 trsfOfLayer [ zT+1 ], & bndError[ zT+1 ]))
4635 // if ( zT == zTgt - 1 )
4637 // for ( size_t iP = 0; iP < myBndColumns.size(); ++iP )
4639 // gp_XYZ fromTrsf = trsfOfLayer [ zT+1].Transform( fromTgtBndPnts[ iP ] );
4640 // cout << "mesh.AddNode( "
4641 // << fromTrsf.X() << ", "
4642 // << fromTrsf.Y() << ", "
4643 // << fromTrsf.Z() << ") " << endl;
4645 // for ( size_t iP = 0; iP < myIntColumns.size(); ++iP )
4646 // cout << "mesh.AddNode( "
4647 // << intPntsOfLayer[ zT ][ iP ].X() << ", "
4648 // << intPntsOfLayer[ zT ][ iP ].Y() << ", "
4649 // << intPntsOfLayer[ zT ][ iP ].Z() << ") " << endl;
4652 fromTgtBndPnts.swap( toTgtBndPnts );
4653 fromSrcBndPnts.swap( toSrcBndPnts );
4656 // Compute two projections of internal points to the central layer
4657 // in order to evaluate an error of internal points
4659 bool centerIntErrorIsSmall;
4660 vector< gp_XYZ > centerSrcIntPnts( myIntColumns.size() );
4661 vector< gp_XYZ > centerTgtIntPnts( myIntColumns.size() );
4663 for ( size_t iP = 0; iP < myBndColumns.size(); ++iP )
4665 toSrcBndPnts[ iP ] = bndPoint( iP, zS );
4666 toTgtBndPnts[ iP ] = bndPoint( iP, zT );
4668 if (! projectIntPoints( fromSrcBndPnts, toSrcBndPnts,
4669 intPntsOfLayer[ zS-1 ], centerSrcIntPnts,
4670 trsfOfLayer [ zS-1 ], & bndError[ zS-1 ]))
4672 if (! projectIntPoints( fromTgtBndPnts, toTgtBndPnts,
4673 intPntsOfLayer[ zT+1 ], centerTgtIntPnts,
4674 trsfOfLayer [ zT+1 ], & bndError[ zT+1 ]))
4677 // evaluate an error of internal points on the central layer
4678 centerIntErrorIsSmall = true;
4679 if ( zS == zT ) // odd zSize
4681 for ( size_t iP = 0; ( iP < myIntColumns.size() && centerIntErrorIsSmall ); ++iP )
4682 centerIntErrorIsSmall =
4683 (centerSrcIntPnts[ iP ] - centerTgtIntPnts[ iP ]).SquareModulus() < tol*tol;
4687 for ( size_t iP = 0; ( iP < myIntColumns.size() && centerIntErrorIsSmall ); ++iP )
4688 centerIntErrorIsSmall =
4689 (intPntsOfLayer[ zS-1 ][ iP ] - centerTgtIntPnts[ iP ]).SquareModulus() < tol*tol;
4692 // Evaluate an error of boundary points
4694 bool bndErrorIsSmall = true;
4695 for ( size_t iP = 0; ( iP < myBndColumns.size() && bndErrorIsSmall ); ++iP )
4697 double sumError = 0;
4698 for ( size_t z = 1; z < zS; ++z ) // loop on layers
4699 sumError += ( bndError[ z-1 ][ iP ].Modulus() +
4700 bndError[ zSize-z ][ iP ].Modulus() );
4702 bndErrorIsSmall = ( sumError < tol );
4705 if ( !bndErrorIsSmall && !allowHighBndError )
4708 // compute final points on the central layer
4709 std::vector< double > int2BndDist( myBndColumns.size() ); // work array of applyBoundaryError()
4710 double r = zS / ( zSize - 1.);
4713 for ( size_t iP = 0; iP < myIntColumns.size(); ++iP )
4715 intPntsOfLayer[ zS ][ iP ] =
4716 ( 1 - r ) * centerSrcIntPnts[ iP ] + r * centerTgtIntPnts[ iP ];
4718 if ( !bndErrorIsSmall )
4720 applyBoundaryError( toSrcBndPnts, bndError[ zS-1 ], bndError[ zS+1 ], r,
4721 intPntsOfLayer[ zS ], int2BndDist );
4726 for ( size_t iP = 0; iP < myIntColumns.size(); ++iP )
4728 intPntsOfLayer[ zS ][ iP ] =
4729 r * intPntsOfLayer[ zS ][ iP ] + ( 1 - r ) * centerSrcIntPnts[ iP ];
4730 intPntsOfLayer[ zT ][ iP ] =
4731 r * intPntsOfLayer[ zT ][ iP ] + ( 1 - r ) * centerTgtIntPnts[ iP ];
4733 if ( !bndErrorIsSmall )
4735 applyBoundaryError( toSrcBndPnts, bndError[ zS-1 ], bndError[ zS+1 ], r,
4736 intPntsOfLayer[ zS ], int2BndDist );
4737 applyBoundaryError( toTgtBndPnts, bndError[ zT+1 ], bndError[ zT-1 ], r,
4738 intPntsOfLayer[ zT ], int2BndDist );
4742 //centerIntErrorIsSmall = true;
4743 //bndErrorIsSmall = true;
4744 if ( !centerIntErrorIsSmall )
4746 // Compensate the central error; continue adding projection
4747 // by going from central layer to the source and target ones
4749 vector< gp_XYZ >& fromSrcIntPnts = centerSrcIntPnts;
4750 vector< gp_XYZ >& fromTgtIntPnts = centerTgtIntPnts;
4751 vector< gp_XYZ > toSrcIntPnts( myIntColumns.size() );
4752 vector< gp_XYZ > toTgtIntPnts( myIntColumns.size() );
4753 vector< gp_XYZ > srcBndError( myBndColumns.size() );
4754 vector< gp_XYZ > tgtBndError( myBndColumns.size() );
4756 fromTgtBndPnts.swap( toTgtBndPnts );
4757 fromSrcBndPnts.swap( toSrcBndPnts );
4759 for ( ++zS, --zT; zS < zTgt; ++zS, --zT ) // vertical loop on layers
4761 // invert transformation
4762 if ( !trsfOfLayer[ zS+1 ].Invert() )
4763 trsfOfLayer[ zS+1 ] = NSProjUtils::TrsfFinder3D(); // to recompute
4764 if ( !trsfOfLayer[ zT-1 ].Invert() )
4765 trsfOfLayer[ zT-1 ] = NSProjUtils::TrsfFinder3D();
4767 // project internal nodes and compute bnd error
4768 for ( size_t iP = 0; iP < myBndColumns.size(); ++iP )
4770 toSrcBndPnts[ iP ] = bndPoint( iP, zS );
4771 toTgtBndPnts[ iP ] = bndPoint( iP, zT );
4773 projectIntPoints( fromSrcBndPnts, toSrcBndPnts,
4774 fromSrcIntPnts, toSrcIntPnts,
4775 trsfOfLayer[ zS+1 ], & srcBndError );
4776 projectIntPoints( fromTgtBndPnts, toTgtBndPnts,
4777 fromTgtIntPnts, toTgtIntPnts,
4778 trsfOfLayer[ zT-1 ], & tgtBndError );
4780 // if ( zS == zTgt - 1 )
4782 // cout << "mesh2 = smesh.Mesh()" << endl;
4783 // for ( size_t iP = 0; iP < myBndColumns.size(); ++iP )
4785 // gp_XYZ fromTrsf = trsfOfLayer [ zS+1].Transform( fromSrcBndPnts[ iP ] );
4786 // cout << "mesh2.AddNode( "
4787 // << fromTrsf.X() << ", "
4788 // << fromTrsf.Y() << ", "
4789 // << fromTrsf.Z() << ") " << endl;
4791 // for ( size_t iP = 0; iP < myIntColumns.size(); ++iP )
4792 // cout << "mesh2.AddNode( "
4793 // << toSrcIntPnts[ iP ].X() << ", "
4794 // << toSrcIntPnts[ iP ].Y() << ", "
4795 // << toSrcIntPnts[ iP ].Z() << ") " << endl;
4798 // sum up 2 projections
4799 r = zS / ( zSize - 1.);
4800 vector< gp_XYZ >& zSIntPnts = intPntsOfLayer[ zS ];
4801 vector< gp_XYZ >& zTIntPnts = intPntsOfLayer[ zT ];
4802 for ( size_t iP = 0; iP < myIntColumns.size(); ++iP )
4804 zSIntPnts[ iP ] = r * zSIntPnts[ iP ] + ( 1 - r ) * toSrcIntPnts[ iP ];
4805 zTIntPnts[ iP ] = r * zTIntPnts[ iP ] + ( 1 - r ) * toTgtIntPnts[ iP ];
4808 // compensate bnd error
4809 if ( !bndErrorIsSmall )
4811 applyBoundaryError( toSrcBndPnts, srcBndError, bndError[ zS+1 ], r,
4812 intPntsOfLayer[ zS ], int2BndDist );
4813 applyBoundaryError( toTgtBndPnts, tgtBndError, bndError[ zT-1 ], r,
4814 intPntsOfLayer[ zT ], int2BndDist );
4817 fromSrcBndPnts.swap( toSrcBndPnts );
4818 fromSrcIntPnts.swap( toSrcIntPnts );
4819 fromTgtBndPnts.swap( toTgtBndPnts );
4820 fromTgtIntPnts.swap( toTgtIntPnts );
4822 } // if ( !centerIntErrorIsSmall )
4824 else if ( !bndErrorIsSmall )
4828 for ( ; zS < zT; ++zS, --zT ) // vertical loop on layers
4830 for ( size_t iP = 0; iP < myBndColumns.size(); ++iP )
4832 toSrcBndPnts[ iP ] = bndPoint( iP, zS );
4833 toTgtBndPnts[ iP ] = bndPoint( iP, zT );
4835 // compensate bnd error
4836 applyBoundaryError( toSrcBndPnts, bndError[ zS-1 ], bndError[ zS-1 ], 0.5,
4837 intPntsOfLayer[ zS ], int2BndDist );
4838 applyBoundaryError( toTgtBndPnts, bndError[ zT+1 ], bndError[ zT+1 ], 0.5,
4839 intPntsOfLayer[ zT ], int2BndDist );
4843 // cout << "centerIntErrorIsSmall = " << centerIntErrorIsSmall<< endl;
4844 // cout << "bndErrorIsSmall = " << bndErrorIsSmall<< endl;
4847 for ( size_t iP = 0; iP < myIntColumns.size(); ++iP )
4849 vector< const SMDS_MeshNode* > & nodeCol = *myIntColumns[ iP ];
4850 for ( size_t z = zSrc + 1; z < zTgt; ++z ) // vertical loop on layers
4852 const gp_XYZ & xyz = intPntsOfLayer[ z ][ iP ];
4853 if ( !( nodeCol[ z ] = helper.AddNode( xyz.X(), xyz.Y(), xyz.Z() )))