From 6ae2a9da945b425168ef891ac249fafb2ef71a9a Mon Sep 17 00:00:00 2001 From: eap Date: Mon, 29 Jul 2013 11:49:21 +0000 Subject: [PATCH] Optimize SMDS_MeshElement::GetNodeIndex() + virtual int GetNodeIndex( const SMDS_MeshNode* node ) const; --- src/SMDS/SMDS_VtkFace.cxx | 16 ++++++++++++++++ src/SMDS/SMDS_VtkFace.hxx | 1 + src/SMDS/SMDS_VtkVolume.cxx | 36 ++++++++++++++++++++++++++++++++++++ src/SMDS/SMDS_VtkVolume.hxx | 1 + 4 files changed, 54 insertions(+) diff --git a/src/SMDS/SMDS_VtkFace.cxx b/src/SMDS/SMDS_VtkFace.cxx index 56787bda0..3d5e82fee 100644 --- a/src/SMDS/SMDS_VtkFace.cxx +++ b/src/SMDS/SMDS_VtkFace.cxx @@ -161,6 +161,22 @@ SMDS_VtkFace::GetNode(const int ind) const return SMDS_Mesh::_meshList[myMeshId]->FindNodeVtk( pts[ ind ]); } +/*! + * \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_VtkFace::GetNodeIndex( const SMDS_MeshNode* node ) const +{ + vtkUnstructuredGrid* grid = SMDS_Mesh::_meshList[myMeshId]->getGrid(); + vtkIdType npts, *pts; + grid->GetCellPoints( this->myVtkID, npts, pts ); + for ( vtkIdType i = 0; i < npts; ++i ) + if ( pts[i] == node->getVtkId() ) + return i; + return -1; +} + bool SMDS_VtkFace::IsQuadratic() const { vtkUnstructuredGrid* grid = SMDS_Mesh::_meshList[myMeshId]->getGrid(); diff --git a/src/SMDS/SMDS_VtkFace.hxx b/src/SMDS/SMDS_VtkFace.hxx index 5fc10324d..f62b86c00 100644 --- a/src/SMDS/SMDS_VtkFace.hxx +++ b/src/SMDS/SMDS_VtkFace.hxx @@ -47,6 +47,7 @@ public: virtual SMDSAbs_EntityType GetEntityType() const; virtual SMDSAbs_GeometryType GetGeomType() const; virtual const SMDS_MeshNode* GetNode(const int ind) const; + virtual int GetNodeIndex( const SMDS_MeshNode* node ) const; virtual bool IsQuadratic() const; virtual bool IsPoly() const; diff --git a/src/SMDS/SMDS_VtkVolume.cxx b/src/SMDS/SMDS_VtkVolume.cxx index 3db0ba03b..22f5de67e 100644 --- a/src/SMDS/SMDS_VtkVolume.cxx +++ b/src/SMDS/SMDS_VtkVolume.cxx @@ -448,6 +448,42 @@ const SMDS_MeshNode* SMDS_VtkVolume::GetNode(const int ind) const const std::vector& interlace = SMDS_MeshCell::fromVtkOrder( VTKCellType( aVtkType )); return SMDS_Mesh::_meshList[myMeshId]->FindNodeVtk( pts[ interlace.empty() ? ind : interlace[ind]] ); } +/*! + * \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_VtkVolume::GetNodeIndex( const SMDS_MeshNode* node ) const +{ + vtkUnstructuredGrid* grid = SMDS_Mesh::_meshList[myMeshId]->getGrid(); + const vtkIdType aVtkType = grid->GetCellType(this->myVtkID); + if ( aVtkType == VTK_POLYHEDRON) + { + vtkIdType nFaces = 0; + vtkIdType* ptIds = 0; + grid->GetFaceStream(this->myVtkID, nFaces, ptIds); + int id = 0, nbPoints = 0; + for (int iF = 0; iF < nFaces; iF++) + { + int nodesInFace = ptIds[id]; + for ( vtkIdType i = 0; i < nodesInFace; ++i ) + if ( ptIds[id+i] == node->getVtkId() ) + return id+i-iF; + nbPoints += nodesInFace; + id += (nodesInFace + 1); + } + return -1; + } + vtkIdType npts, *pts; + grid->GetCellPoints( this->myVtkID, npts, pts ); + for ( vtkIdType i = 0; i < npts; ++i ) + if ( pts[i] == node->getVtkId() ) + { + const std::vector& interlace = SMDS_MeshCell::toVtkOrder( VTKCellType( aVtkType )); + return interlace.empty() ? i : interlace[i]; + } + return -1; +} bool SMDS_VtkVolume::IsQuadratic() const { diff --git a/src/SMDS/SMDS_VtkVolume.hxx b/src/SMDS/SMDS_VtkVolume.hxx index 63c41ecb7..827f17fd7 100644 --- a/src/SMDS/SMDS_VtkVolume.hxx +++ b/src/SMDS/SMDS_VtkVolume.hxx @@ -56,6 +56,7 @@ public: virtual SMDSAbs_EntityType GetEntityType() const; virtual SMDSAbs_GeometryType GetGeomType() const; virtual const SMDS_MeshNode* GetNode(const int ind) const; + virtual int GetNodeIndex( const SMDS_MeshNode* node ) const; virtual bool IsQuadratic() const; virtual bool IsPoly() const; virtual bool IsMediumNode(const SMDS_MeshNode* node) const; -- 2.39.2