Salome HOME
22358: EDF SMESH: Body Fitting algorithm: origin point of grid defined by spacing
authoreap <eap@opencascade.com>
Tue, 4 Feb 2014 15:51:49 +0000 (15:51 +0000)
committereap <eap@opencascade.com>
Tue, 4 Feb 2014 15:51:49 +0000 (15:51 +0000)
src/SMESH_I/SMESH_2smeshpy.cxx
src/SMESH_I/SMESH_MeshEditor_i.cxx
src/SMESH_SWIG/StdMeshersBuilder.py
src/StdMeshers/StdMeshers_CartesianParameters3D.cxx
src/StdMeshers/StdMeshers_CartesianParameters3D.hxx
src/StdMeshers/StdMeshers_Cartesian_3D.cxx
src/StdMeshers_I/StdMeshers_CartesianParameters3D_i.cxx

index b8358a7952b272a89bb7b2ad2c9a788a89e3f943..9c68a33be6d5c427d09f6be082a76501921d79bb 100644 (file)
@@ -372,7 +372,7 @@ namespace {
    */
   //================================================================================
 
-  void StructToList( Handle( _pyCommand)& theCommand )
+  void StructToList( Handle( _pyCommand)& theCommand, const bool checkMethod=true )
   {
     static TStringSet methodsAcceptingList;
     if ( methodsAcceptingList.empty() ) {
@@ -390,7 +390,7 @@ namespace {
         ,"" }; // <- mark of the end
       methodsAcceptingList.Insert( methodNames );
     }
-    if ( methodsAcceptingList.Contains( theCommand->GetMethod() ))
+    if ( !checkMethod || methodsAcceptingList.Contains( theCommand->GetMethod() ))
     {
       for ( int i = theCommand->GetNbArgs(); i > 0; --i )
       {
@@ -3159,13 +3159,23 @@ void _pyComplexParamHypo::Flush()
     for ( ; cmd != myUnusedCommands.end(); ++cmd )
       if ((*cmd)->GetMethod() == "SetObjectEntry" )
         (*cmd)->Clear();
+
+    if ( GetAlgoType() == "Cartesian_3D" )
+    {
+      _pyID algo = myCreationCmd->GetObject();
+      for ( cmd = myProcessedCmds.begin(); cmd != myProcessedCmds.end(); ++cmd )
+      {
+        StructToList( *cmd, /*checkMethod=*/false );
+        (*cmd)->SetObject( algo );
+      }
+    }
   }
 }
 
 //================================================================================
 /*!
  * \brief Convert methods of 1D hypotheses to my own methods
 * \param theCommand - The called hypothesis method
+ * \param theCommand - The called hypothesis method
  */
 //================================================================================
 
index a983a13c3298599e2a7230aeb435134097d7248b..d01b62999c9e0e16968fe9d794472efac5cc658c 100644 (file)
@@ -5253,13 +5253,6 @@ SMESH::long_array* SMESH_MeshEditor_i::FindElementsByPoint(CORBA::Double      x,
   for ( int i = 0; i < foundElems.size(); ++i )
     res[i] = foundElems[i]->GetID();
 
-  if ( !myIsPreviewMode ) // call from tui
-    TPythonDump() << "res = " << this << ".FindElementsByPoint( "
-                  << x << ", "
-                  << y << ", "
-                  << z << ", "
-                  << type << " )";
-
   return res._retn();
 
   SMESH_CATCH( SMESH::throwCorbaException );
@@ -5321,14 +5314,6 @@ SMESH_MeshEditor_i::FindAmongElementsByPoint(SMESH::SMESH_IDSource_ptr elementID
   for ( int i = 0; i < foundElems.size(); ++i )
     res[i] = foundElems[i]->GetID();
 
-  if ( !myIsPreviewMode ) // call from tui
-    TPythonDump() << "res = " << this << ".FindAmongElementsByPoint( "
-                  << elementIDs << ", "
-                  << x << ", "
-                  << y << ", "
-                  << z << ", "
-                  << type << " )";
-
   return res._retn();
 
   SMESH_CATCH( SMESH::throwCorbaException );
index 265a9801b0d449a0407a00e15ab24267808313f1..46032989c8b2d0bf15359e45e3673f187561915b 100644 (file)
@@ -1470,15 +1470,17 @@ class StdMeshersBuilder_Cartesian_3D(Mesh_Algorithm):
     #  through the fixed point in each direction at which the grid is defined
     #  by spacing
     #  @param p coordinates of the fixed point. Either SMESH.PointStruct or
-    #         3 components of coordinates.
+    #         a vertex or 3 components of coordinates.
     #  @param toUnset defines whether the fixed point is defined or removed.
     def SetFixedPoint( self, p, toUnset=False ):
-        import SMESH
+        import SMESH, GEOM
         if toUnset:
             if not self.hyp: return
             p = SMESH.PointStruct(0,0,0)
-        if hasattr( p, "__getitem__" ):
+        elif hasattr( p, "__getitem__" ):
             p = SMESH.PointStruct( p[0],p[1],p[2] )
+        elif isinstance( p, GEOM._objref_GEOM_Object ):
+            p = self.mesh.smeshpyD.GetPointStruct( p )
         if not self.hyp:
             self.hyp = self.Hypothesis("CartesianParameters3D")
         if not self.mesh.IsUsedHypothesis( self.hyp, self.geom ):
index 00cd8615ec4bbddafa83cc1c238d708e52b07766..60b9532d414aa6fe433e8295de49960f9cd47a9a 100644 (file)
@@ -49,6 +49,7 @@
 #include <TopoDS.hxx>
 #include <TopoDS_Face.hxx>
 #include <gp_Dir.hxx>
+#include <gp_Mat.hxx>
 #include <gp_Pln.hxx>
 #include <gp_Vec.hxx>
 
@@ -234,7 +235,7 @@ void StdMeshers_CartesianParameters3D::SetFixedPoint(const double p[3], bool toU
 //purpose  : Returns either false or (true + point coordinates)
 //=======================================================================
 
-bool StdMeshers_CartesianParameters3D::GetFixedPoint(double p[3])
+bool StdMeshers_CartesianParameters3D::GetFixedPoint(double p[3]) const
 {
   if ( Precision::IsInfinite( _fixedPoint[0] ))
     return false;
@@ -294,15 +295,36 @@ bool StdMeshers_CartesianParameters3D::IsGridBySpacing(const int axis) const
 //purpose  : Computes node coordinates by spacing functions
 //=======================================================================
 
-void StdMeshers_CartesianParameters3D::ComputeCoordinates(const double         x0,
-                                                          const double         x1,
-                                                          vector<std::string>& spaceFuns,
-                                                          vector<double>&      points,
-                                                          vector<double>&      coords,
-                                                          const std::string&   axis )
+void StdMeshers_CartesianParameters3D::ComputeCoordinates(const double    x0,
+                                                          const double    x1,
+                                                          vector<string>& theSpaceFuns,
+                                                          vector<double>& thePoints,
+                                                          vector<double>& coords,
+                                                          const string&   axis,
+                                                          const double*   xForced )
   throw ( SALOME_Exception )
 {
-  checkGridSpacing( spaceFuns, points, axis );
+  checkGridSpacing( theSpaceFuns, thePoints, axis );
+
+  vector<string> spaceFuns = theSpaceFuns;
+  vector<double> points    = thePoints;
+
+  bool forced = false;
+  if (( forced = ( xForced && ( x0 < *xForced ) && ( *xForced < x1 ))))
+  {
+    // divide a range at xForced
+
+    // find a range to insert xForced
+    double pos = ( *xForced - x0 ) / ( x1 - x0 );
+    int iR = 1;
+    while ( pos > points[ iR ] ) ++iR;
+
+    // insert xForced
+    vector<double>::iterator pntIt = points.begin() + iR;
+    points.insert( pntIt, pos );
+    vector<string>::iterator funIt = spaceFuns.begin() + iR;
+    spaceFuns.insert( funIt, spaceFuns[ iR-1 ]);
+  }
 
   coords.clear();
   for ( size_t i = 0; i < spaceFuns.size(); ++i )
@@ -345,6 +367,28 @@ void StdMeshers_CartesianParameters3D::ComputeCoordinates(const double         x
     if ( fabs( coords.back() - p1 ) > 0.5 * lastCellLen )
       coords.push_back ( p1 );
   }
+
+  // correct coords if a forced point is too close to a neighbor node
+  if ( forced )
+  {
+    int iF = 0;
+    double minLen = ( x1 - x0 );
+    for ( size_t i = 1; i < coords.size(); ++i )
+    {
+      if ( !iF && Abs( coords[i] - *xForced ) < 1e-20 )
+        iF = i++; // xForced found
+      else
+        minLen = Min( minLen, coords[i] - coords[i-1] );
+    }
+    const double tol = minLen * 1e-3;
+    int iRem = -1;
+    if (( iF > 1 ) && ( coords[iF] - coords[iF-1] < tol ))
+      iRem = iF-1;
+    else if (( iF < coords.size()-2 ) && ( coords[iF+1] - coords[iF] < tol ))
+      iRem = iF+1;
+    if ( iRem > 0 )
+      coords.erase( coords.begin() + iRem );
+  }
 }
 
 //=======================================================================
@@ -370,19 +414,45 @@ void StdMeshers_CartesianParameters3D::GetCoordinates(std::vector<double>& xNode
     bndBox.Get(x0,y0,z0, x1,y1,z1);
   }
 
+  double fp[3], *pfp[3] = { NULL, NULL, NULL };
+  if ( GetFixedPoint( fp ))
+  {
+    // convert fp into a basis defined by _axisDirs
+    gp_XYZ axis[3] = { gp_XYZ( _axisDirs[0], _axisDirs[1], _axisDirs[2] ),
+                       gp_XYZ( _axisDirs[3], _axisDirs[4], _axisDirs[5] ),
+                       gp_XYZ( _axisDirs[6], _axisDirs[7], _axisDirs[8] ) };
+    axis[0].Normalize();
+    axis[1].Normalize();
+    axis[2].Normalize();
+
+    gp_Mat basis( axis[0], axis[1], axis[2] );
+    gp_Mat bi = basis.Inverted();
+
+    gp_XYZ p( fp[0], fp[1], fp[2] );
+    p *= bi;
+    p.Coord( fp[0], fp[1], fp[2] );
+
+    pfp[0] = & fp[0];
+    pfp[1] = & fp[1];
+    pfp[2] = & fp[2];
+  }
+
   StdMeshers_CartesianParameters3D* me = const_cast<StdMeshers_CartesianParameters3D*>(this);
   if ( IsGridBySpacing(0) )
-    ComputeCoordinates( x0, x1, me->_spaceFunctions[0], me->_internalPoints[0], xNodes, "X" );
+    ComputeCoordinates
+      ( x0, x1, me->_spaceFunctions[0], me->_internalPoints[0], xNodes, "X", pfp[0] );
   else
     xNodes = _coords[0];
 
   if ( IsGridBySpacing(1) )
-    ComputeCoordinates( y0, y1, me->_spaceFunctions[1], me->_internalPoints[1], yNodes, "Y" );
+    ComputeCoordinates
+      ( y0, y1, me->_spaceFunctions[1], me->_internalPoints[1], yNodes, "Y", pfp[1] );
   else
     yNodes = _coords[1];
 
   if ( IsGridBySpacing(2) )
-    ComputeCoordinates( z0, z1, me->_spaceFunctions[2], me->_internalPoints[2], zNodes, "Z" );
+    ComputeCoordinates
+      ( z0, z1, me->_spaceFunctions[2], me->_internalPoints[2], zNodes, "Z", pfp[2] );
   else
     zNodes = _coords[2];
 }
index 3ef431cc9872b40af8289217a6e54eecce7e86e6..d7ecbb1bf45bdaeb2ef867e7eb9b9a5ce6a54caf 100644 (file)
@@ -83,7 +83,7 @@ public:
    * is defined by spacing in all directions
    */
   void SetFixedPoint(const double p[3], bool toUnset);
-  bool GetFixedPoint(double p[3]);
+  bool GetFixedPoint(double p[3]) const;
 
   /*!
    * \brief Computes node coordinates by spacing functions
@@ -98,7 +98,8 @@ public:
                                  std::vector<std::string>& spaceFuns,
                                  std::vector<double>&      points,
                                  std::vector<double>&      coords,
-                                 const std::string&        axis ) throw (SALOME_Exception);
+                                 const std::string&        axis,
+                                 const double*             xForced=0) throw (SALOME_Exception);
   /*!
    * Return coordinates of node positions along the three axes.
    * If the grid is defined by spacing functions, the coordinates are computed
index b8c4a92ff98a1233763cf18499be6c8e925e9851..d5435e7ee1b84197a567d3f98ff3902a8d37cf95 100644 (file)
@@ -83,7 +83,7 @@
 #include <gp_Sphere.hxx>
 #include <gp_Torus.hxx>
 
-#undef WITH_TBB
+//#undef WITH_TBB
 #ifdef WITH_TBB
 #include <tbb/parallel_for.h>
 //#include <tbb/enumerable_thread_specific.h>
index 5b383a0f55634ed0581907f1bb82c28060f12fdd..5cdeae0c16036c48e902b1fea14f0b906cfce1c5 100644 (file)
@@ -290,10 +290,7 @@ void StdMeshers_CartesianParameters3D_i::SetFixedPoint(const SMESH::PointStruct&
   double p[3] = { ps.x, ps.y, ps.z };
   GetImpl()->SetFixedPoint( p, toUnset );
 
-  if ( toUnset )
-    SMESH::TPythonDump() << _this() << ".SetFixedPoint([0,0,0], True)";
-  else
-    SMESH::TPythonDump() << _this() << ".SetFixedPoint(" << p << ", " << toUnset << " )";
+  SMESH::TPythonDump() << _this() << ".SetFixedPoint( " << ps << ", " << toUnset << " )";
 }
 
 //=======================================================================