1 // Copyright (C) 2007-2016 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>
54 #include <Standard_ErrorHandler.hxx>
56 #include <TopExp_Explorer.hxx>
57 #include <TopTools_ListIteratorOfListOfShape.hxx>
58 #include <TopTools_ListOfShape.hxx>
59 #include <TopTools_MapOfShape.hxx>
60 #include <TopTools_SequenceOfShape.hxx>
70 #define RETURN_BAD_RESULT(msg) { MESSAGE(")-: Error: " << msg); return false; }
71 #define gpXYZ(n) SMESH_TNodeXYZ(n)
74 #define DBGOUT(msg) //cout << msg << endl;
75 #define SHOWYXZ(msg, xyz) \
76 //{ gp_Pnt p (xyz); cout << msg << " ("<< p.X() << "; " <<p.Y() << "; " <<p.Z() << ") " <<endl; }
79 #define SHOWYXZ(msg, xyz)
82 namespace NSProjUtils = StdMeshers_ProjectionUtils;
84 typedef SMESH_Comment TCom;
86 enum { ID_BOT_FACE = SMESH_Block::ID_Fxy0,
87 ID_TOP_FACE = SMESH_Block::ID_Fxy1,
88 BOTTOM_EDGE = 0, TOP_EDGE, V0_EDGE, V1_EDGE, // edge IDs in face
89 NB_WALL_FACES = 4 }; //
93 //=======================================================================
95 * \brief Quadrangle algorithm
97 struct TQuadrangleAlgo : public StdMeshers_Quadrangle_2D
99 TQuadrangleAlgo(int studyId, SMESH_Gen* gen)
100 : StdMeshers_Quadrangle_2D( gen->GetANewId(), studyId, gen)
103 static StdMeshers_Quadrangle_2D* instance( SMESH_Algo* fatherAlgo,
104 SMESH_MesherHelper* helper=0)
106 static TQuadrangleAlgo* algo = new TQuadrangleAlgo( fatherAlgo->GetStudyId(),
107 fatherAlgo->GetGen() );
110 algo->myProxyMesh->GetMesh() != helper->GetMesh() )
111 algo->myProxyMesh.reset( new SMESH_ProxyMesh( *helper->GetMesh() ));
113 algo->myQuadList.clear();
116 algo->_quadraticMesh = helper->GetIsQuadratic();
121 //=======================================================================
123 * \brief Algorithm projecting 1D mesh
125 struct TProjction1dAlgo : public StdMeshers_Projection_1D
127 StdMeshers_ProjectionSource1D myHyp;
129 TProjction1dAlgo(int studyId, SMESH_Gen* gen)
130 : StdMeshers_Projection_1D( gen->GetANewId(), studyId, gen),
131 myHyp( gen->GetANewId(), studyId, gen)
133 StdMeshers_Projection_1D::_sourceHypo = & myHyp;
135 static TProjction1dAlgo* instance( SMESH_Algo* fatherAlgo )
137 static TProjction1dAlgo* algo = new TProjction1dAlgo( fatherAlgo->GetStudyId(),
138 fatherAlgo->GetGen() );
142 //=======================================================================
144 * \brief Algorithm projecting 2D mesh
146 struct TProjction2dAlgo : public StdMeshers_Projection_1D2D
148 StdMeshers_ProjectionSource2D myHyp;
150 TProjction2dAlgo(int studyId, SMESH_Gen* gen)
151 : StdMeshers_Projection_1D2D( gen->GetANewId(), studyId, gen),
152 myHyp( gen->GetANewId(), studyId, gen)
154 StdMeshers_Projection_2D::_sourceHypo = & myHyp;
156 static TProjction2dAlgo* instance( SMESH_Algo* fatherAlgo )
158 static TProjction2dAlgo* algo = new TProjction2dAlgo( fatherAlgo->GetStudyId(),
159 fatherAlgo->GetGen() );
162 const NSProjUtils::TNodeNodeMap& GetNodesMap()
164 return _src2tgtNodes;
166 void SetEventListener( SMESH_subMesh* tgtSubMesh )
168 NSProjUtils::SetEventListener( tgtSubMesh,
169 _sourceHypo->GetSourceFace(),
170 _sourceHypo->GetSourceMesh() );
173 //=======================================================================
175 * \brief Returns already computed EDGEs
177 void getPrecomputedEdges( SMESH_MesherHelper& theHelper,
178 const TopoDS_Shape& theShape,
179 vector< TopoDS_Edge >& theEdges)
183 SMESHDS_Mesh* meshDS = theHelper.GetMeshDS();
186 TopTools_IndexedMapOfShape edges;
187 TopExp::MapShapes( theShape, TopAbs_EDGE, edges );
188 for ( int iE = 1; iE <= edges.Extent(); ++iE )
190 const TopoDS_Shape edge = edges( iE );
191 if (( ! ( sm = meshDS->MeshElements( edge ))) ||
192 ( sm->NbElements() == 0 ))
195 // there must not be FACEs meshed with triangles and sharing a computed EDGE
196 // as the precomputed EDGEs are used for propagation other to 'vertical' EDGEs
197 bool faceFound = false;
198 PShapeIteratorPtr faceIt =
199 theHelper.GetAncestors( edge, *theHelper.GetMesh(), TopAbs_FACE );
200 while ( const TopoDS_Shape* face = faceIt->next() )
202 if (( sm = meshDS->MeshElements( *face )) &&
203 ( sm->NbElements() > 0 ) &&
204 ( !theHelper.IsSameElemGeometry( sm, SMDSGeom_QUADRANGLE ) ))
210 theEdges.push_back( TopoDS::Edge( edge ));
214 //================================================================================
216 * \brief Make \a botE be the BOTTOM_SIDE of \a quad.
217 * Return false if the BOTTOM_SIDE is composite
219 //================================================================================
221 bool setBottomEdge( const TopoDS_Edge& botE,
222 FaceQuadStruct::Ptr& quad,
223 const TopoDS_Shape& face)
225 quad->side[ QUAD_TOP_SIDE ].grid->Reverse();
226 quad->side[ QUAD_LEFT_SIDE ].grid->Reverse();
228 bool isComposite = false;
229 for ( size_t i = 0; i < quad->side.size(); ++i )
231 StdMeshers_FaceSidePtr quadSide = quad->side[i];
232 for ( int iE = 0; iE < quadSide->NbEdges(); ++iE )
233 if ( botE.IsSame( quadSide->Edge( iE )))
235 if ( quadSide->NbEdges() > 1 )
236 isComposite = true; //return false;
238 i = quad->side.size(); // to quit from the outer loop
242 if ( edgeIndex != QUAD_BOTTOM_SIDE )
243 quad->shift( quad->side.size() - edgeIndex, /*keepUnitOri=*/false );
245 quad->face = TopoDS::Face( face );
250 //================================================================================
252 * \brief Return iterator pointing to node column for the given parameter
253 * \param columnsMap - node column map
254 * \param parameter - parameter
255 * \retval TParam2ColumnMap::iterator - result
257 * it returns closest left column
259 //================================================================================
261 TParam2ColumnIt getColumn( const TParam2ColumnMap* columnsMap,
262 const double parameter )
264 TParam2ColumnIt u_col = columnsMap->upper_bound( parameter );
265 if ( u_col != columnsMap->begin() )
267 return u_col; // return left column
270 //================================================================================
272 * \brief Return nodes around given parameter and a ratio
273 * \param column - node column
274 * \param param - parameter
275 * \param node1 - lower node
276 * \param node2 - upper node
277 * \retval double - ratio
279 //================================================================================
281 double getRAndNodes( const TNodeColumn* column,
283 const SMDS_MeshNode* & node1,
284 const SMDS_MeshNode* & node2)
286 if ( param >= 1.0 || column->size() == 1) {
287 node1 = node2 = column->back();
291 int i = int( param * ( column->size() - 1 ));
292 double u0 = double( i )/ double( column->size() - 1 );
293 double r = ( param - u0 ) * ( column->size() - 1 );
295 node1 = (*column)[ i ];
296 node2 = (*column)[ i + 1];
300 //================================================================================
302 * \brief Compute boundary parameters of face parts
303 * \param nbParts - nb of parts to split columns into
304 * \param columnsMap - node columns of the face to split
305 * \param params - computed parameters
307 //================================================================================
309 void splitParams( const int nbParts,
310 const TParam2ColumnMap* columnsMap,
311 vector< double > & params)
314 params.reserve( nbParts + 1 );
315 TParam2ColumnIt last_par_col = --columnsMap->end();
316 double par = columnsMap->begin()->first; // 0.
317 double parLast = last_par_col->first;
318 params.push_back( par );
319 for ( int i = 0; i < nbParts - 1; ++ i )
321 double partSize = ( parLast - par ) / double ( nbParts - i );
322 TParam2ColumnIt par_col = getColumn( columnsMap, par + partSize );
323 if ( par_col->first == par ) {
325 if ( par_col == last_par_col ) {
326 while ( i < nbParts - 1 )
327 params.push_back( par + partSize * i++ );
331 par = par_col->first;
332 params.push_back( par );
334 params.push_back( parLast ); // 1.
337 //================================================================================
339 * \brief Return coordinate system for z-th layer of nodes
341 //================================================================================
343 gp_Ax2 getLayerCoordSys(const int z,
344 const vector< const TNodeColumn* >& columns,
347 // gravity center of a layer
350 for ( size_t i = 0; i < columns.size(); ++i )
352 O += gpXYZ( (*columns[ i ])[ z ]);
353 if ( vertexCol < 0 &&
354 columns[ i ]->front()->GetPosition()->GetTypeOfPosition() == SMDS_TOP_VERTEX )
361 int iPrev = columns.size()-1;
362 for ( size_t i = 0; i < columns.size(); ++i )
364 gp_Vec v1( O, gpXYZ( (*columns[ iPrev ])[ z ]));
365 gp_Vec v2( O, gpXYZ( (*columns[ i ] )[ z ]));
370 if ( vertexCol >= 0 )
372 O = gpXYZ( (*columns[ vertexCol ])[ z ]);
374 if ( xColumn < 0 || xColumn >= (int) columns.size() )
376 // select a column for X dir
378 for ( size_t i = 0; i < columns.size(); ++i )
380 double dist = ( O - gpXYZ((*columns[ i ])[ z ])).SquareModulus();
381 if ( dist > maxDist )
390 gp_Vec X( O, gpXYZ( (*columns[ xColumn ])[ z ]));
392 return gp_Ax2( O, Z, X);
395 //================================================================================
397 * \brief Removes submeshes that are or can be meshed with regular grid from given list
398 * \retval int - nb of removed submeshes
400 //================================================================================
402 int removeQuasiQuads(list< SMESH_subMesh* >& notQuadSubMesh,
403 SMESH_MesherHelper* helper,
404 StdMeshers_Quadrangle_2D* quadAlgo)
407 //SMESHDS_Mesh* mesh = notQuadSubMesh.front()->GetFather()->GetMeshDS();
408 list< SMESH_subMesh* >::iterator smIt = notQuadSubMesh.begin();
409 while ( smIt != notQuadSubMesh.end() )
411 SMESH_subMesh* faceSm = *smIt;
412 SMESHDS_SubMesh* faceSmDS = faceSm->GetSubMeshDS();
413 int nbQuads = faceSmDS ? faceSmDS->NbElements() : 0;
416 toRemove = helper->IsStructured( faceSm );
418 toRemove = ( quadAlgo->CheckNbEdges( *helper->GetMesh(),
419 faceSm->GetSubShape() ) != NULL );
420 nbRemoved += toRemove;
422 smIt = notQuadSubMesh.erase( smIt );
430 //================================================================================
432 * \brief Return and angle between two EDGEs
433 * \return double - the angle normalized so that
440 //================================================================================
442 // double normAngle(const TopoDS_Edge & E1, const TopoDS_Edge & E2, const TopoDS_Face & F)
444 // return SMESH_MesherHelper::GetAngle( E1, E2, F ) / ( 0.5 * M_PI );
447 //================================================================================
449 * Consider continuous straight EDGES as one side - mark them to unite
451 //================================================================================
453 int countNbSides( const Prism_3D::TPrismTopo & thePrism,
454 vector<int> & nbUnitePerEdge,
455 vector< double > & edgeLength)
457 int nbEdges = thePrism.myNbEdgesInWires.front(); // nb outer edges
458 int nbSides = nbEdges;
461 list< TopoDS_Edge >::const_iterator edgeIt = thePrism.myBottomEdges.begin();
462 std::advance( edgeIt, nbEdges-1 );
463 TopoDS_Edge prevE = *edgeIt;
464 // bool isPrevStraight = SMESH_Algo::IsStraight( prevE );
465 // int iPrev = nbEdges - 1;
467 // int iUnite = -1; // the first of united EDGEs
469 // analyse angles between EDGEs
471 vector< bool > isCorner( nbEdges );
472 edgeIt = thePrism.myBottomEdges.begin();
473 for ( int iE = 0; iE < nbEdges; ++iE, ++edgeIt )
475 const TopoDS_Edge& curE = *edgeIt;
476 edgeLength[ iE ] = SMESH_Algo::EdgeLength( curE );
478 // double normAngle = normAngle( prevE, curE, thePrism.myBottom );
479 // isCorner[ iE ] = false;
480 // if ( normAngle < 2.0 )
482 // if ( normAngle < 0.001 ) // straight or obtuse angle
484 // // unite EDGEs in order not to put a corner of the unit quadrangle at this VERTEX
487 // nbUnitePerEdge[ iUnite ]++;
488 // nbUnitePerEdge[ iE ] = -1;
493 // isCorner[ iE ] = true;
503 // define which of corners to put on a side of the unit quadrangle
505 // edgeIt = thePrism.myBottomEdges.begin();
506 // for ( int iE = 0; iE < nbEdges; ++iE, ++edgeIt )
508 // const TopoDS_Edge& curE = *edgeIt;
509 // edgeLength[ iE ] = SMESH_Algo::EdgeLength( curE );
511 // const bool isCurStraight = SMESH_Algo::IsStraight( curE );
512 // if ( isPrevStraight && isCurStraight && SMESH_Algo::IsContinuous( prevE, curE ))
516 // nbUnitePerEdge[ iUnite ]++;
517 // nbUnitePerEdge[ iE ] = -1;
525 // isPrevStraight = isCurStraight;
532 //================================================================================
534 * \brief Set/get wire index to FaceQuadStruct
536 //================================================================================
538 void setWireIndex( TFaceQuadStructPtr& quad, int iWire )
542 int getWireIndex( const TFaceQuadStructPtr& quad )
547 //================================================================================
549 * \brief Print Python commands adding given points to a mesh
551 //================================================================================
553 void pointsToPython(const std::vector<gp_XYZ>& p)
556 for ( size_t i = SMESH_Block::ID_V000; i < p.size(); ++i )
558 cout << "mesh.AddNode( " << p[i].X() << ", "<< p[i].Y() << ", "<< p[i].Z() << ") # " << i <<" " ;
559 SMESH_Block::DumpShapeID( i, cout ) << endl;
565 //=======================================================================
566 //function : StdMeshers_Prism_3D
568 //=======================================================================
570 StdMeshers_Prism_3D::StdMeshers_Prism_3D(int hypId, int studyId, SMESH_Gen* gen)
571 :SMESH_3D_Algo(hypId, studyId, gen)
574 _shapeType = (1 << TopAbs_SOLID); // 1 bit per shape type
575 _onlyUnaryInput = false; // mesh all SOLIDs at once
576 _requireDiscreteBoundary = false; // mesh FACEs and EDGEs by myself
577 _supportSubmeshes = true; // "source" FACE must be meshed by other algo
578 _neededLowerHyps[ 1 ] = true; // suppress warning on hiding a global 1D algo
579 _neededLowerHyps[ 2 ] = true; // suppress warning on hiding a global 2D algo
581 //myProjectTriangles = false;
582 mySetErrorToSM = true; // to pass an error to a sub-mesh of a current solid or not
583 myPrevBottomSM = 0; // last treated bottom sub-mesh with a suitable algorithm
586 //================================================================================
590 //================================================================================
592 StdMeshers_Prism_3D::~StdMeshers_Prism_3D()
594 pointsToPython( std::vector<gp_XYZ>() ); // avoid warning: pointsToPython defined but not used
597 //=======================================================================
598 //function : CheckHypothesis
600 //=======================================================================
602 bool StdMeshers_Prism_3D::CheckHypothesis(SMESH_Mesh& aMesh,
603 const TopoDS_Shape& aShape,
604 SMESH_Hypothesis::Hypothesis_Status& aStatus)
607 aStatus = SMESH_Hypothesis::HYP_OK;
611 //=======================================================================
613 //purpose : Compute mesh on a COMPOUND of SOLIDs
614 //=======================================================================
616 bool StdMeshers_Prism_3D::Compute(SMESH_Mesh& theMesh, const TopoDS_Shape& theShape)
618 SMESH_MesherHelper helper( theMesh );
622 int nbSolids = helper.Count( theShape, TopAbs_SOLID, /*skipSame=*/false );
626 TopTools_IndexedDataMapOfShapeListOfShape faceToSolids;
627 TopExp::MapShapesAndAncestors( theShape, TopAbs_FACE, TopAbs_SOLID, faceToSolids );
629 // look for meshed FACEs ("source" FACEs) that must be prism bottoms
630 list< TopoDS_Face > meshedFaces, notQuadMeshedFaces, notQuadFaces;
631 const bool meshHasQuads = ( theMesh.NbQuadrangles() > 0 );
632 //StdMeshers_Quadrangle_2D* quadAlgo = TQuadrangleAlgo::instance( this );
633 for ( int iF = 1; iF <= faceToSolids.Extent(); ++iF )
635 const TopoDS_Face& face = TopoDS::Face( faceToSolids.FindKey( iF ));
636 SMESH_subMesh* faceSM = theMesh.GetSubMesh( face );
637 if ( !faceSM->IsEmpty() )
639 if ( !meshHasQuads ||
640 !helper.IsSameElemGeometry( faceSM->GetSubMeshDS(), SMDSGeom_QUADRANGLE ) ||
641 !helper.IsStructured( faceSM )
643 notQuadMeshedFaces.push_front( face );
644 else if ( myHelper->Count( face, TopAbs_EDGE, /*ignoreSame=*/false ) != 4 )
645 meshedFaces.push_front( face );
647 meshedFaces.push_back( face );
649 // not add not quadrilateral FACE as we can't compute it
650 // else if ( !quadAlgo->CheckNbEdges( theMesh, face ))
651 // // not add not quadrilateral FACE as it can be a prism side
652 // // else if ( myHelper->Count( face, TopAbs_EDGE, /*ignoreSame=*/false ) != 4 )
654 // notQuadFaces.push_back( face );
657 // notQuadFaces are of medium priority, put them before ordinary meshed faces
658 meshedFaces.splice( meshedFaces.begin(), notQuadFaces );
659 // notQuadMeshedFaces are of highest priority, put them before notQuadFaces
660 meshedFaces.splice( meshedFaces.begin(), notQuadMeshedFaces );
662 Prism_3D::TPrismTopo prism;
664 bool selectBottom = meshedFaces.empty();
668 TopoDS_Shape solid = TopExp_Explorer( theShape, TopAbs_SOLID ).Current();
669 if ( !meshedFaces.empty() )
670 prism.myBottom = meshedFaces.front();
671 return ( initPrism( prism, solid, selectBottom ) &&
675 // find propagation chains from already computed EDGEs
676 vector< TopoDS_Edge > computedEdges;
677 getPrecomputedEdges( helper, theShape, computedEdges );
678 myPropagChains = new TopTools_IndexedMapOfShape[ computedEdges.size() + 1 ];
679 SMESHUtils::ArrayDeleter< TopTools_IndexedMapOfShape > pcDel( myPropagChains );
680 for ( size_t i = 0, nb = 0; i < computedEdges.size(); ++i )
682 StdMeshers_ProjectionUtils::GetPropagationEdge( &theMesh, TopoDS_Edge(),
683 computedEdges[i], myPropagChains + nb );
684 if ( myPropagChains[ nb ].Extent() < 2 ) // an empty map is a termination sign
685 myPropagChains[ nb ].Clear();
690 TopTools_MapOfShape meshedSolids;
691 list< Prism_3D::TPrismTopo > meshedPrism;
692 list< TopoDS_Face > suspectSourceFaces;
693 TopTools_ListIteratorOfListOfShape solidIt;
695 while ( meshedSolids.Extent() < nbSolids )
697 if ( _computeCanceled )
698 return toSM( error( SMESH_ComputeError::New(COMPERR_CANCELED)));
700 // compute prisms having avident computed source FACE
701 while ( !meshedFaces.empty() )
703 TopoDS_Face face = meshedFaces.front();
704 meshedFaces.pop_front();
705 TopTools_ListOfShape& solidList = faceToSolids.ChangeFromKey( face );
706 while ( !solidList.IsEmpty() )
708 TopoDS_Shape solid = solidList.First();
709 solidList.RemoveFirst();
710 if ( meshedSolids.Add( solid ))
713 prism.myBottom = face;
714 if ( !initPrism( prism, solid, selectBottom ) ||
718 SMESHDS_SubMesh* smDS = theMesh.GetMeshDS()->MeshElements( prism.myTop );
719 if ( !myHelper->IsSameElemGeometry( smDS, SMDSGeom_QUADRANGLE ))
721 meshedFaces.push_front( prism.myTop );
725 suspectSourceFaces.push_back( prism.myTop );
727 meshedPrism.push_back( prism );
731 if ( meshedSolids.Extent() == nbSolids )
734 // below in the loop we try to find source FACEs somehow
736 // project mesh from source FACEs of computed prisms to
737 // prisms sharing wall FACEs
738 list< Prism_3D::TPrismTopo >::iterator prismIt = meshedPrism.begin();
739 for ( ; prismIt != meshedPrism.end(); ++prismIt )
741 for ( size_t iW = 0; iW < prismIt->myWallQuads.size(); ++iW )
743 Prism_3D::TQuadList::iterator wQuad = prismIt->myWallQuads[iW].begin();
744 for ( ; wQuad != prismIt->myWallQuads[iW].end(); ++ wQuad )
746 const TopoDS_Face& wFace = (*wQuad)->face;
747 TopTools_ListOfShape& solidList = faceToSolids.ChangeFromKey( wFace );
748 solidIt.Initialize( solidList );
749 while ( solidIt.More() )
751 const TopoDS_Shape& solid = solidIt.Value();
752 if ( meshedSolids.Contains( solid )) {
753 solidList.Remove( solidIt );
754 continue; // already computed prism
756 if ( myHelper->IsBlock( solid )) {
758 continue; // too trivial
760 // find a source FACE of the SOLID: it's a FACE sharing a bottom EDGE with wFace
761 const TopoDS_Edge& wEdge = (*wQuad)->side[ QUAD_TOP_SIDE ].grid->Edge(0);
762 PShapeIteratorPtr faceIt = myHelper->GetAncestors( wEdge, *myHelper->GetMesh(),
764 while ( const TopoDS_Shape* f = faceIt->next() )
766 const TopoDS_Face& candidateF = TopoDS::Face( *f );
767 if ( candidateF.IsSame( wFace )) continue;
768 // select a source FACE: prismIt->myBottom or prismIt->myTop
769 TopoDS_Face sourceF = prismIt->myBottom;
770 for ( TopExp_Explorer v( prismIt->myTop, TopAbs_VERTEX ); v.More(); v.Next() )
771 if ( myHelper->IsSubShape( v.Current(), candidateF )) {
772 sourceF = prismIt->myTop;
776 prism.myBottom = candidateF;
777 mySetErrorToSM = false;
778 if ( !myHelper->IsSubShape( candidateF, prismIt->myShape3D ) &&
779 myHelper ->IsSubShape( candidateF, solid ) &&
780 !myHelper->GetMesh()->GetSubMesh( candidateF )->IsMeshComputed() &&
781 initPrism( prism, solid, /*selectBottom=*/false ) &&
782 !myHelper->GetMesh()->GetSubMesh( prism.myTop )->IsMeshComputed() &&
783 !myHelper->GetMesh()->GetSubMesh( prism.myBottom )->IsMeshComputed() &&
784 project2dMesh( sourceF, prism.myBottom ))
786 mySetErrorToSM = true;
787 if ( !compute( prism ))
789 SMESHDS_SubMesh* smDS = theMesh.GetMeshDS()->MeshElements( prism.myTop );
790 if ( !myHelper->IsSameElemGeometry( smDS, SMDSGeom_QUADRANGLE ))
792 meshedFaces.push_front( prism.myTop );
793 meshedFaces.push_front( prism.myBottom );
794 selectBottom = false;
796 meshedPrism.push_back( prism );
797 meshedSolids.Add( solid );
801 mySetErrorToSM = true;
803 if ( meshedSolids.Contains( solid ))
804 solidList.Remove( solidIt );
810 if ( !meshedFaces.empty() )
811 break; // to compute prisms with avident sources
814 if ( meshedFaces.empty() )
816 meshedFaces.splice( meshedFaces.end(), suspectSourceFaces );
820 // find FACEs with local 1D hyps, which has to be computed by now,
821 // or at least any computed FACEs
822 if ( meshedFaces.empty() )
825 for ( int iF = 1; iF <= faceToSolids.Extent(); ++iF )
827 const TopoDS_Face& face = TopoDS::Face( faceToSolids.FindKey( iF ));
828 const TopTools_ListOfShape& solidList = faceToSolids.FindFromKey( face );
829 if ( solidList.IsEmpty() ) continue;
830 SMESH_subMesh* faceSM = theMesh.GetSubMesh( face );
831 if ( !faceSM->IsEmpty() )
833 int nbFaces = faceSM->GetSubMeshDS()->NbElements();
834 if ( prevNbFaces < nbFaces )
836 if ( !meshedFaces.empty() ) meshedFaces.pop_back();
837 meshedFaces.push_back( face ); // lower priority
839 prevNbFaces = nbFaces;
844 bool allSubMeComputed = true;
845 SMESH_subMeshIteratorPtr smIt = faceSM->getDependsOnIterator(false,true);
846 while ( smIt->more() && allSubMeComputed )
847 allSubMeComputed = smIt->next()->IsMeshComputed();
848 if ( allSubMeComputed )
850 faceSM->ComputeStateEngine( SMESH_subMesh::COMPUTE );
851 if ( !faceSM->IsEmpty() ) {
852 meshedFaces.push_front( face ); // higher priority
857 faceSM->ComputeStateEngine( SMESH_subMesh::CHECK_COMPUTE_STATE );
865 // TODO. there are other ways to find out the source FACE:
866 // propagation, topological similarity, etc...
868 // simply try to mesh all not meshed SOLIDs
869 if ( meshedFaces.empty() )
871 for ( TopExp_Explorer solid( theShape, TopAbs_SOLID ); solid.More(); solid.Next() )
873 mySetErrorToSM = false;
875 if ( !meshedSolids.Contains( solid.Current() ) &&
876 initPrism( prism, solid.Current() ))
878 mySetErrorToSM = true;
879 if ( !compute( prism ))
881 meshedFaces.push_front( prism.myTop );
882 meshedFaces.push_front( prism.myBottom );
883 meshedPrism.push_back( prism );
884 meshedSolids.Add( solid.Current() );
887 mySetErrorToSM = true;
891 if ( meshedFaces.empty() ) // set same error to 10 not-computed solids
893 SMESH_ComputeErrorPtr err = SMESH_ComputeError::New
894 ( COMPERR_BAD_INPUT_MESH, "No meshed source face found", this );
896 const int maxNbErrors = 10; // limit nb errors not to overload the Compute dialog
897 TopExp_Explorer solid( theShape, TopAbs_SOLID );
898 for ( int i = 0; ( i < maxNbErrors && solid.More() ); ++i, solid.Next() )
899 if ( !meshedSolids.Contains( solid.Current() ))
901 SMESH_subMesh* sm = theMesh.GetSubMesh( solid.Current() );
902 sm->GetComputeError() = err;
907 return error( COMPERR_OK );
910 //================================================================================
912 * \brief Find wall faces by bottom edges
914 //================================================================================
916 bool StdMeshers_Prism_3D::getWallFaces( Prism_3D::TPrismTopo & thePrism,
917 const int totalNbFaces)
919 thePrism.myWallQuads.clear();
921 SMESH_Mesh* mesh = myHelper->GetMesh();
923 StdMeshers_Quadrangle_2D* quadAlgo = TQuadrangleAlgo::instance( this, myHelper );
925 TopTools_MapOfShape faceMap;
926 TopTools_IndexedDataMapOfShapeListOfShape edgeToFaces;
927 TopExp::MapShapesAndAncestors( thePrism.myShape3D,
928 TopAbs_EDGE, TopAbs_FACE, edgeToFaces );
930 // ------------------------------
931 // Get the 1st row of wall FACEs
932 // ------------------------------
934 list< TopoDS_Edge >::iterator edge = thePrism.myBottomEdges.begin();
935 std::list< int >::iterator nbE = thePrism.myNbEdgesInWires.begin();
936 std::list< int > nbQuadsPerWire;
937 int iE = 0, iWire = 0;
938 while ( edge != thePrism.myBottomEdges.end() )
941 if ( SMESH_Algo::isDegenerated( *edge ))
943 edge = thePrism.myBottomEdges.erase( edge );
949 bool hasWallFace = false;
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 ))
957 Prism_3D::TQuadList quadList( 1, quadAlgo->CheckNbEdges( *mesh, face ));
958 if ( !quadList.back() )
959 return toSM( error(TCom("Side face #") << shapeID( face )
960 << " not meshable with quadrangles"));
961 bool isCompositeBase = ! setBottomEdge( *edge, quadList.back(), face );
962 if ( isCompositeBase )
964 // it's OK if all EDGEs of the bottom side belongs to the bottom FACE
965 StdMeshers_FaceSidePtr botSide = quadList.back()->side[ QUAD_BOTTOM_SIDE ];
966 for ( int iE = 0; iE < botSide->NbEdges(); ++iE )
967 if ( !myHelper->IsSubShape( botSide->Edge(iE), thePrism.myBottom ))
968 return toSM( error(TCom("Composite 'horizontal' edges are not supported")));
970 if ( faceMap.Add( face ))
972 setWireIndex( quadList.back(), iWire ); // for use in makeQuadsForOutInProjection()
973 thePrism.myWallQuads.push_back( quadList );
982 else // seam edge (IPAL53561)
984 edge = thePrism.myBottomEdges.erase( edge );
994 int nbQuadPrev = std::accumulate( nbQuadsPerWire.begin(), nbQuadsPerWire.end(), 0 );
995 nbQuadsPerWire.push_back( thePrism.myWallQuads.size() - nbQuadPrev );
999 // -------------------------
1000 // Find the rest wall FACEs
1001 // -------------------------
1003 // Compose a vector of indixes of right neighbour FACE for each wall FACE
1004 // that is not so evident in case of several WIREs in the bottom FACE
1005 thePrism.myRightQuadIndex.clear();
1006 for ( size_t i = 0; i < thePrism.myWallQuads.size(); ++i )
1008 thePrism.myRightQuadIndex.push_back( i+1 ); // OK for all but the last EDGE of a WIRE
1010 list< int >::iterator nbQinW = nbQuadsPerWire.begin();
1011 for ( int iLeft = 0; nbQinW != nbQuadsPerWire.end(); ++nbQinW )
1013 thePrism.myRightQuadIndex[ iLeft + *nbQinW - 1 ] = iLeft; // for the last EDGE of a WIRE
1017 while ( totalNbFaces - faceMap.Extent() > 2 )
1019 // find wall FACEs adjacent to each of wallQuads by the right side EDGE
1022 nbKnownFaces = faceMap.Extent();
1023 StdMeshers_FaceSidePtr rightSide, topSide; // sides of the quad
1024 for ( size_t i = 0; i < thePrism.myWallQuads.size(); ++i )
1026 rightSide = thePrism.myWallQuads[i].back()->side[ QUAD_RIGHT_SIDE ];
1027 for ( int iE = 0; iE < rightSide->NbEdges(); ++iE ) // rightSide can be composite
1029 const TopoDS_Edge & rightE = rightSide->Edge( iE );
1030 TopTools_ListIteratorOfListOfShape face( edgeToFaces.FindFromKey( rightE ));
1031 for ( ; face.More(); face.Next() )
1032 if ( faceMap.Add( face.Value() ))
1034 // a new wall FACE encountered, store it in thePrism.myWallQuads
1035 const int iRight = thePrism.myRightQuadIndex[i];
1036 topSide = thePrism.myWallQuads[ iRight ].back()->side[ QUAD_TOP_SIDE ];
1037 const TopoDS_Edge& newBotE = topSide->Edge(0);
1038 const TopoDS_Shape& newWallF = face.Value();
1039 thePrism.myWallQuads[ iRight ].push_back( quadAlgo->CheckNbEdges( *mesh, newWallF ));
1040 if ( !thePrism.myWallQuads[ iRight ].back() )
1041 return toSM( error(TCom("Side face #") << shapeID( newWallF ) <<
1042 " not meshable with quadrangles"));
1043 if ( ! setBottomEdge( newBotE, thePrism.myWallQuads[ iRight ].back(), newWallF ))
1044 return toSM( error(TCom("Composite 'horizontal' edges are not supported")));
1048 } while ( nbKnownFaces != faceMap.Extent() );
1050 // find wall FACEs adjacent to each of thePrism.myWallQuads by the top side EDGE
1051 if ( totalNbFaces - faceMap.Extent() > 2 )
1053 const int nbFoundWalls = faceMap.Extent();
1054 for ( size_t i = 0; i < thePrism.myWallQuads.size(); ++i )
1056 StdMeshers_FaceSidePtr topSide = thePrism.myWallQuads[i].back()->side[ QUAD_TOP_SIDE ];
1057 const TopoDS_Edge & topE = topSide->Edge( 0 );
1058 if ( topSide->NbEdges() > 1 )
1059 return toSM( error(COMPERR_BAD_SHAPE, TCom("Side face #") <<
1060 shapeID( thePrism.myWallQuads[i].back()->face )
1061 << " has a composite top edge"));
1062 TopTools_ListIteratorOfListOfShape faceIt( edgeToFaces.FindFromKey( topE ));
1063 for ( ; faceIt.More(); faceIt.Next() )
1064 if ( faceMap.Add( faceIt.Value() ))
1066 // a new wall FACE encountered, store it in wallQuads
1067 thePrism.myWallQuads[ i ].push_back( quadAlgo->CheckNbEdges( *mesh, faceIt.Value() ));
1068 if ( !thePrism.myWallQuads[ i ].back() )
1069 return toSM( error(TCom("Side face #") << shapeID( faceIt.Value() ) <<
1070 " not meshable with quadrangles"));
1071 if ( ! setBottomEdge( topE, thePrism.myWallQuads[ i ].back(), faceIt.Value() ))
1072 return toSM( error(TCom("Composite 'horizontal' edges are not supported")));
1073 if ( totalNbFaces - faceMap.Extent() == 2 )
1075 i = thePrism.myWallQuads.size(); // to quit from the outer loop
1080 if ( nbFoundWalls == faceMap.Extent() )
1081 return toSM( error("Failed to find wall faces"));
1084 } // while ( totalNbFaces - faceMap.Extent() > 2 )
1086 // ------------------
1087 // Find the top FACE
1088 // ------------------
1090 if ( thePrism.myTop.IsNull() )
1092 // now only top and bottom FACEs are not in the faceMap
1093 faceMap.Add( thePrism.myBottom );
1094 for ( TopExp_Explorer f( thePrism.myShape3D, TopAbs_FACE ); f.More(); f.Next() )
1095 if ( !faceMap.Contains( f.Current() )) {
1096 thePrism.myTop = TopoDS::Face( f.Current() );
1099 if ( thePrism.myTop.IsNull() )
1100 return toSM( error("Top face not found"));
1103 // Check that the top FACE shares all the top EDGEs
1104 for ( size_t i = 0; i < thePrism.myWallQuads.size(); ++i )
1106 StdMeshers_FaceSidePtr topSide = thePrism.myWallQuads[i].back()->side[ QUAD_TOP_SIDE ];
1107 const TopoDS_Edge & topE = topSide->Edge( 0 );
1108 if ( !myHelper->IsSubShape( topE, thePrism.myTop ))
1109 return toSM( error( TCom("Wrong source face: #") << shapeID( thePrism.myBottom )));
1115 //=======================================================================
1116 //function : compute
1117 //purpose : Compute mesh on a SOLID
1118 //=======================================================================
1120 bool StdMeshers_Prism_3D::compute(const Prism_3D::TPrismTopo& thePrism)
1122 myHelper->IsQuadraticSubMesh( thePrism.myShape3D );
1123 if ( _computeCanceled )
1124 return toSM( error( SMESH_ComputeError::New(COMPERR_CANCELED)));
1126 // Assure the bottom is meshed
1127 if ( !computeBase( thePrism ))
1130 // Make all side FACEs of thePrism meshed with quads
1131 if ( !computeWalls( thePrism ))
1134 // Analyse mesh and geometry to find all block sub-shapes and submeshes
1135 // (after fixing IPAL52499 myBlock is used as a holder of boundary nodes
1136 // and for 2D projection in hard cases where StdMeshers_Projection_2D fails;
1137 // location of internal nodes is usually computed by StdMeshers_Sweeper)
1138 if ( !myBlock.Init( myHelper, thePrism ))
1139 return toSM( error( myBlock.GetError()));
1141 SMESHDS_Mesh* meshDS = myHelper->GetMeshDS();
1143 int volumeID = meshDS->ShapeToIndex( thePrism.myShape3D );
1145 // Try to get gp_Trsf to get all nodes from bottom ones
1146 vector<gp_Trsf> trsf;
1147 gp_Trsf bottomToTopTrsf;
1148 // if ( !myBlock.GetLayersTransformation( trsf, thePrism ))
1150 // else if ( !trsf.empty() )
1151 // bottomToTopTrsf = trsf.back();
1153 // To compute coordinates of a node inside a block using "block approach",
1154 // it is necessary to know
1155 // 1. normalized parameters of the node by which
1156 // 2. coordinates of node projections on all block sub-shapes are computed
1158 // So we fill projections on vertices at once as they are same for all nodes
1159 myShapeXYZ.resize( myBlock.NbSubShapes() );
1160 for ( int iV = SMESH_Block::ID_FirstV; iV < SMESH_Block::ID_FirstE; ++iV ) {
1161 myBlock.VertexPoint( iV, myShapeXYZ[ iV ]);
1162 SHOWYXZ("V point " <<iV << " ", myShapeXYZ[ iV ]);
1165 // Projections on the top and bottom faces are taken from nodes existing
1166 // on these faces; find correspondence between bottom and top nodes
1167 myUseBlock = false; // is set to true if projection is done using "block approach"
1168 myBotToColumnMap.clear();
1169 if ( !assocOrProjBottom2Top( bottomToTopTrsf, thePrism ) ) // it also fills myBotToColumnMap
1173 // Create nodes inside the block
1177 // use transformation (issue 0020680, IPAL0052499) or a "straight line" approach
1178 StdMeshers_Sweeper sweeper;
1179 sweeper.myHelper = myHelper;
1180 sweeper.myBotFace = thePrism.myBottom;
1181 sweeper.myTopFace = thePrism.myTop;
1183 // load boundary nodes into sweeper
1185 const SMDS_MeshNode* prevN0 = 0, *prevN1 = 0;
1186 list< TopoDS_Edge >::const_iterator edge = thePrism.myBottomEdges.begin();
1187 for ( ; edge != thePrism.myBottomEdges.end(); ++edge )
1189 int edgeID = meshDS->ShapeToIndex( *edge );
1190 TParam2ColumnMap* u2col = const_cast<TParam2ColumnMap*>
1191 ( myBlock.GetParam2ColumnMap( edgeID, dummy ));
1193 TParam2ColumnMap::iterator u2colIt = u2col->begin(), u2colEnd = u2col->end();
1194 const SMDS_MeshNode* n0 = u2colIt->second[0];
1195 const SMDS_MeshNode* n1 = u2col->rbegin()->second[0];
1196 if ( n0 == prevN0 || n0 == prevN1 ) ++u2colIt;
1197 if ( n1 == prevN0 || n1 == prevN1 ) --u2colEnd;
1198 prevN0 = n0; prevN1 = n1;
1200 for ( ; u2colIt != u2colEnd; ++u2colIt )
1201 sweeper.myBndColumns.push_back( & u2colIt->second );
1203 // load node columns inside the bottom FACE
1204 TNode2ColumnMap::iterator bot_column = myBotToColumnMap.begin();
1205 sweeper.myIntColumns.reserve( myBotToColumnMap.size() );
1206 for ( ; bot_column != myBotToColumnMap.end(); ++bot_column )
1207 sweeper.myIntColumns.push_back( & bot_column->second );
1209 myHelper->SetElementsOnShape( true );
1211 // If all "vertical" EDGEs are straight, then all nodes of an internal node column
1212 // are located on a line connecting the top node and the bottom node.
1213 bool isStrightColunm = allVerticalEdgesStraight( thePrism );
1214 if ( !isStrightColunm )
1216 double tol = getSweepTolerance( thePrism );
1217 bool allowHighBndError = !isSimpleBottom( thePrism );
1218 myUseBlock = !sweeper.ComputeNodesByTrsf( tol, allowHighBndError );
1220 else if ( sweeper.CheckSameZ() )
1222 myUseBlock = !sweeper.ComputeNodesOnStraightSameZ();
1226 myUseBlock = !sweeper.ComputeNodesOnStraight();
1228 myHelper->SetElementsOnShape( false );
1231 if ( myUseBlock ) // use block approach
1233 // loop on nodes inside the bottom face
1234 Prism_3D::TNode prevBNode;
1235 TNode2ColumnMap::iterator bot_column = myBotToColumnMap.begin();
1236 for ( ; bot_column != myBotToColumnMap.end(); ++bot_column )
1238 const Prism_3D::TNode& tBotNode = bot_column->first; // bottom TNode
1239 if ( tBotNode.GetPositionType() != SMDS_TOP_FACE &&
1240 myBlock.HasNodeColumn( tBotNode.myNode ))
1241 continue; // node is not inside the FACE
1243 // column nodes; middle part of the column are zero pointers
1244 TNodeColumn& column = bot_column->second;
1246 gp_XYZ botParams, topParams;
1247 if ( !tBotNode.HasParams() )
1249 // compute bottom node parameters
1250 gp_XYZ paramHint(-1,-1,-1);
1251 if ( prevBNode.IsNeighbor( tBotNode ))
1252 paramHint = prevBNode.GetParams();
1253 if ( !myBlock.ComputeParameters( tBotNode.GetCoords(), tBotNode.ChangeParams(),
1254 ID_BOT_FACE, paramHint ))
1255 return toSM( error(TCom("Can't compute normalized parameters for node ")
1256 << tBotNode.myNode->GetID() << " on the face #"
1257 << myBlock.SubMesh( ID_BOT_FACE )->GetId() ));
1258 prevBNode = tBotNode;
1260 botParams = topParams = tBotNode.GetParams();
1261 topParams.SetZ( 1 );
1263 // compute top node parameters
1264 if ( column.size() > 2 ) {
1265 gp_Pnt topCoords = gpXYZ( column.back() );
1266 if ( !myBlock.ComputeParameters( topCoords, topParams, ID_TOP_FACE, topParams ))
1267 return toSM( error(TCom("Can't compute normalized parameters ")
1268 << "for node " << column.back()->GetID()
1269 << " on the face #"<< column.back()->getshapeId() ));
1272 else // top nodes are created by projection using parameters
1274 botParams = topParams = tBotNode.GetParams();
1275 topParams.SetZ( 1 );
1278 myShapeXYZ[ ID_BOT_FACE ] = tBotNode.GetCoords();
1279 myShapeXYZ[ ID_TOP_FACE ] = gpXYZ( column.back() );
1282 TNodeColumn::iterator columnNodes = column.begin();
1283 for ( int z = 0; columnNodes != column.end(); ++columnNodes, ++z)
1285 const SMDS_MeshNode* & node = *columnNodes;
1286 if ( node ) continue; // skip bottom or top node
1288 // params of a node to create
1289 double rz = (double) z / (double) ( column.size() - 1 );
1290 gp_XYZ params = botParams * ( 1 - rz ) + topParams * rz;
1292 // set coords on all faces and nodes
1293 const int nbSideFaces = 4;
1294 int sideFaceIDs[nbSideFaces] = { SMESH_Block::ID_Fx0z,
1295 SMESH_Block::ID_Fx1z,
1296 SMESH_Block::ID_F0yz,
1297 SMESH_Block::ID_F1yz };
1298 for ( int iF = 0; iF < nbSideFaces; ++iF )
1299 if ( !setFaceAndEdgesXYZ( sideFaceIDs[ iF ], params, z ))
1302 // compute coords for a new node
1304 if ( !SMESH_Block::ShellPoint( params, myShapeXYZ, coords ))
1305 return toSM( error("Can't compute coordinates by normalized parameters"));
1307 // if ( !meshDS->MeshElements( volumeID ) ||
1308 // meshDS->MeshElements( volumeID )->NbNodes() == 0 )
1309 // pointsToPython(myShapeXYZ);
1310 SHOWYXZ("TOPFacePoint ",myShapeXYZ[ ID_TOP_FACE]);
1311 SHOWYXZ("BOT Node "<< tBotNode.myNode->GetID(),gpXYZ(tBotNode.myNode));
1312 SHOWYXZ("ShellPoint ",coords);
1315 node = meshDS->AddNode( coords.X(), coords.Y(), coords.Z() );
1316 meshDS->SetNodeInVolume( node, volumeID );
1318 if ( _computeCanceled )
1321 } // loop on bottom nodes
1326 SMESHDS_SubMesh* smDS = myBlock.SubMeshDS( ID_BOT_FACE );
1327 if ( !smDS ) return toSM( error(COMPERR_BAD_INPUT_MESH, "Null submesh"));
1329 // loop on bottom mesh faces
1330 vector< const TNodeColumn* > columns;
1331 SMDS_ElemIteratorPtr faceIt = smDS->GetElements();
1332 while ( faceIt->more() )
1334 const SMDS_MeshElement* face = faceIt->next();
1335 if ( !face || face->GetType() != SMDSAbs_Face )
1338 // find node columns for each node
1339 int nbNodes = face->NbCornerNodes();
1340 columns.resize( nbNodes );
1341 for ( int i = 0; i < nbNodes; ++i )
1343 const SMDS_MeshNode* n = face->GetNode( i );
1344 columns[ i ] = NULL;
1346 if ( n->GetPosition()->GetTypeOfPosition() != SMDS_TOP_FACE )
1347 columns[ i ] = myBlock.GetNodeColumn( n );
1349 if ( !columns[ i ] )
1351 TNode2ColumnMap::iterator bot_column = myBotToColumnMap.find( n );
1352 if ( bot_column == myBotToColumnMap.end() )
1353 return toSM( error(TCom("No side nodes found above node ") << n->GetID() ));
1354 columns[ i ] = & bot_column->second;
1358 if ( !AddPrisms( columns, myHelper ))
1359 return toSM( error("Different 'vertical' discretization"));
1361 } // loop on bottom mesh faces
1364 myBotToColumnMap.clear();
1367 // update state of sub-meshes (mostly in order to erase improper errors)
1368 SMESH_subMesh* sm = myHelper->GetMesh()->GetSubMesh( thePrism.myShape3D );
1369 SMESH_subMeshIteratorPtr smIt = sm->getDependsOnIterator(/*includeSelf=*/true);
1370 while ( smIt->more() )
1373 sm->GetComputeError().reset();
1374 sm->ComputeStateEngine( SMESH_subMesh::CHECK_COMPUTE_STATE );
1380 //=======================================================================
1381 //function : computeBase
1382 //purpose : Compute the base face of a prism
1383 //=======================================================================
1385 bool StdMeshers_Prism_3D::computeBase(const Prism_3D::TPrismTopo& thePrism)
1387 SMESH_Mesh* mesh = myHelper->GetMesh();
1388 SMESH_subMesh* botSM = mesh->GetSubMesh( thePrism.myBottom );
1389 if (( botSM->IsEmpty() ) &&
1390 ( ! botSM->GetAlgo() ||
1391 ! _gen->Compute( *botSM->GetFather(), botSM->GetSubShape(), /*shapeOnly=*/true )))
1393 // find any applicable algorithm assigned to any FACE of the main shape
1394 std::vector< TopoDS_Shape > faces;
1395 if ( myPrevBottomSM &&
1396 myPrevBottomSM->GetAlgo()->IsApplicableToShape( thePrism.myBottom, /*all=*/false ))
1397 faces.push_back( myPrevBottomSM->GetSubShape() );
1399 TopExp_Explorer faceIt( mesh->GetShapeToMesh(), TopAbs_FACE );
1400 for ( ; faceIt.More(); faceIt.Next() )
1401 faces.push_back( faceIt.Current() );
1403 faces.push_back( TopoDS_Shape() ); // to try quadrangle algorithm
1405 SMESH_Algo* algo = 0;
1406 for ( size_t i = 0; i < faces.size() && botSM->IsEmpty(); ++i )
1408 if ( faces[i].IsNull() ) algo = TQuadrangleAlgo::instance( this, myHelper );
1409 else algo = mesh->GetSubMesh( faces[i] )->GetAlgo();
1410 if ( algo && algo->IsApplicableToShape( thePrism.myBottom, /*all=*/false ))
1412 // try to compute the bottom FACE
1413 if ( algo->NeedDiscreteBoundary() )
1415 // compute sub-shapes
1416 SMESH_subMeshIteratorPtr smIt = botSM->getDependsOnIterator(false,false);
1418 while ( smIt->more() && subOK )
1420 SMESH_subMesh* sub = smIt->next();
1421 sub->ComputeStateEngine( SMESH_subMesh::COMPUTE );
1422 subOK = sub->IsMeshComputed();
1429 algo->InitComputeError();
1430 algo->Compute( *mesh, botSM->GetSubShape() );
1438 if ( botSM->IsEmpty() )
1439 return error( COMPERR_BAD_INPUT_MESH,
1440 TCom( "No mesher defined to compute the base face #")
1441 << shapeID( thePrism.myBottom ));
1443 if ( botSM->GetAlgo() )
1444 myPrevBottomSM = botSM;
1449 //=======================================================================
1450 //function : computeWalls
1451 //purpose : Compute 2D mesh on walls FACEs of a prism
1452 //=======================================================================
1454 bool StdMeshers_Prism_3D::computeWalls(const Prism_3D::TPrismTopo& thePrism)
1456 SMESH_Mesh* mesh = myHelper->GetMesh();
1457 SMESHDS_Mesh* meshDS = myHelper->GetMeshDS();
1458 DBGOUT( endl << "COMPUTE Prism " << meshDS->ShapeToIndex( thePrism.myShape3D ));
1460 TProjction1dAlgo* projector1D = TProjction1dAlgo::instance( this );
1461 StdMeshers_Quadrangle_2D* quadAlgo = TQuadrangleAlgo::instance( this, myHelper );
1463 // SMESH_HypoFilter hyp1dFilter( SMESH_HypoFilter::IsAlgo(),/*not=*/true);
1464 // hyp1dFilter.And( SMESH_HypoFilter::HasDim( 1 ));
1465 // hyp1dFilter.And( SMESH_HypoFilter::IsMoreLocalThan( thePrism.myShape3D, *mesh ));
1467 // Discretize equally 'vertical' EDGEs
1468 // -----------------------------------
1469 // find source FACE sides for projection: either already computed ones or
1470 // the 'most composite' ones
1471 const size_t nbWalls = thePrism.myWallQuads.size();
1472 vector< int > wgt( nbWalls, 0 ); // "weight" of a wall
1473 for ( size_t iW = 0; iW != nbWalls; ++iW )
1475 Prism_3D::TQuadList::const_iterator quad = thePrism.myWallQuads[iW].begin();
1476 for ( ; quad != thePrism.myWallQuads[iW].end(); ++quad )
1478 StdMeshers_FaceSidePtr lftSide = (*quad)->side[ QUAD_LEFT_SIDE ];
1479 lftSide->Reverse(); // to go up
1480 for ( int i = 0; i < lftSide->NbEdges(); ++i )
1483 const TopoDS_Edge& E = lftSide->Edge(i);
1484 if ( mesh->GetSubMesh( E )->IsMeshComputed() )
1487 wgt[ myHelper->WrapIndex( iW+1, nbWalls)] += 10;
1488 wgt[ myHelper->WrapIndex( iW-1, nbWalls)] += 10;
1490 // else if ( mesh->GetHypothesis( E, hyp1dFilter, true )) // local hypothesis!
1494 // in quadratic mesh, pass ignoreMediumNodes to quad sides
1495 if ( myHelper->GetIsQuadratic() )
1497 quad = thePrism.myWallQuads[iW].begin();
1498 for ( ; quad != thePrism.myWallQuads[iW].end(); ++quad )
1499 for ( int i = 0; i < NB_QUAD_SIDES; ++i )
1500 (*quad)->side[ i ].grid->SetIgnoreMediumNodes( true );
1503 multimap< int, int > wgt2quad;
1504 for ( size_t iW = 0; iW != nbWalls; ++iW )
1505 wgt2quad.insert( make_pair( wgt[ iW ], iW ));
1507 // artificial quads to do outer <-> inner wall projection
1508 std::map< int, FaceQuadStruct > iW2oiQuads;
1509 std::map< int, FaceQuadStruct >::iterator w2oiq;
1510 makeQuadsForOutInProjection( thePrism, wgt2quad, iW2oiQuads );
1512 // Project 'vertical' EDGEs, from left to right
1513 multimap< int, int >::reverse_iterator w2q = wgt2quad.rbegin();
1514 for ( ; w2q != wgt2quad.rend(); ++w2q )
1516 const int iW = w2q->second;
1517 const Prism_3D::TQuadList& quads = thePrism.myWallQuads[ iW ];
1518 Prism_3D::TQuadList::const_iterator quad = quads.begin();
1519 for ( ; quad != quads.end(); ++quad )
1521 StdMeshers_FaceSidePtr rgtSide = (*quad)->side[ QUAD_RIGHT_SIDE ]; // tgt
1522 StdMeshers_FaceSidePtr lftSide = (*quad)->side[ QUAD_LEFT_SIDE ]; // src
1523 bool swapLeftRight = ( lftSide->NbSegments( /*update=*/true ) == 0 &&
1524 rgtSide->NbSegments( /*update=*/true ) > 0 );
1525 if ( swapLeftRight )
1526 std::swap( lftSide, rgtSide );
1528 bool isArtificialQuad = (( w2oiq = iW2oiQuads.find( iW )) != iW2oiQuads.end() );
1529 if ( isArtificialQuad )
1531 // reset sides to perform the outer <-> inner projection
1532 FaceQuadStruct& oiQuad = w2oiq->second;
1533 rgtSide = oiQuad.side[ QUAD_RIGHT_SIDE ];
1534 lftSide = oiQuad.side[ QUAD_LEFT_SIDE ];
1535 iW2oiQuads.erase( w2oiq );
1538 // assure that all the source (left) EDGEs are meshed
1539 int nbSrcSegments = 0;
1540 for ( int i = 0; i < lftSide->NbEdges(); ++i )
1542 if ( isArtificialQuad )
1544 nbSrcSegments = lftSide->NbPoints()-1;
1547 const TopoDS_Edge& srcE = lftSide->Edge(i);
1548 SMESH_subMesh* srcSM = mesh->GetSubMesh( srcE );
1549 if ( !srcSM->IsMeshComputed() ) {
1550 DBGOUT( "COMPUTE V edge " << srcSM->GetId() );
1551 TopoDS_Edge prpgSrcE = findPropagationSource( srcE );
1552 if ( !prpgSrcE.IsNull() ) {
1553 srcSM->ComputeSubMeshStateEngine( SMESH_subMesh::COMPUTE );
1554 projector1D->myHyp.SetSourceEdge( prpgSrcE );
1555 projector1D->Compute( *mesh, srcE );
1556 srcSM->ComputeStateEngine( SMESH_subMesh::CHECK_COMPUTE_STATE );
1559 srcSM->ComputeSubMeshStateEngine( SMESH_subMesh::COMPUTE );
1560 srcSM->ComputeStateEngine ( SMESH_subMesh::COMPUTE );
1562 if ( !srcSM->IsMeshComputed() )
1563 return toSM( error( "Can't compute 1D mesh" ));
1565 nbSrcSegments += srcSM->GetSubMeshDS()->NbElements();
1567 // check target EDGEs
1568 int nbTgtMeshed = 0, nbTgtSegments = 0;
1569 vector< bool > isTgtEdgeComputed( rgtSide->NbEdges() );
1570 for ( int i = 0; i < rgtSide->NbEdges(); ++i )
1572 const TopoDS_Edge& tgtE = rgtSide->Edge(i);
1573 SMESH_subMesh* tgtSM = mesh->GetSubMesh( tgtE );
1574 if ( !( isTgtEdgeComputed[ i ] = tgtSM->IsMeshComputed() )) {
1575 tgtSM->ComputeSubMeshStateEngine( SMESH_subMesh::COMPUTE );
1576 tgtSM->ComputeStateEngine ( SMESH_subMesh::COMPUTE );
1578 if ( tgtSM->IsMeshComputed() ) {
1580 nbTgtSegments += tgtSM->GetSubMeshDS()->NbElements();
1583 if ( rgtSide->NbEdges() == nbTgtMeshed ) // all tgt EDGEs meshed
1585 if ( nbTgtSegments != nbSrcSegments )
1587 bool badMeshRemoved = false;
1588 // remove just computed segments
1589 for ( int i = 0; i < rgtSide->NbEdges(); ++i )
1590 if ( !isTgtEdgeComputed[ i ])
1592 const TopoDS_Edge& tgtE = rgtSide->Edge(i);
1593 SMESH_subMesh* tgtSM = mesh->GetSubMesh( tgtE );
1594 tgtSM->ComputeStateEngine( SMESH_subMesh::CLEAN );
1595 badMeshRemoved = true;
1598 if ( !badMeshRemoved )
1600 for ( int i = 0; i < lftSide->NbEdges(); ++i )
1601 addBadInputElements( meshDS->MeshElements( lftSide->Edge( i )));
1602 for ( int i = 0; i < rgtSide->NbEdges(); ++i )
1603 addBadInputElements( meshDS->MeshElements( rgtSide->Edge( i )));
1604 return toSM( error( TCom("Different nb of segment on logically vertical edges #")
1605 << shapeID( lftSide->Edge(0) ) << " and #"
1606 << shapeID( rgtSide->Edge(0) ) << ": "
1607 << nbSrcSegments << " != " << nbTgtSegments ));
1610 else // if ( nbTgtSegments == nbSrcSegments )
1615 // Compute 'vertical projection'
1616 if ( nbTgtMeshed == 0 )
1618 // compute nodes on target VERTEXes
1619 const UVPtStructVec& srcNodeStr = lftSide->GetUVPtStruct();
1620 if ( srcNodeStr.size() == 0 )
1621 return toSM( error( TCom("Invalid node positions on edge #") <<
1622 lftSide->EdgeID(0) ));
1623 vector< SMDS_MeshNode* > newNodes( srcNodeStr.size() );
1624 for ( int is2ndV = 0; is2ndV < 2; ++is2ndV )
1626 const TopoDS_Edge& E = rgtSide->Edge( is2ndV ? rgtSide->NbEdges()-1 : 0 );
1627 TopoDS_Vertex v = myHelper->IthVertex( is2ndV, E );
1628 mesh->GetSubMesh( v )->ComputeStateEngine( SMESH_subMesh::COMPUTE );
1629 const SMDS_MeshNode* n = SMESH_Algo::VertexNode( v, meshDS );
1630 newNodes[ is2ndV ? 0 : newNodes.size()-1 ] = (SMDS_MeshNode*) n;
1633 // compute nodes on target EDGEs
1634 DBGOUT( "COMPUTE V edge (proj) " << shapeID( lftSide->Edge(0)));
1635 //rgtSide->Reverse(); // direct it same as the lftSide
1636 myHelper->SetElementsOnShape( false ); // myHelper holds the prism shape
1637 TopoDS_Edge tgtEdge;
1638 for ( size_t iN = 1; iN < srcNodeStr.size()-1; ++iN ) // add nodes
1640 gp_Pnt p = rgtSide->Value3d ( srcNodeStr[ iN ].normParam );
1641 double u = rgtSide->Parameter( srcNodeStr[ iN ].normParam, tgtEdge );
1642 newNodes[ iN ] = meshDS->AddNode( p.X(), p.Y(), p.Z() );
1643 meshDS->SetNodeOnEdge( newNodes[ iN ], tgtEdge, u );
1645 for ( size_t iN = 1; iN < srcNodeStr.size(); ++iN ) // add segments
1647 // find an EDGE to set a new segment
1648 std::pair<int, TopAbs_ShapeEnum> id2type =
1649 myHelper->GetMediumPos( newNodes[ iN-1 ], newNodes[ iN ] );
1650 if ( id2type.second != TopAbs_EDGE )
1652 // new nodes are on different EDGEs; put one of them on VERTEX
1653 const int edgeIndex = rgtSide->EdgeIndex( srcNodeStr[ iN-1 ].normParam );
1654 const double vertexParam = rgtSide->LastParameter( edgeIndex );
1655 TopoDS_Vertex vertex = rgtSide->LastVertex( edgeIndex );
1656 const SMDS_MeshNode* vn = SMESH_Algo::VertexNode( vertex, meshDS );
1657 const gp_Pnt p = BRep_Tool::Pnt( vertex );
1658 const int isPrev = ( Abs( srcNodeStr[ iN-1 ].normParam - vertexParam ) <
1659 Abs( srcNodeStr[ iN ].normParam - vertexParam ));
1660 meshDS->UnSetNodeOnShape( newNodes[ iN-isPrev ] );
1661 meshDS->SetNodeOnVertex ( newNodes[ iN-isPrev ], vertex );
1662 meshDS->MoveNode ( newNodes[ iN-isPrev ], p.X(), p.Y(), p.Z() );
1663 id2type.first = newNodes[ iN-(1-isPrev) ]->getshapeId();
1666 SMESH_MeshEditor::TListOfListOfNodes lln( 1, list< const SMDS_MeshNode* >() );
1667 lln.back().push_back ( vn );
1668 lln.back().push_front( newNodes[ iN-isPrev ] ); // to keep
1669 SMESH_MeshEditor( mesh ).MergeNodes( lln );
1672 SMDS_MeshElement* newEdge = myHelper->AddEdge( newNodes[ iN-1 ], newNodes[ iN ] );
1673 meshDS->SetMeshElementOnShape( newEdge, id2type.first );
1675 myHelper->SetElementsOnShape( true );
1676 for ( int i = 0; i < rgtSide->NbEdges(); ++i ) // update state of sub-meshes
1678 const TopoDS_Edge& E = rgtSide->Edge( i );
1679 SMESH_subMesh* tgtSM = mesh->GetSubMesh( E );
1680 tgtSM->ComputeStateEngine( SMESH_subMesh::CHECK_COMPUTE_STATE );
1683 // to continue projection from the just computed side as a source
1684 if ( !swapLeftRight && rgtSide->NbEdges() > 1 && w2q->second == iW )
1686 std::pair<int,int> wgt2quadKeyVal( w2q->first + 1, thePrism.myRightQuadIndex[ iW ]);
1687 wgt2quad.insert( wgt2quadKeyVal ); // it will be skipped by ++w2q
1688 wgt2quad.insert( wgt2quadKeyVal );
1689 w2q = wgt2quad.rbegin();
1694 // HOPE assigned hypotheses are OK, so that equal nb of segments will be generated
1695 //return toSM( error("Partial projection not implemented"));
1697 } // loop on quads of a composite wall side
1698 } // loop on the ordered wall sides
1702 for ( size_t iW = 0; iW != thePrism.myWallQuads.size(); ++iW )
1704 Prism_3D::TQuadList::const_iterator quad = thePrism.myWallQuads[iW].begin();
1705 for ( ; quad != thePrism.myWallQuads[iW].end(); ++quad )
1707 const TopoDS_Face& face = (*quad)->face;
1708 SMESH_subMesh* fSM = mesh->GetSubMesh( face );
1709 if ( ! fSM->IsMeshComputed() )
1711 // Top EDGEs must be projections from the bottom ones
1712 // to compute structured quad mesh on wall FACEs
1713 // ---------------------------------------------------
1714 const TopoDS_Edge& botE = (*quad)->side[ QUAD_BOTTOM_SIDE ].grid->Edge(0);
1715 const TopoDS_Edge& topE = (*quad)->side[ QUAD_TOP_SIDE ].grid->Edge(0);
1716 SMESH_subMesh* botSM = mesh->GetSubMesh( botE );
1717 SMESH_subMesh* topSM = mesh->GetSubMesh( topE );
1718 SMESH_subMesh* srcSM = botSM;
1719 SMESH_subMesh* tgtSM = topSM;
1720 srcSM->ComputeStateEngine( SMESH_subMesh::CHECK_COMPUTE_STATE );
1721 tgtSM->ComputeStateEngine( SMESH_subMesh::CHECK_COMPUTE_STATE );
1722 if ( !srcSM->IsMeshComputed() && tgtSM->IsMeshComputed() )
1723 std::swap( srcSM, tgtSM );
1725 if ( !srcSM->IsMeshComputed() )
1727 DBGOUT( "COMPUTE H edge " << srcSM->GetId());
1728 srcSM->ComputeSubMeshStateEngine( SMESH_subMesh::COMPUTE ); // nodes on VERTEXes
1729 srcSM->ComputeStateEngine( SMESH_subMesh::COMPUTE ); // segments on the EDGE
1732 if ( tgtSM->IsMeshComputed() &&
1733 tgtSM->GetSubMeshDS()->NbNodes() != srcSM->GetSubMeshDS()->NbNodes() )
1735 // the top EDGE is computed differently than the bottom one,
1736 // try to clear a wrong mesh
1737 bool isAdjFaceMeshed = false;
1738 PShapeIteratorPtr fIt = myHelper->GetAncestors( tgtSM->GetSubShape(),
1739 *mesh, TopAbs_FACE );
1740 while ( const TopoDS_Shape* f = fIt->next() )
1741 if (( isAdjFaceMeshed = mesh->GetSubMesh( *f )->IsMeshComputed() ))
1743 if ( isAdjFaceMeshed )
1744 return toSM( error( TCom("Different nb of segment on logically horizontal edges #")
1745 << shapeID( botE ) << " and #"
1746 << shapeID( topE ) << ": "
1747 << tgtSM->GetSubMeshDS()->NbElements() << " != "
1748 << srcSM->GetSubMeshDS()->NbElements() ));
1749 tgtSM->ComputeStateEngine( SMESH_subMesh::CLEAN );
1751 if ( !tgtSM->IsMeshComputed() )
1753 // compute nodes on VERTEXes
1754 SMESH_subMeshIteratorPtr smIt = tgtSM->getDependsOnIterator(/*includeSelf=*/false);
1755 while ( smIt->more() )
1756 smIt->next()->ComputeStateEngine( SMESH_subMesh::COMPUTE );
1758 DBGOUT( "COMPUTE H edge (proj) " << tgtSM->GetId());
1759 projector1D->myHyp.SetSourceEdge( TopoDS::Edge( srcSM->GetSubShape() ));
1760 projector1D->InitComputeError();
1761 bool ok = projector1D->Compute( *mesh, tgtSM->GetSubShape() );
1764 SMESH_ComputeErrorPtr err = projector1D->GetComputeError();
1765 if ( err->IsOK() ) err->myName = COMPERR_ALGO_FAILED;
1766 tgtSM->GetComputeError() = err;
1770 tgtSM->ComputeStateEngine( SMESH_subMesh::CHECK_COMPUTE_STATE );
1773 // Compute quad mesh on wall FACEs
1774 // -------------------------------
1776 // make all EDGES meshed
1777 fSM->ComputeSubMeshStateEngine( SMESH_subMesh::COMPUTE );
1778 if ( !fSM->SubMeshesComputed() )
1779 return toSM( error( COMPERR_BAD_INPUT_MESH,
1780 "Not all edges have valid algorithm and hypothesis"));
1782 quadAlgo->InitComputeError();
1783 DBGOUT( "COMPUTE Quad face " << fSM->GetId());
1784 bool ok = quadAlgo->Compute( *mesh, face );
1785 fSM->GetComputeError() = quadAlgo->GetComputeError();
1788 fSM->ComputeStateEngine( SMESH_subMesh::CHECK_COMPUTE_STATE );
1790 if ( myHelper->GetIsQuadratic() )
1792 // fill myHelper with medium nodes built by quadAlgo
1793 SMDS_ElemIteratorPtr fIt = fSM->GetSubMeshDS()->GetElements();
1794 while ( fIt->more() )
1795 myHelper->AddTLinks( dynamic_cast<const SMDS_MeshFace*>( fIt->next() ));
1803 //=======================================================================
1804 //function : findPropagationSource
1805 //purpose : Returns a source EDGE of propagation to a given EDGE
1806 //=======================================================================
1808 TopoDS_Edge StdMeshers_Prism_3D::findPropagationSource( const TopoDS_Edge& E )
1810 if ( myPropagChains )
1811 for ( size_t i = 0; !myPropagChains[i].IsEmpty(); ++i )
1812 if ( myPropagChains[i].Contains( E ))
1813 return TopoDS::Edge( myPropagChains[i].FindKey( 1 ));
1815 return TopoDS_Edge();
1818 //=======================================================================
1819 //function : makeQuadsForOutInProjection
1820 //purpose : Create artificial wall quads for vertical projection between
1821 // the outer and inner walls
1822 //=======================================================================
1824 void StdMeshers_Prism_3D::makeQuadsForOutInProjection( const Prism_3D::TPrismTopo& thePrism,
1825 multimap< int, int >& wgt2quad,
1826 map< int, FaceQuadStruct >& iQ2oiQuads)
1828 if ( thePrism.NbWires() <= 1 )
1831 std::set< int > doneWires; // processed wires
1833 SMESH_Mesh* mesh = myHelper->GetMesh();
1834 const bool isForward = true;
1835 const bool skipMedium = myHelper->GetIsQuadratic();
1837 // make a source side for all projections
1839 multimap< int, int >::reverse_iterator w2q = wgt2quad.rbegin();
1840 const int iQuad = w2q->second;
1841 const int iWire = getWireIndex( thePrism.myWallQuads[ iQuad ].front() );
1842 doneWires.insert( iWire );
1844 UVPtStructVec srcNodes;
1846 Prism_3D::TQuadList::const_iterator quad = thePrism.myWallQuads[ iQuad ].begin();
1847 for ( ; quad != thePrism.myWallQuads[ iQuad ].end(); ++quad )
1849 StdMeshers_FaceSidePtr lftSide = (*quad)->side[ QUAD_LEFT_SIDE ];
1851 // assure that all the source (left) EDGEs are meshed
1852 for ( int i = 0; i < lftSide->NbEdges(); ++i )
1854 const TopoDS_Edge& srcE = lftSide->Edge(i);
1855 SMESH_subMesh* srcSM = mesh->GetSubMesh( srcE );
1856 if ( !srcSM->IsMeshComputed() ) {
1857 srcSM->ComputeSubMeshStateEngine( SMESH_subMesh::COMPUTE );
1858 srcSM->ComputeStateEngine ( SMESH_subMesh::COMPUTE );
1860 if ( !srcSM->IsMeshComputed() )
1863 const UVPtStructVec& subNodes = lftSide->GetUVPtStruct();
1864 UVPtStructVec::const_iterator subBeg = subNodes.begin(), subEnd = subNodes.end();
1865 if ( !srcNodes.empty() ) ++subBeg;
1866 srcNodes.insert( srcNodes.end(), subBeg, subEnd );
1868 StdMeshers_FaceSidePtr srcSide = StdMeshers_FaceSide::New( srcNodes );
1872 list< TopoDS_Edge > sideEdges;
1874 for ( ++w2q; w2q != wgt2quad.rend(); ++w2q )
1876 const int iQuad = w2q->second;
1877 const Prism_3D::TQuadList& quads = thePrism.myWallQuads[ iQuad ];
1878 const int iWire = getWireIndex( quads.front() );
1879 if ( !doneWires.insert( iWire ).second )
1883 for ( quad = quads.begin(); quad != quads.end(); ++quad )
1885 StdMeshers_FaceSidePtr lftSide = (*quad)->side[ QUAD_LEFT_SIDE ];
1886 for ( int i = 0; i < lftSide->NbEdges(); ++i )
1887 sideEdges.push_back( lftSide->Edge( i ));
1888 face = lftSide->Face();
1890 StdMeshers_FaceSidePtr tgtSide =
1891 StdMeshers_FaceSide::New( face, sideEdges, mesh, isForward, skipMedium, myHelper );
1893 FaceQuadStruct& newQuad = iQ2oiQuads[ iQuad ];
1894 newQuad.side.resize( 4 );
1895 newQuad.side[ QUAD_LEFT_SIDE ] = srcSide;
1896 newQuad.side[ QUAD_RIGHT_SIDE ] = tgtSide;
1898 wgt2quad.insert( *w2q ); // to process this quad after processing the newQuad
1902 //=======================================================================
1903 //function : Evaluate
1905 //=======================================================================
1907 bool StdMeshers_Prism_3D::Evaluate(SMESH_Mesh& theMesh,
1908 const TopoDS_Shape& theShape,
1909 MapShapeNbElems& aResMap)
1911 if ( theShape.ShapeType() == TopAbs_COMPOUND )
1914 for ( TopoDS_Iterator it( theShape ); it.More(); it.Next() )
1915 ok &= Evaluate( theMesh, it.Value(), aResMap );
1918 SMESH_MesherHelper helper( theMesh );
1920 myHelper->SetSubShape( theShape );
1922 // find face contains only triangles
1923 vector < SMESH_subMesh * >meshFaces;
1924 TopTools_SequenceOfShape aFaces;
1925 int NumBase = 0, i = 0, NbQFs = 0;
1926 for (TopExp_Explorer exp(theShape, TopAbs_FACE); exp.More(); exp.Next()) {
1928 aFaces.Append(exp.Current());
1929 SMESH_subMesh *aSubMesh = theMesh.GetSubMesh(exp.Current());
1930 meshFaces.push_back(aSubMesh);
1931 MapShapeNbElemsItr anIt = aResMap.find(meshFaces[i-1]);
1932 if( anIt==aResMap.end() )
1933 return toSM( error( "Submesh can not be evaluated"));
1935 std::vector<int> aVec = (*anIt).second;
1936 int nbtri = Max(aVec[SMDSEntity_Triangle],aVec[SMDSEntity_Quad_Triangle]);
1937 int nbqua = Max(aVec[SMDSEntity_Quadrangle],aVec[SMDSEntity_Quad_Quadrangle]);
1938 if( nbtri==0 && nbqua>0 ) {
1947 std::vector<int> aResVec(SMDSEntity_Last);
1948 for(int i=SMDSEntity_Node; i<SMDSEntity_Last; i++) aResVec[i] = 0;
1949 SMESH_subMesh * sm = theMesh.GetSubMesh(theShape);
1950 aResMap.insert(std::make_pair(sm,aResVec));
1951 return toSM( error( "Submesh can not be evaluated" ));
1954 if(NumBase==0) NumBase = 1; // only quads => set 1 faces as base
1956 // find number of 1d elems for base face
1958 TopTools_MapOfShape Edges1;
1959 for (TopExp_Explorer exp(aFaces.Value(NumBase), TopAbs_EDGE); exp.More(); exp.Next()) {
1960 Edges1.Add(exp.Current());
1961 SMESH_subMesh *sm = theMesh.GetSubMesh(exp.Current());
1963 MapShapeNbElemsItr anIt = aResMap.find(sm);
1964 if( anIt == aResMap.end() ) continue;
1965 std::vector<int> aVec = (*anIt).second;
1966 nb1d += Max(aVec[SMDSEntity_Edge],aVec[SMDSEntity_Quad_Edge]);
1969 // find face opposite to base face
1971 for(i=1; i<=6; i++) {
1972 if(i==NumBase) continue;
1973 bool IsOpposite = true;
1974 for(TopExp_Explorer exp(aFaces.Value(i), TopAbs_EDGE); exp.More(); exp.Next()) {
1975 if( Edges1.Contains(exp.Current()) ) {
1985 // find number of 2d elems on side faces
1987 for(i=1; i<=6; i++) {
1988 if( i==OppNum || i==NumBase ) continue;
1989 MapShapeNbElemsItr anIt = aResMap.find( meshFaces[i-1] );
1990 if( anIt == aResMap.end() ) continue;
1991 std::vector<int> aVec = (*anIt).second;
1992 nb2d += Max(aVec[SMDSEntity_Quadrangle],aVec[SMDSEntity_Quad_Quadrangle]);
1995 MapShapeNbElemsItr anIt = aResMap.find( meshFaces[NumBase-1] );
1996 std::vector<int> aVec = (*anIt).second;
1997 bool IsQuadratic = (aVec[SMDSEntity_Quad_Triangle]>aVec[SMDSEntity_Triangle]) ||
1998 (aVec[SMDSEntity_Quad_Quadrangle]>aVec[SMDSEntity_Quadrangle]);
1999 int nb2d_face0_3 = Max(aVec[SMDSEntity_Triangle],aVec[SMDSEntity_Quad_Triangle]);
2000 int nb2d_face0_4 = Max(aVec[SMDSEntity_Quadrangle],aVec[SMDSEntity_Quad_Quadrangle]);
2001 int nb0d_face0 = aVec[SMDSEntity_Node];
2002 int nb1d_face0_int = ( nb2d_face0_3*3 + nb2d_face0_4*4 - nb1d ) / 2;
2004 std::vector<int> aResVec(SMDSEntity_Last);
2005 for(int i=SMDSEntity_Node; i<SMDSEntity_Last; i++) aResVec[i] = 0;
2007 aResVec[SMDSEntity_Quad_Penta] = nb2d_face0_3 * ( nb2d/nb1d );
2008 aResVec[SMDSEntity_Quad_Hexa] = nb2d_face0_4 * ( nb2d/nb1d );
2009 aResVec[SMDSEntity_Node] = nb0d_face0 * ( 2*nb2d/nb1d - 1 ) - nb1d_face0_int * nb2d/nb1d;
2012 aResVec[SMDSEntity_Node] = nb0d_face0 * ( nb2d/nb1d - 1 );
2013 aResVec[SMDSEntity_Penta] = nb2d_face0_3 * ( nb2d/nb1d );
2014 aResVec[SMDSEntity_Hexa] = nb2d_face0_4 * ( nb2d/nb1d );
2016 SMESH_subMesh * sm = theMesh.GetSubMesh(theShape);
2017 aResMap.insert(std::make_pair(sm,aResVec));
2022 //================================================================================
2024 * \brief Create prisms
2025 * \param columns - columns of nodes generated from nodes of a mesh face
2026 * \param helper - helper initialized by mesh and shape to add prisms to
2028 //================================================================================
2030 bool StdMeshers_Prism_3D::AddPrisms( vector<const TNodeColumn*> & columns,
2031 SMESH_MesherHelper* helper)
2033 size_t nbNodes = columns.size();
2034 size_t nbZ = columns[0]->size();
2035 if ( nbZ < 2 ) return false;
2036 for ( size_t i = 1; i < nbNodes; ++i )
2037 if ( columns[i]->size() != nbZ )
2040 // find out orientation
2041 bool isForward = true;
2042 SMDS_VolumeTool vTool;
2044 switch ( nbNodes ) {
2046 SMDS_VolumeOfNodes tmpPenta ( (*columns[0])[z-1], // bottom
2049 (*columns[0])[z], // top
2052 vTool.Set( &tmpPenta );
2053 isForward = vTool.IsForward();
2057 SMDS_VolumeOfNodes tmpHex( (*columns[0])[z-1], (*columns[1])[z-1], // bottom
2058 (*columns[2])[z-1], (*columns[3])[z-1],
2059 (*columns[0])[z], (*columns[1])[z], // top
2060 (*columns[2])[z], (*columns[3])[z] );
2061 vTool.Set( &tmpHex );
2062 isForward = vTool.IsForward();
2066 const int di = (nbNodes+1) / 3;
2067 SMDS_VolumeOfNodes tmpVol ( (*columns[0] )[z-1],
2068 (*columns[di] )[z-1],
2069 (*columns[2*di])[z-1],
2072 (*columns[2*di])[z] );
2073 vTool.Set( &tmpVol );
2074 isForward = vTool.IsForward();
2077 // vertical loop on columns
2079 helper->SetElementsOnShape( true );
2081 switch ( nbNodes ) {
2083 case 3: { // ---------- pentahedra
2084 const int i1 = isForward ? 1 : 2;
2085 const int i2 = isForward ? 2 : 1;
2086 for ( z = 1; z < nbZ; ++z )
2087 helper->AddVolume( (*columns[0 ])[z-1], // bottom
2088 (*columns[i1])[z-1],
2089 (*columns[i2])[z-1],
2090 (*columns[0 ])[z], // top
2092 (*columns[i2])[z] );
2095 case 4: { // ---------- hexahedra
2096 const int i1 = isForward ? 1 : 3;
2097 const int i3 = isForward ? 3 : 1;
2098 for ( z = 1; z < nbZ; ++z )
2099 helper->AddVolume( (*columns[0])[z-1], (*columns[i1])[z-1], // bottom
2100 (*columns[2])[z-1], (*columns[i3])[z-1],
2101 (*columns[0])[z], (*columns[i1])[z], // top
2102 (*columns[2])[z], (*columns[i3])[z] );
2105 case 6: { // ---------- octahedra
2106 const int iBase1 = isForward ? -1 : 0;
2107 const int iBase2 = isForward ? 0 :-1;
2108 for ( z = 1; z < nbZ; ++z )
2109 helper->AddVolume( (*columns[0])[z+iBase1], (*columns[1])[z+iBase1], // bottom or top
2110 (*columns[2])[z+iBase1], (*columns[3])[z+iBase1],
2111 (*columns[4])[z+iBase1], (*columns[5])[z+iBase1],
2112 (*columns[0])[z+iBase2], (*columns[1])[z+iBase2], // top or bottom
2113 (*columns[2])[z+iBase2], (*columns[3])[z+iBase2],
2114 (*columns[4])[z+iBase2], (*columns[5])[z+iBase2] );
2117 default: // ---------- polyhedra
2118 vector<int> quantities( 2 + nbNodes, 4 );
2119 quantities[0] = quantities[1] = nbNodes;
2120 columns.resize( nbNodes + 1 );
2121 columns[ nbNodes ] = columns[ 0 ];
2122 const int i1 = isForward ? 1 : 3;
2123 const int i3 = isForward ? 3 : 1;
2124 const int iBase1 = isForward ? -1 : 0;
2125 const int iBase2 = isForward ? 0 :-1;
2126 vector<const SMDS_MeshNode*> nodes( 2*nbNodes + 4*nbNodes);
2127 for ( z = 1; z < nbZ; ++z )
2129 for ( size_t i = 0; i < nbNodes; ++i ) {
2130 nodes[ i ] = (*columns[ i ])[z+iBase1]; // bottom or top
2131 nodes[ 2*nbNodes-i-1 ] = (*columns[ i ])[z+iBase2]; // top or bottom
2133 int di = 2*nbNodes + 4*i;
2134 nodes[ di+0 ] = (*columns[i ])[z ];
2135 nodes[ di+i1] = (*columns[i+1])[z ];
2136 nodes[ di+2 ] = (*columns[i+1])[z-1];
2137 nodes[ di+i3] = (*columns[i ])[z-1];
2139 helper->AddPolyhedralVolume( nodes, quantities );
2142 } // switch ( nbNodes )
2147 //================================================================================
2149 * \brief Find correspondence between bottom and top nodes
2150 * If elements on the bottom and top faces are topologically different,
2151 * and projection is possible and allowed, perform the projection
2152 * \retval bool - is a success or not
2154 //================================================================================
2156 bool StdMeshers_Prism_3D::assocOrProjBottom2Top( const gp_Trsf & bottomToTopTrsf,
2157 const Prism_3D::TPrismTopo& thePrism)
2159 SMESH_subMesh * botSM = myHelper->GetMesh()->GetSubMesh( thePrism.myBottom );
2160 SMESH_subMesh * topSM = myHelper->GetMesh()->GetSubMesh( thePrism.myTop );
2162 SMESHDS_SubMesh * botSMDS = botSM->GetSubMeshDS();
2163 SMESHDS_SubMesh * topSMDS = topSM->GetSubMeshDS();
2165 if ( !botSMDS || botSMDS->NbElements() == 0 )
2167 _gen->Compute( *myHelper->GetMesh(), botSM->GetSubShape(), /*aShapeOnly=*/true );
2168 botSMDS = botSM->GetSubMeshDS();
2169 if ( !botSMDS || botSMDS->NbElements() == 0 )
2170 return toSM( error(TCom("No elements on face #") << botSM->GetId() ));
2173 bool needProject = !topSM->IsMeshComputed();
2174 if ( !needProject &&
2175 (botSMDS->NbElements() != topSMDS->NbElements() ||
2176 botSMDS->NbNodes() != topSMDS->NbNodes()))
2178 MESSAGE("nb elem bot " << botSMDS->NbElements() <<
2179 " top " << ( topSMDS ? topSMDS->NbElements() : 0 ));
2180 MESSAGE("nb node bot " << botSMDS->NbNodes() <<
2181 " top " << ( topSMDS ? topSMDS->NbNodes() : 0 ));
2182 return toSM( error(TCom("Mesh on faces #") << botSM->GetId()
2183 <<" and #"<< topSM->GetId() << " seems different" ));
2186 if ( 0/*needProject && !myProjectTriangles*/ )
2187 return toSM( error(TCom("Mesh on faces #") << botSM->GetId()
2188 <<" and #"<< topSM->GetId() << " seems different" ));
2189 ///RETURN_BAD_RESULT("Need to project but not allowed");
2191 NSProjUtils::TNodeNodeMap n2nMap;
2192 const NSProjUtils::TNodeNodeMap* n2nMapPtr = & n2nMap;
2195 if ( !projectBottomToTop( bottomToTopTrsf, thePrism ))
2197 n2nMapPtr = & TProjction2dAlgo::instance( this )->GetNodesMap();
2200 if ( !n2nMapPtr || (int) n2nMapPtr->size() < botSMDS->NbNodes() )
2202 // associate top and bottom faces
2203 NSProjUtils::TShapeShapeMap shape2ShapeMap;
2204 const bool sameTopo =
2205 NSProjUtils::FindSubShapeAssociation( thePrism.myBottom, myHelper->GetMesh(),
2206 thePrism.myTop, myHelper->GetMesh(),
2209 for ( size_t iQ = 0; iQ < thePrism.myWallQuads.size(); ++iQ )
2211 const Prism_3D::TQuadList& quadList = thePrism.myWallQuads[iQ];
2212 StdMeshers_FaceSidePtr botSide = quadList.front()->side[ QUAD_BOTTOM_SIDE ];
2213 StdMeshers_FaceSidePtr topSide = quadList.back ()->side[ QUAD_TOP_SIDE ];
2214 if ( botSide->NbEdges() == topSide->NbEdges() )
2216 for ( int iE = 0; iE < botSide->NbEdges(); ++iE )
2218 NSProjUtils::InsertAssociation( botSide->Edge( iE ),
2219 topSide->Edge( iE ), shape2ShapeMap );
2220 NSProjUtils::InsertAssociation( myHelper->IthVertex( 0, botSide->Edge( iE )),
2221 myHelper->IthVertex( 0, topSide->Edge( iE )),
2227 TopoDS_Vertex vb, vt;
2228 StdMeshers_FaceSidePtr sideB, sideT;
2229 vb = myHelper->IthVertex( 0, botSide->Edge( 0 ));
2230 vt = myHelper->IthVertex( 0, topSide->Edge( 0 ));
2231 sideB = quadList.front()->side[ QUAD_LEFT_SIDE ];
2232 sideT = quadList.back ()->side[ QUAD_LEFT_SIDE ];
2233 if ( vb.IsSame( sideB->FirstVertex() ) &&
2234 vt.IsSame( sideT->LastVertex() ))
2236 NSProjUtils::InsertAssociation( botSide->Edge( 0 ),
2237 topSide->Edge( 0 ), shape2ShapeMap );
2238 NSProjUtils::InsertAssociation( vb, vt, shape2ShapeMap );
2240 vb = myHelper->IthVertex( 1, botSide->Edge( botSide->NbEdges()-1 ));
2241 vt = myHelper->IthVertex( 1, topSide->Edge( topSide->NbEdges()-1 ));
2242 sideB = quadList.front()->side[ QUAD_RIGHT_SIDE ];
2243 sideT = quadList.back ()->side[ QUAD_RIGHT_SIDE ];
2244 if ( vb.IsSame( sideB->FirstVertex() ) &&
2245 vt.IsSame( sideT->LastVertex() ))
2247 NSProjUtils::InsertAssociation( botSide->Edge( botSide->NbEdges()-1 ),
2248 topSide->Edge( topSide->NbEdges()-1 ),
2250 NSProjUtils::InsertAssociation( vb, vt, shape2ShapeMap );
2255 // Find matching nodes of top and bottom faces
2256 n2nMapPtr = & n2nMap;
2257 if ( ! NSProjUtils::FindMatchingNodesOnFaces( thePrism.myBottom, myHelper->GetMesh(),
2258 thePrism.myTop, myHelper->GetMesh(),
2259 shape2ShapeMap, n2nMap ))
2262 return toSM( error(TCom("Mesh on faces #") << botSM->GetId()
2263 <<" and #"<< topSM->GetId() << " seems different" ));
2265 return toSM( error(TCom("Topology of faces #") << botSM->GetId()
2266 <<" and #"<< topSM->GetId() << " seems different" ));
2270 // Fill myBotToColumnMap
2272 int zSize = myBlock.VerticalSize();
2273 TNodeNodeMap::const_iterator bN_tN = n2nMapPtr->begin();
2274 for ( ; bN_tN != n2nMapPtr->end(); ++bN_tN )
2276 const SMDS_MeshNode* botNode = bN_tN->first;
2277 const SMDS_MeshNode* topNode = bN_tN->second;
2278 if ( botNode->GetPosition()->GetTypeOfPosition() != SMDS_TOP_FACE &&
2279 myBlock.HasNodeColumn( botNode ))
2280 continue; // wall columns are contained in myBlock
2281 // create node column
2282 Prism_3D::TNode bN( botNode );
2283 TNode2ColumnMap::iterator bN_col =
2284 myBotToColumnMap.insert( make_pair ( bN, TNodeColumn() )).first;
2285 TNodeColumn & column = bN_col->second;
2286 column.resize( zSize );
2287 column.front() = botNode;
2288 column.back() = topNode;
2293 //================================================================================
2295 * \brief Remove faces from the top face and re-create them by projection from the bottom
2296 * \retval bool - a success or not
2298 //================================================================================
2300 bool StdMeshers_Prism_3D::projectBottomToTop( const gp_Trsf & bottomToTopTrsf,
2301 const Prism_3D::TPrismTopo& thePrism )
2303 if ( project2dMesh( thePrism.myBottom, thePrism.myTop ))
2307 NSProjUtils::TNodeNodeMap& n2nMap =
2308 (NSProjUtils::TNodeNodeMap&) TProjction2dAlgo::instance( this )->GetNodesMap();
2313 SMESHDS_Mesh* meshDS = myHelper->GetMeshDS();
2314 SMESH_subMesh * botSM = myHelper->GetMesh()->GetSubMesh( thePrism.myBottom );
2315 SMESH_subMesh * topSM = myHelper->GetMesh()->GetSubMesh( thePrism.myTop );
2317 SMESHDS_SubMesh * botSMDS = botSM->GetSubMeshDS();
2318 SMESHDS_SubMesh * topSMDS = topSM->GetSubMeshDS();
2320 if ( topSMDS && topSMDS->NbElements() > 0 )
2322 //topSM->ComputeStateEngine( SMESH_subMesh::CLEAN ); -- avoid propagation of events
2323 for ( SMDS_ElemIteratorPtr eIt = topSMDS->GetElements(); eIt->more(); )
2324 meshDS->RemoveFreeElement( eIt->next(), topSMDS, /*fromGroups=*/false );
2325 for ( SMDS_NodeIteratorPtr nIt = topSMDS->GetNodes(); nIt->more(); )
2326 meshDS->RemoveFreeNode( nIt->next(), topSMDS, /*fromGroups=*/false );
2329 const TopoDS_Face& botFace = thePrism.myBottom; // oriented within
2330 const TopoDS_Face& topFace = thePrism.myTop; // the 3D SHAPE
2331 int topFaceID = meshDS->ShapeToIndex( thePrism.myTop );
2333 SMESH_MesherHelper botHelper( *myHelper->GetMesh() );
2334 botHelper.SetSubShape( botFace );
2335 botHelper.ToFixNodeParameters( true );
2337 SMESH_MesherHelper topHelper( *myHelper->GetMesh() );
2338 topHelper.SetSubShape( topFace );
2339 topHelper.ToFixNodeParameters( true );
2340 double distXYZ[4], fixTol = 10 * topHelper.MaxTolerance( topFace );
2342 // Fill myBotToColumnMap
2344 int zSize = myBlock.VerticalSize();
2345 Prism_3D::TNode prevTNode;
2346 SMDS_NodeIteratorPtr nIt = botSMDS->GetNodes();
2347 while ( nIt->more() )
2349 const SMDS_MeshNode* botNode = nIt->next();
2350 const SMDS_MeshNode* topNode = 0;
2351 if ( botNode->GetPosition()->GetTypeOfPosition() != SMDS_TOP_FACE )
2352 continue; // strange
2354 Prism_3D::TNode bN( botNode );
2355 if ( bottomToTopTrsf.Form() == gp_Identity )
2357 // compute bottom node params
2358 gp_XYZ paramHint(-1,-1,-1);
2359 if ( prevTNode.IsNeighbor( bN ))
2361 paramHint = prevTNode.GetParams();
2362 // double tol = 1e-2 * ( prevTNode.GetCoords() - bN.GetCoords() ).Modulus();
2363 // myBlock.SetTolerance( Min( myBlock.GetTolerance(), tol ));
2365 if ( !myBlock.ComputeParameters( bN.GetCoords(), bN.ChangeParams(),
2366 ID_BOT_FACE, paramHint ))
2367 return toSM( error(TCom("Can't compute normalized parameters for node ")
2368 << botNode->GetID() << " on the face #"<< botSM->GetId() ));
2370 // compute top node coords
2371 gp_XYZ topXYZ; gp_XY topUV;
2372 if ( !myBlock.FacePoint( ID_TOP_FACE, bN.GetParams(), topXYZ ) ||
2373 !myBlock.FaceUV ( ID_TOP_FACE, bN.GetParams(), topUV ))
2374 return toSM( error(TCom("Can't compute coordinates "
2375 "by normalized parameters on the face #")<< topSM->GetId() ));
2376 topNode = meshDS->AddNode( topXYZ.X(),topXYZ.Y(),topXYZ.Z() );
2377 meshDS->SetNodeOnFace( topNode, topFaceID, topUV.X(), topUV.Y() );
2379 else // use bottomToTopTrsf
2381 gp_XYZ coords = bN.GetCoords();
2382 bottomToTopTrsf.Transforms( coords );
2383 topNode = meshDS->AddNode( coords.X(), coords.Y(), coords.Z() );
2384 gp_XY topUV = botHelper.GetNodeUV( botFace, botNode, 0, &checkUV );
2385 meshDS->SetNodeOnFace( topNode, topFaceID, topUV.X(), topUV.Y() );
2387 if ( topHelper.CheckNodeUV( topFace, topNode, topUV, fixTol, /*force=*/false, distXYZ ) &&
2388 distXYZ[0] > fixTol && distXYZ[0] < fixTol * 1e+3 )
2389 meshDS->MoveNode( topNode, distXYZ[1], distXYZ[2], distXYZ[3] ); // transform can be inaccurate
2391 // create node column
2392 TNode2ColumnMap::iterator bN_col =
2393 myBotToColumnMap.insert( make_pair ( bN, TNodeColumn() )).first;
2394 TNodeColumn & column = bN_col->second;
2395 column.resize( zSize );
2396 column.front() = botNode;
2397 column.back() = topNode;
2399 n2nMap.insert( n2nMap.end(), make_pair( botNode, topNode ));
2401 if ( _computeCanceled )
2402 return toSM( error( SMESH_ComputeError::New(COMPERR_CANCELED)));
2407 const bool oldSetElemsOnShape = myHelper->SetElementsOnShape( false );
2409 // care of orientation;
2410 // if the bottom faces is orienetd OK then top faces must be reversed
2411 bool reverseTop = true;
2412 if ( myHelper->NbAncestors( botFace, *myBlock.Mesh(), TopAbs_SOLID ) > 1 )
2413 reverseTop = ! myHelper->IsReversedSubMesh( botFace );
2414 int iFrw, iRev, *iPtr = &( reverseTop ? iRev : iFrw );
2416 // loop on bottom mesh faces
2417 SMDS_ElemIteratorPtr faceIt = botSMDS->GetElements();
2418 vector< const SMDS_MeshNode* > nodes;
2419 while ( faceIt->more() )
2421 const SMDS_MeshElement* face = faceIt->next();
2422 if ( !face || face->GetType() != SMDSAbs_Face )
2425 // find top node in columns for each bottom node
2426 int nbNodes = face->NbCornerNodes();
2427 nodes.resize( nbNodes );
2428 for ( iFrw = 0, iRev = nbNodes-1; iFrw < nbNodes; ++iFrw, --iRev )
2430 const SMDS_MeshNode* n = face->GetNode( *iPtr );
2431 if ( n->GetPosition()->GetTypeOfPosition() == SMDS_TOP_FACE ) {
2432 TNode2ColumnMap::iterator bot_column = myBotToColumnMap.find( n );
2433 if ( bot_column == myBotToColumnMap.end() )
2434 return toSM( error(TCom("No nodes found above node ") << n->GetID() ));
2435 nodes[ iFrw ] = bot_column->second.back();
2438 const TNodeColumn* column = myBlock.GetNodeColumn( n );
2440 return toSM( error(TCom("No side nodes found above node ") << n->GetID() ));
2441 nodes[ iFrw ] = column->back();
2444 SMDS_MeshElement* newFace = 0;
2445 switch ( nbNodes ) {
2448 newFace = myHelper->AddFace(nodes[0], nodes[1], nodes[2]);
2452 newFace = myHelper->AddFace( nodes[0], nodes[1], nodes[2], nodes[3] );
2456 newFace = meshDS->AddPolygonalFace( nodes );
2459 meshDS->SetMeshElementOnShape( newFace, topFaceID );
2462 myHelper->SetElementsOnShape( oldSetElemsOnShape );
2464 // Check the projected mesh
2466 if ( thePrism.NbWires() > 1 && // there are holes
2467 topHelper.IsDistorted2D( topSM, /*checkUV=*/false ))
2469 SMESH_MeshEditor editor( topHelper.GetMesh() );
2471 // smooth in 2D or 3D?
2472 TopLoc_Location loc;
2473 Handle(Geom_Surface) surface = BRep_Tool::Surface( topFace, loc );
2474 bool isPlanar = GeomLib_IsPlanarSurface( surface ).IsPlanar();
2476 set<const SMDS_MeshNode*> fixedNodes;
2477 TIDSortedElemSet faces;
2478 for ( faceIt = topSMDS->GetElements(); faceIt->more(); )
2479 faces.insert( faces.end(), faceIt->next() );
2482 for ( int isCentroidal = 0; isCentroidal < 2; ++isCentroidal )
2484 SMESH_MeshEditor::SmoothMethod algo =
2485 isCentroidal ? SMESH_MeshEditor::CENTROIDAL : SMESH_MeshEditor::LAPLACIAN;
2487 int nbAttempts = isCentroidal ? 1 : 10;
2488 for ( int iAttemp = 0; iAttemp < nbAttempts; ++iAttemp )
2490 TIDSortedElemSet workFaces = faces;
2493 editor.Smooth( workFaces, fixedNodes, algo, /*nbIterations=*/ 10,
2494 /*theTgtAspectRatio=*/1.0, /*the2D=*/!isPlanar);
2496 if (( isOk = !topHelper.IsDistorted2D( topSM, /*checkUV=*/true )) &&
2502 return toSM( error( TCom("Projection from face #") << botSM->GetId()
2503 << " to face #" << topSM->GetId()
2504 << " failed: inverted elements created"));
2507 TProjction2dAlgo::instance( this )->SetEventListener( topSM );
2512 //=======================================================================
2513 //function : getSweepTolerance
2514 //purpose : Compute tolerance to pass to StdMeshers_Sweeper
2515 //=======================================================================
2517 double StdMeshers_Prism_3D::getSweepTolerance( const Prism_3D::TPrismTopo& thePrism )
2519 SMESHDS_Mesh* meshDS = myHelper->GetMeshDS();
2520 SMESHDS_SubMesh * sm[2] = { meshDS->MeshElements( thePrism.myBottom ),
2521 meshDS->MeshElements( thePrism.myTop ) };
2522 double minDist = 1e100;
2524 vector< SMESH_TNodeXYZ > nodes;
2525 for ( int iSM = 0; iSM < 2; ++iSM )
2527 if ( !sm[ iSM ]) continue;
2529 SMDS_ElemIteratorPtr fIt = sm[ iSM ]->GetElements();
2530 while ( fIt->more() )
2532 const SMDS_MeshElement* face = fIt->next();
2533 const int nbNodes = face->NbCornerNodes();
2534 SMDS_ElemIteratorPtr nIt = face->nodesIterator();
2536 nodes.resize( nbNodes + 1 );
2537 for ( int iN = 0; iN < nbNodes; ++iN )
2538 nodes[ iN ] = nIt->next();
2539 nodes.back() = nodes[0];
2543 for ( int iN = 0; iN < nbNodes; ++iN )
2545 if ( nodes[ iN ]._node->GetPosition()->GetDim() < 2 &&
2546 nodes[ iN+1 ]._node->GetPosition()->GetDim() < 2 )
2548 // it's a boundary link; measure distance of other
2549 // nodes to this link
2550 gp_XYZ linkDir = nodes[ iN ] - nodes[ iN+1 ];
2551 double linkLen = linkDir.Modulus();
2552 bool isDegen = ( linkLen < numeric_limits<double>::min() );
2553 if ( !isDegen ) linkDir /= linkLen;
2554 for ( int iN2 = 0; iN2 < nbNodes; ++iN2 ) // loop on other nodes
2556 if ( nodes[ iN2 ] == nodes[ iN ] ||
2557 nodes[ iN2 ] == nodes[ iN+1 ]) continue;
2560 dist2 = ( nodes[ iN ] - nodes[ iN2 ]).SquareModulus();
2564 dist2 = linkDir.CrossSquareMagnitude( nodes[ iN ] - nodes[ iN2 ]);
2566 if ( dist2 > numeric_limits<double>::min() )
2567 minDist = Min ( minDist, dist2 );
2570 // measure length link
2571 else if ( nodes[ iN ]._node < nodes[ iN+1 ]._node ) // not to measure same link twice
2573 dist2 = ( nodes[ iN ] - nodes[ iN+1 ]).SquareModulus();
2574 if ( dist2 > numeric_limits<double>::min() )
2575 minDist = Min ( minDist, dist2 );
2580 return 0.1 * Sqrt ( minDist );
2583 //=======================================================================
2584 //function : isSimpleQuad
2585 //purpose : check if the bottom FACE is meshable with nice qudrangles,
2586 // if so the block aproach can work rather fast.
2587 // This is a temporary mean caused by problems in StdMeshers_Sweeper
2588 //=======================================================================
2590 bool StdMeshers_Prism_3D::isSimpleBottom( const Prism_3D::TPrismTopo& thePrism )
2592 if ( thePrism.myNbEdgesInWires.front() != 4 )
2595 // analyse angles between edges
2596 double nbConcaveAng = 0, nbConvexAng = 0;
2597 TopoDS_Face reverseBottom = TopoDS::Face( thePrism.myBottom.Reversed() ); // see initPrism()
2598 TopoDS_Vertex commonV;
2599 const list< TopoDS_Edge >& botEdges = thePrism.myBottomEdges;
2600 list< TopoDS_Edge >::const_iterator edge = botEdges.begin();
2601 while ( edge != botEdges.end() )
2603 if ( SMESH_Algo::isDegenerated( *edge ))
2605 TopoDS_Edge e1 = *edge++;
2606 TopoDS_Edge e2 = ( edge == botEdges.end() ? botEdges.front() : *edge );
2607 if ( ! TopExp::CommonVertex( e1, e2, commonV ))
2609 e2 = botEdges.front();
2610 if ( ! TopExp::CommonVertex( e1, e2, commonV ))
2613 double angle = myHelper->GetAngle( e1, e2, reverseBottom, commonV );
2614 if ( angle < -5 * M_PI/180 )
2615 if ( ++nbConcaveAng > 1 )
2617 if ( angle > 85 * M_PI/180 )
2618 if ( ++nbConvexAng > 4 )
2624 //=======================================================================
2625 //function : allVerticalEdgesStraight
2626 //purpose : Defines if all "vertical" EDGEs are straight
2627 //=======================================================================
2629 bool StdMeshers_Prism_3D::allVerticalEdgesStraight( const Prism_3D::TPrismTopo& thePrism )
2631 for ( size_t i = 0; i < thePrism.myWallQuads.size(); ++i )
2633 const Prism_3D::TQuadList& quads = thePrism.myWallQuads[i];
2634 Prism_3D::TQuadList::const_iterator quadIt = quads.begin();
2635 TopoDS_Edge prevQuadEdge;
2636 for ( ; quadIt != quads.end(); ++quadIt )
2638 StdMeshers_FaceSidePtr rightSide = (*quadIt)->side[ QUAD_RIGHT_SIDE ];
2640 if ( !prevQuadEdge.IsNull() &&
2641 !SMESH_Algo::IsContinuous( rightSide->Edge( 0 ), prevQuadEdge ))
2644 for ( int iE = 0; iE < rightSide->NbEdges(); ++iE )
2646 const TopoDS_Edge & rightE = rightSide->Edge( iE );
2647 if ( !SMESH_Algo::IsStraight( rightE, /*degenResult=*/true ))
2651 !SMESH_Algo::IsContinuous( rightSide->Edge( iE-1 ), rightE ))
2654 prevQuadEdge = rightE;
2661 //=======================================================================
2662 //function : project2dMesh
2663 //purpose : Project mesh faces from a source FACE of one prism (theSrcFace)
2664 // to a source FACE of another prism (theTgtFace)
2665 //=======================================================================
2667 bool StdMeshers_Prism_3D::project2dMesh(const TopoDS_Face& theSrcFace,
2668 const TopoDS_Face& theTgtFace)
2670 TProjction2dAlgo* projector2D = TProjction2dAlgo::instance( this );
2671 projector2D->myHyp.SetSourceFace( theSrcFace );
2672 bool ok = projector2D->Compute( *myHelper->GetMesh(), theTgtFace );
2674 SMESH_subMesh* tgtSM = myHelper->GetMesh()->GetSubMesh( theTgtFace );
2675 if ( !ok && tgtSM->GetSubMeshDS() ) {
2676 //tgtSM->ComputeStateEngine( SMESH_subMesh::CLEAN ); -- avoid propagation of events
2677 SMESHDS_Mesh* meshDS = myHelper->GetMeshDS();
2678 SMESHDS_SubMesh* tgtSMDS = tgtSM->GetSubMeshDS();
2679 for ( SMDS_ElemIteratorPtr eIt = tgtSMDS->GetElements(); eIt->more(); )
2680 meshDS->RemoveFreeElement( eIt->next(), tgtSMDS, /*fromGroups=*/false );
2681 for ( SMDS_NodeIteratorPtr nIt = tgtSMDS->GetNodes(); nIt->more(); )
2682 meshDS->RemoveFreeNode( nIt->next(), tgtSMDS, /*fromGroups=*/false );
2684 tgtSM->ComputeStateEngine ( SMESH_subMesh::CHECK_COMPUTE_STATE );
2685 tgtSM->ComputeSubMeshStateEngine( SMESH_subMesh::CHECK_COMPUTE_STATE );
2687 projector2D->SetEventListener( tgtSM );
2692 //================================================================================
2694 * \brief Set projection coordinates of a node to a face and it's sub-shapes
2695 * \param faceID - the face given by in-block ID
2696 * \param params - node normalized parameters
2697 * \retval bool - is a success
2699 //================================================================================
2701 bool StdMeshers_Prism_3D::setFaceAndEdgesXYZ( const int faceID, const gp_XYZ& params, int z )
2703 // find base and top edges of the face
2704 enum { BASE = 0, TOP, LEFT, RIGHT };
2705 vector< int > edgeVec; // 0-base, 1-top
2706 SMESH_Block::GetFaceEdgesIDs( faceID, edgeVec );
2708 myBlock.EdgePoint( edgeVec[ BASE ], params, myShapeXYZ[ edgeVec[ BASE ]]);
2709 myBlock.EdgePoint( edgeVec[ TOP ], params, myShapeXYZ[ edgeVec[ TOP ]]);
2711 SHOWYXZ("\nparams ", params);
2712 SHOWYXZ("TOP is " <<edgeVec[ TOP ], myShapeXYZ[ edgeVec[ TOP]]);
2713 SHOWYXZ("BASE is "<<edgeVec[ BASE], myShapeXYZ[ edgeVec[ BASE]]);
2715 if ( faceID == SMESH_Block::ID_Fx0z || faceID == SMESH_Block::ID_Fx1z )
2717 myBlock.EdgePoint( edgeVec[ LEFT ], params, myShapeXYZ[ edgeVec[ LEFT ]]);
2718 myBlock.EdgePoint( edgeVec[ RIGHT ], params, myShapeXYZ[ edgeVec[ RIGHT ]]);
2720 SHOWYXZ("VER "<<edgeVec[ LEFT], myShapeXYZ[ edgeVec[ LEFT]]);
2721 SHOWYXZ("VER "<<edgeVec[ RIGHT], myShapeXYZ[ edgeVec[ RIGHT]]);
2723 myBlock.FacePoint( faceID, params, myShapeXYZ[ faceID ]);
2724 SHOWYXZ("FacePoint "<<faceID, myShapeXYZ[ faceID]);
2729 //=======================================================================
2731 //purpose : If (!isOK), sets the error to a sub-mesh of a current SOLID
2732 //=======================================================================
2734 bool StdMeshers_Prism_3D::toSM( bool isOK )
2736 if ( mySetErrorToSM &&
2739 !myHelper->GetSubShape().IsNull() &&
2740 myHelper->GetSubShape().ShapeType() == TopAbs_SOLID)
2742 SMESH_subMesh* sm = myHelper->GetMesh()->GetSubMesh( myHelper->GetSubShape() );
2743 sm->GetComputeError() = this->GetComputeError();
2744 // clear error in order not to return it twice
2745 _error = COMPERR_OK;
2751 //=======================================================================
2752 //function : shapeID
2753 //purpose : Return index of a shape
2754 //=======================================================================
2756 int StdMeshers_Prism_3D::shapeID( const TopoDS_Shape& S )
2758 if ( S.IsNull() ) return 0;
2759 if ( !myHelper ) return -3;
2760 return myHelper->GetMeshDS()->ShapeToIndex( S );
2763 namespace // utils used by StdMeshers_Prism_3D::IsApplicable()
2765 struct EdgeWithNeighbors
2768 int _iBase; /* index in a WIRE with non-base EDGEs excluded */
2769 int _iL, _iR; /* used to connect edges in a base FACE */
2770 bool _isBase; /* is used in a base FACE */
2771 EdgeWithNeighbors(const TopoDS_Edge& E, int iE, int nbE, int shift, bool isBase ):
2772 _edge( E ), _iBase( iE + shift ),
2773 _iL( SMESH_MesherHelper::WrapIndex( iE-1, Max( 1, nbE )) + shift ),
2774 _iR( SMESH_MesherHelper::WrapIndex( iE+1, Max( 1, nbE )) + shift ),
2778 EdgeWithNeighbors() {}
2779 bool IsInternal() const { return !_edge.IsNull() && _edge.Orientation() == TopAbs_INTERNAL; }
2781 // PrismSide contains all FACEs linking a bottom EDGE with a top one.
2784 TopoDS_Face _face; // a currently treated upper FACE
2785 TopTools_IndexedMapOfShape *_faces; // all FACEs (pointer because of a private copy constructor)
2786 TopoDS_Edge _topEdge; // a current top EDGE
2787 vector< EdgeWithNeighbors >*_edges; // all EDGEs of _face
2788 int _iBotEdge; // index of _topEdge within _edges
2789 vector< bool > _isCheckedEdge; // mark EDGEs whose two owner FACEs found
2790 int _nbCheckedEdges; // nb of EDGEs whose location is defined
2791 PrismSide *_leftSide; // neighbor sides
2792 PrismSide *_rightSide;
2793 bool _isInternal; // whether this side raises from an INTERNAL EDGE
2794 void SetExcluded() { _leftSide = _rightSide = NULL; }
2795 bool IsExcluded() const { return !_leftSide; }
2796 const TopoDS_Edge& Edge( int i ) const
2798 return (*_edges)[ i ]._edge;
2800 int FindEdge( const TopoDS_Edge& E ) const
2802 for ( size_t i = 0; i < _edges->size(); ++i )
2803 if ( E.IsSame( Edge( i ))) return i;
2806 bool IsSideFace( const TopoDS_Shape& face, const bool checkNeighbors ) const
2808 if ( _faces->Contains( face )) // avoid returning true for a prism top FACE
2809 return ( !_face.IsNull() || !( face.IsSame( _faces->FindKey( _faces->Extent() ))));
2811 if ( checkNeighbors )
2812 return (( _leftSide && _leftSide->IsSideFace ( face, false )) ||
2813 ( _rightSide && _rightSide->IsSideFace( face, false )));
2818 //--------------------------------------------------------------------------------
2820 * \brief Return another faces sharing an edge
2822 const TopoDS_Face & getAnotherFace( const TopoDS_Face& face,
2823 const TopoDS_Edge& edge,
2824 TopTools_IndexedDataMapOfShapeListOfShape& facesOfEdge)
2826 TopTools_ListIteratorOfListOfShape faceIt( facesOfEdge.FindFromKey( edge ));
2827 for ( ; faceIt.More(); faceIt.Next() )
2828 if ( !face.IsSame( faceIt.Value() ))
2829 return TopoDS::Face( faceIt.Value() );
2833 //--------------------------------------------------------------------------------
2835 * \brief Return ordered edges of a face
2837 bool getEdges( const TopoDS_Face& face,
2838 vector< EdgeWithNeighbors > & edges,
2839 TopTools_IndexedDataMapOfShapeListOfShape& facesOfEdge,
2840 const bool noHolesAllowed)
2842 TopoDS_Face f = face;
2843 if ( f.Orientation() != TopAbs_FORWARD &&
2844 f.Orientation() != TopAbs_REVERSED )
2845 f.Orientation( TopAbs_FORWARD );
2846 list< TopoDS_Edge > ee;
2847 list< int > nbEdgesInWires;
2848 int nbW = SMESH_Block::GetOrderedEdges( f, ee, nbEdgesInWires );
2849 if ( nbW > 1 && noHolesAllowed )
2852 int iE, nbTot = 0, nbBase, iBase;
2853 list< TopoDS_Edge >::iterator e = ee.begin();
2854 list< int >::iterator nbE = nbEdgesInWires.begin();
2855 for ( ; nbE != nbEdgesInWires.end(); ++nbE )
2856 for ( iE = 0; iE < *nbE; ++e, ++iE )
2857 if ( SMESH_Algo::isDegenerated( *e )) // degenerated EDGE is never used
2859 e = --ee.erase( e );
2867 for ( nbE = nbEdgesInWires.begin(); nbE != nbEdgesInWires.end(); ++nbE )
2870 isBase.resize( *nbE );
2871 list< TopoDS_Edge >::iterator eIt = e;
2872 for ( iE = 0; iE < *nbE; ++eIt, ++iE )
2874 isBase[ iE ] = ( getAnotherFace( face, *eIt, facesOfEdge ) != face );
2875 nbBase += isBase[ iE ];
2877 for ( iBase = 0, iE = 0; iE < *nbE; ++e, ++iE )
2879 edges.push_back( EdgeWithNeighbors( *e, iBase, nbBase, nbTot, isBase[ iE ] ));
2880 iBase += isBase[ iE ];
2887 // IPAL53099. Set correct neighbors to INTERNAL EDGEs, which can be connected to
2888 // EDGEs of the outer WIRE but this fact can't be detected by their order.
2891 int iFirst = 0, iLast;
2892 for ( nbE = nbEdgesInWires.begin(); nbE != nbEdgesInWires.end(); ++nbE )
2894 iLast = iFirst + *nbE - 1;
2895 TopoDS_Vertex vv[2] = { SMESH_MesherHelper::IthVertex( 0, edges[ iFirst ]._edge ),
2896 SMESH_MesherHelper::IthVertex( 1, edges[ iLast ]._edge ) };
2897 bool isConnectOk = ( vv[0].IsSame( vv[1] ));
2900 edges[ iFirst ]._iL = edges[ iFirst ]._iBase; // connect to self
2901 edges[ iLast ]._iR = edges[ iLast ]._iBase;
2903 // look for an EDGE of the outer WIREs connected to vv
2904 TopoDS_Vertex v0, v1;
2905 for ( iE = 0; iE < iFirst; ++iE )
2907 v0 = SMESH_MesherHelper::IthVertex( 0, edges[ iE ]._edge );
2908 v1 = SMESH_MesherHelper::IthVertex( 1, edges[ iE ]._edge );
2909 if ( vv[0].IsSame( v0 ) || vv[0].IsSame( v1 ))
2910 edges[ iFirst ]._iL = edges[ iE ]._iBase;
2911 if ( vv[1].IsSame( v0 ) || vv[1].IsSame( v1 ))
2912 edges[ iLast ]._iR = edges[ iE ]._iBase;
2918 return edges.size();
2921 //--------------------------------------------------------------------------------
2923 * \brief Return number of faces sharing given edges
2925 // int nbAdjacentFaces( const std::vector< EdgeWithNeighbors >& edges,
2926 // const TopTools_IndexedDataMapOfShapeListOfShape& facesOfEdge )
2928 // TopTools_MapOfShape adjFaces;
2930 // for ( size_t i = 0; i < edges.size(); ++i )
2932 // TopTools_ListIteratorOfListOfShape faceIt( facesOfEdge.FindFromKey( edges[i]._edge ));
2933 // for ( ; faceIt.More(); faceIt.Next() )
2934 // adjFaces.Add( faceIt.Value() );
2936 // return adjFaces.Extent();
2940 //================================================================================
2942 * \brief Return true if the algorithm can mesh this shape
2943 * \param [in] aShape - shape to check
2944 * \param [in] toCheckAll - if true, this check returns OK if all shapes are OK,
2945 * else, returns OK if at least one shape is OK
2947 //================================================================================
2949 bool StdMeshers_Prism_3D::IsApplicable(const TopoDS_Shape & shape, bool toCheckAll)
2951 TopExp_Explorer sExp( shape, TopAbs_SOLID );
2955 for ( ; sExp.More(); sExp.Next() )
2959 TopExp_Explorer shExp( sExp.Current(), TopAbs_SHELL );
2960 while ( shExp.More() ) {
2961 shell = shExp.Current();
2963 if ( shExp.More() && BRep_Tool::IsClosed( shExp.Current() ))
2966 if ( shell.IsNull() ) {
2967 if ( toCheckAll ) return false;
2971 TopTools_IndexedMapOfShape allFaces;
2972 TopExp::MapShapes( sExp.Current(), TopAbs_FACE, allFaces );
2973 if ( allFaces.Extent() < 3 ) {
2974 if ( toCheckAll ) return false;
2978 if ( allFaces.Extent() == 6 )
2980 TopTools_IndexedMapOfOrientedShape map;
2981 bool isBox = SMESH_Block::FindBlockShapes( TopoDS::Shell( shell ),
2982 TopoDS_Vertex(), TopoDS_Vertex(), map );
2984 if ( !toCheckAll ) return true;
2989 TopTools_IndexedMapOfShape allShapes; // usage: allShapes.FindIndex( s )
2990 TopExp::MapShapes( shape, allShapes );
2993 TopTools_IndexedDataMapOfShapeListOfShape facesOfEdge;
2994 TopTools_ListIteratorOfListOfShape faceIt;
2995 TopExp::MapShapesAndAncestors( sExp.Current(), TopAbs_EDGE, TopAbs_FACE , facesOfEdge );
2996 if ( facesOfEdge.IsEmpty() ) {
2997 if ( toCheckAll ) return false;
3001 typedef vector< EdgeWithNeighbors > TEdgeWithNeighborsVec;
3002 vector< TEdgeWithNeighborsVec > faceEdgesVec( allFaces.Extent() + 1 );
3003 const size_t nbEdgesMax = facesOfEdge.Extent() * 2; // there can be seam EDGEs
3004 TopTools_IndexedMapOfShape* facesOfSide = new TopTools_IndexedMapOfShape[ nbEdgesMax ];
3005 SMESHUtils::ArrayDeleter<TopTools_IndexedMapOfShape> delFacesOfSide( facesOfSide );
3007 // try to use each face as a bottom one
3008 bool prismDetected = false;
3009 vector< PrismSide > sides;
3010 for ( int iF = 1; iF < allFaces.Extent() && !prismDetected; ++iF )
3012 const TopoDS_Face& botF = TopoDS::Face( allFaces( iF ));
3014 TEdgeWithNeighborsVec& botEdges = faceEdgesVec[ iF ];
3015 if ( botEdges.empty() )
3016 if ( !getEdges( botF, botEdges, facesOfEdge, /*noHoles=*/false ))
3020 for ( size_t iS = 0; iS < botEdges.size(); ++iS )
3021 nbBase += botEdges[ iS ]._isBase;
3023 if ( allFaces.Extent()-1 <= nbBase )
3024 continue; // all faces are adjacent to botF - no top FACE
3026 // init data of side FACEs
3028 sides.resize( nbBase );
3030 for ( size_t iE = 0; iE < botEdges.size(); ++iE )
3032 if ( !botEdges[ iE ]._isBase )
3034 sides[ iS ]._topEdge = botEdges[ iE ]._edge;
3035 sides[ iS ]._face = botF;
3036 sides[ iS ]._leftSide = & sides[ botEdges[ iE ]._iR ];
3037 sides[ iS ]._rightSide = & sides[ botEdges[ iE ]._iL ];
3038 sides[ iS ]._isInternal = botEdges[ iE ].IsInternal();
3039 sides[ iS ]._faces = & facesOfSide[ iS ];
3040 sides[ iS ]._faces->Clear();
3044 bool isOK = true; // ok for a current botF
3045 bool isAdvanced = true; // is new data found in a current loop
3046 int nbFoundSideFaces = 0;
3047 for ( int iLoop = 0; isOK && isAdvanced; ++iLoop )
3050 for ( size_t iS = 0; iS < sides.size() && isOK; ++iS )
3052 PrismSide& side = sides[ iS ];
3053 if ( side._face.IsNull() )
3054 continue; // probably the prism top face is the last of side._faces
3056 if ( side._topEdge.IsNull() )
3058 // find vertical EDGEs --- EGDEs shared with neighbor side FACEs
3059 for ( int is2nd = 0; is2nd < 2 && isOK; ++is2nd ) // 2 adjacent neighbors
3061 int di = is2nd ? 1 : -1;
3062 const PrismSide* adjSide = is2nd ? side._rightSide : side._leftSide;
3063 for ( size_t i = 1; i < side._edges->size(); ++i )
3065 int iE = SMESH_MesherHelper::WrapIndex( i*di + side._iBotEdge, side._edges->size());
3066 if ( side._isCheckedEdge[ iE ] ) continue;
3067 const TopoDS_Edge& vertE = side.Edge( iE );
3068 const TopoDS_Shape& neighborF = getAnotherFace( side._face, vertE, facesOfEdge );
3069 bool isEdgeShared = (( adjSide->IsSideFace( neighborF, side._isInternal )) ||
3070 ( adjSide == &side && neighborF.IsSame( side._face )) );
3071 if ( isEdgeShared ) // vertE is shared with adjSide
3074 side._isCheckedEdge[ iE ] = true;
3075 side._nbCheckedEdges++;
3076 int nbNotCheckedE = side._edges->size() - side._nbCheckedEdges;
3077 if ( nbNotCheckedE == 1 )
3082 if ( i == 1 && iLoop == 0 ) isOK = false;
3088 int nbNotCheckedE = side._edges->size() - side._nbCheckedEdges;
3089 if ( nbNotCheckedE == 1 )
3091 vector<bool>::iterator ii = std::find( side._isCheckedEdge.begin(),
3092 side._isCheckedEdge.end(), false );
3093 if ( ii != side._isCheckedEdge.end() )
3095 size_t iE = std::distance( side._isCheckedEdge.begin(), ii );
3096 side._topEdge = side.Edge( iE );
3099 isOK = ( nbNotCheckedE >= 1 );
3101 else //if ( !side._topEdge.IsNull() )
3103 // get a next face of a side
3104 const TopoDS_Shape& f = getAnotherFace( side._face, side._topEdge, facesOfEdge );
3105 side._faces->Add( f );
3107 if ( f.IsSame( side._face ) || // _topEdge is a seam
3108 SMESH_MesherHelper::Count( f, TopAbs_WIRE, false ) != 1 )
3112 else if ( side._leftSide != & side && // not closed side face
3113 side._leftSide->_faces->Contains( f ))
3115 stop = true; // probably f is the prism top face
3116 side._leftSide->_face.Nullify();
3117 side._leftSide->_topEdge.Nullify();
3119 else if ( side._rightSide != & side &&
3120 side._rightSide->_faces->Contains( f ))
3122 stop = true; // probably f is the prism top face
3123 side._rightSide->_face.Nullify();
3124 side._rightSide->_topEdge.Nullify();
3128 side._face.Nullify();
3129 side._topEdge.Nullify();
3132 side._face = TopoDS::Face( f );
3133 int faceID = allFaces.FindIndex( side._face );
3134 side._edges = & faceEdgesVec[ faceID ];
3135 if ( side._edges->empty() )
3136 if ( !getEdges( side._face, * side._edges, facesOfEdge, /*noHoles=*/true ))
3138 const int nbE = side._edges->size();
3143 side._iBotEdge = side.FindEdge( side._topEdge );
3144 side._isCheckedEdge.clear();
3145 side._isCheckedEdge.resize( nbE, false );
3146 side._isCheckedEdge[ side._iBotEdge ] = true;
3147 side._nbCheckedEdges = 1; // bottom EDGE is known
3149 else // probably a triangular top face found
3151 side._face.Nullify();
3153 side._topEdge.Nullify();
3154 isOK = ( !side._edges->empty() || side._faces->Extent() > 1 );
3156 } //if ( !side._topEdge.IsNull() )
3158 } // loop on prism sides
3160 if ( nbFoundSideFaces > allFaces.Extent() )
3164 if ( iLoop > allFaces.Extent() * 10 )
3168 cerr << "BUG: infinite loop in StdMeshers_Prism_3D::IsApplicable()" << endl;
3171 } // while isAdvanced
3173 if ( isOK && sides[0]._faces->Extent() > 1 )
3175 const int nbFaces = sides[0]._faces->Extent();
3176 if ( botEdges.size() == 1 ) // cylinder
3178 prismDetected = ( nbFaces == allFaces.Extent()-1 );
3182 const TopoDS_Shape& topFace = sides[0]._faces->FindKey( nbFaces );
3184 for ( iS = 1; iS < sides.size(); ++iS )
3185 if ( ! sides[ iS ]._faces->Contains( topFace ))
3187 prismDetected = ( iS == sides.size() );
3190 } // loop on allFaces
3192 if ( !prismDetected && toCheckAll ) return false;
3193 if ( prismDetected && !toCheckAll ) return true;
3202 //================================================================================
3204 * \brief Return true if this node and other one belong to one face
3206 //================================================================================
3208 bool Prism_3D::TNode::IsNeighbor( const Prism_3D::TNode& other ) const
3210 if ( !other.myNode || !myNode ) return false;
3212 SMDS_ElemIteratorPtr fIt = other.myNode->GetInverseElementIterator(SMDSAbs_Face);
3213 while ( fIt->more() )
3214 if ( fIt->next()->GetNodeIndex( myNode ) >= 0 )
3219 //================================================================================
3221 * \brief Prism initialization
3223 //================================================================================
3225 void TPrismTopo::Clear()
3227 myShape3D.Nullify();
3230 myWallQuads.clear();
3231 myBottomEdges.clear();
3232 myNbEdgesInWires.clear();
3233 myWallQuads.clear();
3236 //================================================================================
3238 * \brief Set upside-down
3240 //================================================================================
3242 void TPrismTopo::SetUpsideDown()
3244 std::swap( myBottom, myTop );
3245 myBottomEdges.clear();
3246 std::reverse( myBottomEdges.begin(), myBottomEdges.end() );
3247 for ( size_t i = 0; i < myWallQuads.size(); ++i )
3249 myWallQuads[i].reverse();
3250 TQuadList::iterator q = myWallQuads[i].begin();
3251 for ( ; q != myWallQuads[i].end(); ++q )
3253 (*q)->shift( 2, /*keepUnitOri=*/true );
3255 myBottomEdges.push_back( myWallQuads[i].front()->side[ QUAD_BOTTOM_SIDE ].grid->Edge(0) );
3259 } // namespace Prism_3D
3261 //================================================================================
3263 * \brief Constructor. Initialization is needed
3265 //================================================================================
3267 StdMeshers_PrismAsBlock::StdMeshers_PrismAsBlock()
3272 StdMeshers_PrismAsBlock::~StdMeshers_PrismAsBlock()
3276 void StdMeshers_PrismAsBlock::Clear()
3279 myShapeIDMap.Clear();
3283 delete mySide; mySide = 0;
3285 myParam2ColumnMaps.clear();
3286 myShapeIndex2ColumnMap.clear();
3289 //=======================================================================
3290 //function : initPrism
3291 //purpose : Analyse shape geometry and mesh.
3292 // If there are triangles on one of faces, it becomes 'bottom'.
3293 // thePrism.myBottom can be already set up.
3294 //=======================================================================
3296 bool StdMeshers_Prism_3D::initPrism(Prism_3D::TPrismTopo& thePrism,
3297 const TopoDS_Shape& theShape3D,
3298 const bool selectBottom)
3300 myHelper->SetSubShape( theShape3D );
3302 SMESH_subMesh* mainSubMesh = myHelper->GetMesh()->GetSubMeshContaining( theShape3D );
3303 if ( !mainSubMesh ) return toSM( error(COMPERR_BAD_INPUT_MESH,"Null submesh of shape3D"));
3305 // detect not-quad FACE sub-meshes of the 3D SHAPE
3306 list< SMESH_subMesh* > notQuadGeomSubMesh;
3307 list< SMESH_subMesh* > notQuadElemSubMesh;
3308 list< SMESH_subMesh* > meshedSubMesh;
3311 SMESH_subMeshIteratorPtr smIt = mainSubMesh->getDependsOnIterator(false,true);
3312 while ( smIt->more() )
3314 SMESH_subMesh* sm = smIt->next();
3315 const TopoDS_Shape& face = sm->GetSubShape();
3316 if ( face.ShapeType() > TopAbs_FACE ) break;
3317 else if ( face.ShapeType() < TopAbs_FACE ) continue;
3320 // is quadrangle FACE?
3321 list< TopoDS_Edge > orderedEdges;
3322 list< int > nbEdgesInWires;
3323 int nbWires = SMESH_Block::GetOrderedEdges( TopoDS::Face( face ), orderedEdges,
3325 if ( nbWires != 1 || nbEdgesInWires.front() != 4 )
3326 notQuadGeomSubMesh.push_back( sm );
3328 // look for a not structured sub-mesh
3329 if ( !sm->IsEmpty() )
3331 meshedSubMesh.push_back( sm );
3332 if ( !myHelper->IsSameElemGeometry( sm->GetSubMeshDS(), SMDSGeom_QUADRANGLE ) ||
3333 !myHelper->IsStructured ( sm ))
3334 notQuadElemSubMesh.push_back( sm );
3338 int nbNotQuadMeshed = notQuadElemSubMesh.size();
3339 int nbNotQuad = notQuadGeomSubMesh.size();
3340 bool hasNotQuad = ( nbNotQuad || nbNotQuadMeshed );
3343 if ( nbNotQuadMeshed > 2 )
3345 return toSM( error(COMPERR_BAD_INPUT_MESH,
3346 TCom("More than 2 faces with not quadrangle elements: ")
3347 <<nbNotQuadMeshed));
3349 if ( nbNotQuad > 2 || !thePrism.myBottom.IsNull() )
3351 // Issue 0020843 - one of side FACEs is quasi-quadrilateral (not 4 EDGEs).
3352 // Remove from notQuadGeomSubMesh faces meshed with regular grid
3353 int nbQuasiQuads = removeQuasiQuads( notQuadGeomSubMesh, myHelper,
3354 TQuadrangleAlgo::instance(this,myHelper) );
3355 nbNotQuad -= nbQuasiQuads;
3356 if ( nbNotQuad > 2 )
3357 return toSM( error(COMPERR_BAD_SHAPE,
3358 TCom("More than 2 not quadrilateral faces: ") <<nbNotQuad));
3359 hasNotQuad = ( nbNotQuad || nbNotQuadMeshed );
3362 // Analyse mesh and topology of FACEs: choose the bottom sub-mesh.
3363 // If there are not quadrangle FACEs, they are top and bottom ones.
3364 // Not quadrangle FACEs must be only on top and bottom.
3366 SMESH_subMesh * botSM = 0;
3367 SMESH_subMesh * topSM = 0;
3369 if ( hasNotQuad ) // can choose a bottom FACE
3371 if ( nbNotQuadMeshed > 0 ) botSM = notQuadElemSubMesh.front();
3372 else botSM = notQuadGeomSubMesh.front();
3373 if ( nbNotQuadMeshed > 1 ) topSM = notQuadElemSubMesh.back();
3374 else if ( nbNotQuad > 1 ) topSM = notQuadGeomSubMesh.back();
3376 if ( topSM == botSM ) {
3377 if ( nbNotQuadMeshed > 1 ) topSM = notQuadElemSubMesh.front();
3378 else topSM = notQuadGeomSubMesh.front();
3381 // detect mesh triangles on wall FACEs
3382 if ( nbNotQuad == 2 && nbNotQuadMeshed > 0 ) {
3384 if ( nbNotQuadMeshed == 1 )
3385 ok = ( find( notQuadGeomSubMesh.begin(),
3386 notQuadGeomSubMesh.end(), botSM ) != notQuadGeomSubMesh.end() );
3388 ok = ( notQuadGeomSubMesh == notQuadElemSubMesh );
3390 return toSM( error(COMPERR_BAD_INPUT_MESH,
3391 "Side face meshed with not quadrangle elements"));
3395 thePrism.myNotQuadOnTop = ( nbNotQuadMeshed > 1 );
3397 // use thePrism.myBottom
3398 if ( !thePrism.myBottom.IsNull() )
3400 if ( botSM ) { // <-- not quad geom or mesh on botSM
3401 if ( ! botSM->GetSubShape().IsSame( thePrism.myBottom )) {
3402 std::swap( botSM, topSM );
3403 if ( !botSM || ! botSM->GetSubShape().IsSame( thePrism.myBottom )) {
3404 if ( !selectBottom )
3405 return toSM( error( COMPERR_BAD_INPUT_MESH,
3406 "Incompatible non-structured sub-meshes"));
3407 std::swap( botSM, topSM );
3408 thePrism.myBottom = TopoDS::Face( botSM->GetSubShape() );
3412 else if ( !selectBottom ) {
3413 botSM = myHelper->GetMesh()->GetSubMesh( thePrism.myBottom );
3416 if ( !botSM ) // find a proper bottom
3418 bool savedSetErrorToSM = mySetErrorToSM;
3419 mySetErrorToSM = false; // ingore errors in initPrism()
3421 // search among meshed FACEs
3422 list< SMESH_subMesh* >::iterator sm = meshedSubMesh.begin();
3423 for ( ; !botSM && sm != meshedSubMesh.end(); ++sm )
3427 thePrism.myBottom = TopoDS::Face( botSM->GetSubShape() );
3428 if ( !initPrism( thePrism, theShape3D, /*selectBottom=*/false ))
3431 // search among all FACEs
3432 for ( TopExp_Explorer f( theShape3D, TopAbs_FACE ); !botSM && f.More(); f.Next() )
3434 int minNbFaces = 2 + myHelper->Count( f.Current(), TopAbs_EDGE, false);
3435 if ( nbFaces < minNbFaces) continue;
3437 thePrism.myBottom = TopoDS::Face( f.Current() );
3438 botSM = myHelper->GetMesh()->GetSubMesh( thePrism.myBottom );
3439 if ( !initPrism( thePrism, theShape3D, /*selectBottom=*/false ))
3442 mySetErrorToSM = savedSetErrorToSM;
3443 return botSM ? true : toSM( error( COMPERR_BAD_SHAPE ));
3446 // find vertex 000 - the one with smallest coordinates (for easy DEBUG :-)
3448 double minVal = DBL_MAX, minX = 0, val;
3449 for ( TopExp_Explorer exp( botSM->GetSubShape(), TopAbs_VERTEX );
3450 exp.More(); exp.Next() )
3452 const TopoDS_Vertex& v = TopoDS::Vertex( exp.Current() );
3453 gp_Pnt P = BRep_Tool::Pnt( v );
3454 val = P.X() + P.Y() + P.Z();
3455 if ( val < minVal || ( val == minVal && P.X() < minX )) {
3462 thePrism.myShape3D = theShape3D;
3463 if ( thePrism.myBottom.IsNull() )
3464 thePrism.myBottom = TopoDS::Face( botSM->GetSubShape() );
3465 thePrism.myBottom.Orientation( myHelper->GetSubShapeOri( theShape3D, thePrism.myBottom ));
3466 thePrism.myTop. Orientation( myHelper->GetSubShapeOri( theShape3D, thePrism.myTop ));
3468 // Get ordered bottom edges
3469 TopoDS_Face reverseBottom = // to have order of top EDGEs as in the top FACE
3470 TopoDS::Face( thePrism.myBottom.Reversed() );
3471 SMESH_Block::GetOrderedEdges( reverseBottom,
3472 thePrism.myBottomEdges,
3473 thePrism.myNbEdgesInWires, V000 );
3475 // Get Wall faces corresponding to the ordered bottom edges and the top FACE
3476 if ( !getWallFaces( thePrism, nbFaces )) // it also sets thePrism.myTop
3477 return false; //toSM( error(COMPERR_BAD_SHAPE, "Can't find side faces"));
3481 if ( !thePrism.myTop.IsSame( topSM->GetSubShape() ))
3483 (notQuadGeomSubMesh.empty() ? COMPERR_BAD_INPUT_MESH : COMPERR_BAD_SHAPE,
3484 "Non-quadrilateral faces are not opposite"));
3486 // check that the found top and bottom FACEs are opposite
3487 TopTools_IndexedMapOfShape topEdgesMap( thePrism.myBottomEdges.size() );
3488 TopExp::MapShapes( thePrism.myTop, topEdgesMap );
3489 list< TopoDS_Edge >::iterator edge = thePrism.myBottomEdges.begin();
3490 for ( ; edge != thePrism.myBottomEdges.end(); ++edge )
3491 if ( topEdgesMap.Contains( *edge ))
3493 (notQuadGeomSubMesh.empty() ? COMPERR_BAD_INPUT_MESH : COMPERR_BAD_SHAPE,
3494 "Non-quadrilateral faces are not opposite"));
3497 if ( thePrism.myBottomEdges.size() > thePrism.myWallQuads.size() )
3499 // composite bottom sides => set thePrism upside-down
3500 thePrism.SetUpsideDown();
3506 //================================================================================
3508 * \brief Initialization.
3509 * \param helper - helper loaded with mesh and 3D shape
3510 * \param thePrism - a prism data
3511 * \retval bool - false if a mesh or a shape are KO
3513 //================================================================================
3515 bool StdMeshers_PrismAsBlock::Init(SMESH_MesherHelper* helper,
3516 const Prism_3D::TPrismTopo& thePrism)
3519 SMESHDS_Mesh* meshDS = myHelper->GetMeshDS();
3520 SMESH_Mesh* mesh = myHelper->GetMesh();
3523 delete mySide; mySide = 0;
3525 vector< TSideFace* > sideFaces( NB_WALL_FACES, 0 );
3526 vector< pair< double, double> > params( NB_WALL_FACES );
3527 mySide = new TSideFace( *mesh, sideFaces, params );
3530 SMESH_Block::init();
3531 myShapeIDMap.Clear();
3532 myShapeIndex2ColumnMap.clear();
3534 int wallFaceIds[ NB_WALL_FACES ] = { // to walk around a block
3535 SMESH_Block::ID_Fx0z, SMESH_Block::ID_F1yz,
3536 SMESH_Block::ID_Fx1z, SMESH_Block::ID_F0yz
3539 myError = SMESH_ComputeError::New();
3541 myNotQuadOnTop = thePrism.myNotQuadOnTop;
3543 // Find columns of wall nodes and calculate edges' lengths
3544 // --------------------------------------------------------
3546 myParam2ColumnMaps.clear();
3547 myParam2ColumnMaps.resize( thePrism.myBottomEdges.size() ); // total nb edges
3549 size_t iE, nbEdges = thePrism.myNbEdgesInWires.front(); // nb outer edges
3550 vector< double > edgeLength( nbEdges );
3551 multimap< double, int > len2edgeMap;
3553 // for each EDGE: either split into several parts, or join with several next EDGEs
3554 vector<int> nbSplitPerEdge( nbEdges, 0 );
3555 vector<int> nbUnitePerEdge( nbEdges, 0 ); // -1 means "joined to a previous"
3557 // consider continuous straight EDGEs as one side
3558 const int nbSides = countNbSides( thePrism, nbUnitePerEdge, edgeLength );
3560 list< TopoDS_Edge >::const_iterator edgeIt = thePrism.myBottomEdges.begin();
3561 for ( iE = 0; iE < nbEdges; ++iE, ++edgeIt )
3563 TParam2ColumnMap & faceColumns = myParam2ColumnMaps[ iE ];
3565 Prism_3D::TQuadList::const_iterator quad = thePrism.myWallQuads[ iE ].begin();
3566 for ( ; quad != thePrism.myWallQuads[ iE ].end(); ++quad )
3568 const TopoDS_Edge& quadBot = (*quad)->side[ QUAD_BOTTOM_SIDE ].grid->Edge( 0 );
3569 if ( !myHelper->LoadNodeColumns( faceColumns, (*quad)->face, quadBot, meshDS ))
3570 return error(COMPERR_BAD_INPUT_MESH, TCom("Can't find regular quadrangle mesh ")
3571 << "on a side face #" << MeshDS()->ShapeToIndex( (*quad)->face ));
3573 SHOWYXZ("\np1 F " <<iE, gpXYZ(faceColumns.begin()->second.front() ));
3574 SHOWYXZ("p2 F " <<iE, gpXYZ(faceColumns.rbegin()->second.front() ));
3575 SHOWYXZ("V First "<<iE, BRep_Tool::Pnt( TopExp::FirstVertex(*edgeIt,true )));
3577 if ( nbSides < NB_WALL_FACES ) // fill map used to split faces
3578 len2edgeMap.insert( make_pair( edgeLength[ iE ], iE )); // sort edges by length
3580 // Load columns of internal edges (forming holes)
3581 // and fill map ShapeIndex to TParam2ColumnMap for them
3582 for ( ; edgeIt != thePrism.myBottomEdges.end() ; ++edgeIt, ++iE )
3584 TParam2ColumnMap & faceColumns = myParam2ColumnMaps[ iE ];
3586 Prism_3D::TQuadList::const_iterator quad = thePrism.myWallQuads[ iE ].begin();
3587 for ( ; quad != thePrism.myWallQuads[ iE ].end(); ++quad )
3589 const TopoDS_Edge& quadBot = (*quad)->side[ QUAD_BOTTOM_SIDE ].grid->Edge( 0 );
3590 if ( !myHelper->LoadNodeColumns( faceColumns, (*quad)->face, quadBot, meshDS ))
3591 return error(COMPERR_BAD_INPUT_MESH, TCom("Can't find regular quadrangle mesh ")
3592 << "on a side face #" << MeshDS()->ShapeToIndex( (*quad)->face ));
3594 if ( !faceColumns.empty() && (int)faceColumns.begin()->second.size() != VerticalSize() )
3595 return error(COMPERR_BAD_INPUT_MESH, "Different 'vertical' discretization");
3598 int id = MeshDS()->ShapeToIndex( *edgeIt );
3599 bool isForward = true; // meaningless for intenal wires
3600 myShapeIndex2ColumnMap[ id ] = make_pair( & faceColumns, isForward );
3601 // columns for vertices
3603 const SMDS_MeshNode* n0 = faceColumns.begin()->second.front();
3604 id = n0->getshapeId();
3605 myShapeIndex2ColumnMap[ id ] = make_pair( & faceColumns, isForward );
3607 const SMDS_MeshNode* n1 = faceColumns.rbegin()->second.front();
3608 id = n1->getshapeId();
3609 myShapeIndex2ColumnMap[ id ] = make_pair( & faceColumns, isForward );
3611 // SHOWYXZ("\np1 F " <<iE, gpXYZ(faceColumns.begin()->second.front() ));
3612 // SHOWYXZ("p2 F " <<iE, gpXYZ(faceColumns.rbegin()->second.front() ));
3613 // SHOWYXZ("V First "<<iE, BRep_Tool::Pnt( TopExp::FirstVertex(*edgeIt,true )));
3616 // Create 4 wall faces of a block
3617 // -------------------------------
3619 if ( nbSides <= NB_WALL_FACES ) // ************* Split faces if necessary
3621 if ( nbSides != NB_WALL_FACES ) // define how to split
3623 if ( len2edgeMap.size() != nbEdges )
3624 RETURN_BAD_RESULT("Uniqueness of edge lengths not assured");
3626 multimap< double, int >::reverse_iterator maxLen_i = len2edgeMap.rbegin();
3627 multimap< double, int >::reverse_iterator midLen_i = ++len2edgeMap.rbegin();
3629 double maxLen = maxLen_i->first;
3630 double midLen = ( len2edgeMap.size() == 1 ) ? 0 : midLen_i->first;
3631 switch ( nbEdges ) {
3632 case 1: // 0-th edge is split into 4 parts
3633 nbSplitPerEdge[ 0 ] = 4;
3635 case 2: // either the longest edge is split into 3 parts, or both edges into halves
3636 if ( maxLen / 3 > midLen / 2 ) {
3637 nbSplitPerEdge[ maxLen_i->second ] = 3;
3640 nbSplitPerEdge[ maxLen_i->second ] = 2;
3641 nbSplitPerEdge[ midLen_i->second ] = 2;
3646 // split longest into 3 parts
3647 nbSplitPerEdge[ maxLen_i->second ] = 3;
3649 // split longest into halves
3650 nbSplitPerEdge[ maxLen_i->second ] = 2;
3654 else // **************************** Unite faces
3656 int nbExraFaces = nbSides - 4; // nb of faces to fuse
3657 for ( iE = 0; iE < nbEdges; ++iE )
3659 if ( nbUnitePerEdge[ iE ] < 0 )
3661 // look for already united faces
3662 for ( size_t i = iE; i < iE + nbExraFaces; ++i )
3664 if ( nbUnitePerEdge[ i ] > 0 ) // a side including nbUnitePerEdge[i]+1 edge
3665 nbExraFaces += nbUnitePerEdge[ i ];
3666 nbUnitePerEdge[ i ] = -1;
3668 nbUnitePerEdge[ iE ] = nbExraFaces;
3673 // Create TSideFace's
3675 list< TopoDS_Edge >::const_iterator botE = thePrism.myBottomEdges.begin();
3676 for ( iE = 0; iE < nbEdges; ++iE, ++botE )
3678 TFaceQuadStructPtr quad = thePrism.myWallQuads[ iE ].front();
3679 const int nbSplit = nbSplitPerEdge[ iE ];
3680 const int nbExraFaces = nbUnitePerEdge[ iE ] + 1;
3681 if ( nbSplit > 0 ) // split
3683 vector< double > params;
3684 splitParams( nbSplit, &myParam2ColumnMaps[ iE ], params );
3685 const bool isForward =
3686 StdMeshers_PrismAsBlock::IsForwardEdge( myHelper->GetMeshDS(),
3687 myParam2ColumnMaps[iE],
3688 *botE, SMESH_Block::ID_Fx0z );
3689 for ( int i = 0; i < nbSplit; ++i ) {
3690 double f = ( isForward ? params[ i ] : params[ nbSplit - i-1 ]);
3691 double l = ( isForward ? params[ i+1 ] : params[ nbSplit - i ]);
3692 TSideFace* comp = new TSideFace( *mesh, wallFaceIds[ iSide ],
3693 thePrism.myWallQuads[ iE ], *botE,
3694 &myParam2ColumnMaps[ iE ], f, l );
3695 mySide->SetComponent( iSide++, comp );
3698 else if ( nbExraFaces > 1 ) // unite
3700 double u0 = 0, sumLen = 0;
3701 for ( size_t i = iE; i < iE + nbExraFaces; ++i )
3702 sumLen += edgeLength[ i ];
3704 vector< TSideFace* > components( nbExraFaces );
3705 vector< pair< double, double> > params( nbExraFaces );
3706 bool endReached = false;
3707 for ( int i = 0; i < nbExraFaces; ++i, ++botE, ++iE )
3709 if ( iE == nbEdges )
3712 botE = thePrism.myBottomEdges.begin();
3715 components[ i ] = new TSideFace( *mesh, wallFaceIds[ iSide ],
3716 thePrism.myWallQuads[ iE ], *botE,
3717 &myParam2ColumnMaps[ iE ]);
3718 double u1 = u0 + edgeLength[ iE ] / sumLen;
3719 params[ i ] = make_pair( u0 , u1 );
3722 TSideFace* comp = new TSideFace( *mesh, components, params );
3723 mySide->SetComponent( iSide++, comp );
3726 --iE; // for increment in an external loop on iE
3729 else if ( nbExraFaces < 0 ) // skip already united face
3734 TSideFace* comp = new TSideFace( *mesh, wallFaceIds[ iSide ],
3735 thePrism.myWallQuads[ iE ], *botE,
3736 &myParam2ColumnMaps[ iE ]);
3737 mySide->SetComponent( iSide++, comp );
3742 // Fill geometry fields of SMESH_Block
3743 // ------------------------------------
3745 vector< int > botEdgeIdVec;
3746 SMESH_Block::GetFaceEdgesIDs( ID_BOT_FACE, botEdgeIdVec );
3748 bool isForward[NB_WALL_FACES] = { true, true, true, true };
3749 Adaptor2d_Curve2d* botPcurves[NB_WALL_FACES];
3750 Adaptor2d_Curve2d* topPcurves[NB_WALL_FACES];
3752 for ( int iF = 0; iF < NB_WALL_FACES; ++iF )
3754 TSideFace * sideFace = mySide->GetComponent( iF );
3756 RETURN_BAD_RESULT("NULL TSideFace");
3757 int fID = sideFace->FaceID(); // in-block ID
3759 // fill myShapeIDMap
3760 if ( sideFace->InsertSubShapes( myShapeIDMap ) != 8 &&
3761 !sideFace->IsComplex())
3762 MESSAGE( ": Warning : InsertSubShapes() < 8 on side " << iF );
3764 // side faces geometry
3765 Adaptor2d_Curve2d* pcurves[NB_WALL_FACES];
3766 if ( !sideFace->GetPCurves( pcurves ))
3767 RETURN_BAD_RESULT("TSideFace::GetPCurves() failed");
3769 SMESH_Block::TFace& tFace = myFace[ fID - ID_FirstF ];
3770 tFace.Set( fID, sideFace->Surface(), pcurves, isForward );
3772 SHOWYXZ( endl<<"F "<< iF << " id " << fID << " FRW " << sideFace->IsForward(), sideFace->Value(0,0));
3773 // edges 3D geometry
3774 vector< int > edgeIdVec;
3775 SMESH_Block::GetFaceEdgesIDs( fID, edgeIdVec );
3776 for ( int isMax = 0; isMax < 2; ++isMax ) {
3778 int eID = edgeIdVec[ isMax ];
3779 SMESH_Block::TEdge& tEdge = myEdge[ eID - ID_FirstE ];
3780 tEdge.Set( eID, sideFace->HorizCurve(isMax), true);
3781 SHOWYXZ(eID<<" HOR"<<isMax<<"(0)", sideFace->HorizCurve(isMax)->Value(0));
3782 SHOWYXZ(eID<<" HOR"<<isMax<<"(1)", sideFace->HorizCurve(isMax)->Value(1));
3785 int eID = edgeIdVec[ isMax+2 ];
3786 SMESH_Block::TEdge& tEdge = myEdge[ eID - ID_FirstE ];
3787 tEdge.Set( eID, sideFace->VertiCurve(isMax), true);
3788 SHOWYXZ(eID<<" VER"<<isMax<<"(0)", sideFace->VertiCurve(isMax)->Value(0));
3789 SHOWYXZ(eID<<" VER"<<isMax<<"(1)", sideFace->VertiCurve(isMax)->Value(1));
3792 vector< int > vertexIdVec;
3793 SMESH_Block::GetEdgeVertexIDs( eID, vertexIdVec );
3794 myPnt[ vertexIdVec[0] - ID_FirstV ] = tEdge.GetCurve()->Value(0).XYZ();
3795 myPnt[ vertexIdVec[1] - ID_FirstV ] = tEdge.GetCurve()->Value(1).XYZ();
3798 // pcurves on horizontal faces
3799 for ( iE = 0; iE < NB_WALL_FACES; ++iE ) {
3800 if ( edgeIdVec[ BOTTOM_EDGE ] == botEdgeIdVec[ iE ] ) {
3801 botPcurves[ iE ] = sideFace->HorizPCurve( false, thePrism.myBottom );
3802 topPcurves[ iE ] = sideFace->HorizPCurve( true, thePrism.myTop );
3806 //sideFace->dumpNodes( 4 ); // debug
3808 // horizontal faces geometry
3810 SMESH_Block::TFace& tFace = myFace[ ID_BOT_FACE - ID_FirstF ];
3811 tFace.Set( ID_BOT_FACE, new BRepAdaptor_Surface( thePrism.myBottom ), botPcurves, isForward );
3812 SMESH_Block::Insert( thePrism.myBottom, ID_BOT_FACE, myShapeIDMap );
3815 SMESH_Block::TFace& tFace = myFace[ ID_TOP_FACE - ID_FirstF ];
3816 tFace.Set( ID_TOP_FACE, new BRepAdaptor_Surface( thePrism.myTop ), topPcurves, isForward );
3817 SMESH_Block::Insert( thePrism.myTop, ID_TOP_FACE, myShapeIDMap );
3819 //faceGridToPythonDump( SMESH_Block::ID_Fxy0, 50 );
3820 //faceGridToPythonDump( SMESH_Block::ID_Fxy1 );
3822 // Fill map ShapeIndex to TParam2ColumnMap
3823 // ----------------------------------------
3825 list< TSideFace* > fList;
3826 list< TSideFace* >::iterator fListIt;
3827 fList.push_back( mySide );
3828 for ( fListIt = fList.begin(); fListIt != fList.end(); ++fListIt)
3830 int nb = (*fListIt)->NbComponents();
3831 for ( int i = 0; i < nb; ++i ) {
3832 if ( TSideFace* comp = (*fListIt)->GetComponent( i ))
3833 fList.push_back( comp );
3835 if ( TParam2ColumnMap* cols = (*fListIt)->GetColumns()) {
3836 // columns for a base edge
3837 int id = MeshDS()->ShapeToIndex( (*fListIt)->BaseEdge() );
3838 bool isForward = (*fListIt)->IsForward();
3839 myShapeIndex2ColumnMap[ id ] = make_pair( cols, isForward );
3841 // columns for vertices
3842 const SMDS_MeshNode* n0 = cols->begin()->second.front();
3843 id = n0->getshapeId();
3844 myShapeIndex2ColumnMap[ id ] = make_pair( cols, isForward );
3846 const SMDS_MeshNode* n1 = cols->rbegin()->second.front();
3847 id = n1->getshapeId();
3848 myShapeIndex2ColumnMap[ id ] = make_pair( cols, !isForward );
3852 // #define SHOWYXZ(msg, xyz) { gp_Pnt p(xyz); cout << msg << " ("<< p.X() << "; " <<p.Y() << "; " <<p.Z() << ") " <<endl; }
3854 // double _u[]={ 0.1, 0.1, 0.9, 0.9 };
3855 // double _v[]={ 0.1, 0.9, 0.1, 0.9 };
3856 // for ( int z = 0; z < 2; ++z )
3857 // for ( int i = 0; i < 4; ++i )
3859 // //gp_XYZ testPar(0.25, 0.25, 0), testCoord;
3860 // int iFace = (z ? ID_TOP_FACE : ID_BOT_FACE);
3861 // gp_XYZ testPar(_u[i], _v[i], z), testCoord;
3862 // if ( !FacePoint( iFace, testPar, testCoord ))
3863 // RETURN_BAD_RESULT("TEST FacePoint() FAILED");
3864 // SHOWYXZ("IN TEST PARAM" , testPar);
3865 // SHOWYXZ("OUT TEST CORD" , testCoord);
3866 // if ( !ComputeParameters( testCoord, testPar , iFace))
3867 // RETURN_BAD_RESULT("TEST ComputeParameters() FAILED");
3868 // SHOWYXZ("OUT TEST PARAM" , testPar);
3873 //================================================================================
3875 * \brief Return pointer to column of nodes
3876 * \param node - bottom node from which the returned column goes up
3877 * \retval const TNodeColumn* - the found column
3879 //================================================================================
3881 const TNodeColumn* StdMeshers_PrismAsBlock::GetNodeColumn(const SMDS_MeshNode* node) const
3883 int sID = node->getshapeId();
3885 map<int, pair< TParam2ColumnMap*, bool > >::const_iterator col_frw =
3886 myShapeIndex2ColumnMap.find( sID );
3887 if ( col_frw != myShapeIndex2ColumnMap.end() ) {
3888 const TParam2ColumnMap* cols = col_frw->second.first;
3889 TParam2ColumnIt u_col = cols->begin();
3890 for ( ; u_col != cols->end(); ++u_col )
3891 if ( u_col->second[ 0 ] == node )
3892 return & u_col->second;
3897 //=======================================================================
3898 //function : GetLayersTransformation
3899 //purpose : Return transformations to get coordinates of nodes of each layer
3900 // by nodes of the bottom. Layer is a set of nodes at a certain step
3901 // from bottom to top.
3902 // Transformation to get top node from bottom ones is computed
3903 // only if the top FACE is not meshed.
3904 //=======================================================================
3906 bool StdMeshers_PrismAsBlock::GetLayersTransformation(vector<gp_Trsf> & trsf,
3907 const Prism_3D::TPrismTopo& prism) const
3909 const bool itTopMeshed = !SubMesh( ID_BOT_FACE )->IsEmpty();
3910 const int zSize = VerticalSize();
3911 if ( zSize < 3 && !itTopMeshed ) return true;
3912 trsf.resize( zSize - 1 );
3914 // Select some node columns by which we will define coordinate system of layers
3916 vector< const TNodeColumn* > columns;
3919 list< TopoDS_Edge >::const_iterator edgeIt = prism.myBottomEdges.begin();
3920 for ( int iE = 0; iE < prism.myNbEdgesInWires.front(); ++iE, ++edgeIt )
3922 if ( SMESH_Algo::isDegenerated( *edgeIt )) continue;
3923 const TParam2ColumnMap* u2colMap =
3924 GetParam2ColumnMap( MeshDS()->ShapeToIndex( *edgeIt ), isReverse );
3925 if ( !u2colMap ) return false;
3926 double f = u2colMap->begin()->first, l = u2colMap->rbegin()->first;
3927 //isReverse = ( edgeIt->Orientation() == TopAbs_REVERSED );
3928 //if ( isReverse ) swap ( f, l ); -- u2colMap takes orientation into account
3929 const int nbCol = 5;
3930 for ( int i = 0; i < nbCol; ++i )
3932 double u = f + i/double(nbCol) * ( l - f );
3933 const TNodeColumn* col = & getColumn( u2colMap, u )->second;
3934 if ( columns.empty() || col != columns.back() )
3935 columns.push_back( col );
3940 // Find tolerance to check transformations
3945 for ( size_t i = 0; i < columns.size(); ++i )
3946 bndBox.Add( gpXYZ( columns[i]->front() ));
3947 tol2 = bndBox.SquareExtent() * 1e-5;
3950 // Compute transformations
3953 gp_Trsf fromCsZ, toCs0;
3954 gp_Ax3 cs0 = getLayerCoordSys(0, columns, xCol );
3955 //double dist0 = cs0.Location().Distance( gpXYZ( (*columns[0])[0]));
3956 toCs0.SetTransformation( cs0 );
3957 for ( int z = 1; z < zSize; ++z )
3959 gp_Ax3 csZ = getLayerCoordSys(z, columns, xCol );
3960 //double distZ = csZ.Location().Distance( gpXYZ( (*columns[0])[z]));
3961 fromCsZ.SetTransformation( csZ );
3963 gp_Trsf& t = trsf[ z-1 ];
3964 t = fromCsZ * toCs0;
3965 //t.SetScaleFactor( distZ/dist0 ); - it does not work properly, wrong base point
3967 // check a transformation
3968 for ( size_t i = 0; i < columns.size(); ++i )
3970 gp_Pnt p0 = gpXYZ( (*columns[i])[0] );
3971 gp_Pnt pz = gpXYZ( (*columns[i])[z] );
3972 t.Transforms( p0.ChangeCoord() );
3973 if ( p0.SquareDistance( pz ) > tol2 )
3976 return ( z == zSize - 1 ); // OK if fails only botton->top trsf
3983 //================================================================================
3985 * \brief Check curve orientation of a bootom edge
3986 * \param meshDS - mesh DS
3987 * \param columnsMap - node columns map of side face
3988 * \param bottomEdge - the bootom edge
3989 * \param sideFaceID - side face in-block ID
3990 * \retval bool - true if orientation coinside with in-block forward orientation
3992 //================================================================================
3994 bool StdMeshers_PrismAsBlock::IsForwardEdge(SMESHDS_Mesh* meshDS,
3995 const TParam2ColumnMap& columnsMap,
3996 const TopoDS_Edge & bottomEdge,
3997 const int sideFaceID)
3999 bool isForward = false;
4000 if ( SMESH_MesherHelper::IsClosedEdge( bottomEdge ))
4002 isForward = ( bottomEdge.Orientation() == TopAbs_FORWARD );
4006 const TNodeColumn& firstCol = columnsMap.begin()->second;
4007 const SMDS_MeshNode* bottomNode = firstCol[0];
4008 TopoDS_Shape firstVertex = SMESH_MesherHelper::GetSubShapeByNode( bottomNode, meshDS );
4009 isForward = ( firstVertex.IsSame( TopExp::FirstVertex( bottomEdge, true )));
4011 // on 2 of 4 sides first vertex is end
4012 if ( sideFaceID == ID_Fx1z || sideFaceID == ID_F0yz )
4013 isForward = !isForward;
4017 //=======================================================================
4018 //function : faceGridToPythonDump
4019 //purpose : Prints a script creating a normal grid on the prism side
4020 //=======================================================================
4022 void StdMeshers_PrismAsBlock::faceGridToPythonDump(const SMESH_Block::TShapeID face,
4026 gp_XYZ pOnF[6] = { gp_XYZ(0,0,0), gp_XYZ(0,0,1),
4027 gp_XYZ(0,0,0), gp_XYZ(0,1,0),
4028 gp_XYZ(0,0,0), gp_XYZ(1,0,0) };
4030 cout << "mesh = smesh.Mesh( 'Face " << face << "')" << endl;
4031 SMESH_Block::TFace& f = myFace[ face - ID_FirstF ];
4032 gp_XYZ params = pOnF[ face - ID_FirstF ];
4033 //const int nb = 10; // nb face rows
4034 for ( int j = 0; j <= nb; ++j )
4036 params.SetCoord( f.GetVInd(), double( j )/ nb );
4037 for ( int i = 0; i <= nb; ++i )
4039 params.SetCoord( f.GetUInd(), double( i )/ nb );
4040 gp_XYZ p = f.Point( params );
4041 gp_XY uv = f.GetUV( params );
4042 cout << "mesh.AddNode( " << p.X() << ", " << p.Y() << ", " << p.Z() << " )"
4043 << " # " << 1 + i + j * ( nb + 1 )
4044 << " ( " << i << ", " << j << " ) "
4045 << " UV( " << uv.X() << ", " << uv.Y() << " )" << endl;
4046 ShellPoint( params, p2 );
4047 double dist = ( p2 - p ).Modulus();
4049 cout << "#### dist from ShellPoint " << dist
4050 << " (" << p2.X() << ", " << p2.Y() << ", " << p2.Z() << " ) " << endl;
4053 for ( int j = 0; j < nb; ++j )
4054 for ( int i = 0; i < nb; ++i )
4056 int n = 1 + i + j * ( nb + 1 );
4057 cout << "mesh.AddFace([ "
4058 << n << ", " << n+1 << ", "
4059 << n+nb+2 << ", " << n+nb+1 << "]) " << endl;
4065 //================================================================================
4067 * \brief Constructor
4068 * \param faceID - in-block ID
4069 * \param face - geom FACE
4070 * \param baseEdge - EDGE proreply oriented in the bottom EDGE !!!
4071 * \param columnsMap - map of node columns
4072 * \param first - first normalized param
4073 * \param last - last normalized param
4075 //================================================================================
4077 StdMeshers_PrismAsBlock::TSideFace::TSideFace(SMESH_Mesh& mesh,
4079 const Prism_3D::TQuadList& quadList,
4080 const TopoDS_Edge& baseEdge,
4081 TParam2ColumnMap* columnsMap,
4085 myParamToColumnMap( columnsMap ),
4088 myParams.resize( 1 );
4089 myParams[ 0 ] = make_pair( first, last );
4090 mySurface = PSurface( new BRepAdaptor_Surface( quadList.front()->face ));
4091 myBaseEdge = baseEdge;
4092 myIsForward = StdMeshers_PrismAsBlock::IsForwardEdge( myHelper.GetMeshDS(),
4093 *myParamToColumnMap,
4095 myHelper.SetSubShape( quadList.front()->face );
4097 if ( quadList.size() > 1 ) // side is vertically composite
4099 // fill myShapeID2Surf map to enable finding a right surface by any sub-shape ID
4101 SMESHDS_Mesh* meshDS = myHelper.GetMeshDS();
4103 TopTools_IndexedDataMapOfShapeListOfShape subToFaces;
4104 Prism_3D::TQuadList::const_iterator quad = quadList.begin();
4105 for ( ; quad != quadList.end(); ++quad )
4107 const TopoDS_Face& face = (*quad)->face;
4108 TopExp::MapShapesAndAncestors( face, TopAbs_VERTEX, TopAbs_FACE, subToFaces );
4109 TopExp::MapShapesAndAncestors( face, TopAbs_EDGE, TopAbs_FACE, subToFaces );
4110 myShapeID2Surf.insert( make_pair( meshDS->ShapeToIndex( face ),
4111 PSurface( new BRepAdaptor_Surface( face ))));
4113 for ( int i = 1; i <= subToFaces.Extent(); ++i )
4115 const TopoDS_Shape& sub = subToFaces.FindKey( i );
4116 TopTools_ListOfShape& faces = subToFaces( i );
4117 int subID = meshDS->ShapeToIndex( sub );
4118 int faceID = meshDS->ShapeToIndex( faces.First() );
4119 myShapeID2Surf.insert ( make_pair( subID, myShapeID2Surf[ faceID ]));
4124 //================================================================================
4126 * \brief Constructor of a complex side face
4128 //================================================================================
4130 StdMeshers_PrismAsBlock::TSideFace::
4131 TSideFace(SMESH_Mesh& mesh,
4132 const vector< TSideFace* >& components,
4133 const vector< pair< double, double> > & params)
4134 :myID( components[0] ? components[0]->myID : 0 ),
4135 myParamToColumnMap( 0 ),
4137 myIsForward( true ),
4138 myComponents( components ),
4141 if ( myID == ID_Fx1z || myID == ID_F0yz )
4143 // reverse components
4144 std::reverse( myComponents.begin(), myComponents.end() );
4145 std::reverse( myParams.begin(), myParams.end() );
4146 for ( size_t i = 0; i < myParams.size(); ++i )
4148 const double f = myParams[i].first;
4149 const double l = myParams[i].second;
4150 myParams[i] = make_pair( 1. - l, 1. - f );
4154 //================================================================================
4156 * \brief Copy constructor
4157 * \param other - other side
4159 //================================================================================
4161 StdMeshers_PrismAsBlock::TSideFace::TSideFace( const TSideFace& other ):
4162 myID ( other.myID ),
4163 myParamToColumnMap ( other.myParamToColumnMap ),
4164 mySurface ( other.mySurface ),
4165 myBaseEdge ( other.myBaseEdge ),
4166 myShapeID2Surf ( other.myShapeID2Surf ),
4167 myParams ( other.myParams ),
4168 myIsForward ( other.myIsForward ),
4169 myComponents ( other.myComponents.size() ),
4170 myHelper ( *other.myHelper.GetMesh() )
4172 for ( size_t i = 0 ; i < myComponents.size(); ++i )
4173 myComponents[ i ] = new TSideFace( *other.myComponents[ i ]);
4176 //================================================================================
4178 * \brief Deletes myComponents
4180 //================================================================================
4182 StdMeshers_PrismAsBlock::TSideFace::~TSideFace()
4184 for ( size_t i = 0 ; i < myComponents.size(); ++i )
4185 if ( myComponents[ i ] )
4186 delete myComponents[ i ];
4189 //================================================================================
4191 * \brief Return geometry of the vertical curve
4192 * \param isMax - true means curve located closer to (1,1,1) block point
4193 * \retval Adaptor3d_Curve* - curve adaptor
4195 //================================================================================
4197 Adaptor3d_Curve* StdMeshers_PrismAsBlock::TSideFace::VertiCurve(const bool isMax) const
4199 if ( !myComponents.empty() ) {
4201 return myComponents.back()->VertiCurve(isMax);
4203 return myComponents.front()->VertiCurve(isMax);
4205 double f = myParams[0].first, l = myParams[0].second;
4206 if ( !myIsForward ) std::swap( f, l );
4207 return new TVerticalEdgeAdaptor( myParamToColumnMap, isMax ? l : f );
4210 //================================================================================
4212 * \brief Return geometry of the top or bottom curve
4214 * \retval Adaptor3d_Curve* -
4216 //================================================================================
4218 Adaptor3d_Curve* StdMeshers_PrismAsBlock::TSideFace::HorizCurve(const bool isTop) const
4220 return new THorizontalEdgeAdaptor( this, isTop );
4223 //================================================================================
4225 * \brief Return pcurves
4226 * \param pcurv - array of 4 pcurves
4227 * \retval bool - is a success
4229 //================================================================================
4231 bool StdMeshers_PrismAsBlock::TSideFace::GetPCurves(Adaptor2d_Curve2d* pcurv[4]) const
4233 int iEdge[ 4 ] = { BOTTOM_EDGE, TOP_EDGE, V0_EDGE, V1_EDGE };
4235 for ( int i = 0 ; i < 4 ; ++i ) {
4236 Handle(Geom2d_Line) line;
4237 switch ( iEdge[ i ] ) {
4239 line = new Geom2d_Line( gp_Pnt2d( 0, 1 ), gp::DX2d() ); break;
4241 line = new Geom2d_Line( gp::Origin2d(), gp::DX2d() ); break;
4243 line = new Geom2d_Line( gp::Origin2d(), gp::DY2d() ); break;
4245 line = new Geom2d_Line( gp_Pnt2d( 1, 0 ), gp::DY2d() ); break;
4247 pcurv[ i ] = new Geom2dAdaptor_Curve( line, 0, 1 );
4252 //================================================================================
4254 * \brief Returns geometry of pcurve on a horizontal face
4255 * \param isTop - is top or bottom face
4256 * \param horFace - a horizontal face
4257 * \retval Adaptor2d_Curve2d* - curve adaptor
4259 //================================================================================
4262 StdMeshers_PrismAsBlock::TSideFace::HorizPCurve(const bool isTop,
4263 const TopoDS_Face& horFace) const
4265 return new TPCurveOnHorFaceAdaptor( this, isTop, horFace );
4268 //================================================================================
4270 * \brief Return a component corresponding to parameter
4271 * \param U - parameter along a horizontal size
4272 * \param localU - parameter along a horizontal size of a component
4273 * \retval TSideFace* - found component
4275 //================================================================================
4277 StdMeshers_PrismAsBlock::TSideFace*
4278 StdMeshers_PrismAsBlock::TSideFace::GetComponent(const double U,double & localU) const
4281 if ( myComponents.empty() )
4282 return const_cast<TSideFace*>( this );
4285 for ( i = 0; i < myComponents.size(); ++i )
4286 if ( U < myParams[ i ].second )
4288 if ( i >= myComponents.size() )
4289 i = myComponents.size() - 1;
4291 double f = myParams[ i ].first, l = myParams[ i ].second;
4292 localU = ( U - f ) / ( l - f );
4293 return myComponents[ i ];
4296 //================================================================================
4298 * \brief Find node columns for a parameter
4299 * \param U - parameter along a horizontal edge
4300 * \param col1 - the 1st found column
4301 * \param col2 - the 2nd found column
4302 * \retval r - normalized position of U between the found columns
4304 //================================================================================
4306 double StdMeshers_PrismAsBlock::TSideFace::GetColumns(const double U,
4307 TParam2ColumnIt & col1,
4308 TParam2ColumnIt & col2) const
4310 double u = U, r = 0;
4311 if ( !myComponents.empty() ) {
4312 TSideFace * comp = GetComponent(U,u);
4313 return comp->GetColumns( u, col1, col2 );
4318 double f = myParams[0].first, l = myParams[0].second;
4319 u = f + u * ( l - f );
4321 col1 = col2 = getColumn( myParamToColumnMap, u );
4322 if ( ++col2 == myParamToColumnMap->end() ) {
4327 double uf = col1->first;
4328 double ul = col2->first;
4329 r = ( u - uf ) / ( ul - uf );
4334 //================================================================================
4336 * \brief Return all nodes at a given height together with their normalized parameters
4337 * \param [in] Z - the height of interest
4338 * \param [out] nodes - map of parameter to node
4340 //================================================================================
4342 void StdMeshers_PrismAsBlock::
4343 TSideFace::GetNodesAtZ(const int Z,
4344 map<double, const SMDS_MeshNode* >& nodes ) const
4346 if ( !myComponents.empty() )
4349 for ( size_t i = 0; i < myComponents.size(); ++i )
4351 map<double, const SMDS_MeshNode* > nn;
4352 myComponents[i]->GetNodesAtZ( Z, nn );
4353 map<double, const SMDS_MeshNode* >::iterator u2n = nn.begin();
4354 if ( !nodes.empty() && nodes.rbegin()->second == u2n->second )
4356 const double uRange = myParams[i].second - myParams[i].first;
4357 for ( ; u2n != nn.end(); ++u2n )
4358 nodes.insert( nodes.end(), make_pair( u0 + uRange * u2n->first, u2n->second ));
4364 double f = myParams[0].first, l = myParams[0].second;
4367 const double uRange = l - f;
4368 if ( Abs( uRange ) < std::numeric_limits<double>::min() )
4370 TParam2ColumnIt u2col = getColumn( myParamToColumnMap, myParams[0].first + 1e-3 );
4371 for ( ; u2col != myParamToColumnMap->end(); ++u2col )
4372 if ( u2col->first > myParams[0].second + 1e-9 )
4375 nodes.insert( nodes.end(),
4376 make_pair( ( u2col->first - f ) / uRange, u2col->second[ Z ] ));
4380 //================================================================================
4382 * \brief Return coordinates by normalized params
4383 * \param U - horizontal param
4384 * \param V - vertical param
4385 * \retval gp_Pnt - result point
4387 //================================================================================
4389 gp_Pnt StdMeshers_PrismAsBlock::TSideFace::Value(const Standard_Real U,
4390 const Standard_Real V) const
4392 if ( !myComponents.empty() ) {
4394 TSideFace * comp = GetComponent(U,u);
4395 return comp->Value( u, V );
4398 TParam2ColumnIt u_col1, u_col2;
4399 double vR, hR = GetColumns( U, u_col1, u_col2 );
4401 const SMDS_MeshNode* nn[4];
4403 // BEGIN issue 0020680: Bad cell created by Radial prism in center of torus
4404 // Workaround for a wrongly located point returned by mySurface.Value() for
4405 // UV located near boundary of BSpline surface.
4406 // To bypass the problem, we take point from 3D curve of EDGE.
4407 // It solves pb of the bloc_fiss_new.py
4408 const double tol = 1e-3;
4409 if ( V < tol || V+tol >= 1. )
4411 nn[0] = V < tol ? u_col1->second.front() : u_col1->second.back();
4412 nn[2] = V < tol ? u_col2->second.front() : u_col2->second.back();
4420 TopoDS_Shape s = myHelper.GetSubShapeByNode( nn[0], myHelper.GetMeshDS() );
4421 if ( s.ShapeType() != TopAbs_EDGE )
4422 s = myHelper.GetSubShapeByNode( nn[2], myHelper.GetMeshDS() );
4423 if ( !s.IsNull() && s.ShapeType() == TopAbs_EDGE )
4424 edge = TopoDS::Edge( s );
4426 if ( !edge.IsNull() )
4428 double u1 = myHelper.GetNodeU( edge, nn[0], nn[2] );
4429 double u3 = myHelper.GetNodeU( edge, nn[2], nn[0] );
4430 double u = u1 * ( 1 - hR ) + u3 * hR;
4431 TopLoc_Location loc; double f,l;
4432 Handle(Geom_Curve) curve = BRep_Tool::Curve( edge,loc,f,l );
4433 return curve->Value( u ).Transformed( loc );
4436 // END issue 0020680: Bad cell created by Radial prism in center of torus
4438 vR = getRAndNodes( & u_col1->second, V, nn[0], nn[1] );
4439 vR = getRAndNodes( & u_col2->second, V, nn[2], nn[3] );
4441 if ( !myShapeID2Surf.empty() ) // side is vertically composite
4443 // find a FACE on which the 4 nodes lie
4444 TSideFace* me = (TSideFace*) this;
4445 int notFaceID1 = 0, notFaceID2 = 0;
4446 for ( int i = 0; i < 4; ++i )
4447 if ( nn[i]->GetPosition()->GetTypeOfPosition() == SMDS_TOP_FACE ) // node on FACE
4449 me->mySurface = me->myShapeID2Surf[ nn[i]->getshapeId() ];
4453 else if ( notFaceID1 == 0 ) // node on EDGE or VERTEX
4455 me->mySurface = me->myShapeID2Surf[ nn[i]->getshapeId() ];
4456 notFaceID1 = nn[i]->getshapeId();
4458 else if ( notFaceID1 != nn[i]->getshapeId() ) // node on other EDGE or VERTEX
4460 if ( mySurface != me->myShapeID2Surf[ nn[i]->getshapeId() ])
4461 notFaceID2 = nn[i]->getshapeId();
4463 if ( notFaceID2 ) // no nodes of FACE and nodes are on different FACEs
4465 SMESHDS_Mesh* meshDS = myHelper.GetMeshDS();
4466 TopoDS_Shape face = myHelper.GetCommonAncestor( meshDS->IndexToShape( notFaceID1 ),
4467 meshDS->IndexToShape( notFaceID2 ),
4468 *myHelper.GetMesh(),
4470 if ( face.IsNull() )
4471 throw SALOME_Exception("StdMeshers_PrismAsBlock::TSideFace::Value() face.IsNull()");
4472 int faceID = meshDS->ShapeToIndex( face );
4473 me->mySurface = me->myShapeID2Surf[ faceID ];
4475 throw SALOME_Exception("StdMeshers_PrismAsBlock::TSideFace::Value() !mySurface");
4478 ((TSideFace*) this)->myHelper.SetSubShape( mySurface->Face() );
4480 gp_XY uv1 = myHelper.GetNodeUV( mySurface->Face(), nn[0], nn[2]);
4481 gp_XY uv2 = myHelper.GetNodeUV( mySurface->Face(), nn[1], nn[3]);
4482 gp_XY uv12 = uv1 * ( 1 - vR ) + uv2 * vR;
4484 gp_XY uv3 = myHelper.GetNodeUV( mySurface->Face(), nn[2], nn[0]);
4485 gp_XY uv4 = myHelper.GetNodeUV( mySurface->Face(), nn[3], nn[1]);
4486 gp_XY uv34 = uv3 * ( 1 - vR ) + uv4 * vR;
4488 gp_XY uv = uv12 * ( 1 - hR ) + uv34 * hR;
4490 gp_Pnt p = mySurface->Value( uv.X(), uv.Y() );
4495 //================================================================================
4497 * \brief Return boundary edge
4498 * \param edge - edge index
4499 * \retval TopoDS_Edge - found edge
4501 //================================================================================
4503 TopoDS_Edge StdMeshers_PrismAsBlock::TSideFace::GetEdge(const int iEdge) const
4505 if ( !myComponents.empty() ) {
4507 case V0_EDGE : return myComponents.front()->GetEdge( iEdge );
4508 case V1_EDGE : return myComponents.back() ->GetEdge( iEdge );
4509 default: return TopoDS_Edge();
4513 const SMDS_MeshNode* node = 0;
4514 SMESHDS_Mesh * meshDS = myHelper.GetMesh()->GetMeshDS();
4515 TNodeColumn* column;
4520 column = & (( ++myParamToColumnMap->begin())->second );
4521 node = ( iEdge == TOP_EDGE ) ? column->back() : column->front();
4522 edge = myHelper.GetSubShapeByNode ( node, meshDS );
4523 if ( edge.ShapeType() == TopAbs_VERTEX ) {
4524 column = & ( myParamToColumnMap->begin()->second );
4525 node = ( iEdge == TOP_EDGE ) ? column->back() : column->front();
4530 bool back = ( iEdge == V1_EDGE );
4531 if ( !myIsForward ) back = !back;
4533 column = & ( myParamToColumnMap->rbegin()->second );
4535 column = & ( myParamToColumnMap->begin()->second );
4536 if ( column->size() > 0 )
4537 edge = myHelper.GetSubShapeByNode( (*column)[ 1 ], meshDS );
4538 if ( edge.IsNull() || edge.ShapeType() == TopAbs_VERTEX )
4539 node = column->front();
4544 if ( !edge.IsNull() && edge.ShapeType() == TopAbs_EDGE )
4545 return TopoDS::Edge( edge );
4547 // find edge by 2 vertices
4548 TopoDS_Shape V1 = edge;
4549 TopoDS_Shape V2 = myHelper.GetSubShapeByNode( node, meshDS );
4550 if ( !V2.IsNull() && V2.ShapeType() == TopAbs_VERTEX && !V2.IsSame( V1 ))
4552 TopoDS_Shape ancestor = myHelper.GetCommonAncestor( V1, V2, *myHelper.GetMesh(), TopAbs_EDGE);
4553 if ( !ancestor.IsNull() )
4554 return TopoDS::Edge( ancestor );
4556 return TopoDS_Edge();
4559 //================================================================================
4561 * \brief Fill block sub-shapes
4562 * \param shapeMap - map to fill in
4563 * \retval int - nb inserted sub-shapes
4565 //================================================================================
4567 int StdMeshers_PrismAsBlock::TSideFace::InsertSubShapes(TBlockShapes& shapeMap) const
4572 vector< int > edgeIdVec;
4573 SMESH_Block::GetFaceEdgesIDs( myID, edgeIdVec );
4575 for ( int i = BOTTOM_EDGE; i <=V1_EDGE ; ++i ) {
4576 TopoDS_Edge e = GetEdge( i );
4577 if ( !e.IsNull() ) {
4578 nbInserted += SMESH_Block::Insert( e, edgeIdVec[ i ], shapeMap);
4582 // Insert corner vertices
4584 TParam2ColumnIt col1, col2 ;
4585 vector< int > vertIdVec;
4588 SMESH_Block::GetEdgeVertexIDs( edgeIdVec[ V0_EDGE ], vertIdVec);
4589 GetColumns(0, col1, col2 );
4590 const SMDS_MeshNode* node0 = col1->second.front();
4591 const SMDS_MeshNode* node1 = col1->second.back();
4592 TopoDS_Shape v0 = myHelper.GetSubShapeByNode( node0, myHelper.GetMeshDS());
4593 TopoDS_Shape v1 = myHelper.GetSubShapeByNode( node1, myHelper.GetMeshDS());
4594 if ( v0.ShapeType() == TopAbs_VERTEX ) {
4595 nbInserted += SMESH_Block::Insert( v0, vertIdVec[ 0 ], shapeMap);
4597 if ( v1.ShapeType() == TopAbs_VERTEX ) {
4598 nbInserted += SMESH_Block::Insert( v1, vertIdVec[ 1 ], shapeMap);
4602 SMESH_Block::GetEdgeVertexIDs( edgeIdVec[ V1_EDGE ], vertIdVec);
4603 GetColumns(1, col1, col2 );
4604 node0 = col2->second.front();
4605 node1 = col2->second.back();
4606 v0 = myHelper.GetSubShapeByNode( node0, myHelper.GetMeshDS());
4607 v1 = myHelper.GetSubShapeByNode( node1, myHelper.GetMeshDS());
4608 if ( v0.ShapeType() == TopAbs_VERTEX ) {
4609 nbInserted += SMESH_Block::Insert( v0, vertIdVec[ 0 ], shapeMap);
4611 if ( v1.ShapeType() == TopAbs_VERTEX ) {
4612 nbInserted += SMESH_Block::Insert( v1, vertIdVec[ 1 ], shapeMap);
4615 // TopoDS_Vertex V0, V1, Vcom;
4616 // TopExp::Vertices( myBaseEdge, V0, V1, true );
4617 // if ( !myIsForward ) std::swap( V0, V1 );
4619 // // bottom vertex IDs
4620 // SMESH_Block::GetEdgeVertexIDs( edgeIdVec[ _u0 ], vertIdVec);
4621 // SMESH_Block::Insert( V0, vertIdVec[ 0 ], shapeMap);
4622 // SMESH_Block::Insert( V1, vertIdVec[ 1 ], shapeMap);
4624 // TopoDS_Edge sideEdge = GetEdge( V0_EDGE );
4625 // if ( sideEdge.IsNull() || !TopExp::CommonVertex( botEdge, sideEdge, Vcom ))
4628 // // insert one side edge
4630 // if ( Vcom.IsSame( V0 )) edgeID = edgeIdVec[ _v0 ];
4631 // else edgeID = edgeIdVec[ _v1 ];
4632 // SMESH_Block::Insert( sideEdge, edgeID, shapeMap);
4634 // // top vertex of the side edge
4635 // SMESH_Block::GetEdgeVertexIDs( edgeID, vertIdVec);
4636 // TopoDS_Vertex Vtop = TopExp::FirstVertex( sideEdge );
4637 // if ( Vcom.IsSame( Vtop ))
4638 // Vtop = TopExp::LastVertex( sideEdge );
4639 // SMESH_Block::Insert( Vtop, vertIdVec[ 1 ], shapeMap);
4641 // // other side edge
4642 // sideEdge = GetEdge( V1_EDGE );
4643 // if ( sideEdge.IsNull() )
4645 // if ( edgeID = edgeIdVec[ _v1 ]) edgeID = edgeIdVec[ _v0 ];
4646 // else edgeID = edgeIdVec[ _v1 ];
4647 // SMESH_Block::Insert( sideEdge, edgeID, shapeMap);
4650 // TopoDS_Edge topEdge = GetEdge( TOP_EDGE );
4651 // SMESH_Block::Insert( topEdge, edgeIdVec[ _u1 ], shapeMap);
4653 // // top vertex of the other side edge
4654 // if ( !TopExp::CommonVertex( topEdge, sideEdge, Vcom ))
4656 // SMESH_Block::GetEdgeVertexIDs( edgeID, vertIdVec );
4657 // SMESH_Block::Insert( Vcom, vertIdVec[ 1 ], shapeMap);
4662 //================================================================================
4664 * \brief Dump ids of nodes of sides
4666 //================================================================================
4668 void StdMeshers_PrismAsBlock::TSideFace::dumpNodes(int nbNodes) const
4671 cout << endl << "NODES OF FACE "; SMESH_Block::DumpShapeID( myID, cout ) << endl;
4672 THorizontalEdgeAdaptor* hSize0 = (THorizontalEdgeAdaptor*) HorizCurve(0);
4673 cout << "Horiz side 0: "; hSize0->dumpNodes(nbNodes); cout << endl;
4674 THorizontalEdgeAdaptor* hSize1 = (THorizontalEdgeAdaptor*) HorizCurve(1);
4675 cout << "Horiz side 1: "; hSize1->dumpNodes(nbNodes); cout << endl;
4676 TVerticalEdgeAdaptor* vSide0 = (TVerticalEdgeAdaptor*) VertiCurve(0);
4677 cout << "Verti side 0: "; vSide0->dumpNodes(nbNodes); cout << endl;
4678 TVerticalEdgeAdaptor* vSide1 = (TVerticalEdgeAdaptor*) VertiCurve(1);
4679 cout << "Verti side 1: "; vSide1->dumpNodes(nbNodes); cout << endl;
4680 delete hSize0; delete hSize1; delete vSide0; delete vSide1;
4684 //================================================================================
4686 * \brief Creates TVerticalEdgeAdaptor
4687 * \param columnsMap - node column map
4688 * \param parameter - normalized parameter
4690 //================================================================================
4692 StdMeshers_PrismAsBlock::TVerticalEdgeAdaptor::
4693 TVerticalEdgeAdaptor( const TParam2ColumnMap* columnsMap, const double parameter)
4695 myNodeColumn = & getColumn( columnsMap, parameter )->second;
4698 //================================================================================
4700 * \brief Return coordinates for the given normalized parameter
4701 * \param U - normalized parameter
4702 * \retval gp_Pnt - coordinates
4704 //================================================================================
4706 gp_Pnt StdMeshers_PrismAsBlock::TVerticalEdgeAdaptor::Value(const Standard_Real U) const
4708 const SMDS_MeshNode* n1;
4709 const SMDS_MeshNode* n2;
4710 double r = getRAndNodes( myNodeColumn, U, n1, n2 );
4711 return gpXYZ(n1) * ( 1 - r ) + gpXYZ(n2) * r;
4714 //================================================================================
4716 * \brief Dump ids of nodes
4718 //================================================================================
4720 void StdMeshers_PrismAsBlock::TVerticalEdgeAdaptor::dumpNodes(int nbNodes) const
4723 for ( int i = 0; i < nbNodes && i < (int)myNodeColumn->size(); ++i )
4724 cout << (*myNodeColumn)[i]->GetID() << " ";
4725 if ( nbNodes < (int) myNodeColumn->size() )
4726 cout << myNodeColumn->back()->GetID();
4730 //================================================================================
4732 * \brief Return coordinates for the given normalized parameter
4733 * \param U - normalized parameter
4734 * \retval gp_Pnt - coordinates
4736 //================================================================================
4738 gp_Pnt StdMeshers_PrismAsBlock::THorizontalEdgeAdaptor::Value(const Standard_Real U) const
4740 return mySide->TSideFace::Value( U, myV );
4743 //================================================================================
4745 * \brief Dump ids of <nbNodes> first nodes and the last one
4747 //================================================================================
4749 void StdMeshers_PrismAsBlock::THorizontalEdgeAdaptor::dumpNodes(int nbNodes) const
4752 // Not bedugged code. Last node is sometimes incorrect
4753 const TSideFace* side = mySide;
4755 if ( mySide->IsComplex() )
4756 side = mySide->GetComponent(0,u);
4758 TParam2ColumnIt col, col2;
4759 TParam2ColumnMap* u2cols = side->GetColumns();
4760 side->GetColumns( u , col, col2 );
4762 int j, i = myV ? mySide->ColumnHeight()-1 : 0;
4764 const SMDS_MeshNode* n = 0;
4765 const SMDS_MeshNode* lastN
4766 = side->IsForward() ? u2cols->rbegin()->second[ i ] : u2cols->begin()->second[ i ];
4767 for ( j = 0; j < nbNodes && n != lastN; ++j )
4769 n = col->second[ i ];
4770 cout << n->GetID() << " ";
4771 if ( side->IsForward() )
4779 if ( mySide->IsComplex() )
4780 side = mySide->GetComponent(1,u);
4782 side->GetColumns( u , col, col2 );
4783 if ( n != col->second[ i ] )
4784 cout << col->second[ i ]->GetID();
4788 //================================================================================
4790 * \brief Costructor of TPCurveOnHorFaceAdaptor fills its map of
4791 * normalized parameter to node UV on a horizontal face
4792 * \param [in] sideFace - lateral prism side
4793 * \param [in] isTop - is \a horFace top or bottom of the prism
4794 * \param [in] horFace - top or bottom face of the prism
4796 //================================================================================
4798 StdMeshers_PrismAsBlock::
4799 TPCurveOnHorFaceAdaptor::TPCurveOnHorFaceAdaptor( const TSideFace* sideFace,
4801 const TopoDS_Face& horFace)
4803 if ( sideFace && !horFace.IsNull() )
4805 //cout << "\n\t FACE " << sideFace->FaceID() << endl;
4806 const int Z = isTop ? sideFace->ColumnHeight() - 1 : 0;
4807 map<double, const SMDS_MeshNode* > u2nodes;
4808 sideFace->GetNodesAtZ( Z, u2nodes );
4809 if ( u2nodes.empty() )
4812 SMESH_MesherHelper helper( *sideFace->GetMesh() );
4813 helper.SetSubShape( horFace );
4818 Handle(Geom2d_Curve) C2d;
4820 const double tol = 10 * helper.MaxTolerance( horFace );
4821 const SMDS_MeshNode* prevNode = u2nodes.rbegin()->second;
4823 map<double, const SMDS_MeshNode* >::iterator u2n = u2nodes.begin();
4824 for ( ; u2n != u2nodes.end(); ++u2n )
4826 const SMDS_MeshNode* n = u2n->second;
4828 if ( n->GetPosition()->GetTypeOfPosition() == SMDS_TOP_EDGE )
4830 if ( n->getshapeId() != edgeID )
4833 edgeID = n->getshapeId();
4834 TopoDS_Shape S = helper.GetSubShapeByNode( n, helper.GetMeshDS() );
4835 if ( !S.IsNull() && S.ShapeType() == TopAbs_EDGE )
4837 C2d = BRep_Tool::CurveOnSurface( TopoDS::Edge( S ), horFace, f,l );
4840 if ( !C2d.IsNull() )
4842 double u = static_cast< const SMDS_EdgePosition* >( n->GetPosition() )->GetUParameter();
4843 if ( f <= u && u <= l )
4845 uv = C2d->Value( u ).XY();
4846 okUV = helper.CheckNodeUV( horFace, n, uv, tol );
4851 uv = helper.GetNodeUV( horFace, n, prevNode, &okUV );
4853 myUVmap.insert( myUVmap.end(), make_pair( u2n->first, uv ));
4854 // cout << n->getshapeId() << " N " << n->GetID()
4855 // << " \t" << uv.X() << ", " << uv.Y() << " \t" << u2n->first << endl;
4862 //================================================================================
4864 * \brief Return UV on pcurve for the given normalized parameter
4865 * \param U - normalized parameter
4866 * \retval gp_Pnt - coordinates
4868 //================================================================================
4870 gp_Pnt2d StdMeshers_PrismAsBlock::TPCurveOnHorFaceAdaptor::Value(const Standard_Real U) const
4872 map< double, gp_XY >::const_iterator i1 = myUVmap.upper_bound( U );
4874 if ( i1 == myUVmap.end() )
4875 return myUVmap.empty() ? gp_XY(0,0) : myUVmap.rbegin()->second;
4877 if ( i1 == myUVmap.begin() )
4878 return (*i1).second;
4880 map< double, gp_XY >::const_iterator i2 = i1--;
4882 double r = ( U - i1->first ) / ( i2->first - i1->first );
4883 return i1->second * ( 1 - r ) + i2->second * r;
4886 //================================================================================
4888 * \brief Projects internal nodes using transformation found by boundary nodes
4890 //================================================================================
4892 bool StdMeshers_Sweeper::projectIntPoints(const vector< gp_XYZ >& fromBndPoints,
4893 const vector< gp_XYZ >& toBndPoints,
4894 const vector< gp_XYZ >& fromIntPoints,
4895 vector< gp_XYZ >& toIntPoints,
4896 NSProjUtils::TrsfFinder3D& trsf,
4897 vector< gp_XYZ > * bndError)
4899 // find transformation
4900 if ( trsf.IsIdentity() && !trsf.Solve( fromBndPoints, toBndPoints ))
4903 // compute internal points using the found trsf
4904 for ( size_t iP = 0; iP < fromIntPoints.size(); ++iP )
4906 toIntPoints[ iP ] = trsf.Transform( fromIntPoints[ iP ]);
4909 // compute boundary error
4912 bndError->resize( fromBndPoints.size() );
4914 for ( size_t iP = 0; iP < fromBndPoints.size(); ++iP )
4916 fromTrsf = trsf.Transform( fromBndPoints[ iP ] );
4917 (*bndError)[ iP ] = toBndPoints[ iP ] - fromTrsf;
4923 //================================================================================
4925 * \brief Add boundary error to ineternal points
4927 //================================================================================
4929 void StdMeshers_Sweeper::applyBoundaryError(const vector< gp_XYZ >& bndPoints,
4930 const vector< gp_XYZ >& bndError1,
4931 const vector< gp_XYZ >& bndError2,
4933 vector< gp_XYZ >& intPoints,
4934 vector< double >& int2BndDist)
4936 // fix each internal point
4937 const double eps = 1e-100;
4938 for ( size_t iP = 0; iP < intPoints.size(); ++iP )
4940 gp_XYZ & intPnt = intPoints[ iP ];
4942 // compute distance from intPnt to each boundary node
4943 double int2BndDistSum = 0;
4944 for ( size_t iBnd = 0; iBnd < bndPoints.size(); ++iBnd )
4946 int2BndDist[ iBnd ] = 1 / (( intPnt - bndPoints[ iBnd ]).SquareModulus() + eps );
4947 int2BndDistSum += int2BndDist[ iBnd ];
4951 for ( size_t iBnd = 0; iBnd < bndPoints.size(); ++iBnd )
4953 intPnt += bndError1[ iBnd ] * ( 1 - r ) * int2BndDist[ iBnd ] / int2BndDistSum;
4954 intPnt += bndError2[ iBnd ] * r * int2BndDist[ iBnd ] / int2BndDistSum;
4959 //================================================================================
4961 * \brief Create internal nodes of the prism by computing an affine transformation
4962 * from layer to layer
4964 //================================================================================
4966 bool StdMeshers_Sweeper::ComputeNodesByTrsf( const double tol,
4967 const bool allowHighBndError)
4969 const size_t zSize = myBndColumns[0]->size();
4970 const size_t zSrc = 0, zTgt = zSize-1;
4971 if ( zSize < 3 ) return true;
4973 vector< vector< gp_XYZ > > intPntsOfLayer( zSize ); // node coodinates to compute
4974 // set coordinates of src and tgt nodes
4975 for ( size_t z = 0; z < intPntsOfLayer.size(); ++z )
4976 intPntsOfLayer[ z ].resize( myIntColumns.size() );
4977 for ( size_t iP = 0; iP < myIntColumns.size(); ++iP )
4979 intPntsOfLayer[ zSrc ][ iP ] = intPoint( iP, zSrc );
4980 intPntsOfLayer[ zTgt ][ iP ] = intPoint( iP, zTgt );
4983 // compute coordinates of internal nodes by projecting (transfroming) src and tgt
4984 // nodes towards the central layer
4986 vector< NSProjUtils::TrsfFinder3D > trsfOfLayer( zSize );
4987 vector< vector< gp_XYZ > > bndError( zSize );
4989 // boundary points used to compute an affine transformation from a layer to a next one
4990 vector< gp_XYZ > fromSrcBndPnts( myBndColumns.size() ), fromTgtBndPnts( myBndColumns.size() );
4991 vector< gp_XYZ > toSrcBndPnts ( myBndColumns.size() ), toTgtBndPnts ( myBndColumns.size() );
4992 for ( size_t iP = 0; iP < myBndColumns.size(); ++iP )
4994 fromSrcBndPnts[ iP ] = bndPoint( iP, zSrc );
4995 fromTgtBndPnts[ iP ] = bndPoint( iP, zTgt );
4998 size_t zS = zSrc + 1;
4999 size_t zT = zTgt - 1;
5000 for ( ; zS < zT; ++zS, --zT ) // vertical loop on layers
5002 for ( size_t iP = 0; iP < myBndColumns.size(); ++iP )
5004 toSrcBndPnts[ iP ] = bndPoint( iP, zS );
5005 toTgtBndPnts[ iP ] = bndPoint( iP, zT );
5007 if (! projectIntPoints( fromSrcBndPnts, toSrcBndPnts,
5008 intPntsOfLayer[ zS-1 ], intPntsOfLayer[ zS ],
5009 trsfOfLayer [ zS-1 ], & bndError[ zS-1 ]))
5011 if (! projectIntPoints( fromTgtBndPnts, toTgtBndPnts,
5012 intPntsOfLayer[ zT+1 ], intPntsOfLayer[ zT ],
5013 trsfOfLayer [ zT+1 ], & bndError[ zT+1 ]))
5016 // if ( zT == zTgt - 1 )
5018 // for ( size_t iP = 0; iP < myBndColumns.size(); ++iP )
5020 // gp_XYZ fromTrsf = trsfOfLayer [ zT+1].Transform( fromTgtBndPnts[ iP ] );
5021 // cout << "mesh.AddNode( "
5022 // << fromTrsf.X() << ", "
5023 // << fromTrsf.Y() << ", "
5024 // << fromTrsf.Z() << ") " << endl;
5026 // for ( size_t iP = 0; iP < myIntColumns.size(); ++iP )
5027 // cout << "mesh.AddNode( "
5028 // << intPntsOfLayer[ zT ][ iP ].X() << ", "
5029 // << intPntsOfLayer[ zT ][ iP ].Y() << ", "
5030 // << intPntsOfLayer[ zT ][ iP ].Z() << ") " << endl;
5033 fromTgtBndPnts.swap( toTgtBndPnts );
5034 fromSrcBndPnts.swap( toSrcBndPnts );
5037 // Compute two projections of internal points to the central layer
5038 // in order to evaluate an error of internal points
5040 bool centerIntErrorIsSmall;
5041 vector< gp_XYZ > centerSrcIntPnts( myIntColumns.size() );
5042 vector< gp_XYZ > centerTgtIntPnts( myIntColumns.size() );
5044 for ( size_t iP = 0; iP < myBndColumns.size(); ++iP )
5046 toSrcBndPnts[ iP ] = bndPoint( iP, zS );
5047 toTgtBndPnts[ iP ] = bndPoint( iP, zT );
5049 if (! projectIntPoints( fromSrcBndPnts, toSrcBndPnts,
5050 intPntsOfLayer[ zS-1 ], centerSrcIntPnts,
5051 trsfOfLayer [ zS-1 ], & bndError[ zS-1 ]))
5053 if (! projectIntPoints( fromTgtBndPnts, toTgtBndPnts,
5054 intPntsOfLayer[ zT+1 ], centerTgtIntPnts,
5055 trsfOfLayer [ zT+1 ], & bndError[ zT+1 ]))
5058 // evaluate an error of internal points on the central layer
5059 centerIntErrorIsSmall = true;
5060 if ( zS == zT ) // odd zSize
5062 for ( size_t iP = 0; ( iP < myIntColumns.size() && centerIntErrorIsSmall ); ++iP )
5063 centerIntErrorIsSmall =
5064 (centerSrcIntPnts[ iP ] - centerTgtIntPnts[ iP ]).SquareModulus() < tol*tol;
5068 for ( size_t iP = 0; ( iP < myIntColumns.size() && centerIntErrorIsSmall ); ++iP )
5069 centerIntErrorIsSmall =
5070 (intPntsOfLayer[ zS-1 ][ iP ] - centerTgtIntPnts[ iP ]).SquareModulus() < tol*tol;
5073 // Evaluate an error of boundary points
5075 bool bndErrorIsSmall = true;
5076 for ( size_t iP = 0; ( iP < myBndColumns.size() && bndErrorIsSmall ); ++iP )
5078 double sumError = 0;
5079 for ( size_t z = 1; z < zS; ++z ) // loop on layers
5080 sumError += ( bndError[ z-1 ][ iP ].Modulus() +
5081 bndError[ zSize-z ][ iP ].Modulus() );
5083 bndErrorIsSmall = ( sumError < tol );
5086 if ( !bndErrorIsSmall && !allowHighBndError )
5089 // compute final points on the central layer
5090 std::vector< double > int2BndDist( myBndColumns.size() ); // work array of applyBoundaryError()
5091 double r = zS / ( zSize - 1.);
5094 for ( size_t iP = 0; iP < myIntColumns.size(); ++iP )
5096 intPntsOfLayer[ zS ][ iP ] =
5097 ( 1 - r ) * centerSrcIntPnts[ iP ] + r * centerTgtIntPnts[ iP ];
5099 if ( !bndErrorIsSmall )
5101 applyBoundaryError( toSrcBndPnts, bndError[ zS-1 ], bndError[ zS+1 ], r,
5102 intPntsOfLayer[ zS ], int2BndDist );
5107 for ( size_t iP = 0; iP < myIntColumns.size(); ++iP )
5109 intPntsOfLayer[ zS ][ iP ] =
5110 r * intPntsOfLayer[ zS ][ iP ] + ( 1 - r ) * centerSrcIntPnts[ iP ];
5111 intPntsOfLayer[ zT ][ iP ] =
5112 r * intPntsOfLayer[ zT ][ iP ] + ( 1 - r ) * centerTgtIntPnts[ iP ];
5114 if ( !bndErrorIsSmall )
5116 applyBoundaryError( toSrcBndPnts, bndError[ zS-1 ], bndError[ zS+1 ], r,
5117 intPntsOfLayer[ zS ], int2BndDist );
5118 applyBoundaryError( toTgtBndPnts, bndError[ zT+1 ], bndError[ zT-1 ], r,
5119 intPntsOfLayer[ zT ], int2BndDist );
5123 centerIntErrorIsSmall = true; // 3D_mesh_Extrusion_00/A3
5124 bndErrorIsSmall = true;
5125 if ( !centerIntErrorIsSmall )
5127 // Compensate the central error; continue adding projection
5128 // by going from central layer to the source and target ones
5130 vector< gp_XYZ >& fromSrcIntPnts = centerSrcIntPnts;
5131 vector< gp_XYZ >& fromTgtIntPnts = centerTgtIntPnts;
5132 vector< gp_XYZ > toSrcIntPnts( myIntColumns.size() );
5133 vector< gp_XYZ > toTgtIntPnts( myIntColumns.size() );
5134 vector< gp_XYZ > srcBndError( myBndColumns.size() );
5135 vector< gp_XYZ > tgtBndError( myBndColumns.size() );
5137 fromTgtBndPnts.swap( toTgtBndPnts );
5138 fromSrcBndPnts.swap( toSrcBndPnts );
5140 for ( ++zS, --zT; zS < zTgt; ++zS, --zT ) // vertical loop on layers
5142 // invert transformation
5143 if ( !trsfOfLayer[ zS+1 ].Invert() )
5144 trsfOfLayer[ zS+1 ] = NSProjUtils::TrsfFinder3D(); // to recompute
5145 if ( !trsfOfLayer[ zT-1 ].Invert() )
5146 trsfOfLayer[ zT-1 ] = NSProjUtils::TrsfFinder3D();
5148 // project internal nodes and compute bnd error
5149 for ( size_t iP = 0; iP < myBndColumns.size(); ++iP )
5151 toSrcBndPnts[ iP ] = bndPoint( iP, zS );
5152 toTgtBndPnts[ iP ] = bndPoint( iP, zT );
5154 projectIntPoints( fromSrcBndPnts, toSrcBndPnts,
5155 fromSrcIntPnts, toSrcIntPnts,
5156 trsfOfLayer[ zS+1 ], & srcBndError );
5157 projectIntPoints( fromTgtBndPnts, toTgtBndPnts,
5158 fromTgtIntPnts, toTgtIntPnts,
5159 trsfOfLayer[ zT-1 ], & tgtBndError );
5161 // if ( zS == zTgt - 1 )
5163 // cout << "mesh2 = smesh.Mesh()" << endl;
5164 // for ( size_t iP = 0; iP < myBndColumns.size(); ++iP )
5166 // gp_XYZ fromTrsf = trsfOfLayer [ zS+1].Transform( fromSrcBndPnts[ iP ] );
5167 // cout << "mesh2.AddNode( "
5168 // << fromTrsf.X() << ", "
5169 // << fromTrsf.Y() << ", "
5170 // << fromTrsf.Z() << ") " << endl;
5172 // for ( size_t iP = 0; iP < myIntColumns.size(); ++iP )
5173 // cout << "mesh2.AddNode( "
5174 // << toSrcIntPnts[ iP ].X() << ", "
5175 // << toSrcIntPnts[ iP ].Y() << ", "
5176 // << toSrcIntPnts[ iP ].Z() << ") " << endl;
5179 // sum up 2 projections
5180 r = zS / ( zSize - 1.);
5181 vector< gp_XYZ >& zSIntPnts = intPntsOfLayer[ zS ];
5182 vector< gp_XYZ >& zTIntPnts = intPntsOfLayer[ zT ];
5183 for ( size_t iP = 0; iP < myIntColumns.size(); ++iP )
5185 zSIntPnts[ iP ] = r * zSIntPnts[ iP ] + ( 1 - r ) * toSrcIntPnts[ iP ];
5186 zTIntPnts[ iP ] = r * zTIntPnts[ iP ] + ( 1 - r ) * toTgtIntPnts[ iP ];
5189 // compensate bnd error
5190 if ( !bndErrorIsSmall )
5192 applyBoundaryError( toSrcBndPnts, srcBndError, bndError[ zS+1 ], r,
5193 intPntsOfLayer[ zS ], int2BndDist );
5194 applyBoundaryError( toTgtBndPnts, tgtBndError, bndError[ zT-1 ], r,
5195 intPntsOfLayer[ zT ], int2BndDist );
5198 fromSrcBndPnts.swap( toSrcBndPnts );
5199 fromSrcIntPnts.swap( toSrcIntPnts );
5200 fromTgtBndPnts.swap( toTgtBndPnts );
5201 fromTgtIntPnts.swap( toTgtIntPnts );
5203 } // if ( !centerIntErrorIsSmall )
5205 else if ( !bndErrorIsSmall )
5209 for ( ; zS < zT; ++zS, --zT ) // vertical loop on layers
5211 for ( size_t iP = 0; iP < myBndColumns.size(); ++iP )
5213 toSrcBndPnts[ iP ] = bndPoint( iP, zS );
5214 toTgtBndPnts[ iP ] = bndPoint( iP, zT );
5216 // compensate bnd error
5217 applyBoundaryError( toSrcBndPnts, bndError[ zS-1 ], bndError[ zS-1 ], 0.5,
5218 intPntsOfLayer[ zS ], int2BndDist );
5219 applyBoundaryError( toTgtBndPnts, bndError[ zT+1 ], bndError[ zT+1 ], 0.5,
5220 intPntsOfLayer[ zT ], int2BndDist );
5224 // cout << "centerIntErrorIsSmall = " << centerIntErrorIsSmall<< endl;
5225 // cout << "bndErrorIsSmall = " << bndErrorIsSmall<< endl;
5228 for ( size_t iP = 0; iP < myIntColumns.size(); ++iP )
5230 vector< const SMDS_MeshNode* > & nodeCol = *myIntColumns[ iP ];
5231 for ( size_t z = zSrc + 1; z < zTgt; ++z ) // vertical loop on layers
5233 const gp_XYZ & xyz = intPntsOfLayer[ z ][ iP ];
5234 if ( !( nodeCol[ z ] = myHelper->AddNode( xyz.X(), xyz.Y(), xyz.Z() )))
5242 //================================================================================
5244 * \brief Check if all nodes of each layers have same logical Z
5246 //================================================================================
5248 bool StdMeshers_Sweeper::CheckSameZ()
5250 myZColumns.resize( myBndColumns.size() );
5251 fillZColumn( myZColumns[0], *myBndColumns[0] );
5254 const double tol = 0.1 * 1./ myBndColumns[0]->size();
5256 // check columns based on VERTEXes
5258 vector< int > vertexIndex;
5259 vertexIndex.push_back( 0 );
5260 for ( size_t iC = 1; iC < myBndColumns.size() && sameZ; ++iC )
5262 if ( myBndColumns[iC]->front()->GetPosition()->GetDim() > 0 )
5263 continue; // not on VERTEX
5265 vertexIndex.push_back( iC );
5266 fillZColumn( myZColumns[iC], *myBndColumns[iC] );
5268 for ( size_t iZ = 0; iZ < myZColumns[0].size() && sameZ; ++iZ )
5269 sameZ = ( Abs( myZColumns[0][iZ] - myZColumns[iC][iZ]) < tol );
5272 // check columns based on EDGEs, one per EDGE
5274 for ( size_t i = 1; i < vertexIndex.size() && sameZ; ++i )
5276 if ( vertexIndex[i] - vertexIndex[i-1] < 2 )
5279 int iC = ( vertexIndex[i] + vertexIndex[i-1] ) / 2;
5280 fillZColumn( myZColumns[iC], *myBndColumns[iC] );
5282 for ( size_t iZ = 0; iZ < myZColumns[0].size() && sameZ; ++iZ )
5283 sameZ = ( Abs( myZColumns[0][iZ] - myZColumns[iC][iZ]) < tol );
5288 myZColumns.resize(1);
5292 for ( size_t iC = 1; iC < myBndColumns.size(); ++iC )
5293 fillZColumn( myZColumns[iC], *myBndColumns[iC] );
5299 //================================================================================
5301 * \brief Create internal nodes of the prism all located on straight lines with
5302 * the same distribution along the lines.
5304 //================================================================================
5306 bool StdMeshers_Sweeper::ComputeNodesOnStraightSameZ()
5308 TZColumn& z = myZColumns[0];
5310 for ( size_t i = 0; i < myIntColumns.size(); ++i )
5312 TNodeColumn& nodes = *myIntColumns[i];
5313 SMESH_NodeXYZ n0( nodes[0] ), n1( nodes.back() );
5315 for ( size_t iZ = 0; iZ < z.size(); ++iZ )
5317 gp_XYZ p = n0 * ( 1 - z[iZ] ) + n1 * z[iZ];
5318 nodes[ iZ+1 ] = myHelper->AddNode( p.X(), p.Y(), p.Z() );
5325 //================================================================================
5327 * \brief Create internal nodes of the prism all located on straight lines with
5328 * different distributions along the lines.
5330 //================================================================================
5332 bool StdMeshers_Sweeper::ComputeNodesOnStraight()
5334 prepareTopBotDelaunay();
5336 const SMDS_MeshNode *botNode, *topNode;
5337 const BRepMesh_Triangle *topTria;
5338 double botBC[3], topBC[3]; // barycentric coordinates
5339 int botTriaNodes[3], topTriaNodes[3];
5340 bool checkUV = true;
5342 int nbInternalNodes = myIntColumns.size();
5343 myBotDelaunay->InitTraversal( nbInternalNodes );
5345 while (( botNode = myBotDelaunay->NextNode( botBC, botTriaNodes )))
5347 TNodeColumn* column = myIntColumns[ myNodeID2ColID( botNode->GetID() )];
5349 // find a Delaunay triangle containing the topNode
5350 topNode = column->back();
5351 gp_XY topUV = myHelper->GetNodeUV( myTopFace, topNode, NULL, &checkUV );
5352 // get a starting triangle basing on that top and bot boundary nodes have same index
5353 topTria = myTopDelaunay->GetTriangleNear( botTriaNodes[0] );
5354 topTria = myTopDelaunay->FindTriangle( topUV, topTria, topBC, topTriaNodes );
5358 // create nodes along a line
5359 SMESH_NodeXYZ botP( botNode ), topP( topNode);
5360 for ( size_t iZ = 0; iZ < myZColumns[0].size(); ++iZ )
5362 // use barycentric coordinates as weight of Z of boundary columns
5363 double botZ = 0, topZ = 0;
5364 for ( int i = 0; i < 3; ++i )
5366 botZ += botBC[i] * myZColumns[ botTriaNodes[i] ][ iZ ];
5367 topZ += topBC[i] * myZColumns[ topTriaNodes[i] ][ iZ ];
5369 double rZ = double( iZ + 1 ) / ( myZColumns[0].size() + 1 );
5370 double z = botZ * ( 1 - rZ ) + topZ * rZ;
5371 gp_XYZ p = botP * ( 1 - z ) + topP * z;
5372 (*column)[ iZ+1 ] = myHelper->AddNode( p.X(), p.Y(), p.Z() );
5376 return myBotDelaunay->NbVisitedNodes() == nbInternalNodes;
5379 //================================================================================
5381 * \brief Compute Z of nodes of a straight column
5383 //================================================================================
5385 void StdMeshers_Sweeper::fillZColumn( TZColumn& zColumn,
5386 TNodeColumn& nodes )
5388 if ( zColumn.size() == nodes.size() - 2 )
5391 gp_Pnt p0 = SMESH_NodeXYZ( nodes[0] );
5392 gp_Vec line( p0, SMESH_NodeXYZ( nodes.back() ));
5393 double len2 = line.SquareMagnitude();
5395 zColumn.resize( nodes.size() - 2 );
5396 for ( size_t i = 0; i < zColumn.size(); ++i )
5398 gp_Vec vec( p0, SMESH_NodeXYZ( nodes[ i+1] ));
5399 zColumn[i] = ( line * vec ) / len2; // param [0,1] on the line
5403 //================================================================================
5405 * \brief Initialize *Delaunay members
5407 //================================================================================
5409 void StdMeshers_Sweeper::prepareTopBotDelaunay()
5411 UVPtStructVec botUV( myBndColumns.size() );
5412 UVPtStructVec topUV( myBndColumns.size() );
5413 for ( size_t i = 0; i < myBndColumns.size(); ++i )
5415 TNodeColumn& nodes = *myBndColumns[i];
5416 botUV[i].node = nodes[0];
5417 botUV[i].SetUV( myHelper->GetNodeUV( myBotFace, nodes[0] ));
5418 topUV[i].node = nodes.back();
5419 topUV[i].SetUV( myHelper->GetNodeUV( myTopFace, nodes.back() ));
5420 botUV[i].node->setIsMarked( true );
5423 SMESH_Mesh* mesh = myHelper->GetMesh();
5424 TSideVector botWires( 1, StdMeshers_FaceSide::New( botUV, myBotFace, dummyE, mesh ));
5425 TSideVector topWires( 1, StdMeshers_FaceSide::New( topUV, myTopFace, dummyE, mesh ));
5427 // Delaunay mesh on the FACEs.
5428 bool checkUV = false;
5429 myBotDelaunay.reset( new NSProjUtils::Delaunay( botWires, checkUV ));
5430 myTopDelaunay.reset( new NSProjUtils::Delaunay( topWires, checkUV ));
5432 if ( myHelper->GetIsQuadratic() )
5434 // mark all medium nodes of faces on botFace to avoid their treating
5435 SMESHDS_SubMesh* smDS = myHelper->GetMeshDS()->MeshElements( myBotFace );
5436 SMDS_ElemIteratorPtr eIt = smDS->GetElements();
5437 while ( eIt->more() )
5439 const SMDS_MeshElement* e = eIt->next();
5440 for ( int i = e->NbCornerNodes(), nb = e->NbNodes(); i < nb; ++i )
5441 e->GetNode( i )->setIsMarked( true );
5445 // map to get a node column by a bottom node
5446 myNodeID2ColID.Clear(/*doReleaseMemory=*/false);
5447 myNodeID2ColID.ReSize( myIntColumns.size() );
5449 // un-mark nodes to treat (internal bottom nodes) to be returned by myBotDelaunay
5450 for ( size_t i = 0; i < myIntColumns.size(); ++i )
5452 const SMDS_MeshNode* botNode = myIntColumns[i]->front();
5453 botNode->setIsMarked( false );
5454 myNodeID2ColID.Bind( botNode->GetID(), i );