From: prascle Date: Thu, 15 Apr 2010 15:52:18 +0000 (+0000) Subject: PR: debug compact vtkUnstructuredGrid in progress X-Git-Tag: smds_memimp_V5_1_3~2 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=7163ce5c50fdafdca1689d5aba073ff645e847a2;p=modules%2Fsmesh.git PR: debug compact vtkUnstructuredGrid in progress --- diff --git a/src/SMDS/SMDS_Mesh.cxx b/src/SMDS/SMDS_Mesh.cxx index c6f18287e..1f704a681 100644 --- a/src/SMDS/SMDS_Mesh.cxx +++ b/src/SMDS/SMDS_Mesh.cxx @@ -123,7 +123,7 @@ SMDS_Mesh::SMDS_Mesh() myElementIDFactory(new SMDS_MeshElementIDFactory()), myHasConstructionEdges(false), myHasConstructionFaces(false), myHasInverseElements(true), - myNodeMin(0), myNodeMax(0), myCellLinksSize(0), + myNodeMin(0), myNodeMax(0), myNodePool(0), myEdgePool(0), myFacePool(0), myVolumePool(0) { myMeshId = _meshList.size(); // --- index of the mesh to push back in the vector @@ -796,11 +796,11 @@ SMDS_MeshVolume* SMDS_Mesh::AddVolumeWithID(const SMDS_MeshNode * n1, vector nodeIds; nodeIds.clear(); nodeIds.push_back(n1->getId()); - nodeIds.push_back(n3->getId()); nodeIds.push_back(n2->getId()); + nodeIds.push_back(n3->getId()); nodeIds.push_back(n4->getId()); - nodeIds.push_back(n6->getId()); nodeIds.push_back(n5->getId()); + nodeIds.push_back(n6->getId()); SMDS_VtkVolume *volvtk = myVolumePool->getNew(); volvtk->init(nodeIds, this); @@ -1979,6 +1979,7 @@ const SMDS_MeshElement* SMDS_Mesh::FindElement(int IDelem) const if ((IDelem < 0) || IDelem >= myCells.size()) { MESSAGE("----------------------------------- bad IDelem " << IDelem << " " << myCells.size()); + assert(0); return 0; } return myCells[IDelem]; @@ -2687,7 +2688,7 @@ void SMDS_Mesh::RemoveElement(const SMDS_MeshElement * elem, list& removedNodes, bool removenodes) { - MESSAGE("SMDS_Mesh::RemoveElement " << elem->GetID() << " " << removenodes); + //MESSAGE("SMDS_Mesh::RemoveElement " << elem->GetID() << " " << removenodes); // get finite elements built on elem set * s1; if (elem->GetType() == SMDSAbs_0DElement || @@ -3530,24 +3531,24 @@ SMDS_MeshVolume* SMDS_Mesh::AddVolumeWithID(const SMDS_MeshNode * n1, vector nodeIds; nodeIds.clear(); nodeIds.push_back(n1->getId()); - nodeIds.push_back(n3->getId()); nodeIds.push_back(n2->getId()); + nodeIds.push_back(n3->getId()); nodeIds.push_back(n4->getId()); - nodeIds.push_back(n6->getId()); nodeIds.push_back(n5->getId()); + nodeIds.push_back(n6->getId()); - nodeIds.push_back(n31->getId()); - nodeIds.push_back(n23->getId()); nodeIds.push_back(n12->getId()); + nodeIds.push_back(n23->getId()); + nodeIds.push_back(n31->getId()); - nodeIds.push_back(n64->getId()); - nodeIds.push_back(n56->getId()); nodeIds.push_back(n45->getId()); + nodeIds.push_back(n56->getId()); + nodeIds.push_back(n64->getId()); nodeIds.push_back(n14->getId()); - nodeIds.push_back(n36->getId()); nodeIds.push_back(n25->getId()); + nodeIds.push_back(n36->getId()); SMDS_VtkVolume *volvtk = myVolumePool->getNew(); volvtk->init(nodeIds, this); @@ -3747,14 +3748,14 @@ void SMDS_Mesh::adjustStructure() void SMDS_Mesh::dumpGrid(string ficdump) { MESSAGE("SMDS_Mesh::dumpGrid " << ficdump); - vtkUnstructuredGridWriter* aWriter = vtkUnstructuredGridWriter::New(); - aWriter->SetFileName(ficdump.c_str()); - aWriter->SetInput(myGrid); - if(myGrid->GetNumberOfCells()) - { - aWriter->Write(); - } - aWriter->Delete(); +// vtkUnstructuredGridWriter* aWriter = vtkUnstructuredGridWriter::New(); +// aWriter->SetFileName(ficdump.c_str()); +// aWriter->SetInput(myGrid); +// if(myGrid->GetNumberOfCells()) +// { +// aWriter->Write(); +// } +// aWriter->Delete(); ficdump = ficdump + "_connectivity"; ofstream ficcon(ficdump.c_str(), ios::out); int nbPoints = myGrid->GetNumberOfPoints(); @@ -3767,6 +3768,8 @@ void SMDS_Mesh::dumpGrid(string ficdump) ficcon << "-------------------------------- cells " << nbCells << endl; for (int i=0; iGetCell(i)); +// MESSAGE(" " << myGrid->GetCell(i)->GetCellType()); ficcon << i << " - " << myGrid->GetCell(i)->GetCellType() << " -"; int nbptcell = myGrid->GetCell(i)->GetNumberOfPoints(); vtkIdList *listid = myGrid->GetCell(i)->GetPointIds(); diff --git a/src/SMDS/SMDS_Mesh.hxx b/src/SMDS/SMDS_Mesh.hxx index f32a366fe..357ee8eeb 100644 --- a/src/SMDS/SMDS_Mesh.hxx +++ b/src/SMDS/SMDS_Mesh.hxx @@ -43,6 +43,7 @@ #include "SMDS_VtkFace.hxx" #include "SMDS_VtkVolume.hxx" #include "ObjectPool.hxx" +#include "SMDS_UnstructuredGrid.hxx" #include #include @@ -53,8 +54,6 @@ #include "Utils_SALOME_Exception.hxx" #define MYASSERT(val) if (!(val)) throw SALOME_Exception(LOCALIZED("assertion not verified")); -class vtkUnstructuredGrid; - class SMDS_EXPORT SMDS_Mesh:public SMDS_MeshObject{ public: friend class SMDS_MeshElementIDFactory; @@ -570,12 +569,10 @@ public: void incrementCellsCapacity(int nbCells); void adjustStructure(); void dumpGrid(string ficdump="dumpGrid"); - - int myCellLinksSize; static int chunkSize; -private: +protected: SMDS_Mesh(SMDS_Mesh * parent); SMDS_MeshFace * createTriangle(const SMDS_MeshNode * node1, @@ -617,7 +614,7 @@ private: int myMeshId; //! actual nodes coordinates, cells definition and reverse connectivity are stored in a vtkUnstructuredGrid - vtkUnstructuredGrid* myGrid; + SMDS_UnstructuredGrid* myGrid; //! Small objects like SMDS_MeshNode are allocated by chunks to limit memory costs of new ObjectPool* myNodePool; diff --git a/src/SMDS/SMDS_MeshElement.hxx b/src/SMDS/SMDS_MeshElement.hxx index 9fea64cea..939eabd5c 100644 --- a/src/SMDS/SMDS_MeshElement.hxx +++ b/src/SMDS/SMDS_MeshElement.hxx @@ -81,6 +81,7 @@ public: friend SMDS_EXPORT std::ostream & operator <<(std::ostream & OS, const SMDS_MeshElement *); friend SMDS_EXPORT bool SMDS_MeshElementIDFactory::BindID(int ID,SMDS_MeshElement* elem); friend class SMDS_Mesh; + friend class SMESHDS_Mesh; // =========================== // Access to nodes by index @@ -134,6 +135,7 @@ public: inline void setIdInShape(int id) { myIdInShape = id; }; protected: + inline void setId(int id) {myID = id; }; SMDS_MeshElement(int ID=-1); SMDS_MeshElement(int id, ShortType meshId, ShortType shapeId=-1); virtual void Print(std::ostream & OS) const; diff --git a/src/SMDS/SMDS_MeshIDFactory.cxx b/src/SMDS/SMDS_MeshIDFactory.cxx index 7465a1a8d..8bde46aa5 100644 --- a/src/SMDS/SMDS_MeshIDFactory.cxx +++ b/src/SMDS/SMDS_MeshIDFactory.cxx @@ -90,16 +90,23 @@ void SMDS_MeshIDFactory::ReleaseID(const int ID) void SMDS_MeshIDFactory::Clear() { - myMaxID = -1; - myPoolOfID.clear(); + myMaxID = -1; + myPoolOfID.clear(); } - void SMDS_MeshIDFactory::SetMesh(SMDS_Mesh *mesh) - { - myMesh = mesh; - } +void SMDS_MeshIDFactory::SetMesh(SMDS_Mesh *mesh) +{ + myMesh = mesh; +} - SMDS_Mesh* SMDS_MeshIDFactory::GetMesh() - { - return myMesh; - } +SMDS_Mesh* SMDS_MeshIDFactory::GetMesh() +{ + return myMesh; +} + +void SMDS_MeshIDFactory::emptyPool(int maxId) +{ + MESSAGE("SMDS_MeshIDFactory::emptyPool " << myMaxID << " --> " << maxId-1); + myMaxID = maxId-1; + myPoolOfID.clear(); +} diff --git a/src/SMDS/SMDS_MeshIDFactory.hxx b/src/SMDS/SMDS_MeshIDFactory.hxx index 09ed074b9..9e433c951 100644 --- a/src/SMDS/SMDS_MeshIDFactory.hxx +++ b/src/SMDS/SMDS_MeshIDFactory.hxx @@ -42,6 +42,8 @@ public: void SetMesh(SMDS_Mesh *mesh); SMDS_Mesh* GetMesh(); + inline bool isPoolIdEmpty() { return myPoolOfID.empty(); }; + void emptyPool(int maxId); protected: SMDS_MeshIDFactory(); int myMaxID; diff --git a/src/SMDS/SMDS_MeshNode.cxx b/src/SMDS/SMDS_MeshNode.cxx index 888d8967b..f1c100046 100644 --- a/src/SMDS/SMDS_MeshNode.cxx +++ b/src/SMDS/SMDS_MeshNode.cxx @@ -71,42 +71,10 @@ void SMDS_MeshNode::init(int id, int meshId, int shapeId, double x, double y, do SMDS_Mesh* mesh = SMDS_Mesh::_meshList[myMeshId]; vtkUnstructuredGrid * grid = mesh->getGrid(); vtkPoints *points = grid->GetPoints(); - //int nbp = points->GetNumberOfPoints(); points->InsertPoint(myID, x, y, z); - if (myID >= mesh->myCellLinksSize) - { - //points->SetNumberOfPoints(myID+SMDS_Mesh::chunkSize); - vtkCellLinks *cellLinks = grid->GetCellLinks(); - -// int imax = cellLinks->Size; -// for (int i =0; iGetLink(i); -// int ncells = ilink.ncells; -// int *cells = ilink.cells; -// MESSAGE("NODE " << i << " " << cellLinks << " " << cells << " " << ncells); -// for (int j=0; j< ncells; j++) -// MESSAGE(" " << j << " " << cells[j]); -// } - - cellLinks->Resize(myID+SMDS_Mesh::chunkSize); - -// cellLinks = grid->GetCellLinks(); -// imax = cellLinks->Size; -// for (int i =0; iGetLink(i); -// int ncells = ilink.ncells; -// int *cells = ilink.cells; -// MESSAGE("NODE " << i << " " << cellLinks << " " << cells << " " << ncells); -// for (int j=0; j< ncells; j++) -// MESSAGE(" " << j << " " << cells[j]); -// } - - mesh->myCellLinksSize = cellLinks->Size; - //MESSAGE(" -------------------------------------- resize CellLinks " << myID << " --> " << mesh->myCellLinksSize); - } - //setXYZ(x, y, z); + vtkCellLinks *cellLinks = grid->GetCellLinks(); + if (myID >=cellLinks->Size) + cellLinks->Resize(myID+SMDS_Mesh::chunkSize); } SMDS_MeshNode::~SMDS_MeshNode() diff --git a/src/SMDS/SMDS_UnstructuredGrid.cxx b/src/SMDS/SMDS_UnstructuredGrid.cxx index 1c219a27d..7fe994f21 100644 --- a/src/SMDS/SMDS_UnstructuredGrid.cxx +++ b/src/SMDS/SMDS_UnstructuredGrid.cxx @@ -3,75 +3,18 @@ #include "SMDS_UnstructuredGrid.hxx" #include "utilities.h" -using namespace std; +#include +#include +#include + +#include -//vtkCellLinks::Link* SMDS_CellLinks::AdjustSize(vtkIdType sz) -//{ -// vtkIdType i; -// vtkCellLinks::Link *newArray; -// vtkIdType newSize = sz; -// vtkCellLinks::Link linkInit = {0,NULL}; -// -// newArray = new vtkCellLinks::Link[newSize]; -// -// for (i=0; iSize; i++) -// { -// newArray[i] = this->Array[i]; -// } -// -// for (i=this->Size; i < newSize ; i++) -// { -// newArray[i] = linkInit; -// } -// -// this->Size = newSize; -// delete [] this->Array; -// this->Array = newArray; -// -// return this->Array; -//} -// -//SMDS_CellLinks* SMDS_CellLinks::New() -//{ -// return new SMDS_CellLinks(); -//} -// -//SMDS_CellLinks::SMDS_CellLinks() : vtkCellLinks() -//{ -//} -// -//SMDS_CellLinks::~SMDS_CellLinks() -//{ -//} -// -// -///*! initialize an SMDS_CellLinks instance instead of a vtkCellLinks instance -// * -// */ -//void SMDS_UnstructuredGrid::BuildLinks() -//{ -// // Remove the old links if they are already built -// if (this->Links) -// { -// this->Links->UnRegister(this); -// } -// -// this->Links = SMDS_CellLinks::New(); -// this->Links->Allocate(this->GetNumberOfPoints()); -// this->Links->Register(this); -// this->Links->BuildLinks(this, this->Connectivity); -// this->Links->Delete(); -//} -// -//SMDS_CellLinks* SMDS_UnstructuredGrid::GetCellLinks() -//{ -// return static_cast(this->Links); -//} +using namespace std; SMDS_UnstructuredGrid* SMDS_UnstructuredGrid::New() { MESSAGE("SMDS_UnstructuredGrid::New"); - return new SMDS_UnstructuredGrid(); + return new SMDS_UnstructuredGrid(); } SMDS_UnstructuredGrid::SMDS_UnstructuredGrid() : vtkUnstructuredGrid() @@ -95,3 +38,189 @@ void SMDS_UnstructuredGrid::UpdateInformation() MESSAGE("SMDS_UnstructuredGrid::UpdateInformation"); return vtkUnstructuredGrid::UpdateInformation(); } + +void SMDS_UnstructuredGrid::compactGrid(std::vector& idNodesOldToNew, int newNodeSize, + std::vector& idCellsOldToNew, int newCellSize) +{ + MESSAGE("------------------------- SMDS_UnstructuredGrid::compactGrid " << newNodeSize << " " << newCellSize); + + int startHole = 0; + int endHole = 0; + int startBloc = 0; + int endBloc = 0; + int alreadyCopied = 0; + typedef enum {lookHoleStart, lookHoleEnd, lookBlocEnd} enumState; + enumState compactState = lookHoleStart; + + // --- if newNodeSize, create a new compacted vtkPoints + + vtkPoints *newPoints = 0; + if (newNodeSize) + { + MESSAGE("-------------- compactGrid, newNodeSize"); + newPoints = vtkPoints::New(); + newPoints->Initialize(); + newPoints->Allocate(newNodeSize); + newPoints->SetNumberOfPoints(newNodeSize); + int oldNodeSize = idNodesOldToNew.size(); + + for (int i=0; i< oldNodeSize; i++) + { + switch(compactState) + { + case lookHoleStart: + if (idNodesOldToNew[i] < 0) + { + startHole = i; + compactState = lookHoleEnd; + } + break; + case lookHoleEnd: + if (idNodesOldToNew[i] >= 0) + { + endHole = i; + startBloc = i; + compactState = lookBlocEnd; + } + break; + case lookBlocEnd: + if (idNodesOldToNew[i] < 0) endBloc = i; // see nbPoints below + else if (i == (oldNodeSize-1)) endBloc = i+1; + if (endBloc) + { + MESSAGE("-------------- newNodeSize, endbloc"); + void *target = newPoints->GetVoidPointer(3*alreadyCopied); + void *source = this->Points->GetVoidPointer(3*startBloc); + int nbPoints = endBloc - startBloc; + memcpy(target, source, 3*sizeof(float)*nbPoints); + for (int j=startBloc; jGetVoidPointer(0); + void *source = this->Points->GetVoidPointer(0); + int nbPoints = newNodeSize; + memcpy(target, source, 3*sizeof(float)*nbPoints); + } + } + + // --- create new compacted Connectivity, Locations and Types + + int oldCellSize = this->Types->GetNumberOfTuples(); + + vtkCellArray *newConnectivity = vtkCellArray::New(); + newConnectivity->Initialize(); + int oldCellDataSize = this->Connectivity->GetData()->GetSize(); + newConnectivity->Allocate(oldCellDataSize); + MESSAGE("oldCellSize="<< oldCellSize << " oldCellDataSize=" << oldCellDataSize); + + vtkUnsignedCharArray *newTypes = vtkUnsignedCharArray::New(); + newTypes->Initialize(); + //newTypes->Allocate(oldCellSize); + newTypes->SetNumberOfValues(newCellSize); + + vtkIdTypeArray *newLocations = vtkIdTypeArray::New(); + newLocations->Initialize(); + //newLocations->Allocate(oldCellSize); + newLocations->SetNumberOfValues(newCellSize); + + startHole = 0; + endHole = 0; + startBloc = 0; + endBloc = 0; + alreadyCopied = 0; + compactState = lookHoleStart; + + vtkIdType tmpid[50]; + vtkIdType *pointsCell =&tmpid[0]; // --- points id to fill a new cell + + for (int i=0; iTypes->GetValue(i) == VTK_EMPTY_CELL) + { + startHole = i; + compactState = lookHoleEnd; + } + break; + case lookHoleEnd: + if (this->Types->GetValue(i) != VTK_EMPTY_CELL) + { + endHole = i; + startBloc = i; + compactState = lookBlocEnd; + } + break; + case lookBlocEnd: + if (this->Types->GetValue(i) == VTK_EMPTY_CELL) endBloc =i; + else if (i == (oldCellSize-1)) endBloc = i+1; + if (endBloc) + { + MESSAGE(" -------- newCellSize, endBloc"); + for (int j=startBloc; jSetValue(alreadyCopied, this->Types->GetValue(j)); + idCellsOldToNew[j] = alreadyCopied; + int oldLoc = this->Locations->GetValue(j); + int nbpts; + this->Connectivity->GetCell(oldLoc, nbpts, pointsCell); + for (int l=0; lInsertNextCell(nbpts, pointsCell); + int newLoc = newConnectivity->GetInsertLocation(nbpts); + newLocations->SetValue(alreadyCopied, newLoc); + alreadyCopied++; + } + } + break; + } + } + if (!alreadyCopied) // no hole, but shorter + { + MESSAGE(" -------- newCellSize, shorter"); + for (int j=0; jSetValue(alreadyCopied, this->Types->GetValue(j)); + idCellsOldToNew[j] = alreadyCopied; + int oldLoc = this->Locations->GetValue(j); + int nbpts; + this->Connectivity->GetCell(oldLoc, nbpts, pointsCell); + //MESSAGE(j << " " << alreadyCopied << " " << (int)this->Types->GetValue(j) << " " << oldLoc << " " << nbpts ); + for (int l=0; lInsertNextCell(nbpts, pointsCell); + int newLoc = newConnectivity->GetInsertLocation(nbpts); + //MESSAGE(newcnt << " " << newLoc); + newLocations->SetValue(alreadyCopied, newLoc); + alreadyCopied++; + } + } + + newConnectivity->Squeeze(); + //newTypes->Squeeze(); + //newLocations->Squeeze(); + + if (newNodeSize) + { + MESSAGE("------- newNodeSize, setPoints"); + this->SetPoints(newPoints); + } + this->SetCells(newTypes, newLocations, newConnectivity); + this->BuildLinks(); +} diff --git a/src/SMDS/SMDS_UnstructuredGrid.hxx b/src/SMDS/SMDS_UnstructuredGrid.hxx index ce4fed74c..e2bc01d0d 100644 --- a/src/SMDS/SMDS_UnstructuredGrid.hxx +++ b/src/SMDS/SMDS_UnstructuredGrid.hxx @@ -8,39 +8,24 @@ #ifndef _SMDS_UNSTRUCTUREDGRID_HXX #define _SMDS_UNSTRUCTUREDGRID_HXX +#include + #include -//#include - -//class SMDS_CellLinks: public vtkCellLinks -//{ -//public: -// Link *AdjustSize(vtkIdType sz); -// -// //virtual void Delete(); -// static SMDS_CellLinks* New(); -//protected: -// SMDS_CellLinks(); -// ~SMDS_CellLinks(); -//}; class SMDS_UnstructuredGrid: public vtkUnstructuredGrid { public: -// void BuildLinks(); // initialise un SMDS_CellLinks; -// SMDS_CellLinks* GetCellLinks(); -// -// vtkIdType GetCellArraySize() { return (this->Connectivity ? this->Connectivity->GetSize() : 0); }; + void compactGrid(std::vector& idNodesOldToNew, int newNodeSize, + std::vector& idCellsOldToNew, int newCellSize); virtual unsigned long GetMTime(); virtual void UpdateInformation(); - //virtual void Delete(); static SMDS_UnstructuredGrid* New(); protected: SMDS_UnstructuredGrid(); ~SMDS_UnstructuredGrid(); }; - #endif /* _SMDS_UNSTRUCTUREDGRID_HXX */ diff --git a/src/SMDS/SMDS_VtkCellIterator.cxx b/src/SMDS/SMDS_VtkCellIterator.cxx index 8d6fe266f..1d0138f1b 100644 --- a/src/SMDS/SMDS_VtkCellIterator.cxx +++ b/src/SMDS/SMDS_VtkCellIterator.cxx @@ -22,8 +22,8 @@ SMDS_VtkCellIterator::SMDS_VtkCellIterator(SMDS_Mesh* mesh, int vtkCellId, SMDSA } case SMDSEntity_Penta: { - this->exchange(1, 2); - this->exchange(4, 5); + //this->exchange(1, 2); + //this->exchange(4, 5); break; } case SMDSEntity_Hexa: @@ -49,11 +49,11 @@ SMDS_VtkCellIterator::SMDS_VtkCellIterator(SMDS_Mesh* mesh, int vtkCellId, SMDSA } case SMDSEntity_Quad_Penta: { - this->exchange(1, 2); - this->exchange(4, 5); - this->exchange(6, 8); - this->exchange(9, 11); - this->exchange(13, 14); + //this->exchange(1, 2); + //this->exchange(4, 5); + //this->exchange(6, 8); + //this->exchange(9, 11); + //this->exchange(13, 14); break; } case SMDSEntity_Quad_Hexa: diff --git a/src/SMESH/SMESH_Gen.cxx b/src/SMESH/SMESH_Gen.cxx index 0cbac04e8..a86d65b35 100644 --- a/src/SMESH/SMESH_Gen.cxx +++ b/src/SMESH/SMESH_Gen.cxx @@ -296,6 +296,8 @@ bool SMESH_Gen::Compute(SMESH_Mesh & aMesh, SMESHDS_Mesh *myMesh = aMesh.GetMeshDS(); myMesh->adjustStructure(); + myMesh->compactMesh(); + //myMesh->adjustStructure(); list listind = myMesh->SubMeshIndices(); list::iterator it = listind.begin(); int total = 0; @@ -304,9 +306,9 @@ bool SMESH_Gen::Compute(SMESH_Mesh & aMesh, ::SMESHDS_SubMesh *subMesh = myMesh->MeshElements(*it); total += subMesh->getSize(); } - cerr << "total elements and nodes in submesh sets:" << total << endl; - cerr << "Number of node objects " << SMDS_MeshNode::nbNodes << endl; - cerr << "Number of cell objects " << SMDS_MeshCell::nbCells << endl; + MESSAGE("total elements and nodes in submesh sets:" << total); + MESSAGE("Number of node objects " << SMDS_MeshNode::nbNodes); + MESSAGE("Number of cell objects " << SMDS_MeshCell::nbCells); //myMesh->dumpGrid(); return ret; } diff --git a/src/SMESHDS/SMESHDS_Mesh.cxx b/src/SMESHDS/SMESHDS_Mesh.cxx index 34118b829..d3bcea07b 100644 --- a/src/SMESHDS/SMESHDS_Mesh.cxx +++ b/src/SMESHDS/SMESHDS_Mesh.cxx @@ -1775,4 +1775,92 @@ SMDS_MeshVolume* SMESHDS_Mesh::AddVolumeWithID(const SMDS_MeshNode * n1, ID); } +void SMESHDS_Mesh::compactMesh() +{ + int newNodeSize = 0; + int nbNodes = myNodes.size(); + vector idNodesOldToNew; + idNodesOldToNew.clear(); + idNodesOldToNew.resize(nbNodes, -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 idCellsOldToNew; + idCellsOldToNew.clear(); + idCellsOldToNew.resize(nbCells, -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"); + for (int i=0; i " << newid); + myNodes[i]->setId(newid); + ASSERT(!myNodes[newid]); + myNodes[newid] = myNodes[i]; + } + } + } + this->myNodeIDFactory->emptyPool(newNodeSize); + } + + // --- SMDS_MeshCell, myIDElements and myVtkIndex (myCells and myElementIdFactory are not compacted) + + for (int oldVtkId=0; oldVtkIdmyVtkIndex[oldVtkId]; + if (smdsId >=0) + { + int newVtkId = idCellsOldToNew[oldVtkId]; + myCells[smdsId]->setVtkId(newVtkId); + myIDElements[smdsId] = newVtkId; + myVtkIndex[newVtkId] = smdsId; + } + } + + // ---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 116deb607..fa8d97d20 100644 --- a/src/SMESHDS/SMESHDS_Mesh.hxx +++ b/src/SMESHDS/SMESHDS_Mesh.hxx @@ -438,6 +438,8 @@ public: bool IsGroupOfSubShapes (const TopoDS_Shape& aSubShape) const; + void compactMesh(); + ~SMESHDS_Mesh(); private: diff --git a/src/SMESHDS/SMESHDS_SubMesh.cxx b/src/SMESHDS/SMESHDS_SubMesh.cxx index f06398de1..02141893d 100644 --- a/src/SMESHDS/SMESHDS_SubMesh.cxx +++ b/src/SMESHDS/SMESHDS_SubMesh.cxx @@ -412,8 +412,12 @@ int SMESHDS_SubMesh::getSize() { int c = NbNodes(); int d = NbElements(); - cerr << "SMESHDS_SubMesh::NbNodes " << c << endl; - cerr << "SMESHDS_SubMesh::NbElements " << d << endl; + //cerr << "SMESHDS_SubMesh::NbNodes " << c << endl; + //cerr << "SMESHDS_SubMesh::NbElements " << d << endl; return c+d; } +void SMESHDS_SubMesh::compactList() +{ + // todo : compact vector of nodes and elements +} diff --git a/src/SMESHDS/SMESHDS_SubMesh.hxx b/src/SMESHDS/SMESHDS_SubMesh.hxx index ca5e3098d..84b93d62d 100644 --- a/src/SMESHDS/SMESHDS_SubMesh.hxx +++ b/src/SMESHDS/SMESHDS_SubMesh.hxx @@ -66,6 +66,7 @@ class SMESHDS_EXPORT SMESHDS_SubMesh // clear the contents void Clear(); int getSize(); + void compactList(); private: