From 53a9669e91942323b40cd607fa33d7403e133c19 Mon Sep 17 00:00:00 2001 From: prascle Date: Wed, 20 Oct 2010 15:21:51 +0000 Subject: [PATCH] PR: debug autotests in progress, still 98 bugs --- src/DriverUNV/DriverUNV_R_SMDS_Mesh.cxx | 12 +- src/SMDS/SMDS_Mesh.cxx | 347 +++++++++++--------- src/SMDS/SMDS_MeshElementIDFactory.cxx | 2 +- src/SMDS/SMDS_UnstructuredGrid.cxx | 2 +- src/SMDS/SMDS_VtkCellIterator.cxx | 12 +- src/SMDS/SMDS_VtkEdge.cxx | 12 +- src/SMDS/SMDS_VtkEdge.hxx | 1 + src/SMDS/SMDS_VtkFace.cxx | 127 ++++--- src/SMDS/SMDS_VtkFace.hxx | 2 + src/SMDS/SMDS_VtkVolume.cxx | 192 ++++++++--- src/SMDS/SMDS_VtkVolume.hxx | 6 + src/SMESH/SMESH_MeshEditor.cxx | 109 +++--- src/SMESH/SMESH_MeshEditor.hxx | 4 +- src/SMESHDS/SMESHDS_Mesh.cxx | 1 + src/SMESHDS/SMESHDS_SubMesh.cxx | 11 +- src/StdMeshers/StdMeshers_Quadrangle_2D.cxx | 8 +- 16 files changed, 514 insertions(+), 334 deletions(-) diff --git a/src/DriverUNV/DriverUNV_R_SMDS_Mesh.cxx b/src/DriverUNV/DriverUNV_R_SMDS_Mesh.cxx index 4e3630b48..7678e1701 100644 --- a/src/DriverUNV/DriverUNV_R_SMDS_Mesh.cxx +++ b/src/DriverUNV/DriverUNV_R_SMDS_Mesh.cxx @@ -65,7 +65,7 @@ Driver_Mesh::Status DriverUNV_R_SMDS_Mesh::Perform() for(; anIter != aDataSet2411.end(); anIter++){ const TNodeLab& aLabel = anIter->first; const TRecord& aRec = anIter->second; - MESSAGE("AddNodeWithID " << aLabel << " " << aRec.coord[0] << " " << aRec.coord[1] << " " << aRec.coord[2]); + //MESSAGE("AddNodeWithID " << aLabel << " " << aRec.coord[0] << " " << aRec.coord[1] << " " << aRec.coord[2]); myMesh->AddNodeWithID(aRec.coord[0],aRec.coord[1],aRec.coord[2],aLabel); } } @@ -83,13 +83,13 @@ Driver_Mesh::Status DriverUNV_R_SMDS_Mesh::Perform() if(IsBeam(aRec.fe_descriptor_id)) { switch ( aRec.node_labels.size() ) { case 2: // edge with two nodes - MESSAGE("add edge " << aLabel << " " << aRec.node_labels[0] << " " << aRec.node_labels[1]); + //MESSAGE("add edge " << aLabel << " " << aRec.node_labels[0] << " " << aRec.node_labels[1]); anElement = myMesh->AddEdgeWithID(aRec.node_labels[0], aRec.node_labels[1], aLabel); break; case 3: // quadratic edge (with 3 nodes) - MESSAGE("add edge " << aLabel << " " << aRec.node_labels[0] << " " << aRec.node_labels[1] << " " << aRec.node_labels[2]); + //MESSAGE("add edge " << aLabel << " " << aRec.node_labels[0] << " " << aRec.node_labels[1] << " " << aRec.node_labels[2]); anElement = myMesh->AddEdgeWithID(aRec.node_labels[0], aRec.node_labels[2], aRec.node_labels[1], @@ -97,7 +97,7 @@ Driver_Mesh::Status DriverUNV_R_SMDS_Mesh::Perform() } } else if(IsFace(aRec.fe_descriptor_id)) { - MESSAGE("add face " << aLabel); + //MESSAGE("add face " << aLabel); switch(aRec.fe_descriptor_id){ case 71: // TRI3 case 72: @@ -113,7 +113,7 @@ Driver_Mesh::Status DriverUNV_R_SMDS_Mesh::Perform() case 42: // Plane Stress Quadratic Triangle - TRI6 case 92: // Thin Shell Quadratic Triangle - TRI6 - MESSAGE("add face " << aLabel << " " << aRec.node_labels[0] << " " << aRec.node_labels[1] << " " << aRec.node_labels[2] << " " << aRec.node_labels[3] << " " << aRec.node_labels[4] << " " << aRec.node_labels[5]); + //MESSAGE("add face " << aLabel << " " << aRec.node_labels[0] << " " << aRec.node_labels[1] << " " << aRec.node_labels[2] << " " << aRec.node_labels[3] << " " << aRec.node_labels[4] << " " << aRec.node_labels[5]); anElement = myMesh->AddFaceWithID(aRec.node_labels[0], aRec.node_labels[2], aRec.node_labels[4], @@ -147,7 +147,7 @@ Driver_Mesh::Status DriverUNV_R_SMDS_Mesh::Perform() } } else if(IsVolume(aRec.fe_descriptor_id)){ - MESSAGE("add volume " << aLabel); + //MESSAGE("add volume " << aLabel); switch(aRec.fe_descriptor_id){ case 111: // Solid Linear Tetrahedron - TET4 diff --git a/src/SMDS/SMDS_Mesh.cxx b/src/SMDS/SMDS_Mesh.cxx index bb600ea23..ec297f49d 100644 --- a/src/SMDS/SMDS_Mesh.cxx +++ b/src/SMDS/SMDS_Mesh.cxx @@ -20,7 +20,7 @@ // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com // -// SMESH SMDS : implementaion of Salome mesh data structure +// SMESH SMDS : implementation of Salome mesh data structure // #ifdef _MSC_VER #pragma warning(disable:4786) @@ -373,7 +373,7 @@ SMDS_MeshFace* SMDS_Mesh::AddFaceWithID(const SMDS_MeshNode * n1, const SMDS_MeshNode * n3, int ID) { - //MESSAGE("AddFaceWithID " << ID) + //MESSAGE("AddFaceWithID " << ID) SMDS_MeshFace * face=createTriangle(n1, n2, n3, ID); // if (face && !registerElement(ID, face)) { @@ -1145,28 +1145,50 @@ SMDS_MeshFace* SMDS_Mesh::AddPolygonalFaceWithID SMDS_MeshFace * face; //if ( myFaces.Extent() % CHECKMEMORY_INTERVAL == 0 ) CheckMemory(); - MESSAGE("AddPolygonalFaceWithID " << ID); if (hasConstructionEdges()) - { - MESSAGE("Error : Not implemented"); - return NULL; - } + { + MESSAGE("Error : Not implemented"); + return NULL; + } else - { - for ( int i = 0; i < nodes.size(); ++i ) + { +#ifdef VTK_HAVE_POLYHEDRON + MESSAGE("AddPolygonalFaceWithID vtk " << ID); + vector nodeIds; + nodeIds.clear(); + vector::iterator it = nodes.begin(); + for ( ; it != nodes.end(); ++it) + nodeIds.push_back((*it)->getId()); + + SMDS_VtkFace *facevtk = myFacePool->getNew(); + facevtk->initPoly(nodeIds, this); + if (!this->registerElement(ID,facevtk)) + { + this->myGrid->GetCellTypesArray()->SetValue(facevtk->getVtkId(), VTK_EMPTY_CELL); + myFacePool->destroy(facevtk); + return 0; + } + face = facevtk; +#else + MESSAGE("AddPolygonalFaceWithID smds " << ID); + for ( int i = 0; i < nodes.size(); ++i ) if ( !nodes[ i ] ) return 0; - face = new SMDS_PolygonalFaceOfNodes(nodes); - adjustmyCellsCapacity(ID); - myCells[ID] = face; - myInfo.myNbPolygons++; - } + face = new SMDS_PolygonalFaceOfNodes(nodes); +#endif + adjustmyCellsCapacity(ID); + myCells[ID] = face; + myInfo.myNbPolygons++; + } - if (!registerElement(ID, face)) { - registerElement(myElementIDFactory->GetFreeID(), face); - //RemoveElement(face, false); - //face = NULL; - } - return face; +#ifndef VTK_HAVE_POLYHEDRON + if (!registerElement(ID, face)) + { + registerElement(myElementIDFactory->GetFreeID(), face); + //RemoveElement(face, false); + //face = NULL; + } +#endif + return face; } /////////////////////////////////////////////////////////////////////////////// @@ -1211,48 +1233,55 @@ SMDS_MeshVolume* SMDS_Mesh::AddPolyhedralVolumeWithID vector quantities, const int ID) { - MESSAGE("AddPolyhedralVolumeWithID" << ID); SMDS_MeshVolume* volume; //if ( myVolumes.Extent() % CHECKMEMORY_INTERVAL == 0 ) CheckMemory(); - if (hasConstructionFaces()) { - MESSAGE("Error : Not implemented"); - return NULL; - } else if (hasConstructionEdges()) { - MESSAGE("Error : Not implemented"); - return NULL; - } else { + if (hasConstructionFaces()) + { + MESSAGE("Error : Not implemented"); + return NULL; + } + else if (hasConstructionEdges()) + { + MESSAGE("Error : Not implemented"); + return NULL; + } + else + { #ifdef VTK_HAVE_POLYHEDRON - vector nodeIds; - nodeIds.clear(); - vector::iterator it = nodes.begin(); - for ( ; it != nodes.end(); ++it) - nodeIds.push_back((*it)->getId()); - - SMDS_VtkVolume *volvtk = myVolumePool->getNew(); - volvtk->initPoly(nodeIds, quantities, this); - if (!this->registerElement(ID,volvtk)) - { - this->myGrid->GetCellTypesArray()->SetValue(volvtk->getVtkId(), VTK_EMPTY_CELL); - myVolumePool->destroy(volvtk); - return 0; - } - volume = volvtk; + MESSAGE("AddPolyhedralVolumeWithID vtk " << ID); + vector nodeIds; + nodeIds.clear(); + vector::iterator it = nodes.begin(); + for (; it != nodes.end(); ++it) + nodeIds.push_back((*it)->getId()); + + SMDS_VtkVolume *volvtk = myVolumePool->getNew(); + volvtk->initPoly(nodeIds, quantities, this); + if (!this->registerElement(ID, volvtk)) + { + this->myGrid->GetCellTypesArray()->SetValue(volvtk->getVtkId(), VTK_EMPTY_CELL); + myVolumePool->destroy(volvtk); + return 0; + } + volume = volvtk; #else - for ( int i = 0; i < nodes.size(); ++i ) + MESSAGE("AddPolyhedralVolumeWithID smds " << ID); + for ( int i = 0; i < nodes.size(); ++i ) if ( !nodes[ i ] ) return 0; - volume = new SMDS_PolyhedralVolumeOfNodes(nodes, quantities); + volume = new SMDS_PolyhedralVolumeOfNodes(nodes, quantities); #endif - adjustmyCellsCapacity(ID); - myCells[ID] = volume; - myInfo.myNbPolyhedrons++; - } + adjustmyCellsCapacity(ID); + myCells[ID] = volume; + myInfo.myNbPolyhedrons++; + } #ifndef VTK_HAVE_POLYHEDRON - if (!registerElement(ID, volume)) { - registerElement(myElementIDFactory->GetFreeID(), volume); - //RemoveElement(volume, false); - //volume = NULL; - } + if (!registerElement(ID, volume)) + { + registerElement(myElementIDFactory->GetFreeID(), volume); + //RemoveElement(volume, false); + //volume = NULL; + } #endif return volume; } @@ -2721,7 +2750,7 @@ void SMDS_Mesh::addChildrenWithNodes(set& setOfChildren switch(element->GetType()) { case SMDSAbs_Node: - MESSAGE("Internal Error: This should not happend"); + MESSAGE("Internal Error: This should not happen"); break; case SMDSAbs_0DElement: { @@ -2803,130 +2832,140 @@ void SMDS_Mesh::RemoveElement(const SMDS_MeshElement * elem, //MESSAGE("SMDS_Mesh::RemoveElement " << elem->GetID() << " " << removenodes); // get finite elements built on elem set * s1; - if (elem->GetType() == SMDSAbs_0DElement || - elem->GetType() == SMDSAbs_Edge && !hasConstructionEdges() || - elem->GetType() == SMDSAbs_Face && !hasConstructionFaces() || - elem->GetType() == SMDSAbs_Volume) - { - s1 = new set(); - s1->insert(elem); - } + if (elem->GetType() == SMDSAbs_0DElement || elem->GetType() == SMDSAbs_Edge && !hasConstructionEdges() + || elem->GetType() == SMDSAbs_Face && !hasConstructionFaces() || elem->GetType() == SMDSAbs_Volume) + { + s1 = new set (); + s1->insert(elem); + } else s1 = getFinitElements(elem); // get exclusive nodes (which would become free afterwards) set * s2; if (elem->GetType() == SMDSAbs_Node) // a node is removed - { - // do not remove nodes except elem - s2 = new set(); - s2->insert(elem); - removenodes = true; - } + { + // do not remove nodes except elem + s2 = new set (); + s2->insert(elem); + removenodes = true; + } else s2 = getExclusiveNodes(*s1); // form the set of finite and construction elements to remove set s3; - set::iterator it=s1->begin(); - while(it!=s1->end()) - { - addChildrenWithNodes(s3, *it ,*s2); - s3.insert(*it); - it++; - } - if(elem->GetType()!=SMDSAbs_Node) s3.insert(elem); - - // remove finite and construction elements - it=s3.begin(); - while(it!=s3.end()) - { - // Remove element from of its nodes - SMDS_ElemIteratorPtr itn=(*it)->nodesIterator(); - while(itn->more()) + set::iterator it = s1->begin(); + while (it != s1->end()) { - SMDS_MeshNode * n = static_cast - (const_cast(itn->next())); - n->RemoveInverseElement( (*it) ); + addChildrenWithNodes(s3, *it, *s2); + s3.insert(*it); + it++; } - int IdToRemove = (*it)->GetID(); - MESSAGE("elem Id to remove " << IdToRemove << " vtktype " << (*it)->GetVtkType()); - switch((*it)->GetType()) + if (elem->GetType() != SMDSAbs_Node) + s3.insert(elem); + + // remove finite and construction elements + it = s3.begin(); + while (it != s3.end()) { - case SMDSAbs_Node: - MYASSERT("Internal Error: This should not happen"); - break; - case SMDSAbs_0DElement: - if (IdToRemove >= 0) - { - myCells[IdToRemove] = 0; // -PR- ici ou dans myElementIDFactory->ReleaseID ? - myInfo.remove(*it); - } - removedElems.push_back( (*it) ); - myElementIDFactory->ReleaseID(IdToRemove); - delete (*it); - break; - case SMDSAbs_Edge: - if (IdToRemove >= 0) - { - myCells[IdToRemove] = 0; - myInfo.RemoveEdge(*it); - } - removedElems.push_back( (*it) ); - myElementIDFactory->ReleaseID(IdToRemove); - if (const SMDS_VtkEdge* vtkElem = dynamic_cast(*it)) - myEdgePool->destroy((SMDS_VtkEdge*)vtkElem); - else delete (*it); - break; - case SMDSAbs_Face: - if (IdToRemove >= 0) + // Remove element from of its nodes + SMDS_ElemIteratorPtr itn = (*it)->nodesIterator(); + while (itn->more()) { - myCells[IdToRemove] = 0; - myInfo.RemoveFace(*it); + SMDS_MeshNode * n = static_cast (const_cast (itn->next())); + n->RemoveInverseElement((*it)); } - removedElems.push_back( (*it) ); - myElementIDFactory->ReleaseID(IdToRemove); - if (const SMDS_VtkFace* vtkElem = dynamic_cast(*it)) - myFacePool->destroy((SMDS_VtkFace*)vtkElem); - else delete (*it); - break; - case SMDSAbs_Volume: - if (IdToRemove >= 0) + int IdToRemove = (*it)->GetID(); + int vtkid = this->fromSmdsToVtk(IdToRemove); + //MESSAGE("elem Id to remove " << IdToRemove << " vtkid " << vtkid << + // " vtktype " << (*it)->GetVtkType() << " type " << (*it)->GetType()); + switch ((*it)->GetType()) + { + case SMDSAbs_Node: + MYASSERT("Internal Error: This should not happen") + ; + break; + case SMDSAbs_0DElement: + if (IdToRemove >= 0) + { + myCells[IdToRemove] = 0; // -PR- ici ou dans myElementIDFactory->ReleaseID ? + myInfo.remove(*it); + } + removedElems.push_back((*it)); + myElementIDFactory->ReleaseID(IdToRemove); + delete (*it); + break; + case SMDSAbs_Edge: + if (IdToRemove >= 0) + { + myCells[IdToRemove] = 0; + myInfo.RemoveEdge(*it); + } + removedElems.push_back((*it)); + myElementIDFactory->ReleaseID(IdToRemove); + if (const SMDS_VtkEdge* vtkElem = dynamic_cast(*it)) + myEdgePool->destroy((SMDS_VtkEdge*) vtkElem); + else + delete (*it); + break; + case SMDSAbs_Face: + if (IdToRemove >= 0) + { + myCells[IdToRemove] = 0; + myInfo.RemoveFace(*it); + } + removedElems.push_back((*it)); + myElementIDFactory->ReleaseID(IdToRemove); + if (const SMDS_VtkFace* vtkElem = dynamic_cast(*it)) + myFacePool->destroy((SMDS_VtkFace*) vtkElem); + else + delete (*it); + break; + case SMDSAbs_Volume: + if (IdToRemove >= 0) + { + myCells[IdToRemove] = 0; + myInfo.RemoveVolume(*it); + } + removedElems.push_back((*it)); + myElementIDFactory->ReleaseID(IdToRemove); + if (const SMDS_VtkVolume* vtkElem = dynamic_cast(*it)) + myVolumePool->destroy((SMDS_VtkVolume*) vtkElem); + else + delete (*it); + break; + } + if (vtkid >= 0) { - myCells[IdToRemove] = 0; - myInfo.RemoveVolume(*it); + //MESSAGE("VTK_EMPTY_CELL in " << vtkid); + this->myGrid->GetCellTypesArray()->SetValue(vtkid, VTK_EMPTY_CELL); } - removedElems.push_back( (*it) ); - myElementIDFactory->ReleaseID(IdToRemove); - if (const SMDS_VtkVolume* vtkElem = dynamic_cast(*it)) - myVolumePool->destroy((SMDS_VtkVolume*)vtkElem); - else delete (*it); - break; + it++; } - it++; - } // remove exclusive (free) nodes - if(removenodes) - { - it=s2->begin(); - while(it!=s2->end()) + if (removenodes) { - int IdToRemove = (*it)->GetID(); - MESSAGE( "SMDS: RM node " << IdToRemove); - if (IdToRemove >= 0) + it = s2->begin(); + while (it != s2->end()) { - myNodes[IdToRemove] = 0; - myInfo.myNbNodes--; + int IdToRemove = (*it)->GetID(); + //MESSAGE( "SMDS: RM node " << IdToRemove); + if (IdToRemove >= 0) + { + myNodes[IdToRemove] = 0; + myInfo.myNbNodes--; + } + myNodeIDFactory->ReleaseID((*it)->GetID()); + removedNodes.push_back((*it)); + if (const SMDS_MeshNode* vtkElem = dynamic_cast(*it)) + myNodePool->destroy((SMDS_MeshNode*) vtkElem); + else + delete (*it); + it++; } - myNodeIDFactory->ReleaseID((*it)->GetID()); - removedNodes.push_back( (*it) ); - if (const SMDS_MeshNode* vtkElem = dynamic_cast(*it)) - myNodePool->destroy((SMDS_MeshNode*)vtkElem); - else delete (*it); - it++; } - } delete s2; delete s1; diff --git a/src/SMDS/SMDS_MeshElementIDFactory.cxx b/src/SMDS/SMDS_MeshElementIDFactory.cxx index 2287086b6..e6755edc5 100644 --- a/src/SMDS/SMDS_MeshElementIDFactory.cxx +++ b/src/SMDS/SMDS_MeshElementIDFactory.cxx @@ -134,7 +134,7 @@ void SMDS_MeshElementIDFactory::ReleaseID(const int ID) { if (ID < 0) { - MESSAGE("~~~~~~~~~~~~~~ SMDS_MeshElementIDFactory::ReleaseID ID = " << ID); + //MESSAGE("~~~~~~~~~~~~~~ SMDS_MeshElementIDFactory::ReleaseID ID = " << ID); return; } int vtkId = myMesh->myIDElements[ID]; diff --git a/src/SMDS/SMDS_UnstructuredGrid.cxx b/src/SMDS/SMDS_UnstructuredGrid.cxx index e5d8a7868..08eb325c6 100644 --- a/src/SMDS/SMDS_UnstructuredGrid.cxx +++ b/src/SMDS/SMDS_UnstructuredGrid.cxx @@ -264,7 +264,7 @@ void SMDS_UnstructuredGrid::compactGrid(std::vector& idNodesOldToNew, int n MESSAGE(" -------- newCellSize, endBloc " << endBloc << " " << oldCellSize); copyBloc(newTypes, idCellsOldToNew, idNodesOldToNew, newConnectivity, newLocations, pointsCell, alreadyCopied, startBloc, endBloc); - compactState = lookHoleStart; + compactState = lookHoleEnd; } break; } diff --git a/src/SMDS/SMDS_VtkCellIterator.cxx b/src/SMDS/SMDS_VtkCellIterator.cxx index 4c1ed5632..3346bc101 100644 --- a/src/SMDS/SMDS_VtkCellIterator.cxx +++ b/src/SMDS/SMDS_VtkCellIterator.cxx @@ -104,7 +104,7 @@ SMDS_VtkCellIteratorToUNV::SMDS_VtkCellIteratorToUNV(SMDS_Mesh* mesh, _cellId = vtkCellId; _index = 0; _type = aType; - MESSAGE("SMDS_VtkCellInterlacedIterator " << _type); + //MESSAGE("SMDS_VtkCellInterlacedIterator " << _type); _vtkIdList = vtkIdList::New(); vtkIdType* pts; @@ -164,19 +164,11 @@ SMDS_VtkCellIteratorToUNV::SMDS_VtkCellIteratorToUNV(SMDS_Mesh* mesh, } case SMDSEntity_Polygon: case SMDSEntity_Quad_Polygon: - { - MESSAGE("SMDS_VtkCellIterator polygon"); - break; - } case SMDSEntity_Polyhedra: case SMDSEntity_Quad_Polyhedra: - { - MESSAGE("SMDS_VtkCellIterator Polyhedra"); - break; - } default: { - static int id[] = {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19}; + static int id[] = {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29}; ids = id; break; } diff --git a/src/SMDS/SMDS_VtkEdge.cxx b/src/SMDS/SMDS_VtkEdge.cxx index ecd723f65..f893a752d 100644 --- a/src/SMDS/SMDS_VtkEdge.cxx +++ b/src/SMDS/SMDS_VtkEdge.cxx @@ -58,6 +58,15 @@ bool SMDS_VtkEdge::ChangeNodes(const SMDS_MeshNode* nodes[], const int nbNodes) return true; } +bool SMDS_VtkEdge::IsMediumNode(const SMDS_MeshNode* node) const +{ + vtkUnstructuredGrid* grid = SMDS_Mesh::_meshList[myMeshId]->getGrid(); + vtkIdType npts = 0; + vtkIdType* pts = 0; + grid->GetCellPoints(myVtkID, npts, pts); + return ((npts == 3) && (node->GetID() == pts[2])); +} + void SMDS_VtkEdge::Print(std::ostream & OS) const { OS << "edge <" << GetID() << "> : "; @@ -101,7 +110,8 @@ vtkIdType SMDS_VtkEdge::GetVtkType() const const SMDS_MeshNode* SMDS_VtkEdge::GetNode(const int ind) const { - return SMDS_MeshElement::GetNode(ind); // --- a optimiser ! + // TODO optimize !! + return SMDS_MeshElement::GetNode(ind); } bool SMDS_VtkEdge::IsQuadratic() const diff --git a/src/SMDS/SMDS_VtkEdge.hxx b/src/SMDS/SMDS_VtkEdge.hxx index 19baccea6..1f1cddcbe 100644 --- a/src/SMDS/SMDS_VtkEdge.hxx +++ b/src/SMDS/SMDS_VtkEdge.hxx @@ -17,6 +17,7 @@ public: void init(std::vector nodeIds, SMDS_Mesh* mesh); bool ChangeNodes(const SMDS_MeshNode * node1, const SMDS_MeshNode * node2); virtual bool ChangeNodes(const SMDS_MeshNode* nodes[], const int nbNodes); + virtual bool IsMediumNode(const SMDS_MeshNode* node) const; void Print(std::ostream & OS) const; int NbNodes() const; diff --git a/src/SMDS/SMDS_VtkFace.cxx b/src/SMDS/SMDS_VtkFace.cxx index 7a52ed4f1..fc6e591ab 100644 --- a/src/SMDS/SMDS_VtkFace.cxx +++ b/src/SMDS/SMDS_VtkFace.cxx @@ -43,12 +43,20 @@ void SMDS_VtkFace::init(std::vector nodeIds, SMDS_Mesh* mesh) aType = VTK_QUADRATIC_QUAD; break; default: - aType = VTK_TRIANGLE; + aType = VTK_POLYGON; break; } myVtkID = grid->InsertNextLinkedCell(aType, nodeIds.size(), &nodeIds[0]); } +void SMDS_VtkFace::initPoly(std::vector nodeIds, SMDS_Mesh* mesh) +{ + vtkUnstructuredGrid* grid = mesh->getGrid(); + myIdInShape = -1; + myMeshId = mesh->getMeshId(); + myVtkID = grid->InsertNextLinkedCell(VTK_POLYGON, nodeIds.size(), &nodeIds[0]); +} + bool SMDS_VtkFace::ChangeNodes(const SMDS_MeshNode* nodes[], const int nbNodes) { vtkUnstructuredGrid* grid = SMDS_Mesh::_meshList[myMeshId]->getGrid(); @@ -60,7 +68,7 @@ bool SMDS_VtkFace::ChangeNodes(const SMDS_MeshNode* nodes[], const int nbNodes) MESSAGE("ChangeNodes problem: not the same number of nodes " << npts << " -> " << nbNodes); return false; } - for (int i=0; iGetID(); } @@ -69,24 +77,31 @@ bool SMDS_VtkFace::ChangeNodes(const SMDS_MeshNode* nodes[], const int nbNodes) void SMDS_VtkFace::Print(std::ostream & OS) const { - OS << "edge <" << GetID() << "> : "; + OS << "face <" << GetID() << "> : "; } int SMDS_VtkFace::NbEdges() const { - switch (NbNodes()) + // TODO quadratic polygons ? + vtkUnstructuredGrid* grid = SMDS_Mesh::_meshList[myMeshId]->getGrid(); + vtkIdType aVtkType = grid->GetCellType(this->myVtkID); + int nbEdges = 3; + switch (aVtkType) { - case 3: - case 6: - return 3; - case 4: - case 8: - return 4; + case VTK_TRIANGLE: + case VTK_QUADRATIC_TRIANGLE: + nbEdges = 3; + break; + case VTK_QUAD: + case VTK_QUADRATIC_QUAD: + nbEdges = 4; + break; + case VTK_POLYGON: default: - MESSAGE("invalid number of nodes") - ; + nbEdges = grid->GetCell(myVtkID)->GetNumberOfPoints(); + break; } - return 0; + return nbEdges; } int SMDS_VtkFace::NbFaces() const @@ -114,63 +129,73 @@ SMDS_VtkFace::GetNode(const int ind) const bool SMDS_VtkFace::IsQuadratic() const { - if (this->NbNodes() > 5) - return true; - else - return false; + vtkUnstructuredGrid* grid = SMDS_Mesh::_meshList[myMeshId]->getGrid(); + vtkIdType aVtkType = grid->GetCellType(this->myVtkID); + // TODO quadratic polygons ? + switch (aVtkType) + { + case VTK_QUADRATIC_TRIANGLE: + case VTK_QUADRATIC_QUAD: + return true; + break; + default: + return false; + } +} + +bool SMDS_VtkFace::IsPoly() const +{ + vtkUnstructuredGrid* grid = SMDS_Mesh::_meshList[myMeshId]->getGrid(); + vtkIdType aVtkType = grid->GetCellType(this->myVtkID); + return (aVtkType == VTK_POLYGON); } SMDSAbs_EntityType SMDS_VtkFace::GetEntityType() const { + vtkUnstructuredGrid* grid = SMDS_Mesh::_meshList[myMeshId]->getGrid(); + vtkIdType aVtkType = grid->GetCellType(this->myVtkID); SMDSAbs_EntityType aType = SMDSEntity_Polygon; - switch (NbNodes()) + switch (aVtkType) { - case 3: + case VTK_TRIANGLE: aType = SMDSEntity_Triangle; break; - case 6: - aType = SMDSEntity_Quad_Triangle; - break; - case 4: + case VTK_QUAD: aType = SMDSEntity_Quadrangle; break; - case 8: + case VTK_QUADRATIC_TRIANGLE: + aType = SMDSEntity_Quad_Triangle; + break; + case VTK_QUADRATIC_QUAD: aType = SMDSEntity_Quad_Quadrangle; break; + default: + aType = SMDSEntity_Polygon; } return aType; } -vtkIdType SMDS_VtkFace::GetVtkType() const -{ - switch (NbNodes()) + vtkIdType SMDS_VtkFace::GetVtkType() const { - case 3: - return VTK_TRIANGLE; - case 6: - return VTK_QUADRATIC_TRIANGLE; - case 4: - return VTK_QUAD; - case 8: - return VTK_QUADRATIC_QUAD; - default: - return VTK_POLYGON; + vtkUnstructuredGrid* grid = SMDS_Mesh::_meshList[myMeshId]->getGrid(); + vtkIdType aVtkType = grid->GetCellType(this->myVtkID); + return aVtkType; } -} -SMDS_ElemIteratorPtr SMDS_VtkFace::elementsIterator(SMDSAbs_ElementType type) const -{ - switch (type) + SMDS_ElemIteratorPtr SMDS_VtkFace::elementsIterator(SMDSAbs_ElementType type) const { - case SMDSAbs_Node: - return SMDS_ElemIteratorPtr(new SMDS_VtkCellIterator(SMDS_Mesh::_meshList[myMeshId], myVtkID, GetEntityType())); - default: - MESSAGE("ERROR : Iterator not implemented"); - return SMDS_ElemIteratorPtr((SMDS_ElemIterator*) NULL); + switch (type) + { + case SMDSAbs_Node: + return SMDS_ElemIteratorPtr(new SMDS_VtkCellIterator(SMDS_Mesh::_meshList[myMeshId], myVtkID, GetEntityType())); + default: + MESSAGE("ERROR : Iterator not implemented") + ; + return SMDS_ElemIteratorPtr((SMDS_ElemIterator*) NULL); + } } -} -SMDS_ElemIteratorPtr SMDS_VtkFace::nodesIteratorToUNV() const -{ - return SMDS_ElemIteratorPtr(new SMDS_VtkCellIteratorToUNV(SMDS_Mesh::_meshList[myMeshId], myVtkID, GetEntityType())); -} + SMDS_ElemIteratorPtr SMDS_VtkFace::nodesIteratorToUNV() const + { + return SMDS_ElemIteratorPtr(new SMDS_VtkCellIteratorToUNV(SMDS_Mesh::_meshList[myMeshId], myVtkID, GetEntityType())); + } diff --git a/src/SMDS/SMDS_VtkFace.hxx b/src/SMDS/SMDS_VtkFace.hxx index ecc0585ec..baa4b9ac6 100644 --- a/src/SMDS/SMDS_VtkFace.hxx +++ b/src/SMDS/SMDS_VtkFace.hxx @@ -14,6 +14,7 @@ public: SMDS_VtkFace(std::vector nodeIds, SMDS_Mesh* mesh); ~SMDS_VtkFace(); 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 Print(std::ostream & OS) const; @@ -25,6 +26,7 @@ public: virtual SMDSAbs_EntityType GetEntityType() const; virtual const SMDS_MeshNode* GetNode(const int ind) const; virtual bool IsQuadratic() const; + virtual bool IsPoly() const; protected: virtual SMDS_ElemIteratorPtr elementsIterator(SMDSAbs_ElementType type) const; diff --git a/src/SMDS/SMDS_VtkVolume.cxx b/src/SMDS/SMDS_VtkVolume.cxx index 7bb479925..88af62331 100644 --- a/src/SMDS/SMDS_VtkVolume.cxx +++ b/src/SMDS/SMDS_VtkVolume.cxx @@ -63,6 +63,9 @@ void SMDS_VtkVolume::initPoly(std::vector nodeIds, std::vector n { MESSAGE("SMDS_VtkVolume::initPoly"); SMDS_UnstructuredGrid* grid = mesh->getGrid(); + // TODO is it useful to orient faces ? + double center[3]; + this->gravityCenter(grid, &nodeIds[0], nodeIds.size(), ¢er[0]); vector ptIds; ptIds.clear(); vtkIdType nbFaces = nbNodesPerFace.size(); @@ -71,11 +74,22 @@ void SMDS_VtkVolume::initPoly(std::vector nodeIds, std::vector n { int nf = nbNodesPerFace[i]; ptIds.push_back(nf); - for (int n = 0; n < nf; n++) - { - ptIds.push_back(nodeIds[k]); - k++; - } + double a[3]; + double b[3]; + double c[3]; + grid->GetPoints()->GetPoint(nodeIds[k],a); + grid->GetPoints()->GetPoint(nodeIds[k+1],b); + grid->GetPoints()->GetPoint(nodeIds[k+2],c); + bool isFaceForward = this->isForward(a, b, c, center); + //MESSAGE("isFaceForward " << i << " " << isFaceForward); + vtkIdType *facePts = &nodeIds[k]; + if (isFaceForward) + for (int n = 0; n < nf; n++) + ptIds.push_back(facePts[n]); + else + for (int n = nf-1; n >= 0; n--) + ptIds.push_back(facePts[n]); + k += nf; } myVtkID = grid->InsertNextLinkedCell(VTK_POLYHEDRON, nbFaces, &ptIds[0]); } @@ -110,26 +124,38 @@ void SMDS_VtkVolume::Print(ostream & OS) const int SMDS_VtkVolume::NbFaces() const { - // TODO polyedres - switch (NbNodes()) + vtkUnstructuredGrid* grid = SMDS_Mesh::_meshList[myMeshId]->getGrid(); + vtkIdType aVtkType = grid->GetCellType(this->myVtkID); + int nbFaces = 4; + switch (aVtkType) { - case 4: - case 10: - return 4; - case 5: - case 13: - return 5; - case 6: - case 15: - return 5; - case 8: - case 20: - return 6; + case VTK_TETRA: + case VTK_QUADRATIC_TETRA: + nbFaces = 4; + break; + case VTK_PYRAMID: + case VTK_WEDGE: + case VTK_QUADRATIC_PYRAMID: + case VTK_QUADRATIC_WEDGE: + nbFaces = 5; + break; + case VTK_HEXAHEDRON: + case VTK_QUADRATIC_HEXAHEDRON: + nbFaces = 6; + break; + case VTK_POLYHEDRON: + { + vtkIdType nFaces = 0; + vtkIdType* ptIds = 0; + grid->GetFaceStream(this->myVtkID, nFaces, ptIds); + nbFaces = nFaces; + } default: - MESSAGE("invalid number of nodes") - ; + MESSAGE("invalid volume type"); + nbFaces = 0; + break; } - return 0; + return nbFaces; } int SMDS_VtkVolume::NbNodes() const @@ -141,26 +167,49 @@ int SMDS_VtkVolume::NbNodes() const int SMDS_VtkVolume::NbEdges() const { - // TODO polyedres - switch (NbNodes()) + vtkUnstructuredGrid* grid = SMDS_Mesh::_meshList[myMeshId]->getGrid(); + vtkIdType aVtkType = grid->GetCellType(this->myVtkID); + int nbEdges = 6; + switch (aVtkType) { - case 4: - case 10: - return 6; - case 5: - case 13: - return 8; - case 6: - case 15: - return 9; - case 8: - case 20: - return 12; + case VTK_TETRA: + case VTK_QUADRATIC_TETRA: + nbEdges = 6; + break; + case VTK_PYRAMID: + case VTK_QUADRATIC_PYRAMID: + nbEdges = 8; + break; + case VTK_WEDGE: + case VTK_QUADRATIC_WEDGE: + nbEdges = 9; + break; + case VTK_HEXAHEDRON: + case VTK_QUADRATIC_HEXAHEDRON: + nbEdges = 12; + break; + case VTK_POLYHEDRON: + { + vtkIdType nFaces = 0; + vtkIdType* ptIds = 0; + grid->GetFaceStream(this->myVtkID, nFaces, ptIds); + nbEdges = 0; + int id = 0; + for (int i = 0; i < nFaces; i++) + { + int edgesInFace = ptIds[id]; + id += (edgesInFace + 1); + nbEdges += edgesInFace; + } + nbEdges = nbEdges / 2; + break; + } default: - MESSAGE("invalid number of nodes") - ; + MESSAGE("invalid volume type"); + nbEdges = 0; + break; } - return 0; + return nbEdges; } SMDS_ElemIteratorPtr SMDS_VtkVolume::elementsIterator(SMDSAbs_ElementType type) const @@ -198,17 +247,33 @@ const SMDS_MeshNode* SMDS_VtkVolume::GetNode(const int ind) const bool SMDS_VtkVolume::IsQuadratic() const { - // TODO polyedres - if (this->NbNodes() > 9) - return true; - else - return false; + vtkUnstructuredGrid* grid = SMDS_Mesh::_meshList[myMeshId]->getGrid(); + vtkIdType aVtkType = grid->GetCellType(this->myVtkID); + // TODO quadratic polyhedrons ? + switch (aVtkType) + { + case VTK_QUADRATIC_TETRA: + case VTK_QUADRATIC_PYRAMID: + case VTK_QUADRATIC_WEDGE: + case VTK_QUADRATIC_HEXAHEDRON: + return true; + break; + default: + return false; + } +} + +bool SMDS_VtkVolume::IsPoly() const +{ + vtkUnstructuredGrid* grid = SMDS_Mesh::_meshList[myMeshId]->getGrid(); + vtkIdType aVtkType = grid->GetCellType(this->myVtkID); + return (aVtkType == VTK_POLYHEDRON); } SMDSAbs_EntityType SMDS_VtkVolume::GetEntityType() const { - // TODO see SMDS_MeshElementIDFactory::GetVtkCellType - vtkIdType aVtkType = this->GetVtkType(); + vtkUnstructuredGrid* grid = SMDS_Mesh::_meshList[myMeshId]->getGrid(); + vtkIdType aVtkType = grid->GetCellType(this->myVtkID); SMDSAbs_EntityType aType = SMDSEntity_Tetra; switch (aVtkType) @@ -255,3 +320,38 @@ vtkIdType SMDS_VtkVolume::GetVtkType() const vtkIdType aType = grid->GetCellType(myVtkID); return aType; } + + void SMDS_VtkVolume::gravityCenter(SMDS_UnstructuredGrid* grid, vtkIdType *nodeIds, int nbNodes, double* result) +{ + for (int j=0; j<3; j++) + result[j] = 0; + if (nbNodes <= 0) + return; + for (int i =0; i< nbNodes; i++) + { + double *coords = grid->GetPoint(nodeIds[i]); + for (int j=0; j<3; j++) + result[j] += coords[j]; + } + for (int j=0; j<3; j++) + result[j] = result[j]/nbNodes; + //MESSAGE("center " << result[0] << " " << result[1] << " " << result[2]); + return; +} + + bool SMDS_VtkVolume::isForward(double* a,double* b,double* c,double* d) + { + double u[3], v[3], w[3]; + for (int j = 0; j < 3; j++) + { + //MESSAGE("a,b,c,d " << a[j] << " " << b[j] << " " << c[j] << " " << d[j]); + u[j] = b[j] - a[j]; + v[j] = c[j] - a[j]; + w[j] = d[j] - a[j]; + //MESSAGE("u,v,w " << u[j] << " " << v[j] << " " << w[j]); + } + double prodmixte = (u[2] * v[3] - u[3] * v[2]) * w[1] + + (u[3] * v[1] - u[1] * v[3]) * w[2] + + (u[1] * v[2] - u[2] * v[1]) * w[3]; + return (prodmixte >= 0); +} diff --git a/src/SMDS/SMDS_VtkVolume.hxx b/src/SMDS/SMDS_VtkVolume.hxx index 1b8360d94..68f3d7877 100644 --- a/src/SMDS/SMDS_VtkVolume.hxx +++ b/src/SMDS/SMDS_VtkVolume.hxx @@ -28,6 +28,12 @@ public: virtual SMDSAbs_EntityType GetEntityType() const; virtual const SMDS_MeshNode* GetNode(const int ind) const; virtual bool IsQuadratic() const; + virtual bool IsPoly() const; + static void gravityCenter(SMDS_UnstructuredGrid* grid, + vtkIdType *nodeIds, + int nbNodes, + double* result); + static bool isForward(double* a,double* b,double* c,double* d); protected: virtual SMDS_ElemIteratorPtr elementsIterator(SMDSAbs_ElementType type) const; diff --git a/src/SMESH/SMESH_MeshEditor.cxx b/src/SMESH/SMESH_MeshEditor.cxx index f9e79c551..543bace8a 100644 --- a/src/SMESH/SMESH_MeshEditor.cxx +++ b/src/SMESH/SMESH_MeshEditor.cxx @@ -124,75 +124,76 @@ SMESH_MeshEditor::AddElement(const vector & node, const bool isPoly, const int ID) { + //MESSAGE("AddElement " <Add0DElementWithID(node[0], ID); + if ( ID >= 0 ) e = mesh->Add0DElementWithID(node[0], ID); else e = mesh->Add0DElement (node[0] ); break; case SMDSAbs_Edge: if ( nbnode == 2 ) - if ( ID ) e = mesh->AddEdgeWithID(node[0], node[1], ID); + if ( ID >= 0 ) e = mesh->AddEdgeWithID(node[0], node[1], ID); else e = mesh->AddEdge (node[0], node[1] ); else if ( nbnode == 3 ) - if ( ID ) e = mesh->AddEdgeWithID(node[0], node[1], node[2], ID); + if ( ID >= 0 ) e = mesh->AddEdgeWithID(node[0], node[1], node[2], ID); else e = mesh->AddEdge (node[0], node[1], node[2] ); break; case SMDSAbs_Face: if ( !isPoly ) { if (nbnode == 3) - if ( ID ) e = mesh->AddFaceWithID(node[0], node[1], node[2], ID); + if ( ID >= 0 ) e = mesh->AddFaceWithID(node[0], node[1], node[2], ID); else e = mesh->AddFace (node[0], node[1], node[2] ); else if (nbnode == 4) - if ( ID ) e = mesh->AddFaceWithID(node[0], node[1], node[2], node[3], ID); + if ( ID >= 0 ) e = mesh->AddFaceWithID(node[0], node[1], node[2], node[3], ID); else e = mesh->AddFace (node[0], node[1], node[2], node[3] ); else if (nbnode == 6) - if ( ID ) e = mesh->AddFaceWithID(node[0], node[1], node[2], node[3], + if ( ID >= 0 ) e = mesh->AddFaceWithID(node[0], node[1], node[2], node[3], node[4], node[5], ID); else e = mesh->AddFace (node[0], node[1], node[2], node[3], node[4], node[5] ); else if (nbnode == 8) - if ( ID ) e = mesh->AddFaceWithID(node[0], node[1], node[2], node[3], + if ( ID >= 0 ) e = mesh->AddFaceWithID(node[0], node[1], node[2], node[3], node[4], node[5], node[6], node[7], ID); else e = mesh->AddFace (node[0], node[1], node[2], node[3], node[4], node[5], node[6], node[7] ); } else { - if ( ID ) e = mesh->AddPolygonalFaceWithID(node, ID); + if ( ID >= 0 ) e = mesh->AddPolygonalFaceWithID(node, ID); else e = mesh->AddPolygonalFace (node ); } break; case SMDSAbs_Volume: if ( !isPoly ) { if (nbnode == 4) - if ( ID ) e = mesh->AddVolumeWithID(node[0], node[1], node[2], node[3], ID); + if ( ID >= 0 ) e = mesh->AddVolumeWithID(node[0], node[1], node[2], node[3], ID); else e = mesh->AddVolume (node[0], node[1], node[2], node[3] ); else if (nbnode == 5) - if ( ID ) e = mesh->AddVolumeWithID(node[0], node[1], node[2], node[3], + if ( ID >= 0 ) e = mesh->AddVolumeWithID(node[0], node[1], node[2], node[3], node[4], ID); else e = mesh->AddVolume (node[0], node[1], node[2], node[3], node[4] ); else if (nbnode == 6) - if ( ID ) e = mesh->AddVolumeWithID(node[0], node[1], node[2], node[3], + if ( ID >= 0 ) e = mesh->AddVolumeWithID(node[0], node[1], node[2], node[3], node[4], node[5], ID); else e = mesh->AddVolume (node[0], node[1], node[2], node[3], node[4], node[5] ); else if (nbnode == 8) - if ( ID ) e = mesh->AddVolumeWithID(node[0], node[1], node[2], node[3], + if ( ID >= 0 ) e = mesh->AddVolumeWithID(node[0], node[1], node[2], node[3], node[4], node[5], node[6], node[7], ID); else e = mesh->AddVolume (node[0], node[1], node[2], node[3], node[4], node[5], node[6], node[7] ); else if (nbnode == 10) - if ( ID ) e = mesh->AddVolumeWithID(node[0], node[1], node[2], node[3], + if ( ID >= 0 ) e = mesh->AddVolumeWithID(node[0], node[1], node[2], node[3], node[4], node[5], node[6], node[7], node[8], node[9], ID); else e = mesh->AddVolume (node[0], node[1], node[2], node[3], node[4], node[5], node[6], node[7], node[8], node[9] ); else if (nbnode == 13) - if ( ID ) e = mesh->AddVolumeWithID(node[0], node[1], node[2], node[3], + if ( ID >= 0 ) e = mesh->AddVolumeWithID(node[0], node[1], node[2], node[3], node[4], node[5], node[6], node[7], node[8], node[9], node[10],node[11], node[12],ID); @@ -201,7 +202,7 @@ SMESH_MeshEditor::AddElement(const vector & node, node[8], node[9], node[10],node[11], node[12] ); else if (nbnode == 15) - if ( ID ) e = mesh->AddVolumeWithID(node[0], node[1], node[2], node[3], + if ( ID >= 0 ) e = mesh->AddVolumeWithID(node[0], node[1], node[2], node[3], node[4], node[5], node[6], node[7], node[8], node[9], node[10],node[11], node[12],node[13],node[14],ID); @@ -210,7 +211,7 @@ SMESH_MeshEditor::AddElement(const vector & node, node[8], node[9], node[10],node[11], node[12],node[13],node[14] ); else if (nbnode == 20) - if ( ID ) e = mesh->AddVolumeWithID(node[0], node[1], node[2], node[3], + if ( ID >= 0 ) e = mesh->AddVolumeWithID(node[0], node[1], node[2], node[3], node[4], node[5], node[6], node[7], node[8], node[9], node[10],node[11], node[12],node[13],node[14],node[15], @@ -551,7 +552,7 @@ bool SMESH_MeshEditor::InverseDiag (const SMDS_MeshElement * theTria1, // check case of quadratic faces if (theTria1->GetEntityType() != SMDSEntity_Quad_Triangle) return false; - if (theTria2->GetEntityType() == SMDSEntity_Quad_Triangle) + if (theTria2->GetEntityType() != SMDSEntity_Quad_Triangle) return false; // 5 @@ -7079,10 +7080,12 @@ void SMESH_MeshEditor::MergeNodes (TListOfListOfNodes & theGroupsOfNodes) list& nodes = *grIt; list::iterator nIt = nodes.begin(); const SMDS_MeshNode* nToKeep = *nIt; + //MESSAGE("node to keep " << nToKeep->GetID()); for ( ++nIt; nIt != nodes.end(); nIt++ ) { const SMDS_MeshNode* nToRemove = *nIt; nodeNodeMap.insert( TNodeNodeMap::value_type( nToRemove, nToKeep )); if ( nToRemove != nToKeep ) { + //MESSAGE(" node to remove " << nToRemove->GetID()); rmNodeIds.push_back( nToRemove->GetID() ); AddToSameGroups( nToKeep, nToRemove, aMesh ); } @@ -7099,6 +7102,7 @@ void SMESH_MeshEditor::MergeNodes (TListOfListOfNodes & theGroupsOfNodes) set::iterator eIt = elems.begin(); for ( ; eIt != elems.end(); eIt++ ) { const SMDS_MeshElement* elem = *eIt; + //MESSAGE(" ---- inverse elem on node to remove " << elem->GetID()); int nbNodes = elem->NbNodes(); int aShapeId = FindShape( elem ); @@ -7148,6 +7152,7 @@ void SMESH_MeshEditor::MergeNodes (TListOfListOfNodes & theGroupsOfNodes) bool isOk = true; int nbUniqueNodes = nodeSet.size(); + //MESSAGE("nbNodes nbUniqueNodes " << nbNodes << " " << nbUniqueNodes); if ( nbNodes != nbUniqueNodes ) { // some nodes stick // Polygons and Polyhedral volumes if (elem->IsPoly()) { @@ -7251,6 +7256,7 @@ void SMESH_MeshEditor::MergeNodes (TListOfListOfNodes & theGroupsOfNodes) isOk = false; else if ( nbRepl == 2 && iRepl[ 1 ] - iRepl[ 0 ] == 2 ) isOk = false; // opposite nodes stick + //MESSAGE("isOk " << isOk); } break; case 6: ///////////////////////////////////// PENTAHEDRON @@ -7600,28 +7606,10 @@ void SMESH_MeshEditor::MergeNodes (TListOfListOfNodes & theGroupsOfNodes) } } else { - // Change regular element or polygon - SMDS_MeshElement* newElem = 0; - switch (nbUniqueNodes) - { - case 3: - newElem = aMesh->AddFace(uniqueNodes[0], uniqueNodes[1], uniqueNodes[2]); - break; - case 4: - newElem = aMesh->AddVolume(uniqueNodes[0], uniqueNodes[1], uniqueNodes[2], - uniqueNodes[3]); - break; - case 5: - newElem = aMesh->AddVolume(uniqueNodes[0], uniqueNodes[1], uniqueNodes[2], - uniqueNodes[3], uniqueNodes[4]); - break; - case 6: - newElem = aMesh->AddVolume(uniqueNodes[0], uniqueNodes[1], uniqueNodes[2], - uniqueNodes[3], uniqueNodes[4], uniqueNodes[5]); - break; - default: - MESSAGE("invalid number of nodes:" << nbUniqueNodes); - } + //MESSAGE("Change regular element or polygon " << elem->GetID()); + SMDSAbs_ElementType etyp = elem->GetType(); + uniqueNodes.resize(nbUniqueNodes); + SMDS_MeshElement* newElem = this->AddElement(uniqueNodes, etyp, false); if (newElem) { myLastCreatedElems.Append(newElem); @@ -7633,6 +7621,7 @@ void SMESH_MeshEditor::MergeNodes (TListOfListOfNodes & theGroupsOfNodes) } else { // Remove invalid regular element or invalid polygon + //MESSAGE("Remove invalid " << elem->GetID()); rmElemIds.push_back( elem->GetID() ); } @@ -8088,7 +8077,7 @@ SMESH_MeshEditor::SewFreeBorder (const SMDS_MeshNode* theBordFirstNode, // links of the free border // ------------------------------------------------------------------------- - // 1. Since sewing may brake if there are volumes to split on the side 2, + // 1. Since sewing may break if there are volumes to split on the side 2, // we wont move nodes but just compute new coordinates for them typedef map TNodeXYZMap; TNodeXYZMap nBordXYZ; @@ -8627,6 +8616,7 @@ void SMESH_MeshEditor::InsertNodesIntoLink(const SMDS_MeshElement* theFace, return; } + SMESHDS_Mesh *aMesh = GetMeshDS(); if( !theFace->IsQuadratic() ) { // put aNodesToInsert between theBetweenNode1 and theBetweenNode2 @@ -8677,7 +8667,6 @@ void SMESH_MeshEditor::InsertNodesIntoLink(const SMDS_MeshElement* theFace, } // create new elements - SMESHDS_Mesh *aMesh = GetMeshDS(); int aShapeId = FindShape( theFace ); i1 = 0; i2 = 1; @@ -8703,10 +8692,16 @@ void SMESH_MeshEditor::InsertNodesIntoLink(const SMDS_MeshElement* theFace, newNodes[ 1 ] = linkNodes[ i2 ]; newNodes[ 2 ] = nodes[ iSplit >= iBestQuad ? i3 : i4 ]; newNodes[ 3 ] = nodes[ i4 ]; - // TODO problem ChangeElementNodes : not the same number of nodes, not the same type - MESSAGE("ChangeElementNodes"); - aMesh->ChangeElementNodes( theFace, newNodes, iSplit == iBestQuad ? 4 : 3 ); - } // end if(!theFace->IsQuadratic()) + //aMesh->ChangeElementNodes( theFace, newNodes, iSplit == iBestQuad ? 4 : 3 ); + const SMDS_MeshElement* newElem = 0; + if (iSplit == iBestQuad) + newElem = aMesh->AddFace( newNodes[0], newNodes[1], newNodes[2], newNodes[3] ); + else + newElem = aMesh->AddFace( newNodes[0], newNodes[1], newNodes[2] ); + myLastCreatedElems.Append(newElem); + if ( aShapeId && newElem ) + aMesh->SetMeshElementOnShape( newElem, aShapeId ); +} // end if(!theFace->IsQuadratic()) else { // theFace is quadratic // we have to split theFace on simple triangles and one simple quadrangle int tmp = il1/2; @@ -8733,7 +8728,6 @@ void SMESH_MeshEditor::InsertNodesIntoLink(const SMDS_MeshElement* theFace, // n4 n6 n5 n4 // create new elements - SMESHDS_Mesh *aMesh = GetMeshDS(); int aShapeId = FindShape( theFace ); int n1,n2,n3; @@ -8816,9 +8810,9 @@ void SMESH_MeshEditor::InsertNodesIntoLink(const SMDS_MeshElement* theFace, if ( aShapeId && newElem ) aMesh->SetMeshElementOnShape( newElem, aShapeId ); } - // remove old quadratic face - aMesh->RemoveElement(theFace); } + // remove old face + aMesh->RemoveElement(theFace); } //======================================================================= @@ -9250,7 +9244,7 @@ SMESH_MeshEditor::SewSideElements (TIDSortedElemSet& theSide1, // 1. Build set of faces representing each side: // ======================================================================= // a. build set of nodes belonging to faces - // b. complete set of faces: find missing fices whose nodes are in set of nodes + // b. complete set of faces: find missing faces whose nodes are in set of nodes // c. create temporary faces representing side of volumes if correspondent // face does not exist @@ -9292,7 +9286,7 @@ SMESH_MeshEditor::SewSideElements (TIDSortedElemSet& theSide1, // ----------------------------------------------------------- // 1a. Collect nodes of existing faces // and build set of face nodes in order to detect missing - // faces corresponing to sides of volumes + // faces corresponding to sides of volumes // ----------------------------------------------------------- set< set > setOfFaceNodeSet; @@ -9316,7 +9310,7 @@ SMESH_MeshEditor::SewSideElements (TIDSortedElemSet& theSide1, volSet->insert( elem ); } // ------------------------------------------------------------------------------ - // 1b. Complete set of faces: find missing fices whose nodes are in set of nodes + // 1b. Complete set of faces: find missing faces whose nodes are in set of nodes // ------------------------------------------------------------------------------ for ( nIt = nodeSet->begin(); nIt != nodeSet->end(); nIt++ ) { // loop on nodes of iSide @@ -9425,7 +9419,7 @@ SMESH_MeshEditor::SewSideElements (TIDSortedElemSet& theSide1, fIt++; } else - freeFaceList.erase( fIt++ ); // here fIt++ occures before erase + freeFaceList.erase( fIt++ ); // here fIt++ occurs before erase } if ( freeFaceList.size() > 1 ) { @@ -9803,9 +9797,14 @@ SMESH_MeshEditor::SewSideElements (TIDSortedElemSet& theSide1, // else if ( nbReplaced ) { - // TODO problem ChangeElementNodes : not the same number of nodes, not the same type - MESSAGE("ChangeElementNodes"); - aMesh->ChangeElementNodes( e, & nodes[0], nbNodes ); + SMDSAbs_ElementType etyp = e->GetType(); + SMDS_MeshElement* newElem = this->AddElement(nodes, etyp, false); + if (newElem) + { + myLastCreatedElems.Append(newElem); + AddToSameGroups(newElem, e, aMesh); + } + aMesh->RemoveElement(e); } } } diff --git a/src/SMESH/SMESH_MeshEditor.hxx b/src/SMESH/SMESH_MeshEditor.hxx index cef86b4af..0264a8037 100644 --- a/src/SMESH/SMESH_MeshEditor.hxx +++ b/src/SMESH/SMESH_MeshEditor.hxx @@ -162,14 +162,14 @@ public: SMDS_MeshElement* AddElement(const std::vector & nodes, const SMDSAbs_ElementType type, const bool isPoly, - const int ID = 0); + const int ID = -1); /*! * \brief Add element */ SMDS_MeshElement* AddElement(const std::vector & nodeIDs, const SMDSAbs_ElementType type, const bool isPoly, - const int ID = 0); + const int ID = -1); bool Remove (const std::list< int >& theElemIDs, const bool isNodes); // Remove a node or an element. diff --git a/src/SMESHDS/SMESHDS_Mesh.cxx b/src/SMESHDS/SMESHDS_Mesh.cxx index 95da59fcd..db558bd89 100644 --- a/src/SMESHDS/SMESHDS_Mesh.cxx +++ b/src/SMESHDS/SMESHDS_Mesh.cxx @@ -1931,6 +1931,7 @@ void SMESHDS_Mesh::compactMesh() myIDElements.swap(newSmdsToVtk); myVtkIndex.swap(newVtkToSmds); MESSAGE("myCells.size()=" << myCells.size() << " myIDElements.size()=" << myIDElements.size() << " myVtkIndex.size()=" << myVtkIndex.size() ); + this->myElementIDFactory->emptyPool(newSmdsId); // ---TODO: myNodes, myElements in submeshes diff --git a/src/SMESHDS/SMESHDS_SubMesh.cxx b/src/SMESHDS/SMESHDS_SubMesh.cxx index 7657c5984..abbeac195 100644 --- a/src/SMESHDS/SMESHDS_SubMesh.cxx +++ b/src/SMESHDS/SMESHDS_SubMesh.cxx @@ -49,11 +49,16 @@ SMESHDS_SubMesh::SMESHDS_SubMesh() //======================================================================= void SMESHDS_SubMesh::AddElement(const SMDS_MeshElement * ME) { - if ( !IsComplexSubmesh() ) + if (!IsComplexSubmesh()) { int idInSubShape = ME->getIdInShape(); - assert(idInSubShape == -1); - SMDS_MeshElement* elem = (SMDS_MeshElement*)(ME); + if (idInSubShape != -1) + { + MESSAGE("add element in subshape already belonging to a subshape " + << ME->GetID() << " " << ME->getIdInShape() << " " << ME->getshapeId()); + throw SALOME_Exception(LOCALIZED("add element in subshape already belonging to a subshape")); + } + SMDS_MeshElement* elem = (SMDS_MeshElement*) (ME); elem->setIdInShape(myElements.size()); myElements.push_back(ME); } diff --git a/src/StdMeshers/StdMeshers_Quadrangle_2D.cxx b/src/StdMeshers/StdMeshers_Quadrangle_2D.cxx index 1c0cf5e5b..58bf3a4e9 100644 --- a/src/StdMeshers/StdMeshers_Quadrangle_2D.cxx +++ b/src/StdMeshers/StdMeshers_Quadrangle_2D.cxx @@ -1159,10 +1159,10 @@ bool StdMeshers_Quadrangle_2D::SetNormalizedGrid (SMESH_Mesh & aMesh, const TopoDS_Shape& aShape, FaceQuadStruct* & quad) //throw (SALOME_Exception) { - // Algorithme décrit dans "Génération automatique de maillages" - // P.L. GEORGE, MASSON, § 6.4.1 p. 84-85 - // traitement dans le domaine paramétrique 2d u,v - // transport - projection sur le carré unité + // Algorithme décrit dans "Génération automatique de maillages" + // P.L. GEORGE, MASSON, § 6.4.1 p. 84-85 + // traitement dans le domaine paramétrique 2d u,v + // transport - projection sur le carré unité // MESSAGE("StdMeshers_Quadrangle_2D::SetNormalizedGrid"); // const TopoDS_Face& F = TopoDS::Face(aShape); -- 2.39.2