1 // SMESH SMESH : implementaion of SMESH idl descriptions
3 // Copyright (C) 2003 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
24 // File : StdMeshers_Prism_3D.cxx
26 // Created : Fri Oct 20 11:37:07 2006
27 // Author : Edward AGAPOV (eap)
30 #include "StdMeshers_Prism_3D.hxx"
32 #include "StdMeshers_ProjectionUtils.hxx"
33 #include "SMESH_MeshEditor.hxx"
34 #include "SMDS_VolumeTool.hxx"
35 #include "SMDS_VolumeOfNodes.hxx"
36 #include "SMDS_EdgePosition.hxx"
37 #include "SMESH_Comment.hxx"
39 #include "utilities.h"
41 #include <BRepAdaptor_Curve.hxx>
42 #include <BRepAdaptor_Curve2d.hxx>
43 #include <BRep_Builder.hxx>
44 #include <BRep_Tool.hxx>
45 #include <Geom2dAdaptor_Curve.hxx>
46 #include <Geom2d_Line.hxx>
47 #include <TopTools_ListIteratorOfListOfShape.hxx>
51 #define RETURN_BAD_RESULT(msg) { MESSAGE(msg); return false; }
52 #define gpXYZ(n) gp_XYZ(n->X(),n->Y(),n->Z())
53 #define SHOWYXZ(msg, xyz) // {\
55 // cout << msg << " ("<< p.X() << "; " <<p.Y() << "; " <<p.Z() << ") " <<endl;\
58 typedef StdMeshers_ProjectionUtils TAssocTool;
59 typedef SMESH_Comment TCom;
61 enum { ID_BOT_FACE = SMESH_Block::ID_Fxy0,
62 ID_TOP_FACE = SMESH_Block::ID_Fxy1,
63 BOTTOM_EDGE = 0, TOP_EDGE, V0_EDGE, V1_EDGE, // edge IDs in face
64 NB_WALL_FACES = 4 }; //
68 //================================================================================
70 * \brief Return iterator pointing to node column for the given parameter
71 * \param columnsMap - node column map
72 * \param parameter - parameter
73 * \retval TParam2ColumnMap::iterator - result
75 * it returns closest left column
77 //================================================================================
79 TParam2ColumnIt getColumn( const TParam2ColumnMap* columnsMap,
80 const double parameter )
82 TParam2ColumnIt u_col = columnsMap->upper_bound( parameter );
83 if ( u_col != columnsMap->begin() )
85 return u_col; // return left column
88 //================================================================================
90 * \brief Return nodes around given parameter and a ratio
91 * \param column - node column
92 * \param param - parameter
93 * \param node1 - lower node
94 * \param node2 - upper node
95 * \retval double - ratio
97 //================================================================================
99 double getRAndNodes( const TNodeColumn* column,
101 const SMDS_MeshNode* & node1,
102 const SMDS_MeshNode* & node2)
104 if ( param >= 1.0 || column->size() == 1) {
105 node1 = node2 = column->back();
109 int i = int( param * ( column->size() - 1 ));
110 double u0 = double( i )/ double( column->size() - 1 );
111 double r = ( param - u0 ) * ( column->size() - 1 );
113 node1 = (*column)[ i ];
114 node2 = (*column)[ i + 1];
118 //================================================================================
120 * \brief Compute boundary parameters of face parts
121 * \param nbParts - nb of parts to split columns into
122 * \param columnsMap - node columns of the face to split
123 * \param params - computed parameters
125 //================================================================================
127 void splitParams( const int nbParts,
128 const TParam2ColumnMap* columnsMap,
129 vector< double > & params)
132 params.reserve( nbParts + 1 );
133 TParam2ColumnIt last_par_col = --columnsMap->end();
134 double par = columnsMap->begin()->first; // 0.
135 double parLast = last_par_col->first;
136 params.push_back( par );
137 for ( int i = 0; i < nbParts - 1; ++ i )
139 double partSize = ( parLast - par ) / double ( nbParts - i );
140 TParam2ColumnIt par_col = getColumn( columnsMap, par + partSize );
141 if ( par_col->first == par ) {
143 if ( par_col == last_par_col ) {
144 while ( i < nbParts - 1 )
145 params.push_back( par + partSize * i++ );
149 par = par_col->first;
150 params.push_back( par );
152 params.push_back( parLast ); // 1.
156 //=======================================================================
157 //function : StdMeshers_Prism_3D
159 //=======================================================================
161 StdMeshers_Prism_3D::StdMeshers_Prism_3D(int hypId, int studyId, SMESH_Gen* gen)
162 :SMESH_3D_Algo(hypId, studyId, gen)
165 _shapeType = (1 << TopAbs_SHELL) | (1 << TopAbs_SOLID); // 1 bit per shape type
166 myProjectTriangles = false;
169 //================================================================================
173 //================================================================================
175 StdMeshers_Prism_3D::~StdMeshers_Prism_3D()
178 //=======================================================================
179 //function : CheckHypothesis
181 //=======================================================================
183 bool StdMeshers_Prism_3D::CheckHypothesis(SMESH_Mesh& aMesh,
184 const TopoDS_Shape& aShape,
185 SMESH_Hypothesis::Hypothesis_Status& aStatus)
187 // Check shape geometry
189 aStatus = SMESH_Hypothesis::HYP_BAD_GEOMETRY;
191 // find not quadrangle faces
192 list< TopoDS_Shape > notQuadFaces;
193 int nbEdge, nbWire, nbFace = 0;
194 TopExp_Explorer exp( aShape, TopAbs_FACE );
195 for ( ; exp.More(); exp.Next() ) {
197 const TopoDS_Shape& face = exp.Current();
198 nbEdge = TAssocTool::Count( face, TopAbs_EDGE, 0 );
199 nbWire = TAssocTool::Count( face, TopAbs_WIRE, 0 );
200 if ( nbEdge!= 4 || nbWire!= 1 ) {
201 if ( !notQuadFaces.empty() ) {
202 if ( TAssocTool::Count( notQuadFaces.back(), TopAbs_EDGE, 0 ) != nbEdge ||
203 TAssocTool::Count( notQuadFaces.back(), TopAbs_WIRE, 0 ) != nbWire )
204 RETURN_BAD_RESULT("Different not quad faces");
206 notQuadFaces.push_back( face );
209 if ( !notQuadFaces.empty() )
211 if ( notQuadFaces.size() != 2 )
212 RETURN_BAD_RESULT("Bad nb not quad faces: " << notQuadFaces.size());
214 // check total nb faces
215 nbEdge = TAssocTool::Count( notQuadFaces.back(), TopAbs_EDGE, 0 );
216 if ( nbFace != nbEdge + 2 )
217 RETURN_BAD_RESULT("Bad nb of faces: " << nbFace << " but must be " << nbEdge + 2);
221 aStatus = SMESH_Hypothesis::HYP_OK;
225 //=======================================================================
228 //=======================================================================
230 bool StdMeshers_Prism_3D::Compute(SMESH_Mesh& theMesh, const TopoDS_Shape& theShape)
232 SMESH_MesherHelper helper( theMesh );
235 myHelper->IsQuadraticSubMesh( theShape );
237 // Analyse mesh and geomerty to find block subshapes and submeshes
238 if ( !myBlock.Init( myHelper, theShape ))
239 return error( myBlock.GetError());
241 SMESHDS_Mesh* meshDS = theMesh.GetMeshDS();
243 int volumeID = meshDS->ShapeToIndex( theShape );
246 // To compute coordinates of a node inside a block, it is necessary to know
247 // 1. normalized parameters of the node by which
248 // 2. coordinates of node projections on all block sub-shapes are computed
250 // So we fill projections on vertices at once as they are same for all nodes
251 myShapeXYZ.resize( myBlock.NbSubShapes() );
252 for ( int iV = SMESH_Block::ID_FirstV; iV < SMESH_Block::ID_FirstE; ++iV ) {
253 myBlock.VertexPoint( iV, myShapeXYZ[ iV ]);
254 SHOWYXZ("V point " <<iV << " ", myShapeXYZ[ iV ]);
257 // Projections on the top and bottom faces are taken from nodes existing
258 // on these faces; find correspondence between bottom and top nodes
259 myBotToColumnMap.clear();
260 if ( !assocOrProjBottom2Top() ) // it also fill myBotToColumnMap
264 // Create nodes inside the block
266 // loop on nodes inside the bottom face
267 TNode2ColumnMap::iterator bot_column = myBotToColumnMap.begin();
268 for ( ; bot_column != myBotToColumnMap.end(); ++bot_column )
270 const TNode& tBotNode = bot_column->first; // bottom TNode
271 if ( tBotNode.GetPositionType() != SMDS_TOP_FACE )
272 continue; // node is not inside face
274 // column nodes; middle part of the column are zero pointers
275 TNodeColumn& column = bot_column->second;
277 // bottom node parameters and coords
278 gp_XYZ botParams = tBotNode.GetParams();
279 myShapeXYZ[ ID_BOT_FACE ] = tBotNode.GetCoords();
281 // compute top node parameters
283 myShapeXYZ[ ID_TOP_FACE ] = gpXYZ( column.back() );
284 if ( column.size() < 3 ) { // only top and bottom nodes in columns
285 topParams = botParams;
288 gp_Pnt topCoords = myShapeXYZ[ ID_TOP_FACE ];
289 if ( !myBlock.ComputeParameters( topCoords, topParams, ID_TOP_FACE ))
290 return error(TCom("Can't compute normalized parameters ")
291 << "for node " << column.back()->GetID()
292 << " on the face #"<< column.back()->GetPosition()->GetShapeId() );
296 TNodeColumn::iterator columnNodes = column.begin();
297 for ( int z = 0; columnNodes != column.end(); ++columnNodes, ++z)
299 const SMDS_MeshNode* & node = *columnNodes;
300 if ( node ) continue; // skip bottom or top node
302 // params of a node to create
303 double rz = (double) z / (double) ( column.size() - 1 );
304 gp_XYZ params = botParams * ( 1 - rz ) + topParams * rz;
306 // set coords on all faces and nodes
307 const int nbSideFaces = 4;
308 int sideFaceIDs[nbSideFaces] = { SMESH_Block::ID_Fx0z,
309 SMESH_Block::ID_Fx1z,
310 SMESH_Block::ID_F0yz,
311 SMESH_Block::ID_F1yz };
312 for ( int iF = 0; iF < nbSideFaces; ++iF )
313 if ( !setFaceAndEdgesXYZ( sideFaceIDs[ iF ], params, z ))
316 // compute coords for a new node
318 if ( !SMESH_Block::ShellPoint( params, myShapeXYZ, coords ))
319 return error("Can't compute coordinates by normalized parameters");
322 node = meshDS->AddNode( coords.X(), coords.Y(), coords.Z() );
323 meshDS->SetNodeInVolume( node, volumeID );
325 } // loop on bottom nodes
330 SMESHDS_SubMesh* smDS = myBlock.SubMeshDS( ID_BOT_FACE );
331 if ( !smDS ) return error(COMPERR_BAD_INPUT_MESH, "Null submesh");
333 // loop on bottom mesh faces
334 SMDS_ElemIteratorPtr faceIt = smDS->GetElements();
335 while ( faceIt->more() )
337 const SMDS_MeshElement* face = faceIt->next();
338 if ( !face || face->GetType() != SMDSAbs_Face )
340 int nbNodes = face->NbNodes();
341 if ( face->IsQuadratic() )
344 // find node columns for each node
345 vector< const TNodeColumn* > columns( nbNodes );
346 for ( int i = 0; i < nbNodes; ++i )
348 const SMDS_MeshNode* n = face->GetNode( i );
349 if ( n->GetPosition()->GetTypeOfPosition() == SMDS_TOP_FACE ) {
350 bot_column = myBotToColumnMap.find( n );
351 if ( bot_column == myBotToColumnMap.end() )
352 return error(TCom("No nodes found above node ") << n->GetID() );
353 columns[ i ] = & bot_column->second;
356 columns[ i ] = myBlock.GetNodeColumn( n );
358 return error(TCom("No side nodes found above node ") << n->GetID() );
362 AddPrisms( columns, myHelper );
364 } // loop on bottom mesh faces
369 //================================================================================
371 * \brief Create prisms
372 * \param columns - columns of nodes generated from nodes of a mesh face
373 * \param helper - helper initialized by mesh and shape to add prisms to
375 //================================================================================
377 void StdMeshers_Prism_3D::AddPrisms( vector<const TNodeColumn*> & columns,
378 SMESH_MesherHelper* helper)
380 SMESHDS_Mesh * meshDS = helper->GetMeshDS();
381 int shapeID = helper->GetSubShapeID();
383 int nbNodes = columns.size();
385 // vertical loop on columns
386 for ( int z = 1; z < columns[0]->size(); ++z)
388 SMDS_MeshElement* vol = 0;
389 SMDS_VolumeTool vTool;
393 const SMDS_MeshNode* botNodes[3] = { (*columns[0])[z-1],
395 (*columns[2])[z-1] };
396 const SMDS_MeshNode* topNodes[3] = { (*columns[0])[z],
399 // assure good orientation
400 SMDS_VolumeOfNodes tmpVol ( botNodes[0], botNodes[1], botNodes[2],
401 topNodes[0], topNodes[1], topNodes[2]);
402 vTool.Set( &tmpVol );
403 if ( vTool.IsForward() )
404 vol = helper->AddVolume( botNodes[0], botNodes[1], botNodes[2],
405 topNodes[0], topNodes[1], topNodes[2]);
407 vol = helper->AddVolume( topNodes[0], topNodes[1], topNodes[2],
408 botNodes[0], botNodes[1], botNodes[2]);
412 const SMDS_MeshNode* botNodes[4] = { (*columns[0])[z-1], (*columns[1])[z-1],
413 (*columns[2])[z-1], (*columns[3])[z-1] };
414 const SMDS_MeshNode* topNodes[4] = { (*columns[0])[z], (*columns[1])[z],
415 (*columns[2])[z], (*columns[3])[z] };
416 // assure good orientation
417 SMDS_VolumeOfNodes tmpVol ( botNodes[0], botNodes[1], botNodes[2], botNodes[3],
418 topNodes[0], topNodes[1], topNodes[2], topNodes[3]);
419 vTool.Set( &tmpVol );
420 if ( vTool.IsForward() )
421 vol = helper->AddVolume( botNodes[0], botNodes[1], botNodes[2], botNodes[3],
422 topNodes[0], topNodes[1], topNodes[2], topNodes[3]);
424 vol = helper->AddVolume( topNodes[0], topNodes[1], topNodes[2], topNodes[3],
425 botNodes[0], botNodes[1], botNodes[2], botNodes[3]);
430 vector<const SMDS_MeshNode*> nodes( 2*nbNodes + 4*nbNodes);
431 vector<int> quantities( 2 + nbNodes, 4 );
432 quantities[0] = quantities[1] = nbNodes;
433 columns.resize( nbNodes + 1 );
434 columns[ nbNodes ] = columns[ 0 ];
435 for ( int i = 0; i < nbNodes; ++i ) {
436 nodes[ i ] = (*columns[ i ])[z-1]; // bottom
437 nodes[ i+nbNodes ] = (*columns[ i ])[z ]; // top
439 int di = 2*nbNodes + 4*i - 1;
440 nodes[ di ] = (*columns[i ])[z-1];
441 nodes[ di+1 ] = (*columns[i+1])[z-1];
442 nodes[ di+2 ] = (*columns[i+1])[z ];
443 nodes[ di+3 ] = (*columns[i ])[z ];
445 vol = meshDS->AddPolyhedralVolume( nodes, quantities );
447 if ( vol && shapeID > 0 )
448 meshDS->SetMeshElementOnShape( vol, shapeID );
452 //================================================================================
454 * \brief Find correspondence between bottom and top nodes
455 * If elements on the bottom and top faces are topologically different,
456 * and projection is possible and allowed, perform the projection
457 * \retval bool - is a success or not
459 //================================================================================
461 bool StdMeshers_Prism_3D::assocOrProjBottom2Top()
463 SMESH_subMesh * botSM = myBlock.SubMesh( ID_BOT_FACE );
464 SMESH_subMesh * topSM = myBlock.SubMesh( ID_TOP_FACE );
466 SMESHDS_SubMesh * botSMDS = botSM->GetSubMeshDS();
467 SMESHDS_SubMesh * topSMDS = topSM->GetSubMeshDS();
469 if ( !botSMDS || botSMDS->NbElements() == 0 )
470 return error(TCom("No elememts on face #") << botSM->GetId());
472 bool needProject = false;
474 botSMDS->NbElements() != topSMDS->NbElements() ||
475 botSMDS->NbNodes() != topSMDS->NbNodes())
477 if ( myBlock.HasNotQuadElemOnTop() )
478 return error(TCom("Mesh on faces #") << botSM->GetId()
479 <<" and #"<< topSM->GetId() << " seems different" );
483 if ( 0/*needProject && !myProjectTriangles*/ )
484 return error(TCom("Mesh on faces #") << botSM->GetId()
485 <<" and #"<< topSM->GetId() << " seems different" );
486 ///RETURN_BAD_RESULT("Need to project but not allowed");
490 return projectBottomToTop();
493 TopoDS_Face botFace = TopoDS::Face( myBlock.Shape( ID_BOT_FACE ));
494 TopoDS_Face topFace = TopoDS::Face( myBlock.Shape( ID_TOP_FACE ));
495 // associate top and bottom faces
496 TAssocTool::TShapeShapeMap shape2ShapeMap;
497 if ( !TAssocTool::FindSubShapeAssociation( botFace, myBlock.Mesh(),
498 topFace, myBlock.Mesh(),
500 return error(TCom("Topology of faces #") << botSM->GetId()
501 <<" and #"<< topSM->GetId() << " seems different" );
503 // Find matching nodes of top and bottom faces
505 if ( ! TAssocTool::FindMatchingNodesOnFaces( botFace, myBlock.Mesh(),
506 topFace, myBlock.Mesh(),
507 shape2ShapeMap, n2nMap ))
508 return error(TCom("Mesh on faces #") << botSM->GetId()
509 <<" and #"<< topSM->GetId() << " seems different" );
511 // Fill myBotToColumnMap
513 int zSize = myBlock.VerticalSize();
514 TNodeNodeMap::iterator bN_tN = n2nMap.begin();
515 for ( ; bN_tN != n2nMap.end(); ++bN_tN )
517 const SMDS_MeshNode* botNode = bN_tN->first;
518 const SMDS_MeshNode* topNode = bN_tN->second;
519 if ( botNode->GetPosition()->GetTypeOfPosition() != SMDS_TOP_FACE )
520 continue; // wall columns are contained in myBlock
521 // compute bottom node params
524 if ( !myBlock.ComputeParameters( bN.GetCoords(), bN.ChangeParams(), ID_BOT_FACE ))
525 return error(TCom("Can't compute normalized parameters ")
526 << "for node " << botNode->GetID() << " on the face #"<< botSM->GetId() );
527 // create node column
528 TNode2ColumnMap::iterator bN_col =
529 myBotToColumnMap.insert( make_pair ( bN, TNodeColumn() )).first;
530 TNodeColumn & column = bN_col->second;
531 column.resize( zSize );
532 column.front() = botNode;
533 column.back() = topNode;
538 //================================================================================
540 * \brief Remove quadrangles from the top face and
541 * create triangles there by projection from the bottom
542 * \retval bool - a success or not
544 //================================================================================
546 bool StdMeshers_Prism_3D::projectBottomToTop()
548 SMESH_subMesh * botSM = myBlock.SubMesh( ID_BOT_FACE );
549 SMESH_subMesh * topSM = myBlock.SubMesh( ID_TOP_FACE );
551 SMESHDS_SubMesh * botSMDS = botSM->GetSubMeshDS();
552 SMESHDS_SubMesh * topSMDS = topSM->GetSubMeshDS();
555 topSM->ComputeStateEngine( SMESH_subMesh::CLEAN );
557 SMESHDS_Mesh* meshDS = myBlock.MeshDS();
558 int shapeID = myHelper->GetSubShapeID();
559 int topFaceID = meshDS->ShapeToIndex( topSM->GetSubShape() );
561 // Fill myBotToColumnMap
563 int zSize = myBlock.VerticalSize();
564 SMDS_NodeIteratorPtr nIt = botSMDS->GetNodes();
565 while ( nIt->more() )
567 const SMDS_MeshNode* botNode = nIt->next();
568 if ( botNode->GetPosition()->GetTypeOfPosition() != SMDS_TOP_FACE )
570 // compute bottom node params
572 if ( !myBlock.ComputeParameters( bN.GetCoords(), bN.ChangeParams(), ID_BOT_FACE ))
573 return error(TCom("Can't compute normalized parameters ")
574 << "for node " << botNode->GetID() << " on the face #"<< botSM->GetId() );
575 // compute top node coords
576 gp_XYZ topXYZ; gp_XY topUV;
577 if ( !myBlock.FacePoint( ID_TOP_FACE, bN.GetParams(), topXYZ ) ||
578 !myBlock.FaceUV ( ID_TOP_FACE, bN.GetParams(), topUV ))
579 return error(TCom("Can't compute coordinates ")
580 << "by normalized parameters on the face #"<< topSM->GetId() );
581 SMDS_MeshNode * topNode = meshDS->AddNode( topXYZ.X(),topXYZ.Y(),topXYZ.Z() );
582 meshDS->SetNodeOnFace( topNode, topFaceID, topUV.X(), topUV.Y() );
583 // create node column
584 TNode2ColumnMap::iterator bN_col =
585 myBotToColumnMap.insert( make_pair ( bN, TNodeColumn() )).first;
586 TNodeColumn & column = bN_col->second;
587 column.resize( zSize );
588 column.front() = botNode;
589 column.back() = topNode;
594 // loop on bottom mesh faces
595 SMDS_ElemIteratorPtr faceIt = botSMDS->GetElements();
596 while ( faceIt->more() )
598 const SMDS_MeshElement* face = faceIt->next();
599 if ( !face || face->GetType() != SMDSAbs_Face )
601 int nbNodes = face->NbNodes();
602 if ( face->IsQuadratic() )
605 // find top node in columns for each bottom node
606 vector< const SMDS_MeshNode* > nodes( nbNodes );
607 for ( int i = 0; i < nbNodes; ++i )
609 const SMDS_MeshNode* n = face->GetNode( nbNodes - i - 1 );
610 if ( n->GetPosition()->GetTypeOfPosition() == SMDS_TOP_FACE ) {
611 TNode2ColumnMap::iterator bot_column = myBotToColumnMap.find( n );
612 if ( bot_column == myBotToColumnMap.end() )
613 return error(TCom("No nodes found above node ") << n->GetID() );
614 nodes[ i ] = bot_column->second.back();
617 const TNodeColumn* column = myBlock.GetNodeColumn( n );
619 return error(TCom("No side nodes found above node ") << n->GetID() );
620 nodes[ i ] = column->back();
623 // create a face, with reversed orientation
624 SMDS_MeshElement* newFace = 0;
628 newFace = myHelper->AddFace(nodes[0], nodes[1], nodes[2]);
632 newFace = myHelper->AddFace( nodes[0], nodes[1], nodes[2], nodes[3] );
636 newFace = meshDS->AddPolygonalFace( nodes );
638 if ( newFace && shapeID > 0 )
639 meshDS->SetMeshElementOnShape( newFace, shapeID );
645 //================================================================================
647 * \brief Set projection coordinates of a node to a face and it's subshapes
648 * \param faceID - the face given by in-block ID
649 * \param params - node normalized parameters
650 * \retval bool - is a success
652 //================================================================================
654 bool StdMeshers_Prism_3D::setFaceAndEdgesXYZ( const int faceID, const gp_XYZ& params, int z )
656 // find base and top edges of the face
657 enum { BASE = 0, TOP, LEFT, RIGHT };
658 vector< int > edgeVec; // 0-base, 1-top
659 SMESH_Block::GetFaceEdgesIDs( faceID, edgeVec );
661 myBlock.EdgePoint( edgeVec[ BASE ], params, myShapeXYZ[ edgeVec[ BASE ]]);
662 myBlock.EdgePoint( edgeVec[ TOP ], params, myShapeXYZ[ edgeVec[ TOP ]]);
664 SHOWYXZ("\nparams ", params);
665 SHOWYXZ("TOP is "<<edgeVec[ TOP], myShapeXYZ[ edgeVec[ TOP]]);
666 SHOWYXZ("BASE is "<<edgeVec[ BASE], myShapeXYZ[ edgeVec[ BASE]]);
668 if ( faceID == SMESH_Block::ID_Fx0z || faceID == SMESH_Block::ID_Fx1z )
670 myBlock.EdgePoint( edgeVec[ LEFT ], params, myShapeXYZ[ edgeVec[ LEFT ]]);
671 myBlock.EdgePoint( edgeVec[ RIGHT ], params, myShapeXYZ[ edgeVec[ RIGHT ]]);
673 SHOWYXZ("VER "<<edgeVec[ LEFT], myShapeXYZ[ edgeVec[ LEFT]]);
674 SHOWYXZ("VER "<<edgeVec[ RIGHT], myShapeXYZ[ edgeVec[ RIGHT]]);
676 myBlock.FacePoint( faceID, params, myShapeXYZ[ faceID ]);
677 SHOWYXZ("FacePoint "<<faceID, myShapeXYZ[ faceID]);
682 //================================================================================
684 * \brief Constructor. Initialization is needed
686 //================================================================================
688 StdMeshers_PrismAsBlock::StdMeshers_PrismAsBlock()
693 StdMeshers_PrismAsBlock::~StdMeshers_PrismAsBlock()
696 delete mySide; mySide = 0;
700 //================================================================================
702 * \brief Initialization.
703 * \param helper - helper loaded with mesh and 3D shape
704 * \param shape3D - a closed shell or solid
705 * \retval bool - false if a mesh or a shape are KO
707 //================================================================================
709 bool StdMeshers_PrismAsBlock::Init(SMESH_MesherHelper* helper,
710 const TopoDS_Shape& shape3D)
713 delete mySide; mySide = 0;
715 vector< TSideFace* > sideFaces( NB_WALL_FACES, 0 );
716 vector< pair< double, double> > params ( NB_WALL_FACES );
717 mySide = new TSideFace( sideFaces, params );
720 SMESHDS_Mesh* meshDS = myHelper->GetMeshDS();
723 myShapeIDMap.Clear();
724 myShapeIndex2ColumnMap.clear();
726 int wallFaceIds[ NB_WALL_FACES ] = { // to walk around a block
727 SMESH_Block::ID_Fx0z, SMESH_Block::ID_F1yz,
728 SMESH_Block::ID_Fx1z, SMESH_Block::ID_F0yz
731 myError = SMESH_ComputeError::New();
733 // -------------------------------------------------------------
734 // Look for top and bottom faces: not quadrangle ones or meshed
735 // with not quadrangle elements
736 // -------------------------------------------------------------
738 list< SMESH_subMesh* > notQuadGeomSubMesh;
739 list< SMESH_subMesh* > notQuadElemSubMesh;
742 SMESH_subMesh* mainSubMesh = myHelper->GetMesh()->GetSubMeshContaining( shape3D );
743 if ( !mainSubMesh ) return error(COMPERR_BAD_INPUT_MESH,"Null submesh of shape3D");
745 // analyse face submeshes
746 SMESH_subMeshIteratorPtr smIt = mainSubMesh->getDependsOnIterator(false,false);
747 while ( smIt->more() )
749 SMESH_subMesh* sm = smIt->next();
750 const TopoDS_Shape& face = sm->GetSubShape();
751 if ( face.ShapeType() != TopAbs_FACE )
755 // is quadrangle face?
756 list< TopoDS_Edge > orderedEdges;
757 list< int > nbEdgesInWires;
759 int nbWires = GetOrderedEdges( TopoDS::Face( face ),
760 V000, orderedEdges, nbEdgesInWires );
761 if ( nbWires != 1 || nbEdgesInWires.front() != 4 )
762 notQuadGeomSubMesh.push_back( sm );
764 // look for not quadrangle mesh elements
765 if ( SMESHDS_SubMesh* smDS = sm->GetSubMeshDS() ) {
766 bool hasNotQuad = false;
767 SMDS_ElemIteratorPtr eIt = smDS->GetElements();
768 while ( eIt->more() && !hasNotQuad ) {
769 const SMDS_MeshElement* elem = eIt->next();
770 if ( elem->GetType() == SMDSAbs_Face ) {
771 int nbNodes = elem->NbNodes();
772 if ( elem->IsQuadratic() )
774 hasNotQuad = ( nbNodes != 4 );
778 notQuadElemSubMesh.push_back( sm );
781 return error(COMPERR_BAD_INPUT_MESH,TCom("Not meshed face #")<<sm->GetId());
783 // check if a quadrangle face is meshed with a quadranglar grid
784 if ( notQuadGeomSubMesh.back() != sm &&
785 notQuadElemSubMesh.back() != sm )
787 // count nb edges on face sides
788 vector< int > nbEdges;
789 nbEdges.reserve( nbEdgesInWires.front() );
790 for ( list< TopoDS_Edge >::iterator edge = orderedEdges.begin();
791 edge != orderedEdges.end(); ++edge )
793 if ( SMESHDS_SubMesh* smDS = meshDS->MeshElements( *edge ))
794 nbEdges.push_back ( smDS->NbElements() );
796 nbEdges.push_back ( 0 );
798 int nbQuads = sm->GetSubMeshDS()->NbElements();
799 if ( nbEdges[0] * nbEdges[1] != nbQuads ||
800 nbEdges[0] != nbEdges[2] ||
801 nbEdges[1] != nbEdges[3] )
802 notQuadElemSubMesh.push_back( sm );
806 // ----------------------------------------------------------------------
807 // Analyse faces mesh and topology: choose the bottom submesh.
808 // If there are not quadrangle geom faces, they are top and bottom ones.
809 // Not quadrangle geom faces must be only on top and bottom.
810 // ----------------------------------------------------------------------
812 SMESH_subMesh * botSM = 0;
813 SMESH_subMesh * topSM = 0;
815 int nbNotQuad = notQuadGeomSubMesh.size();
816 int nbNotQuadMeshed = notQuadElemSubMesh.size();
817 bool hasNotQuad = ( nbNotQuad || nbNotQuadMeshed );
820 if ( nbNotQuad > 0 && nbNotQuad != 2 )
821 return error(COMPERR_BAD_SHAPE,
822 TCom("More than 2 not quadrilateral faces ")
824 if ( nbNotQuadMeshed > 2 )
825 return error(COMPERR_BAD_INPUT_MESH,
826 TCom("More than 2 faces meshed with not quadrangle elements ")
829 // get found submeshes
832 if ( nbNotQuadMeshed > 0 ) botSM = notQuadElemSubMesh.front();
833 else botSM = notQuadGeomSubMesh.front();
834 if ( nbNotQuadMeshed > 1 ) topSM = notQuadElemSubMesh.back();
835 else if ( nbNotQuad > 1 ) topSM = notQuadGeomSubMesh.back();
837 // detect other bad cases
838 if ( nbNotQuad == 2 && nbNotQuadMeshed > 0 ) {
840 if ( nbNotQuadMeshed == 1 )
841 ok = ( find( notQuadGeomSubMesh.begin(),
842 notQuadGeomSubMesh.end(), botSM ) != notQuadGeomSubMesh.end() );
844 ok = ( notQuadGeomSubMesh == notQuadElemSubMesh );
846 return error(COMPERR_BAD_INPUT_MESH, "Side face meshed with not quadrangle elements");
849 myNotQuadOnTop = ( nbNotQuadMeshed > 1 );
851 // ----------------------------------------------------------
853 if ( nbNotQuad == 0 ) // Standard block of 6 quadrangle faces ?
855 // SMESH_Block will perform geometry analysis, we need just to find 2
856 // connected vertices on top and bottom
858 TopoDS_Vertex Vbot, Vtop;
859 if ( nbNotQuadMeshed > 0 ) // Look for vertices
861 TopTools_IndexedMapOfShape edgeMap;
862 TopExp::MapShapes( botSM->GetSubShape(), TopAbs_EDGE, edgeMap );
863 // vertex 1 is any vertex of the bottom face
864 Vbot = TopExp::FirstVertex( TopoDS::Edge( edgeMap( 1 )));
865 // vertex 2 is end vertex of edge sharing Vbot and not belonging to the bottom face
866 TopTools_ListIteratorOfListOfShape ancestIt = Mesh()->GetAncestors( Vbot );
867 for ( ; Vtop.IsNull() && ancestIt.More(); ancestIt.Next() )
869 const TopoDS_Shape & ancestor = ancestIt.Value();
870 if ( ancestor.ShapeType() == TopAbs_EDGE && !edgeMap.FindIndex( ancestor ))
872 TopoDS_Vertex V1, V2;
873 TopExp::Vertices( TopoDS::Edge( ancestor ), V1, V2);
874 if ( Vbot.IsSame ( V1 )) Vtop = V2;
875 else if ( Vbot.IsSame ( V2 )) Vtop = V1;
876 // check that Vtop belongs to shape3D
877 TopExp_Explorer exp( shape3D, TopAbs_VERTEX );
878 for ( ; exp.More(); exp.Next() )
879 if ( Vtop.IsSame( exp.Current() ))
886 // get shell from shape3D
888 TopExp_Explorer exp( shape3D, TopAbs_SHELL );
890 for ( ; exp.More(); exp.Next(), ++nbShell )
891 shell = TopoDS::Shell( exp.Current() );
892 // if ( nbShell != 1 )
893 // RETURN_BAD_RESULT("There must be 1 shell in the block");
895 // Load geometry in SMESH_Block
896 if ( !SMESH_Block::FindBlockShapes( shell, Vbot, Vtop, myShapeIDMap )) {
898 return error(COMPERR_BAD_SHAPE, "Can't detect top and bottom of a prism");
901 if ( !botSM ) botSM = Mesh()->GetSubMeshContaining( myShapeIDMap( ID_BOT_FACE ));
902 if ( !topSM ) topSM = Mesh()->GetSubMeshContaining( myShapeIDMap( ID_TOP_FACE ));
905 } // end Standard block of 6 quadrangle faces
906 // --------------------------------------------------------
908 // Here the top and bottom faces are found
909 if ( nbNotQuadMeshed == 2 ) // roughly check correspondence of horiz meshes
911 // SMESHDS_SubMesh* topSMDS = topSM->GetSubMeshDS();
912 // SMESHDS_SubMesh* botSMDS = botSM->GetSubMeshDS();
913 // if ( topSMDS->NbNodes() != botSMDS->NbNodes() ||
914 // topSMDS->NbElements() != botSMDS->NbElements() )
915 // RETURN_BAD_RESULT("Top mesh doesn't correspond to bottom one");
918 // ---------------------------------------------------------
919 // If there are not quadrangle geom faces, we emulate
920 // a block of 6 quadrangle faces.
921 // Load SMESH_Block with faces and edges geometry
922 // ---------------------------------------------------------
925 // find vertex 000 - the one with smallest coordinates (for easy DEBUG :-)
927 double minVal = DBL_MAX, minX, val;
928 for ( TopExp_Explorer exp( botSM->GetSubShape(), TopAbs_VERTEX );
929 exp.More(); exp.Next() )
931 const TopoDS_Vertex& v = TopoDS::Vertex( exp.Current() );
932 gp_Pnt P = BRep_Tool::Pnt( v );
933 val = P.X() + P.Y() + P.Z();
934 if ( val < minVal || ( val == minVal && P.X() < minX )) {
941 // Get ordered bottom edges
942 list< TopoDS_Edge > orderedEdges;
943 list< int > nbVertexInWires;
944 SMESH_Block::GetOrderedEdges( TopoDS::Face( botSM->GetSubShape().Reversed() ),
945 V000, orderedEdges, nbVertexInWires );
946 // if ( nbVertexInWires.size() != 1 )
947 // RETURN_BAD_RESULT("Wrong prism geometry");
949 // Get Wall faces corresponding to the ordered bottom edges
950 list< TopoDS_Face > wallFaces;
951 if ( !GetWallFaces( Mesh(), shape3D, botSM->GetSubShape(), orderedEdges, wallFaces))
952 return error(COMPERR_BAD_SHAPE, "Can't find side faces");
954 // Find columns of wall nodes and calculate edges' lengths
955 // --------------------------------------------------------
957 myParam2ColumnMaps.clear();
958 myParam2ColumnMaps.resize( orderedEdges.size() ); // total nb edges
960 int iE, nbEdges = nbVertexInWires.front(); // nb outer edges
961 vector< double > edgeLength( nbEdges );
962 map< double, int > len2edgeMap;
964 list< TopoDS_Edge >::iterator edgeIt = orderedEdges.begin();
965 list< TopoDS_Face >::iterator faceIt = wallFaces.begin();
966 for ( iE = 0; iE < nbEdges; ++edgeIt, ++faceIt )
968 TParam2ColumnMap & faceColumns = myParam2ColumnMaps[ iE ];
969 if ( !myHelper->LoadNodeColumns( faceColumns, *faceIt, *edgeIt, meshDS ))
970 return error(COMPERR_BAD_INPUT_MESH, TCom("Can't find regular quadrangle mesh ")
971 << "on a side face #" << MeshDS()->ShapeToIndex( *faceIt ));
973 SHOWYXZ("\np1 F "<<iE, gpXYZ(faceColumns.begin()->second.front() ));
974 SHOWYXZ("p2 F "<<iE, gpXYZ(faceColumns.rbegin()->second.front() ));
975 SHOWYXZ("V First "<<iE, BRep_Tool::Pnt( TopExp::FirstVertex(*edgeIt,true )));
977 edgeLength[ iE ] = SMESH_Algo::EdgeLength( *edgeIt );
979 if ( nbEdges < NB_WALL_FACES ) // fill map used to split faces
981 SMESHDS_SubMesh* smDS = meshDS->MeshElements( *edgeIt);
983 return error(COMPERR_BAD_INPUT_MESH, TCom("Null submesh on the edge #")
984 << MeshDS()->ShapeToIndex( *edgeIt ));
985 // assure length uniqueness
986 edgeLength[ iE ] *= smDS->NbNodes() + edgeLength[ iE ] / ( 1000 + iE );
987 len2edgeMap[ edgeLength[ iE ]] = iE;
991 // Load columns of internal edges (forming holes)
992 // and fill map ShapeIndex to TParam2ColumnMap for them
993 for ( ; edgeIt != orderedEdges.end() ; ++edgeIt, ++faceIt )
995 TParam2ColumnMap & faceColumns = myParam2ColumnMaps[ iE ];
996 if ( !myHelper->LoadNodeColumns( faceColumns, *faceIt, *edgeIt, meshDS ))
997 return error(COMPERR_BAD_INPUT_MESH, TCom("Can't find regular quadrangle mesh ")
998 << "on a side face #" << MeshDS()->ShapeToIndex( *faceIt ));
1000 int id = MeshDS()->ShapeToIndex( *edgeIt );
1001 bool isForward = true; // meaningless for intenal wires
1002 myShapeIndex2ColumnMap[ id ] = make_pair( & faceColumns, isForward );
1003 // columns for vertices
1005 const SMDS_MeshNode* n0 = faceColumns.begin()->second.front();
1006 id = n0->GetPosition()->GetShapeId();
1007 myShapeIndex2ColumnMap[ id ] = make_pair( & faceColumns, isForward );
1009 const SMDS_MeshNode* n1 = faceColumns.rbegin()->second.front();
1010 id = n1->GetPosition()->GetShapeId();
1011 myShapeIndex2ColumnMap[ id ] = make_pair( & faceColumns, isForward );
1012 // SHOWYXZ("\np1 F "<<iE, gpXYZ(faceColumns.begin()->second.front() ));
1013 // SHOWYXZ("p2 F "<<iE, gpXYZ(faceColumns.rbegin()->second.front() ));
1014 // SHOWYXZ("V First "<<iE, BRep_Tool::Pnt( TopExp::FirstVertex(*edgeIt,true )));
1018 // Create 4 wall faces of a block
1019 // -------------------------------
1021 if ( nbEdges <= NB_WALL_FACES ) // ************* Split faces if necessary
1023 map< int, int > iE2nbSplit;
1024 if ( nbEdges != NB_WALL_FACES ) // define how to split
1026 if ( len2edgeMap.size() != nbEdges )
1027 RETURN_BAD_RESULT("Uniqueness of edge lengths not assured");
1028 map< double, int >::reverse_iterator maxLen_i = len2edgeMap.rbegin();
1029 map< double, int >::reverse_iterator midLen_i = ++len2edgeMap.rbegin();
1030 double maxLen = maxLen_i->first;
1031 double midLen = ( len2edgeMap.size() == 1 ) ? 0 : midLen_i->first;
1032 switch ( nbEdges ) {
1033 case 1: // 0-th edge is split into 4 parts
1034 iE2nbSplit.insert( make_pair( 0, 4 )); break;
1035 case 2: // either the longest edge is split into 3 parts, or both edges into halves
1036 if ( maxLen / 3 > midLen / 2 ) {
1037 iE2nbSplit.insert( make_pair( maxLen_i->second, 3 ));
1040 iE2nbSplit.insert( make_pair( maxLen_i->second, 2 ));
1041 iE2nbSplit.insert( make_pair( midLen_i->second, 2 ));
1045 // split longest into halves
1046 iE2nbSplit.insert( make_pair( maxLen_i->second, 2 ));
1049 // Create TSideFace's
1050 faceIt = wallFaces.begin();
1051 edgeIt = orderedEdges.begin();
1053 for ( iE = 0; iE < nbEdges; ++edgeIt, ++faceIt )
1056 map< int, int >::iterator i_nb = iE2nbSplit.find( iE );
1057 if ( i_nb != iE2nbSplit.end() ) {
1059 int nbSplit = i_nb->second;
1060 vector< double > params;
1061 splitParams( nbSplit, &myParam2ColumnMaps[ iE ], params );
1062 bool isForward = ( edgeIt->Orientation() == TopAbs_FORWARD );
1063 for ( int i = 0; i < nbSplit; ++i ) {
1064 double f = ( isForward ? params[ i ] : params[ nbSplit - i-1 ]);
1065 double l = ( isForward ? params[ i+1 ] : params[ nbSplit - i ]);
1066 TSideFace* comp = new TSideFace( myHelper, wallFaceIds[ iSide ],
1068 &myParam2ColumnMaps[ iE ], f, l );
1069 mySide->SetComponent( iSide++, comp );
1073 TSideFace* comp = new TSideFace( myHelper, wallFaceIds[ iSide ],
1075 &myParam2ColumnMaps[ iE ]);
1076 mySide->SetComponent( iSide++, comp );
1081 else { // **************************** Unite faces
1083 // unite first faces
1084 int nbExraFaces = nbEdges - 3;
1086 double u0 = 0, sumLen = 0;
1087 for ( iE = 0; iE < nbExraFaces; ++iE )
1088 sumLen += edgeLength[ iE ];
1090 vector< TSideFace* > components( nbExraFaces );
1091 vector< pair< double, double> > params( nbExraFaces );
1092 faceIt = wallFaces.begin();
1093 edgeIt = orderedEdges.begin();
1094 for ( iE = 0; iE < nbExraFaces; ++edgeIt, ++faceIt )
1096 components[ iE ] = new TSideFace( myHelper, wallFaceIds[ iSide ],
1098 &myParam2ColumnMaps[ iE ]);
1099 double u1 = u0 + edgeLength[ iE ] / sumLen;
1100 params[ iE ] = make_pair( u0 , u1 );
1104 mySide->SetComponent( iSide++, new TSideFace( components, params ));
1106 // fill the rest faces
1107 for ( ; iE < nbEdges; ++faceIt, ++edgeIt )
1109 TSideFace* comp = new TSideFace( myHelper, wallFaceIds[ iSide ],
1111 &myParam2ColumnMaps[ iE ]);
1112 mySide->SetComponent( iSide++, comp );
1118 // Fill geometry fields of SMESH_Block
1119 // ------------------------------------
1121 TopoDS_Face botF = TopoDS::Face( botSM->GetSubShape() );
1122 TopoDS_Face topF = TopoDS::Face( topSM->GetSubShape() );
1124 vector< int > botEdgeIdVec;
1125 SMESH_Block::GetFaceEdgesIDs( ID_BOT_FACE, botEdgeIdVec );
1127 bool isForward[NB_WALL_FACES] = { true, true, true, true };
1128 Adaptor2d_Curve2d* botPcurves[NB_WALL_FACES];
1129 Adaptor2d_Curve2d* topPcurves[NB_WALL_FACES];
1131 for ( int iF = 0; iF < NB_WALL_FACES; ++iF )
1133 TSideFace * sideFace = mySide->GetComponent( iF );
1135 RETURN_BAD_RESULT("NULL TSideFace");
1136 int fID = sideFace->FaceID();
1138 // fill myShapeIDMap
1139 if ( sideFace->InsertSubShapes( myShapeIDMap ) != 8 &&
1140 !sideFace->IsComplex())
1141 MESSAGE( ": Warning : InsertSubShapes() < 8 on side " << iF );
1143 // side faces geometry
1144 Adaptor2d_Curve2d* pcurves[NB_WALL_FACES];
1145 if ( !sideFace->GetPCurves( pcurves ))
1146 RETURN_BAD_RESULT("TSideFace::GetPCurves() failed");
1148 SMESH_Block::TFace& tFace = myFace[ fID - ID_FirstF ];
1149 tFace.Set( fID, sideFace->Surface(), pcurves, isForward );
1151 SHOWYXZ( endl<<"F "<< iF << " id " << fID << " FRW " << sideFace->IsForward(), sideFace->Value(0,0));
1152 // edges 3D geometry
1153 vector< int > edgeIdVec;
1154 SMESH_Block::GetFaceEdgesIDs( fID, edgeIdVec );
1155 for ( int isMax = 0; isMax < 2; ++isMax ) {
1157 int eID = edgeIdVec[ isMax ];
1158 SMESH_Block::TEdge& tEdge = myEdge[ eID - ID_FirstE ];
1159 tEdge.Set( eID, sideFace->HorizCurve(isMax), true);
1160 SHOWYXZ(eID<<" HOR"<<isMax<<"(0)", sideFace->HorizCurve(isMax)->Value(0));
1161 SHOWYXZ(eID<<" HOR"<<isMax<<"(1)", sideFace->HorizCurve(isMax)->Value(1));
1164 int eID = edgeIdVec[ isMax+2 ];
1165 SMESH_Block::TEdge& tEdge = myEdge[ eID - ID_FirstE ];
1166 tEdge.Set( eID, sideFace->VertiCurve(isMax), true);
1167 SHOWYXZ(eID<<" VER"<<isMax<<"(0)", sideFace->VertiCurve(isMax)->Value(0));
1168 SHOWYXZ(eID<<" VER"<<isMax<<"(1)", sideFace->VertiCurve(isMax)->Value(1));
1171 vector< int > vertexIdVec;
1172 SMESH_Block::GetEdgeVertexIDs( eID, vertexIdVec );
1173 myPnt[ vertexIdVec[0] - ID_FirstV ] = tEdge.GetCurve()->Value(0).XYZ();
1174 myPnt[ vertexIdVec[1] - ID_FirstV ] = tEdge.GetCurve()->Value(1).XYZ();
1177 // pcurves on horizontal faces
1178 for ( iE = 0; iE < NB_WALL_FACES; ++iE ) {
1179 if ( edgeIdVec[ BOTTOM_EDGE ] == botEdgeIdVec[ iE ] ) {
1180 botPcurves[ iE ] = sideFace->HorizPCurve( false, botF );
1181 topPcurves[ iE ] = sideFace->HorizPCurve( true, topF );
1186 // horizontal faces geometry
1188 SMESH_Block::TFace& tFace = myFace[ ID_BOT_FACE - ID_FirstF ];
1189 tFace.Set( ID_BOT_FACE, new BRepAdaptor_Surface( botF ), botPcurves, isForward );
1190 SMESH_Block::Insert( botF, ID_BOT_FACE, myShapeIDMap );
1193 SMESH_Block::TFace& tFace = myFace[ ID_TOP_FACE - ID_FirstF ];
1194 tFace.Set( ID_TOP_FACE, new BRepAdaptor_Surface( topF ), topPcurves, isForward );
1195 SMESH_Block::Insert( topF, ID_TOP_FACE, myShapeIDMap );
1198 // Fill map ShapeIndex to TParam2ColumnMap
1199 // ----------------------------------------
1201 list< TSideFace* > fList;
1202 list< TSideFace* >::iterator fListIt;
1203 fList.push_back( mySide );
1204 for ( fListIt = fList.begin(); fListIt != fList.end(); ++fListIt)
1206 int nb = (*fListIt)->NbComponents();
1207 for ( int i = 0; i < nb; ++i ) {
1208 if ( TSideFace* comp = (*fListIt)->GetComponent( i ))
1209 fList.push_back( comp );
1211 if ( TParam2ColumnMap* cols = (*fListIt)->GetColumns()) {
1212 // columns for a base edge
1213 int id = MeshDS()->ShapeToIndex( (*fListIt)->BaseEdge() );
1214 bool isForward = (*fListIt)->IsForward();
1215 myShapeIndex2ColumnMap[ id ] = make_pair( cols, isForward );
1217 // columns for vertices
1218 const SMDS_MeshNode* n0 = cols->begin()->second.front();
1219 id = n0->GetPosition()->GetShapeId();
1220 myShapeIndex2ColumnMap[ id ] = make_pair( cols, isForward );
1222 const SMDS_MeshNode* n1 = cols->rbegin()->second.front();
1223 id = n1->GetPosition()->GetShapeId();
1224 myShapeIndex2ColumnMap[ id ] = make_pair( cols, !isForward );
1228 // gp_XYZ testPar(0.25, 0.25, 0), testCoord;
1229 // if ( !FacePoint( ID_BOT_FACE, testPar, testCoord ))
1230 // RETURN_BAD_RESULT("TEST FacePoint() FAILED");
1231 // SHOWYXZ("IN TEST PARAM" , testPar);
1232 // SHOWYXZ("OUT TEST CORD" , testCoord);
1233 // if ( !ComputeParameters( testCoord, testPar , ID_BOT_FACE))
1234 // RETURN_BAD_RESULT("TEST ComputeParameters() FAILED");
1235 // SHOWYXZ("OUT TEST PARAM" , testPar);
1240 //================================================================================
1242 * \brief Return pointer to column of nodes
1243 * \param node - bottom node from which the returned column goes up
1244 * \retval const TNodeColumn* - the found column
1246 //================================================================================
1248 const TNodeColumn* StdMeshers_PrismAsBlock::GetNodeColumn(const SMDS_MeshNode* node) const
1250 int sID = node->GetPosition()->GetShapeId();
1252 map<int, pair< TParam2ColumnMap*, bool > >::const_iterator col_frw =
1253 myShapeIndex2ColumnMap.find( sID );
1254 if ( col_frw != myShapeIndex2ColumnMap.end() ) {
1255 const TParam2ColumnMap* cols = col_frw->second.first;
1256 TParam2ColumnIt u_col = cols->begin();
1257 for ( ; u_col != cols->end(); ++u_col )
1258 if ( u_col->second[ 0 ] == node )
1259 return & u_col->second;
1264 //================================================================================
1266 * \brief Check curve orientation of a bootom edge
1267 * \param meshDS - mesh DS
1268 * \param columnsMap - node columns map of side face
1269 * \param bottomEdge - the bootom edge
1270 * \param sideFaceID - side face in-block ID
1271 * \retval bool - true if orientation coinside with in-block froward orientation
1273 //================================================================================
1275 bool StdMeshers_PrismAsBlock::IsForwardEdge(SMESHDS_Mesh* meshDS,
1276 const TParam2ColumnMap& columnsMap,
1277 const TopoDS_Edge & bottomEdge,
1278 const int sideFaceID)
1280 bool isForward = false;
1281 if ( TAssocTool::IsClosedEdge( bottomEdge ))
1283 isForward = ( bottomEdge.Orientation() == TopAbs_FORWARD );
1287 const TNodeColumn& firstCol = columnsMap.begin()->second;
1288 const SMDS_MeshNode* bottomNode = firstCol[0];
1289 TopoDS_Shape firstVertex = SMESH_MesherHelper::GetSubShapeByNode( bottomNode, meshDS );
1290 isForward = ( firstVertex.IsSame( TopExp::FirstVertex( bottomEdge, true )));
1292 // on 2 of 4 sides first vertex is end
1293 if ( sideFaceID == ID_Fx1z || sideFaceID == ID_F0yz )
1294 isForward = !isForward;
1298 //================================================================================
1300 * \brief Find wall faces by bottom edges
1301 * \param mesh - the mesh
1302 * \param mainShape - the prism
1303 * \param bottomFace - the bottom face
1304 * \param bottomEdges - edges bounding the bottom face
1305 * \param wallFaces - faces list to fill in
1307 //================================================================================
1309 bool StdMeshers_PrismAsBlock::GetWallFaces( SMESH_Mesh* mesh,
1310 const TopoDS_Shape & mainShape,
1311 const TopoDS_Shape & bottomFace,
1312 const std::list< TopoDS_Edge >& bottomEdges,
1313 std::list< TopoDS_Face >& wallFaces)
1317 TopTools_IndexedMapOfShape faceMap;
1318 TopExp::MapShapes( mainShape, TopAbs_FACE, faceMap );
1320 list< TopoDS_Edge >::const_iterator edge = bottomEdges.begin();
1321 for ( ; edge != bottomEdges.end(); ++edge )
1323 TopTools_ListIteratorOfListOfShape ancestIt = mesh->GetAncestors( *edge );
1324 for ( ; ancestIt.More(); ancestIt.Next() )
1326 const TopoDS_Shape& ancestor = ancestIt.Value();
1327 if ( ancestor.ShapeType() == TopAbs_FACE && // face
1328 !bottomFace.IsSame( ancestor ) && // not bottom
1329 faceMap.FindIndex( ancestor )) // belongs to the prism
1331 wallFaces.push_back( TopoDS::Face( ancestor ));
1336 return ( wallFaces.size() == bottomEdges.size() );
1339 //================================================================================
1341 * \brief Constructor
1342 * \param faceID - in-block ID
1343 * \param face - geom face
1344 * \param columnsMap - map of node columns
1345 * \param first - first normalized param
1346 * \param last - last normalized param
1348 //================================================================================
1350 StdMeshers_PrismAsBlock::TSideFace::TSideFace(SMESH_MesherHelper* helper,
1352 const TopoDS_Face& face,
1353 const TopoDS_Edge& baseEdge,
1354 TParam2ColumnMap* columnsMap,
1358 myParamToColumnMap( columnsMap ),
1359 myBaseEdge( baseEdge ),
1362 mySurface.Initialize( face );
1363 myParams.resize( 1 );
1364 myParams[ 0 ] = make_pair( first, last );
1365 myIsForward = StdMeshers_PrismAsBlock::IsForwardEdge( myHelper->GetMeshDS(),
1366 *myParamToColumnMap,
1370 //================================================================================
1372 * \brief Constructor of complex side face
1374 //================================================================================
1376 StdMeshers_PrismAsBlock::TSideFace::
1377 TSideFace(const vector< TSideFace* >& components,
1378 const vector< pair< double, double> > & params)
1379 :myID( components[0] ? components[0]->myID : 0 ),
1380 myParamToColumnMap( 0 ),
1382 myIsForward( true ),
1383 myComponents( components ),
1384 myHelper( components[0] ? components[0]->myHelper : 0 )
1386 //================================================================================
1388 * \brief Copy constructor
1389 * \param other - other side
1391 //================================================================================
1393 StdMeshers_PrismAsBlock::TSideFace::TSideFace( const TSideFace& other )
1396 mySurface = other.mySurface;
1397 myBaseEdge = other.myBaseEdge;
1398 myParams = other.myParams;
1399 myIsForward = other.myIsForward;
1400 myHelper = other.myHelper;
1401 myParamToColumnMap = other.myParamToColumnMap;
1403 myComponents.resize( other.myComponents.size());
1404 for (int i = 0 ; i < myComponents.size(); ++i )
1405 myComponents[ i ] = new TSideFace( *other.myComponents[ i ]);
1408 //================================================================================
1410 * \brief Deletes myComponents
1412 //================================================================================
1414 StdMeshers_PrismAsBlock::TSideFace::~TSideFace()
1416 for (int i = 0 ; i < myComponents.size(); ++i )
1417 if ( myComponents[ i ] )
1418 delete myComponents[ i ];
1421 //================================================================================
1423 * \brief Return geometry of the vertical curve
1424 * \param isMax - true means curve located closer to (1,1,1) block point
1425 * \retval Adaptor3d_Curve* - curve adaptor
1427 //================================================================================
1429 Adaptor3d_Curve* StdMeshers_PrismAsBlock::TSideFace::VertiCurve(const bool isMax) const
1431 if ( !myComponents.empty() ) {
1433 return myComponents.back()->VertiCurve(isMax);
1435 return myComponents.front()->VertiCurve(isMax);
1437 double f = myParams[0].first, l = myParams[0].second;
1438 if ( !myIsForward ) std::swap( f, l );
1439 return new TVerticalEdgeAdaptor( myParamToColumnMap, isMax ? l : f );
1442 //================================================================================
1444 * \brief Return geometry of the top or bottom curve
1446 * \retval Adaptor3d_Curve* -
1448 //================================================================================
1450 Adaptor3d_Curve* StdMeshers_PrismAsBlock::TSideFace::HorizCurve(const bool isTop) const
1452 return new THorizontalEdgeAdaptor( this, isTop );
1455 //================================================================================
1457 * \brief Return pcurves
1458 * \param pcurv - array of 4 pcurves
1459 * \retval bool - is a success
1461 //================================================================================
1463 bool StdMeshers_PrismAsBlock::TSideFace::GetPCurves(Adaptor2d_Curve2d* pcurv[4]) const
1465 int iEdge[ 4 ] = { BOTTOM_EDGE, TOP_EDGE, V0_EDGE, V1_EDGE };
1467 for ( int i = 0 ; i < 4 ; ++i ) {
1468 Handle(Geom2d_Line) line;
1469 switch ( iEdge[ i ] ) {
1471 line = new Geom2d_Line( gp_Pnt2d( 0, 1 ), gp::DX2d() ); break;
1473 line = new Geom2d_Line( gp::Origin2d(), gp::DX2d() ); break;
1475 line = new Geom2d_Line( gp::Origin2d(), gp::DY2d() ); break;
1477 line = new Geom2d_Line( gp_Pnt2d( 1, 0 ), gp::DY2d() ); break;
1479 pcurv[ i ] = new Geom2dAdaptor_Curve( line, 0, 1 );
1484 //================================================================================
1486 * \brief Returns geometry of pcurve on a horizontal face
1487 * \param isTop - is top or bottom face
1488 * \param horFace - a horizontal face
1489 * \retval Adaptor2d_Curve2d* - curve adaptor
1491 //================================================================================
1494 StdMeshers_PrismAsBlock::TSideFace::HorizPCurve(const bool isTop,
1495 const TopoDS_Face& horFace) const
1497 return new TPCurveOnHorFaceAdaptor( this, isTop, horFace );
1500 //================================================================================
1502 * \brief Return a component corresponding to parameter
1503 * \param U - parameter along a horizontal size
1504 * \param localU - parameter along a horizontal size of a component
1505 * \retval TSideFace* - found component
1507 //================================================================================
1509 StdMeshers_PrismAsBlock::TSideFace*
1510 StdMeshers_PrismAsBlock::TSideFace::GetComponent(const double U,double & localU) const
1513 if ( myComponents.empty() )
1514 return const_cast<TSideFace*>( this );
1517 for ( i = 0; i < myComponents.size(); ++i )
1518 if ( U < myParams[ i ].second )
1520 if ( i >= myComponents.size() )
1521 i = myComponents.size() - 1;
1523 double f = myParams[ i ].first, l = myParams[ i ].second;
1524 localU = ( U - f ) / ( l - f );
1525 return myComponents[ i ];
1528 //================================================================================
1530 * \brief Find node columns for a parameter
1531 * \param U - parameter along a horizontal edge
1532 * \param col1 - the 1st found column
1533 * \param col2 - the 2nd found column
1534 * \retval r - normalized position of U between the found columns
1536 //================================================================================
1538 double StdMeshers_PrismAsBlock::TSideFace::GetColumns(const double U,
1539 TParam2ColumnIt & col1,
1540 TParam2ColumnIt & col2) const
1542 double u = U, r = 0;
1543 if ( !myComponents.empty() ) {
1544 TSideFace * comp = GetComponent(U,u);
1545 return comp->GetColumns( u, col1, col2 );
1550 double f = myParams[0].first, l = myParams[0].second;
1551 u = f + u * ( l - f );
1553 col1 = col2 = getColumn( myParamToColumnMap, u );
1554 if ( ++col2 == myParamToColumnMap->end() ) {
1559 // if ( !myIsForward )
1560 // std::swap( col1, col2 );
1561 double uf = col1->first;
1562 double ul = col2->first;
1563 r = ( u - uf ) / ( ul - uf );
1568 //================================================================================
1570 * \brief Return coordinates by normalized params
1571 * \param U - horizontal param
1572 * \param V - vertical param
1573 * \retval gp_Pnt - result point
1575 //================================================================================
1577 gp_Pnt StdMeshers_PrismAsBlock::TSideFace::Value(const Standard_Real U,
1578 const Standard_Real V) const
1581 if ( !myComponents.empty() ) {
1582 TSideFace * comp = GetComponent(U,u);
1583 return comp->Value( u, V );
1586 TParam2ColumnIt u_col1, u_col2;
1587 double vR, hR = GetColumns( U, u_col1, u_col2 );
1589 const SMDS_MeshNode* n1 = 0;
1590 const SMDS_MeshNode* n2 = 0;
1591 const SMDS_MeshNode* n3 = 0;
1592 const SMDS_MeshNode* n4 = 0;
1595 vR = getRAndNodes( & u_col1->second, V, n1, n2 );
1596 vR = getRAndNodes( & u_col2->second, V, n3, n4 );
1598 gp_XY uv1 = myHelper->GetNodeUV( mySurface.Face(), n1, n4);
1599 gp_XY uv2 = myHelper->GetNodeUV( mySurface.Face(), n2, n3);
1600 gp_XY uv12 = uv1 * ( 1 - vR ) + uv2 * vR;
1602 gp_XY uv3 = myHelper->GetNodeUV( mySurface.Face(), n3, n2);
1603 gp_XY uv4 = myHelper->GetNodeUV( mySurface.Face(), n4, n1);
1604 gp_XY uv34 = uv3 * ( 1 - vR ) + uv4 * vR;
1606 gp_XY uv = uv12 * ( 1 - hR ) + uv34 * hR;
1608 return mySurface.Value( uv.X(), uv.Y() );
1612 //================================================================================
1614 * \brief Return boundary edge
1615 * \param edge - edge index
1616 * \retval TopoDS_Edge - found edge
1618 //================================================================================
1620 TopoDS_Edge StdMeshers_PrismAsBlock::TSideFace::GetEdge(const int iEdge) const
1622 if ( !myComponents.empty() ) {
1624 case V0_EDGE : return myComponents.front()->GetEdge( iEdge );
1625 case V1_EDGE : return myComponents.back() ->GetEdge( iEdge );
1626 default: return TopoDS_Edge();
1630 const SMDS_MeshNode* node = 0;
1631 SMESHDS_Mesh * meshDS = myHelper->GetMesh()->GetMeshDS();
1632 TNodeColumn* column;
1637 column = & (( ++myParamToColumnMap->begin())->second );
1638 node = ( iEdge == TOP_EDGE ) ? column->back() : column->front();
1639 edge = myHelper->GetSubShapeByNode ( node, meshDS );
1640 if ( edge.ShapeType() == TopAbs_VERTEX ) {
1641 column = & ( myParamToColumnMap->begin()->second );
1642 node = ( iEdge == TOP_EDGE ) ? column->back() : column->front();
1647 bool back = ( iEdge == V1_EDGE );
1648 if ( !myIsForward ) back = !back;
1650 column = & ( myParamToColumnMap->rbegin()->second );
1652 column = & ( myParamToColumnMap->begin()->second );
1653 if ( column->size() > 0 )
1654 edge = myHelper->GetSubShapeByNode( (*column)[ 1 ], meshDS );
1655 if ( edge.IsNull() || edge.ShapeType() == TopAbs_VERTEX )
1656 node = column->front();
1661 if ( !edge.IsNull() && edge.ShapeType() == TopAbs_EDGE )
1662 return TopoDS::Edge( edge );
1664 // find edge by 2 vertices
1665 TopoDS_Shape V1 = edge;
1666 TopoDS_Shape V2 = myHelper->GetSubShapeByNode( node, meshDS );
1667 if ( V2.ShapeType() == TopAbs_VERTEX && !V2.IsSame( V1 ))
1669 TopTools_ListIteratorOfListOfShape ancestIt =
1670 myHelper->GetMesh()->GetAncestors( V1 );
1671 for ( ; ancestIt.More(); ancestIt.Next() )
1673 const TopoDS_Shape & ancestor = ancestIt.Value();
1674 if ( ancestor.ShapeType() == TopAbs_EDGE )
1675 for ( TopExp_Explorer e( ancestor, TopAbs_VERTEX ); e.More(); e.Next() )
1676 if ( V2.IsSame( e.Current() ))
1677 return TopoDS::Edge( ancestor );
1680 return TopoDS_Edge();
1683 //================================================================================
1685 * \brief Fill block subshapes
1686 * \param shapeMap - map to fill in
1687 * \retval int - nb inserted subshapes
1689 //================================================================================
1691 int StdMeshers_PrismAsBlock::TSideFace::InsertSubShapes(TBlockShapes& shapeMap) const
1696 vector< int > edgeIdVec;
1697 SMESH_Block::GetFaceEdgesIDs( myID, edgeIdVec );
1699 for ( int i = BOTTOM_EDGE; i <=V1_EDGE ; ++i ) {
1700 TopoDS_Edge e = GetEdge( i );
1701 if ( !e.IsNull() ) {
1702 nbInserted += SMESH_Block::Insert( e, edgeIdVec[ i ], shapeMap);
1706 // Insert corner vertices
1708 TParam2ColumnIt col1, col2 ;
1709 vector< int > vertIdVec;
1712 SMESH_Block::GetEdgeVertexIDs( edgeIdVec[ V0_EDGE ], vertIdVec);
1713 GetColumns(0, col1, col2 );
1714 const SMDS_MeshNode* node0 = col1->second.front();
1715 const SMDS_MeshNode* node1 = col1->second.back();
1716 TopoDS_Shape v0 = myHelper->GetSubShapeByNode( node0, myHelper->GetMeshDS());
1717 TopoDS_Shape v1 = myHelper->GetSubShapeByNode( node1, myHelper->GetMeshDS());
1718 if ( v0.ShapeType() == TopAbs_VERTEX ) {
1719 nbInserted += SMESH_Block::Insert( v0, vertIdVec[ 0 ], shapeMap);
1721 if ( v1.ShapeType() == TopAbs_VERTEX ) {
1722 nbInserted += SMESH_Block::Insert( v1, vertIdVec[ 1 ], shapeMap);
1726 SMESH_Block::GetEdgeVertexIDs( edgeIdVec[ V1_EDGE ], vertIdVec);
1727 GetColumns(1, col1, col2 );
1728 node0 = col2->second.front();
1729 node1 = col2->second.back();
1730 v0 = myHelper->GetSubShapeByNode( node0, myHelper->GetMeshDS());
1731 v1 = myHelper->GetSubShapeByNode( node1, myHelper->GetMeshDS());
1732 if ( v0.ShapeType() == TopAbs_VERTEX ) {
1733 nbInserted += SMESH_Block::Insert( v0, vertIdVec[ 0 ], shapeMap);
1735 if ( v1.ShapeType() == TopAbs_VERTEX ) {
1736 nbInserted += SMESH_Block::Insert( v1, vertIdVec[ 1 ], shapeMap);
1739 // TopoDS_Vertex V0, V1, Vcom;
1740 // TopExp::Vertices( myBaseEdge, V0, V1, true );
1741 // if ( !myIsForward ) std::swap( V0, V1 );
1743 // // bottom vertex IDs
1744 // SMESH_Block::GetEdgeVertexIDs( edgeIdVec[ _u0 ], vertIdVec);
1745 // SMESH_Block::Insert( V0, vertIdVec[ 0 ], shapeMap);
1746 // SMESH_Block::Insert( V1, vertIdVec[ 1 ], shapeMap);
1748 // TopoDS_Edge sideEdge = GetEdge( V0_EDGE );
1749 // if ( sideEdge.IsNull() || !TopExp::CommonVertex( botEdge, sideEdge, Vcom ))
1752 // // insert one side edge
1754 // if ( Vcom.IsSame( V0 )) edgeID = edgeIdVec[ _v0 ];
1755 // else edgeID = edgeIdVec[ _v1 ];
1756 // SMESH_Block::Insert( sideEdge, edgeID, shapeMap);
1758 // // top vertex of the side edge
1759 // SMESH_Block::GetEdgeVertexIDs( edgeID, vertIdVec);
1760 // TopoDS_Vertex Vtop = TopExp::FirstVertex( sideEdge );
1761 // if ( Vcom.IsSame( Vtop ))
1762 // Vtop = TopExp::LastVertex( sideEdge );
1763 // SMESH_Block::Insert( Vtop, vertIdVec[ 1 ], shapeMap);
1765 // // other side edge
1766 // sideEdge = GetEdge( V1_EDGE );
1767 // if ( sideEdge.IsNull() )
1769 // if ( edgeID = edgeIdVec[ _v1 ]) edgeID = edgeIdVec[ _v0 ];
1770 // else edgeID = edgeIdVec[ _v1 ];
1771 // SMESH_Block::Insert( sideEdge, edgeID, shapeMap);
1774 // TopoDS_Edge topEdge = GetEdge( TOP_EDGE );
1775 // SMESH_Block::Insert( topEdge, edgeIdVec[ _u1 ], shapeMap);
1777 // // top vertex of the other side edge
1778 // if ( !TopExp::CommonVertex( topEdge, sideEdge, Vcom ))
1780 // SMESH_Block::GetEdgeVertexIDs( edgeID, vertIdVec );
1781 // SMESH_Block::Insert( Vcom, vertIdVec[ 1 ], shapeMap);
1786 //================================================================================
1788 * \brief Creates TVerticalEdgeAdaptor
1789 * \param columnsMap - node column map
1790 * \param parameter - normalized parameter
1792 //================================================================================
1794 StdMeshers_PrismAsBlock::TVerticalEdgeAdaptor::
1795 TVerticalEdgeAdaptor( const TParam2ColumnMap* columnsMap, const double parameter)
1797 myNodeColumn = & getColumn( columnsMap, parameter )->second;
1800 //================================================================================
1802 * \brief Return coordinates for the given normalized parameter
1803 * \param U - normalized parameter
1804 * \retval gp_Pnt - coordinates
1806 //================================================================================
1808 gp_Pnt StdMeshers_PrismAsBlock::TVerticalEdgeAdaptor::Value(const Standard_Real U) const
1810 const SMDS_MeshNode* n1;
1811 const SMDS_MeshNode* n2;
1812 double r = getRAndNodes( myNodeColumn, U, n1, n2 );
1813 return gpXYZ(n1) * ( 1 - r ) + gpXYZ(n2) * r;
1816 //================================================================================
1818 * \brief Return coordinates for the given normalized parameter
1819 * \param U - normalized parameter
1820 * \retval gp_Pnt - coordinates
1822 //================================================================================
1824 gp_Pnt StdMeshers_PrismAsBlock::THorizontalEdgeAdaptor::Value(const Standard_Real U) const
1826 return mySide->TSideFace::Value( U, myV );
1829 //================================================================================
1831 * \brief Return UV on pcurve for the given normalized parameter
1832 * \param U - normalized parameter
1833 * \retval gp_Pnt - coordinates
1835 //================================================================================
1837 gp_Pnt2d StdMeshers_PrismAsBlock::TPCurveOnHorFaceAdaptor::Value(const Standard_Real U) const
1839 TParam2ColumnIt u_col1, u_col2;
1840 double r = mySide->GetColumns( U, u_col1, u_col2 );
1841 gp_XY uv1 = mySide->GetNodeUV( myFace, u_col1->second[ myZ ]);
1842 gp_XY uv2 = mySide->GetNodeUV( myFace, u_col2->second[ myZ ]);
1843 return uv1 * ( 1 - r ) + uv2 * r;