- SMDS_Mesh::compactMesh();
-
- int newNodeSize = 0;
- int nbNodes = myNodes.size();
- int nbVtkNodes = myGrid->GetNumberOfPoints();
- int nbNodeTemp = Max( nbVtkNodes, nbNodes );
- vector<int> idNodesOldToNew(nbNodeTemp, -1); // all unused id will be -1
-
- for (int i = 0; i < nbNodes; i++)
- {
- if (myNodes[i])
- {
- int vtkid = myNodes[i]->getVtkId();
- idNodesOldToNew[vtkid] = i; // old vtkId --> old smdsId (valid smdsId are >= 0)
- newNodeSize++;
- }
- }
- bool areNodesModified = (newNodeSize != nbVtkNodes);
- areNodesModified = true;
-
- int newCellSize = 0;
- int nbCells = myCells.size();
- int nbVtkCells = myGrid->GetNumberOfCells();
- int nbCellTemp = Max( nbVtkCells, nbCells );
- vector<int> idCellsOldToNew(nbCellTemp, -1); // all unused id will be -1
-
- for (int i = 0; i < nbCells; i++)
- {
- if (myCells[i])
- {
- newCellSize++;
- }
- }
- if (areNodesModified)
- myGrid->compactGrid(idNodesOldToNew, newNodeSize, idCellsOldToNew, newCellSize);
- else
- myGrid->compactGrid(idNodesOldToNew, 0, idCellsOldToNew, newCellSize);
-
- int nbVtkPts = myGrid->GetNumberOfPoints();
- nbVtkCells = myGrid->GetNumberOfCells();
- if (nbVtkPts != newNodeSize)
- {
- MESSAGE("===> nbVtkPts != newNodeSize " << nbVtkPts << " " << newNodeSize);
- if (nbVtkPts > newNodeSize) newNodeSize = nbVtkPts; // several points with same SMDS Id
- }
- if (nbVtkCells != newCellSize)
- {
- MESSAGE("===> nbVtkCells != newCellSize " << nbVtkCells << " " << newCellSize);
- if (nbVtkCells > newCellSize) newCellSize = nbVtkCells; // several cells with same SMDS Id
- }
-
- // --- SMDS_MeshNode and myNodes, myNodeIdFactory
-
- if ( true )
- {
- SetOfNodes newNodes(newNodeSize+1,NULL); // 0 not used, SMDS numbers 1..n
- int newSmdsId = 0;
- for (int i = 0; i < nbNodes; i++)
- {
- if (myNodes[i])
- {
- newSmdsId++; // SMDS id starts from 1
- int oldVtkId = myNodes[i]->getVtkId();
- int newVtkId = idNodesOldToNew[oldVtkId];
- myNodes[i]->setVtkId(newVtkId);
- myNodes[i]->setId(newSmdsId);
- newNodes[newSmdsId] = myNodes[i];
- }
- }
- myNodes.swap(newNodes);
- this->myNodeIDFactory->emptyPool(newSmdsId); // newSmdsId = number of nodes
- }
-
- // --- SMDS_MeshCell, myCellIdVtkToSmds, myCellIdSmdsToVtk, myCells
-
- int vtkIndexSize = myCellIdVtkToSmds.size();
- for (int oldVtkId = 0; oldVtkId < vtkIndexSize; oldVtkId++)
- {
- int oldSmdsId = this->myCellIdVtkToSmds[oldVtkId];
- if (oldSmdsId > 0)
- {
- int newVtkId = idCellsOldToNew[oldVtkId];
- myCells[oldSmdsId]->setVtkId(newVtkId);
- }
- }
-
- SetOfCells newCells(newCellSize+1, NULL); // 0 not used, SMDS numbers 1..n
- vector<int> newVtkToSmds(newCellSize+1, -1);