1 // Copyright (C) 2007-2012 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.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 // File : StdMeshers_Prism_3D.cxx
25 // Created : Fri Oct 20 11:37:07 2006
26 // Author : Edward AGAPOV (eap)
28 #include "StdMeshers_Prism_3D.hxx"
30 #include "SMDS_EdgePosition.hxx"
31 #include "SMDS_VolumeOfNodes.hxx"
32 #include "SMDS_VolumeTool.hxx"
33 #include "SMESH_Comment.hxx"
34 #include "SMESH_Gen.hxx"
35 #include "SMESH_HypoFilter.hxx"
36 #include "SMESH_MesherHelper.hxx"
37 #include "StdMeshers_FaceSide.hxx"
38 #include "StdMeshers_ProjectionSource1D.hxx"
39 #include "StdMeshers_ProjectionSource2D.hxx"
40 #include "StdMeshers_ProjectionUtils.hxx"
41 #include "StdMeshers_Projection_1D.hxx"
42 #include "StdMeshers_Projection_1D2D.hxx"
43 #include "StdMeshers_Quadrangle_2D.hxx"
45 #include "utilities.h"
47 #include <BRepAdaptor_CompCurve.hxx>
48 #include <BRep_Tool.hxx>
49 #include <Bnd_B3d.hxx>
50 #include <Geom2dAdaptor_Curve.hxx>
51 #include <Geom2d_Line.hxx>
52 #include <Geom_Curve.hxx>
54 #include <TopExp_Explorer.hxx>
55 #include <TopTools_ListIteratorOfListOfShape.hxx>
56 #include <TopTools_ListOfShape.hxx>
57 #include <TopTools_MapOfShape.hxx>
58 #include <TopTools_SequenceOfShape.hxx>
65 #define RETURN_BAD_RESULT(msg) { MESSAGE(")-: Error: " << msg); return false; }
66 #define gpXYZ(n) gp_XYZ(n->X(),n->Y(),n->Z())
67 #define SHOWYXZ(msg, xyz) // {\
69 // cout << msg << " ("<< p.X() << "; " <<p.Y() << "; " <<p.Z() << ") " <<endl;\
72 namespace TAssocTool = StdMeshers_ProjectionUtils;
74 typedef SMESH_Comment TCom;
76 enum { ID_BOT_FACE = SMESH_Block::ID_Fxy0,
77 ID_TOP_FACE = SMESH_Block::ID_Fxy1,
78 BOTTOM_EDGE = 0, TOP_EDGE, V0_EDGE, V1_EDGE, // edge IDs in face
79 NB_WALL_FACES = 4 }; //
83 //=======================================================================
85 * \brief Quadrangle algorithm
87 struct TQuadrangleAlgo : public StdMeshers_Quadrangle_2D
89 TQuadrangleAlgo(int studyId, SMESH_Gen* gen)
90 : StdMeshers_Quadrangle_2D( gen->GetANewId(), studyId, gen)
93 static StdMeshers_Quadrangle_2D* instance( SMESH_Algo* fatherAlgo,
94 SMESH_MesherHelper* helper=0)
96 static TQuadrangleAlgo* algo = new TQuadrangleAlgo( fatherAlgo->GetStudyId(),
97 fatherAlgo->GetGen() );
100 algo->myProxyMesh->GetMesh() != helper->GetMesh() )
101 algo->myProxyMesh.reset( new SMESH_ProxyMesh( *helper->GetMesh() ));
103 algo->myQuadStruct.reset();
106 algo->_quadraticMesh = helper->GetIsQuadratic();
111 //=======================================================================
113 * \brief Algorithm projecting 1D mesh
115 struct TProjction1dAlgo : public StdMeshers_Projection_1D
117 StdMeshers_ProjectionSource1D myHyp;
119 TProjction1dAlgo(int studyId, SMESH_Gen* gen)
120 : StdMeshers_Projection_1D( gen->GetANewId(), studyId, gen),
121 myHyp( gen->GetANewId(), studyId, gen)
123 StdMeshers_Projection_1D::_sourceHypo = & myHyp;
125 static TProjction1dAlgo* instance( SMESH_Algo* fatherAlgo )
127 static TProjction1dAlgo* algo = new TProjction1dAlgo( fatherAlgo->GetStudyId(),
128 fatherAlgo->GetGen() );
132 //=======================================================================
134 * \brief Algorithm projecting 2D mesh
136 struct TProjction2dAlgo : public StdMeshers_Projection_1D2D
138 StdMeshers_ProjectionSource2D myHyp;
140 TProjction2dAlgo(int studyId, SMESH_Gen* gen)
141 : StdMeshers_Projection_1D2D( gen->GetANewId(), studyId, gen),
142 myHyp( gen->GetANewId(), studyId, gen)
144 StdMeshers_Projection_2D::_sourceHypo = & myHyp;
146 static TProjction2dAlgo* instance( SMESH_Algo* fatherAlgo )
148 static TProjction2dAlgo* algo = new TProjction2dAlgo( fatherAlgo->GetStudyId(),
149 fatherAlgo->GetGen() );
154 //================================================================================
156 * \brief Make \a botE be the BOTTOM_SIDE of \a quad.
157 * Return false if the BOTTOM_SIDE is composite
159 //================================================================================
161 bool setBottomEdge( const TopoDS_Edge& botE,
162 faceQuadStruct::Ptr& quad,
163 const TopoDS_Shape& face)
165 quad->side[ QUAD_TOP_SIDE ]->Reverse();
166 quad->side[ QUAD_LEFT_SIDE ]->Reverse();
168 for ( size_t i = 0; i < quad->side.size(); ++i )
170 StdMeshers_FaceSide* quadSide = quad->side[i];
171 for ( int iE = 0; iE < quadSide->NbEdges(); ++iE )
172 if ( botE.IsSame( quadSide->Edge( iE )))
174 if ( quadSide->NbEdges() > 1 )
177 i = quad->side.size(); // to quit from the outer loop
181 if ( edgeIndex != QUAD_BOTTOM_SIDE )
182 quad->shift( quad->side.size() - edgeIndex, /*keepUnitOri=*/false );
184 quad->face = TopoDS::Face( face );
189 //================================================================================
191 * \brief Return iterator pointing to node column for the given parameter
192 * \param columnsMap - node column map
193 * \param parameter - parameter
194 * \retval TParam2ColumnMap::iterator - result
196 * it returns closest left column
198 //================================================================================
200 TParam2ColumnIt getColumn( const TParam2ColumnMap* columnsMap,
201 const double parameter )
203 TParam2ColumnIt u_col = columnsMap->upper_bound( parameter );
204 if ( u_col != columnsMap->begin() )
206 return u_col; // return left column
209 //================================================================================
211 * \brief Return nodes around given parameter and a ratio
212 * \param column - node column
213 * \param param - parameter
214 * \param node1 - lower node
215 * \param node2 - upper node
216 * \retval double - ratio
218 //================================================================================
220 double getRAndNodes( const TNodeColumn* column,
222 const SMDS_MeshNode* & node1,
223 const SMDS_MeshNode* & node2)
225 if ( param >= 1.0 || column->size() == 1) {
226 node1 = node2 = column->back();
230 int i = int( param * ( column->size() - 1 ));
231 double u0 = double( i )/ double( column->size() - 1 );
232 double r = ( param - u0 ) * ( column->size() - 1 );
234 node1 = (*column)[ i ];
235 node2 = (*column)[ i + 1];
239 //================================================================================
241 * \brief Compute boundary parameters of face parts
242 * \param nbParts - nb of parts to split columns into
243 * \param columnsMap - node columns of the face to split
244 * \param params - computed parameters
246 //================================================================================
248 void splitParams( const int nbParts,
249 const TParam2ColumnMap* columnsMap,
250 vector< double > & params)
253 params.reserve( nbParts + 1 );
254 TParam2ColumnIt last_par_col = --columnsMap->end();
255 double par = columnsMap->begin()->first; // 0.
256 double parLast = last_par_col->first;
257 params.push_back( par );
258 for ( int i = 0; i < nbParts - 1; ++ i )
260 double partSize = ( parLast - par ) / double ( nbParts - i );
261 TParam2ColumnIt par_col = getColumn( columnsMap, par + partSize );
262 if ( par_col->first == par ) {
264 if ( par_col == last_par_col ) {
265 while ( i < nbParts - 1 )
266 params.push_back( par + partSize * i++ );
270 par = par_col->first;
271 params.push_back( par );
273 params.push_back( parLast ); // 1.
276 //================================================================================
278 * \brief Return coordinate system for z-th layer of nodes
280 //================================================================================
282 gp_Ax2 getLayerCoordSys(const int z,
283 const vector< const TNodeColumn* >& columns,
286 // gravity center of a layer
289 for ( int i = 0; i < columns.size(); ++i )
291 O += gpXYZ( (*columns[ i ])[ z ]);
292 if ( vertexCol < 0 &&
293 columns[ i ]->front()->GetPosition()->GetTypeOfPosition() == SMDS_TOP_VERTEX )
300 int iPrev = columns.size()-1;
301 for ( int i = 0; i < columns.size(); ++i )
303 gp_Vec v1( O, gpXYZ( (*columns[ iPrev ])[ z ]));
304 gp_Vec v2( O, gpXYZ( (*columns[ i ] )[ z ]));
309 if ( vertexCol >= 0 )
311 O = gpXYZ( (*columns[ vertexCol ])[ z ]);
313 if ( xColumn < 0 || xColumn >= columns.size() )
315 // select a column for X dir
317 for ( int i = 0; i < columns.size(); ++i )
319 double dist = ( O - gpXYZ((*columns[ i ])[ z ])).SquareModulus();
320 if ( dist > maxDist )
329 gp_Vec X( O, gpXYZ( (*columns[ xColumn ])[ z ]));
331 return gp_Ax2( O, Z, X);
334 //================================================================================
336 * \brief Removes submeshes that are or can be meshed with regular grid from given list
337 * \retval int - nb of removed submeshes
339 //================================================================================
341 int removeQuasiQuads(list< SMESH_subMesh* >& notQuadSubMesh,
342 SMESH_MesherHelper* helper,
343 StdMeshers_Quadrangle_2D* quadAlgo)
346 //SMESHDS_Mesh* mesh = notQuadSubMesh.front()->GetFather()->GetMeshDS();
347 list< SMESH_subMesh* >::iterator smIt = notQuadSubMesh.begin();
348 while ( smIt != notQuadSubMesh.end() )
350 SMESH_subMesh* faceSm = *smIt;
351 SMESHDS_SubMesh* faceSmDS = faceSm->GetSubMeshDS();
352 int nbQuads = faceSmDS ? faceSmDS->NbElements() : 0;
355 toRemove = helper->IsStructured( faceSm );
357 toRemove = quadAlgo->CheckNbEdges( *helper->GetMesh(),
358 faceSm->GetSubShape() );
359 nbRemoved += toRemove;
361 smIt = notQuadSubMesh.erase( smIt );
371 //=======================================================================
372 //function : StdMeshers_Prism_3D
374 //=======================================================================
376 StdMeshers_Prism_3D::StdMeshers_Prism_3D(int hypId, int studyId, SMESH_Gen* gen)
377 :SMESH_3D_Algo(hypId, studyId, gen)
380 _shapeType = (1 << TopAbs_SOLID); // 1 bit per shape type
381 _onlyUnaryInput = false; // accept all SOLIDs at once
382 _requireDiscreteBoundary = false; // mesh FACEs and EDGEs by myself
383 _supportSubmeshes = true; // "source" FACE must be meshed by other algo
384 _neededLowerHyps[ 1 ] = true; // suppress warning on hiding a global 1D algo
385 _neededLowerHyps[ 2 ] = true; // suppress warning on hiding a global 2D algo
387 //myProjectTriangles = false;
388 mySetErrorToSM = true; // to pass an error to a sub-mesh of a current solid or not
391 //================================================================================
395 //================================================================================
397 StdMeshers_Prism_3D::~StdMeshers_Prism_3D()
400 //=======================================================================
401 //function : CheckHypothesis
403 //=======================================================================
405 bool StdMeshers_Prism_3D::CheckHypothesis(SMESH_Mesh& aMesh,
406 const TopoDS_Shape& aShape,
407 SMESH_Hypothesis::Hypothesis_Status& aStatus)
409 // Check shape geometry
411 aStatus = SMESH_Hypothesis::HYP_BAD_GEOMETRY;
413 // find not quadrangle faces
414 list< TopoDS_Shape > notQuadFaces;
415 int nbEdge, nbWire, nbFace = 0;
416 TopExp_Explorer exp( aShape, TopAbs_FACE );
417 for ( ; exp.More(); exp.Next() ) {
419 const TopoDS_Shape& face = exp.Current();
420 nbEdge = TAssocTool::Count( face, TopAbs_EDGE, 0 );
421 nbWire = TAssocTool::Count( face, TopAbs_WIRE, 0 );
422 if ( nbEdge!= 4 || nbWire!= 1 ) {
423 if ( !notQuadFaces.empty() ) {
424 if ( TAssocTool::Count( notQuadFaces.back(), TopAbs_EDGE, 0 ) != nbEdge ||
425 TAssocTool::Count( notQuadFaces.back(), TopAbs_WIRE, 0 ) != nbWire )
426 RETURN_BAD_RESULT("Different not quad faces");
428 notQuadFaces.push_back( face );
431 if ( !notQuadFaces.empty() )
433 if ( notQuadFaces.size() != 2 )
434 RETURN_BAD_RESULT("Bad nb not quad faces: " << notQuadFaces.size());
436 // check total nb faces
437 nbEdge = TAssocTool::Count( notQuadFaces.back(), TopAbs_EDGE, 0 );
438 if ( nbFace != nbEdge + 2 )
439 RETURN_BAD_RESULT("Bad nb of faces: " << nbFace << " but must be " << nbEdge + 2);
443 aStatus = SMESH_Hypothesis::HYP_OK;
447 //=======================================================================
449 //purpose : Compute mesh on a COMPOUND of SOLIDs
450 //=======================================================================
452 bool StdMeshers_Prism_3D::Compute(SMESH_Mesh& theMesh, const TopoDS_Shape& theShape)
454 SMESH_MesherHelper helper( theMesh );
457 int nbSolids = helper.Count( theShape, TopAbs_SOLID, /*skipSame=*/false );
461 Prism_3D::TPrismTopo prism;
465 return ( initPrism( prism, TopExp_Explorer( theShape, TopAbs_SOLID ).Current() ) &&
469 TopTools_IndexedDataMapOfShapeListOfShape faceToSolids;
470 TopExp::MapShapesAndAncestors( theShape, TopAbs_FACE, TopAbs_SOLID, faceToSolids );
472 // look for meshed FACEs ("source" FACEs) that must be prism bottoms
473 list< TopoDS_Face > meshedFaces, notQuadMeshedFaces;//, notQuadFaces;
474 const bool meshHasQuads = ( theMesh.NbQuadrangles() > 0 );
475 for ( int iF = 1; iF < faceToSolids.Extent(); ++iF )
477 const TopoDS_Face& face = TopoDS::Face( faceToSolids.FindKey( iF ));
478 SMESH_subMesh* faceSM = theMesh.GetSubMesh( face );
479 if ( !faceSM->IsEmpty() )
481 if ( !meshHasQuads ||
482 !helper.IsSameElemGeometry( faceSM->GetSubMeshDS(), SMDSGeom_QUADRANGLE ) ||
483 !helper.IsStructured( faceSM )
485 notQuadMeshedFaces.push_front( face );
486 else if ( myHelper->Count( face, TopAbs_EDGE, /*ignoreSame=*/false ) != 4 )
487 meshedFaces.push_front( face );
489 meshedFaces.push_back( face );
492 // notQuadMeshedFaces are of highest priority
493 meshedFaces.splice( meshedFaces.begin(), notQuadMeshedFaces );
495 // if ( meshedFaces.empty() )
496 // return error( COMPERR_BAD_INPUT_MESH, "No meshed source faces found" );
498 TopTools_MapOfShape meshedSolids;
499 list< Prism_3D::TPrismTopo > meshedPrism;
500 TopTools_ListIteratorOfListOfShape solidIt;
502 while ( meshedSolids.Extent() < nbSolids )
504 if ( _computeCanceled )
505 return toSM( error( SMESH_ComputeError::New(COMPERR_CANCELED)));
507 // compute prisms having avident computed source FACE
508 while ( !meshedFaces.empty() )
510 TopoDS_Face face = meshedFaces.front();
511 meshedFaces.pop_front();
512 TopTools_ListOfShape& solidList = faceToSolids.ChangeFromKey( face );
513 while ( !solidList.IsEmpty() )
515 TopoDS_Shape solid = solidList.First();
516 solidList.RemoveFirst();
517 if ( meshedSolids.Add( solid ))
520 prism.myBottom = face;
521 if ( !initPrism( prism, solid ) ||
525 meshedFaces.push_front( prism.myTop );
526 meshedPrism.push_back( prism );
530 if ( meshedSolids.Extent() == nbSolids )
533 // below in the loop we try to find source FACEs somehow
535 // project mesh from source FACEs of computed prisms to
536 // prisms sharing wall FACEs
537 list< Prism_3D::TPrismTopo >::iterator prismIt = meshedPrism.begin();
538 for ( ; prismIt != meshedPrism.end(); ++prismIt )
540 for ( size_t iW = 0; iW < prismIt->myWallQuads.size(); ++iW )
542 Prism_3D::TQuadList::iterator wQuad = prismIt->myWallQuads[iW].begin();
543 for ( ; wQuad != prismIt->myWallQuads[iW].end(); ++ wQuad )
545 const TopoDS_Face& wFace = (*wQuad)->face;
546 TopTools_ListOfShape& solidList = faceToSolids.ChangeFromKey( wFace );
547 solidIt.Initialize( solidList );
548 while ( solidIt.More() )
550 const TopoDS_Shape& solid = solidIt.Value();
551 if ( meshedSolids.Contains( solid )) {
552 solidList.Remove( solidIt );
553 continue; // already computed prism
555 // find a source FACE of the SOLID: it's a FACE sharing a bottom EDGE with wFace
556 const TopoDS_Edge& wEdge = (*wQuad)->side[ QUAD_TOP_SIDE ]->Edge(0);
557 PShapeIteratorPtr faceIt = myHelper->GetAncestors( wEdge, *myHelper->GetMesh(),
559 while ( const TopoDS_Shape* f = faceIt->next() )
561 const TopoDS_Face& candidateF = TopoDS::Face( *f );
563 prism.myBottom = candidateF;
564 mySetErrorToSM = false;
565 if ( !myHelper->IsSubShape( candidateF, prismIt->myShape3D ) &&
566 !myHelper->GetMesh()->GetSubMesh( candidateF )->IsMeshComputed() &&
567 initPrism( prism, solid ) &&
568 project2dMesh( prismIt->myBottom, candidateF))
570 mySetErrorToSM = true;
571 if ( !compute( prism ))
573 meshedFaces.push_front( prism.myTop );
574 meshedFaces.push_front( prism.myBottom );
575 meshedPrism.push_back( prism );
576 meshedSolids.Add( solid );
580 mySetErrorToSM = true;
582 if ( meshedSolids.Contains( solid ))
583 solidList.Remove( solidIt );
589 if ( !meshedFaces.empty() )
590 break; // to compute prisms with avident sources
593 // find FACEs with local 1D hyps, which has to be computed by now,
594 // or at least any computed FACEs
595 for ( int iF = 1; ( meshedFaces.empty() && iF < faceToSolids.Extent() ); ++iF )
597 const TopoDS_Face& face = TopoDS::Face( faceToSolids.FindKey( iF ));
598 const TopTools_ListOfShape& solidList = faceToSolids.FindFromKey( face );
599 if ( solidList.IsEmpty() ) continue;
600 SMESH_subMesh* faceSM = theMesh.GetSubMesh( face );
601 if ( !faceSM->IsEmpty() )
603 meshedFaces.push_back( face ); // lower priority
607 bool allSubMeComputed = true;
608 SMESH_subMeshIteratorPtr smIt = faceSM->getDependsOnIterator(false,true);
609 while ( smIt->more() && allSubMeComputed )
610 allSubMeComputed = smIt->next()->IsMeshComputed();
611 if ( allSubMeComputed )
613 faceSM->ComputeStateEngine( SMESH_subMesh::COMPUTE );
614 if ( !faceSM->IsEmpty() )
615 meshedFaces.push_front( face ); // higher priority
617 faceSM->ComputeStateEngine( SMESH_subMesh::CHECK_COMPUTE_STATE );
623 // TODO. there are other ways to find out the source FACE:
624 // propagation, topological similarity, ect.
627 if ( meshedFaces.empty() ) // set same error to 10 not-computed solids
629 SMESH_ComputeErrorPtr err = SMESH_ComputeError::New
630 ( COMPERR_BAD_INPUT_MESH, "No meshed source face found", this );
632 const int maxNbErrors = 10; // limit nb errors not to overload the Compute dialog
633 TopExp_Explorer solid( theShape, TopAbs_SOLID );
634 for ( int i = 0; ( i < maxNbErrors && solid.More() ); ++i, solid.Next() )
635 if ( !meshedSolids.Contains( solid.Current() ))
637 SMESH_subMesh* sm = theMesh.GetSubMesh( solid.Current() );
638 sm->GetComputeError() = err;
646 //================================================================================
648 * \brief Find wall faces by bottom edges
650 //================================================================================
652 bool StdMeshers_Prism_3D::getWallFaces( Prism_3D::TPrismTopo & thePrism,
653 const int totalNbFaces)
655 thePrism.myWallQuads.clear();
657 SMESH_Mesh* mesh = myHelper->GetMesh();
659 StdMeshers_Quadrangle_2D* quadAlgo = TQuadrangleAlgo::instance( this, myHelper );
661 TopTools_MapOfShape faceMap;
662 TopTools_IndexedDataMapOfShapeListOfShape edgeToFaces;
663 TopExp::MapShapesAndAncestors( thePrism.myShape3D,
664 TopAbs_EDGE, TopAbs_FACE, edgeToFaces );
666 // ------------------------------
667 // Get the 1st row of wall FACEs
668 // ------------------------------
670 list< TopoDS_Edge >::iterator edge = thePrism.myBottomEdges.begin();
671 std::list< int >::iterator nbE = thePrism.myNbEdgesInWires.begin();
673 while ( edge != thePrism.myBottomEdges.end() )
676 if ( BRep_Tool::Degenerated( *edge ))
678 edge = thePrism.myBottomEdges.erase( edge );
684 TopTools_ListIteratorOfListOfShape faceIt( edgeToFaces.FindFromKey( *edge ));
685 for ( ; faceIt.More(); faceIt.Next() )
687 const TopoDS_Face& face = TopoDS::Face( faceIt.Value() );
688 if ( !thePrism.myBottom.IsSame( face ))
690 Prism_3D::TQuadList quadList( 1, quadAlgo->CheckNbEdges( *mesh, face ));
691 if ( !quadList.back() )
692 return toSM( error(TCom("Side face #") << shapeID( face )
693 << " not meshable with quadrangles"));
694 if ( ! setBottomEdge( *edge, quadList.back(), face ))
695 return toSM( error(TCom("Composite 'horizontal' edges are not supported")));
696 thePrism.myWallQuads.push_back( quadList );
710 // -------------------------
711 // Find the rest wall FACEs
712 // -------------------------
714 // Compose a vector of indixes of right neighbour FACE for each wall FACE
715 // that is not so evident in case of several WIREs in the bottom FACE
716 thePrism.myRightQuadIndex.clear();
717 for ( size_t i = 0; i < thePrism.myWallQuads.size(); ++i )
718 thePrism.myRightQuadIndex.push_back( i+1 );
719 list< int >::iterator nbEinW = thePrism.myNbEdgesInWires.begin();
720 for ( int iLeft = 0; nbEinW != thePrism.myNbEdgesInWires.end(); ++nbEinW )
722 thePrism.myRightQuadIndex[ iLeft + *nbEinW - 1 ] = iLeft; // 1st EDGE index of a current WIRE
726 while ( totalNbFaces - faceMap.Extent() > 2 )
728 // find wall FACEs adjacent to each of wallQuads by the right side EDGE
731 nbKnownFaces = faceMap.Extent();
732 StdMeshers_FaceSide *rightSide, *topSide; // sides of the quad
733 for ( size_t i = 0; i < thePrism.myWallQuads.size(); ++i )
735 rightSide = thePrism.myWallQuads[i].back()->side[ QUAD_RIGHT_SIDE ];
736 for ( int iE = 0; iE < rightSide->NbEdges(); ++iE ) // rightSide can be composite
738 const TopoDS_Edge & rightE = rightSide->Edge( iE );
739 TopTools_ListIteratorOfListOfShape face( edgeToFaces.FindFromKey( rightE ));
740 for ( ; face.More(); face.Next() )
741 if ( faceMap.Add( face.Value() ))
743 // a new wall FACE encountered, store it in thePrism.myWallQuads
744 const int iRight = thePrism.myRightQuadIndex[i];
745 topSide = thePrism.myWallQuads[ iRight ].back()->side[ QUAD_TOP_SIDE ];
746 const TopoDS_Edge& newBotE = topSide->Edge(0);
747 const TopoDS_Shape& newWallF = face.Value();
748 thePrism.myWallQuads[ iRight ].push_back( quadAlgo->CheckNbEdges( *mesh, newWallF ));
749 if ( !thePrism.myWallQuads[ iRight ].back() )
750 return toSM( error(TCom("Side face #") << shapeID( newWallF ) <<
751 " not meshable with quadrangles"));
752 if ( ! setBottomEdge( newBotE, thePrism.myWallQuads[ iRight ].back(), newWallF ))
753 return toSM( error(TCom("Composite 'horizontal' edges are not supported")));
757 } while ( nbKnownFaces != faceMap.Extent() );
759 // find wall FACEs adjacent to each of thePrism.myWallQuads by the top side EDGE
760 if ( totalNbFaces - faceMap.Extent() > 2 )
762 for ( size_t i = 0; i < thePrism.myWallQuads.size(); ++i )
764 StdMeshers_FaceSide* topSide = thePrism.myWallQuads[i].back()->side[ QUAD_TOP_SIDE ];
765 const TopoDS_Edge & topE = topSide->Edge( 0 );
766 if ( topSide->NbEdges() > 1 )
767 return toSM( error(COMPERR_BAD_SHAPE, TCom("Side face #") <<
768 shapeID( thePrism.myWallQuads[i].back()->face )
769 << " has a composite top edge"));
770 TopTools_ListIteratorOfListOfShape faceIt( edgeToFaces.FindFromKey( topE ));
771 for ( ; faceIt.More(); faceIt.Next() )
772 if ( faceMap.Add( faceIt.Value() ))
774 // a new wall FACE encountered, store it in wallQuads
775 thePrism.myWallQuads[ i ].push_back( quadAlgo->CheckNbEdges( *mesh, faceIt.Value() ));
776 if ( !thePrism.myWallQuads[ i ].back() )
777 return toSM( error(TCom("Side face #") << shapeID( faceIt.Value() ) <<
778 " not meshable with quadrangles"));
779 if ( ! setBottomEdge( topE, thePrism.myWallQuads[ i ].back(), faceIt.Value() ))
780 return toSM( error(TCom("Composite 'horizontal' edges are not supported")));
781 if ( totalNbFaces - faceMap.Extent() == 2 )
783 i = thePrism.myWallQuads.size(); // to quit from the outer loop
789 } // while ( totalNbFaces - faceMap.Extent() > 2 )
791 // ------------------
793 // ------------------
795 if ( thePrism.myTop.IsNull() )
797 // now only top and bottom FACEs are not in the faceMap
798 faceMap.Add( thePrism.myBottom );
799 for ( TopExp_Explorer f( thePrism.myShape3D, TopAbs_FACE );f.More(); f.Next() )
800 if ( !faceMap.Contains( f.Current() )) {
801 thePrism.myTop = TopoDS::Face( f.Current() );
804 if ( thePrism.myTop.IsNull() )
805 return toSM( error("Top face not found"));
808 // Check that the top FACE shares all the top EDGEs
809 for ( size_t i = 0; i < thePrism.myWallQuads.size(); ++i )
811 StdMeshers_FaceSide* topSide = thePrism.myWallQuads[i].back()->side[ QUAD_TOP_SIDE ];
812 const TopoDS_Edge & topE = topSide->Edge( 0 );
813 if ( !myHelper->IsSubShape( topE, thePrism.myTop ))
814 return toSM( error( TCom("Wrong source face (#") << shapeID( thePrism.myBottom )));
820 //=======================================================================
822 //purpose : Compute mesh on a SOLID
823 //=======================================================================
825 bool StdMeshers_Prism_3D::compute(const Prism_3D::TPrismTopo& thePrism)
827 myHelper->IsQuadraticSubMesh( thePrism.myShape3D );
828 if ( _computeCanceled )
829 return toSM( error( SMESH_ComputeError::New(COMPERR_CANCELED)));
831 // Make all side FACEs of thePrism meshed with quads
832 if ( !computeWalls( thePrism ))
835 // Analyse mesh and geometry to find block sub-shapes and submeshes
836 if ( !myBlock.Init( myHelper, thePrism ))
837 return toSM( error( myBlock.GetError()));
839 SMESHDS_Mesh* meshDS = myHelper->GetMeshDS();
841 int volumeID = meshDS->ShapeToIndex( thePrism.myShape3D );
844 // To compute coordinates of a node inside a block, it is necessary to know
845 // 1. normalized parameters of the node by which
846 // 2. coordinates of node projections on all block sub-shapes are computed
848 // So we fill projections on vertices at once as they are same for all nodes
849 myShapeXYZ.resize( myBlock.NbSubShapes() );
850 for ( int iV = SMESH_Block::ID_FirstV; iV < SMESH_Block::ID_FirstE; ++iV ) {
851 myBlock.VertexPoint( iV, myShapeXYZ[ iV ]);
852 SHOWYXZ("V point " <<iV << " ", myShapeXYZ[ iV ]);
855 // Projections on the top and bottom faces are taken from nodes existing
856 // on these faces; find correspondence between bottom and top nodes
857 myBotToColumnMap.clear();
858 if ( !assocOrProjBottom2Top() ) // it also fills myBotToColumnMap
862 // Create nodes inside the block
864 // try to use transformation (issue 0020680)
865 vector<gp_Trsf> trsf;
866 if ( myBlock.GetLayersTransformation( trsf, thePrism ))
868 // loop on nodes inside the bottom face
869 TNode2ColumnMap::iterator bot_column = myBotToColumnMap.begin();
870 for ( ; bot_column != myBotToColumnMap.end(); ++bot_column )
872 const Prism_3D::TNode& tBotNode = bot_column->first; // bottom TNode
873 if ( tBotNode.GetPositionType() != SMDS_TOP_FACE )
874 continue; // node is not inside face
876 // column nodes; middle part of the column are zero pointers
877 TNodeColumn& column = bot_column->second;
878 TNodeColumn::iterator columnNodes = column.begin();
879 for ( int z = 0; columnNodes != column.end(); ++columnNodes, ++z)
881 const SMDS_MeshNode* & node = *columnNodes;
882 if ( node ) continue; // skip bottom or top node
884 gp_XYZ coords = tBotNode.GetCoords();
885 trsf[z-1].Transforms( coords );
886 node = meshDS->AddNode( coords.X(), coords.Y(), coords.Z() );
887 meshDS->SetNodeInVolume( node, volumeID );
889 } // loop on bottom nodes
891 else // use block approach
893 // loop on nodes inside the bottom face
894 Prism_3D::TNode prevBNode;
895 TNode2ColumnMap::iterator bot_column = myBotToColumnMap.begin();
896 for ( ; bot_column != myBotToColumnMap.end(); ++bot_column )
898 const Prism_3D::TNode& tBotNode = bot_column->first; // bottom TNode
899 if ( tBotNode.GetPositionType() != SMDS_TOP_FACE )
900 continue; // node is not inside face
902 // column nodes; middle part of the column are zero pointers
903 TNodeColumn& column = bot_column->second;
905 // compute bottom node parameters
906 gp_XYZ paramHint(-1,-1,-1);
907 if ( prevBNode.IsNeighbor( tBotNode ))
908 paramHint = prevBNode.GetParams();
909 if ( !myBlock.ComputeParameters( tBotNode.GetCoords(), tBotNode.ChangeParams(),
910 ID_BOT_FACE, paramHint ))
911 return toSM( error(TCom("Can't compute normalized parameters for node ")
912 << tBotNode.myNode->GetID() << " on the face #"
913 << myBlock.SubMesh( ID_BOT_FACE )->GetId() ));
914 prevBNode = tBotNode;
916 myShapeXYZ[ ID_BOT_FACE ] = tBotNode.GetCoords();
917 gp_XYZ botParams = tBotNode.GetParams();
919 // compute top node parameters
920 myShapeXYZ[ ID_TOP_FACE ] = gpXYZ( column.back() );
921 gp_XYZ topParams = botParams;
923 if ( column.size() > 2 ) {
924 gp_Pnt topCoords = myShapeXYZ[ ID_TOP_FACE ];
925 if ( !myBlock.ComputeParameters( topCoords, topParams, ID_TOP_FACE, topParams ))
926 return toSM( error(TCom("Can't compute normalized parameters ")
927 << "for node " << column.back()->GetID()
928 << " on the face #"<< column.back()->getshapeId() ));
932 TNodeColumn::iterator columnNodes = column.begin();
933 for ( int z = 0; columnNodes != column.end(); ++columnNodes, ++z)
935 const SMDS_MeshNode* & node = *columnNodes;
936 if ( node ) continue; // skip bottom or top node
938 // params of a node to create
939 double rz = (double) z / (double) ( column.size() - 1 );
940 gp_XYZ params = botParams * ( 1 - rz ) + topParams * rz;
942 // set coords on all faces and nodes
943 const int nbSideFaces = 4;
944 int sideFaceIDs[nbSideFaces] = { SMESH_Block::ID_Fx0z,
945 SMESH_Block::ID_Fx1z,
946 SMESH_Block::ID_F0yz,
947 SMESH_Block::ID_F1yz };
948 for ( int iF = 0; iF < nbSideFaces; ++iF )
949 if ( !setFaceAndEdgesXYZ( sideFaceIDs[ iF ], params, z ))
952 // compute coords for a new node
954 if ( !SMESH_Block::ShellPoint( params, myShapeXYZ, coords ))
955 return toSM( error("Can't compute coordinates by normalized parameters"));
957 SHOWYXZ("TOPFacePoint ",myShapeXYZ[ ID_TOP_FACE]);
958 SHOWYXZ("BOT Node "<< tBotNode.myNode->GetID(),gpXYZ(tBotNode.myNode));
959 SHOWYXZ("ShellPoint ",coords);
962 node = meshDS->AddNode( coords.X(), coords.Y(), coords.Z() );
963 meshDS->SetNodeInVolume( node, volumeID );
965 } // loop on bottom nodes
970 SMESHDS_SubMesh* smDS = myBlock.SubMeshDS( ID_BOT_FACE );
971 if ( !smDS ) return toSM( error(COMPERR_BAD_INPUT_MESH, "Null submesh"));
973 // loop on bottom mesh faces
974 SMDS_ElemIteratorPtr faceIt = smDS->GetElements();
975 while ( faceIt->more() )
977 const SMDS_MeshElement* face = faceIt->next();
978 if ( !face || face->GetType() != SMDSAbs_Face )
981 // find node columns for each node
982 int nbNodes = face->NbCornerNodes();
983 vector< const TNodeColumn* > columns( nbNodes );
984 for ( int i = 0; i < nbNodes; ++i )
986 const SMDS_MeshNode* n = face->GetNode( i );
987 if ( n->GetPosition()->GetTypeOfPosition() == SMDS_TOP_FACE ) {
988 TNode2ColumnMap::iterator bot_column = myBotToColumnMap.find( n );
989 if ( bot_column == myBotToColumnMap.end() )
990 return toSM( error(TCom("No nodes found above node ") << n->GetID() ));
991 columns[ i ] = & bot_column->second;
994 columns[ i ] = myBlock.GetNodeColumn( n );
996 return toSM( error(TCom("No side nodes found above node ") << n->GetID() ));
1000 AddPrisms( columns, myHelper );
1002 } // loop on bottom mesh faces
1005 myBotToColumnMap.clear();
1011 //=======================================================================
1012 //function : computeWalls
1013 //purpose : Compute 2D mesh on walls FACEs of a prism
1014 //=======================================================================
1016 bool StdMeshers_Prism_3D::computeWalls(const Prism_3D::TPrismTopo& thePrism)
1018 SMESH_Mesh* mesh = myHelper->GetMesh();
1019 SMESHDS_Mesh* meshDS = myHelper->GetMeshDS();
1021 TProjction1dAlgo* projector1D = TProjction1dAlgo::instance( this );
1022 StdMeshers_Quadrangle_2D* quadAlgo = TQuadrangleAlgo::instance( this, myHelper );
1024 SMESH_HypoFilter hyp1dFilter( SMESH_HypoFilter::IsAlgo(),/*not=*/true);
1025 hyp1dFilter.And( SMESH_HypoFilter::HasDim( 1 ));
1026 hyp1dFilter.And( SMESH_HypoFilter::IsMoreLocalThan( thePrism.myShape3D, *mesh ));
1028 // Discretize equally 'vertical' EDGEs
1029 // -----------------------------------
1030 // find source FACE sides for projection: either already computed ones or
1031 // the 'most composite' ones
1032 multimap< int, int > wgt2quad;
1033 for ( size_t iW = 0; iW != thePrism.myWallQuads.size(); ++iW )
1035 Prism_3D::TQuadList::const_iterator quad = thePrism.myWallQuads[iW].begin();
1036 int wgt = 0; // "weight"
1037 for ( ; quad != thePrism.myWallQuads[iW].end(); ++quad )
1039 StdMeshers_FaceSide* lftSide = (*quad)->side[ QUAD_LEFT_SIDE ];
1040 for ( int i = 0; i < lftSide->NbEdges(); ++i )
1043 const TopoDS_Edge& E = lftSide->Edge(i);
1044 if ( mesh->GetSubMesh( E )->IsMeshComputed() )
1046 else if ( mesh->GetHypothesis( E, hyp1dFilter, true )) // local hypothesis!
1050 wgt2quad.insert( make_pair( wgt, iW ));
1052 // in quadratic mesh, pass ignoreMediumNodes to quad sides
1053 if ( myHelper->GetIsQuadratic() )
1055 quad = thePrism.myWallQuads[iW].begin();
1056 for ( ; quad != thePrism.myWallQuads[iW].end(); ++quad )
1057 for ( int i = 0; i < NB_QUAD_SIDES; ++i )
1058 (*quad)->side[ i ]->SetIgnoreMediumNodes( true );
1062 // Project 'vertical' EDGEs, from left to right
1063 multimap< int, int >::reverse_iterator w2q = wgt2quad.rbegin();
1064 for ( ; w2q != wgt2quad.rend(); ++w2q )
1066 const int iW = w2q->second;
1067 const Prism_3D::TQuadList& quads = thePrism.myWallQuads[ iW ];
1068 Prism_3D::TQuadList::const_iterator quad = quads.begin();
1069 for ( ; quad != quads.end(); ++quad )
1071 StdMeshers_FaceSide* rgtSide = (*quad)->side[ QUAD_RIGHT_SIDE ]; // tgt
1072 StdMeshers_FaceSide* lftSide = (*quad)->side[ QUAD_LEFT_SIDE ]; // src
1073 bool swapLeftRight = ( lftSide->NbSegments( /*update=*/true ) == 0 &&
1074 rgtSide->NbSegments( /*update=*/true ) > 0 );
1075 if ( swapLeftRight )
1076 std::swap( lftSide, rgtSide );
1078 // assure that all the source (left) EDGEs are meshed
1079 int nbSrcSegments = 0;
1080 for ( int i = 0; i < lftSide->NbEdges(); ++i )
1082 const TopoDS_Edge& srcE = lftSide->Edge(i);
1083 SMESH_subMesh* srcSM = mesh->GetSubMesh( srcE );
1084 if ( !srcSM->IsMeshComputed() ) {
1085 srcSM->ComputeSubMeshStateEngine( SMESH_subMesh::COMPUTE );
1086 srcSM->ComputeStateEngine ( SMESH_subMesh::COMPUTE );
1087 if ( !srcSM->IsMeshComputed() )
1090 nbSrcSegments += srcSM->GetSubMeshDS()->NbElements();
1092 // check target EDGEs
1093 int nbTgtMeshed = 0, nbTgtSegments = 0;
1094 vector< bool > isTgtEdgeComputed( rgtSide->NbEdges() );
1095 for ( int i = 0; i < rgtSide->NbEdges(); ++i )
1097 const TopoDS_Edge& tgtE = rgtSide->Edge(i);
1098 SMESH_subMesh* tgtSM = mesh->GetSubMesh( tgtE );
1099 if (( isTgtEdgeComputed[ i ] = tgtSM->IsMeshComputed() )) {
1101 nbTgtSegments += tgtSM->GetSubMeshDS()->NbElements();
1104 if ( rgtSide->NbEdges() == nbTgtMeshed ) // all tgt EDGEs meshed
1106 if ( nbTgtSegments != nbSrcSegments )
1108 for ( int i = 0; i < lftSide->NbEdges(); ++i )
1109 addBadInputElements( meshDS->MeshElements( lftSide->Edge( i )));
1110 for ( int i = 0; i < rgtSide->NbEdges(); ++i )
1111 addBadInputElements( meshDS->MeshElements( rgtSide->Edge( i )));
1112 return toSM( error( TCom("Different nb of segment on logically vertical edges #")
1113 << shapeID( lftSide->Edge(0) ) << " and #"
1114 << shapeID( rgtSide->Edge(0) ) << ": "
1115 << nbSrcSegments << " != " << nbTgtSegments ));
1120 if ( nbTgtMeshed == 0 )
1122 // compute nodes on target VERTEXes
1123 const UVPtStructVec& srcNodeStr = lftSide->GetUVPtStruct();
1124 if ( srcNodeStr.size() == 0 )
1125 return toSM( error( TCom("Invalid node positions on edge #") <<
1126 shapeID( lftSide->Edge(0) )));
1127 vector< SMDS_MeshNode* > newNodes( srcNodeStr.size() );
1128 for ( int is2ndV = 0; is2ndV < 2; ++is2ndV )
1130 const TopoDS_Edge& E = rgtSide->Edge( is2ndV ? rgtSide->NbEdges()-1 : 0 );
1131 TopoDS_Vertex v = myHelper->IthVertex( is2ndV, E );
1132 mesh->GetSubMesh( v )->ComputeStateEngine( SMESH_subMesh::COMPUTE );
1133 const SMDS_MeshNode* n = SMESH_Algo::VertexNode( v, meshDS );
1134 newNodes[ is2ndV ? 0 : newNodes.size()-1 ] = (SMDS_MeshNode*) n;
1137 // compute nodes on target EDGEs
1138 rgtSide->Reverse(); // direct it same as the lftSide
1139 myHelper->SetElementsOnShape( false );
1140 TopoDS_Edge tgtEdge;
1141 for ( size_t iN = 1; iN < srcNodeStr.size()-1; ++iN ) // add nodes
1143 gp_Pnt p = rgtSide->Value3d ( srcNodeStr[ iN ].normParam );
1144 double u = rgtSide->Parameter( srcNodeStr[ iN ].normParam, tgtEdge );
1145 newNodes[ iN ] = meshDS->AddNode( p.X(), p.Y(), p.Z() );
1146 meshDS->SetNodeOnEdge( newNodes[ iN ], tgtEdge, u );
1148 for ( size_t iN = 1; iN < srcNodeStr.size(); ++iN ) // add segments
1150 SMDS_MeshElement* newEdge = myHelper->AddEdge( newNodes[ iN-1 ], newNodes[ iN ] );
1151 std::pair<int, TopAbs_ShapeEnum> id2type =
1152 myHelper->GetMediumPos( newNodes[ iN-1 ], newNodes[ iN ] );
1153 if ( id2type.second == TopAbs_EDGE )
1155 meshDS->SetMeshElementOnShape( newEdge, id2type.first );
1157 else // new nodes are on different EDGEs; put one of them on VERTEX
1159 const int edgeIndex = rgtSide->EdgeIndex( srcNodeStr[ iN-1 ].normParam );
1160 const double vertexParam = rgtSide->LastParameter( edgeIndex );
1161 const gp_Pnt p = BRep_Tool::Pnt( rgtSide->LastVertex( edgeIndex ));
1162 const int isPrev = ( Abs( srcNodeStr[ iN-1 ].normParam - vertexParam ) <
1163 Abs( srcNodeStr[ iN ].normParam - vertexParam ));
1164 meshDS->SetMeshElementOnShape( newEdge, newNodes[ iN-(1-isPrev) ]->getshapeId() );
1165 meshDS->UnSetNodeOnShape( newNodes[ iN-isPrev ] );
1166 meshDS->SetNodeOnVertex ( newNodes[ iN-isPrev ], rgtSide->LastVertex( edgeIndex ));
1167 meshDS->MoveNode( newNodes[ iN-isPrev ], p.X(), p.Y(), p.Z() );
1170 myHelper->SetElementsOnShape( true );
1171 for ( int i = 0; i < rgtSide->NbEdges(); ++i ) // update state of sub-meshes
1173 const TopoDS_Edge& E = rgtSide->Edge( i );
1174 SMESH_subMesh* tgtSM = mesh->GetSubMesh( E );
1175 tgtSM->ComputeStateEngine( SMESH_subMesh::CHECK_COMPUTE_STATE );
1178 // to continue projection from the just computed side as a source
1179 if ( !swapLeftRight && rgtSide->NbEdges() > 1 && w2q->second == iW )
1181 std::pair<int,int> wgt2quadKeyVal( w2q->first + 1, thePrism.myRightQuadIndex[ iW ]);
1182 wgt2quad.insert( wgt2quadKeyVal ); // it will be skipped by ++w2q
1183 wgt2quad.insert( wgt2quadKeyVal );
1184 w2q = wgt2quad.rbegin();
1189 // HOPE assigned hypotheses are OK, so that equal nb of segments will be generated
1190 //return toSM( error("Partial projection not implemented"));
1192 } // loop on quads of a composite wall side
1193 } // loop on the ordered wall sides
1197 for ( size_t iW = 0; iW != thePrism.myWallQuads.size(); ++iW )
1199 Prism_3D::TQuadList::const_iterator quad = thePrism.myWallQuads[iW].begin();
1200 for ( ; quad != thePrism.myWallQuads[iW].end(); ++quad )
1202 // Top EDGEs must be projections from the bottom ones
1203 // to compute stuctured quad mesh on wall FACEs
1204 // ---------------------------------------------------
1205 const TopoDS_Edge& botE = (*quad)->side[ QUAD_BOTTOM_SIDE ]->Edge(0);
1206 const TopoDS_Edge& topE = (*quad)->side[ QUAD_TOP_SIDE ]->Edge(0);
1208 projector1D->myHyp.SetSourceEdge( botE );
1210 SMESH_subMesh* tgtEdgeSm = mesh->GetSubMesh( topE );
1211 if ( !tgtEdgeSm->IsMeshComputed() )
1213 // compute nodes on VERTEXes
1214 tgtEdgeSm->ComputeSubMeshStateEngine( SMESH_subMesh::COMPUTE );
1216 projector1D->InitComputeError();
1217 bool ok = projector1D->Compute( *mesh, topE );
1220 SMESH_ComputeErrorPtr err = projector1D->GetComputeError();
1221 if ( err->IsOK() ) err->myName = COMPERR_ALGO_FAILED;
1222 tgtEdgeSm->GetComputeError() = err;
1226 tgtEdgeSm->ComputeStateEngine( SMESH_subMesh::CHECK_COMPUTE_STATE );
1228 // Compute quad mesh on wall FACEs
1229 // -------------------------------
1230 const TopoDS_Face& face = (*quad)->face;
1231 SMESH_subMesh* fSM = mesh->GetSubMesh( face );
1232 if ( ! fSM->IsMeshComputed() )
1234 // make all EDGES meshed
1235 fSM->ComputeSubMeshStateEngine( SMESH_subMesh::COMPUTE );
1236 if ( !fSM->SubMeshesComputed() )
1237 return toSM( error( COMPERR_BAD_INPUT_MESH,
1238 "Not all edges have valid algorithm and hypothesis"));
1240 quadAlgo->InitComputeError();
1241 bool ok = quadAlgo->Compute( *mesh, face );
1242 fSM->GetComputeError() = quadAlgo->GetComputeError();
1245 fSM->ComputeStateEngine( SMESH_subMesh::CHECK_COMPUTE_STATE );
1247 if ( myHelper->GetIsQuadratic() )
1249 // fill myHelper with medium nodes built by quadAlgo
1250 SMDS_ElemIteratorPtr fIt = fSM->GetSubMeshDS()->GetElements();
1251 while ( fIt->more() )
1252 myHelper->AddTLinks( dynamic_cast<const SMDS_MeshFace*>( fIt->next() ));
1260 //=======================================================================
1261 //function : Evaluate
1263 //=======================================================================
1265 bool StdMeshers_Prism_3D::Evaluate(SMESH_Mesh& theMesh,
1266 const TopoDS_Shape& theShape,
1267 MapShapeNbElems& aResMap)
1269 if ( theShape.ShapeType() == TopAbs_COMPOUND )
1272 for ( TopoDS_Iterator it( theShape ); it.More(); it.Next() )
1273 ok &= Evaluate( theMesh, it.Value(), aResMap );
1276 SMESH_MesherHelper helper( theMesh );
1278 myHelper->SetSubShape( theShape );
1280 // find face contains only triangles
1281 vector < SMESH_subMesh * >meshFaces;
1282 TopTools_SequenceOfShape aFaces;
1283 int NumBase = 0, i = 0, NbQFs = 0;
1284 for (TopExp_Explorer exp(theShape, TopAbs_FACE); exp.More(); exp.Next()) {
1286 aFaces.Append(exp.Current());
1287 SMESH_subMesh *aSubMesh = theMesh.GetSubMesh(exp.Current());
1288 meshFaces.push_back(aSubMesh);
1289 MapShapeNbElemsItr anIt = aResMap.find(meshFaces[i-1]);
1290 if( anIt==aResMap.end() )
1291 return toSM( error( "Submesh can not be evaluated"));
1293 std::vector<int> aVec = (*anIt).second;
1294 int nbtri = Max(aVec[SMDSEntity_Triangle],aVec[SMDSEntity_Quad_Triangle]);
1295 int nbqua = Max(aVec[SMDSEntity_Quadrangle],aVec[SMDSEntity_Quad_Quadrangle]);
1296 if( nbtri==0 && nbqua>0 ) {
1305 std::vector<int> aResVec(SMDSEntity_Last);
1306 for(int i=SMDSEntity_Node; i<SMDSEntity_Last; i++) aResVec[i] = 0;
1307 SMESH_subMesh * sm = theMesh.GetSubMesh(theShape);
1308 aResMap.insert(std::make_pair(sm,aResVec));
1309 return toSM( error( "Submesh can not be evaluated" ));
1312 if(NumBase==0) NumBase = 1; // only quads => set 1 faces as base
1314 // find number of 1d elems for base face
1316 TopTools_MapOfShape Edges1;
1317 for (TopExp_Explorer exp(aFaces.Value(NumBase), TopAbs_EDGE); exp.More(); exp.Next()) {
1318 Edges1.Add(exp.Current());
1319 SMESH_subMesh *sm = theMesh.GetSubMesh(exp.Current());
1321 MapShapeNbElemsItr anIt = aResMap.find(sm);
1322 if( anIt == aResMap.end() ) continue;
1323 std::vector<int> aVec = (*anIt).second;
1324 nb1d += Max(aVec[SMDSEntity_Edge],aVec[SMDSEntity_Quad_Edge]);
1327 // find face opposite to base face
1329 for(i=1; i<=6; i++) {
1330 if(i==NumBase) continue;
1331 bool IsOpposite = true;
1332 for(TopExp_Explorer exp(aFaces.Value(i), TopAbs_EDGE); exp.More(); exp.Next()) {
1333 if( Edges1.Contains(exp.Current()) ) {
1343 // find number of 2d elems on side faces
1345 for(i=1; i<=6; i++) {
1346 if( i==OppNum || i==NumBase ) continue;
1347 MapShapeNbElemsItr anIt = aResMap.find( meshFaces[i-1] );
1348 if( anIt == aResMap.end() ) continue;
1349 std::vector<int> aVec = (*anIt).second;
1350 nb2d += Max(aVec[SMDSEntity_Quadrangle],aVec[SMDSEntity_Quad_Quadrangle]);
1353 MapShapeNbElemsItr anIt = aResMap.find( meshFaces[NumBase-1] );
1354 std::vector<int> aVec = (*anIt).second;
1355 bool IsQuadratic = (aVec[SMDSEntity_Quad_Triangle]>aVec[SMDSEntity_Triangle]) ||
1356 (aVec[SMDSEntity_Quad_Quadrangle]>aVec[SMDSEntity_Quadrangle]);
1357 int nb2d_face0_3 = Max(aVec[SMDSEntity_Triangle],aVec[SMDSEntity_Quad_Triangle]);
1358 int nb2d_face0_4 = Max(aVec[SMDSEntity_Quadrangle],aVec[SMDSEntity_Quad_Quadrangle]);
1359 int nb0d_face0 = aVec[SMDSEntity_Node];
1360 int nb1d_face0_int = ( nb2d_face0_3*3 + nb2d_face0_4*4 - nb1d ) / 2;
1362 std::vector<int> aResVec(SMDSEntity_Last);
1363 for(int i=SMDSEntity_Node; i<SMDSEntity_Last; i++) aResVec[i] = 0;
1365 aResVec[SMDSEntity_Quad_Penta] = nb2d_face0_3 * ( nb2d/nb1d );
1366 aResVec[SMDSEntity_Quad_Hexa] = nb2d_face0_4 * ( nb2d/nb1d );
1367 aResVec[SMDSEntity_Node] = nb0d_face0 * ( 2*nb2d/nb1d - 1 ) - nb1d_face0_int * nb2d/nb1d;
1370 aResVec[SMDSEntity_Node] = nb0d_face0 * ( nb2d/nb1d - 1 );
1371 aResVec[SMDSEntity_Penta] = nb2d_face0_3 * ( nb2d/nb1d );
1372 aResVec[SMDSEntity_Hexa] = nb2d_face0_4 * ( nb2d/nb1d );
1374 SMESH_subMesh * sm = theMesh.GetSubMesh(theShape);
1375 aResMap.insert(std::make_pair(sm,aResVec));
1380 //================================================================================
1382 * \brief Create prisms
1383 * \param columns - columns of nodes generated from nodes of a mesh face
1384 * \param helper - helper initialized by mesh and shape to add prisms to
1386 //================================================================================
1388 void StdMeshers_Prism_3D::AddPrisms( vector<const TNodeColumn*> & columns,
1389 SMESH_MesherHelper* helper)
1391 int nbNodes = columns.size();
1392 int nbZ = columns[0]->size();
1393 if ( nbZ < 2 ) return;
1395 // find out orientation
1396 bool isForward = true;
1397 SMDS_VolumeTool vTool;
1399 switch ( nbNodes ) {
1401 SMDS_VolumeOfNodes tmpPenta ( (*columns[0])[z-1], // bottom
1404 (*columns[0])[z], // top
1407 vTool.Set( &tmpPenta );
1408 isForward = vTool.IsForward();
1412 SMDS_VolumeOfNodes tmpHex( (*columns[0])[z-1], (*columns[1])[z-1], // bottom
1413 (*columns[2])[z-1], (*columns[3])[z-1],
1414 (*columns[0])[z], (*columns[1])[z], // top
1415 (*columns[2])[z], (*columns[3])[z] );
1416 vTool.Set( &tmpHex );
1417 isForward = vTool.IsForward();
1421 const int di = (nbNodes+1) / 3;
1422 SMDS_VolumeOfNodes tmpVol ( (*columns[0] )[z-1],
1423 (*columns[di] )[z-1],
1424 (*columns[2*di])[z-1],
1427 (*columns[2*di])[z] );
1428 vTool.Set( &tmpVol );
1429 isForward = vTool.IsForward();
1432 // vertical loop on columns
1434 helper->SetElementsOnShape( true );
1436 switch ( nbNodes ) {
1438 case 3: { // ---------- pentahedra
1439 const int i1 = isForward ? 1 : 2;
1440 const int i2 = isForward ? 2 : 1;
1441 for ( z = 1; z < nbZ; ++z )
1442 helper->AddVolume( (*columns[0 ])[z-1], // bottom
1443 (*columns[i1])[z-1],
1444 (*columns[i2])[z-1],
1445 (*columns[0 ])[z], // top
1447 (*columns[i2])[z] );
1450 case 4: { // ---------- hexahedra
1451 const int i1 = isForward ? 1 : 3;
1452 const int i3 = isForward ? 3 : 1;
1453 for ( z = 1; z < nbZ; ++z )
1454 helper->AddVolume( (*columns[0])[z-1], (*columns[i1])[z-1], // bottom
1455 (*columns[2])[z-1], (*columns[i3])[z-1],
1456 (*columns[0])[z], (*columns[i1])[z], // top
1457 (*columns[2])[z], (*columns[i3])[z] );
1460 case 6: { // ---------- octahedra
1461 const int iBase1 = isForward ? -1 : 0;
1462 const int iBase2 = isForward ? 0 :-1;
1463 for ( z = 1; z < nbZ; ++z )
1464 helper->AddVolume( (*columns[0])[z+iBase1], (*columns[1])[z+iBase1], // bottom or top
1465 (*columns[2])[z+iBase1], (*columns[3])[z+iBase1],
1466 (*columns[4])[z+iBase1], (*columns[5])[z+iBase1],
1467 (*columns[0])[z+iBase2], (*columns[1])[z+iBase2], // top or bottom
1468 (*columns[2])[z+iBase2], (*columns[3])[z+iBase2],
1469 (*columns[4])[z+iBase2], (*columns[5])[z+iBase2] );
1472 default: // ---------- polyhedra
1473 vector<int> quantities( 2 + nbNodes, 4 );
1474 quantities[0] = quantities[1] = nbNodes;
1475 columns.resize( nbNodes + 1 );
1476 columns[ nbNodes ] = columns[ 0 ];
1477 const int i1 = isForward ? 1 : 3;
1478 const int i3 = isForward ? 3 : 1;
1479 const int iBase1 = isForward ? -1 : 0;
1480 const int iBase2 = isForward ? 0 :-1;
1481 vector<const SMDS_MeshNode*> nodes( 2*nbNodes + 4*nbNodes);
1482 for ( z = 1; z < nbZ; ++z )
1484 for ( int i = 0; i < nbNodes; ++i ) {
1485 nodes[ i ] = (*columns[ i ])[z+iBase1]; // bottom or top
1486 nodes[ 2*nbNodes-i-1 ] = (*columns[ i ])[z+iBase2]; // top or bottom
1488 int di = 2*nbNodes + 4*i;
1489 nodes[ di+0 ] = (*columns[i ])[z ];
1490 nodes[ di+i1] = (*columns[i+1])[z ];
1491 nodes[ di+2 ] = (*columns[i+1])[z-1];
1492 nodes[ di+i3] = (*columns[i ])[z-1];
1494 helper->AddPolyhedralVolume( nodes, quantities );
1497 } // switch ( nbNodes )
1500 //================================================================================
1502 * \brief Find correspondence between bottom and top nodes
1503 * If elements on the bottom and top faces are topologically different,
1504 * and projection is possible and allowed, perform the projection
1505 * \retval bool - is a success or not
1507 //================================================================================
1509 bool StdMeshers_Prism_3D::assocOrProjBottom2Top()
1511 SMESH_subMesh * botSM = myBlock.SubMesh( ID_BOT_FACE );
1512 SMESH_subMesh * topSM = myBlock.SubMesh( ID_TOP_FACE );
1514 SMESHDS_SubMesh * botSMDS = botSM->GetSubMeshDS();
1515 SMESHDS_SubMesh * topSMDS = topSM->GetSubMeshDS();
1517 if ( !botSMDS || botSMDS->NbElements() == 0 )
1519 _gen->Compute( *myHelper->GetMesh(), botSM->GetSubShape() );
1520 botSMDS = botSM->GetSubMeshDS();
1521 if ( !botSMDS || botSMDS->NbElements() == 0 )
1522 return toSM( error(TCom("No elememts on face #") << botSM->GetId() ));
1525 bool needProject = !topSM->IsMeshComputed();
1526 if ( !needProject &&
1527 (botSMDS->NbElements() != topSMDS->NbElements() ||
1528 botSMDS->NbNodes() != topSMDS->NbNodes()))
1530 MESSAGE("nb elem bot " << botSMDS->NbElements() <<
1531 " top " << ( topSMDS ? topSMDS->NbElements() : 0 ));
1532 MESSAGE("nb node bot " << botSMDS->NbNodes() <<
1533 " top " << ( topSMDS ? topSMDS->NbNodes() : 0 ));
1534 return toSM( error(TCom("Mesh on faces #") << botSM->GetId()
1535 <<" and #"<< topSM->GetId() << " seems different" ));
1538 if ( 0/*needProject && !myProjectTriangles*/ )
1539 return toSM( error(TCom("Mesh on faces #") << botSM->GetId()
1540 <<" and #"<< topSM->GetId() << " seems different" ));
1541 ///RETURN_BAD_RESULT("Need to project but not allowed");
1545 return projectBottomToTop();
1548 TopoDS_Face botFace = TopoDS::Face( myBlock.Shape( ID_BOT_FACE ));
1549 TopoDS_Face topFace = TopoDS::Face( myBlock.Shape( ID_TOP_FACE ));
1550 // associate top and bottom faces
1551 TAssocTool::TShapeShapeMap shape2ShapeMap;
1552 if ( !TAssocTool::FindSubShapeAssociation( botFace, myBlock.Mesh(),
1553 topFace, myBlock.Mesh(),
1555 return toSM( error(TCom("Topology of faces #") << botSM->GetId()
1556 <<" and #"<< topSM->GetId() << " seems different" ));
1558 // Find matching nodes of top and bottom faces
1559 TNodeNodeMap n2nMap;
1560 if ( ! TAssocTool::FindMatchingNodesOnFaces( botFace, myBlock.Mesh(),
1561 topFace, myBlock.Mesh(),
1562 shape2ShapeMap, n2nMap ))
1563 return toSM( error(TCom("Mesh on faces #") << botSM->GetId()
1564 <<" and #"<< topSM->GetId() << " seems different" ));
1566 // Fill myBotToColumnMap
1568 int zSize = myBlock.VerticalSize();
1570 TNodeNodeMap::iterator bN_tN = n2nMap.begin();
1571 for ( ; bN_tN != n2nMap.end(); ++bN_tN )
1573 const SMDS_MeshNode* botNode = bN_tN->first;
1574 const SMDS_MeshNode* topNode = bN_tN->second;
1575 if ( botNode->GetPosition()->GetTypeOfPosition() != SMDS_TOP_FACE )
1576 continue; // wall columns are contained in myBlock
1577 // create node column
1578 Prism_3D::TNode bN( botNode );
1579 TNode2ColumnMap::iterator bN_col =
1580 myBotToColumnMap.insert( make_pair ( bN, TNodeColumn() )).first;
1581 TNodeColumn & column = bN_col->second;
1582 column.resize( zSize );
1583 column.front() = botNode;
1584 column.back() = topNode;
1589 //================================================================================
1591 * \brief Remove quadrangles from the top face and
1592 * create triangles there by projection from the bottom
1593 * \retval bool - a success or not
1595 //================================================================================
1597 bool StdMeshers_Prism_3D::projectBottomToTop()
1599 SMESHDS_Mesh* meshDS = myBlock.MeshDS();
1600 SMESH_subMesh * botSM = myBlock.SubMesh( ID_BOT_FACE );
1601 SMESH_subMesh * topSM = myBlock.SubMesh( ID_TOP_FACE );
1603 SMESHDS_SubMesh * botSMDS = botSM->GetSubMeshDS();
1604 SMESHDS_SubMesh * topSMDS = topSM->GetSubMeshDS();
1606 if ( topSMDS && topSMDS->NbElements() > 0 )
1607 topSM->ComputeStateEngine( SMESH_subMesh::CLEAN );
1609 const TopoDS_Shape& botFace = myBlock.Shape( ID_BOT_FACE ); // oriented within the 3D SHAPE
1610 const TopoDS_Shape& topFace = myBlock.Shape( ID_TOP_FACE);
1611 int topFaceID = meshDS->ShapeToIndex( topFace );
1613 // Fill myBotToColumnMap
1615 int zSize = myBlock.VerticalSize();
1616 Prism_3D::TNode prevTNode;
1617 SMDS_NodeIteratorPtr nIt = botSMDS->GetNodes();
1618 while ( nIt->more() )
1620 const SMDS_MeshNode* botNode = nIt->next();
1621 if ( botNode->GetPosition()->GetTypeOfPosition() != SMDS_TOP_FACE )
1622 continue; // strange
1623 // compute bottom node params
1624 Prism_3D::TNode bN( botNode );
1625 gp_XYZ paramHint(-1,-1,-1);
1626 if ( prevTNode.IsNeighbor( bN ))
1627 paramHint = prevTNode.GetParams();
1628 if ( !myBlock.ComputeParameters( bN.GetCoords(), bN.ChangeParams(),
1629 ID_BOT_FACE, paramHint ))
1630 return toSM( error(TCom("Can't compute normalized parameters for node ")
1631 << botNode->GetID() << " on the face #"<< botSM->GetId() ));
1633 // compute top node coords
1634 gp_XYZ topXYZ; gp_XY topUV;
1635 if ( !myBlock.FacePoint( ID_TOP_FACE, bN.GetParams(), topXYZ ) ||
1636 !myBlock.FaceUV ( ID_TOP_FACE, bN.GetParams(), topUV ))
1637 return toSM( error(TCom("Can't compute coordinates "
1638 "by normalized parameters on the face #")<< topSM->GetId() ));
1639 SMDS_MeshNode * topNode = meshDS->AddNode( topXYZ.X(),topXYZ.Y(),topXYZ.Z() );
1640 meshDS->SetNodeOnFace( topNode, topFaceID, topUV.X(), topUV.Y() );
1641 // create node column
1642 TNode2ColumnMap::iterator bN_col =
1643 myBotToColumnMap.insert( make_pair ( bN, TNodeColumn() )).first;
1644 TNodeColumn & column = bN_col->second;
1645 column.resize( zSize );
1646 column.front() = botNode;
1647 column.back() = topNode;
1652 const bool oldSetElemsOnShape = myHelper->SetElementsOnShape( false );
1654 // care of orientation;
1655 // if the bottom faces is orienetd OK then top faces must be reversed
1656 bool reverseTop = true;
1657 if ( myHelper->NbAncestors( botFace, *myBlock.Mesh(), TopAbs_SOLID ) > 1 )
1658 reverseTop = ! myHelper->IsReversedSubMesh( TopoDS::Face( botFace ));
1659 int iFrw, iRev, *iPtr = &( reverseTop ? iRev : iFrw );
1661 // loop on bottom mesh faces
1662 SMDS_ElemIteratorPtr faceIt = botSMDS->GetElements();
1663 vector< const SMDS_MeshNode* > nodes;
1664 while ( faceIt->more() )
1666 const SMDS_MeshElement* face = faceIt->next();
1667 if ( !face || face->GetType() != SMDSAbs_Face )
1670 // find top node in columns for each bottom node
1671 int nbNodes = face->NbCornerNodes();
1672 nodes.resize( nbNodes );
1673 for ( iFrw = 0, iRev = nbNodes-1; iFrw < nbNodes; ++iFrw, --iRev )
1675 const SMDS_MeshNode* n = face->GetNode( *iPtr );
1676 if ( n->GetPosition()->GetTypeOfPosition() == SMDS_TOP_FACE ) {
1677 TNode2ColumnMap::iterator bot_column = myBotToColumnMap.find( n );
1678 if ( bot_column == myBotToColumnMap.end() )
1679 return toSM( error(TCom("No nodes found above node ") << n->GetID() ));
1680 nodes[ iFrw ] = bot_column->second.back();
1683 const TNodeColumn* column = myBlock.GetNodeColumn( n );
1685 return toSM( error(TCom("No side nodes found above node ") << n->GetID() ));
1686 nodes[ iFrw ] = column->back();
1689 SMDS_MeshElement* newFace = 0;
1690 switch ( nbNodes ) {
1693 newFace = myHelper->AddFace(nodes[0], nodes[1], nodes[2]);
1697 newFace = myHelper->AddFace( nodes[0], nodes[1], nodes[2], nodes[3] );
1701 newFace = meshDS->AddPolygonalFace( nodes );
1704 meshDS->SetMeshElementOnShape( newFace, topFaceID );
1707 myHelper->SetElementsOnShape( oldSetElemsOnShape );
1712 //=======================================================================
1713 //function : project2dMesh
1714 //purpose : Project mesh faces from a source FACE of one prism (theSrcFace)
1715 // to a source FACE of another prism (theTgtFace)
1716 //=======================================================================
1718 bool StdMeshers_Prism_3D::project2dMesh(const TopoDS_Face& theSrcFace,
1719 const TopoDS_Face& theTgtFace)
1721 TProjction2dAlgo* projector2D = TProjction2dAlgo::instance( this );
1722 projector2D->myHyp.SetSourceFace( theSrcFace );
1723 bool ok = projector2D->Compute( *myHelper->GetMesh(), theTgtFace );
1725 SMESH_subMesh* tgtSM = myHelper->GetMesh()->GetSubMesh( theTgtFace );
1726 tgtSM->ComputeStateEngine ( SMESH_subMesh::CHECK_COMPUTE_STATE );
1727 tgtSM->ComputeSubMeshStateEngine( SMESH_subMesh::CHECK_COMPUTE_STATE );
1732 //================================================================================
1734 * \brief Set projection coordinates of a node to a face and it's sub-shapes
1735 * \param faceID - the face given by in-block ID
1736 * \param params - node normalized parameters
1737 * \retval bool - is a success
1739 //================================================================================
1741 bool StdMeshers_Prism_3D::setFaceAndEdgesXYZ( const int faceID, const gp_XYZ& params, int z )
1743 // find base and top edges of the face
1744 enum { BASE = 0, TOP, LEFT, RIGHT };
1745 vector< int > edgeVec; // 0-base, 1-top
1746 SMESH_Block::GetFaceEdgesIDs( faceID, edgeVec );
1748 myBlock.EdgePoint( edgeVec[ BASE ], params, myShapeXYZ[ edgeVec[ BASE ]]);
1749 myBlock.EdgePoint( edgeVec[ TOP ], params, myShapeXYZ[ edgeVec[ TOP ]]);
1751 SHOWYXZ("\nparams ", params);
1752 SHOWYXZ("TOP is " <<edgeVec[ TOP ], myShapeXYZ[ edgeVec[ TOP]]);
1753 SHOWYXZ("BASE is "<<edgeVec[ BASE], myShapeXYZ[ edgeVec[ BASE]]);
1755 if ( faceID == SMESH_Block::ID_Fx0z || faceID == SMESH_Block::ID_Fx1z )
1757 myBlock.EdgePoint( edgeVec[ LEFT ], params, myShapeXYZ[ edgeVec[ LEFT ]]);
1758 myBlock.EdgePoint( edgeVec[ RIGHT ], params, myShapeXYZ[ edgeVec[ RIGHT ]]);
1760 SHOWYXZ("VER "<<edgeVec[ LEFT], myShapeXYZ[ edgeVec[ LEFT]]);
1761 SHOWYXZ("VER "<<edgeVec[ RIGHT], myShapeXYZ[ edgeVec[ RIGHT]]);
1763 myBlock.FacePoint( faceID, params, myShapeXYZ[ faceID ]);
1764 SHOWYXZ("FacePoint "<<faceID, myShapeXYZ[ faceID]);
1769 //=======================================================================
1771 //purpose : If (!isOK), sets the error to a sub-mesh of a current SOLID
1772 //=======================================================================
1774 bool StdMeshers_Prism_3D::toSM( bool isOK )
1776 if ( mySetErrorToSM &&
1779 !myHelper->GetSubShape().IsNull() &&
1780 myHelper->GetSubShape().ShapeType() == TopAbs_SOLID)
1782 SMESH_subMesh* sm = myHelper->GetMesh()->GetSubMesh( myHelper->GetSubShape() );
1783 sm->GetComputeError() = this->GetComputeError();
1784 // clear error in order not to return it twice
1785 _error = COMPERR_OK;
1791 //=======================================================================
1792 //function : shapeID
1793 //purpose : Return index of a shape
1794 //=======================================================================
1796 int StdMeshers_Prism_3D::shapeID( const TopoDS_Shape& S )
1798 if ( S.IsNull() ) return 0;
1799 if ( !myHelper ) return -3;
1800 return myHelper->GetMeshDS()->ShapeToIndex( S );
1805 //================================================================================
1807 * \brief Return true if this node and other one belong to one face
1809 //================================================================================
1811 bool Prism_3D::TNode::IsNeighbor( const Prism_3D::TNode& other ) const
1813 if ( !other.myNode || !myNode ) return false;
1815 SMDS_ElemIteratorPtr fIt = other.myNode->GetInverseElementIterator(SMDSAbs_Face);
1816 while ( fIt->more() )
1817 if ( fIt->next()->GetNodeIndex( myNode ) >= 0 )
1822 //================================================================================
1824 * \brief Prism initialization
1826 //================================================================================
1828 void TPrismTopo::Clear()
1830 myShape3D.Nullify();
1833 myWallQuads.clear();
1834 myBottomEdges.clear();
1835 myNbEdgesInWires.clear();
1836 myWallQuads.clear();
1839 } // namespace Prism_3D
1841 //================================================================================
1843 * \brief Constructor. Initialization is needed
1845 //================================================================================
1847 StdMeshers_PrismAsBlock::StdMeshers_PrismAsBlock()
1852 StdMeshers_PrismAsBlock::~StdMeshers_PrismAsBlock()
1856 void StdMeshers_PrismAsBlock::Clear()
1859 myShapeIDMap.Clear();
1863 delete mySide; mySide = 0;
1865 myParam2ColumnMaps.clear();
1866 myShapeIndex2ColumnMap.clear();
1869 //=======================================================================
1870 //function : initPrism
1871 //purpose : Analyse shape geometry and mesh.
1872 // If there are triangles on one of faces, it becomes 'bottom'.
1873 // thePrism.myBottom can be already set up.
1874 //=======================================================================
1876 bool StdMeshers_Prism_3D::initPrism(Prism_3D::TPrismTopo& thePrism,
1877 const TopoDS_Shape& shape3D)
1879 myHelper->SetSubShape( shape3D );
1881 SMESH_subMesh* mainSubMesh = myHelper->GetMesh()->GetSubMeshContaining( shape3D );
1882 if ( !mainSubMesh ) return toSM( error(COMPERR_BAD_INPUT_MESH,"Null submesh of shape3D"));
1884 // detect not-quad FACE sub-meshes of the 3D SHAPE
1885 list< SMESH_subMesh* > notQuadGeomSubMesh;
1886 list< SMESH_subMesh* > notQuadElemSubMesh;
1889 SMESH_subMesh* anyFaceSM = 0;
1890 SMESH_subMeshIteratorPtr smIt = mainSubMesh->getDependsOnIterator(false,true);
1891 while ( smIt->more() )
1893 SMESH_subMesh* sm = smIt->next();
1894 const TopoDS_Shape& face = sm->GetSubShape();
1895 if ( face.ShapeType() > TopAbs_FACE ) break;
1896 else if ( face.ShapeType() < TopAbs_FACE ) continue;
1900 // is quadrangle FACE?
1901 list< TopoDS_Edge > orderedEdges;
1902 list< int > nbEdgesInWires;
1903 int nbWires = SMESH_Block::GetOrderedEdges( TopoDS::Face( face ), orderedEdges,
1905 if ( nbWires != 1 || nbEdgesInWires.front() != 4 )
1906 notQuadGeomSubMesh.push_back( sm );
1908 // look for not quadrangle mesh elements
1909 if ( SMESHDS_SubMesh* smDS = sm->GetSubMeshDS() )
1910 if ( !myHelper->IsSameElemGeometry( smDS, SMDSGeom_QUADRANGLE ))
1911 notQuadElemSubMesh.push_back( sm );
1914 int nbNotQuadMeshed = notQuadElemSubMesh.size();
1915 int nbNotQuad = notQuadGeomSubMesh.size();
1916 bool hasNotQuad = ( nbNotQuad || nbNotQuadMeshed );
1919 if ( nbNotQuadMeshed > 2 )
1921 return toSM( error(COMPERR_BAD_INPUT_MESH,
1922 TCom("More than 2 faces with not quadrangle elements: ")
1923 <<nbNotQuadMeshed));
1925 if ( nbNotQuad > 2 || !thePrism.myBottom.IsNull() )
1927 // Issue 0020843 - one of side FACEs is quasi-quadrilateral (not 4 EDGEs).
1928 // Remove from notQuadGeomSubMesh faces meshed with regular grid
1929 int nbQuasiQuads = removeQuasiQuads( notQuadGeomSubMesh, myHelper,
1930 TQuadrangleAlgo::instance(this,myHelper) );
1931 nbNotQuad -= nbQuasiQuads;
1932 if ( nbNotQuad > 2 )
1933 return toSM( error(COMPERR_BAD_SHAPE,
1934 TCom("More than 2 not quadrilateral faces: ") <<nbNotQuad));
1935 hasNotQuad = ( nbNotQuad || nbNotQuadMeshed );
1938 // Analyse mesh and topology of FACEs: choose the bottom sub-mesh.
1939 // If there are not quadrangle FACEs, they are top and bottom ones.
1940 // Not quadrangle FACEs must be only on top and bottom.
1942 SMESH_subMesh * botSM = 0;
1943 SMESH_subMesh * topSM = 0;
1945 if ( hasNotQuad ) // can chose a bottom FACE
1947 if ( nbNotQuadMeshed > 0 ) botSM = notQuadElemSubMesh.front();
1948 else botSM = notQuadGeomSubMesh.front();
1949 if ( nbNotQuadMeshed > 1 ) topSM = notQuadElemSubMesh.back();
1950 else if ( nbNotQuad > 1 ) topSM = notQuadGeomSubMesh.back();
1952 if ( topSM == botSM ) {
1953 if ( nbNotQuadMeshed > 1 ) topSM = notQuadElemSubMesh.front();
1954 else topSM = notQuadGeomSubMesh.front();
1957 // detect mesh triangles on wall FACEs
1958 if ( nbNotQuad == 2 && nbNotQuadMeshed > 0 ) {
1960 if ( nbNotQuadMeshed == 1 )
1961 ok = ( find( notQuadGeomSubMesh.begin(),
1962 notQuadGeomSubMesh.end(), botSM ) != notQuadGeomSubMesh.end() );
1964 ok = ( notQuadGeomSubMesh == notQuadElemSubMesh );
1966 return toSM( error(COMPERR_BAD_INPUT_MESH,
1967 "Side face meshed with not quadrangle elements"));
1971 thePrism.myNotQuadOnTop = ( nbNotQuadMeshed > 1 );
1973 // use thePrism.myBottom
1974 if ( !thePrism.myBottom.IsNull() )
1977 if ( ! botSM->GetSubShape().IsSame( thePrism.myBottom )) {
1978 std::swap( botSM, topSM );
1979 if ( ! botSM->GetSubShape().IsSame( thePrism.myBottom ))
1980 return toSM( error( COMPERR_BAD_INPUT_MESH,
1981 "Incompatible non-structured sub-meshes"));
1985 botSM = myHelper->GetMesh()->GetSubMesh( thePrism.myBottom );
1988 else if ( !botSM ) // find a proper bottom
1990 // composite walls or not prism shape
1991 for ( TopExp_Explorer f( shape3D, TopAbs_FACE ); f.More(); f.Next() )
1993 int minNbFaces = 2 + myHelper->Count( f.Current(), TopAbs_EDGE, false);
1994 if ( nbFaces >= minNbFaces)
1997 thePrism.myBottom = TopoDS::Face( f.Current() );
1998 if ( initPrism( thePrism, shape3D ))
2001 return toSM( error( COMPERR_BAD_SHAPE ));
2005 // find vertex 000 - the one with smallest coordinates (for easy DEBUG :-)
2007 double minVal = DBL_MAX, minX, val;
2008 for ( TopExp_Explorer exp( botSM->GetSubShape(), TopAbs_VERTEX );
2009 exp.More(); exp.Next() )
2011 const TopoDS_Vertex& v = TopoDS::Vertex( exp.Current() );
2012 gp_Pnt P = BRep_Tool::Pnt( v );
2013 val = P.X() + P.Y() + P.Z();
2014 if ( val < minVal || ( val == minVal && P.X() < minX )) {
2021 thePrism.myShape3D = shape3D;
2022 if ( thePrism.myBottom.IsNull() )
2023 thePrism.myBottom = TopoDS::Face( botSM->GetSubShape() );
2024 thePrism.myBottom.Orientation( myHelper->GetSubShapeOri( shape3D,
2025 thePrism.myBottom ));
2026 // Get ordered bottom edges
2027 TopoDS_Face reverseBottom = // to have order of top EDGEs as in the top FACE
2028 TopoDS::Face( thePrism.myBottom.Reversed() );
2029 SMESH_Block::GetOrderedEdges( reverseBottom,
2030 thePrism.myBottomEdges,
2031 thePrism.myNbEdgesInWires, V000 );
2033 // Get Wall faces corresponding to the ordered bottom edges and the top FACE
2034 if ( !getWallFaces( thePrism, nbFaces ))
2035 return false; //toSM( error(COMPERR_BAD_SHAPE, "Can't find side faces"));
2039 if ( !thePrism.myTop.IsSame( topSM->GetSubShape() ))
2041 (notQuadGeomSubMesh.empty() ? COMPERR_BAD_INPUT_MESH : COMPERR_BAD_SHAPE,
2042 "Non-quadrilateral faces are not opposite"));
2044 // check that the found top and bottom FACEs are opposite
2045 list< TopoDS_Edge >::iterator edge = thePrism.myBottomEdges.begin();
2046 for ( ; edge != thePrism.myBottomEdges.end(); ++edge )
2047 if ( myHelper->IsSubShape( *edge, thePrism.myTop ))
2049 (notQuadGeomSubMesh.empty() ? COMPERR_BAD_INPUT_MESH : COMPERR_BAD_SHAPE,
2050 "Non-quadrilateral faces are not opposite"));
2056 //================================================================================
2058 * \brief Initialization.
2059 * \param helper - helper loaded with mesh and 3D shape
2060 * \param thePrism - a prosm data
2061 * \retval bool - false if a mesh or a shape are KO
2063 //================================================================================
2065 bool StdMeshers_PrismAsBlock::Init(SMESH_MesherHelper* helper,
2066 const Prism_3D::TPrismTopo& thePrism)
2069 delete mySide; mySide = 0;
2071 vector< TSideFace* > sideFaces( NB_WALL_FACES, 0 );
2072 vector< pair< double, double> > params( NB_WALL_FACES );
2073 mySide = new TSideFace( sideFaces, params );
2076 SMESHDS_Mesh* meshDS = myHelper->GetMeshDS();
2078 SMESH_Block::init();
2079 myShapeIDMap.Clear();
2080 myShapeIndex2ColumnMap.clear();
2082 int wallFaceIds[ NB_WALL_FACES ] = { // to walk around a block
2083 SMESH_Block::ID_Fx0z, SMESH_Block::ID_F1yz,
2084 SMESH_Block::ID_Fx1z, SMESH_Block::ID_F0yz
2087 myError = SMESH_ComputeError::New();
2089 myNotQuadOnTop = thePrism.myNotQuadOnTop;
2091 // Find columns of wall nodes and calculate edges' lengths
2092 // --------------------------------------------------------
2094 myParam2ColumnMaps.clear();
2095 myParam2ColumnMaps.resize( thePrism.myBottomEdges.size() ); // total nb edges
2097 size_t iE, nbEdges = thePrism.myNbEdgesInWires.front(); // nb outer edges
2098 vector< double > edgeLength( nbEdges );
2099 multimap< double, int > len2edgeMap;
2101 list< TopoDS_Edge >::const_iterator edgeIt = thePrism.myBottomEdges.begin();
2102 for ( iE = 0; iE < nbEdges; ++iE, ++edgeIt )
2104 TParam2ColumnMap & faceColumns = myParam2ColumnMaps[ iE ];
2106 Prism_3D::TQuadList::const_iterator quad = thePrism.myWallQuads[ iE ].begin();
2107 for ( ; quad != thePrism.myWallQuads[ iE ].end(); ++quad )
2109 const TopoDS_Edge& quadBot = (*quad)->side[ QUAD_BOTTOM_SIDE ]->Edge( 0 );
2110 if ( !myHelper->LoadNodeColumns( faceColumns, (*quad)->face, quadBot, meshDS ))
2111 return error(COMPERR_BAD_INPUT_MESH, TCom("Can't find regular quadrangle mesh ")
2112 << "on a side face #" << MeshDS()->ShapeToIndex( (*quad)->face ));
2114 SHOWYXZ("\np1 F " <<iE, gpXYZ(faceColumns.begin()->second.front() ));
2115 SHOWYXZ("p2 F " <<iE, gpXYZ(faceColumns.rbegin()->second.front() ));
2116 SHOWYXZ("V First "<<iE, BRep_Tool::Pnt( TopExp::FirstVertex(*edgeIt,true )));
2118 edgeLength[ iE ] = SMESH_Algo::EdgeLength( *edgeIt );
2120 if ( nbEdges < NB_WALL_FACES ) // fill map used to split faces
2122 SMESHDS_SubMesh* smDS = meshDS->MeshElements( *edgeIt);
2124 return error(COMPERR_BAD_INPUT_MESH, TCom("Null submesh on the edge #")
2125 << MeshDS()->ShapeToIndex( *edgeIt ));
2126 len2edgeMap.insert( make_pair( edgeLength[ iE ], iE ));
2129 // Load columns of internal edges (forming holes)
2130 // and fill map ShapeIndex to TParam2ColumnMap for them
2131 for ( ; edgeIt != thePrism.myBottomEdges.end() ; ++edgeIt, ++iE )
2133 TParam2ColumnMap & faceColumns = myParam2ColumnMaps[ iE ];
2135 Prism_3D::TQuadList::const_iterator quad = thePrism.myWallQuads[ iE ].begin();
2136 for ( ; quad != thePrism.myWallQuads[ iE ].end(); ++quad )
2138 const TopoDS_Edge& quadBot = (*quad)->side[ QUAD_BOTTOM_SIDE ]->Edge( 0 );
2139 if ( !myHelper->LoadNodeColumns( faceColumns, (*quad)->face, quadBot, meshDS ))
2140 return error(COMPERR_BAD_INPUT_MESH, TCom("Can't find regular quadrangle mesh ")
2141 << "on a side face #" << MeshDS()->ShapeToIndex( (*quad)->face ));
2144 int id = MeshDS()->ShapeToIndex( *edgeIt );
2145 bool isForward = true; // meaningless for intenal wires
2146 myShapeIndex2ColumnMap[ id ] = make_pair( & faceColumns, isForward );
2147 // columns for vertices
2149 const SMDS_MeshNode* n0 = faceColumns.begin()->second.front();
2150 id = n0->getshapeId();
2151 myShapeIndex2ColumnMap[ id ] = make_pair( & faceColumns, isForward );
2153 const SMDS_MeshNode* n1 = faceColumns.rbegin()->second.front();
2154 id = n1->getshapeId();
2155 myShapeIndex2ColumnMap[ id ] = make_pair( & faceColumns, isForward );
2157 // SHOWYXZ("\np1 F " <<iE, gpXYZ(faceColumns.begin()->second.front() ));
2158 // SHOWYXZ("p2 F " <<iE, gpXYZ(faceColumns.rbegin()->second.front() ));
2159 // SHOWYXZ("V First "<<iE, BRep_Tool::Pnt( TopExp::FirstVertex(*edgeIt,true )));
2162 // Create 4 wall faces of a block
2163 // -------------------------------
2165 if ( nbEdges <= NB_WALL_FACES ) // ************* Split faces if necessary
2167 map< int, int > iE2nbSplit;
2168 if ( nbEdges != NB_WALL_FACES ) // define how to split
2170 if ( len2edgeMap.size() != nbEdges )
2171 RETURN_BAD_RESULT("Uniqueness of edge lengths not assured");
2172 map< double, int >::reverse_iterator maxLen_i = len2edgeMap.rbegin();
2173 map< double, int >::reverse_iterator midLen_i = ++len2edgeMap.rbegin();
2174 double maxLen = maxLen_i->first;
2175 double midLen = ( len2edgeMap.size() == 1 ) ? 0 : midLen_i->first;
2176 switch ( nbEdges ) {
2177 case 1: // 0-th edge is split into 4 parts
2178 iE2nbSplit.insert( make_pair( 0, 4 )); break;
2179 case 2: // either the longest edge is split into 3 parts, or both edges into halves
2180 if ( maxLen / 3 > midLen / 2 ) {
2181 iE2nbSplit.insert( make_pair( maxLen_i->second, 3 ));
2184 iE2nbSplit.insert( make_pair( maxLen_i->second, 2 ));
2185 iE2nbSplit.insert( make_pair( midLen_i->second, 2 ));
2189 // split longest into halves
2190 iE2nbSplit.insert( make_pair( maxLen_i->second, 2 ));
2193 // Create TSideFace's
2195 list< TopoDS_Edge >::const_iterator botE = thePrism.myBottomEdges.begin();
2196 for ( iE = 0; iE < nbEdges; ++iE, ++botE )
2198 TFaceQuadStructPtr quad = thePrism.myWallQuads[ iE ].front();
2200 map< int, int >::iterator i_nb = iE2nbSplit.find( iE );
2201 if ( i_nb != iE2nbSplit.end() ) {
2203 int nbSplit = i_nb->second;
2204 vector< double > params;
2205 splitParams( nbSplit, &myParam2ColumnMaps[ iE ], params );
2206 const bool isForward =
2207 StdMeshers_PrismAsBlock::IsForwardEdge( myHelper->GetMeshDS(),
2208 myParam2ColumnMaps[iE],
2209 *botE, SMESH_Block::ID_Fx0z );
2210 for ( int i = 0; i < nbSplit; ++i ) {
2211 double f = ( isForward ? params[ i ] : params[ nbSplit - i-1 ]);
2212 double l = ( isForward ? params[ i+1 ] : params[ nbSplit - i ]);
2213 TSideFace* comp = new TSideFace( myHelper, wallFaceIds[ iSide ],
2214 thePrism.myWallQuads[ iE ], *botE,
2215 &myParam2ColumnMaps[ iE ], f, l );
2216 mySide->SetComponent( iSide++, comp );
2220 TSideFace* comp = new TSideFace( myHelper, wallFaceIds[ iSide ],
2221 thePrism.myWallQuads[ iE ], *botE,
2222 &myParam2ColumnMaps[ iE ]);
2223 mySide->SetComponent( iSide++, comp );
2227 else { // **************************** Unite faces
2229 // unite first faces
2230 int nbExraFaces = nbEdges - 3;
2232 double u0 = 0, sumLen = 0;
2233 for ( iE = 0; iE < nbExraFaces; ++iE )
2234 sumLen += edgeLength[ iE ];
2236 vector< TSideFace* > components( nbExraFaces );
2237 vector< pair< double, double> > params( nbExraFaces );
2238 list< TopoDS_Edge >::const_iterator botE = thePrism.myBottomEdges.begin();
2239 for ( iE = 0; iE < nbExraFaces; ++iE, ++botE )
2241 components[ iE ] = new TSideFace( myHelper, wallFaceIds[ iSide ],
2242 thePrism.myWallQuads[ iE ], *botE,
2243 &myParam2ColumnMaps[ iE ]);
2244 double u1 = u0 + edgeLength[ iE ] / sumLen;
2245 params[ iE ] = make_pair( u0 , u1 );
2248 mySide->SetComponent( iSide++, new TSideFace( components, params ));
2250 // fill the rest faces
2251 for ( ; iE < nbEdges; ++iE, ++botE )
2253 TSideFace* comp = new TSideFace( myHelper, wallFaceIds[ iSide ],
2254 thePrism.myWallQuads[ iE ], *botE,
2255 &myParam2ColumnMaps[ iE ]);
2256 mySide->SetComponent( iSide++, comp );
2261 // Fill geometry fields of SMESH_Block
2262 // ------------------------------------
2264 vector< int > botEdgeIdVec;
2265 SMESH_Block::GetFaceEdgesIDs( ID_BOT_FACE, botEdgeIdVec );
2267 bool isForward[NB_WALL_FACES] = { true, true, true, true };
2268 Adaptor2d_Curve2d* botPcurves[NB_WALL_FACES];
2269 Adaptor2d_Curve2d* topPcurves[NB_WALL_FACES];
2271 for ( int iF = 0; iF < NB_WALL_FACES; ++iF )
2273 TSideFace * sideFace = mySide->GetComponent( iF );
2275 RETURN_BAD_RESULT("NULL TSideFace");
2276 int fID = sideFace->FaceID(); // in-block ID
2278 // fill myShapeIDMap
2279 if ( sideFace->InsertSubShapes( myShapeIDMap ) != 8 &&
2280 !sideFace->IsComplex())
2281 MESSAGE( ": Warning : InsertSubShapes() < 8 on side " << iF );
2283 // side faces geometry
2284 Adaptor2d_Curve2d* pcurves[NB_WALL_FACES];
2285 if ( !sideFace->GetPCurves( pcurves ))
2286 RETURN_BAD_RESULT("TSideFace::GetPCurves() failed");
2288 SMESH_Block::TFace& tFace = myFace[ fID - ID_FirstF ];
2289 tFace.Set( fID, sideFace->Surface(), pcurves, isForward );
2291 SHOWYXZ( endl<<"F "<< iF << " id " << fID << " FRW " << sideFace->IsForward(), sideFace->Value(0,0));
2292 // edges 3D geometry
2293 vector< int > edgeIdVec;
2294 SMESH_Block::GetFaceEdgesIDs( fID, edgeIdVec );
2295 for ( int isMax = 0; isMax < 2; ++isMax ) {
2297 int eID = edgeIdVec[ isMax ];
2298 SMESH_Block::TEdge& tEdge = myEdge[ eID - ID_FirstE ];
2299 tEdge.Set( eID, sideFace->HorizCurve(isMax), true);
2300 SHOWYXZ(eID<<" HOR"<<isMax<<"(0)", sideFace->HorizCurve(isMax)->Value(0));
2301 SHOWYXZ(eID<<" HOR"<<isMax<<"(1)", sideFace->HorizCurve(isMax)->Value(1));
2304 int eID = edgeIdVec[ isMax+2 ];
2305 SMESH_Block::TEdge& tEdge = myEdge[ eID - ID_FirstE ];
2306 tEdge.Set( eID, sideFace->VertiCurve(isMax), true);
2307 SHOWYXZ(eID<<" VER"<<isMax<<"(0)", sideFace->VertiCurve(isMax)->Value(0));
2308 SHOWYXZ(eID<<" VER"<<isMax<<"(1)", sideFace->VertiCurve(isMax)->Value(1));
2311 vector< int > vertexIdVec;
2312 SMESH_Block::GetEdgeVertexIDs( eID, vertexIdVec );
2313 myPnt[ vertexIdVec[0] - ID_FirstV ] = tEdge.GetCurve()->Value(0).XYZ();
2314 myPnt[ vertexIdVec[1] - ID_FirstV ] = tEdge.GetCurve()->Value(1).XYZ();
2317 // pcurves on horizontal faces
2318 for ( iE = 0; iE < NB_WALL_FACES; ++iE ) {
2319 if ( edgeIdVec[ BOTTOM_EDGE ] == botEdgeIdVec[ iE ] ) {
2320 botPcurves[ iE ] = sideFace->HorizPCurve( false, thePrism.myBottom );
2321 topPcurves[ iE ] = sideFace->HorizPCurve( true, thePrism.myTop );
2325 //sideFace->dumpNodes( 4 ); // debug
2327 // horizontal faces geometry
2329 SMESH_Block::TFace& tFace = myFace[ ID_BOT_FACE - ID_FirstF ];
2330 tFace.Set( ID_BOT_FACE, new BRepAdaptor_Surface( thePrism.myBottom ), botPcurves, isForward );
2331 SMESH_Block::Insert( thePrism.myBottom, ID_BOT_FACE, myShapeIDMap );
2334 SMESH_Block::TFace& tFace = myFace[ ID_TOP_FACE - ID_FirstF ];
2335 tFace.Set( ID_TOP_FACE, new BRepAdaptor_Surface( thePrism.myTop ), topPcurves, isForward );
2336 SMESH_Block::Insert( thePrism.myTop, ID_TOP_FACE, myShapeIDMap );
2339 // Fill map ShapeIndex to TParam2ColumnMap
2340 // ----------------------------------------
2342 list< TSideFace* > fList;
2343 list< TSideFace* >::iterator fListIt;
2344 fList.push_back( mySide );
2345 for ( fListIt = fList.begin(); fListIt != fList.end(); ++fListIt)
2347 int nb = (*fListIt)->NbComponents();
2348 for ( int i = 0; i < nb; ++i ) {
2349 if ( TSideFace* comp = (*fListIt)->GetComponent( i ))
2350 fList.push_back( comp );
2352 if ( TParam2ColumnMap* cols = (*fListIt)->GetColumns()) {
2353 // columns for a base edge
2354 int id = MeshDS()->ShapeToIndex( (*fListIt)->BaseEdge() );
2355 bool isForward = (*fListIt)->IsForward();
2356 myShapeIndex2ColumnMap[ id ] = make_pair( cols, isForward );
2358 // columns for vertices
2359 const SMDS_MeshNode* n0 = cols->begin()->second.front();
2360 id = n0->getshapeId();
2361 myShapeIndex2ColumnMap[ id ] = make_pair( cols, isForward );
2363 const SMDS_MeshNode* n1 = cols->rbegin()->second.front();
2364 id = n1->getshapeId();
2365 myShapeIndex2ColumnMap[ id ] = make_pair( cols, !isForward );
2369 // gp_XYZ testPar(0.25, 0.25, 0), testCoord;
2370 // if ( !FacePoint( ID_BOT_FACE, testPar, testCoord ))
2371 // RETURN_BAD_RESULT("TEST FacePoint() FAILED");
2372 // SHOWYXZ("IN TEST PARAM" , testPar);
2373 // SHOWYXZ("OUT TEST CORD" , testCoord);
2374 // if ( !ComputeParameters( testCoord, testPar , ID_BOT_FACE))
2375 // RETURN_BAD_RESULT("TEST ComputeParameters() FAILED");
2376 // SHOWYXZ("OUT TEST PARAM" , testPar);
2381 //================================================================================
2383 * \brief Return pointer to column of nodes
2384 * \param node - bottom node from which the returned column goes up
2385 * \retval const TNodeColumn* - the found column
2387 //================================================================================
2389 const TNodeColumn* StdMeshers_PrismAsBlock::GetNodeColumn(const SMDS_MeshNode* node) const
2391 int sID = node->getshapeId();
2393 map<int, pair< TParam2ColumnMap*, bool > >::const_iterator col_frw =
2394 myShapeIndex2ColumnMap.find( sID );
2395 if ( col_frw != myShapeIndex2ColumnMap.end() ) {
2396 const TParam2ColumnMap* cols = col_frw->second.first;
2397 TParam2ColumnIt u_col = cols->begin();
2398 for ( ; u_col != cols->end(); ++u_col )
2399 if ( u_col->second[ 0 ] == node )
2400 return & u_col->second;
2405 //=======================================================================
2406 //function : GetLayersTransformation
2407 //purpose : Return transformations to get coordinates of nodes of each layer
2408 // by nodes of the bottom. Layer is a set of nodes at a certain step
2409 // from bottom to top.
2410 //=======================================================================
2412 bool StdMeshers_PrismAsBlock::GetLayersTransformation(vector<gp_Trsf> & trsf,
2413 const Prism_3D::TPrismTopo& prism) const
2415 const int zSize = VerticalSize();
2416 if ( zSize < 3 ) return true;
2417 trsf.resize( zSize - 2 );
2419 // Select some node columns by which we will define coordinate system of layers
2421 vector< const TNodeColumn* > columns;
2424 list< TopoDS_Edge >::const_iterator edgeIt = prism.myBottomEdges.begin();
2425 for ( int iE = 0; iE < prism.myNbEdgesInWires.front(); ++iE, ++edgeIt )
2427 if ( BRep_Tool::Degenerated( *edgeIt )) continue;
2428 const TParam2ColumnMap* u2colMap =
2429 GetParam2ColumnMap( MeshDS()->ShapeToIndex( *edgeIt ), isReverse );
2430 if ( !u2colMap ) return false;
2431 double f = u2colMap->begin()->first, l = u2colMap->rbegin()->first;
2432 //isReverse = ( edgeIt->Orientation() == TopAbs_REVERSED );
2433 //if ( isReverse ) swap ( f, l ); -- u2colMap takes orientation into account
2434 const int nbCol = 5;
2435 for ( int i = 0; i < nbCol; ++i )
2437 double u = f + i/double(nbCol) * ( l - f );
2438 const TNodeColumn* col = & getColumn( u2colMap, u )->second;
2439 if ( columns.empty() || col != columns.back() )
2440 columns.push_back( col );
2445 // Find tolerance to check transformations
2450 for ( int i = 0; i < columns.size(); ++i )
2451 bndBox.Add( gpXYZ( columns[i]->front() ));
2452 tol2 = bndBox.SquareExtent() * 1e-5;
2455 // Compute transformations
2458 gp_Trsf fromCsZ, toCs0;
2459 gp_Ax3 cs0 = getLayerCoordSys(0, columns, xCol );
2460 //double dist0 = cs0.Location().Distance( gpXYZ( (*columns[0])[0]));
2461 toCs0.SetTransformation( cs0 );
2462 for ( int z = 1; z < zSize-1; ++z )
2464 gp_Ax3 csZ = getLayerCoordSys(z, columns, xCol );
2465 //double distZ = csZ.Location().Distance( gpXYZ( (*columns[0])[z]));
2466 fromCsZ.SetTransformation( csZ );
2468 gp_Trsf& t = trsf[ z-1 ];
2469 t = fromCsZ * toCs0;
2470 //t.SetScaleFactor( distZ/dist0 ); - it does not work properly, wrong base point
2472 // check a transformation
2473 for ( int i = 0; i < columns.size(); ++i )
2475 gp_Pnt p0 = gpXYZ( (*columns[i])[0] );
2476 gp_Pnt pz = gpXYZ( (*columns[i])[z] );
2477 t.Transforms( p0.ChangeCoord() );
2478 if ( p0.SquareDistance( pz ) > tol2 )
2485 //================================================================================
2487 * \brief Check curve orientation of a bootom edge
2488 * \param meshDS - mesh DS
2489 * \param columnsMap - node columns map of side face
2490 * \param bottomEdge - the bootom edge
2491 * \param sideFaceID - side face in-block ID
2492 * \retval bool - true if orientation coinside with in-block forward orientation
2494 //================================================================================
2496 bool StdMeshers_PrismAsBlock::IsForwardEdge(SMESHDS_Mesh* meshDS,
2497 const TParam2ColumnMap& columnsMap,
2498 const TopoDS_Edge & bottomEdge,
2499 const int sideFaceID)
2501 bool isForward = false;
2502 if ( SMESH_MesherHelper::IsClosedEdge( bottomEdge ))
2504 isForward = ( bottomEdge.Orientation() == TopAbs_FORWARD );
2508 const TNodeColumn& firstCol = columnsMap.begin()->second;
2509 const SMDS_MeshNode* bottomNode = firstCol[0];
2510 TopoDS_Shape firstVertex = SMESH_MesherHelper::GetSubShapeByNode( bottomNode, meshDS );
2511 isForward = ( firstVertex.IsSame( TopExp::FirstVertex( bottomEdge, true )));
2513 // on 2 of 4 sides first vertex is end
2514 if ( sideFaceID == ID_Fx1z || sideFaceID == ID_F0yz )
2515 isForward = !isForward;
2519 //================================================================================
2521 * \brief Constructor
2522 * \param faceID - in-block ID
2523 * \param face - geom FACE
2524 * \param baseEdge - EDGE proreply oriented in the bottom EDGE !!!
2525 * \param columnsMap - map of node columns
2526 * \param first - first normalized param
2527 * \param last - last normalized param
2529 //================================================================================
2531 StdMeshers_PrismAsBlock::TSideFace::TSideFace(SMESH_MesherHelper* helper,
2533 const Prism_3D::TQuadList& quadList,
2534 const TopoDS_Edge& baseEdge,
2535 TParam2ColumnMap* columnsMap,
2539 myParamToColumnMap( columnsMap ),
2542 myParams.resize( 1 );
2543 myParams[ 0 ] = make_pair( first, last );
2544 mySurface = PSurface( new BRepAdaptor_Surface( quadList.front()->face ));
2545 myBaseEdge = baseEdge;
2546 myIsForward = StdMeshers_PrismAsBlock::IsForwardEdge( myHelper->GetMeshDS(),
2547 *myParamToColumnMap,
2549 if ( quadList.size() > 1 ) // side is vertically composite
2551 // fill myShapeID2Surf map to enable finding a right surface by any sub-shape ID
2553 SMESHDS_Mesh* meshDS = myHelper->GetMeshDS();
2555 TopTools_IndexedDataMapOfShapeListOfShape subToFaces;
2556 Prism_3D::TQuadList::const_iterator quad = quadList.begin();
2557 for ( ; quad != quadList.end(); ++quad )
2559 const TopoDS_Face& face = (*quad)->face;
2560 TopExp::MapShapesAndAncestors( face, TopAbs_VERTEX, TopAbs_FACE, subToFaces );
2561 TopExp::MapShapesAndAncestors( face, TopAbs_EDGE, TopAbs_FACE, subToFaces );
2562 myShapeID2Surf.insert( make_pair( meshDS->ShapeToIndex( face ),
2563 PSurface( new BRepAdaptor_Surface( face ))));
2565 for ( int i = 1; i <= subToFaces.Extent(); ++i )
2567 const TopoDS_Shape& sub = subToFaces.FindKey( i );
2568 TopTools_ListOfShape& faces = subToFaces( i );
2569 int subID = meshDS->ShapeToIndex( sub );
2570 int faceID = meshDS->ShapeToIndex( faces.First() );
2571 myShapeID2Surf.insert ( make_pair( subID, myShapeID2Surf[ faceID ]));
2576 //================================================================================
2578 * \brief Constructor of complex side face
2580 //================================================================================
2582 StdMeshers_PrismAsBlock::TSideFace::
2583 TSideFace(const vector< TSideFace* >& components,
2584 const vector< pair< double, double> > & params)
2585 :myID( components[0] ? components[0]->myID : 0 ),
2586 myParamToColumnMap( 0 ),
2588 myIsForward( true ),
2589 myComponents( components ),
2590 myHelper( components[0] ? components[0]->myHelper : 0 )
2592 //================================================================================
2594 * \brief Copy constructor
2595 * \param other - other side
2597 //================================================================================
2599 StdMeshers_PrismAsBlock::TSideFace::TSideFace( const TSideFace& other )
2602 mySurface = other.mySurface;
2603 myBaseEdge = other.myBaseEdge;
2604 myParams = other.myParams;
2605 myIsForward = other.myIsForward;
2606 myHelper = other.myHelper;
2607 myParamToColumnMap = other.myParamToColumnMap;
2609 myComponents.resize( other.myComponents.size());
2610 for (int i = 0 ; i < myComponents.size(); ++i )
2611 myComponents[ i ] = new TSideFace( *other.myComponents[ i ]);
2614 //================================================================================
2616 * \brief Deletes myComponents
2618 //================================================================================
2620 StdMeshers_PrismAsBlock::TSideFace::~TSideFace()
2622 for (int i = 0 ; i < myComponents.size(); ++i )
2623 if ( myComponents[ i ] )
2624 delete myComponents[ i ];
2627 //================================================================================
2629 * \brief Return geometry of the vertical curve
2630 * \param isMax - true means curve located closer to (1,1,1) block point
2631 * \retval Adaptor3d_Curve* - curve adaptor
2633 //================================================================================
2635 Adaptor3d_Curve* StdMeshers_PrismAsBlock::TSideFace::VertiCurve(const bool isMax) const
2637 if ( !myComponents.empty() ) {
2639 return myComponents.back()->VertiCurve(isMax);
2641 return myComponents.front()->VertiCurve(isMax);
2643 double f = myParams[0].first, l = myParams[0].second;
2644 if ( !myIsForward ) std::swap( f, l );
2645 return new TVerticalEdgeAdaptor( myParamToColumnMap, isMax ? l : f );
2648 //================================================================================
2650 * \brief Return geometry of the top or bottom curve
2652 * \retval Adaptor3d_Curve* -
2654 //================================================================================
2656 Adaptor3d_Curve* StdMeshers_PrismAsBlock::TSideFace::HorizCurve(const bool isTop) const
2658 return new THorizontalEdgeAdaptor( this, isTop );
2661 //================================================================================
2663 * \brief Return pcurves
2664 * \param pcurv - array of 4 pcurves
2665 * \retval bool - is a success
2667 //================================================================================
2669 bool StdMeshers_PrismAsBlock::TSideFace::GetPCurves(Adaptor2d_Curve2d* pcurv[4]) const
2671 int iEdge[ 4 ] = { BOTTOM_EDGE, TOP_EDGE, V0_EDGE, V1_EDGE };
2673 for ( int i = 0 ; i < 4 ; ++i ) {
2674 Handle(Geom2d_Line) line;
2675 switch ( iEdge[ i ] ) {
2677 line = new Geom2d_Line( gp_Pnt2d( 0, 1 ), gp::DX2d() ); break;
2679 line = new Geom2d_Line( gp::Origin2d(), gp::DX2d() ); break;
2681 line = new Geom2d_Line( gp::Origin2d(), gp::DY2d() ); break;
2683 line = new Geom2d_Line( gp_Pnt2d( 1, 0 ), gp::DY2d() ); break;
2685 pcurv[ i ] = new Geom2dAdaptor_Curve( line, 0, 1 );
2690 //================================================================================
2692 * \brief Returns geometry of pcurve on a horizontal face
2693 * \param isTop - is top or bottom face
2694 * \param horFace - a horizontal face
2695 * \retval Adaptor2d_Curve2d* - curve adaptor
2697 //================================================================================
2700 StdMeshers_PrismAsBlock::TSideFace::HorizPCurve(const bool isTop,
2701 const TopoDS_Face& horFace) const
2703 return new TPCurveOnHorFaceAdaptor( this, isTop, horFace );
2706 //================================================================================
2708 * \brief Return a component corresponding to parameter
2709 * \param U - parameter along a horizontal size
2710 * \param localU - parameter along a horizontal size of a component
2711 * \retval TSideFace* - found component
2713 //================================================================================
2715 StdMeshers_PrismAsBlock::TSideFace*
2716 StdMeshers_PrismAsBlock::TSideFace::GetComponent(const double U,double & localU) const
2719 if ( myComponents.empty() )
2720 return const_cast<TSideFace*>( this );
2723 for ( i = 0; i < myComponents.size(); ++i )
2724 if ( U < myParams[ i ].second )
2726 if ( i >= myComponents.size() )
2727 i = myComponents.size() - 1;
2729 double f = myParams[ i ].first, l = myParams[ i ].second;
2730 localU = ( U - f ) / ( l - f );
2731 return myComponents[ i ];
2734 //================================================================================
2736 * \brief Find node columns for a parameter
2737 * \param U - parameter along a horizontal edge
2738 * \param col1 - the 1st found column
2739 * \param col2 - the 2nd found column
2740 * \retval r - normalized position of U between the found columns
2742 //================================================================================
2744 double StdMeshers_PrismAsBlock::TSideFace::GetColumns(const double U,
2745 TParam2ColumnIt & col1,
2746 TParam2ColumnIt & col2) const
2748 double u = U, r = 0;
2749 if ( !myComponents.empty() ) {
2750 TSideFace * comp = GetComponent(U,u);
2751 return comp->GetColumns( u, col1, col2 );
2756 double f = myParams[0].first, l = myParams[0].second;
2757 u = f + u * ( l - f );
2759 col1 = col2 = getColumn( myParamToColumnMap, u );
2760 if ( ++col2 == myParamToColumnMap->end() ) {
2765 double uf = col1->first;
2766 double ul = col2->first;
2767 r = ( u - uf ) / ( ul - uf );
2772 //================================================================================
2774 * \brief Return coordinates by normalized params
2775 * \param U - horizontal param
2776 * \param V - vertical param
2777 * \retval gp_Pnt - result point
2779 //================================================================================
2781 gp_Pnt StdMeshers_PrismAsBlock::TSideFace::Value(const Standard_Real U,
2782 const Standard_Real V) const
2784 if ( !myComponents.empty() ) {
2786 TSideFace * comp = GetComponent(U,u);
2787 return comp->Value( u, V );
2790 TParam2ColumnIt u_col1, u_col2;
2791 double vR, hR = GetColumns( U, u_col1, u_col2 );
2793 const SMDS_MeshNode* nn[4];
2795 // BEGIN issue 0020680: Bad cell created by Radial prism in center of torus
2796 // Workaround for a wrongly located point returned by mySurface.Value() for
2797 // UV located near boundary of BSpline surface.
2798 // To bypass the problem, we take point from 3D curve of EDGE.
2799 // It solves pb of the bloc_fiss_new.py
2800 const double tol = 1e-3;
2801 if ( V < tol || V+tol >= 1. )
2803 nn[0] = V < tol ? u_col1->second.front() : u_col1->second.back();
2804 nn[2] = V < tol ? u_col2->second.front() : u_col2->second.back();
2812 TopoDS_Shape s = myHelper->GetSubShapeByNode( nn[0], myHelper->GetMeshDS() );
2813 if ( s.ShapeType() != TopAbs_EDGE )
2814 s = myHelper->GetSubShapeByNode( nn[2], myHelper->GetMeshDS() );
2815 if ( s.ShapeType() == TopAbs_EDGE )
2816 edge = TopoDS::Edge( s );
2818 if ( !edge.IsNull() )
2820 double u1 = myHelper->GetNodeU( edge, nn[0] );
2821 double u3 = myHelper->GetNodeU( edge, nn[2] );
2822 double u = u1 * ( 1 - hR ) + u3 * hR;
2823 TopLoc_Location loc; double f,l;
2824 Handle(Geom_Curve) curve = BRep_Tool::Curve( edge,loc,f,l );
2825 return curve->Value( u ).Transformed( loc );
2828 // END issue 0020680: Bad cell created by Radial prism in center of torus
2830 vR = getRAndNodes( & u_col1->second, V, nn[0], nn[1] );
2831 vR = getRAndNodes( & u_col2->second, V, nn[2], nn[3] );
2833 if ( !myShapeID2Surf.empty() ) // side is vertically composite
2835 // find a FACE on which the 4 nodes lie
2836 TSideFace* me = (TSideFace*) this;
2837 int notFaceID1 = 0, notFaceID2 = 0;
2838 for ( int i = 0; i < 4; ++i )
2839 if ( nn[i]->GetPosition()->GetTypeOfPosition() == SMDS_TOP_FACE ) // node on FACE
2841 me->mySurface = me->myShapeID2Surf[ nn[i]->getshapeId() ];
2845 else if ( notFaceID1 == 0 ) // node on EDGE or VERTEX
2847 me->mySurface = me->myShapeID2Surf[ nn[i]->getshapeId() ];
2848 notFaceID1 = nn[i]->getshapeId();
2850 else if ( notFaceID1 != nn[i]->getshapeId() ) // node on other EDGE or VERTEX
2852 if ( mySurface != me->myShapeID2Surf[ nn[i]->getshapeId() ])
2853 notFaceID2 = nn[i]->getshapeId();
2855 if ( notFaceID2 ) // no nodes of FACE and nodes are on different FACEs
2857 SMESHDS_Mesh* meshDS = myHelper->GetMeshDS();
2858 TopoDS_Shape face = myHelper->GetCommonAncestor( meshDS->IndexToShape( notFaceID1 ),
2859 meshDS->IndexToShape( notFaceID2 ),
2860 *myHelper->GetMesh(),
2862 if ( face.IsNull() )
2863 throw SALOME_Exception("StdMeshers_PrismAsBlock::TSideFace::Value() face.IsNull()");
2864 int faceID = meshDS->ShapeToIndex( face );
2865 me->mySurface = me->myShapeID2Surf[ faceID ];
2867 throw SALOME_Exception("StdMeshers_PrismAsBlock::TSideFace::Value() !mySurface");
2871 gp_XY uv1 = myHelper->GetNodeUV( mySurface->Face(), nn[0], nn[2]);
2872 gp_XY uv2 = myHelper->GetNodeUV( mySurface->Face(), nn[1], nn[3]);
2873 gp_XY uv12 = uv1 * ( 1 - vR ) + uv2 * vR;
2875 gp_XY uv3 = myHelper->GetNodeUV( mySurface->Face(), nn[2], nn[0]);
2876 gp_XY uv4 = myHelper->GetNodeUV( mySurface->Face(), nn[3], nn[1]);
2877 gp_XY uv34 = uv3 * ( 1 - vR ) + uv4 * vR;
2879 gp_XY uv = uv12 * ( 1 - hR ) + uv34 * hR;
2881 gp_Pnt p = mySurface->Value( uv.X(), uv.Y() );
2886 //================================================================================
2888 * \brief Return boundary edge
2889 * \param edge - edge index
2890 * \retval TopoDS_Edge - found edge
2892 //================================================================================
2894 TopoDS_Edge StdMeshers_PrismAsBlock::TSideFace::GetEdge(const int iEdge) const
2896 if ( !myComponents.empty() ) {
2898 case V0_EDGE : return myComponents.front()->GetEdge( iEdge );
2899 case V1_EDGE : return myComponents.back() ->GetEdge( iEdge );
2900 default: return TopoDS_Edge();
2904 const SMDS_MeshNode* node = 0;
2905 SMESHDS_Mesh * meshDS = myHelper->GetMesh()->GetMeshDS();
2906 TNodeColumn* column;
2911 column = & (( ++myParamToColumnMap->begin())->second );
2912 node = ( iEdge == TOP_EDGE ) ? column->back() : column->front();
2913 edge = myHelper->GetSubShapeByNode ( node, meshDS );
2914 if ( edge.ShapeType() == TopAbs_VERTEX ) {
2915 column = & ( myParamToColumnMap->begin()->second );
2916 node = ( iEdge == TOP_EDGE ) ? column->back() : column->front();
2921 bool back = ( iEdge == V1_EDGE );
2922 if ( !myIsForward ) back = !back;
2924 column = & ( myParamToColumnMap->rbegin()->second );
2926 column = & ( myParamToColumnMap->begin()->second );
2927 if ( column->size() > 0 )
2928 edge = myHelper->GetSubShapeByNode( (*column)[ 1 ], meshDS );
2929 if ( edge.IsNull() || edge.ShapeType() == TopAbs_VERTEX )
2930 node = column->front();
2935 if ( !edge.IsNull() && edge.ShapeType() == TopAbs_EDGE )
2936 return TopoDS::Edge( edge );
2938 // find edge by 2 vertices
2939 TopoDS_Shape V1 = edge;
2940 TopoDS_Shape V2 = myHelper->GetSubShapeByNode( node, meshDS );
2941 if ( !V2.IsNull() && V2.ShapeType() == TopAbs_VERTEX && !V2.IsSame( V1 ))
2943 TopoDS_Shape ancestor = myHelper->GetCommonAncestor( V1, V2, *myHelper->GetMesh(), TopAbs_EDGE);
2944 if ( !ancestor.IsNull() )
2945 return TopoDS::Edge( ancestor );
2947 return TopoDS_Edge();
2950 //================================================================================
2952 * \brief Fill block sub-shapes
2953 * \param shapeMap - map to fill in
2954 * \retval int - nb inserted sub-shapes
2956 //================================================================================
2958 int StdMeshers_PrismAsBlock::TSideFace::InsertSubShapes(TBlockShapes& shapeMap) const
2963 vector< int > edgeIdVec;
2964 SMESH_Block::GetFaceEdgesIDs( myID, edgeIdVec );
2966 for ( int i = BOTTOM_EDGE; i <=V1_EDGE ; ++i ) {
2967 TopoDS_Edge e = GetEdge( i );
2968 if ( !e.IsNull() ) {
2969 nbInserted += SMESH_Block::Insert( e, edgeIdVec[ i ], shapeMap);
2973 // Insert corner vertices
2975 TParam2ColumnIt col1, col2 ;
2976 vector< int > vertIdVec;
2979 SMESH_Block::GetEdgeVertexIDs( edgeIdVec[ V0_EDGE ], vertIdVec);
2980 GetColumns(0, col1, col2 );
2981 const SMDS_MeshNode* node0 = col1->second.front();
2982 const SMDS_MeshNode* node1 = col1->second.back();
2983 TopoDS_Shape v0 = myHelper->GetSubShapeByNode( node0, myHelper->GetMeshDS());
2984 TopoDS_Shape v1 = myHelper->GetSubShapeByNode( node1, myHelper->GetMeshDS());
2985 if ( v0.ShapeType() == TopAbs_VERTEX ) {
2986 nbInserted += SMESH_Block::Insert( v0, vertIdVec[ 0 ], shapeMap);
2988 if ( v1.ShapeType() == TopAbs_VERTEX ) {
2989 nbInserted += SMESH_Block::Insert( v1, vertIdVec[ 1 ], shapeMap);
2993 SMESH_Block::GetEdgeVertexIDs( edgeIdVec[ V1_EDGE ], vertIdVec);
2994 GetColumns(1, col1, col2 );
2995 node0 = col2->second.front();
2996 node1 = col2->second.back();
2997 v0 = myHelper->GetSubShapeByNode( node0, myHelper->GetMeshDS());
2998 v1 = myHelper->GetSubShapeByNode( node1, myHelper->GetMeshDS());
2999 if ( v0.ShapeType() == TopAbs_VERTEX ) {
3000 nbInserted += SMESH_Block::Insert( v0, vertIdVec[ 0 ], shapeMap);
3002 if ( v1.ShapeType() == TopAbs_VERTEX ) {
3003 nbInserted += SMESH_Block::Insert( v1, vertIdVec[ 1 ], shapeMap);
3006 // TopoDS_Vertex V0, V1, Vcom;
3007 // TopExp::Vertices( myBaseEdge, V0, V1, true );
3008 // if ( !myIsForward ) std::swap( V0, V1 );
3010 // // bottom vertex IDs
3011 // SMESH_Block::GetEdgeVertexIDs( edgeIdVec[ _u0 ], vertIdVec);
3012 // SMESH_Block::Insert( V0, vertIdVec[ 0 ], shapeMap);
3013 // SMESH_Block::Insert( V1, vertIdVec[ 1 ], shapeMap);
3015 // TopoDS_Edge sideEdge = GetEdge( V0_EDGE );
3016 // if ( sideEdge.IsNull() || !TopExp::CommonVertex( botEdge, sideEdge, Vcom ))
3019 // // insert one side edge
3021 // if ( Vcom.IsSame( V0 )) edgeID = edgeIdVec[ _v0 ];
3022 // else edgeID = edgeIdVec[ _v1 ];
3023 // SMESH_Block::Insert( sideEdge, edgeID, shapeMap);
3025 // // top vertex of the side edge
3026 // SMESH_Block::GetEdgeVertexIDs( edgeID, vertIdVec);
3027 // TopoDS_Vertex Vtop = TopExp::FirstVertex( sideEdge );
3028 // if ( Vcom.IsSame( Vtop ))
3029 // Vtop = TopExp::LastVertex( sideEdge );
3030 // SMESH_Block::Insert( Vtop, vertIdVec[ 1 ], shapeMap);
3032 // // other side edge
3033 // sideEdge = GetEdge( V1_EDGE );
3034 // if ( sideEdge.IsNull() )
3036 // if ( edgeID = edgeIdVec[ _v1 ]) edgeID = edgeIdVec[ _v0 ];
3037 // else edgeID = edgeIdVec[ _v1 ];
3038 // SMESH_Block::Insert( sideEdge, edgeID, shapeMap);
3041 // TopoDS_Edge topEdge = GetEdge( TOP_EDGE );
3042 // SMESH_Block::Insert( topEdge, edgeIdVec[ _u1 ], shapeMap);
3044 // // top vertex of the other side edge
3045 // if ( !TopExp::CommonVertex( topEdge, sideEdge, Vcom ))
3047 // SMESH_Block::GetEdgeVertexIDs( edgeID, vertIdVec );
3048 // SMESH_Block::Insert( Vcom, vertIdVec[ 1 ], shapeMap);
3053 //================================================================================
3055 * \brief Dump ids of nodes of sides
3057 //================================================================================
3059 void StdMeshers_PrismAsBlock::TSideFace::dumpNodes(int nbNodes) const
3062 cout << endl << "NODES OF FACE "; SMESH_Block::DumpShapeID( myID, cout ) << endl;
3063 THorizontalEdgeAdaptor* hSize0 = (THorizontalEdgeAdaptor*) HorizCurve(0);
3064 cout << "Horiz side 0: "; hSize0->dumpNodes(nbNodes); cout << endl;
3065 THorizontalEdgeAdaptor* hSize1 = (THorizontalEdgeAdaptor*) HorizCurve(1);
3066 cout << "Horiz side 1: "; hSize1->dumpNodes(nbNodes); cout << endl;
3067 TVerticalEdgeAdaptor* vSide0 = (TVerticalEdgeAdaptor*) VertiCurve(0);
3068 cout << "Verti side 0: "; vSide0->dumpNodes(nbNodes); cout << endl;
3069 TVerticalEdgeAdaptor* vSide1 = (TVerticalEdgeAdaptor*) VertiCurve(1);
3070 cout << "Verti side 1: "; vSide1->dumpNodes(nbNodes); cout << endl;
3071 delete hSize0; delete hSize1; delete vSide0; delete vSide1;
3075 //================================================================================
3077 * \brief Creates TVerticalEdgeAdaptor
3078 * \param columnsMap - node column map
3079 * \param parameter - normalized parameter
3081 //================================================================================
3083 StdMeshers_PrismAsBlock::TVerticalEdgeAdaptor::
3084 TVerticalEdgeAdaptor( const TParam2ColumnMap* columnsMap, const double parameter)
3086 myNodeColumn = & getColumn( columnsMap, parameter )->second;
3089 //================================================================================
3091 * \brief Return coordinates for the given normalized parameter
3092 * \param U - normalized parameter
3093 * \retval gp_Pnt - coordinates
3095 //================================================================================
3097 gp_Pnt StdMeshers_PrismAsBlock::TVerticalEdgeAdaptor::Value(const Standard_Real U) const
3099 const SMDS_MeshNode* n1;
3100 const SMDS_MeshNode* n2;
3101 double r = getRAndNodes( myNodeColumn, U, n1, n2 );
3102 return gpXYZ(n1) * ( 1 - r ) + gpXYZ(n2) * r;
3105 //================================================================================
3107 * \brief Dump ids of nodes
3109 //================================================================================
3111 void StdMeshers_PrismAsBlock::TVerticalEdgeAdaptor::dumpNodes(int nbNodes) const
3114 for ( int i = 0; i < nbNodes && i < myNodeColumn->size(); ++i )
3115 cout << (*myNodeColumn)[i]->GetID() << " ";
3116 if ( nbNodes < myNodeColumn->size() )
3117 cout << myNodeColumn->back()->GetID();
3121 //================================================================================
3123 * \brief Return coordinates for the given normalized parameter
3124 * \param U - normalized parameter
3125 * \retval gp_Pnt - coordinates
3127 //================================================================================
3129 gp_Pnt StdMeshers_PrismAsBlock::THorizontalEdgeAdaptor::Value(const Standard_Real U) const
3131 return mySide->TSideFace::Value( U, myV );
3134 //================================================================================
3136 * \brief Dump ids of <nbNodes> first nodes and the last one
3138 //================================================================================
3140 void StdMeshers_PrismAsBlock::THorizontalEdgeAdaptor::dumpNodes(int nbNodes) const
3143 // Not bedugged code. Last node is sometimes incorrect
3144 const TSideFace* side = mySide;
3146 if ( mySide->IsComplex() )
3147 side = mySide->GetComponent(0,u);
3149 TParam2ColumnIt col, col2;
3150 TParam2ColumnMap* u2cols = side->GetColumns();
3151 side->GetColumns( u , col, col2 );
3153 int j, i = myV ? mySide->ColumnHeight()-1 : 0;
3155 const SMDS_MeshNode* n = 0;
3156 const SMDS_MeshNode* lastN
3157 = side->IsForward() ? u2cols->rbegin()->second[ i ] : u2cols->begin()->second[ i ];
3158 for ( j = 0; j < nbNodes && n != lastN; ++j )
3160 n = col->second[ i ];
3161 cout << n->GetID() << " ";
3162 if ( side->IsForward() )
3170 if ( mySide->IsComplex() )
3171 side = mySide->GetComponent(1,u);
3173 side->GetColumns( u , col, col2 );
3174 if ( n != col->second[ i ] )
3175 cout << col->second[ i ]->GetID();
3178 //================================================================================
3180 * \brief Return UV on pcurve for the given normalized parameter
3181 * \param U - normalized parameter
3182 * \retval gp_Pnt - coordinates
3184 //================================================================================
3186 gp_Pnt2d StdMeshers_PrismAsBlock::TPCurveOnHorFaceAdaptor::Value(const Standard_Real U) const
3188 TParam2ColumnIt u_col1, u_col2;
3189 double r = mySide->GetColumns( U, u_col1, u_col2 );
3190 gp_XY uv1 = mySide->GetNodeUV( myFace, u_col1->second[ myZ ]);
3191 gp_XY uv2 = mySide->GetNodeUV( myFace, u_col2->second[ myZ ]);
3192 return uv1 * ( 1 - r ) + uv2 * r;