smesh/src/SMDS/SMDS_MeshNode.cxx

321 lines
9.1 KiB
C++
Raw Normal View History

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
// SMESH SMDS : implementation of Salome mesh data structure
2003-07-10 15:49:12 +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"
2012-08-09 16:03:55 +06:00
#include "SMDS_Mesh.hxx"
#include <vtkUnstructuredGrid.h>
#include "utilities.h"
#include "Utils_SALOME_Exception.hxx"
#include <cassert>
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
int SMDS_MeshNode::nbNodes =0;
2003-05-19 19:49:00 +06:00
//=======================================================================
//function : SMDS_MeshNode
//purpose :
2003-05-19 19:49:00 +06:00
//=======================================================================
2012-08-09 16:03:55 +06:00
SMDS_MeshNode::SMDS_MeshNode() :
SMDS_MeshElement(-1, -1, 0),
myPosition(SMDS_SpacePosition::originSpacePosition())
{
nbNodes++;
}
SMDS_MeshNode::SMDS_MeshNode(int id, int meshId, int shapeId, double x, double y, double z):
SMDS_MeshElement(id, meshId, shapeId),
myPosition(SMDS_SpacePosition::originSpacePosition())
{
nbNodes++;
init(id, meshId, shapeId, x, y ,z);
}
void SMDS_MeshNode::init(int id, int meshId, int shapeId, double x, double y, double z)
{
SMDS_MeshElement::init(id, meshId, shapeId);
myVtkID = id - 1;
2012-08-09 16:03:55 +06:00
assert(myVtkID >= 0);
SMDS_UnstructuredGrid * grid = SMDS_Mesh::_meshList[myMeshId]->getGrid();
2012-08-09 16:03:55 +06:00
vtkPoints *points = grid->GetPoints();
points->InsertPoint(myVtkID, x, y, z);
if ( grid->HasLinks() )
grid->GetLinks()->ResizeForPoint( myVtkID );
2012-08-09 16:03:55 +06:00
}
2003-05-19 19:49:00 +06:00
2012-08-09 16:03:55 +06:00
SMDS_MeshNode::~SMDS_MeshNode()
2003-05-19 19:49:00 +06:00
{
2012-08-09 16:03:55 +06:00
nbNodes--;
if ( myPosition && myPosition != SMDS_SpacePosition::originSpacePosition() )
delete myPosition, myPosition = 0;
2003-05-19 19:49:00 +06:00
}
//=======================================================================
//function : RemoveInverseElement
//purpose :
2003-05-19 19:49:00 +06:00
//=======================================================================
void SMDS_MeshNode::RemoveInverseElement(const SMDS_MeshElement * elem)
2003-05-19 19:49:00 +06:00
{
if ( SMDS_Mesh::_meshList[myMeshId]->getGrid()->HasLinks() )
SMDS_Mesh::_meshList[myMeshId]->getGrid()->RemoveReferenceToCell(myVtkID, elem->getVtkId());
2003-05-19 19:49:00 +06:00
}
//=======================================================================
//function : Print
//purpose :
2003-05-19 19:49:00 +06:00
//=======================================================================
2003-09-03 23:30:36 +06:00
void SMDS_MeshNode::Print(ostream & OS) const
2003-05-19 19:49:00 +06:00
{
OS << "Node <" << myID << "> : X = " << X() << " Y = "
<< Y() << " Z = " << Z() << endl;
2003-05-19 19:49:00 +06:00
}
//=======================================================================
//function : SetPosition
//purpose :
2003-05-19 19:49:00 +06:00
//=======================================================================
2004-06-18 14:34:31 +06:00
void SMDS_MeshNode::SetPosition(const SMDS_PositionPtr& aPos)
2003-05-19 19:49:00 +06:00
{
2012-08-09 16:03:55 +06:00
if ( myPosition &&
myPosition != SMDS_SpacePosition::originSpacePosition() &&
myPosition != aPos )
delete myPosition;
myPosition = aPos;
2003-05-19 19:49:00 +06:00
}
//=======================================================================
//function : GetPosition
//purpose :
2003-05-19 19:49:00 +06:00
//=======================================================================
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;
2003-09-03 23:30:36 +06:00
}
//=======================================================================
/*!
* \brief Iterator on list of elements
*/
//=======================================================================
2012-08-09 16:03:55 +06:00
class SMDS_MeshNode_MyInvIterator: public SMDS_ElemIterator
2003-09-03 23:30:36 +06:00
{
2012-08-09 16:03:55 +06:00
private:
SMDS_Mesh* myMesh;
vtkIdType* myCells;
int myNcells;
SMDSAbs_ElementType myType;
int iter;
vector<vtkIdType> cellList;
public:
SMDS_MeshNode_MyInvIterator(SMDS_Mesh *mesh, vtkIdType* cells, int ncells, SMDSAbs_ElementType type) :
myMesh(mesh), myCells(cells), myNcells(ncells), myType(type), iter(0)
{
if ( ncells )
{
cellList.reserve( ncells );
if (type == SMDSAbs_All)
{
cellList.assign( cells, cells + ncells );
}
else
2012-08-09 16:03:55 +06:00
{
for (int i = 0; i < ncells; i++)
{
int vtkId = cells[i];
int smdsId = myMesh->fromVtkToSmds(vtkId);
const SMDS_MeshElement* elem = myMesh->FindElement(smdsId);
if (elem->GetType() == type)
{
cellList.push_back(vtkId);
}
}
2012-08-09 16:03:55 +06:00
}
myCells = cellList.empty() ? 0 : &cellList[0];
myNcells = cellList.size();
}
2012-08-09 16:03:55 +06:00
}
2004-06-18 14:34:31 +06:00
bool more()
{
2012-08-09 16:03:55 +06:00
return (iter < myNcells);
2004-06-18 14:34:31 +06:00
}
const SMDS_MeshElement* next()
{
2012-08-09 16:03:55 +06:00
int vtkId = myCells[iter];
int smdsId = myMesh->fromVtkToSmds(vtkId);
const SMDS_MeshElement* elem = myMesh->FindElement(smdsId);
if (!elem)
{
MESSAGE("SMDS_MeshNode_MyInvIterator problem Null element");
throw SALOME_Exception("SMDS_MeshNode_MyInvIterator problem Null element");
}
2012-08-09 16:03:55 +06:00
iter++;
return elem;
}
2004-06-18 14:34:31 +06:00
};
SMDS_ElemIteratorPtr SMDS_MeshNode::GetInverseElementIterator(SMDSAbs_ElementType type) const
2003-09-03 23:30:36 +06:00
{
if ( SMDS_Mesh::_meshList[myMeshId]->NbElements() > 0 ) // avoid building links
2004-06-18 14:34:31 +06:00
{
vtkCellLinks::Link& l = SMDS_Mesh::_meshList[myMeshId]->getGrid()->GetLinks()->GetLink(myVtkID);
return SMDS_ElemIteratorPtr(new SMDS_MeshNode_MyInvIterator(SMDS_Mesh::_meshList[myMeshId], l.cells, l.ncells, type));
2004-06-18 14:34:31 +06:00
}
else
2004-06-18 14:34:31 +06:00
{
return SMDS_ElemIteratorPtr(new SMDS_MeshNode_MyInvIterator(SMDS_Mesh::_meshList[myMeshId], 0, 0, type));
2004-06-18 14:34:31 +06:00
}
}
2004-06-18 14:34:31 +06:00
SMDS_ElemIteratorPtr SMDS_MeshNode::elementsIterator(SMDSAbs_ElementType type) const
2003-09-03 23:30:36 +06:00
{
if ( type == SMDSAbs_Node )
return SMDS_MeshElement::elementsIterator( SMDSAbs_Node );
2004-06-18 14:34:31 +06:00
else
return GetInverseElementIterator( type );
2003-09-03 23:30:36 +06:00
}
int SMDS_MeshNode::NbNodes() const
{
return 1;
2012-08-09 16:03:55 +06:00
}
double* SMDS_MeshNode::getCoord() const
{
return SMDS_Mesh::_meshList[myMeshId]->getGrid()->GetPoint(myVtkID);
2003-09-03 23:30:36 +06:00
}
double SMDS_MeshNode::X() const
{
2012-08-09 16:03:55 +06:00
double *coord = getCoord();
return coord[0];
2003-09-03 23:30:36 +06:00
}
double SMDS_MeshNode::Y() const
{
2012-08-09 16:03:55 +06:00
double *coord = getCoord();
return coord[1];
2003-09-03 23:30:36 +06:00
}
double SMDS_MeshNode::Z() const
{
2012-08-09 16:03:55 +06:00
double *coord = getCoord();
return coord[2];
2003-09-03 23:30:36 +06:00
}
2012-08-09 16:03:55 +06:00
//================================================================================
/*!
* \brief thread safe getting coords
*/
//================================================================================
2012-08-09 16:03:55 +06:00
void SMDS_MeshNode::GetXYZ(double xyz[3]) const
{
return SMDS_Mesh::_meshList[myMeshId]->getGrid()->GetPoint(myVtkID,xyz);
}
//================================================================================
2003-09-03 23:30:36 +06:00
void SMDS_MeshNode::setXYZ(double x, double y, double z)
{
2012-08-09 16:03:55 +06:00
SMDS_Mesh *mesh = SMDS_Mesh::_meshList[myMeshId];
vtkPoints *points = mesh->getGrid()->GetPoints();
points->InsertPoint(myVtkID, x, y, z);
mesh->adjustBoundingBox(x, y, z);
mesh->setMyModified();
2003-09-03 23:30:36 +06:00
}
SMDSAbs_ElementType SMDS_MeshNode::GetType() const
{
return SMDSAbs_Node;
2012-08-09 16:03:55 +06:00
}
vtkIdType SMDS_MeshNode::GetVtkType() const
{
return VTK_VERTEX;
2003-09-03 23:30:36 +06:00
}
//=======================================================================
//function : AddInverseElement
//purpose :
//=======================================================================
void SMDS_MeshNode::AddInverseElement(const SMDS_MeshElement* ME)
{
2012-08-09 16:03:55 +06:00
SMDS_UnstructuredGrid* grid = SMDS_Mesh::_meshList[myMeshId]->getGrid();
if ( grid->HasLinks() )
{
vtkCellLinks *Links = grid->GetLinks();
Links->ResizeCellList(myVtkID, 1);
Links->AddCellReference(ME->getVtkId(), myVtkID);
}
2003-09-03 23:30:36 +06:00
}
//=======================================================================
//function : ClearInverseElements
//purpose :
//=======================================================================
void SMDS_MeshNode::ClearInverseElements()
{
2012-08-09 16:03:55 +06:00
SMDS_Mesh::_meshList[myMeshId]->getGrid()->ResizeCellList(myVtkID, 0);
2003-09-03 23:30:36 +06:00
}
//================================================================================
/*!
* \brief Count inverse elements of given type
*/
//================================================================================
2009-02-17 10:27:49 +05:00
int SMDS_MeshNode::NbInverseElements(SMDSAbs_ElementType type) const
{
int nb = 0;
if ( SMDS_Mesh::_meshList[myMeshId]->NbElements() > 0 ) // avoid building links
{
vtkCellLinks::Link& l = SMDS_Mesh::_meshList[myMeshId]->getGrid()->GetLinks()->GetLink(myVtkID);
if ( type == SMDSAbs_All )
return l.ncells;
SMDS_Mesh *mesh = SMDS_Mesh::_meshList[myMeshId];
for ( int i = 0; i < l.ncells; i++ )
{
const SMDS_MeshElement* elem = mesh->FindElement( mesh->fromVtkToSmds( l.cells[i] ));
nb += ( elem->GetType() == type );
}
}
return nb;
2003-05-19 19:49:00 +06:00
}