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"
38 #include "utilities.h"
40 #include <BRepAdaptor_Curve.hxx>
41 #include <BRepAdaptor_Curve2d.hxx>
42 #include <BRep_Builder.hxx>
43 #include <BRep_Tool.hxx>
44 #include <Geom2dAdaptor_Curve.hxx>
45 #include <Geom2d_Line.hxx>
46 #include <TopTools_ListIteratorOfListOfShape.hxx>
50 #define RETURN_BAD_RESULT(msg) { MESSAGE(msg); return false; }
51 #define gpXYZ(n) gp_XYZ(n->X(),n->Y(),n->Z())
52 #define SHOWYXZ(msg, xyz) // {\
54 // cout << msg << " ("<< p.X() << "; " <<p.Y() << "; " <<p.Z() << ") " <<endl;\
57 typedef StdMeshers_ProjectionUtils TAssocTool;
59 enum { ID_BOT_FACE = SMESH_Block::ID_Fxy0,
60 ID_TOP_FACE = SMESH_Block::ID_Fxy1,
61 BOTTOM_EDGE = 0, TOP_EDGE, V0_EDGE, V1_EDGE, // edge IDs in face
62 NB_WALL_FACES = 4 }; //
66 //================================================================================
68 * \brief Return iterator pointing to node column for the given parameter
69 * \param columnsMap - node column map
70 * \param parameter - parameter
71 * \retval TParam2ColumnMap::iterator - result
73 * it returns closest left column
75 //================================================================================
77 TParam2ColumnIt getColumn( const TParam2ColumnMap* columnsMap,
78 const double parameter )
80 TParam2ColumnIt u_col = columnsMap->upper_bound( parameter );
81 if ( u_col != columnsMap->begin() )
83 return u_col; // return left column
86 //================================================================================
88 * \brief Return nodes around given parameter and a ratio
89 * \param column - node column
90 * \param param - parameter
91 * \param node1 - lower node
92 * \param node2 - upper node
93 * \retval double - ratio
95 //================================================================================
97 double getRAndNodes( const TNodeColumn* column,
99 const SMDS_MeshNode* & node1,
100 const SMDS_MeshNode* & node2)
102 if ( param == 1.0 || column->size() == 1) {
103 node1 = node2 = column->back();
107 int i = int( param * ( column->size() - 1 ));
108 double u0 = double( i )/ double( column->size() - 1 );
109 double r = ( param - u0 ) * ( column->size() - 1 );
111 node1 = (*column)[ i ];
112 node2 = (*column)[ i + 1];
116 //================================================================================
118 * \brief Compute boundary parameters of face parts
119 * \param nbParts - nb of parts to split columns into
120 * \param columnsMap - node columns of the face to split
121 * \param params - computed parameters
123 //================================================================================
125 void splitParams( const int nbParts,
126 const TParam2ColumnMap* columnsMap,
127 vector< double > & params)
130 params.reserve( nbParts + 1 );
131 TParam2ColumnIt last_par_col = --columnsMap->end();
132 double par = columnsMap->begin()->first; // 0.
133 double parLast = last_par_col->first;
134 params.push_back( par );
135 for ( int i = 0; i < nbParts - 1; ++ i )
137 double partSize = ( parLast - par ) / double ( nbParts - i );
138 TParam2ColumnIt par_col = getColumn( columnsMap, par + partSize );
139 if ( par_col->first == par ) {
141 if ( par_col == last_par_col ) {
142 while ( i < nbParts - 1 )
143 params.push_back( par + partSize * i++ );
147 par = par_col->first;
148 params.push_back( par );
150 params.push_back( parLast ); // 1.
154 //=======================================================================
155 //function : StdMeshers_Prism_3D
157 //=======================================================================
159 StdMeshers_Prism_3D::StdMeshers_Prism_3D(int hypId, int studyId, SMESH_Gen* gen)
160 :SMESH_3D_Algo(hypId, studyId, gen)
163 _shapeType = (1 << TopAbs_SHELL) | (1 << TopAbs_SOLID); // 1 bit per shape type
164 myProjectTriangles = false;
167 //================================================================================
171 //================================================================================
173 StdMeshers_Prism_3D::~StdMeshers_Prism_3D()
176 //=======================================================================
177 //function : CheckHypothesis
179 //=======================================================================
181 bool StdMeshers_Prism_3D::CheckHypothesis(SMESH_Mesh& aMesh,
182 const TopoDS_Shape& aShape,
183 SMESH_Hypothesis::Hypothesis_Status& aStatus)
186 aStatus = SMESH_Hypothesis::HYP_OK;
190 //=======================================================================
193 //=======================================================================
195 bool StdMeshers_Prism_3D::Compute(SMESH_Mesh& theMesh, const TopoDS_Shape& theShape)
197 myHelper = new SMESH_MesherHelper( theMesh );
198 // to delete helper at exit from Compute()
199 std::auto_ptr<SMESH_MesherHelper> helperDeleter( myHelper );
201 myHelper->IsQuadraticSubMesh( theShape );
203 // Analyse mesh and geomerty to find block subshapes and submeshes
204 if ( !myBlock.Init( myHelper, theShape ))
207 SMESHDS_Mesh* meshDS = theMesh.GetMeshDS();
209 int volumeID = meshDS->ShapeToIndex( theShape );
212 // To compute coordinates of a node inside a block, it is necessary to know
213 // 1. normalized parameters of the node by which
214 // 2. coordinates of node projections on all block sub-shapes are computed
216 // So we fill projections on vertices at once as they are same for all nodes
217 myShapeXYZ.resize( myBlock.NbSubShapes() );
218 for ( int iV = SMESH_Block::ID_FirstV; iV < SMESH_Block::ID_FirstE; ++iV ) {
219 myBlock.VertexPoint( iV, myShapeXYZ[ iV ]);
220 SHOWYXZ("V point " <<iV << " ", myShapeXYZ[ iV ]);
223 // Projections on the top and bottom faces are taken from nodes existing
224 // on these faces; find correspondence between bottom and top nodes
225 myBotToColumnMap.clear();
226 if ( !assocOrProjBottom2Top() ) // it also fill myBotToColumnMap
230 // Create nodes inside the block
232 // loop on nodes inside the bottom face
233 TNode2ColumnMap::iterator bot_column = myBotToColumnMap.begin();
234 for ( ; bot_column != myBotToColumnMap.end(); ++bot_column )
236 const TNode& tBotNode = bot_column->first; // bottom TNode
237 if ( tBotNode.GetPositionType() != SMDS_TOP_FACE )
238 continue; // node is not inside face
240 // column nodes; middle part of the column are zero pointers
241 TNodeColumn& column = bot_column->second;
243 // bottom node parameters and coords
244 gp_XYZ botParams = tBotNode.GetParams();
245 myShapeXYZ[ ID_BOT_FACE ] = tBotNode.GetCoords();
247 // compute top node parameters
249 myShapeXYZ[ ID_TOP_FACE ] = gpXYZ( column.back() );
250 gp_Pnt topCoords = myShapeXYZ[ ID_TOP_FACE ];
251 if ( !myBlock.ComputeParameters( topCoords, topParams, ID_TOP_FACE ))
252 RETURN_BAD_RESULT("ComputeParameters() on the top face failed");
255 TNodeColumn::iterator columnNodes = column.begin();
256 for ( int z = 0; columnNodes != column.end(); ++columnNodes, ++z)
258 const SMDS_MeshNode* & node = *columnNodes;
259 if ( node ) continue; // skip bottom or top node
261 // params of a node to create
262 double rz = (double) z / (double) ( column.size() - 1 );
263 gp_XYZ params = botParams * ( 1 - rz ) + topParams * rz;
265 // set coords on all faces and nodes
266 const int nbSideFaces = 4;
267 int sideFaceIDs[nbSideFaces] = { SMESH_Block::ID_Fx0z,
268 SMESH_Block::ID_Fx1z,
269 SMESH_Block::ID_F0yz,
270 SMESH_Block::ID_F1yz };
271 for ( int iF = 0; iF < nbSideFaces; ++iF )
272 if ( !setFaceAndEdgesXYZ( sideFaceIDs[ iF ], params, z ))
275 // compute coords for a new node
277 if ( !SMESH_Block::ShellPoint( params, myShapeXYZ, coords ))
278 RETURN_BAD_RESULT("SMESH_Block::ShellPoint() failed");
281 node = meshDS->AddNode( coords.X(), coords.Y(), coords.Z() );
282 meshDS->SetNodeInVolume( node, volumeID );
284 } // loop on bottom nodes
289 SMESHDS_SubMesh* smDS = myBlock.SubMeshDS( ID_BOT_FACE );
290 if ( !smDS ) RETURN_BAD_RESULT("Null submesh");
292 // loop on bottom mesh faces
293 SMDS_ElemIteratorPtr faceIt = smDS->GetElements();
294 while ( faceIt->more() )
296 const SMDS_MeshElement* face = faceIt->next();
297 if ( !face || face->GetType() != SMDSAbs_Face )
299 int nbNodes = face->NbNodes();
300 if ( face->IsQuadratic() )
303 // find node columns for each node
304 vector< const TNodeColumn* > columns( nbNodes );
305 for ( int i = 0; i < nbNodes; ++i )
307 const SMDS_MeshNode* n = face->GetNode( i );
308 if ( n->GetPosition()->GetTypeOfPosition() == SMDS_TOP_FACE ) {
309 bot_column = myBotToColumnMap.find( n );
310 if ( bot_column == myBotToColumnMap.end() )
311 RETURN_BAD_RESULT(" node column for a node not found");
312 columns[ i ] = & bot_column->second;
315 columns[ i ] = myBlock.GetNodeColumn( n );
317 RETURN_BAD_RESULT(" node column not found for a node " << n->GetID() );
321 AddPrisms( columns, myHelper );
323 } // loop on bottom mesh faces
328 //================================================================================
330 * \brief Create prisms
331 * \param columns - columns of nodes generated from nodes of a mesh face
332 * \param helper - helper initialized by mesh and shape to add prisms to
334 //================================================================================
336 void StdMeshers_Prism_3D::AddPrisms( vector<const TNodeColumn*> & columns,
337 SMESH_MesherHelper* helper)
339 SMESHDS_Mesh * meshDS = helper->GetMeshDS();
340 int shapeID = helper->GetSubShapeID();
342 int nbNodes = columns.size();
344 // vertical loop on columns
345 for ( int z = 1; z < columns[0]->size(); ++z)
347 SMDS_MeshElement* vol = 0;
348 SMDS_VolumeTool vTool;
352 const SMDS_MeshNode* botNodes[3] = { (*columns[0])[z-1],
354 (*columns[2])[z-1] };
355 const SMDS_MeshNode* topNodes[3] = { (*columns[0])[z],
358 // assure good orientation
359 SMDS_VolumeOfNodes tmpVol ( botNodes[0], botNodes[1], botNodes[2],
360 topNodes[0], topNodes[1], topNodes[2]);
361 vTool.Set( &tmpVol );
362 if ( vTool.IsForward() )
363 vol = helper->AddVolume( botNodes[0], botNodes[1], botNodes[2],
364 topNodes[0], topNodes[1], topNodes[2]);
366 vol = helper->AddVolume( topNodes[0], topNodes[1], topNodes[2],
367 botNodes[0], botNodes[1], botNodes[2]);
371 const SMDS_MeshNode* botNodes[4] = { (*columns[0])[z-1], (*columns[1])[z-1],
372 (*columns[2])[z-1], (*columns[3])[z-1] };
373 const SMDS_MeshNode* topNodes[4] = { (*columns[0])[z], (*columns[1])[z],
374 (*columns[2])[z], (*columns[3])[z] };
375 // assure good orientation
376 SMDS_VolumeOfNodes tmpVol ( botNodes[0], botNodes[1], botNodes[2], botNodes[3],
377 topNodes[0], topNodes[1], topNodes[2], topNodes[3]);
378 vTool.Set( &tmpVol );
379 if ( vTool.IsForward() )
380 vol = helper->AddVolume( botNodes[0], botNodes[1], botNodes[2], botNodes[3],
381 topNodes[0], topNodes[1], topNodes[2], topNodes[3]);
383 vol = helper->AddVolume( topNodes[0], topNodes[1], topNodes[2], topNodes[3],
384 botNodes[0], botNodes[1], botNodes[2], botNodes[3]);
389 vector<const SMDS_MeshNode*> nodes( 2*nbNodes + 4*nbNodes);
390 vector<int> quantities( 2 + nbNodes, 4 );
391 quantities[0] = quantities[1] = nbNodes;
392 columns.resize( nbNodes + 1 );
393 columns[ nbNodes ] = columns[ 0 ];
394 for ( int i = 0; i < nbNodes; ++i ) {
395 nodes[ i ] = (*columns[ i ])[z-1]; // bottom
396 nodes[ i+nbNodes ] = (*columns[ i ])[z ]; // top
398 int di = 2*nbNodes + 4*i - 1;
399 nodes[ di ] = (*columns[i ])[z-1];
400 nodes[ di+1 ] = (*columns[i+1])[z-1];
401 nodes[ di+2 ] = (*columns[i+1])[z ];
402 nodes[ di+3 ] = (*columns[i ])[z ];
404 vol = meshDS->AddPolyhedralVolume( nodes, quantities );
406 if ( vol && shapeID > 0 )
407 meshDS->SetMeshElementOnShape( vol, shapeID );
411 //================================================================================
413 * \brief Find correspondence between bottom and top nodes
414 * If elements on the bottom and top faces are topologically different,
415 * and projection is possible and allowed, perform the projection
416 * \retval bool - is a success or not
418 //================================================================================
420 bool StdMeshers_Prism_3D::assocOrProjBottom2Top()
422 SMESH_subMesh * botSM = myBlock.SubMesh( ID_BOT_FACE );
423 SMESH_subMesh * topSM = myBlock.SubMesh( ID_TOP_FACE );
425 SMESHDS_SubMesh * botSMDS = botSM->GetSubMeshDS();
426 SMESHDS_SubMesh * topSMDS = topSM->GetSubMeshDS();
428 if ( !botSMDS || botSMDS->NbElements() == 0 )
429 RETURN_BAD_RESULT("Empty horiz submesh");
431 bool needProject = false;
433 botSMDS->NbElements() != topSMDS->NbElements() ||
434 botSMDS->NbNodes() != topSMDS->NbNodes())
436 if ( myBlock.HasNotQuadElemOnTop() )
437 RETURN_BAD_RESULT("Different triangles on 2 sides");
441 if ( 0/*needProject && !myProjectTriangles*/ )
442 RETURN_BAD_RESULT("Need to project but not allowed");
446 return projectBottomToTop();
449 TopoDS_Face botFace = TopoDS::Face( myBlock.Shape( ID_BOT_FACE ));
450 TopoDS_Face topFace = TopoDS::Face( myBlock.Shape( ID_TOP_FACE ));
451 // associate top and bottom faces
452 TAssocTool::TShapeShapeMap shape2ShapeMap;
453 if ( !TAssocTool::FindSubShapeAssociation( botFace, myBlock.Mesh(),
454 topFace, myBlock.Mesh(),
456 RETURN_BAD_RESULT("FindSubShapeAssociation failed");
458 // Find matching nodes of in and out faces
460 if ( ! TAssocTool::FindMatchingNodesOnFaces( botFace, myBlock.Mesh(),
461 topFace, myBlock.Mesh(),
462 shape2ShapeMap, n2nMap ))
463 RETURN_BAD_RESULT("Different mesh on top and bottom faces");
465 // Fill myBotToColumnMap
467 int zSize = myBlock.VerticalSize();
468 TNodeNodeMap::iterator bN_tN = n2nMap.begin();
469 for ( ; bN_tN != n2nMap.end(); ++bN_tN )
471 const SMDS_MeshNode* botNode = bN_tN->first;
472 const SMDS_MeshNode* topNode = bN_tN->second;
473 if ( botNode->GetPosition()->GetTypeOfPosition() != SMDS_TOP_FACE )
474 continue; // wall columns are contained in myBlock
475 // compute bottom node params
477 if ( !myBlock.ComputeParameters( bN.GetCoords(), bN.ChangeParams(), ID_BOT_FACE ))
478 RETURN_BAD_RESULT("ComputeParameters() on the bottom face failed");
479 // create node column
480 TNode2ColumnMap::iterator bN_col =
481 myBotToColumnMap.insert( make_pair ( bN, TNodeColumn() )).first;
482 TNodeColumn & column = bN_col->second;
483 column.resize( zSize );
484 column.front() = botNode;
485 column.back() = topNode;
490 //================================================================================
492 * \brief Remove quadrangles from the top face and
493 * create triangles there by projection from the bottom
494 * \retval bool - a success or not
496 //================================================================================
498 bool StdMeshers_Prism_3D::projectBottomToTop()
500 SMESH_subMesh * botSM = myBlock.SubMesh( ID_BOT_FACE );
501 SMESH_subMesh * topSM = myBlock.SubMesh( ID_TOP_FACE );
503 SMESHDS_SubMesh * botSMDS = botSM->GetSubMeshDS();
504 SMESHDS_SubMesh * topSMDS = topSM->GetSubMeshDS();
507 topSM->ComputeStateEngine( SMESH_subMesh::CLEAN );
509 SMESHDS_Mesh* meshDS = myBlock.MeshDS();
510 int shapeID = myHelper->GetSubShapeID();
511 int topFaceID = meshDS->ShapeToIndex( topSM->GetSubShape() );
513 // Fill myBotToColumnMap
515 int zSize = myBlock.VerticalSize();
516 SMDS_NodeIteratorPtr nIt = botSMDS->GetNodes();
517 while ( nIt->more() )
519 const SMDS_MeshNode* botNode = nIt->next();
520 if ( botNode->GetPosition()->GetTypeOfPosition() != SMDS_TOP_FACE )
522 // compute bottom node params
524 if ( !myBlock.ComputeParameters( bN.GetCoords(), bN.ChangeParams(), ID_BOT_FACE ))
525 RETURN_BAD_RESULT("ComputeParameters() on the bottom face failed");
526 // compute top node coords
527 gp_XYZ topXYZ; gp_XY topUV;
528 if ( !myBlock.FacePoint( ID_TOP_FACE, bN.GetParams(), topXYZ ) ||
529 !myBlock.FaceUV ( ID_TOP_FACE, bN.GetParams(), topUV ))
530 RETURN_BAD_RESULT("SMESH_Block::FacePoint() on the top face failed");
531 SMDS_MeshNode * topNode = meshDS->AddNode( topXYZ.X(),topXYZ.Y(),topXYZ.Z() );
532 meshDS->SetNodeOnFace( topNode, topFaceID, topUV.X(), topUV.Y() );
533 // create node column
534 TNode2ColumnMap::iterator bN_col =
535 myBotToColumnMap.insert( make_pair ( bN, TNodeColumn() )).first;
536 TNodeColumn & column = bN_col->second;
537 column.resize( zSize );
538 column.front() = botNode;
539 column.back() = topNode;
544 // loop on bottom mesh faces
545 SMDS_ElemIteratorPtr faceIt = botSMDS->GetElements();
546 while ( faceIt->more() )
548 const SMDS_MeshElement* face = faceIt->next();
549 if ( !face || face->GetType() != SMDSAbs_Face )
551 int nbNodes = face->NbNodes();
552 if ( face->IsQuadratic() )
555 // find top node in columns for each bottom node
556 vector< const SMDS_MeshNode* > nodes( nbNodes );
557 for ( int i = 0; i < nbNodes; ++i )
559 const SMDS_MeshNode* n = face->GetNode( nbNodes - i - 1 );
560 if ( n->GetPosition()->GetTypeOfPosition() == SMDS_TOP_FACE ) {
561 TNode2ColumnMap::iterator bot_column = myBotToColumnMap.find( n );
562 if ( bot_column == myBotToColumnMap.end() )
563 RETURN_BAD_RESULT(" node column for a node not found");
564 nodes[ i ] = bot_column->second.back();
567 const TNodeColumn* column = myBlock.GetNodeColumn( n );
569 RETURN_BAD_RESULT(" node column not found for a node " << n->GetID() );
570 nodes[ i ] = column->back();
573 // create a face, with reversed orientation
574 SMDS_MeshElement* newFace = 0;
578 newFace = myHelper->AddFace(nodes[0], nodes[1], nodes[2]);
582 newFace = myHelper->AddFace( nodes[0], nodes[1], nodes[2], nodes[3] );
586 newFace = meshDS->AddPolygonalFace( nodes );
588 if ( newFace && shapeID > 0 )
589 meshDS->SetMeshElementOnShape( newFace, shapeID );
595 //================================================================================
597 * \brief Set projection coordinates of a node to a face and it's subshapes
598 * \param faceID - the face given by in-block ID
599 * \param params - node normalized parameters
600 * \retval bool - is a success
602 //================================================================================
604 bool StdMeshers_Prism_3D::setFaceAndEdgesXYZ( const int faceID, const gp_XYZ& params, int z )
606 // find base and top edges of the face
607 enum { BASE = 0, TOP, LEFT, RIGHT };
608 vector< int > edgeVec; // 0-base, 1-top
609 SMESH_Block::GetFaceEdgesIDs( faceID, edgeVec );
611 myBlock.EdgePoint( edgeVec[ BASE ], params, myShapeXYZ[ edgeVec[ BASE ]]);
612 myBlock.EdgePoint( edgeVec[ TOP ], params, myShapeXYZ[ edgeVec[ TOP ]]);
614 SHOWYXZ("\nparams ", params);
615 SHOWYXZ("TOP is "<<edgeVec[ TOP], myShapeXYZ[ edgeVec[ TOP]]);
616 SHOWYXZ("BASE is "<<edgeVec[ BASE], myShapeXYZ[ edgeVec[ BASE]]);
618 if ( faceID == SMESH_Block::ID_Fx0z || faceID == SMESH_Block::ID_Fx1z )
620 myBlock.EdgePoint( edgeVec[ LEFT ], params, myShapeXYZ[ edgeVec[ LEFT ]]);
621 myBlock.EdgePoint( edgeVec[ RIGHT ], params, myShapeXYZ[ edgeVec[ RIGHT ]]);
623 SHOWYXZ("VER "<<edgeVec[ LEFT], myShapeXYZ[ edgeVec[ LEFT]]);
624 SHOWYXZ("VER "<<edgeVec[ RIGHT], myShapeXYZ[ edgeVec[ RIGHT]]);
626 myBlock.FacePoint( faceID, params, myShapeXYZ[ faceID ]);
627 SHOWYXZ("FacePoint "<<faceID, myShapeXYZ[ faceID]);
632 //================================================================================
634 * \brief Constructor. Initialization is needed
636 //================================================================================
638 StdMeshers_PrismAsBlock::StdMeshers_PrismAsBlock()
643 StdMeshers_PrismAsBlock::~StdMeshers_PrismAsBlock()
646 delete mySide; mySide = 0;
650 //================================================================================
652 * \brief Initialization.
653 * \param helper - helper loaded with mesh and 3D shape
654 * \param shape3D - a closed shell or solid
655 * \retval bool - false if a mesh or a shape are KO
657 //================================================================================
659 bool StdMeshers_PrismAsBlock::Init(SMESH_MesherHelper* helper,
660 const TopoDS_Shape& shape3D)
663 delete mySide; mySide = 0;
665 vector< TSideFace* > sideFaces( NB_WALL_FACES, 0 );
666 vector< pair< double, double> > params ( NB_WALL_FACES );
667 mySide = new TSideFace( sideFaces, params );
670 SMESHDS_Mesh* meshDS = myHelper->GetMesh()->GetMeshDS();
672 int wallFaceIds[ NB_WALL_FACES ] = { // to walk around a block
673 SMESH_Block::ID_Fx0z, SMESH_Block::ID_F1yz,
674 SMESH_Block::ID_Fx1z, SMESH_Block::ID_F0yz
678 // -------------------------------------------------------------
679 // Look for top and bottom faces: not quadrangle ones or meshed
680 // with not quadrangle elements
681 // -------------------------------------------------------------
683 list< SMESH_subMesh* > notQuadGeomSubMesh;
684 list< SMESH_subMesh* > notQuadElemSubMesh;
687 SMESH_subMesh* mainSubMesh = myHelper->GetMesh()->GetSubMeshContaining( shape3D );
688 if ( !mainSubMesh ) RETURN_BAD_RESULT("Null submesh of shape3D");
690 const map< int, SMESH_subMesh * >& subSM = mainSubMesh->DependsOn();
691 map< int, SMESH_subMesh * >::const_iterator i_subSM = subSM.begin();
692 for ( ; i_subSM != subSM.end(); ++i_subSM )
694 SMESH_subMesh* sm = i_subSM->second;
695 const TopoDS_Shape& face = sm->GetSubShape();
696 if ( face.ShapeType() != TopAbs_FACE )
700 // is quadrangle face?
701 if ( TAssocTool::Count( face, TopAbs_EDGE, 0 ) != 4 ||
702 TAssocTool::Count( face, TopAbs_WIRE, 0 ) != 1 )
703 notQuadGeomSubMesh.push_back( sm );
705 // count not quadrangle mesh elements
706 if ( SMESHDS_SubMesh* smDS = sm->GetSubMeshDS() ) {
707 SMDS_ElemIteratorPtr eIt = smDS->GetElements();
708 bool hasNotQuad = false;
709 while ( eIt->more() && !hasNotQuad ) {
710 const SMDS_MeshElement* elem = eIt->next();
711 if ( elem->GetType() == SMDSAbs_Face ) {
712 int nbNodes = elem->NbNodes();
713 if ( elem->IsQuadratic() )
715 hasNotQuad = ( nbNodes != 4 );
719 notQuadElemSubMesh.push_back( sm );
722 RETURN_BAD_RESULT("not meshed face");
726 // ----------------------------------------------------------------------
727 // Analyse faces mesh and topology: choose the bottom submesh.
728 // If there are not quadrangle geom faces, they are top and bottom ones.
729 // Not quadrangle geom faces must be only on top and bottom.
730 // ----------------------------------------------------------------------
732 SMESH_subMesh * botSM = 0;
733 SMESH_subMesh * topSM = 0;
735 int nbNotQuad = notQuadGeomSubMesh.size();
736 int nbNotQuadMeshed = notQuadElemSubMesh.size();
737 bool hasNotQuad = ( nbNotQuad || nbNotQuadMeshed );
740 if ( nbNotQuad > 0 && nbNotQuad != 2 )
741 RETURN_BAD_RESULT("Wrong shape geometry");
742 if ( nbNotQuadMeshed > 2 )
743 RETURN_BAD_RESULT("More then 2 faces meshed with not quadrangle elements");
745 // get found submeshes
748 if ( nbNotQuadMeshed > 0 ) botSM = notQuadElemSubMesh.front();
749 else botSM = notQuadGeomSubMesh.front();
750 if ( nbNotQuadMeshed > 1 ) topSM = notQuadElemSubMesh.back();
751 else if ( nbNotQuad > 1 ) topSM = notQuadGeomSubMesh.back();
753 // detect other bad cases
754 if ( nbNotQuad == 2 && nbNotQuadMeshed > 0 ) {
756 if ( nbNotQuadMeshed == 1 )
757 ok = ( find( notQuadGeomSubMesh.begin(),
758 notQuadGeomSubMesh.end(), botSM ) != notQuadGeomSubMesh.end() );
760 ok = ( notQuadGeomSubMesh == notQuadElemSubMesh );
762 RETURN_BAD_RESULT("Side face meshed with not quadrangle elements");
765 myNotQuadOnTop = ( nbNotQuadMeshed > 1 );
767 // ----------------------------------------------------------
769 if ( nbNotQuad == 0 ) // Standard block of 6 quadrangle faces ?
771 // SMESH_Block will perform geometry analysis, we need just to find 2
772 // connected vertices on top and bottom
774 TopoDS_Vertex Vbot, Vtop;
775 if ( nbNotQuadMeshed > 0 ) // Look for vertices
777 TopTools_IndexedMapOfShape edgeMap;
778 TopExp::MapShapes( botSM->GetSubShape(), TopAbs_EDGE, edgeMap );
779 // vertex 1 is any vertex of the bottom face
780 Vbot = TopExp::FirstVertex( TopoDS::Edge( edgeMap( 1 )));
781 // vertex 2 is end vertex of edge sharing Vbot and not belonging to the bottom face
782 TopTools_ListIteratorOfListOfShape ancestIt = Mesh()->GetAncestors( Vbot );
783 for ( ; Vtop.IsNull() && ancestIt.More(); ancestIt.Next() )
785 const TopoDS_Shape & ancestor = ancestIt.Value();
786 if ( ancestor.ShapeType() == TopAbs_EDGE && !edgeMap.FindIndex( ancestor ))
788 Vtop = TopExp::LastVertex( TopoDS::Edge( ancestor ));
789 if ( Vbot.IsSame ( Vtop ))
790 Vtop = TopExp::FirstVertex( TopoDS::Edge( ancestor ));
794 // get shell from shape3D
796 TopExp_Explorer exp( shape3D, TopAbs_SHELL );
798 for ( ; exp.More(); exp.Next(), ++nbShell )
799 shell = TopoDS::Shell( exp.Current() );
800 // if ( nbShell != 1 )
801 // RETURN_BAD_RESULT("There must be 1 shell in the block");
803 // Load geometry in SMESH_Block
804 myShapeIDMap.Clear();
805 if ( !SMESH_Block::FindBlockShapes( shell, Vbot, Vtop, myShapeIDMap )) {
807 RETURN_BAD_RESULT("Can not detect top and bottom");
810 if ( !botSM ) botSM = Mesh()->GetSubMeshContaining( myShapeIDMap( ID_BOT_FACE ));
811 if ( !topSM ) topSM = Mesh()->GetSubMeshContaining( myShapeIDMap( ID_TOP_FACE ));
814 } // end Standard block of 6 quadrangle faces
815 // --------------------------------------------------------
817 // Here the top and bottom faces are found
818 if ( nbNotQuadMeshed == 2 ) // roughly check correspondence of horiz meshes
820 // SMESHDS_SubMesh* topSMDS = topSM->GetSubMeshDS();
821 // SMESHDS_SubMesh* botSMDS = botSM->GetSubMeshDS();
822 // if ( topSMDS->NbNodes() != botSMDS->NbNodes() ||
823 // topSMDS->NbElements() != botSMDS->NbElements() )
824 // RETURN_BAD_RESULT("Top mesh doesn't correspond to bottom one");
827 // ---------------------------------------------------------
828 // If there are not quadrangle geom faces, we emulate
829 // a block of 6 quadrangle faces.
830 // Load SMESH_Block with faces and edges geometry
831 // ---------------------------------------------------------
834 // find vertex 000 - the one with smallest coordinates (for easy DEBUG :-)
836 double minVal = DBL_MAX, minX, val;
837 for ( TopExp_Explorer exp( botSM->GetSubShape(), TopAbs_VERTEX );
838 exp.More(); exp.Next() )
840 const TopoDS_Vertex& v = TopoDS::Vertex( exp.Current() );
841 gp_Pnt P = BRep_Tool::Pnt( v );
842 val = P.X() + P.Y() + P.Z();
843 if ( val < minVal || ( val == minVal && P.X() < minX )) {
850 // Get ordered bottom edges
851 list< TopoDS_Edge > orderedEdges;
852 list< int > nbVertexInWires;
853 SMESH_Block::GetOrderedEdges( TopoDS::Face( botSM->GetSubShape().Reversed() ),
854 V000, orderedEdges, nbVertexInWires );
855 // if ( nbVertexInWires.size() != 1 )
856 // RETURN_BAD_RESULT("Wrong prism geometry");
858 // Get Wall faces corresponding to the ordered bottom edges
859 list< TopoDS_Face > wallFaces;
860 if ( !GetWallFaces( Mesh(), shape3D, botSM->GetSubShape(), orderedEdges, wallFaces))
861 RETURN_BAD_RESULT("GetWallFaces() failed");
863 // Find columns of wall nodes and calculate edges' lengths
864 // --------------------------------------------------------
866 myParam2ColumnMaps.clear();
867 myParam2ColumnMaps.resize( orderedEdges.size() ); // total nb edges
869 int iE, nbEdges = nbVertexInWires.front(); // nb outer edges
870 vector< double > edgeLength( nbEdges );
871 map< double, int > len2edgeMap;
873 list< TopoDS_Edge >::iterator edgeIt = orderedEdges.begin();
874 list< TopoDS_Face >::iterator faceIt = wallFaces.begin();
875 for ( iE = 0; iE < nbEdges; ++edgeIt, ++faceIt )
877 TParam2ColumnMap & faceColumns = myParam2ColumnMaps[ iE ];
878 if ( !myHelper->LoadNodeColumns( faceColumns, *faceIt, *edgeIt, meshDS ))
879 RETURN_BAD_RESULT("SMESH_MesherHelper::LoadNodeColumns() failed");
881 SHOWYXZ("\np1 F "<<iE, gpXYZ(faceColumns.begin()->second.front() ));
882 SHOWYXZ("p2 F "<<iE, gpXYZ(faceColumns.rbegin()->second.front() ));
883 SHOWYXZ("V First "<<iE, BRep_Tool::Pnt( TopExp::FirstVertex(*edgeIt,true )));
885 edgeLength[ iE ] = SMESH_Algo::EdgeLength( *edgeIt );
887 if ( nbEdges < NB_WALL_FACES ) // fill map used to split faces
889 SMESHDS_SubMesh* smDS = meshDS->MeshElements( *edgeIt);
891 RETURN_BAD_RESULT("Null submesh on a bottom edge");
892 // assure length uniqueness
893 edgeLength[ iE ] *= smDS->NbNodes() + edgeLength[ iE ] / ( 1000 + iE );
894 len2edgeMap[ edgeLength[ iE ]] = iE;
898 // Load columns of internal edges (forming holes)
899 // and fill map ShapeIndex to TParam2ColumnMap for them
900 for ( ; edgeIt != orderedEdges.end() ; ++edgeIt, ++faceIt )
902 TParam2ColumnMap & faceColumns = myParam2ColumnMaps[ iE ];
903 if ( !myHelper->LoadNodeColumns( faceColumns, *faceIt, *edgeIt, meshDS ))
904 RETURN_BAD_RESULT("SMESH_MesherHelper::LoadNodeColumns() failed");
906 int id = MeshDS()->ShapeToIndex( *edgeIt );
907 bool isForward = true; // meaningless for intenal wires
908 myShapeIndex2ColumnMap[ id ] = make_pair( & faceColumns, isForward );
909 // columns for vertices
911 const SMDS_MeshNode* n0 = faceColumns.begin()->second.front();
912 id = n0->GetPosition()->GetShapeId();
913 myShapeIndex2ColumnMap[ id ] = make_pair( & faceColumns, isForward );
915 const SMDS_MeshNode* n1 = faceColumns.rbegin()->second.front();
916 id = n1->GetPosition()->GetShapeId();
917 myShapeIndex2ColumnMap[ id ] = make_pair( & faceColumns, isForward );
918 // SHOWYXZ("\np1 F "<<iE, gpXYZ(faceColumns.begin()->second.front() ));
919 // SHOWYXZ("p2 F "<<iE, gpXYZ(faceColumns.rbegin()->second.front() ));
920 // SHOWYXZ("V First "<<iE, BRep_Tool::Pnt( TopExp::FirstVertex(*edgeIt,true )));
924 // Create 4 wall faces of a block
925 // -------------------------------
927 if ( nbEdges <= NB_WALL_FACES ) // ************* Split faces if necessary
929 map< int, int > iE2nbSplit;
930 if ( nbEdges != NB_WALL_FACES ) // define how to split
932 if ( len2edgeMap.size() != nbEdges )
933 RETURN_BAD_RESULT("Uniqueness of edge lengths not assured");
934 map< double, int >::reverse_iterator maxLen_i = len2edgeMap.rbegin();
935 map< double, int >::reverse_iterator midLen_i = ++len2edgeMap.rbegin();
936 double maxLen = maxLen_i->first;
937 double midLen = ( len2edgeMap.size() == 1 ) ? 0 : midLen_i->first;
939 case 1: // 0-th edge is split into 4 parts
940 iE2nbSplit.insert( make_pair( 0, 4 )); break;
941 case 2: // either the longest edge is split into 3 parts, or both edges into halves
942 if ( maxLen / 3 > midLen / 2 ) {
943 iE2nbSplit.insert( make_pair( maxLen_i->second, 3 ));
946 iE2nbSplit.insert( make_pair( maxLen_i->second, 2 ));
947 iE2nbSplit.insert( make_pair( midLen_i->second, 2 ));
951 // split longest into halves
952 iE2nbSplit.insert( make_pair( maxLen_i->second, 2 ));
955 // Create TSideFace's
956 faceIt = wallFaces.begin();
957 edgeIt = orderedEdges.begin();
959 for ( iE = 0; iE < nbEdges; ++edgeIt, ++faceIt )
962 map< int, int >::iterator i_nb = iE2nbSplit.find( iE );
963 if ( i_nb != iE2nbSplit.end() ) {
965 int nbSplit = i_nb->second;
966 vector< double > params;
967 splitParams( nbSplit, &myParam2ColumnMaps[ iE ], params );
968 bool isForward = ( edgeIt->Orientation() == TopAbs_FORWARD );
969 for ( int i = 0; i < nbSplit; ++i ) {
970 double f = ( isForward ? params[ i ] : params[ nbSplit - i-1 ]);
971 double l = ( isForward ? params[ i+1 ] : params[ nbSplit - i ]);
972 TSideFace* comp = new TSideFace( myHelper, wallFaceIds[ iSide ],
974 &myParam2ColumnMaps[ iE ], f, l );
975 mySide->SetComponent( iSide++, comp );
979 TSideFace* comp = new TSideFace( myHelper, wallFaceIds[ iSide ],
981 &myParam2ColumnMaps[ iE ]);
982 mySide->SetComponent( iSide++, comp );
987 else { // **************************** Unite faces
990 int nbExraFaces = nbEdges - 3;
992 double u0 = 0, sumLen = 0;
993 for ( iE = 0; iE < nbExraFaces; ++iE )
994 sumLen += edgeLength[ iE ];
996 vector< TSideFace* > components( nbExraFaces );
997 vector< pair< double, double> > params( nbExraFaces );
998 faceIt = wallFaces.begin();
999 edgeIt = orderedEdges.begin();
1000 for ( iE = 0; iE < nbExraFaces; ++edgeIt, ++faceIt )
1002 components[ iE ] = new TSideFace( myHelper, wallFaceIds[ iSide ],
1004 &myParam2ColumnMaps[ iE ]);
1005 double u1 = u0 + edgeLength[ iE ] / sumLen;
1006 params[ iE ] = make_pair( u0 , u1 );
1010 mySide->SetComponent( iSide++, new TSideFace( components, params ));
1012 // fill the rest faces
1013 for ( ; iE < nbEdges; ++faceIt, ++edgeIt )
1015 TSideFace* comp = new TSideFace( myHelper, wallFaceIds[ iSide ],
1017 &myParam2ColumnMaps[ iE ]);
1018 mySide->SetComponent( iSide++, comp );
1024 // Fill geometry fields of SMESH_Block
1025 // ------------------------------------
1027 TopoDS_Face botF = TopoDS::Face( botSM->GetSubShape() );
1028 TopoDS_Face topF = TopoDS::Face( topSM->GetSubShape() );
1030 vector< int > botEdgeIdVec;
1031 SMESH_Block::GetFaceEdgesIDs( ID_BOT_FACE, botEdgeIdVec );
1033 bool isForward[NB_WALL_FACES] = { true, true, true, true };
1034 Adaptor2d_Curve2d* botPcurves[NB_WALL_FACES];
1035 Adaptor2d_Curve2d* topPcurves[NB_WALL_FACES];
1037 for ( int iF = 0; iF < NB_WALL_FACES; ++iF )
1039 TSideFace * sideFace = mySide->GetComponent( iF );
1041 RETURN_BAD_RESULT("NULL TSideFace");
1042 int fID = sideFace->FaceID();
1044 // fill myShapeIDMap
1045 if ( sideFace->InsertSubShapes( myShapeIDMap ) != 8 &&
1046 !sideFace->IsComplex())
1047 MESSAGE( ": Warning : InsertSubShapes() < 8 on side " << iF );
1049 // side faces geometry
1050 Adaptor2d_Curve2d* pcurves[NB_WALL_FACES];
1051 if ( !sideFace->GetPCurves( pcurves ))
1052 RETURN_BAD_RESULT("TSideFace::GetPCurves() failed");
1054 SMESH_Block::TFace& tFace = myFace[ fID - ID_FirstF ];
1055 tFace.Set( fID, sideFace->Surface(), pcurves, isForward );
1057 SHOWYXZ( endl<<"F "<< iF << " id " << fID << " FRW " << sideFace->IsForward(), );
1058 // edges 3D geometry
1059 vector< int > edgeIdVec;
1060 SMESH_Block::GetFaceEdgesIDs( fID, edgeIdVec );
1061 for ( int isMax = 0; isMax < 2; ++isMax ) {
1063 int eID = edgeIdVec[ isMax ];
1064 SMESH_Block::TEdge& tEdge = myEdge[ eID - ID_FirstE ];
1065 tEdge.Set( eID, sideFace->HorizCurve(isMax), true);
1066 SHOWYXZ(eID<<" HOR"<<isMax<<"(0)", sideFace->HorizCurve(isMax)->Value(0));
1067 SHOWYXZ(eID<<" HOR"<<isMax<<"(1)", sideFace->HorizCurve(isMax)->Value(1));
1070 int eID = edgeIdVec[ isMax+2 ];
1071 SMESH_Block::TEdge& tEdge = myEdge[ eID - ID_FirstE ];
1072 tEdge.Set( eID, sideFace->VertiCurve(isMax), true);
1073 SHOWYXZ(eID<<" VER"<<isMax<<"(0)", sideFace->VertiCurve(isMax)->Value(0));
1074 SHOWYXZ(eID<<" VER"<<isMax<<"(1)", sideFace->VertiCurve(isMax)->Value(1));
1077 vector< int > vertexIdVec;
1078 SMESH_Block::GetEdgeVertexIDs( eID, vertexIdVec );
1079 myPnt[ vertexIdVec[0] - ID_FirstV ] = tEdge.GetCurve()->Value(0).XYZ();
1080 myPnt[ vertexIdVec[1] - ID_FirstV ] = tEdge.GetCurve()->Value(1).XYZ();
1083 // pcurves on horizontal faces
1084 for ( iE = 0; iE < NB_WALL_FACES; ++iE ) {
1085 if ( edgeIdVec[ BOTTOM_EDGE ] == botEdgeIdVec[ iE ] ) {
1086 botPcurves[ iE ] = sideFace->HorizPCurve( false, botF );
1087 topPcurves[ iE ] = sideFace->HorizPCurve( true, topF );
1092 // horizontal faces geometry
1094 SMESH_Block::TFace& tFace = myFace[ ID_BOT_FACE - ID_FirstF ];
1095 tFace.Set( ID_BOT_FACE, new BRepAdaptor_Surface( botF ), botPcurves, isForward );
1096 SMESH_Block::Insert( botF, ID_BOT_FACE, myShapeIDMap );
1099 SMESH_Block::TFace& tFace = myFace[ ID_TOP_FACE - ID_FirstF ];
1100 tFace.Set( ID_TOP_FACE, new BRepAdaptor_Surface( topF ), topPcurves, isForward );
1101 SMESH_Block::Insert( topF, ID_TOP_FACE, myShapeIDMap );
1104 // Fill map ShapeIndex to TParam2ColumnMap
1105 // ----------------------------------------
1107 list< TSideFace* > fList;
1108 list< TSideFace* >::iterator fListIt;
1109 fList.push_back( mySide );
1110 for ( fListIt = fList.begin(); fListIt != fList.end(); ++fListIt)
1112 int nb = (*fListIt)->NbComponents();
1113 for ( int i = 0; i < nb; ++i ) {
1114 if ( TSideFace* comp = (*fListIt)->GetComponent( i ))
1115 fList.push_back( comp );
1117 if ( TParam2ColumnMap* cols = (*fListIt)->GetColumns()) {
1118 // columns for a base edge
1119 int id = MeshDS()->ShapeToIndex( (*fListIt)->BaseEdge() );
1120 bool isForward = (*fListIt)->IsForward();
1121 myShapeIndex2ColumnMap[ id ] = make_pair( cols, isForward );
1123 // columns for vertices
1124 const SMDS_MeshNode* n0 = cols->begin()->second.front();
1125 id = n0->GetPosition()->GetShapeId();
1126 myShapeIndex2ColumnMap[ id ] = make_pair( cols, isForward );
1128 const SMDS_MeshNode* n1 = cols->rbegin()->second.front();
1129 id = n1->GetPosition()->GetShapeId();
1130 myShapeIndex2ColumnMap[ id ] = make_pair( cols, !isForward );
1134 // gp_XYZ testPar(0.25, 0.25, 0), testCoord;
1135 // if ( !FacePoint( ID_BOT_FACE, testPar, testCoord ))
1136 // RETURN_BAD_RESULT("TEST FacePoint() FAILED");
1137 // SHOWYXZ("IN TEST PARAM" , testPar);
1138 // SHOWYXZ("OUT TEST CORD" , testCoord);
1139 // if ( !ComputeParameters( testCoord, testPar , ID_BOT_FACE))
1140 // RETURN_BAD_RESULT("TEST ComputeParameters() FAILED");
1141 // SHOWYXZ("OUT TEST PARAM" , testPar);
1146 //================================================================================
1148 * \brief Return pointer to column of nodes
1149 * \param node - bottom node from which the returned column goes up
1150 * \retval const TNodeColumn* - the found column
1152 //================================================================================
1154 const TNodeColumn* StdMeshers_PrismAsBlock::GetNodeColumn(const SMDS_MeshNode* node) const
1156 int sID = node->GetPosition()->GetShapeId();
1158 map<int, pair< TParam2ColumnMap*, bool > >::const_iterator col_frw =
1159 myShapeIndex2ColumnMap.find( sID );
1160 if ( col_frw != myShapeIndex2ColumnMap.end() ) {
1161 const TParam2ColumnMap* cols = col_frw->second.first;
1162 TParam2ColumnIt u_col = cols->begin();
1163 for ( ; u_col != cols->end(); ++u_col )
1164 if ( u_col->second[ 0 ] == node )
1165 return & u_col->second;
1170 //================================================================================
1172 * \brief Check curve orientation of a bootom edge
1173 * \param meshDS - mesh DS
1174 * \param columnsMap - node columns map of side face
1175 * \param bottomEdge - the bootom edge
1176 * \param sideFaceID - side face in-block ID
1177 * \retval bool - true if orientation coinside with in-block froward orientation
1179 //================================================================================
1181 bool StdMeshers_PrismAsBlock::IsForwardEdge(SMESHDS_Mesh* meshDS,
1182 const TParam2ColumnMap& columnsMap,
1183 const TopoDS_Edge & bottomEdge,
1184 const int sideFaceID)
1186 bool isForward = false;
1187 if ( TAssocTool::IsClosedEdge( bottomEdge ))
1189 isForward = ( bottomEdge.Orientation() == TopAbs_FORWARD );
1193 const TNodeColumn& firstCol = columnsMap.begin()->second;
1194 const SMDS_MeshNode* bottomNode = firstCol[0];
1195 TopoDS_Shape firstVertex = SMESH_MesherHelper::GetSubShapeByNode( bottomNode, meshDS );
1196 isForward = ( firstVertex.IsSame( TopExp::FirstVertex( bottomEdge, true )));
1198 // on 2 of 4 sides first vertex is end
1199 if ( sideFaceID == ID_Fx1z || sideFaceID == ID_F0yz )
1200 isForward = !isForward;
1204 //================================================================================
1206 * \brief Find wall faces by bottom edges
1207 * \param mesh - the mesh
1208 * \param mainShape - the prism
1209 * \param bottomFace - the bottom face
1210 * \param bottomEdges - edges bounding the bottom face
1211 * \param wallFaces - faces list to fill in
1213 //================================================================================
1215 bool StdMeshers_PrismAsBlock::GetWallFaces( SMESH_Mesh* mesh,
1216 const TopoDS_Shape & mainShape,
1217 const TopoDS_Shape & bottomFace,
1218 const std::list< TopoDS_Edge >& bottomEdges,
1219 std::list< TopoDS_Face >& wallFaces)
1223 TopTools_IndexedMapOfShape faceMap;
1224 TopExp::MapShapes( mainShape, TopAbs_FACE, faceMap );
1226 list< TopoDS_Edge >::const_iterator edge = bottomEdges.begin();
1227 for ( ; edge != bottomEdges.end(); ++edge )
1229 TopTools_ListIteratorOfListOfShape ancestIt = mesh->GetAncestors( *edge );
1230 for ( ; ancestIt.More(); ancestIt.Next() )
1232 const TopoDS_Shape& ancestor = ancestIt.Value();
1233 if ( ancestor.ShapeType() == TopAbs_FACE && // face
1234 !bottomFace.IsSame( ancestor ) && // not bottom
1235 faceMap.FindIndex( ancestor )) // belongs to the prism
1237 wallFaces.push_back( TopoDS::Face( ancestor ));
1242 return ( wallFaces.size() == bottomEdges.size() );
1245 //================================================================================
1247 * \brief Constructor
1248 * \param faceID - in-block ID
1249 * \param face - geom face
1250 * \param columnsMap - map of node columns
1251 * \param first - first normalized param
1252 * \param last - last normalized param
1254 //================================================================================
1256 StdMeshers_PrismAsBlock::TSideFace::TSideFace(SMESH_MesherHelper* helper,
1258 const TopoDS_Face& face,
1259 const TopoDS_Edge& baseEdge,
1260 TParam2ColumnMap* columnsMap,
1264 myParamToColumnMap( columnsMap ),
1265 myBaseEdge( baseEdge ),
1268 mySurface.Initialize( face );
1269 myParams.resize( 1 );
1270 myParams[ 0 ] = make_pair( first, last );
1271 myIsForward = StdMeshers_PrismAsBlock::IsForwardEdge( myHelper->GetMeshDS(),
1272 *myParamToColumnMap,
1276 //================================================================================
1278 * \brief Constructor of complex side face
1280 //================================================================================
1282 StdMeshers_PrismAsBlock::TSideFace::
1283 TSideFace(const vector< TSideFace* >& components,
1284 const vector< pair< double, double> > & params)
1285 :myID( components[0] ? components[0]->myID : 0 ),
1286 myParamToColumnMap( 0 ),
1288 myIsForward( true ),
1289 myComponents( components ),
1290 myHelper( components[0] ? components[0]->myHelper : 0 )
1292 //================================================================================
1294 * \brief Copy constructor
1295 * \param other - other side
1297 //================================================================================
1299 StdMeshers_PrismAsBlock::TSideFace::TSideFace( const TSideFace& other )
1302 mySurface = other.mySurface;
1303 myBaseEdge = other.myBaseEdge;
1304 myParams = other.myParams;
1305 myIsForward = other.myIsForward;
1306 myHelper = other.myHelper;
1307 myParamToColumnMap = other.myParamToColumnMap;
1309 myComponents.resize( other.myComponents.size());
1310 for (int i = 0 ; i < myComponents.size(); ++i )
1311 myComponents[ i ] = new TSideFace( *other.myComponents[ i ]);
1314 //================================================================================
1316 * \brief Deletes myComponents
1318 //================================================================================
1320 StdMeshers_PrismAsBlock::TSideFace::~TSideFace()
1322 for (int i = 0 ; i < myComponents.size(); ++i )
1323 if ( myComponents[ i ] )
1324 delete myComponents[ i ];
1327 //================================================================================
1329 * \brief Return geometry of the vertical curve
1330 * \param isMax - true means curve located closer to (1,1,1) block point
1331 * \retval Adaptor3d_Curve* - curve adaptor
1333 //================================================================================
1335 Adaptor3d_Curve* StdMeshers_PrismAsBlock::TSideFace::VertiCurve(const bool isMax) const
1337 if ( !myComponents.empty() ) {
1339 return myComponents.back()->VertiCurve(isMax);
1341 return myComponents.front()->VertiCurve(isMax);
1343 double f = myParams[0].first, l = myParams[0].second;
1344 if ( !myIsForward ) std::swap( f, l );
1345 return new TVerticalEdgeAdaptor( myParamToColumnMap, isMax ? l : f );
1348 //================================================================================
1350 * \brief Return geometry of the top or bottom curve
1352 * \retval Adaptor3d_Curve* -
1354 //================================================================================
1356 Adaptor3d_Curve* StdMeshers_PrismAsBlock::TSideFace::HorizCurve(const bool isTop) const
1358 return new THorizontalEdgeAdaptor( this, isTop );
1361 //================================================================================
1363 * \brief Return pcurves
1364 * \param pcurv - array of 4 pcurves
1365 * \retval bool - is a success
1367 //================================================================================
1369 bool StdMeshers_PrismAsBlock::TSideFace::GetPCurves(Adaptor2d_Curve2d* pcurv[4]) const
1371 int iEdge[ 4 ] = { BOTTOM_EDGE, TOP_EDGE, V0_EDGE, V1_EDGE };
1373 for ( int i = 0 ; i < 4 ; ++i ) {
1374 Handle(Geom2d_Line) line;
1375 switch ( iEdge[ i ] ) {
1377 line = new Geom2d_Line( gp_Pnt2d( 0, 1 ), gp::DX2d() ); break;
1379 line = new Geom2d_Line( gp::Origin2d(), gp::DX2d() ); break;
1381 line = new Geom2d_Line( gp::Origin2d(), gp::DY2d() ); break;
1383 line = new Geom2d_Line( gp_Pnt2d( 1, 0 ), gp::DY2d() ); break;
1385 pcurv[ i ] = new Geom2dAdaptor_Curve( line, 0, 1 );
1390 //================================================================================
1392 * \brief Returns geometry of pcurve on a horizontal face
1393 * \param isTop - is top or bottom face
1394 * \param horFace - a horizontal face
1395 * \retval Adaptor2d_Curve2d* - curve adaptor
1397 //================================================================================
1400 StdMeshers_PrismAsBlock::TSideFace::HorizPCurve(const bool isTop,
1401 const TopoDS_Face& horFace) const
1403 return new TPCurveOnHorFaceAdaptor( this, isTop, horFace );
1406 //================================================================================
1408 * \brief Return a component corresponding to parameter
1409 * \param U - parameter along a horizontal size
1410 * \param localU - parameter along a horizontal size of a component
1411 * \retval TSideFace* - found component
1413 //================================================================================
1415 StdMeshers_PrismAsBlock::TSideFace*
1416 StdMeshers_PrismAsBlock::TSideFace::GetComponent(const double U,double & localU) const
1419 if ( myComponents.empty() )
1420 return const_cast<TSideFace*>( this );
1423 for ( i = 0; i < myComponents.size(); ++i )
1424 if ( U < myParams[ i ].second )
1426 if ( i >= myComponents.size() )
1427 i = myComponents.size() - 1;
1429 double f = myParams[ i ].first, l = myParams[ i ].second;
1430 localU = ( U - f ) / ( l - f );
1431 return myComponents[ i ];
1434 //================================================================================
1436 * \brief Find node columns for a parameter
1437 * \param U - parameter along a horizontal edge
1438 * \param col1 - the 1st found column
1439 * \param col2 - the 2nd found column
1440 * \retval r - normalized position of U between the found columns
1442 //================================================================================
1444 double StdMeshers_PrismAsBlock::TSideFace::GetColumns(const double U,
1445 TParam2ColumnIt & col1,
1446 TParam2ColumnIt & col2) const
1448 double u = U, r = 0;
1449 if ( !myComponents.empty() ) {
1450 TSideFace * comp = GetComponent(U,u);
1451 return comp->GetColumns( u, col1, col2 );
1456 double f = myParams[0].first, l = myParams[0].second;
1457 u = f + u * ( l - f );
1459 col1 = col2 = getColumn( myParamToColumnMap, u );
1460 if ( ++col2 == myParamToColumnMap->end() ) {
1465 // if ( !myIsForward )
1466 // std::swap( col1, col2 );
1467 double uf = col1->first;
1468 double ul = col2->first;
1469 r = ( u - uf ) / ( ul - uf );
1474 //================================================================================
1476 * \brief Return coordinates by normalized params
1477 * \param U - horizontal param
1478 * \param V - vertical param
1479 * \retval gp_Pnt - result point
1481 //================================================================================
1483 gp_Pnt StdMeshers_PrismAsBlock::TSideFace::Value(const Standard_Real U,
1484 const Standard_Real V) const
1487 if ( !myComponents.empty() ) {
1488 TSideFace * comp = GetComponent(U,u);
1489 return comp->Value( u, V );
1492 TParam2ColumnIt u_col1, u_col2;
1493 double vR, hR = GetColumns( U, u_col1, u_col2 );
1495 const SMDS_MeshNode* n1 = 0;
1496 const SMDS_MeshNode* n2 = 0;
1497 const SMDS_MeshNode* n3 = 0;
1498 const SMDS_MeshNode* n4 = 0;
1501 vR = getRAndNodes( & u_col1->second, V, n1, n2 );
1502 vR = getRAndNodes( & u_col2->second, V, n3, n4 );
1504 gp_XY uv1 = myHelper->GetNodeUV( mySurface.Face(), n1, n4);
1505 gp_XY uv2 = myHelper->GetNodeUV( mySurface.Face(), n2, n3);
1506 gp_XY uv12 = uv1 * ( 1 - vR ) + uv2 * vR;
1508 gp_XY uv3 = myHelper->GetNodeUV( mySurface.Face(), n3, n2);
1509 gp_XY uv4 = myHelper->GetNodeUV( mySurface.Face(), n4, n1);
1510 gp_XY uv34 = uv3 * ( 1 - vR ) + uv4 * vR;
1512 gp_XY uv = uv12 * ( 1 - hR ) + uv34 * hR;
1514 return mySurface.Value( uv.X(), uv.Y() );
1518 //================================================================================
1520 * \brief Return boundary edge
1521 * \param edge - edge index
1522 * \retval TopoDS_Edge - found edge
1524 //================================================================================
1526 TopoDS_Edge StdMeshers_PrismAsBlock::TSideFace::GetEdge(const int iEdge) const
1528 if ( !myComponents.empty() ) {
1530 case V0_EDGE : return myComponents.front()->GetEdge( iEdge );
1531 case V1_EDGE : return myComponents.back() ->GetEdge( iEdge );
1532 default: return TopoDS_Edge();
1536 const SMDS_MeshNode* node = 0;
1537 SMESHDS_Mesh * meshDS = myHelper->GetMesh()->GetMeshDS();
1538 TNodeColumn* column;
1543 column = & (( ++myParamToColumnMap->begin())->second );
1544 node = ( iEdge == TOP_EDGE ) ? column->back() : column->front();
1545 edge = myHelper->GetSubShapeByNode ( node, meshDS );
1546 if ( edge.ShapeType() == TopAbs_VERTEX ) {
1547 column = & ( myParamToColumnMap->begin()->second );
1548 node = ( iEdge == TOP_EDGE ) ? column->back() : column->front();
1553 bool back = ( iEdge == V1_EDGE );
1554 if ( !myIsForward ) back = !back;
1556 column = & ( myParamToColumnMap->rbegin()->second );
1558 column = & ( myParamToColumnMap->begin()->second );
1559 if ( column->size() > 0 )
1560 edge = myHelper->GetSubShapeByNode( (*column)[ 1 ], meshDS );
1561 if ( edge.IsNull() || edge.ShapeType() == TopAbs_VERTEX )
1562 node = column->front();
1567 if ( !edge.IsNull() || edge.ShapeType() == TopAbs_EDGE )
1568 return TopoDS::Edge( edge );
1570 // find edge by 2 vertices
1571 TopoDS_Shape V1 = edge;
1572 TopoDS_Shape V2 = myHelper->GetSubShapeByNode( node, meshDS );
1573 if ( V2.ShapeType() == TopAbs_VERTEX && !V2.IsSame( V1 ))
1575 TopTools_ListIteratorOfListOfShape ancestIt =
1576 myHelper->GetMesh()->GetAncestors( V1 );
1577 for ( ; ancestIt.More(); ancestIt.Next() )
1579 const TopoDS_Shape & ancestor = ancestIt.Value();
1580 if ( ancestor.ShapeType() == TopAbs_EDGE )
1581 for ( TopExp_Explorer e( ancestor, TopAbs_VERTEX ); e.More(); e.Next() )
1582 if ( V2.IsSame( e.Current() ))
1583 return TopoDS::Edge( ancestor );
1586 return TopoDS_Edge();
1589 //================================================================================
1591 * \brief Fill block subshapes
1592 * \param shapeMap - map to fill in
1593 * \retval int - nb inserted subshapes
1595 //================================================================================
1597 int StdMeshers_PrismAsBlock::TSideFace::InsertSubShapes(TBlockShapes& shapeMap) const
1602 vector< int > edgeIdVec;
1603 SMESH_Block::GetFaceEdgesIDs( myID, edgeIdVec );
1605 for ( int i = BOTTOM_EDGE; i <=V1_EDGE ; ++i ) {
1606 TopoDS_Edge e = GetEdge( i );
1607 if ( !e.IsNull() ) {
1608 nbInserted += SMESH_Block::Insert( e, edgeIdVec[ i ], shapeMap);
1612 // Insert corner vertices
1614 TParam2ColumnIt col1, col2 ;
1615 vector< int > vertIdVec;
1618 SMESH_Block::GetEdgeVertexIDs( edgeIdVec[ V0_EDGE ], vertIdVec);
1619 GetColumns(0, col1, col2 );
1620 const SMDS_MeshNode* node0 = col1->second.front();
1621 const SMDS_MeshNode* node1 = col1->second.back();
1622 TopoDS_Shape v0 = myHelper->GetSubShapeByNode( node0, myHelper->GetMeshDS());
1623 TopoDS_Shape v1 = myHelper->GetSubShapeByNode( node1, myHelper->GetMeshDS());
1624 if ( v0.ShapeType() == TopAbs_VERTEX ) {
1625 nbInserted += SMESH_Block::Insert( v0, vertIdVec[ 0 ], shapeMap);
1627 if ( v1.ShapeType() == TopAbs_VERTEX ) {
1628 nbInserted += SMESH_Block::Insert( v1, vertIdVec[ 1 ], shapeMap);
1632 SMESH_Block::GetEdgeVertexIDs( edgeIdVec[ V1_EDGE ], vertIdVec);
1633 GetColumns(1, col1, col2 );
1634 node0 = col2->second.front();
1635 node1 = col2->second.back();
1636 v0 = myHelper->GetSubShapeByNode( node0, myHelper->GetMeshDS());
1637 v1 = myHelper->GetSubShapeByNode( node1, myHelper->GetMeshDS());
1638 if ( v0.ShapeType() == TopAbs_VERTEX ) {
1639 nbInserted += SMESH_Block::Insert( v0, vertIdVec[ 0 ], shapeMap);
1641 if ( v1.ShapeType() == TopAbs_VERTEX ) {
1642 nbInserted += SMESH_Block::Insert( v1, vertIdVec[ 1 ], shapeMap);
1645 // TopoDS_Vertex V0, V1, Vcom;
1646 // TopExp::Vertices( myBaseEdge, V0, V1, true );
1647 // if ( !myIsForward ) std::swap( V0, V1 );
1649 // // bottom vertex IDs
1650 // SMESH_Block::GetEdgeVertexIDs( edgeIdVec[ _u0 ], vertIdVec);
1651 // SMESH_Block::Insert( V0, vertIdVec[ 0 ], shapeMap);
1652 // SMESH_Block::Insert( V1, vertIdVec[ 1 ], shapeMap);
1654 // TopoDS_Edge sideEdge = GetEdge( V0_EDGE );
1655 // if ( sideEdge.IsNull() || !TopExp::CommonVertex( botEdge, sideEdge, Vcom ))
1658 // // insert one side edge
1660 // if ( Vcom.IsSame( V0 )) edgeID = edgeIdVec[ _v0 ];
1661 // else edgeID = edgeIdVec[ _v1 ];
1662 // SMESH_Block::Insert( sideEdge, edgeID, shapeMap);
1664 // // top vertex of the side edge
1665 // SMESH_Block::GetEdgeVertexIDs( edgeID, vertIdVec);
1666 // TopoDS_Vertex Vtop = TopExp::FirstVertex( sideEdge );
1667 // if ( Vcom.IsSame( Vtop ))
1668 // Vtop = TopExp::LastVertex( sideEdge );
1669 // SMESH_Block::Insert( Vtop, vertIdVec[ 1 ], shapeMap);
1671 // // other side edge
1672 // sideEdge = GetEdge( V1_EDGE );
1673 // if ( sideEdge.IsNull() )
1675 // if ( edgeID = edgeIdVec[ _v1 ]) edgeID = edgeIdVec[ _v0 ];
1676 // else edgeID = edgeIdVec[ _v1 ];
1677 // SMESH_Block::Insert( sideEdge, edgeID, shapeMap);
1680 // TopoDS_Edge topEdge = GetEdge( TOP_EDGE );
1681 // SMESH_Block::Insert( topEdge, edgeIdVec[ _u1 ], shapeMap);
1683 // // top vertex of the other side edge
1684 // if ( !TopExp::CommonVertex( topEdge, sideEdge, Vcom ))
1686 // SMESH_Block::GetEdgeVertexIDs( edgeID, vertIdVec );
1687 // SMESH_Block::Insert( Vcom, vertIdVec[ 1 ], shapeMap);
1692 //================================================================================
1694 * \brief Creates TVerticalEdgeAdaptor
1695 * \param columnsMap - node column map
1696 * \param parameter - normalized parameter
1698 //================================================================================
1700 StdMeshers_PrismAsBlock::TVerticalEdgeAdaptor::
1701 TVerticalEdgeAdaptor( const TParam2ColumnMap* columnsMap, const double parameter)
1703 myNodeColumn = & getColumn( columnsMap, parameter )->second;
1706 //================================================================================
1708 * \brief Return coordinates for the given normalized parameter
1709 * \param U - normalized parameter
1710 * \retval gp_Pnt - coordinates
1712 //================================================================================
1714 gp_Pnt StdMeshers_PrismAsBlock::TVerticalEdgeAdaptor::Value(const Standard_Real U) const
1716 const SMDS_MeshNode* n1;
1717 const SMDS_MeshNode* n2;
1718 double r = getRAndNodes( myNodeColumn, U, n1, n2 );
1719 return gpXYZ(n1) * ( 1 - r ) + gpXYZ(n2) * r;
1722 //================================================================================
1724 * \brief Return coordinates for the given normalized parameter
1725 * \param U - normalized parameter
1726 * \retval gp_Pnt - coordinates
1728 //================================================================================
1730 gp_Pnt StdMeshers_PrismAsBlock::THorizontalEdgeAdaptor::Value(const Standard_Real U) const
1732 return mySide->TSideFace::Value( U, myV );
1735 //================================================================================
1737 * \brief Return UV on pcurve for the given normalized parameter
1738 * \param U - normalized parameter
1739 * \retval gp_Pnt - coordinates
1741 //================================================================================
1743 gp_Pnt2d StdMeshers_PrismAsBlock::TPCurveOnHorFaceAdaptor::Value(const Standard_Real U) const
1745 TParam2ColumnIt u_col1, u_col2;
1746 double r = mySide->GetColumns( U, u_col1, u_col2 );
1747 gp_XY uv1 = mySide->GetNodeUV( myFace, u_col1->second[ myZ ]);
1748 gp_XY uv2 = mySide->GetNodeUV( myFace, u_col2->second[ myZ ]);
1749 return uv1 * ( 1 - r ) + uv2 * r;