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->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 // analyse face submeshes
727 const map< int, SMESH_subMesh * >& subSM = mainSubMesh->DependsOn();
728 map< int, SMESH_subMesh * >::const_iterator i_subSM = subSM.begin();
729 for ( ; i_subSM != subSM.end(); ++i_subSM )
731 SMESH_subMesh* sm = i_subSM->second;
732 const TopoDS_Shape& face = sm->GetSubShape();
733 if ( face.ShapeType() != TopAbs_FACE )
737 // is quadrangle face?
738 list< TopoDS_Edge > orderedEdges;
739 list< int > nbEdgesInWires;
741 int nbWires = GetOrderedEdges( TopoDS::Face( face ),
742 V000, orderedEdges, nbEdgesInWires );
743 if ( nbWires != 1 || nbEdgesInWires.front() != 4 )
744 notQuadGeomSubMesh.push_back( sm );
746 // look for not quadrangle mesh elements
747 if ( SMESHDS_SubMesh* smDS = sm->GetSubMeshDS() ) {
748 bool hasNotQuad = false;
749 SMDS_ElemIteratorPtr eIt = smDS->GetElements();
750 while ( eIt->more() && !hasNotQuad ) {
751 const SMDS_MeshElement* elem = eIt->next();
752 if ( elem->GetType() == SMDSAbs_Face ) {
753 int nbNodes = elem->NbNodes();
754 if ( elem->IsQuadratic() )
756 hasNotQuad = ( nbNodes != 4 );
760 notQuadElemSubMesh.push_back( sm );
763 RETURN_BAD_RESULT("not meshed face");
765 // check if a quadrangle face is meshed with a quadranglar grid
766 if ( notQuadGeomSubMesh.back() != sm &&
767 notQuadElemSubMesh.back() != sm )
769 // count nb edges on face sides
770 vector< int > nbEdges;
771 nbEdges.reserve( nbEdgesInWires.front() );
772 for ( list< TopoDS_Edge >::iterator edge = orderedEdges.begin();
773 edge != orderedEdges.end(); ++edge )
775 if ( SMESHDS_SubMesh* smDS = meshDS->MeshElements( *edge ))
776 nbEdges.push_back ( smDS->NbElements() );
778 nbEdges.push_back ( 0 );
780 int nbQuads = sm->GetSubMeshDS()->NbElements();
781 if ( nbEdges[0] * nbEdges[1] != nbQuads ||
782 nbEdges[0] != nbEdges[2] ||
783 nbEdges[1] != nbEdges[3] )
784 notQuadElemSubMesh.push_back( sm );
788 // ----------------------------------------------------------------------
789 // Analyse faces mesh and topology: choose the bottom submesh.
790 // If there are not quadrangle geom faces, they are top and bottom ones.
791 // Not quadrangle geom faces must be only on top and bottom.
792 // ----------------------------------------------------------------------
794 SMESH_subMesh * botSM = 0;
795 SMESH_subMesh * topSM = 0;
797 int nbNotQuad = notQuadGeomSubMesh.size();
798 int nbNotQuadMeshed = notQuadElemSubMesh.size();
799 bool hasNotQuad = ( nbNotQuad || nbNotQuadMeshed );
802 if ( nbNotQuad > 0 && nbNotQuad != 2 )
803 RETURN_BAD_RESULT("Wrong shape geometry");
804 if ( nbNotQuadMeshed > 2 )
805 RETURN_BAD_RESULT("More then 2 faces meshed with not quadrangle elements");
807 // get found submeshes
810 if ( nbNotQuadMeshed > 0 ) botSM = notQuadElemSubMesh.front();
811 else botSM = notQuadGeomSubMesh.front();
812 if ( nbNotQuadMeshed > 1 ) topSM = notQuadElemSubMesh.back();
813 else if ( nbNotQuad > 1 ) topSM = notQuadGeomSubMesh.back();
815 // detect other bad cases
816 if ( nbNotQuad == 2 && nbNotQuadMeshed > 0 ) {
818 if ( nbNotQuadMeshed == 1 )
819 ok = ( find( notQuadGeomSubMesh.begin(),
820 notQuadGeomSubMesh.end(), botSM ) != notQuadGeomSubMesh.end() );
822 ok = ( notQuadGeomSubMesh == notQuadElemSubMesh );
824 RETURN_BAD_RESULT("Side face meshed with not quadrangle elements");
827 myNotQuadOnTop = ( nbNotQuadMeshed > 1 );
829 // ----------------------------------------------------------
831 if ( nbNotQuad == 0 ) // Standard block of 6 quadrangle faces ?
833 // SMESH_Block will perform geometry analysis, we need just to find 2
834 // connected vertices on top and bottom
836 TopoDS_Vertex Vbot, Vtop;
837 if ( nbNotQuadMeshed > 0 ) // Look for vertices
839 TopTools_IndexedMapOfShape edgeMap;
840 TopExp::MapShapes( botSM->GetSubShape(), TopAbs_EDGE, edgeMap );
841 // vertex 1 is any vertex of the bottom face
842 Vbot = TopExp::FirstVertex( TopoDS::Edge( edgeMap( 1 )));
843 // vertex 2 is end vertex of edge sharing Vbot and not belonging to the bottom face
844 TopTools_ListIteratorOfListOfShape ancestIt = Mesh()->GetAncestors( Vbot );
845 for ( ; Vtop.IsNull() && ancestIt.More(); ancestIt.Next() )
847 const TopoDS_Shape & ancestor = ancestIt.Value();
848 if ( ancestor.ShapeType() == TopAbs_EDGE && !edgeMap.FindIndex( ancestor ))
850 TopoDS_Vertex V1, V2;
851 TopExp::Vertices( TopoDS::Edge( ancestor ), V1, V2);
852 if ( Vbot.IsSame ( V1 )) Vtop = V2;
853 else if ( Vbot.IsSame ( V2 )) Vtop = V1;
854 // check that Vtop belongs to shape3D
855 TopExp_Explorer exp( shape3D, TopAbs_VERTEX );
856 for ( ; exp.More(); exp.Next() )
857 if ( Vtop.IsSame( exp.Current() ))
864 // get shell from shape3D
866 TopExp_Explorer exp( shape3D, TopAbs_SHELL );
868 for ( ; exp.More(); exp.Next(), ++nbShell )
869 shell = TopoDS::Shell( exp.Current() );
870 // if ( nbShell != 1 )
871 // RETURN_BAD_RESULT("There must be 1 shell in the block");
873 // Load geometry in SMESH_Block
874 if ( !SMESH_Block::FindBlockShapes( shell, Vbot, Vtop, myShapeIDMap )) {
876 RETURN_BAD_RESULT("Can not detect top and bottom");
879 if ( !botSM ) botSM = Mesh()->GetSubMeshContaining( myShapeIDMap( ID_BOT_FACE ));
880 if ( !topSM ) topSM = Mesh()->GetSubMeshContaining( myShapeIDMap( ID_TOP_FACE ));
883 } // end Standard block of 6 quadrangle faces
884 // --------------------------------------------------------
886 // Here the top and bottom faces are found
887 if ( nbNotQuadMeshed == 2 ) // roughly check correspondence of horiz meshes
889 // SMESHDS_SubMesh* topSMDS = topSM->GetSubMeshDS();
890 // SMESHDS_SubMesh* botSMDS = botSM->GetSubMeshDS();
891 // if ( topSMDS->NbNodes() != botSMDS->NbNodes() ||
892 // topSMDS->NbElements() != botSMDS->NbElements() )
893 // RETURN_BAD_RESULT("Top mesh doesn't correspond to bottom one");
896 // ---------------------------------------------------------
897 // If there are not quadrangle geom faces, we emulate
898 // a block of 6 quadrangle faces.
899 // Load SMESH_Block with faces and edges geometry
900 // ---------------------------------------------------------
903 // find vertex 000 - the one with smallest coordinates (for easy DEBUG :-)
905 double minVal = DBL_MAX, minX, val;
906 for ( TopExp_Explorer exp( botSM->GetSubShape(), TopAbs_VERTEX );
907 exp.More(); exp.Next() )
909 const TopoDS_Vertex& v = TopoDS::Vertex( exp.Current() );
910 gp_Pnt P = BRep_Tool::Pnt( v );
911 val = P.X() + P.Y() + P.Z();
912 if ( val < minVal || ( val == minVal && P.X() < minX )) {
919 // Get ordered bottom edges
920 list< TopoDS_Edge > orderedEdges;
921 list< int > nbVertexInWires;
922 SMESH_Block::GetOrderedEdges( TopoDS::Face( botSM->GetSubShape().Reversed() ),
923 V000, orderedEdges, nbVertexInWires );
924 // if ( nbVertexInWires.size() != 1 )
925 // RETURN_BAD_RESULT("Wrong prism geometry");
927 // Get Wall faces corresponding to the ordered bottom edges
928 list< TopoDS_Face > wallFaces;
929 if ( !GetWallFaces( Mesh(), shape3D, botSM->GetSubShape(), orderedEdges, wallFaces))
930 RETURN_BAD_RESULT("GetWallFaces() failed");
932 // Find columns of wall nodes and calculate edges' lengths
933 // --------------------------------------------------------
935 myParam2ColumnMaps.clear();
936 myParam2ColumnMaps.resize( orderedEdges.size() ); // total nb edges
938 int iE, nbEdges = nbVertexInWires.front(); // nb outer edges
939 vector< double > edgeLength( nbEdges );
940 map< double, int > len2edgeMap;
942 list< TopoDS_Edge >::iterator edgeIt = orderedEdges.begin();
943 list< TopoDS_Face >::iterator faceIt = wallFaces.begin();
944 for ( iE = 0; iE < nbEdges; ++edgeIt, ++faceIt )
946 TParam2ColumnMap & faceColumns = myParam2ColumnMaps[ iE ];
947 if ( !myHelper->LoadNodeColumns( faceColumns, *faceIt, *edgeIt, meshDS ))
948 RETURN_BAD_RESULT("SMESH_MesherHelper::LoadNodeColumns() failed");
950 SHOWYXZ("\np1 F "<<iE, gpXYZ(faceColumns.begin()->second.front() ));
951 SHOWYXZ("p2 F "<<iE, gpXYZ(faceColumns.rbegin()->second.front() ));
952 SHOWYXZ("V First "<<iE, BRep_Tool::Pnt( TopExp::FirstVertex(*edgeIt,true )));
954 edgeLength[ iE ] = SMESH_Algo::EdgeLength( *edgeIt );
956 if ( nbEdges < NB_WALL_FACES ) // fill map used to split faces
958 SMESHDS_SubMesh* smDS = meshDS->MeshElements( *edgeIt);
960 RETURN_BAD_RESULT("Null submesh on a bottom edge");
961 // assure length uniqueness
962 edgeLength[ iE ] *= smDS->NbNodes() + edgeLength[ iE ] / ( 1000 + iE );
963 len2edgeMap[ edgeLength[ iE ]] = iE;
967 // Load columns of internal edges (forming holes)
968 // and fill map ShapeIndex to TParam2ColumnMap for them
969 for ( ; edgeIt != orderedEdges.end() ; ++edgeIt, ++faceIt )
971 TParam2ColumnMap & faceColumns = myParam2ColumnMaps[ iE ];
972 if ( !myHelper->LoadNodeColumns( faceColumns, *faceIt, *edgeIt, meshDS ))
973 RETURN_BAD_RESULT("SMESH_MesherHelper::LoadNodeColumns() failed");
975 int id = MeshDS()->ShapeToIndex( *edgeIt );
976 bool isForward = true; // meaningless for intenal wires
977 myShapeIndex2ColumnMap[ id ] = make_pair( & faceColumns, isForward );
978 // columns for vertices
980 const SMDS_MeshNode* n0 = faceColumns.begin()->second.front();
981 id = n0->GetPosition()->GetShapeId();
982 myShapeIndex2ColumnMap[ id ] = make_pair( & faceColumns, isForward );
984 const SMDS_MeshNode* n1 = faceColumns.rbegin()->second.front();
985 id = n1->GetPosition()->GetShapeId();
986 myShapeIndex2ColumnMap[ id ] = make_pair( & faceColumns, isForward );
987 // SHOWYXZ("\np1 F "<<iE, gpXYZ(faceColumns.begin()->second.front() ));
988 // SHOWYXZ("p2 F "<<iE, gpXYZ(faceColumns.rbegin()->second.front() ));
989 // SHOWYXZ("V First "<<iE, BRep_Tool::Pnt( TopExp::FirstVertex(*edgeIt,true )));
993 // Create 4 wall faces of a block
994 // -------------------------------
996 if ( nbEdges <= NB_WALL_FACES ) // ************* Split faces if necessary
998 map< int, int > iE2nbSplit;
999 if ( nbEdges != NB_WALL_FACES ) // define how to split
1001 if ( len2edgeMap.size() != nbEdges )
1002 RETURN_BAD_RESULT("Uniqueness of edge lengths not assured");
1003 map< double, int >::reverse_iterator maxLen_i = len2edgeMap.rbegin();
1004 map< double, int >::reverse_iterator midLen_i = ++len2edgeMap.rbegin();
1005 double maxLen = maxLen_i->first;
1006 double midLen = ( len2edgeMap.size() == 1 ) ? 0 : midLen_i->first;
1007 switch ( nbEdges ) {
1008 case 1: // 0-th edge is split into 4 parts
1009 iE2nbSplit.insert( make_pair( 0, 4 )); break;
1010 case 2: // either the longest edge is split into 3 parts, or both edges into halves
1011 if ( maxLen / 3 > midLen / 2 ) {
1012 iE2nbSplit.insert( make_pair( maxLen_i->second, 3 ));
1015 iE2nbSplit.insert( make_pair( maxLen_i->second, 2 ));
1016 iE2nbSplit.insert( make_pair( midLen_i->second, 2 ));
1020 // split longest into halves
1021 iE2nbSplit.insert( make_pair( maxLen_i->second, 2 ));
1024 // Create TSideFace's
1025 faceIt = wallFaces.begin();
1026 edgeIt = orderedEdges.begin();
1028 for ( iE = 0; iE < nbEdges; ++edgeIt, ++faceIt )
1031 map< int, int >::iterator i_nb = iE2nbSplit.find( iE );
1032 if ( i_nb != iE2nbSplit.end() ) {
1034 int nbSplit = i_nb->second;
1035 vector< double > params;
1036 splitParams( nbSplit, &myParam2ColumnMaps[ iE ], params );
1037 bool isForward = ( edgeIt->Orientation() == TopAbs_FORWARD );
1038 for ( int i = 0; i < nbSplit; ++i ) {
1039 double f = ( isForward ? params[ i ] : params[ nbSplit - i-1 ]);
1040 double l = ( isForward ? params[ i+1 ] : params[ nbSplit - i ]);
1041 TSideFace* comp = new TSideFace( myHelper, wallFaceIds[ iSide ],
1043 &myParam2ColumnMaps[ iE ], f, l );
1044 mySide->SetComponent( iSide++, comp );
1048 TSideFace* comp = new TSideFace( myHelper, wallFaceIds[ iSide ],
1050 &myParam2ColumnMaps[ iE ]);
1051 mySide->SetComponent( iSide++, comp );
1056 else { // **************************** Unite faces
1058 // unite first faces
1059 int nbExraFaces = nbEdges - 3;
1061 double u0 = 0, sumLen = 0;
1062 for ( iE = 0; iE < nbExraFaces; ++iE )
1063 sumLen += edgeLength[ iE ];
1065 vector< TSideFace* > components( nbExraFaces );
1066 vector< pair< double, double> > params( nbExraFaces );
1067 faceIt = wallFaces.begin();
1068 edgeIt = orderedEdges.begin();
1069 for ( iE = 0; iE < nbExraFaces; ++edgeIt, ++faceIt )
1071 components[ iE ] = new TSideFace( myHelper, wallFaceIds[ iSide ],
1073 &myParam2ColumnMaps[ iE ]);
1074 double u1 = u0 + edgeLength[ iE ] / sumLen;
1075 params[ iE ] = make_pair( u0 , u1 );
1079 mySide->SetComponent( iSide++, new TSideFace( components, params ));
1081 // fill the rest faces
1082 for ( ; iE < nbEdges; ++faceIt, ++edgeIt )
1084 TSideFace* comp = new TSideFace( myHelper, wallFaceIds[ iSide ],
1086 &myParam2ColumnMaps[ iE ]);
1087 mySide->SetComponent( iSide++, comp );
1093 // Fill geometry fields of SMESH_Block
1094 // ------------------------------------
1096 TopoDS_Face botF = TopoDS::Face( botSM->GetSubShape() );
1097 TopoDS_Face topF = TopoDS::Face( topSM->GetSubShape() );
1099 vector< int > botEdgeIdVec;
1100 SMESH_Block::GetFaceEdgesIDs( ID_BOT_FACE, botEdgeIdVec );
1102 bool isForward[NB_WALL_FACES] = { true, true, true, true };
1103 Adaptor2d_Curve2d* botPcurves[NB_WALL_FACES];
1104 Adaptor2d_Curve2d* topPcurves[NB_WALL_FACES];
1106 for ( int iF = 0; iF < NB_WALL_FACES; ++iF )
1108 TSideFace * sideFace = mySide->GetComponent( iF );
1110 RETURN_BAD_RESULT("NULL TSideFace");
1111 int fID = sideFace->FaceID();
1113 // fill myShapeIDMap
1114 if ( sideFace->InsertSubShapes( myShapeIDMap ) != 8 &&
1115 !sideFace->IsComplex())
1116 MESSAGE( ": Warning : InsertSubShapes() < 8 on side " << iF );
1118 // side faces geometry
1119 Adaptor2d_Curve2d* pcurves[NB_WALL_FACES];
1120 if ( !sideFace->GetPCurves( pcurves ))
1121 RETURN_BAD_RESULT("TSideFace::GetPCurves() failed");
1123 SMESH_Block::TFace& tFace = myFace[ fID - ID_FirstF ];
1124 tFace.Set( fID, sideFace->Surface(), pcurves, isForward );
1126 SHOWYXZ( endl<<"F "<< iF << " id " << fID << " FRW " << sideFace->IsForward(), );
1127 // edges 3D geometry
1128 vector< int > edgeIdVec;
1129 SMESH_Block::GetFaceEdgesIDs( fID, edgeIdVec );
1130 for ( int isMax = 0; isMax < 2; ++isMax ) {
1132 int eID = edgeIdVec[ isMax ];
1133 SMESH_Block::TEdge& tEdge = myEdge[ eID - ID_FirstE ];
1134 tEdge.Set( eID, sideFace->HorizCurve(isMax), true);
1135 SHOWYXZ(eID<<" HOR"<<isMax<<"(0)", sideFace->HorizCurve(isMax)->Value(0));
1136 SHOWYXZ(eID<<" HOR"<<isMax<<"(1)", sideFace->HorizCurve(isMax)->Value(1));
1139 int eID = edgeIdVec[ isMax+2 ];
1140 SMESH_Block::TEdge& tEdge = myEdge[ eID - ID_FirstE ];
1141 tEdge.Set( eID, sideFace->VertiCurve(isMax), true);
1142 SHOWYXZ(eID<<" VER"<<isMax<<"(0)", sideFace->VertiCurve(isMax)->Value(0));
1143 SHOWYXZ(eID<<" VER"<<isMax<<"(1)", sideFace->VertiCurve(isMax)->Value(1));
1146 vector< int > vertexIdVec;
1147 SMESH_Block::GetEdgeVertexIDs( eID, vertexIdVec );
1148 myPnt[ vertexIdVec[0] - ID_FirstV ] = tEdge.GetCurve()->Value(0).XYZ();
1149 myPnt[ vertexIdVec[1] - ID_FirstV ] = tEdge.GetCurve()->Value(1).XYZ();
1152 // pcurves on horizontal faces
1153 for ( iE = 0; iE < NB_WALL_FACES; ++iE ) {
1154 if ( edgeIdVec[ BOTTOM_EDGE ] == botEdgeIdVec[ iE ] ) {
1155 botPcurves[ iE ] = sideFace->HorizPCurve( false, botF );
1156 topPcurves[ iE ] = sideFace->HorizPCurve( true, topF );
1161 // horizontal faces geometry
1163 SMESH_Block::TFace& tFace = myFace[ ID_BOT_FACE - ID_FirstF ];
1164 tFace.Set( ID_BOT_FACE, new BRepAdaptor_Surface( botF ), botPcurves, isForward );
1165 SMESH_Block::Insert( botF, ID_BOT_FACE, myShapeIDMap );
1168 SMESH_Block::TFace& tFace = myFace[ ID_TOP_FACE - ID_FirstF ];
1169 tFace.Set( ID_TOP_FACE, new BRepAdaptor_Surface( topF ), topPcurves, isForward );
1170 SMESH_Block::Insert( topF, ID_TOP_FACE, myShapeIDMap );
1173 // Fill map ShapeIndex to TParam2ColumnMap
1174 // ----------------------------------------
1176 list< TSideFace* > fList;
1177 list< TSideFace* >::iterator fListIt;
1178 fList.push_back( mySide );
1179 for ( fListIt = fList.begin(); fListIt != fList.end(); ++fListIt)
1181 int nb = (*fListIt)->NbComponents();
1182 for ( int i = 0; i < nb; ++i ) {
1183 if ( TSideFace* comp = (*fListIt)->GetComponent( i ))
1184 fList.push_back( comp );
1186 if ( TParam2ColumnMap* cols = (*fListIt)->GetColumns()) {
1187 // columns for a base edge
1188 int id = MeshDS()->ShapeToIndex( (*fListIt)->BaseEdge() );
1189 bool isForward = (*fListIt)->IsForward();
1190 myShapeIndex2ColumnMap[ id ] = make_pair( cols, isForward );
1192 // columns for vertices
1193 const SMDS_MeshNode* n0 = cols->begin()->second.front();
1194 id = n0->GetPosition()->GetShapeId();
1195 myShapeIndex2ColumnMap[ id ] = make_pair( cols, isForward );
1197 const SMDS_MeshNode* n1 = cols->rbegin()->second.front();
1198 id = n1->GetPosition()->GetShapeId();
1199 myShapeIndex2ColumnMap[ id ] = make_pair( cols, !isForward );
1203 // gp_XYZ testPar(0.25, 0.25, 0), testCoord;
1204 // if ( !FacePoint( ID_BOT_FACE, testPar, testCoord ))
1205 // RETURN_BAD_RESULT("TEST FacePoint() FAILED");
1206 // SHOWYXZ("IN TEST PARAM" , testPar);
1207 // SHOWYXZ("OUT TEST CORD" , testCoord);
1208 // if ( !ComputeParameters( testCoord, testPar , ID_BOT_FACE))
1209 // RETURN_BAD_RESULT("TEST ComputeParameters() FAILED");
1210 // SHOWYXZ("OUT TEST PARAM" , testPar);
1215 //================================================================================
1217 * \brief Return pointer to column of nodes
1218 * \param node - bottom node from which the returned column goes up
1219 * \retval const TNodeColumn* - the found column
1221 //================================================================================
1223 const TNodeColumn* StdMeshers_PrismAsBlock::GetNodeColumn(const SMDS_MeshNode* node) const
1225 int sID = node->GetPosition()->GetShapeId();
1227 map<int, pair< TParam2ColumnMap*, bool > >::const_iterator col_frw =
1228 myShapeIndex2ColumnMap.find( sID );
1229 if ( col_frw != myShapeIndex2ColumnMap.end() ) {
1230 const TParam2ColumnMap* cols = col_frw->second.first;
1231 TParam2ColumnIt u_col = cols->begin();
1232 for ( ; u_col != cols->end(); ++u_col )
1233 if ( u_col->second[ 0 ] == node )
1234 return & u_col->second;
1239 //================================================================================
1241 * \brief Check curve orientation of a bootom edge
1242 * \param meshDS - mesh DS
1243 * \param columnsMap - node columns map of side face
1244 * \param bottomEdge - the bootom edge
1245 * \param sideFaceID - side face in-block ID
1246 * \retval bool - true if orientation coinside with in-block froward orientation
1248 //================================================================================
1250 bool StdMeshers_PrismAsBlock::IsForwardEdge(SMESHDS_Mesh* meshDS,
1251 const TParam2ColumnMap& columnsMap,
1252 const TopoDS_Edge & bottomEdge,
1253 const int sideFaceID)
1255 bool isForward = false;
1256 if ( TAssocTool::IsClosedEdge( bottomEdge ))
1258 isForward = ( bottomEdge.Orientation() == TopAbs_FORWARD );
1262 const TNodeColumn& firstCol = columnsMap.begin()->second;
1263 const SMDS_MeshNode* bottomNode = firstCol[0];
1264 TopoDS_Shape firstVertex = SMESH_MesherHelper::GetSubShapeByNode( bottomNode, meshDS );
1265 isForward = ( firstVertex.IsSame( TopExp::FirstVertex( bottomEdge, true )));
1267 // on 2 of 4 sides first vertex is end
1268 if ( sideFaceID == ID_Fx1z || sideFaceID == ID_F0yz )
1269 isForward = !isForward;
1273 //================================================================================
1275 * \brief Find wall faces by bottom edges
1276 * \param mesh - the mesh
1277 * \param mainShape - the prism
1278 * \param bottomFace - the bottom face
1279 * \param bottomEdges - edges bounding the bottom face
1280 * \param wallFaces - faces list to fill in
1282 //================================================================================
1284 bool StdMeshers_PrismAsBlock::GetWallFaces( SMESH_Mesh* mesh,
1285 const TopoDS_Shape & mainShape,
1286 const TopoDS_Shape & bottomFace,
1287 const std::list< TopoDS_Edge >& bottomEdges,
1288 std::list< TopoDS_Face >& wallFaces)
1292 TopTools_IndexedMapOfShape faceMap;
1293 TopExp::MapShapes( mainShape, TopAbs_FACE, faceMap );
1295 list< TopoDS_Edge >::const_iterator edge = bottomEdges.begin();
1296 for ( ; edge != bottomEdges.end(); ++edge )
1298 TopTools_ListIteratorOfListOfShape ancestIt = mesh->GetAncestors( *edge );
1299 for ( ; ancestIt.More(); ancestIt.Next() )
1301 const TopoDS_Shape& ancestor = ancestIt.Value();
1302 if ( ancestor.ShapeType() == TopAbs_FACE && // face
1303 !bottomFace.IsSame( ancestor ) && // not bottom
1304 faceMap.FindIndex( ancestor )) // belongs to the prism
1306 wallFaces.push_back( TopoDS::Face( ancestor ));
1311 return ( wallFaces.size() == bottomEdges.size() );
1314 //================================================================================
1316 * \brief Constructor
1317 * \param faceID - in-block ID
1318 * \param face - geom face
1319 * \param columnsMap - map of node columns
1320 * \param first - first normalized param
1321 * \param last - last normalized param
1323 //================================================================================
1325 StdMeshers_PrismAsBlock::TSideFace::TSideFace(SMESH_MesherHelper* helper,
1327 const TopoDS_Face& face,
1328 const TopoDS_Edge& baseEdge,
1329 TParam2ColumnMap* columnsMap,
1333 myParamToColumnMap( columnsMap ),
1334 myBaseEdge( baseEdge ),
1337 mySurface.Initialize( face );
1338 myParams.resize( 1 );
1339 myParams[ 0 ] = make_pair( first, last );
1340 myIsForward = StdMeshers_PrismAsBlock::IsForwardEdge( myHelper->GetMeshDS(),
1341 *myParamToColumnMap,
1345 //================================================================================
1347 * \brief Constructor of complex side face
1349 //================================================================================
1351 StdMeshers_PrismAsBlock::TSideFace::
1352 TSideFace(const vector< TSideFace* >& components,
1353 const vector< pair< double, double> > & params)
1354 :myID( components[0] ? components[0]->myID : 0 ),
1355 myParamToColumnMap( 0 ),
1357 myIsForward( true ),
1358 myComponents( components ),
1359 myHelper( components[0] ? components[0]->myHelper : 0 )
1361 //================================================================================
1363 * \brief Copy constructor
1364 * \param other - other side
1366 //================================================================================
1368 StdMeshers_PrismAsBlock::TSideFace::TSideFace( const TSideFace& other )
1371 mySurface = other.mySurface;
1372 myBaseEdge = other.myBaseEdge;
1373 myParams = other.myParams;
1374 myIsForward = other.myIsForward;
1375 myHelper = other.myHelper;
1376 myParamToColumnMap = other.myParamToColumnMap;
1378 myComponents.resize( other.myComponents.size());
1379 for (int i = 0 ; i < myComponents.size(); ++i )
1380 myComponents[ i ] = new TSideFace( *other.myComponents[ i ]);
1383 //================================================================================
1385 * \brief Deletes myComponents
1387 //================================================================================
1389 StdMeshers_PrismAsBlock::TSideFace::~TSideFace()
1391 for (int i = 0 ; i < myComponents.size(); ++i )
1392 if ( myComponents[ i ] )
1393 delete myComponents[ i ];
1396 //================================================================================
1398 * \brief Return geometry of the vertical curve
1399 * \param isMax - true means curve located closer to (1,1,1) block point
1400 * \retval Adaptor3d_Curve* - curve adaptor
1402 //================================================================================
1404 Adaptor3d_Curve* StdMeshers_PrismAsBlock::TSideFace::VertiCurve(const bool isMax) const
1406 if ( !myComponents.empty() ) {
1408 return myComponents.back()->VertiCurve(isMax);
1410 return myComponents.front()->VertiCurve(isMax);
1412 double f = myParams[0].first, l = myParams[0].second;
1413 if ( !myIsForward ) std::swap( f, l );
1414 return new TVerticalEdgeAdaptor( myParamToColumnMap, isMax ? l : f );
1417 //================================================================================
1419 * \brief Return geometry of the top or bottom curve
1421 * \retval Adaptor3d_Curve* -
1423 //================================================================================
1425 Adaptor3d_Curve* StdMeshers_PrismAsBlock::TSideFace::HorizCurve(const bool isTop) const
1427 return new THorizontalEdgeAdaptor( this, isTop );
1430 //================================================================================
1432 * \brief Return pcurves
1433 * \param pcurv - array of 4 pcurves
1434 * \retval bool - is a success
1436 //================================================================================
1438 bool StdMeshers_PrismAsBlock::TSideFace::GetPCurves(Adaptor2d_Curve2d* pcurv[4]) const
1440 int iEdge[ 4 ] = { BOTTOM_EDGE, TOP_EDGE, V0_EDGE, V1_EDGE };
1442 for ( int i = 0 ; i < 4 ; ++i ) {
1443 Handle(Geom2d_Line) line;
1444 switch ( iEdge[ i ] ) {
1446 line = new Geom2d_Line( gp_Pnt2d( 0, 1 ), gp::DX2d() ); break;
1448 line = new Geom2d_Line( gp::Origin2d(), gp::DX2d() ); break;
1450 line = new Geom2d_Line( gp::Origin2d(), gp::DY2d() ); break;
1452 line = new Geom2d_Line( gp_Pnt2d( 1, 0 ), gp::DY2d() ); break;
1454 pcurv[ i ] = new Geom2dAdaptor_Curve( line, 0, 1 );
1459 //================================================================================
1461 * \brief Returns geometry of pcurve on a horizontal face
1462 * \param isTop - is top or bottom face
1463 * \param horFace - a horizontal face
1464 * \retval Adaptor2d_Curve2d* - curve adaptor
1466 //================================================================================
1469 StdMeshers_PrismAsBlock::TSideFace::HorizPCurve(const bool isTop,
1470 const TopoDS_Face& horFace) const
1472 return new TPCurveOnHorFaceAdaptor( this, isTop, horFace );
1475 //================================================================================
1477 * \brief Return a component corresponding to parameter
1478 * \param U - parameter along a horizontal size
1479 * \param localU - parameter along a horizontal size of a component
1480 * \retval TSideFace* - found component
1482 //================================================================================
1484 StdMeshers_PrismAsBlock::TSideFace*
1485 StdMeshers_PrismAsBlock::TSideFace::GetComponent(const double U,double & localU) const
1488 if ( myComponents.empty() )
1489 return const_cast<TSideFace*>( this );
1492 for ( i = 0; i < myComponents.size(); ++i )
1493 if ( U < myParams[ i ].second )
1495 if ( i >= myComponents.size() )
1496 i = myComponents.size() - 1;
1498 double f = myParams[ i ].first, l = myParams[ i ].second;
1499 localU = ( U - f ) / ( l - f );
1500 return myComponents[ i ];
1503 //================================================================================
1505 * \brief Find node columns for a parameter
1506 * \param U - parameter along a horizontal edge
1507 * \param col1 - the 1st found column
1508 * \param col2 - the 2nd found column
1509 * \retval r - normalized position of U between the found columns
1511 //================================================================================
1513 double StdMeshers_PrismAsBlock::TSideFace::GetColumns(const double U,
1514 TParam2ColumnIt & col1,
1515 TParam2ColumnIt & col2) const
1517 double u = U, r = 0;
1518 if ( !myComponents.empty() ) {
1519 TSideFace * comp = GetComponent(U,u);
1520 return comp->GetColumns( u, col1, col2 );
1525 double f = myParams[0].first, l = myParams[0].second;
1526 u = f + u * ( l - f );
1528 col1 = col2 = getColumn( myParamToColumnMap, u );
1529 if ( ++col2 == myParamToColumnMap->end() ) {
1534 // if ( !myIsForward )
1535 // std::swap( col1, col2 );
1536 double uf = col1->first;
1537 double ul = col2->first;
1538 r = ( u - uf ) / ( ul - uf );
1543 //================================================================================
1545 * \brief Return coordinates by normalized params
1546 * \param U - horizontal param
1547 * \param V - vertical param
1548 * \retval gp_Pnt - result point
1550 //================================================================================
1552 gp_Pnt StdMeshers_PrismAsBlock::TSideFace::Value(const Standard_Real U,
1553 const Standard_Real V) const
1556 if ( !myComponents.empty() ) {
1557 TSideFace * comp = GetComponent(U,u);
1558 return comp->Value( u, V );
1561 TParam2ColumnIt u_col1, u_col2;
1562 double vR, hR = GetColumns( U, u_col1, u_col2 );
1564 const SMDS_MeshNode* n1 = 0;
1565 const SMDS_MeshNode* n2 = 0;
1566 const SMDS_MeshNode* n3 = 0;
1567 const SMDS_MeshNode* n4 = 0;
1570 vR = getRAndNodes( & u_col1->second, V, n1, n2 );
1571 vR = getRAndNodes( & u_col2->second, V, n3, n4 );
1573 gp_XY uv1 = myHelper->GetNodeUV( mySurface.Face(), n1, n4);
1574 gp_XY uv2 = myHelper->GetNodeUV( mySurface.Face(), n2, n3);
1575 gp_XY uv12 = uv1 * ( 1 - vR ) + uv2 * vR;
1577 gp_XY uv3 = myHelper->GetNodeUV( mySurface.Face(), n3, n2);
1578 gp_XY uv4 = myHelper->GetNodeUV( mySurface.Face(), n4, n1);
1579 gp_XY uv34 = uv3 * ( 1 - vR ) + uv4 * vR;
1581 gp_XY uv = uv12 * ( 1 - hR ) + uv34 * hR;
1583 return mySurface.Value( uv.X(), uv.Y() );
1587 //================================================================================
1589 * \brief Return boundary edge
1590 * \param edge - edge index
1591 * \retval TopoDS_Edge - found edge
1593 //================================================================================
1595 TopoDS_Edge StdMeshers_PrismAsBlock::TSideFace::GetEdge(const int iEdge) const
1597 if ( !myComponents.empty() ) {
1599 case V0_EDGE : return myComponents.front()->GetEdge( iEdge );
1600 case V1_EDGE : return myComponents.back() ->GetEdge( iEdge );
1601 default: return TopoDS_Edge();
1605 const SMDS_MeshNode* node = 0;
1606 SMESHDS_Mesh * meshDS = myHelper->GetMesh()->GetMeshDS();
1607 TNodeColumn* column;
1612 column = & (( ++myParamToColumnMap->begin())->second );
1613 node = ( iEdge == TOP_EDGE ) ? column->back() : column->front();
1614 edge = myHelper->GetSubShapeByNode ( node, meshDS );
1615 if ( edge.ShapeType() == TopAbs_VERTEX ) {
1616 column = & ( myParamToColumnMap->begin()->second );
1617 node = ( iEdge == TOP_EDGE ) ? column->back() : column->front();
1622 bool back = ( iEdge == V1_EDGE );
1623 if ( !myIsForward ) back = !back;
1625 column = & ( myParamToColumnMap->rbegin()->second );
1627 column = & ( myParamToColumnMap->begin()->second );
1628 if ( column->size() > 0 )
1629 edge = myHelper->GetSubShapeByNode( (*column)[ 1 ], meshDS );
1630 if ( edge.IsNull() || edge.ShapeType() == TopAbs_VERTEX )
1631 node = column->front();
1636 if ( !edge.IsNull() && edge.ShapeType() == TopAbs_EDGE )
1637 return TopoDS::Edge( edge );
1639 // find edge by 2 vertices
1640 TopoDS_Shape V1 = edge;
1641 TopoDS_Shape V2 = myHelper->GetSubShapeByNode( node, meshDS );
1642 if ( V2.ShapeType() == TopAbs_VERTEX && !V2.IsSame( V1 ))
1644 TopTools_ListIteratorOfListOfShape ancestIt =
1645 myHelper->GetMesh()->GetAncestors( V1 );
1646 for ( ; ancestIt.More(); ancestIt.Next() )
1648 const TopoDS_Shape & ancestor = ancestIt.Value();
1649 if ( ancestor.ShapeType() == TopAbs_EDGE )
1650 for ( TopExp_Explorer e( ancestor, TopAbs_VERTEX ); e.More(); e.Next() )
1651 if ( V2.IsSame( e.Current() ))
1652 return TopoDS::Edge( ancestor );
1655 return TopoDS_Edge();
1658 //================================================================================
1660 * \brief Fill block subshapes
1661 * \param shapeMap - map to fill in
1662 * \retval int - nb inserted subshapes
1664 //================================================================================
1666 int StdMeshers_PrismAsBlock::TSideFace::InsertSubShapes(TBlockShapes& shapeMap) const
1671 vector< int > edgeIdVec;
1672 SMESH_Block::GetFaceEdgesIDs( myID, edgeIdVec );
1674 for ( int i = BOTTOM_EDGE; i <=V1_EDGE ; ++i ) {
1675 TopoDS_Edge e = GetEdge( i );
1676 if ( !e.IsNull() ) {
1677 nbInserted += SMESH_Block::Insert( e, edgeIdVec[ i ], shapeMap);
1681 // Insert corner vertices
1683 TParam2ColumnIt col1, col2 ;
1684 vector< int > vertIdVec;
1687 SMESH_Block::GetEdgeVertexIDs( edgeIdVec[ V0_EDGE ], vertIdVec);
1688 GetColumns(0, col1, col2 );
1689 const SMDS_MeshNode* node0 = col1->second.front();
1690 const SMDS_MeshNode* node1 = col1->second.back();
1691 TopoDS_Shape v0 = myHelper->GetSubShapeByNode( node0, myHelper->GetMeshDS());
1692 TopoDS_Shape v1 = myHelper->GetSubShapeByNode( node1, myHelper->GetMeshDS());
1693 if ( v0.ShapeType() == TopAbs_VERTEX ) {
1694 nbInserted += SMESH_Block::Insert( v0, vertIdVec[ 0 ], shapeMap);
1696 if ( v1.ShapeType() == TopAbs_VERTEX ) {
1697 nbInserted += SMESH_Block::Insert( v1, vertIdVec[ 1 ], shapeMap);
1701 SMESH_Block::GetEdgeVertexIDs( edgeIdVec[ V1_EDGE ], vertIdVec);
1702 GetColumns(1, col1, col2 );
1703 node0 = col2->second.front();
1704 node1 = col2->second.back();
1705 v0 = myHelper->GetSubShapeByNode( node0, myHelper->GetMeshDS());
1706 v1 = myHelper->GetSubShapeByNode( node1, myHelper->GetMeshDS());
1707 if ( v0.ShapeType() == TopAbs_VERTEX ) {
1708 nbInserted += SMESH_Block::Insert( v0, vertIdVec[ 0 ], shapeMap);
1710 if ( v1.ShapeType() == TopAbs_VERTEX ) {
1711 nbInserted += SMESH_Block::Insert( v1, vertIdVec[ 1 ], shapeMap);
1714 // TopoDS_Vertex V0, V1, Vcom;
1715 // TopExp::Vertices( myBaseEdge, V0, V1, true );
1716 // if ( !myIsForward ) std::swap( V0, V1 );
1718 // // bottom vertex IDs
1719 // SMESH_Block::GetEdgeVertexIDs( edgeIdVec[ _u0 ], vertIdVec);
1720 // SMESH_Block::Insert( V0, vertIdVec[ 0 ], shapeMap);
1721 // SMESH_Block::Insert( V1, vertIdVec[ 1 ], shapeMap);
1723 // TopoDS_Edge sideEdge = GetEdge( V0_EDGE );
1724 // if ( sideEdge.IsNull() || !TopExp::CommonVertex( botEdge, sideEdge, Vcom ))
1727 // // insert one side edge
1729 // if ( Vcom.IsSame( V0 )) edgeID = edgeIdVec[ _v0 ];
1730 // else edgeID = edgeIdVec[ _v1 ];
1731 // SMESH_Block::Insert( sideEdge, edgeID, shapeMap);
1733 // // top vertex of the side edge
1734 // SMESH_Block::GetEdgeVertexIDs( edgeID, vertIdVec);
1735 // TopoDS_Vertex Vtop = TopExp::FirstVertex( sideEdge );
1736 // if ( Vcom.IsSame( Vtop ))
1737 // Vtop = TopExp::LastVertex( sideEdge );
1738 // SMESH_Block::Insert( Vtop, vertIdVec[ 1 ], shapeMap);
1740 // // other side edge
1741 // sideEdge = GetEdge( V1_EDGE );
1742 // if ( sideEdge.IsNull() )
1744 // if ( edgeID = edgeIdVec[ _v1 ]) edgeID = edgeIdVec[ _v0 ];
1745 // else edgeID = edgeIdVec[ _v1 ];
1746 // SMESH_Block::Insert( sideEdge, edgeID, shapeMap);
1749 // TopoDS_Edge topEdge = GetEdge( TOP_EDGE );
1750 // SMESH_Block::Insert( topEdge, edgeIdVec[ _u1 ], shapeMap);
1752 // // top vertex of the other side edge
1753 // if ( !TopExp::CommonVertex( topEdge, sideEdge, Vcom ))
1755 // SMESH_Block::GetEdgeVertexIDs( edgeID, vertIdVec );
1756 // SMESH_Block::Insert( Vcom, vertIdVec[ 1 ], shapeMap);
1761 //================================================================================
1763 * \brief Creates TVerticalEdgeAdaptor
1764 * \param columnsMap - node column map
1765 * \param parameter - normalized parameter
1767 //================================================================================
1769 StdMeshers_PrismAsBlock::TVerticalEdgeAdaptor::
1770 TVerticalEdgeAdaptor( const TParam2ColumnMap* columnsMap, const double parameter)
1772 myNodeColumn = & getColumn( columnsMap, parameter )->second;
1775 //================================================================================
1777 * \brief Return coordinates for the given normalized parameter
1778 * \param U - normalized parameter
1779 * \retval gp_Pnt - coordinates
1781 //================================================================================
1783 gp_Pnt StdMeshers_PrismAsBlock::TVerticalEdgeAdaptor::Value(const Standard_Real U) const
1785 const SMDS_MeshNode* n1;
1786 const SMDS_MeshNode* n2;
1787 double r = getRAndNodes( myNodeColumn, U, n1, n2 );
1788 return gpXYZ(n1) * ( 1 - r ) + gpXYZ(n2) * r;
1791 //================================================================================
1793 * \brief Return coordinates for the given normalized parameter
1794 * \param U - normalized parameter
1795 * \retval gp_Pnt - coordinates
1797 //================================================================================
1799 gp_Pnt StdMeshers_PrismAsBlock::THorizontalEdgeAdaptor::Value(const Standard_Real U) const
1801 return mySide->TSideFace::Value( U, myV );
1804 //================================================================================
1806 * \brief Return UV on pcurve for the given normalized parameter
1807 * \param U - normalized parameter
1808 * \retval gp_Pnt - coordinates
1810 //================================================================================
1812 gp_Pnt2d StdMeshers_PrismAsBlock::TPCurveOnHorFaceAdaptor::Value(const Standard_Real U) const
1814 TParam2ColumnIt u_col1, u_col2;
1815 double r = mySide->GetColumns( U, u_col1, u_col2 );
1816 gp_XY uv1 = mySide->GetNodeUV( myFace, u_col1->second[ myZ ]);
1817 gp_XY uv2 = mySide->GetNodeUV( myFace, u_col2->second[ myZ ]);
1818 return uv1 * ( 1 - r ) + uv2 * r;