+ // ------------------------------
+ // Get the 1st row of wall FACEs
+ // ------------------------------
+
+ list< TopoDS_Edge >::iterator edge = thePrism.myBottomEdges.begin();
+ std::list< int >::iterator nbE = thePrism.myNbEdgesInWires.begin();
+ std::list< int > nbQuadsPerWire;
+ int iE = 0;
+ double f,l;
+ while ( edge != thePrism.myBottomEdges.end() )
+ {
+ ++iE;
+ if ( BRep_Tool::Curve( *edge, f,l ).IsNull() )
+ {
+ edge = thePrism.myBottomEdges.erase( edge );
+ --iE;
+ --(*nbE);
+ }
+ else
+ {
+ TopTools_ListIteratorOfListOfShape faceIt( edgeToFaces.FindFromKey( *edge ));
+ for ( ; faceIt.More(); faceIt.Next() )
+ {
+ const TopoDS_Face& face = TopoDS::Face( faceIt.Value() );
+ if ( !thePrism.myBottom.IsSame( face ))
+ {
+ Prism_3D::TQuadList quadList( 1, quadAlgo->CheckNbEdges( *mesh, face ));
+ if ( !quadList.back() )
+ return toSM( error(TCom("Side face #") << shapeID( face )
+ << " not meshable with quadrangles"));
+ bool isCompositeBase = ! setBottomEdge( *edge, quadList.back(), face );
+ if ( isCompositeBase )
+ {
+ // it's OK if all EDGEs of the bottom side belongs to the bottom FACE
+ StdMeshers_FaceSidePtr botSide = quadList.back()->side[ QUAD_BOTTOM_SIDE ];
+ for ( int iE = 0; iE < botSide->NbEdges(); ++iE )
+ if ( !myHelper->IsSubShape( botSide->Edge(iE), thePrism.myBottom ))
+ return toSM( error(TCom("Composite 'horizontal' edges are not supported")));
+ }
+ if ( faceMap.Add( face ))
+ thePrism.myWallQuads.push_back( quadList );
+ break;
+ }
+ }
+ ++edge;
+ }
+ if ( iE == *nbE )
+ {
+ iE = 0;
+ ++nbE;
+ int nbQuadPrev = std::accumulate( nbQuadsPerWire.begin(), nbQuadsPerWire.end(), 0 );
+ nbQuadsPerWire.push_back( thePrism.myWallQuads.size() - nbQuadPrev );
+ }
+ }
+
+ // -------------------------
+ // Find the rest wall FACEs
+ // -------------------------
+
+ // Compose a vector of indixes of right neighbour FACE for each wall FACE
+ // that is not so evident in case of several WIREs in the bottom FACE
+ thePrism.myRightQuadIndex.clear();
+ for ( size_t i = 0; i < thePrism.myWallQuads.size(); ++i )
+ {
+ thePrism.myRightQuadIndex.push_back( i+1 ); // OK for all but the last EDGE of a WIRE
+ }
+ list< int >::iterator nbQinW = nbQuadsPerWire.begin();
+ for ( int iLeft = 0; nbQinW != nbQuadsPerWire.end(); ++nbQinW )
+ {
+ thePrism.myRightQuadIndex[ iLeft + *nbQinW - 1 ] = iLeft; // for the last EDGE of a WIRE
+ iLeft += *nbQinW;
+ }
+
+ while ( totalNbFaces - faceMap.Extent() > 2 )
+ {
+ // find wall FACEs adjacent to each of wallQuads by the right side EDGE
+ int nbKnownFaces;
+ do {
+ nbKnownFaces = faceMap.Extent();
+ StdMeshers_FaceSidePtr rightSide, topSide; // sides of the quad
+ for ( size_t i = 0; i < thePrism.myWallQuads.size(); ++i )
+ {
+ rightSide = thePrism.myWallQuads[i].back()->side[ QUAD_RIGHT_SIDE ];
+ for ( int iE = 0; iE < rightSide->NbEdges(); ++iE ) // rightSide can be composite
+ {
+ const TopoDS_Edge & rightE = rightSide->Edge( iE );
+ TopTools_ListIteratorOfListOfShape face( edgeToFaces.FindFromKey( rightE ));
+ for ( ; face.More(); face.Next() )
+ if ( faceMap.Add( face.Value() ))
+ {
+ // a new wall FACE encountered, store it in thePrism.myWallQuads
+ const int iRight = thePrism.myRightQuadIndex[i];
+ topSide = thePrism.myWallQuads[ iRight ].back()->side[ QUAD_TOP_SIDE ];
+ const TopoDS_Edge& newBotE = topSide->Edge(0);
+ const TopoDS_Shape& newWallF = face.Value();
+ thePrism.myWallQuads[ iRight ].push_back( quadAlgo->CheckNbEdges( *mesh, newWallF ));
+ if ( !thePrism.myWallQuads[ iRight ].back() )
+ return toSM( error(TCom("Side face #") << shapeID( newWallF ) <<
+ " not meshable with quadrangles"));
+ if ( ! setBottomEdge( newBotE, thePrism.myWallQuads[ iRight ].back(), newWallF ))
+ return toSM( error(TCom("Composite 'horizontal' edges are not supported")));
+ }
+ }
+ }
+ } while ( nbKnownFaces != faceMap.Extent() );
+
+ // find wall FACEs adjacent to each of thePrism.myWallQuads by the top side EDGE
+ if ( totalNbFaces - faceMap.Extent() > 2 )
+ {
+ const int nbFoundWalls = faceMap.Extent();
+ for ( size_t i = 0; i < thePrism.myWallQuads.size(); ++i )
+ {
+ StdMeshers_FaceSidePtr topSide = thePrism.myWallQuads[i].back()->side[ QUAD_TOP_SIDE ];
+ const TopoDS_Edge & topE = topSide->Edge( 0 );
+ if ( topSide->NbEdges() > 1 )
+ return toSM( error(COMPERR_BAD_SHAPE, TCom("Side face #") <<
+ shapeID( thePrism.myWallQuads[i].back()->face )
+ << " has a composite top edge"));
+ TopTools_ListIteratorOfListOfShape faceIt( edgeToFaces.FindFromKey( topE ));
+ for ( ; faceIt.More(); faceIt.Next() )
+ if ( faceMap.Add( faceIt.Value() ))
+ {
+ // a new wall FACE encountered, store it in wallQuads
+ thePrism.myWallQuads[ i ].push_back( quadAlgo->CheckNbEdges( *mesh, faceIt.Value() ));
+ if ( !thePrism.myWallQuads[ i ].back() )
+ return toSM( error(TCom("Side face #") << shapeID( faceIt.Value() ) <<
+ " not meshable with quadrangles"));
+ if ( ! setBottomEdge( topE, thePrism.myWallQuads[ i ].back(), faceIt.Value() ))
+ return toSM( error(TCom("Composite 'horizontal' edges are not supported")));
+ if ( totalNbFaces - faceMap.Extent() == 2 )
+ {
+ i = thePrism.myWallQuads.size(); // to quit from the outer loop
+ break;
+ }
+ }
+ }
+ if ( nbFoundWalls == faceMap.Extent() )
+ return toSM( error("Failed to find wall faces"));
+
+ }
+ } // while ( totalNbFaces - faceMap.Extent() > 2 )
+
+ // ------------------
+ // Find the top FACE
+ // ------------------
+
+ if ( thePrism.myTop.IsNull() )
+ {
+ // now only top and bottom FACEs are not in the faceMap
+ faceMap.Add( thePrism.myBottom );
+ for ( TopExp_Explorer f( thePrism.myShape3D, TopAbs_FACE ); f.More(); f.Next() )
+ if ( !faceMap.Contains( f.Current() )) {
+ thePrism.myTop = TopoDS::Face( f.Current() );
+ break;
+ }
+ if ( thePrism.myTop.IsNull() )
+ return toSM( error("Top face not found"));
+ }
+
+ // Check that the top FACE shares all the top EDGEs
+ for ( size_t i = 0; i < thePrism.myWallQuads.size(); ++i )
+ {
+ StdMeshers_FaceSidePtr topSide = thePrism.myWallQuads[i].back()->side[ QUAD_TOP_SIDE ];
+ const TopoDS_Edge & topE = topSide->Edge( 0 );
+ if ( !myHelper->IsSubShape( topE, thePrism.myTop ))
+ return toSM( error( TCom("Wrong source face: #") << shapeID( thePrism.myBottom )));
+ }
+
+ return true;
+}
+
+//=======================================================================
+//function : compute
+//purpose : Compute mesh on a SOLID
+//=======================================================================
+
+bool StdMeshers_Prism_3D::compute(const Prism_3D::TPrismTopo& thePrism)
+{
+ myHelper->IsQuadraticSubMesh( thePrism.myShape3D );
+ if ( _computeCanceled )
+ return toSM( error( SMESH_ComputeError::New(COMPERR_CANCELED)));
+
+ // Assure the bottom is meshed
+ SMESH_subMesh * botSM = myHelper->GetMesh()->GetSubMesh( thePrism.myBottom );
+ if (( botSM->IsEmpty() ) &&
+ ( ! botSM->GetAlgo() ||
+ ! _gen->Compute( *botSM->GetFather(), botSM->GetSubShape(), /*shapeOnly=*/true )))
+ return error( COMPERR_BAD_INPUT_MESH,
+ TCom( "No mesher defined to compute the base face #")
+ << shapeID( thePrism.myBottom ));
+
+ // Make all side FACEs of thePrism meshed with quads
+ if ( !computeWalls( thePrism ))
+ return false;
+
+ // Analyse mesh and geometry to find all block sub-shapes and submeshes
+ // (after fixing IPAL52499 myBlock is used as a holder of boundary nodes
+ // and for 2D projection in hard cases where StdMeshers_Projection_2D fails;
+ // location of internal nodes is usually computed by StdMeshers_Sweeper)
+ if ( !myBlock.Init( myHelper, thePrism ))
+ return toSM( error( myBlock.GetError()));
+
+ SMESHDS_Mesh* meshDS = myHelper->GetMeshDS();
+
+ int volumeID = meshDS->ShapeToIndex( thePrism.myShape3D );
+
+ // Try to get gp_Trsf to get all nodes from bottom ones
+ vector<gp_Trsf> trsf;
+ gp_Trsf bottomToTopTrsf;
+ // if ( !myBlock.GetLayersTransformation( trsf, thePrism ))
+ // trsf.clear();
+ // else if ( !trsf.empty() )
+ // bottomToTopTrsf = trsf.back();
+
+ // To compute coordinates of a node inside a block, it is necessary to know
+ // 1. normalized parameters of the node by which
+ // 2. coordinates of node projections on all block sub-shapes are computed
+
+ // So we fill projections on vertices at once as they are same for all nodes
+ myShapeXYZ.resize( myBlock.NbSubShapes() );
+ for ( int iV = SMESH_Block::ID_FirstV; iV < SMESH_Block::ID_FirstE; ++iV ) {
+ myBlock.VertexPoint( iV, myShapeXYZ[ iV ]);
+ SHOWYXZ("V point " <<iV << " ", myShapeXYZ[ iV ]);
+ }
+
+ // Projections on the top and bottom faces are taken from nodes existing
+ // on these faces; find correspondence between bottom and top nodes
+ myUseBlock = false;
+ myBotToColumnMap.clear();
+ if ( !assocOrProjBottom2Top( bottomToTopTrsf, thePrism ) ) // it also fills myBotToColumnMap
+ return false;
+
+
+ // Create nodes inside the block
+
+ // use transformation (issue 0020680, IPAL0052499)
+ StdMeshers_Sweeper sweeper;
+ double tol;
+ bool allowHighBndError;
+
+ if ( !myUseBlock )
+ {
+ // load boundary nodes into sweeper
+ bool dummy;
+ list< TopoDS_Edge >::const_iterator edge = thePrism.myBottomEdges.begin();
+ for ( ; edge != thePrism.myBottomEdges.end(); ++edge )
+ {
+ int edgeID = meshDS->ShapeToIndex( *edge );
+ TParam2ColumnMap* u2col = const_cast<TParam2ColumnMap*>
+ ( myBlock.GetParam2ColumnMap( edgeID, dummy ));
+ TParam2ColumnMap::iterator u2colIt = u2col->begin();
+ for ( ; u2colIt != u2col->end(); ++u2colIt )
+ sweeper.myBndColumns.push_back( & u2colIt->second );
+ }
+ // load node columns inside the bottom face
+ TNode2ColumnMap::iterator bot_column = myBotToColumnMap.begin();
+ for ( ; bot_column != myBotToColumnMap.end(); ++bot_column )
+ sweeper.myIntColumns.push_back( & bot_column->second );
+
+ tol = getSweepTolerance( thePrism );
+ allowHighBndError = !isSimpleBottom( thePrism );
+ }
+
+ if ( !myUseBlock && sweeper.ComputeNodes( *myHelper, tol, allowHighBndError ))
+ {
+ }
+ else // use block approach
+ {
+ // loop on nodes inside the bottom face
+ Prism_3D::TNode prevBNode;
+ TNode2ColumnMap::iterator bot_column = myBotToColumnMap.begin();
+ for ( ; bot_column != myBotToColumnMap.end(); ++bot_column )
+ {
+ const Prism_3D::TNode& tBotNode = bot_column->first; // bottom TNode
+ if ( tBotNode.GetPositionType() != SMDS_TOP_FACE )
+ continue; // node is not inside the FACE
+
+ // column nodes; middle part of the column are zero pointers
+ TNodeColumn& column = bot_column->second;
+
+ gp_XYZ botParams, topParams;
+ if ( !tBotNode.HasParams() )
+ {
+ // compute bottom node parameters
+ gp_XYZ paramHint(-1,-1,-1);
+ if ( prevBNode.IsNeighbor( tBotNode ))
+ paramHint = prevBNode.GetParams();
+ if ( !myBlock.ComputeParameters( tBotNode.GetCoords(), tBotNode.ChangeParams(),
+ ID_BOT_FACE, paramHint ))
+ return toSM( error(TCom("Can't compute normalized parameters for node ")
+ << tBotNode.myNode->GetID() << " on the face #"
+ << myBlock.SubMesh( ID_BOT_FACE )->GetId() ));
+ prevBNode = tBotNode;
+
+ botParams = topParams = tBotNode.GetParams();
+ topParams.SetZ( 1 );
+
+ // compute top node parameters
+ if ( column.size() > 2 ) {
+ gp_Pnt topCoords = gpXYZ( column.back() );
+ if ( !myBlock.ComputeParameters( topCoords, topParams, ID_TOP_FACE, topParams ))
+ return toSM( error(TCom("Can't compute normalized parameters ")
+ << "for node " << column.back()->GetID()
+ << " on the face #"<< column.back()->getshapeId() ));
+ }
+ }
+ else // top nodes are created by projection using parameters
+ {
+ botParams = topParams = tBotNode.GetParams();
+ topParams.SetZ( 1 );
+ }
+
+ myShapeXYZ[ ID_BOT_FACE ] = tBotNode.GetCoords();
+ myShapeXYZ[ ID_TOP_FACE ] = gpXYZ( column.back() );
+
+ // vertical loop
+ TNodeColumn::iterator columnNodes = column.begin();
+ for ( int z = 0; columnNodes != column.end(); ++columnNodes, ++z)
+ {
+ const SMDS_MeshNode* & node = *columnNodes;
+ if ( node ) continue; // skip bottom or top node
+
+ // params of a node to create
+ double rz = (double) z / (double) ( column.size() - 1 );
+ gp_XYZ params = botParams * ( 1 - rz ) + topParams * rz;
+
+ // set coords on all faces and nodes
+ const int nbSideFaces = 4;
+ int sideFaceIDs[nbSideFaces] = { SMESH_Block::ID_Fx0z,
+ SMESH_Block::ID_Fx1z,
+ SMESH_Block::ID_F0yz,
+ SMESH_Block::ID_F1yz };
+ for ( int iF = 0; iF < nbSideFaces; ++iF )
+ if ( !setFaceAndEdgesXYZ( sideFaceIDs[ iF ], params, z ))
+ return false;
+
+ // compute coords for a new node
+ gp_XYZ coords;
+ if ( !SMESH_Block::ShellPoint( params, myShapeXYZ, coords ))
+ return toSM( error("Can't compute coordinates by normalized parameters"));
+
+ // if ( !meshDS->MeshElements( volumeID ) ||
+ // meshDS->MeshElements( volumeID )->NbNodes() == 0 )
+ // pointsToPython(myShapeXYZ);
+ SHOWYXZ("TOPFacePoint ",myShapeXYZ[ ID_TOP_FACE]);
+ SHOWYXZ("BOT Node "<< tBotNode.myNode->GetID(),gpXYZ(tBotNode.myNode));
+ SHOWYXZ("ShellPoint ",coords);
+
+ // create a node
+ node = meshDS->AddNode( coords.X(), coords.Y(), coords.Z() );
+ meshDS->SetNodeInVolume( node, volumeID );
+
+ if ( _computeCanceled )
+ return false;
+ }
+ } // loop on bottom nodes
+ }
+
+ // Create volumes
+
+ SMESHDS_SubMesh* smDS = myBlock.SubMeshDS( ID_BOT_FACE );
+ if ( !smDS ) return toSM( error(COMPERR_BAD_INPUT_MESH, "Null submesh"));
+
+ // loop on bottom mesh faces
+ vector< const TNodeColumn* > columns;
+ SMDS_ElemIteratorPtr faceIt = smDS->GetElements();
+ while ( faceIt->more() )
+ {
+ const SMDS_MeshElement* face = faceIt->next();
+ if ( !face || face->GetType() != SMDSAbs_Face )
+ continue;
+
+ // find node columns for each node
+ int nbNodes = face->NbCornerNodes();
+ columns.resize( nbNodes );
+ for ( int i = 0; i < nbNodes; ++i )
+ {
+ const SMDS_MeshNode* n = face->GetNode( i );
+ if ( n->GetPosition()->GetTypeOfPosition() == SMDS_TOP_FACE ) {
+ TNode2ColumnMap::iterator bot_column = myBotToColumnMap.find( n );
+ if ( bot_column == myBotToColumnMap.end() )
+ return toSM( error(TCom("No nodes found above node ") << n->GetID() ));
+ columns[ i ] = & bot_column->second;
+ }
+ else {
+ columns[ i ] = myBlock.GetNodeColumn( n );
+ if ( !columns[ i ] )
+ return toSM( error(TCom("No side nodes found above node ") << n->GetID() ));
+ }
+ }
+ // create prisms
+ if ( !AddPrisms( columns, myHelper ))
+ return toSM( error("Different 'vertical' discretization"));
+
+ } // loop on bottom mesh faces
+
+ // clear data
+ myBotToColumnMap.clear();
+ myBlock.Clear();
+
+ // update state of sub-meshes (mostly in order to erase improper errors)
+ SMESH_subMesh* sm = myHelper->GetMesh()->GetSubMesh( thePrism.myShape3D );
+ SMESH_subMeshIteratorPtr smIt = sm->getDependsOnIterator(/*includeSelf=*/true);
+ while ( smIt->more() )
+ {
+ sm = smIt->next();
+ sm->GetComputeError().reset();
+ sm->ComputeStateEngine( SMESH_subMesh::CHECK_COMPUTE_STATE );
+ }
+
+ return true;
+}
+
+//=======================================================================
+//function : computeWalls
+//purpose : Compute 2D mesh on walls FACEs of a prism
+//=======================================================================
+
+bool StdMeshers_Prism_3D::computeWalls(const Prism_3D::TPrismTopo& thePrism)
+{
+ SMESH_Mesh* mesh = myHelper->GetMesh();
+ SMESHDS_Mesh* meshDS = myHelper->GetMeshDS();
+ DBGOUT( endl << "COMPUTE Prism " << meshDS->ShapeToIndex( thePrism.myShape3D ));
+
+ TProjction1dAlgo* projector1D = TProjction1dAlgo::instance( this );
+ StdMeshers_Quadrangle_2D* quadAlgo = TQuadrangleAlgo::instance( this, myHelper );
+
+ // SMESH_HypoFilter hyp1dFilter( SMESH_HypoFilter::IsAlgo(),/*not=*/true);
+ // hyp1dFilter.And( SMESH_HypoFilter::HasDim( 1 ));
+ // hyp1dFilter.And( SMESH_HypoFilter::IsMoreLocalThan( thePrism.myShape3D, *mesh ));
+
+ // Discretize equally 'vertical' EDGEs
+ // -----------------------------------
+ // find source FACE sides for projection: either already computed ones or
+ // the 'most composite' ones
+ const size_t nbWalls = thePrism.myWallQuads.size();
+ vector< int > wgt( nbWalls, 0 ); // "weight" of a wall
+ for ( size_t iW = 0; iW != nbWalls; ++iW )
+ {
+ Prism_3D::TQuadList::const_iterator quad = thePrism.myWallQuads[iW].begin();
+ for ( ; quad != thePrism.myWallQuads[iW].end(); ++quad )
+ {
+ StdMeshers_FaceSidePtr lftSide = (*quad)->side[ QUAD_LEFT_SIDE ];
+ for ( int i = 0; i < lftSide->NbEdges(); ++i )
+ {
+ ++wgt[ iW ];
+ const TopoDS_Edge& E = lftSide->Edge(i);
+ if ( mesh->GetSubMesh( E )->IsMeshComputed() )
+ {
+ wgt[ iW ] += 100;
+ wgt[ myHelper->WrapIndex( iW+1, nbWalls)] += 10;
+ wgt[ myHelper->WrapIndex( iW-1, nbWalls)] += 10;
+ }
+ // else if ( mesh->GetHypothesis( E, hyp1dFilter, true )) // local hypothesis!
+ // wgt += 100;
+ }
+ }
+ // in quadratic mesh, pass ignoreMediumNodes to quad sides
+ if ( myHelper->GetIsQuadratic() )
+ {
+ quad = thePrism.myWallQuads[iW].begin();
+ for ( ; quad != thePrism.myWallQuads[iW].end(); ++quad )
+ for ( int i = 0; i < NB_QUAD_SIDES; ++i )
+ (*quad)->side[ i ].grid->SetIgnoreMediumNodes( true );
+ }
+ }
+ multimap< int, int > wgt2quad;
+ for ( size_t iW = 0; iW != nbWalls; ++iW )
+ wgt2quad.insert( make_pair( wgt[ iW ], iW ));
+
+ // Project 'vertical' EDGEs, from left to right
+ multimap< int, int >::reverse_iterator w2q = wgt2quad.rbegin();
+ for ( ; w2q != wgt2quad.rend(); ++w2q )
+ {
+ const int iW = w2q->second;
+ const Prism_3D::TQuadList& quads = thePrism.myWallQuads[ iW ];
+ Prism_3D::TQuadList::const_iterator quad = quads.begin();
+ for ( ; quad != quads.end(); ++quad )
+ {
+ StdMeshers_FaceSidePtr rgtSide = (*quad)->side[ QUAD_RIGHT_SIDE ]; // tgt
+ StdMeshers_FaceSidePtr lftSide = (*quad)->side[ QUAD_LEFT_SIDE ]; // src
+ bool swapLeftRight = ( lftSide->NbSegments( /*update=*/true ) == 0 &&
+ rgtSide->NbSegments( /*update=*/true ) > 0 );
+ if ( swapLeftRight )
+ std::swap( lftSide, rgtSide );
+
+ // assure that all the source (left) EDGEs are meshed
+ int nbSrcSegments = 0;
+ for ( int i = 0; i < lftSide->NbEdges(); ++i )
+ {
+ const TopoDS_Edge& srcE = lftSide->Edge(i);
+ SMESH_subMesh* srcSM = mesh->GetSubMesh( srcE );
+ if ( !srcSM->IsMeshComputed() ) {
+ DBGOUT( "COMPUTE V edge " << srcSM->GetId() );
+ TopoDS_Edge prpgSrcE = findPropagationSource( srcE );
+ if ( !prpgSrcE.IsNull() ) {
+ srcSM->ComputeSubMeshStateEngine( SMESH_subMesh::COMPUTE );
+ projector1D->myHyp.SetSourceEdge( prpgSrcE );
+ projector1D->Compute( *mesh, srcE );
+ srcSM->ComputeStateEngine( SMESH_subMesh::CHECK_COMPUTE_STATE );
+ }
+ else {
+ srcSM->ComputeSubMeshStateEngine( SMESH_subMesh::COMPUTE );
+ srcSM->ComputeStateEngine ( SMESH_subMesh::COMPUTE );
+ }
+ if ( !srcSM->IsMeshComputed() )
+ return toSM( error( "Can't compute 1D mesh" ));
+ }
+ nbSrcSegments += srcSM->GetSubMeshDS()->NbElements();
+ }
+ // check target EDGEs
+ int nbTgtMeshed = 0, nbTgtSegments = 0;
+ vector< bool > isTgtEdgeComputed( rgtSide->NbEdges() );
+ for ( int i = 0; i < rgtSide->NbEdges(); ++i )
+ {
+ const TopoDS_Edge& tgtE = rgtSide->Edge(i);
+ SMESH_subMesh* tgtSM = mesh->GetSubMesh( tgtE );
+ if ( !( isTgtEdgeComputed[ i ] = tgtSM->IsMeshComputed() )) {
+ tgtSM->ComputeSubMeshStateEngine( SMESH_subMesh::COMPUTE );
+ tgtSM->ComputeStateEngine ( SMESH_subMesh::COMPUTE );
+ }
+ if ( tgtSM->IsMeshComputed() ) {
+ ++nbTgtMeshed;
+ nbTgtSegments += tgtSM->GetSubMeshDS()->NbElements();
+ }
+ }
+ if ( rgtSide->NbEdges() == nbTgtMeshed ) // all tgt EDGEs meshed
+ {
+ if ( nbTgtSegments != nbSrcSegments )
+ {
+ bool badMeshRemoved = false;
+ // remove just computed segments
+ for ( int i = 0; i < rgtSide->NbEdges(); ++i )
+ if ( !isTgtEdgeComputed[ i ])
+ {
+ const TopoDS_Edge& tgtE = rgtSide->Edge(i);
+ SMESH_subMesh* tgtSM = mesh->GetSubMesh( tgtE );
+ tgtSM->ComputeStateEngine( SMESH_subMesh::CLEAN );
+ badMeshRemoved = true;
+ nbTgtMeshed--;
+ }
+ if ( !badMeshRemoved )
+ {
+ for ( int i = 0; i < lftSide->NbEdges(); ++i )
+ addBadInputElements( meshDS->MeshElements( lftSide->Edge( i )));
+ for ( int i = 0; i < rgtSide->NbEdges(); ++i )
+ addBadInputElements( meshDS->MeshElements( rgtSide->Edge( i )));
+ return toSM( error( TCom("Different nb of segment on logically vertical edges #")
+ << shapeID( lftSide->Edge(0) ) << " and #"
+ << shapeID( rgtSide->Edge(0) ) << ": "
+ << nbSrcSegments << " != " << nbTgtSegments ));
+ }
+ }
+ else // if ( nbTgtSegments == nbSrcSegments )
+ {
+ continue;
+ }
+ }
+ // Compute 'vertical projection'
+ if ( nbTgtMeshed == 0 )
+ {
+ // compute nodes on target VERTEXes
+ const UVPtStructVec& srcNodeStr = lftSide->GetUVPtStruct();
+ if ( srcNodeStr.size() == 0 )
+ return toSM( error( TCom("Invalid node positions on edge #") <<
+ shapeID( lftSide->Edge(0) )));
+ vector< SMDS_MeshNode* > newNodes( srcNodeStr.size() );
+ for ( int is2ndV = 0; is2ndV < 2; ++is2ndV )
+ {
+ const TopoDS_Edge& E = rgtSide->Edge( is2ndV ? rgtSide->NbEdges()-1 : 0 );
+ TopoDS_Vertex v = myHelper->IthVertex( is2ndV, E );
+ mesh->GetSubMesh( v )->ComputeStateEngine( SMESH_subMesh::COMPUTE );
+ const SMDS_MeshNode* n = SMESH_Algo::VertexNode( v, meshDS );
+ newNodes[ is2ndV ? 0 : newNodes.size()-1 ] = (SMDS_MeshNode*) n;
+ }
+
+ // compute nodes on target EDGEs
+ DBGOUT( "COMPUTE V edge (proj) " << shapeID( lftSide->Edge(0)));
+ rgtSide->Reverse(); // direct it same as the lftSide
+ myHelper->SetElementsOnShape( false ); // myHelper holds the prism shape
+ TopoDS_Edge tgtEdge;
+ for ( size_t iN = 1; iN < srcNodeStr.size()-1; ++iN ) // add nodes
+ {
+ gp_Pnt p = rgtSide->Value3d ( srcNodeStr[ iN ].normParam );
+ double u = rgtSide->Parameter( srcNodeStr[ iN ].normParam, tgtEdge );
+ newNodes[ iN ] = meshDS->AddNode( p.X(), p.Y(), p.Z() );
+ meshDS->SetNodeOnEdge( newNodes[ iN ], tgtEdge, u );
+ }
+ for ( size_t iN = 1; iN < srcNodeStr.size(); ++iN ) // add segments
+ {
+ // find an EDGE to set a new segment
+ std::pair<int, TopAbs_ShapeEnum> id2type =
+ myHelper->GetMediumPos( newNodes[ iN-1 ], newNodes[ iN ] );
+ if ( id2type.second != TopAbs_EDGE )
+ {
+ // new nodes are on different EDGEs; put one of them on VERTEX
+ const int edgeIndex = rgtSide->EdgeIndex( srcNodeStr[ iN-1 ].normParam );
+ const double vertexParam = rgtSide->LastParameter( edgeIndex );
+ TopoDS_Vertex vertex = rgtSide->LastVertex( edgeIndex );
+ const SMDS_MeshNode* vn = SMESH_Algo::VertexNode( vertex, meshDS );
+ const gp_Pnt p = BRep_Tool::Pnt( vertex );
+ const int isPrev = ( Abs( srcNodeStr[ iN-1 ].normParam - vertexParam ) <
+ Abs( srcNodeStr[ iN ].normParam - vertexParam ));
+ meshDS->UnSetNodeOnShape( newNodes[ iN-isPrev ] );
+ meshDS->SetNodeOnVertex ( newNodes[ iN-isPrev ], vertex );
+ meshDS->MoveNode ( newNodes[ iN-isPrev ], p.X(), p.Y(), p.Z() );
+ id2type.first = newNodes[ iN-(1-isPrev) ]->getshapeId();
+ if ( vn )
+ {
+ SMESH_MeshEditor::TListOfListOfNodes lln( 1, list< const SMDS_MeshNode* >() );
+ lln.back().push_back ( vn );
+ lln.back().push_front( newNodes[ iN-isPrev ] ); // to keep
+ SMESH_MeshEditor( mesh ).MergeNodes( lln );
+ }
+ }
+ SMDS_MeshElement* newEdge = myHelper->AddEdge( newNodes[ iN-1 ], newNodes[ iN ] );
+ meshDS->SetMeshElementOnShape( newEdge, id2type.first );
+ }
+ myHelper->SetElementsOnShape( true );
+ for ( int i = 0; i < rgtSide->NbEdges(); ++i ) // update state of sub-meshes
+ {
+ const TopoDS_Edge& E = rgtSide->Edge( i );
+ SMESH_subMesh* tgtSM = mesh->GetSubMesh( E );
+ tgtSM->ComputeStateEngine( SMESH_subMesh::CHECK_COMPUTE_STATE );
+ }
+
+ // to continue projection from the just computed side as a source
+ if ( !swapLeftRight && rgtSide->NbEdges() > 1 && w2q->second == iW )
+ {
+ std::pair<int,int> wgt2quadKeyVal( w2q->first + 1, thePrism.myRightQuadIndex[ iW ]);
+ wgt2quad.insert( wgt2quadKeyVal ); // it will be skipped by ++w2q
+ wgt2quad.insert( wgt2quadKeyVal );
+ w2q = wgt2quad.rbegin();
+ }
+ }
+ else
+ {
+ // HOPE assigned hypotheses are OK, so that equal nb of segments will be generated
+ //return toSM( error("Partial projection not implemented"));
+ }
+ } // loop on quads of a composite wall side
+ } // loop on the ordered wall sides
+
+
+
+ for ( size_t iW = 0; iW != thePrism.myWallQuads.size(); ++iW )
+ {
+ Prism_3D::TQuadList::const_iterator quad = thePrism.myWallQuads[iW].begin();
+ for ( ; quad != thePrism.myWallQuads[iW].end(); ++quad )
+ {
+ const TopoDS_Face& face = (*quad)->face;
+ SMESH_subMesh* fSM = mesh->GetSubMesh( face );
+ if ( ! fSM->IsMeshComputed() )
+ {
+ // Top EDGEs must be projections from the bottom ones
+ // to compute stuctured quad mesh on wall FACEs
+ // ---------------------------------------------------
+ const TopoDS_Edge& botE = (*quad)->side[ QUAD_BOTTOM_SIDE ].grid->Edge(0);
+ const TopoDS_Edge& topE = (*quad)->side[ QUAD_TOP_SIDE ].grid->Edge(0);
+ SMESH_subMesh* botSM = mesh->GetSubMesh( botE );
+ SMESH_subMesh* topSM = mesh->GetSubMesh( topE );
+ SMESH_subMesh* srcSM = botSM;
+ SMESH_subMesh* tgtSM = topSM;
+ srcSM->ComputeStateEngine( SMESH_subMesh::CHECK_COMPUTE_STATE );
+ tgtSM->ComputeStateEngine( SMESH_subMesh::CHECK_COMPUTE_STATE );
+ if ( !srcSM->IsMeshComputed() && tgtSM->IsMeshComputed() )
+ std::swap( srcSM, tgtSM );
+
+ if ( !srcSM->IsMeshComputed() )
+ {
+ DBGOUT( "COMPUTE H edge " << srcSM->GetId());
+ srcSM->ComputeSubMeshStateEngine( SMESH_subMesh::COMPUTE ); // nodes on VERTEXes
+ srcSM->ComputeStateEngine( SMESH_subMesh::COMPUTE ); // segments on the EDGE
+ }
+
+ if ( tgtSM->IsMeshComputed() &&
+ tgtSM->GetSubMeshDS()->NbNodes() != srcSM->GetSubMeshDS()->NbNodes() )
+ {
+ // the top EDGE is computed differently than the bottom one,
+ // try to clear a wrong mesh
+ bool isAdjFaceMeshed = false;
+ PShapeIteratorPtr fIt = myHelper->GetAncestors( tgtSM->GetSubShape(),
+ *mesh, TopAbs_FACE );
+ while ( const TopoDS_Shape* f = fIt->next() )
+ if (( isAdjFaceMeshed = mesh->GetSubMesh( *f )->IsMeshComputed() ))
+ break;
+ if ( isAdjFaceMeshed )
+ return toSM( error( TCom("Different nb of segment on logically horizontal edges #")
+ << shapeID( botE ) << " and #"
+ << shapeID( topE ) << ": "
+ << tgtSM->GetSubMeshDS()->NbElements() << " != "
+ << srcSM->GetSubMeshDS()->NbElements() ));
+ tgtSM->ComputeStateEngine( SMESH_subMesh::CLEAN );
+ }
+ if ( !tgtSM->IsMeshComputed() )
+ {
+ // compute nodes on VERTEXes
+ SMESH_subMeshIteratorPtr smIt = tgtSM->getDependsOnIterator(/*includeSelf=*/false);
+ while ( smIt->more() )
+ smIt->next()->ComputeStateEngine( SMESH_subMesh::COMPUTE );
+ // project segments
+ DBGOUT( "COMPUTE H edge (proj) " << tgtSM->GetId());
+ projector1D->myHyp.SetSourceEdge( TopoDS::Edge( srcSM->GetSubShape() ));
+ projector1D->InitComputeError();
+ bool ok = projector1D->Compute( *mesh, tgtSM->GetSubShape() );
+ if ( !ok )
+ {
+ SMESH_ComputeErrorPtr err = projector1D->GetComputeError();
+ if ( err->IsOK() ) err->myName = COMPERR_ALGO_FAILED;
+ tgtSM->GetComputeError() = err;
+ return false;
+ }
+ }
+ tgtSM->ComputeStateEngine( SMESH_subMesh::CHECK_COMPUTE_STATE );
+
+
+ // Compute quad mesh on wall FACEs
+ // -------------------------------
+
+ // make all EDGES meshed
+ fSM->ComputeSubMeshStateEngine( SMESH_subMesh::COMPUTE );
+ if ( !fSM->SubMeshesComputed() )
+ return toSM( error( COMPERR_BAD_INPUT_MESH,
+ "Not all edges have valid algorithm and hypothesis"));
+ // mesh the <face>
+ quadAlgo->InitComputeError();
+ DBGOUT( "COMPUTE Quad face " << fSM->GetId());
+ bool ok = quadAlgo->Compute( *mesh, face );
+ fSM->GetComputeError() = quadAlgo->GetComputeError();
+ if ( !ok )
+ return false;
+ fSM->ComputeStateEngine( SMESH_subMesh::CHECK_COMPUTE_STATE );
+ }
+ if ( myHelper->GetIsQuadratic() )
+ {
+ // fill myHelper with medium nodes built by quadAlgo
+ SMDS_ElemIteratorPtr fIt = fSM->GetSubMeshDS()->GetElements();
+ while ( fIt->more() )
+ myHelper->AddTLinks( dynamic_cast<const SMDS_MeshFace*>( fIt->next() ));
+ }
+ }
+ }
+
+ return true;
+}
+
+//=======================================================================
+/*!
+ * \brief Returns a source EDGE of propagation to a given EDGE
+ */
+//=======================================================================
+
+TopoDS_Edge StdMeshers_Prism_3D::findPropagationSource( const TopoDS_Edge& E )
+{
+ if ( myPropagChains )
+ for ( size_t i = 0; !myPropagChains[i].IsEmpty(); ++i )
+ if ( myPropagChains[i].Contains( E ))
+ return TopoDS::Edge( myPropagChains[i].FindKey( 1 ));
+
+ return TopoDS_Edge();
+}
+
+//=======================================================================
+//function : Evaluate
+//purpose :
+//=======================================================================
+
+bool StdMeshers_Prism_3D::Evaluate(SMESH_Mesh& theMesh,
+ const TopoDS_Shape& theShape,
+ MapShapeNbElems& aResMap)
+{
+ if ( theShape.ShapeType() == TopAbs_COMPOUND )
+ {
+ bool ok = true;
+ for ( TopoDS_Iterator it( theShape ); it.More(); it.Next() )
+ ok &= Evaluate( theMesh, it.Value(), aResMap );
+ return ok;
+ }
+ SMESH_MesherHelper helper( theMesh );
+ myHelper = &helper;
+ myHelper->SetSubShape( theShape );
+
+ // find face contains only triangles
+ vector < SMESH_subMesh * >meshFaces;
+ TopTools_SequenceOfShape aFaces;
+ int NumBase = 0, i = 0, NbQFs = 0;
+ for (TopExp_Explorer exp(theShape, TopAbs_FACE); exp.More(); exp.Next()) {
+ i++;
+ aFaces.Append(exp.Current());
+ SMESH_subMesh *aSubMesh = theMesh.GetSubMesh(exp.Current());
+ meshFaces.push_back(aSubMesh);
+ MapShapeNbElemsItr anIt = aResMap.find(meshFaces[i-1]);
+ if( anIt==aResMap.end() )
+ return toSM( error( "Submesh can not be evaluated"));
+
+ std::vector<int> aVec = (*anIt).second;
+ int nbtri = Max(aVec[SMDSEntity_Triangle],aVec[SMDSEntity_Quad_Triangle]);
+ int nbqua = Max(aVec[SMDSEntity_Quadrangle],aVec[SMDSEntity_Quad_Quadrangle]);
+ if( nbtri==0 && nbqua>0 ) {
+ NbQFs++;
+ }
+ if( nbtri>0 ) {
+ NumBase = i;
+ }
+ }
+
+ if(NbQFs<4) {
+ std::vector<int> aResVec(SMDSEntity_Last);
+ for(int i=SMDSEntity_Node; i<SMDSEntity_Last; i++) aResVec[i] = 0;
+ SMESH_subMesh * sm = theMesh.GetSubMesh(theShape);
+ aResMap.insert(std::make_pair(sm,aResVec));
+ return toSM( error( "Submesh can not be evaluated" ));
+ }
+
+ if(NumBase==0) NumBase = 1; // only quads => set 1 faces as base
+
+ // find number of 1d elems for base face
+ int nb1d = 0;
+ TopTools_MapOfShape Edges1;
+ for (TopExp_Explorer exp(aFaces.Value(NumBase), TopAbs_EDGE); exp.More(); exp.Next()) {
+ Edges1.Add(exp.Current());
+ SMESH_subMesh *sm = theMesh.GetSubMesh(exp.Current());
+ if( sm ) {
+ MapShapeNbElemsItr anIt = aResMap.find(sm);
+ if( anIt == aResMap.end() ) continue;
+ std::vector<int> aVec = (*anIt).second;
+ nb1d += Max(aVec[SMDSEntity_Edge],aVec[SMDSEntity_Quad_Edge]);
+ }
+ }
+ // find face opposite to base face
+ int OppNum = 0;
+ for(i=1; i<=6; i++) {
+ if(i==NumBase) continue;
+ bool IsOpposite = true;
+ for(TopExp_Explorer exp(aFaces.Value(i), TopAbs_EDGE); exp.More(); exp.Next()) {
+ if( Edges1.Contains(exp.Current()) ) {
+ IsOpposite = false;
+ break;
+ }
+ }
+ if(IsOpposite) {
+ OppNum = i;
+ break;
+ }
+ }
+ // find number of 2d elems on side faces
+ int nb2d = 0;
+ for(i=1; i<=6; i++) {
+ if( i==OppNum || i==NumBase ) continue;
+ MapShapeNbElemsItr anIt = aResMap.find( meshFaces[i-1] );
+ if( anIt == aResMap.end() ) continue;
+ std::vector<int> aVec = (*anIt).second;
+ nb2d += Max(aVec[SMDSEntity_Quadrangle],aVec[SMDSEntity_Quad_Quadrangle]);
+ }
+
+ MapShapeNbElemsItr anIt = aResMap.find( meshFaces[NumBase-1] );
+ std::vector<int> aVec = (*anIt).second;
+ bool IsQuadratic = (aVec[SMDSEntity_Quad_Triangle]>aVec[SMDSEntity_Triangle]) ||
+ (aVec[SMDSEntity_Quad_Quadrangle]>aVec[SMDSEntity_Quadrangle]);
+ int nb2d_face0_3 = Max(aVec[SMDSEntity_Triangle],aVec[SMDSEntity_Quad_Triangle]);
+ int nb2d_face0_4 = Max(aVec[SMDSEntity_Quadrangle],aVec[SMDSEntity_Quad_Quadrangle]);
+ int nb0d_face0 = aVec[SMDSEntity_Node];
+ int nb1d_face0_int = ( nb2d_face0_3*3 + nb2d_face0_4*4 - nb1d ) / 2;
+
+ std::vector<int> aResVec(SMDSEntity_Last);
+ for(int i=SMDSEntity_Node; i<SMDSEntity_Last; i++) aResVec[i] = 0;
+ if(IsQuadratic) {
+ aResVec[SMDSEntity_Quad_Penta] = nb2d_face0_3 * ( nb2d/nb1d );
+ aResVec[SMDSEntity_Quad_Hexa] = nb2d_face0_4 * ( nb2d/nb1d );
+ aResVec[SMDSEntity_Node] = nb0d_face0 * ( 2*nb2d/nb1d - 1 ) - nb1d_face0_int * nb2d/nb1d;
+ }
+ else {
+ aResVec[SMDSEntity_Node] = nb0d_face0 * ( nb2d/nb1d - 1 );
+ aResVec[SMDSEntity_Penta] = nb2d_face0_3 * ( nb2d/nb1d );
+ aResVec[SMDSEntity_Hexa] = nb2d_face0_4 * ( nb2d/nb1d );
+ }
+ SMESH_subMesh * sm = theMesh.GetSubMesh(theShape);
+ aResMap.insert(std::make_pair(sm,aResVec));
+
+ return true;
+}
+
+//================================================================================
+/*!
+ * \brief Create prisms
+ * \param columns - columns of nodes generated from nodes of a mesh face
+ * \param helper - helper initialized by mesh and shape to add prisms to
+ */
+//================================================================================
+
+bool StdMeshers_Prism_3D::AddPrisms( vector<const TNodeColumn*> & columns,
+ SMESH_MesherHelper* helper)
+{
+ size_t nbNodes = columns.size();
+ size_t nbZ = columns[0]->size();
+ if ( nbZ < 2 ) return false;
+ for ( size_t i = 1; i < nbNodes; ++i )
+ if ( columns[i]->size() != nbZ )
+ return false;
+
+ // find out orientation
+ bool isForward = true;
+ SMDS_VolumeTool vTool;
+ size_t z = 1;
+ switch ( nbNodes ) {
+ case 3: {
+ SMDS_VolumeOfNodes tmpPenta ( (*columns[0])[z-1], // bottom
+ (*columns[1])[z-1],
+ (*columns[2])[z-1],
+ (*columns[0])[z], // top
+ (*columns[1])[z],
+ (*columns[2])[z] );
+ vTool.Set( &tmpPenta );
+ isForward = vTool.IsForward();
+ break;
+ }
+ case 4: {
+ SMDS_VolumeOfNodes tmpHex( (*columns[0])[z-1], (*columns[1])[z-1], // bottom
+ (*columns[2])[z-1], (*columns[3])[z-1],
+ (*columns[0])[z], (*columns[1])[z], // top
+ (*columns[2])[z], (*columns[3])[z] );
+ vTool.Set( &tmpHex );
+ isForward = vTool.IsForward();
+ break;
+ }
+ default:
+ const int di = (nbNodes+1) / 3;
+ SMDS_VolumeOfNodes tmpVol ( (*columns[0] )[z-1],
+ (*columns[di] )[z-1],
+ (*columns[2*di])[z-1],
+ (*columns[0] )[z],
+ (*columns[di] )[z],
+ (*columns[2*di])[z] );
+ vTool.Set( &tmpVol );
+ isForward = vTool.IsForward();
+ }
+
+ // vertical loop on columns
+
+ helper->SetElementsOnShape( true );
+
+ switch ( nbNodes ) {
+
+ case 3: { // ---------- pentahedra
+ const int i1 = isForward ? 1 : 2;
+ const int i2 = isForward ? 2 : 1;
+ for ( z = 1; z < nbZ; ++z )
+ helper->AddVolume( (*columns[0 ])[z-1], // bottom
+ (*columns[i1])[z-1],
+ (*columns[i2])[z-1],
+ (*columns[0 ])[z], // top
+ (*columns[i1])[z],
+ (*columns[i2])[z] );
+ break;
+ }
+ case 4: { // ---------- hexahedra
+ const int i1 = isForward ? 1 : 3;
+ const int i3 = isForward ? 3 : 1;
+ for ( z = 1; z < nbZ; ++z )
+ helper->AddVolume( (*columns[0])[z-1], (*columns[i1])[z-1], // bottom
+ (*columns[2])[z-1], (*columns[i3])[z-1],
+ (*columns[0])[z], (*columns[i1])[z], // top
+ (*columns[2])[z], (*columns[i3])[z] );
+ break;