1 // Copyright (C) 2007-2020 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License, or (at your option) any later version.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 // File : StdMeshers_Prism_3D.cxx
25 // Created : Fri Oct 20 11:37:07 2006
26 // Author : Edward AGAPOV (eap)
28 #include "StdMeshers_Prism_3D.hxx"
30 #include "SMDS_EdgePosition.hxx"
31 #include "SMDS_VolumeOfNodes.hxx"
32 #include "SMDS_VolumeTool.hxx"
33 #include "SMESH_Comment.hxx"
34 #include "SMESH_Gen.hxx"
35 #include "SMESH_HypoFilter.hxx"
36 #include "SMESH_MeshEditor.hxx"
37 #include "SMESH_MesherHelper.hxx"
38 #include "StdMeshers_FaceSide.hxx"
39 #include "StdMeshers_ProjectionSource1D.hxx"
40 #include "StdMeshers_ProjectionSource2D.hxx"
41 #include "StdMeshers_ProjectionUtils.hxx"
42 #include "StdMeshers_Projection_1D.hxx"
43 #include "StdMeshers_Projection_1D2D.hxx"
44 #include "StdMeshers_Quadrangle_2D.hxx"
46 #include "utilities.h"
48 #include <BRepAdaptor_CompCurve.hxx>
49 #include <BRep_Tool.hxx>
50 #include <Bnd_B3d.hxx>
51 #include <Geom2dAdaptor_Curve.hxx>
52 #include <Geom2d_Line.hxx>
53 #include <GeomLib_IsPlanarSurface.hxx>
54 #include <Geom_Curve.hxx>
55 #include <Standard_ErrorHandler.hxx>
57 #include <TopExp_Explorer.hxx>
58 #include <TopTools_ListIteratorOfListOfShape.hxx>
59 #include <TopTools_ListOfShape.hxx>
60 #include <TopTools_MapOfShape.hxx>
61 #include <TopTools_SequenceOfShape.hxx>
71 #define RETURN_BAD_RESULT(msg) { MESSAGE(")-: Error: " << msg); return false; }
72 #define gpXYZ(n) SMESH_TNodeXYZ(n)
75 #define DBGOUT(msg) //cout << msg << endl;
76 #define SHOWYXZ(msg, xyz) \
77 //{ gp_Pnt p (xyz); cout << msg << " ("<< p.X() << "; " <<p.Y() << "; " <<p.Z() << ") " <<endl; }
80 #define SHOWYXZ(msg, xyz)
83 namespace NSProjUtils = StdMeshers_ProjectionUtils;
85 typedef SMESH_Comment TCom;
87 enum { ID_BOT_FACE = SMESH_Block::ID_Fxy0,
88 ID_TOP_FACE = SMESH_Block::ID_Fxy1,
89 BOTTOM_EDGE = 0, TOP_EDGE, V0_EDGE, V1_EDGE, // edge IDs in face
90 NB_WALL_FACES = 4 }; //
94 //=======================================================================
96 * \brief Auxiliary mesh
98 struct TmpMesh: public SMESH_Mesh
101 _isShapeToMesh = (_id = 0);
102 _myMeshDS = new SMESHDS_Mesh( _id, true );
105 //=======================================================================
107 * \brief Quadrangle algorithm
109 class TQuadrangleAlgo : public StdMeshers_Quadrangle_2D
111 typedef NCollection_DataMap< TopoDS_Face, FaceQuadStruct::Ptr > TFace2QuadMap;
112 TFace2QuadMap myFace2QuadMap;
114 TQuadrangleAlgo(SMESH_Gen* gen)
115 : StdMeshers_Quadrangle_2D( gen->GetANewId(), gen)
120 //================================================================================
121 // Clear data of TQuadrangleAlgo at destruction
124 TQuadrangleAlgo* myAlgo;
126 Cleaner(TQuadrangleAlgo* algo): myAlgo( algo ){}
127 ~Cleaner() { myAlgo->reset(); }
130 //================================================================================
131 // Return TQuadrangleAlgo singleton
132 static TQuadrangleAlgo* instance( SMESH_Algo* fatherAlgo,
133 SMESH_MesherHelper* helper=0)
135 static TQuadrangleAlgo* algo = new TQuadrangleAlgo( fatherAlgo->GetGen() );
138 algo->myProxyMesh->GetMesh() != helper->GetMesh() )
139 algo->myProxyMesh.reset( new SMESH_ProxyMesh( *helper->GetMesh() ));
141 algo->myQuadList.clear();
145 algo->_quadraticMesh = helper->GetIsQuadratic();
150 //================================================================================
151 // Clear collected data
154 StdMeshers_Quadrangle_2D::myQuadList.clear();
155 StdMeshers_Quadrangle_2D::myHelper = nullptr;
156 StdMeshers_Quadrangle_2D::myProxyMesh.reset();
157 myFace2QuadMap.Clear();
160 //================================================================================
162 * \brief Return FaceQuadStruct if a given FACE can be meshed by StdMeshers_Quadrangle_2D
164 FaceQuadStruct::Ptr CheckNbEdges(SMESH_Mesh& theMesh,
165 const TopoDS_Shape& theShape )
167 const TopoDS_Face& face = TopoDS::Face( theShape );
168 if ( myFace2QuadMap.IsBound( face ))
169 return myFace2QuadMap.Find( face );
171 FaceQuadStruct::Ptr & resultQuad = * myFace2QuadMap.Bound( face, FaceQuadStruct::Ptr() );
173 FaceQuadStruct::Ptr quad =
174 StdMeshers_Quadrangle_2D::CheckNbEdges( theMesh, face, /*considerMesh=*/false, myHelper );
177 // check if the quadrangle mesh would be valid
179 // check existing 1D mesh
180 // int nbSegments[4], i = 0;
181 // for ( FaceQuadStruct::Side & side : quad->side )
182 // nbSegments[ i++ ] = side.grid->NbSegments();
183 // if ( nbSegments[0] > 0 && nbSegments[2] > 0 && nbSegments[0] != nbSegments[2] ||
184 // nbSegments[1] > 0 && nbSegments[3] > 0 && nbSegments[1] != nbSegments[3] )
185 // return resultQuad;
188 for ( FaceQuadStruct::Side & side : quad->side )
189 nbEdges += side.grid->NbEdges();
191 return resultQuad = quad;
194 mesh.ShapeToMesh( face );
195 SMESHDS_Mesh* meshDS = mesh.GetMeshDS();
196 SMESH_MesherHelper helper( mesh );
197 helper.SetSubShape( face );
198 helper.SetElementsOnShape( true );
200 // create nodes on all VERTEX'es
201 for ( TopExp_Explorer vert( face, TopAbs_VERTEX ); vert.More(); vert.Next() )
202 mesh.GetSubMesh( vert.Current() )->ComputeStateEngine( SMESH_subMesh::COMPUTE );
204 FaceQuadStruct::Ptr tmpQuad( new FaceQuadStruct() );
205 tmpQuad->side.resize( 4 );
207 // divide quad sides into halves at least
208 const SMDS_MeshNode* node;
209 for ( int iDir = 0; iDir < 2; ++iDir )
211 StdMeshers_FaceSidePtr sides[2] = { quad->side[iDir], quad->side[iDir+2] };
212 std::map< double, const SMDS_MeshNode* > nodes[2];
213 for ( int iS : { 0, 1 } )
215 node = SMESH_Algo::VertexNode( sides[iS]->FirstVertex(), meshDS );
216 nodes[iS].insert( std::make_pair( 0, node ));
218 for ( int iE = 1; iE < sides[iS]->NbEdges(); ++iE )
220 curLen += sides[iS]->EdgeLength( iE - 1 );
221 double u = curLen / sides[iS]->Length();
222 node = SMESH_Algo::VertexNode( sides[iS]->FirstVertex( iE ), meshDS );
223 nodes[iS ].insert( std::make_pair( u, node ));
224 nodes[1-iS].insert( std::make_pair( u, nullptr ));
226 nodes[iS].insert( std::make_pair( 0.5, nullptr ));
227 node = SMESH_Algo::VertexNode( sides[iS]->LastVertex(), meshDS );
228 nodes[iS].insert( std::make_pair( 1, node ));
231 for ( int iS : { 0, 1 } )
233 UVPtStructVec sideNodes;
234 sideNodes.reserve( nodes[ iS ].size() );
235 for ( auto & u_node : nodes[ iS ])
237 if ( !u_node.second )
239 gp_Pnt p = sides[iS]->Value3d( u_node.first );
240 u_node.second = meshDS->AddNode( p.X(), p.Y(), p.Z() );
242 double param = sides[iS]->Parameter( u_node.first, edge );
243 meshDS->SetNodeOnEdge( u_node.second, edge, param );
245 sideNodes.push_back( u_node.second );
246 sideNodes.back().SetUV( helper.GetNodeUV( face, u_node.second ));
248 tmpQuad->side[ iS ? iDir+2 : iDir ] = StdMeshers_FaceSide::New( sideNodes, face );
251 StdMeshers_Quadrangle_2D::myCheckOri = true;
252 StdMeshers_Quadrangle_2D::myQuadList.clear();
253 StdMeshers_Quadrangle_2D::myQuadList.push_back( tmpQuad );
254 StdMeshers_Quadrangle_2D::myHelper = &helper;
255 if ( StdMeshers_Quadrangle_2D::computeQuadDominant( mesh, face, tmpQuad ) &&
256 StdMeshers_Quadrangle_2D::check())
260 StdMeshers_Quadrangle_2D::myQuadList.clear();
261 StdMeshers_Quadrangle_2D::myHelper = nullptr;
267 //=======================================================================
269 * \brief Algorithm projecting 1D mesh
271 struct TProjction1dAlgo : public StdMeshers_Projection_1D
273 StdMeshers_ProjectionSource1D myHyp;
275 TProjction1dAlgo(SMESH_Gen* gen)
276 : StdMeshers_Projection_1D( gen->GetANewId(), gen),
277 myHyp( gen->GetANewId(), gen)
279 StdMeshers_Projection_1D::_sourceHypo = & myHyp;
281 static TProjction1dAlgo* instance( SMESH_Algo* fatherAlgo )
283 static TProjction1dAlgo* algo = new TProjction1dAlgo( fatherAlgo->GetGen() );
287 //=======================================================================
289 * \brief Algorithm projecting 2D mesh
291 struct TProjction2dAlgo : public StdMeshers_Projection_1D2D
293 StdMeshers_ProjectionSource2D myHyp;
295 TProjction2dAlgo(SMESH_Gen* gen)
296 : StdMeshers_Projection_1D2D( gen->GetANewId(), gen),
297 myHyp( gen->GetANewId(), gen)
299 StdMeshers_Projection_2D::_sourceHypo = & myHyp;
301 static TProjction2dAlgo* instance( SMESH_Algo* fatherAlgo )
303 static TProjction2dAlgo* algo = new TProjction2dAlgo( fatherAlgo->GetGen() );
306 const NSProjUtils::TNodeNodeMap& GetNodesMap()
308 return _src2tgtNodes;
310 void SetEventListener( SMESH_subMesh* tgtSubMesh )
312 NSProjUtils::SetEventListener( tgtSubMesh,
313 _sourceHypo->GetSourceFace(),
314 _sourceHypo->GetSourceMesh() );
317 //=======================================================================
319 * \brief Returns already computed EDGEs
321 void getPrecomputedEdges( SMESH_MesherHelper& theHelper,
322 const TopoDS_Shape& theShape,
323 vector< TopoDS_Edge >& theEdges)
327 SMESHDS_Mesh* meshDS = theHelper.GetMeshDS();
330 TopTools_IndexedMapOfShape edges;
331 TopExp::MapShapes( theShape, TopAbs_EDGE, edges );
332 for ( int iE = 1; iE <= edges.Extent(); ++iE )
334 const TopoDS_Shape edge = edges( iE );
335 if (( ! ( sm = meshDS->MeshElements( edge ))) ||
336 ( sm->NbElements() == 0 ))
339 // there must not be FACEs meshed with triangles and sharing a computed EDGE
340 // as the precomputed EDGEs are used for propagation other to 'vertical' EDGEs
341 bool faceFound = false;
342 PShapeIteratorPtr faceIt =
343 theHelper.GetAncestors( edge, *theHelper.GetMesh(), TopAbs_FACE );
344 while ( const TopoDS_Shape* face = faceIt->next() )
346 if (( sm = meshDS->MeshElements( *face )) &&
347 ( sm->NbElements() > 0 ) &&
348 ( !theHelper.IsSameElemGeometry( sm, SMDSGeom_QUADRANGLE ) ))
354 theEdges.push_back( TopoDS::Edge( edge ));
358 //================================================================================
360 * \brief Make \a botE be the BOTTOM_SIDE of \a quad.
361 * Return false if the BOTTOM_SIDE is composite
363 //================================================================================
365 bool setBottomEdge( const TopoDS_Edge& botE,
366 FaceQuadStruct::Ptr& quad,
367 const TopoDS_Shape& face)
369 quad->side[ QUAD_TOP_SIDE ].grid->Reverse();
370 quad->side[ QUAD_LEFT_SIDE ].grid->Reverse();
372 bool isComposite = false;
373 for ( size_t i = 0; i < quad->side.size(); ++i )
375 StdMeshers_FaceSidePtr quadSide = quad->side[i];
376 for ( int iE = 0; iE < quadSide->NbEdges(); ++iE )
377 if ( botE.IsSame( quadSide->Edge( iE )))
379 if ( quadSide->NbEdges() > 1 )
380 isComposite = true; //return false;
382 i = quad->side.size(); // to quit from the outer loop
386 if ( edgeIndex != QUAD_BOTTOM_SIDE )
387 quad->shift( quad->side.size() - edgeIndex, /*keepUnitOri=*/false );
389 quad->face = TopoDS::Face( face );
394 //================================================================================
396 * \brief Return iterator pointing to node column for the given parameter
397 * \param columnsMap - node column map
398 * \param parameter - parameter
399 * \retval TParam2ColumnMap::iterator - result
401 * it returns closest left column
403 //================================================================================
405 TParam2ColumnIt getColumn( const TParam2ColumnMap* columnsMap,
406 const double parameter )
408 TParam2ColumnIt u_col = columnsMap->upper_bound( parameter );
409 if ( u_col != columnsMap->begin() )
411 return u_col; // return left column
414 //================================================================================
416 * \brief Return nodes around given parameter and a ratio
417 * \param column - node column
418 * \param param - parameter
419 * \param node1 - lower node
420 * \param node2 - upper node
421 * \retval double - ratio
423 //================================================================================
425 double getRAndNodes( const TNodeColumn* column,
427 const SMDS_MeshNode* & node1,
428 const SMDS_MeshNode* & node2)
430 if ( param >= 1.0 || column->size() == 1) {
431 node1 = node2 = column->back();
435 int i = int( param * ( column->size() - 1 ));
436 double u0 = double( i )/ double( column->size() - 1 );
437 double r = ( param - u0 ) * ( column->size() - 1 );
439 node1 = (*column)[ i ];
440 node2 = (*column)[ i + 1];
444 //================================================================================
446 * \brief Compute boundary parameters of face parts
447 * \param nbParts - nb of parts to split columns into
448 * \param columnsMap - node columns of the face to split
449 * \param params - computed parameters
451 //================================================================================
453 void splitParams( const int nbParts,
454 const TParam2ColumnMap* columnsMap,
455 vector< double > & params)
458 params.reserve( nbParts + 1 );
459 TParam2ColumnIt last_par_col = --columnsMap->end();
460 double par = columnsMap->begin()->first; // 0.
461 double parLast = last_par_col->first;
462 params.push_back( par );
463 for ( int i = 0; i < nbParts - 1; ++ i )
465 double partSize = ( parLast - par ) / double ( nbParts - i );
466 TParam2ColumnIt par_col = getColumn( columnsMap, par + partSize );
467 if ( par_col->first == par ) {
469 if ( par_col == last_par_col ) {
470 while ( i < nbParts - 1 )
471 params.push_back( par + partSize * i++ );
475 par = par_col->first;
476 params.push_back( par );
478 params.push_back( parLast ); // 1.
481 //================================================================================
483 * \brief Return coordinate system for z-th layer of nodes
485 //================================================================================
487 gp_Ax2 getLayerCoordSys(const int z,
488 const vector< const TNodeColumn* >& columns,
491 // gravity center of a layer
494 for ( size_t i = 0; i < columns.size(); ++i )
496 O += gpXYZ( (*columns[ i ])[ z ]);
497 if ( vertexCol < 0 &&
498 columns[ i ]->front()->GetPosition()->GetTypeOfPosition() == SMDS_TOP_VERTEX )
505 int iPrev = columns.size()-1;
506 for ( size_t i = 0; i < columns.size(); ++i )
508 gp_Vec v1( O, gpXYZ( (*columns[ iPrev ])[ z ]));
509 gp_Vec v2( O, gpXYZ( (*columns[ i ] )[ z ]));
514 if ( vertexCol >= 0 )
516 O = gpXYZ( (*columns[ vertexCol ])[ z ]);
518 if ( xColumn < 0 || xColumn >= (int) columns.size() )
520 // select a column for X dir
522 for ( size_t i = 0; i < columns.size(); ++i )
524 double dist = ( O - gpXYZ((*columns[ i ])[ z ])).SquareModulus();
525 if ( dist > maxDist )
534 gp_Vec X( O, gpXYZ( (*columns[ xColumn ])[ z ]));
536 return gp_Ax2( O, Z, X);
539 //================================================================================
541 * \brief Removes submeshes that are or can be meshed with regular grid from given list
542 * \retval int - nb of removed submeshes
544 //================================================================================
546 int removeQuasiQuads(list< SMESH_subMesh* >& notQuadSubMesh,
547 SMESH_MesherHelper* helper,
548 TQuadrangleAlgo* quadAlgo)
551 //SMESHDS_Mesh* mesh = notQuadSubMesh.front()->GetFather()->GetMeshDS();
552 list< SMESH_subMesh* >::iterator smIt = notQuadSubMesh.begin();
553 while ( smIt != notQuadSubMesh.end() )
555 SMESH_subMesh* faceSm = *smIt;
556 SMESHDS_SubMesh* faceSmDS = faceSm->GetSubMeshDS();
557 int nbQuads = faceSmDS ? faceSmDS->NbElements() : 0;
560 toRemove = helper->IsStructured( faceSm );
562 toRemove = ( quadAlgo->CheckNbEdges( *helper->GetMesh(),
563 faceSm->GetSubShape() ) != NULL );
564 nbRemoved += toRemove;
566 smIt = notQuadSubMesh.erase( smIt );
574 //================================================================================
576 * \brief Return and angle between two EDGEs
577 * \return double - the angle normalized so that
584 //================================================================================
586 // double normAngle(const TopoDS_Edge & E1, const TopoDS_Edge & E2, const TopoDS_Face & F)
588 // return SMESH_MesherHelper::GetAngle( E1, E2, F ) / ( 0.5 * M_PI );
591 //================================================================================
593 * Consider continuous straight EDGES as one side - mark them to unite
595 //================================================================================
597 int countNbSides( const Prism_3D::TPrismTopo & thePrism,
598 vector<int> & /*nbUnitePerEdge*/,
599 vector< double > & edgeLength)
601 int nbEdges = thePrism.myNbEdgesInWires.front(); // nb outer edges
602 int nbSides = nbEdges;
605 list< TopoDS_Edge >::const_iterator edgeIt = thePrism.myBottomEdges.begin();
606 std::advance( edgeIt, nbEdges-1 );
607 TopoDS_Edge prevE = *edgeIt;
608 // bool isPrevStraight = SMESH_Algo::IsStraight( prevE );
609 // int iPrev = nbEdges - 1;
611 // int iUnite = -1; // the first of united EDGEs
613 // analyse angles between EDGEs
615 vector< bool > isCorner( nbEdges );
616 edgeIt = thePrism.myBottomEdges.begin();
617 for ( int iE = 0; iE < nbEdges; ++iE, ++edgeIt )
619 const TopoDS_Edge& curE = *edgeIt;
620 edgeLength[ iE ] = SMESH_Algo::EdgeLength( curE );
622 // double normAngle = normAngle( prevE, curE, thePrism.myBottom );
623 // isCorner[ iE ] = false;
624 // if ( normAngle < 2.0 )
626 // if ( normAngle < 0.001 ) // straight or obtuse angle
628 // // unite EDGEs in order not to put a corner of the unit quadrangle at this VERTEX
631 // nbUnitePerEdge[ iUnite ]++;
632 // nbUnitePerEdge[ iE ] = -1;
637 // isCorner[ iE ] = true;
647 // define which of corners to put on a side of the unit quadrangle
649 // edgeIt = thePrism.myBottomEdges.begin();
650 // for ( int iE = 0; iE < nbEdges; ++iE, ++edgeIt )
652 // const TopoDS_Edge& curE = *edgeIt;
653 // edgeLength[ iE ] = SMESH_Algo::EdgeLength( curE );
655 // const bool isCurStraight = SMESH_Algo::IsStraight( curE );
656 // if ( isPrevStraight && isCurStraight && SMESH_Algo::IsContinuous( prevE, curE ))
660 // nbUnitePerEdge[ iUnite ]++;
661 // nbUnitePerEdge[ iE ] = -1;
669 // isPrevStraight = isCurStraight;
676 //================================================================================
678 * \brief Count EDGEs ignoring degenerated ones
680 //================================================================================
682 int CountEdges( const TopoDS_Face& face )
685 for ( TopExp_Explorer edgeExp( face, TopAbs_EDGE ); edgeExp.More(); edgeExp.Next() )
686 if ( !SMESH_Algo::isDegenerated( TopoDS::Edge( edgeExp.Current() )))
692 //================================================================================
694 * \brief Set/get wire index to FaceQuadStruct
696 //================================================================================
698 void setWireIndex( TFaceQuadStructPtr& quad, int iWire )
702 int getWireIndex( const TFaceQuadStructPtr& quad )
707 //================================================================================
709 * \brief Print Python commands adding given points to a mesh
711 //================================================================================
713 void pointsToPython(const std::vector<gp_XYZ>& p)
716 for ( size_t i = SMESH_Block::ID_V000; i < p.size(); ++i )
718 cout << "mesh.AddNode( " << p[i].X() << ", "<< p[i].Y() << ", "<< p[i].Z() << ") # " << i <<" " ;
719 SMESH_Block::DumpShapeID( i, cout ) << endl;
722 (void)p; // unused in release mode
728 //=======================================================================
729 //function : StdMeshers_Prism_3D
731 //=======================================================================
733 StdMeshers_Prism_3D::StdMeshers_Prism_3D(int hypId, SMESH_Gen* gen)
734 :SMESH_3D_Algo(hypId, gen)
737 _shapeType = (1 << TopAbs_SOLID); // 1 bit per shape type
738 _onlyUnaryInput = false; // mesh all SOLIDs at once
739 _requireDiscreteBoundary = false; // mesh FACEs and EDGEs by myself
740 _supportSubmeshes = true; // "source" FACE must be meshed by other algo
741 _neededLowerHyps[ 1 ] = true; // suppress warning on hiding a global 1D algo
742 _neededLowerHyps[ 2 ] = true; // suppress warning on hiding a global 2D algo
744 //myProjectTriangles = false;
745 mySetErrorToSM = true; // to pass an error to a sub-mesh of a current solid or not
746 myPrevBottomSM = 0; // last treated bottom sub-mesh with a suitable algorithm
749 //================================================================================
753 //================================================================================
755 StdMeshers_Prism_3D::~StdMeshers_Prism_3D()
757 pointsToPython( std::vector<gp_XYZ>() ); // avoid warning: pointsToPython defined but not used
760 //=======================================================================
761 //function : CheckHypothesis
763 //=======================================================================
765 bool StdMeshers_Prism_3D::CheckHypothesis(SMESH_Mesh& /*aMesh*/,
766 const TopoDS_Shape& /*aShape*/,
767 SMESH_Hypothesis::Hypothesis_Status& aStatus)
770 aStatus = SMESH_Hypothesis::HYP_OK;
774 //=======================================================================
776 //purpose : Compute mesh on a COMPOUND of SOLIDs
777 //=======================================================================
779 bool StdMeshers_Prism_3D::Compute(SMESH_Mesh& theMesh, const TopoDS_Shape& theShape)
781 SMESH_MesherHelper helper( theMesh );
784 TQuadrangleAlgo::Cleaner quadCleaner( TQuadrangleAlgo::instance( this ));
786 int nbSolids = helper.Count( theShape, TopAbs_SOLID, /*skipSame=*/false );
790 TopTools_IndexedDataMapOfShapeListOfShape faceToSolids;
791 TopExp::MapShapesAndAncestors( theShape, TopAbs_FACE, TopAbs_SOLID, faceToSolids );
793 // look for meshed FACEs ("source" FACEs) that must be prism bottoms
794 list< TopoDS_Face > meshedFaces, notQuadMeshedFaces, notQuadFaces;
795 const bool meshHasQuads = ( theMesh.NbQuadrangles() > 0 );
796 for ( int iF = 1; iF <= faceToSolids.Extent(); ++iF )
798 const TopoDS_Face& face = TopoDS::Face( faceToSolids.FindKey( iF ));
799 SMESH_subMesh* faceSM = theMesh.GetSubMesh( face );
800 if ( !faceSM->IsEmpty() )
802 if ( !meshHasQuads ||
803 !helper.IsSameElemGeometry( faceSM->GetSubMeshDS(), SMDSGeom_QUADRANGLE ) ||
804 !helper.IsStructured( faceSM )
806 notQuadMeshedFaces.push_front( face );
807 else if ( myHelper->Count( face, TopAbs_EDGE, /*ignoreSame=*/false ) != 4 )
808 meshedFaces.push_front( face );
810 meshedFaces.push_back( face );
812 // not add not quadrilateral FACE as we can't compute it
813 // else if ( !quadAlgo->CheckNbEdges( theMesh, face ))
814 // // not add not quadrilateral FACE as it can be a prism side
815 // // else if ( myHelper->Count( face, TopAbs_EDGE, /*ignoreSame=*/false ) != 4 )
817 // notQuadFaces.push_back( face );
820 // notQuadFaces are of medium priority, put them before ordinary meshed faces
821 meshedFaces.splice( meshedFaces.begin(), notQuadFaces );
822 // notQuadMeshedFaces are of highest priority, put them before notQuadFaces
823 meshedFaces.splice( meshedFaces.begin(), notQuadMeshedFaces );
825 Prism_3D::TPrismTopo prism;
827 bool selectBottom = meshedFaces.empty();
831 TopoDS_Shape solid = TopExp_Explorer( theShape, TopAbs_SOLID ).Current();
832 if ( !meshedFaces.empty() )
833 prism.myBottom = meshedFaces.front();
834 return ( initPrism( prism, solid, selectBottom ) &&
838 // find propagation chains from already computed EDGEs
839 vector< TopoDS_Edge > computedEdges;
840 getPrecomputedEdges( helper, theShape, computedEdges );
841 myPropagChains = new TopTools_IndexedMapOfShape[ computedEdges.size() + 1 ];
842 SMESHUtils::ArrayDeleter< TopTools_IndexedMapOfShape > pcDel( myPropagChains );
843 for ( size_t i = 0, nb = 0; i < computedEdges.size(); ++i )
845 StdMeshers_ProjectionUtils::GetPropagationEdge( &theMesh, TopoDS_Edge(),
846 computedEdges[i], myPropagChains + nb );
847 if ( myPropagChains[ nb ].Extent() < 2 ) // an empty map is a termination sign
848 myPropagChains[ nb ].Clear();
853 TopTools_MapOfShape meshedSolids;
854 NCollection_DataMap< TopoDS_Shape, SMESH_subMesh* > meshedFace2AlgoSM;
855 list< Prism_3D::TPrismTopo > meshedPrism;
856 list< TopoDS_Face > suspectSourceFaces;
857 TopTools_ListIteratorOfListOfShape solidIt;
859 while ( meshedSolids.Extent() < nbSolids )
861 if ( _computeCanceled )
862 return toSM( error( SMESH_ComputeError::New(COMPERR_CANCELED)));
864 // compute prisms having avident computed source FACE
865 while ( !meshedFaces.empty() )
867 TopoDS_Face face = meshedFaces.front();
868 meshedFaces.pop_front();
869 TopTools_ListOfShape& solidList = faceToSolids.ChangeFromKey( face );
870 while ( !solidList.IsEmpty() )
872 TopoDS_Shape solid = solidList.First();
873 solidList.RemoveFirst();
874 if ( meshedSolids.Add( solid ))
877 prism.myBottom = face;
878 if ( meshedFace2AlgoSM.IsBound( face ))
879 prism.myAlgoSM = meshedFace2AlgoSM.Find( face );
880 if ( !initPrism( prism, solid, selectBottom ) ||
884 SMESHDS_SubMesh* smDS = theMesh.GetMeshDS()->MeshElements( prism.myTop );
885 if ( !myHelper->IsSameElemGeometry( smDS, SMDSGeom_QUADRANGLE ) ||
886 !myHelper->IsStructured( theMesh.GetSubMesh( prism.myTop )))
888 meshedFaces.push_front( prism.myTop );
889 if ( prism.myAlgoSM && prism.myAlgoSM->GetAlgo() )
891 meshedFace2AlgoSM.Bind( prism.myTop, prism.myAlgoSM );
892 meshedFace2AlgoSM.Bind( prism.myBottom, prism.myAlgoSM );
897 suspectSourceFaces.push_back( prism.myTop );
899 meshedPrism.push_back( prism );
903 if ( meshedSolids.Extent() == nbSolids )
906 // below in the loop we try to find source FACEs somehow
908 // project mesh from source FACEs of computed prisms to
909 // prisms sharing wall FACEs
910 list< Prism_3D::TPrismTopo >::iterator prismIt = meshedPrism.begin();
911 for ( ; prismIt != meshedPrism.end(); ++prismIt )
913 for ( size_t iW = 0; iW < prismIt->myWallQuads.size(); ++iW )
915 Prism_3D::TQuadList::iterator wQuad = prismIt->myWallQuads[iW].begin();
916 for ( ; wQuad != prismIt->myWallQuads[iW].end(); ++ wQuad )
918 const TopoDS_Face& wFace = (*wQuad)->face;
919 TopTools_ListOfShape& solidList = faceToSolids.ChangeFromKey( wFace );
920 solidIt.Initialize( solidList );
921 while ( solidIt.More() )
923 const TopoDS_Shape& solid = solidIt.Value();
924 if ( meshedSolids.Contains( solid )) {
925 solidList.Remove( solidIt );
926 continue; // already computed prism
928 if ( myHelper->IsBlock( solid ))
930 bool isStructBase = true;
931 if ( prismIt->myAlgoSM )
932 isStructBase = ( myHelper->IsSameElemGeometry( prismIt->myAlgoSM->GetSubMeshDS(),
933 SMDSGeom_QUADRANGLE ) &&
934 myHelper->IsStructured(prismIt->myAlgoSM ));
938 continue; // too trivial
941 // find a source FACE of the SOLID: it's a FACE sharing a bottom EDGE with wFace
942 const TopoDS_Edge& wEdge = (*wQuad)->side[ QUAD_TOP_SIDE ].grid->Edge(0);
943 PShapeIteratorPtr faceIt = myHelper->GetAncestors( wEdge, *myHelper->GetMesh(),
945 while ( const TopoDS_Shape* f = faceIt->next() )
947 const TopoDS_Face& candidateF = TopoDS::Face( *f );
948 if ( candidateF.IsSame( wFace )) continue;
949 // select a source FACE: prismIt->myBottom or prismIt->myTop
950 TopoDS_Face sourceF = prismIt->myBottom;
951 for ( TopExp_Explorer v( prismIt->myTop, TopAbs_VERTEX ); v.More(); v.Next() )
952 if ( myHelper->IsSubShape( v.Current(), candidateF )) {
953 sourceF = prismIt->myTop;
957 prism.myBottom = candidateF;
958 prism.myAlgoSM = prismIt->myAlgoSM;
959 mySetErrorToSM = false;
960 if ( !myHelper->IsSubShape( candidateF, prismIt->myShape3D ) &&
961 myHelper ->IsSubShape( candidateF, solid ) &&
962 !myHelper->GetMesh()->GetSubMesh( candidateF )->IsMeshComputed() &&
963 initPrism( prism, solid, /*selectBottom=*/false ) &&
964 !myHelper->GetMesh()->GetSubMesh( prism.myTop )->IsMeshComputed() &&
965 !myHelper->GetMesh()->GetSubMesh( prism.myBottom )->IsMeshComputed() )
967 if ( project2dMesh( sourceF, prism.myBottom ))
969 mySetErrorToSM = true;
970 if ( !compute( prism ))
972 SMESHDS_SubMesh* smDS = theMesh.GetMeshDS()->MeshElements( prism.myTop );
973 if ( !myHelper->IsSameElemGeometry( smDS, SMDSGeom_QUADRANGLE ))
975 meshedFaces.push_front( prism.myTop );
976 meshedFaces.push_front( prism.myBottom );
977 selectBottom = false;
978 if ( prism.myAlgoSM && prism.myAlgoSM->GetAlgo() )
980 meshedFace2AlgoSM.Bind( prism.myTop, prism.myAlgoSM );
981 meshedFace2AlgoSM.Bind( prism.myBottom, prism.myAlgoSM );
984 meshedPrism.push_back( prism );
985 meshedSolids.Add( solid );
989 suspectSourceFaces.push_back( prism.myBottom );
990 if ( prism.myAlgoSM && prism.myAlgoSM->GetAlgo() )
991 meshedFace2AlgoSM.Bind( prism.myBottom, prism.myAlgoSM );
996 mySetErrorToSM = true;
998 if ( meshedSolids.Contains( solid ))
999 solidList.Remove( solidIt );
1005 if ( !meshedFaces.empty() )
1006 break; // to compute prisms with avident sources
1009 if ( meshedFaces.empty() )
1011 meshedFaces.splice( meshedFaces.end(), suspectSourceFaces );
1012 selectBottom = true;
1015 // find FACEs with local 1D hyps, which has to be computed by now,
1016 // or at least any computed FACEs
1017 if ( meshedFaces.empty() )
1019 int prevNbFaces = 0;
1020 for ( int iF = 1; iF <= faceToSolids.Extent(); ++iF )
1022 const TopoDS_Face& face = TopoDS::Face( faceToSolids.FindKey( iF ));
1023 const TopTools_ListOfShape& solidList = faceToSolids.FindFromKey( face );
1024 if ( solidList.IsEmpty() ) continue;
1025 SMESH_subMesh* faceSM = theMesh.GetSubMesh( face );
1026 if ( !faceSM->IsEmpty() )
1028 int nbFaces = faceSM->GetSubMeshDS()->NbElements();
1029 if ( prevNbFaces < nbFaces )
1031 if ( !meshedFaces.empty() ) meshedFaces.pop_back();
1032 meshedFaces.push_back( face ); // lower priority
1033 selectBottom = true;
1034 prevNbFaces = nbFaces;
1039 bool allSubMeComputed = true;
1040 SMESH_subMeshIteratorPtr smIt = faceSM->getDependsOnIterator(false,true);
1041 while ( smIt->more() && allSubMeComputed )
1042 allSubMeComputed = smIt->next()->IsMeshComputed();
1043 if ( allSubMeComputed )
1045 faceSM->ComputeStateEngine( SMESH_subMesh::COMPUTE_SUBMESH );
1046 if ( !faceSM->IsEmpty() ) {
1047 meshedFaces.push_front( face ); // higher priority
1048 selectBottom = true;
1052 faceSM->ComputeStateEngine( SMESH_subMesh::CHECK_COMPUTE_STATE );
1060 // TODO. there are other ways to find out the source FACE:
1061 // propagation, topological similarity, etc...
1063 // simply try to mesh all not meshed SOLIDs
1064 if ( meshedFaces.empty() )
1066 for ( TopExp_Explorer solid( theShape, TopAbs_SOLID ); solid.More(); solid.Next() )
1068 mySetErrorToSM = false;
1070 if ( !meshedSolids.Contains( solid.Current() ) &&
1071 initPrism( prism, solid.Current() ))
1073 mySetErrorToSM = true;
1074 if ( !compute( prism ))
1076 meshedFaces.push_front( prism.myTop );
1077 meshedFaces.push_front( prism.myBottom );
1078 meshedPrism.push_back( prism );
1079 meshedSolids.Add( solid.Current() );
1080 selectBottom = true;
1082 mySetErrorToSM = true;
1086 if ( meshedFaces.empty() ) // set same error to 10 not-computed solids
1088 SMESH_ComputeErrorPtr err = SMESH_ComputeError::New
1089 ( COMPERR_BAD_INPUT_MESH, "No meshed source face found", this );
1091 const int maxNbErrors = 10; // limit nb errors not to overload the Compute dialog
1092 TopExp_Explorer solid( theShape, TopAbs_SOLID );
1093 for ( int i = 0; ( i < maxNbErrors && solid.More() ); ++i, solid.Next() )
1094 if ( !meshedSolids.Contains( solid.Current() ))
1096 SMESH_subMesh* sm = theMesh.GetSubMesh( solid.Current() );
1097 sm->GetComputeError() = err;
1099 return error( err );
1102 return error( COMPERR_OK );
1105 //================================================================================
1107 * \brief Find wall faces by bottom edges
1109 //================================================================================
1111 bool StdMeshers_Prism_3D::getWallFaces( Prism_3D::TPrismTopo & thePrism,
1112 const int totalNbFaces)
1114 thePrism.myWallQuads.clear();
1116 SMESH_Mesh* mesh = myHelper->GetMesh();
1118 TQuadrangleAlgo* quadAlgo = TQuadrangleAlgo::instance( this, myHelper );
1120 TopTools_MapOfShape faceMap;
1121 TopTools_IndexedDataMapOfShapeListOfShape edgeToFaces;
1122 TopExp::MapShapesAndAncestors( thePrism.myShape3D,
1123 TopAbs_EDGE, TopAbs_FACE, edgeToFaces );
1125 // ------------------------------
1126 // Get the 1st row of wall FACEs
1127 // ------------------------------
1129 list< TopoDS_Edge >::iterator edge = thePrism.myBottomEdges.begin();
1130 std::list< int >::iterator nbE = thePrism.myNbEdgesInWires.begin();
1131 std::list< int > nbQuadsPerWire;
1132 int iE = 0, iWire = 0;
1133 while ( edge != thePrism.myBottomEdges.end() )
1136 if ( SMESH_Algo::isDegenerated( *edge ))
1138 edge = thePrism.myBottomEdges.erase( edge );
1144 bool hasWallFace = false;
1145 TopTools_ListIteratorOfListOfShape faceIt( edgeToFaces.FindFromKey( *edge ));
1146 for ( ; faceIt.More(); faceIt.Next() )
1148 const TopoDS_Face& face = TopoDS::Face( faceIt.Value() );
1149 if ( !thePrism.myBottom.IsSame( face ))
1152 Prism_3D::TQuadList quadList( 1, quadAlgo->CheckNbEdges( *mesh, face ));
1153 if ( !quadList.back() )
1154 return toSM( error(TCom("Side face #") << shapeID( face )
1155 << " not meshable with quadrangles"));
1156 bool isCompositeBase = ! setBottomEdge( *edge, quadList.back(), face );
1157 if ( isCompositeBase )
1159 // it's OK if all EDGEs of the bottom side belongs to the bottom FACE
1160 StdMeshers_FaceSidePtr botSide = quadList.back()->side[ QUAD_BOTTOM_SIDE ];
1161 for ( int iE = 0; iE < botSide->NbEdges(); ++iE )
1162 if ( !myHelper->IsSubShape( botSide->Edge(iE), thePrism.myBottom ))
1163 return toSM( error(TCom("Composite 'horizontal' edges are not supported")));
1165 if ( faceMap.Add( face ))
1167 setWireIndex( quadList.back(), iWire ); // for use in makeQuadsForOutInProjection()
1168 thePrism.myWallQuads.push_back( quadList );
1177 else // seam edge (IPAL53561)
1179 edge = thePrism.myBottomEdges.erase( edge );
1189 int nbQuadPrev = std::accumulate( nbQuadsPerWire.begin(), nbQuadsPerWire.end(), 0 );
1190 nbQuadsPerWire.push_back( thePrism.myWallQuads.size() - nbQuadPrev );
1194 // -------------------------
1195 // Find the rest wall FACEs
1196 // -------------------------
1198 // Compose a vector of indixes of right neighbour FACE for each wall FACE
1199 // that is not so evident in case of several WIREs in the bottom FACE
1200 thePrism.myRightQuadIndex.clear();
1201 for ( size_t i = 0; i < thePrism.myWallQuads.size(); ++i )
1203 thePrism.myRightQuadIndex.push_back( i+1 ); // OK for all but the last EDGE of a WIRE
1205 list< int >::iterator nbQinW = nbQuadsPerWire.begin();
1206 for ( int iLeft = 0; nbQinW != nbQuadsPerWire.end(); ++nbQinW )
1208 thePrism.myRightQuadIndex[ iLeft + *nbQinW - 1 ] = iLeft; // for the last EDGE of a WIRE
1212 while ( totalNbFaces - faceMap.Extent() > 2 )
1214 // find wall FACEs adjacent to each of wallQuads by the right side EDGE
1217 nbKnownFaces = faceMap.Extent();
1218 StdMeshers_FaceSidePtr rightSide, topSide; // sides of the quad
1219 for ( size_t i = 0; i < thePrism.myWallQuads.size(); ++i )
1221 rightSide = thePrism.myWallQuads[i].back()->side[ QUAD_RIGHT_SIDE ];
1222 for ( int iE = 0; iE < rightSide->NbEdges(); ++iE ) // rightSide can be composite
1224 const TopoDS_Edge & rightE = rightSide->Edge( iE );
1225 TopTools_ListIteratorOfListOfShape face( edgeToFaces.FindFromKey( rightE ));
1226 for ( ; face.More(); face.Next() )
1227 if ( faceMap.Add( face.Value() ))
1229 // a new wall FACE encountered, store it in thePrism.myWallQuads
1230 const int iRight = thePrism.myRightQuadIndex[i];
1231 topSide = thePrism.myWallQuads[ iRight ].back()->side[ QUAD_TOP_SIDE ];
1232 const TopoDS_Edge& newBotE = topSide->Edge(0);
1233 const TopoDS_Shape& newWallF = face.Value();
1234 thePrism.myWallQuads[ iRight ].push_back( quadAlgo->CheckNbEdges( *mesh, newWallF ));
1235 if ( !thePrism.myWallQuads[ iRight ].back() )
1236 return toSM( error(TCom("Side face #") << shapeID( newWallF ) <<
1237 " not meshable with quadrangles"));
1238 if ( ! setBottomEdge( newBotE, thePrism.myWallQuads[ iRight ].back(), newWallF ))
1239 return toSM( error(TCom("Composite 'horizontal' edges are not supported")));
1243 } while ( nbKnownFaces != faceMap.Extent() );
1245 // find wall FACEs adjacent to each of thePrism.myWallQuads by the top side EDGE
1246 if ( totalNbFaces - faceMap.Extent() > 2 )
1248 const int nbFoundWalls = faceMap.Extent();
1249 for ( size_t i = 0; i < thePrism.myWallQuads.size(); ++i )
1251 StdMeshers_FaceSidePtr topSide = thePrism.myWallQuads[i].back()->side[ QUAD_TOP_SIDE ];
1252 const TopoDS_Edge & topE = topSide->Edge( 0 );
1253 if ( topSide->NbEdges() > 1 )
1254 return toSM( error(COMPERR_BAD_SHAPE, TCom("Side face #") <<
1255 shapeID( thePrism.myWallQuads[i].back()->face )
1256 << " has a composite top edge"));
1257 TopTools_ListIteratorOfListOfShape faceIt( edgeToFaces.FindFromKey( topE ));
1258 for ( ; faceIt.More(); faceIt.Next() )
1259 if ( faceMap.Add( faceIt.Value() ))
1261 // a new wall FACE encountered, store it in wallQuads
1262 thePrism.myWallQuads[ i ].push_back( quadAlgo->CheckNbEdges( *mesh, faceIt.Value() ));
1263 if ( !thePrism.myWallQuads[ i ].back() )
1264 return toSM( error(TCom("Side face #") << shapeID( faceIt.Value() ) <<
1265 " not meshable with quadrangles"));
1266 if ( ! setBottomEdge( topE, thePrism.myWallQuads[ i ].back(), faceIt.Value() ))
1267 return toSM( error(TCom("Composite 'horizontal' edges are not supported")));
1268 if ( totalNbFaces - faceMap.Extent() == 2 )
1270 i = thePrism.myWallQuads.size(); // to quit from the outer loop
1275 if ( nbFoundWalls == faceMap.Extent() )
1276 return toSM( error("Failed to find wall faces"));
1279 } // while ( totalNbFaces - faceMap.Extent() > 2 )
1281 // ------------------
1282 // Find the top FACE
1283 // ------------------
1285 if ( thePrism.myTop.IsNull() )
1287 // now only top and bottom FACEs are not in the faceMap
1288 faceMap.Add( thePrism.myBottom );
1289 for ( TopExp_Explorer f( thePrism.myShape3D, TopAbs_FACE ); f.More(); f.Next() )
1290 if ( !faceMap.Contains( f.Current() )) {
1291 thePrism.myTop = TopoDS::Face( f.Current() );
1294 if ( thePrism.myTop.IsNull() )
1295 return toSM( error("Top face not found"));
1298 // Check that the top FACE shares all the top EDGEs
1299 for ( size_t i = 0; i < thePrism.myWallQuads.size(); ++i )
1301 StdMeshers_FaceSidePtr topSide = thePrism.myWallQuads[i].back()->side[ QUAD_TOP_SIDE ];
1302 const TopoDS_Edge & topE = topSide->Edge( 0 );
1303 if ( !myHelper->IsSubShape( topE, thePrism.myTop ))
1304 return toSM( error( TCom("Wrong source face: #") << shapeID( thePrism.myBottom )));
1310 //=======================================================================
1311 //function : compute
1312 //purpose : Compute mesh on a SOLID
1313 //=======================================================================
1315 bool StdMeshers_Prism_3D::compute(const Prism_3D::TPrismTopo& thePrism)
1317 myHelper->IsQuadraticSubMesh( thePrism.myShape3D );
1318 if ( _computeCanceled )
1319 return toSM( error( SMESH_ComputeError::New(COMPERR_CANCELED)));
1321 // Assure the bottom is meshed
1322 if ( !computeBase( thePrism ))
1325 // Make all side FACEs of thePrism meshed with quads
1326 if ( !computeWalls( thePrism ))
1329 // Analyse mesh and geometry to find all block sub-shapes and submeshes
1330 // (after fixing IPAL52499 myBlock is used as a holder of boundary nodes
1331 // and for 2D projection in hard cases where StdMeshers_Projection_2D fails;
1332 // location of internal nodes is usually computed by StdMeshers_Sweeper)
1333 if ( !myBlock.Init( myHelper, thePrism ))
1334 return toSM( error( myBlock.GetError()));
1336 SMESHDS_Mesh* meshDS = myHelper->GetMeshDS();
1338 int volumeID = meshDS->ShapeToIndex( thePrism.myShape3D );
1340 // Try to get gp_Trsf to get all nodes from bottom ones
1341 vector<gp_Trsf> trsf;
1342 gp_Trsf bottomToTopTrsf;
1343 // if ( !myBlock.GetLayersTransformation( trsf, thePrism ))
1345 // else if ( !trsf.empty() )
1346 // bottomToTopTrsf = trsf.back();
1348 // To compute coordinates of a node inside a block using "block approach",
1349 // it is necessary to know
1350 // 1. normalized parameters of the node by which
1351 // 2. coordinates of node projections on all block sub-shapes are computed
1353 // So we fill projections on vertices at once as they are same for all nodes
1354 myShapeXYZ.resize( myBlock.NbSubShapes() );
1355 for ( int iV = SMESH_Block::ID_FirstV; iV < SMESH_Block::ID_FirstE; ++iV ) {
1356 myBlock.VertexPoint( iV, myShapeXYZ[ iV ]);
1357 SHOWYXZ("V point " <<iV << " ", myShapeXYZ[ iV ]);
1360 // Projections on the top and bottom faces are taken from nodes existing
1361 // on these faces; find correspondence between bottom and top nodes
1362 myUseBlock = false; // is set to true if projection is done using "block approach"
1363 myBotToColumnMap.clear();
1364 if ( !assocOrProjBottom2Top( bottomToTopTrsf, thePrism ) ) // it also fills myBotToColumnMap
1367 // If all "vertical" EDGEs are straight, then all nodes of an internal node column
1368 // are located on a line connecting the top node and the bottom node.
1369 bool isStrightColunm = allVerticalEdgesStraight( thePrism );
1370 if ( isStrightColunm )
1373 // Create nodes inside the block
1377 // use transformation (issue 0020680, IPAL0052499) or a "straight line" approach
1378 StdMeshers_Sweeper sweeper;
1379 sweeper.myHelper = myHelper;
1380 sweeper.myBotFace = thePrism.myBottom;
1381 sweeper.myTopFace = thePrism.myTop;
1383 // load boundary nodes into sweeper
1385 std::set< const SMDS_MeshNode* > usedEndNodes;
1386 list< TopoDS_Edge >::const_iterator edge = thePrism.myBottomEdges.begin();
1387 for ( ; edge != thePrism.myBottomEdges.end(); ++edge )
1389 int edgeID = meshDS->ShapeToIndex( *edge );
1390 TParam2ColumnMap* u2col = const_cast<TParam2ColumnMap*>
1391 ( myBlock.GetParam2ColumnMap( edgeID, dummy ));
1393 TParam2ColumnMap::iterator u2colIt = u2col->begin(), u2colEnd = u2col->end();
1394 const SMDS_MeshNode* n0 = u2colIt->second[0];
1395 const SMDS_MeshNode* n1 = u2col->rbegin()->second[0];
1396 if ( !usedEndNodes.insert ( n0 ).second ) ++u2colIt;
1397 if ( !usedEndNodes.insert ( n1 ).second ) --u2colEnd;
1399 for ( ; u2colIt != u2colEnd; ++u2colIt )
1400 sweeper.myBndColumns.push_back( & u2colIt->second );
1402 // load node columns inside the bottom FACE
1403 sweeper.myIntColumns.reserve( myBotToColumnMap.size() );
1404 TNode2ColumnMap::iterator bot_column = myBotToColumnMap.begin();
1405 for ( ; bot_column != myBotToColumnMap.end(); ++bot_column )
1406 sweeper.myIntColumns.push_back( & bot_column->second );
1408 myHelper->SetElementsOnShape( true );
1410 if ( !isStrightColunm )
1412 double tol = getSweepTolerance( thePrism );
1413 bool allowHighBndError = !isSimpleBottom( thePrism );
1414 myUseBlock = !sweeper.ComputeNodesByTrsf( tol, allowHighBndError );
1416 else if ( sweeper.CheckSameZ() )
1418 myUseBlock = !sweeper.ComputeNodesOnStraightSameZ();
1422 myUseBlock = !sweeper.ComputeNodesOnStraight();
1424 myHelper->SetElementsOnShape( false );
1427 if ( myUseBlock ) // use block approach
1429 // loop on nodes inside the bottom face
1430 Prism_3D::TNode prevBNode;
1431 TNode2ColumnMap::iterator bot_column = myBotToColumnMap.begin();
1432 for ( ; bot_column != myBotToColumnMap.end(); ++bot_column )
1434 const Prism_3D::TNode& tBotNode = bot_column->first; // bottom TNode
1435 if ( tBotNode.GetPositionType() != SMDS_TOP_FACE &&
1436 myBlock.HasNodeColumn( tBotNode.myNode ))
1437 continue; // node is not inside the FACE
1439 // column nodes; middle part of the column are zero pointers
1440 TNodeColumn& column = bot_column->second;
1442 // check if a column is already computed using non-block approach
1444 for ( i = 0; i < column.size(); ++i )
1447 if ( i == column.size() )
1448 continue; // all nodes created
1450 gp_XYZ botParams, topParams;
1451 if ( !tBotNode.HasParams() )
1453 // compute bottom node parameters
1454 gp_XYZ paramHint(-1,-1,-1);
1455 if ( prevBNode.IsNeighbor( tBotNode ))
1456 paramHint = prevBNode.GetParams();
1457 if ( !myBlock.ComputeParameters( tBotNode.GetCoords(), tBotNode.ChangeParams(),
1458 ID_BOT_FACE, paramHint ))
1459 return toSM( error(TCom("Can't compute normalized parameters for node ")
1460 << tBotNode.myNode->GetID() << " on the face #"
1461 << myBlock.SubMesh( ID_BOT_FACE )->GetId() ));
1462 prevBNode = tBotNode;
1464 botParams = topParams = tBotNode.GetParams();
1465 topParams.SetZ( 1 );
1467 // compute top node parameters
1468 if ( column.size() > 2 ) {
1469 gp_Pnt topCoords = gpXYZ( column.back() );
1470 if ( !myBlock.ComputeParameters( topCoords, topParams, ID_TOP_FACE, topParams ))
1471 return toSM( error(TCom("Can't compute normalized parameters ")
1472 << "for node " << column.back()->GetID()
1473 << " on the face #"<< column.back()->getshapeId() ));
1476 else // top nodes are created by projection using parameters
1478 botParams = topParams = tBotNode.GetParams();
1479 topParams.SetZ( 1 );
1482 myShapeXYZ[ ID_BOT_FACE ] = tBotNode.GetCoords();
1483 myShapeXYZ[ ID_TOP_FACE ] = gpXYZ( column.back() );
1486 TNodeColumn::iterator columnNodes = column.begin();
1487 for ( int z = 0; columnNodes != column.end(); ++columnNodes, ++z)
1489 const SMDS_MeshNode* & node = *columnNodes;
1490 if ( node ) continue; // skip bottom or top node
1492 // params of a node to create
1493 double rz = (double) z / (double) ( column.size() - 1 );
1494 gp_XYZ params = botParams * ( 1 - rz ) + topParams * rz;
1496 // set coords on all faces and nodes
1497 const int nbSideFaces = 4;
1498 int sideFaceIDs[nbSideFaces] = { SMESH_Block::ID_Fx0z,
1499 SMESH_Block::ID_Fx1z,
1500 SMESH_Block::ID_F0yz,
1501 SMESH_Block::ID_F1yz };
1502 for ( int iF = 0; iF < nbSideFaces; ++iF )
1503 if ( !setFaceAndEdgesXYZ( sideFaceIDs[ iF ], params, z ))
1506 // compute coords for a new node
1508 if ( !SMESH_Block::ShellPoint( params, myShapeXYZ, coords ))
1509 return toSM( error("Can't compute coordinates by normalized parameters"));
1511 // if ( !meshDS->MeshElements( volumeID ) ||
1512 // meshDS->MeshElements( volumeID )->NbNodes() == 0 )
1513 // pointsToPython(myShapeXYZ);
1514 SHOWYXZ("TOPFacePoint ",myShapeXYZ[ ID_TOP_FACE]);
1515 SHOWYXZ("BOT Node "<< tBotNode.myNode->GetID(),gpXYZ(tBotNode.myNode));
1516 SHOWYXZ("ShellPoint ",coords);
1519 node = meshDS->AddNode( coords.X(), coords.Y(), coords.Z() );
1520 meshDS->SetNodeInVolume( node, volumeID );
1522 if ( _computeCanceled )
1525 } // loop on bottom nodes
1530 SMESHDS_SubMesh* smDS = myBlock.SubMeshDS( ID_BOT_FACE );
1531 if ( !smDS ) return toSM( error(COMPERR_BAD_INPUT_MESH, "Null submesh"));
1533 // loop on bottom mesh faces
1534 vector< const TNodeColumn* > columns;
1535 SMDS_ElemIteratorPtr faceIt = smDS->GetElements();
1536 while ( faceIt->more() )
1538 const SMDS_MeshElement* face = faceIt->next();
1539 if ( !face || face->GetType() != SMDSAbs_Face )
1542 // find node columns for each node
1543 int nbNodes = face->NbCornerNodes();
1544 columns.resize( nbNodes );
1545 for ( int i = 0; i < nbNodes; ++i )
1547 const SMDS_MeshNode* n = face->GetNode( i );
1548 columns[ i ] = NULL;
1550 if ( n->GetPosition()->GetTypeOfPosition() != SMDS_TOP_FACE )
1551 columns[ i ] = myBlock.GetNodeColumn( n );
1553 if ( !columns[ i ] )
1555 TNode2ColumnMap::iterator bot_column = myBotToColumnMap.find( n );
1556 if ( bot_column == myBotToColumnMap.end() )
1557 return toSM( error(TCom("No side nodes found above node ") << n->GetID() ));
1558 columns[ i ] = & bot_column->second;
1562 if ( !AddPrisms( columns, myHelper ))
1563 return toSM( error("Different 'vertical' discretization"));
1565 } // loop on bottom mesh faces
1568 myBotToColumnMap.clear();
1571 // update state of sub-meshes (mostly in order to erase improper errors)
1572 SMESH_subMesh* sm = myHelper->GetMesh()->GetSubMesh( thePrism.myShape3D );
1573 SMESH_subMeshIteratorPtr smIt = sm->getDependsOnIterator(/*includeSelf=*/true);
1574 while ( smIt->more() )
1577 sm->GetComputeError().reset();
1578 sm->ComputeStateEngine( SMESH_subMesh::CHECK_COMPUTE_STATE );
1584 //=======================================================================
1585 //function : computeBase
1586 //purpose : Compute the base face of a prism
1587 //=======================================================================
1589 bool StdMeshers_Prism_3D::computeBase(const Prism_3D::TPrismTopo& thePrism)
1591 SMESH_Mesh* mesh = myHelper->GetMesh();
1592 SMESH_subMesh* botSM = mesh->GetSubMesh( thePrism.myBottom );
1593 if (( botSM->IsEmpty() ) &&
1594 ( ! botSM->GetAlgo() ||
1595 ! _gen->Compute( *botSM->GetFather(), botSM->GetSubShape(), /*shapeOnly=*/true )))
1597 // find any applicable algorithm assigned to any FACE of the main shape
1598 std::vector< TopoDS_Shape > faces;
1599 if ( thePrism.myAlgoSM && thePrism.myAlgoSM->GetAlgo() )
1600 faces.push_back( thePrism.myAlgoSM->GetSubShape() );
1601 if ( myPrevBottomSM && myPrevBottomSM->GetAlgo() )
1602 faces.push_back( myPrevBottomSM->GetSubShape() );
1604 TopExp_Explorer faceIt( mesh->GetShapeToMesh(), TopAbs_FACE );
1605 for ( ; faceIt.More(); faceIt.Next() )
1606 faces.push_back( faceIt.Current() );
1608 faces.push_back( TopoDS_Shape() ); // to try quadrangle algorithm
1610 SMESH_Algo* algo = 0;
1611 for ( size_t i = 0; i < faces.size() && botSM->IsEmpty(); ++i )
1613 if ( faces[i].IsNull() ) algo = TQuadrangleAlgo::instance( this, myHelper );
1614 else algo = mesh->GetSubMesh( faces[i] )->GetAlgo();
1615 if ( algo && algo->IsApplicableToShape( thePrism.myBottom, /*all=*/false ))
1617 // try to compute the bottom FACE
1618 if ( algo->NeedDiscreteBoundary() )
1620 // compute sub-shapes
1621 SMESH_subMeshIteratorPtr smIt = botSM->getDependsOnIterator(false,false);
1623 while ( smIt->more() && subOK )
1625 SMESH_subMesh* sub = smIt->next();
1626 sub->ComputeStateEngine( SMESH_subMesh::COMPUTE_SUBMESH );
1627 subOK = sub->IsMeshComputed();
1635 Hypothesis_Status status;
1636 algo->CheckHypothesis( *mesh, faces[i], status );
1637 algo->InitComputeError();
1638 if ( algo->Compute( *mesh, botSM->GetSubShape() ))
1640 myPrevBottomSM = thePrism.myAlgoSM = mesh->GetSubMesh( faces[i] );
1651 myPrevBottomSM = thePrism.myAlgoSM = botSM;
1654 if ( botSM->IsEmpty() )
1655 return error( COMPERR_BAD_INPUT_MESH,
1656 TCom( "No mesher defined to compute the base face #")
1657 << shapeID( thePrism.myBottom ));
1662 //=======================================================================
1663 //function : computeWalls
1664 //purpose : Compute 2D mesh on walls FACEs of a prism
1665 //=======================================================================
1667 bool StdMeshers_Prism_3D::computeWalls(const Prism_3D::TPrismTopo& thePrism)
1669 SMESH_Mesh* mesh = myHelper->GetMesh();
1670 SMESHDS_Mesh* meshDS = myHelper->GetMeshDS();
1671 DBGOUT( endl << "COMPUTE Prism " << meshDS->ShapeToIndex( thePrism.myShape3D ));
1673 TProjction1dAlgo* projector1D = TProjction1dAlgo::instance( this );
1674 TQuadrangleAlgo* quadAlgo = TQuadrangleAlgo::instance( this, myHelper );
1676 // SMESH_HypoFilter hyp1dFilter( SMESH_HypoFilter::IsAlgo(),/*not=*/true);
1677 // hyp1dFilter.And( SMESH_HypoFilter::HasDim( 1 ));
1678 // hyp1dFilter.And( SMESH_HypoFilter::IsMoreLocalThan( thePrism.myShape3D, *mesh ));
1680 // Discretize equally 'vertical' EDGEs
1681 // -----------------------------------
1682 // find source FACE sides for projection: either already computed ones or
1683 // the 'most composite' ones
1684 const size_t nbWalls = thePrism.myWallQuads.size();
1685 vector< int > wgt( nbWalls, 0 ); // "weight" of a wall
1686 for ( size_t iW = 0; iW != nbWalls; ++iW )
1688 Prism_3D::TQuadList::const_iterator quad = thePrism.myWallQuads[iW].begin();
1689 for ( ; quad != thePrism.myWallQuads[iW].end(); ++quad )
1691 StdMeshers_FaceSidePtr lftSide = (*quad)->side[ QUAD_LEFT_SIDE ];
1692 lftSide->Reverse(); // to go up
1693 for ( int i = 0; i < lftSide->NbEdges(); ++i )
1696 const TopoDS_Edge& E = lftSide->Edge(i);
1697 if ( mesh->GetSubMesh( E )->IsMeshComputed() )
1700 wgt[ myHelper->WrapIndex( iW+1, nbWalls)] += 10;
1701 wgt[ myHelper->WrapIndex( iW-1, nbWalls)] += 10;
1703 // else if ( mesh->GetHypothesis( E, hyp1dFilter, true )) // local hypothesis!
1707 // in quadratic mesh, pass ignoreMediumNodes to quad sides
1708 if ( myHelper->GetIsQuadratic() )
1710 quad = thePrism.myWallQuads[iW].begin();
1711 for ( ; quad != thePrism.myWallQuads[iW].end(); ++quad )
1712 for ( int i = 0; i < NB_QUAD_SIDES; ++i )
1713 (*quad)->side[ i ].grid->SetIgnoreMediumNodes( true );
1716 multimap< int, int > wgt2quad;
1717 for ( size_t iW = 0; iW != nbWalls; ++iW )
1718 wgt2quad.insert( make_pair( wgt[ iW ], iW ));
1720 // artificial quads to do outer <-> inner wall projection
1721 std::map< int, FaceQuadStruct > iW2oiQuads;
1722 std::map< int, FaceQuadStruct >::iterator w2oiq;
1723 makeQuadsForOutInProjection( thePrism, wgt2quad, iW2oiQuads );
1725 // Project 'vertical' EDGEs, from left to right
1726 multimap< int, int >::reverse_iterator w2q = wgt2quad.rbegin();
1727 for ( ; w2q != wgt2quad.rend(); ++w2q )
1729 const int iW = w2q->second;
1730 const Prism_3D::TQuadList& quads = thePrism.myWallQuads[ iW ];
1731 Prism_3D::TQuadList::const_iterator quad = quads.begin();
1732 for ( ; quad != quads.end(); ++quad )
1734 StdMeshers_FaceSidePtr rgtSide = (*quad)->side[ QUAD_RIGHT_SIDE ]; // tgt
1735 StdMeshers_FaceSidePtr lftSide = (*quad)->side[ QUAD_LEFT_SIDE ]; // src
1736 bool swapLeftRight = ( lftSide->NbSegments( /*update=*/true ) == 0 &&
1737 rgtSide->NbSegments( /*update=*/true ) > 0 );
1738 if ( swapLeftRight )
1739 std::swap( lftSide, rgtSide );
1741 bool isArtificialQuad = (( w2oiq = iW2oiQuads.find( iW )) != iW2oiQuads.end() );
1742 if ( isArtificialQuad )
1744 // reset sides to perform the outer <-> inner projection
1745 FaceQuadStruct& oiQuad = w2oiq->second;
1746 rgtSide = oiQuad.side[ QUAD_RIGHT_SIDE ];
1747 lftSide = oiQuad.side[ QUAD_LEFT_SIDE ];
1748 iW2oiQuads.erase( w2oiq );
1751 // assure that all the source (left) EDGEs are meshed
1752 int nbSrcSegments = 0;
1753 for ( int i = 0; i < lftSide->NbEdges(); ++i )
1755 if ( isArtificialQuad )
1757 nbSrcSegments = lftSide->NbPoints()-1;
1760 const TopoDS_Edge& srcE = lftSide->Edge(i);
1761 SMESH_subMesh* srcSM = mesh->GetSubMesh( srcE );
1762 if ( !srcSM->IsMeshComputed() ) {
1763 DBGOUT( "COMPUTE V edge " << srcSM->GetId() );
1764 TopoDS_Edge prpgSrcE = findPropagationSource( srcE );
1765 if ( !prpgSrcE.IsNull() ) {
1766 srcSM->ComputeSubMeshStateEngine( SMESH_subMesh::COMPUTE );
1767 projector1D->myHyp.SetSourceEdge( prpgSrcE );
1768 projector1D->Compute( *mesh, srcE );
1769 srcSM->ComputeStateEngine( SMESH_subMesh::CHECK_COMPUTE_STATE );
1772 srcSM->ComputeSubMeshStateEngine( SMESH_subMesh::COMPUTE );
1773 srcSM->ComputeStateEngine ( SMESH_subMesh::COMPUTE );
1775 if ( !srcSM->IsMeshComputed() )
1776 return toSM( error( "Can't compute 1D mesh" ));
1778 nbSrcSegments += srcSM->GetSubMeshDS()->NbElements();
1780 // check target EDGEs
1781 int nbTgtMeshed = 0, nbTgtSegments = 0;
1782 vector< bool > isTgtEdgeComputed( rgtSide->NbEdges() );
1783 for ( int i = 0; i < rgtSide->NbEdges(); ++i )
1785 const TopoDS_Edge& tgtE = rgtSide->Edge(i);
1786 SMESH_subMesh* tgtSM = mesh->GetSubMesh( tgtE );
1787 if ( !( isTgtEdgeComputed[ i ] = tgtSM->IsMeshComputed() )) {
1788 tgtSM->ComputeSubMeshStateEngine( SMESH_subMesh::COMPUTE );
1789 tgtSM->ComputeStateEngine ( SMESH_subMesh::COMPUTE );
1791 if ( tgtSM->IsMeshComputed() ) {
1793 nbTgtSegments += tgtSM->GetSubMeshDS()->NbElements();
1796 if ( rgtSide->NbEdges() == nbTgtMeshed ) // all tgt EDGEs meshed
1798 if ( nbTgtSegments != nbSrcSegments )
1800 bool badMeshRemoved = false;
1801 // remove just computed segments
1802 for ( int i = 0; i < rgtSide->NbEdges(); ++i )
1803 if ( !isTgtEdgeComputed[ i ])
1805 const TopoDS_Edge& tgtE = rgtSide->Edge(i);
1806 SMESH_subMesh* tgtSM = mesh->GetSubMesh( tgtE );
1807 tgtSM->ComputeStateEngine( SMESH_subMesh::CLEAN );
1808 badMeshRemoved = true;
1811 if ( !badMeshRemoved )
1813 for ( int i = 0; i < lftSide->NbEdges(); ++i )
1814 addBadInputElements( meshDS->MeshElements( lftSide->Edge( i )));
1815 for ( int i = 0; i < rgtSide->NbEdges(); ++i )
1816 addBadInputElements( meshDS->MeshElements( rgtSide->Edge( i )));
1817 return toSM( error( TCom("Different nb of segment on logically vertical edges #")
1818 << shapeID( lftSide->Edge(0) ) << " and #"
1819 << shapeID( rgtSide->Edge(0) ) << ": "
1820 << nbSrcSegments << " != " << nbTgtSegments ));
1823 else // if ( nbTgtSegments == nbSrcSegments )
1828 // Compute 'vertical projection'
1829 if ( nbTgtMeshed == 0 )
1831 // compute nodes on target VERTEXes
1832 const UVPtStructVec& srcNodeStr = lftSide->GetUVPtStruct();
1833 if ( srcNodeStr.size() == 0 )
1834 return toSM( error( TCom("Invalid node positions on edge #") <<
1835 lftSide->EdgeID(0) ));
1836 vector< SMDS_MeshNode* > newNodes( srcNodeStr.size() );
1837 for ( int is2ndV = 0; is2ndV < 2; ++is2ndV )
1839 const TopoDS_Edge& E = rgtSide->Edge( is2ndV ? rgtSide->NbEdges()-1 : 0 );
1840 TopoDS_Vertex v = myHelper->IthVertex( is2ndV, E );
1841 mesh->GetSubMesh( v )->ComputeStateEngine( SMESH_subMesh::COMPUTE );
1842 const SMDS_MeshNode* n = SMESH_Algo::VertexNode( v, meshDS );
1843 newNodes[ is2ndV ? newNodes.size()-1 : 0 ] = (SMDS_MeshNode*) n;
1846 // compute nodes on target EDGEs
1847 DBGOUT( "COMPUTE V edge (proj) " << shapeID( lftSide->Edge(0)));
1848 //rgtSide->Reverse(); // direct it same as the lftSide
1849 myHelper->SetElementsOnShape( false ); // myHelper holds the prism shape
1850 TopoDS_Edge tgtEdge;
1851 for ( size_t iN = 1; iN < srcNodeStr.size()-1; ++iN ) // add nodes
1853 gp_Pnt p = rgtSide->Value3d ( srcNodeStr[ iN ].normParam );
1854 double u = rgtSide->Parameter( srcNodeStr[ iN ].normParam, tgtEdge );
1855 newNodes[ iN ] = meshDS->AddNode( p.X(), p.Y(), p.Z() );
1856 meshDS->SetNodeOnEdge( newNodes[ iN ], tgtEdge, u );
1858 for ( size_t iN = 1; iN < srcNodeStr.size(); ++iN ) // add segments
1860 // find an EDGE to set a new segment
1861 std::pair<int, TopAbs_ShapeEnum> id2type =
1862 myHelper->GetMediumPos( newNodes[ iN-1 ], newNodes[ iN ] );
1863 if ( id2type.second != TopAbs_EDGE )
1865 // new nodes are on different EDGEs; put one of them on VERTEX
1866 const int edgeIndex = rgtSide->EdgeIndex( srcNodeStr[ iN-1 ].normParam );
1867 const double vertexParam = rgtSide->LastParameter( edgeIndex );
1868 TopoDS_Vertex vertex = rgtSide->LastVertex( edgeIndex );
1869 const SMDS_MeshNode* vn = SMESH_Algo::VertexNode( vertex, meshDS );
1870 const gp_Pnt p = BRep_Tool::Pnt( vertex );
1871 const int isPrev = ( Abs( srcNodeStr[ iN-1 ].normParam - vertexParam ) <
1872 Abs( srcNodeStr[ iN ].normParam - vertexParam ));
1873 meshDS->UnSetNodeOnShape( newNodes[ iN-isPrev ] );
1874 meshDS->SetNodeOnVertex ( newNodes[ iN-isPrev ], vertex );
1875 meshDS->MoveNode ( newNodes[ iN-isPrev ], p.X(), p.Y(), p.Z() );
1876 id2type.first = newNodes[ iN-(1-isPrev) ]->getshapeId();
1879 SMESH_MeshEditor::TListOfListOfNodes lln( 1, list< const SMDS_MeshNode* >() );
1880 lln.back().push_back ( vn );
1881 lln.back().push_front( newNodes[ iN-isPrev ] ); // to keep
1882 SMESH_MeshEditor( mesh ).MergeNodes( lln );
1885 SMDS_MeshElement* newEdge = myHelper->AddEdge( newNodes[ iN-1 ], newNodes[ iN ] );
1886 meshDS->SetMeshElementOnShape( newEdge, id2type.first );
1888 myHelper->SetElementsOnShape( true );
1889 for ( int i = 0; i < rgtSide->NbEdges(); ++i ) // update state of sub-meshes
1891 const TopoDS_Edge& E = rgtSide->Edge( i );
1892 SMESH_subMesh* tgtSM = mesh->GetSubMesh( E );
1893 tgtSM->ComputeStateEngine( SMESH_subMesh::CHECK_COMPUTE_STATE );
1896 // to continue projection from the just computed side as a source
1897 if ( !swapLeftRight && rgtSide->NbEdges() > 1 && w2q->second == iW )
1899 std::pair<int,int> wgt2quadKeyVal( w2q->first + 1, thePrism.myRightQuadIndex[ iW ]);
1900 wgt2quad.insert( wgt2quadKeyVal ); // it will be skipped by ++w2q
1901 wgt2quad.insert( wgt2quadKeyVal );
1902 w2q = wgt2quad.rbegin();
1907 // HOPE assigned hypotheses are OK, so that equal nb of segments will be generated
1908 //return toSM( error("Partial projection not implemented"));
1910 } // loop on quads of a composite wall side
1911 } // loop on the ordered wall sides
1915 for ( size_t iW = 0; iW != thePrism.myWallQuads.size(); ++iW )
1917 Prism_3D::TQuadList::const_iterator quad = thePrism.myWallQuads[iW].begin();
1918 for ( ; quad != thePrism.myWallQuads[iW].end(); ++quad )
1920 const TopoDS_Face& face = (*quad)->face;
1921 SMESH_subMesh* fSM = mesh->GetSubMesh( face );
1922 if ( ! fSM->IsMeshComputed() )
1924 // Top EDGEs must be projections from the bottom ones
1925 // to compute structured quad mesh on wall FACEs
1926 // ---------------------------------------------------
1927 const TopoDS_Edge& botE = (*quad)->side[ QUAD_BOTTOM_SIDE ].grid->Edge(0);
1928 const TopoDS_Edge& topE = (*quad)->side[ QUAD_TOP_SIDE ].grid->Edge(0);
1929 SMESH_subMesh* botSM = mesh->GetSubMesh( botE );
1930 SMESH_subMesh* topSM = mesh->GetSubMesh( topE );
1931 SMESH_subMesh* srcSM = botSM;
1932 SMESH_subMesh* tgtSM = topSM;
1933 srcSM->ComputeStateEngine( SMESH_subMesh::CHECK_COMPUTE_STATE );
1934 tgtSM->ComputeStateEngine( SMESH_subMesh::CHECK_COMPUTE_STATE );
1935 if ( !srcSM->IsMeshComputed() && tgtSM->IsMeshComputed() )
1936 std::swap( srcSM, tgtSM );
1938 if ( !srcSM->IsMeshComputed() )
1940 DBGOUT( "COMPUTE H edge " << srcSM->GetId());
1941 srcSM->ComputeSubMeshStateEngine( SMESH_subMesh::COMPUTE ); // nodes on VERTEXes
1942 srcSM->ComputeStateEngine( SMESH_subMesh::COMPUTE ); // segments on the EDGE
1945 if ( tgtSM->IsMeshComputed() &&
1946 tgtSM->GetSubMeshDS()->NbNodes() != srcSM->GetSubMeshDS()->NbNodes() )
1948 // the top EDGE is computed differently than the bottom one,
1949 // try to clear a wrong mesh
1950 bool isAdjFaceMeshed = false;
1951 PShapeIteratorPtr fIt = myHelper->GetAncestors( tgtSM->GetSubShape(),
1952 *mesh, TopAbs_FACE );
1953 while ( const TopoDS_Shape* f = fIt->next() )
1954 if (( isAdjFaceMeshed = mesh->GetSubMesh( *f )->IsMeshComputed() ))
1956 if ( isAdjFaceMeshed )
1957 return toSM( error( TCom("Different nb of segment on logically horizontal edges #")
1958 << shapeID( botE ) << " and #"
1959 << shapeID( topE ) << ": "
1960 << tgtSM->GetSubMeshDS()->NbElements() << " != "
1961 << srcSM->GetSubMeshDS()->NbElements() ));
1962 tgtSM->ComputeStateEngine( SMESH_subMesh::CLEAN );
1964 if ( !tgtSM->IsMeshComputed() )
1966 // compute nodes on VERTEXes
1967 SMESH_subMeshIteratorPtr smIt = tgtSM->getDependsOnIterator(/*includeSelf=*/false);
1968 while ( smIt->more() )
1969 smIt->next()->ComputeStateEngine( SMESH_subMesh::COMPUTE );
1971 DBGOUT( "COMPUTE H edge (proj) " << tgtSM->GetId());
1972 projector1D->myHyp.SetSourceEdge( TopoDS::Edge( srcSM->GetSubShape() ));
1973 projector1D->InitComputeError();
1974 bool ok = projector1D->Compute( *mesh, tgtSM->GetSubShape() );
1977 SMESH_ComputeErrorPtr err = projector1D->GetComputeError();
1978 if ( err->IsOK() ) err->myName = COMPERR_ALGO_FAILED;
1979 tgtSM->GetComputeError() = err;
1983 tgtSM->ComputeStateEngine( SMESH_subMesh::CHECK_COMPUTE_STATE );
1986 // Compute quad mesh on wall FACEs
1987 // -------------------------------
1989 // make all EDGES meshed
1990 fSM->ComputeSubMeshStateEngine( SMESH_subMesh::COMPUTE );
1991 if ( !fSM->SubMeshesComputed() )
1992 return toSM( error( COMPERR_BAD_INPUT_MESH,
1993 "Not all edges have valid algorithm and hypothesis"));
1995 quadAlgo->InitComputeError();
1996 DBGOUT( "COMPUTE Quad face " << fSM->GetId());
1997 bool ok = quadAlgo->Compute( *mesh, face );
1998 fSM->GetComputeError() = quadAlgo->GetComputeError();
2001 fSM->ComputeStateEngine( SMESH_subMesh::CHECK_COMPUTE_STATE );
2003 if ( myHelper->GetIsQuadratic() )
2005 // fill myHelper with medium nodes built by quadAlgo
2006 for ( SMDS_ElemIteratorPtr fIt = fSM->GetSubMeshDS()->GetElements(); fIt->more(); )
2007 myHelper->AddTLinks( SMDS_Mesh::DownCast<SMDS_MeshFace>( fIt->next() ));
2015 //=======================================================================
2016 //function : findPropagationSource
2017 //purpose : Returns a source EDGE of propagation to a given EDGE
2018 //=======================================================================
2020 TopoDS_Edge StdMeshers_Prism_3D::findPropagationSource( const TopoDS_Edge& E )
2022 if ( myPropagChains )
2023 for ( size_t i = 0; !myPropagChains[i].IsEmpty(); ++i )
2024 if ( myPropagChains[i].Contains( E ))
2025 return TopoDS::Edge( myPropagChains[i].FindKey( 1 ));
2027 return TopoDS_Edge();
2030 //=======================================================================
2031 //function : makeQuadsForOutInProjection
2032 //purpose : Create artificial wall quads for vertical projection between
2033 // the outer and inner walls
2034 //=======================================================================
2036 void StdMeshers_Prism_3D::makeQuadsForOutInProjection( const Prism_3D::TPrismTopo& thePrism,
2037 multimap< int, int >& wgt2quad,
2038 map< int, FaceQuadStruct >& iQ2oiQuads)
2040 if ( thePrism.NbWires() <= 1 )
2043 std::set< int > doneWires; // processed wires
2045 SMESH_Mesh* mesh = myHelper->GetMesh();
2046 const bool isForward = true;
2047 const bool skipMedium = myHelper->GetIsQuadratic();
2049 // make a source side for all projections
2051 multimap< int, int >::reverse_iterator w2q = wgt2quad.rbegin();
2052 const int iQuad = w2q->second;
2053 const int iWire = getWireIndex( thePrism.myWallQuads[ iQuad ].front() );
2054 doneWires.insert( iWire );
2056 UVPtStructVec srcNodes;
2058 Prism_3D::TQuadList::const_iterator quad = thePrism.myWallQuads[ iQuad ].begin();
2059 for ( ; quad != thePrism.myWallQuads[ iQuad ].end(); ++quad )
2061 StdMeshers_FaceSidePtr lftSide = (*quad)->side[ QUAD_LEFT_SIDE ];
2063 // assure that all the source (left) EDGEs are meshed
2064 for ( int i = 0; i < lftSide->NbEdges(); ++i )
2066 const TopoDS_Edge& srcE = lftSide->Edge(i);
2067 SMESH_subMesh* srcSM = mesh->GetSubMesh( srcE );
2068 if ( !srcSM->IsMeshComputed() ) {
2069 srcSM->ComputeSubMeshStateEngine( SMESH_subMesh::COMPUTE );
2070 srcSM->ComputeStateEngine ( SMESH_subMesh::COMPUTE );
2072 if ( !srcSM->IsMeshComputed() )
2075 const UVPtStructVec& subNodes = lftSide->GetUVPtStruct();
2076 UVPtStructVec::const_iterator subBeg = subNodes.begin(), subEnd = subNodes.end();
2077 if ( !srcNodes.empty() ) ++subBeg;
2078 srcNodes.insert( srcNodes.end(), subBeg, subEnd );
2080 StdMeshers_FaceSidePtr srcSide = StdMeshers_FaceSide::New( srcNodes );
2084 list< TopoDS_Edge > sideEdges;
2086 for ( ++w2q; w2q != wgt2quad.rend(); ++w2q )
2088 const int iQuad = w2q->second;
2089 const Prism_3D::TQuadList& quads = thePrism.myWallQuads[ iQuad ];
2090 const int iWire = getWireIndex( quads.front() );
2091 if ( !doneWires.insert( iWire ).second )
2095 for ( quad = quads.begin(); quad != quads.end(); ++quad )
2097 StdMeshers_FaceSidePtr lftSide = (*quad)->side[ QUAD_LEFT_SIDE ];
2098 for ( int i = 0; i < lftSide->NbEdges(); ++i )
2099 sideEdges.push_back( lftSide->Edge( i ));
2100 face = lftSide->Face();
2102 StdMeshers_FaceSidePtr tgtSide =
2103 StdMeshers_FaceSide::New( face, sideEdges, mesh, isForward, skipMedium, myHelper );
2105 FaceQuadStruct& newQuad = iQ2oiQuads[ iQuad ];
2106 newQuad.side.resize( 4 );
2107 newQuad.side[ QUAD_LEFT_SIDE ] = srcSide;
2108 newQuad.side[ QUAD_RIGHT_SIDE ] = tgtSide;
2110 wgt2quad.insert( *w2q ); // to process this quad after processing the newQuad
2114 //=======================================================================
2115 //function : Evaluate
2117 //=======================================================================
2119 bool StdMeshers_Prism_3D::Evaluate(SMESH_Mesh& theMesh,
2120 const TopoDS_Shape& theShape,
2121 MapShapeNbElems& aResMap)
2123 if ( theShape.ShapeType() == TopAbs_COMPOUND )
2126 for ( TopoDS_Iterator it( theShape ); it.More(); it.Next() )
2127 ok &= Evaluate( theMesh, it.Value(), aResMap );
2130 SMESH_MesherHelper helper( theMesh );
2132 myHelper->SetSubShape( theShape );
2134 // find face contains only triangles
2135 vector < SMESH_subMesh * >meshFaces;
2136 TopTools_SequenceOfShape aFaces;
2137 int NumBase = 0, i = 0, NbQFs = 0;
2138 for (TopExp_Explorer exp(theShape, TopAbs_FACE); exp.More(); exp.Next()) {
2140 aFaces.Append(exp.Current());
2141 SMESH_subMesh *aSubMesh = theMesh.GetSubMesh(exp.Current());
2142 meshFaces.push_back(aSubMesh);
2143 MapShapeNbElemsItr anIt = aResMap.find(meshFaces[i-1]);
2144 if( anIt==aResMap.end() )
2145 return toSM( error( "Submesh can not be evaluated"));
2147 std::vector<int> aVec = (*anIt).second;
2148 int nbtri = Max(aVec[SMDSEntity_Triangle],aVec[SMDSEntity_Quad_Triangle]);
2149 int nbqua = Max(aVec[SMDSEntity_Quadrangle],aVec[SMDSEntity_Quad_Quadrangle]);
2150 if( nbtri==0 && nbqua>0 ) {
2159 std::vector<int> aResVec(SMDSEntity_Last);
2160 for(int i=SMDSEntity_Node; i<SMDSEntity_Last; i++) aResVec[i] = 0;
2161 SMESH_subMesh * sm = theMesh.GetSubMesh(theShape);
2162 aResMap.insert(std::make_pair(sm,aResVec));
2163 return toSM( error( "Submesh can not be evaluated" ));
2166 if(NumBase==0) NumBase = 1; // only quads => set 1 faces as base
2168 // find number of 1d elems for base face
2170 TopTools_MapOfShape Edges1;
2171 for (TopExp_Explorer exp(aFaces.Value(NumBase), TopAbs_EDGE); exp.More(); exp.Next()) {
2172 Edges1.Add(exp.Current());
2173 SMESH_subMesh *sm = theMesh.GetSubMesh(exp.Current());
2175 MapShapeNbElemsItr anIt = aResMap.find(sm);
2176 if( anIt == aResMap.end() ) continue;
2177 std::vector<int> aVec = (*anIt).second;
2178 nb1d += Max(aVec[SMDSEntity_Edge],aVec[SMDSEntity_Quad_Edge]);
2181 // find face opposite to base face
2183 for(i=1; i<=6; i++) {
2184 if(i==NumBase) continue;
2185 bool IsOpposite = true;
2186 for(TopExp_Explorer exp(aFaces.Value(i), TopAbs_EDGE); exp.More(); exp.Next()) {
2187 if( Edges1.Contains(exp.Current()) ) {
2197 // find number of 2d elems on side faces
2199 for(i=1; i<=6; i++) {
2200 if( i==OppNum || i==NumBase ) continue;
2201 MapShapeNbElemsItr anIt = aResMap.find( meshFaces[i-1] );
2202 if( anIt == aResMap.end() ) continue;
2203 std::vector<int> aVec = (*anIt).second;
2204 nb2d += Max(aVec[SMDSEntity_Quadrangle],aVec[SMDSEntity_Quad_Quadrangle]);
2207 MapShapeNbElemsItr anIt = aResMap.find( meshFaces[NumBase-1] );
2208 std::vector<int> aVec = (*anIt).second;
2209 bool IsQuadratic = (aVec[SMDSEntity_Quad_Triangle]>aVec[SMDSEntity_Triangle]) ||
2210 (aVec[SMDSEntity_Quad_Quadrangle]>aVec[SMDSEntity_Quadrangle]);
2211 int nb2d_face0_3 = Max(aVec[SMDSEntity_Triangle],aVec[SMDSEntity_Quad_Triangle]);
2212 int nb2d_face0_4 = Max(aVec[SMDSEntity_Quadrangle],aVec[SMDSEntity_Quad_Quadrangle]);
2213 int nb0d_face0 = aVec[SMDSEntity_Node];
2214 int nb1d_face0_int = ( nb2d_face0_3*3 + nb2d_face0_4*4 - nb1d ) / 2;
2216 std::vector<int> aResVec(SMDSEntity_Last);
2217 for(int i=SMDSEntity_Node; i<SMDSEntity_Last; i++) aResVec[i] = 0;
2219 aResVec[SMDSEntity_Quad_Penta] = nb2d_face0_3 * ( nb2d/nb1d );
2220 aResVec[SMDSEntity_Quad_Hexa] = nb2d_face0_4 * ( nb2d/nb1d );
2221 aResVec[SMDSEntity_Node] = nb0d_face0 * ( 2*nb2d/nb1d - 1 ) - nb1d_face0_int * nb2d/nb1d;
2224 aResVec[SMDSEntity_Node] = nb0d_face0 * ( nb2d/nb1d - 1 );
2225 aResVec[SMDSEntity_Penta] = nb2d_face0_3 * ( nb2d/nb1d );
2226 aResVec[SMDSEntity_Hexa] = nb2d_face0_4 * ( nb2d/nb1d );
2228 SMESH_subMesh * sm = theMesh.GetSubMesh(theShape);
2229 aResMap.insert(std::make_pair(sm,aResVec));
2234 //================================================================================
2236 * \brief Create prisms
2237 * \param columns - columns of nodes generated from nodes of a mesh face
2238 * \param helper - helper initialized by mesh and shape to add prisms to
2240 //================================================================================
2242 bool StdMeshers_Prism_3D::AddPrisms( vector<const TNodeColumn*> & columns,
2243 SMESH_MesherHelper* helper)
2245 size_t nbNodes = columns.size();
2246 size_t nbZ = columns[0]->size();
2247 if ( nbZ < 2 ) return false;
2248 for ( size_t i = 1; i < nbNodes; ++i )
2249 if ( columns[i]->size() != nbZ )
2252 // find out orientation
2253 bool isForward = true;
2254 SMDS_VolumeTool vTool;
2256 switch ( nbNodes ) {
2258 SMDS_VolumeOfNodes tmpPenta ( (*columns[0])[z-1], // bottom
2261 (*columns[0])[z], // top
2264 vTool.Set( &tmpPenta );
2265 isForward = vTool.IsForward();
2269 SMDS_VolumeOfNodes tmpHex( (*columns[0])[z-1], (*columns[1])[z-1], // bottom
2270 (*columns[2])[z-1], (*columns[3])[z-1],
2271 (*columns[0])[z], (*columns[1])[z], // top
2272 (*columns[2])[z], (*columns[3])[z] );
2273 vTool.Set( &tmpHex );
2274 isForward = vTool.IsForward();
2278 const int di = (nbNodes+1) / 3;
2279 SMDS_VolumeOfNodes tmpVol ( (*columns[0] )[z-1],
2280 (*columns[di] )[z-1],
2281 (*columns[2*di])[z-1],
2284 (*columns[2*di])[z] );
2285 vTool.Set( &tmpVol );
2286 isForward = vTool.IsForward();
2289 // vertical loop on columns
2291 helper->SetElementsOnShape( true );
2293 switch ( nbNodes ) {
2295 case 3: { // ---------- pentahedra
2296 const int i1 = isForward ? 1 : 2;
2297 const int i2 = isForward ? 2 : 1;
2298 for ( z = 1; z < nbZ; ++z )
2299 helper->AddVolume( (*columns[0 ])[z-1], // bottom
2300 (*columns[i1])[z-1],
2301 (*columns[i2])[z-1],
2302 (*columns[0 ])[z], // top
2304 (*columns[i2])[z] );
2307 case 4: { // ---------- hexahedra
2308 const int i1 = isForward ? 1 : 3;
2309 const int i3 = isForward ? 3 : 1;
2310 for ( z = 1; z < nbZ; ++z )
2311 helper->AddVolume( (*columns[0])[z-1], (*columns[i1])[z-1], // bottom
2312 (*columns[2])[z-1], (*columns[i3])[z-1],
2313 (*columns[0])[z], (*columns[i1])[z], // top
2314 (*columns[2])[z], (*columns[i3])[z] );
2317 case 6: { // ---------- octahedra
2318 const int iBase1 = isForward ? -1 : 0;
2319 const int iBase2 = isForward ? 0 :-1;
2320 for ( z = 1; z < nbZ; ++z )
2321 helper->AddVolume( (*columns[0])[z+iBase1], (*columns[1])[z+iBase1], // bottom or top
2322 (*columns[2])[z+iBase1], (*columns[3])[z+iBase1],
2323 (*columns[4])[z+iBase1], (*columns[5])[z+iBase1],
2324 (*columns[0])[z+iBase2], (*columns[1])[z+iBase2], // top or bottom
2325 (*columns[2])[z+iBase2], (*columns[3])[z+iBase2],
2326 (*columns[4])[z+iBase2], (*columns[5])[z+iBase2] );
2329 default: // ---------- polyhedra
2330 vector<int> quantities( 2 + nbNodes, 4 );
2331 quantities[0] = quantities[1] = nbNodes;
2332 columns.resize( nbNodes + 1 );
2333 columns[ nbNodes ] = columns[ 0 ];
2334 const int i1 = isForward ? 1 : 3;
2335 const int i3 = isForward ? 3 : 1;
2336 const int iBase1 = isForward ? -1 : 0;
2337 const int iBase2 = isForward ? 0 :-1;
2338 vector<const SMDS_MeshNode*> nodes( 2*nbNodes + 4*nbNodes);
2339 for ( z = 1; z < nbZ; ++z )
2341 for ( size_t i = 0; i < nbNodes; ++i ) {
2342 nodes[ i ] = (*columns[ i ])[z+iBase1]; // bottom or top
2343 nodes[ 2*nbNodes-i-1 ] = (*columns[ i ])[z+iBase2]; // top or bottom
2345 int di = 2*nbNodes + 4*i;
2346 nodes[ di+0 ] = (*columns[i ])[z ];
2347 nodes[ di+i1] = (*columns[i+1])[z ];
2348 nodes[ di+2 ] = (*columns[i+1])[z-1];
2349 nodes[ di+i3] = (*columns[i ])[z-1];
2351 helper->AddPolyhedralVolume( nodes, quantities );
2354 } // switch ( nbNodes )
2359 //================================================================================
2361 * \brief Find correspondence between bottom and top nodes
2362 * If elements on the bottom and top faces are topologically different,
2363 * and projection is possible and allowed, perform the projection
2364 * \retval bool - is a success or not
2366 //================================================================================
2368 bool StdMeshers_Prism_3D::assocOrProjBottom2Top( const gp_Trsf & bottomToTopTrsf,
2369 const Prism_3D::TPrismTopo& thePrism)
2371 SMESH_subMesh * botSM = myHelper->GetMesh()->GetSubMesh( thePrism.myBottom );
2372 SMESH_subMesh * topSM = myHelper->GetMesh()->GetSubMesh( thePrism.myTop );
2374 SMESHDS_SubMesh * botSMDS = botSM->GetSubMeshDS();
2375 SMESHDS_SubMesh * topSMDS = topSM->GetSubMeshDS();
2377 if ( !botSMDS || botSMDS->NbElements() == 0 )
2379 _gen->Compute( *myHelper->GetMesh(), botSM->GetSubShape(), /*aShapeOnly=*/true );
2380 botSMDS = botSM->GetSubMeshDS();
2381 if ( !botSMDS || botSMDS->NbElements() == 0 )
2382 return toSM( error(TCom("No elements on face #") << botSM->GetId() ));
2385 bool needProject = !topSM->IsMeshComputed();
2386 if ( !needProject &&
2387 (botSMDS->NbElements() != topSMDS->NbElements() ||
2388 botSMDS->NbNodes() != topSMDS->NbNodes()))
2390 MESSAGE("nb elem bot " << botSMDS->NbElements() <<
2391 " top " << ( topSMDS ? topSMDS->NbElements() : 0 ));
2392 MESSAGE("nb node bot " << botSMDS->NbNodes() <<
2393 " top " << ( topSMDS ? topSMDS->NbNodes() : 0 ));
2394 return toSM( error(TCom("Mesh on faces #") << botSM->GetId()
2395 <<" and #"<< topSM->GetId() << " seems different" ));
2398 if ( 0/*needProject && !myProjectTriangles*/ )
2399 return toSM( error(TCom("Mesh on faces #") << botSM->GetId()
2400 <<" and #"<< topSM->GetId() << " seems different" ));
2401 ///RETURN_BAD_RESULT("Need to project but not allowed");
2403 NSProjUtils::TNodeNodeMap n2nMap;
2404 const NSProjUtils::TNodeNodeMap* n2nMapPtr = & n2nMap;
2407 if ( !projectBottomToTop( bottomToTopTrsf, thePrism ))
2409 n2nMapPtr = & TProjction2dAlgo::instance( this )->GetNodesMap();
2412 if ( !n2nMapPtr || (int) n2nMapPtr->size() < botSMDS->NbNodes() )
2414 // associate top and bottom faces
2415 NSProjUtils::TShapeShapeMap shape2ShapeMap;
2416 const bool sameTopo =
2417 NSProjUtils::FindSubShapeAssociation( thePrism.myBottom, myHelper->GetMesh(),
2418 thePrism.myTop, myHelper->GetMesh(),
2421 for ( size_t iQ = 0; iQ < thePrism.myWallQuads.size(); ++iQ )
2423 const Prism_3D::TQuadList& quadList = thePrism.myWallQuads[iQ];
2424 StdMeshers_FaceSidePtr botSide = quadList.front()->side[ QUAD_BOTTOM_SIDE ];
2425 StdMeshers_FaceSidePtr topSide = quadList.back ()->side[ QUAD_TOP_SIDE ];
2426 if ( botSide->NbEdges() == topSide->NbEdges() )
2428 for ( int iE = 0; iE < botSide->NbEdges(); ++iE )
2430 NSProjUtils::InsertAssociation( botSide->Edge( iE ),
2431 topSide->Edge( iE ), shape2ShapeMap );
2432 NSProjUtils::InsertAssociation( myHelper->IthVertex( 0, botSide->Edge( iE )),
2433 myHelper->IthVertex( 0, topSide->Edge( iE )),
2439 TopoDS_Vertex vb, vt;
2440 StdMeshers_FaceSidePtr sideB, sideT;
2441 vb = myHelper->IthVertex( 0, botSide->Edge( 0 ));
2442 vt = myHelper->IthVertex( 0, topSide->Edge( 0 ));
2443 sideB = quadList.front()->side[ QUAD_LEFT_SIDE ];
2444 sideT = quadList.back ()->side[ QUAD_LEFT_SIDE ];
2445 if ( vb.IsSame( sideB->FirstVertex() ) &&
2446 vt.IsSame( sideT->LastVertex() ))
2448 NSProjUtils::InsertAssociation( botSide->Edge( 0 ),
2449 topSide->Edge( 0 ), shape2ShapeMap );
2450 NSProjUtils::InsertAssociation( vb, vt, shape2ShapeMap );
2452 vb = myHelper->IthVertex( 1, botSide->Edge( botSide->NbEdges()-1 ));
2453 vt = myHelper->IthVertex( 1, topSide->Edge( topSide->NbEdges()-1 ));
2454 sideB = quadList.front()->side[ QUAD_RIGHT_SIDE ];
2455 sideT = quadList.back ()->side[ QUAD_RIGHT_SIDE ];
2456 if ( vb.IsSame( sideB->FirstVertex() ) &&
2457 vt.IsSame( sideT->LastVertex() ))
2459 NSProjUtils::InsertAssociation( botSide->Edge( botSide->NbEdges()-1 ),
2460 topSide->Edge( topSide->NbEdges()-1 ),
2462 NSProjUtils::InsertAssociation( vb, vt, shape2ShapeMap );
2467 // Find matching nodes of top and bottom faces
2468 n2nMapPtr = & n2nMap;
2469 if ( ! NSProjUtils::FindMatchingNodesOnFaces( thePrism.myBottom, myHelper->GetMesh(),
2470 thePrism.myTop, myHelper->GetMesh(),
2471 shape2ShapeMap, n2nMap ))
2474 return toSM( error(TCom("Mesh on faces #") << botSM->GetId()
2475 <<" and #"<< topSM->GetId() << " seems different" ));
2477 return toSM( error(TCom("Topology of faces #") << botSM->GetId()
2478 <<" and #"<< topSM->GetId() << " seems different" ));
2482 // Fill myBotToColumnMap
2484 int zSize = myBlock.VerticalSize();
2485 TNodeNodeMap::const_iterator bN_tN = n2nMapPtr->begin();
2486 for ( ; bN_tN != n2nMapPtr->end(); ++bN_tN )
2488 const SMDS_MeshNode* botNode = bN_tN->first;
2489 const SMDS_MeshNode* topNode = bN_tN->second;
2490 if ( botNode->GetPosition()->GetTypeOfPosition() != SMDS_TOP_FACE &&
2491 myBlock.HasNodeColumn( botNode ))
2492 continue; // wall columns are contained in myBlock
2493 // create node column
2494 Prism_3D::TNode bN( botNode );
2495 TNode2ColumnMap::iterator bN_col =
2496 myBotToColumnMap.insert( make_pair ( bN, TNodeColumn() )).first;
2497 TNodeColumn & column = bN_col->second;
2498 column.resize( zSize, 0 );
2499 column.front() = botNode;
2500 column.back() = topNode;
2505 //================================================================================
2507 * \brief Remove faces from the top face and re-create them by projection from the bottom
2508 * \retval bool - a success or not
2510 //================================================================================
2512 bool StdMeshers_Prism_3D::projectBottomToTop( const gp_Trsf & bottomToTopTrsf,
2513 const Prism_3D::TPrismTopo& thePrism )
2515 if ( project2dMesh( thePrism.myBottom, thePrism.myTop ))
2519 NSProjUtils::TNodeNodeMap& n2nMap =
2520 (NSProjUtils::TNodeNodeMap&) TProjction2dAlgo::instance( this )->GetNodesMap();
2525 SMESHDS_Mesh* meshDS = myHelper->GetMeshDS();
2526 SMESH_subMesh * botSM = myHelper->GetMesh()->GetSubMesh( thePrism.myBottom );
2527 SMESH_subMesh * topSM = myHelper->GetMesh()->GetSubMesh( thePrism.myTop );
2529 SMESHDS_SubMesh * botSMDS = botSM->GetSubMeshDS();
2530 SMESHDS_SubMesh * topSMDS = topSM->GetSubMeshDS();
2532 if ( topSMDS && topSMDS->NbElements() > 0 )
2534 //topSM->ComputeStateEngine( SMESH_subMesh::CLEAN ); -- avoid propagation of events
2535 for ( SMDS_ElemIteratorPtr eIt = topSMDS->GetElements(); eIt->more(); )
2536 meshDS->RemoveFreeElement( eIt->next(), topSMDS, /*fromGroups=*/false );
2537 for ( SMDS_NodeIteratorPtr nIt = topSMDS->GetNodes(); nIt->more(); )
2538 meshDS->RemoveFreeNode( nIt->next(), topSMDS, /*fromGroups=*/false );
2541 const TopoDS_Face& botFace = thePrism.myBottom; // oriented within
2542 const TopoDS_Face& topFace = thePrism.myTop; // the 3D SHAPE
2543 int topFaceID = meshDS->ShapeToIndex( thePrism.myTop );
2545 SMESH_MesherHelper botHelper( *myHelper->GetMesh() );
2546 botHelper.SetSubShape( botFace );
2547 botHelper.ToFixNodeParameters( true );
2549 SMESH_MesherHelper topHelper( *myHelper->GetMesh() );
2550 topHelper.SetSubShape( topFace );
2551 topHelper.ToFixNodeParameters( true );
2552 double distXYZ[4], fixTol = 10 * topHelper.MaxTolerance( topFace );
2554 // Fill myBotToColumnMap
2556 int zSize = myBlock.VerticalSize();
2557 Prism_3D::TNode prevTNode;
2558 SMDS_NodeIteratorPtr nIt = botSMDS->GetNodes();
2559 while ( nIt->more() )
2561 const SMDS_MeshNode* botNode = nIt->next();
2562 const SMDS_MeshNode* topNode = 0;
2563 if ( botNode->GetPosition()->GetTypeOfPosition() != SMDS_TOP_FACE )
2564 continue; // strange
2566 Prism_3D::TNode bN( botNode );
2567 if ( bottomToTopTrsf.Form() == gp_Identity )
2569 // compute bottom node params
2570 gp_XYZ paramHint(-1,-1,-1);
2571 if ( prevTNode.IsNeighbor( bN ))
2573 paramHint = prevTNode.GetParams();
2574 // double tol = 1e-2 * ( prevTNode.GetCoords() - bN.GetCoords() ).Modulus();
2575 // myBlock.SetTolerance( Min( myBlock.GetTolerance(), tol ));
2577 if ( !myBlock.ComputeParameters( bN.GetCoords(), bN.ChangeParams(),
2578 ID_BOT_FACE, paramHint ))
2579 return toSM( error(TCom("Can't compute normalized parameters for node ")
2580 << botNode->GetID() << " on the face #"<< botSM->GetId() ));
2582 // compute top node coords
2583 gp_XYZ topXYZ; gp_XY topUV;
2584 if ( !myBlock.FacePoint( ID_TOP_FACE, bN.GetParams(), topXYZ ) ||
2585 !myBlock.FaceUV ( ID_TOP_FACE, bN.GetParams(), topUV ))
2586 return toSM( error(TCom("Can't compute coordinates "
2587 "by normalized parameters on the face #")<< topSM->GetId() ));
2588 topNode = meshDS->AddNode( topXYZ.X(),topXYZ.Y(),topXYZ.Z() );
2589 meshDS->SetNodeOnFace( topNode, topFaceID, topUV.X(), topUV.Y() );
2591 else // use bottomToTopTrsf
2593 gp_XYZ coords = bN.GetCoords();
2594 bottomToTopTrsf.Transforms( coords );
2595 topNode = meshDS->AddNode( coords.X(), coords.Y(), coords.Z() );
2596 gp_XY topUV = botHelper.GetNodeUV( botFace, botNode, 0, &checkUV );
2597 meshDS->SetNodeOnFace( topNode, topFaceID, topUV.X(), topUV.Y() );
2599 if ( topHelper.CheckNodeUV( topFace, topNode, topUV, fixTol, /*force=*/false, distXYZ ) &&
2600 distXYZ[0] > fixTol && distXYZ[0] < fixTol * 1e+3 )
2601 meshDS->MoveNode( topNode, distXYZ[1], distXYZ[2], distXYZ[3] ); // transform can be inaccurate
2603 // create node column
2604 TNode2ColumnMap::iterator bN_col =
2605 myBotToColumnMap.insert( make_pair ( bN, TNodeColumn() )).first;
2606 TNodeColumn & column = bN_col->second;
2607 column.resize( zSize );
2608 column.front() = botNode;
2609 column.back() = topNode;
2611 n2nMap.insert( n2nMap.end(), make_pair( botNode, topNode ));
2613 if ( _computeCanceled )
2614 return toSM( error( SMESH_ComputeError::New(COMPERR_CANCELED)));
2619 const bool oldSetElemsOnShape = myHelper->SetElementsOnShape( false );
2621 // care of orientation;
2622 // if the bottom faces is orienetd OK then top faces must be reversed
2623 bool reverseTop = true;
2624 if ( myHelper->NbAncestors( botFace, *myBlock.Mesh(), TopAbs_SOLID ) > 1 )
2625 reverseTop = ! myHelper->IsReversedSubMesh( botFace );
2626 int iFrw, iRev, *iPtr = &( reverseTop ? iRev : iFrw );
2628 // loop on bottom mesh faces
2629 SMDS_ElemIteratorPtr faceIt = botSMDS->GetElements();
2630 vector< const SMDS_MeshNode* > nodes;
2631 while ( faceIt->more() )
2633 const SMDS_MeshElement* face = faceIt->next();
2634 if ( !face || face->GetType() != SMDSAbs_Face )
2637 // find top node in columns for each bottom node
2638 int nbNodes = face->NbCornerNodes();
2639 nodes.resize( nbNodes );
2640 for ( iFrw = 0, iRev = nbNodes-1; iFrw < nbNodes; ++iFrw, --iRev )
2642 const SMDS_MeshNode* n = face->GetNode( *iPtr );
2643 if ( n->GetPosition()->GetTypeOfPosition() == SMDS_TOP_FACE ) {
2644 TNode2ColumnMap::iterator bot_column = myBotToColumnMap.find( n );
2645 if ( bot_column == myBotToColumnMap.end() )
2646 return toSM( error(TCom("No nodes found above node ") << n->GetID() ));
2647 nodes[ iFrw ] = bot_column->second.back();
2650 const TNodeColumn* column = myBlock.GetNodeColumn( n );
2652 return toSM( error(TCom("No side nodes found above node ") << n->GetID() ));
2653 nodes[ iFrw ] = column->back();
2656 SMDS_MeshElement* newFace = 0;
2657 switch ( nbNodes ) {
2660 newFace = myHelper->AddFace(nodes[0], nodes[1], nodes[2]);
2664 newFace = myHelper->AddFace( nodes[0], nodes[1], nodes[2], nodes[3] );
2668 newFace = meshDS->AddPolygonalFace( nodes );
2671 meshDS->SetMeshElementOnShape( newFace, topFaceID );
2674 myHelper->SetElementsOnShape( oldSetElemsOnShape );
2676 // Check the projected mesh
2678 if ( thePrism.NbWires() > 1 && // there are holes
2679 topHelper.IsDistorted2D( topSM, /*checkUV=*/false ))
2681 SMESH_MeshEditor editor( topHelper.GetMesh() );
2683 // smooth in 2D or 3D?
2684 TopLoc_Location loc;
2685 Handle(Geom_Surface) surface = BRep_Tool::Surface( topFace, loc );
2686 bool isPlanar = GeomLib_IsPlanarSurface( surface ).IsPlanar();
2688 set<const SMDS_MeshNode*> fixedNodes;
2689 TIDSortedElemSet faces;
2690 for ( faceIt = topSMDS->GetElements(); faceIt->more(); )
2691 faces.insert( faces.end(), faceIt->next() );
2694 for ( int isCentroidal = 0; isCentroidal < 2; ++isCentroidal )
2696 SMESH_MeshEditor::SmoothMethod algo =
2697 isCentroidal ? SMESH_MeshEditor::CENTROIDAL : SMESH_MeshEditor::LAPLACIAN;
2699 int nbAttempts = isCentroidal ? 1 : 10;
2700 for ( int iAttemp = 0; iAttemp < nbAttempts; ++iAttemp )
2702 TIDSortedElemSet workFaces = faces;
2705 editor.Smooth( workFaces, fixedNodes, algo, /*nbIterations=*/ 10,
2706 /*theTgtAspectRatio=*/1.0, /*the2D=*/!isPlanar);
2708 if (( isOk = !topHelper.IsDistorted2D( topSM, /*checkUV=*/true )) &&
2714 return toSM( error( TCom("Projection from face #") << botSM->GetId()
2715 << " to face #" << topSM->GetId()
2716 << " failed: inverted elements created"));
2719 TProjction2dAlgo::instance( this )->SetEventListener( topSM );
2724 //=======================================================================
2725 //function : getSweepTolerance
2726 //purpose : Compute tolerance to pass to StdMeshers_Sweeper
2727 //=======================================================================
2729 double StdMeshers_Prism_3D::getSweepTolerance( const Prism_3D::TPrismTopo& thePrism )
2731 SMESHDS_Mesh* meshDS = myHelper->GetMeshDS();
2732 SMESHDS_SubMesh * sm[2] = { meshDS->MeshElements( thePrism.myBottom ),
2733 meshDS->MeshElements( thePrism.myTop ) };
2734 double minDist = 1e100;
2736 vector< SMESH_TNodeXYZ > nodes;
2737 for ( int iSM = 0; iSM < 2; ++iSM )
2739 if ( !sm[ iSM ]) continue;
2741 SMDS_ElemIteratorPtr fIt = sm[ iSM ]->GetElements();
2742 while ( fIt->more() )
2744 const SMDS_MeshElement* face = fIt->next();
2745 const int nbNodes = face->NbCornerNodes();
2746 SMDS_ElemIteratorPtr nIt = face->nodesIterator();
2748 nodes.resize( nbNodes + 1 );
2749 for ( int iN = 0; iN < nbNodes; ++iN )
2750 nodes[ iN ] = nIt->next();
2751 nodes.back() = nodes[0];
2755 for ( int iN = 0; iN < nbNodes; ++iN )
2757 if ( nodes[ iN ]._node->GetPosition()->GetDim() < 2 &&
2758 nodes[ iN+1 ]._node->GetPosition()->GetDim() < 2 )
2760 // it's a boundary link; measure distance of other
2761 // nodes to this link
2762 gp_XYZ linkDir = nodes[ iN ] - nodes[ iN+1 ];
2763 double linkLen = linkDir.Modulus();
2764 bool isDegen = ( linkLen < numeric_limits<double>::min() );
2765 if ( !isDegen ) linkDir /= linkLen;
2766 for ( int iN2 = 0; iN2 < nbNodes; ++iN2 ) // loop on other nodes
2768 if ( nodes[ iN2 ] == nodes[ iN ] ||
2769 nodes[ iN2 ] == nodes[ iN+1 ]) continue;
2772 dist2 = ( nodes[ iN ] - nodes[ iN2 ]).SquareModulus();
2776 dist2 = linkDir.CrossSquareMagnitude( nodes[ iN ] - nodes[ iN2 ]);
2778 if ( dist2 > numeric_limits<double>::min() )
2779 minDist = Min ( minDist, dist2 );
2782 // measure length link
2783 else if ( nodes[ iN ]._node < nodes[ iN+1 ]._node ) // not to measure same link twice
2785 dist2 = ( nodes[ iN ] - nodes[ iN+1 ]).SquareModulus();
2786 if ( dist2 > numeric_limits<double>::min() )
2787 minDist = Min ( minDist, dist2 );
2792 return 0.1 * Sqrt ( minDist );
2795 //=======================================================================
2796 //function : isSimpleQuad
2797 //purpose : check if the bottom FACE is meshable with nice quadrangles,
2798 // if so the block approach can work rather fast.
2799 // This is a temporary mean caused by problems in StdMeshers_Sweeper
2800 //=======================================================================
2802 bool StdMeshers_Prism_3D::isSimpleBottom( const Prism_3D::TPrismTopo& thePrism )
2804 if ( thePrism.myNbEdgesInWires.front() != 4 )
2807 // analyse angles between edges
2808 double nbConcaveAng = 0, nbConvexAng = 0;
2809 TopoDS_Face reverseBottom = TopoDS::Face( thePrism.myBottom.Reversed() ); // see initPrism()
2810 TopoDS_Vertex commonV;
2811 const list< TopoDS_Edge >& botEdges = thePrism.myBottomEdges;
2812 list< TopoDS_Edge >::const_iterator edge = botEdges.begin();
2813 while ( edge != botEdges.end() )
2815 if ( SMESH_Algo::isDegenerated( *edge ))
2817 TopoDS_Edge e1 = *edge++;
2818 TopoDS_Edge e2 = ( edge == botEdges.end() ? botEdges.front() : *edge );
2819 if ( ! TopExp::CommonVertex( e1, e2, commonV ))
2821 e2 = botEdges.front();
2822 if ( ! TopExp::CommonVertex( e1, e2, commonV ))
2825 double angle = myHelper->GetAngle( e1, e2, reverseBottom, commonV );
2826 if ( angle < -5 * M_PI/180 )
2827 if ( ++nbConcaveAng > 1 )
2829 if ( angle > 85 * M_PI/180 )
2830 if ( ++nbConvexAng > 4 )
2836 //=======================================================================
2837 //function : allVerticalEdgesStraight
2838 //purpose : Defines if all "vertical" EDGEs are straight
2839 //=======================================================================
2841 bool StdMeshers_Prism_3D::allVerticalEdgesStraight( const Prism_3D::TPrismTopo& thePrism )
2843 for ( size_t i = 0; i < thePrism.myWallQuads.size(); ++i )
2845 const Prism_3D::TQuadList& quads = thePrism.myWallQuads[i];
2846 Prism_3D::TQuadList::const_iterator quadIt = quads.begin();
2847 TopoDS_Edge prevQuadEdge;
2848 for ( ; quadIt != quads.end(); ++quadIt )
2850 StdMeshers_FaceSidePtr rightSide = (*quadIt)->side[ QUAD_RIGHT_SIDE ];
2852 if ( !prevQuadEdge.IsNull() &&
2853 !SMESH_Algo::IsContinuous( rightSide->Edge( 0 ), prevQuadEdge ))
2856 for ( int iE = 0; iE < rightSide->NbEdges(); ++iE )
2858 const TopoDS_Edge & rightE = rightSide->Edge( iE );
2859 if ( !SMESH_Algo::IsStraight( rightE, /*degenResult=*/true ))
2863 !SMESH_Algo::IsContinuous( rightSide->Edge( iE-1 ), rightE ))
2866 prevQuadEdge = rightE;
2873 //=======================================================================
2874 //function : project2dMesh
2875 //purpose : Project mesh faces from a source FACE of one prism (theSrcFace)
2876 // to a source FACE of another prism (theTgtFace)
2877 //=======================================================================
2879 bool StdMeshers_Prism_3D::project2dMesh(const TopoDS_Face& theSrcFace,
2880 const TopoDS_Face& theTgtFace)
2882 if ( CountEdges( theSrcFace ) != CountEdges( theTgtFace ))
2885 TProjction2dAlgo* projector2D = TProjction2dAlgo::instance( this );
2886 projector2D->myHyp.SetSourceFace( theSrcFace );
2887 bool ok = projector2D->Compute( *myHelper->GetMesh(), theTgtFace );
2889 SMESH_subMesh* tgtSM = myHelper->GetMesh()->GetSubMesh( theTgtFace );
2890 if ( !ok && tgtSM->GetSubMeshDS() ) {
2891 //tgtSM->ComputeStateEngine( SMESH_subMesh::CLEAN ); -- avoid propagation of events
2892 SMESHDS_Mesh* meshDS = myHelper->GetMeshDS();
2893 SMESHDS_SubMesh* tgtSMDS = tgtSM->GetSubMeshDS();
2894 for ( SMDS_ElemIteratorPtr eIt = tgtSMDS->GetElements(); eIt->more(); )
2895 meshDS->RemoveFreeElement( eIt->next(), tgtSMDS, /*fromGroups=*/false );
2896 for ( SMDS_NodeIteratorPtr nIt = tgtSMDS->GetNodes(); nIt->more(); )
2897 meshDS->RemoveFreeNode( nIt->next(), tgtSMDS, /*fromGroups=*/false );
2899 tgtSM->ComputeStateEngine ( SMESH_subMesh::CHECK_COMPUTE_STATE );
2900 tgtSM->ComputeSubMeshStateEngine( SMESH_subMesh::CHECK_COMPUTE_STATE );
2902 projector2D->SetEventListener( tgtSM );
2907 //================================================================================
2909 * \brief Set projection coordinates of a node to a face and it's sub-shapes
2910 * \param faceID - the face given by in-block ID
2911 * \param params - node normalized parameters
2912 * \retval bool - is a success
2914 //================================================================================
2916 bool StdMeshers_Prism_3D::setFaceAndEdgesXYZ( const int faceID, const gp_XYZ& params, int /*z*/ )
2918 // find base and top edges of the face
2919 enum { BASE = 0, TOP, LEFT, RIGHT };
2920 vector< int > edgeVec; // 0-base, 1-top
2921 SMESH_Block::GetFaceEdgesIDs( faceID, edgeVec );
2923 myBlock.EdgePoint( edgeVec[ BASE ], params, myShapeXYZ[ edgeVec[ BASE ]]);
2924 myBlock.EdgePoint( edgeVec[ TOP ], params, myShapeXYZ[ edgeVec[ TOP ]]);
2926 SHOWYXZ("\nparams ", params);
2927 SHOWYXZ("TOP is " <<edgeVec[ TOP ], myShapeXYZ[ edgeVec[ TOP]]);
2928 SHOWYXZ("BASE is "<<edgeVec[ BASE], myShapeXYZ[ edgeVec[ BASE]]);
2930 if ( faceID == SMESH_Block::ID_Fx0z || faceID == SMESH_Block::ID_Fx1z )
2932 myBlock.EdgePoint( edgeVec[ LEFT ], params, myShapeXYZ[ edgeVec[ LEFT ]]);
2933 myBlock.EdgePoint( edgeVec[ RIGHT ], params, myShapeXYZ[ edgeVec[ RIGHT ]]);
2935 SHOWYXZ("VER "<<edgeVec[ LEFT], myShapeXYZ[ edgeVec[ LEFT]]);
2936 SHOWYXZ("VER "<<edgeVec[ RIGHT], myShapeXYZ[ edgeVec[ RIGHT]]);
2938 myBlock.FacePoint( faceID, params, myShapeXYZ[ faceID ]);
2939 SHOWYXZ("FacePoint "<<faceID, myShapeXYZ[ faceID]);
2944 //=======================================================================
2946 //purpose : If (!isOK), sets the error to a sub-mesh of a current SOLID
2947 //=======================================================================
2949 bool StdMeshers_Prism_3D::toSM( bool isOK )
2951 if ( mySetErrorToSM &&
2954 !myHelper->GetSubShape().IsNull() &&
2955 myHelper->GetSubShape().ShapeType() == TopAbs_SOLID)
2957 SMESH_subMesh* sm = myHelper->GetMesh()->GetSubMesh( myHelper->GetSubShape() );
2958 sm->GetComputeError() = this->GetComputeError();
2959 // clear error in order not to return it twice
2960 _error = COMPERR_OK;
2966 //=======================================================================
2967 //function : shapeID
2968 //purpose : Return index of a shape
2969 //=======================================================================
2971 int StdMeshers_Prism_3D::shapeID( const TopoDS_Shape& S )
2973 if ( S.IsNull() ) return 0;
2974 if ( !myHelper ) return -3;
2975 return myHelper->GetMeshDS()->ShapeToIndex( S );
2978 namespace // utils used by StdMeshers_Prism_3D::IsApplicable()
2980 struct EdgeWithNeighbors
2983 int _iBase; // index in a WIRE with non-base EDGEs excluded
2984 int _iL, _iR; // used to connect PrismSide's
2985 int _iE; // index in a WIRE
2986 int _iLE, _iRE; // used to connect EdgeWithNeighbors's
2987 bool _isBase; // is used in a base FACE
2988 TopoDS_Vertex _vv[2]; // end VERTEXes
2989 EdgeWithNeighbors(const TopoDS_Edge& E,
2990 int iE, int nbE, int shift,
2991 int iEE, int nbEE, int shiftE,
2992 bool isBase, bool setVV ):
2994 _iBase( iE + shift ),
2995 _iL ( SMESH_MesherHelper::WrapIndex( iE-1, Max( 1, nbE )) + shift ),
2996 _iR ( SMESH_MesherHelper::WrapIndex( iE+1, Max( 1, nbE )) + shift ),
2997 _iE ( iEE + shiftE ),
2998 _iLE( SMESH_MesherHelper::WrapIndex( iEE-1, Max( 1, nbEE )) + shiftE ),
2999 _iRE( SMESH_MesherHelper::WrapIndex( iEE+1, Max( 1, nbEE )) + shiftE ),
3008 EdgeWithNeighbors() {}
3009 bool IsInternal() const { return !_edge.IsNull() && _edge.Orientation() == TopAbs_INTERNAL; }
3010 bool IsConnected( const EdgeWithNeighbors& edge, int iEnd ) const
3012 return (( _vv[ iEnd ].IsSame( edge._vv[ 1 - iEnd ])) ||
3013 ( IsInternal() && _vv[ iEnd ].IsSame( edge._vv[ iEnd ])));
3015 bool IsConnected( const std::vector< EdgeWithNeighbors > & edges, int iEnd ) const
3017 int iEdge = iEnd ? _iRE : _iLE;
3018 return iEdge == _iE ? false : IsConnected( edges[ iEdge ], iEnd );
3020 const TopoDS_Vertex& Vertex( int iEnd )
3022 if ( _vv[ iEnd ].IsNull() )
3023 _vv[ iEnd ] = SMESH_MesherHelper::IthVertex( iEnd, _edge );
3027 // PrismSide contains all FACEs linking a bottom EDGE with a top one.
3030 TopoDS_Face _face; // a currently treated upper FACE
3031 TopTools_IndexedMapOfShape *_faces; // all FACEs (pointer because of a private copy constructor)
3032 TopoDS_Edge _topEdge; // a current top EDGE
3033 vector< EdgeWithNeighbors >*_edges; // all EDGEs of _face
3034 int _iBotEdge; // index of _topEdge within _edges
3035 vector< bool > _isCheckedEdge; // mark EDGEs whose two owner FACEs found
3036 int _nbCheckedEdges; // nb of EDGEs whose location is defined
3037 PrismSide *_leftSide; // neighbor sides
3038 PrismSide *_rightSide;
3039 bool _isInternal; // whether this side raises from an INTERNAL EDGE
3040 //void SetExcluded() { _leftSide = _rightSide = NULL; }
3041 //bool IsExcluded() const { return !_leftSide; }
3042 const TopoDS_Edge& Edge( int i ) const
3044 return (*_edges)[ i ]._edge;
3046 int FindEdge( const TopoDS_Edge& E ) const
3048 for ( size_t i = 0; i < _edges->size(); ++i )
3049 if ( E.IsSame( Edge( i ))) return i;
3052 const TopoDS_Vertex& Vertex( int iE, int iEnd ) const
3054 return (*_edges)[ iE ].Vertex( iEnd );
3056 bool HasVertex( const TopoDS_Vertex& V ) const
3058 for ( size_t i = 0; i < _edges->size(); ++i )
3059 if ( V.IsSame( Vertex( i, 0 ))) return true;
3062 bool IsSideFace( const TopTools_ListOfShape& faces,
3063 const TopoDS_Face& avoidFace,
3064 const bool checkNeighbors ) const
3066 TopTools_ListIteratorOfListOfShape faceIt( faces );
3067 for ( ; faceIt.More(); faceIt.Next() )
3069 const TopoDS_Shape& face = faceIt.Value();
3070 if ( !face.IsSame( avoidFace ))
3072 if ( _faces->Contains( face )) // avoid returning true for a prism top FACE
3073 return ( !_face.IsNull() || !( face.IsSame( _faces->FindKey( _faces->Extent() ))));
3076 if ( checkNeighbors )
3077 return (( _leftSide && _leftSide->IsSideFace ( faces, avoidFace, false )) ||
3078 ( _rightSide && _rightSide->IsSideFace( faces, avoidFace, false )));
3083 //--------------------------------------------------------------------------------
3085 * \brief Return another faces sharing an edge
3087 const TopoDS_Face & getAnotherFace( const TopoDS_Face& face,
3088 const TopTools_ListOfShape& faces)
3090 TopTools_ListIteratorOfListOfShape faceIt( faces );
3091 for ( ; faceIt.More(); faceIt.Next() )
3092 if ( !face.IsSame( faceIt.Value() ))
3093 return TopoDS::Face( faceIt.Value() );
3096 //--------------------------------------------------------------------------------
3098 * \brief Return another faces sharing an edge
3100 const TopoDS_Face & getAnotherFace( const TopoDS_Face& face,
3101 const TopoDS_Edge& edge,
3102 TopTools_IndexedDataMapOfShapeListOfShape& facesOfEdge)
3104 return getAnotherFace( face, facesOfEdge.FindFromKey( edge ));
3107 //--------------------------------------------------------------------------------
3109 * \brief Return ordered edges of a face
3111 //================================================================================
3113 * \brief Return ordered edges of a face
3114 * \param [in] face - the face
3115 * \param [out] edges - return edge (edges from which no vertical faces raise excluded)
3116 * \param [in] facesOfEdge - faces of each edge
3117 * \param [in] noHolesAllowed - are multiple wires allowed
3119 //================================================================================
3121 bool getEdges( const TopoDS_Face& face,
3122 vector< EdgeWithNeighbors > & edges,
3123 TopTools_IndexedDataMapOfShapeListOfShape& facesOfEdge,
3124 const bool noHolesAllowed)
3126 TopoDS_Face f = face;
3127 if ( f.Orientation() != TopAbs_FORWARD &&
3128 f.Orientation() != TopAbs_REVERSED )
3129 f.Orientation( TopAbs_FORWARD );
3130 list< TopoDS_Edge > ee;
3131 list< int > nbEdgesInWires;
3132 int nbW = SMESH_Block::GetOrderedEdges( f, ee, nbEdgesInWires );
3133 if ( nbW > 1 && noHolesAllowed )
3136 list< TopoDS_Edge >::iterator e = ee.begin();
3137 list< int >::iterator nbE = nbEdgesInWires.begin();
3138 for ( ; nbE != nbEdgesInWires.end(); ++nbE )
3139 for ( int iE = 0; iE < *nbE; ++e, ++iE )
3140 if ( SMESH_Algo::isDegenerated( *e )) // degenerated EDGE is never used
3142 e = --ee.erase( e );
3147 int iE, nbTot = 0, iBase, nbBase, nbTotBase = 0;
3151 for ( nbE = nbEdgesInWires.begin(); nbE != nbEdgesInWires.end(); ++nbE )
3154 isBase.resize( *nbE );
3155 list< TopoDS_Edge >::iterator eIt = e;
3156 for ( iE = 0; iE < *nbE; ++eIt, ++iE )
3158 isBase[ iE ] = ( getAnotherFace( face, *eIt, facesOfEdge ) != face );
3159 nbBase += isBase[ iE ];
3161 for ( iBase = 0, iE = 0; iE < *nbE; ++e, ++iE )
3163 edges.push_back( EdgeWithNeighbors( *e,
3164 iBase, nbBase, nbTotBase,
3166 isBase[ iE ], nbW > 1 ));
3167 iBase += isBase[ iE ];
3170 nbTotBase += nbBase;
3172 if ( nbTotBase == 0 )
3175 // IPAL53099, 54416. Set correct neighbors to INTERNAL EDGEs
3178 int iFirst = 0, iLast;
3179 for ( nbE = nbEdgesInWires.begin(); nbE != nbEdgesInWires.end(); ++nbE )
3181 iLast = iFirst + *nbE - 1;
3182 bool isConnectOk = ( edges[ iFirst ].IsConnected( edges, 0 ) &&
3183 edges[ iFirst ].IsConnected( edges, 1 ));
3186 for ( iE = iFirst; iE <= iLast; ++iE )
3188 if ( !edges[ iE ]._isBase )
3190 int* iNei[] = { & edges[ iE ]._iL,
3191 & edges[ iE ]._iR };
3192 for ( int iV = 0; iV < 2; ++iV )
3194 if ( edges[ iE ].IsConnected( edges, iV ))
3195 continue; // Ok - connected to a neighbor EDGE
3197 // look for a connected EDGE
3199 for ( int iE2 = 0, nbE = edges.size(); iE2 < nbE && !found; ++iE2 )
3200 if (( iE2 != iE ) &&
3201 ( found = edges[ iE ].IsConnected( edges[ iE2 ], iV )))
3203 *iNei[ iV ] = edges[ iE2 ]._iBase;
3206 *iNei[ iV ] = edges[ iE ]._iBase; // connect to self
3213 return edges.size();
3216 //--------------------------------------------------------------------------------
3218 * \brief Return number of faces sharing given edges
3220 // int nbAdjacentFaces( const std::vector< EdgeWithNeighbors >& edges,
3221 // const TopTools_IndexedDataMapOfShapeListOfShape& facesOfEdge )
3223 // TopTools_MapOfShape adjFaces;
3225 // for ( size_t i = 0; i < edges.size(); ++i )
3227 // TopTools_ListIteratorOfListOfShape faceIt( facesOfEdge.FindFromKey( edges[i]._edge ));
3228 // for ( ; faceIt.More(); faceIt.Next() )
3229 // adjFaces.Add( faceIt.Value() );
3231 // return adjFaces.Extent();
3235 //================================================================================
3237 * \brief Return true if the algorithm can mesh this shape
3238 * \param [in] aShape - shape to check
3239 * \param [in] toCheckAll - if true, this check returns OK if all shapes are OK,
3240 * else, returns OK if at least one shape is OK
3242 //================================================================================
3244 bool StdMeshers_Prism_3D::IsApplicable(const TopoDS_Shape & shape, bool toCheckAll)
3246 TopExp_Explorer sExp( shape, TopAbs_SOLID );
3250 for ( ; sExp.More(); sExp.Next() )
3254 TopExp_Explorer shExp( sExp.Current(), TopAbs_SHELL );
3255 while ( shExp.More() ) {
3256 shell = shExp.Current();
3258 if ( shExp.More() && BRep_Tool::IsClosed( shExp.Current() ))
3261 if ( shell.IsNull() ) {
3262 if ( toCheckAll ) return false;
3266 TopTools_IndexedMapOfShape allFaces;
3267 TopExp::MapShapes( sExp.Current(), TopAbs_FACE, allFaces );
3268 if ( allFaces.Extent() < 3 ) {
3269 if ( toCheckAll ) return false;
3273 if ( allFaces.Extent() == 6 )
3275 TopTools_IndexedMapOfOrientedShape map;
3276 bool isBox = SMESH_Block::FindBlockShapes( TopoDS::Shell( shell ),
3277 TopoDS_Vertex(), TopoDS_Vertex(), map );
3279 if ( !toCheckAll ) return true;
3284 TopTools_IndexedMapOfShape allShapes; // usage: allShapes.FindIndex( s )
3285 TopExp::MapShapes( shape, allShapes );
3288 TopTools_IndexedDataMapOfShapeListOfShape facesOfEdge;
3289 TopTools_ListIteratorOfListOfShape faceIt;
3290 TopExp::MapShapesAndAncestors( sExp.Current(), TopAbs_EDGE, TopAbs_FACE , facesOfEdge );
3291 if ( facesOfEdge.IsEmpty() ) {
3292 if ( toCheckAll ) return false;
3296 typedef vector< EdgeWithNeighbors > TEdgeWithNeighborsVec;
3297 vector< TEdgeWithNeighborsVec > faceEdgesVec( allFaces.Extent() + 1 );
3298 const size_t nbEdgesMax = facesOfEdge.Extent() * 2; // there can be seam EDGEs
3299 TopTools_IndexedMapOfShape* facesOfSide = new TopTools_IndexedMapOfShape[ nbEdgesMax ];
3300 SMESHUtils::ArrayDeleter<TopTools_IndexedMapOfShape> delFacesOfSide( facesOfSide );
3302 // try to use each face as a bottom one
3303 bool prismDetected = false;
3304 vector< PrismSide > sides;
3305 for ( int iF = 1; iF < allFaces.Extent() && !prismDetected; ++iF )
3307 const TopoDS_Face& botF = TopoDS::Face( allFaces( iF ));
3309 TEdgeWithNeighborsVec& botEdges = faceEdgesVec[ iF ];
3310 if ( botEdges.empty() )
3311 if ( !getEdges( botF, botEdges, facesOfEdge, /*noHoles=*/false ))
3315 for ( size_t iS = 0; iS < botEdges.size(); ++iS )
3316 nbBase += botEdges[ iS ]._isBase;
3318 if ( allFaces.Extent()-1 <= nbBase )
3319 continue; // all faces are adjacent to botF - no top FACE
3321 // init data of side FACEs
3323 sides.resize( nbBase );
3325 for ( size_t iE = 0; iE < botEdges.size(); ++iE )
3327 if ( !botEdges[ iE ]._isBase )
3329 sides[ iS ]._topEdge = botEdges[ iE ]._edge;
3330 sides[ iS ]._face = botF;
3331 sides[ iS ]._leftSide = & sides[ botEdges[ iE ]._iR ];
3332 sides[ iS ]._rightSide = & sides[ botEdges[ iE ]._iL ];
3333 sides[ iS ]._isInternal = botEdges[ iE ].IsInternal();
3334 sides[ iS ]._faces = & facesOfSide[ iS ];
3335 sides[ iS ]._faces->Clear();
3339 bool isOK = true; // ok for a current botF
3340 bool hasAdvanced = true; // is new data found in a current loop
3341 int nbFoundSideFaces = 0;
3342 for ( int iLoop = 0; isOK && hasAdvanced; ++iLoop )
3344 hasAdvanced = false;
3345 for ( size_t iS = 0; iS < sides.size() && isOK; ++iS )
3347 PrismSide& side = sides[ iS ];
3348 if ( side._face.IsNull() )
3349 continue; // probably the prism top face is the last of side._faces
3351 if ( side._topEdge.IsNull() )
3353 // find vertical EDGEs --- EDGEs shared with neighbor side FACEs
3354 for ( int is2nd = 0; is2nd < 2 && isOK; ++is2nd ) // 2 adjacent neighbors
3356 const PrismSide* adjSide = is2nd ? side._rightSide : side._leftSide;
3357 if ( side._isInternal )
3359 const TopoDS_Vertex& V = side.Vertex( side._iBotEdge, is2nd );
3360 bool lHasV = side._leftSide ->HasVertex( V );
3361 bool rHasV = side._rightSide->HasVertex( V );
3362 if ( lHasV == rHasV )
3363 adjSide = ( &side == side._leftSide ) ? side._rightSide : side._leftSide;
3365 adjSide = ( rHasV ) ? side._rightSide : side._leftSide;
3367 int di = is2nd ? 1 : -1;
3368 for ( size_t i = 1; i < side._edges->size(); ++i )
3370 int iE = SMESH_MesherHelper::WrapIndex( i*di + side._iBotEdge, side._edges->size());
3371 if ( side._isCheckedEdge[ iE ] ) continue;
3372 const TopoDS_Edge& vertE = side.Edge( iE );
3373 const TopTools_ListOfShape& neighborFF = facesOfEdge.FindFromKey( vertE );
3374 bool isEdgeShared = (( adjSide->IsSideFace( neighborFF, side._face,
3375 side._isInternal )) ||
3376 ( adjSide == &side &&
3377 side._face.IsSame( getAnotherFace( side._face,
3379 if ( isEdgeShared ) // vertE is shared with adjSide
3382 side._isCheckedEdge[ iE ] = true;
3383 side._nbCheckedEdges++;
3384 int nbNotCheckedE = side._edges->size() - side._nbCheckedEdges;
3385 if ( nbNotCheckedE == 1 )
3390 if ( i == 1 && iLoop == 0 ) isOK = false;
3396 int nbNotCheckedE = side._edges->size() - side._nbCheckedEdges;
3397 if ( nbNotCheckedE == 1 )
3399 vector<bool>::iterator ii = std::find( side._isCheckedEdge.begin(),
3400 side._isCheckedEdge.end(), false );
3401 if ( ii != side._isCheckedEdge.end() )
3403 size_t iE = std::distance( side._isCheckedEdge.begin(), ii );
3404 side._topEdge = side.Edge( iE );
3407 isOK = ( nbNotCheckedE >= 1 );
3409 else //if ( !side._topEdge.IsNull() )
3411 // get a next face of a side
3412 const TopoDS_Shape& f = getAnotherFace( side._face, side._topEdge, facesOfEdge );
3413 side._faces->Add( f );
3415 if ( f.IsSame( side._face ) || // _topEdge is a seam
3416 SMESH_MesherHelper::Count( f, TopAbs_WIRE, false ) != 1 )
3420 else if ( side._leftSide != & side && // not closed side face
3421 side._leftSide->_faces->Contains( f ))
3423 stop = true; // probably f is the prism top face
3424 side._leftSide->_face.Nullify();
3425 side._leftSide->_topEdge.Nullify();
3427 else if ( side._rightSide != & side &&
3428 side._rightSide->_faces->Contains( f ))
3430 stop = true; // probably f is the prism top face
3431 side._rightSide->_face.Nullify();
3432 side._rightSide->_topEdge.Nullify();
3436 side._face.Nullify();
3437 side._topEdge.Nullify();
3440 side._face = TopoDS::Face( f );
3441 int faceID = allFaces.FindIndex( side._face );
3442 side._edges = & faceEdgesVec[ faceID ];
3443 if ( side._edges->empty() )
3444 if ( !getEdges( side._face, * side._edges, facesOfEdge, /*noHoles=*/true ))
3446 const int nbE = side._edges->size();
3451 side._iBotEdge = side.FindEdge( side._topEdge );
3452 side._isCheckedEdge.clear();
3453 side._isCheckedEdge.resize( nbE, false );
3454 side._isCheckedEdge[ side._iBotEdge ] = true;
3455 side._nbCheckedEdges = 1; // bottom EDGE is known
3457 else // probably a triangular top face found
3459 side._face.Nullify();
3461 side._topEdge.Nullify();
3462 isOK = ( !side._edges->empty() || side._faces->Extent() > 1 );
3464 } //if ( !side._topEdge.IsNull() )
3466 } // loop on prism sides
3468 if ( nbFoundSideFaces > allFaces.Extent() )
3472 if ( iLoop > allFaces.Extent() * 10 )
3476 cerr << "BUG: infinite loop in StdMeshers_Prism_3D::IsApplicable()" << endl;
3479 } // while hasAdvanced
3481 if ( isOK && sides[0]._faces->Extent() > 1 )
3483 const int nbFaces = sides[0]._faces->Extent();
3484 if ( botEdges.size() == 1 ) // cylinder
3486 prismDetected = ( nbFaces == allFaces.Extent()-1 );
3490 // check that all face columns end up at the same top face
3491 const TopoDS_Shape& topFace = sides[0]._faces->FindKey( nbFaces );
3493 for ( iS = 1; iS < sides.size(); ++iS )
3494 if ( ! sides[ iS ]._faces->Contains( topFace ))
3496 if (( prismDetected = ( iS == sides.size() )))
3498 // check that bottom and top faces has equal nb of edges
3499 TEdgeWithNeighborsVec& topEdges = faceEdgesVec[ allFaces.FindIndex( topFace )];
3500 if ( topEdges.empty() )
3501 getEdges( TopoDS::Face( topFace ), topEdges, facesOfEdge, /*noHoles=*/false );
3502 prismDetected = ( botEdges.size() == topEdges.size() );
3506 } // loop on allFaces
3508 if ( !prismDetected && toCheckAll ) return false;
3509 if ( prismDetected && !toCheckAll ) return true;
3518 //================================================================================
3520 * \brief Return true if this node and other one belong to one face
3522 //================================================================================
3524 bool Prism_3D::TNode::IsNeighbor( const Prism_3D::TNode& other ) const
3526 if ( !other.myNode || !myNode ) return false;
3528 SMDS_ElemIteratorPtr fIt = other.myNode->GetInverseElementIterator(SMDSAbs_Face);
3529 while ( fIt->more() )
3530 if ( fIt->next()->GetNodeIndex( myNode ) >= 0 )
3535 //================================================================================
3537 * \brief Prism initialization
3539 //================================================================================
3541 void TPrismTopo::Clear()
3543 myShape3D.Nullify();
3546 myWallQuads.clear();
3547 myBottomEdges.clear();
3548 myNbEdgesInWires.clear();
3549 myWallQuads.clear();
3553 //================================================================================
3555 * \brief Set upside-down
3557 //================================================================================
3559 void TPrismTopo::SetUpsideDown()
3561 std::swap( myBottom, myTop );
3562 myBottomEdges.clear();
3563 std::reverse( myBottomEdges.begin(), myBottomEdges.end() );
3564 for ( size_t i = 0; i < myWallQuads.size(); ++i )
3566 myWallQuads[i].reverse();
3567 TQuadList::iterator q = myWallQuads[i].begin();
3568 for ( ; q != myWallQuads[i].end(); ++q )
3570 (*q)->shift( 2, /*keepUnitOri=*/true );
3572 myBottomEdges.push_back( myWallQuads[i].front()->side[ QUAD_BOTTOM_SIDE ].grid->Edge(0) );
3576 } // namespace Prism_3D
3578 //================================================================================
3580 * \brief Constructor. Initialization is needed
3582 //================================================================================
3584 StdMeshers_PrismAsBlock::StdMeshers_PrismAsBlock()
3589 StdMeshers_PrismAsBlock::~StdMeshers_PrismAsBlock()
3593 void StdMeshers_PrismAsBlock::Clear()
3596 myShapeIDMap.Clear();
3600 delete mySide; mySide = 0;
3602 myParam2ColumnMaps.clear();
3603 myShapeIndex2ColumnMap.clear();
3606 //=======================================================================
3607 //function : initPrism
3608 //purpose : Analyse shape geometry and mesh.
3609 // If there are triangles on one of faces, it becomes 'bottom'.
3610 // thePrism.myBottom can be already set up.
3611 //=======================================================================
3613 bool StdMeshers_Prism_3D::initPrism(Prism_3D::TPrismTopo& thePrism,
3614 const TopoDS_Shape& theShape3D,
3615 const bool selectBottom)
3617 myHelper->SetSubShape( theShape3D );
3619 SMESH_subMesh* mainSubMesh = myHelper->GetMesh()->GetSubMeshContaining( theShape3D );
3620 if ( !mainSubMesh ) return toSM( error(COMPERR_BAD_INPUT_MESH,"Null submesh of shape3D"));
3622 // detect not-quad FACE sub-meshes of the 3D SHAPE
3623 list< SMESH_subMesh* > notQuadGeomSubMesh;
3624 list< SMESH_subMesh* > notQuadElemSubMesh;
3625 list< SMESH_subMesh* > meshedSubMesh;
3628 SMESH_subMeshIteratorPtr smIt = mainSubMesh->getDependsOnIterator(false,true);
3629 while ( smIt->more() )
3631 SMESH_subMesh* sm = smIt->next();
3632 const TopoDS_Shape& face = sm->GetSubShape();
3633 if ( face.ShapeType() > TopAbs_FACE ) break;
3634 else if ( face.ShapeType() < TopAbs_FACE ) continue;
3637 // is quadrangle FACE?
3638 list< TopoDS_Edge > orderedEdges;
3639 list< int > nbEdgesInWires;
3640 int nbWires = SMESH_Block::GetOrderedEdges( TopoDS::Face( face ), orderedEdges,
3642 if ( nbWires != 1 || nbEdgesInWires.front() != 4 )
3643 notQuadGeomSubMesh.push_back( sm );
3645 // look for a not structured sub-mesh
3646 if ( !sm->IsEmpty() )
3648 meshedSubMesh.push_back( sm );
3649 if ( !myHelper->IsSameElemGeometry( sm->GetSubMeshDS(), SMDSGeom_QUADRANGLE ) ||
3650 !myHelper->IsStructured ( sm ))
3651 notQuadElemSubMesh.push_back( sm );
3655 int nbNotQuadMeshed = notQuadElemSubMesh.size();
3656 int nbNotQuad = notQuadGeomSubMesh.size();
3657 bool hasNotQuad = ( nbNotQuad || nbNotQuadMeshed );
3660 if ( nbNotQuadMeshed > 2 )
3662 return toSM( error(COMPERR_BAD_INPUT_MESH,
3663 TCom("More than 2 faces with not quadrangle elements: ")
3664 <<nbNotQuadMeshed));
3666 if ( nbNotQuad > 2 || !thePrism.myBottom.IsNull() )
3668 // Issue 0020843 - one of side FACEs is quasi-quadrilateral (not 4 EDGEs).
3669 // Remove from notQuadGeomSubMesh faces meshed with regular grid
3670 int nbQuasiQuads = removeQuasiQuads( notQuadGeomSubMesh, myHelper,
3671 TQuadrangleAlgo::instance(this,myHelper) );
3672 nbNotQuad -= nbQuasiQuads;
3673 if ( nbNotQuad > 2 )
3674 return toSM( error(COMPERR_BAD_SHAPE,
3675 TCom("More than 2 not quadrilateral faces: ") <<nbNotQuad));
3676 hasNotQuad = ( nbNotQuad || nbNotQuadMeshed );
3679 // Analyse mesh and topology of FACEs: choose the bottom sub-mesh.
3680 // If there are not quadrangle FACEs, they are top and bottom ones.
3681 // Not quadrangle FACEs must be only on top and bottom.
3683 SMESH_subMesh * botSM = 0;
3684 SMESH_subMesh * topSM = 0;
3686 if ( hasNotQuad ) // can choose a bottom FACE
3688 if ( nbNotQuadMeshed > 0 ) botSM = notQuadElemSubMesh.front();
3689 else botSM = notQuadGeomSubMesh.front();
3690 if ( nbNotQuadMeshed > 1 ) topSM = notQuadElemSubMesh.back();
3691 else if ( nbNotQuad > 1 ) topSM = notQuadGeomSubMesh.back();
3693 if ( topSM == botSM ) {
3694 if ( nbNotQuadMeshed > 1 ) topSM = notQuadElemSubMesh.front();
3695 else topSM = notQuadGeomSubMesh.front();
3698 // detect mesh triangles on wall FACEs
3699 if ( nbNotQuad == 2 && nbNotQuadMeshed > 0 ) {
3701 if ( nbNotQuadMeshed == 1 )
3702 ok = ( find( notQuadGeomSubMesh.begin(),
3703 notQuadGeomSubMesh.end(), botSM ) != notQuadGeomSubMesh.end() );
3705 ok = ( notQuadGeomSubMesh == notQuadElemSubMesh );
3707 return toSM( error(COMPERR_BAD_INPUT_MESH,
3708 "Side face meshed with not quadrangle elements"));
3712 thePrism.myNotQuadOnTop = ( nbNotQuadMeshed > 1 );
3714 // use thePrism.myBottom
3715 if ( !thePrism.myBottom.IsNull() )
3717 if ( botSM ) { // <-- not quad geom or mesh on botSM
3718 if ( ! botSM->GetSubShape().IsSame( thePrism.myBottom )) {
3719 std::swap( botSM, topSM );
3720 if ( !botSM || ! botSM->GetSubShape().IsSame( thePrism.myBottom )) {
3721 if ( !selectBottom )
3722 return toSM( error( COMPERR_BAD_INPUT_MESH,
3723 "Incompatible non-structured sub-meshes"));
3724 std::swap( botSM, topSM );
3725 thePrism.myBottom = TopoDS::Face( botSM->GetSubShape() );
3729 else if ( !selectBottom ) {
3730 botSM = myHelper->GetMesh()->GetSubMesh( thePrism.myBottom );
3733 if ( !botSM ) // find a proper bottom
3735 bool savedSetErrorToSM = mySetErrorToSM;
3736 mySetErrorToSM = false; // ignore errors in initPrism()
3738 // search among meshed FACEs
3739 list< SMESH_subMesh* >::iterator sm = meshedSubMesh.begin();
3740 for ( ; !botSM && sm != meshedSubMesh.end(); ++sm )
3744 thePrism.myBottom = TopoDS::Face( botSM->GetSubShape() );
3745 if ( !initPrism( thePrism, theShape3D, /*selectBottom=*/false ))
3748 // search among all FACEs
3749 for ( TopExp_Explorer f( theShape3D, TopAbs_FACE ); !botSM && f.More(); f.Next() )
3751 int minNbFaces = 2 + myHelper->Count( f.Current(), TopAbs_EDGE, false);
3752 if ( nbFaces < minNbFaces) continue;
3754 thePrism.myBottom = TopoDS::Face( f.Current() );
3755 botSM = myHelper->GetMesh()->GetSubMesh( thePrism.myBottom );
3756 if ( !initPrism( thePrism, theShape3D, /*selectBottom=*/false ))
3759 mySetErrorToSM = savedSetErrorToSM;
3760 return botSM ? true : toSM( error( COMPERR_BAD_SHAPE ));
3763 // find vertex 000 - the one with smallest coordinates (for easy DEBUG :-)
3765 double minVal = DBL_MAX, minX = 0, val;
3766 for ( TopExp_Explorer exp( botSM->GetSubShape(), TopAbs_VERTEX );
3767 exp.More(); exp.Next() )
3769 const TopoDS_Vertex& v = TopoDS::Vertex( exp.Current() );
3770 gp_Pnt P = BRep_Tool::Pnt( v );
3771 val = P.X() + P.Y() + P.Z();
3772 if ( val < minVal || ( val == minVal && P.X() < minX )) {
3779 thePrism.myShape3D = theShape3D;
3780 if ( thePrism.myBottom.IsNull() )
3781 thePrism.myBottom = TopoDS::Face( botSM->GetSubShape() );
3782 thePrism.myBottom.Orientation( myHelper->GetSubShapeOri( theShape3D, thePrism.myBottom ));
3783 thePrism.myTop. Orientation( myHelper->GetSubShapeOri( theShape3D, thePrism.myTop ));
3785 // Get ordered bottom edges
3786 TopoDS_Face reverseBottom = // to have order of top EDGEs as in the top FACE
3787 TopoDS::Face( thePrism.myBottom.Reversed() );
3788 SMESH_Block::GetOrderedEdges( reverseBottom,
3789 thePrism.myBottomEdges,
3790 thePrism.myNbEdgesInWires, V000 );
3792 // Get Wall faces corresponding to the ordered bottom edges and the top FACE
3793 if ( !getWallFaces( thePrism, nbFaces )) // it also sets thePrism.myTop
3794 return false; //toSM( error(COMPERR_BAD_SHAPE, "Can't find side faces"));
3798 if ( !thePrism.myTop.IsSame( topSM->GetSubShape() ))
3800 (notQuadGeomSubMesh.empty() ? COMPERR_BAD_INPUT_MESH : COMPERR_BAD_SHAPE,
3801 "Non-quadrilateral faces are not opposite"));
3803 // check that the found top and bottom FACEs are opposite
3804 TopTools_IndexedMapOfShape topEdgesMap( thePrism.myBottomEdges.size() );
3805 TopExp::MapShapes( thePrism.myTop, topEdgesMap );
3806 list< TopoDS_Edge >::iterator edge = thePrism.myBottomEdges.begin();
3807 for ( ; edge != thePrism.myBottomEdges.end(); ++edge )
3808 if ( topEdgesMap.Contains( *edge ))
3810 (notQuadGeomSubMesh.empty() ? COMPERR_BAD_INPUT_MESH : COMPERR_BAD_SHAPE,
3811 "Non-quadrilateral faces are not opposite"));
3814 if ( thePrism.myBottomEdges.size() > thePrism.myWallQuads.size() )
3816 // composite bottom sides => set thePrism upside-down
3817 thePrism.SetUpsideDown();
3823 //================================================================================
3825 * \brief Initialization.
3826 * \param helper - helper loaded with mesh and 3D shape
3827 * \param thePrism - a prism data
3828 * \retval bool - false if a mesh or a shape are KO
3830 //================================================================================
3832 bool StdMeshers_PrismAsBlock::Init(SMESH_MesherHelper* helper,
3833 const Prism_3D::TPrismTopo& thePrism)
3836 SMESHDS_Mesh* meshDS = myHelper->GetMeshDS();
3837 SMESH_Mesh* mesh = myHelper->GetMesh();
3840 delete mySide; mySide = 0;
3842 vector< TSideFace* > sideFaces( NB_WALL_FACES, 0 );
3843 vector< pair< double, double> > params( NB_WALL_FACES );
3844 mySide = new TSideFace( *mesh, sideFaces, params );
3847 SMESH_Block::init();
3848 myShapeIDMap.Clear();
3849 myShapeIndex2ColumnMap.clear();
3851 int wallFaceIds[ NB_WALL_FACES ] = { // to walk around a block
3852 SMESH_Block::ID_Fx0z, SMESH_Block::ID_F1yz,
3853 SMESH_Block::ID_Fx1z, SMESH_Block::ID_F0yz
3856 myError = SMESH_ComputeError::New();
3858 myNotQuadOnTop = thePrism.myNotQuadOnTop;
3860 // Find columns of wall nodes and calculate edges' lengths
3861 // --------------------------------------------------------
3863 myParam2ColumnMaps.clear();
3864 myParam2ColumnMaps.resize( thePrism.myBottomEdges.size() ); // total nb edges
3866 size_t iE, nbEdges = thePrism.myNbEdgesInWires.front(); // nb outer edges
3867 vector< double > edgeLength( nbEdges );
3868 multimap< double, int > len2edgeMap;
3870 // for each EDGE: either split into several parts, or join with several next EDGEs
3871 vector<int> nbSplitPerEdge( nbEdges, 0 );
3872 vector<int> nbUnitePerEdge( nbEdges, 0 ); // -1 means "joined to a previous"
3874 // consider continuous straight EDGEs as one side
3875 const int nbSides = countNbSides( thePrism, nbUnitePerEdge, edgeLength );
3877 list< TopoDS_Edge >::const_iterator edgeIt = thePrism.myBottomEdges.begin();
3878 for ( iE = 0; iE < nbEdges; ++iE, ++edgeIt )
3880 TParam2ColumnMap & faceColumns = myParam2ColumnMaps[ iE ];
3882 Prism_3D::TQuadList::const_iterator quad = thePrism.myWallQuads[ iE ].begin();
3883 for ( ; quad != thePrism.myWallQuads[ iE ].end(); ++quad )
3885 const TopoDS_Edge& quadBot = (*quad)->side[ QUAD_BOTTOM_SIDE ].grid->Edge( 0 );
3886 if ( !myHelper->LoadNodeColumns( faceColumns, (*quad)->face, quadBot, meshDS ))
3887 return error(COMPERR_BAD_INPUT_MESH, TCom("Can't find regular quadrangle mesh ")
3888 << "on a side face #" << MeshDS()->ShapeToIndex( (*quad)->face ));
3890 SHOWYXZ("\np1 F " <<iE, gpXYZ(faceColumns.begin()->second.front() ));
3891 SHOWYXZ("p2 F " <<iE, gpXYZ(faceColumns.rbegin()->second.front() ));
3892 SHOWYXZ("V First "<<iE, BRep_Tool::Pnt( TopExp::FirstVertex(*edgeIt,true )));
3894 if ( nbSides < NB_WALL_FACES ) // fill map used to split faces
3895 len2edgeMap.insert( make_pair( edgeLength[ iE ], iE )); // sort edges by length
3897 // Load columns of internal edges (forming holes)
3898 // and fill map ShapeIndex to TParam2ColumnMap for them
3899 for ( ; edgeIt != thePrism.myBottomEdges.end() ; ++edgeIt, ++iE )
3901 TParam2ColumnMap & faceColumns = myParam2ColumnMaps[ iE ];
3903 Prism_3D::TQuadList::const_iterator quad = thePrism.myWallQuads[ iE ].begin();
3904 for ( ; quad != thePrism.myWallQuads[ iE ].end(); ++quad )
3906 const TopoDS_Edge& quadBot = (*quad)->side[ QUAD_BOTTOM_SIDE ].grid->Edge( 0 );
3907 if ( !myHelper->LoadNodeColumns( faceColumns, (*quad)->face, quadBot, meshDS ))
3908 return error(COMPERR_BAD_INPUT_MESH, TCom("Can't find regular quadrangle mesh ")
3909 << "on a side face #" << MeshDS()->ShapeToIndex( (*quad)->face ));
3911 if ( !faceColumns.empty() && (int)faceColumns.begin()->second.size() != VerticalSize() )
3912 return error(COMPERR_BAD_INPUT_MESH, "Different 'vertical' discretization");
3915 int id = MeshDS()->ShapeToIndex( *edgeIt );
3916 bool isForward = true; // meaningless for intenal wires
3917 myShapeIndex2ColumnMap[ id ] = make_pair( & faceColumns, isForward );
3918 // columns for vertices
3920 const SMDS_MeshNode* n0 = faceColumns.begin()->second.front();
3921 id = n0->getshapeId();
3922 myShapeIndex2ColumnMap[ id ] = make_pair( & faceColumns, isForward );
3924 const SMDS_MeshNode* n1 = faceColumns.rbegin()->second.front();
3925 id = n1->getshapeId();
3926 myShapeIndex2ColumnMap[ id ] = make_pair( & faceColumns, isForward );
3928 // SHOWYXZ("\np1 F " <<iE, gpXYZ(faceColumns.begin()->second.front() ));
3929 // SHOWYXZ("p2 F " <<iE, gpXYZ(faceColumns.rbegin()->second.front() ));
3930 // SHOWYXZ("V First "<<iE, BRep_Tool::Pnt( TopExp::FirstVertex(*edgeIt,true )));
3933 // Create 4 wall faces of a block
3934 // -------------------------------
3936 if ( nbSides <= NB_WALL_FACES ) // ************* Split faces if necessary
3938 if ( nbSides != NB_WALL_FACES ) // define how to split
3940 if ( len2edgeMap.size() != nbEdges )
3941 RETURN_BAD_RESULT("Uniqueness of edge lengths not assured");
3943 multimap< double, int >::reverse_iterator maxLen_i = len2edgeMap.rbegin();
3944 multimap< double, int >::reverse_iterator midLen_i = ++len2edgeMap.rbegin();
3946 double maxLen = maxLen_i->first;
3947 double midLen = ( len2edgeMap.size() == 1 ) ? 0 : midLen_i->first;
3948 switch ( nbEdges ) {
3949 case 1: // 0-th edge is split into 4 parts
3950 nbSplitPerEdge[ 0 ] = 4;
3952 case 2: // either the longest edge is split into 3 parts, or both edges into halves
3953 if ( maxLen / 3 > midLen / 2 ) {
3954 nbSplitPerEdge[ maxLen_i->second ] = 3;
3957 nbSplitPerEdge[ maxLen_i->second ] = 2;
3958 nbSplitPerEdge[ midLen_i->second ] = 2;
3963 // split longest into 3 parts
3964 nbSplitPerEdge[ maxLen_i->second ] = 3;
3966 // split longest into halves
3967 nbSplitPerEdge[ maxLen_i->second ] = 2;
3971 else // **************************** Unite faces
3973 int nbExraFaces = nbSides - 4; // nb of faces to fuse
3974 for ( iE = 0; iE < nbEdges; ++iE )
3976 if ( nbUnitePerEdge[ iE ] < 0 )
3978 // look for already united faces
3979 for ( size_t i = iE; i < iE + nbExraFaces; ++i )
3981 if ( nbUnitePerEdge[ i ] > 0 ) // a side including nbUnitePerEdge[i]+1 edge
3982 nbExraFaces += nbUnitePerEdge[ i ];
3983 nbUnitePerEdge[ i ] = -1;
3985 nbUnitePerEdge[ iE ] = nbExraFaces;
3990 // Create TSideFace's
3992 list< TopoDS_Edge >::const_iterator botE = thePrism.myBottomEdges.begin();
3993 for ( iE = 0; iE < nbEdges; ++iE, ++botE )
3995 TFaceQuadStructPtr quad = thePrism.myWallQuads[ iE ].front();
3996 const int nbSplit = nbSplitPerEdge[ iE ];
3997 const int nbExraFaces = nbUnitePerEdge[ iE ] + 1;
3998 if ( nbSplit > 0 ) // split
4000 vector< double > params;
4001 splitParams( nbSplit, &myParam2ColumnMaps[ iE ], params );
4002 const bool isForward =
4003 StdMeshers_PrismAsBlock::IsForwardEdge( myHelper->GetMeshDS(),
4004 myParam2ColumnMaps[iE],
4005 *botE, SMESH_Block::ID_Fx0z );
4006 for ( int i = 0; i < nbSplit; ++i ) {
4007 double f = ( isForward ? params[ i ] : params[ nbSplit - i-1 ]);
4008 double l = ( isForward ? params[ i+1 ] : params[ nbSplit - i ]);
4009 TSideFace* comp = new TSideFace( *mesh, wallFaceIds[ iSide ],
4010 thePrism.myWallQuads[ iE ], *botE,
4011 &myParam2ColumnMaps[ iE ], f, l );
4012 mySide->SetComponent( iSide++, comp );
4015 else if ( nbExraFaces > 1 ) // unite
4017 double u0 = 0, sumLen = 0;
4018 for ( size_t i = iE; i < iE + nbExraFaces; ++i )
4019 sumLen += edgeLength[ i ];
4021 vector< TSideFace* > components( nbExraFaces );
4022 vector< pair< double, double> > params( nbExraFaces );
4023 bool endReached = false;
4024 for ( int i = 0; i < nbExraFaces; ++i, ++botE, ++iE )
4026 if ( iE == nbEdges )
4029 botE = thePrism.myBottomEdges.begin();
4032 components[ i ] = new TSideFace( *mesh, wallFaceIds[ iSide ],
4033 thePrism.myWallQuads[ iE ], *botE,
4034 &myParam2ColumnMaps[ iE ]);
4035 double u1 = u0 + edgeLength[ iE ] / sumLen;
4036 params[ i ] = make_pair( u0 , u1 );
4039 TSideFace* comp = new TSideFace( *mesh, components, params );
4040 mySide->SetComponent( iSide++, comp );
4043 --iE; // for increment in an external loop on iE
4046 else if ( nbExraFaces < 0 ) // skip already united face
4051 TSideFace* comp = new TSideFace( *mesh, wallFaceIds[ iSide ],
4052 thePrism.myWallQuads[ iE ], *botE,
4053 &myParam2ColumnMaps[ iE ]);
4054 mySide->SetComponent( iSide++, comp );
4059 // Fill geometry fields of SMESH_Block
4060 // ------------------------------------
4062 vector< int > botEdgeIdVec;
4063 SMESH_Block::GetFaceEdgesIDs( ID_BOT_FACE, botEdgeIdVec );
4065 bool isForward[NB_WALL_FACES] = { true, true, true, true };
4066 Adaptor2d_Curve2d* botPcurves[NB_WALL_FACES];
4067 Adaptor2d_Curve2d* topPcurves[NB_WALL_FACES];
4069 for ( int iF = 0; iF < NB_WALL_FACES; ++iF )
4071 TSideFace * sideFace = mySide->GetComponent( iF );
4073 RETURN_BAD_RESULT("NULL TSideFace");
4074 int fID = sideFace->FaceID(); // in-block ID
4076 // fill myShapeIDMap
4077 if ( sideFace->InsertSubShapes( myShapeIDMap ) != 8 &&
4078 !sideFace->IsComplex())
4079 MESSAGE( ": Warning : InsertSubShapes() < 8 on side " << iF );
4081 // side faces geometry
4082 Adaptor2d_Curve2d* pcurves[NB_WALL_FACES];
4083 if ( !sideFace->GetPCurves( pcurves ))
4084 RETURN_BAD_RESULT("TSideFace::GetPCurves() failed");
4086 SMESH_Block::TFace& tFace = myFace[ fID - ID_FirstF ];
4087 tFace.Set( fID, sideFace->Surface(), pcurves, isForward );
4089 SHOWYXZ( endl<<"F "<< iF << " id " << fID << " FRW " << sideFace->IsForward(), sideFace->Value(0,0));
4090 // edges 3D geometry
4091 vector< int > edgeIdVec;
4092 SMESH_Block::GetFaceEdgesIDs( fID, edgeIdVec );
4093 for ( int isMax = 0; isMax < 2; ++isMax ) {
4095 int eID = edgeIdVec[ isMax ];
4096 SMESH_Block::TEdge& tEdge = myEdge[ eID - ID_FirstE ];
4097 tEdge.Set( eID, sideFace->HorizCurve(isMax), true);
4098 SHOWYXZ(eID<<" HOR"<<isMax<<"(0)", sideFace->HorizCurve(isMax)->Value(0));
4099 SHOWYXZ(eID<<" HOR"<<isMax<<"(1)", sideFace->HorizCurve(isMax)->Value(1));
4102 int eID = edgeIdVec[ isMax+2 ];
4103 SMESH_Block::TEdge& tEdge = myEdge[ eID - ID_FirstE ];
4104 tEdge.Set( eID, sideFace->VertiCurve(isMax), true);
4105 SHOWYXZ(eID<<" VER"<<isMax<<"(0)", sideFace->VertiCurve(isMax)->Value(0));
4106 SHOWYXZ(eID<<" VER"<<isMax<<"(1)", sideFace->VertiCurve(isMax)->Value(1));
4109 vector< int > vertexIdVec;
4110 SMESH_Block::GetEdgeVertexIDs( eID, vertexIdVec );
4111 myPnt[ vertexIdVec[0] - ID_FirstV ] = tEdge.GetCurve()->Value(0).XYZ();
4112 myPnt[ vertexIdVec[1] - ID_FirstV ] = tEdge.GetCurve()->Value(1).XYZ();
4115 // pcurves on horizontal faces
4116 for ( iE = 0; iE < NB_WALL_FACES; ++iE ) {
4117 if ( edgeIdVec[ BOTTOM_EDGE ] == botEdgeIdVec[ iE ] ) {
4118 botPcurves[ iE ] = sideFace->HorizPCurve( false, thePrism.myBottom );
4119 topPcurves[ iE ] = sideFace->HorizPCurve( true, thePrism.myTop );
4123 //sideFace->dumpNodes( 4 ); // debug
4125 // horizontal faces geometry
4127 SMESH_Block::TFace& tFace = myFace[ ID_BOT_FACE - ID_FirstF ];
4128 tFace.Set( ID_BOT_FACE, new BRepAdaptor_Surface( thePrism.myBottom ), botPcurves, isForward );
4129 SMESH_Block::Insert( thePrism.myBottom, ID_BOT_FACE, myShapeIDMap );
4132 SMESH_Block::TFace& tFace = myFace[ ID_TOP_FACE - ID_FirstF ];
4133 tFace.Set( ID_TOP_FACE, new BRepAdaptor_Surface( thePrism.myTop ), topPcurves, isForward );
4134 SMESH_Block::Insert( thePrism.myTop, ID_TOP_FACE, myShapeIDMap );
4136 //faceGridToPythonDump( SMESH_Block::ID_Fxy0, 50 );
4137 //faceGridToPythonDump( SMESH_Block::ID_Fxy1 );
4139 // Fill map ShapeIndex to TParam2ColumnMap
4140 // ----------------------------------------
4142 list< TSideFace* > fList;
4143 list< TSideFace* >::iterator fListIt;
4144 fList.push_back( mySide );
4145 for ( fListIt = fList.begin(); fListIt != fList.end(); ++fListIt)
4147 int nb = (*fListIt)->NbComponents();
4148 for ( int i = 0; i < nb; ++i ) {
4149 if ( TSideFace* comp = (*fListIt)->GetComponent( i ))
4150 fList.push_back( comp );
4152 if ( TParam2ColumnMap* cols = (*fListIt)->GetColumns()) {
4153 // columns for a base edge
4154 int id = MeshDS()->ShapeToIndex( (*fListIt)->BaseEdge() );
4155 bool isForward = (*fListIt)->IsForward();
4156 myShapeIndex2ColumnMap[ id ] = make_pair( cols, isForward );
4158 // columns for vertices
4159 const SMDS_MeshNode* n0 = cols->begin()->second.front();
4160 id = n0->getshapeId();
4161 myShapeIndex2ColumnMap[ id ] = make_pair( cols, isForward );
4163 const SMDS_MeshNode* n1 = cols->rbegin()->second.front();
4164 id = n1->getshapeId();
4165 myShapeIndex2ColumnMap[ id ] = make_pair( cols, !isForward );
4169 // #define SHOWYXZ(msg, xyz) { gp_Pnt p(xyz); cout << msg << " ("<< p.X() << "; " <<p.Y() << "; " <<p.Z() << ") " <<endl; }
4171 // double _u[]={ 0.1, 0.1, 0.9, 0.9 };
4172 // double _v[]={ 0.1, 0.9, 0.1, 0.9 };
4173 // for ( int z = 0; z < 2; ++z )
4174 // for ( int i = 0; i < 4; ++i )
4176 // //gp_XYZ testPar(0.25, 0.25, 0), testCoord;
4177 // int iFace = (z ? ID_TOP_FACE : ID_BOT_FACE);
4178 // gp_XYZ testPar(_u[i], _v[i], z), testCoord;
4179 // if ( !FacePoint( iFace, testPar, testCoord ))
4180 // RETURN_BAD_RESULT("TEST FacePoint() FAILED");
4181 // SHOWYXZ("IN TEST PARAM" , testPar);
4182 // SHOWYXZ("OUT TEST CORD" , testCoord);
4183 // if ( !ComputeParameters( testCoord, testPar , iFace))
4184 // RETURN_BAD_RESULT("TEST ComputeParameters() FAILED");
4185 // SHOWYXZ("OUT TEST PARAM" , testPar);
4190 //================================================================================
4192 * \brief Return pointer to column of nodes
4193 * \param node - bottom node from which the returned column goes up
4194 * \retval const TNodeColumn* - the found column
4196 //================================================================================
4198 const TNodeColumn* StdMeshers_PrismAsBlock::GetNodeColumn(const SMDS_MeshNode* node) const
4200 int sID = node->getshapeId();
4202 map<int, pair< TParam2ColumnMap*, bool > >::const_iterator col_frw =
4203 myShapeIndex2ColumnMap.find( sID );
4204 if ( col_frw != myShapeIndex2ColumnMap.end() ) {
4205 const TParam2ColumnMap* cols = col_frw->second.first;
4206 TParam2ColumnIt u_col = cols->begin();
4207 for ( ; u_col != cols->end(); ++u_col )
4208 if ( u_col->second[ 0 ] == node )
4209 return & u_col->second;
4214 //=======================================================================
4215 //function : GetLayersTransformation
4216 //purpose : Return transformations to get coordinates of nodes of each layer
4217 // by nodes of the bottom. Layer is a set of nodes at a certain step
4218 // from bottom to top.
4219 // Transformation to get top node from bottom ones is computed
4220 // only if the top FACE is not meshed.
4221 //=======================================================================
4223 bool StdMeshers_PrismAsBlock::GetLayersTransformation(vector<gp_Trsf> & trsf,
4224 const Prism_3D::TPrismTopo& prism) const
4226 const bool itTopMeshed = !SubMesh( ID_BOT_FACE )->IsEmpty();
4227 const int zSize = VerticalSize();
4228 if ( zSize < 3 && !itTopMeshed ) return true;
4229 trsf.resize( zSize - 1 );
4231 // Select some node columns by which we will define coordinate system of layers
4233 vector< const TNodeColumn* > columns;
4236 list< TopoDS_Edge >::const_iterator edgeIt = prism.myBottomEdges.begin();
4237 for ( int iE = 0; iE < prism.myNbEdgesInWires.front(); ++iE, ++edgeIt )
4239 if ( SMESH_Algo::isDegenerated( *edgeIt )) continue;
4240 const TParam2ColumnMap* u2colMap =
4241 GetParam2ColumnMap( MeshDS()->ShapeToIndex( *edgeIt ), isReverse );
4242 if ( !u2colMap ) return false;
4243 double f = u2colMap->begin()->first, l = u2colMap->rbegin()->first;
4244 //isReverse = ( edgeIt->Orientation() == TopAbs_REVERSED );
4245 //if ( isReverse ) swap ( f, l ); -- u2colMap takes orientation into account
4246 const int nbCol = 5;
4247 for ( int i = 0; i < nbCol; ++i )
4249 double u = f + i/double(nbCol) * ( l - f );
4250 const TNodeColumn* col = & getColumn( u2colMap, u )->second;
4251 if ( columns.empty() || col != columns.back() )
4252 columns.push_back( col );
4257 // Find tolerance to check transformations
4262 for ( size_t i = 0; i < columns.size(); ++i )
4263 bndBox.Add( gpXYZ( columns[i]->front() ));
4264 tol2 = bndBox.SquareExtent() * 1e-5;
4267 // Compute transformations
4270 gp_Trsf fromCsZ, toCs0;
4271 gp_Ax3 cs0 = getLayerCoordSys(0, columns, xCol );
4272 //double dist0 = cs0.Location().Distance( gpXYZ( (*columns[0])[0]));
4273 toCs0.SetTransformation( cs0 );
4274 for ( int z = 1; z < zSize; ++z )
4276 gp_Ax3 csZ = getLayerCoordSys(z, columns, xCol );
4277 //double distZ = csZ.Location().Distance( gpXYZ( (*columns[0])[z]));
4278 fromCsZ.SetTransformation( csZ );
4280 gp_Trsf& t = trsf[ z-1 ];
4281 t = fromCsZ * toCs0;
4282 //t.SetScaleFactor( distZ/dist0 ); - it does not work properly, wrong base point
4284 // check a transformation
4285 for ( size_t i = 0; i < columns.size(); ++i )
4287 gp_Pnt p0 = gpXYZ( (*columns[i])[0] );
4288 gp_Pnt pz = gpXYZ( (*columns[i])[z] );
4289 t.Transforms( p0.ChangeCoord() );
4290 if ( p0.SquareDistance( pz ) > tol2 )
4293 return ( z == zSize - 1 ); // OK if fails only bottom->top trsf
4300 //================================================================================
4302 * \brief Check curve orientation of a bottom edge
4303 * \param meshDS - mesh DS
4304 * \param columnsMap - node columns map of side face
4305 * \param bottomEdge - the bottom edge
4306 * \param sideFaceID - side face in-block ID
4307 * \retval bool - true if orientation coincide with in-block forward orientation
4309 //================================================================================
4311 bool StdMeshers_PrismAsBlock::IsForwardEdge(SMESHDS_Mesh* meshDS,
4312 const TParam2ColumnMap& columnsMap,
4313 const TopoDS_Edge & bottomEdge,
4314 const int sideFaceID)
4316 bool isForward = false;
4317 if ( SMESH_MesherHelper::IsClosedEdge( bottomEdge ))
4319 isForward = ( bottomEdge.Orientation() == TopAbs_FORWARD );
4323 const TNodeColumn& firstCol = columnsMap.begin()->second;
4324 const SMDS_MeshNode* bottomNode = firstCol[0];
4325 TopoDS_Shape firstVertex = SMESH_MesherHelper::GetSubShapeByNode( bottomNode, meshDS );
4326 isForward = ( firstVertex.IsSame( TopExp::FirstVertex( bottomEdge, true )));
4328 // on 2 of 4 sides first vertex is end
4329 if ( sideFaceID == ID_Fx1z || sideFaceID == ID_F0yz )
4330 isForward = !isForward;
4334 //=======================================================================
4335 //function : faceGridToPythonDump
4336 //purpose : Prints a script creating a normal grid on the prism side
4337 //=======================================================================
4339 void StdMeshers_PrismAsBlock::faceGridToPythonDump(const SMESH_Block::TShapeID face,
4343 gp_XYZ pOnF[6] = { gp_XYZ(0,0,0), gp_XYZ(0,0,1),
4344 gp_XYZ(0,0,0), gp_XYZ(0,1,0),
4345 gp_XYZ(0,0,0), gp_XYZ(1,0,0) };
4347 cout << "mesh = smesh.Mesh( 'Face " << face << "')" << endl;
4348 SMESH_Block::TFace& f = myFace[ face - ID_FirstF ];
4349 gp_XYZ params = pOnF[ face - ID_FirstF ];
4350 //const int nb = 10; // nb face rows
4351 for ( int j = 0; j <= nb; ++j )
4353 params.SetCoord( f.GetVInd(), double( j )/ nb );
4354 for ( int i = 0; i <= nb; ++i )
4356 params.SetCoord( f.GetUInd(), double( i )/ nb );
4357 gp_XYZ p = f.Point( params );
4358 gp_XY uv = f.GetUV( params );
4359 cout << "mesh.AddNode( " << p.X() << ", " << p.Y() << ", " << p.Z() << " )"
4360 << " # " << 1 + i + j * ( nb + 1 )
4361 << " ( " << i << ", " << j << " ) "
4362 << " UV( " << uv.X() << ", " << uv.Y() << " )" << endl;
4363 ShellPoint( params, p2 );
4364 double dist = ( p2 - p ).Modulus();
4366 cout << "#### dist from ShellPoint " << dist
4367 << " (" << p2.X() << ", " << p2.Y() << ", " << p2.Z() << " ) " << endl;
4370 for ( int j = 0; j < nb; ++j )
4371 for ( int i = 0; i < nb; ++i )
4373 int n = 1 + i + j * ( nb + 1 );
4374 cout << "mesh.AddFace([ "
4375 << n << ", " << n+1 << ", "
4376 << n+nb+2 << ", " << n+nb+1 << "]) " << endl;
4379 (void)face; // unused in release mode
4380 (void)nb; // unused in release mode
4384 //================================================================================
4386 * \brief Constructor
4387 * \param faceID - in-block ID
4388 * \param face - geom FACE
4389 * \param baseEdge - EDGE proreply oriented in the bottom EDGE !!!
4390 * \param columnsMap - map of node columns
4391 * \param first - first normalized param
4392 * \param last - last normalized param
4394 //================================================================================
4396 StdMeshers_PrismAsBlock::TSideFace::TSideFace(SMESH_Mesh& mesh,
4398 const Prism_3D::TQuadList& quadList,
4399 const TopoDS_Edge& baseEdge,
4400 TParam2ColumnMap* columnsMap,
4404 myParamToColumnMap( columnsMap ),
4407 myParams.resize( 1 );
4408 myParams[ 0 ] = make_pair( first, last );
4409 mySurface = PSurface( new BRepAdaptor_Surface( quadList.front()->face ));
4410 myBaseEdge = baseEdge;
4411 myIsForward = StdMeshers_PrismAsBlock::IsForwardEdge( myHelper.GetMeshDS(),
4412 *myParamToColumnMap,
4414 myHelper.SetSubShape( quadList.front()->face );
4416 if ( quadList.size() > 1 ) // side is vertically composite
4418 // fill myShapeID2Surf map to enable finding a right surface by any sub-shape ID
4420 SMESHDS_Mesh* meshDS = myHelper.GetMeshDS();
4422 TopTools_IndexedDataMapOfShapeListOfShape subToFaces;
4423 Prism_3D::TQuadList::const_iterator quad = quadList.begin();
4424 for ( ; quad != quadList.end(); ++quad )
4426 const TopoDS_Face& face = (*quad)->face;
4427 TopExp::MapShapesAndAncestors( face, TopAbs_VERTEX, TopAbs_FACE, subToFaces );
4428 TopExp::MapShapesAndAncestors( face, TopAbs_EDGE, TopAbs_FACE, subToFaces );
4429 myShapeID2Surf.insert( make_pair( meshDS->ShapeToIndex( face ),
4430 PSurface( new BRepAdaptor_Surface( face ))));
4432 for ( int i = 1; i <= subToFaces.Extent(); ++i )
4434 const TopoDS_Shape& sub = subToFaces.FindKey( i );
4435 TopTools_ListOfShape& faces = subToFaces( i );
4436 int subID = meshDS->ShapeToIndex( sub );
4437 int faceID = meshDS->ShapeToIndex( faces.First() );
4438 myShapeID2Surf.insert ( make_pair( subID, myShapeID2Surf[ faceID ]));
4443 //================================================================================
4445 * \brief Constructor of a complex side face
4447 //================================================================================
4449 StdMeshers_PrismAsBlock::TSideFace::
4450 TSideFace(SMESH_Mesh& mesh,
4451 const vector< TSideFace* >& components,
4452 const vector< pair< double, double> > & params)
4453 :myID( components[0] ? components[0]->myID : 0 ),
4454 myParamToColumnMap( 0 ),
4456 myIsForward( true ),
4457 myComponents( components ),
4460 if ( myID == ID_Fx1z || myID == ID_F0yz )
4462 // reverse components
4463 std::reverse( myComponents.begin(), myComponents.end() );
4464 std::reverse( myParams.begin(), myParams.end() );
4465 for ( size_t i = 0; i < myParams.size(); ++i )
4467 const double f = myParams[i].first;
4468 const double l = myParams[i].second;
4469 myParams[i] = make_pair( 1. - l, 1. - f );
4473 //================================================================================
4475 * \brief Copy constructor
4476 * \param other - other side
4478 //================================================================================
4480 StdMeshers_PrismAsBlock::TSideFace::TSideFace( const TSideFace& other ):
4481 myID ( other.myID ),
4482 myParamToColumnMap ( other.myParamToColumnMap ),
4483 mySurface ( other.mySurface ),
4484 myBaseEdge ( other.myBaseEdge ),
4485 myShapeID2Surf ( other.myShapeID2Surf ),
4486 myParams ( other.myParams ),
4487 myIsForward ( other.myIsForward ),
4488 myComponents ( other.myComponents.size() ),
4489 myHelper ( *other.myHelper.GetMesh() )
4491 for ( size_t i = 0 ; i < myComponents.size(); ++i )
4492 myComponents[ i ] = new TSideFace( *other.myComponents[ i ]);
4495 //================================================================================
4497 * \brief Deletes myComponents
4499 //================================================================================
4501 StdMeshers_PrismAsBlock::TSideFace::~TSideFace()
4503 for ( size_t i = 0 ; i < myComponents.size(); ++i )
4504 if ( myComponents[ i ] )
4505 delete myComponents[ i ];
4508 //================================================================================
4510 * \brief Return geometry of the vertical curve
4511 * \param isMax - true means curve located closer to (1,1,1) block point
4512 * \retval Adaptor3d_Curve* - curve adaptor
4514 //================================================================================
4516 Adaptor3d_Curve* StdMeshers_PrismAsBlock::TSideFace::VertiCurve(const bool isMax) const
4518 if ( !myComponents.empty() ) {
4520 return myComponents.back()->VertiCurve(isMax);
4522 return myComponents.front()->VertiCurve(isMax);
4524 double f = myParams[0].first, l = myParams[0].second;
4525 if ( !myIsForward ) std::swap( f, l );
4526 return new TVerticalEdgeAdaptor( myParamToColumnMap, isMax ? l : f );
4529 //================================================================================
4531 * \brief Return geometry of the top or bottom curve
4533 * \retval Adaptor3d_Curve* -
4535 //================================================================================
4537 Adaptor3d_Curve* StdMeshers_PrismAsBlock::TSideFace::HorizCurve(const bool isTop) const
4539 return new THorizontalEdgeAdaptor( this, isTop );
4542 //================================================================================
4544 * \brief Return pcurves
4545 * \param pcurv - array of 4 pcurves
4546 * \retval bool - is a success
4548 //================================================================================
4550 bool StdMeshers_PrismAsBlock::TSideFace::GetPCurves(Adaptor2d_Curve2d* pcurv[4]) const
4552 int iEdge[ 4 ] = { BOTTOM_EDGE, TOP_EDGE, V0_EDGE, V1_EDGE };
4554 for ( int i = 0 ; i < 4 ; ++i ) {
4555 Handle(Geom2d_Line) line;
4556 switch ( iEdge[ i ] ) {
4558 line = new Geom2d_Line( gp_Pnt2d( 0, 1 ), gp::DX2d() ); break;
4560 line = new Geom2d_Line( gp::Origin2d(), gp::DX2d() ); break;
4562 line = new Geom2d_Line( gp::Origin2d(), gp::DY2d() ); break;
4564 line = new Geom2d_Line( gp_Pnt2d( 1, 0 ), gp::DY2d() ); break;
4566 pcurv[ i ] = new Geom2dAdaptor_Curve( line, 0, 1 );
4571 //================================================================================
4573 * \brief Returns geometry of pcurve on a horizontal face
4574 * \param isTop - is top or bottom face
4575 * \param horFace - a horizontal face
4576 * \retval Adaptor2d_Curve2d* - curve adaptor
4578 //================================================================================
4581 StdMeshers_PrismAsBlock::TSideFace::HorizPCurve(const bool isTop,
4582 const TopoDS_Face& horFace) const
4584 return new TPCurveOnHorFaceAdaptor( this, isTop, horFace );
4587 //================================================================================
4589 * \brief Return a component corresponding to parameter
4590 * \param U - parameter along a horizontal size
4591 * \param localU - parameter along a horizontal size of a component
4592 * \retval TSideFace* - found component
4594 //================================================================================
4596 StdMeshers_PrismAsBlock::TSideFace*
4597 StdMeshers_PrismAsBlock::TSideFace::GetComponent(const double U,double & localU) const
4600 if ( myComponents.empty() )
4601 return const_cast<TSideFace*>( this );
4604 for ( i = 0; i < myComponents.size(); ++i )
4605 if ( U < myParams[ i ].second )
4607 if ( i >= myComponents.size() )
4608 i = myComponents.size() - 1;
4610 double f = myParams[ i ].first, l = myParams[ i ].second;
4611 localU = ( U - f ) / ( l - f );
4612 return myComponents[ i ];
4615 //================================================================================
4617 * \brief Find node columns for a parameter
4618 * \param U - parameter along a horizontal edge
4619 * \param col1 - the 1st found column
4620 * \param col2 - the 2nd found column
4621 * \retval r - normalized position of U between the found columns
4623 //================================================================================
4625 double StdMeshers_PrismAsBlock::TSideFace::GetColumns(const double U,
4626 TParam2ColumnIt & col1,
4627 TParam2ColumnIt & col2) const
4629 double u = U, r = 0;
4630 if ( !myComponents.empty() ) {
4631 TSideFace * comp = GetComponent(U,u);
4632 return comp->GetColumns( u, col1, col2 );
4637 double f = myParams[0].first, l = myParams[0].second;
4638 u = f + u * ( l - f );
4640 col1 = col2 = getColumn( myParamToColumnMap, u );
4641 if ( ++col2 == myParamToColumnMap->end() ) {
4646 double uf = col1->first;
4647 double ul = col2->first;
4648 r = ( u - uf ) / ( ul - uf );
4653 //================================================================================
4655 * \brief Return all nodes at a given height together with their normalized parameters
4656 * \param [in] Z - the height of interest
4657 * \param [out] nodes - map of parameter to node
4659 //================================================================================
4661 void StdMeshers_PrismAsBlock::
4662 TSideFace::GetNodesAtZ(const int Z,
4663 map<double, const SMDS_MeshNode* >& nodes ) const
4665 if ( !myComponents.empty() )
4668 for ( size_t i = 0; i < myComponents.size(); ++i )
4670 map<double, const SMDS_MeshNode* > nn;
4671 myComponents[i]->GetNodesAtZ( Z, nn );
4672 map<double, const SMDS_MeshNode* >::iterator u2n = nn.begin();
4673 if ( !nodes.empty() && nodes.rbegin()->second == u2n->second )
4675 const double uRange = myParams[i].second - myParams[i].first;
4676 for ( ; u2n != nn.end(); ++u2n )
4677 nodes.insert( nodes.end(), make_pair( u0 + uRange * u2n->first, u2n->second ));
4683 double f = myParams[0].first, l = myParams[0].second;
4686 const double uRange = l - f;
4687 if ( Abs( uRange ) < std::numeric_limits<double>::min() )
4689 TParam2ColumnIt u2col = getColumn( myParamToColumnMap, myParams[0].first + 1e-3 );
4690 for ( ; u2col != myParamToColumnMap->end(); ++u2col )
4691 if ( u2col->first > myParams[0].second + 1e-9 )
4694 nodes.insert( nodes.end(),
4695 make_pair( ( u2col->first - f ) / uRange, u2col->second[ Z ] ));
4699 //================================================================================
4701 * \brief Return coordinates by normalized params
4702 * \param U - horizontal param
4703 * \param V - vertical param
4704 * \retval gp_Pnt - result point
4706 //================================================================================
4708 gp_Pnt StdMeshers_PrismAsBlock::TSideFace::Value(const Standard_Real U,
4709 const Standard_Real V) const
4711 if ( !myComponents.empty() ) {
4713 TSideFace * comp = GetComponent(U,u);
4714 return comp->Value( u, V );
4717 TParam2ColumnIt u_col1, u_col2;
4718 double vR, hR = GetColumns( U, u_col1, u_col2 );
4720 const SMDS_MeshNode* nn[4];
4722 // BEGIN issue 0020680: Bad cell created by Radial prism in center of torus
4723 // Workaround for a wrongly located point returned by mySurface.Value() for
4724 // UV located near boundary of BSpline surface.
4725 // To bypass the problem, we take point from 3D curve of EDGE.
4726 // It solves pb of the bloc_fiss_new.py
4727 const double tol = 1e-3;
4728 if ( V < tol || V+tol >= 1. )
4730 nn[0] = V < tol ? u_col1->second.front() : u_col1->second.back();
4731 nn[2] = V < tol ? u_col2->second.front() : u_col2->second.back();
4739 TopoDS_Shape s = myHelper.GetSubShapeByNode( nn[0], myHelper.GetMeshDS() );
4740 if ( s.ShapeType() != TopAbs_EDGE )
4741 s = myHelper.GetSubShapeByNode( nn[2], myHelper.GetMeshDS() );
4742 if ( !s.IsNull() && s.ShapeType() == TopAbs_EDGE )
4743 edge = TopoDS::Edge( s );
4745 if ( !edge.IsNull() )
4747 double u1 = myHelper.GetNodeU( edge, nn[0], nn[2] );
4748 double u3 = myHelper.GetNodeU( edge, nn[2], nn[0] );
4749 double u = u1 * ( 1 - hR ) + u3 * hR;
4750 TopLoc_Location loc; double f,l;
4751 Handle(Geom_Curve) curve = BRep_Tool::Curve( edge,loc,f,l );
4752 return curve->Value( u ).Transformed( loc );
4755 // END issue 0020680: Bad cell created by Radial prism in center of torus
4757 vR = getRAndNodes( & u_col1->second, V, nn[0], nn[1] );
4758 vR = getRAndNodes( & u_col2->second, V, nn[2], nn[3] );
4760 if ( !myShapeID2Surf.empty() ) // side is vertically composite
4762 // find a FACE on which the 4 nodes lie
4763 TSideFace* me = (TSideFace*) this;
4764 int notFaceID1 = 0, notFaceID2 = 0;
4765 for ( int i = 0; i < 4; ++i )
4766 if ( nn[i]->GetPosition()->GetTypeOfPosition() == SMDS_TOP_FACE ) // node on FACE
4768 me->mySurface = me->myShapeID2Surf[ nn[i]->getshapeId() ];
4772 else if ( notFaceID1 == 0 ) // node on EDGE or VERTEX
4774 me->mySurface = me->myShapeID2Surf[ nn[i]->getshapeId() ];
4775 notFaceID1 = nn[i]->getshapeId();
4777 else if ( notFaceID1 != nn[i]->getshapeId() ) // node on other EDGE or VERTEX
4779 if ( mySurface != me->myShapeID2Surf[ nn[i]->getshapeId() ])
4780 notFaceID2 = nn[i]->getshapeId();
4782 if ( notFaceID2 ) // no nodes of FACE and nodes are on different FACEs
4784 SMESHDS_Mesh* meshDS = myHelper.GetMeshDS();
4785 TopoDS_Shape face = myHelper.GetCommonAncestor( meshDS->IndexToShape( notFaceID1 ),
4786 meshDS->IndexToShape( notFaceID2 ),
4787 *myHelper.GetMesh(),
4789 if ( face.IsNull() )
4790 throw SALOME_Exception("StdMeshers_PrismAsBlock::TSideFace::Value() face.IsNull()");
4791 int faceID = meshDS->ShapeToIndex( face );
4792 me->mySurface = me->myShapeID2Surf[ faceID ];
4794 throw SALOME_Exception("StdMeshers_PrismAsBlock::TSideFace::Value() !mySurface");
4797 ((TSideFace*) this)->myHelper.SetSubShape( mySurface->Face() );
4799 gp_XY uv1 = myHelper.GetNodeUV( mySurface->Face(), nn[0], nn[2]);
4800 gp_XY uv2 = myHelper.GetNodeUV( mySurface->Face(), nn[1], nn[3]);
4801 gp_XY uv12 = uv1 * ( 1 - vR ) + uv2 * vR;
4803 gp_XY uv3 = myHelper.GetNodeUV( mySurface->Face(), nn[2], nn[0]);
4804 gp_XY uv4 = myHelper.GetNodeUV( mySurface->Face(), nn[3], nn[1]);
4805 gp_XY uv34 = uv3 * ( 1 - vR ) + uv4 * vR;
4807 gp_XY uv = uv12 * ( 1 - hR ) + uv34 * hR;
4809 gp_Pnt p = mySurface->Value( uv.X(), uv.Y() );
4814 //================================================================================
4816 * \brief Return boundary edge
4817 * \param edge - edge index
4818 * \retval TopoDS_Edge - found edge
4820 //================================================================================
4822 TopoDS_Edge StdMeshers_PrismAsBlock::TSideFace::GetEdge(const int iEdge) const
4824 if ( !myComponents.empty() ) {
4826 case V0_EDGE : return myComponents.front()->GetEdge( iEdge );
4827 case V1_EDGE : return myComponents.back() ->GetEdge( iEdge );
4828 default: return TopoDS_Edge();
4832 const SMDS_MeshNode* node = 0;
4833 SMESHDS_Mesh * meshDS = myHelper.GetMesh()->GetMeshDS();
4834 TNodeColumn* column;
4839 column = & (( ++myParamToColumnMap->begin())->second );
4840 node = ( iEdge == TOP_EDGE ) ? column->back() : column->front();
4841 edge = myHelper.GetSubShapeByNode ( node, meshDS );
4842 if ( edge.ShapeType() == TopAbs_VERTEX ) {
4843 column = & ( myParamToColumnMap->begin()->second );
4844 node = ( iEdge == TOP_EDGE ) ? column->back() : column->front();
4849 bool back = ( iEdge == V1_EDGE );
4850 if ( !myIsForward ) back = !back;
4852 column = & ( myParamToColumnMap->rbegin()->second );
4854 column = & ( myParamToColumnMap->begin()->second );
4855 if ( column->size() > 1 )
4856 edge = myHelper.GetSubShapeByNode( (*column)[ 1 ], meshDS );
4857 if ( edge.IsNull() || edge.ShapeType() == TopAbs_VERTEX )
4858 node = column->front();
4863 if ( !edge.IsNull() && edge.ShapeType() == TopAbs_EDGE )
4864 return TopoDS::Edge( edge );
4866 // find edge by 2 vertices
4867 TopoDS_Shape V1 = edge;
4868 TopoDS_Shape V2 = myHelper.GetSubShapeByNode( node, meshDS );
4869 if ( !V2.IsNull() && V2.ShapeType() == TopAbs_VERTEX && !V2.IsSame( V1 ))
4871 TopoDS_Shape ancestor = myHelper.GetCommonAncestor( V1, V2, *myHelper.GetMesh(), TopAbs_EDGE);
4872 if ( !ancestor.IsNull() )
4873 return TopoDS::Edge( ancestor );
4875 return TopoDS_Edge();
4878 //================================================================================
4880 * \brief Fill block sub-shapes
4881 * \param shapeMap - map to fill in
4882 * \retval int - nb inserted sub-shapes
4884 //================================================================================
4886 int StdMeshers_PrismAsBlock::TSideFace::InsertSubShapes(TBlockShapes& shapeMap) const
4891 vector< int > edgeIdVec;
4892 SMESH_Block::GetFaceEdgesIDs( myID, edgeIdVec );
4894 for ( int i = BOTTOM_EDGE; i <=V1_EDGE ; ++i ) {
4895 TopoDS_Edge e = GetEdge( i );
4896 if ( !e.IsNull() ) {
4897 nbInserted += SMESH_Block::Insert( e, edgeIdVec[ i ], shapeMap);
4901 // Insert corner vertices
4903 TParam2ColumnIt col1, col2 ;
4904 vector< int > vertIdVec;
4907 SMESH_Block::GetEdgeVertexIDs( edgeIdVec[ V0_EDGE ], vertIdVec);
4908 GetColumns(0, col1, col2 );
4909 const SMDS_MeshNode* node0 = col1->second.front();
4910 const SMDS_MeshNode* node1 = col1->second.back();
4911 TopoDS_Shape v0 = myHelper.GetSubShapeByNode( node0, myHelper.GetMeshDS());
4912 TopoDS_Shape v1 = myHelper.GetSubShapeByNode( node1, myHelper.GetMeshDS());
4913 if ( v0.ShapeType() == TopAbs_VERTEX ) {
4914 nbInserted += SMESH_Block::Insert( v0, vertIdVec[ 0 ], shapeMap);
4916 if ( v1.ShapeType() == TopAbs_VERTEX ) {
4917 nbInserted += SMESH_Block::Insert( v1, vertIdVec[ 1 ], shapeMap);
4921 SMESH_Block::GetEdgeVertexIDs( edgeIdVec[ V1_EDGE ], vertIdVec);
4922 GetColumns(1, col1, col2 );
4923 node0 = col2->second.front();
4924 node1 = col2->second.back();
4925 v0 = myHelper.GetSubShapeByNode( node0, myHelper.GetMeshDS());
4926 v1 = myHelper.GetSubShapeByNode( node1, myHelper.GetMeshDS());
4927 if ( v0.ShapeType() == TopAbs_VERTEX ) {
4928 nbInserted += SMESH_Block::Insert( v0, vertIdVec[ 0 ], shapeMap);
4930 if ( v1.ShapeType() == TopAbs_VERTEX ) {
4931 nbInserted += SMESH_Block::Insert( v1, vertIdVec[ 1 ], shapeMap);
4934 // TopoDS_Vertex V0, V1, Vcom;
4935 // TopExp::Vertices( myBaseEdge, V0, V1, true );
4936 // if ( !myIsForward ) std::swap( V0, V1 );
4938 // // bottom vertex IDs
4939 // SMESH_Block::GetEdgeVertexIDs( edgeIdVec[ _u0 ], vertIdVec);
4940 // SMESH_Block::Insert( V0, vertIdVec[ 0 ], shapeMap);
4941 // SMESH_Block::Insert( V1, vertIdVec[ 1 ], shapeMap);
4943 // TopoDS_Edge sideEdge = GetEdge( V0_EDGE );
4944 // if ( sideEdge.IsNull() || !TopExp::CommonVertex( botEdge, sideEdge, Vcom ))
4947 // // insert one side edge
4949 // if ( Vcom.IsSame( V0 )) edgeID = edgeIdVec[ _v0 ];
4950 // else edgeID = edgeIdVec[ _v1 ];
4951 // SMESH_Block::Insert( sideEdge, edgeID, shapeMap);
4953 // // top vertex of the side edge
4954 // SMESH_Block::GetEdgeVertexIDs( edgeID, vertIdVec);
4955 // TopoDS_Vertex Vtop = TopExp::FirstVertex( sideEdge );
4956 // if ( Vcom.IsSame( Vtop ))
4957 // Vtop = TopExp::LastVertex( sideEdge );
4958 // SMESH_Block::Insert( Vtop, vertIdVec[ 1 ], shapeMap);
4960 // // other side edge
4961 // sideEdge = GetEdge( V1_EDGE );
4962 // if ( sideEdge.IsNull() )
4964 // if ( edgeID = edgeIdVec[ _v1 ]) edgeID = edgeIdVec[ _v0 ];
4965 // else edgeID = edgeIdVec[ _v1 ];
4966 // SMESH_Block::Insert( sideEdge, edgeID, shapeMap);
4969 // TopoDS_Edge topEdge = GetEdge( TOP_EDGE );
4970 // SMESH_Block::Insert( topEdge, edgeIdVec[ _u1 ], shapeMap);
4972 // // top vertex of the other side edge
4973 // if ( !TopExp::CommonVertex( topEdge, sideEdge, Vcom ))
4975 // SMESH_Block::GetEdgeVertexIDs( edgeID, vertIdVec );
4976 // SMESH_Block::Insert( Vcom, vertIdVec[ 1 ], shapeMap);
4981 //================================================================================
4983 * \brief Dump ids of nodes of sides
4985 //================================================================================
4987 void StdMeshers_PrismAsBlock::TSideFace::dumpNodes(int nbNodes) const
4990 cout << endl << "NODES OF FACE "; SMESH_Block::DumpShapeID( myID, cout ) << endl;
4991 THorizontalEdgeAdaptor* hSize0 = (THorizontalEdgeAdaptor*) HorizCurve(0);
4992 cout << "Horiz side 0: "; hSize0->dumpNodes(nbNodes); cout << endl;
4993 THorizontalEdgeAdaptor* hSize1 = (THorizontalEdgeAdaptor*) HorizCurve(1);
4994 cout << "Horiz side 1: "; hSize1->dumpNodes(nbNodes); cout << endl;
4995 TVerticalEdgeAdaptor* vSide0 = (TVerticalEdgeAdaptor*) VertiCurve(0);
4996 cout << "Verti side 0: "; vSide0->dumpNodes(nbNodes); cout << endl;
4997 TVerticalEdgeAdaptor* vSide1 = (TVerticalEdgeAdaptor*) VertiCurve(1);
4998 cout << "Verti side 1: "; vSide1->dumpNodes(nbNodes); cout << endl;
4999 delete hSize0; delete hSize1; delete vSide0; delete vSide1;
5001 (void)nbNodes; // unused in release mode
5005 //================================================================================
5007 * \brief Creates TVerticalEdgeAdaptor
5008 * \param columnsMap - node column map
5009 * \param parameter - normalized parameter
5011 //================================================================================
5013 StdMeshers_PrismAsBlock::TVerticalEdgeAdaptor::
5014 TVerticalEdgeAdaptor( const TParam2ColumnMap* columnsMap, const double parameter)
5016 myNodeColumn = & getColumn( columnsMap, parameter )->second;
5019 //================================================================================
5021 * \brief Return coordinates for the given normalized parameter
5022 * \param U - normalized parameter
5023 * \retval gp_Pnt - coordinates
5025 //================================================================================
5027 gp_Pnt StdMeshers_PrismAsBlock::TVerticalEdgeAdaptor::Value(const Standard_Real U) const
5029 const SMDS_MeshNode* n1;
5030 const SMDS_MeshNode* n2;
5031 double r = getRAndNodes( myNodeColumn, U, n1, n2 );
5032 return gpXYZ(n1) * ( 1 - r ) + gpXYZ(n2) * r;
5035 //================================================================================
5037 * \brief Dump ids of nodes
5039 //================================================================================
5041 void StdMeshers_PrismAsBlock::TVerticalEdgeAdaptor::dumpNodes(int nbNodes) const
5044 for ( int i = 0; i < nbNodes && i < (int)myNodeColumn->size(); ++i )
5045 cout << (*myNodeColumn)[i]->GetID() << " ";
5046 if ( nbNodes < (int) myNodeColumn->size() )
5047 cout << myNodeColumn->back()->GetID();
5049 (void)nbNodes; // unused in release mode
5053 //================================================================================
5055 * \brief Return coordinates for the given normalized parameter
5056 * \param U - normalized parameter
5057 * \retval gp_Pnt - coordinates
5059 //================================================================================
5061 gp_Pnt StdMeshers_PrismAsBlock::THorizontalEdgeAdaptor::Value(const Standard_Real U) const
5063 return mySide->TSideFace::Value( U, myV );
5066 //================================================================================
5068 * \brief Dump ids of <nbNodes> first nodes and the last one
5070 //================================================================================
5072 void StdMeshers_PrismAsBlock::THorizontalEdgeAdaptor::dumpNodes(int nbNodes) const
5075 // Not bedugged code. Last node is sometimes incorrect
5076 const TSideFace* side = mySide;
5078 if ( mySide->IsComplex() )
5079 side = mySide->GetComponent(0,u);
5081 TParam2ColumnIt col, col2;
5082 TParam2ColumnMap* u2cols = side->GetColumns();
5083 side->GetColumns( u , col, col2 );
5085 int j, i = myV ? mySide->ColumnHeight()-1 : 0;
5087 const SMDS_MeshNode* n = 0;
5088 const SMDS_MeshNode* lastN
5089 = side->IsForward() ? u2cols->rbegin()->second[ i ] : u2cols->begin()->second[ i ];
5090 for ( j = 0; j < nbNodes && n != lastN; ++j )
5092 n = col->second[ i ];
5093 cout << n->GetID() << " ";
5094 if ( side->IsForward() )
5102 if ( mySide->IsComplex() )
5103 side = mySide->GetComponent(1,u);
5105 side->GetColumns( u , col, col2 );
5106 if ( n != col->second[ i ] )
5107 cout << col->second[ i ]->GetID();
5109 (void)nbNodes; // unused in release mode
5113 //================================================================================
5115 * \brief Constructor of TPCurveOnHorFaceAdaptor fills its map of
5116 * normalized parameter to node UV on a horizontal face
5117 * \param [in] sideFace - lateral prism side
5118 * \param [in] isTop - is \a horFace top or bottom of the prism
5119 * \param [in] horFace - top or bottom face of the prism
5121 //================================================================================
5123 StdMeshers_PrismAsBlock::
5124 TPCurveOnHorFaceAdaptor::TPCurveOnHorFaceAdaptor( const TSideFace* sideFace,
5126 const TopoDS_Face& horFace)
5128 if ( sideFace && !horFace.IsNull() )
5130 //cout << "\n\t FACE " << sideFace->FaceID() << endl;
5131 const int Z = isTop ? sideFace->ColumnHeight() - 1 : 0;
5132 map<double, const SMDS_MeshNode* > u2nodes;
5133 sideFace->GetNodesAtZ( Z, u2nodes );
5134 if ( u2nodes.empty() )
5137 SMESH_MesherHelper helper( *sideFace->GetMesh() );
5138 helper.SetSubShape( horFace );
5143 Handle(Geom2d_Curve) C2d;
5145 const double tol = 10 * helper.MaxTolerance( horFace );
5146 const SMDS_MeshNode* prevNode = u2nodes.rbegin()->second;
5148 map<double, const SMDS_MeshNode* >::iterator u2n = u2nodes.begin();
5149 for ( ; u2n != u2nodes.end(); ++u2n )
5151 const SMDS_MeshNode* n = u2n->second;
5153 if ( n->GetPosition()->GetTypeOfPosition() == SMDS_TOP_EDGE )
5155 if ( n->getshapeId() != edgeID )
5158 edgeID = n->getshapeId();
5159 TopoDS_Shape S = helper.GetSubShapeByNode( n, helper.GetMeshDS() );
5160 if ( !S.IsNull() && S.ShapeType() == TopAbs_EDGE )
5162 C2d = BRep_Tool::CurveOnSurface( TopoDS::Edge( S ), horFace, f,l );
5165 if ( !C2d.IsNull() )
5167 double u = SMDS_EdgePositionPtr( n->GetPosition() )->GetUParameter();
5168 if ( f <= u && u <= l )
5170 uv = C2d->Value( u ).XY();
5171 okUV = helper.CheckNodeUV( horFace, n, uv, tol );
5176 uv = helper.GetNodeUV( horFace, n, prevNode, &okUV );
5178 myUVmap.insert( myUVmap.end(), make_pair( u2n->first, uv ));
5179 // cout << n->getshapeId() << " N " << n->GetID()
5180 // << " \t" << uv.X() << ", " << uv.Y() << " \t" << u2n->first << endl;
5187 //================================================================================
5189 * \brief Return UV on pcurve for the given normalized parameter
5190 * \param U - normalized parameter
5191 * \retval gp_Pnt - coordinates
5193 //================================================================================
5195 gp_Pnt2d StdMeshers_PrismAsBlock::TPCurveOnHorFaceAdaptor::Value(const Standard_Real U) const
5197 map< double, gp_XY >::const_iterator i1 = myUVmap.upper_bound( U );
5199 if ( i1 == myUVmap.end() )
5200 return myUVmap.empty() ? gp_XY(0,0) : myUVmap.rbegin()->second;
5202 if ( i1 == myUVmap.begin() )
5203 return (*i1).second;
5205 map< double, gp_XY >::const_iterator i2 = i1--;
5207 double r = ( U - i1->first ) / ( i2->first - i1->first );
5208 return i1->second * ( 1 - r ) + i2->second * r;
5211 //================================================================================
5213 * \brief Projects internal nodes using transformation found by boundary nodes
5215 //================================================================================
5217 bool StdMeshers_Sweeper::projectIntPoints(const vector< gp_XYZ >& fromBndPoints,
5218 const vector< gp_XYZ >& toBndPoints,
5219 const vector< gp_XYZ >& fromIntPoints,
5220 vector< gp_XYZ >& toIntPoints,
5222 NSProjUtils::TrsfFinder3D& trsf,
5223 vector< gp_XYZ > * bndError)
5225 // find transformation
5226 if ( trsf.IsIdentity() && !trsf.Solve( fromBndPoints, toBndPoints ))
5229 // compute internal points using the found trsf
5230 for ( size_t iP = 0; iP < fromIntPoints.size(); ++iP )
5232 toIntPoints[ iP ] = trsf.Transform( fromIntPoints[ iP ]);
5235 // compute boundary error
5238 bndError->resize( fromBndPoints.size() );
5240 for ( size_t iP = 0; iP < fromBndPoints.size(); ++iP )
5242 fromTrsf = trsf.Transform( fromBndPoints[ iP ] );
5243 (*bndError)[ iP ] = toBndPoints[ iP ] - fromTrsf;
5247 // apply boundary error
5248 if ( bndError && toIntPoints.size() == myTopBotTriangles.size() )
5250 for ( size_t iP = 0; iP < toIntPoints.size(); ++iP )
5252 const TopBotTriangles& tbTrias = myTopBotTriangles[ iP ];
5253 for ( int i = 0; i < 3; ++i ) // boundary errors at 3 triangle nodes
5255 toIntPoints[ iP ] +=
5256 ( (*bndError)[ tbTrias.myBotTriaNodes[i] ] * tbTrias.myBotBC[i] * ( 1 - r ) +
5257 (*bndError)[ tbTrias.myTopTriaNodes[i] ] * tbTrias.myTopBC[i] * ( r ));
5265 //================================================================================
5267 * \brief Create internal nodes of the prism by computing an affine transformation
5268 * from layer to layer
5270 //================================================================================
5272 bool StdMeshers_Sweeper::ComputeNodesByTrsf( const double tol,
5273 const bool allowHighBndError)
5275 const size_t zSize = myBndColumns[0]->size();
5276 const size_t zSrc = 0, zTgt = zSize-1;
5277 if ( zSize < 3 ) return true;
5279 vector< vector< gp_XYZ > > intPntsOfLayer( zSize ); // node coordinates to compute
5280 // set coordinates of src and tgt nodes
5281 for ( size_t z = 0; z < intPntsOfLayer.size(); ++z )
5282 intPntsOfLayer[ z ].resize( myIntColumns.size() );
5283 for ( size_t iP = 0; iP < myIntColumns.size(); ++iP )
5285 intPntsOfLayer[ zSrc ][ iP ] = intPoint( iP, zSrc );
5286 intPntsOfLayer[ zTgt ][ iP ] = intPoint( iP, zTgt );
5289 // for each internal column find boundary nodes whose error to use for correction
5290 prepareTopBotDelaunay();
5291 bool isErrorCorrectable = findDelaunayTriangles();
5293 // compute coordinates of internal nodes by projecting (transforming) src and tgt
5294 // nodes towards the central layer
5296 vector< NSProjUtils::TrsfFinder3D > trsfOfLayer( zSize );
5297 vector< vector< gp_XYZ > > bndError( zSize );
5299 // boundary points used to compute an affine transformation from a layer to a next one
5300 vector< gp_XYZ > fromSrcBndPnts( myBndColumns.size() ), fromTgtBndPnts( myBndColumns.size() );
5301 vector< gp_XYZ > toSrcBndPnts ( myBndColumns.size() ), toTgtBndPnts ( myBndColumns.size() );
5302 for ( size_t iP = 0; iP < myBndColumns.size(); ++iP )
5304 fromSrcBndPnts[ iP ] = bndPoint( iP, zSrc );
5305 fromTgtBndPnts[ iP ] = bndPoint( iP, zTgt );
5308 size_t zS = zSrc + 1;
5309 size_t zT = zTgt - 1;
5310 for ( ; zS < zT; ++zS, --zT ) // vertical loop on layers
5312 for ( size_t iP = 0; iP < myBndColumns.size(); ++iP )
5314 toSrcBndPnts[ iP ] = bndPoint( iP, zS );
5315 toTgtBndPnts[ iP ] = bndPoint( iP, zT );
5317 if (! projectIntPoints( fromSrcBndPnts, toSrcBndPnts,
5318 intPntsOfLayer[ zS-1 ], intPntsOfLayer[ zS ],
5320 trsfOfLayer [ zS-1 ], & bndError[ zS-1 ]))
5322 if (! projectIntPoints( fromTgtBndPnts, toTgtBndPnts,
5323 intPntsOfLayer[ zT+1 ], intPntsOfLayer[ zT ],
5325 trsfOfLayer [ zT+1 ], & bndError[ zT+1 ]))
5328 // if ( zT == zTgt - 1 )
5330 // for ( size_t iP = 0; iP < myBndColumns.size(); ++iP )
5332 // gp_XYZ fromTrsf = trsfOfLayer [ zT+1].Transform( fromTgtBndPnts[ iP ] );
5333 // cout << "mesh.AddNode( "
5334 // << fromTrsf.X() << ", "
5335 // << fromTrsf.Y() << ", "
5336 // << fromTrsf.Z() << ") " << endl;
5338 // for ( size_t iP = 0; iP < myIntColumns.size(); ++iP )
5339 // cout << "mesh.AddNode( "
5340 // << intPntsOfLayer[ zT ][ iP ].X() << ", "
5341 // << intPntsOfLayer[ zT ][ iP ].Y() << ", "
5342 // << intPntsOfLayer[ zT ][ iP ].Z() << ") " << endl;
5345 fromTgtBndPnts.swap( toTgtBndPnts );
5346 fromSrcBndPnts.swap( toSrcBndPnts );
5349 // Evaluate an error of boundary points
5351 if ( !isErrorCorrectable && !allowHighBndError )
5353 for ( size_t iP = 0; iP < myBndColumns.size(); ++iP )
5355 double sumError = 0;
5356 for ( size_t z = 1; z < zS; ++z ) // loop on layers
5357 sumError += ( bndError[ z-1 ][ iP ].Modulus() +
5358 bndError[ zSize-z ][ iP ].Modulus() );
5360 if ( sumError > tol )
5365 // Compute two projections of internal points to the central layer
5366 // in order to evaluate an error of internal points
5368 bool centerIntErrorIsSmall;
5369 vector< gp_XYZ > centerSrcIntPnts( myIntColumns.size() );
5370 vector< gp_XYZ > centerTgtIntPnts( myIntColumns.size() );
5372 for ( size_t iP = 0; iP < myBndColumns.size(); ++iP )
5374 toSrcBndPnts[ iP ] = bndPoint( iP, zS );
5375 toTgtBndPnts[ iP ] = bndPoint( iP, zT );
5377 if (! projectIntPoints( fromSrcBndPnts, toSrcBndPnts,
5378 intPntsOfLayer[ zS-1 ], centerSrcIntPnts,
5380 trsfOfLayer [ zS-1 ], & bndError[ zS-1 ]))
5382 if (! projectIntPoints( fromTgtBndPnts, toTgtBndPnts,
5383 intPntsOfLayer[ zT+1 ], centerTgtIntPnts,
5385 trsfOfLayer [ zT+1 ], & bndError[ zT+1 ]))
5388 // evaluate an error of internal points on the central layer
5389 centerIntErrorIsSmall = true;
5390 if ( zS == zT ) // odd zSize
5392 for ( size_t iP = 0; ( iP < myIntColumns.size() && centerIntErrorIsSmall ); ++iP )
5393 centerIntErrorIsSmall =
5394 (centerSrcIntPnts[ iP ] - centerTgtIntPnts[ iP ]).SquareModulus() < tol*tol;
5398 for ( size_t iP = 0; ( iP < myIntColumns.size() && centerIntErrorIsSmall ); ++iP )
5399 centerIntErrorIsSmall =
5400 (intPntsOfLayer[ zS-1 ][ iP ] - centerTgtIntPnts[ iP ]).SquareModulus() < tol*tol;
5403 // compute final points on the central layer
5404 double r = zS / ( zSize - 1.);
5407 for ( size_t iP = 0; iP < myIntColumns.size(); ++iP )
5409 intPntsOfLayer[ zS ][ iP ] =
5410 ( 1 - r ) * centerSrcIntPnts[ iP ] + r * centerTgtIntPnts[ iP ];
5415 for ( size_t iP = 0; iP < myIntColumns.size(); ++iP )
5417 intPntsOfLayer[ zS ][ iP ] =
5418 r * intPntsOfLayer[ zS ][ iP ] + ( 1 - r ) * centerSrcIntPnts[ iP ];
5419 intPntsOfLayer[ zT ][ iP ] =
5420 r * intPntsOfLayer[ zT ][ iP ] + ( 1 - r ) * centerTgtIntPnts[ iP ];
5424 if ( !centerIntErrorIsSmall )
5426 // Compensate the central error; continue adding projection
5427 // by going from central layer to the source and target ones
5429 vector< gp_XYZ >& fromSrcIntPnts = centerSrcIntPnts;
5430 vector< gp_XYZ >& fromTgtIntPnts = centerTgtIntPnts;
5431 vector< gp_XYZ > toSrcIntPnts( myIntColumns.size() );
5432 vector< gp_XYZ > toTgtIntPnts( myIntColumns.size() );
5433 vector< gp_XYZ > srcBndError( myBndColumns.size() );
5434 vector< gp_XYZ > tgtBndError( myBndColumns.size() );
5436 fromTgtBndPnts.swap( toTgtBndPnts );
5437 fromSrcBndPnts.swap( toSrcBndPnts );
5439 for ( ++zS, --zT; zS < zTgt; ++zS, --zT ) // vertical loop on layers
5441 // invert transformation
5442 //if ( !trsfOfLayer[ zS+1 ].Invert() )
5443 trsfOfLayer[ zS+1 ] = NSProjUtils::TrsfFinder3D(); // to recompute
5444 //if ( !trsfOfLayer[ zT-1 ].Invert() )
5445 trsfOfLayer[ zT-1 ] = NSProjUtils::TrsfFinder3D();
5447 // project internal nodes and compute bnd error
5448 for ( size_t iP = 0; iP < myBndColumns.size(); ++iP )
5450 toSrcBndPnts[ iP ] = bndPoint( iP, zS );
5451 toTgtBndPnts[ iP ] = bndPoint( iP, zT );
5453 projectIntPoints( fromSrcBndPnts, toSrcBndPnts,
5454 fromSrcIntPnts, toSrcIntPnts,
5456 trsfOfLayer[ zS+1 ], & srcBndError );
5457 projectIntPoints( fromTgtBndPnts, toTgtBndPnts,
5458 fromTgtIntPnts, toTgtIntPnts,
5460 trsfOfLayer[ zT-1 ], & tgtBndError );
5462 // if ( zS == zTgt - 1 )
5464 // cout << "mesh2 = smesh.Mesh()" << endl;
5465 // for ( size_t iP = 0; iP < myBndColumns.size(); ++iP )
5467 // gp_XYZ fromTrsf = trsfOfLayer [ zS+1].Transform( fromSrcBndPnts[ iP ] );
5468 // cout << "mesh2.AddNode( "
5469 // << fromTrsf.X() << ", "
5470 // << fromTrsf.Y() << ", "
5471 // << fromTrsf.Z() << ") " << endl;
5473 // for ( size_t iP = 0; iP < myIntColumns.size(); ++iP )
5474 // cout << "mesh2.AddNode( "
5475 // << toSrcIntPnts[ iP ].X() << ", "
5476 // << toSrcIntPnts[ iP ].Y() << ", "
5477 // << toSrcIntPnts[ iP ].Z() << ") " << endl;
5480 // sum up 2 projections
5481 r = zS / ( zSize - 1.);
5482 vector< gp_XYZ >& zSIntPnts = intPntsOfLayer[ zS ];
5483 vector< gp_XYZ >& zTIntPnts = intPntsOfLayer[ zT ];
5484 for ( size_t iP = 0; iP < myIntColumns.size(); ++iP )
5486 zSIntPnts[ iP ] = r * zSIntPnts[ iP ] + ( 1 - r ) * toSrcIntPnts[ iP ];
5487 zTIntPnts[ iP ] = r * zTIntPnts[ iP ] + ( 1 - r ) * toTgtIntPnts[ iP ];
5490 fromSrcBndPnts.swap( toSrcBndPnts );
5491 fromSrcIntPnts.swap( toSrcIntPnts );
5492 fromTgtBndPnts.swap( toTgtBndPnts );
5493 fromTgtIntPnts.swap( toTgtIntPnts );
5495 } // if ( !centerIntErrorIsSmall )
5498 //cout << "centerIntErrorIsSmall = " << centerIntErrorIsSmall<< endl;
5501 for ( size_t iP = 0; iP < myIntColumns.size(); ++iP )
5503 vector< const SMDS_MeshNode* > & nodeCol = *myIntColumns[ iP ];
5504 for ( size_t z = zSrc + 1; z < zTgt; ++z ) // vertical loop on layers
5506 const gp_XYZ & xyz = intPntsOfLayer[ z ][ iP ];
5507 if ( !( nodeCol[ z ] = myHelper->AddNode( xyz.X(), xyz.Y(), xyz.Z() )))
5515 //================================================================================
5517 * \brief Check if all nodes of each layers have same logical Z
5519 //================================================================================
5521 bool StdMeshers_Sweeper::CheckSameZ()
5523 myZColumns.resize( myBndColumns.size() );
5524 fillZColumn( myZColumns[0], *myBndColumns[0] );
5527 const double tol = 0.1 * 1./ myBndColumns[0]->size();
5529 // check columns based on VERTEXes
5531 vector< int > vertexIndex;
5532 vertexIndex.push_back( 0 );
5533 for ( size_t iC = 1; iC < myBndColumns.size() && sameZ; ++iC )
5535 if ( myBndColumns[iC]->front()->GetPosition()->GetDim() > 0 )
5536 continue; // not on VERTEX
5538 vertexIndex.push_back( iC );
5539 fillZColumn( myZColumns[iC], *myBndColumns[iC] );
5541 for ( size_t iZ = 0; iZ < myZColumns[0].size() && sameZ; ++iZ )
5542 sameZ = ( Abs( myZColumns[0][iZ] - myZColumns[iC][iZ]) < tol );
5545 // check columns based on EDGEs, one per EDGE
5547 for ( size_t i = 1; i < vertexIndex.size() && sameZ; ++i )
5549 if ( vertexIndex[i] - vertexIndex[i-1] < 2 )
5552 int iC = ( vertexIndex[i] + vertexIndex[i-1] ) / 2;
5553 fillZColumn( myZColumns[iC], *myBndColumns[iC] );
5555 for ( size_t iZ = 0; iZ < myZColumns[0].size() && sameZ; ++iZ )
5556 sameZ = ( Abs( myZColumns[0][iZ] - myZColumns[iC][iZ]) < tol );
5561 myZColumns.resize(1);
5565 for ( size_t iC = 1; iC < myBndColumns.size(); ++iC )
5566 fillZColumn( myZColumns[iC], *myBndColumns[iC] );
5572 //================================================================================
5574 * \brief Create internal nodes of the prism all located on straight lines with
5575 * the same distribution along the lines.
5577 //================================================================================
5579 bool StdMeshers_Sweeper::ComputeNodesOnStraightSameZ()
5581 TZColumn& z = myZColumns[0];
5583 for ( size_t i = 0; i < myIntColumns.size(); ++i )
5585 TNodeColumn& nodes = *myIntColumns[i];
5586 SMESH_NodeXYZ n0( nodes[0] ), n1( nodes.back() );
5588 for ( size_t iZ = 0; iZ < z.size(); ++iZ )
5590 gp_XYZ p = n0 * ( 1 - z[iZ] ) + n1 * z[iZ];
5591 nodes[ iZ+1 ] = myHelper->AddNode( p.X(), p.Y(), p.Z() );
5598 //================================================================================
5600 * \brief Create internal nodes of the prism all located on straight lines with
5601 * different distributions along the lines.
5603 //================================================================================
5605 bool StdMeshers_Sweeper::ComputeNodesOnStraight()
5607 prepareTopBotDelaunay();
5609 const SMDS_MeshNode *botNode, *topNode;
5610 const BRepMesh_Triangle *topTria;
5611 double botBC[3], topBC[3]; // barycentric coordinates
5612 int botTriaNodes[3], topTriaNodes[3];
5613 bool checkUV = true;
5615 int nbInternalNodes = myIntColumns.size();
5616 myBotDelaunay->InitTraversal( nbInternalNodes );
5618 while (( botNode = myBotDelaunay->NextNode( botBC, botTriaNodes )))
5620 TNodeColumn* column = myIntColumns[ myNodeID2ColID( botNode->GetID() )];
5622 // find a Delaunay triangle containing the topNode
5623 topNode = column->back();
5624 gp_XY topUV = myHelper->GetNodeUV( myTopFace, topNode, NULL, &checkUV );
5625 // get a starting triangle basing on that top and bot boundary nodes have same index
5626 topTria = myTopDelaunay->GetTriangleNear( botTriaNodes[0] );
5627 topTria = myTopDelaunay->FindTriangle( topUV, topTria, topBC, topTriaNodes );
5631 // create nodes along a line
5632 SMESH_NodeXYZ botP( botNode ), topP( topNode );
5633 for ( size_t iZ = 0; iZ < myZColumns[0].size(); ++iZ )
5635 // use barycentric coordinates as weight of Z of boundary columns
5636 double botZ = 0, topZ = 0;
5637 for ( int i = 0; i < 3; ++i )
5639 botZ += botBC[i] * myZColumns[ botTriaNodes[i] ][ iZ ];
5640 topZ += topBC[i] * myZColumns[ topTriaNodes[i] ][ iZ ];
5642 double rZ = double( iZ + 1 ) / ( myZColumns[0].size() + 1 );
5643 double z = botZ * ( 1 - rZ ) + topZ * rZ;
5644 gp_XYZ p = botP * ( 1 - z ) + topP * z;
5645 (*column)[ iZ+1 ] = myHelper->AddNode( p.X(), p.Y(), p.Z() );
5649 return myBotDelaunay->NbVisitedNodes() == nbInternalNodes;
5652 //================================================================================
5654 * \brief Compute Z of nodes of a straight column
5656 //================================================================================
5658 void StdMeshers_Sweeper::fillZColumn( TZColumn& zColumn,
5659 TNodeColumn& nodes )
5661 if ( zColumn.size() == nodes.size() - 2 )
5664 gp_Pnt p0 = SMESH_NodeXYZ( nodes[0] );
5665 gp_Vec line( p0, SMESH_NodeXYZ( nodes.back() ));
5666 double len2 = line.SquareMagnitude();
5668 zColumn.resize( nodes.size() - 2 );
5669 for ( size_t i = 0; i < zColumn.size(); ++i )
5671 gp_Vec vec( p0, SMESH_NodeXYZ( nodes[ i+1] ));
5672 zColumn[i] = ( line * vec ) / len2; // param [0,1] on the line
5676 //================================================================================
5678 * \brief Initialize *Delaunay members
5680 //================================================================================
5682 void StdMeshers_Sweeper::prepareTopBotDelaunay()
5684 SMESH_MesherHelper* helper[2] = { myHelper, myHelper };
5685 SMESH_MesherHelper botHelper( *myHelper->GetMesh() );
5686 SMESH_MesherHelper topHelper( *myHelper->GetMesh() );
5687 const SMDS_MeshNode* intBotNode = 0;
5688 const SMDS_MeshNode* intTopNode = 0;
5689 if ( myHelper->HasSeam() || myHelper->HasDegeneratedEdges() ) // use individual helpers
5691 botHelper.SetSubShape( myBotFace );
5692 topHelper.SetSubShape( myTopFace );
5693 helper[0] = & botHelper;
5694 helper[1] = & topHelper;
5695 if ( !myIntColumns.empty() )
5697 TNodeColumn& nodes = *myIntColumns[ myIntColumns.size()/2 ];
5698 intBotNode = nodes[0];
5699 intTopNode = nodes.back();
5703 UVPtStructVec botUV( myBndColumns.size() );
5704 UVPtStructVec topUV( myBndColumns.size() );
5705 for ( size_t i = 0; i < myBndColumns.size(); ++i )
5707 TNodeColumn& nodes = *myBndColumns[i];
5708 botUV[i].node = nodes[0];
5709 botUV[i].SetUV( helper[0]->GetNodeUV( myBotFace, nodes[0], intBotNode ));
5710 topUV[i].node = nodes.back();
5711 topUV[i].SetUV( helper[1]->GetNodeUV( myTopFace, nodes.back(), intTopNode ));
5712 botUV[i].node->setIsMarked( true );
5715 SMESH_Mesh* mesh = myHelper->GetMesh();
5716 TSideVector botWires( 1, StdMeshers_FaceSide::New( botUV, myBotFace, dummyE, mesh ));
5717 TSideVector topWires( 1, StdMeshers_FaceSide::New( topUV, myTopFace, dummyE, mesh ));
5719 // Delaunay mesh on the FACEs.
5720 bool checkUV = false;
5721 myBotDelaunay.reset( new NSProjUtils::Delaunay( botWires, checkUV ));
5722 myTopDelaunay.reset( new NSProjUtils::Delaunay( topWires, checkUV ));
5724 if ( myHelper->GetIsQuadratic() )
5726 // mark all medium nodes of faces on botFace to avoid their treating
5727 SMESHDS_SubMesh* smDS = myHelper->GetMeshDS()->MeshElements( myBotFace );
5728 SMDS_ElemIteratorPtr eIt = smDS->GetElements();
5729 while ( eIt->more() )
5731 const SMDS_MeshElement* e = eIt->next();
5732 for ( int i = e->NbCornerNodes(), nb = e->NbNodes(); i < nb; ++i )
5733 e->GetNode( i )->setIsMarked( true );
5737 // map to get a node column by a bottom node
5738 myNodeID2ColID.Clear(/*doReleaseMemory=*/false);
5739 myNodeID2ColID.ReSize( myIntColumns.size() );
5741 // un-mark nodes to treat (internal bottom nodes) to be returned by myBotDelaunay
5742 for ( size_t i = 0; i < myIntColumns.size(); ++i )
5744 const SMDS_MeshNode* botNode = myIntColumns[i]->front();
5745 botNode->setIsMarked( false );
5746 myNodeID2ColID.Bind( botNode->GetID(), i );
5750 //================================================================================
5752 * \brief For each internal node column, find Delaunay triangles including it
5753 * and Barycentric Coordinates within the triangles. Fill in myTopBotTriangles
5755 //================================================================================
5757 bool StdMeshers_Sweeper::findDelaunayTriangles()
5759 const SMDS_MeshNode *botNode, *topNode;
5760 const BRepMesh_Triangle *topTria;
5761 TopBotTriangles tbTrias;
5762 bool checkUV = true;
5764 int nbInternalNodes = myIntColumns.size();
5765 myTopBotTriangles.resize( nbInternalNodes );
5767 myBotDelaunay->InitTraversal( nbInternalNodes );
5769 while (( botNode = myBotDelaunay->NextNode( tbTrias.myBotBC, tbTrias.myBotTriaNodes )))
5771 int colID = myNodeID2ColID( botNode->GetID() );
5772 TNodeColumn* column = myIntColumns[ colID ];
5774 // find a Delaunay triangle containing the topNode
5775 topNode = column->back();
5776 gp_XY topUV = myHelper->GetNodeUV( myTopFace, topNode, NULL, &checkUV );
5777 // get a starting triangle basing on that top and bot boundary nodes have same index
5778 topTria = myTopDelaunay->GetTriangleNear( tbTrias.myBotTriaNodes[0] );
5779 topTria = myTopDelaunay->FindTriangle( topUV, topTria,
5780 tbTrias.myTopBC, tbTrias.myTopTriaNodes );
5782 tbTrias.SetTopByBottom();
5784 myTopBotTriangles[ colID ] = tbTrias;
5787 if ( myBotDelaunay->NbVisitedNodes() < nbInternalNodes )
5789 myTopBotTriangles.clear();
5793 myBotDelaunay.reset();
5794 myTopDelaunay.reset();
5795 myNodeID2ColID.Clear();
5800 //================================================================================
5802 * \brief Initialize fields
5804 //================================================================================
5806 StdMeshers_Sweeper::TopBotTriangles::TopBotTriangles()
5808 myBotBC[0] = myBotBC[1] = myBotBC[2] = myTopBC[0] = myTopBC[1] = myTopBC[2] = 0.;
5809 myBotTriaNodes[0] = myBotTriaNodes[1] = myBotTriaNodes[2] = 0;
5810 myTopTriaNodes[0] = myTopTriaNodes[1] = myTopTriaNodes[2] = 0;
5813 //================================================================================
5815 * \brief Set top data equal to bottom data
5817 //================================================================================
5819 void StdMeshers_Sweeper::TopBotTriangles::SetTopByBottom()
5821 for ( int i = 0; i < 3; ++i )
5823 myTopBC[i] = myBotBC[i];
5824 myTopTriaNodes[i] = myBotTriaNodes[0];