Back to index

salome-geom  6.5.0
BlockFix_PeriodicSurfaceModifier.cxx
Go to the documentation of this file.
00001 // Copyright (C) 2007-2012  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:      BlockFix_PeriodicSurfaceModifier.cxx
00024 // Created:   15.12.04 10:08:50
00025 // Author:    Sergey KUUL
00026 
00027 #include <BlockFix_PeriodicSurfaceModifier.ixx>
00028 
00029 #include <BRep_Builder.hxx>
00030 #include <BRep_Tool.hxx>
00031 #include <BRepTools.hxx>
00032 #include <Geom_CylindricalSurface.hxx>
00033 #include <Geom_SphericalSurface.hxx>
00034 #include <ShapeFix_Edge.hxx>
00035 #include <TopExp.hxx>
00036 
00037 
00038 //=======================================================================
00039 //function : BlockFix_PeriodicSurfaceModifier()
00040 //purpose  : Constructor
00041 //=======================================================================
00042 
00043 BlockFix_PeriodicSurfaceModifier::BlockFix_PeriodicSurfaceModifier (  )
00044 {
00045   myMapOfFaces.Clear();
00046   myMapOfSurfaces.Clear();
00047 }
00048 
00049 
00050 //=======================================================================
00051 //function : SetTolerance
00052 //purpose  :
00053 //=======================================================================
00054 
00055 void BlockFix_PeriodicSurfaceModifier::SetTolerance(const Standard_Real Tol)
00056 {
00057   myTolerance = Tol;
00058 }
00059 
00060 
00061 //=======================================================================
00062 //function : ModifySurface
00063 //purpose  : auxilary
00064 //=======================================================================
00065 
00066 static Standard_Boolean ModifySurface(const TopoDS_Face& aFace,
00067                                       const Handle(Geom_Surface)& aSurface,
00068                                       Handle(Geom_Surface)& aNewSurface)
00069 {
00070   Handle(Geom_Surface) S = aSurface;
00071 
00072   if(S->IsKind(STANDARD_TYPE(Geom_CylindricalSurface))) {
00073     Handle(Geom_CylindricalSurface) aCyl =
00074       Handle(Geom_CylindricalSurface)::DownCast(S);
00075     Standard_Real Umin, Umax, Vmin, Vmax;
00076     BRepTools::UVBounds(aFace, Umin, Umax, Vmin, Vmax);
00077     if (Umin < -Precision::PConfusion() || Umax > 2*M_PI + Precision::PConfusion()) {
00078       gp_Ax3 ax3 = aCyl->Position();
00079       gp_Ax1 NDir = ax3.Axis();
00080       gp_Ax3 newax3 = ax3.Rotated(NDir,Umin-Precision::PConfusion());
00081       Handle(Geom_CylindricalSurface) aNewCyl =
00082         new Geom_CylindricalSurface(newax3,aCyl->Radius());
00083       aNewSurface = aNewCyl;
00084       return Standard_True;
00085     }
00086   }
00087 
00088   if(S->IsKind(STANDARD_TYPE(Geom_SphericalSurface))) {
00089     Handle(Geom_SphericalSurface) aSphere = Handle(Geom_SphericalSurface)::DownCast(S);
00090     Standard_Real Umin, Umax, Vmin, Vmax;
00091     BRepTools::UVBounds(aFace, Umin, Umax, Vmin, Vmax);
00092     if (Umin < -Precision::PConfusion() || Umax > 2*M_PI + Precision::PConfusion()) {
00093       gp_Ax3 ax3 = aSphere->Position();
00094       gp_Ax1 NDir = ax3.Axis();
00095       gp_Ax3 newax3 = ax3.Rotated(NDir,Umin-Precision::PConfusion());
00096       Handle(Geom_SphericalSurface) aNewSphere = new Geom_SphericalSurface(newax3,aSphere->Radius());
00097       aNewSurface = aNewSphere;
00098       return Standard_True;
00099     }
00100   }
00101 
00102   return Standard_False;
00103 }
00104 
00105 
00106 //=======================================================================
00107 //function : NewSurface
00108 //purpose  :
00109 //=======================================================================
00110 
00111 Standard_Boolean BlockFix_PeriodicSurfaceModifier::NewSurface(const TopoDS_Face& F,
00112                                                               Handle(Geom_Surface)& S,
00113                                                               TopLoc_Location& L,Standard_Real& Tol,
00114                                                               Standard_Boolean& RevWires,
00115                                                               Standard_Boolean& RevFace)
00116 {
00117   TopLoc_Location LS;
00118   Handle(Geom_Surface) SIni = BRep_Tool::Surface(F, LS);
00119 
00120   if(ModifySurface(F, SIni, S)) {
00121 
00122     RevWires = Standard_False;
00123     RevFace = Standard_False;
00124 
00125     L = LS;
00126     Tol = BRep_Tool::Tolerance(F);
00127 
00128     Standard_Integer anIndex = myMapOfSurfaces.Add(S);
00129     myMapOfFaces.Bind(F,anIndex);
00130     return Standard_True;
00131   }
00132 
00133   return Standard_False;
00134 }
00135 
00136 
00137 //=======================================================================
00138 //function : NewCurve
00139 //purpose  :
00140 //=======================================================================
00141 
00142 Standard_Boolean BlockFix_PeriodicSurfaceModifier::NewCurve(const TopoDS_Edge& /*E*/,
00143                                                             Handle(Geom_Curve)& /*C*/,
00144                                                             TopLoc_Location& /*L*/,
00145                                                             Standard_Real& /*Tol*/)
00146 {
00147   return Standard_False;
00148 }
00149 
00150 
00151 //=======================================================================
00152 //function : NewPoint
00153 //purpose  :
00154 //=======================================================================
00155 
00156 Standard_Boolean BlockFix_PeriodicSurfaceModifier::NewPoint(const TopoDS_Vertex& /*V*/,
00157                                                             gp_Pnt& /*P*/,
00158                                                             Standard_Real& /*Tol*/)
00159 {
00160   return Standard_False;
00161 }
00162 
00163 
00164 //=======================================================================
00165 //function : NewCurve2d
00166 //purpose  :
00167 //=======================================================================
00168 
00169 Standard_Boolean BlockFix_PeriodicSurfaceModifier::NewCurve2d(const TopoDS_Edge& E,
00170                                                               const TopoDS_Face& F,
00171                                                               const TopoDS_Edge& /*NewE*/,
00172                                                               const TopoDS_Face& /*NewF*/,
00173                                                               Handle(Geom2d_Curve)& C,
00174                                                               Standard_Real& Tol)
00175 {
00176   //check if undelying surface of the face was modified
00177   if(myMapOfFaces.IsBound(F)) {
00178     Standard_Integer anIndex = myMapOfFaces.Find(F);
00179 
00180     Handle(Geom_Surface) aNewSurf = Handle(Geom_Surface)::DownCast(myMapOfSurfaces.FindKey(anIndex));
00181 
00182     Standard_Real f,l;
00183     TopLoc_Location LC, LS;
00184     Handle(Geom_Curve) C3d = BRep_Tool::Curve ( E, LC, f, l );
00185     Handle(Geom_Surface) S = BRep_Tool::Surface(F, LS);
00186 
00187     //taking into accound the orientation of the seam
00188     C = BRep_Tool::CurveOnSurface(E,F,f,l);
00189     Tol = BRep_Tool::Tolerance(E);
00190 
00191     BRep_Builder B;
00192     TopoDS_Edge TempE;
00193     B.MakeEdge(TempE);
00194     B.Add(TempE, TopExp::FirstVertex(E));
00195     B.Add(TempE, TopExp::LastVertex(E));
00196 
00197     if(!C3d.IsNull())
00198       B.UpdateEdge(TempE, Handle(Geom_Curve)::DownCast(C3d->Transformed(LC.Transformation())), Precision::Confusion());
00199     B.Range(TempE, f, l);
00200 
00201     Handle(ShapeFix_Edge) sfe = new ShapeFix_Edge;
00202     Handle(Geom_Surface) STemp = Handle(Geom_Surface)::DownCast(aNewSurf->Transformed(LS.Transformation()));
00203     TopLoc_Location LTemp;
00204     LTemp.Identity();
00205 
00206     Standard_Boolean isClosed = BRep_Tool::IsClosed (E, F);
00207     Standard_Real aWorkTol = 2*myTolerance+Tol;
00208     sfe->FixAddPCurve(TempE, STemp, LTemp, isClosed, Max(Precision::Confusion(), aWorkTol));
00209     sfe->FixSameParameter(TempE);
00210 
00211     //keep the orientation of original edge
00212     TempE.Orientation(E.Orientation());
00213     C = BRep_Tool::CurveOnSurface(TempE, STemp, LTemp, f, l);
00214 
00215     //surface was modified
00216     return Standard_True;
00217   }
00218 
00219   return Standard_False;
00220 }
00221 
00222 
00223 //=======================================================================
00224 //function : NewParameter
00225 //purpose  :
00226 //=======================================================================
00227 
00228 Standard_Boolean BlockFix_PeriodicSurfaceModifier::NewParameter(const TopoDS_Vertex& /*V*/,
00229                                                                 const TopoDS_Edge& /*E*/,
00230                                                                 Standard_Real& /*P*/,
00231                                                                 Standard_Real& /*Tol*/)
00232 {
00233   return Standard_False;
00234 }
00235 
00236 
00237 //=======================================================================
00238 //function : Continuity
00239 //purpose  :
00240 //=======================================================================
00241 
00242 GeomAbs_Shape BlockFix_PeriodicSurfaceModifier::Continuity(const TopoDS_Edge& E,
00243                                                            const TopoDS_Face& F1,
00244                                                            const TopoDS_Face& F2,
00245                                                            const TopoDS_Edge& /*NewE*/,
00246                                                            const TopoDS_Face& /*NewF1*/,
00247                                                            const TopoDS_Face& /*NewF2*/)
00248 {
00249   return BRep_Tool::Continuity(E,F1,F2);
00250 }
00251