Improve SMDS: replace std::vector with simple array

for storage of links to nodes in mesh elements
This commit is contained in:
msv 2005-01-14 13:26:34 +00:00
parent 40e9d61119
commit 61d5fb0e6a
8 changed files with 126 additions and 73 deletions

View File

@ -19,6 +19,10 @@
//
// See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
#ifdef _MSC_VER
#pragma warning(disable:4786)
#endif
#include "SMDS_FaceOfEdges.hxx"
#include "SMDS_IteratorOfElements.hxx"
#include "SMDS_MeshNode.hxx"
@ -32,7 +36,7 @@ using namespace std;
int SMDS_FaceOfEdges::NbEdges() const
{
return myEdges.size();
return myNbEdges;
}
int SMDS_FaceOfEdges::NbFaces() const
@ -57,17 +61,23 @@ SMDSAbs_ElementType SMDS_FaceOfEdges::GetType() const
return SMDSAbs_Face;
}
//=======================================================================
//function : elementsIterator
//purpose :
//=======================================================================
class SMDS_FaceOfEdges_MyIterator:public SMDS_ElemIterator
{
const vector<const SMDS_MeshEdge*>& mySet;
const SMDS_MeshEdge* const *mySet;
int myLength;
int index;
public:
SMDS_FaceOfEdges_MyIterator(const vector<const SMDS_MeshEdge*>& s):
mySet(s),index(0) {}
SMDS_FaceOfEdges_MyIterator(const SMDS_MeshEdge* const *s, int l):
mySet(s),myLength(l),index(0) {}
bool more()
{
return index<mySet.size();
return index<myLength;
}
const SMDS_MeshElement* next()
@ -76,30 +86,33 @@ class SMDS_FaceOfEdges_MyIterator:public SMDS_ElemIterator
return mySet[index-1];
}
};
SMDS_ElemIteratorPtr SMDS_FaceOfEdges::
elementsIterator(SMDSAbs_ElementType type) const
SMDS_ElemIteratorPtr SMDS_FaceOfEdges::elementsIterator
(SMDSAbs_ElementType type) const
{
switch(type)
{
case SMDSAbs_Face:
return SMDS_MeshElement::elementsIterator(SMDSAbs_Face);
case SMDSAbs_Edge:
return SMDS_ElemIteratorPtr(new SMDS_FaceOfEdges_MyIterator(myEdges));
default:
return SMDS_ElemIteratorPtr
(new SMDS_IteratorOfElements
(this,type, SMDS_ElemIteratorPtr(new SMDS_FaceOfEdges_MyIterator(myEdges))));
}
switch(type)
{
case SMDSAbs_Face:
return SMDS_MeshElement::elementsIterator(SMDSAbs_Face);
case SMDSAbs_Edge:
return SMDS_ElemIteratorPtr(new SMDS_FaceOfEdges_MyIterator(myEdges,myNbEdges));
default:
return SMDS_ElemIteratorPtr
(new SMDS_IteratorOfElements
(this,type, SMDS_ElemIteratorPtr
(new SMDS_FaceOfEdges_MyIterator(myEdges,myNbEdges))));
}
}
SMDS_FaceOfEdges::SMDS_FaceOfEdges(const SMDS_MeshEdge* edge1,
const SMDS_MeshEdge* edge2,
const SMDS_MeshEdge* edge3)
{
myEdges.resize(3);
myNbEdges = 3;
myEdges[0]=edge1;
myEdges[1]=edge2;
myEdges[2]=edge3;
myEdges[3]=0;
}
SMDS_FaceOfEdges::SMDS_FaceOfEdges(const SMDS_MeshEdge* edge1,
@ -107,7 +120,7 @@ SMDS_FaceOfEdges::SMDS_FaceOfEdges(const SMDS_MeshEdge* edge1,
const SMDS_MeshEdge* edge3,
const SMDS_MeshEdge* edge4)
{
myEdges.resize(4);
myNbEdges = 4;
myEdges[0]=edge1;
myEdges[1]=edge2;
myEdges[2]=edge3;

View File

@ -51,7 +51,8 @@ class SMDS_FaceOfEdges:public SMDS_MeshFace
elementsIterator(SMDSAbs_ElementType type) const;
private:
std::vector<const SMDS_MeshEdge*> myEdges;
const SMDS_MeshEdge* myEdges[4];
int myNbEdges;
};

View File

@ -19,6 +19,10 @@
//
// See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
#ifdef _MSC_VER
#pragma warning(disable:4786)
#endif
#include "SMDS_FaceOfNodes.hxx"
#include "SMDS_IteratorOfElements.hxx"
#include "SMDS_MeshNode.hxx"
@ -43,8 +47,9 @@ int SMDS_FaceOfNodes::NbFaces() const
int SMDS_FaceOfNodes::NbNodes() const
{
return myNodes.size();
return myNbNodes;
}
//=======================================================================
//function : Print
//purpose :
@ -58,41 +63,49 @@ void SMDS_FaceOfNodes::Print(ostream & OS) const
OS << myNodes[i] << ") " << endl;
}
//=======================================================================
//function : elementsIterator
//purpose :
//=======================================================================
class SMDS_FaceOfNodes_MyIterator:public SMDS_ElemIterator
{
const vector<const SMDS_MeshNode*>& mySet;
const SMDS_MeshNode* const *mySet;
int myLength;
int index;
public:
SMDS_FaceOfNodes_MyIterator(const vector<const SMDS_MeshNode*>& s):
mySet(s),index(0) {}
SMDS_FaceOfNodes_MyIterator(const SMDS_MeshNode* const *s, int l):
mySet(s),myLength(l),index(0) {}
bool more()
{
return index<mySet.size();
return index<myLength;
}
const SMDS_MeshElement* next()
{
index++;
return mySet[index-1];
}
}
};
SMDS_ElemIteratorPtr SMDS_FaceOfNodes::
elementsIterator(SMDSAbs_ElementType type) const
SMDS_ElemIteratorPtr SMDS_FaceOfNodes::elementsIterator
(SMDSAbs_ElementType type) const
{
switch(type)
{
case SMDSAbs_Face:
return SMDS_MeshElement::elementsIterator(SMDSAbs_Face);
case SMDSAbs_Node:
return SMDS_ElemIteratorPtr(new SMDS_FaceOfNodes_MyIterator(myNodes));
return SMDS_ElemIteratorPtr(new SMDS_FaceOfNodes_MyIterator(myNodes,myNbNodes));
case SMDSAbs_Edge:
MESSAGE("Error : edge iterator for SMDS_FaceOfNodes not implemented");
break;
default:
return SMDS_ElemIteratorPtr
(new SMDS_IteratorOfElements
(this,type,SMDS_ElemIteratorPtr(new SMDS_FaceOfNodes_MyIterator(myNodes))));
(this,type,SMDS_ElemIteratorPtr
(new SMDS_FaceOfNodes_MyIterator(myNodes,myNbNodes))));
}
return SMDS_ElemIteratorPtr();
}
@ -101,10 +114,11 @@ SMDS_FaceOfNodes::SMDS_FaceOfNodes(const SMDS_MeshNode* node1,
const SMDS_MeshNode* node2,
const SMDS_MeshNode* node3)
{
myNodes.resize(3);
myNbNodes = 3;
myNodes[0]=node1;
myNodes[1]=node2;
myNodes[2]=node3;
myNodes[3]=0;
}
SMDS_FaceOfNodes::SMDS_FaceOfNodes(const SMDS_MeshNode* node1,
@ -112,7 +126,7 @@ SMDS_FaceOfNodes::SMDS_FaceOfNodes(const SMDS_MeshNode* node1,
const SMDS_MeshNode* node3,
const SMDS_MeshNode* node4)
{
myNodes.resize(4);
myNbNodes = 4;
myNodes[0]=node1;
myNodes[1]=node2;
myNodes[2]=node3;
@ -121,20 +135,13 @@ SMDS_FaceOfNodes::SMDS_FaceOfNodes(const SMDS_MeshNode* node1,
bool SMDS_FaceOfNodes::ChangeNodes(const SMDS_MeshNode* nodes[],
const int nbNodes)
{
if (nbNodes == 3) {
myNodes.resize(3);
myNodes[0]=nodes[0];
myNodes[1]=nodes[1];
myNodes[2]=nodes[2];
}
else if ( nbNodes == 4) {
myNodes.resize(4);
myNodes[0]=nodes[0];
myNodes[1]=nodes[1];
myNodes[2]=nodes[2];
myNbNodes = nbNodes;
myNodes[0]=nodes[0];
myNodes[1]=nodes[1];
myNodes[2]=nodes[2];
if (nbNodes == 4)
myNodes[3]=nodes[3];
}
else
else if (nbNodes != 3)
return false;
return true;

View File

@ -49,7 +49,8 @@ class SMDS_FaceOfNodes:public SMDS_MeshFace
elementsIterator(SMDSAbs_ElementType type) const;
private:
std::vector<const SMDS_MeshNode*> myNodes;
const SMDS_MeshNode* myNodes[4];
int myNbNodes;
};

View File

@ -25,6 +25,10 @@
// Author : Jean-Michel BOULCOURT
// Module : SMESH
#ifdef _MSC_VER
#pragma warning(disable:4786)
#endif
#include "SMDS_VolumeOfFaces.hxx"
#include "SMDS_IteratorOfElements.hxx"
@ -39,27 +43,28 @@ void SMDS_VolumeOfFaces::Print(ostream & OS) const
{
OS << "volume <" << GetID() << "> : ";
int i;
for (i = 0; i < myFaces.size()-1; ++i) OS << myFaces[i] << ",";
for (i = 0; i < NbFaces()-1; ++i) OS << myFaces[i] << ",";
OS << myFaces[i]<< ") " << endl;
}
int SMDS_VolumeOfFaces::NbFaces() const
{
return myFaces.size();
return myNbFaces;
}
class SMDS_VolumeOfFaces_MyIterator:public SMDS_ElemIterator
{
const vector<const SMDS_MeshFace*>& mySet;
const SMDS_MeshFace* const *mySet;
int myLength;
int index;
public:
SMDS_VolumeOfFaces_MyIterator(const vector<const SMDS_MeshFace*>& s):
mySet(s),index(0) {}
SMDS_VolumeOfFaces_MyIterator(const SMDS_MeshFace* const *s, int l):
mySet(s),myLength(l),index(0) {}
bool more()
{
return index<mySet.size();
return index<myLength;
}
const SMDS_MeshElement* next()
@ -77,11 +82,12 @@ SMDS_ElemIteratorPtr SMDS_VolumeOfFaces::
case SMDSAbs_Volume:
return SMDS_MeshElement::elementsIterator(SMDSAbs_Volume);
case SMDSAbs_Face:
return SMDS_ElemIteratorPtr(new SMDS_VolumeOfFaces_MyIterator(myFaces));
return SMDS_ElemIteratorPtr(new SMDS_VolumeOfFaces_MyIterator(myFaces,myNbFaces));
default:
return SMDS_ElemIteratorPtr
(new SMDS_IteratorOfElements
(this,type,SMDS_ElemIteratorPtr(new SMDS_VolumeOfFaces_MyIterator(myFaces))));
(this,type,SMDS_ElemIteratorPtr
(new SMDS_VolumeOfFaces_MyIterator(myFaces,myNbFaces))));
}
}
@ -90,11 +96,13 @@ SMDS_VolumeOfFaces::SMDS_VolumeOfFaces(const SMDS_MeshFace * face1,
const SMDS_MeshFace * face3,
const SMDS_MeshFace * face4)
{
myFaces.resize(4);
myNbFaces = 4;
myFaces[0]=face1;
myFaces[1]=face2;
myFaces[2]=face3;
myFaces[3]=face4;
myFaces[4]=0;
myFaces[5]=0;
}
SMDS_VolumeOfFaces::SMDS_VolumeOfFaces(const SMDS_MeshFace * face1,
@ -103,12 +111,13 @@ SMDS_VolumeOfFaces::SMDS_VolumeOfFaces(const SMDS_MeshFace * face1,
const SMDS_MeshFace * face4,
const SMDS_MeshFace * face5)
{
myFaces.resize(5);
myNbFaces = 5;
myFaces[0]=face1;
myFaces[1]=face2;
myFaces[2]=face3;
myFaces[3]=face4;
myFaces[4]=face5;
myFaces[5]=0;
}
SMDS_VolumeOfFaces::SMDS_VolumeOfFaces(const SMDS_MeshFace * face1,
@ -118,7 +127,7 @@ SMDS_VolumeOfFaces::SMDS_VolumeOfFaces(const SMDS_MeshFace * face1,
const SMDS_MeshFace * face5,
const SMDS_MeshFace * face6)
{
myFaces.resize(6);
myNbFaces = 6;
myFaces[0]=face1;
myFaces[1]=face2;
myFaces[2]=face3;

View File

@ -30,7 +30,6 @@
#include "SMDS_MeshVolume.hxx"
#include "SMDS_MeshFace.hxx"
#include "SMDS_Iterator.hxx"
#include <vector>
#include <iostream>
@ -61,6 +60,7 @@ class SMDS_VolumeOfFaces:public SMDS_MeshVolume
protected:
SMDS_ElemIteratorPtr
elementsIterator(SMDSAbs_ElementType type) const;
std::vector<const SMDS_MeshFace *> myFaces;
const SMDS_MeshFace * myFaces[6];
int myNbFaces;
};
#endif

View File

@ -19,6 +19,10 @@
//
// See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
#ifdef _MSC_VER
#pragma warning(disable:4786)
#endif
#include "SMDS_VolumeOfNodes.hxx"
#include "SMDS_MeshNode.hxx"
#include "utilities.h"
@ -39,7 +43,8 @@ SMDS_VolumeOfNodes::SMDS_VolumeOfNodes(
const SMDS_MeshNode * node7,
const SMDS_MeshNode * node8)
{
myNodes.resize(8);
myNbNodes = 8;
myNodes = new const SMDS_MeshNode* [myNbNodes];
myNodes[0]=node1;
myNodes[1]=node2;
myNodes[2]=node3;
@ -56,7 +61,8 @@ SMDS_VolumeOfNodes::SMDS_VolumeOfNodes(
const SMDS_MeshNode * node3,
const SMDS_MeshNode * node4)
{
myNodes.resize(4);
myNbNodes = 4;
myNodes = new const SMDS_MeshNode* [myNbNodes];
myNodes[0]=node1;
myNodes[1]=node2;
myNodes[2]=node3;
@ -70,7 +76,8 @@ SMDS_VolumeOfNodes::SMDS_VolumeOfNodes(
const SMDS_MeshNode * node4,
const SMDS_MeshNode * node5)
{
myNodes.resize(5);
myNbNodes = 5;
myNodes = new const SMDS_MeshNode* [myNbNodes];
myNodes[0]=node1;
myNodes[1]=node2;
myNodes[2]=node3;
@ -86,7 +93,8 @@ SMDS_VolumeOfNodes::SMDS_VolumeOfNodes(
const SMDS_MeshNode * node5,
const SMDS_MeshNode * node6)
{
myNodes.resize(6);
myNbNodes = 6;
myNodes = new const SMDS_MeshNode* [myNbNodes];
myNodes[0]=node1;
myNodes[1]=node2;
myNodes[2]=node3;
@ -94,18 +102,30 @@ SMDS_VolumeOfNodes::SMDS_VolumeOfNodes(
myNodes[4]=node5;
myNodes[5]=node6;
}
bool SMDS_VolumeOfNodes::ChangeNodes(const SMDS_MeshNode* nodes[],
const int nbNodes)
{
if (nbNodes < 4 || nbNodes > 8 || nbNodes == 7)
return false;
myNodes.resize( nbNodes );
delete [] myNodes;
myNbNodes = nbNodes;
myNodes = new const SMDS_MeshNode* [myNbNodes];
for ( int i = 0; i < nbNodes; i++ )
myNodes[ i ] = nodes [ i ];
return true;
}
SMDS_VolumeOfNodes::~SMDS_VolumeOfNodes()
{
if (myNodes != NULL) {
delete [] myNodes;
myNodes = NULL;
}
}
//=======================================================================
//function : Print
//purpose :
@ -134,7 +154,7 @@ int SMDS_VolumeOfNodes::NbFaces() const
int SMDS_VolumeOfNodes::NbNodes() const
{
return myNodes.size();
return myNbNodes;
}
int SMDS_VolumeOfNodes::NbEdges() const
@ -152,15 +172,16 @@ int SMDS_VolumeOfNodes::NbEdges() const
class SMDS_VolumeOfNodes_MyIterator:public SMDS_ElemIterator
{
const vector<const SMDS_MeshNode*>& mySet;
const SMDS_MeshNode* const* mySet;
int myLength;
int index;
public:
SMDS_VolumeOfNodes_MyIterator(const vector<const SMDS_MeshNode*>& s):
mySet(s),index(0) {}
SMDS_VolumeOfNodes_MyIterator(const SMDS_MeshNode* const* s, int l):
mySet(s),myLength(l),index(0) {}
bool more()
{
return index<mySet.size();
return index<myLength;
}
const SMDS_MeshElement* next()
@ -178,7 +199,7 @@ SMDS_ElemIteratorPtr SMDS_VolumeOfNodes::
case SMDSAbs_Volume:
return SMDS_MeshElement::elementsIterator(SMDSAbs_Volume);
case SMDSAbs_Node:
return SMDS_ElemIteratorPtr(new SMDS_VolumeOfNodes_MyIterator(myNodes));
return SMDS_ElemIteratorPtr(new SMDS_VolumeOfNodes_MyIterator(myNodes,myNbNodes));
default:
MESSAGE("ERROR : Iterator not implemented");
return SMDS_ElemIteratorPtr((SMDS_ElemIterator*)NULL);

View File

@ -28,7 +28,6 @@
#define _SMDS_VolumeOfNodes_HeaderFile
#include "SMDS_MeshVolume.hxx"
#include <vector>
class SMDS_VolumeOfNodes:public SMDS_MeshVolume
@ -64,6 +63,7 @@ class SMDS_VolumeOfNodes:public SMDS_MeshVolume
const SMDS_MeshNode * node8);
bool ChangeNodes(const SMDS_MeshNode* nodes[],
const int nbNodes);
~SMDS_VolumeOfNodes();
void Print(std::ostream & OS) const;
int NbFaces() const;
@ -73,6 +73,7 @@ class SMDS_VolumeOfNodes:public SMDS_MeshVolume
protected:
SMDS_ElemIteratorPtr
elementsIterator(SMDSAbs_ElementType type) const;
std::vector<const SMDS_MeshNode *> myNodes;
const SMDS_MeshNode** myNodes;
int myNbNodes;
};
#endif