smesh/src/SMDS/SMDS_VtkVolume.cxx

258 lines
5.5 KiB
C++
Raw Normal View History

2010-01-08 15:53:25 +00:00
#include "SMDS_VtkVolume.hxx"
#include "SMDS_MeshNode.hxx"
#include "SMDS_Mesh.hxx"
#include "SMDS_VtkCellIterator.hxx"
#include "utilities.h"
#include <vector>
SMDS_VtkVolume::SMDS_VtkVolume()
{
}
SMDS_VtkVolume::SMDS_VtkVolume(std::vector<vtkIdType> nodeIds, SMDS_Mesh* mesh)
{
init(nodeIds, mesh);
}
2010-04-02 13:55:36 +00:00
/*!
* typed used are vtk types (@see vtkCellType.h)
* see GetEntityType() for conversion in SMDS type (@see SMDSAbs_ElementType.hxx)
*/
2010-01-08 15:53:25 +00:00
void SMDS_VtkVolume::init(std::vector<vtkIdType> nodeIds, SMDS_Mesh* mesh)
{
vtkUnstructuredGrid* grid = mesh->getGrid();
2010-01-22 15:02:34 +00:00
myIdInShape = -1;
2010-01-08 15:53:25 +00:00
myMeshId = mesh->getMeshId();
2010-01-22 15:02:34 +00:00
vtkIdType aType = VTK_TETRA;
2010-07-01 14:46:31 +00:00
switch (nodeIds.size())
{
case 4:
aType = VTK_TETRA;
break;
case 5:
aType = VTK_PYRAMID;
break;
case 6:
aType = VTK_WEDGE;
break;
case 8:
aType = VTK_HEXAHEDRON;
break;
case 10:
aType = VTK_QUADRATIC_TETRA;
break;
case 13:
aType = VTK_QUADRATIC_PYRAMID;
break;
case 15:
aType = VTK_QUADRATIC_WEDGE;
break;
case 20:
aType = VTK_QUADRATIC_HEXAHEDRON;
break;
default:
aType = VTK_HEXAHEDRON;
break;
}
2010-01-22 15:02:34 +00:00
myVtkID = grid->InsertNextLinkedCell(aType, nodeIds.size(), &nodeIds[0]);
2010-01-08 15:53:25 +00:00
}
#ifdef VTK_HAVE_POLYHEDRON
void SMDS_VtkVolume::initPoly(std::vector<vtkIdType> nodeIds, std::vector<int> nbNodesPerFace, SMDS_Mesh* mesh)
{
MESSAGE("SMDS_VtkVolume::initPoly");
SMDS_UnstructuredGrid* grid = mesh->getGrid();
vector<vtkIdType> ptIds;
ptIds.clear();
vtkIdType nbFaces = nbNodesPerFace.size();
int k = 0;
for (int i = 0; i < nbFaces; i++)
{
int nf = nbNodesPerFace[i];
ptIds.push_back(nf);
for (int n = 0; n < nf; n++)
{
ptIds.push_back(nodeIds[k]);
k++;
}
}
myVtkID = grid->InsertNextLinkedCell(VTK_POLYHEDRON, nbFaces, &ptIds[0]);
}
#endif
bool SMDS_VtkVolume::ChangeNodes(const SMDS_MeshNode* nodes[], const int nbNodes)
2010-01-08 15:53:25 +00:00
{
2010-10-15 08:56:06 +00:00
vtkUnstructuredGrid* grid = SMDS_Mesh::_meshList[myMeshId]->getGrid();
vtkIdType npts = 0;
vtkIdType* pts = 0;
grid->GetCellPoints(myVtkID, npts, pts);
if (nbNodes != npts)
{
MESSAGE("ChangeNodes problem: not the same number of nodes " << npts << " -> " << nbNodes);
return false;
}
for (int i=0; i<nbNodes; i++)
{
pts[i] = nodes[i]->GetID();
}
2010-01-08 15:53:25 +00:00
return true;
}
SMDS_VtkVolume::~SMDS_VtkVolume()
{
}
void SMDS_VtkVolume::Print(ostream & OS) const
{
OS << "volume <" << GetID() << "> : ";
}
int SMDS_VtkVolume::NbFaces() const
{
// TODO polyedres
2010-07-01 14:46:31 +00:00
switch (NbNodes())
{
case 4:
case 10:
return 4;
case 5:
case 13:
return 5;
case 6:
case 15:
return 5;
case 8:
case 20:
return 6;
default:
MESSAGE("invalid number of nodes")
;
}
2010-01-08 15:53:25 +00:00
return 0;
}
int SMDS_VtkVolume::NbNodes() const
{
2010-07-01 14:46:31 +00:00
vtkUnstructuredGrid* grid = SMDS_Mesh::_meshList[myMeshId]->getGrid();
2010-01-08 15:53:25 +00:00
int nbPoints = grid->GetCell(myVtkID)->GetNumberOfPoints();
return nbPoints;
}
int SMDS_VtkVolume::NbEdges() const
{
// TODO polyedres
2010-07-01 14:46:31 +00:00
switch (NbNodes())
{
case 4:
case 10:
return 6;
case 5:
case 13:
return 8;
case 6:
case 15:
return 9;
case 8:
case 20:
return 12;
default:
MESSAGE("invalid number of nodes")
;
}
2010-01-08 15:53:25 +00:00
return 0;
}
SMDS_ElemIteratorPtr SMDS_VtkVolume::elementsIterator(SMDSAbs_ElementType type) const
{
2010-07-01 14:46:31 +00:00
switch (type)
{
2010-01-08 15:53:25 +00:00
case SMDSAbs_Node:
return SMDS_ElemIteratorPtr(new SMDS_VtkCellIterator(SMDS_Mesh::_meshList[myMeshId], myVtkID, GetEntityType()));
2010-01-08 15:53:25 +00:00
default:
2010-10-15 08:56:06 +00:00
MESSAGE("ERROR : Iterator not implemented");
2010-07-01 14:46:31 +00:00
return SMDS_ElemIteratorPtr((SMDS_ElemIterator*) NULL);
}
2010-01-08 15:53:25 +00:00
}
2010-10-15 08:56:06 +00:00
SMDS_ElemIteratorPtr SMDS_VtkVolume::nodesIteratorToUNV() const
{
return SMDS_ElemIteratorPtr(new SMDS_VtkCellIteratorToUNV(SMDS_Mesh::_meshList[myMeshId], myVtkID, GetEntityType()));
}
2010-01-08 15:53:25 +00:00
SMDSAbs_ElementType SMDS_VtkVolume::GetType() const
{
return SMDSAbs_Volume;
}
/*!
* \brief Return node by its index
* \param ind - node index
* \retval const SMDS_MeshNode* - the node
*/
const SMDS_MeshNode* SMDS_VtkVolume::GetNode(const int ind) const
{
2010-04-02 13:55:36 +00:00
return SMDS_MeshElement::GetNode(ind); // --- a optimiser !
}
bool SMDS_VtkVolume::IsQuadratic() const
{
// TODO polyedres
2010-04-02 13:55:36 +00:00
if (this->NbNodes() > 9)
2010-07-01 14:46:31 +00:00
return true;
2010-04-02 13:55:36 +00:00
else
2010-07-01 14:46:31 +00:00
return false;
2010-01-08 15:53:25 +00:00
}
SMDSAbs_EntityType SMDS_VtkVolume::GetEntityType() const
{
// TODO see SMDS_MeshElementIDFactory::GetVtkCellType
vtkIdType aVtkType = this->GetVtkType();
2010-01-08 15:53:25 +00:00
SMDSAbs_EntityType aType = SMDSEntity_Tetra;
switch (aVtkType)
2010-07-01 14:46:31 +00:00
{
case VTK_TETRA:
2010-07-01 14:46:31 +00:00
aType = SMDSEntity_Tetra;
break;
case VTK_PYRAMID:
2010-07-01 14:46:31 +00:00
aType = SMDSEntity_Pyramid;
break;
case VTK_WEDGE:
2010-07-01 14:46:31 +00:00
aType = SMDSEntity_Penta;
break;
case VTK_HEXAHEDRON:
2010-07-01 14:46:31 +00:00
aType = SMDSEntity_Hexa;
break;
case VTK_QUADRATIC_TETRA:
2010-07-01 14:46:31 +00:00
aType = SMDSEntity_Quad_Tetra;
break;
case VTK_QUADRATIC_PYRAMID:
2010-07-01 14:46:31 +00:00
aType = SMDSEntity_Quad_Pyramid;
break;
case VTK_QUADRATIC_WEDGE:
2010-07-01 14:46:31 +00:00
aType = SMDSEntity_Quad_Penta;
break;
case VTK_QUADRATIC_HEXAHEDRON:
2010-07-01 14:46:31 +00:00
aType = SMDSEntity_Quad_Hexa;
break;
#ifdef VTK_HAVE_POLYHEDRON
case VTK_POLYHEDRON:
aType = SMDSEntity_Polyhedra;
break;
#endif
2010-07-01 14:46:31 +00:00
default:
aType = SMDSEntity_Polyhedra;
2010-07-01 14:46:31 +00:00
break;
}
2010-01-08 15:53:25 +00:00
return aType;
}
2010-01-22 15:02:34 +00:00
vtkIdType SMDS_VtkVolume::GetVtkType() const
{
vtkUnstructuredGrid* grid = SMDS_Mesh::_meshList[myMeshId]->getGrid();
vtkIdType aType = grid->GetCellType(myVtkID);
2010-07-01 14:46:31 +00:00
return aType;
2010-01-22 15:02:34 +00:00
}