delete node positions at node removal

This commit is contained in:
eap 2011-01-18 10:47:49 +00:00
parent 0c1947cfe5
commit 6e58f2fb40
2 changed files with 43 additions and 37 deletions

View File

@ -223,10 +223,6 @@ SMDS_MeshNode * SMDS_Mesh::AddNodeWithID(double x, double y, double z, int ID)
SMDS_MeshNode * node = myNodePool->getNew(); SMDS_MeshNode * node = myNodePool->getNew();
node->init(ID, myMeshId, 0, x, y, z); node->init(ID, myMeshId, 0, x, y, z);
//rnv: Set SMDS_SpacePosition for node if need
if( node->GetPosition()->GetTypeOfPosition() != SMDS_TOP_3DSPACE)
node->SetPosition(SMDS_SpacePosition::originSpacePosition());
if (ID >= myNodes.size()) if (ID >= myNodes.size())
{ {
myNodes.resize(ID+SMDS_Mesh::chunkSize, 0); myNodes.resize(ID+SMDS_Mesh::chunkSize, 0);
@ -2317,9 +2313,9 @@ void SMDS_Mesh::DebugStats() const
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
int SMDS_Mesh::NbNodes() const int SMDS_Mesh::NbNodes() const
{ {
//MESSAGE(myGrid->GetNumberOfPoints()); //MESSAGE(myGrid->GetNumberOfPoints());
//MESSAGE(myInfo.NbNodes()); //MESSAGE(myInfo.NbNodes());
//MESSAGE(myNodeMax); //MESSAGE(myNodeMax);
return myInfo.NbNodes(); return myInfo.NbNodes();
} }
@ -2395,6 +2391,7 @@ SMDS_Mesh::~SMDS_Mesh()
while (itn->more()) while (itn->more())
{ {
const SMDS_MeshNode *node = itn->next(); const SMDS_MeshNode *node = itn->next();
((SMDS_MeshNode*)node)->SetPosition(SMDS_SpacePosition::originSpacePosition());
myNodeIDFactory->ReleaseID(node->GetID(), node->getVtkId()); myNodeIDFactory->ReleaseID(node->GetID(), node->getVtkId());
} }
} }
@ -2493,6 +2490,7 @@ void SMDS_Mesh::Clear()
while (itn->more()) while (itn->more())
{ {
SMDS_MeshNode *node = (SMDS_MeshNode*)(itn->next()); SMDS_MeshNode *node = (SMDS_MeshNode*)(itn->next());
node->SetPosition(SMDS_SpacePosition::originSpacePosition());
myNodePool->destroy(node); myNodePool->destroy(node);
} }
myNodes.clear(); myNodes.clear();
@ -3129,7 +3127,10 @@ void SMDS_Mesh::RemoveElement(const SMDS_MeshElement * elem,
myNodeIDFactory->ReleaseID((*it)->GetID(), (*it)->getVtkId()); myNodeIDFactory->ReleaseID((*it)->GetID(), (*it)->getVtkId());
removedNodes.push_back((*it)); removedNodes.push_back((*it));
if (const SMDS_MeshNode* vtkElem = dynamic_cast<const SMDS_MeshNode*>(*it)) if (const SMDS_MeshNode* vtkElem = dynamic_cast<const SMDS_MeshNode*>(*it))
{
((SMDS_MeshNode*)vtkElem)->SetPosition(SMDS_SpacePosition::originSpacePosition());
myNodePool->destroy((SMDS_MeshNode*) vtkElem); myNodePool->destroy((SMDS_MeshNode*) vtkElem);
}
else else
delete (*it); delete (*it);
it++; it++;
@ -3159,6 +3160,7 @@ void SMDS_Mesh::RemoveFreeElement(const SMDS_MeshElement * elem)
if (!itFe->more()) { // free node if (!itFe->more()) { // free node
myNodes[elemId] = 0; myNodes[elemId] = 0;
myInfo.myNbNodes--; myInfo.myNbNodes--;
((SMDS_MeshNode*) n)->SetPosition(SMDS_SpacePosition::originSpacePosition());
myNodePool->destroy(static_cast<SMDS_MeshNode*>(todest)); myNodePool->destroy(static_cast<SMDS_MeshNode*>(todest));
myNodeIDFactory->ReleaseID(elemId, vtkId); myNodeIDFactory->ReleaseID(elemId, vtkId);
} }
@ -3408,8 +3410,8 @@ SMDS_MeshEdge* SMDS_Mesh::AddEdgeWithID(const SMDS_MeshNode * n1,
myInfo.myNbQuadEdges++; myInfo.myNbQuadEdges++;
// if (!registerElement(ID, edge)) { // if (!registerElement(ID, edge)) {
// RemoveElement(edge, false); // RemoveElement(edge, false);
// edge = NULL; // edge = NULL;
// } // }
return edge; return edge;
@ -3553,7 +3555,7 @@ SMDS_MeshFace* SMDS_Mesh::AddFaceWithID(const SMDS_MeshNode * n1,
if ( !n1 || !n2 || !n3 || !n4 || !n12 || !n23 || !n34 || !n41) return 0; if ( !n1 || !n2 || !n3 || !n4 || !n12 || !n23 || !n34 || !n41) return 0;
if(hasConstructionEdges()) { if(hasConstructionEdges()) {
// creation quadratic edges - not implemented // creation quadratic edges - not implemented
return 0; return 0;
} }
else else
{ {
@ -4090,8 +4092,8 @@ void SMDS_Mesh::updateNodeMinMax()
myNodeMin = 0; myNodeMin = 0;
if (myNodes.size() == 0) if (myNodes.size() == 0)
{ {
myNodeMax=0; myNodeMax=0;
return; return;
} }
while (!myNodes[myNodeMin] && (myNodeMin<myNodes.size())) while (!myNodes[myNodeMin] && (myNodeMin<myNodes.size()))
myNodeMin++; myNodeMin++;
@ -4127,7 +4129,7 @@ void SMDS_Mesh::adjustStructure()
void SMDS_Mesh::dumpGrid(string ficdump) void SMDS_Mesh::dumpGrid(string ficdump)
{ {
MESSAGE("SMDS_Mesh::dumpGrid " << ficdump); MESSAGE("SMDS_Mesh::dumpGrid " << ficdump);
// vtkUnstructuredGridWriter* aWriter = vtkUnstructuredGridWriter::New(); // vtkUnstructuredGridWriter* aWriter = vtkUnstructuredGridWriter::New();
// aWriter->SetFileName(ficdump.c_str()); // aWriter->SetFileName(ficdump.c_str());
// aWriter->SetInput(myGrid); // aWriter->SetInput(myGrid);
@ -4142,35 +4144,35 @@ void SMDS_Mesh::dumpGrid(string ficdump)
ficcon << "-------------------------------- points " << nbPoints << endl; ficcon << "-------------------------------- points " << nbPoints << endl;
for (int i=0; i<nbPoints; i++) for (int i=0; i<nbPoints; i++)
{ {
ficcon << i << " " << *(myGrid->GetPoint(i)) << " " << *(myGrid->GetPoint(i)+1) << " " << " " << *(myGrid->GetPoint(i)+2) << endl; ficcon << i << " " << *(myGrid->GetPoint(i)) << " " << *(myGrid->GetPoint(i)+1) << " " << " " << *(myGrid->GetPoint(i)+2) << endl;
} }
int nbCells = myGrid->GetNumberOfCells(); int nbCells = myGrid->GetNumberOfCells();
ficcon << "-------------------------------- cells " << nbCells << endl; ficcon << "-------------------------------- cells " << nbCells << endl;
for (int i=0; i<nbCells; i++) for (int i=0; i<nbCells; i++)
{ {
// MESSAGE(i << " " << myGrid->GetCell(i)); // MESSAGE(i << " " << myGrid->GetCell(i));
// MESSAGE(" " << myGrid->GetCell(i)->GetCellType()); // MESSAGE(" " << myGrid->GetCell(i)->GetCellType());
ficcon << i << " - " << myGrid->GetCell(i)->GetCellType() << " -"; ficcon << i << " - " << myGrid->GetCell(i)->GetCellType() << " -";
int nbptcell = myGrid->GetCell(i)->GetNumberOfPoints(); int nbptcell = myGrid->GetCell(i)->GetNumberOfPoints();
vtkIdList *listid = myGrid->GetCell(i)->GetPointIds(); vtkIdList *listid = myGrid->GetCell(i)->GetPointIds();
for (int j=0; j<nbptcell; j++) for (int j=0; j<nbptcell; j++)
{ {
ficcon << " " << listid->GetId(j); ficcon << " " << listid->GetId(j);
} }
ficcon << endl; ficcon << endl;
} }
ficcon << "-------------------------------- connectivity " << nbPoints << endl; ficcon << "-------------------------------- connectivity " << nbPoints << endl;
vtkCellLinks *links = myGrid->GetCellLinks(); vtkCellLinks *links = myGrid->GetCellLinks();
for (int i=0; i<nbPoints; i++) for (int i=0; i<nbPoints; i++)
{ {
int ncells = links->GetNcells(i); int ncells = links->GetNcells(i);
vtkIdType *cells = links->GetCells(i); vtkIdType *cells = links->GetCells(i);
ficcon << i << " - " << ncells << " -"; ficcon << i << " - " << ncells << " -";
for (int j=0; j<ncells; j++) for (int j=0; j<ncells; j++)
{ {
ficcon << " " << cells[j]; ficcon << " " << cells[j];
} }
ficcon << endl; ficcon << endl;
} }
ficcon.close(); ficcon.close();

View File

@ -72,12 +72,14 @@ void SMDS_MeshNode::init(int id, int meshId, int shapeId, double x, double y, do
SMDS_CellLinks *cellLinks = dynamic_cast<SMDS_CellLinks*>(grid->GetCellLinks()); SMDS_CellLinks *cellLinks = dynamic_cast<SMDS_CellLinks*>(grid->GetCellLinks());
assert(cellLinks); assert(cellLinks);
if (myVtkID >= cellLinks->GetLinksSize()) if (myVtkID >= cellLinks->GetLinksSize())
cellLinks->ResizeL(myVtkID+SMDS_Mesh::chunkSize); cellLinks->ResizeL(myVtkID+SMDS_Mesh::chunkSize);
} }
SMDS_MeshNode::~SMDS_MeshNode() SMDS_MeshNode::~SMDS_MeshNode()
{ {
nbNodes--; nbNodes--;
if ( myPosition && myPosition != SMDS_SpacePosition::originSpacePosition() )
delete myPosition, myPosition = 0;
} }
//======================================================================= //=======================================================================
@ -111,7 +113,9 @@ void SMDS_MeshNode::Print(ostream & OS) const
void SMDS_MeshNode::SetPosition(const SMDS_PositionPtr& aPos) void SMDS_MeshNode::SetPosition(const SMDS_PositionPtr& aPos)
{ {
myPosition = aPos; if ( myPosition && myPosition != aPos )
delete myPosition;
myPosition = aPos;
} }
//======================================================================= //=======================================================================
@ -214,7 +218,7 @@ private:
SMDSAbs_ElementType type): SMDSAbs_ElementType type):
myMesh(mesh), myCells(cells), myNcells(ncells), myType(type), iter(0) myMesh(mesh), myCells(cells), myNcells(ncells), myType(type), iter(0)
{ {
//MESSAGE("myNcells " << myNcells); //MESSAGE("myNcells " << myNcells);
for (; iter<ncells; iter++) for (; iter<ncells; iter++)
{ {
int vtkId = myCells[iter]; int vtkId = myCells[iter];
@ -225,7 +229,7 @@ private:
myFiltCells.push_back((SMDS_MeshElement*)elem); myFiltCells.push_back((SMDS_MeshElement*)elem);
} }
myNcells = myFiltCells.size(); myNcells = myFiltCells.size();
//MESSAGE("myNcells " << myNcells); //MESSAGE("myNcells " << myNcells);
iter = 0; iter = 0;
//MESSAGE("SMDS_MeshNode_MyIterator (filter) " << ncells << " " << myNcells); //MESSAGE("SMDS_MeshNode_MyIterator (filter) " << ncells << " " << myNcells);
} }