+ notQuadFaces.push_back( face );
+ }
+ }
+ if ( !notQuadFaces.empty() )
+ {
+ if ( notQuadFaces.size() != 2 )
+ RETURN_BAD_RESULT("Bad nb not quad faces: " << notQuadFaces.size());
+
+ // check total nb faces
+ nbEdge = TAssocTool::Count( notQuadFaces.back(), TopAbs_EDGE, 0 );
+ if ( nbFace != nbEdge + 2 )
+ RETURN_BAD_RESULT("Bad nb of faces: " << nbFace << " but must be " << nbEdge + 2);
+ }
+*/
+ // no hypothesis
+ aStatus = SMESH_Hypothesis::HYP_OK;
+ return true;
+}
+
+//=======================================================================
+//function : Compute
+//purpose : Compute mesh on a COMPOUND of SOLIDs
+//=======================================================================
+
+bool StdMeshers_Prism_3D::Compute(SMESH_Mesh& theMesh, const TopoDS_Shape& theShape)
+{
+ SMESH_MesherHelper helper( theMesh );
+ myHelper = &helper;
+
+ int nbSolids = helper.Count( theShape, TopAbs_SOLID, /*skipSame=*/false );
+ if ( nbSolids < 1 )
+ return true;
+
+ TopTools_IndexedDataMapOfShapeListOfShape faceToSolids;
+ TopExp::MapShapesAndAncestors( theShape, TopAbs_FACE, TopAbs_SOLID, faceToSolids );
+
+ // look for meshed FACEs ("source" FACEs) that must be prism bottoms
+ list< TopoDS_Face > meshedFaces, notQuadMeshedFaces, notQuadFaces;
+ const bool meshHasQuads = ( theMesh.NbQuadrangles() > 0 );
+ //StdMeshers_Quadrangle_2D* quadAlgo = TQuadrangleAlgo::instance( this );
+ for ( int iF = 1; iF <= faceToSolids.Extent(); ++iF )
+ {
+ const TopoDS_Face& face = TopoDS::Face( faceToSolids.FindKey( iF ));
+ SMESH_subMesh* faceSM = theMesh.GetSubMesh( face );
+ if ( !faceSM->IsEmpty() )
+ {
+ if ( !meshHasQuads ||
+ !helper.IsSameElemGeometry( faceSM->GetSubMeshDS(), SMDSGeom_QUADRANGLE ) ||
+ !helper.IsStructured( faceSM )
+ )
+ notQuadMeshedFaces.push_front( face );
+ else if ( myHelper->Count( face, TopAbs_EDGE, /*ignoreSame=*/false ) != 4 )
+ meshedFaces.push_front( face );
+ else
+ meshedFaces.push_back( face );
+ }
+ // not add not quadrilateral FACE as we can't compute it
+ // else if ( !quadAlgo->CheckNbEdges( theMesh, face ))
+ // // not add not quadrilateral FACE as it can be a prism side
+ // // else if ( myHelper->Count( face, TopAbs_EDGE, /*ignoreSame=*/false ) != 4 )
+ // {
+ // notQuadFaces.push_back( face );
+ // }
+ }
+ // notQuadFaces are of medium priority, put them before ordinary meshed faces
+ meshedFaces.splice( meshedFaces.begin(), notQuadFaces );
+ // notQuadMeshedFaces are of highest priority, put them before notQuadFaces
+ meshedFaces.splice( meshedFaces.begin(), notQuadMeshedFaces );
+
+ Prism_3D::TPrismTopo prism;
+
+ if ( nbSolids == 1 )
+ {
+ if ( !meshedFaces.empty() )
+ prism.myBottom = meshedFaces.front();
+ return ( initPrism( prism, TopExp_Explorer( theShape, TopAbs_SOLID ).Current() ) &&
+ compute( prism ));
+ }
+
+ TopTools_MapOfShape meshedSolids;
+ list< Prism_3D::TPrismTopo > meshedPrism;
+ TopTools_ListIteratorOfListOfShape solidIt;
+
+ while ( meshedSolids.Extent() < nbSolids )
+ {
+ if ( _computeCanceled )
+ return toSM( error( SMESH_ComputeError::New(COMPERR_CANCELED)));
+
+ // compute prisms having avident computed source FACE
+ while ( !meshedFaces.empty() )
+ {
+ TopoDS_Face face = meshedFaces.front();
+ meshedFaces.pop_front();
+ TopTools_ListOfShape& solidList = faceToSolids.ChangeFromKey( face );
+ while ( !solidList.IsEmpty() )
+ {
+ TopoDS_Shape solid = solidList.First();
+ solidList.RemoveFirst();
+ if ( meshedSolids.Add( solid ))
+ {
+ prism.Clear();
+ prism.myBottom = face;
+ if ( !initPrism( prism, solid ) ||
+ !compute( prism ))
+ return false;
+
+ meshedFaces.push_front( prism.myTop );
+ meshedPrism.push_back( prism );
+ }
+ }
+ }
+ if ( meshedSolids.Extent() == nbSolids )
+ break;
+
+ // below in the loop we try to find source FACEs somehow
+
+ // project mesh from source FACEs of computed prisms to
+ // prisms sharing wall FACEs
+ list< Prism_3D::TPrismTopo >::iterator prismIt = meshedPrism.begin();
+ for ( ; prismIt != meshedPrism.end(); ++prismIt )
+ {
+ for ( size_t iW = 0; iW < prismIt->myWallQuads.size(); ++iW )
+ {
+ Prism_3D::TQuadList::iterator wQuad = prismIt->myWallQuads[iW].begin();
+ for ( ; wQuad != prismIt->myWallQuads[iW].end(); ++ wQuad )
+ {
+ const TopoDS_Face& wFace = (*wQuad)->face;
+ TopTools_ListOfShape& solidList = faceToSolids.ChangeFromKey( wFace );
+ solidIt.Initialize( solidList );
+ while ( solidIt.More() )
+ {
+ const TopoDS_Shape& solid = solidIt.Value();
+ if ( meshedSolids.Contains( solid )) {
+ solidList.Remove( solidIt );
+ continue; // already computed prism
+ }
+ // find a source FACE of the SOLID: it's a FACE sharing a bottom EDGE with wFace
+ const TopoDS_Edge& wEdge = (*wQuad)->side[ QUAD_TOP_SIDE ]->Edge(0);
+ PShapeIteratorPtr faceIt = myHelper->GetAncestors( wEdge, *myHelper->GetMesh(),
+ TopAbs_FACE);
+ while ( const TopoDS_Shape* f = faceIt->next() )
+ {
+ const TopoDS_Face& candidateF = TopoDS::Face( *f );
+ prism.Clear();
+ prism.myBottom = candidateF;
+ mySetErrorToSM = false;
+ if ( !myHelper->IsSubShape( candidateF, prismIt->myShape3D ) &&
+ !myHelper->GetMesh()->GetSubMesh( candidateF )->IsMeshComputed() &&
+ initPrism( prism, solid ) &&
+ project2dMesh( prismIt->myBottom, candidateF))
+ {
+ mySetErrorToSM = true;
+ if ( !compute( prism ))
+ return false;
+ meshedFaces.push_front( prism.myTop );
+ meshedFaces.push_front( prism.myBottom );
+ meshedPrism.push_back( prism );
+ meshedSolids.Add( solid );
+ }
+ InitComputeError();
+ }
+ mySetErrorToSM = true;
+ InitComputeError();
+ if ( meshedSolids.Contains( solid ))
+ solidList.Remove( solidIt );
+ else
+ solidIt.Next();
+ }
+ }
+ }
+ if ( !meshedFaces.empty() )
+ break; // to compute prisms with avident sources
+ }
+
+ // find FACEs with local 1D hyps, which has to be computed by now,
+ // or at least any computed FACEs
+ for ( int iF = 1; ( meshedFaces.empty() && iF < faceToSolids.Extent() ); ++iF )
+ {
+ const TopoDS_Face& face = TopoDS::Face( faceToSolids.FindKey( iF ));
+ const TopTools_ListOfShape& solidList = faceToSolids.FindFromKey( face );
+ if ( solidList.IsEmpty() ) continue;
+ SMESH_subMesh* faceSM = theMesh.GetSubMesh( face );
+ if ( !faceSM->IsEmpty() )
+ {
+ meshedFaces.push_back( face ); // lower priority
+ }
+ else
+ {
+ bool allSubMeComputed = true;
+ SMESH_subMeshIteratorPtr smIt = faceSM->getDependsOnIterator(false,true);
+ while ( smIt->more() && allSubMeComputed )
+ allSubMeComputed = smIt->next()->IsMeshComputed();
+ if ( allSubMeComputed )
+ {
+ faceSM->ComputeStateEngine( SMESH_subMesh::COMPUTE );
+ if ( !faceSM->IsEmpty() )
+ meshedFaces.push_front( face ); // higher priority
+ else
+ faceSM->ComputeStateEngine( SMESH_subMesh::CHECK_COMPUTE_STATE );
+ }
+ }
+ }
+
+
+ // TODO. there are other ways to find out the source FACE:
+ // propagation, topological similarity, ect.
+
+ // simply try to mesh all not meshed SOLIDs
+ if ( meshedFaces.empty() )
+ {
+ for ( TopExp_Explorer solid( theShape, TopAbs_SOLID ); solid.More(); solid.Next() )
+ {
+ mySetErrorToSM = false;
+ prism.Clear();
+ if ( !meshedSolids.Contains( solid.Current() ) &&
+ initPrism( prism, solid.Current() ))
+ {
+ mySetErrorToSM = true;
+ if ( !compute( prism ))
+ return false;
+ meshedFaces.push_front( prism.myTop );
+ meshedFaces.push_front( prism.myBottom );
+ meshedPrism.push_back( prism );
+ meshedSolids.Add( solid.Current() );
+ }
+ mySetErrorToSM = true;
+ }
+ }
+
+ if ( meshedFaces.empty() ) // set same error to 10 not-computed solids
+ {
+ SMESH_ComputeErrorPtr err = SMESH_ComputeError::New
+ ( COMPERR_BAD_INPUT_MESH, "No meshed source face found", this );
+
+ const int maxNbErrors = 10; // limit nb errors not to overload the Compute dialog
+ TopExp_Explorer solid( theShape, TopAbs_SOLID );
+ for ( int i = 0; ( i < maxNbErrors && solid.More() ); ++i, solid.Next() )
+ if ( !meshedSolids.Contains( solid.Current() ))
+ {
+ SMESH_subMesh* sm = theMesh.GetSubMesh( solid.Current() );
+ sm->GetComputeError() = err;
+ }
+ return error( err );
+ }
+ }
+ return true;
+}
+
+//================================================================================
+/*!
+ * \brief Find wall faces by bottom edges
+ */
+//================================================================================
+
+bool StdMeshers_Prism_3D::getWallFaces( Prism_3D::TPrismTopo & thePrism,
+ const int totalNbFaces)
+{
+ thePrism.myWallQuads.clear();
+
+ SMESH_Mesh* mesh = myHelper->GetMesh();
+
+ StdMeshers_Quadrangle_2D* quadAlgo = TQuadrangleAlgo::instance( this, myHelper );
+
+ TopTools_MapOfShape faceMap;
+ TopTools_IndexedDataMapOfShapeListOfShape edgeToFaces;
+ TopExp::MapShapesAndAncestors( thePrism.myShape3D,
+ TopAbs_EDGE, TopAbs_FACE, edgeToFaces );
+
+ // ------------------------------
+ // Get the 1st row of wall FACEs
+ // ------------------------------
+
+ list< TopoDS_Edge >::iterator edge = thePrism.myBottomEdges.begin();
+ std::list< int >::iterator nbE = thePrism.myNbEdgesInWires.begin();
+ 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"));
+ if ( ! setBottomEdge( *edge, quadList.back(), face ))
+ return toSM( error(TCom("Composite 'horizontal' edges are not supported")));
+ thePrism.myWallQuads.push_back( quadList );
+ faceMap.Add( face );
+ break;
+ }
+ }
+ ++edge;
+ }
+ if ( iE == *nbE )
+ {
+ iE = 0;
+ ++nbE;
+ }
+ }
+
+ // -------------------------
+ // 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 );
+ list< int >::iterator nbEinW = thePrism.myNbEdgesInWires.begin();
+ for ( int iLeft = 0; nbEinW != thePrism.myNbEdgesInWires.end(); ++nbEinW )
+ {
+ thePrism.myRightQuadIndex[ iLeft + *nbEinW - 1 ] = iLeft; // 1st EDGE index of a current WIRE
+ iLeft += *nbEinW;
+ }
+
+ 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_FaceSide *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 )
+ {
+ for ( size_t i = 0; i < thePrism.myWallQuads.size(); ++i )
+ {
+ StdMeshers_FaceSide* 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;
+ }
+ }
+ }
+ }
+ } // 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_FaceSide* 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)));
+
+ // Make all side FACEs of thePrism meshed with quads
+ if ( !computeWalls( thePrism ))
+ return false;
+
+ // Analyse mesh and geometry to find block sub-shapes and submeshes
+ 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
+ myBotToColumnMap.clear();
+ if ( !assocOrProjBottom2Top( bottomToTopTrsf ) ) // it also fills myBotToColumnMap
+ return false;
+
+
+ // Create nodes inside the block
+
+ // try to use transformation (issue 0020680)
+ if ( !trsf.empty() )
+ {
+ // loop on nodes inside the bottom face
+ 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 face
+
+ // column nodes; middle part of the column are zero pointers
+ TNodeColumn& column = bot_column->second;
+ 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
+
+ gp_XYZ coords = tBotNode.GetCoords();
+ trsf[z-1].Transforms( coords );
+ node = meshDS->AddNode( coords.X(), coords.Y(), coords.Z() );
+ meshDS->SetNodeInVolume( node, volumeID );
+ }
+ } // loop on bottom nodes
+ }
+ 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 );
+ }
+ } // 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
+ 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();
+ vector< const TNodeColumn* > columns( 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
+ AddPrisms( columns, myHelper );
+
+ } // loop on bottom mesh faces
+
+ // clear data
+ myBotToColumnMap.clear();
+ myBlock.Clear();
+
+ 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
+ multimap< int, int > wgt2quad;
+ for ( size_t iW = 0; iW != thePrism.myWallQuads.size(); ++iW )
+ {
+ Prism_3D::TQuadList::const_iterator quad = thePrism.myWallQuads[iW].begin();
+ int wgt = 0; // "weight"
+ for ( ; quad != thePrism.myWallQuads[iW].end(); ++quad )
+ {
+ StdMeshers_FaceSide* lftSide = (*quad)->side[ QUAD_LEFT_SIDE ];
+ for ( int i = 0; i < lftSide->NbEdges(); ++i )
+ {
+ ++wgt;
+ const TopoDS_Edge& E = lftSide->Edge(i);
+ if ( mesh->GetSubMesh( E )->IsMeshComputed() )
+ wgt += 10;
+ else if ( mesh->GetHypothesis( E, hyp1dFilter, true )) // local hypothesis!
+ wgt += 100;
+ }
+ }
+ wgt2quad.insert( make_pair( wgt, iW ));
+
+ // 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 ]->SetIgnoreMediumNodes( true );
+ }
+ }
+
+ // 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_FaceSide* rgtSide = (*quad)->side[ QUAD_RIGHT_SIDE ]; // tgt
+ StdMeshers_FaceSide* 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() );
+ 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() )) {
+ ++nbTgtMeshed;
+ nbTgtSegments += tgtSM->GetSubMeshDS()->NbElements();
+ }
+ }
+ if ( rgtSide->NbEdges() == nbTgtMeshed ) // all tgt EDGEs meshed
+ {
+ if ( nbTgtSegments != nbSrcSegments )
+ {
+ 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 ));
+ }
+ 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 );
+ const gp_Pnt p = BRep_Tool::Pnt( rgtSide->LastVertex( edgeIndex ));
+ const int isPrev = ( Abs( srcNodeStr[ iN-1 ].normParam - vertexParam ) <
+ Abs( srcNodeStr[ iN ].normParam - vertexParam ));
+ meshDS->UnSetNodeOnShape( newNodes[ iN-isPrev ] );
+ meshDS->SetNodeOnVertex ( newNodes[ iN-isPrev ], rgtSide->LastVertex( edgeIndex ));
+ meshDS->MoveNode ( newNodes[ iN-isPrev ], p.X(), p.Y(), p.Z() );
+ id2type.first = newNodes[ iN-(1-isPrev) ]->getshapeId();
+ }
+ 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 )
+ {
+ // 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 ]->Edge(0);
+ const TopoDS_Edge& topE = (*quad)->side[ QUAD_TOP_SIDE ]->Edge(0);
+ SMESH_subMesh* botSM = mesh->GetSubMesh( botE );
+ SMESH_subMesh* topSM = mesh->GetSubMesh( topE );
+ SMESH_subMesh* srcSM = botSM;
+ SMESH_subMesh* tgtSM = topSM;
+ if ( !srcSM->IsMeshComputed() && topSM->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
+ }
+ srcSM->ComputeStateEngine( SMESH_subMesh::CHECK_COMPUTE_STATE );
+
+ if ( !tgtSM->IsMeshComputed() )
+ {
+ // compute nodes on VERTEXes
+ tgtSM->ComputeSubMeshStateEngine( 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
+ // -------------------------------
+ const TopoDS_Face& face = (*quad)->face;
+ SMESH_subMesh* fSM = mesh->GetSubMesh( face );
+ if ( ! fSM->IsMeshComputed() )
+ {
+ // 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() ));
+ }