1 // Copyright (C) 2007-2020 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_MeshEditor.hxx"
37 #include "SMESH_MesherHelper.hxx"
38 #include "StdMeshers_FaceSide.hxx"
39 #include "StdMeshers_ProjectionSource1D.hxx"
40 #include "StdMeshers_ProjectionSource2D.hxx"
41 #include "StdMeshers_ProjectionUtils.hxx"
42 #include "StdMeshers_Projection_1D.hxx"
43 #include "StdMeshers_Projection_1D2D.hxx"
44 #include "StdMeshers_Quadrangle_2D.hxx"
46 #include "utilities.h"
48 #include <BRepAdaptor_CompCurve.hxx>
49 #include <BRep_Tool.hxx>
50 #include <Bnd_B3d.hxx>
51 #include <Geom2dAdaptor_Curve.hxx>
52 #include <Geom2d_Line.hxx>
53 #include <GeomLib_IsPlanarSurface.hxx>
54 #include <Geom_Curve.hxx>
55 #include <Standard_ErrorHandler.hxx>
57 #include <TopExp_Explorer.hxx>
58 #include <TopTools_ListIteratorOfListOfShape.hxx>
59 #include <TopTools_ListOfShape.hxx>
60 #include <TopTools_MapOfShape.hxx>
61 #include <TopTools_SequenceOfShape.hxx>
71 #define RETURN_BAD_RESULT(msg) { MESSAGE(")-: Error: " << msg); return false; }
72 #define gpXYZ(n) SMESH_TNodeXYZ(n)
75 #define DBGOUT(msg) //cout << msg << endl;
76 #define SHOWYXZ(msg, xyz) \
77 //{ gp_Pnt p (xyz); cout << msg << " ("<< p.X() << "; " <<p.Y() << "; " <<p.Z() << ") " <<endl; }
80 #define SHOWYXZ(msg, xyz)
83 namespace NSProjUtils = StdMeshers_ProjectionUtils;
85 typedef SMESH_Comment TCom;
87 enum { ID_BOT_FACE = SMESH_Block::ID_Fxy0,
88 ID_TOP_FACE = SMESH_Block::ID_Fxy1,
89 BOTTOM_EDGE = 0, TOP_EDGE, V0_EDGE, V1_EDGE, // edge IDs in face
90 NB_WALL_FACES = 4 }; //
94 //=======================================================================
96 * \brief Quadrangle algorithm
98 struct TQuadrangleAlgo : public StdMeshers_Quadrangle_2D
100 TQuadrangleAlgo(SMESH_Gen* gen)
101 : StdMeshers_Quadrangle_2D( gen->GetANewId(), gen)
104 static StdMeshers_Quadrangle_2D* instance( SMESH_Algo* fatherAlgo,
105 SMESH_MesherHelper* helper=0)
107 static TQuadrangleAlgo* algo = new TQuadrangleAlgo( fatherAlgo->GetGen() );
110 algo->myProxyMesh->GetMesh() != helper->GetMesh() )
111 algo->myProxyMesh.reset( new SMESH_ProxyMesh( *helper->GetMesh() ));
113 algo->myQuadList.clear();
117 algo->_quadraticMesh = helper->GetIsQuadratic();
122 //=======================================================================
124 * \brief Algorithm projecting 1D mesh
126 struct TProjction1dAlgo : public StdMeshers_Projection_1D
128 StdMeshers_ProjectionSource1D myHyp;
130 TProjction1dAlgo(SMESH_Gen* gen)
131 : StdMeshers_Projection_1D( gen->GetANewId(), gen),
132 myHyp( gen->GetANewId(), gen)
134 StdMeshers_Projection_1D::_sourceHypo = & myHyp;
136 static TProjction1dAlgo* instance( SMESH_Algo* fatherAlgo )
138 static TProjction1dAlgo* algo = new TProjction1dAlgo( fatherAlgo->GetGen() );
142 //=======================================================================
144 * \brief Algorithm projecting 2D mesh
146 struct TProjction2dAlgo : public StdMeshers_Projection_1D2D
148 StdMeshers_ProjectionSource2D myHyp;
150 TProjction2dAlgo(SMESH_Gen* gen)
151 : StdMeshers_Projection_1D2D( gen->GetANewId(), gen),
152 myHyp( gen->GetANewId(), gen)
154 StdMeshers_Projection_2D::_sourceHypo = & myHyp;
156 static TProjction2dAlgo* instance( SMESH_Algo* fatherAlgo )
158 static TProjction2dAlgo* algo = new TProjction2dAlgo( fatherAlgo->GetGen() );
161 const NSProjUtils::TNodeNodeMap& GetNodesMap()
163 return _src2tgtNodes;
165 void SetEventListener( SMESH_subMesh* tgtSubMesh )
167 NSProjUtils::SetEventListener( tgtSubMesh,
168 _sourceHypo->GetSourceFace(),
169 _sourceHypo->GetSourceMesh() );
172 //=======================================================================
174 * \brief Returns already computed EDGEs
176 void getPrecomputedEdges( SMESH_MesherHelper& theHelper,
177 const TopoDS_Shape& theShape,
178 vector< TopoDS_Edge >& theEdges)
182 SMESHDS_Mesh* meshDS = theHelper.GetMeshDS();
185 TopTools_IndexedMapOfShape edges;
186 TopExp::MapShapes( theShape, TopAbs_EDGE, edges );
187 for ( int iE = 1; iE <= edges.Extent(); ++iE )
189 const TopoDS_Shape edge = edges( iE );
190 if (( ! ( sm = meshDS->MeshElements( edge ))) ||
191 ( sm->NbElements() == 0 ))
194 // there must not be FACEs meshed with triangles and sharing a computed EDGE
195 // as the precomputed EDGEs are used for propagation other to 'vertical' EDGEs
196 bool faceFound = false;
197 PShapeIteratorPtr faceIt =
198 theHelper.GetAncestors( edge, *theHelper.GetMesh(), TopAbs_FACE );
199 while ( const TopoDS_Shape* face = faceIt->next() )
201 if (( sm = meshDS->MeshElements( *face )) &&
202 ( sm->NbElements() > 0 ) &&
203 ( !theHelper.IsSameElemGeometry( sm, SMDSGeom_QUADRANGLE ) ))
209 theEdges.push_back( TopoDS::Edge( edge ));
213 //================================================================================
215 * \brief Make \a botE be the BOTTOM_SIDE of \a quad.
216 * Return false if the BOTTOM_SIDE is composite
218 //================================================================================
220 bool setBottomEdge( const TopoDS_Edge& botE,
221 FaceQuadStruct::Ptr& quad,
222 const TopoDS_Shape& face)
224 quad->side[ QUAD_TOP_SIDE ].grid->Reverse();
225 quad->side[ QUAD_LEFT_SIDE ].grid->Reverse();
227 bool isComposite = false;
228 for ( size_t i = 0; i < quad->side.size(); ++i )
230 StdMeshers_FaceSidePtr quadSide = quad->side[i];
231 for ( int iE = 0; iE < quadSide->NbEdges(); ++iE )
232 if ( botE.IsSame( quadSide->Edge( iE )))
234 if ( quadSide->NbEdges() > 1 )
235 isComposite = true; //return false;
237 i = quad->side.size(); // to quit from the outer loop
241 if ( edgeIndex != QUAD_BOTTOM_SIDE )
242 quad->shift( quad->side.size() - edgeIndex, /*keepUnitOri=*/false );
244 quad->face = TopoDS::Face( face );
249 //================================================================================
251 * \brief Return iterator pointing to node column for the given parameter
252 * \param columnsMap - node column map
253 * \param parameter - parameter
254 * \retval TParam2ColumnMap::iterator - result
256 * it returns closest left column
258 //================================================================================
260 TParam2ColumnIt getColumn( const TParam2ColumnMap* columnsMap,
261 const double parameter )
263 TParam2ColumnIt u_col = columnsMap->upper_bound( parameter );
264 if ( u_col != columnsMap->begin() )
266 return u_col; // return left column
269 //================================================================================
271 * \brief Return nodes around given parameter and a ratio
272 * \param column - node column
273 * \param param - parameter
274 * \param node1 - lower node
275 * \param node2 - upper node
276 * \retval double - ratio
278 //================================================================================
280 double getRAndNodes( const TNodeColumn* column,
282 const SMDS_MeshNode* & node1,
283 const SMDS_MeshNode* & node2)
285 if ( param >= 1.0 || column->size() == 1) {
286 node1 = node2 = column->back();
290 int i = int( param * ( column->size() - 1 ));
291 double u0 = double( i )/ double( column->size() - 1 );
292 double r = ( param - u0 ) * ( column->size() - 1 );
294 node1 = (*column)[ i ];
295 node2 = (*column)[ i + 1];
299 //================================================================================
301 * \brief Compute boundary parameters of face parts
302 * \param nbParts - nb of parts to split columns into
303 * \param columnsMap - node columns of the face to split
304 * \param params - computed parameters
306 //================================================================================
308 void splitParams( const int nbParts,
309 const TParam2ColumnMap* columnsMap,
310 vector< double > & params)
313 params.reserve( nbParts + 1 );
314 TParam2ColumnIt last_par_col = --columnsMap->end();
315 double par = columnsMap->begin()->first; // 0.
316 double parLast = last_par_col->first;
317 params.push_back( par );
318 for ( int i = 0; i < nbParts - 1; ++ i )
320 double partSize = ( parLast - par ) / double ( nbParts - i );
321 TParam2ColumnIt par_col = getColumn( columnsMap, par + partSize );
322 if ( par_col->first == par ) {
324 if ( par_col == last_par_col ) {
325 while ( i < nbParts - 1 )
326 params.push_back( par + partSize * i++ );
330 par = par_col->first;
331 params.push_back( par );
333 params.push_back( parLast ); // 1.
336 //================================================================================
338 * \brief Return coordinate system for z-th layer of nodes
340 //================================================================================
342 gp_Ax2 getLayerCoordSys(const int z,
343 const vector< const TNodeColumn* >& columns,
346 // gravity center of a layer
349 for ( size_t i = 0; i < columns.size(); ++i )
351 O += gpXYZ( (*columns[ i ])[ z ]);
352 if ( vertexCol < 0 &&
353 columns[ i ]->front()->GetPosition()->GetTypeOfPosition() == SMDS_TOP_VERTEX )
360 int iPrev = columns.size()-1;
361 for ( size_t i = 0; i < columns.size(); ++i )
363 gp_Vec v1( O, gpXYZ( (*columns[ iPrev ])[ z ]));
364 gp_Vec v2( O, gpXYZ( (*columns[ i ] )[ z ]));
369 if ( vertexCol >= 0 )
371 O = gpXYZ( (*columns[ vertexCol ])[ z ]);
373 if ( xColumn < 0 || xColumn >= (int) columns.size() )
375 // select a column for X dir
377 for ( size_t i = 0; i < columns.size(); ++i )
379 double dist = ( O - gpXYZ((*columns[ i ])[ z ])).SquareModulus();
380 if ( dist > maxDist )
389 gp_Vec X( O, gpXYZ( (*columns[ xColumn ])[ z ]));
391 return gp_Ax2( O, Z, X);
394 //================================================================================
396 * \brief Removes submeshes that are or can be meshed with regular grid from given list
397 * \retval int - nb of removed submeshes
399 //================================================================================
401 int removeQuasiQuads(list< SMESH_subMesh* >& notQuadSubMesh,
402 SMESH_MesherHelper* helper,
403 StdMeshers_Quadrangle_2D* quadAlgo)
406 //SMESHDS_Mesh* mesh = notQuadSubMesh.front()->GetFather()->GetMeshDS();
407 list< SMESH_subMesh* >::iterator smIt = notQuadSubMesh.begin();
408 while ( smIt != notQuadSubMesh.end() )
410 SMESH_subMesh* faceSm = *smIt;
411 SMESHDS_SubMesh* faceSmDS = faceSm->GetSubMeshDS();
412 int nbQuads = faceSmDS ? faceSmDS->NbElements() : 0;
415 toRemove = helper->IsStructured( faceSm );
417 toRemove = ( quadAlgo->CheckNbEdges( *helper->GetMesh(),
418 faceSm->GetSubShape() ) != NULL );
419 nbRemoved += toRemove;
421 smIt = notQuadSubMesh.erase( smIt );
429 //================================================================================
431 * \brief Return and angle between two EDGEs
432 * \return double - the angle normalized so that
439 //================================================================================
441 // double normAngle(const TopoDS_Edge & E1, const TopoDS_Edge & E2, const TopoDS_Face & F)
443 // return SMESH_MesherHelper::GetAngle( E1, E2, F ) / ( 0.5 * M_PI );
446 //================================================================================
448 * Consider continuous straight EDGES as one side - mark them to unite
450 //================================================================================
452 int countNbSides( const Prism_3D::TPrismTopo & thePrism,
453 vector<int> & nbUnitePerEdge,
454 vector< double > & edgeLength)
456 int nbEdges = thePrism.myNbEdgesInWires.front(); // nb outer edges
457 int nbSides = nbEdges;
460 list< TopoDS_Edge >::const_iterator edgeIt = thePrism.myBottomEdges.begin();
461 std::advance( edgeIt, nbEdges-1 );
462 TopoDS_Edge prevE = *edgeIt;
463 // bool isPrevStraight = SMESH_Algo::IsStraight( prevE );
464 // int iPrev = nbEdges - 1;
466 // int iUnite = -1; // the first of united EDGEs
468 // analyse angles between EDGEs
470 vector< bool > isCorner( nbEdges );
471 edgeIt = thePrism.myBottomEdges.begin();
472 for ( int iE = 0; iE < nbEdges; ++iE, ++edgeIt )
474 const TopoDS_Edge& curE = *edgeIt;
475 edgeLength[ iE ] = SMESH_Algo::EdgeLength( curE );
477 // double normAngle = normAngle( prevE, curE, thePrism.myBottom );
478 // isCorner[ iE ] = false;
479 // if ( normAngle < 2.0 )
481 // if ( normAngle < 0.001 ) // straight or obtuse angle
483 // // unite EDGEs in order not to put a corner of the unit quadrangle at this VERTEX
486 // nbUnitePerEdge[ iUnite ]++;
487 // nbUnitePerEdge[ iE ] = -1;
492 // isCorner[ iE ] = true;
502 // define which of corners to put on a side of the unit quadrangle
504 // edgeIt = thePrism.myBottomEdges.begin();
505 // for ( int iE = 0; iE < nbEdges; ++iE, ++edgeIt )
507 // const TopoDS_Edge& curE = *edgeIt;
508 // edgeLength[ iE ] = SMESH_Algo::EdgeLength( curE );
510 // const bool isCurStraight = SMESH_Algo::IsStraight( curE );
511 // if ( isPrevStraight && isCurStraight && SMESH_Algo::IsContinuous( prevE, curE ))
515 // nbUnitePerEdge[ iUnite ]++;
516 // nbUnitePerEdge[ iE ] = -1;
524 // isPrevStraight = isCurStraight;
531 //================================================================================
533 * \brief Set/get wire index to FaceQuadStruct
535 //================================================================================
537 void setWireIndex( TFaceQuadStructPtr& quad, int iWire )
541 int getWireIndex( const TFaceQuadStructPtr& quad )
546 //================================================================================
548 * \brief Print Python commands adding given points to a mesh
550 //================================================================================
552 void pointsToPython(const std::vector<gp_XYZ>& p)
555 for ( size_t i = SMESH_Block::ID_V000; i < p.size(); ++i )
557 cout << "mesh.AddNode( " << p[i].X() << ", "<< p[i].Y() << ", "<< p[i].Z() << ") # " << i <<" " ;
558 SMESH_Block::DumpShapeID( i, cout ) << endl;
564 //=======================================================================
565 //function : StdMeshers_Prism_3D
567 //=======================================================================
569 StdMeshers_Prism_3D::StdMeshers_Prism_3D(int hypId, SMESH_Gen* gen)
570 :SMESH_3D_Algo(hypId, gen)
573 _shapeType = (1 << TopAbs_SOLID); // 1 bit per shape type
574 _onlyUnaryInput = false; // mesh all SOLIDs at once
575 _requireDiscreteBoundary = false; // mesh FACEs and EDGEs by myself
576 _supportSubmeshes = true; // "source" FACE must be meshed by other algo
577 _neededLowerHyps[ 1 ] = true; // suppress warning on hiding a global 1D algo
578 _neededLowerHyps[ 2 ] = true; // suppress warning on hiding a global 2D algo
580 //myProjectTriangles = false;
581 mySetErrorToSM = true; // to pass an error to a sub-mesh of a current solid or not
582 myPrevBottomSM = 0; // last treated bottom sub-mesh with a suitable algorithm
585 //================================================================================
589 //================================================================================
591 StdMeshers_Prism_3D::~StdMeshers_Prism_3D()
593 pointsToPython( std::vector<gp_XYZ>() ); // avoid warning: pointsToPython defined but not used
596 //=======================================================================
597 //function : CheckHypothesis
599 //=======================================================================
601 bool StdMeshers_Prism_3D::CheckHypothesis(SMESH_Mesh& aMesh,
602 const TopoDS_Shape& aShape,
603 SMESH_Hypothesis::Hypothesis_Status& aStatus)
606 aStatus = SMESH_Hypothesis::HYP_OK;
610 //=======================================================================
612 //purpose : Compute mesh on a COMPOUND of SOLIDs
613 //=======================================================================
615 bool StdMeshers_Prism_3D::Compute(SMESH_Mesh& theMesh, const TopoDS_Shape& theShape)
617 SMESH_MesherHelper helper( theMesh );
621 int nbSolids = helper.Count( theShape, TopAbs_SOLID, /*skipSame=*/false );
625 TopTools_IndexedDataMapOfShapeListOfShape faceToSolids;
626 TopExp::MapShapesAndAncestors( theShape, TopAbs_FACE, TopAbs_SOLID, faceToSolids );
628 // look for meshed FACEs ("source" FACEs) that must be prism bottoms
629 list< TopoDS_Face > meshedFaces, notQuadMeshedFaces, notQuadFaces;
630 const bool meshHasQuads = ( theMesh.NbQuadrangles() > 0 );
631 //StdMeshers_Quadrangle_2D* quadAlgo = TQuadrangleAlgo::instance( this );
632 for ( int iF = 1; iF <= faceToSolids.Extent(); ++iF )
634 const TopoDS_Face& face = TopoDS::Face( faceToSolids.FindKey( iF ));
635 SMESH_subMesh* faceSM = theMesh.GetSubMesh( face );
636 if ( !faceSM->IsEmpty() )
638 if ( !meshHasQuads ||
639 !helper.IsSameElemGeometry( faceSM->GetSubMeshDS(), SMDSGeom_QUADRANGLE ) ||
640 !helper.IsStructured( faceSM )
642 notQuadMeshedFaces.push_front( face );
643 else if ( myHelper->Count( face, TopAbs_EDGE, /*ignoreSame=*/false ) != 4 )
644 meshedFaces.push_front( face );
646 meshedFaces.push_back( face );
648 // not add not quadrilateral FACE as we can't compute it
649 // else if ( !quadAlgo->CheckNbEdges( theMesh, face ))
650 // // not add not quadrilateral FACE as it can be a prism side
651 // // else if ( myHelper->Count( face, TopAbs_EDGE, /*ignoreSame=*/false ) != 4 )
653 // notQuadFaces.push_back( face );
656 // notQuadFaces are of medium priority, put them before ordinary meshed faces
657 meshedFaces.splice( meshedFaces.begin(), notQuadFaces );
658 // notQuadMeshedFaces are of highest priority, put them before notQuadFaces
659 meshedFaces.splice( meshedFaces.begin(), notQuadMeshedFaces );
661 Prism_3D::TPrismTopo prism;
663 bool selectBottom = meshedFaces.empty();
667 TopoDS_Shape solid = TopExp_Explorer( theShape, TopAbs_SOLID ).Current();
668 if ( !meshedFaces.empty() )
669 prism.myBottom = meshedFaces.front();
670 return ( initPrism( prism, solid, selectBottom ) &&
674 // find propagation chains from already computed EDGEs
675 vector< TopoDS_Edge > computedEdges;
676 getPrecomputedEdges( helper, theShape, computedEdges );
677 myPropagChains = new TopTools_IndexedMapOfShape[ computedEdges.size() + 1 ];
678 SMESHUtils::ArrayDeleter< TopTools_IndexedMapOfShape > pcDel( myPropagChains );
679 for ( size_t i = 0, nb = 0; i < computedEdges.size(); ++i )
681 StdMeshers_ProjectionUtils::GetPropagationEdge( &theMesh, TopoDS_Edge(),
682 computedEdges[i], myPropagChains + nb );
683 if ( myPropagChains[ nb ].Extent() < 2 ) // an empty map is a termination sign
684 myPropagChains[ nb ].Clear();
689 TopTools_MapOfShape meshedSolids;
690 list< Prism_3D::TPrismTopo > meshedPrism;
691 list< TopoDS_Face > suspectSourceFaces;
692 TopTools_ListIteratorOfListOfShape solidIt;
694 while ( meshedSolids.Extent() < nbSolids )
696 if ( _computeCanceled )
697 return toSM( error( SMESH_ComputeError::New(COMPERR_CANCELED)));
699 // compute prisms having avident computed source FACE
700 while ( !meshedFaces.empty() )
702 TopoDS_Face face = meshedFaces.front();
703 meshedFaces.pop_front();
704 TopTools_ListOfShape& solidList = faceToSolids.ChangeFromKey( face );
705 while ( !solidList.IsEmpty() )
707 TopoDS_Shape solid = solidList.First();
708 solidList.RemoveFirst();
709 if ( meshedSolids.Add( solid ))
712 prism.myBottom = face;
713 if ( !initPrism( prism, solid, selectBottom ) ||
717 SMESHDS_SubMesh* smDS = theMesh.GetMeshDS()->MeshElements( prism.myTop );
718 if ( !myHelper->IsSameElemGeometry( smDS, SMDSGeom_QUADRANGLE ))
720 meshedFaces.push_front( prism.myTop );
724 suspectSourceFaces.push_back( prism.myTop );
726 meshedPrism.push_back( prism );
730 if ( meshedSolids.Extent() == nbSolids )
733 // below in the loop we try to find source FACEs somehow
735 // project mesh from source FACEs of computed prisms to
736 // prisms sharing wall FACEs
737 list< Prism_3D::TPrismTopo >::iterator prismIt = meshedPrism.begin();
738 for ( ; prismIt != meshedPrism.end(); ++prismIt )
740 for ( size_t iW = 0; iW < prismIt->myWallQuads.size(); ++iW )
742 Prism_3D::TQuadList::iterator wQuad = prismIt->myWallQuads[iW].begin();
743 for ( ; wQuad != prismIt->myWallQuads[iW].end(); ++ wQuad )
745 const TopoDS_Face& wFace = (*wQuad)->face;
746 TopTools_ListOfShape& solidList = faceToSolids.ChangeFromKey( wFace );
747 solidIt.Initialize( solidList );
748 while ( solidIt.More() )
750 const TopoDS_Shape& solid = solidIt.Value();
751 if ( meshedSolids.Contains( solid )) {
752 solidList.Remove( solidIt );
753 continue; // already computed prism
755 if ( myHelper->IsBlock( solid )) {
757 continue; // too trivial
759 // find a source FACE of the SOLID: it's a FACE sharing a bottom EDGE with wFace
760 const TopoDS_Edge& wEdge = (*wQuad)->side[ QUAD_TOP_SIDE ].grid->Edge(0);
761 PShapeIteratorPtr faceIt = myHelper->GetAncestors( wEdge, *myHelper->GetMesh(),
763 while ( const TopoDS_Shape* f = faceIt->next() )
765 const TopoDS_Face& candidateF = TopoDS::Face( *f );
766 if ( candidateF.IsSame( wFace )) continue;
767 // select a source FACE: prismIt->myBottom or prismIt->myTop
768 TopoDS_Face sourceF = prismIt->myBottom;
769 for ( TopExp_Explorer v( prismIt->myTop, TopAbs_VERTEX ); v.More(); v.Next() )
770 if ( myHelper->IsSubShape( v.Current(), candidateF )) {
771 sourceF = prismIt->myTop;
775 prism.myBottom = candidateF;
776 mySetErrorToSM = false;
777 if ( !myHelper->IsSubShape( candidateF, prismIt->myShape3D ) &&
778 myHelper ->IsSubShape( candidateF, solid ) &&
779 !myHelper->GetMesh()->GetSubMesh( candidateF )->IsMeshComputed() &&
780 initPrism( prism, solid, /*selectBottom=*/false ) &&
781 !myHelper->GetMesh()->GetSubMesh( prism.myTop )->IsMeshComputed() &&
782 !myHelper->GetMesh()->GetSubMesh( prism.myBottom )->IsMeshComputed() &&
783 project2dMesh( sourceF, prism.myBottom ))
785 mySetErrorToSM = true;
786 if ( !compute( prism ))
788 SMESHDS_SubMesh* smDS = theMesh.GetMeshDS()->MeshElements( prism.myTop );
789 if ( !myHelper->IsSameElemGeometry( smDS, SMDSGeom_QUADRANGLE ))
791 meshedFaces.push_front( prism.myTop );
792 meshedFaces.push_front( prism.myBottom );
793 selectBottom = false;
795 meshedPrism.push_back( prism );
796 meshedSolids.Add( solid );
800 mySetErrorToSM = true;
802 if ( meshedSolids.Contains( solid ))
803 solidList.Remove( solidIt );
809 if ( !meshedFaces.empty() )
810 break; // to compute prisms with avident sources
813 if ( meshedFaces.empty() )
815 meshedFaces.splice( meshedFaces.end(), suspectSourceFaces );
819 // find FACEs with local 1D hyps, which has to be computed by now,
820 // or at least any computed FACEs
821 if ( meshedFaces.empty() )
824 for ( int iF = 1; iF <= faceToSolids.Extent(); ++iF )
826 const TopoDS_Face& face = TopoDS::Face( faceToSolids.FindKey( iF ));
827 const TopTools_ListOfShape& solidList = faceToSolids.FindFromKey( face );
828 if ( solidList.IsEmpty() ) continue;
829 SMESH_subMesh* faceSM = theMesh.GetSubMesh( face );
830 if ( !faceSM->IsEmpty() )
832 int nbFaces = faceSM->GetSubMeshDS()->NbElements();
833 if ( prevNbFaces < nbFaces )
835 if ( !meshedFaces.empty() ) meshedFaces.pop_back();
836 meshedFaces.push_back( face ); // lower priority
838 prevNbFaces = nbFaces;
843 bool allSubMeComputed = true;
844 SMESH_subMeshIteratorPtr smIt = faceSM->getDependsOnIterator(false,true);
845 while ( smIt->more() && allSubMeComputed )
846 allSubMeComputed = smIt->next()->IsMeshComputed();
847 if ( allSubMeComputed )
849 faceSM->ComputeStateEngine( SMESH_subMesh::COMPUTE );
850 if ( !faceSM->IsEmpty() ) {
851 meshedFaces.push_front( face ); // higher priority
856 faceSM->ComputeStateEngine( SMESH_subMesh::CHECK_COMPUTE_STATE );
864 // TODO. there are other ways to find out the source FACE:
865 // propagation, topological similarity, etc...
867 // simply try to mesh all not meshed SOLIDs
868 if ( meshedFaces.empty() )
870 for ( TopExp_Explorer solid( theShape, TopAbs_SOLID ); solid.More(); solid.Next() )
872 mySetErrorToSM = false;
874 if ( !meshedSolids.Contains( solid.Current() ) &&
875 initPrism( prism, solid.Current() ))
877 mySetErrorToSM = true;
878 if ( !compute( prism ))
880 meshedFaces.push_front( prism.myTop );
881 meshedFaces.push_front( prism.myBottom );
882 meshedPrism.push_back( prism );
883 meshedSolids.Add( solid.Current() );
886 mySetErrorToSM = true;
890 if ( meshedFaces.empty() ) // set same error to 10 not-computed solids
892 SMESH_ComputeErrorPtr err = SMESH_ComputeError::New
893 ( COMPERR_BAD_INPUT_MESH, "No meshed source face found", this );
895 const int maxNbErrors = 10; // limit nb errors not to overload the Compute dialog
896 TopExp_Explorer solid( theShape, TopAbs_SOLID );
897 for ( int i = 0; ( i < maxNbErrors && solid.More() ); ++i, solid.Next() )
898 if ( !meshedSolids.Contains( solid.Current() ))
900 SMESH_subMesh* sm = theMesh.GetSubMesh( solid.Current() );
901 sm->GetComputeError() = err;
906 return error( COMPERR_OK );
909 //================================================================================
911 * \brief Find wall faces by bottom edges
913 //================================================================================
915 bool StdMeshers_Prism_3D::getWallFaces( Prism_3D::TPrismTopo & thePrism,
916 const int totalNbFaces)
918 thePrism.myWallQuads.clear();
920 SMESH_Mesh* mesh = myHelper->GetMesh();
922 StdMeshers_Quadrangle_2D* quadAlgo = TQuadrangleAlgo::instance( this, myHelper );
924 TopTools_MapOfShape faceMap;
925 TopTools_IndexedDataMapOfShapeListOfShape edgeToFaces;
926 TopExp::MapShapesAndAncestors( thePrism.myShape3D,
927 TopAbs_EDGE, TopAbs_FACE, edgeToFaces );
929 // ------------------------------
930 // Get the 1st row of wall FACEs
931 // ------------------------------
933 list< TopoDS_Edge >::iterator edge = thePrism.myBottomEdges.begin();
934 std::list< int >::iterator nbE = thePrism.myNbEdgesInWires.begin();
935 std::list< int > nbQuadsPerWire;
936 int iE = 0, iWire = 0;
937 while ( edge != thePrism.myBottomEdges.end() )
940 if ( SMESH_Algo::isDegenerated( *edge ))
942 edge = thePrism.myBottomEdges.erase( edge );
948 bool hasWallFace = false;
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 ))
956 Prism_3D::TQuadList quadList( 1, quadAlgo->CheckNbEdges( *mesh, face ));
957 if ( !quadList.back() )
958 return toSM( error(TCom("Side face #") << shapeID( face )
959 << " not meshable with quadrangles"));
960 bool isCompositeBase = ! setBottomEdge( *edge, quadList.back(), face );
961 if ( isCompositeBase )
963 // it's OK if all EDGEs of the bottom side belongs to the bottom FACE
964 StdMeshers_FaceSidePtr botSide = quadList.back()->side[ QUAD_BOTTOM_SIDE ];
965 for ( int iE = 0; iE < botSide->NbEdges(); ++iE )
966 if ( !myHelper->IsSubShape( botSide->Edge(iE), thePrism.myBottom ))
967 return toSM( error(TCom("Composite 'horizontal' edges are not supported")));
969 if ( faceMap.Add( face ))
971 setWireIndex( quadList.back(), iWire ); // for use in makeQuadsForOutInProjection()
972 thePrism.myWallQuads.push_back( quadList );
981 else // seam edge (IPAL53561)
983 edge = thePrism.myBottomEdges.erase( edge );
993 int nbQuadPrev = std::accumulate( nbQuadsPerWire.begin(), nbQuadsPerWire.end(), 0 );
994 nbQuadsPerWire.push_back( thePrism.myWallQuads.size() - nbQuadPrev );
998 // -------------------------
999 // Find the rest wall FACEs
1000 // -------------------------
1002 // Compose a vector of indixes of right neighbour FACE for each wall FACE
1003 // that is not so evident in case of several WIREs in the bottom FACE
1004 thePrism.myRightQuadIndex.clear();
1005 for ( size_t i = 0; i < thePrism.myWallQuads.size(); ++i )
1007 thePrism.myRightQuadIndex.push_back( i+1 ); // OK for all but the last EDGE of a WIRE
1009 list< int >::iterator nbQinW = nbQuadsPerWire.begin();
1010 for ( int iLeft = 0; nbQinW != nbQuadsPerWire.end(); ++nbQinW )
1012 thePrism.myRightQuadIndex[ iLeft + *nbQinW - 1 ] = iLeft; // for the last EDGE of a WIRE
1016 while ( totalNbFaces - faceMap.Extent() > 2 )
1018 // find wall FACEs adjacent to each of wallQuads by the right side EDGE
1021 nbKnownFaces = faceMap.Extent();
1022 StdMeshers_FaceSidePtr rightSide, topSide; // sides of the quad
1023 for ( size_t i = 0; i < thePrism.myWallQuads.size(); ++i )
1025 rightSide = thePrism.myWallQuads[i].back()->side[ QUAD_RIGHT_SIDE ];
1026 for ( int iE = 0; iE < rightSide->NbEdges(); ++iE ) // rightSide can be composite
1028 const TopoDS_Edge & rightE = rightSide->Edge( iE );
1029 TopTools_ListIteratorOfListOfShape face( edgeToFaces.FindFromKey( rightE ));
1030 for ( ; face.More(); face.Next() )
1031 if ( faceMap.Add( face.Value() ))
1033 // a new wall FACE encountered, store it in thePrism.myWallQuads
1034 const int iRight = thePrism.myRightQuadIndex[i];
1035 topSide = thePrism.myWallQuads[ iRight ].back()->side[ QUAD_TOP_SIDE ];
1036 const TopoDS_Edge& newBotE = topSide->Edge(0);
1037 const TopoDS_Shape& newWallF = face.Value();
1038 thePrism.myWallQuads[ iRight ].push_back( quadAlgo->CheckNbEdges( *mesh, newWallF ));
1039 if ( !thePrism.myWallQuads[ iRight ].back() )
1040 return toSM( error(TCom("Side face #") << shapeID( newWallF ) <<
1041 " not meshable with quadrangles"));
1042 if ( ! setBottomEdge( newBotE, thePrism.myWallQuads[ iRight ].back(), newWallF ))
1043 return toSM( error(TCom("Composite 'horizontal' edges are not supported")));
1047 } while ( nbKnownFaces != faceMap.Extent() );
1049 // find wall FACEs adjacent to each of thePrism.myWallQuads by the top side EDGE
1050 if ( totalNbFaces - faceMap.Extent() > 2 )
1052 const int nbFoundWalls = faceMap.Extent();
1053 for ( size_t i = 0; i < thePrism.myWallQuads.size(); ++i )
1055 StdMeshers_FaceSidePtr topSide = thePrism.myWallQuads[i].back()->side[ QUAD_TOP_SIDE ];
1056 const TopoDS_Edge & topE = topSide->Edge( 0 );
1057 if ( topSide->NbEdges() > 1 )
1058 return toSM( error(COMPERR_BAD_SHAPE, TCom("Side face #") <<
1059 shapeID( thePrism.myWallQuads[i].back()->face )
1060 << " has a composite top edge"));
1061 TopTools_ListIteratorOfListOfShape faceIt( edgeToFaces.FindFromKey( topE ));
1062 for ( ; faceIt.More(); faceIt.Next() )
1063 if ( faceMap.Add( faceIt.Value() ))
1065 // a new wall FACE encountered, store it in wallQuads
1066 thePrism.myWallQuads[ i ].push_back( quadAlgo->CheckNbEdges( *mesh, faceIt.Value() ));
1067 if ( !thePrism.myWallQuads[ i ].back() )
1068 return toSM( error(TCom("Side face #") << shapeID( faceIt.Value() ) <<
1069 " not meshable with quadrangles"));
1070 if ( ! setBottomEdge( topE, thePrism.myWallQuads[ i ].back(), faceIt.Value() ))
1071 return toSM( error(TCom("Composite 'horizontal' edges are not supported")));
1072 if ( totalNbFaces - faceMap.Extent() == 2 )
1074 i = thePrism.myWallQuads.size(); // to quit from the outer loop
1079 if ( nbFoundWalls == faceMap.Extent() )
1080 return toSM( error("Failed to find wall faces"));
1083 } // while ( totalNbFaces - faceMap.Extent() > 2 )
1085 // ------------------
1086 // Find the top FACE
1087 // ------------------
1089 if ( thePrism.myTop.IsNull() )
1091 // now only top and bottom FACEs are not in the faceMap
1092 faceMap.Add( thePrism.myBottom );
1093 for ( TopExp_Explorer f( thePrism.myShape3D, TopAbs_FACE ); f.More(); f.Next() )
1094 if ( !faceMap.Contains( f.Current() )) {
1095 thePrism.myTop = TopoDS::Face( f.Current() );
1098 if ( thePrism.myTop.IsNull() )
1099 return toSM( error("Top face not found"));
1102 // Check that the top FACE shares all the top EDGEs
1103 for ( size_t i = 0; i < thePrism.myWallQuads.size(); ++i )
1105 StdMeshers_FaceSidePtr topSide = thePrism.myWallQuads[i].back()->side[ QUAD_TOP_SIDE ];
1106 const TopoDS_Edge & topE = topSide->Edge( 0 );
1107 if ( !myHelper->IsSubShape( topE, thePrism.myTop ))
1108 return toSM( error( TCom("Wrong source face: #") << shapeID( thePrism.myBottom )));
1114 //=======================================================================
1115 //function : compute
1116 //purpose : Compute mesh on a SOLID
1117 //=======================================================================
1119 bool StdMeshers_Prism_3D::compute(const Prism_3D::TPrismTopo& thePrism)
1121 myHelper->IsQuadraticSubMesh( thePrism.myShape3D );
1122 if ( _computeCanceled )
1123 return toSM( error( SMESH_ComputeError::New(COMPERR_CANCELED)));
1125 // Assure the bottom is meshed
1126 if ( !computeBase( thePrism ))
1129 // Make all side FACEs of thePrism meshed with quads
1130 if ( !computeWalls( thePrism ))
1133 // Analyse mesh and geometry to find all block sub-shapes and submeshes
1134 // (after fixing IPAL52499 myBlock is used as a holder of boundary nodes
1135 // and for 2D projection in hard cases where StdMeshers_Projection_2D fails;
1136 // location of internal nodes is usually computed by StdMeshers_Sweeper)
1137 if ( !myBlock.Init( myHelper, thePrism ))
1138 return toSM( error( myBlock.GetError()));
1140 SMESHDS_Mesh* meshDS = myHelper->GetMeshDS();
1142 int volumeID = meshDS->ShapeToIndex( thePrism.myShape3D );
1144 // Try to get gp_Trsf to get all nodes from bottom ones
1145 vector<gp_Trsf> trsf;
1146 gp_Trsf bottomToTopTrsf;
1147 // if ( !myBlock.GetLayersTransformation( trsf, thePrism ))
1149 // else if ( !trsf.empty() )
1150 // bottomToTopTrsf = trsf.back();
1152 // To compute coordinates of a node inside a block using "block approach",
1153 // it is necessary to know
1154 // 1. normalized parameters of the node by which
1155 // 2. coordinates of node projections on all block sub-shapes are computed
1157 // So we fill projections on vertices at once as they are same for all nodes
1158 myShapeXYZ.resize( myBlock.NbSubShapes() );
1159 for ( int iV = SMESH_Block::ID_FirstV; iV < SMESH_Block::ID_FirstE; ++iV ) {
1160 myBlock.VertexPoint( iV, myShapeXYZ[ iV ]);
1161 SHOWYXZ("V point " <<iV << " ", myShapeXYZ[ iV ]);
1164 // Projections on the top and bottom faces are taken from nodes existing
1165 // on these faces; find correspondence between bottom and top nodes
1166 myUseBlock = false; // is set to true if projection is done using "block approach"
1167 myBotToColumnMap.clear();
1168 if ( !assocOrProjBottom2Top( bottomToTopTrsf, thePrism ) ) // it also fills myBotToColumnMap
1171 // If all "vertical" EDGEs are straight, then all nodes of an internal node column
1172 // are located on a line connecting the top node and the bottom node.
1173 bool isStrightColunm = allVerticalEdgesStraight( thePrism );
1174 if ( isStrightColunm )
1177 // Create nodes inside the block
1181 // use transformation (issue 0020680, IPAL0052499) or a "straight line" approach
1182 StdMeshers_Sweeper sweeper;
1183 sweeper.myHelper = myHelper;
1184 sweeper.myBotFace = thePrism.myBottom;
1185 sweeper.myTopFace = thePrism.myTop;
1187 // load boundary nodes into sweeper
1189 std::set< const SMDS_MeshNode* > usedEndNodes;
1190 list< TopoDS_Edge >::const_iterator edge = thePrism.myBottomEdges.begin();
1191 for ( ; edge != thePrism.myBottomEdges.end(); ++edge )
1193 int edgeID = meshDS->ShapeToIndex( *edge );
1194 TParam2ColumnMap* u2col = const_cast<TParam2ColumnMap*>
1195 ( myBlock.GetParam2ColumnMap( edgeID, dummy ));
1197 TParam2ColumnMap::iterator u2colIt = u2col->begin(), u2colEnd = u2col->end();
1198 const SMDS_MeshNode* n0 = u2colIt->second[0];
1199 const SMDS_MeshNode* n1 = u2col->rbegin()->second[0];
1200 if ( !usedEndNodes.insert ( n0 ).second ) ++u2colIt;
1201 if ( !usedEndNodes.insert ( n1 ).second ) --u2colEnd;
1203 for ( ; u2colIt != u2colEnd; ++u2colIt )
1204 sweeper.myBndColumns.push_back( & u2colIt->second );
1206 // load node columns inside the bottom FACE
1207 sweeper.myIntColumns.reserve( myBotToColumnMap.size() );
1208 TNode2ColumnMap::iterator bot_column = myBotToColumnMap.begin();
1209 for ( ; bot_column != myBotToColumnMap.end(); ++bot_column )
1210 sweeper.myIntColumns.push_back( & bot_column->second );
1212 myHelper->SetElementsOnShape( true );
1214 if ( !isStrightColunm )
1216 double tol = getSweepTolerance( thePrism );
1217 bool allowHighBndError = !isSimpleBottom( thePrism );
1218 myUseBlock = !sweeper.ComputeNodesByTrsf( tol, allowHighBndError );
1220 else if ( sweeper.CheckSameZ() )
1222 myUseBlock = !sweeper.ComputeNodesOnStraightSameZ();
1226 myUseBlock = !sweeper.ComputeNodesOnStraight();
1228 myHelper->SetElementsOnShape( false );
1231 if ( myUseBlock ) // use block approach
1233 // loop on nodes inside the bottom face
1234 Prism_3D::TNode prevBNode;
1235 TNode2ColumnMap::iterator bot_column = myBotToColumnMap.begin();
1236 for ( ; bot_column != myBotToColumnMap.end(); ++bot_column )
1238 const Prism_3D::TNode& tBotNode = bot_column->first; // bottom TNode
1239 if ( tBotNode.GetPositionType() != SMDS_TOP_FACE &&
1240 myBlock.HasNodeColumn( tBotNode.myNode ))
1241 continue; // node is not inside the FACE
1243 // column nodes; middle part of the column are zero pointers
1244 TNodeColumn& column = bot_column->second;
1246 // check if a column is already computed using non-block approach
1248 for ( i = 0; i < column.size(); ++i )
1251 if ( i == column.size() )
1252 continue; // all nodes created
1254 gp_XYZ botParams, topParams;
1255 if ( !tBotNode.HasParams() )
1257 // compute bottom node parameters
1258 gp_XYZ paramHint(-1,-1,-1);
1259 if ( prevBNode.IsNeighbor( tBotNode ))
1260 paramHint = prevBNode.GetParams();
1261 if ( !myBlock.ComputeParameters( tBotNode.GetCoords(), tBotNode.ChangeParams(),
1262 ID_BOT_FACE, paramHint ))
1263 return toSM( error(TCom("Can't compute normalized parameters for node ")
1264 << tBotNode.myNode->GetID() << " on the face #"
1265 << myBlock.SubMesh( ID_BOT_FACE )->GetId() ));
1266 prevBNode = tBotNode;
1268 botParams = topParams = tBotNode.GetParams();
1269 topParams.SetZ( 1 );
1271 // compute top node parameters
1272 if ( column.size() > 2 ) {
1273 gp_Pnt topCoords = gpXYZ( column.back() );
1274 if ( !myBlock.ComputeParameters( topCoords, topParams, ID_TOP_FACE, topParams ))
1275 return toSM( error(TCom("Can't compute normalized parameters ")
1276 << "for node " << column.back()->GetID()
1277 << " on the face #"<< column.back()->getshapeId() ));
1280 else // top nodes are created by projection using parameters
1282 botParams = topParams = tBotNode.GetParams();
1283 topParams.SetZ( 1 );
1286 myShapeXYZ[ ID_BOT_FACE ] = tBotNode.GetCoords();
1287 myShapeXYZ[ ID_TOP_FACE ] = gpXYZ( column.back() );
1290 TNodeColumn::iterator columnNodes = column.begin();
1291 for ( int z = 0; columnNodes != column.end(); ++columnNodes, ++z)
1293 const SMDS_MeshNode* & node = *columnNodes;
1294 if ( node ) continue; // skip bottom or top node
1296 // params of a node to create
1297 double rz = (double) z / (double) ( column.size() - 1 );
1298 gp_XYZ params = botParams * ( 1 - rz ) + topParams * rz;
1300 // set coords on all faces and nodes
1301 const int nbSideFaces = 4;
1302 int sideFaceIDs[nbSideFaces] = { SMESH_Block::ID_Fx0z,
1303 SMESH_Block::ID_Fx1z,
1304 SMESH_Block::ID_F0yz,
1305 SMESH_Block::ID_F1yz };
1306 for ( int iF = 0; iF < nbSideFaces; ++iF )
1307 if ( !setFaceAndEdgesXYZ( sideFaceIDs[ iF ], params, z ))
1310 // compute coords for a new node
1312 if ( !SMESH_Block::ShellPoint( params, myShapeXYZ, coords ))
1313 return toSM( error("Can't compute coordinates by normalized parameters"));
1315 // if ( !meshDS->MeshElements( volumeID ) ||
1316 // meshDS->MeshElements( volumeID )->NbNodes() == 0 )
1317 // pointsToPython(myShapeXYZ);
1318 SHOWYXZ("TOPFacePoint ",myShapeXYZ[ ID_TOP_FACE]);
1319 SHOWYXZ("BOT Node "<< tBotNode.myNode->GetID(),gpXYZ(tBotNode.myNode));
1320 SHOWYXZ("ShellPoint ",coords);
1323 node = meshDS->AddNode( coords.X(), coords.Y(), coords.Z() );
1324 meshDS->SetNodeInVolume( node, volumeID );
1326 if ( _computeCanceled )
1329 } // loop on bottom nodes
1334 SMESHDS_SubMesh* smDS = myBlock.SubMeshDS( ID_BOT_FACE );
1335 if ( !smDS ) return toSM( error(COMPERR_BAD_INPUT_MESH, "Null submesh"));
1337 // loop on bottom mesh faces
1338 vector< const TNodeColumn* > columns;
1339 SMDS_ElemIteratorPtr faceIt = smDS->GetElements();
1340 while ( faceIt->more() )
1342 const SMDS_MeshElement* face = faceIt->next();
1343 if ( !face || face->GetType() != SMDSAbs_Face )
1346 // find node columns for each node
1347 int nbNodes = face->NbCornerNodes();
1348 columns.resize( nbNodes );
1349 for ( int i = 0; i < nbNodes; ++i )
1351 const SMDS_MeshNode* n = face->GetNode( i );
1352 columns[ i ] = NULL;
1354 if ( n->GetPosition()->GetTypeOfPosition() != SMDS_TOP_FACE )
1355 columns[ i ] = myBlock.GetNodeColumn( n );
1357 if ( !columns[ i ] )
1359 TNode2ColumnMap::iterator bot_column = myBotToColumnMap.find( n );
1360 if ( bot_column == myBotToColumnMap.end() )
1361 return toSM( error(TCom("No side nodes found above node ") << n->GetID() ));
1362 columns[ i ] = & bot_column->second;
1366 if ( !AddPrisms( columns, myHelper ))
1367 return toSM( error("Different 'vertical' discretization"));
1369 } // loop on bottom mesh faces
1372 myBotToColumnMap.clear();
1375 // update state of sub-meshes (mostly in order to erase improper errors)
1376 SMESH_subMesh* sm = myHelper->GetMesh()->GetSubMesh( thePrism.myShape3D );
1377 SMESH_subMeshIteratorPtr smIt = sm->getDependsOnIterator(/*includeSelf=*/true);
1378 while ( smIt->more() )
1381 sm->GetComputeError().reset();
1382 sm->ComputeStateEngine( SMESH_subMesh::CHECK_COMPUTE_STATE );
1388 //=======================================================================
1389 //function : computeBase
1390 //purpose : Compute the base face of a prism
1391 //=======================================================================
1393 bool StdMeshers_Prism_3D::computeBase(const Prism_3D::TPrismTopo& thePrism)
1395 SMESH_Mesh* mesh = myHelper->GetMesh();
1396 SMESH_subMesh* botSM = mesh->GetSubMesh( thePrism.myBottom );
1397 if (( botSM->IsEmpty() ) &&
1398 ( ! botSM->GetAlgo() ||
1399 ! _gen->Compute( *botSM->GetFather(), botSM->GetSubShape(), /*shapeOnly=*/true )))
1401 // find any applicable algorithm assigned to any FACE of the main shape
1402 std::vector< TopoDS_Shape > faces;
1403 if ( myPrevBottomSM &&
1404 myPrevBottomSM->GetAlgo()->IsApplicableToShape( thePrism.myBottom, /*all=*/false ))
1405 faces.push_back( myPrevBottomSM->GetSubShape() );
1407 TopExp_Explorer faceIt( mesh->GetShapeToMesh(), TopAbs_FACE );
1408 for ( ; faceIt.More(); faceIt.Next() )
1409 faces.push_back( faceIt.Current() );
1411 faces.push_back( TopoDS_Shape() ); // to try quadrangle algorithm
1413 SMESH_Algo* algo = 0;
1414 for ( size_t i = 0; i < faces.size() && botSM->IsEmpty(); ++i )
1416 if ( faces[i].IsNull() ) algo = TQuadrangleAlgo::instance( this, myHelper );
1417 else algo = mesh->GetSubMesh( faces[i] )->GetAlgo();
1418 if ( algo && algo->IsApplicableToShape( thePrism.myBottom, /*all=*/false ))
1420 // try to compute the bottom FACE
1421 if ( algo->NeedDiscreteBoundary() )
1423 // compute sub-shapes
1424 SMESH_subMeshIteratorPtr smIt = botSM->getDependsOnIterator(false,false);
1426 while ( smIt->more() && subOK )
1428 SMESH_subMesh* sub = smIt->next();
1429 sub->ComputeStateEngine( SMESH_subMesh::COMPUTE );
1430 subOK = sub->IsMeshComputed();
1437 algo->InitComputeError();
1438 algo->Compute( *mesh, botSM->GetSubShape() );
1446 if ( botSM->IsEmpty() )
1447 return error( COMPERR_BAD_INPUT_MESH,
1448 TCom( "No mesher defined to compute the base face #")
1449 << shapeID( thePrism.myBottom ));
1451 if ( botSM->GetAlgo() )
1452 myPrevBottomSM = botSM;
1457 //=======================================================================
1458 //function : computeWalls
1459 //purpose : Compute 2D mesh on walls FACEs of a prism
1460 //=======================================================================
1462 bool StdMeshers_Prism_3D::computeWalls(const Prism_3D::TPrismTopo& thePrism)
1464 SMESH_Mesh* mesh = myHelper->GetMesh();
1465 SMESHDS_Mesh* meshDS = myHelper->GetMeshDS();
1466 DBGOUT( endl << "COMPUTE Prism " << meshDS->ShapeToIndex( thePrism.myShape3D ));
1468 TProjction1dAlgo* projector1D = TProjction1dAlgo::instance( this );
1469 StdMeshers_Quadrangle_2D* quadAlgo = TQuadrangleAlgo::instance( this, myHelper );
1471 // SMESH_HypoFilter hyp1dFilter( SMESH_HypoFilter::IsAlgo(),/*not=*/true);
1472 // hyp1dFilter.And( SMESH_HypoFilter::HasDim( 1 ));
1473 // hyp1dFilter.And( SMESH_HypoFilter::IsMoreLocalThan( thePrism.myShape3D, *mesh ));
1475 // Discretize equally 'vertical' EDGEs
1476 // -----------------------------------
1477 // find source FACE sides for projection: either already computed ones or
1478 // the 'most composite' ones
1479 const size_t nbWalls = thePrism.myWallQuads.size();
1480 vector< int > wgt( nbWalls, 0 ); // "weight" of a wall
1481 for ( size_t iW = 0; iW != nbWalls; ++iW )
1483 Prism_3D::TQuadList::const_iterator quad = thePrism.myWallQuads[iW].begin();
1484 for ( ; quad != thePrism.myWallQuads[iW].end(); ++quad )
1486 StdMeshers_FaceSidePtr lftSide = (*quad)->side[ QUAD_LEFT_SIDE ];
1487 lftSide->Reverse(); // to go up
1488 for ( int i = 0; i < lftSide->NbEdges(); ++i )
1491 const TopoDS_Edge& E = lftSide->Edge(i);
1492 if ( mesh->GetSubMesh( E )->IsMeshComputed() )
1495 wgt[ myHelper->WrapIndex( iW+1, nbWalls)] += 10;
1496 wgt[ myHelper->WrapIndex( iW-1, nbWalls)] += 10;
1498 // else if ( mesh->GetHypothesis( E, hyp1dFilter, true )) // local hypothesis!
1502 // in quadratic mesh, pass ignoreMediumNodes to quad sides
1503 if ( myHelper->GetIsQuadratic() )
1505 quad = thePrism.myWallQuads[iW].begin();
1506 for ( ; quad != thePrism.myWallQuads[iW].end(); ++quad )
1507 for ( int i = 0; i < NB_QUAD_SIDES; ++i )
1508 (*quad)->side[ i ].grid->SetIgnoreMediumNodes( true );
1511 multimap< int, int > wgt2quad;
1512 for ( size_t iW = 0; iW != nbWalls; ++iW )
1513 wgt2quad.insert( make_pair( wgt[ iW ], iW ));
1515 // artificial quads to do outer <-> inner wall projection
1516 std::map< int, FaceQuadStruct > iW2oiQuads;
1517 std::map< int, FaceQuadStruct >::iterator w2oiq;
1518 makeQuadsForOutInProjection( thePrism, wgt2quad, iW2oiQuads );
1520 // Project 'vertical' EDGEs, from left to right
1521 multimap< int, int >::reverse_iterator w2q = wgt2quad.rbegin();
1522 for ( ; w2q != wgt2quad.rend(); ++w2q )
1524 const int iW = w2q->second;
1525 const Prism_3D::TQuadList& quads = thePrism.myWallQuads[ iW ];
1526 Prism_3D::TQuadList::const_iterator quad = quads.begin();
1527 for ( ; quad != quads.end(); ++quad )
1529 StdMeshers_FaceSidePtr rgtSide = (*quad)->side[ QUAD_RIGHT_SIDE ]; // tgt
1530 StdMeshers_FaceSidePtr lftSide = (*quad)->side[ QUAD_LEFT_SIDE ]; // src
1531 bool swapLeftRight = ( lftSide->NbSegments( /*update=*/true ) == 0 &&
1532 rgtSide->NbSegments( /*update=*/true ) > 0 );
1533 if ( swapLeftRight )
1534 std::swap( lftSide, rgtSide );
1536 bool isArtificialQuad = (( w2oiq = iW2oiQuads.find( iW )) != iW2oiQuads.end() );
1537 if ( isArtificialQuad )
1539 // reset sides to perform the outer <-> inner projection
1540 FaceQuadStruct& oiQuad = w2oiq->second;
1541 rgtSide = oiQuad.side[ QUAD_RIGHT_SIDE ];
1542 lftSide = oiQuad.side[ QUAD_LEFT_SIDE ];
1543 iW2oiQuads.erase( w2oiq );
1546 // assure that all the source (left) EDGEs are meshed
1547 int nbSrcSegments = 0;
1548 for ( int i = 0; i < lftSide->NbEdges(); ++i )
1550 if ( isArtificialQuad )
1552 nbSrcSegments = lftSide->NbPoints()-1;
1555 const TopoDS_Edge& srcE = lftSide->Edge(i);
1556 SMESH_subMesh* srcSM = mesh->GetSubMesh( srcE );
1557 if ( !srcSM->IsMeshComputed() ) {
1558 DBGOUT( "COMPUTE V edge " << srcSM->GetId() );
1559 TopoDS_Edge prpgSrcE = findPropagationSource( srcE );
1560 if ( !prpgSrcE.IsNull() ) {
1561 srcSM->ComputeSubMeshStateEngine( SMESH_subMesh::COMPUTE );
1562 projector1D->myHyp.SetSourceEdge( prpgSrcE );
1563 projector1D->Compute( *mesh, srcE );
1564 srcSM->ComputeStateEngine( SMESH_subMesh::CHECK_COMPUTE_STATE );
1567 srcSM->ComputeSubMeshStateEngine( SMESH_subMesh::COMPUTE );
1568 srcSM->ComputeStateEngine ( SMESH_subMesh::COMPUTE );
1570 if ( !srcSM->IsMeshComputed() )
1571 return toSM( error( "Can't compute 1D mesh" ));
1573 nbSrcSegments += srcSM->GetSubMeshDS()->NbElements();
1575 // check target EDGEs
1576 int nbTgtMeshed = 0, nbTgtSegments = 0;
1577 vector< bool > isTgtEdgeComputed( rgtSide->NbEdges() );
1578 for ( int i = 0; i < rgtSide->NbEdges(); ++i )
1580 const TopoDS_Edge& tgtE = rgtSide->Edge(i);
1581 SMESH_subMesh* tgtSM = mesh->GetSubMesh( tgtE );
1582 if ( !( isTgtEdgeComputed[ i ] = tgtSM->IsMeshComputed() )) {
1583 tgtSM->ComputeSubMeshStateEngine( SMESH_subMesh::COMPUTE );
1584 tgtSM->ComputeStateEngine ( SMESH_subMesh::COMPUTE );
1586 if ( tgtSM->IsMeshComputed() ) {
1588 nbTgtSegments += tgtSM->GetSubMeshDS()->NbElements();
1591 if ( rgtSide->NbEdges() == nbTgtMeshed ) // all tgt EDGEs meshed
1593 if ( nbTgtSegments != nbSrcSegments )
1595 bool badMeshRemoved = false;
1596 // remove just computed segments
1597 for ( int i = 0; i < rgtSide->NbEdges(); ++i )
1598 if ( !isTgtEdgeComputed[ i ])
1600 const TopoDS_Edge& tgtE = rgtSide->Edge(i);
1601 SMESH_subMesh* tgtSM = mesh->GetSubMesh( tgtE );
1602 tgtSM->ComputeStateEngine( SMESH_subMesh::CLEAN );
1603 badMeshRemoved = true;
1606 if ( !badMeshRemoved )
1608 for ( int i = 0; i < lftSide->NbEdges(); ++i )
1609 addBadInputElements( meshDS->MeshElements( lftSide->Edge( i )));
1610 for ( int i = 0; i < rgtSide->NbEdges(); ++i )
1611 addBadInputElements( meshDS->MeshElements( rgtSide->Edge( i )));
1612 return toSM( error( TCom("Different nb of segment on logically vertical edges #")
1613 << shapeID( lftSide->Edge(0) ) << " and #"
1614 << shapeID( rgtSide->Edge(0) ) << ": "
1615 << nbSrcSegments << " != " << nbTgtSegments ));
1618 else // if ( nbTgtSegments == nbSrcSegments )
1623 // Compute 'vertical projection'
1624 if ( nbTgtMeshed == 0 )
1626 // compute nodes on target VERTEXes
1627 const UVPtStructVec& srcNodeStr = lftSide->GetUVPtStruct();
1628 if ( srcNodeStr.size() == 0 )
1629 return toSM( error( TCom("Invalid node positions on edge #") <<
1630 lftSide->EdgeID(0) ));
1631 vector< SMDS_MeshNode* > newNodes( srcNodeStr.size() );
1632 for ( int is2ndV = 0; is2ndV < 2; ++is2ndV )
1634 const TopoDS_Edge& E = rgtSide->Edge( is2ndV ? rgtSide->NbEdges()-1 : 0 );
1635 TopoDS_Vertex v = myHelper->IthVertex( is2ndV, E );
1636 mesh->GetSubMesh( v )->ComputeStateEngine( SMESH_subMesh::COMPUTE );
1637 const SMDS_MeshNode* n = SMESH_Algo::VertexNode( v, meshDS );
1638 newNodes[ is2ndV ? newNodes.size()-1 : 0 ] = (SMDS_MeshNode*) n;
1641 // compute nodes on target EDGEs
1642 DBGOUT( "COMPUTE V edge (proj) " << shapeID( lftSide->Edge(0)));
1643 //rgtSide->Reverse(); // direct it same as the lftSide
1644 myHelper->SetElementsOnShape( false ); // myHelper holds the prism shape
1645 TopoDS_Edge tgtEdge;
1646 for ( size_t iN = 1; iN < srcNodeStr.size()-1; ++iN ) // add nodes
1648 gp_Pnt p = rgtSide->Value3d ( srcNodeStr[ iN ].normParam );
1649 double u = rgtSide->Parameter( srcNodeStr[ iN ].normParam, tgtEdge );
1650 newNodes[ iN ] = meshDS->AddNode( p.X(), p.Y(), p.Z() );
1651 meshDS->SetNodeOnEdge( newNodes[ iN ], tgtEdge, u );
1653 for ( size_t iN = 1; iN < srcNodeStr.size(); ++iN ) // add segments
1655 // find an EDGE to set a new segment
1656 std::pair<int, TopAbs_ShapeEnum> id2type =
1657 myHelper->GetMediumPos( newNodes[ iN-1 ], newNodes[ iN ] );
1658 if ( id2type.second != TopAbs_EDGE )
1660 // new nodes are on different EDGEs; put one of them on VERTEX
1661 const int edgeIndex = rgtSide->EdgeIndex( srcNodeStr[ iN-1 ].normParam );
1662 const double vertexParam = rgtSide->LastParameter( edgeIndex );
1663 TopoDS_Vertex vertex = rgtSide->LastVertex( edgeIndex );
1664 const SMDS_MeshNode* vn = SMESH_Algo::VertexNode( vertex, meshDS );
1665 const gp_Pnt p = BRep_Tool::Pnt( vertex );
1666 const int isPrev = ( Abs( srcNodeStr[ iN-1 ].normParam - vertexParam ) <
1667 Abs( srcNodeStr[ iN ].normParam - vertexParam ));
1668 meshDS->UnSetNodeOnShape( newNodes[ iN-isPrev ] );
1669 meshDS->SetNodeOnVertex ( newNodes[ iN-isPrev ], vertex );
1670 meshDS->MoveNode ( newNodes[ iN-isPrev ], p.X(), p.Y(), p.Z() );
1671 id2type.first = newNodes[ iN-(1-isPrev) ]->getshapeId();
1674 SMESH_MeshEditor::TListOfListOfNodes lln( 1, list< const SMDS_MeshNode* >() );
1675 lln.back().push_back ( vn );
1676 lln.back().push_front( newNodes[ iN-isPrev ] ); // to keep
1677 SMESH_MeshEditor( mesh ).MergeNodes( lln );
1680 SMDS_MeshElement* newEdge = myHelper->AddEdge( newNodes[ iN-1 ], newNodes[ iN ] );
1681 meshDS->SetMeshElementOnShape( newEdge, id2type.first );
1683 myHelper->SetElementsOnShape( true );
1684 for ( int i = 0; i < rgtSide->NbEdges(); ++i ) // update state of sub-meshes
1686 const TopoDS_Edge& E = rgtSide->Edge( i );
1687 SMESH_subMesh* tgtSM = mesh->GetSubMesh( E );
1688 tgtSM->ComputeStateEngine( SMESH_subMesh::CHECK_COMPUTE_STATE );
1691 // to continue projection from the just computed side as a source
1692 if ( !swapLeftRight && rgtSide->NbEdges() > 1 && w2q->second == iW )
1694 std::pair<int,int> wgt2quadKeyVal( w2q->first + 1, thePrism.myRightQuadIndex[ iW ]);
1695 wgt2quad.insert( wgt2quadKeyVal ); // it will be skipped by ++w2q
1696 wgt2quad.insert( wgt2quadKeyVal );
1697 w2q = wgt2quad.rbegin();
1702 // HOPE assigned hypotheses are OK, so that equal nb of segments will be generated
1703 //return toSM( error("Partial projection not implemented"));
1705 } // loop on quads of a composite wall side
1706 } // loop on the ordered wall sides
1710 for ( size_t iW = 0; iW != thePrism.myWallQuads.size(); ++iW )
1712 Prism_3D::TQuadList::const_iterator quad = thePrism.myWallQuads[iW].begin();
1713 for ( ; quad != thePrism.myWallQuads[iW].end(); ++quad )
1715 const TopoDS_Face& face = (*quad)->face;
1716 SMESH_subMesh* fSM = mesh->GetSubMesh( face );
1717 if ( ! fSM->IsMeshComputed() )
1719 // Top EDGEs must be projections from the bottom ones
1720 // to compute structured quad mesh on wall FACEs
1721 // ---------------------------------------------------
1722 const TopoDS_Edge& botE = (*quad)->side[ QUAD_BOTTOM_SIDE ].grid->Edge(0);
1723 const TopoDS_Edge& topE = (*quad)->side[ QUAD_TOP_SIDE ].grid->Edge(0);
1724 SMESH_subMesh* botSM = mesh->GetSubMesh( botE );
1725 SMESH_subMesh* topSM = mesh->GetSubMesh( topE );
1726 SMESH_subMesh* srcSM = botSM;
1727 SMESH_subMesh* tgtSM = topSM;
1728 srcSM->ComputeStateEngine( SMESH_subMesh::CHECK_COMPUTE_STATE );
1729 tgtSM->ComputeStateEngine( SMESH_subMesh::CHECK_COMPUTE_STATE );
1730 if ( !srcSM->IsMeshComputed() && tgtSM->IsMeshComputed() )
1731 std::swap( srcSM, tgtSM );
1733 if ( !srcSM->IsMeshComputed() )
1735 DBGOUT( "COMPUTE H edge " << srcSM->GetId());
1736 srcSM->ComputeSubMeshStateEngine( SMESH_subMesh::COMPUTE ); // nodes on VERTEXes
1737 srcSM->ComputeStateEngine( SMESH_subMesh::COMPUTE ); // segments on the EDGE
1740 if ( tgtSM->IsMeshComputed() &&
1741 tgtSM->GetSubMeshDS()->NbNodes() != srcSM->GetSubMeshDS()->NbNodes() )
1743 // the top EDGE is computed differently than the bottom one,
1744 // try to clear a wrong mesh
1745 bool isAdjFaceMeshed = false;
1746 PShapeIteratorPtr fIt = myHelper->GetAncestors( tgtSM->GetSubShape(),
1747 *mesh, TopAbs_FACE );
1748 while ( const TopoDS_Shape* f = fIt->next() )
1749 if (( isAdjFaceMeshed = mesh->GetSubMesh( *f )->IsMeshComputed() ))
1751 if ( isAdjFaceMeshed )
1752 return toSM( error( TCom("Different nb of segment on logically horizontal edges #")
1753 << shapeID( botE ) << " and #"
1754 << shapeID( topE ) << ": "
1755 << tgtSM->GetSubMeshDS()->NbElements() << " != "
1756 << srcSM->GetSubMeshDS()->NbElements() ));
1757 tgtSM->ComputeStateEngine( SMESH_subMesh::CLEAN );
1759 if ( !tgtSM->IsMeshComputed() )
1761 // compute nodes on VERTEXes
1762 SMESH_subMeshIteratorPtr smIt = tgtSM->getDependsOnIterator(/*includeSelf=*/false);
1763 while ( smIt->more() )
1764 smIt->next()->ComputeStateEngine( SMESH_subMesh::COMPUTE );
1766 DBGOUT( "COMPUTE H edge (proj) " << tgtSM->GetId());
1767 projector1D->myHyp.SetSourceEdge( TopoDS::Edge( srcSM->GetSubShape() ));
1768 projector1D->InitComputeError();
1769 bool ok = projector1D->Compute( *mesh, tgtSM->GetSubShape() );
1772 SMESH_ComputeErrorPtr err = projector1D->GetComputeError();
1773 if ( err->IsOK() ) err->myName = COMPERR_ALGO_FAILED;
1774 tgtSM->GetComputeError() = err;
1778 tgtSM->ComputeStateEngine( SMESH_subMesh::CHECK_COMPUTE_STATE );
1781 // Compute quad mesh on wall FACEs
1782 // -------------------------------
1784 // make all EDGES meshed
1785 fSM->ComputeSubMeshStateEngine( SMESH_subMesh::COMPUTE );
1786 if ( !fSM->SubMeshesComputed() )
1787 return toSM( error( COMPERR_BAD_INPUT_MESH,
1788 "Not all edges have valid algorithm and hypothesis"));
1790 quadAlgo->InitComputeError();
1791 DBGOUT( "COMPUTE Quad face " << fSM->GetId());
1792 bool ok = quadAlgo->Compute( *mesh, face );
1793 fSM->GetComputeError() = quadAlgo->GetComputeError();
1796 fSM->ComputeStateEngine( SMESH_subMesh::CHECK_COMPUTE_STATE );
1798 if ( myHelper->GetIsQuadratic() )
1800 // fill myHelper with medium nodes built by quadAlgo
1801 for ( SMDS_ElemIteratorPtr fIt = fSM->GetSubMeshDS()->GetElements(); fIt->more(); )
1802 myHelper->AddTLinks( SMDS_Mesh::DownCast<SMDS_MeshFace>( fIt->next() ));
1810 //=======================================================================
1811 //function : findPropagationSource
1812 //purpose : Returns a source EDGE of propagation to a given EDGE
1813 //=======================================================================
1815 TopoDS_Edge StdMeshers_Prism_3D::findPropagationSource( const TopoDS_Edge& E )
1817 if ( myPropagChains )
1818 for ( size_t i = 0; !myPropagChains[i].IsEmpty(); ++i )
1819 if ( myPropagChains[i].Contains( E ))
1820 return TopoDS::Edge( myPropagChains[i].FindKey( 1 ));
1822 return TopoDS_Edge();
1825 //=======================================================================
1826 //function : makeQuadsForOutInProjection
1827 //purpose : Create artificial wall quads for vertical projection between
1828 // the outer and inner walls
1829 //=======================================================================
1831 void StdMeshers_Prism_3D::makeQuadsForOutInProjection( const Prism_3D::TPrismTopo& thePrism,
1832 multimap< int, int >& wgt2quad,
1833 map< int, FaceQuadStruct >& iQ2oiQuads)
1835 if ( thePrism.NbWires() <= 1 )
1838 std::set< int > doneWires; // processed wires
1840 SMESH_Mesh* mesh = myHelper->GetMesh();
1841 const bool isForward = true;
1842 const bool skipMedium = myHelper->GetIsQuadratic();
1844 // make a source side for all projections
1846 multimap< int, int >::reverse_iterator w2q = wgt2quad.rbegin();
1847 const int iQuad = w2q->second;
1848 const int iWire = getWireIndex( thePrism.myWallQuads[ iQuad ].front() );
1849 doneWires.insert( iWire );
1851 UVPtStructVec srcNodes;
1853 Prism_3D::TQuadList::const_iterator quad = thePrism.myWallQuads[ iQuad ].begin();
1854 for ( ; quad != thePrism.myWallQuads[ iQuad ].end(); ++quad )
1856 StdMeshers_FaceSidePtr lftSide = (*quad)->side[ QUAD_LEFT_SIDE ];
1858 // assure that all the source (left) EDGEs are meshed
1859 for ( int i = 0; i < lftSide->NbEdges(); ++i )
1861 const TopoDS_Edge& srcE = lftSide->Edge(i);
1862 SMESH_subMesh* srcSM = mesh->GetSubMesh( srcE );
1863 if ( !srcSM->IsMeshComputed() ) {
1864 srcSM->ComputeSubMeshStateEngine( SMESH_subMesh::COMPUTE );
1865 srcSM->ComputeStateEngine ( SMESH_subMesh::COMPUTE );
1867 if ( !srcSM->IsMeshComputed() )
1870 const UVPtStructVec& subNodes = lftSide->GetUVPtStruct();
1871 UVPtStructVec::const_iterator subBeg = subNodes.begin(), subEnd = subNodes.end();
1872 if ( !srcNodes.empty() ) ++subBeg;
1873 srcNodes.insert( srcNodes.end(), subBeg, subEnd );
1875 StdMeshers_FaceSidePtr srcSide = StdMeshers_FaceSide::New( srcNodes );
1879 list< TopoDS_Edge > sideEdges;
1881 for ( ++w2q; w2q != wgt2quad.rend(); ++w2q )
1883 const int iQuad = w2q->second;
1884 const Prism_3D::TQuadList& quads = thePrism.myWallQuads[ iQuad ];
1885 const int iWire = getWireIndex( quads.front() );
1886 if ( !doneWires.insert( iWire ).second )
1890 for ( quad = quads.begin(); quad != quads.end(); ++quad )
1892 StdMeshers_FaceSidePtr lftSide = (*quad)->side[ QUAD_LEFT_SIDE ];
1893 for ( int i = 0; i < lftSide->NbEdges(); ++i )
1894 sideEdges.push_back( lftSide->Edge( i ));
1895 face = lftSide->Face();
1897 StdMeshers_FaceSidePtr tgtSide =
1898 StdMeshers_FaceSide::New( face, sideEdges, mesh, isForward, skipMedium, myHelper );
1900 FaceQuadStruct& newQuad = iQ2oiQuads[ iQuad ];
1901 newQuad.side.resize( 4 );
1902 newQuad.side[ QUAD_LEFT_SIDE ] = srcSide;
1903 newQuad.side[ QUAD_RIGHT_SIDE ] = tgtSide;
1905 wgt2quad.insert( *w2q ); // to process this quad after processing the newQuad
1909 //=======================================================================
1910 //function : Evaluate
1912 //=======================================================================
1914 bool StdMeshers_Prism_3D::Evaluate(SMESH_Mesh& theMesh,
1915 const TopoDS_Shape& theShape,
1916 MapShapeNbElems& aResMap)
1918 if ( theShape.ShapeType() == TopAbs_COMPOUND )
1921 for ( TopoDS_Iterator it( theShape ); it.More(); it.Next() )
1922 ok &= Evaluate( theMesh, it.Value(), aResMap );
1925 SMESH_MesherHelper helper( theMesh );
1927 myHelper->SetSubShape( theShape );
1929 // find face contains only triangles
1930 vector < SMESH_subMesh * >meshFaces;
1931 TopTools_SequenceOfShape aFaces;
1932 int NumBase = 0, i = 0, NbQFs = 0;
1933 for (TopExp_Explorer exp(theShape, TopAbs_FACE); exp.More(); exp.Next()) {
1935 aFaces.Append(exp.Current());
1936 SMESH_subMesh *aSubMesh = theMesh.GetSubMesh(exp.Current());
1937 meshFaces.push_back(aSubMesh);
1938 MapShapeNbElemsItr anIt = aResMap.find(meshFaces[i-1]);
1939 if( anIt==aResMap.end() )
1940 return toSM( error( "Submesh can not be evaluated"));
1942 std::vector<int> aVec = (*anIt).second;
1943 int nbtri = Max(aVec[SMDSEntity_Triangle],aVec[SMDSEntity_Quad_Triangle]);
1944 int nbqua = Max(aVec[SMDSEntity_Quadrangle],aVec[SMDSEntity_Quad_Quadrangle]);
1945 if( nbtri==0 && nbqua>0 ) {
1954 std::vector<int> aResVec(SMDSEntity_Last);
1955 for(int i=SMDSEntity_Node; i<SMDSEntity_Last; i++) aResVec[i] = 0;
1956 SMESH_subMesh * sm = theMesh.GetSubMesh(theShape);
1957 aResMap.insert(std::make_pair(sm,aResVec));
1958 return toSM( error( "Submesh can not be evaluated" ));
1961 if(NumBase==0) NumBase = 1; // only quads => set 1 faces as base
1963 // find number of 1d elems for base face
1965 TopTools_MapOfShape Edges1;
1966 for (TopExp_Explorer exp(aFaces.Value(NumBase), TopAbs_EDGE); exp.More(); exp.Next()) {
1967 Edges1.Add(exp.Current());
1968 SMESH_subMesh *sm = theMesh.GetSubMesh(exp.Current());
1970 MapShapeNbElemsItr anIt = aResMap.find(sm);
1971 if( anIt == aResMap.end() ) continue;
1972 std::vector<int> aVec = (*anIt).second;
1973 nb1d += Max(aVec[SMDSEntity_Edge],aVec[SMDSEntity_Quad_Edge]);
1976 // find face opposite to base face
1978 for(i=1; i<=6; i++) {
1979 if(i==NumBase) continue;
1980 bool IsOpposite = true;
1981 for(TopExp_Explorer exp(aFaces.Value(i), TopAbs_EDGE); exp.More(); exp.Next()) {
1982 if( Edges1.Contains(exp.Current()) ) {
1992 // find number of 2d elems on side faces
1994 for(i=1; i<=6; i++) {
1995 if( i==OppNum || i==NumBase ) continue;
1996 MapShapeNbElemsItr anIt = aResMap.find( meshFaces[i-1] );
1997 if( anIt == aResMap.end() ) continue;
1998 std::vector<int> aVec = (*anIt).second;
1999 nb2d += Max(aVec[SMDSEntity_Quadrangle],aVec[SMDSEntity_Quad_Quadrangle]);
2002 MapShapeNbElemsItr anIt = aResMap.find( meshFaces[NumBase-1] );
2003 std::vector<int> aVec = (*anIt).second;
2004 bool IsQuadratic = (aVec[SMDSEntity_Quad_Triangle]>aVec[SMDSEntity_Triangle]) ||
2005 (aVec[SMDSEntity_Quad_Quadrangle]>aVec[SMDSEntity_Quadrangle]);
2006 int nb2d_face0_3 = Max(aVec[SMDSEntity_Triangle],aVec[SMDSEntity_Quad_Triangle]);
2007 int nb2d_face0_4 = Max(aVec[SMDSEntity_Quadrangle],aVec[SMDSEntity_Quad_Quadrangle]);
2008 int nb0d_face0 = aVec[SMDSEntity_Node];
2009 int nb1d_face0_int = ( nb2d_face0_3*3 + nb2d_face0_4*4 - nb1d ) / 2;
2011 std::vector<int> aResVec(SMDSEntity_Last);
2012 for(int i=SMDSEntity_Node; i<SMDSEntity_Last; i++) aResVec[i] = 0;
2014 aResVec[SMDSEntity_Quad_Penta] = nb2d_face0_3 * ( nb2d/nb1d );
2015 aResVec[SMDSEntity_Quad_Hexa] = nb2d_face0_4 * ( nb2d/nb1d );
2016 aResVec[SMDSEntity_Node] = nb0d_face0 * ( 2*nb2d/nb1d - 1 ) - nb1d_face0_int * nb2d/nb1d;
2019 aResVec[SMDSEntity_Node] = nb0d_face0 * ( nb2d/nb1d - 1 );
2020 aResVec[SMDSEntity_Penta] = nb2d_face0_3 * ( nb2d/nb1d );
2021 aResVec[SMDSEntity_Hexa] = nb2d_face0_4 * ( nb2d/nb1d );
2023 SMESH_subMesh * sm = theMesh.GetSubMesh(theShape);
2024 aResMap.insert(std::make_pair(sm,aResVec));
2029 //================================================================================
2031 * \brief Create prisms
2032 * \param columns - columns of nodes generated from nodes of a mesh face
2033 * \param helper - helper initialized by mesh and shape to add prisms to
2035 //================================================================================
2037 bool StdMeshers_Prism_3D::AddPrisms( vector<const TNodeColumn*> & columns,
2038 SMESH_MesherHelper* helper)
2040 size_t nbNodes = columns.size();
2041 size_t nbZ = columns[0]->size();
2042 if ( nbZ < 2 ) return false;
2043 for ( size_t i = 1; i < nbNodes; ++i )
2044 if ( columns[i]->size() != nbZ )
2047 // find out orientation
2048 bool isForward = true;
2049 SMDS_VolumeTool vTool;
2051 switch ( nbNodes ) {
2053 SMDS_VolumeOfNodes tmpPenta ( (*columns[0])[z-1], // bottom
2056 (*columns[0])[z], // top
2059 vTool.Set( &tmpPenta );
2060 isForward = vTool.IsForward();
2064 SMDS_VolumeOfNodes tmpHex( (*columns[0])[z-1], (*columns[1])[z-1], // bottom
2065 (*columns[2])[z-1], (*columns[3])[z-1],
2066 (*columns[0])[z], (*columns[1])[z], // top
2067 (*columns[2])[z], (*columns[3])[z] );
2068 vTool.Set( &tmpHex );
2069 isForward = vTool.IsForward();
2073 const int di = (nbNodes+1) / 3;
2074 SMDS_VolumeOfNodes tmpVol ( (*columns[0] )[z-1],
2075 (*columns[di] )[z-1],
2076 (*columns[2*di])[z-1],
2079 (*columns[2*di])[z] );
2080 vTool.Set( &tmpVol );
2081 isForward = vTool.IsForward();
2084 // vertical loop on columns
2086 helper->SetElementsOnShape( true );
2088 switch ( nbNodes ) {
2090 case 3: { // ---------- pentahedra
2091 const int i1 = isForward ? 1 : 2;
2092 const int i2 = isForward ? 2 : 1;
2093 for ( z = 1; z < nbZ; ++z )
2094 helper->AddVolume( (*columns[0 ])[z-1], // bottom
2095 (*columns[i1])[z-1],
2096 (*columns[i2])[z-1],
2097 (*columns[0 ])[z], // top
2099 (*columns[i2])[z] );
2102 case 4: { // ---------- hexahedra
2103 const int i1 = isForward ? 1 : 3;
2104 const int i3 = isForward ? 3 : 1;
2105 for ( z = 1; z < nbZ; ++z )
2106 helper->AddVolume( (*columns[0])[z-1], (*columns[i1])[z-1], // bottom
2107 (*columns[2])[z-1], (*columns[i3])[z-1],
2108 (*columns[0])[z], (*columns[i1])[z], // top
2109 (*columns[2])[z], (*columns[i3])[z] );
2112 case 6: { // ---------- octahedra
2113 const int iBase1 = isForward ? -1 : 0;
2114 const int iBase2 = isForward ? 0 :-1;
2115 for ( z = 1; z < nbZ; ++z )
2116 helper->AddVolume( (*columns[0])[z+iBase1], (*columns[1])[z+iBase1], // bottom or top
2117 (*columns[2])[z+iBase1], (*columns[3])[z+iBase1],
2118 (*columns[4])[z+iBase1], (*columns[5])[z+iBase1],
2119 (*columns[0])[z+iBase2], (*columns[1])[z+iBase2], // top or bottom
2120 (*columns[2])[z+iBase2], (*columns[3])[z+iBase2],
2121 (*columns[4])[z+iBase2], (*columns[5])[z+iBase2] );
2124 default: // ---------- polyhedra
2125 vector<int> quantities( 2 + nbNodes, 4 );
2126 quantities[0] = quantities[1] = nbNodes;
2127 columns.resize( nbNodes + 1 );
2128 columns[ nbNodes ] = columns[ 0 ];
2129 const int i1 = isForward ? 1 : 3;
2130 const int i3 = isForward ? 3 : 1;
2131 const int iBase1 = isForward ? -1 : 0;
2132 const int iBase2 = isForward ? 0 :-1;
2133 vector<const SMDS_MeshNode*> nodes( 2*nbNodes + 4*nbNodes);
2134 for ( z = 1; z < nbZ; ++z )
2136 for ( size_t i = 0; i < nbNodes; ++i ) {
2137 nodes[ i ] = (*columns[ i ])[z+iBase1]; // bottom or top
2138 nodes[ 2*nbNodes-i-1 ] = (*columns[ i ])[z+iBase2]; // top or bottom
2140 int di = 2*nbNodes + 4*i;
2141 nodes[ di+0 ] = (*columns[i ])[z ];
2142 nodes[ di+i1] = (*columns[i+1])[z ];
2143 nodes[ di+2 ] = (*columns[i+1])[z-1];
2144 nodes[ di+i3] = (*columns[i ])[z-1];
2146 helper->AddPolyhedralVolume( nodes, quantities );
2149 } // switch ( nbNodes )
2154 //================================================================================
2156 * \brief Find correspondence between bottom and top nodes
2157 * If elements on the bottom and top faces are topologically different,
2158 * and projection is possible and allowed, perform the projection
2159 * \retval bool - is a success or not
2161 //================================================================================
2163 bool StdMeshers_Prism_3D::assocOrProjBottom2Top( const gp_Trsf & bottomToTopTrsf,
2164 const Prism_3D::TPrismTopo& thePrism)
2166 SMESH_subMesh * botSM = myHelper->GetMesh()->GetSubMesh( thePrism.myBottom );
2167 SMESH_subMesh * topSM = myHelper->GetMesh()->GetSubMesh( thePrism.myTop );
2169 SMESHDS_SubMesh * botSMDS = botSM->GetSubMeshDS();
2170 SMESHDS_SubMesh * topSMDS = topSM->GetSubMeshDS();
2172 if ( !botSMDS || botSMDS->NbElements() == 0 )
2174 _gen->Compute( *myHelper->GetMesh(), botSM->GetSubShape(), /*aShapeOnly=*/true );
2175 botSMDS = botSM->GetSubMeshDS();
2176 if ( !botSMDS || botSMDS->NbElements() == 0 )
2177 return toSM( error(TCom("No elements on face #") << botSM->GetId() ));
2180 bool needProject = !topSM->IsMeshComputed();
2181 if ( !needProject &&
2182 (botSMDS->NbElements() != topSMDS->NbElements() ||
2183 botSMDS->NbNodes() != topSMDS->NbNodes()))
2185 MESSAGE("nb elem bot " << botSMDS->NbElements() <<
2186 " top " << ( topSMDS ? topSMDS->NbElements() : 0 ));
2187 MESSAGE("nb node bot " << botSMDS->NbNodes() <<
2188 " top " << ( topSMDS ? topSMDS->NbNodes() : 0 ));
2189 return toSM( error(TCom("Mesh on faces #") << botSM->GetId()
2190 <<" and #"<< topSM->GetId() << " seems different" ));
2193 if ( 0/*needProject && !myProjectTriangles*/ )
2194 return toSM( error(TCom("Mesh on faces #") << botSM->GetId()
2195 <<" and #"<< topSM->GetId() << " seems different" ));
2196 ///RETURN_BAD_RESULT("Need to project but not allowed");
2198 NSProjUtils::TNodeNodeMap n2nMap;
2199 const NSProjUtils::TNodeNodeMap* n2nMapPtr = & n2nMap;
2202 if ( !projectBottomToTop( bottomToTopTrsf, thePrism ))
2204 n2nMapPtr = & TProjction2dAlgo::instance( this )->GetNodesMap();
2207 if ( !n2nMapPtr || (int) n2nMapPtr->size() < botSMDS->NbNodes() )
2209 // associate top and bottom faces
2210 NSProjUtils::TShapeShapeMap shape2ShapeMap;
2211 const bool sameTopo =
2212 NSProjUtils::FindSubShapeAssociation( thePrism.myBottom, myHelper->GetMesh(),
2213 thePrism.myTop, myHelper->GetMesh(),
2216 for ( size_t iQ = 0; iQ < thePrism.myWallQuads.size(); ++iQ )
2218 const Prism_3D::TQuadList& quadList = thePrism.myWallQuads[iQ];
2219 StdMeshers_FaceSidePtr botSide = quadList.front()->side[ QUAD_BOTTOM_SIDE ];
2220 StdMeshers_FaceSidePtr topSide = quadList.back ()->side[ QUAD_TOP_SIDE ];
2221 if ( botSide->NbEdges() == topSide->NbEdges() )
2223 for ( int iE = 0; iE < botSide->NbEdges(); ++iE )
2225 NSProjUtils::InsertAssociation( botSide->Edge( iE ),
2226 topSide->Edge( iE ), shape2ShapeMap );
2227 NSProjUtils::InsertAssociation( myHelper->IthVertex( 0, botSide->Edge( iE )),
2228 myHelper->IthVertex( 0, topSide->Edge( iE )),
2234 TopoDS_Vertex vb, vt;
2235 StdMeshers_FaceSidePtr sideB, sideT;
2236 vb = myHelper->IthVertex( 0, botSide->Edge( 0 ));
2237 vt = myHelper->IthVertex( 0, topSide->Edge( 0 ));
2238 sideB = quadList.front()->side[ QUAD_LEFT_SIDE ];
2239 sideT = quadList.back ()->side[ QUAD_LEFT_SIDE ];
2240 if ( vb.IsSame( sideB->FirstVertex() ) &&
2241 vt.IsSame( sideT->LastVertex() ))
2243 NSProjUtils::InsertAssociation( botSide->Edge( 0 ),
2244 topSide->Edge( 0 ), shape2ShapeMap );
2245 NSProjUtils::InsertAssociation( vb, vt, shape2ShapeMap );
2247 vb = myHelper->IthVertex( 1, botSide->Edge( botSide->NbEdges()-1 ));
2248 vt = myHelper->IthVertex( 1, topSide->Edge( topSide->NbEdges()-1 ));
2249 sideB = quadList.front()->side[ QUAD_RIGHT_SIDE ];
2250 sideT = quadList.back ()->side[ QUAD_RIGHT_SIDE ];
2251 if ( vb.IsSame( sideB->FirstVertex() ) &&
2252 vt.IsSame( sideT->LastVertex() ))
2254 NSProjUtils::InsertAssociation( botSide->Edge( botSide->NbEdges()-1 ),
2255 topSide->Edge( topSide->NbEdges()-1 ),
2257 NSProjUtils::InsertAssociation( vb, vt, shape2ShapeMap );
2262 // Find matching nodes of top and bottom faces
2263 n2nMapPtr = & n2nMap;
2264 if ( ! NSProjUtils::FindMatchingNodesOnFaces( thePrism.myBottom, myHelper->GetMesh(),
2265 thePrism.myTop, myHelper->GetMesh(),
2266 shape2ShapeMap, n2nMap ))
2269 return toSM( error(TCom("Mesh on faces #") << botSM->GetId()
2270 <<" and #"<< topSM->GetId() << " seems different" ));
2272 return toSM( error(TCom("Topology of faces #") << botSM->GetId()
2273 <<" and #"<< topSM->GetId() << " seems different" ));
2277 // Fill myBotToColumnMap
2279 int zSize = myBlock.VerticalSize();
2280 TNodeNodeMap::const_iterator bN_tN = n2nMapPtr->begin();
2281 for ( ; bN_tN != n2nMapPtr->end(); ++bN_tN )
2283 const SMDS_MeshNode* botNode = bN_tN->first;
2284 const SMDS_MeshNode* topNode = bN_tN->second;
2285 if ( botNode->GetPosition()->GetTypeOfPosition() != SMDS_TOP_FACE &&
2286 myBlock.HasNodeColumn( botNode ))
2287 continue; // wall columns are contained in myBlock
2288 // create node column
2289 Prism_3D::TNode bN( botNode );
2290 TNode2ColumnMap::iterator bN_col =
2291 myBotToColumnMap.insert( make_pair ( bN, TNodeColumn() )).first;
2292 TNodeColumn & column = bN_col->second;
2293 column.resize( zSize, 0 );
2294 column.front() = botNode;
2295 column.back() = topNode;
2300 //================================================================================
2302 * \brief Remove faces from the top face and re-create them by projection from the bottom
2303 * \retval bool - a success or not
2305 //================================================================================
2307 bool StdMeshers_Prism_3D::projectBottomToTop( const gp_Trsf & bottomToTopTrsf,
2308 const Prism_3D::TPrismTopo& thePrism )
2310 if ( project2dMesh( thePrism.myBottom, thePrism.myTop ))
2314 NSProjUtils::TNodeNodeMap& n2nMap =
2315 (NSProjUtils::TNodeNodeMap&) TProjction2dAlgo::instance( this )->GetNodesMap();
2320 SMESHDS_Mesh* meshDS = myHelper->GetMeshDS();
2321 SMESH_subMesh * botSM = myHelper->GetMesh()->GetSubMesh( thePrism.myBottom );
2322 SMESH_subMesh * topSM = myHelper->GetMesh()->GetSubMesh( thePrism.myTop );
2324 SMESHDS_SubMesh * botSMDS = botSM->GetSubMeshDS();
2325 SMESHDS_SubMesh * topSMDS = topSM->GetSubMeshDS();
2327 if ( topSMDS && topSMDS->NbElements() > 0 )
2329 //topSM->ComputeStateEngine( SMESH_subMesh::CLEAN ); -- avoid propagation of events
2330 for ( SMDS_ElemIteratorPtr eIt = topSMDS->GetElements(); eIt->more(); )
2331 meshDS->RemoveFreeElement( eIt->next(), topSMDS, /*fromGroups=*/false );
2332 for ( SMDS_NodeIteratorPtr nIt = topSMDS->GetNodes(); nIt->more(); )
2333 meshDS->RemoveFreeNode( nIt->next(), topSMDS, /*fromGroups=*/false );
2336 const TopoDS_Face& botFace = thePrism.myBottom; // oriented within
2337 const TopoDS_Face& topFace = thePrism.myTop; // the 3D SHAPE
2338 int topFaceID = meshDS->ShapeToIndex( thePrism.myTop );
2340 SMESH_MesherHelper botHelper( *myHelper->GetMesh() );
2341 botHelper.SetSubShape( botFace );
2342 botHelper.ToFixNodeParameters( true );
2344 SMESH_MesherHelper topHelper( *myHelper->GetMesh() );
2345 topHelper.SetSubShape( topFace );
2346 topHelper.ToFixNodeParameters( true );
2347 double distXYZ[4], fixTol = 10 * topHelper.MaxTolerance( topFace );
2349 // Fill myBotToColumnMap
2351 int zSize = myBlock.VerticalSize();
2352 Prism_3D::TNode prevTNode;
2353 SMDS_NodeIteratorPtr nIt = botSMDS->GetNodes();
2354 while ( nIt->more() )
2356 const SMDS_MeshNode* botNode = nIt->next();
2357 const SMDS_MeshNode* topNode = 0;
2358 if ( botNode->GetPosition()->GetTypeOfPosition() != SMDS_TOP_FACE )
2359 continue; // strange
2361 Prism_3D::TNode bN( botNode );
2362 if ( bottomToTopTrsf.Form() == gp_Identity )
2364 // compute bottom node params
2365 gp_XYZ paramHint(-1,-1,-1);
2366 if ( prevTNode.IsNeighbor( bN ))
2368 paramHint = prevTNode.GetParams();
2369 // double tol = 1e-2 * ( prevTNode.GetCoords() - bN.GetCoords() ).Modulus();
2370 // myBlock.SetTolerance( Min( myBlock.GetTolerance(), tol ));
2372 if ( !myBlock.ComputeParameters( bN.GetCoords(), bN.ChangeParams(),
2373 ID_BOT_FACE, paramHint ))
2374 return toSM( error(TCom("Can't compute normalized parameters for node ")
2375 << botNode->GetID() << " on the face #"<< botSM->GetId() ));
2377 // compute top node coords
2378 gp_XYZ topXYZ; gp_XY topUV;
2379 if ( !myBlock.FacePoint( ID_TOP_FACE, bN.GetParams(), topXYZ ) ||
2380 !myBlock.FaceUV ( ID_TOP_FACE, bN.GetParams(), topUV ))
2381 return toSM( error(TCom("Can't compute coordinates "
2382 "by normalized parameters on the face #")<< topSM->GetId() ));
2383 topNode = meshDS->AddNode( topXYZ.X(),topXYZ.Y(),topXYZ.Z() );
2384 meshDS->SetNodeOnFace( topNode, topFaceID, topUV.X(), topUV.Y() );
2386 else // use bottomToTopTrsf
2388 gp_XYZ coords = bN.GetCoords();
2389 bottomToTopTrsf.Transforms( coords );
2390 topNode = meshDS->AddNode( coords.X(), coords.Y(), coords.Z() );
2391 gp_XY topUV = botHelper.GetNodeUV( botFace, botNode, 0, &checkUV );
2392 meshDS->SetNodeOnFace( topNode, topFaceID, topUV.X(), topUV.Y() );
2394 if ( topHelper.CheckNodeUV( topFace, topNode, topUV, fixTol, /*force=*/false, distXYZ ) &&
2395 distXYZ[0] > fixTol && distXYZ[0] < fixTol * 1e+3 )
2396 meshDS->MoveNode( topNode, distXYZ[1], distXYZ[2], distXYZ[3] ); // transform can be inaccurate
2398 // create node column
2399 TNode2ColumnMap::iterator bN_col =
2400 myBotToColumnMap.insert( make_pair ( bN, TNodeColumn() )).first;
2401 TNodeColumn & column = bN_col->second;
2402 column.resize( zSize );
2403 column.front() = botNode;
2404 column.back() = topNode;
2406 n2nMap.insert( n2nMap.end(), make_pair( botNode, topNode ));
2408 if ( _computeCanceled )
2409 return toSM( error( SMESH_ComputeError::New(COMPERR_CANCELED)));
2414 const bool oldSetElemsOnShape = myHelper->SetElementsOnShape( false );
2416 // care of orientation;
2417 // if the bottom faces is orienetd OK then top faces must be reversed
2418 bool reverseTop = true;
2419 if ( myHelper->NbAncestors( botFace, *myBlock.Mesh(), TopAbs_SOLID ) > 1 )
2420 reverseTop = ! myHelper->IsReversedSubMesh( botFace );
2421 int iFrw, iRev, *iPtr = &( reverseTop ? iRev : iFrw );
2423 // loop on bottom mesh faces
2424 SMDS_ElemIteratorPtr faceIt = botSMDS->GetElements();
2425 vector< const SMDS_MeshNode* > nodes;
2426 while ( faceIt->more() )
2428 const SMDS_MeshElement* face = faceIt->next();
2429 if ( !face || face->GetType() != SMDSAbs_Face )
2432 // find top node in columns for each bottom node
2433 int nbNodes = face->NbCornerNodes();
2434 nodes.resize( nbNodes );
2435 for ( iFrw = 0, iRev = nbNodes-1; iFrw < nbNodes; ++iFrw, --iRev )
2437 const SMDS_MeshNode* n = face->GetNode( *iPtr );
2438 if ( n->GetPosition()->GetTypeOfPosition() == SMDS_TOP_FACE ) {
2439 TNode2ColumnMap::iterator bot_column = myBotToColumnMap.find( n );
2440 if ( bot_column == myBotToColumnMap.end() )
2441 return toSM( error(TCom("No nodes found above node ") << n->GetID() ));
2442 nodes[ iFrw ] = bot_column->second.back();
2445 const TNodeColumn* column = myBlock.GetNodeColumn( n );
2447 return toSM( error(TCom("No side nodes found above node ") << n->GetID() ));
2448 nodes[ iFrw ] = column->back();
2451 SMDS_MeshElement* newFace = 0;
2452 switch ( nbNodes ) {
2455 newFace = myHelper->AddFace(nodes[0], nodes[1], nodes[2]);
2459 newFace = myHelper->AddFace( nodes[0], nodes[1], nodes[2], nodes[3] );
2463 newFace = meshDS->AddPolygonalFace( nodes );
2466 meshDS->SetMeshElementOnShape( newFace, topFaceID );
2469 myHelper->SetElementsOnShape( oldSetElemsOnShape );
2471 // Check the projected mesh
2473 if ( thePrism.NbWires() > 1 && // there are holes
2474 topHelper.IsDistorted2D( topSM, /*checkUV=*/false ))
2476 SMESH_MeshEditor editor( topHelper.GetMesh() );
2478 // smooth in 2D or 3D?
2479 TopLoc_Location loc;
2480 Handle(Geom_Surface) surface = BRep_Tool::Surface( topFace, loc );
2481 bool isPlanar = GeomLib_IsPlanarSurface( surface ).IsPlanar();
2483 set<const SMDS_MeshNode*> fixedNodes;
2484 TIDSortedElemSet faces;
2485 for ( faceIt = topSMDS->GetElements(); faceIt->more(); )
2486 faces.insert( faces.end(), faceIt->next() );
2489 for ( int isCentroidal = 0; isCentroidal < 2; ++isCentroidal )
2491 SMESH_MeshEditor::SmoothMethod algo =
2492 isCentroidal ? SMESH_MeshEditor::CENTROIDAL : SMESH_MeshEditor::LAPLACIAN;
2494 int nbAttempts = isCentroidal ? 1 : 10;
2495 for ( int iAttemp = 0; iAttemp < nbAttempts; ++iAttemp )
2497 TIDSortedElemSet workFaces = faces;
2500 editor.Smooth( workFaces, fixedNodes, algo, /*nbIterations=*/ 10,
2501 /*theTgtAspectRatio=*/1.0, /*the2D=*/!isPlanar);
2503 if (( isOk = !topHelper.IsDistorted2D( topSM, /*checkUV=*/true )) &&
2509 return toSM( error( TCom("Projection from face #") << botSM->GetId()
2510 << " to face #" << topSM->GetId()
2511 << " failed: inverted elements created"));
2514 TProjction2dAlgo::instance( this )->SetEventListener( topSM );
2519 //=======================================================================
2520 //function : getSweepTolerance
2521 //purpose : Compute tolerance to pass to StdMeshers_Sweeper
2522 //=======================================================================
2524 double StdMeshers_Prism_3D::getSweepTolerance( const Prism_3D::TPrismTopo& thePrism )
2526 SMESHDS_Mesh* meshDS = myHelper->GetMeshDS();
2527 SMESHDS_SubMesh * sm[2] = { meshDS->MeshElements( thePrism.myBottom ),
2528 meshDS->MeshElements( thePrism.myTop ) };
2529 double minDist = 1e100;
2531 vector< SMESH_TNodeXYZ > nodes;
2532 for ( int iSM = 0; iSM < 2; ++iSM )
2534 if ( !sm[ iSM ]) continue;
2536 SMDS_ElemIteratorPtr fIt = sm[ iSM ]->GetElements();
2537 while ( fIt->more() )
2539 const SMDS_MeshElement* face = fIt->next();
2540 const int nbNodes = face->NbCornerNodes();
2541 SMDS_ElemIteratorPtr nIt = face->nodesIterator();
2543 nodes.resize( nbNodes + 1 );
2544 for ( int iN = 0; iN < nbNodes; ++iN )
2545 nodes[ iN ] = nIt->next();
2546 nodes.back() = nodes[0];
2550 for ( int iN = 0; iN < nbNodes; ++iN )
2552 if ( nodes[ iN ]._node->GetPosition()->GetDim() < 2 &&
2553 nodes[ iN+1 ]._node->GetPosition()->GetDim() < 2 )
2555 // it's a boundary link; measure distance of other
2556 // nodes to this link
2557 gp_XYZ linkDir = nodes[ iN ] - nodes[ iN+1 ];
2558 double linkLen = linkDir.Modulus();
2559 bool isDegen = ( linkLen < numeric_limits<double>::min() );
2560 if ( !isDegen ) linkDir /= linkLen;
2561 for ( int iN2 = 0; iN2 < nbNodes; ++iN2 ) // loop on other nodes
2563 if ( nodes[ iN2 ] == nodes[ iN ] ||
2564 nodes[ iN2 ] == nodes[ iN+1 ]) continue;
2567 dist2 = ( nodes[ iN ] - nodes[ iN2 ]).SquareModulus();
2571 dist2 = linkDir.CrossSquareMagnitude( nodes[ iN ] - nodes[ iN2 ]);
2573 if ( dist2 > numeric_limits<double>::min() )
2574 minDist = Min ( minDist, dist2 );
2577 // measure length link
2578 else if ( nodes[ iN ]._node < nodes[ iN+1 ]._node ) // not to measure same link twice
2580 dist2 = ( nodes[ iN ] - nodes[ iN+1 ]).SquareModulus();
2581 if ( dist2 > numeric_limits<double>::min() )
2582 minDist = Min ( minDist, dist2 );
2587 return 0.1 * Sqrt ( minDist );
2590 //=======================================================================
2591 //function : isSimpleQuad
2592 //purpose : check if the bottom FACE is meshable with nice quadrangles,
2593 // if so the block approach can work rather fast.
2594 // This is a temporary mean caused by problems in StdMeshers_Sweeper
2595 //=======================================================================
2597 bool StdMeshers_Prism_3D::isSimpleBottom( const Prism_3D::TPrismTopo& thePrism )
2599 if ( thePrism.myNbEdgesInWires.front() != 4 )
2602 // analyse angles between edges
2603 double nbConcaveAng = 0, nbConvexAng = 0;
2604 TopoDS_Face reverseBottom = TopoDS::Face( thePrism.myBottom.Reversed() ); // see initPrism()
2605 TopoDS_Vertex commonV;
2606 const list< TopoDS_Edge >& botEdges = thePrism.myBottomEdges;
2607 list< TopoDS_Edge >::const_iterator edge = botEdges.begin();
2608 while ( edge != botEdges.end() )
2610 if ( SMESH_Algo::isDegenerated( *edge ))
2612 TopoDS_Edge e1 = *edge++;
2613 TopoDS_Edge e2 = ( edge == botEdges.end() ? botEdges.front() : *edge );
2614 if ( ! TopExp::CommonVertex( e1, e2, commonV ))
2616 e2 = botEdges.front();
2617 if ( ! TopExp::CommonVertex( e1, e2, commonV ))
2620 double angle = myHelper->GetAngle( e1, e2, reverseBottom, commonV );
2621 if ( angle < -5 * M_PI/180 )
2622 if ( ++nbConcaveAng > 1 )
2624 if ( angle > 85 * M_PI/180 )
2625 if ( ++nbConvexAng > 4 )
2631 //=======================================================================
2632 //function : allVerticalEdgesStraight
2633 //purpose : Defines if all "vertical" EDGEs are straight
2634 //=======================================================================
2636 bool StdMeshers_Prism_3D::allVerticalEdgesStraight( const Prism_3D::TPrismTopo& thePrism )
2638 for ( size_t i = 0; i < thePrism.myWallQuads.size(); ++i )
2640 const Prism_3D::TQuadList& quads = thePrism.myWallQuads[i];
2641 Prism_3D::TQuadList::const_iterator quadIt = quads.begin();
2642 TopoDS_Edge prevQuadEdge;
2643 for ( ; quadIt != quads.end(); ++quadIt )
2645 StdMeshers_FaceSidePtr rightSide = (*quadIt)->side[ QUAD_RIGHT_SIDE ];
2647 if ( !prevQuadEdge.IsNull() &&
2648 !SMESH_Algo::IsContinuous( rightSide->Edge( 0 ), prevQuadEdge ))
2651 for ( int iE = 0; iE < rightSide->NbEdges(); ++iE )
2653 const TopoDS_Edge & rightE = rightSide->Edge( iE );
2654 if ( !SMESH_Algo::IsStraight( rightE, /*degenResult=*/true ))
2658 !SMESH_Algo::IsContinuous( rightSide->Edge( iE-1 ), rightE ))
2661 prevQuadEdge = rightE;
2668 //=======================================================================
2669 //function : project2dMesh
2670 //purpose : Project mesh faces from a source FACE of one prism (theSrcFace)
2671 // to a source FACE of another prism (theTgtFace)
2672 //=======================================================================
2674 bool StdMeshers_Prism_3D::project2dMesh(const TopoDS_Face& theSrcFace,
2675 const TopoDS_Face& theTgtFace)
2677 TProjction2dAlgo* projector2D = TProjction2dAlgo::instance( this );
2678 projector2D->myHyp.SetSourceFace( theSrcFace );
2679 bool ok = projector2D->Compute( *myHelper->GetMesh(), theTgtFace );
2681 SMESH_subMesh* tgtSM = myHelper->GetMesh()->GetSubMesh( theTgtFace );
2682 if ( !ok && tgtSM->GetSubMeshDS() ) {
2683 //tgtSM->ComputeStateEngine( SMESH_subMesh::CLEAN ); -- avoid propagation of events
2684 SMESHDS_Mesh* meshDS = myHelper->GetMeshDS();
2685 SMESHDS_SubMesh* tgtSMDS = tgtSM->GetSubMeshDS();
2686 for ( SMDS_ElemIteratorPtr eIt = tgtSMDS->GetElements(); eIt->more(); )
2687 meshDS->RemoveFreeElement( eIt->next(), tgtSMDS, /*fromGroups=*/false );
2688 for ( SMDS_NodeIteratorPtr nIt = tgtSMDS->GetNodes(); nIt->more(); )
2689 meshDS->RemoveFreeNode( nIt->next(), tgtSMDS, /*fromGroups=*/false );
2691 tgtSM->ComputeStateEngine ( SMESH_subMesh::CHECK_COMPUTE_STATE );
2692 tgtSM->ComputeSubMeshStateEngine( SMESH_subMesh::CHECK_COMPUTE_STATE );
2694 projector2D->SetEventListener( tgtSM );
2699 //================================================================================
2701 * \brief Set projection coordinates of a node to a face and it's sub-shapes
2702 * \param faceID - the face given by in-block ID
2703 * \param params - node normalized parameters
2704 * \retval bool - is a success
2706 //================================================================================
2708 bool StdMeshers_Prism_3D::setFaceAndEdgesXYZ( const int faceID, const gp_XYZ& params, int z )
2710 // find base and top edges of the face
2711 enum { BASE = 0, TOP, LEFT, RIGHT };
2712 vector< int > edgeVec; // 0-base, 1-top
2713 SMESH_Block::GetFaceEdgesIDs( faceID, edgeVec );
2715 myBlock.EdgePoint( edgeVec[ BASE ], params, myShapeXYZ[ edgeVec[ BASE ]]);
2716 myBlock.EdgePoint( edgeVec[ TOP ], params, myShapeXYZ[ edgeVec[ TOP ]]);
2718 SHOWYXZ("\nparams ", params);
2719 SHOWYXZ("TOP is " <<edgeVec[ TOP ], myShapeXYZ[ edgeVec[ TOP]]);
2720 SHOWYXZ("BASE is "<<edgeVec[ BASE], myShapeXYZ[ edgeVec[ BASE]]);
2722 if ( faceID == SMESH_Block::ID_Fx0z || faceID == SMESH_Block::ID_Fx1z )
2724 myBlock.EdgePoint( edgeVec[ LEFT ], params, myShapeXYZ[ edgeVec[ LEFT ]]);
2725 myBlock.EdgePoint( edgeVec[ RIGHT ], params, myShapeXYZ[ edgeVec[ RIGHT ]]);
2727 SHOWYXZ("VER "<<edgeVec[ LEFT], myShapeXYZ[ edgeVec[ LEFT]]);
2728 SHOWYXZ("VER "<<edgeVec[ RIGHT], myShapeXYZ[ edgeVec[ RIGHT]]);
2730 myBlock.FacePoint( faceID, params, myShapeXYZ[ faceID ]);
2731 SHOWYXZ("FacePoint "<<faceID, myShapeXYZ[ faceID]);
2736 //=======================================================================
2738 //purpose : If (!isOK), sets the error to a sub-mesh of a current SOLID
2739 //=======================================================================
2741 bool StdMeshers_Prism_3D::toSM( bool isOK )
2743 if ( mySetErrorToSM &&
2746 !myHelper->GetSubShape().IsNull() &&
2747 myHelper->GetSubShape().ShapeType() == TopAbs_SOLID)
2749 SMESH_subMesh* sm = myHelper->GetMesh()->GetSubMesh( myHelper->GetSubShape() );
2750 sm->GetComputeError() = this->GetComputeError();
2751 // clear error in order not to return it twice
2752 _error = COMPERR_OK;
2758 //=======================================================================
2759 //function : shapeID
2760 //purpose : Return index of a shape
2761 //=======================================================================
2763 int StdMeshers_Prism_3D::shapeID( const TopoDS_Shape& S )
2765 if ( S.IsNull() ) return 0;
2766 if ( !myHelper ) return -3;
2767 return myHelper->GetMeshDS()->ShapeToIndex( S );
2770 namespace // utils used by StdMeshers_Prism_3D::IsApplicable()
2772 struct EdgeWithNeighbors
2775 int _iBase; // index in a WIRE with non-base EDGEs excluded
2776 int _iL, _iR; // used to connect PrismSide's
2777 int _iE; // index in a WIRE
2778 int _iLE, _iRE; // used to connect EdgeWithNeighbors's
2779 bool _isBase; // is used in a base FACE
2780 TopoDS_Vertex _vv[2]; // end VERTEXes
2781 EdgeWithNeighbors(const TopoDS_Edge& E,
2782 int iE, int nbE, int shift,
2783 int iEE, int nbEE, int shiftE,
2784 bool isBase, bool setVV ):
2786 _iBase( iE + shift ),
2787 _iL ( SMESH_MesherHelper::WrapIndex( iE-1, Max( 1, nbE )) + shift ),
2788 _iR ( SMESH_MesherHelper::WrapIndex( iE+1, Max( 1, nbE )) + shift ),
2789 _iE ( iEE + shiftE ),
2790 _iLE( SMESH_MesherHelper::WrapIndex( iEE-1, Max( 1, nbEE )) + shiftE ),
2791 _iRE( SMESH_MesherHelper::WrapIndex( iEE+1, Max( 1, nbEE )) + shiftE ),
2800 EdgeWithNeighbors() {}
2801 bool IsInternal() const { return !_edge.IsNull() && _edge.Orientation() == TopAbs_INTERNAL; }
2802 bool IsConnected( const EdgeWithNeighbors& edge, int iEnd ) const
2804 return (( _vv[ iEnd ].IsSame( edge._vv[ 1 - iEnd ])) ||
2805 ( IsInternal() && _vv[ iEnd ].IsSame( edge._vv[ iEnd ])));
2807 bool IsConnected( const std::vector< EdgeWithNeighbors > & edges, int iEnd ) const
2809 int iEdge = iEnd ? _iRE : _iLE;
2810 return iEdge == _iE ? false : IsConnected( edges[ iEdge ], iEnd );
2812 const TopoDS_Vertex& Vertex( int iEnd )
2814 if ( _vv[ iEnd ].IsNull() )
2815 _vv[ iEnd ] = SMESH_MesherHelper::IthVertex( iEnd, _edge );
2819 // PrismSide contains all FACEs linking a bottom EDGE with a top one.
2822 TopoDS_Face _face; // a currently treated upper FACE
2823 TopTools_IndexedMapOfShape *_faces; // all FACEs (pointer because of a private copy constructor)
2824 TopoDS_Edge _topEdge; // a current top EDGE
2825 vector< EdgeWithNeighbors >*_edges; // all EDGEs of _face
2826 int _iBotEdge; // index of _topEdge within _edges
2827 vector< bool > _isCheckedEdge; // mark EDGEs whose two owner FACEs found
2828 int _nbCheckedEdges; // nb of EDGEs whose location is defined
2829 PrismSide *_leftSide; // neighbor sides
2830 PrismSide *_rightSide;
2831 bool _isInternal; // whether this side raises from an INTERNAL EDGE
2832 //void SetExcluded() { _leftSide = _rightSide = NULL; }
2833 //bool IsExcluded() const { return !_leftSide; }
2834 const TopoDS_Edge& Edge( int i ) const
2836 return (*_edges)[ i ]._edge;
2838 int FindEdge( const TopoDS_Edge& E ) const
2840 for ( size_t i = 0; i < _edges->size(); ++i )
2841 if ( E.IsSame( Edge( i ))) return i;
2844 const TopoDS_Vertex& Vertex( int iE, int iEnd ) const
2846 return (*_edges)[ iE ].Vertex( iEnd );
2848 bool HasVertex( const TopoDS_Vertex& V ) const
2850 for ( size_t i = 0; i < _edges->size(); ++i )
2851 if ( V.IsSame( Vertex( i, 0 ))) return true;
2854 bool IsSideFace( const TopTools_ListOfShape& faces,
2855 const TopoDS_Face& avoidFace,
2856 const bool checkNeighbors ) const
2858 TopTools_ListIteratorOfListOfShape faceIt( faces );
2859 for ( ; faceIt.More(); faceIt.Next() )
2861 const TopoDS_Shape& face = faceIt.Value();
2862 if ( !face.IsSame( avoidFace ))
2864 if ( _faces->Contains( face )) // avoid returning true for a prism top FACE
2865 return ( !_face.IsNull() || !( face.IsSame( _faces->FindKey( _faces->Extent() ))));
2868 if ( checkNeighbors )
2869 return (( _leftSide && _leftSide->IsSideFace ( faces, avoidFace, false )) ||
2870 ( _rightSide && _rightSide->IsSideFace( faces, avoidFace, false )));
2875 //--------------------------------------------------------------------------------
2877 * \brief Return another faces sharing an edge
2879 const TopoDS_Face & getAnotherFace( const TopoDS_Face& face,
2880 const TopTools_ListOfShape& faces)
2882 TopTools_ListIteratorOfListOfShape faceIt( faces );
2883 for ( ; faceIt.More(); faceIt.Next() )
2884 if ( !face.IsSame( faceIt.Value() ))
2885 return TopoDS::Face( faceIt.Value() );
2888 //--------------------------------------------------------------------------------
2890 * \brief Return another faces sharing an edge
2892 const TopoDS_Face & getAnotherFace( const TopoDS_Face& face,
2893 const TopoDS_Edge& edge,
2894 TopTools_IndexedDataMapOfShapeListOfShape& facesOfEdge)
2896 return getAnotherFace( face, facesOfEdge.FindFromKey( edge ));
2899 //--------------------------------------------------------------------------------
2901 * \brief Return ordered edges of a face
2903 //================================================================================
2905 * \brief Return ordered edges of a face
2906 * \param [in] face - the face
2907 * \param [out] edges - return edge (edges from which no vertical faces raise excluded)
2908 * \param [in] facesOfEdge - faces of each edge
2909 * \param [in] noHolesAllowed - are multiple wires allowed
2911 //================================================================================
2913 bool getEdges( const TopoDS_Face& face,
2914 vector< EdgeWithNeighbors > & edges,
2915 TopTools_IndexedDataMapOfShapeListOfShape& facesOfEdge,
2916 const bool noHolesAllowed)
2918 TopoDS_Face f = face;
2919 if ( f.Orientation() != TopAbs_FORWARD &&
2920 f.Orientation() != TopAbs_REVERSED )
2921 f.Orientation( TopAbs_FORWARD );
2922 list< TopoDS_Edge > ee;
2923 list< int > nbEdgesInWires;
2924 int nbW = SMESH_Block::GetOrderedEdges( f, ee, nbEdgesInWires );
2925 if ( nbW > 1 && noHolesAllowed )
2928 list< TopoDS_Edge >::iterator e = ee.begin();
2929 list< int >::iterator nbE = nbEdgesInWires.begin();
2930 for ( ; nbE != nbEdgesInWires.end(); ++nbE )
2931 for ( int iE = 0; iE < *nbE; ++e, ++iE )
2932 if ( SMESH_Algo::isDegenerated( *e )) // degenerated EDGE is never used
2934 e = --ee.erase( e );
2939 int iE, nbTot = 0, iBase, nbBase, nbTotBase = 0;
2943 for ( nbE = nbEdgesInWires.begin(); nbE != nbEdgesInWires.end(); ++nbE )
2946 isBase.resize( *nbE );
2947 list< TopoDS_Edge >::iterator eIt = e;
2948 for ( iE = 0; iE < *nbE; ++eIt, ++iE )
2950 isBase[ iE ] = ( getAnotherFace( face, *eIt, facesOfEdge ) != face );
2951 nbBase += isBase[ iE ];
2953 for ( iBase = 0, iE = 0; iE < *nbE; ++e, ++iE )
2955 edges.push_back( EdgeWithNeighbors( *e,
2956 iBase, nbBase, nbTotBase,
2958 isBase[ iE ], nbW > 1 ));
2959 iBase += isBase[ iE ];
2962 nbTotBase += nbBase;
2964 if ( nbTotBase == 0 )
2967 // IPAL53099, 54416. Set correct neighbors to INTERNAL EDGEs
2970 int iFirst = 0, iLast;
2971 for ( nbE = nbEdgesInWires.begin(); nbE != nbEdgesInWires.end(); ++nbE )
2973 iLast = iFirst + *nbE - 1;
2974 bool isConnectOk = ( edges[ iFirst ].IsConnected( edges, 0 ) &&
2975 edges[ iFirst ].IsConnected( edges, 1 ));
2978 for ( iE = iFirst; iE <= iLast; ++iE )
2980 if ( !edges[ iE ]._isBase )
2982 int* iNei[] = { & edges[ iE ]._iL,
2983 & edges[ iE ]._iR };
2984 for ( int iV = 0; iV < 2; ++iV )
2986 if ( edges[ iE ].IsConnected( edges, iV ))
2987 continue; // Ok - connected to a neighbor EDGE
2989 // look for a connected EDGE
2991 for ( int iE2 = 0, nbE = edges.size(); iE2 < nbE && !found; ++iE2 )
2992 if (( iE2 != iE ) &&
2993 ( found = edges[ iE ].IsConnected( edges[ iE2 ], iV )))
2995 *iNei[ iV ] = edges[ iE2 ]._iBase;
2998 *iNei[ iV ] = edges[ iE ]._iBase; // connect to self
3005 return edges.size();
3008 //--------------------------------------------------------------------------------
3010 * \brief Return number of faces sharing given edges
3012 // int nbAdjacentFaces( const std::vector< EdgeWithNeighbors >& edges,
3013 // const TopTools_IndexedDataMapOfShapeListOfShape& facesOfEdge )
3015 // TopTools_MapOfShape adjFaces;
3017 // for ( size_t i = 0; i < edges.size(); ++i )
3019 // TopTools_ListIteratorOfListOfShape faceIt( facesOfEdge.FindFromKey( edges[i]._edge ));
3020 // for ( ; faceIt.More(); faceIt.Next() )
3021 // adjFaces.Add( faceIt.Value() );
3023 // return adjFaces.Extent();
3027 //================================================================================
3029 * \brief Return true if the algorithm can mesh this shape
3030 * \param [in] aShape - shape to check
3031 * \param [in] toCheckAll - if true, this check returns OK if all shapes are OK,
3032 * else, returns OK if at least one shape is OK
3034 //================================================================================
3036 bool StdMeshers_Prism_3D::IsApplicable(const TopoDS_Shape & shape, bool toCheckAll)
3038 TopExp_Explorer sExp( shape, TopAbs_SOLID );
3042 for ( ; sExp.More(); sExp.Next() )
3046 TopExp_Explorer shExp( sExp.Current(), TopAbs_SHELL );
3047 while ( shExp.More() ) {
3048 shell = shExp.Current();
3050 if ( shExp.More() && BRep_Tool::IsClosed( shExp.Current() ))
3053 if ( shell.IsNull() ) {
3054 if ( toCheckAll ) return false;
3058 TopTools_IndexedMapOfShape allFaces;
3059 TopExp::MapShapes( sExp.Current(), TopAbs_FACE, allFaces );
3060 if ( allFaces.Extent() < 3 ) {
3061 if ( toCheckAll ) return false;
3065 if ( allFaces.Extent() == 6 )
3067 TopTools_IndexedMapOfOrientedShape map;
3068 bool isBox = SMESH_Block::FindBlockShapes( TopoDS::Shell( shell ),
3069 TopoDS_Vertex(), TopoDS_Vertex(), map );
3071 if ( !toCheckAll ) return true;
3076 TopTools_IndexedMapOfShape allShapes; // usage: allShapes.FindIndex( s )
3077 TopExp::MapShapes( shape, allShapes );
3080 TopTools_IndexedDataMapOfShapeListOfShape facesOfEdge;
3081 TopTools_ListIteratorOfListOfShape faceIt;
3082 TopExp::MapShapesAndAncestors( sExp.Current(), TopAbs_EDGE, TopAbs_FACE , facesOfEdge );
3083 if ( facesOfEdge.IsEmpty() ) {
3084 if ( toCheckAll ) return false;
3088 typedef vector< EdgeWithNeighbors > TEdgeWithNeighborsVec;
3089 vector< TEdgeWithNeighborsVec > faceEdgesVec( allFaces.Extent() + 1 );
3090 const size_t nbEdgesMax = facesOfEdge.Extent() * 2; // there can be seam EDGEs
3091 TopTools_IndexedMapOfShape* facesOfSide = new TopTools_IndexedMapOfShape[ nbEdgesMax ];
3092 SMESHUtils::ArrayDeleter<TopTools_IndexedMapOfShape> delFacesOfSide( facesOfSide );
3094 // try to use each face as a bottom one
3095 bool prismDetected = false;
3096 vector< PrismSide > sides;
3097 for ( int iF = 1; iF < allFaces.Extent() && !prismDetected; ++iF )
3099 const TopoDS_Face& botF = TopoDS::Face( allFaces( iF ));
3101 TEdgeWithNeighborsVec& botEdges = faceEdgesVec[ iF ];
3102 if ( botEdges.empty() )
3103 if ( !getEdges( botF, botEdges, facesOfEdge, /*noHoles=*/false ))
3107 for ( size_t iS = 0; iS < botEdges.size(); ++iS )
3108 nbBase += botEdges[ iS ]._isBase;
3110 if ( allFaces.Extent()-1 <= nbBase )
3111 continue; // all faces are adjacent to botF - no top FACE
3113 // init data of side FACEs
3115 sides.resize( nbBase );
3117 for ( size_t iE = 0; iE < botEdges.size(); ++iE )
3119 if ( !botEdges[ iE ]._isBase )
3121 sides[ iS ]._topEdge = botEdges[ iE ]._edge;
3122 sides[ iS ]._face = botF;
3123 sides[ iS ]._leftSide = & sides[ botEdges[ iE ]._iR ];
3124 sides[ iS ]._rightSide = & sides[ botEdges[ iE ]._iL ];
3125 sides[ iS ]._isInternal = botEdges[ iE ].IsInternal();
3126 sides[ iS ]._faces = & facesOfSide[ iS ];
3127 sides[ iS ]._faces->Clear();
3131 bool isOK = true; // ok for a current botF
3132 bool hasAdvanced = true; // is new data found in a current loop
3133 int nbFoundSideFaces = 0;
3134 for ( int iLoop = 0; isOK && hasAdvanced; ++iLoop )
3136 hasAdvanced = false;
3137 for ( size_t iS = 0; iS < sides.size() && isOK; ++iS )
3139 PrismSide& side = sides[ iS ];
3140 if ( side._face.IsNull() )
3141 continue; // probably the prism top face is the last of side._faces
3143 if ( side._topEdge.IsNull() )
3145 // find vertical EDGEs --- EDGEs shared with neighbor side FACEs
3146 for ( int is2nd = 0; is2nd < 2 && isOK; ++is2nd ) // 2 adjacent neighbors
3148 const PrismSide* adjSide = is2nd ? side._rightSide : side._leftSide;
3149 if ( side._isInternal )
3151 const TopoDS_Vertex& V = side.Vertex( side._iBotEdge, is2nd );
3152 bool lHasV = side._leftSide ->HasVertex( V );
3153 bool rHasV = side._rightSide->HasVertex( V );
3154 if ( lHasV == rHasV )
3155 adjSide = ( &side == side._leftSide ) ? side._rightSide : side._leftSide;
3157 adjSide = ( rHasV ) ? side._rightSide : side._leftSide;
3159 int di = is2nd ? 1 : -1;
3160 for ( size_t i = 1; i < side._edges->size(); ++i )
3162 int iE = SMESH_MesherHelper::WrapIndex( i*di + side._iBotEdge, side._edges->size());
3163 if ( side._isCheckedEdge[ iE ] ) continue;
3164 const TopoDS_Edge& vertE = side.Edge( iE );
3165 const TopTools_ListOfShape& neighborFF = facesOfEdge.FindFromKey( vertE );
3166 bool isEdgeShared = (( adjSide->IsSideFace( neighborFF, side._face,
3167 side._isInternal )) ||
3168 ( adjSide == &side &&
3169 side._face.IsSame( getAnotherFace( side._face,
3171 if ( isEdgeShared ) // vertE is shared with adjSide
3174 side._isCheckedEdge[ iE ] = true;
3175 side._nbCheckedEdges++;
3176 int nbNotCheckedE = side._edges->size() - side._nbCheckedEdges;
3177 if ( nbNotCheckedE == 1 )
3182 if ( i == 1 && iLoop == 0 ) isOK = false;
3188 int nbNotCheckedE = side._edges->size() - side._nbCheckedEdges;
3189 if ( nbNotCheckedE == 1 )
3191 vector<bool>::iterator ii = std::find( side._isCheckedEdge.begin(),
3192 side._isCheckedEdge.end(), false );
3193 if ( ii != side._isCheckedEdge.end() )
3195 size_t iE = std::distance( side._isCheckedEdge.begin(), ii );
3196 side._topEdge = side.Edge( iE );
3199 isOK = ( nbNotCheckedE >= 1 );
3201 else //if ( !side._topEdge.IsNull() )
3203 // get a next face of a side
3204 const TopoDS_Shape& f = getAnotherFace( side._face, side._topEdge, facesOfEdge );
3205 side._faces->Add( f );
3207 if ( f.IsSame( side._face ) || // _topEdge is a seam
3208 SMESH_MesherHelper::Count( f, TopAbs_WIRE, false ) != 1 )
3212 else if ( side._leftSide != & side && // not closed side face
3213 side._leftSide->_faces->Contains( f ))
3215 stop = true; // probably f is the prism top face
3216 side._leftSide->_face.Nullify();
3217 side._leftSide->_topEdge.Nullify();
3219 else if ( side._rightSide != & side &&
3220 side._rightSide->_faces->Contains( f ))
3222 stop = true; // probably f is the prism top face
3223 side._rightSide->_face.Nullify();
3224 side._rightSide->_topEdge.Nullify();
3228 side._face.Nullify();
3229 side._topEdge.Nullify();
3232 side._face = TopoDS::Face( f );
3233 int faceID = allFaces.FindIndex( side._face );
3234 side._edges = & faceEdgesVec[ faceID ];
3235 if ( side._edges->empty() )
3236 if ( !getEdges( side._face, * side._edges, facesOfEdge, /*noHoles=*/true ))
3238 const int nbE = side._edges->size();
3243 side._iBotEdge = side.FindEdge( side._topEdge );
3244 side._isCheckedEdge.clear();
3245 side._isCheckedEdge.resize( nbE, false );
3246 side._isCheckedEdge[ side._iBotEdge ] = true;
3247 side._nbCheckedEdges = 1; // bottom EDGE is known
3249 else // probably a triangular top face found
3251 side._face.Nullify();
3253 side._topEdge.Nullify();
3254 isOK = ( !side._edges->empty() || side._faces->Extent() > 1 );
3256 } //if ( !side._topEdge.IsNull() )
3258 } // loop on prism sides
3260 if ( nbFoundSideFaces > allFaces.Extent() )
3264 if ( iLoop > allFaces.Extent() * 10 )
3268 cerr << "BUG: infinite loop in StdMeshers_Prism_3D::IsApplicable()" << endl;
3271 } // while hasAdvanced
3273 if ( isOK && sides[0]._faces->Extent() > 1 )
3275 const int nbFaces = sides[0]._faces->Extent();
3276 if ( botEdges.size() == 1 ) // cylinder
3278 prismDetected = ( nbFaces == allFaces.Extent()-1 );
3282 // check that all face columns end up at the same top face
3283 const TopoDS_Shape& topFace = sides[0]._faces->FindKey( nbFaces );
3285 for ( iS = 1; iS < sides.size(); ++iS )
3286 if ( ! sides[ iS ]._faces->Contains( topFace ))
3288 if (( prismDetected = ( iS == sides.size() )))
3290 // check that bottom and top faces has equal nb of edges
3291 TEdgeWithNeighborsVec& topEdges = faceEdgesVec[ allFaces.FindIndex( topFace )];
3292 if ( topEdges.empty() )
3293 getEdges( TopoDS::Face( topFace ), topEdges, facesOfEdge, /*noHoles=*/false );
3294 prismDetected = ( botEdges.size() == topEdges.size() );
3298 } // loop on allFaces
3300 if ( !prismDetected && toCheckAll ) return false;
3301 if ( prismDetected && !toCheckAll ) return true;
3310 //================================================================================
3312 * \brief Return true if this node and other one belong to one face
3314 //================================================================================
3316 bool Prism_3D::TNode::IsNeighbor( const Prism_3D::TNode& other ) const
3318 if ( !other.myNode || !myNode ) return false;
3320 SMDS_ElemIteratorPtr fIt = other.myNode->GetInverseElementIterator(SMDSAbs_Face);
3321 while ( fIt->more() )
3322 if ( fIt->next()->GetNodeIndex( myNode ) >= 0 )
3327 //================================================================================
3329 * \brief Prism initialization
3331 //================================================================================
3333 void TPrismTopo::Clear()
3335 myShape3D.Nullify();
3338 myWallQuads.clear();
3339 myBottomEdges.clear();
3340 myNbEdgesInWires.clear();
3341 myWallQuads.clear();
3344 //================================================================================
3346 * \brief Set upside-down
3348 //================================================================================
3350 void TPrismTopo::SetUpsideDown()
3352 std::swap( myBottom, myTop );
3353 myBottomEdges.clear();
3354 std::reverse( myBottomEdges.begin(), myBottomEdges.end() );
3355 for ( size_t i = 0; i < myWallQuads.size(); ++i )
3357 myWallQuads[i].reverse();
3358 TQuadList::iterator q = myWallQuads[i].begin();
3359 for ( ; q != myWallQuads[i].end(); ++q )
3361 (*q)->shift( 2, /*keepUnitOri=*/true );
3363 myBottomEdges.push_back( myWallQuads[i].front()->side[ QUAD_BOTTOM_SIDE ].grid->Edge(0) );
3367 } // namespace Prism_3D
3369 //================================================================================
3371 * \brief Constructor. Initialization is needed
3373 //================================================================================
3375 StdMeshers_PrismAsBlock::StdMeshers_PrismAsBlock()
3380 StdMeshers_PrismAsBlock::~StdMeshers_PrismAsBlock()
3384 void StdMeshers_PrismAsBlock::Clear()
3387 myShapeIDMap.Clear();
3391 delete mySide; mySide = 0;
3393 myParam2ColumnMaps.clear();
3394 myShapeIndex2ColumnMap.clear();
3397 //=======================================================================
3398 //function : initPrism
3399 //purpose : Analyse shape geometry and mesh.
3400 // If there are triangles on one of faces, it becomes 'bottom'.
3401 // thePrism.myBottom can be already set up.
3402 //=======================================================================
3404 bool StdMeshers_Prism_3D::initPrism(Prism_3D::TPrismTopo& thePrism,
3405 const TopoDS_Shape& theShape3D,
3406 const bool selectBottom)
3408 myHelper->SetSubShape( theShape3D );
3410 SMESH_subMesh* mainSubMesh = myHelper->GetMesh()->GetSubMeshContaining( theShape3D );
3411 if ( !mainSubMesh ) return toSM( error(COMPERR_BAD_INPUT_MESH,"Null submesh of shape3D"));
3413 // detect not-quad FACE sub-meshes of the 3D SHAPE
3414 list< SMESH_subMesh* > notQuadGeomSubMesh;
3415 list< SMESH_subMesh* > notQuadElemSubMesh;
3416 list< SMESH_subMesh* > meshedSubMesh;
3419 SMESH_subMeshIteratorPtr smIt = mainSubMesh->getDependsOnIterator(false,true);
3420 while ( smIt->more() )
3422 SMESH_subMesh* sm = smIt->next();
3423 const TopoDS_Shape& face = sm->GetSubShape();
3424 if ( face.ShapeType() > TopAbs_FACE ) break;
3425 else if ( face.ShapeType() < TopAbs_FACE ) continue;
3428 // is quadrangle FACE?
3429 list< TopoDS_Edge > orderedEdges;
3430 list< int > nbEdgesInWires;
3431 int nbWires = SMESH_Block::GetOrderedEdges( TopoDS::Face( face ), orderedEdges,
3433 if ( nbWires != 1 || nbEdgesInWires.front() != 4 )
3434 notQuadGeomSubMesh.push_back( sm );
3436 // look for a not structured sub-mesh
3437 if ( !sm->IsEmpty() )
3439 meshedSubMesh.push_back( sm );
3440 if ( !myHelper->IsSameElemGeometry( sm->GetSubMeshDS(), SMDSGeom_QUADRANGLE ) ||
3441 !myHelper->IsStructured ( sm ))
3442 notQuadElemSubMesh.push_back( sm );
3446 int nbNotQuadMeshed = notQuadElemSubMesh.size();
3447 int nbNotQuad = notQuadGeomSubMesh.size();
3448 bool hasNotQuad = ( nbNotQuad || nbNotQuadMeshed );
3451 if ( nbNotQuadMeshed > 2 )
3453 return toSM( error(COMPERR_BAD_INPUT_MESH,
3454 TCom("More than 2 faces with not quadrangle elements: ")
3455 <<nbNotQuadMeshed));
3457 if ( nbNotQuad > 2 || !thePrism.myBottom.IsNull() )
3459 // Issue 0020843 - one of side FACEs is quasi-quadrilateral (not 4 EDGEs).
3460 // Remove from notQuadGeomSubMesh faces meshed with regular grid
3461 int nbQuasiQuads = removeQuasiQuads( notQuadGeomSubMesh, myHelper,
3462 TQuadrangleAlgo::instance(this,myHelper) );
3463 nbNotQuad -= nbQuasiQuads;
3464 if ( nbNotQuad > 2 )
3465 return toSM( error(COMPERR_BAD_SHAPE,
3466 TCom("More than 2 not quadrilateral faces: ") <<nbNotQuad));
3467 hasNotQuad = ( nbNotQuad || nbNotQuadMeshed );
3470 // Analyse mesh and topology of FACEs: choose the bottom sub-mesh.
3471 // If there are not quadrangle FACEs, they are top and bottom ones.
3472 // Not quadrangle FACEs must be only on top and bottom.
3474 SMESH_subMesh * botSM = 0;
3475 SMESH_subMesh * topSM = 0;
3477 if ( hasNotQuad ) // can choose a bottom FACE
3479 if ( nbNotQuadMeshed > 0 ) botSM = notQuadElemSubMesh.front();
3480 else botSM = notQuadGeomSubMesh.front();
3481 if ( nbNotQuadMeshed > 1 ) topSM = notQuadElemSubMesh.back();
3482 else if ( nbNotQuad > 1 ) topSM = notQuadGeomSubMesh.back();
3484 if ( topSM == botSM ) {
3485 if ( nbNotQuadMeshed > 1 ) topSM = notQuadElemSubMesh.front();
3486 else topSM = notQuadGeomSubMesh.front();
3489 // detect mesh triangles on wall FACEs
3490 if ( nbNotQuad == 2 && nbNotQuadMeshed > 0 ) {
3492 if ( nbNotQuadMeshed == 1 )
3493 ok = ( find( notQuadGeomSubMesh.begin(),
3494 notQuadGeomSubMesh.end(), botSM ) != notQuadGeomSubMesh.end() );
3496 ok = ( notQuadGeomSubMesh == notQuadElemSubMesh );
3498 return toSM( error(COMPERR_BAD_INPUT_MESH,
3499 "Side face meshed with not quadrangle elements"));
3503 thePrism.myNotQuadOnTop = ( nbNotQuadMeshed > 1 );
3505 // use thePrism.myBottom
3506 if ( !thePrism.myBottom.IsNull() )
3508 if ( botSM ) { // <-- not quad geom or mesh on botSM
3509 if ( ! botSM->GetSubShape().IsSame( thePrism.myBottom )) {
3510 std::swap( botSM, topSM );
3511 if ( !botSM || ! botSM->GetSubShape().IsSame( thePrism.myBottom )) {
3512 if ( !selectBottom )
3513 return toSM( error( COMPERR_BAD_INPUT_MESH,
3514 "Incompatible non-structured sub-meshes"));
3515 std::swap( botSM, topSM );
3516 thePrism.myBottom = TopoDS::Face( botSM->GetSubShape() );
3520 else if ( !selectBottom ) {
3521 botSM = myHelper->GetMesh()->GetSubMesh( thePrism.myBottom );
3524 if ( !botSM ) // find a proper bottom
3526 bool savedSetErrorToSM = mySetErrorToSM;
3527 mySetErrorToSM = false; // ignore errors in initPrism()
3529 // search among meshed FACEs
3530 list< SMESH_subMesh* >::iterator sm = meshedSubMesh.begin();
3531 for ( ; !botSM && sm != meshedSubMesh.end(); ++sm )
3535 thePrism.myBottom = TopoDS::Face( botSM->GetSubShape() );
3536 if ( !initPrism( thePrism, theShape3D, /*selectBottom=*/false ))
3539 // search among all FACEs
3540 for ( TopExp_Explorer f( theShape3D, TopAbs_FACE ); !botSM && f.More(); f.Next() )
3542 int minNbFaces = 2 + myHelper->Count( f.Current(), TopAbs_EDGE, false);
3543 if ( nbFaces < minNbFaces) continue;
3545 thePrism.myBottom = TopoDS::Face( f.Current() );
3546 botSM = myHelper->GetMesh()->GetSubMesh( thePrism.myBottom );
3547 if ( !initPrism( thePrism, theShape3D, /*selectBottom=*/false ))
3550 mySetErrorToSM = savedSetErrorToSM;
3551 return botSM ? true : toSM( error( COMPERR_BAD_SHAPE ));
3554 // find vertex 000 - the one with smallest coordinates (for easy DEBUG :-)
3556 double minVal = DBL_MAX, minX = 0, val;
3557 for ( TopExp_Explorer exp( botSM->GetSubShape(), TopAbs_VERTEX );
3558 exp.More(); exp.Next() )
3560 const TopoDS_Vertex& v = TopoDS::Vertex( exp.Current() );
3561 gp_Pnt P = BRep_Tool::Pnt( v );
3562 val = P.X() + P.Y() + P.Z();
3563 if ( val < minVal || ( val == minVal && P.X() < minX )) {
3570 thePrism.myShape3D = theShape3D;
3571 if ( thePrism.myBottom.IsNull() )
3572 thePrism.myBottom = TopoDS::Face( botSM->GetSubShape() );
3573 thePrism.myBottom.Orientation( myHelper->GetSubShapeOri( theShape3D, thePrism.myBottom ));
3574 thePrism.myTop. Orientation( myHelper->GetSubShapeOri( theShape3D, thePrism.myTop ));
3576 // Get ordered bottom edges
3577 TopoDS_Face reverseBottom = // to have order of top EDGEs as in the top FACE
3578 TopoDS::Face( thePrism.myBottom.Reversed() );
3579 SMESH_Block::GetOrderedEdges( reverseBottom,
3580 thePrism.myBottomEdges,
3581 thePrism.myNbEdgesInWires, V000 );
3583 // Get Wall faces corresponding to the ordered bottom edges and the top FACE
3584 if ( !getWallFaces( thePrism, nbFaces )) // it also sets thePrism.myTop
3585 return false; //toSM( error(COMPERR_BAD_SHAPE, "Can't find side faces"));
3589 if ( !thePrism.myTop.IsSame( topSM->GetSubShape() ))
3591 (notQuadGeomSubMesh.empty() ? COMPERR_BAD_INPUT_MESH : COMPERR_BAD_SHAPE,
3592 "Non-quadrilateral faces are not opposite"));
3594 // check that the found top and bottom FACEs are opposite
3595 TopTools_IndexedMapOfShape topEdgesMap( thePrism.myBottomEdges.size() );
3596 TopExp::MapShapes( thePrism.myTop, topEdgesMap );
3597 list< TopoDS_Edge >::iterator edge = thePrism.myBottomEdges.begin();
3598 for ( ; edge != thePrism.myBottomEdges.end(); ++edge )
3599 if ( topEdgesMap.Contains( *edge ))
3601 (notQuadGeomSubMesh.empty() ? COMPERR_BAD_INPUT_MESH : COMPERR_BAD_SHAPE,
3602 "Non-quadrilateral faces are not opposite"));
3605 if ( thePrism.myBottomEdges.size() > thePrism.myWallQuads.size() )
3607 // composite bottom sides => set thePrism upside-down
3608 thePrism.SetUpsideDown();
3614 //================================================================================
3616 * \brief Initialization.
3617 * \param helper - helper loaded with mesh and 3D shape
3618 * \param thePrism - a prism data
3619 * \retval bool - false if a mesh or a shape are KO
3621 //================================================================================
3623 bool StdMeshers_PrismAsBlock::Init(SMESH_MesherHelper* helper,
3624 const Prism_3D::TPrismTopo& thePrism)
3627 SMESHDS_Mesh* meshDS = myHelper->GetMeshDS();
3628 SMESH_Mesh* mesh = myHelper->GetMesh();
3631 delete mySide; mySide = 0;
3633 vector< TSideFace* > sideFaces( NB_WALL_FACES, 0 );
3634 vector< pair< double, double> > params( NB_WALL_FACES );
3635 mySide = new TSideFace( *mesh, sideFaces, params );
3638 SMESH_Block::init();
3639 myShapeIDMap.Clear();
3640 myShapeIndex2ColumnMap.clear();
3642 int wallFaceIds[ NB_WALL_FACES ] = { // to walk around a block
3643 SMESH_Block::ID_Fx0z, SMESH_Block::ID_F1yz,
3644 SMESH_Block::ID_Fx1z, SMESH_Block::ID_F0yz
3647 myError = SMESH_ComputeError::New();
3649 myNotQuadOnTop = thePrism.myNotQuadOnTop;
3651 // Find columns of wall nodes and calculate edges' lengths
3652 // --------------------------------------------------------
3654 myParam2ColumnMaps.clear();
3655 myParam2ColumnMaps.resize( thePrism.myBottomEdges.size() ); // total nb edges
3657 size_t iE, nbEdges = thePrism.myNbEdgesInWires.front(); // nb outer edges
3658 vector< double > edgeLength( nbEdges );
3659 multimap< double, int > len2edgeMap;
3661 // for each EDGE: either split into several parts, or join with several next EDGEs
3662 vector<int> nbSplitPerEdge( nbEdges, 0 );
3663 vector<int> nbUnitePerEdge( nbEdges, 0 ); // -1 means "joined to a previous"
3665 // consider continuous straight EDGEs as one side
3666 const int nbSides = countNbSides( thePrism, nbUnitePerEdge, edgeLength );
3668 list< TopoDS_Edge >::const_iterator edgeIt = thePrism.myBottomEdges.begin();
3669 for ( iE = 0; iE < nbEdges; ++iE, ++edgeIt )
3671 TParam2ColumnMap & faceColumns = myParam2ColumnMaps[ iE ];
3673 Prism_3D::TQuadList::const_iterator quad = thePrism.myWallQuads[ iE ].begin();
3674 for ( ; quad != thePrism.myWallQuads[ iE ].end(); ++quad )
3676 const TopoDS_Edge& quadBot = (*quad)->side[ QUAD_BOTTOM_SIDE ].grid->Edge( 0 );
3677 if ( !myHelper->LoadNodeColumns( faceColumns, (*quad)->face, quadBot, meshDS ))
3678 return error(COMPERR_BAD_INPUT_MESH, TCom("Can't find regular quadrangle mesh ")
3679 << "on a side face #" << MeshDS()->ShapeToIndex( (*quad)->face ));
3681 SHOWYXZ("\np1 F " <<iE, gpXYZ(faceColumns.begin()->second.front() ));
3682 SHOWYXZ("p2 F " <<iE, gpXYZ(faceColumns.rbegin()->second.front() ));
3683 SHOWYXZ("V First "<<iE, BRep_Tool::Pnt( TopExp::FirstVertex(*edgeIt,true )));
3685 if ( nbSides < NB_WALL_FACES ) // fill map used to split faces
3686 len2edgeMap.insert( make_pair( edgeLength[ iE ], iE )); // sort edges by length
3688 // Load columns of internal edges (forming holes)
3689 // and fill map ShapeIndex to TParam2ColumnMap for them
3690 for ( ; edgeIt != thePrism.myBottomEdges.end() ; ++edgeIt, ++iE )
3692 TParam2ColumnMap & faceColumns = myParam2ColumnMaps[ iE ];
3694 Prism_3D::TQuadList::const_iterator quad = thePrism.myWallQuads[ iE ].begin();
3695 for ( ; quad != thePrism.myWallQuads[ iE ].end(); ++quad )
3697 const TopoDS_Edge& quadBot = (*quad)->side[ QUAD_BOTTOM_SIDE ].grid->Edge( 0 );
3698 if ( !myHelper->LoadNodeColumns( faceColumns, (*quad)->face, quadBot, meshDS ))
3699 return error(COMPERR_BAD_INPUT_MESH, TCom("Can't find regular quadrangle mesh ")
3700 << "on a side face #" << MeshDS()->ShapeToIndex( (*quad)->face ));
3702 if ( !faceColumns.empty() && (int)faceColumns.begin()->second.size() != VerticalSize() )
3703 return error(COMPERR_BAD_INPUT_MESH, "Different 'vertical' discretization");
3706 int id = MeshDS()->ShapeToIndex( *edgeIt );
3707 bool isForward = true; // meaningless for intenal wires
3708 myShapeIndex2ColumnMap[ id ] = make_pair( & faceColumns, isForward );
3709 // columns for vertices
3711 const SMDS_MeshNode* n0 = faceColumns.begin()->second.front();
3712 id = n0->getshapeId();
3713 myShapeIndex2ColumnMap[ id ] = make_pair( & faceColumns, isForward );
3715 const SMDS_MeshNode* n1 = faceColumns.rbegin()->second.front();
3716 id = n1->getshapeId();
3717 myShapeIndex2ColumnMap[ id ] = make_pair( & faceColumns, isForward );
3719 // SHOWYXZ("\np1 F " <<iE, gpXYZ(faceColumns.begin()->second.front() ));
3720 // SHOWYXZ("p2 F " <<iE, gpXYZ(faceColumns.rbegin()->second.front() ));
3721 // SHOWYXZ("V First "<<iE, BRep_Tool::Pnt( TopExp::FirstVertex(*edgeIt,true )));
3724 // Create 4 wall faces of a block
3725 // -------------------------------
3727 if ( nbSides <= NB_WALL_FACES ) // ************* Split faces if necessary
3729 if ( nbSides != NB_WALL_FACES ) // define how to split
3731 if ( len2edgeMap.size() != nbEdges )
3732 RETURN_BAD_RESULT("Uniqueness of edge lengths not assured");
3734 multimap< double, int >::reverse_iterator maxLen_i = len2edgeMap.rbegin();
3735 multimap< double, int >::reverse_iterator midLen_i = ++len2edgeMap.rbegin();
3737 double maxLen = maxLen_i->first;
3738 double midLen = ( len2edgeMap.size() == 1 ) ? 0 : midLen_i->first;
3739 switch ( nbEdges ) {
3740 case 1: // 0-th edge is split into 4 parts
3741 nbSplitPerEdge[ 0 ] = 4;
3743 case 2: // either the longest edge is split into 3 parts, or both edges into halves
3744 if ( maxLen / 3 > midLen / 2 ) {
3745 nbSplitPerEdge[ maxLen_i->second ] = 3;
3748 nbSplitPerEdge[ maxLen_i->second ] = 2;
3749 nbSplitPerEdge[ midLen_i->second ] = 2;
3754 // split longest into 3 parts
3755 nbSplitPerEdge[ maxLen_i->second ] = 3;
3757 // split longest into halves
3758 nbSplitPerEdge[ maxLen_i->second ] = 2;
3762 else // **************************** Unite faces
3764 int nbExraFaces = nbSides - 4; // nb of faces to fuse
3765 for ( iE = 0; iE < nbEdges; ++iE )
3767 if ( nbUnitePerEdge[ iE ] < 0 )
3769 // look for already united faces
3770 for ( size_t i = iE; i < iE + nbExraFaces; ++i )
3772 if ( nbUnitePerEdge[ i ] > 0 ) // a side including nbUnitePerEdge[i]+1 edge
3773 nbExraFaces += nbUnitePerEdge[ i ];
3774 nbUnitePerEdge[ i ] = -1;
3776 nbUnitePerEdge[ iE ] = nbExraFaces;
3781 // Create TSideFace's
3783 list< TopoDS_Edge >::const_iterator botE = thePrism.myBottomEdges.begin();
3784 for ( iE = 0; iE < nbEdges; ++iE, ++botE )
3786 TFaceQuadStructPtr quad = thePrism.myWallQuads[ iE ].front();
3787 const int nbSplit = nbSplitPerEdge[ iE ];
3788 const int nbExraFaces = nbUnitePerEdge[ iE ] + 1;
3789 if ( nbSplit > 0 ) // split
3791 vector< double > params;
3792 splitParams( nbSplit, &myParam2ColumnMaps[ iE ], params );
3793 const bool isForward =
3794 StdMeshers_PrismAsBlock::IsForwardEdge( myHelper->GetMeshDS(),
3795 myParam2ColumnMaps[iE],
3796 *botE, SMESH_Block::ID_Fx0z );
3797 for ( int i = 0; i < nbSplit; ++i ) {
3798 double f = ( isForward ? params[ i ] : params[ nbSplit - i-1 ]);
3799 double l = ( isForward ? params[ i+1 ] : params[ nbSplit - i ]);
3800 TSideFace* comp = new TSideFace( *mesh, wallFaceIds[ iSide ],
3801 thePrism.myWallQuads[ iE ], *botE,
3802 &myParam2ColumnMaps[ iE ], f, l );
3803 mySide->SetComponent( iSide++, comp );
3806 else if ( nbExraFaces > 1 ) // unite
3808 double u0 = 0, sumLen = 0;
3809 for ( size_t i = iE; i < iE + nbExraFaces; ++i )
3810 sumLen += edgeLength[ i ];
3812 vector< TSideFace* > components( nbExraFaces );
3813 vector< pair< double, double> > params( nbExraFaces );
3814 bool endReached = false;
3815 for ( int i = 0; i < nbExraFaces; ++i, ++botE, ++iE )
3817 if ( iE == nbEdges )
3820 botE = thePrism.myBottomEdges.begin();
3823 components[ i ] = new TSideFace( *mesh, wallFaceIds[ iSide ],
3824 thePrism.myWallQuads[ iE ], *botE,
3825 &myParam2ColumnMaps[ iE ]);
3826 double u1 = u0 + edgeLength[ iE ] / sumLen;
3827 params[ i ] = make_pair( u0 , u1 );
3830 TSideFace* comp = new TSideFace( *mesh, components, params );
3831 mySide->SetComponent( iSide++, comp );
3834 --iE; // for increment in an external loop on iE
3837 else if ( nbExraFaces < 0 ) // skip already united face
3842 TSideFace* comp = new TSideFace( *mesh, wallFaceIds[ iSide ],
3843 thePrism.myWallQuads[ iE ], *botE,
3844 &myParam2ColumnMaps[ iE ]);
3845 mySide->SetComponent( iSide++, comp );
3850 // Fill geometry fields of SMESH_Block
3851 // ------------------------------------
3853 vector< int > botEdgeIdVec;
3854 SMESH_Block::GetFaceEdgesIDs( ID_BOT_FACE, botEdgeIdVec );
3856 bool isForward[NB_WALL_FACES] = { true, true, true, true };
3857 Adaptor2d_Curve2d* botPcurves[NB_WALL_FACES];
3858 Adaptor2d_Curve2d* topPcurves[NB_WALL_FACES];
3860 for ( int iF = 0; iF < NB_WALL_FACES; ++iF )
3862 TSideFace * sideFace = mySide->GetComponent( iF );
3864 RETURN_BAD_RESULT("NULL TSideFace");
3865 int fID = sideFace->FaceID(); // in-block ID
3867 // fill myShapeIDMap
3868 if ( sideFace->InsertSubShapes( myShapeIDMap ) != 8 &&
3869 !sideFace->IsComplex())
3870 MESSAGE( ": Warning : InsertSubShapes() < 8 on side " << iF );
3872 // side faces geometry
3873 Adaptor2d_Curve2d* pcurves[NB_WALL_FACES];
3874 if ( !sideFace->GetPCurves( pcurves ))
3875 RETURN_BAD_RESULT("TSideFace::GetPCurves() failed");
3877 SMESH_Block::TFace& tFace = myFace[ fID - ID_FirstF ];
3878 tFace.Set( fID, sideFace->Surface(), pcurves, isForward );
3880 SHOWYXZ( endl<<"F "<< iF << " id " << fID << " FRW " << sideFace->IsForward(), sideFace->Value(0,0));
3881 // edges 3D geometry
3882 vector< int > edgeIdVec;
3883 SMESH_Block::GetFaceEdgesIDs( fID, edgeIdVec );
3884 for ( int isMax = 0; isMax < 2; ++isMax ) {
3886 int eID = edgeIdVec[ isMax ];
3887 SMESH_Block::TEdge& tEdge = myEdge[ eID - ID_FirstE ];
3888 tEdge.Set( eID, sideFace->HorizCurve(isMax), true);
3889 SHOWYXZ(eID<<" HOR"<<isMax<<"(0)", sideFace->HorizCurve(isMax)->Value(0));
3890 SHOWYXZ(eID<<" HOR"<<isMax<<"(1)", sideFace->HorizCurve(isMax)->Value(1));
3893 int eID = edgeIdVec[ isMax+2 ];
3894 SMESH_Block::TEdge& tEdge = myEdge[ eID - ID_FirstE ];
3895 tEdge.Set( eID, sideFace->VertiCurve(isMax), true);
3896 SHOWYXZ(eID<<" VER"<<isMax<<"(0)", sideFace->VertiCurve(isMax)->Value(0));
3897 SHOWYXZ(eID<<" VER"<<isMax<<"(1)", sideFace->VertiCurve(isMax)->Value(1));
3900 vector< int > vertexIdVec;
3901 SMESH_Block::GetEdgeVertexIDs( eID, vertexIdVec );
3902 myPnt[ vertexIdVec[0] - ID_FirstV ] = tEdge.GetCurve()->Value(0).XYZ();
3903 myPnt[ vertexIdVec[1] - ID_FirstV ] = tEdge.GetCurve()->Value(1).XYZ();
3906 // pcurves on horizontal faces
3907 for ( iE = 0; iE < NB_WALL_FACES; ++iE ) {
3908 if ( edgeIdVec[ BOTTOM_EDGE ] == botEdgeIdVec[ iE ] ) {
3909 botPcurves[ iE ] = sideFace->HorizPCurve( false, thePrism.myBottom );
3910 topPcurves[ iE ] = sideFace->HorizPCurve( true, thePrism.myTop );
3914 //sideFace->dumpNodes( 4 ); // debug
3916 // horizontal faces geometry
3918 SMESH_Block::TFace& tFace = myFace[ ID_BOT_FACE - ID_FirstF ];
3919 tFace.Set( ID_BOT_FACE, new BRepAdaptor_Surface( thePrism.myBottom ), botPcurves, isForward );
3920 SMESH_Block::Insert( thePrism.myBottom, ID_BOT_FACE, myShapeIDMap );
3923 SMESH_Block::TFace& tFace = myFace[ ID_TOP_FACE - ID_FirstF ];
3924 tFace.Set( ID_TOP_FACE, new BRepAdaptor_Surface( thePrism.myTop ), topPcurves, isForward );
3925 SMESH_Block::Insert( thePrism.myTop, ID_TOP_FACE, myShapeIDMap );
3927 //faceGridToPythonDump( SMESH_Block::ID_Fxy0, 50 );
3928 //faceGridToPythonDump( SMESH_Block::ID_Fxy1 );
3930 // Fill map ShapeIndex to TParam2ColumnMap
3931 // ----------------------------------------
3933 list< TSideFace* > fList;
3934 list< TSideFace* >::iterator fListIt;
3935 fList.push_back( mySide );
3936 for ( fListIt = fList.begin(); fListIt != fList.end(); ++fListIt)
3938 int nb = (*fListIt)->NbComponents();
3939 for ( int i = 0; i < nb; ++i ) {
3940 if ( TSideFace* comp = (*fListIt)->GetComponent( i ))
3941 fList.push_back( comp );
3943 if ( TParam2ColumnMap* cols = (*fListIt)->GetColumns()) {
3944 // columns for a base edge
3945 int id = MeshDS()->ShapeToIndex( (*fListIt)->BaseEdge() );
3946 bool isForward = (*fListIt)->IsForward();
3947 myShapeIndex2ColumnMap[ id ] = make_pair( cols, isForward );
3949 // columns for vertices
3950 const SMDS_MeshNode* n0 = cols->begin()->second.front();
3951 id = n0->getshapeId();
3952 myShapeIndex2ColumnMap[ id ] = make_pair( cols, isForward );
3954 const SMDS_MeshNode* n1 = cols->rbegin()->second.front();
3955 id = n1->getshapeId();
3956 myShapeIndex2ColumnMap[ id ] = make_pair( cols, !isForward );
3960 // #define SHOWYXZ(msg, xyz) { gp_Pnt p(xyz); cout << msg << " ("<< p.X() << "; " <<p.Y() << "; " <<p.Z() << ") " <<endl; }
3962 // double _u[]={ 0.1, 0.1, 0.9, 0.9 };
3963 // double _v[]={ 0.1, 0.9, 0.1, 0.9 };
3964 // for ( int z = 0; z < 2; ++z )
3965 // for ( int i = 0; i < 4; ++i )
3967 // //gp_XYZ testPar(0.25, 0.25, 0), testCoord;
3968 // int iFace = (z ? ID_TOP_FACE : ID_BOT_FACE);
3969 // gp_XYZ testPar(_u[i], _v[i], z), testCoord;
3970 // if ( !FacePoint( iFace, testPar, testCoord ))
3971 // RETURN_BAD_RESULT("TEST FacePoint() FAILED");
3972 // SHOWYXZ("IN TEST PARAM" , testPar);
3973 // SHOWYXZ("OUT TEST CORD" , testCoord);
3974 // if ( !ComputeParameters( testCoord, testPar , iFace))
3975 // RETURN_BAD_RESULT("TEST ComputeParameters() FAILED");
3976 // SHOWYXZ("OUT TEST PARAM" , testPar);
3981 //================================================================================
3983 * \brief Return pointer to column of nodes
3984 * \param node - bottom node from which the returned column goes up
3985 * \retval const TNodeColumn* - the found column
3987 //================================================================================
3989 const TNodeColumn* StdMeshers_PrismAsBlock::GetNodeColumn(const SMDS_MeshNode* node) const
3991 int sID = node->getshapeId();
3993 map<int, pair< TParam2ColumnMap*, bool > >::const_iterator col_frw =
3994 myShapeIndex2ColumnMap.find( sID );
3995 if ( col_frw != myShapeIndex2ColumnMap.end() ) {
3996 const TParam2ColumnMap* cols = col_frw->second.first;
3997 TParam2ColumnIt u_col = cols->begin();
3998 for ( ; u_col != cols->end(); ++u_col )
3999 if ( u_col->second[ 0 ] == node )
4000 return & u_col->second;
4005 //=======================================================================
4006 //function : GetLayersTransformation
4007 //purpose : Return transformations to get coordinates of nodes of each layer
4008 // by nodes of the bottom. Layer is a set of nodes at a certain step
4009 // from bottom to top.
4010 // Transformation to get top node from bottom ones is computed
4011 // only if the top FACE is not meshed.
4012 //=======================================================================
4014 bool StdMeshers_PrismAsBlock::GetLayersTransformation(vector<gp_Trsf> & trsf,
4015 const Prism_3D::TPrismTopo& prism) const
4017 const bool itTopMeshed = !SubMesh( ID_BOT_FACE )->IsEmpty();
4018 const int zSize = VerticalSize();
4019 if ( zSize < 3 && !itTopMeshed ) return true;
4020 trsf.resize( zSize - 1 );
4022 // Select some node columns by which we will define coordinate system of layers
4024 vector< const TNodeColumn* > columns;
4027 list< TopoDS_Edge >::const_iterator edgeIt = prism.myBottomEdges.begin();
4028 for ( int iE = 0; iE < prism.myNbEdgesInWires.front(); ++iE, ++edgeIt )
4030 if ( SMESH_Algo::isDegenerated( *edgeIt )) continue;
4031 const TParam2ColumnMap* u2colMap =
4032 GetParam2ColumnMap( MeshDS()->ShapeToIndex( *edgeIt ), isReverse );
4033 if ( !u2colMap ) return false;
4034 double f = u2colMap->begin()->first, l = u2colMap->rbegin()->first;
4035 //isReverse = ( edgeIt->Orientation() == TopAbs_REVERSED );
4036 //if ( isReverse ) swap ( f, l ); -- u2colMap takes orientation into account
4037 const int nbCol = 5;
4038 for ( int i = 0; i < nbCol; ++i )
4040 double u = f + i/double(nbCol) * ( l - f );
4041 const TNodeColumn* col = & getColumn( u2colMap, u )->second;
4042 if ( columns.empty() || col != columns.back() )
4043 columns.push_back( col );
4048 // Find tolerance to check transformations
4053 for ( size_t i = 0; i < columns.size(); ++i )
4054 bndBox.Add( gpXYZ( columns[i]->front() ));
4055 tol2 = bndBox.SquareExtent() * 1e-5;
4058 // Compute transformations
4061 gp_Trsf fromCsZ, toCs0;
4062 gp_Ax3 cs0 = getLayerCoordSys(0, columns, xCol );
4063 //double dist0 = cs0.Location().Distance( gpXYZ( (*columns[0])[0]));
4064 toCs0.SetTransformation( cs0 );
4065 for ( int z = 1; z < zSize; ++z )
4067 gp_Ax3 csZ = getLayerCoordSys(z, columns, xCol );
4068 //double distZ = csZ.Location().Distance( gpXYZ( (*columns[0])[z]));
4069 fromCsZ.SetTransformation( csZ );
4071 gp_Trsf& t = trsf[ z-1 ];
4072 t = fromCsZ * toCs0;
4073 //t.SetScaleFactor( distZ/dist0 ); - it does not work properly, wrong base point
4075 // check a transformation
4076 for ( size_t i = 0; i < columns.size(); ++i )
4078 gp_Pnt p0 = gpXYZ( (*columns[i])[0] );
4079 gp_Pnt pz = gpXYZ( (*columns[i])[z] );
4080 t.Transforms( p0.ChangeCoord() );
4081 if ( p0.SquareDistance( pz ) > tol2 )
4084 return ( z == zSize - 1 ); // OK if fails only bottom->top trsf
4091 //================================================================================
4093 * \brief Check curve orientation of a bottom edge
4094 * \param meshDS - mesh DS
4095 * \param columnsMap - node columns map of side face
4096 * \param bottomEdge - the bottom edge
4097 * \param sideFaceID - side face in-block ID
4098 * \retval bool - true if orientation coincide with in-block forward orientation
4100 //================================================================================
4102 bool StdMeshers_PrismAsBlock::IsForwardEdge(SMESHDS_Mesh* meshDS,
4103 const TParam2ColumnMap& columnsMap,
4104 const TopoDS_Edge & bottomEdge,
4105 const int sideFaceID)
4107 bool isForward = false;
4108 if ( SMESH_MesherHelper::IsClosedEdge( bottomEdge ))
4110 isForward = ( bottomEdge.Orientation() == TopAbs_FORWARD );
4114 const TNodeColumn& firstCol = columnsMap.begin()->second;
4115 const SMDS_MeshNode* bottomNode = firstCol[0];
4116 TopoDS_Shape firstVertex = SMESH_MesherHelper::GetSubShapeByNode( bottomNode, meshDS );
4117 isForward = ( firstVertex.IsSame( TopExp::FirstVertex( bottomEdge, true )));
4119 // on 2 of 4 sides first vertex is end
4120 if ( sideFaceID == ID_Fx1z || sideFaceID == ID_F0yz )
4121 isForward = !isForward;
4125 //=======================================================================
4126 //function : faceGridToPythonDump
4127 //purpose : Prints a script creating a normal grid on the prism side
4128 //=======================================================================
4130 void StdMeshers_PrismAsBlock::faceGridToPythonDump(const SMESH_Block::TShapeID face,
4134 gp_XYZ pOnF[6] = { gp_XYZ(0,0,0), gp_XYZ(0,0,1),
4135 gp_XYZ(0,0,0), gp_XYZ(0,1,0),
4136 gp_XYZ(0,0,0), gp_XYZ(1,0,0) };
4138 cout << "mesh = smesh.Mesh( 'Face " << face << "')" << endl;
4139 SMESH_Block::TFace& f = myFace[ face - ID_FirstF ];
4140 gp_XYZ params = pOnF[ face - ID_FirstF ];
4141 //const int nb = 10; // nb face rows
4142 for ( int j = 0; j <= nb; ++j )
4144 params.SetCoord( f.GetVInd(), double( j )/ nb );
4145 for ( int i = 0; i <= nb; ++i )
4147 params.SetCoord( f.GetUInd(), double( i )/ nb );
4148 gp_XYZ p = f.Point( params );
4149 gp_XY uv = f.GetUV( params );
4150 cout << "mesh.AddNode( " << p.X() << ", " << p.Y() << ", " << p.Z() << " )"
4151 << " # " << 1 + i + j * ( nb + 1 )
4152 << " ( " << i << ", " << j << " ) "
4153 << " UV( " << uv.X() << ", " << uv.Y() << " )" << endl;
4154 ShellPoint( params, p2 );
4155 double dist = ( p2 - p ).Modulus();
4157 cout << "#### dist from ShellPoint " << dist
4158 << " (" << p2.X() << ", " << p2.Y() << ", " << p2.Z() << " ) " << endl;
4161 for ( int j = 0; j < nb; ++j )
4162 for ( int i = 0; i < nb; ++i )
4164 int n = 1 + i + j * ( nb + 1 );
4165 cout << "mesh.AddFace([ "
4166 << n << ", " << n+1 << ", "
4167 << n+nb+2 << ", " << n+nb+1 << "]) " << endl;
4173 //================================================================================
4175 * \brief Constructor
4176 * \param faceID - in-block ID
4177 * \param face - geom FACE
4178 * \param baseEdge - EDGE proreply oriented in the bottom EDGE !!!
4179 * \param columnsMap - map of node columns
4180 * \param first - first normalized param
4181 * \param last - last normalized param
4183 //================================================================================
4185 StdMeshers_PrismAsBlock::TSideFace::TSideFace(SMESH_Mesh& mesh,
4187 const Prism_3D::TQuadList& quadList,
4188 const TopoDS_Edge& baseEdge,
4189 TParam2ColumnMap* columnsMap,
4193 myParamToColumnMap( columnsMap ),
4196 myParams.resize( 1 );
4197 myParams[ 0 ] = make_pair( first, last );
4198 mySurface = PSurface( new BRepAdaptor_Surface( quadList.front()->face ));
4199 myBaseEdge = baseEdge;
4200 myIsForward = StdMeshers_PrismAsBlock::IsForwardEdge( myHelper.GetMeshDS(),
4201 *myParamToColumnMap,
4203 myHelper.SetSubShape( quadList.front()->face );
4205 if ( quadList.size() > 1 ) // side is vertically composite
4207 // fill myShapeID2Surf map to enable finding a right surface by any sub-shape ID
4209 SMESHDS_Mesh* meshDS = myHelper.GetMeshDS();
4211 TopTools_IndexedDataMapOfShapeListOfShape subToFaces;
4212 Prism_3D::TQuadList::const_iterator quad = quadList.begin();
4213 for ( ; quad != quadList.end(); ++quad )
4215 const TopoDS_Face& face = (*quad)->face;
4216 TopExp::MapShapesAndAncestors( face, TopAbs_VERTEX, TopAbs_FACE, subToFaces );
4217 TopExp::MapShapesAndAncestors( face, TopAbs_EDGE, TopAbs_FACE, subToFaces );
4218 myShapeID2Surf.insert( make_pair( meshDS->ShapeToIndex( face ),
4219 PSurface( new BRepAdaptor_Surface( face ))));
4221 for ( int i = 1; i <= subToFaces.Extent(); ++i )
4223 const TopoDS_Shape& sub = subToFaces.FindKey( i );
4224 TopTools_ListOfShape& faces = subToFaces( i );
4225 int subID = meshDS->ShapeToIndex( sub );
4226 int faceID = meshDS->ShapeToIndex( faces.First() );
4227 myShapeID2Surf.insert ( make_pair( subID, myShapeID2Surf[ faceID ]));
4232 //================================================================================
4234 * \brief Constructor of a complex side face
4236 //================================================================================
4238 StdMeshers_PrismAsBlock::TSideFace::
4239 TSideFace(SMESH_Mesh& mesh,
4240 const vector< TSideFace* >& components,
4241 const vector< pair< double, double> > & params)
4242 :myID( components[0] ? components[0]->myID : 0 ),
4243 myParamToColumnMap( 0 ),
4245 myIsForward( true ),
4246 myComponents( components ),
4249 if ( myID == ID_Fx1z || myID == ID_F0yz )
4251 // reverse components
4252 std::reverse( myComponents.begin(), myComponents.end() );
4253 std::reverse( myParams.begin(), myParams.end() );
4254 for ( size_t i = 0; i < myParams.size(); ++i )
4256 const double f = myParams[i].first;
4257 const double l = myParams[i].second;
4258 myParams[i] = make_pair( 1. - l, 1. - f );
4262 //================================================================================
4264 * \brief Copy constructor
4265 * \param other - other side
4267 //================================================================================
4269 StdMeshers_PrismAsBlock::TSideFace::TSideFace( const TSideFace& other ):
4270 myID ( other.myID ),
4271 myParamToColumnMap ( other.myParamToColumnMap ),
4272 mySurface ( other.mySurface ),
4273 myBaseEdge ( other.myBaseEdge ),
4274 myShapeID2Surf ( other.myShapeID2Surf ),
4275 myParams ( other.myParams ),
4276 myIsForward ( other.myIsForward ),
4277 myComponents ( other.myComponents.size() ),
4278 myHelper ( *other.myHelper.GetMesh() )
4280 for ( size_t i = 0 ; i < myComponents.size(); ++i )
4281 myComponents[ i ] = new TSideFace( *other.myComponents[ i ]);
4284 //================================================================================
4286 * \brief Deletes myComponents
4288 //================================================================================
4290 StdMeshers_PrismAsBlock::TSideFace::~TSideFace()
4292 for ( size_t i = 0 ; i < myComponents.size(); ++i )
4293 if ( myComponents[ i ] )
4294 delete myComponents[ i ];
4297 //================================================================================
4299 * \brief Return geometry of the vertical curve
4300 * \param isMax - true means curve located closer to (1,1,1) block point
4301 * \retval Adaptor3d_Curve* - curve adaptor
4303 //================================================================================
4305 Adaptor3d_Curve* StdMeshers_PrismAsBlock::TSideFace::VertiCurve(const bool isMax) const
4307 if ( !myComponents.empty() ) {
4309 return myComponents.back()->VertiCurve(isMax);
4311 return myComponents.front()->VertiCurve(isMax);
4313 double f = myParams[0].first, l = myParams[0].second;
4314 if ( !myIsForward ) std::swap( f, l );
4315 return new TVerticalEdgeAdaptor( myParamToColumnMap, isMax ? l : f );
4318 //================================================================================
4320 * \brief Return geometry of the top or bottom curve
4322 * \retval Adaptor3d_Curve* -
4324 //================================================================================
4326 Adaptor3d_Curve* StdMeshers_PrismAsBlock::TSideFace::HorizCurve(const bool isTop) const
4328 return new THorizontalEdgeAdaptor( this, isTop );
4331 //================================================================================
4333 * \brief Return pcurves
4334 * \param pcurv - array of 4 pcurves
4335 * \retval bool - is a success
4337 //================================================================================
4339 bool StdMeshers_PrismAsBlock::TSideFace::GetPCurves(Adaptor2d_Curve2d* pcurv[4]) const
4341 int iEdge[ 4 ] = { BOTTOM_EDGE, TOP_EDGE, V0_EDGE, V1_EDGE };
4343 for ( int i = 0 ; i < 4 ; ++i ) {
4344 Handle(Geom2d_Line) line;
4345 switch ( iEdge[ i ] ) {
4347 line = new Geom2d_Line( gp_Pnt2d( 0, 1 ), gp::DX2d() ); break;
4349 line = new Geom2d_Line( gp::Origin2d(), gp::DX2d() ); break;
4351 line = new Geom2d_Line( gp::Origin2d(), gp::DY2d() ); break;
4353 line = new Geom2d_Line( gp_Pnt2d( 1, 0 ), gp::DY2d() ); break;
4355 pcurv[ i ] = new Geom2dAdaptor_Curve( line, 0, 1 );
4360 //================================================================================
4362 * \brief Returns geometry of pcurve on a horizontal face
4363 * \param isTop - is top or bottom face
4364 * \param horFace - a horizontal face
4365 * \retval Adaptor2d_Curve2d* - curve adaptor
4367 //================================================================================
4370 StdMeshers_PrismAsBlock::TSideFace::HorizPCurve(const bool isTop,
4371 const TopoDS_Face& horFace) const
4373 return new TPCurveOnHorFaceAdaptor( this, isTop, horFace );
4376 //================================================================================
4378 * \brief Return a component corresponding to parameter
4379 * \param U - parameter along a horizontal size
4380 * \param localU - parameter along a horizontal size of a component
4381 * \retval TSideFace* - found component
4383 //================================================================================
4385 StdMeshers_PrismAsBlock::TSideFace*
4386 StdMeshers_PrismAsBlock::TSideFace::GetComponent(const double U,double & localU) const
4389 if ( myComponents.empty() )
4390 return const_cast<TSideFace*>( this );
4393 for ( i = 0; i < myComponents.size(); ++i )
4394 if ( U < myParams[ i ].second )
4396 if ( i >= myComponents.size() )
4397 i = myComponents.size() - 1;
4399 double f = myParams[ i ].first, l = myParams[ i ].second;
4400 localU = ( U - f ) / ( l - f );
4401 return myComponents[ i ];
4404 //================================================================================
4406 * \brief Find node columns for a parameter
4407 * \param U - parameter along a horizontal edge
4408 * \param col1 - the 1st found column
4409 * \param col2 - the 2nd found column
4410 * \retval r - normalized position of U between the found columns
4412 //================================================================================
4414 double StdMeshers_PrismAsBlock::TSideFace::GetColumns(const double U,
4415 TParam2ColumnIt & col1,
4416 TParam2ColumnIt & col2) const
4418 double u = U, r = 0;
4419 if ( !myComponents.empty() ) {
4420 TSideFace * comp = GetComponent(U,u);
4421 return comp->GetColumns( u, col1, col2 );
4426 double f = myParams[0].first, l = myParams[0].second;
4427 u = f + u * ( l - f );
4429 col1 = col2 = getColumn( myParamToColumnMap, u );
4430 if ( ++col2 == myParamToColumnMap->end() ) {
4435 double uf = col1->first;
4436 double ul = col2->first;
4437 r = ( u - uf ) / ( ul - uf );
4442 //================================================================================
4444 * \brief Return all nodes at a given height together with their normalized parameters
4445 * \param [in] Z - the height of interest
4446 * \param [out] nodes - map of parameter to node
4448 //================================================================================
4450 void StdMeshers_PrismAsBlock::
4451 TSideFace::GetNodesAtZ(const int Z,
4452 map<double, const SMDS_MeshNode* >& nodes ) const
4454 if ( !myComponents.empty() )
4457 for ( size_t i = 0; i < myComponents.size(); ++i )
4459 map<double, const SMDS_MeshNode* > nn;
4460 myComponents[i]->GetNodesAtZ( Z, nn );
4461 map<double, const SMDS_MeshNode* >::iterator u2n = nn.begin();
4462 if ( !nodes.empty() && nodes.rbegin()->second == u2n->second )
4464 const double uRange = myParams[i].second - myParams[i].first;
4465 for ( ; u2n != nn.end(); ++u2n )
4466 nodes.insert( nodes.end(), make_pair( u0 + uRange * u2n->first, u2n->second ));
4472 double f = myParams[0].first, l = myParams[0].second;
4475 const double uRange = l - f;
4476 if ( Abs( uRange ) < std::numeric_limits<double>::min() )
4478 TParam2ColumnIt u2col = getColumn( myParamToColumnMap, myParams[0].first + 1e-3 );
4479 for ( ; u2col != myParamToColumnMap->end(); ++u2col )
4480 if ( u2col->first > myParams[0].second + 1e-9 )
4483 nodes.insert( nodes.end(),
4484 make_pair( ( u2col->first - f ) / uRange, u2col->second[ Z ] ));
4488 //================================================================================
4490 * \brief Return coordinates by normalized params
4491 * \param U - horizontal param
4492 * \param V - vertical param
4493 * \retval gp_Pnt - result point
4495 //================================================================================
4497 gp_Pnt StdMeshers_PrismAsBlock::TSideFace::Value(const Standard_Real U,
4498 const Standard_Real V) const
4500 if ( !myComponents.empty() ) {
4502 TSideFace * comp = GetComponent(U,u);
4503 return comp->Value( u, V );
4506 TParam2ColumnIt u_col1, u_col2;
4507 double vR, hR = GetColumns( U, u_col1, u_col2 );
4509 const SMDS_MeshNode* nn[4];
4511 // BEGIN issue 0020680: Bad cell created by Radial prism in center of torus
4512 // Workaround for a wrongly located point returned by mySurface.Value() for
4513 // UV located near boundary of BSpline surface.
4514 // To bypass the problem, we take point from 3D curve of EDGE.
4515 // It solves pb of the bloc_fiss_new.py
4516 const double tol = 1e-3;
4517 if ( V < tol || V+tol >= 1. )
4519 nn[0] = V < tol ? u_col1->second.front() : u_col1->second.back();
4520 nn[2] = V < tol ? u_col2->second.front() : u_col2->second.back();
4528 TopoDS_Shape s = myHelper.GetSubShapeByNode( nn[0], myHelper.GetMeshDS() );
4529 if ( s.ShapeType() != TopAbs_EDGE )
4530 s = myHelper.GetSubShapeByNode( nn[2], myHelper.GetMeshDS() );
4531 if ( !s.IsNull() && s.ShapeType() == TopAbs_EDGE )
4532 edge = TopoDS::Edge( s );
4534 if ( !edge.IsNull() )
4536 double u1 = myHelper.GetNodeU( edge, nn[0], nn[2] );
4537 double u3 = myHelper.GetNodeU( edge, nn[2], nn[0] );
4538 double u = u1 * ( 1 - hR ) + u3 * hR;
4539 TopLoc_Location loc; double f,l;
4540 Handle(Geom_Curve) curve = BRep_Tool::Curve( edge,loc,f,l );
4541 return curve->Value( u ).Transformed( loc );
4544 // END issue 0020680: Bad cell created by Radial prism in center of torus
4546 vR = getRAndNodes( & u_col1->second, V, nn[0], nn[1] );
4547 vR = getRAndNodes( & u_col2->second, V, nn[2], nn[3] );
4549 if ( !myShapeID2Surf.empty() ) // side is vertically composite
4551 // find a FACE on which the 4 nodes lie
4552 TSideFace* me = (TSideFace*) this;
4553 int notFaceID1 = 0, notFaceID2 = 0;
4554 for ( int i = 0; i < 4; ++i )
4555 if ( nn[i]->GetPosition()->GetTypeOfPosition() == SMDS_TOP_FACE ) // node on FACE
4557 me->mySurface = me->myShapeID2Surf[ nn[i]->getshapeId() ];
4561 else if ( notFaceID1 == 0 ) // node on EDGE or VERTEX
4563 me->mySurface = me->myShapeID2Surf[ nn[i]->getshapeId() ];
4564 notFaceID1 = nn[i]->getshapeId();
4566 else if ( notFaceID1 != nn[i]->getshapeId() ) // node on other EDGE or VERTEX
4568 if ( mySurface != me->myShapeID2Surf[ nn[i]->getshapeId() ])
4569 notFaceID2 = nn[i]->getshapeId();
4571 if ( notFaceID2 ) // no nodes of FACE and nodes are on different FACEs
4573 SMESHDS_Mesh* meshDS = myHelper.GetMeshDS();
4574 TopoDS_Shape face = myHelper.GetCommonAncestor( meshDS->IndexToShape( notFaceID1 ),
4575 meshDS->IndexToShape( notFaceID2 ),
4576 *myHelper.GetMesh(),
4578 if ( face.IsNull() )
4579 throw SALOME_Exception("StdMeshers_PrismAsBlock::TSideFace::Value() face.IsNull()");
4580 int faceID = meshDS->ShapeToIndex( face );
4581 me->mySurface = me->myShapeID2Surf[ faceID ];
4583 throw SALOME_Exception("StdMeshers_PrismAsBlock::TSideFace::Value() !mySurface");
4586 ((TSideFace*) this)->myHelper.SetSubShape( mySurface->Face() );
4588 gp_XY uv1 = myHelper.GetNodeUV( mySurface->Face(), nn[0], nn[2]);
4589 gp_XY uv2 = myHelper.GetNodeUV( mySurface->Face(), nn[1], nn[3]);
4590 gp_XY uv12 = uv1 * ( 1 - vR ) + uv2 * vR;
4592 gp_XY uv3 = myHelper.GetNodeUV( mySurface->Face(), nn[2], nn[0]);
4593 gp_XY uv4 = myHelper.GetNodeUV( mySurface->Face(), nn[3], nn[1]);
4594 gp_XY uv34 = uv3 * ( 1 - vR ) + uv4 * vR;
4596 gp_XY uv = uv12 * ( 1 - hR ) + uv34 * hR;
4598 gp_Pnt p = mySurface->Value( uv.X(), uv.Y() );
4603 //================================================================================
4605 * \brief Return boundary edge
4606 * \param edge - edge index
4607 * \retval TopoDS_Edge - found edge
4609 //================================================================================
4611 TopoDS_Edge StdMeshers_PrismAsBlock::TSideFace::GetEdge(const int iEdge) const
4613 if ( !myComponents.empty() ) {
4615 case V0_EDGE : return myComponents.front()->GetEdge( iEdge );
4616 case V1_EDGE : return myComponents.back() ->GetEdge( iEdge );
4617 default: return TopoDS_Edge();
4621 const SMDS_MeshNode* node = 0;
4622 SMESHDS_Mesh * meshDS = myHelper.GetMesh()->GetMeshDS();
4623 TNodeColumn* column;
4628 column = & (( ++myParamToColumnMap->begin())->second );
4629 node = ( iEdge == TOP_EDGE ) ? column->back() : column->front();
4630 edge = myHelper.GetSubShapeByNode ( node, meshDS );
4631 if ( edge.ShapeType() == TopAbs_VERTEX ) {
4632 column = & ( myParamToColumnMap->begin()->second );
4633 node = ( iEdge == TOP_EDGE ) ? column->back() : column->front();
4638 bool back = ( iEdge == V1_EDGE );
4639 if ( !myIsForward ) back = !back;
4641 column = & ( myParamToColumnMap->rbegin()->second );
4643 column = & ( myParamToColumnMap->begin()->second );
4644 if ( column->size() > 0 )
4645 edge = myHelper.GetSubShapeByNode( (*column)[ 1 ], meshDS );
4646 if ( edge.IsNull() || edge.ShapeType() == TopAbs_VERTEX )
4647 node = column->front();
4652 if ( !edge.IsNull() && edge.ShapeType() == TopAbs_EDGE )
4653 return TopoDS::Edge( edge );
4655 // find edge by 2 vertices
4656 TopoDS_Shape V1 = edge;
4657 TopoDS_Shape V2 = myHelper.GetSubShapeByNode( node, meshDS );
4658 if ( !V2.IsNull() && V2.ShapeType() == TopAbs_VERTEX && !V2.IsSame( V1 ))
4660 TopoDS_Shape ancestor = myHelper.GetCommonAncestor( V1, V2, *myHelper.GetMesh(), TopAbs_EDGE);
4661 if ( !ancestor.IsNull() )
4662 return TopoDS::Edge( ancestor );
4664 return TopoDS_Edge();
4667 //================================================================================
4669 * \brief Fill block sub-shapes
4670 * \param shapeMap - map to fill in
4671 * \retval int - nb inserted sub-shapes
4673 //================================================================================
4675 int StdMeshers_PrismAsBlock::TSideFace::InsertSubShapes(TBlockShapes& shapeMap) const
4680 vector< int > edgeIdVec;
4681 SMESH_Block::GetFaceEdgesIDs( myID, edgeIdVec );
4683 for ( int i = BOTTOM_EDGE; i <=V1_EDGE ; ++i ) {
4684 TopoDS_Edge e = GetEdge( i );
4685 if ( !e.IsNull() ) {
4686 nbInserted += SMESH_Block::Insert( e, edgeIdVec[ i ], shapeMap);
4690 // Insert corner vertices
4692 TParam2ColumnIt col1, col2 ;
4693 vector< int > vertIdVec;
4696 SMESH_Block::GetEdgeVertexIDs( edgeIdVec[ V0_EDGE ], vertIdVec);
4697 GetColumns(0, col1, col2 );
4698 const SMDS_MeshNode* node0 = col1->second.front();
4699 const SMDS_MeshNode* node1 = col1->second.back();
4700 TopoDS_Shape v0 = myHelper.GetSubShapeByNode( node0, myHelper.GetMeshDS());
4701 TopoDS_Shape v1 = myHelper.GetSubShapeByNode( node1, myHelper.GetMeshDS());
4702 if ( v0.ShapeType() == TopAbs_VERTEX ) {
4703 nbInserted += SMESH_Block::Insert( v0, vertIdVec[ 0 ], shapeMap);
4705 if ( v1.ShapeType() == TopAbs_VERTEX ) {
4706 nbInserted += SMESH_Block::Insert( v1, vertIdVec[ 1 ], shapeMap);
4710 SMESH_Block::GetEdgeVertexIDs( edgeIdVec[ V1_EDGE ], vertIdVec);
4711 GetColumns(1, col1, col2 );
4712 node0 = col2->second.front();
4713 node1 = col2->second.back();
4714 v0 = myHelper.GetSubShapeByNode( node0, myHelper.GetMeshDS());
4715 v1 = myHelper.GetSubShapeByNode( node1, myHelper.GetMeshDS());
4716 if ( v0.ShapeType() == TopAbs_VERTEX ) {
4717 nbInserted += SMESH_Block::Insert( v0, vertIdVec[ 0 ], shapeMap);
4719 if ( v1.ShapeType() == TopAbs_VERTEX ) {
4720 nbInserted += SMESH_Block::Insert( v1, vertIdVec[ 1 ], shapeMap);
4723 // TopoDS_Vertex V0, V1, Vcom;
4724 // TopExp::Vertices( myBaseEdge, V0, V1, true );
4725 // if ( !myIsForward ) std::swap( V0, V1 );
4727 // // bottom vertex IDs
4728 // SMESH_Block::GetEdgeVertexIDs( edgeIdVec[ _u0 ], vertIdVec);
4729 // SMESH_Block::Insert( V0, vertIdVec[ 0 ], shapeMap);
4730 // SMESH_Block::Insert( V1, vertIdVec[ 1 ], shapeMap);
4732 // TopoDS_Edge sideEdge = GetEdge( V0_EDGE );
4733 // if ( sideEdge.IsNull() || !TopExp::CommonVertex( botEdge, sideEdge, Vcom ))
4736 // // insert one side edge
4738 // if ( Vcom.IsSame( V0 )) edgeID = edgeIdVec[ _v0 ];
4739 // else edgeID = edgeIdVec[ _v1 ];
4740 // SMESH_Block::Insert( sideEdge, edgeID, shapeMap);
4742 // // top vertex of the side edge
4743 // SMESH_Block::GetEdgeVertexIDs( edgeID, vertIdVec);
4744 // TopoDS_Vertex Vtop = TopExp::FirstVertex( sideEdge );
4745 // if ( Vcom.IsSame( Vtop ))
4746 // Vtop = TopExp::LastVertex( sideEdge );
4747 // SMESH_Block::Insert( Vtop, vertIdVec[ 1 ], shapeMap);
4749 // // other side edge
4750 // sideEdge = GetEdge( V1_EDGE );
4751 // if ( sideEdge.IsNull() )
4753 // if ( edgeID = edgeIdVec[ _v1 ]) edgeID = edgeIdVec[ _v0 ];
4754 // else edgeID = edgeIdVec[ _v1 ];
4755 // SMESH_Block::Insert( sideEdge, edgeID, shapeMap);
4758 // TopoDS_Edge topEdge = GetEdge( TOP_EDGE );
4759 // SMESH_Block::Insert( topEdge, edgeIdVec[ _u1 ], shapeMap);
4761 // // top vertex of the other side edge
4762 // if ( !TopExp::CommonVertex( topEdge, sideEdge, Vcom ))
4764 // SMESH_Block::GetEdgeVertexIDs( edgeID, vertIdVec );
4765 // SMESH_Block::Insert( Vcom, vertIdVec[ 1 ], shapeMap);
4770 //================================================================================
4772 * \brief Dump ids of nodes of sides
4774 //================================================================================
4776 void StdMeshers_PrismAsBlock::TSideFace::dumpNodes(int nbNodes) const
4779 cout << endl << "NODES OF FACE "; SMESH_Block::DumpShapeID( myID, cout ) << endl;
4780 THorizontalEdgeAdaptor* hSize0 = (THorizontalEdgeAdaptor*) HorizCurve(0);
4781 cout << "Horiz side 0: "; hSize0->dumpNodes(nbNodes); cout << endl;
4782 THorizontalEdgeAdaptor* hSize1 = (THorizontalEdgeAdaptor*) HorizCurve(1);
4783 cout << "Horiz side 1: "; hSize1->dumpNodes(nbNodes); cout << endl;
4784 TVerticalEdgeAdaptor* vSide0 = (TVerticalEdgeAdaptor*) VertiCurve(0);
4785 cout << "Verti side 0: "; vSide0->dumpNodes(nbNodes); cout << endl;
4786 TVerticalEdgeAdaptor* vSide1 = (TVerticalEdgeAdaptor*) VertiCurve(1);
4787 cout << "Verti side 1: "; vSide1->dumpNodes(nbNodes); cout << endl;
4788 delete hSize0; delete hSize1; delete vSide0; delete vSide1;
4792 //================================================================================
4794 * \brief Creates TVerticalEdgeAdaptor
4795 * \param columnsMap - node column map
4796 * \param parameter - normalized parameter
4798 //================================================================================
4800 StdMeshers_PrismAsBlock::TVerticalEdgeAdaptor::
4801 TVerticalEdgeAdaptor( const TParam2ColumnMap* columnsMap, const double parameter)
4803 myNodeColumn = & getColumn( columnsMap, parameter )->second;
4806 //================================================================================
4808 * \brief Return coordinates for the given normalized parameter
4809 * \param U - normalized parameter
4810 * \retval gp_Pnt - coordinates
4812 //================================================================================
4814 gp_Pnt StdMeshers_PrismAsBlock::TVerticalEdgeAdaptor::Value(const Standard_Real U) const
4816 const SMDS_MeshNode* n1;
4817 const SMDS_MeshNode* n2;
4818 double r = getRAndNodes( myNodeColumn, U, n1, n2 );
4819 return gpXYZ(n1) * ( 1 - r ) + gpXYZ(n2) * r;
4822 //================================================================================
4824 * \brief Dump ids of nodes
4826 //================================================================================
4828 void StdMeshers_PrismAsBlock::TVerticalEdgeAdaptor::dumpNodes(int nbNodes) const
4831 for ( int i = 0; i < nbNodes && i < (int)myNodeColumn->size(); ++i )
4832 cout << (*myNodeColumn)[i]->GetID() << " ";
4833 if ( nbNodes < (int) myNodeColumn->size() )
4834 cout << myNodeColumn->back()->GetID();
4838 //================================================================================
4840 * \brief Return coordinates for the given normalized parameter
4841 * \param U - normalized parameter
4842 * \retval gp_Pnt - coordinates
4844 //================================================================================
4846 gp_Pnt StdMeshers_PrismAsBlock::THorizontalEdgeAdaptor::Value(const Standard_Real U) const
4848 return mySide->TSideFace::Value( U, myV );
4851 //================================================================================
4853 * \brief Dump ids of <nbNodes> first nodes and the last one
4855 //================================================================================
4857 void StdMeshers_PrismAsBlock::THorizontalEdgeAdaptor::dumpNodes(int nbNodes) const
4860 // Not bedugged code. Last node is sometimes incorrect
4861 const TSideFace* side = mySide;
4863 if ( mySide->IsComplex() )
4864 side = mySide->GetComponent(0,u);
4866 TParam2ColumnIt col, col2;
4867 TParam2ColumnMap* u2cols = side->GetColumns();
4868 side->GetColumns( u , col, col2 );
4870 int j, i = myV ? mySide->ColumnHeight()-1 : 0;
4872 const SMDS_MeshNode* n = 0;
4873 const SMDS_MeshNode* lastN
4874 = side->IsForward() ? u2cols->rbegin()->second[ i ] : u2cols->begin()->second[ i ];
4875 for ( j = 0; j < nbNodes && n != lastN; ++j )
4877 n = col->second[ i ];
4878 cout << n->GetID() << " ";
4879 if ( side->IsForward() )
4887 if ( mySide->IsComplex() )
4888 side = mySide->GetComponent(1,u);
4890 side->GetColumns( u , col, col2 );
4891 if ( n != col->second[ i ] )
4892 cout << col->second[ i ]->GetID();
4896 //================================================================================
4898 * \brief Constructor of TPCurveOnHorFaceAdaptor fills its map of
4899 * normalized parameter to node UV on a horizontal face
4900 * \param [in] sideFace - lateral prism side
4901 * \param [in] isTop - is \a horFace top or bottom of the prism
4902 * \param [in] horFace - top or bottom face of the prism
4904 //================================================================================
4906 StdMeshers_PrismAsBlock::
4907 TPCurveOnHorFaceAdaptor::TPCurveOnHorFaceAdaptor( const TSideFace* sideFace,
4909 const TopoDS_Face& horFace)
4911 if ( sideFace && !horFace.IsNull() )
4913 //cout << "\n\t FACE " << sideFace->FaceID() << endl;
4914 const int Z = isTop ? sideFace->ColumnHeight() - 1 : 0;
4915 map<double, const SMDS_MeshNode* > u2nodes;
4916 sideFace->GetNodesAtZ( Z, u2nodes );
4917 if ( u2nodes.empty() )
4920 SMESH_MesherHelper helper( *sideFace->GetMesh() );
4921 helper.SetSubShape( horFace );
4926 Handle(Geom2d_Curve) C2d;
4928 const double tol = 10 * helper.MaxTolerance( horFace );
4929 const SMDS_MeshNode* prevNode = u2nodes.rbegin()->second;
4931 map<double, const SMDS_MeshNode* >::iterator u2n = u2nodes.begin();
4932 for ( ; u2n != u2nodes.end(); ++u2n )
4934 const SMDS_MeshNode* n = u2n->second;
4936 if ( n->GetPosition()->GetTypeOfPosition() == SMDS_TOP_EDGE )
4938 if ( n->getshapeId() != edgeID )
4941 edgeID = n->getshapeId();
4942 TopoDS_Shape S = helper.GetSubShapeByNode( n, helper.GetMeshDS() );
4943 if ( !S.IsNull() && S.ShapeType() == TopAbs_EDGE )
4945 C2d = BRep_Tool::CurveOnSurface( TopoDS::Edge( S ), horFace, f,l );
4948 if ( !C2d.IsNull() )
4950 double u = SMDS_EdgePositionPtr( n->GetPosition() )->GetUParameter();
4951 if ( f <= u && u <= l )
4953 uv = C2d->Value( u ).XY();
4954 okUV = helper.CheckNodeUV( horFace, n, uv, tol );
4959 uv = helper.GetNodeUV( horFace, n, prevNode, &okUV );
4961 myUVmap.insert( myUVmap.end(), make_pair( u2n->first, uv ));
4962 // cout << n->getshapeId() << " N " << n->GetID()
4963 // << " \t" << uv.X() << ", " << uv.Y() << " \t" << u2n->first << endl;
4970 //================================================================================
4972 * \brief Return UV on pcurve for the given normalized parameter
4973 * \param U - normalized parameter
4974 * \retval gp_Pnt - coordinates
4976 //================================================================================
4978 gp_Pnt2d StdMeshers_PrismAsBlock::TPCurveOnHorFaceAdaptor::Value(const Standard_Real U) const
4980 map< double, gp_XY >::const_iterator i1 = myUVmap.upper_bound( U );
4982 if ( i1 == myUVmap.end() )
4983 return myUVmap.empty() ? gp_XY(0,0) : myUVmap.rbegin()->second;
4985 if ( i1 == myUVmap.begin() )
4986 return (*i1).second;
4988 map< double, gp_XY >::const_iterator i2 = i1--;
4990 double r = ( U - i1->first ) / ( i2->first - i1->first );
4991 return i1->second * ( 1 - r ) + i2->second * r;
4994 //================================================================================
4996 * \brief Projects internal nodes using transformation found by boundary nodes
4998 //================================================================================
5000 bool StdMeshers_Sweeper::projectIntPoints(const vector< gp_XYZ >& fromBndPoints,
5001 const vector< gp_XYZ >& toBndPoints,
5002 const vector< gp_XYZ >& fromIntPoints,
5003 vector< gp_XYZ >& toIntPoints,
5005 NSProjUtils::TrsfFinder3D& trsf,
5006 vector< gp_XYZ > * bndError)
5008 // find transformation
5009 if ( trsf.IsIdentity() && !trsf.Solve( fromBndPoints, toBndPoints ))
5012 // compute internal points using the found trsf
5013 for ( size_t iP = 0; iP < fromIntPoints.size(); ++iP )
5015 toIntPoints[ iP ] = trsf.Transform( fromIntPoints[ iP ]);
5018 // compute boundary error
5021 bndError->resize( fromBndPoints.size() );
5023 for ( size_t iP = 0; iP < fromBndPoints.size(); ++iP )
5025 fromTrsf = trsf.Transform( fromBndPoints[ iP ] );
5026 (*bndError)[ iP ] = toBndPoints[ iP ] - fromTrsf;
5030 // apply boundary error
5031 if ( bndError && toIntPoints.size() == myTopBotTriangles.size() )
5033 for ( size_t iP = 0; iP < toIntPoints.size(); ++iP )
5035 const TopBotTriangles& tbTrias = myTopBotTriangles[ iP ];
5036 for ( int i = 0; i < 3; ++i ) // boundary errors at 3 triangle nodes
5038 toIntPoints[ iP ] +=
5039 ( (*bndError)[ tbTrias.myBotTriaNodes[i] ] * tbTrias.myBotBC[i] * ( 1 - r ) +
5040 (*bndError)[ tbTrias.myTopTriaNodes[i] ] * tbTrias.myTopBC[i] * ( r ));
5048 //================================================================================
5050 * \brief Create internal nodes of the prism by computing an affine transformation
5051 * from layer to layer
5053 //================================================================================
5055 bool StdMeshers_Sweeper::ComputeNodesByTrsf( const double tol,
5056 const bool allowHighBndError)
5058 const size_t zSize = myBndColumns[0]->size();
5059 const size_t zSrc = 0, zTgt = zSize-1;
5060 if ( zSize < 3 ) return true;
5062 vector< vector< gp_XYZ > > intPntsOfLayer( zSize ); // node coordinates to compute
5063 // set coordinates of src and tgt nodes
5064 for ( size_t z = 0; z < intPntsOfLayer.size(); ++z )
5065 intPntsOfLayer[ z ].resize( myIntColumns.size() );
5066 for ( size_t iP = 0; iP < myIntColumns.size(); ++iP )
5068 intPntsOfLayer[ zSrc ][ iP ] = intPoint( iP, zSrc );
5069 intPntsOfLayer[ zTgt ][ iP ] = intPoint( iP, zTgt );
5072 // for each internal column find boundary nodes whose error to use for correction
5073 prepareTopBotDelaunay();
5074 bool isErrorCorrectable = findDelaunayTriangles();
5076 // compute coordinates of internal nodes by projecting (transforming) src and tgt
5077 // nodes towards the central layer
5079 vector< NSProjUtils::TrsfFinder3D > trsfOfLayer( zSize );
5080 vector< vector< gp_XYZ > > bndError( zSize );
5082 // boundary points used to compute an affine transformation from a layer to a next one
5083 vector< gp_XYZ > fromSrcBndPnts( myBndColumns.size() ), fromTgtBndPnts( myBndColumns.size() );
5084 vector< gp_XYZ > toSrcBndPnts ( myBndColumns.size() ), toTgtBndPnts ( myBndColumns.size() );
5085 for ( size_t iP = 0; iP < myBndColumns.size(); ++iP )
5087 fromSrcBndPnts[ iP ] = bndPoint( iP, zSrc );
5088 fromTgtBndPnts[ iP ] = bndPoint( iP, zTgt );
5091 size_t zS = zSrc + 1;
5092 size_t zT = zTgt - 1;
5093 for ( ; zS < zT; ++zS, --zT ) // vertical loop on layers
5095 for ( size_t iP = 0; iP < myBndColumns.size(); ++iP )
5097 toSrcBndPnts[ iP ] = bndPoint( iP, zS );
5098 toTgtBndPnts[ iP ] = bndPoint( iP, zT );
5100 if (! projectIntPoints( fromSrcBndPnts, toSrcBndPnts,
5101 intPntsOfLayer[ zS-1 ], intPntsOfLayer[ zS ],
5103 trsfOfLayer [ zS-1 ], & bndError[ zS-1 ]))
5105 if (! projectIntPoints( fromTgtBndPnts, toTgtBndPnts,
5106 intPntsOfLayer[ zT+1 ], intPntsOfLayer[ zT ],
5108 trsfOfLayer [ zT+1 ], & bndError[ zT+1 ]))
5111 // if ( zT == zTgt - 1 )
5113 // for ( size_t iP = 0; iP < myBndColumns.size(); ++iP )
5115 // gp_XYZ fromTrsf = trsfOfLayer [ zT+1].Transform( fromTgtBndPnts[ iP ] );
5116 // cout << "mesh.AddNode( "
5117 // << fromTrsf.X() << ", "
5118 // << fromTrsf.Y() << ", "
5119 // << fromTrsf.Z() << ") " << endl;
5121 // for ( size_t iP = 0; iP < myIntColumns.size(); ++iP )
5122 // cout << "mesh.AddNode( "
5123 // << intPntsOfLayer[ zT ][ iP ].X() << ", "
5124 // << intPntsOfLayer[ zT ][ iP ].Y() << ", "
5125 // << intPntsOfLayer[ zT ][ iP ].Z() << ") " << endl;
5128 fromTgtBndPnts.swap( toTgtBndPnts );
5129 fromSrcBndPnts.swap( toSrcBndPnts );
5132 // Evaluate an error of boundary points
5134 if ( !isErrorCorrectable && !allowHighBndError )
5136 for ( size_t iP = 0; iP < myBndColumns.size(); ++iP )
5138 double sumError = 0;
5139 for ( size_t z = 1; z < zS; ++z ) // loop on layers
5140 sumError += ( bndError[ z-1 ][ iP ].Modulus() +
5141 bndError[ zSize-z ][ iP ].Modulus() );
5143 if ( sumError > tol )
5148 // Compute two projections of internal points to the central layer
5149 // in order to evaluate an error of internal points
5151 bool centerIntErrorIsSmall;
5152 vector< gp_XYZ > centerSrcIntPnts( myIntColumns.size() );
5153 vector< gp_XYZ > centerTgtIntPnts( myIntColumns.size() );
5155 for ( size_t iP = 0; iP < myBndColumns.size(); ++iP )
5157 toSrcBndPnts[ iP ] = bndPoint( iP, zS );
5158 toTgtBndPnts[ iP ] = bndPoint( iP, zT );
5160 if (! projectIntPoints( fromSrcBndPnts, toSrcBndPnts,
5161 intPntsOfLayer[ zS-1 ], centerSrcIntPnts,
5163 trsfOfLayer [ zS-1 ], & bndError[ zS-1 ]))
5165 if (! projectIntPoints( fromTgtBndPnts, toTgtBndPnts,
5166 intPntsOfLayer[ zT+1 ], centerTgtIntPnts,
5168 trsfOfLayer [ zT+1 ], & bndError[ zT+1 ]))
5171 // evaluate an error of internal points on the central layer
5172 centerIntErrorIsSmall = true;
5173 if ( zS == zT ) // odd zSize
5175 for ( size_t iP = 0; ( iP < myIntColumns.size() && centerIntErrorIsSmall ); ++iP )
5176 centerIntErrorIsSmall =
5177 (centerSrcIntPnts[ iP ] - centerTgtIntPnts[ iP ]).SquareModulus() < tol*tol;
5181 for ( size_t iP = 0; ( iP < myIntColumns.size() && centerIntErrorIsSmall ); ++iP )
5182 centerIntErrorIsSmall =
5183 (intPntsOfLayer[ zS-1 ][ iP ] - centerTgtIntPnts[ iP ]).SquareModulus() < tol*tol;
5186 // compute final points on the central layer
5187 double r = zS / ( zSize - 1.);
5190 for ( size_t iP = 0; iP < myIntColumns.size(); ++iP )
5192 intPntsOfLayer[ zS ][ iP ] =
5193 ( 1 - r ) * centerSrcIntPnts[ iP ] + r * centerTgtIntPnts[ iP ];
5198 for ( size_t iP = 0; iP < myIntColumns.size(); ++iP )
5200 intPntsOfLayer[ zS ][ iP ] =
5201 r * intPntsOfLayer[ zS ][ iP ] + ( 1 - r ) * centerSrcIntPnts[ iP ];
5202 intPntsOfLayer[ zT ][ iP ] =
5203 r * intPntsOfLayer[ zT ][ iP ] + ( 1 - r ) * centerTgtIntPnts[ iP ];
5207 if ( !centerIntErrorIsSmall )
5209 // Compensate the central error; continue adding projection
5210 // by going from central layer to the source and target ones
5212 vector< gp_XYZ >& fromSrcIntPnts = centerSrcIntPnts;
5213 vector< gp_XYZ >& fromTgtIntPnts = centerTgtIntPnts;
5214 vector< gp_XYZ > toSrcIntPnts( myIntColumns.size() );
5215 vector< gp_XYZ > toTgtIntPnts( myIntColumns.size() );
5216 vector< gp_XYZ > srcBndError( myBndColumns.size() );
5217 vector< gp_XYZ > tgtBndError( myBndColumns.size() );
5219 fromTgtBndPnts.swap( toTgtBndPnts );
5220 fromSrcBndPnts.swap( toSrcBndPnts );
5222 for ( ++zS, --zT; zS < zTgt; ++zS, --zT ) // vertical loop on layers
5224 // invert transformation
5225 //if ( !trsfOfLayer[ zS+1 ].Invert() )
5226 trsfOfLayer[ zS+1 ] = NSProjUtils::TrsfFinder3D(); // to recompute
5227 //if ( !trsfOfLayer[ zT-1 ].Invert() )
5228 trsfOfLayer[ zT-1 ] = NSProjUtils::TrsfFinder3D();
5230 // project internal nodes and compute bnd error
5231 for ( size_t iP = 0; iP < myBndColumns.size(); ++iP )
5233 toSrcBndPnts[ iP ] = bndPoint( iP, zS );
5234 toTgtBndPnts[ iP ] = bndPoint( iP, zT );
5236 projectIntPoints( fromSrcBndPnts, toSrcBndPnts,
5237 fromSrcIntPnts, toSrcIntPnts,
5239 trsfOfLayer[ zS+1 ], & srcBndError );
5240 projectIntPoints( fromTgtBndPnts, toTgtBndPnts,
5241 fromTgtIntPnts, toTgtIntPnts,
5243 trsfOfLayer[ zT-1 ], & tgtBndError );
5245 // if ( zS == zTgt - 1 )
5247 // cout << "mesh2 = smesh.Mesh()" << endl;
5248 // for ( size_t iP = 0; iP < myBndColumns.size(); ++iP )
5250 // gp_XYZ fromTrsf = trsfOfLayer [ zS+1].Transform( fromSrcBndPnts[ iP ] );
5251 // cout << "mesh2.AddNode( "
5252 // << fromTrsf.X() << ", "
5253 // << fromTrsf.Y() << ", "
5254 // << fromTrsf.Z() << ") " << endl;
5256 // for ( size_t iP = 0; iP < myIntColumns.size(); ++iP )
5257 // cout << "mesh2.AddNode( "
5258 // << toSrcIntPnts[ iP ].X() << ", "
5259 // << toSrcIntPnts[ iP ].Y() << ", "
5260 // << toSrcIntPnts[ iP ].Z() << ") " << endl;
5263 // sum up 2 projections
5264 r = zS / ( zSize - 1.);
5265 vector< gp_XYZ >& zSIntPnts = intPntsOfLayer[ zS ];
5266 vector< gp_XYZ >& zTIntPnts = intPntsOfLayer[ zT ];
5267 for ( size_t iP = 0; iP < myIntColumns.size(); ++iP )
5269 zSIntPnts[ iP ] = r * zSIntPnts[ iP ] + ( 1 - r ) * toSrcIntPnts[ iP ];
5270 zTIntPnts[ iP ] = r * zTIntPnts[ iP ] + ( 1 - r ) * toTgtIntPnts[ iP ];
5273 fromSrcBndPnts.swap( toSrcBndPnts );
5274 fromSrcIntPnts.swap( toSrcIntPnts );
5275 fromTgtBndPnts.swap( toTgtBndPnts );
5276 fromTgtIntPnts.swap( toTgtIntPnts );
5278 } // if ( !centerIntErrorIsSmall )
5281 //cout << "centerIntErrorIsSmall = " << centerIntErrorIsSmall<< endl;
5284 for ( size_t iP = 0; iP < myIntColumns.size(); ++iP )
5286 vector< const SMDS_MeshNode* > & nodeCol = *myIntColumns[ iP ];
5287 for ( size_t z = zSrc + 1; z < zTgt; ++z ) // vertical loop on layers
5289 const gp_XYZ & xyz = intPntsOfLayer[ z ][ iP ];
5290 if ( !( nodeCol[ z ] = myHelper->AddNode( xyz.X(), xyz.Y(), xyz.Z() )))
5298 //================================================================================
5300 * \brief Check if all nodes of each layers have same logical Z
5302 //================================================================================
5304 bool StdMeshers_Sweeper::CheckSameZ()
5306 myZColumns.resize( myBndColumns.size() );
5307 fillZColumn( myZColumns[0], *myBndColumns[0] );
5310 const double tol = 0.1 * 1./ myBndColumns[0]->size();
5312 // check columns based on VERTEXes
5314 vector< int > vertexIndex;
5315 vertexIndex.push_back( 0 );
5316 for ( size_t iC = 1; iC < myBndColumns.size() && sameZ; ++iC )
5318 if ( myBndColumns[iC]->front()->GetPosition()->GetDim() > 0 )
5319 continue; // not on VERTEX
5321 vertexIndex.push_back( iC );
5322 fillZColumn( myZColumns[iC], *myBndColumns[iC] );
5324 for ( size_t iZ = 0; iZ < myZColumns[0].size() && sameZ; ++iZ )
5325 sameZ = ( Abs( myZColumns[0][iZ] - myZColumns[iC][iZ]) < tol );
5328 // check columns based on EDGEs, one per EDGE
5330 for ( size_t i = 1; i < vertexIndex.size() && sameZ; ++i )
5332 if ( vertexIndex[i] - vertexIndex[i-1] < 2 )
5335 int iC = ( vertexIndex[i] + vertexIndex[i-1] ) / 2;
5336 fillZColumn( myZColumns[iC], *myBndColumns[iC] );
5338 for ( size_t iZ = 0; iZ < myZColumns[0].size() && sameZ; ++iZ )
5339 sameZ = ( Abs( myZColumns[0][iZ] - myZColumns[iC][iZ]) < tol );
5344 myZColumns.resize(1);
5348 for ( size_t iC = 1; iC < myBndColumns.size(); ++iC )
5349 fillZColumn( myZColumns[iC], *myBndColumns[iC] );
5355 //================================================================================
5357 * \brief Create internal nodes of the prism all located on straight lines with
5358 * the same distribution along the lines.
5360 //================================================================================
5362 bool StdMeshers_Sweeper::ComputeNodesOnStraightSameZ()
5364 TZColumn& z = myZColumns[0];
5366 for ( size_t i = 0; i < myIntColumns.size(); ++i )
5368 TNodeColumn& nodes = *myIntColumns[i];
5369 SMESH_NodeXYZ n0( nodes[0] ), n1( nodes.back() );
5371 for ( size_t iZ = 0; iZ < z.size(); ++iZ )
5373 gp_XYZ p = n0 * ( 1 - z[iZ] ) + n1 * z[iZ];
5374 nodes[ iZ+1 ] = myHelper->AddNode( p.X(), p.Y(), p.Z() );
5381 //================================================================================
5383 * \brief Create internal nodes of the prism all located on straight lines with
5384 * different distributions along the lines.
5386 //================================================================================
5388 bool StdMeshers_Sweeper::ComputeNodesOnStraight()
5390 prepareTopBotDelaunay();
5392 const SMDS_MeshNode *botNode, *topNode;
5393 const BRepMesh_Triangle *topTria;
5394 double botBC[3], topBC[3]; // barycentric coordinates
5395 int botTriaNodes[3], topTriaNodes[3];
5396 bool checkUV = true;
5398 int nbInternalNodes = myIntColumns.size();
5399 myBotDelaunay->InitTraversal( nbInternalNodes );
5401 while (( botNode = myBotDelaunay->NextNode( botBC, botTriaNodes )))
5403 TNodeColumn* column = myIntColumns[ myNodeID2ColID( botNode->GetID() )];
5405 // find a Delaunay triangle containing the topNode
5406 topNode = column->back();
5407 gp_XY topUV = myHelper->GetNodeUV( myTopFace, topNode, NULL, &checkUV );
5408 // get a starting triangle basing on that top and bot boundary nodes have same index
5409 topTria = myTopDelaunay->GetTriangleNear( botTriaNodes[0] );
5410 topTria = myTopDelaunay->FindTriangle( topUV, topTria, topBC, topTriaNodes );
5414 // create nodes along a line
5415 SMESH_NodeXYZ botP( botNode ), topP( topNode );
5416 for ( size_t iZ = 0; iZ < myZColumns[0].size(); ++iZ )
5418 // use barycentric coordinates as weight of Z of boundary columns
5419 double botZ = 0, topZ = 0;
5420 for ( int i = 0; i < 3; ++i )
5422 botZ += botBC[i] * myZColumns[ botTriaNodes[i] ][ iZ ];
5423 topZ += topBC[i] * myZColumns[ topTriaNodes[i] ][ iZ ];
5425 double rZ = double( iZ + 1 ) / ( myZColumns[0].size() + 1 );
5426 double z = botZ * ( 1 - rZ ) + topZ * rZ;
5427 gp_XYZ p = botP * ( 1 - z ) + topP * z;
5428 (*column)[ iZ+1 ] = myHelper->AddNode( p.X(), p.Y(), p.Z() );
5432 return myBotDelaunay->NbVisitedNodes() == nbInternalNodes;
5435 //================================================================================
5437 * \brief Compute Z of nodes of a straight column
5439 //================================================================================
5441 void StdMeshers_Sweeper::fillZColumn( TZColumn& zColumn,
5442 TNodeColumn& nodes )
5444 if ( zColumn.size() == nodes.size() - 2 )
5447 gp_Pnt p0 = SMESH_NodeXYZ( nodes[0] );
5448 gp_Vec line( p0, SMESH_NodeXYZ( nodes.back() ));
5449 double len2 = line.SquareMagnitude();
5451 zColumn.resize( nodes.size() - 2 );
5452 for ( size_t i = 0; i < zColumn.size(); ++i )
5454 gp_Vec vec( p0, SMESH_NodeXYZ( nodes[ i+1] ));
5455 zColumn[i] = ( line * vec ) / len2; // param [0,1] on the line
5459 //================================================================================
5461 * \brief Initialize *Delaunay members
5463 //================================================================================
5465 void StdMeshers_Sweeper::prepareTopBotDelaunay()
5467 SMESH_MesherHelper* helper[2] = { myHelper, myHelper };
5468 SMESH_MesherHelper botHelper( *myHelper->GetMesh() );
5469 SMESH_MesherHelper topHelper( *myHelper->GetMesh() );
5470 const SMDS_MeshNode* intBotNode = 0;
5471 const SMDS_MeshNode* intTopNode = 0;
5472 if ( myHelper->HasSeam() || myHelper->HasDegeneratedEdges() ) // use individual helpers
5474 botHelper.SetSubShape( myBotFace );
5475 topHelper.SetSubShape( myTopFace );
5476 helper[0] = & botHelper;
5477 helper[1] = & topHelper;
5478 if ( !myIntColumns.empty() )
5480 TNodeColumn& nodes = *myIntColumns[ myIntColumns.size()/2 ];
5481 intBotNode = nodes[0];
5482 intTopNode = nodes.back();
5486 UVPtStructVec botUV( myBndColumns.size() );
5487 UVPtStructVec topUV( myBndColumns.size() );
5488 for ( size_t i = 0; i < myBndColumns.size(); ++i )
5490 TNodeColumn& nodes = *myBndColumns[i];
5491 botUV[i].node = nodes[0];
5492 botUV[i].SetUV( helper[0]->GetNodeUV( myBotFace, nodes[0], intBotNode ));
5493 topUV[i].node = nodes.back();
5494 topUV[i].SetUV( helper[1]->GetNodeUV( myTopFace, nodes.back(), intTopNode ));
5495 botUV[i].node->setIsMarked( true );
5498 SMESH_Mesh* mesh = myHelper->GetMesh();
5499 TSideVector botWires( 1, StdMeshers_FaceSide::New( botUV, myBotFace, dummyE, mesh ));
5500 TSideVector topWires( 1, StdMeshers_FaceSide::New( topUV, myTopFace, dummyE, mesh ));
5502 // Delaunay mesh on the FACEs.
5503 bool checkUV = false;
5504 myBotDelaunay.reset( new NSProjUtils::Delaunay( botWires, checkUV ));
5505 myTopDelaunay.reset( new NSProjUtils::Delaunay( topWires, checkUV ));
5507 if ( myHelper->GetIsQuadratic() )
5509 // mark all medium nodes of faces on botFace to avoid their treating
5510 SMESHDS_SubMesh* smDS = myHelper->GetMeshDS()->MeshElements( myBotFace );
5511 SMDS_ElemIteratorPtr eIt = smDS->GetElements();
5512 while ( eIt->more() )
5514 const SMDS_MeshElement* e = eIt->next();
5515 for ( int i = e->NbCornerNodes(), nb = e->NbNodes(); i < nb; ++i )
5516 e->GetNode( i )->setIsMarked( true );
5520 // map to get a node column by a bottom node
5521 myNodeID2ColID.Clear(/*doReleaseMemory=*/false);
5522 myNodeID2ColID.ReSize( myIntColumns.size() );
5524 // un-mark nodes to treat (internal bottom nodes) to be returned by myBotDelaunay
5525 for ( size_t i = 0; i < myIntColumns.size(); ++i )
5527 const SMDS_MeshNode* botNode = myIntColumns[i]->front();
5528 botNode->setIsMarked( false );
5529 myNodeID2ColID.Bind( botNode->GetID(), i );
5533 //================================================================================
5535 * \brief For each internal node column, find Delaunay triangles including it
5536 * and Barycentric Coordinates within the triangles. Fill in myTopBotTriangles
5538 //================================================================================
5540 bool StdMeshers_Sweeper::findDelaunayTriangles()
5542 const SMDS_MeshNode *botNode, *topNode;
5543 const BRepMesh_Triangle *topTria;
5544 TopBotTriangles tbTrias;
5545 bool checkUV = true;
5547 int nbInternalNodes = myIntColumns.size();
5548 myTopBotTriangles.resize( nbInternalNodes );
5550 myBotDelaunay->InitTraversal( nbInternalNodes );
5552 while (( botNode = myBotDelaunay->NextNode( tbTrias.myBotBC, tbTrias.myBotTriaNodes )))
5554 int colID = myNodeID2ColID( botNode->GetID() );
5555 TNodeColumn* column = myIntColumns[ colID ];
5557 // find a Delaunay triangle containing the topNode
5558 topNode = column->back();
5559 gp_XY topUV = myHelper->GetNodeUV( myTopFace, topNode, NULL, &checkUV );
5560 // get a starting triangle basing on that top and bot boundary nodes have same index
5561 topTria = myTopDelaunay->GetTriangleNear( tbTrias.myBotTriaNodes[0] );
5562 topTria = myTopDelaunay->FindTriangle( topUV, topTria,
5563 tbTrias.myTopBC, tbTrias.myTopTriaNodes );
5565 tbTrias.SetTopByBottom();
5567 myTopBotTriangles[ colID ] = tbTrias;
5570 if ( myBotDelaunay->NbVisitedNodes() < nbInternalNodes )
5572 myTopBotTriangles.clear();
5576 myBotDelaunay.reset();
5577 myTopDelaunay.reset();
5578 myNodeID2ColID.Clear();
5583 //================================================================================
5585 * \brief Initialize fields
5587 //================================================================================
5589 StdMeshers_Sweeper::TopBotTriangles::TopBotTriangles()
5591 myBotBC[0] = myBotBC[1] = myBotBC[2] = myTopBC[0] = myTopBC[1] = myTopBC[2] = 0.;
5592 myBotTriaNodes[0] = myBotTriaNodes[1] = myBotTriaNodes[2] = 0;
5593 myTopTriaNodes[0] = myTopTriaNodes[1] = myTopTriaNodes[2] = 0;
5596 //================================================================================
5598 * \brief Set top data equal to bottom data
5600 //================================================================================
5602 void StdMeshers_Sweeper::TopBotTriangles::SetTopByBottom()
5604 for ( int i = 0; i < 3; ++i )
5606 myTopBC[i] = myBotBC[i];
5607 myTopTriaNodes[i] = myBotTriaNodes[0];