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)
185 // Check shape geometry
187 aStatus = SMESH_Hypothesis::HYP_BAD_GEOMETRY;
189 // find not quadrangle faces
190 list< TopoDS_Shape > notQuadFaces;
191 int nbEdge, nbWire, nbFace = 0;
192 TopExp_Explorer exp( aShape, TopAbs_FACE );
193 for ( ; exp.More(); exp.Next() ) {
195 const TopoDS_Shape& face = exp.Current();
196 nbEdge = TAssocTool::Count( face, TopAbs_EDGE, 0 );
197 nbWire = TAssocTool::Count( face, TopAbs_WIRE, 0 );
198 if ( nbEdge!= 4 || nbWire!= 1 ) {
199 if ( !notQuadFaces.empty() ) {
200 if ( TAssocTool::Count( notQuadFaces.back(), TopAbs_EDGE, 0 ) != nbEdge ||
201 TAssocTool::Count( notQuadFaces.back(), TopAbs_WIRE, 0 ) != nbWire )
202 RETURN_BAD_RESULT("Different not quad faces");
204 notQuadFaces.push_back( face );
207 if ( !notQuadFaces.empty() )
209 if ( notQuadFaces.size() != 2 )
210 RETURN_BAD_RESULT("Bad nb not quad faces: " << notQuadFaces.size());
212 // check total nb faces
213 nbEdge = TAssocTool::Count( notQuadFaces.back(), TopAbs_EDGE, 0 );
214 if ( nbFace != nbEdge + 2 )
215 RETURN_BAD_RESULT("Bad nb of faces: " << nbFace << " but must be " << nbEdge + 2);
219 aStatus = SMESH_Hypothesis::HYP_OK;
223 //=======================================================================
226 //=======================================================================
228 bool StdMeshers_Prism_3D::Compute(SMESH_Mesh& theMesh, const TopoDS_Shape& theShape)
230 myHelper = new SMESH_MesherHelper( theMesh );
231 // to delete helper at exit from Compute()
232 std::auto_ptr<SMESH_MesherHelper> helperDeleter( myHelper );
234 myHelper->IsQuadraticSubMesh( theShape );
236 // Analyse mesh and geomerty to find block subshapes and submeshes
237 if ( !myBlock.Init( myHelper, theShape ))
240 SMESHDS_Mesh* meshDS = theMesh.GetMeshDS();
242 int volumeID = meshDS->ShapeToIndex( theShape );
245 // To compute coordinates of a node inside a block, it is necessary to know
246 // 1. normalized parameters of the node by which
247 // 2. coordinates of node projections on all block sub-shapes are computed
249 // So we fill projections on vertices at once as they are same for all nodes
250 myShapeXYZ.resize( myBlock.NbSubShapes() );
251 for ( int iV = SMESH_Block::ID_FirstV; iV < SMESH_Block::ID_FirstE; ++iV ) {
252 myBlock.VertexPoint( iV, myShapeXYZ[ iV ]);
253 SHOWYXZ("V point " <<iV << " ", myShapeXYZ[ iV ]);
256 // Projections on the top and bottom faces are taken from nodes existing
257 // on these faces; find correspondence between bottom and top nodes
258 myBotToColumnMap.clear();
259 if ( !assocOrProjBottom2Top() ) // it also fill myBotToColumnMap
263 // Create nodes inside the block
265 // loop on nodes inside the bottom face
266 TNode2ColumnMap::iterator bot_column = myBotToColumnMap.begin();
267 for ( ; bot_column != myBotToColumnMap.end(); ++bot_column )
269 const TNode& tBotNode = bot_column->first; // bottom TNode
270 if ( tBotNode.GetPositionType() != SMDS_TOP_FACE )
271 continue; // node is not inside face
273 // column nodes; middle part of the column are zero pointers
274 TNodeColumn& column = bot_column->second;
276 // bottom node parameters and coords
277 gp_XYZ botParams = tBotNode.GetParams();
278 myShapeXYZ[ ID_BOT_FACE ] = tBotNode.GetCoords();
280 // compute top node parameters
282 myShapeXYZ[ ID_TOP_FACE ] = gpXYZ( column.back() );
283 gp_Pnt topCoords = myShapeXYZ[ ID_TOP_FACE ];
284 if ( !myBlock.ComputeParameters( topCoords, topParams, ID_TOP_FACE ))
285 RETURN_BAD_RESULT("ComputeParameters() on the top face failed");
288 TNodeColumn::iterator columnNodes = column.begin();
289 for ( int z = 0; columnNodes != column.end(); ++columnNodes, ++z)
291 const SMDS_MeshNode* & node = *columnNodes;
292 if ( node ) continue; // skip bottom or top node
294 // params of a node to create
295 double rz = (double) z / (double) ( column.size() - 1 );
296 gp_XYZ params = botParams * ( 1 - rz ) + topParams * rz;
298 // set coords on all faces and nodes
299 const int nbSideFaces = 4;
300 int sideFaceIDs[nbSideFaces] = { SMESH_Block::ID_Fx0z,
301 SMESH_Block::ID_Fx1z,
302 SMESH_Block::ID_F0yz,
303 SMESH_Block::ID_F1yz };
304 for ( int iF = 0; iF < nbSideFaces; ++iF )
305 if ( !setFaceAndEdgesXYZ( sideFaceIDs[ iF ], params, z ))
308 // compute coords for a new node
310 if ( !SMESH_Block::ShellPoint( params, myShapeXYZ, coords ))
311 RETURN_BAD_RESULT("SMESH_Block::ShellPoint() failed");
314 node = meshDS->AddNode( coords.X(), coords.Y(), coords.Z() );
315 meshDS->SetNodeInVolume( node, volumeID );
317 } // loop on bottom nodes
322 SMESHDS_SubMesh* smDS = myBlock.SubMeshDS( ID_BOT_FACE );
323 if ( !smDS ) RETURN_BAD_RESULT("Null submesh");
325 // loop on bottom mesh faces
326 SMDS_ElemIteratorPtr faceIt = smDS->GetElements();
327 while ( faceIt->more() )
329 const SMDS_MeshElement* face = faceIt->next();
330 if ( !face || face->GetType() != SMDSAbs_Face )
332 int nbNodes = face->NbNodes();
333 if ( face->IsQuadratic() )
336 // find node columns for each node
337 vector< const TNodeColumn* > columns( nbNodes );
338 for ( int i = 0; i < nbNodes; ++i )
340 const SMDS_MeshNode* n = face->GetNode( i );
341 if ( n->GetPosition()->GetTypeOfPosition() == SMDS_TOP_FACE ) {
342 bot_column = myBotToColumnMap.find( n );
343 if ( bot_column == myBotToColumnMap.end() )
344 RETURN_BAD_RESULT(" node column for a node not found");
345 columns[ i ] = & bot_column->second;
348 columns[ i ] = myBlock.GetNodeColumn( n );
350 RETURN_BAD_RESULT(" node column not found for a node " << n->GetID() );
354 AddPrisms( columns, myHelper );
356 } // loop on bottom mesh faces
361 //================================================================================
363 * \brief Create prisms
364 * \param columns - columns of nodes generated from nodes of a mesh face
365 * \param helper - helper initialized by mesh and shape to add prisms to
367 //================================================================================
369 void StdMeshers_Prism_3D::AddPrisms( vector<const TNodeColumn*> & columns,
370 SMESH_MesherHelper* helper)
372 SMESHDS_Mesh * meshDS = helper->GetMeshDS();
373 int shapeID = helper->GetSubShapeID();
375 int nbNodes = columns.size();
377 // vertical loop on columns
378 for ( int z = 1; z < columns[0]->size(); ++z)
380 SMDS_MeshElement* vol = 0;
381 SMDS_VolumeTool vTool;
385 const SMDS_MeshNode* botNodes[3] = { (*columns[0])[z-1],
387 (*columns[2])[z-1] };
388 const SMDS_MeshNode* topNodes[3] = { (*columns[0])[z],
391 // assure good orientation
392 SMDS_VolumeOfNodes tmpVol ( botNodes[0], botNodes[1], botNodes[2],
393 topNodes[0], topNodes[1], topNodes[2]);
394 vTool.Set( &tmpVol );
395 if ( vTool.IsForward() )
396 vol = helper->AddVolume( botNodes[0], botNodes[1], botNodes[2],
397 topNodes[0], topNodes[1], topNodes[2]);
399 vol = helper->AddVolume( topNodes[0], topNodes[1], topNodes[2],
400 botNodes[0], botNodes[1], botNodes[2]);
404 const SMDS_MeshNode* botNodes[4] = { (*columns[0])[z-1], (*columns[1])[z-1],
405 (*columns[2])[z-1], (*columns[3])[z-1] };
406 const SMDS_MeshNode* topNodes[4] = { (*columns[0])[z], (*columns[1])[z],
407 (*columns[2])[z], (*columns[3])[z] };
408 // assure good orientation
409 SMDS_VolumeOfNodes tmpVol ( botNodes[0], botNodes[1], botNodes[2], botNodes[3],
410 topNodes[0], topNodes[1], topNodes[2], topNodes[3]);
411 vTool.Set( &tmpVol );
412 if ( vTool.IsForward() )
413 vol = helper->AddVolume( botNodes[0], botNodes[1], botNodes[2], botNodes[3],
414 topNodes[0], topNodes[1], topNodes[2], topNodes[3]);
416 vol = helper->AddVolume( topNodes[0], topNodes[1], topNodes[2], topNodes[3],
417 botNodes[0], botNodes[1], botNodes[2], botNodes[3]);
422 vector<const SMDS_MeshNode*> nodes( 2*nbNodes + 4*nbNodes);
423 vector<int> quantities( 2 + nbNodes, 4 );
424 quantities[0] = quantities[1] = nbNodes;
425 columns.resize( nbNodes + 1 );
426 columns[ nbNodes ] = columns[ 0 ];
427 for ( int i = 0; i < nbNodes; ++i ) {
428 nodes[ i ] = (*columns[ i ])[z-1]; // bottom
429 nodes[ i+nbNodes ] = (*columns[ i ])[z ]; // top
431 int di = 2*nbNodes + 4*i - 1;
432 nodes[ di ] = (*columns[i ])[z-1];
433 nodes[ di+1 ] = (*columns[i+1])[z-1];
434 nodes[ di+2 ] = (*columns[i+1])[z ];
435 nodes[ di+3 ] = (*columns[i ])[z ];
437 vol = meshDS->AddPolyhedralVolume( nodes, quantities );
439 if ( vol && shapeID > 0 )
440 meshDS->SetMeshElementOnShape( vol, shapeID );
444 //================================================================================
446 * \brief Find correspondence between bottom and top nodes
447 * If elements on the bottom and top faces are topologically different,
448 * and projection is possible and allowed, perform the projection
449 * \retval bool - is a success or not
451 //================================================================================
453 bool StdMeshers_Prism_3D::assocOrProjBottom2Top()
455 SMESH_subMesh * botSM = myBlock.SubMesh( ID_BOT_FACE );
456 SMESH_subMesh * topSM = myBlock.SubMesh( ID_TOP_FACE );
458 SMESHDS_SubMesh * botSMDS = botSM->GetSubMeshDS();
459 SMESHDS_SubMesh * topSMDS = topSM->GetSubMeshDS();
461 if ( !botSMDS || botSMDS->NbElements() == 0 )
462 RETURN_BAD_RESULT("Empty horiz submesh");
464 bool needProject = false;
466 botSMDS->NbElements() != topSMDS->NbElements() ||
467 botSMDS->NbNodes() != topSMDS->NbNodes())
469 if ( myBlock.HasNotQuadElemOnTop() )
470 RETURN_BAD_RESULT("Different triangles on 2 sides");
474 if ( 0/*needProject && !myProjectTriangles*/ )
475 RETURN_BAD_RESULT("Need to project but not allowed");
479 return projectBottomToTop();
482 TopoDS_Face botFace = TopoDS::Face( myBlock.Shape( ID_BOT_FACE ));
483 TopoDS_Face topFace = TopoDS::Face( myBlock.Shape( ID_TOP_FACE ));
484 // associate top and bottom faces
485 TAssocTool::TShapeShapeMap shape2ShapeMap;
486 if ( !TAssocTool::FindSubShapeAssociation( botFace, myBlock.Mesh(),
487 topFace, myBlock.Mesh(),
489 RETURN_BAD_RESULT("FindSubShapeAssociation failed");
491 // Find matching nodes of in and out faces
493 if ( ! TAssocTool::FindMatchingNodesOnFaces( botFace, myBlock.Mesh(),
494 topFace, myBlock.Mesh(),
495 shape2ShapeMap, n2nMap ))
496 RETURN_BAD_RESULT("Different mesh on top and bottom faces");
498 // Fill myBotToColumnMap
500 int zSize = myBlock.VerticalSize();
501 TNodeNodeMap::iterator bN_tN = n2nMap.begin();
502 for ( ; bN_tN != n2nMap.end(); ++bN_tN )
504 const SMDS_MeshNode* botNode = bN_tN->first;
505 const SMDS_MeshNode* topNode = bN_tN->second;
506 if ( botNode->GetPosition()->GetTypeOfPosition() != SMDS_TOP_FACE )
507 continue; // wall columns are contained in myBlock
508 // compute bottom node params
510 if ( !myBlock.ComputeParameters( bN.GetCoords(), bN.ChangeParams(), ID_BOT_FACE ))
511 RETURN_BAD_RESULT("ComputeParameters() on the bottom face failed");
512 // create node column
513 TNode2ColumnMap::iterator bN_col =
514 myBotToColumnMap.insert( make_pair ( bN, TNodeColumn() )).first;
515 TNodeColumn & column = bN_col->second;
516 column.resize( zSize );
517 column.front() = botNode;
518 column.back() = topNode;
523 //================================================================================
525 * \brief Remove quadrangles from the top face and
526 * create triangles there by projection from the bottom
527 * \retval bool - a success or not
529 //================================================================================
531 bool StdMeshers_Prism_3D::projectBottomToTop()
533 SMESH_subMesh * botSM = myBlock.SubMesh( ID_BOT_FACE );
534 SMESH_subMesh * topSM = myBlock.SubMesh( ID_TOP_FACE );
536 SMESHDS_SubMesh * botSMDS = botSM->GetSubMeshDS();
537 SMESHDS_SubMesh * topSMDS = topSM->GetSubMeshDS();
540 topSM->ComputeStateEngine( SMESH_subMesh::CLEAN );
542 SMESHDS_Mesh* meshDS = myBlock.MeshDS();
543 int shapeID = myHelper->GetSubShapeID();
544 int topFaceID = meshDS->ShapeToIndex( topSM->GetSubShape() );
546 // Fill myBotToColumnMap
548 int zSize = myBlock.VerticalSize();
549 SMDS_NodeIteratorPtr nIt = botSMDS->GetNodes();
550 while ( nIt->more() )
552 const SMDS_MeshNode* botNode = nIt->next();
553 if ( botNode->GetPosition()->GetTypeOfPosition() != SMDS_TOP_FACE )
555 // compute bottom node params
557 if ( !myBlock.ComputeParameters( bN.GetCoords(), bN.ChangeParams(), ID_BOT_FACE ))
558 RETURN_BAD_RESULT("ComputeParameters() on the bottom face failed");
559 // compute top node coords
560 gp_XYZ topXYZ; gp_XY topUV;
561 if ( !myBlock.FacePoint( ID_TOP_FACE, bN.GetParams(), topXYZ ) ||
562 !myBlock.FaceUV ( ID_TOP_FACE, bN.GetParams(), topUV ))
563 RETURN_BAD_RESULT("SMESH_Block::FacePoint() on the top face failed");
564 SMDS_MeshNode * topNode = meshDS->AddNode( topXYZ.X(),topXYZ.Y(),topXYZ.Z() );
565 meshDS->SetNodeOnFace( topNode, topFaceID, topUV.X(), topUV.Y() );
566 // create node column
567 TNode2ColumnMap::iterator bN_col =
568 myBotToColumnMap.insert( make_pair ( bN, TNodeColumn() )).first;
569 TNodeColumn & column = bN_col->second;
570 column.resize( zSize );
571 column.front() = botNode;
572 column.back() = topNode;
577 // loop on bottom mesh faces
578 SMDS_ElemIteratorPtr faceIt = botSMDS->GetElements();
579 while ( faceIt->more() )
581 const SMDS_MeshElement* face = faceIt->next();
582 if ( !face || face->GetType() != SMDSAbs_Face )
584 int nbNodes = face->NbNodes();
585 if ( face->IsQuadratic() )
588 // find top node in columns for each bottom node
589 vector< const SMDS_MeshNode* > nodes( nbNodes );
590 for ( int i = 0; i < nbNodes; ++i )
592 const SMDS_MeshNode* n = face->GetNode( nbNodes - i - 1 );
593 if ( n->GetPosition()->GetTypeOfPosition() == SMDS_TOP_FACE ) {
594 TNode2ColumnMap::iterator bot_column = myBotToColumnMap.find( n );
595 if ( bot_column == myBotToColumnMap.end() )
596 RETURN_BAD_RESULT(" node column for a node not found");
597 nodes[ i ] = bot_column->second.back();
600 const TNodeColumn* column = myBlock.GetNodeColumn( n );
602 RETURN_BAD_RESULT(" node column not found for a node " << n->GetID() );
603 nodes[ i ] = column->back();
606 // create a face, with reversed orientation
607 SMDS_MeshElement* newFace = 0;
611 newFace = myHelper->AddFace(nodes[0], nodes[1], nodes[2]);
615 newFace = myHelper->AddFace( nodes[0], nodes[1], nodes[2], nodes[3] );
619 newFace = meshDS->AddPolygonalFace( nodes );
621 if ( newFace && shapeID > 0 )
622 meshDS->SetMeshElementOnShape( newFace, shapeID );
628 //================================================================================
630 * \brief Set projection coordinates of a node to a face and it's subshapes
631 * \param faceID - the face given by in-block ID
632 * \param params - node normalized parameters
633 * \retval bool - is a success
635 //================================================================================
637 bool StdMeshers_Prism_3D::setFaceAndEdgesXYZ( const int faceID, const gp_XYZ& params, int z )
639 // find base and top edges of the face
640 enum { BASE = 0, TOP, LEFT, RIGHT };
641 vector< int > edgeVec; // 0-base, 1-top
642 SMESH_Block::GetFaceEdgesIDs( faceID, edgeVec );
644 myBlock.EdgePoint( edgeVec[ BASE ], params, myShapeXYZ[ edgeVec[ BASE ]]);
645 myBlock.EdgePoint( edgeVec[ TOP ], params, myShapeXYZ[ edgeVec[ TOP ]]);
647 SHOWYXZ("\nparams ", params);
648 SHOWYXZ("TOP is "<<edgeVec[ TOP], myShapeXYZ[ edgeVec[ TOP]]);
649 SHOWYXZ("BASE is "<<edgeVec[ BASE], myShapeXYZ[ edgeVec[ BASE]]);
651 if ( faceID == SMESH_Block::ID_Fx0z || faceID == SMESH_Block::ID_Fx1z )
653 myBlock.EdgePoint( edgeVec[ LEFT ], params, myShapeXYZ[ edgeVec[ LEFT ]]);
654 myBlock.EdgePoint( edgeVec[ RIGHT ], params, myShapeXYZ[ edgeVec[ RIGHT ]]);
656 SHOWYXZ("VER "<<edgeVec[ LEFT], myShapeXYZ[ edgeVec[ LEFT]]);
657 SHOWYXZ("VER "<<edgeVec[ RIGHT], myShapeXYZ[ edgeVec[ RIGHT]]);
659 myBlock.FacePoint( faceID, params, myShapeXYZ[ faceID ]);
660 SHOWYXZ("FacePoint "<<faceID, myShapeXYZ[ faceID]);
665 //================================================================================
667 * \brief Constructor. Initialization is needed
669 //================================================================================
671 StdMeshers_PrismAsBlock::StdMeshers_PrismAsBlock()
676 StdMeshers_PrismAsBlock::~StdMeshers_PrismAsBlock()
679 delete mySide; mySide = 0;
683 //================================================================================
685 * \brief Initialization.
686 * \param helper - helper loaded with mesh and 3D shape
687 * \param shape3D - a closed shell or solid
688 * \retval bool - false if a mesh or a shape are KO
690 //================================================================================
692 bool StdMeshers_PrismAsBlock::Init(SMESH_MesherHelper* helper,
693 const TopoDS_Shape& shape3D)
696 delete mySide; mySide = 0;
698 vector< TSideFace* > sideFaces( NB_WALL_FACES, 0 );
699 vector< pair< double, double> > params ( NB_WALL_FACES );
700 mySide = new TSideFace( sideFaces, params );
703 SMESHDS_Mesh* meshDS = myHelper->GetMesh()->GetMeshDS();
706 myShapeIDMap.Clear();
707 myShapeIndex2ColumnMap.clear();
709 int wallFaceIds[ NB_WALL_FACES ] = { // to walk around a block
710 SMESH_Block::ID_Fx0z, SMESH_Block::ID_F1yz,
711 SMESH_Block::ID_Fx1z, SMESH_Block::ID_F0yz
714 // -------------------------------------------------------------
715 // Look for top and bottom faces: not quadrangle ones or meshed
716 // with not quadrangle elements
717 // -------------------------------------------------------------
719 list< SMESH_subMesh* > notQuadGeomSubMesh;
720 list< SMESH_subMesh* > notQuadElemSubMesh;
723 SMESH_subMesh* mainSubMesh = myHelper->GetMesh()->GetSubMeshContaining( shape3D );
724 if ( !mainSubMesh ) RETURN_BAD_RESULT("Null submesh of shape3D");
726 const map< int, SMESH_subMesh * >& subSM = mainSubMesh->DependsOn();
727 map< int, SMESH_subMesh * >::const_iterator i_subSM = subSM.begin();
728 for ( ; i_subSM != subSM.end(); ++i_subSM )
730 SMESH_subMesh* sm = i_subSM->second;
731 const TopoDS_Shape& face = sm->GetSubShape();
732 if ( face.ShapeType() != TopAbs_FACE )
736 // is quadrangle face?
737 if ( TAssocTool::Count( face, TopAbs_EDGE, 0 ) != 4 ||
738 TAssocTool::Count( face, TopAbs_WIRE, 0 ) != 1 )
739 notQuadGeomSubMesh.push_back( sm );
741 // count not quadrangle mesh elements
742 if ( SMESHDS_SubMesh* smDS = sm->GetSubMeshDS() ) {
743 SMDS_ElemIteratorPtr eIt = smDS->GetElements();
744 bool hasNotQuad = false;
745 while ( eIt->more() && !hasNotQuad ) {
746 const SMDS_MeshElement* elem = eIt->next();
747 if ( elem->GetType() == SMDSAbs_Face ) {
748 int nbNodes = elem->NbNodes();
749 if ( elem->IsQuadratic() )
751 hasNotQuad = ( nbNodes != 4 );
755 notQuadElemSubMesh.push_back( sm );
758 RETURN_BAD_RESULT("not meshed face");
762 // ----------------------------------------------------------------------
763 // Analyse faces mesh and topology: choose the bottom submesh.
764 // If there are not quadrangle geom faces, they are top and bottom ones.
765 // Not quadrangle geom faces must be only on top and bottom.
766 // ----------------------------------------------------------------------
768 SMESH_subMesh * botSM = 0;
769 SMESH_subMesh * topSM = 0;
771 int nbNotQuad = notQuadGeomSubMesh.size();
772 int nbNotQuadMeshed = notQuadElemSubMesh.size();
773 bool hasNotQuad = ( nbNotQuad || nbNotQuadMeshed );
776 if ( nbNotQuad > 0 && nbNotQuad != 2 )
777 RETURN_BAD_RESULT("Wrong shape geometry");
778 if ( nbNotQuadMeshed > 2 )
779 RETURN_BAD_RESULT("More then 2 faces meshed with not quadrangle elements");
781 // get found submeshes
784 if ( nbNotQuadMeshed > 0 ) botSM = notQuadElemSubMesh.front();
785 else botSM = notQuadGeomSubMesh.front();
786 if ( nbNotQuadMeshed > 1 ) topSM = notQuadElemSubMesh.back();
787 else if ( nbNotQuad > 1 ) topSM = notQuadGeomSubMesh.back();
789 // detect other bad cases
790 if ( nbNotQuad == 2 && nbNotQuadMeshed > 0 ) {
792 if ( nbNotQuadMeshed == 1 )
793 ok = ( find( notQuadGeomSubMesh.begin(),
794 notQuadGeomSubMesh.end(), botSM ) != notQuadGeomSubMesh.end() );
796 ok = ( notQuadGeomSubMesh == notQuadElemSubMesh );
798 RETURN_BAD_RESULT("Side face meshed with not quadrangle elements");
801 myNotQuadOnTop = ( nbNotQuadMeshed > 1 );
803 // ----------------------------------------------------------
805 if ( nbNotQuad == 0 ) // Standard block of 6 quadrangle faces ?
807 // SMESH_Block will perform geometry analysis, we need just to find 2
808 // connected vertices on top and bottom
810 TopoDS_Vertex Vbot, Vtop;
811 if ( nbNotQuadMeshed > 0 ) // Look for vertices
813 TopTools_IndexedMapOfShape edgeMap;
814 TopExp::MapShapes( botSM->GetSubShape(), TopAbs_EDGE, edgeMap );
815 // vertex 1 is any vertex of the bottom face
816 Vbot = TopExp::FirstVertex( TopoDS::Edge( edgeMap( 1 )));
817 // vertex 2 is end vertex of edge sharing Vbot and not belonging to the bottom face
818 TopTools_ListIteratorOfListOfShape ancestIt = Mesh()->GetAncestors( Vbot );
819 for ( ; Vtop.IsNull() && ancestIt.More(); ancestIt.Next() )
821 const TopoDS_Shape & ancestor = ancestIt.Value();
822 if ( ancestor.ShapeType() == TopAbs_EDGE && !edgeMap.FindIndex( ancestor ))
824 Vtop = TopExp::LastVertex( TopoDS::Edge( ancestor ));
825 if ( Vbot.IsSame ( Vtop ))
826 Vtop = TopExp::FirstVertex( TopoDS::Edge( ancestor ));
830 // get shell from shape3D
832 TopExp_Explorer exp( shape3D, TopAbs_SHELL );
834 for ( ; exp.More(); exp.Next(), ++nbShell )
835 shell = TopoDS::Shell( exp.Current() );
836 // if ( nbShell != 1 )
837 // RETURN_BAD_RESULT("There must be 1 shell in the block");
839 // Load geometry in SMESH_Block
840 if ( !SMESH_Block::FindBlockShapes( shell, Vbot, Vtop, myShapeIDMap )) {
842 RETURN_BAD_RESULT("Can not detect top and bottom");
845 if ( !botSM ) botSM = Mesh()->GetSubMeshContaining( myShapeIDMap( ID_BOT_FACE ));
846 if ( !topSM ) topSM = Mesh()->GetSubMeshContaining( myShapeIDMap( ID_TOP_FACE ));
849 } // end Standard block of 6 quadrangle faces
850 // --------------------------------------------------------
852 // Here the top and bottom faces are found
853 if ( nbNotQuadMeshed == 2 ) // roughly check correspondence of horiz meshes
855 // SMESHDS_SubMesh* topSMDS = topSM->GetSubMeshDS();
856 // SMESHDS_SubMesh* botSMDS = botSM->GetSubMeshDS();
857 // if ( topSMDS->NbNodes() != botSMDS->NbNodes() ||
858 // topSMDS->NbElements() != botSMDS->NbElements() )
859 // RETURN_BAD_RESULT("Top mesh doesn't correspond to bottom one");
862 // ---------------------------------------------------------
863 // If there are not quadrangle geom faces, we emulate
864 // a block of 6 quadrangle faces.
865 // Load SMESH_Block with faces and edges geometry
866 // ---------------------------------------------------------
869 // find vertex 000 - the one with smallest coordinates (for easy DEBUG :-)
871 double minVal = DBL_MAX, minX, val;
872 for ( TopExp_Explorer exp( botSM->GetSubShape(), TopAbs_VERTEX );
873 exp.More(); exp.Next() )
875 const TopoDS_Vertex& v = TopoDS::Vertex( exp.Current() );
876 gp_Pnt P = BRep_Tool::Pnt( v );
877 val = P.X() + P.Y() + P.Z();
878 if ( val < minVal || ( val == minVal && P.X() < minX )) {
885 // Get ordered bottom edges
886 list< TopoDS_Edge > orderedEdges;
887 list< int > nbVertexInWires;
888 SMESH_Block::GetOrderedEdges( TopoDS::Face( botSM->GetSubShape().Reversed() ),
889 V000, orderedEdges, nbVertexInWires );
890 // if ( nbVertexInWires.size() != 1 )
891 // RETURN_BAD_RESULT("Wrong prism geometry");
893 // Get Wall faces corresponding to the ordered bottom edges
894 list< TopoDS_Face > wallFaces;
895 if ( !GetWallFaces( Mesh(), shape3D, botSM->GetSubShape(), orderedEdges, wallFaces))
896 RETURN_BAD_RESULT("GetWallFaces() failed");
898 // Find columns of wall nodes and calculate edges' lengths
899 // --------------------------------------------------------
901 myParam2ColumnMaps.clear();
902 myParam2ColumnMaps.resize( orderedEdges.size() ); // total nb edges
904 int iE, nbEdges = nbVertexInWires.front(); // nb outer edges
905 vector< double > edgeLength( nbEdges );
906 map< double, int > len2edgeMap;
908 list< TopoDS_Edge >::iterator edgeIt = orderedEdges.begin();
909 list< TopoDS_Face >::iterator faceIt = wallFaces.begin();
910 for ( iE = 0; iE < nbEdges; ++edgeIt, ++faceIt )
912 TParam2ColumnMap & faceColumns = myParam2ColumnMaps[ iE ];
913 if ( !myHelper->LoadNodeColumns( faceColumns, *faceIt, *edgeIt, meshDS ))
914 RETURN_BAD_RESULT("SMESH_MesherHelper::LoadNodeColumns() failed");
916 SHOWYXZ("\np1 F "<<iE, gpXYZ(faceColumns.begin()->second.front() ));
917 SHOWYXZ("p2 F "<<iE, gpXYZ(faceColumns.rbegin()->second.front() ));
918 SHOWYXZ("V First "<<iE, BRep_Tool::Pnt( TopExp::FirstVertex(*edgeIt,true )));
920 edgeLength[ iE ] = SMESH_Algo::EdgeLength( *edgeIt );
922 if ( nbEdges < NB_WALL_FACES ) // fill map used to split faces
924 SMESHDS_SubMesh* smDS = meshDS->MeshElements( *edgeIt);
926 RETURN_BAD_RESULT("Null submesh on a bottom edge");
927 // assure length uniqueness
928 edgeLength[ iE ] *= smDS->NbNodes() + edgeLength[ iE ] / ( 1000 + iE );
929 len2edgeMap[ edgeLength[ iE ]] = iE;
933 // Load columns of internal edges (forming holes)
934 // and fill map ShapeIndex to TParam2ColumnMap for them
935 for ( ; edgeIt != orderedEdges.end() ; ++edgeIt, ++faceIt )
937 TParam2ColumnMap & faceColumns = myParam2ColumnMaps[ iE ];
938 if ( !myHelper->LoadNodeColumns( faceColumns, *faceIt, *edgeIt, meshDS ))
939 RETURN_BAD_RESULT("SMESH_MesherHelper::LoadNodeColumns() failed");
941 int id = MeshDS()->ShapeToIndex( *edgeIt );
942 bool isForward = true; // meaningless for intenal wires
943 myShapeIndex2ColumnMap[ id ] = make_pair( & faceColumns, isForward );
944 // columns for vertices
946 const SMDS_MeshNode* n0 = faceColumns.begin()->second.front();
947 id = n0->GetPosition()->GetShapeId();
948 myShapeIndex2ColumnMap[ id ] = make_pair( & faceColumns, isForward );
950 const SMDS_MeshNode* n1 = faceColumns.rbegin()->second.front();
951 id = n1->GetPosition()->GetShapeId();
952 myShapeIndex2ColumnMap[ id ] = make_pair( & faceColumns, isForward );
953 // SHOWYXZ("\np1 F "<<iE, gpXYZ(faceColumns.begin()->second.front() ));
954 // SHOWYXZ("p2 F "<<iE, gpXYZ(faceColumns.rbegin()->second.front() ));
955 // SHOWYXZ("V First "<<iE, BRep_Tool::Pnt( TopExp::FirstVertex(*edgeIt,true )));
959 // Create 4 wall faces of a block
960 // -------------------------------
962 if ( nbEdges <= NB_WALL_FACES ) // ************* Split faces if necessary
964 map< int, int > iE2nbSplit;
965 if ( nbEdges != NB_WALL_FACES ) // define how to split
967 if ( len2edgeMap.size() != nbEdges )
968 RETURN_BAD_RESULT("Uniqueness of edge lengths not assured");
969 map< double, int >::reverse_iterator maxLen_i = len2edgeMap.rbegin();
970 map< double, int >::reverse_iterator midLen_i = ++len2edgeMap.rbegin();
971 double maxLen = maxLen_i->first;
972 double midLen = ( len2edgeMap.size() == 1 ) ? 0 : midLen_i->first;
974 case 1: // 0-th edge is split into 4 parts
975 iE2nbSplit.insert( make_pair( 0, 4 )); break;
976 case 2: // either the longest edge is split into 3 parts, or both edges into halves
977 if ( maxLen / 3 > midLen / 2 ) {
978 iE2nbSplit.insert( make_pair( maxLen_i->second, 3 ));
981 iE2nbSplit.insert( make_pair( maxLen_i->second, 2 ));
982 iE2nbSplit.insert( make_pair( midLen_i->second, 2 ));
986 // split longest into halves
987 iE2nbSplit.insert( make_pair( maxLen_i->second, 2 ));
990 // Create TSideFace's
991 faceIt = wallFaces.begin();
992 edgeIt = orderedEdges.begin();
994 for ( iE = 0; iE < nbEdges; ++edgeIt, ++faceIt )
997 map< int, int >::iterator i_nb = iE2nbSplit.find( iE );
998 if ( i_nb != iE2nbSplit.end() ) {
1000 int nbSplit = i_nb->second;
1001 vector< double > params;
1002 splitParams( nbSplit, &myParam2ColumnMaps[ iE ], params );
1003 bool isForward = ( edgeIt->Orientation() == TopAbs_FORWARD );
1004 for ( int i = 0; i < nbSplit; ++i ) {
1005 double f = ( isForward ? params[ i ] : params[ nbSplit - i-1 ]);
1006 double l = ( isForward ? params[ i+1 ] : params[ nbSplit - i ]);
1007 TSideFace* comp = new TSideFace( myHelper, wallFaceIds[ iSide ],
1009 &myParam2ColumnMaps[ iE ], f, l );
1010 mySide->SetComponent( iSide++, comp );
1014 TSideFace* comp = new TSideFace( myHelper, wallFaceIds[ iSide ],
1016 &myParam2ColumnMaps[ iE ]);
1017 mySide->SetComponent( iSide++, comp );
1022 else { // **************************** Unite faces
1024 // unite first faces
1025 int nbExraFaces = nbEdges - 3;
1027 double u0 = 0, sumLen = 0;
1028 for ( iE = 0; iE < nbExraFaces; ++iE )
1029 sumLen += edgeLength[ iE ];
1031 vector< TSideFace* > components( nbExraFaces );
1032 vector< pair< double, double> > params( nbExraFaces );
1033 faceIt = wallFaces.begin();
1034 edgeIt = orderedEdges.begin();
1035 for ( iE = 0; iE < nbExraFaces; ++edgeIt, ++faceIt )
1037 components[ iE ] = new TSideFace( myHelper, wallFaceIds[ iSide ],
1039 &myParam2ColumnMaps[ iE ]);
1040 double u1 = u0 + edgeLength[ iE ] / sumLen;
1041 params[ iE ] = make_pair( u0 , u1 );
1045 mySide->SetComponent( iSide++, new TSideFace( components, params ));
1047 // fill the rest faces
1048 for ( ; iE < nbEdges; ++faceIt, ++edgeIt )
1050 TSideFace* comp = new TSideFace( myHelper, wallFaceIds[ iSide ],
1052 &myParam2ColumnMaps[ iE ]);
1053 mySide->SetComponent( iSide++, comp );
1059 // Fill geometry fields of SMESH_Block
1060 // ------------------------------------
1062 TopoDS_Face botF = TopoDS::Face( botSM->GetSubShape() );
1063 TopoDS_Face topF = TopoDS::Face( topSM->GetSubShape() );
1065 vector< int > botEdgeIdVec;
1066 SMESH_Block::GetFaceEdgesIDs( ID_BOT_FACE, botEdgeIdVec );
1068 bool isForward[NB_WALL_FACES] = { true, true, true, true };
1069 Adaptor2d_Curve2d* botPcurves[NB_WALL_FACES];
1070 Adaptor2d_Curve2d* topPcurves[NB_WALL_FACES];
1072 for ( int iF = 0; iF < NB_WALL_FACES; ++iF )
1074 TSideFace * sideFace = mySide->GetComponent( iF );
1076 RETURN_BAD_RESULT("NULL TSideFace");
1077 int fID = sideFace->FaceID();
1079 // fill myShapeIDMap
1080 if ( sideFace->InsertSubShapes( myShapeIDMap ) != 8 &&
1081 !sideFace->IsComplex())
1082 MESSAGE( ": Warning : InsertSubShapes() < 8 on side " << iF );
1084 // side faces geometry
1085 Adaptor2d_Curve2d* pcurves[NB_WALL_FACES];
1086 if ( !sideFace->GetPCurves( pcurves ))
1087 RETURN_BAD_RESULT("TSideFace::GetPCurves() failed");
1089 SMESH_Block::TFace& tFace = myFace[ fID - ID_FirstF ];
1090 tFace.Set( fID, sideFace->Surface(), pcurves, isForward );
1092 SHOWYXZ( endl<<"F "<< iF << " id " << fID << " FRW " << sideFace->IsForward(), );
1093 // edges 3D geometry
1094 vector< int > edgeIdVec;
1095 SMESH_Block::GetFaceEdgesIDs( fID, edgeIdVec );
1096 for ( int isMax = 0; isMax < 2; ++isMax ) {
1098 int eID = edgeIdVec[ isMax ];
1099 SMESH_Block::TEdge& tEdge = myEdge[ eID - ID_FirstE ];
1100 tEdge.Set( eID, sideFace->HorizCurve(isMax), true);
1101 SHOWYXZ(eID<<" HOR"<<isMax<<"(0)", sideFace->HorizCurve(isMax)->Value(0));
1102 SHOWYXZ(eID<<" HOR"<<isMax<<"(1)", sideFace->HorizCurve(isMax)->Value(1));
1105 int eID = edgeIdVec[ isMax+2 ];
1106 SMESH_Block::TEdge& tEdge = myEdge[ eID - ID_FirstE ];
1107 tEdge.Set( eID, sideFace->VertiCurve(isMax), true);
1108 SHOWYXZ(eID<<" VER"<<isMax<<"(0)", sideFace->VertiCurve(isMax)->Value(0));
1109 SHOWYXZ(eID<<" VER"<<isMax<<"(1)", sideFace->VertiCurve(isMax)->Value(1));
1112 vector< int > vertexIdVec;
1113 SMESH_Block::GetEdgeVertexIDs( eID, vertexIdVec );
1114 myPnt[ vertexIdVec[0] - ID_FirstV ] = tEdge.GetCurve()->Value(0).XYZ();
1115 myPnt[ vertexIdVec[1] - ID_FirstV ] = tEdge.GetCurve()->Value(1).XYZ();
1118 // pcurves on horizontal faces
1119 for ( iE = 0; iE < NB_WALL_FACES; ++iE ) {
1120 if ( edgeIdVec[ BOTTOM_EDGE ] == botEdgeIdVec[ iE ] ) {
1121 botPcurves[ iE ] = sideFace->HorizPCurve( false, botF );
1122 topPcurves[ iE ] = sideFace->HorizPCurve( true, topF );
1127 // horizontal faces geometry
1129 SMESH_Block::TFace& tFace = myFace[ ID_BOT_FACE - ID_FirstF ];
1130 tFace.Set( ID_BOT_FACE, new BRepAdaptor_Surface( botF ), botPcurves, isForward );
1131 SMESH_Block::Insert( botF, ID_BOT_FACE, myShapeIDMap );
1134 SMESH_Block::TFace& tFace = myFace[ ID_TOP_FACE - ID_FirstF ];
1135 tFace.Set( ID_TOP_FACE, new BRepAdaptor_Surface( topF ), topPcurves, isForward );
1136 SMESH_Block::Insert( topF, ID_TOP_FACE, myShapeIDMap );
1139 // Fill map ShapeIndex to TParam2ColumnMap
1140 // ----------------------------------------
1142 list< TSideFace* > fList;
1143 list< TSideFace* >::iterator fListIt;
1144 fList.push_back( mySide );
1145 for ( fListIt = fList.begin(); fListIt != fList.end(); ++fListIt)
1147 int nb = (*fListIt)->NbComponents();
1148 for ( int i = 0; i < nb; ++i ) {
1149 if ( TSideFace* comp = (*fListIt)->GetComponent( i ))
1150 fList.push_back( comp );
1152 if ( TParam2ColumnMap* cols = (*fListIt)->GetColumns()) {
1153 // columns for a base edge
1154 int id = MeshDS()->ShapeToIndex( (*fListIt)->BaseEdge() );
1155 bool isForward = (*fListIt)->IsForward();
1156 myShapeIndex2ColumnMap[ id ] = make_pair( cols, isForward );
1158 // columns for vertices
1159 const SMDS_MeshNode* n0 = cols->begin()->second.front();
1160 id = n0->GetPosition()->GetShapeId();
1161 myShapeIndex2ColumnMap[ id ] = make_pair( cols, isForward );
1163 const SMDS_MeshNode* n1 = cols->rbegin()->second.front();
1164 id = n1->GetPosition()->GetShapeId();
1165 myShapeIndex2ColumnMap[ id ] = make_pair( cols, !isForward );
1169 // gp_XYZ testPar(0.25, 0.25, 0), testCoord;
1170 // if ( !FacePoint( ID_BOT_FACE, testPar, testCoord ))
1171 // RETURN_BAD_RESULT("TEST FacePoint() FAILED");
1172 // SHOWYXZ("IN TEST PARAM" , testPar);
1173 // SHOWYXZ("OUT TEST CORD" , testCoord);
1174 // if ( !ComputeParameters( testCoord, testPar , ID_BOT_FACE))
1175 // RETURN_BAD_RESULT("TEST ComputeParameters() FAILED");
1176 // SHOWYXZ("OUT TEST PARAM" , testPar);
1181 //================================================================================
1183 * \brief Return pointer to column of nodes
1184 * \param node - bottom node from which the returned column goes up
1185 * \retval const TNodeColumn* - the found column
1187 //================================================================================
1189 const TNodeColumn* StdMeshers_PrismAsBlock::GetNodeColumn(const SMDS_MeshNode* node) const
1191 int sID = node->GetPosition()->GetShapeId();
1193 map<int, pair< TParam2ColumnMap*, bool > >::const_iterator col_frw =
1194 myShapeIndex2ColumnMap.find( sID );
1195 if ( col_frw != myShapeIndex2ColumnMap.end() ) {
1196 const TParam2ColumnMap* cols = col_frw->second.first;
1197 TParam2ColumnIt u_col = cols->begin();
1198 for ( ; u_col != cols->end(); ++u_col )
1199 if ( u_col->second[ 0 ] == node )
1200 return & u_col->second;
1205 //================================================================================
1207 * \brief Check curve orientation of a bootom edge
1208 * \param meshDS - mesh DS
1209 * \param columnsMap - node columns map of side face
1210 * \param bottomEdge - the bootom edge
1211 * \param sideFaceID - side face in-block ID
1212 * \retval bool - true if orientation coinside with in-block froward orientation
1214 //================================================================================
1216 bool StdMeshers_PrismAsBlock::IsForwardEdge(SMESHDS_Mesh* meshDS,
1217 const TParam2ColumnMap& columnsMap,
1218 const TopoDS_Edge & bottomEdge,
1219 const int sideFaceID)
1221 bool isForward = false;
1222 if ( TAssocTool::IsClosedEdge( bottomEdge ))
1224 isForward = ( bottomEdge.Orientation() == TopAbs_FORWARD );
1228 const TNodeColumn& firstCol = columnsMap.begin()->second;
1229 const SMDS_MeshNode* bottomNode = firstCol[0];
1230 TopoDS_Shape firstVertex = SMESH_MesherHelper::GetSubShapeByNode( bottomNode, meshDS );
1231 isForward = ( firstVertex.IsSame( TopExp::FirstVertex( bottomEdge, true )));
1233 // on 2 of 4 sides first vertex is end
1234 if ( sideFaceID == ID_Fx1z || sideFaceID == ID_F0yz )
1235 isForward = !isForward;
1239 //================================================================================
1241 * \brief Find wall faces by bottom edges
1242 * \param mesh - the mesh
1243 * \param mainShape - the prism
1244 * \param bottomFace - the bottom face
1245 * \param bottomEdges - edges bounding the bottom face
1246 * \param wallFaces - faces list to fill in
1248 //================================================================================
1250 bool StdMeshers_PrismAsBlock::GetWallFaces( SMESH_Mesh* mesh,
1251 const TopoDS_Shape & mainShape,
1252 const TopoDS_Shape & bottomFace,
1253 const std::list< TopoDS_Edge >& bottomEdges,
1254 std::list< TopoDS_Face >& wallFaces)
1258 TopTools_IndexedMapOfShape faceMap;
1259 TopExp::MapShapes( mainShape, TopAbs_FACE, faceMap );
1261 list< TopoDS_Edge >::const_iterator edge = bottomEdges.begin();
1262 for ( ; edge != bottomEdges.end(); ++edge )
1264 TopTools_ListIteratorOfListOfShape ancestIt = mesh->GetAncestors( *edge );
1265 for ( ; ancestIt.More(); ancestIt.Next() )
1267 const TopoDS_Shape& ancestor = ancestIt.Value();
1268 if ( ancestor.ShapeType() == TopAbs_FACE && // face
1269 !bottomFace.IsSame( ancestor ) && // not bottom
1270 faceMap.FindIndex( ancestor )) // belongs to the prism
1272 wallFaces.push_back( TopoDS::Face( ancestor ));
1277 return ( wallFaces.size() == bottomEdges.size() );
1280 //================================================================================
1282 * \brief Constructor
1283 * \param faceID - in-block ID
1284 * \param face - geom face
1285 * \param columnsMap - map of node columns
1286 * \param first - first normalized param
1287 * \param last - last normalized param
1289 //================================================================================
1291 StdMeshers_PrismAsBlock::TSideFace::TSideFace(SMESH_MesherHelper* helper,
1293 const TopoDS_Face& face,
1294 const TopoDS_Edge& baseEdge,
1295 TParam2ColumnMap* columnsMap,
1299 myParamToColumnMap( columnsMap ),
1300 myBaseEdge( baseEdge ),
1303 mySurface.Initialize( face );
1304 myParams.resize( 1 );
1305 myParams[ 0 ] = make_pair( first, last );
1306 myIsForward = StdMeshers_PrismAsBlock::IsForwardEdge( myHelper->GetMeshDS(),
1307 *myParamToColumnMap,
1311 //================================================================================
1313 * \brief Constructor of complex side face
1315 //================================================================================
1317 StdMeshers_PrismAsBlock::TSideFace::
1318 TSideFace(const vector< TSideFace* >& components,
1319 const vector< pair< double, double> > & params)
1320 :myID( components[0] ? components[0]->myID : 0 ),
1321 myParamToColumnMap( 0 ),
1323 myIsForward( true ),
1324 myComponents( components ),
1325 myHelper( components[0] ? components[0]->myHelper : 0 )
1327 //================================================================================
1329 * \brief Copy constructor
1330 * \param other - other side
1332 //================================================================================
1334 StdMeshers_PrismAsBlock::TSideFace::TSideFace( const TSideFace& other )
1337 mySurface = other.mySurface;
1338 myBaseEdge = other.myBaseEdge;
1339 myParams = other.myParams;
1340 myIsForward = other.myIsForward;
1341 myHelper = other.myHelper;
1342 myParamToColumnMap = other.myParamToColumnMap;
1344 myComponents.resize( other.myComponents.size());
1345 for (int i = 0 ; i < myComponents.size(); ++i )
1346 myComponents[ i ] = new TSideFace( *other.myComponents[ i ]);
1349 //================================================================================
1351 * \brief Deletes myComponents
1353 //================================================================================
1355 StdMeshers_PrismAsBlock::TSideFace::~TSideFace()
1357 for (int i = 0 ; i < myComponents.size(); ++i )
1358 if ( myComponents[ i ] )
1359 delete myComponents[ i ];
1362 //================================================================================
1364 * \brief Return geometry of the vertical curve
1365 * \param isMax - true means curve located closer to (1,1,1) block point
1366 * \retval Adaptor3d_Curve* - curve adaptor
1368 //================================================================================
1370 Adaptor3d_Curve* StdMeshers_PrismAsBlock::TSideFace::VertiCurve(const bool isMax) const
1372 if ( !myComponents.empty() ) {
1374 return myComponents.back()->VertiCurve(isMax);
1376 return myComponents.front()->VertiCurve(isMax);
1378 double f = myParams[0].first, l = myParams[0].second;
1379 if ( !myIsForward ) std::swap( f, l );
1380 return new TVerticalEdgeAdaptor( myParamToColumnMap, isMax ? l : f );
1383 //================================================================================
1385 * \brief Return geometry of the top or bottom curve
1387 * \retval Adaptor3d_Curve* -
1389 //================================================================================
1391 Adaptor3d_Curve* StdMeshers_PrismAsBlock::TSideFace::HorizCurve(const bool isTop) const
1393 return new THorizontalEdgeAdaptor( this, isTop );
1396 //================================================================================
1398 * \brief Return pcurves
1399 * \param pcurv - array of 4 pcurves
1400 * \retval bool - is a success
1402 //================================================================================
1404 bool StdMeshers_PrismAsBlock::TSideFace::GetPCurves(Adaptor2d_Curve2d* pcurv[4]) const
1406 int iEdge[ 4 ] = { BOTTOM_EDGE, TOP_EDGE, V0_EDGE, V1_EDGE };
1408 for ( int i = 0 ; i < 4 ; ++i ) {
1409 Handle(Geom2d_Line) line;
1410 switch ( iEdge[ i ] ) {
1412 line = new Geom2d_Line( gp_Pnt2d( 0, 1 ), gp::DX2d() ); break;
1414 line = new Geom2d_Line( gp::Origin2d(), gp::DX2d() ); break;
1416 line = new Geom2d_Line( gp::Origin2d(), gp::DY2d() ); break;
1418 line = new Geom2d_Line( gp_Pnt2d( 1, 0 ), gp::DY2d() ); break;
1420 pcurv[ i ] = new Geom2dAdaptor_Curve( line, 0, 1 );
1425 //================================================================================
1427 * \brief Returns geometry of pcurve on a horizontal face
1428 * \param isTop - is top or bottom face
1429 * \param horFace - a horizontal face
1430 * \retval Adaptor2d_Curve2d* - curve adaptor
1432 //================================================================================
1435 StdMeshers_PrismAsBlock::TSideFace::HorizPCurve(const bool isTop,
1436 const TopoDS_Face& horFace) const
1438 return new TPCurveOnHorFaceAdaptor( this, isTop, horFace );
1441 //================================================================================
1443 * \brief Return a component corresponding to parameter
1444 * \param U - parameter along a horizontal size
1445 * \param localU - parameter along a horizontal size of a component
1446 * \retval TSideFace* - found component
1448 //================================================================================
1450 StdMeshers_PrismAsBlock::TSideFace*
1451 StdMeshers_PrismAsBlock::TSideFace::GetComponent(const double U,double & localU) const
1454 if ( myComponents.empty() )
1455 return const_cast<TSideFace*>( this );
1458 for ( i = 0; i < myComponents.size(); ++i )
1459 if ( U < myParams[ i ].second )
1461 if ( i >= myComponents.size() )
1462 i = myComponents.size() - 1;
1464 double f = myParams[ i ].first, l = myParams[ i ].second;
1465 localU = ( U - f ) / ( l - f );
1466 return myComponents[ i ];
1469 //================================================================================
1471 * \brief Find node columns for a parameter
1472 * \param U - parameter along a horizontal edge
1473 * \param col1 - the 1st found column
1474 * \param col2 - the 2nd found column
1475 * \retval r - normalized position of U between the found columns
1477 //================================================================================
1479 double StdMeshers_PrismAsBlock::TSideFace::GetColumns(const double U,
1480 TParam2ColumnIt & col1,
1481 TParam2ColumnIt & col2) const
1483 double u = U, r = 0;
1484 if ( !myComponents.empty() ) {
1485 TSideFace * comp = GetComponent(U,u);
1486 return comp->GetColumns( u, col1, col2 );
1491 double f = myParams[0].first, l = myParams[0].second;
1492 u = f + u * ( l - f );
1494 col1 = col2 = getColumn( myParamToColumnMap, u );
1495 if ( ++col2 == myParamToColumnMap->end() ) {
1500 // if ( !myIsForward )
1501 // std::swap( col1, col2 );
1502 double uf = col1->first;
1503 double ul = col2->first;
1504 r = ( u - uf ) / ( ul - uf );
1509 //================================================================================
1511 * \brief Return coordinates by normalized params
1512 * \param U - horizontal param
1513 * \param V - vertical param
1514 * \retval gp_Pnt - result point
1516 //================================================================================
1518 gp_Pnt StdMeshers_PrismAsBlock::TSideFace::Value(const Standard_Real U,
1519 const Standard_Real V) const
1522 if ( !myComponents.empty() ) {
1523 TSideFace * comp = GetComponent(U,u);
1524 return comp->Value( u, V );
1527 TParam2ColumnIt u_col1, u_col2;
1528 double vR, hR = GetColumns( U, u_col1, u_col2 );
1530 const SMDS_MeshNode* n1 = 0;
1531 const SMDS_MeshNode* n2 = 0;
1532 const SMDS_MeshNode* n3 = 0;
1533 const SMDS_MeshNode* n4 = 0;
1536 vR = getRAndNodes( & u_col1->second, V, n1, n2 );
1537 vR = getRAndNodes( & u_col2->second, V, n3, n4 );
1539 gp_XY uv1 = myHelper->GetNodeUV( mySurface.Face(), n1, n4);
1540 gp_XY uv2 = myHelper->GetNodeUV( mySurface.Face(), n2, n3);
1541 gp_XY uv12 = uv1 * ( 1 - vR ) + uv2 * vR;
1543 gp_XY uv3 = myHelper->GetNodeUV( mySurface.Face(), n3, n2);
1544 gp_XY uv4 = myHelper->GetNodeUV( mySurface.Face(), n4, n1);
1545 gp_XY uv34 = uv3 * ( 1 - vR ) + uv4 * vR;
1547 gp_XY uv = uv12 * ( 1 - hR ) + uv34 * hR;
1549 return mySurface.Value( uv.X(), uv.Y() );
1553 //================================================================================
1555 * \brief Return boundary edge
1556 * \param edge - edge index
1557 * \retval TopoDS_Edge - found edge
1559 //================================================================================
1561 TopoDS_Edge StdMeshers_PrismAsBlock::TSideFace::GetEdge(const int iEdge) const
1563 if ( !myComponents.empty() ) {
1565 case V0_EDGE : return myComponents.front()->GetEdge( iEdge );
1566 case V1_EDGE : return myComponents.back() ->GetEdge( iEdge );
1567 default: return TopoDS_Edge();
1571 const SMDS_MeshNode* node = 0;
1572 SMESHDS_Mesh * meshDS = myHelper->GetMesh()->GetMeshDS();
1573 TNodeColumn* column;
1578 column = & (( ++myParamToColumnMap->begin())->second );
1579 node = ( iEdge == TOP_EDGE ) ? column->back() : column->front();
1580 edge = myHelper->GetSubShapeByNode ( node, meshDS );
1581 if ( edge.ShapeType() == TopAbs_VERTEX ) {
1582 column = & ( myParamToColumnMap->begin()->second );
1583 node = ( iEdge == TOP_EDGE ) ? column->back() : column->front();
1588 bool back = ( iEdge == V1_EDGE );
1589 if ( !myIsForward ) back = !back;
1591 column = & ( myParamToColumnMap->rbegin()->second );
1593 column = & ( myParamToColumnMap->begin()->second );
1594 if ( column->size() > 0 )
1595 edge = myHelper->GetSubShapeByNode( (*column)[ 1 ], meshDS );
1596 if ( edge.IsNull() || edge.ShapeType() == TopAbs_VERTEX )
1597 node = column->front();
1602 if ( !edge.IsNull() || edge.ShapeType() == TopAbs_EDGE )
1603 return TopoDS::Edge( edge );
1605 // find edge by 2 vertices
1606 TopoDS_Shape V1 = edge;
1607 TopoDS_Shape V2 = myHelper->GetSubShapeByNode( node, meshDS );
1608 if ( V2.ShapeType() == TopAbs_VERTEX && !V2.IsSame( V1 ))
1610 TopTools_ListIteratorOfListOfShape ancestIt =
1611 myHelper->GetMesh()->GetAncestors( V1 );
1612 for ( ; ancestIt.More(); ancestIt.Next() )
1614 const TopoDS_Shape & ancestor = ancestIt.Value();
1615 if ( ancestor.ShapeType() == TopAbs_EDGE )
1616 for ( TopExp_Explorer e( ancestor, TopAbs_VERTEX ); e.More(); e.Next() )
1617 if ( V2.IsSame( e.Current() ))
1618 return TopoDS::Edge( ancestor );
1621 return TopoDS_Edge();
1624 //================================================================================
1626 * \brief Fill block subshapes
1627 * \param shapeMap - map to fill in
1628 * \retval int - nb inserted subshapes
1630 //================================================================================
1632 int StdMeshers_PrismAsBlock::TSideFace::InsertSubShapes(TBlockShapes& shapeMap) const
1637 vector< int > edgeIdVec;
1638 SMESH_Block::GetFaceEdgesIDs( myID, edgeIdVec );
1640 for ( int i = BOTTOM_EDGE; i <=V1_EDGE ; ++i ) {
1641 TopoDS_Edge e = GetEdge( i );
1642 if ( !e.IsNull() ) {
1643 nbInserted += SMESH_Block::Insert( e, edgeIdVec[ i ], shapeMap);
1647 // Insert corner vertices
1649 TParam2ColumnIt col1, col2 ;
1650 vector< int > vertIdVec;
1653 SMESH_Block::GetEdgeVertexIDs( edgeIdVec[ V0_EDGE ], vertIdVec);
1654 GetColumns(0, col1, col2 );
1655 const SMDS_MeshNode* node0 = col1->second.front();
1656 const SMDS_MeshNode* node1 = col1->second.back();
1657 TopoDS_Shape v0 = myHelper->GetSubShapeByNode( node0, myHelper->GetMeshDS());
1658 TopoDS_Shape v1 = myHelper->GetSubShapeByNode( node1, myHelper->GetMeshDS());
1659 if ( v0.ShapeType() == TopAbs_VERTEX ) {
1660 nbInserted += SMESH_Block::Insert( v0, vertIdVec[ 0 ], shapeMap);
1662 if ( v1.ShapeType() == TopAbs_VERTEX ) {
1663 nbInserted += SMESH_Block::Insert( v1, vertIdVec[ 1 ], shapeMap);
1667 SMESH_Block::GetEdgeVertexIDs( edgeIdVec[ V1_EDGE ], vertIdVec);
1668 GetColumns(1, col1, col2 );
1669 node0 = col2->second.front();
1670 node1 = col2->second.back();
1671 v0 = myHelper->GetSubShapeByNode( node0, myHelper->GetMeshDS());
1672 v1 = myHelper->GetSubShapeByNode( node1, myHelper->GetMeshDS());
1673 if ( v0.ShapeType() == TopAbs_VERTEX ) {
1674 nbInserted += SMESH_Block::Insert( v0, vertIdVec[ 0 ], shapeMap);
1676 if ( v1.ShapeType() == TopAbs_VERTEX ) {
1677 nbInserted += SMESH_Block::Insert( v1, vertIdVec[ 1 ], shapeMap);
1680 // TopoDS_Vertex V0, V1, Vcom;
1681 // TopExp::Vertices( myBaseEdge, V0, V1, true );
1682 // if ( !myIsForward ) std::swap( V0, V1 );
1684 // // bottom vertex IDs
1685 // SMESH_Block::GetEdgeVertexIDs( edgeIdVec[ _u0 ], vertIdVec);
1686 // SMESH_Block::Insert( V0, vertIdVec[ 0 ], shapeMap);
1687 // SMESH_Block::Insert( V1, vertIdVec[ 1 ], shapeMap);
1689 // TopoDS_Edge sideEdge = GetEdge( V0_EDGE );
1690 // if ( sideEdge.IsNull() || !TopExp::CommonVertex( botEdge, sideEdge, Vcom ))
1693 // // insert one side edge
1695 // if ( Vcom.IsSame( V0 )) edgeID = edgeIdVec[ _v0 ];
1696 // else edgeID = edgeIdVec[ _v1 ];
1697 // SMESH_Block::Insert( sideEdge, edgeID, shapeMap);
1699 // // top vertex of the side edge
1700 // SMESH_Block::GetEdgeVertexIDs( edgeID, vertIdVec);
1701 // TopoDS_Vertex Vtop = TopExp::FirstVertex( sideEdge );
1702 // if ( Vcom.IsSame( Vtop ))
1703 // Vtop = TopExp::LastVertex( sideEdge );
1704 // SMESH_Block::Insert( Vtop, vertIdVec[ 1 ], shapeMap);
1706 // // other side edge
1707 // sideEdge = GetEdge( V1_EDGE );
1708 // if ( sideEdge.IsNull() )
1710 // if ( edgeID = edgeIdVec[ _v1 ]) edgeID = edgeIdVec[ _v0 ];
1711 // else edgeID = edgeIdVec[ _v1 ];
1712 // SMESH_Block::Insert( sideEdge, edgeID, shapeMap);
1715 // TopoDS_Edge topEdge = GetEdge( TOP_EDGE );
1716 // SMESH_Block::Insert( topEdge, edgeIdVec[ _u1 ], shapeMap);
1718 // // top vertex of the other side edge
1719 // if ( !TopExp::CommonVertex( topEdge, sideEdge, Vcom ))
1721 // SMESH_Block::GetEdgeVertexIDs( edgeID, vertIdVec );
1722 // SMESH_Block::Insert( Vcom, vertIdVec[ 1 ], shapeMap);
1727 //================================================================================
1729 * \brief Creates TVerticalEdgeAdaptor
1730 * \param columnsMap - node column map
1731 * \param parameter - normalized parameter
1733 //================================================================================
1735 StdMeshers_PrismAsBlock::TVerticalEdgeAdaptor::
1736 TVerticalEdgeAdaptor( const TParam2ColumnMap* columnsMap, const double parameter)
1738 myNodeColumn = & getColumn( columnsMap, parameter )->second;
1741 //================================================================================
1743 * \brief Return coordinates for the given normalized parameter
1744 * \param U - normalized parameter
1745 * \retval gp_Pnt - coordinates
1747 //================================================================================
1749 gp_Pnt StdMeshers_PrismAsBlock::TVerticalEdgeAdaptor::Value(const Standard_Real U) const
1751 const SMDS_MeshNode* n1;
1752 const SMDS_MeshNode* n2;
1753 double r = getRAndNodes( myNodeColumn, U, n1, n2 );
1754 return gpXYZ(n1) * ( 1 - r ) + gpXYZ(n2) * r;
1757 //================================================================================
1759 * \brief Return coordinates for the given normalized parameter
1760 * \param U - normalized parameter
1761 * \retval gp_Pnt - coordinates
1763 //================================================================================
1765 gp_Pnt StdMeshers_PrismAsBlock::THorizontalEdgeAdaptor::Value(const Standard_Real U) const
1767 return mySide->TSideFace::Value( U, myV );
1770 //================================================================================
1772 * \brief Return UV on pcurve for the given normalized parameter
1773 * \param U - normalized parameter
1774 * \retval gp_Pnt - coordinates
1776 //================================================================================
1778 gp_Pnt2d StdMeshers_PrismAsBlock::TPCurveOnHorFaceAdaptor::Value(const Standard_Real U) const
1780 TParam2ColumnIt u_col1, u_col2;
1781 double r = mySide->GetColumns( U, u_col1, u_col2 );
1782 gp_XY uv1 = mySide->GetNodeUV( myFace, u_col1->second[ myZ ]);
1783 gp_XY uv2 = mySide->GetNodeUV( myFace, u_col2->second[ myZ ]);
1784 return uv1 * ( 1 - r ) + uv2 * r;