1 // Copyright (C) 2007-2016 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License, or (at your option) any later version.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 // File : StdMeshers_Prism_3D.cxx
25 // Created : Fri Oct 20 11:37:07 2006
26 // Author : Edward AGAPOV (eap)
28 #include "StdMeshers_Prism_3D.hxx"
30 #include "SMDS_EdgePosition.hxx"
31 #include "SMDS_VolumeOfNodes.hxx"
32 #include "SMDS_VolumeTool.hxx"
33 #include "SMESH_Comment.hxx"
34 #include "SMESH_Gen.hxx"
35 #include "SMESH_HypoFilter.hxx"
36 #include "SMESH_MesherHelper.hxx"
37 #include "StdMeshers_FaceSide.hxx"
38 #include "StdMeshers_ProjectionSource1D.hxx"
39 #include "StdMeshers_ProjectionSource2D.hxx"
40 #include "StdMeshers_ProjectionUtils.hxx"
41 #include "StdMeshers_Projection_1D.hxx"
42 #include "StdMeshers_Projection_1D2D.hxx"
43 #include "StdMeshers_Quadrangle_2D.hxx"
45 #include "utilities.h"
47 #include <BRepAdaptor_CompCurve.hxx>
48 #include <BRep_Tool.hxx>
49 #include <Bnd_B3d.hxx>
50 #include <Geom2dAdaptor_Curve.hxx>
51 #include <Geom2d_Line.hxx>
52 #include <GeomLib_IsPlanarSurface.hxx>
53 #include <Geom_Curve.hxx>
54 #include <TColStd_DataMapOfIntegerInteger.hxx>
56 #include <TopExp_Explorer.hxx>
57 #include <TopTools_ListIteratorOfListOfShape.hxx>
58 #include <TopTools_ListOfShape.hxx>
59 #include <TopTools_MapOfShape.hxx>
60 #include <TopTools_SequenceOfShape.hxx>
70 #define RETURN_BAD_RESULT(msg) { MESSAGE(")-: Error: " << msg); return false; }
71 #define gpXYZ(n) SMESH_TNodeXYZ(n)
74 #define DBGOUT(msg) //cout << msg << endl;
75 #define SHOWYXZ(msg, xyz) \
76 //{ gp_Pnt p (xyz); cout << msg << " ("<< p.X() << "; " <<p.Y() << "; " <<p.Z() << ") " <<endl; }
79 #define SHOWYXZ(msg, xyz)
82 namespace NSProjUtils = StdMeshers_ProjectionUtils;
84 typedef SMESH_Comment TCom;
86 enum { ID_BOT_FACE = SMESH_Block::ID_Fxy0,
87 ID_TOP_FACE = SMESH_Block::ID_Fxy1,
88 BOTTOM_EDGE = 0, TOP_EDGE, V0_EDGE, V1_EDGE, // edge IDs in face
89 NB_WALL_FACES = 4 }; //
93 //=======================================================================
95 * \brief Quadrangle algorithm
97 struct TQuadrangleAlgo : public StdMeshers_Quadrangle_2D
99 TQuadrangleAlgo(int studyId, SMESH_Gen* gen)
100 : StdMeshers_Quadrangle_2D( gen->GetANewId(), studyId, gen)
103 static StdMeshers_Quadrangle_2D* instance( SMESH_Algo* fatherAlgo,
104 SMESH_MesherHelper* helper=0)
106 static TQuadrangleAlgo* algo = new TQuadrangleAlgo( fatherAlgo->GetStudyId(),
107 fatherAlgo->GetGen() );
110 algo->myProxyMesh->GetMesh() != helper->GetMesh() )
111 algo->myProxyMesh.reset( new SMESH_ProxyMesh( *helper->GetMesh() ));
113 algo->myQuadList.clear();
116 algo->_quadraticMesh = helper->GetIsQuadratic();
121 //=======================================================================
123 * \brief Algorithm projecting 1D mesh
125 struct TProjction1dAlgo : public StdMeshers_Projection_1D
127 StdMeshers_ProjectionSource1D myHyp;
129 TProjction1dAlgo(int studyId, SMESH_Gen* gen)
130 : StdMeshers_Projection_1D( gen->GetANewId(), studyId, gen),
131 myHyp( gen->GetANewId(), studyId, gen)
133 StdMeshers_Projection_1D::_sourceHypo = & myHyp;
135 static TProjction1dAlgo* instance( SMESH_Algo* fatherAlgo )
137 static TProjction1dAlgo* algo = new TProjction1dAlgo( fatherAlgo->GetStudyId(),
138 fatherAlgo->GetGen() );
142 //=======================================================================
144 * \brief Algorithm projecting 2D mesh
146 struct TProjction2dAlgo : public StdMeshers_Projection_1D2D
148 StdMeshers_ProjectionSource2D myHyp;
150 TProjction2dAlgo(int studyId, SMESH_Gen* gen)
151 : StdMeshers_Projection_1D2D( gen->GetANewId(), studyId, gen),
152 myHyp( gen->GetANewId(), studyId, gen)
154 StdMeshers_Projection_2D::_sourceHypo = & myHyp;
156 static TProjction2dAlgo* instance( SMESH_Algo* fatherAlgo )
158 static TProjction2dAlgo* algo = new TProjction2dAlgo( fatherAlgo->GetStudyId(),
159 fatherAlgo->GetGen() );
162 const NSProjUtils::TNodeNodeMap& GetNodesMap()
164 return _src2tgtNodes;
166 void SetEventListener( SMESH_subMesh* tgtSubMesh )
168 NSProjUtils::SetEventListener( tgtSubMesh,
169 _sourceHypo->GetSourceFace(),
170 _sourceHypo->GetSourceMesh() );
173 //=======================================================================
175 * \brief Returns already computed EDGEs
177 void getPrecomputedEdges( SMESH_MesherHelper& theHelper,
178 const TopoDS_Shape& theShape,
179 vector< TopoDS_Edge >& theEdges)
183 SMESHDS_Mesh* meshDS = theHelper.GetMeshDS();
186 TopTools_IndexedMapOfShape edges;
187 TopExp::MapShapes( theShape, TopAbs_EDGE, edges );
188 for ( int iE = 1; iE <= edges.Extent(); ++iE )
190 const TopoDS_Shape edge = edges( iE );
191 if (( ! ( sm = meshDS->MeshElements( edge ))) ||
192 ( sm->NbElements() == 0 ))
195 // there must not be FACEs meshed with triangles and sharing a computed EDGE
196 // as the precomputed EDGEs are used for propagation other to 'vertical' EDGEs
197 bool faceFound = false;
198 PShapeIteratorPtr faceIt =
199 theHelper.GetAncestors( edge, *theHelper.GetMesh(), TopAbs_FACE );
200 while ( const TopoDS_Shape* face = faceIt->next() )
202 if (( sm = meshDS->MeshElements( *face )) &&
203 ( sm->NbElements() > 0 ) &&
204 ( !theHelper.IsSameElemGeometry( sm, SMDSGeom_QUADRANGLE ) ))
210 theEdges.push_back( TopoDS::Edge( edge ));
214 //================================================================================
216 * \brief Make \a botE be the BOTTOM_SIDE of \a quad.
217 * Return false if the BOTTOM_SIDE is composite
219 //================================================================================
221 bool setBottomEdge( const TopoDS_Edge& botE,
222 FaceQuadStruct::Ptr& quad,
223 const TopoDS_Shape& face)
225 quad->side[ QUAD_TOP_SIDE ].grid->Reverse();
226 quad->side[ QUAD_LEFT_SIDE ].grid->Reverse();
228 bool isComposite = false;
229 for ( size_t i = 0; i < quad->side.size(); ++i )
231 StdMeshers_FaceSidePtr quadSide = quad->side[i];
232 for ( int iE = 0; iE < quadSide->NbEdges(); ++iE )
233 if ( botE.IsSame( quadSide->Edge( iE )))
235 if ( quadSide->NbEdges() > 1 )
236 isComposite = true; //return false;
238 i = quad->side.size(); // to quit from the outer loop
242 if ( edgeIndex != QUAD_BOTTOM_SIDE )
243 quad->shift( quad->side.size() - edgeIndex, /*keepUnitOri=*/false );
245 quad->face = TopoDS::Face( face );
250 //================================================================================
252 * \brief Return iterator pointing to node column for the given parameter
253 * \param columnsMap - node column map
254 * \param parameter - parameter
255 * \retval TParam2ColumnMap::iterator - result
257 * it returns closest left column
259 //================================================================================
261 TParam2ColumnIt getColumn( const TParam2ColumnMap* columnsMap,
262 const double parameter )
264 TParam2ColumnIt u_col = columnsMap->upper_bound( parameter );
265 if ( u_col != columnsMap->begin() )
267 return u_col; // return left column
270 //================================================================================
272 * \brief Return nodes around given parameter and a ratio
273 * \param column - node column
274 * \param param - parameter
275 * \param node1 - lower node
276 * \param node2 - upper node
277 * \retval double - ratio
279 //================================================================================
281 double getRAndNodes( const TNodeColumn* column,
283 const SMDS_MeshNode* & node1,
284 const SMDS_MeshNode* & node2)
286 if ( param >= 1.0 || column->size() == 1) {
287 node1 = node2 = column->back();
291 int i = int( param * ( column->size() - 1 ));
292 double u0 = double( i )/ double( column->size() - 1 );
293 double r = ( param - u0 ) * ( column->size() - 1 );
295 node1 = (*column)[ i ];
296 node2 = (*column)[ i + 1];
300 //================================================================================
302 * \brief Compute boundary parameters of face parts
303 * \param nbParts - nb of parts to split columns into
304 * \param columnsMap - node columns of the face to split
305 * \param params - computed parameters
307 //================================================================================
309 void splitParams( const int nbParts,
310 const TParam2ColumnMap* columnsMap,
311 vector< double > & params)
314 params.reserve( nbParts + 1 );
315 TParam2ColumnIt last_par_col = --columnsMap->end();
316 double par = columnsMap->begin()->first; // 0.
317 double parLast = last_par_col->first;
318 params.push_back( par );
319 for ( int i = 0; i < nbParts - 1; ++ i )
321 double partSize = ( parLast - par ) / double ( nbParts - i );
322 TParam2ColumnIt par_col = getColumn( columnsMap, par + partSize );
323 if ( par_col->first == par ) {
325 if ( par_col == last_par_col ) {
326 while ( i < nbParts - 1 )
327 params.push_back( par + partSize * i++ );
331 par = par_col->first;
332 params.push_back( par );
334 params.push_back( parLast ); // 1.
337 //================================================================================
339 * \brief Return coordinate system for z-th layer of nodes
341 //================================================================================
343 gp_Ax2 getLayerCoordSys(const int z,
344 const vector< const TNodeColumn* >& columns,
347 // gravity center of a layer
350 for ( size_t i = 0; i < columns.size(); ++i )
352 O += gpXYZ( (*columns[ i ])[ z ]);
353 if ( vertexCol < 0 &&
354 columns[ i ]->front()->GetPosition()->GetTypeOfPosition() == SMDS_TOP_VERTEX )
361 int iPrev = columns.size()-1;
362 for ( size_t i = 0; i < columns.size(); ++i )
364 gp_Vec v1( O, gpXYZ( (*columns[ iPrev ])[ z ]));
365 gp_Vec v2( O, gpXYZ( (*columns[ i ] )[ z ]));
370 if ( vertexCol >= 0 )
372 O = gpXYZ( (*columns[ vertexCol ])[ z ]);
374 if ( xColumn < 0 || xColumn >= (int) columns.size() )
376 // select a column for X dir
378 for ( size_t i = 0; i < columns.size(); ++i )
380 double dist = ( O - gpXYZ((*columns[ i ])[ z ])).SquareModulus();
381 if ( dist > maxDist )
390 gp_Vec X( O, gpXYZ( (*columns[ xColumn ])[ z ]));
392 return gp_Ax2( O, Z, X);
395 //================================================================================
397 * \brief Removes submeshes that are or can be meshed with regular grid from given list
398 * \retval int - nb of removed submeshes
400 //================================================================================
402 int removeQuasiQuads(list< SMESH_subMesh* >& notQuadSubMesh,
403 SMESH_MesherHelper* helper,
404 StdMeshers_Quadrangle_2D* quadAlgo)
407 //SMESHDS_Mesh* mesh = notQuadSubMesh.front()->GetFather()->GetMeshDS();
408 list< SMESH_subMesh* >::iterator smIt = notQuadSubMesh.begin();
409 while ( smIt != notQuadSubMesh.end() )
411 SMESH_subMesh* faceSm = *smIt;
412 SMESHDS_SubMesh* faceSmDS = faceSm->GetSubMeshDS();
413 int nbQuads = faceSmDS ? faceSmDS->NbElements() : 0;
416 toRemove = helper->IsStructured( faceSm );
418 toRemove = ( quadAlgo->CheckNbEdges( *helper->GetMesh(),
419 faceSm->GetSubShape() ) != NULL );
420 nbRemoved += toRemove;
422 smIt = notQuadSubMesh.erase( smIt );
430 //================================================================================
432 * \brief Return and angle between two EDGEs
433 * \return double - the angle normalized so that
440 //================================================================================
442 // double normAngle(const TopoDS_Edge & E1, const TopoDS_Edge & E2, const TopoDS_Face & F)
444 // return SMESH_MesherHelper::GetAngle( E1, E2, F ) / ( 0.5 * M_PI );
447 //================================================================================
449 * Consider continuous straight EDGES as one side - mark them to unite
451 //================================================================================
453 int countNbSides( const Prism_3D::TPrismTopo & thePrism,
454 vector<int> & nbUnitePerEdge,
455 vector< double > & edgeLength)
457 int nbEdges = thePrism.myNbEdgesInWires.front(); // nb outer edges
458 int nbSides = nbEdges;
461 list< TopoDS_Edge >::const_iterator edgeIt = thePrism.myBottomEdges.begin();
462 std::advance( edgeIt, nbEdges-1 );
463 TopoDS_Edge prevE = *edgeIt;
464 // bool isPrevStraight = SMESH_Algo::IsStraight( prevE );
465 // int iPrev = nbEdges - 1;
467 // int iUnite = -1; // the first of united EDGEs
469 // analyse angles between EDGEs
471 vector< bool > isCorner( nbEdges );
472 edgeIt = thePrism.myBottomEdges.begin();
473 for ( int iE = 0; iE < nbEdges; ++iE, ++edgeIt )
475 const TopoDS_Edge& curE = *edgeIt;
476 edgeLength[ iE ] = SMESH_Algo::EdgeLength( curE );
478 // double normAngle = normAngle( prevE, curE, thePrism.myBottom );
479 // isCorner[ iE ] = false;
480 // if ( normAngle < 2.0 )
482 // if ( normAngle < 0.001 ) // straight or obtuse angle
484 // // unite EDGEs in order not to put a corner of the unit quadrangle at this VERTEX
487 // nbUnitePerEdge[ iUnite ]++;
488 // nbUnitePerEdge[ iE ] = -1;
493 // isCorner[ iE ] = true;
503 // define which of corners to put on a side of the unit quadrangle
505 // edgeIt = thePrism.myBottomEdges.begin();
506 // for ( int iE = 0; iE < nbEdges; ++iE, ++edgeIt )
508 // const TopoDS_Edge& curE = *edgeIt;
509 // edgeLength[ iE ] = SMESH_Algo::EdgeLength( curE );
511 // const bool isCurStraight = SMESH_Algo::IsStraight( curE );
512 // if ( isPrevStraight && isCurStraight && SMESH_Algo::IsContinuous( prevE, curE ))
516 // nbUnitePerEdge[ iUnite ]++;
517 // nbUnitePerEdge[ iE ] = -1;
525 // isPrevStraight = isCurStraight;
532 void pointsToPython(const std::vector<gp_XYZ>& p)
535 for ( size_t i = SMESH_Block::ID_V000; i < p.size(); ++i )
537 cout << "mesh.AddNode( " << p[i].X() << ", "<< p[i].Y() << ", "<< p[i].Z() << ") # " << i <<" " ;
538 SMESH_Block::DumpShapeID( i, cout ) << endl;
544 //=======================================================================
545 //function : StdMeshers_Prism_3D
547 //=======================================================================
549 StdMeshers_Prism_3D::StdMeshers_Prism_3D(int hypId, int studyId, SMESH_Gen* gen)
550 :SMESH_3D_Algo(hypId, studyId, gen)
553 _shapeType = (1 << TopAbs_SOLID); // 1 bit per shape type
554 _onlyUnaryInput = false; // mesh all SOLIDs at once
555 _requireDiscreteBoundary = false; // mesh FACEs and EDGEs by myself
556 _supportSubmeshes = true; // "source" FACE must be meshed by other algo
557 _neededLowerHyps[ 1 ] = true; // suppress warning on hiding a global 1D algo
558 _neededLowerHyps[ 2 ] = true; // suppress warning on hiding a global 2D algo
560 //myProjectTriangles = false;
561 mySetErrorToSM = true; // to pass an error to a sub-mesh of a current solid or not
564 //================================================================================
568 //================================================================================
570 StdMeshers_Prism_3D::~StdMeshers_Prism_3D()
572 pointsToPython( std::vector<gp_XYZ>() ); // avoid warning: pointsToPython defined but not used
575 //=======================================================================
576 //function : CheckHypothesis
578 //=======================================================================
580 bool StdMeshers_Prism_3D::CheckHypothesis(SMESH_Mesh& aMesh,
581 const TopoDS_Shape& aShape,
582 SMESH_Hypothesis::Hypothesis_Status& aStatus)
584 // Check shape geometry
586 aStatus = SMESH_Hypothesis::HYP_BAD_GEOMETRY;
588 // find not quadrangle faces
589 list< TopoDS_Shape > notQuadFaces;
590 int nbEdge, nbWire, nbFace = 0;
591 TopExp_Explorer exp( aShape, TopAbs_FACE );
592 for ( ; exp.More(); exp.Next() ) {
594 const TopoDS_Shape& face = exp.Current();
595 nbEdge = NSProjUtils::Count( face, TopAbs_EDGE, 0 );
596 nbWire = NSProjUtils::Count( face, TopAbs_WIRE, 0 );
597 if ( nbEdge!= 4 || nbWire!= 1 ) {
598 if ( !notQuadFaces.empty() ) {
599 if ( NSProjUtils::Count( notQuadFaces.back(), TopAbs_EDGE, 0 ) != nbEdge ||
600 NSProjUtils::Count( notQuadFaces.back(), TopAbs_WIRE, 0 ) != nbWire )
601 RETURN_BAD_RESULT("Different not quad faces");
603 notQuadFaces.push_back( face );
606 if ( !notQuadFaces.empty() )
608 if ( notQuadFaces.size() != 2 )
609 RETURN_BAD_RESULT("Bad nb not quad faces: " << notQuadFaces.size());
611 // check total nb faces
612 nbEdge = NSProjUtils::Count( notQuadFaces.back(), TopAbs_EDGE, 0 );
613 if ( nbFace != nbEdge + 2 )
614 RETURN_BAD_RESULT("Bad nb of faces: " << nbFace << " but must be " << nbEdge + 2);
618 aStatus = SMESH_Hypothesis::HYP_OK;
622 //=======================================================================
624 //purpose : Compute mesh on a COMPOUND of SOLIDs
625 //=======================================================================
627 bool StdMeshers_Prism_3D::Compute(SMESH_Mesh& theMesh, const TopoDS_Shape& theShape)
629 SMESH_MesherHelper helper( theMesh );
632 int nbSolids = helper.Count( theShape, TopAbs_SOLID, /*skipSame=*/false );
636 TopTools_IndexedDataMapOfShapeListOfShape faceToSolids;
637 TopExp::MapShapesAndAncestors( theShape, TopAbs_FACE, TopAbs_SOLID, faceToSolids );
639 // look for meshed FACEs ("source" FACEs) that must be prism bottoms
640 list< TopoDS_Face > meshedFaces, notQuadMeshedFaces, notQuadFaces;
641 const bool meshHasQuads = ( theMesh.NbQuadrangles() > 0 );
642 //StdMeshers_Quadrangle_2D* quadAlgo = TQuadrangleAlgo::instance( this );
643 for ( int iF = 1; iF <= faceToSolids.Extent(); ++iF )
645 const TopoDS_Face& face = TopoDS::Face( faceToSolids.FindKey( iF ));
646 SMESH_subMesh* faceSM = theMesh.GetSubMesh( face );
647 if ( !faceSM->IsEmpty() )
649 if ( !meshHasQuads ||
650 !helper.IsSameElemGeometry( faceSM->GetSubMeshDS(), SMDSGeom_QUADRANGLE ) ||
651 !helper.IsStructured( faceSM )
653 notQuadMeshedFaces.push_front( face );
654 else if ( myHelper->Count( face, TopAbs_EDGE, /*ignoreSame=*/false ) != 4 )
655 meshedFaces.push_front( face );
657 meshedFaces.push_back( face );
659 // not add not quadrilateral FACE as we can't compute it
660 // else if ( !quadAlgo->CheckNbEdges( theMesh, face ))
661 // // not add not quadrilateral FACE as it can be a prism side
662 // // else if ( myHelper->Count( face, TopAbs_EDGE, /*ignoreSame=*/false ) != 4 )
664 // notQuadFaces.push_back( face );
667 // notQuadFaces are of medium priority, put them before ordinary meshed faces
668 meshedFaces.splice( meshedFaces.begin(), notQuadFaces );
669 // notQuadMeshedFaces are of highest priority, put them before notQuadFaces
670 meshedFaces.splice( meshedFaces.begin(), notQuadMeshedFaces );
672 Prism_3D::TPrismTopo prism;
674 bool selectBottom = meshedFaces.empty();
678 TopoDS_Shape solid = TopExp_Explorer( theShape, TopAbs_SOLID ).Current();
679 if ( !meshedFaces.empty() )
680 prism.myBottom = meshedFaces.front();
681 return ( initPrism( prism, solid, selectBottom ) &&
685 // find propagation chains from already computed EDGEs
686 vector< TopoDS_Edge > computedEdges;
687 getPrecomputedEdges( helper, theShape, computedEdges );
688 myPropagChains = new TopTools_IndexedMapOfShape[ computedEdges.size() + 1 ];
689 SMESHUtils::ArrayDeleter< TopTools_IndexedMapOfShape > pcDel( myPropagChains );
690 for ( size_t i = 0, nb = 0; i < computedEdges.size(); ++i )
692 StdMeshers_ProjectionUtils::GetPropagationEdge( &theMesh, TopoDS_Edge(),
693 computedEdges[i], myPropagChains + nb );
694 if ( myPropagChains[ nb ].Extent() < 2 ) // an empty map is a termination sign
695 myPropagChains[ nb ].Clear();
700 TopTools_MapOfShape meshedSolids;
701 list< Prism_3D::TPrismTopo > meshedPrism;
702 list< TopoDS_Face > suspectSourceFaces;
703 TopTools_ListIteratorOfListOfShape solidIt;
705 while ( meshedSolids.Extent() < nbSolids )
707 if ( _computeCanceled )
708 return toSM( error( SMESH_ComputeError::New(COMPERR_CANCELED)));
710 // compute prisms having avident computed source FACE
711 while ( !meshedFaces.empty() )
713 TopoDS_Face face = meshedFaces.front();
714 meshedFaces.pop_front();
715 TopTools_ListOfShape& solidList = faceToSolids.ChangeFromKey( face );
716 while ( !solidList.IsEmpty() )
718 TopoDS_Shape solid = solidList.First();
719 solidList.RemoveFirst();
720 if ( meshedSolids.Add( solid ))
723 prism.myBottom = face;
724 if ( !initPrism( prism, solid, selectBottom ) ||
728 SMESHDS_SubMesh* smDS = theMesh.GetMeshDS()->MeshElements( prism.myTop );
729 if ( !myHelper->IsSameElemGeometry( smDS, SMDSGeom_QUADRANGLE ))
731 meshedFaces.push_front( prism.myTop );
735 suspectSourceFaces.push_back( prism.myTop );
737 meshedPrism.push_back( prism );
741 if ( meshedSolids.Extent() == nbSolids )
744 // below in the loop we try to find source FACEs somehow
746 // project mesh from source FACEs of computed prisms to
747 // prisms sharing wall FACEs
748 list< Prism_3D::TPrismTopo >::iterator prismIt = meshedPrism.begin();
749 for ( ; prismIt != meshedPrism.end(); ++prismIt )
751 for ( size_t iW = 0; iW < prismIt->myWallQuads.size(); ++iW )
753 Prism_3D::TQuadList::iterator wQuad = prismIt->myWallQuads[iW].begin();
754 for ( ; wQuad != prismIt->myWallQuads[iW].end(); ++ wQuad )
756 const TopoDS_Face& wFace = (*wQuad)->face;
757 TopTools_ListOfShape& solidList = faceToSolids.ChangeFromKey( wFace );
758 solidIt.Initialize( solidList );
759 while ( solidIt.More() )
761 const TopoDS_Shape& solid = solidIt.Value();
762 if ( meshedSolids.Contains( solid )) {
763 solidList.Remove( solidIt );
764 continue; // already computed prism
766 if ( myHelper->IsBlock( solid )) {
768 continue; // too trivial
770 // find a source FACE of the SOLID: it's a FACE sharing a bottom EDGE with wFace
771 const TopoDS_Edge& wEdge = (*wQuad)->side[ QUAD_TOP_SIDE ].grid->Edge(0);
772 PShapeIteratorPtr faceIt = myHelper->GetAncestors( wEdge, *myHelper->GetMesh(),
774 while ( const TopoDS_Shape* f = faceIt->next() )
776 const TopoDS_Face& candidateF = TopoDS::Face( *f );
777 if ( candidateF.IsSame( wFace )) continue;
778 // select a source FACE: prismIt->myBottom or prismIt->myTop
779 TopoDS_Face sourceF = prismIt->myBottom;
780 for ( TopExp_Explorer v( prismIt->myTop, TopAbs_VERTEX ); v.More(); v.Next() )
781 if ( myHelper->IsSubShape( v.Current(), candidateF )) {
782 sourceF = prismIt->myTop;
786 prism.myBottom = candidateF;
787 mySetErrorToSM = false;
788 if ( !myHelper->IsSubShape( candidateF, prismIt->myShape3D ) &&
789 myHelper ->IsSubShape( candidateF, solid ) &&
790 !myHelper->GetMesh()->GetSubMesh( candidateF )->IsMeshComputed() &&
791 initPrism( prism, solid, /*selectBottom=*/false ) &&
792 !myHelper->GetMesh()->GetSubMesh( prism.myTop )->IsMeshComputed() &&
793 !myHelper->GetMesh()->GetSubMesh( prism.myBottom )->IsMeshComputed() &&
794 project2dMesh( sourceF, prism.myBottom ))
796 mySetErrorToSM = true;
797 if ( !compute( prism ))
799 SMESHDS_SubMesh* smDS = theMesh.GetMeshDS()->MeshElements( prism.myTop );
800 if ( !myHelper->IsSameElemGeometry( smDS, SMDSGeom_QUADRANGLE ))
802 meshedFaces.push_front( prism.myTop );
803 meshedFaces.push_front( prism.myBottom );
804 selectBottom = false;
806 meshedPrism.push_back( prism );
807 meshedSolids.Add( solid );
811 mySetErrorToSM = true;
813 if ( meshedSolids.Contains( solid ))
814 solidList.Remove( solidIt );
820 if ( !meshedFaces.empty() )
821 break; // to compute prisms with avident sources
824 if ( meshedFaces.empty() )
826 meshedFaces.splice( meshedFaces.end(), suspectSourceFaces );
830 // find FACEs with local 1D hyps, which has to be computed by now,
831 // or at least any computed FACEs
832 if ( meshedFaces.empty() )
835 for ( int iF = 1; iF <= faceToSolids.Extent(); ++iF )
837 const TopoDS_Face& face = TopoDS::Face( faceToSolids.FindKey( iF ));
838 const TopTools_ListOfShape& solidList = faceToSolids.FindFromKey( face );
839 if ( solidList.IsEmpty() ) continue;
840 SMESH_subMesh* faceSM = theMesh.GetSubMesh( face );
841 if ( !faceSM->IsEmpty() )
843 int nbFaces = faceSM->GetSubMeshDS()->NbElements();
844 if ( prevNbFaces < nbFaces )
846 if ( !meshedFaces.empty() ) meshedFaces.pop_back();
847 meshedFaces.push_back( face ); // lower priority
849 prevNbFaces = nbFaces;
854 bool allSubMeComputed = true;
855 SMESH_subMeshIteratorPtr smIt = faceSM->getDependsOnIterator(false,true);
856 while ( smIt->more() && allSubMeComputed )
857 allSubMeComputed = smIt->next()->IsMeshComputed();
858 if ( allSubMeComputed )
860 faceSM->ComputeStateEngine( SMESH_subMesh::COMPUTE );
861 if ( !faceSM->IsEmpty() ) {
862 meshedFaces.push_front( face ); // higher priority
867 faceSM->ComputeStateEngine( SMESH_subMesh::CHECK_COMPUTE_STATE );
875 // TODO. there are other ways to find out the source FACE:
876 // propagation, topological similarity, etc...
878 // simply try to mesh all not meshed SOLIDs
879 if ( meshedFaces.empty() )
881 for ( TopExp_Explorer solid( theShape, TopAbs_SOLID ); solid.More(); solid.Next() )
883 mySetErrorToSM = false;
885 if ( !meshedSolids.Contains( solid.Current() ) &&
886 initPrism( prism, solid.Current() ))
888 mySetErrorToSM = true;
889 if ( !compute( prism ))
891 meshedFaces.push_front( prism.myTop );
892 meshedFaces.push_front( prism.myBottom );
893 meshedPrism.push_back( prism );
894 meshedSolids.Add( solid.Current() );
897 mySetErrorToSM = true;
901 if ( meshedFaces.empty() ) // set same error to 10 not-computed solids
903 SMESH_ComputeErrorPtr err = SMESH_ComputeError::New
904 ( COMPERR_BAD_INPUT_MESH, "No meshed source face found", this );
906 const int maxNbErrors = 10; // limit nb errors not to overload the Compute dialog
907 TopExp_Explorer solid( theShape, TopAbs_SOLID );
908 for ( int i = 0; ( i < maxNbErrors && solid.More() ); ++i, solid.Next() )
909 if ( !meshedSolids.Contains( solid.Current() ))
911 SMESH_subMesh* sm = theMesh.GetSubMesh( solid.Current() );
912 sm->GetComputeError() = err;
917 return error( COMPERR_OK );
920 //================================================================================
922 * \brief Find wall faces by bottom edges
924 //================================================================================
926 bool StdMeshers_Prism_3D::getWallFaces( Prism_3D::TPrismTopo & thePrism,
927 const int totalNbFaces)
929 thePrism.myWallQuads.clear();
931 SMESH_Mesh* mesh = myHelper->GetMesh();
933 StdMeshers_Quadrangle_2D* quadAlgo = TQuadrangleAlgo::instance( this, myHelper );
935 TopTools_MapOfShape faceMap;
936 TopTools_IndexedDataMapOfShapeListOfShape edgeToFaces;
937 TopExp::MapShapesAndAncestors( thePrism.myShape3D,
938 TopAbs_EDGE, TopAbs_FACE, edgeToFaces );
940 // ------------------------------
941 // Get the 1st row of wall FACEs
942 // ------------------------------
944 list< TopoDS_Edge >::iterator edge = thePrism.myBottomEdges.begin();
945 std::list< int >::iterator nbE = thePrism.myNbEdgesInWires.begin();
946 std::list< int > nbQuadsPerWire;
948 while ( edge != thePrism.myBottomEdges.end() )
951 if ( SMESH_Algo::isDegenerated( *edge ))
953 edge = thePrism.myBottomEdges.erase( edge );
959 bool hasWallFace = false;
960 TopTools_ListIteratorOfListOfShape faceIt( edgeToFaces.FindFromKey( *edge ));
961 for ( ; faceIt.More(); faceIt.Next() )
963 const TopoDS_Face& face = TopoDS::Face( faceIt.Value() );
964 if ( !thePrism.myBottom.IsSame( face ))
967 Prism_3D::TQuadList quadList( 1, quadAlgo->CheckNbEdges( *mesh, face ));
968 if ( !quadList.back() )
969 return toSM( error(TCom("Side face #") << shapeID( face )
970 << " not meshable with quadrangles"));
971 bool isCompositeBase = ! setBottomEdge( *edge, quadList.back(), face );
972 if ( isCompositeBase )
974 // it's OK if all EDGEs of the bottom side belongs to the bottom FACE
975 StdMeshers_FaceSidePtr botSide = quadList.back()->side[ QUAD_BOTTOM_SIDE ];
976 for ( int iE = 0; iE < botSide->NbEdges(); ++iE )
977 if ( !myHelper->IsSubShape( botSide->Edge(iE), thePrism.myBottom ))
978 return toSM( error(TCom("Composite 'horizontal' edges are not supported")));
980 if ( faceMap.Add( face ))
981 thePrism.myWallQuads.push_back( quadList );
989 else // seam edge (IPAL53561)
991 edge = thePrism.myBottomEdges.erase( edge );
1000 int nbQuadPrev = std::accumulate( nbQuadsPerWire.begin(), nbQuadsPerWire.end(), 0 );
1001 nbQuadsPerWire.push_back( thePrism.myWallQuads.size() - nbQuadPrev );
1005 // -------------------------
1006 // Find the rest wall FACEs
1007 // -------------------------
1009 // Compose a vector of indixes of right neighbour FACE for each wall FACE
1010 // that is not so evident in case of several WIREs in the bottom FACE
1011 thePrism.myRightQuadIndex.clear();
1012 for ( size_t i = 0; i < thePrism.myWallQuads.size(); ++i )
1014 thePrism.myRightQuadIndex.push_back( i+1 ); // OK for all but the last EDGE of a WIRE
1016 list< int >::iterator nbQinW = nbQuadsPerWire.begin();
1017 for ( int iLeft = 0; nbQinW != nbQuadsPerWire.end(); ++nbQinW )
1019 thePrism.myRightQuadIndex[ iLeft + *nbQinW - 1 ] = iLeft; // for the last EDGE of a WIRE
1023 while ( totalNbFaces - faceMap.Extent() > 2 )
1025 // find wall FACEs adjacent to each of wallQuads by the right side EDGE
1028 nbKnownFaces = faceMap.Extent();
1029 StdMeshers_FaceSidePtr rightSide, topSide; // sides of the quad
1030 for ( size_t i = 0; i < thePrism.myWallQuads.size(); ++i )
1032 rightSide = thePrism.myWallQuads[i].back()->side[ QUAD_RIGHT_SIDE ];
1033 for ( int iE = 0; iE < rightSide->NbEdges(); ++iE ) // rightSide can be composite
1035 const TopoDS_Edge & rightE = rightSide->Edge( iE );
1036 TopTools_ListIteratorOfListOfShape face( edgeToFaces.FindFromKey( rightE ));
1037 for ( ; face.More(); face.Next() )
1038 if ( faceMap.Add( face.Value() ))
1040 // a new wall FACE encountered, store it in thePrism.myWallQuads
1041 const int iRight = thePrism.myRightQuadIndex[i];
1042 topSide = thePrism.myWallQuads[ iRight ].back()->side[ QUAD_TOP_SIDE ];
1043 const TopoDS_Edge& newBotE = topSide->Edge(0);
1044 const TopoDS_Shape& newWallF = face.Value();
1045 thePrism.myWallQuads[ iRight ].push_back( quadAlgo->CheckNbEdges( *mesh, newWallF ));
1046 if ( !thePrism.myWallQuads[ iRight ].back() )
1047 return toSM( error(TCom("Side face #") << shapeID( newWallF ) <<
1048 " not meshable with quadrangles"));
1049 if ( ! setBottomEdge( newBotE, thePrism.myWallQuads[ iRight ].back(), newWallF ))
1050 return toSM( error(TCom("Composite 'horizontal' edges are not supported")));
1054 } while ( nbKnownFaces != faceMap.Extent() );
1056 // find wall FACEs adjacent to each of thePrism.myWallQuads by the top side EDGE
1057 if ( totalNbFaces - faceMap.Extent() > 2 )
1059 const int nbFoundWalls = faceMap.Extent();
1060 for ( size_t i = 0; i < thePrism.myWallQuads.size(); ++i )
1062 StdMeshers_FaceSidePtr topSide = thePrism.myWallQuads[i].back()->side[ QUAD_TOP_SIDE ];
1063 const TopoDS_Edge & topE = topSide->Edge( 0 );
1064 if ( topSide->NbEdges() > 1 )
1065 return toSM( error(COMPERR_BAD_SHAPE, TCom("Side face #") <<
1066 shapeID( thePrism.myWallQuads[i].back()->face )
1067 << " has a composite top edge"));
1068 TopTools_ListIteratorOfListOfShape faceIt( edgeToFaces.FindFromKey( topE ));
1069 for ( ; faceIt.More(); faceIt.Next() )
1070 if ( faceMap.Add( faceIt.Value() ))
1072 // a new wall FACE encountered, store it in wallQuads
1073 thePrism.myWallQuads[ i ].push_back( quadAlgo->CheckNbEdges( *mesh, faceIt.Value() ));
1074 if ( !thePrism.myWallQuads[ i ].back() )
1075 return toSM( error(TCom("Side face #") << shapeID( faceIt.Value() ) <<
1076 " not meshable with quadrangles"));
1077 if ( ! setBottomEdge( topE, thePrism.myWallQuads[ i ].back(), faceIt.Value() ))
1078 return toSM( error(TCom("Composite 'horizontal' edges are not supported")));
1079 if ( totalNbFaces - faceMap.Extent() == 2 )
1081 i = thePrism.myWallQuads.size(); // to quit from the outer loop
1086 if ( nbFoundWalls == faceMap.Extent() )
1087 return toSM( error("Failed to find wall faces"));
1090 } // while ( totalNbFaces - faceMap.Extent() > 2 )
1092 // ------------------
1093 // Find the top FACE
1094 // ------------------
1096 if ( thePrism.myTop.IsNull() )
1098 // now only top and bottom FACEs are not in the faceMap
1099 faceMap.Add( thePrism.myBottom );
1100 for ( TopExp_Explorer f( thePrism.myShape3D, TopAbs_FACE ); f.More(); f.Next() )
1101 if ( !faceMap.Contains( f.Current() )) {
1102 thePrism.myTop = TopoDS::Face( f.Current() );
1105 if ( thePrism.myTop.IsNull() )
1106 return toSM( error("Top face not found"));
1109 // Check that the top FACE shares all the top EDGEs
1110 for ( size_t i = 0; i < thePrism.myWallQuads.size(); ++i )
1112 StdMeshers_FaceSidePtr topSide = thePrism.myWallQuads[i].back()->side[ QUAD_TOP_SIDE ];
1113 const TopoDS_Edge & topE = topSide->Edge( 0 );
1114 if ( !myHelper->IsSubShape( topE, thePrism.myTop ))
1115 return toSM( error( TCom("Wrong source face: #") << shapeID( thePrism.myBottom )));
1121 //=======================================================================
1122 //function : compute
1123 //purpose : Compute mesh on a SOLID
1124 //=======================================================================
1126 bool StdMeshers_Prism_3D::compute(const Prism_3D::TPrismTopo& thePrism)
1128 myHelper->IsQuadraticSubMesh( thePrism.myShape3D );
1129 if ( _computeCanceled )
1130 return toSM( error( SMESH_ComputeError::New(COMPERR_CANCELED)));
1132 // Assure the bottom is meshed
1133 SMESH_subMesh * botSM = myHelper->GetMesh()->GetSubMesh( thePrism.myBottom );
1134 if (( botSM->IsEmpty() ) &&
1135 ( ! botSM->GetAlgo() ||
1136 ! _gen->Compute( *botSM->GetFather(), botSM->GetSubShape(), /*shapeOnly=*/true )))
1137 return error( COMPERR_BAD_INPUT_MESH,
1138 TCom( "No mesher defined to compute the base face #")
1139 << shapeID( thePrism.myBottom ));
1141 // Make all side FACEs of thePrism meshed with quads
1142 if ( !computeWalls( thePrism ))
1145 // Analyse mesh and geometry to find all block sub-shapes and submeshes
1146 // (after fixing IPAL52499 myBlock is used as a holder of boundary nodes
1147 // and for 2D projection in hard cases where StdMeshers_Projection_2D fails;
1148 // location of internal nodes is usually computed by StdMeshers_Sweeper)
1149 if ( !myBlock.Init( myHelper, thePrism ))
1150 return toSM( error( myBlock.GetError()));
1152 SMESHDS_Mesh* meshDS = myHelper->GetMeshDS();
1154 int volumeID = meshDS->ShapeToIndex( thePrism.myShape3D );
1156 // Try to get gp_Trsf to get all nodes from bottom ones
1157 vector<gp_Trsf> trsf;
1158 gp_Trsf bottomToTopTrsf;
1159 // if ( !myBlock.GetLayersTransformation( trsf, thePrism ))
1161 // else if ( !trsf.empty() )
1162 // bottomToTopTrsf = trsf.back();
1164 // To compute coordinates of a node inside a block, it is necessary to know
1165 // 1. normalized parameters of the node by which
1166 // 2. coordinates of node projections on all block sub-shapes are computed
1168 // So we fill projections on vertices at once as they are same for all nodes
1169 myShapeXYZ.resize( myBlock.NbSubShapes() );
1170 for ( int iV = SMESH_Block::ID_FirstV; iV < SMESH_Block::ID_FirstE; ++iV ) {
1171 myBlock.VertexPoint( iV, myShapeXYZ[ iV ]);
1172 SHOWYXZ("V point " <<iV << " ", myShapeXYZ[ iV ]);
1175 // Projections on the top and bottom faces are taken from nodes existing
1176 // on these faces; find correspondence between bottom and top nodes
1177 myUseBlock = false; // is set to true if projection is done using "block approach"
1178 myBotToColumnMap.clear();
1179 if ( !assocOrProjBottom2Top( bottomToTopTrsf, thePrism ) ) // it also fills myBotToColumnMap
1183 // Create nodes inside the block
1187 // use transformation (issue 0020680, IPAL0052499) or a "straight line" approach
1188 StdMeshers_Sweeper sweeper;
1190 // load boundary nodes into sweeper
1192 const SMDS_MeshNode* prevN0 = 0, *prevN1 = 0;
1193 list< TopoDS_Edge >::const_iterator edge = thePrism.myBottomEdges.begin();
1194 for ( ; edge != thePrism.myBottomEdges.end(); ++edge )
1196 int edgeID = meshDS->ShapeToIndex( *edge );
1197 TParam2ColumnMap* u2col = const_cast<TParam2ColumnMap*>
1198 ( myBlock.GetParam2ColumnMap( edgeID, dummy ));
1200 TParam2ColumnMap::iterator u2colIt = u2col->begin(), u2colEnd = u2col->end();
1201 const SMDS_MeshNode* n0 = u2colIt->second[0];
1202 const SMDS_MeshNode* n1 = u2col->rbegin()->second[0];
1203 if ( n0 == prevN0 || n0 == prevN1 ) ++u2colIt;
1204 if ( n1 == prevN0 || n1 == prevN1 ) --u2colEnd;
1205 prevN0 = n0; prevN1 = n1;
1207 for ( ; u2colIt != u2colEnd; ++u2colIt )
1208 sweeper.myBndColumns.push_back( & u2colIt->second );
1210 // load node columns inside the bottom FACE
1211 TNode2ColumnMap::iterator bot_column = myBotToColumnMap.begin();
1212 sweeper.myIntColumns.reserve( myBotToColumnMap.size() );
1213 for ( ; bot_column != myBotToColumnMap.end(); ++bot_column )
1214 sweeper.myIntColumns.push_back( & bot_column->second );
1216 myHelper->SetElementsOnShape( true );
1218 // If all "vertical" EDGEs are straight, then all nodes of an internal node column
1219 // are located on a line connecting the top node and the bottom node.
1220 bool isStrightColunm = allVerticalEdgesStraight( thePrism );
1221 if ( !isStrightColunm )
1223 double tol = getSweepTolerance( thePrism );
1224 bool allowHighBndError = !isSimpleBottom( thePrism );
1225 myUseBlock = !sweeper.ComputeNodes( *myHelper, tol, allowHighBndError );
1227 else if ( sweeper.CheckSameZ() )
1229 myUseBlock = !sweeper.ComputeNodesOnStraightSameZ( *myHelper );
1233 myUseBlock = !sweeper.ComputeNodesOnStraight( *myHelper, thePrism.myBottom, thePrism.myTop );
1235 myHelper->SetElementsOnShape( false );
1238 if ( myUseBlock ) // use block approach
1240 // loop on nodes inside the bottom face
1241 Prism_3D::TNode prevBNode;
1242 TNode2ColumnMap::iterator bot_column = myBotToColumnMap.begin();
1243 for ( ; bot_column != myBotToColumnMap.end(); ++bot_column )
1245 const Prism_3D::TNode& tBotNode = bot_column->first; // bottom TNode
1246 if ( tBotNode.GetPositionType() != SMDS_TOP_FACE &&
1247 myBlock.HasNodeColumn( tBotNode.myNode ))
1248 continue; // node is not inside the FACE
1250 // column nodes; middle part of the column are zero pointers
1251 TNodeColumn& column = bot_column->second;
1253 gp_XYZ botParams, topParams;
1254 if ( !tBotNode.HasParams() )
1256 // compute bottom node parameters
1257 gp_XYZ paramHint(-1,-1,-1);
1258 if ( prevBNode.IsNeighbor( tBotNode ))
1259 paramHint = prevBNode.GetParams();
1260 if ( !myBlock.ComputeParameters( tBotNode.GetCoords(), tBotNode.ChangeParams(),
1261 ID_BOT_FACE, paramHint ))
1262 return toSM( error(TCom("Can't compute normalized parameters for node ")
1263 << tBotNode.myNode->GetID() << " on the face #"
1264 << myBlock.SubMesh( ID_BOT_FACE )->GetId() ));
1265 prevBNode = tBotNode;
1267 botParams = topParams = tBotNode.GetParams();
1268 topParams.SetZ( 1 );
1270 // compute top node parameters
1271 if ( column.size() > 2 ) {
1272 gp_Pnt topCoords = gpXYZ( column.back() );
1273 if ( !myBlock.ComputeParameters( topCoords, topParams, ID_TOP_FACE, topParams ))
1274 return toSM( error(TCom("Can't compute normalized parameters ")
1275 << "for node " << column.back()->GetID()
1276 << " on the face #"<< column.back()->getshapeId() ));
1279 else // top nodes are created by projection using parameters
1281 botParams = topParams = tBotNode.GetParams();
1282 topParams.SetZ( 1 );
1285 myShapeXYZ[ ID_BOT_FACE ] = tBotNode.GetCoords();
1286 myShapeXYZ[ ID_TOP_FACE ] = gpXYZ( column.back() );
1289 TNodeColumn::iterator columnNodes = column.begin();
1290 for ( int z = 0; columnNodes != column.end(); ++columnNodes, ++z)
1292 const SMDS_MeshNode* & node = *columnNodes;
1293 if ( node ) continue; // skip bottom or top node
1295 // params of a node to create
1296 double rz = (double) z / (double) ( column.size() - 1 );
1297 gp_XYZ params = botParams * ( 1 - rz ) + topParams * rz;
1299 // set coords on all faces and nodes
1300 const int nbSideFaces = 4;
1301 int sideFaceIDs[nbSideFaces] = { SMESH_Block::ID_Fx0z,
1302 SMESH_Block::ID_Fx1z,
1303 SMESH_Block::ID_F0yz,
1304 SMESH_Block::ID_F1yz };
1305 for ( int iF = 0; iF < nbSideFaces; ++iF )
1306 if ( !setFaceAndEdgesXYZ( sideFaceIDs[ iF ], params, z ))
1309 // compute coords for a new node
1311 if ( !SMESH_Block::ShellPoint( params, myShapeXYZ, coords ))
1312 return toSM( error("Can't compute coordinates by normalized parameters"));
1314 // if ( !meshDS->MeshElements( volumeID ) ||
1315 // meshDS->MeshElements( volumeID )->NbNodes() == 0 )
1316 // pointsToPython(myShapeXYZ);
1317 SHOWYXZ("TOPFacePoint ",myShapeXYZ[ ID_TOP_FACE]);
1318 SHOWYXZ("BOT Node "<< tBotNode.myNode->GetID(),gpXYZ(tBotNode.myNode));
1319 SHOWYXZ("ShellPoint ",coords);
1322 node = meshDS->AddNode( coords.X(), coords.Y(), coords.Z() );
1323 meshDS->SetNodeInVolume( node, volumeID );
1325 if ( _computeCanceled )
1328 } // loop on bottom nodes
1333 SMESHDS_SubMesh* smDS = myBlock.SubMeshDS( ID_BOT_FACE );
1334 if ( !smDS ) return toSM( error(COMPERR_BAD_INPUT_MESH, "Null submesh"));
1336 // loop on bottom mesh faces
1337 vector< const TNodeColumn* > columns;
1338 SMDS_ElemIteratorPtr faceIt = smDS->GetElements();
1339 while ( faceIt->more() )
1341 const SMDS_MeshElement* face = faceIt->next();
1342 if ( !face || face->GetType() != SMDSAbs_Face )
1345 // find node columns for each node
1346 int nbNodes = face->NbCornerNodes();
1347 columns.resize( nbNodes );
1348 for ( int i = 0; i < nbNodes; ++i )
1350 const SMDS_MeshNode* n = face->GetNode( i );
1351 columns[ i ] = NULL;
1353 if ( n->GetPosition()->GetTypeOfPosition() != SMDS_TOP_FACE )
1354 columns[ i ] = myBlock.GetNodeColumn( n );
1356 if ( !columns[ i ] )
1358 TNode2ColumnMap::iterator bot_column = myBotToColumnMap.find( n );
1359 if ( bot_column == myBotToColumnMap.end() )
1360 return toSM( error(TCom("No side nodes found above node ") << n->GetID() ));
1361 columns[ i ] = & bot_column->second;
1365 if ( !AddPrisms( columns, myHelper ))
1366 return toSM( error("Different 'vertical' discretization"));
1368 } // loop on bottom mesh faces
1371 myBotToColumnMap.clear();
1374 // update state of sub-meshes (mostly in order to erase improper errors)
1375 SMESH_subMesh* sm = myHelper->GetMesh()->GetSubMesh( thePrism.myShape3D );
1376 SMESH_subMeshIteratorPtr smIt = sm->getDependsOnIterator(/*includeSelf=*/true);
1377 while ( smIt->more() )
1380 sm->GetComputeError().reset();
1381 sm->ComputeStateEngine( SMESH_subMesh::CHECK_COMPUTE_STATE );
1387 //=======================================================================
1388 //function : computeWalls
1389 //purpose : Compute 2D mesh on walls FACEs of a prism
1390 //=======================================================================
1392 bool StdMeshers_Prism_3D::computeWalls(const Prism_3D::TPrismTopo& thePrism)
1394 SMESH_Mesh* mesh = myHelper->GetMesh();
1395 SMESHDS_Mesh* meshDS = myHelper->GetMeshDS();
1396 DBGOUT( endl << "COMPUTE Prism " << meshDS->ShapeToIndex( thePrism.myShape3D ));
1398 TProjction1dAlgo* projector1D = TProjction1dAlgo::instance( this );
1399 StdMeshers_Quadrangle_2D* quadAlgo = TQuadrangleAlgo::instance( this, myHelper );
1401 // SMESH_HypoFilter hyp1dFilter( SMESH_HypoFilter::IsAlgo(),/*not=*/true);
1402 // hyp1dFilter.And( SMESH_HypoFilter::HasDim( 1 ));
1403 // hyp1dFilter.And( SMESH_HypoFilter::IsMoreLocalThan( thePrism.myShape3D, *mesh ));
1405 // Discretize equally 'vertical' EDGEs
1406 // -----------------------------------
1407 // find source FACE sides for projection: either already computed ones or
1408 // the 'most composite' ones
1409 const size_t nbWalls = thePrism.myWallQuads.size();
1410 vector< int > wgt( nbWalls, 0 ); // "weight" of a wall
1411 for ( size_t iW = 0; iW != nbWalls; ++iW )
1413 Prism_3D::TQuadList::const_iterator quad = thePrism.myWallQuads[iW].begin();
1414 for ( ; quad != thePrism.myWallQuads[iW].end(); ++quad )
1416 StdMeshers_FaceSidePtr lftSide = (*quad)->side[ QUAD_LEFT_SIDE ];
1417 for ( int i = 0; i < lftSide->NbEdges(); ++i )
1420 const TopoDS_Edge& E = lftSide->Edge(i);
1421 if ( mesh->GetSubMesh( E )->IsMeshComputed() )
1424 wgt[ myHelper->WrapIndex( iW+1, nbWalls)] += 10;
1425 wgt[ myHelper->WrapIndex( iW-1, nbWalls)] += 10;
1427 // else if ( mesh->GetHypothesis( E, hyp1dFilter, true )) // local hypothesis!
1431 // in quadratic mesh, pass ignoreMediumNodes to quad sides
1432 if ( myHelper->GetIsQuadratic() )
1434 quad = thePrism.myWallQuads[iW].begin();
1435 for ( ; quad != thePrism.myWallQuads[iW].end(); ++quad )
1436 for ( int i = 0; i < NB_QUAD_SIDES; ++i )
1437 (*quad)->side[ i ].grid->SetIgnoreMediumNodes( true );
1440 multimap< int, int > wgt2quad;
1441 for ( size_t iW = 0; iW != nbWalls; ++iW )
1442 wgt2quad.insert( make_pair( wgt[ iW ], iW ));
1444 // Project 'vertical' EDGEs, from left to right
1445 multimap< int, int >::reverse_iterator w2q = wgt2quad.rbegin();
1446 for ( ; w2q != wgt2quad.rend(); ++w2q )
1448 const int iW = w2q->second;
1449 const Prism_3D::TQuadList& quads = thePrism.myWallQuads[ iW ];
1450 Prism_3D::TQuadList::const_iterator quad = quads.begin();
1451 for ( ; quad != quads.end(); ++quad )
1453 StdMeshers_FaceSidePtr rgtSide = (*quad)->side[ QUAD_RIGHT_SIDE ]; // tgt
1454 StdMeshers_FaceSidePtr lftSide = (*quad)->side[ QUAD_LEFT_SIDE ]; // src
1455 bool swapLeftRight = ( lftSide->NbSegments( /*update=*/true ) == 0 &&
1456 rgtSide->NbSegments( /*update=*/true ) > 0 );
1457 if ( swapLeftRight )
1458 std::swap( lftSide, rgtSide );
1460 // assure that all the source (left) EDGEs are meshed
1461 int nbSrcSegments = 0;
1462 for ( int i = 0; i < lftSide->NbEdges(); ++i )
1464 const TopoDS_Edge& srcE = lftSide->Edge(i);
1465 SMESH_subMesh* srcSM = mesh->GetSubMesh( srcE );
1466 if ( !srcSM->IsMeshComputed() ) {
1467 DBGOUT( "COMPUTE V edge " << srcSM->GetId() );
1468 TopoDS_Edge prpgSrcE = findPropagationSource( srcE );
1469 if ( !prpgSrcE.IsNull() ) {
1470 srcSM->ComputeSubMeshStateEngine( SMESH_subMesh::COMPUTE );
1471 projector1D->myHyp.SetSourceEdge( prpgSrcE );
1472 projector1D->Compute( *mesh, srcE );
1473 srcSM->ComputeStateEngine( SMESH_subMesh::CHECK_COMPUTE_STATE );
1476 srcSM->ComputeSubMeshStateEngine( SMESH_subMesh::COMPUTE );
1477 srcSM->ComputeStateEngine ( SMESH_subMesh::COMPUTE );
1479 if ( !srcSM->IsMeshComputed() )
1480 return toSM( error( "Can't compute 1D mesh" ));
1482 nbSrcSegments += srcSM->GetSubMeshDS()->NbElements();
1484 // check target EDGEs
1485 int nbTgtMeshed = 0, nbTgtSegments = 0;
1486 vector< bool > isTgtEdgeComputed( rgtSide->NbEdges() );
1487 for ( int i = 0; i < rgtSide->NbEdges(); ++i )
1489 const TopoDS_Edge& tgtE = rgtSide->Edge(i);
1490 SMESH_subMesh* tgtSM = mesh->GetSubMesh( tgtE );
1491 if ( !( isTgtEdgeComputed[ i ] = tgtSM->IsMeshComputed() )) {
1492 tgtSM->ComputeSubMeshStateEngine( SMESH_subMesh::COMPUTE );
1493 tgtSM->ComputeStateEngine ( SMESH_subMesh::COMPUTE );
1495 if ( tgtSM->IsMeshComputed() ) {
1497 nbTgtSegments += tgtSM->GetSubMeshDS()->NbElements();
1500 if ( rgtSide->NbEdges() == nbTgtMeshed ) // all tgt EDGEs meshed
1502 if ( nbTgtSegments != nbSrcSegments )
1504 bool badMeshRemoved = false;
1505 // remove just computed segments
1506 for ( int i = 0; i < rgtSide->NbEdges(); ++i )
1507 if ( !isTgtEdgeComputed[ i ])
1509 const TopoDS_Edge& tgtE = rgtSide->Edge(i);
1510 SMESH_subMesh* tgtSM = mesh->GetSubMesh( tgtE );
1511 tgtSM->ComputeStateEngine( SMESH_subMesh::CLEAN );
1512 badMeshRemoved = true;
1515 if ( !badMeshRemoved )
1517 for ( int i = 0; i < lftSide->NbEdges(); ++i )
1518 addBadInputElements( meshDS->MeshElements( lftSide->Edge( i )));
1519 for ( int i = 0; i < rgtSide->NbEdges(); ++i )
1520 addBadInputElements( meshDS->MeshElements( rgtSide->Edge( i )));
1521 return toSM( error( TCom("Different nb of segment on logically vertical edges #")
1522 << shapeID( lftSide->Edge(0) ) << " and #"
1523 << shapeID( rgtSide->Edge(0) ) << ": "
1524 << nbSrcSegments << " != " << nbTgtSegments ));
1527 else // if ( nbTgtSegments == nbSrcSegments )
1532 // Compute 'vertical projection'
1533 if ( nbTgtMeshed == 0 )
1535 // compute nodes on target VERTEXes
1536 const UVPtStructVec& srcNodeStr = lftSide->GetUVPtStruct();
1537 if ( srcNodeStr.size() == 0 )
1538 return toSM( error( TCom("Invalid node positions on edge #") <<
1539 shapeID( lftSide->Edge(0) )));
1540 vector< SMDS_MeshNode* > newNodes( srcNodeStr.size() );
1541 for ( int is2ndV = 0; is2ndV < 2; ++is2ndV )
1543 const TopoDS_Edge& E = rgtSide->Edge( is2ndV ? rgtSide->NbEdges()-1 : 0 );
1544 TopoDS_Vertex v = myHelper->IthVertex( is2ndV, E );
1545 mesh->GetSubMesh( v )->ComputeStateEngine( SMESH_subMesh::COMPUTE );
1546 const SMDS_MeshNode* n = SMESH_Algo::VertexNode( v, meshDS );
1547 newNodes[ is2ndV ? 0 : newNodes.size()-1 ] = (SMDS_MeshNode*) n;
1550 // compute nodes on target EDGEs
1551 DBGOUT( "COMPUTE V edge (proj) " << shapeID( lftSide->Edge(0)));
1552 rgtSide->Reverse(); // direct it same as the lftSide
1553 myHelper->SetElementsOnShape( false ); // myHelper holds the prism shape
1554 TopoDS_Edge tgtEdge;
1555 for ( size_t iN = 1; iN < srcNodeStr.size()-1; ++iN ) // add nodes
1557 gp_Pnt p = rgtSide->Value3d ( srcNodeStr[ iN ].normParam );
1558 double u = rgtSide->Parameter( srcNodeStr[ iN ].normParam, tgtEdge );
1559 newNodes[ iN ] = meshDS->AddNode( p.X(), p.Y(), p.Z() );
1560 meshDS->SetNodeOnEdge( newNodes[ iN ], tgtEdge, u );
1562 for ( size_t iN = 1; iN < srcNodeStr.size(); ++iN ) // add segments
1564 // find an EDGE to set a new segment
1565 std::pair<int, TopAbs_ShapeEnum> id2type =
1566 myHelper->GetMediumPos( newNodes[ iN-1 ], newNodes[ iN ] );
1567 if ( id2type.second != TopAbs_EDGE )
1569 // new nodes are on different EDGEs; put one of them on VERTEX
1570 const int edgeIndex = rgtSide->EdgeIndex( srcNodeStr[ iN-1 ].normParam );
1571 const double vertexParam = rgtSide->LastParameter( edgeIndex );
1572 TopoDS_Vertex vertex = rgtSide->LastVertex( edgeIndex );
1573 const SMDS_MeshNode* vn = SMESH_Algo::VertexNode( vertex, meshDS );
1574 const gp_Pnt p = BRep_Tool::Pnt( vertex );
1575 const int isPrev = ( Abs( srcNodeStr[ iN-1 ].normParam - vertexParam ) <
1576 Abs( srcNodeStr[ iN ].normParam - vertexParam ));
1577 meshDS->UnSetNodeOnShape( newNodes[ iN-isPrev ] );
1578 meshDS->SetNodeOnVertex ( newNodes[ iN-isPrev ], vertex );
1579 meshDS->MoveNode ( newNodes[ iN-isPrev ], p.X(), p.Y(), p.Z() );
1580 id2type.first = newNodes[ iN-(1-isPrev) ]->getshapeId();
1583 SMESH_MeshEditor::TListOfListOfNodes lln( 1, list< const SMDS_MeshNode* >() );
1584 lln.back().push_back ( vn );
1585 lln.back().push_front( newNodes[ iN-isPrev ] ); // to keep
1586 SMESH_MeshEditor( mesh ).MergeNodes( lln );
1589 SMDS_MeshElement* newEdge = myHelper->AddEdge( newNodes[ iN-1 ], newNodes[ iN ] );
1590 meshDS->SetMeshElementOnShape( newEdge, id2type.first );
1592 myHelper->SetElementsOnShape( true );
1593 for ( int i = 0; i < rgtSide->NbEdges(); ++i ) // update state of sub-meshes
1595 const TopoDS_Edge& E = rgtSide->Edge( i );
1596 SMESH_subMesh* tgtSM = mesh->GetSubMesh( E );
1597 tgtSM->ComputeStateEngine( SMESH_subMesh::CHECK_COMPUTE_STATE );
1600 // to continue projection from the just computed side as a source
1601 if ( !swapLeftRight && rgtSide->NbEdges() > 1 && w2q->second == iW )
1603 std::pair<int,int> wgt2quadKeyVal( w2q->first + 1, thePrism.myRightQuadIndex[ iW ]);
1604 wgt2quad.insert( wgt2quadKeyVal ); // it will be skipped by ++w2q
1605 wgt2quad.insert( wgt2quadKeyVal );
1606 w2q = wgt2quad.rbegin();
1611 // HOPE assigned hypotheses are OK, so that equal nb of segments will be generated
1612 //return toSM( error("Partial projection not implemented"));
1614 } // loop on quads of a composite wall side
1615 } // loop on the ordered wall sides
1619 for ( size_t iW = 0; iW != thePrism.myWallQuads.size(); ++iW )
1621 Prism_3D::TQuadList::const_iterator quad = thePrism.myWallQuads[iW].begin();
1622 for ( ; quad != thePrism.myWallQuads[iW].end(); ++quad )
1624 const TopoDS_Face& face = (*quad)->face;
1625 SMESH_subMesh* fSM = mesh->GetSubMesh( face );
1626 if ( ! fSM->IsMeshComputed() )
1628 // Top EDGEs must be projections from the bottom ones
1629 // to compute structured quad mesh on wall FACEs
1630 // ---------------------------------------------------
1631 const TopoDS_Edge& botE = (*quad)->side[ QUAD_BOTTOM_SIDE ].grid->Edge(0);
1632 const TopoDS_Edge& topE = (*quad)->side[ QUAD_TOP_SIDE ].grid->Edge(0);
1633 SMESH_subMesh* botSM = mesh->GetSubMesh( botE );
1634 SMESH_subMesh* topSM = mesh->GetSubMesh( topE );
1635 SMESH_subMesh* srcSM = botSM;
1636 SMESH_subMesh* tgtSM = topSM;
1637 srcSM->ComputeStateEngine( SMESH_subMesh::CHECK_COMPUTE_STATE );
1638 tgtSM->ComputeStateEngine( SMESH_subMesh::CHECK_COMPUTE_STATE );
1639 if ( !srcSM->IsMeshComputed() && tgtSM->IsMeshComputed() )
1640 std::swap( srcSM, tgtSM );
1642 if ( !srcSM->IsMeshComputed() )
1644 DBGOUT( "COMPUTE H edge " << srcSM->GetId());
1645 srcSM->ComputeSubMeshStateEngine( SMESH_subMesh::COMPUTE ); // nodes on VERTEXes
1646 srcSM->ComputeStateEngine( SMESH_subMesh::COMPUTE ); // segments on the EDGE
1649 if ( tgtSM->IsMeshComputed() &&
1650 tgtSM->GetSubMeshDS()->NbNodes() != srcSM->GetSubMeshDS()->NbNodes() )
1652 // the top EDGE is computed differently than the bottom one,
1653 // try to clear a wrong mesh
1654 bool isAdjFaceMeshed = false;
1655 PShapeIteratorPtr fIt = myHelper->GetAncestors( tgtSM->GetSubShape(),
1656 *mesh, TopAbs_FACE );
1657 while ( const TopoDS_Shape* f = fIt->next() )
1658 if (( isAdjFaceMeshed = mesh->GetSubMesh( *f )->IsMeshComputed() ))
1660 if ( isAdjFaceMeshed )
1661 return toSM( error( TCom("Different nb of segment on logically horizontal edges #")
1662 << shapeID( botE ) << " and #"
1663 << shapeID( topE ) << ": "
1664 << tgtSM->GetSubMeshDS()->NbElements() << " != "
1665 << srcSM->GetSubMeshDS()->NbElements() ));
1666 tgtSM->ComputeStateEngine( SMESH_subMesh::CLEAN );
1668 if ( !tgtSM->IsMeshComputed() )
1670 // compute nodes on VERTEXes
1671 SMESH_subMeshIteratorPtr smIt = tgtSM->getDependsOnIterator(/*includeSelf=*/false);
1672 while ( smIt->more() )
1673 smIt->next()->ComputeStateEngine( SMESH_subMesh::COMPUTE );
1675 DBGOUT( "COMPUTE H edge (proj) " << tgtSM->GetId());
1676 projector1D->myHyp.SetSourceEdge( TopoDS::Edge( srcSM->GetSubShape() ));
1677 projector1D->InitComputeError();
1678 bool ok = projector1D->Compute( *mesh, tgtSM->GetSubShape() );
1681 SMESH_ComputeErrorPtr err = projector1D->GetComputeError();
1682 if ( err->IsOK() ) err->myName = COMPERR_ALGO_FAILED;
1683 tgtSM->GetComputeError() = err;
1687 tgtSM->ComputeStateEngine( SMESH_subMesh::CHECK_COMPUTE_STATE );
1690 // Compute quad mesh on wall FACEs
1691 // -------------------------------
1693 // make all EDGES meshed
1694 fSM->ComputeSubMeshStateEngine( SMESH_subMesh::COMPUTE );
1695 if ( !fSM->SubMeshesComputed() )
1696 return toSM( error( COMPERR_BAD_INPUT_MESH,
1697 "Not all edges have valid algorithm and hypothesis"));
1699 quadAlgo->InitComputeError();
1700 DBGOUT( "COMPUTE Quad face " << fSM->GetId());
1701 bool ok = quadAlgo->Compute( *mesh, face );
1702 fSM->GetComputeError() = quadAlgo->GetComputeError();
1705 fSM->ComputeStateEngine( SMESH_subMesh::CHECK_COMPUTE_STATE );
1707 if ( myHelper->GetIsQuadratic() )
1709 // fill myHelper with medium nodes built by quadAlgo
1710 SMDS_ElemIteratorPtr fIt = fSM->GetSubMeshDS()->GetElements();
1711 while ( fIt->more() )
1712 myHelper->AddTLinks( dynamic_cast<const SMDS_MeshFace*>( fIt->next() ));
1720 //=======================================================================
1722 * \brief Returns a source EDGE of propagation to a given EDGE
1724 //=======================================================================
1726 TopoDS_Edge StdMeshers_Prism_3D::findPropagationSource( const TopoDS_Edge& E )
1728 if ( myPropagChains )
1729 for ( size_t i = 0; !myPropagChains[i].IsEmpty(); ++i )
1730 if ( myPropagChains[i].Contains( E ))
1731 return TopoDS::Edge( myPropagChains[i].FindKey( 1 ));
1733 return TopoDS_Edge();
1736 //=======================================================================
1737 //function : Evaluate
1739 //=======================================================================
1741 bool StdMeshers_Prism_3D::Evaluate(SMESH_Mesh& theMesh,
1742 const TopoDS_Shape& theShape,
1743 MapShapeNbElems& aResMap)
1745 if ( theShape.ShapeType() == TopAbs_COMPOUND )
1748 for ( TopoDS_Iterator it( theShape ); it.More(); it.Next() )
1749 ok &= Evaluate( theMesh, it.Value(), aResMap );
1752 SMESH_MesherHelper helper( theMesh );
1754 myHelper->SetSubShape( theShape );
1756 // find face contains only triangles
1757 vector < SMESH_subMesh * >meshFaces;
1758 TopTools_SequenceOfShape aFaces;
1759 int NumBase = 0, i = 0, NbQFs = 0;
1760 for (TopExp_Explorer exp(theShape, TopAbs_FACE); exp.More(); exp.Next()) {
1762 aFaces.Append(exp.Current());
1763 SMESH_subMesh *aSubMesh = theMesh.GetSubMesh(exp.Current());
1764 meshFaces.push_back(aSubMesh);
1765 MapShapeNbElemsItr anIt = aResMap.find(meshFaces[i-1]);
1766 if( anIt==aResMap.end() )
1767 return toSM( error( "Submesh can not be evaluated"));
1769 std::vector<int> aVec = (*anIt).second;
1770 int nbtri = Max(aVec[SMDSEntity_Triangle],aVec[SMDSEntity_Quad_Triangle]);
1771 int nbqua = Max(aVec[SMDSEntity_Quadrangle],aVec[SMDSEntity_Quad_Quadrangle]);
1772 if( nbtri==0 && nbqua>0 ) {
1781 std::vector<int> aResVec(SMDSEntity_Last);
1782 for(int i=SMDSEntity_Node; i<SMDSEntity_Last; i++) aResVec[i] = 0;
1783 SMESH_subMesh * sm = theMesh.GetSubMesh(theShape);
1784 aResMap.insert(std::make_pair(sm,aResVec));
1785 return toSM( error( "Submesh can not be evaluated" ));
1788 if(NumBase==0) NumBase = 1; // only quads => set 1 faces as base
1790 // find number of 1d elems for base face
1792 TopTools_MapOfShape Edges1;
1793 for (TopExp_Explorer exp(aFaces.Value(NumBase), TopAbs_EDGE); exp.More(); exp.Next()) {
1794 Edges1.Add(exp.Current());
1795 SMESH_subMesh *sm = theMesh.GetSubMesh(exp.Current());
1797 MapShapeNbElemsItr anIt = aResMap.find(sm);
1798 if( anIt == aResMap.end() ) continue;
1799 std::vector<int> aVec = (*anIt).second;
1800 nb1d += Max(aVec[SMDSEntity_Edge],aVec[SMDSEntity_Quad_Edge]);
1803 // find face opposite to base face
1805 for(i=1; i<=6; i++) {
1806 if(i==NumBase) continue;
1807 bool IsOpposite = true;
1808 for(TopExp_Explorer exp(aFaces.Value(i), TopAbs_EDGE); exp.More(); exp.Next()) {
1809 if( Edges1.Contains(exp.Current()) ) {
1819 // find number of 2d elems on side faces
1821 for(i=1; i<=6; i++) {
1822 if( i==OppNum || i==NumBase ) continue;
1823 MapShapeNbElemsItr anIt = aResMap.find( meshFaces[i-1] );
1824 if( anIt == aResMap.end() ) continue;
1825 std::vector<int> aVec = (*anIt).second;
1826 nb2d += Max(aVec[SMDSEntity_Quadrangle],aVec[SMDSEntity_Quad_Quadrangle]);
1829 MapShapeNbElemsItr anIt = aResMap.find( meshFaces[NumBase-1] );
1830 std::vector<int> aVec = (*anIt).second;
1831 bool IsQuadratic = (aVec[SMDSEntity_Quad_Triangle]>aVec[SMDSEntity_Triangle]) ||
1832 (aVec[SMDSEntity_Quad_Quadrangle]>aVec[SMDSEntity_Quadrangle]);
1833 int nb2d_face0_3 = Max(aVec[SMDSEntity_Triangle],aVec[SMDSEntity_Quad_Triangle]);
1834 int nb2d_face0_4 = Max(aVec[SMDSEntity_Quadrangle],aVec[SMDSEntity_Quad_Quadrangle]);
1835 int nb0d_face0 = aVec[SMDSEntity_Node];
1836 int nb1d_face0_int = ( nb2d_face0_3*3 + nb2d_face0_4*4 - nb1d ) / 2;
1838 std::vector<int> aResVec(SMDSEntity_Last);
1839 for(int i=SMDSEntity_Node; i<SMDSEntity_Last; i++) aResVec[i] = 0;
1841 aResVec[SMDSEntity_Quad_Penta] = nb2d_face0_3 * ( nb2d/nb1d );
1842 aResVec[SMDSEntity_Quad_Hexa] = nb2d_face0_4 * ( nb2d/nb1d );
1843 aResVec[SMDSEntity_Node] = nb0d_face0 * ( 2*nb2d/nb1d - 1 ) - nb1d_face0_int * nb2d/nb1d;
1846 aResVec[SMDSEntity_Node] = nb0d_face0 * ( nb2d/nb1d - 1 );
1847 aResVec[SMDSEntity_Penta] = nb2d_face0_3 * ( nb2d/nb1d );
1848 aResVec[SMDSEntity_Hexa] = nb2d_face0_4 * ( nb2d/nb1d );
1850 SMESH_subMesh * sm = theMesh.GetSubMesh(theShape);
1851 aResMap.insert(std::make_pair(sm,aResVec));
1856 //================================================================================
1858 * \brief Create prisms
1859 * \param columns - columns of nodes generated from nodes of a mesh face
1860 * \param helper - helper initialized by mesh and shape to add prisms to
1862 //================================================================================
1864 bool StdMeshers_Prism_3D::AddPrisms( vector<const TNodeColumn*> & columns,
1865 SMESH_MesherHelper* helper)
1867 size_t nbNodes = columns.size();
1868 size_t nbZ = columns[0]->size();
1869 if ( nbZ < 2 ) return false;
1870 for ( size_t i = 1; i < nbNodes; ++i )
1871 if ( columns[i]->size() != nbZ )
1874 // find out orientation
1875 bool isForward = true;
1876 SMDS_VolumeTool vTool;
1878 switch ( nbNodes ) {
1880 SMDS_VolumeOfNodes tmpPenta ( (*columns[0])[z-1], // bottom
1883 (*columns[0])[z], // top
1886 vTool.Set( &tmpPenta );
1887 isForward = vTool.IsForward();
1891 SMDS_VolumeOfNodes tmpHex( (*columns[0])[z-1], (*columns[1])[z-1], // bottom
1892 (*columns[2])[z-1], (*columns[3])[z-1],
1893 (*columns[0])[z], (*columns[1])[z], // top
1894 (*columns[2])[z], (*columns[3])[z] );
1895 vTool.Set( &tmpHex );
1896 isForward = vTool.IsForward();
1900 const int di = (nbNodes+1) / 3;
1901 SMDS_VolumeOfNodes tmpVol ( (*columns[0] )[z-1],
1902 (*columns[di] )[z-1],
1903 (*columns[2*di])[z-1],
1906 (*columns[2*di])[z] );
1907 vTool.Set( &tmpVol );
1908 isForward = vTool.IsForward();
1911 // vertical loop on columns
1913 helper->SetElementsOnShape( true );
1915 switch ( nbNodes ) {
1917 case 3: { // ---------- pentahedra
1918 const int i1 = isForward ? 1 : 2;
1919 const int i2 = isForward ? 2 : 1;
1920 for ( z = 1; z < nbZ; ++z )
1921 helper->AddVolume( (*columns[0 ])[z-1], // bottom
1922 (*columns[i1])[z-1],
1923 (*columns[i2])[z-1],
1924 (*columns[0 ])[z], // top
1926 (*columns[i2])[z] );
1929 case 4: { // ---------- hexahedra
1930 const int i1 = isForward ? 1 : 3;
1931 const int i3 = isForward ? 3 : 1;
1932 for ( z = 1; z < nbZ; ++z )
1933 helper->AddVolume( (*columns[0])[z-1], (*columns[i1])[z-1], // bottom
1934 (*columns[2])[z-1], (*columns[i3])[z-1],
1935 (*columns[0])[z], (*columns[i1])[z], // top
1936 (*columns[2])[z], (*columns[i3])[z] );
1939 case 6: { // ---------- octahedra
1940 const int iBase1 = isForward ? -1 : 0;
1941 const int iBase2 = isForward ? 0 :-1;
1942 for ( z = 1; z < nbZ; ++z )
1943 helper->AddVolume( (*columns[0])[z+iBase1], (*columns[1])[z+iBase1], // bottom or top
1944 (*columns[2])[z+iBase1], (*columns[3])[z+iBase1],
1945 (*columns[4])[z+iBase1], (*columns[5])[z+iBase1],
1946 (*columns[0])[z+iBase2], (*columns[1])[z+iBase2], // top or bottom
1947 (*columns[2])[z+iBase2], (*columns[3])[z+iBase2],
1948 (*columns[4])[z+iBase2], (*columns[5])[z+iBase2] );
1951 default: // ---------- polyhedra
1952 vector<int> quantities( 2 + nbNodes, 4 );
1953 quantities[0] = quantities[1] = nbNodes;
1954 columns.resize( nbNodes + 1 );
1955 columns[ nbNodes ] = columns[ 0 ];
1956 const int i1 = isForward ? 1 : 3;
1957 const int i3 = isForward ? 3 : 1;
1958 const int iBase1 = isForward ? -1 : 0;
1959 const int iBase2 = isForward ? 0 :-1;
1960 vector<const SMDS_MeshNode*> nodes( 2*nbNodes + 4*nbNodes);
1961 for ( z = 1; z < nbZ; ++z )
1963 for ( size_t i = 0; i < nbNodes; ++i ) {
1964 nodes[ i ] = (*columns[ i ])[z+iBase1]; // bottom or top
1965 nodes[ 2*nbNodes-i-1 ] = (*columns[ i ])[z+iBase2]; // top or bottom
1967 int di = 2*nbNodes + 4*i;
1968 nodes[ di+0 ] = (*columns[i ])[z ];
1969 nodes[ di+i1] = (*columns[i+1])[z ];
1970 nodes[ di+2 ] = (*columns[i+1])[z-1];
1971 nodes[ di+i3] = (*columns[i ])[z-1];
1973 helper->AddPolyhedralVolume( nodes, quantities );
1976 } // switch ( nbNodes )
1981 //================================================================================
1983 * \brief Find correspondence between bottom and top nodes
1984 * If elements on the bottom and top faces are topologically different,
1985 * and projection is possible and allowed, perform the projection
1986 * \retval bool - is a success or not
1988 //================================================================================
1990 bool StdMeshers_Prism_3D::assocOrProjBottom2Top( const gp_Trsf & bottomToTopTrsf,
1991 const Prism_3D::TPrismTopo& thePrism)
1993 SMESH_subMesh * botSM = myHelper->GetMesh()->GetSubMesh( thePrism.myBottom );
1994 SMESH_subMesh * topSM = myHelper->GetMesh()->GetSubMesh( thePrism.myTop );
1996 SMESHDS_SubMesh * botSMDS = botSM->GetSubMeshDS();
1997 SMESHDS_SubMesh * topSMDS = topSM->GetSubMeshDS();
1999 if ( !botSMDS || botSMDS->NbElements() == 0 )
2001 _gen->Compute( *myHelper->GetMesh(), botSM->GetSubShape(), /*aShapeOnly=*/true );
2002 botSMDS = botSM->GetSubMeshDS();
2003 if ( !botSMDS || botSMDS->NbElements() == 0 )
2004 return toSM( error(TCom("No elements on face #") << botSM->GetId() ));
2007 bool needProject = !topSM->IsMeshComputed();
2008 if ( !needProject &&
2009 (botSMDS->NbElements() != topSMDS->NbElements() ||
2010 botSMDS->NbNodes() != topSMDS->NbNodes()))
2012 MESSAGE("nb elem bot " << botSMDS->NbElements() <<
2013 " top " << ( topSMDS ? topSMDS->NbElements() : 0 ));
2014 MESSAGE("nb node bot " << botSMDS->NbNodes() <<
2015 " top " << ( topSMDS ? topSMDS->NbNodes() : 0 ));
2016 return toSM( error(TCom("Mesh on faces #") << botSM->GetId()
2017 <<" and #"<< topSM->GetId() << " seems different" ));
2020 if ( 0/*needProject && !myProjectTriangles*/ )
2021 return toSM( error(TCom("Mesh on faces #") << botSM->GetId()
2022 <<" and #"<< topSM->GetId() << " seems different" ));
2023 ///RETURN_BAD_RESULT("Need to project but not allowed");
2025 NSProjUtils::TNodeNodeMap n2nMap;
2026 const NSProjUtils::TNodeNodeMap* n2nMapPtr = & n2nMap;
2029 if ( !projectBottomToTop( bottomToTopTrsf, thePrism ))
2031 n2nMapPtr = & TProjction2dAlgo::instance( this )->GetNodesMap();
2034 if ( !n2nMapPtr || (int) n2nMapPtr->size() < botSMDS->NbNodes() )
2036 // associate top and bottom faces
2037 NSProjUtils::TShapeShapeMap shape2ShapeMap;
2038 const bool sameTopo =
2039 NSProjUtils::FindSubShapeAssociation( thePrism.myBottom, myHelper->GetMesh(),
2040 thePrism.myTop, myHelper->GetMesh(),
2043 for ( size_t iQ = 0; iQ < thePrism.myWallQuads.size(); ++iQ )
2045 const Prism_3D::TQuadList& quadList = thePrism.myWallQuads[iQ];
2046 StdMeshers_FaceSidePtr botSide = quadList.front()->side[ QUAD_BOTTOM_SIDE ];
2047 StdMeshers_FaceSidePtr topSide = quadList.back ()->side[ QUAD_TOP_SIDE ];
2048 if ( botSide->NbEdges() == topSide->NbEdges() )
2050 for ( int iE = 0; iE < botSide->NbEdges(); ++iE )
2052 NSProjUtils::InsertAssociation( botSide->Edge( iE ),
2053 topSide->Edge( iE ), shape2ShapeMap );
2054 NSProjUtils::InsertAssociation( myHelper->IthVertex( 0, botSide->Edge( iE )),
2055 myHelper->IthVertex( 0, topSide->Edge( iE )),
2061 TopoDS_Vertex vb, vt;
2062 StdMeshers_FaceSidePtr sideB, sideT;
2063 vb = myHelper->IthVertex( 0, botSide->Edge( 0 ));
2064 vt = myHelper->IthVertex( 0, topSide->Edge( 0 ));
2065 sideB = quadList.front()->side[ QUAD_LEFT_SIDE ];
2066 sideT = quadList.back ()->side[ QUAD_LEFT_SIDE ];
2067 if ( vb.IsSame( sideB->FirstVertex() ) &&
2068 vt.IsSame( sideT->LastVertex() ))
2070 NSProjUtils::InsertAssociation( botSide->Edge( 0 ),
2071 topSide->Edge( 0 ), shape2ShapeMap );
2072 NSProjUtils::InsertAssociation( vb, vt, shape2ShapeMap );
2074 vb = myHelper->IthVertex( 1, botSide->Edge( botSide->NbEdges()-1 ));
2075 vt = myHelper->IthVertex( 1, topSide->Edge( topSide->NbEdges()-1 ));
2076 sideB = quadList.front()->side[ QUAD_RIGHT_SIDE ];
2077 sideT = quadList.back ()->side[ QUAD_RIGHT_SIDE ];
2078 if ( vb.IsSame( sideB->FirstVertex() ) &&
2079 vt.IsSame( sideT->LastVertex() ))
2081 NSProjUtils::InsertAssociation( botSide->Edge( botSide->NbEdges()-1 ),
2082 topSide->Edge( topSide->NbEdges()-1 ),
2084 NSProjUtils::InsertAssociation( vb, vt, shape2ShapeMap );
2089 // Find matching nodes of top and bottom faces
2090 n2nMapPtr = & n2nMap;
2091 if ( ! NSProjUtils::FindMatchingNodesOnFaces( thePrism.myBottom, myHelper->GetMesh(),
2092 thePrism.myTop, myHelper->GetMesh(),
2093 shape2ShapeMap, n2nMap ))
2096 return toSM( error(TCom("Mesh on faces #") << botSM->GetId()
2097 <<" and #"<< topSM->GetId() << " seems different" ));
2099 return toSM( error(TCom("Topology of faces #") << botSM->GetId()
2100 <<" and #"<< topSM->GetId() << " seems different" ));
2104 // Fill myBotToColumnMap
2106 int zSize = myBlock.VerticalSize();
2107 TNodeNodeMap::const_iterator bN_tN = n2nMapPtr->begin();
2108 for ( ; bN_tN != n2nMapPtr->end(); ++bN_tN )
2110 const SMDS_MeshNode* botNode = bN_tN->first;
2111 const SMDS_MeshNode* topNode = bN_tN->second;
2112 if ( botNode->GetPosition()->GetTypeOfPosition() != SMDS_TOP_FACE &&
2113 myBlock.HasNodeColumn( botNode ))
2114 continue; // wall columns are contained in myBlock
2115 // create node column
2116 Prism_3D::TNode bN( botNode );
2117 TNode2ColumnMap::iterator bN_col =
2118 myBotToColumnMap.insert( make_pair ( bN, TNodeColumn() )).first;
2119 TNodeColumn & column = bN_col->second;
2120 column.resize( zSize );
2121 column.front() = botNode;
2122 column.back() = topNode;
2127 //================================================================================
2129 * \brief Remove faces from the top face and re-create them by projection from the bottom
2130 * \retval bool - a success or not
2132 //================================================================================
2134 bool StdMeshers_Prism_3D::projectBottomToTop( const gp_Trsf & bottomToTopTrsf,
2135 const Prism_3D::TPrismTopo& thePrism )
2137 if ( project2dMesh( thePrism.myBottom, thePrism.myTop ))
2141 NSProjUtils::TNodeNodeMap& n2nMap =
2142 (NSProjUtils::TNodeNodeMap&) TProjction2dAlgo::instance( this )->GetNodesMap();
2147 SMESHDS_Mesh* meshDS = myHelper->GetMeshDS();
2148 SMESH_subMesh * botSM = myHelper->GetMesh()->GetSubMesh( thePrism.myBottom );
2149 SMESH_subMesh * topSM = myHelper->GetMesh()->GetSubMesh( thePrism.myTop );
2151 SMESHDS_SubMesh * botSMDS = botSM->GetSubMeshDS();
2152 SMESHDS_SubMesh * topSMDS = topSM->GetSubMeshDS();
2154 if ( topSMDS && topSMDS->NbElements() > 0 )
2156 //topSM->ComputeStateEngine( SMESH_subMesh::CLEAN ); -- avoid propagation of events
2157 for ( SMDS_ElemIteratorPtr eIt = topSMDS->GetElements(); eIt->more(); )
2158 meshDS->RemoveFreeElement( eIt->next(), topSMDS, /*fromGroups=*/false );
2159 for ( SMDS_NodeIteratorPtr nIt = topSMDS->GetNodes(); nIt->more(); )
2160 meshDS->RemoveFreeNode( nIt->next(), topSMDS, /*fromGroups=*/false );
2163 const TopoDS_Face& botFace = thePrism.myBottom; // oriented within
2164 const TopoDS_Face& topFace = thePrism.myTop; // the 3D SHAPE
2165 int topFaceID = meshDS->ShapeToIndex( thePrism.myTop );
2167 SMESH_MesherHelper botHelper( *myHelper->GetMesh() );
2168 botHelper.SetSubShape( botFace );
2169 botHelper.ToFixNodeParameters( true );
2171 SMESH_MesherHelper topHelper( *myHelper->GetMesh() );
2172 topHelper.SetSubShape( topFace );
2173 topHelper.ToFixNodeParameters( true );
2174 double distXYZ[4], fixTol = 10 * topHelper.MaxTolerance( topFace );
2176 // Fill myBotToColumnMap
2178 int zSize = myBlock.VerticalSize();
2179 Prism_3D::TNode prevTNode;
2180 SMDS_NodeIteratorPtr nIt = botSMDS->GetNodes();
2181 while ( nIt->more() )
2183 const SMDS_MeshNode* botNode = nIt->next();
2184 const SMDS_MeshNode* topNode = 0;
2185 if ( botNode->GetPosition()->GetTypeOfPosition() != SMDS_TOP_FACE )
2186 continue; // strange
2188 Prism_3D::TNode bN( botNode );
2189 if ( bottomToTopTrsf.Form() == gp_Identity )
2191 // compute bottom node params
2192 gp_XYZ paramHint(-1,-1,-1);
2193 if ( prevTNode.IsNeighbor( bN ))
2195 paramHint = prevTNode.GetParams();
2196 // double tol = 1e-2 * ( prevTNode.GetCoords() - bN.GetCoords() ).Modulus();
2197 // myBlock.SetTolerance( Min( myBlock.GetTolerance(), tol ));
2199 if ( !myBlock.ComputeParameters( bN.GetCoords(), bN.ChangeParams(),
2200 ID_BOT_FACE, paramHint ))
2201 return toSM( error(TCom("Can't compute normalized parameters for node ")
2202 << botNode->GetID() << " on the face #"<< botSM->GetId() ));
2204 // compute top node coords
2205 gp_XYZ topXYZ; gp_XY topUV;
2206 if ( !myBlock.FacePoint( ID_TOP_FACE, bN.GetParams(), topXYZ ) ||
2207 !myBlock.FaceUV ( ID_TOP_FACE, bN.GetParams(), topUV ))
2208 return toSM( error(TCom("Can't compute coordinates "
2209 "by normalized parameters on the face #")<< topSM->GetId() ));
2210 topNode = meshDS->AddNode( topXYZ.X(),topXYZ.Y(),topXYZ.Z() );
2211 meshDS->SetNodeOnFace( topNode, topFaceID, topUV.X(), topUV.Y() );
2213 else // use bottomToTopTrsf
2215 gp_XYZ coords = bN.GetCoords();
2216 bottomToTopTrsf.Transforms( coords );
2217 topNode = meshDS->AddNode( coords.X(), coords.Y(), coords.Z() );
2218 gp_XY topUV = botHelper.GetNodeUV( botFace, botNode, 0, &checkUV );
2219 meshDS->SetNodeOnFace( topNode, topFaceID, topUV.X(), topUV.Y() );
2221 if ( topHelper.CheckNodeUV( topFace, topNode, topUV, fixTol, /*force=*/false, distXYZ ) &&
2222 distXYZ[0] > fixTol && distXYZ[0] < fixTol * 1e+3 )
2223 meshDS->MoveNode( topNode, distXYZ[1], distXYZ[2], distXYZ[3] ); // transform can be inaccurate
2225 // create node column
2226 TNode2ColumnMap::iterator bN_col =
2227 myBotToColumnMap.insert( make_pair ( bN, TNodeColumn() )).first;
2228 TNodeColumn & column = bN_col->second;
2229 column.resize( zSize );
2230 column.front() = botNode;
2231 column.back() = topNode;
2233 n2nMap.insert( n2nMap.end(), make_pair( botNode, topNode ));
2235 if ( _computeCanceled )
2236 return toSM( error( SMESH_ComputeError::New(COMPERR_CANCELED)));
2241 const bool oldSetElemsOnShape = myHelper->SetElementsOnShape( false );
2243 // care of orientation;
2244 // if the bottom faces is orienetd OK then top faces must be reversed
2245 bool reverseTop = true;
2246 if ( myHelper->NbAncestors( botFace, *myBlock.Mesh(), TopAbs_SOLID ) > 1 )
2247 reverseTop = ! myHelper->IsReversedSubMesh( botFace );
2248 int iFrw, iRev, *iPtr = &( reverseTop ? iRev : iFrw );
2250 // loop on bottom mesh faces
2251 SMDS_ElemIteratorPtr faceIt = botSMDS->GetElements();
2252 vector< const SMDS_MeshNode* > nodes;
2253 while ( faceIt->more() )
2255 const SMDS_MeshElement* face = faceIt->next();
2256 if ( !face || face->GetType() != SMDSAbs_Face )
2259 // find top node in columns for each bottom node
2260 int nbNodes = face->NbCornerNodes();
2261 nodes.resize( nbNodes );
2262 for ( iFrw = 0, iRev = nbNodes-1; iFrw < nbNodes; ++iFrw, --iRev )
2264 const SMDS_MeshNode* n = face->GetNode( *iPtr );
2265 if ( n->GetPosition()->GetTypeOfPosition() == SMDS_TOP_FACE ) {
2266 TNode2ColumnMap::iterator bot_column = myBotToColumnMap.find( n );
2267 if ( bot_column == myBotToColumnMap.end() )
2268 return toSM( error(TCom("No nodes found above node ") << n->GetID() ));
2269 nodes[ iFrw ] = bot_column->second.back();
2272 const TNodeColumn* column = myBlock.GetNodeColumn( n );
2274 return toSM( error(TCom("No side nodes found above node ") << n->GetID() ));
2275 nodes[ iFrw ] = column->back();
2278 SMDS_MeshElement* newFace = 0;
2279 switch ( nbNodes ) {
2282 newFace = myHelper->AddFace(nodes[0], nodes[1], nodes[2]);
2286 newFace = myHelper->AddFace( nodes[0], nodes[1], nodes[2], nodes[3] );
2290 newFace = meshDS->AddPolygonalFace( nodes );
2293 meshDS->SetMeshElementOnShape( newFace, topFaceID );
2296 myHelper->SetElementsOnShape( oldSetElemsOnShape );
2298 // Check the projected mesh
2300 if ( thePrism.myNbEdgesInWires.size() > 1 && // there are holes
2301 topHelper.IsDistorted2D( topSM, /*checkUV=*/false ))
2303 SMESH_MeshEditor editor( topHelper.GetMesh() );
2305 // smooth in 2D or 3D?
2306 TopLoc_Location loc;
2307 Handle(Geom_Surface) surface = BRep_Tool::Surface( topFace, loc );
2308 bool isPlanar = GeomLib_IsPlanarSurface( surface ).IsPlanar();
2310 set<const SMDS_MeshNode*> fixedNodes;
2311 TIDSortedElemSet faces;
2312 for ( faceIt = topSMDS->GetElements(); faceIt->more(); )
2313 faces.insert( faces.end(), faceIt->next() );
2316 for ( int isCentroidal = 0; isCentroidal < 2; ++isCentroidal )
2318 SMESH_MeshEditor::SmoothMethod algo =
2319 isCentroidal ? SMESH_MeshEditor::CENTROIDAL : SMESH_MeshEditor::LAPLACIAN;
2321 int nbAttempts = isCentroidal ? 1 : 10;
2322 for ( int iAttemp = 0; iAttemp < nbAttempts; ++iAttemp )
2324 TIDSortedElemSet workFaces = faces;
2327 editor.Smooth( workFaces, fixedNodes, algo, /*nbIterations=*/ 10,
2328 /*theTgtAspectRatio=*/1.0, /*the2D=*/!isPlanar);
2330 if (( isOk = !topHelper.IsDistorted2D( topSM, /*checkUV=*/true )) &&
2336 return toSM( error( TCom("Projection from face #") << botSM->GetId()
2337 << " to face #" << topSM->GetId()
2338 << " failed: inverted elements created"));
2341 TProjction2dAlgo::instance( this )->SetEventListener( topSM );
2346 //=======================================================================
2347 //function : getSweepTolerance
2348 //purpose : Compute tolerance to pass to StdMeshers_Sweeper
2349 //=======================================================================
2351 double StdMeshers_Prism_3D::getSweepTolerance( const Prism_3D::TPrismTopo& thePrism )
2353 SMESHDS_Mesh* meshDS = myHelper->GetMeshDS();
2354 SMESHDS_SubMesh * sm[2] = { meshDS->MeshElements( thePrism.myBottom ),
2355 meshDS->MeshElements( thePrism.myTop ) };
2356 double minDist = 1e100;
2358 vector< SMESH_TNodeXYZ > nodes;
2359 for ( int iSM = 0; iSM < 2; ++iSM )
2361 if ( !sm[ iSM ]) continue;
2363 SMDS_ElemIteratorPtr fIt = sm[ iSM ]->GetElements();
2364 while ( fIt->more() )
2366 const SMDS_MeshElement* face = fIt->next();
2367 const int nbNodes = face->NbCornerNodes();
2368 SMDS_ElemIteratorPtr nIt = face->nodesIterator();
2370 nodes.resize( nbNodes + 1 );
2371 for ( int iN = 0; iN < nbNodes; ++iN )
2372 nodes[ iN ] = nIt->next();
2373 nodes.back() = nodes[0];
2377 for ( int iN = 0; iN < nbNodes; ++iN )
2379 if ( nodes[ iN ]._node->GetPosition()->GetDim() < 2 &&
2380 nodes[ iN+1 ]._node->GetPosition()->GetDim() < 2 )
2382 // it's a boundary link; measure distance of other
2383 // nodes to this link
2384 gp_XYZ linkDir = nodes[ iN ] - nodes[ iN+1 ];
2385 double linkLen = linkDir.Modulus();
2386 bool isDegen = ( linkLen < numeric_limits<double>::min() );
2387 if ( !isDegen ) linkDir /= linkLen;
2388 for ( int iN2 = 0; iN2 < nbNodes; ++iN2 ) // loop on other nodes
2390 if ( nodes[ iN2 ] == nodes[ iN ] ||
2391 nodes[ iN2 ] == nodes[ iN+1 ]) continue;
2394 dist2 = ( nodes[ iN ] - nodes[ iN2 ]).SquareModulus();
2398 dist2 = linkDir.CrossSquareMagnitude( nodes[ iN ] - nodes[ iN2 ]);
2400 if ( dist2 > numeric_limits<double>::min() )
2401 minDist = Min ( minDist, dist2 );
2404 // measure length link
2405 else if ( nodes[ iN ]._node < nodes[ iN+1 ]._node ) // not to measure same link twice
2407 dist2 = ( nodes[ iN ] - nodes[ iN+1 ]).SquareModulus();
2408 if ( dist2 > numeric_limits<double>::min() )
2409 minDist = Min ( minDist, dist2 );
2414 return 0.1 * Sqrt ( minDist );
2417 //=======================================================================
2418 //function : isSimpleQuad
2419 //purpose : check if the bottom FACE is meshable with nice qudrangles,
2420 // if so the block aproach can work rather fast.
2421 // This is a temporary mean caused by problems in StdMeshers_Sweeper
2422 //=======================================================================
2424 bool StdMeshers_Prism_3D::isSimpleBottom( const Prism_3D::TPrismTopo& thePrism )
2426 if ( thePrism.myNbEdgesInWires.front() != 4 )
2429 // analyse angles between edges
2430 double nbConcaveAng = 0, nbConvexAng = 0;
2431 TopoDS_Face reverseBottom = TopoDS::Face( thePrism.myBottom.Reversed() ); // see initPrism()
2432 TopoDS_Vertex commonV;
2433 const list< TopoDS_Edge >& botEdges = thePrism.myBottomEdges;
2434 list< TopoDS_Edge >::const_iterator edge = botEdges.begin();
2435 while ( edge != botEdges.end() )
2437 if ( SMESH_Algo::isDegenerated( *edge ))
2439 TopoDS_Edge e1 = *edge++;
2440 TopoDS_Edge e2 = ( edge == botEdges.end() ? botEdges.front() : *edge );
2441 if ( ! TopExp::CommonVertex( e1, e2, commonV ))
2443 e2 = botEdges.front();
2444 if ( ! TopExp::CommonVertex( e1, e2, commonV ))
2447 double angle = myHelper->GetAngle( e1, e2, reverseBottom, commonV );
2448 if ( angle < -5 * M_PI/180 )
2449 if ( ++nbConcaveAng > 1 )
2451 if ( angle > 85 * M_PI/180 )
2452 if ( ++nbConvexAng > 4 )
2458 //=======================================================================
2459 //function : allVerticalEdgesStraight
2460 //purpose : Defines if all "vertical" EDGEs are straight
2461 //=======================================================================
2463 bool StdMeshers_Prism_3D::allVerticalEdgesStraight( const Prism_3D::TPrismTopo& thePrism )
2465 for ( size_t i = 0; i < thePrism.myWallQuads.size(); ++i )
2467 const Prism_3D::TQuadList& quads = thePrism.myWallQuads[i];
2468 Prism_3D::TQuadList::const_iterator quadIt = quads.begin();
2469 TopoDS_Edge prevQuadEdge;
2470 for ( ; quadIt != quads.end(); ++quadIt )
2472 StdMeshers_FaceSidePtr rightSide = (*quadIt)->side[ QUAD_RIGHT_SIDE ];
2474 if ( !prevQuadEdge.IsNull() &&
2475 !SMESH_Algo::IsContinuous( rightSide->Edge( 0 ), prevQuadEdge ))
2478 for ( int iE = 0; iE < rightSide->NbEdges(); ++iE )
2480 const TopoDS_Edge & rightE = rightSide->Edge( iE );
2481 if ( !SMESH_Algo::IsStraight( rightE, /*degenResult=*/true ))
2485 !SMESH_Algo::IsContinuous( rightSide->Edge( iE-1 ), rightE ))
2488 prevQuadEdge = rightE;
2495 //=======================================================================
2496 //function : project2dMesh
2497 //purpose : Project mesh faces from a source FACE of one prism (theSrcFace)
2498 // to a source FACE of another prism (theTgtFace)
2499 //=======================================================================
2501 bool StdMeshers_Prism_3D::project2dMesh(const TopoDS_Face& theSrcFace,
2502 const TopoDS_Face& theTgtFace)
2504 TProjction2dAlgo* projector2D = TProjction2dAlgo::instance( this );
2505 projector2D->myHyp.SetSourceFace( theSrcFace );
2506 bool ok = projector2D->Compute( *myHelper->GetMesh(), theTgtFace );
2508 SMESH_subMesh* tgtSM = myHelper->GetMesh()->GetSubMesh( theTgtFace );
2509 if ( !ok && tgtSM->GetSubMeshDS() ) {
2510 //tgtSM->ComputeStateEngine( SMESH_subMesh::CLEAN ); -- avoid propagation of events
2511 SMESHDS_Mesh* meshDS = myHelper->GetMeshDS();
2512 SMESHDS_SubMesh* tgtSMDS = tgtSM->GetSubMeshDS();
2513 for ( SMDS_ElemIteratorPtr eIt = tgtSMDS->GetElements(); eIt->more(); )
2514 meshDS->RemoveFreeElement( eIt->next(), tgtSMDS, /*fromGroups=*/false );
2515 for ( SMDS_NodeIteratorPtr nIt = tgtSMDS->GetNodes(); nIt->more(); )
2516 meshDS->RemoveFreeNode( nIt->next(), tgtSMDS, /*fromGroups=*/false );
2518 tgtSM->ComputeStateEngine ( SMESH_subMesh::CHECK_COMPUTE_STATE );
2519 tgtSM->ComputeSubMeshStateEngine( SMESH_subMesh::CHECK_COMPUTE_STATE );
2521 projector2D->SetEventListener( tgtSM );
2526 //================================================================================
2528 * \brief Set projection coordinates of a node to a face and it's sub-shapes
2529 * \param faceID - the face given by in-block ID
2530 * \param params - node normalized parameters
2531 * \retval bool - is a success
2533 //================================================================================
2535 bool StdMeshers_Prism_3D::setFaceAndEdgesXYZ( const int faceID, const gp_XYZ& params, int z )
2537 // find base and top edges of the face
2538 enum { BASE = 0, TOP, LEFT, RIGHT };
2539 vector< int > edgeVec; // 0-base, 1-top
2540 SMESH_Block::GetFaceEdgesIDs( faceID, edgeVec );
2542 myBlock.EdgePoint( edgeVec[ BASE ], params, myShapeXYZ[ edgeVec[ BASE ]]);
2543 myBlock.EdgePoint( edgeVec[ TOP ], params, myShapeXYZ[ edgeVec[ TOP ]]);
2545 SHOWYXZ("\nparams ", params);
2546 SHOWYXZ("TOP is " <<edgeVec[ TOP ], myShapeXYZ[ edgeVec[ TOP]]);
2547 SHOWYXZ("BASE is "<<edgeVec[ BASE], myShapeXYZ[ edgeVec[ BASE]]);
2549 if ( faceID == SMESH_Block::ID_Fx0z || faceID == SMESH_Block::ID_Fx1z )
2551 myBlock.EdgePoint( edgeVec[ LEFT ], params, myShapeXYZ[ edgeVec[ LEFT ]]);
2552 myBlock.EdgePoint( edgeVec[ RIGHT ], params, myShapeXYZ[ edgeVec[ RIGHT ]]);
2554 SHOWYXZ("VER "<<edgeVec[ LEFT], myShapeXYZ[ edgeVec[ LEFT]]);
2555 SHOWYXZ("VER "<<edgeVec[ RIGHT], myShapeXYZ[ edgeVec[ RIGHT]]);
2557 myBlock.FacePoint( faceID, params, myShapeXYZ[ faceID ]);
2558 SHOWYXZ("FacePoint "<<faceID, myShapeXYZ[ faceID]);
2563 //=======================================================================
2565 //purpose : If (!isOK), sets the error to a sub-mesh of a current SOLID
2566 //=======================================================================
2568 bool StdMeshers_Prism_3D::toSM( bool isOK )
2570 if ( mySetErrorToSM &&
2573 !myHelper->GetSubShape().IsNull() &&
2574 myHelper->GetSubShape().ShapeType() == TopAbs_SOLID)
2576 SMESH_subMesh* sm = myHelper->GetMesh()->GetSubMesh( myHelper->GetSubShape() );
2577 sm->GetComputeError() = this->GetComputeError();
2578 // clear error in order not to return it twice
2579 _error = COMPERR_OK;
2585 //=======================================================================
2586 //function : shapeID
2587 //purpose : Return index of a shape
2588 //=======================================================================
2590 int StdMeshers_Prism_3D::shapeID( const TopoDS_Shape& S )
2592 if ( S.IsNull() ) return 0;
2593 if ( !myHelper ) return -3;
2594 return myHelper->GetMeshDS()->ShapeToIndex( S );
2597 namespace // utils used by StdMeshers_Prism_3D::IsApplicable()
2599 struct EdgeWithNeighbors
2602 int _iBase; /* index in a WIRE with non-base EDGEs excluded */
2603 int _iL, _iR; /* used to connect edges in a base FACE */
2604 bool _isBase; /* is used in a base FACE */
2605 EdgeWithNeighbors(const TopoDS_Edge& E, int iE, int nbE, int shift, bool isBase ):
2606 _edge( E ), _iBase( iE + shift ),
2607 _iL( SMESH_MesherHelper::WrapIndex( iE-1, Max( 1, nbE )) + shift ),
2608 _iR( SMESH_MesherHelper::WrapIndex( iE+1, Max( 1, nbE )) + shift ),
2612 EdgeWithNeighbors() {}
2613 bool IsInternal() const { return !_edge.IsNull() && _edge.Orientation() == TopAbs_INTERNAL; }
2615 // PrismSide contains all FACEs linking a bottom EDGE with a top one.
2618 TopoDS_Face _face; // a currently treated upper FACE
2619 TopTools_IndexedMapOfShape *_faces; // all FACEs (pointer because of a private copy constructor)
2620 TopoDS_Edge _topEdge; // a current top EDGE
2621 vector< EdgeWithNeighbors >*_edges; // all EDGEs of _face
2622 int _iBotEdge; // index of _topEdge within _edges
2623 vector< bool > _isCheckedEdge; // mark EDGEs whose two owner FACEs found
2624 int _nbCheckedEdges; // nb of EDGEs whose location is defined
2625 PrismSide *_leftSide; // neighbor sides
2626 PrismSide *_rightSide;
2627 bool _isInternal; // whether this side raises from an INTERNAL EDGE
2628 void SetExcluded() { _leftSide = _rightSide = NULL; }
2629 bool IsExcluded() const { return !_leftSide; }
2630 const TopoDS_Edge& Edge( int i ) const
2632 return (*_edges)[ i ]._edge;
2634 int FindEdge( const TopoDS_Edge& E ) const
2636 for ( size_t i = 0; i < _edges->size(); ++i )
2637 if ( E.IsSame( Edge( i ))) return i;
2640 bool IsSideFace( const TopoDS_Shape& face, const bool checkNeighbors ) const
2642 if ( _faces->Contains( face )) // avoid returning true for a prism top FACE
2643 return ( !_face.IsNull() || !( face.IsSame( _faces->FindKey( _faces->Extent() ))));
2645 if ( checkNeighbors )
2646 return (( _leftSide && _leftSide->IsSideFace ( face, false )) ||
2647 ( _rightSide && _rightSide->IsSideFace( face, false )));
2652 //--------------------------------------------------------------------------------
2654 * \brief Return another faces sharing an edge
2656 const TopoDS_Face & getAnotherFace( const TopoDS_Face& face,
2657 const TopoDS_Edge& edge,
2658 TopTools_IndexedDataMapOfShapeListOfShape& facesOfEdge)
2660 TopTools_ListIteratorOfListOfShape faceIt( facesOfEdge.FindFromKey( edge ));
2661 for ( ; faceIt.More(); faceIt.Next() )
2662 if ( !face.IsSame( faceIt.Value() ))
2663 return TopoDS::Face( faceIt.Value() );
2667 //--------------------------------------------------------------------------------
2669 * \brief Return ordered edges of a face
2671 bool getEdges( const TopoDS_Face& face,
2672 vector< EdgeWithNeighbors > & edges,
2673 TopTools_IndexedDataMapOfShapeListOfShape& facesOfEdge,
2674 const bool noHolesAllowed)
2676 TopoDS_Face f = face;
2677 if ( f.Orientation() != TopAbs_FORWARD &&
2678 f.Orientation() != TopAbs_REVERSED )
2679 f.Orientation( TopAbs_FORWARD );
2680 list< TopoDS_Edge > ee;
2681 list< int > nbEdgesInWires;
2682 int nbW = SMESH_Block::GetOrderedEdges( f, ee, nbEdgesInWires );
2683 if ( nbW > 1 && noHolesAllowed )
2686 int iE, nbTot = 0, nbBase, iBase;
2687 list< TopoDS_Edge >::iterator e = ee.begin();
2688 list< int >::iterator nbE = nbEdgesInWires.begin();
2689 for ( ; nbE != nbEdgesInWires.end(); ++nbE )
2690 for ( iE = 0; iE < *nbE; ++e, ++iE )
2691 if ( SMESH_Algo::isDegenerated( *e )) // degenerated EDGE is never used
2693 e = --ee.erase( e );
2701 for ( nbE = nbEdgesInWires.begin(); nbE != nbEdgesInWires.end(); ++nbE )
2704 isBase.resize( *nbE );
2705 list< TopoDS_Edge >::iterator eIt = e;
2706 for ( iE = 0; iE < *nbE; ++eIt, ++iE )
2708 isBase[ iE ] = ( getAnotherFace( face, *eIt, facesOfEdge ) != face );
2709 nbBase += isBase[ iE ];
2711 for ( iBase = 0, iE = 0; iE < *nbE; ++e, ++iE )
2713 edges.push_back( EdgeWithNeighbors( *e, iBase, nbBase, nbTot, isBase[ iE ] ));
2714 iBase += isBase[ iE ];
2721 // IPAL53099. Set correct neighbors to INTERNAL EDGEs, which can be connected to
2722 // EDGEs of the outer WIRE but this fact can't be detected by their order.
2725 int iFirst = 0, iLast;
2726 for ( nbE = nbEdgesInWires.begin(); nbE != nbEdgesInWires.end(); ++nbE )
2728 iLast = iFirst + *nbE - 1;
2729 TopoDS_Vertex vv[2] = { SMESH_MesherHelper::IthVertex( 0, edges[ iFirst ]._edge ),
2730 SMESH_MesherHelper::IthVertex( 1, edges[ iLast ]._edge ) };
2731 bool isConnectOk = ( vv[0].IsSame( vv[1] ));
2734 edges[ iFirst ]._iL = edges[ iFirst ]._iBase; // connect to self
2735 edges[ iLast ]._iR = edges[ iLast ]._iBase;
2737 // look for an EDGE of the outer WIREs connected to vv
2738 TopoDS_Vertex v0, v1;
2739 for ( iE = 0; iE < iFirst; ++iE )
2741 v0 = SMESH_MesherHelper::IthVertex( 0, edges[ iE ]._edge );
2742 v1 = SMESH_MesherHelper::IthVertex( 1, edges[ iE ]._edge );
2743 if ( vv[0].IsSame( v0 ) || vv[0].IsSame( v1 ))
2744 edges[ iFirst ]._iL = edges[ iE ]._iBase;
2745 if ( vv[1].IsSame( v0 ) || vv[1].IsSame( v1 ))
2746 edges[ iLast ]._iR = edges[ iE ]._iBase;
2752 return edges.size();
2755 //--------------------------------------------------------------------------------
2757 * \brief Return number of faces sharing given edges
2759 // int nbAdjacentFaces( const std::vector< EdgeWithNeighbors >& edges,
2760 // const TopTools_IndexedDataMapOfShapeListOfShape& facesOfEdge )
2762 // TopTools_MapOfShape adjFaces;
2764 // for ( size_t i = 0; i < edges.size(); ++i )
2766 // TopTools_ListIteratorOfListOfShape faceIt( facesOfEdge.FindFromKey( edges[i]._edge ));
2767 // for ( ; faceIt.More(); faceIt.Next() )
2768 // adjFaces.Add( faceIt.Value() );
2770 // return adjFaces.Extent();
2774 //================================================================================
2776 * \brief Return true if the algorithm can mesh this shape
2777 * \param [in] aShape - shape to check
2778 * \param [in] toCheckAll - if true, this check returns OK if all shapes are OK,
2779 * else, returns OK if at least one shape is OK
2781 //================================================================================
2783 bool StdMeshers_Prism_3D::IsApplicable(const TopoDS_Shape & shape, bool toCheckAll)
2785 TopExp_Explorer sExp( shape, TopAbs_SOLID );
2789 for ( ; sExp.More(); sExp.Next() )
2793 TopExp_Explorer shExp( sExp.Current(), TopAbs_SHELL );
2794 while ( shExp.More() ) {
2795 shell = shExp.Current();
2797 if ( shExp.More() && BRep_Tool::IsClosed( shExp.Current() ))
2800 if ( shell.IsNull() ) {
2801 if ( toCheckAll ) return false;
2805 TopTools_IndexedMapOfShape allFaces;
2806 TopExp::MapShapes( sExp.Current(), TopAbs_FACE, allFaces );
2807 if ( allFaces.Extent() < 3 ) {
2808 if ( toCheckAll ) return false;
2812 if ( allFaces.Extent() == 6 )
2814 TopTools_IndexedMapOfOrientedShape map;
2815 bool isBox = SMESH_Block::FindBlockShapes( TopoDS::Shell( shell ),
2816 TopoDS_Vertex(), TopoDS_Vertex(), map );
2818 if ( !toCheckAll ) return true;
2823 TopTools_IndexedMapOfShape allShapes; // usage: allShapes.FindIndex( s )
2824 TopExp::MapShapes( shape, allShapes );
2827 TopTools_IndexedDataMapOfShapeListOfShape facesOfEdge;
2828 TopTools_ListIteratorOfListOfShape faceIt;
2829 TopExp::MapShapesAndAncestors( sExp.Current(), TopAbs_EDGE, TopAbs_FACE , facesOfEdge );
2830 if ( facesOfEdge.IsEmpty() ) {
2831 if ( toCheckAll ) return false;
2835 typedef vector< EdgeWithNeighbors > TEdgeWithNeighborsVec;
2836 vector< TEdgeWithNeighborsVec > faceEdgesVec( allFaces.Extent() + 1 );
2837 const size_t nbEdgesMax = facesOfEdge.Extent() * 2; // there can be seam EDGEs
2838 TopTools_IndexedMapOfShape* facesOfSide = new TopTools_IndexedMapOfShape[ nbEdgesMax ];
2839 SMESHUtils::ArrayDeleter<TopTools_IndexedMapOfShape> delFacesOfSide( facesOfSide );
2841 // try to use each face as a bottom one
2842 bool prismDetected = false;
2843 vector< PrismSide > sides;
2844 for ( int iF = 1; iF < allFaces.Extent() && !prismDetected; ++iF )
2846 const TopoDS_Face& botF = TopoDS::Face( allFaces( iF ));
2848 TEdgeWithNeighborsVec& botEdges = faceEdgesVec[ iF ];
2849 if ( botEdges.empty() )
2850 if ( !getEdges( botF, botEdges, facesOfEdge, /*noHoles=*/false ))
2854 for ( size_t iS = 0; iS < botEdges.size(); ++iS )
2855 nbBase += botEdges[ iS ]._isBase;
2857 if ( allFaces.Extent()-1 <= nbBase )
2858 continue; // all faces are adjacent to botF - no top FACE
2860 // init data of side FACEs
2862 sides.resize( nbBase );
2864 for ( size_t iE = 0; iE < botEdges.size(); ++iE )
2866 if ( !botEdges[ iE ]._isBase )
2868 sides[ iS ]._topEdge = botEdges[ iE ]._edge;
2869 sides[ iS ]._face = botF;
2870 sides[ iS ]._leftSide = & sides[ botEdges[ iE ]._iR ];
2871 sides[ iS ]._rightSide = & sides[ botEdges[ iE ]._iL ];
2872 sides[ iS ]._isInternal = botEdges[ iE ].IsInternal();
2873 sides[ iS ]._faces = & facesOfSide[ iS ];
2874 sides[ iS ]._faces->Clear();
2878 bool isOK = true; // ok for a current botF
2879 bool isAdvanced = true; // is new data found in a current loop
2880 int nbFoundSideFaces = 0;
2881 for ( int iLoop = 0; isOK && isAdvanced; ++iLoop )
2884 for ( size_t iS = 0; iS < sides.size() && isOK; ++iS )
2886 PrismSide& side = sides[ iS ];
2887 if ( side._face.IsNull() )
2888 continue; // probably the prism top face is the last of side._faces
2890 if ( side._topEdge.IsNull() )
2892 // find vertical EDGEs --- EGDEs shared with neighbor side FACEs
2893 for ( int is2nd = 0; is2nd < 2 && isOK; ++is2nd ) // 2 adjacent neighbors
2895 int di = is2nd ? 1 : -1;
2896 const PrismSide* adjSide = is2nd ? side._rightSide : side._leftSide;
2897 for ( size_t i = 1; i < side._edges->size(); ++i )
2899 int iE = SMESH_MesherHelper::WrapIndex( i*di + side._iBotEdge, side._edges->size());
2900 if ( side._isCheckedEdge[ iE ] ) continue;
2901 const TopoDS_Edge& vertE = side.Edge( iE );
2902 const TopoDS_Shape& neighborF = getAnotherFace( side._face, vertE, facesOfEdge );
2903 bool isEdgeShared = (( adjSide->IsSideFace( neighborF, side._isInternal )) ||
2904 ( adjSide == &side && neighborF.IsSame( side._face )) );
2905 if ( isEdgeShared ) // vertE is shared with adjSide
2908 side._isCheckedEdge[ iE ] = true;
2909 side._nbCheckedEdges++;
2910 int nbNotCheckedE = side._edges->size() - side._nbCheckedEdges;
2911 if ( nbNotCheckedE == 1 )
2916 if ( i == 1 && iLoop == 0 ) isOK = false;
2922 int nbNotCheckedE = side._edges->size() - side._nbCheckedEdges;
2923 if ( nbNotCheckedE == 1 )
2925 vector<bool>::iterator ii = std::find( side._isCheckedEdge.begin(),
2926 side._isCheckedEdge.end(), false );
2927 if ( ii != side._isCheckedEdge.end() )
2929 size_t iE = std::distance( side._isCheckedEdge.begin(), ii );
2930 side._topEdge = side.Edge( iE );
2933 isOK = ( nbNotCheckedE >= 1 );
2935 else //if ( !side._topEdge.IsNull() )
2937 // get a next face of a side
2938 const TopoDS_Shape& f = getAnotherFace( side._face, side._topEdge, facesOfEdge );
2939 side._faces->Add( f );
2941 if ( f.IsSame( side._face ) || // _topEdge is a seam
2942 SMESH_MesherHelper::Count( f, TopAbs_WIRE, false ) != 1 )
2946 else if ( side._leftSide != & side && // not closed side face
2947 side._leftSide->_faces->Contains( f ))
2949 stop = true; // probably f is the prism top face
2950 side._leftSide->_face.Nullify();
2951 side._leftSide->_topEdge.Nullify();
2953 else if ( side._rightSide != & side &&
2954 side._rightSide->_faces->Contains( f ))
2956 stop = true; // probably f is the prism top face
2957 side._rightSide->_face.Nullify();
2958 side._rightSide->_topEdge.Nullify();
2962 side._face.Nullify();
2963 side._topEdge.Nullify();
2966 side._face = TopoDS::Face( f );
2967 int faceID = allFaces.FindIndex( side._face );
2968 side._edges = & faceEdgesVec[ faceID ];
2969 if ( side._edges->empty() )
2970 if ( !getEdges( side._face, * side._edges, facesOfEdge, /*noHoles=*/true ))
2972 const int nbE = side._edges->size();
2977 side._iBotEdge = side.FindEdge( side._topEdge );
2978 side._isCheckedEdge.clear();
2979 side._isCheckedEdge.resize( nbE, false );
2980 side._isCheckedEdge[ side._iBotEdge ] = true;
2981 side._nbCheckedEdges = 1; // bottom EDGE is known
2983 else // probably a triangular top face found
2985 side._face.Nullify();
2987 side._topEdge.Nullify();
2988 isOK = ( !side._edges->empty() || side._faces->Extent() > 1 );
2990 } //if ( !side._topEdge.IsNull() )
2992 } // loop on prism sides
2994 if ( nbFoundSideFaces > allFaces.Extent() )
2998 if ( iLoop > allFaces.Extent() * 10 )
3002 cerr << "BUG: infinite loop in StdMeshers_Prism_3D::IsApplicable()" << endl;
3005 } // while isAdvanced
3007 if ( isOK && sides[0]._faces->Extent() > 1 )
3009 const int nbFaces = sides[0]._faces->Extent();
3010 if ( botEdges.size() == 1 ) // cylinder
3012 prismDetected = ( nbFaces == allFaces.Extent()-1 );
3016 const TopoDS_Shape& topFace = sides[0]._faces->FindKey( nbFaces );
3018 for ( iS = 1; iS < sides.size(); ++iS )
3019 if ( ! sides[ iS ]._faces->Contains( topFace ))
3021 prismDetected = ( iS == sides.size() );
3024 } // loop on allFaces
3026 if ( !prismDetected && toCheckAll ) return false;
3027 if ( prismDetected && !toCheckAll ) return true;
3036 //================================================================================
3038 * \brief Return true if this node and other one belong to one face
3040 //================================================================================
3042 bool Prism_3D::TNode::IsNeighbor( const Prism_3D::TNode& other ) const
3044 if ( !other.myNode || !myNode ) return false;
3046 SMDS_ElemIteratorPtr fIt = other.myNode->GetInverseElementIterator(SMDSAbs_Face);
3047 while ( fIt->more() )
3048 if ( fIt->next()->GetNodeIndex( myNode ) >= 0 )
3053 //================================================================================
3055 * \brief Prism initialization
3057 //================================================================================
3059 void TPrismTopo::Clear()
3061 myShape3D.Nullify();
3064 myWallQuads.clear();
3065 myBottomEdges.clear();
3066 myNbEdgesInWires.clear();
3067 myWallQuads.clear();
3070 //================================================================================
3072 * \brief Set upside-down
3074 //================================================================================
3076 void TPrismTopo::SetUpsideDown()
3078 std::swap( myBottom, myTop );
3079 myBottomEdges.clear();
3080 std::reverse( myBottomEdges.begin(), myBottomEdges.end() );
3081 for ( size_t i = 0; i < myWallQuads.size(); ++i )
3083 myWallQuads[i].reverse();
3084 TQuadList::iterator q = myWallQuads[i].begin();
3085 for ( ; q != myWallQuads[i].end(); ++q )
3087 (*q)->shift( 2, /*keepUnitOri=*/true );
3089 myBottomEdges.push_back( myWallQuads[i].front()->side[ QUAD_BOTTOM_SIDE ].grid->Edge(0) );
3093 } // namespace Prism_3D
3095 //================================================================================
3097 * \brief Constructor. Initialization is needed
3099 //================================================================================
3101 StdMeshers_PrismAsBlock::StdMeshers_PrismAsBlock()
3106 StdMeshers_PrismAsBlock::~StdMeshers_PrismAsBlock()
3110 void StdMeshers_PrismAsBlock::Clear()
3113 myShapeIDMap.Clear();
3117 delete mySide; mySide = 0;
3119 myParam2ColumnMaps.clear();
3120 myShapeIndex2ColumnMap.clear();
3123 //=======================================================================
3124 //function : initPrism
3125 //purpose : Analyse shape geometry and mesh.
3126 // If there are triangles on one of faces, it becomes 'bottom'.
3127 // thePrism.myBottom can be already set up.
3128 //=======================================================================
3130 bool StdMeshers_Prism_3D::initPrism(Prism_3D::TPrismTopo& thePrism,
3131 const TopoDS_Shape& theShape3D,
3132 const bool selectBottom)
3134 myHelper->SetSubShape( theShape3D );
3136 SMESH_subMesh* mainSubMesh = myHelper->GetMesh()->GetSubMeshContaining( theShape3D );
3137 if ( !mainSubMesh ) return toSM( error(COMPERR_BAD_INPUT_MESH,"Null submesh of shape3D"));
3139 // detect not-quad FACE sub-meshes of the 3D SHAPE
3140 list< SMESH_subMesh* > notQuadGeomSubMesh;
3141 list< SMESH_subMesh* > notQuadElemSubMesh;
3142 list< SMESH_subMesh* > meshedSubMesh;
3145 SMESH_subMeshIteratorPtr smIt = mainSubMesh->getDependsOnIterator(false,true);
3146 while ( smIt->more() )
3148 SMESH_subMesh* sm = smIt->next();
3149 const TopoDS_Shape& face = sm->GetSubShape();
3150 if ( face.ShapeType() > TopAbs_FACE ) break;
3151 else if ( face.ShapeType() < TopAbs_FACE ) continue;
3154 // is quadrangle FACE?
3155 list< TopoDS_Edge > orderedEdges;
3156 list< int > nbEdgesInWires;
3157 int nbWires = SMESH_Block::GetOrderedEdges( TopoDS::Face( face ), orderedEdges,
3159 if ( nbWires != 1 || nbEdgesInWires.front() != 4 )
3160 notQuadGeomSubMesh.push_back( sm );
3162 // look for a not structured sub-mesh
3163 if ( !sm->IsEmpty() )
3165 meshedSubMesh.push_back( sm );
3166 if ( !myHelper->IsSameElemGeometry( sm->GetSubMeshDS(), SMDSGeom_QUADRANGLE ) ||
3167 !myHelper->IsStructured ( sm ))
3168 notQuadElemSubMesh.push_back( sm );
3172 int nbNotQuadMeshed = notQuadElemSubMesh.size();
3173 int nbNotQuad = notQuadGeomSubMesh.size();
3174 bool hasNotQuad = ( nbNotQuad || nbNotQuadMeshed );
3177 if ( nbNotQuadMeshed > 2 )
3179 return toSM( error(COMPERR_BAD_INPUT_MESH,
3180 TCom("More than 2 faces with not quadrangle elements: ")
3181 <<nbNotQuadMeshed));
3183 if ( nbNotQuad > 2 || !thePrism.myBottom.IsNull() )
3185 // Issue 0020843 - one of side FACEs is quasi-quadrilateral (not 4 EDGEs).
3186 // Remove from notQuadGeomSubMesh faces meshed with regular grid
3187 int nbQuasiQuads = removeQuasiQuads( notQuadGeomSubMesh, myHelper,
3188 TQuadrangleAlgo::instance(this,myHelper) );
3189 nbNotQuad -= nbQuasiQuads;
3190 if ( nbNotQuad > 2 )
3191 return toSM( error(COMPERR_BAD_SHAPE,
3192 TCom("More than 2 not quadrilateral faces: ") <<nbNotQuad));
3193 hasNotQuad = ( nbNotQuad || nbNotQuadMeshed );
3196 // Analyse mesh and topology of FACEs: choose the bottom sub-mesh.
3197 // If there are not quadrangle FACEs, they are top and bottom ones.
3198 // Not quadrangle FACEs must be only on top and bottom.
3200 SMESH_subMesh * botSM = 0;
3201 SMESH_subMesh * topSM = 0;
3203 if ( hasNotQuad ) // can choose a bottom FACE
3205 if ( nbNotQuadMeshed > 0 ) botSM = notQuadElemSubMesh.front();
3206 else botSM = notQuadGeomSubMesh.front();
3207 if ( nbNotQuadMeshed > 1 ) topSM = notQuadElemSubMesh.back();
3208 else if ( nbNotQuad > 1 ) topSM = notQuadGeomSubMesh.back();
3210 if ( topSM == botSM ) {
3211 if ( nbNotQuadMeshed > 1 ) topSM = notQuadElemSubMesh.front();
3212 else topSM = notQuadGeomSubMesh.front();
3215 // detect mesh triangles on wall FACEs
3216 if ( nbNotQuad == 2 && nbNotQuadMeshed > 0 ) {
3218 if ( nbNotQuadMeshed == 1 )
3219 ok = ( find( notQuadGeomSubMesh.begin(),
3220 notQuadGeomSubMesh.end(), botSM ) != notQuadGeomSubMesh.end() );
3222 ok = ( notQuadGeomSubMesh == notQuadElemSubMesh );
3224 return toSM( error(COMPERR_BAD_INPUT_MESH,
3225 "Side face meshed with not quadrangle elements"));
3229 thePrism.myNotQuadOnTop = ( nbNotQuadMeshed > 1 );
3231 // use thePrism.myBottom
3232 if ( !thePrism.myBottom.IsNull() )
3234 if ( botSM ) { // <-- not quad geom or mesh on botSM
3235 if ( ! botSM->GetSubShape().IsSame( thePrism.myBottom )) {
3236 std::swap( botSM, topSM );
3237 if ( !botSM || ! botSM->GetSubShape().IsSame( thePrism.myBottom )) {
3238 if ( !selectBottom )
3239 return toSM( error( COMPERR_BAD_INPUT_MESH,
3240 "Incompatible non-structured sub-meshes"));
3241 std::swap( botSM, topSM );
3242 thePrism.myBottom = TopoDS::Face( botSM->GetSubShape() );
3246 else if ( !selectBottom ) {
3247 botSM = myHelper->GetMesh()->GetSubMesh( thePrism.myBottom );
3250 if ( !botSM ) // find a proper bottom
3252 bool savedSetErrorToSM = mySetErrorToSM;
3253 mySetErrorToSM = false; // ingore errors in initPrism()
3255 // search among meshed FACEs
3256 list< SMESH_subMesh* >::iterator sm = meshedSubMesh.begin();
3257 for ( ; !botSM && sm != meshedSubMesh.end(); ++sm )
3261 thePrism.myBottom = TopoDS::Face( botSM->GetSubShape() );
3262 if ( !initPrism( thePrism, theShape3D, /*selectBottom=*/false ))
3265 // search among all FACEs
3266 for ( TopExp_Explorer f( theShape3D, TopAbs_FACE ); !botSM && f.More(); f.Next() )
3268 int minNbFaces = 2 + myHelper->Count( f.Current(), TopAbs_EDGE, false);
3269 if ( nbFaces < minNbFaces) continue;
3271 thePrism.myBottom = TopoDS::Face( f.Current() );
3272 botSM = myHelper->GetMesh()->GetSubMesh( thePrism.myBottom );
3273 if ( !initPrism( thePrism, theShape3D, /*selectBottom=*/false ))
3276 mySetErrorToSM = savedSetErrorToSM;
3277 return botSM ? true : toSM( error( COMPERR_BAD_SHAPE ));
3280 // find vertex 000 - the one with smallest coordinates (for easy DEBUG :-)
3282 double minVal = DBL_MAX, minX = 0, val;
3283 for ( TopExp_Explorer exp( botSM->GetSubShape(), TopAbs_VERTEX );
3284 exp.More(); exp.Next() )
3286 const TopoDS_Vertex& v = TopoDS::Vertex( exp.Current() );
3287 gp_Pnt P = BRep_Tool::Pnt( v );
3288 val = P.X() + P.Y() + P.Z();
3289 if ( val < minVal || ( val == minVal && P.X() < minX )) {
3296 thePrism.myShape3D = theShape3D;
3297 if ( thePrism.myBottom.IsNull() )
3298 thePrism.myBottom = TopoDS::Face( botSM->GetSubShape() );
3299 thePrism.myBottom.Orientation( myHelper->GetSubShapeOri( theShape3D, thePrism.myBottom ));
3300 thePrism.myTop. Orientation( myHelper->GetSubShapeOri( theShape3D, thePrism.myTop ));
3302 // Get ordered bottom edges
3303 TopoDS_Face reverseBottom = // to have order of top EDGEs as in the top FACE
3304 TopoDS::Face( thePrism.myBottom.Reversed() );
3305 SMESH_Block::GetOrderedEdges( reverseBottom,
3306 thePrism.myBottomEdges,
3307 thePrism.myNbEdgesInWires, V000 );
3309 // Get Wall faces corresponding to the ordered bottom edges and the top FACE
3310 if ( !getWallFaces( thePrism, nbFaces )) // it also sets thePrism.myTop
3311 return false; //toSM( error(COMPERR_BAD_SHAPE, "Can't find side faces"));
3315 if ( !thePrism.myTop.IsSame( topSM->GetSubShape() ))
3317 (notQuadGeomSubMesh.empty() ? COMPERR_BAD_INPUT_MESH : COMPERR_BAD_SHAPE,
3318 "Non-quadrilateral faces are not opposite"));
3320 // check that the found top and bottom FACEs are opposite
3321 TopTools_IndexedMapOfShape topEdgesMap( thePrism.myBottomEdges.size() );
3322 TopExp::MapShapes( thePrism.myTop, topEdgesMap );
3323 list< TopoDS_Edge >::iterator edge = thePrism.myBottomEdges.begin();
3324 for ( ; edge != thePrism.myBottomEdges.end(); ++edge )
3325 if ( topEdgesMap.Contains( *edge ))
3327 (notQuadGeomSubMesh.empty() ? COMPERR_BAD_INPUT_MESH : COMPERR_BAD_SHAPE,
3328 "Non-quadrilateral faces are not opposite"));
3331 if ( thePrism.myBottomEdges.size() > thePrism.myWallQuads.size() )
3333 // composite bottom sides => set thePrism upside-down
3334 thePrism.SetUpsideDown();
3340 //================================================================================
3342 * \brief Initialization.
3343 * \param helper - helper loaded with mesh and 3D shape
3344 * \param thePrism - a prism data
3345 * \retval bool - false if a mesh or a shape are KO
3347 //================================================================================
3349 bool StdMeshers_PrismAsBlock::Init(SMESH_MesherHelper* helper,
3350 const Prism_3D::TPrismTopo& thePrism)
3353 SMESHDS_Mesh* meshDS = myHelper->GetMeshDS();
3354 SMESH_Mesh* mesh = myHelper->GetMesh();
3357 delete mySide; mySide = 0;
3359 vector< TSideFace* > sideFaces( NB_WALL_FACES, 0 );
3360 vector< pair< double, double> > params( NB_WALL_FACES );
3361 mySide = new TSideFace( *mesh, sideFaces, params );
3364 SMESH_Block::init();
3365 myShapeIDMap.Clear();
3366 myShapeIndex2ColumnMap.clear();
3368 int wallFaceIds[ NB_WALL_FACES ] = { // to walk around a block
3369 SMESH_Block::ID_Fx0z, SMESH_Block::ID_F1yz,
3370 SMESH_Block::ID_Fx1z, SMESH_Block::ID_F0yz
3373 myError = SMESH_ComputeError::New();
3375 myNotQuadOnTop = thePrism.myNotQuadOnTop;
3377 // Find columns of wall nodes and calculate edges' lengths
3378 // --------------------------------------------------------
3380 myParam2ColumnMaps.clear();
3381 myParam2ColumnMaps.resize( thePrism.myBottomEdges.size() ); // total nb edges
3383 size_t iE, nbEdges = thePrism.myNbEdgesInWires.front(); // nb outer edges
3384 vector< double > edgeLength( nbEdges );
3385 multimap< double, int > len2edgeMap;
3387 // for each EDGE: either split into several parts, or join with several next EDGEs
3388 vector<int> nbSplitPerEdge( nbEdges, 0 );
3389 vector<int> nbUnitePerEdge( nbEdges, 0 ); // -1 means "joined to a previous"
3391 // consider continuous straight EDGEs as one side
3392 const int nbSides = countNbSides( thePrism, nbUnitePerEdge, edgeLength );
3394 list< TopoDS_Edge >::const_iterator edgeIt = thePrism.myBottomEdges.begin();
3395 for ( iE = 0; iE < nbEdges; ++iE, ++edgeIt )
3397 TParam2ColumnMap & faceColumns = myParam2ColumnMaps[ iE ];
3399 Prism_3D::TQuadList::const_iterator quad = thePrism.myWallQuads[ iE ].begin();
3400 for ( ; quad != thePrism.myWallQuads[ iE ].end(); ++quad )
3402 const TopoDS_Edge& quadBot = (*quad)->side[ QUAD_BOTTOM_SIDE ].grid->Edge( 0 );
3403 if ( !myHelper->LoadNodeColumns( faceColumns, (*quad)->face, quadBot, meshDS ))
3404 return error(COMPERR_BAD_INPUT_MESH, TCom("Can't find regular quadrangle mesh ")
3405 << "on a side face #" << MeshDS()->ShapeToIndex( (*quad)->face ));
3407 SHOWYXZ("\np1 F " <<iE, gpXYZ(faceColumns.begin()->second.front() ));
3408 SHOWYXZ("p2 F " <<iE, gpXYZ(faceColumns.rbegin()->second.front() ));
3409 SHOWYXZ("V First "<<iE, BRep_Tool::Pnt( TopExp::FirstVertex(*edgeIt,true )));
3411 if ( nbSides < NB_WALL_FACES ) // fill map used to split faces
3412 len2edgeMap.insert( make_pair( edgeLength[ iE ], iE )); // sort edges by length
3414 // Load columns of internal edges (forming holes)
3415 // and fill map ShapeIndex to TParam2ColumnMap for them
3416 for ( ; edgeIt != thePrism.myBottomEdges.end() ; ++edgeIt, ++iE )
3418 TParam2ColumnMap & faceColumns = myParam2ColumnMaps[ iE ];
3420 Prism_3D::TQuadList::const_iterator quad = thePrism.myWallQuads[ iE ].begin();
3421 for ( ; quad != thePrism.myWallQuads[ iE ].end(); ++quad )
3423 const TopoDS_Edge& quadBot = (*quad)->side[ QUAD_BOTTOM_SIDE ].grid->Edge( 0 );
3424 if ( !myHelper->LoadNodeColumns( faceColumns, (*quad)->face, quadBot, meshDS ))
3425 return error(COMPERR_BAD_INPUT_MESH, TCom("Can't find regular quadrangle mesh ")
3426 << "on a side face #" << MeshDS()->ShapeToIndex( (*quad)->face ));
3428 if ( !faceColumns.empty() && (int)faceColumns.begin()->second.size() != VerticalSize() )
3429 return error(COMPERR_BAD_INPUT_MESH, "Different 'vertical' discretization");
3432 int id = MeshDS()->ShapeToIndex( *edgeIt );
3433 bool isForward = true; // meaningless for intenal wires
3434 myShapeIndex2ColumnMap[ id ] = make_pair( & faceColumns, isForward );
3435 // columns for vertices
3437 const SMDS_MeshNode* n0 = faceColumns.begin()->second.front();
3438 id = n0->getshapeId();
3439 myShapeIndex2ColumnMap[ id ] = make_pair( & faceColumns, isForward );
3441 const SMDS_MeshNode* n1 = faceColumns.rbegin()->second.front();
3442 id = n1->getshapeId();
3443 myShapeIndex2ColumnMap[ id ] = make_pair( & faceColumns, isForward );
3445 // SHOWYXZ("\np1 F " <<iE, gpXYZ(faceColumns.begin()->second.front() ));
3446 // SHOWYXZ("p2 F " <<iE, gpXYZ(faceColumns.rbegin()->second.front() ));
3447 // SHOWYXZ("V First "<<iE, BRep_Tool::Pnt( TopExp::FirstVertex(*edgeIt,true )));
3450 // Create 4 wall faces of a block
3451 // -------------------------------
3453 if ( nbSides <= NB_WALL_FACES ) // ************* Split faces if necessary
3455 if ( nbSides != NB_WALL_FACES ) // define how to split
3457 if ( len2edgeMap.size() != nbEdges )
3458 RETURN_BAD_RESULT("Uniqueness of edge lengths not assured");
3460 multimap< double, int >::reverse_iterator maxLen_i = len2edgeMap.rbegin();
3461 multimap< double, int >::reverse_iterator midLen_i = ++len2edgeMap.rbegin();
3463 double maxLen = maxLen_i->first;
3464 double midLen = ( len2edgeMap.size() == 1 ) ? 0 : midLen_i->first;
3465 switch ( nbEdges ) {
3466 case 1: // 0-th edge is split into 4 parts
3467 nbSplitPerEdge[ 0 ] = 4;
3469 case 2: // either the longest edge is split into 3 parts, or both edges into halves
3470 if ( maxLen / 3 > midLen / 2 ) {
3471 nbSplitPerEdge[ maxLen_i->second ] = 3;
3474 nbSplitPerEdge[ maxLen_i->second ] = 2;
3475 nbSplitPerEdge[ midLen_i->second ] = 2;
3480 // split longest into 3 parts
3481 nbSplitPerEdge[ maxLen_i->second ] = 3;
3483 // split longest into halves
3484 nbSplitPerEdge[ maxLen_i->second ] = 2;
3488 else // **************************** Unite faces
3490 int nbExraFaces = nbSides - 4; // nb of faces to fuse
3491 for ( iE = 0; iE < nbEdges; ++iE )
3493 if ( nbUnitePerEdge[ iE ] < 0 )
3495 // look for already united faces
3496 for ( size_t i = iE; i < iE + nbExraFaces; ++i )
3498 if ( nbUnitePerEdge[ i ] > 0 ) // a side including nbUnitePerEdge[i]+1 edge
3499 nbExraFaces += nbUnitePerEdge[ i ];
3500 nbUnitePerEdge[ i ] = -1;
3502 nbUnitePerEdge[ iE ] = nbExraFaces;
3507 // Create TSideFace's
3509 list< TopoDS_Edge >::const_iterator botE = thePrism.myBottomEdges.begin();
3510 for ( iE = 0; iE < nbEdges; ++iE, ++botE )
3512 TFaceQuadStructPtr quad = thePrism.myWallQuads[ iE ].front();
3513 const int nbSplit = nbSplitPerEdge[ iE ];
3514 const int nbExraFaces = nbUnitePerEdge[ iE ] + 1;
3515 if ( nbSplit > 0 ) // split
3517 vector< double > params;
3518 splitParams( nbSplit, &myParam2ColumnMaps[ iE ], params );
3519 const bool isForward =
3520 StdMeshers_PrismAsBlock::IsForwardEdge( myHelper->GetMeshDS(),
3521 myParam2ColumnMaps[iE],
3522 *botE, SMESH_Block::ID_Fx0z );
3523 for ( int i = 0; i < nbSplit; ++i ) {
3524 double f = ( isForward ? params[ i ] : params[ nbSplit - i-1 ]);
3525 double l = ( isForward ? params[ i+1 ] : params[ nbSplit - i ]);
3526 TSideFace* comp = new TSideFace( *mesh, wallFaceIds[ iSide ],
3527 thePrism.myWallQuads[ iE ], *botE,
3528 &myParam2ColumnMaps[ iE ], f, l );
3529 mySide->SetComponent( iSide++, comp );
3532 else if ( nbExraFaces > 1 ) // unite
3534 double u0 = 0, sumLen = 0;
3535 for ( size_t i = iE; i < iE + nbExraFaces; ++i )
3536 sumLen += edgeLength[ i ];
3538 vector< TSideFace* > components( nbExraFaces );
3539 vector< pair< double, double> > params( nbExraFaces );
3540 bool endReached = false;
3541 for ( int i = 0; i < nbExraFaces; ++i, ++botE, ++iE )
3543 if ( iE == nbEdges )
3546 botE = thePrism.myBottomEdges.begin();
3549 components[ i ] = new TSideFace( *mesh, wallFaceIds[ iSide ],
3550 thePrism.myWallQuads[ iE ], *botE,
3551 &myParam2ColumnMaps[ iE ]);
3552 double u1 = u0 + edgeLength[ iE ] / sumLen;
3553 params[ i ] = make_pair( u0 , u1 );
3556 TSideFace* comp = new TSideFace( *mesh, components, params );
3557 mySide->SetComponent( iSide++, comp );
3560 --iE; // for increment in an external loop on iE
3563 else if ( nbExraFaces < 0 ) // skip already united face
3568 TSideFace* comp = new TSideFace( *mesh, wallFaceIds[ iSide ],
3569 thePrism.myWallQuads[ iE ], *botE,
3570 &myParam2ColumnMaps[ iE ]);
3571 mySide->SetComponent( iSide++, comp );
3576 // Fill geometry fields of SMESH_Block
3577 // ------------------------------------
3579 vector< int > botEdgeIdVec;
3580 SMESH_Block::GetFaceEdgesIDs( ID_BOT_FACE, botEdgeIdVec );
3582 bool isForward[NB_WALL_FACES] = { true, true, true, true };
3583 Adaptor2d_Curve2d* botPcurves[NB_WALL_FACES];
3584 Adaptor2d_Curve2d* topPcurves[NB_WALL_FACES];
3586 for ( int iF = 0; iF < NB_WALL_FACES; ++iF )
3588 TSideFace * sideFace = mySide->GetComponent( iF );
3590 RETURN_BAD_RESULT("NULL TSideFace");
3591 int fID = sideFace->FaceID(); // in-block ID
3593 // fill myShapeIDMap
3594 if ( sideFace->InsertSubShapes( myShapeIDMap ) != 8 &&
3595 !sideFace->IsComplex())
3596 MESSAGE( ": Warning : InsertSubShapes() < 8 on side " << iF );
3598 // side faces geometry
3599 Adaptor2d_Curve2d* pcurves[NB_WALL_FACES];
3600 if ( !sideFace->GetPCurves( pcurves ))
3601 RETURN_BAD_RESULT("TSideFace::GetPCurves() failed");
3603 SMESH_Block::TFace& tFace = myFace[ fID - ID_FirstF ];
3604 tFace.Set( fID, sideFace->Surface(), pcurves, isForward );
3606 SHOWYXZ( endl<<"F "<< iF << " id " << fID << " FRW " << sideFace->IsForward(), sideFace->Value(0,0));
3607 // edges 3D geometry
3608 vector< int > edgeIdVec;
3609 SMESH_Block::GetFaceEdgesIDs( fID, edgeIdVec );
3610 for ( int isMax = 0; isMax < 2; ++isMax ) {
3612 int eID = edgeIdVec[ isMax ];
3613 SMESH_Block::TEdge& tEdge = myEdge[ eID - ID_FirstE ];
3614 tEdge.Set( eID, sideFace->HorizCurve(isMax), true);
3615 SHOWYXZ(eID<<" HOR"<<isMax<<"(0)", sideFace->HorizCurve(isMax)->Value(0));
3616 SHOWYXZ(eID<<" HOR"<<isMax<<"(1)", sideFace->HorizCurve(isMax)->Value(1));
3619 int eID = edgeIdVec[ isMax+2 ];
3620 SMESH_Block::TEdge& tEdge = myEdge[ eID - ID_FirstE ];
3621 tEdge.Set( eID, sideFace->VertiCurve(isMax), true);
3622 SHOWYXZ(eID<<" VER"<<isMax<<"(0)", sideFace->VertiCurve(isMax)->Value(0));
3623 SHOWYXZ(eID<<" VER"<<isMax<<"(1)", sideFace->VertiCurve(isMax)->Value(1));
3626 vector< int > vertexIdVec;
3627 SMESH_Block::GetEdgeVertexIDs( eID, vertexIdVec );
3628 myPnt[ vertexIdVec[0] - ID_FirstV ] = tEdge.GetCurve()->Value(0).XYZ();
3629 myPnt[ vertexIdVec[1] - ID_FirstV ] = tEdge.GetCurve()->Value(1).XYZ();
3632 // pcurves on horizontal faces
3633 for ( iE = 0; iE < NB_WALL_FACES; ++iE ) {
3634 if ( edgeIdVec[ BOTTOM_EDGE ] == botEdgeIdVec[ iE ] ) {
3635 botPcurves[ iE ] = sideFace->HorizPCurve( false, thePrism.myBottom );
3636 topPcurves[ iE ] = sideFace->HorizPCurve( true, thePrism.myTop );
3640 //sideFace->dumpNodes( 4 ); // debug
3642 // horizontal faces geometry
3644 SMESH_Block::TFace& tFace = myFace[ ID_BOT_FACE - ID_FirstF ];
3645 tFace.Set( ID_BOT_FACE, new BRepAdaptor_Surface( thePrism.myBottom ), botPcurves, isForward );
3646 SMESH_Block::Insert( thePrism.myBottom, ID_BOT_FACE, myShapeIDMap );
3649 SMESH_Block::TFace& tFace = myFace[ ID_TOP_FACE - ID_FirstF ];
3650 tFace.Set( ID_TOP_FACE, new BRepAdaptor_Surface( thePrism.myTop ), topPcurves, isForward );
3651 SMESH_Block::Insert( thePrism.myTop, ID_TOP_FACE, myShapeIDMap );
3653 //faceGridToPythonDump( SMESH_Block::ID_Fxy0, 50 );
3654 //faceGridToPythonDump( SMESH_Block::ID_Fxy1 );
3656 // Fill map ShapeIndex to TParam2ColumnMap
3657 // ----------------------------------------
3659 list< TSideFace* > fList;
3660 list< TSideFace* >::iterator fListIt;
3661 fList.push_back( mySide );
3662 for ( fListIt = fList.begin(); fListIt != fList.end(); ++fListIt)
3664 int nb = (*fListIt)->NbComponents();
3665 for ( int i = 0; i < nb; ++i ) {
3666 if ( TSideFace* comp = (*fListIt)->GetComponent( i ))
3667 fList.push_back( comp );
3669 if ( TParam2ColumnMap* cols = (*fListIt)->GetColumns()) {
3670 // columns for a base edge
3671 int id = MeshDS()->ShapeToIndex( (*fListIt)->BaseEdge() );
3672 bool isForward = (*fListIt)->IsForward();
3673 myShapeIndex2ColumnMap[ id ] = make_pair( cols, isForward );
3675 // columns for vertices
3676 const SMDS_MeshNode* n0 = cols->begin()->second.front();
3677 id = n0->getshapeId();
3678 myShapeIndex2ColumnMap[ id ] = make_pair( cols, isForward );
3680 const SMDS_MeshNode* n1 = cols->rbegin()->second.front();
3681 id = n1->getshapeId();
3682 myShapeIndex2ColumnMap[ id ] = make_pair( cols, !isForward );
3686 // #define SHOWYXZ(msg, xyz) { gp_Pnt p(xyz); cout << msg << " ("<< p.X() << "; " <<p.Y() << "; " <<p.Z() << ") " <<endl; }
3688 // double _u[]={ 0.1, 0.1, 0.9, 0.9 };
3689 // double _v[]={ 0.1, 0.9, 0.1, 0.9 };
3690 // for ( int z = 0; z < 2; ++z )
3691 // for ( int i = 0; i < 4; ++i )
3693 // //gp_XYZ testPar(0.25, 0.25, 0), testCoord;
3694 // int iFace = (z ? ID_TOP_FACE : ID_BOT_FACE);
3695 // gp_XYZ testPar(_u[i], _v[i], z), testCoord;
3696 // if ( !FacePoint( iFace, testPar, testCoord ))
3697 // RETURN_BAD_RESULT("TEST FacePoint() FAILED");
3698 // SHOWYXZ("IN TEST PARAM" , testPar);
3699 // SHOWYXZ("OUT TEST CORD" , testCoord);
3700 // if ( !ComputeParameters( testCoord, testPar , iFace))
3701 // RETURN_BAD_RESULT("TEST ComputeParameters() FAILED");
3702 // SHOWYXZ("OUT TEST PARAM" , testPar);
3707 //================================================================================
3709 * \brief Return pointer to column of nodes
3710 * \param node - bottom node from which the returned column goes up
3711 * \retval const TNodeColumn* - the found column
3713 //================================================================================
3715 const TNodeColumn* StdMeshers_PrismAsBlock::GetNodeColumn(const SMDS_MeshNode* node) const
3717 int sID = node->getshapeId();
3719 map<int, pair< TParam2ColumnMap*, bool > >::const_iterator col_frw =
3720 myShapeIndex2ColumnMap.find( sID );
3721 if ( col_frw != myShapeIndex2ColumnMap.end() ) {
3722 const TParam2ColumnMap* cols = col_frw->second.first;
3723 TParam2ColumnIt u_col = cols->begin();
3724 for ( ; u_col != cols->end(); ++u_col )
3725 if ( u_col->second[ 0 ] == node )
3726 return & u_col->second;
3731 //=======================================================================
3732 //function : GetLayersTransformation
3733 //purpose : Return transformations to get coordinates of nodes of each layer
3734 // by nodes of the bottom. Layer is a set of nodes at a certain step
3735 // from bottom to top.
3736 // Transformation to get top node from bottom ones is computed
3737 // only if the top FACE is not meshed.
3738 //=======================================================================
3740 bool StdMeshers_PrismAsBlock::GetLayersTransformation(vector<gp_Trsf> & trsf,
3741 const Prism_3D::TPrismTopo& prism) const
3743 const bool itTopMeshed = !SubMesh( ID_BOT_FACE )->IsEmpty();
3744 const int zSize = VerticalSize();
3745 if ( zSize < 3 && !itTopMeshed ) return true;
3746 trsf.resize( zSize - 1 );
3748 // Select some node columns by which we will define coordinate system of layers
3750 vector< const TNodeColumn* > columns;
3753 list< TopoDS_Edge >::const_iterator edgeIt = prism.myBottomEdges.begin();
3754 for ( int iE = 0; iE < prism.myNbEdgesInWires.front(); ++iE, ++edgeIt )
3756 if ( SMESH_Algo::isDegenerated( *edgeIt )) continue;
3757 const TParam2ColumnMap* u2colMap =
3758 GetParam2ColumnMap( MeshDS()->ShapeToIndex( *edgeIt ), isReverse );
3759 if ( !u2colMap ) return false;
3760 double f = u2colMap->begin()->first, l = u2colMap->rbegin()->first;
3761 //isReverse = ( edgeIt->Orientation() == TopAbs_REVERSED );
3762 //if ( isReverse ) swap ( f, l ); -- u2colMap takes orientation into account
3763 const int nbCol = 5;
3764 for ( int i = 0; i < nbCol; ++i )
3766 double u = f + i/double(nbCol) * ( l - f );
3767 const TNodeColumn* col = & getColumn( u2colMap, u )->second;
3768 if ( columns.empty() || col != columns.back() )
3769 columns.push_back( col );
3774 // Find tolerance to check transformations
3779 for ( size_t i = 0; i < columns.size(); ++i )
3780 bndBox.Add( gpXYZ( columns[i]->front() ));
3781 tol2 = bndBox.SquareExtent() * 1e-5;
3784 // Compute transformations
3787 gp_Trsf fromCsZ, toCs0;
3788 gp_Ax3 cs0 = getLayerCoordSys(0, columns, xCol );
3789 //double dist0 = cs0.Location().Distance( gpXYZ( (*columns[0])[0]));
3790 toCs0.SetTransformation( cs0 );
3791 for ( int z = 1; z < zSize; ++z )
3793 gp_Ax3 csZ = getLayerCoordSys(z, columns, xCol );
3794 //double distZ = csZ.Location().Distance( gpXYZ( (*columns[0])[z]));
3795 fromCsZ.SetTransformation( csZ );
3797 gp_Trsf& t = trsf[ z-1 ];
3798 t = fromCsZ * toCs0;
3799 //t.SetScaleFactor( distZ/dist0 ); - it does not work properly, wrong base point
3801 // check a transformation
3802 for ( size_t i = 0; i < columns.size(); ++i )
3804 gp_Pnt p0 = gpXYZ( (*columns[i])[0] );
3805 gp_Pnt pz = gpXYZ( (*columns[i])[z] );
3806 t.Transforms( p0.ChangeCoord() );
3807 if ( p0.SquareDistance( pz ) > tol2 )
3810 return ( z == zSize - 1 ); // OK if fails only botton->top trsf
3817 //================================================================================
3819 * \brief Check curve orientation of a bootom edge
3820 * \param meshDS - mesh DS
3821 * \param columnsMap - node columns map of side face
3822 * \param bottomEdge - the bootom edge
3823 * \param sideFaceID - side face in-block ID
3824 * \retval bool - true if orientation coinside with in-block forward orientation
3826 //================================================================================
3828 bool StdMeshers_PrismAsBlock::IsForwardEdge(SMESHDS_Mesh* meshDS,
3829 const TParam2ColumnMap& columnsMap,
3830 const TopoDS_Edge & bottomEdge,
3831 const int sideFaceID)
3833 bool isForward = false;
3834 if ( SMESH_MesherHelper::IsClosedEdge( bottomEdge ))
3836 isForward = ( bottomEdge.Orientation() == TopAbs_FORWARD );
3840 const TNodeColumn& firstCol = columnsMap.begin()->second;
3841 const SMDS_MeshNode* bottomNode = firstCol[0];
3842 TopoDS_Shape firstVertex = SMESH_MesherHelper::GetSubShapeByNode( bottomNode, meshDS );
3843 isForward = ( firstVertex.IsSame( TopExp::FirstVertex( bottomEdge, true )));
3845 // on 2 of 4 sides first vertex is end
3846 if ( sideFaceID == ID_Fx1z || sideFaceID == ID_F0yz )
3847 isForward = !isForward;
3851 //=======================================================================
3852 //function : faceGridToPythonDump
3853 //purpose : Prints a script creating a normal grid on the prism side
3854 //=======================================================================
3856 void StdMeshers_PrismAsBlock::faceGridToPythonDump(const SMESH_Block::TShapeID face,
3860 gp_XYZ pOnF[6] = { gp_XYZ(0,0,0), gp_XYZ(0,0,1),
3861 gp_XYZ(0,0,0), gp_XYZ(0,1,0),
3862 gp_XYZ(0,0,0), gp_XYZ(1,0,0) };
3864 cout << "mesh = smesh.Mesh( 'Face " << face << "')" << endl;
3865 SMESH_Block::TFace& f = myFace[ face - ID_FirstF ];
3866 gp_XYZ params = pOnF[ face - ID_FirstF ];
3867 //const int nb = 10; // nb face rows
3868 for ( int j = 0; j <= nb; ++j )
3870 params.SetCoord( f.GetVInd(), double( j )/ nb );
3871 for ( int i = 0; i <= nb; ++i )
3873 params.SetCoord( f.GetUInd(), double( i )/ nb );
3874 gp_XYZ p = f.Point( params );
3875 gp_XY uv = f.GetUV( params );
3876 cout << "mesh.AddNode( " << p.X() << ", " << p.Y() << ", " << p.Z() << " )"
3877 << " # " << 1 + i + j * ( nb + 1 )
3878 << " ( " << i << ", " << j << " ) "
3879 << " UV( " << uv.X() << ", " << uv.Y() << " )" << endl;
3880 ShellPoint( params, p2 );
3881 double dist = ( p2 - p ).Modulus();
3883 cout << "#### dist from ShellPoint " << dist
3884 << " (" << p2.X() << ", " << p2.Y() << ", " << p2.Z() << " ) " << endl;
3887 for ( int j = 0; j < nb; ++j )
3888 for ( int i = 0; i < nb; ++i )
3890 int n = 1 + i + j * ( nb + 1 );
3891 cout << "mesh.AddFace([ "
3892 << n << ", " << n+1 << ", "
3893 << n+nb+2 << ", " << n+nb+1 << "]) " << endl;
3899 //================================================================================
3901 * \brief Constructor
3902 * \param faceID - in-block ID
3903 * \param face - geom FACE
3904 * \param baseEdge - EDGE proreply oriented in the bottom EDGE !!!
3905 * \param columnsMap - map of node columns
3906 * \param first - first normalized param
3907 * \param last - last normalized param
3909 //================================================================================
3911 StdMeshers_PrismAsBlock::TSideFace::TSideFace(SMESH_Mesh& mesh,
3913 const Prism_3D::TQuadList& quadList,
3914 const TopoDS_Edge& baseEdge,
3915 TParam2ColumnMap* columnsMap,
3919 myParamToColumnMap( columnsMap ),
3922 myParams.resize( 1 );
3923 myParams[ 0 ] = make_pair( first, last );
3924 mySurface = PSurface( new BRepAdaptor_Surface( quadList.front()->face ));
3925 myBaseEdge = baseEdge;
3926 myIsForward = StdMeshers_PrismAsBlock::IsForwardEdge( myHelper.GetMeshDS(),
3927 *myParamToColumnMap,
3929 myHelper.SetSubShape( quadList.front()->face );
3931 if ( quadList.size() > 1 ) // side is vertically composite
3933 // fill myShapeID2Surf map to enable finding a right surface by any sub-shape ID
3935 SMESHDS_Mesh* meshDS = myHelper.GetMeshDS();
3937 TopTools_IndexedDataMapOfShapeListOfShape subToFaces;
3938 Prism_3D::TQuadList::const_iterator quad = quadList.begin();
3939 for ( ; quad != quadList.end(); ++quad )
3941 const TopoDS_Face& face = (*quad)->face;
3942 TopExp::MapShapesAndAncestors( face, TopAbs_VERTEX, TopAbs_FACE, subToFaces );
3943 TopExp::MapShapesAndAncestors( face, TopAbs_EDGE, TopAbs_FACE, subToFaces );
3944 myShapeID2Surf.insert( make_pair( meshDS->ShapeToIndex( face ),
3945 PSurface( new BRepAdaptor_Surface( face ))));
3947 for ( int i = 1; i <= subToFaces.Extent(); ++i )
3949 const TopoDS_Shape& sub = subToFaces.FindKey( i );
3950 TopTools_ListOfShape& faces = subToFaces( i );
3951 int subID = meshDS->ShapeToIndex( sub );
3952 int faceID = meshDS->ShapeToIndex( faces.First() );
3953 myShapeID2Surf.insert ( make_pair( subID, myShapeID2Surf[ faceID ]));
3958 //================================================================================
3960 * \brief Constructor of a complex side face
3962 //================================================================================
3964 StdMeshers_PrismAsBlock::TSideFace::
3965 TSideFace(SMESH_Mesh& mesh,
3966 const vector< TSideFace* >& components,
3967 const vector< pair< double, double> > & params)
3968 :myID( components[0] ? components[0]->myID : 0 ),
3969 myParamToColumnMap( 0 ),
3971 myIsForward( true ),
3972 myComponents( components ),
3975 if ( myID == ID_Fx1z || myID == ID_F0yz )
3977 // reverse components
3978 std::reverse( myComponents.begin(), myComponents.end() );
3979 std::reverse( myParams.begin(), myParams.end() );
3980 for ( size_t i = 0; i < myParams.size(); ++i )
3982 const double f = myParams[i].first;
3983 const double l = myParams[i].second;
3984 myParams[i] = make_pair( 1. - l, 1. - f );
3988 //================================================================================
3990 * \brief Copy constructor
3991 * \param other - other side
3993 //================================================================================
3995 StdMeshers_PrismAsBlock::TSideFace::TSideFace( const TSideFace& other ):
3996 myID ( other.myID ),
3997 myParamToColumnMap ( other.myParamToColumnMap ),
3998 mySurface ( other.mySurface ),
3999 myBaseEdge ( other.myBaseEdge ),
4000 myShapeID2Surf ( other.myShapeID2Surf ),
4001 myParams ( other.myParams ),
4002 myIsForward ( other.myIsForward ),
4003 myComponents ( other.myComponents.size() ),
4004 myHelper ( *other.myHelper.GetMesh() )
4006 for ( size_t i = 0 ; i < myComponents.size(); ++i )
4007 myComponents[ i ] = new TSideFace( *other.myComponents[ i ]);
4010 //================================================================================
4012 * \brief Deletes myComponents
4014 //================================================================================
4016 StdMeshers_PrismAsBlock::TSideFace::~TSideFace()
4018 for ( size_t i = 0 ; i < myComponents.size(); ++i )
4019 if ( myComponents[ i ] )
4020 delete myComponents[ i ];
4023 //================================================================================
4025 * \brief Return geometry of the vertical curve
4026 * \param isMax - true means curve located closer to (1,1,1) block point
4027 * \retval Adaptor3d_Curve* - curve adaptor
4029 //================================================================================
4031 Adaptor3d_Curve* StdMeshers_PrismAsBlock::TSideFace::VertiCurve(const bool isMax) const
4033 if ( !myComponents.empty() ) {
4035 return myComponents.back()->VertiCurve(isMax);
4037 return myComponents.front()->VertiCurve(isMax);
4039 double f = myParams[0].first, l = myParams[0].second;
4040 if ( !myIsForward ) std::swap( f, l );
4041 return new TVerticalEdgeAdaptor( myParamToColumnMap, isMax ? l : f );
4044 //================================================================================
4046 * \brief Return geometry of the top or bottom curve
4048 * \retval Adaptor3d_Curve* -
4050 //================================================================================
4052 Adaptor3d_Curve* StdMeshers_PrismAsBlock::TSideFace::HorizCurve(const bool isTop) const
4054 return new THorizontalEdgeAdaptor( this, isTop );
4057 //================================================================================
4059 * \brief Return pcurves
4060 * \param pcurv - array of 4 pcurves
4061 * \retval bool - is a success
4063 //================================================================================
4065 bool StdMeshers_PrismAsBlock::TSideFace::GetPCurves(Adaptor2d_Curve2d* pcurv[4]) const
4067 int iEdge[ 4 ] = { BOTTOM_EDGE, TOP_EDGE, V0_EDGE, V1_EDGE };
4069 for ( int i = 0 ; i < 4 ; ++i ) {
4070 Handle(Geom2d_Line) line;
4071 switch ( iEdge[ i ] ) {
4073 line = new Geom2d_Line( gp_Pnt2d( 0, 1 ), gp::DX2d() ); break;
4075 line = new Geom2d_Line( gp::Origin2d(), gp::DX2d() ); break;
4077 line = new Geom2d_Line( gp::Origin2d(), gp::DY2d() ); break;
4079 line = new Geom2d_Line( gp_Pnt2d( 1, 0 ), gp::DY2d() ); break;
4081 pcurv[ i ] = new Geom2dAdaptor_Curve( line, 0, 1 );
4086 //================================================================================
4088 * \brief Returns geometry of pcurve on a horizontal face
4089 * \param isTop - is top or bottom face
4090 * \param horFace - a horizontal face
4091 * \retval Adaptor2d_Curve2d* - curve adaptor
4093 //================================================================================
4096 StdMeshers_PrismAsBlock::TSideFace::HorizPCurve(const bool isTop,
4097 const TopoDS_Face& horFace) const
4099 return new TPCurveOnHorFaceAdaptor( this, isTop, horFace );
4102 //================================================================================
4104 * \brief Return a component corresponding to parameter
4105 * \param U - parameter along a horizontal size
4106 * \param localU - parameter along a horizontal size of a component
4107 * \retval TSideFace* - found component
4109 //================================================================================
4111 StdMeshers_PrismAsBlock::TSideFace*
4112 StdMeshers_PrismAsBlock::TSideFace::GetComponent(const double U,double & localU) const
4115 if ( myComponents.empty() )
4116 return const_cast<TSideFace*>( this );
4119 for ( i = 0; i < myComponents.size(); ++i )
4120 if ( U < myParams[ i ].second )
4122 if ( i >= myComponents.size() )
4123 i = myComponents.size() - 1;
4125 double f = myParams[ i ].first, l = myParams[ i ].second;
4126 localU = ( U - f ) / ( l - f );
4127 return myComponents[ i ];
4130 //================================================================================
4132 * \brief Find node columns for a parameter
4133 * \param U - parameter along a horizontal edge
4134 * \param col1 - the 1st found column
4135 * \param col2 - the 2nd found column
4136 * \retval r - normalized position of U between the found columns
4138 //================================================================================
4140 double StdMeshers_PrismAsBlock::TSideFace::GetColumns(const double U,
4141 TParam2ColumnIt & col1,
4142 TParam2ColumnIt & col2) const
4144 double u = U, r = 0;
4145 if ( !myComponents.empty() ) {
4146 TSideFace * comp = GetComponent(U,u);
4147 return comp->GetColumns( u, col1, col2 );
4152 double f = myParams[0].first, l = myParams[0].second;
4153 u = f + u * ( l - f );
4155 col1 = col2 = getColumn( myParamToColumnMap, u );
4156 if ( ++col2 == myParamToColumnMap->end() ) {
4161 double uf = col1->first;
4162 double ul = col2->first;
4163 r = ( u - uf ) / ( ul - uf );
4168 //================================================================================
4170 * \brief Return all nodes at a given height together with their normalized parameters
4171 * \param [in] Z - the height of interest
4172 * \param [out] nodes - map of parameter to node
4174 //================================================================================
4176 void StdMeshers_PrismAsBlock::
4177 TSideFace::GetNodesAtZ(const int Z,
4178 map<double, const SMDS_MeshNode* >& nodes ) const
4180 if ( !myComponents.empty() )
4183 for ( size_t i = 0; i < myComponents.size(); ++i )
4185 map<double, const SMDS_MeshNode* > nn;
4186 myComponents[i]->GetNodesAtZ( Z, nn );
4187 map<double, const SMDS_MeshNode* >::iterator u2n = nn.begin();
4188 if ( !nodes.empty() && nodes.rbegin()->second == u2n->second )
4190 const double uRange = myParams[i].second - myParams[i].first;
4191 for ( ; u2n != nn.end(); ++u2n )
4192 nodes.insert( nodes.end(), make_pair( u0 + uRange * u2n->first, u2n->second ));
4198 double f = myParams[0].first, l = myParams[0].second;
4201 const double uRange = l - f;
4202 if ( Abs( uRange ) < std::numeric_limits<double>::min() )
4204 TParam2ColumnIt u2col = getColumn( myParamToColumnMap, myParams[0].first + 1e-3 );
4205 for ( ; u2col != myParamToColumnMap->end(); ++u2col )
4206 if ( u2col->first > myParams[0].second + 1e-9 )
4209 nodes.insert( nodes.end(),
4210 make_pair( ( u2col->first - f ) / uRange, u2col->second[ Z ] ));
4214 //================================================================================
4216 * \brief Return coordinates by normalized params
4217 * \param U - horizontal param
4218 * \param V - vertical param
4219 * \retval gp_Pnt - result point
4221 //================================================================================
4223 gp_Pnt StdMeshers_PrismAsBlock::TSideFace::Value(const Standard_Real U,
4224 const Standard_Real V) const
4226 if ( !myComponents.empty() ) {
4228 TSideFace * comp = GetComponent(U,u);
4229 return comp->Value( u, V );
4232 TParam2ColumnIt u_col1, u_col2;
4233 double vR, hR = GetColumns( U, u_col1, u_col2 );
4235 const SMDS_MeshNode* nn[4];
4237 // BEGIN issue 0020680: Bad cell created by Radial prism in center of torus
4238 // Workaround for a wrongly located point returned by mySurface.Value() for
4239 // UV located near boundary of BSpline surface.
4240 // To bypass the problem, we take point from 3D curve of EDGE.
4241 // It solves pb of the bloc_fiss_new.py
4242 const double tol = 1e-3;
4243 if ( V < tol || V+tol >= 1. )
4245 nn[0] = V < tol ? u_col1->second.front() : u_col1->second.back();
4246 nn[2] = V < tol ? u_col2->second.front() : u_col2->second.back();
4254 TopoDS_Shape s = myHelper.GetSubShapeByNode( nn[0], myHelper.GetMeshDS() );
4255 if ( s.ShapeType() != TopAbs_EDGE )
4256 s = myHelper.GetSubShapeByNode( nn[2], myHelper.GetMeshDS() );
4257 if ( !s.IsNull() && s.ShapeType() == TopAbs_EDGE )
4258 edge = TopoDS::Edge( s );
4260 if ( !edge.IsNull() )
4262 double u1 = myHelper.GetNodeU( edge, nn[0], nn[2] );
4263 double u3 = myHelper.GetNodeU( edge, nn[2], nn[0] );
4264 double u = u1 * ( 1 - hR ) + u3 * hR;
4265 TopLoc_Location loc; double f,l;
4266 Handle(Geom_Curve) curve = BRep_Tool::Curve( edge,loc,f,l );
4267 return curve->Value( u ).Transformed( loc );
4270 // END issue 0020680: Bad cell created by Radial prism in center of torus
4272 vR = getRAndNodes( & u_col1->second, V, nn[0], nn[1] );
4273 vR = getRAndNodes( & u_col2->second, V, nn[2], nn[3] );
4275 if ( !myShapeID2Surf.empty() ) // side is vertically composite
4277 // find a FACE on which the 4 nodes lie
4278 TSideFace* me = (TSideFace*) this;
4279 int notFaceID1 = 0, notFaceID2 = 0;
4280 for ( int i = 0; i < 4; ++i )
4281 if ( nn[i]->GetPosition()->GetTypeOfPosition() == SMDS_TOP_FACE ) // node on FACE
4283 me->mySurface = me->myShapeID2Surf[ nn[i]->getshapeId() ];
4287 else if ( notFaceID1 == 0 ) // node on EDGE or VERTEX
4289 me->mySurface = me->myShapeID2Surf[ nn[i]->getshapeId() ];
4290 notFaceID1 = nn[i]->getshapeId();
4292 else if ( notFaceID1 != nn[i]->getshapeId() ) // node on other EDGE or VERTEX
4294 if ( mySurface != me->myShapeID2Surf[ nn[i]->getshapeId() ])
4295 notFaceID2 = nn[i]->getshapeId();
4297 if ( notFaceID2 ) // no nodes of FACE and nodes are on different FACEs
4299 SMESHDS_Mesh* meshDS = myHelper.GetMeshDS();
4300 TopoDS_Shape face = myHelper.GetCommonAncestor( meshDS->IndexToShape( notFaceID1 ),
4301 meshDS->IndexToShape( notFaceID2 ),
4302 *myHelper.GetMesh(),
4304 if ( face.IsNull() )
4305 throw SALOME_Exception("StdMeshers_PrismAsBlock::TSideFace::Value() face.IsNull()");
4306 int faceID = meshDS->ShapeToIndex( face );
4307 me->mySurface = me->myShapeID2Surf[ faceID ];
4309 throw SALOME_Exception("StdMeshers_PrismAsBlock::TSideFace::Value() !mySurface");
4312 ((TSideFace*) this)->myHelper.SetSubShape( mySurface->Face() );
4314 gp_XY uv1 = myHelper.GetNodeUV( mySurface->Face(), nn[0], nn[2]);
4315 gp_XY uv2 = myHelper.GetNodeUV( mySurface->Face(), nn[1], nn[3]);
4316 gp_XY uv12 = uv1 * ( 1 - vR ) + uv2 * vR;
4318 gp_XY uv3 = myHelper.GetNodeUV( mySurface->Face(), nn[2], nn[0]);
4319 gp_XY uv4 = myHelper.GetNodeUV( mySurface->Face(), nn[3], nn[1]);
4320 gp_XY uv34 = uv3 * ( 1 - vR ) + uv4 * vR;
4322 gp_XY uv = uv12 * ( 1 - hR ) + uv34 * hR;
4324 gp_Pnt p = mySurface->Value( uv.X(), uv.Y() );
4329 //================================================================================
4331 * \brief Return boundary edge
4332 * \param edge - edge index
4333 * \retval TopoDS_Edge - found edge
4335 //================================================================================
4337 TopoDS_Edge StdMeshers_PrismAsBlock::TSideFace::GetEdge(const int iEdge) const
4339 if ( !myComponents.empty() ) {
4341 case V0_EDGE : return myComponents.front()->GetEdge( iEdge );
4342 case V1_EDGE : return myComponents.back() ->GetEdge( iEdge );
4343 default: return TopoDS_Edge();
4347 const SMDS_MeshNode* node = 0;
4348 SMESHDS_Mesh * meshDS = myHelper.GetMesh()->GetMeshDS();
4349 TNodeColumn* column;
4354 column = & (( ++myParamToColumnMap->begin())->second );
4355 node = ( iEdge == TOP_EDGE ) ? column->back() : column->front();
4356 edge = myHelper.GetSubShapeByNode ( node, meshDS );
4357 if ( edge.ShapeType() == TopAbs_VERTEX ) {
4358 column = & ( myParamToColumnMap->begin()->second );
4359 node = ( iEdge == TOP_EDGE ) ? column->back() : column->front();
4364 bool back = ( iEdge == V1_EDGE );
4365 if ( !myIsForward ) back = !back;
4367 column = & ( myParamToColumnMap->rbegin()->second );
4369 column = & ( myParamToColumnMap->begin()->second );
4370 if ( column->size() > 0 )
4371 edge = myHelper.GetSubShapeByNode( (*column)[ 1 ], meshDS );
4372 if ( edge.IsNull() || edge.ShapeType() == TopAbs_VERTEX )
4373 node = column->front();
4378 if ( !edge.IsNull() && edge.ShapeType() == TopAbs_EDGE )
4379 return TopoDS::Edge( edge );
4381 // find edge by 2 vertices
4382 TopoDS_Shape V1 = edge;
4383 TopoDS_Shape V2 = myHelper.GetSubShapeByNode( node, meshDS );
4384 if ( !V2.IsNull() && V2.ShapeType() == TopAbs_VERTEX && !V2.IsSame( V1 ))
4386 TopoDS_Shape ancestor = myHelper.GetCommonAncestor( V1, V2, *myHelper.GetMesh(), TopAbs_EDGE);
4387 if ( !ancestor.IsNull() )
4388 return TopoDS::Edge( ancestor );
4390 return TopoDS_Edge();
4393 //================================================================================
4395 * \brief Fill block sub-shapes
4396 * \param shapeMap - map to fill in
4397 * \retval int - nb inserted sub-shapes
4399 //================================================================================
4401 int StdMeshers_PrismAsBlock::TSideFace::InsertSubShapes(TBlockShapes& shapeMap) const
4406 vector< int > edgeIdVec;
4407 SMESH_Block::GetFaceEdgesIDs( myID, edgeIdVec );
4409 for ( int i = BOTTOM_EDGE; i <=V1_EDGE ; ++i ) {
4410 TopoDS_Edge e = GetEdge( i );
4411 if ( !e.IsNull() ) {
4412 nbInserted += SMESH_Block::Insert( e, edgeIdVec[ i ], shapeMap);
4416 // Insert corner vertices
4418 TParam2ColumnIt col1, col2 ;
4419 vector< int > vertIdVec;
4422 SMESH_Block::GetEdgeVertexIDs( edgeIdVec[ V0_EDGE ], vertIdVec);
4423 GetColumns(0, col1, col2 );
4424 const SMDS_MeshNode* node0 = col1->second.front();
4425 const SMDS_MeshNode* node1 = col1->second.back();
4426 TopoDS_Shape v0 = myHelper.GetSubShapeByNode( node0, myHelper.GetMeshDS());
4427 TopoDS_Shape v1 = myHelper.GetSubShapeByNode( node1, myHelper.GetMeshDS());
4428 if ( v0.ShapeType() == TopAbs_VERTEX ) {
4429 nbInserted += SMESH_Block::Insert( v0, vertIdVec[ 0 ], shapeMap);
4431 if ( v1.ShapeType() == TopAbs_VERTEX ) {
4432 nbInserted += SMESH_Block::Insert( v1, vertIdVec[ 1 ], shapeMap);
4436 SMESH_Block::GetEdgeVertexIDs( edgeIdVec[ V1_EDGE ], vertIdVec);
4437 GetColumns(1, col1, col2 );
4438 node0 = col2->second.front();
4439 node1 = col2->second.back();
4440 v0 = myHelper.GetSubShapeByNode( node0, myHelper.GetMeshDS());
4441 v1 = myHelper.GetSubShapeByNode( node1, myHelper.GetMeshDS());
4442 if ( v0.ShapeType() == TopAbs_VERTEX ) {
4443 nbInserted += SMESH_Block::Insert( v0, vertIdVec[ 0 ], shapeMap);
4445 if ( v1.ShapeType() == TopAbs_VERTEX ) {
4446 nbInserted += SMESH_Block::Insert( v1, vertIdVec[ 1 ], shapeMap);
4449 // TopoDS_Vertex V0, V1, Vcom;
4450 // TopExp::Vertices( myBaseEdge, V0, V1, true );
4451 // if ( !myIsForward ) std::swap( V0, V1 );
4453 // // bottom vertex IDs
4454 // SMESH_Block::GetEdgeVertexIDs( edgeIdVec[ _u0 ], vertIdVec);
4455 // SMESH_Block::Insert( V0, vertIdVec[ 0 ], shapeMap);
4456 // SMESH_Block::Insert( V1, vertIdVec[ 1 ], shapeMap);
4458 // TopoDS_Edge sideEdge = GetEdge( V0_EDGE );
4459 // if ( sideEdge.IsNull() || !TopExp::CommonVertex( botEdge, sideEdge, Vcom ))
4462 // // insert one side edge
4464 // if ( Vcom.IsSame( V0 )) edgeID = edgeIdVec[ _v0 ];
4465 // else edgeID = edgeIdVec[ _v1 ];
4466 // SMESH_Block::Insert( sideEdge, edgeID, shapeMap);
4468 // // top vertex of the side edge
4469 // SMESH_Block::GetEdgeVertexIDs( edgeID, vertIdVec);
4470 // TopoDS_Vertex Vtop = TopExp::FirstVertex( sideEdge );
4471 // if ( Vcom.IsSame( Vtop ))
4472 // Vtop = TopExp::LastVertex( sideEdge );
4473 // SMESH_Block::Insert( Vtop, vertIdVec[ 1 ], shapeMap);
4475 // // other side edge
4476 // sideEdge = GetEdge( V1_EDGE );
4477 // if ( sideEdge.IsNull() )
4479 // if ( edgeID = edgeIdVec[ _v1 ]) edgeID = edgeIdVec[ _v0 ];
4480 // else edgeID = edgeIdVec[ _v1 ];
4481 // SMESH_Block::Insert( sideEdge, edgeID, shapeMap);
4484 // TopoDS_Edge topEdge = GetEdge( TOP_EDGE );
4485 // SMESH_Block::Insert( topEdge, edgeIdVec[ _u1 ], shapeMap);
4487 // // top vertex of the other side edge
4488 // if ( !TopExp::CommonVertex( topEdge, sideEdge, Vcom ))
4490 // SMESH_Block::GetEdgeVertexIDs( edgeID, vertIdVec );
4491 // SMESH_Block::Insert( Vcom, vertIdVec[ 1 ], shapeMap);
4496 //================================================================================
4498 * \brief Dump ids of nodes of sides
4500 //================================================================================
4502 void StdMeshers_PrismAsBlock::TSideFace::dumpNodes(int nbNodes) const
4505 cout << endl << "NODES OF FACE "; SMESH_Block::DumpShapeID( myID, cout ) << endl;
4506 THorizontalEdgeAdaptor* hSize0 = (THorizontalEdgeAdaptor*) HorizCurve(0);
4507 cout << "Horiz side 0: "; hSize0->dumpNodes(nbNodes); cout << endl;
4508 THorizontalEdgeAdaptor* hSize1 = (THorizontalEdgeAdaptor*) HorizCurve(1);
4509 cout << "Horiz side 1: "; hSize1->dumpNodes(nbNodes); cout << endl;
4510 TVerticalEdgeAdaptor* vSide0 = (TVerticalEdgeAdaptor*) VertiCurve(0);
4511 cout << "Verti side 0: "; vSide0->dumpNodes(nbNodes); cout << endl;
4512 TVerticalEdgeAdaptor* vSide1 = (TVerticalEdgeAdaptor*) VertiCurve(1);
4513 cout << "Verti side 1: "; vSide1->dumpNodes(nbNodes); cout << endl;
4514 delete hSize0; delete hSize1; delete vSide0; delete vSide1;
4518 //================================================================================
4520 * \brief Creates TVerticalEdgeAdaptor
4521 * \param columnsMap - node column map
4522 * \param parameter - normalized parameter
4524 //================================================================================
4526 StdMeshers_PrismAsBlock::TVerticalEdgeAdaptor::
4527 TVerticalEdgeAdaptor( const TParam2ColumnMap* columnsMap, const double parameter)
4529 myNodeColumn = & getColumn( columnsMap, parameter )->second;
4532 //================================================================================
4534 * \brief Return coordinates for the given normalized parameter
4535 * \param U - normalized parameter
4536 * \retval gp_Pnt - coordinates
4538 //================================================================================
4540 gp_Pnt StdMeshers_PrismAsBlock::TVerticalEdgeAdaptor::Value(const Standard_Real U) const
4542 const SMDS_MeshNode* n1;
4543 const SMDS_MeshNode* n2;
4544 double r = getRAndNodes( myNodeColumn, U, n1, n2 );
4545 return gpXYZ(n1) * ( 1 - r ) + gpXYZ(n2) * r;
4548 //================================================================================
4550 * \brief Dump ids of nodes
4552 //================================================================================
4554 void StdMeshers_PrismAsBlock::TVerticalEdgeAdaptor::dumpNodes(int nbNodes) const
4557 for ( int i = 0; i < nbNodes && i < (int)myNodeColumn->size(); ++i )
4558 cout << (*myNodeColumn)[i]->GetID() << " ";
4559 if ( nbNodes < (int) myNodeColumn->size() )
4560 cout << myNodeColumn->back()->GetID();
4564 //================================================================================
4566 * \brief Return coordinates for the given normalized parameter
4567 * \param U - normalized parameter
4568 * \retval gp_Pnt - coordinates
4570 //================================================================================
4572 gp_Pnt StdMeshers_PrismAsBlock::THorizontalEdgeAdaptor::Value(const Standard_Real U) const
4574 return mySide->TSideFace::Value( U, myV );
4577 //================================================================================
4579 * \brief Dump ids of <nbNodes> first nodes and the last one
4581 //================================================================================
4583 void StdMeshers_PrismAsBlock::THorizontalEdgeAdaptor::dumpNodes(int nbNodes) const
4586 // Not bedugged code. Last node is sometimes incorrect
4587 const TSideFace* side = mySide;
4589 if ( mySide->IsComplex() )
4590 side = mySide->GetComponent(0,u);
4592 TParam2ColumnIt col, col2;
4593 TParam2ColumnMap* u2cols = side->GetColumns();
4594 side->GetColumns( u , col, col2 );
4596 int j, i = myV ? mySide->ColumnHeight()-1 : 0;
4598 const SMDS_MeshNode* n = 0;
4599 const SMDS_MeshNode* lastN
4600 = side->IsForward() ? u2cols->rbegin()->second[ i ] : u2cols->begin()->second[ i ];
4601 for ( j = 0; j < nbNodes && n != lastN; ++j )
4603 n = col->second[ i ];
4604 cout << n->GetID() << " ";
4605 if ( side->IsForward() )
4613 if ( mySide->IsComplex() )
4614 side = mySide->GetComponent(1,u);
4616 side->GetColumns( u , col, col2 );
4617 if ( n != col->second[ i ] )
4618 cout << col->second[ i ]->GetID();
4622 //================================================================================
4624 * \brief Costructor of TPCurveOnHorFaceAdaptor fills its map of
4625 * normalized parameter to node UV on a horizontal face
4626 * \param [in] sideFace - lateral prism side
4627 * \param [in] isTop - is \a horFace top or bottom of the prism
4628 * \param [in] horFace - top or bottom face of the prism
4630 //================================================================================
4632 StdMeshers_PrismAsBlock::
4633 TPCurveOnHorFaceAdaptor::TPCurveOnHorFaceAdaptor( const TSideFace* sideFace,
4635 const TopoDS_Face& horFace)
4637 if ( sideFace && !horFace.IsNull() )
4639 //cout << "\n\t FACE " << sideFace->FaceID() << endl;
4640 const int Z = isTop ? sideFace->ColumnHeight() - 1 : 0;
4641 map<double, const SMDS_MeshNode* > u2nodes;
4642 sideFace->GetNodesAtZ( Z, u2nodes );
4643 if ( u2nodes.empty() )
4646 SMESH_MesherHelper helper( *sideFace->GetMesh() );
4647 helper.SetSubShape( horFace );
4652 Handle(Geom2d_Curve) C2d;
4654 const double tol = 10 * helper.MaxTolerance( horFace );
4655 const SMDS_MeshNode* prevNode = u2nodes.rbegin()->second;
4657 map<double, const SMDS_MeshNode* >::iterator u2n = u2nodes.begin();
4658 for ( ; u2n != u2nodes.end(); ++u2n )
4660 const SMDS_MeshNode* n = u2n->second;
4662 if ( n->GetPosition()->GetTypeOfPosition() == SMDS_TOP_EDGE )
4664 if ( n->getshapeId() != edgeID )
4667 edgeID = n->getshapeId();
4668 TopoDS_Shape S = helper.GetSubShapeByNode( n, helper.GetMeshDS() );
4669 if ( !S.IsNull() && S.ShapeType() == TopAbs_EDGE )
4671 C2d = BRep_Tool::CurveOnSurface( TopoDS::Edge( S ), horFace, f,l );
4674 if ( !C2d.IsNull() )
4676 double u = static_cast< const SMDS_EdgePosition* >( n->GetPosition() )->GetUParameter();
4677 if ( f <= u && u <= l )
4679 uv = C2d->Value( u ).XY();
4680 okUV = helper.CheckNodeUV( horFace, n, uv, tol );
4685 uv = helper.GetNodeUV( horFace, n, prevNode, &okUV );
4687 myUVmap.insert( myUVmap.end(), make_pair( u2n->first, uv ));
4688 // cout << n->getshapeId() << " N " << n->GetID()
4689 // << " \t" << uv.X() << ", " << uv.Y() << " \t" << u2n->first << endl;
4696 //================================================================================
4698 * \brief Return UV on pcurve for the given normalized parameter
4699 * \param U - normalized parameter
4700 * \retval gp_Pnt - coordinates
4702 //================================================================================
4704 gp_Pnt2d StdMeshers_PrismAsBlock::TPCurveOnHorFaceAdaptor::Value(const Standard_Real U) const
4706 map< double, gp_XY >::const_iterator i1 = myUVmap.upper_bound( U );
4708 if ( i1 == myUVmap.end() )
4709 return myUVmap.empty() ? gp_XY(0,0) : myUVmap.rbegin()->second;
4711 if ( i1 == myUVmap.begin() )
4712 return (*i1).second;
4714 map< double, gp_XY >::const_iterator i2 = i1--;
4716 double r = ( U - i1->first ) / ( i2->first - i1->first );
4717 return i1->second * ( 1 - r ) + i2->second * r;
4720 //================================================================================
4722 * \brief Projects internal nodes using transformation found by boundary nodes
4724 //================================================================================
4726 bool StdMeshers_Sweeper::projectIntPoints(const vector< gp_XYZ >& fromBndPoints,
4727 const vector< gp_XYZ >& toBndPoints,
4728 const vector< gp_XYZ >& fromIntPoints,
4729 vector< gp_XYZ >& toIntPoints,
4730 NSProjUtils::TrsfFinder3D& trsf,
4731 vector< gp_XYZ > * bndError)
4733 // find transformation
4734 if ( trsf.IsIdentity() && !trsf.Solve( fromBndPoints, toBndPoints ))
4737 // compute internal points using the found trsf
4738 for ( size_t iP = 0; iP < fromIntPoints.size(); ++iP )
4740 toIntPoints[ iP ] = trsf.Transform( fromIntPoints[ iP ]);
4743 // compute boundary error
4746 bndError->resize( fromBndPoints.size() );
4748 for ( size_t iP = 0; iP < fromBndPoints.size(); ++iP )
4750 fromTrsf = trsf.Transform( fromBndPoints[ iP ] );
4751 (*bndError)[ iP ] = toBndPoints[ iP ] - fromTrsf;
4757 //================================================================================
4759 * \brief Add boundary error to ineternal points
4761 //================================================================================
4763 void StdMeshers_Sweeper::applyBoundaryError(const vector< gp_XYZ >& bndPoints,
4764 const vector< gp_XYZ >& bndError1,
4765 const vector< gp_XYZ >& bndError2,
4767 vector< gp_XYZ >& intPoints,
4768 vector< double >& int2BndDist)
4770 // fix each internal point
4771 const double eps = 1e-100;
4772 for ( size_t iP = 0; iP < intPoints.size(); ++iP )
4774 gp_XYZ & intPnt = intPoints[ iP ];
4776 // compute distance from intPnt to each boundary node
4777 double int2BndDistSum = 0;
4778 for ( size_t iBnd = 0; iBnd < bndPoints.size(); ++iBnd )
4780 int2BndDist[ iBnd ] = 1 / (( intPnt - bndPoints[ iBnd ]).SquareModulus() + eps );
4781 int2BndDistSum += int2BndDist[ iBnd ];
4785 for ( size_t iBnd = 0; iBnd < bndPoints.size(); ++iBnd )
4787 intPnt += bndError1[ iBnd ] * ( 1 - r ) * int2BndDist[ iBnd ] / int2BndDistSum;
4788 intPnt += bndError2[ iBnd ] * r * int2BndDist[ iBnd ] / int2BndDistSum;
4793 //================================================================================
4795 * \brief Create internal nodes of the prism
4797 //================================================================================
4799 bool StdMeshers_Sweeper::ComputeNodes( SMESH_MesherHelper& helper,
4801 const bool allowHighBndError)
4803 const size_t zSize = myBndColumns[0]->size();
4804 const size_t zSrc = 0, zTgt = zSize-1;
4805 if ( zSize < 3 ) return true;
4807 vector< vector< gp_XYZ > > intPntsOfLayer( zSize ); // node coodinates to compute
4808 // set coordinates of src and tgt nodes
4809 for ( size_t z = 0; z < intPntsOfLayer.size(); ++z )
4810 intPntsOfLayer[ z ].resize( myIntColumns.size() );
4811 for ( size_t iP = 0; iP < myIntColumns.size(); ++iP )
4813 intPntsOfLayer[ zSrc ][ iP ] = intPoint( iP, zSrc );
4814 intPntsOfLayer[ zTgt ][ iP ] = intPoint( iP, zTgt );
4817 // compute coordinates of internal nodes by projecting (transfroming) src and tgt
4818 // nodes towards the central layer
4820 vector< NSProjUtils::TrsfFinder3D > trsfOfLayer( zSize );
4821 vector< vector< gp_XYZ > > bndError( zSize );
4823 // boundary points used to compute an affine transformation from a layer to a next one
4824 vector< gp_XYZ > fromSrcBndPnts( myBndColumns.size() ), fromTgtBndPnts( myBndColumns.size() );
4825 vector< gp_XYZ > toSrcBndPnts ( myBndColumns.size() ), toTgtBndPnts ( myBndColumns.size() );
4826 for ( size_t iP = 0; iP < myBndColumns.size(); ++iP )
4828 fromSrcBndPnts[ iP ] = bndPoint( iP, zSrc );
4829 fromTgtBndPnts[ iP ] = bndPoint( iP, zTgt );
4832 size_t zS = zSrc + 1;
4833 size_t zT = zTgt - 1;
4834 for ( ; zS < zT; ++zS, --zT ) // vertical loop on layers
4836 for ( size_t iP = 0; iP < myBndColumns.size(); ++iP )
4838 toSrcBndPnts[ iP ] = bndPoint( iP, zS );
4839 toTgtBndPnts[ iP ] = bndPoint( iP, zT );
4841 if (! projectIntPoints( fromSrcBndPnts, toSrcBndPnts,
4842 intPntsOfLayer[ zS-1 ], intPntsOfLayer[ zS ],
4843 trsfOfLayer [ zS-1 ], & bndError[ zS-1 ]))
4845 if (! projectIntPoints( fromTgtBndPnts, toTgtBndPnts,
4846 intPntsOfLayer[ zT+1 ], intPntsOfLayer[ zT ],
4847 trsfOfLayer [ zT+1 ], & bndError[ zT+1 ]))
4850 // if ( zT == zTgt - 1 )
4852 // for ( size_t iP = 0; iP < myBndColumns.size(); ++iP )
4854 // gp_XYZ fromTrsf = trsfOfLayer [ zT+1].Transform( fromTgtBndPnts[ iP ] );
4855 // cout << "mesh.AddNode( "
4856 // << fromTrsf.X() << ", "
4857 // << fromTrsf.Y() << ", "
4858 // << fromTrsf.Z() << ") " << endl;
4860 // for ( size_t iP = 0; iP < myIntColumns.size(); ++iP )
4861 // cout << "mesh.AddNode( "
4862 // << intPntsOfLayer[ zT ][ iP ].X() << ", "
4863 // << intPntsOfLayer[ zT ][ iP ].Y() << ", "
4864 // << intPntsOfLayer[ zT ][ iP ].Z() << ") " << endl;
4867 fromTgtBndPnts.swap( toTgtBndPnts );
4868 fromSrcBndPnts.swap( toSrcBndPnts );
4871 // Compute two projections of internal points to the central layer
4872 // in order to evaluate an error of internal points
4874 bool centerIntErrorIsSmall;
4875 vector< gp_XYZ > centerSrcIntPnts( myIntColumns.size() );
4876 vector< gp_XYZ > centerTgtIntPnts( myIntColumns.size() );
4878 for ( size_t iP = 0; iP < myBndColumns.size(); ++iP )
4880 toSrcBndPnts[ iP ] = bndPoint( iP, zS );
4881 toTgtBndPnts[ iP ] = bndPoint( iP, zT );
4883 if (! projectIntPoints( fromSrcBndPnts, toSrcBndPnts,
4884 intPntsOfLayer[ zS-1 ], centerSrcIntPnts,
4885 trsfOfLayer [ zS-1 ], & bndError[ zS-1 ]))
4887 if (! projectIntPoints( fromTgtBndPnts, toTgtBndPnts,
4888 intPntsOfLayer[ zT+1 ], centerTgtIntPnts,
4889 trsfOfLayer [ zT+1 ], & bndError[ zT+1 ]))
4892 // evaluate an error of internal points on the central layer
4893 centerIntErrorIsSmall = true;
4894 if ( zS == zT ) // odd zSize
4896 for ( size_t iP = 0; ( iP < myIntColumns.size() && centerIntErrorIsSmall ); ++iP )
4897 centerIntErrorIsSmall =
4898 (centerSrcIntPnts[ iP ] - centerTgtIntPnts[ iP ]).SquareModulus() < tol*tol;
4902 for ( size_t iP = 0; ( iP < myIntColumns.size() && centerIntErrorIsSmall ); ++iP )
4903 centerIntErrorIsSmall =
4904 (intPntsOfLayer[ zS-1 ][ iP ] - centerTgtIntPnts[ iP ]).SquareModulus() < tol*tol;
4907 // Evaluate an error of boundary points
4909 bool bndErrorIsSmall = true;
4910 for ( size_t iP = 0; ( iP < myBndColumns.size() && bndErrorIsSmall ); ++iP )
4912 double sumError = 0;
4913 for ( size_t z = 1; z < zS; ++z ) // loop on layers
4914 sumError += ( bndError[ z-1 ][ iP ].Modulus() +
4915 bndError[ zSize-z ][ iP ].Modulus() );
4917 bndErrorIsSmall = ( sumError < tol );
4920 if ( !bndErrorIsSmall && !allowHighBndError )
4923 // compute final points on the central layer
4924 std::vector< double > int2BndDist( myBndColumns.size() ); // work array of applyBoundaryError()
4925 double r = zS / ( zSize - 1.);
4928 for ( size_t iP = 0; iP < myIntColumns.size(); ++iP )
4930 intPntsOfLayer[ zS ][ iP ] =
4931 ( 1 - r ) * centerSrcIntPnts[ iP ] + r * centerTgtIntPnts[ iP ];
4933 if ( !bndErrorIsSmall )
4935 applyBoundaryError( toSrcBndPnts, bndError[ zS-1 ], bndError[ zS+1 ], r,
4936 intPntsOfLayer[ zS ], int2BndDist );
4941 for ( size_t iP = 0; iP < myIntColumns.size(); ++iP )
4943 intPntsOfLayer[ zS ][ iP ] =
4944 r * intPntsOfLayer[ zS ][ iP ] + ( 1 - r ) * centerSrcIntPnts[ iP ];
4945 intPntsOfLayer[ zT ][ iP ] =
4946 r * intPntsOfLayer[ zT ][ iP ] + ( 1 - r ) * centerTgtIntPnts[ iP ];
4948 if ( !bndErrorIsSmall )
4950 applyBoundaryError( toSrcBndPnts, bndError[ zS-1 ], bndError[ zS+1 ], r,
4951 intPntsOfLayer[ zS ], int2BndDist );
4952 applyBoundaryError( toTgtBndPnts, bndError[ zT+1 ], bndError[ zT-1 ], r,
4953 intPntsOfLayer[ zT ], int2BndDist );
4957 centerIntErrorIsSmall = true; // 3D_mesh_Extrusion_00/A3
4958 bndErrorIsSmall = true;
4959 if ( !centerIntErrorIsSmall )
4961 // Compensate the central error; continue adding projection
4962 // by going from central layer to the source and target ones
4964 vector< gp_XYZ >& fromSrcIntPnts = centerSrcIntPnts;
4965 vector< gp_XYZ >& fromTgtIntPnts = centerTgtIntPnts;
4966 vector< gp_XYZ > toSrcIntPnts( myIntColumns.size() );
4967 vector< gp_XYZ > toTgtIntPnts( myIntColumns.size() );
4968 vector< gp_XYZ > srcBndError( myBndColumns.size() );
4969 vector< gp_XYZ > tgtBndError( myBndColumns.size() );
4971 fromTgtBndPnts.swap( toTgtBndPnts );
4972 fromSrcBndPnts.swap( toSrcBndPnts );
4974 for ( ++zS, --zT; zS < zTgt; ++zS, --zT ) // vertical loop on layers
4976 // invert transformation
4977 if ( !trsfOfLayer[ zS+1 ].Invert() )
4978 trsfOfLayer[ zS+1 ] = NSProjUtils::TrsfFinder3D(); // to recompute
4979 if ( !trsfOfLayer[ zT-1 ].Invert() )
4980 trsfOfLayer[ zT-1 ] = NSProjUtils::TrsfFinder3D();
4982 // project internal nodes and compute bnd error
4983 for ( size_t iP = 0; iP < myBndColumns.size(); ++iP )
4985 toSrcBndPnts[ iP ] = bndPoint( iP, zS );
4986 toTgtBndPnts[ iP ] = bndPoint( iP, zT );
4988 projectIntPoints( fromSrcBndPnts, toSrcBndPnts,
4989 fromSrcIntPnts, toSrcIntPnts,
4990 trsfOfLayer[ zS+1 ], & srcBndError );
4991 projectIntPoints( fromTgtBndPnts, toTgtBndPnts,
4992 fromTgtIntPnts, toTgtIntPnts,
4993 trsfOfLayer[ zT-1 ], & tgtBndError );
4995 // if ( zS == zTgt - 1 )
4997 // cout << "mesh2 = smesh.Mesh()" << endl;
4998 // for ( size_t iP = 0; iP < myBndColumns.size(); ++iP )
5000 // gp_XYZ fromTrsf = trsfOfLayer [ zS+1].Transform( fromSrcBndPnts[ iP ] );
5001 // cout << "mesh2.AddNode( "
5002 // << fromTrsf.X() << ", "
5003 // << fromTrsf.Y() << ", "
5004 // << fromTrsf.Z() << ") " << endl;
5006 // for ( size_t iP = 0; iP < myIntColumns.size(); ++iP )
5007 // cout << "mesh2.AddNode( "
5008 // << toSrcIntPnts[ iP ].X() << ", "
5009 // << toSrcIntPnts[ iP ].Y() << ", "
5010 // << toSrcIntPnts[ iP ].Z() << ") " << endl;
5013 // sum up 2 projections
5014 r = zS / ( zSize - 1.);
5015 vector< gp_XYZ >& zSIntPnts = intPntsOfLayer[ zS ];
5016 vector< gp_XYZ >& zTIntPnts = intPntsOfLayer[ zT ];
5017 for ( size_t iP = 0; iP < myIntColumns.size(); ++iP )
5019 zSIntPnts[ iP ] = r * zSIntPnts[ iP ] + ( 1 - r ) * toSrcIntPnts[ iP ];
5020 zTIntPnts[ iP ] = r * zTIntPnts[ iP ] + ( 1 - r ) * toTgtIntPnts[ iP ];
5023 // compensate bnd error
5024 if ( !bndErrorIsSmall )
5026 applyBoundaryError( toSrcBndPnts, srcBndError, bndError[ zS+1 ], r,
5027 intPntsOfLayer[ zS ], int2BndDist );
5028 applyBoundaryError( toTgtBndPnts, tgtBndError, bndError[ zT-1 ], r,
5029 intPntsOfLayer[ zT ], int2BndDist );
5032 fromSrcBndPnts.swap( toSrcBndPnts );
5033 fromSrcIntPnts.swap( toSrcIntPnts );
5034 fromTgtBndPnts.swap( toTgtBndPnts );
5035 fromTgtIntPnts.swap( toTgtIntPnts );
5037 } // if ( !centerIntErrorIsSmall )
5039 else if ( !bndErrorIsSmall )
5043 for ( ; zS < zT; ++zS, --zT ) // vertical loop on layers
5045 for ( size_t iP = 0; iP < myBndColumns.size(); ++iP )
5047 toSrcBndPnts[ iP ] = bndPoint( iP, zS );
5048 toTgtBndPnts[ iP ] = bndPoint( iP, zT );
5050 // compensate bnd error
5051 applyBoundaryError( toSrcBndPnts, bndError[ zS-1 ], bndError[ zS-1 ], 0.5,
5052 intPntsOfLayer[ zS ], int2BndDist );
5053 applyBoundaryError( toTgtBndPnts, bndError[ zT+1 ], bndError[ zT+1 ], 0.5,
5054 intPntsOfLayer[ zT ], int2BndDist );
5058 // cout << "centerIntErrorIsSmall = " << centerIntErrorIsSmall<< endl;
5059 // cout << "bndErrorIsSmall = " << bndErrorIsSmall<< endl;
5062 for ( size_t iP = 0; iP < myIntColumns.size(); ++iP )
5064 vector< const SMDS_MeshNode* > & nodeCol = *myIntColumns[ iP ];
5065 for ( size_t z = zSrc + 1; z < zTgt; ++z ) // vertical loop on layers
5067 const gp_XYZ & xyz = intPntsOfLayer[ z ][ iP ];
5068 if ( !( nodeCol[ z ] = helper.AddNode( xyz.X(), xyz.Y(), xyz.Z() )))
5076 //================================================================================
5078 * \brief Check if all nodes of each layers have same logical Z
5080 //================================================================================
5082 bool StdMeshers_Sweeper::CheckSameZ()
5084 myZColumns.resize( myBndColumns.size() );
5085 fillZColumn( myZColumns[0], *myBndColumns[0] );
5088 const double tol = 0.1 * 1./ myBndColumns[0]->size();
5090 // check columns based on VERTEXes
5092 vector< int > vertexIndex;
5093 vertexIndex.push_back( 0 );
5094 for ( size_t iC = 1; iC < myBndColumns.size() && sameZ; ++iC )
5096 if ( myBndColumns[iC]->front()->GetPosition()->GetDim() > 0 )
5097 continue; // not on VERTEX
5099 vertexIndex.push_back( iC );
5100 fillZColumn( myZColumns[iC], *myBndColumns[iC] );
5102 for ( size_t iZ = 0; iZ < myZColumns[0].size() && sameZ; ++iZ )
5103 sameZ = ( Abs( myZColumns[0][iZ] - myZColumns[iC][iZ]) < tol );
5106 // check columns based on EDGEs, one per EDGE
5108 for ( size_t i = 1; i < vertexIndex.size() && sameZ; ++i )
5110 if ( vertexIndex[i] - vertexIndex[i-1] < 2 )
5113 int iC = ( vertexIndex[i] + vertexIndex[i-1] ) / 2;
5114 fillZColumn( myZColumns[iC], *myBndColumns[iC] );
5116 for ( size_t iZ = 0; iZ < myZColumns[0].size() && sameZ; ++iZ )
5117 sameZ = ( Abs( myZColumns[0][iZ] - myZColumns[iC][iZ]) < tol );
5122 myZColumns.resize(1);
5126 for ( size_t iC = 1; iC < myBndColumns.size(); ++iC )
5127 fillZColumn( myZColumns[iC], *myBndColumns[iC] );
5133 //================================================================================
5135 * \brief Create internal nodes of the prism all located on straight lines with
5136 * the same distribution along the lines.
5138 //================================================================================
5140 bool StdMeshers_Sweeper::ComputeNodesOnStraightSameZ( SMESH_MesherHelper& helper )
5142 TZColumn& z = myZColumns[0];
5144 for ( size_t i = 0; i < myIntColumns.size(); ++i )
5146 TNodeColumn& nodes = *myIntColumns[i];
5147 SMESH_NodeXYZ n0( nodes[0] ), n1( nodes.back() );
5149 for ( size_t iZ = 0; iZ < z.size(); ++iZ )
5151 gp_XYZ p = n0 * ( 1 - z[iZ] ) + n1 * z[iZ];
5152 nodes[ iZ+1 ] = helper.AddNode( p.X(), p.Y(), p.Z() );
5159 //================================================================================
5161 * \brief Create internal nodes of the prism all located on straight lines with
5162 * different distributions along the lines.
5164 //================================================================================
5166 bool StdMeshers_Sweeper::ComputeNodesOnStraight( SMESH_MesherHelper& helper,
5167 const TopoDS_Face& botFace,
5168 const TopoDS_Face& topFace )
5170 // get data to create a Morph
5171 UVPtStructVec botUV( myBndColumns.size() + 1 );
5172 UVPtStructVec topUV( myBndColumns.size() + 1 );
5173 for ( size_t i = 0; i < myBndColumns.size(); ++i )
5175 TNodeColumn& nodes = *myBndColumns[i];
5176 botUV[i].node = nodes[0];
5177 botUV[i].SetUV( helper.GetNodeUV( botFace, nodes[0] ));
5178 topUV[i].node = nodes.back();
5179 topUV[i].SetUV( helper.GetNodeUV( topFace, nodes.back() ));
5180 botUV[i].node->setIsMarked( true );
5182 botUV.back() = botUV[0];
5183 topUV.back() = topUV[0];
5186 TSideVector botWires( 1, StdMeshers_FaceSide::New( botUV, botFace, dummyE, helper.GetMesh() ));
5187 TSideVector topWires( 1, StdMeshers_FaceSide::New( topUV, topFace, dummyE, helper.GetMesh() ));
5189 // use Morph to make delauney mesh on the FACEs. Locating of a node within a
5190 // delauney triangle will be used to get a weighted Z.
5191 NSProjUtils::Morph botDelauney( botWires );
5192 NSProjUtils::Morph topDelauney( topWires );
5194 if ( helper.GetIsQuadratic() )
5196 // mark all medium nodes of faces on botFace to avoid their treating
5197 SMESHDS_SubMesh* smDS = helper.GetMeshDS()->MeshElements( botFace );
5198 SMDS_ElemIteratorPtr eIt = smDS->GetElements();
5199 while ( eIt->more() )
5201 const SMDS_MeshElement* e = eIt->next();
5202 for ( int i = e->NbCornerNodes(), nb = e->NbNodes(); i < nb; ++i )
5203 e->GetNode( i )->setIsMarked( true );
5207 // map to get a node column by a bottom node
5208 TColStd_DataMapOfIntegerInteger iNode2iCol( myIntColumns.size() );
5210 // un-mark nodes to treat (internal bottom nodes); later we will mark treated nodes
5211 for ( size_t i = 0; i < myIntColumns.size(); ++i )
5213 const SMDS_MeshNode* botNode = myIntColumns[i]->front();
5214 botNode->setIsMarked( false );
5215 iNode2iCol.Bind( botNode->GetID(), i );
5218 const int botFaceID = helper.GetMesh()->GetSubMesh( botFace )->GetId();
5219 const SMDS_MeshNode *botNode, *topNode;
5220 const BRepMesh_Triangle *botTria, *topTria;
5221 double botBC[3], topBC[3]; // barycentric coordinates
5222 int botTriaNodes[3], topTriaNodes[3];
5223 bool checkUV = true;
5225 // a queue of bottom nodes with starting delauney triangles
5226 NSProjUtils::Morph::TNodeTriaList botNoTriQueue;
5228 size_t iBndN = 1; // index of a bottom boundary node
5229 int nbNodesToProcess = myIntColumns.size();
5230 while ( nbNodesToProcess > 0 )
5232 while ( !botNoTriQueue.empty() ) // treat all nodes in the queue
5234 botNode = botNoTriQueue.front().first;
5235 botTria = botNoTriQueue.front().second;
5236 botNoTriQueue.pop_front();
5237 if ( botNode->isMarked() )
5240 botNode->setIsMarked( true );
5242 TNodeColumn* column = myIntColumns[ iNode2iCol( botNode->GetID() )];
5244 // find a delauney triangle containing the botNode
5245 gp_XY botUV = helper.GetNodeUV( botFace, botNode, NULL, &checkUV );
5246 botUV *= botDelauney.GetScale();
5247 botTria = botDelauney.FindTriangle( botUV, botTria, botBC, botTriaNodes );
5251 // find a delauney triangle containing the topNode
5252 topNode = column->back();
5253 gp_XY topUV = helper.GetNodeUV( topFace, topNode, NULL, &checkUV );
5254 topUV *= topDelauney.GetScale();
5255 // get a starting triangle basing on that top and bot boundary nodes have same index
5256 topTria = topDelauney.GetTriangleNear( botTriaNodes[0] );
5257 topTria = topDelauney.FindTriangle( topUV, topTria, topBC, topTriaNodes );
5261 // create nodes along a line
5262 SMESH_NodeXYZ botP( botNode ), topP( topNode);
5263 for ( size_t iZ = 0; iZ < myZColumns[0].size(); ++iZ )
5265 // use barycentric coordinates as weight of Z of boundary columns
5266 double botZ = 0, topZ = 0;
5267 for ( int i = 0; i < 3; ++i )
5269 botZ += botBC[i] * myZColumns[ botTriaNodes[i]-1 ][ iZ ];
5270 topZ += topBC[i] * myZColumns[ topTriaNodes[i]-1 ][ iZ ];
5272 double rZ = double( iZ + 1 ) / ( myZColumns[0].size() + 1 );
5273 double z = botZ * ( 1 - rZ ) + topZ * rZ;
5274 gp_XYZ p = botP * ( 1 - z ) + topP * z;
5275 (*column)[ iZ+1 ] = helper.AddNode( p.X(), p.Y(), p.Z() );
5278 // add neighbor nodes to the queue
5279 botDelauney.AddCloseNodes( botNode, botTria, botFaceID, botNoTriQueue );
5282 if ( nbNodesToProcess > 0 ) // fill the queue
5284 // assure that all bot nodes are visited
5285 for ( ; iBndN-1 < myBndColumns.size() && botNoTriQueue.empty(); ++iBndN )
5287 botTria = botDelauney.GetTriangleNear( iBndN );
5288 const SMDS_MeshNode* bndNode = botDelauney.GetBndNodes()[ iBndN ];
5289 botDelauney.AddCloseNodes( bndNode, botTria, botFaceID, botNoTriQueue );
5291 if ( botNoTriQueue.empty() )
5293 for ( size_t i = 0; i < myIntColumns.size(); ++i )
5295 botNode = myIntColumns[i]->front();
5296 if ( !botNode->isMarked() )
5297 botNoTriQueue.push_back( make_pair( botNode, botTria ));
5306 //================================================================================
5308 * \brief Compute Z of nodes of a straight column
5310 //================================================================================
5312 void StdMeshers_Sweeper::fillZColumn( TZColumn& zColumn,
5313 TNodeColumn& nodes )
5315 if ( zColumn.size() == nodes.size() - 2 )
5318 gp_Pnt p0 = SMESH_NodeXYZ( nodes[0] );
5319 gp_Vec line( p0, SMESH_NodeXYZ( nodes.back() ));
5320 double len2 = line.SquareMagnitude();
5322 zColumn.resize( nodes.size() - 2 );
5323 for ( size_t i = 0; i < zColumn.size(); ++i )
5325 gp_Vec vec( p0, SMESH_NodeXYZ( nodes[ i+1] ));
5326 zColumn[i] = ( line * vec ) / len2; // param [0,1] on the line