From 259cd96526eaf46906cadf3174eebd4780541f3b Mon Sep 17 00:00:00 2001 From: prascle Date: Tue, 21 Dec 2010 04:50:51 +0000 Subject: [PATCH] PR: fix QuadToTriaAdaptor --- src/SMDS/SMDS_MeshNode.cxx | 9 ++-- src/SMDS/SMDS_MeshNode.hxx | 1 + src/SMDS/SMDS_VtkFace.cxx | 4 +- src/SMDS/SMDS_VtkFace.hxx | 2 +- .../StdMeshers_QuadToTriaAdaptor.cxx | 50 +++++++++---------- 5 files changed, 35 insertions(+), 31 deletions(-) diff --git a/src/SMDS/SMDS_MeshNode.cxx b/src/SMDS/SMDS_MeshNode.cxx index acb2f4904..fd6116368 100644 --- a/src/SMDS/SMDS_MeshNode.cxx +++ b/src/SMDS/SMDS_MeshNode.cxx @@ -309,9 +309,12 @@ vtkIdType SMDS_MeshNode::GetVtkType() const //======================================================================= void SMDS_MeshNode::AddInverseElement(const SMDS_MeshElement* ME) { - const SMDS_MeshCell *cell = dynamic_cast(ME); - assert(cell); - SMDS_Mesh::_meshList[myMeshId]->getGrid()->AddReferenceToCell(myVtkID, cell->getVtkId()); + const SMDS_MeshCell *cell = dynamic_cast (ME); + assert(cell); + SMDS_UnstructuredGrid* grid = SMDS_Mesh::_meshList[myMeshId]->getGrid(); + vtkCellLinks *Links = grid->GetCellLinks(); + Links->ResizeCellList(myVtkID, 1); + Links->AddCellReference(cell->getVtkId(), myVtkID); } //======================================================================= diff --git a/src/SMDS/SMDS_MeshNode.hxx b/src/SMDS/SMDS_MeshNode.hxx index 02fc1ef61..773f39fcf 100644 --- a/src/SMDS/SMDS_MeshNode.hxx +++ b/src/SMDS/SMDS_MeshNode.hxx @@ -40,6 +40,7 @@ public: friend class SMESHDS_Mesh; friend class SMDS_Mesh; friend class ObjectPool; + friend class SMDS_VtkFace; void Print(std::ostream & OS) const; double X() const; diff --git a/src/SMDS/SMDS_VtkFace.cxx b/src/SMDS/SMDS_VtkFace.cxx index 7437d1452..0a7d5163f 100644 --- a/src/SMDS/SMDS_VtkFace.cxx +++ b/src/SMDS/SMDS_VtkFace.cxx @@ -249,7 +249,7 @@ SMDS_ElemIteratorPtr SMDS_VtkFace::interlacedNodesElemIterator() const } //! change only the first node, used for temporary triangles in quadrangle to triangle adaptor -void SMDS_VtkFace::ChangeApex(const SMDS_MeshNode* node) +void SMDS_VtkFace::ChangeApex(SMDS_MeshNode* node) { vtkUnstructuredGrid* grid = SMDS_Mesh::_meshList[myMeshId]->getGrid(); vtkIdType npts = 0; @@ -257,6 +257,6 @@ void SMDS_VtkFace::ChangeApex(const SMDS_MeshNode* node) grid->GetCellPoints(myVtkID, npts, pts); grid->RemoveReferenceToCell(pts[0], myVtkID); pts[0] = node->getVtkId(); - grid->AddReferenceToCell(pts[0], myVtkID); + node->AddInverseElement(this), SMDS_Mesh::_meshList[myMeshId]->setMyModified(); } diff --git a/src/SMDS/SMDS_VtkFace.hxx b/src/SMDS/SMDS_VtkFace.hxx index 7a346fd55..ea1bf0ba8 100644 --- a/src/SMDS/SMDS_VtkFace.hxx +++ b/src/SMDS/SMDS_VtkFace.hxx @@ -16,7 +16,7 @@ public: void init(std::vector nodeIds, SMDS_Mesh* mesh); void initPoly(std::vector nodeIds, SMDS_Mesh* mesh); bool ChangeNodes(const SMDS_MeshNode* nodes[], const int nbNodes); - void ChangeApex(const SMDS_MeshNode* node); // to use only for tmp triangles + void ChangeApex(SMDS_MeshNode* node); // to use only for tmp triangles void Print(std::ostream & OS) const; int NbEdges() const; int NbFaces() const; diff --git a/src/StdMeshers/StdMeshers_QuadToTriaAdaptor.cxx b/src/StdMeshers/StdMeshers_QuadToTriaAdaptor.cxx index 25b472c3e..4b9731812 100644 --- a/src/StdMeshers/StdMeshers_QuadToTriaAdaptor.cxx +++ b/src/StdMeshers/StdMeshers_QuadToTriaAdaptor.cxx @@ -82,10 +82,10 @@ namespace 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(PrmI->GetNode(4)); if ( CommonNode == Nrem ) return; // already merged int nbI = CommonNode->NbInverseElements( SMDSAbs_Volume ); - //cerr << __LINE__ << " " << nbI << " " << nbJ << endl; SMESH_MeshEditor::TNodeXYZ Pi( CommonNode ); gp_XYZ Pnew = ( nbI*Pi + nbJ*Pj ) / (nbI+nbJ); CommonNode->setXYZ( Pnew.X(), Pnew.Y(), Pnew.Z() ); @@ -116,7 +116,6 @@ namespace } // set the common apex node to pyramids and triangles merged with J - //cerr << __LINE__ << " NbInverseElements " << Nrem->NbInverseElements() << endl; SMDS_ElemIteratorPtr itJ = Nrem->GetInverseElementIterator(); while ( itJ->more() ) { @@ -124,22 +123,15 @@ namespace if ( elem->GetType() == SMDSAbs_Volume ) // pyramid { vector< const SMDS_MeshNode* > nodes( elem->begin_nodes(), elem->end_nodes() ); - //cerr << __LINE__ << " volId " << elem->GetID() << " nbNodes " << nodes.size() << endl; nodes[4] = CommonNode; MESSAGE("ChangeElementNodes"); meshDS->ChangeElementNodes( elem, &nodes[0], nodes.size()); } else if ( tempTrias.count(elem) ) // tmp triangles { - //cerr << __LINE__ << " triaId " << elem->GetID() << endl; ((SMDS_VtkFace*) elem )->ChangeApex( CommonNode ); } -// else -// { -// cerr << __LINE__ << " other " << elem->GetVtkType() << endl; -// } } - //cerr << __LINE__ << " NbInverseElements " << Nrem->NbInverseElements() << endl; ASSERT( Nrem->NbInverseElements() == 0 ); meshDS->RemoveFreeNode( Nrem, meshDS->MeshElements( Nrem->getshapeId()), @@ -157,6 +149,8 @@ namespace const SMDS_MeshElement* PrmJ, const bool hasShape) { + if (PrmI->GetVtkType() != VTK_PYRAMID) throw SALOME_Exception(LOCALIZED("not a pyramid")); + if (PrmJ->GetVtkType() != VTK_PYRAMID) throw SALOME_Exception(LOCALIZED("not a pyramid")); const SMDS_MeshNode* nApexI = PrmI->GetNode(4); const SMDS_MeshNode* nApexJ = PrmJ->GetNode(4); if ( nApexI == nApexJ || @@ -264,6 +258,7 @@ namespace TRemTrias & tempTrias, set& nodesToMove) { + if (PrmI->GetVtkType() != VTK_PYRAMID) throw SALOME_Exception(LOCALIZED("not a pyramid")); TIDSortedElemSet adjacentPyrams, mergedPyrams; for(int k=0; k<4; k++) // loop on 4 base nodes of PrmI { @@ -302,6 +297,8 @@ namespace StdMeshers_QuadToTriaAdaptor::StdMeshers_QuadToTriaAdaptor(): myElemSearcher(0), myNbTriangles(0) { + myResMap.clear(); + myTempTriangles.clear(); } //================================================================================ @@ -1003,6 +1000,7 @@ bool StdMeshers_QuadToTriaAdaptor::Compute2ndPart(SMESH_Mesh& aMesh) return true; SMESHDS_Mesh * meshDS = aMesh.GetMeshDS(); + if (myPyramids[0]->GetVtkType() != VTK_PYRAMID) throw SALOME_Exception(LOCALIZED("not a pyramid")); int i, j, k, myShapeID = myPyramids[0]->GetNode(4)->getshapeId(); if ( !myElemSearcher ) @@ -1016,6 +1014,7 @@ bool StdMeshers_QuadToTriaAdaptor::Compute2ndPart(SMESH_Mesh& aMesh) for ( i = 0; i < myPyramids.size(); ++i ) { const SMDS_MeshElement* PrmI = myPyramids[i]; + if (PrmI->GetVtkType() != VTK_PYRAMID) throw SALOME_Exception(LOCALIZED("not a pyramid")); MergeAdjacent( PrmI, aMesh, myTempTriangles, nodesToMove ); } @@ -1023,6 +1022,7 @@ bool StdMeshers_QuadToTriaAdaptor::Compute2ndPart(SMESH_Mesh& aMesh) for ( i = 0; i < myPyramids.size(); ++i ) { const SMDS_MeshElement* PrmI = myPyramids[i]; + if (PrmI->GetVtkType() != VTK_PYRAMID) throw SALOME_Exception(LOCALIZED("not a pyramid")); // compare PrmI with all the rest pyramids @@ -1051,6 +1051,7 @@ bool StdMeshers_QuadToTriaAdaptor::Compute2ndPart(SMESH_Mesh& aMesh) for ( j = 0; j < suspectPyrams.size(); ++j ) { const SMDS_MeshElement* PrmJ = suspectPyrams[j]; + //if (PrmJ->GetVtkType() != VTK_PYRAMID) throw SALOME_Exception(LOCALIZED("not a pyramid")); if ( PrmJ == PrmI || PrmJ->NbCornerNodes() != 5 ) continue; if ( myShapeID != PrmJ->GetNode(4)->getshapeId()) @@ -1135,12 +1136,12 @@ bool StdMeshers_QuadToTriaAdaptor::Compute2ndPart(SMESH_Mesh& aMesh) } // loop on all pyramids - if( !nodesToMove.empty() && !meshDS->IsEmbeddedMode() ) - { - set::iterator n = nodesToMove.begin(); - for ( ; n != nodesToMove.end(); ++n ) - meshDS->MoveNode( *n, (*n)->X(), (*n)->Y(), (*n)->Z() ); - } +// if( !nodesToMove.empty() && !meshDS->IsEmbeddedMode() ) +// { +// set::iterator n = nodesToMove.begin(); +// for ( ; n != nodesToMove.end(); ++n ) +// meshDS->MoveNode( *n, (*n)->X(), (*n)->Y(), (*n)->Z() ); +// } // rebind triangles of pyramids sharing the same base quadrangle to the first // entrance of the base quadrangle @@ -1148,31 +1149,30 @@ bool StdMeshers_QuadToTriaAdaptor::Compute2ndPart(SMESH_Mesh& aMesh) for ( ++q2t; q2t != myResMap.end(); ++q2t, ++q2tPrev ) { if ( q2t->first == q2tPrev->first ) - { - //cerr << __LINE__ << " splice" << endl; - q2tPrev->second.splice( q2tPrev->second.end(), q2t->second ); - } + q2tPrev->second.splice( q2tPrev->second.end(), q2t->second ); } // delete removed triangles and count resulting nb of triangles for (q2t = myResMap.begin(); q2t != myResMap.end(); ++q2t) { TTriaList & trias = q2t->second; - vector faceToErase; + set faceToErase; faceToErase.clear(); - //cerr << __LINE__ << " " << trias.size() << endl; for (TTriaList::iterator tri = trias.begin(); tri != trias.end(); ++tri) { - //cerr << " " << __LINE__ << endl; const SMDS_MeshFace* face = *tri; if (myTempTriangles.count(face) && (myTempTriangles[face] == false)) - faceToErase.push_back(face); + faceToErase.insert(face); else myNbTriangles++; } - for (vector::iterator it = faceToErase.begin(); it != faceToErase.end(); ++it) + for (set::iterator it = faceToErase.begin(); it != faceToErase.end(); ++it) { const SMDS_MeshFace *face = dynamic_cast(*it); - if (face) trias.remove(face); + if (face) + { + trias.remove(face); + myTempTriangles.erase(face); + } meshDS->RemoveFreeElement(face, 0, false); } } -- 2.39.2