1 // Copyright (C) 2007-2015 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License, or (at your option) any later version.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 // File : StdMeshers_Prism_3D.cxx
25 // Created : Fri Oct 20 11:37:07 2006
26 // Author : Edward AGAPOV (eap)
28 #include "StdMeshers_Prism_3D.hxx"
30 #include "SMDS_EdgePosition.hxx"
31 #include "SMDS_VolumeOfNodes.hxx"
32 #include "SMDS_VolumeTool.hxx"
33 #include "SMESH_Comment.hxx"
34 #include "SMESH_Gen.hxx"
35 #include "SMESH_HypoFilter.hxx"
36 #include "SMESH_MesherHelper.hxx"
37 #include "StdMeshers_FaceSide.hxx"
38 #include "StdMeshers_ProjectionSource1D.hxx"
39 #include "StdMeshers_ProjectionSource2D.hxx"
40 #include "StdMeshers_ProjectionUtils.hxx"
41 #include "StdMeshers_Projection_1D.hxx"
42 #include "StdMeshers_Projection_1D2D.hxx"
43 #include "StdMeshers_Quadrangle_2D.hxx"
45 #include "utilities.h"
47 #include <BRepAdaptor_CompCurve.hxx>
48 #include <BRep_Tool.hxx>
49 #include <Bnd_B3d.hxx>
50 #include <Geom2dAdaptor_Curve.hxx>
51 #include <Geom2d_Line.hxx>
52 #include <GeomLib_IsPlanarSurface.hxx>
53 #include <Geom_Curve.hxx>
55 #include <TopExp_Explorer.hxx>
56 #include <TopTools_ListIteratorOfListOfShape.hxx>
57 #include <TopTools_ListOfShape.hxx>
58 #include <TopTools_MapOfShape.hxx>
59 #include <TopTools_SequenceOfShape.hxx>
68 #define RETURN_BAD_RESULT(msg) { MESSAGE(")-: Error: " << msg); return false; }
69 #define gpXYZ(n) SMESH_TNodeXYZ(n)
72 #define DBGOUT(msg) //cout << msg << endl;
73 #define SHOWYXZ(msg, xyz) \
74 //{ gp_Pnt p (xyz); cout << msg << " ("<< p.X() << "; " <<p.Y() << "; " <<p.Z() << ") " <<endl; }
77 #define SHOWYXZ(msg, xyz)
80 namespace NSProjUtils = StdMeshers_ProjectionUtils;
82 typedef SMESH_Comment TCom;
84 enum { ID_BOT_FACE = SMESH_Block::ID_Fxy0,
85 ID_TOP_FACE = SMESH_Block::ID_Fxy1,
86 BOTTOM_EDGE = 0, TOP_EDGE, V0_EDGE, V1_EDGE, // edge IDs in face
87 NB_WALL_FACES = 4 }; //
91 //=======================================================================
93 * \brief Quadrangle algorithm
95 struct TQuadrangleAlgo : public StdMeshers_Quadrangle_2D
97 TQuadrangleAlgo(int studyId, SMESH_Gen* gen)
98 : StdMeshers_Quadrangle_2D( gen->GetANewId(), studyId, gen)
101 static StdMeshers_Quadrangle_2D* instance( SMESH_Algo* fatherAlgo,
102 SMESH_MesherHelper* helper=0)
104 static TQuadrangleAlgo* algo = new TQuadrangleAlgo( fatherAlgo->GetStudyId(),
105 fatherAlgo->GetGen() );
108 algo->myProxyMesh->GetMesh() != helper->GetMesh() )
109 algo->myProxyMesh.reset( new SMESH_ProxyMesh( *helper->GetMesh() ));
111 algo->myQuadList.clear();
114 algo->_quadraticMesh = helper->GetIsQuadratic();
119 //=======================================================================
121 * \brief Algorithm projecting 1D mesh
123 struct TProjction1dAlgo : public StdMeshers_Projection_1D
125 StdMeshers_ProjectionSource1D myHyp;
127 TProjction1dAlgo(int studyId, SMESH_Gen* gen)
128 : StdMeshers_Projection_1D( gen->GetANewId(), studyId, gen),
129 myHyp( gen->GetANewId(), studyId, gen)
131 StdMeshers_Projection_1D::_sourceHypo = & myHyp;
133 static TProjction1dAlgo* instance( SMESH_Algo* fatherAlgo )
135 static TProjction1dAlgo* algo = new TProjction1dAlgo( fatherAlgo->GetStudyId(),
136 fatherAlgo->GetGen() );
140 //=======================================================================
142 * \brief Algorithm projecting 2D mesh
144 struct TProjction2dAlgo : public StdMeshers_Projection_1D2D
146 StdMeshers_ProjectionSource2D myHyp;
148 TProjction2dAlgo(int studyId, SMESH_Gen* gen)
149 : StdMeshers_Projection_1D2D( gen->GetANewId(), studyId, gen),
150 myHyp( gen->GetANewId(), studyId, gen)
152 StdMeshers_Projection_2D::_sourceHypo = & myHyp;
154 static TProjction2dAlgo* instance( SMESH_Algo* fatherAlgo )
156 static TProjction2dAlgo* algo = new TProjction2dAlgo( fatherAlgo->GetStudyId(),
157 fatherAlgo->GetGen() );
160 const NSProjUtils::TNodeNodeMap& GetNodesMap()
162 return _src2tgtNodes;
165 //=======================================================================
167 * \brief Returns already computed EDGEs
169 void getPrecomputedEdges( SMESH_MesherHelper& theHelper,
170 const TopoDS_Shape& theShape,
171 vector< TopoDS_Edge >& theEdges)
175 SMESHDS_Mesh* meshDS = theHelper.GetMeshDS();
178 TopTools_IndexedMapOfShape edges;
179 TopExp::MapShapes( theShape, TopAbs_EDGE, edges );
180 for ( int iE = 1; iE <= edges.Extent(); ++iE )
182 const TopoDS_Shape edge = edges( iE );
183 if (( ! ( sm = meshDS->MeshElements( edge ))) ||
184 ( sm->NbElements() == 0 ))
187 // there must not be FACEs meshed with triangles and sharing a computed EDGE
188 // as the precomputed EDGEs are used for propagation other to 'vertical' EDGEs
189 bool faceFound = false;
190 PShapeIteratorPtr faceIt =
191 theHelper.GetAncestors( edge, *theHelper.GetMesh(), TopAbs_FACE );
192 while ( const TopoDS_Shape* face = faceIt->next() )
194 if (( sm = meshDS->MeshElements( *face )) &&
195 ( sm->NbElements() > 0 ) &&
196 ( !theHelper.IsSameElemGeometry( sm, SMDSGeom_QUADRANGLE ) ))
202 theEdges.push_back( TopoDS::Edge( edge ));
206 //================================================================================
208 * \brief Make \a botE be the BOTTOM_SIDE of \a quad.
209 * Return false if the BOTTOM_SIDE is composite
211 //================================================================================
213 bool setBottomEdge( const TopoDS_Edge& botE,
214 FaceQuadStruct::Ptr& quad,
215 const TopoDS_Shape& face)
217 quad->side[ QUAD_TOP_SIDE ].grid->Reverse();
218 quad->side[ QUAD_LEFT_SIDE ].grid->Reverse();
220 bool isComposite = false;
221 for ( size_t i = 0; i < quad->side.size(); ++i )
223 StdMeshers_FaceSidePtr quadSide = quad->side[i];
224 for ( int iE = 0; iE < quadSide->NbEdges(); ++iE )
225 if ( botE.IsSame( quadSide->Edge( iE )))
227 if ( quadSide->NbEdges() > 1 )
228 isComposite = true; //return false;
230 i = quad->side.size(); // to quit from the outer loop
234 if ( edgeIndex != QUAD_BOTTOM_SIDE )
235 quad->shift( quad->side.size() - edgeIndex, /*keepUnitOri=*/false );
237 quad->face = TopoDS::Face( face );
242 //================================================================================
244 * \brief Return iterator pointing to node column for the given parameter
245 * \param columnsMap - node column map
246 * \param parameter - parameter
247 * \retval TParam2ColumnMap::iterator - result
249 * it returns closest left column
251 //================================================================================
253 TParam2ColumnIt getColumn( const TParam2ColumnMap* columnsMap,
254 const double parameter )
256 TParam2ColumnIt u_col = columnsMap->upper_bound( parameter );
257 if ( u_col != columnsMap->begin() )
259 return u_col; // return left column
262 //================================================================================
264 * \brief Return nodes around given parameter and a ratio
265 * \param column - node column
266 * \param param - parameter
267 * \param node1 - lower node
268 * \param node2 - upper node
269 * \retval double - ratio
271 //================================================================================
273 double getRAndNodes( const TNodeColumn* column,
275 const SMDS_MeshNode* & node1,
276 const SMDS_MeshNode* & node2)
278 if ( param >= 1.0 || column->size() == 1) {
279 node1 = node2 = column->back();
283 int i = int( param * ( column->size() - 1 ));
284 double u0 = double( i )/ double( column->size() - 1 );
285 double r = ( param - u0 ) * ( column->size() - 1 );
287 node1 = (*column)[ i ];
288 node2 = (*column)[ i + 1];
292 //================================================================================
294 * \brief Compute boundary parameters of face parts
295 * \param nbParts - nb of parts to split columns into
296 * \param columnsMap - node columns of the face to split
297 * \param params - computed parameters
299 //================================================================================
301 void splitParams( const int nbParts,
302 const TParam2ColumnMap* columnsMap,
303 vector< double > & params)
306 params.reserve( nbParts + 1 );
307 TParam2ColumnIt last_par_col = --columnsMap->end();
308 double par = columnsMap->begin()->first; // 0.
309 double parLast = last_par_col->first;
310 params.push_back( par );
311 for ( int i = 0; i < nbParts - 1; ++ i )
313 double partSize = ( parLast - par ) / double ( nbParts - i );
314 TParam2ColumnIt par_col = getColumn( columnsMap, par + partSize );
315 if ( par_col->first == par ) {
317 if ( par_col == last_par_col ) {
318 while ( i < nbParts - 1 )
319 params.push_back( par + partSize * i++ );
323 par = par_col->first;
324 params.push_back( par );
326 params.push_back( parLast ); // 1.
329 //================================================================================
331 * \brief Return coordinate system for z-th layer of nodes
333 //================================================================================
335 gp_Ax2 getLayerCoordSys(const int z,
336 const vector< const TNodeColumn* >& columns,
339 // gravity center of a layer
342 for ( int i = 0; i < columns.size(); ++i )
344 O += gpXYZ( (*columns[ i ])[ z ]);
345 if ( vertexCol < 0 &&
346 columns[ i ]->front()->GetPosition()->GetTypeOfPosition() == SMDS_TOP_VERTEX )
353 int iPrev = columns.size()-1;
354 for ( int i = 0; i < columns.size(); ++i )
356 gp_Vec v1( O, gpXYZ( (*columns[ iPrev ])[ z ]));
357 gp_Vec v2( O, gpXYZ( (*columns[ i ] )[ z ]));
362 if ( vertexCol >= 0 )
364 O = gpXYZ( (*columns[ vertexCol ])[ z ]);
366 if ( xColumn < 0 || xColumn >= columns.size() )
368 // select a column for X dir
370 for ( int i = 0; i < columns.size(); ++i )
372 double dist = ( O - gpXYZ((*columns[ i ])[ z ])).SquareModulus();
373 if ( dist > maxDist )
382 gp_Vec X( O, gpXYZ( (*columns[ xColumn ])[ z ]));
384 return gp_Ax2( O, Z, X);
387 //================================================================================
389 * \brief Removes submeshes that are or can be meshed with regular grid from given list
390 * \retval int - nb of removed submeshes
392 //================================================================================
394 int removeQuasiQuads(list< SMESH_subMesh* >& notQuadSubMesh,
395 SMESH_MesherHelper* helper,
396 StdMeshers_Quadrangle_2D* quadAlgo)
399 //SMESHDS_Mesh* mesh = notQuadSubMesh.front()->GetFather()->GetMeshDS();
400 list< SMESH_subMesh* >::iterator smIt = notQuadSubMesh.begin();
401 while ( smIt != notQuadSubMesh.end() )
403 SMESH_subMesh* faceSm = *smIt;
404 SMESHDS_SubMesh* faceSmDS = faceSm->GetSubMeshDS();
405 int nbQuads = faceSmDS ? faceSmDS->NbElements() : 0;
408 toRemove = helper->IsStructured( faceSm );
410 toRemove = ( quadAlgo->CheckNbEdges( *helper->GetMesh(),
411 faceSm->GetSubShape() ) != NULL );
412 nbRemoved += toRemove;
414 smIt = notQuadSubMesh.erase( smIt );
422 //================================================================================
424 * \brief Return and angle between two EDGEs
425 * \return double - the angle normalized so that
432 //================================================================================
434 // double normAngle(const TopoDS_Edge & E1, const TopoDS_Edge & E2, const TopoDS_Face & F)
436 // return SMESH_MesherHelper::GetAngle( E1, E2, F ) / ( 0.5 * M_PI );
439 //================================================================================
441 * Consider continuous straight EDGES as one side - mark them to unite
443 //================================================================================
445 int countNbSides( const Prism_3D::TPrismTopo & thePrism,
446 vector<int> & nbUnitePerEdge,
447 vector< double > & edgeLength)
449 int nbEdges = thePrism.myNbEdgesInWires.front(); // nb outer edges
450 int nbSides = nbEdges;
453 list< TopoDS_Edge >::const_iterator edgeIt = thePrism.myBottomEdges.begin();
454 std::advance( edgeIt, nbEdges-1 );
455 TopoDS_Edge prevE = *edgeIt;
456 // bool isPrevStraight = SMESH_Algo::IsStraight( prevE );
457 int iPrev = nbEdges - 1;
459 int iUnite = -1; // the first of united EDGEs
461 // analyse angles between EDGEs
463 vector< bool > isCorner( nbEdges );
464 edgeIt = thePrism.myBottomEdges.begin();
465 for ( int iE = 0; iE < nbEdges; ++iE, ++edgeIt )
467 const TopoDS_Edge& curE = *edgeIt;
468 edgeLength[ iE ] = SMESH_Algo::EdgeLength( curE );
470 // double normAngle = normAngle( prevE, curE, thePrism.myBottom );
471 // isCorner[ iE ] = false;
472 // if ( normAngle < 2.0 )
474 // if ( normAngle < 0.001 ) // straight or obtuse angle
476 // // unite EDGEs in order not to put a corner of the unit quadrangle at this VERTEX
479 // nbUnitePerEdge[ iUnite ]++;
480 // nbUnitePerEdge[ iE ] = -1;
485 // isCorner[ iE ] = true;
495 // define which of corners to put on a side of the unit quadrangle
497 // edgeIt = thePrism.myBottomEdges.begin();
498 // for ( int iE = 0; iE < nbEdges; ++iE, ++edgeIt )
500 // const TopoDS_Edge& curE = *edgeIt;
501 // edgeLength[ iE ] = SMESH_Algo::EdgeLength( curE );
503 // const bool isCurStraight = SMESH_Algo::IsStraight( curE );
504 // if ( isPrevStraight && isCurStraight && SMESH_Algo::IsContinuous( prevE, curE ))
508 // nbUnitePerEdge[ iUnite ]++;
509 // nbUnitePerEdge[ iE ] = -1;
517 // isPrevStraight = isCurStraight;
524 void pointsToPython(const std::vector<gp_XYZ>& p)
527 for ( int i = SMESH_Block::ID_V000; i < p.size(); ++i )
529 cout << "mesh.AddNode( " << p[i].X() << ", "<< p[i].Y() << ", "<< p[i].Z() << ") # " << i <<" " ;
530 SMESH_Block::DumpShapeID( i, cout ) << endl;
536 //=======================================================================
537 //function : StdMeshers_Prism_3D
539 //=======================================================================
541 StdMeshers_Prism_3D::StdMeshers_Prism_3D(int hypId, int studyId, SMESH_Gen* gen)
542 :SMESH_3D_Algo(hypId, studyId, gen)
545 _shapeType = (1 << TopAbs_SOLID); // 1 bit per shape type
546 _onlyUnaryInput = false; // mesh all SOLIDs at once
547 _requireDiscreteBoundary = false; // mesh FACEs and EDGEs by myself
548 _supportSubmeshes = true; // "source" FACE must be meshed by other algo
549 _neededLowerHyps[ 1 ] = true; // suppress warning on hiding a global 1D algo
550 _neededLowerHyps[ 2 ] = true; // suppress warning on hiding a global 2D algo
552 //myProjectTriangles = false;
553 mySetErrorToSM = true; // to pass an error to a sub-mesh of a current solid or not
556 //================================================================================
560 //================================================================================
562 StdMeshers_Prism_3D::~StdMeshers_Prism_3D()
565 //=======================================================================
566 //function : CheckHypothesis
568 //=======================================================================
570 bool StdMeshers_Prism_3D::CheckHypothesis(SMESH_Mesh& aMesh,
571 const TopoDS_Shape& aShape,
572 SMESH_Hypothesis::Hypothesis_Status& aStatus)
574 // Check shape geometry
576 aStatus = SMESH_Hypothesis::HYP_BAD_GEOMETRY;
578 // find not quadrangle faces
579 list< TopoDS_Shape > notQuadFaces;
580 int nbEdge, nbWire, nbFace = 0;
581 TopExp_Explorer exp( aShape, TopAbs_FACE );
582 for ( ; exp.More(); exp.Next() ) {
584 const TopoDS_Shape& face = exp.Current();
585 nbEdge = NSProjUtils::Count( face, TopAbs_EDGE, 0 );
586 nbWire = NSProjUtils::Count( face, TopAbs_WIRE, 0 );
587 if ( nbEdge!= 4 || nbWire!= 1 ) {
588 if ( !notQuadFaces.empty() ) {
589 if ( NSProjUtils::Count( notQuadFaces.back(), TopAbs_EDGE, 0 ) != nbEdge ||
590 NSProjUtils::Count( notQuadFaces.back(), TopAbs_WIRE, 0 ) != nbWire )
591 RETURN_BAD_RESULT("Different not quad faces");
593 notQuadFaces.push_back( face );
596 if ( !notQuadFaces.empty() )
598 if ( notQuadFaces.size() != 2 )
599 RETURN_BAD_RESULT("Bad nb not quad faces: " << notQuadFaces.size());
601 // check total nb faces
602 nbEdge = NSProjUtils::Count( notQuadFaces.back(), TopAbs_EDGE, 0 );
603 if ( nbFace != nbEdge + 2 )
604 RETURN_BAD_RESULT("Bad nb of faces: " << nbFace << " but must be " << nbEdge + 2);
608 aStatus = SMESH_Hypothesis::HYP_OK;
612 //=======================================================================
614 //purpose : Compute mesh on a COMPOUND of SOLIDs
615 //=======================================================================
617 bool StdMeshers_Prism_3D::Compute(SMESH_Mesh& theMesh, const TopoDS_Shape& theShape)
619 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, ect.
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();
938 while ( edge != thePrism.myBottomEdges.end() )
941 if ( BRep_Tool::Curve( *edge, f,l ).IsNull() )
943 edge = thePrism.myBottomEdges.erase( edge );
949 TopTools_ListIteratorOfListOfShape faceIt( edgeToFaces.FindFromKey( *edge ));
950 for ( ; faceIt.More(); faceIt.Next() )
952 const TopoDS_Face& face = TopoDS::Face( faceIt.Value() );
953 if ( !thePrism.myBottom.IsSame( face ))
955 Prism_3D::TQuadList quadList( 1, quadAlgo->CheckNbEdges( *mesh, face ));
956 if ( !quadList.back() )
957 return toSM( error(TCom("Side face #") << shapeID( face )
958 << " not meshable with quadrangles"));
959 bool isCompositeBase = ! setBottomEdge( *edge, quadList.back(), face );
960 if ( isCompositeBase )
962 // it's OK if all EDGEs of the bottom side belongs to the bottom FACE
963 StdMeshers_FaceSidePtr botSide = quadList.back()->side[ QUAD_BOTTOM_SIDE ];
964 for ( int iE = 0; iE < botSide->NbEdges(); ++iE )
965 if ( !myHelper->IsSubShape( botSide->Edge(iE), thePrism.myBottom ))
966 return toSM( error(TCom("Composite 'horizontal' edges are not supported")));
968 if ( faceMap.Add( face ))
969 thePrism.myWallQuads.push_back( quadList );
982 // -------------------------
983 // Find the rest wall FACEs
984 // -------------------------
986 // Compose a vector of indixes of right neighbour FACE for each wall FACE
987 // that is not so evident in case of several WIREs in the bottom FACE
988 thePrism.myRightQuadIndex.clear();
989 for ( size_t i = 0; i < thePrism.myWallQuads.size(); ++i )
990 thePrism.myRightQuadIndex.push_back( i+1 );
991 list< int >::iterator nbEinW = thePrism.myNbEdgesInWires.begin();
992 for ( int iLeft = 0; nbEinW != thePrism.myNbEdgesInWires.end(); ++nbEinW )
994 thePrism.myRightQuadIndex[ iLeft + *nbEinW - 1 ] = iLeft; // 1st EDGE index of a current WIRE
998 while ( totalNbFaces - faceMap.Extent() > 2 )
1000 // find wall FACEs adjacent to each of wallQuads by the right side EDGE
1003 nbKnownFaces = faceMap.Extent();
1004 StdMeshers_FaceSidePtr rightSide, topSide; // sides of the quad
1005 for ( size_t i = 0; i < thePrism.myWallQuads.size(); ++i )
1007 rightSide = thePrism.myWallQuads[i].back()->side[ QUAD_RIGHT_SIDE ];
1008 for ( int iE = 0; iE < rightSide->NbEdges(); ++iE ) // rightSide can be composite
1010 const TopoDS_Edge & rightE = rightSide->Edge( iE );
1011 TopTools_ListIteratorOfListOfShape face( edgeToFaces.FindFromKey( rightE ));
1012 for ( ; face.More(); face.Next() )
1013 if ( faceMap.Add( face.Value() ))
1015 // a new wall FACE encountered, store it in thePrism.myWallQuads
1016 const int iRight = thePrism.myRightQuadIndex[i];
1017 topSide = thePrism.myWallQuads[ iRight ].back()->side[ QUAD_TOP_SIDE ];
1018 const TopoDS_Edge& newBotE = topSide->Edge(0);
1019 const TopoDS_Shape& newWallF = face.Value();
1020 thePrism.myWallQuads[ iRight ].push_back( quadAlgo->CheckNbEdges( *mesh, newWallF ));
1021 if ( !thePrism.myWallQuads[ iRight ].back() )
1022 return toSM( error(TCom("Side face #") << shapeID( newWallF ) <<
1023 " not meshable with quadrangles"));
1024 if ( ! setBottomEdge( newBotE, thePrism.myWallQuads[ iRight ].back(), newWallF ))
1025 return toSM( error(TCom("Composite 'horizontal' edges are not supported")));
1029 } while ( nbKnownFaces != faceMap.Extent() );
1031 // find wall FACEs adjacent to each of thePrism.myWallQuads by the top side EDGE
1032 if ( totalNbFaces - faceMap.Extent() > 2 )
1034 const int nbFoundWalls = faceMap.Extent();
1035 for ( size_t i = 0; i < thePrism.myWallQuads.size(); ++i )
1037 StdMeshers_FaceSidePtr topSide = thePrism.myWallQuads[i].back()->side[ QUAD_TOP_SIDE ];
1038 const TopoDS_Edge & topE = topSide->Edge( 0 );
1039 if ( topSide->NbEdges() > 1 )
1040 return toSM( error(COMPERR_BAD_SHAPE, TCom("Side face #") <<
1041 shapeID( thePrism.myWallQuads[i].back()->face )
1042 << " has a composite top edge"));
1043 TopTools_ListIteratorOfListOfShape faceIt( edgeToFaces.FindFromKey( topE ));
1044 for ( ; faceIt.More(); faceIt.Next() )
1045 if ( faceMap.Add( faceIt.Value() ))
1047 // a new wall FACE encountered, store it in wallQuads
1048 thePrism.myWallQuads[ i ].push_back( quadAlgo->CheckNbEdges( *mesh, faceIt.Value() ));
1049 if ( !thePrism.myWallQuads[ i ].back() )
1050 return toSM( error(TCom("Side face #") << shapeID( faceIt.Value() ) <<
1051 " not meshable with quadrangles"));
1052 if ( ! setBottomEdge( topE, thePrism.myWallQuads[ i ].back(), faceIt.Value() ))
1053 return toSM( error(TCom("Composite 'horizontal' edges are not supported")));
1054 if ( totalNbFaces - faceMap.Extent() == 2 )
1056 i = thePrism.myWallQuads.size(); // to quit from the outer loop
1061 if ( nbFoundWalls == faceMap.Extent() )
1062 return toSM( error("Failed to find wall faces"));
1065 } // while ( totalNbFaces - faceMap.Extent() > 2 )
1067 // ------------------
1068 // Find the top FACE
1069 // ------------------
1071 if ( thePrism.myTop.IsNull() )
1073 // now only top and bottom FACEs are not in the faceMap
1074 faceMap.Add( thePrism.myBottom );
1075 for ( TopExp_Explorer f( thePrism.myShape3D, TopAbs_FACE );f.More(); f.Next() )
1076 if ( !faceMap.Contains( f.Current() )) {
1077 thePrism.myTop = TopoDS::Face( f.Current() );
1080 if ( thePrism.myTop.IsNull() )
1081 return toSM( error("Top face not found"));
1084 // Check that the top FACE shares all the top EDGEs
1085 for ( size_t i = 0; i < thePrism.myWallQuads.size(); ++i )
1087 StdMeshers_FaceSidePtr topSide = thePrism.myWallQuads[i].back()->side[ QUAD_TOP_SIDE ];
1088 const TopoDS_Edge & topE = topSide->Edge( 0 );
1089 if ( !myHelper->IsSubShape( topE, thePrism.myTop ))
1090 return toSM( error( TCom("Wrong source face: #") << shapeID( thePrism.myBottom )));
1096 //=======================================================================
1097 //function : compute
1098 //purpose : Compute mesh on a SOLID
1099 //=======================================================================
1101 bool StdMeshers_Prism_3D::compute(const Prism_3D::TPrismTopo& thePrism)
1103 myHelper->IsQuadraticSubMesh( thePrism.myShape3D );
1104 if ( _computeCanceled )
1105 return toSM( error( SMESH_ComputeError::New(COMPERR_CANCELED)));
1107 // Assure the bottom is meshed
1108 SMESH_subMesh * botSM = myHelper->GetMesh()->GetSubMesh( thePrism.myBottom );
1109 if (( botSM->IsEmpty() ) &&
1110 ( ! botSM->GetAlgo() ||
1111 ! _gen->Compute( *botSM->GetFather(), botSM->GetSubShape(), /*shapeOnly=*/true )))
1112 return error( COMPERR_BAD_INPUT_MESH,
1113 TCom( "No mesher defined to compute the face #")
1114 << shapeID( thePrism.myBottom ));
1116 // Make all side FACEs of thePrism meshed with quads
1117 if ( !computeWalls( thePrism ))
1120 // Analyse mesh and geometry to find all block sub-shapes and submeshes
1121 // (after fixing IPAL52499 myBlock is used as a holder of boundary nodes
1122 // and for 2D projection in hard cases where StdMeshers_Projection_2D fails;
1123 // location of internal nodes is usually computed by StdMeshers_Sweeper)
1124 if ( !myBlock.Init( myHelper, thePrism ))
1125 return toSM( error( myBlock.GetError()));
1127 SMESHDS_Mesh* meshDS = myHelper->GetMeshDS();
1129 int volumeID = meshDS->ShapeToIndex( thePrism.myShape3D );
1131 // Try to get gp_Trsf to get all nodes from bottom ones
1132 vector<gp_Trsf> trsf;
1133 gp_Trsf bottomToTopTrsf;
1134 // if ( !myBlock.GetLayersTransformation( trsf, thePrism ))
1136 // else if ( !trsf.empty() )
1137 // bottomToTopTrsf = trsf.back();
1139 // To compute coordinates of a node inside a block, it is necessary to know
1140 // 1. normalized parameters of the node by which
1141 // 2. coordinates of node projections on all block sub-shapes are computed
1143 // So we fill projections on vertices at once as they are same for all nodes
1144 myShapeXYZ.resize( myBlock.NbSubShapes() );
1145 for ( int iV = SMESH_Block::ID_FirstV; iV < SMESH_Block::ID_FirstE; ++iV ) {
1146 myBlock.VertexPoint( iV, myShapeXYZ[ iV ]);
1147 SHOWYXZ("V point " <<iV << " ", myShapeXYZ[ iV ]);
1150 // Projections on the top and bottom faces are taken from nodes existing
1151 // on these faces; find correspondence between bottom and top nodes
1153 myBotToColumnMap.clear();
1154 if ( !assocOrProjBottom2Top( bottomToTopTrsf, thePrism ) ) // it also fills myBotToColumnMap
1158 // Create nodes inside the block
1160 // use transformation (issue 0020680, IPAL0052499)
1161 StdMeshers_Sweeper sweeper;
1163 bool allowHighBndError;
1167 // load boundary nodes into sweeper
1169 list< TopoDS_Edge >::const_iterator edge = thePrism.myBottomEdges.begin();
1170 for ( ; edge != thePrism.myBottomEdges.end(); ++edge )
1172 int edgeID = meshDS->ShapeToIndex( *edge );
1173 TParam2ColumnMap* u2col = const_cast<TParam2ColumnMap*>
1174 ( myBlock.GetParam2ColumnMap( edgeID, dummy ));
1175 TParam2ColumnMap::iterator u2colIt = u2col->begin();
1176 for ( ; u2colIt != u2col->end(); ++u2colIt )
1177 sweeper.myBndColumns.push_back( & u2colIt->second );
1179 // load node columns inside the bottom face
1180 TNode2ColumnMap::iterator bot_column = myBotToColumnMap.begin();
1181 for ( ; bot_column != myBotToColumnMap.end(); ++bot_column )
1182 sweeper.myIntColumns.push_back( & bot_column->second );
1184 tol = getSweepTolerance( thePrism );
1185 allowHighBndError = !isSimpleBottom( thePrism );
1188 if ( !myUseBlock && sweeper.ComputeNodes( *myHelper, tol, allowHighBndError ))
1191 else // use block approach
1193 // loop on nodes inside the bottom face
1194 Prism_3D::TNode prevBNode;
1195 TNode2ColumnMap::iterator bot_column = myBotToColumnMap.begin();
1196 for ( ; bot_column != myBotToColumnMap.end(); ++bot_column )
1198 const Prism_3D::TNode& tBotNode = bot_column->first; // bottom TNode
1199 if ( tBotNode.GetPositionType() != SMDS_TOP_FACE )
1200 continue; // node is not inside the FACE
1202 // column nodes; middle part of the column are zero pointers
1203 TNodeColumn& column = bot_column->second;
1205 gp_XYZ botParams, topParams;
1206 if ( !tBotNode.HasParams() )
1208 // compute bottom node parameters
1209 gp_XYZ paramHint(-1,-1,-1);
1210 if ( prevBNode.IsNeighbor( tBotNode ))
1211 paramHint = prevBNode.GetParams();
1212 if ( !myBlock.ComputeParameters( tBotNode.GetCoords(), tBotNode.ChangeParams(),
1213 ID_BOT_FACE, paramHint ))
1214 return toSM( error(TCom("Can't compute normalized parameters for node ")
1215 << tBotNode.myNode->GetID() << " on the face #"
1216 << myBlock.SubMesh( ID_BOT_FACE )->GetId() ));
1217 prevBNode = tBotNode;
1219 botParams = topParams = tBotNode.GetParams();
1220 topParams.SetZ( 1 );
1222 // compute top node parameters
1223 if ( column.size() > 2 ) {
1224 gp_Pnt topCoords = gpXYZ( column.back() );
1225 if ( !myBlock.ComputeParameters( topCoords, topParams, ID_TOP_FACE, topParams ))
1226 return toSM( error(TCom("Can't compute normalized parameters ")
1227 << "for node " << column.back()->GetID()
1228 << " on the face #"<< column.back()->getshapeId() ));
1231 else // top nodes are created by projection using parameters
1233 botParams = topParams = tBotNode.GetParams();
1234 topParams.SetZ( 1 );
1237 myShapeXYZ[ ID_BOT_FACE ] = tBotNode.GetCoords();
1238 myShapeXYZ[ ID_TOP_FACE ] = gpXYZ( column.back() );
1241 TNodeColumn::iterator columnNodes = column.begin();
1242 for ( int z = 0; columnNodes != column.end(); ++columnNodes, ++z)
1244 const SMDS_MeshNode* & node = *columnNodes;
1245 if ( node ) continue; // skip bottom or top node
1247 // params of a node to create
1248 double rz = (double) z / (double) ( column.size() - 1 );
1249 gp_XYZ params = botParams * ( 1 - rz ) + topParams * rz;
1251 // set coords on all faces and nodes
1252 const int nbSideFaces = 4;
1253 int sideFaceIDs[nbSideFaces] = { SMESH_Block::ID_Fx0z,
1254 SMESH_Block::ID_Fx1z,
1255 SMESH_Block::ID_F0yz,
1256 SMESH_Block::ID_F1yz };
1257 for ( int iF = 0; iF < nbSideFaces; ++iF )
1258 if ( !setFaceAndEdgesXYZ( sideFaceIDs[ iF ], params, z ))
1261 // compute coords for a new node
1263 if ( !SMESH_Block::ShellPoint( params, myShapeXYZ, coords ))
1264 return toSM( error("Can't compute coordinates by normalized parameters"));
1266 // if ( !meshDS->MeshElements( volumeID ) ||
1267 // meshDS->MeshElements( volumeID )->NbNodes() == 0 )
1268 // pointsToPython(myShapeXYZ);
1269 SHOWYXZ("TOPFacePoint ",myShapeXYZ[ ID_TOP_FACE]);
1270 SHOWYXZ("BOT Node "<< tBotNode.myNode->GetID(),gpXYZ(tBotNode.myNode));
1271 SHOWYXZ("ShellPoint ",coords);
1274 node = meshDS->AddNode( coords.X(), coords.Y(), coords.Z() );
1275 meshDS->SetNodeInVolume( node, volumeID );
1277 if ( _computeCanceled )
1280 } // loop on bottom nodes
1285 SMESHDS_SubMesh* smDS = myBlock.SubMeshDS( ID_BOT_FACE );
1286 if ( !smDS ) return toSM( error(COMPERR_BAD_INPUT_MESH, "Null submesh"));
1288 // loop on bottom mesh faces
1289 SMDS_ElemIteratorPtr faceIt = smDS->GetElements();
1290 while ( faceIt->more() )
1292 const SMDS_MeshElement* face = faceIt->next();
1293 if ( !face || face->GetType() != SMDSAbs_Face )
1296 // find node columns for each node
1297 int nbNodes = face->NbCornerNodes();
1298 vector< const TNodeColumn* > columns( nbNodes );
1299 for ( int i = 0; i < nbNodes; ++i )
1301 const SMDS_MeshNode* n = face->GetNode( i );
1302 if ( n->GetPosition()->GetTypeOfPosition() == SMDS_TOP_FACE ) {
1303 TNode2ColumnMap::iterator bot_column = myBotToColumnMap.find( n );
1304 if ( bot_column == myBotToColumnMap.end() )
1305 return toSM( error(TCom("No nodes found above node ") << n->GetID() ));
1306 columns[ i ] = & bot_column->second;
1309 columns[ i ] = myBlock.GetNodeColumn( n );
1310 if ( !columns[ i ] )
1311 return toSM( error(TCom("No side nodes found above node ") << n->GetID() ));
1315 AddPrisms( columns, myHelper );
1317 } // loop on bottom mesh faces
1320 myBotToColumnMap.clear();
1323 // update state of sub-meshes (mostly in order to erase improper errors)
1324 SMESH_subMesh* sm = myHelper->GetMesh()->GetSubMesh( thePrism.myShape3D );
1325 SMESH_subMeshIteratorPtr smIt = sm->getDependsOnIterator(/*includeSelf=*/false);
1326 while ( smIt->more() )
1329 sm->GetComputeError().reset();
1330 sm->ComputeStateEngine( SMESH_subMesh::CHECK_COMPUTE_STATE );
1336 //=======================================================================
1337 //function : computeWalls
1338 //purpose : Compute 2D mesh on walls FACEs of a prism
1339 //=======================================================================
1341 bool StdMeshers_Prism_3D::computeWalls(const Prism_3D::TPrismTopo& thePrism)
1343 SMESH_Mesh* mesh = myHelper->GetMesh();
1344 SMESHDS_Mesh* meshDS = myHelper->GetMeshDS();
1345 DBGOUT( endl << "COMPUTE Prism " << meshDS->ShapeToIndex( thePrism.myShape3D ));
1347 TProjction1dAlgo* projector1D = TProjction1dAlgo::instance( this );
1348 StdMeshers_Quadrangle_2D* quadAlgo = TQuadrangleAlgo::instance( this, myHelper );
1350 // SMESH_HypoFilter hyp1dFilter( SMESH_HypoFilter::IsAlgo(),/*not=*/true);
1351 // hyp1dFilter.And( SMESH_HypoFilter::HasDim( 1 ));
1352 // hyp1dFilter.And( SMESH_HypoFilter::IsMoreLocalThan( thePrism.myShape3D, *mesh ));
1354 // Discretize equally 'vertical' EDGEs
1355 // -----------------------------------
1356 // find source FACE sides for projection: either already computed ones or
1357 // the 'most composite' ones
1358 const size_t nbWalls = thePrism.myWallQuads.size();
1359 vector< int > wgt( nbWalls, 0 ); // "weight" of a wall
1360 for ( size_t iW = 0; iW != nbWalls; ++iW )
1362 Prism_3D::TQuadList::const_iterator quad = thePrism.myWallQuads[iW].begin();
1363 for ( ; quad != thePrism.myWallQuads[iW].end(); ++quad )
1365 StdMeshers_FaceSidePtr lftSide = (*quad)->side[ QUAD_LEFT_SIDE ];
1366 for ( int i = 0; i < lftSide->NbEdges(); ++i )
1369 const TopoDS_Edge& E = lftSide->Edge(i);
1370 if ( mesh->GetSubMesh( E )->IsMeshComputed() )
1373 wgt[ myHelper->WrapIndex( iW+1, nbWalls)] += 10;
1374 wgt[ myHelper->WrapIndex( iW-1, nbWalls)] += 10;
1376 // else if ( mesh->GetHypothesis( E, hyp1dFilter, true )) // local hypothesis!
1380 // in quadratic mesh, pass ignoreMediumNodes to quad sides
1381 if ( myHelper->GetIsQuadratic() )
1383 quad = thePrism.myWallQuads[iW].begin();
1384 for ( ; quad != thePrism.myWallQuads[iW].end(); ++quad )
1385 for ( int i = 0; i < NB_QUAD_SIDES; ++i )
1386 (*quad)->side[ i ].grid->SetIgnoreMediumNodes( true );
1389 multimap< int, int > wgt2quad;
1390 for ( size_t iW = 0; iW != nbWalls; ++iW )
1391 wgt2quad.insert( make_pair( wgt[ iW ], iW ));
1393 // Project 'vertical' EDGEs, from left to right
1394 multimap< int, int >::reverse_iterator w2q = wgt2quad.rbegin();
1395 for ( ; w2q != wgt2quad.rend(); ++w2q )
1397 const int iW = w2q->second;
1398 const Prism_3D::TQuadList& quads = thePrism.myWallQuads[ iW ];
1399 Prism_3D::TQuadList::const_iterator quad = quads.begin();
1400 for ( ; quad != quads.end(); ++quad )
1402 StdMeshers_FaceSidePtr rgtSide = (*quad)->side[ QUAD_RIGHT_SIDE ]; // tgt
1403 StdMeshers_FaceSidePtr lftSide = (*quad)->side[ QUAD_LEFT_SIDE ]; // src
1404 bool swapLeftRight = ( lftSide->NbSegments( /*update=*/true ) == 0 &&
1405 rgtSide->NbSegments( /*update=*/true ) > 0 );
1406 if ( swapLeftRight )
1407 std::swap( lftSide, rgtSide );
1409 // assure that all the source (left) EDGEs are meshed
1410 int nbSrcSegments = 0;
1411 for ( int i = 0; i < lftSide->NbEdges(); ++i )
1413 const TopoDS_Edge& srcE = lftSide->Edge(i);
1414 SMESH_subMesh* srcSM = mesh->GetSubMesh( srcE );
1415 if ( !srcSM->IsMeshComputed() ) {
1416 DBGOUT( "COMPUTE V edge " << srcSM->GetId() );
1417 TopoDS_Edge prpgSrcE = findPropagationSource( srcE );
1418 if ( !prpgSrcE.IsNull() ) {
1419 srcSM->ComputeSubMeshStateEngine( SMESH_subMesh::COMPUTE );
1420 projector1D->myHyp.SetSourceEdge( prpgSrcE );
1421 projector1D->Compute( *mesh, srcE );
1422 srcSM->ComputeStateEngine( SMESH_subMesh::CHECK_COMPUTE_STATE );
1425 srcSM->ComputeSubMeshStateEngine( SMESH_subMesh::COMPUTE );
1426 srcSM->ComputeStateEngine ( SMESH_subMesh::COMPUTE );
1428 if ( !srcSM->IsMeshComputed() )
1429 return toSM( error( "Can't compute 1D mesh" ));
1431 nbSrcSegments += srcSM->GetSubMeshDS()->NbElements();
1433 // check target EDGEs
1434 int nbTgtMeshed = 0, nbTgtSegments = 0;
1435 vector< bool > isTgtEdgeComputed( rgtSide->NbEdges() );
1436 for ( int i = 0; i < rgtSide->NbEdges(); ++i )
1438 const TopoDS_Edge& tgtE = rgtSide->Edge(i);
1439 SMESH_subMesh* tgtSM = mesh->GetSubMesh( tgtE );
1440 if ( !( isTgtEdgeComputed[ i ] = tgtSM->IsMeshComputed() )) {
1441 tgtSM->ComputeSubMeshStateEngine( SMESH_subMesh::COMPUTE );
1442 tgtSM->ComputeStateEngine ( SMESH_subMesh::COMPUTE );
1444 if ( tgtSM->IsMeshComputed() ) {
1446 nbTgtSegments += tgtSM->GetSubMeshDS()->NbElements();
1449 if ( rgtSide->NbEdges() == nbTgtMeshed ) // all tgt EDGEs meshed
1451 if ( nbTgtSegments != nbSrcSegments )
1453 bool badMeshRemoved = false;
1454 // remove just computed segments
1455 for ( int i = 0; i < rgtSide->NbEdges(); ++i )
1456 if ( !isTgtEdgeComputed[ i ])
1458 const TopoDS_Edge& tgtE = rgtSide->Edge(i);
1459 SMESH_subMesh* tgtSM = mesh->GetSubMesh( tgtE );
1460 tgtSM->ComputeStateEngine( SMESH_subMesh::CLEAN );
1461 badMeshRemoved = true;
1464 if ( !badMeshRemoved )
1466 for ( int i = 0; i < lftSide->NbEdges(); ++i )
1467 addBadInputElements( meshDS->MeshElements( lftSide->Edge( i )));
1468 for ( int i = 0; i < rgtSide->NbEdges(); ++i )
1469 addBadInputElements( meshDS->MeshElements( rgtSide->Edge( i )));
1470 return toSM( error( TCom("Different nb of segment on logically vertical edges #")
1471 << shapeID( lftSide->Edge(0) ) << " and #"
1472 << shapeID( rgtSide->Edge(0) ) << ": "
1473 << nbSrcSegments << " != " << nbTgtSegments ));
1476 else // if ( nbTgtSegments == nbSrcSegments )
1481 // Compute 'vertical projection'
1482 if ( nbTgtMeshed == 0 )
1484 // compute nodes on target VERTEXes
1485 const UVPtStructVec& srcNodeStr = lftSide->GetUVPtStruct();
1486 if ( srcNodeStr.size() == 0 )
1487 return toSM( error( TCom("Invalid node positions on edge #") <<
1488 shapeID( lftSide->Edge(0) )));
1489 vector< SMDS_MeshNode* > newNodes( srcNodeStr.size() );
1490 for ( int is2ndV = 0; is2ndV < 2; ++is2ndV )
1492 const TopoDS_Edge& E = rgtSide->Edge( is2ndV ? rgtSide->NbEdges()-1 : 0 );
1493 TopoDS_Vertex v = myHelper->IthVertex( is2ndV, E );
1494 mesh->GetSubMesh( v )->ComputeStateEngine( SMESH_subMesh::COMPUTE );
1495 const SMDS_MeshNode* n = SMESH_Algo::VertexNode( v, meshDS );
1496 newNodes[ is2ndV ? 0 : newNodes.size()-1 ] = (SMDS_MeshNode*) n;
1499 // compute nodes on target EDGEs
1500 DBGOUT( "COMPUTE V edge (proj) " << shapeID( lftSide->Edge(0)));
1501 rgtSide->Reverse(); // direct it same as the lftSide
1502 myHelper->SetElementsOnShape( false ); // myHelper holds the prism shape
1503 TopoDS_Edge tgtEdge;
1504 for ( size_t iN = 1; iN < srcNodeStr.size()-1; ++iN ) // add nodes
1506 gp_Pnt p = rgtSide->Value3d ( srcNodeStr[ iN ].normParam );
1507 double u = rgtSide->Parameter( srcNodeStr[ iN ].normParam, tgtEdge );
1508 newNodes[ iN ] = meshDS->AddNode( p.X(), p.Y(), p.Z() );
1509 meshDS->SetNodeOnEdge( newNodes[ iN ], tgtEdge, u );
1511 for ( size_t iN = 1; iN < srcNodeStr.size(); ++iN ) // add segments
1513 // find an EDGE to set a new segment
1514 std::pair<int, TopAbs_ShapeEnum> id2type =
1515 myHelper->GetMediumPos( newNodes[ iN-1 ], newNodes[ iN ] );
1516 if ( id2type.second != TopAbs_EDGE )
1518 // new nodes are on different EDGEs; put one of them on VERTEX
1519 const int edgeIndex = rgtSide->EdgeIndex( srcNodeStr[ iN-1 ].normParam );
1520 const double vertexParam = rgtSide->LastParameter( edgeIndex );
1521 TopoDS_Vertex vertex = rgtSide->LastVertex( edgeIndex );
1522 const SMDS_MeshNode* vn = SMESH_Algo::VertexNode( vertex, meshDS );
1523 const gp_Pnt p = BRep_Tool::Pnt( vertex );
1524 const int isPrev = ( Abs( srcNodeStr[ iN-1 ].normParam - vertexParam ) <
1525 Abs( srcNodeStr[ iN ].normParam - vertexParam ));
1526 meshDS->UnSetNodeOnShape( newNodes[ iN-isPrev ] );
1527 meshDS->SetNodeOnVertex ( newNodes[ iN-isPrev ], vertex );
1528 meshDS->MoveNode ( newNodes[ iN-isPrev ], p.X(), p.Y(), p.Z() );
1529 id2type.first = newNodes[ iN-(1-isPrev) ]->getshapeId();
1532 SMESH_MeshEditor::TListOfListOfNodes lln( 1, list< const SMDS_MeshNode* >() );
1533 lln.back().push_back ( vn );
1534 lln.back().push_front( newNodes[ iN-isPrev ] ); // to keep
1535 SMESH_MeshEditor( mesh ).MergeNodes( lln );
1538 SMDS_MeshElement* newEdge = myHelper->AddEdge( newNodes[ iN-1 ], newNodes[ iN ] );
1539 meshDS->SetMeshElementOnShape( newEdge, id2type.first );
1541 myHelper->SetElementsOnShape( true );
1542 for ( int i = 0; i < rgtSide->NbEdges(); ++i ) // update state of sub-meshes
1544 const TopoDS_Edge& E = rgtSide->Edge( i );
1545 SMESH_subMesh* tgtSM = mesh->GetSubMesh( E );
1546 tgtSM->ComputeStateEngine( SMESH_subMesh::CHECK_COMPUTE_STATE );
1549 // to continue projection from the just computed side as a source
1550 if ( !swapLeftRight && rgtSide->NbEdges() > 1 && w2q->second == iW )
1552 std::pair<int,int> wgt2quadKeyVal( w2q->first + 1, thePrism.myRightQuadIndex[ iW ]);
1553 wgt2quad.insert( wgt2quadKeyVal ); // it will be skipped by ++w2q
1554 wgt2quad.insert( wgt2quadKeyVal );
1555 w2q = wgt2quad.rbegin();
1560 // HOPE assigned hypotheses are OK, so that equal nb of segments will be generated
1561 //return toSM( error("Partial projection not implemented"));
1563 } // loop on quads of a composite wall side
1564 } // loop on the ordered wall sides
1568 for ( size_t iW = 0; iW != thePrism.myWallQuads.size(); ++iW )
1570 Prism_3D::TQuadList::const_iterator quad = thePrism.myWallQuads[iW].begin();
1571 for ( ; quad != thePrism.myWallQuads[iW].end(); ++quad )
1573 const TopoDS_Face& face = (*quad)->face;
1574 SMESH_subMesh* fSM = mesh->GetSubMesh( face );
1575 if ( ! fSM->IsMeshComputed() )
1577 // Top EDGEs must be projections from the bottom ones
1578 // to compute stuctured quad mesh on wall FACEs
1579 // ---------------------------------------------------
1580 const TopoDS_Edge& botE = (*quad)->side[ QUAD_BOTTOM_SIDE ].grid->Edge(0);
1581 const TopoDS_Edge& topE = (*quad)->side[ QUAD_TOP_SIDE ].grid->Edge(0);
1582 SMESH_subMesh* botSM = mesh->GetSubMesh( botE );
1583 SMESH_subMesh* topSM = mesh->GetSubMesh( topE );
1584 SMESH_subMesh* srcSM = botSM;
1585 SMESH_subMesh* tgtSM = topSM;
1586 srcSM->ComputeStateEngine( SMESH_subMesh::CHECK_COMPUTE_STATE );
1587 tgtSM->ComputeStateEngine( SMESH_subMesh::CHECK_COMPUTE_STATE );
1588 if ( !srcSM->IsMeshComputed() && tgtSM->IsMeshComputed() )
1589 std::swap( srcSM, tgtSM );
1591 if ( !srcSM->IsMeshComputed() )
1593 DBGOUT( "COMPUTE H edge " << srcSM->GetId());
1594 srcSM->ComputeSubMeshStateEngine( SMESH_subMesh::COMPUTE ); // nodes on VERTEXes
1595 srcSM->ComputeStateEngine( SMESH_subMesh::COMPUTE ); // segments on the EDGE
1598 if ( tgtSM->IsMeshComputed() &&
1599 tgtSM->GetSubMeshDS()->NbNodes() != srcSM->GetSubMeshDS()->NbNodes() )
1601 // the top EDGE is computed differently than the bottom one,
1602 // try to clear a wrong mesh
1603 bool isAdjFaceMeshed = false;
1604 PShapeIteratorPtr fIt = myHelper->GetAncestors( tgtSM->GetSubShape(),
1605 *mesh, TopAbs_FACE );
1606 while ( const TopoDS_Shape* f = fIt->next() )
1607 if (( isAdjFaceMeshed = mesh->GetSubMesh( *f )->IsMeshComputed() ))
1609 if ( isAdjFaceMeshed )
1610 return toSM( error( TCom("Different nb of segment on logically horizontal edges #")
1611 << shapeID( botE ) << " and #"
1612 << shapeID( topE ) << ": "
1613 << tgtSM->GetSubMeshDS()->NbElements() << " != "
1614 << srcSM->GetSubMeshDS()->NbElements() ));
1615 tgtSM->ComputeStateEngine( SMESH_subMesh::CLEAN );
1617 if ( !tgtSM->IsMeshComputed() )
1619 // compute nodes on VERTEXes
1620 SMESH_subMeshIteratorPtr smIt = tgtSM->getDependsOnIterator(/*includeSelf=*/false);
1621 while ( smIt->more() )
1622 smIt->next()->ComputeStateEngine( SMESH_subMesh::COMPUTE );
1624 DBGOUT( "COMPUTE H edge (proj) " << tgtSM->GetId());
1625 projector1D->myHyp.SetSourceEdge( TopoDS::Edge( srcSM->GetSubShape() ));
1626 projector1D->InitComputeError();
1627 bool ok = projector1D->Compute( *mesh, tgtSM->GetSubShape() );
1630 SMESH_ComputeErrorPtr err = projector1D->GetComputeError();
1631 if ( err->IsOK() ) err->myName = COMPERR_ALGO_FAILED;
1632 tgtSM->GetComputeError() = err;
1636 tgtSM->ComputeStateEngine( SMESH_subMesh::CHECK_COMPUTE_STATE );
1639 // Compute quad mesh on wall FACEs
1640 // -------------------------------
1642 // make all EDGES meshed
1643 fSM->ComputeSubMeshStateEngine( SMESH_subMesh::COMPUTE );
1644 if ( !fSM->SubMeshesComputed() )
1645 return toSM( error( COMPERR_BAD_INPUT_MESH,
1646 "Not all edges have valid algorithm and hypothesis"));
1648 quadAlgo->InitComputeError();
1649 DBGOUT( "COMPUTE Quad face " << fSM->GetId());
1650 bool ok = quadAlgo->Compute( *mesh, face );
1651 fSM->GetComputeError() = quadAlgo->GetComputeError();
1654 fSM->ComputeStateEngine( SMESH_subMesh::CHECK_COMPUTE_STATE );
1656 if ( myHelper->GetIsQuadratic() )
1658 // fill myHelper with medium nodes built by quadAlgo
1659 SMDS_ElemIteratorPtr fIt = fSM->GetSubMeshDS()->GetElements();
1660 while ( fIt->more() )
1661 myHelper->AddTLinks( dynamic_cast<const SMDS_MeshFace*>( fIt->next() ));
1669 //=======================================================================
1671 * \brief Returns a source EDGE of propagation to a given EDGE
1673 //=======================================================================
1675 TopoDS_Edge StdMeshers_Prism_3D::findPropagationSource( const TopoDS_Edge& E )
1677 if ( myPropagChains )
1678 for ( size_t i = 0; !myPropagChains[i].IsEmpty(); ++i )
1679 if ( myPropagChains[i].Contains( E ))
1680 return TopoDS::Edge( myPropagChains[i].FindKey( 1 ));
1682 return TopoDS_Edge();
1685 //=======================================================================
1686 //function : Evaluate
1688 //=======================================================================
1690 bool StdMeshers_Prism_3D::Evaluate(SMESH_Mesh& theMesh,
1691 const TopoDS_Shape& theShape,
1692 MapShapeNbElems& aResMap)
1694 if ( theShape.ShapeType() == TopAbs_COMPOUND )
1697 for ( TopoDS_Iterator it( theShape ); it.More(); it.Next() )
1698 ok &= Evaluate( theMesh, it.Value(), aResMap );
1701 SMESH_MesherHelper helper( theMesh );
1703 myHelper->SetSubShape( theShape );
1705 // find face contains only triangles
1706 vector < SMESH_subMesh * >meshFaces;
1707 TopTools_SequenceOfShape aFaces;
1708 int NumBase = 0, i = 0, NbQFs = 0;
1709 for (TopExp_Explorer exp(theShape, TopAbs_FACE); exp.More(); exp.Next()) {
1711 aFaces.Append(exp.Current());
1712 SMESH_subMesh *aSubMesh = theMesh.GetSubMesh(exp.Current());
1713 meshFaces.push_back(aSubMesh);
1714 MapShapeNbElemsItr anIt = aResMap.find(meshFaces[i-1]);
1715 if( anIt==aResMap.end() )
1716 return toSM( error( "Submesh can not be evaluated"));
1718 std::vector<int> aVec = (*anIt).second;
1719 int nbtri = Max(aVec[SMDSEntity_Triangle],aVec[SMDSEntity_Quad_Triangle]);
1720 int nbqua = Max(aVec[SMDSEntity_Quadrangle],aVec[SMDSEntity_Quad_Quadrangle]);
1721 if( nbtri==0 && nbqua>0 ) {
1730 std::vector<int> aResVec(SMDSEntity_Last);
1731 for(int i=SMDSEntity_Node; i<SMDSEntity_Last; i++) aResVec[i] = 0;
1732 SMESH_subMesh * sm = theMesh.GetSubMesh(theShape);
1733 aResMap.insert(std::make_pair(sm,aResVec));
1734 return toSM( error( "Submesh can not be evaluated" ));
1737 if(NumBase==0) NumBase = 1; // only quads => set 1 faces as base
1739 // find number of 1d elems for base face
1741 TopTools_MapOfShape Edges1;
1742 for (TopExp_Explorer exp(aFaces.Value(NumBase), TopAbs_EDGE); exp.More(); exp.Next()) {
1743 Edges1.Add(exp.Current());
1744 SMESH_subMesh *sm = theMesh.GetSubMesh(exp.Current());
1746 MapShapeNbElemsItr anIt = aResMap.find(sm);
1747 if( anIt == aResMap.end() ) continue;
1748 std::vector<int> aVec = (*anIt).second;
1749 nb1d += Max(aVec[SMDSEntity_Edge],aVec[SMDSEntity_Quad_Edge]);
1752 // find face opposite to base face
1754 for(i=1; i<=6; i++) {
1755 if(i==NumBase) continue;
1756 bool IsOpposite = true;
1757 for(TopExp_Explorer exp(aFaces.Value(i), TopAbs_EDGE); exp.More(); exp.Next()) {
1758 if( Edges1.Contains(exp.Current()) ) {
1768 // find number of 2d elems on side faces
1770 for(i=1; i<=6; i++) {
1771 if( i==OppNum || i==NumBase ) continue;
1772 MapShapeNbElemsItr anIt = aResMap.find( meshFaces[i-1] );
1773 if( anIt == aResMap.end() ) continue;
1774 std::vector<int> aVec = (*anIt).second;
1775 nb2d += Max(aVec[SMDSEntity_Quadrangle],aVec[SMDSEntity_Quad_Quadrangle]);
1778 MapShapeNbElemsItr anIt = aResMap.find( meshFaces[NumBase-1] );
1779 std::vector<int> aVec = (*anIt).second;
1780 bool IsQuadratic = (aVec[SMDSEntity_Quad_Triangle]>aVec[SMDSEntity_Triangle]) ||
1781 (aVec[SMDSEntity_Quad_Quadrangle]>aVec[SMDSEntity_Quadrangle]);
1782 int nb2d_face0_3 = Max(aVec[SMDSEntity_Triangle],aVec[SMDSEntity_Quad_Triangle]);
1783 int nb2d_face0_4 = Max(aVec[SMDSEntity_Quadrangle],aVec[SMDSEntity_Quad_Quadrangle]);
1784 int nb0d_face0 = aVec[SMDSEntity_Node];
1785 int nb1d_face0_int = ( nb2d_face0_3*3 + nb2d_face0_4*4 - nb1d ) / 2;
1787 std::vector<int> aResVec(SMDSEntity_Last);
1788 for(int i=SMDSEntity_Node; i<SMDSEntity_Last; i++) aResVec[i] = 0;
1790 aResVec[SMDSEntity_Quad_Penta] = nb2d_face0_3 * ( nb2d/nb1d );
1791 aResVec[SMDSEntity_Quad_Hexa] = nb2d_face0_4 * ( nb2d/nb1d );
1792 aResVec[SMDSEntity_Node] = nb0d_face0 * ( 2*nb2d/nb1d - 1 ) - nb1d_face0_int * nb2d/nb1d;
1795 aResVec[SMDSEntity_Node] = nb0d_face0 * ( nb2d/nb1d - 1 );
1796 aResVec[SMDSEntity_Penta] = nb2d_face0_3 * ( nb2d/nb1d );
1797 aResVec[SMDSEntity_Hexa] = nb2d_face0_4 * ( nb2d/nb1d );
1799 SMESH_subMesh * sm = theMesh.GetSubMesh(theShape);
1800 aResMap.insert(std::make_pair(sm,aResVec));
1805 //================================================================================
1807 * \brief Create prisms
1808 * \param columns - columns of nodes generated from nodes of a mesh face
1809 * \param helper - helper initialized by mesh and shape to add prisms to
1811 //================================================================================
1813 void StdMeshers_Prism_3D::AddPrisms( vector<const TNodeColumn*> & columns,
1814 SMESH_MesherHelper* helper)
1816 int nbNodes = columns.size();
1817 int nbZ = columns[0]->size();
1818 if ( nbZ < 2 ) return;
1820 // find out orientation
1821 bool isForward = true;
1822 SMDS_VolumeTool vTool;
1824 switch ( nbNodes ) {
1826 SMDS_VolumeOfNodes tmpPenta ( (*columns[0])[z-1], // bottom
1829 (*columns[0])[z], // top
1832 vTool.Set( &tmpPenta );
1833 isForward = vTool.IsForward();
1837 SMDS_VolumeOfNodes tmpHex( (*columns[0])[z-1], (*columns[1])[z-1], // bottom
1838 (*columns[2])[z-1], (*columns[3])[z-1],
1839 (*columns[0])[z], (*columns[1])[z], // top
1840 (*columns[2])[z], (*columns[3])[z] );
1841 vTool.Set( &tmpHex );
1842 isForward = vTool.IsForward();
1846 const int di = (nbNodes+1) / 3;
1847 SMDS_VolumeOfNodes tmpVol ( (*columns[0] )[z-1],
1848 (*columns[di] )[z-1],
1849 (*columns[2*di])[z-1],
1852 (*columns[2*di])[z] );
1853 vTool.Set( &tmpVol );
1854 isForward = vTool.IsForward();
1857 // vertical loop on columns
1859 helper->SetElementsOnShape( true );
1861 switch ( nbNodes ) {
1863 case 3: { // ---------- pentahedra
1864 const int i1 = isForward ? 1 : 2;
1865 const int i2 = isForward ? 2 : 1;
1866 for ( z = 1; z < nbZ; ++z )
1867 helper->AddVolume( (*columns[0 ])[z-1], // bottom
1868 (*columns[i1])[z-1],
1869 (*columns[i2])[z-1],
1870 (*columns[0 ])[z], // top
1872 (*columns[i2])[z] );
1875 case 4: { // ---------- hexahedra
1876 const int i1 = isForward ? 1 : 3;
1877 const int i3 = isForward ? 3 : 1;
1878 for ( z = 1; z < nbZ; ++z )
1879 helper->AddVolume( (*columns[0])[z-1], (*columns[i1])[z-1], // bottom
1880 (*columns[2])[z-1], (*columns[i3])[z-1],
1881 (*columns[0])[z], (*columns[i1])[z], // top
1882 (*columns[2])[z], (*columns[i3])[z] );
1885 case 6: { // ---------- octahedra
1886 const int iBase1 = isForward ? -1 : 0;
1887 const int iBase2 = isForward ? 0 :-1;
1888 for ( z = 1; z < nbZ; ++z )
1889 helper->AddVolume( (*columns[0])[z+iBase1], (*columns[1])[z+iBase1], // bottom or top
1890 (*columns[2])[z+iBase1], (*columns[3])[z+iBase1],
1891 (*columns[4])[z+iBase1], (*columns[5])[z+iBase1],
1892 (*columns[0])[z+iBase2], (*columns[1])[z+iBase2], // top or bottom
1893 (*columns[2])[z+iBase2], (*columns[3])[z+iBase2],
1894 (*columns[4])[z+iBase2], (*columns[5])[z+iBase2] );
1897 default: // ---------- polyhedra
1898 vector<int> quantities( 2 + nbNodes, 4 );
1899 quantities[0] = quantities[1] = nbNodes;
1900 columns.resize( nbNodes + 1 );
1901 columns[ nbNodes ] = columns[ 0 ];
1902 const int i1 = isForward ? 1 : 3;
1903 const int i3 = isForward ? 3 : 1;
1904 const int iBase1 = isForward ? -1 : 0;
1905 const int iBase2 = isForward ? 0 :-1;
1906 vector<const SMDS_MeshNode*> nodes( 2*nbNodes + 4*nbNodes);
1907 for ( z = 1; z < nbZ; ++z )
1909 for ( int i = 0; i < nbNodes; ++i ) {
1910 nodes[ i ] = (*columns[ i ])[z+iBase1]; // bottom or top
1911 nodes[ 2*nbNodes-i-1 ] = (*columns[ i ])[z+iBase2]; // top or bottom
1913 int di = 2*nbNodes + 4*i;
1914 nodes[ di+0 ] = (*columns[i ])[z ];
1915 nodes[ di+i1] = (*columns[i+1])[z ];
1916 nodes[ di+2 ] = (*columns[i+1])[z-1];
1917 nodes[ di+i3] = (*columns[i ])[z-1];
1919 helper->AddPolyhedralVolume( nodes, quantities );
1922 } // switch ( nbNodes )
1925 //================================================================================
1927 * \brief Find correspondence between bottom and top nodes
1928 * If elements on the bottom and top faces are topologically different,
1929 * and projection is possible and allowed, perform the projection
1930 * \retval bool - is a success or not
1932 //================================================================================
1934 bool StdMeshers_Prism_3D::assocOrProjBottom2Top( const gp_Trsf & bottomToTopTrsf,
1935 const Prism_3D::TPrismTopo& thePrism)
1937 SMESH_subMesh * botSM = myHelper->GetMesh()->GetSubMesh( thePrism.myBottom );
1938 SMESH_subMesh * topSM = myHelper->GetMesh()->GetSubMesh( thePrism.myTop );
1940 SMESHDS_SubMesh * botSMDS = botSM->GetSubMeshDS();
1941 SMESHDS_SubMesh * topSMDS = topSM->GetSubMeshDS();
1943 if ( !botSMDS || botSMDS->NbElements() == 0 )
1945 _gen->Compute( *myHelper->GetMesh(), botSM->GetSubShape(), /*aShapeOnly=*/true );
1946 botSMDS = botSM->GetSubMeshDS();
1947 if ( !botSMDS || botSMDS->NbElements() == 0 )
1948 return toSM( error(TCom("No elements on face #") << botSM->GetId() ));
1951 bool needProject = !topSM->IsMeshComputed();
1952 if ( !needProject &&
1953 (botSMDS->NbElements() != topSMDS->NbElements() ||
1954 botSMDS->NbNodes() != topSMDS->NbNodes()))
1956 MESSAGE("nb elem bot " << botSMDS->NbElements() <<
1957 " top " << ( topSMDS ? topSMDS->NbElements() : 0 ));
1958 MESSAGE("nb node bot " << botSMDS->NbNodes() <<
1959 " top " << ( topSMDS ? topSMDS->NbNodes() : 0 ));
1960 return toSM( error(TCom("Mesh on faces #") << botSM->GetId()
1961 <<" and #"<< topSM->GetId() << " seems different" ));
1964 if ( 0/*needProject && !myProjectTriangles*/ )
1965 return toSM( error(TCom("Mesh on faces #") << botSM->GetId()
1966 <<" and #"<< topSM->GetId() << " seems different" ));
1967 ///RETURN_BAD_RESULT("Need to project but not allowed");
1969 NSProjUtils::TNodeNodeMap n2nMap;
1970 const NSProjUtils::TNodeNodeMap* n2nMapPtr = & n2nMap;
1973 if ( !projectBottomToTop( bottomToTopTrsf, thePrism ))
1975 n2nMapPtr = & TProjction2dAlgo::instance( this )->GetNodesMap();
1978 if ( !n2nMapPtr || n2nMapPtr->size() < botSMDS->NbNodes() )
1980 // associate top and bottom faces
1981 NSProjUtils::TShapeShapeMap shape2ShapeMap;
1982 const bool sameTopo =
1983 NSProjUtils::FindSubShapeAssociation( thePrism.myBottom, myHelper->GetMesh(),
1984 thePrism.myTop, myHelper->GetMesh(),
1987 for ( size_t iQ = 0; iQ < thePrism.myWallQuads.size(); ++iQ )
1989 const Prism_3D::TQuadList& quadList = thePrism.myWallQuads[iQ];
1990 StdMeshers_FaceSidePtr botSide = quadList.front()->side[ QUAD_BOTTOM_SIDE ];
1991 StdMeshers_FaceSidePtr topSide = quadList.back ()->side[ QUAD_TOP_SIDE ];
1992 if ( botSide->NbEdges() == topSide->NbEdges() )
1994 for ( int iE = 0; iE < botSide->NbEdges(); ++iE )
1996 NSProjUtils::InsertAssociation( botSide->Edge( iE ),
1997 topSide->Edge( iE ), shape2ShapeMap );
1998 NSProjUtils::InsertAssociation( myHelper->IthVertex( 0, botSide->Edge( iE )),
1999 myHelper->IthVertex( 0, topSide->Edge( iE )),
2005 TopoDS_Vertex vb, vt;
2006 StdMeshers_FaceSidePtr sideB, sideT;
2007 vb = myHelper->IthVertex( 0, botSide->Edge( 0 ));
2008 vt = myHelper->IthVertex( 0, topSide->Edge( 0 ));
2009 sideB = quadList.front()->side[ QUAD_LEFT_SIDE ];
2010 sideT = quadList.back ()->side[ QUAD_LEFT_SIDE ];
2011 if ( vb.IsSame( sideB->FirstVertex() ) &&
2012 vt.IsSame( sideT->LastVertex() ))
2014 NSProjUtils::InsertAssociation( botSide->Edge( 0 ),
2015 topSide->Edge( 0 ), shape2ShapeMap );
2016 NSProjUtils::InsertAssociation( vb, vt, shape2ShapeMap );
2018 vb = myHelper->IthVertex( 1, botSide->Edge( botSide->NbEdges()-1 ));
2019 vt = myHelper->IthVertex( 1, topSide->Edge( topSide->NbEdges()-1 ));
2020 sideB = quadList.front()->side[ QUAD_RIGHT_SIDE ];
2021 sideT = quadList.back ()->side[ QUAD_RIGHT_SIDE ];
2022 if ( vb.IsSame( sideB->FirstVertex() ) &&
2023 vt.IsSame( sideT->LastVertex() ))
2025 NSProjUtils::InsertAssociation( botSide->Edge( botSide->NbEdges()-1 ),
2026 topSide->Edge( topSide->NbEdges()-1 ),
2028 NSProjUtils::InsertAssociation( vb, vt, shape2ShapeMap );
2033 // Find matching nodes of top and bottom faces
2034 n2nMapPtr = & n2nMap;
2035 if ( ! NSProjUtils::FindMatchingNodesOnFaces( thePrism.myBottom, myHelper->GetMesh(),
2036 thePrism.myTop, myHelper->GetMesh(),
2037 shape2ShapeMap, n2nMap ))
2040 return toSM( error(TCom("Mesh on faces #") << botSM->GetId()
2041 <<" and #"<< topSM->GetId() << " seems different" ));
2043 return toSM( error(TCom("Topology of faces #") << botSM->GetId()
2044 <<" and #"<< topSM->GetId() << " seems different" ));
2048 // Fill myBotToColumnMap
2050 int zSize = myBlock.VerticalSize();
2051 TNodeNodeMap::const_iterator bN_tN = n2nMapPtr->begin();
2052 for ( ; bN_tN != n2nMapPtr->end(); ++bN_tN )
2054 const SMDS_MeshNode* botNode = bN_tN->first;
2055 const SMDS_MeshNode* topNode = bN_tN->second;
2056 if ( botNode->GetPosition()->GetTypeOfPosition() != SMDS_TOP_FACE )
2057 continue; // wall columns are contained in myBlock
2058 // create node column
2059 Prism_3D::TNode bN( botNode );
2060 TNode2ColumnMap::iterator bN_col =
2061 myBotToColumnMap.insert( make_pair ( bN, TNodeColumn() )).first;
2062 TNodeColumn & column = bN_col->second;
2063 column.resize( zSize );
2064 column.front() = botNode;
2065 column.back() = topNode;
2070 //================================================================================
2072 * \brief Remove faces from the top face and re-create them by projection from the bottom
2073 * \retval bool - a success or not
2075 //================================================================================
2077 bool StdMeshers_Prism_3D::projectBottomToTop( const gp_Trsf & bottomToTopTrsf,
2078 const Prism_3D::TPrismTopo& thePrism )
2080 if ( project2dMesh( thePrism.myBottom, thePrism.myTop ))
2084 NSProjUtils::TNodeNodeMap& n2nMap =
2085 (NSProjUtils::TNodeNodeMap&) TProjction2dAlgo::instance( this )->GetNodesMap();
2090 SMESHDS_Mesh* meshDS = myHelper->GetMeshDS();
2091 SMESH_subMesh * botSM = myHelper->GetMesh()->GetSubMesh( thePrism.myBottom );
2092 SMESH_subMesh * topSM = myHelper->GetMesh()->GetSubMesh( thePrism.myTop );
2094 SMESHDS_SubMesh * botSMDS = botSM->GetSubMeshDS();
2095 SMESHDS_SubMesh * topSMDS = topSM->GetSubMeshDS();
2097 if ( topSMDS && topSMDS->NbElements() > 0 )
2099 //topSM->ComputeStateEngine( SMESH_subMesh::CLEAN ); -- avoid propagation of events
2100 for ( SMDS_ElemIteratorPtr eIt = topSMDS->GetElements(); eIt->more(); )
2101 meshDS->RemoveFreeElement( eIt->next(), topSMDS, /*fromGroups=*/false );
2102 for ( SMDS_NodeIteratorPtr nIt = topSMDS->GetNodes(); nIt->more(); )
2103 meshDS->RemoveFreeNode( nIt->next(), topSMDS, /*fromGroups=*/false );
2106 const TopoDS_Face& botFace = thePrism.myBottom; // oriented within
2107 const TopoDS_Face& topFace = thePrism.myTop; // the 3D SHAPE
2108 int topFaceID = meshDS->ShapeToIndex( thePrism.myTop );
2110 SMESH_MesherHelper botHelper( *myHelper->GetMesh() );
2111 botHelper.SetSubShape( botFace );
2112 botHelper.ToFixNodeParameters( true );
2114 SMESH_MesherHelper topHelper( *myHelper->GetMesh() );
2115 topHelper.SetSubShape( topFace );
2116 topHelper.ToFixNodeParameters( true );
2117 double distXYZ[4], fixTol = 10 * topHelper.MaxTolerance( topFace );
2119 // Fill myBotToColumnMap
2121 int zSize = myBlock.VerticalSize();
2122 Prism_3D::TNode prevTNode;
2123 SMDS_NodeIteratorPtr nIt = botSMDS->GetNodes();
2124 while ( nIt->more() )
2126 const SMDS_MeshNode* botNode = nIt->next();
2127 const SMDS_MeshNode* topNode = 0;
2128 if ( botNode->GetPosition()->GetTypeOfPosition() != SMDS_TOP_FACE )
2129 continue; // strange
2131 Prism_3D::TNode bN( botNode );
2132 if ( bottomToTopTrsf.Form() == gp_Identity )
2134 // compute bottom node params
2135 gp_XYZ paramHint(-1,-1,-1);
2136 if ( prevTNode.IsNeighbor( bN ))
2138 paramHint = prevTNode.GetParams();
2139 // double tol = 1e-2 * ( prevTNode.GetCoords() - bN.GetCoords() ).Modulus();
2140 // myBlock.SetTolerance( Min( myBlock.GetTolerance(), tol ));
2142 if ( !myBlock.ComputeParameters( bN.GetCoords(), bN.ChangeParams(),
2143 ID_BOT_FACE, paramHint ))
2144 return toSM( error(TCom("Can't compute normalized parameters for node ")
2145 << botNode->GetID() << " on the face #"<< botSM->GetId() ));
2147 // compute top node coords
2148 gp_XYZ topXYZ; gp_XY topUV;
2149 if ( !myBlock.FacePoint( ID_TOP_FACE, bN.GetParams(), topXYZ ) ||
2150 !myBlock.FaceUV ( ID_TOP_FACE, bN.GetParams(), topUV ))
2151 return toSM( error(TCom("Can't compute coordinates "
2152 "by normalized parameters on the face #")<< topSM->GetId() ));
2153 topNode = meshDS->AddNode( topXYZ.X(),topXYZ.Y(),topXYZ.Z() );
2154 meshDS->SetNodeOnFace( topNode, topFaceID, topUV.X(), topUV.Y() );
2156 else // use bottomToTopTrsf
2158 gp_XYZ coords = bN.GetCoords();
2159 bottomToTopTrsf.Transforms( coords );
2160 topNode = meshDS->AddNode( coords.X(), coords.Y(), coords.Z() );
2161 gp_XY topUV = botHelper.GetNodeUV( botFace, botNode, 0, &checkUV );
2162 meshDS->SetNodeOnFace( topNode, topFaceID, topUV.X(), topUV.Y() );
2164 if ( topHelper.CheckNodeUV( topFace, topNode, topUV, fixTol, /*force=*/false, distXYZ ) &&
2165 distXYZ[0] > fixTol && distXYZ[0] < fixTol * 1e+3 )
2166 meshDS->MoveNode( topNode, distXYZ[1], distXYZ[2], distXYZ[3] ); // transform can be inaccurate
2168 // create node column
2169 TNode2ColumnMap::iterator bN_col =
2170 myBotToColumnMap.insert( make_pair ( bN, TNodeColumn() )).first;
2171 TNodeColumn & column = bN_col->second;
2172 column.resize( zSize );
2173 column.front() = botNode;
2174 column.back() = topNode;
2176 n2nMap.insert( n2nMap.end(), make_pair( botNode, topNode ));
2178 if ( _computeCanceled )
2179 return toSM( error( SMESH_ComputeError::New(COMPERR_CANCELED)));
2184 const bool oldSetElemsOnShape = myHelper->SetElementsOnShape( false );
2186 // care of orientation;
2187 // if the bottom faces is orienetd OK then top faces must be reversed
2188 bool reverseTop = true;
2189 if ( myHelper->NbAncestors( botFace, *myBlock.Mesh(), TopAbs_SOLID ) > 1 )
2190 reverseTop = ! myHelper->IsReversedSubMesh( botFace );
2191 int iFrw, iRev, *iPtr = &( reverseTop ? iRev : iFrw );
2193 // loop on bottom mesh faces
2194 SMDS_ElemIteratorPtr faceIt = botSMDS->GetElements();
2195 vector< const SMDS_MeshNode* > nodes;
2196 while ( faceIt->more() )
2198 const SMDS_MeshElement* face = faceIt->next();
2199 if ( !face || face->GetType() != SMDSAbs_Face )
2202 // find top node in columns for each bottom node
2203 int nbNodes = face->NbCornerNodes();
2204 nodes.resize( nbNodes );
2205 for ( iFrw = 0, iRev = nbNodes-1; iFrw < nbNodes; ++iFrw, --iRev )
2207 const SMDS_MeshNode* n = face->GetNode( *iPtr );
2208 if ( n->GetPosition()->GetTypeOfPosition() == SMDS_TOP_FACE ) {
2209 TNode2ColumnMap::iterator bot_column = myBotToColumnMap.find( n );
2210 if ( bot_column == myBotToColumnMap.end() )
2211 return toSM( error(TCom("No nodes found above node ") << n->GetID() ));
2212 nodes[ iFrw ] = bot_column->second.back();
2215 const TNodeColumn* column = myBlock.GetNodeColumn( n );
2217 return toSM( error(TCom("No side nodes found above node ") << n->GetID() ));
2218 nodes[ iFrw ] = column->back();
2221 SMDS_MeshElement* newFace = 0;
2222 switch ( nbNodes ) {
2225 newFace = myHelper->AddFace(nodes[0], nodes[1], nodes[2]);
2229 newFace = myHelper->AddFace( nodes[0], nodes[1], nodes[2], nodes[3] );
2233 newFace = meshDS->AddPolygonalFace( nodes );
2236 meshDS->SetMeshElementOnShape( newFace, topFaceID );
2239 myHelper->SetElementsOnShape( oldSetElemsOnShape );
2241 // Check the projected mesh
2243 if ( thePrism.myNbEdgesInWires.size() > 1 && // there are holes
2244 topHelper.IsDistorted2D( topSM, /*checkUV=*/false ))
2246 SMESH_MeshEditor editor( topHelper.GetMesh() );
2248 // smooth in 2D or 3D?
2249 TopLoc_Location loc;
2250 Handle(Geom_Surface) surface = BRep_Tool::Surface( topFace, loc );
2251 bool isPlanar = GeomLib_IsPlanarSurface( surface ).IsPlanar();
2253 bool isFixed = false;
2254 set<const SMDS_MeshNode*> fixedNodes;
2255 for ( int iAttemp = 0; !isFixed && iAttemp < 10; ++iAttemp )
2257 TIDSortedElemSet faces;
2258 for ( faceIt = topSMDS->GetElements(); faceIt->more(); )
2259 faces.insert( faces.end(), faceIt->next() );
2261 SMESH_MeshEditor::SmoothMethod algo =
2262 iAttemp ? SMESH_MeshEditor::CENTROIDAL : SMESH_MeshEditor::LAPLACIAN;
2265 editor.Smooth( faces, fixedNodes, algo, /*nbIterations=*/ 10,
2266 /*theTgtAspectRatio=*/1.0, /*the2D=*/!isPlanar);
2268 isFixed = !topHelper.IsDistorted2D( topSM, /*checkUV=*/true );
2271 return toSM( error( TCom("Projection from face #") << botSM->GetId()
2272 << " to face #" << topSM->GetId()
2273 << " failed: inverted elements created"));
2279 //=======================================================================
2280 //function : getSweepTolerance
2281 //purpose : Compute tolerance to pass to StdMeshers_Sweeper
2282 //=======================================================================
2284 double StdMeshers_Prism_3D::getSweepTolerance( const Prism_3D::TPrismTopo& thePrism )
2286 SMESHDS_Mesh* meshDS = myHelper->GetMeshDS();
2287 SMESHDS_SubMesh * sm[2] = { meshDS->MeshElements( thePrism.myBottom ),
2288 meshDS->MeshElements( thePrism.myTop ) };
2289 double minDist = 1e100;
2291 vector< SMESH_TNodeXYZ > nodes;
2292 for ( int iSM = 0; iSM < 2; ++iSM )
2294 if ( !sm[ iSM ]) continue;
2296 SMDS_ElemIteratorPtr fIt = sm[ iSM ]->GetElements();
2297 while ( fIt->more() )
2299 const SMDS_MeshElement* face = fIt->next();
2300 const int nbNodes = face->NbCornerNodes();
2301 SMDS_ElemIteratorPtr nIt = face->nodesIterator();
2303 nodes.resize( nbNodes + 1 );
2304 for ( int iN = 0; iN < nbNodes; ++iN )
2305 nodes[ iN ] = nIt->next();
2306 nodes.back() = nodes[0];
2310 for ( int iN = 0; iN < nbNodes; ++iN )
2312 if ( nodes[ iN ]._node->GetPosition()->GetDim() < 2 &&
2313 nodes[ iN+1 ]._node->GetPosition()->GetDim() < 2 )
2315 // it's a boundary link; measure distance of other
2316 // nodes to this link
2317 gp_XYZ linkDir = nodes[ iN ] - nodes[ iN+1 ];
2318 double linkLen = linkDir.Modulus();
2319 bool isDegen = ( linkLen < numeric_limits<double>::min() );
2320 if ( !isDegen ) linkDir /= linkLen;
2321 for ( int iN2 = 0; iN2 < nbNodes; ++iN2 ) // loop on other nodes
2323 if ( nodes[ iN2 ] == nodes[ iN ] ||
2324 nodes[ iN2 ] == nodes[ iN+1 ]) continue;
2327 dist2 = ( nodes[ iN ] - nodes[ iN2 ]).SquareModulus();
2331 dist2 = linkDir.CrossSquareMagnitude( nodes[ iN ] - nodes[ iN2 ]);
2333 if ( dist2 > numeric_limits<double>::min() )
2334 minDist = Min ( minDist, dist2 );
2337 // measure length link
2338 else if ( nodes[ iN ]._node < nodes[ iN+1 ]._node ) // not to measure same link twice
2340 dist2 = ( nodes[ iN ] - nodes[ iN+1 ]).SquareModulus();
2341 if ( dist2 > numeric_limits<double>::min() )
2342 minDist = Min ( minDist, dist2 );
2347 return 0.1 * Sqrt ( minDist );
2350 //=======================================================================
2351 //function : isSimpleQuad
2352 //purpose : check if the bottom FACE is meshable with nice qudrangles,
2353 // if so the block aproach can work rather fast.
2354 // This is a temporary mean caused by problems in StdMeshers_Sweeper
2355 //=======================================================================
2357 bool StdMeshers_Prism_3D::isSimpleBottom( const Prism_3D::TPrismTopo& thePrism )
2359 // analyse angles between edges
2360 double nbConcaveAng = 0, nbConvexAng = 0;
2361 TopoDS_Face reverseBottom = TopoDS::Face( thePrism.myBottom.Reversed() ); // see initPrism()
2362 TopoDS_Vertex commonV;
2363 const list< TopoDS_Edge >& botEdges = thePrism.myBottomEdges;
2364 list< TopoDS_Edge >::const_iterator edge = botEdges.begin();
2365 while ( edge != botEdges.end() )
2367 if ( SMESH_Algo::isDegenerated( *edge ))
2369 TopoDS_Edge e1 = *edge++;
2370 TopoDS_Edge e2 = ( edge == botEdges.end() ? botEdges.front() : *edge );
2371 if ( ! TopExp::CommonVertex( e1, e2, commonV ))
2373 e2 = botEdges.front();
2374 if ( ! TopExp::CommonVertex( e1, e2, commonV ))
2377 double angle = myHelper->GetAngle( e1, e2, reverseBottom, commonV );
2378 if ( angle < -5 * M_PI/180 )
2379 if ( ++nbConcaveAng > 1 )
2381 if ( angle > 85 * M_PI/180 )
2382 if ( ++nbConvexAng > 4 )
2388 //=======================================================================
2389 //function : project2dMesh
2390 //purpose : Project mesh faces from a source FACE of one prism (theSrcFace)
2391 // to a source FACE of another prism (theTgtFace)
2392 //=======================================================================
2394 bool StdMeshers_Prism_3D::project2dMesh(const TopoDS_Face& theSrcFace,
2395 const TopoDS_Face& theTgtFace)
2397 TProjction2dAlgo* projector2D = TProjction2dAlgo::instance( this );
2398 projector2D->myHyp.SetSourceFace( theSrcFace );
2399 bool ok = projector2D->Compute( *myHelper->GetMesh(), theTgtFace );
2401 SMESH_subMesh* tgtSM = myHelper->GetMesh()->GetSubMesh( theTgtFace );
2402 if ( !ok && tgtSM->GetSubMeshDS() ) {
2403 //tgtSM->ComputeStateEngine( SMESH_subMesh::CLEAN ); -- avoid propagation of events
2404 SMESHDS_Mesh* meshDS = myHelper->GetMeshDS();
2405 SMESHDS_SubMesh* tgtSMDS = tgtSM->GetSubMeshDS();
2406 for ( SMDS_ElemIteratorPtr eIt = tgtSMDS->GetElements(); eIt->more(); )
2407 meshDS->RemoveFreeElement( eIt->next(), tgtSMDS, /*fromGroups=*/false );
2408 for ( SMDS_NodeIteratorPtr nIt = tgtSMDS->GetNodes(); nIt->more(); )
2409 meshDS->RemoveFreeNode( nIt->next(), tgtSMDS, /*fromGroups=*/false );
2411 tgtSM->ComputeStateEngine ( SMESH_subMesh::CHECK_COMPUTE_STATE );
2412 tgtSM->ComputeSubMeshStateEngine( SMESH_subMesh::CHECK_COMPUTE_STATE );
2417 //================================================================================
2419 * \brief Set projection coordinates of a node to a face and it's sub-shapes
2420 * \param faceID - the face given by in-block ID
2421 * \param params - node normalized parameters
2422 * \retval bool - is a success
2424 //================================================================================
2426 bool StdMeshers_Prism_3D::setFaceAndEdgesXYZ( const int faceID, const gp_XYZ& params, int z )
2428 // find base and top edges of the face
2429 enum { BASE = 0, TOP, LEFT, RIGHT };
2430 vector< int > edgeVec; // 0-base, 1-top
2431 SMESH_Block::GetFaceEdgesIDs( faceID, edgeVec );
2433 myBlock.EdgePoint( edgeVec[ BASE ], params, myShapeXYZ[ edgeVec[ BASE ]]);
2434 myBlock.EdgePoint( edgeVec[ TOP ], params, myShapeXYZ[ edgeVec[ TOP ]]);
2436 SHOWYXZ("\nparams ", params);
2437 SHOWYXZ("TOP is " <<edgeVec[ TOP ], myShapeXYZ[ edgeVec[ TOP]]);
2438 SHOWYXZ("BASE is "<<edgeVec[ BASE], myShapeXYZ[ edgeVec[ BASE]]);
2440 if ( faceID == SMESH_Block::ID_Fx0z || faceID == SMESH_Block::ID_Fx1z )
2442 myBlock.EdgePoint( edgeVec[ LEFT ], params, myShapeXYZ[ edgeVec[ LEFT ]]);
2443 myBlock.EdgePoint( edgeVec[ RIGHT ], params, myShapeXYZ[ edgeVec[ RIGHT ]]);
2445 SHOWYXZ("VER "<<edgeVec[ LEFT], myShapeXYZ[ edgeVec[ LEFT]]);
2446 SHOWYXZ("VER "<<edgeVec[ RIGHT], myShapeXYZ[ edgeVec[ RIGHT]]);
2448 myBlock.FacePoint( faceID, params, myShapeXYZ[ faceID ]);
2449 SHOWYXZ("FacePoint "<<faceID, myShapeXYZ[ faceID]);
2454 //=======================================================================
2456 //purpose : If (!isOK), sets the error to a sub-mesh of a current SOLID
2457 //=======================================================================
2459 bool StdMeshers_Prism_3D::toSM( bool isOK )
2461 if ( mySetErrorToSM &&
2464 !myHelper->GetSubShape().IsNull() &&
2465 myHelper->GetSubShape().ShapeType() == TopAbs_SOLID)
2467 SMESH_subMesh* sm = myHelper->GetMesh()->GetSubMesh( myHelper->GetSubShape() );
2468 sm->GetComputeError() = this->GetComputeError();
2469 // clear error in order not to return it twice
2470 _error = COMPERR_OK;
2476 //=======================================================================
2477 //function : shapeID
2478 //purpose : Return index of a shape
2479 //=======================================================================
2481 int StdMeshers_Prism_3D::shapeID( const TopoDS_Shape& S )
2483 if ( S.IsNull() ) return 0;
2484 if ( !myHelper ) return -3;
2485 return myHelper->GetMeshDS()->ShapeToIndex( S );
2488 namespace // utils used by StdMeshers_Prism_3D::IsApplicable()
2490 struct EdgeWithNeighbors
2494 EdgeWithNeighbors(const TopoDS_Edge& E, int iE, int nbE, int shift = 0 ):
2496 _iL( SMESH_MesherHelper::WrapIndex( iE-1, nbE ) + shift ),
2497 _iR( SMESH_MesherHelper::WrapIndex( iE+1, nbE ) + shift )
2500 EdgeWithNeighbors() {}
2505 TopTools_IndexedMapOfShape *_faces; // pointer because its copy constructor is private
2506 TopoDS_Edge _topEdge;
2507 vector< EdgeWithNeighbors >*_edges;
2509 vector< bool > _isCheckedEdge;
2510 int _nbCheckedEdges; // nb of EDGEs whose location is defined
2511 PrismSide *_leftSide;
2512 PrismSide *_rightSide;
2513 const TopoDS_Edge& Edge( int i ) const
2515 return (*_edges)[ i ]._edge;
2517 int FindEdge( const TopoDS_Edge& E ) const
2519 for ( size_t i = 0; i < _edges->size(); ++i )
2520 if ( E.IsSame( Edge( i ))) return i;
2523 bool IsSideFace( const TopoDS_Shape& face ) const
2525 if ( _faces->Contains( face )) // avoid returning true for a prism top FACE
2526 return ( !_face.IsNull() || !( face.IsSame( _faces->FindKey( _faces->Extent() ))));
2530 //--------------------------------------------------------------------------------
2532 * \brief Return ordered edges of a face
2534 bool getEdges( const TopoDS_Face& face,
2535 vector< EdgeWithNeighbors > & edges,
2536 const bool noHolesAllowed)
2538 list< TopoDS_Edge > ee;
2539 list< int > nbEdgesInWires;
2540 int nbW = SMESH_Block::GetOrderedEdges( face, ee, nbEdgesInWires );
2541 if ( nbW > 1 && noHolesAllowed )
2545 list< TopoDS_Edge >::iterator e = ee.begin();
2546 list< int >::iterator nbE = nbEdgesInWires.begin();
2547 for ( ; nbE != nbEdgesInWires.end(); ++nbE )
2548 for ( iE = 0; iE < *nbE; ++e, ++iE )
2549 if ( SMESH_Algo::isDegenerated( *e ))
2551 e = --ee.erase( e );
2557 e->Orientation( TopAbs_FORWARD ); // for operator==() to work
2562 for ( nbE = nbEdgesInWires.begin(); nbE != nbEdgesInWires.end(); ++nbE )
2564 for ( iE = 0; iE < *nbE; ++e, ++iE )
2565 edges.push_back( EdgeWithNeighbors( *e, iE, *nbE, nbTot ));
2568 return edges.size();
2570 //--------------------------------------------------------------------------------
2572 * \brief Return another faces sharing an edge
2574 const TopoDS_Shape & getAnotherFace( const TopoDS_Face& face,
2575 const TopoDS_Edge& edge,
2576 TopTools_IndexedDataMapOfShapeListOfShape& facesOfEdge)
2578 TopTools_ListIteratorOfListOfShape faceIt( facesOfEdge.FindFromKey( edge ));
2579 for ( ; faceIt.More(); faceIt.Next() )
2580 if ( !face.IsSame( faceIt.Value() ))
2581 return faceIt.Value();
2586 //================================================================================
2588 * \brief Return true if the algorithm can mesh this shape
2589 * \param [in] aShape - shape to check
2590 * \param [in] toCheckAll - if true, this check returns OK if all shapes are OK,
2591 * else, returns OK if at least one shape is OK
2593 //================================================================================
2595 bool StdMeshers_Prism_3D::IsApplicable(const TopoDS_Shape & shape, bool toCheckAll)
2597 TopExp_Explorer sExp( shape, TopAbs_SOLID );
2601 for ( ; sExp.More(); sExp.Next() )
2605 TopExp_Explorer shExp( sExp.Current(), TopAbs_SHELL );
2606 if ( shExp.More() ) {
2607 shell = shExp.Current();
2612 if ( shell.IsNull() ) {
2613 if ( toCheckAll ) return false;
2617 TopTools_IndexedMapOfShape allFaces;
2618 TopExp::MapShapes( shell, TopAbs_FACE, allFaces );
2619 if ( allFaces.Extent() < 3 ) {
2620 if ( toCheckAll ) return false;
2624 if ( allFaces.Extent() == 6 )
2626 TopTools_IndexedMapOfOrientedShape map;
2627 bool isBox = SMESH_Block::FindBlockShapes( TopoDS::Shell( shell ),
2628 TopoDS_Vertex(), TopoDS_Vertex(), map );
2630 if ( !toCheckAll ) return true;
2635 TopTools_IndexedMapOfShape allShapes;
2636 TopExp::MapShapes( shape, allShapes );
2639 TopTools_IndexedDataMapOfShapeListOfShape facesOfEdge;
2640 TopTools_ListIteratorOfListOfShape faceIt;
2641 TopExp::MapShapesAndAncestors( sExp.Current(), TopAbs_EDGE, TopAbs_FACE , facesOfEdge );
2642 if ( facesOfEdge.IsEmpty() ) {
2643 if ( toCheckAll ) return false;
2647 typedef vector< EdgeWithNeighbors > TEdgeWithNeighborsVec;
2648 vector< TEdgeWithNeighborsVec > faceEdgesVec( allFaces.Extent() + 1 );
2649 TopTools_IndexedMapOfShape* facesOfSide = new TopTools_IndexedMapOfShape[ faceEdgesVec.size() ];
2650 SMESHUtils::ArrayDeleter<TopTools_IndexedMapOfShape> delFacesOfSide( facesOfSide );
2652 // try to use each face as a bottom one
2653 bool prismDetected = false;
2654 for ( int iF = 1; iF < allFaces.Extent() && !prismDetected; ++iF )
2656 const TopoDS_Face& botF = TopoDS::Face( allFaces( iF ));
2658 TEdgeWithNeighborsVec& botEdges = faceEdgesVec[ iF ];
2659 if ( botEdges.empty() )
2660 if ( !getEdges( botF, botEdges, /*noHoles=*/false ))
2662 if ( allFaces.Extent()-1 <= (int) botEdges.size() )
2663 continue; // all faces are adjacent to botF - no top FACE
2665 // init data of side FACEs
2666 vector< PrismSide > sides( botEdges.size() );
2667 for ( int iS = 0; iS < botEdges.size(); ++iS )
2669 sides[ iS ]._topEdge = botEdges[ iS ]._edge;
2670 sides[ iS ]._face = botF;
2671 sides[ iS ]._leftSide = & sides[ botEdges[ iS ]._iR ];
2672 sides[ iS ]._rightSide = & sides[ botEdges[ iS ]._iL ];
2673 sides[ iS ]._faces = & facesOfSide[ iS ];
2674 sides[ iS ]._faces->Clear();
2677 bool isOK = true; // ok for a current botF
2678 bool isAdvanced = true; // is new data found in a current loop
2679 int nbFoundSideFaces = 0;
2680 for ( int iLoop = 0; isOK && isAdvanced; ++iLoop )
2683 for ( size_t iS = 0; iS < sides.size() && isOK; ++iS )
2685 PrismSide& side = sides[ iS ];
2686 if ( side._face.IsNull() )
2687 continue; // probably the prism top face is the last of side._faces
2689 if ( side._topEdge.IsNull() )
2691 // find vertical EDGEs --- EGDEs shared with neighbor side FACEs
2692 for ( int is2nd = 0; is2nd < 2 && isOK; ++is2nd ) // 2 adjacent neighbors
2694 int di = is2nd ? 1 : -1;
2695 const PrismSide* adjSide = is2nd ? side._rightSide : side._leftSide;
2696 for ( size_t i = 1; i < side._edges->size(); ++i )
2698 int iE = SMESH_MesherHelper::WrapIndex( i*di + side._iBotEdge, side._edges->size());
2699 if ( side._isCheckedEdge[ iE ] ) continue;
2700 const TopoDS_Edge& vertE = side.Edge( iE );
2701 const TopoDS_Shape& neighborF = getAnotherFace( side._face, vertE, facesOfEdge );
2702 bool isEdgeShared = adjSide->IsSideFace( neighborF );
2706 side._isCheckedEdge[ iE ] = true;
2707 side._nbCheckedEdges++;
2708 int nbNotCheckedE = side._edges->size() - side._nbCheckedEdges;
2709 if ( nbNotCheckedE == 1 )
2714 if ( i == 1 && iLoop == 0 ) isOK = false;
2720 int nbNotCheckedE = side._edges->size() - side._nbCheckedEdges;
2721 if ( nbNotCheckedE == 1 )
2723 vector<bool>::iterator ii = std::find( side._isCheckedEdge.begin(),
2724 side._isCheckedEdge.end(), false );
2725 if ( ii != side._isCheckedEdge.end() )
2727 size_t iE = std::distance( side._isCheckedEdge.begin(), ii );
2728 side._topEdge = side.Edge( iE );
2731 isOK = ( nbNotCheckedE >= 1 );
2733 else //if ( !side._topEdge.IsNull() )
2735 // get a next face of a side
2736 const TopoDS_Shape& f = getAnotherFace( side._face, side._topEdge, facesOfEdge );
2737 side._faces->Add( f );
2739 if ( f.IsSame( side._face ) || // _topEdge is a seam
2740 SMESH_MesherHelper::Count( f, TopAbs_WIRE, false ) != 1 )
2744 else if ( side._leftSide != & side ) // not closed side face
2746 if ( side._leftSide->_faces->Contains( f ))
2748 stop = true; // probably f is the prism top face
2749 side._leftSide->_face.Nullify();
2750 side._leftSide->_topEdge.Nullify();
2752 if ( side._rightSide->_faces->Contains( f ))
2754 stop = true; // probably f is the prism top face
2755 side._rightSide->_face.Nullify();
2756 side._rightSide->_topEdge.Nullify();
2761 side._face.Nullify();
2762 side._topEdge.Nullify();
2765 side._face = TopoDS::Face( f );
2766 int faceID = allFaces.FindIndex( side._face );
2767 side._edges = & faceEdgesVec[ faceID ];
2768 if ( side._edges->empty() )
2769 if ( !getEdges( side._face, * side._edges, /*noHoles=*/true ))
2771 const int nbE = side._edges->size();
2776 side._iBotEdge = side.FindEdge( side._topEdge );
2777 side._isCheckedEdge.clear();
2778 side._isCheckedEdge.resize( nbE, false );
2779 side._isCheckedEdge[ side._iBotEdge ] = true;
2780 side._nbCheckedEdges = 1; // bottom EDGE is known
2782 side._topEdge.Nullify();
2783 isOK = ( !side._edges->empty() || side._faces->Extent() > 1 );
2785 } //if ( !side._topEdge.IsNull() )
2787 } // loop on prism sides
2789 if ( nbFoundSideFaces > allFaces.Extent() )
2793 if ( iLoop > allFaces.Extent() * 10 )
2797 cerr << "BUG: infinite loop in StdMeshers_Prism_3D::IsApplicable()" << endl;
2800 } // while isAdvanced
2802 if ( isOK && sides[0]._faces->Extent() > 1 )
2804 const int nbFaces = sides[0]._faces->Extent();
2805 if ( botEdges.size() == 1 ) // cylinder
2807 prismDetected = ( nbFaces == allFaces.Extent()-1 );
2811 const TopoDS_Shape& topFace = sides[0]._faces->FindKey( nbFaces );
2813 for ( iS = 1; iS < sides.size(); ++iS )
2814 if ( !sides[ iS ]._faces->Contains( topFace ))
2816 prismDetected = ( iS == sides.size() );
2819 } // loop on allFaces
2821 if ( !prismDetected && toCheckAll ) return false;
2822 if ( prismDetected && !toCheckAll ) return true;
2831 //================================================================================
2833 * \brief Return true if this node and other one belong to one face
2835 //================================================================================
2837 bool Prism_3D::TNode::IsNeighbor( const Prism_3D::TNode& other ) const
2839 if ( !other.myNode || !myNode ) return false;
2841 SMDS_ElemIteratorPtr fIt = other.myNode->GetInverseElementIterator(SMDSAbs_Face);
2842 while ( fIt->more() )
2843 if ( fIt->next()->GetNodeIndex( myNode ) >= 0 )
2848 //================================================================================
2850 * \brief Prism initialization
2852 //================================================================================
2854 void TPrismTopo::Clear()
2856 myShape3D.Nullify();
2859 myWallQuads.clear();
2860 myBottomEdges.clear();
2861 myNbEdgesInWires.clear();
2862 myWallQuads.clear();
2865 //================================================================================
2867 * \brief Set upside-down
2869 //================================================================================
2871 void TPrismTopo::SetUpsideDown()
2873 std::swap( myBottom, myTop );
2874 myBottomEdges.clear();
2875 std::reverse( myBottomEdges.begin(), myBottomEdges.end() );
2876 for ( size_t i = 0; i < myWallQuads.size(); ++i )
2878 myWallQuads[i].reverse();
2879 TQuadList::iterator q = myWallQuads[i].begin();
2880 for ( ; q != myWallQuads[i].end(); ++q )
2882 (*q)->shift( 2, /*keepUnitOri=*/true );
2884 myBottomEdges.push_back( myWallQuads[i].front()->side[ QUAD_BOTTOM_SIDE ].grid->Edge(0) );
2888 } // namespace Prism_3D
2890 //================================================================================
2892 * \brief Constructor. Initialization is needed
2894 //================================================================================
2896 StdMeshers_PrismAsBlock::StdMeshers_PrismAsBlock()
2901 StdMeshers_PrismAsBlock::~StdMeshers_PrismAsBlock()
2905 void StdMeshers_PrismAsBlock::Clear()
2908 myShapeIDMap.Clear();
2912 delete mySide; mySide = 0;
2914 myParam2ColumnMaps.clear();
2915 myShapeIndex2ColumnMap.clear();
2918 //=======================================================================
2919 //function : initPrism
2920 //purpose : Analyse shape geometry and mesh.
2921 // If there are triangles on one of faces, it becomes 'bottom'.
2922 // thePrism.myBottom can be already set up.
2923 //=======================================================================
2925 bool StdMeshers_Prism_3D::initPrism(Prism_3D::TPrismTopo& thePrism,
2926 const TopoDS_Shape& theShape3D,
2927 const bool selectBottom)
2929 myHelper->SetSubShape( theShape3D );
2931 SMESH_subMesh* mainSubMesh = myHelper->GetMesh()->GetSubMeshContaining( theShape3D );
2932 if ( !mainSubMesh ) return toSM( error(COMPERR_BAD_INPUT_MESH,"Null submesh of shape3D"));
2934 // detect not-quad FACE sub-meshes of the 3D SHAPE
2935 list< SMESH_subMesh* > notQuadGeomSubMesh;
2936 list< SMESH_subMesh* > notQuadElemSubMesh;
2937 list< SMESH_subMesh* > meshedSubMesh;
2940 SMESH_subMesh* anyFaceSM = 0;
2941 SMESH_subMeshIteratorPtr smIt = mainSubMesh->getDependsOnIterator(false,true);
2942 while ( smIt->more() )
2944 SMESH_subMesh* sm = smIt->next();
2945 const TopoDS_Shape& face = sm->GetSubShape();
2946 if ( face.ShapeType() > TopAbs_FACE ) break;
2947 else if ( face.ShapeType() < TopAbs_FACE ) continue;
2951 // is quadrangle FACE?
2952 list< TopoDS_Edge > orderedEdges;
2953 list< int > nbEdgesInWires;
2954 int nbWires = SMESH_Block::GetOrderedEdges( TopoDS::Face( face ), orderedEdges,
2956 if ( nbWires != 1 || nbEdgesInWires.front() != 4 )
2957 notQuadGeomSubMesh.push_back( sm );
2959 // look for a not structured sub-mesh
2960 if ( !sm->IsEmpty() )
2962 meshedSubMesh.push_back( sm );
2963 if ( !myHelper->IsSameElemGeometry( sm->GetSubMeshDS(), SMDSGeom_QUADRANGLE ) ||
2964 !myHelper->IsStructured ( sm ))
2965 notQuadElemSubMesh.push_back( sm );
2969 int nbNotQuadMeshed = notQuadElemSubMesh.size();
2970 int nbNotQuad = notQuadGeomSubMesh.size();
2971 bool hasNotQuad = ( nbNotQuad || nbNotQuadMeshed );
2974 if ( nbNotQuadMeshed > 2 )
2976 return toSM( error(COMPERR_BAD_INPUT_MESH,
2977 TCom("More than 2 faces with not quadrangle elements: ")
2978 <<nbNotQuadMeshed));
2980 if ( nbNotQuad > 2 || !thePrism.myBottom.IsNull() )
2982 // Issue 0020843 - one of side FACEs is quasi-quadrilateral (not 4 EDGEs).
2983 // Remove from notQuadGeomSubMesh faces meshed with regular grid
2984 int nbQuasiQuads = removeQuasiQuads( notQuadGeomSubMesh, myHelper,
2985 TQuadrangleAlgo::instance(this,myHelper) );
2986 nbNotQuad -= nbQuasiQuads;
2987 if ( nbNotQuad > 2 )
2988 return toSM( error(COMPERR_BAD_SHAPE,
2989 TCom("More than 2 not quadrilateral faces: ") <<nbNotQuad));
2990 hasNotQuad = ( nbNotQuad || nbNotQuadMeshed );
2993 // Analyse mesh and topology of FACEs: choose the bottom sub-mesh.
2994 // If there are not quadrangle FACEs, they are top and bottom ones.
2995 // Not quadrangle FACEs must be only on top and bottom.
2997 SMESH_subMesh * botSM = 0;
2998 SMESH_subMesh * topSM = 0;
3000 if ( hasNotQuad ) // can choose a bottom FACE
3002 if ( nbNotQuadMeshed > 0 ) botSM = notQuadElemSubMesh.front();
3003 else botSM = notQuadGeomSubMesh.front();
3004 if ( nbNotQuadMeshed > 1 ) topSM = notQuadElemSubMesh.back();
3005 else if ( nbNotQuad > 1 ) topSM = notQuadGeomSubMesh.back();
3007 if ( topSM == botSM ) {
3008 if ( nbNotQuadMeshed > 1 ) topSM = notQuadElemSubMesh.front();
3009 else topSM = notQuadGeomSubMesh.front();
3012 // detect mesh triangles on wall FACEs
3013 if ( nbNotQuad == 2 && nbNotQuadMeshed > 0 ) {
3015 if ( nbNotQuadMeshed == 1 )
3016 ok = ( find( notQuadGeomSubMesh.begin(),
3017 notQuadGeomSubMesh.end(), botSM ) != notQuadGeomSubMesh.end() );
3019 ok = ( notQuadGeomSubMesh == notQuadElemSubMesh );
3021 return toSM( error(COMPERR_BAD_INPUT_MESH,
3022 "Side face meshed with not quadrangle elements"));
3026 thePrism.myNotQuadOnTop = ( nbNotQuadMeshed > 1 );
3028 // use thePrism.myBottom
3029 if ( !thePrism.myBottom.IsNull() )
3031 if ( botSM ) { // <-- not quad geom or mesh on botSM
3032 if ( ! botSM->GetSubShape().IsSame( thePrism.myBottom )) {
3033 std::swap( botSM, topSM );
3034 if ( !botSM || ! botSM->GetSubShape().IsSame( thePrism.myBottom )) {
3035 if ( !selectBottom )
3036 return toSM( error( COMPERR_BAD_INPUT_MESH,
3037 "Incompatible non-structured sub-meshes"));
3038 std::swap( botSM, topSM );
3039 thePrism.myBottom = TopoDS::Face( botSM->GetSubShape() );
3043 else if ( !selectBottom ) {
3044 botSM = myHelper->GetMesh()->GetSubMesh( thePrism.myBottom );
3047 if ( !botSM ) // find a proper bottom
3049 bool savedSetErrorToSM = mySetErrorToSM;
3050 mySetErrorToSM = false; // ingore errors in initPrism()
3052 // search among meshed FACEs
3053 list< SMESH_subMesh* >::iterator sm = meshedSubMesh.begin();
3054 for ( ; !botSM && sm != meshedSubMesh.end(); ++sm )
3058 thePrism.myBottom = TopoDS::Face( botSM->GetSubShape() );
3059 if ( !initPrism( thePrism, theShape3D, /*selectBottom=*/false ))
3062 // search among all FACEs
3063 for ( TopExp_Explorer f( theShape3D, TopAbs_FACE ); !botSM && f.More(); f.Next() )
3065 int minNbFaces = 2 + myHelper->Count( f.Current(), TopAbs_EDGE, false);
3066 if ( nbFaces < minNbFaces) continue;
3068 thePrism.myBottom = TopoDS::Face( f.Current() );
3069 botSM = myHelper->GetMesh()->GetSubMesh( thePrism.myBottom );
3070 if ( !initPrism( thePrism, theShape3D, /*selectBottom=*/false ))
3073 mySetErrorToSM = savedSetErrorToSM;
3074 return botSM ? true : toSM( error( COMPERR_BAD_SHAPE ));
3077 // find vertex 000 - the one with smallest coordinates (for easy DEBUG :-)
3079 double minVal = DBL_MAX, minX, val;
3080 for ( TopExp_Explorer exp( botSM->GetSubShape(), TopAbs_VERTEX );
3081 exp.More(); exp.Next() )
3083 const TopoDS_Vertex& v = TopoDS::Vertex( exp.Current() );
3084 gp_Pnt P = BRep_Tool::Pnt( v );
3085 val = P.X() + P.Y() + P.Z();
3086 if ( val < minVal || ( val == minVal && P.X() < minX )) {
3093 thePrism.myShape3D = theShape3D;
3094 if ( thePrism.myBottom.IsNull() )
3095 thePrism.myBottom = TopoDS::Face( botSM->GetSubShape() );
3096 thePrism.myBottom.Orientation( myHelper->GetSubShapeOri( theShape3D, thePrism.myBottom ));
3097 thePrism.myTop. Orientation( myHelper->GetSubShapeOri( theShape3D, thePrism.myTop ));
3099 // Get ordered bottom edges
3100 TopoDS_Face reverseBottom = // to have order of top EDGEs as in the top FACE
3101 TopoDS::Face( thePrism.myBottom.Reversed() );
3102 SMESH_Block::GetOrderedEdges( reverseBottom,
3103 thePrism.myBottomEdges,
3104 thePrism.myNbEdgesInWires, V000 );
3106 // Get Wall faces corresponding to the ordered bottom edges and the top FACE
3107 if ( !getWallFaces( thePrism, nbFaces )) // it also sets thePrism.myTop
3108 return false; //toSM( error(COMPERR_BAD_SHAPE, "Can't find side faces"));
3112 if ( !thePrism.myTop.IsSame( topSM->GetSubShape() ))
3114 (notQuadGeomSubMesh.empty() ? COMPERR_BAD_INPUT_MESH : COMPERR_BAD_SHAPE,
3115 "Non-quadrilateral faces are not opposite"));
3117 // check that the found top and bottom FACEs are opposite
3118 list< TopoDS_Edge >::iterator edge = thePrism.myBottomEdges.begin();
3119 for ( ; edge != thePrism.myBottomEdges.end(); ++edge )
3120 if ( myHelper->IsSubShape( *edge, thePrism.myTop ))
3122 (notQuadGeomSubMesh.empty() ? COMPERR_BAD_INPUT_MESH : COMPERR_BAD_SHAPE,
3123 "Non-quadrilateral faces are not opposite"));
3126 if ( thePrism.myBottomEdges.size() > thePrism.myWallQuads.size() )
3128 // composite bottom sides => set thePrism upside-down
3129 thePrism.SetUpsideDown();
3135 //================================================================================
3137 * \brief Initialization.
3138 * \param helper - helper loaded with mesh and 3D shape
3139 * \param thePrism - a prism data
3140 * \retval bool - false if a mesh or a shape are KO
3142 //================================================================================
3144 bool StdMeshers_PrismAsBlock::Init(SMESH_MesherHelper* helper,
3145 const Prism_3D::TPrismTopo& thePrism)
3148 SMESHDS_Mesh* meshDS = myHelper->GetMeshDS();
3149 SMESH_Mesh* mesh = myHelper->GetMesh();
3152 delete mySide; mySide = 0;
3154 vector< TSideFace* > sideFaces( NB_WALL_FACES, 0 );
3155 vector< pair< double, double> > params( NB_WALL_FACES );
3156 mySide = new TSideFace( *mesh, sideFaces, params );
3159 SMESH_Block::init();
3160 myShapeIDMap.Clear();
3161 myShapeIndex2ColumnMap.clear();
3163 int wallFaceIds[ NB_WALL_FACES ] = { // to walk around a block
3164 SMESH_Block::ID_Fx0z, SMESH_Block::ID_F1yz,
3165 SMESH_Block::ID_Fx1z, SMESH_Block::ID_F0yz
3168 myError = SMESH_ComputeError::New();
3170 myNotQuadOnTop = thePrism.myNotQuadOnTop;
3172 // Find columns of wall nodes and calculate edges' lengths
3173 // --------------------------------------------------------
3175 myParam2ColumnMaps.clear();
3176 myParam2ColumnMaps.resize( thePrism.myBottomEdges.size() ); // total nb edges
3178 size_t iE, nbEdges = thePrism.myNbEdgesInWires.front(); // nb outer edges
3179 vector< double > edgeLength( nbEdges );
3180 multimap< double, int > len2edgeMap;
3182 // for each EDGE: either split into several parts, or join with several next EDGEs
3183 vector<int> nbSplitPerEdge( nbEdges, 0 );
3184 vector<int> nbUnitePerEdge( nbEdges, 0 ); // -1 means "joined to a previous"
3186 // consider continuous straight EDGEs as one side
3187 const int nbSides = countNbSides( thePrism, nbUnitePerEdge, edgeLength );
3189 list< TopoDS_Edge >::const_iterator edgeIt = thePrism.myBottomEdges.begin();
3190 for ( iE = 0; iE < nbEdges; ++iE, ++edgeIt )
3192 TParam2ColumnMap & faceColumns = myParam2ColumnMaps[ iE ];
3194 Prism_3D::TQuadList::const_iterator quad = thePrism.myWallQuads[ iE ].begin();
3195 for ( ; quad != thePrism.myWallQuads[ iE ].end(); ++quad )
3197 const TopoDS_Edge& quadBot = (*quad)->side[ QUAD_BOTTOM_SIDE ].grid->Edge( 0 );
3198 if ( !myHelper->LoadNodeColumns( faceColumns, (*quad)->face, quadBot, meshDS ))
3199 return error(COMPERR_BAD_INPUT_MESH, TCom("Can't find regular quadrangle mesh ")
3200 << "on a side face #" << MeshDS()->ShapeToIndex( (*quad)->face ));
3202 SHOWYXZ("\np1 F " <<iE, gpXYZ(faceColumns.begin()->second.front() ));
3203 SHOWYXZ("p2 F " <<iE, gpXYZ(faceColumns.rbegin()->second.front() ));
3204 SHOWYXZ("V First "<<iE, BRep_Tool::Pnt( TopExp::FirstVertex(*edgeIt,true )));
3206 if ( nbSides < NB_WALL_FACES ) // fill map used to split faces
3207 len2edgeMap.insert( make_pair( edgeLength[ iE ], iE )); // sort edges by length
3209 // Load columns of internal edges (forming holes)
3210 // and fill map ShapeIndex to TParam2ColumnMap for them
3211 for ( ; edgeIt != thePrism.myBottomEdges.end() ; ++edgeIt, ++iE )
3213 TParam2ColumnMap & faceColumns = myParam2ColumnMaps[ iE ];
3215 Prism_3D::TQuadList::const_iterator quad = thePrism.myWallQuads[ iE ].begin();
3216 for ( ; quad != thePrism.myWallQuads[ iE ].end(); ++quad )
3218 const TopoDS_Edge& quadBot = (*quad)->side[ QUAD_BOTTOM_SIDE ].grid->Edge( 0 );
3219 if ( !myHelper->LoadNodeColumns( faceColumns, (*quad)->face, quadBot, meshDS ))
3220 return error(COMPERR_BAD_INPUT_MESH, TCom("Can't find regular quadrangle mesh ")
3221 << "on a side face #" << MeshDS()->ShapeToIndex( (*quad)->face ));
3224 int id = MeshDS()->ShapeToIndex( *edgeIt );
3225 bool isForward = true; // meaningless for intenal wires
3226 myShapeIndex2ColumnMap[ id ] = make_pair( & faceColumns, isForward );
3227 // columns for vertices
3229 const SMDS_MeshNode* n0 = faceColumns.begin()->second.front();
3230 id = n0->getshapeId();
3231 myShapeIndex2ColumnMap[ id ] = make_pair( & faceColumns, isForward );
3233 const SMDS_MeshNode* n1 = faceColumns.rbegin()->second.front();
3234 id = n1->getshapeId();
3235 myShapeIndex2ColumnMap[ id ] = make_pair( & faceColumns, isForward );
3237 // SHOWYXZ("\np1 F " <<iE, gpXYZ(faceColumns.begin()->second.front() ));
3238 // SHOWYXZ("p2 F " <<iE, gpXYZ(faceColumns.rbegin()->second.front() ));
3239 // SHOWYXZ("V First "<<iE, BRep_Tool::Pnt( TopExp::FirstVertex(*edgeIt,true )));
3242 // Create 4 wall faces of a block
3243 // -------------------------------
3245 if ( nbSides <= NB_WALL_FACES ) // ************* Split faces if necessary
3247 if ( nbSides != NB_WALL_FACES ) // define how to split
3249 if ( len2edgeMap.size() != nbEdges )
3250 RETURN_BAD_RESULT("Uniqueness of edge lengths not assured");
3252 multimap< double, int >::reverse_iterator maxLen_i = len2edgeMap.rbegin();
3253 multimap< double, int >::reverse_iterator midLen_i = ++len2edgeMap.rbegin();
3255 double maxLen = maxLen_i->first;
3256 double midLen = ( len2edgeMap.size() == 1 ) ? 0 : midLen_i->first;
3257 switch ( nbEdges ) {
3258 case 1: // 0-th edge is split into 4 parts
3259 nbSplitPerEdge[ 0 ] = 4;
3261 case 2: // either the longest edge is split into 3 parts, or both edges into halves
3262 if ( maxLen / 3 > midLen / 2 ) {
3263 nbSplitPerEdge[ maxLen_i->second ] = 3;
3266 nbSplitPerEdge[ maxLen_i->second ] = 2;
3267 nbSplitPerEdge[ midLen_i->second ] = 2;
3272 // split longest into 3 parts
3273 nbSplitPerEdge[ maxLen_i->second ] = 3;
3275 // split longest into halves
3276 nbSplitPerEdge[ maxLen_i->second ] = 2;
3280 else // **************************** Unite faces
3282 int nbExraFaces = nbSides - 4; // nb of faces to fuse
3283 for ( iE = 0; iE < nbEdges; ++iE )
3285 if ( nbUnitePerEdge[ iE ] < 0 )
3287 // look for already united faces
3288 for ( int i = iE; i < iE + nbExraFaces; ++i )
3290 if ( nbUnitePerEdge[ i ] > 0 ) // a side including nbUnitePerEdge[i]+1 edge
3291 nbExraFaces += nbUnitePerEdge[ i ];
3292 nbUnitePerEdge[ i ] = -1;
3294 nbUnitePerEdge[ iE ] = nbExraFaces;
3299 // Create TSideFace's
3301 list< TopoDS_Edge >::const_iterator botE = thePrism.myBottomEdges.begin();
3302 for ( iE = 0; iE < nbEdges; ++iE, ++botE )
3304 TFaceQuadStructPtr quad = thePrism.myWallQuads[ iE ].front();
3305 const int nbSplit = nbSplitPerEdge[ iE ];
3306 const int nbExraFaces = nbUnitePerEdge[ iE ] + 1;
3307 if ( nbSplit > 0 ) // split
3309 vector< double > params;
3310 splitParams( nbSplit, &myParam2ColumnMaps[ iE ], params );
3311 const bool isForward =
3312 StdMeshers_PrismAsBlock::IsForwardEdge( myHelper->GetMeshDS(),
3313 myParam2ColumnMaps[iE],
3314 *botE, SMESH_Block::ID_Fx0z );
3315 for ( int i = 0; i < nbSplit; ++i ) {
3316 double f = ( isForward ? params[ i ] : params[ nbSplit - i-1 ]);
3317 double l = ( isForward ? params[ i+1 ] : params[ nbSplit - i ]);
3318 TSideFace* comp = new TSideFace( *mesh, wallFaceIds[ iSide ],
3319 thePrism.myWallQuads[ iE ], *botE,
3320 &myParam2ColumnMaps[ iE ], f, l );
3321 mySide->SetComponent( iSide++, comp );
3324 else if ( nbExraFaces > 1 ) // unite
3326 double u0 = 0, sumLen = 0;
3327 for ( int i = iE; i < iE + nbExraFaces; ++i )
3328 sumLen += edgeLength[ i ];
3330 vector< TSideFace* > components( nbExraFaces );
3331 vector< pair< double, double> > params( nbExraFaces );
3332 bool endReached = false;
3333 for ( int i = 0; i < nbExraFaces; ++i, ++botE, ++iE )
3335 if ( iE == nbEdges )
3338 botE = thePrism.myBottomEdges.begin();
3341 components[ i ] = new TSideFace( *mesh, wallFaceIds[ iSide ],
3342 thePrism.myWallQuads[ iE ], *botE,
3343 &myParam2ColumnMaps[ iE ]);
3344 double u1 = u0 + edgeLength[ iE ] / sumLen;