-
- //================================================================================
- /*!
- * \brief Merge the two pyramids (i.e. fuse their apex) and others already merged with them
- */
- //================================================================================
-
- void MergePyramids( const SMDS_MeshElement* PrmI,
- const SMDS_MeshElement* PrmJ,
- SMESHDS_Mesh* meshDS,
- TRemTrias& tempTrias,
- set<const SMDS_MeshNode*> & nodesToMove)
- {
- const SMDS_MeshNode* Nrem = PrmJ->GetNode(4); // node to remove
- int nbJ = Nrem->NbInverseElements( SMDSAbs_Volume );
- SMESH_MeshEditor::TNodeXYZ Pj( Nrem );
-
- // an apex node to make common to all merged pyramids
- if (PrmI->GetVtkType() != VTK_PYRAMID) throw SALOME_Exception(LOCALIZED("not a pyramid"));
- SMDS_MeshNode* CommonNode = const_cast<SMDS_MeshNode*>(PrmI->GetNode(4));
- if ( CommonNode == Nrem ) return; // already merged
- int nbI = CommonNode->NbInverseElements( SMDSAbs_Volume );
- SMESH_MeshEditor::TNodeXYZ Pi( CommonNode );
- gp_XYZ Pnew = ( nbI*Pi + nbJ*Pj ) / (nbI+nbJ);
- CommonNode->setXYZ( Pnew.X(), Pnew.Y(), Pnew.Z() );
-
- nodesToMove.insert( CommonNode );
- nodesToMove.erase ( Nrem );
-
- // find and remove coincided faces of merged pyramids
- SMDS_ElemIteratorPtr triItI = CommonNode->GetInverseElementIterator(SMDSAbs_Face);
- while ( triItI->more() )
- {
- const SMDS_MeshElement* FI = triItI->next();
- const SMDS_MeshElement* FJEqual = 0;
- SMDS_ElemIteratorPtr triItJ = Nrem->GetInverseElementIterator(SMDSAbs_Face);
- while ( !FJEqual && triItJ->more() )
- {
- const SMDS_MeshElement* FJ = triItJ->next();
- if ( EqualTriangles( FJ, FI ))
- FJEqual = FJ;
- }
- if ( FJEqual )
- {
- //meshDS->RemoveFreeElement(FI, 0, false);
- //meshDS->RemoveFreeElement(FJEqual, 0, false);
- tempTrias[FI] = false;
- tempTrias[FJEqual] = false;
- }
- }
-
- // set the common apex node to pyramids and triangles merged with J
- SMDS_ElemIteratorPtr itJ = Nrem->GetInverseElementIterator();
- while ( itJ->more() )
- {
- const SMDS_MeshElement* elem = itJ->next();
- if ( elem->GetType() == SMDSAbs_Volume ) // pyramid
- {
- vector< const SMDS_MeshNode* > nodes( elem->begin_nodes(), elem->end_nodes() );
- nodes[4] = CommonNode;
- MESSAGE("ChangeElementNodes");
- meshDS->ChangeElementNodes( elem, &nodes[0], nodes.size());
- }
- else if ( tempTrias.count(elem) ) // tmp triangles
- {
- ((SMDS_VtkFace*) elem )->ChangeApex( CommonNode );
- }
- }
- ASSERT( Nrem->NbInverseElements() == 0 );
- meshDS->RemoveFreeNode( Nrem,
- meshDS->MeshElements( Nrem->getshapeId()),
- /*fromGroups=*/false);
- }
-