Salome HOME
Copyright update: 2016
[modules/smesh.git] / src / StdMeshers / StdMeshers_ProjectionUtils.cxx
index a21f5d7aa26b1986e6cbccc706a138ef5df5d70c..814c38dfdd9e50345fc94c0619851df5f42de9bf 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2007-2015  CEA/DEN, EDF R&D, OPEN CASCADE
+// Copyright (C) 2007-2016  CEA/DEN, EDF R&D, OPEN CASCADE
 //
 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
@@ -79,23 +79,9 @@ using namespace std;
 #define RETURN_BAD_RESULT(msg) { MESSAGE(")-: Error: " << msg); return false; }
 #define CONT_BAD_RESULT(msg) { MESSAGE(")-: Error: " << msg); continue; }
 #define SHOW_SHAPE(v,msg) \
-// { \
-//  if ( (v).IsNull() ) cout << msg << " NULL SHAPE" << endl; \
-// else if ((v).ShapeType() == TopAbs_VERTEX) {\
-//   gp_Pnt p = BRep_Tool::Pnt( TopoDS::Vertex( (v) ));\
-//   cout<<msg<<" "<<shapeIndex((v))<<" ( "<<p.X()<<", "<<p.Y()<<", "<<p.Z()<<" )"<<endl;} \
-// else {\
-//   cout << msg << " "; TopAbs::Print((v).ShapeType(),cout) <<" "<<shapeIndex((v))<<endl;}\
-// }
+  // { show_shape((v),(msg)); }
 #define SHOW_LIST(msg,l) \
-// { \
-//     cout << msg << " ";\
-//     list< TopoDS_Edge >::const_iterator e = l.begin();\
-//     for ( int i = 0; e != l.end(); ++e, ++i ) {\
-//       cout << i << "V (" << TopExp::FirstVertex( *e, true ).TShape().operator->() << ") "\
-//            << i << "E (" << e->TShape().operator->() << "); "; }\
-//     cout << endl;\
-//   }
+  // { show_list((msg),(l)); }
 
 namespace HERE = StdMeshers_ProjectionUtils;
 
@@ -108,7 +94,24 @@ namespace {
       return max(theMeshDS[0]->ShapeToIndex(S), theMeshDS[1]->ShapeToIndex(S) );
     return long(S.TShape().operator->());
   }
