From: prascle Date: Fri, 15 Oct 2010 08:56:06 +0000 (+0000) Subject: PR:debug automatic tests in progress X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=a9f0b607095e6395351dd369abd73fc9ada26990;p=modules%2Fsmesh.git PR:debug automatic tests in progress --- diff --git a/src/DriverMED/DriverMED_R_SMESHDS_Mesh.cxx b/src/DriverMED/DriverMED_R_SMESHDS_Mesh.cxx index 5b425f212..27edfccff 100644 --- a/src/DriverMED/DriverMED_R_SMESHDS_Mesh.cxx +++ b/src/DriverMED/DriverMED_R_SMESHDS_Mesh.cxx @@ -40,7 +40,7 @@ #include #ifdef _DEBUG_ -static int MYDEBUG = 0; +static int MYDEBUG = 1; //#define _DEXCEPT_ #else static int MYDEBUG = 0; @@ -161,9 +161,11 @@ DriverMED_R_SMESHDS_Mesh if(anIsNodeNum) { aNode = myMesh->AddNodeWithID (aCoords[0],aCoords[1],aCoords[2],aNodeInfo->GetElemNum(iElem)); + //MESSAGE("AddNodeWithID " << aNodeInfo->GetElemNum(iElem)); } else { - aNode = myMesh->AddNode - (aCoords[0],aCoords[1],aCoords[2]); + aNode = myMesh->AddNodeWithID + (aCoords[0],aCoords[1],aCoords[2], iElem+1); + //MESSAGE("AddNode " << aNode->GetID()); } //cout<GetID()<<": "<X()<<", "<Y()<<", "<Z()<GetElemNum(iElem); anElement = myMesh->AddPolygonalFaceWithID(aNodeIds,anElemId); + //MESSAGE("AddPolygonalFaceWithID " << anElemId); } if(!anElement){ vector aNodes(aNbConn); for(TInt iConn = 0; iConn < aNbConn; iConn++) aNodes[iConn] = FindNode(myMesh,aNodeIds[iConn]); anElement = myMesh->AddPolygonalFace(aNodes); + //MESSAGE("AddPolygonalFace " << anElement->GetID()); isRenum = anIsElemNum; } #ifndef _DEXCEPT_ @@ -298,12 +302,14 @@ DriverMED_R_SMESHDS_Mesh if(anIsElemNum){ TInt anElemId = aPolyedreInfo->GetElemNum(iElem); anElement = myMesh->AddPolyhedralVolumeWithID(aNodeIds,aQuantities,anElemId); + //MESSAGE("AddPolyhedralVolumeWithID " << anElemId); } if(!anElement){ vector aNodes(aNbNodes); for(TInt iConn = 0; iConn < aNbNodes; iConn++) aNodes[iConn] = FindNode(myMesh,aNodeIds[iConn]); anElement = myMesh->AddPolyhedralVolume(aNodes,aQuantities); + //MESSAGE("AddPolyhedralVolume " << anElement->GetID()); isRenum = anIsElemNum; } #ifndef _DEXCEPT_ @@ -378,10 +384,10 @@ DriverMED_R_SMESHDS_Mesh anIsValidConnect = true; #ifndef _DEXCEPT_ }catch(const std::exception& exc){ - //INFOS("Follow exception was cought:\n\t"<AddVolumeWithID(aNodeIds[0], aNodeIds[1], aNodeIds[2], aNodeIds[3], @@ -693,13 +699,18 @@ DriverMED_R_SMESHDS_Mesh } break; } - +// if (anIsElemNum) { +// MESSAGE("add element with id " << aCellInfo->GetElemNum(iElem)); +// } +// else { +// MESSAGE("add element "<< anElement->GetID()); +// } #ifndef _DEXCEPT_ }catch(const std::exception& exc){ - //INFOS("Follow exception was cought:\n\t"<compactMesh(); if(MYDEBUG) MESSAGE("Perform - aResult status = "< DriverMED_R_SMESHDS_Mesh::GetMeshNames(Status& theStatus) } } }catch(const std::exception& exc){ - INFOS("Follow exception was cought:\n\t"<first; const TRecord& aRec = anIter->second; + MESSAGE("AddNodeWithID " << aLabel << " " << aRec.coord[0] << " " << aRec.coord[1] << " " << aRec.coord[2]); myMesh->AddNodeWithID(aRec.coord[0],aRec.coord[1],aRec.coord[2],aLabel); } } @@ -82,11 +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]); 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]); anElement = myMesh->AddEdgeWithID(aRec.node_labels[0], aRec.node_labels[2], aRec.node_labels[1], @@ -94,6 +97,7 @@ Driver_Mesh::Status DriverUNV_R_SMDS_Mesh::Perform() } } else if(IsFace(aRec.fe_descriptor_id)) { + MESSAGE("add face " << aLabel); switch(aRec.fe_descriptor_id){ case 71: // TRI3 case 72: @@ -109,6 +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]); anElement = myMesh->AddFaceWithID(aRec.node_labels[0], aRec.node_labels[2], aRec.node_labels[4], @@ -142,6 +147,7 @@ Driver_Mesh::Status DriverUNV_R_SMDS_Mesh::Perform() } } else if(IsVolume(aRec.fe_descriptor_id)){ + MESSAGE("add volume " << aLabel); switch(aRec.fe_descriptor_id){ case 111: // Solid Linear Tetrahedron - TET4 @@ -365,5 +371,7 @@ Driver_Mesh::Status DriverUNV_R_SMDS_Mesh::Perform() catch(...){ INFOS("Unknown exception was cought !!!"); } + if (myMesh) + myMesh->compactMesh(); return aResult; } diff --git a/src/DriverUNV/DriverUNV_W_SMDS_Mesh.cxx b/src/DriverUNV/DriverUNV_W_SMDS_Mesh.cxx index cf7778300..ade9abba5 100644 --- a/src/DriverUNV/DriverUNV_W_SMDS_Mesh.cxx +++ b/src/DriverUNV/DriverUNV_W_SMDS_Mesh.cxx @@ -99,12 +99,10 @@ Driver_Mesh::Status DriverUNV_W_SMDS_Mesh::Perform() TRecord aRec; aRec.node_labels.reserve(aNbNodes); SMDS_ElemIteratorPtr aNodesIter; + aNodesIter = anElem->nodesIteratorToUNV(); if( anElem->IsQuadratic() ) { - aNodesIter = static_cast - ( anElem )->interlacedNodesElemIterator(); aRec.fe_descriptor_id = 22; } else { - aNodesIter = anElem->nodesIterator(); aRec.fe_descriptor_id = 11; } for(; aNodesIter->more();){ @@ -126,11 +124,7 @@ Driver_Mesh::Status DriverUNV_W_SMDS_Mesh::Perform() TRecord aRec; aRec.node_labels.reserve(aNbNodes); SMDS_ElemIteratorPtr aNodesIter; - if( anElem->IsQuadratic() ) - aNodesIter = static_cast - ( anElem )->interlacedNodesElemIterator(); - else - aNodesIter = anElem->nodesIterator(); + aNodesIter = anElem->nodesIteratorToUNV(); for(; aNodesIter->more();){ const SMDS_MeshElement* aNode = aNodesIter->next(); aRec.node_labels.push_back(aNode->GetID()); @@ -164,8 +158,11 @@ Driver_Mesh::Status DriverUNV_W_SMDS_Mesh::Perform() TElementLab aLabel = anElem->GetID(); int aNbNodes = anElem->NbNodes(); - SMDS_ElemIteratorPtr aNodesIter = anElem->nodesIterator(); + MESSAGE("aNbNodes="<nodesIteratorToUNV(); if ( anElem->IsPoly() ) { + MESSAGE("anElem->IsPoly"); if ( const SMDS_PolyhedralVolumeOfNodes* ph = dynamic_cast (anElem)) { @@ -173,63 +170,47 @@ Driver_Mesh::Status DriverUNV_W_SMDS_Mesh::Perform() aNodesIter = ph->uniqueNodesIterator(); } } - aConnect.resize(aNbNodes); - GetConnect(aNodesIter,aConnect); int anId = -1; - int* aConn = NULL; switch(aNbNodes){ case 4: { - static int anIds[] = {0,2,1,3}; - aConn = anIds; anId = 111; break; } case 6: { - static int anIds[] = {0,2,1,3,5,4}; - aConn = anIds; anId = 112; break; } case 8: { - static int anIds[] = {0,3,2,1,4,7,6,5}; - aConn = anIds; anId = 115; break; } case 10: { - static int anIds[] = {0,4,2,9,5,3, 1,6,8, 7}; - aConn = anIds; anId = 118; break; } case 13: { - static int anIds[] = {0,6,4,2,7,5,3,1,8,11,10,9,12}; - aConn = anIds; anId = 114; break; } case 15: { - static int anIds[] = {0,4,2,9,13,11,5,3,1,14,12,10,6,8,7}; - aConn = anIds; anId = 113; break; } case 20: { - static int anIds[] = {0,6, 4,2, 12,18,16,14,7, 5, 3, 1, 19,17,15,13,8, 11,10,9}; - aConn = anIds; anId = 116; break; } default: continue; } - if(aConn){ + if(anId>0){ TRecord aRec; aRec.fe_descriptor_id = anId; - aRec.node_labels.resize(aNbNodes); - for(int aNodeId = 0; aNodeId < aNbNodes; aNodeId++){ - aRec.node_labels[aConn[aNodeId]] = aConnect[aNodeId]; + aRec.node_labels.reserve(aNbNodes); + for(; aNodesIter->more();){ + const SMDS_MeshElement* aNode = aNodesIter->next(); + aRec.node_labels.push_back(aNode->GetID()); } aDataSet2412.insert(TDataSet::value_type(aLabel,aRec)); } diff --git a/src/SMDS/SMDS_Mesh.cxx b/src/SMDS/SMDS_Mesh.cxx index ce6145a50..bb600ea23 100644 --- a/src/SMDS/SMDS_Mesh.cxx +++ b/src/SMDS/SMDS_Mesh.cxx @@ -320,16 +320,22 @@ SMDS_MeshEdge* SMDS_Mesh::AddEdgeWithID(const SMDS_MeshNode * n1, SMDS_VtkEdge *edgevtk = myEdgePool->getNew(); edgevtk->init(nodeIds, this); + if (!this->registerElement(ID,edgevtk)) + { + this->myGrid->GetCellTypesArray()->SetValue(edgevtk->getVtkId(), VTK_EMPTY_CELL); + myEdgePool->destroy(edgevtk); + return 0; + } edge = edgevtk; adjustmyCellsCapacity(ID); myCells[ID] = edge; myInfo.myNbEdges++; - if (edge && !registerElement(ID, edge)) - { - RemoveElement(edge, false); - edge = NULL; - } +// if (edge && !registerElement(ID, edge)) +// { +// RemoveElement(edge, false); +// edge = NULL; +// } return edge; } @@ -370,10 +376,10 @@ SMDS_MeshFace* SMDS_Mesh::AddFaceWithID(const SMDS_MeshNode * n1, //MESSAGE("AddFaceWithID " << ID) SMDS_MeshFace * face=createTriangle(n1, n2, n3, ID); - if (face && !registerElement(ID, face)) { - RemoveElement(face, false); - face = NULL; - } +// if (face && !registerElement(ID, face)) { +// RemoveElement(face, false); +// face = NULL; +// } return face; } @@ -422,10 +428,10 @@ SMDS_MeshFace* SMDS_Mesh::AddFaceWithID(const SMDS_MeshNode * n1, //MESSAGE("AddFaceWithID " << ID); SMDS_MeshFace * face=createQuadrangle(n1, n2, n3, n4, ID); - if (face && !registerElement(ID, face)) { - RemoveElement(face, false); - face = NULL; - } +// if (face && !registerElement(ID, face)) { +// RemoveElement(face, false); +// face = NULL; +// } return face; } @@ -458,7 +464,7 @@ SMDS_MeshFace* SMDS_Mesh::AddFaceWithID(const SMDS_MeshEdge * e1, if ( !e1 || !e2 || !e3 ) return 0; //if ( myFaces.Extent() % CHECKMEMORY_INTERVAL == 0 ) CheckMemory(); - //MESSAGE("AddFaceWithID" << ID); + MESSAGE("AddFaceWithID" << ID); SMDS_MeshFace * face = new SMDS_FaceOfEdges(e1,e2,e3); adjustmyCellsCapacity(ID); @@ -466,8 +472,9 @@ SMDS_MeshFace* SMDS_Mesh::AddFaceWithID(const SMDS_MeshEdge * e1, myInfo.myNbTriangles++; if (!registerElement(ID, face)) { - RemoveElement(face, false); - face = NULL; + registerElement(myElementIDFactory->GetFreeID(), face); + //RemoveElement(face, false); + //face = NULL; } return face; } @@ -500,7 +507,7 @@ SMDS_MeshFace* SMDS_Mesh::AddFaceWithID(const SMDS_MeshEdge * e1, { if (!hasConstructionEdges()) return NULL; - //MESSAGE("AddFaceWithID" << ID); + MESSAGE("AddFaceWithID" << ID); if ( !e1 || !e2 || !e3 || !e4 ) return 0; //if ( myFaces.Extent() % CHECKMEMORY_INTERVAL == 0 ) CheckMemory(); SMDS_MeshFace * face = new SMDS_FaceOfEdges(e1,e2,e3,e4); @@ -510,8 +517,9 @@ SMDS_MeshFace* SMDS_Mesh::AddFaceWithID(const SMDS_MeshEdge * e1, if (!registerElement(ID, face)) { - RemoveElement(face, false); - face = NULL; + registerElement(myElementIDFactory->GetFreeID(), face); + //RemoveElement(face, false); + //face = NULL; } return face; } @@ -597,16 +605,22 @@ SMDS_MeshVolume* SMDS_Mesh::AddVolumeWithID(const SMDS_MeshNode * n1, SMDS_VtkVolume *volvtk = myVolumePool->getNew(); volvtk->init(nodeIds, this); + if (!this->registerElement(ID,volvtk)) + { + this->myGrid->GetCellTypesArray()->SetValue(volvtk->getVtkId(), VTK_EMPTY_CELL); + myVolumePool->destroy(volvtk); + return 0; + } volume = volvtk; adjustmyCellsCapacity(ID); myCells[ID] = volume; myInfo.myNbTetras++; } - if (!registerElement(ID, volume)) { - RemoveElement(volume, false); - volume = NULL; - } +// if (!registerElement(ID, volume)) { +// RemoveElement(volume, false); +// volume = NULL; +// } return volume; } @@ -699,16 +713,22 @@ SMDS_MeshVolume* SMDS_Mesh::AddVolumeWithID(const SMDS_MeshNode * n1, SMDS_VtkVolume *volvtk = myVolumePool->getNew(); volvtk->init(nodeIds, this); + if (!this->registerElement(ID,volvtk)) + { + this->myGrid->GetCellTypesArray()->SetValue(volvtk->getVtkId(), VTK_EMPTY_CELL); + myVolumePool->destroy(volvtk); + return 0; + } volume = volvtk; adjustmyCellsCapacity(ID); myCells[ID] = volume; myInfo.myNbPyramids++; } - if (!registerElement(ID, volume)) { - RemoveElement(volume, false); - volume = NULL; - } +// if (!registerElement(ID, volume)) { +// RemoveElement(volume, false); +// volume = NULL; +// } return volume; } @@ -807,16 +827,22 @@ SMDS_MeshVolume* SMDS_Mesh::AddVolumeWithID(const SMDS_MeshNode * n1, SMDS_VtkVolume *volvtk = myVolumePool->getNew(); volvtk->init(nodeIds, this); + if (!this->registerElement(ID,volvtk)) + { + this->myGrid->GetCellTypesArray()->SetValue(volvtk->getVtkId(), VTK_EMPTY_CELL); + myVolumePool->destroy(volvtk); + return 0; + } volume = volvtk; adjustmyCellsCapacity(ID); myCells[ID] = volume; myInfo.myNbPrisms++; } - if (!registerElement(ID, volume)) { - RemoveElement(volume, false); - volume = NULL; - } +// if (!registerElement(ID, volume)) { +// RemoveElement(volume, false); +// volume = NULL; +// } return volume; } @@ -929,16 +955,22 @@ SMDS_MeshVolume* SMDS_Mesh::AddVolumeWithID(const SMDS_MeshNode * n1, SMDS_VtkVolume *volvtk = myVolumePool->getNew(); volvtk->init(nodeIds, this); + if (!this->registerElement(ID,volvtk)) + { + this->myGrid->GetCellTypesArray()->SetValue(volvtk->getVtkId(), VTK_EMPTY_CELL); + myVolumePool->destroy(volvtk); + return 0; + } volume = volvtk; adjustmyCellsCapacity(ID); myCells[ID] = volume; myInfo.myNbHexas++; } - if (!registerElement(ID, volume)) { - RemoveElement(volume, false); - volume = NULL; - } +// if (!registerElement(ID, volume)) { +// RemoveElement(volume, false); +// volume = NULL; +// } return volume; } @@ -970,7 +1002,7 @@ SMDS_MeshVolume* SMDS_Mesh::AddVolumeWithID(const SMDS_MeshFace * f1, const SMDS_MeshFace * f4, int ID) { - //MESSAGE("AddVolumeWithID" << ID); + MESSAGE("AddVolumeWithID" << ID); if (!hasConstructionFaces()) return NULL; if ( !f1 || !f2 || !f3 || !f4) return 0; @@ -981,8 +1013,9 @@ SMDS_MeshVolume* SMDS_Mesh::AddVolumeWithID(const SMDS_MeshFace * f1, myInfo.myNbTetras++; if (!registerElement(ID, volume)) { - RemoveElement(volume, false); - volume = NULL; + registerElement(myElementIDFactory->GetFreeID(), volume); + //RemoveElement(volume, false); + //volume = NULL; } return volume; } @@ -1017,7 +1050,7 @@ SMDS_MeshVolume* SMDS_Mesh::AddVolumeWithID(const SMDS_MeshFace * f1, const SMDS_MeshFace * f5, int ID) { - //MESSAGE("AddVolumeWithID" << ID); + MESSAGE("AddVolumeWithID" << ID); if (!hasConstructionFaces()) return NULL; if ( !f1 || !f2 || !f3 || !f4 || !f5) return 0; @@ -1028,8 +1061,9 @@ SMDS_MeshVolume* SMDS_Mesh::AddVolumeWithID(const SMDS_MeshFace * f1, myInfo.myNbPyramids++; if (!registerElement(ID, volume)) { - RemoveElement(volume, false); - volume = NULL; + registerElement(myElementIDFactory->GetFreeID(), volume); + //RemoveElement(volume, false); + //volume = NULL; } return volume; } @@ -1066,7 +1100,7 @@ SMDS_MeshVolume* SMDS_Mesh::AddVolumeWithID(const SMDS_MeshFace * f1, const SMDS_MeshFace * f6, int ID) { - //MESSAGE("AddVolumeWithID" << ID); + MESSAGE("AddVolumeWithID" << ID); if (!hasConstructionFaces()) return NULL; if ( !f1 || !f2 || !f3 || !f4 || !f5 || !f6) return 0; @@ -1077,8 +1111,9 @@ SMDS_MeshVolume* SMDS_Mesh::AddVolumeWithID(const SMDS_MeshFace * f1, myInfo.myNbPrisms++; if (!registerElement(ID, volume)) { - RemoveElement(volume, false); - volume = NULL; + registerElement(myElementIDFactory->GetFreeID(), volume); + //RemoveElement(volume, false); + //volume = NULL; } return volume; } @@ -1110,6 +1145,7 @@ SMDS_MeshFace* SMDS_Mesh::AddPolygonalFaceWithID SMDS_MeshFace * face; //if ( myFaces.Extent() % CHECKMEMORY_INTERVAL == 0 ) CheckMemory(); + MESSAGE("AddPolygonalFaceWithID " << ID); if (hasConstructionEdges()) { MESSAGE("Error : Not implemented"); @@ -1126,8 +1162,9 @@ SMDS_MeshFace* SMDS_Mesh::AddPolygonalFaceWithID } if (!registerElement(ID, face)) { - RemoveElement(face, false); - face = NULL; + registerElement(myElementIDFactory->GetFreeID(), face); + //RemoveElement(face, false); + //face = NULL; } return face; } @@ -1174,6 +1211,7 @@ 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()) { @@ -1192,6 +1230,12 @@ SMDS_MeshVolume* SMDS_Mesh::AddPolyhedralVolumeWithID 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 ) @@ -1203,10 +1247,13 @@ SMDS_MeshVolume* SMDS_Mesh::AddPolyhedralVolumeWithID myInfo.myNbPolyhedrons++; } +#ifndef VTK_HAVE_POLYHEDRON if (!registerElement(ID, volume)) { - RemoveElement(volume, false); - volume = NULL; + registerElement(myElementIDFactory->GetFreeID(), volume); + //RemoveElement(volume, false); + //volume = NULL; } +#endif return volume; } @@ -1317,7 +1364,13 @@ SMDS_MeshFace * SMDS_Mesh::createTriangle(const SMDS_MeshNode * node1, SMDS_MeshFace * face = 0; SMDS_VtkFace *facevtk = myFacePool->getNew(); - facevtk->init(nodeIds, this); + facevtk->init(nodeIds, this); // put in vtkUnstructuredGrid + if (!this->registerElement(ID,facevtk)) + { + this->myGrid->GetCellTypesArray()->SetValue(facevtk->getVtkId(), VTK_EMPTY_CELL); + myFacePool->destroy(facevtk); + return 0; + } face = facevtk; adjustmyCellsCapacity(ID); myCells[ID] = face; @@ -1367,6 +1420,12 @@ SMDS_MeshFace * SMDS_Mesh::createQuadrangle(const SMDS_MeshNode * node1, SMDS_MeshFace * face = 0; SMDS_VtkFace *facevtk = myFacePool->getNew(); facevtk->init(nodeIds, this); + if (!this->registerElement(ID,facevtk)) + { + this->myGrid->GetCellTypesArray()->SetValue(facevtk->getVtkId(), VTK_EMPTY_CELL); + myFacePool->destroy(facevtk); + return 0; + } face = facevtk; adjustmyCellsCapacity(ID); myCells[ID] = face; @@ -1468,65 +1527,19 @@ bool SMDS_Mesh::ChangeElementNodes(const SMDS_MeshElement * element, const SMDS_MeshNode * nodes[], const int nbnodes) { - // TODO use polymorphism, check number of nodes and type are unchanged. - MYASSERT(0); // REVOIR LES TYPES + MESSAGE("SMDS_Mesh::ChangeElementNodes"); // keep current nodes of elem set oldNodes; SMDS_ElemIteratorPtr itn = element->nodesIterator(); while(itn->more()) oldNodes.insert( itn->next() ); - if ( !element->IsPoly() ) - myInfo.remove( element ); // element may change type - // change nodes bool Ok = false; SMDS_MeshCell* cell = dynamic_cast((SMDS_MeshElement*) element); if (cell) Ok = cell->ChangeNodes(nodes, nbnodes); -// SMDS_MeshElement* elem = const_cast(element); -// switch ( elem->GetType() ) -// { -// case SMDSAbs_0DElement: { -// if ( SMDS_Mesh0DElement* elem0d = dynamic_cast( elem )) -// Ok = elem0d->ChangeNode( nodes[0] ); -// break; -// } -// case SMDSAbs_Edge: { -// if ( nbnodes == 2 ) { -// if ( SMDS_VtkEdge* edge = dynamic_cast( elem )) -// Ok = edge->ChangeNodes( nodes[0], nodes[1] ); -// } -// else if ( nbnodes == 3 ) { -// if ( SMDS_QuadraticEdge* edge = dynamic_cast( elem )) -// Ok = edge->ChangeNodes( nodes[0], nodes[1], nodes[2] ); -// } -// break; -// } -// case SMDSAbs_Face: { -// if ( SMDS_FaceOfNodes* face = dynamic_cast( elem )) -// Ok = face->ChangeNodes( nodes, nbnodes ); -// else -// if ( SMDS_QuadraticFaceOfNodes* QF = dynamic_cast( elem )) -// Ok = QF->ChangeNodes( nodes, nbnodes ); -// else -// if (SMDS_PolygonalFaceOfNodes* face = dynamic_cast(elem)) -// Ok = face->ChangeNodes(nodes, nbnodes); -// break; -// } -// case SMDSAbs_Volume: { -// if ( SMDS_VolumeOfNodes* vol = dynamic_cast( elem )) -// Ok = vol->ChangeNodes( nodes, nbnodes ); -// else -// if ( SMDS_QuadraticVolumeOfNodes* QV = dynamic_cast( elem )) -// Ok = QV->ChangeNodes( nodes, nbnodes ); -// break; -// } -// default: -// MESSAGE ( "WRONG ELEM TYPE"); -// } - if ( Ok ) { // update InverseElements set::iterator it; @@ -1550,9 +1563,6 @@ bool SMDS_Mesh::ChangeElementNodes(const SMDS_MeshElement * element, } } - if ( !element->IsPoly() ) - myInfo.add( element ); // element may change type - return Ok; } @@ -1716,6 +1726,12 @@ SMDS_MeshEdge* SMDS_Mesh::FindEdgeOrCreate(const SMDS_MeshNode * node1, SMDS_VtkEdge *edgevtk = myEdgePool->getNew(); edgevtk->init(nodeIds, this); + if (!this->registerElement(ID,edgevtk)) + { + this->myGrid->GetCellTypesArray()->SetValue(edgevtk->getVtkId(), VTK_EMPTY_CELL); + myEdgePool->destroy(edgevtk); + return 0; + } toReturn = edgevtk; myCells[ID] = toReturn; myInfo.myNbEdges++; @@ -2833,42 +2849,55 @@ void SMDS_Mesh::RemoveElement(const SMDS_MeshElement * elem, (const_cast(itn->next())); n->RemoveInverseElement( (*it) ); } - + int IdToRemove = (*it)->GetID(); + MESSAGE("elem Id to remove " << IdToRemove << " vtktype " << (*it)->GetVtkType()); switch((*it)->GetType()) { case SMDSAbs_Node: MYASSERT("Internal Error: This should not happen"); break; case SMDSAbs_0DElement: - myCells[(*it)->GetID()] = 0; // -PR- ici ou dans myElementIDFactory->ReleaseID ? - myInfo.remove(*it); + if (IdToRemove >= 0) + { + myCells[IdToRemove] = 0; // -PR- ici ou dans myElementIDFactory->ReleaseID ? + myInfo.remove(*it); + } removedElems.push_back( (*it) ); - myElementIDFactory->ReleaseID((*it)->GetID()); + myElementIDFactory->ReleaseID(IdToRemove); delete (*it); break; case SMDSAbs_Edge: - myCells[(*it)->GetID()] = 0; - myInfo.RemoveEdge(*it); + if (IdToRemove >= 0) + { + myCells[IdToRemove] = 0; + myInfo.RemoveEdge(*it); + } removedElems.push_back( (*it) ); - myElementIDFactory->ReleaseID((*it)->GetID()); + myElementIDFactory->ReleaseID(IdToRemove); if (const SMDS_VtkEdge* vtkElem = dynamic_cast(*it)) myEdgePool->destroy((SMDS_VtkEdge*)vtkElem); else delete (*it); break; case SMDSAbs_Face: - myCells[(*it)->GetID()] = 0; - myInfo.RemoveFace(*it); + if (IdToRemove >= 0) + { + myCells[IdToRemove] = 0; + myInfo.RemoveFace(*it); + } removedElems.push_back( (*it) ); - myElementIDFactory->ReleaseID((*it)->GetID()); + myElementIDFactory->ReleaseID(IdToRemove); if (const SMDS_VtkFace* vtkElem = dynamic_cast(*it)) myFacePool->destroy((SMDS_VtkFace*)vtkElem); else delete (*it); break; case SMDSAbs_Volume: - myCells[(*it)->GetID()] = 0; - myInfo.RemoveVolume(*it); + if (IdToRemove >= 0) + { + myCells[IdToRemove] = 0; + myInfo.RemoveVolume(*it); + } removedElems.push_back( (*it) ); - myElementIDFactory->ReleaseID((*it)->GetID()); + myElementIDFactory->ReleaseID(IdToRemove); if (const SMDS_VtkVolume* vtkElem = dynamic_cast(*it)) myVolumePool->destroy((SMDS_VtkVolume*)vtkElem); else delete (*it); @@ -2883,9 +2912,13 @@ void SMDS_Mesh::RemoveElement(const SMDS_MeshElement * elem, it=s2->begin(); while(it!=s2->end()) { - //MESSAGE( "SMDS: RM node " << (*it)->GetID() ); - myNodes[(*it)->GetID()] = 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)) @@ -3154,15 +3187,21 @@ SMDS_MeshEdge* SMDS_Mesh::AddEdgeWithID(const SMDS_MeshNode * n1, SMDS_MeshEdge * edge = 0; SMDS_VtkEdge *edgevtk = myEdgePool->getNew(); edgevtk->init(nodeIds, this); + if (!this->registerElement(ID,edgevtk)) + { + this->myGrid->GetCellTypesArray()->SetValue(edgevtk->getVtkId(), VTK_EMPTY_CELL); + myEdgePool->destroy(edgevtk); + return 0; + } edge = edgevtk; adjustmyCellsCapacity(ID); myCells[ID] = edge; myInfo.myNbQuadEdges++; - if (!registerElement(ID, edge)) { - RemoveElement(edge, false); - edge = NULL; - } +// if (!registerElement(ID, edge)) { +// RemoveElement(edge, false); +// edge = NULL; +// } return edge; } @@ -3232,15 +3271,21 @@ SMDS_MeshFace* SMDS_Mesh::AddFaceWithID(const SMDS_MeshNode * n1, SMDS_MeshFace * face = 0; SMDS_VtkFace *facevtk = myFacePool->getNew(); facevtk->init(nodeIds, this); + if (!this->registerElement(ID,facevtk)) + { + this->myGrid->GetCellTypesArray()->SetValue(facevtk->getVtkId(), VTK_EMPTY_CELL); + myFacePool->destroy(facevtk); + return 0; + } face = facevtk; adjustmyCellsCapacity(ID); myCells[ID] = face; myInfo.myNbQuadTriangles++; - if (!registerElement(ID, face)) { - RemoveElement(face, false); - face = NULL; - } +// if (!registerElement(ID, face)) { +// RemoveElement(face, false); +// face = NULL; +// } return face; } } @@ -3318,15 +3363,21 @@ SMDS_MeshFace* SMDS_Mesh::AddFaceWithID(const SMDS_MeshNode * n1, SMDS_MeshFace * face = 0; SMDS_VtkFace *facevtk = myFacePool->getNew(); facevtk->init(nodeIds, this); + if (!this->registerElement(ID,facevtk)) + { + this->myGrid->GetCellTypesArray()->SetValue(facevtk->getVtkId(), VTK_EMPTY_CELL); + myFacePool->destroy(facevtk); + return 0; + } face = facevtk; adjustmyCellsCapacity(ID); myCells[ID] = face; myInfo.myNbQuadQuadrangles++; - if (!registerElement(ID, face)) { - RemoveElement(face, false); - face = NULL; - } +// if (!registerElement(ID, face)) { +// RemoveElement(face, false); +// face = NULL; +// } return face; } } @@ -3416,14 +3467,20 @@ SMDS_MeshVolume* SMDS_Mesh::AddVolumeWithID(const SMDS_MeshNode * n1, SMDS_VtkVolume *volvtk = myVolumePool->getNew(); volvtk->init(nodeIds, this); + if (!this->registerElement(ID,volvtk)) + { + this->myGrid->GetCellTypesArray()->SetValue(volvtk->getVtkId(), VTK_EMPTY_CELL); + myVolumePool->destroy(volvtk); + return 0; + } adjustmyCellsCapacity(ID); myCells[ID] = volvtk; myInfo.myNbQuadTetras++; - if (!registerElement(ID, volvtk)) { - RemoveElement(volvtk, false); - volvtk = NULL; - } +// if (!registerElement(ID, volvtk)) { +// RemoveElement(volvtk, false); +// volvtk = NULL; +// } return volvtk; } @@ -3526,14 +3583,20 @@ SMDS_MeshVolume* SMDS_Mesh::AddVolumeWithID(const SMDS_MeshNode * n1, SMDS_VtkVolume *volvtk = myVolumePool->getNew(); volvtk->init(nodeIds, this); + if (!this->registerElement(ID,volvtk)) + { + this->myGrid->GetCellTypesArray()->SetValue(volvtk->getVtkId(), VTK_EMPTY_CELL); + myVolumePool->destroy(volvtk); + return 0; + } adjustmyCellsCapacity(ID); myCells[ID] = volvtk; myInfo.myNbQuadPyramids++; - if (!registerElement(ID, volvtk)) { - RemoveElement(volvtk, false); - volvtk = NULL; - } +// if (!registerElement(ID, volvtk)) { +// RemoveElement(volvtk, false); +// volvtk = NULL; +// } return volvtk; } @@ -3648,14 +3711,20 @@ SMDS_MeshVolume* SMDS_Mesh::AddVolumeWithID(const SMDS_MeshNode * n1, SMDS_VtkVolume *volvtk = myVolumePool->getNew(); volvtk->init(nodeIds, this); + if (!this->registerElement(ID,volvtk)) + { + this->myGrid->GetCellTypesArray()->SetValue(volvtk->getVtkId(), VTK_EMPTY_CELL); + myVolumePool->destroy(volvtk); + return 0; + } adjustmyCellsCapacity(ID); myCells[ID] = volvtk; myInfo.myNbQuadPrisms++; - if (!registerElement(ID, volvtk)) { - RemoveElement(volvtk, false); - volvtk = NULL; - } +// if (!registerElement(ID, volvtk)) { +// RemoveElement(volvtk, false); +// volvtk = NULL; +// } return volvtk; } @@ -3790,14 +3859,20 @@ SMDS_MeshVolume* SMDS_Mesh::AddVolumeWithID(const SMDS_MeshNode * n1, SMDS_VtkVolume *volvtk = myVolumePool->getNew(); volvtk->init(nodeIds, this); + if (!this->registerElement(ID,volvtk)) + { + this->myGrid->GetCellTypesArray()->SetValue(volvtk->getVtkId(), VTK_EMPTY_CELL); + myVolumePool->destroy(volvtk); + return 0; + } adjustmyCellsCapacity(ID); myCells[ID] = volvtk; myInfo.myNbQuadHexas++; - if (!registerElement(ID, volvtk)) { - RemoveElement(volvtk, false); - volvtk = NULL; - } +// if (!registerElement(ID, volvtk)) { +// RemoveElement(volvtk, false); +// volvtk = NULL; +// } return volvtk; } @@ -3891,3 +3966,8 @@ void SMDS_Mesh::dumpGrid(string ficdump) ficcon.close(); } + +void SMDS_Mesh::compactMesh() +{ + MESSAGE("SMDS_Mesh::compactMesh do nothing!"); +} diff --git a/src/SMDS/SMDS_Mesh.hxx b/src/SMDS/SMDS_Mesh.hxx index 83204682a..914f14cde 100644 --- a/src/SMDS/SMDS_Mesh.hxx +++ b/src/SMDS/SMDS_Mesh.hxx @@ -472,6 +472,7 @@ public: virtual void Renumber (const bool isNodes, const int startID = 1, const int deltaID = 1); // Renumber all nodes or elements. + virtual void compactMesh(); const SMDS_MeshNode *FindNode(int idnode) const; const SMDS_Mesh0DElement* Find0DElement(int idnode) const; diff --git a/src/SMDS/SMDS_MeshElement.cxx b/src/SMDS/SMDS_MeshElement.cxx index 8d0a608c4..46451674f 100644 --- a/src/SMDS/SMDS_MeshElement.cxx +++ b/src/SMDS/SMDS_MeshElement.cxx @@ -151,6 +151,7 @@ class SMDS_MeshElement_MyIterator:public SMDS_ElemIterator return myElement; } }; + SMDS_ElemIteratorPtr SMDS_MeshElement:: elementsIterator(SMDSAbs_ElementType type) const { @@ -167,6 +168,13 @@ SMDS_ElemIteratorPtr SMDS_MeshElement:: } } +//! virtual, redefined in vtkEdge, vtkFace and vtkVolume classes +SMDS_ElemIteratorPtr SMDS_MeshElement::nodesIteratorToUNV() const +{ + MESSAGE("Iterator not implemented"); + return SMDS_ElemIteratorPtr((SMDS_ElemIterator*) NULL); +} + /////////////////////////////////////////////////////////////////////////////// ///Return the ID of the element /////////////////////////////////////////////////////////////////////////////// diff --git a/src/SMDS/SMDS_MeshElement.hxx b/src/SMDS/SMDS_MeshElement.hxx index 3f8459a4e..c93085b1d 100644 --- a/src/SMDS/SMDS_MeshElement.hxx +++ b/src/SMDS/SMDS_MeshElement.hxx @@ -64,6 +64,7 @@ public: SMDS_ElemIteratorPtr edgesIterator() const; SMDS_ElemIteratorPtr facesIterator() const; virtual SMDS_ElemIteratorPtr elementsIterator(SMDSAbs_ElementType type) const; + virtual SMDS_ElemIteratorPtr nodesIteratorToUNV() const; // std-like iteration on nodes typedef SMDS_StdIterator< const SMDS_MeshNode*, SMDS_ElemIteratorPtr > iterator; diff --git a/src/SMDS/SMDS_MeshElementIDFactory.cxx b/src/SMDS/SMDS_MeshElementIDFactory.cxx index 901e6a044..2287086b6 100644 --- a/src/SMDS/SMDS_MeshElementIDFactory.cxx +++ b/src/SMDS/SMDS_MeshElementIDFactory.cxx @@ -79,7 +79,7 @@ SMDS_MeshElementIDFactory::SMDS_MeshElementIDFactory(): int SMDS_MeshElementIDFactory::SetInVtkGrid(SMDS_MeshElement * elem) { - // --- retreive nodes ID + // --- retrieve nodes ID vector nodeIds; SMDS_ElemIteratorPtr it = elem->nodesIterator(); @@ -132,10 +132,18 @@ SMDS_MeshElement* SMDS_MeshElementIDFactory::MeshElement(int ID) //======================================================================= void SMDS_MeshElementIDFactory::ReleaseID(const int ID) { + if (ID < 0) + { + MESSAGE("~~~~~~~~~~~~~~ SMDS_MeshElementIDFactory::ReleaseID ID = " << ID); + return; + } int vtkId = myMesh->myIDElements[ID]; //MESSAGE("~~~~~~~~~~~~~~ SMDS_MeshElementIDFactory::ReleaseID smdsId vtkId " << ID << " " << vtkId); - myMesh->myIDElements[ID] = -1; - myMesh->myVtkIndex[vtkId] = -1; + if (ID >=0) + { + myMesh->myIDElements[ID] = -1; + myMesh->myVtkIndex[vtkId] = -1; + } SMDS_MeshIDFactory::ReleaseID(ID); if (ID == myMax) myMax = 0; diff --git a/src/SMDS/SMDS_MeshNode.cxx b/src/SMDS/SMDS_MeshNode.cxx index 227c36732..71019c101 100644 --- a/src/SMDS/SMDS_MeshNode.cxx +++ b/src/SMDS/SMDS_MeshNode.cxx @@ -181,7 +181,7 @@ public: const SMDS_MeshElement* elem = myMesh->FindElement(smdsId); if (!elem) { - assert(0); + MESSAGE("SMDS_MeshNode_MyInvIterator problem Null element"); throw SALOME_Exception("SMDS_MeshNode_MyInvIterator problem Null element"); } //MESSAGE("vtkId " << vtkId << " smdsId " << smdsId << " " << elem->GetType()); diff --git a/src/SMDS/SMDS_UnstructuredGrid.cxx b/src/SMDS/SMDS_UnstructuredGrid.cxx index a62267de9..e5d8a7868 100644 --- a/src/SMDS/SMDS_UnstructuredGrid.cxx +++ b/src/SMDS/SMDS_UnstructuredGrid.cxx @@ -142,6 +142,7 @@ void SMDS_UnstructuredGrid::compactGrid(std::vector& idNodesOldToNew, int n for (int i = 0; i < oldNodeSize; i++) { + //MESSAGE(" " << i << " " << idNodesOldToNew[i]); switch (compactState) { case lookHoleStart: @@ -175,7 +176,7 @@ void SMDS_UnstructuredGrid::compactGrid(std::vector& idNodesOldToNew, int n { MESSAGE("-------------- newNodeSize, endbloc " << endBloc << " " << oldNodeSize); copyNodes(newPoints, idNodesOldToNew, alreadyCopied, startBloc, endBloc); - compactState = lookHoleStart; + compactState = lookHoleEnd; startHole = i; endHole = 0; startBloc = 0; diff --git a/src/SMDS/SMDS_VtkCellIterator.cxx b/src/SMDS/SMDS_VtkCellIterator.cxx index e2188f36b..4c1ed5632 100644 --- a/src/SMDS/SMDS_VtkCellIterator.cxx +++ b/src/SMDS/SMDS_VtkCellIterator.cxx @@ -1,15 +1,14 @@ #include "SMDS_VtkCellIterator.hxx" #include "utilities.h" - SMDS_VtkCellIterator::SMDS_VtkCellIterator(SMDS_Mesh* mesh, int vtkCellId, SMDSAbs_EntityType aType) : _mesh(mesh), _cellId(vtkCellId), _index(0), _type(aType) { - vtkUnstructuredGrid* grid = _mesh->getGrid(); + //MESSAGE("SMDS_VtkCellIterator " << _type); _vtkIdList = vtkIdList::New(); + vtkUnstructuredGrid* grid = _mesh->getGrid(); grid->GetCellPoints(_cellId, _vtkIdList); _nbNodes = _vtkIdList->GetNumberOfIds(); - vtkIdType tempid; switch (_type) { case SMDSEntity_Tetra: @@ -95,3 +94,99 @@ const SMDS_MeshElement* SMDS_VtkCellIterator::next() vtkIdType id = _vtkIdList->GetId(_index++); return _mesh->FindNode(id); } + +SMDS_VtkCellIteratorToUNV::SMDS_VtkCellIteratorToUNV(SMDS_Mesh* mesh, + int vtkCellId, + SMDSAbs_EntityType aType) +: SMDS_VtkCellIterator() +{ + _mesh = mesh; + _cellId = vtkCellId; + _index = 0; + _type = aType; + MESSAGE("SMDS_VtkCellInterlacedIterator " << _type); + + _vtkIdList = vtkIdList::New(); + vtkIdType* pts; + vtkUnstructuredGrid* grid = _mesh->getGrid(); + grid->GetCellPoints(_cellId, _nbNodes, pts); + _vtkIdList->SetNumberOfIds(_nbNodes); + int *ids = 0; + switch (_type) + { + case SMDSEntity_Quad_Edge: + { + static int id[] = {0,2,1}; + ids = id; + break; + } + case SMDSEntity_Quad_Triangle: + { + static int id[] = {0,3,1,4,2,5}; + ids = id; + break; + } + case SMDSEntity_Quad_Quadrangle: + { + static int id[] = {0,4,1,5,2,6,3,7}; + ids = id; + break; + } + case SMDSEntity_Quad_Tetra: + { + static int id[] = {0,4,1,5,2,6,7,8,9,3}; + ids = id; + break; + } + case SMDSEntity_Quad_Pyramid: + { + static int id[] = {0,5,1,6,2,7,3,8,9,10,11,12,4}; + ids = id; + break; + } + case SMDSEntity_Penta: + { + static int id[] = {0,2,1,3,5,4}; + ids = id; + break; + } + case SMDSEntity_Quad_Penta: + { + static int id[] = {0,8,2,7,1,6,12,14,13,3,11,5,10,4,9}; + ids = id; + break; + } + case SMDSEntity_Quad_Hexa: + { + static int id[] = {0,8,1,9,2,10,3,11,16,17,18,19,4,12,5,13,6,14,7,15}; + ids = id; + break; + } + 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}; + ids = id; + break; + } + } + //MESSAGE("_nbNodes " << _nbNodes); + for (int i=0; i<_nbNodes; i++) + _vtkIdList->SetId(i, pts[ids[i]]); +} + +SMDS_VtkCellIteratorToUNV::~SMDS_VtkCellIteratorToUNV() +{ +} + diff --git a/src/SMDS/SMDS_VtkCellIterator.hxx b/src/SMDS/SMDS_VtkCellIterator.hxx index 537c76d2c..bd7bf90ab 100644 --- a/src/SMDS/SMDS_VtkCellIterator.hxx +++ b/src/SMDS/SMDS_VtkCellIterator.hxx @@ -11,8 +11,7 @@ class SMDS_VtkCellIterator: public SMDS_ElemIterator { public: - SMDS_VtkCellIterator(SMDS_Mesh* mesh, int vtkCellId, - SMDSAbs_EntityType aType); + SMDS_VtkCellIterator(SMDS_Mesh* mesh, int vtkCellId, SMDSAbs_EntityType aType); virtual ~SMDS_VtkCellIterator(); virtual bool more(); virtual const SMDS_MeshElement* next(); @@ -24,6 +23,8 @@ public: } protected: + SMDS_VtkCellIterator() {}; + SMDS_Mesh* _mesh; int _cellId; int _index; @@ -32,4 +33,11 @@ protected: vtkIdList* _vtkIdList; }; +class SMDS_VtkCellIteratorToUNV: public SMDS_VtkCellIterator +{ +public: + SMDS_VtkCellIteratorToUNV(SMDS_Mesh* mesh, int vtkCellId, SMDSAbs_EntityType aType); + virtual ~SMDS_VtkCellIteratorToUNV(); +}; + #endif diff --git a/src/SMDS/SMDS_VtkEdge.cxx b/src/SMDS/SMDS_VtkEdge.cxx index 923a6212b..ecd723f65 100644 --- a/src/SMDS/SMDS_VtkEdge.cxx +++ b/src/SMDS/SMDS_VtkEdge.cxx @@ -34,16 +34,27 @@ void SMDS_VtkEdge::init(std::vector nodeIds, SMDS_Mesh* mesh) myVtkID = grid->InsertNextLinkedCell(aType, nodeIds.size(), &nodeIds[0]); } -bool SMDS_VtkEdge::ChangeNodes(const SMDS_MeshNode * node1, - const SMDS_MeshNode * node2) +bool SMDS_VtkEdge::ChangeNodes(const SMDS_MeshNode * node1, const SMDS_MeshNode * node2) { - // TODO remove - return true; + const SMDS_MeshNode* nodes[] = { node1, node2 }; + return ChangeNodes(nodes, 2); } bool SMDS_VtkEdge::ChangeNodes(const SMDS_MeshNode* nodes[], const int nbNodes) { - // TODO + vtkUnstructuredGrid* grid = SMDS_Mesh::_meshList[myMeshId]->getGrid(); + vtkIdType npts = 0; + vtkIdType* pts = 0; + grid->GetCellPoints(myVtkID, npts, pts); + if (nbNodes != npts) + { + MESSAGE("ChangeNodes problem: not the same number of nodes " << npts << " -> " << nbNodes); + return false; + } + for (int i = 0; i < nbNodes; i++) + { + pts[i] = nodes[i]->GetID(); + } return true; } @@ -106,14 +117,15 @@ SMDS_ElemIteratorPtr SMDS_VtkEdge::elementsIterator(SMDSAbs_ElementType type) co switch (type) { case SMDSAbs_Node: - return SMDS_ElemIteratorPtr( - new SMDS_VtkCellIterator( - SMDS_Mesh::_meshList[myMeshId], - myVtkID, - GetEntityType())); + 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_VtkEdge::nodesIteratorToUNV() const +{ + return SMDS_ElemIteratorPtr(new SMDS_VtkCellIteratorToUNV(SMDS_Mesh::_meshList[myMeshId], myVtkID, GetEntityType())); +} diff --git a/src/SMDS/SMDS_VtkEdge.hxx b/src/SMDS/SMDS_VtkEdge.hxx index b68b904f7..19baccea6 100644 --- a/src/SMDS/SMDS_VtkEdge.hxx +++ b/src/SMDS/SMDS_VtkEdge.hxx @@ -28,8 +28,7 @@ public: virtual bool IsQuadratic() const; protected: - SMDS_ElemIteratorPtr - elementsIterator(SMDSAbs_ElementType type) const; - + virtual SMDS_ElemIteratorPtr elementsIterator(SMDSAbs_ElementType type) const; + virtual SMDS_ElemIteratorPtr nodesIteratorToUNV() const; }; #endif diff --git a/src/SMDS/SMDS_VtkFace.cxx b/src/SMDS/SMDS_VtkFace.cxx index 763219c39..7a52ed4f1 100644 --- a/src/SMDS/SMDS_VtkFace.cxx +++ b/src/SMDS/SMDS_VtkFace.cxx @@ -51,7 +51,19 @@ void SMDS_VtkFace::init(std::vector nodeIds, SMDS_Mesh* mesh) bool SMDS_VtkFace::ChangeNodes(const SMDS_MeshNode* nodes[], const int nbNodes) { - // TODO + vtkUnstructuredGrid* grid = SMDS_Mesh::_meshList[myMeshId]->getGrid(); + vtkIdType npts = 0; + vtkIdType* pts = 0; + grid->GetCellPoints(myVtkID, npts, pts); + if (nbNodes != npts) + { + MESSAGE("ChangeNodes problem: not the same number of nodes " << npts << " -> " << nbNodes); + return false; + } + for (int i=0; iGetID(); + } return true; } @@ -110,17 +122,21 @@ bool SMDS_VtkFace::IsQuadratic() const SMDSAbs_EntityType SMDS_VtkFace::GetEntityType() const { - SMDSAbs_EntityType aType = SMDSEntity_Triangle; + SMDSAbs_EntityType aType = SMDSEntity_Polygon; switch (NbNodes()) { case 3: - case 6: aType = SMDSEntity_Triangle; break; + case 6: + aType = SMDSEntity_Quad_Triangle; + break; case 4: - case 8: aType = SMDSEntity_Quadrangle; break; + case 8: + aType = SMDSEntity_Quad_Quadrangle; + break; } return aType; } @@ -137,6 +153,8 @@ vtkIdType SMDS_VtkFace::GetVtkType() const return VTK_QUAD; case 8: return VTK_QUADRATIC_QUAD; + default: + return VTK_POLYGON; } } @@ -145,15 +163,14 @@ SMDS_ElemIteratorPtr SMDS_VtkFace::elementsIterator(SMDSAbs_ElementType type) co switch (type) { case SMDSAbs_Node: - return SMDS_ElemIteratorPtr( - new SMDS_VtkCellIterator( - SMDS_Mesh::_meshList[myMeshId], - myVtkID, - GetEntityType())); + return SMDS_ElemIteratorPtr(new SMDS_VtkCellIterator(SMDS_Mesh::_meshList[myMeshId], myVtkID, GetEntityType())); default: - MESSAGE("ERROR : Iterator not implemented") - ; + 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())); +} diff --git a/src/SMDS/SMDS_VtkFace.hxx b/src/SMDS/SMDS_VtkFace.hxx index e371396b9..ecc0585ec 100644 --- a/src/SMDS/SMDS_VtkFace.hxx +++ b/src/SMDS/SMDS_VtkFace.hxx @@ -27,8 +27,8 @@ public: virtual bool IsQuadratic() const; protected: - SMDS_ElemIteratorPtr - elementsIterator(SMDSAbs_ElementType type) const; + virtual SMDS_ElemIteratorPtr elementsIterator(SMDSAbs_ElementType type) const; + virtual SMDS_ElemIteratorPtr nodesIteratorToUNV() const; }; #endif diff --git a/src/SMDS/SMDS_VtkVolume.cxx b/src/SMDS/SMDS_VtkVolume.cxx index d2a15d5e7..7bb479925 100644 --- a/src/SMDS/SMDS_VtkVolume.cxx +++ b/src/SMDS/SMDS_VtkVolume.cxx @@ -83,7 +83,19 @@ void SMDS_VtkVolume::initPoly(std::vector nodeIds, std::vector n bool SMDS_VtkVolume::ChangeNodes(const SMDS_MeshNode* nodes[], const int nbNodes) { - // TODO utilise dans SMDS_Mesh + vtkUnstructuredGrid* grid = SMDS_Mesh::_meshList[myMeshId]->getGrid(); + vtkIdType npts = 0; + vtkIdType* pts = 0; + grid->GetCellPoints(myVtkID, npts, pts); + if (nbNodes != npts) + { + MESSAGE("ChangeNodes problem: not the same number of nodes " << npts << " -> " << nbNodes); + return false; + } + for (int i=0; iGetID(); + } return true; } @@ -158,12 +170,17 @@ SMDS_ElemIteratorPtr SMDS_VtkVolume::elementsIterator(SMDSAbs_ElementType type) case SMDSAbs_Node: return SMDS_ElemIteratorPtr(new SMDS_VtkCellIterator(SMDS_Mesh::_meshList[myMeshId], myVtkID, GetEntityType())); default: - MESSAGE("ERROR : Iterator not implemented") - ; + MESSAGE("ERROR : Iterator not implemented"); return SMDS_ElemIteratorPtr((SMDS_ElemIterator*) NULL); } } +SMDS_ElemIteratorPtr SMDS_VtkVolume::nodesIteratorToUNV() const +{ + return SMDS_ElemIteratorPtr(new SMDS_VtkCellIteratorToUNV(SMDS_Mesh::_meshList[myMeshId], myVtkID, GetEntityType())); +} + + SMDSAbs_ElementType SMDS_VtkVolume::GetType() const { return SMDSAbs_Volume; diff --git a/src/SMDS/SMDS_VtkVolume.hxx b/src/SMDS/SMDS_VtkVolume.hxx index 54d01b605..1b8360d94 100644 --- a/src/SMDS/SMDS_VtkVolume.hxx +++ b/src/SMDS/SMDS_VtkVolume.hxx @@ -30,8 +30,8 @@ public: virtual bool IsQuadratic() const; protected: - SMDS_ElemIteratorPtr - elementsIterator(SMDSAbs_ElementType type) const; + virtual SMDS_ElemIteratorPtr elementsIterator(SMDSAbs_ElementType type) const; + virtual SMDS_ElemIteratorPtr nodesIteratorToUNV() const; }; #endif diff --git a/src/SMESH/SMESH_MeshEditor.cxx b/src/SMESH/SMESH_MeshEditor.cxx index 5b4bfbaf5..f9e79c551 100644 --- a/src/SMESH/SMESH_MeshEditor.cxx +++ b/src/SMESH/SMESH_MeshEditor.cxx @@ -476,15 +476,19 @@ static bool GetNodesFromTwoTria(const SMDS_MeshElement * theTria1, bool SMESH_MeshEditor::InverseDiag (const SMDS_MeshElement * theTria1, const SMDS_MeshElement * theTria2 ) { + MESSAGE("InverseDiag"); myLastCreatedElems.Clear(); myLastCreatedNodes.Clear(); if (!theTria1 || !theTria2) return false; - const SMDS_FaceOfNodes* F1 = dynamic_cast( theTria1 ); - const SMDS_FaceOfNodes* F2 = dynamic_cast( theTria2 ); - if (F1 && F2) { + const SMDS_VtkFace* F1 = dynamic_cast( theTria1 ); + if (!F1) return false; + const SMDS_VtkFace* F2 = dynamic_cast( theTria2 ); + if (!F2) return false; + if ((theTria1->GetEntityType() == SMDSEntity_Triangle) && + (theTria2->GetEntityType() == SMDSEntity_Triangle)) { // 1 +--+ A theTria1: ( 1 A B ) A->2 ( 1 2 B ) 1 +--+ A // | /| theTria2: ( B A 2 ) B->1 ( 1 A 2 ) |\ | @@ -537,24 +541,18 @@ bool SMESH_MeshEditor::InverseDiag (const SMDS_MeshElement * theTria1, // theTria2: B->1 aNodes[ sameInd[ iB ]] = aNodes[ i1 ]; - //MESSAGE( theTria1 << theTria2 ); - GetMeshDS()->ChangeElementNodes( theTria1, aNodes, 3 ); GetMeshDS()->ChangeElementNodes( theTria2, &aNodes[ 3 ], 3 ); - //MESSAGE( theTria1 << theTria2 ); - return true; } // end if(F1 && F2) // check case of quadratic faces - const SMDS_QuadraticFaceOfNodes* QF1 = - dynamic_cast (theTria1); - if(!QF1) return false; - const SMDS_QuadraticFaceOfNodes* QF2 = - dynamic_cast (theTria2); - if(!QF2) return false; + if (theTria1->GetEntityType() != SMDSEntity_Quad_Triangle) + return false; + if (theTria2->GetEntityType() == SMDSEntity_Quad_Triangle) + return false; // 5 // 1 +--+--+ 2 theTria1: (1 2 4 5 9 7) or (2 4 1 9 7 5) or (4 1 2 7 5 9) @@ -657,11 +655,12 @@ bool SMESH_MeshEditor::InverseDiag (const SMDS_MeshNode * theNode1, if ( !findTriangles( theNode1, theNode2, tr1, tr2 )) return false; - const SMDS_FaceOfNodes* F1 = dynamic_cast( tr1 ); - //if (!F1) return false; - const SMDS_FaceOfNodes* F2 = dynamic_cast( tr2 ); - //if (!F2) return false; - if (F1 && F2) { + const SMDS_VtkFace* F1 = dynamic_cast( tr1 ); + if (!F1) return false; + const SMDS_VtkFace* F2 = dynamic_cast( tr2 ); + if (!F2) return false; + if ((tr1->GetEntityType() == SMDSEntity_Triangle) && + (tr2->GetEntityType() == SMDSEntity_Triangle)) { // 1 +--+ A tr1: ( 1 A B ) A->2 ( 1 2 B ) 1 +--+ A // | /| tr2: ( B A 2 ) B->1 ( 1 A 2 ) |\ | @@ -699,23 +698,13 @@ bool SMESH_MeshEditor::InverseDiag (const SMDS_MeshNode * theNode1, // tr2: B->1 aNodes2[ iB2 ] = aNodes1[ i1 ]; - //MESSAGE( tr1 << tr2 ); - GetMeshDS()->ChangeElementNodes( tr1, aNodes1, 3 ); GetMeshDS()->ChangeElementNodes( tr2, aNodes2, 3 ); - //MESSAGE( tr1 << tr2 ); - return true; } // check case of quadratic faces - const SMDS_QuadraticFaceOfNodes* QF1 = - dynamic_cast (tr1); - if(!QF1) return false; - const SMDS_QuadraticFaceOfNodes* QF2 = - dynamic_cast (tr2); - if(!QF2) return false; return InverseDiag(tr1,tr2); } @@ -789,34 +778,34 @@ bool SMESH_MeshEditor::DeleteDiag (const SMDS_MeshNode * theNode1, if ( !findTriangles( theNode1, theNode2, tr1, tr2 )) return false; - const SMDS_FaceOfNodes* F1 = dynamic_cast( tr1 ); - //if (!F1) return false; - const SMDS_FaceOfNodes* F2 = dynamic_cast( tr2 ); - //if (!F2) return false; - if (F1 && F2) { + const SMDS_VtkFace* F1 = dynamic_cast( tr1 ); + if (!F1) return false; + const SMDS_VtkFace* F2 = dynamic_cast( tr2 ); + if (!F2) return false; + SMESHDS_Mesh * aMesh = GetMeshDS(); + + if ((tr1->GetEntityType() == SMDSEntity_Triangle) && + (tr2->GetEntityType() == SMDSEntity_Triangle)) { const SMDS_MeshNode* aNodes [ 4 ]; if ( ! getQuadrangleNodes( aNodes, theNode1, theNode2, tr1, tr2 )) return false; - //MESSAGE( endl << tr1 << tr2 ); - // TODO problem ChangeElementNodes : not the same number of nodes, not the same type - GetMeshDS()->ChangeElementNodes( tr1, aNodes, 4 ); - myLastCreatedElems.Append(tr1); - GetMeshDS()->RemoveElement( tr2 ); - - //MESSAGE( endl << tr1 ); + const SMDS_MeshElement* newElem = 0; + newElem = aMesh->AddFace( aNodes[0], aNodes[1], aNodes[2], aNodes[3] ); + myLastCreatedElems.Append(newElem); + AddToSameGroups( newElem, tr1, aMesh ); + aMesh->RemoveElement( tr1 ); + aMesh->RemoveElement( tr2 ); return true; } // check case of quadratic faces - const SMDS_QuadraticFaceOfNodes* QF1 = - dynamic_cast (tr1); - if(!QF1) return false; - const SMDS_QuadraticFaceOfNodes* QF2 = - dynamic_cast (tr2); - if(!QF2) return false; + if (tr1->GetEntityType() != SMDSEntity_Quad_Triangle) + return false; + if (tr2->GetEntityType() != SMDSEntity_Quad_Triangle) + return false; // 5 // 1 +--+--+ 2 tr1: (1 2 4 5 9 7) or (2 4 1 9 7 5) or (4 1 2 7 5 9) @@ -846,10 +835,13 @@ bool SMESH_MeshEditor::DeleteDiag (const SMDS_MeshNode * theNode1, aNodes[6] = N2[3]; aNodes[7] = N1[5]; - // TODO problem ChangeElementNodes : not the same number of nodes, not the same type - GetMeshDS()->ChangeElementNodes( tr1, aNodes, 8 ); - myLastCreatedElems.Append(tr1); - GetMeshDS()->RemoveElement( tr2 ); + const SMDS_MeshElement* newElem = 0; + newElem = aMesh->AddFace( aNodes[0], aNodes[1], aNodes[2], aNodes[3], + aNodes[4], aNodes[5], aNodes[6], aNodes[7]); + myLastCreatedElems.Append(newElem); + AddToSameGroups( newElem, tr1, aMesh ); + aMesh->RemoveElement( tr1 ); + aMesh->RemoveElement( tr2 ); // remove middle node (9) GetMeshDS()->RemoveNode( N1[4] ); @@ -864,6 +856,7 @@ bool SMESH_MeshEditor::DeleteDiag (const SMDS_MeshNode * theNode1, bool SMESH_MeshEditor::Reorient (const SMDS_MeshElement * theElem) { + MESSAGE("Reorient"); myLastCreatedElems.Clear(); myLastCreatedNodes.Clear(); @@ -910,6 +903,8 @@ bool SMESH_MeshEditor::Reorient (const SMDS_MeshElement * theElem) } case SMDSAbs_Volume: { if (theElem->IsPoly()) { + // TODO reorient vtk polyhedron + MESSAGE("reorient vtk polyhedron ?"); const SMDS_PolyhedralVolumeOfNodes* aPolyedre = static_cast( theElem ); if (!aPolyedre) { @@ -940,6 +935,7 @@ bool SMESH_MeshEditor::Reorient (const SMDS_MeshElement * theElem) if ( !vTool.Set( theElem )) return false; vTool.Inverse(); + MESSAGE("ChangeElementNodes reorient: check vTool.Inverse"); return GetMeshDS()->ChangeElementNodes( theElem, vTool.GetNodes(), vTool.NbNodes() ); } } @@ -1012,23 +1008,21 @@ bool SMESH_MeshEditor::QuadToTri (TIDSortedElemSet & theElems, aBadRate2 = getBadRate( &tr3, theCrit ) + getBadRate( &tr4, theCrit ); int aShapeId = FindShape( elem ); - const SMDS_MeshElement* newElem = 0; + const SMDS_MeshElement* newElem1 = 0; + const SMDS_MeshElement* newElem2 = 0; if( !elem->IsQuadratic() ) { // split liner quadrangle - if ( aBadRate1 <= aBadRate2 ) { // tr1 + tr2 is better - // TODO problem ChangeElementNodes : not the same number of nodes, not the same type - aMesh->ChangeElementNodes( elem, aNodes, 3 ); - newElem = aMesh->AddFace( aNodes[2], aNodes[3], aNodes[0] ); + newElem1 = aMesh->AddFace( aNodes[2], aNodes[3], aNodes[0] ); + newElem2 = aMesh->AddFace( aNodes[2], aNodes[0], aNodes[1] ); } else { // tr3 + tr4 is better - // TODO problem ChangeElementNodes : not the same number of nodes, not the same type - aMesh->ChangeElementNodes( elem, &aNodes[1], 3 ); - newElem = aMesh->AddFace( aNodes[3], aNodes[0], aNodes[1] ); + newElem1 = aMesh->AddFace( aNodes[3], aNodes[0], aNodes[1] ); + newElem2 = aMesh->AddFace( aNodes[3], aNodes[1], aNodes[2] ); } } else { @@ -1089,8 +1083,10 @@ bool SMESH_MeshEditor::QuadToTri (TIDSortedElemSet & theElems, N[3] = aNodes[4]; N[4] = aNodes[5]; N[5] = newN; - newElem = aMesh->AddFace(aNodes[2], aNodes[3], aNodes[0], - aNodes[6], aNodes[7], newN ); + newElem1 = aMesh->AddFace(aNodes[2], aNodes[3], aNodes[0], + aNodes[6], aNodes[7], newN ); + newElem2 = aMesh->AddFace(aNodes[2], aNodes[0], aNodes[1], + newN, aNodes[4], aNodes[5] ); } else { N[0] = aNodes[1]; @@ -1099,22 +1095,27 @@ bool SMESH_MeshEditor::QuadToTri (TIDSortedElemSet & theElems, N[3] = aNodes[5]; N[4] = aNodes[6]; N[5] = newN; - newElem = aMesh->AddFace(aNodes[3], aNodes[0], aNodes[1], - aNodes[7], aNodes[4], newN ); + newElem1 = aMesh->AddFace(aNodes[3], aNodes[0], aNodes[1], + aNodes[7], aNodes[4], newN ); + newElem2 = aMesh->AddFace(aNodes[3], aNodes[1], aNodes[2], + newN, aNodes[5], aNodes[6] ); } - // TODO problem ChangeElementNodes : not the same number of nodes, not the same type - aMesh->ChangeElementNodes( elem, N, 6 ); - } // quadratic case // care of a new element - myLastCreatedElems.Append(newElem); - AddToSameGroups( newElem, elem, aMesh ); + myLastCreatedElems.Append(newElem1); + myLastCreatedElems.Append(newElem2); + AddToSameGroups( newElem1, elem, aMesh ); + AddToSameGroups( newElem2, elem, aMesh ); // put a new triangle on the same shape if ( aShapeId ) - aMesh->SetMeshElementOnShape( newElem, aShapeId ); + { + aMesh->SetMeshElementOnShape( newElem1, aShapeId ); + aMesh->SetMeshElementOnShape( newElem2, aShapeId ); + } + aMesh->RemoveElement( elem ); } return true; } @@ -1733,22 +1734,28 @@ bool SMESH_MeshEditor::QuadToTri (TIDSortedElemSet & theElems, aNodes[ i++ ] = static_cast( itN->next() ); int aShapeId = FindShape( elem ); - const SMDS_MeshElement* newElem = 0; + const SMDS_MeshElement* newElem1 = 0; + const SMDS_MeshElement* newElem2 = 0; if ( the13Diag ) { - // TODO problem ChangeElementNodes : not the same number of nodes, not the same type - aMesh->ChangeElementNodes( elem, aNodes, 3 ); - newElem = aMesh->AddFace( aNodes[2], aNodes[3], aNodes[0] ); + newElem1 = aMesh->AddFace( aNodes[2], aNodes[0], aNodes[1] ); + newElem2 = aMesh->AddFace( aNodes[2], aNodes[3], aNodes[0] ); } else { - // TODO problem ChangeElementNodes : not the same number of nodes, not the same type - aMesh->ChangeElementNodes( elem, &aNodes[1], 3 ); - newElem = aMesh->AddFace( aNodes[3], aNodes[0], aNodes[1] ); + newElem1 = aMesh->AddFace( aNodes[3], aNodes[0], aNodes[1] ); + newElem2 = aMesh->AddFace( aNodes[3], aNodes[1], aNodes[2] ); } - myLastCreatedElems.Append(newElem); + myLastCreatedElems.Append(newElem1); + myLastCreatedElems.Append(newElem2); // put a new triangle on the same shape and add to the same groups if ( aShapeId ) - aMesh->SetMeshElementOnShape( newElem, aShapeId ); - AddToSameGroups( newElem, elem, aMesh ); + { + aMesh->SetMeshElementOnShape( newElem1, aShapeId ); + aMesh->SetMeshElementOnShape( newElem2, aShapeId ); + } + AddToSameGroups( newElem1, elem, aMesh ); + AddToSameGroups( newElem2, elem, aMesh ); + //aMesh->RemoveFreeElement(elem, aMesh->MeshElements(aShapeId), true); + aMesh->RemoveElement( elem ); } // Quadratic quadrangle @@ -1803,7 +1810,8 @@ bool SMESH_MeshEditor::QuadToTri (TIDSortedElemSet & theElems, myLastCreatedNodes.Append(newN); // create a new element - const SMDS_MeshElement* newElem = 0; + const SMDS_MeshElement* newElem1 = 0; + const SMDS_MeshElement* newElem2 = 0; const SMDS_MeshNode* N[6]; if ( the13Diag ) { N[0] = aNodes[0]; @@ -1812,8 +1820,10 @@ bool SMESH_MeshEditor::QuadToTri (TIDSortedElemSet & theElems, N[3] = aNodes[4]; N[4] = aNodes[5]; N[5] = newN; - newElem = aMesh->AddFace(aNodes[2], aNodes[3], aNodes[0], - aNodes[6], aNodes[7], newN ); + newElem1 = aMesh->AddFace(aNodes[2], aNodes[3], aNodes[0], + aNodes[6], aNodes[7], newN ); + newElem2 = aMesh->AddFace(aNodes[2], aNodes[0], aNodes[1], + newN, aNodes[4], aNodes[5] ); } else { N[0] = aNodes[1]; @@ -1822,16 +1832,22 @@ bool SMESH_MeshEditor::QuadToTri (TIDSortedElemSet & theElems, N[3] = aNodes[5]; N[4] = aNodes[6]; N[5] = newN; - newElem = aMesh->AddFace(aNodes[3], aNodes[0], aNodes[1], - aNodes[7], aNodes[4], newN ); + newElem1 = aMesh->AddFace(aNodes[3], aNodes[0], aNodes[1], + aNodes[7], aNodes[4], newN ); + newElem2 = aMesh->AddFace(aNodes[3], aNodes[1], aNodes[2], + newN, aNodes[5], aNodes[6] ); } - myLastCreatedElems.Append(newElem); - // TODO problem ChangeElementNodes : not the same number of nodes, not the same type - aMesh->ChangeElementNodes( elem, N, 6 ); + myLastCreatedElems.Append(newElem1); + myLastCreatedElems.Append(newElem2); // put a new triangle on the same shape and add to the same groups if ( aShapeId ) - aMesh->SetMeshElementOnShape( newElem, aShapeId ); - AddToSameGroups( newElem, elem, aMesh ); + { + aMesh->SetMeshElementOnShape( newElem1, aShapeId ); + aMesh->SetMeshElementOnShape( newElem2, aShapeId ); + } + AddToSameGroups( newElem1, elem, aMesh ); + AddToSameGroups( newElem2, elem, aMesh ); + aMesh->RemoveElement( elem ); } } @@ -2127,18 +2143,12 @@ bool SMESH_MeshEditor::TriToQuad (TIDSortedElemSet & theElems, mapEl_setLi.erase( tr2 ); mapLi_listEl.erase( *link12 ); if(tr1->NbNodes()==3) { - if( tr1->GetID() < tr2->GetID() ) { - // TODO problem ChangeElementNodes : not the same number of nodes, not the same type - aMesh->ChangeElementNodes( tr1, n12, 4 ); - myLastCreatedElems.Append(tr1); - aMesh->RemoveElement( tr2 ); - } - else { - // TODO problem ChangeElementNodes : not the same number of nodes, not the same type - aMesh->ChangeElementNodes( tr2, n12, 4 ); - myLastCreatedElems.Append(tr2); - aMesh->RemoveElement( tr1); - } + const SMDS_MeshElement* newElem = 0; + newElem = aMesh->AddFace(n12[0], n12[1], n12[2], n12[3] ); + myLastCreatedElems.Append(newElem); + AddToSameGroups( newElem, tr1, aMesh ); + aMesh->RemoveElement( tr1 ); + aMesh->RemoveElement( tr2 ); } else { const SMDS_MeshNode* N1 [6]; @@ -2156,18 +2166,13 @@ bool SMESH_MeshEditor::TriToQuad (TIDSortedElemSet & theElems, aNodes[5] = N2[5]; aNodes[6] = N2[3]; aNodes[7] = N1[5]; - if( tr1->GetID() < tr2->GetID() ) { - // TODO problem ChangeElementNodes : not the same number of nodes, not the same type - GetMeshDS()->ChangeElementNodes( tr1, aNodes, 8 ); - myLastCreatedElems.Append(tr1); - GetMeshDS()->RemoveElement( tr2 ); - } - else { - // TODO problem ChangeElementNodes : not the same number of nodes, not the same type - GetMeshDS()->ChangeElementNodes( tr2, aNodes, 8 ); - myLastCreatedElems.Append(tr2); - GetMeshDS()->RemoveElement( tr1 ); - } + const SMDS_MeshElement* newElem = 0; + newElem = aMesh->AddFace(aNodes[0], aNodes[1], aNodes[2], aNodes[3], + aNodes[4], aNodes[5], aNodes[6], aNodes[7]); + myLastCreatedElems.Append(newElem); + AddToSameGroups( newElem, tr1, aMesh ); + aMesh->RemoveElement( tr1 ); + aMesh->RemoveElement( tr2 ); // remove middle node (9) GetMeshDS()->RemoveNode( N1[4] ); } @@ -2176,18 +2181,12 @@ bool SMESH_MeshEditor::TriToQuad (TIDSortedElemSet & theElems, mapEl_setLi.erase( tr3 ); mapLi_listEl.erase( *link13 ); if(tr1->NbNodes()==3) { - if( tr1->GetID() < tr2->GetID() ) { - // TODO problem ChangeElementNodes : not the same number of nodes, not the same type - aMesh->ChangeElementNodes( tr1, n13, 4 ); - myLastCreatedElems.Append(tr1); - aMesh->RemoveElement( tr3 ); - } - else { - // TODO problem ChangeElementNodes : not the same number of nodes, not the same type - aMesh->ChangeElementNodes( tr3, n13, 4 ); - myLastCreatedElems.Append(tr3); - aMesh->RemoveElement( tr1 ); - } + const SMDS_MeshElement* newElem = 0; + newElem = aMesh->AddFace(n13[0], n13[1], n13[2], n13[3] ); + myLastCreatedElems.Append(newElem); + AddToSameGroups( newElem, tr1, aMesh ); + aMesh->RemoveElement( tr1 ); + aMesh->RemoveElement( tr3 ); } else { const SMDS_MeshNode* N1 [6]; @@ -2205,18 +2204,13 @@ bool SMESH_MeshEditor::TriToQuad (TIDSortedElemSet & theElems, aNodes[5] = N2[5]; aNodes[6] = N2[3]; aNodes[7] = N1[5]; - if( tr1->GetID() < tr2->GetID() ) { - // TODO problem ChangeElementNodes : not the same number of nodes, not the same type - GetMeshDS()->ChangeElementNodes( tr1, aNodes, 8 ); - myLastCreatedElems.Append(tr1); - GetMeshDS()->RemoveElement( tr3 ); - } - else { - // TODO problem ChangeElementNodes : not the same number of nodes, not the same type - GetMeshDS()->ChangeElementNodes( tr3, aNodes, 8 ); - myLastCreatedElems.Append(tr3); - GetMeshDS()->RemoveElement( tr1 ); - } + const SMDS_MeshElement* newElem = 0; + newElem = aMesh->AddFace(aNodes[0], aNodes[1], aNodes[2], aNodes[3], + aNodes[4], aNodes[5], aNodes[6], aNodes[7]); + myLastCreatedElems.Append(newElem); + AddToSameGroups( newElem, tr1, aMesh ); + aMesh->RemoveElement( tr1 ); + aMesh->RemoveElement( tr3 ); // remove middle node (9) GetMeshDS()->RemoveNode( N1[4] ); } @@ -3689,6 +3683,7 @@ void SMESH_MeshEditor::makeWalls (TNodeOfNodeListMap & mapNewNodes, const int nbSteps, SMESH_SequenceOfElemPtr& srcElements) { + MESSAGE("makeWalls"); ASSERT( newElemsMap.size() == elemNewNodesMap.size() ); SMESHDS_Mesh* aMesh = GetMeshDS(); @@ -3889,8 +3884,10 @@ void SMESH_MeshEditor::makeWalls (TNodeOfNodeListMap & mapNewNodes, if ( !f ) myLastCreatedElems.Append(aMesh->AddFace( nodes[ 0 ], nodes[ 1 ], nodes[ 2 ] )); else if ( nodes[ 1 ] != f->GetNodeWrap( f->GetNodeIndex( nodes[ 0 ] ) + 1 )) - // TODO problem ChangeElementNodes : not the same number of nodes, not the same type - aMesh->ChangeElementNodes( f, nodes, nbn ); + { + myLastCreatedElems.Append(aMesh->AddFace( nodes[ 0 ], nodes[ 1 ], nodes[ 2 ] )); + aMesh->RemoveElement(f); + } break; } case 4: { ///// quadrangle @@ -3898,8 +3895,10 @@ void SMESH_MeshEditor::makeWalls (TNodeOfNodeListMap & mapNewNodes, if ( !f ) myLastCreatedElems.Append(aMesh->AddFace( nodes[ 0 ], nodes[ 1 ], nodes[ 2 ], nodes[ 3 ] )); else if ( nodes[ 1 ] != f->GetNodeWrap( f->GetNodeIndex( nodes[ 0 ] ) + 1 )) - // TODO problem ChangeElementNodes : not the same number of nodes, not the same type - aMesh->ChangeElementNodes( f, nodes, nbn ); + { + myLastCreatedElems.Append(aMesh->AddFace( nodes[ 0 ], nodes[ 1 ], nodes[ 2 ], nodes[ 3 ] )); + aMesh->RemoveElement(f); + } break; } default: @@ -3919,8 +3918,9 @@ void SMESH_MeshEditor::makeWalls (TNodeOfNodeListMap & mapNewNodes, tmpnodes[3] = nodes[1]; tmpnodes[4] = nodes[3]; tmpnodes[5] = nodes[5]; - // TODO problem ChangeElementNodes : not the same number of nodes, not the same type - aMesh->ChangeElementNodes( f, tmpnodes, nbn ); + myLastCreatedElems.Append(aMesh->AddFace(nodes[0], nodes[2], nodes[4], + nodes[1], nodes[3], nodes[5])); + aMesh->RemoveElement(f); } } else { /////// quadratic quadrangle @@ -3940,8 +3940,9 @@ void SMESH_MeshEditor::makeWalls (TNodeOfNodeListMap & mapNewNodes, tmpnodes[5] = nodes[3]; tmpnodes[6] = nodes[5]; tmpnodes[7] = nodes[7]; - // TODO problem ChangeElementNodes : not the same number of nodes, not the same type - aMesh->ChangeElementNodes( f, tmpnodes, nbn ); + myLastCreatedElems.Append(aMesh->AddFace(nodes[0], nodes[2], nodes[4], nodes[6], + nodes[1], nodes[3], nodes[5], nodes[7])); + aMesh->RemoveElement(f); } } } @@ -3951,8 +3952,11 @@ void SMESH_MeshEditor::makeWalls (TNodeOfNodeListMap & mapNewNodes, if ( !f ) myLastCreatedElems.Append(aMesh->AddPolygonalFace(polygon_nodes)); else if ( nodes[ 1 ] != f->GetNodeWrap( f->GetNodeIndex( nodes[ 0 ] ) + 1 )) + { // TODO problem ChangeElementNodes : not the same number of nodes, not the same type + MESSAGE("ChangeElementNodes"); aMesh->ChangeElementNodes( f, nodes, nbn ); + } } } while ( srcElements.Length() < myLastCreatedElems.Length() ) @@ -5244,7 +5248,7 @@ SMESH_MeshEditor::Transform (TIDSortedElemSet & theElems, theElems.insert( *invElemIt ); // replicate or reverse elements - + // TODO revoir ordre reverse vtk enum { REV_TETRA = 0, // = nbNodes - 4 REV_PYRAMID = 1, // = nbNodes - 4 @@ -5459,6 +5463,7 @@ SMESH_MeshEditor::Scale (TIDSortedElemSet & theElems, const bool theMakeGroups, SMESH_Mesh* theTargetMesh) { + MESSAGE("Scale"); myLastCreatedElems.Clear(); myLastCreatedNodes.Clear(); @@ -7057,6 +7062,7 @@ int SMESH_MeshEditor::SimplifyFace (const vector faceNode void SMESH_MeshEditor::MergeNodes (TListOfListOfNodes & theGroupsOfNodes) { + MESSAGE("MergeNodes"); myLastCreatedElems.Clear(); myLastCreatedNodes.Clear(); @@ -7171,6 +7177,7 @@ void SMESH_MeshEditor::MergeNodes (TListOfListOfNodes & theGroupsOfNodes) if (aShapeId) aMesh->SetMeshElementOnShape(newElem, aShapeId); } + MESSAGE("ChangeElementNodes MergeNodes Poly"); aMesh->ChangeElementNodes(elem, &polygons_nodes[inode], quantities[nbNew - 1]); } else { @@ -7594,7 +7601,34 @@ void SMESH_MeshEditor::MergeNodes (TListOfListOfNodes & theGroupsOfNodes) } else { // Change regular element or polygon - aMesh->ChangeElementNodes( elem, & uniqueNodes[0], nbUniqueNodes ); + 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); + } + if (newElem) + { + myLastCreatedElems.Append(newElem); + if ( aShapeId ) + aMesh->SetMeshElementOnShape( newElem, aShapeId ); + } + aMesh->RemoveElement(elem); } } else { @@ -8670,6 +8704,7 @@ void SMESH_MeshEditor::InsertNodesIntoLink(const SMDS_MeshElement* theFace, 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()) else { // theFace is quadratic @@ -8959,6 +8994,7 @@ int SMESH_MeshEditor::convertElemToQuadratic(SMESHDS_SubMesh * theSm, if( NewElem ) theSm->AddElement( NewElem ); } + GetMeshDS()->compactMesh(); return nbElem; } @@ -9086,6 +9122,7 @@ void SMESH_MeshEditor::ConvertToQuadratic(const bool theForce3d) aHelper.SetSubShape(0); // apply to the whole mesh aHelper.FixQuadraticElements(); } + GetMeshDS()->compactMesh(); } //======================================================================= @@ -9765,8 +9802,11 @@ SMESH_MeshEditor::SewSideElements (TIDSortedElemSet& theSide1, // elemIDsToRemove.push_back( e->GetID() ); // else if ( nbReplaced ) + { // TODO problem ChangeElementNodes : not the same number of nodes, not the same type + MESSAGE("ChangeElementNodes"); aMesh->ChangeElementNodes( e, & nodes[0], nbNodes ); + } } } @@ -10002,6 +10042,7 @@ bool SMESH_MeshEditor::doubleNodes( SMESHDS_Mesh* theMeshDS, const SMDS_MeshNode* >& theNodeNodeMap, const bool theIsDoubleElem ) { + MESSAGE("doubleNodes"); // iterate on through element and duplicate them (by nodes duplication) bool res = false; TIDSortedElemSet::const_iterator elemItr = theElems.begin(); @@ -10039,8 +10080,10 @@ bool SMESH_MeshEditor::doubleNodes( SMESHDS_Mesh* theMeshDS, if ( theIsDoubleElem ) myLastCreatedElems.Append( AddElement(newNodes, anElem->GetType(), anElem->IsPoly()) ); else + { + MESSAGE("ChangeElementNodes"); theMeshDS->ChangeElementNodes( anElem, &newNodes[ 0 ], anElem->NbNodes() ); - + } res = true; } return res; @@ -10060,6 +10103,7 @@ bool SMESH_MeshEditor::doubleNodes( SMESHDS_Mesh* theMeshDS, bool SMESH_MeshEditor::DoubleNodes( const std::list< int >& theListOfNodes, const std::list< int >& theListOfModifiedElems ) { + MESSAGE("DoubleNodes"); myLastCreatedElems.Clear(); myLastCreatedNodes.Clear(); @@ -10132,7 +10176,10 @@ bool SMESH_MeshEditor::DoubleNodes( const std::list< int >& theListOfNodes, const SMDS_MeshElement* anElem = anElemToNodesIter->first; vector aNodeArr = anElemToNodesIter->second; if ( anElem ) + { + MESSAGE("ChangeElementNodes"); aMeshDS->ChangeElementNodes( anElem, &aNodeArr[ 0 ], anElem->NbNodes() ); + } } return true; diff --git a/src/SMESHDS/SMESHDS_Mesh.cxx b/src/SMESHDS/SMESHDS_Mesh.cxx index 0afc862cd..95da59fcd 100644 --- a/src/SMESHDS/SMESHDS_Mesh.cxx +++ b/src/SMESHDS/SMESHDS_Mesh.cxx @@ -193,6 +193,7 @@ bool SMESHDS_Mesh::ChangeElementNodes(const SMDS_MeshElement * elem, const SMDS_MeshNode * nodes[], const int nbnodes) { + MESSAGE("SMESHDS_Mesh::ChangeElementNodes"); if ( ! SMDS_Mesh::ChangeElementNodes( elem, nodes, nbnodes )) return false; @@ -248,8 +249,10 @@ bool SMESHDS_Mesh::ChangePolyhedronNodes void SMESHDS_Mesh::Renumber (const bool isNodes, const int startID, const int deltaID) { - SMDS_Mesh::Renumber( isNodes, startID, deltaID ); - myScript->Renumber( isNodes, startID, deltaID ); + // TODO not possible yet to have node numbers not starting to O and continuous. + this->compactMesh(); +// SMDS_Mesh::Renumber( isNodes, startID, deltaID ); +// myScript->Renumber( isNodes, startID, deltaID ); } //======================================================================= @@ -1790,138 +1793,152 @@ SMDS_MeshVolume* SMESHDS_Mesh::AddVolumeWithID(const SMDS_MeshNode * n1, void SMESHDS_Mesh::compactMesh() { - int newNodeSize = 0; - int nbNodes = myNodes.size(); - int nbVtkNodes = myGrid->GetNumberOfPoints(); - MESSAGE("nbNodes=" << nbNodes << " nbVtkNodes=" << nbVtkNodes); - int nbNodeTemp = nbVtkNodes; - if (nbNodes > nbVtkNodes) nbNodeTemp = nbNodes; - vector idNodesOldToNew; - idNodesOldToNew.clear(); - idNodesOldToNew.resize(nbNodeTemp, -1); // all unused id will be -1 - - bool areNodesModified = ! myNodeIDFactory->isPoolIdEmpty(); - MESSAGE("------------------------------------------------- SMESHDS_Mesh::compactMesh " << areNodesModified); - if (areNodesModified) - { - for (int i=0; i= 0 - newNodeSize++; - } - } - } - else - { - for (int i=0; i nbVtkNodes) - newNodeSize = nbVtkNodes; // else 0 means nothing to change (no need to compact vtkPoints) - } - - int newCellSize = 0; - int nbCells = myCells.size(); - int nbVtkCells = myGrid->GetNumberOfCells(); - MESSAGE("nbCells=" << nbCells << " nbVtkCells=" << nbVtkCells); - int nbCellTemp = nbVtkCells; - if (nbCells > nbVtkCells) nbCellTemp = nbCells; - vector idCellsOldToNew; - idCellsOldToNew.clear(); - idCellsOldToNew.resize(nbCellTemp, -1); // all unused id will be -1 - - for (int i=0; i = 0 - newCellSize++; - } - } - myGrid->compactGrid(idNodesOldToNew, newNodeSize, idCellsOldToNew, newCellSize); - - // --- SMDS_MeshNode and myNodes (id in SMDS and in VTK are the same), myNodeIdFactory - - if (areNodesModified) - { - MESSAGE("-------------- modify myNodes"); - SetOfNodes newNodes; - newNodes.resize(newNodeSize); - - for (int i=0; i " << newid);; - myNodes[i]->setId(newid); - newNodes[newid] = myNodes[i]; - } - } - myNodes.swap(newNodes); - this->myNodeIDFactory->emptyPool(newNodeSize); - } - - // --- SMDS_MeshCell, myIDElements and myVtkIndex (myCells and myElementIdFactory are not compacted) - - int vtkIndexSize = myVtkIndex.size(); - int maxVtkId = 0; - for (int oldVtkId=0; oldVtkIdmyVtkIndex[oldVtkId]; - if (smdsId >=0) - { - int newVtkId = idCellsOldToNew[oldVtkId]; - if (newVtkId > maxVtkId) maxVtkId = newVtkId; - //MESSAGE("===========> smdsId newVtkId " << smdsId << " " << newVtkId); - myCells[smdsId]->setVtkId(newVtkId); - myIDElements[smdsId] = newVtkId; - myVtkIndex[newVtkId] = smdsId; - } - } - maxVtkId++; - MESSAGE("myCells.size()=" << myCells.size() << " myIDElements.size()=" << myIDElements.size() << " myVtkIndex.size()=" << myVtkIndex.size() ); - MESSAGE("maxVtkId=" << maxVtkId); - - SetOfCells newCells; - vector newSmdsToVtk; - vector newVtkToSmds; - - newCells.resize(maxVtkId,0); - newSmdsToVtk.resize(maxVtkId,-1); - newVtkToSmds.resize(maxVtkId,-1); - - int myCellsSize = myCells.size(); - int newSmdsId =0; - for (int i=0; igetVtkId(); - newSmdsToVtk[newSmdsId] = idvtk; - assert(idvtk < maxVtkId); - newVtkToSmds[idvtk] = newSmdsId; - myCells[i]->setId(newSmdsId); - newSmdsId++; - assert(newSmdsId <= maxVtkId); - } - } - - myCells.swap(newCells); - myIDElements.swap(newSmdsToVtk); - myVtkIndex.swap(newVtkToSmds); - MESSAGE("myCells.size()=" << myCells.size() << " myIDElements.size()=" << myIDElements.size() << " myVtkIndex.size()=" << myVtkIndex.size() ); - - // ---TODO: myNodes, myElements in submeshes - -// map::iterator it = myShapeIndexToSubMesh.begin(); -// for(; it != myShapeIndexToSubMesh.end(); ++it) + int newNodeSize = 0; + int nbNodes = myNodes.size(); + int nbVtkNodes = myGrid->GetNumberOfPoints(); + MESSAGE("nbNodes=" << nbNodes << " nbVtkNodes=" << nbVtkNodes); + int nbNodeTemp = nbVtkNodes; + if (nbNodes > nbVtkNodes) + nbNodeTemp = nbNodes; + vector idNodesOldToNew; + idNodesOldToNew.clear(); + idNodesOldToNew.resize(nbNodeTemp, -1); // all unused id will be -1 + + for (int i = 0; i < nbNodes; i++) + { + if (myNodes[i]) + { + idNodesOldToNew[i] = i; // all valid id are >= 0 + newNodeSize++; + } + } + bool areNodesModified = (newNodeSize < nbVtkNodes); + MESSAGE("------------------------------------------------- SMESHDS_Mesh::compactMesh " << areNodesModified); + +// bool areNodesModified = !myNodeIDFactory->isPoolIdEmpty(); +// MESSAGE("------------------------------------------------- SMESHDS_Mesh::compactMesh " << areNodesModified); +// if (areNodesModified) // { -// (*it).second->compactList(idNodesOldToNew, newNodeSize, idCellsOldToNew, newCellSize); +// for (int i = 0; i < nbNodes; i++) +// { +// if (myNodes[i]) +// { +// idNodesOldToNew[i] = i; // all valid id are >= 0 +// newNodeSize++; +// } +// } // } +// else +// { +// for (int i = 0; i < nbNodes; i++) +// idNodesOldToNew[i] = i; +// if (nbNodes > nbVtkNodes) +// newNodeSize = nbVtkNodes; // else 0 means nothing to change (no need to compact vtkPoints) +// } + + int newCellSize = 0; + int nbCells = myCells.size(); + int nbVtkCells = myGrid->GetNumberOfCells(); + MESSAGE("nbCells=" << nbCells << " nbVtkCells=" << nbVtkCells); + int nbCellTemp = nbVtkCells; + if (nbCells > nbVtkCells) + nbCellTemp = nbCells; + vector idCellsOldToNew; + idCellsOldToNew.clear(); + idCellsOldToNew.resize(nbCellTemp, -1); // all unused id will be -1 + + for (int i = 0; i < nbCells; i++) + { + if (myCells[i]) + { + idCellsOldToNew[i] = myVtkIndex[i]; // valid vtk indexes are > = 0 + newCellSize++; + } + } + myGrid->compactGrid(idNodesOldToNew, newNodeSize, idCellsOldToNew, newCellSize); + + // --- SMDS_MeshNode and myNodes (id in SMDS and in VTK are the same), myNodeIdFactory + + if (areNodesModified) + { + MESSAGE("-------------- modify myNodes"); + SetOfNodes newNodes; + newNodes.resize(newNodeSize); + + for (int i = 0; i < nbNodes; i++) + { + if (myNodes[i]) + { + int newid = idNodesOldToNew[i]; + //MESSAGE(i << " --> " << newid);; + myNodes[i]->setId(newid); + newNodes[newid] = myNodes[i]; + } + } + myNodes.swap(newNodes); + this->myNodeIDFactory->emptyPool(newNodeSize); + } + + // --- SMDS_MeshCell, myIDElements and myVtkIndex (myCells and myElementIdFactory are not compacted) + + int vtkIndexSize = myVtkIndex.size(); + int maxVtkId = 0; + for (int oldVtkId = 0; oldVtkId < vtkIndexSize; oldVtkId++) + { + int smdsId = this->myVtkIndex[oldVtkId]; + if (smdsId >= 0) + { + int newVtkId = idCellsOldToNew[oldVtkId]; + if (newVtkId > maxVtkId) + maxVtkId = newVtkId; + //MESSAGE("===========> smdsId newVtkId " << smdsId << " " << newVtkId); + myCells[smdsId]->setVtkId(newVtkId); + myIDElements[smdsId] = newVtkId; + myVtkIndex[newVtkId] = smdsId; + } + } + maxVtkId++; + MESSAGE("myCells.size()=" << myCells.size() << " myIDElements.size()=" << myIDElements.size() << " myVtkIndex.size()=" << myVtkIndex.size() ); + MESSAGE("maxVtkId=" << maxVtkId); + + SetOfCells newCells; + vector newSmdsToVtk; + vector newVtkToSmds; + + newCells.resize(maxVtkId, 0); + newSmdsToVtk.resize(maxVtkId, -1); + newVtkToSmds.resize(maxVtkId, -1); + + int myCellsSize = myCells.size(); + int newSmdsId = 0; + for (int i = 0; i < myCellsSize; i++) + { + if (myCells[i]) + { + //MESSAGE(newSmdsId << " " << i); + newCells[newSmdsId] = myCells[i]; + int idvtk = myCells[i]->getVtkId(); + newSmdsToVtk[newSmdsId] = idvtk; + assert(idvtk < maxVtkId); + newVtkToSmds[idvtk] = newSmdsId; + myCells[i]->setId(newSmdsId); + newSmdsId++; + assert(newSmdsId <= maxVtkId); + } + } + + myCells.swap(newCells); + myIDElements.swap(newSmdsToVtk); + myVtkIndex.swap(newVtkToSmds); + MESSAGE("myCells.size()=" << myCells.size() << " myIDElements.size()=" << myIDElements.size() << " myVtkIndex.size()=" << myVtkIndex.size() ); + + // ---TODO: myNodes, myElements in submeshes + + // map::iterator it = myShapeIndexToSubMesh.begin(); + // for(; it != myShapeIndexToSubMesh.end(); ++it) + // { + // (*it).second->compactList(idNodesOldToNew, newNodeSize, idCellsOldToNew, newCellSize); + // } } diff --git a/src/SMESHDS/SMESHDS_Mesh.hxx b/src/SMESHDS/SMESHDS_Mesh.hxx index 70af413ab..ef3351b32 100644 --- a/src/SMESHDS/SMESHDS_Mesh.hxx +++ b/src/SMESHDS/SMESHDS_Mesh.hxx @@ -442,7 +442,7 @@ public: bool IsGroupOfSubShapes (const TopoDS_Shape& aSubShape) const; - void compactMesh(); + virtual void compactMesh(); void BuildDownWardConnectivity(bool withEdges); ~SMESHDS_Mesh(); diff --git a/src/SMESH_SWIG/SMESH_AdvancedEditor.py b/src/SMESH_SWIG/SMESH_AdvancedEditor.py index 2e5ae0bfc..ae7ef4265 100644 --- a/src/SMESH_SWIG/SMESH_AdvancedEditor.py +++ b/src/SMESH_SWIG/SMESH_AdvancedEditor.py @@ -1,4 +1,4 @@ -# -*- coding: iso-8859-1 -*- +# -*- coding: utf-8 -*- # Copyright (C) 2007-2010 CEA/DEN, EDF R&D, OPEN CASCADE # # Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, @@ -25,6 +25,8 @@ import salome import smesh import math +salome.salome_init() + def GetNewNodes(mesh,Elems,OldNodes): """ Auxilary function, which return list of nodes from diff --git a/src/SMESH_SWIG/SMESH_mechanic_editor.py b/src/SMESH_SWIG/SMESH_mechanic_editor.py index 94c0719ff..85e12a3a7 100644 --- a/src/SMESH_SWIG/SMESH_mechanic_editor.py +++ b/src/SMESH_SWIG/SMESH_mechanic_editor.py @@ -1,4 +1,4 @@ -# -*- coding: iso-8859-1 -*- +# -*- coding: utf-8 -*- # Copyright (C) 2007-2010 CEA/DEN, EDF R&D, OPEN CASCADE # # Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, @@ -31,6 +31,7 @@ import salome import geompy import smesh +salome.salome_init() # ---------------------------- GEOM -------------------------------------- # ---- define contigous arcs and segment to define a closed wire @@ -192,7 +193,7 @@ print "Number of tetrahedrons: ", mesh.NbTetras() mesh.SplitQuadObject(submesh2, 1) #2 cutting of triangles of the group -FacesTriToQuad = [2381, 2382, 2383, 2384, 2385, 2386, 2387, 2388, 2389, 2390, 2391, 2392, 2393, 2394, 2395, 2396, 2397, 2398, 2399, 2400, 2401, 2402, 2403, 2404, 2405, 2406, 2407, 2408, 2409, 2410, 2411, 2412, 2413, 2414, 2415, 2416, 2417, 2418, 2419, 2420, 2421, 2422] +FacesTriToQuad = [ 2391, 2824, 2825, 2826, 2827, 2828, 2832, 2833, 2834, 2835, 2836, 2837, 2838, 2839, 2841, 2844, 2845, 2847, 2854, 2861, 2863, 2922, 2923, 2924, 2925, 2926, 2927, 2928, 2929, 2930, 2931, 2932, 2933, 2934, 2935, 2936, 2937, 2938, 2940, 2941, 2946, 2951, 2970, 2971, 2972, 2973, 2974, 2975, 2976, 2977, 2978, 2979, 2980, 2981, 2982, 2983, 2984, 2985 ] GroupTriToQuad = mesh.MakeGroupByIds("Group of faces (quad)", smesh.FACE, FacesTriToQuad) mesh.TriToQuadObject(GroupTriToQuad, None , 1.57)