/src/contrib/geom-5.1.2.7/src/BlockFix/BlockFix_PeriodicSurfaceModifier.cpp

http://pythonocc.googlecode.com/ · C++ · 250 lines · 138 code · 47 blank · 65 comment · 9 complexity · 536e3455a323e601be05b61243a53c40 MD5 · raw file

  1. // Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE
  2. //
  3. // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
  4. // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
  5. //
  6. // This library is free software; you can redistribute it and/or
  7. // modify it under the terms of the GNU Lesser General Public
  8. // License as published by the Free Software Foundation; either
  9. // version 2.1 of the License.
  10. //
  11. // This library is distributed in the hope that it will be useful,
  12. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. // Lesser General Public License for more details.
  15. //
  16. // You should have received a copy of the GNU Lesser General Public
  17. // License along with this library; if not, write to the Free Software
  18. // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  19. //
  20. // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
  21. //
  22. // File: BlockFix_PeriodicSurfaceModifier.cxx
  23. // Created: 15.12.04 10:08:50
  24. // Author: Sergey KUUL
  25. //
  26. #include <BlockFix_PeriodicSurfaceModifier.ixx>
  27. #include <BRep_Builder.hxx>
  28. #include <BRep_Tool.hxx>
  29. #include <BRepTools.hxx>
  30. #include <Geom_CylindricalSurface.hxx>
  31. #include <Geom_SphericalSurface.hxx>
  32. #include <ShapeFix_Edge.hxx>
  33. #include <TopExp.hxx>
  34. //=======================================================================
  35. //function : BlockFix_PeriodicSurfaceModifier()
  36. //purpose : Constructor
  37. //=======================================================================
  38. BlockFix_PeriodicSurfaceModifier::BlockFix_PeriodicSurfaceModifier ( )
  39. {
  40. myMapOfFaces.Clear();
  41. myMapOfSurfaces.Clear();
  42. }
  43. //=======================================================================
  44. //function : SetTolerance
  45. //purpose :
  46. //=======================================================================
  47. void BlockFix_PeriodicSurfaceModifier::SetTolerance(const Standard_Real Tol)
  48. {
  49. myTolerance = Tol;
  50. }
  51. //=======================================================================
  52. //function : ModifySurface
  53. //purpose : auxilary
  54. //=======================================================================
  55. static Standard_Boolean ModifySurface(const TopoDS_Face& aFace,
  56. const Handle(Geom_Surface)& aSurface,
  57. Handle(Geom_Surface)& aNewSurface)
  58. {
  59. Handle(Geom_Surface) S = aSurface;
  60. if(S->IsKind(STANDARD_TYPE(Geom_CylindricalSurface))) {
  61. Handle(Geom_CylindricalSurface) aCyl =
  62. Handle(Geom_CylindricalSurface)::DownCast(S);
  63. Standard_Real Umin, Umax, Vmin, Vmax;
  64. BRepTools::UVBounds(aFace, Umin, Umax, Vmin, Vmax);
  65. if( Umin<-Precision::PConfusion() || Umax>2*PI+Precision::PConfusion() ) {
  66. gp_Ax3 ax3 = aCyl->Position();
  67. gp_Ax1 NDir = ax3.Axis();
  68. gp_Ax3 newax3 = ax3.Rotated(NDir,Umin-Precision::PConfusion());
  69. Handle(Geom_CylindricalSurface) aNewCyl =
  70. new Geom_CylindricalSurface(newax3,aCyl->Radius());
  71. aNewSurface = aNewCyl;
  72. return Standard_True;
  73. }
  74. }
  75. if(S->IsKind(STANDARD_TYPE(Geom_SphericalSurface))) {
  76. Handle(Geom_SphericalSurface) aSphere = Handle(Geom_SphericalSurface)::DownCast(S);
  77. Standard_Real Umin, Umax, Vmin, Vmax;
  78. BRepTools::UVBounds(aFace, Umin, Umax, Vmin, Vmax);
  79. if( Umin<-Precision::PConfusion() || Umax>2*PI+Precision::PConfusion() ) {
  80. gp_Ax3 ax3 = aSphere->Position();
  81. gp_Ax1 NDir = ax3.Axis();
  82. gp_Ax3 newax3 = ax3.Rotated(NDir,Umin-Precision::PConfusion());
  83. Handle(Geom_SphericalSurface) aNewSphere = new Geom_SphericalSurface(newax3,aSphere->Radius());
  84. aNewSurface = aNewSphere;
  85. return Standard_True;
  86. }
  87. }
  88. return Standard_False;
  89. }
  90. //=======================================================================
  91. //function : NewSurface
  92. //purpose :
  93. //=======================================================================
  94. Standard_Boolean BlockFix_PeriodicSurfaceModifier::NewSurface(const TopoDS_Face& F,
  95. Handle(Geom_Surface)& S,
  96. TopLoc_Location& L,Standard_Real& Tol,
  97. Standard_Boolean& RevWires,
  98. Standard_Boolean& RevFace)
  99. {
  100. TopLoc_Location LS;
  101. Handle(Geom_Surface) SIni = BRep_Tool::Surface(F, LS);
  102. if(ModifySurface(F, SIni, S)) {
  103. RevWires = Standard_False;
  104. RevFace = Standard_False;
  105. L = LS;
  106. Tol = BRep_Tool::Tolerance(F);
  107. Standard_Integer anIndex = myMapOfSurfaces.Add(S);
  108. myMapOfFaces.Bind(F,anIndex);
  109. return Standard_True;
  110. }
  111. return Standard_False;
  112. }
  113. //=======================================================================
  114. //function : NewCurve
  115. //purpose :
  116. //=======================================================================
  117. Standard_Boolean BlockFix_PeriodicSurfaceModifier::NewCurve(const TopoDS_Edge& /*E*/,
  118. Handle(Geom_Curve)& /*C*/,
  119. TopLoc_Location& /*L*/,
  120. Standard_Real& /*Tol*/)
  121. {
  122. return Standard_False;
  123. }
  124. //=======================================================================
  125. //function : NewPoint
  126. //purpose :
  127. //=======================================================================
  128. Standard_Boolean BlockFix_PeriodicSurfaceModifier::NewPoint(const TopoDS_Vertex& /*V*/,
  129. gp_Pnt& /*P*/,
  130. Standard_Real& /*Tol*/)
  131. {
  132. return Standard_False;
  133. }
  134. //=======================================================================
  135. //function : NewCurve2d
  136. //purpose :
  137. //=======================================================================
  138. Standard_Boolean BlockFix_PeriodicSurfaceModifier::NewCurve2d(const TopoDS_Edge& E,
  139. const TopoDS_Face& F,
  140. const TopoDS_Edge& /*NewE*/,
  141. const TopoDS_Face& /*NewF*/,
  142. Handle(Geom2d_Curve)& C,
  143. Standard_Real& Tol)
  144. {
  145. //check if undelying surface of the face was modified
  146. if(myMapOfFaces.IsBound(F)) {
  147. Standard_Integer anIndex = myMapOfFaces.Find(F);
  148. Handle(Geom_Surface) aNewSurf = Handle(Geom_Surface)::DownCast(myMapOfSurfaces.FindKey(anIndex));
  149. Standard_Real f,l;
  150. TopLoc_Location LC, LS;
  151. Handle(Geom_Curve) C3d = BRep_Tool::Curve ( E, LC, f, l );
  152. Handle(Geom_Surface) S = BRep_Tool::Surface(F, LS);
  153. //taking into accound the orientation of the seam
  154. C = BRep_Tool::CurveOnSurface(E,F,f,l);
  155. Tol = BRep_Tool::Tolerance(E);
  156. BRep_Builder B;
  157. TopoDS_Edge TempE;
  158. B.MakeEdge(TempE);
  159. B.Add(TempE, TopExp::FirstVertex(E));
  160. B.Add(TempE, TopExp::LastVertex(E));
  161. if(!C3d.IsNull())
  162. B.UpdateEdge(TempE, Handle(Geom_Curve)::DownCast(C3d->Transformed(LC.Transformation())), Precision::Confusion());
  163. B.Range(TempE, f, l);
  164. Handle(ShapeFix_Edge) sfe = new ShapeFix_Edge;
  165. Handle(Geom_Surface) STemp = Handle(Geom_Surface)::DownCast(aNewSurf->Transformed(LS.Transformation()));
  166. TopLoc_Location LTemp;
  167. LTemp.Identity();
  168. Standard_Boolean isClosed = BRep_Tool::IsClosed (E, F);
  169. Standard_Real aWorkTol = 2*myTolerance+Tol;
  170. sfe->FixAddPCurve(TempE, STemp, LTemp, isClosed, Max(Precision::Confusion(), aWorkTol));
  171. sfe->FixSameParameter(TempE);
  172. //keep the orientation of original edge
  173. TempE.Orientation(E.Orientation());
  174. C = BRep_Tool::CurveOnSurface(TempE, STemp, LTemp, f, l);
  175. //surface was modified
  176. return Standard_True;
  177. }
  178. return Standard_False;
  179. }
  180. //=======================================================================
  181. //function : NewParameter
  182. //purpose :
  183. //=======================================================================
  184. Standard_Boolean BlockFix_PeriodicSurfaceModifier::NewParameter(const TopoDS_Vertex& /*V*/,
  185. const TopoDS_Edge& /*E*/,
  186. Standard_Real& /*P*/,
  187. Standard_Real& /*Tol*/)
  188. {
  189. return Standard_False;
  190. }
  191. //=======================================================================
  192. //function : Continuity
  193. //purpose :
  194. //=======================================================================
  195. GeomAbs_Shape BlockFix_PeriodicSurfaceModifier::Continuity(const TopoDS_Edge& E,
  196. const TopoDS_Face& F1,
  197. const TopoDS_Face& F2,
  198. const TopoDS_Edge& /*NewE*/,
  199. const TopoDS_Face& /*NewF1*/,
  200. const TopoDS_Face& /*NewF2*/)
  201. {
  202. return BRep_Tool::Continuity(E,F1,F2);
  203. }