1 // Copyright (C) 2007-2014 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License, or (at your option) any later version.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 // File : StdMeshers_Prism_3D.cxx
25 // Created : Fri Oct 20 11:37:07 2006
26 // Author : Edward AGAPOV (eap)
28 #include "StdMeshers_Prism_3D.hxx"
30 #include "SMDS_EdgePosition.hxx"
31 #include "SMDS_VolumeOfNodes.hxx"
32 #include "SMDS_VolumeTool.hxx"
33 #include "SMESH_Comment.hxx"
34 #include "SMESH_Gen.hxx"
35 #include "SMESH_HypoFilter.hxx"
36 #include "SMESH_MesherHelper.hxx"
37 #include "StdMeshers_FaceSide.hxx"
38 #include "StdMeshers_ProjectionSource1D.hxx"
39 #include "StdMeshers_ProjectionSource2D.hxx"
40 #include "StdMeshers_ProjectionUtils.hxx"
41 #include "StdMeshers_Projection_1D.hxx"
42 #include "StdMeshers_Projection_1D2D.hxx"
43 #include "StdMeshers_Quadrangle_2D.hxx"
45 #include "utilities.h"
47 #include <BRepAdaptor_CompCurve.hxx>
48 #include <BRep_Tool.hxx>
49 #include <Bnd_B3d.hxx>
50 #include <Geom2dAdaptor_Curve.hxx>
51 #include <Geom2d_Line.hxx>
52 #include <Geom_Curve.hxx>
54 #include <TopExp_Explorer.hxx>
55 #include <TopTools_ListIteratorOfListOfShape.hxx>
56 #include <TopTools_ListOfShape.hxx>
57 #include <TopTools_MapOfShape.hxx>
58 #include <TopTools_SequenceOfShape.hxx>
67 #define RETURN_BAD_RESULT(msg) { MESSAGE(")-: Error: " << msg); return false; }
68 #define gpXYZ(n) SMESH_TNodeXYZ(n)
71 #define DBGOUT(msg) //cout << msg << endl;
72 #define SHOWYXZ(msg, xyz) \
73 // { gp_Pnt p (xyz); \
74 // cout << msg << " ("<< p.X() << "; " <<p.Y() << "; " <<p.Z() << ") " <<endl; }
77 #define SHOWYXZ(msg, xyz)
80 namespace NSProjUtils = StdMeshers_ProjectionUtils;
82 typedef SMESH_Comment TCom;
84 enum { ID_BOT_FACE = SMESH_Block::ID_Fxy0,
85 ID_TOP_FACE = SMESH_Block::ID_Fxy1,
86 BOTTOM_EDGE = 0, TOP_EDGE, V0_EDGE, V1_EDGE, // edge IDs in face
87 NB_WALL_FACES = 4 }; //
91 //=======================================================================
93 * \brief Quadrangle algorithm
95 struct TQuadrangleAlgo : public StdMeshers_Quadrangle_2D
97 TQuadrangleAlgo(int studyId, SMESH_Gen* gen)
98 : StdMeshers_Quadrangle_2D( gen->GetANewId(), studyId, gen)
101 static StdMeshers_Quadrangle_2D* instance( SMESH_Algo* fatherAlgo,
102 SMESH_MesherHelper* helper=0)
104 static TQuadrangleAlgo* algo = new TQuadrangleAlgo( fatherAlgo->GetStudyId(),
105 fatherAlgo->GetGen() );
108 algo->myProxyMesh->GetMesh() != helper->GetMesh() )
109 algo->myProxyMesh.reset( new SMESH_ProxyMesh( *helper->GetMesh() ));
111 algo->myQuadList.clear();
114 algo->_quadraticMesh = helper->GetIsQuadratic();
119 //=======================================================================
121 * \brief Algorithm projecting 1D mesh
123 struct TProjction1dAlgo : public StdMeshers_Projection_1D
125 StdMeshers_ProjectionSource1D myHyp;
127 TProjction1dAlgo(int studyId, SMESH_Gen* gen)
128 : StdMeshers_Projection_1D( gen->GetANewId(), studyId, gen),
129 myHyp( gen->GetANewId(), studyId, gen)
131 StdMeshers_Projection_1D::_sourceHypo = & myHyp;
133 static TProjction1dAlgo* instance( SMESH_Algo* fatherAlgo )
135 static TProjction1dAlgo* algo = new TProjction1dAlgo( fatherAlgo->GetStudyId(),
136 fatherAlgo->GetGen() );
140 //=======================================================================
142 * \brief Algorithm projecting 2D mesh
144 struct TProjction2dAlgo : public StdMeshers_Projection_1D2D
146 StdMeshers_ProjectionSource2D myHyp;
148 TProjction2dAlgo(int studyId, SMESH_Gen* gen)
149 : StdMeshers_Projection_1D2D( gen->GetANewId(), studyId, gen),
150 myHyp( gen->GetANewId(), studyId, gen)
152 StdMeshers_Projection_2D::_sourceHypo = & myHyp;
154 static TProjction2dAlgo* instance( SMESH_Algo* fatherAlgo )
156 static TProjction2dAlgo* algo = new TProjction2dAlgo( fatherAlgo->GetStudyId(),
157 fatherAlgo->GetGen() );
160 const NSProjUtils::TNodeNodeMap& GetNodesMap()
162 return _src2tgtNodes;
165 //=======================================================================
167 * \brief Returns already computed EDGEs
169 void getPrecomputedEdges( SMESH_MesherHelper& theHelper,
170 const TopoDS_Shape& theShape,
171 vector< TopoDS_Edge >& theEdges)
175 SMESHDS_Mesh* meshDS = theHelper.GetMeshDS();
178 TopTools_IndexedMapOfShape edges;
179 TopExp::MapShapes( theShape, TopAbs_EDGE, edges );
180 for ( int iE = 1; iE <= edges.Extent(); ++iE )
182 const TopoDS_Shape edge = edges( iE );
183 if (( ! ( sm = meshDS->MeshElements( edge ))) ||
184 ( sm->NbElements() == 0 ))
187 // there must not be FACEs meshed with triangles and sharing a computed EDGE
188 // as the precomputed EDGEs are used for propagation other to 'vertical' EDGEs
189 bool faceFound = false;
190 PShapeIteratorPtr faceIt =
191 theHelper.GetAncestors( edge, *theHelper.GetMesh(), TopAbs_FACE );
192 while ( const TopoDS_Shape* face = faceIt->next() )
194 if (( sm = meshDS->MeshElements( *face )) &&
195 ( sm->NbElements() > 0 ) &&
196 ( !theHelper.IsSameElemGeometry( sm, SMDSGeom_QUADRANGLE ) ))
202 theEdges.push_back( TopoDS::Edge( edge ));
206 //================================================================================
208 * \brief Make \a botE be the BOTTOM_SIDE of \a quad.
209 * Return false if the BOTTOM_SIDE is composite
211 //================================================================================
213 bool setBottomEdge( const TopoDS_Edge& botE,
214 FaceQuadStruct::Ptr& quad,
215 const TopoDS_Shape& face)
217 quad->side[ QUAD_TOP_SIDE ].grid->Reverse();
218 quad->side[ QUAD_LEFT_SIDE ].grid->Reverse();
220 bool isComposite = false;
221 for ( size_t i = 0; i < quad->side.size(); ++i )
223 StdMeshers_FaceSidePtr quadSide = quad->side[i];
224 for ( int iE = 0; iE < quadSide->NbEdges(); ++iE )
225 if ( botE.IsSame( quadSide->Edge( iE )))
227 if ( quadSide->NbEdges() > 1 )
228 isComposite = true; //return false;
230 i = quad->side.size(); // to quit from the outer loop
234 if ( edgeIndex != QUAD_BOTTOM_SIDE )
235 quad->shift( quad->side.size() - edgeIndex, /*keepUnitOri=*/false );
237 quad->face = TopoDS::Face( face );
242 //================================================================================
244 * \brief Return iterator pointing to node column for the given parameter
245 * \param columnsMap - node column map
246 * \param parameter - parameter
247 * \retval TParam2ColumnMap::iterator - result
249 * it returns closest left column
251 //================================================================================
253 TParam2ColumnIt getColumn( const TParam2ColumnMap* columnsMap,
254 const double parameter )
256 TParam2ColumnIt u_col = columnsMap->upper_bound( parameter );
257 if ( u_col != columnsMap->begin() )
259 return u_col; // return left column
262 //================================================================================
264 * \brief Return nodes around given parameter and a ratio
265 * \param column - node column
266 * \param param - parameter
267 * \param node1 - lower node
268 * \param node2 - upper node
269 * \retval double - ratio
271 //================================================================================
273 double getRAndNodes( const TNodeColumn* column,
275 const SMDS_MeshNode* & node1,
276 const SMDS_MeshNode* & node2)
278 if ( param >= 1.0 || column->size() == 1) {
279 node1 = node2 = column->back();
283 int i = int( param * ( column->size() - 1 ));
284 double u0 = double( i )/ double( column->size() - 1 );
285 double r = ( param - u0 ) * ( column->size() - 1 );
287 node1 = (*column)[ i ];
288 node2 = (*column)[ i + 1];
292 //================================================================================
294 * \brief Compute boundary parameters of face parts
295 * \param nbParts - nb of parts to split columns into
296 * \param columnsMap - node columns of the face to split
297 * \param params - computed parameters
299 //================================================================================
301 void splitParams( const int nbParts,
302 const TParam2ColumnMap* columnsMap,
303 vector< double > & params)
306 params.reserve( nbParts + 1 );
307 TParam2ColumnIt last_par_col = --columnsMap->end();
308 double par = columnsMap->begin()->first; // 0.
309 double parLast = last_par_col->first;
310 params.push_back( par );
311 for ( int i = 0; i < nbParts - 1; ++ i )
313 double partSize = ( parLast - par ) / double ( nbParts - i );
314 TParam2ColumnIt par_col = getColumn( columnsMap, par + partSize );
315 if ( par_col->first == par ) {
317 if ( par_col == last_par_col ) {
318 while ( i < nbParts - 1 )
319 params.push_back( par + partSize * i++ );
323 par = par_col->first;
324 params.push_back( par );
326 params.push_back( parLast ); // 1.
329 //================================================================================
331 * \brief Return coordinate system for z-th layer of nodes
333 //================================================================================
335 gp_Ax2 getLayerCoordSys(const int z,
336 const vector< const TNodeColumn* >& columns,
339 // gravity center of a layer
342 for ( int i = 0; i < columns.size(); ++i )
344 O += gpXYZ( (*columns[ i ])[ z ]);
345 if ( vertexCol < 0 &&
346 columns[ i ]->front()->GetPosition()->GetTypeOfPosition() == SMDS_TOP_VERTEX )
353 int iPrev = columns.size()-1;
354 for ( int i = 0; i < columns.size(); ++i )
356 gp_Vec v1( O, gpXYZ( (*columns[ iPrev ])[ z ]));
357 gp_Vec v2( O, gpXYZ( (*columns[ i ] )[ z ]));
362 if ( vertexCol >= 0 )
364 O = gpXYZ( (*columns[ vertexCol ])[ z ]);
366 if ( xColumn < 0 || xColumn >= columns.size() )
368 // select a column for X dir
370 for ( int i = 0; i < columns.size(); ++i )
372 double dist = ( O - gpXYZ((*columns[ i ])[ z ])).SquareModulus();
373 if ( dist > maxDist )
382 gp_Vec X( O, gpXYZ( (*columns[ xColumn ])[ z ]));
384 return gp_Ax2( O, Z, X);
387 //================================================================================
389 * \brief Removes submeshes that are or can be meshed with regular grid from given list
390 * \retval int - nb of removed submeshes
392 //================================================================================
394 int removeQuasiQuads(list< SMESH_subMesh* >& notQuadSubMesh,
395 SMESH_MesherHelper* helper,
396 StdMeshers_Quadrangle_2D* quadAlgo)
399 //SMESHDS_Mesh* mesh = notQuadSubMesh.front()->GetFather()->GetMeshDS();
400 list< SMESH_subMesh* >::iterator smIt = notQuadSubMesh.begin();
401 while ( smIt != notQuadSubMesh.end() )
403 SMESH_subMesh* faceSm = *smIt;
404 SMESHDS_SubMesh* faceSmDS = faceSm->GetSubMeshDS();
405 int nbQuads = faceSmDS ? faceSmDS->NbElements() : 0;
408 toRemove = helper->IsStructured( faceSm );
410 toRemove = quadAlgo->CheckNbEdges( *helper->GetMesh(),
411 faceSm->GetSubShape() );
412 nbRemoved += toRemove;
414 smIt = notQuadSubMesh.erase( smIt );
422 //================================================================================
424 * \brief Return and angle between two EDGEs
425 * \return double - the angle normalized so that
432 //================================================================================
434 // double normAngle(const TopoDS_Edge & E1, const TopoDS_Edge & E2, const TopoDS_Face & F)
436 // return SMESH_MesherHelper::GetAngle( E1, E2, F ) / ( 0.5 * M_PI );
439 //================================================================================
441 * Consider continuous straight EDGES as one side - mark them to unite
443 //================================================================================
445 int countNbSides( const Prism_3D::TPrismTopo & thePrism,
446 vector<int> & nbUnitePerEdge,
447 vector< double > & edgeLength)
449 int nbEdges = thePrism.myNbEdgesInWires.front(); // nb outer edges
450 int nbSides = nbEdges;
453 list< TopoDS_Edge >::const_iterator edgeIt = thePrism.myBottomEdges.begin();
454 std::advance( edgeIt, nbEdges-1 );
455 TopoDS_Edge prevE = *edgeIt;
456 // bool isPrevStraight = SMESH_Algo::IsStraight( prevE );
457 int iPrev = nbEdges - 1;
459 int iUnite = -1; // the first of united EDGEs
461 // analyse angles between EDGEs
463 vector< bool > isCorner( nbEdges );
464 edgeIt = thePrism.myBottomEdges.begin();
465 for ( int iE = 0; iE < nbEdges; ++iE, ++edgeIt )
467 const TopoDS_Edge& curE = *edgeIt;
468 edgeLength[ iE ] = SMESH_Algo::EdgeLength( curE );
470 // double normAngle = normAngle( prevE, curE, thePrism.myBottom );
471 // isCorner[ iE ] = false;
472 // if ( normAngle < 2.0 )
474 // if ( normAngle < 0.001 ) // straight or obtuse angle
476 // // unite EDGEs in order not to put a corner of the unit quadrangle at this VERTEX
479 // nbUnitePerEdge[ iUnite ]++;
480 // nbUnitePerEdge[ iE ] = -1;
485 // isCorner[ iE ] = true;
495 // define which of corners to put on a side of the unit quadrangle
497 // edgeIt = thePrism.myBottomEdges.begin();
498 // for ( int iE = 0; iE < nbEdges; ++iE, ++edgeIt )
500 // const TopoDS_Edge& curE = *edgeIt;
501 // edgeLength[ iE ] = SMESH_Algo::EdgeLength( curE );
503 // const bool isCurStraight = SMESH_Algo::IsStraight( curE );
504 // if ( isPrevStraight && isCurStraight && SMESH_Algo::IsContinuous( prevE, curE ))
508 // nbUnitePerEdge[ iUnite ]++;
509 // nbUnitePerEdge[ iE ] = -1;
517 // isPrevStraight = isCurStraight;
524 void pointsToPython(const std::vector<gp_XYZ>& p)
527 for ( int i = SMESH_Block::ID_V000; i < p.size(); ++i )
529 cout << "mesh.AddNode( " << p[i].X() << ", "<< p[i].Y() << ", "<< p[i].Z() << ") # " << i <<" " ;
530 SMESH_Block::DumpShapeID( i, cout ) << endl;
536 //=======================================================================
537 //function : StdMeshers_Prism_3D
539 //=======================================================================
541 StdMeshers_Prism_3D::StdMeshers_Prism_3D(int hypId, int studyId, SMESH_Gen* gen)
542 :SMESH_3D_Algo(hypId, studyId, gen)
545 _shapeType = (1 << TopAbs_SOLID); // 1 bit per shape type
546 _onlyUnaryInput = false; // mesh all SOLIDs at once
547 _requireDiscreteBoundary = false; // mesh FACEs and EDGEs by myself
548 _supportSubmeshes = true; // "source" FACE must be meshed by other algo
549 _neededLowerHyps[ 1 ] = true; // suppress warning on hiding a global 1D algo
550 _neededLowerHyps[ 2 ] = true; // suppress warning on hiding a global 2D algo
552 //myProjectTriangles = false;
553 mySetErrorToSM = true; // to pass an error to a sub-mesh of a current solid or not
556 //================================================================================
560 //================================================================================
562 StdMeshers_Prism_3D::~StdMeshers_Prism_3D()
565 //=======================================================================
566 //function : CheckHypothesis
568 //=======================================================================
570 bool StdMeshers_Prism_3D::CheckHypothesis(SMESH_Mesh& aMesh,
571 const TopoDS_Shape& aShape,
572 SMESH_Hypothesis::Hypothesis_Status& aStatus)
574 // Check shape geometry
576 aStatus = SMESH_Hypothesis::HYP_BAD_GEOMETRY;
578 // find not quadrangle faces
579 list< TopoDS_Shape > notQuadFaces;
580 int nbEdge, nbWire, nbFace = 0;
581 TopExp_Explorer exp( aShape, TopAbs_FACE );
582 for ( ; exp.More(); exp.Next() ) {
584 const TopoDS_Shape& face = exp.Current();
585 nbEdge = NSProjUtils::Count( face, TopAbs_EDGE, 0 );
586 nbWire = NSProjUtils::Count( face, TopAbs_WIRE, 0 );
587 if ( nbEdge!= 4 || nbWire!= 1 ) {
588 if ( !notQuadFaces.empty() ) {
589 if ( NSProjUtils::Count( notQuadFaces.back(), TopAbs_EDGE, 0 ) != nbEdge ||
590 NSProjUtils::Count( notQuadFaces.back(), TopAbs_WIRE, 0 ) != nbWire )
591 RETURN_BAD_RESULT("Different not quad faces");
593 notQuadFaces.push_back( face );
596 if ( !notQuadFaces.empty() )
598 if ( notQuadFaces.size() != 2 )
599 RETURN_BAD_RESULT("Bad nb not quad faces: " << notQuadFaces.size());
601 // check total nb faces
602 nbEdge = NSProjUtils::Count( notQuadFaces.back(), TopAbs_EDGE, 0 );
603 if ( nbFace != nbEdge + 2 )
604 RETURN_BAD_RESULT("Bad nb of faces: " << nbFace << " but must be " << nbEdge + 2);
608 aStatus = SMESH_Hypothesis::HYP_OK;
612 //=======================================================================
614 //purpose : Compute mesh on a COMPOUND of SOLIDs
615 //=======================================================================
617 bool StdMeshers_Prism_3D::Compute(SMESH_Mesh& theMesh, const TopoDS_Shape& theShape)
619 SMESH_MesherHelper helper( theMesh );
622 int nbSolids = helper.Count( theShape, TopAbs_SOLID, /*skipSame=*/false );
626 TopTools_IndexedDataMapOfShapeListOfShape faceToSolids;
627 TopExp::MapShapesAndAncestors( theShape, TopAbs_FACE, TopAbs_SOLID, faceToSolids );
629 // look for meshed FACEs ("source" FACEs) that must be prism bottoms
630 list< TopoDS_Face > meshedFaces, notQuadMeshedFaces, notQuadFaces;
631 const bool meshHasQuads = ( theMesh.NbQuadrangles() > 0 );
632 //StdMeshers_Quadrangle_2D* quadAlgo = TQuadrangleAlgo::instance( this );
633 for ( int iF = 1; iF <= faceToSolids.Extent(); ++iF )
635 const TopoDS_Face& face = TopoDS::Face( faceToSolids.FindKey( iF ));
636 SMESH_subMesh* faceSM = theMesh.GetSubMesh( face );
637 if ( !faceSM->IsEmpty() )
639 if ( !meshHasQuads ||
640 !helper.IsSameElemGeometry( faceSM->GetSubMeshDS(), SMDSGeom_QUADRANGLE ) ||
641 !helper.IsStructured( faceSM )
643 notQuadMeshedFaces.push_front( face );
644 else if ( myHelper->Count( face, TopAbs_EDGE, /*ignoreSame=*/false ) != 4 )
645 meshedFaces.push_front( face );
647 meshedFaces.push_back( face );
649 // not add not quadrilateral FACE as we can't compute it
650 // else if ( !quadAlgo->CheckNbEdges( theMesh, face ))
651 // // not add not quadrilateral FACE as it can be a prism side
652 // // else if ( myHelper->Count( face, TopAbs_EDGE, /*ignoreSame=*/false ) != 4 )
654 // notQuadFaces.push_back( face );
657 // notQuadFaces are of medium priority, put them before ordinary meshed faces
658 meshedFaces.splice( meshedFaces.begin(), notQuadFaces );
659 // notQuadMeshedFaces are of highest priority, put them before notQuadFaces
660 meshedFaces.splice( meshedFaces.begin(), notQuadMeshedFaces );
662 Prism_3D::TPrismTopo prism;
667 if ( !meshedFaces.empty() )
668 prism.myBottom = meshedFaces.front();
669 return ( initPrism( prism, TopExp_Explorer( theShape, TopAbs_SOLID ).Current() ) &&
673 // find propagation chains from already computed EDGEs
674 vector< TopoDS_Edge > computedEdges;
675 getPrecomputedEdges( helper, theShape, computedEdges );
676 myPropagChains = new TopTools_IndexedMapOfShape[ computedEdges.size() + 1 ];
677 SMESHUtils::ArrayDeleter< TopTools_IndexedMapOfShape > pcDel( myPropagChains );
678 for ( size_t i = 0, nb = 0; i < computedEdges.size(); ++i )
680 StdMeshers_ProjectionUtils::GetPropagationEdge( &theMesh, TopoDS_Edge(),
681 computedEdges[i], myPropagChains + nb );
682 if ( myPropagChains[ nb ].Extent() < 2 ) // an empty map is a termination sign
683 myPropagChains[ nb ].Clear();
688 TopTools_MapOfShape meshedSolids;
689 list< Prism_3D::TPrismTopo > meshedPrism;
690 TopTools_ListIteratorOfListOfShape solidIt;
692 while ( meshedSolids.Extent() < nbSolids )
694 if ( _computeCanceled )
695 return toSM( error( SMESH_ComputeError::New(COMPERR_CANCELED)));
697 // compute prisms having avident computed source FACE
698 while ( !meshedFaces.empty() )
700 TopoDS_Face face = meshedFaces.front();
701 meshedFaces.pop_front();
702 TopTools_ListOfShape& solidList = faceToSolids.ChangeFromKey( face );
703 while ( !solidList.IsEmpty() )
705 TopoDS_Shape solid = solidList.First();
706 solidList.RemoveFirst();
707 if ( meshedSolids.Add( solid ))
710 prism.myBottom = face;
711 if ( !initPrism( prism, solid ) ||
715 SMESHDS_SubMesh* smDS = theMesh.GetMeshDS()->MeshElements( prism.myTop );
716 if ( !myHelper->IsSameElemGeometry( smDS, SMDSGeom_QUADRANGLE ))
718 meshedFaces.push_front( prism.myTop );
720 meshedPrism.push_back( prism );
724 if ( meshedSolids.Extent() == nbSolids )
727 // below in the loop we try to find source FACEs somehow
729 // project mesh from source FACEs of computed prisms to
730 // prisms sharing wall FACEs
731 list< Prism_3D::TPrismTopo >::iterator prismIt = meshedPrism.begin();
732 for ( ; prismIt != meshedPrism.end(); ++prismIt )
734 for ( size_t iW = 0; iW < prismIt->myWallQuads.size(); ++iW )
736 Prism_3D::TQuadList::iterator wQuad = prismIt->myWallQuads[iW].begin();
737 for ( ; wQuad != prismIt->myWallQuads[iW].end(); ++ wQuad )
739 const TopoDS_Face& wFace = (*wQuad)->face;
740 TopTools_ListOfShape& solidList = faceToSolids.ChangeFromKey( wFace );
741 solidIt.Initialize( solidList );
742 while ( solidIt.More() )
744 const TopoDS_Shape& solid = solidIt.Value();
745 if ( meshedSolids.Contains( solid )) {
746 solidList.Remove( solidIt );
747 continue; // already computed prism
749 // find a source FACE of the SOLID: it's a FACE sharing a bottom EDGE with wFace
750 const TopoDS_Edge& wEdge = (*wQuad)->side[ QUAD_TOP_SIDE ].grid->Edge(0);
751 PShapeIteratorPtr faceIt = myHelper->GetAncestors( wEdge, *myHelper->GetMesh(),
753 while ( const TopoDS_Shape* f = faceIt->next() )
755 const TopoDS_Face& candidateF = TopoDS::Face( *f );
757 prism.myBottom = candidateF;
758 mySetErrorToSM = false;
759 if ( !myHelper->IsSubShape( candidateF, prismIt->myShape3D ) &&
760 myHelper->IsSubShape( candidateF, solid ) &&
761 !myHelper->GetMesh()->GetSubMesh( candidateF )->IsMeshComputed() &&
762 initPrism( prism, solid ) &&
763 project2dMesh( prismIt->myBottom, candidateF))
765 mySetErrorToSM = true;
766 if ( !compute( prism ))
768 SMESHDS_SubMesh* smDS = theMesh.GetMeshDS()->MeshElements( prism.myTop );
769 if ( !myHelper->IsSameElemGeometry( smDS, SMDSGeom_QUADRANGLE ))
771 meshedFaces.push_front( prism.myTop );
772 meshedFaces.push_front( prism.myBottom );
774 meshedPrism.push_back( prism );
775 meshedSolids.Add( solid );
779 mySetErrorToSM = true;
781 if ( meshedSolids.Contains( solid ))
782 solidList.Remove( solidIt );
788 if ( !meshedFaces.empty() )
789 break; // to compute prisms with avident sources
792 // find FACEs with local 1D hyps, which has to be computed by now,
793 // or at least any computed FACEs
794 for ( int iF = 1; ( meshedFaces.empty() && iF < faceToSolids.Extent() ); ++iF )
796 const TopoDS_Face& face = TopoDS::Face( faceToSolids.FindKey( iF ));
797 const TopTools_ListOfShape& solidList = faceToSolids.FindFromKey( face );
798 if ( solidList.IsEmpty() ) continue;
799 SMESH_subMesh* faceSM = theMesh.GetSubMesh( face );
800 if ( !faceSM->IsEmpty() )
802 meshedFaces.push_back( face ); // lower priority
806 bool allSubMeComputed = true;
807 SMESH_subMeshIteratorPtr smIt = faceSM->getDependsOnIterator(false,true);
808 while ( smIt->more() && allSubMeComputed )
809 allSubMeComputed = smIt->next()->IsMeshComputed();
810 if ( allSubMeComputed )
812 faceSM->ComputeStateEngine( SMESH_subMesh::COMPUTE );
813 if ( !faceSM->IsEmpty() )
814 meshedFaces.push_front( face ); // higher priority
816 faceSM->ComputeStateEngine( SMESH_subMesh::CHECK_COMPUTE_STATE );
822 // TODO. there are other ways to find out the source FACE:
823 // propagation, topological similarity, ect.
825 // simply try to mesh all not meshed SOLIDs
826 if ( meshedFaces.empty() )
828 for ( TopExp_Explorer solid( theShape, TopAbs_SOLID ); solid.More(); solid.Next() )
830 mySetErrorToSM = false;
832 if ( !meshedSolids.Contains( solid.Current() ) &&
833 initPrism( prism, solid.Current() ))
835 mySetErrorToSM = true;
836 if ( !compute( prism ))
838 meshedFaces.push_front( prism.myTop );
839 meshedFaces.push_front( prism.myBottom );
840 meshedPrism.push_back( prism );
841 meshedSolids.Add( solid.Current() );
843 mySetErrorToSM = true;
847 if ( meshedFaces.empty() ) // set same error to 10 not-computed solids
849 SMESH_ComputeErrorPtr err = SMESH_ComputeError::New
850 ( COMPERR_BAD_INPUT_MESH, "No meshed source face found", this );
852 const int maxNbErrors = 10; // limit nb errors not to overload the Compute dialog
853 TopExp_Explorer solid( theShape, TopAbs_SOLID );
854 for ( int i = 0; ( i < maxNbErrors && solid.More() ); ++i, solid.Next() )
855 if ( !meshedSolids.Contains( solid.Current() ))
857 SMESH_subMesh* sm = theMesh.GetSubMesh( solid.Current() );
858 sm->GetComputeError() = err;
866 //================================================================================
868 * \brief Find wall faces by bottom edges
870 //================================================================================
872 bool StdMeshers_Prism_3D::getWallFaces( Prism_3D::TPrismTopo & thePrism,
873 const int totalNbFaces)
875 thePrism.myWallQuads.clear();
877 SMESH_Mesh* mesh = myHelper->GetMesh();
879 StdMeshers_Quadrangle_2D* quadAlgo = TQuadrangleAlgo::instance( this, myHelper );
881 TopTools_MapOfShape faceMap;
882 TopTools_IndexedDataMapOfShapeListOfShape edgeToFaces;
883 TopExp::MapShapesAndAncestors( thePrism.myShape3D,
884 TopAbs_EDGE, TopAbs_FACE, edgeToFaces );
886 // ------------------------------
887 // Get the 1st row of wall FACEs
888 // ------------------------------
890 list< TopoDS_Edge >::iterator edge = thePrism.myBottomEdges.begin();
891 std::list< int >::iterator nbE = thePrism.myNbEdgesInWires.begin();
894 while ( edge != thePrism.myBottomEdges.end() )
897 if ( BRep_Tool::Curve( *edge, f,l ).IsNull() )
899 edge = thePrism.myBottomEdges.erase( edge );
905 TopTools_ListIteratorOfListOfShape faceIt( edgeToFaces.FindFromKey( *edge ));
906 for ( ; faceIt.More(); faceIt.Next() )
908 const TopoDS_Face& face = TopoDS::Face( faceIt.Value() );
909 if ( !thePrism.myBottom.IsSame( face ))
911 Prism_3D::TQuadList quadList( 1, quadAlgo->CheckNbEdges( *mesh, face ));
912 if ( !quadList.back() )
913 return toSM( error(TCom("Side face #") << shapeID( face )
914 << " not meshable with quadrangles"));
915 bool isCompositeBase = ! setBottomEdge( *edge, quadList.back(), face );
916 if ( isCompositeBase )
918 // it's OK if all EDGEs of the bottom side belongs to the bottom FACE
919 StdMeshers_FaceSidePtr botSide = quadList.back()->side[ QUAD_BOTTOM_SIDE ];
920 for ( int iE = 0; iE < botSide->NbEdges(); ++iE )
921 if ( !myHelper->IsSubShape( botSide->Edge(iE), thePrism.myBottom ))
922 return toSM( error(TCom("Composite 'horizontal' edges are not supported")));
924 if ( faceMap.Add( face ))
925 thePrism.myWallQuads.push_back( quadList );
938 // -------------------------
939 // Find the rest wall FACEs
940 // -------------------------
942 // Compose a vector of indixes of right neighbour FACE for each wall FACE
943 // that is not so evident in case of several WIREs in the bottom FACE
944 thePrism.myRightQuadIndex.clear();
945 for ( size_t i = 0; i < thePrism.myWallQuads.size(); ++i )
946 thePrism.myRightQuadIndex.push_back( i+1 );
947 list< int >::iterator nbEinW = thePrism.myNbEdgesInWires.begin();
948 for ( int iLeft = 0; nbEinW != thePrism.myNbEdgesInWires.end(); ++nbEinW )
950 thePrism.myRightQuadIndex[ iLeft + *nbEinW - 1 ] = iLeft; // 1st EDGE index of a current WIRE
954 while ( totalNbFaces - faceMap.Extent() > 2 )
956 // find wall FACEs adjacent to each of wallQuads by the right side EDGE
959 nbKnownFaces = faceMap.Extent();
960 StdMeshers_FaceSidePtr rightSide, topSide; // sides of the quad
961 for ( size_t i = 0; i < thePrism.myWallQuads.size(); ++i )
963 rightSide = thePrism.myWallQuads[i].back()->side[ QUAD_RIGHT_SIDE ];
964 for ( int iE = 0; iE < rightSide->NbEdges(); ++iE ) // rightSide can be composite
966 const TopoDS_Edge & rightE = rightSide->Edge( iE );
967 TopTools_ListIteratorOfListOfShape face( edgeToFaces.FindFromKey( rightE ));
968 for ( ; face.More(); face.Next() )
969 if ( faceMap.Add( face.Value() ))
971 // a new wall FACE encountered, store it in thePrism.myWallQuads
972 const int iRight = thePrism.myRightQuadIndex[i];
973 topSide = thePrism.myWallQuads[ iRight ].back()->side[ QUAD_TOP_SIDE ];
974 const TopoDS_Edge& newBotE = topSide->Edge(0);
975 const TopoDS_Shape& newWallF = face.Value();
976 thePrism.myWallQuads[ iRight ].push_back( quadAlgo->CheckNbEdges( *mesh, newWallF ));
977 if ( !thePrism.myWallQuads[ iRight ].back() )
978 return toSM( error(TCom("Side face #") << shapeID( newWallF ) <<
979 " not meshable with quadrangles"));
980 if ( ! setBottomEdge( newBotE, thePrism.myWallQuads[ iRight ].back(), newWallF ))
981 return toSM( error(TCom("Composite 'horizontal' edges are not supported")));
985 } while ( nbKnownFaces != faceMap.Extent() );
987 // find wall FACEs adjacent to each of thePrism.myWallQuads by the top side EDGE
988 if ( totalNbFaces - faceMap.Extent() > 2 )
990 for ( size_t i = 0; i < thePrism.myWallQuads.size(); ++i )
992 StdMeshers_FaceSidePtr topSide = thePrism.myWallQuads[i].back()->side[ QUAD_TOP_SIDE ];
993 const TopoDS_Edge & topE = topSide->Edge( 0 );
994 if ( topSide->NbEdges() > 1 )
995 return toSM( error(COMPERR_BAD_SHAPE, TCom("Side face #") <<
996 shapeID( thePrism.myWallQuads[i].back()->face )
997 << " has a composite top edge"));
998 TopTools_ListIteratorOfListOfShape faceIt( edgeToFaces.FindFromKey( topE ));
999 for ( ; faceIt.More(); faceIt.Next() )
1000 if ( faceMap.Add( faceIt.Value() ))
1002 // a new wall FACE encountered, store it in wallQuads
1003 thePrism.myWallQuads[ i ].push_back( quadAlgo->CheckNbEdges( *mesh, faceIt.Value() ));
1004 if ( !thePrism.myWallQuads[ i ].back() )
1005 return toSM( error(TCom("Side face #") << shapeID( faceIt.Value() ) <<
1006 " not meshable with quadrangles"));
1007 if ( ! setBottomEdge( topE, thePrism.myWallQuads[ i ].back(), faceIt.Value() ))
1008 return toSM( error(TCom("Composite 'horizontal' edges are not supported")));
1009 if ( totalNbFaces - faceMap.Extent() == 2 )
1011 i = thePrism.myWallQuads.size(); // to quit from the outer loop
1017 } // while ( totalNbFaces - faceMap.Extent() > 2 )
1019 // ------------------
1020 // Find the top FACE
1021 // ------------------
1023 if ( thePrism.myTop.IsNull() )
1025 // now only top and bottom FACEs are not in the faceMap
1026 faceMap.Add( thePrism.myBottom );
1027 for ( TopExp_Explorer f( thePrism.myShape3D, TopAbs_FACE );f.More(); f.Next() )
1028 if ( !faceMap.Contains( f.Current() )) {
1029 thePrism.myTop = TopoDS::Face( f.Current() );
1032 if ( thePrism.myTop.IsNull() )
1033 return toSM( error("Top face not found"));
1036 // Check that the top FACE shares all the top EDGEs
1037 for ( size_t i = 0; i < thePrism.myWallQuads.size(); ++i )
1039 StdMeshers_FaceSidePtr topSide = thePrism.myWallQuads[i].back()->side[ QUAD_TOP_SIDE ];
1040 const TopoDS_Edge & topE = topSide->Edge( 0 );
1041 if ( !myHelper->IsSubShape( topE, thePrism.myTop ))
1042 return toSM( error( TCom("Wrong source face (#") << shapeID( thePrism.myBottom )));
1048 //=======================================================================
1049 //function : compute
1050 //purpose : Compute mesh on a SOLID
1051 //=======================================================================
1053 bool StdMeshers_Prism_3D::compute(const Prism_3D::TPrismTopo& thePrism)
1055 myHelper->IsQuadraticSubMesh( thePrism.myShape3D );
1056 if ( _computeCanceled )
1057 return toSM( error( SMESH_ComputeError::New(COMPERR_CANCELED)));
1059 // Make all side FACEs of thePrism meshed with quads
1060 if ( !computeWalls( thePrism ))
1063 // Analyse mesh and geometry to find all block sub-shapes and submeshes
1064 // (after fixing IPAL52499 myBlock is used only as a holder of boundary nodes
1065 // and location of internal nodes is computed by StdMeshers_Sweeper)
1066 if ( !myBlock.Init( myHelper, thePrism ))
1067 return toSM( error( myBlock.GetError()));
1069 SMESHDS_Mesh* meshDS = myHelper->GetMeshDS();
1071 int volumeID = meshDS->ShapeToIndex( thePrism.myShape3D );
1073 // Try to get gp_Trsf to get all nodes from bottom ones
1074 vector<gp_Trsf> trsf;
1075 gp_Trsf bottomToTopTrsf;
1076 // if ( !myBlock.GetLayersTransformation( trsf, thePrism ))
1078 // else if ( !trsf.empty() )
1079 // bottomToTopTrsf = trsf.back();
1081 // To compute coordinates of a node inside a block, it is necessary to know
1082 // 1. normalized parameters of the node by which
1083 // 2. coordinates of node projections on all block sub-shapes are computed
1085 // So we fill projections on vertices at once as they are same for all nodes
1086 myShapeXYZ.resize( myBlock.NbSubShapes() );
1087 for ( int iV = SMESH_Block::ID_FirstV; iV < SMESH_Block::ID_FirstE; ++iV ) {
1088 myBlock.VertexPoint( iV, myShapeXYZ[ iV ]);
1089 SHOWYXZ("V point " <<iV << " ", myShapeXYZ[ iV ]);
1092 // Projections on the top and bottom faces are taken from nodes existing
1093 // on these faces; find correspondence between bottom and top nodes
1094 myBotToColumnMap.clear();
1095 if ( !assocOrProjBottom2Top( bottomToTopTrsf, thePrism ) ) // it also fills myBotToColumnMap
1099 // Create nodes inside the block
1101 // use transformation (issue 0020680, IPAL0052499)
1102 StdMeshers_Sweeper sweeper;
1104 // load boundary nodes
1106 list< TopoDS_Edge >::const_iterator edge = thePrism.myBottomEdges.begin();
1107 for ( ; edge != thePrism.myBottomEdges.end(); ++edge )
1109 int edgeID = meshDS->ShapeToIndex( *edge );
1110 TParam2ColumnMap* u2col = const_cast<TParam2ColumnMap*>
1111 ( myBlock.GetParam2ColumnMap( edgeID, dummy ));
1112 TParam2ColumnMap::iterator u2colIt = u2col->begin();
1113 for ( ; u2colIt != u2col->end(); ++u2colIt )
1114 sweeper.myBndColumns.push_back( & u2colIt->second );
1116 // load node columns inside the bottom face
1117 TNode2ColumnMap::iterator bot_column = myBotToColumnMap.begin();
1118 for ( ; bot_column != myBotToColumnMap.end(); ++bot_column )
1119 sweeper.myIntColumns.push_back( & bot_column->second );
1121 const double tol = getSweepTolerance( thePrism );
1123 if ( sweeper.ComputeNodes( *myHelper, tol ))
1126 else // use block approach
1128 // loop on nodes inside the bottom face
1129 Prism_3D::TNode prevBNode;
1130 TNode2ColumnMap::iterator bot_column = myBotToColumnMap.begin();
1131 for ( ; bot_column != myBotToColumnMap.end(); ++bot_column )
1133 const Prism_3D::TNode& tBotNode = bot_column->first; // bottom TNode
1134 if ( tBotNode.GetPositionType() != SMDS_TOP_FACE )
1135 continue; // node is not inside the FACE
1137 // column nodes; middle part of the column are zero pointers
1138 TNodeColumn& column = bot_column->second;
1140 gp_XYZ botParams, topParams;
1141 if ( !tBotNode.HasParams() )
1143 // compute bottom node parameters
1144 gp_XYZ paramHint(-1,-1,-1);
1145 if ( prevBNode.IsNeighbor( tBotNode ))
1146 paramHint = prevBNode.GetParams();
1147 if ( !myBlock.ComputeParameters( tBotNode.GetCoords(), tBotNode.ChangeParams(),
1148 ID_BOT_FACE, paramHint ))
1149 return toSM( error(TCom("Can't compute normalized parameters for node ")
1150 << tBotNode.myNode->GetID() << " on the face #"
1151 << myBlock.SubMesh( ID_BOT_FACE )->GetId() ));
1152 prevBNode = tBotNode;
1154 botParams = topParams = tBotNode.GetParams();
1155 topParams.SetZ( 1 );
1157 // compute top node parameters
1158 if ( column.size() > 2 ) {
1159 gp_Pnt topCoords = gpXYZ( column.back() );
1160 if ( !myBlock.ComputeParameters( topCoords, topParams, ID_TOP_FACE, topParams ))
1161 return toSM( error(TCom("Can't compute normalized parameters ")
1162 << "for node " << column.back()->GetID()
1163 << " on the face #"<< column.back()->getshapeId() ));
1166 else // top nodes are created by projection using parameters
1168 botParams = topParams = tBotNode.GetParams();
1169 topParams.SetZ( 1 );
1172 myShapeXYZ[ ID_BOT_FACE ] = tBotNode.GetCoords();
1173 myShapeXYZ[ ID_TOP_FACE ] = gpXYZ( column.back() );
1176 TNodeColumn::iterator columnNodes = column.begin();
1177 for ( int z = 0; columnNodes != column.end(); ++columnNodes, ++z)
1179 const SMDS_MeshNode* & node = *columnNodes;
1180 if ( node ) continue; // skip bottom or top node
1182 // params of a node to create
1183 double rz = (double) z / (double) ( column.size() - 1 );
1184 gp_XYZ params = botParams * ( 1 - rz ) + topParams * rz;
1186 // set coords on all faces and nodes
1187 const int nbSideFaces = 4;
1188 int sideFaceIDs[nbSideFaces] = { SMESH_Block::ID_Fx0z,
1189 SMESH_Block::ID_Fx1z,
1190 SMESH_Block::ID_F0yz,
1191 SMESH_Block::ID_F1yz };
1192 for ( int iF = 0; iF < nbSideFaces; ++iF )
1193 if ( !setFaceAndEdgesXYZ( sideFaceIDs[ iF ], params, z ))
1196 // compute coords for a new node
1198 if ( !SMESH_Block::ShellPoint( params, myShapeXYZ, coords ))
1199 return toSM( error("Can't compute coordinates by normalized parameters"));
1201 // if ( !meshDS->MeshElements( volumeID ) ||
1202 // meshDS->MeshElements( volumeID )->NbNodes() == 0 )
1203 // pointsToPython(myShapeXYZ);
1204 SHOWYXZ("TOPFacePoint ",myShapeXYZ[ ID_TOP_FACE]);
1205 SHOWYXZ("BOT Node "<< tBotNode.myNode->GetID(),gpXYZ(tBotNode.myNode));
1206 SHOWYXZ("ShellPoint ",coords);
1209 node = meshDS->AddNode( coords.X(), coords.Y(), coords.Z() );
1210 meshDS->SetNodeInVolume( node, volumeID );
1212 if ( _computeCanceled )
1215 } // loop on bottom nodes
1220 SMESHDS_SubMesh* smDS = myBlock.SubMeshDS( ID_BOT_FACE );
1221 if ( !smDS ) return toSM( error(COMPERR_BAD_INPUT_MESH, "Null submesh"));
1223 // loop on bottom mesh faces
1224 SMDS_ElemIteratorPtr faceIt = smDS->GetElements();
1225 while ( faceIt->more() )
1227 const SMDS_MeshElement* face = faceIt->next();
1228 if ( !face || face->GetType() != SMDSAbs_Face )
1231 // find node columns for each node
1232 int nbNodes = face->NbCornerNodes();
1233 vector< const TNodeColumn* > columns( nbNodes );
1234 for ( int i = 0; i < nbNodes; ++i )
1236 const SMDS_MeshNode* n = face->GetNode( i );
1237 if ( n->GetPosition()->GetTypeOfPosition() == SMDS_TOP_FACE ) {
1238 TNode2ColumnMap::iterator bot_column = myBotToColumnMap.find( n );
1239 if ( bot_column == myBotToColumnMap.end() )
1240 return toSM( error(TCom("No nodes found above node ") << n->GetID() ));
1241 columns[ i ] = & bot_column->second;
1244 columns[ i ] = myBlock.GetNodeColumn( n );
1245 if ( !columns[ i ] )
1246 return toSM( error(TCom("No side nodes found above node ") << n->GetID() ));
1250 AddPrisms( columns, myHelper );
1252 } // loop on bottom mesh faces
1255 myBotToColumnMap.clear();
1261 //=======================================================================
1262 //function : computeWalls
1263 //purpose : Compute 2D mesh on walls FACEs of a prism
1264 //=======================================================================
1266 bool StdMeshers_Prism_3D::computeWalls(const Prism_3D::TPrismTopo& thePrism)
1268 SMESH_Mesh* mesh = myHelper->GetMesh();
1269 SMESHDS_Mesh* meshDS = myHelper->GetMeshDS();
1270 DBGOUT( endl << "COMPUTE Prism " << meshDS->ShapeToIndex( thePrism.myShape3D ));
1272 TProjction1dAlgo* projector1D = TProjction1dAlgo::instance( this );
1273 StdMeshers_Quadrangle_2D* quadAlgo = TQuadrangleAlgo::instance( this, myHelper );
1275 // SMESH_HypoFilter hyp1dFilter( SMESH_HypoFilter::IsAlgo(),/*not=*/true);
1276 // hyp1dFilter.And( SMESH_HypoFilter::HasDim( 1 ));
1277 // hyp1dFilter.And( SMESH_HypoFilter::IsMoreLocalThan( thePrism.myShape3D, *mesh ));
1279 // Discretize equally 'vertical' EDGEs
1280 // -----------------------------------
1281 // find source FACE sides for projection: either already computed ones or
1282 // the 'most composite' ones
1283 const size_t nbWalls = thePrism.myWallQuads.size();
1284 vector< int > wgt( nbWalls, 0 ); // "weight" of a wall
1285 for ( size_t iW = 0; iW != nbWalls; ++iW )
1287 Prism_3D::TQuadList::const_iterator quad = thePrism.myWallQuads[iW].begin();
1288 for ( ; quad != thePrism.myWallQuads[iW].end(); ++quad )
1290 StdMeshers_FaceSidePtr lftSide = (*quad)->side[ QUAD_LEFT_SIDE ];
1291 for ( int i = 0; i < lftSide->NbEdges(); ++i )
1294 const TopoDS_Edge& E = lftSide->Edge(i);
1295 if ( mesh->GetSubMesh( E )->IsMeshComputed() )
1298 wgt[ myHelper->WrapIndex( iW+1, nbWalls)] += 10;
1299 wgt[ myHelper->WrapIndex( iW-1, nbWalls)] += 10;
1301 // else if ( mesh->GetHypothesis( E, hyp1dFilter, true )) // local hypothesis!
1305 // in quadratic mesh, pass ignoreMediumNodes to quad sides
1306 if ( myHelper->GetIsQuadratic() )
1308 quad = thePrism.myWallQuads[iW].begin();
1309 for ( ; quad != thePrism.myWallQuads[iW].end(); ++quad )
1310 for ( int i = 0; i < NB_QUAD_SIDES; ++i )
1311 (*quad)->side[ i ].grid->SetIgnoreMediumNodes( true );
1314 multimap< int, int > wgt2quad;
1315 for ( size_t iW = 0; iW != nbWalls; ++iW )
1316 wgt2quad.insert( make_pair( wgt[ iW ], iW ));
1318 // Project 'vertical' EDGEs, from left to right
1319 multimap< int, int >::reverse_iterator w2q = wgt2quad.rbegin();
1320 for ( ; w2q != wgt2quad.rend(); ++w2q )
1322 const int iW = w2q->second;
1323 const Prism_3D::TQuadList& quads = thePrism.myWallQuads[ iW ];
1324 Prism_3D::TQuadList::const_iterator quad = quads.begin();
1325 for ( ; quad != quads.end(); ++quad )
1327 StdMeshers_FaceSidePtr rgtSide = (*quad)->side[ QUAD_RIGHT_SIDE ]; // tgt
1328 StdMeshers_FaceSidePtr lftSide = (*quad)->side[ QUAD_LEFT_SIDE ]; // src
1329 bool swapLeftRight = ( lftSide->NbSegments( /*update=*/true ) == 0 &&
1330 rgtSide->NbSegments( /*update=*/true ) > 0 );
1331 if ( swapLeftRight )
1332 std::swap( lftSide, rgtSide );
1334 // assure that all the source (left) EDGEs are meshed
1335 int nbSrcSegments = 0;
1336 for ( int i = 0; i < lftSide->NbEdges(); ++i )
1338 const TopoDS_Edge& srcE = lftSide->Edge(i);
1339 SMESH_subMesh* srcSM = mesh->GetSubMesh( srcE );
1340 if ( !srcSM->IsMeshComputed() ) {
1341 DBGOUT( "COMPUTE V edge " << srcSM->GetId() );
1342 TopoDS_Edge prpgSrcE = findPropagationSource( srcE );
1343 if ( !prpgSrcE.IsNull() ) {
1344 srcSM->ComputeSubMeshStateEngine( SMESH_subMesh::COMPUTE );
1345 projector1D->myHyp.SetSourceEdge( prpgSrcE );
1346 projector1D->Compute( *mesh, srcE );
1347 srcSM->ComputeStateEngine( SMESH_subMesh::CHECK_COMPUTE_STATE );
1350 srcSM->ComputeSubMeshStateEngine( SMESH_subMesh::COMPUTE );
1351 srcSM->ComputeStateEngine ( SMESH_subMesh::COMPUTE );
1353 if ( !srcSM->IsMeshComputed() )
1354 return toSM( error( "Can't compute 1D mesh" ));
1356 nbSrcSegments += srcSM->GetSubMeshDS()->NbElements();
1358 // check target EDGEs
1359 int nbTgtMeshed = 0, nbTgtSegments = 0;
1360 vector< bool > isTgtEdgeComputed( rgtSide->NbEdges() );
1361 for ( int i = 0; i < rgtSide->NbEdges(); ++i )
1363 const TopoDS_Edge& tgtE = rgtSide->Edge(i);
1364 SMESH_subMesh* tgtSM = mesh->GetSubMesh( tgtE );
1365 if ( !( isTgtEdgeComputed[ i ] = tgtSM->IsMeshComputed() )) {
1366 tgtSM->ComputeSubMeshStateEngine( SMESH_subMesh::COMPUTE );
1367 tgtSM->ComputeStateEngine ( SMESH_subMesh::COMPUTE );
1369 if ( tgtSM->IsMeshComputed() ) {
1371 nbTgtSegments += tgtSM->GetSubMeshDS()->NbElements();
1374 if ( rgtSide->NbEdges() == nbTgtMeshed ) // all tgt EDGEs meshed
1376 if ( nbTgtSegments != nbSrcSegments )
1378 bool badMeshRemoved = false;
1379 // remove just computed segments
1380 for ( int i = 0; i < rgtSide->NbEdges(); ++i )
1381 if ( !isTgtEdgeComputed[ i ])
1383 const TopoDS_Edge& tgtE = rgtSide->Edge(i);
1384 SMESH_subMesh* tgtSM = mesh->GetSubMesh( tgtE );
1385 tgtSM->ComputeStateEngine( SMESH_subMesh::CLEAN );
1386 badMeshRemoved = true;
1389 if ( !badMeshRemoved )
1391 for ( int i = 0; i < lftSide->NbEdges(); ++i )
1392 addBadInputElements( meshDS->MeshElements( lftSide->Edge( i )));
1393 for ( int i = 0; i < rgtSide->NbEdges(); ++i )
1394 addBadInputElements( meshDS->MeshElements( rgtSide->Edge( i )));
1395 return toSM( error( TCom("Different nb of segment on logically vertical edges #")
1396 << shapeID( lftSide->Edge(0) ) << " and #"
1397 << shapeID( rgtSide->Edge(0) ) << ": "
1398 << nbSrcSegments << " != " << nbTgtSegments ));
1401 else // if ( nbTgtSegments == nbSrcSegments )
1406 // Compute 'vertical projection'
1407 if ( nbTgtMeshed == 0 )
1409 // compute nodes on target VERTEXes
1410 const UVPtStructVec& srcNodeStr = lftSide->GetUVPtStruct();
1411 if ( srcNodeStr.size() == 0 )
1412 return toSM( error( TCom("Invalid node positions on edge #") <<
1413 shapeID( lftSide->Edge(0) )));
1414 vector< SMDS_MeshNode* > newNodes( srcNodeStr.size() );
1415 for ( int is2ndV = 0; is2ndV < 2; ++is2ndV )
1417 const TopoDS_Edge& E = rgtSide->Edge( is2ndV ? rgtSide->NbEdges()-1 : 0 );
1418 TopoDS_Vertex v = myHelper->IthVertex( is2ndV, E );
1419 mesh->GetSubMesh( v )->ComputeStateEngine( SMESH_subMesh::COMPUTE );
1420 const SMDS_MeshNode* n = SMESH_Algo::VertexNode( v, meshDS );
1421 newNodes[ is2ndV ? 0 : newNodes.size()-1 ] = (SMDS_MeshNode*) n;
1424 // compute nodes on target EDGEs
1425 DBGOUT( "COMPUTE V edge (proj) " << shapeID( lftSide->Edge(0)));
1426 rgtSide->Reverse(); // direct it same as the lftSide
1427 myHelper->SetElementsOnShape( false ); // myHelper holds the prism shape
1428 TopoDS_Edge tgtEdge;
1429 for ( size_t iN = 1; iN < srcNodeStr.size()-1; ++iN ) // add nodes
1431 gp_Pnt p = rgtSide->Value3d ( srcNodeStr[ iN ].normParam );
1432 double u = rgtSide->Parameter( srcNodeStr[ iN ].normParam, tgtEdge );
1433 newNodes[ iN ] = meshDS->AddNode( p.X(), p.Y(), p.Z() );
1434 meshDS->SetNodeOnEdge( newNodes[ iN ], tgtEdge, u );
1436 for ( size_t iN = 1; iN < srcNodeStr.size(); ++iN ) // add segments
1438 // find an EDGE to set a new segment
1439 std::pair<int, TopAbs_ShapeEnum> id2type =
1440 myHelper->GetMediumPos( newNodes[ iN-1 ], newNodes[ iN ] );
1441 if ( id2type.second != TopAbs_EDGE )
1443 // new nodes are on different EDGEs; put one of them on VERTEX
1444 const int edgeIndex = rgtSide->EdgeIndex( srcNodeStr[ iN-1 ].normParam );
1445 const double vertexParam = rgtSide->LastParameter( edgeIndex );
1446 TopoDS_Vertex vertex = rgtSide->LastVertex( edgeIndex );
1447 const SMDS_MeshNode* vn = SMESH_Algo::VertexNode( vertex, meshDS );
1448 const gp_Pnt p = BRep_Tool::Pnt( vertex );
1449 const int isPrev = ( Abs( srcNodeStr[ iN-1 ].normParam - vertexParam ) <
1450 Abs( srcNodeStr[ iN ].normParam - vertexParam ));
1451 meshDS->UnSetNodeOnShape( newNodes[ iN-isPrev ] );
1452 meshDS->SetNodeOnVertex ( newNodes[ iN-isPrev ], vertex );
1453 meshDS->MoveNode ( newNodes[ iN-isPrev ], p.X(), p.Y(), p.Z() );
1454 id2type.first = newNodes[ iN-(1-isPrev) ]->getshapeId();
1457 SMESH_MeshEditor::TListOfListOfNodes lln( 1, list< const SMDS_MeshNode* >() );
1458 lln.back().push_back ( vn );
1459 lln.back().push_front( newNodes[ iN-isPrev ] ); // to keep
1460 SMESH_MeshEditor( mesh ).MergeNodes( lln );
1463 SMDS_MeshElement* newEdge = myHelper->AddEdge( newNodes[ iN-1 ], newNodes[ iN ] );
1464 meshDS->SetMeshElementOnShape( newEdge, id2type.first );
1466 myHelper->SetElementsOnShape( true );
1467 for ( int i = 0; i < rgtSide->NbEdges(); ++i ) // update state of sub-meshes
1469 const TopoDS_Edge& E = rgtSide->Edge( i );
1470 SMESH_subMesh* tgtSM = mesh->GetSubMesh( E );
1471 tgtSM->ComputeStateEngine( SMESH_subMesh::CHECK_COMPUTE_STATE );
1474 // to continue projection from the just computed side as a source
1475 if ( !swapLeftRight && rgtSide->NbEdges() > 1 && w2q->second == iW )
1477 std::pair<int,int> wgt2quadKeyVal( w2q->first + 1, thePrism.myRightQuadIndex[ iW ]);
1478 wgt2quad.insert( wgt2quadKeyVal ); // it will be skipped by ++w2q
1479 wgt2quad.insert( wgt2quadKeyVal );
1480 w2q = wgt2quad.rbegin();
1485 // HOPE assigned hypotheses are OK, so that equal nb of segments will be generated
1486 //return toSM( error("Partial projection not implemented"));
1488 } // loop on quads of a composite wall side
1489 } // loop on the ordered wall sides
1493 for ( size_t iW = 0; iW != thePrism.myWallQuads.size(); ++iW )
1495 Prism_3D::TQuadList::const_iterator quad = thePrism.myWallQuads[iW].begin();
1496 for ( ; quad != thePrism.myWallQuads[iW].end(); ++quad )
1498 const TopoDS_Face& face = (*quad)->face;
1499 SMESH_subMesh* fSM = mesh->GetSubMesh( face );
1500 if ( ! fSM->IsMeshComputed() )
1502 // Top EDGEs must be projections from the bottom ones
1503 // to compute stuctured quad mesh on wall FACEs
1504 // ---------------------------------------------------
1505 const TopoDS_Edge& botE = (*quad)->side[ QUAD_BOTTOM_SIDE ].grid->Edge(0);
1506 const TopoDS_Edge& topE = (*quad)->side[ QUAD_TOP_SIDE ].grid->Edge(0);
1507 SMESH_subMesh* botSM = mesh->GetSubMesh( botE );
1508 SMESH_subMesh* topSM = mesh->GetSubMesh( topE );
1509 SMESH_subMesh* srcSM = botSM;
1510 SMESH_subMesh* tgtSM = topSM;
1511 if ( !srcSM->IsMeshComputed() && tgtSM->IsMeshComputed() )
1512 std::swap( srcSM, tgtSM );
1514 if ( !srcSM->IsMeshComputed() )
1516 DBGOUT( "COMPUTE H edge " << srcSM->GetId());
1517 srcSM->ComputeSubMeshStateEngine( SMESH_subMesh::COMPUTE ); // nodes on VERTEXes
1518 srcSM->ComputeStateEngine( SMESH_subMesh::COMPUTE ); // segments on the EDGE
1520 srcSM->ComputeStateEngine( SMESH_subMesh::CHECK_COMPUTE_STATE );
1522 if ( tgtSM->IsMeshComputed() &&
1523 tgtSM->GetSubMeshDS()->NbNodes() != srcSM->GetSubMeshDS()->NbNodes() )
1525 // the top EDGE is computed differently than the bottom one,
1526 // try to clear a wrong mesh
1527 bool isAdjFaceMeshed = false;
1528 PShapeIteratorPtr fIt = myHelper->GetAncestors( tgtSM->GetSubShape(),
1529 *mesh, TopAbs_FACE );
1530 while ( const TopoDS_Shape* f = fIt->next() )
1531 if (( isAdjFaceMeshed = mesh->GetSubMesh( *f )->IsMeshComputed() ))
1533 if ( isAdjFaceMeshed )
1534 return toSM( error( TCom("Different nb of segment on logically horizontal edges #")
1535 << shapeID( botE ) << " and #"
1536 << shapeID( topE ) << ": "
1537 << tgtSM->GetSubMeshDS()->NbElements() << " != "
1538 << srcSM->GetSubMeshDS()->NbElements() ));
1539 tgtSM->ComputeStateEngine( SMESH_subMesh::CLEAN );
1541 if ( !tgtSM->IsMeshComputed() )
1543 // compute nodes on VERTEXes
1544 SMESH_subMeshIteratorPtr smIt = tgtSM->getDependsOnIterator(/*includeSelf=*/false);
1545 while ( smIt->more() )
1546 smIt->next()->ComputeStateEngine( SMESH_subMesh::COMPUTE );
1548 DBGOUT( "COMPUTE H edge (proj) " << tgtSM->GetId());
1549 projector1D->myHyp.SetSourceEdge( TopoDS::Edge( srcSM->GetSubShape() ));
1550 projector1D->InitComputeError();
1551 bool ok = projector1D->Compute( *mesh, tgtSM->GetSubShape() );
1554 SMESH_ComputeErrorPtr err = projector1D->GetComputeError();
1555 if ( err->IsOK() ) err->myName = COMPERR_ALGO_FAILED;
1556 tgtSM->GetComputeError() = err;
1560 tgtSM->ComputeStateEngine( SMESH_subMesh::CHECK_COMPUTE_STATE );
1563 // Compute quad mesh on wall FACEs
1564 // -------------------------------
1566 // make all EDGES meshed
1567 fSM->ComputeSubMeshStateEngine( SMESH_subMesh::COMPUTE );
1568 if ( !fSM->SubMeshesComputed() )
1569 return toSM( error( COMPERR_BAD_INPUT_MESH,
1570 "Not all edges have valid algorithm and hypothesis"));
1572 quadAlgo->InitComputeError();
1573 DBGOUT( "COMPUTE Quad face " << fSM->GetId());
1574 bool ok = quadAlgo->Compute( *mesh, face );
1575 fSM->GetComputeError() = quadAlgo->GetComputeError();
1578 fSM->ComputeStateEngine( SMESH_subMesh::CHECK_COMPUTE_STATE );
1580 if ( myHelper->GetIsQuadratic() )
1582 // fill myHelper with medium nodes built by quadAlgo
1583 SMDS_ElemIteratorPtr fIt = fSM->GetSubMeshDS()->GetElements();
1584 while ( fIt->more() )
1585 myHelper->AddTLinks( dynamic_cast<const SMDS_MeshFace*>( fIt->next() ));
1593 //=======================================================================
1595 * \brief Returns a source EDGE of propagation to a given EDGE
1597 //=======================================================================
1599 TopoDS_Edge StdMeshers_Prism_3D::findPropagationSource( const TopoDS_Edge& E )
1601 if ( myPropagChains )
1602 for ( size_t i = 0; !myPropagChains[i].IsEmpty(); ++i )
1603 if ( myPropagChains[i].Contains( E ))
1604 return TopoDS::Edge( myPropagChains[i].FindKey( 1 ));
1606 return TopoDS_Edge();
1609 //=======================================================================
1610 //function : Evaluate
1612 //=======================================================================
1614 bool StdMeshers_Prism_3D::Evaluate(SMESH_Mesh& theMesh,
1615 const TopoDS_Shape& theShape,
1616 MapShapeNbElems& aResMap)
1618 if ( theShape.ShapeType() == TopAbs_COMPOUND )
1621 for ( TopoDS_Iterator it( theShape ); it.More(); it.Next() )
1622 ok &= Evaluate( theMesh, it.Value(), aResMap );
1625 SMESH_MesherHelper helper( theMesh );
1627 myHelper->SetSubShape( theShape );
1629 // find face contains only triangles
1630 vector < SMESH_subMesh * >meshFaces;
1631 TopTools_SequenceOfShape aFaces;
1632 int NumBase = 0, i = 0, NbQFs = 0;
1633 for (TopExp_Explorer exp(theShape, TopAbs_FACE); exp.More(); exp.Next()) {
1635 aFaces.Append(exp.Current());
1636 SMESH_subMesh *aSubMesh = theMesh.GetSubMesh(exp.Current());
1637 meshFaces.push_back(aSubMesh);
1638 MapShapeNbElemsItr anIt = aResMap.find(meshFaces[i-1]);
1639 if( anIt==aResMap.end() )
1640 return toSM( error( "Submesh can not be evaluated"));
1642 std::vector<int> aVec = (*anIt).second;
1643 int nbtri = Max(aVec[SMDSEntity_Triangle],aVec[SMDSEntity_Quad_Triangle]);
1644 int nbqua = Max(aVec[SMDSEntity_Quadrangle],aVec[SMDSEntity_Quad_Quadrangle]);
1645 if( nbtri==0 && nbqua>0 ) {
1654 std::vector<int> aResVec(SMDSEntity_Last);
1655 for(int i=SMDSEntity_Node; i<SMDSEntity_Last; i++) aResVec[i] = 0;
1656 SMESH_subMesh * sm = theMesh.GetSubMesh(theShape);
1657 aResMap.insert(std::make_pair(sm,aResVec));
1658 return toSM( error( "Submesh can not be evaluated" ));
1661 if(NumBase==0) NumBase = 1; // only quads => set 1 faces as base
1663 // find number of 1d elems for base face
1665 TopTools_MapOfShape Edges1;
1666 for (TopExp_Explorer exp(aFaces.Value(NumBase), TopAbs_EDGE); exp.More(); exp.Next()) {
1667 Edges1.Add(exp.Current());
1668 SMESH_subMesh *sm = theMesh.GetSubMesh(exp.Current());
1670 MapShapeNbElemsItr anIt = aResMap.find(sm);
1671 if( anIt == aResMap.end() ) continue;
1672 std::vector<int> aVec = (*anIt).second;
1673 nb1d += Max(aVec[SMDSEntity_Edge],aVec[SMDSEntity_Quad_Edge]);
1676 // find face opposite to base face
1678 for(i=1; i<=6; i++) {
1679 if(i==NumBase) continue;
1680 bool IsOpposite = true;
1681 for(TopExp_Explorer exp(aFaces.Value(i), TopAbs_EDGE); exp.More(); exp.Next()) {
1682 if( Edges1.Contains(exp.Current()) ) {
1692 // find number of 2d elems on side faces
1694 for(i=1; i<=6; i++) {
1695 if( i==OppNum || i==NumBase ) continue;
1696 MapShapeNbElemsItr anIt = aResMap.find( meshFaces[i-1] );
1697 if( anIt == aResMap.end() ) continue;
1698 std::vector<int> aVec = (*anIt).second;
1699 nb2d += Max(aVec[SMDSEntity_Quadrangle],aVec[SMDSEntity_Quad_Quadrangle]);
1702 MapShapeNbElemsItr anIt = aResMap.find( meshFaces[NumBase-1] );
1703 std::vector<int> aVec = (*anIt).second;
1704 bool IsQuadratic = (aVec[SMDSEntity_Quad_Triangle]>aVec[SMDSEntity_Triangle]) ||
1705 (aVec[SMDSEntity_Quad_Quadrangle]>aVec[SMDSEntity_Quadrangle]);
1706 int nb2d_face0_3 = Max(aVec[SMDSEntity_Triangle],aVec[SMDSEntity_Quad_Triangle]);
1707 int nb2d_face0_4 = Max(aVec[SMDSEntity_Quadrangle],aVec[SMDSEntity_Quad_Quadrangle]);
1708 int nb0d_face0 = aVec[SMDSEntity_Node];
1709 int nb1d_face0_int = ( nb2d_face0_3*3 + nb2d_face0_4*4 - nb1d ) / 2;
1711 std::vector<int> aResVec(SMDSEntity_Last);
1712 for(int i=SMDSEntity_Node; i<SMDSEntity_Last; i++) aResVec[i] = 0;
1714 aResVec[SMDSEntity_Quad_Penta] = nb2d_face0_3 * ( nb2d/nb1d );
1715 aResVec[SMDSEntity_Quad_Hexa] = nb2d_face0_4 * ( nb2d/nb1d );
1716 aResVec[SMDSEntity_Node] = nb0d_face0 * ( 2*nb2d/nb1d - 1 ) - nb1d_face0_int * nb2d/nb1d;
1719 aResVec[SMDSEntity_Node] = nb0d_face0 * ( nb2d/nb1d - 1 );
1720 aResVec[SMDSEntity_Penta] = nb2d_face0_3 * ( nb2d/nb1d );
1721 aResVec[SMDSEntity_Hexa] = nb2d_face0_4 * ( nb2d/nb1d );
1723 SMESH_subMesh * sm = theMesh.GetSubMesh(theShape);
1724 aResMap.insert(std::make_pair(sm,aResVec));
1729 //================================================================================
1731 * \brief Create prisms
1732 * \param columns - columns of nodes generated from nodes of a mesh face
1733 * \param helper - helper initialized by mesh and shape to add prisms to
1735 //================================================================================
1737 void StdMeshers_Prism_3D::AddPrisms( vector<const TNodeColumn*> & columns,
1738 SMESH_MesherHelper* helper)
1740 int nbNodes = columns.size();
1741 int nbZ = columns[0]->size();
1742 if ( nbZ < 2 ) return;
1744 // find out orientation
1745 bool isForward = true;
1746 SMDS_VolumeTool vTool;
1748 switch ( nbNodes ) {
1750 SMDS_VolumeOfNodes tmpPenta ( (*columns[0])[z-1], // bottom
1753 (*columns[0])[z], // top
1756 vTool.Set( &tmpPenta );
1757 isForward = vTool.IsForward();
1761 SMDS_VolumeOfNodes tmpHex( (*columns[0])[z-1], (*columns[1])[z-1], // bottom
1762 (*columns[2])[z-1], (*columns[3])[z-1],
1763 (*columns[0])[z], (*columns[1])[z], // top
1764 (*columns[2])[z], (*columns[3])[z] );
1765 vTool.Set( &tmpHex );
1766 isForward = vTool.IsForward();
1770 const int di = (nbNodes+1) / 3;
1771 SMDS_VolumeOfNodes tmpVol ( (*columns[0] )[z-1],
1772 (*columns[di] )[z-1],
1773 (*columns[2*di])[z-1],
1776 (*columns[2*di])[z] );
1777 vTool.Set( &tmpVol );
1778 isForward = vTool.IsForward();
1781 // vertical loop on columns
1783 helper->SetElementsOnShape( true );
1785 switch ( nbNodes ) {
1787 case 3: { // ---------- pentahedra
1788 const int i1 = isForward ? 1 : 2;
1789 const int i2 = isForward ? 2 : 1;
1790 for ( z = 1; z < nbZ; ++z )
1791 helper->AddVolume( (*columns[0 ])[z-1], // bottom
1792 (*columns[i1])[z-1],
1793 (*columns[i2])[z-1],
1794 (*columns[0 ])[z], // top
1796 (*columns[i2])[z] );
1799 case 4: { // ---------- hexahedra
1800 const int i1 = isForward ? 1 : 3;
1801 const int i3 = isForward ? 3 : 1;
1802 for ( z = 1; z < nbZ; ++z )
1803 helper->AddVolume( (*columns[0])[z-1], (*columns[i1])[z-1], // bottom
1804 (*columns[2])[z-1], (*columns[i3])[z-1],
1805 (*columns[0])[z], (*columns[i1])[z], // top
1806 (*columns[2])[z], (*columns[i3])[z] );
1809 case 6: { // ---------- octahedra
1810 const int iBase1 = isForward ? -1 : 0;
1811 const int iBase2 = isForward ? 0 :-1;
1812 for ( z = 1; z < nbZ; ++z )
1813 helper->AddVolume( (*columns[0])[z+iBase1], (*columns[1])[z+iBase1], // bottom or top
1814 (*columns[2])[z+iBase1], (*columns[3])[z+iBase1],
1815 (*columns[4])[z+iBase1], (*columns[5])[z+iBase1],
1816 (*columns[0])[z+iBase2], (*columns[1])[z+iBase2], // top or bottom
1817 (*columns[2])[z+iBase2], (*columns[3])[z+iBase2],
1818 (*columns[4])[z+iBase2], (*columns[5])[z+iBase2] );
1821 default: // ---------- polyhedra
1822 vector<int> quantities( 2 + nbNodes, 4 );
1823 quantities[0] = quantities[1] = nbNodes;
1824 columns.resize( nbNodes + 1 );
1825 columns[ nbNodes ] = columns[ 0 ];
1826 const int i1 = isForward ? 1 : 3;
1827 const int i3 = isForward ? 3 : 1;
1828 const int iBase1 = isForward ? -1 : 0;
1829 const int iBase2 = isForward ? 0 :-1;
1830 vector<const SMDS_MeshNode*> nodes( 2*nbNodes + 4*nbNodes);
1831 for ( z = 1; z < nbZ; ++z )
1833 for ( int i = 0; i < nbNodes; ++i ) {
1834 nodes[ i ] = (*columns[ i ])[z+iBase1]; // bottom or top
1835 nodes[ 2*nbNodes-i-1 ] = (*columns[ i ])[z+iBase2]; // top or bottom
1837 int di = 2*nbNodes + 4*i;
1838 nodes[ di+0 ] = (*columns[i ])[z ];
1839 nodes[ di+i1] = (*columns[i+1])[z ];
1840 nodes[ di+2 ] = (*columns[i+1])[z-1];
1841 nodes[ di+i3] = (*columns[i ])[z-1];
1843 helper->AddPolyhedralVolume( nodes, quantities );
1846 } // switch ( nbNodes )
1849 //================================================================================
1851 * \brief Find correspondence between bottom and top nodes
1852 * If elements on the bottom and top faces are topologically different,
1853 * and projection is possible and allowed, perform the projection
1854 * \retval bool - is a success or not
1856 //================================================================================
1858 bool StdMeshers_Prism_3D::assocOrProjBottom2Top( const gp_Trsf & bottomToTopTrsf,
1859 const Prism_3D::TPrismTopo& thePrism)
1861 SMESH_subMesh * botSM = myHelper->GetMesh()->GetSubMesh( thePrism.myBottom );
1862 SMESH_subMesh * topSM = myHelper->GetMesh()->GetSubMesh( thePrism.myTop );
1864 SMESHDS_SubMesh * botSMDS = botSM->GetSubMeshDS();
1865 SMESHDS_SubMesh * topSMDS = topSM->GetSubMeshDS();
1867 if ( !botSMDS || botSMDS->NbElements() == 0 )
1869 _gen->Compute( *myHelper->GetMesh(), botSM->GetSubShape(), /*aShapeOnly=*/true );
1870 botSMDS = botSM->GetSubMeshDS();
1871 if ( !botSMDS || botSMDS->NbElements() == 0 )
1872 return toSM( error(TCom("No elements on face #") << botSM->GetId() ));
1875 bool needProject = !topSM->IsMeshComputed();
1876 if ( !needProject &&
1877 (botSMDS->NbElements() != topSMDS->NbElements() ||
1878 botSMDS->NbNodes() != topSMDS->NbNodes()))
1880 MESSAGE("nb elem bot " << botSMDS->NbElements() <<
1881 " top " << ( topSMDS ? topSMDS->NbElements() : 0 ));
1882 MESSAGE("nb node bot " << botSMDS->NbNodes() <<
1883 " top " << ( topSMDS ? topSMDS->NbNodes() : 0 ));
1884 return toSM( error(TCom("Mesh on faces #") << botSM->GetId()
1885 <<" and #"<< topSM->GetId() << " seems different" ));
1888 if ( 0/*needProject && !myProjectTriangles*/ )
1889 return toSM( error(TCom("Mesh on faces #") << botSM->GetId()
1890 <<" and #"<< topSM->GetId() << " seems different" ));
1891 ///RETURN_BAD_RESULT("Need to project but not allowed");
1893 NSProjUtils::TNodeNodeMap n2nMap;
1894 const NSProjUtils::TNodeNodeMap* n2nMapPtr = & n2nMap;
1897 if ( !projectBottomToTop( bottomToTopTrsf, thePrism ))
1899 n2nMapPtr = & TProjction2dAlgo::instance( this )->GetNodesMap();
1902 if ( !n2nMapPtr || n2nMapPtr->size() < botSMDS->NbNodes() )
1904 // associate top and bottom faces
1905 NSProjUtils::TShapeShapeMap shape2ShapeMap;
1906 const bool sameTopo =
1907 NSProjUtils::FindSubShapeAssociation( thePrism.myBottom, myHelper->GetMesh(),
1908 thePrism.myTop, myHelper->GetMesh(),
1911 for ( size_t iQ = 0; iQ < thePrism.myWallQuads.size(); ++iQ )
1913 const Prism_3D::TQuadList& quadList = thePrism.myWallQuads[iQ];
1914 StdMeshers_FaceSidePtr botSide = quadList.front()->side[ QUAD_BOTTOM_SIDE ];
1915 StdMeshers_FaceSidePtr topSide = quadList.back ()->side[ QUAD_TOP_SIDE ];
1916 if ( botSide->NbEdges() == topSide->NbEdges() )
1918 for ( int iE = 0; iE < botSide->NbEdges(); ++iE )
1920 NSProjUtils::InsertAssociation( botSide->Edge( iE ),
1921 topSide->Edge( iE ), shape2ShapeMap );
1922 NSProjUtils::InsertAssociation( myHelper->IthVertex( 0, botSide->Edge( iE )),
1923 myHelper->IthVertex( 0, topSide->Edge( iE )),
1929 TopoDS_Vertex vb, vt;
1930 StdMeshers_FaceSidePtr sideB, sideT;
1931 vb = myHelper->IthVertex( 0, botSide->Edge( 0 ));
1932 vt = myHelper->IthVertex( 0, topSide->Edge( 0 ));
1933 sideB = quadList.front()->side[ QUAD_LEFT_SIDE ];
1934 sideT = quadList.back ()->side[ QUAD_LEFT_SIDE ];
1935 if ( vb.IsSame( sideB->FirstVertex() ) &&
1936 vt.IsSame( sideT->LastVertex() ))
1938 NSProjUtils::InsertAssociation( botSide->Edge( 0 ),
1939 topSide->Edge( 0 ), shape2ShapeMap );
1940 NSProjUtils::InsertAssociation( vb, vt, shape2ShapeMap );
1942 vb = myHelper->IthVertex( 1, botSide->Edge( botSide->NbEdges()-1 ));
1943 vt = myHelper->IthVertex( 1, topSide->Edge( topSide->NbEdges()-1 ));
1944 sideB = quadList.front()->side[ QUAD_RIGHT_SIDE ];
1945 sideT = quadList.back ()->side[ QUAD_RIGHT_SIDE ];
1946 if ( vb.IsSame( sideB->FirstVertex() ) &&
1947 vt.IsSame( sideT->LastVertex() ))
1949 NSProjUtils::InsertAssociation( botSide->Edge( botSide->NbEdges()-1 ),
1950 topSide->Edge( topSide->NbEdges()-1 ),
1952 NSProjUtils::InsertAssociation( vb, vt, shape2ShapeMap );
1957 // Find matching nodes of top and bottom faces
1958 n2nMapPtr = & n2nMap;
1959 if ( ! NSProjUtils::FindMatchingNodesOnFaces( thePrism.myBottom, myHelper->GetMesh(),
1960 thePrism.myTop, myHelper->GetMesh(),
1961 shape2ShapeMap, n2nMap ))
1964 return toSM( error(TCom("Mesh on faces #") << botSM->GetId()
1965 <<" and #"<< topSM->GetId() << " seems different" ));
1967 return toSM( error(TCom("Topology of faces #") << botSM->GetId()
1968 <<" and #"<< topSM->GetId() << " seems different" ));
1972 // Fill myBotToColumnMap
1974 int zSize = myBlock.VerticalSize();
1975 TNodeNodeMap::const_iterator bN_tN = n2nMapPtr->begin();
1976 for ( ; bN_tN != n2nMapPtr->end(); ++bN_tN )
1978 const SMDS_MeshNode* botNode = bN_tN->first;
1979 const SMDS_MeshNode* topNode = bN_tN->second;
1980 if ( botNode->GetPosition()->GetTypeOfPosition() != SMDS_TOP_FACE )
1981 continue; // wall columns are contained in myBlock
1982 // create node column
1983 Prism_3D::TNode bN( botNode );
1984 TNode2ColumnMap::iterator bN_col =
1985 myBotToColumnMap.insert( make_pair ( bN, TNodeColumn() )).first;
1986 TNodeColumn & column = bN_col->second;
1987 column.resize( zSize );
1988 column.front() = botNode;
1989 column.back() = topNode;
1994 //================================================================================
1996 * \brief Remove faces from the top face and re-create them by projection from the bottom
1997 * \retval bool - a success or not
1999 //================================================================================
2001 bool StdMeshers_Prism_3D::projectBottomToTop( const gp_Trsf & bottomToTopTrsf,
2002 const Prism_3D::TPrismTopo& thePrism )
2004 if ( project2dMesh( thePrism.myBottom, thePrism.myTop ))
2009 SMESHDS_Mesh* meshDS = myHelper->GetMeshDS();
2010 SMESH_subMesh * botSM = myHelper->GetMesh()->GetSubMesh( thePrism.myBottom );
2011 SMESH_subMesh * topSM = myHelper->GetMesh()->GetSubMesh( thePrism.myTop );
2013 SMESHDS_SubMesh * botSMDS = botSM->GetSubMeshDS();
2014 SMESHDS_SubMesh * topSMDS = topSM->GetSubMeshDS();
2016 if ( topSMDS && topSMDS->NbElements() > 0 )
2017 topSM->ComputeStateEngine( SMESH_subMesh::CLEAN );
2019 const TopoDS_Face& botFace = thePrism.myBottom; // oriented within
2020 const TopoDS_Face& topFace = thePrism.myTop; // the 3D SHAPE
2021 int topFaceID = meshDS->ShapeToIndex( thePrism.myTop );
2023 SMESH_MesherHelper botHelper( *myHelper->GetMesh() );
2024 botHelper.SetSubShape( botFace );
2025 botHelper.ToFixNodeParameters( true );
2027 SMESH_MesherHelper topHelper( *myHelper->GetMesh() );
2028 topHelper.SetSubShape( topFace );
2029 topHelper.ToFixNodeParameters( true );
2030 double distXYZ[4], fixTol = 10 * topHelper.MaxTolerance( topFace );
2032 // Fill myBotToColumnMap
2034 int zSize = myBlock.VerticalSize();
2035 Prism_3D::TNode prevTNode;
2036 SMDS_NodeIteratorPtr nIt = botSMDS->GetNodes();
2037 while ( nIt->more() )
2039 const SMDS_MeshNode* botNode = nIt->next();
2040 const SMDS_MeshNode* topNode = 0;
2041 if ( botNode->GetPosition()->GetTypeOfPosition() != SMDS_TOP_FACE )
2042 continue; // strange
2044 Prism_3D::TNode bN( botNode );
2045 if ( bottomToTopTrsf.Form() == gp_Identity )
2047 // compute bottom node params
2048 gp_XYZ paramHint(-1,-1,-1);
2049 if ( prevTNode.IsNeighbor( bN ))
2051 paramHint = prevTNode.GetParams();
2052 // double tol = 1e-2 * ( prevTNode.GetCoords() - bN.GetCoords() ).Modulus();
2053 // myBlock.SetTolerance( Min( myBlock.GetTolerance(), tol ));
2055 if ( !myBlock.ComputeParameters( bN.GetCoords(), bN.ChangeParams(),
2056 ID_BOT_FACE, paramHint ))
2057 return toSM( error(TCom("Can't compute normalized parameters for node ")
2058 << botNode->GetID() << " on the face #"<< botSM->GetId() ));
2060 // compute top node coords
2061 gp_XYZ topXYZ; gp_XY topUV;
2062 if ( !myBlock.FacePoint( ID_TOP_FACE, bN.GetParams(), topXYZ ) ||
2063 !myBlock.FaceUV ( ID_TOP_FACE, bN.GetParams(), topUV ))
2064 return toSM( error(TCom("Can't compute coordinates "
2065 "by normalized parameters on the face #")<< topSM->GetId() ));
2066 topNode = meshDS->AddNode( topXYZ.X(),topXYZ.Y(),topXYZ.Z() );
2067 meshDS->SetNodeOnFace( topNode, topFaceID, topUV.X(), topUV.Y() );
2069 else // use bottomToTopTrsf
2071 gp_XYZ coords = bN.GetCoords();
2072 bottomToTopTrsf.Transforms( coords );
2073 topNode = meshDS->AddNode( coords.X(), coords.Y(), coords.Z() );
2074 gp_XY topUV = botHelper.GetNodeUV( botFace, botNode, 0, &checkUV );
2075 meshDS->SetNodeOnFace( topNode, topFaceID, topUV.X(), topUV.Y() );
2077 if ( topHelper.CheckNodeUV( topFace, topNode, topUV, fixTol, /*force=*/false, distXYZ ) &&
2078 distXYZ[0] > fixTol && distXYZ[0] < fixTol * 1e+3 )
2079 meshDS->MoveNode( topNode, distXYZ[1], distXYZ[2], distXYZ[3] ); // transform can be inaccurate
2081 // create node column
2082 TNode2ColumnMap::iterator bN_col =
2083 myBotToColumnMap.insert( make_pair ( bN, TNodeColumn() )).first;
2084 TNodeColumn & column = bN_col->second;
2085 column.resize( zSize );
2086 column.front() = botNode;
2087 column.back() = topNode;
2089 if ( _computeCanceled )
2090 return toSM( error( SMESH_ComputeError::New(COMPERR_CANCELED)));
2095 const bool oldSetElemsOnShape = myHelper->SetElementsOnShape( false );
2097 // care of orientation;
2098 // if the bottom faces is orienetd OK then top faces must be reversed
2099 bool reverseTop = true;
2100 if ( myHelper->NbAncestors( botFace, *myBlock.Mesh(), TopAbs_SOLID ) > 1 )
2101 reverseTop = ! myHelper->IsReversedSubMesh( botFace );
2102 int iFrw, iRev, *iPtr = &( reverseTop ? iRev : iFrw );
2104 // loop on bottom mesh faces
2105 SMDS_ElemIteratorPtr faceIt = botSMDS->GetElements();
2106 vector< const SMDS_MeshNode* > nodes;
2107 while ( faceIt->more() )
2109 const SMDS_MeshElement* face = faceIt->next();
2110 if ( !face || face->GetType() != SMDSAbs_Face )
2113 // find top node in columns for each bottom node
2114 int nbNodes = face->NbCornerNodes();
2115 nodes.resize( nbNodes );
2116 for ( iFrw = 0, iRev = nbNodes-1; iFrw < nbNodes; ++iFrw, --iRev )
2118 const SMDS_MeshNode* n = face->GetNode( *iPtr );
2119 if ( n->GetPosition()->GetTypeOfPosition() == SMDS_TOP_FACE ) {
2120 TNode2ColumnMap::iterator bot_column = myBotToColumnMap.find( n );
2121 if ( bot_column == myBotToColumnMap.end() )
2122 return toSM( error(TCom("No nodes found above node ") << n->GetID() ));
2123 nodes[ iFrw ] = bot_column->second.back();
2126 const TNodeColumn* column = myBlock.GetNodeColumn( n );
2128 return toSM( error(TCom("No side nodes found above node ") << n->GetID() ));
2129 nodes[ iFrw ] = column->back();
2132 SMDS_MeshElement* newFace = 0;
2133 switch ( nbNodes ) {
2136 newFace = myHelper->AddFace(nodes[0], nodes[1], nodes[2]);
2140 newFace = myHelper->AddFace( nodes[0], nodes[1], nodes[2], nodes[3] );
2144 newFace = meshDS->AddPolygonalFace( nodes );
2147 meshDS->SetMeshElementOnShape( newFace, topFaceID );
2150 myHelper->SetElementsOnShape( oldSetElemsOnShape );
2155 //=======================================================================
2156 //function : getSweepTolerance
2157 //purpose : Compute tolerance to pass to StdMeshers_Sweeper
2158 //=======================================================================
2160 double StdMeshers_Prism_3D::getSweepTolerance( const Prism_3D::TPrismTopo& thePrism )
2162 SMESHDS_Mesh* meshDS = myHelper->GetMeshDS();
2163 SMESHDS_SubMesh * sm[2] = { meshDS->MeshElements( thePrism.myBottom ),
2164 meshDS->MeshElements( thePrism.myTop ) };
2165 double minDist = 1e100;
2167 vector< SMESH_TNodeXYZ > nodes;
2168 for ( int iSM = 0; iSM < 2; ++iSM )
2170 if ( !sm[ iSM ]) continue;
2172 SMDS_ElemIteratorPtr fIt = sm[ iSM ]->GetElements();
2173 while ( fIt->more() )
2175 const SMDS_MeshElement* face = fIt->next();
2176 const int nbNodes = face->NbCornerNodes();
2177 SMDS_ElemIteratorPtr nIt = face->nodesIterator();
2179 nodes.resize( nbNodes + 1 );
2180 for ( int iN = 0; iN < nbNodes; ++iN )
2181 nodes[ iN ] = nIt->next();
2182 nodes.back() = nodes[0];
2186 for ( int iN = 0; iN < nbNodes; ++iN )
2188 if ( nodes[ iN ]._node->GetPosition()->GetDim() < 2 &&
2189 nodes[ iN+1 ]._node->GetPosition()->GetDim() < 2 )
2191 // it's a boundary link; measure distance of other
2192 // nodes to this link
2193 gp_XYZ linkDir = nodes[ iN ] - nodes[ iN+1 ];
2194 double linkLen = linkDir.Modulus();
2195 bool isDegen = ( linkLen < numeric_limits<double>::min() );
2196 if ( !isDegen ) linkDir /= linkLen;
2197 for ( int iN2 = 0; iN2 < nbNodes; ++iN2 ) // loop on other nodes
2199 if ( nodes[ iN2 ] == nodes[ iN ] ||
2200 nodes[ iN2 ] == nodes[ iN+1 ]) continue;
2203 dist2 = ( nodes[ iN ] - nodes[ iN2 ]).SquareModulus();
2207 dist2 = linkDir.CrossSquareMagnitude( nodes[ iN ] - nodes[ iN2 ]);
2209 if ( dist2 > numeric_limits<double>::min() )
2210 minDist = Min ( minDist, dist2 );
2213 // measure length link
2214 else if ( nodes[ iN ]._node < nodes[ iN+1 ]._node ) // not to measure same link twice
2216 dist2 = ( nodes[ iN ] - nodes[ iN+1 ]).SquareModulus();
2217 if ( dist2 > numeric_limits<double>::min() )
2218 minDist = Min ( minDist, dist2 );
2223 return 0.1 * Sqrt ( minDist );
2226 //=======================================================================
2227 //function : project2dMesh
2228 //purpose : Project mesh faces from a source FACE of one prism (theSrcFace)
2229 // to a source FACE of another prism (theTgtFace)
2230 //=======================================================================
2232 bool StdMeshers_Prism_3D::project2dMesh(const TopoDS_Face& theSrcFace,
2233 const TopoDS_Face& theTgtFace)
2235 TProjction2dAlgo* projector2D = TProjction2dAlgo::instance( this );
2236 projector2D->myHyp.SetSourceFace( theSrcFace );
2237 bool ok = projector2D->Compute( *myHelper->GetMesh(), theTgtFace );
2239 SMESH_subMesh* tgtSM = myHelper->GetMesh()->GetSubMesh( theTgtFace );
2240 tgtSM->ComputeStateEngine ( SMESH_subMesh::CHECK_COMPUTE_STATE );
2241 tgtSM->ComputeSubMeshStateEngine( SMESH_subMesh::CHECK_COMPUTE_STATE );
2246 //================================================================================
2248 * \brief Set projection coordinates of a node to a face and it's sub-shapes
2249 * \param faceID - the face given by in-block ID
2250 * \param params - node normalized parameters
2251 * \retval bool - is a success
2253 //================================================================================
2255 bool StdMeshers_Prism_3D::setFaceAndEdgesXYZ( const int faceID, const gp_XYZ& params, int z )
2257 // find base and top edges of the face
2258 enum { BASE = 0, TOP, LEFT, RIGHT };
2259 vector< int > edgeVec; // 0-base, 1-top
2260 SMESH_Block::GetFaceEdgesIDs( faceID, edgeVec );
2262 myBlock.EdgePoint( edgeVec[ BASE ], params, myShapeXYZ[ edgeVec[ BASE ]]);
2263 myBlock.EdgePoint( edgeVec[ TOP ], params, myShapeXYZ[ edgeVec[ TOP ]]);
2265 SHOWYXZ("\nparams ", params);
2266 SHOWYXZ("TOP is " <<edgeVec[ TOP ], myShapeXYZ[ edgeVec[ TOP]]);
2267 SHOWYXZ("BASE is "<<edgeVec[ BASE], myShapeXYZ[ edgeVec[ BASE]]);
2269 if ( faceID == SMESH_Block::ID_Fx0z || faceID == SMESH_Block::ID_Fx1z )
2271 myBlock.EdgePoint( edgeVec[ LEFT ], params, myShapeXYZ[ edgeVec[ LEFT ]]);
2272 myBlock.EdgePoint( edgeVec[ RIGHT ], params, myShapeXYZ[ edgeVec[ RIGHT ]]);
2274 SHOWYXZ("VER "<<edgeVec[ LEFT], myShapeXYZ[ edgeVec[ LEFT]]);
2275 SHOWYXZ("VER "<<edgeVec[ RIGHT], myShapeXYZ[ edgeVec[ RIGHT]]);
2277 myBlock.FacePoint( faceID, params, myShapeXYZ[ faceID ]);
2278 SHOWYXZ("FacePoint "<<faceID, myShapeXYZ[ faceID]);
2283 //=======================================================================
2285 //purpose : If (!isOK), sets the error to a sub-mesh of a current SOLID
2286 //=======================================================================
2288 bool StdMeshers_Prism_3D::toSM( bool isOK )
2290 if ( mySetErrorToSM &&
2293 !myHelper->GetSubShape().IsNull() &&
2294 myHelper->GetSubShape().ShapeType() == TopAbs_SOLID)
2296 SMESH_subMesh* sm = myHelper->GetMesh()->GetSubMesh( myHelper->GetSubShape() );
2297 sm->GetComputeError() = this->GetComputeError();
2298 // clear error in order not to return it twice
2299 _error = COMPERR_OK;
2305 //=======================================================================
2306 //function : shapeID
2307 //purpose : Return index of a shape
2308 //=======================================================================
2310 int StdMeshers_Prism_3D::shapeID( const TopoDS_Shape& S )
2312 if ( S.IsNull() ) return 0;
2313 if ( !myHelper ) return -3;
2314 return myHelper->GetMeshDS()->ShapeToIndex( S );
2317 namespace // utils used by StdMeshers_Prism_3D::IsApplicable()
2319 struct EdgeWithNeighbors
2323 EdgeWithNeighbors(const TopoDS_Edge& E, int iE, int nbE, int shift = 0 ):
2325 _iL( SMESH_MesherHelper::WrapIndex( iE-1, nbE ) + shift ),
2326 _iR( SMESH_MesherHelper::WrapIndex( iE+1, nbE ) + shift )
2329 EdgeWithNeighbors() {}
2334 TopTools_IndexedMapOfShape *_faces; // pointer because its copy constructor is private
2335 TopoDS_Edge _topEdge;
2336 vector< EdgeWithNeighbors >*_edges;
2338 vector< bool > _isCheckedEdge;
2339 int _nbCheckedEdges; // nb of EDGEs whose location is defined
2340 PrismSide *_leftSide;
2341 PrismSide *_rightSide;
2342 const TopoDS_Edge& Edge( int i ) const
2344 return (*_edges)[ i ]._edge;
2346 int FindEdge( const TopoDS_Edge& E ) const
2348 for ( size_t i = 0; i < _edges->size(); ++i )
2349 if ( E.IsSame( Edge( i ))) return i;
2352 bool IsSideFace( const TopoDS_Shape& face ) const
2354 if ( _faces->Contains( face )) // avoid returning true for a prism top FACE
2355 return ( !_face.IsNull() || !( face.IsSame( _faces->FindKey( _faces->Extent() ))));
2359 //--------------------------------------------------------------------------------
2361 * \brief Return ordered edges of a face
2363 bool getEdges( const TopoDS_Face& face,
2364 vector< EdgeWithNeighbors > & edges,
2365 const bool noHolesAllowed)
2367 list< TopoDS_Edge > ee;
2368 list< int > nbEdgesInWires;
2369 int nbW = SMESH_Block::GetOrderedEdges( face, ee, nbEdgesInWires );
2370 if ( nbW > 1 && noHolesAllowed )
2374 list< TopoDS_Edge >::iterator e = ee.begin();
2375 list< int >::iterator nbE = nbEdgesInWires.begin();
2376 for ( ; nbE != nbEdgesInWires.end(); ++nbE )
2377 for ( iE = 0; iE < *nbE; ++e, ++iE )
2378 if ( SMESH_Algo::isDegenerated( *e ))
2386 e->Orientation( TopAbs_FORWARD ); // for operator==() to work
2391 for ( nbE = nbEdgesInWires.begin(); nbE != nbEdgesInWires.end(); ++nbE )
2393 for ( iE = 0; iE < *nbE; ++e, ++iE )
2394 edges.push_back( EdgeWithNeighbors( *e, iE, *nbE, nbTot ));
2397 return edges.size();
2399 //--------------------------------------------------------------------------------
2401 * \brief Return another faces sharing an edge
2403 const TopoDS_Shape & getAnotherFace( const TopoDS_Face& face,
2404 const TopoDS_Edge& edge,
2405 TopTools_IndexedDataMapOfShapeListOfShape& facesOfEdge)
2407 TopTools_ListIteratorOfListOfShape faceIt( facesOfEdge.FindFromKey( edge ));
2408 for ( ; faceIt.More(); faceIt.Next() )
2409 if ( !face.IsSame( faceIt.Value() ))
2410 return faceIt.Value();
2415 //================================================================================
2417 * \brief Return true if the algorithm can mesh this shape
2418 * \param [in] aShape - shape to check
2419 * \param [in] toCheckAll - if true, this check returns OK if all shapes are OK,
2420 * else, returns OK if at least one shape is OK
2422 //================================================================================
2424 bool StdMeshers_Prism_3D::IsApplicable(const TopoDS_Shape & shape, bool toCheckAll)
2426 TopExp_Explorer sExp( shape, TopAbs_SOLID );
2430 for ( ; sExp.More(); sExp.Next() )
2434 TopExp_Explorer shExp( sExp.Current(), TopAbs_SHELL );
2435 if ( shExp.More() ) {
2436 shell = shExp.Current();
2441 if ( shell.IsNull() ) {
2442 if ( toCheckAll ) return false;
2446 TopTools_IndexedMapOfShape allFaces;
2447 TopExp::MapShapes( shell, TopAbs_FACE, allFaces );
2448 if ( allFaces.Extent() < 3 ) {
2449 if ( toCheckAll ) return false;
2453 if ( allFaces.Extent() == 6 )
2455 TopTools_IndexedMapOfOrientedShape map;
2456 bool isBox = SMESH_Block::FindBlockShapes( TopoDS::Shell( shell ),
2457 TopoDS_Vertex(), TopoDS_Vertex(), map );
2459 if ( !toCheckAll ) return true;
2464 TopTools_IndexedMapOfShape allShapes;
2465 TopExp::MapShapes( shape, allShapes );
2468 TopTools_IndexedDataMapOfShapeListOfShape facesOfEdge;
2469 TopTools_ListIteratorOfListOfShape faceIt;
2470 TopExp::MapShapesAndAncestors( sExp.Current(), TopAbs_EDGE, TopAbs_FACE , facesOfEdge );
2471 if ( facesOfEdge.IsEmpty() ) {
2472 if ( toCheckAll ) return false;
2476 typedef vector< EdgeWithNeighbors > TEdgeWithNeighborsVec;
2477 vector< TEdgeWithNeighborsVec > faceEdgesVec( allFaces.Extent() + 1 );
2478 TopTools_IndexedMapOfShape* facesOfSide = new TopTools_IndexedMapOfShape[ faceEdgesVec.size() ];
2479 SMESHUtils::ArrayDeleter<TopTools_IndexedMapOfShape> delFacesOfSide( facesOfSide );
2481 // try to use each face as a bottom one
2482 bool prismDetected = false;
2483 for ( int iF = 1; iF < allFaces.Extent() && !prismDetected; ++iF )
2485 const TopoDS_Face& botF = TopoDS::Face( allFaces( iF ));
2487 TEdgeWithNeighborsVec& botEdges = faceEdgesVec[ iF ];
2488 if ( botEdges.empty() )
2489 if ( !getEdges( botF, botEdges, /*noHoles=*/false ))
2491 if ( allFaces.Extent()-1 <= (int) botEdges.size() )
2492 continue; // all faces are adjacent to botF - no top FACE
2494 // init data of side FACEs
2495 vector< PrismSide > sides( botEdges.size() );
2496 for ( int iS = 0; iS < botEdges.size(); ++iS )
2498 sides[ iS ]._topEdge = botEdges[ iS ]._edge;
2499 sides[ iS ]._face = botF;
2500 sides[ iS ]._leftSide = & sides[ botEdges[ iS ]._iR ];
2501 sides[ iS ]._rightSide = & sides[ botEdges[ iS ]._iL ];
2502 sides[ iS ]._faces = & facesOfSide[ iS ];
2503 sides[ iS ]._faces->Clear();
2506 bool isOK = true; // ok for a current botF
2507 bool isAdvanced = true; // is new data found in a current loop
2508 int nbFoundSideFaces = 0;
2509 for ( int iLoop = 0; isOK && isAdvanced; ++iLoop )
2512 for ( size_t iS = 0; iS < sides.size() && isOK; ++iS )
2514 PrismSide& side = sides[ iS ];
2515 if ( side._face.IsNull() )
2516 continue; // probably the prism top face is the last of side._faces
2518 if ( side._topEdge.IsNull() )
2520 // find vertical EDGEs --- EGDEs shared with neighbor side FACEs
2521 for ( int is2nd = 0; is2nd < 2 && isOK; ++is2nd ) // 2 adjacent neighbors
2523 int di = is2nd ? 1 : -1;
2524 const PrismSide* adjSide = is2nd ? side._rightSide : side._leftSide;
2525 for ( size_t i = 1; i < side._edges->size(); ++i )
2527 int iE = SMESH_MesherHelper::WrapIndex( i*di + side._iBotEdge, side._edges->size());
2528 if ( side._isCheckedEdge[ iE ] ) continue;
2529 const TopoDS_Edge& vertE = side.Edge( iE );
2530 const TopoDS_Shape& neighborF = getAnotherFace( side._face, vertE, facesOfEdge );
2531 bool isEdgeShared = adjSide->IsSideFace( neighborF );
2535 side._isCheckedEdge[ iE ] = true;
2536 side._nbCheckedEdges++;
2537 int nbNotCheckedE = side._edges->size() - side._nbCheckedEdges;
2538 if ( nbNotCheckedE == 1 )
2543 if ( i == 1 && iLoop == 0 ) isOK = false;
2549 int nbNotCheckedE = side._edges->size() - side._nbCheckedEdges;
2550 if ( nbNotCheckedE == 1 )
2552 vector<bool>::iterator ii = std::find( side._isCheckedEdge.begin(),
2553 side._isCheckedEdge.end(), false );
2554 if ( ii != side._isCheckedEdge.end() )
2556 size_t iE = std::distance( side._isCheckedEdge.begin(), ii );
2557 side._topEdge = side.Edge( iE );
2560 isOK = ( nbNotCheckedE >= 1 );
2562 else //if ( !side._topEdge.IsNull() )
2564 // get a next face of a side
2565 const TopoDS_Shape& f = getAnotherFace( side._face, side._topEdge, facesOfEdge );
2566 side._faces->Add( f );
2568 if ( f.IsSame( side._face ) || // _topEdge is a seam
2569 SMESH_MesherHelper::Count( f, TopAbs_WIRE, false ) != 1 )
2573 else if ( side._leftSide != & side ) // not closed side face
2575 if ( side._leftSide->_faces->Contains( f ))
2577 stop = true; // probably f is the prism top face
2578 side._leftSide->_face.Nullify();
2579 side._leftSide->_topEdge.Nullify();
2581 if ( side._rightSide->_faces->Contains( f ))
2583 stop = true; // probably f is the prism top face
2584 side._rightSide->_face.Nullify();
2585 side._rightSide->_topEdge.Nullify();
2590 side._face.Nullify();
2591 side._topEdge.Nullify();
2594 side._face = TopoDS::Face( f );
2595 int faceID = allFaces.FindIndex( side._face );
2596 side._edges = & faceEdgesVec[ faceID ];
2597 if ( side._edges->empty() )
2598 if ( !getEdges( side._face, * side._edges, /*noHoles=*/true ))
2600 const int nbE = side._edges->size();
2605 side._iBotEdge = side.FindEdge( side._topEdge );
2606 side._isCheckedEdge.clear();
2607 side._isCheckedEdge.resize( nbE, false );
2608 side._isCheckedEdge[ side._iBotEdge ] = true;
2609 side._nbCheckedEdges = 1; // bottom EDGE is known
2611 side._topEdge.Nullify();
2612 isOK = ( !side._edges->empty() || side._faces->Extent() > 1 );
2614 } //if ( !side._topEdge.IsNull() )
2616 } // loop on prism sides
2618 if ( nbFoundSideFaces > allFaces.Extent() )
2622 if ( iLoop > allFaces.Extent() * 10 )
2626 cerr << "BUG: infinite loop in StdMeshers_Prism_3D::IsApplicable()" << endl;
2629 } // while isAdvanced
2631 if ( isOK && sides[0]._faces->Extent() > 1 )
2633 const int nbFaces = sides[0]._faces->Extent();
2634 if ( botEdges.size() == 1 ) // cylinder
2636 prismDetected = ( nbFaces == allFaces.Extent()-1 );
2640 const TopoDS_Shape& topFace = sides[0]._faces->FindKey( nbFaces );
2642 for ( iS = 1; iS < sides.size(); ++iS )
2643 if ( !sides[ iS ]._faces->Contains( topFace ))
2645 prismDetected = ( iS == sides.size() );
2648 } // loop on allFaces
2650 if ( !prismDetected && toCheckAll ) return false;
2651 if ( prismDetected && !toCheckAll ) return true;
2660 //================================================================================
2662 * \brief Return true if this node and other one belong to one face
2664 //================================================================================
2666 bool Prism_3D::TNode::IsNeighbor( const Prism_3D::TNode& other ) const
2668 if ( !other.myNode || !myNode ) return false;
2670 SMDS_ElemIteratorPtr fIt = other.myNode->GetInverseElementIterator(SMDSAbs_Face);
2671 while ( fIt->more() )
2672 if ( fIt->next()->GetNodeIndex( myNode ) >= 0 )
2677 //================================================================================
2679 * \brief Prism initialization
2681 //================================================================================
2683 void TPrismTopo::Clear()
2685 myShape3D.Nullify();
2688 myWallQuads.clear();
2689 myBottomEdges.clear();
2690 myNbEdgesInWires.clear();
2691 myWallQuads.clear();
2694 //================================================================================
2696 * \brief Set upside-down
2698 //================================================================================
2700 void TPrismTopo::SetUpsideDown()
2702 std::swap( myBottom, myTop );
2703 myBottomEdges.clear();
2704 std::reverse( myBottomEdges.begin(), myBottomEdges.end() );
2705 for ( size_t i = 0; i < myWallQuads.size(); ++i )
2707 myWallQuads[i].reverse();
2708 TQuadList::iterator q = myWallQuads[i].begin();
2709 for ( ; q != myWallQuads[i].end(); ++q )
2711 (*q)->shift( 2, /*keepUnitOri=*/true );
2713 myBottomEdges.push_back( myWallQuads[i].front()->side[ QUAD_BOTTOM_SIDE ].grid->Edge(0) );
2717 } // namespace Prism_3D
2719 //================================================================================
2721 * \brief Constructor. Initialization is needed
2723 //================================================================================
2725 StdMeshers_PrismAsBlock::StdMeshers_PrismAsBlock()
2730 StdMeshers_PrismAsBlock::~StdMeshers_PrismAsBlock()
2734 void StdMeshers_PrismAsBlock::Clear()
2737 myShapeIDMap.Clear();
2741 delete mySide; mySide = 0;
2743 myParam2ColumnMaps.clear();
2744 myShapeIndex2ColumnMap.clear();
2747 //=======================================================================
2748 //function : initPrism
2749 //purpose : Analyse shape geometry and mesh.
2750 // If there are triangles on one of faces, it becomes 'bottom'.
2751 // thePrism.myBottom can be already set up.
2752 //=======================================================================
2754 bool StdMeshers_Prism_3D::initPrism(Prism_3D::TPrismTopo& thePrism,
2755 const TopoDS_Shape& shape3D)
2757 myHelper->SetSubShape( shape3D );
2759 SMESH_subMesh* mainSubMesh = myHelper->GetMesh()->GetSubMeshContaining( shape3D );
2760 if ( !mainSubMesh ) return toSM( error(COMPERR_BAD_INPUT_MESH,"Null submesh of shape3D"));
2762 // detect not-quad FACE sub-meshes of the 3D SHAPE
2763 list< SMESH_subMesh* > notQuadGeomSubMesh;
2764 list< SMESH_subMesh* > notQuadElemSubMesh;
2767 SMESH_subMesh* anyFaceSM = 0;
2768 SMESH_subMeshIteratorPtr smIt = mainSubMesh->getDependsOnIterator(false,true);
2769 while ( smIt->more() )
2771 SMESH_subMesh* sm = smIt->next();
2772 const TopoDS_Shape& face = sm->GetSubShape();
2773 if ( face.ShapeType() > TopAbs_FACE ) break;
2774 else if ( face.ShapeType() < TopAbs_FACE ) continue;
2778 // is quadrangle FACE?
2779 list< TopoDS_Edge > orderedEdges;
2780 list< int > nbEdgesInWires;
2781 int nbWires = SMESH_Block::GetOrderedEdges( TopoDS::Face( face ), orderedEdges,
2783 if ( nbWires != 1 || nbEdgesInWires.front() != 4 )
2784 notQuadGeomSubMesh.push_back( sm );
2786 // look for not quadrangle mesh elements
2787 if ( SMESHDS_SubMesh* smDS = sm->GetSubMeshDS() )
2788 if ( !myHelper->IsSameElemGeometry( smDS, SMDSGeom_QUADRANGLE ))
2789 notQuadElemSubMesh.push_back( sm );
2792 int nbNotQuadMeshed = notQuadElemSubMesh.size();
2793 int nbNotQuad = notQuadGeomSubMesh.size();
2794 bool hasNotQuad = ( nbNotQuad || nbNotQuadMeshed );
2797 if ( nbNotQuadMeshed > 2 )
2799 return toSM( error(COMPERR_BAD_INPUT_MESH,
2800 TCom("More than 2 faces with not quadrangle elements: ")
2801 <<nbNotQuadMeshed));
2803 if ( nbNotQuad > 2 || !thePrism.myBottom.IsNull() )
2805 // Issue 0020843 - one of side FACEs is quasi-quadrilateral (not 4 EDGEs).
2806 // Remove from notQuadGeomSubMesh faces meshed with regular grid
2807 int nbQuasiQuads = removeQuasiQuads( notQuadGeomSubMesh, myHelper,
2808 TQuadrangleAlgo::instance(this,myHelper) );
2809 nbNotQuad -= nbQuasiQuads;
2810 if ( nbNotQuad > 2 )
2811 return toSM( error(COMPERR_BAD_SHAPE,
2812 TCom("More than 2 not quadrilateral faces: ") <<nbNotQuad));
2813 hasNotQuad = ( nbNotQuad || nbNotQuadMeshed );
2816 // Analyse mesh and topology of FACEs: choose the bottom sub-mesh.
2817 // If there are not quadrangle FACEs, they are top and bottom ones.
2818 // Not quadrangle FACEs must be only on top and bottom.
2820 SMESH_subMesh * botSM = 0;
2821 SMESH_subMesh * topSM = 0;
2823 if ( hasNotQuad ) // can choose a bottom FACE
2825 if ( nbNotQuadMeshed > 0 ) botSM = notQuadElemSubMesh.front();
2826 else botSM = notQuadGeomSubMesh.front();
2827 if ( nbNotQuadMeshed > 1 ) topSM = notQuadElemSubMesh.back();
2828 else if ( nbNotQuad > 1 ) topSM = notQuadGeomSubMesh.back();
2830 if ( topSM == botSM ) {
2831 if ( nbNotQuadMeshed > 1 ) topSM = notQuadElemSubMesh.front();
2832 else topSM = notQuadGeomSubMesh.front();
2835 // detect mesh triangles on wall FACEs
2836 if ( nbNotQuad == 2 && nbNotQuadMeshed > 0 ) {
2838 if ( nbNotQuadMeshed == 1 )
2839 ok = ( find( notQuadGeomSubMesh.begin(),
2840 notQuadGeomSubMesh.end(), botSM ) != notQuadGeomSubMesh.end() );
2842 ok = ( notQuadGeomSubMesh == notQuadElemSubMesh );
2844 return toSM( error(COMPERR_BAD_INPUT_MESH,
2845 "Side face meshed with not quadrangle elements"));
2849 thePrism.myNotQuadOnTop = ( nbNotQuadMeshed > 1 );
2851 // use thePrism.myBottom
2852 if ( !thePrism.myBottom.IsNull() )
2855 if ( ! botSM->GetSubShape().IsSame( thePrism.myBottom )) {
2856 std::swap( botSM, topSM );
2857 if ( !botSM || ! botSM->GetSubShape().IsSame( thePrism.myBottom ))
2858 return toSM( error( COMPERR_BAD_INPUT_MESH,
2859 "Incompatible non-structured sub-meshes"));
2863 botSM = myHelper->GetMesh()->GetSubMesh( thePrism.myBottom );
2866 else if ( !botSM ) // find a proper bottom
2868 // composite walls or not prism shape
2869 for ( TopExp_Explorer f( shape3D, TopAbs_FACE ); f.More(); f.Next() )
2871 int minNbFaces = 2 + myHelper->Count( f.Current(), TopAbs_EDGE, false);
2872 if ( nbFaces >= minNbFaces)
2875 thePrism.myBottom = TopoDS::Face( f.Current() );
2876 if ( initPrism( thePrism, shape3D ))
2879 return toSM( error( COMPERR_BAD_SHAPE ));
2883 // find vertex 000 - the one with smallest coordinates (for easy DEBUG :-)
2885 double minVal = DBL_MAX, minX, val;
2886 for ( TopExp_Explorer exp( botSM->GetSubShape(), TopAbs_VERTEX );
2887 exp.More(); exp.Next() )
2889 const TopoDS_Vertex& v = TopoDS::Vertex( exp.Current() );
2890 gp_Pnt P = BRep_Tool::Pnt( v );
2891 val = P.X() + P.Y() + P.Z();
2892 if ( val < minVal || ( val == minVal && P.X() < minX )) {
2899 thePrism.myShape3D = shape3D;
2900 if ( thePrism.myBottom.IsNull() )
2901 thePrism.myBottom = TopoDS::Face( botSM->GetSubShape() );
2902 thePrism.myBottom.Orientation( myHelper->GetSubShapeOri( shape3D, thePrism.myBottom ));
2903 thePrism.myTop. Orientation( myHelper->GetSubShapeOri( shape3D, thePrism.myTop ));
2905 // Get ordered bottom edges
2906 TopoDS_Face reverseBottom = // to have order of top EDGEs as in the top FACE
2907 TopoDS::Face( thePrism.myBottom.Reversed() );
2908 SMESH_Block::GetOrderedEdges( reverseBottom,
2909 thePrism.myBottomEdges,
2910 thePrism.myNbEdgesInWires, V000 );
2912 // Get Wall faces corresponding to the ordered bottom edges and the top FACE
2913 if ( !getWallFaces( thePrism, nbFaces ))
2914 return false; //toSM( error(COMPERR_BAD_SHAPE, "Can't find side faces"));
2918 if ( !thePrism.myTop.IsSame( topSM->GetSubShape() ))
2920 (notQuadGeomSubMesh.empty() ? COMPERR_BAD_INPUT_MESH : COMPERR_BAD_SHAPE,
2921 "Non-quadrilateral faces are not opposite"));
2923 // check that the found top and bottom FACEs are opposite
2924 list< TopoDS_Edge >::iterator edge = thePrism.myBottomEdges.begin();
2925 for ( ; edge != thePrism.myBottomEdges.end(); ++edge )
2926 if ( myHelper->IsSubShape( *edge, thePrism.myTop ))
2928 (notQuadGeomSubMesh.empty() ? COMPERR_BAD_INPUT_MESH : COMPERR_BAD_SHAPE,
2929 "Non-quadrilateral faces are not opposite"));
2932 if ( thePrism.myBottomEdges.size() > thePrism.myWallQuads.size() )
2934 // composite bottom sides => set thePrism upside-down
2935 thePrism.SetUpsideDown();
2941 //================================================================================
2943 * \brief Initialization.
2944 * \param helper - helper loaded with mesh and 3D shape
2945 * \param thePrism - a prism data
2946 * \retval bool - false if a mesh or a shape are KO
2948 //================================================================================
2950 bool StdMeshers_PrismAsBlock::Init(SMESH_MesherHelper* helper,
2951 const Prism_3D::TPrismTopo& thePrism)
2954 SMESHDS_Mesh* meshDS = myHelper->GetMeshDS();
2955 SMESH_Mesh* mesh = myHelper->GetMesh();
2958 delete mySide; mySide = 0;
2960 vector< TSideFace* > sideFaces( NB_WALL_FACES, 0 );
2961 vector< pair< double, double> > params( NB_WALL_FACES );
2962 mySide = new TSideFace( *mesh, sideFaces, params );
2965 SMESH_Block::init();
2966 myShapeIDMap.Clear();
2967 myShapeIndex2ColumnMap.clear();
2969 int wallFaceIds[ NB_WALL_FACES ] = { // to walk around a block
2970 SMESH_Block::ID_Fx0z, SMESH_Block::ID_F1yz,
2971 SMESH_Block::ID_Fx1z, SMESH_Block::ID_F0yz
2974 myError = SMESH_ComputeError::New();
2976 myNotQuadOnTop = thePrism.myNotQuadOnTop;
2978 // Find columns of wall nodes and calculate edges' lengths
2979 // --------------------------------------------------------
2981 myParam2ColumnMaps.clear();
2982 myParam2ColumnMaps.resize( thePrism.myBottomEdges.size() ); // total nb edges
2984 size_t iE, nbEdges = thePrism.myNbEdgesInWires.front(); // nb outer edges
2985 vector< double > edgeLength( nbEdges );
2986 multimap< double, int > len2edgeMap;
2988 // for each EDGE: either split into several parts, or join with several next EDGEs
2989 vector<int> nbSplitPerEdge( nbEdges, 0 );
2990 vector<int> nbUnitePerEdge( nbEdges, 0 ); // -1 means "joined to a previous"
2992 // consider continuous straight EDGEs as one side
2993 const int nbSides = countNbSides( thePrism, nbUnitePerEdge, edgeLength );
2995 list< TopoDS_Edge >::const_iterator edgeIt = thePrism.myBottomEdges.begin();
2996 for ( iE = 0; iE < nbEdges; ++iE, ++edgeIt )
2998 TParam2ColumnMap & faceColumns = myParam2ColumnMaps[ iE ];
3000 Prism_3D::TQuadList::const_iterator quad = thePrism.myWallQuads[ iE ].begin();
3001 for ( ; quad != thePrism.myWallQuads[ iE ].end(); ++quad )
3003 const TopoDS_Edge& quadBot = (*quad)->side[ QUAD_BOTTOM_SIDE ].grid->Edge( 0 );
3004 if ( !myHelper->LoadNodeColumns( faceColumns, (*quad)->face, quadBot, meshDS ))
3005 return error(COMPERR_BAD_INPUT_MESH, TCom("Can't find regular quadrangle mesh ")
3006 << "on a side face #" << MeshDS()->ShapeToIndex( (*quad)->face ));
3008 SHOWYXZ("\np1 F " <<iE, gpXYZ(faceColumns.begin()->second.front() ));
3009 SHOWYXZ("p2 F " <<iE, gpXYZ(faceColumns.rbegin()->second.front() ));
3010 SHOWYXZ("V First "<<iE, BRep_Tool::Pnt( TopExp::FirstVertex(*edgeIt,true )));
3012 if ( nbSides < NB_WALL_FACES ) // fill map used to split faces
3013 len2edgeMap.insert( make_pair( edgeLength[ iE ], iE )); // sort edges by length
3015 // Load columns of internal edges (forming holes)
3016 // and fill map ShapeIndex to TParam2ColumnMap for them
3017 for ( ; edgeIt != thePrism.myBottomEdges.end() ; ++edgeIt, ++iE )
3019 TParam2ColumnMap & faceColumns = myParam2ColumnMaps[ iE ];
3021 Prism_3D::TQuadList::const_iterator quad = thePrism.myWallQuads[ iE ].begin();
3022 for ( ; quad != thePrism.myWallQuads[ iE ].end(); ++quad )
3024 const TopoDS_Edge& quadBot = (*quad)->side[ QUAD_BOTTOM_SIDE ].grid->Edge( 0 );
3025 if ( !myHelper->LoadNodeColumns( faceColumns, (*quad)->face, quadBot, meshDS ))
3026 return error(COMPERR_BAD_INPUT_MESH, TCom("Can't find regular quadrangle mesh ")
3027 << "on a side face #" << MeshDS()->ShapeToIndex( (*quad)->face ));
3030 int id = MeshDS()->ShapeToIndex( *edgeIt );
3031 bool isForward = true; // meaningless for intenal wires
3032 myShapeIndex2ColumnMap[ id ] = make_pair( & faceColumns, isForward );
3033 // columns for vertices
3035 const SMDS_MeshNode* n0 = faceColumns.begin()->second.front();
3036 id = n0->getshapeId();
3037 myShapeIndex2ColumnMap[ id ] = make_pair( & faceColumns, isForward );
3039 const SMDS_MeshNode* n1 = faceColumns.rbegin()->second.front();
3040 id = n1->getshapeId();
3041 myShapeIndex2ColumnMap[ id ] = make_pair( & faceColumns, isForward );
3043 // SHOWYXZ("\np1 F " <<iE, gpXYZ(faceColumns.begin()->second.front() ));
3044 // SHOWYXZ("p2 F " <<iE, gpXYZ(faceColumns.rbegin()->second.front() ));
3045 // SHOWYXZ("V First "<<iE, BRep_Tool::Pnt( TopExp::FirstVertex(*edgeIt,true )));
3048 // Create 4 wall faces of a block
3049 // -------------------------------
3051 if ( nbSides <= NB_WALL_FACES ) // ************* Split faces if necessary
3053 if ( nbSides != NB_WALL_FACES ) // define how to split
3055 if ( len2edgeMap.size() != nbEdges )
3056 RETURN_BAD_RESULT("Uniqueness of edge lengths not assured");
3058 multimap< double, int >::reverse_iterator maxLen_i = len2edgeMap.rbegin();
3059 multimap< double, int >::reverse_iterator midLen_i = ++len2edgeMap.rbegin();
3061 double maxLen = maxLen_i->first;
3062 double midLen = ( len2edgeMap.size() == 1 ) ? 0 : midLen_i->first;
3063 switch ( nbEdges ) {
3064 case 1: // 0-th edge is split into 4 parts
3065 nbSplitPerEdge[ 0 ] = 4;
3067 case 2: // either the longest edge is split into 3 parts, or both edges into halves
3068 if ( maxLen / 3 > midLen / 2 ) {
3069 nbSplitPerEdge[ maxLen_i->second ] = 3;
3072 nbSplitPerEdge[ maxLen_i->second ] = 2;
3073 nbSplitPerEdge[ midLen_i->second ] = 2;
3078 // split longest into 3 parts
3079 nbSplitPerEdge[ maxLen_i->second ] = 3;
3081 // split longest into halves
3082 nbSplitPerEdge[ maxLen_i->second ] = 2;
3086 else // **************************** Unite faces
3088 int nbExraFaces = nbSides - 4; // nb of faces to fuse
3089 for ( iE = 0; iE < nbEdges; ++iE )
3091 if ( nbUnitePerEdge[ iE ] < 0 )
3093 // look for already united faces
3094 for ( int i = iE; i < iE + nbExraFaces; ++i )
3096 if ( nbUnitePerEdge[ i ] > 0 ) // a side including nbUnitePerEdge[i]+1 edge
3097 nbExraFaces += nbUnitePerEdge[ i ];
3098 nbUnitePerEdge[ i ] = -1;
3100 nbUnitePerEdge[ iE ] = nbExraFaces;
3105 // Create TSideFace's
3107 list< TopoDS_Edge >::const_iterator botE = thePrism.myBottomEdges.begin();
3108 for ( iE = 0; iE < nbEdges; ++iE, ++botE )
3110 TFaceQuadStructPtr quad = thePrism.myWallQuads[ iE ].front();
3111 const int nbSplit = nbSplitPerEdge[ iE ];
3112 const int nbExraFaces = nbUnitePerEdge[ iE ] + 1;
3113 if ( nbSplit > 0 ) // split
3115 vector< double > params;
3116 splitParams( nbSplit, &myParam2ColumnMaps[ iE ], params );
3117 const bool isForward =
3118 StdMeshers_PrismAsBlock::IsForwardEdge( myHelper->GetMeshDS(),
3119 myParam2ColumnMaps[iE],
3120 *botE, SMESH_Block::ID_Fx0z );
3121 for ( int i = 0; i < nbSplit; ++i ) {
3122 double f = ( isForward ? params[ i ] : params[ nbSplit - i-1 ]);
3123 double l = ( isForward ? params[ i+1 ] : params[ nbSplit - i ]);
3124 TSideFace* comp = new TSideFace( *mesh, wallFaceIds[ iSide ],
3125 thePrism.myWallQuads[ iE ], *botE,
3126 &myParam2ColumnMaps[ iE ], f, l );
3127 mySide->SetComponent( iSide++, comp );
3130 else if ( nbExraFaces > 1 ) // unite
3132 double u0 = 0, sumLen = 0;
3133 for ( int i = iE; i < iE + nbExraFaces; ++i )
3134 sumLen += edgeLength[ i ];
3136 vector< TSideFace* > components( nbExraFaces );
3137 vector< pair< double, double> > params( nbExraFaces );
3138 bool endReached = false;
3139 for ( int i = 0; i < nbExraFaces; ++i, ++botE, ++iE )
3141 if ( iE == nbEdges )
3144 botE = thePrism.myBottomEdges.begin();
3147 components[ i ] = new TSideFace( *mesh, wallFaceIds[ iSide ],
3148 thePrism.myWallQuads[ iE ], *botE,
3149 &myParam2ColumnMaps[ iE ]);
3150 double u1 = u0 + edgeLength[ iE ] / sumLen;
3151 params[ i ] = make_pair( u0 , u1 );
3154 TSideFace* comp = new TSideFace( *mesh, components, params );
3155 mySide->SetComponent( iSide++, comp );
3158 --iE; // for increment in an external loop on iE
3161 else if ( nbExraFaces < 0 ) // skip already united face
3166 TSideFace* comp = new TSideFace( *mesh, wallFaceIds[ iSide ],
3167 thePrism.myWallQuads[ iE ], *botE,
3168 &myParam2ColumnMaps[ iE ]);
3169 mySide->SetComponent( iSide++, comp );
3174 // Fill geometry fields of SMESH_Block
3175 // ------------------------------------
3177 vector< int > botEdgeIdVec;
3178 SMESH_Block::GetFaceEdgesIDs( ID_BOT_FACE, botEdgeIdVec );
3180 bool isForward[NB_WALL_FACES] = { true, true, true, true };
3181 Adaptor2d_Curve2d* botPcurves[NB_WALL_FACES];
3182 Adaptor2d_Curve2d* topPcurves[NB_WALL_FACES];
3184 for ( int iF = 0; iF < NB_WALL_FACES; ++iF )
3186 TSideFace * sideFace = mySide->GetComponent( iF );
3188 RETURN_BAD_RESULT("NULL TSideFace");
3189 int fID = sideFace->FaceID(); // in-block ID
3191 // fill myShapeIDMap
3192 if ( sideFace->InsertSubShapes( myShapeIDMap ) != 8 &&
3193 !sideFace->IsComplex())
3194 MESSAGE( ": Warning : InsertSubShapes() < 8 on side " << iF );
3196 // side faces geometry
3197 Adaptor2d_Curve2d* pcurves[NB_WALL_FACES];
3198 if ( !sideFace->GetPCurves( pcurves ))
3199 RETURN_BAD_RESULT("TSideFace::GetPCurves() failed");
3201 SMESH_Block::TFace& tFace = myFace[ fID - ID_FirstF ];
3202 tFace.Set( fID, sideFace->Surface(), pcurves, isForward );
3204 SHOWYXZ( endl<<"F "<< iF << " id " << fID << " FRW " << sideFace->IsForward(), sideFace->Value(0,0));
3205 // edges 3D geometry
3206 vector< int > edgeIdVec;
3207 SMESH_Block::GetFaceEdgesIDs( fID, edgeIdVec );
3208 for ( int isMax = 0; isMax < 2; ++isMax ) {
3210 int eID = edgeIdVec[ isMax ];
3211 SMESH_Block::TEdge& tEdge = myEdge[ eID - ID_FirstE ];
3212 tEdge.Set( eID, sideFace->HorizCurve(isMax), true);
3213 SHOWYXZ(eID<<" HOR"<<isMax<<"(0)", sideFace->HorizCurve(isMax)->Value(0));
3214 SHOWYXZ(eID<<" HOR"<<isMax<<"(1)", sideFace->HorizCurve(isMax)->Value(1));
3217 int eID = edgeIdVec[ isMax+2 ];
3218 SMESH_Block::TEdge& tEdge = myEdge[ eID - ID_FirstE ];
3219 tEdge.Set( eID, sideFace->VertiCurve(isMax), true);
3220 SHOWYXZ(eID<<" VER"<<isMax<<"(0)", sideFace->VertiCurve(isMax)->Value(0));
3221 SHOWYXZ(eID<<" VER"<<isMax<<"(1)", sideFace->VertiCurve(isMax)->Value(1));
3224 vector< int > vertexIdVec;
3225 SMESH_Block::GetEdgeVertexIDs( eID, vertexIdVec );
3226 myPnt[ vertexIdVec[0] - ID_FirstV ] = tEdge.GetCurve()->Value(0).XYZ();
3227 myPnt[ vertexIdVec[1] - ID_FirstV ] = tEdge.GetCurve()->Value(1).XYZ();
3230 // pcurves on horizontal faces
3231 for ( iE = 0; iE < NB_WALL_FACES; ++iE ) {
3232 if ( edgeIdVec[ BOTTOM_EDGE ] == botEdgeIdVec[ iE ] ) {
3233 botPcurves[ iE ] = sideFace->HorizPCurve( false, thePrism.myBottom );
3234 topPcurves[ iE ] = sideFace->HorizPCurve( true, thePrism.myTop );
3238 //sideFace->dumpNodes( 4 ); // debug
3240 // horizontal faces geometry
3242 SMESH_Block::TFace& tFace = myFace[ ID_BOT_FACE - ID_FirstF ];
3243 tFace.Set( ID_BOT_FACE, new BRepAdaptor_Surface( thePrism.myBottom ), botPcurves, isForward );
3244 SMESH_Block::Insert( thePrism.myBottom, ID_BOT_FACE, myShapeIDMap );
3247 SMESH_Block::TFace& tFace = myFace[ ID_TOP_FACE - ID_FirstF ];
3248 tFace.Set( ID_TOP_FACE, new BRepAdaptor_Surface( thePrism.myTop ), topPcurves, isForward );
3249 SMESH_Block::Insert( thePrism.myTop, ID_TOP_FACE, myShapeIDMap );
3251 //faceGridToPythonDump( SMESH_Block::ID_Fxy0, 50 );
3252 //faceGridToPythonDump( SMESH_Block::ID_Fxy1 );
3254 // Fill map ShapeIndex to TParam2ColumnMap
3255 // ----------------------------------------
3257 list< TSideFace* > fList;
3258 list< TSideFace* >::iterator fListIt;
3259 fList.push_back( mySide );
3260 for ( fListIt = fList.begin(); fListIt != fList.end(); ++fListIt)
3262 int nb = (*fListIt)->NbComponents();
3263 for ( int i = 0; i < nb; ++i ) {
3264 if ( TSideFace* comp = (*fListIt)->GetComponent( i ))
3265 fList.push_back( comp );
3267 if ( TParam2ColumnMap* cols = (*fListIt)->GetColumns()) {
3268 // columns for a base edge
3269 int id = MeshDS()->ShapeToIndex( (*fListIt)->BaseEdge() );
3270 bool isForward = (*fListIt)->IsForward();
3271 myShapeIndex2ColumnMap[ id ] = make_pair( cols, isForward );
3273 // columns for vertices
3274 const SMDS_MeshNode* n0 = cols->begin()->second.front();
3275 id = n0->getshapeId();
3276 myShapeIndex2ColumnMap[ id ] = make_pair( cols, isForward );
3278 const SMDS_MeshNode* n1 = cols->rbegin()->second.front();
3279 id = n1->getshapeId();
3280 myShapeIndex2ColumnMap[ id ] = make_pair( cols, !isForward );
3284 // #define SHOWYXZ(msg, xyz) { \
3285 // gp_Pnt p (xyz); \
3286 // cout << msg << " ("<< p.X() << "; " <<p.Y() << "; " <<p.Z() << ") " <<endl; \
3288 // double _u[]={ 0.1, 0.1, 0.9, 0.9 };
3289 // double _v[]={ 0.1, 0.9, 0.1, 0.9 };
3290 // for ( int z = 0; z < 2; ++z )
3291 // for ( int i = 0; i < 4; ++i )
3293 // //gp_XYZ testPar(0.25, 0.25, 0), testCoord;
3294 // int iFace = (z ? ID_TOP_FACE : ID_BOT_FACE);
3295 // gp_XYZ testPar(_u[i], _v[i], z), testCoord;
3296 // if ( !FacePoint( iFace, testPar, testCoord ))
3297 // RETURN_BAD_RESULT("TEST FacePoint() FAILED");
3298 // SHOWYXZ("IN TEST PARAM" , testPar);
3299 // SHOWYXZ("OUT TEST CORD" , testCoord);
3300 // if ( !ComputeParameters( testCoord, testPar , iFace))
3301 // RETURN_BAD_RESULT("TEST ComputeParameters() FAILED");
3302 // SHOWYXZ("OUT TEST PARAM" , testPar);
3307 //================================================================================
3309 * \brief Return pointer to column of nodes
3310 * \param node - bottom node from which the returned column goes up
3311 * \retval const TNodeColumn* - the found column
3313 //================================================================================
3315 const TNodeColumn* StdMeshers_PrismAsBlock::GetNodeColumn(const SMDS_MeshNode* node) const
3317 int sID = node->getshapeId();
3319 map<int, pair< TParam2ColumnMap*, bool > >::const_iterator col_frw =
3320 myShapeIndex2ColumnMap.find( sID );
3321 if ( col_frw != myShapeIndex2ColumnMap.end() ) {
3322 const TParam2ColumnMap* cols = col_frw->second.first;
3323 TParam2ColumnIt u_col = cols->begin();
3324 for ( ; u_col != cols->end(); ++u_col )
3325 if ( u_col->second[ 0 ] == node )
3326 return & u_col->second;
3331 //=======================================================================
3332 //function : GetLayersTransformation
3333 //purpose : Return transformations to get coordinates of nodes of each layer
3334 // by nodes of the bottom. Layer is a set of nodes at a certain step
3335 // from bottom to top.
3336 // Transformation to get top node from bottom ones is computed
3337 // only if the top FACE is not meshed.
3338 //=======================================================================
3340 bool StdMeshers_PrismAsBlock::GetLayersTransformation(vector<gp_Trsf> & trsf,
3341 const Prism_3D::TPrismTopo& prism) const
3343 const bool itTopMeshed = !SubMesh( ID_BOT_FACE )->IsEmpty();
3344 const int zSize = VerticalSize();
3345 if ( zSize < 3 && !itTopMeshed ) return true;
3346 trsf.resize( zSize - 1 );
3348 // Select some node columns by which we will define coordinate system of layers
3350 vector< const TNodeColumn* > columns;
3353 list< TopoDS_Edge >::const_iterator edgeIt = prism.myBottomEdges.begin();
3354 for ( int iE = 0; iE < prism.myNbEdgesInWires.front(); ++iE, ++edgeIt )
3356 if ( SMESH_Algo::isDegenerated( *edgeIt )) continue;
3357 const TParam2ColumnMap* u2colMap =
3358 GetParam2ColumnMap( MeshDS()->ShapeToIndex( *edgeIt ), isReverse );
3359 if ( !u2colMap ) return false;
3360 double f = u2colMap->begin()->first, l = u2colMap->rbegin()->first;
3361 //isReverse = ( edgeIt->Orientation() == TopAbs_REVERSED );
3362 //if ( isReverse ) swap ( f, l ); -- u2colMap takes orientation into account
3363 const int nbCol = 5;
3364 for ( int i = 0; i < nbCol; ++i )
3366 double u = f + i/double(nbCol) * ( l - f );
3367 const TNodeColumn* col = & getColumn( u2colMap, u )->second;
3368 if ( columns.empty() || col != columns.back() )
3369 columns.push_back( col );
3374 // Find tolerance to check transformations
3379 for ( int i = 0; i < columns.size(); ++i )
3380 bndBox.Add( gpXYZ( columns[i]->front() ));
3381 tol2 = bndBox.SquareExtent() * 1e-5;
3384 // Compute transformations
3387 gp_Trsf fromCsZ, toCs0;
3388 gp_Ax3 cs0 = getLayerCoordSys(0, columns, xCol );
3389 //double dist0 = cs0.Location().Distance( gpXYZ( (*columns[0])[0]));
3390 toCs0.SetTransformation( cs0 );
3391 for ( int z = 1; z < zSize; ++z )
3393 gp_Ax3 csZ = getLayerCoordSys(z, columns, xCol );
3394 //double distZ = csZ.Location().Distance( gpXYZ( (*columns[0])[z]));
3395 fromCsZ.SetTransformation( csZ );
3397 gp_Trsf& t = trsf[ z-1 ];
3398 t = fromCsZ * toCs0;
3399 //t.SetScaleFactor( distZ/dist0 ); - it does not work properly, wrong base point
3401 // check a transformation
3402 for ( int i = 0; i < columns.size(); ++i )
3404 gp_Pnt p0 = gpXYZ( (*columns[i])[0] );
3405 gp_Pnt pz = gpXYZ( (*columns[i])[z] );
3406 t.Transforms( p0.ChangeCoord() );
3407 if ( p0.SquareDistance( pz ) > tol2 )
3410 return ( z == zSize - 1 ); // OK if fails only botton->top trsf
3417 //================================================================================
3419 * \brief Check curve orientation of a bootom edge
3420 * \param meshDS - mesh DS
3421 * \param columnsMap - node columns map of side face
3422 * \param bottomEdge - the bootom edge
3423 * \param sideFaceID - side face in-block ID
3424 * \retval bool - true if orientation coinside with in-block forward orientation
3426 //================================================================================
3428 bool StdMeshers_PrismAsBlock::IsForwardEdge(SMESHDS_Mesh* meshDS,
3429 const TParam2ColumnMap& columnsMap,
3430 const TopoDS_Edge & bottomEdge,
3431 const int sideFaceID)
3433 bool isForward = false;
3434 if ( SMESH_MesherHelper::IsClosedEdge( bottomEdge ))
3436 isForward = ( bottomEdge.Orientation() == TopAbs_FORWARD );
3440 const TNodeColumn& firstCol = columnsMap.begin()->second;
3441 const SMDS_MeshNode* bottomNode = firstCol[0];
3442 TopoDS_Shape firstVertex = SMESH_MesherHelper::GetSubShapeByNode( bottomNode, meshDS );
3443 isForward = ( firstVertex.IsSame( TopExp::FirstVertex( bottomEdge, true )));
3445 // on 2 of 4 sides first vertex is end
3446 if ( sideFaceID == ID_Fx1z || sideFaceID == ID_F0yz )
3447 isForward = !isForward;
3451 //=======================================================================
3452 //function : faceGridToPythonDump
3453 //purpose : Prints a script creating a normal grid on the prism side
3454 //=======================================================================
3456 void StdMeshers_PrismAsBlock::faceGridToPythonDump(const SMESH_Block::TShapeID face,
3460 gp_XYZ pOnF[6] = { gp_XYZ(0,0,0), gp_XYZ(0,0,1),
3461 gp_XYZ(0,0,0), gp_XYZ(0,1,0),
3462 gp_XYZ(0,0,0), gp_XYZ(1,0,0) };
3464 cout << "mesh = smesh.Mesh( 'Face " << face << "')" << endl;
3465 SMESH_Block::TFace& f = myFace[ face - ID_FirstF ];
3466 gp_XYZ params = pOnF[ face - ID_FirstF ];
3467 //const int nb = 10; // nb face rows
3468 for ( int j = 0; j <= nb; ++j )
3470 params.SetCoord( f.GetVInd(), double( j )/ nb );
3471 for ( int i = 0; i <= nb; ++i )
3473 params.SetCoord( f.GetUInd(), double( i )/ nb );
3474 gp_XYZ p = f.Point( params );
3475 gp_XY uv = f.GetUV( params );
3476 cout << "mesh.AddNode( " << p.X() << ", " << p.Y() << ", " << p.Z() << " )"
3477 << " # " << 1 + i + j * ( nb + 1 )
3478 << " ( " << i << ", " << j << " ) "
3479 << " UV( " << uv.X() << ", " << uv.Y() << " )" << endl;
3480 ShellPoint( params, p2 );
3481 double dist = ( p2 - p ).Modulus();
3483 cout << "#### dist from ShellPoint " << dist
3484 << " (" << p2.X() << ", " << p2.Y() << ", " << p2.Z() << " ) " << endl;
3487 for ( int j = 0; j < nb; ++j )
3488 for ( int i = 0; i < nb; ++i )
3490 int n = 1 + i + j * ( nb + 1 );
3491 cout << "mesh.AddFace([ "
3492 << n << ", " << n+1 << ", "
3493 << n+nb+2 << ", " << n+nb+1 << "]) " << endl;
3499 //================================================================================
3501 * \brief Constructor
3502 * \param faceID - in-block ID
3503 * \param face - geom FACE
3504 * \param baseEdge - EDGE proreply oriented in the bottom EDGE !!!
3505 * \param columnsMap - map of node columns
3506 * \param first - first normalized param
3507 * \param last - last normalized param
3509 //================================================================================
3511 StdMeshers_PrismAsBlock::TSideFace::TSideFace(SMESH_Mesh& mesh,
3513 const Prism_3D::TQuadList& quadList,
3514 const TopoDS_Edge& baseEdge,
3515 TParam2ColumnMap* columnsMap,
3519 myParamToColumnMap( columnsMap ),
3522 myParams.resize( 1 );
3523 myParams[ 0 ] = make_pair( first, last );
3524 mySurface = PSurface( new BRepAdaptor_Surface( quadList.front()->face ));
3525 myBaseEdge = baseEdge;
3526 myIsForward = StdMeshers_PrismAsBlock::IsForwardEdge( myHelper.GetMeshDS(),
3527 *myParamToColumnMap,
3529 myHelper.SetSubShape( quadList.front()->face );
3531 if ( quadList.size() > 1 ) // side is vertically composite
3533 // fill myShapeID2Surf map to enable finding a right surface by any sub-shape ID
3535 SMESHDS_Mesh* meshDS = myHelper.GetMeshDS();
3537 TopTools_IndexedDataMapOfShapeListOfShape subToFaces;
3538 Prism_3D::TQuadList::const_iterator quad = quadList.begin();
3539 for ( ; quad != quadList.end(); ++quad )
3541 const TopoDS_Face& face = (*quad)->face;
3542 TopExp::MapShapesAndAncestors( face, TopAbs_VERTEX, TopAbs_FACE, subToFaces );
3543 TopExp::MapShapesAndAncestors( face, TopAbs_EDGE, TopAbs_FACE, subToFaces );
3544 myShapeID2Surf.insert( make_pair( meshDS->ShapeToIndex( face ),
3545 PSurface( new BRepAdaptor_Surface( face ))));
3547 for ( int i = 1; i <= subToFaces.Extent(); ++i )
3549 const TopoDS_Shape& sub = subToFaces.FindKey( i );
3550 TopTools_ListOfShape& faces = subToFaces( i );
3551 int subID = meshDS->ShapeToIndex( sub );
3552 int faceID = meshDS->ShapeToIndex( faces.First() );
3553 myShapeID2Surf.insert ( make_pair( subID, myShapeID2Surf[ faceID ]));
3558 //================================================================================
3560 * \brief Constructor of a complex side face
3562 //================================================================================
3564 StdMeshers_PrismAsBlock::TSideFace::
3565 TSideFace(SMESH_Mesh& mesh,
3566 const vector< TSideFace* >& components,
3567 const vector< pair< double, double> > & params)
3568 :myID( components[0] ? components[0]->myID : 0 ),
3569 myParamToColumnMap( 0 ),
3571 myIsForward( true ),
3572 myComponents( components ),
3575 if ( myID == ID_Fx1z || myID == ID_F0yz )
3577 // reverse components
3578 std::reverse( myComponents.begin(), myComponents.end() );
3579 std::reverse( myParams.begin(), myParams.end() );
3580 for ( size_t i = 0; i < myParams.size(); ++i )
3582 const double f = myParams[i].first;
3583 const double l = myParams[i].second;
3584 myParams[i] = make_pair( 1. - l, 1. - f );
3588 //================================================================================
3590 * \brief Copy constructor
3591 * \param other - other side
3593 //================================================================================
3595 StdMeshers_PrismAsBlock::TSideFace::TSideFace( const TSideFace& other ):
3596 myID ( other.myID ),
3597 myParamToColumnMap ( other.myParamToColumnMap ),
3598 mySurface ( other.mySurface ),
3599 myBaseEdge ( other.myBaseEdge ),
3600 myShapeID2Surf ( other.myShapeID2Surf ),
3601 myParams ( other.myParams ),
3602 myIsForward ( other.myIsForward ),
3603 myComponents ( other.myComponents.size() ),
3604 myHelper ( *other.myHelper.GetMesh() )
3606 for (int i = 0 ; i < myComponents.size(); ++i )
3607 myComponents[ i ] = new TSideFace( *other.myComponents[ i ]);
3610 //================================================================================
3612 * \brief Deletes myComponents
3614 //================================================================================
3616 StdMeshers_PrismAsBlock::TSideFace::~TSideFace()
3618 for (int i = 0 ; i < myComponents.size(); ++i )
3619 if ( myComponents[ i ] )
3620 delete myComponents[ i ];
3623 //================================================================================
3625 * \brief Return geometry of the vertical curve
3626 * \param isMax - true means curve located closer to (1,1,1) block point
3627 * \retval Adaptor3d_Curve* - curve adaptor
3629 //================================================================================
3631 Adaptor3d_Curve* StdMeshers_PrismAsBlock::TSideFace::VertiCurve(const bool isMax) const
3633 if ( !myComponents.empty() ) {
3635 return myComponents.back()->VertiCurve(isMax);
3637 return myComponents.front()->VertiCurve(isMax);
3639 double f = myParams[0].first, l = myParams[0].second;
3640 if ( !myIsForward ) std::swap( f, l );
3641 return new TVerticalEdgeAdaptor( myParamToColumnMap, isMax ? l : f );
3644 //================================================================================
3646 * \brief Return geometry of the top or bottom curve
3648 * \retval Adaptor3d_Curve* -
3650 //================================================================================
3652 Adaptor3d_Curve* StdMeshers_PrismAsBlock::TSideFace::HorizCurve(const bool isTop) const
3654 return new THorizontalEdgeAdaptor( this, isTop );
3657 //================================================================================
3659 * \brief Return pcurves
3660 * \param pcurv - array of 4 pcurves
3661 * \retval bool - is a success
3663 //================================================================================
3665 bool StdMeshers_PrismAsBlock::TSideFace::GetPCurves(Adaptor2d_Curve2d* pcurv[4]) const
3667 int iEdge[ 4 ] = { BOTTOM_EDGE, TOP_EDGE, V0_EDGE, V1_EDGE };
3669 for ( int i = 0 ; i < 4 ; ++i ) {
3670 Handle(Geom2d_Line) line;
3671 switch ( iEdge[ i ] ) {
3673 line = new Geom2d_Line( gp_Pnt2d( 0, 1 ), gp::DX2d() ); break;
3675 line = new Geom2d_Line( gp::Origin2d(), gp::DX2d() ); break;
3677 line = new Geom2d_Line( gp::Origin2d(), gp::DY2d() ); break;
3679 line = new Geom2d_Line( gp_Pnt2d( 1, 0 ), gp::DY2d() ); break;
3681 pcurv[ i ] = new Geom2dAdaptor_Curve( line, 0, 1 );
3686 //================================================================================
3688 * \brief Returns geometry of pcurve on a horizontal face
3689 * \param isTop - is top or bottom face
3690 * \param horFace - a horizontal face
3691 * \retval Adaptor2d_Curve2d* - curve adaptor
3693 //================================================================================
3696 StdMeshers_PrismAsBlock::TSideFace::HorizPCurve(const bool isTop,
3697 const TopoDS_Face& horFace) const
3699 return new TPCurveOnHorFaceAdaptor( this, isTop, horFace );
3702 //================================================================================
3704 * \brief Return a component corresponding to parameter
3705 * \param U - parameter along a horizontal size
3706 * \param localU - parameter along a horizontal size of a component
3707 * \retval TSideFace* - found component
3709 //================================================================================
3711 StdMeshers_PrismAsBlock::TSideFace*
3712 StdMeshers_PrismAsBlock::TSideFace::GetComponent(const double U,double & localU) const
3715 if ( myComponents.empty() )
3716 return const_cast<TSideFace*>( this );
3719 for ( i = 0; i < myComponents.size(); ++i )
3720 if ( U < myParams[ i ].second )
3722 if ( i >= myComponents.size() )
3723 i = myComponents.size() - 1;
3725 double f = myParams[ i ].first, l = myParams[ i ].second;
3726 localU = ( U - f ) / ( l - f );
3727 return myComponents[ i ];
3730 //================================================================================
3732 * \brief Find node columns for a parameter
3733 * \param U - parameter along a horizontal edge
3734 * \param col1 - the 1st found column
3735 * \param col2 - the 2nd found column
3736 * \retval r - normalized position of U between the found columns
3738 //================================================================================
3740 double StdMeshers_PrismAsBlock::TSideFace::GetColumns(const double U,
3741 TParam2ColumnIt & col1,
3742 TParam2ColumnIt & col2) const
3744 double u = U, r = 0;
3745 if ( !myComponents.empty() ) {
3746 TSideFace * comp = GetComponent(U,u);
3747 return comp->GetColumns( u, col1, col2 );
3752 double f = myParams[0].first, l = myParams[0].second;
3753 u = f + u * ( l - f );
3755 col1 = col2 = getColumn( myParamToColumnMap, u );
3756 if ( ++col2 == myParamToColumnMap->end() ) {
3761 double uf = col1->first;
3762 double ul = col2->first;
3763 r = ( u - uf ) / ( ul - uf );
3768 //================================================================================
3770 * \brief Return all nodes at a given height together with their normalized parameters
3771 * \param [in] Z - the height of interest
3772 * \param [out] nodes - map of parameter to node
3774 //================================================================================
3776 void StdMeshers_PrismAsBlock::
3777 TSideFace::GetNodesAtZ(const int Z,
3778 map<double, const SMDS_MeshNode* >& nodes ) const
3780 if ( !myComponents.empty() )
3783 for ( size_t i = 0; i < myComponents.size(); ++i )
3785 map<double, const SMDS_MeshNode* > nn;
3786 myComponents[i]->GetNodesAtZ( Z, nn );
3787 map<double, const SMDS_MeshNode* >::iterator u2n = nn.begin();
3788 if ( !nodes.empty() && nodes.rbegin()->second == u2n->second )
3790 const double uRange = myParams[i].second - myParams[i].first;
3791 for ( ; u2n != nn.end(); ++u2n )
3792 nodes.insert( nodes.end(), make_pair( u0 + uRange * u2n->first, u2n->second ));
3798 double f = myParams[0].first, l = myParams[0].second;
3801 const double uRange = l - f;
3802 if ( Abs( uRange ) < std::numeric_limits<double>::min() )
3804 TParam2ColumnIt u2col = getColumn( myParamToColumnMap, myParams[0].first + 1e-3 );
3805 for ( ; u2col != myParamToColumnMap->end(); ++u2col )
3806 if ( u2col->first > myParams[0].second + 1e-9 )
3809 nodes.insert( nodes.end(),
3810 make_pair( ( u2col->first - f ) / uRange, u2col->second[ Z ] ));
3814 //================================================================================
3816 * \brief Return coordinates by normalized params
3817 * \param U - horizontal param
3818 * \param V - vertical param
3819 * \retval gp_Pnt - result point
3821 //================================================================================
3823 gp_Pnt StdMeshers_PrismAsBlock::TSideFace::Value(const Standard_Real U,
3824 const Standard_Real V) const
3826 if ( !myComponents.empty() ) {
3828 TSideFace * comp = GetComponent(U,u);
3829 return comp->Value( u, V );
3832 TParam2ColumnIt u_col1, u_col2;
3833 double vR, hR = GetColumns( U, u_col1, u_col2 );
3835 const SMDS_MeshNode* nn[4];
3837 // BEGIN issue 0020680: Bad cell created by Radial prism in center of torus
3838 // Workaround for a wrongly located point returned by mySurface.Value() for
3839 // UV located near boundary of BSpline surface.
3840 // To bypass the problem, we take point from 3D curve of EDGE.
3841 // It solves pb of the bloc_fiss_new.py
3842 const double tol = 1e-3;
3843 if ( V < tol || V+tol >= 1. )
3845 nn[0] = V < tol ? u_col1->second.front() : u_col1->second.back();
3846 nn[2] = V < tol ? u_col2->second.front() : u_col2->second.back();
3854 TopoDS_Shape s = myHelper.GetSubShapeByNode( nn[0], myHelper.GetMeshDS() );
3855 if ( s.ShapeType() != TopAbs_EDGE )
3856 s = myHelper.GetSubShapeByNode( nn[2], myHelper.GetMeshDS() );
3857 if ( s.ShapeType() == TopAbs_EDGE )
3858 edge = TopoDS::Edge( s );
3860 if ( !edge.IsNull() )
3862 double u1 = myHelper.GetNodeU( edge, nn[0], nn[2] );
3863 double u3 = myHelper.GetNodeU( edge, nn[2], nn[0] );
3864 double u = u1 * ( 1 - hR ) + u3 * hR;
3865 TopLoc_Location loc; double f,l;
3866 Handle(Geom_Curve) curve = BRep_Tool::Curve( edge,loc,f,l );
3867 return curve->Value( u ).Transformed( loc );
3870 // END issue 0020680: Bad cell created by Radial prism in center of torus
3872 vR = getRAndNodes( & u_col1->second, V, nn[0], nn[1] );
3873 vR = getRAndNodes( & u_col2->second, V, nn[2], nn[3] );
3875 if ( !myShapeID2Surf.empty() ) // side is vertically composite
3877 // find a FACE on which the 4 nodes lie
3878 TSideFace* me = (TSideFace*) this;
3879 int notFaceID1 = 0, notFaceID2 = 0;
3880 for ( int i = 0; i < 4; ++i )
3881 if ( nn[i]->GetPosition()->GetTypeOfPosition() == SMDS_TOP_FACE ) // node on FACE
3883 me->mySurface = me->myShapeID2Surf[ nn[i]->getshapeId() ];
3887 else if ( notFaceID1 == 0 ) // node on EDGE or VERTEX
3889 me->mySurface = me->myShapeID2Surf[ nn[i]->getshapeId() ];
3890 notFaceID1 = nn[i]->getshapeId();
3892 else if ( notFaceID1 != nn[i]->getshapeId() ) // node on other EDGE or VERTEX
3894 if ( mySurface != me->myShapeID2Surf[ nn[i]->getshapeId() ])
3895 notFaceID2 = nn[i]->getshapeId();
3897 if ( notFaceID2 ) // no nodes of FACE and nodes are on different FACEs
3899 SMESHDS_Mesh* meshDS = myHelper.GetMeshDS();
3900 TopoDS_Shape face = myHelper.GetCommonAncestor( meshDS->IndexToShape( notFaceID1 ),
3901 meshDS->IndexToShape( notFaceID2 ),
3902 *myHelper.GetMesh(),
3904 if ( face.IsNull() )
3905 throw SALOME_Exception("StdMeshers_PrismAsBlock::TSideFace::Value() face.IsNull()");
3906 int faceID = meshDS->ShapeToIndex( face );
3907 me->mySurface = me->myShapeID2Surf[ faceID ];
3909 throw SALOME_Exception("StdMeshers_PrismAsBlock::TSideFace::Value() !mySurface");
3912 ((TSideFace*) this)->myHelper.SetSubShape( mySurface->Face() );
3914 gp_XY uv1 = myHelper.GetNodeUV( mySurface->Face(), nn[0], nn[2]);
3915 gp_XY uv2 = myHelper.GetNodeUV( mySurface->Face(), nn[1], nn[3]);
3916 gp_XY uv12 = uv1 * ( 1 - vR ) + uv2 * vR;
3918 gp_XY uv3 = myHelper.GetNodeUV( mySurface->Face(), nn[2], nn[0]);
3919 gp_XY uv4 = myHelper.GetNodeUV( mySurface->Face(), nn[3], nn[1]);
3920 gp_XY uv34 = uv3 * ( 1 - vR ) + uv4 * vR;
3922 gp_XY uv = uv12 * ( 1 - hR ) + uv34 * hR;
3924 gp_Pnt p = mySurface->Value( uv.X(), uv.Y() );
3929 //================================================================================
3931 * \brief Return boundary edge
3932 * \param edge - edge index
3933 * \retval TopoDS_Edge - found edge
3935 //================================================================================
3937 TopoDS_Edge StdMeshers_PrismAsBlock::TSideFace::GetEdge(const int iEdge) const
3939 if ( !myComponents.empty() ) {
3941 case V0_EDGE : return myComponents.front()->GetEdge( iEdge );
3942 case V1_EDGE : return myComponents.back() ->GetEdge( iEdge );
3943 default: return TopoDS_Edge();
3947 const SMDS_MeshNode* node = 0;
3948 SMESHDS_Mesh * meshDS = myHelper.GetMesh()->GetMeshDS();
3949 TNodeColumn* column;
3954 column = & (( ++myParamToColumnMap->begin())->second );
3955 node = ( iEdge == TOP_EDGE ) ? column->back() : column->front();
3956 edge = myHelper.GetSubShapeByNode ( node, meshDS );
3957 if ( edge.ShapeType() == TopAbs_VERTEX ) {
3958 column = & ( myParamToColumnMap->begin()->second );
3959 node = ( iEdge == TOP_EDGE ) ? column->back() : column->front();
3964 bool back = ( iEdge == V1_EDGE );
3965 if ( !myIsForward ) back = !back;
3967 column = & ( myParamToColumnMap->rbegin()->second );
3969 column = & ( myParamToColumnMap->begin()->second );
3970 if ( column->size() > 0 )
3971 edge = myHelper.GetSubShapeByNode( (*column)[ 1 ], meshDS );
3972 if ( edge.IsNull() || edge.ShapeType() == TopAbs_VERTEX )
3973 node = column->front();
3978 if ( !edge.IsNull() && edge.ShapeType() == TopAbs_EDGE )
3979 return TopoDS::Edge( edge );
3981 // find edge by 2 vertices
3982 TopoDS_Shape V1 = edge;
3983 TopoDS_Shape V2 = myHelper.GetSubShapeByNode( node, meshDS );
3984 if ( !V2.IsNull() && V2.ShapeType() == TopAbs_VERTEX && !V2.IsSame( V1 ))
3986 TopoDS_Shape ancestor = myHelper.GetCommonAncestor( V1, V2, *myHelper.GetMesh(), TopAbs_EDGE);
3987 if ( !ancestor.IsNull() )
3988 return TopoDS::Edge( ancestor );
3990 return TopoDS_Edge();
3993 //================================================================================
3995 * \brief Fill block sub-shapes
3996 * \param shapeMap - map to fill in
3997 * \retval int - nb inserted sub-shapes
3999 //================================================================================
4001 int StdMeshers_PrismAsBlock::TSideFace::InsertSubShapes(TBlockShapes& shapeMap) const
4006 vector< int > edgeIdVec;
4007 SMESH_Block::GetFaceEdgesIDs( myID, edgeIdVec );
4009 for ( int i = BOTTOM_EDGE; i <=V1_EDGE ; ++i ) {
4010 TopoDS_Edge e = GetEdge( i );
4011 if ( !e.IsNull() ) {
4012 nbInserted += SMESH_Block::Insert( e, edgeIdVec[ i ], shapeMap);
4016 // Insert corner vertices
4018 TParam2ColumnIt col1, col2 ;
4019 vector< int > vertIdVec;
4022 SMESH_Block::GetEdgeVertexIDs( edgeIdVec[ V0_EDGE ], vertIdVec);
4023 GetColumns(0, col1, col2 );
4024 const SMDS_MeshNode* node0 = col1->second.front();
4025 const SMDS_MeshNode* node1 = col1->second.back();
4026 TopoDS_Shape v0 = myHelper.GetSubShapeByNode( node0, myHelper.GetMeshDS());
4027 TopoDS_Shape v1 = myHelper.GetSubShapeByNode( node1, myHelper.GetMeshDS());
4028 if ( v0.ShapeType() == TopAbs_VERTEX ) {
4029 nbInserted += SMESH_Block::Insert( v0, vertIdVec[ 0 ], shapeMap);
4031 if ( v1.ShapeType() == TopAbs_VERTEX ) {
4032 nbInserted += SMESH_Block::Insert( v1, vertIdVec[ 1 ], shapeMap);
4036 SMESH_Block::GetEdgeVertexIDs( edgeIdVec[ V1_EDGE ], vertIdVec);
4037 GetColumns(1, col1, col2 );
4038 node0 = col2->second.front();
4039 node1 = col2->second.back();
4040 v0 = myHelper.GetSubShapeByNode( node0, myHelper.GetMeshDS());
4041 v1 = myHelper.GetSubShapeByNode( node1, myHelper.GetMeshDS());
4042 if ( v0.ShapeType() == TopAbs_VERTEX ) {
4043 nbInserted += SMESH_Block::Insert( v0, vertIdVec[ 0 ], shapeMap);
4045 if ( v1.ShapeType() == TopAbs_VERTEX ) {
4046 nbInserted += SMESH_Block::Insert( v1, vertIdVec[ 1 ], shapeMap);
4049 // TopoDS_Vertex V0, V1, Vcom;
4050 // TopExp::Vertices( myBaseEdge, V0, V1, true );
4051 // if ( !myIsForward ) std::swap( V0, V1 );
4053 // // bottom vertex IDs
4054 // SMESH_Block::GetEdgeVertexIDs( edgeIdVec[ _u0 ], vertIdVec);
4055 // SMESH_Block::Insert( V0, vertIdVec[ 0 ], shapeMap);
4056 // SMESH_Block::Insert( V1, vertIdVec[ 1 ], shapeMap);
4058 // TopoDS_Edge sideEdge = GetEdge( V0_EDGE );
4059 // if ( sideEdge.IsNull() || !TopExp::CommonVertex( botEdge, sideEdge, Vcom ))
4062 // // insert one side edge
4064 // if ( Vcom.IsSame( V0 )) edgeID = edgeIdVec[ _v0 ];
4065 // else edgeID = edgeIdVec[ _v1 ];
4066 // SMESH_Block::Insert( sideEdge, edgeID, shapeMap);
4068 // // top vertex of the side edge
4069 // SMESH_Block::GetEdgeVertexIDs( edgeID, vertIdVec);
4070 // TopoDS_Vertex Vtop = TopExp::FirstVertex( sideEdge );
4071 // if ( Vcom.IsSame( Vtop ))
4072 // Vtop = TopExp::LastVertex( sideEdge );
4073 // SMESH_Block::Insert( Vtop, vertIdVec[ 1 ], shapeMap);
4075 // // other side edge
4076 // sideEdge = GetEdge( V1_EDGE );
4077 // if ( sideEdge.IsNull() )
4079 // if ( edgeID = edgeIdVec[ _v1 ]) edgeID = edgeIdVec[ _v0 ];
4080 // else edgeID = edgeIdVec[ _v1 ];
4081 // SMESH_Block::Insert( sideEdge, edgeID, shapeMap);
4084 // TopoDS_Edge topEdge = GetEdge( TOP_EDGE );
4085 // SMESH_Block::Insert( topEdge, edgeIdVec[ _u1 ], shapeMap);
4087 // // top vertex of the other side edge
4088 // if ( !TopExp::CommonVertex( topEdge, sideEdge, Vcom ))
4090 // SMESH_Block::GetEdgeVertexIDs( edgeID, vertIdVec );
4091 // SMESH_Block::Insert( Vcom, vertIdVec[ 1 ], shapeMap);
4096 //================================================================================
4098 * \brief Dump ids of nodes of sides
4100 //================================================================================
4102 void StdMeshers_PrismAsBlock::TSideFace::dumpNodes(int nbNodes) const
4105 cout << endl << "NODES OF FACE "; SMESH_Block::DumpShapeID( myID, cout ) << endl;
4106 THorizontalEdgeAdaptor* hSize0 = (THorizontalEdgeAdaptor*) HorizCurve(0);
4107 cout << "Horiz side 0: "; hSize0->dumpNodes(nbNodes); cout << endl;
4108 THorizontalEdgeAdaptor* hSize1 = (THorizontalEdgeAdaptor*) HorizCurve(1);
4109 cout << "Horiz side 1: "; hSize1->dumpNodes(nbNodes); cout << endl;
4110 TVerticalEdgeAdaptor* vSide0 = (TVerticalEdgeAdaptor*) VertiCurve(0);
4111 cout << "Verti side 0: "; vSide0->dumpNodes(nbNodes); cout << endl;
4112 TVerticalEdgeAdaptor* vSide1 = (TVerticalEdgeAdaptor*) VertiCurve(1);
4113 cout << "Verti side 1: "; vSide1->dumpNodes(nbNodes); cout << endl;
4114 delete hSize0; delete hSize1; delete vSide0; delete vSide1;
4118 //================================================================================
4120 * \brief Creates TVerticalEdgeAdaptor
4121 * \param columnsMap - node column map
4122 * \param parameter - normalized parameter
4124 //================================================================================
4126 StdMeshers_PrismAsBlock::TVerticalEdgeAdaptor::
4127 TVerticalEdgeAdaptor( const TParam2ColumnMap* columnsMap, const double parameter)
4129 myNodeColumn = & getColumn( columnsMap, parameter )->second;
4132 //================================================================================
4134 * \brief Return coordinates for the given normalized parameter
4135 * \param U - normalized parameter
4136 * \retval gp_Pnt - coordinates
4138 //================================================================================
4140 gp_Pnt StdMeshers_PrismAsBlock::TVerticalEdgeAdaptor::Value(const Standard_Real U) const
4142 const SMDS_MeshNode* n1;
4143 const SMDS_MeshNode* n2;
4144 double r = getRAndNodes( myNodeColumn, U, n1, n2 );
4145 return gpXYZ(n1) * ( 1 - r ) + gpXYZ(n2) * r;
4148 //================================================================================
4150 * \brief Dump ids of nodes
4152 //================================================================================
4154 void StdMeshers_PrismAsBlock::TVerticalEdgeAdaptor::dumpNodes(int nbNodes) const
4157 for ( int i = 0; i < nbNodes && i < myNodeColumn->size(); ++i )
4158 cout << (*myNodeColumn)[i]->GetID() << " ";
4159 if ( nbNodes < myNodeColumn->size() )
4160 cout << myNodeColumn->back()->GetID();
4164 //================================================================================
4166 * \brief Return coordinates for the given normalized parameter
4167 * \param U - normalized parameter
4168 * \retval gp_Pnt - coordinates
4170 //================================================================================
4172 gp_Pnt StdMeshers_PrismAsBlock::THorizontalEdgeAdaptor::Value(const Standard_Real U) const
4174 return mySide->TSideFace::Value( U, myV );
4177 //================================================================================
4179 * \brief Dump ids of <nbNodes> first nodes and the last one
4181 //================================================================================
4183 void StdMeshers_PrismAsBlock::THorizontalEdgeAdaptor::dumpNodes(int nbNodes) const
4186 // Not bedugged code. Last node is sometimes incorrect
4187 const TSideFace* side = mySide;
4189 if ( mySide->IsComplex() )
4190 side = mySide->GetComponent(0,u);
4192 TParam2ColumnIt col, col2;
4193 TParam2ColumnMap* u2cols = side->GetColumns();
4194 side->GetColumns( u , col, col2 );
4196 int j, i = myV ? mySide->ColumnHeight()-1 : 0;
4198 const SMDS_MeshNode* n = 0;
4199 const SMDS_MeshNode* lastN
4200 = side->IsForward() ? u2cols->rbegin()->second[ i ] : u2cols->begin()->second[ i ];
4201 for ( j = 0; j < nbNodes && n != lastN; ++j )
4203 n = col->second[ i ];
4204 cout << n->GetID() << " ";
4205 if ( side->IsForward() )
4213 if ( mySide->IsComplex() )
4214 side = mySide->GetComponent(1,u);
4216 side->GetColumns( u , col, col2 );
4217 if ( n != col->second[ i ] )
4218 cout << col->second[ i ]->GetID();
4222 //================================================================================
4224 * \brief Costructor of TPCurveOnHorFaceAdaptor fills its map of
4225 * normalized parameter to node UV on a horizontal face
4226 * \param [in] sideFace - lateral prism side
4227 * \param [in] isTop - is \a horFace top or bottom of the prism
4228 * \param [in] horFace - top or bottom face of the prism
4230 //================================================================================
4232 StdMeshers_PrismAsBlock::
4233 TPCurveOnHorFaceAdaptor::TPCurveOnHorFaceAdaptor( const TSideFace* sideFace,
4235 const TopoDS_Face& horFace)
4237 if ( sideFace && !horFace.IsNull() )
4239 //cout << "\n\t FACE " << sideFace->FaceID() << endl;
4240 const int Z = isTop ? sideFace->ColumnHeight() - 1 : 0;
4241 map<double, const SMDS_MeshNode* > u2nodes;
4242 sideFace->GetNodesAtZ( Z, u2nodes );
4243 if ( u2nodes.empty() )
4246 SMESH_MesherHelper helper( *sideFace->GetMesh() );
4247 helper.SetSubShape( horFace );
4252 Handle(Geom2d_Curve) C2d;
4254 const double tol = 10 * helper.MaxTolerance( horFace );
4255 const SMDS_MeshNode* prevNode = u2nodes.rbegin()->second;
4257 map<double, const SMDS_MeshNode* >::iterator u2n = u2nodes.begin();
4258 for ( ; u2n != u2nodes.end(); ++u2n )
4260 const SMDS_MeshNode* n = u2n->second;
4262 if ( n->GetPosition()->GetTypeOfPosition() == SMDS_TOP_EDGE )
4264 if ( n->getshapeId() != edgeID )
4267 edgeID = n->getshapeId();
4268 TopoDS_Shape S = helper.GetSubShapeByNode( n, helper.GetMeshDS() );
4269 if ( !S.IsNull() && S.ShapeType() == TopAbs_EDGE )
4271 C2d = BRep_Tool::CurveOnSurface( TopoDS::Edge( S ), horFace, f,l );
4274 if ( !C2d.IsNull() )
4276 double u = static_cast< const SMDS_EdgePosition* >( n->GetPosition() )->GetUParameter();
4277 if ( f <= u && u <= l )
4279 uv = C2d->Value( u ).XY();
4280 okUV = helper.CheckNodeUV( horFace, n, uv, tol );
4285 uv = helper.GetNodeUV( horFace, n, prevNode, &okUV );
4287 myUVmap.insert( myUVmap.end(), make_pair( u2n->first, uv ));
4288 // cout << n->getshapeId() << " N " << n->GetID()
4289 // << " \t" << uv.X() << ", " << uv.Y() << " \t" << u2n->first << endl;
4296 //================================================================================
4298 * \brief Return UV on pcurve for the given normalized parameter
4299 * \param U - normalized parameter
4300 * \retval gp_Pnt - coordinates
4302 //================================================================================
4304 gp_Pnt2d StdMeshers_PrismAsBlock::TPCurveOnHorFaceAdaptor::Value(const Standard_Real U) const
4306 map< double, gp_XY >::const_iterator i1 = myUVmap.upper_bound( U );
4308 if ( i1 == myUVmap.end() )
4309 return myUVmap.empty() ? gp_XY(0,0) : myUVmap.rbegin()->second;
4311 if ( i1 == myUVmap.begin() )
4312 return (*i1).second;
4314 map< double, gp_XY >::const_iterator i2 = i1--;
4316 double r = ( U - i1->first ) / ( i2->first - i1->first );
4317 return i1->second * ( 1 - r ) + i2->second * r;
4320 //================================================================================
4322 * \brief Projects internal nodes using transformation found by boundary nodes
4324 //================================================================================
4326 bool StdMeshers_Sweeper::projectIntPoints(const vector< gp_XYZ >& fromBndPoints,
4327 const vector< gp_XYZ >& toBndPoints,
4328 const vector< gp_XYZ >& fromIntPoints,
4329 vector< gp_XYZ >& toIntPoints,
4330 NSProjUtils::TrsfFinder3D& trsf,
4331 vector< gp_XYZ > * bndError)
4333 // find transformation
4334 if ( trsf.IsIdentity() && !trsf.Solve( fromBndPoints, toBndPoints ))
4337 // compute internal points using the found trsf
4338 for ( size_t iP = 0; iP < fromIntPoints.size(); ++iP )
4340 toIntPoints[ iP ] = trsf.Transform( fromIntPoints[ iP ]);
4343 // compute boundary error
4346 bndError->resize( fromBndPoints.size() );
4348 for ( size_t iP = 0; iP < fromBndPoints.size(); ++iP )
4350 fromTrsf = trsf.Transform( fromBndPoints[ iP ] );
4351 (*bndError)[ iP ] = toBndPoints[ iP ] - fromTrsf;
4357 //================================================================================
4359 * \brief Add boundary error to ineternal points
4361 //================================================================================
4363 void StdMeshers_Sweeper::applyBoundaryError(const vector< gp_XYZ >& bndPoints,
4364 const vector< gp_XYZ >& bndError1,
4365 const vector< gp_XYZ >& bndError2,
4367 vector< gp_XYZ >& intPoints,
4368 vector< double >& int2BndDist)
4370 // fix each internal point
4371 const double eps = 1e-100;
4372 for ( size_t iP = 0; iP < intPoints.size(); ++iP )
4374 gp_XYZ & intPnt = intPoints[ iP ];
4376 // compute distance from intPnt to each boundary node
4377 double int2BndDistSum = 0;
4378 for ( size_t iBnd = 0; iBnd < bndPoints.size(); ++iBnd )
4380 int2BndDist[ iBnd ] = 1 / (( intPnt - bndPoints[ iBnd ]).SquareModulus() + eps );
4381 int2BndDistSum += int2BndDist[ iBnd ];
4385 for ( size_t iBnd = 0; iBnd < bndPoints.size(); ++iBnd )
4387 intPnt += bndError1[ iBnd ] * ( 1 - r ) * int2BndDist[ iBnd ] / int2BndDistSum;
4388 intPnt += bndError2[ iBnd ] * r * int2BndDist[ iBnd ] / int2BndDistSum;
4393 //================================================================================
4395 * \brief Creates internal nodes of the prism
4397 //================================================================================
4399 bool StdMeshers_Sweeper::ComputeNodes( SMESH_MesherHelper& helper,
4402 const size_t zSize = myBndColumns[0]->size();
4403 const size_t zSrc = 0, zTgt = zSize-1;
4404 if ( zSize < 3 ) return true;
4406 vector< vector< gp_XYZ > > intPntsOfLayer( zSize ); // node coodinates to compute
4407 // set coordinates of src and tgt nodes
4408 for ( size_t z = 0; z < intPntsOfLayer.size(); ++z )
4409 intPntsOfLayer[ z ].resize( myIntColumns.size() );
4410 for ( size_t iP = 0; iP < myIntColumns.size(); ++iP )
4412 intPntsOfLayer[ zSrc ][ iP ] = intPoint( iP, zSrc );
4413 intPntsOfLayer[ zTgt ][ iP ] = intPoint( iP, zTgt );
4416 // compute coordinates of internal nodes by projecting (transfroming) src and tgt
4417 // nodes towards the central layer
4419 vector< NSProjUtils::TrsfFinder3D > trsfOfLayer( zSize );
4420 vector< vector< gp_XYZ > > bndError( zSize );
4422 // boundary points used to compute an affine transformation from a layer to a next one
4423 vector< gp_XYZ > fromSrcBndPnts( myBndColumns.size() ), fromTgtBndPnts( myBndColumns.size() );
4424 vector< gp_XYZ > toSrcBndPnts ( myBndColumns.size() ), toTgtBndPnts ( myBndColumns.size() );
4425 for ( size_t iP = 0; iP < myBndColumns.size(); ++iP )
4427 fromSrcBndPnts[ iP ] = bndPoint( iP, zSrc );
4428 fromTgtBndPnts[ iP ] = bndPoint( iP, zTgt );
4431 size_t zS = zSrc + 1;
4432 size_t zT = zTgt - 1;
4433 for ( ; zS < zT; ++zS, --zT ) // vertical loop on layers
4435 for ( size_t iP = 0; iP < myBndColumns.size(); ++iP )
4437 toSrcBndPnts[ iP ] = bndPoint( iP, zS );
4438 toTgtBndPnts[ iP ] = bndPoint( iP, zT );
4440 if (! projectIntPoints( fromSrcBndPnts, toSrcBndPnts,
4441 intPntsOfLayer[ zS-1 ], intPntsOfLayer[ zS ],
4442 trsfOfLayer [ zS-1 ], & bndError[ zS-1 ]))
4444 if (! projectIntPoints( fromTgtBndPnts, toTgtBndPnts,
4445 intPntsOfLayer[ zT+1 ], intPntsOfLayer[ zT ],
4446 trsfOfLayer [ zT+1 ], & bndError[ zT+1 ]))
4449 // if ( zT == zTgt - 1 )
4451 // for ( size_t iP = 0; iP < myBndColumns.size(); ++iP )
4453 // gp_XYZ fromTrsf = trsfOfLayer [ zT+1].Transform( fromTgtBndPnts[ iP ] );
4454 // cout << "mesh.AddNode( "
4455 // << fromTrsf.X() << ", "
4456 // << fromTrsf.Y() << ", "
4457 // << fromTrsf.Z() << ") " << endl;
4459 // for ( size_t iP = 0; iP < myIntColumns.size(); ++iP )
4460 // cout << "mesh.AddNode( "
4461 // << intPntsOfLayer[ zT ][ iP ].X() << ", "
4462 // << intPntsOfLayer[ zT ][ iP ].Y() << ", "
4463 // << intPntsOfLayer[ zT ][ iP ].Z() << ") " << endl;
4466 fromTgtBndPnts.swap( toTgtBndPnts );
4467 fromSrcBndPnts.swap( toSrcBndPnts );
4470 // Compute two projections of internal points to the central layer
4471 // in order to evaluate an error of internal points
4473 bool centerIntErrorIsSmall;
4474 vector< gp_XYZ > centerSrcIntPnts( myIntColumns.size() );
4475 vector< gp_XYZ > centerTgtIntPnts( myIntColumns.size() );
4477 for ( size_t iP = 0; iP < myBndColumns.size(); ++iP )
4479 toSrcBndPnts[ iP ] = bndPoint( iP, zS );
4480 toTgtBndPnts[ iP ] = bndPoint( iP, zT );
4482 if (! projectIntPoints( fromSrcBndPnts, toSrcBndPnts,
4483 intPntsOfLayer[ zS-1 ], centerSrcIntPnts,
4484 trsfOfLayer [ zS-1 ], & bndError[ zS-1 ]))
4486 if (! projectIntPoints( fromTgtBndPnts, toTgtBndPnts,
4487 intPntsOfLayer[ zT+1 ], centerTgtIntPnts,
4488 trsfOfLayer [ zT+1 ], & bndError[ zT+1 ]))
4491 // evaluate an error of internal points on the central layer
4492 centerIntErrorIsSmall = true;
4493 if ( zS == zT ) // odd zSize
4495 for ( size_t iP = 0; ( iP < myIntColumns.size() && centerIntErrorIsSmall ); ++iP )
4496 centerIntErrorIsSmall =
4497 (centerSrcIntPnts[ iP ] - centerTgtIntPnts[ iP ]).SquareModulus() < tol*tol;
4501 for ( size_t iP = 0; ( iP < myIntColumns.size() && centerIntErrorIsSmall ); ++iP )
4502 centerIntErrorIsSmall =
4503 (intPntsOfLayer[ zS-1 ][ iP ] - centerTgtIntPnts[ iP ]).SquareModulus() < tol*tol;
4506 // Evaluate an error of boundary points
4508 bool bndErrorIsSmall = true;
4509 for ( size_t iP = 0; ( iP < myBndColumns.size() && bndErrorIsSmall ); ++iP )
4511 double sumError = 0;
4512 for ( size_t z = 1; z < zS; ++z ) // loop on layers
4513 sumError += ( bndError[ z-1 ][ iP ].Modulus() +
4514 bndError[ zSize-z ][ iP ].Modulus() );
4516 bndErrorIsSmall = ( sumError < tol );
4519 // compute final points on the central layer
4520 std::vector< double > int2BndDist( myBndColumns.size() ); // work array of applyBoundaryError()
4521 double r = zS / ( zSize - 1.);
4524 for ( size_t iP = 0; iP < myIntColumns.size(); ++iP )
4526 intPntsOfLayer[ zS ][ iP ] =
4527 ( 1 - r ) * centerSrcIntPnts[ iP ] + r * centerTgtIntPnts[ iP ];
4529 if ( !bndErrorIsSmall )
4531 applyBoundaryError( toSrcBndPnts, bndError[ zS-1 ], bndError[ zS+1 ], r,
4532 intPntsOfLayer[ zS ], int2BndDist );
4537 for ( size_t iP = 0; iP < myIntColumns.size(); ++iP )
4539 intPntsOfLayer[ zS ][ iP ] =
4540 r * intPntsOfLayer[ zS ][ iP ] + ( 1 - r ) * centerSrcIntPnts[ iP ];
4541 intPntsOfLayer[ zT ][ iP ] =
4542 r * intPntsOfLayer[ zT ][ iP ] + ( 1 - r ) * centerTgtIntPnts[ iP ];
4544 if ( !bndErrorIsSmall )
4546 applyBoundaryError( toSrcBndPnts, bndError[ zS-1 ], bndError[ zS+1 ], r,
4547 intPntsOfLayer[ zS ], int2BndDist );
4548 applyBoundaryError( toTgtBndPnts, bndError[ zT+1 ], bndError[ zT-1 ], r,
4549 intPntsOfLayer[ zT ], int2BndDist );
4553 //centerIntErrorIsSmall = true;
4554 //bndErrorIsSmall = true;
4555 if ( !centerIntErrorIsSmall )
4557 // Compensate the central error; continue adding projection
4558 // by going from central layer to the source and target ones
4560 vector< gp_XYZ >& fromSrcIntPnts = centerSrcIntPnts;
4561 vector< gp_XYZ >& fromTgtIntPnts = centerTgtIntPnts;
4562 vector< gp_XYZ > toSrcIntPnts( myIntColumns.size() );
4563 vector< gp_XYZ > toTgtIntPnts( myIntColumns.size() );
4564 vector< gp_XYZ > srcBndError( myBndColumns.size() );
4565 vector< gp_XYZ > tgtBndError( myBndColumns.size() );
4567 fromTgtBndPnts.swap( toTgtBndPnts );
4568 fromSrcBndPnts.swap( toSrcBndPnts );
4570 for ( ++zS, --zT; zS < zTgt; ++zS, --zT ) // vertical loop on layers
4572 // invert transformation
4573 if ( !trsfOfLayer[ zS+1 ].Invert() )
4574 trsfOfLayer[ zS+1 ] = NSProjUtils::TrsfFinder3D(); // to recompute
4575 if ( !trsfOfLayer[ zT-1 ].Invert() )
4576 trsfOfLayer[ zT-1 ] = NSProjUtils::TrsfFinder3D();
4578 // project internal nodes and compute bnd error
4579 for ( size_t iP = 0; iP < myBndColumns.size(); ++iP )
4581 toSrcBndPnts[ iP ] = bndPoint( iP, zS );
4582 toTgtBndPnts[ iP ] = bndPoint( iP, zT );
4584 projectIntPoints( fromSrcBndPnts, toSrcBndPnts,
4585 fromSrcIntPnts, toSrcIntPnts,
4586 trsfOfLayer[ zS+1 ], & srcBndError );
4587 projectIntPoints( fromTgtBndPnts, toTgtBndPnts,
4588 fromTgtIntPnts, toTgtIntPnts,
4589 trsfOfLayer[ zT-1 ], & tgtBndError );
4591 // if ( zS == zTgt - 1 )
4593 // cout << "mesh2 = smesh.Mesh()" << endl;
4594 // for ( size_t iP = 0; iP < myBndColumns.size(); ++iP )
4596 // gp_XYZ fromTrsf = trsfOfLayer [ zS+1].Transform( fromSrcBndPnts[ iP ] );
4597 // cout << "mesh2.AddNode( "
4598 // << fromTrsf.X() << ", "
4599 // << fromTrsf.Y() << ", "
4600 // << fromTrsf.Z() << ") " << endl;
4602 // for ( size_t iP = 0; iP < myIntColumns.size(); ++iP )
4603 // cout << "mesh2.AddNode( "
4604 // << toSrcIntPnts[ iP ].X() << ", "
4605 // << toSrcIntPnts[ iP ].Y() << ", "
4606 // << toSrcIntPnts[ iP ].Z() << ") " << endl;
4609 // sum up 2 projections
4610 r = zS / ( zSize - 1.);
4611 vector< gp_XYZ >& zSIntPnts = intPntsOfLayer[ zS ];
4612 vector< gp_XYZ >& zTIntPnts = intPntsOfLayer[ zT ];
4613 for ( size_t iP = 0; iP < myIntColumns.size(); ++iP )
4615 zSIntPnts[ iP ] = r * zSIntPnts[ iP ] + ( 1 - r ) * toSrcIntPnts[ iP ];
4616 zTIntPnts[ iP ] = r * zTIntPnts[ iP ] + ( 1 - r ) * toTgtIntPnts[ iP ];
4619 // compensate bnd error
4620 if ( !bndErrorIsSmall )
4622 applyBoundaryError( toSrcBndPnts, srcBndError, bndError[ zS+1 ], r,
4623 intPntsOfLayer[ zS ], int2BndDist );
4624 applyBoundaryError( toTgtBndPnts, tgtBndError, bndError[ zT-1 ], r,
4625 intPntsOfLayer[ zT ], int2BndDist );
4628 fromSrcBndPnts.swap( toSrcBndPnts );
4629 fromSrcIntPnts.swap( toSrcIntPnts );
4630 fromTgtBndPnts.swap( toTgtBndPnts );
4631 fromTgtIntPnts.swap( toTgtIntPnts );
4633 } // if ( !centerIntErrorIsSmall )
4635 else if ( !bndErrorIsSmall )
4639 for ( ; zS < zT; ++zS, --zT ) // vertical loop on layers
4641 for ( size_t iP = 0; iP < myBndColumns.size(); ++iP )
4643 toSrcBndPnts[ iP ] = bndPoint( iP, zS );
4644 toTgtBndPnts[ iP ] = bndPoint( iP, zT );
4646 // compensate bnd error
4647 applyBoundaryError( toSrcBndPnts, bndError[ zS-1 ], bndError[ zS-1 ], 0.5,
4648 intPntsOfLayer[ zS ], int2BndDist );
4649 applyBoundaryError( toTgtBndPnts, bndError[ zT+1 ], bndError[ zT+1 ], 0.5,
4650 intPntsOfLayer[ zT ], int2BndDist );
4654 // cout << "centerIntErrorIsSmall = " << centerIntErrorIsSmall<< endl;
4655 // cout << "bndErrorIsSmall = " << bndErrorIsSmall<< endl;
4658 for ( size_t iP = 0; iP < myIntColumns.size(); ++iP )
4660 vector< const SMDS_MeshNode* > & nodeCol = *myIntColumns[ iP ];
4661 for ( size_t z = zSrc + 1; z < zTgt; ++z ) // vertical loop on layers
4663 const gp_XYZ & xyz = intPntsOfLayer[ z ][ iP ];
4664 if ( !( nodeCol[ z ] = helper.AddNode( xyz.X(), xyz.Y(), xyz.Z() )))