-
+  void show_shape( TopoDS_Shape v, const char* msg ) // debug
+  {
+    if ( v.IsNull() ) cout << msg << " NULL SHAPE" << endl;
+    else if (v.ShapeType() == TopAbs_VERTEX) {
+      gp_Pnt p = BRep_Tool::Pnt( TopoDS::Vertex( v ));
+      cout<<msg<<" "<<shapeIndex((v))<<" ( "<<p.X()<<", "<<p.Y()<<", "<<p.Z()<<" )"<<endl;}
+    else {
+      cout << msg << " "; TopAbs::Print((v).ShapeType(),cout) <<" "<<shapeIndex((v))<<endl;}
+  }
+  void show_list( const char* msg, const list< TopoDS_Edge >& l ) // debug
+  {
+    cout << msg << " ";
+    list< TopoDS_Edge >::const_iterator e = l.begin();
+    for ( int i = 0; e != l.end(); ++e, ++i ) {
+      cout << i << "V (" << TopExp::FirstVertex( *e, true ).TShape().operator->() << ") "
+           << i << "E (" << e->TShape().operator->() << "); "; }
+    cout << endl;
+  }
   //================================================================================
   /*!
    * \brief Write shape for debug purposes
@@ -756,6 +759,10 @@ bool StdMeshers_ProjectionUtils::FindSubShapeAssociation(const TopoDS_Shape& the
           TopoDS_Face nextFace1 = GetNextFace( edgeToFace1, *eIt1, face1 );
           TopoDS_Face nextFace2 = GetNextFace( edgeToFace2, *eIt2, face2 );
           if ( !nextFace1.IsNull() && !nextFace2.IsNull() ) {
+            if ( SMESH_MesherHelper::GetSubShapeOri( nextFace1, *eIt1 ) == eIt1->Orientation() )
+              nextFace1.Reverse();
+            if ( SMESH_MesherHelper::GetSubShapeOri( nextFace2, *eIt2 ) == eIt2->Orientation() )
+              nextFace2.Reverse();
             FE1.push_back( make_pair( nextFace1, *eIt1 ));
             FE2.push_back( make_pair( nextFace2, *eIt2 ));
           }
@@ -1170,11 +1177,11 @@ bool StdMeshers_ProjectionUtils::FindSubShapeAssociation(const TopoDS_Shape& the
       if ( !VV1[1].IsNull() ) {
         InsertAssociation( VV1[0], VV2[0], theMap );
         InsertAssociation( VV1[1], VV2[1], theMap );
+        TShapeShapeMap::EAssocType asType = theMap._assocType;
+        theMap.SetAssocType( TShapeShapeMap::PROPAGATION );
         if ( FindSubShapeAssociation( theShape1, theMesh1, theShape2, theMesh2, theMap ))
-        {
-          theMap.SetAssocType( TShapeShapeMap::PROPAGATION );
           return true;
-        }
+        theMap._assocType = asType;
       }
     }
     break; // try by vertex closeness
@@ -1230,11 +1237,11 @@ bool StdMeshers_ProjectionUtils::FindSubShapeAssociation(const TopoDS_Shape& the
       {
         InsertAssociation( VV1[0], VV1[0], theMap );
         InsertAssociation( VV1[1], VV1[1], theMap );
-        if (FindSubShapeAssociation( theShape1, theMesh1, theShape2, theMesh2, theMap ))
-        {
-          theMap.SetAssocType( TShapeShapeMap::COMMON_VERTEX );
+        TShapeShapeMap::EAssocType asType = theMap._assocType;
+        theMap.SetAssocType( TShapeShapeMap::COMMON_VERTEX );
+        if ( FindSubShapeAssociation( theShape1, theMesh1, theShape2, theMesh2, theMap ))
           return true;
-        }
+        theMap._assocType = asType;
       }
     }
   }
@@ -1406,7 +1413,7 @@ int StdMeshers_ProjectionUtils::FindFaceAssociation(const TopoDS_Face&    face1,
       }
       if ( TopExp::FirstVertex( *edgeIt ).IsSame( TopExp::LastVertex( *edgeIt )) &&
            SMESH_Algo::isDegenerated( *edgeIt )) {
-        --edgeIt; // skip a degenerated edge (www.salome-platform.org/forum/forum_11/173031193)
+        --edgeIt; // skip a degenerated edge (test 3D_mesh_Projection_00/A3)
       }
       if ( !VV1[1].IsSame( TopExp::FirstVertex( *edgeIt, true ))) {
         CONT_BAD_RESULT("GetOrderedEdges() failed");
@@ -1593,20 +1600,21 @@ int StdMeshers_ProjectionUtils::FindFaceAssociation(const TopoDS_Face&    face1,
               // reverse edges2 if needed
               if ( SMESH_MesherHelper::IsClosedEdge( *edge1Beg ))
               {
-                double f,l;
-                Handle(Geom2d_Curve) c1 = BRep_Tool::CurveOnSurface( *edge1Beg, face1,f,l );
-                if (  edge1Beg->Orientation() == TopAbs_REVERSED )
-                  std::swap( f,l );
-                gp_Pnt2d uv1 = dUV + c1->Value( f * 0.8 + l * 0.2 ).XY();
-
-                Handle(Geom2d_Curve) c2 = BRep_Tool::CurveOnSurface( *edge2Beg, face2,f,l );
-                if (  edge2Beg->Orientation() == TopAbs_REVERSED )
-                  std::swap( f,l );
-                gp_Pnt2d uv2 = c2->Value( f * 0.8 + l * 0.2 );
-                gp_Pnt2d uv3 = c2->Value( l * 0.8 + f * 0.2 );
-
-                if ( uv1.SquareDistance( uv2 ) > uv1.SquareDistance( uv3 ))
-                  edge2Beg->Reverse();
+                // Commented (so far?) as it's not checked if orientation must be same or reversed
+                // double f,l;
+                // Handle(Geom2d_Curve) c1 = BRep_Tool::CurveOnSurface( *edge1Beg, face1,f,l );
+                // if (  edge1Beg->Orientation() == TopAbs_REVERSED )
+                //   std::swap( f,l );
+                // gp_Pnt2d uv1 = dUV + c1->Value( f * 0.8 + l * 0.2 ).XY();
+
+                // Handle(Geom2d_Curve) c2 = BRep_Tool::CurveOnSurface( *edge2Beg, face2,f,l );
+                // if (  edge2Beg->Orientation() == TopAbs_REVERSED )
+                //   std::swap( f,l );
+                // gp_Pnt2d uv2 = c2->Value( f * 0.8 + l * 0.2 );
+                // gp_Pnt2d uv3 = c2->Value( l * 0.8 + f * 0.2 );
+
+                // if ( uv1.SquareDistance( uv2 ) > uv1.SquareDistance( uv3 ))
+                //   edge2Beg->Reverse();
               }
               else
               {
@@ -1860,7 +1868,7 @@ StdMeshers_ProjectionUtils::GetPropagationEdge( SMESH_Mesh*                 aMes
             int prevChainSize = aChain.Extent();
             if ( aChain.Add(anOppE) > prevChainSize ) { // ... anOppE is not in aChain
               // Add found edge to the chain oriented so that to
-              // have it co-directed with a forward MainEdge
+              // have it co-directed with a fromEdge
               TopAbs_Orientation ori = anE.Orientation();
               if ( anOppE.Orientation() == fourEdges[found].Orientation() )
                 ori = TopAbs::Reverse( ori );
@@ -1923,7 +1931,7 @@ FindMatchingNodesOnFaces( const TopoDS_Face&     face1,
 
   helper1.SetSubShape( face1 );
   helper2.SetSubShape( face2 );
-  if ( helper1.HasSeam() != helper2.HasSeam() )
+  if ( helper1.HasRealSeam() != helper2.HasRealSeam() )
     RETURN_BAD_RESULT("Different faces' geometry");
 
   // Data to call SMESH_MeshEditor::FindMatchingNodes():
@@ -2175,7 +2183,7 @@ FindMatchingNodesOnFaces( const TopoDS_Face&     face1,
           static_cast<const SMDS_EdgePosition*>(node->GetPosition());
         pos2nodes.insert( make_pair( pos->GetUParameter(), node ));
       }
-      if ( pos2nodes.size() != edgeSM->NbNodes() )
+      if ((int) pos2nodes.size() != edgeSM->NbNodes() )
         RETURN_BAD_RESULT("Equal params of nodes on edge "
                           << smDS->ShapeToIndex( edge ) << " of face " << is2 );
     }
@@ -2613,13 +2621,13 @@ namespace StdMeshers_ProjectionUtils
     // cout << vec( 1 ) << "\t " << vec( 2 ) << endl
     //      << vec( 3 ) << "\t " << vec( 4 ) << endl;
 
-    _trsf.SetTranslation( tgtGC );
+    _trsf.SetTranslationPart( tgtGC );
     _srcOrig = srcGC;
 
-    gp_Mat2d& M = const_cast< gp_Mat2d& >( _trsf.HVectorialPart());
+    gp_Mat2d& M = const_cast< gp_Mat2d& >( _trsf.VectorialPart());
     M( 1,1 ) = vec( 1 );
-    M( 2,1 ) = vec( 2 );
-    M( 1,2 ) = vec( 3 );
+    M( 2,1 ) = vec( 2 ); // | 1 3 | -- is it correct ????????
+    M( 1,2 ) = vec( 3 ); // | 2 4 |
     M( 2,2 ) = vec( 4 );
 
     return true;
@@ -2710,9 +2718,9 @@ namespace StdMeshers_ProjectionUtils
     //      << vec( 7 ) << "\t " << vec( 8 ) << "\t " << vec( 9 ) << endl;
 
     _srcOrig = srcOrig;
-    _trsf.SetTranslation( tgtOrig );
+    _trsf.SetTranslationPart( tgtOrig );
 
-    gp_Mat& M = const_cast< gp_Mat& >( _trsf.HVectorialPart() );
+    gp_Mat& M = const_cast< gp_Mat& >( _trsf.VectorialPart() );
     M.SetRows( gp_XYZ( vec( 1 ), vec( 2 ), vec( 3 )),
                gp_XYZ( vec( 4 ), vec( 5 ), vec( 6 )),
                gp_XYZ( vec( 7 ), vec( 8 ), vec( 9 )));
@@ -2740,7 +2748,7 @@ namespace StdMeshers_ProjectionUtils
 
   gp_XYZ TrsfFinder3D::TransformVec( const gp_Vec& v ) const
   {
-    return v.XYZ().Multiplied( _trsf.HVectorialPart() );
+    return v.XYZ().Multiplied( _trsf.VectorialPart() );
   }
   //================================================================================
   /*!
@@ -2755,7 +2763,7 @@ namespace StdMeshers_ProjectionUtils
     {
       // seems to be defined via Solve()
       gp_XYZ newSrcOrig = _trsf.TranslationPart();
-      gp_Mat& M = const_cast< gp_Mat& >( _trsf.HVectorialPart() );
+      gp_Mat& M = const_cast< gp_Mat& >( _trsf.VectorialPart() );
       const double D = M.Determinant();
       if ( D < 1e-3 * ( newSrcOrig - _srcOrig ).Modulus() )
       {
@@ -2766,7 +2774,7 @@ namespace StdMeshers_ProjectionUtils
         return false;
       }
       gp_Mat Minv = M.Inverted();
-      _trsf.SetTranslation( _srcOrig );
+      _trsf.SetTranslationPart( _srcOrig );
       _srcOrig = newSrcOrig;
       M = Minv;
     }