2003-07-10 15:49:12 +06:00
|
|
|
// SMESH SMDS : implementaion of Salome mesh data structure
|
|
|
|
//
|
|
|
|
// Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
|
|
|
|
// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
|
|
|
|
//
|
|
|
|
// This library is free software; you can redistribute it and/or
|
|
|
|
// modify it under the terms of the GNU Lesser General Public
|
|
|
|
// License as published by the Free Software Foundation; either
|
|
|
|
// version 2.1 of the License.
|
|
|
|
//
|
|
|
|
// This library is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
// Lesser General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU Lesser General Public
|
|
|
|
// License along with this library; if not, write to the Free Software
|
|
|
|
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
//
|
2006-06-01 17:39:17 +06:00
|
|
|
// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
|
2003-05-19 19:49:00 +06:00
|
|
|
|
2005-01-20 11:25:54 +05:00
|
|
|
#ifdef _MSC_VER
|
|
|
|
#pragma warning(disable:4786)
|
|
|
|
#endif
|
2003-05-19 19:49:00 +06:00
|
|
|
|
2003-09-03 23:30:36 +06:00
|
|
|
#include "SMDS_MeshNode.hxx"
|
|
|
|
#include "SMDS_SpacePosition.hxx"
|
|
|
|
#include "SMDS_IteratorOfElements.hxx"
|
2003-05-19 19:49:00 +06:00
|
|
|
|
2004-12-01 15:48:31 +05:00
|
|
|
using namespace std;
|
|
|
|
|
2003-05-19 19:49:00 +06:00
|
|
|
//=======================================================================
|
|
|
|
//function : SMDS_MeshNode
|
|
|
|
//purpose :
|
|
|
|
//=======================================================================
|
|
|
|
|
2003-09-03 23:30:36 +06:00
|
|
|
SMDS_MeshNode::SMDS_MeshNode(double x, double y, double z):
|
|
|
|
myX(x), myY(y), myZ(z),
|
|
|
|
myPosition(SMDS_SpacePosition::originSpacePosition())
|
2003-05-19 19:49:00 +06:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
//=======================================================================
|
|
|
|
//function : RemoveInverseElement
|
|
|
|
//purpose :
|
|
|
|
//=======================================================================
|
|
|
|
|
2003-09-03 23:30:36 +06:00
|
|
|
void SMDS_MeshNode::RemoveInverseElement(const SMDS_MeshElement * parent)
|
2003-05-19 19:49:00 +06:00
|
|
|
{
|
2005-01-20 11:25:54 +05:00
|
|
|
NCollection_List<const SMDS_MeshElement*>::Iterator it(myInverseElements);
|
|
|
|
while (it.More()) {
|
|
|
|
const SMDS_MeshElement* elem = it.Value();
|
|
|
|
if (elem == parent)
|
|
|
|
myInverseElements.Remove(it);
|
|
|
|
else
|
|
|
|
it.Next();
|
|
|
|
}
|
2003-05-19 19:49:00 +06:00
|
|
|
}
|
|
|
|
|
|
|
|
//=======================================================================
|
|
|
|
//function : Print
|
|
|
|
//purpose :
|
|
|
|
//=======================================================================
|
|
|
|
|
2003-09-03 23:30:36 +06:00
|
|
|
void SMDS_MeshNode::Print(ostream & OS) const
|
2003-05-19 19:49:00 +06:00
|
|
|
{
|
2003-09-03 23:30:36 +06:00
|
|
|
OS << "Node <" << GetID() << "> : X = " << myX << " Y = "
|
|
|
|
<< myY << " Z = " << myZ << endl;
|
2003-05-19 19:49:00 +06:00
|
|
|
}
|
|
|
|
|
|
|
|
//=======================================================================
|
|
|
|
//function : SetPosition
|
|
|
|
//purpose :
|
|
|
|
//=======================================================================
|
|
|
|
|
2004-06-18 14:34:31 +06:00
|
|
|
void SMDS_MeshNode::SetPosition(const SMDS_PositionPtr& aPos)
|
2003-05-19 19:49:00 +06:00
|
|
|
{
|
2003-09-03 23:30:36 +06:00
|
|
|
myPosition = aPos;
|
2003-05-19 19:49:00 +06:00
|
|
|
}
|
|
|
|
|
|
|
|
//=======================================================================
|
|
|
|
//function : GetPosition
|
|
|
|
//purpose :
|
|
|
|
//=======================================================================
|
|
|
|
|
2004-06-18 14:34:31 +06:00
|
|
|
const SMDS_PositionPtr& SMDS_MeshNode::GetPosition() const
|
2003-09-03 23:30:36 +06:00
|
|
|
{
|
|
|
|
return myPosition;
|
|
|
|
}
|
|
|
|
|
2007-04-18 21:44:59 +06:00
|
|
|
//=======================================================================
|
|
|
|
/*!
|
|
|
|
* \brief Iterator on list of elements
|
|
|
|
*/
|
|
|
|
//=======================================================================
|
|
|
|
|
2004-06-18 14:34:31 +06:00
|
|
|
class SMDS_MeshNode_MyInvIterator:public SMDS_ElemIterator
|
2003-09-03 23:30:36 +06:00
|
|
|
{
|
2005-01-20 11:25:54 +05:00
|
|
|
NCollection_List<const SMDS_MeshElement*>::Iterator myIterator;
|
2007-04-18 21:44:59 +06:00
|
|
|
SMDSAbs_ElementType myType;
|
2004-06-18 14:34:31 +06:00
|
|
|
public:
|
2007-04-18 21:44:59 +06:00
|
|
|
SMDS_MeshNode_MyInvIterator(const NCollection_List<const SMDS_MeshElement*>& s,
|
|
|
|
SMDSAbs_ElementType type):
|
|
|
|
myIterator(s), myType(type)
|
2005-01-20 11:25:54 +05:00
|
|
|
{}
|
2004-06-18 14:34:31 +06:00
|
|
|
|
|
|
|
bool more()
|
|
|
|
{
|
2007-04-18 21:44:59 +06:00
|
|
|
if ( myType != SMDSAbs_All ) {
|
|
|
|
while ( myIterator.More() && myIterator.Value()->GetType() != myType)
|
|
|
|
myIterator.Next();
|
|
|
|
}
|
2005-01-20 11:25:54 +05:00
|
|
|
return myIterator.More() != Standard_False;
|
2004-06-18 14:34:31 +06:00
|
|
|
}
|
|
|
|
|
|
|
|
const SMDS_MeshElement* next()
|
|
|
|
{
|
2005-01-20 11:25:54 +05:00
|
|
|
const SMDS_MeshElement* current=myIterator.Value();
|
|
|
|
myIterator.Next();
|
|
|
|
return current;
|
2004-06-18 14:34:31 +06:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
SMDS_ElemIteratorPtr SMDS_MeshNode::
|
2007-04-18 21:44:59 +06:00
|
|
|
GetInverseElementIterator(SMDSAbs_ElementType type) const
|
2003-09-03 23:30:36 +06:00
|
|
|
{
|
2007-04-18 21:44:59 +06:00
|
|
|
return SMDS_ElemIteratorPtr(new SMDS_MeshNode_MyInvIterator(myInverseElements,type));
|
2003-09-03 23:30:36 +06:00
|
|
|
}
|
|
|
|
|
2004-06-18 14:34:31 +06:00
|
|
|
// Same as GetInverseElementIterator but the create iterator only return
|
|
|
|
// wanted type elements.
|
|
|
|
class SMDS_MeshNode_MyIterator:public SMDS_ElemIterator
|
|
|
|
{
|
2005-01-20 11:25:54 +05:00
|
|
|
NCollection_List<const SMDS_MeshElement*> mySet;
|
|
|
|
NCollection_List<const SMDS_MeshElement*>::Iterator myIterator;
|
2004-06-18 14:34:31 +06:00
|
|
|
public:
|
|
|
|
SMDS_MeshNode_MyIterator(SMDSAbs_ElementType type,
|
2005-01-20 11:25:54 +05:00
|
|
|
const NCollection_List<const SMDS_MeshElement*>& s)
|
2004-06-18 14:34:31 +06:00
|
|
|
{
|
|
|
|
const SMDS_MeshElement * e;
|
|
|
|
bool toInsert;
|
2005-01-20 11:25:54 +05:00
|
|
|
NCollection_List<const SMDS_MeshElement*>::Iterator it(s);
|
|
|
|
for(; it.More(); it.Next())
|
2004-06-18 14:34:31 +06:00
|
|
|
{
|
2005-01-20 11:25:54 +05:00
|
|
|
e=it.Value();
|
2004-06-18 14:34:31 +06:00
|
|
|
switch(type)
|
|
|
|
{
|
|
|
|
case SMDSAbs_Edge: toInsert=true; break;
|
|
|
|
case SMDSAbs_Face: toInsert=(e->GetType()!=SMDSAbs_Edge); break;
|
|
|
|
case SMDSAbs_Volume: toInsert=(e->GetType()==SMDSAbs_Volume); break;
|
|
|
|
}
|
2005-01-20 11:25:54 +05:00
|
|
|
if(toInsert) mySet.Append(e);
|
2004-06-18 14:34:31 +06:00
|
|
|
}
|
2005-01-20 11:25:54 +05:00
|
|
|
myIterator.Init(mySet);
|
2004-06-18 14:34:31 +06:00
|
|
|
}
|
|
|
|
|
|
|
|
bool more()
|
|
|
|
{
|
2005-01-20 11:25:54 +05:00
|
|
|
return myIterator.More() != Standard_False;
|
2004-06-18 14:34:31 +06:00
|
|
|
}
|
|
|
|
|
|
|
|
const SMDS_MeshElement* next()
|
|
|
|
{
|
2005-01-20 11:25:54 +05:00
|
|
|
const SMDS_MeshElement* current=myIterator.Value();
|
|
|
|
myIterator.Next();
|
2004-06-18 14:34:31 +06:00
|
|
|
return current;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
SMDS_ElemIteratorPtr SMDS_MeshNode::
|
2003-09-03 23:30:36 +06:00
|
|
|
elementsIterator(SMDSAbs_ElementType type) const
|
|
|
|
{
|
2004-06-18 14:34:31 +06:00
|
|
|
if(type==SMDSAbs_Node)
|
|
|
|
return SMDS_MeshElement::elementsIterator(SMDSAbs_Node);
|
|
|
|
else
|
|
|
|
return SMDS_ElemIteratorPtr
|
|
|
|
(new SMDS_IteratorOfElements
|
|
|
|
(this,type,
|
|
|
|
SMDS_ElemIteratorPtr(new SMDS_MeshNode_MyIterator(type, myInverseElements))));
|
2003-09-03 23:30:36 +06:00
|
|
|
}
|
|
|
|
|
|
|
|
int SMDS_MeshNode::NbNodes() const
|
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
double SMDS_MeshNode::X() const
|
|
|
|
{
|
|
|
|
return myX;
|
|
|
|
}
|
|
|
|
|
|
|
|
double SMDS_MeshNode::Y() const
|
|
|
|
{
|
|
|
|
return myY;
|
|
|
|
}
|
|
|
|
|
|
|
|
double SMDS_MeshNode::Z() const
|
|
|
|
{
|
|
|
|
return myZ;
|
|
|
|
}
|
|
|
|
|
|
|
|
void SMDS_MeshNode::setXYZ(double x, double y, double z)
|
|
|
|
{
|
|
|
|
myX=x;
|
|
|
|
myY=y;
|
|
|
|
myZ=z;
|
|
|
|
}
|
|
|
|
|
|
|
|
SMDSAbs_ElementType SMDS_MeshNode::GetType() const
|
|
|
|
{
|
|
|
|
return SMDSAbs_Node;
|
|
|
|
}
|
|
|
|
|
|
|
|
//=======================================================================
|
|
|
|
//function : AddInverseElement
|
|
|
|
//purpose :
|
|
|
|
//=======================================================================
|
|
|
|
void SMDS_MeshNode::AddInverseElement(const SMDS_MeshElement* ME)
|
|
|
|
{
|
2005-01-20 11:25:54 +05:00
|
|
|
NCollection_List<const SMDS_MeshElement*>::Iterator it(myInverseElements);
|
|
|
|
for (; it.More(); it.Next()) {
|
|
|
|
const SMDS_MeshElement* elem = it.Value();
|
|
|
|
if (elem == ME)
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
myInverseElements.Append(ME);
|
2003-09-03 23:30:36 +06:00
|
|
|
}
|
|
|
|
|
|
|
|
//=======================================================================
|
|
|
|
//function : ClearInverseElements
|
|
|
|
//purpose :
|
|
|
|
//=======================================================================
|
|
|
|
void SMDS_MeshNode::ClearInverseElements()
|
|
|
|
{
|
2005-01-20 11:25:54 +05:00
|
|
|
myInverseElements.Clear();
|
2003-09-03 23:30:36 +06:00
|
|
|
}
|
|
|
|
|
|
|
|
bool SMDS_MeshNode::emptyInverseElements()
|
|
|
|
{
|
2005-01-20 11:25:54 +05:00
|
|
|
return myInverseElements.IsEmpty() != Standard_False;
|
2003-09-03 23:30:36 +06:00
|
|
|
}
|
|
|
|
|
2007-04-18 21:44:59 +06:00
|
|
|
//================================================================================
|
|
|
|
/*!
|
|
|
|
* \brief Count inverse elements of given type
|
|
|
|
*/
|
|
|
|
//================================================================================
|
|
|
|
|
2008-07-22 15:10:35 +06:00
|
|
|
int SMDS_MeshNode::NbInverseElements(SMDSAbs_ElementType type) const
|
2007-04-18 21:44:59 +06:00
|
|
|
{
|
|
|
|
if ( type == SMDSAbs_All )
|
|
|
|
return myInverseElements.Extent();
|
|
|
|
int nb = 0;
|
|
|
|
NCollection_List<const SMDS_MeshElement*>::Iterator it( myInverseElements );
|
|
|
|
for ( ; it.More(); it.Next() )
|
|
|
|
if ( it.Value()->GetType() == type )
|
|
|
|
nb++;
|
|
|
|
return nb;
|
|
|
|
}
|
|
|
|
|
2003-09-03 23:30:36 +06:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
/// To be used with STL set
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
bool operator<(const SMDS_MeshNode& e1, const SMDS_MeshNode& e2)
|
2003-05-19 19:49:00 +06:00
|
|
|
{
|
2003-09-03 23:30:36 +06:00
|
|
|
return e1.GetID()<e2.GetID();
|
|
|
|
/*if(e1.myX<e2.myX) return true;
|
|
|
|
else if(e1.myX==e2.myX)
|
|
|
|
{
|
|
|
|
if(e1.myY<e2.myY) return true;
|
|
|
|
else if(e1.myY==e2.myY) return (e1.myZ<e2.myZ);
|
|
|
|
else return false;
|
|
|
|
}
|
|
|
|
else return false;*/
|
2003-05-19 19:49:00 +06:00
|
|
|
}
|
|
|
|
|