1 // SMESH SMESH : implementaion of SMESH idl descriptions
3 // Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
24 // File : StdMeshers_Prism_3D.cxx
26 // Created : Fri Oct 20 11:37:07 2006
27 // Author : Edward AGAPOV (eap)
30 #include "StdMeshers_Prism_3D.hxx"
32 #include "StdMeshers_ProjectionUtils.hxx"
33 #include "SMESH_MeshEditor.hxx"
34 #include "SMDS_VolumeTool.hxx"
35 #include "SMDS_VolumeOfNodes.hxx"
36 #include "SMDS_EdgePosition.hxx"
37 #include "SMESH_Comment.hxx"
39 #include "utilities.h"
41 #include <BRepAdaptor_Curve.hxx>
42 #include <BRepAdaptor_Curve2d.hxx>
43 #include <BRep_Builder.hxx>
44 #include <BRep_Tool.hxx>
45 #include <Geom2dAdaptor_Curve.hxx>
46 #include <Geom2d_Line.hxx>
47 #include <TopTools_ListIteratorOfListOfShape.hxx>
51 #define RETURN_BAD_RESULT(msg) { MESSAGE(msg); return false; }
52 #define gpXYZ(n) gp_XYZ(n->X(),n->Y(),n->Z())
53 #define SHOWYXZ(msg, xyz) // {\
55 // cout << msg << " ("<< p.X() << "; " <<p.Y() << "; " <<p.Z() << ") " <<endl;\
58 typedef StdMeshers_ProjectionUtils TAssocTool;
59 typedef SMESH_Comment TCom;
61 enum { ID_BOT_FACE = SMESH_Block::ID_Fxy0,
62 ID_TOP_FACE = SMESH_Block::ID_Fxy1,
63 BOTTOM_EDGE = 0, TOP_EDGE, V0_EDGE, V1_EDGE, // edge IDs in face
64 NB_WALL_FACES = 4 }; //
68 //================================================================================
70 * \brief Return iterator pointing to node column for the given parameter
71 * \param columnsMap - node column map
72 * \param parameter - parameter
73 * \retval TParam2ColumnMap::iterator - result
75 * it returns closest left column
77 //================================================================================
79 TParam2ColumnIt getColumn( const TParam2ColumnMap* columnsMap,
80 const double parameter )
82 TParam2ColumnIt u_col = columnsMap->upper_bound( parameter );
83 if ( u_col != columnsMap->begin() )
85 return u_col; // return left column
88 //================================================================================
90 * \brief Return nodes around given parameter and a ratio
91 * \param column - node column
92 * \param param - parameter
93 * \param node1 - lower node
94 * \param node2 - upper node
95 * \retval double - ratio
97 //================================================================================
99 double getRAndNodes( const TNodeColumn* column,
101 const SMDS_MeshNode* & node1,
102 const SMDS_MeshNode* & node2)
104 if ( param == 1.0 || column->size() == 1) {
105 node1 = node2 = column->back();
109 int i = int( param * ( column->size() - 1 ));
110 double u0 = double( i )/ double( column->size() - 1 );
111 double r = ( param - u0 ) * ( column->size() - 1 );
113 node1 = (*column)[ i ];
114 node2 = (*column)[ i + 1];
118 //================================================================================
120 * \brief Compute boundary parameters of face parts
121 * \param nbParts - nb of parts to split columns into
122 * \param columnsMap - node columns of the face to split
123 * \param params - computed parameters
125 //================================================================================
127 void splitParams( const int nbParts,
128 const TParam2ColumnMap* columnsMap,
129 vector< double > & params)
132 params.reserve( nbParts + 1 );
133 TParam2ColumnIt last_par_col = --columnsMap->end();
134 double par = columnsMap->begin()->first; // 0.
135 double parLast = last_par_col->first;
136 params.push_back( par );
137 for ( int i = 0; i < nbParts - 1; ++ i )
139 double partSize = ( parLast - par ) / double ( nbParts - i );
140 TParam2ColumnIt par_col = getColumn( columnsMap, par + partSize );
141 if ( par_col->first == par ) {
143 if ( par_col == last_par_col ) {
144 while ( i < nbParts - 1 )
145 params.push_back( par + partSize * i++ );
149 par = par_col->first;
150 params.push_back( par );
152 params.push_back( parLast ); // 1.
156 //=======================================================================
157 //function : StdMeshers_Prism_3D
159 //=======================================================================
161 StdMeshers_Prism_3D::StdMeshers_Prism_3D(int hypId, int studyId, SMESH_Gen* gen)
162 :SMESH_3D_Algo(hypId, studyId, gen)
165 _shapeType = (1 << TopAbs_SHELL) | (1 << TopAbs_SOLID); // 1 bit per shape type
166 myProjectTriangles = false;
169 //================================================================================
173 //================================================================================
175 StdMeshers_Prism_3D::~StdMeshers_Prism_3D()
178 //=======================================================================
179 //function : CheckHypothesis
181 //=======================================================================
183 bool StdMeshers_Prism_3D::CheckHypothesis(SMESH_Mesh& aMesh,
184 const TopoDS_Shape& aShape,
185 SMESH_Hypothesis::Hypothesis_Status& aStatus)
187 // Check shape geometry
189 aStatus = SMESH_Hypothesis::HYP_BAD_GEOMETRY;
191 // find not quadrangle faces
192 list< TopoDS_Shape > notQuadFaces;
193 int nbEdge, nbWire, nbFace = 0;
194 TopExp_Explorer exp( aShape, TopAbs_FACE );
195 for ( ; exp.More(); exp.Next() ) {
197 const TopoDS_Shape& face = exp.Current();
198 nbEdge = TAssocTool::Count( face, TopAbs_EDGE, 0 );
199 nbWire = TAssocTool::Count( face, TopAbs_WIRE, 0 );
200 if ( nbEdge!= 4 || nbWire!= 1 ) {
201 if ( !notQuadFaces.empty() ) {
202 if ( TAssocTool::Count( notQuadFaces.back(), TopAbs_EDGE, 0 ) != nbEdge ||
203 TAssocTool::Count( notQuadFaces.back(), TopAbs_WIRE, 0 ) != nbWire )
204 RETURN_BAD_RESULT("Different not quad faces");
206 notQuadFaces.push_back( face );
209 if ( !notQuadFaces.empty() )
211 if ( notQuadFaces.size() != 2 )
212 RETURN_BAD_RESULT("Bad nb not quad faces: " << notQuadFaces.size());
214 // check total nb faces
215 nbEdge = TAssocTool::Count( notQuadFaces.back(), TopAbs_EDGE, 0 );
216 if ( nbFace != nbEdge + 2 )
217 RETURN_BAD_RESULT("Bad nb of faces: " << nbFace << " but must be " << nbEdge + 2);
221 aStatus = SMESH_Hypothesis::HYP_OK;
225 //=======================================================================
228 //=======================================================================
230 bool StdMeshers_Prism_3D::Compute(SMESH_Mesh& theMesh, const TopoDS_Shape& theShape)
232 SMESH_MesherHelper helper( theMesh );
235 myHelper->IsQuadraticSubMesh( theShape );
237 // Analyse mesh and geomerty to find block subshapes and submeshes
238 if ( !myBlock.Init( myHelper, theShape ))
239 return error( myBlock.GetError());
241 SMESHDS_Mesh* meshDS = theMesh.GetMeshDS();
243 int volumeID = meshDS->ShapeToIndex( theShape );
246 // To compute coordinates of a node inside a block, it is necessary to know
247 // 1. normalized parameters of the node by which
248 // 2. coordinates of node projections on all block sub-shapes are computed
250 // So we fill projections on vertices at once as they are same for all nodes
251 myShapeXYZ.resize( myBlock.NbSubShapes() );
252 for ( int iV = SMESH_Block::ID_FirstV; iV < SMESH_Block::ID_FirstE; ++iV ) {
253 myBlock.VertexPoint( iV, myShapeXYZ[ iV ]);
254 SHOWYXZ("V point " <<iV << " ", myShapeXYZ[ iV ]);
257 // Projections on the top and bottom faces are taken from nodes existing
258 // on these faces; find correspondence between bottom and top nodes
259 myBotToColumnMap.clear();
260 if ( !assocOrProjBottom2Top() ) // it also fill myBotToColumnMap
264 // Create nodes inside the block
266 // loop on nodes inside the bottom face
267 TNode2ColumnMap::iterator bot_column = myBotToColumnMap.begin();
268 for ( ; bot_column != myBotToColumnMap.end(); ++bot_column )
270 const TNode& tBotNode = bot_column->first; // bottom TNode
271 if ( tBotNode.GetPositionType() != SMDS_TOP_FACE )
272 continue; // node is not inside face
274 // column nodes; middle part of the column are zero pointers
275 TNodeColumn& column = bot_column->second;
277 // bottom node parameters and coords
278 gp_XYZ botParams = tBotNode.GetParams();
279 myShapeXYZ[ ID_BOT_FACE ] = tBotNode.GetCoords();
281 // compute top node parameters
283 myShapeXYZ[ ID_TOP_FACE ] = gpXYZ( column.back() );
284 gp_Pnt topCoords = myShapeXYZ[ ID_TOP_FACE ];
285 if ( !myBlock.ComputeParameters( topCoords, topParams, ID_TOP_FACE ))
286 return error(dfltErr(),TCom("Can't compute normalized parameters ")
287 << "for node " << column.back()->GetID()
288 << " on the face #"<< column.back()->GetPosition()->GetShapeId() );
291 TNodeColumn::iterator columnNodes = column.begin();
292 for ( int z = 0; columnNodes != column.end(); ++columnNodes, ++z)
294 const SMDS_MeshNode* & node = *columnNodes;
295 if ( node ) continue; // skip bottom or top node
297 // params of a node to create
298 double rz = (double) z / (double) ( column.size() - 1 );
299 gp_XYZ params = botParams * ( 1 - rz ) + topParams * rz;
301 // set coords on all faces and nodes
302 const int nbSideFaces = 4;
303 int sideFaceIDs[nbSideFaces] = { SMESH_Block::ID_Fx0z,
304 SMESH_Block::ID_Fx1z,
305 SMESH_Block::ID_F0yz,
306 SMESH_Block::ID_F1yz };
307 for ( int iF = 0; iF < nbSideFaces; ++iF )
308 if ( !setFaceAndEdgesXYZ( sideFaceIDs[ iF ], params, z ))
311 // compute coords for a new node
313 if ( !SMESH_Block::ShellPoint( params, myShapeXYZ, coords ))
314 return error(dfltErr(),"Can't compute coordinates by normalized parameters");
317 node = meshDS->AddNode( coords.X(), coords.Y(), coords.Z() );
318 meshDS->SetNodeInVolume( node, volumeID );
320 } // loop on bottom nodes
325 SMESHDS_SubMesh* smDS = myBlock.SubMeshDS( ID_BOT_FACE );
326 if ( !smDS ) return error(COMPERR_BAD_INPUT_MESH, "Null submesh");
328 // loop on bottom mesh faces
329 SMDS_ElemIteratorPtr faceIt = smDS->GetElements();
330 while ( faceIt->more() )
332 const SMDS_MeshElement* face = faceIt->next();
333 if ( !face || face->GetType() != SMDSAbs_Face )
335 int nbNodes = face->NbNodes();
336 if ( face->IsQuadratic() )
339 // find node columns for each node
340 vector< const TNodeColumn* > columns( nbNodes );
341 for ( int i = 0; i < nbNodes; ++i )
343 const SMDS_MeshNode* n = face->GetNode( i );
344 if ( n->GetPosition()->GetTypeOfPosition() == SMDS_TOP_FACE ) {
345 bot_column = myBotToColumnMap.find( n );
346 if ( bot_column == myBotToColumnMap.end() )
347 return error(dfltErr(),TCom("No nodes found above node ") << n->GetID() );
348 columns[ i ] = & bot_column->second;
351 columns[ i ] = myBlock.GetNodeColumn( n );
353 return error(dfltErr(),TCom("No side nodes found above node ") << n->GetID() );
357 AddPrisms( columns, myHelper );
359 } // loop on bottom mesh faces
364 //================================================================================
366 * \brief Create prisms
367 * \param columns - columns of nodes generated from nodes of a mesh face
368 * \param helper - helper initialized by mesh and shape to add prisms to
370 //================================================================================
372 void StdMeshers_Prism_3D::AddPrisms( vector<const TNodeColumn*> & columns,
373 SMESH_MesherHelper* helper)
375 SMESHDS_Mesh * meshDS = helper->GetMeshDS();
376 int shapeID = helper->GetSubShapeID();
378 int nbNodes = columns.size();
380 // vertical loop on columns
381 for ( int z = 1; z < columns[0]->size(); ++z)
383 SMDS_MeshElement* vol = 0;
384 SMDS_VolumeTool vTool;
388 const SMDS_MeshNode* botNodes[3] = { (*columns[0])[z-1],
390 (*columns[2])[z-1] };
391 const SMDS_MeshNode* topNodes[3] = { (*columns[0])[z],
394 // assure good orientation
395 SMDS_VolumeOfNodes tmpVol ( botNodes[0], botNodes[1], botNodes[2],
396 topNodes[0], topNodes[1], topNodes[2]);
397 vTool.Set( &tmpVol );
398 if ( vTool.IsForward() )
399 vol = helper->AddVolume( botNodes[0], botNodes[1], botNodes[2],
400 topNodes[0], topNodes[1], topNodes[2]);
402 vol = helper->AddVolume( topNodes[0], topNodes[1], topNodes[2],
403 botNodes[0], botNodes[1], botNodes[2]);
407 const SMDS_MeshNode* botNodes[4] = { (*columns[0])[z-1], (*columns[1])[z-1],
408 (*columns[2])[z-1], (*columns[3])[z-1] };
409 const SMDS_MeshNode* topNodes[4] = { (*columns[0])[z], (*columns[1])[z],
410 (*columns[2])[z], (*columns[3])[z] };
411 // assure good orientation
412 SMDS_VolumeOfNodes tmpVol ( botNodes[0], botNodes[1], botNodes[2], botNodes[3],
413 topNodes[0], topNodes[1], topNodes[2], topNodes[3]);
414 vTool.Set( &tmpVol );
415 if ( vTool.IsForward() )
416 vol = helper->AddVolume( botNodes[0], botNodes[1], botNodes[2], botNodes[3],
417 topNodes[0], topNodes[1], topNodes[2], topNodes[3]);
419 vol = helper->AddVolume( topNodes[0], topNodes[1], topNodes[2], topNodes[3],
420 botNodes[0], botNodes[1], botNodes[2], botNodes[3]);
425 vector<const SMDS_MeshNode*> nodes( 2*nbNodes + 4*nbNodes);
426 vector<int> quantities( 2 + nbNodes, 4 );
427 quantities[0] = quantities[1] = nbNodes;
428 columns.resize( nbNodes + 1 );
429 columns[ nbNodes ] = columns[ 0 ];
430 for ( int i = 0; i < nbNodes; ++i ) {
431 nodes[ i ] = (*columns[ i ])[z-1]; // bottom
432 nodes[ i+nbNodes ] = (*columns[ i ])[z ]; // top
434 int di = 2*nbNodes + 4*i - 1;
435 nodes[ di ] = (*columns[i ])[z-1];
436 nodes[ di+1 ] = (*columns[i+1])[z-1];
437 nodes[ di+2 ] = (*columns[i+1])[z ];
438 nodes[ di+3 ] = (*columns[i ])[z ];
440 vol = meshDS->AddPolyhedralVolume( nodes, quantities );
442 if ( vol && shapeID > 0 )
443 meshDS->SetMeshElementOnShape( vol, shapeID );
447 //================================================================================
449 * \brief Find correspondence between bottom and top nodes
450 * If elements on the bottom and top faces are topologically different,
451 * and projection is possible and allowed, perform the projection
452 * \retval bool - is a success or not
454 //================================================================================
456 bool StdMeshers_Prism_3D::assocOrProjBottom2Top()
458 SMESH_subMesh * botSM = myBlock.SubMesh( ID_BOT_FACE );
459 SMESH_subMesh * topSM = myBlock.SubMesh( ID_TOP_FACE );
461 SMESHDS_SubMesh * botSMDS = botSM->GetSubMeshDS();
462 SMESHDS_SubMesh * topSMDS = topSM->GetSubMeshDS();
464 if ( !botSMDS || botSMDS->NbElements() == 0 )
465 return error(dfltErr(),TCom("No elememts on face #") << botSM->GetId());
467 bool needProject = false;
469 botSMDS->NbElements() != topSMDS->NbElements() ||
470 botSMDS->NbNodes() != topSMDS->NbNodes())
472 if ( myBlock.HasNotQuadElemOnTop() )
473 return error(dfltErr(),TCom("Mesh on faces #") << botSM->GetId()
474 <<" and #"<< topSM->GetId() << " seems different" );
478 if ( 0/*needProject && !myProjectTriangles*/ )
479 return error(dfltErr(),TCom("Mesh on faces #") << botSM->GetId()
480 <<" and #"<< topSM->GetId() << " seems different" );
481 ///RETURN_BAD_RESULT("Need to project but not allowed");
485 return projectBottomToTop();
488 TopoDS_Face botFace = TopoDS::Face( myBlock.Shape( ID_BOT_FACE ));
489 TopoDS_Face topFace = TopoDS::Face( myBlock.Shape( ID_TOP_FACE ));
490 // associate top and bottom faces
491 TAssocTool::TShapeShapeMap shape2ShapeMap;
492 if ( !TAssocTool::FindSubShapeAssociation( botFace, myBlock.Mesh(),
493 topFace, myBlock.Mesh(),
495 return error(dfltErr(),TCom("Topology of faces #") << botSM->GetId()
496 <<" and #"<< topSM->GetId() << " seems different" );
498 // Find matching nodes of top and bottom faces
500 if ( ! TAssocTool::FindMatchingNodesOnFaces( botFace, myBlock.Mesh(),
501 topFace, myBlock.Mesh(),
502 shape2ShapeMap, n2nMap ))
503 return error(dfltErr(),TCom("Mesh on faces #") << botSM->GetId()
504 <<" and #"<< topSM->GetId() << " seems different" );
506 // Fill myBotToColumnMap
508 int zSize = myBlock.VerticalSize();
509 TNodeNodeMap::iterator bN_tN = n2nMap.begin();
510 for ( ; bN_tN != n2nMap.end(); ++bN_tN )
512 const SMDS_MeshNode* botNode = bN_tN->first;
513 const SMDS_MeshNode* topNode = bN_tN->second;
514 if ( botNode->GetPosition()->GetTypeOfPosition() != SMDS_TOP_FACE )
515 continue; // wall columns are contained in myBlock
516 // compute bottom node params
518 if ( !myBlock.ComputeParameters( bN.GetCoords(), bN.ChangeParams(), ID_BOT_FACE ))
519 return error(dfltErr(),TCom("Can't compute normalized parameters ")
520 << "for node " << botNode->GetID() << " on the face #"<< botSM->GetId() );
521 // create node column
522 TNode2ColumnMap::iterator bN_col =
523 myBotToColumnMap.insert( make_pair ( bN, TNodeColumn() )).first;
524 TNodeColumn & column = bN_col->second;
525 column.resize( zSize );
526 column.front() = botNode;
527 column.back() = topNode;
532 //================================================================================
534 * \brief Remove quadrangles from the top face and
535 * create triangles there by projection from the bottom
536 * \retval bool - a success or not
538 //================================================================================
540 bool StdMeshers_Prism_3D::projectBottomToTop()
542 SMESH_subMesh * botSM = myBlock.SubMesh( ID_BOT_FACE );
543 SMESH_subMesh * topSM = myBlock.SubMesh( ID_TOP_FACE );
545 SMESHDS_SubMesh * botSMDS = botSM->GetSubMeshDS();
546 SMESHDS_SubMesh * topSMDS = topSM->GetSubMeshDS();
549 topSM->ComputeStateEngine( SMESH_subMesh::CLEAN );
551 SMESHDS_Mesh* meshDS = myBlock.MeshDS();
552 int shapeID = myHelper->GetSubShapeID();
553 int topFaceID = meshDS->ShapeToIndex( topSM->GetSubShape() );
555 // Fill myBotToColumnMap
557 int zSize = myBlock.VerticalSize();
558 SMDS_NodeIteratorPtr nIt = botSMDS->GetNodes();
559 while ( nIt->more() )
561 const SMDS_MeshNode* botNode = nIt->next();
562 if ( botNode->GetPosition()->GetTypeOfPosition() != SMDS_TOP_FACE )
564 // compute bottom node params
566 if ( !myBlock.ComputeParameters( bN.GetCoords(), bN.ChangeParams(), ID_BOT_FACE ))
567 return error(dfltErr(),TCom("Can't compute normalized parameters ")
568 << "for node " << botNode->GetID() << " on the face #"<< botSM->GetId() );
569 // compute top node coords
570 gp_XYZ topXYZ; gp_XY topUV;
571 if ( !myBlock.FacePoint( ID_TOP_FACE, bN.GetParams(), topXYZ ) ||
572 !myBlock.FaceUV ( ID_TOP_FACE, bN.GetParams(), topUV ))
573 return error(dfltErr(),TCom("Can't compute coordinates ")
574 << "by normalized parameters on the face #"<< topSM->GetId() );
575 SMDS_MeshNode * topNode = meshDS->AddNode( topXYZ.X(),topXYZ.Y(),topXYZ.Z() );
576 meshDS->SetNodeOnFace( topNode, topFaceID, topUV.X(), topUV.Y() );
577 // create node column
578 TNode2ColumnMap::iterator bN_col =
579 myBotToColumnMap.insert( make_pair ( bN, TNodeColumn() )).first;
580 TNodeColumn & column = bN_col->second;
581 column.resize( zSize );
582 column.front() = botNode;
583 column.back() = topNode;
588 // loop on bottom mesh faces
589 SMDS_ElemIteratorPtr faceIt = botSMDS->GetElements();
590 while ( faceIt->more() )
592 const SMDS_MeshElement* face = faceIt->next();
593 if ( !face || face->GetType() != SMDSAbs_Face )
595 int nbNodes = face->NbNodes();
596 if ( face->IsQuadratic() )
599 // find top node in columns for each bottom node
600 vector< const SMDS_MeshNode* > nodes( nbNodes );
601 for ( int i = 0; i < nbNodes; ++i )
603 const SMDS_MeshNode* n = face->GetNode( nbNodes - i - 1 );
604 if ( n->GetPosition()->GetTypeOfPosition() == SMDS_TOP_FACE ) {
605 TNode2ColumnMap::iterator bot_column = myBotToColumnMap.find( n );
606 if ( bot_column == myBotToColumnMap.end() )
607 return error(dfltErr(),TCom("No nodes found above node ") << n->GetID() );
608 nodes[ i ] = bot_column->second.back();
611 const TNodeColumn* column = myBlock.GetNodeColumn( n );
613 return error(dfltErr(),TCom("No side nodes found above node ") << n->GetID() );
614 nodes[ i ] = column->back();
617 // create a face, with reversed orientation
618 SMDS_MeshElement* newFace = 0;
622 newFace = myHelper->AddFace(nodes[0], nodes[1], nodes[2]);
626 newFace = myHelper->AddFace( nodes[0], nodes[1], nodes[2], nodes[3] );
630 newFace = meshDS->AddPolygonalFace( nodes );
632 if ( newFace && shapeID > 0 )
633 meshDS->SetMeshElementOnShape( newFace, shapeID );
639 //================================================================================
641 * \brief Set projection coordinates of a node to a face and it's subshapes
642 * \param faceID - the face given by in-block ID
643 * \param params - node normalized parameters
644 * \retval bool - is a success
646 //================================================================================
648 bool StdMeshers_Prism_3D::setFaceAndEdgesXYZ( const int faceID, const gp_XYZ& params, int z )
650 // find base and top edges of the face
651 enum { BASE = 0, TOP, LEFT, RIGHT };
652 vector< int > edgeVec; // 0-base, 1-top
653 SMESH_Block::GetFaceEdgesIDs( faceID, edgeVec );
655 myBlock.EdgePoint( edgeVec[ BASE ], params, myShapeXYZ[ edgeVec[ BASE ]]);
656 myBlock.EdgePoint( edgeVec[ TOP ], params, myShapeXYZ[ edgeVec[ TOP ]]);
658 SHOWYXZ("\nparams ", params);
659 SHOWYXZ("TOP is "<<edgeVec[ TOP], myShapeXYZ[ edgeVec[ TOP]]);
660 SHOWYXZ("BASE is "<<edgeVec[ BASE], myShapeXYZ[ edgeVec[ BASE]]);
662 if ( faceID == SMESH_Block::ID_Fx0z || faceID == SMESH_Block::ID_Fx1z )
664 myBlock.EdgePoint( edgeVec[ LEFT ], params, myShapeXYZ[ edgeVec[ LEFT ]]);
665 myBlock.EdgePoint( edgeVec[ RIGHT ], params, myShapeXYZ[ edgeVec[ RIGHT ]]);
667 SHOWYXZ("VER "<<edgeVec[ LEFT], myShapeXYZ[ edgeVec[ LEFT]]);
668 SHOWYXZ("VER "<<edgeVec[ RIGHT], myShapeXYZ[ edgeVec[ RIGHT]]);
670 myBlock.FacePoint( faceID, params, myShapeXYZ[ faceID ]);
671 SHOWYXZ("FacePoint "<<faceID, myShapeXYZ[ faceID]);
676 //================================================================================
678 * \brief Constructor. Initialization is needed
680 //================================================================================
682 StdMeshers_PrismAsBlock::StdMeshers_PrismAsBlock()
687 StdMeshers_PrismAsBlock::~StdMeshers_PrismAsBlock()
690 delete mySide; mySide = 0;
694 //================================================================================
696 * \brief Initialization.
697 * \param helper - helper loaded with mesh and 3D shape
698 * \param shape3D - a closed shell or solid
699 * \retval bool - false if a mesh or a shape are KO
701 //================================================================================
703 bool StdMeshers_PrismAsBlock::Init(SMESH_MesherHelper* helper,
704 const TopoDS_Shape& shape3D)
707 delete mySide; mySide = 0;
709 vector< TSideFace* > sideFaces( NB_WALL_FACES, 0 );
710 vector< pair< double, double> > params ( NB_WALL_FACES );
711 mySide = new TSideFace( sideFaces, params );
714 SMESHDS_Mesh* meshDS = myHelper->GetMeshDS();
717 myShapeIDMap.Clear();
718 myShapeIndex2ColumnMap.clear();
720 int wallFaceIds[ NB_WALL_FACES ] = { // to walk around a block
721 SMESH_Block::ID_Fx0z, SMESH_Block::ID_F1yz,
722 SMESH_Block::ID_Fx1z, SMESH_Block::ID_F0yz
725 myError = SMESH_ComputeError::New();
727 // -------------------------------------------------------------
728 // Look for top and bottom faces: not quadrangle ones or meshed
729 // with not quadrangle elements
730 // -------------------------------------------------------------
732 list< SMESH_subMesh* > notQuadGeomSubMesh;
733 list< SMESH_subMesh* > notQuadElemSubMesh;
736 SMESH_subMesh* mainSubMesh = myHelper->GetMesh()->GetSubMeshContaining( shape3D );
737 if ( !mainSubMesh ) return error(COMPERR_BAD_INPUT_MESH,"Null submesh of shape3D");
739 // analyse face submeshes
740 SMESH_subMeshIteratorPtr smIt = mainSubMesh->getDependsOnIterator(false,false);
741 while ( smIt->more() )
743 SMESH_subMesh* sm = smIt->next();
744 const TopoDS_Shape& face = sm->GetSubShape();
745 if ( face.ShapeType() != TopAbs_FACE )
749 // is quadrangle face?
750 list< TopoDS_Edge > orderedEdges;
751 list< int > nbEdgesInWires;
753 int nbWires = GetOrderedEdges( TopoDS::Face( face ),
754 V000, orderedEdges, nbEdgesInWires );
755 if ( nbWires != 1 || nbEdgesInWires.front() != 4 )
756 notQuadGeomSubMesh.push_back( sm );
758 // look for not quadrangle mesh elements
759 if ( SMESHDS_SubMesh* smDS = sm->GetSubMeshDS() ) {
760 bool hasNotQuad = false;
761 SMDS_ElemIteratorPtr eIt = smDS->GetElements();
762 while ( eIt->more() && !hasNotQuad ) {
763 const SMDS_MeshElement* elem = eIt->next();
764 if ( elem->GetType() == SMDSAbs_Face ) {
765 int nbNodes = elem->NbNodes();
766 if ( elem->IsQuadratic() )
768 hasNotQuad = ( nbNodes != 4 );
772 notQuadElemSubMesh.push_back( sm );
775 return error(COMPERR_BAD_INPUT_MESH,TCom("Not meshed face #")<<sm->GetId());
777 // check if a quadrangle face is meshed with a quadranglar grid
778 if ( notQuadGeomSubMesh.back() != sm &&
779 notQuadElemSubMesh.back() != sm )
781 // count nb edges on face sides
782 vector< int > nbEdges;
783 nbEdges.reserve( nbEdgesInWires.front() );
784 for ( list< TopoDS_Edge >::iterator edge = orderedEdges.begin();
785 edge != orderedEdges.end(); ++edge )
787 if ( SMESHDS_SubMesh* smDS = meshDS->MeshElements( *edge ))
788 nbEdges.push_back ( smDS->NbElements() );
790 nbEdges.push_back ( 0 );
792 int nbQuads = sm->GetSubMeshDS()->NbElements();
793 if ( nbEdges[0] * nbEdges[1] != nbQuads ||
794 nbEdges[0] != nbEdges[2] ||
795 nbEdges[1] != nbEdges[3] )
796 notQuadElemSubMesh.push_back( sm );
800 // ----------------------------------------------------------------------
801 // Analyse faces mesh and topology: choose the bottom submesh.
802 // If there are not quadrangle geom faces, they are top and bottom ones.
803 // Not quadrangle geom faces must be only on top and bottom.
804 // ----------------------------------------------------------------------
806 SMESH_subMesh * botSM = 0;
807 SMESH_subMesh * topSM = 0;
809 int nbNotQuad = notQuadGeomSubMesh.size();
810 int nbNotQuadMeshed = notQuadElemSubMesh.size();
811 bool hasNotQuad = ( nbNotQuad || nbNotQuadMeshed );
814 if ( nbNotQuad > 0 && nbNotQuad != 2 )
815 return error(COMPERR_BAD_SHAPE,
816 TCom("More than 2 not quadrilateral faces")
818 if ( nbNotQuadMeshed > 2 )
819 return error(COMPERR_BAD_INPUT_MESH,
820 TCom("More then 2 faces meshed with not quadrangle elements")
823 // get found submeshes
826 if ( nbNotQuadMeshed > 0 ) botSM = notQuadElemSubMesh.front();
827 else botSM = notQuadGeomSubMesh.front();
828 if ( nbNotQuadMeshed > 1 ) topSM = notQuadElemSubMesh.back();
829 else if ( nbNotQuad > 1 ) topSM = notQuadGeomSubMesh.back();
831 // detect other bad cases
832 if ( nbNotQuad == 2 && nbNotQuadMeshed > 0 ) {
834 if ( nbNotQuadMeshed == 1 )
835 ok = ( find( notQuadGeomSubMesh.begin(),
836 notQuadGeomSubMesh.end(), botSM ) != notQuadGeomSubMesh.end() );
838 ok = ( notQuadGeomSubMesh == notQuadElemSubMesh );
840 return error(COMPERR_BAD_INPUT_MESH, "Side face meshed with not quadrangle elements");
843 myNotQuadOnTop = ( nbNotQuadMeshed > 1 );
845 // ----------------------------------------------------------
847 if ( nbNotQuad == 0 ) // Standard block of 6 quadrangle faces ?
849 // SMESH_Block will perform geometry analysis, we need just to find 2
850 // connected vertices on top and bottom
852 TopoDS_Vertex Vbot, Vtop;
853 if ( nbNotQuadMeshed > 0 ) // Look for vertices
855 TopTools_IndexedMapOfShape edgeMap;
856 TopExp::MapShapes( botSM->GetSubShape(), TopAbs_EDGE, edgeMap );
857 // vertex 1 is any vertex of the bottom face
858 Vbot = TopExp::FirstVertex( TopoDS::Edge( edgeMap( 1 )));
859 // vertex 2 is end vertex of edge sharing Vbot and not belonging to the bottom face
860 TopTools_ListIteratorOfListOfShape ancestIt = Mesh()->GetAncestors( Vbot );
861 for ( ; Vtop.IsNull() && ancestIt.More(); ancestIt.Next() )
863 const TopoDS_Shape & ancestor = ancestIt.Value();
864 if ( ancestor.ShapeType() == TopAbs_EDGE && !edgeMap.FindIndex( ancestor ))
866 TopoDS_Vertex V1, V2;
867 TopExp::Vertices( TopoDS::Edge( ancestor ), V1, V2);
868 if ( Vbot.IsSame ( V1 )) Vtop = V2;
869 else if ( Vbot.IsSame ( V2 )) Vtop = V1;
870 // check that Vtop belongs to shape3D
871 TopExp_Explorer exp( shape3D, TopAbs_VERTEX );
872 for ( ; exp.More(); exp.Next() )
873 if ( Vtop.IsSame( exp.Current() ))
880 // get shell from shape3D
882 TopExp_Explorer exp( shape3D, TopAbs_SHELL );
884 for ( ; exp.More(); exp.Next(), ++nbShell )
885 shell = TopoDS::Shell( exp.Current() );
886 // if ( nbShell != 1 )
887 // RETURN_BAD_RESULT("There must be 1 shell in the block");
889 // Load geometry in SMESH_Block
890 if ( !SMESH_Block::FindBlockShapes( shell, Vbot, Vtop, myShapeIDMap )) {
892 return error(COMPERR_BAD_SHAPE, "Can't detect top and bottom of a prism");
895 if ( !botSM ) botSM = Mesh()->GetSubMeshContaining( myShapeIDMap( ID_BOT_FACE ));
896 if ( !topSM ) topSM = Mesh()->GetSubMeshContaining( myShapeIDMap( ID_TOP_FACE ));
899 } // end Standard block of 6 quadrangle faces
900 // --------------------------------------------------------
902 // Here the top and bottom faces are found
903 if ( nbNotQuadMeshed == 2 ) // roughly check correspondence of horiz meshes
905 // SMESHDS_SubMesh* topSMDS = topSM->GetSubMeshDS();
906 // SMESHDS_SubMesh* botSMDS = botSM->GetSubMeshDS();
907 // if ( topSMDS->NbNodes() != botSMDS->NbNodes() ||
908 // topSMDS->NbElements() != botSMDS->NbElements() )
909 // RETURN_BAD_RESULT("Top mesh doesn't correspond to bottom one");
912 // ---------------------------------------------------------
913 // If there are not quadrangle geom faces, we emulate
914 // a block of 6 quadrangle faces.
915 // Load SMESH_Block with faces and edges geometry
916 // ---------------------------------------------------------
919 // find vertex 000 - the one with smallest coordinates (for easy DEBUG :-)
921 double minVal = DBL_MAX, minX, val;
922 for ( TopExp_Explorer exp( botSM->GetSubShape(), TopAbs_VERTEX );
923 exp.More(); exp.Next() )
925 const TopoDS_Vertex& v = TopoDS::Vertex( exp.Current() );
926 gp_Pnt P = BRep_Tool::Pnt( v );
927 val = P.X() + P.Y() + P.Z();
928 if ( val < minVal || ( val == minVal && P.X() < minX )) {
935 // Get ordered bottom edges
936 list< TopoDS_Edge > orderedEdges;
937 list< int > nbVertexInWires;
938 SMESH_Block::GetOrderedEdges( TopoDS::Face( botSM->GetSubShape().Reversed() ),
939 V000, orderedEdges, nbVertexInWires );
940 // if ( nbVertexInWires.size() != 1 )
941 // RETURN_BAD_RESULT("Wrong prism geometry");
943 // Get Wall faces corresponding to the ordered bottom edges
944 list< TopoDS_Face > wallFaces;
945 if ( !GetWallFaces( Mesh(), shape3D, botSM->GetSubShape(), orderedEdges, wallFaces))
946 return error(COMPERR_BAD_SHAPE, "Can't find side faces");
948 // Find columns of wall nodes and calculate edges' lengths
949 // --------------------------------------------------------
951 myParam2ColumnMaps.clear();
952 myParam2ColumnMaps.resize( orderedEdges.size() ); // total nb edges
954 int iE, nbEdges = nbVertexInWires.front(); // nb outer edges
955 vector< double > edgeLength( nbEdges );
956 map< double, int > len2edgeMap;
958 list< TopoDS_Edge >::iterator edgeIt = orderedEdges.begin();
959 list< TopoDS_Face >::iterator faceIt = wallFaces.begin();
960 for ( iE = 0; iE < nbEdges; ++edgeIt, ++faceIt )
962 TParam2ColumnMap & faceColumns = myParam2ColumnMaps[ iE ];
963 if ( !myHelper->LoadNodeColumns( faceColumns, *faceIt, *edgeIt, meshDS ))
964 return error(COMPERR_BAD_INPUT_MESH, TCom("Can't find regular quadrangle mesh ")
965 << "on a side face #" << MeshDS()->ShapeToIndex( *faceIt ));
967 SHOWYXZ("\np1 F "<<iE, gpXYZ(faceColumns.begin()->second.front() ));
968 SHOWYXZ("p2 F "<<iE, gpXYZ(faceColumns.rbegin()->second.front() ));
969 SHOWYXZ("V First "<<iE, BRep_Tool::Pnt( TopExp::FirstVertex(*edgeIt,true )));
971 edgeLength[ iE ] = SMESH_Algo::EdgeLength( *edgeIt );
973 if ( nbEdges < NB_WALL_FACES ) // fill map used to split faces
975 SMESHDS_SubMesh* smDS = meshDS->MeshElements( *edgeIt);
977 return error(COMPERR_BAD_INPUT_MESH, TCom("Null submesh on the edge #")
978 << MeshDS()->ShapeToIndex( *edgeIt ));
979 // assure length uniqueness
980 edgeLength[ iE ] *= smDS->NbNodes() + edgeLength[ iE ] / ( 1000 + iE );
981 len2edgeMap[ edgeLength[ iE ]] = iE;
985 // Load columns of internal edges (forming holes)
986 // and fill map ShapeIndex to TParam2ColumnMap for them
987 for ( ; edgeIt != orderedEdges.end() ; ++edgeIt, ++faceIt )
989 TParam2ColumnMap & faceColumns = myParam2ColumnMaps[ iE ];
990 if ( !myHelper->LoadNodeColumns( faceColumns, *faceIt, *edgeIt, meshDS ))
991 return error(COMPERR_BAD_INPUT_MESH, TCom("Can't find regular quadrangle mesh ")
992 << "on a side face #" << MeshDS()->ShapeToIndex( *faceIt ));
994 int id = MeshDS()->ShapeToIndex( *edgeIt );
995 bool isForward = true; // meaningless for intenal wires
996 myShapeIndex2ColumnMap[ id ] = make_pair( & faceColumns, isForward );
997 // columns for vertices
999 const SMDS_MeshNode* n0 = faceColumns.begin()->second.front();
1000 id = n0->GetPosition()->GetShapeId();
1001 myShapeIndex2ColumnMap[ id ] = make_pair( & faceColumns, isForward );
1003 const SMDS_MeshNode* n1 = faceColumns.rbegin()->second.front();
1004 id = n1->GetPosition()->GetShapeId();
1005 myShapeIndex2ColumnMap[ id ] = make_pair( & faceColumns, isForward );
1006 // SHOWYXZ("\np1 F "<<iE, gpXYZ(faceColumns.begin()->second.front() ));
1007 // SHOWYXZ("p2 F "<<iE, gpXYZ(faceColumns.rbegin()->second.front() ));
1008 // SHOWYXZ("V First "<<iE, BRep_Tool::Pnt( TopExp::FirstVertex(*edgeIt,true )));
1012 // Create 4 wall faces of a block
1013 // -------------------------------
1015 if ( nbEdges <= NB_WALL_FACES ) // ************* Split faces if necessary
1017 map< int, int > iE2nbSplit;
1018 if ( nbEdges != NB_WALL_FACES ) // define how to split
1020 if ( len2edgeMap.size() != nbEdges )
1021 RETURN_BAD_RESULT("Uniqueness of edge lengths not assured");
1022 map< double, int >::reverse_iterator maxLen_i = len2edgeMap.rbegin();
1023 map< double, int >::reverse_iterator midLen_i = ++len2edgeMap.rbegin();
1024 double maxLen = maxLen_i->first;
1025 double midLen = ( len2edgeMap.size() == 1 ) ? 0 : midLen_i->first;
1026 switch ( nbEdges ) {
1027 case 1: // 0-th edge is split into 4 parts
1028 iE2nbSplit.insert( make_pair( 0, 4 )); break;
1029 case 2: // either the longest edge is split into 3 parts, or both edges into halves
1030 if ( maxLen / 3 > midLen / 2 ) {
1031 iE2nbSplit.insert( make_pair( maxLen_i->second, 3 ));
1034 iE2nbSplit.insert( make_pair( maxLen_i->second, 2 ));
1035 iE2nbSplit.insert( make_pair( midLen_i->second, 2 ));
1039 // split longest into halves
1040 iE2nbSplit.insert( make_pair( maxLen_i->second, 2 ));
1043 // Create TSideFace's
1044 faceIt = wallFaces.begin();
1045 edgeIt = orderedEdges.begin();
1047 for ( iE = 0; iE < nbEdges; ++edgeIt, ++faceIt )
1050 map< int, int >::iterator i_nb = iE2nbSplit.find( iE );
1051 if ( i_nb != iE2nbSplit.end() ) {
1053 int nbSplit = i_nb->second;
1054 vector< double > params;
1055 splitParams( nbSplit, &myParam2ColumnMaps[ iE ], params );
1056 bool isForward = ( edgeIt->Orientation() == TopAbs_FORWARD );
1057 for ( int i = 0; i < nbSplit; ++i ) {
1058 double f = ( isForward ? params[ i ] : params[ nbSplit - i-1 ]);
1059 double l = ( isForward ? params[ i+1 ] : params[ nbSplit - i ]);
1060 TSideFace* comp = new TSideFace( myHelper, wallFaceIds[ iSide ],
1062 &myParam2ColumnMaps[ iE ], f, l );
1063 mySide->SetComponent( iSide++, comp );
1067 TSideFace* comp = new TSideFace( myHelper, wallFaceIds[ iSide ],
1069 &myParam2ColumnMaps[ iE ]);
1070 mySide->SetComponent( iSide++, comp );
1075 else { // **************************** Unite faces
1077 // unite first faces
1078 int nbExraFaces = nbEdges - 3;
1080 double u0 = 0, sumLen = 0;
1081 for ( iE = 0; iE < nbExraFaces; ++iE )
1082 sumLen += edgeLength[ iE ];
1084 vector< TSideFace* > components( nbExraFaces );
1085 vector< pair< double, double> > params( nbExraFaces );
1086 faceIt = wallFaces.begin();
1087 edgeIt = orderedEdges.begin();
1088 for ( iE = 0; iE < nbExraFaces; ++edgeIt, ++faceIt )
1090 components[ iE ] = new TSideFace( myHelper, wallFaceIds[ iSide ],
1092 &myParam2ColumnMaps[ iE ]);
1093 double u1 = u0 + edgeLength[ iE ] / sumLen;
1094 params[ iE ] = make_pair( u0 , u1 );
1098 mySide->SetComponent( iSide++, new TSideFace( components, params ));
1100 // fill the rest faces
1101 for ( ; iE < nbEdges; ++faceIt, ++edgeIt )
1103 TSideFace* comp = new TSideFace( myHelper, wallFaceIds[ iSide ],
1105 &myParam2ColumnMaps[ iE ]);
1106 mySide->SetComponent( iSide++, comp );
1112 // Fill geometry fields of SMESH_Block
1113 // ------------------------------------
1115 TopoDS_Face botF = TopoDS::Face( botSM->GetSubShape() );
1116 TopoDS_Face topF = TopoDS::Face( topSM->GetSubShape() );
1118 vector< int > botEdgeIdVec;
1119 SMESH_Block::GetFaceEdgesIDs( ID_BOT_FACE, botEdgeIdVec );
1121 bool isForward[NB_WALL_FACES] = { true, true, true, true };
1122 Adaptor2d_Curve2d* botPcurves[NB_WALL_FACES];
1123 Adaptor2d_Curve2d* topPcurves[NB_WALL_FACES];
1125 for ( int iF = 0; iF < NB_WALL_FACES; ++iF )
1127 TSideFace * sideFace = mySide->GetComponent( iF );
1129 RETURN_BAD_RESULT("NULL TSideFace");
1130 int fID = sideFace->FaceID();
1132 // fill myShapeIDMap
1133 if ( sideFace->InsertSubShapes( myShapeIDMap ) != 8 &&
1134 !sideFace->IsComplex())
1135 MESSAGE( ": Warning : InsertSubShapes() < 8 on side " << iF );
1137 // side faces geometry
1138 Adaptor2d_Curve2d* pcurves[NB_WALL_FACES];
1139 if ( !sideFace->GetPCurves( pcurves ))
1140 RETURN_BAD_RESULT("TSideFace::GetPCurves() failed");
1142 SMESH_Block::TFace& tFace = myFace[ fID - ID_FirstF ];
1143 tFace.Set( fID, sideFace->Surface(), pcurves, isForward );
1145 SHOWYXZ( endl<<"F "<< iF << " id " << fID << " FRW " << sideFace->IsForward(), );
1146 // edges 3D geometry
1147 vector< int > edgeIdVec;
1148 SMESH_Block::GetFaceEdgesIDs( fID, edgeIdVec );
1149 for ( int isMax = 0; isMax < 2; ++isMax ) {
1151 int eID = edgeIdVec[ isMax ];
1152 SMESH_Block::TEdge& tEdge = myEdge[ eID - ID_FirstE ];
1153 tEdge.Set( eID, sideFace->HorizCurve(isMax), true);
1154 SHOWYXZ(eID<<" HOR"<<isMax<<"(0)", sideFace->HorizCurve(isMax)->Value(0));
1155 SHOWYXZ(eID<<" HOR"<<isMax<<"(1)", sideFace->HorizCurve(isMax)->Value(1));
1158 int eID = edgeIdVec[ isMax+2 ];
1159 SMESH_Block::TEdge& tEdge = myEdge[ eID - ID_FirstE ];
1160 tEdge.Set( eID, sideFace->VertiCurve(isMax), true);
1161 SHOWYXZ(eID<<" VER"<<isMax<<"(0)", sideFace->VertiCurve(isMax)->Value(0));
1162 SHOWYXZ(eID<<" VER"<<isMax<<"(1)", sideFace->VertiCurve(isMax)->Value(1));
1165 vector< int > vertexIdVec;
1166 SMESH_Block::GetEdgeVertexIDs( eID, vertexIdVec );
1167 myPnt[ vertexIdVec[0] - ID_FirstV ] = tEdge.GetCurve()->Value(0).XYZ();
1168 myPnt[ vertexIdVec[1] - ID_FirstV ] = tEdge.GetCurve()->Value(1).XYZ();
1171 // pcurves on horizontal faces
1172 for ( iE = 0; iE < NB_WALL_FACES; ++iE ) {
1173 if ( edgeIdVec[ BOTTOM_EDGE ] == botEdgeIdVec[ iE ] ) {
1174 botPcurves[ iE ] = sideFace->HorizPCurve( false, botF );
1175 topPcurves[ iE ] = sideFace->HorizPCurve( true, topF );
1180 // horizontal faces geometry
1182 SMESH_Block::TFace& tFace = myFace[ ID_BOT_FACE - ID_FirstF ];
1183 tFace.Set( ID_BOT_FACE, new BRepAdaptor_Surface( botF ), botPcurves, isForward );
1184 SMESH_Block::Insert( botF, ID_BOT_FACE, myShapeIDMap );
1187 SMESH_Block::TFace& tFace = myFace[ ID_TOP_FACE - ID_FirstF ];
1188 tFace.Set( ID_TOP_FACE, new BRepAdaptor_Surface( topF ), topPcurves, isForward );
1189 SMESH_Block::Insert( topF, ID_TOP_FACE, myShapeIDMap );
1192 // Fill map ShapeIndex to TParam2ColumnMap
1193 // ----------------------------------------
1195 list< TSideFace* > fList;
1196 list< TSideFace* >::iterator fListIt;
1197 fList.push_back( mySide );
1198 for ( fListIt = fList.begin(); fListIt != fList.end(); ++fListIt)
1200 int nb = (*fListIt)->NbComponents();
1201 for ( int i = 0; i < nb; ++i ) {
1202 if ( TSideFace* comp = (*fListIt)->GetComponent( i ))
1203 fList.push_back( comp );
1205 if ( TParam2ColumnMap* cols = (*fListIt)->GetColumns()) {
1206 // columns for a base edge
1207 int id = MeshDS()->ShapeToIndex( (*fListIt)->BaseEdge() );
1208 bool isForward = (*fListIt)->IsForward();
1209 myShapeIndex2ColumnMap[ id ] = make_pair( cols, isForward );
1211 // columns for vertices
1212 const SMDS_MeshNode* n0 = cols->begin()->second.front();
1213 id = n0->GetPosition()->GetShapeId();
1214 myShapeIndex2ColumnMap[ id ] = make_pair( cols, isForward );
1216 const SMDS_MeshNode* n1 = cols->rbegin()->second.front();
1217 id = n1->GetPosition()->GetShapeId();
1218 myShapeIndex2ColumnMap[ id ] = make_pair( cols, !isForward );
1222 // gp_XYZ testPar(0.25, 0.25, 0), testCoord;
1223 // if ( !FacePoint( ID_BOT_FACE, testPar, testCoord ))
1224 // RETURN_BAD_RESULT("TEST FacePoint() FAILED");
1225 // SHOWYXZ("IN TEST PARAM" , testPar);
1226 // SHOWYXZ("OUT TEST CORD" , testCoord);
1227 // if ( !ComputeParameters( testCoord, testPar , ID_BOT_FACE))
1228 // RETURN_BAD_RESULT("TEST ComputeParameters() FAILED");
1229 // SHOWYXZ("OUT TEST PARAM" , testPar);
1234 //================================================================================
1236 * \brief Return pointer to column of nodes
1237 * \param node - bottom node from which the returned column goes up
1238 * \retval const TNodeColumn* - the found column
1240 //================================================================================
1242 const TNodeColumn* StdMeshers_PrismAsBlock::GetNodeColumn(const SMDS_MeshNode* node) const
1244 int sID = node->GetPosition()->GetShapeId();
1246 map<int, pair< TParam2ColumnMap*, bool > >::const_iterator col_frw =
1247 myShapeIndex2ColumnMap.find( sID );
1248 if ( col_frw != myShapeIndex2ColumnMap.end() ) {
1249 const TParam2ColumnMap* cols = col_frw->second.first;
1250 TParam2ColumnIt u_col = cols->begin();
1251 for ( ; u_col != cols->end(); ++u_col )
1252 if ( u_col->second[ 0 ] == node )
1253 return & u_col->second;
1258 //================================================================================
1260 * \brief Check curve orientation of a bootom edge
1261 * \param meshDS - mesh DS
1262 * \param columnsMap - node columns map of side face
1263 * \param bottomEdge - the bootom edge
1264 * \param sideFaceID - side face in-block ID
1265 * \retval bool - true if orientation coinside with in-block froward orientation
1267 //================================================================================
1269 bool StdMeshers_PrismAsBlock::IsForwardEdge(SMESHDS_Mesh* meshDS,
1270 const TParam2ColumnMap& columnsMap,
1271 const TopoDS_Edge & bottomEdge,
1272 const int sideFaceID)
1274 bool isForward = false;
1275 if ( TAssocTool::IsClosedEdge( bottomEdge ))
1277 isForward = ( bottomEdge.Orientation() == TopAbs_FORWARD );
1281 const TNodeColumn& firstCol = columnsMap.begin()->second;
1282 const SMDS_MeshNode* bottomNode = firstCol[0];
1283 TopoDS_Shape firstVertex = SMESH_MesherHelper::GetSubShapeByNode( bottomNode, meshDS );
1284 isForward = ( firstVertex.IsSame( TopExp::FirstVertex( bottomEdge, true )));
1286 // on 2 of 4 sides first vertex is end
1287 if ( sideFaceID == ID_Fx1z || sideFaceID == ID_F0yz )
1288 isForward = !isForward;
1292 //================================================================================
1294 * \brief Find wall faces by bottom edges
1295 * \param mesh - the mesh
1296 * \param mainShape - the prism
1297 * \param bottomFace - the bottom face
1298 * \param bottomEdges - edges bounding the bottom face
1299 * \param wallFaces - faces list to fill in
1301 //================================================================================
1303 bool StdMeshers_PrismAsBlock::GetWallFaces( SMESH_Mesh* mesh,
1304 const TopoDS_Shape & mainShape,
1305 const TopoDS_Shape & bottomFace,
1306 const std::list< TopoDS_Edge >& bottomEdges,
1307 std::list< TopoDS_Face >& wallFaces)
1311 TopTools_IndexedMapOfShape faceMap;
1312 TopExp::MapShapes( mainShape, TopAbs_FACE, faceMap );
1314 list< TopoDS_Edge >::const_iterator edge = bottomEdges.begin();
1315 for ( ; edge != bottomEdges.end(); ++edge )
1317 TopTools_ListIteratorOfListOfShape ancestIt = mesh->GetAncestors( *edge );
1318 for ( ; ancestIt.More(); ancestIt.Next() )
1320 const TopoDS_Shape& ancestor = ancestIt.Value();
1321 if ( ancestor.ShapeType() == TopAbs_FACE && // face
1322 !bottomFace.IsSame( ancestor ) && // not bottom
1323 faceMap.FindIndex( ancestor )) // belongs to the prism
1325 wallFaces.push_back( TopoDS::Face( ancestor ));
1330 return ( wallFaces.size() == bottomEdges.size() );
1333 //================================================================================
1335 * \brief Constructor
1336 * \param faceID - in-block ID
1337 * \param face - geom face
1338 * \param columnsMap - map of node columns
1339 * \param first - first normalized param
1340 * \param last - last normalized param
1342 //================================================================================
1344 StdMeshers_PrismAsBlock::TSideFace::TSideFace(SMESH_MesherHelper* helper,
1346 const TopoDS_Face& face,
1347 const TopoDS_Edge& baseEdge,
1348 TParam2ColumnMap* columnsMap,
1352 myParamToColumnMap( columnsMap ),
1353 myBaseEdge( baseEdge ),
1356 mySurface.Initialize( face );
1357 myParams.resize( 1 );
1358 myParams[ 0 ] = make_pair( first, last );
1359 myIsForward = StdMeshers_PrismAsBlock::IsForwardEdge( myHelper->GetMeshDS(),
1360 *myParamToColumnMap,
1364 //================================================================================
1366 * \brief Constructor of complex side face
1368 //================================================================================
1370 StdMeshers_PrismAsBlock::TSideFace::
1371 TSideFace(const vector< TSideFace* >& components,
1372 const vector< pair< double, double> > & params)
1373 :myID( components[0] ? components[0]->myID : 0 ),
1374 myParamToColumnMap( 0 ),
1376 myIsForward( true ),
1377 myComponents( components ),
1378 myHelper( components[0] ? components[0]->myHelper : 0 )
1380 //================================================================================
1382 * \brief Copy constructor
1383 * \param other - other side
1385 //================================================================================
1387 StdMeshers_PrismAsBlock::TSideFace::TSideFace( const TSideFace& other )
1390 mySurface = other.mySurface;
1391 myBaseEdge = other.myBaseEdge;
1392 myParams = other.myParams;
1393 myIsForward = other.myIsForward;
1394 myHelper = other.myHelper;
1395 myParamToColumnMap = other.myParamToColumnMap;
1397 myComponents.resize( other.myComponents.size());
1398 for (int i = 0 ; i < myComponents.size(); ++i )
1399 myComponents[ i ] = new TSideFace( *other.myComponents[ i ]);
1402 //================================================================================
1404 * \brief Deletes myComponents
1406 //================================================================================
1408 StdMeshers_PrismAsBlock::TSideFace::~TSideFace()
1410 for (int i = 0 ; i < myComponents.size(); ++i )
1411 if ( myComponents[ i ] )
1412 delete myComponents[ i ];
1415 //================================================================================
1417 * \brief Return geometry of the vertical curve
1418 * \param isMax - true means curve located closer to (1,1,1) block point
1419 * \retval Adaptor3d_Curve* - curve adaptor
1421 //================================================================================
1423 Adaptor3d_Curve* StdMeshers_PrismAsBlock::TSideFace::VertiCurve(const bool isMax) const
1425 if ( !myComponents.empty() ) {
1427 return myComponents.back()->VertiCurve(isMax);
1429 return myComponents.front()->VertiCurve(isMax);
1431 double f = myParams[0].first, l = myParams[0].second;
1432 if ( !myIsForward ) std::swap( f, l );
1433 return new TVerticalEdgeAdaptor( myParamToColumnMap, isMax ? l : f );
1436 //================================================================================
1438 * \brief Return geometry of the top or bottom curve
1440 * \retval Adaptor3d_Curve* -
1442 //================================================================================
1444 Adaptor3d_Curve* StdMeshers_PrismAsBlock::TSideFace::HorizCurve(const bool isTop) const
1446 return new THorizontalEdgeAdaptor( this, isTop );
1449 //================================================================================
1451 * \brief Return pcurves
1452 * \param pcurv - array of 4 pcurves
1453 * \retval bool - is a success
1455 //================================================================================
1457 bool StdMeshers_PrismAsBlock::TSideFace::GetPCurves(Adaptor2d_Curve2d* pcurv[4]) const
1459 int iEdge[ 4 ] = { BOTTOM_EDGE, TOP_EDGE, V0_EDGE, V1_EDGE };
1461 for ( int i = 0 ; i < 4 ; ++i ) {
1462 Handle(Geom2d_Line) line;
1463 switch ( iEdge[ i ] ) {
1465 line = new Geom2d_Line( gp_Pnt2d( 0, 1 ), gp::DX2d() ); break;
1467 line = new Geom2d_Line( gp::Origin2d(), gp::DX2d() ); break;
1469 line = new Geom2d_Line( gp::Origin2d(), gp::DY2d() ); break;
1471 line = new Geom2d_Line( gp_Pnt2d( 1, 0 ), gp::DY2d() ); break;
1473 pcurv[ i ] = new Geom2dAdaptor_Curve( line, 0, 1 );
1478 //================================================================================
1480 * \brief Returns geometry of pcurve on a horizontal face
1481 * \param isTop - is top or bottom face
1482 * \param horFace - a horizontal face
1483 * \retval Adaptor2d_Curve2d* - curve adaptor
1485 //================================================================================
1488 StdMeshers_PrismAsBlock::TSideFace::HorizPCurve(const bool isTop,
1489 const TopoDS_Face& horFace) const
1491 return new TPCurveOnHorFaceAdaptor( this, isTop, horFace );
1494 //================================================================================
1496 * \brief Return a component corresponding to parameter
1497 * \param U - parameter along a horizontal size
1498 * \param localU - parameter along a horizontal size of a component
1499 * \retval TSideFace* - found component
1501 //================================================================================
1503 StdMeshers_PrismAsBlock::TSideFace*
1504 StdMeshers_PrismAsBlock::TSideFace::GetComponent(const double U,double & localU) const
1507 if ( myComponents.empty() )
1508 return const_cast<TSideFace*>( this );
1511 for ( i = 0; i < myComponents.size(); ++i )
1512 if ( U < myParams[ i ].second )
1514 if ( i >= myComponents.size() )
1515 i = myComponents.size() - 1;
1517 double f = myParams[ i ].first, l = myParams[ i ].second;
1518 localU = ( U - f ) / ( l - f );
1519 return myComponents[ i ];
1522 //================================================================================
1524 * \brief Find node columns for a parameter
1525 * \param U - parameter along a horizontal edge
1526 * \param col1 - the 1st found column
1527 * \param col2 - the 2nd found column
1528 * \retval r - normalized position of U between the found columns
1530 //================================================================================
1532 double StdMeshers_PrismAsBlock::TSideFace::GetColumns(const double U,
1533 TParam2ColumnIt & col1,
1534 TParam2ColumnIt & col2) const
1536 double u = U, r = 0;
1537 if ( !myComponents.empty() ) {
1538 TSideFace * comp = GetComponent(U,u);
1539 return comp->GetColumns( u, col1, col2 );
1544 double f = myParams[0].first, l = myParams[0].second;
1545 u = f + u * ( l - f );
1547 col1 = col2 = getColumn( myParamToColumnMap, u );
1548 if ( ++col2 == myParamToColumnMap->end() ) {
1553 // if ( !myIsForward )
1554 // std::swap( col1, col2 );
1555 double uf = col1->first;
1556 double ul = col2->first;
1557 r = ( u - uf ) / ( ul - uf );
1562 //================================================================================
1564 * \brief Return coordinates by normalized params
1565 * \param U - horizontal param
1566 * \param V - vertical param
1567 * \retval gp_Pnt - result point
1569 //================================================================================
1571 gp_Pnt StdMeshers_PrismAsBlock::TSideFace::Value(const Standard_Real U,
1572 const Standard_Real V) const
1575 if ( !myComponents.empty() ) {
1576 TSideFace * comp = GetComponent(U,u);
1577 return comp->Value( u, V );
1580 TParam2ColumnIt u_col1, u_col2;
1581 double vR, hR = GetColumns( U, u_col1, u_col2 );
1583 const SMDS_MeshNode* n1 = 0;
1584 const SMDS_MeshNode* n2 = 0;
1585 const SMDS_MeshNode* n3 = 0;
1586 const SMDS_MeshNode* n4 = 0;
1589 vR = getRAndNodes( & u_col1->second, V, n1, n2 );
1590 vR = getRAndNodes( & u_col2->second, V, n3, n4 );
1592 gp_XY uv1 = myHelper->GetNodeUV( mySurface.Face(), n1, n4);
1593 gp_XY uv2 = myHelper->GetNodeUV( mySurface.Face(), n2, n3);
1594 gp_XY uv12 = uv1 * ( 1 - vR ) + uv2 * vR;
1596 gp_XY uv3 = myHelper->GetNodeUV( mySurface.Face(), n3, n2);
1597 gp_XY uv4 = myHelper->GetNodeUV( mySurface.Face(), n4, n1);
1598 gp_XY uv34 = uv3 * ( 1 - vR ) + uv4 * vR;
1600 gp_XY uv = uv12 * ( 1 - hR ) + uv34 * hR;
1602 return mySurface.Value( uv.X(), uv.Y() );
1606 //================================================================================
1608 * \brief Return boundary edge
1609 * \param edge - edge index
1610 * \retval TopoDS_Edge - found edge
1612 //================================================================================
1614 TopoDS_Edge StdMeshers_PrismAsBlock::TSideFace::GetEdge(const int iEdge) const
1616 if ( !myComponents.empty() ) {
1618 case V0_EDGE : return myComponents.front()->GetEdge( iEdge );
1619 case V1_EDGE : return myComponents.back() ->GetEdge( iEdge );
1620 default: return TopoDS_Edge();
1624 const SMDS_MeshNode* node = 0;
1625 SMESHDS_Mesh * meshDS = myHelper->GetMesh()->GetMeshDS();
1626 TNodeColumn* column;
1631 column = & (( ++myParamToColumnMap->begin())->second );
1632 node = ( iEdge == TOP_EDGE ) ? column->back() : column->front();
1633 edge = myHelper->GetSubShapeByNode ( node, meshDS );
1634 if ( edge.ShapeType() == TopAbs_VERTEX ) {
1635 column = & ( myParamToColumnMap->begin()->second );
1636 node = ( iEdge == TOP_EDGE ) ? column->back() : column->front();
1641 bool back = ( iEdge == V1_EDGE );
1642 if ( !myIsForward ) back = !back;
1644 column = & ( myParamToColumnMap->rbegin()->second );
1646 column = & ( myParamToColumnMap->begin()->second );
1647 if ( column->size() > 0 )
1648 edge = myHelper->GetSubShapeByNode( (*column)[ 1 ], meshDS );
1649 if ( edge.IsNull() || edge.ShapeType() == TopAbs_VERTEX )
1650 node = column->front();
1655 if ( !edge.IsNull() && edge.ShapeType() == TopAbs_EDGE )
1656 return TopoDS::Edge( edge );
1658 // find edge by 2 vertices
1659 TopoDS_Shape V1 = edge;
1660 TopoDS_Shape V2 = myHelper->GetSubShapeByNode( node, meshDS );
1661 if ( V2.ShapeType() == TopAbs_VERTEX && !V2.IsSame( V1 ))
1663 TopTools_ListIteratorOfListOfShape ancestIt =
1664 myHelper->GetMesh()->GetAncestors( V1 );
1665 for ( ; ancestIt.More(); ancestIt.Next() )
1667 const TopoDS_Shape & ancestor = ancestIt.Value();
1668 if ( ancestor.ShapeType() == TopAbs_EDGE )
1669 for ( TopExp_Explorer e( ancestor, TopAbs_VERTEX ); e.More(); e.Next() )
1670 if ( V2.IsSame( e.Current() ))
1671 return TopoDS::Edge( ancestor );
1674 return TopoDS_Edge();
1677 //================================================================================
1679 * \brief Fill block subshapes
1680 * \param shapeMap - map to fill in
1681 * \retval int - nb inserted subshapes
1683 //================================================================================
1685 int StdMeshers_PrismAsBlock::TSideFace::InsertSubShapes(TBlockShapes& shapeMap) const
1690 vector< int > edgeIdVec;
1691 SMESH_Block::GetFaceEdgesIDs( myID, edgeIdVec );
1693 for ( int i = BOTTOM_EDGE; i <=V1_EDGE ; ++i ) {
1694 TopoDS_Edge e = GetEdge( i );
1695 if ( !e.IsNull() ) {
1696 nbInserted += SMESH_Block::Insert( e, edgeIdVec[ i ], shapeMap);
1700 // Insert corner vertices
1702 TParam2ColumnIt col1, col2 ;
1703 vector< int > vertIdVec;
1706 SMESH_Block::GetEdgeVertexIDs( edgeIdVec[ V0_EDGE ], vertIdVec);
1707 GetColumns(0, col1, col2 );
1708 const SMDS_MeshNode* node0 = col1->second.front();
1709 const SMDS_MeshNode* node1 = col1->second.back();
1710 TopoDS_Shape v0 = myHelper->GetSubShapeByNode( node0, myHelper->GetMeshDS());
1711 TopoDS_Shape v1 = myHelper->GetSubShapeByNode( node1, myHelper->GetMeshDS());
1712 if ( v0.ShapeType() == TopAbs_VERTEX ) {
1713 nbInserted += SMESH_Block::Insert( v0, vertIdVec[ 0 ], shapeMap);
1715 if ( v1.ShapeType() == TopAbs_VERTEX ) {
1716 nbInserted += SMESH_Block::Insert( v1, vertIdVec[ 1 ], shapeMap);
1720 SMESH_Block::GetEdgeVertexIDs( edgeIdVec[ V1_EDGE ], vertIdVec);
1721 GetColumns(1, col1, col2 );
1722 node0 = col2->second.front();
1723 node1 = col2->second.back();
1724 v0 = myHelper->GetSubShapeByNode( node0, myHelper->GetMeshDS());
1725 v1 = myHelper->GetSubShapeByNode( node1, myHelper->GetMeshDS());
1726 if ( v0.ShapeType() == TopAbs_VERTEX ) {
1727 nbInserted += SMESH_Block::Insert( v0, vertIdVec[ 0 ], shapeMap);
1729 if ( v1.ShapeType() == TopAbs_VERTEX ) {
1730 nbInserted += SMESH_Block::Insert( v1, vertIdVec[ 1 ], shapeMap);
1733 // TopoDS_Vertex V0, V1, Vcom;
1734 // TopExp::Vertices( myBaseEdge, V0, V1, true );
1735 // if ( !myIsForward ) std::swap( V0, V1 );
1737 // // bottom vertex IDs
1738 // SMESH_Block::GetEdgeVertexIDs( edgeIdVec[ _u0 ], vertIdVec);
1739 // SMESH_Block::Insert( V0, vertIdVec[ 0 ], shapeMap);
1740 // SMESH_Block::Insert( V1, vertIdVec[ 1 ], shapeMap);
1742 // TopoDS_Edge sideEdge = GetEdge( V0_EDGE );
1743 // if ( sideEdge.IsNull() || !TopExp::CommonVertex( botEdge, sideEdge, Vcom ))
1746 // // insert one side edge
1748 // if ( Vcom.IsSame( V0 )) edgeID = edgeIdVec[ _v0 ];
1749 // else edgeID = edgeIdVec[ _v1 ];
1750 // SMESH_Block::Insert( sideEdge, edgeID, shapeMap);
1752 // // top vertex of the side edge
1753 // SMESH_Block::GetEdgeVertexIDs( edgeID, vertIdVec);
1754 // TopoDS_Vertex Vtop = TopExp::FirstVertex( sideEdge );
1755 // if ( Vcom.IsSame( Vtop ))
1756 // Vtop = TopExp::LastVertex( sideEdge );
1757 // SMESH_Block::Insert( Vtop, vertIdVec[ 1 ], shapeMap);
1759 // // other side edge
1760 // sideEdge = GetEdge( V1_EDGE );
1761 // if ( sideEdge.IsNull() )
1763 // if ( edgeID = edgeIdVec[ _v1 ]) edgeID = edgeIdVec[ _v0 ];
1764 // else edgeID = edgeIdVec[ _v1 ];
1765 // SMESH_Block::Insert( sideEdge, edgeID, shapeMap);
1768 // TopoDS_Edge topEdge = GetEdge( TOP_EDGE );
1769 // SMESH_Block::Insert( topEdge, edgeIdVec[ _u1 ], shapeMap);
1771 // // top vertex of the other side edge
1772 // if ( !TopExp::CommonVertex( topEdge, sideEdge, Vcom ))
1774 // SMESH_Block::GetEdgeVertexIDs( edgeID, vertIdVec );
1775 // SMESH_Block::Insert( Vcom, vertIdVec[ 1 ], shapeMap);
1780 //================================================================================
1782 * \brief Creates TVerticalEdgeAdaptor
1783 * \param columnsMap - node column map
1784 * \param parameter - normalized parameter
1786 //================================================================================
1788 StdMeshers_PrismAsBlock::TVerticalEdgeAdaptor::
1789 TVerticalEdgeAdaptor( const TParam2ColumnMap* columnsMap, const double parameter)
1791 myNodeColumn = & getColumn( columnsMap, parameter )->second;
1794 //================================================================================
1796 * \brief Return coordinates for the given normalized parameter
1797 * \param U - normalized parameter
1798 * \retval gp_Pnt - coordinates
1800 //================================================================================
1802 gp_Pnt StdMeshers_PrismAsBlock::TVerticalEdgeAdaptor::Value(const Standard_Real U) const
1804 const SMDS_MeshNode* n1;
1805 const SMDS_MeshNode* n2;
1806 double r = getRAndNodes( myNodeColumn, U, n1, n2 );
1807 return gpXYZ(n1) * ( 1 - r ) + gpXYZ(n2) * r;
1810 //================================================================================
1812 * \brief Return coordinates for the given normalized parameter
1813 * \param U - normalized parameter
1814 * \retval gp_Pnt - coordinates
1816 //================================================================================
1818 gp_Pnt StdMeshers_PrismAsBlock::THorizontalEdgeAdaptor::Value(const Standard_Real U) const
1820 return mySide->TSideFace::Value( U, myV );
1823 //================================================================================
1825 * \brief Return UV on pcurve for the given normalized parameter
1826 * \param U - normalized parameter
1827 * \retval gp_Pnt - coordinates
1829 //================================================================================
1831 gp_Pnt2d StdMeshers_PrismAsBlock::TPCurveOnHorFaceAdaptor::Value(const Standard_Real U) const
1833 TParam2ColumnIt u_col1, u_col2;
1834 double r = mySide->GetColumns( U, u_col1, u_col2 );
1835 gp_XY uv1 = mySide->GetNodeUV( myFace, u_col1->second[ myZ ]);
1836 gp_XY uv2 = mySide->GetNodeUV( myFace, u_col2->second[ myZ ]);
1837 return uv1 * ( 1 - r ) + uv2 * r;