From fff55ee5fcac3d9198e917b48a7ced8fca5d53e7 Mon Sep 17 00:00:00 2001 From: Pasukhin Dmitry Date: Mon, 15 Dec 2025 20:38:53 +0000 Subject: [PATCH] Modeling Algorithms - Refactor IntCurveSurface and HLRBRep intersection packages (#912) Modernized curve/surface intersection algorithms by replacing preprocessor-based generic programming (.gxx macros) with C++ templates (.pxx headers): IntCurveSurface package (TKGeomAlgo): - Introduced IntCurveSurface_Inter.pxx with callback-based template functions for intersection algorithms, replacing IntCurveSurface_Inter.gxx - Created IntCurveSurface_InterUtils.pxx with utility template functions for surface decomposition, UV clamping, and quadric intersection handling - Added IntCurveSurface_PolygonUtils.pxx for polygon construction utilities - Added IntCurveSurface_PolyhedronUtils.pxx for polyhedron construction utilities - Added IntCurveSurface_QuadricCurveExactInterUtils.pxx for exact quadric intersection computations - Converted standalone implementation files from macro instantiation (_0.cxx) to direct template usage (.cxx) - Removed obsolete .gxx and .lxx files HLRBRep package (TKHLR): - Updated HLRBRep_InterCSurf to use new IntCurveSurface template utilities - Converted HLRBRep polygon, polyhedron, and intersection classes to use modern template instantiation pattern - Removed legacy macro-based instantiation files (_0.cxx) This refactoring improves code maintainability, enables better IDE support and debugging, and aligns with modern C++ practices while preserving the existing API and functionality. --- .../TKGeomAlgo/IntCurveSurface/FILES.cmake | 26 +- .../IntCurveSurface_HInter.cxx | 584 +++++ .../IntCurveSurface_HInter_0.cxx | 75 - .../IntCurveSurface/IntCurveSurface_Inter.gxx | 2285 ----------------- .../IntCurveSurface/IntCurveSurface_Inter.pxx | 971 +++++++ .../IntCurveSurface_InterUtils.pxx | 1512 +++++++++++ .../IntCurveSurface_Polygon.gxx | 263 -- .../IntCurveSurface_PolygonTool.lxx | 58 - .../IntCurveSurface_PolygonUtils.pxx | 206 ++ .../IntCurveSurface_Polyhedron.gxx | 951 ------- .../IntCurveSurface_Polyhedron.lxx | 24 - .../IntCurveSurface_PolyhedronTool.lxx | 89 - .../IntCurveSurface_PolyhedronUtils.pxx | 239 ++ ...IntCurveSurface_QuadricCurveExactInter.gxx | 150 -- ...rveSurface_QuadricCurveExactInterUtils.pxx | 134 + .../IntCurveSurface_ThePolygonOfHInter.cxx | 143 ++ .../IntCurveSurface_ThePolygonOfHInter_0.cxx | 31 - ...ntCurveSurface_ThePolygonToolOfHInter.cxx} | 0 ...IntCurveSurface_ThePolygonToolOfHInter.hxx | 61 +- .../IntCurveSurface_ThePolyhedronOfHInter.cxx | 786 ++++++ .../IntCurveSurface_ThePolyhedronOfHInter.hxx | 18 +- ...ntCurveSurface_ThePolyhedronOfHInter_0.cxx | 32 - ...urveSurface_ThePolyhedronToolOfHInter.cxx} | 0 ...CurveSurface_ThePolyhedronToolOfHInter.hxx | 68 +- ...IntCurveSurface_TheQuadCurvExactHInter.cxx | 80 + ...tCurveSurface_TheQuadCurvExactHInter_0.cxx | 38 - ...eQuadCurvFuncOfTheQuadCurvExactHInter.cxx} | 0 .../TKHLR/HLRBRep/FILES.cmake | 8 +- .../TKHLR/HLRBRep/HLRBRep_InterCSurf.cxx | 583 +++++ .../TKHLR/HLRBRep/HLRBRep_InterCSurf_0.cxx | 73 - .../HLRBRep_ThePolygonOfInterCSurf.cxx | 137 + .../HLRBRep_ThePolygonOfInterCSurf_0.cxx | 31 - .../HLRBRep_ThePolygonToolOfInterCSurf.hxx | 63 +- .../HLRBRep_ThePolyhedronOfInterCSurf.cxx | 781 ++++++ .../HLRBRep_ThePolyhedronOfInterCSurf.hxx | 18 +- .../HLRBRep_ThePolyhedronOfInterCSurf_0.cxx | 31 - .../HLRBRep_ThePolyhedronToolOfInterCSurf.hxx | 67 +- .../HLRBRep_TheQuadCurvExactInterCSurf.cxx | 78 + .../HLRBRep_TheQuadCurvExactInterCSurf_0.cxx | 37 - 39 files changed, 6384 insertions(+), 4347 deletions(-) create mode 100644 src/ModelingAlgorithms/TKGeomAlgo/IntCurveSurface/IntCurveSurface_HInter.cxx delete mode 100644 src/ModelingAlgorithms/TKGeomAlgo/IntCurveSurface/IntCurveSurface_HInter_0.cxx delete mode 100644 src/ModelingAlgorithms/TKGeomAlgo/IntCurveSurface/IntCurveSurface_Inter.gxx create mode 100644 src/ModelingAlgorithms/TKGeomAlgo/IntCurveSurface/IntCurveSurface_Inter.pxx create mode 100644 src/ModelingAlgorithms/TKGeomAlgo/IntCurveSurface/IntCurveSurface_InterUtils.pxx delete mode 100644 src/ModelingAlgorithms/TKGeomAlgo/IntCurveSurface/IntCurveSurface_Polygon.gxx delete mode 100644 src/ModelingAlgorithms/TKGeomAlgo/IntCurveSurface/IntCurveSurface_PolygonTool.lxx create mode 100644 src/ModelingAlgorithms/TKGeomAlgo/IntCurveSurface/IntCurveSurface_PolygonUtils.pxx delete mode 100644 src/ModelingAlgorithms/TKGeomAlgo/IntCurveSurface/IntCurveSurface_Polyhedron.gxx delete mode 100644 src/ModelingAlgorithms/TKGeomAlgo/IntCurveSurface/IntCurveSurface_Polyhedron.lxx delete mode 100644 src/ModelingAlgorithms/TKGeomAlgo/IntCurveSurface/IntCurveSurface_PolyhedronTool.lxx create mode 100644 src/ModelingAlgorithms/TKGeomAlgo/IntCurveSurface/IntCurveSurface_PolyhedronUtils.pxx delete mode 100644 src/ModelingAlgorithms/TKGeomAlgo/IntCurveSurface/IntCurveSurface_QuadricCurveExactInter.gxx create mode 100644 src/ModelingAlgorithms/TKGeomAlgo/IntCurveSurface/IntCurveSurface_QuadricCurveExactInterUtils.pxx create mode 100644 src/ModelingAlgorithms/TKGeomAlgo/IntCurveSurface/IntCurveSurface_ThePolygonOfHInter.cxx delete mode 100644 src/ModelingAlgorithms/TKGeomAlgo/IntCurveSurface/IntCurveSurface_ThePolygonOfHInter_0.cxx rename src/ModelingAlgorithms/TKGeomAlgo/IntCurveSurface/{IntCurveSurface_ThePolygonToolOfHInter_0.cxx => IntCurveSurface_ThePolygonToolOfHInter.cxx} (100%) create mode 100644 src/ModelingAlgorithms/TKGeomAlgo/IntCurveSurface/IntCurveSurface_ThePolyhedronOfHInter.cxx delete mode 100644 src/ModelingAlgorithms/TKGeomAlgo/IntCurveSurface/IntCurveSurface_ThePolyhedronOfHInter_0.cxx rename src/ModelingAlgorithms/TKGeomAlgo/IntCurveSurface/{IntCurveSurface_ThePolyhedronToolOfHInter_0.cxx => IntCurveSurface_ThePolyhedronToolOfHInter.cxx} (100%) create mode 100644 src/ModelingAlgorithms/TKGeomAlgo/IntCurveSurface/IntCurveSurface_TheQuadCurvExactHInter.cxx delete mode 100644 src/ModelingAlgorithms/TKGeomAlgo/IntCurveSurface/IntCurveSurface_TheQuadCurvExactHInter_0.cxx rename src/ModelingAlgorithms/TKGeomAlgo/IntCurveSurface/{IntCurveSurface_TheQuadCurvFuncOfTheQuadCurvExactHInter_0.cxx => IntCurveSurface_TheQuadCurvFuncOfTheQuadCurvExactHInter.cxx} (100%) create mode 100644 src/ModelingAlgorithms/TKHLR/HLRBRep/HLRBRep_InterCSurf.cxx delete mode 100644 src/ModelingAlgorithms/TKHLR/HLRBRep/HLRBRep_InterCSurf_0.cxx create mode 100644 src/ModelingAlgorithms/TKHLR/HLRBRep/HLRBRep_ThePolygonOfInterCSurf.cxx delete mode 100644 src/ModelingAlgorithms/TKHLR/HLRBRep/HLRBRep_ThePolygonOfInterCSurf_0.cxx create mode 100644 src/ModelingAlgorithms/TKHLR/HLRBRep/HLRBRep_ThePolyhedronOfInterCSurf.cxx delete mode 100644 src/ModelingAlgorithms/TKHLR/HLRBRep/HLRBRep_ThePolyhedronOfInterCSurf_0.cxx create mode 100644 src/ModelingAlgorithms/TKHLR/HLRBRep/HLRBRep_TheQuadCurvExactInterCSurf.cxx delete mode 100644 src/ModelingAlgorithms/TKHLR/HLRBRep/HLRBRep_TheQuadCurvExactInterCSurf_0.cxx diff --git a/src/ModelingAlgorithms/TKGeomAlgo/IntCurveSurface/FILES.cmake b/src/ModelingAlgorithms/TKGeomAlgo/IntCurveSurface/FILES.cmake index 3f23a750be..4d5cfd285e 100644 --- a/src/ModelingAlgorithms/TKGeomAlgo/IntCurveSurface/FILES.cmake +++ b/src/ModelingAlgorithms/TKGeomAlgo/IntCurveSurface/FILES.cmake @@ -3,8 +3,8 @@ set(OCCT_IntCurveSurface_FILES_LOCATION "${CMAKE_CURRENT_LIST_DIR}") set(OCCT_IntCurveSurface_FILES IntCurveSurface_HInter.hxx - IntCurveSurface_HInter_0.cxx - IntCurveSurface_Inter.gxx + IntCurveSurface_HInter.cxx + IntCurveSurface_Inter.pxx IntCurveSurface_Intersection.cxx IntCurveSurface_Intersection.hxx IntCurveSurface_IntersectionPoint.cxx @@ -12,12 +12,10 @@ set(OCCT_IntCurveSurface_FILES IntCurveSurface_IntersectionPoint.lxx IntCurveSurface_IntersectionSegment.cxx IntCurveSurface_IntersectionSegment.hxx - IntCurveSurface_Polygon.gxx - IntCurveSurface_PolygonTool.lxx - IntCurveSurface_Polyhedron.gxx - IntCurveSurface_Polyhedron.lxx - IntCurveSurface_PolyhedronTool.lxx - IntCurveSurface_QuadricCurveExactInter.gxx + IntCurveSurface_InterUtils.pxx + IntCurveSurface_PolygonUtils.pxx + IntCurveSurface_PolyhedronUtils.pxx + IntCurveSurface_QuadricCurveExactInterUtils.pxx IntCurveSurface_SequenceOfPnt.hxx IntCurveSurface_SequenceOfSeg.hxx IntCurveSurface_TheCSFunctionOfHInter.hxx @@ -29,16 +27,16 @@ set(OCCT_IntCurveSurface_FILES IntCurveSurface_TheInterferenceOfHInter.hxx IntCurveSurface_TheInterferenceOfHInter_0.cxx IntCurveSurface_ThePolygonOfHInter.hxx - IntCurveSurface_ThePolygonOfHInter_0.cxx + IntCurveSurface_ThePolygonOfHInter.cxx IntCurveSurface_ThePolygonToolOfHInter.hxx - IntCurveSurface_ThePolygonToolOfHInter_0.cxx + IntCurveSurface_ThePolygonToolOfHInter.cxx IntCurveSurface_ThePolyhedronOfHInter.hxx - IntCurveSurface_ThePolyhedronOfHInter_0.cxx + IntCurveSurface_ThePolyhedronOfHInter.cxx IntCurveSurface_ThePolyhedronToolOfHInter.hxx - IntCurveSurface_ThePolyhedronToolOfHInter_0.cxx + IntCurveSurface_ThePolyhedronToolOfHInter.cxx IntCurveSurface_TheQuadCurvExactHInter.hxx - IntCurveSurface_TheQuadCurvExactHInter_0.cxx + IntCurveSurface_TheQuadCurvExactHInter.cxx IntCurveSurface_TheQuadCurvFuncOfTheQuadCurvExactHInter.hxx - IntCurveSurface_TheQuadCurvFuncOfTheQuadCurvExactHInter_0.cxx + IntCurveSurface_TheQuadCurvFuncOfTheQuadCurvExactHInter.cxx IntCurveSurface_TransitionOnCurve.hxx ) diff --git a/src/ModelingAlgorithms/TKGeomAlgo/IntCurveSurface/IntCurveSurface_HInter.cxx b/src/ModelingAlgorithms/TKGeomAlgo/IntCurveSurface/IntCurveSurface_HInter.cxx new file mode 100644 index 0000000000..5d736a5b85 --- /dev/null +++ b/src/ModelingAlgorithms/TKGeomAlgo/IntCurveSurface/IntCurveSurface_HInter.cxx @@ -0,0 +1,584 @@ +// Created on: 1993-04-07 +// Created by: Laurent BUCHARD +// Copyright (c) 1993-1999 Matra Datavision +// Copyright (c) 1999-2014 OPEN CASCADE SAS +// +// This file is part of Open CASCADE Technology software library. +// +// This library is free software; you can redistribute it and/or modify it under +// the terms of the GNU Lesser General Public License version 2.1 as published +// by the Free Software Foundation, with special exception defined in the file +// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT +// distribution for complete text of the license and disclaimer of any warranty. +// +// Alternatively, this file may be used under the terms of Open CASCADE +// commercial license or contractual agreement. + +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "IntCurveSurface_Inter.pxx" + +// Type aliases for readability +using TheCurve = Handle(Adaptor3d_Curve); +using TheCurveTool = IntCurveSurface_TheHCurveTool; +using TheSurface = Handle(Adaptor3d_Surface); +using TheSurfaceTool = Adaptor3d_HSurfaceTool; +using ThePolygon = IntCurveSurface_ThePolygonOfHInter; +using ThePolyhedron = IntCurveSurface_ThePolyhedronOfHInter; +using TheInterference = IntCurveSurface_TheInterferenceOfHInter; +using TheCSFunction = IntCurveSurface_TheCSFunctionOfHInter; +using TheExactInter = IntCurveSurface_TheExactHInter; +using TheQuadCurvExactInter = IntCurveSurface_TheQuadCurvExactHInter; + +//================================================================================================== + +IntCurveSurface_HInter::IntCurveSurface_HInter() {} + +//================================================================================================== + +void IntCurveSurface_HInter::DoSurface(const TheSurface& surface, + const Standard_Real u0, + const Standard_Real u1, + const Standard_Real v0, + const Standard_Real v1, + TColgp_Array2OfPnt& pntsOnSurface, + Bnd_Box& boxSurface, + Standard_Real& gap) +{ + IntCurveSurface_InterUtils::DoSurface(surface, + u0, + u1, + v0, + v1, + pntsOnSurface, + boxSurface, + gap); +} + +//================================================================================================== + +void IntCurveSurface_HInter::DoNewBounds(const TheSurface& surface, + const Standard_Real u0, + const Standard_Real u1, + const Standard_Real v0, + const Standard_Real v1, + const TColgp_Array2OfPnt& pntsOnSurface, + const TColStd_Array1OfReal& X, + const TColStd_Array1OfReal& Y, + const TColStd_Array1OfReal& Z, + TColStd_Array1OfReal& Bounds) +{ + IntCurveSurface_InterUtils::DoNewBounds(surface, + u0, + u1, + v0, + v1, + pntsOnSurface, + X, + Y, + Z, + Bounds); +} + +//================================================================================================== + +void IntCurveSurface_HInter::Perform(const TheCurve& curve, const TheSurface& surface) +{ + IntCurveSurface_InterImpl::Perform( + curve, + surface, + done, + [this]() { this->ResetFields(); }, + [this](const TheCurve& c, + const TheSurface& s, + Standard_Real u0, + Standard_Real v0, + Standard_Real u1, + Standard_Real v1) { this->Perform(c, s, u0, v0, u1, v1); }); +} + +//================================================================================================== + +void IntCurveSurface_HInter::Perform(const TheCurve& curve, + const TheSurface& surface, + const Standard_Real U1, + const Standard_Real V1, + const Standard_Real U2, + const Standard_Real V2) +{ + IntCurveSurface_InterImpl:: + PerformBounds( + curve, + surface, + U1, + V1, + U2, + V2, + [this](const auto& conic, + const TheCurve& c, + const TheSurface& s, + Standard_Real u1, + Standard_Real v1, + Standard_Real u2, + Standard_Real v2) { this->PerformConicSurf(conic, c, s, u1, v1, u2, v2); }, + [this](const TheCurve& c, + const ThePolygon& p, + const TheSurface& s, + Standard_Real u1, + Standard_Real v1, + Standard_Real u2, + Standard_Real v2) { this->InternalPerform(c, p, s, u1, v1, u2, v2); }, + [this](const TheCurve& c, const TheSurface& s) { this->InternalPerformCurveQuadric(c, s); }); +} + +//================================================================================================== + +void IntCurveSurface_HInter::Perform(const TheCurve& curve, + const ThePolygon& polygon, + const TheSurface& surface) +{ + IntCurveSurface_InterImpl:: + PerformPolygon( + curve, + polygon, + surface, + done, + [this]() { this->ResetFields(); }, + [this](const TheCurve& c, const ThePolygon& p, const TheSurface& s, const ThePolyhedron& ph) { + this->Perform(c, p, s, ph); + }); +} + +//================================================================================================== + +void IntCurveSurface_HInter::Perform(const TheCurve& curve, + const TheSurface& surface, + const ThePolyhedron& polyhedron) +{ + IntCurveSurface_InterImpl::PerformPolyhedron( + curve, + surface, + polyhedron, + done, + [this]() { this->ResetFields(); }, + [this](const TheCurve& c, const ThePolygon& p, const TheSurface& s, const ThePolyhedron& ph) { + this->Perform(c, p, s, ph); + }); +} + +//================================================================================================== + +void IntCurveSurface_HInter::Perform(const TheCurve& curve, + const ThePolygon& polygon, + const TheSurface& surface, + const ThePolyhedron& polyhedron) +{ + IntCurveSurface_InterImpl::PerformPolygonPolyhedron( + curve, + polygon, + surface, + polyhedron, + done, + [this]() { this->ResetFields(); }, + [this](const TheCurve& c, + const ThePolygon& p, + const TheSurface& s, + const ThePolyhedron& ph, + Standard_Real u1, + Standard_Real v1, + Standard_Real u2, + Standard_Real v2) { this->InternalPerform(c, p, s, ph, u1, v1, u2, v2); }); +} + +//================================================================================================== + +void IntCurveSurface_HInter::Perform(const TheCurve& curve, + const ThePolygon& polygon, + const TheSurface& surface, + const ThePolyhedron& polyhedron, + Bnd_BoundSortBox& BndBSB) +{ + IntCurveSurface_InterImpl::PerformPolygonPolyhedronBSB( + curve, + polygon, + surface, + polyhedron, + BndBSB, + done, + [this]() { this->ResetFields(); }, + [this](const TheCurve& c, + const ThePolygon& p, + const TheSurface& s, + const ThePolyhedron& ph, + Standard_Real u1, + Standard_Real v1, + Standard_Real u2, + Standard_Real v2, + Bnd_BoundSortBox& bsb) { this->InternalPerform(c, p, s, ph, u1, v1, u2, v2, bsb); }); +} + +//================================================================================================== + +void IntCurveSurface_HInter::InternalPerform(const TheCurve& curve, + const ThePolygon& polygon, + const TheSurface& surface, + const ThePolyhedron& polyhedron, + const Standard_Real u0, + const Standard_Real v0, + const Standard_Real u1, + const Standard_Real v1, + Bnd_BoundSortBox& BSB) +{ + IntCurveSurface_InterImpl::InternalPerformBSB( + curve, + polygon, + surface, + polyhedron, + u0, + v0, + u1, + v1, + BSB, + [this](const IntCurveSurface_IntersectionPoint& pt) { this->Append(pt); }); +} + +//================================================================================================== + +void IntCurveSurface_HInter::InternalPerform(const TheCurve& curve, + const ThePolygon& polygon, + const TheSurface& surface, + const ThePolyhedron& polyhedron, + const Standard_Real u0, + const Standard_Real v0, + const Standard_Real u1, + const Standard_Real v1) +{ + IntCurveSurface_InterImpl::InternalPerform( + curve, + polygon, + surface, + polyhedron, + u0, + v0, + u1, + v1, + [this](const IntCurveSurface_IntersectionPoint& pt) { this->Append(pt); }); +} + +//================================================================================================== + +void IntCurveSurface_HInter::InternalPerformCurveQuadric(const TheCurve& curve, + const TheSurface& surface) +{ + IntCurveSurface_InterImpl::InternalPerformCurveQuadric( + curve, + surface, + [this](const IntCurveSurface_IntersectionPoint& pt) { this->Append(pt); }); +} + +//================================================================================================== + +void IntCurveSurface_HInter::InternalPerform(const TheCurve& curve, + const ThePolygon& polygon, + const TheSurface& surface, + const Standard_Real U1, + const Standard_Real V1, + const Standard_Real U2, + const Standard_Real V2) +{ + IntCurveSurface_InterImpl::InternalPerformPolygonBounds( + curve, + polygon, + surface, + U1, + V1, + U2, + V2, + [this](const TheCurve& c, + const ThePolygon& p, + const TheSurface& s, + const ThePolyhedron& ph, + Standard_Real u1, + Standard_Real v1, + Standard_Real u2, + Standard_Real v2) { this->InternalPerform(c, p, s, ph, u1, v1, u2, v2); }, + [this](const IntCurveSurface_IntersectionPoint& pt) { this->Append(pt); }); +} + +//================================================================================================== + +void IntCurveSurface_HInter::PerformConicSurf(const gp_Lin& Line, + const TheCurve& curve, + const TheSurface& surface, + const Standard_Real U1, + const Standard_Real V1, + const Standard_Real U2, + const Standard_Real V2) +{ + IntCurveSurface_InterImpl::PerformConicSurfLine( + Line, + curve, + surface, + U1, + V1, + U2, + V2, + [this](const TheCurve& c, const TheSurface& s, const IntAna_IntConicQuad& ana) { + this->AppendIntAna(c, s, ana); + }, + [this](const TheCurve& c, + const ThePolygon& p, + const TheSurface& s, + const ThePolyhedron& ph, + Standard_Real u1, + Standard_Real v1, + Standard_Real u2, + Standard_Real v2) { this->InternalPerform(c, p, s, ph, u1, v1, u2, v2); }, + [this](const IntCurveSurface_IntersectionPoint& pt) { this->Append(pt); }); +} + +//================================================================================================== + +void IntCurveSurface_HInter::PerformConicSurf(const gp_Circ& Circle, + const TheCurve& curve, + const TheSurface& surface, + const Standard_Real U1, + const Standard_Real V1, + const Standard_Real U2, + const Standard_Real V2) +{ + IntCurveSurface_InterImpl:: + PerformConicSurfCircle( + Circle, + curve, + surface, + U1, + V1, + U2, + V2, + [this](const TheCurve& c, const TheSurface& s, const IntAna_IntConicQuad& ana) { + this->AppendIntAna(c, s, ana); + }, + [this](const TheCurve& c, + const ThePolygon& p, + const TheSurface& s, + Standard_Real u1, + Standard_Real v1, + Standard_Real u2, + Standard_Real v2) { this->InternalPerform(c, p, s, u1, v1, u2, v2); }); +} + +//================================================================================================== + +void IntCurveSurface_HInter::PerformConicSurf(const gp_Elips& Ellipse, + const TheCurve& curve, + const TheSurface& surface, + const Standard_Real U1, + const Standard_Real V1, + const Standard_Real U2, + const Standard_Real V2) +{ + IntCurveSurface_InterImpl:: + PerformConicSurfEllipse( + Ellipse, + curve, + surface, + U1, + V1, + U2, + V2, + [this](const TheCurve& c, const TheSurface& s, const IntAna_IntConicQuad& ana) { + this->AppendIntAna(c, s, ana); + }, + [this](const TheCurve& c, + const ThePolygon& p, + const TheSurface& s, + Standard_Real u1, + Standard_Real v1, + Standard_Real u2, + Standard_Real v2) { this->InternalPerform(c, p, s, u1, v1, u2, v2); }); +} + +//================================================================================================== + +void IntCurveSurface_HInter::PerformConicSurf(const gp_Parab& Parab, + const TheCurve& curve, + const TheSurface& surface, + const Standard_Real U1, + const Standard_Real V1, + const Standard_Real U2, + const Standard_Real V2) +{ + IntCurveSurface_InterImpl::PerformConicSurfParabola( + Parab, + curve, + surface, + U1, + V1, + U2, + V2, + [this](const TheCurve& c, const TheSurface& s, const IntAna_IntConicQuad& ana) { + this->AppendIntAna(c, s, ana); + }, + [this](const TheCurve& c, + const ThePolygon& p, + const TheSurface& s, + const ThePolyhedron& ph, + Standard_Real u1, + Standard_Real v1, + Standard_Real u2, + Standard_Real v2) { this->InternalPerform(c, p, s, ph, u1, v1, u2, v2); }); +} + +//================================================================================================== + +void IntCurveSurface_HInter::PerformConicSurf(const gp_Hypr& Hypr, + const TheCurve& curve, + const TheSurface& surface, + const Standard_Real U1, + const Standard_Real V1, + const Standard_Real U2, + const Standard_Real V2) +{ + IntCurveSurface_InterImpl::PerformConicSurfHyperbola( + Hypr, + curve, + surface, + U1, + V1, + U2, + V2, + [this](const TheCurve& c, const TheSurface& s, const IntAna_IntConicQuad& ana) { + this->AppendIntAna(c, s, ana); + }, + [this](const TheCurve& c, + const ThePolygon& p, + const TheSurface& s, + const ThePolyhedron& ph, + Standard_Real u1, + Standard_Real v1, + Standard_Real u2, + Standard_Real v2) { this->InternalPerform(c, p, s, ph, u1, v1, u2, v2); }); +} + +//================================================================================================== + +void IntCurveSurface_HInter::AppendIntAna(const TheCurve& curve, + const TheSurface& surface, + const IntAna_IntConicQuad& intana_ConicQuad) +{ + IntCurveSurface_InterImpl::AppendIntAna( + curve, + surface, + intana_ConicQuad, + myIsParallel, + [this](const IntCurveSurface_IntersectionPoint& pt) { this->Append(pt); }); +} + +//================================================================================================== + +void IntCurveSurface_HInter::AppendPoint(const TheCurve& curve, + const Standard_Real lw, + const TheSurface& surface, + const Standard_Real su, + const Standard_Real sv) +{ + IntCurveSurface_IntersectionPoint aPoint; + if (IntCurveSurface_InterUtils:: + ComputeAppendPoint(curve, + lw, + surface, + su, + sv, + aPoint)) + { + Append(aPoint); + } +} + +//================================================================================================== + +void IntCurveSurface_HInter::AppendSegment(const TheCurve&, + const Standard_Real, + const Standard_Real, + const TheSurface&) +{ + // Not implemented +} diff --git a/src/ModelingAlgorithms/TKGeomAlgo/IntCurveSurface/IntCurveSurface_HInter_0.cxx b/src/ModelingAlgorithms/TKGeomAlgo/IntCurveSurface/IntCurveSurface_HInter_0.cxx deleted file mode 100644 index f294dbd43f..0000000000 --- a/src/ModelingAlgorithms/TKGeomAlgo/IntCurveSurface/IntCurveSurface_HInter_0.cxx +++ /dev/null @@ -1,75 +0,0 @@ -// Created on: 1993-04-07 -// Created by: Laurent BUCHARD -// Copyright (c) 1993-1999 Matra Datavision -// Copyright (c) 1999-2014 OPEN CASCADE SAS -// -// This file is part of Open CASCADE Technology software library. -// -// This library is free software; you can redistribute it and/or modify it under -// the terms of the GNU Lesser General Public License version 2.1 as published -// by the Free Software Foundation, with special exception defined in the file -// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT -// distribution for complete text of the license and disclaimer of any warranty. -// -// Alternatively, this file may be used under the terms of Open CASCADE -// commercial license or contractual agreement. - -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#define TheCurve Handle(Adaptor3d_Curve) -#define TheCurve_hxx -#define TheCurveTool IntCurveSurface_TheHCurveTool -#define TheCurveTool_hxx -#define TheSurface Handle(Adaptor3d_Surface) -#define TheSurface_hxx -#define TheSurfaceTool Adaptor3d_HSurfaceTool -#define TheSurfaceTool_hxx -#define IntCurveSurface_ThePolygon IntCurveSurface_ThePolygonOfHInter -#define IntCurveSurface_ThePolygon_hxx -#define IntCurveSurface_ThePolygonTool IntCurveSurface_ThePolygonToolOfHInter -#define IntCurveSurface_ThePolygonTool_hxx -#define IntCurveSurface_ThePolyhedron IntCurveSurface_ThePolyhedronOfHInter -#define IntCurveSurface_ThePolyhedron_hxx -#define IntCurveSurface_ThePolyhedronTool IntCurveSurface_ThePolyhedronToolOfHInter -#define IntCurveSurface_ThePolyhedronTool_hxx -#define IntCurveSurface_TheInterference IntCurveSurface_TheInterferenceOfHInter -#define IntCurveSurface_TheInterference_hxx -#define IntCurveSurface_TheCSFunction IntCurveSurface_TheCSFunctionOfHInter -#define IntCurveSurface_TheCSFunction_hxx -#define IntCurveSurface_TheExactInter IntCurveSurface_TheExactHInter -#define IntCurveSurface_TheExactInter_hxx -#define IntCurveSurface_TheQuadCurvExactInter IntCurveSurface_TheQuadCurvExactHInter -#define IntCurveSurface_TheQuadCurvExactInter_hxx -#define IntCurveSurface_TheQuadCurvFuncOfTheQuadCurvExactInter \ - IntCurveSurface_TheQuadCurvFuncOfTheQuadCurvExactHInter -#define IntCurveSurface_TheQuadCurvFuncOfTheQuadCurvExactInter_hxx \ - -#define IntCurveSurface_TheQuadCurvFuncOfTheQuadCurvExactInter \ - IntCurveSurface_TheQuadCurvFuncOfTheQuadCurvExactHInter -#define IntCurveSurface_TheQuadCurvFuncOfTheQuadCurvExactInter_hxx \ - -#define IntCurveSurface_Inter IntCurveSurface_HInter -#define IntCurveSurface_Inter_hxx -#include diff --git a/src/ModelingAlgorithms/TKGeomAlgo/IntCurveSurface/IntCurveSurface_Inter.gxx b/src/ModelingAlgorithms/TKGeomAlgo/IntCurveSurface/IntCurveSurface_Inter.gxx deleted file mode 100644 index 335bb0beed..0000000000 --- a/src/ModelingAlgorithms/TKGeomAlgo/IntCurveSurface/IntCurveSurface_Inter.gxx +++ /dev/null @@ -1,2285 +0,0 @@ -// Created on: 1993-04-09 -// Created by: Laurent BUCHARD -// Copyright (c) 1993-1999 Matra Datavision -// Copyright (c) 1999-2014 OPEN CASCADE SAS -// -// This file is part of Open CASCADE Technology software library. -// -// This library is free software; you can redistribute it and/or modify it under -// the terms of the GNU Lesser General Public License version 2.1 as published -// by the Free Software Foundation, with special exception defined in the file -// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT -// distribution for complete text of the license and disclaimer of any warranty. -// -// Alternatively, this file may be used under the terms of Open CASCADE -// commercial license or contractual agreement. - -// #ifndef OCCT_DEBUG -// #define No_Standard_RangeError -// #define No_Standard_OutOfRange -// #endif - -#define TOLTANGENCY 0.00000001 -#define TOLERANCE_ANGULAIRE 1.e-12 // 0.00000001 -#define TOLERANCE 0.00000001 - -#define NBSAMPLESONCIRCLE 32 -#define NBSAMPLESONELLIPSE 32 -#define NBSAMPLESONPARAB 16 -#define NBSAMPLESONHYPR 32 - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include -// #define ICS_DEB -static void EstLimForInfExtr(const gp_Lin& Line, - const TheSurface& surface, - const Standard_Boolean IsOffSurf, - const Standard_Integer nbsu, - const Standard_Boolean U1inf, - const Standard_Boolean U2inf, - const Standard_Boolean V1inf, - const Standard_Boolean V2inf, - Standard_Real& U1new, - Standard_Real& U2new, - Standard_Real& V1new, - Standard_Real& V2new, - Standard_Boolean& NoIntersection); - -static void EstLimForInfRevl(const gp_Lin& Line, - const TheSurface& surface, - const Standard_Boolean U1inf, - const Standard_Boolean U2inf, - const Standard_Boolean V1inf, - const Standard_Boolean V2inf, - Standard_Real& U1new, - Standard_Real& U2new, - Standard_Real& V1new, - Standard_Real& V2new, - Standard_Boolean& NoIntersection); - -static void EstLimForInfOffs(const gp_Lin& Line, - const TheSurface& surface, - const Standard_Integer nbsu, - const Standard_Boolean U1inf, - const Standard_Boolean U2inf, - const Standard_Boolean V1inf, - const Standard_Boolean V2inf, - Standard_Real& U1new, - Standard_Real& U2new, - Standard_Real& V1new, - Standard_Real& V2new, - Standard_Boolean& NoIntersection); - -static void EstLimForInfSurf(Standard_Real& U1new, - Standard_Real& U2new, - Standard_Real& V1new, - Standard_Real& V2new); - -static void SectionPointToParameters(const Intf_SectionPoint& Sp, - const IntCurveSurface_ThePolyhedron& Surf, - const IntCurveSurface_ThePolygon& Curv, - Standard_Real& u, - Standard_Real& v, - Standard_Real& w); - -static void IntCurveSurface_ComputeTransitions(const TheCurve& curve, - const Standard_Real w, - IntCurveSurface_TransitionOnCurve& TransOnCurve, - const TheSurface& surface, - const Standard_Real u, - const Standard_Real v); - -static void IntCurveSurface_ComputeParamsOnQuadric(const TheSurface& surface, - const gp_Pnt& P, - Standard_Real& u, - Standard_Real& v); - -static void ProjectIntersectAndEstLim(const gp_Lin& theLine, - const gp_Pln& thePln, - const ProjLib_Plane& theBasCurvProj, - Standard_Real& theVmin, - Standard_Real& theVmax, - Standard_Boolean& theNoIntersection); - -//================================================================================================= - -IntCurveSurface_Inter::IntCurveSurface_Inter() {} - -//================================================================================================= - -void IntCurveSurface_Inter::DoSurface(const TheSurface& surface, - const Standard_Real u0, - const Standard_Real u1, - const Standard_Real v0, - const Standard_Real v1, - TColgp_Array2OfPnt& pntsOnSurface, - Bnd_Box& boxSurface, - Standard_Real& gap) -{ - Standard_Integer iU = 0, iV = 0; - Standard_Real U = 0., V = 0; - // modified by NIZHNY-MKK Mon Oct 3 17:38:45 2005 - // Standard_Real dU = fabs(u1-u0)/50., dV = fabs(v1-v0)/50.; - Standard_Real dU = (u1 - u0) / 50., dV = (v1 - v0) / 50.; - gp_Pnt aPnt; - - for (iU = 0; iU < 50; iU++) - { - - if (iU == 0) - U = u0; - else if (iU == 49) - U = u1; - else - U = u0 + dU * ((Standard_Real)iU); - - for (iV = 0; iV < 50; iV++) - { - - if (iV == 0) - V = v0; - else if (iV == 49) - V = v1; - else - V = v0 + dV * ((Standard_Real)iV); - - TheSurfaceTool::D0(surface, U, V, aPnt); - boxSurface.Add(aPnt); - pntsOnSurface.SetValue(iU + 1, iV + 1, aPnt); - } - } - Standard_Real Ures = TheSurfaceTool::UResolution(surface, dU); - Standard_Real Vres = TheSurfaceTool::VResolution(surface, dV); - gap = std::max(Ures, Vres); -} - -//================================================================================================= - -void IntCurveSurface_Inter::DoNewBounds(const TheSurface& surface, - const Standard_Real u0, - const Standard_Real u1, - const Standard_Real v0, - const Standard_Real v1, - const TColgp_Array2OfPnt& pntsOnSurface, - const TColStd_Array1OfReal& X, - const TColStd_Array1OfReal& Y, - const TColStd_Array1OfReal& Z, - TColStd_Array1OfReal& Bounds) -{ - Bounds.SetValue(1, u0); - Bounds.SetValue(2, u1); - Bounds.SetValue(3, v0); - Bounds.SetValue(4, v1); - - Standard_Boolean isUClosed = - (TheSurfaceTool::IsUClosed(surface) || TheSurfaceTool::IsUPeriodic(surface)); - Standard_Boolean isVClosed = - (TheSurfaceTool::IsVClosed(surface) || TheSurfaceTool::IsVPeriodic(surface)); - Standard_Boolean checkU = (isUClosed) ? Standard_False : Standard_True; - Standard_Boolean checkV = (isVClosed) ? Standard_False : Standard_True; - - Standard_Integer i = 0, j = 0, k = 0, iU = 0, iV = 0; - Standard_Integer iUmin = 50, iVmin = 50, iUmax = 1, iVmax = 1; - - for (i = 1; i <= 2; i++) - { - for (j = 1; j <= 2; j++) - { - for (k = 1; k <= 2; k++) - { - gp_Pnt aPoint(X(i), Y(j), Z(k)); - Standard_Real DistMin = 1.e+100; - Standard_Integer diU = 0, diV = 0; - for (iU = 1; iU <= 50; iU++) - { - for (iV = 1; iV <= 50; iV++) - { - const gp_Pnt aP = pntsOnSurface.Value(iU, iV); - Standard_Real dist = aP.SquareDistance(aPoint); - if (dist < DistMin) - { - DistMin = dist; - diU = iU; - diV = iV; - } - } - } - if (diU > 0 && diU < iUmin) - iUmin = diU; - if (diU > 0 && diU > iUmax) - iUmax = diU; - if (diV > 0 && diV < iVmin) - iVmin = diV; - if (diV > 0 && diV > iVmax) - iVmax = diV; - } - } - } - - // modified by NIZHNY-MKK Mon Oct 3 17:38:43 2005 - // Standard_Real dU = fabs(u1-u0)/50., dV = fabs(v1-v0)/50.; - Standard_Real dU = (u1 - u0) / 50., dV = (v1 - v0) / 50.; - - Standard_Real USmin = u0 + dU * ((Standard_Real)(iUmin - 1)); - Standard_Real USmax = u0 + dU * ((Standard_Real)(iUmax - 1)); - Standard_Real VSmin = v0 + dV * ((Standard_Real)(iVmin - 1)); - Standard_Real VSmax = v0 + dV * ((Standard_Real)(iVmax - 1)); - - if (USmin > USmax) - { - Standard_Real tmp = USmax; - USmax = USmin; - USmin = tmp; - } - if (VSmin > VSmax) - { - Standard_Real tmp = VSmax; - VSmax = VSmin; - VSmin = tmp; - } - - USmin -= 1.5 * dU; - if (USmin < u0) - USmin = u0; - USmax += 1.5 * dU; - if (USmax > u1) - USmax = u1; - VSmin -= 1.5 * dV; - if (VSmin < v0) - VSmin = v0; - VSmax += 1.5 * dV; - if (VSmax > v1) - VSmax = v1; - - if (checkU) - { - Bounds.SetValue(1, USmin); - Bounds.SetValue(2, USmax); - } - if (checkV) - { - Bounds.SetValue(3, VSmin); - Bounds.SetValue(4, VSmax); - } -} - -//======================================================================= -// function : Perform -// purpose : Decompose la surface si besoin est -//======================================================================= -void IntCurveSurface_Inter::Perform(const TheCurve& curve, const TheSurface& surface) -{ - ResetFields(); - done = Standard_True; - Standard_Integer NbUOnS = TheSurfaceTool::NbUIntervals(surface, GeomAbs_C2); - Standard_Integer NbVOnS = TheSurfaceTool::NbVIntervals(surface, GeomAbs_C2); - Standard_Real U0, U1, V0, V1; - - if (NbUOnS > 1) - { - TColStd_Array1OfReal TabU(1, NbUOnS + 1); - TheSurfaceTool::UIntervals(surface, TabU, GeomAbs_C2); - for (Standard_Integer iu = 1; iu <= NbUOnS; iu++) - { - U0 = TabU.Value(iu); - U1 = TabU.Value(iu + 1); - if (NbVOnS > 1) - { - TColStd_Array1OfReal TabV(1, NbVOnS + 1); - TheSurfaceTool::VIntervals(surface, TabV, GeomAbs_C2); - for (Standard_Integer iv = 1; iv <= NbVOnS; iv++) - { - // More than one interval on U and V param space. - V0 = TabV.Value(iv); - V1 = TabV.Value(iv + 1); - Perform(curve, surface, U0, V0, U1, V1); - } - } - else - { - // More than one interval only on U param space. - V0 = TheSurfaceTool::FirstVParameter(surface); - V1 = TheSurfaceTool::LastVParameter(surface); - Perform(curve, surface, U0, V0, U1, V1); - } - } - } - else if (NbVOnS > 1) - { - // More than one interval only on V param space. - U0 = TheSurfaceTool::FirstUParameter(surface); - U1 = TheSurfaceTool::LastUParameter(surface); - TColStd_Array1OfReal TabV(1, NbVOnS + 1); - TheSurfaceTool::VIntervals(surface, TabV, GeomAbs_C2); - for (Standard_Integer iv = 1; iv <= NbVOnS; iv++) - { - V0 = TabV.Value(iv); - V1 = TabV.Value(iv + 1); - Perform(curve, surface, U0, V0, U1, V1); - } - } - else - { - // One interval on U and V param space. - V0 = TheSurfaceTool::FirstVParameter(surface); - V1 = TheSurfaceTool::LastVParameter(surface); - U0 = TheSurfaceTool::FirstUParameter(surface); - U1 = TheSurfaceTool::LastUParameter(surface); - - Perform(curve, surface, U0, V0, U1, V1); - } -} - -//================================================================================================= - -void IntCurveSurface_Inter::Perform(const TheCurve& curve, - const TheSurface& surface, - const Standard_Real U1, - const Standard_Real V1, - const Standard_Real U2, - const Standard_Real V2) -{ - // Protection from double type overflow. - // This may happen inside square magnitude computation based on normal, - // which was computed on bound parameters (bug26525). - Standard_Real UU1 = U1, UU2 = U2, VV1 = V1, VV2 = V2; - if (U1 < -1.0e50) - UU1 = -1.0e50; - if (U2 > 1.0e50) - UU2 = 1.0e50; - if (V1 < -1.0e50) - VV1 = -1.0e50; - if (V2 > 1.0e50) - VV2 = 1.0e50; - - GeomAbs_CurveType CurveType = TheCurveTool::GetType(curve); - - switch (CurveType) - { - case GeomAbs_Line: { - PerformConicSurf(TheCurveTool::Line(curve), curve, surface, UU1, VV1, UU2, VV2); - break; - } - case GeomAbs_Circle: { - PerformConicSurf(TheCurveTool::Circle(curve), curve, surface, UU1, VV1, UU2, VV2); - break; - } - case GeomAbs_Ellipse: { - PerformConicSurf(TheCurveTool::Ellipse(curve), curve, surface, UU1, VV1, UU2, VV2); - break; - } - case GeomAbs_Parabola: { - PerformConicSurf(TheCurveTool::Parabola(curve), curve, surface, UU1, VV1, UU2, VV2); - break; - } - case GeomAbs_Hyperbola: { - PerformConicSurf(TheCurveTool::Hyperbola(curve), curve, surface, UU1, VV1, UU2, VV2); - break; - } - default: { - Standard_Integer nbIntervalsOnCurve = TheCurveTool::NbIntervals(curve, GeomAbs_C2); - GeomAbs_SurfaceType SurfaceType = TheSurfaceTool::GetType(surface); - if ((SurfaceType != GeomAbs_Plane) && (SurfaceType != GeomAbs_Cylinder) - && (SurfaceType != GeomAbs_Cone) && (SurfaceType != GeomAbs_Sphere)) - { - - if (nbIntervalsOnCurve > 1) - { - TColStd_Array1OfReal TabW(1, nbIntervalsOnCurve + 1); - TheCurveTool::Intervals(curve, TabW, GeomAbs_C2); - for (Standard_Integer i = 1; i <= nbIntervalsOnCurve; i++) - { - Standard_Real u1, u2; - u1 = TabW.Value(i); - u2 = TabW.Value(i + 1); - - Handle(TColStd_HArray1OfReal) aPars; - Standard_Real defl = 0.1; - Standard_Integer NbMin = 10; - TheCurveTool::SamplePars(curve, u1, u2, defl, NbMin, aPars); - - // IntCurveSurface_ThePolygon - // polygon(curve,u1,u2,TheCurveTool::NbSamples(curve,u1,u2)); - IntCurveSurface_ThePolygon polygon(curve, aPars->Array1()); - InternalPerform(curve, polygon, surface, UU1, VV1, UU2, VV2); - } - } - else - { - Standard_Real u1, u2; - u1 = TheCurveTool::FirstParameter(curve); - u2 = TheCurveTool::LastParameter(curve); - - Handle(TColStd_HArray1OfReal) aPars; - Standard_Real defl = 0.1; - Standard_Integer NbMin = 10; - TheCurveTool::SamplePars(curve, u1, u2, defl, NbMin, aPars); - - // IntCurveSurface_ThePolygon polygon(curve,TheCurveTool::NbSamples(curve,u1,u2)); - IntCurveSurface_ThePolygon polygon(curve, aPars->Array1()); - InternalPerform(curve, polygon, surface, UU1, VV1, UU2, VV2); - } - } - else - { //-- la surface est une quadrique - InternalPerformCurveQuadric(curve, surface); - } - } - } -} - -//================================================================================================= - -void IntCurveSurface_Inter::Perform(const TheCurve& curve, - const IntCurveSurface_ThePolygon& polygon, - const TheSurface& surface) -{ - ResetFields(); - done = Standard_True; - Standard_Real u1, v1, u2, v2; - u1 = TheSurfaceTool::FirstUParameter(surface); - v1 = TheSurfaceTool::FirstVParameter(surface); - u2 = TheSurfaceTool::LastUParameter(surface); - v2 = TheSurfaceTool::LastVParameter(surface); - Standard_Integer nbsu, nbsv; - nbsu = TheSurfaceTool::NbSamplesU(surface, u1, u2); - nbsv = TheSurfaceTool::NbSamplesV(surface, v1, v2); - if (nbsu > 40) - nbsu = 40; - if (nbsv > 40) - nbsv = 40; - IntCurveSurface_ThePolyhedron polyhedron(surface, nbsu, nbsv, u1, v1, u2, v2); - Perform(curve, polygon, surface, polyhedron); -} - -//================================================================================================= - -void IntCurveSurface_Inter::Perform(const TheCurve& curve, - const TheSurface& surface, - const IntCurveSurface_ThePolyhedron& polyhedron) -{ - ResetFields(); - done = Standard_True; - Standard_Real u1 = TheCurveTool::FirstParameter(curve); - Standard_Real u2 = TheCurveTool::LastParameter(curve); - IntCurveSurface_ThePolygon polygon(curve, TheCurveTool::NbSamples(curve, u1, u2)); - Perform(curve, polygon, surface, polyhedron); -} - -//================================================================================================= - -void IntCurveSurface_Inter::Perform(const TheCurve& curve, - const IntCurveSurface_ThePolygon& polygon, - const TheSurface& surface, - const IntCurveSurface_ThePolyhedron& polyhedron) -{ - ResetFields(); - done = Standard_True; - Standard_Real u1, v1, u2, v2; - u1 = TheSurfaceTool::FirstUParameter(surface); - v1 = TheSurfaceTool::FirstVParameter(surface); - u2 = TheSurfaceTool::LastUParameter(surface); - v2 = TheSurfaceTool::LastVParameter(surface); - InternalPerform(curve, polygon, surface, polyhedron, u1, v1, u2, v2); -} - -//================================================================================================= - -void IntCurveSurface_Inter::Perform(const TheCurve& curve, - const IntCurveSurface_ThePolygon& polygon, - const TheSurface& surface, - const IntCurveSurface_ThePolyhedron& polyhedron, - Bnd_BoundSortBox& BndBSB) -{ - ResetFields(); - done = Standard_True; - Standard_Real u1, v1, u2, v2; - u1 = TheSurfaceTool::FirstUParameter(surface); - v1 = TheSurfaceTool::FirstVParameter(surface); - u2 = TheSurfaceTool::LastUParameter(surface); - v2 = TheSurfaceTool::LastVParameter(surface); - InternalPerform(curve, polygon, surface, polyhedron, u1, v1, u2, v2, BndBSB); -} - -//======================================================================= -// function : InternalPerform -// purpose : C a l c u l d u p o i n t a p p r o c h e -//== p u i s d u p o i n t E x a c t -//======================================================================= -void IntCurveSurface_Inter::InternalPerform(const TheCurve& curve, - const IntCurveSurface_ThePolygon& polygon, - const TheSurface& surface, - const IntCurveSurface_ThePolyhedron& polyhedron, - const Standard_Real u0, - const Standard_Real v0, - const Standard_Real u1, - const Standard_Real v1, - Bnd_BoundSortBox& BSB) -{ - IntCurveSurface_TheInterference interference(polygon, polyhedron, BSB); - IntCurveSurface_TheCSFunction theicsfunction(surface, curve); - IntCurveSurface_TheExactInter intersectionExacte(theicsfunction, TOLTANGENCY); - math_FunctionSetRoot rsnld(intersectionExacte.Function()); - - // Standard_Real u,v,w,winit; - Standard_Real u, v, w; - gp_Pnt P; - Standard_Real winf = polygon.InfParameter(); - Standard_Real wsup = polygon.SupParameter(); - Standard_Integer NbSectionPoints = interference.NbSectionPoints(); - Standard_Integer NbTangentZones = interference.NbTangentZones(); - - //-- Les interferences renvoient parfois de nombreuses fois (>20) les memes points - - Standard_Integer i, NbStartPoints = NbSectionPoints; - for (i = 1; i <= NbTangentZones; i++) - { - const Intf_TangentZone& TZ = interference.ZoneValue(i); - Standard_Integer nbpnts = TZ.NumberOfPoints(); - NbStartPoints += nbpnts; - } - - if (NbStartPoints) - { - Standard_Real* TabU = new Standard_Real[NbStartPoints + 1]; - Standard_Real* TabV = new Standard_Real[NbStartPoints + 1]; - Standard_Real* TabW = new Standard_Real[NbStartPoints + 1]; - Standard_Integer IndexPoint = 0; - - for (i = 1; i <= NbSectionPoints; i++) - { - const Intf_SectionPoint& SP = interference.PntValue(i); - SectionPointToParameters(SP, polyhedron, polygon, u, v, w); - TabU[IndexPoint] = u; - TabV[IndexPoint] = v; - TabW[IndexPoint] = w; - IndexPoint++; - } - for (i = 1; i <= NbTangentZones; i++) - { - const Intf_TangentZone& TZ = interference.ZoneValue(i); - Standard_Integer nbpnts = TZ.NumberOfPoints(); - for (Standard_Integer j = 1; j <= nbpnts; j++) - { - const Intf_SectionPoint& SP = TZ.GetPoint(j); - SectionPointToParameters(SP, polyhedron, polygon, u, v, w); - TabU[IndexPoint] = u; - TabV[IndexPoint] = v; - TabW[IndexPoint] = w; - IndexPoint++; - } - } - - //-- Tri - Standard_Real su = 0, sv = 0, sw = 0, ptol; - ptol = 10 * Precision::PConfusion(); - - //-- Tri suivant la variable W - Standard_Boolean Triok; - do - { - Triok = Standard_True; - Standard_Integer im1; - for (i = 1, im1 = 0; i < NbStartPoints; im1++, i++) - { - if (TabW[i] < TabW[im1]) - { - Standard_Real t = TabW[i]; - TabW[i] = TabW[im1]; - TabW[im1] = t; - t = TabU[i]; - TabU[i] = TabU[im1]; - TabU[im1] = t; - t = TabV[i]; - TabV[i] = TabV[im1]; - TabV[im1] = t; - Triok = Standard_False; - } - } - } while (Triok == Standard_False); - - //-- On trie pour des meme W suivant U - do - { - Triok = Standard_True; - Standard_Integer im1; - for (i = 1, im1 = 0; i < NbStartPoints; im1++, i++) - { - // modified by NIZHNY-MKK Mon Oct 3 17:38:49 2005 - // if(std::abs(TabW[i]-TabW[im1]) ptol || std::abs(v - sv) > ptol || std::abs(w - sw) > ptol) - { - intersectionExacte.Perform(u, v, w, rsnld, u0, u1, v0, v1, winf, wsup); - if (intersectionExacte.IsDone()) - { - if (!intersectionExacte.IsEmpty()) - { - P = intersectionExacte.Point(); - w = intersectionExacte.ParameterOnCurve(); - intersectionExacte.ParameterOnSurface(u, v); - AppendPoint(curve, w, surface, u, v); - } - } - } - su = TabU[i]; - sv = TabV[i]; - sw = TabW[i]; - } - delete[] TabW; - delete[] TabV; - delete[] TabU; - } -} - -//================================================================================================= - -void IntCurveSurface_Inter::InternalPerform(const TheCurve& curve, - const IntCurveSurface_ThePolygon& polygon, - const TheSurface& surface, - const IntCurveSurface_ThePolyhedron& polyhedron, - const Standard_Real u0, - const Standard_Real v0, - const Standard_Real u1, - const Standard_Real v1) -{ - IntCurveSurface_TheInterference interference(polygon, polyhedron); - IntCurveSurface_TheCSFunction theicsfunction(surface, curve); - IntCurveSurface_TheExactInter intersectionExacte(theicsfunction, TOLTANGENCY); - math_FunctionSetRoot rsnld(intersectionExacte.Function()); - - // Standard_Real u,v,w,winit; - Standard_Real u, v, w; - gp_Pnt P; - Standard_Real winf = polygon.InfParameter(); - Standard_Real wsup = polygon.SupParameter(); - Standard_Integer NbSectionPoints = interference.NbSectionPoints(); - Standard_Integer NbTangentZones = interference.NbTangentZones(); - - //-- Les interferences renvoient parfois de nombreuses fois (>20) les memes points - - Standard_Integer i, NbStartPoints = NbSectionPoints; - for (i = 1; i <= NbTangentZones; i++) - { - const Intf_TangentZone& TZ = interference.ZoneValue(i); - Standard_Integer nbpnts = TZ.NumberOfPoints(); - NbStartPoints += nbpnts; - } - - if (NbStartPoints) - { - Standard_Real* TabU = new Standard_Real[NbStartPoints + 1]; - Standard_Real* TabV = new Standard_Real[NbStartPoints + 1]; - Standard_Real* TabW = new Standard_Real[NbStartPoints + 1]; - Standard_Integer IndexPoint = 0; - - for (i = 1; i <= NbSectionPoints; i++) - { - const Intf_SectionPoint& SP = interference.PntValue(i); - SectionPointToParameters(SP, polyhedron, polygon, u, v, w); - TabU[IndexPoint] = u; - TabV[IndexPoint] = v; - TabW[IndexPoint] = w; - IndexPoint++; - } - for (i = 1; i <= NbTangentZones; i++) - { - const Intf_TangentZone& TZ = interference.ZoneValue(i); - Standard_Integer nbpnts = TZ.NumberOfPoints(); - for (Standard_Integer j = 1; j <= nbpnts; j++) - { - const Intf_SectionPoint& SP = TZ.GetPoint(j); - SectionPointToParameters(SP, polyhedron, polygon, u, v, w); - TabU[IndexPoint] = u; - TabV[IndexPoint] = v; - TabW[IndexPoint] = w; - IndexPoint++; - } - } - - //-- Tri - Standard_Real su = 0, sv = 0, sw = 0, ptol; - ptol = 10 * Precision::PConfusion(); - - //-- Tri suivant la variable W - Standard_Boolean Triok; - do - { - Triok = Standard_True; - Standard_Integer im1; - for (i = 1, im1 = 0; i < NbStartPoints; im1++, i++) - { - if (TabW[i] < TabW[im1]) - { - Standard_Real t = TabW[i]; - TabW[i] = TabW[im1]; - TabW[im1] = t; - t = TabU[i]; - TabU[i] = TabU[im1]; - TabU[im1] = t; - t = TabV[i]; - TabV[i] = TabV[im1]; - TabV[im1] = t; - Triok = Standard_False; - } - } - } while (Triok == Standard_False); - - //-- On trie pour des meme W suivant U - do - { - Triok = Standard_True; - Standard_Integer im1; - for (i = 1, im1 = 0; i < NbStartPoints; im1++, i++) - { - // modified by NIZHNY-MKK Mon Oct 3 17:38:56 2005 - // if(std::abs(TabW[i]-TabW[im1]) ptol || std::abs(v - sv) > ptol || std::abs(w - sw) > ptol) - { - intersectionExacte.Perform(u, v, w, rsnld, u0, u1, v0, v1, winf, wsup); - if (intersectionExacte.IsDone()) - { - if (!intersectionExacte.IsEmpty()) - { - P = intersectionExacte.Point(); - w = intersectionExacte.ParameterOnCurve(); - intersectionExacte.ParameterOnSurface(u, v); - AppendPoint(curve, w, surface, u, v); - } - } - } - su = TabU[i]; - sv = TabV[i]; - sw = TabW[i]; - } - delete[] TabW; - delete[] TabV; - delete[] TabU; - } -} - -//================================================================================================= - -void IntCurveSurface_Inter::InternalPerformCurveQuadric(const TheCurve& curve, - const TheSurface& surface) -{ - IntCurveSurface_TheQuadCurvExactInter QuadCurv(surface, curve); - if (QuadCurv.IsDone()) - { - Standard_Integer NbRoots = QuadCurv.NbRoots(); - Standard_Real u, v, w; - for (Standard_Integer i = 1; i <= NbRoots; i++) - { - w = QuadCurv.Root(i); - IntCurveSurface_ComputeParamsOnQuadric(surface, TheCurveTool::Value(curve, w), u, v); - AppendPoint(curve, w, surface, u, v); - } - //-- Intervals non traites ............................................. - } -} - -//================================================================================================= - -void IntCurveSurface_Inter::InternalPerform(const TheCurve& curve, - const IntCurveSurface_ThePolygon& polygon, - const TheSurface& surface, - const Standard_Real U1, - const Standard_Real V1, - const Standard_Real U2, - const Standard_Real V2) -{ - GeomAbs_SurfaceType SurfaceType = TheSurfaceTool::GetType(surface); - if ((SurfaceType != GeomAbs_Plane) && (SurfaceType != GeomAbs_Cylinder) - && (SurfaceType != GeomAbs_Cone) && (SurfaceType != GeomAbs_Sphere)) - { - if (SurfaceType != GeomAbs_BSplineSurface) - { - Standard_Integer nbsu, nbsv; - nbsu = TheSurfaceTool::NbSamplesU(surface, U1, U2); - nbsv = TheSurfaceTool::NbSamplesV(surface, V1, V2); - if (nbsu > 40) - nbsu = 40; - if (nbsv > 40) - nbsv = 40; - IntCurveSurface_ThePolyhedron polyhedron(surface, nbsu, nbsv, U1, V1, U2, V2); - InternalPerform(curve, polygon, surface, polyhedron, U1, V1, U2, V2); - } - else - { - Handle(Adaptor3d_Surface) aS = TheSurfaceTool::UTrim(surface, U1, U2, 1.e-9); - aS = aS->VTrim(V1, V2, 1.e-9); - Handle(Adaptor3d_TopolTool) aTopTool = new Adaptor3d_TopolTool(aS); - Standard_Real defl = 0.1; - aTopTool->SamplePnts(defl, 10, 10); - - Standard_Integer nbpu = aTopTool->NbSamplesU(); - Standard_Integer nbpv = aTopTool->NbSamplesV(); - TColStd_Array1OfReal Upars(1, nbpu), Vpars(1, nbpv); - aTopTool->UParameters(Upars); - aTopTool->VParameters(Vpars); - - IntCurveSurface_ThePolyhedron polyhedron(surface, Upars, Vpars); - InternalPerform(curve, polygon, surface, polyhedron, U1, V1, U2, V2); - } - } - else - { - IntCurveSurface_TheQuadCurvExactInter QuadCurv(surface, curve); - if (QuadCurv.IsDone()) - { - Standard_Integer NbRoots = QuadCurv.NbRoots(); - Standard_Real u, v, w; - for (Standard_Integer i = 1; i <= NbRoots; i++) - { - w = QuadCurv.Root(i); - IntCurveSurface_ComputeParamsOnQuadric(surface, TheCurveTool::Value(curve, w), u, v); - AppendPoint(curve, w, surface, u, v); - } - //-- Intervalles non traites ............................................. - } - } //-- Fin : la Surface est une quadrique -} - -//================================================================================================= - -void IntCurveSurface_Inter::PerformConicSurf(const gp_Lin& Line, - const TheCurve& curve, - const TheSurface& surface, - const Standard_Real U1, - const Standard_Real V1, - const Standard_Real U2, - const Standard_Real V2) -{ - - GeomAbs_SurfaceType SurfaceType = TheSurfaceTool::GetType(surface); - Standard_Boolean isAnaProcessed = Standard_True; - switch (SurfaceType) - { - case GeomAbs_Plane: { - IntAna_IntConicQuad LinPlane(Line, TheSurfaceTool::Plane(surface), TOLERANCE_ANGULAIRE); - AppendIntAna(curve, surface, LinPlane); - break; - } - case GeomAbs_Cylinder: { - IntAna_IntConicQuad LinCylinder(Line, TheSurfaceTool::Cylinder(surface)); - AppendIntAna(curve, surface, LinCylinder); - break; - } - case GeomAbs_Sphere: { - IntAna_IntConicQuad LinSphere(Line, TheSurfaceTool::Sphere(surface)); - AppendIntAna(curve, surface, LinSphere); - break; - } - case GeomAbs_Torus: { - IntAna_IntLinTorus intlintorus(Line, TheSurfaceTool::Torus(surface)); - if (intlintorus.IsDone()) - { - Standard_Integer nbp = intlintorus.NbPoints(); - Standard_Real fi, theta, w; - for (Standard_Integer i = 1; i <= nbp; i++) - { - const gp_Pnt aDebPnt(intlintorus.Value(i)); - (void)aDebPnt; - w = intlintorus.ParamOnLine(i); - intlintorus.ParamOnTorus(i, fi, theta); - AppendPoint(curve, w, surface, fi, theta); - } - } - else - isAnaProcessed = Standard_False; - break; - } - case GeomAbs_Cone: { - constexpr Standard_Real correction = 1.E+5 * Precision::Angular(); - gp_Cone cn = TheSurfaceTool::Cone(surface); - if (std::abs(cn.SemiAngle()) < M_PI / 2.0 - correction) - { - IntAna_IntConicQuad LinCone(Line, cn); - AppendIntAna(curve, surface, LinCone); - } - else - isAnaProcessed = Standard_False; - break; - } - default: - isAnaProcessed = Standard_False; - } - if (!isAnaProcessed) - { - Standard_Integer nbsu, nbsv; - nbsu = TheSurfaceTool::NbSamplesU(surface, U1, U2); - nbsv = TheSurfaceTool::NbSamplesV(surface, V1, V2); - - Standard_Boolean U1inf = Precision::IsInfinite(U1); - Standard_Boolean U2inf = Precision::IsInfinite(U2); - Standard_Boolean V1inf = Precision::IsInfinite(V1); - Standard_Boolean V2inf = Precision::IsInfinite(V2); - - Standard_Real U1new = U1, U2new = U2, V1new = V1, V2new = V2; - - Standard_Boolean NoIntersection = Standard_False; - - if (U1inf || U2inf || V1inf || V2inf) - { - - if (SurfaceType == GeomAbs_SurfaceOfExtrusion) - { - - EstLimForInfExtr(Line, - surface, - Standard_False, - nbsu, - U1inf, - U2inf, - V1inf, - V2inf, - U1new, - U2new, - V1new, - V2new, - NoIntersection); - } - else if (SurfaceType == GeomAbs_SurfaceOfRevolution) - { - - EstLimForInfRevl(Line, - surface, - U1inf, - U2inf, - V1inf, - V2inf, - U1new, - U2new, - V1new, - V2new, - NoIntersection); - } - else if (SurfaceType == GeomAbs_OffsetSurface) - { - - EstLimForInfOffs(Line, - surface, - nbsu, - U1inf, - U2inf, - V1inf, - V2inf, - U1new, - U2new, - V1new, - V2new, - NoIntersection); - } - else - { - - EstLimForInfSurf(U1new, U2new, V1new, V2new); - } - } - - if (NoIntersection) - return; - - // modified by NIZHNY-OFV Mon Aug 20 14:56:47 2001 (60963 begin) - if (nbsu < 20) - nbsu = 20; - if (nbsv < 20) - nbsv = 20; - // modified by NIZHNY-OFV Mon Aug 20 14:57:06 2001 (60963 end) - IntCurveSurface_ThePolyhedron polyhedron(surface, nbsu, nbsv, U1new, V1new, U2new, V2new); - Intf_Tool bndTool; - Bnd_Box boxLine; - bndTool.LinBox(Line, polyhedron.Bounding(), boxLine); - for (Standard_Integer nbseg = 1; nbseg <= bndTool.NbSegments(); nbseg++) - { - Standard_Real pinf = bndTool.BeginParam(nbseg); - Standard_Real psup = bndTool.EndParam(nbseg); - if ((psup - pinf) < 1e-10) - { - pinf -= 1e-10; - psup += 1e-10; - } - IntCurveSurface_ThePolygon polygon(curve, pinf, psup, 2); - InternalPerform(curve, polygon, surface, polyhedron, U1new, V1new, U2new, V2new); - } - } -} - -//================================================================================================= - -void IntCurveSurface_Inter::PerformConicSurf(const gp_Circ& Circle, - const TheCurve& curve, - const TheSurface& surface, - const Standard_Real U1, - const Standard_Real V1, - const Standard_Real U2, - const Standard_Real V2) -{ - - GeomAbs_SurfaceType SurfaceType = TheSurfaceTool::GetType(surface); - switch (SurfaceType) - { - case GeomAbs_Plane: { - IntAna_IntConicQuad CircPlane(Circle, - TheSurfaceTool::Plane(surface), - TOLERANCE_ANGULAIRE, - TOLERANCE); - AppendIntAna(curve, surface, CircPlane); - break; - } - case GeomAbs_Cylinder: { - IntAna_IntConicQuad CircCylinder(Circle, TheSurfaceTool::Cylinder(surface)); - AppendIntAna(curve, surface, CircCylinder); - break; - } - case GeomAbs_Cone: { - IntAna_IntConicQuad CircCone(Circle, TheSurfaceTool::Cone(surface)); - AppendIntAna(curve, surface, CircCone); - break; - } - case GeomAbs_Sphere: { - IntAna_IntConicQuad CircSphere(Circle, TheSurfaceTool::Sphere(surface)); - AppendIntAna(curve, surface, CircSphere); - break; - } - default: { - IntCurveSurface_ThePolygon polygon(curve, NBSAMPLESONCIRCLE); - InternalPerform(curve, polygon, surface, U1, V1, U2, V2); - } - } -} - -//================================================================================================= - -void IntCurveSurface_Inter::PerformConicSurf(const gp_Elips& Ellipse, - const TheCurve& curve, - const TheSurface& surface, - const Standard_Real U1, - const Standard_Real V1, - const Standard_Real U2, - const Standard_Real V2) -{ - - GeomAbs_SurfaceType SurfaceType = TheSurfaceTool::GetType(surface); - switch (SurfaceType) - { - case GeomAbs_Plane: { - IntAna_IntConicQuad EllipsePlane(Ellipse, - TheSurfaceTool::Plane(surface), - TOLERANCE_ANGULAIRE, - TOLERANCE); - AppendIntAna(curve, surface, EllipsePlane); - break; - } - case GeomAbs_Cylinder: { - IntAna_IntConicQuad EllipseCylinder(Ellipse, TheSurfaceTool::Cylinder(surface)); - AppendIntAna(curve, surface, EllipseCylinder); - break; - } - case GeomAbs_Cone: { - IntAna_IntConicQuad EllipseCone(Ellipse, TheSurfaceTool::Cone(surface)); - AppendIntAna(curve, surface, EllipseCone); - break; - } - case GeomAbs_Sphere: { - IntAna_IntConicQuad EllipseSphere(Ellipse, TheSurfaceTool::Sphere(surface)); - AppendIntAna(curve, surface, EllipseSphere); - break; - } - default: { - IntCurveSurface_ThePolygon polygon(curve, NBSAMPLESONELLIPSE); - InternalPerform(curve, polygon, surface, U1, V1, U2, V2); - } - } -} - -//================================================================================================= - -void IntCurveSurface_Inter::PerformConicSurf(const gp_Parab& Parab, - const TheCurve& curve, - const TheSurface& surface, - const Standard_Real U1, - const Standard_Real V1, - const Standard_Real U2, - const Standard_Real V2) -{ - - GeomAbs_SurfaceType SurfaceType = TheSurfaceTool::GetType(surface); - switch (SurfaceType) - { - case GeomAbs_Plane: { - IntAna_IntConicQuad ParabPlane(Parab, TheSurfaceTool::Plane(surface), TOLERANCE_ANGULAIRE); - AppendIntAna(curve, surface, ParabPlane); - break; - } - case GeomAbs_Cylinder: { - IntAna_IntConicQuad ParabCylinder(Parab, TheSurfaceTool::Cylinder(surface)); - AppendIntAna(curve, surface, ParabCylinder); - break; - } - case GeomAbs_Cone: { - IntAna_IntConicQuad ParabCone(Parab, TheSurfaceTool::Cone(surface)); - AppendIntAna(curve, surface, ParabCone); - break; - } - case GeomAbs_Sphere: { - IntAna_IntConicQuad ParabSphere(Parab, TheSurfaceTool::Sphere(surface)); - AppendIntAna(curve, surface, ParabSphere); - break; - } - default: { - Standard_Integer nbsu, nbsv; - nbsu = TheSurfaceTool::NbSamplesU(surface, U1, U2); - nbsv = TheSurfaceTool::NbSamplesV(surface, V1, V2); - if (nbsu > 40) - nbsu = 40; - if (nbsv > 40) - nbsv = 40; - IntCurveSurface_ThePolyhedron polyhedron(surface, nbsu, nbsv, U1, V1, U2, V2); - Intf_Tool bndTool; - Bnd_Box boxParab; - bndTool.ParabBox(Parab, polyhedron.Bounding(), boxParab); - for (Standard_Integer nbseg = 1; nbseg <= bndTool.NbSegments(); nbseg++) - { - IntCurveSurface_ThePolygon polygon(curve, - bndTool.BeginParam(nbseg), - bndTool.EndParam(nbseg), - NBSAMPLESONPARAB); - InternalPerform(curve, polygon, surface, polyhedron, U1, V1, U2, V2); - } - } - } -} - -//================================================================================================= - -void IntCurveSurface_Inter::PerformConicSurf(const gp_Hypr& Hypr, - const TheCurve& curve, - const TheSurface& surface, - const Standard_Real U1, - const Standard_Real V1, - const Standard_Real U2, - const Standard_Real V2) -{ - - GeomAbs_SurfaceType SurfaceType = TheSurfaceTool::GetType(surface); - switch (SurfaceType) - { - case GeomAbs_Plane: { - IntAna_IntConicQuad HyprPlane(Hypr, TheSurfaceTool::Plane(surface), TOLERANCE_ANGULAIRE); - AppendIntAna(curve, surface, HyprPlane); - break; - } - case GeomAbs_Cylinder: { - IntAna_IntConicQuad HyprCylinder(Hypr, TheSurfaceTool::Cylinder(surface)); - AppendIntAna(curve, surface, HyprCylinder); - break; - } - case GeomAbs_Cone: { - IntAna_IntConicQuad HyprCone(Hypr, TheSurfaceTool::Cone(surface)); - AppendIntAna(curve, surface, HyprCone); - break; - } - case GeomAbs_Sphere: { - IntAna_IntConicQuad HyprSphere(Hypr, TheSurfaceTool::Sphere(surface)); - AppendIntAna(curve, surface, HyprSphere); - break; - } - default: { - Standard_Integer nbsu, nbsv; - nbsu = TheSurfaceTool::NbSamplesU(surface, U1, U2); - nbsv = TheSurfaceTool::NbSamplesV(surface, V1, V2); - if (nbsu > 40) - nbsu = 40; - if (nbsv > 40) - nbsv = 40; - IntCurveSurface_ThePolyhedron polyhedron(surface, nbsu, nbsv, U1, V1, U2, V2); - Intf_Tool bndTool; - Bnd_Box boxHypr; - bndTool.HyprBox(Hypr, polyhedron.Bounding(), boxHypr); - for (Standard_Integer nbseg = 1; nbseg <= bndTool.NbSegments(); nbseg++) - { - IntCurveSurface_ThePolygon polygon(curve, - bndTool.BeginParam(nbseg), - bndTool.EndParam(nbseg), - NBSAMPLESONHYPR); - InternalPerform(curve, polygon, surface, polyhedron, U1, V1, U2, V2); - } - } - } -} - -//================================================================================================= - -void IntCurveSurface_Inter::AppendIntAna(const TheCurve& curve, - const TheSurface& surface, - const IntAna_IntConicQuad& intana_ConicQuad) -{ - if (intana_ConicQuad.IsDone()) - { - if (intana_ConicQuad.IsInQuadric()) - { - //-- std::cout<<" Courbe Dans la Quadrique !!! Non Traite !!!"<= TOLTANGENCY || (w - W1) >= TOLTANGENCY) - return; - - GeomAbs_SurfaceType aSType = TheSurfaceTool::GetType(surface); - if (TheSurfaceTool::IsUPeriodic(surface) || aSType == GeomAbs_Cylinder || aSType == GeomAbs_Cone - || aSType == GeomAbs_Sphere) - { - u = ElCLib::InPeriod(u, U0, U0 + TheSurfaceTool::UPeriod(surface)); - } - - if (TheSurfaceTool::IsVPeriodic(surface)) - { - v = ElCLib::InPeriod(v, V0, V0 + TheSurfaceTool::VPeriod(surface)); - } - - if ((U0 - u) >= TOLTANGENCY || (u - U1) >= TOLTANGENCY) - return; - if ((V0 - v) >= TOLTANGENCY || (v - V1) >= TOLTANGENCY) - return; - - IntCurveSurface_TransitionOnCurve TransOnCurve; - IntCurveSurface_ComputeTransitions(curve, w, TransOnCurve, surface, u, v); - gp_Pnt P(TheCurveTool::Value(curve, w)); - IntCurveSurface_IntersectionPoint IP(P, u, v, w, TransOnCurve); - Append(IP); //-- invoque la methode de IntCurveSurface_Intersection. -} - -//================================================================================================= - -void IntCurveSurface_Inter::AppendSegment(const TheCurve&, - const Standard_Real, - const Standard_Real, - const TheSurface&) -{ - // std::cout<<" !!! Not Yet Implemented - // IntCurveSurface_Inter::Append(const IntCurveSurf ...)"< -// U , V e t W -//======================================================================= -void SectionPointToParameters(const Intf_SectionPoint& Sp, - const IntCurveSurface_ThePolyhedron& Polyhedron, - const IntCurveSurface_ThePolygon& Polygon, - Standard_Real& U, - Standard_Real& V, - Standard_Real& W) -{ - - Intf_PIType typ; - Standard_Integer Adr1, Adr2; - Standard_Real Param, u, v; - gp_Pnt P(Sp.Pnt()); - - Standard_Integer Pt1, Pt2, Pt3; - Standard_Real u1 = 0., v1 = 0., param; - //---------------------------------------------------------------------- - //-- Calcul des parametres approches sur la surface -- - //---------------------------------------------------------------------- - - Sp.InfoSecond(typ, Adr1, Adr2, Param); - switch (typ) - { - case Intf_VERTEX: //-- Adr1 est le numero du vertex - { - Polyhedron.Parameters(Adr1, u1, v1); - break; - } - case Intf_EDGE: { - Polyhedron.Parameters(Adr1, u1, v1); - Polyhedron.Parameters(Adr2, u, v); - u1 += Param * (u - u1); - v1 += Param * (v - v1); - break; - } - case Intf_FACE: { - Standard_Real ua, va, ub, vb, uc, vc, ca, cb, cc, cabc; - Polyhedron.Triangle(Adr1, Pt1, Pt2, Pt3); - gp_Pnt PA(Polyhedron.Point(Pt1)); - gp_Pnt PB(Polyhedron.Point(Pt2)); - gp_Pnt PC(Polyhedron.Point(Pt3)); - Polyhedron.Parameters(Pt1, ua, va); - Polyhedron.Parameters(Pt2, ub, vb); - Polyhedron.Parameters(Pt3, uc, vc); - gp_Vec Normale(gp_Vec(PA, PB).Crossed(gp_Vec(PA, PC))); - cc = (gp_Vec(PA, PB).Crossed(gp_Vec(PA, P))).Dot(Normale); - ca = (gp_Vec(PB, PC).Crossed(gp_Vec(PB, P))).Dot(Normale); - cb = (gp_Vec(PC, PA).Crossed(gp_Vec(PC, P))).Dot(Normale); - cabc = ca + cb + cc; - - ca /= cabc; - cb /= cabc; - cc /= cabc; - - u1 = ca * ua + cb * ub + cc * uc; - v1 = ca * va + cb * vb + cc * vc; - break; - } - default: { - std::cout << " Default dans SectionPointToParameters " << std::endl; - break; - } - } - //---------------------------------------------------------------------- - //-- Calcul du point approche sur la Curve -- - //---------------------------------------------------------------------- - Standard_Integer SegIndex; - - Sp.InfoFirst(typ, SegIndex, param); - W = Polygon.ApproxParamOnCurve(SegIndex, param); - if (param > 1.0 || param < 0.0) - { - //-- IntCurveSurface_ThePolyhedronTool::Dump(Polyhedron); - //-- IntCurveSurface_ThePolygonTool::Dump(Polygon); - } - U = u1; - V = v1; -} - -//================================================================================================= - -void IntCurveSurface_ComputeTransitions(const TheCurve& curve, - const Standard_Real w, - IntCurveSurface_TransitionOnCurve& TransOnCurve, - const TheSurface& surface, - const Standard_Real u, - const Standard_Real v) -{ - - gp_Vec NSurf, D1U, D1V; // TgCurv; - gp_Pnt Psurf; - Standard_Real CosDir; - - TheSurfaceTool::D1(surface, u, v, Psurf, D1U, D1V); - NSurf = D1U.Crossed(D1V); - TheCurveTool::D1(curve, w, Psurf, D1U); - Standard_Real Norm = NSurf.Magnitude(); - if (Norm > TOLERANCE_ANGULAIRE && D1U.SquareMagnitude() > TOLERANCE_ANGULAIRE) - { - D1U.Normalize(); - CosDir = NSurf.Dot(D1U); - CosDir /= Norm; - if (-CosDir > TOLERANCE_ANGULAIRE) - { - //-- --Curve---> <----Surface---- - TransOnCurve = IntCurveSurface_In; - } - else if (CosDir > TOLERANCE_ANGULAIRE) - { - //-- --Curve---> ----Surface--> - TransOnCurve = IntCurveSurface_Out; - } - else - { - TransOnCurve = IntCurveSurface_Tangent; - } - } - else - { - TransOnCurve = IntCurveSurface_Tangent; - } -} - -//================================================================================================= - -void IntCurveSurface_ComputeParamsOnQuadric(const TheSurface& surface, - const gp_Pnt& P, - Standard_Real& u, - Standard_Real& v) -{ - GeomAbs_SurfaceType SurfaceType = TheSurfaceTool::GetType(surface); - switch (SurfaceType) - { - case GeomAbs_Plane: { - ElSLib::Parameters(TheSurfaceTool::Plane(surface), P, u, v); - break; - } - case GeomAbs_Cylinder: { - ElSLib::Parameters(TheSurfaceTool::Cylinder(surface), P, u, v); - break; - } - case GeomAbs_Cone: { - ElSLib::Parameters(TheSurfaceTool::Cone(surface), P, u, v); - break; - } - case GeomAbs_Sphere: { - ElSLib::Parameters(TheSurfaceTool::Sphere(surface), P, u, v); - break; - } - default: - break; - } -} - -//======================================================================= -// function : EstLimForInfExtr -// purpose : Estimation of limits for infinite surfaces -//======================================================================= -void EstLimForInfExtr(const gp_Lin& Line, - const TheSurface& surface, - const Standard_Boolean IsOffSurf, - const Standard_Integer nbsu, - const Standard_Boolean U1inf, - const Standard_Boolean U2inf, - const Standard_Boolean V1inf, - const Standard_Boolean V2inf, - Standard_Real& U1new, - Standard_Real& U2new, - Standard_Real& V1new, - Standard_Real& V2new, - Standard_Boolean& NoIntersection) - -{ - - NoIntersection = Standard_False; - - Handle(Adaptor3d_Surface) aBasSurf; - - if (IsOffSurf) - aBasSurf = TheSurfaceTool::BasisSurface(surface); - - gp_Dir aDirOfExt; - - if (IsOffSurf) - aDirOfExt = aBasSurf->Direction(); - else - aDirOfExt = TheSurfaceTool::Direction(surface); - - Standard_Real tolang = TOLERANCE_ANGULAIRE; - - if (aDirOfExt.IsParallel(Line.Direction(), tolang)) - { - NoIntersection = Standard_True; - return; - } - - if ((V1inf || V2inf) && !(U1inf || U2inf)) - { - - Standard_Real vmin = RealLast(), vmax = -vmin; - gp_Lin aL; - Standard_Real step = (U2new - U1new) / nbsu; - Standard_Real u = U1new, v; - gp_Pnt aP; - Extrema_POnCurv aP1, aP2; - Standard_Integer i; - - for (i = 0; i <= nbsu; i++) - { - - TheSurfaceTool::D0(surface, u, 0., aP); - aL.SetLocation(aP); - aL.SetDirection(aDirOfExt); - - Extrema_ExtElC aExtr(aL, Line, tolang); - - if (!aExtr.IsDone()) - return; - - if (aExtr.IsParallel()) - { - NoIntersection = Standard_True; - return; - } - - aExtr.Points(1, aP1, aP2); - v = aP1.Parameter(); - vmin = std::min(vmin, v); - vmax = std::max(vmax, v); - - u += step; - } - - vmin = vmin - std::abs(vmin) - 10.; - vmax = vmax + std::abs(vmax) + 10.; - - V1new = std::max(V1new, vmin); - V2new = std::min(V2new, vmax); - } - else if (U1inf || U2inf) - { - - Standard_Real umin = RealLast(), umax = -umin; - Standard_Real u0 = std::min(std::max(0., U1new), U2new); - Standard_Real v0 = std::min(std::max(0., V1new), V2new); - gp_Pnt aP; - TheSurfaceTool::D0(surface, u0, v0, aP); - gp_Pln aRefPln(aP, aDirOfExt); - - Handle(Adaptor3d_Curve) aBasCurv; - - if (IsOffSurf) - aBasCurv = aBasSurf->BasisCurve(); - else - aBasCurv = TheSurfaceTool::BasisCurve(surface); - - ProjLib_Plane Projector(aRefPln); - - Projector.Project(Line); - - if (!Projector.IsDone()) - return; - - gp_Lin2d Line2d = Projector.Line(); - - GeomAbs_CurveType aCurvTyp = aBasCurv->GetType(); - - if (aCurvTyp == GeomAbs_Line) - { - - Projector.Project(aBasCurv->Line()); - - if (!Projector.IsDone()) - return; - - gp_Lin2d aL2d = Projector.Line(); - - IntAna2d_AnaIntersection anInter(Line2d, aL2d); - - if (!anInter.IsDone()) - return; - - if (anInter.IsEmpty() || anInter.IdenticalElements() || anInter.ParallelElements()) - { - NoIntersection = Standard_True; - return; - } - - const IntAna2d_IntPoint& anIntPnt = anInter.Point(1); - umin = umax = anIntPnt.ParamOnSecond(); - } - else if (aCurvTyp == GeomAbs_Parabola || aCurvTyp == GeomAbs_Hyperbola) - { - - IntAna2d_Conic aCon(Line2d); - IntAna2d_AnaIntersection anInter; - - if (aCurvTyp == GeomAbs_Parabola) - { - Projector.Project(aBasCurv->Parabola()); - if (!Projector.IsDone()) - return; - - const gp_Parab2d& aP2d = Projector.Parabola(); - - anInter.Perform(aP2d, aCon); - } - else - { - Projector.Project(aBasCurv->Hyperbola()); - if (!Projector.IsDone()) - return; - - const gp_Hypr2d& aH2d = Projector.Hyperbola(); - anInter.Perform(aH2d, aCon); - } - - if (!anInter.IsDone()) - return; - - if (anInter.IsEmpty()) - { - NoIntersection = Standard_True; - return; - } - - Standard_Integer i, nbint = anInter.NbPoints(); - for (i = 1; i <= nbint; i++) - { - - const IntAna2d_IntPoint& anIntPnt = anInter.Point(i); - - umin = std::min(anIntPnt.ParamOnFirst(), umin); - umax = std::max(anIntPnt.ParamOnFirst(), umax); - } - } - else - { - return; - } - - umin = umin - std::abs(umin) - 10; - umax = umax + std::abs(umax) + 10; - - U1new = std::max(U1new, umin); - U2new = std::min(U2new, umax); - - if (V1inf || V2inf) - { - EstLimForInfExtr(Line, - surface, - IsOffSurf, - nbsu, - Standard_False, - Standard_False, - V1inf, - V2inf, - U1new, - U2new, - V1new, - V2new, - NoIntersection); - } - } - - return; -} - -//======================================================================= -// function : ProjectIntersectAndEstLim -// purpose : project and it's X-axe symmetric line to and -// intersect resulting curve with . -// Then estimate max and min parameters of intersection on -// . -// Is called from EstLimForInfRevl() -//======================================================================= -void ProjectIntersectAndEstLim(const gp_Lin& theLine, - const gp_Pln& thePln, - const ProjLib_Plane& theBasCurvProj, - Standard_Real& theVmin, - Standard_Real& theVmax, - Standard_Boolean& theNoIntersection) -{ - ProjLib_Plane aLineProj(thePln, theLine); - if (!aLineProj.IsDone()) - { -#ifdef OCCT_DEBUG - std::cout << "Info: IntCurveSurface_Inter::ProjectIntersectAndEstLim(), !aLineProj.IsDone()" - << std::endl; -#endif - return; - } - gp_Lin2d aLin2d = aLineProj.Line(); - - // make a second line X-axe symmetric to the first one - gp_Pnt2d aP1 = aLin2d.Location(); - gp_Pnt2d aP2(aP1.XY() + aLin2d.Direction().XY()); - gp_Pnt2d aP1sym(aP1.X(), -aP1.Y()); - gp_Pnt2d aP2sym(aP2.X(), -aP2.Y()); - gp_Lin2d aLin2dsym(aP1sym, gp_Vec2d(aP1sym, aP2sym)); - - // intersect projections - IntAna2d_Conic aCon(aLin2d); - IntAna2d_Conic aConSym(aLin2dsym); - IntAna2d_AnaIntersection anIntersect; - IntAna2d_AnaIntersection anIntersectSym; - - switch (theBasCurvProj.GetType()) - { - case GeomAbs_Line: - anIntersectSym.Perform(theBasCurvProj.Line(), aConSym); - anIntersect.Perform(theBasCurvProj.Line(), aCon); - break; - case GeomAbs_Hyperbola: - anIntersectSym.Perform(theBasCurvProj.Hyperbola(), aConSym); - anIntersect.Perform(theBasCurvProj.Hyperbola(), aCon); - break; - case GeomAbs_Parabola: - anIntersectSym.Perform(theBasCurvProj.Parabola(), aConSym); - anIntersect.Perform(theBasCurvProj.Parabola(), aCon); - break; - default: - return; // not infinite curve - } - - // retrieve params of intersections - Standard_Integer aNbIntPnt = anIntersect.IsDone() ? anIntersect.NbPoints() : 0; - Standard_Integer aNbIntPntSym = anIntersectSym.IsDone() ? anIntersectSym.NbPoints() : 0; - Standard_Integer iPnt, aNbPnt = std::max(aNbIntPnt, aNbIntPntSym); - - if (aNbPnt == 0) - { - theNoIntersection = Standard_True; - return; - } - Standard_Real aParam; - for (iPnt = 1; iPnt <= aNbPnt; iPnt++) - { - if (iPnt <= aNbIntPnt) - { - const IntAna2d_IntPoint& aIntPnt = anIntersect.Point(iPnt); - aParam = aIntPnt.ParamOnFirst(); - theVmin = std::min(theVmin, aParam); - theVmax = std::max(theVmax, aParam); - } - if (iPnt <= aNbIntPntSym) - { - const IntAna2d_IntPoint& aIntPnt = anIntersectSym.Point(iPnt); - aParam = aIntPnt.ParamOnFirst(); - theVmin = std::min(theVmin, aParam); - theVmax = std::max(theVmax, aParam); - } - } - - return; -} - -//======================================================================= -// function : EstLimForInfRevl -// purpose : Estimate V1 and V2 to pass to InternalPerform() if they are -// infinite for Surface of Revolution -// Algo: intersect projections of Line and basis curve on the -// plane passing through revolution axe -//======================================================================= -void EstLimForInfRevl(const gp_Lin& Line, - const TheSurface& surface, - const Standard_Boolean U1inf, - const Standard_Boolean U2inf, - const Standard_Boolean V1inf, - const Standard_Boolean V2inf, - Standard_Real& U1new, - Standard_Real& U2new, - Standard_Real& V1new, - Standard_Real& V2new, - Standard_Boolean& NoIntersection) -{ - - NoIntersection = Standard_False; - - if (U1inf || U2inf) - { - if (U1inf) - U1new = std::max(0., U1new); - else - U2new = std::min(2 * M_PI, U2new); - if (!V1inf && !V2inf) - return; - } - - Handle(Adaptor3d_Curve) aBasisCurve = TheSurfaceTool::BasisCurve(surface); - gp_Ax1 aRevAx = TheSurfaceTool::AxeOfRevolution(surface); - gp_Vec aXVec = aRevAx.Direction(); - constexpr Standard_Real aTolAng = Precision::Angular(); - - // make plane to project a basis curve - gp_Pnt O = aRevAx.Location(); - Standard_Real aU = 0.; - gp_Pnt P = aBasisCurve->Value(aU); - while (O.SquareDistance(P) <= Precision::PConfusion() || aXVec.IsParallel(gp_Vec(O, P), aTolAng)) - { - aU += 1.; - P = aBasisCurve->Value(aU); - if (aU > 3) - // basis curve is a line coinciding with aXVec, P is any not on aXVec - P = gp_Pnt(aU, aU + 1, aU + 2); - } - gp_Vec aNVec = aXVec ^ gp_Vec(O, P); - gp_Pln aPln(gp_Ax3(O, aNVec, aXVec)); - - // project basic curve - ProjLib_Plane aBasCurvProj(aPln); - switch (aBasisCurve->GetType()) - { - case GeomAbs_Line: - aBasCurvProj.Project(aBasisCurve->Line()); - break; - case GeomAbs_Hyperbola: - aBasCurvProj.Project(aBasisCurve->Hyperbola()); - break; - case GeomAbs_Parabola: - aBasCurvProj.Project(aBasisCurve->Parabola()); - break; - default: - return; // not infinite curve - } - if (!aBasCurvProj.IsDone()) - { -#ifdef OCCT_DEBUG - std::cout << "Info: IntCurveSurface_Inter::EstLimForInfRevl(), !aBasCurvProj.IsDone()" - << std::endl; -#endif - return; - } - // make plane to project Line - if (aXVec.IsParallel(Line.Direction(), aTolAng)) - { - P = Line.Location(); - while (O.SquareDistance(P) <= Precision::PConfusion()) - { - aU += 1.; - P = gp_Pnt(aU, aU + 1, aU + 2); // any not on aXVec - } - aNVec = aXVec ^ gp_Vec(O, P); - } - else - aNVec = aXVec.Crossed(Line.Direction()); - - aPln = gp_Pln(gp_Ax3(O, aNVec, aXVec)); - - // make a second plane perpendicular to the first one, rotated around aXVec - gp_Pln aPlnPrp = aPln.Rotated(gp_Ax1(O, aXVec), M_PI / 2.); - - // project Line and it's X-axe symmetric one to plane and intersect - // resulting curve with projection of Basic Curve - Standard_Real aVmin = RealLast(), aVmax = -aVmin; - Standard_Boolean aNoInt1 = Standard_False, aNoInt2 = Standard_False; - ProjectIntersectAndEstLim(Line, aPln, aBasCurvProj, aVmin, aVmax, aNoInt1); - ProjectIntersectAndEstLim(Line, aPlnPrp, aBasCurvProj, aVmin, aVmax, aNoInt2); - - if (aNoInt1 && aNoInt2) - { - NoIntersection = Standard_True; - return; - } - - aVmin = aVmin - std::abs(aVmin) - 10; - aVmax = aVmax + std::abs(aVmax) + 10; - - if (V1inf) - V1new = aVmin; - if (V2inf) - V2new = aVmax; - - // std::cout << "EstLimForInfRevl: Vmin " << V1new << " Vmax " << V2new << std::endl; - - return; -} - -//================================================================================================= - -void EstLimForInfOffs(const gp_Lin& Line, - const TheSurface& surface, - const Standard_Integer nbsu, - const Standard_Boolean U1inf, - const Standard_Boolean U2inf, - const Standard_Boolean V1inf, - const Standard_Boolean V2inf, - Standard_Real& U1new, - Standard_Real& U2new, - Standard_Real& V1new, - Standard_Real& V2new, - Standard_Boolean& NoIntersection) -{ - - NoIntersection = Standard_False; - - const Handle(Adaptor3d_Surface)& aBasSurf = TheSurfaceTool::BasisSurface(surface); - Standard_Real anOffVal = TheSurfaceTool::OffsetValue(surface); - - GeomAbs_SurfaceType aTypeOfBasSurf = aBasSurf->GetType(); - - // case for plane, cylinder and cone - make equivalent surface; - if (aTypeOfBasSurf == GeomAbs_Plane) - { - - gp_Pln aPln = aBasSurf->Plane(); - gp_Vec aT = aPln.Position().XDirection() ^ aPln.Position().YDirection(); - aT *= anOffVal; - aPln.Translate(aT); - IntAna_IntConicQuad LinPlane(Line, aPln, TOLERANCE_ANGULAIRE); - - if (!LinPlane.IsDone()) - return; - - if (LinPlane.IsParallel() || LinPlane.IsInQuadric()) - { - - NoIntersection = Standard_True; - return; - } - - Standard_Real u, v; - ElSLib::Parameters(aPln, LinPlane.Point(1), u, v); - U1new = std::max(U1new, u - 10.); - U2new = std::min(U2new, u + 10.); - V1new = std::max(V1new, v - 10.); - V2new = std::min(V2new, v + 10.); - } - else if (aTypeOfBasSurf == GeomAbs_Cylinder) - { - - gp_Cylinder aCyl = aBasSurf->Cylinder(); - - Standard_Real aR = aCyl.Radius(); - gp_Ax3 anA = aCyl.Position(); - - if (anA.Direct()) - aR += anOffVal; - else - aR -= anOffVal; - - if (aR >= TOLTANGENCY) - { - aCyl.SetRadius(aR); - } - else if (aR <= -TOLTANGENCY) - { - anA.Rotate(gp_Ax1(anA.Location(), anA.Direction()), M_PI); - aCyl.SetPosition(anA); - // modified by NIZHNY-MKK Mon Oct 3 17:37:54 2005 - // aCyl.SetRadius(std::abs(aR)); - aCyl.SetRadius(-aR); - } - else - { - - NoIntersection = Standard_True; - return; - } - - IntAna_IntConicQuad LinCylinder(Line, aCyl); - - if (!LinCylinder.IsDone()) - return; - - if (LinCylinder.IsParallel() || LinCylinder.IsInQuadric()) - { - - NoIntersection = Standard_True; - return; - } - - Standard_Integer i, nbp = LinCylinder.NbPoints(); - Standard_Real vmin = RealLast(), vmax = -vmin, u, v; - - for (i = 1; i <= nbp; i++) - { - - ElSLib::Parameters(aCyl, LinCylinder.Point(i), u, v); - vmin = std::min(vmin, v); - vmax = std::max(vmax, v); - } - - V1new = std::max(V1new, vmin - std::abs(vmin) - 10.); - V2new = std::min(V2new, vmax + std::abs(vmax) + 10.); - } - else if (aTypeOfBasSurf == GeomAbs_Cone) - { - - gp_Cone aCon = aBasSurf->Cone(); - Standard_Real anAng = aCon.SemiAngle(); - Standard_Real aR = aCon.RefRadius() + anOffVal * std::cos(anAng); - gp_Ax3 anA = aCon.Position(); - if (aR >= 0.) - { - - gp_Vec aZ(anA.Direction()); - aZ *= -anOffVal * std::sin(anAng); - anA.Translate(aZ); - aCon.SetPosition(anA); - aCon.SetRadius(aR); - aCon.SetSemiAngle(anAng); - } - else - { - - return; - } - - IntAna_IntConicQuad LinCone(Line, aCon); - - if (!LinCone.IsDone()) - return; - - if (LinCone.IsParallel() || LinCone.IsInQuadric()) - { - - NoIntersection = Standard_True; - return; - } - - Standard_Integer i, nbp = LinCone.NbPoints(); - Standard_Real vmin = RealLast(), vmax = -vmin, u, v; - - for (i = 1; i <= nbp; i++) - { - - ElSLib::Parameters(aCon, LinCone.Point(i), u, v); - vmin = std::min(vmin, v); - vmax = std::max(vmax, v); - } - - V1new = std::max(V1new, vmin - std::abs(vmin) - 10.); - V2new = std::min(V2new, vmax + std::abs(vmax) + 10.); - } - else if (aTypeOfBasSurf == GeomAbs_SurfaceOfExtrusion) - { - - Standard_Real anU1 = U1new, anU2 = U2new; - - EstLimForInfExtr(Line, - surface, - Standard_True, - nbsu, - U1inf, - U2inf, - V1inf, - V2inf, - U1new, - U2new, - V1new, - V2new, - NoIntersection); - - if (NoIntersection) - return; - - if (U1inf || U2inf) - { - - GeomAbs_CurveType aBasCurvType = aBasSurf->BasisCurve()->GetType(); - if (aBasCurvType == GeomAbs_Line) - { - U1new = std::max(anU1, -1.e10); - U2new = std::min(anU2, 1.e10); - } - else if (aBasCurvType == GeomAbs_Parabola) - { - gp_Parab aPrb = aBasSurf->BasisCurve()->Parabola(); - Standard_Real aF = aPrb.Focal(); - Standard_Real dU = 2.e5 * std::sqrt(aF); - U1new = std::max(anU1, -dU); - U2new = std::min(anU2, dU); - } - else if (aBasCurvType == GeomAbs_Hyperbola) - { - U1new = std::max(anU1, -30.); - U2new = std::min(anU2, 30.); - } - else - { - U1new = std::max(anU1, -1.e10); - U2new = std::min(anU2, 1.e10); - } - } - } - else if (aTypeOfBasSurf == GeomAbs_SurfaceOfRevolution) - { - - GeomAbs_CurveType aBasCurvType = aBasSurf->BasisCurve()->GetType(); - if (aBasCurvType == GeomAbs_Line) - { - V1new = std::max(V1new, -1.e10); - V2new = std::min(V2new, 1.e10); - } - else if (aBasCurvType == GeomAbs_Parabola) - { - gp_Parab aPrb = aBasSurf->BasisCurve()->Parabola(); - Standard_Real aF = aPrb.Focal(); - Standard_Real dV = 2.e5 * std::sqrt(aF); - V1new = std::max(V1new, -dV); - V2new = std::min(V2new, dV); - } - else if (aBasCurvType == GeomAbs_Hyperbola) - { - V1new = std::max(V1new, -30.); - V2new = std::min(V2new, 30.); - } - else - { - V1new = std::max(V1new, -1.e10); - V2new = std::min(V2new, 1.e10); - } - } - else - { - - V1new = std::max(V1new, -1.e10); - V2new = std::min(V2new, 1.e10); - } -} - -//================================================================================================= - -void EstLimForInfSurf(Standard_Real& U1new, - Standard_Real& U2new, - Standard_Real& V1new, - Standard_Real& V2new) -{ - U1new = std::max(U1new, -1.e10); - U2new = std::min(U2new, 1.e10); - V1new = std::max(V1new, -1.e10); - V2new = std::min(V2new, 1.e10); -} diff --git a/src/ModelingAlgorithms/TKGeomAlgo/IntCurveSurface/IntCurveSurface_Inter.pxx b/src/ModelingAlgorithms/TKGeomAlgo/IntCurveSurface/IntCurveSurface_Inter.pxx new file mode 100644 index 0000000000..09c539278d --- /dev/null +++ b/src/ModelingAlgorithms/TKGeomAlgo/IntCurveSurface/IntCurveSurface_Inter.pxx @@ -0,0 +1,971 @@ +// Copyright (c) 1993-1999 Matra Datavision +// Copyright (c) 1999-2014 OPEN CASCADE SAS +// +// This file is part of Open CASCADE Technology software library. +// +// This library is free software; you can redistribute it and/or modify it under +// the terms of the GNU Lesser General Public License version 2.1 as published +// by the Free Software Foundation, with special exception defined in the file +// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT +// distribution for complete text of the license and disclaimer of any warranty. +// +// Alternatively, this file may be used under the terms of Open CASCADE +// commercial license or contractual agreement. + +#ifndef IntCurveSurface_Inter_PXX +#define IntCurveSurface_Inter_PXX + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "IntCurveSurface_InterUtils.pxx" + +namespace IntCurveSurface_InterImpl +{ + +constexpr double THE_TOLTANGENCY = 0.00000001; +constexpr double THE_TOLERANCE_ANGULAIRE = 1.e-12; +constexpr double THE_TOLERANCE = 0.00000001; +constexpr int THE_NBSAMPLESONCIRCLE = 32; +constexpr int THE_NBSAMPLESONELLIPSE = 32; +constexpr int THE_NBSAMPLESONPARAB = 16; +constexpr int THE_NBSAMPLESONHYPR = 32; + +//! Perform intersection decomposing surface by C2 intervals. +//! @tparam CurveType The curve type +//! @tparam CurveTool The curve tool class +//! @tparam SurfaceType The surface type +//! @tparam SurfaceTool The surface tool class +//! @tparam PerformBoundsFunc Callback type for Perform with bounds +template +void Perform(const CurveType& theCurve, + const SurfaceType& theSurface, + bool& theDone, + ResetFunc theReset, + PerformBoundsFunc thePerformBounds) +{ + theReset(); + theDone = true; + + NCollection_Vector aIntervals; + IntCurveSurface_InterUtils::DecomposeSurfaceIntervals(theSurface, + aIntervals); + + for (const IntCurveSurface_InterUtils::UVBounds& aBounds : aIntervals) + { + thePerformBounds(theCurve, theSurface, aBounds.U0, aBounds.V0, aBounds.U1, aBounds.V1); + } +} + +//! Perform intersection with given UV bounds. +//! @tparam CurveType The curve type +//! @tparam CurveTool The curve tool class +//! @tparam SurfaceType The surface type +//! @tparam SurfaceTool The surface tool class +//! @tparam PolygonType The polygon type +//! @tparam PerformConicFunc Callback for conic surface intersection +//! @tparam InternalPerformFunc Callback for internal perform +//! @tparam InternalPerformQuadricFunc Callback for quadric perform +template +void PerformBounds(const CurveType& theCurve, + const SurfaceType& theSurface, + const Standard_Real theU1, + const Standard_Real theV1, + const Standard_Real theU2, + const Standard_Real theV2, + PerformConicFunc thePerformConic, + InternalPerformFunc theInternalPerform, + InternalPerformQuadricFunc theInternalPerformQuadric) +{ + // Protection from double type overflow (bug26525). + Standard_Real UU1 = theU1, UU2 = theU2, VV1 = theV1, VV2 = theV2; + IntCurveSurface_InterUtils::ClampUVParameters(UU1, UU2, VV1, VV2); + + GeomAbs_CurveType aCurveType = CurveTool::GetType(theCurve); + + switch (aCurveType) + { + case GeomAbs_Line: + thePerformConic(CurveTool::Line(theCurve), theCurve, theSurface, UU1, VV1, UU2, VV2); + break; + case GeomAbs_Circle: + thePerformConic(CurveTool::Circle(theCurve), theCurve, theSurface, UU1, VV1, UU2, VV2); + break; + case GeomAbs_Ellipse: + thePerformConic(CurveTool::Ellipse(theCurve), theCurve, theSurface, UU1, VV1, UU2, VV2); + break; + case GeomAbs_Parabola: + thePerformConic(CurveTool::Parabola(theCurve), theCurve, theSurface, UU1, VV1, UU2, VV2); + break; + case GeomAbs_Hyperbola: + thePerformConic(CurveTool::Hyperbola(theCurve), theCurve, theSurface, UU1, VV1, UU2, VV2); + break; + default: { + Standard_Integer nbIntervalsOnCurve = CurveTool::NbIntervals(theCurve, GeomAbs_C2); + GeomAbs_SurfaceType aSurfaceType = SurfaceTool::GetType(theSurface); + if ((aSurfaceType != GeomAbs_Plane) && (aSurfaceType != GeomAbs_Cylinder) + && (aSurfaceType != GeomAbs_Cone) && (aSurfaceType != GeomAbs_Sphere)) + { + if (nbIntervalsOnCurve > 1) + { + TColStd_Array1OfReal TabW(1, nbIntervalsOnCurve + 1); + CurveTool::Intervals(theCurve, TabW, GeomAbs_C2); + for (Standard_Integer i = 1; i <= nbIntervalsOnCurve; i++) + { + Standard_Real u1 = TabW.Value(i); + Standard_Real u2 = TabW.Value(i + 1); + + Handle(TColStd_HArray1OfReal) aPars; + Standard_Real defl = 0.1; + Standard_Integer NbMin = 10; + CurveTool::SamplePars(theCurve, u1, u2, defl, NbMin, aPars); + + PolygonType polygon(theCurve, aPars->Array1()); + theInternalPerform(theCurve, polygon, theSurface, UU1, VV1, UU2, VV2); + } + } + else + { + Standard_Real u1 = CurveTool::FirstParameter(theCurve); + Standard_Real u2 = CurveTool::LastParameter(theCurve); + + Handle(TColStd_HArray1OfReal) aPars; + Standard_Real defl = 0.1; + Standard_Integer NbMin = 10; + CurveTool::SamplePars(theCurve, u1, u2, defl, NbMin, aPars); + + PolygonType polygon(theCurve, aPars->Array1()); + theInternalPerform(theCurve, polygon, theSurface, UU1, VV1, UU2, VV2); + } + } + else + { + theInternalPerformQuadric(theCurve, theSurface); + } + } + } +} + +//! Perform with polygon, creating polyhedron internally. +template +void PerformPolygon(const CurveType& theCurve, + const PolygonType& thePolygon, + const SurfaceType& theSurface, + bool& theDone, + ResetFunc theReset, + PerformPolyFunc thePerformPoly) +{ + theReset(); + theDone = true; + Standard_Real u1 = SurfaceTool::FirstUParameter(theSurface); + Standard_Real v1 = SurfaceTool::FirstVParameter(theSurface); + Standard_Real u2 = SurfaceTool::LastUParameter(theSurface); + Standard_Real v2 = SurfaceTool::LastVParameter(theSurface); + Standard_Integer nbsu = SurfaceTool::NbSamplesU(theSurface, u1, u2); + Standard_Integer nbsv = SurfaceTool::NbSamplesV(theSurface, v1, v2); + if (nbsu > 40) + nbsu = 40; + if (nbsv > 40) + nbsv = 40; + PolyhedronType polyhedron(theSurface, nbsu, nbsv, u1, v1, u2, v2); + thePerformPoly(theCurve, thePolygon, theSurface, polyhedron); +} + +//! Perform with polyhedron, creating polygon internally. +template +void PerformPolyhedron(const CurveType& theCurve, + const SurfaceType& theSurface, + const PolyhedronType& thePolyhedron, + bool& theDone, + ResetFunc theReset, + PerformPolyFunc thePerformPoly) +{ + theReset(); + theDone = true; + Standard_Real u1 = CurveTool::FirstParameter(theCurve); + Standard_Real u2 = CurveTool::LastParameter(theCurve); + PolygonType polygon(theCurve, CurveTool::NbSamples(theCurve, u1, u2)); + thePerformPoly(theCurve, polygon, theSurface, thePolyhedron); +} + +//! Perform with both polygon and polyhedron provided. +template +void PerformPolygonPolyhedron(const CurveType& theCurve, + const PolygonType& thePolygon, + const SurfaceType& theSurface, + const PolyhedronType& thePolyhedron, + bool& theDone, + ResetFunc theReset, + InternalPerformFunc theInternalPerform) +{ + theReset(); + theDone = true; + Standard_Real u1 = SurfaceTool::FirstUParameter(theSurface); + Standard_Real v1 = SurfaceTool::FirstVParameter(theSurface); + Standard_Real u2 = SurfaceTool::LastUParameter(theSurface); + Standard_Real v2 = SurfaceTool::LastVParameter(theSurface); + theInternalPerform(theCurve, thePolygon, theSurface, thePolyhedron, u1, v1, u2, v2); +} + +//! Perform with polygon, polyhedron and bounding sort box. +template +void PerformPolygonPolyhedronBSB(const CurveType& theCurve, + const PolygonType& thePolygon, + const SurfaceType& theSurface, + const PolyhedronType& thePolyhedron, + Bnd_BoundSortBox& theBSB, + bool& theDone, + ResetFunc theReset, + InternalPerformBSBFunc theInternalPerform) +{ + theReset(); + theDone = true; + Standard_Real u1 = SurfaceTool::FirstUParameter(theSurface); + Standard_Real v1 = SurfaceTool::FirstVParameter(theSurface); + Standard_Real u2 = SurfaceTool::LastUParameter(theSurface); + Standard_Real v2 = SurfaceTool::LastVParameter(theSurface); + theInternalPerform(theCurve, thePolygon, theSurface, thePolyhedron, u1, v1, u2, v2, theBSB); +} + +//! Internal perform with interference from BSB. +template +void InternalPerformBSB(const CurveType& theCurve, + const PolygonType& thePolygon, + const SurfaceType& theSurface, + const PolyhedronType& thePolyhedron, + const Standard_Real theU0, + const Standard_Real theV0, + const Standard_Real theU1, + const Standard_Real theV1, + Bnd_BoundSortBox& theBSB, + AppendFunc theAppend) +{ + InterferenceType interference(thePolygon, thePolyhedron, theBSB); + CSFunctionType theicsfunction(theSurface, theCurve); + ExactInterType intersectionExacte(theicsfunction, THE_TOLTANGENCY); + math_FunctionSetRoot rsnld(intersectionExacte.Function()); + + Standard_Real winf = thePolygon.InfParameter(); + Standard_Real wsup = thePolygon.SupParameter(); + + IntCurveSurface_InterUtils::SortedStartPoints aStartPoints; + IntCurveSurface_InterUtils:: + CollectInterferencePoints(interference, + thePolyhedron, + thePolygon, + aStartPoints); + IntCurveSurface_InterUtils::SortStartPoints(aStartPoints); + + NCollection_Vector aResultPoints; + IntCurveSurface_InterUtils:: + ProcessSortedPoints( + intersectionExacte, + rsnld, + aStartPoints, + theU0, + theU1, + theV0, + theV1, + winf, + wsup, + theCurve, + theSurface, + aResultPoints); + + for (const IntCurveSurface_IntersectionPoint& aPoint : aResultPoints) + { + theAppend(aPoint); + } +} + +//! Internal perform without BSB. +template +void InternalPerform(const CurveType& theCurve, + const PolygonType& thePolygon, + const SurfaceType& theSurface, + const PolyhedronType& thePolyhedron, + const Standard_Real theU0, + const Standard_Real theV0, + const Standard_Real theU1, + const Standard_Real theV1, + AppendFunc theAppend) +{ + InterferenceType interference(thePolygon, thePolyhedron); + CSFunctionType theicsfunction(theSurface, theCurve); + ExactInterType intersectionExacte(theicsfunction, THE_TOLTANGENCY); + math_FunctionSetRoot rsnld(intersectionExacte.Function()); + + Standard_Real winf = thePolygon.InfParameter(); + Standard_Real wsup = thePolygon.SupParameter(); + + IntCurveSurface_InterUtils::SortedStartPoints aStartPoints; + IntCurveSurface_InterUtils:: + CollectInterferencePoints(interference, + thePolyhedron, + thePolygon, + aStartPoints); + IntCurveSurface_InterUtils::SortStartPoints(aStartPoints); + + NCollection_Vector aResultPoints; + IntCurveSurface_InterUtils:: + ProcessSortedPoints( + intersectionExacte, + rsnld, + aStartPoints, + theU0, + theU1, + theV0, + theV1, + winf, + wsup, + theCurve, + theSurface, + aResultPoints); + + for (const IntCurveSurface_IntersectionPoint& aPoint : aResultPoints) + { + theAppend(aPoint); + } +} + +//! Internal perform for curve-quadric intersection. +template +void InternalPerformCurveQuadric(const CurveType& theCurve, + const SurfaceType& theSurface, + AppendFunc theAppend) +{ + NCollection_Vector aPoints; + + IntCurveSurface_InterUtils:: + PerformCurveQuadric( + theCurve, + theSurface, + aPoints); + + for (const IntCurveSurface_IntersectionPoint& aPoint : aPoints) + { + theAppend(aPoint); + } +} + +//! Internal perform with polygon and UV bounds, creating polyhedron as needed. +template +void InternalPerformPolygonBounds(const CurveType& theCurve, + const PolygonType& thePolygon, + const SurfaceType& theSurface, + const Standard_Real theU1, + const Standard_Real theV1, + const Standard_Real theU2, + const Standard_Real theV2, + InternalPerformPolyFunc theInternalPerformPoly, + AppendFunc theAppend) +{ + GeomAbs_SurfaceType aSurfaceType = SurfaceTool::GetType(theSurface); + if ((aSurfaceType != GeomAbs_Plane) && (aSurfaceType != GeomAbs_Cylinder) + && (aSurfaceType != GeomAbs_Cone) && (aSurfaceType != GeomAbs_Sphere)) + { + if (aSurfaceType != GeomAbs_BSplineSurface) + { + Standard_Integer nbsu = SurfaceTool::NbSamplesU(theSurface, theU1, theU2); + Standard_Integer nbsv = SurfaceTool::NbSamplesV(theSurface, theV1, theV2); + if (nbsu > 40) + nbsu = 40; + if (nbsv > 40) + nbsv = 40; + PolyhedronType polyhedron(theSurface, nbsu, nbsv, theU1, theV1, theU2, theV2); + theInternalPerformPoly(theCurve, + thePolygon, + theSurface, + polyhedron, + theU1, + theV1, + theU2, + theV2); + } + else + { + Handle(Adaptor3d_Surface) aS = SurfaceTool::UTrim(theSurface, theU1, theU2, 1.e-9); + aS = aS->VTrim(theV1, theV2, 1.e-9); + Handle(Adaptor3d_TopolTool) aTopTool = new Adaptor3d_TopolTool(aS); + Standard_Real defl = 0.1; + aTopTool->SamplePnts(defl, 10, 10); + + Standard_Integer nbpu = aTopTool->NbSamplesU(); + Standard_Integer nbpv = aTopTool->NbSamplesV(); + TColStd_Array1OfReal Upars(1, nbpu), Vpars(1, nbpv); + aTopTool->UParameters(Upars); + aTopTool->VParameters(Vpars); + + PolyhedronType polyhedron(theSurface, Upars, Vpars); + theInternalPerformPoly(theCurve, + thePolygon, + theSurface, + polyhedron, + theU1, + theV1, + theU2, + theV2); + } + } + else + { + InternalPerformCurveQuadric(theCurve, theSurface, theAppend); + } +} + +//! Perform conic (line) surface intersection. +template +void PerformConicSurfLine(const gp_Lin& theLine, + const CurveType& theCurve, + const SurfaceType& theSurface, + const Standard_Real theU1, + const Standard_Real theV1, + const Standard_Real theU2, + const Standard_Real theV2, + AppendIntAnaFunc theAppendIntAna, + InternalPerformPolyFunc theInternalPerformPoly, + AppendFunc theAppend) +{ + GeomAbs_SurfaceType aSurfaceType = SurfaceTool::GetType(theSurface); + Standard_Boolean isAnaProcessed = Standard_True; + + switch (aSurfaceType) + { + case GeomAbs_Plane: { + IntAna_IntConicQuad LinPlane(theLine, + SurfaceTool::Plane(theSurface), + THE_TOLERANCE_ANGULAIRE); + theAppendIntAna(theCurve, theSurface, LinPlane); + break; + } + case GeomAbs_Cylinder: { + IntAna_IntConicQuad LinCylinder(theLine, SurfaceTool::Cylinder(theSurface)); + theAppendIntAna(theCurve, theSurface, LinCylinder); + break; + } + case GeomAbs_Sphere: { + IntAna_IntConicQuad LinSphere(theLine, SurfaceTool::Sphere(theSurface)); + theAppendIntAna(theCurve, theSurface, LinSphere); + break; + } + case GeomAbs_Torus: { + NCollection_Vector aPoints; + if (IntCurveSurface_InterUtils:: + ProcessLinTorus(theLine, + theCurve, + theSurface, + aPoints)) + { + for (const IntCurveSurface_IntersectionPoint& aPoint : aPoints) + { + theAppend(aPoint); + } + } + else + isAnaProcessed = Standard_False; + break; + } + case GeomAbs_Cone: { + constexpr Standard_Real correction = 1.E+5 * Precision::Angular(); + gp_Cone cn = SurfaceTool::Cone(theSurface); + if (std::abs(cn.SemiAngle()) < M_PI / 2.0 - correction) + { + IntAna_IntConicQuad LinCone(theLine, cn); + theAppendIntAna(theCurve, theSurface, LinCone); + } + else + isAnaProcessed = Standard_False; + break; + } + default: + isAnaProcessed = Standard_False; + } + + if (!isAnaProcessed) + { + Standard_Integer nbsu = SurfaceTool::NbSamplesU(theSurface, theU1, theU2); + Standard_Integer nbsv = SurfaceTool::NbSamplesV(theSurface, theV1, theV2); + + Standard_Boolean U1inf = Precision::IsInfinite(theU1); + Standard_Boolean U2inf = Precision::IsInfinite(theU2); + Standard_Boolean V1inf = Precision::IsInfinite(theV1); + Standard_Boolean V2inf = Precision::IsInfinite(theV2); + + Standard_Real U1new = theU1, U2new = theU2, V1new = theV1, V2new = theV2; + Standard_Boolean NoIntersection = Standard_False; + + if (U1inf || U2inf || V1inf || V2inf) + { + if (aSurfaceType == GeomAbs_SurfaceOfExtrusion) + { + IntCurveSurface_InterUtils::EstLimForInfExtr(theLine, + theSurface, + Standard_False, + nbsu, + U1inf, + U2inf, + V1inf, + V2inf, + U1new, + U2new, + V1new, + V2new, + NoIntersection); + } + else if (aSurfaceType == GeomAbs_SurfaceOfRevolution) + { + IntCurveSurface_InterUtils::EstLimForInfRevl(theLine, + theSurface, + U1inf, + U2inf, + V1inf, + V2inf, + U1new, + U2new, + V1new, + V2new, + NoIntersection); + } + else if (aSurfaceType == GeomAbs_OffsetSurface) + { + IntCurveSurface_InterUtils::EstLimForInfOffs(theLine, + theSurface, + nbsu, + U1inf, + U2inf, + V1inf, + V2inf, + U1new, + U2new, + V1new, + V2new, + NoIntersection); + } + else + { + IntCurveSurface_InterUtils::EstLimForInfSurf(U1new, U2new, V1new, V2new); + } + } + + if (NoIntersection) + return; + + if (nbsu < 20) + nbsu = 20; + if (nbsv < 20) + nbsv = 20; + + PolyhedronType polyhedron(theSurface, nbsu, nbsv, U1new, V1new, U2new, V2new); + Intf_Tool bndTool; + Bnd_Box boxLine; + bndTool.LinBox(theLine, polyhedron.Bounding(), boxLine); + + for (Standard_Integer nbseg = 1; nbseg <= bndTool.NbSegments(); nbseg++) + { + Standard_Real pinf = bndTool.BeginParam(nbseg); + Standard_Real psup = bndTool.EndParam(nbseg); + if ((psup - pinf) < 1e-10) + { + pinf -= 1e-10; + psup += 1e-10; + } + PolygonType polygon(theCurve, pinf, psup, 2); + theInternalPerformPoly(theCurve, polygon, theSurface, polyhedron, U1new, V1new, U2new, V2new); + } + } +} + +//! Perform conic (circle) surface intersection. +template +void PerformConicSurfCircle(const gp_Circ& theCircle, + const CurveType& theCurve, + const SurfaceType& theSurface, + const Standard_Real theU1, + const Standard_Real theV1, + const Standard_Real theU2, + const Standard_Real theV2, + AppendIntAnaFunc theAppendIntAna, + InternalPerformFunc theInternalPerform) +{ + GeomAbs_SurfaceType aSurfaceType = SurfaceTool::GetType(theSurface); + switch (aSurfaceType) + { + case GeomAbs_Plane: { + IntAna_IntConicQuad CircPlane(theCircle, + SurfaceTool::Plane(theSurface), + THE_TOLERANCE_ANGULAIRE, + THE_TOLERANCE); + theAppendIntAna(theCurve, theSurface, CircPlane); + break; + } + case GeomAbs_Cylinder: { + IntAna_IntConicQuad CircCylinder(theCircle, SurfaceTool::Cylinder(theSurface)); + theAppendIntAna(theCurve, theSurface, CircCylinder); + break; + } + case GeomAbs_Cone: { + IntAna_IntConicQuad CircCone(theCircle, SurfaceTool::Cone(theSurface)); + theAppendIntAna(theCurve, theSurface, CircCone); + break; + } + case GeomAbs_Sphere: { + IntAna_IntConicQuad CircSphere(theCircle, SurfaceTool::Sphere(theSurface)); + theAppendIntAna(theCurve, theSurface, CircSphere); + break; + } + default: { + PolygonType polygon(theCurve, THE_NBSAMPLESONCIRCLE); + theInternalPerform(theCurve, polygon, theSurface, theU1, theV1, theU2, theV2); + } + } +} + +//! Perform conic (ellipse) surface intersection. +template +void PerformConicSurfEllipse(const gp_Elips& theEllipse, + const CurveType& theCurve, + const SurfaceType& theSurface, + const Standard_Real theU1, + const Standard_Real theV1, + const Standard_Real theU2, + const Standard_Real theV2, + AppendIntAnaFunc theAppendIntAna, + InternalPerformFunc theInternalPerform) +{ + GeomAbs_SurfaceType aSurfaceType = SurfaceTool::GetType(theSurface); + switch (aSurfaceType) + { + case GeomAbs_Plane: { + IntAna_IntConicQuad EllipsePlane(theEllipse, + SurfaceTool::Plane(theSurface), + THE_TOLERANCE_ANGULAIRE, + THE_TOLERANCE); + theAppendIntAna(theCurve, theSurface, EllipsePlane); + break; + } + case GeomAbs_Cylinder: { + IntAna_IntConicQuad EllipseCylinder(theEllipse, SurfaceTool::Cylinder(theSurface)); + theAppendIntAna(theCurve, theSurface, EllipseCylinder); + break; + } + case GeomAbs_Cone: { + IntAna_IntConicQuad EllipseCone(theEllipse, SurfaceTool::Cone(theSurface)); + theAppendIntAna(theCurve, theSurface, EllipseCone); + break; + } + case GeomAbs_Sphere: { + IntAna_IntConicQuad EllipseSphere(theEllipse, SurfaceTool::Sphere(theSurface)); + theAppendIntAna(theCurve, theSurface, EllipseSphere); + break; + } + default: { + PolygonType polygon(theCurve, THE_NBSAMPLESONELLIPSE); + theInternalPerform(theCurve, polygon, theSurface, theU1, theV1, theU2, theV2); + } + } +} + +//! Perform conic (parabola) surface intersection. +template +void PerformConicSurfParabola(const gp_Parab& theParab, + const CurveType& theCurve, + const SurfaceType& theSurface, + const Standard_Real theU1, + const Standard_Real theV1, + const Standard_Real theU2, + const Standard_Real theV2, + AppendIntAnaFunc theAppendIntAna, + InternalPerformPolyFunc theInternalPerformPoly) +{ + GeomAbs_SurfaceType aSurfaceType = SurfaceTool::GetType(theSurface); + switch (aSurfaceType) + { + case GeomAbs_Plane: { + IntAna_IntConicQuad ParabPlane(theParab, + SurfaceTool::Plane(theSurface), + THE_TOLERANCE_ANGULAIRE); + theAppendIntAna(theCurve, theSurface, ParabPlane); + break; + } + case GeomAbs_Cylinder: { + IntAna_IntConicQuad ParabCylinder(theParab, SurfaceTool::Cylinder(theSurface)); + theAppendIntAna(theCurve, theSurface, ParabCylinder); + break; + } + case GeomAbs_Cone: { + IntAna_IntConicQuad ParabCone(theParab, SurfaceTool::Cone(theSurface)); + theAppendIntAna(theCurve, theSurface, ParabCone); + break; + } + case GeomAbs_Sphere: { + IntAna_IntConicQuad ParabSphere(theParab, SurfaceTool::Sphere(theSurface)); + theAppendIntAna(theCurve, theSurface, ParabSphere); + break; + } + default: { + Standard_Integer nbsu = SurfaceTool::NbSamplesU(theSurface, theU1, theU2); + Standard_Integer nbsv = SurfaceTool::NbSamplesV(theSurface, theV1, theV2); + if (nbsu > 40) + nbsu = 40; + if (nbsv > 40) + nbsv = 40; + PolyhedronType polyhedron(theSurface, nbsu, nbsv, theU1, theV1, theU2, theV2); + Intf_Tool bndTool; + Bnd_Box boxParab; + bndTool.ParabBox(theParab, polyhedron.Bounding(), boxParab); + for (Standard_Integer nbseg = 1; nbseg <= bndTool.NbSegments(); nbseg++) + { + PolygonType polygon(theCurve, + bndTool.BeginParam(nbseg), + bndTool.EndParam(nbseg), + THE_NBSAMPLESONPARAB); + theInternalPerformPoly(theCurve, + polygon, + theSurface, + polyhedron, + theU1, + theV1, + theU2, + theV2); + } + } + } +} + +//! Perform conic (hyperbola) surface intersection. +template +void PerformConicSurfHyperbola(const gp_Hypr& theHypr, + const CurveType& theCurve, + const SurfaceType& theSurface, + const Standard_Real theU1, + const Standard_Real theV1, + const Standard_Real theU2, + const Standard_Real theV2, + AppendIntAnaFunc theAppendIntAna, + InternalPerformPolyFunc theInternalPerformPoly) +{ + GeomAbs_SurfaceType aSurfaceType = SurfaceTool::GetType(theSurface); + switch (aSurfaceType) + { + case GeomAbs_Plane: { + IntAna_IntConicQuad HyprPlane(theHypr, + SurfaceTool::Plane(theSurface), + THE_TOLERANCE_ANGULAIRE); + theAppendIntAna(theCurve, theSurface, HyprPlane); + break; + } + case GeomAbs_Cylinder: { + IntAna_IntConicQuad HyprCylinder(theHypr, SurfaceTool::Cylinder(theSurface)); + theAppendIntAna(theCurve, theSurface, HyprCylinder); + break; + } + case GeomAbs_Cone: { + IntAna_IntConicQuad HyprCone(theHypr, SurfaceTool::Cone(theSurface)); + theAppendIntAna(theCurve, theSurface, HyprCone); + break; + } + case GeomAbs_Sphere: { + IntAna_IntConicQuad HyprSphere(theHypr, SurfaceTool::Sphere(theSurface)); + theAppendIntAna(theCurve, theSurface, HyprSphere); + break; + } + default: { + Standard_Integer nbsu = SurfaceTool::NbSamplesU(theSurface, theU1, theU2); + Standard_Integer nbsv = SurfaceTool::NbSamplesV(theSurface, theV1, theV2); + if (nbsu > 40) + nbsu = 40; + if (nbsv > 40) + nbsv = 40; + PolyhedronType polyhedron(theSurface, nbsu, nbsv, theU1, theV1, theU2, theV2); + Intf_Tool bndTool; + Bnd_Box boxHypr; + bndTool.HyprBox(theHypr, polyhedron.Bounding(), boxHypr); + for (Standard_Integer nbseg = 1; nbseg <= bndTool.NbSegments(); nbseg++) + { + PolygonType polygon(theCurve, + bndTool.BeginParam(nbseg), + bndTool.EndParam(nbseg), + THE_NBSAMPLESONHYPR); + theInternalPerformPoly(theCurve, + polygon, + theSurface, + polyhedron, + theU1, + theV1, + theU2, + theV2); + } + } + } +} + +//! Append analytical intersection results. +template +void AppendIntAna(const CurveType& theCurve, + const SurfaceType& theSurface, + const IntAna_IntConicQuad& theIntAna, + bool& theIsParallel, + AppendFunc theAppend) +{ + Standard_Boolean aIsParallel = Standard_False; + NCollection_Vector aPoints; + + if (IntCurveSurface_InterUtils::ProcessIntAna( + theCurve, + theSurface, + theIntAna, + aIsParallel, + aPoints)) + { + if (aIsParallel) + { + theIsParallel = true; + } + else + { + for (const IntCurveSurface_IntersectionPoint& aPoint : aPoints) + { + theAppend(aPoint); + } + } + } +} + +} // namespace IntCurveSurface_InterImpl + +#endif // IntCurveSurface_Inter_PXX diff --git a/src/ModelingAlgorithms/TKGeomAlgo/IntCurveSurface/IntCurveSurface_InterUtils.pxx b/src/ModelingAlgorithms/TKGeomAlgo/IntCurveSurface/IntCurveSurface_InterUtils.pxx new file mode 100644 index 0000000000..4addfcf5de --- /dev/null +++ b/src/ModelingAlgorithms/TKGeomAlgo/IntCurveSurface/IntCurveSurface_InterUtils.pxx @@ -0,0 +1,1512 @@ +// Copyright (c) 1993-1999 Matra Datavision +// Copyright (c) 1999-2014 OPEN CASCADE SAS +// +// This file is part of Open CASCADE Technology software library. +// +// This library is free software; you can redistribute it and/or modify it under +// the terms of the GNU Lesser General Public License version 2.1 as published +// by the Free Software Foundation, with special exception defined in the file +// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT +// distribution for complete text of the license and disclaimer of any warranty. +// +// Alternatively, this file may be used under the terms of Open CASCADE +// commercial license or contractual agreement. + +#ifndef IntCurveSurface_InterUtils_HeaderFile +#define IntCurveSurface_InterUtils_HeaderFile + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +namespace IntCurveSurface_InterUtils +{ + +constexpr double THE_TOLERANCE_ANGULAIRE = 1.e-12; +constexpr double THE_TOLTANGENCY = 0.00000001; + +//! Project theLine and its X-axis symmetric line to thePln and +//! intersect resulting curve with theBasCurvProj. +//! Then estimate max and min parameters of intersection on theBasCurvProj. +inline void ProjectIntersectAndEstLim(const gp_Lin& theLine, + const gp_Pln& thePln, + const ProjLib_Plane& theBasCurvProj, + Standard_Real& theVmin, + Standard_Real& theVmax, + Standard_Boolean& theNoIntersection) +{ + ProjLib_Plane aLineProj(thePln, theLine); + if (!aLineProj.IsDone()) + { + return; + } + gp_Lin2d aLin2d = aLineProj.Line(); + + // make a second line X-axe symmetric to the first one + gp_Pnt2d aP1 = aLin2d.Location(); + gp_Pnt2d aP2(aP1.XY() + aLin2d.Direction().XY()); + gp_Pnt2d aP1sym(aP1.X(), -aP1.Y()); + gp_Pnt2d aP2sym(aP2.X(), -aP2.Y()); + gp_Lin2d aLin2dsym(aP1sym, gp_Vec2d(aP1sym, aP2sym)); + + // intersect projections + IntAna2d_Conic aCon(aLin2d); + IntAna2d_Conic aConSym(aLin2dsym); + IntAna2d_AnaIntersection anIntersect; + IntAna2d_AnaIntersection anIntersectSym; + + switch (theBasCurvProj.GetType()) + { + case GeomAbs_Line: + anIntersectSym.Perform(theBasCurvProj.Line(), aConSym); + anIntersect.Perform(theBasCurvProj.Line(), aCon); + break; + case GeomAbs_Hyperbola: + anIntersectSym.Perform(theBasCurvProj.Hyperbola(), aConSym); + anIntersect.Perform(theBasCurvProj.Hyperbola(), aCon); + break; + case GeomAbs_Parabola: + anIntersectSym.Perform(theBasCurvProj.Parabola(), aConSym); + anIntersect.Perform(theBasCurvProj.Parabola(), aCon); + break; + default: + return; // not infinite curve + } + + // retrieve params of intersections + Standard_Integer aNbIntPnt = anIntersect.IsDone() ? anIntersect.NbPoints() : 0; + Standard_Integer aNbIntPntSym = anIntersectSym.IsDone() ? anIntersectSym.NbPoints() : 0; + Standard_Integer iPnt, aNbPnt = std::max(aNbIntPnt, aNbIntPntSym); + + if (aNbPnt == 0) + { + theNoIntersection = Standard_True; + return; + } + Standard_Real aParam; + for (iPnt = 1; iPnt <= aNbPnt; iPnt++) + { + if (iPnt <= aNbIntPnt) + { + const IntAna2d_IntPoint& aIntPnt = anIntersect.Point(iPnt); + aParam = aIntPnt.ParamOnFirst(); + theVmin = std::min(theVmin, aParam); + theVmax = std::max(theVmax, aParam); + } + if (iPnt <= aNbIntPntSym) + { + const IntAna2d_IntPoint& aIntPnt = anIntersectSym.Point(iPnt); + aParam = aIntPnt.ParamOnFirst(); + theVmin = std::min(theVmin, aParam); + theVmax = std::max(theVmax, aParam); + } + } +} + +//! Estimate limits for infinite surfaces (generic fallback). +inline void EstLimForInfSurf(Standard_Real& U1new, + Standard_Real& U2new, + Standard_Real& V1new, + Standard_Real& V2new) +{ + U1new = std::max(U1new, -1.e10); + U2new = std::min(U2new, 1.e10); + V1new = std::max(V1new, -1.e10); + V2new = std::min(V2new, 1.e10); +} + +//! Estimate limits for infinite extrusion surfaces. +//! @tparam SurfaceType The surface type +//! @tparam SurfaceTool The surface tool class +template +void EstLimForInfExtr(const gp_Lin& Line, + const SurfaceType& surface, + const Standard_Boolean IsOffSurf, + const Standard_Integer nbsu, + const Standard_Boolean U1inf, + const Standard_Boolean U2inf, + const Standard_Boolean V1inf, + const Standard_Boolean V2inf, + Standard_Real& U1new, + Standard_Real& U2new, + Standard_Real& V1new, + Standard_Real& V2new, + Standard_Boolean& NoIntersection) +{ + NoIntersection = Standard_False; + + Handle(Adaptor3d_Surface) aBasSurf; + + if (IsOffSurf) + aBasSurf = SurfaceTool::BasisSurface(surface); + + gp_Dir aDirOfExt; + + if (IsOffSurf) + aDirOfExt = aBasSurf->Direction(); + else + aDirOfExt = SurfaceTool::Direction(surface); + + Standard_Real tolang = THE_TOLERANCE_ANGULAIRE; + + if (aDirOfExt.IsParallel(Line.Direction(), tolang)) + { + NoIntersection = Standard_True; + return; + } + + if ((V1inf || V2inf) && !(U1inf || U2inf)) + { + Standard_Real vmin = RealLast(), vmax = -vmin; + gp_Lin aL; + Standard_Real step = (U2new - U1new) / nbsu; + Standard_Real u = U1new, v; + gp_Pnt aP; + Extrema_POnCurv aP1, aP2; + Standard_Integer i; + + for (i = 0; i <= nbsu; i++) + { + SurfaceTool::D0(surface, u, 0., aP); + aL.SetLocation(aP); + aL.SetDirection(aDirOfExt); + + Extrema_ExtElC aExtr(aL, Line, tolang); + + if (!aExtr.IsDone()) + return; + + if (aExtr.IsParallel()) + { + NoIntersection = Standard_True; + return; + } + + aExtr.Points(1, aP1, aP2); + v = aP1.Parameter(); + vmin = std::min(vmin, v); + vmax = std::max(vmax, v); + + u += step; + } + + vmin = vmin - std::abs(vmin) - 10.; + vmax = vmax + std::abs(vmax) + 10.; + + V1new = std::max(V1new, vmin); + V2new = std::min(V2new, vmax); + } + else if (U1inf || U2inf) + { + Standard_Real umin = RealLast(), umax = -umin; + Standard_Real u0 = std::min(std::max(0., U1new), U2new); + Standard_Real v0 = std::min(std::max(0., V1new), V2new); + gp_Pnt aP; + SurfaceTool::D0(surface, u0, v0, aP); + gp_Pln aRefPln(aP, aDirOfExt); + + Handle(Adaptor3d_Curve) aBasCurv; + + if (IsOffSurf) + aBasCurv = aBasSurf->BasisCurve(); + else + aBasCurv = SurfaceTool::BasisCurve(surface); + + ProjLib_Plane Projector(aRefPln); + + Projector.Project(Line); + + if (!Projector.IsDone()) + return; + + gp_Lin2d Line2d = Projector.Line(); + + GeomAbs_CurveType aCurvTyp = aBasCurv->GetType(); + + if (aCurvTyp == GeomAbs_Line) + { + Projector.Project(aBasCurv->Line()); + + if (!Projector.IsDone()) + return; + + gp_Lin2d aL2d = Projector.Line(); + + IntAna2d_AnaIntersection anInter(Line2d, aL2d); + + if (!anInter.IsDone()) + return; + + if (anInter.IsEmpty() || anInter.IdenticalElements() || anInter.ParallelElements()) + { + NoIntersection = Standard_True; + return; + } + + const IntAna2d_IntPoint& anIntPnt = anInter.Point(1); + umin = umax = anIntPnt.ParamOnSecond(); + } + else if (aCurvTyp == GeomAbs_Parabola || aCurvTyp == GeomAbs_Hyperbola) + { + IntAna2d_Conic aCon(Line2d); + IntAna2d_AnaIntersection anInter; + + if (aCurvTyp == GeomAbs_Parabola) + { + Projector.Project(aBasCurv->Parabola()); + if (!Projector.IsDone()) + return; + + const gp_Parab2d& aP2d = Projector.Parabola(); + + anInter.Perform(aP2d, aCon); + } + else + { + Projector.Project(aBasCurv->Hyperbola()); + if (!Projector.IsDone()) + return; + + const gp_Hypr2d& aH2d = Projector.Hyperbola(); + anInter.Perform(aH2d, aCon); + } + + if (!anInter.IsDone()) + return; + + if (anInter.IsEmpty()) + { + NoIntersection = Standard_True; + return; + } + + Standard_Integer i, nbint = anInter.NbPoints(); + for (i = 1; i <= nbint; i++) + { + const IntAna2d_IntPoint& anIntPnt = anInter.Point(i); + + umin = std::min(anIntPnt.ParamOnFirst(), umin); + umax = std::max(anIntPnt.ParamOnFirst(), umax); + } + } + else + { + return; + } + + umin = umin - std::abs(umin) - 10; + umax = umax + std::abs(umax) + 10; + + U1new = std::max(U1new, umin); + U2new = std::min(U2new, umax); + + if (V1inf || V2inf) + { + EstLimForInfExtr(Line, + surface, + IsOffSurf, + nbsu, + Standard_False, + Standard_False, + V1inf, + V2inf, + U1new, + U2new, + V1new, + V2new, + NoIntersection); + } + } +} + +//! Estimate V1 and V2 for infinite surfaces of revolution. +//! @tparam SurfaceType The surface type +//! @tparam SurfaceTool The surface tool class +template +void EstLimForInfRevl(const gp_Lin& Line, + const SurfaceType& surface, + const Standard_Boolean U1inf, + const Standard_Boolean U2inf, + const Standard_Boolean V1inf, + const Standard_Boolean V2inf, + Standard_Real& U1new, + Standard_Real& U2new, + Standard_Real& V1new, + Standard_Real& V2new, + Standard_Boolean& NoIntersection) +{ + NoIntersection = Standard_False; + + if (U1inf || U2inf) + { + if (U1inf) + U1new = std::max(0., U1new); + else + U2new = std::min(2 * M_PI, U2new); + if (!V1inf && !V2inf) + return; + } + + Handle(Adaptor3d_Curve) aBasisCurve = SurfaceTool::BasisCurve(surface); + gp_Ax1 aRevAx = SurfaceTool::AxeOfRevolution(surface); + gp_Vec aXVec = aRevAx.Direction(); + constexpr Standard_Real aTolAng = Precision::Angular(); + + // make plane to project a basis curve + gp_Pnt O = aRevAx.Location(); + Standard_Real aU = 0.; + gp_Pnt P = aBasisCurve->Value(aU); + while (O.SquareDistance(P) <= Precision::PConfusion() || aXVec.IsParallel(gp_Vec(O, P), aTolAng)) + { + aU += 1.; + P = aBasisCurve->Value(aU); + if (aU > 3) + // basis curve is a line coinciding with aXVec, P is any not on aXVec + P = gp_Pnt(aU, aU + 1, aU + 2); + } + gp_Vec aNVec = aXVec ^ gp_Vec(O, P); + gp_Pln aPln(gp_Ax3(O, aNVec, aXVec)); + + // project basic curve + ProjLib_Plane aBasCurvProj(aPln); + switch (aBasisCurve->GetType()) + { + case GeomAbs_Line: + aBasCurvProj.Project(aBasisCurve->Line()); + break; + case GeomAbs_Hyperbola: + aBasCurvProj.Project(aBasisCurve->Hyperbola()); + break; + case GeomAbs_Parabola: + aBasCurvProj.Project(aBasisCurve->Parabola()); + break; + default: + return; // not infinite curve + } + if (!aBasCurvProj.IsDone()) + { + return; + } + // make plane to project Line + if (aXVec.IsParallel(Line.Direction(), aTolAng)) + { + P = Line.Location(); + while (O.SquareDistance(P) <= Precision::PConfusion()) + { + aU += 1.; + P = gp_Pnt(aU, aU + 1, aU + 2); // any not on aXVec + } + aNVec = aXVec ^ gp_Vec(O, P); + } + else + aNVec = aXVec.Crossed(Line.Direction()); + + aPln = gp_Pln(gp_Ax3(O, aNVec, aXVec)); + + // make a second plane perpendicular to the first one, rotated around aXVec + gp_Pln aPlnPrp = aPln.Rotated(gp_Ax1(O, aXVec), M_PI / 2.); + + // project Line and its X-axe symmetric one to plane and intersect + // resulting curve with projection of Basic Curve + Standard_Real aVmin = RealLast(), aVmax = -aVmin; + Standard_Boolean aNoInt1 = Standard_False, aNoInt2 = Standard_False; + ProjectIntersectAndEstLim(Line, aPln, aBasCurvProj, aVmin, aVmax, aNoInt1); + ProjectIntersectAndEstLim(Line, aPlnPrp, aBasCurvProj, aVmin, aVmax, aNoInt2); + + if (aNoInt1 && aNoInt2) + { + NoIntersection = Standard_True; + return; + } + + aVmin = aVmin - std::abs(aVmin) - 10; + aVmax = aVmax + std::abs(aVmax) + 10; + + if (V1inf) + V1new = aVmin; + if (V2inf) + V2new = aVmax; +} + +//! Estimate limits for infinite offset surfaces. +//! @tparam SurfaceType The surface type +//! @tparam SurfaceTool The surface tool class +template +void EstLimForInfOffs(const gp_Lin& Line, + const SurfaceType& surface, + const Standard_Integer nbsu, + const Standard_Boolean U1inf, + const Standard_Boolean U2inf, + const Standard_Boolean V1inf, + const Standard_Boolean V2inf, + Standard_Real& U1new, + Standard_Real& U2new, + Standard_Real& V1new, + Standard_Real& V2new, + Standard_Boolean& NoIntersection) +{ + NoIntersection = Standard_False; + + const Handle(Adaptor3d_Surface)& aBasSurf = SurfaceTool::BasisSurface(surface); + Standard_Real anOffVal = SurfaceTool::OffsetValue(surface); + + GeomAbs_SurfaceType aTypeOfBasSurf = aBasSurf->GetType(); + + // case for plane, cylinder and cone - make equivalent surface; + if (aTypeOfBasSurf == GeomAbs_Plane) + { + gp_Pln aPln = aBasSurf->Plane(); + gp_Vec aT = aPln.Position().XDirection() ^ aPln.Position().YDirection(); + aT *= anOffVal; + aPln.Translate(aT); + IntAna_IntConicQuad LinPlane(Line, aPln, THE_TOLERANCE_ANGULAIRE); + + if (!LinPlane.IsDone()) + return; + + if (LinPlane.IsParallel() || LinPlane.IsInQuadric()) + { + NoIntersection = Standard_True; + return; + } + + Standard_Real u, v; + ElSLib::Parameters(aPln, LinPlane.Point(1), u, v); + U1new = std::max(U1new, u - 10.); + U2new = std::min(U2new, u + 10.); + V1new = std::max(V1new, v - 10.); + V2new = std::min(V2new, v + 10.); + } + else if (aTypeOfBasSurf == GeomAbs_Cylinder) + { + gp_Cylinder aCyl = aBasSurf->Cylinder(); + + Standard_Real aR = aCyl.Radius(); + gp_Ax3 anA = aCyl.Position(); + + if (anA.Direct()) + aR += anOffVal; + else + aR -= anOffVal; + + if (aR >= THE_TOLTANGENCY) + { + aCyl.SetRadius(aR); + } + else if (aR <= -THE_TOLTANGENCY) + { + anA.Rotate(gp_Ax1(anA.Location(), anA.Direction()), M_PI); + aCyl.SetPosition(anA); + aCyl.SetRadius(-aR); + } + else + { + NoIntersection = Standard_True; + return; + } + + IntAna_IntConicQuad LinCylinder(Line, aCyl); + + if (!LinCylinder.IsDone()) + return; + + if (LinCylinder.IsParallel() || LinCylinder.IsInQuadric()) + { + NoIntersection = Standard_True; + return; + } + + Standard_Integer i, nbp = LinCylinder.NbPoints(); + Standard_Real vmin = RealLast(), vmax = -vmin, u, v; + + for (i = 1; i <= nbp; i++) + { + ElSLib::Parameters(aCyl, LinCylinder.Point(i), u, v); + vmin = std::min(vmin, v); + vmax = std::max(vmax, v); + } + + V1new = std::max(V1new, vmin - std::abs(vmin) - 10.); + V2new = std::min(V2new, vmax + std::abs(vmax) + 10.); + } + else if (aTypeOfBasSurf == GeomAbs_Cone) + { + gp_Cone aCon = aBasSurf->Cone(); + Standard_Real anAng = aCon.SemiAngle(); + Standard_Real aR = aCon.RefRadius() + anOffVal * std::cos(anAng); + gp_Ax3 anA = aCon.Position(); + if (aR >= 0.) + { + gp_Vec aZ(anA.Direction()); + aZ *= -anOffVal * std::sin(anAng); + anA.Translate(aZ); + aCon.SetPosition(anA); + aCon.SetRadius(aR); + aCon.SetSemiAngle(anAng); + } + else + { + return; + } + + IntAna_IntConicQuad LinCone(Line, aCon); + + if (!LinCone.IsDone()) + return; + + if (LinCone.IsParallel() || LinCone.IsInQuadric()) + { + NoIntersection = Standard_True; + return; + } + + Standard_Integer i, nbp = LinCone.NbPoints(); + Standard_Real vmin = RealLast(), vmax = -vmin, u, v; + + for (i = 1; i <= nbp; i++) + { + ElSLib::Parameters(aCon, LinCone.Point(i), u, v); + vmin = std::min(vmin, v); + vmax = std::max(vmax, v); + } + + V1new = std::max(V1new, vmin - std::abs(vmin) - 10.); + V2new = std::min(V2new, vmax + std::abs(vmax) + 10.); + } + else if (aTypeOfBasSurf == GeomAbs_SurfaceOfExtrusion) + { + Standard_Real anU1 = U1new, anU2 = U2new; + + EstLimForInfExtr(Line, + surface, + Standard_True, + nbsu, + U1inf, + U2inf, + V1inf, + V2inf, + U1new, + U2new, + V1new, + V2new, + NoIntersection); + + if (NoIntersection) + return; + + if (U1inf || U2inf) + { + GeomAbs_CurveType aBasCurvType = aBasSurf->BasisCurve()->GetType(); + if (aBasCurvType == GeomAbs_Line) + { + U1new = std::max(anU1, -1.e10); + U2new = std::min(anU2, 1.e10); + } + else if (aBasCurvType == GeomAbs_Parabola) + { + gp_Parab aPrb = aBasSurf->BasisCurve()->Parabola(); + Standard_Real aF = aPrb.Focal(); + Standard_Real dU = 2.e5 * std::sqrt(aF); + U1new = std::max(anU1, -dU); + U2new = std::min(anU2, dU); + } + else if (aBasCurvType == GeomAbs_Hyperbola) + { + U1new = std::max(anU1, -30.); + U2new = std::min(anU2, 30.); + } + else + { + U1new = std::max(anU1, -1.e10); + U2new = std::min(anU2, 1.e10); + } + } + } + else if (aTypeOfBasSurf == GeomAbs_SurfaceOfRevolution) + { + GeomAbs_CurveType aBasCurvType = aBasSurf->BasisCurve()->GetType(); + if (aBasCurvType == GeomAbs_Line) + { + V1new = std::max(V1new, -1.e10); + V2new = std::min(V2new, 1.e10); + } + else if (aBasCurvType == GeomAbs_Parabola) + { + gp_Parab aPrb = aBasSurf->BasisCurve()->Parabola(); + Standard_Real aF = aPrb.Focal(); + Standard_Real dV = 2.e5 * std::sqrt(aF); + V1new = std::max(V1new, -dV); + V2new = std::min(V2new, dV); + } + else if (aBasCurvType == GeomAbs_Hyperbola) + { + V1new = std::max(V1new, -30.); + V2new = std::min(V2new, 30.); + } + else + { + V1new = std::max(V1new, -1.e10); + V2new = std::min(V2new, 1.e10); + } + } + else + { + V1new = std::max(V1new, -1.e10); + V2new = std::min(V2new, 1.e10); + } +} + +//! Convert section point to surface and curve parameters. +//! @tparam PolyhedronType The polyhedron type +//! @tparam PolygonType The polygon type +template +void SectionPointToParameters(const Intf_SectionPoint& Sp, + const PolyhedronType& Polyhedron, + const PolygonType& Polygon, + Standard_Real& U, + Standard_Real& V, + Standard_Real& W) +{ + Intf_PIType typ; + Standard_Integer Adr1, Adr2; + Standard_Real Param, u, v; + gp_Pnt P(Sp.Pnt()); + + Standard_Integer Pt1, Pt2, Pt3; + Standard_Real u1 = 0., v1 = 0., param; + //---------------------------------------------------------------------- + //-- Approximate parameter calculation on surface -- + //---------------------------------------------------------------------- + + Sp.InfoSecond(typ, Adr1, Adr2, Param); + switch (typ) + { + case Intf_VERTEX: //-- Adr1 is the vertex number + { + Polyhedron.Parameters(Adr1, u1, v1); + break; + } + case Intf_EDGE: { + Polyhedron.Parameters(Adr1, u1, v1); + Polyhedron.Parameters(Adr2, u, v); + u1 += Param * (u - u1); + v1 += Param * (v - v1); + break; + } + case Intf_FACE: { + Standard_Real ua, va, ub, vb, uc, vc, ca, cb, cc, cabc; + Polyhedron.Triangle(Adr1, Pt1, Pt2, Pt3); + gp_Pnt PA(Polyhedron.Point(Pt1)); + gp_Pnt PB(Polyhedron.Point(Pt2)); + gp_Pnt PC(Polyhedron.Point(Pt3)); + Polyhedron.Parameters(Pt1, ua, va); + Polyhedron.Parameters(Pt2, ub, vb); + Polyhedron.Parameters(Pt3, uc, vc); + gp_Vec Normale(gp_Vec(PA, PB).Crossed(gp_Vec(PA, PC))); + cc = (gp_Vec(PA, PB).Crossed(gp_Vec(PA, P))).Dot(Normale); + ca = (gp_Vec(PB, PC).Crossed(gp_Vec(PB, P))).Dot(Normale); + cb = (gp_Vec(PC, PA).Crossed(gp_Vec(PC, P))).Dot(Normale); + cabc = ca + cb + cc; + + ca /= cabc; + cb /= cabc; + cc /= cabc; + + u1 = ca * ua + cb * ub + cc * uc; + v1 = ca * va + cb * vb + cc * vc; + break; + } + default: { + break; + } + } + //---------------------------------------------------------------------- + //-- Approximate point calculation on Curve -- + //---------------------------------------------------------------------- + Standard_Integer SegIndex; + + Sp.InfoFirst(typ, SegIndex, param); + W = Polygon.ApproxParamOnCurve(SegIndex, param); + U = u1; + V = v1; +} + +//! Compute transitions at intersection point. +//! @tparam CurveType The curve type +//! @tparam CurveTool The curve tool class +//! @tparam SurfaceType The surface type +//! @tparam SurfaceTool The surface tool class +template +void ComputeTransitions(const CurveType& curve, + const Standard_Real w, + IntCurveSurface_TransitionOnCurve& TransOnCurve, + const SurfaceType& surface, + const Standard_Real u, + const Standard_Real v) +{ + gp_Vec NSurf, D1U, D1V; + gp_Pnt Psurf; + Standard_Real CosDir; + + SurfaceTool::D1(surface, u, v, Psurf, D1U, D1V); + NSurf = D1U.Crossed(D1V); + CurveTool::D1(curve, w, Psurf, D1U); + Standard_Real Norm = NSurf.Magnitude(); + if (Norm > THE_TOLERANCE_ANGULAIRE && D1U.SquareMagnitude() > THE_TOLERANCE_ANGULAIRE) + { + D1U.Normalize(); + CosDir = NSurf.Dot(D1U); + CosDir /= Norm; + if (-CosDir > THE_TOLERANCE_ANGULAIRE) + { + //-- --Curve---> <----Surface---- + TransOnCurve = IntCurveSurface_In; + } + else if (CosDir > THE_TOLERANCE_ANGULAIRE) + { + //-- --Curve---> ----Surface--> + TransOnCurve = IntCurveSurface_Out; + } + else + { + TransOnCurve = IntCurveSurface_Tangent; + } + } + else + { + TransOnCurve = IntCurveSurface_Tangent; + } +} + +//! Compute parameters on quadric surface from a point. +//! @tparam SurfaceType The surface type +//! @tparam SurfaceTool The surface tool class +template +void ComputeParamsOnQuadric(const SurfaceType& surface, + const gp_Pnt& P, + Standard_Real& u, + Standard_Real& v) +{ + GeomAbs_SurfaceType SurfaceType_ = SurfaceTool::GetType(surface); + switch (SurfaceType_) + { + case GeomAbs_Plane: { + ElSLib::Parameters(SurfaceTool::Plane(surface), P, u, v); + break; + } + case GeomAbs_Cylinder: { + ElSLib::Parameters(SurfaceTool::Cylinder(surface), P, u, v); + break; + } + case GeomAbs_Cone: { + ElSLib::Parameters(SurfaceTool::Cone(surface), P, u, v); + break; + } + case GeomAbs_Sphere: { + ElSLib::Parameters(SurfaceTool::Sphere(surface), P, u, v); + break; + } + default: + break; + } +} + +//! Sample surface points into array and compute bounding box. +//! @tparam SurfaceType The surface type +//! @tparam SurfaceTool The surface tool class +template +void DoSurface(const SurfaceType& theSurface, + const Standard_Real theU0, + const Standard_Real theU1, + const Standard_Real theV0, + const Standard_Real theV1, + TColgp_Array2OfPnt& thePntsOnSurface, + Bnd_Box& theBoxSurface, + Standard_Real& theGap) +{ + Standard_Integer iU = 0, iV = 0; + Standard_Real U = 0., V = 0.; + Standard_Real dU = (theU1 - theU0) / 50., dV = (theV1 - theV0) / 50.; + gp_Pnt aPnt; + + for (iU = 0; iU < 50; iU++) + { + if (iU == 0) + U = theU0; + else if (iU == 49) + U = theU1; + else + U = theU0 + dU * ((Standard_Real)iU); + + for (iV = 0; iV < 50; iV++) + { + if (iV == 0) + V = theV0; + else if (iV == 49) + V = theV1; + else + V = theV0 + dV * ((Standard_Real)iV); + + SurfaceTool::D0(theSurface, U, V, aPnt); + theBoxSurface.Add(aPnt); + thePntsOnSurface.SetValue(iU + 1, iV + 1, aPnt); + } + } + Standard_Real Ures = SurfaceTool::UResolution(theSurface, dU); + Standard_Real Vres = SurfaceTool::VResolution(theSurface, dV); + theGap = std::max(Ures, Vres); +} + +//! Compute new bounds for surface based on intersection with bounding box corners. +//! @tparam SurfaceType The surface type +//! @tparam SurfaceTool The surface tool class +template +void DoNewBounds(const SurfaceType& theSurface, + const Standard_Real theU0, + const Standard_Real theU1, + const Standard_Real theV0, + const Standard_Real theV1, + const TColgp_Array2OfPnt& thePntsOnSurface, + const TColStd_Array1OfReal& theX, + const TColStd_Array1OfReal& theY, + const TColStd_Array1OfReal& theZ, + TColStd_Array1OfReal& theBounds) +{ + theBounds.SetValue(1, theU0); + theBounds.SetValue(2, theU1); + theBounds.SetValue(3, theV0); + theBounds.SetValue(4, theV1); + + Standard_Boolean isUClosed = + (SurfaceTool::IsUClosed(theSurface) || SurfaceTool::IsUPeriodic(theSurface)); + Standard_Boolean isVClosed = + (SurfaceTool::IsVClosed(theSurface) || SurfaceTool::IsVPeriodic(theSurface)); + Standard_Boolean checkU = (isUClosed) ? Standard_False : Standard_True; + Standard_Boolean checkV = (isVClosed) ? Standard_False : Standard_True; + + Standard_Integer i = 0, j = 0, k = 0, iU = 0, iV = 0; + Standard_Integer iUmin = 50, iVmin = 50, iUmax = 1, iVmax = 1; + + for (i = 1; i <= 2; i++) + { + for (j = 1; j <= 2; j++) + { + for (k = 1; k <= 2; k++) + { + gp_Pnt aPoint(theX(i), theY(j), theZ(k)); + Standard_Real DistMin = 1.e+100; + Standard_Integer diU = 0, diV = 0; + for (iU = 1; iU <= 50; iU++) + { + for (iV = 1; iV <= 50; iV++) + { + const gp_Pnt aP = thePntsOnSurface.Value(iU, iV); + Standard_Real dist = aP.SquareDistance(aPoint); + if (dist < DistMin) + { + DistMin = dist; + diU = iU; + diV = iV; + } + } + } + if (diU > 0 && diU < iUmin) + iUmin = diU; + if (diU > 0 && diU > iUmax) + iUmax = diU; + if (diV > 0 && diV < iVmin) + iVmin = diV; + if (diV > 0 && diV > iVmax) + iVmax = diV; + } + } + } + + Standard_Real dU = (theU1 - theU0) / 50., dV = (theV1 - theV0) / 50.; + + Standard_Real USmin = theU0 + dU * ((Standard_Real)(iUmin - 1)); + Standard_Real USmax = theU0 + dU * ((Standard_Real)(iUmax - 1)); + Standard_Real VSmin = theV0 + dV * ((Standard_Real)(iVmin - 1)); + Standard_Real VSmax = theV0 + dV * ((Standard_Real)(iVmax - 1)); + + if (USmin > USmax) + { + Standard_Real tmp = USmax; + USmax = USmin; + USmin = tmp; + } + if (VSmin > VSmax) + { + Standard_Real tmp = VSmax; + VSmax = VSmin; + VSmin = tmp; + } + + USmin -= 1.5 * dU; + if (USmin < theU0) + USmin = theU0; + USmax += 1.5 * dU; + if (USmax > theU1) + USmax = theU1; + VSmin -= 1.5 * dV; + if (VSmin < theV0) + VSmin = theV0; + VSmax += 1.5 * dV; + if (VSmax > theV1) + VSmax = theV1; + + if (checkU) + { + theBounds.SetValue(1, USmin); + theBounds.SetValue(2, USmax); + } + if (checkV) + { + theBounds.SetValue(3, VSmin); + theBounds.SetValue(4, VSmax); + } +} + +//! Compute intersection point with parameter validation and transition computation. +//! Returns true if the point is valid and should be appended. +//! @tparam CurveType The curve type +//! @tparam CurveTool The curve tool class +//! @tparam SurfaceType The surface type +//! @tparam SurfaceTool The surface tool class +//! @param[out] thePoint The computed intersection point (valid only if returns true) +template +bool ComputeAppendPoint(const CurveType& theCurve, + const Standard_Real theLw, + const SurfaceType& theSurface, + const Standard_Real theSu, + const Standard_Real theSv, + IntCurveSurface_IntersectionPoint& thePoint) +{ + Standard_Real W0 = CurveTool::FirstParameter(theCurve); + Standard_Real W1 = CurveTool::LastParameter(theCurve); + Standard_Real U0 = SurfaceTool::FirstUParameter(theSurface); + Standard_Real U1 = SurfaceTool::LastUParameter(theSurface); + Standard_Real V0 = SurfaceTool::FirstVParameter(theSurface); + Standard_Real V1 = SurfaceTool::LastVParameter(theSurface); + + Standard_Real w = theLw, u = theSu, v = theSv; + + GeomAbs_CurveType aCType = CurveTool::GetType(theCurve); + + if (CurveTool::IsPeriodic(theCurve) || aCType == GeomAbs_Circle || aCType == GeomAbs_Ellipse) + { + w = ElCLib::InPeriod(w, W0, W0 + CurveTool::Period(theCurve)); + } + + if ((W0 - w) >= THE_TOLTANGENCY || (w - W1) >= THE_TOLTANGENCY) + return false; + + GeomAbs_SurfaceType aSType = SurfaceTool::GetType(theSurface); + if (SurfaceTool::IsUPeriodic(theSurface) || aSType == GeomAbs_Cylinder || aSType == GeomAbs_Cone + || aSType == GeomAbs_Sphere) + { + u = ElCLib::InPeriod(u, U0, U0 + SurfaceTool::UPeriod(theSurface)); + } + + if (SurfaceTool::IsVPeriodic(theSurface)) + { + v = ElCLib::InPeriod(v, V0, V0 + SurfaceTool::VPeriod(theSurface)); + } + + if ((U0 - u) >= THE_TOLTANGENCY || (u - U1) >= THE_TOLTANGENCY) + return false; + if ((V0 - v) >= THE_TOLTANGENCY || (v - V1) >= THE_TOLTANGENCY) + return false; + + IntCurveSurface_TransitionOnCurve TransOnCurve; + ComputeTransitions(theCurve, + w, + TransOnCurve, + theSurface, + u, + v); + gp_Pnt P(CurveTool::Value(theCurve, w)); + thePoint = IntCurveSurface_IntersectionPoint(P, u, v, w, TransOnCurve); + return true; +} + +//! Process analytical intersection of conic with quadric. +//! Returns status and computes intersection points. +//! @tparam CurveType The curve type +//! @tparam CurveTool The curve tool class +//! @tparam SurfaceType The surface type +//! @tparam SurfaceTool The surface tool class +//! @param[out] theIsParallel Set to true if curve is parallel or in quadric +//! @param[out] thePoints Vector of computed intersection points +//! @return true if the operation was done successfully +template +bool ProcessIntAna(const CurveType& theCurve, + const SurfaceType& theSurface, + const IntAna_IntConicQuad& theIntAna, + Standard_Boolean& theIsParallel, + NCollection_Vector& thePoints) +{ + theIsParallel = Standard_False; + thePoints.Clear(); + + if (!theIntAna.IsDone()) + { + return false; + } + + if (theIntAna.IsInQuadric() || theIntAna.IsParallel()) + { + theIsParallel = Standard_True; + return true; + } + + Standard_Integer nbp = theIntAna.NbPoints(); + Standard_Real u, v, w; + for (Standard_Integer i = 1; i <= nbp; i++) + { + gp_Pnt P(theIntAna.Point(i)); + w = theIntAna.ParamOnConic(i); + ComputeParamsOnQuadric(theSurface, P, u, v); + + IntCurveSurface_IntersectionPoint aPoint; + if (ComputeAppendPoint(theCurve, + w, + theSurface, + u, + v, + aPoint)) + { + thePoints.Append(aPoint); + } + } + return true; +} + +//! Perform intersection between curve and quadric surface. +//! Uses exact quadric-curve intersection algorithm. +//! @tparam QuadCurvExactType The exact quadric-curve intersection type +//! @tparam CurveType The curve type +//! @tparam CurveTool The curve tool class +//! @tparam SurfaceType The surface type +//! @tparam SurfaceTool The surface tool class +//! @param[out] thePoints Vector of computed intersection points +template +void PerformCurveQuadric(const CurveType& theCurve, + const SurfaceType& theSurface, + NCollection_Vector& thePoints) +{ + thePoints.Clear(); + + QuadCurvExactType QuadCurv(theSurface, theCurve); + if (QuadCurv.IsDone()) + { + Standard_Integer NbRoots = QuadCurv.NbRoots(); + Standard_Real u, v, w; + for (Standard_Integer i = 1; i <= NbRoots; i++) + { + w = QuadCurv.Root(i); + ComputeParamsOnQuadric(theSurface, + CurveTool::Value(theCurve, w), + u, + v); + + IntCurveSurface_IntersectionPoint aPoint; + if (ComputeAppendPoint(theCurve, + w, + theSurface, + u, + v, + aPoint)) + { + thePoints.Append(aPoint); + } + } + } +} + +//! Process line-torus intersection. +//! @tparam CurveType The curve type +//! @tparam CurveTool The curve tool class +//! @tparam SurfaceType The surface type +//! @tparam SurfaceTool The surface tool class +//! @return true if intersection was processed successfully, false if fallback is needed +template +bool ProcessLinTorus(const gp_Lin& theLine, + const CurveType& theCurve, + const SurfaceType& theSurface, + NCollection_Vector& thePoints) +{ + thePoints.Clear(); + + IntAna_IntLinTorus intlintorus(theLine, SurfaceTool::Torus(theSurface)); + if (!intlintorus.IsDone()) + { + return false; + } + + Standard_Integer nbp = intlintorus.NbPoints(); + Standard_Real fi, theta, w; + for (Standard_Integer i = 1; i <= nbp; i++) + { + w = intlintorus.ParamOnLine(i); + intlintorus.ParamOnTorus(i, fi, theta); + + IntCurveSurface_IntersectionPoint aPoint; + if (ComputeAppendPoint(theCurve, + w, + theSurface, + fi, + theta, + aPoint)) + { + thePoints.Append(aPoint); + } + } + return true; +} + +//! Structure to hold sorted intersection start points. +struct SortedStartPoints +{ + NCollection_Vector TabU; + NCollection_Vector TabV; + NCollection_Vector TabW; + + void Clear() + { + TabU.Clear(); + TabV.Clear(); + TabW.Clear(); + } + + Standard_Integer Size() const { return TabU.Size(); } + + void Append(Standard_Real theU, Standard_Real theV, Standard_Real theW) + { + TabU.Append(theU); + TabV.Append(theV); + TabW.Append(theW); + } +}; + +//! Collect section points from interference and convert to parameters. +//! @tparam InterferenceType The interference type +//! @tparam PolyhedronType The polyhedron type +//! @tparam PolygonType The polygon type +template +void CollectInterferencePoints(const InterferenceType& theInterference, + const PolyhedronType& thePolyhedron, + const PolygonType& thePolygon, + SortedStartPoints& thePoints) +{ + thePoints.Clear(); + + Standard_Integer NbSectionPoints = theInterference.NbSectionPoints(); + Standard_Integer NbTangentZones = theInterference.NbTangentZones(); + + Standard_Real u, v, w; + + for (Standard_Integer i = 1; i <= NbSectionPoints; i++) + { + const Intf_SectionPoint& SP = theInterference.PntValue(i); + SectionPointToParameters(SP, thePolyhedron, thePolygon, u, v, w); + thePoints.Append(u, v, w); + } + + for (Standard_Integer i = 1; i <= NbTangentZones; i++) + { + const Intf_TangentZone& TZ = theInterference.ZoneValue(i); + Standard_Integer nbpnts = TZ.NumberOfPoints(); + for (Standard_Integer j = 1; j <= nbpnts; j++) + { + const Intf_SectionPoint& SP = TZ.GetPoint(j); + SectionPointToParameters(SP, thePolyhedron, thePolygon, u, v, w); + thePoints.Append(u, v, w); + } + } +} + +//! Sort start points by W, then U, then V parameters. +//! Uses bubble sort to eliminate duplicates. +inline void SortStartPoints(SortedStartPoints& thePoints) +{ + Standard_Integer NbStartPoints = thePoints.Size(); + if (NbStartPoints == 0) + return; + + Standard_Real ptol = 10 * Precision::PConfusion(); + + // Sort by W + Standard_Boolean Triok; + do + { + Triok = Standard_True; + for (Standard_Integer i = 1; i < NbStartPoints; i++) + { + Standard_Integer im1 = i - 1; + if (thePoints.TabW(i) < thePoints.TabW(im1)) + { + std::swap(thePoints.TabW.ChangeValue(i), thePoints.TabW.ChangeValue(im1)); + std::swap(thePoints.TabU.ChangeValue(i), thePoints.TabU.ChangeValue(im1)); + std::swap(thePoints.TabV.ChangeValue(i), thePoints.TabV.ChangeValue(im1)); + Triok = Standard_False; + } + } + } while (!Triok); + + // Sort by U for same W + do + { + Triok = Standard_True; + for (Standard_Integer i = 1; i < NbStartPoints; i++) + { + Standard_Integer im1 = i - 1; + if ((thePoints.TabW(i) - thePoints.TabW(im1)) < ptol) + { + thePoints.TabW.ChangeValue(i) = thePoints.TabW(im1); + if (thePoints.TabU(i) < thePoints.TabU(im1)) + { + std::swap(thePoints.TabU.ChangeValue(i), thePoints.TabU.ChangeValue(im1)); + std::swap(thePoints.TabV.ChangeValue(i), thePoints.TabV.ChangeValue(im1)); + Triok = Standard_False; + } + } + } + } while (!Triok); + + // Sort by V for same W and U + do + { + Triok = Standard_True; + for (Standard_Integer i = 1; i < NbStartPoints; i++) + { + Standard_Integer im1 = i - 1; + if (((thePoints.TabW(i) - thePoints.TabW(im1)) < ptol) + && ((thePoints.TabU(i) - thePoints.TabU(im1)) < ptol)) + { + thePoints.TabU.ChangeValue(i) = thePoints.TabU(im1); + if (thePoints.TabV(i) < thePoints.TabV(im1)) + { + std::swap(thePoints.TabV.ChangeValue(i), thePoints.TabV.ChangeValue(im1)); + Triok = Standard_False; + } + } + } + } while (!Triok); +} + +//! Process sorted start points through exact intersection. +//! @tparam ExactInterType The exact intersection type +//! @tparam CurveType The curve type +//! @tparam CurveTool The curve tool class +//! @tparam SurfaceType The surface type +//! @tparam SurfaceTool The surface tool class +template +void ProcessSortedPoints(ExactInterType& theExactInter, + math_FunctionSetRoot& theRsnld, + const SortedStartPoints& thePoints, + const Standard_Real theU0, + const Standard_Real theU1, + const Standard_Real theV0, + const Standard_Real theV1, + const Standard_Real theWinf, + const Standard_Real theWsup, + const CurveType& theCurve, + const SurfaceType& theSurface, + NCollection_Vector& theResult) +{ + theResult.Clear(); + + Standard_Integer NbStartPoints = thePoints.Size(); + if (NbStartPoints == 0) + return; + + Standard_Real ptol = 10 * Precision::PConfusion(); + Standard_Real su = 0, sv = 0, sw = 0; + + for (Standard_Integer i = 0; i < NbStartPoints; i++) + { + Standard_Real u = thePoints.TabU(i); + Standard_Real v = thePoints.TabV(i); + Standard_Real w = thePoints.TabW(i); + + if (i == 0) + { + su = u - 1; + } + + if (std::abs(u - su) > ptol || std::abs(v - sv) > ptol || std::abs(w - sw) > ptol) + { + theExactInter.Perform(u, v, w, theRsnld, theU0, theU1, theV0, theV1, theWinf, theWsup); + if (theExactInter.IsDone() && !theExactInter.IsEmpty()) + { + w = theExactInter.ParameterOnCurve(); + theExactInter.ParameterOnSurface(u, v); + + IntCurveSurface_IntersectionPoint aPoint; + if (ComputeAppendPoint(theCurve, + w, + theSurface, + u, + v, + aPoint)) + { + theResult.Append(aPoint); + } + } + } + su = thePoints.TabU(i); + sv = thePoints.TabV(i); + sw = thePoints.TabW(i); + } +} + +//! Structure to hold UV parameter bounds. +struct UVBounds +{ + Standard_Real U0; + Standard_Real U1; + Standard_Real V0; + Standard_Real V1; + + UVBounds() + : U0(0.), + U1(0.), + V0(0.), + V1(0.) + { + } + + UVBounds(Standard_Real theU0, Standard_Real theU1, Standard_Real theV0, Standard_Real theV1) + : U0(theU0), + U1(theU1), + V0(theV0), + V1(theV1) + { + } +}; + +//! Decompose surface into UV intervals based on C2 continuity. +//! @tparam SurfaceType The surface type +//! @tparam SurfaceTool The surface tool class +template +void DecomposeSurfaceIntervals(const SurfaceType& theSurface, + NCollection_Vector& theIntervals) +{ + theIntervals.Clear(); + + Standard_Integer NbUOnS = SurfaceTool::NbUIntervals(theSurface, GeomAbs_C2); + Standard_Integer NbVOnS = SurfaceTool::NbVIntervals(theSurface, GeomAbs_C2); + + if (NbUOnS > 1) + { + TColStd_Array1OfReal TabU(1, NbUOnS + 1); + SurfaceTool::UIntervals(theSurface, TabU, GeomAbs_C2); + + for (Standard_Integer iu = 1; iu <= NbUOnS; iu++) + { + Standard_Real U0 = TabU.Value(iu); + Standard_Real U1 = TabU.Value(iu + 1); + + if (NbVOnS > 1) + { + TColStd_Array1OfReal TabV(1, NbVOnS + 1); + SurfaceTool::VIntervals(theSurface, TabV, GeomAbs_C2); + for (Standard_Integer iv = 1; iv <= NbVOnS; iv++) + { + Standard_Real V0 = TabV.Value(iv); + Standard_Real V1 = TabV.Value(iv + 1); + theIntervals.Append(UVBounds(U0, U1, V0, V1)); + } + } + else + { + Standard_Real V0 = SurfaceTool::FirstVParameter(theSurface); + Standard_Real V1 = SurfaceTool::LastVParameter(theSurface); + theIntervals.Append(UVBounds(U0, U1, V0, V1)); + } + } + } + else if (NbVOnS > 1) + { + Standard_Real U0 = SurfaceTool::FirstUParameter(theSurface); + Standard_Real U1 = SurfaceTool::LastUParameter(theSurface); + + TColStd_Array1OfReal TabV(1, NbVOnS + 1); + SurfaceTool::VIntervals(theSurface, TabV, GeomAbs_C2); + + for (Standard_Integer iv = 1; iv <= NbVOnS; iv++) + { + Standard_Real V0 = TabV.Value(iv); + Standard_Real V1 = TabV.Value(iv + 1); + theIntervals.Append(UVBounds(U0, U1, V0, V1)); + } + } + else + { + Standard_Real U0 = SurfaceTool::FirstUParameter(theSurface); + Standard_Real U1 = SurfaceTool::LastUParameter(theSurface); + Standard_Real V0 = SurfaceTool::FirstVParameter(theSurface); + Standard_Real V1 = SurfaceTool::LastVParameter(theSurface); + theIntervals.Append(UVBounds(U0, U1, V0, V1)); + } +} + +//! Clamp UV parameters to prevent double overflow. +//! Protection from double type overflow in square magnitude computation. +inline void ClampUVParameters(Standard_Real& theU1, + Standard_Real& theU2, + Standard_Real& theV1, + Standard_Real& theV2) +{ + constexpr Standard_Real THE_PARAM_LIMIT = 1.0e50; + if (theU1 < -THE_PARAM_LIMIT) + theU1 = -THE_PARAM_LIMIT; + if (theU2 > THE_PARAM_LIMIT) + theU2 = THE_PARAM_LIMIT; + if (theV1 < -THE_PARAM_LIMIT) + theV1 = -THE_PARAM_LIMIT; + if (theV2 > THE_PARAM_LIMIT) + theV2 = THE_PARAM_LIMIT; +} + +} // namespace IntCurveSurface_InterUtils + +#endif // IntCurveSurface_InterUtils_HeaderFile diff --git a/src/ModelingAlgorithms/TKGeomAlgo/IntCurveSurface/IntCurveSurface_Polygon.gxx b/src/ModelingAlgorithms/TKGeomAlgo/IntCurveSurface/IntCurveSurface_Polygon.gxx deleted file mode 100644 index 5684a3dbeb..0000000000 --- a/src/ModelingAlgorithms/TKGeomAlgo/IntCurveSurface/IntCurveSurface_Polygon.gxx +++ /dev/null @@ -1,263 +0,0 @@ -// Created on: 1992-10-12 -// Created by: Laurent BUCHARD -// Copyright (c) 1992-1999 Matra Datavision -// Copyright (c) 1999-2014 OPEN CASCADE SAS -// -// This file is part of Open CASCADE Technology software library. -// -// This library is free software; you can redistribute it and/or modify it under -// the terms of the GNU Lesser General Public License version 2.1 as published -// by the Free Software Foundation, with special exception defined in the file -// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT -// distribution for complete text of the license and disclaimer of any warranty. -// -// Alternatively, this file may be used under the terms of Open CASCADE -// commercial license or contractual agreement. - -#include -#include -#include -#include -#include -#include - -//====================================================================== -//== On echantillonne sur le Domain de la Curve NbPts Points -//== a parametres constants. -//== -//== On estime la fleche maximum en prenant la distance maxi entre la -//== droite Curve.Value(X(i))-->Curve.Value(X(i+1)) -//== et le point Curve.Value(X(i+1/2)) -//====================================================================== -IntCurveSurface_Polygon::IntCurveSurface_Polygon(const TheCurve& C, const Standard_Integer tNbPts) - : ThePnts(1, (tNbPts < 5) ? 5 : tNbPts) -{ - Standard_Integer NbPts = (tNbPts < 5) ? 5 : tNbPts; - NbPntIn = NbPts; - Binf = TheCurveTool::FirstParameter(C); - Bsup = TheCurveTool::LastParameter(C); - Init(C); -} - -IntCurveSurface_Polygon::IntCurveSurface_Polygon(const TheCurve& C, - const Standard_Real U1, - const Standard_Real U2, - const Standard_Integer tNbPts) - : ThePnts(1, (tNbPts < 5) ? 5 : tNbPts), - Binf(U1), - Bsup(U2) -{ - - Standard_Integer NbPts = (tNbPts < 5) ? 5 : tNbPts; - NbPntIn = NbPts; - Init(C); -} - -//================================================================================================= - -IntCurveSurface_Polygon::IntCurveSurface_Polygon(const TheCurve& C, - const TColStd_Array1OfReal& Upars) - : ThePnts(1, Upars.Length()), - Binf(Upars(Upars.Lower())), - Bsup(Upars(Upars.Upper())) -{ - - // ddout << "IntCurveSurface_Polygon::IntCurveSurface_Polygon" << endl; - Standard_Integer NbPts = Upars.Length(); - // ddout << "NbPts :" << NbPts << endl; - NbPntIn = NbPts; - Init(C, Upars); -} - -void IntCurveSurface_Polygon::Init(const TheCurve& C) -{ - - Standard_Real u = Binf; - Standard_Real u1 = Bsup; - Standard_Real du = (u1 - u) / (Standard_Real)(NbPntIn - 1); - Standard_Integer i = 1; - gp_Pnt P; - do - { - TheCurveTool::D0(C, u, P); - TheBnd.Add(P); - ThePnts.SetValue(i, P); - u += du; - i++; - } while (i <= NbPntIn); - - //----------------------------------------------------- - //--- Calcul d un majorant de fleche approche - //--- - TheDeflection = 0.0; - - if (NbPntIn > 3) - { - - i = 1; - u = Binf; - u += du * 0.5; - - do - { - gp_Pnt Pm = TheCurveTool::Value(C, u); - gp_Pnt P1 = ThePnts.Value(i); - gp_Pnt P2 = ThePnts.Value(i + 1); - gp_Lin L(P1, gp_Dir(gp_Vec(P1, P2))); - Standard_Real t = L.Distance(Pm); - - if (t > TheDeflection) - { - TheDeflection = t; - } - u += du; - i++; - } while (i < NbPntIn); - - TheBnd.Enlarge(1.5 * TheDeflection); - } - else - { - TheBnd.Enlarge(1e-10); - } - ClosedPolygon = Standard_False; -} - -//================================================================================================= - -void IntCurveSurface_Polygon::Init(const TheCurve& C, const TColStd_Array1OfReal& Upars) -{ - - // ddout << "IntCurveSurface_Polygon::Init" << endl; - Standard_Real u = Binf; - Standard_Integer i = 1, i0 = Upars.Lower() - 1; - gp_Pnt P; - - myParams = new TColStd_HArray1OfReal(1, Upars.Length()); - do - { - // ddout << "-------------Parameter : " << i << " " << Upars(i+i0) << endl; - myParams->SetValue(i, Upars(i + i0)); - TheCurveTool::D0(C, Upars(i + i0), P); - // ddout << "P : " << P.X() << " " << P.Y() << " " << P.Z() << endl; - TheBnd.Add(P); - ThePnts.SetValue(i, P); - i++; - } while (i <= NbPntIn); - - //----------------------------------------------------- - //--- Calcul d un majorant de fleche approche - //--- - TheDeflection = 0.0; - - if (NbPntIn > 3) - { - - i = 1; - // ddout << "Deflection estimation" << endl; - do - { - u = 0.5 * (Upars(i0 + i) + Upars(i0 + i + 1)); - // ddout << "===========Parameter : " << i << " " << u << endl; - gp_Pnt Pm = TheCurveTool::Value(C, u); - // ddout << "Pm : " << Pm.X() << " " << Pm.Y() << " " << Pm.Z() << endl; - gp_Pnt P1 = ThePnts.Value(i); - // ddout << "P1 : " << P1.X() << " " << P1.Y() << " " << P1.Z() << endl; - gp_Pnt P2 = ThePnts.Value(i + 1); - // ddout << "P2 : " << P2.X() << " " << P2.Y() << " " << P2.Z() << endl; - gp_Lin L(P1, gp_Dir(gp_Vec(P1, P2))); - Standard_Real t = L.Distance(Pm); - // ddout << "Distance " << t << endl; - if (t > TheDeflection) - { - TheDeflection = t; - } - i++; - } while (i < NbPntIn); - // ddout << " TheDeflection = " << TheDeflection << endl; - TheBnd.Enlarge(1.5 * TheDeflection); - } - else - { - TheBnd.Enlarge(1e-10); - } - ClosedPolygon = Standard_False; -} - -//================================================================================================= - -Standard_Real IntCurveSurface_Polygon::ApproxParamOnCurve(const Standard_Integer TheIndex, - const Standard_Real TheParamOnLine) const -{ - // ddout << "IntCurveSurface_Polygon::ApproxParamOnCurve" << endl; - if (TheParamOnLine < 0.0 || TheParamOnLine > 1.0) - { -#ifdef OCCT_DEBUG - std::cout << " ParamOnLine = " << TheParamOnLine << " avec Index = " << TheIndex - << " dans IntCurveSurface_Polygon::ApproxParamOnCurve" << std::endl; -#endif - return (Binf + (TheParamOnLine * (Bsup - Binf)) / (Standard_Real)(NbPntIn - 1)); - } - - Standard_Integer Index = TheIndex; - Standard_Real ParamOnLine = TheParamOnLine; -#ifdef OCCT_DEBUG - if (Index > NbPntIn) - { - std::cout << "OutOfRange Polygon::ApproxParamOnCurve " << std::endl; - } -#endif - if ((Index == NbPntIn) && (ParamOnLine == 0.0)) - { - Index--; - ParamOnLine = 1.0; - } - - Standard_Real du, u; - if (myParams.IsNull()) - { - du = (Bsup - Binf) / (Standard_Real)(NbPntIn - 1); - u = Binf + du * (Standard_Real)(Index - 1); - } - else - { - du = myParams->Value(Index + 1) - myParams->Value(Index); - u = myParams->Value(Index); - } - - u += du * ParamOnLine; - return (u); -} - -//================================================================================================= - -void IntCurveSurface_Polygon::Dump(void) const -{ -#if 0 - static Standard_Integer Compteur=0; - char tamp[100]; - Compteur++; - Sprintf(tamp,"Poly%d",Compteur); - std::cout<<" @@@@@@@@@@@ F i c h i e r : "< %f \n",Binf,Bsup); - fprintf(fp,"\npol %d %d %f",Compteur,NbPntIn,TheDeflection); - gp_Pnt p1,p2; - for (Standard_Integer iObje=1; iObje<=NbSegments(); iObje++) { - p1=BeginOfSeg(iObje); - fprintf(fp,"\npnt %d %f %f",Compteur,p1.X(),p1.Y()); - } - p1=EndOfSeg(NbSegments()); - fprintf(fp,"\npnt %d %f %f",Compteur,p1.X(),p1.Y()); - fprintf(fp,"\ndispol %d\n#\n",Compteur); - fclose(fp); -#endif -} - -//====================================================================== -//====================================================================== diff --git a/src/ModelingAlgorithms/TKGeomAlgo/IntCurveSurface/IntCurveSurface_PolygonTool.lxx b/src/ModelingAlgorithms/TKGeomAlgo/IntCurveSurface/IntCurveSurface_PolygonTool.lxx deleted file mode 100644 index 9578404c6f..0000000000 --- a/src/ModelingAlgorithms/TKGeomAlgo/IntCurveSurface/IntCurveSurface_PolygonTool.lxx +++ /dev/null @@ -1,58 +0,0 @@ -// Created on: 1993-06-03 -// Created by: Laurent BUCHARD -// Copyright (c) 1993-1999 Matra Datavision -// Copyright (c) 1999-2014 OPEN CASCADE SAS -// -// This file is part of Open CASCADE Technology software library. -// -// This library is free software; you can redistribute it and/or modify it under -// the terms of the GNU Lesser General Public License version 2.1 as published -// by the Free Software Foundation, with special exception defined in the file -// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT -// distribution for complete text of the license and disclaimer of any warranty. -// -// Alternatively, this file may be used under the terms of Open CASCADE -// commercial license or contractual agreement. - -#include ThePolygon_hxx - -//================================================================= -inline const TheBoundingBox& IntCurveSurface_PolygonTool::Bounding(const ThePolygon& thePolygon) -{ - return thePolygon.Bounding(); -} - -//================================================================= -inline Standard_Real IntCurveSurface_PolygonTool::DeflectionOverEstimation( - const ThePolygon& thePolygon) -{ - return thePolygon.DeflectionOverEstimation(); -} - -//================================================================= -inline Standard_Boolean IntCurveSurface_PolygonTool::Closed(const ThePolygon& thePolygon) -{ - return thePolygon.Closed(); -} - -//================================================================= -inline Standard_Integer IntCurveSurface_PolygonTool::NbSegments(const ThePolygon& thePolygon) -{ - return thePolygon.NbSegments(); -} - -//================================================================= -inline const ThePoint& IntCurveSurface_PolygonTool::BeginOfSeg(const ThePolygon& thePolygon, - const Standard_Integer Index) -{ - return thePolygon.BeginOfSeg(Index); -} - -//================================================================= -inline const ThePoint& IntCurveSurface_PolygonTool::EndOfSeg(const ThePolygon& thePolygon, - const Standard_Integer Index) -{ - return thePolygon.EndOfSeg(Index); -} - -//================================================================= diff --git a/src/ModelingAlgorithms/TKGeomAlgo/IntCurveSurface/IntCurveSurface_PolygonUtils.pxx b/src/ModelingAlgorithms/TKGeomAlgo/IntCurveSurface/IntCurveSurface_PolygonUtils.pxx new file mode 100644 index 0000000000..188ccab0ad --- /dev/null +++ b/src/ModelingAlgorithms/TKGeomAlgo/IntCurveSurface/IntCurveSurface_PolygonUtils.pxx @@ -0,0 +1,206 @@ +// Copyright (c) 2025 OPEN CASCADE SAS +// +// This file is part of Open CASCADE Technology software library. +// +// This library is free software; you can redistribute it and/or modify it under +// the terms of the GNU Lesser General Public License version 2.1 as published +// by the Free Software Foundation, with special exception defined in the file +// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT +// distribution for complete text of the license and disclaimer of any warranty. +// +// Alternatively, this file may be used under the terms of Open CASCADE +// commercial license or contractual agreement. + +#ifndef IntCurveSurface_PolygonUtils_pxx_HeaderFile +#define IntCurveSurface_PolygonUtils_pxx_HeaderFile + +#include +#include +#include +#include +#include +#include +#include +#include + +//! Utility functions for polygon discretization of curves. +//! These template functions implement the core logic previously in IntCurveSurface_Polygon.gxx. +namespace IntCurveSurface_PolygonUtils +{ + +//! Initialize polygon with uniform parameter sampling. +//! Samples theNbPntIn points along the curve from theBinf to theBsup with equal parameter spacing. +//! Computes the bounding box and estimates the maximum deflection. +//! @tparam CurveType Type of curve (e.g., Handle(Adaptor3d_Curve) or gp_Lin) +//! @tparam CurveTool Tool class providing curve operations (D0, Value, FirstParameter, etc.) +//! @param[in] theCurve The curve to discretize +//! @param[in] theBinf First parameter value +//! @param[in] theBsup Last parameter value +//! @param[in] theNbPntIn Number of sample points +//! @param[in,out] thePnts Array to store sampled points (must be pre-allocated) +//! @param[in,out] theBnd Bounding box to update +//! @param[out] theDeflection Estimated maximum deflection +template +void InitUniform(const CurveType& theCurve, + const double theBinf, + const double theBsup, + const int theNbPntIn, + TColgp_Array1OfPnt& thePnts, + Bnd_Box& theBnd, + double& theDeflection) +{ + const double du = (theBsup - theBinf) / static_cast(theNbPntIn - 1); + double u = theBinf; + gp_Pnt P; + + for (int i = 1; i <= theNbPntIn; ++i) + { + CurveTool::D0(theCurve, u, P); + theBnd.Add(P); + thePnts.SetValue(i, P); + u += du; + } + + // Calculate deflection estimate by measuring distance from midpoints to chord lines + theDeflection = 0.0; + if (theNbPntIn > 3) + { + u = theBinf + du * 0.5; + for (int i = 1; i < theNbPntIn; ++i) + { + const gp_Pnt Pm = CurveTool::Value(theCurve, u); + const gp_Pnt& P1 = thePnts.Value(i); + const gp_Pnt& P2 = thePnts.Value(i + 1); + const gp_Lin L(P1, gp_Dir(gp_Vec(P1, P2))); + const double t = L.Distance(Pm); + if (t > theDeflection) + { + theDeflection = t; + } + u += du; + } + theBnd.Enlarge(1.5 * theDeflection); + } + else + { + theBnd.Enlarge(1e-10); + } +} + +//! Initialize polygon with explicit parameter array. +//! Samples points at the specified parameter values and stores them for later lookup. +//! @tparam CurveType Type of curve (e.g., Handle(Adaptor3d_Curve) or gp_Lin) +//! @tparam CurveTool Tool class providing curve operations +//! @param[in] theCurve The curve to discretize +//! @param[in] theUpars Array of parameter values +//! @param[in] theNbPntIn Number of sample points +//! @param[in,out] thePnts Array to store sampled points (must be pre-allocated) +//! @param[in,out] theBnd Bounding box to update +//! @param[out] theDeflection Estimated maximum deflection +//! @param[out] theParams Handle to store copy of parameters (created internally) +template +void InitWithParams(const CurveType& theCurve, + const TColStd_Array1OfReal& theUpars, + const int theNbPntIn, + TColgp_Array1OfPnt& thePnts, + Bnd_Box& theBnd, + double& theDeflection, + Handle(TColStd_HArray1OfReal)& theParams) +{ + theParams = new TColStd_HArray1OfReal(1, theUpars.Length()); + const int i0 = theUpars.Lower() - 1; + gp_Pnt P; + + for (int i = 1; i <= theNbPntIn; ++i) + { + theParams->SetValue(i, theUpars(i + i0)); + CurveTool::D0(theCurve, theUpars(i + i0), P); + theBnd.Add(P); + thePnts.SetValue(i, P); + } + + // Calculate deflection estimate + theDeflection = 0.0; + if (theNbPntIn > 3) + { + for (int i = 1; i < theNbPntIn; ++i) + { + const double u = 0.5 * (theUpars(i0 + i) + theUpars(i0 + i + 1)); + const gp_Pnt Pm = CurveTool::Value(theCurve, u); + const gp_Pnt& P1 = thePnts.Value(i); + const gp_Pnt& P2 = thePnts.Value(i + 1); + const gp_Lin L(P1, gp_Dir(gp_Vec(P1, P2))); + const double t = L.Distance(Pm); + if (t > theDeflection) + { + theDeflection = t; + } + } + theBnd.Enlarge(1.5 * theDeflection); + } + else + { + theBnd.Enlarge(1e-10); + } +} + +//! Compute approximate parameter on curve for a given polygon segment and position. +//! This is a non-template function as it only operates on stored data. +//! @param[in] theIndex Segment index (1-based) +//! @param[in] theParamOnLine Position along segment [0,1] +//! @param[in] theBinf First parameter of polygon range +//! @param[in] theBsup Last parameter of polygon range +//! @param[in] theNbPntIn Number of points in polygon +//! @param[in] theParams Optional explicit parameter array (may be null for uniform) +//! @return Approximate parameter value on the curve +inline double ApproxParamOnCurve(int theIndex, + double theParamOnLine, + const double theBinf, + const double theBsup, + const int theNbPntIn, + const Handle(TColStd_HArray1OfReal)& theParams) +{ + if (theParamOnLine < 0.0 || theParamOnLine > 1.0) + { +#ifdef OCCT_DEBUG + std::cout << " ParamOnLine = " << theParamOnLine << " avec Index = " << theIndex + << " dans IntCurveSurface_Polygon::ApproxParamOnCurve" << std::endl; +#endif + return theBinf + (theParamOnLine * (theBsup - theBinf)) / static_cast(theNbPntIn - 1); + } + + int Index = theIndex; + double ParamOnLine = theParamOnLine; + +#ifdef OCCT_DEBUG + if (Index > theNbPntIn) + { + std::cout << "OutOfRange Polygon::ApproxParamOnCurve " << std::endl; + } +#endif + + if ((Index == theNbPntIn) && (ParamOnLine == 0.0)) + { + Index--; + ParamOnLine = 1.0; + } + + double du, u; + if (theParams.IsNull()) + { + du = (theBsup - theBinf) / static_cast(theNbPntIn - 1); + u = theBinf + du * static_cast(Index - 1); + } + else + { + du = theParams->Value(Index + 1) - theParams->Value(Index); + u = theParams->Value(Index); + } + + u += du * ParamOnLine; + return u; +} + +} // namespace IntCurveSurface_PolygonUtils + +#endif // IntCurveSurface_PolygonUtils_pxx_HeaderFile diff --git a/src/ModelingAlgorithms/TKGeomAlgo/IntCurveSurface/IntCurveSurface_Polyhedron.gxx b/src/ModelingAlgorithms/TKGeomAlgo/IntCurveSurface/IntCurveSurface_Polyhedron.gxx deleted file mode 100644 index c8cc62eeaa..0000000000 --- a/src/ModelingAlgorithms/TKGeomAlgo/IntCurveSurface/IntCurveSurface_Polyhedron.gxx +++ /dev/null @@ -1,951 +0,0 @@ -// Created on: 1993-02-03 -// Created by: Laurent BUCHARD -// Copyright (c) 1993-1999 Matra Datavision -// Copyright (c) 1999-2014 OPEN CASCADE SAS -// -// This file is part of Open CASCADE Technology software library. -// -// This library is free software; you can redistribute it and/or modify it under -// the terms of the GNU Lesser General Public License version 2.1 as published -// by the Free Software Foundation, with special exception defined in the file -// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT -// distribution for complete text of the license and disclaimer of any warranty. -// -// Alternatively, this file may be used under the terms of Open CASCADE -// commercial license or contractual agreement. - -#include -#include -#include -#include -#include -#include -#include - -#include - -#include - -#include - -#define CHECKBOUNDS 0 - -//----------------------------------------------------- -#define LONGUEUR_MINI_EDGE_TRIANGLE 1e-15 - -//================================================================================================= - -IntCurveSurface_Polyhedron::IntCurveSurface_Polyhedron(const ThePSurface& Surface, - const Standard_Integer nbdU, - const Standard_Integer nbdV, - const Standard_Real u1, - const Standard_Real v1, - const Standard_Real u2, - const Standard_Real v2) - : nbdeltaU((nbdU < 3) ? 3 : nbdU), - nbdeltaV((nbdV < 3) ? 3 : nbdV), - TheDeflection(Epsilon(100.)), - C_MyPnts(NULL), - C_MyU(NULL), - C_MyV(NULL), - C_MyIsOnBounds(NULL) -{ - Standard_Integer t = (nbdeltaU + 1) * (nbdeltaV + 1) + 1; - gp_Pnt* CMyPnts = new gp_Pnt[t]; - C_MyPnts = (void*)CMyPnts; - Standard_Real* CMyU = new Standard_Real[t]; - C_MyU = (void*)CMyU; - Standard_Real* CMyV = new Standard_Real[t]; - C_MyV = (void*)CMyV; - - // Modified by Sergey KHROMOV - Fri Dec 7 12:03:46 2001 Begin - Standard_Boolean* CMyIsOnBounds = new Standard_Boolean[t]; - - C_MyIsOnBounds = (void*)CMyIsOnBounds; - // Modified by Sergey KHROMOV - Fri Dec 7 12:03:47 2001 End - Init(Surface, u1, v1, u2, v2); -} - -//================================================================================================= - -IntCurveSurface_Polyhedron::IntCurveSurface_Polyhedron(const ThePSurface& Surface, - const TColStd_Array1OfReal& Upars, - const TColStd_Array1OfReal& Vpars) - : nbdeltaU(Upars.Length() - 1), - nbdeltaV(Vpars.Length() - 1), - TheDeflection(Epsilon(100.)), - C_MyPnts(NULL), - C_MyU(NULL), - C_MyV(NULL), - C_MyIsOnBounds(NULL) -{ - Standard_Integer t = (nbdeltaU + 1) * (nbdeltaV + 1) + 1; - gp_Pnt* CMyPnts = new gp_Pnt[t]; - C_MyPnts = (void*)CMyPnts; - Standard_Real* CMyU = new Standard_Real[t]; - C_MyU = (void*)CMyU; - Standard_Real* CMyV = new Standard_Real[t]; - C_MyV = (void*)CMyV; - - // Modified by Sergey KHROMOV - Fri Dec 7 12:03:46 2001 Begin - Standard_Boolean* CMyIsOnBounds = new Standard_Boolean[t]; - - C_MyIsOnBounds = (void*)CMyIsOnBounds; - // Modified by Sergey KHROMOV - Fri Dec 7 12:03:47 2001 End - Init(Surface, Upars, Vpars); -} - -void IntCurveSurface_Polyhedron::Destroy() -{ - //-- printf("\n IntCurveSurface_Polyhedron::Destroy\n"); - gp_Pnt* CMyPnts = (gp_Pnt*)C_MyPnts; - if (C_MyPnts) - delete[] CMyPnts; - Standard_Real* CMyU = (Standard_Real*)C_MyU; - if (C_MyU) - delete[] CMyU; - Standard_Real* CMyV = (Standard_Real*)C_MyV; - if (C_MyV) - delete[] CMyV; - - // Modified by Sergey KHROMOV - Fri Dec 7 12:03:46 2001 Begin - Standard_Boolean* CMyIsOnBounds = (Standard_Boolean*)C_MyIsOnBounds; - - if (C_MyIsOnBounds) - delete[] CMyIsOnBounds; - // Modified by Sergey KHROMOV - Fri Dec 7 12:03:47 2001 End - - C_MyPnts = C_MyU = C_MyV = C_MyIsOnBounds = NULL; -} - -//================================================================================================= - -void IntCurveSurface_Polyhedron::Init(const ThePSurface& Surface, - const Standard_Real U0, - const Standard_Real V0, - const Standard_Real U1, - const Standard_Real V1) -{ - // #define DEBUGDUMP - Standard_Integer i1, i2; - Standard_Real U, V; - Standard_Real U1mU0sNbdeltaU = (U1 - U0) / (Standard_Real)nbdeltaU; - Standard_Real V1mV0sNbdeltaV = (V1 - V0) / (Standard_Real)nbdeltaV; - gp_Pnt TP; - Standard_Integer Index = 1; - //-- -------------------------------------------------- - //-- Index varie de 1 -> (nbdu+1)*(nbdv+1) - //-- V est la colonne - //-- U est la ligne - //-- -------------------------------------------------- - gp_Pnt* CMyPnts = (gp_Pnt*)C_MyPnts; - Standard_Real* CMyU = (Standard_Real*)C_MyU; - Standard_Real* CMyV = (Standard_Real*)C_MyV; - Standard_Boolean* CMyIsOnBounds = (Standard_Boolean*)C_MyIsOnBounds; - - for (i1 = 0, U = U0; i1 <= nbdeltaU; i1++, U += U1mU0sNbdeltaU) - { - for (i2 = 0, V = V0; i2 <= nbdeltaV; i2++, V += V1mV0sNbdeltaV) - { - ThePSurfaceTool::D0(Surface, U, V, TP); - //-- Point(TP,i1, i2,U,V); - CMyPnts[Index] = TP; - CMyU[Index] = U; - CMyV[Index] = V; - // Modified by Sergey KHROMOV - Fri Dec 7 12:07:51 2001 - CMyIsOnBounds[Index] = (i1 == 0 || i1 == nbdeltaU || i2 == 0 || i2 == nbdeltaV); - // Modified by Sergey KHROMOV - Fri Dec 7 12:07:52 2001 - TheBnd.Add(TP); - Index++; - } - } - //-- Calcul de la deflection Triangle <-> Point milieu - Standard_Real tol = 0.0; - Standard_Integer nbtriangles = NbTriangles(); - for (i1 = 1; i1 <= nbtriangles; i1++) - { - Standard_Real tol1 = DeflectionOnTriangle(Surface, i1); - if (tol1 > tol) - tol = tol1; - } - //-- Calcul de la deflection Bord <-> Point milieu - - DeflectionOverEstimation(tol * 1.2); - FillBounding(); - - // Modified by Sergey KHROMOV - Fri Dec 7 11:23:33 2001 Begin - Standard_Real aDeflection; - - TheBorderDeflection = RealFirst(); - - // Compute the deflection on the lower bound (U-isoline) of the surface. - aDeflection = ComputeBorderDeflection(Surface, U0, V0, V1, Standard_True); - - if (aDeflection > TheBorderDeflection) - TheBorderDeflection = aDeflection; - - // Compute the deflection on the upper bound (U-isoline) of the surface. - aDeflection = ComputeBorderDeflection(Surface, U1, V0, V1, Standard_True); - - if (aDeflection > TheBorderDeflection) - TheBorderDeflection = aDeflection; - - // Compute the deflection on the lower bound (V-isoline) of the surface. - aDeflection = ComputeBorderDeflection(Surface, V0, U0, U1, Standard_False); - - if (aDeflection > TheBorderDeflection) - TheBorderDeflection = aDeflection; - - // Compute the deflection on the upper bound (V-isoline) of the surface. - aDeflection = ComputeBorderDeflection(Surface, V1, U0, U1, Standard_False); - - if (aDeflection > TheBorderDeflection) - TheBorderDeflection = aDeflection; - - // Modified by Sergey KHROMOV - Fri Dec 7 11:23:34 2001 End - -#ifdef OCCT_DEBUG_DUMP - Dump(); -#endif -} - -//================================================================================================= - -void IntCurveSurface_Polyhedron::Init(const ThePSurface& Surface, - const TColStd_Array1OfReal& Upars, - const TColStd_Array1OfReal& Vpars) -{ - // #define DEBUGDUMP - Standard_Integer i1, i2; - Standard_Real U, V; - gp_Pnt TP; - Standard_Integer Index = 1; - //-- -------------------------------------------------- - //-- Index varie de 1 -> (nbdu+1)*(nbdv+1) - //-- V est la colonne - //-- U est la ligne - //-- -------------------------------------------------- - gp_Pnt* CMyPnts = (gp_Pnt*)C_MyPnts; - Standard_Real* CMyU = (Standard_Real*)C_MyU; - Standard_Real* CMyV = (Standard_Real*)C_MyV; - Standard_Boolean* CMyIsOnBounds = (Standard_Boolean*)C_MyIsOnBounds; - Standard_Integer i0 = Upars.Lower(), j0 = Vpars.Lower(); - - for (i1 = 0; i1 <= nbdeltaU; i1++) - { - U = Upars(i1 + i0); - for (i2 = 0; i2 <= nbdeltaV; i2++) - { - V = Vpars(i2 + j0); - ThePSurfaceTool::D0(Surface, U, V, TP); - //-- Point(TP,i1, i2,U,V); - CMyPnts[Index] = TP; - CMyU[Index] = U; - CMyV[Index] = V; - // Modified by Sergey KHROMOV - Fri Dec 7 12:07:51 2001 - CMyIsOnBounds[Index] = (i1 == 0 || i1 == nbdeltaU || i2 == 0 || i2 == nbdeltaV); - // Modified by Sergey KHROMOV - Fri Dec 7 12:07:52 2001 - TheBnd.Add(TP); - Index++; - } - } - //-- Calcul de la deflection Triangle <-> Point milieu - Standard_Real tol = 0.0; - Standard_Integer nbtriangles = NbTriangles(); - for (i1 = 1; i1 <= nbtriangles; i1++) - { - Standard_Real tol1 = DeflectionOnTriangle(Surface, i1); - if (tol1 > tol) - tol = tol1; - } - //-- Calcul de la deflection Bord <-> Point milieu - - DeflectionOverEstimation(tol * 1.2); - FillBounding(); - - // Modified by Sergey KHROMOV - Fri Dec 7 11:23:33 2001 Begin - Standard_Real aDeflection; - - TheBorderDeflection = RealFirst(); - Standard_Real U0 = Upars(i0); - Standard_Real V0 = Vpars(j0); - Standard_Real U1 = Upars(Upars.Upper()); - Standard_Real V1 = Vpars(Vpars.Upper()); - - // Compute the deflection on the lower bound (U-isoline) of the surface. - aDeflection = ComputeBorderDeflection(Surface, U0, V0, V1, Standard_True); - - if (aDeflection > TheBorderDeflection) - TheBorderDeflection = aDeflection; - - // Compute the deflection on the upper bound (U-isoline) of the surface. - aDeflection = ComputeBorderDeflection(Surface, U1, V0, V1, Standard_True); - - if (aDeflection > TheBorderDeflection) - TheBorderDeflection = aDeflection; - - // Compute the deflection on the lower bound (V-isoline) of the surface. - aDeflection = ComputeBorderDeflection(Surface, V0, U0, U1, Standard_False); - - if (aDeflection > TheBorderDeflection) - TheBorderDeflection = aDeflection; - - // Compute the deflection on the upper bound (V-isoline) of the surface. - aDeflection = ComputeBorderDeflection(Surface, V1, U0, U1, Standard_False); - - if (aDeflection > TheBorderDeflection) - TheBorderDeflection = aDeflection; - - // Modified by Sergey KHROMOV - Fri Dec 7 11:23:34 2001 End - -#ifdef OCCT_DEBUG_DUMP - Dump(); -#endif -} - -//================================================================================================= - -Standard_Real IntCurveSurface_Polyhedron::DeflectionOnTriangle(const ThePSurface& Surface, - const Standard_Integer Triang) const -{ - Standard_Integer i1, i2, i3; - Triangle(Triang, i1, i2, i3); - //-- Calcul de l equation du plan - Standard_Real u1, v1, u2, v2, u3, v3; - gp_Pnt P1, P2, P3; - P1 = Point(i1, u1, v1); - P2 = Point(i2, u2, v2); - P3 = Point(i3, u3, v3); - if (P1.SquareDistance(P2) <= LONGUEUR_MINI_EDGE_TRIANGLE) - return (0); - if (P1.SquareDistance(P3) <= LONGUEUR_MINI_EDGE_TRIANGLE) - return (0); - if (P2.SquareDistance(P3) <= LONGUEUR_MINI_EDGE_TRIANGLE) - return (0); - gp_XYZ XYZ1 = P2.XYZ() - P1.XYZ(); - gp_XYZ XYZ2 = P3.XYZ() - P2.XYZ(); - gp_XYZ XYZ3 = P1.XYZ() - P3.XYZ(); - gp_Vec NormalVector((XYZ1 ^ XYZ2) + (XYZ2 ^ XYZ3) + (XYZ3 ^ XYZ1)); - Standard_Real aNormLen = NormalVector.Magnitude(); - if (aNormLen < gp::Resolution()) - { - return 0.; - } - // - NormalVector.Divide(aNormLen); - //-- Standard_Real PolarDistance = NormalVector * P1.XYZ(); - //-- Calcul du point u,v au centre du triangle - Standard_Real u = (u1 + u2 + u3) / 3.0; - Standard_Real v = (v1 + v2 + v3) / 3.0; - gp_Pnt P = ThePSurfaceTool::Value(Surface, u, v); - gp_Vec P1P(P1, P); - return (std::abs(P1P.Dot(NormalVector))); -} - -//================================================================================================= - -void IntCurveSurface_Polyhedron::Parameters(const Standard_Integer Index, - Standard_Real& U, - Standard_Real& V) const -{ -#if CHECKBOUNDS - if (Index < 0 || Index > ((nbdeltaU + 1) * (nbdeltaV + 1))) - { - printf("\n Erreur IntCurveSurface_Polyhedron::Parameters\n"); - } -#endif - Standard_Real* CMyU = (Standard_Real*)C_MyU; - U = CMyU[Index]; - Standard_Real* CMyV = (Standard_Real*)C_MyV; - V = CMyV[Index]; -} - -//================================================================================================= - -void IntCurveSurface_Polyhedron::DeflectionOverEstimation(const Standard_Real flec) -{ - if (flec < 0.0001) - { - TheDeflection = 0.0001; - TheBnd.Enlarge(0.0001); - } - else - { - TheDeflection = flec; - TheBnd.Enlarge(flec); - } -} - -//================================================================================================= - -Standard_Real IntCurveSurface_Polyhedron::DeflectionOverEstimation() const -{ - return TheDeflection; -} - -//================================================================================================= - -const Bnd_Box& IntCurveSurface_Polyhedron::Bounding() const -{ - return TheBnd; -} - -//================================================================================================= - -void IntCurveSurface_Polyhedron::FillBounding() -{ - TheComponentsBnd = new Bnd_HArray1OfBox(1, NbTriangles()); - Bnd_Box Boite; - Standard_Integer np1, np2, np3; - Standard_Integer nbtriangles = NbTriangles(); - for (Standard_Integer iTri = 1; iTri <= nbtriangles; iTri++) - { - Triangle(iTri, np1, np2, np3); - gp_Pnt p1(Point(np1)); - gp_Pnt p2(Point(np2)); - gp_Pnt p3(Point(np3)); - Boite.SetVoid(); - if (p1.SquareDistance(p2) > LONGUEUR_MINI_EDGE_TRIANGLE) - { - if (p1.SquareDistance(p3) > LONGUEUR_MINI_EDGE_TRIANGLE) - { - if (p2.SquareDistance(p3) > LONGUEUR_MINI_EDGE_TRIANGLE) - { - Boite.Add(p1); - Boite.Add(p2); - Boite.Add(p3); - Boite.Enlarge(TheDeflection); - } - } - } - Boite.Enlarge(TheDeflection); - TheComponentsBnd->SetValue(iTri, Boite); - } -} - -//================================================================================================= - -const Handle(Bnd_HArray1OfBox)& IntCurveSurface_Polyhedron::ComponentsBounding() const -{ - return TheComponentsBnd; -} - -//================================================================================================= - -Standard_Integer IntCurveSurface_Polyhedron::NbTriangles() const -{ - return nbdeltaU * nbdeltaV * 2; -} - -//================================================================================================= - -Standard_Integer IntCurveSurface_Polyhedron::NbPoints() const -{ - return (nbdeltaU + 1) * (nbdeltaV + 1); -} - -//================================================================================================= - -Standard_Integer IntCurveSurface_Polyhedron::TriConnex(const Standard_Integer Triang, - const Standard_Integer Pivot, - const Standard_Integer Pedge, - Standard_Integer& TriCon, - Standard_Integer& OtherP) const -{ - Standard_Integer Pivotm1 = Pivot - 1; - Standard_Integer nbdeltaVp1 = nbdeltaV + 1; - Standard_Integer nbdeltaVm2 = nbdeltaV + nbdeltaV; - - // Pivot position in the MaTriangle : - Standard_Integer ligP = Pivotm1 / nbdeltaVp1; - Standard_Integer colP = Pivotm1 - ligP * nbdeltaVp1; - - // Point sur Edge position in the MaTriangle and edge typ : - Standard_Integer ligE = 0, colE = 0, typE = 0; - if (Pedge != 0) - { - ligE = (Pedge - 1) / nbdeltaVp1; - colE = (Pedge - 1) - (ligE * nbdeltaVp1); - // Horizontal - if (ligP == ligE) - typE = 1; - // Vertical - else if (colP == colE) - typE = 2; - // Oblique - else - typE = 3; - } - else - { - typE = 0; - } - - // Triangle position General case : - - Standard_Integer linT = 0, colT = 0; - Standard_Integer linO = 0, colO = 0; - Standard_Integer t = 0, tt = 0; - - if (Triang != 0) - { - t = (Triang - 1) / (nbdeltaVm2); - tt = (Triang - 1) - t * nbdeltaVm2; - linT = 1 + t; - colT = 1 + tt; - if (typE == 0) - { - if (ligP == linT) - { - ligE = ligP - 1; - colE = colP - 1; - typE = 3; - } - else - { - if (colT == ligP + ligP) - { - ligE = ligP; - colE = colP - 1; - typE = 1; - } - else - { - ligE = ligP + 1; - colE = colP + 1; - typE = 3; - } - } - } - switch (typE) - { - case 1: // Horizontal - if (linT == ligP) - { - linT++; - linO = ligP + 1; - colO = (colP > colE) ? colP : colE; //--colO=Max(colP, colE); - } - else - { - linT--; - linO = ligP - 1; - colO = (colP < colE) ? colP : colE; //--colO=Min(colP, colE); - } - break; - case 2: // Vertical - if (colT == (colP + colP)) - { - colT++; - linO = (ligP > ligE) ? ligP : ligE; //--linO=Max(ligP, ligE); - colO = colP + 1; - } - else - { - colT--; - linO = (ligP < ligE) ? ligP : ligE; //--linO=Min(ligP, ligE); - colO = colP - 1; - } - break; - case 3: // Oblique - if ((colT & 1) == 0) - { - colT--; - linO = (ligP > ligE) ? ligP : ligE; //--linO=Max(ligP, ligE); - colO = (colP < colE) ? colP : colE; //--colO=Min(colP, colE); - } - else - { - colT++; - linO = (ligP < ligE) ? ligP : ligE; //--linO=Min(ligP, ligE); - colO = (colP > colE) ? colP : colE; //--colO=Max(colP, colE); - } - break; - } - } - else - { - // Unknown Triangle position : - if (Pedge == 0) - { - // Unknown edge : - linT = (1 > ligP) ? 1 : ligP; //--linT=Max(1, ligP); - colT = (1 > (colP + colP)) ? 1 : (colP + colP); //--colT=Max(1, colP+colP); - if (ligP == 0) - linO = ligP + 1; - else - linO = ligP - 1; - colO = colP; - } - else - { - // Known edge We take the left or down connectivity : - switch (typE) - { - case 1: // Horizontal - linT = ligP + 1; - colT = (colP > colE) ? colP : colE; //--colT=Max(colP,colE); - colT += colT; - linO = ligP + 1; - colO = (colP > colE) ? colP : colE; //--colO=Max(colP,colE); - break; - case 2: // Vertical - linT = (ligP > ligE) ? ligP : ligE; //--linT=Max(ligP, ligE); - colT = colP + colP; - linO = (ligP < ligE) ? ligP : ligE; //--linO=Min(ligP, ligE); - colO = colP - 1; - break; - case 3: // Oblique - linT = (ligP > ligE) ? ligP : ligE; //--linT=Max(ligP, ligE); - colT = colP + colE; - linO = (ligP > ligE) ? ligP : ligE; //--linO=Max(ligP, ligE); - colO = (colP < colE) ? colP : colE; //--colO=Min(colP, colE); - break; - } - } - } - - TriCon = (linT - 1) * nbdeltaVm2 + colT; - - if (linT < 1) - { - linO = 0; - colO = colP + colP - colE; - if (colO < 0) - { - colO = 0; - linO = 1; - } - else if (colO > nbdeltaV) - { - colO = nbdeltaV; - linO = 1; - } - TriCon = 0; - } - else if (linT > nbdeltaU) - { - linO = nbdeltaU; - colO = colP + colP - colE; - if (colO < 0) - { - colO = 0; - linO = nbdeltaU - 1; - } - else if (colO > nbdeltaV) - { - colO = nbdeltaV; - linO = nbdeltaU - 1; - } - TriCon = 0; - } - - if (colT < 1) - { - colO = 0; - linO = ligP + ligP - ligE; - if (linO < 0) - { - linO = 0; - colO = 1; - } - else if (linO > nbdeltaU) - { - linO = nbdeltaU; - colO = 1; - } - TriCon = 0; - } - else if (colT > nbdeltaV) - { - colO = nbdeltaV; - linO = ligP + ligP - ligE; - if (linO < 0) - { - linO = 0; - colO = nbdeltaV - 1; - } - else if (linO > nbdeltaU) - { - linO = nbdeltaU; - colO = nbdeltaV - 1; - } - TriCon = 0; - } - - OtherP = linO * nbdeltaVp1 + colO + 1; - - return TriCon; -} - -//================================================================================================= - -void IntCurveSurface_Polyhedron::PlaneEquation(const Standard_Integer Triang, - gp_XYZ& NormalVector, - Standard_Real& PolarDistance) const -{ - Standard_Integer i1, i2, i3; - Triangle(Triang, i1, i2, i3); - - //-- gp_XYZ v1=Point(i2).XYZ()-Point(i1).XYZ(); - //-- gp_XYZ v2=Point(i3).XYZ()-Point(i2).XYZ(); - //-- gp_XYZ v3=Point(i1).XYZ()-Point(i3).XYZ(); - - gp_XYZ Pointi1(Point(i1).XYZ()); - gp_XYZ Pointi2(Point(i2).XYZ()); - gp_XYZ Pointi3(Point(i3).XYZ()); - - gp_XYZ v1 = Pointi2 - Pointi1; - gp_XYZ v2 = Pointi3 - Pointi2; - gp_XYZ v3 = Pointi1 - Pointi3; - - if (v1.SquareModulus() <= LONGUEUR_MINI_EDGE_TRIANGLE) - { - NormalVector.SetCoord(1.0, 0.0, 0.0); - return; - } - if (v2.SquareModulus() <= LONGUEUR_MINI_EDGE_TRIANGLE) - { - NormalVector.SetCoord(1.0, 0.0, 0.0); - return; - } - if (v3.SquareModulus() <= LONGUEUR_MINI_EDGE_TRIANGLE) - { - NormalVector.SetCoord(1.0, 0.0, 0.0); - return; - } - - NormalVector = (v1 ^ v2) + (v2 ^ v3) + (v3 ^ v1); - Standard_Real aNormLen = NormalVector.Modulus(); - if (aNormLen < gp::Resolution()) - { - PolarDistance = 0.; - } - else - { - NormalVector.Divide(aNormLen); - PolarDistance = NormalVector * Point(i1).XYZ(); - } -} - -//================================================================================================= - -Standard_Boolean IntCurveSurface_Polyhedron::Contain(const Standard_Integer Triang, - const gp_Pnt& ThePnt) const -{ - Standard_Integer i1, i2, i3; - Triangle(Triang, i1, i2, i3); - gp_XYZ Pointi1(Point(i1).XYZ()); - gp_XYZ Pointi2(Point(i2).XYZ()); - gp_XYZ Pointi3(Point(i3).XYZ()); - - gp_XYZ v1 = (Pointi2 - Pointi1) ^ (ThePnt.XYZ() - Pointi1); - gp_XYZ v2 = (Pointi3 - Pointi2) ^ (ThePnt.XYZ() - Pointi2); - gp_XYZ v3 = (Pointi1 - Pointi3) ^ (ThePnt.XYZ() - Pointi3); - if (v1 * v2 >= 0. && v2 * v3 >= 0. && v3 * v1 >= 0.) - return Standard_True; - else - return Standard_False; -} - -//================================================================================================= - -void IntCurveSurface_Polyhedron::Dump() const {} - -//================================================================================================= - -void IntCurveSurface_Polyhedron::Size(Standard_Integer& nbdu, Standard_Integer& nbdv) const -{ - nbdu = nbdeltaU; - nbdv = nbdeltaV; -} - -//================================================================================================= - -void IntCurveSurface_Polyhedron::Triangle(const Standard_Integer Index, - Standard_Integer& P1, - Standard_Integer& P2, - Standard_Integer& P3) const -{ - Standard_Integer line = 1 + ((Index - 1) / (nbdeltaV * 2)); - Standard_Integer colon = 1 + ((Index - 1) % (nbdeltaV * 2)); - Standard_Integer colpnt = (colon + 1) / 2; - - // General formula = (line-1)*(nbdeltaV+1)+colpnt - - // Position of P1 = MesXYZ(line,colpnt); - P1 = (line - 1) * (nbdeltaV + 1) + colpnt; - - // Position of P2= MesXYZ(line+1,colpnt+((colon-1)%2)); - P2 = line * (nbdeltaV + 1) + colpnt + ((colon - 1) % 2); - - // Position of P3= MesXYZ(line+(colon%2),colpnt+1); - P3 = (line - 1 + (colon % 2)) * (nbdeltaV + 1) + colpnt + 1; -} - -//======================================================================= -// function : Point -//======================================================================= -const gp_Pnt& IntCurveSurface_Polyhedron::Point(const Standard_Integer Index, - Standard_Real& U, - Standard_Real& V) const -{ -#if CHECKBOUNDS - if (Index < 0 || Index > ((nbdeltaU + 1) * (nbdeltaV + 1))) - { - printf("\n Erreur IntCurveSurface_Polyhedron::Parameters\n"); - } -#endif - gp_Pnt* CMyPnts = (gp_Pnt*)C_MyPnts; - Standard_Real* CMyU = (Standard_Real*)C_MyU; - Standard_Real* CMyV = (Standard_Real*)C_MyV; - U = CMyU[Index]; - V = CMyV[Index]; - return CMyPnts[Index]; -} - -//======================================================================= -// function : Point -//======================================================================= -const gp_Pnt& IntCurveSurface_Polyhedron::Point(const Standard_Integer Index) const -{ -#if CHECKBOUNDS - if (Index < 0 || Index > ((nbdeltaU + 1) * (nbdeltaV + 1))) - { - printf("\n Erreur IntCurveSurface_Polyhedron::Parameters\n"); - } -#endif - - gp_Pnt* CMyPnts = (gp_Pnt*)C_MyPnts; - return CMyPnts[Index]; -} - -//======================================================================= -// function : Point -//======================================================================= -// void IntCurveSurface_Polyhedron::Point (const gp_Pnt& p, -// const Standard_Integer lig, -// const Standard_Integer col, -// const Standard_Real u, -// const Standard_Real v) -void IntCurveSurface_Polyhedron::Point(const gp_Pnt&, - const Standard_Integer, - const Standard_Integer, - const Standard_Real, - const Standard_Real) -{ - printf("\n IntCurveSurface_Polyhedron::Point : Ne dois pas etre appelle\n"); -} - -//======================================================================= -// function : Point -//======================================================================= -void IntCurveSurface_Polyhedron::Point(const Standard_Integer Index, gp_Pnt& P) const -{ -#if CHECKBOUNDS - if (Index < 0 || Index > ((nbdeltaU + 1) * (nbdeltaV + 1))) - { - printf("\n Erreur IntCurveSurface_Polyhedron::Parameters\n"); - } -#endif - - gp_Pnt* CMyPnts = (gp_Pnt*)C_MyPnts; - P = CMyPnts[Index]; -} - -// Modified by Sergey KHROMOV - Fri Dec 7 10:12:47 2001 Begin - -//======================================================================= -// function : IsOnBound -// purpose : This method returns true if the edge based on points with -// indices Index1 and Index2 represents a boundary edge. -//======================================================================= - -Standard_Boolean IntCurveSurface_Polyhedron::IsOnBound(const Standard_Integer Index1, - const Standard_Integer Index2) const -{ -#if CHECKBOUNDS - if (Index1 < 0 || Index1 > ((nbdeltaU + 1) * (nbdeltaV + 1))) - { - printf("\n Erreur IntCurveSurface_Polyhedron::IsOnBound\n"); - } - if (Index2 < 0 || Index2 > ((nbdeltaU + 1) * (nbdeltaV + 1))) - { - printf("\n Erreur IntCurveSurface_Polyhedron::IsOnBound\n"); - } -#endif - Standard_Boolean* CMyIsOnBounds = (Standard_Boolean*)C_MyIsOnBounds; - Standard_Integer aDiff = std::abs(Index1 - Index2); - Standard_Integer i; - - // Check if points are neighbour ones. - if (aDiff != 1 && aDiff != nbdeltaV + 1) - return Standard_False; - - for (i = 0; i <= nbdeltaU; i++) - { - if ((Index1 == 1 + i * (nbdeltaV + 1)) && (Index2 == Index1 - 1)) - return Standard_False; - - if ((Index1 == (1 + i) * (nbdeltaV + 1)) && (Index2 == Index1 + 1)) - return Standard_False; - } - - return (CMyIsOnBounds[Index1] && CMyIsOnBounds[Index2]); -} - -//======================================================================= -// function : ComputeBorderDeflection -// purpose : This method computes and returns a deflection of isoline -// of given parameter on Surface. -//======================================================================= - -Standard_Real IntCurveSurface_Polyhedron::ComputeBorderDeflection( - const ThePSurface& Surface, - const Standard_Real Parameter, - const Standard_Real PMin, - const Standard_Real PMax, - const Standard_Boolean isUIso) const -{ - Standard_Integer aNbSamples; - Standard_Integer i; - - if (isUIso) - aNbSamples = nbdeltaV; - else - aNbSamples = nbdeltaU; - - Standard_Real aDelta = (PMax - PMin) / aNbSamples; - Standard_Real aPar = PMin; - Standard_Real aDeflection = RealFirst(); - gp_XYZ aP1; - gp_XYZ aP2; - gp_XYZ aPMid; - gp_XYZ aPParMid; - - for (i = 0; i <= aNbSamples; i++, aPar += aDelta) - { - if (isUIso) - { - aP1 = ThePSurfaceTool::Value(Surface, Parameter, aPar).XYZ(); - aP2 = ThePSurfaceTool::Value(Surface, Parameter, aPar + aDelta).XYZ(); - aPParMid = ThePSurfaceTool::Value(Surface, Parameter, aPar + aDelta / 2.).XYZ(); - } - else - { - aP1 = ThePSurfaceTool::Value(Surface, aPar, Parameter).XYZ(); - aP2 = ThePSurfaceTool::Value(Surface, aPar + aDelta, Parameter).XYZ(); - aPParMid = ThePSurfaceTool::Value(Surface, aPar + aDelta / 2., Parameter).XYZ(); - } - aPMid = (aP2 + aP1) / 2.; - - Standard_Real aDist = (aPMid - aPParMid).Modulus(); - - if (aDist > aDeflection) - aDeflection = aDist; - } - - return aDeflection; -} - -// Modified by Sergey KHROMOV - Fri Dec 7 11:21:52 2001 End diff --git a/src/ModelingAlgorithms/TKGeomAlgo/IntCurveSurface/IntCurveSurface_Polyhedron.lxx b/src/ModelingAlgorithms/TKGeomAlgo/IntCurveSurface/IntCurveSurface_Polyhedron.lxx deleted file mode 100644 index e91cf53cad..0000000000 --- a/src/ModelingAlgorithms/TKGeomAlgo/IntCurveSurface/IntCurveSurface_Polyhedron.lxx +++ /dev/null @@ -1,24 +0,0 @@ -// Created on: 2001-12-07 -// Created by: Sergey KHROMOV -// Copyright (c) 2001-2014 OPEN CASCADE SAS -// -// This file is part of Open CASCADE Technology software library. -// -// This library is free software; you can redistribute it and/or modify it under -// the terms of the GNU Lesser General Public License version 2.1 as published -// by the Free Software Foundation, with special exception defined in the file -// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT -// distribution for complete text of the license and disclaimer of any warranty. -// -// Alternatively, this file may be used under the terms of Open CASCADE -// commercial license or contractual agreement. - -//======================================================================= -// function : GetBorderDeflection -// purpose : This method returns a border deflection. -//======================================================================= - -inline Standard_Real IntCurveSurface_Polyhedron::GetBorderDeflection() const -{ - return TheBorderDeflection; -} diff --git a/src/ModelingAlgorithms/TKGeomAlgo/IntCurveSurface/IntCurveSurface_PolyhedronTool.lxx b/src/ModelingAlgorithms/TKGeomAlgo/IntCurveSurface/IntCurveSurface_PolyhedronTool.lxx deleted file mode 100644 index ef99a9e873..0000000000 --- a/src/ModelingAlgorithms/TKGeomAlgo/IntCurveSurface/IntCurveSurface_PolyhedronTool.lxx +++ /dev/null @@ -1,89 +0,0 @@ -// Copyright (c) 1995-1999 Matra Datavision -// Copyright (c) 1999-2014 OPEN CASCADE SAS -// -// This file is part of Open CASCADE Technology software library. -// -// This library is free software; you can redistribute it and/or modify it under -// the terms of the GNU Lesser General Public License version 2.1 as published -// by the Free Software Foundation, with special exception defined in the file -// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT -// distribution for complete text of the license and disclaimer of any warranty. -// -// Alternatively, this file may be used under the terms of Open CASCADE -// commercial license or contractual agreement. - -#include ThePolyhedron_hxx - -inline const Bnd_Box& IntCurveSurface_PolyhedronTool::Bounding(const ThePolyhedron& thePolyh) -{ - return thePolyh.Bounding(); -} - -inline const Handle(Bnd_HArray1OfBox)& IntCurveSurface_PolyhedronTool::ComponentsBounding( - const ThePolyhedron& thePolyh) -{ - return thePolyh.ComponentsBounding(); -} - -inline Standard_Real IntCurveSurface_PolyhedronTool::DeflectionOverEstimation( - const ThePolyhedron& thePolyh) -{ - return thePolyh.DeflectionOverEstimation(); -} - -inline Standard_Integer IntCurveSurface_PolyhedronTool::NbTriangles(const ThePolyhedron& thePolyh) -{ - return thePolyh.NbTriangles(); -} - -inline void IntCurveSurface_PolyhedronTool::Triangle(const ThePolyhedron& thePolyh, - const Standard_Integer Index, - Standard_Integer& P1, - Standard_Integer& P2, - Standard_Integer& P3) -{ - thePolyh.Triangle(Index, P1, P2, P3); -} - -inline const gp_Pnt& IntCurveSurface_PolyhedronTool::Point(const ThePolyhedron& thePolyh, - const Standard_Integer Index) -{ - return thePolyh.Point(Index); -} - -inline Standard_Integer IntCurveSurface_PolyhedronTool::TriConnex(const ThePolyhedron& thePolyh, - const Standard_Integer Triang, - const Standard_Integer Pivot, - const Standard_Integer Pedge, - Standard_Integer& TriCon, - Standard_Integer& OtherP) -{ - return thePolyh.TriConnex(Triang, Pivot, Pedge, TriCon, OtherP); -} - -// Modified by Sergey KHROMOV - Fri Dec 7 13:47:07 2001 Begin -//======================================================================= -// function : IsOnBound -// purpose : This method returns true if the edge based on points with -// indices Index1 and Index2 represents a boundary edge. -//======================================================================= - -inline Standard_Boolean IntCurveSurface_PolyhedronTool::IsOnBound(const ThePolyhedron& thePolyh, - const Standard_Integer Index1, - const Standard_Integer Index2) -{ - return thePolyh.IsOnBound(Index1, Index2); -} - -//======================================================================= -// function : GetBorderDeflection -// purpose : This method returns a border deflection of the polyhedron. -//======================================================================= - -inline Standard_Real IntCurveSurface_PolyhedronTool::GetBorderDeflection( - const ThePolyhedron& thePolyh) -{ - return thePolyh.GetBorderDeflection(); -} - -// Modified by Sergey KHROMOV - Fri Dec 7 13:46:56 2001 End diff --git a/src/ModelingAlgorithms/TKGeomAlgo/IntCurveSurface/IntCurveSurface_PolyhedronUtils.pxx b/src/ModelingAlgorithms/TKGeomAlgo/IntCurveSurface/IntCurveSurface_PolyhedronUtils.pxx new file mode 100644 index 0000000000..1e40194a30 --- /dev/null +++ b/src/ModelingAlgorithms/TKGeomAlgo/IntCurveSurface/IntCurveSurface_PolyhedronUtils.pxx @@ -0,0 +1,239 @@ +// Copyright (c) 2025 OPEN CASCADE SAS +// +// This file is part of Open CASCADE Technology software library. +// +// This library is free software; you can redistribute it and/or modify it under +// the terms of the GNU Lesser General Public License version 2.1 as published +// by the Free Software Foundation, with special exception defined in the file +// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT +// distribution for complete text of the license and disclaimer of any warranty. +// +// Alternatively, this file may be used under the terms of Open CASCADE +// commercial license or contractual agreement. + +#ifndef IntCurveSurface_PolyhedronUtils_pxx_HeaderFile +#define IntCurveSurface_PolyhedronUtils_pxx_HeaderFile + +#include +#include +#include +#include +#include +#include +#include + +//! Utility functions for polyhedron discretization of surfaces. +//! These template functions implement the core logic previously in IntCurveSurface_Polyhedron.gxx. +namespace IntCurveSurface_PolyhedronUtils +{ + +//! Minimum edge length for valid triangles. +constexpr double THE_MIN_EDGE_LENGTH_SQUARED = 1e-15; + +//! Initialize polyhedron with uniform UV sampling. +//! @tparam SurfaceType Type of surface (e.g., Handle(Adaptor3d_Surface)) +//! @tparam SurfaceTool Tool class providing surface operations (D0, Value) +//! @param[in] theSurface The surface to discretize +//! @param[in] theU0 First U parameter +//! @param[in] theV0 First V parameter +//! @param[in] theU1 Last U parameter +//! @param[in] theV1 Last V parameter +//! @param[in] theNbDeltaU Number of U subdivisions +//! @param[in] theNbDeltaV Number of V subdivisions +//! @param[out] thePnts Array of sampled points (cast to gp_Pnt*) +//! @param[out] theU Array of U parameters (cast to double*) +//! @param[out] theV Array of V parameters (cast to double*) +//! @param[out] theIsOnBounds Array of boundary flags (cast to bool*) +//! @param[in,out] theBnd Bounding box to update +template +void InitUniform(const SurfaceType& theSurface, + const double theU0, + const double theV0, + const double theU1, + const double theV1, + const int theNbDeltaU, + const int theNbDeltaV, + gp_Pnt* thePnts, + double* theU, + double* theV, + Standard_Boolean* theIsOnBounds, + Bnd_Box& theBnd) +{ + const double dU = (theU1 - theU0) / static_cast(theNbDeltaU); + const double dV = (theV1 - theV0) / static_cast(theNbDeltaV); + + int Index = 1; + double U = theU0; + + for (int i1 = 0; i1 <= theNbDeltaU; ++i1, U += dU) + { + double V = theV0; + for (int i2 = 0; i2 <= theNbDeltaV; ++i2, V += dV) + { + gp_Pnt TP; + SurfaceTool::D0(theSurface, U, V, TP); + thePnts[Index] = TP; + theU[Index] = U; + theV[Index] = V; + theIsOnBounds[Index] = (i1 == 0 || i1 == theNbDeltaU || i2 == 0 || i2 == theNbDeltaV); + theBnd.Add(TP); + ++Index; + } + } +} + +//! Initialize polyhedron with explicit UV parameter arrays. +//! @tparam SurfaceType Type of surface +//! @tparam SurfaceTool Tool class providing surface operations +//! @param[in] theSurface The surface to discretize +//! @param[in] theUpars Array of U parameters +//! @param[in] theVpars Array of V parameters +//! @param[in] theNbDeltaU Number of U subdivisions +//! @param[in] theNbDeltaV Number of V subdivisions +//! @param[out] thePnts Array of sampled points +//! @param[out] theU Array of U parameters +//! @param[out] theV Array of V parameters +//! @param[out] theIsOnBounds Array of boundary flags +//! @param[in,out] theBnd Bounding box to update +template +void InitWithParams(const SurfaceType& theSurface, + const TColStd_Array1OfReal& theUpars, + const TColStd_Array1OfReal& theVpars, + const int theNbDeltaU, + const int theNbDeltaV, + gp_Pnt* thePnts, + double* theU, + double* theV, + Standard_Boolean* theIsOnBounds, + Bnd_Box& theBnd) +{ + const int i0 = theUpars.Lower(); + const int j0 = theVpars.Lower(); + int Index = 1; + + for (int i1 = 0; i1 <= theNbDeltaU; ++i1) + { + const double U = theUpars(i1 + i0); + for (int i2 = 0; i2 <= theNbDeltaV; ++i2) + { + const double V = theVpars(i2 + j0); + gp_Pnt TP; + SurfaceTool::D0(theSurface, U, V, TP); + thePnts[Index] = TP; + theU[Index] = U; + theV[Index] = V; + theIsOnBounds[Index] = (i1 == 0 || i1 == theNbDeltaU || i2 == 0 || i2 == theNbDeltaV); + theBnd.Add(TP); + ++Index; + } + } +} + +//! Calculate deflection on a single triangle. +//! @tparam SurfaceType Type of surface +//! @tparam SurfaceTool Tool class providing surface operations +//! @param[in] theSurface The surface +//! @param[in] theP1 First vertex point +//! @param[in] theP2 Second vertex point +//! @param[in] theP3 Third vertex point +//! @param[in] theU1 U parameter at first vertex +//! @param[in] theV1 V parameter at first vertex +//! @param[in] theU2 U parameter at second vertex +//! @param[in] theV2 V parameter at second vertex +//! @param[in] theU3 U parameter at third vertex +//! @param[in] theV3 V parameter at third vertex +//! @return Deflection value (distance from triangle center to surface) +template +double DeflectionOnTriangle(const SurfaceType& theSurface, + const gp_Pnt& theP1, + const gp_Pnt& theP2, + const gp_Pnt& theP3, + const double theU1, + const double theV1, + const double theU2, + const double theV2, + const double theU3, + const double theV3) +{ + // Check for degenerate triangles + if (theP1.SquareDistance(theP2) <= THE_MIN_EDGE_LENGTH_SQUARED) + return 0.0; + if (theP1.SquareDistance(theP3) <= THE_MIN_EDGE_LENGTH_SQUARED) + return 0.0; + if (theP2.SquareDistance(theP3) <= THE_MIN_EDGE_LENGTH_SQUARED) + return 0.0; + + // Compute normal vector + const gp_XYZ XYZ1 = theP2.XYZ() - theP1.XYZ(); + const gp_XYZ XYZ2 = theP3.XYZ() - theP2.XYZ(); + const gp_XYZ XYZ3 = theP1.XYZ() - theP3.XYZ(); + gp_Vec NormalVector((XYZ1 ^ XYZ2) + (XYZ2 ^ XYZ3) + (XYZ3 ^ XYZ1)); + + const double aNormLen = NormalVector.Magnitude(); + if (aNormLen < gp::Resolution()) + return 0.0; + + NormalVector.Divide(aNormLen); + + // Calculate center point on surface + const double u = (theU1 + theU2 + theU3) / 3.0; + const double v = (theV1 + theV2 + theV3) / 3.0; + const gp_Pnt P = SurfaceTool::Value(theSurface, u, v); + + // Return distance from center to triangle plane + const gp_Vec P1P(theP1, P); + return std::abs(P1P.Dot(NormalVector)); +} + +//! Compute border deflection for a boundary isoline. +//! @tparam SurfaceType Type of surface +//! @tparam SurfaceTool Tool class providing surface operations +//! @param[in] theSurface The surface +//! @param[in] theParameter Fixed parameter value (U or V depending on isUIso) +//! @param[in] thePMin Start of varying parameter range +//! @param[in] thePMax End of varying parameter range +//! @param[in] theIsUIso True if this is a U-isoline, false for V-isoline +//! @param[in] theNbSamples Number of samples along the boundary +//! @return Maximum deflection along the border +template +double ComputeBorderDeflection(const SurfaceType& theSurface, + const double theParameter, + const double thePMin, + const double thePMax, + const bool theIsUIso, + const int theNbSamples) +{ + const double aDelta = (thePMax - thePMin) / theNbSamples; + double aPar = thePMin; + double aDeflection = RealFirst(); + + for (int i = 0; i <= theNbSamples; ++i, aPar += aDelta) + { + gp_XYZ aP1, aP2, aPParMid; + + if (theIsUIso) + { + aP1 = SurfaceTool::Value(theSurface, theParameter, aPar).XYZ(); + aP2 = SurfaceTool::Value(theSurface, theParameter, aPar + aDelta).XYZ(); + aPParMid = SurfaceTool::Value(theSurface, theParameter, aPar + aDelta / 2.0).XYZ(); + } + else + { + aP1 = SurfaceTool::Value(theSurface, aPar, theParameter).XYZ(); + aP2 = SurfaceTool::Value(theSurface, aPar + aDelta, theParameter).XYZ(); + aPParMid = SurfaceTool::Value(theSurface, aPar + aDelta / 2.0, theParameter).XYZ(); + } + + const gp_XYZ aPMid = (aP2 + aP1) / 2.0; + const double aDist = (aPMid - aPParMid).Modulus(); + + if (aDist > aDeflection) + aDeflection = aDist; + } + + return aDeflection; +} + +} // namespace IntCurveSurface_PolyhedronUtils + +#endif // IntCurveSurface_PolyhedronUtils_pxx_HeaderFile diff --git a/src/ModelingAlgorithms/TKGeomAlgo/IntCurveSurface/IntCurveSurface_QuadricCurveExactInter.gxx b/src/ModelingAlgorithms/TKGeomAlgo/IntCurveSurface/IntCurveSurface_QuadricCurveExactInter.gxx deleted file mode 100644 index df11bd283c..0000000000 --- a/src/ModelingAlgorithms/TKGeomAlgo/IntCurveSurface/IntCurveSurface_QuadricCurveExactInter.gxx +++ /dev/null @@ -1,150 +0,0 @@ -// Created on: 1993-08-18 -// Created by: Laurent BUCHARD -// Copyright (c) 1993-1999 Matra Datavision -// Copyright (c) 1999-2014 OPEN CASCADE SAS -// -// This file is part of Open CASCADE Technology software library. -// -// This library is free software; you can redistribute it and/or modify it under -// the terms of the GNU Lesser General Public License version 2.1 as published -// by the Free Software Foundation, with special exception defined in the file -// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT -// distribution for complete text of the license and disclaimer of any warranty. -// -// Alternatively, this file may be used under the terms of Open CASCADE -// commercial license or contractual agreement. - -// Modified by skv - Wed Jun 16 17:36:47 2004 OCC6001 - -#include -#include -#include -#include -#include - -#define EPSX 0.00000000000001 -#define EPSDIST 0.00000001 -#define EPSNUL 0.00000001 - -//================================================================================================= - -IntCurveSurface_QuadricCurveExactInter::IntCurveSurface_QuadricCurveExactInter(const TheSurface& S, - const TheCurve& C) - : nbpnts(-1), - nbintv(-1) -{ - GeomAbs_SurfaceType QuadricType = TheSurfaceTool::GetType(S); - IntSurf_Quadric Quadric; - switch (QuadricType) - { - case GeomAbs_Plane: { - Quadric.SetValue(TheSurfaceTool::Plane(S)); - break; - } - case GeomAbs_Cylinder: { - Quadric.SetValue(TheSurfaceTool::Cylinder(S)); - break; - } - case GeomAbs_Cone: { - Quadric.SetValue(TheSurfaceTool::Cone(S)); - break; - } - case GeomAbs_Sphere: { - Quadric.SetValue(TheSurfaceTool::Sphere(S)); - break; - } - default: { - // cout<<" Probleme Sur le Type de Surface dans IntCurveSurface_Inter::InternalPerform - // "< nbIntervals) - { - nbpnts = pnts.Length(); - nbintv = intv.Length() / 2; - } - // Modified by skv - Wed Jun 16 17:36:47 2004 OCC6001 End -} - -//================================================================================================= - -Standard_Boolean IntCurveSurface_QuadricCurveExactInter::IsDone() const -{ - return (nbpnts != -1); -} - -//================================================================================================= - -Standard_Integer IntCurveSurface_QuadricCurveExactInter::NbRoots() const -{ - return (nbpnts); -} - -//================================================================================================= - -Standard_Integer IntCurveSurface_QuadricCurveExactInter::NbIntervals() const -{ - return (nbintv); -} - -//================================================================================================= - -Standard_Real IntCurveSurface_QuadricCurveExactInter::Root(const Standard_Integer Index) const -{ - return (pnts(Index)); -} - -//================================================================================================= - -void IntCurveSurface_QuadricCurveExactInter::Intervals(const Standard_Integer Index, - Standard_Real& a, - Standard_Real& b) const -{ - Standard_Integer Index2 = Index + Index - 1; - a = intv(Index2); - b = intv(Index2 + 1); -} diff --git a/src/ModelingAlgorithms/TKGeomAlgo/IntCurveSurface/IntCurveSurface_QuadricCurveExactInterUtils.pxx b/src/ModelingAlgorithms/TKGeomAlgo/IntCurveSurface/IntCurveSurface_QuadricCurveExactInterUtils.pxx new file mode 100644 index 0000000000..34cfd8fc33 --- /dev/null +++ b/src/ModelingAlgorithms/TKGeomAlgo/IntCurveSurface/IntCurveSurface_QuadricCurveExactInterUtils.pxx @@ -0,0 +1,134 @@ +// Copyright (c) 1993-1999 Matra Datavision +// Copyright (c) 1999-2014 OPEN CASCADE SAS +// +// This file is part of Open CASCADE Technology software library. +// +// This library is free software; you can redistribute it and/or modify it under +// the terms of the GNU Lesser General Public License version 2.1 as published +// by the Free Software Foundation, with special exception defined in the file +// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT +// distribution for complete text of the license and disclaimer of any warranty. +// +// Alternatively, this file may be used under the terms of Open CASCADE +// commercial license or contractual agreement. + +#ifndef IntCurveSurface_QuadricCurveExactInterUtils_HeaderFile +#define IntCurveSurface_QuadricCurveExactInterUtils_HeaderFile + +#include +#include +#include +#include +#include +#include + +namespace IntCurveSurface_QuadricCurveExactInterUtils +{ + +//! Tolerance values for root finding +constexpr double EPSX = 0.00000000000001; +constexpr double EPSDIST = 0.00000001; +constexpr double EPSNUL = 0.00000001; + +//! Performs intersection of a curve with a quadric surface. +//! @tparam SurfaceType The surface type (Handle(Adaptor3d_Surface) or Standard_Address) +//! @tparam SurfaceTool The surface tool class +//! @tparam CurveType The curve type (Handle(Adaptor3d_Curve) or gp_Lin) +//! @tparam CurveTool The curve tool class +//! @tparam QuadCurvFuncType The quadric curve function class +//! @param theSurface [in] The quadric surface +//! @param theCurve [in] The curve to intersect +//! @param thePnts [out] Sequence of intersection parameter values (roots) +//! @param theIntv [out] Sequence of interval boundaries (pairs of start/end) +//! @param theNbPnts [out] Number of intersection points (-1 if failed) +//! @param theNbIntv [out] Number of intersection intervals (-1 if failed) +template +void PerformIntersection(const SurfaceType& theSurface, + const CurveType& theCurve, + TColStd_SequenceOfReal& thePnts, + TColStd_SequenceOfReal& theIntv, + int& theNbPnts, + int& theNbIntv) +{ + theNbPnts = -1; + theNbIntv = -1; + + GeomAbs_SurfaceType aQuadricType = SurfaceTool::GetType(theSurface); + IntSurf_Quadric aQuadric; + + switch (aQuadricType) + { + case GeomAbs_Plane: { + aQuadric.SetValue(SurfaceTool::Plane(theSurface)); + break; + } + case GeomAbs_Cylinder: { + aQuadric.SetValue(SurfaceTool::Cylinder(theSurface)); + break; + } + case GeomAbs_Cone: { + aQuadric.SetValue(SurfaceTool::Cone(theSurface)); + break; + } + case GeomAbs_Sphere: { + aQuadric.SetValue(SurfaceTool::Sphere(theSurface)); + break; + } + default: { + break; + } + } + + int aNbIntervals = CurveTool::NbIntervals(theCurve, GeomAbs_C1); + TColStd_Array1OfReal anIntervals(1, aNbIntervals + 1); + int ii; + + CurveTool::Intervals(theCurve, anIntervals, GeomAbs_C1); + + for (ii = 1; ii <= aNbIntervals; ii++) + { + double U1 = anIntervals.Value(ii); + double U2 = anIntervals.Value(ii + 1); + + math_FunctionSample aSample(U1, U2, CurveTool::NbSamples(theCurve, U1, U2)); + QuadCurvFuncType aFunction(aQuadric, theCurve); + math_FunctionAllRoots aRoots(aFunction, aSample, EPSX, EPSDIST, EPSNUL); + + if (aRoots.IsDone()) + { + int aNbPoints = aRoots.NbPoints(); + int aNbRootIntv = aRoots.NbIntervals(); + + for (int i = 1; i <= aNbPoints; i++) + { + thePnts.Append(aRoots.GetPoint(i)); + } + + double a, b; + for (int i = 1; i <= aNbRootIntv; i++) + { + aRoots.GetInterval(i, a, b); + theIntv.Append(a); + theIntv.Append(b); + } + } + else + { + break; + } + } + + if (ii > aNbIntervals) + { + theNbPnts = thePnts.Length(); + theNbIntv = theIntv.Length() / 2; + } +} + +} // namespace IntCurveSurface_QuadricCurveExactInterUtils + +#endif // IntCurveSurface_QuadricCurveExactInterUtils_HeaderFile diff --git a/src/ModelingAlgorithms/TKGeomAlgo/IntCurveSurface/IntCurveSurface_ThePolygonOfHInter.cxx b/src/ModelingAlgorithms/TKGeomAlgo/IntCurveSurface/IntCurveSurface_ThePolygonOfHInter.cxx new file mode 100644 index 0000000000..108bea93a3 --- /dev/null +++ b/src/ModelingAlgorithms/TKGeomAlgo/IntCurveSurface/IntCurveSurface_ThePolygonOfHInter.cxx @@ -0,0 +1,143 @@ +// Created on: 1993-04-07 +// Created by: Laurent BUCHARD +// Copyright (c) 1993-1999 Matra Datavision +// Copyright (c) 1999-2014 OPEN CASCADE SAS +// +// This file is part of Open CASCADE Technology software library. +// +// This library is free software; you can redistribute it and/or modify it under +// the terms of the GNU Lesser General Public License version 2.1 as published +// by the Free Software Foundation, with special exception defined in the file +// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT +// distribution for complete text of the license and disclaimer of any warranty. +// +// Alternatively, this file may be used under the terms of Open CASCADE +// commercial license or contractual agreement. + +#include + +#include +#include +#include +#include "IntCurveSurface_PolygonUtils.pxx" +#include +#include + +//================================================================================================== + +IntCurveSurface_ThePolygonOfHInter::IntCurveSurface_ThePolygonOfHInter( + const Handle(Adaptor3d_Curve)& Curve, + const Standard_Integer NbPnt) + : ThePnts(1, (NbPnt < 5) ? 5 : NbPnt), + ClosedPolygon(Standard_False) +{ + NbPntIn = (NbPnt < 5) ? 5 : NbPnt; + Binf = IntCurveSurface_TheHCurveTool::FirstParameter(Curve); + Bsup = IntCurveSurface_TheHCurveTool::LastParameter(Curve); + Init(Curve); +} + +//================================================================================================== + +IntCurveSurface_ThePolygonOfHInter::IntCurveSurface_ThePolygonOfHInter( + const Handle(Adaptor3d_Curve)& Curve, + const Standard_Real U1, + const Standard_Real U2, + const Standard_Integer NbPnt) + : ThePnts(1, (NbPnt < 5) ? 5 : NbPnt), + ClosedPolygon(Standard_False), + Binf(U1), + Bsup(U2) +{ + NbPntIn = (NbPnt < 5) ? 5 : NbPnt; + Init(Curve); +} + +//================================================================================================== + +IntCurveSurface_ThePolygonOfHInter::IntCurveSurface_ThePolygonOfHInter( + const Handle(Adaptor3d_Curve)& Curve, + const TColStd_Array1OfReal& Upars) + : ThePnts(1, Upars.Length()), + ClosedPolygon(Standard_False), + Binf(Upars(Upars.Lower())), + Bsup(Upars(Upars.Upper())) +{ + NbPntIn = Upars.Length(); + Init(Curve, Upars); +} + +//================================================================================================== + +void IntCurveSurface_ThePolygonOfHInter::Init(const Handle(Adaptor3d_Curve)& Curve) +{ + IntCurveSurface_PolygonUtils::InitUniform( + Curve, + Binf, + Bsup, + NbPntIn, + ThePnts, + TheBnd, + TheDeflection); + ClosedPolygon = Standard_False; +} + +//================================================================================================== + +void IntCurveSurface_ThePolygonOfHInter::Init(const Handle(Adaptor3d_Curve)& Curve, + const TColStd_Array1OfReal& Upars) +{ + IntCurveSurface_PolygonUtils::InitWithParams(Curve, + Upars, + NbPntIn, + ThePnts, + TheBnd, + TheDeflection, + myParams); + ClosedPolygon = Standard_False; +} + +//================================================================================================== + +Standard_Real IntCurveSurface_ThePolygonOfHInter::ApproxParamOnCurve( + const Standard_Integer Index, + const Standard_Real ParamOnLine) const +{ + return IntCurveSurface_PolygonUtils::ApproxParamOnCurve(Index, + ParamOnLine, + Binf, + Bsup, + NbPntIn, + myParams); +} + +//================================================================================================== + +void IntCurveSurface_ThePolygonOfHInter::Dump() const +{ +#if 0 + static Standard_Integer Compteur=0; + char tamp[100]; + Compteur++; + Sprintf(tamp,"Poly%d",Compteur); + std::cout<<" @@@@@@@@@@@ F i c h i e r : "< %f \n",Binf,Bsup); + fprintf(fp,"\npol %d %d %f",Compteur,NbPntIn,TheDeflection); + gp_Pnt p1,p2; + for (Standard_Integer iObje=1; iObje<=NbSegments(); iObje++) { + p1=BeginOfSeg(iObje); + fprintf(fp,"\npnt %d %f %f",Compteur,p1.X(),p1.Y()); + } + p1=EndOfSeg(NbSegments()); + fprintf(fp,"\npnt %d %f %f",Compteur,p1.X(),p1.Y()); + fprintf(fp,"\ndispol %d\n#\n",Compteur); + fclose(fp); +#endif +} diff --git a/src/ModelingAlgorithms/TKGeomAlgo/IntCurveSurface/IntCurveSurface_ThePolygonOfHInter_0.cxx b/src/ModelingAlgorithms/TKGeomAlgo/IntCurveSurface/IntCurveSurface_ThePolygonOfHInter_0.cxx deleted file mode 100644 index fe00a39c9c..0000000000 --- a/src/ModelingAlgorithms/TKGeomAlgo/IntCurveSurface/IntCurveSurface_ThePolygonOfHInter_0.cxx +++ /dev/null @@ -1,31 +0,0 @@ -// Created on: 1993-04-07 -// Created by: Laurent BUCHARD -// Copyright (c) 1993-1999 Matra Datavision -// Copyright (c) 1999-2014 OPEN CASCADE SAS -// -// This file is part of Open CASCADE Technology software library. -// -// This library is free software; you can redistribute it and/or modify it under -// the terms of the GNU Lesser General Public License version 2.1 as published -// by the Free Software Foundation, with special exception defined in the file -// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT -// distribution for complete text of the license and disclaimer of any warranty. -// -// Alternatively, this file may be used under the terms of Open CASCADE -// commercial license or contractual agreement. - -#include - -#include -#include -#include -#include -#include - -#define TheCurve Handle(Adaptor3d_Curve) -#define TheCurve_hxx -#define TheCurveTool IntCurveSurface_TheHCurveTool -#define TheCurveTool_hxx -#define IntCurveSurface_Polygon IntCurveSurface_ThePolygonOfHInter -#define IntCurveSurface_Polygon_hxx -#include diff --git a/src/ModelingAlgorithms/TKGeomAlgo/IntCurveSurface/IntCurveSurface_ThePolygonToolOfHInter_0.cxx b/src/ModelingAlgorithms/TKGeomAlgo/IntCurveSurface/IntCurveSurface_ThePolygonToolOfHInter.cxx similarity index 100% rename from src/ModelingAlgorithms/TKGeomAlgo/IntCurveSurface/IntCurveSurface_ThePolygonToolOfHInter_0.cxx rename to src/ModelingAlgorithms/TKGeomAlgo/IntCurveSurface/IntCurveSurface_ThePolygonToolOfHInter.cxx diff --git a/src/ModelingAlgorithms/TKGeomAlgo/IntCurveSurface/IntCurveSurface_ThePolygonToolOfHInter.hxx b/src/ModelingAlgorithms/TKGeomAlgo/IntCurveSurface/IntCurveSurface_ThePolygonToolOfHInter.hxx index 5b7a024cc5..f2bc27d07c 100644 --- a/src/ModelingAlgorithms/TKGeomAlgo/IntCurveSurface/IntCurveSurface_ThePolygonToolOfHInter.hxx +++ b/src/ModelingAlgorithms/TKGeomAlgo/IntCurveSurface/IntCurveSurface_ThePolygonToolOfHInter.hxx @@ -20,11 +20,9 @@ #include #include -#include -class Standard_OutOfRange; -class gp_Pnt; -class IntCurveSurface_ThePolygonOfHInter; -class Bnd_Box; +#include +#include +#include class IntCurveSurface_ThePolygonToolOfHInter { @@ -32,47 +30,42 @@ public: DEFINE_STANDARD_ALLOC //! Give the bounding box of the polygon. - static const Bnd_Box& Bounding(const IntCurveSurface_ThePolygonOfHInter& thePolygon); + static const Bnd_Box& Bounding(const IntCurveSurface_ThePolygonOfHInter& thePolygon) + { + return thePolygon.Bounding(); + } static Standard_Real DeflectionOverEstimation( - const IntCurveSurface_ThePolygonOfHInter& thePolygon); + const IntCurveSurface_ThePolygonOfHInter& thePolygon) + { + return thePolygon.DeflectionOverEstimation(); + } - static Standard_Boolean Closed(const IntCurveSurface_ThePolygonOfHInter& thePolygon); + static Standard_Boolean Closed(const IntCurveSurface_ThePolygonOfHInter& thePolygon) + { + return thePolygon.Closed(); + } - static Standard_Integer NbSegments(const IntCurveSurface_ThePolygonOfHInter& thePolygon); + static Standard_Integer NbSegments(const IntCurveSurface_ThePolygonOfHInter& thePolygon) + { + return thePolygon.NbSegments(); + } //! Give the point of range Index in the Polygon. static const gp_Pnt& BeginOfSeg(const IntCurveSurface_ThePolygonOfHInter& thePolygon, - const Standard_Integer Index); + const Standard_Integer Index) + { + return thePolygon.BeginOfSeg(Index); + } //! Give the point of range Index in the Polygon. static const gp_Pnt& EndOfSeg(const IntCurveSurface_ThePolygonOfHInter& thePolygon, - const Standard_Integer Index); + const Standard_Integer Index) + { + return thePolygon.EndOfSeg(Index); + } Standard_EXPORT static void Dump(const IntCurveSurface_ThePolygonOfHInter& thePolygon); - -protected: -private: }; -#define ThePoint gp_Pnt -#define ThePoint_hxx -#define ThePolygon IntCurveSurface_ThePolygonOfHInter -#define ThePolygon_hxx -#define TheBoundingBox Bnd_Box -#define TheBoundingBox_hxx -#define IntCurveSurface_PolygonTool IntCurveSurface_ThePolygonToolOfHInter -#define IntCurveSurface_PolygonTool_hxx - -#include - -#undef ThePoint -#undef ThePoint_hxx -#undef ThePolygon -#undef ThePolygon_hxx -#undef TheBoundingBox -#undef TheBoundingBox_hxx -#undef IntCurveSurface_PolygonTool -#undef IntCurveSurface_PolygonTool_hxx - #endif // _IntCurveSurface_ThePolygonToolOfHInter_HeaderFile diff --git a/src/ModelingAlgorithms/TKGeomAlgo/IntCurveSurface/IntCurveSurface_ThePolyhedronOfHInter.cxx b/src/ModelingAlgorithms/TKGeomAlgo/IntCurveSurface/IntCurveSurface_ThePolyhedronOfHInter.cxx new file mode 100644 index 0000000000..f87379fab6 --- /dev/null +++ b/src/ModelingAlgorithms/TKGeomAlgo/IntCurveSurface/IntCurveSurface_ThePolyhedronOfHInter.cxx @@ -0,0 +1,786 @@ +// Created on: 1993-04-07 +// Created by: Laurent BUCHARD +// Copyright (c) 1993-1999 Matra Datavision +// Copyright (c) 1999-2014 OPEN CASCADE SAS +// +// This file is part of Open CASCADE Technology software library. +// +// This library is free software; you can redistribute it and/or modify it under +// the terms of the GNU Lesser General Public License version 2.1 as published +// by the Free Software Foundation, with special exception defined in the file +// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT +// distribution for complete text of the license and disclaimer of any warranty. +// +// Alternatively, this file may be used under the terms of Open CASCADE +// commercial license or contractual agreement. + +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "IntCurveSurface_PolyhedronUtils.pxx" + +#define LONGUEUR_MINI_EDGE_TRIANGLE 1e-15 + +//================================================================================================== + +IntCurveSurface_ThePolyhedronOfHInter::IntCurveSurface_ThePolyhedronOfHInter( + const Handle(Adaptor3d_Surface)& Surface, + const Standard_Integer nbdU, + const Standard_Integer nbdV, + const Standard_Real u1, + const Standard_Real v1, + const Standard_Real u2, + const Standard_Real v2) + : nbdeltaU((nbdU < 3) ? 3 : nbdU), + nbdeltaV((nbdV < 3) ? 3 : nbdV), + TheDeflection(Epsilon(100.)), + C_MyPnts(NULL), + C_MyU(NULL), + C_MyV(NULL), + C_MyIsOnBounds(NULL) +{ + Standard_Integer t = (nbdeltaU + 1) * (nbdeltaV + 1) + 1; + C_MyPnts = new gp_Pnt[t]; + C_MyU = new Standard_Real[t]; + C_MyV = new Standard_Real[t]; + C_MyIsOnBounds = new Standard_Boolean[t]; + Init(Surface, u1, v1, u2, v2); +} + +//================================================================================================== + +IntCurveSurface_ThePolyhedronOfHInter::IntCurveSurface_ThePolyhedronOfHInter( + const Handle(Adaptor3d_Surface)& Surface, + const TColStd_Array1OfReal& Upars, + const TColStd_Array1OfReal& Vpars) + : nbdeltaU(Upars.Length() - 1), + nbdeltaV(Vpars.Length() - 1), + TheDeflection(Epsilon(100.)), + C_MyPnts(NULL), + C_MyU(NULL), + C_MyV(NULL), + C_MyIsOnBounds(NULL) +{ + Standard_Integer t = (nbdeltaU + 1) * (nbdeltaV + 1) + 1; + C_MyPnts = new gp_Pnt[t]; + C_MyU = new Standard_Real[t]; + C_MyV = new Standard_Real[t]; + C_MyIsOnBounds = new Standard_Boolean[t]; + Init(Surface, Upars, Vpars); +} + +//================================================================================================== + +void IntCurveSurface_ThePolyhedronOfHInter::Destroy() +{ + gp_Pnt* CMyPnts = (gp_Pnt*)C_MyPnts; + if (C_MyPnts) + delete[] CMyPnts; + Standard_Real* CMyU = (Standard_Real*)C_MyU; + if (C_MyU) + delete[] CMyU; + Standard_Real* CMyV = (Standard_Real*)C_MyV; + if (C_MyV) + delete[] CMyV; + Standard_Boolean* CMyIsOnBounds = (Standard_Boolean*)C_MyIsOnBounds; + if (C_MyIsOnBounds) + delete[] CMyIsOnBounds; + + C_MyPnts = C_MyU = C_MyV = C_MyIsOnBounds = NULL; +} + +//================================================================================================== + +void IntCurveSurface_ThePolyhedronOfHInter::Init(const Handle(Adaptor3d_Surface)& Surface, + const Standard_Real U0, + const Standard_Real V0, + const Standard_Real U1, + const Standard_Real V1) +{ + IntCurveSurface_PolyhedronUtils::InitUniform( + Surface, + U0, + V0, + U1, + V1, + nbdeltaU, + nbdeltaV, + (gp_Pnt*)C_MyPnts, + (Standard_Real*)C_MyU, + (Standard_Real*)C_MyV, + (Standard_Boolean*)C_MyIsOnBounds, + TheBnd); + + // Calculate triangle deflections + Standard_Real tol = 0.0; + Standard_Integer nbtriangles = NbTriangles(); + for (Standard_Integer i1 = 1; i1 <= nbtriangles; i1++) + { + Standard_Real tol1 = DeflectionOnTriangle(Surface, i1); + if (tol1 > tol) + tol = tol1; + } + + DeflectionOverEstimation(tol * 1.2); + FillBounding(); + + // Compute border deflection + TheBorderDeflection = RealFirst(); + Standard_Real aDeflection; + + aDeflection = ComputeBorderDeflection(Surface, U0, V0, V1, Standard_True); + if (aDeflection > TheBorderDeflection) + TheBorderDeflection = aDeflection; + + aDeflection = ComputeBorderDeflection(Surface, U1, V0, V1, Standard_True); + if (aDeflection > TheBorderDeflection) + TheBorderDeflection = aDeflection; + + aDeflection = ComputeBorderDeflection(Surface, V0, U0, U1, Standard_False); + if (aDeflection > TheBorderDeflection) + TheBorderDeflection = aDeflection; + + aDeflection = ComputeBorderDeflection(Surface, V1, U0, U1, Standard_False); + if (aDeflection > TheBorderDeflection) + TheBorderDeflection = aDeflection; +} + +//================================================================================================== + +void IntCurveSurface_ThePolyhedronOfHInter::Init(const Handle(Adaptor3d_Surface)& Surface, + const TColStd_Array1OfReal& Upars, + const TColStd_Array1OfReal& Vpars) +{ + IntCurveSurface_PolyhedronUtils::InitWithParams( + Surface, + Upars, + Vpars, + nbdeltaU, + nbdeltaV, + (gp_Pnt*)C_MyPnts, + (Standard_Real*)C_MyU, + (Standard_Real*)C_MyV, + (Standard_Boolean*)C_MyIsOnBounds, + TheBnd); + + // Calculate triangle deflections + Standard_Real tol = 0.0; + Standard_Integer nbtriangles = NbTriangles(); + for (Standard_Integer i1 = 1; i1 <= nbtriangles; i1++) + { + Standard_Real tol1 = DeflectionOnTriangle(Surface, i1); + if (tol1 > tol) + tol = tol1; + } + + DeflectionOverEstimation(tol * 1.2); + FillBounding(); + + // Compute border deflection + TheBorderDeflection = RealFirst(); + Standard_Integer i0 = Upars.Lower(); + Standard_Integer j0 = Vpars.Lower(); + Standard_Real U0 = Upars(i0); + Standard_Real V0 = Vpars(j0); + Standard_Real U1 = Upars(Upars.Upper()); + Standard_Real V1 = Vpars(Vpars.Upper()); + Standard_Real aDeflection; + + aDeflection = ComputeBorderDeflection(Surface, U0, V0, V1, Standard_True); + if (aDeflection > TheBorderDeflection) + TheBorderDeflection = aDeflection; + + aDeflection = ComputeBorderDeflection(Surface, U1, V0, V1, Standard_True); + if (aDeflection > TheBorderDeflection) + TheBorderDeflection = aDeflection; + + aDeflection = ComputeBorderDeflection(Surface, V0, U0, U1, Standard_False); + if (aDeflection > TheBorderDeflection) + TheBorderDeflection = aDeflection; + + aDeflection = ComputeBorderDeflection(Surface, V1, U0, U1, Standard_False); + if (aDeflection > TheBorderDeflection) + TheBorderDeflection = aDeflection; +} + +//================================================================================================== + +Standard_Real IntCurveSurface_ThePolyhedronOfHInter::DeflectionOnTriangle( + const Handle(Adaptor3d_Surface)& Surface, + const Standard_Integer Triang) const +{ + Standard_Integer i1, i2, i3; + Triangle(Triang, i1, i2, i3); + + Standard_Real u1, v1, u2, v2, u3, v3; + gp_Pnt P1 = Point(i1, u1, v1); + gp_Pnt P2 = Point(i2, u2, v2); + gp_Pnt P3 = Point(i3, u3, v3); + + return IntCurveSurface_PolyhedronUtils::DeflectionOnTriangle< + Handle(Adaptor3d_Surface), + Adaptor3d_HSurfaceTool>(Surface, P1, P2, P3, u1, v1, u2, v2, u3, v3); +} + +//================================================================================================== + +Standard_Real IntCurveSurface_ThePolyhedronOfHInter::ComputeBorderDeflection( + const Handle(Adaptor3d_Surface)& Surface, + const Standard_Real Parameter, + const Standard_Real PMin, + const Standard_Real PMax, + const Standard_Boolean isUIso) const +{ + Standard_Integer aNbSamples = isUIso ? nbdeltaV : nbdeltaU; + + return IntCurveSurface_PolyhedronUtils::ComputeBorderDeflection( + Surface, + Parameter, + PMin, + PMax, + isUIso, + aNbSamples); +} + +//================================================================================================== + +void IntCurveSurface_ThePolyhedronOfHInter::Parameters(const Standard_Integer Index, + Standard_Real& U, + Standard_Real& V) const +{ + Standard_Real* CMyU = (Standard_Real*)C_MyU; + U = CMyU[Index]; + Standard_Real* CMyV = (Standard_Real*)C_MyV; + V = CMyV[Index]; +} + +//================================================================================================== + +void IntCurveSurface_ThePolyhedronOfHInter::DeflectionOverEstimation(const Standard_Real flec) +{ + if (flec < 0.0001) + { + TheDeflection = 0.0001; + TheBnd.Enlarge(0.0001); + } + else + { + TheDeflection = flec; + TheBnd.Enlarge(flec); + } +} + +//================================================================================================== + +Standard_Real IntCurveSurface_ThePolyhedronOfHInter::DeflectionOverEstimation() const +{ + return TheDeflection; +} + +//================================================================================================== + +const Bnd_Box& IntCurveSurface_ThePolyhedronOfHInter::Bounding() const +{ + return TheBnd; +} + +//================================================================================================== + +void IntCurveSurface_ThePolyhedronOfHInter::FillBounding() +{ + TheComponentsBnd = new Bnd_HArray1OfBox(1, NbTriangles()); + Bnd_Box Boite; + Standard_Integer np1, np2, np3; + Standard_Integer nbtriangles = NbTriangles(); + for (Standard_Integer iTri = 1; iTri <= nbtriangles; iTri++) + { + Triangle(iTri, np1, np2, np3); + gp_Pnt p1(Point(np1)); + gp_Pnt p2(Point(np2)); + gp_Pnt p3(Point(np3)); + Boite.SetVoid(); + if (p1.SquareDistance(p2) > LONGUEUR_MINI_EDGE_TRIANGLE) + { + if (p1.SquareDistance(p3) > LONGUEUR_MINI_EDGE_TRIANGLE) + { + if (p2.SquareDistance(p3) > LONGUEUR_MINI_EDGE_TRIANGLE) + { + Boite.Add(p1); + Boite.Add(p2); + Boite.Add(p3); + Boite.Enlarge(TheDeflection); + } + } + } + Boite.Enlarge(TheDeflection); + TheComponentsBnd->SetValue(iTri, Boite); + } +} + +//================================================================================================== + +const Handle(Bnd_HArray1OfBox)& IntCurveSurface_ThePolyhedronOfHInter::ComponentsBounding() const +{ + return TheComponentsBnd; +} + +//================================================================================================== + +Standard_Integer IntCurveSurface_ThePolyhedronOfHInter::NbTriangles() const +{ + return nbdeltaU * nbdeltaV * 2; +} + +//================================================================================================== + +Standard_Integer IntCurveSurface_ThePolyhedronOfHInter::NbPoints() const +{ + return (nbdeltaU + 1) * (nbdeltaV + 1); +} + +//================================================================================================== + +Standard_Integer IntCurveSurface_ThePolyhedronOfHInter::TriConnex(const Standard_Integer Triang, + const Standard_Integer Pivot, + const Standard_Integer Pedge, + Standard_Integer& TriCon, + Standard_Integer& OtherP) const +{ + Standard_Integer Pivotm1 = Pivot - 1; + Standard_Integer nbdeltaVp1 = nbdeltaV + 1; + Standard_Integer nbdeltaVm2 = nbdeltaV + nbdeltaV; + + Standard_Integer ligP = Pivotm1 / nbdeltaVp1; + Standard_Integer colP = Pivotm1 - ligP * nbdeltaVp1; + + Standard_Integer ligE = 0, colE = 0, typE = 0; + if (Pedge != 0) + { + ligE = (Pedge - 1) / nbdeltaVp1; + colE = (Pedge - 1) - (ligE * nbdeltaVp1); + if (ligP == ligE) + typE = 1; + else if (colP == colE) + typE = 2; + else + typE = 3; + } + + Standard_Integer linT = 0, colT = 0; + Standard_Integer linO = 0, colO = 0; + Standard_Integer t = 0, tt = 0; + + if (Triang != 0) + { + t = (Triang - 1) / nbdeltaVm2; + tt = (Triang - 1) - t * nbdeltaVm2; + linT = 1 + t; + colT = 1 + tt; + if (typE == 0) + { + if (ligP == linT) + { + ligE = ligP - 1; + colE = colP - 1; + typE = 3; + } + else + { + if (colT == ligP + ligP) + { + ligE = ligP; + colE = colP - 1; + typE = 1; + } + else + { + ligE = ligP + 1; + colE = colP + 1; + typE = 3; + } + } + } + switch (typE) + { + case 1: + if (linT == ligP) + { + linT++; + linO = ligP + 1; + colO = (colP > colE) ? colP : colE; + } + else + { + linT--; + linO = ligP - 1; + colO = (colP < colE) ? colP : colE; + } + break; + case 2: + if (colT == (colP + colP)) + { + colT++; + linO = (ligP > ligE) ? ligP : ligE; + colO = colP + 1; + } + else + { + colT--; + linO = (ligP < ligE) ? ligP : ligE; + colO = colP - 1; + } + break; + case 3: + if ((colT & 1) == 0) + { + colT--; + linO = (ligP > ligE) ? ligP : ligE; + colO = (colP < colE) ? colP : colE; + } + else + { + colT++; + linO = (ligP < ligE) ? ligP : ligE; + colO = (colP > colE) ? colP : colE; + } + break; + } + } + else + { + if (Pedge == 0) + { + linT = (1 > ligP) ? 1 : ligP; + colT = (1 > (colP + colP)) ? 1 : (colP + colP); + if (ligP == 0) + linO = ligP + 1; + else + linO = ligP - 1; + colO = colP; + } + else + { + switch (typE) + { + case 1: + linT = ligP + 1; + colT = (colP > colE) ? colP : colE; + colT += colT; + linO = ligP + 1; + colO = (colP > colE) ? colP : colE; + break; + case 2: + linT = (ligP > ligE) ? ligP : ligE; + colT = colP + colP; + linO = (ligP < ligE) ? ligP : ligE; + colO = colP - 1; + break; + case 3: + linT = (ligP > ligE) ? ligP : ligE; + colT = colP + colE; + linO = (ligP > ligE) ? ligP : ligE; + colO = (colP < colE) ? colP : colE; + break; + } + } + } + + TriCon = (linT - 1) * nbdeltaVm2 + colT; + + if (linT < 1) + { + linO = 0; + colO = colP + colP - colE; + if (colO < 0) + { + colO = 0; + linO = 1; + } + else if (colO > nbdeltaV) + { + colO = nbdeltaV; + linO = 1; + } + TriCon = 0; + } + else if (linT > nbdeltaU) + { + linO = nbdeltaU; + colO = colP + colP - colE; + if (colO < 0) + { + colO = 0; + linO = nbdeltaU - 1; + } + else if (colO > nbdeltaV) + { + colO = nbdeltaV; + linO = nbdeltaU - 1; + } + TriCon = 0; + } + + if (colT < 1) + { + colO = 0; + linO = ligP + ligP - ligE; + if (linO < 0) + { + linO = 0; + colO = 1; + } + else if (linO > nbdeltaU) + { + linO = nbdeltaU; + colO = 1; + } + TriCon = 0; + } + else if (colT > nbdeltaV) + { + colO = nbdeltaV; + linO = ligP + ligP - ligE; + if (linO < 0) + { + linO = 0; + colO = nbdeltaV - 1; + } + else if (linO > nbdeltaU) + { + linO = nbdeltaU; + colO = nbdeltaV - 1; + } + TriCon = 0; + } + + OtherP = linO * nbdeltaVp1 + colO + 1; + + return TriCon; +} + +//================================================================================================== + +void IntCurveSurface_ThePolyhedronOfHInter::PlaneEquation(const Standard_Integer Triang, + gp_XYZ& NormalVector, + Standard_Real& PolarDistance) const +{ + Standard_Integer i1, i2, i3; + Triangle(Triang, i1, i2, i3); + + gp_XYZ Pointi1(Point(i1).XYZ()); + gp_XYZ Pointi2(Point(i2).XYZ()); + gp_XYZ Pointi3(Point(i3).XYZ()); + + gp_XYZ v1 = Pointi2 - Pointi1; + gp_XYZ v2 = Pointi3 - Pointi2; + gp_XYZ v3 = Pointi1 - Pointi3; + + if (v1.SquareModulus() <= LONGUEUR_MINI_EDGE_TRIANGLE) + { + NormalVector.SetCoord(1.0, 0.0, 0.0); + return; + } + if (v2.SquareModulus() <= LONGUEUR_MINI_EDGE_TRIANGLE) + { + NormalVector.SetCoord(1.0, 0.0, 0.0); + return; + } + if (v3.SquareModulus() <= LONGUEUR_MINI_EDGE_TRIANGLE) + { + NormalVector.SetCoord(1.0, 0.0, 0.0); + return; + } + + NormalVector = (v1 ^ v2) + (v2 ^ v3) + (v3 ^ v1); + Standard_Real aNormLen = NormalVector.Modulus(); + if (aNormLen < gp::Resolution()) + { + PolarDistance = 0.; + } + else + { + NormalVector.Divide(aNormLen); + PolarDistance = NormalVector * Point(i1).XYZ(); + } +} + +//================================================================================================== + +Standard_Boolean IntCurveSurface_ThePolyhedronOfHInter::Contain(const Standard_Integer Triang, + const gp_Pnt& ThePnt) const +{ + Standard_Integer i1, i2, i3; + Triangle(Triang, i1, i2, i3); + gp_XYZ Pointi1(Point(i1).XYZ()); + gp_XYZ Pointi2(Point(i2).XYZ()); + gp_XYZ Pointi3(Point(i3).XYZ()); + + gp_XYZ v1 = (Pointi2 - Pointi1) ^ (ThePnt.XYZ() - Pointi1); + gp_XYZ v2 = (Pointi3 - Pointi2) ^ (ThePnt.XYZ() - Pointi2); + gp_XYZ v3 = (Pointi1 - Pointi3) ^ (ThePnt.XYZ() - Pointi3); + if (v1 * v2 >= 0. && v2 * v3 >= 0. && v3 * v1 >= 0.) + return Standard_True; + else + return Standard_False; +} + +//================================================================================================== + +void IntCurveSurface_ThePolyhedronOfHInter::Dump() const {} + +//================================================================================================== + +void IntCurveSurface_ThePolyhedronOfHInter::Size(Standard_Integer& nbdu, + Standard_Integer& nbdv) const +{ + nbdu = nbdeltaU; + nbdv = nbdeltaV; +} + +//================================================================================================== + +void IntCurveSurface_ThePolyhedronOfHInter::Triangle(const Standard_Integer Index, + Standard_Integer& P1, + Standard_Integer& P2, + Standard_Integer& P3) const +{ + Standard_Integer line = 1 + ((Index - 1) / (nbdeltaV * 2)); + Standard_Integer colon = 1 + ((Index - 1) % (nbdeltaV * 2)); + Standard_Integer colpnt = (colon + 1) / 2; + + P1 = (line - 1) * (nbdeltaV + 1) + colpnt; + P2 = line * (nbdeltaV + 1) + colpnt + ((colon - 1) % 2); + P3 = (line - 1 + (colon % 2)) * (nbdeltaV + 1) + colpnt + 1; +} + +//================================================================================================== + +const gp_Pnt& IntCurveSurface_ThePolyhedronOfHInter::Point(const Standard_Integer Index, + Standard_Real& U, + Standard_Real& V) const +{ + gp_Pnt* CMyPnts = (gp_Pnt*)C_MyPnts; + Standard_Real* CMyU = (Standard_Real*)C_MyU; + Standard_Real* CMyV = (Standard_Real*)C_MyV; + U = CMyU[Index]; + V = CMyV[Index]; + return CMyPnts[Index]; +} + +//================================================================================================== + +const gp_Pnt& IntCurveSurface_ThePolyhedronOfHInter::Point(const Standard_Integer Index) const +{ + gp_Pnt* CMyPnts = (gp_Pnt*)C_MyPnts; + return CMyPnts[Index]; +} + +//================================================================================================== + +void IntCurveSurface_ThePolyhedronOfHInter::Point(const gp_Pnt&, + const Standard_Integer, + const Standard_Integer, + const Standard_Real, + const Standard_Real) +{ + // Should not be called +} + +//================================================================================================== + +void IntCurveSurface_ThePolyhedronOfHInter::Point(const Standard_Integer Index, gp_Pnt& P) const +{ + gp_Pnt* CMyPnts = (gp_Pnt*)C_MyPnts; + P = CMyPnts[Index]; +} + +//================================================================================================== + +Standard_Boolean IntCurveSurface_ThePolyhedronOfHInter::IsOnBound( + const Standard_Integer Index1, + const Standard_Integer Index2) const +{ + Standard_Boolean* CMyIsOnBounds = (Standard_Boolean*)C_MyIsOnBounds; + Standard_Integer aDiff = std::abs(Index1 - Index2); + + if (aDiff != 1 && aDiff != nbdeltaV + 1) + return Standard_False; + + for (Standard_Integer i = 0; i <= nbdeltaU; i++) + { + if ((Index1 == 1 + i * (nbdeltaV + 1)) && (Index2 == Index1 - 1)) + return Standard_False; + + if ((Index1 == (1 + i) * (nbdeltaV + 1)) && (Index2 == Index1 + 1)) + return Standard_False; + } + + return (CMyIsOnBounds[Index1] && CMyIsOnBounds[Index2]); +} + +//================================================================================================== + +void IntCurveSurface_ThePolyhedronOfHInter::UMinSingularity(const Standard_Boolean Sing) +{ + UMinSingular = Sing; +} + +//================================================================================================== + +void IntCurveSurface_ThePolyhedronOfHInter::UMaxSingularity(const Standard_Boolean Sing) +{ + UMaxSingular = Sing; +} + +//================================================================================================== + +void IntCurveSurface_ThePolyhedronOfHInter::VMinSingularity(const Standard_Boolean Sing) +{ + VMinSingular = Sing; +} + +//================================================================================================== + +void IntCurveSurface_ThePolyhedronOfHInter::VMaxSingularity(const Standard_Boolean Sing) +{ + VMaxSingular = Sing; +} + +//================================================================================================== + +Standard_Boolean IntCurveSurface_ThePolyhedronOfHInter::HasUMinSingularity() const +{ + return UMinSingular; +} + +//================================================================================================== + +Standard_Boolean IntCurveSurface_ThePolyhedronOfHInter::HasUMaxSingularity() const +{ + return UMaxSingular; +} + +//================================================================================================== + +Standard_Boolean IntCurveSurface_ThePolyhedronOfHInter::HasVMinSingularity() const +{ + return VMinSingular; +} + +//================================================================================================== + +Standard_Boolean IntCurveSurface_ThePolyhedronOfHInter::HasVMaxSingularity() const +{ + return VMaxSingular; +} diff --git a/src/ModelingAlgorithms/TKGeomAlgo/IntCurveSurface/IntCurveSurface_ThePolyhedronOfHInter.hxx b/src/ModelingAlgorithms/TKGeomAlgo/IntCurveSurface/IntCurveSurface_ThePolyhedronOfHInter.hxx index 2655704bd9..329d39b7d4 100644 --- a/src/ModelingAlgorithms/TKGeomAlgo/IntCurveSurface/IntCurveSurface_ThePolyhedronOfHInter.hxx +++ b/src/ModelingAlgorithms/TKGeomAlgo/IntCurveSurface/IntCurveSurface_ThePolyhedronOfHInter.hxx @@ -148,7 +148,7 @@ public: const Standard_Integer Index2) const; //! This method returns a border deflection. - Standard_Real GetBorderDeflection() const; + Standard_Real GetBorderDeflection() const { return TheBorderDeflection; } Standard_EXPORT void Dump() const; @@ -188,20 +188,4 @@ private: Standard_Address C_MyIsOnBounds; }; -#define ThePSurface Handle(Adaptor3d_Surface) -#define ThePSurface_hxx -#define ThePSurfaceTool Adaptor3d_HSurfaceTool -#define ThePSurfaceTool_hxx -#define IntCurveSurface_Polyhedron IntCurveSurface_ThePolyhedronOfHInter -#define IntCurveSurface_Polyhedron_hxx - -#include - -#undef ThePSurface -#undef ThePSurface_hxx -#undef ThePSurfaceTool -#undef ThePSurfaceTool_hxx -#undef IntCurveSurface_Polyhedron -#undef IntCurveSurface_Polyhedron_hxx - #endif // _IntCurveSurface_ThePolyhedronOfHInter_HeaderFile diff --git a/src/ModelingAlgorithms/TKGeomAlgo/IntCurveSurface/IntCurveSurface_ThePolyhedronOfHInter_0.cxx b/src/ModelingAlgorithms/TKGeomAlgo/IntCurveSurface/IntCurveSurface_ThePolyhedronOfHInter_0.cxx deleted file mode 100644 index 645532d9b8..0000000000 --- a/src/ModelingAlgorithms/TKGeomAlgo/IntCurveSurface/IntCurveSurface_ThePolyhedronOfHInter_0.cxx +++ /dev/null @@ -1,32 +0,0 @@ -// Created on: 1993-04-07 -// Created by: Laurent BUCHARD -// Copyright (c) 1993-1999 Matra Datavision -// Copyright (c) 1999-2014 OPEN CASCADE SAS -// -// This file is part of Open CASCADE Technology software library. -// -// This library is free software; you can redistribute it and/or modify it under -// the terms of the GNU Lesser General Public License version 2.1 as published -// by the Free Software Foundation, with special exception defined in the file -// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT -// distribution for complete text of the license and disclaimer of any warranty. -// -// Alternatively, this file may be used under the terms of Open CASCADE -// commercial license or contractual agreement. - -#include - -#include -#include -#include -#include -#include -#include - -#define ThePSurface Handle(Adaptor3d_Surface) -#define ThePSurface_hxx -#define ThePSurfaceTool Adaptor3d_HSurfaceTool -#define ThePSurfaceTool_hxx -#define IntCurveSurface_Polyhedron IntCurveSurface_ThePolyhedronOfHInter -#define IntCurveSurface_Polyhedron_hxx -#include diff --git a/src/ModelingAlgorithms/TKGeomAlgo/IntCurveSurface/IntCurveSurface_ThePolyhedronToolOfHInter_0.cxx b/src/ModelingAlgorithms/TKGeomAlgo/IntCurveSurface/IntCurveSurface_ThePolyhedronToolOfHInter.cxx similarity index 100% rename from src/ModelingAlgorithms/TKGeomAlgo/IntCurveSurface/IntCurveSurface_ThePolyhedronToolOfHInter_0.cxx rename to src/ModelingAlgorithms/TKGeomAlgo/IntCurveSurface/IntCurveSurface_ThePolyhedronToolOfHInter.cxx diff --git a/src/ModelingAlgorithms/TKGeomAlgo/IntCurveSurface/IntCurveSurface_ThePolyhedronToolOfHInter.hxx b/src/ModelingAlgorithms/TKGeomAlgo/IntCurveSurface/IntCurveSurface_ThePolyhedronToolOfHInter.hxx index 8f3fa7d6f9..2bba705607 100644 --- a/src/ModelingAlgorithms/TKGeomAlgo/IntCurveSurface/IntCurveSurface_ThePolyhedronToolOfHInter.hxx +++ b/src/ModelingAlgorithms/TKGeomAlgo/IntCurveSurface/IntCurveSurface_ThePolyhedronToolOfHInter.hxx @@ -21,12 +21,10 @@ #include #include +#include #include -#include -class Standard_OutOfRange; -class IntCurveSurface_ThePolyhedronOfHInter; -class Bnd_Box; -class gp_Pnt; +#include +#include class IntCurveSurface_ThePolyhedronToolOfHInter { @@ -34,19 +32,31 @@ public: DEFINE_STANDARD_ALLOC //! Give the bounding box of the PolyhedronTool. - static const Bnd_Box& Bounding(const IntCurveSurface_ThePolyhedronOfHInter& thePolyh); + static const Bnd_Box& Bounding(const IntCurveSurface_ThePolyhedronOfHInter& thePolyh) + { + return thePolyh.Bounding(); + } //! Give the array of boxes. The box corresponding //! to the triangle . static const Handle(Bnd_HArray1OfBox)& ComponentsBounding( - const IntCurveSurface_ThePolyhedronOfHInter& thePolyh); + const IntCurveSurface_ThePolyhedronOfHInter& thePolyh) + { + return thePolyh.ComponentsBounding(); + } //! Give the tolerance of the polygon. static Standard_Real DeflectionOverEstimation( - const IntCurveSurface_ThePolyhedronOfHInter& thePolyh); + const IntCurveSurface_ThePolyhedronOfHInter& thePolyh) + { + return thePolyh.DeflectionOverEstimation(); + } //! Give the number of triangles in this polyhedral surface. - static Standard_Integer NbTriangles(const IntCurveSurface_ThePolyhedronOfHInter& thePolyh); + static Standard_Integer NbTriangles(const IntCurveSurface_ThePolyhedronOfHInter& thePolyh) + { + return thePolyh.NbTriangles(); + } //! Give the indices of the 3 points of the triangle of //! address Index in the PolyhedronTool. @@ -54,11 +64,17 @@ public: const Standard_Integer Index, Standard_Integer& P1, Standard_Integer& P2, - Standard_Integer& P3); + Standard_Integer& P3) + { + thePolyh.Triangle(Index, P1, P2, P3); + } //! Give the point of index i in the polyhedral surface. static const gp_Pnt& Point(const IntCurveSurface_ThePolyhedronOfHInter& thePolyh, - const Standard_Integer Index); + const Standard_Integer Index) + { + return thePolyh.Point(Index); + } //! Give the address Tricon of the triangle connexe to //! the triangle of address Triang by the edge Pivot Pedge @@ -71,7 +87,10 @@ public: const Standard_Integer Pivot, const Standard_Integer Pedge, Standard_Integer& TriCon, - Standard_Integer& OtherP); + Standard_Integer& OtherP) + { + return thePolyh.TriConnex(Triang, Pivot, Pedge, TriCon, OtherP); + } //! This method returns true if the edge based on points with //! indices Index1 and Index2 represents a boundary edge. It is @@ -79,27 +98,18 @@ public: //! this edge. static Standard_Boolean IsOnBound(const IntCurveSurface_ThePolyhedronOfHInter& thePolyh, const Standard_Integer Index1, - const Standard_Integer Index2); + const Standard_Integer Index2) + { + return thePolyh.IsOnBound(Index1, Index2); + } //! This method returns a border deflection of the polyhedron. - static Standard_Real GetBorderDeflection(const IntCurveSurface_ThePolyhedronOfHInter& thePolyh); + static Standard_Real GetBorderDeflection(const IntCurveSurface_ThePolyhedronOfHInter& thePolyh) + { + return thePolyh.GetBorderDeflection(); + } Standard_EXPORT static void Dump(const IntCurveSurface_ThePolyhedronOfHInter& thePolyh); - -protected: -private: }; -#define ThePolyhedron IntCurveSurface_ThePolyhedronOfHInter -#define ThePolyhedron_hxx -#define IntCurveSurface_PolyhedronTool IntCurveSurface_ThePolyhedronToolOfHInter -#define IntCurveSurface_PolyhedronTool_hxx - -#include - -#undef ThePolyhedron -#undef ThePolyhedron_hxx -#undef IntCurveSurface_PolyhedronTool -#undef IntCurveSurface_PolyhedronTool_hxx - #endif // _IntCurveSurface_ThePolyhedronToolOfHInter_HeaderFile diff --git a/src/ModelingAlgorithms/TKGeomAlgo/IntCurveSurface/IntCurveSurface_TheQuadCurvExactHInter.cxx b/src/ModelingAlgorithms/TKGeomAlgo/IntCurveSurface/IntCurveSurface_TheQuadCurvExactHInter.cxx new file mode 100644 index 0000000000..195af84e45 --- /dev/null +++ b/src/ModelingAlgorithms/TKGeomAlgo/IntCurveSurface/IntCurveSurface_TheQuadCurvExactHInter.cxx @@ -0,0 +1,80 @@ +// Created on: 1993-04-07 +// Created by: Laurent BUCHARD +// Copyright (c) 1993-1999 Matra Datavision +// Copyright (c) 1999-2014 OPEN CASCADE SAS +// +// This file is part of Open CASCADE Technology software library. +// +// This library is free software; you can redistribute it and/or modify it under +// the terms of the GNU Lesser General Public License version 2.1 as published +// by the Free Software Foundation, with special exception defined in the file +// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT +// distribution for complete text of the license and disclaimer of any warranty. +// +// Alternatively, this file may be used under the terms of Open CASCADE +// commercial license or contractual agreement. + +#include + +#include +#include +#include +#include +#include + +#include "IntCurveSurface_QuadricCurveExactInterUtils.pxx" + +//================================================================================================== + +IntCurveSurface_TheQuadCurvExactHInter::IntCurveSurface_TheQuadCurvExactHInter( + const Handle(Adaptor3d_Surface)& S, + const Handle(Adaptor3d_Curve)& C) + : nbpnts(-1), + nbintv(-1) +{ + IntCurveSurface_QuadricCurveExactInterUtils::PerformIntersection< + Handle(Adaptor3d_Surface), + Adaptor3d_HSurfaceTool, + Handle(Adaptor3d_Curve), + IntCurveSurface_TheHCurveTool, + IntCurveSurface_TheQuadCurvFuncOfTheQuadCurvExactHInter>(S, C, pnts, intv, nbpnts, nbintv); +} + +//================================================================================================== + +Standard_Boolean IntCurveSurface_TheQuadCurvExactHInter::IsDone() const +{ + return (nbpnts != -1); +} + +//================================================================================================== + +Standard_Integer IntCurveSurface_TheQuadCurvExactHInter::NbRoots() const +{ + return nbpnts; +} + +//================================================================================================== + +Standard_Integer IntCurveSurface_TheQuadCurvExactHInter::NbIntervals() const +{ + return nbintv; +} + +//================================================================================================== + +Standard_Real IntCurveSurface_TheQuadCurvExactHInter::Root(const Standard_Integer Index) const +{ + return pnts(Index); +} + +//================================================================================================== + +void IntCurveSurface_TheQuadCurvExactHInter::Intervals(const Standard_Integer Index, + Standard_Real& a, + Standard_Real& b) const +{ + Standard_Integer Index2 = Index + Index - 1; + a = intv(Index2); + b = intv(Index2 + 1); +} diff --git a/src/ModelingAlgorithms/TKGeomAlgo/IntCurveSurface/IntCurveSurface_TheQuadCurvExactHInter_0.cxx b/src/ModelingAlgorithms/TKGeomAlgo/IntCurveSurface/IntCurveSurface_TheQuadCurvExactHInter_0.cxx deleted file mode 100644 index c1c8807aed..0000000000 --- a/src/ModelingAlgorithms/TKGeomAlgo/IntCurveSurface/IntCurveSurface_TheQuadCurvExactHInter_0.cxx +++ /dev/null @@ -1,38 +0,0 @@ -// Created on: 1993-04-07 -// Created by: Laurent BUCHARD -// Copyright (c) 1993-1999 Matra Datavision -// Copyright (c) 1999-2014 OPEN CASCADE SAS -// -// This file is part of Open CASCADE Technology software library. -// -// This library is free software; you can redistribute it and/or modify it under -// the terms of the GNU Lesser General Public License version 2.1 as published -// by the Free Software Foundation, with special exception defined in the file -// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT -// distribution for complete text of the license and disclaimer of any warranty. -// -// Alternatively, this file may be used under the terms of Open CASCADE -// commercial license or contractual agreement. - -#include - -#include -#include -#include -#include -#include - -#define TheSurface Handle(Adaptor3d_Surface) -#define TheSurface_hxx -#define TheSurfaceTool Adaptor3d_HSurfaceTool -#define TheSurfaceTool_hxx -#define TheCurve Handle(Adaptor3d_Curve) -#define TheCurve_hxx -#define TheCurveTool IntCurveSurface_TheHCurveTool -#define TheCurveTool_hxx -#define IntCurveSurface_TheQuadCurvFunc IntCurveSurface_TheQuadCurvFuncOfTheQuadCurvExactHInter -#define IntCurveSurface_TheQuadCurvFunc_hxx \ - -#define IntCurveSurface_QuadricCurveExactInter IntCurveSurface_TheQuadCurvExactHInter -#define IntCurveSurface_QuadricCurveExactInter_hxx -#include diff --git a/src/ModelingAlgorithms/TKGeomAlgo/IntCurveSurface/IntCurveSurface_TheQuadCurvFuncOfTheQuadCurvExactHInter_0.cxx b/src/ModelingAlgorithms/TKGeomAlgo/IntCurveSurface/IntCurveSurface_TheQuadCurvFuncOfTheQuadCurvExactHInter.cxx similarity index 100% rename from src/ModelingAlgorithms/TKGeomAlgo/IntCurveSurface/IntCurveSurface_TheQuadCurvFuncOfTheQuadCurvExactHInter_0.cxx rename to src/ModelingAlgorithms/TKGeomAlgo/IntCurveSurface/IntCurveSurface_TheQuadCurvFuncOfTheQuadCurvExactHInter.cxx diff --git a/src/ModelingAlgorithms/TKHLR/HLRBRep/FILES.cmake b/src/ModelingAlgorithms/TKHLR/HLRBRep/FILES.cmake index 345d4ff155..d33e89dd34 100644 --- a/src/ModelingAlgorithms/TKHLR/HLRBRep/FILES.cmake +++ b/src/ModelingAlgorithms/TKHLR/HLRBRep/FILES.cmake @@ -61,7 +61,7 @@ set(OCCT_HLRBRep_FILES HLRBRep_IntConicCurveOfCInter.hxx HLRBRep_IntConicCurveOfCInter_0.cxx HLRBRep_InterCSurf.hxx - HLRBRep_InterCSurf_0.cxx + HLRBRep_InterCSurf.cxx HLRBRep_InternalAlgo.cxx HLRBRep_InternalAlgo.hxx HLRBRep_Intersector.cxx @@ -115,17 +115,17 @@ set(OCCT_HLRBRep_FILES HLRBRep_ThePolygon2dOfTheIntPCurvePCurveOfCInter.hxx HLRBRep_ThePolygon2dOfTheIntPCurvePCurveOfCInter_0.cxx HLRBRep_ThePolygonOfInterCSurf.hxx - HLRBRep_ThePolygonOfInterCSurf_0.cxx + HLRBRep_ThePolygonOfInterCSurf.cxx HLRBRep_ThePolygonToolOfInterCSurf.hxx HLRBRep_ThePolygonToolOfInterCSurf_0.cxx HLRBRep_ThePolyhedronOfInterCSurf.hxx - HLRBRep_ThePolyhedronOfInterCSurf_0.cxx + HLRBRep_ThePolyhedronOfInterCSurf.cxx HLRBRep_ThePolyhedronToolOfInterCSurf.hxx HLRBRep_ThePolyhedronToolOfInterCSurf_0.cxx HLRBRep_TheProjPCurOfCInter.hxx HLRBRep_TheProjPCurOfCInter_0.cxx HLRBRep_TheQuadCurvExactInterCSurf.hxx - HLRBRep_TheQuadCurvExactInterCSurf_0.cxx + HLRBRep_TheQuadCurvExactInterCSurf.cxx HLRBRep_TheQuadCurvFuncOfTheQuadCurvExactInterCSurf.hxx HLRBRep_TheQuadCurvFuncOfTheQuadCurvExactInterCSurf_0.cxx HLRBRep_VertexList.cxx diff --git a/src/ModelingAlgorithms/TKHLR/HLRBRep/HLRBRep_InterCSurf.cxx b/src/ModelingAlgorithms/TKHLR/HLRBRep/HLRBRep_InterCSurf.cxx new file mode 100644 index 0000000000..97e76fbadf --- /dev/null +++ b/src/ModelingAlgorithms/TKHLR/HLRBRep/HLRBRep_InterCSurf.cxx @@ -0,0 +1,583 @@ +// Created on: 1992-10-14 +// Created by: Christophe MARION +// Copyright (c) 1992-1999 Matra Datavision +// Copyright (c) 1999-2014 OPEN CASCADE SAS +// +// This file is part of Open CASCADE Technology software library. +// +// This library is free software; you can redistribute it and/or modify it under +// the terms of the GNU Lesser General Public License version 2.1 as published +// by the Free Software Foundation, with special exception defined in the file +// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT +// distribution for complete text of the license and disclaimer of any warranty. +// +// Alternatively, this file may be used under the terms of Open CASCADE +// commercial license or contractual agreement. + +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "../../TKGeomAlgo/IntCurveSurface/IntCurveSurface_Inter.pxx" + +// Type aliases for readability +using TheCurve = gp_Lin; +using TheCurveTool = HLRBRep_LineTool; +using TheSurface = Standard_Address; +using TheSurfaceTool = HLRBRep_SurfaceTool; +using ThePolygon = HLRBRep_ThePolygonOfInterCSurf; +using ThePolyhedron = HLRBRep_ThePolyhedronOfInterCSurf; +using TheInterference = HLRBRep_TheInterferenceOfInterCSurf; +using TheCSFunction = HLRBRep_TheCSFunctionOfInterCSurf; +using TheExactInter = HLRBRep_TheExactInterCSurf; +using TheQuadCurvExactInter = HLRBRep_TheQuadCurvExactInterCSurf; + +//================================================================================================== + +HLRBRep_InterCSurf::HLRBRep_InterCSurf() {} + +//================================================================================================== + +void HLRBRep_InterCSurf::DoSurface(const TheSurface& surface, + const Standard_Real u0, + const Standard_Real u1, + const Standard_Real v0, + const Standard_Real v1, + TColgp_Array2OfPnt& pntsOnSurface, + Bnd_Box& boxSurface, + Standard_Real& gap) +{ + IntCurveSurface_InterUtils::DoSurface(surface, + u0, + u1, + v0, + v1, + pntsOnSurface, + boxSurface, + gap); +} + +//================================================================================================== + +void HLRBRep_InterCSurf::DoNewBounds(const TheSurface& surface, + const Standard_Real u0, + const Standard_Real u1, + const Standard_Real v0, + const Standard_Real v1, + const TColgp_Array2OfPnt& pntsOnSurface, + const TColStd_Array1OfReal& X, + const TColStd_Array1OfReal& Y, + const TColStd_Array1OfReal& Z, + TColStd_Array1OfReal& Bounds) +{ + IntCurveSurface_InterUtils::DoNewBounds(surface, + u0, + u1, + v0, + v1, + pntsOnSurface, + X, + Y, + Z, + Bounds); +} + +//================================================================================================== + +void HLRBRep_InterCSurf::Perform(const TheCurve& curve, const TheSurface& surface) +{ + IntCurveSurface_InterImpl::Perform( + curve, + surface, + done, + [this]() { this->ResetFields(); }, + [this](const TheCurve& c, + const TheSurface& s, + Standard_Real u0, + Standard_Real v0, + Standard_Real u1, + Standard_Real v1) { this->Perform(c, s, u0, v0, u1, v1); }); +} + +//================================================================================================== + +void HLRBRep_InterCSurf::Perform(const TheCurve& curve, + const TheSurface& surface, + const Standard_Real U1, + const Standard_Real V1, + const Standard_Real U2, + const Standard_Real V2) +{ + IntCurveSurface_InterImpl:: + PerformBounds( + curve, + surface, + U1, + V1, + U2, + V2, + [this](const auto& conic, + const TheCurve& c, + const TheSurface& s, + Standard_Real u1, + Standard_Real v1, + Standard_Real u2, + Standard_Real v2) { this->PerformConicSurf(conic, c, s, u1, v1, u2, v2); }, + [this](const TheCurve& c, + const ThePolygon& p, + const TheSurface& s, + Standard_Real u1, + Standard_Real v1, + Standard_Real u2, + Standard_Real v2) { this->InternalPerform(c, p, s, u1, v1, u2, v2); }, + [this](const TheCurve& c, const TheSurface& s) { this->InternalPerformCurveQuadric(c, s); }); +} + +//================================================================================================== + +void HLRBRep_InterCSurf::Perform(const TheCurve& curve, + const ThePolygon& polygon, + const TheSurface& surface) +{ + IntCurveSurface_InterImpl:: + PerformPolygon( + curve, + polygon, + surface, + done, + [this]() { this->ResetFields(); }, + [this](const TheCurve& c, const ThePolygon& p, const TheSurface& s, const ThePolyhedron& ph) { + this->Perform(c, p, s, ph); + }); +} + +//================================================================================================== + +void HLRBRep_InterCSurf::Perform(const TheCurve& curve, + const TheSurface& surface, + const ThePolyhedron& polyhedron) +{ + IntCurveSurface_InterImpl::PerformPolyhedron( + curve, + surface, + polyhedron, + done, + [this]() { this->ResetFields(); }, + [this](const TheCurve& c, const ThePolygon& p, const TheSurface& s, const ThePolyhedron& ph) { + this->Perform(c, p, s, ph); + }); +} + +//================================================================================================== + +void HLRBRep_InterCSurf::Perform(const TheCurve& curve, + const ThePolygon& polygon, + const TheSurface& surface, + const ThePolyhedron& polyhedron) +{ + IntCurveSurface_InterImpl::PerformPolygonPolyhedron( + curve, + polygon, + surface, + polyhedron, + done, + [this]() { this->ResetFields(); }, + [this](const TheCurve& c, + const ThePolygon& p, + const TheSurface& s, + const ThePolyhedron& ph, + Standard_Real u1, + Standard_Real v1, + Standard_Real u2, + Standard_Real v2) { this->InternalPerform(c, p, s, ph, u1, v1, u2, v2); }); +} + +//================================================================================================== + +void HLRBRep_InterCSurf::Perform(const TheCurve& curve, + const ThePolygon& polygon, + const TheSurface& surface, + const ThePolyhedron& polyhedron, + Bnd_BoundSortBox& BndBSB) +{ + IntCurveSurface_InterImpl::PerformPolygonPolyhedronBSB( + curve, + polygon, + surface, + polyhedron, + BndBSB, + done, + [this]() { this->ResetFields(); }, + [this](const TheCurve& c, + const ThePolygon& p, + const TheSurface& s, + const ThePolyhedron& ph, + Standard_Real u1, + Standard_Real v1, + Standard_Real u2, + Standard_Real v2, + Bnd_BoundSortBox& bsb) { this->InternalPerform(c, p, s, ph, u1, v1, u2, v2, bsb); }); +} + +//================================================================================================== + +void HLRBRep_InterCSurf::InternalPerform(const TheCurve& curve, + const ThePolygon& polygon, + const TheSurface& surface, + const ThePolyhedron& polyhedron, + const Standard_Real u0, + const Standard_Real v0, + const Standard_Real u1, + const Standard_Real v1, + Bnd_BoundSortBox& BSB) +{ + IntCurveSurface_InterImpl::InternalPerformBSB( + curve, + polygon, + surface, + polyhedron, + u0, + v0, + u1, + v1, + BSB, + [this](const IntCurveSurface_IntersectionPoint& pt) { this->Append(pt); }); +} + +//================================================================================================== + +void HLRBRep_InterCSurf::InternalPerform(const TheCurve& curve, + const ThePolygon& polygon, + const TheSurface& surface, + const ThePolyhedron& polyhedron, + const Standard_Real u0, + const Standard_Real v0, + const Standard_Real u1, + const Standard_Real v1) +{ + IntCurveSurface_InterImpl::InternalPerform( + curve, + polygon, + surface, + polyhedron, + u0, + v0, + u1, + v1, + [this](const IntCurveSurface_IntersectionPoint& pt) { this->Append(pt); }); +} + +//================================================================================================== + +void HLRBRep_InterCSurf::InternalPerformCurveQuadric(const TheCurve& curve, + const TheSurface& surface) +{ + IntCurveSurface_InterImpl::InternalPerformCurveQuadric( + curve, + surface, + [this](const IntCurveSurface_IntersectionPoint& pt) { this->Append(pt); }); +} + +//================================================================================================== + +void HLRBRep_InterCSurf::InternalPerform(const TheCurve& curve, + const ThePolygon& polygon, + const TheSurface& surface, + const Standard_Real U1, + const Standard_Real V1, + const Standard_Real U2, + const Standard_Real V2) +{ + IntCurveSurface_InterImpl::InternalPerformPolygonBounds( + curve, + polygon, + surface, + U1, + V1, + U2, + V2, + [this](const TheCurve& c, + const ThePolygon& p, + const TheSurface& s, + const ThePolyhedron& ph, + Standard_Real u1, + Standard_Real v1, + Standard_Real u2, + Standard_Real v2) { this->InternalPerform(c, p, s, ph, u1, v1, u2, v2); }, + [this](const IntCurveSurface_IntersectionPoint& pt) { this->Append(pt); }); +} + +//================================================================================================== + +void HLRBRep_InterCSurf::PerformConicSurf(const gp_Lin& Line, + const TheCurve& curve, + const TheSurface& surface, + const Standard_Real U1, + const Standard_Real V1, + const Standard_Real U2, + const Standard_Real V2) +{ + IntCurveSurface_InterImpl::PerformConicSurfLine( + Line, + curve, + surface, + U1, + V1, + U2, + V2, + [this](const TheCurve& c, const TheSurface& s, const IntAna_IntConicQuad& ana) { + this->AppendIntAna(c, s, ana); + }, + [this](const TheCurve& c, + const ThePolygon& p, + const TheSurface& s, + const ThePolyhedron& ph, + Standard_Real u1, + Standard_Real v1, + Standard_Real u2, + Standard_Real v2) { this->InternalPerform(c, p, s, ph, u1, v1, u2, v2); }, + [this](const IntCurveSurface_IntersectionPoint& pt) { this->Append(pt); }); +} + +//================================================================================================== + +void HLRBRep_InterCSurf::PerformConicSurf(const gp_Circ& Circle, + const TheCurve& curve, + const TheSurface& surface, + const Standard_Real U1, + const Standard_Real V1, + const Standard_Real U2, + const Standard_Real V2) +{ + IntCurveSurface_InterImpl:: + PerformConicSurfCircle( + Circle, + curve, + surface, + U1, + V1, + U2, + V2, + [this](const TheCurve& c, const TheSurface& s, const IntAna_IntConicQuad& ana) { + this->AppendIntAna(c, s, ana); + }, + [this](const TheCurve& c, + const ThePolygon& p, + const TheSurface& s, + Standard_Real u1, + Standard_Real v1, + Standard_Real u2, + Standard_Real v2) { this->InternalPerform(c, p, s, u1, v1, u2, v2); }); +} + +//================================================================================================== + +void HLRBRep_InterCSurf::PerformConicSurf(const gp_Elips& Ellipse, + const TheCurve& curve, + const TheSurface& surface, + const Standard_Real U1, + const Standard_Real V1, + const Standard_Real U2, + const Standard_Real V2) +{ + IntCurveSurface_InterImpl:: + PerformConicSurfEllipse( + Ellipse, + curve, + surface, + U1, + V1, + U2, + V2, + [this](const TheCurve& c, const TheSurface& s, const IntAna_IntConicQuad& ana) { + this->AppendIntAna(c, s, ana); + }, + [this](const TheCurve& c, + const ThePolygon& p, + const TheSurface& s, + Standard_Real u1, + Standard_Real v1, + Standard_Real u2, + Standard_Real v2) { this->InternalPerform(c, p, s, u1, v1, u2, v2); }); +} + +//================================================================================================== + +void HLRBRep_InterCSurf::PerformConicSurf(const gp_Parab& Parab, + const TheCurve& curve, + const TheSurface& surface, + const Standard_Real U1, + const Standard_Real V1, + const Standard_Real U2, + const Standard_Real V2) +{ + IntCurveSurface_InterImpl::PerformConicSurfParabola( + Parab, + curve, + surface, + U1, + V1, + U2, + V2, + [this](const TheCurve& c, const TheSurface& s, const IntAna_IntConicQuad& ana) { + this->AppendIntAna(c, s, ana); + }, + [this](const TheCurve& c, + const ThePolygon& p, + const TheSurface& s, + const ThePolyhedron& ph, + Standard_Real u1, + Standard_Real v1, + Standard_Real u2, + Standard_Real v2) { this->InternalPerform(c, p, s, ph, u1, v1, u2, v2); }); +} + +//================================================================================================== + +void HLRBRep_InterCSurf::PerformConicSurf(const gp_Hypr& Hypr, + const TheCurve& curve, + const TheSurface& surface, + const Standard_Real U1, + const Standard_Real V1, + const Standard_Real U2, + const Standard_Real V2) +{ + IntCurveSurface_InterImpl::PerformConicSurfHyperbola( + Hypr, + curve, + surface, + U1, + V1, + U2, + V2, + [this](const TheCurve& c, const TheSurface& s, const IntAna_IntConicQuad& ana) { + this->AppendIntAna(c, s, ana); + }, + [this](const TheCurve& c, + const ThePolygon& p, + const TheSurface& s, + const ThePolyhedron& ph, + Standard_Real u1, + Standard_Real v1, + Standard_Real u2, + Standard_Real v2) { this->InternalPerform(c, p, s, ph, u1, v1, u2, v2); }); +} + +//================================================================================================== + +void HLRBRep_InterCSurf::AppendIntAna(const TheCurve& curve, + const TheSurface& surface, + const IntAna_IntConicQuad& intana_ConicQuad) +{ + IntCurveSurface_InterImpl::AppendIntAna( + curve, + surface, + intana_ConicQuad, + myIsParallel, + [this](const IntCurveSurface_IntersectionPoint& pt) { this->Append(pt); }); +} + +//================================================================================================== + +void HLRBRep_InterCSurf::AppendPoint(const TheCurve& curve, + const Standard_Real lw, + const TheSurface& surface, + const Standard_Real su, + const Standard_Real sv) +{ + IntCurveSurface_IntersectionPoint aPoint; + if (IntCurveSurface_InterUtils:: + ComputeAppendPoint(curve, + lw, + surface, + su, + sv, + aPoint)) + { + Append(aPoint); + } +} + +//================================================================================================== + +void HLRBRep_InterCSurf::AppendSegment(const TheCurve&, + const Standard_Real, + const Standard_Real, + const TheSurface&) +{ + // Not implemented +} diff --git a/src/ModelingAlgorithms/TKHLR/HLRBRep/HLRBRep_InterCSurf_0.cxx b/src/ModelingAlgorithms/TKHLR/HLRBRep/HLRBRep_InterCSurf_0.cxx deleted file mode 100644 index cabd10412a..0000000000 --- a/src/ModelingAlgorithms/TKHLR/HLRBRep/HLRBRep_InterCSurf_0.cxx +++ /dev/null @@ -1,73 +0,0 @@ -// Created on: 1992-10-14 -// Created by: Christophe MARION -// Copyright (c) 1992-1999 Matra Datavision -// Copyright (c) 1999-2014 OPEN CASCADE SAS -// -// This file is part of Open CASCADE Technology software library. -// -// This library is free software; you can redistribute it and/or modify it under -// the terms of the GNU Lesser General Public License version 2.1 as published -// by the Free Software Foundation, with special exception defined in the file -// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT -// distribution for complete text of the license and disclaimer of any warranty. -// -// Alternatively, this file may be used under the terms of Open CASCADE -// commercial license or contractual agreement. - -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#define TheCurve gp_Lin -#define TheCurve_hxx -#define TheCurveTool HLRBRep_LineTool -#define TheCurveTool_hxx -#define TheSurface Standard_Address -#define TheSurface_hxx -#define TheSurfaceTool HLRBRep_SurfaceTool -#define TheSurfaceTool_hxx -#define IntCurveSurface_ThePolygon HLRBRep_ThePolygonOfInterCSurf -#define IntCurveSurface_ThePolygon_hxx -#define IntCurveSurface_ThePolygonTool HLRBRep_ThePolygonToolOfInterCSurf -#define IntCurveSurface_ThePolygonTool_hxx -#define IntCurveSurface_ThePolyhedron HLRBRep_ThePolyhedronOfInterCSurf -#define IntCurveSurface_ThePolyhedron_hxx -#define IntCurveSurface_ThePolyhedronTool HLRBRep_ThePolyhedronToolOfInterCSurf -#define IntCurveSurface_ThePolyhedronTool_hxx -#define IntCurveSurface_TheInterference HLRBRep_TheInterferenceOfInterCSurf -#define IntCurveSurface_TheInterference_hxx -#define IntCurveSurface_TheCSFunction HLRBRep_TheCSFunctionOfInterCSurf -#define IntCurveSurface_TheCSFunction_hxx -#define IntCurveSurface_TheExactInter HLRBRep_TheExactInterCSurf -#define IntCurveSurface_TheExactInter_hxx -#define IntCurveSurface_TheQuadCurvExactInter HLRBRep_TheQuadCurvExactInterCSurf -#define IntCurveSurface_TheQuadCurvExactInter_hxx -#define IntCurveSurface_TheQuadCurvFuncOfTheQuadCurvExactInter \ - HLRBRep_TheQuadCurvFuncOfTheQuadCurvExactInterCSurf -#define IntCurveSurface_TheQuadCurvFuncOfTheQuadCurvExactInter_hxx \ - -#define IntCurveSurface_TheQuadCurvFuncOfTheQuadCurvExactInter \ - HLRBRep_TheQuadCurvFuncOfTheQuadCurvExactInterCSurf -#define IntCurveSurface_TheQuadCurvFuncOfTheQuadCurvExactInter_hxx \ - -#define IntCurveSurface_Inter HLRBRep_InterCSurf -#define IntCurveSurface_Inter_hxx -#include diff --git a/src/ModelingAlgorithms/TKHLR/HLRBRep/HLRBRep_ThePolygonOfInterCSurf.cxx b/src/ModelingAlgorithms/TKHLR/HLRBRep/HLRBRep_ThePolygonOfInterCSurf.cxx new file mode 100644 index 0000000000..edc3b6e29b --- /dev/null +++ b/src/ModelingAlgorithms/TKHLR/HLRBRep/HLRBRep_ThePolygonOfInterCSurf.cxx @@ -0,0 +1,137 @@ +// Created on: 1992-10-14 +// Created by: Christophe MARION +// Copyright (c) 1992-1999 Matra Datavision +// Copyright (c) 1999-2014 OPEN CASCADE SAS +// +// This file is part of Open CASCADE Technology software library. +// +// This library is free software; you can redistribute it and/or modify it under +// the terms of the GNU Lesser General Public License version 2.1 as published +// by the Free Software Foundation, with special exception defined in the file +// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT +// distribution for complete text of the license and disclaimer of any warranty. +// +// Alternatively, this file may be used under the terms of Open CASCADE +// commercial license or contractual agreement. + +#include + +#include +#include +#include +#include +#include "../../TKGeomAlgo/IntCurveSurface/IntCurveSurface_PolygonUtils.pxx" +#include + +//================================================================================================== + +HLRBRep_ThePolygonOfInterCSurf::HLRBRep_ThePolygonOfInterCSurf(const gp_Lin& Curve, + const Standard_Integer NbPnt) + : ThePnts(1, (NbPnt < 5) ? 5 : NbPnt), + ClosedPolygon(Standard_False) +{ + NbPntIn = (NbPnt < 5) ? 5 : NbPnt; + Binf = HLRBRep_LineTool::FirstParameter(Curve); + Bsup = HLRBRep_LineTool::LastParameter(Curve); + Init(Curve); +} + +//================================================================================================== + +HLRBRep_ThePolygonOfInterCSurf::HLRBRep_ThePolygonOfInterCSurf(const gp_Lin& Curve, + const Standard_Real U1, + const Standard_Real U2, + const Standard_Integer NbPnt) + : ThePnts(1, (NbPnt < 5) ? 5 : NbPnt), + ClosedPolygon(Standard_False), + Binf(U1), + Bsup(U2) +{ + NbPntIn = (NbPnt < 5) ? 5 : NbPnt; + Init(Curve); +} + +//================================================================================================== + +HLRBRep_ThePolygonOfInterCSurf::HLRBRep_ThePolygonOfInterCSurf(const gp_Lin& Curve, + const TColStd_Array1OfReal& Upars) + : ThePnts(1, Upars.Length()), + ClosedPolygon(Standard_False), + Binf(Upars(Upars.Lower())), + Bsup(Upars(Upars.Upper())) +{ + NbPntIn = Upars.Length(); + Init(Curve, Upars); +} + +//================================================================================================== + +void HLRBRep_ThePolygonOfInterCSurf::Init(const gp_Lin& Curve) +{ + IntCurveSurface_PolygonUtils::InitUniform(Curve, + Binf, + Bsup, + NbPntIn, + ThePnts, + TheBnd, + TheDeflection); + ClosedPolygon = Standard_False; +} + +//================================================================================================== + +void HLRBRep_ThePolygonOfInterCSurf::Init(const gp_Lin& Curve, const TColStd_Array1OfReal& Upars) +{ + IntCurveSurface_PolygonUtils::InitWithParams(Curve, + Upars, + NbPntIn, + ThePnts, + TheBnd, + TheDeflection, + myParams); + ClosedPolygon = Standard_False; +} + +//================================================================================================== + +Standard_Real HLRBRep_ThePolygonOfInterCSurf::ApproxParamOnCurve( + const Standard_Integer Index, + const Standard_Real ParamOnLine) const +{ + return IntCurveSurface_PolygonUtils::ApproxParamOnCurve(Index, + ParamOnLine, + Binf, + Bsup, + NbPntIn, + myParams); +} + +//================================================================================================== + +void HLRBRep_ThePolygonOfInterCSurf::Dump() const +{ +#if 0 + static Standard_Integer Compteur=0; + char tamp[100]; + Compteur++; + Sprintf(tamp,"Poly%d",Compteur); + std::cout<<" @@@@@@@@@@@ F i c h i e r : "< %f \n",Binf,Bsup); + fprintf(fp,"\npol %d %d %f",Compteur,NbPntIn,TheDeflection); + gp_Pnt p1,p2; + for (Standard_Integer iObje=1; iObje<=NbSegments(); iObje++) { + p1=BeginOfSeg(iObje); + fprintf(fp,"\npnt %d %f %f",Compteur,p1.X(),p1.Y()); + } + p1=EndOfSeg(NbSegments()); + fprintf(fp,"\npnt %d %f %f",Compteur,p1.X(),p1.Y()); + fprintf(fp,"\ndispol %d\n#\n",Compteur); + fclose(fp); +#endif +} diff --git a/src/ModelingAlgorithms/TKHLR/HLRBRep/HLRBRep_ThePolygonOfInterCSurf_0.cxx b/src/ModelingAlgorithms/TKHLR/HLRBRep/HLRBRep_ThePolygonOfInterCSurf_0.cxx deleted file mode 100644 index 413cc09a3e..0000000000 --- a/src/ModelingAlgorithms/TKHLR/HLRBRep/HLRBRep_ThePolygonOfInterCSurf_0.cxx +++ /dev/null @@ -1,31 +0,0 @@ -// Created on: 1992-10-14 -// Created by: Christophe MARION -// Copyright (c) 1992-1999 Matra Datavision -// Copyright (c) 1999-2014 OPEN CASCADE SAS -// -// This file is part of Open CASCADE Technology software library. -// -// This library is free software; you can redistribute it and/or modify it under -// the terms of the GNU Lesser General Public License version 2.1 as published -// by the Free Software Foundation, with special exception defined in the file -// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT -// distribution for complete text of the license and disclaimer of any warranty. -// -// Alternatively, this file may be used under the terms of Open CASCADE -// commercial license or contractual agreement. - -#include - -#include -#include -#include -#include -#include - -#define TheCurve gp_Lin -#define TheCurve_hxx -#define TheCurveTool HLRBRep_LineTool -#define TheCurveTool_hxx -#define IntCurveSurface_Polygon HLRBRep_ThePolygonOfInterCSurf -#define IntCurveSurface_Polygon_hxx -#include diff --git a/src/ModelingAlgorithms/TKHLR/HLRBRep/HLRBRep_ThePolygonToolOfInterCSurf.hxx b/src/ModelingAlgorithms/TKHLR/HLRBRep/HLRBRep_ThePolygonToolOfInterCSurf.hxx index 02f9cd10f4..658bf1a2b3 100644 --- a/src/ModelingAlgorithms/TKHLR/HLRBRep/HLRBRep_ThePolygonToolOfInterCSurf.hxx +++ b/src/ModelingAlgorithms/TKHLR/HLRBRep/HLRBRep_ThePolygonToolOfInterCSurf.hxx @@ -19,14 +19,10 @@ #include #include -#include -#include -#include -class Standard_OutOfRange; -class gp_Pnt; -class HLRBRep_ThePolygonOfInterCSurf; -class Bnd_Box; +#include +#include +#include class HLRBRep_ThePolygonToolOfInterCSurf { @@ -34,46 +30,41 @@ public: DEFINE_STANDARD_ALLOC //! Give the bounding box of the polygon. - static const Bnd_Box& Bounding(const HLRBRep_ThePolygonOfInterCSurf& thePolygon); + static const Bnd_Box& Bounding(const HLRBRep_ThePolygonOfInterCSurf& thePolygon) + { + return thePolygon.Bounding(); + } - static Standard_Real DeflectionOverEstimation(const HLRBRep_ThePolygonOfInterCSurf& thePolygon); + static Standard_Real DeflectionOverEstimation(const HLRBRep_ThePolygonOfInterCSurf& thePolygon) + { + return thePolygon.DeflectionOverEstimation(); + } - static Standard_Boolean Closed(const HLRBRep_ThePolygonOfInterCSurf& thePolygon); + static Standard_Boolean Closed(const HLRBRep_ThePolygonOfInterCSurf& thePolygon) + { + return thePolygon.Closed(); + } - static Standard_Integer NbSegments(const HLRBRep_ThePolygonOfInterCSurf& thePolygon); + static Standard_Integer NbSegments(const HLRBRep_ThePolygonOfInterCSurf& thePolygon) + { + return thePolygon.NbSegments(); + } //! Give the point of range Index in the Polygon. static const gp_Pnt& BeginOfSeg(const HLRBRep_ThePolygonOfInterCSurf& thePolygon, - const Standard_Integer Index); + const Standard_Integer Index) + { + return thePolygon.BeginOfSeg(Index); + } //! Give the point of range Index in the Polygon. static const gp_Pnt& EndOfSeg(const HLRBRep_ThePolygonOfInterCSurf& thePolygon, - const Standard_Integer Index); + const Standard_Integer Index) + { + return thePolygon.EndOfSeg(Index); + } Standard_EXPORT static void Dump(const HLRBRep_ThePolygonOfInterCSurf& thePolygon); - -protected: -private: }; -#define ThePoint gp_Pnt -#define ThePoint_hxx -#define ThePolygon HLRBRep_ThePolygonOfInterCSurf -#define ThePolygon_hxx -#define TheBoundingBox Bnd_Box -#define TheBoundingBox_hxx -#define IntCurveSurface_PolygonTool HLRBRep_ThePolygonToolOfInterCSurf -#define IntCurveSurface_PolygonTool_hxx - -#include - -#undef ThePoint -#undef ThePoint_hxx -#undef ThePolygon -#undef ThePolygon_hxx -#undef TheBoundingBox -#undef TheBoundingBox_hxx -#undef IntCurveSurface_PolygonTool -#undef IntCurveSurface_PolygonTool_hxx - #endif // _HLRBRep_ThePolygonToolOfInterCSurf_HeaderFile diff --git a/src/ModelingAlgorithms/TKHLR/HLRBRep/HLRBRep_ThePolyhedronOfInterCSurf.cxx b/src/ModelingAlgorithms/TKHLR/HLRBRep/HLRBRep_ThePolyhedronOfInterCSurf.cxx new file mode 100644 index 0000000000..0aaba45b70 --- /dev/null +++ b/src/ModelingAlgorithms/TKHLR/HLRBRep/HLRBRep_ThePolyhedronOfInterCSurf.cxx @@ -0,0 +1,781 @@ +// Created on: 1992-10-14 +// Created by: Christophe MARION +// Copyright (c) 1992-1999 Matra Datavision +// Copyright (c) 1999-2014 OPEN CASCADE SAS +// +// This file is part of Open CASCADE Technology software library. +// +// This library is free software; you can redistribute it and/or modify it under +// the terms of the GNU Lesser General Public License version 2.1 as published +// by the Free Software Foundation, with special exception defined in the file +// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT +// distribution for complete text of the license and disclaimer of any warranty. +// +// Alternatively, this file may be used under the terms of Open CASCADE +// commercial license or contractual agreement. + +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +#include "../../TKGeomAlgo/IntCurveSurface/IntCurveSurface_PolyhedronUtils.pxx" + +#define LONGUEUR_MINI_EDGE_TRIANGLE 1e-15 + +//================================================================================================== + +HLRBRep_ThePolyhedronOfInterCSurf::HLRBRep_ThePolyhedronOfInterCSurf( + const Standard_Address& Surface, + const Standard_Integer nbdU, + const Standard_Integer nbdV, + const Standard_Real u1, + const Standard_Real v1, + const Standard_Real u2, + const Standard_Real v2) + : nbdeltaU((nbdU < 3) ? 3 : nbdU), + nbdeltaV((nbdV < 3) ? 3 : nbdV), + TheDeflection(Epsilon(100.)), + C_MyPnts(NULL), + C_MyU(NULL), + C_MyV(NULL), + C_MyIsOnBounds(NULL) +{ + Standard_Integer t = (nbdeltaU + 1) * (nbdeltaV + 1) + 1; + C_MyPnts = new gp_Pnt[t]; + C_MyU = new Standard_Real[t]; + C_MyV = new Standard_Real[t]; + C_MyIsOnBounds = new Standard_Boolean[t]; + Init(Surface, u1, v1, u2, v2); +} + +//================================================================================================== + +HLRBRep_ThePolyhedronOfInterCSurf::HLRBRep_ThePolyhedronOfInterCSurf( + const Standard_Address& Surface, + const TColStd_Array1OfReal& Upars, + const TColStd_Array1OfReal& Vpars) + : nbdeltaU(Upars.Length() - 1), + nbdeltaV(Vpars.Length() - 1), + TheDeflection(Epsilon(100.)), + C_MyPnts(NULL), + C_MyU(NULL), + C_MyV(NULL), + C_MyIsOnBounds(NULL) +{ + Standard_Integer t = (nbdeltaU + 1) * (nbdeltaV + 1) + 1; + C_MyPnts = new gp_Pnt[t]; + C_MyU = new Standard_Real[t]; + C_MyV = new Standard_Real[t]; + C_MyIsOnBounds = new Standard_Boolean[t]; + Init(Surface, Upars, Vpars); +} + +//================================================================================================== + +void HLRBRep_ThePolyhedronOfInterCSurf::Destroy() +{ + gp_Pnt* CMyPnts = (gp_Pnt*)C_MyPnts; + if (C_MyPnts) + delete[] CMyPnts; + Standard_Real* CMyU = (Standard_Real*)C_MyU; + if (C_MyU) + delete[] CMyU; + Standard_Real* CMyV = (Standard_Real*)C_MyV; + if (C_MyV) + delete[] CMyV; + Standard_Boolean* CMyIsOnBounds = (Standard_Boolean*)C_MyIsOnBounds; + if (C_MyIsOnBounds) + delete[] CMyIsOnBounds; + + C_MyPnts = C_MyU = C_MyV = C_MyIsOnBounds = NULL; +} + +//================================================================================================== + +void HLRBRep_ThePolyhedronOfInterCSurf::Init(const Standard_Address& Surface, + const Standard_Real U0, + const Standard_Real V0, + const Standard_Real U1, + const Standard_Real V1) +{ + IntCurveSurface_PolyhedronUtils::InitUniform( + Surface, + U0, + V0, + U1, + V1, + nbdeltaU, + nbdeltaV, + (gp_Pnt*)C_MyPnts, + (Standard_Real*)C_MyU, + (Standard_Real*)C_MyV, + (Standard_Boolean*)C_MyIsOnBounds, + TheBnd); + + // Calculate triangle deflections + Standard_Real tol = 0.0; + Standard_Integer nbtriangles = NbTriangles(); + for (Standard_Integer i1 = 1; i1 <= nbtriangles; i1++) + { + Standard_Real tol1 = DeflectionOnTriangle(Surface, i1); + if (tol1 > tol) + tol = tol1; + } + + DeflectionOverEstimation(tol * 1.2); + FillBounding(); + + // Compute border deflection + TheBorderDeflection = RealFirst(); + Standard_Real aDeflection; + + aDeflection = ComputeBorderDeflection(Surface, U0, V0, V1, Standard_True); + if (aDeflection > TheBorderDeflection) + TheBorderDeflection = aDeflection; + + aDeflection = ComputeBorderDeflection(Surface, U1, V0, V1, Standard_True); + if (aDeflection > TheBorderDeflection) + TheBorderDeflection = aDeflection; + + aDeflection = ComputeBorderDeflection(Surface, V0, U0, U1, Standard_False); + if (aDeflection > TheBorderDeflection) + TheBorderDeflection = aDeflection; + + aDeflection = ComputeBorderDeflection(Surface, V1, U0, U1, Standard_False); + if (aDeflection > TheBorderDeflection) + TheBorderDeflection = aDeflection; +} + +//================================================================================================== + +void HLRBRep_ThePolyhedronOfInterCSurf::Init(const Standard_Address& Surface, + const TColStd_Array1OfReal& Upars, + const TColStd_Array1OfReal& Vpars) +{ + IntCurveSurface_PolyhedronUtils::InitWithParams( + Surface, + Upars, + Vpars, + nbdeltaU, + nbdeltaV, + (gp_Pnt*)C_MyPnts, + (Standard_Real*)C_MyU, + (Standard_Real*)C_MyV, + (Standard_Boolean*)C_MyIsOnBounds, + TheBnd); + + // Calculate triangle deflections + Standard_Real tol = 0.0; + Standard_Integer nbtriangles = NbTriangles(); + for (Standard_Integer i1 = 1; i1 <= nbtriangles; i1++) + { + Standard_Real tol1 = DeflectionOnTriangle(Surface, i1); + if (tol1 > tol) + tol = tol1; + } + + DeflectionOverEstimation(tol * 1.2); + FillBounding(); + + // Compute border deflection + TheBorderDeflection = RealFirst(); + Standard_Integer i0 = Upars.Lower(); + Standard_Integer j0 = Vpars.Lower(); + Standard_Real U0 = Upars(i0); + Standard_Real V0 = Vpars(j0); + Standard_Real U1 = Upars(Upars.Upper()); + Standard_Real V1 = Vpars(Vpars.Upper()); + Standard_Real aDeflection; + + aDeflection = ComputeBorderDeflection(Surface, U0, V0, V1, Standard_True); + if (aDeflection > TheBorderDeflection) + TheBorderDeflection = aDeflection; + + aDeflection = ComputeBorderDeflection(Surface, U1, V0, V1, Standard_True); + if (aDeflection > TheBorderDeflection) + TheBorderDeflection = aDeflection; + + aDeflection = ComputeBorderDeflection(Surface, V0, U0, U1, Standard_False); + if (aDeflection > TheBorderDeflection) + TheBorderDeflection = aDeflection; + + aDeflection = ComputeBorderDeflection(Surface, V1, U0, U1, Standard_False); + if (aDeflection > TheBorderDeflection) + TheBorderDeflection = aDeflection; +} + +//================================================================================================== + +Standard_Real HLRBRep_ThePolyhedronOfInterCSurf::DeflectionOnTriangle( + const Standard_Address& Surface, + const Standard_Integer Triang) const +{ + Standard_Integer i1, i2, i3; + Triangle(Triang, i1, i2, i3); + + Standard_Real u1, v1, u2, v2, u3, v3; + gp_Pnt P1 = Point(i1, u1, v1); + gp_Pnt P2 = Point(i2, u2, v2); + gp_Pnt P3 = Point(i3, u3, v3); + + return IntCurveSurface_PolyhedronUtils::DeflectionOnTriangle< + Standard_Address, + HLRBRep_SurfaceTool>(Surface, P1, P2, P3, u1, v1, u2, v2, u3, v3); +} + +//================================================================================================== + +Standard_Real HLRBRep_ThePolyhedronOfInterCSurf::ComputeBorderDeflection( + const Standard_Address& Surface, + const Standard_Real Parameter, + const Standard_Real PMin, + const Standard_Real PMax, + const Standard_Boolean isUIso) const +{ + Standard_Integer aNbSamples = isUIso ? nbdeltaV : nbdeltaU; + + return IntCurveSurface_PolyhedronUtils::ComputeBorderDeflection(Surface, + Parameter, + PMin, + PMax, + isUIso, + aNbSamples); +} + +//================================================================================================== + +void HLRBRep_ThePolyhedronOfInterCSurf::Parameters(const Standard_Integer Index, + Standard_Real& U, + Standard_Real& V) const +{ + Standard_Real* CMyU = (Standard_Real*)C_MyU; + U = CMyU[Index]; + Standard_Real* CMyV = (Standard_Real*)C_MyV; + V = CMyV[Index]; +} + +//================================================================================================== + +void HLRBRep_ThePolyhedronOfInterCSurf::DeflectionOverEstimation(const Standard_Real flec) +{ + if (flec < 0.0001) + { + TheDeflection = 0.0001; + TheBnd.Enlarge(0.0001); + } + else + { + TheDeflection = flec; + TheBnd.Enlarge(flec); + } +} + +//================================================================================================== + +Standard_Real HLRBRep_ThePolyhedronOfInterCSurf::DeflectionOverEstimation() const +{ + return TheDeflection; +} + +//================================================================================================== + +const Bnd_Box& HLRBRep_ThePolyhedronOfInterCSurf::Bounding() const +{ + return TheBnd; +} + +//================================================================================================== + +void HLRBRep_ThePolyhedronOfInterCSurf::FillBounding() +{ + TheComponentsBnd = new Bnd_HArray1OfBox(1, NbTriangles()); + Bnd_Box Boite; + Standard_Integer np1, np2, np3; + Standard_Integer nbtriangles = NbTriangles(); + for (Standard_Integer iTri = 1; iTri <= nbtriangles; iTri++) + { + Triangle(iTri, np1, np2, np3); + gp_Pnt p1(Point(np1)); + gp_Pnt p2(Point(np2)); + gp_Pnt p3(Point(np3)); + Boite.SetVoid(); + if (p1.SquareDistance(p2) > LONGUEUR_MINI_EDGE_TRIANGLE) + { + if (p1.SquareDistance(p3) > LONGUEUR_MINI_EDGE_TRIANGLE) + { + if (p2.SquareDistance(p3) > LONGUEUR_MINI_EDGE_TRIANGLE) + { + Boite.Add(p1); + Boite.Add(p2); + Boite.Add(p3); + Boite.Enlarge(TheDeflection); + } + } + } + Boite.Enlarge(TheDeflection); + TheComponentsBnd->SetValue(iTri, Boite); + } +} + +//================================================================================================== + +const Handle(Bnd_HArray1OfBox)& HLRBRep_ThePolyhedronOfInterCSurf::ComponentsBounding() const +{ + return TheComponentsBnd; +} + +//================================================================================================== + +Standard_Integer HLRBRep_ThePolyhedronOfInterCSurf::NbTriangles() const +{ + return nbdeltaU * nbdeltaV * 2; +} + +//================================================================================================== + +Standard_Integer HLRBRep_ThePolyhedronOfInterCSurf::NbPoints() const +{ + return (nbdeltaU + 1) * (nbdeltaV + 1); +} + +//================================================================================================== + +Standard_Integer HLRBRep_ThePolyhedronOfInterCSurf::TriConnex(const Standard_Integer Triang, + const Standard_Integer Pivot, + const Standard_Integer Pedge, + Standard_Integer& TriCon, + Standard_Integer& OtherP) const +{ + Standard_Integer Pivotm1 = Pivot - 1; + Standard_Integer nbdeltaVp1 = nbdeltaV + 1; + Standard_Integer nbdeltaVm2 = nbdeltaV + nbdeltaV; + + Standard_Integer ligP = Pivotm1 / nbdeltaVp1; + Standard_Integer colP = Pivotm1 - ligP * nbdeltaVp1; + + Standard_Integer ligE = 0, colE = 0, typE = 0; + if (Pedge != 0) + { + ligE = (Pedge - 1) / nbdeltaVp1; + colE = (Pedge - 1) - (ligE * nbdeltaVp1); + if (ligP == ligE) + typE = 1; + else if (colP == colE) + typE = 2; + else + typE = 3; + } + + Standard_Integer linT = 0, colT = 0; + Standard_Integer linO = 0, colO = 0; + Standard_Integer t = 0, tt = 0; + + if (Triang != 0) + { + t = (Triang - 1) / nbdeltaVm2; + tt = (Triang - 1) - t * nbdeltaVm2; + linT = 1 + t; + colT = 1 + tt; + if (typE == 0) + { + if (ligP == linT) + { + ligE = ligP - 1; + colE = colP - 1; + typE = 3; + } + else + { + if (colT == ligP + ligP) + { + ligE = ligP; + colE = colP - 1; + typE = 1; + } + else + { + ligE = ligP + 1; + colE = colP + 1; + typE = 3; + } + } + } + switch (typE) + { + case 1: + if (linT == ligP) + { + linT++; + linO = ligP + 1; + colO = (colP > colE) ? colP : colE; + } + else + { + linT--; + linO = ligP - 1; + colO = (colP < colE) ? colP : colE; + } + break; + case 2: + if (colT == (colP + colP)) + { + colT++; + linO = (ligP > ligE) ? ligP : ligE; + colO = colP + 1; + } + else + { + colT--; + linO = (ligP < ligE) ? ligP : ligE; + colO = colP - 1; + } + break; + case 3: + if ((colT & 1) == 0) + { + colT--; + linO = (ligP > ligE) ? ligP : ligE; + colO = (colP < colE) ? colP : colE; + } + else + { + colT++; + linO = (ligP < ligE) ? ligP : ligE; + colO = (colP > colE) ? colP : colE; + } + break; + } + } + else + { + if (Pedge == 0) + { + linT = (1 > ligP) ? 1 : ligP; + colT = (1 > (colP + colP)) ? 1 : (colP + colP); + if (ligP == 0) + linO = ligP + 1; + else + linO = ligP - 1; + colO = colP; + } + else + { + switch (typE) + { + case 1: + linT = ligP + 1; + colT = (colP > colE) ? colP : colE; + colT += colT; + linO = ligP + 1; + colO = (colP > colE) ? colP : colE; + break; + case 2: + linT = (ligP > ligE) ? ligP : ligE; + colT = colP + colP; + linO = (ligP < ligE) ? ligP : ligE; + colO = colP - 1; + break; + case 3: + linT = (ligP > ligE) ? ligP : ligE; + colT = colP + colE; + linO = (ligP > ligE) ? ligP : ligE; + colO = (colP < colE) ? colP : colE; + break; + } + } + } + + TriCon = (linT - 1) * nbdeltaVm2 + colT; + + if (linT < 1) + { + linO = 0; + colO = colP + colP - colE; + if (colO < 0) + { + colO = 0; + linO = 1; + } + else if (colO > nbdeltaV) + { + colO = nbdeltaV; + linO = 1; + } + TriCon = 0; + } + else if (linT > nbdeltaU) + { + linO = nbdeltaU; + colO = colP + colP - colE; + if (colO < 0) + { + colO = 0; + linO = nbdeltaU - 1; + } + else if (colO > nbdeltaV) + { + colO = nbdeltaV; + linO = nbdeltaU - 1; + } + TriCon = 0; + } + + if (colT < 1) + { + colO = 0; + linO = ligP + ligP - ligE; + if (linO < 0) + { + linO = 0; + colO = 1; + } + else if (linO > nbdeltaU) + { + linO = nbdeltaU; + colO = 1; + } + TriCon = 0; + } + else if (colT > nbdeltaV) + { + colO = nbdeltaV; + linO = ligP + ligP - ligE; + if (linO < 0) + { + linO = 0; + colO = nbdeltaV - 1; + } + else if (linO > nbdeltaU) + { + linO = nbdeltaU; + colO = nbdeltaV - 1; + } + TriCon = 0; + } + + OtherP = linO * nbdeltaVp1 + colO + 1; + + return TriCon; +} + +//================================================================================================== + +void HLRBRep_ThePolyhedronOfInterCSurf::PlaneEquation(const Standard_Integer Triang, + gp_XYZ& NormalVector, + Standard_Real& PolarDistance) const +{ + Standard_Integer i1, i2, i3; + Triangle(Triang, i1, i2, i3); + + gp_XYZ Pointi1(Point(i1).XYZ()); + gp_XYZ Pointi2(Point(i2).XYZ()); + gp_XYZ Pointi3(Point(i3).XYZ()); + + gp_XYZ v1 = Pointi2 - Pointi1; + gp_XYZ v2 = Pointi3 - Pointi2; + gp_XYZ v3 = Pointi1 - Pointi3; + + if (v1.SquareModulus() <= LONGUEUR_MINI_EDGE_TRIANGLE) + { + NormalVector.SetCoord(1.0, 0.0, 0.0); + return; + } + if (v2.SquareModulus() <= LONGUEUR_MINI_EDGE_TRIANGLE) + { + NormalVector.SetCoord(1.0, 0.0, 0.0); + return; + } + if (v3.SquareModulus() <= LONGUEUR_MINI_EDGE_TRIANGLE) + { + NormalVector.SetCoord(1.0, 0.0, 0.0); + return; + } + + NormalVector = (v1 ^ v2) + (v2 ^ v3) + (v3 ^ v1); + Standard_Real aNormLen = NormalVector.Modulus(); + if (aNormLen < gp::Resolution()) + { + PolarDistance = 0.; + } + else + { + NormalVector.Divide(aNormLen); + PolarDistance = NormalVector * Point(i1).XYZ(); + } +} + +//================================================================================================== + +Standard_Boolean HLRBRep_ThePolyhedronOfInterCSurf::Contain(const Standard_Integer Triang, + const gp_Pnt& ThePnt) const +{ + Standard_Integer i1, i2, i3; + Triangle(Triang, i1, i2, i3); + gp_XYZ Pointi1(Point(i1).XYZ()); + gp_XYZ Pointi2(Point(i2).XYZ()); + gp_XYZ Pointi3(Point(i3).XYZ()); + + gp_XYZ v1 = (Pointi2 - Pointi1) ^ (ThePnt.XYZ() - Pointi1); + gp_XYZ v2 = (Pointi3 - Pointi2) ^ (ThePnt.XYZ() - Pointi2); + gp_XYZ v3 = (Pointi1 - Pointi3) ^ (ThePnt.XYZ() - Pointi3); + if (v1 * v2 >= 0. && v2 * v3 >= 0. && v3 * v1 >= 0.) + return Standard_True; + else + return Standard_False; +} + +//================================================================================================== + +void HLRBRep_ThePolyhedronOfInterCSurf::Dump() const {} + +//================================================================================================== + +void HLRBRep_ThePolyhedronOfInterCSurf::Size(Standard_Integer& nbdu, Standard_Integer& nbdv) const +{ + nbdu = nbdeltaU; + nbdv = nbdeltaV; +} + +//================================================================================================== + +void HLRBRep_ThePolyhedronOfInterCSurf::Triangle(const Standard_Integer Index, + Standard_Integer& P1, + Standard_Integer& P2, + Standard_Integer& P3) const +{ + Standard_Integer line = 1 + ((Index - 1) / (nbdeltaV * 2)); + Standard_Integer colon = 1 + ((Index - 1) % (nbdeltaV * 2)); + Standard_Integer colpnt = (colon + 1) / 2; + + P1 = (line - 1) * (nbdeltaV + 1) + colpnt; + P2 = line * (nbdeltaV + 1) + colpnt + ((colon - 1) % 2); + P3 = (line - 1 + (colon % 2)) * (nbdeltaV + 1) + colpnt + 1; +} + +//================================================================================================== + +const gp_Pnt& HLRBRep_ThePolyhedronOfInterCSurf::Point(const Standard_Integer Index, + Standard_Real& U, + Standard_Real& V) const +{ + gp_Pnt* CMyPnts = (gp_Pnt*)C_MyPnts; + Standard_Real* CMyU = (Standard_Real*)C_MyU; + Standard_Real* CMyV = (Standard_Real*)C_MyV; + U = CMyU[Index]; + V = CMyV[Index]; + return CMyPnts[Index]; +} + +//================================================================================================== + +const gp_Pnt& HLRBRep_ThePolyhedronOfInterCSurf::Point(const Standard_Integer Index) const +{ + gp_Pnt* CMyPnts = (gp_Pnt*)C_MyPnts; + return CMyPnts[Index]; +} + +//================================================================================================== + +void HLRBRep_ThePolyhedronOfInterCSurf::Point(const gp_Pnt&, + const Standard_Integer, + const Standard_Integer, + const Standard_Real, + const Standard_Real) +{ + // Should not be called +} + +//================================================================================================== + +void HLRBRep_ThePolyhedronOfInterCSurf::Point(const Standard_Integer Index, gp_Pnt& P) const +{ + gp_Pnt* CMyPnts = (gp_Pnt*)C_MyPnts; + P = CMyPnts[Index]; +} + +//================================================================================================== + +Standard_Boolean HLRBRep_ThePolyhedronOfInterCSurf::IsOnBound(const Standard_Integer Index1, + const Standard_Integer Index2) const +{ + Standard_Boolean* CMyIsOnBounds = (Standard_Boolean*)C_MyIsOnBounds; + Standard_Integer aDiff = std::abs(Index1 - Index2); + + if (aDiff != 1 && aDiff != nbdeltaV + 1) + return Standard_False; + + for (Standard_Integer i = 0; i <= nbdeltaU; i++) + { + if ((Index1 == 1 + i * (nbdeltaV + 1)) && (Index2 == Index1 - 1)) + return Standard_False; + + if ((Index1 == (1 + i) * (nbdeltaV + 1)) && (Index2 == Index1 + 1)) + return Standard_False; + } + + return (CMyIsOnBounds[Index1] && CMyIsOnBounds[Index2]); +} + +//================================================================================================== + +void HLRBRep_ThePolyhedronOfInterCSurf::UMinSingularity(const Standard_Boolean Sing) +{ + UMinSingular = Sing; +} + +//================================================================================================== + +void HLRBRep_ThePolyhedronOfInterCSurf::UMaxSingularity(const Standard_Boolean Sing) +{ + UMaxSingular = Sing; +} + +//================================================================================================== + +void HLRBRep_ThePolyhedronOfInterCSurf::VMinSingularity(const Standard_Boolean Sing) +{ + VMinSingular = Sing; +} + +//================================================================================================== + +void HLRBRep_ThePolyhedronOfInterCSurf::VMaxSingularity(const Standard_Boolean Sing) +{ + VMaxSingular = Sing; +} + +//================================================================================================== + +Standard_Boolean HLRBRep_ThePolyhedronOfInterCSurf::HasUMinSingularity() const +{ + return UMinSingular; +} + +//================================================================================================== + +Standard_Boolean HLRBRep_ThePolyhedronOfInterCSurf::HasUMaxSingularity() const +{ + return UMaxSingular; +} + +//================================================================================================== + +Standard_Boolean HLRBRep_ThePolyhedronOfInterCSurf::HasVMinSingularity() const +{ + return VMinSingular; +} + +//================================================================================================== + +Standard_Boolean HLRBRep_ThePolyhedronOfInterCSurf::HasVMaxSingularity() const +{ + return VMaxSingular; +} diff --git a/src/ModelingAlgorithms/TKHLR/HLRBRep/HLRBRep_ThePolyhedronOfInterCSurf.hxx b/src/ModelingAlgorithms/TKHLR/HLRBRep/HLRBRep_ThePolyhedronOfInterCSurf.hxx index f42ad1e28d..11ba22643b 100644 --- a/src/ModelingAlgorithms/TKHLR/HLRBRep/HLRBRep_ThePolyhedronOfInterCSurf.hxx +++ b/src/ModelingAlgorithms/TKHLR/HLRBRep/HLRBRep_ThePolyhedronOfInterCSurf.hxx @@ -155,7 +155,7 @@ public: const Standard_Integer Index2) const; //! This method returns a border deflection. - Standard_Real GetBorderDeflection() const; + Standard_Real GetBorderDeflection() const { return TheBorderDeflection; } Standard_EXPORT void Dump() const; @@ -196,20 +196,4 @@ private: Standard_Address C_MyIsOnBounds; }; -#define ThePSurface Standard_Address -#define ThePSurface_hxx -#define ThePSurfaceTool HLRBRep_SurfaceTool -#define ThePSurfaceTool_hxx -#define IntCurveSurface_Polyhedron HLRBRep_ThePolyhedronOfInterCSurf -#define IntCurveSurface_Polyhedron_hxx - -#include - -#undef ThePSurface -#undef ThePSurface_hxx -#undef ThePSurfaceTool -#undef ThePSurfaceTool_hxx -#undef IntCurveSurface_Polyhedron -#undef IntCurveSurface_Polyhedron_hxx - #endif // _HLRBRep_ThePolyhedronOfInterCSurf_HeaderFile diff --git a/src/ModelingAlgorithms/TKHLR/HLRBRep/HLRBRep_ThePolyhedronOfInterCSurf_0.cxx b/src/ModelingAlgorithms/TKHLR/HLRBRep/HLRBRep_ThePolyhedronOfInterCSurf_0.cxx deleted file mode 100644 index c44fc02515..0000000000 --- a/src/ModelingAlgorithms/TKHLR/HLRBRep/HLRBRep_ThePolyhedronOfInterCSurf_0.cxx +++ /dev/null @@ -1,31 +0,0 @@ -// Created on: 1992-10-14 -// Created by: Christophe MARION -// Copyright (c) 1992-1999 Matra Datavision -// Copyright (c) 1999-2014 OPEN CASCADE SAS -// -// This file is part of Open CASCADE Technology software library. -// -// This library is free software; you can redistribute it and/or modify it under -// the terms of the GNU Lesser General Public License version 2.1 as published -// by the Free Software Foundation, with special exception defined in the file -// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT -// distribution for complete text of the license and disclaimer of any warranty. -// -// Alternatively, this file may be used under the terms of Open CASCADE -// commercial license or contractual agreement. - -#include - -#include -#include -#include -#include -#include - -#define ThePSurface Standard_Address -#define ThePSurface_hxx -#define ThePSurfaceTool HLRBRep_SurfaceTool -#define ThePSurfaceTool_hxx -#define IntCurveSurface_Polyhedron HLRBRep_ThePolyhedronOfInterCSurf -#define IntCurveSurface_Polyhedron_hxx -#include diff --git a/src/ModelingAlgorithms/TKHLR/HLRBRep/HLRBRep_ThePolyhedronToolOfInterCSurf.hxx b/src/ModelingAlgorithms/TKHLR/HLRBRep/HLRBRep_ThePolyhedronToolOfInterCSurf.hxx index 1e0c534618..9fa384c854 100644 --- a/src/ModelingAlgorithms/TKHLR/HLRBRep/HLRBRep_ThePolyhedronToolOfInterCSurf.hxx +++ b/src/ModelingAlgorithms/TKHLR/HLRBRep/HLRBRep_ThePolyhedronToolOfInterCSurf.hxx @@ -21,14 +21,10 @@ #include #include +#include #include -#include -#include -#include -class Standard_OutOfRange; -class HLRBRep_ThePolyhedronOfInterCSurf; -class Bnd_Box; -class gp_Pnt; +#include +#include class HLRBRep_ThePolyhedronToolOfInterCSurf { @@ -36,18 +32,30 @@ public: DEFINE_STANDARD_ALLOC //! Give the bounding box of the PolyhedronTool. - static const Bnd_Box& Bounding(const HLRBRep_ThePolyhedronOfInterCSurf& thePolyh); + static const Bnd_Box& Bounding(const HLRBRep_ThePolyhedronOfInterCSurf& thePolyh) + { + return thePolyh.Bounding(); + } //! Give the array of boxes. The box corresponding //! to the triangle . static const Handle(Bnd_HArray1OfBox)& ComponentsBounding( - const HLRBRep_ThePolyhedronOfInterCSurf& thePolyh); + const HLRBRep_ThePolyhedronOfInterCSurf& thePolyh) + { + return thePolyh.ComponentsBounding(); + } //! Give the tolerance of the polygon. - static Standard_Real DeflectionOverEstimation(const HLRBRep_ThePolyhedronOfInterCSurf& thePolyh); + static Standard_Real DeflectionOverEstimation(const HLRBRep_ThePolyhedronOfInterCSurf& thePolyh) + { + return thePolyh.DeflectionOverEstimation(); + } //! Give the number of triangles in this polyhedral surface. - static Standard_Integer NbTriangles(const HLRBRep_ThePolyhedronOfInterCSurf& thePolyh); + static Standard_Integer NbTriangles(const HLRBRep_ThePolyhedronOfInterCSurf& thePolyh) + { + return thePolyh.NbTriangles(); + } //! Give the indices of the 3 points of the triangle of //! address Index in the PolyhedronTool. @@ -55,11 +63,17 @@ public: const Standard_Integer Index, Standard_Integer& P1, Standard_Integer& P2, - Standard_Integer& P3); + Standard_Integer& P3) + { + thePolyh.Triangle(Index, P1, P2, P3); + } //! Give the point of index i in the polyhedral surface. static const gp_Pnt& Point(const HLRBRep_ThePolyhedronOfInterCSurf& thePolyh, - const Standard_Integer Index); + const Standard_Integer Index) + { + return thePolyh.Point(Index); + } //! Give the address Tricon of the triangle connexe to //! the triangle of address Triang by the edge Pivot Pedge @@ -72,31 +86,28 @@ public: const Standard_Integer Pivot, const Standard_Integer Pedge, Standard_Integer& TriCon, - Standard_Integer& OtherP); + Standard_Integer& OtherP) + { + return thePolyh.TriConnex(Triang, Pivot, Pedge, TriCon, OtherP); + } //! This method returns true if the edge based on points with //! indices Index1 and Index2 represents a boundary edge. //! It is necessary to take into account the boundary deflection for this edge. static Standard_Boolean IsOnBound(const HLRBRep_ThePolyhedronOfInterCSurf& thePolyh, const Standard_Integer Index1, - const Standard_Integer Index2); + const Standard_Integer Index2) + { + return thePolyh.IsOnBound(Index1, Index2); + } //! This method returns a border deflection of the polyhedron. - static Standard_Real GetBorderDeflection(const HLRBRep_ThePolyhedronOfInterCSurf& thePolyh); + static Standard_Real GetBorderDeflection(const HLRBRep_ThePolyhedronOfInterCSurf& thePolyh) + { + return thePolyh.GetBorderDeflection(); + } Standard_EXPORT static void Dump(const HLRBRep_ThePolyhedronOfInterCSurf& thePolyh); }; -#define ThePolyhedron HLRBRep_ThePolyhedronOfInterCSurf -#define ThePolyhedron_hxx -#define IntCurveSurface_PolyhedronTool HLRBRep_ThePolyhedronToolOfInterCSurf -#define IntCurveSurface_PolyhedronTool_hxx - -#include - -#undef ThePolyhedron -#undef ThePolyhedron_hxx -#undef IntCurveSurface_PolyhedronTool -#undef IntCurveSurface_PolyhedronTool_hxx - #endif // _HLRBRep_ThePolyhedronToolOfInterCSurf_HeaderFile diff --git a/src/ModelingAlgorithms/TKHLR/HLRBRep/HLRBRep_TheQuadCurvExactInterCSurf.cxx b/src/ModelingAlgorithms/TKHLR/HLRBRep/HLRBRep_TheQuadCurvExactInterCSurf.cxx new file mode 100644 index 0000000000..c8a171276e --- /dev/null +++ b/src/ModelingAlgorithms/TKHLR/HLRBRep/HLRBRep_TheQuadCurvExactInterCSurf.cxx @@ -0,0 +1,78 @@ +// Created on: 1992-10-14 +// Created by: Christophe MARION +// Copyright (c) 1992-1999 Matra Datavision +// Copyright (c) 1999-2014 OPEN CASCADE SAS +// +// This file is part of Open CASCADE Technology software library. +// +// This library is free software; you can redistribute it and/or modify it under +// the terms of the GNU Lesser General Public License version 2.1 as published +// by the Free Software Foundation, with special exception defined in the file +// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT +// distribution for complete text of the license and disclaimer of any warranty. +// +// Alternatively, this file may be used under the terms of Open CASCADE +// commercial license or contractual agreement. + +#include + +#include +#include +#include +#include + +#include "../../TKGeomAlgo/IntCurveSurface/IntCurveSurface_QuadricCurveExactInterUtils.pxx" + +//================================================================================================== + +HLRBRep_TheQuadCurvExactInterCSurf::HLRBRep_TheQuadCurvExactInterCSurf(const Standard_Address& S, + const gp_Lin& C) + : nbpnts(-1), + nbintv(-1) +{ + IntCurveSurface_QuadricCurveExactInterUtils::PerformIntersection< + Standard_Address, + HLRBRep_SurfaceTool, + gp_Lin, + HLRBRep_LineTool, + HLRBRep_TheQuadCurvFuncOfTheQuadCurvExactInterCSurf>(S, C, pnts, intv, nbpnts, nbintv); +} + +//================================================================================================== + +Standard_Boolean HLRBRep_TheQuadCurvExactInterCSurf::IsDone() const +{ + return (nbpnts != -1); +} + +//================================================================================================== + +Standard_Integer HLRBRep_TheQuadCurvExactInterCSurf::NbRoots() const +{ + return nbpnts; +} + +//================================================================================================== + +Standard_Integer HLRBRep_TheQuadCurvExactInterCSurf::NbIntervals() const +{ + return nbintv; +} + +//================================================================================================== + +Standard_Real HLRBRep_TheQuadCurvExactInterCSurf::Root(const Standard_Integer Index) const +{ + return pnts(Index); +} + +//================================================================================================== + +void HLRBRep_TheQuadCurvExactInterCSurf::Intervals(const Standard_Integer Index, + Standard_Real& a, + Standard_Real& b) const +{ + Standard_Integer Index2 = Index + Index - 1; + a = intv(Index2); + b = intv(Index2 + 1); +} diff --git a/src/ModelingAlgorithms/TKHLR/HLRBRep/HLRBRep_TheQuadCurvExactInterCSurf_0.cxx b/src/ModelingAlgorithms/TKHLR/HLRBRep/HLRBRep_TheQuadCurvExactInterCSurf_0.cxx deleted file mode 100644 index 3ae376ded1..0000000000 --- a/src/ModelingAlgorithms/TKHLR/HLRBRep/HLRBRep_TheQuadCurvExactInterCSurf_0.cxx +++ /dev/null @@ -1,37 +0,0 @@ -// Created on: 1992-10-14 -// Created by: Christophe MARION -// Copyright (c) 1992-1999 Matra Datavision -// Copyright (c) 1999-2014 OPEN CASCADE SAS -// -// This file is part of Open CASCADE Technology software library. -// -// This library is free software; you can redistribute it and/or modify it under -// the terms of the GNU Lesser General Public License version 2.1 as published -// by the Free Software Foundation, with special exception defined in the file -// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT -// distribution for complete text of the license and disclaimer of any warranty. -// -// Alternatively, this file may be used under the terms of Open CASCADE -// commercial license or contractual agreement. - -#include - -#include -#include -#include -#include - -#define TheSurface Standard_Address -#define TheSurface_hxx -#define TheSurfaceTool HLRBRep_SurfaceTool -#define TheSurfaceTool_hxx -#define TheCurve gp_Lin -#define TheCurve_hxx -#define TheCurveTool HLRBRep_LineTool -#define TheCurveTool_hxx -#define IntCurveSurface_TheQuadCurvFunc HLRBRep_TheQuadCurvFuncOfTheQuadCurvExactInterCSurf -#define IntCurveSurface_TheQuadCurvFunc_hxx \ - -#define IntCurveSurface_QuadricCurveExactInter HLRBRep_TheQuadCurvExactInterCSurf -#define IntCurveSurface_QuadricCurveExactInter_hxx -#include