Salome HOME
PAL0023627: [IMACS] ASERIS: project point to the mesh
authoreap <eap@opencascade.com>
Wed, 7 Nov 2018 15:02:19 +0000 (18:02 +0300)
committereap <eap@opencascade.com>
Wed, 7 Nov 2018 15:02:19 +0000 (18:02 +0300)
idl/SMESH_MeshEditor.idl
src/SMESHUtils/SMESH_MeshAlgos.cxx
src/SMESH_I/SMESH_MeshEditor_i.cxx
src/SMESH_I/SMESH_MeshEditor_i.hxx
src/SMESH_SWIG/smeshBuilder.py

index 86493fe3464c924ee3110cf4b4eef289efaa867b..2ec0484ea4e2435532c6b00c7271481628d4e0e6 100644 (file)
@@ -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.
index 91f6984a343f8054b23bce2d3587a8fdf90d475d..0fc388e75939e987fed1b662f93419fbce4a79fd 100644 (file)
@@ -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;
index 1628af333ae73581417b70eca80a566662b9c023..34383168510373c139035d9dadb006d3dbf417fb 100644 (file)
@@ -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<SMESH_Group_i*>( 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<SMESH_Mesh_i*>( 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<SMESH_Mesh_i*>( 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.
index 44a87ba45aea27eaa79a66b0a48c8f3019acd7fc..28d5e730737ebab69b01d20af413c25b1e6d9e68 100644 (file)
@@ -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.
index 1a39b452b4e7378b542b51589fcad7ae194f24f0..fed6214bbc2a85023a408b43aef7a9b23c1bc373 100755 (executable)
@@ -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: