///////////////////////////////////////////////////////////////////////////////
/// Create a new mesh object
///////////////////////////////////////////////////////////////////////////////
-SMDS_Mesh::SMDS_Mesh()
- :myParent(NULL),
- myNodeIDFactory(new SMDS_MeshNodeIDFactory()),
- myElementIDFactory(new SMDS_MeshElementIDFactory()),
- myHasConstructionEdges(false), myHasConstructionFaces(false),
- myHasInverseElements(true),
- myNodeMin(0), myNodeMax(0),
- myNodePool(0), myEdgePool(0), myFacePool(0), myVolumePool(0),myBallPool(0),
- myModified(false), myModifTime(0), myCompactTime(0),
- xmin(0), xmax(0), ymin(0), ymax(0), zmin(0), zmax(0)
+SMDS_Mesh::SMDS_Mesh():
+ myNodePool(0), myVolumePool(0), myFacePool(0), myEdgePool(0), myBallPool(0),
+ myParent(NULL),
+ myNodeIDFactory(new SMDS_MeshNodeIDFactory()),
+ myElementIDFactory(new SMDS_MeshElementIDFactory()),
+ myModified(false), myModifTime(0), myCompactTime(0),
+ myNodeMin(0), myNodeMax(0),
+ myHasConstructionEdges(false), myHasConstructionFaces(false),
+ myHasInverseElements(true),
+ xmin(0), xmax(0), ymin(0), ymax(0), zmin(0), zmax(0)
{
myMeshId = _meshList.size(); // --- index of the mesh to push back in the vector
myNodeIDFactory->SetMesh(this);
/// Note that the tree structure of SMDS_Mesh seems to be unused in this version
/// (2003-09-08) of SMESH
///////////////////////////////////////////////////////////////////////////////
-SMDS_Mesh::SMDS_Mesh(SMDS_Mesh * parent)
- :myParent(parent), myNodeIDFactory(parent->myNodeIDFactory),
- myElementIDFactory(parent->myElementIDFactory),
- myHasConstructionEdges(false), myHasConstructionFaces(false),
- myHasInverseElements(true),
- myNodePool(parent->myNodePool),
- myEdgePool(parent->myEdgePool),
- myFacePool(parent->myFacePool),
- myVolumePool(parent->myVolumePool),
- myBallPool(parent->myBallPool)
+SMDS_Mesh::SMDS_Mesh(SMDS_Mesh * parent):
+ myNodePool(parent->myNodePool),
+ myVolumePool(parent->myVolumePool),
+ myFacePool(parent->myFacePool),
+ myEdgePool(parent->myEdgePool),
+ myBallPool(parent->myBallPool),
+ myParent(parent), myNodeIDFactory(parent->myNodeIDFactory),
+ myElementIDFactory(parent->myElementIDFactory),
+ myHasConstructionEdges(false), myHasConstructionFaces(false),
+ myHasInverseElements(true)
{
}
SMDS_Mesh *SMDS_Mesh::AddSubMesh()
{
- SMDS_Mesh *submesh = new SMDS_Mesh(this);
- myChildren.insert(myChildren.end(), submesh);
- return submesh;
+ SMDS_Mesh *submesh = new SMDS_Mesh(this);
+ myChildren.insert(myChildren.end(), submesh);
+ return submesh;
}
///////////////////////////////////////////////////////////////////////////////
SMDS_MeshNode * node = myNodePool->getNew();
node->init(ID, myMeshId, 0, x, y, z);
- if (ID >= myNodes.size())
+ if (ID >= (int)myNodes.size())
{
myNodes.resize(ID+SMDS_Mesh::chunkSize, 0);
// MESSAGE(" ------------------ myNodes resize " << ID << " --> " << ID+SMDS_Mesh::chunkSize);
SMDS_BallElement *ball = myBallPool->getNew();
ball->init(n->getVtkId(), diameter, this);
if (!this->registerElement(ID,ball))
- {
- this->myGrid->GetCellTypesArray()->SetValue(ball->getVtkId(), VTK_EMPTY_CELL);
- myBallPool->destroy(ball);
- return 0;
- }
+ {
+ this->myGrid->GetCellTypesArray()->SetValue(ball->getVtkId(), VTK_EMPTY_CELL);
+ myBallPool->destroy(ball);
+ return 0;
+ }
adjustmyCellsCapacity(ID);
myCells[ID] = ball;
myInfo.myNbBalls++;
bool SMDS_Mesh::registerElement(int ID, SMDS_MeshElement* element)
{
//MESSAGE("registerElement " << ID);
- if ((ID >=0) && (ID < myCells.size()) && myCells[ID]) // --- already bound
+ if ((ID >=0) && (ID < (int)myCells.size()) && myCells[ID]) // --- already bound
{
MESSAGE(" ------------------ already bound "<< ID << " " << myCells[ID]->getVtkId());
return false;
if (vtkId == -1)
vtkId = myElementIDFactory->SetInVtkGrid(element);
- if (vtkId >= myCellIdVtkToSmds.size()) // --- resize local vector
+ if (vtkId >= (int)myCellIdVtkToSmds.size()) // --- resize local vector
{
// MESSAGE(" --------------------- resize myCellIdVtkToSmds " << vtkId << " --> " << vtkId + SMDS_Mesh::chunkSize);
myCellIdVtkToSmds.resize(vtkId + SMDS_Mesh::chunkSize, -1);
///////////////////////////////////////////////////////////////////////////////
const SMDS_MeshNode * SMDS_Mesh::FindNode(int ID) const
{
- if (ID < 1 || ID >= myNodes.size())
+ if (ID < 1 || ID >= (int)myNodes.size())
{
// MESSAGE("------------------------------------------------------------------------- ");
// MESSAGE("----------------------------------- bad ID " << ID << " " << myNodes.size());
const SMDS_MeshNode * SMDS_Mesh::FindNodeVtk(int vtkId) const
{
// TODO if needed use mesh->nodeIdFromVtkToSmds
- if (vtkId < 0 || vtkId >= (myNodes.size() -1))
+ if ( vtkId < 0 || vtkId+1 >= (int) myNodes.size() )
{
MESSAGE("------------------------------------------------------------------------- ");
MESSAGE("---------------------------- bad VTK ID " << vtkId << " " << myNodes.size());
const SMDS_MeshElement* SMDS_Mesh::FindElement(int IDelem) const
{
- if ((IDelem <= 0) || IDelem >= myCells.size())
+ if ( IDelem <= 0 || IDelem >= (int)myCells.size() )
{
MESSAGE("--------------------------------------------------------------------------------- ");
MESSAGE("----------------------------------- bad IDelem " << IDelem << " " << myCells.size());
{
const SMDS_MeshElement* e = itF->next();
int nbNodesToCheck = noMedium ? e->NbCornerNodes() : e->NbNodes();
- if ( nbNodesToCheck == nodes.size() )
+ if ( nbNodesToCheck == (int)nodes.size() )
{
- for ( int i = 1; e && i < nodes.size(); ++ i )
+ for ( size_t i = 1; e && i < nodes.size(); ++i )
{
int nodeIndex = e->GetNodeIndex( nodes[ i ]);
if ( nodeIndex < 0 || nodeIndex >= nbNodesToCheck )
///////////////////////////////////////////////////////////////////////////////
/// Return the list of nodes used only by the given elements
///////////////////////////////////////////////////////////////////////////////
-static set<const SMDS_MeshElement*> * getExclusiveNodes(
- set<const SMDS_MeshElement*>& elements)
+static set<const SMDS_MeshElement*> * getExclusiveNodes(set<const SMDS_MeshElement*>& elements)
{
- set<const SMDS_MeshElement*> * toReturn=new set<const SMDS_MeshElement*>();
- set<const SMDS_MeshElement*>::iterator itElements=elements.begin();
+ set<const SMDS_MeshElement*> * toReturn=new set<const SMDS_MeshElement*>();
+ set<const SMDS_MeshElement*>::iterator itElements=elements.begin();
- while(itElements!=elements.end())
- {
- SMDS_ElemIteratorPtr itNodes = (*itElements)->nodesIterator();
- itElements++;
+ while(itElements!=elements.end())
+ {
+ SMDS_ElemIteratorPtr itNodes = (*itElements)->nodesIterator();
+ itElements++;
- while(itNodes->more())
- {
- const SMDS_MeshNode * n=static_cast<const SMDS_MeshNode*>(itNodes->next());
- SMDS_ElemIteratorPtr itFe = n->GetInverseElementIterator();
- set<const SMDS_MeshElement*> s;
- while(itFe->more())
- s.insert(itFe->next());
- if(s==elements) toReturn->insert(n);
- }
- }
- return toReturn;
+ while(itNodes->more())
+ {
+ const SMDS_MeshNode * n=static_cast<const SMDS_MeshNode*>(itNodes->next());
+ SMDS_ElemIteratorPtr itFe = n->GetInverseElementIterator();
+ set<const SMDS_MeshElement*> s;
+ while(itFe->more())
+ s.insert(itFe->next());
+ if(s==elements) toReturn->insert(n);
+ }
+ }
+ return toReturn;
}
///////////////////////////////////////////////////////////////////////////////
set<const SMDS_MeshElement*>& nodes)
{
switch(element->GetType())
+ {
+ case SMDSAbs_Node:
+ MESSAGE("Internal Error: This should not happen");
+ break;
+ case SMDSAbs_0DElement:
+ case SMDSAbs_Ball:
+ {
+ }
+ break;
+ case SMDSAbs_Edge:
+ {
+ SMDS_ElemIteratorPtr itn=element->nodesIterator();
+ while(itn->more())
{
- case SMDSAbs_Node:
- MESSAGE("Internal Error: This should not happen");
- break;
- case SMDSAbs_0DElement:
+ const SMDS_MeshElement * e=itn->next();
+ if(nodes.find(e)!=nodes.end())
{
+ setOfChildren.insert(element);
+ break;
+ }
+ }
+ } break;
+ case SMDSAbs_Face:
+ {
+ SMDS_ElemIteratorPtr itn=element->nodesIterator();
+ while(itn->more())
+ {
+ const SMDS_MeshElement * e=itn->next();
+ if(nodes.find(e)!=nodes.end())
+ {
+ setOfChildren.insert(element);
+ break;
}
- break;
- case SMDSAbs_Edge:
- {
- SMDS_ElemIteratorPtr itn=element->nodesIterator();
- while(itn->more())
- {
- const SMDS_MeshElement * e=itn->next();
- if(nodes.find(e)!=nodes.end())
- {
- setOfChildren.insert(element);
- break;
- }
- }
- } break;
- case SMDSAbs_Face:
- {
- SMDS_ElemIteratorPtr itn=element->nodesIterator();
- while(itn->more())
- {
- const SMDS_MeshElement * e=itn->next();
- if(nodes.find(e)!=nodes.end())
- {
- setOfChildren.insert(element);
- break;
- }
- }
- if(hasConstructionEdges())
- {
- SMDS_ElemIteratorPtr ite=element->edgesIterator();
- while(ite->more())
- addChildrenWithNodes(setOfChildren, ite->next(), nodes);
- }
- } break;
- case SMDSAbs_Volume:
- {
- if(hasConstructionFaces())
- {
- SMDS_ElemIteratorPtr ite=element->facesIterator();
- while(ite->more())
- addChildrenWithNodes(setOfChildren, ite->next(), nodes);
- }
- else if(hasConstructionEdges())
- {
- SMDS_ElemIteratorPtr ite=element->edgesIterator();
- while(ite->more())
- addChildrenWithNodes(setOfChildren, ite->next(), nodes);
- }
- }
}
+ if(hasConstructionEdges())
+ {
+ SMDS_ElemIteratorPtr ite=element->edgesIterator();
+ while(ite->more())
+ addChildrenWithNodes(setOfChildren, ite->next(), nodes);
+ }
+ } break;
+ case SMDSAbs_Volume:
+ {
+ if(hasConstructionFaces())
+ {
+ SMDS_ElemIteratorPtr ite=element->facesIterator();
+ while(ite->more())
+ addChildrenWithNodes(setOfChildren, ite->next(), nodes);
+ }
+ else if(hasConstructionEdges())
+ {
+ SMDS_ElemIteratorPtr ite=element->edgesIterator();
+ while(ite->more())
+ addChildrenWithNodes(setOfChildren, ite->next(), nodes);
+ }
+ }
+ case SMDSAbs_NbElementTypes:
+ case SMDSAbs_All: break;
+ }
}
///////////////////////////////////////////////////////////////////////////////
list<const SMDS_MeshElement *>& removedNodes,
bool removenodes)
{
- //MESSAGE("SMDS_Mesh::RemoveElement " << elem->getVtkId() << " " << removenodes);
// get finite elements built on elem
set<const SMDS_MeshElement*> * s1;
if ( (elem->GetType() == SMDSAbs_0DElement)
// Remove element from <InverseElements> of its nodes
SMDS_ElemIteratorPtr itn = (*it)->nodesIterator();
while (itn->more())
- {
- SMDS_MeshNode * n = static_cast<SMDS_MeshNode *> (const_cast<SMDS_MeshElement *> (itn->next()));
- n->RemoveInverseElement((*it));
- }
+ {
+ SMDS_MeshNode * n = static_cast<SMDS_MeshNode *> (const_cast<SMDS_MeshElement *> (itn->next()));
+ n->RemoveInverseElement((*it));
+ }
int IdToRemove = (*it)->GetID();
int vtkid = (*it)->getVtkId();
- //MESSAGE("elem Id to remove " << IdToRemove << " vtkid " << vtkid <<
- // " vtktype " << (*it)->GetVtkType() << " type " << (*it)->GetType());
switch ((*it)->GetType())
{
case SMDSAbs_Node:
- MYASSERT("Internal Error: This should not happen")
- ;
+ MYASSERT("Internal Error: This should not happen");
break;
case SMDSAbs_0DElement:
if (IdToRemove >= 0)
myElementIDFactory->ReleaseID(IdToRemove, vtkid);
if (const SMDS_VtkEdge* vtkElem = dynamic_cast<const SMDS_VtkEdge*>(*it))
myEdgePool->destroy((SMDS_VtkEdge*) vtkElem);
- else
+ else {
+ ((SMDS_MeshElement*) *it)->init( -1, -1, -1 ); // avoid reuse
delete (*it);
+ }
break;
case SMDSAbs_Face:
if (IdToRemove >= 0)
myElementIDFactory->ReleaseID(IdToRemove, vtkid);
if (const SMDS_VtkFace* vtkElem = dynamic_cast<const SMDS_VtkFace*>(*it))
myFacePool->destroy((SMDS_VtkFace*) vtkElem);
- else
+ else {
+ ((SMDS_MeshElement*) *it)->init( -1, -1, -1 ); // avoid reuse
delete (*it);
+ }
break;
case SMDSAbs_Volume:
if (IdToRemove >= 0)
myElementIDFactory->ReleaseID(IdToRemove, vtkid);
if (const SMDS_VtkVolume* vtkElem = dynamic_cast<const SMDS_VtkVolume*>(*it))
myVolumePool->destroy((SMDS_VtkVolume*) vtkElem);
- else
+ else {
+ ((SMDS_MeshElement*) *it)->init( -1, -1, -1 ); // avoid reuse
delete (*it);
+ }
break;
case SMDSAbs_Ball:
if (IdToRemove >= 0)
myElementIDFactory->ReleaseID(IdToRemove, vtkid);
if (const SMDS_BallElement* vtkElem = dynamic_cast<const SMDS_BallElement*>(*it))
myBallPool->destroy(const_cast<SMDS_BallElement*>( vtkElem ));
- else
+ else {
+ ((SMDS_MeshElement*) *it)->init( -1, -1, -1 ); // avoid reuse
delete (*it);
+ }
break;
+
+ case SMDSAbs_All: // avoid compilation warning
+ case SMDSAbs_NbElementTypes: break;
}
if (vtkid >= 0)
- {
- //MESSAGE("VTK_EMPTY_CELL in " << vtkid);
- this->myGrid->GetCellTypesArray()->SetValue(vtkid, VTK_EMPTY_CELL);
- }
+ {
+ this->myGrid->GetCellTypesArray()->SetValue(vtkid, VTK_EMPTY_CELL);
+ }
it++;
}
// remove exclusive (free) nodes
if (removenodes)
+ {
+ it = s2->begin();
+ while (it != s2->end())
{
- it = s2->begin();
- while (it != s2->end())
- {
- int IdToRemove = (*it)->GetID();
- //MESSAGE( "SMDS: RM node " << IdToRemove);
- if (IdToRemove >= 0)
- {
- myNodes[IdToRemove] = 0;
- myInfo.myNbNodes--;
- }
- myNodeIDFactory->ReleaseID((*it)->GetID(), (*it)->getVtkId());
- removedNodes.push_back((*it));
- if (const SMDS_MeshNode* vtkElem = dynamic_cast<const SMDS_MeshNode*>(*it))
- {
- ((SMDS_MeshNode*)vtkElem)->SetPosition(SMDS_SpacePosition::originSpacePosition());
- myNodePool->destroy((SMDS_MeshNode*) vtkElem);
- }
- else
- delete (*it);
- it++;
- }
+ int IdToRemove = (*it)->GetID();
+ if (IdToRemove >= 0)
+ {
+ myNodes[IdToRemove] = 0;
+ myInfo.myNbNodes--;
+ }
+ myNodeIDFactory->ReleaseID((*it)->GetID(), (*it)->getVtkId());
+ removedNodes.push_back((*it));
+ if (const SMDS_MeshNode* vtkElem = dynamic_cast<const SMDS_MeshNode*>(*it))
+ {
+ ((SMDS_MeshNode*)vtkElem)->SetPosition(SMDS_SpacePosition::originSpacePosition());
+ myNodePool->destroy((SMDS_MeshNode*) vtkElem);
+ }
+ else
+ delete (*it);
+ it++;
}
+ }
delete s2;
delete s1;
}
// in meshes without descendants elements are always free
- switch (aType) {
+ switch (aType) {
case SMDSAbs_0DElement:
myCells[elemId] = 0;
myInfo.remove(elem);
delete elem;
+ elem = 0;
break;
case SMDSAbs_Edge:
myCells[elemId] = 0;
this->myGrid->GetCellTypesArray()->SetValue(vtkId, VTK_EMPTY_CELL);
// --- to do: keep vtkid in a list of reusable cells
+
+ if ( elem )
+ ((SMDS_MeshElement*) elem)->init( -1, -1, -1 ); // avoid reuse
}
}
myNodeMax=0;
return;
}
- while (!myNodes[myNodeMin] && (myNodeMin<myNodes.size()))
+ while ( !myNodes[myNodeMin] && myNodeMin < (int)myNodes.size() )
myNodeMin++;
myNodeMax=myNodes.size()-1;
while (!myNodes[myNodeMax] && (myNodeMin>=0))
int SMDS_Mesh::fromVtkToSmds(int vtkid)
{
- if (vtkid >= 0 && vtkid < myCellIdVtkToSmds.size())
+ if (vtkid >= 0 && vtkid < (int)myCellIdVtkToSmds.size())
return myCellIdVtkToSmds[vtkid];
throw SALOME_Exception(LOCALIZED ("vtk id out of bounds"));
}