From 858b4bff6498075831d120d54f3dfe25566336b9 Mon Sep 17 00:00:00 2001 From: eap Date: Wed, 7 Nov 2018 18:02:19 +0300 Subject: [PATCH] PAL0023627: [IMACS] ASERIS: project point to the mesh --- idl/SMESH_MeshEditor.idl | 14 +++++++ src/SMESHUtils/SMESH_MeshAlgos.cxx | 4 +- src/SMESH_I/SMESH_MeshEditor_i.cxx | 66 +++++++++++++++++++++++++++++- src/SMESH_I/SMESH_MeshEditor_i.hxx | 14 +++++++ src/SMESH_SWIG/smeshBuilder.py | 11 +++++ 5 files changed, 105 insertions(+), 4 deletions(-) diff --git a/idl/SMESH_MeshEditor.idl b/idl/SMESH_MeshEditor.idl index 86493fe34..2ec0484ea 100644 --- a/idl/SMESH_MeshEditor.idl +++ b/idl/SMESH_MeshEditor.idl @@ -773,6 +773,20 @@ module SMESH in ElementType type) raises (SALOME::SALOME_Exception); + /*! + * Project a point to a mesh object. + * Return ID of an element of given type where the given point is projected + * and coordinates of the projection point. + * In the case if nothing found, return -1 and [] + */ + long ProjectPoint(in double x, + in double y, + in double z, + in SMESH_IDSource meshObject, + in ElementType type, + out double_array projecton) + raises (SALOME::SALOME_Exception); + /*! * Return point state in a closed 2D mesh in terms of TopAbs_State enumeration. * TopAbs_UNKNOWN state means that either mesh is wrong or the analysis fails. diff --git a/src/SMESHUtils/SMESH_MeshAlgos.cxx b/src/SMESHUtils/SMESH_MeshAlgos.cxx index 91f6984a3..0fc388e75 100644 --- a/src/SMESHUtils/SMESH_MeshAlgos.cxx +++ b/src/SMESHUtils/SMESH_MeshAlgos.cxx @@ -1243,11 +1243,11 @@ gp_XYZ SMESH_ElementSearcherImpl::Project(const gp_Pnt& point, ElementBndBoxTree*& ebbTree = _ebbTree[ _elementType ]; if ( !ebbTree ) - ebbTree = new ElementBndBoxTree( *_mesh, _elementType ); + ebbTree = new ElementBndBoxTree( *_mesh, _elementType, _meshPartIt ); gp_XYZ p = point.XYZ(); ElementBndBoxTree* ebbLeaf = ebbTree->getLeafAtPoint( p ); - const Bnd_B3d* box = ebbLeaf->getBox(); + const Bnd_B3d* box = ebbLeaf ? ebbLeaf->getBox() : ebbTree->getBox(); double radius = ( box->CornerMax() - box->CornerMin() ).Modulus(); ElementBndBoxTree::TElemSeq elems; diff --git a/src/SMESH_I/SMESH_MeshEditor_i.cxx b/src/SMESH_I/SMESH_MeshEditor_i.cxx index 1628af333..343831685 100644 --- a/src/SMESH_I/SMESH_MeshEditor_i.cxx +++ b/src/SMESH_I/SMESH_MeshEditor_i.cxx @@ -178,7 +178,7 @@ namespace MeshEditor_I { //============================================================================= /*! - * \brief Deleter of theNodeSearcher at any compute event occurred + * \brief Deleter of theNodeSearcher and theElementSearcher at any compute event occurred */ //============================================================================= @@ -381,7 +381,7 @@ namespace MeshEditor_I { */ //================================================================================ - string getPartIOR( SMESH::SMESH_IDSource_ptr theMeshPart, SMESH::ElementType type) + string getPartIOR( SMESH::SMESH_IDSource_ptr theMeshPart, SMESH::ElementType type = SMESH::ALL ) { string partIOR = SMESH_Gen_i::GetORB()->object_to_string( theMeshPart ); if ( SMESH_Group_i* group_i = SMESH::DownCast( theMeshPart )) @@ -4652,6 +4652,68 @@ SMESH_MeshEditor_i::FindAmongElementsByPoint(SMESH::SMESH_IDSource_ptr elementID return 0; } +//======================================================================= +//function : ProjectPoint +//purpose : Project a point to a mesh object. +// Return ID of an element of given type where the given point is projected +// and coordinates of the projection point. +// In the case if nothing found, return -1 and [] +//======================================================================= + +CORBA::Long SMESH_MeshEditor_i::ProjectPoint(CORBA::Double x, + CORBA::Double y, + CORBA::Double z, + SMESH::SMESH_IDSource_ptr meshObject, + SMESH::ElementType type, + SMESH::double_array_out projecton) + throw (SALOME::SALOME_Exception) +{ + if ( CORBA::is_nil( meshObject )) + THROW_SALOME_CORBA_EXCEPTION("NULL meshObject", SALOME::BAD_PARAM); + + SMESH_TRY; + + SMESH::SMESH_Mesh_var mesh = meshObject->GetMesh(); + SMESH_Mesh_i* mesh_i = SMESH::DownCast( mesh ); + if ( mesh_i != myMesh_i ) + { + SMESH::SMESH_MeshEditor_var editor= + myIsPreviewMode ? mesh_i->GetMeshEditPreviewer() : mesh_i->GetMeshEditor(); + return editor->ProjectPoint( x,y,z, meshObject, type, projecton ); + } + + + theSearchersDeleter.Set( myMesh, getPartIOR( meshObject )); + if ( !theElementSearcher ) + { + // create a searcher from meshObject + + SMDS_ElemIteratorPtr elemIt; + if ( ! SMESH::DownCast( meshObject )) + elemIt = myMesh_i->GetElements( meshObject, type ); + + theElementSearcher = SMESH_MeshAlgos::GetElementSearcher( *getMeshDS(), elemIt ); + } + + const SMDS_MeshElement* elem = 0; + gp_XYZ pProj = theElementSearcher->Project( gp_Pnt( x,y,z ), + SMDSAbs_ElementType( type ), + &elem ); + + projecton = new SMESH::double_array(); + if ( elem && !elem->IsNull() ) + { + projecton->length( 3 ); + projecton[0] = pProj.X(); + projecton[1] = pProj.Y(); + projecton[2] = pProj.Z(); + return elem->GetID(); + } + + SMESH_CATCH( SMESH::throwCorbaException ); + return -1; +} + //======================================================================= //function : GetPointState //purpose : Return point state in a closed 2D mesh in terms of TopAbs_State enumeration. diff --git a/src/SMESH_I/SMESH_MeshEditor_i.hxx b/src/SMESH_I/SMESH_MeshEditor_i.hxx index 44a87ba45..28d5e7307 100644 --- a/src/SMESH_I/SMESH_MeshEditor_i.hxx +++ b/src/SMESH_I/SMESH_MeshEditor_i.hxx @@ -546,6 +546,20 @@ public: SMESH::ElementType type) throw (SALOME::SALOME_Exception); + /*! + * Project a point to a mesh object. + * Return ID of an element of given type where the given point is projected + * and coordinates of the projection point. + * In the case if nothing found, return -1 and [] + */ + CORBA::Long ProjectPoint(CORBA::Double x, + CORBA::Double y, + CORBA::Double z, + SMESH::SMESH_IDSource_ptr meshObject, + SMESH::ElementType type, + SMESH::double_array_out projecton) + throw (SALOME::SALOME_Exception); + /*! * Return point state in a closed 2D mesh in terms of TopAbs_State enumeration. * TopAbs_UNKNOWN state means that either mesh is wrong or the analysis fails. diff --git a/src/SMESH_SWIG/smeshBuilder.py b/src/SMESH_SWIG/smeshBuilder.py index 1a39b452b..fed6214bb 100755 --- a/src/SMESH_SWIG/smeshBuilder.py +++ b/src/SMESH_SWIG/smeshBuilder.py @@ -4228,6 +4228,17 @@ class Mesh(metaclass = MeshMeta): else: return self.editor.FindElementsByPoint(x, y, z, elementType) + def ProjectPoint(self, x,y,z, meshObject, elementType): + """ + Project a point to a mesh object. + Return ID of an element of given type where the given point is projected + and coordinates of the projection point. + In the case if nothing found, return -1 and [] + """ + if ( isinstance( meshObject, Mesh )): + meshObject = meshObject.GetMesh() + return self.editor.ProjectPoint( x,y,z, meshObject, elementType ) + def GetPointState(self, x, y, z): """ Return point state in a closed 2D mesh in terms of TopAbs_State enumeration: -- 2.30.2