smesh/src/SMDS/SMDS_MeshElementIDFactory.cxx

184 lines
5.5 KiB
C++
Raw Normal View History

2015-02-13 13:38:35 +05:00
// Copyright (C) 2007-2015 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.
2003-07-10 15:49:12 +06: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.
2003-07-10 15:49:12 +06: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
2003-07-10 15:49:12 +06:00
//
2012-08-09 16:03:55 +06:00
// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
2003-07-10 15:49:12 +06:00
//
2012-08-09 16:03:55 +06:00
2009-02-17 10:27:49 +05:00
// SMESH SMDS : implementaion of Salome mesh data structure
2003-07-10 15:49:12 +06:00
// File : SMDS_MeshElementIDFactory.cxx
// Author : Jean-Michel BOULCOURT
// Module : SMESH
2009-02-17 10:27:49 +05:00
//
2005-01-20 11:25:54 +05:00
#ifdef _MSC_VER
#pragma warning(disable:4786)
#endif
2003-09-03 23:29:04 +06:00
#include "SMDS_MeshElementIDFactory.hxx"
#include "SMDS_MeshElement.hxx"
2012-08-09 16:03:55 +06:00
#include "SMDS_Mesh.hxx"
#include "utilities.h"
#include "SMDS_UnstructuredGrid.hxx"
#include <vtkCellType.h>
#include <climits>
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_MeshElementIDFactory
//purpose :
//=======================================================================
2005-01-20 11:25:54 +05:00
SMDS_MeshElementIDFactory::SMDS_MeshElementIDFactory():
2012-08-09 16:03:55 +06:00
SMDS_MeshNodeIDFactory()
{
}
int SMDS_MeshElementIDFactory::SetInVtkGrid(SMDS_MeshElement * elem)
2003-09-03 23:29:04 +06:00
{
2012-08-09 16:03:55 +06:00
// --- retrieve nodes ID
SMDS_MeshCell *cell = dynamic_cast<SMDS_MeshCell*>(elem);
assert(cell);
vector<vtkIdType> nodeIds;
SMDS_ElemIteratorPtr it = elem->nodesIterator();
while(it->more())
{
int nodeId = (static_cast<const SMDS_MeshNode*>(it->next()))->getVtkId();
MESSAGE(" node in cell " << cell->getVtkId() << " : " << nodeId)
nodeIds.push_back(nodeId);
}
// --- insert cell in vtkUnstructuredGrid
vtkUnstructuredGrid * grid = myMesh->getGrid();
//int locType = elem->GetType();
int typ = VTK_VERTEX;//GetVtkCellType(locType);
int cellId = grid->InsertNextLinkedCell(typ, nodeIds.size(), &nodeIds[0]);
cell->setVtkId(cellId);
//MESSAGE("SMDS_MeshElementIDFactory::SetInVtkGrid " << cellId);
return cellId;
2003-09-03 23:29:04 +06:00
}
2003-05-19 19:49:00 +06:00
2003-09-03 23:29:04 +06:00
//=======================================================================
//function : BindID
//purpose :
//=======================================================================
2012-08-09 16:03:55 +06:00
2003-09-03 23:29:04 +06:00
bool SMDS_MeshElementIDFactory::BindID(int ID, SMDS_MeshElement * elem)
2003-05-19 19:49:00 +06:00
{
2012-08-09 16:03:55 +06:00
MESSAGE("SMDS_MeshElementIDFactory::BindID " << ID);
SetInVtkGrid(elem);
return myMesh->registerElement(ID, elem);
2003-05-19 19:49:00 +06:00
}
2003-09-03 23:29:04 +06:00
//=======================================================================
//function : MeshElement
//purpose :
//=======================================================================
SMDS_MeshElement* SMDS_MeshElementIDFactory::MeshElement(int ID)
{
2012-08-09 16:03:55 +06:00
if ((ID<1) || (ID>=myMesh->myCells.size()))
2005-01-20 11:25:54 +05:00
return NULL;
2012-08-09 16:03:55 +06:00
const SMDS_MeshElement* elem = GetMesh()->FindElement(ID);
return (SMDS_MeshElement*)(elem);
2003-09-03 23:29:04 +06:00
}
2004-06-18 14:34:31 +06:00
//=======================================================================
//function : GetFreeID
//purpose :
//=======================================================================
2012-08-09 16:03:55 +06:00
2004-06-18 14:34:31 +06:00
int SMDS_MeshElementIDFactory::GetFreeID()
{
int ID;
do {
ID = SMDS_MeshIDFactory::GetFreeID();
2012-08-09 16:03:55 +06:00
} while ( MeshElement( ID ));
2004-06-18 14:34:31 +06:00
return ID;
}
//=======================================================================
//function : ReleaseID
//purpose :
//=======================================================================
2012-08-09 16:03:55 +06:00
void SMDS_MeshElementIDFactory::ReleaseID(int ID, int vtkId)
2004-06-18 14:34:31 +06:00
{
2012-08-09 16:03:55 +06:00
if (ID < 1) // TODO check case ID == O
{
MESSAGE("~~~~~~~~~~~~~~ SMDS_MeshElementIDFactory::ReleaseID ID = " << ID);
return;
}
//MESSAGE("~~~~~~~~~~~~~~ SMDS_MeshElementIDFactory::ReleaseID smdsId vtkId " << ID << " " << vtkId);
if (vtkId >= 0)
{
assert(vtkId < myMesh->myCellIdVtkToSmds.size());
myMesh->myCellIdVtkToSmds[vtkId] = -1;
myMesh->setMyModified();
}
2004-06-18 14:34:31 +06:00
SMDS_MeshIDFactory::ReleaseID(ID);
2005-01-20 11:25:54 +05:00
if (ID == myMax)
myMax = 0;
if (ID == myMin)
2012-08-09 16:03:55 +06:00
myMax = 0;
2005-01-20 11:25:54 +05:00
}
2004-12-01 15:48:31 +05:00
2005-01-20 11:25:54 +05:00
//=======================================================================
//function : updateMinMax
//purpose :
//=======================================================================
void SMDS_MeshElementIDFactory::updateMinMax() const
{
2012-08-09 16:03:55 +06:00
myMin = INT_MAX;
2005-01-20 11:25:54 +05:00
myMax = 0;
2012-08-09 16:03:55 +06:00
for (int i = 0; i < myMesh->myCells.size(); i++)
{
if (myMesh->myCells[i])
{
int id = myMesh->myCells[i]->GetID();
if (id > myMax)
myMax = id;
if (id < myMin)
myMin = id;
}
}
if (myMin == INT_MAX)
2005-01-20 11:25:54 +05:00
myMin = 0;
2004-12-01 15:48:31 +05:00
}
2005-01-20 11:25:54 +05:00
//=======================================================================
//function : elementsIterator
//purpose : Return an iterator on elements of the factory
//=======================================================================
SMDS_ElemIteratorPtr SMDS_MeshElementIDFactory::elementsIterator() const
{
2012-08-09 16:03:55 +06:00
return myMesh->elementsIterator(SMDSAbs_All);
2005-01-20 11:25:54 +05:00
}
2009-02-17 10:27:49 +05:00
void SMDS_MeshElementIDFactory::Clear()
{
2012-08-09 16:03:55 +06:00
//myMesh->myCellIdSmdsToVtk.clear();
myMesh->myCellIdVtkToSmds.clear();
2009-02-17 10:27:49 +05:00
myMin = myMax = 0;
SMDS_MeshIDFactory::Clear();
}