2016-03-18 22:10:20 +05:00
|
|
|
// Copyright (C) 2007-2016 CEA/DEN, EDF R&D, OPEN CASCADE
|
2009-02-17 10:27:49 +05:00
|
|
|
//
|
2012-08-09 16:03:55 +06:00
|
|
|
// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
|
|
|
|
// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
|
2009-02-17 10:27:49 +05:00
|
|
|
//
|
2012-08-09 16:03:55 +06:00
|
|
|
// 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
|
2014-02-20 18:25:37 +06:00
|
|
|
// version 2.1 of the License, or (at your option) any later version.
|
2009-02-17 10:27:49 +05:00
|
|
|
//
|
2012-08-09 16:03:55 +06:00
|
|
|
// 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.
|
2009-02-17 10:27:49 +05:00
|
|
|
//
|
2012-08-09 16:03:55 +06:00
|
|
|
// 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
|
2009-02-17 10:27:49 +05:00
|
|
|
//
|
2012-08-09 16:03:55 +06:00
|
|
|
// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
|
2009-02-17 10:27:49 +05:00
|
|
|
//
|
2012-08-09 16:03:55 +06:00
|
|
|
|
2003-07-10 15:49:12 +06:00
|
|
|
// SMESH SMDS : implementaion of Salome mesh data structure
|
|
|
|
//
|
2005-01-20 11:25:54 +05:00
|
|
|
#ifdef _MSC_VER
|
|
|
|
#pragma warning(disable:4786)
|
|
|
|
#endif
|
|
|
|
|
2003-09-03 23:30:36 +06:00
|
|
|
#include "SMDS_MeshElement.hxx"
|
|
|
|
#include "SMDS_MeshNode.hxx"
|
|
|
|
#include "SMDS_MeshEdge.hxx"
|
|
|
|
#include "SMDS_MeshFace.hxx"
|
|
|
|
#include "SMDS_MeshVolume.hxx"
|
|
|
|
#include "utilities.h"
|
2003-05-19 19:49:00 +06:00
|
|
|
|
2004-12-01 15:48:31 +05:00
|
|
|
using namespace std;
|
|
|
|
|
2012-08-09 16:03:55 +06:00
|
|
|
SMDS_MeshElement::SMDS_MeshElement(int ID)
|
|
|
|
{
|
|
|
|
init(ID);
|
|
|
|
}
|
|
|
|
|
|
|
|
SMDS_MeshElement::SMDS_MeshElement(int id, ShortType meshId, LongType shapeId)
|
|
|
|
{
|
|
|
|
init(id, meshId, shapeId);
|
|
|
|
}
|
|
|
|
|
|
|
|
void SMDS_MeshElement::init(int id, ShortType meshId, LongType shapeId )
|
2003-05-19 19:49:00 +06:00
|
|
|
{
|
2012-08-09 16:03:55 +06:00
|
|
|
myID = id;
|
|
|
|
myMeshId = meshId;
|
|
|
|
myShapeId = shapeId;
|
|
|
|
myIdInShape = -1;
|
2003-05-19 19:49:00 +06:00
|
|
|
}
|
|
|
|
|
2003-09-03 23:30:36 +06:00
|
|
|
void SMDS_MeshElement::Print(ostream & OS) const
|
2003-05-19 19:49:00 +06:00
|
|
|
{
|
2012-08-09 16:03:55 +06:00
|
|
|
OS << "dump of mesh element" << endl;
|
2003-05-19 19:49:00 +06:00
|
|
|
}
|
|
|
|
|
2003-09-03 23:30:36 +06:00
|
|
|
ostream & operator <<(ostream & OS, const SMDS_MeshElement * ME)
|
2003-05-19 19:49:00 +06:00
|
|
|
{
|
2012-08-09 16:03:55 +06:00
|
|
|
ME->Print(OS);
|
|
|
|
return OS;
|
2003-05-19 19:49:00 +06:00
|
|
|
}
|
|
|
|
|
2003-09-03 23:30:36 +06:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
/// Create an iterator which iterate on nodes owned by the element.
|
|
|
|
/// This method call elementsIterator().
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
2004-06-18 14:34:31 +06:00
|
|
|
SMDS_ElemIteratorPtr SMDS_MeshElement::nodesIterator() const
|
2003-05-19 19:49:00 +06:00
|
|
|
{
|
2012-08-09 16:03:55 +06:00
|
|
|
return elementsIterator(SMDSAbs_Node);
|
2003-05-19 19:49:00 +06:00
|
|
|
}
|
|
|
|
|
2003-09-03 23:30:36 +06:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
/// Create an iterator which iterate on edges linked with or owned by the element.
|
|
|
|
/// This method call elementsIterator().
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
2004-06-18 14:34:31 +06:00
|
|
|
SMDS_ElemIteratorPtr SMDS_MeshElement::edgesIterator() const
|
2003-05-19 19:49:00 +06:00
|
|
|
{
|
2012-08-09 16:03:55 +06:00
|
|
|
return elementsIterator(SMDSAbs_Edge);
|
2003-05-19 19:49:00 +06:00
|
|
|
}
|
|
|
|
|
2003-09-03 23:30:36 +06:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
/// Create an iterator which iterate on faces linked with or owned by the element.
|
|
|
|
/// This method call elementsIterator().
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
2004-06-18 14:34:31 +06:00
|
|
|
SMDS_ElemIteratorPtr SMDS_MeshElement::facesIterator() const
|
2003-05-19 19:49:00 +06:00
|
|
|
{
|
2012-08-09 16:03:55 +06:00
|
|
|
return elementsIterator(SMDSAbs_Face);
|
2003-05-19 19:49:00 +06:00
|
|
|
}
|
|
|
|
|
2003-09-03 23:30:36 +06:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
///Return The number of nodes owned by the current element
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
int SMDS_MeshElement::NbNodes() const
|
2003-05-19 19:49:00 +06:00
|
|
|
{
|
2012-08-09 16:03:55 +06:00
|
|
|
int nbnodes=0;
|
|
|
|
SMDS_ElemIteratorPtr it=nodesIterator();
|
|
|
|
while(it->more())
|
|
|
|
{
|
|
|
|
it->next();
|
|
|
|
nbnodes++;
|
|
|
|
}
|
|
|
|
return nbnodes;
|
2003-05-19 19:49:00 +06:00
|
|
|
}
|
|
|
|
|
2003-09-03 23:30:36 +06:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
///Return the number of edges owned by or linked with the current element
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
int SMDS_MeshElement::NbEdges() const
|
2003-05-19 19:49:00 +06:00
|
|
|
{
|
2012-08-09 16:03:55 +06:00
|
|
|
int nbedges=0;
|
|
|
|
SMDS_ElemIteratorPtr it=edgesIterator();
|
|
|
|
while(it->more())
|
|
|
|
{
|
|
|
|
it->next();
|
|
|
|
nbedges++;
|
|
|
|
}
|
|
|
|
return nbedges;
|
2003-05-19 19:49:00 +06:00
|
|
|
}
|
|
|
|
|
2003-09-03 23:30:36 +06:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
///Return the number of faces owned by or linked with the current element
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
int SMDS_MeshElement::NbFaces() const
|
2003-05-19 19:49:00 +06:00
|
|
|
{
|
2012-08-09 16:03:55 +06:00
|
|
|
int nbfaces=0;
|
|
|
|
SMDS_ElemIteratorPtr it=facesIterator();
|
|
|
|
while(it->more())
|
|
|
|
{
|
|
|
|
it->next();
|
|
|
|
nbfaces++;
|
|
|
|
}
|
|
|
|
return nbfaces;
|
2003-05-19 19:49:00 +06:00
|
|
|
}
|
|
|
|
|
2003-09-03 23:30:36 +06:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
2004-06-18 14:34:31 +06:00
|
|
|
///Create an iterator which iterate on elements linked with the current element.
|
2003-09-03 23:30:36 +06:00
|
|
|
///@param type The of elements on which you want to iterate
|
2004-06-18 14:34:31 +06:00
|
|
|
///@return A smart pointer to iterator, you are not to take care of freeing memory
|
2003-09-03 23:30:36 +06:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
2004-06-18 14:34:31 +06:00
|
|
|
class SMDS_MeshElement_MyIterator:public SMDS_ElemIterator
|
|
|
|
{
|
|
|
|
const SMDS_MeshElement * myElement;
|
|
|
|
bool myMore;
|
|
|
|
public:
|
|
|
|
SMDS_MeshElement_MyIterator(const SMDS_MeshElement * element):
|
|
|
|
myElement(element),myMore(true) {}
|
|
|
|
|
|
|
|
bool more()
|
|
|
|
{
|
|
|
|
return myMore;
|
|
|
|
}
|
|
|
|
|
|
|
|
const SMDS_MeshElement* next()
|
|
|
|
{
|
|
|
|
myMore=false;
|
2012-08-09 16:03:55 +06:00
|
|
|
return myElement;
|
|
|
|
}
|
2004-06-18 14:34:31 +06:00
|
|
|
};
|
2012-08-09 16:03:55 +06:00
|
|
|
|
2013-05-16 22:08:00 +06:00
|
|
|
SMDS_ElemIteratorPtr
|
|
|
|
SMDS_MeshElement::elementsIterator(SMDSAbs_ElementType type) const
|
|
|
|
{
|
|
|
|
/** @todo Check that iterator in the child classes return elements
|
|
|
|
in the same order for each different implementation (i.e: SMDS_VolumeOfNodes
|
|
|
|
and SMDS_VolumeOfFaces */
|
|
|
|
if(type==GetType())
|
|
|
|
return SMDS_ElemIteratorPtr(new SMDS_MeshElement_MyIterator(this));
|
|
|
|
else
|
|
|
|
{
|
|
|
|
MESSAGE("Iterator not implemented");
|
|
|
|
return SMDS_ElemIteratorPtr((SMDS_ElemIterator*)NULL);
|
|
|
|
}
|
2003-05-19 19:49:00 +06:00
|
|
|
}
|
|
|
|
|
2012-08-09 16:03:55 +06:00
|
|
|
//! virtual, redefined in vtkEdge, vtkFace and vtkVolume classes
|
2013-05-16 22:08:00 +06:00
|
|
|
SMDS_NodeIteratorPtr SMDS_MeshElement::nodesIteratorToUNV() const
|
2003-05-19 19:49:00 +06:00
|
|
|
{
|
2013-05-16 22:08:00 +06:00
|
|
|
return nodeIterator();
|
2012-08-09 16:03:55 +06:00
|
|
|
}
|
|
|
|
|
|
|
|
//! virtual, redefined in vtkEdge, vtkFace and vtkVolume classes
|
2013-05-16 22:08:00 +06:00
|
|
|
SMDS_NodeIteratorPtr SMDS_MeshElement::interlacedNodesIterator() const
|
|
|
|
{
|
|
|
|
return nodeIterator();
|
|
|
|
}
|
|
|
|
|
|
|
|
namespace
|
|
|
|
{
|
|
|
|
//=======================================================================
|
|
|
|
//class : _MyNodeIteratorFromElemIterator
|
|
|
|
//=======================================================================
|
|
|
|
class _MyNodeIteratorFromElemIterator : public SMDS_NodeIterator
|
|
|
|
{
|
|
|
|
SMDS_ElemIteratorPtr myItr;
|
|
|
|
public:
|
|
|
|
_MyNodeIteratorFromElemIterator(SMDS_ElemIteratorPtr elemItr):myItr( elemItr ) {}
|
|
|
|
bool more() { return myItr->more(); }
|
|
|
|
const SMDS_MeshNode* next() { return static_cast< const SMDS_MeshNode*>( myItr->next() ); }
|
|
|
|
};
|
|
|
|
//=======================================================================
|
|
|
|
//class : _MyElemIteratorFromNodeIterator
|
|
|
|
//=======================================================================
|
|
|
|
class _MyElemIteratorFromNodeIterator : public SMDS_ElemIterator
|
|
|
|
{
|
|
|
|
SMDS_NodeIteratorPtr myItr;
|
|
|
|
public:
|
|
|
|
_MyElemIteratorFromNodeIterator(SMDS_NodeIteratorPtr nodeItr): myItr( nodeItr ) {}
|
|
|
|
bool more() { return myItr->more(); }
|
|
|
|
const SMDS_MeshElement* next() { return myItr->next(); }
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2012-08-09 16:03:55 +06:00
|
|
|
SMDS_ElemIteratorPtr SMDS_MeshElement::interlacedNodesElemIterator() const
|
|
|
|
{
|
2013-05-16 22:08:00 +06:00
|
|
|
return SMDS_ElemIteratorPtr
|
|
|
|
( new _MyElemIteratorFromNodeIterator( interlacedNodesIterator() ));
|
|
|
|
}
|
|
|
|
|
|
|
|
SMDS_NodeIteratorPtr SMDS_MeshElement::nodeIterator() const
|
|
|
|
{
|
|
|
|
return SMDS_NodeIteratorPtr
|
|
|
|
( new _MyNodeIteratorFromElemIterator( nodesIterator() ));
|
2003-05-19 19:49:00 +06:00
|
|
|
}
|
|
|
|
|
2003-09-03 23:30:36 +06:00
|
|
|
bool operator<(const SMDS_MeshElement& e1, const SMDS_MeshElement& e2)
|
2003-05-19 19:49:00 +06:00
|
|
|
{
|
2012-08-09 16:03:55 +06:00
|
|
|
if(e1.GetType()!=e2.GetType()) return false;
|
|
|
|
switch(e1.GetType())
|
|
|
|
{
|
|
|
|
case SMDSAbs_Node:
|
|
|
|
return static_cast<const SMDS_MeshNode &>(e1) <
|
|
|
|
static_cast<const SMDS_MeshNode &>(e2);
|
2003-09-03 23:30:36 +06:00
|
|
|
|
2012-08-09 16:03:55 +06:00
|
|
|
case SMDSAbs_Edge:
|
|
|
|
return static_cast<const SMDS_MeshEdge &>(e1) <
|
|
|
|
static_cast<const SMDS_MeshEdge &>(e2);
|
2003-09-03 23:30:36 +06:00
|
|
|
|
2012-08-09 16:03:55 +06:00
|
|
|
case SMDSAbs_Face:
|
|
|
|
return static_cast<const SMDS_MeshFace &>(e1) <
|
|
|
|
static_cast<const SMDS_MeshFace &>(e2);
|
2003-09-03 23:30:36 +06:00
|
|
|
|
2012-08-09 16:03:55 +06:00
|
|
|
case SMDSAbs_Volume:
|
|
|
|
return static_cast<const SMDS_MeshVolume &>(e1) <
|
|
|
|
static_cast<const SMDS_MeshVolume &>(e2);
|
2003-09-03 23:30:36 +06:00
|
|
|
|
2012-08-09 16:03:55 +06:00
|
|
|
default : MESSAGE("Internal Error");
|
|
|
|
}
|
2004-12-01 15:48:31 +05:00
|
|
|
return false;
|
2003-05-19 19:49:00 +06:00
|
|
|
}
|
2006-03-13 20:29:49 +05:00
|
|
|
|
|
|
|
bool SMDS_MeshElement::IsValidIndex(const int ind) const
|
|
|
|
{
|
|
|
|
return ( ind>-1 && ind<NbNodes() );
|
|
|
|
}
|
|
|
|
|
|
|
|
const SMDS_MeshNode* SMDS_MeshElement::GetNode(const int ind) const
|
|
|
|
{
|
2012-08-09 16:03:55 +06:00
|
|
|
if ( ind >= 0 ) {
|
|
|
|
SMDS_ElemIteratorPtr it = nodesIterator();
|
|
|
|
for ( int i = 0; i < ind; ++i )
|
|
|
|
it->next();
|
|
|
|
if ( it->more() )
|
|
|
|
return static_cast<const SMDS_MeshNode*> (it->next());
|
|
|
|
}
|
2006-03-13 20:29:49 +05:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool SMDS_MeshElement::IsQuadratic() const
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool SMDS_MeshElement::IsMediumNode(const SMDS_MeshNode* node) const
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
2006-05-06 14:51:48 +06:00
|
|
|
|
2012-08-09 16:03:55 +06:00
|
|
|
//================================================================================
|
|
|
|
/*!
|
|
|
|
* \brief Return number of nodes excluding medium ones
|
|
|
|
*/
|
|
|
|
//================================================================================
|
|
|
|
|
|
|
|
int SMDS_MeshElement::NbCornerNodes() const
|
|
|
|
{
|
|
|
|
return IsQuadratic() ? NbNodes() - NbEdges() : NbNodes();
|
|
|
|
}
|
|
|
|
|
2006-05-06 14:51:48 +06:00
|
|
|
//================================================================================
|
|
|
|
/*!
|
|
|
|
* \brief Check if a node belongs to the element
|
|
|
|
* \param node - the node to check
|
|
|
|
* \retval int - node index within the element, -1 if not found
|
|
|
|
*/
|
|
|
|
//================================================================================
|
|
|
|
|
|
|
|
int SMDS_MeshElement::GetNodeIndex( const SMDS_MeshNode* node ) const
|
|
|
|
{
|
|
|
|
SMDS_ElemIteratorPtr nIt = nodesIterator();
|
|
|
|
for ( int i = 0; nIt->more(); ++i )
|
|
|
|
if ( nIt->next() == node )
|
|
|
|
return i;
|
|
|
|
return -1;
|
|
|
|
}
|