#include <sys/sysinfo.h>
#endif
-
//================================================================================
/*!
* \brief Raise an exception if free memory (ram+swap) too low
//purpose :
//=======================================================================
-bool SMDS_Mesh::ChangeElementNodes(const SMDS_MeshElement * elem,
+bool SMDS_Mesh::ChangeElementNodes(const SMDS_MeshElement * element,
const SMDS_MeshNode * nodes[],
const int nbnodes)
{
// keep current nodes of elem
set<const SMDS_MeshElement*> oldNodes;
- SMDS_ElemIteratorPtr itn = elem->nodesIterator();
+ 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_MeshElement* elem = const_cast<SMDS_MeshElement*>(element);
switch ( elem->GetType() )
{
case SMDSAbs_Edge: {
if ( nbnodes == 2 ) {
- const SMDS_MeshEdge* edge = dynamic_cast<const SMDS_MeshEdge*>( elem );
- if ( edge )
- Ok = const_cast<SMDS_MeshEdge*>( edge )->ChangeNodes( nodes[0], nodes[1] );
+ if ( SMDS_MeshEdge* edge = dynamic_cast<SMDS_MeshEdge*>( elem ))
+ Ok = edge->ChangeNodes( nodes[0], nodes[1] );
}
else if ( nbnodes == 3 ) {
- const SMDS_QuadraticEdge* edge = dynamic_cast<const SMDS_QuadraticEdge*>( elem );
- if ( edge )
- Ok = const_cast<SMDS_QuadraticEdge*>( edge )->ChangeNodes( nodes[0], nodes[1], nodes[2] );
+ if ( SMDS_QuadraticEdge* edge = dynamic_cast<SMDS_QuadraticEdge*>( elem ))
+ Ok = edge->ChangeNodes( nodes[0], nodes[1], nodes[2] );
}
break;
}
case SMDSAbs_Face: {
- const SMDS_FaceOfNodes* face = dynamic_cast<const SMDS_FaceOfNodes*>( elem );
- if ( face ) {
- Ok = const_cast<SMDS_FaceOfNodes*>( face )->ChangeNodes( nodes, nbnodes );
- }
- else {
- const SMDS_QuadraticFaceOfNodes* QF =
- dynamic_cast<const SMDS_QuadraticFaceOfNodes*>( elem );
- if ( QF ) {
- Ok = const_cast<SMDS_QuadraticFaceOfNodes*>( QF )->ChangeNodes( nodes, nbnodes );
- }
- else {
- /// ??? begin
- const SMDS_PolygonalFaceOfNodes* face = dynamic_cast<const SMDS_PolygonalFaceOfNodes*>(elem);
- if (face) {
- Ok = const_cast<SMDS_PolygonalFaceOfNodes*>(face)->ChangeNodes(nodes, nbnodes);
- }
- /// ??? end
- }
- }
+ if ( SMDS_FaceOfNodes* face = dynamic_cast<SMDS_FaceOfNodes*>( elem ))
+ Ok = face->ChangeNodes( nodes, nbnodes );
+ else
+ if ( SMDS_QuadraticFaceOfNodes* QF = dynamic_cast<SMDS_QuadraticFaceOfNodes*>( elem ))
+ Ok = QF->ChangeNodes( nodes, nbnodes );
+ else
+ if (SMDS_PolygonalFaceOfNodes* face = dynamic_cast<SMDS_PolygonalFaceOfNodes*>(elem))
+ Ok = face->ChangeNodes(nodes, nbnodes);
break;
}
- //case SMDSAbs_PolygonalFace: {
- // const SMDS_PolygonalFaceOfNodes* face = dynamic_cast<const SMDS_PolygonalFaceOfNodes*>(elem);
- // if (face) {
- // Ok = const_cast<SMDS_PolygonalFaceOfNodes*>(face)->ChangeNodes(nodes, nbnodes);
- // }
- // break;
- //}
case SMDSAbs_Volume: {
- const SMDS_VolumeOfNodes* vol = dynamic_cast<const SMDS_VolumeOfNodes*>( elem );
- if ( vol ) {
- Ok = const_cast<SMDS_VolumeOfNodes*>( vol )->ChangeNodes( nodes, nbnodes );
- }
- else {
- const SMDS_QuadraticVolumeOfNodes* QV = dynamic_cast<const SMDS_QuadraticVolumeOfNodes*>( elem );
- if ( QV ) {
- Ok = const_cast<SMDS_QuadraticVolumeOfNodes*>( QV )->ChangeNodes( nodes, nbnodes );
- }
- }
+ if ( SMDS_VolumeOfNodes* vol = dynamic_cast<SMDS_VolumeOfNodes*>( elem ))
+ Ok = vol->ChangeNodes( nodes, nbnodes );
+ else
+ if ( SMDS_QuadraticVolumeOfNodes* QV = dynamic_cast<SMDS_QuadraticVolumeOfNodes*>( elem ))
+ Ok = QV->ChangeNodes( nodes, nbnodes );
break;
}
default:
if ( Ok ) { // update InverseElements
+ set<const SMDS_MeshElement*>::iterator it;
+
// AddInverseElement to new nodes
- for ( int i = 0; i < nbnodes; i++ )
- if ( oldNodes.find( nodes[i] ) == oldNodes.end() )
+ for ( int i = 0; i < nbnodes; i++ ) {
+ it = oldNodes.find( nodes[i] );
+ if ( it == oldNodes.end() )
// new node
const_cast<SMDS_MeshNode*>( nodes[i] )->AddInverseElement( elem );
else
// remove from oldNodes a node that remains in elem
- oldNodes.erase( nodes[i] );
-
-
+ oldNodes.erase( it );
+ }
// RemoveInverseElement from the nodes removed from elem
- set<const SMDS_MeshElement*>::iterator it;
for ( it = oldNodes.begin(); it != oldNodes.end(); it++ )
{
SMDS_MeshNode * n = static_cast<SMDS_MeshNode *>
}
}
- //MESSAGE ( "::ChangeNodes() Ok = " << Ok);
+ if ( !element->IsPoly() )
+ myInfo.add( element ); // element may change type
return Ok;
}
//function : ChangePolyhedronNodes
//purpose : to change nodes of polyhedral volume
//=======================================================================
-bool SMDS_Mesh::ChangePolyhedronNodes (const SMDS_MeshElement * elem,
- std::vector<const SMDS_MeshNode*> nodes,
- std::vector<int> quantities)
+bool SMDS_Mesh::ChangePolyhedronNodes (const SMDS_MeshElement * elem,
+ const vector<const SMDS_MeshNode*>& nodes,
+ const vector<int> & quantities)
{
if (elem->GetType() != SMDSAbs_Volume) {
MESSAGE("WRONG ELEM TYPE");
// AddInverseElement to new nodes
int nbnodes = nodes.size();
+ set<const SMDS_MeshElement*>::iterator it;
for (int i = 0; i < nbnodes; i++) {
- if (oldNodes.find(nodes[i]) == oldNodes.end()) {
+ it = oldNodes.find(nodes[i]);
+ if (it == oldNodes.end()) {
// new node
const_cast<SMDS_MeshNode*>(nodes[i])->AddInverseElement(elem);
} else {
// remove from oldNodes a node that remains in elem
- oldNodes.erase(nodes[i]);
+ oldNodes.erase(it);
}
}
// RemoveInverseElement from the nodes removed from elem
- set<const SMDS_MeshElement*>::iterator it;
for (it = oldNodes.begin(); it != oldNodes.end(); it++) {
SMDS_MeshNode * n = static_cast<SMDS_MeshNode *>
(const_cast<SMDS_MeshElement *>( *it ));
virtual bool RemoveFromParent();
virtual bool RemoveSubMesh(const SMDS_Mesh * aMesh);
- static bool ChangeElementNodes(const SMDS_MeshElement * elem,
- const SMDS_MeshNode * nodes[],
- const int nbnodes);
- static bool ChangePolyhedronNodes(const SMDS_MeshElement * elem,
- std::vector<const SMDS_MeshNode*> nodes,
- std::vector<int> quantities);
+ bool ChangeElementNodes(const SMDS_MeshElement * elem,
+ const SMDS_MeshNode * nodes[],
+ const int nbnodes);
+ bool ChangePolyhedronNodes(const SMDS_MeshElement * elem,
+ const std::vector<const SMDS_MeshNode*>& nodes,
+ const std::vector<int> & quantities);
virtual void Renumber (const bool isNodes, const int startID = 1, const int deltaID = 1);
// Renumber all nodes or elements.
private:
friend class SMDS_Mesh;
+ // methods to count NOT POLY elements
+ inline void remove(const SMDS_MeshElement* el);
+ inline void add (const SMDS_MeshElement* el);
+ inline int index(SMDSAbs_ElementType type, int nbNodes);
+ // methods to remove elements of ANY kind
inline void RemoveEdge(const SMDS_MeshElement* el);
inline void RemoveFace(const SMDS_MeshElement* el);
inline void RemoveVolume(const SMDS_MeshElement* el);
int myNbPyramids, myNbQuadPyramids;
int myNbPrisms , myNbQuadPrisms ;
int myNbPolyhedrons;
-
+
+ vector<int*> myNb; // pointers to myNb... fields
+ vector<int> myShift; // shift to get an index in myNb by elem->NbNodes()
};
inline SMDS_MeshInfo::SMDS_MeshInfo():
myNbPyramids(0), myNbQuadPyramids(0),
myNbPrisms (0), myNbQuadPrisms (0),
myNbPolyhedrons(0)
-{}
+{
+ // Number of nodes in standard element types
+ // n v f e
+ // o o a d
+ // d l c g
+ // e e e
+ // -----------
+ // 1
+ // 2 *
+ // 3 *
+ // 4 * * *
+ // 5 *
+ // 6 * *
+ // 7
+ // 8 * *
+ // 9
+ // 10 *
+ // 11
+ // 12
+ // 13 *
+ // 14
+ // 15 *
+ // 16
+ // 17
+ // 18
+ // 19
+ // 20 *
+ //
+ // So to have a unique index for each type basing on nb of nodes, we use a shift:
+ myShift.resize(SMDSAbs_Volume + 1, 0);
+ myShift[ SMDSAbs_Face ] = +8; // 3->11, 4->12, 6->14, 8->16
+ myShift[ SMDSAbs_Edge ] = -2; // 2->0, 4->2
+
+ myNb.resize( index( SMDSAbs_Volume,20 ) + 1, NULL);
+ myNb[ index( SMDSAbs_Node,1 )] = & myNbNodes;
+
+ myNb[ index( SMDSAbs_Edge,2 )] = & myNbEdges;
+ myNb[ index( SMDSAbs_Edge,4 )] = & myNbQuadEdges;
+
+ myNb[ index( SMDSAbs_Face,3 )] = & myNbTriangles;
+ myNb[ index( SMDSAbs_Face,4 )] = & myNbQuadrangles;
+ myNb[ index( SMDSAbs_Face,6 )] = & myNbQuadTriangles;
+ myNb[ index( SMDSAbs_Face,8 )] = & myNbQuadQuadrangles;
+
+ myNb[ index( SMDSAbs_Volume, 4)] = & myNbTetras;
+ myNb[ index( SMDSAbs_Volume, 5)] = & myNbPyramids;
+ myNb[ index( SMDSAbs_Volume, 6)] = & myNbPrisms;
+ myNb[ index( SMDSAbs_Volume, 8)] = & myNbHexas;
+ myNb[ index( SMDSAbs_Volume, 10)] = & myNbQuadTetras;
+ myNb[ index( SMDSAbs_Volume, 13)] = & myNbQuadPyramids;
+ myNb[ index( SMDSAbs_Volume, 15)] = & myNbQuadPrisms;
+ myNb[ index( SMDSAbs_Volume, 20)] = & myNbQuadHexas;
+}
+
+inline int // index
+SMDS_MeshInfo::index(SMDSAbs_ElementType type, int nbNodes)
+{ return nbNodes + myShift[ type ]; }
+
+inline void // remove
+SMDS_MeshInfo::remove(const SMDS_MeshElement* el)
+{ --(*myNb[ index(el->GetType(), el->NbNodes()) ]); }
+
+inline void // add
+SMDS_MeshInfo::add(const SMDS_MeshElement* el)
+{ ++(*myNb[ index(el->GetType(), el->NbNodes()) ]); }
+
+inline void // RemoveEdge
+SMDS_MeshInfo::RemoveEdge(const SMDS_MeshElement* el)
+{ if ( el->IsQuadratic() ) --myNbQuadEdges; else --myNbEdges; }
+
+inline void // RemoveFace
+SMDS_MeshInfo::RemoveFace(const SMDS_MeshElement* el)
+{ if ( el->IsPoly() ) --myNbPolygons; else remove( el ); }
+
+inline void // RemoveVolume
+SMDS_MeshInfo::RemoveVolume(const SMDS_MeshElement* el)
+{ if ( el->IsPoly() ) --myNbPolyhedrons; else remove( el ); }
inline int // NbEdges
SMDS_MeshInfo::NbEdges (SMDSAbs_ElementOrder order) const
SMDS_MeshInfo::NbPrisms (SMDSAbs_ElementOrder order) const
{ return order == ORDER_ANY ? myNbPrisms+myNbQuadPrisms : order == ORDER_LINEAR ? myNbPrisms : myNbQuadPrisms; }
-// RemoveEdge
-inline void SMDS_MeshInfo::RemoveEdge(const SMDS_MeshElement* el)
-{
- if ( el->IsQuadratic() ) --myNbQuadEdges; else --myNbEdges;
-}
-
-// RemoveFace
-inline void SMDS_MeshInfo::RemoveFace(const SMDS_MeshElement* el)
-{
- int nbnode = el->NbNodes();
- if ( el->IsPoly() ) --myNbPolygons;
- else if (nbnode == 3) --myNbTriangles;
- else if (nbnode == 4) --myNbQuadrangles;
- else if (nbnode == 6) --myNbQuadTriangles;
- else if (nbnode == 8) --myNbQuadQuadrangles;
-}
-
-// RemoveVolume
-inline void SMDS_MeshInfo::RemoveVolume(const SMDS_MeshElement* el)
-{
- int nbnode = el->NbNodes();
- if ( el->IsPoly() ) --myNbPolyhedrons;
- else if (nbnode == 4) --myNbTetras;
- else if (nbnode == 5) --myNbPyramids;
- else if (nbnode == 6) --myNbPrisms;
- else if (nbnode == 8) --myNbHexas;
- else if (nbnode == 10) --myNbQuadTetras;
- else if (nbnode == 13) --myNbQuadPyramids;
- else if (nbnode == 15) --myNbQuadPrisms;
- else if (nbnode == 20) --myNbQuadHexas;
-}
-
#endif