Version: 6.3.1

src/StdMeshers/StdMeshers_FaceSide.cxx

Go to the documentation of this file.
00001 // Copyright (C) 2007-2011  CEA/DEN, EDF R&D, OPEN CASCADE
00002 //
00003 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
00004 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
00005 //
00006 // This library is free software; you can redistribute it and/or
00007 // modify it under the terms of the GNU Lesser General Public
00008 // License as published by the Free Software Foundation; either
00009 // version 2.1 of the License.
00010 //
00011 // This library is distributed in the hope that it will be useful,
00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014 // Lesser General Public License for more details.
00015 //
00016 // You should have received a copy of the GNU Lesser General Public
00017 // License along with this library; if not, write to the Free Software
00018 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00019 //
00020 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
00021 //
00022 
00023 // File      : StdMeshers_FaceSide.hxx
00024 // Created   : Wed Jan 31 18:41:25 2007
00025 // Author    : Edward AGAPOV (eap)
00026 // Module    : SMESH
00027 //
00028 #include "StdMeshers_FaceSide.hxx"
00029 
00030 #include "SMDS_EdgePosition.hxx"
00031 #include "SMDS_MeshNode.hxx"
00032 #include "SMESHDS_Mesh.hxx"
00033 #include "SMESHDS_SubMesh.hxx"
00034 #include "SMESH_Algo.hxx"
00035 #include "SMESH_Mesh.hxx"
00036 #include "SMESH_MesherHelper.hxx"
00037 #include "SMESH_ComputeError.hxx"
00038 #include "SMESH_Block.hxx"
00039 
00040 #include <Adaptor2d_Curve2d.hxx>
00041 #include <BRepAdaptor_CompCurve.hxx>
00042 #include <BRep_Builder.hxx>
00043 #include <BRep_Tool.hxx>
00044 #include <GCPnts_AbscissaPoint.hxx>
00045 #include <Geom2dAdaptor_Curve.hxx>
00046 #include <TopExp.hxx>
00047 #include <TopExp_Explorer.hxx>
00048 #include <TopoDS.hxx>
00049 #include <TopoDS_Face.hxx>
00050 #include <TopoDS_Vertex.hxx>
00051 #include <TopoDS_Wire.hxx>
00052 
00053 #include <map>
00054 
00055 #include "utilities.h"
00056 
00057 //================================================================================
00063 //================================================================================
00064 
00065 StdMeshers_FaceSide::StdMeshers_FaceSide(const TopoDS_Face& theFace,
00066                                          const TopoDS_Edge& theEdge,
00067                                          SMESH_Mesh*        theMesh,
00068                                          const bool         theIsForward,
00069                                          const bool         theIgnoreMediumNodes)
00070 {
00071   list<TopoDS_Edge> edges(1,theEdge);
00072   *this = StdMeshers_FaceSide( theFace, edges, theMesh, theIsForward, theIgnoreMediumNodes );
00073 }
00074 
00075 //================================================================================
00081 //================================================================================
00082 
00083 StdMeshers_FaceSide::StdMeshers_FaceSide(const TopoDS_Face& theFace,
00084                                          list<TopoDS_Edge>& theEdges,
00085                                          SMESH_Mesh*        theMesh,
00086                                          const bool         theIsForward,
00087                                          const bool         theIgnoreMediumNodes)
00088 {
00089   int nbEdges = theEdges.size();
00090   myEdge.resize( nbEdges );
00091   myEdgeID.resize( nbEdges );
00092   myC2d.resize( nbEdges );
00093   myC3dAdaptor.resize( nbEdges );
00094   myFirst.resize( nbEdges );
00095   myLast.resize( nbEdges );
00096   myNormPar.resize( nbEdges );
00097   myEdgeLength.resize( nbEdges );
00098   myIsUniform.resize( nbEdges, true );
00099   myLength = 0;
00100   myNbPonits = myNbSegments = 0;
00101   myMesh = theMesh;
00102   myMissingVertexNodes = false;
00103   myIgnoreMediumNodes = theIgnoreMediumNodes;
00104   myDefaultPnt2d = gp_Pnt2d( 1e+100, 1e+100 );
00105   if ( nbEdges == 0 ) return;
00106 
00107   SMESHDS_Mesh* meshDS = theMesh->GetMeshDS();
00108 
00109   int nbDegen = 0;
00110   list<TopoDS_Edge>::iterator edge = theEdges.begin();
00111   TopoDS_Iterator vExp;
00112   for ( int index = 0; edge != theEdges.end(); ++index, ++edge )
00113   {
00114     int i = theIsForward ? index : nbEdges - index - 1;
00115     myEdgeLength[i] = SMESH_Algo::EdgeLength( *edge );
00116     if ( myEdgeLength[i] < DBL_MIN ) nbDegen++;
00117     myLength += myEdgeLength[i];
00118     myEdge[i] = *edge;
00119     myEdgeID[i] = meshDS->ShapeToIndex( *edge );
00120     if ( !theIsForward ) myEdge[i].Reverse();
00121 
00122     if ( theFace.IsNull() )
00123       BRep_Tool::Range( *edge, myFirst[i], myLast[i] );
00124     else
00125       myC2d[i] = BRep_Tool::CurveOnSurface( *edge, theFace, myFirst[i], myLast[i] );
00126     if ( myEdge[i].Orientation() == TopAbs_REVERSED )
00127       std::swap( myFirst[i], myLast[i] );
00128 
00129     if ( SMESHDS_SubMesh* sm = meshDS->MeshElements( *edge )) {
00130       int nbN = sm->NbNodes();
00131       if ( theIgnoreMediumNodes ) {
00132         SMDS_ElemIteratorPtr elemIt = sm->GetElements();
00133         if ( elemIt->more() && elemIt->next()->IsQuadratic() )
00134           nbN -= sm->NbElements();
00135       }
00136       myNbPonits += nbN;
00137       myNbSegments += sm->NbElements();
00138     }
00139     // TopExp::FirstVertex() and TopExp::LastVertex() return NULL from INTERNAL edge
00140     vExp.Initialize( *edge );
00141     if ( vExp.Value().Orientation() == TopAbs_REVERSED ) vExp.Next();
00142     if ( SMESH_Algo::VertexNode( TopoDS::Vertex( vExp.Value()), meshDS ))
00143       myNbPonits += 1; // for the first end
00144     else
00145       myMissingVertexNodes = true;
00146 
00147     // check if edge has non-uniform parametrization (issue 0020705)
00148     if ( !myC2d[i].IsNull() && myEdgeLength[i] > DBL_MIN)
00149     {
00150       Geom2dAdaptor_Curve A2dC( myC2d[i] );
00151       double p2 = myFirst[i]+(myLast[i]-myFirst[i])/2., p4 = myFirst[i]+(myLast[i]-myFirst[i])/4.;
00152       double d2 = GCPnts_AbscissaPoint::Length( A2dC, myFirst[i], p2 );
00153       double d4 = GCPnts_AbscissaPoint::Length( A2dC, myFirst[i], p4 );
00154       //cout<<"len = "<<len<<"  d2 = "<<d2<<"  fabs(2*d2/len-1.0) = "<<fabs(2*d2/len-1.0)<<endl;
00155       myIsUniform[i] = !( fabs(2*d2/myEdgeLength[i]-1.0) > 0.01 || fabs(2*d4/d2-1.0) > 0.01 );
00156       if ( !myIsUniform[i] )
00157       {
00158         double fp,lp;
00159         TopLoc_Location L;
00160         Handle(Geom_Curve) C3d = BRep_Tool::Curve(myEdge[i],L,fp,lp);
00161         myC3dAdaptor[i].Load( C3d, fp,lp );
00162       }
00163     }
00164   }
00165   vExp.Initialize( theEdges.back() );
00166   if ( vExp.Value().Orientation() != TopAbs_REVERSED ) vExp.Next();
00167   if ( vExp.More() )
00168   {
00169     if ( SMESH_Algo::VertexNode( TopoDS::Vertex( vExp.Value()), meshDS ))
00170       myNbPonits++; // for the last end
00171     else
00172       myMissingVertexNodes = true;
00173   }
00174   if ( nbEdges > 1 && myLength > DBL_MIN ) {
00175     const double degenNormLen = 1.e-5;
00176     double totLength = myLength;
00177     if ( nbDegen )
00178       totLength += myLength * degenNormLen * nbDegen;
00179     double prevNormPar = 0;
00180     for ( int i = 0; i < nbEdges; ++i ) {
00181       if ( myEdgeLength[ i ] < DBL_MIN )
00182         myEdgeLength[ i ] = myLength * degenNormLen;
00183       myNormPar[ i ] = prevNormPar + myEdgeLength[i]/totLength;
00184       prevNormPar = myNormPar[ i ];
00185     }
00186   }
00187   myNormPar[nbEdges-1] = 1.;
00188   //dump();
00189 }
00190 
00191 //================================================================================
00197 //================================================================================
00198 
00199 StdMeshers_FaceSide::StdMeshers_FaceSide(const SMDS_MeshNode* theNode,
00200                                          const gp_Pnt2d thePnt2d,
00201                                          const StdMeshers_FaceSide* theSide)
00202 {
00203   myC2d.resize(1);
00204   myLength = 0;
00205   myMesh = theSide->GetMesh();
00206   myDefaultPnt2d = thePnt2d;
00207 
00208   myPoints = theSide->GetUVPtStruct();
00209   myNbPonits = myNbSegments = myPoints.size();
00210   std::vector<uvPtStruct>::iterator it = myPoints.begin();
00211   for(; it!=myPoints.end(); it++) {
00212     (*it).u = thePnt2d.X();
00213     (*it).v = thePnt2d.Y();
00214     (*it).y = 0.0;
00215     (*it).node = theNode;
00216   }
00217 }
00218 
00219 //================================================================================
00224 //================================================================================
00225 
00226 const vector<UVPtStruct>& StdMeshers_FaceSide::GetUVPtStruct(bool   isXConst,
00227                                                              double constValue) const
00228 {
00229   if ( myPoints.empty() ) {
00230 
00231     if ( NbEdges() == 0 ) return myPoints;
00232 
00233     SMESHDS_Mesh* meshDS = myMesh->GetMeshDS();
00234     SMESH_MesherHelper helper(*myMesh);
00235     bool paramOK;
00236 
00237     // sort nodes of all edges putting them into a map
00238 
00239     map< double, const SMDS_MeshNode*> u2node;
00240     //int nbOnDegen = 0;
00241     for ( int i = 0; i < myEdge.size(); ++i )
00242     {
00243       // Put 1st vertex node of a current edge
00244       TopoDS_Vertex VV[2]; // TopExp::FirstVertex() returns NULL for INTERNAL edge
00245       VV[0] = SMESH_MesherHelper::IthVertex( 0, myEdge[i]);
00246       VV[1] = SMESH_MesherHelper::IthVertex( 1, myEdge[i]);
00247       const SMDS_MeshNode* node = SMESH_Algo::VertexNode( VV[0], meshDS );
00248       double prevNormPar = ( i == 0 ? 0 : myNormPar[ i-1 ]); // normalized param
00249       if ( node ) { // internal nodes may be missing
00250         u2node.insert( make_pair( prevNormPar, node ));
00251       }
00252       else if ( i == 0 ) {
00253         MESSAGE(" NO NODE on VERTEX" );
00254         return myPoints;
00255       }
00256 
00257       // Put internal nodes
00258       SMESHDS_SubMesh* sm = meshDS->MeshElements( myEdge[i] );
00259       if ( !sm ) continue;
00260       vector< pair< double, const SMDS_MeshNode*> > u2nodeVec;
00261       u2nodeVec.reserve( sm->NbNodes() );
00262       SMDS_NodeIteratorPtr nItr = sm->GetNodes();
00263       double paramSize = myLast[i] - myFirst[i];
00264       double r = myNormPar[i] - prevNormPar;
00265       if ( !myIsUniform[i] )
00266         while ( nItr->more() )
00267         {
00268           const SMDS_MeshNode* node = nItr->next();
00269           if ( myIgnoreMediumNodes && SMESH_MeshEditor::IsMedium( node, SMDSAbs_Edge ))
00270             continue;
00271           double u = helper.GetNodeU( myEdge[i], node, 0, &paramOK );
00272           double aLenU = GCPnts_AbscissaPoint::Length
00273             ( const_cast<GeomAdaptor_Curve&>( myC3dAdaptor[i]), myFirst[i], u );
00274           if ( myEdgeLength[i] < aLenU ) // nonregression test "3D_mesh_NETGEN/G6"
00275           {
00276             u2nodeVec.clear();
00277             break;
00278           }
00279           double normPar = prevNormPar + r*aLenU/myEdgeLength[i];
00280           u2nodeVec.push_back( make_pair( normPar, node ));
00281         }
00282       nItr = sm->GetNodes();
00283       if ( u2nodeVec.empty() )
00284         while ( nItr->more() )
00285         {
00286           const SMDS_MeshNode* node = nItr->next();
00287           if ( myIgnoreMediumNodes && SMESH_MeshEditor::IsMedium( node, SMDSAbs_Edge ))
00288             continue;
00289           double u = helper.GetNodeU( myEdge[i], node, 0, &paramOK );
00290 
00291           // paramSize is signed so orientation is taken into account
00292           double normPar = prevNormPar + r * ( u - myFirst[i] ) / paramSize;
00293           u2nodeVec.push_back( make_pair( normPar, node ));
00294         }
00295       u2node.insert( u2nodeVec.begin(), u2nodeVec.end() );
00296 
00297       // Put 2nd vertex node for a last edge
00298       if ( i+1 == myEdge.size() ) {
00299         node = SMESH_Algo::VertexNode( VV[1], meshDS );
00300         if ( !node ) {
00301           MESSAGE(" NO NODE on VERTEX" );
00302           return myPoints;
00303         }
00304         u2node.insert( make_pair( 1., node ));
00305       }
00306     }
00307     if ( u2node.size() != myNbPonits ) {
00308       MESSAGE("Wrong node parameters on edges, u2node.size():"
00309               <<u2node.size()<<" !=  myNbPonits:"<<myNbPonits);
00310       return myPoints;
00311     }
00312 
00313     // fill array of UVPtStruct
00314 
00315     vector<uvPtStruct>* points = const_cast<vector<uvPtStruct>*>( &myPoints );
00316     points->resize( myNbPonits );
00317 
00318     int EdgeIndex = 0;
00319     double prevNormPar = 0, paramSize = myNormPar[ EdgeIndex ];
00320     map< double, const SMDS_MeshNode*>::iterator u_node = u2node.begin();
00321     for (int i = 0 ; u_node != u2node.end(); ++u_node, ++i ) {
00322       UVPtStruct & uvPt = (*points)[i];
00323       uvPt.node = u_node->second;
00324       uvPt.x = uvPt.y = uvPt.normParam = u_node->first;
00325       if ( isXConst ) uvPt.x = constValue;
00326       else            uvPt.y = constValue;
00327       const SMDS_EdgePosition* epos =
00328         dynamic_cast<const SMDS_EdgePosition*>(uvPt.node->GetPosition());
00329       if (( myNormPar[ EdgeIndex ] < uvPt.normParam ) ||
00330           ( epos && uvPt.node->getshapeId() != myEdgeID[ EdgeIndex ])) // for myMissingVertexNodes
00331       {
00332         prevNormPar = myNormPar[ EdgeIndex ];
00333         ++EdgeIndex;
00334 #ifdef _DEBUG_
00335         if ( EdgeIndex >= myEdge.size() ) {
00336           dump("DEBUG");
00337           MESSAGE ( "WRONg EdgeIndex " << 1+EdgeIndex
00338                     << " myNormPar.size()="<<myNormPar.size()
00339                     << " myNormPar["<< EdgeIndex<<"]="<< myNormPar[ EdgeIndex ]
00340                     << " uvPt.normParam="<<uvPt.normParam );
00341         }
00342 #endif
00343         paramSize = myNormPar[ EdgeIndex ] - prevNormPar;
00344       }
00345       if ( epos ) {
00346         uvPt.param = epos->GetUParameter();
00347       }
00348       else {
00349         double r = ( uvPt.normParam - prevNormPar )/ paramSize;
00350 //         uvPt.param = myFirst[EdgeIndex] * ( 1 - r ) + myLast[EdgeIndex] * r;
00351         uvPt.param = ( r > 0.5 ? myLast[EdgeIndex] : myFirst[EdgeIndex] );
00352       }
00353       if ( !myC2d[ EdgeIndex ].IsNull() ) {
00354         gp_Pnt2d p = myC2d[ EdgeIndex ]->Value( uvPt.param );
00355         uvPt.u = p.X();
00356         uvPt.v = p.Y();
00357       }
00358       else {
00359         uvPt.u = uvPt.v = 1e+100;
00360       }
00361     }
00362   }
00363   return myPoints;
00364 }
00365 
00366 //================================================================================
00372 //================================================================================
00373 
00374 const vector<UVPtStruct>& StdMeshers_FaceSide::SimulateUVPtStruct(int    nbSeg,
00375                                                                   bool   isXConst,
00376                                                                   double constValue) const
00377 {
00378   if ( myFalsePoints.empty() ) {
00379 
00380     if ( NbEdges() == 0 ) return myFalsePoints;
00381 
00382     vector<uvPtStruct>* points = const_cast<vector<uvPtStruct>*>( &myFalsePoints );
00383     points->resize( nbSeg+1 );
00384 
00385     int EdgeIndex = 0;
00386     double prevNormPar = 0, paramSize = myNormPar[ EdgeIndex ];
00387     for (int i = 0 ; i < myFalsePoints.size(); ++i ) {
00388       double normPar = double(i) / double(nbSeg);
00389       UVPtStruct & uvPt = (*points)[i];
00390       uvPt.node = 0;
00391       uvPt.x = uvPt.y = uvPt.param = uvPt.normParam = normPar;
00392       if ( isXConst ) uvPt.x = constValue;
00393       else            uvPt.y = constValue;
00394       if ( myNormPar[ EdgeIndex ] < normPar ) {
00395         prevNormPar = myNormPar[ EdgeIndex ];
00396         ++EdgeIndex;
00397         paramSize = myNormPar[ EdgeIndex ] - prevNormPar;
00398       }
00399       double r = ( normPar - prevNormPar )/ paramSize;
00400       uvPt.param = myFirst[EdgeIndex] * ( 1 - r ) + myLast[EdgeIndex] * r;
00401       if ( !myC2d[ EdgeIndex ].IsNull() ) {
00402         gp_Pnt2d p = myC2d[ EdgeIndex ]->Value( uvPt.param );
00403         uvPt.u = p.X();
00404         uvPt.v = p.Y();
00405       }
00406       else {
00407         uvPt.u = uvPt.v = 1e+100;
00408       }
00409     }
00410   }
00411   return myFalsePoints;
00412 }
00413 // gp_Pnt StdMeshers_FaceSide::Value(double U) const
00414 // {
00415 // }
00416 
00417 //================================================================================
00422 //================================================================================
00423 
00424 template <typename T > void reverse(vector<T> & vec)
00425 {
00426   for ( int f=0, r=vec.size()-1; f < r; ++f, --r )
00427     std::swap( vec[f], vec[r] );
00428 }
00429 
00430 //================================================================================
00434 //================================================================================
00435 
00436 void StdMeshers_FaceSide::Reverse()
00437 {
00438   int nbEdges = myEdge.size();
00439   for ( int i = nbEdges-1; i >= 0; --i ) {
00440     std::swap( myFirst[i], myLast[i] );
00441     myEdge[i].Reverse();
00442     if ( i > 0 ) // at the first loop 1. is overwritten
00443       myNormPar[i] = 1 - myNormPar[i-1];
00444   }
00445   if ( nbEdges > 1 ) {
00446     reverse( myEdge );
00447     reverse( myEdgeID );
00448     reverse( myC2d );
00449     reverse( myC3dAdaptor );
00450     reverse( myFirst );
00451     reverse( myLast );
00452     reverse( myNormPar );
00453     reverse( myEdgeLength );
00454     reverse( myIsUniform );
00455   }
00456   if ( nbEdges > 0 )
00457   {
00458     myNormPar[nbEdges-1]=1.;
00459     myPoints.clear();
00460     myFalsePoints.clear();
00461   }
00462 }
00463 
00464 //================================================================================
00468 //================================================================================
00469 
00470 void StdMeshers_FaceSide::dump(const char* msg) const
00471 {
00472 #ifdef _DEBUG_
00473   if (msg) MESSAGE ( std::endl << msg );
00474   MESSAGE_BEGIN ("NB EDGES: "<< myEdge.size() );
00475   MESSAGE_ADD ( "nbPoints: "<<myNbPonits<<" vecSize: " << myPoints.size()<<" "<<myFalsePoints.size() );
00476   for ( int i=0; i<myEdge.size(); ++i)
00477   {
00478     MESSAGE_ADD ( "\t"<<i+1 );
00479     MESSAGE_ADD ( "\tEDGE: " );
00480     if (myEdge[i].IsNull()) {
00481       MESSAGE_ADD ( "NULL" );
00482     }
00483     else {
00484       TopAbs::Print(myEdge[i].Orientation(),cout)<<" "<<myEdge[i].TShape().operator->()<<endl;
00485       MESSAGE_ADD ( "\tV1: " << TopExp::FirstVertex( myEdge[i], 1).TShape().operator->()
00486                  << "  V2: " << TopExp::LastVertex( myEdge[i], 1).TShape().operator->() );
00487     }
00488     MESSAGE_ADD ( "\tC2d: ");
00489     
00490     if (myC2d[i].IsNull()) {
00491       MESSAGE_ADD ( "NULL" );
00492     }
00493     else {
00494       MESSAGE_ADD ( myC2d[i].operator->() );
00495     }
00496       
00497     MESSAGE_ADD ( "\tF: "<<myFirst[i]<< " L: "<< myLast[i] );
00498     MESSAGE_END ( "\tnormPar: "<<myNormPar[i]<<endl );
00499   }
00500 #endif
00501 }
00502 
00503 //================================================================================
00508 //================================================================================
00509 
00510 struct Adaptor2dCurve2d : public Adaptor2d_Curve2d
00511 {
00512   const StdMeshers_FaceSide* mySide;
00513   Adaptor2dCurve2d(const StdMeshers_FaceSide* faceSide):mySide(faceSide) {}
00514   gp_Pnt2d Value(const Standard_Real U) const { return mySide->Value2d( U ); }
00515   Standard_Real FirstParameter() const { return 0; }
00516   Standard_Real LastParameter() const { return 1; }
00517 };
00518 
00519 Adaptor2d_Curve2d* StdMeshers_FaceSide::GetCurve2d() const
00520 {
00521   return new Adaptor2dCurve2d( this );
00522 }
00523 
00524 //================================================================================
00528 //================================================================================
00529 
00530 BRepAdaptor_CompCurve* StdMeshers_FaceSide::GetCurve3d() const
00531 {
00532   if ( myEdge.empty() )
00533     return 0;
00534 
00535   TopoDS_Wire aWire;
00536   BRep_Builder aBuilder;
00537   aBuilder.MakeWire(aWire);
00538   for ( int i=0; i<myEdge.size(); ++i )
00539     aBuilder.Add( aWire, myEdge[i] );
00540 
00541   if ( myEdge.size() == 2 && FirstVertex().IsSame( LastVertex() ))
00542     aWire.Closed(true); // issue 0021141
00543 
00544   return new BRepAdaptor_CompCurve( aWire );
00545 }
00546 
00547 
00548 //================================================================================
00554 //================================================================================
00555 
00556 gp_Pnt2d StdMeshers_FaceSide::Value2d(double U) const
00557 {
00558   if ( !myC2d[0].IsNull() ) {
00559     int i = EdgeIndex( U );
00560     double prevU = i ? myNormPar[ i-1 ] : 0;
00561     double r = ( U - prevU )/ ( myNormPar[ i ] - prevU );
00562 
00563     double par = myFirst[i] * ( 1 - r ) + myLast[i] * r;
00564     
00565     // check parametrization of curve
00566     if( !myIsUniform[i] )
00567     {
00568       double aLen3dU = r * myEdgeLength[i] * ( myFirst[i]>myLast[i] ? -1. : 1.);
00569       GCPnts_AbscissaPoint AbPnt
00570         ( const_cast<GeomAdaptor_Curve&>( myC3dAdaptor[i]), aLen3dU, myFirst[i] );
00571       if( AbPnt.IsDone() ) {
00572         par = AbPnt.Parameter();
00573       }
00574     }
00575     return myC2d[ i ]->Value(par);
00576 
00577   }
00578   return myDefaultPnt2d;
00579 }
00580 
00581 //================================================================================
00585 //================================================================================
00586 
00587 TSideVector StdMeshers_FaceSide::GetFaceWires(const TopoDS_Face& theFace,
00588                                               SMESH_Mesh &       theMesh,
00589                                               const bool         theIgnoreMediumNodes,
00590                                               TError &           theError)
00591 {
00592   TopoDS_Vertex V1;
00593   list< TopoDS_Edge > edges, internalEdges;
00594   list< int > nbEdgesInWires;
00595   int nbWires = SMESH_Block::GetOrderedEdges (theFace, V1, edges, nbEdgesInWires);
00596 
00597   // split list of all edges into separate wires
00598   TSideVector wires( nbWires );
00599   list< int >::iterator nbE = nbEdgesInWires.begin();
00600   list< TopoDS_Edge >::iterator from = edges.begin(), to = from;
00601   for ( int iW = 0; iW < nbWires; ++iW, ++nbE )
00602   {
00603     std::advance( to, *nbE );
00604     if ( *nbE == 0 ) // Issue 0020676
00605     {
00606       --nbWires;
00607       --iW;
00608       wires.resize( nbWires );
00609       continue;
00610     }
00611     list< TopoDS_Edge > wireEdges( from, to );
00612     // assure that there is a node on the first vertex
00613     // as StdMeshers_FaceSide::GetUVPtStruct() requires
00614     if ( wireEdges.front().Orientation() != TopAbs_INTERNAL ) // Issue 0020676
00615     {
00616       while ( !SMESH_Algo::VertexNode( TopExp::FirstVertex( wireEdges.front(), true),
00617                                        theMesh.GetMeshDS()))
00618       {
00619         wireEdges.splice(wireEdges.end(), wireEdges,
00620                          wireEdges.begin(), ++wireEdges.begin());
00621         if ( from->IsSame( wireEdges.front() )) {
00622           theError = TError
00623             ( new SMESH_ComputeError(COMPERR_BAD_INPUT_MESH,"No nodes on vertices"));
00624           return TSideVector(0);
00625         }
00626       }
00627     }
00628     else if ( *nbE > 1 ) // Issue 0020676 (Face_pb_netgen.brep) - several internal edges in a wire
00629     {
00630       internalEdges.splice( internalEdges.end(), wireEdges, ++wireEdges.begin(), wireEdges.end());
00631     }
00632 
00633     StdMeshers_FaceSide* wire = new StdMeshers_FaceSide( theFace, wireEdges, &theMesh,
00634                                                          /*isForward=*/true, theIgnoreMediumNodes);
00635     wires[ iW ] = StdMeshers_FaceSidePtr( wire );
00636     from = to;
00637   }
00638   while ( !internalEdges.empty() )
00639   {
00640     StdMeshers_FaceSide* wire = new StdMeshers_FaceSide( theFace, internalEdges.back(), &theMesh,
00641                                                          /*isForward=*/true, theIgnoreMediumNodes);
00642     wires.push_back( StdMeshers_FaceSidePtr( wire ));
00643     internalEdges.pop_back();
00644   }
00645   return wires;
00646 }
00647 
00648 //================================================================================
00652 //================================================================================
00653 
00654 TopoDS_Vertex StdMeshers_FaceSide::FirstVertex(int i) const
00655 {
00656   TopoDS_Vertex v;
00657   if ( i < NbEdges() )
00658   {
00659     v = myEdge[i].Orientation() <= TopAbs_REVERSED ? // FORWARD || REVERSED
00660         TopExp::FirstVertex( myEdge[i], 1 )        :
00661         TopoDS::Vertex( TopoDS_Iterator( myEdge[i] ).Value() );
00662   }
00663   return v;
00664 }
00665 
00666 //================================================================================
00670 //================================================================================
00671 
00672 TopoDS_Vertex StdMeshers_FaceSide::LastVertex(int i) const
00673 {
00674   TopoDS_Vertex v;
00675   if ( i < NbEdges() )
00676   {
00677     const TopoDS_Edge& edge = i<0 ? myEdge[ NbEdges() + i ] : myEdge[i];
00678     if ( edge.Orientation() <= TopAbs_REVERSED ) // FORWARD || REVERSED
00679       v = TopExp::LastVertex( edge, 1 );
00680     else
00681       for ( TopoDS_Iterator vIt( edge ); vIt.More(); vIt.Next() )
00682         v = TopoDS::Vertex( vIt.Value() );
00683   }
00684   return v;
00685 }
00686 
Copyright © 2007-2011 CEA/DEN, EDF R&D, OPEN CASCADE
Copyright © 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS