diff --git a/src/BRepExtrema/BRepExtrema.cdl b/src/BRepExtrema/BRepExtrema.cdl index ca563523a5..35efe3ce9e 100755 --- a/src/BRepExtrema/BRepExtrema.cdl +++ b/src/BRepExtrema/BRepExtrema.cdl @@ -1,8 +1,7 @@ --- File: BRepExtrema.cdl --- Created: Fri Dec 3 15:48:19 1993 --- Author: Christophe MARION --- ----Copyright: Matra Datavision 1993 +-- File: BRepExtrema.cdl +-- Created: Fri Dec 3 15:48:19 1993 +-- Author: Christophe MARION +---Copyright: Matra Datavision 1993 package BRepExtrema @@ -27,37 +26,37 @@ is ---------------------------------------------------------- -- Extrema between two Shapes with triangulation. ---------------------------------------------------------- - class Poly; + imported Poly; ---------------------------------------------------------- -- Extrema between a Point and an Edge. ---------------------------------------------------------- - class ExtPC; + imported ExtPC; ---------------------------------------------------------- -- Extrema between two Edges. ---------------------------------------------------------- - class ExtCC; + imported ExtCC; ---------------------------------------------------------- -- Extrema between a Point and a Face. ---------------------------------------------------------- - class ExtPF; + imported ExtPF; ---------------------------------------------------------- -- Extrema between an Edge and a Face. ---------------------------------------------------------- - class ExtCF; + imported ExtCF; ---------------------------------------------------------- -- Extrema between two Faces. ---------------------------------------------------------- - class ExtFF; + imported ExtFF; ---------------------------------------------------------- @@ -73,8 +72,7 @@ is -- IsInFace => The solution is inside a Face. ---------------------------------------------------------- - enumeration SupportType is IsVertex, IsOnEdge, IsInFace end SupportType; - + imported SupportType; ---------------------------------------------------------- @@ -82,39 +80,21 @@ is -- between two shapes and the corresponding couples of solution points. ---------------------------------------------------------- - class DistShapeShape; - - + imported DistShapeShape; ---------------------------------------------------------- -- This class is used to store a solution on a Shape. -- (used only by class DistShapeShape) ---------------------------------------------------------- - class SolutionElem; - + imported SolutionElem; ---------------------------------------------------------- -- This sequence is used to store all the solution on each Shape. ---------------------------------------------------------- - class SeqOfSolution instantiates Sequence from TCollection - ( SolutionElem from BRepExtrema); - - - - - - ---------------------------------------------------------- - -- This class is used to compute minimum distance between two elementary - -- Shapes ( Vertex, Edge, Face ) (used only by class DistShapeShape) - ---------------------------------------------------------- - private class DistanceSS from BRepExtrema; - - - - - + imported SeqOfSolution; + imported DistanceSS; end BRepExtrema; diff --git a/src/BRepExtrema/BRepExtrema_DistShapeShape.cxx b/src/BRepExtrema/BRepExtrema_DistShapeShape.cxx index 168e1816d7..90ac2bfbd1 100755 --- a/src/BRepExtrema/BRepExtrema_DistShapeShape.cxx +++ b/src/BRepExtrema/BRepExtrema_DistShapeShape.cxx @@ -1,18 +1,16 @@ -// File: BRepExtrema_DistShapeShape.cxx -// Created: Mon Apr 22 17:03:37 1996 -// Modified : Mps(10-04-97) portage WNT -// Author: Maria PUMBORIOS -// Author: Herve LOUESSARD -// +// File: BRepExtrema_DistShapeShape.cxx +// Created: Mon Apr 22 17:03:37 1996 +// Modified: Mps(10-04-97) portage WNT +// Author: Maria PUMBORIOS +// Author: Herve LOUESSARD + +#include -#include #include #include #include #include #include -#include -#include #include #include #include @@ -21,44 +19,40 @@ #include #include #include -#include -#include #include #include #include #include +#include static void Decomposition(const TopoDS_Shape& S, TopTools_IndexedMapOfShape& MapV, TopTools_IndexedMapOfShape& MapE, TopTools_IndexedMapOfShape& MapF) { - MapV.Clear(); - MapE.Clear(); - MapF.Clear(); - TopExp::MapShapes(S,TopAbs_VERTEX,MapV); - TopExp::MapShapes(S,TopAbs_EDGE,MapE); - TopExp::MapShapes(S,TopAbs_FACE,MapF); + MapV.Clear(); + MapE.Clear(); + MapF.Clear(); + TopExp::MapShapes(S,TopAbs_VERTEX,MapV); + TopExp::MapShapes(S,TopAbs_EDGE,MapE); + TopExp::MapShapes(S,TopAbs_FACE,MapF); } static void BoxCalculation(const TopTools_IndexedMapOfShape& Map, Bnd_SeqOfBox& SBox) { - Standard_Integer i = 0; - for(i = 1; i <= Map.Extent(); i++) { - Bnd_Box box; - BRepBndLib::Add( Map(i), box); - SBox.Append(box); - } + for (Standard_Integer i = 1; i <= Map.Extent(); i++) + { + Bnd_Box box; + BRepBndLib::Add(Map(i), box); + SBox.Append(box); + } } -static Standard_Real DistanceInitiale(const TopoDS_Vertex V1, +inline Standard_Real DistanceInitiale(const TopoDS_Vertex V1, const TopoDS_Vertex V2) { - gp_Pnt P1,P2; - P1= BRep_Tool::Pnt(V1); - P2= BRep_Tool::Pnt(V2); - return(P1.Distance(P2)); + return (BRep_Tool::Pnt(V1).Distance(BRep_Tool::Pnt(V2))); } //======================================================================= @@ -71,39 +65,40 @@ void BRepExtrema_DistShapeShape::DistanceMapMap(const TopTools_IndexedMapOfShape const Bnd_SeqOfBox& LBox1, const Bnd_SeqOfBox& LBox2) { - Standard_Integer i = 0, j = 0; - Bnd_Box box1, box2; - TopoDS_Shape S1, S2; - BRepExtrema_SeqOfSolution seq1, seq2; + Standard_Integer i, j; + BRepExtrema_SeqOfSolution seq1, seq2; + + const Standard_Integer n1 = Map1.Extent(); + const Standard_Integer n2 = Map2.Extent(); + for (i = 1; i <= n1; i++) + { + const Bnd_Box &box1 = LBox1.Value(i); + const TopoDS_Shape &S1 = Map1(i); + for (j = 1; j <= n2; j++) + { + const Bnd_Box &box2= LBox2.Value(j); + const TopoDS_Shape &S2 = Map2(j); - Standard_Integer n1 = Map1.Extent(); - Standard_Integer n2 = Map2.Extent(); - for(i = 1; i <= n1; i++) { - box1= LBox1.Value(i); - S1= TopoDS_Shape (Map1(i)); - for(j = 1; j <= n2; j++) { - box2= LBox2.Value(j); - S2 = TopoDS_Shape (Map2(j)); BRepExtrema_DistanceSS dist(S1,S2,box1,box2,myDistRef,myEps); - if(dist.IsDone()) - if(dist.DistValue() < (myDistRef-myEps)) { - ListeDeSolutionShape1.Clear(); - ListeDeSolutionShape2.Clear(); + if (dist.IsDone()) + if(dist.DistValue() < (myDistRef-myEps)) + { + mySolutionsShape1.Clear(); + mySolutionsShape2.Clear(); seq1= dist.Seq1Value(); seq2= dist.Seq2Value(); - ListeDeSolutionShape1.Append(seq1); - ListeDeSolutionShape2.Append(seq2); + mySolutionsShape1.Append(seq1); + mySolutionsShape2.Append(seq2); myDistRef=dist.DistValue(); } - else if(fabs (dist.DistValue()-myDistRef)< myEps ) { + else if(fabs(dist.DistValue()-myDistRef) < myEps) + { seq1= dist.Seq1Value(); seq2= dist.Seq2Value(); - ListeDeSolutionShape1.Append(seq1); - ListeDeSolutionShape2.Append(seq2); - // Modified by Sergey KHROMOV - Tue Mar 6 12:15:39 2001 Begin + mySolutionsShape1.Append(seq1); + mySolutionsShape2.Append(seq2); if (myDistRef > dist.DistValue()) myDistRef=dist.DistValue(); - // Modified by Sergey KHROMOV - Tue Mar 6 12:15:37 2001 End } } } @@ -115,8 +110,14 @@ void BRepExtrema_DistShapeShape::DistanceMapMap(const TopTools_IndexedMapOfShape //======================================================================= BRepExtrema_DistShapeShape::BRepExtrema_DistShapeShape() +: myDistRef(0.), + myDistValue(0.), + myIsDone(Standard_False), + myInnerSol(Standard_False), + myEps(Precision::Confusion()), + myFlag(Extrema_ExtFlag_MINMAX), + myAlgo(Extrema_ExtAlgo_Grad) { - myEps = Precision::Confusion(); } //======================================================================= @@ -124,9 +125,17 @@ BRepExtrema_DistShapeShape::BRepExtrema_DistShapeShape() //purpose : //======================================================================= BRepExtrema_DistShapeShape::BRepExtrema_DistShapeShape(const TopoDS_Shape& Shape1, - const TopoDS_Shape& Shape2) + const TopoDS_Shape& Shape2, + const Extrema_ExtFlag F, + const Extrema_ExtAlgo A) +: myDistRef(0.), + myDistValue(0.), + myIsDone(Standard_False), + myInnerSol(Standard_False), + myEps(Precision::Confusion()), + myFlag(F), + myAlgo(A) { - myEps = Precision::Confusion(); LoadS1(Shape1); LoadS2(Shape2); Perform(); @@ -138,25 +147,23 @@ BRepExtrema_DistShapeShape::BRepExtrema_DistShapeShape(const TopoDS_Shape& Shape //======================================================================= BRepExtrema_DistShapeShape::BRepExtrema_DistShapeShape(const TopoDS_Shape& Shape1, - const TopoDS_Shape& Shape2, - const Standard_Real theDeflection) + const TopoDS_Shape& Shape2, + const Standard_Real theDeflection, + const Extrema_ExtFlag F, + const Extrema_ExtAlgo A) +: myDistRef(0.), + myDistValue(0.), + myIsDone(Standard_False), + myInnerSol(Standard_False), + myEps(theDeflection), + myFlag(F), + myAlgo(A) { - myEps = theDeflection; LoadS1(Shape1); LoadS2(Shape2); Perform(); } -//======================================================================= -//function : SetDeflection -//purpose : -//======================================================================= - -void BRepExtrema_DistShapeShape::SetDeflection(const Standard_Real theDeflection) -{ - myEps = theDeflection; -} - //======================================================================= //function : LoadS1 //purpose : @@ -188,143 +195,110 @@ Standard_Boolean BRepExtrema_DistShapeShape::Perform() { myIsDone=Standard_False; myInnerSol=Standard_False; - ListeDeSolutionShape1.Clear(); - ListeDeSolutionShape2.Clear(); - - if( myShape1.IsNull() || myShape2.IsNull() ) + mySolutionsShape1.Clear(); + mySolutionsShape2.Clear(); + + if ( myShape1.IsNull() || myShape2.IsNull() ) return Standard_False; + TopoDS_Vertex V; Bnd_SeqOfBox BV1, BV2, BE1, BE2, BF1, BF2; - Standard_Real tol = 0.001; - gp_Pnt P; - Standard_Integer nbv1,nbv2; + const Standard_Real tol = 0.001; - // traitement des solides - TopAbs_ShapeEnum Type1 = myShape1.ShapeType(); - TopAbs_ShapeEnum Type2 = myShape2.ShapeType(); - if((Type1==TopAbs_SOLID) || (Type1 == TopAbs_COMPSOLID)) { + // Treatment of solids + const TopAbs_ShapeEnum Type1 = myShape1.ShapeType(); + if ((Type1==TopAbs_SOLID) || (Type1 == TopAbs_COMPSOLID)) + { BRepClass3d_SolidClassifier Classi(myShape1); - nbv2=myMapV2.Extent(); - nbv1=0; - while ( (nbv1 myEps ) DistanceMapMap(myMapF1,myMapF2,BF1,BF2); // Modified by Sergey KHROMOV - Tue Mar 6 11:55:03 2001 Begin - Standard_Integer i = 0; - for(i = 1; i <= ListeDeSolutionShape1.Length(); i++) - if (ListeDeSolutionShape1.Value(i).Dist() > myDistRef + myEps) { - ListeDeSolutionShape1.Remove(i); - ListeDeSolutionShape2.Remove(i); + Standard_Integer i = 1; + for (; i <= mySolutionsShape1.Length(); i++) + if (mySolutionsShape1.Value(i).Dist() > myDistRef + myEps) + { + mySolutionsShape1.Remove(i); + mySolutionsShape2.Remove(i); } // Modified by Sergey KHROMOV - Tue Mar 6 11:55:04 2001 End - myNbSolution = ListeDeSolutionShape1.Length(); - if( myNbSolution > 0 ) - myIsDone = Standard_True; - else - myIsDone = Standard_False; + myIsDone = ( mySolutionsShape1.Length() > 0 ); } return myIsDone; } -//======================================================================= -//function : -//purpose : -//======================================================================= - -Standard_Boolean BRepExtrema_DistShapeShape:: InnerSolution () const -{ - return (myInnerSol); -} - -//======================================================================= -//function : IsDone -//purpose : -//======================================================================= - -Standard_Boolean BRepExtrema_DistShapeShape::IsDone() const -{ - return (myIsDone); -} - -//======================================================================= -//function : NbSolution -//purpose : -//======================================================================= - -Standard_Integer BRepExtrema_DistShapeShape::NbSolution() const -{ - if (myIsDone == Standard_False) { - StdFail_NotDone::Raise - ("BRepExtrema_DistShapeShape::NbSolution: There's no solution "); - } - return (myNbSolution); -} - //======================================================================= //function : Value //purpose : @@ -332,83 +306,10 @@ Standard_Integer BRepExtrema_DistShapeShape::NbSolution() const Standard_Real BRepExtrema_DistShapeShape::Value() const { - if (myIsDone == Standard_False) { - StdFail_NotDone::Raise - ("BRepExtrema_DistShapeShape::Value: There's no solution "); - } - return (myDistRef); -} + if (!myIsDone) + StdFail_NotDone::Raise("BRepExtrema_DistShapeShape::Value: There's no solution "); -//======================================================================= -//function : PointOnShape1 -//purpose : -//======================================================================= - -gp_Pnt BRepExtrema_DistShapeShape::PointOnShape1(const Standard_Integer N) const -{ - if (myIsDone == Standard_False) - { StdFail_NotDone::Raise - ("BRepExtrema_DistShapeShape::PointOnShape1: There's no solution "); - } - if ((N<1)||(N>myNbSolution)) - { Standard_OutOfRange::Raise - ("BRepExtrema_DistShapeShape::PointOnShape1: Nth solution doesn't exist "); - } - return ((ListeDeSolutionShape1.Value(N)).Point()); -} - -//======================================================================= -//function : PointOnShape2 -//purpose : -//======================================================================= - -gp_Pnt BRepExtrema_DistShapeShape::PointOnShape2(const Standard_Integer N) const -{ - if (myIsDone == Standard_False) - { StdFail_NotDone::Raise - ("BRepExtrema_DistShapeShape::PointOnShape2: There's no solution "); - } - if ((N<1)||(N>myNbSolution)) - { Standard_OutOfRange::Raise - ("BRepExtrema_DistShapeShape::PointOnShape2: Nth solution doesn't exist "); - } - return ((ListeDeSolutionShape2.Value(N)).Point()); -} - -//======================================================================= -//function : SupportTypeShape1 -//purpose : -//======================================================================= - -BRepExtrema_SupportType BRepExtrema_DistShapeShape::SupportTypeShape1(const Standard_Integer N) const -{ - if (myIsDone == Standard_False) - { StdFail_NotDone::Raise - ("BRepExtrema_DistShapeShape::SupportTypeShape1: There's no solution "); - } - if ((N<1)||(N>myNbSolution)) - { Standard_OutOfRange::Raise - ("BRepExtrema_DistShapeShape::SupportTypeShape1: Nth solution doesn't exist "); - } - return ((ListeDeSolutionShape1.Value(N)).SupportKind()); -} - -//======================================================================= -//function : SupportTypeShape2 -//purpose : -//======================================================================= - -BRepExtrema_SupportType BRepExtrema_DistShapeShape::SupportTypeShape2(const Standard_Integer N) const -{ - if (myIsDone == Standard_False) - { StdFail_NotDone::Raise - ("BRepExtrema_DistShapeShape::SupportTypeShape2: There's no solution "); - } - if ((N<1)||(N>myNbSolution)) - { Standard_OutOfRange::Raise - ("BRepExtrema_DistShapeShape::SupportTypeShape2: Nth solution doesn't exist "); - } - return ((ListeDeSolutionShape2.Value(N)).SupportKind()); + return myDistRef; } //======================================================================= @@ -416,30 +317,19 @@ BRepExtrema_SupportType BRepExtrema_DistShapeShape::SupportTypeShape2(const Stan //purpose : //======================================================================= -TopoDS_Shape BRepExtrema_DistShapeShape::SupportOnShape1(const Standard_Integer N) const +TopoDS_Shape BRepExtrema_DistShapeShape::SupportOnShape1(const Standard_Integer N) const { - BRepExtrema_SupportType Type; - TopoDS_Shape a_shape; - - if (myIsDone == Standard_False) - { StdFail_NotDone::Raise - ("BRepExtrema_DistShapeShape::SupportOnShape1: There's no solution "); - } - if ((N<1)||(N>myNbSolution)) - { Standard_OutOfRange::Raise - ("BRepExtrema_DistShapeShape::SupportOnShape1: Nth solution doesn't exist "); - } - Type = ((ListeDeSolutionShape1.Value(N)).SupportKind()); - switch ( Type) - { case BRepExtrema_IsVertex : a_shape=ListeDeSolutionShape1.Value(N).Vertex(); - break; - case BRepExtrema_IsOnEdge : a_shape=ListeDeSolutionShape1.Value(N).Edge(); - break; - case BRepExtrema_IsInFace : a_shape=ListeDeSolutionShape1.Value(N).Face(); - break; - default :{} - } - return a_shape ; + if (!myIsDone) + StdFail_NotDone::Raise("BRepExtrema_DistShapeShape::SupportOnShape1: There's no solution "); + + const BRepExtrema_SolutionElem &sol = mySolutionsShape1.Value(N); + switch (sol.SupportKind()) + { + case BRepExtrema_IsVertex : return sol.Vertex(); + case BRepExtrema_IsOnEdge : return sol.Edge(); + case BRepExtrema_IsInFace : return sol.Face(); + } + return TopoDS_Shape(); } //======================================================================= @@ -449,28 +339,17 @@ TopoDS_Shape BRepExtrema_DistShapeShape::SupportOnShape1(const Standard_Integer TopoDS_Shape BRepExtrema_DistShapeShape::SupportOnShape2(const Standard_Integer N) const { - BRepExtrema_SupportType Type; - TopoDS_Shape a_shape ; - - if (myIsDone == Standard_False) - { StdFail_NotDone::Raise - ("BRepExtrema_DistShapeShape::SupportOnShape2: There's no solution "); - } - if ((N<1)||(N>myNbSolution)) - { Standard_OutOfRange::Raise - ("BRepExtrema_DistShapeShape::SupportOnShape2: Nth solution doesn't exist "); - } - Type = ((ListeDeSolutionShape2.Value(N)).SupportKind()); - switch ( Type) - { case BRepExtrema_IsVertex : a_shape=ListeDeSolutionShape2.Value(N).Vertex(); - break; - case BRepExtrema_IsOnEdge : a_shape=ListeDeSolutionShape2.Value(N).Edge(); - break; - case BRepExtrema_IsInFace : a_shape=ListeDeSolutionShape2.Value(N).Face(); - break; - default :{} - } - return a_shape ; + if (!myIsDone) + StdFail_NotDone::Raise("BRepExtrema_DistShapeShape::SupportOnShape2: There's no solution "); + + const BRepExtrema_SolutionElem &sol = mySolutionsShape2.Value(N); + switch (sol.SupportKind()) + { + case BRepExtrema_IsVertex : return sol.Vertex(); + case BRepExtrema_IsOnEdge : return sol.Edge(); + case BRepExtrema_IsInFace : return sol.Face(); + } + return TopoDS_Shape(); } //======================================================================= @@ -480,24 +359,15 @@ TopoDS_Shape BRepExtrema_DistShapeShape::SupportOnShape2(const Standard_Integer void BRepExtrema_DistShapeShape::ParOnEdgeS1(const Standard_Integer N, Standard_Real& t) const { - BRepExtrema_SupportType Type; - - if (myIsDone == Standard_False) - { StdFail_NotDone::Raise - ("BRepExtrema_DistShapeShape::ParOnEdgeS1: There's no solution "); - } - if ((N<1)||(N>myNbSolution)) - { Standard_OutOfRange::Raise - ("BRepExtrema_DistShapeShape::ParOnEdgeS1: Nth solution doesn't exist "); - } + if (!myIsDone) + StdFail_NotDone::Raise("BRepExtrema_DistShapeShape::ParOnEdgeS1: There's no solution"); - Type = ((ListeDeSolutionShape1.Value(N)).SupportKind()); - if (Type != BRepExtrema_IsOnEdge) - { BRepExtrema_UnCompatibleShape::Raise - ("BRepExtrema_DistShapeShape::ParOnEdgeS1:ParOnEdgeS1 is impossible without EDGE "); - } + const BRepExtrema_SolutionElem &sol = mySolutionsShape1.Value(N); + if (sol.SupportKind() != BRepExtrema_IsOnEdge) + BRepExtrema_UnCompatibleShape::Raise + ("BRepExtrema_DistShapeShape::ParOnEdgeS1: ParOnEdgeS1 is impossible without EDGE"); - (ListeDeSolutionShape1.Value(N)).EdgeParameter(t); + sol.EdgeParameter(t); } //======================================================================= @@ -507,24 +377,15 @@ void BRepExtrema_DistShapeShape::ParOnEdgeS1(const Standard_Integer N, Standard_ void BRepExtrema_DistShapeShape::ParOnEdgeS2(const Standard_Integer N, Standard_Real& t) const { - BRepExtrema_SupportType Type; + if (!myIsDone) + StdFail_NotDone::Raise("BRepExtrema_DistShapeShape::ParOnEdgeS2: There's no solution"); - if (myIsDone == Standard_False) - { StdFail_NotDone::Raise - ("BRepExtrema_DistShapeShape::ParOnEdgeS2: There's no solution "); - } - if ((N<1)||(N>myNbSolution)) - { Standard_OutOfRange::Raise - ("BRepExtrema_DistShapeShape::ParOnEdgeS2: Nth solution doesn't exist "); - } - - Type = ((ListeDeSolutionShape2.Value(N)).SupportKind()); - if (Type != BRepExtrema_IsOnEdge) - { BRepExtrema_UnCompatibleShape::Raise - ("BRepExtrema_DistShapeShape::ParOnEdgeS2:ParOnEdgeS2 is impossible without EDGE "); - } + const BRepExtrema_SolutionElem &sol = mySolutionsShape2.Value(N); + if (sol.SupportKind() != BRepExtrema_IsOnEdge) + BRepExtrema_UnCompatibleShape::Raise + ("BRepExtrema_DistShapeShape::ParOnEdgeS2: ParOnEdgeS2 is impossible without EDGE"); - (ListeDeSolutionShape2.Value(N)).EdgeParameter(t); + sol.EdgeParameter(t); } //======================================================================= @@ -534,46 +395,33 @@ void BRepExtrema_DistShapeShape::ParOnEdgeS2(const Standard_Integer N, Standard void BRepExtrema_DistShapeShape::ParOnFaceS1(const Standard_Integer N, Standard_Real& u, Standard_Real& v) const { - BRepExtrema_SupportType Type; + if (!myIsDone) + StdFail_NotDone::Raise("BRepExtrema_DistShapeShape::ParOnFaceS1: There's no solution"); - if (myIsDone == Standard_False) - { StdFail_NotDone::Raise - ("BRepExtrema_DistShapeShape::ParOnFaceS1: There's no solution "); - } - if ((N<1)||(N>myNbSolution)) - { Standard_OutOfRange::Raise - ("BRepExtrema_DistShapeShape::ParOnFaceS1: Nth solution doesn't exist "); - } - - Type = ((ListeDeSolutionShape1.Value(N)).SupportKind()); - if (Type != BRepExtrema_IsInFace) - { BRepExtrema_UnCompatibleShape::Raise - ("BRepExtrema_DistShapeShape::ParOnFaceS1:ParOnFaceS1 is impossible without FACE "); - } + const BRepExtrema_SolutionElem &sol = mySolutionsShape1.Value(N); + if (sol.SupportKind() != BRepExtrema_IsInFace) + BRepExtrema_UnCompatibleShape::Raise + ("BRepExtrema_DistShapeShape::ParOnFaceS1: ParOnFaceS1 is impossible without FACE"); - (ListeDeSolutionShape1.Value(N)).FaceParameter(u, v); + sol.FaceParameter(u, v); } +//======================================================================= +//function : ParOnFaceS2 +//purpose : +//======================================================================= + void BRepExtrema_DistShapeShape::ParOnFaceS2(const Standard_Integer N, Standard_Real& u, Standard_Real& v) const { - BRepExtrema_SupportType Type; + if (!myIsDone) + StdFail_NotDone::Raise("BRepExtrema_DistShapeShape::ParOnFaceS2: There's no solution"); - if (myIsDone == Standard_False) - { StdFail_NotDone::Raise - ("BRepExtrema_DistShapeShape::ParOnFaceS2: There's no solution "); - } - if ((N<1)||(N>myNbSolution)) - { Standard_OutOfRange::Raise - ("BRepExtrema_DistShapeShape::ParOnFaceS2: Nth solution doesn't exist "); - } - Type = ((ListeDeSolutionShape2.Value(N)).SupportKind()); - if (Type != BRepExtrema_IsInFace) - { BRepExtrema_UnCompatibleShape::Raise - ("BRepExtrema_DistShapeShape::ParOnFaceS2:ParOnFaceS2 is impossible without FACE "); - } + const BRepExtrema_SolutionElem &sol = mySolutionsShape2.Value(N); + if (sol.SupportKind() != BRepExtrema_IsInFace) + BRepExtrema_UnCompatibleShape::Raise + ("BRepExtrema_DistShapeShape::ParOnFaceS2:ParOnFaceS2 is impossible without FACE "); - (ListeDeSolutionShape2.Value(N)).FaceParameter(u, v); - + sol.FaceParameter(u, v); } //======================================================================= @@ -585,13 +433,13 @@ void BRepExtrema_DistShapeShape::Dump(Standard_OStream& o) const { Standard_Integer i; Standard_Real r1,r2; - BRepExtrema_SupportType Type1, Type2; o<< "the distance value is : " << Value()< +#endif +#ifndef _Standard_Macro_HeaderFile +#include +#endif + +#ifndef _Standard_Integer_HeaderFile +#include +#endif +#ifndef _Standard_Real_HeaderFile +#include +#endif +#ifndef _Standard_Boolean_HeaderFile +#include +#endif +#ifndef _BRepExtrema_SeqOfSolution_HeaderFile +#include +#endif +#ifndef _BRepExtrema_SolutionElem_HeaderFile +#include +#endif +#ifndef _TopoDS_Shape_HeaderFile +#include +#endif +#ifndef _TopTools_IndexedMapOfShape_HeaderFile +#include +#endif +#ifndef _Extrema_ExtFlag_HeaderFile +#include +#endif +#ifndef _Extrema_ExtAlgo_HeaderFile +#include +#endif +#ifndef _BRepExtrema_SupportType_HeaderFile +#include +#endif +#ifndef _Standard_OStream_HeaderFile +#include +#endif +#ifndef _gp_Pnt_HeaderFile +#include +#endif +class TopoDS_Shape; +class TopTools_IndexedMapOfShape; +class Bnd_SeqOfBox; + + +//! This class provides tools to compute minimum distance
+//! between two Shapes (Compound,CompSolid, Solid, Shell, Face, Wire, Edge, Vertex).
+class BRepExtrema_DistShapeShape +{ + public: + + void* operator new(size_t,void* anAddress) + { + return anAddress; + } + void* operator new(size_t size) + { + return Standard::Allocate(size); + } + void operator delete(void *anAddress) + { + if (anAddress) Standard::Free((Standard_Address&)anAddress); + } + + //! create empty tool
+ Standard_EXPORT BRepExtrema_DistShapeShape(); + //! computation of the minimum distance (value and pair of points) using default deflection
+ //! Default value is Precision::Confusion().
+ Standard_EXPORT BRepExtrema_DistShapeShape(const TopoDS_Shape& Shape1,const TopoDS_Shape& Shape2,const Extrema_ExtFlag F = Extrema_ExtFlag_MINMAX,const Extrema_ExtAlgo A = Extrema_ExtAlgo_Grad); + //! create tool and load both shapes into it
+ Standard_EXPORT BRepExtrema_DistShapeShape(const TopoDS_Shape& Shape1,const TopoDS_Shape& Shape2,const Standard_Real theDeflection,const Extrema_ExtFlag F = Extrema_ExtFlag_MINMAX,const Extrema_ExtAlgo A = Extrema_ExtAlgo_Grad); + + Standard_EXPORT void SetDeflection(const Standard_Real theDeflection) + { + myEps = theDeflection; + } + //! load first shape into extrema
+ Standard_EXPORT void LoadS1(const TopoDS_Shape& Shape1); + //! load second shape into extrema
+ Standard_EXPORT void LoadS2(const TopoDS_Shape& Shape1); + //! computation of the minimum distance (value and
+ //! couple of points). Parameter theDeflection is used
+ //! to specify a maximum deviation of extreme distances
+ //! from the minimum one.
+ //! Returns IsDone status.
+ Standard_EXPORT Standard_Boolean Perform(); + //! True if the minimum distance is found.
+ Standard_EXPORT Standard_Boolean IsDone() const + { + return myIsDone; + } + //! Returns the number of solutions satisfying the minimum distance.
+ Standard_EXPORT Standard_Integer NbSolution() const + { + return mySolutionsShape1.Length(); + } + //! Returns the value of the minimum distance.
+ Standard_EXPORT Standard_Real Value() const; + //! True if one of the shapes is a solid and the other shape
+ //! is completely or partially inside the solid.
+ Standard_EXPORT Standard_Boolean InnerSolution() const + { + return myInnerSol; + } + //! Returns the Point corresponding to the th solution on the first Shape
+ Standard_EXPORT const gp_Pnt & PointOnShape1(const Standard_Integer N) const + { + return mySolutionsShape1.Value(N).Point(); + } + //! Returns the Point corresponding to the th solution on the second Shape
+ Standard_EXPORT const gp_Pnt & PointOnShape2(const Standard_Integer N) const + { + return mySolutionsShape2.Value(N).Point(); + } + //! gives the type of the support where the Nth solution on the first shape is situated:
+ //! IsVertex => the Nth solution on the first shape is a Vertex
+ //! IsOnEdge => the Nth soluion on the first shape is on a Edge
+ //! IsInFace => the Nth solution on the first shape is inside a face
+ //! the corresponding support is obtained by the method SupportOnShape1
+ Standard_EXPORT BRepExtrema_SupportType SupportTypeShape1(const Standard_Integer N) const + { + return mySolutionsShape1.Value(N).SupportKind(); + } + //! gives the type of the support where the Nth solution on the second shape is situated:
+ //! IsVertex => the Nth solution on the second shape is a Vertex
+ //! IsOnEdge => the Nth soluion on the secondt shape is on a Edge
+ //! IsInFace => the Nth solution on the second shape is inside a face
+ //! the corresponding support is obtained by the method SupportOnShape2
+ Standard_EXPORT BRepExtrema_SupportType SupportTypeShape2(const Standard_Integer N) const + { + return mySolutionsShape2.Value(N).SupportKind(); + } + //! gives the support where the Nth solution on the first shape is situated.
+ //! This support can be a Vertex, an Edge or a Face.
+ Standard_EXPORT TopoDS_Shape SupportOnShape1(const Standard_Integer N) const; + //! gives the support where the Nth solution on the second shape is situated.
+ //! This support can be a Vertex, an Edge or a Face.
+ Standard_EXPORT TopoDS_Shape SupportOnShape2(const Standard_Integer N) const; + //! gives the corresponding parameter t if the Nth solution
+ //! is situated on an Egde of the first shape
+ Standard_EXPORT void ParOnEdgeS1(const Standard_Integer N,Standard_Real& t) const; + //! gives the corresponding parameter t if the Nth solution
+ //! is situated on an Egde of the first shape
+ Standard_EXPORT void ParOnEdgeS2(const Standard_Integer N,Standard_Real& t) const; + //! gives the corresponding parameters (U,V) if the Nth solution
+ //! is situated on an face of the first shape
+ Standard_EXPORT void ParOnFaceS1(const Standard_Integer N,Standard_Real& u,Standard_Real& v) const; + //! gives the corresponding parameters (U,V) if the Nth solution
+ //! is situated on an Face of the second shape
+ Standard_EXPORT void ParOnFaceS2(const Standard_Integer N,Standard_Real& u,Standard_Real& v) const; + //! Prints on the stream o information on the current state of the object.
+ Standard_EXPORT void Dump(Standard_OStream& o) const; + + Standard_EXPORT void SetFlag(const Extrema_ExtFlag F) + { + myFlag = F; + } + + Standard_EXPORT void SetAlgo(const Extrema_ExtAlgo A) + { + myAlgo = A; + } + +private: + + //! computes the minimum distance between two maps of shapes (Face,Edge,Vertex)
+ Standard_EXPORT void DistanceMapMap(const TopTools_IndexedMapOfShape& Map1,const TopTools_IndexedMapOfShape& Map2,const Bnd_SeqOfBox& LBox1,const Bnd_SeqOfBox& LBox2); + + Standard_Real myDistRef; + Standard_Real myDistValue; + Standard_Boolean myIsDone; + BRepExtrema_SeqOfSolution mySolutionsShape1; + BRepExtrema_SeqOfSolution mySolutionsShape2; + Standard_Boolean myInnerSol; + Standard_Real myEps; + TopoDS_Shape myShape1; + TopoDS_Shape myShape2; + TopTools_IndexedMapOfShape myMapV1; + TopTools_IndexedMapOfShape myMapV2; + TopTools_IndexedMapOfShape myMapE1; + TopTools_IndexedMapOfShape myMapE2; + TopTools_IndexedMapOfShape myMapF1; + TopTools_IndexedMapOfShape myMapF2; + Extrema_ExtFlag myFlag; + Extrema_ExtAlgo myAlgo; +}; + +#endif diff --git a/src/BRepExtrema/BRepExtrema_DistanceSS.cxx b/src/BRepExtrema/BRepExtrema_DistanceSS.cxx index 22e60db5b5..828e4f1f6f 100755 --- a/src/BRepExtrema/BRepExtrema_DistanceSS.cxx +++ b/src/BRepExtrema/BRepExtrema_DistanceSS.cxx @@ -1,18 +1,18 @@ -// File: BRepExtrema_DistanceSS.cxx -// Created: Mon Apr 22 17:03:37 1996 +// File: BRepExtrema_DistanceSS.cxx +// Created: Mon Apr 22 17:03:37 1996 // Author: Maria PUMBORIOS -// Author: Herve LOUESSARD -// +// Author: Herve LOUESSARD +// Modified: Sergey ZERCHANINOV + +#include -#include #include #include #include #include #include #include -#include #include #include #include @@ -23,6 +23,7 @@ #include #include #include +#include #include #include #include @@ -45,385 +46,331 @@ #include - -/*********************************************************************************/ /*********************************************************************************/ //------------------------------------------------------------------------------ // function: TRI_SOLUTION //------------------------------------------------------------------------------ -void TRI_SOLUTION (const BRepExtrema_SeqOfSolution& SeqSol, - const gp_Pnt& Pt, Standard_Boolean& inserer ) +static Standard_Boolean TRI_SOLUTION (const BRepExtrema_SeqOfSolution& SeqSol, const gp_Pnt& Pt) { - inserer = Standard_True; - Standard_Integer Nbsol= SeqSol.Length(); - Standard_Integer i; - Standard_Real dst; - for (i=1;i<=Nbsol;i++) - {gp_Pnt P1=SeqSol.Value(i).Point(); - dst=P1.Distance(Pt); - if (dst<=Precision::Confusion()) inserer=Standard_False;} + const Standard_Integer Nbsol = SeqSol.Length(); + for (Standard_Integer i = 1; i <= Nbsol; i++) + { + const Standard_Real dst = SeqSol.Value(i).Point().Distance(Pt); + if (dst <= Precision::Confusion()) return Standard_False; + } + return Standard_True; } //------------------------------------------------------------------------------ // function: MIN_SOLUTION //------------------------------------------------------------------------------ -void MIN_SOLUTION (const BRepExtrema_SeqOfSolution& SeqSol1, - const BRepExtrema_SeqOfSolution& SeqSol2, - const Standard_Real& DstRef, - const Standard_Real& Eps, - BRepExtrema_SeqOfSolution& seqSol1, - BRepExtrema_SeqOfSolution& seqSol2) +static void MIN_SOLUTION (const BRepExtrema_SeqOfSolution& SeqSol1, + const BRepExtrema_SeqOfSolution& SeqSol2, + const Standard_Real DstRef, + const Standard_Real Eps, + BRepExtrema_SeqOfSolution& seqSol1, + BRepExtrema_SeqOfSolution& seqSol2) { - Standard_Real dst1; - Standard_Integer nbSol = SeqSol1.Length(); - - for (Standard_Integer i = 1; i<=nbSol; i++) - { - dst1 = SeqSol1.Value(i).Dist(); - - if (fabs(dst1 - DstRef) < Eps) + const Standard_Integer nbSol = SeqSol1.Length(); + for (Standard_Integer i = 1; i <= nbSol; i++) + { + const Standard_Real dst1 = SeqSol1.Value(i).Dist(); + if (fabs(dst1 - DstRef) < Eps) { - seqSol1.Append(SeqSol1.Value(i)); - seqSol2.Append(SeqSol2.Value(i)); + seqSol1.Append(SeqSol1.Value(i)); + seqSol2.Append(SeqSol2.Value(i)); } - } + } } - //------------------------------------------------------------------------------ // function: TRIM_INFINIT_EDGE //------------------------------------------------------------------------------ -void TRIM_INFINIT_EDGE(const TopoDS_Edge& S1, - const TopoDS_Edge& S2, - TopoDS_Edge& aResEdge, - Standard_Boolean& bIsTrim1, - Standard_Boolean& bIsTrim2) +static void TRIM_INFINIT_EDGE(const TopoDS_Edge& S1, const TopoDS_Edge& S2, TopoDS_Edge& aResEdge, + Standard_Boolean& bIsTrim1, Standard_Boolean& bIsTrim2) { - if ( BRep_Tool::Degenerated(S1) || - BRep_Tool::Degenerated(S2) ) + if ( BRep_Tool::Degenerated(S1) || BRep_Tool::Degenerated(S2) ) return; aResEdge = S2; Standard_Real aFirst1, aLast1, aFirst2, aLast2; - Handle(Geom_Curve) pCurv; Handle(Geom_Curve) pCurv1 = BRep_Tool::Curve(S1, aFirst1, aLast1); Handle(Geom_Curve) pCurv2 = BRep_Tool::Curve(S2, aFirst2, aLast2); - Standard_Real Umin, Umax; - Standard_Boolean bUmin, bUmax; - bUmin = bUmax = Standard_False; - if (Precision::IsInfinite(aFirst1) && Precision::IsInfinite(aLast1) && Precision::IsInfinite(aFirst2) && Precision::IsInfinite(aLast2)) return; - - if ( !pCurv1.IsNull() && (Precision::IsInfinite(aFirst1) || - Precision::IsInfinite(aLast1)) ) + Standard_Real Umin, Umax; + Standard_Boolean bUmin, bUmax; + bUmin = bUmax = Standard_False; + + Handle(Geom_Curve) pCurv; + if ( !pCurv1.IsNull() && (Precision::IsInfinite(aFirst1) || Precision::IsInfinite(aLast1)) ) + { + pCurv = pCurv1; + bIsTrim1 = Standard_True; + if (!Precision::IsInfinite(aFirst1)) { - pCurv = pCurv1; - bIsTrim1 = Standard_True; - if (!Precision::IsInfinite(aFirst1)) - { - bUmin = Standard_True; - Umin = aFirst1; - } - else if (!Precision::IsInfinite(aLast1)) - { - bUmax = Standard_True; - Umax = aLast1; - } + bUmin = Standard_True; + Umin = aFirst1; } - else if ( !pCurv2.IsNull() && (Precision::IsInfinite(aFirst2) || - Precision::IsInfinite(aLast2)) ) + else if (!Precision::IsInfinite(aLast1)) { - pCurv = pCurv2; - bIsTrim2 = Standard_True; - if (!Precision::IsInfinite(aFirst2)) - { - bUmin = Standard_True; - Umin = aFirst2; - } - else if (!Precision::IsInfinite(aLast2)) - { - bUmax = Standard_True; - Umax = aLast2; - } + bUmax = Standard_True; + Umax = aLast1; } + } + else if ( !pCurv2.IsNull() && (Precision::IsInfinite(aFirst2) || Precision::IsInfinite(aLast2)) ) + { + pCurv = pCurv2; + bIsTrim2 = Standard_True; + if (!Precision::IsInfinite(aFirst2)) + { + bUmin = Standard_True; + Umin = aFirst2; + } + else if (!Precision::IsInfinite(aLast2)) + { + bUmax = Standard_True; + Umax = aLast2; + } + } if (bIsTrim1 || bIsTrim2) - { - Bnd_Box aEdgeBox; - if (bIsTrim1) - BRepBndLib::Add(S2, aEdgeBox); - if (bIsTrim2) - BRepBndLib::Add(S1, aEdgeBox); - Standard_Real Xmin, Ymin, Zmin, Xmax, Ymax, Zmax; - aEdgeBox.Get(Xmin, Ymin, Zmin, Xmax, Ymax, Zmax); + { + Bnd_Box aEdgeBox; + if (bIsTrim1) + BRepBndLib::Add(S2, aEdgeBox); + if (bIsTrim2) + BRepBndLib::Add(S1, aEdgeBox); + Standard_Real Xmin, Ymin, Zmin, Xmax, Ymax, Zmax; + aEdgeBox.Get(Xmin, Ymin, Zmin, Xmax, Ymax, Zmax); + const gp_Pnt aPnt0(Xmin, Ymin, Zmin); + const gp_Pnt aPnt1(Xmin, Ymax, Zmin); + const gp_Pnt aPnt2(Xmin, Ymax, Zmax); + const gp_Pnt aPnt3(Xmin, Ymin, Zmax); + const gp_Pnt aPnt4(Xmax, Ymax, Zmin); + const gp_Pnt aPnt5(Xmax, Ymax, Zmax); + const gp_Pnt aPnt6(Xmax, Ymin, Zmax); + const gp_Pnt aPnt7(Xmax, Ymin, Zmin); - TColStd_Array1OfReal arrU(1, 8); - TColgp_Array1OfPnt arrPnt(1, 8); - - gp_Pnt aPnt1(Xmin, Ymin, Zmin); - arrPnt.SetValue(1, aPnt1); - gp_Pnt aPnt2(Xmin, Ymax, Zmin); - arrPnt.SetValue(2, aPnt2); - gp_Pnt aPnt3(Xmin, Ymax, Zmax); - arrPnt.SetValue(3, aPnt3); - gp_Pnt aPnt4(Xmin, Ymin, Zmax); - arrPnt.SetValue(4, aPnt4); - gp_Pnt aPnt5(Xmax, Ymax, Zmin); - arrPnt.SetValue(5, aPnt5); - gp_Pnt aPnt6(Xmax, Ymax, Zmax); - arrPnt.SetValue(6, aPnt6); - gp_Pnt aPnt7(Xmax, Ymin, Zmax); - arrPnt.SetValue(7, aPnt7); - gp_Pnt aPnt8(Xmax, Ymin, Zmin); - arrPnt.SetValue(8, aPnt8); - - Standard_Real U; - Standard_Integer i = 1; - - GeomAPI_ProjectPointOnCurve aProj(aPnt1, pCurv); - - for (i = 1; i <= arrPnt.Length(); i++) - { - gp_Pnt aPnt = arrPnt.Value(i); - aProj.Perform(aPnt); - U = aProj.LowerDistanceParameter(); - arrU.SetValue(i, U); - } - - Standard_Real aU; - - if (!bUmin) - Umin = arrU.Value(1); + Standard_Real arrU[8]; + GeomAPI_ProjectPointOnCurve aProj(aPnt0, pCurv); + /*szv:aProj.Perform(aPnt0);*/ arrU[0] = aProj.LowerDistanceParameter(); + aProj.Perform(aPnt1); arrU[1] = aProj.LowerDistanceParameter(); + aProj.Perform(aPnt2); arrU[2] = aProj.LowerDistanceParameter(); + aProj.Perform(aPnt3); arrU[3] = aProj.LowerDistanceParameter(); + aProj.Perform(aPnt4); arrU[4] = aProj.LowerDistanceParameter(); + aProj.Perform(aPnt5); arrU[5] = aProj.LowerDistanceParameter(); + aProj.Perform(aPnt6); arrU[6] = aProj.LowerDistanceParameter(); + aProj.Perform(aPnt7); arrU[7] = aProj.LowerDistanceParameter(); + + if (!bUmin) + Umin = arrU[0]; - if (!bUmax) - Umax = arrU.Value(1); + if (!bUmax) + Umax = arrU[0]; - for(i = 1; i <= arrU.Length(); i++) + Standard_Integer i = 0; + while (i < 8) { - aU = arrU.Value(i); + const Standard_Real aU = arrU[i++]; if (aU < Umin) Umin = aU; else if (aU > Umax) Umax = aU; - - } - GeomAdaptor_Curve aGAC(pCurv); - Standard_Real tol = Precision::Confusion(); - if (bIsTrim1) - tol = BRep_Tool::Tolerance(S1); - else if (bIsTrim2) - tol = BRep_Tool::Tolerance(S2); - - Standard_Real EpsU = aGAC.Resolution(3*tol); - if (fabs(Umin - Umax) < EpsU) - { - Umin = Umin - EpsU; - Umax = Umax + EpsU; } + Standard_Real tol = Precision::Confusion(); + if (bIsTrim1) + tol = BRep_Tool::Tolerance(S1); + else if (bIsTrim2) + tol = BRep_Tool::Tolerance(S2); - Handle(Geom_Curve) result = new Geom_TrimmedCurve(pCurv, Umin, Umax); - aResEdge = BRepBuilderAPI_MakeEdge(result); + const Standard_Real EpsU = GeomAdaptor_Curve(pCurv).Resolution(3.*tol); + if (fabs(Umin - Umax) < EpsU) + { + Umin -= EpsU; + Umax += EpsU; } + + Handle(Geom_Curve) result = new Geom_TrimmedCurve(pCurv, Umin, Umax); + aResEdge = BRepBuilderAPI_MakeEdge(result); + } } //------------------------------------------------------------------------------ // function: TRIM_INFINIT_FACE //------------------------------------------------------------------------------ -void TRIM_INFINIT_FACE(const TopoDS_Shape& S1, - const TopoDS_Shape& S2, - TopoDS_Face& aResFace, - Standard_Boolean& bIsInfinit) +static void TRIM_INFINIT_FACE(const TopoDS_Shape& S1, const TopoDS_Shape& S2, + TopoDS_Face& aResFace, Standard_Boolean& bIsInfinit) { bIsInfinit = Standard_False; - TopAbs_ShapeEnum Type1, Type2; - Type1 = S1.ShapeType(); - Type2 = S2.ShapeType(); + TopAbs_ShapeEnum Type1 = S1.ShapeType(); + TopAbs_ShapeEnum Type2 = S2.ShapeType(); TopoDS_Edge aE; TopoDS_Face aF; if (Type1 == TopAbs_EDGE && Type2 == TopAbs_FACE) - { - aE = TopoDS::Edge(S1); - if ( BRep_Tool::Degenerated(aE) ) - return; - aF = TopoDS::Face(S2); - } - else if (Type2 == TopAbs_EDGE && Type1 == TopAbs_FACE) - { - aE = TopoDS::Edge(S2); - if ( BRep_Tool::Degenerated(aE) ) - return; - aF = TopoDS::Face(S1); - } - else - { - bIsInfinit = Standard_False; + { + aE = TopoDS::Edge(S1); + if ( BRep_Tool::Degenerated(aE) ) return; - } - Standard_Real Umin, Umax, Vmin, Vmax; + aF = TopoDS::Face(S2); + } + else if (Type2 == TopAbs_EDGE && Type1 == TopAbs_FACE) + { + aE = TopoDS::Edge(S2); + if ( BRep_Tool::Degenerated(aE) ) + return; + aF = TopoDS::Face(S1); + } + else + { + bIsInfinit = Standard_False; + return; + } - Standard_Boolean bIsTrim = Standard_False; - - aResFace = aF; Handle(Geom_Surface) pSurf = BRep_Tool::Surface(aF); - Standard_Real U1, V1, U2, V2; - - Standard_Boolean bRestrict = BRep_Tool::NaturalRestriction(aF); + const Standard_Boolean bRestrict = BRep_Tool::NaturalRestriction(aF); + Standard_Real U1, V1, U2, V2; + Standard_Real Umin, Umax, Vmin, Vmax; Standard_Boolean bUmin, bUmax, bVmin, bVmax; bUmin = bUmax = bVmin = bVmax = Standard_False; + Standard_Boolean bIsTrim = Standard_False; if (bRestrict) + { + pSurf->Bounds(U1, U2, V1, V2); + if (Precision::IsInfinite(U1)) + bIsTrim = Standard_True; + else { - pSurf->Bounds(U1, U2, V1, V2); - if (Precision::IsInfinite(U1)) - bIsTrim = Standard_True; - else - { - Umin = U1; - bUmin = Standard_True; - } + Umin = U1; + bUmin = Standard_True; + } - if (Precision::IsInfinite(U2)) - bIsTrim = Standard_True; - else - { - Umax = U2; - bUmax = Standard_True; - } + if (Precision::IsInfinite(U2)) + bIsTrim = Standard_True; + else + { + Umax = U2; + bUmax = Standard_True; + } - if (Precision::IsInfinite(V1)) - bIsTrim = Standard_True; - else + if (Precision::IsInfinite(V1)) + bIsTrim = Standard_True; + else { - Vmin = V1; - bVmin = Standard_True; + Vmin = V1; + bVmin = Standard_True; } - if (Precision::IsInfinite(V2)) - bIsTrim = Standard_True; - else + if (Precision::IsInfinite(V2)) + bIsTrim = Standard_True; + else { - Vmax = V2; - bVmax = Standard_True; - } + Vmax = V2; + bVmax = Standard_True; } + } else - { - BRepTools::UVBounds(aF, U1, U2, V1, V2); - if (Precision::IsInfinite(U1) && - Precision::IsInfinite(U2) && - Precision::IsInfinite(V1) && - Precision::IsInfinite(V2)) - bIsTrim = Standard_True; - } + { + BRepTools::UVBounds(aF, U1, U2, V1, V2); + if (Precision::IsInfinite(U1) && + Precision::IsInfinite(U2) && + Precision::IsInfinite(V1) && + Precision::IsInfinite(V2)) + bIsTrim = Standard_True; + } if (bIsTrim) - { - Bnd_Box aEdgeBox; - BRepBndLib::Add(aE, aEdgeBox); + { + Bnd_Box aEdgeBox; + BRepBndLib::Add(aE, aEdgeBox); - if(aEdgeBox.IsWhole()) - return; + if(aEdgeBox.IsWhole()) + return; - Standard_Real Xmin, Ymin, Zmin, Xmax, Ymax, Zmax; - aEdgeBox.Get(Xmin, Ymin, Zmin, Xmax, Ymax, Zmax); + Standard_Real Xmin, Ymin, Zmin, Xmax, Ymax, Zmax; + aEdgeBox.Get(Xmin, Ymin, Zmin, Xmax, Ymax, Zmax); - TColStd_Array1OfReal arrU(1, 8); - TColStd_Array1OfReal arrV(1, 8); - TColgp_Array1OfPnt arrPnt(1, 8); + const gp_Pnt aPnt0(Xmin, Ymin, Zmin); + const gp_Pnt aPnt1(Xmin, Ymax, Zmin); + const gp_Pnt aPnt2(Xmin, Ymax, Zmax); + const gp_Pnt aPnt3(Xmin, Ymin, Zmax); + const gp_Pnt aPnt4(Xmax, Ymax, Zmin); + const gp_Pnt aPnt5(Xmax, Ymax, Zmax); + const gp_Pnt aPnt6(Xmax, Ymin, Zmax); + const gp_Pnt aPnt7(Xmax, Ymin, Zmin); - gp_Pnt aPnt1(Xmin, Ymin, Zmin); - arrPnt.SetValue(1, aPnt1); - gp_Pnt aPnt2(Xmin, Ymax, Zmin); - arrPnt.SetValue(2, aPnt2); - gp_Pnt aPnt3(Xmin, Ymax, Zmax); - arrPnt.SetValue(3, aPnt3); - gp_Pnt aPnt4(Xmin, Ymin, Zmax); - arrPnt.SetValue(4, aPnt4); - gp_Pnt aPnt5(Xmax, Ymax, Zmin); - arrPnt.SetValue(5, aPnt5); - gp_Pnt aPnt6(Xmax, Ymax, Zmax); - arrPnt.SetValue(6, aPnt6); - gp_Pnt aPnt7(Xmax, Ymin, Zmax); - arrPnt.SetValue(7, aPnt7); - gp_Pnt aPnt8(Xmax, Ymin, Zmin); - arrPnt.SetValue(8, aPnt8); - - Standard_Real U, V; - Standard_Integer i; - GeomAPI_ProjectPointOnSurf aProj(aPnt1, pSurf); - for (i = 1; i <= arrPnt.Length(); i++) + Standard_Real arrU[8], arrV[8]; + GeomAPI_ProjectPointOnSurf aProj(aPnt0, pSurf); + /*szv:aProj.Perform(aPnt0);*/ if (aProj.IsDone()) aProj.LowerDistanceParameters(arrU[0],arrV[0]); + aProj.Perform(aPnt1); if (aProj.IsDone()) aProj.LowerDistanceParameters(arrU[1],arrV[1]); + aProj.Perform(aPnt2); if (aProj.IsDone()) aProj.LowerDistanceParameters(arrU[2],arrV[2]); + aProj.Perform(aPnt3); if (aProj.IsDone()) aProj.LowerDistanceParameters(arrU[3],arrV[3]); + aProj.Perform(aPnt4); if (aProj.IsDone()) aProj.LowerDistanceParameters(arrU[4],arrV[4]); + aProj.Perform(aPnt5); if (aProj.IsDone()) aProj.LowerDistanceParameters(arrU[5],arrV[5]); + aProj.Perform(aPnt6); if (aProj.IsDone()) aProj.LowerDistanceParameters(arrU[6],arrV[6]); + aProj.Perform(aPnt7); if (aProj.IsDone()) aProj.LowerDistanceParameters(arrU[7],arrV[7]); + + if (!bUmin) + Umin = arrU[0]; + if (!bUmax) + Umax = arrU[0]; + if (!bVmin) + Vmin = arrV[0]; + if (!bVmax) + Vmax = arrV[0]; + + Standard_Integer i = 0; + while (i < 8) { - gp_Pnt aPnt = arrPnt.Value(i); - aProj.Perform(aPnt); - if (aProj.IsDone()) - { - aProj.LowerDistanceParameters(U, V); - arrU.SetValue(i, U); - arrV.SetValue(i, V); - - } - } - - Standard_Real aU, aV; - if (!bUmin) - Umin = arrU.Value(1); - if (!bUmax) - Umax = arrU.Value(1); - if (!bVmin) - Vmin = arrV.Value(1); - if (!bVmax) - Vmax = arrV.Value(1); - - for(i = 1; i <= arrU.Length(); i++) - { - aU = arrU.Value(i); + const Standard_Real aU = arrU[i]; if (aU < Umin) Umin = aU; else if (aU > Umax) Umax = aU; - aV = arrV.Value(i); + const Standard_Real aV = arrV[i]; if (aV < Vmin) Vmin = aV; else if (aV > Vmax) Vmax = aV; } - GeomAdaptor_Surface aGAS(pSurf); - Standard_Real tol = BRep_Tool::Tolerance(aF); - Standard_Real EpsU = aGAS.UResolution(3*tol); - Standard_Real EpsV = aGAS.VResolution(3*tol); - if (fabs(Umin - Umax) < EpsU) - { - Umin = Umin - EpsU; - Umax = Umax + EpsU; - } + GeomAdaptor_Surface aGAS(pSurf); + const Standard_Real tol = BRep_Tool::Tolerance(aF); - if (fabs(Vmin - Vmax) < EpsV) - { - Vmin = Vmin - EpsV; - Vmax = Vmax + EpsV; - } - - Handle(Geom_Surface) result = new Geom_RectangularTrimmedSurface(pSurf, Umin, Umax, Vmin, Vmax); - aResFace = BRepBuilderAPI_MakeFace(result); - - bIsInfinit = Standard_True; + const Standard_Real EpsU = aGAS.UResolution(3.*tol); + if (fabs(Umin - Umax) < EpsU) + { + Umin -= EpsU; + Umax += EpsU; } + + const Standard_Real EpsV = aGAS.VResolution(3.*tol); + if (fabs(Vmin - Vmax) < EpsV) + { + Vmin -= EpsV; + Vmax += EpsV; + } + + Handle(Geom_Surface) result = new Geom_RectangularTrimmedSurface(pSurf, Umin, Umax, Vmin, Vmax); + aResFace = BRepBuilderAPI_MakeFace(result); + + bIsInfinit = Standard_True; + } else bIsInfinit = Standard_False; } @@ -431,1076 +378,670 @@ void TRIM_INFINIT_FACE(const TopoDS_Shape& S1, //------------------------------------------------------------------------------ // static function: PERFORM_C0 //------------------------------------------------------------------------------ -static void PERFORM_C0(TopoDS_Edge S1, - TopoDS_Edge S2, - BRepExtrema_SeqOfSolution& SeqSol1, - BRepExtrema_SeqOfSolution& SeqSol2, - Standard_Real DstRef, - Standard_Real& mDstRef, - const Standard_Real& Eps) +static void PERFORM_C0(const TopoDS_Edge &S1, const TopoDS_Edge &S2, + BRepExtrema_SeqOfSolution& SeqSol1, + BRepExtrema_SeqOfSolution& SeqSol2, + const Standard_Real DstRef, + Standard_Real& mDstRef, + const Standard_Real Eps) { - - if ( BRep_Tool::Degenerated(S1) || - BRep_Tool::Degenerated(S2) ) + if ( BRep_Tool::Degenerated(S1) || BRep_Tool::Degenerated(S2) ) return; + Standard_Integer iE; -// TopoDS_Edge E, Eover; for (iE = 0; iE < 2; iE++) - { - TopoDS_Edge E, Eother; - if (iE == 0) + { + TopoDS_Edge E, Eother; + if (iE == 0) { E = S1; Eother = S2; } - else + else { E = S2; Eother = S1; } - Standard_Real aFirst, aLast, epsP = Precision::PConfusion(), Udeb, Ufin; - Handle(Geom_Curve) pCurv = BRep_Tool::Curve(E, aFirst, aLast); - - Standard_Real aFOther, aLOther; - Handle(Geom_Curve) pCurvOther = BRep_Tool::Curve(Eother, aFOther, aLOther); - + Standard_Real aFirst, aLast; + Handle(Geom_Curve) pCurv = BRep_Tool::Curve(E, aFirst, aLast); - GeomAbs_Shape s = pCurv->Continuity(); - if (s == GeomAbs_C0) + Standard_Real aFOther, aLOther; + Handle(Geom_Curve) pCurvOther = BRep_Tool::Curve(Eother, aFOther, aLOther); + + if (pCurv->Continuity() == GeomAbs_C0) { - GeomAdaptor_Curve aAdaptorCurve(pCurv, aFirst, aLast); - Standard_Integer nbIntervals = aAdaptorCurve.NbIntervals(GeomAbs_C1); - - TColStd_Array1OfReal arrInter(1,1+nbIntervals); - aAdaptorCurve.Intervals(arrInter, GeomAbs_C1); + const Standard_Real epsP = Precision::PConfusion(); - GeomAdaptor_Curve aAdaptorCurveOther(pCurvOther, aFOther, aLOther); - Standard_Integer nbIntervalsOther = aAdaptorCurveOther.NbIntervals(GeomAbs_C1); - TColStd_Array1OfReal arrInterOther(1,1+nbIntervalsOther); - aAdaptorCurveOther.Intervals(arrInterOther, GeomAbs_C1); - - Standard_Real Dstmin, Dst; - gp_Pnt P1,Pt; - gp_Pnt2d PUV; - Standard_Boolean notavertex, inserer; - Standard_Integer i, ii; - BRepClass_FaceClassifier classifier; - Standard_Real aParameter; - for (i=1; i<=arrInter.Length(); i++) - { - gp_Pnt aPnt = aAdaptorCurve.Value(arrInter(i)); - - TopoDS_Vertex V1 = BRepBuilderAPI_MakeVertex(aPnt); - - aParameter = arrInter(i); - BRepExtrema_ExtPC Ext(V1,Eother); - if ( (Ext.IsDone()) && (Ext.NbExt() > 0) ) - { - Standard_Integer NbExtrema=Ext.NbExt(); - - // Recherche de la distance minimum dstmin - Dstmin=sqrt (Ext.SquareDistance(1)); - for (ii=2;ii<=NbExtrema;ii++) - { - Dst=sqrt (Ext.SquareDistance(ii)); - if (Dst Dstmin) - mDstRef=Dstmin; - // Modified by Sergey KHROMOV - Tue Mar 6 12:28:54 2001 End - //myModif=Standard_True; - P1=BRep_Tool::Pnt(V1); - BRepExtrema_SolutionElem Sol1 (Dstmin,P1,BRepExtrema_IsOnEdge,E, aParameter); - BRepExtrema_SolutionElem Sol2 (Dstmin,Pt,BRepExtrema_IsOnEdge,Eother,t); - SeqSol1.Append(iE == 0 ? Sol1 : Sol2); - SeqSol2.Append(iE == 0 ? Sol2 : Sol1); - } - } - } - } - - - } - Standard_Real aParameterOther; - for (Standard_Integer i2 = 1; i2<=arrInterOther.Length(); i2++) - { - gp_Pnt aPntOther = aAdaptorCurveOther.Value(arrInterOther(i2)); - Dst=aPnt.Distance(aPntOther); - aParameterOther = arrInterOther(i2); - if( (Dst< DstRef - Eps ) || (fabs(Dst-DstRef)< Eps )) - { - if (mDstRef > Dst) - mDstRef=Dst; + TColStd_Array1OfReal arrInter(1,1+nbIntervals); + aAdaptorCurve.Intervals(arrInter, GeomAbs_C1); - BRepExtrema_SolutionElem Sol1 (Dst,aPnt,BRepExtrema_IsOnEdge,E, aParameter); - BRepExtrema_SolutionElem Sol2 (Dst,aPntOther, BRepExtrema_IsOnEdge,Eother, aParameterOther); - SeqSol1.Append(iE == 0 ? Sol1 : Sol2); - SeqSol2.Append(iE == 0 ? Sol2 : Sol1); - } + GeomAdaptor_Curve aAdaptorCurveOther(pCurvOther, aFOther, aLOther); + const Standard_Integer nbIntervalsOther = aAdaptorCurveOther.NbIntervals(GeomAbs_C1); + TColStd_Array1OfReal arrInterOther(1,1+nbIntervalsOther); + aAdaptorCurveOther.Intervals(arrInterOther, GeomAbs_C1); - } - } - - - } - } -} + Standard_Real Udeb,Ufin; + BRep_Tool::Range(Eother,Udeb,Ufin); -/*********************************************************************************/ - -BRepExtrema_DistanceSS::BRepExtrema_DistanceSS(const TopoDS_Shape& S1, - const TopoDS_Shape& S2, - const Bnd_Box& B1, - const Bnd_Box& B2, - const Standard_Real DstRef) - -{ - myEps = Precision::Confusion(); - Perform(S1, S2, B1, B2, DstRef); -} - -/*********************************************************************************/ - -BRepExtrema_DistanceSS::BRepExtrema_DistanceSS(const TopoDS_Shape& S1, - const TopoDS_Shape& S2, - const Bnd_Box& B1, - const Bnd_Box& B2, - const Standard_Real DstRef, - const Standard_Real theDeflection) - -{ - myEps = theDeflection; - Perform(S1, S2, B1, B2, DstRef); -} - -/*********************************************************************************/ - -void BRepExtrema_DistanceSS::Perform(const TopoDS_Shape& S1, - const TopoDS_Shape& S2, - const Bnd_Box& B1, - const Bnd_Box& B2, - const Standard_Real DstRef) - -{ -TopAbs_ShapeEnum Type1, Type2; - Type1 = S1.ShapeType(); - Type2 = S2.ShapeType(); -// Modified by Sergey KHROMOV - Tue Mar 6 12:55:05 2001 Begin - myDstRef = DstRef; -// Modified by Sergey KHROMOV - Tue Mar 6 12:55:05 2001 End - TopoDS_Face aTrimFace; - TopoDS_Edge aTrimEdge; - Standard_Boolean bIsInfinit; - switch ( Type1) - { case TopAbs_VERTEX : - switch (Type2) - { case TopAbs_VERTEX : { TopoDS_Vertex V1 = TopoDS::Vertex(S1); - TopoDS_Vertex V2 = TopoDS::Vertex(S2); - Perform ( V1 , V2, B1, B2,DstRef );} - break; - case TopAbs_EDGE : { TopoDS_Vertex V1 = TopoDS::Vertex(S1); - TopoDS_Edge V2 = TopoDS::Edge(S2); - Perform ( V1 , V2, B1, B2,DstRef );} - break; - case TopAbs_FACE : { TopoDS_Vertex V1 = TopoDS::Vertex(S1); - TopoDS_Face V2 = TopoDS::Face(S2); - Perform ( V1 , V2, B1, B2,DstRef );} - break; - default :{} - }break; - - case TopAbs_EDGE : - switch (Type2) - { case TopAbs_VERTEX : { TopoDS_Edge V1 = TopoDS::Edge(S1); - TopoDS_Vertex V2 = TopoDS::Vertex(S2); - Perform ( V1 , V2, B1, B2,DstRef );} - break; - case TopAbs_EDGE : { TopoDS_Edge V1 = TopoDS::Edge(S1); - TopoDS_Edge V2 = TopoDS::Edge(S2); - Standard_Boolean bIsTrim1 = Standard_False; - Standard_Boolean bIsTrim2 = Standard_False; - TRIM_INFINIT_EDGE(V1, V2, aTrimEdge, bIsTrim1, bIsTrim2); - if (bIsTrim1) - V1 = aTrimEdge; - if (bIsTrim2) - V2 = aTrimEdge; - Perform ( V1 , V2, B1, B2,DstRef );} - break; - case TopAbs_FACE : { TopoDS_Edge V1 = TopoDS::Edge(S1); - TopoDS_Face V2 = TopoDS::Face(S2); - TRIM_INFINIT_FACE(V1, V2, aTrimFace, bIsInfinit); - if (bIsInfinit) - V2 = aTrimFace; - Perform ( V1 , V2, B1, B2,DstRef );} - break; - default :{} }break; - - case TopAbs_FACE : - switch (Type2) - { case TopAbs_VERTEX : { TopoDS_Face V1 = TopoDS::Face(S1); - TopoDS_Vertex V2 = TopoDS::Vertex(S2); - Perform ( V1 , V2, B1, B2,DstRef);} - break; - case TopAbs_EDGE : { TopoDS_Face V1 = TopoDS::Face(S1); - TopoDS_Edge V2 = TopoDS::Edge(S2); - TRIM_INFINIT_FACE(V1, V2, aTrimFace, bIsInfinit); - if (bIsInfinit) - V1 = aTrimFace; - Perform ( V1 , V2, B1, B2,DstRef );} - break; - case TopAbs_FACE : { TopoDS_Face V1 = TopoDS::Face(S1); - TopoDS_Face V2 = TopoDS::Face(S2); - Perform( V1 , V2, B1, B2,DstRef);} - break; - default :{} - }break; - default :{} - } -} - -/*********************************************************************************/ - -void BRepExtrema_DistanceSS::Perform(const TopoDS_Vertex& S1, const TopoDS_Vertex& S2, - const Bnd_Box& , -// const Bnd_Box& B2, - const Bnd_Box& , - const Standard_Real DstRef) -{ - gp_Pnt P1,P2; - Standard_Real Dst; - P1= BRep_Tool::Pnt(S1); - P2= BRep_Tool::Pnt(S2); - Dst=P1.Distance(P2); - SeqSolShape1.Clear(); - SeqSolShape2.Clear(); - myModif=Standard_False; - - if( (Dst< DstRef -myEps ) || (fabs(Dst-DstRef)< myEps )) - { -// Modified by Sergey KHROMOV - Tue Mar 6 12:28:51 2001 Begin - if (myDstRef > Dst) - myDstRef=Dst; -// Modified by Sergey KHROMOV - Tue Mar 6 12:28:54 2001 End - myModif=Standard_True; - BRepExtrema_SolutionElem Sol1 (Dst,P1,BRepExtrema_IsVertex,S1); - BRepExtrema_SolutionElem Sol2 (Dst,P2, BRepExtrema_IsVertex,S2); - SeqSolShape1.Append(Sol1); - SeqSolShape2.Append(Sol2); - } -} - -/*********************************************************************************/ - -void BRepExtrema_DistanceSS::Perform(const TopoDS_Vertex& S1, const TopoDS_Edge& S2, - const Bnd_Box& B1, const Bnd_Box& B2, - const Standard_Real DstRef) -{ - Standard_Real Dst,Dstmin,epsP,Udeb,Ufin ; - gp_Pnt Pt,P1; - Standard_Boolean inserer,notavertex; - Standard_Integer i; - - epsP=Precision::PConfusion(); - SeqSolShape1.Clear(); - SeqSolShape2.Clear(); - myModif=Standard_False; - - - if (!BRep_Tool::Degenerated (S2)) { - Dst=B1.Distance(B2); - if ( (Dst< DstRef -myEps ) || (fabs(Dst-DstRef)< myEps )) - { - BRepExtrema_ExtPC Ext(S1,S2); - if ( (Ext.IsDone()) && (Ext.NbExt() > 0) ) - { Standard_Integer NbExtrema=Ext.NbExt(); -// Recherche de la distance minimum dstmin - Dstmin=sqrt(Ext.SquareDistance(1)); - for (i=2;i<=NbExtrema;i++) - {Dst=sqrt(Ext.SquareDistance(i)); - if (Dst Dstmin) - myDstRef=Dstmin; -// Modified by Sergey KHROMOV - Tue Mar 6 12:28:54 2001 End - myModif=Standard_True; - P1=BRep_Tool::Pnt(S1); - BRepExtrema_SolutionElem Sol1 (Dstmin,P1,BRepExtrema_IsVertex,S1); - BRepExtrema_SolutionElem Sol2 (Dstmin,Pt,BRepExtrema_IsOnEdge,S2,t); - SeqSolShape1.Append(Sol1); - SeqSolShape2.Append(Sol2); - } - } - } - } - } - } -} -} - -/*********************************************************************************/ - -void BRepExtrema_DistanceSS::Perform(const TopoDS_Vertex& S1, const TopoDS_Face& S2, - const Bnd_Box& B1, const Bnd_Box& B2, - const Standard_Real DstRef) -{ - Standard_Real Dst,Dstmin,epsP,U,V ; - gp_Pnt P1,Pt; - gp_Pnt2d PUV; - Standard_Boolean inserer,notavertex; - Standard_Integer i; - BRepClass_FaceClassifier classifier; - - epsP=Precision::PConfusion(); - SeqSolShape1.Clear(); - SeqSolShape2.Clear(); - myModif=Standard_False; - - - Dst=B1.Distance(B2); - if ( (Dst< DstRef -myEps ) || (fabs(Dst-DstRef)< myEps )) - { - BRepExtrema_ExtPF Ext(S1,S2); - if ( (Ext.IsDone()) && (Ext.NbExt() > 0) ) - { Standard_Integer NbExtrema=Ext.NbExt(); -// Recherche de la distance minimum dstmin - Dstmin=sqrt(Ext.SquareDistance(1)); - for (i=2;i<=NbExtrema;i++) - {Dst=sqrt (Ext.SquareDistance(i)); - if (Dst Dstmin) - myDstRef=Dstmin; -// Modified by Sergey KHROMOV - Tue Mar 6 12:28:54 2001 End - myModif=Standard_True; - P1=BRep_Tool::Pnt(S1); - BRepExtrema_SolutionElem Sol1 (Dstmin,P1,BRepExtrema_IsVertex,S1); - BRepExtrema_SolutionElem Sol2 (Dstmin,Pt,BRepExtrema_IsInFace,S2,U,V); - SeqSolShape1.Append(Sol1); - SeqSolShape2.Append(Sol2); - } - } - } - } - } - } -} - -/*********************************************************************************/ - -void BRepExtrema_DistanceSS::Perform(const TopoDS_Edge& S1, const TopoDS_Vertex& S2, - const Bnd_Box& B1, const Bnd_Box& B2, - const Standard_Real DstRef) - -{Standard_Real Dst,Dstmin,epsP,Udeb,Ufin ; - gp_Pnt Pt,P1; - Standard_Boolean inserer,notavertex; - Standard_Integer i; - - epsP=Precision::PConfusion(); - SeqSolShape1.Clear(); - SeqSolShape2.Clear(); - myModif=Standard_False; - - if (!BRep_Tool::Degenerated(S1)) { - Dst=B1.Distance(B2); - if ( (Dst< DstRef -myEps ) || (fabs(Dst-DstRef)< myEps )) - { - BRepExtrema_ExtPC Ext(S2,S1); - if ( (Ext.IsDone()) && (Ext.NbExt() > 0) ) - { Standard_Integer NbExtrema=Ext.NbExt(); -// Recherche de la distance minimum dstmin - Dstmin=sqrt(Ext.SquareDistance(1)); - for (i=2;i<=NbExtrema;i++) - - {Dst=sqrt(Ext.SquareDistance(i)); - if (Dst Dstmin) - myDstRef=Dstmin; -// Modified by Sergey KHROMOV - Tue Mar 6 12:28:54 2001 End - myModif=Standard_True; - P1=BRep_Tool::Pnt(S2); - BRepExtrema_SolutionElem Sol1 (Dstmin,Pt,BRepExtrema_IsOnEdge,S1,t); - BRepExtrema_SolutionElem Sol2 (Dstmin,P1,BRepExtrema_IsVertex,S2); - SeqSolShape1.Append(Sol1); - SeqSolShape2.Append(Sol2); - } - } - } - } - } - } -} -} - -/*********************************************************************************/ - -void BRepExtrema_DistanceSS::Perform(const TopoDS_Edge& S1, const TopoDS_Edge& S2, - const Bnd_Box& B1, const Bnd_Box& B2, - const Standard_Real DstRef) - -{ - Standard_Real Dst,Dstmin,epsP,Udeb,Ufin; - gp_Pnt Pt1,Pt2; - Standard_Boolean insere1, insere2, notavertex; - Standard_Integer i; - - epsP=Precision::PConfusion(); - SeqSolShape1.Clear(); - SeqSolShape2.Clear(); - myModif=Standard_False; - - if (!BRep_Tool::Degenerated(S1)&& !BRep_Tool::Degenerated(S2)) - - { - - Dst=B1.Distance(B2); - if ( (Dst< DstRef -myEps ) || (fabs(Dst-DstRef)< myEps )) - { - BRepExtrema_ExtCC Ext(S1,S2); - if ( (Ext.IsDone()) && (Ext.NbExt() > 0) && (!Ext.IsParallel())) - { Standard_Integer NbExtrema=Ext.NbExt(); -// Recherche de la distance minimum dstmin - Dstmin=sqrt (Ext.SquareDistance(1)); - for (i=2;i<=NbExtrema;i++) - {Dst=sqrt (Ext.SquareDistance(i)); - if (Dst Dstmin) - myDstRef=Dstmin; -// Modified by Sergey KHROMOV - Tue Mar 6 12:28:54 2001 End - myModif=Standard_True; - BRepExtrema_SolutionElem Sol1 (Dstmin,Pt1,BRepExtrema_IsOnEdge,S1,t1); - BRepExtrema_SolutionElem Sol2 (Dstmin,Pt2,BRepExtrema_IsOnEdge,S2,t2); - SeqSolShape1.Append(Sol1); - SeqSolShape2.Append(Sol2); - } - } - - } - } - } - - BRepExtrema_SeqOfSolution SeqSolution1; - BRepExtrema_SeqOfSolution SeqSolution2; -// Standard_Integer i; - - PERFORM_C0(S1, S2, SeqSolution1, SeqSolution2, DstRef, myDstRef, myEps); - - BRepExtrema_SeqOfSolution seqSol1; - BRepExtrema_SeqOfSolution seqSol2; - - if (SeqSolution1.Length() > 0 && SeqSolution2.Length() > 0) { - MIN_SOLUTION(SeqSolution1, SeqSolution2, myDstRef, myEps, seqSol1, seqSol2); - } - - if (!seqSol1.IsEmpty() && !seqSol2.IsEmpty()) - { - SeqSolShape1.Append(seqSol1); - SeqSolShape2.Append(seqSol2); - myModif = Standard_True; - } - - } - } - } - -/*********************************************************************************/ - -void BRepExtrema_DistanceSS::Perform(const TopoDS_Edge& S1, const TopoDS_Face& S2, - const Bnd_Box& B1, const Bnd_Box& B2, - const Standard_Real DstRef) -{ - Standard_Real Dst,Dstmin,epsP,Udeb,Ufin,U,V ; - gp_Pnt Pt1,Pt2; - gp_Pnt2d PUV; - Standard_Boolean insere1 ,insere2, notavertex; - BRepClass_FaceClassifier classifier; - Standard_Integer i; - - epsP=Precision::PConfusion(); - SeqSolShape1.Clear(); - SeqSolShape2.Clear(); - myModif=Standard_False; - - if (!BRep_Tool::Degenerated(S1)) { - - Dst=B1.Distance(B2); - if ( (Dst< DstRef -myEps ) || (fabs(Dst-DstRef)< myEps )) + gp_Pnt P1,Pt; + Standard_Integer i, ii; + BRepClass_FaceClassifier classifier; + for (i = 1; i <= arrInter.Length(); i++) { - BRepExtrema_ExtCF Ext(S1,S2); - if ( (Ext.IsDone()) && ((Ext.NbExt() > 0) && (!Ext.IsParallel()) )) - { Standard_Integer NbExtrema=Ext.NbExt(); - // Recherche de la distance minimum dstmin - Dstmin=sqrt (Ext.SquareDistance(1)); - for (i=2;i<=NbExtrema;i++) - {Dst=sqrt (Ext.SquareDistance(i)); - if (Dst Dstmin) - myDstRef=Dstmin; -// Modified by Sergey KHROMOV - Tue Mar 6 12:28:54 2001 End - myModif=Standard_True; - BRepExtrema_SolutionElem Sol1 (Dstmin,Pt1,BRepExtrema_IsOnEdge,S1,t1); - BRepExtrema_SolutionElem Sol2 (Dstmin,Pt2,BRepExtrema_IsInFace,S2,U,V); - SeqSolShape1.Append(Sol1); - SeqSolShape2.Append(Sol2); - } - } - } - } - } - Standard_Real aFirst, aLast; - Handle(Geom_Curve) pCurv = BRep_Tool::Curve(S1, aFirst, aLast); - GeomAbs_Shape s = pCurv->Continuity(); - if (s == GeomAbs_C0) - { - BRepExtrema_SeqOfSolution SeqSolution1; - BRepExtrema_SeqOfSolution SeqSolution2; + const Standard_Real aParameter = arrInter(i); + const gp_Pnt aPnt = aAdaptorCurve.Value(aParameter); + const TopoDS_Vertex V1 = BRepBuilderAPI_MakeVertex(aPnt); - - GeomAdaptor_Curve aAdaptorCurve(pCurv, aFirst, aLast); - Standard_Integer nbIntervals = aAdaptorCurve.NbIntervals(GeomAbs_C1); - - TColStd_Array1OfReal arrInter(1,1+nbIntervals); - aAdaptorCurve.Intervals(arrInter, GeomAbs_C1); - -// Standard_Real U,V; - gp_Pnt P1,Pt; -// gp_Pnt2d PUV; -// Standard_Boolean notavertex; -// Standard_Integer i, ii; - Standard_Integer ii; -// BRepClass_FaceClassifier classifier; - Standard_Real aParameter; - for (i=1; i<=arrInter.Length(); i++) - { - gp_Pnt aPnt = aAdaptorCurve.Value(arrInter(i)); - - TopoDS_Vertex V1 = BRepBuilderAPI_MakeVertex(aPnt); + BRepExtrema_ExtPC Ext(V1,Eother); + const Standard_Integer NbExtrema = Ext.IsDone()? Ext.NbExt() : 0; + if ( NbExtrema > 0 ) + { + // Search minimum distance dstmin + Standard_Real Dstmin = Ext.SquareDistance(1); + for (ii = 2; ii <= NbExtrema; ii++) + { + const Standard_Real sDst = Ext.SquareDistance(ii); + if (sDst 0) ) - { - Standard_Integer NbExtrema=ExtPF.NbExt(); - // Recherche de la distance minimum dstmin - Dstmin=sqrt (ExtPF.SquareDistance(1)); - for (ii=2;ii<=NbExtrema;ii++) - {Dst=sqrt(ExtPF.SquareDistance(ii)); - if (Dst Dstmin) - myDstRef=Dstmin; - // Modified by Sergey KHROMOV - Tue Mar 6 12:28:54 2001 End - myModif=Standard_True; - P1=BRep_Tool::Pnt(V1); - BRepExtrema_SolutionElem Sol1 (Dstmin,P1,BRepExtrema_IsOnEdge,S1,aParameter); - BRepExtrema_SolutionElem Sol2 (Dstmin,Pt,BRepExtrema_IsInFace,S2,U,V); - SeqSolution1.Append(Sol1); - SeqSolution2.Append(Sol2); - } - } - } - } - } - } - BRepExtrema_SeqOfSolution seqSol1; - BRepExtrema_SeqOfSolution seqSol2; - Standard_Boolean bIsMini = Standard_False; - if (SeqSolution1.Length() > 0 && SeqSolution2.Length() > 0) - MIN_SOLUTION(SeqSolution1, SeqSolution2, myDstRef, myEps, seqSol1, seqSol2); - - if (!seqSol1.IsEmpty() && !seqSol2.IsEmpty()) - { - SeqSolShape1.Append(seqSol1); - SeqSolShape2.Append(seqSol2); - } - } + if ((Dstmin < DstRef - Eps) || (fabs(Dstmin-DstRef) < Eps)) + for (ii = 1; ii <= NbExtrema; ii++) + { + if (fabs(Dstmin-sqrt(Ext.SquareDistance(ii)))=epsP)&&(fabs(t-Ufin)>epsP)) + { + if (mDstRef > Dstmin) + mDstRef=Dstmin; + const BRepExtrema_SolutionElem Sol1(Dstmin,aPnt,BRepExtrema_IsOnEdge,E,aParameter); + const BRepExtrema_SolutionElem Sol2(Dstmin,Pt,BRepExtrema_IsOnEdge,Eother,t); + SeqSol1.Append(iE == 0 ? Sol1 : Sol2); + SeqSol2.Append(iE == 0 ? Sol2 : Sol1); + } + } + } + } + } + for (Standard_Integer i2 = 1; i2<=arrInterOther.Length(); i2++) + { + const Standard_Real aParameterOther = arrInterOther(i2); + const gp_Pnt aPntOther = aAdaptorCurveOther.Value(aParameterOther); + const Standard_Real Dst = aPnt.Distance(aPntOther); + if ((Dst < DstRef - Eps) || (fabs(Dst-DstRef) < Eps)) + { + if (mDstRef > Dst) + mDstRef=Dst; + const BRepExtrema_SolutionElem Sol1(Dst,aPnt,BRepExtrema_IsOnEdge,E,aParameter); + const BRepExtrema_SolutionElem Sol2(Dst,aPntOther,BRepExtrema_IsOnEdge,Eother,aParameterOther); + SeqSol1.Append(iE == 0 ? Sol1 : Sol2); + SeqSol2.Append(iE == 0 ? Sol2 : Sol1); + } + } } + } } } /*********************************************************************************/ -void BRepExtrema_DistanceSS::Perform(const TopoDS_Face& S1, const TopoDS_Vertex& S2, - const Bnd_Box& B1, const Bnd_Box& B2, - const Standard_Real DstRef) - +void BRepExtrema_DistanceSS::Perform(const TopoDS_Shape& S1, const TopoDS_Shape& S2, + const Bnd_Box& B1, const Bnd_Box& B2) { - const Standard_Real epsP=Precision::PConfusion(); SeqSolShape1.Clear(); SeqSolShape2.Clear(); myModif=Standard_False; - Standard_Real Dst=B1.Distance(B2); - if ((Dst < DstRef -myEps) || (fabs(Dst-DstRef)< myEps)) - { - BRepExtrema_ExtPF Ext(S2,S1); - if ( Ext.IsDone() && (Ext.NbExt() > 0) ) + switch (S1.ShapeType()) + { + case TopAbs_VERTEX : { - const Standard_Integer NbExtrema=Ext.NbExt(); - // Search the minimal distance Dstmin + TopoDS_Vertex V1 = TopoDS::Vertex(S1); + switch (S2.ShapeType()) + { + case TopAbs_VERTEX : + { + TopoDS_Vertex V2 = TopoDS::Vertex(S2); + Perform( V1, V2 ); + break; + } + case TopAbs_EDGE : + { + TopoDS_Edge E2 = TopoDS::Edge(S2); + Perform( V1, E2, B1, B2 ); + break; + } + case TopAbs_FACE : + { + TopoDS_Face F2 = TopoDS::Face(S2); + Perform( V1, F2, B1, B2 ); + break; + } + } + break; + } + + case TopAbs_EDGE : + { + TopoDS_Edge E1 = TopoDS::Edge(S1); + switch (S2.ShapeType()) + { + case TopAbs_VERTEX : + { + TopoDS_Vertex V2 = TopoDS::Vertex(S2); + Perform( E1, V2, B1, B2 ); + break; + } + case TopAbs_EDGE : + { + TopoDS_Edge E2 = TopoDS::Edge(S2); + TopoDS_Edge aTrimEdge; + Standard_Boolean bIsTrim1 = Standard_False; + Standard_Boolean bIsTrim2 = Standard_False; + TRIM_INFINIT_EDGE( E1, E2, aTrimEdge, bIsTrim1, bIsTrim2 ); + if (bIsTrim1) + E1 = aTrimEdge; + if (bIsTrim2) + E2 = aTrimEdge; + Perform( E1, E2, B1, B2 ); + break; + } + case TopAbs_FACE : + { + TopoDS_Face F2 = TopoDS::Face(S2); + TopoDS_Face aTrimFace; + Standard_Boolean bIsInfinit; + TRIM_INFINIT_FACE( E1, F2, aTrimFace, bIsInfinit ); + if (bIsInfinit) + F2 = aTrimFace; + Perform( E1, F2, B1, B2 ); + break; + } + } + break; + } + + case TopAbs_FACE : + { + TopoDS_Face F1 = TopoDS::Face(S1); + switch (S2.ShapeType()) + { + case TopAbs_VERTEX : + { + TopoDS_Vertex V2 = TopoDS::Vertex(S2); + Perform( F1, V2, B1, B2 ); + break; + } + case TopAbs_EDGE : + { + TopoDS_Edge E2 = TopoDS::Edge(S2); + TopoDS_Face aTrimFace; + Standard_Boolean bIsInfinit; + TRIM_INFINIT_FACE( F1, E2, aTrimFace, bIsInfinit ); + if (bIsInfinit) + F1 = aTrimFace; + Perform( F1, E2, B1, B2 ); + break; + } + case TopAbs_FACE : + { + TopoDS_Face F2 = TopoDS::Face(S2); + Perform( F1, F2, B1, B2 ); + break; + } + } + break; + } + } +} + +/*********************************************************************************/ + +void BRepExtrema_DistanceSS::Perform(const TopoDS_Vertex& S1, const TopoDS_Vertex& S2) +{ + const gp_Pnt P1 = BRep_Tool::Pnt(S1); + const gp_Pnt P2 = BRep_Tool::Pnt(S2); + + const Standard_Real Dst = P1.Distance(P2); + if ((Dst < myDstRef - myEps) || (fabs(Dst-myDstRef) < myEps)) + { + if (myDstRef > Dst) + myDstRef=Dst; + myModif=Standard_True; + const BRepExtrema_SolutionElem Sol1(Dst,P1,BRepExtrema_IsVertex,S1); + const BRepExtrema_SolutionElem Sol2(Dst,P2,BRepExtrema_IsVertex,S2); + SeqSolShape1.Append(Sol1); + SeqSolShape2.Append(Sol2); + } +} + +/*********************************************************************************/ + +void BRepExtrema_DistanceSS::Perform(const TopoDS_Vertex& S1, const TopoDS_Edge& S2, + const Bnd_Box& B1, const Bnd_Box& B2) +{ + if (BRep_Tool::Degenerated(S2)) + return; + + const Standard_Real Dst=B1.Distance(B2); + if ((Dst < myDstRef - myEps) || (fabs(Dst-myDstRef) < myEps)) + { + BRepExtrema_ExtPC Ext(S1,S2); + const Standard_Integer NbExtrema = Ext.IsDone()? Ext.NbExt() : 0; + if ( NbExtrema > 0 ) + { + // Search minimum distance Dstmin Standard_Integer i; Standard_Real Dstmin = Ext.SquareDistance(1); - for (i=2;i<=NbExtrema;i++) - { - Dst = Ext.SquareDistance(i); - if (Dst=epsP) && (fabs(t-Ufin)>epsP) ) { -// Modified by Sergey KHROMOV - Tue Mar 6 12:28:51 2001 Begin - if (myDstRef > Dstmin) - myDstRef=Dstmin; -// Modified by Sergey KHROMOV - Tue Mar 6 12:28:54 2001 End + if (myDstRef > Dstmin) + myDstRef=Dstmin; myModif=Standard_True; - P1=BRep_Tool::Pnt(S2); - BRepExtrema_SolutionElem Sol1 (Dstmin,Pt,BRepExtrema_IsInFace,S1,U,V); - BRepExtrema_SolutionElem Sol2 (Dstmin,P1,BRepExtrema_IsVertex,S2); + const BRepExtrema_SolutionElem Sol1(Dstmin,P1,BRepExtrema_IsVertex,S1); + const BRepExtrema_SolutionElem Sol2(Dstmin,Pt,BRepExtrema_IsOnEdge,S2,t); SeqSolShape1.Append(Sol1); SeqSolShape2.Append(Sol2); } } } } - } + } } } } /*********************************************************************************/ -void BRepExtrema_DistanceSS::Perform(const TopoDS_Face& S1, const TopoDS_Edge& S2, - const Bnd_Box& B1, const Bnd_Box& B2, - const Standard_Real DstRef) - +void BRepExtrema_DistanceSS::Perform(const TopoDS_Vertex& S1, const TopoDS_Face& S2, + const Bnd_Box& B1, const Bnd_Box& B2) { - Standard_Real Dst,Dstmin,epsP,Udeb,Ufin,U,V ; - gp_Pnt Pt1,Pt2; - gp_Pnt2d PUV; - Standard_Boolean insere1,insere2,notavertex; - BRepClass_FaceClassifier classifier; - Standard_Integer i; - - epsP=Precision::PConfusion(); - SeqSolShape1.Clear(); - SeqSolShape2.Clear(); - myModif=Standard_False; - - if (!BRep_Tool::Degenerated(S2)) - { - Dst=B1.Distance(B2); - if ( (Dst< DstRef -myEps ) || (fabs(Dst-DstRef)< myEps )) - { - BRepExtrema_ExtCF Ext(S2,S1); - if ( (Ext.IsDone()) && ((Ext.NbExt() > 0) && (!Ext.IsParallel())) ) - { Standard_Integer NbExtrema=Ext.NbExt(); -// Recherche de la distance minimum dstmin - Dstmin=sqrt (Ext.SquareDistance(1)); - for (i=2;i<=NbExtrema;i++) - {Dst=sqrt (Ext.SquareDistance(i)); - if (Dst Dstmin) - myDstRef=Dstmin; -// Modified by Sergey KHROMOV - Tue Mar 6 12:28:54 2001 End - myModif=Standard_True; - BRepExtrema_SolutionElem Sol1 (Dstmin,Pt1,BRepExtrema_IsInFace,S1,U,V); - BRepExtrema_SolutionElem Sol2 (Dstmin,Pt2,BRepExtrema_IsOnEdge,S2,t1); - SeqSolShape1.Append(Sol1); - SeqSolShape2.Append(Sol2); - } - } - } - } - } - - Standard_Real aFirst, aLast; - Handle(Geom_Curve) pCurv = BRep_Tool::Curve(S2, aFirst, aLast); - GeomAbs_Shape s = pCurv->Continuity(); - if (s == GeomAbs_C0) - { - BRepExtrema_SeqOfSolution SeqSolution1; - BRepExtrema_SeqOfSolution SeqSolution2; - - - GeomAdaptor_Curve aAdaptorCurve(pCurv, aFirst, aLast); - Standard_Integer nbIntervals = aAdaptorCurve.NbIntervals(GeomAbs_C1); - - TColStd_Array1OfReal arrInter(1,1+nbIntervals); - aAdaptorCurve.Intervals(arrInter, GeomAbs_C1); - -// Standard_Real U,V; - gp_Pnt P1,Pt; -// gp_Pnt2d PUV; -// Standard_Boolean notavertex; - Standard_Integer ii; -// BRepClass_FaceClassifier classifier; - Standard_Real aParameter; - for (i=1; i<=arrInter.Length(); i++) - { - gp_Pnt aPnt = aAdaptorCurve.Value(arrInter(i)); - - TopoDS_Vertex V1 = BRepBuilderAPI_MakeVertex(aPnt); - - aParameter = arrInter(i); - - BRepExtrema_ExtPF ExtPF(V1,S1); - if ( (ExtPF.IsDone()) && (ExtPF.NbExt() > 0) ) - { - Standard_Integer NbExtrema=ExtPF.NbExt(); - // Recherche de la distance minimum dstmin - Dstmin=sqrt(ExtPF.SquareDistance(1)); - for (ii=2;ii<=NbExtrema;ii++) - {Dst=sqrt(ExtPF.SquareDistance(ii)); - if (Dst Dstmin) - myDstRef=Dstmin; - // Modified by Sergey KHROMOV - Tue Mar 6 12:28:54 2001 End - myModif=Standard_True; - P1=BRep_Tool::Pnt(V1); - BRepExtrema_SolutionElem Sol1 (Dstmin,Pt,BRepExtrema_IsInFace,S1,U,V); - BRepExtrema_SolutionElem Sol2 (Dstmin,P1,BRepExtrema_IsOnEdge,S2,aParameter); - SeqSolution1.Append(Sol1); - SeqSolution2.Append(Sol2); - } - } - } - } - } - } - BRepExtrema_SeqOfSolution seqSol1; - BRepExtrema_SeqOfSolution seqSol2; - Standard_Boolean bIsMini = Standard_False; - if (SeqSolution1.Length() > 0 && SeqSolution2.Length() > 0) - MIN_SOLUTION(SeqSolution1, SeqSolution2, myDstRef, myEps, seqSol1, seqSol2); - - if (!seqSol1.IsEmpty() && !seqSol2.IsEmpty()) - { - SeqSolShape1.Append(seqSol1); - SeqSolShape2.Append(seqSol2); - } - } - - } - } - } - -/*********************************************************************************/ - -void BRepExtrema_DistanceSS::Perform(const TopoDS_Face& S1, const TopoDS_Face& S2, - const Bnd_Box& B1, const Bnd_Box& B2, - const Standard_Real DstRef) - -{ - Standard_Real Dst,Dstmin,epsP,U1,V1,U2,V2,tol ; - gp_Pnt Pt1,Pt2; - gp_Pnt2d PUV; - Standard_Boolean insere1,insere2,notavertex; - BRepClass_FaceClassifier classifier; - Standard_Integer i; - - epsP=Precision::PConfusion(); - SeqSolShape1.Clear(); - SeqSolShape2.Clear(); - myModif=Standard_False; + const Standard_Real Dst=B1.Distance(B2); + if ((Dst < myDstRef - myEps) || (fabs(Dst-myDstRef) < myEps)) + { + BRepExtrema_ExtPF Ext(S1,S2,myFlag,myAlgo); + const Standard_Integer NbExtrema = Ext.IsDone()? Ext.NbExt() : 0; + if ( NbExtrema > 0 ) + { + // Search minimum distance Dstmin + Standard_Integer i; + Standard_Real Dstmin = Ext.SquareDistance(1); + for (i = 2; i <= NbExtrema; i++) + { + const Standard_Real sDst = Ext.SquareDistance(i); + if (sDst 0) && (!Ext.IsParallel()) )) - { Standard_Integer NbExtrema=Ext.NbExt(); -// Recherche de la distance minimum dstmin - Dstmin=sqrt (Ext.SquareDistance(1)); - for (i=2;i<=NbExtrema;i++) - {Dst=sqrt(Ext.SquareDistance(i)); - if (Dst Dstmin) - myDstRef=Dstmin; -// Modified by Sergey KHROMOV - Tue Mar 6 12:28:54 2001 End - myModif=Standard_True; - BRepExtrema_SolutionElem Sol1 (Dstmin,Pt1,BRepExtrema_IsInFace,S1,U1,V1); - BRepExtrema_SolutionElem Sol2 (Dstmin,Pt2,BRepExtrema_IsInFace,S2,U2,V2); - SeqSolShape1.Append(Sol1); - SeqSolShape2.Append(Sol2); - } - } - } - } - } - } + for (i = 1; i <= NbExtrema; i++) + { + if (fabs(Dstmin-sqrt(Ext.SquareDistance(i))) Dstmin) + myDstRef=Dstmin; + myModif=Standard_True; + const BRepExtrema_SolutionElem Sol1(Dstmin,P1,BRepExtrema_IsVertex,S1); + const BRepExtrema_SolutionElem Sol2(Dstmin,Pt,BRepExtrema_IsInFace,S2,U,V); + SeqSolShape1.Append(Sol1); + SeqSolShape2.Append(Sol2); + } + } + } + } + } + } + } } /*********************************************************************************/ -Standard_Boolean BRepExtrema_DistanceSS::IsDone() const +void BRepExtrema_DistanceSS::Perform(const TopoDS_Edge& S1, const TopoDS_Edge& S2, + const Bnd_Box& B1, const Bnd_Box& B2) { - return myModif; + if (BRep_Tool::Degenerated(S1) || BRep_Tool::Degenerated(S2)) + return; + + const Standard_Real Dst=B1.Distance(B2); + if ((Dst < myDstRef - myEps) || (fabs(Dst-myDstRef) < myEps)) + { + const Standard_Real DstRef = myDstRef; + + BRepExtrema_ExtCC Ext(S1,S2); + const Standard_Integer NbExtrema = Ext.IsDone()? (Ext.IsParallel()? 0 : Ext.NbExt()) : 0; + if ( NbExtrema > 0 ) + { + // Search minimum distance Dstmin + Standard_Integer i; + Standard_Real Dstmin = Ext.SquareDistance(1); + for (i = 2; i <= NbExtrema; i++) + { + const Standard_Real sDst = Ext.SquareDistance(i); + if (sDst=epsP)&&(fabs(t1-Ufin1)>epsP)&&(fabs(t2-Udeb2)>=epsP)&&(fabs(t2-Ufin2)>epsP)) + { + if (myDstRef > Dstmin) + myDstRef=Dstmin; + myModif=Standard_True; + const BRepExtrema_SolutionElem Sol1(Dstmin,Pt1,BRepExtrema_IsOnEdge,S1,t1); + const BRepExtrema_SolutionElem Sol2(Dstmin,Pt2,BRepExtrema_IsOnEdge,S2,t2); + SeqSolShape1.Append(Sol1); + SeqSolShape2.Append(Sol2); + } + } + } + } + } + } + + BRepExtrema_SeqOfSolution SeqSolution1; + BRepExtrema_SeqOfSolution SeqSolution2; + + PERFORM_C0(S1, S2, SeqSolution1, SeqSolution2, DstRef, myDstRef, myEps); + + BRepExtrema_SeqOfSolution seqSol1; + BRepExtrema_SeqOfSolution seqSol2; + + if (SeqSolution1.Length() > 0 && SeqSolution2.Length() > 0) + MIN_SOLUTION(SeqSolution1, SeqSolution2, myDstRef, myEps, seqSol1, seqSol2); + + if (!seqSol1.IsEmpty() && !seqSol2.IsEmpty()) + { + SeqSolShape1.Append(seqSol1); + SeqSolShape2.Append(seqSol2); + myModif = Standard_True; + } + } } /*********************************************************************************/ -Standard_Real BRepExtrema_DistanceSS::DistValue() const +void BRepExtrema_DistanceSS::Perform(const TopoDS_Edge& S1, const TopoDS_Face& S2, + const Bnd_Box& B1, const Bnd_Box& B2) { - return myDstRef; + if (BRep_Tool::Degenerated(S1)) + return; + + const Standard_Real Dst=B1.Distance(B2); + if ((Dst < myDstRef - myEps) || (fabs(Dst-myDstRef) < myEps)) + { + BRepClass_FaceClassifier classifier; + + BRepExtrema_ExtCF Ext(S1,S2); + const Standard_Integer NbExtrema = Ext.IsDone()? (Ext.IsParallel()? 0 : Ext.NbExt()) : 0; + if ( NbExtrema > 0 ) + { + // Search minimum distance Dstmin + Standard_Integer i; + Standard_Real Dstmin = Ext.SquareDistance(1); + for (i = 2; i <= NbExtrema; i++) + { + const Standard_Real sDst = Ext.SquareDistance(i); + if (sDst=epsP)&&(fabs(t1-Ufin)>epsP)) + { + Ext.ParameterOnFace(i,U,V); + const gp_Pnt2d PUV(U,V); + classifier.Perform(S2,PUV,tol); + if (classifier.State()==TopAbs_IN) + { + if (myDstRef > Dstmin) + myDstRef=Dstmin; + myModif=Standard_True; + const BRepExtrema_SolutionElem Sol1(Dstmin,Pt1,BRepExtrema_IsOnEdge,S1,t1); + const BRepExtrema_SolutionElem Sol2(Dstmin,Pt2,BRepExtrema_IsInFace,S2,U,V); + SeqSolShape1.Append(Sol1); + SeqSolShape2.Append(Sol2); + } + } + } + } + } + } + } + + Standard_Real aFirst, aLast; + Handle(Geom_Curve) pCurv = BRep_Tool::Curve(S1, aFirst, aLast); + if (pCurv->Continuity() == GeomAbs_C0) + { + BRepExtrema_SeqOfSolution SeqSolution1; + BRepExtrema_SeqOfSolution SeqSolution2; + + GeomAdaptor_Curve aAdaptorCurve(pCurv, aFirst, aLast); + const Standard_Integer nbIntervals = aAdaptorCurve.NbIntervals(GeomAbs_C1); + + TColStd_Array1OfReal arrInter(1,1+nbIntervals); + aAdaptorCurve.Intervals(arrInter, GeomAbs_C1); + + gp_Pnt Pt; + Standard_Real U,V; + const Standard_Real tol = BRep_Tool::Tolerance(S2); + + Standard_Integer i; + for (i = 1; i <= arrInter.Length(); i++) + { + const Standard_Real aParameter = arrInter(i); + gp_Pnt aPnt = aAdaptorCurve.Value(aParameter); + TopoDS_Vertex V1 = BRepBuilderAPI_MakeVertex(aPnt); + + BRepExtrema_ExtPF ExtPF(V1,S2); + const Standard_Integer NbExtrema = ExtPF.IsDone()? ExtPF.NbExt() : 0; + if ( NbExtrema > 0 ) + { + // Search minimum distance Dstmin + Standard_Integer ii; + Standard_Real Dstmin = ExtPF.SquareDistance(1); + for (ii = 2; ii <= NbExtrema; ii++) + { + const Standard_Real sDst = ExtPF.SquareDistance(ii); + if (sDst Dstmin) + myDstRef=Dstmin; + myModif=Standard_True; + const BRepExtrema_SolutionElem Sol1(Dstmin,aPnt,BRepExtrema_IsOnEdge,S1,aParameter); + const BRepExtrema_SolutionElem Sol2(Dstmin,ExtPF.Point(ii),BRepExtrema_IsInFace,S2,U,V); + SeqSolution1.Append(Sol1); + SeqSolution2.Append(Sol2); + } + } + } + } + } + } + + BRepExtrema_SeqOfSolution seqSol1; + BRepExtrema_SeqOfSolution seqSol2; + Standard_Boolean bIsMini = Standard_False; + if (SeqSolution1.Length() > 0 && SeqSolution2.Length() > 0) + MIN_SOLUTION(SeqSolution1, SeqSolution2, myDstRef, myEps, seqSol1, seqSol2); + + if (!seqSol1.IsEmpty() && !seqSol2.IsEmpty()) + { + SeqSolShape1.Append(seqSol1); + SeqSolShape2.Append(seqSol2); + } + } + } } /*********************************************************************************/ -const BRepExtrema_SeqOfSolution& BRepExtrema_DistanceSS::Seq1Value() const +void BRepExtrema_DistanceSS::Perform(const TopoDS_Face& S1, const TopoDS_Face& S2, + const Bnd_Box& B1, const Bnd_Box& B2) { - return SeqSolShape1; + const Standard_Real Dst=B1.Distance(B2); + if ((Dst < myDstRef - myEps) || (fabs(Dst-myDstRef) < myEps)) + { + BRepExtrema_ExtFF Ext(S1,S2); + const Standard_Integer NbExtrema = Ext.IsDone()? (Ext.IsParallel()? 0 : Ext.NbExt()) : 0; + if ( NbExtrema > 0 ) + { + // Search minimum distance Dstmin + Standard_Integer i; + Standard_Real Dstmin = Ext.SquareDistance(1); + for (i = 2; i <= NbExtrema; i++) + { + const Standard_Real sDst = Ext.SquareDistance(i); + if (sDst Dstmin) + myDstRef=Dstmin; + myModif=Standard_True; + const BRepExtrema_SolutionElem Sol1(Dstmin,Pt1,BRepExtrema_IsInFace,S1,U1,V1); + const BRepExtrema_SolutionElem Sol2(Dstmin,Pt2,BRepExtrema_IsInFace,S2,U2,V2); + SeqSolShape1.Append(Sol1); + SeqSolShape2.Append(Sol2); + } + } + } + } + } + } + } + } } /*********************************************************************************/ - -const BRepExtrema_SeqOfSolution& BRepExtrema_DistanceSS::Seq2Value() const -{ -return SeqSolShape2; -} - -/*********************************************************************************/ -/*********************************************************************************/ diff --git a/src/BRepExtrema/BRepExtrema_DistanceSS.hxx b/src/BRepExtrema/BRepExtrema_DistanceSS.hxx new file mode 100644 index 0000000000..446441168f --- /dev/null +++ b/src/BRepExtrema/BRepExtrema_DistanceSS.hxx @@ -0,0 +1,174 @@ +// File generated by CPPExt (Value) +// +// Copyright (C) 1991 - 2000 by +// Matra Datavision SA. All rights reserved. +// +// Copyright (C) 2001 - 2004 by +// Open CASCADE SA. All rights reserved. +// +// This file is part of the Open CASCADE Technology software. +// +// This software may be distributed and/or modified under the terms and +// conditions of the Open CASCADE Public License as defined by Open CASCADE SA +// and appearing in the file LICENSE included in the packaging of this file. +// +// This software is distributed on an "AS IS" basis, without warranty of any +// kind, and Open CASCADE SA hereby disclaims all such warranties, +// including without limitation, any warranties of merchantability, fitness +// for a particular purpose or non-infringement. Please see the License for +// the specific terms and conditions governing rights and limitations under the +// License. + +#ifndef _BRepExtrema_DistanceSS_HeaderFile +#define _BRepExtrema_DistanceSS_HeaderFile + +#ifndef _Standard_HeaderFile +#include +#endif +#ifndef _Standard_Macro_HeaderFile +#include +#endif + +#ifndef _BRepExtrema_SeqOfSolution_HeaderFile +#include +#endif +#ifndef _Standard_Real_HeaderFile +#include +#endif +#ifndef _Standard_Boolean_HeaderFile +#include +#endif +#ifndef _Extrema_ExtFlag_HeaderFile +#include +#endif +#ifndef _Extrema_ExtAlgo_HeaderFile +#include +#endif +#ifndef _Precision_HeaderFile +#include +#endif +class TopoDS_Shape; +class Bnd_Box; +class TopoDS_Vertex; +class TopoDS_Edge; +class TopoDS_Face; + + +//! This class allows to compute minimum distance between two shapes
+//! (face edge vertex) and is used in DistShapeShape class.
+class BRepExtrema_DistanceSS +{ + public: + + void* operator new(size_t,void* anAddress) + { + return anAddress; + } + void* operator new(size_t size) + { + return Standard::Allocate(size); + } + void operator delete(void *anAddress) + { + if (anAddress) Standard::Free((Standard_Address&)anAddress); + } + + //! computes the distance between two Shapes ( face edge vertex).
+ Standard_EXPORT BRepExtrema_DistanceSS(const TopoDS_Shape& S1, const TopoDS_Shape& S2, + const Bnd_Box& B1, const Bnd_Box& B2, + const Standard_Real DstRef, + const Extrema_ExtFlag F = Extrema_ExtFlag_MINMAX, + const Extrema_ExtAlgo A = Extrema_ExtAlgo_Grad) + : myDstRef(DstRef), myModif(Standard_False), myEps(Precision::Confusion()), myFlag(F), myAlgo(A) + { + Perform(S1, S2, B1, B2); + } + //! computes the distance between two Shapes ( face edge vertex).
+ //! Parameter theDeflection is used to specify a maximum deviation
+ //! of extreme distances from the minimum one.
+ //! Default value is Precision::Confusion().
+ Standard_EXPORT BRepExtrema_DistanceSS(const TopoDS_Shape& S1, const TopoDS_Shape& S2, + const Bnd_Box& B1, const Bnd_Box& B2, + const Standard_Real DstRef, const Standard_Real aDeflection, + const Extrema_ExtFlag F = Extrema_ExtFlag_MINMAX, + const Extrema_ExtAlgo A = Extrema_ExtAlgo_Grad) + : myDstRef(DstRef), myModif(Standard_False), myEps(aDeflection), myFlag(F), myAlgo(A) + { + Perform(S1, S2, B1, B2); + } + //! True if the distance has been computed
+ Standard_EXPORT Standard_Boolean IsDone() const + { + return myModif; + } + //! returns the distance value
+ Standard_EXPORT Standard_Real DistValue() const + { + return myDstRef; + } + //! returns the list of solutions on the first shape
+ Standard_EXPORT const BRepExtrema_SeqOfSolution& Seq1Value() const + { + return SeqSolShape1; + } + //! returns the list of solutions on the second shape
+ Standard_EXPORT const BRepExtrema_SeqOfSolution& Seq2Value() const + { + return SeqSolShape2; + } + //! sets the flag controlling minimum and maximum search + Standard_EXPORT void SetFlag(const Extrema_ExtFlag F) + { + myFlag = F; + } + //! sets the flag controlling ... + Standard_EXPORT void SetAlgo(const Extrema_ExtAlgo A) + { + myAlgo = A; + } + + private: + + //! computes the distance between two Shapes ( face edge vertex)
+ void Perform(const TopoDS_Shape& S1,const TopoDS_Shape& S2,const Bnd_Box& B1,const Bnd_Box& B2); + + //! computes the distance between two vertices
+ void Perform(const TopoDS_Vertex& S1,const TopoDS_Vertex& S2); + //! computes the minimum distance between a vertex and an edge
+ void Perform(const TopoDS_Vertex& S1,const TopoDS_Edge& S2,const Bnd_Box& B1,const Bnd_Box& B2); + //! computes the minimum distance between a vertex and a face
+ void Perform(const TopoDS_Vertex& S1,const TopoDS_Face& S2,const Bnd_Box& B1,const Bnd_Box& B2); + + //! computes the minimum distance between an edge and a vertex
+ void Perform(const TopoDS_Edge& S1,const TopoDS_Vertex& S2,const Bnd_Box& B1,const Bnd_Box& B2) + { + Perform(S2, S1, B2, B1); + } + //! computes the minimum distance between two edges
+ void Perform(const TopoDS_Edge& S1,const TopoDS_Edge& S2,const Bnd_Box& B1,const Bnd_Box& B2); + //! computes the minimum distance an edge and a face
+ void Perform(const TopoDS_Edge& S1,const TopoDS_Face& S2,const Bnd_Box& B1,const Bnd_Box& B2); + + //! computes the minimum distance betwwen a face and a vertex
+ void Perform(const TopoDS_Face& S1,const TopoDS_Vertex& S2,const Bnd_Box& B1,const Bnd_Box& B2) + { + Perform(S2, S1, B2, B1); + } + //! computes the minimum distance between a face and an edge
+ void Perform(const TopoDS_Face& S1,const TopoDS_Edge& S2,const Bnd_Box& B1,const Bnd_Box& B2) + { + Perform(S2, S1, B2, B1); + } + //! computes the minimum distance between two faces
+ void Perform(const TopoDS_Face& S1,const TopoDS_Face& S2,const Bnd_Box& B1,const Bnd_Box& B2); + + BRepExtrema_SeqOfSolution SeqSolShape1; + BRepExtrema_SeqOfSolution SeqSolShape2; + Standard_Real myDstRef; + Standard_Boolean myModif; + Standard_Real myEps; + Extrema_ExtFlag myFlag; + Extrema_ExtAlgo myAlgo; +}; + +#endif diff --git a/src/BRepExtrema/BRepExtrema_ExtCC.cxx b/src/BRepExtrema/BRepExtrema_ExtCC.cxx index 7b247d499d..3909c63567 100755 --- a/src/BRepExtrema/BRepExtrema_ExtCC.cxx +++ b/src/BRepExtrema/BRepExtrema_ExtCC.cxx @@ -1,12 +1,10 @@ // File: BRepExtrema_ExtCC.cxx // Created: Wed Dec 15 16:48:53 1993 // Author: Christophe MARION -// -#include +#include + #include -#include -#include #include #include #include @@ -17,18 +15,7 @@ //purpose : //======================================================================= -BRepExtrema_ExtCC::BRepExtrema_ExtCC() -{ -} - -//======================================================================= -//function : BRepExtrema_ExtCC -//purpose : -//======================================================================= - -BRepExtrema_ExtCC::BRepExtrema_ExtCC - (const TopoDS_Edge& E1, - const TopoDS_Edge& E2) +BRepExtrema_ExtCC::BRepExtrema_ExtCC(const TopoDS_Edge& E1, const TopoDS_Edge& E2) { Initialize(E2); Perform(E1); @@ -45,7 +32,7 @@ void BRepExtrema_ExtCC::Initialize(const TopoDS_Edge& E2) BRepAdaptor_Curve Curv(E2); myHC = new BRepAdaptor_HCurve(Curv); BRep_Tool::Range(E2,V1,V2); - myExtrem.SetCurve (2, myHC->Curve(),V1,V2); + myExtCC.SetCurve(2,myHC->Curve(),V1,V2); } //======================================================================= @@ -59,49 +46,8 @@ void BRepExtrema_ExtCC::Perform(const TopoDS_Edge& E1) BRepAdaptor_Curve Curv(E1); Handle(BRepAdaptor_HCurve) HC = new BRepAdaptor_HCurve(Curv); BRep_Tool::Range(E1,U1,U2); - myExtrem.SetCurve (1, HC->Curve(), U1, U2); - myExtrem.Perform(); -} - -//======================================================================= -//function : IsDone -//purpose : -//======================================================================= - -Standard_Boolean BRepExtrema_ExtCC::IsDone()const -{ - return myExtrem.IsDone(); -} - -//======================================================================= -//function : NbExt -//purpose : -//======================================================================= - -Standard_Integer BRepExtrema_ExtCC::NbExt() const -{ - return myExtrem.NbExt(); -} - -//======================================================================= -//function : IsMin -//purpose : -//======================================================================= - -Standard_Boolean BRepExtrema_ExtCC::IsParallel() const -{ - return myExtrem.IsParallel(); -} - -//======================================================================= -//function : SquareDistance -//purpose : -//======================================================================= - -Standard_Real BRepExtrema_ExtCC::SquareDistance - (const Standard_Integer N) const -{ - return myExtrem.SquareDistance(N); + myExtCC.SetCurve (1, HC->Curve(), U1, U2); + myExtCC.Perform(); } //======================================================================= @@ -109,11 +55,10 @@ Standard_Real BRepExtrema_ExtCC::SquareDistance //purpose : //======================================================================= -Standard_Real BRepExtrema_ExtCC::ParameterOnE1 - (const Standard_Integer N) const +Standard_Real BRepExtrema_ExtCC::ParameterOnE1(const Standard_Integer N) const { Extrema_POnCurv POnE1, POnE2; - myExtrem.Points(N, POnE1, POnE2); + myExtCC.Points(N, POnE1, POnE2); return POnE1.Parameter(); } @@ -122,13 +67,11 @@ Standard_Real BRepExtrema_ExtCC::ParameterOnE1 //purpose : //======================================================================= -gp_Pnt BRepExtrema_ExtCC::PointOnE1 - (const Standard_Integer N) const +gp_Pnt BRepExtrema_ExtCC::PointOnE1(const Standard_Integer N) const { Extrema_POnCurv POnE1, POnE2; - myExtrem.Points(N, POnE1, POnE2); - gp_Pnt P = POnE1.Value(); - return P; + myExtCC.Points(N, POnE1, POnE2); + return POnE1.Value(); } //======================================================================= @@ -136,11 +79,10 @@ gp_Pnt BRepExtrema_ExtCC::PointOnE1 //purpose : //======================================================================= -Standard_Real BRepExtrema_ExtCC::ParameterOnE2 - (const Standard_Integer N) const +Standard_Real BRepExtrema_ExtCC::ParameterOnE2(const Standard_Integer N) const { Extrema_POnCurv POnE1, POnE2; - myExtrem.Points(N, POnE1, POnE2); + myExtCC.Points(N, POnE1, POnE2); return POnE2.Parameter(); } @@ -149,13 +91,11 @@ Standard_Real BRepExtrema_ExtCC::ParameterOnE2 //purpose : //======================================================================= -gp_Pnt BRepExtrema_ExtCC::PointOnE2 - (const Standard_Integer N) const +gp_Pnt BRepExtrema_ExtCC::PointOnE2(const Standard_Integer N) const { Extrema_POnCurv POnE1, POnE2; - myExtrem.Points(N, POnE1, POnE2); - gp_Pnt P = POnE2.Value(); - return P; + myExtCC.Points(N, POnE1, POnE2); + return POnE2.Value(); } @@ -174,7 +114,6 @@ void BRepExtrema_ExtCC::TrimmedSquareDistances gp_Pnt& pnt21, gp_Pnt& pnt22) const { - myExtrem.TrimmedSquareDistances(dist11,dist12,dist21, dist22, - pnt11,pnt12, pnt21, pnt22); + myExtCC.TrimmedSquareDistances(dist11,dist12,dist21,dist22, + pnt11,pnt12,pnt21,pnt22); } - diff --git a/src/BRepExtrema/BRepExtrema_ExtCC.hxx b/src/BRepExtrema/BRepExtrema_ExtCC.hxx new file mode 100644 index 0000000000..a6e2fcd31c --- /dev/null +++ b/src/BRepExtrema/BRepExtrema_ExtCC.hxx @@ -0,0 +1,102 @@ +// This file is generated by WOK (CPPExt). +// Please do not edit this file; modify original file instead. +// The copyright and license terms as defined for the original file apply to +// this header file considered to be the "object code" form of the original source. + +#ifndef _BRepExtrema_ExtCC_HeaderFile +#define _BRepExtrema_ExtCC_HeaderFile + +#ifndef _Standard_HeaderFile +#include +#endif +#ifndef _Standard_Macro_HeaderFile +#include +#endif + +#ifndef _Extrema_ExtCC_HeaderFile +#include +#endif +#ifndef _Handle_BRepAdaptor_HCurve_HeaderFile +#include +#endif +#ifndef _Standard_Boolean_HeaderFile +#include +#endif +#ifndef _Standard_Integer_HeaderFile +#include +#endif +#ifndef _Standard_Real_HeaderFile +#include +#endif +class BRepAdaptor_HCurve; +class TopoDS_Edge; +class gp_Pnt; + + +class BRepExtrema_ExtCC +{ + public: + + void* operator new(size_t,void* anAddress) + { + return anAddress; + } + void* operator new(size_t size) + { + return Standard::Allocate(size); + } + void operator delete(void *anAddress) + { + if (anAddress) Standard::Free((Standard_Address&)anAddress); + } + + Standard_EXPORT BRepExtrema_ExtCC() + { + } + //! It calculates all the distances.
+ Standard_EXPORT BRepExtrema_ExtCC(const TopoDS_Edge& E1,const TopoDS_Edge& E2); + + Standard_EXPORT void Initialize(const TopoDS_Edge& E2); + //! An exception is raised if the fields have not been initialized.
+ Standard_EXPORT void Perform(const TopoDS_Edge& E1); + //! True if the distances are found.
+ Standard_EXPORT Standard_Boolean IsDone() const + { + return myExtCC.IsDone(); + } + //! Returns the number of extremum distances.
+ Standard_EXPORT Standard_Integer NbExt() const + { + return myExtCC.NbExt(); + } + //! Returns True if E1 and E2 are parallel.
+ Standard_EXPORT Standard_Boolean IsParallel() const + { + return myExtCC.IsParallel(); + } + //! Returns the value of the th extremum square distance.
+ Standard_EXPORT Standard_Real SquareDistance(const Standard_Integer N) const + { + return myExtCC.SquareDistance(N); + } + //! Returns the parameter on the first edge of the th extremum distance.
+ Standard_EXPORT Standard_Real ParameterOnE1(const Standard_Integer N) const; + //! Returns the Point of the th extremum distance on the edge E1.
+ Standard_EXPORT gp_Pnt PointOnE1(const Standard_Integer N) const; + //! Returns the parameter on the second edge of the th extremum distance.
+ Standard_EXPORT Standard_Real ParameterOnE2(const Standard_Integer N) const; + //! Returns the Point of the th extremum distance on the edge E2.
+ Standard_EXPORT gp_Pnt PointOnE2(const Standard_Integer N) const; + //! if the edges is a trimmed curve,
+ //! dist11 is a square distance between the point on E1
+ //! of parameter FirstParameter and the point of
+ //! parameter FirstParameter on E2.
+ Standard_EXPORT void TrimmedSquareDistances(Standard_Real& dist11,Standard_Real& distP12,Standard_Real& distP21,Standard_Real& distP22,gp_Pnt& P11,gp_Pnt& P12,gp_Pnt& P21,gp_Pnt& P22) const; + + private: + + Extrema_ExtCC myExtCC; + Handle_BRepAdaptor_HCurve myHC; +}; + +#endif diff --git a/src/BRepExtrema/BRepExtrema_ExtCF.cxx b/src/BRepExtrema/BRepExtrema_ExtCF.cxx index 1ea003bee9..0bd97b0f6a 100755 --- a/src/BRepExtrema/BRepExtrema_ExtCF.cxx +++ b/src/BRepExtrema/BRepExtrema_ExtCF.cxx @@ -1,18 +1,13 @@ // File: BRepExtrema_ExtCF.cxx // Created: Wed Dec 15 16:48:53 1993 // Author: Christophe MARION -// -#include +#include + #include #include #include -#include -#include #include -#include -#include -#include #include #include #include @@ -24,18 +19,7 @@ //purpose : //======================================================================= -BRepExtrema_ExtCF::BRepExtrema_ExtCF() -{ -} - -//======================================================================= -//function : BRepExtrema_ExtCF -//purpose : -//======================================================================= - -BRepExtrema_ExtCF::BRepExtrema_ExtCF - (const TopoDS_Edge& E, - const TopoDS_Face& F) +BRepExtrema_ExtCF::BRepExtrema_ExtCF(const TopoDS_Edge& E, const TopoDS_Face& F) { Initialize(F); Perform(E, F); @@ -50,10 +34,10 @@ void BRepExtrema_ExtCF::Initialize(const TopoDS_Face& F2) { BRepAdaptor_Surface Surf(F2); myHS = new BRepAdaptor_HSurface(Surf); - Standard_Real Tol = BRep_Tool::Tolerance(F2); + const Standard_Real Tol = BRep_Tool::Tolerance(F2); Standard_Real U1, U2, V1, V2; BRepTools::UVBounds(F2, U1, U2, V1, V2); - myExtrem.Initialize(myHS->Surface(), U1, U2, V1, V2, Tol, Tol); + myExtCS.Initialize(myHS->Surface(), U1, U2, V1, V2, Tol, Tol); } //======================================================================= @@ -61,149 +45,45 @@ void BRepExtrema_ExtCF::Initialize(const TopoDS_Face& F2) //purpose : //======================================================================= -void BRepExtrema_ExtCF::Perform(const TopoDS_Edge& E, - const TopoDS_Face& F2) +void BRepExtrema_ExtCF::Perform(const TopoDS_Edge& E, const TopoDS_Face& F2) { mySqDist.Clear(); myPointsOnS.Clear(); myPointsOnC.Clear(); + Standard_Real U1, U2; BRep_Tool::Range(E, U1, U2); BRepAdaptor_Curve Curv(E); Handle(BRepAdaptor_HCurve) HC = new BRepAdaptor_HCurve(Curv); - myExtrem.Perform(HC->Curve(), U1, U2); + myExtCS.Perform(HC->Curve(), U1, U2); - // exploration des points et classification: - BRepClass_FaceClassifier classifier; - gp_Pnt2d Puv; - TopAbs_State state; - Standard_Real Tol = BRep_Tool::Tolerance(F2); - Extrema_POnCurv P1; - Extrema_POnSurf P2; - mynbext = 0; - - if(!myExtrem.IsDone()) + if(!myExtCS.IsDone()) return; - if (myExtrem.IsParallel()) { - mySqDist.Append(myExtrem.SquareDistance(1)); - mynbext = 1; - } - else { - for (Standard_Integer i = 1; i <= myExtrem.NbExt(); i++) { - myExtrem.Points(i, P1, P2); + if (myExtCS.IsParallel()) + mySqDist.Append(myExtCS.SquareDistance(1)); + else + { + // Exploration of points and classification + BRepClass_FaceClassifier classifier; + const Standard_Real Tol = BRep_Tool::Tolerance(F2); + Extrema_POnCurv P1; + Extrema_POnSurf P2; + + for (Standard_Integer i = 1; i <= myExtCS.NbExt(); i++) + { + myExtCS.Points(i, P1, P2); P2.Parameter(U1, U2); - Puv.SetCoord(U1, U2); + const gp_Pnt2d Puv(U1, U2); classifier.Perform(F2, Puv, Tol); - state = classifier.State(); - if(state == TopAbs_ON || state == TopAbs_IN) { - mynbext++; - mySqDist.Append(myExtrem.SquareDistance(i)); - myPointsOnC.Append(P1); - myPointsOnS.Append(P2); + const TopAbs_State state = classifier.State(); + if (state == TopAbs_ON || state == TopAbs_IN) + { + mySqDist.Append(myExtCS.SquareDistance(i)); + myPointsOnC.Append(P1); + myPointsOnS.Append(P2); } } } } -//======================================================================= -//function : IsDone -//purpose : -//======================================================================= - -Standard_Boolean BRepExtrema_ExtCF::IsDone()const -{ - return myExtrem.IsDone(); -} - - -//======================================================================= -//function : IsParallel -//purpose : -//======================================================================= - -Standard_Boolean BRepExtrema_ExtCF::IsParallel()const -{ - return myExtrem.IsParallel(); -} - -//======================================================================= -//function : NbExt -//purpose : -//======================================================================= - -Standard_Integer BRepExtrema_ExtCF::NbExt() const -{ - if(!myExtrem.IsDone()) StdFail_NotDone::Raise(); - return mynbext; -} - - -//======================================================================= -//function : SquareDistance -//purpose : -//======================================================================= - -Standard_Real BRepExtrema_ExtCF::SquareDistance - (const Standard_Integer N) const -{ - if(!myExtrem.IsDone()) StdFail_NotDone::Raise(); - if ((N < 1) || (N > mynbext)) Standard_OutOfRange::Raise(); - return mySqDist.Value(N); -} - -//======================================================================= -//function : ParameterOnFace -//purpose : -//======================================================================= - -void BRepExtrema_ExtCF::ParameterOnFace(const Standard_Integer N, - Standard_Real& U, - Standard_Real& V) const -{ - if(!myExtrem.IsDone()) StdFail_NotDone::Raise(); - if ((N < 1) || (N > mynbext)) Standard_OutOfRange::Raise(); - myPointsOnS.Value(N).Parameter(U, V); -} - -//======================================================================= -//function : ParameterOnEdge -//purpose : -//======================================================================= - -Standard_Real BRepExtrema_ExtCF::ParameterOnEdge - (const Standard_Integer N) const -{ - if(!myExtrem.IsDone()) StdFail_NotDone::Raise(); - if ((N < 1) || (N > mynbext)) Standard_OutOfRange::Raise(); - return myPointsOnC.Value(N).Parameter(); -} - -//======================================================================= -//function : PointOnEdge -//purpose : -//======================================================================= - -gp_Pnt BRepExtrema_ExtCF::PointOnEdge - (const Standard_Integer N) const -{ - if(!myExtrem.IsDone()) StdFail_NotDone::Raise(); - if ((N < 1) || (N > mynbext)) Standard_OutOfRange::Raise(); - gp_Pnt P = myPointsOnC.Value(N).Value(); - return P; -} - -//======================================================================= -//function : PointOnFace -//purpose : -//======================================================================= - -gp_Pnt BRepExtrema_ExtCF::PointOnFace - (const Standard_Integer N) const -{ - if(!myExtrem.IsDone()) StdFail_NotDone::Raise(); - if ((N < 1) || (N > mynbext)) Standard_OutOfRange::Raise(); - gp_Pnt P = myPointsOnS.Value(N).Value(); - return P; -} - diff --git a/src/BRepExtrema/BRepExtrema_ExtCF.hxx b/src/BRepExtrema/BRepExtrema_ExtCF.hxx new file mode 100644 index 0000000000..1fb6d62743 --- /dev/null +++ b/src/BRepExtrema/BRepExtrema_ExtCF.hxx @@ -0,0 +1,129 @@ +// This file is generated by WOK (CPPExt). +// Please do not edit this file; modify original file instead. +// The copyright and license terms as defined for the original file apply to +// this header file considered to be the "object code" form of the original source. + +#ifndef _BRepExtrema_ExtCF_HeaderFile +#define _BRepExtrema_ExtCF_HeaderFile + +#ifndef _Standard_HeaderFile +#include +#endif +#ifndef _Standard_Macro_HeaderFile +#include +#endif + +#ifndef _Extrema_ExtCS_HeaderFile +#include +#endif +#ifndef _Standard_Integer_HeaderFile +#include +#endif +#ifndef _TColStd_SequenceOfReal_HeaderFile +#include +#endif +#ifndef _Extrema_SequenceOfPOnSurf_HeaderFile +#include +#endif +#ifndef _Extrema_SequenceOfPOnCurv_HeaderFile +#include +#endif +#ifndef _Handle_BRepAdaptor_HSurface_HeaderFile +#include +#endif +#ifndef _Standard_Boolean_HeaderFile +#include +#endif +#ifndef _Standard_Real_HeaderFile +#include +#endif +#ifndef _Extrema_POnCurv_HeaderFile +#include +#endif +#ifndef _Extrema_POnSurf_HeaderFile +#include +#endif +class BRepAdaptor_HSurface; +class TopoDS_Edge; +class TopoDS_Face; +class gp_Pnt; + + +class BRepExtrema_ExtCF +{ + public: + + void* operator new(size_t,void* anAddress) + { + return anAddress; + } + void* operator new(size_t size) + { + return Standard::Allocate(size); + } + void operator delete(void *anAddress) + { + if (anAddress) Standard::Free((Standard_Address&)anAddress); + } + + Standard_EXPORT BRepExtrema_ExtCF() + { + } + //! It calculates all the distances.
+ Standard_EXPORT BRepExtrema_ExtCF(const TopoDS_Edge& V,const TopoDS_Face& E); + + Standard_EXPORT void Initialize(const TopoDS_Face& E); + //! An exception is raised if the fields have not been initialized.
+ //! Be careful: this method uses the Face only for classify not for the fields.
+ Standard_EXPORT void Perform(const TopoDS_Edge& V,const TopoDS_Face& F); + //! True if the distances are found.
+ Standard_EXPORT Standard_Boolean IsDone() const + { + return myExtCS.IsDone(); + } + //! Returns the number of extremum distances.
+ Standard_EXPORT Standard_Integer NbExt() const + { + return mySqDist.Length(); + } + //! Returns the value of the th extremum square distance.
+ Standard_EXPORT Standard_Real SquareDistance(const Standard_Integer N) const + { + return mySqDist.Value(N); + } + //! Returns True if the curve is on a parallel surface.
+ Standard_EXPORT Standard_Boolean IsParallel() const + { + return myExtCS.IsParallel(); + } + //! Returns the parameters on the Edge of the th extremum distance.
+ Standard_EXPORT Standard_Real ParameterOnEdge(const Standard_Integer N) const + { + return myPointsOnC.Value(N).Parameter(); + } + //! Returns the parameters on the Face of the th extremum distance.
+ Standard_EXPORT void ParameterOnFace(const Standard_Integer N,Standard_Real& U,Standard_Real& V) const + { + myPointsOnS.Value(N).Parameter(U, V); + } + //! Returns the Point of the th extremum distance.
+ Standard_EXPORT gp_Pnt PointOnEdge(const Standard_Integer N) const + { + return myPointsOnC.Value(N).Value(); + } + //! Returns the Point of the th extremum distance.
+ Standard_EXPORT gp_Pnt PointOnFace(const Standard_Integer N) const + { + return myPointsOnS.Value(N).Value(); + } + + private: + + Extrema_ExtCS myExtCS; + TColStd_SequenceOfReal mySqDist; + Extrema_SequenceOfPOnSurf myPointsOnS; + Extrema_SequenceOfPOnCurv myPointsOnC; + Handle_BRepAdaptor_HSurface myHS; +}; + +#endif diff --git a/src/BRepExtrema/BRepExtrema_ExtFF.cxx b/src/BRepExtrema/BRepExtrema_ExtFF.cxx index 466bb1203f..515a8e2c3f 100755 --- a/src/BRepExtrema/BRepExtrema_ExtFF.cxx +++ b/src/BRepExtrema/BRepExtrema_ExtFF.cxx @@ -1,22 +1,15 @@ // File: BRepExtrema_ExtFF.cxx // Created: Wed Dec 15 16:48:53 1993 // Author: Christophe MARION -// // modified by mps (juillet 96 ): on utilise BRepAdaptor a la place de // GeomAdaptor dans Initialize et Perform. -#include + +#include + #include #include #include -#include -#include -#include #include -#include -#include -#include -#include -#include #include #include #include @@ -26,22 +19,12 @@ //purpose : //======================================================================= -BRepExtrema_ExtFF::BRepExtrema_ExtFF() -{ -} - -//======================================================================= -//function : BRepExtrema_ExtFF -//purpose : -//======================================================================= - -BRepExtrema_ExtFF::BRepExtrema_ExtFF - (const TopoDS_Face& F1, - const TopoDS_Face& F2) +BRepExtrema_ExtFF::BRepExtrema_ExtFF(const TopoDS_Face& F1, const TopoDS_Face& F2) { Initialize(F2); Perform(F1,F2); } + //======================================================================= //function : Initialize //purpose : @@ -51,11 +34,10 @@ void BRepExtrema_ExtFF::Initialize(const TopoDS_Face& F2) { BRepAdaptor_Surface Surf(F2); myHS = new BRepAdaptor_HSurface(Surf); - Standard_Real Tol = BRep_Tool::Tolerance(F2); + const Standard_Real Tol = BRep_Tool::Tolerance(F2); Standard_Real U1, U2, V1, V2; BRepTools::UVBounds(F2, U1, U2, V1, V2); - myExtrem.Initialize(myHS->Surface(), U1, U2, V1, V2, Tol); - + myExtSS.Initialize(myHS->Surface(), U1, U2, V1, V2, Tol); } //======================================================================= @@ -63,156 +45,52 @@ void BRepExtrema_ExtFF::Initialize(const TopoDS_Face& F2) //purpose : //======================================================================= -void BRepExtrema_ExtFF::Perform(const TopoDS_Face& F1, - const TopoDS_Face& F2) +void BRepExtrema_ExtFF::Perform(const TopoDS_Face& F1, const TopoDS_Face& F2) { - Standard_Real U1, U2, V1, V2; - Standard_Integer i; mySqDist.Clear(); myPointsOnS1.Clear(); myPointsOnS2.Clear(); + BRepAdaptor_Surface Surf1(F1); Handle(BRepAdaptor_HSurface) HS1 = new BRepAdaptor_HSurface(Surf1); - Standard_Real Tol1 = BRep_Tool::Tolerance(F1); + const Standard_Real Tol1 = BRep_Tool::Tolerance(F1); + Standard_Real U1, U2, V1, V2; BRepTools::UVBounds(F1, U1, U2, V1, V2); - myExtrem.Perform(HS1->Surface(), U1, U2, V1, V2, Tol1); - + myExtSS.Perform(HS1->Surface(), U1, U2, V1, V2, Tol1); - // exploration des points et classification: - BRepClass_FaceClassifier classifier; - gp_Pnt2d Puv; - TopAbs_State state1, state2; - Standard_Real Tol2 = BRep_Tool::Tolerance(F2); - Extrema_POnSurf P1, P2; - mynbext = 0; + if (!myExtSS.IsDone()) + return; - if (myExtrem.IsParallel()) { - mySqDist.Append(myExtrem.SquareDistance(1)); - mynbext = 1; - } - else { - for (i = 1; i <= myExtrem.NbExt(); i++) { - myExtrem.Points(i, P1, P2); + if (myExtSS.IsParallel()) + mySqDist.Append(myExtSS.SquareDistance(1)); + else + { + // Exploration of points and classification + BRepClass_FaceClassifier classifier; + const Standard_Real Tol2 = BRep_Tool::Tolerance(F2); + Extrema_POnSurf P1, P2; + + Standard_Integer i; + for (i = 1; i <= myExtSS.NbExt(); i++) + { + myExtSS.Points(i, P1, P2); P1.Parameter(U1, U2); - Puv.SetCoord(U1, U2); - classifier.Perform(F1, Puv, Tol1); - state1 = classifier.State(); - P2.Parameter(U1, U2); - Puv.SetCoord(U1, U2); - classifier.Perform(F2, Puv, Tol2); - state2 = classifier.State(); - if((state1 == TopAbs_ON || state1 == TopAbs_IN) && - (state2 == TopAbs_ON || state2 == TopAbs_IN)) { - mynbext++; - mySqDist.Append(myExtrem.SquareDistance(i)); - myPointsOnS1.Append(P1); - myPointsOnS2.Append(P2); + const gp_Pnt2d Puv1(U1, U2); + classifier.Perform(F1, Puv1, Tol1); + const TopAbs_State state1 = classifier.State(); + if (state1 == TopAbs_ON || state1 == TopAbs_IN) + { + P2.Parameter(U1, U2); + const gp_Pnt2d Puv2(U1, U2); + classifier.Perform(F2, Puv2, Tol2); + const TopAbs_State state2 = classifier.State(); + if (state2 == TopAbs_ON || state2 == TopAbs_IN) + { + mySqDist.Append(myExtSS.SquareDistance(i)); + myPointsOnS1.Append(P1); + myPointsOnS2.Append(P2); + } } } } } - -//======================================================================= -//function : IsDone -//purpose : -//======================================================================= - -Standard_Boolean BRepExtrema_ExtFF::IsDone()const -{ - return myExtrem.IsDone(); -} - -//======================================================================= -//function : IsParallel -//purpose : -//======================================================================= - -Standard_Boolean BRepExtrema_ExtFF::IsParallel()const -{ - return myExtrem.IsParallel(); -} - - -//======================================================================= -//function : NbExt -//purpose : -//======================================================================= - -Standard_Integer BRepExtrema_ExtFF::NbExt() const -{ - if(!myExtrem.IsDone()) StdFail_NotDone::Raise(); - return mynbext; -} - - -//======================================================================= -//function : SquareDistance -//purpose : -//======================================================================= - -Standard_Real BRepExtrema_ExtFF::SquareDistance - (const Standard_Integer N) const -{ - if(!myExtrem.IsDone()) StdFail_NotDone::Raise(); - if ((N < 1) || (N > mynbext)) Standard_OutOfRange::Raise(); - return mySqDist.Value(N); -} - -//======================================================================= -//function : ParameterOnFace1 -//purpose : -//======================================================================= - -void BRepExtrema_ExtFF::ParameterOnFace1(const Standard_Integer N, - Standard_Real& U, - Standard_Real& V) const -{ - if(!myExtrem.IsDone()) StdFail_NotDone::Raise(); - if ((N < 1) || (N > mynbext)) Standard_OutOfRange::Raise(); - myPointsOnS1.Value(N).Parameter(U, V); -} - -//======================================================================= -//function : PointOnFace1 -//purpose : -//======================================================================= - -gp_Pnt BRepExtrema_ExtFF::PointOnFace1 - (const Standard_Integer N) const -{ - if(!myExtrem.IsDone()) StdFail_NotDone::Raise(); - if ((N < 1) || (N > mynbext)) Standard_OutOfRange::Raise(); - gp_Pnt P = myPointsOnS1.Value(N).Value(); - return P; -} - - -//======================================================================= -//function : ParameterOnFace2 -//purpose : -//======================================================================= - -void BRepExtrema_ExtFF::ParameterOnFace2(const Standard_Integer N, - Standard_Real& U, - Standard_Real& V) const -{ - if(!myExtrem.IsDone()) StdFail_NotDone::Raise(); - if ((N < 1) || (N > mynbext)) Standard_OutOfRange::Raise(); - myPointsOnS2.Value(N).Parameter(U, V); -} - -//======================================================================= -//function : PointOnFace1 -//purpose : -//======================================================================= - -gp_Pnt BRepExtrema_ExtFF::PointOnFace2 - (const Standard_Integer N) const -{ - if(!myExtrem.IsDone()) StdFail_NotDone::Raise(); - if ((N < 1) || (N > mynbext)) Standard_OutOfRange::Raise(); - gp_Pnt P = myPointsOnS2.Value(N).Value(); - return P; -} - - diff --git a/src/BRepExtrema/BRepExtrema_ExtFF.hxx b/src/BRepExtrema/BRepExtrema_ExtFF.hxx new file mode 100644 index 0000000000..9e2035e7d7 --- /dev/null +++ b/src/BRepExtrema/BRepExtrema_ExtFF.hxx @@ -0,0 +1,124 @@ +// This file is generated by WOK (CPPExt). +// Please do not edit this file; modify original file instead. +// The copyright and license terms as defined for the original file apply to +// this header file considered to be the "object code" form of the original source. + +#ifndef _BRepExtrema_ExtFF_HeaderFile +#define _BRepExtrema_ExtFF_HeaderFile + +#ifndef _Standard_HeaderFile +#include +#endif +#ifndef _Standard_Macro_HeaderFile +#include +#endif + +#ifndef _Extrema_ExtSS_HeaderFile +#include +#endif +#ifndef _Standard_Integer_HeaderFile +#include +#endif +#ifndef _TColStd_SequenceOfReal_HeaderFile +#include +#endif +#ifndef _Extrema_SequenceOfPOnSurf_HeaderFile +#include +#endif +#ifndef _Handle_BRepAdaptor_HSurface_HeaderFile +#include +#endif +#ifndef _Standard_Boolean_HeaderFile +#include +#endif +#ifndef _Standard_Real_HeaderFile +#include +#endif +#ifndef _Extrema_POnSurf_HeaderFile +#include +#endif +class BRepAdaptor_HSurface; +class TopoDS_Face; +class gp_Pnt; + + + +class BRepExtrema_ExtFF +{ + public: + + void* operator new(size_t,void* anAddress) + { + return anAddress; + } + void* operator new(size_t size) + { + return Standard::Allocate(size); + } + void operator delete(void *anAddress) + { + if (anAddress) Standard::Free((Standard_Address&)anAddress); + } + + + Standard_EXPORT BRepExtrema_ExtFF() + { + } + //! It calculates all the distances.
+ Standard_EXPORT BRepExtrema_ExtFF(const TopoDS_Face& F1,const TopoDS_Face& F2); + + Standard_EXPORT void Initialize(const TopoDS_Face& F2) ; + //! An exception is raised if the fields have not been initialized.
+ //! Be careful: this method uses the Face F2 only for classify, not for the fields.
+ Standard_EXPORT void Perform(const TopoDS_Face& F1,const TopoDS_Face& F2); + //! True if the distances are found.
+ Standard_EXPORT Standard_Boolean IsDone() const + { + return myExtSS.IsDone(); + } + //! Returns True if the surfaces are parallel.
+ Standard_EXPORT Standard_Boolean IsParallel() const + { + return myExtSS.IsParallel(); + } + //! Returns the number of extremum distances.
+ Standard_EXPORT Standard_Integer NbExt() const + { + return mySqDist.Length(); + } + //! Returns the value of the th extremum square distance.
+ Standard_EXPORT Standard_Real SquareDistance(const Standard_Integer N) const + { + return mySqDist.Value(N); + } + //! Returns the parameters on the Face F1 of the th extremum distance.
+ Standard_EXPORT void ParameterOnFace1(const Standard_Integer N,Standard_Real& U,Standard_Real& V) const + { + myPointsOnS1.Value(N).Parameter(U, V); + } + //! Returns the parameters on the Face F2 of the th extremum distance.
+ Standard_EXPORT void ParameterOnFace2(const Standard_Integer N,Standard_Real& U,Standard_Real& V) const + { + myPointsOnS2.Value(N).Parameter(U, V); + } + //! Returns the Point of the th extremum distance.
+ Standard_EXPORT gp_Pnt PointOnFace1(const Standard_Integer N) const + { + return myPointsOnS1.Value(N).Value(); + } + //! Returns the Point of the th extremum distance.
+ Standard_EXPORT gp_Pnt PointOnFace2(const Standard_Integer N) const + { + return myPointsOnS2.Value(N).Value(); + } + + private: + + Extrema_ExtSS myExtSS; + TColStd_SequenceOfReal mySqDist; + Extrema_SequenceOfPOnSurf myPointsOnS1; + Extrema_SequenceOfPOnSurf myPointsOnS2; + Handle_BRepAdaptor_HSurface myHS; +}; + +#endif diff --git a/src/BRepExtrema/BRepExtrema_ExtPC.cxx b/src/BRepExtrema/BRepExtrema_ExtPC.cxx index 2f4250ffbf..6dbb59d31e 100755 --- a/src/BRepExtrema/BRepExtrema_ExtPC.cxx +++ b/src/BRepExtrema/BRepExtrema_ExtPC.cxx @@ -1,12 +1,12 @@ // File: BRepExtrema_ExtPC.cxx // Created: Wed Dec 15 16:48:53 1993 // Author: Christophe MARION -// -#include +#include + #include -#include -#include +//#include +//#include #include #include @@ -16,18 +16,7 @@ //purpose : //======================================================================= -BRepExtrema_ExtPC::BRepExtrema_ExtPC() -{ -} - -//======================================================================= -//function : BRepExtrema_ExtPC -//purpose : -//======================================================================= - -BRepExtrema_ExtPC::BRepExtrema_ExtPC - (const TopoDS_Vertex& V, - const TopoDS_Edge& E) +BRepExtrema_ExtPC::BRepExtrema_ExtPC(const TopoDS_Vertex& V, const TopoDS_Edge& E) { Initialize(E); Perform(V); @@ -44,7 +33,7 @@ void BRepExtrema_ExtPC::Initialize(const TopoDS_Edge& E) BRepAdaptor_Curve Curv(E); myHC = new BRepAdaptor_HCurve(Curv); BRep_Tool::Range(E,U1,U2); - myExtrem.Initialize(myHC->Curve(),U1,U2); + myExtPC.Initialize(myHC->Curve(),U1,U2); } //======================================================================= @@ -55,93 +44,5 @@ void BRepExtrema_ExtPC::Initialize(const TopoDS_Edge& E) void BRepExtrema_ExtPC::Perform(const TopoDS_Vertex& V) { gp_Pnt P = BRep_Tool::Pnt(V); - myExtrem.Perform(P); + myExtPC.Perform(P); } - -//======================================================================= -//function : IsDone -//purpose : -//======================================================================= - -Standard_Boolean BRepExtrema_ExtPC::IsDone()const -{ - return myExtrem.IsDone(); -} - -//======================================================================= -//function : NbExt -//purpose : -//======================================================================= - -Standard_Integer BRepExtrema_ExtPC::NbExt() const -{ - if(!myExtrem.IsDone()) StdFail_NotDone::Raise(); - return myExtrem.NbExt(); -} - -//======================================================================= -//function : IsMin -//purpose : -//======================================================================= - -Standard_Boolean BRepExtrema_ExtPC::IsMin - (const Standard_Integer N) const -{ - if(!myExtrem.IsDone()) StdFail_NotDone::Raise(); - if ((N < 1) || (N > myExtrem.NbExt())) Standard_OutOfRange::Raise(); - return myExtrem.IsMin(N); -} - -//======================================================================= -//function : Value -//purpose : -//======================================================================= - -Standard_Real BRepExtrema_ExtPC::SquareDistance - (const Standard_Integer N) const -{ - if(!myExtrem.IsDone()) StdFail_NotDone::Raise(); - if ((N < 1) || (N > myExtrem.NbExt())) Standard_OutOfRange::Raise(); - return myExtrem.SquareDistance(N); -} - -//======================================================================= -//function : Parameter -//purpose : -//======================================================================= - -Standard_Real BRepExtrema_ExtPC::Parameter - (const Standard_Integer N) const -{ - if(!myExtrem.IsDone()) StdFail_NotDone::Raise(); - if ((N < 1) || (N > myExtrem.NbExt())) Standard_OutOfRange::Raise(); - return myExtrem.Point(N).Parameter(); -} - -//======================================================================= -//function : Point -//purpose : -//======================================================================= - -gp_Pnt BRepExtrema_ExtPC::Point - (const Standard_Integer N) const -{ - if(!myExtrem.IsDone()) StdFail_NotDone::Raise(); - if ((N < 1) || (N > myExtrem.NbExt())) Standard_OutOfRange::Raise(); - return (myExtrem.Point(N).Value()); -} - -//======================================================================= -//function : TrimmedDistances -//purpose : -//======================================================================= - -void BRepExtrema_ExtPC::TrimmedSquareDistances - (Standard_Real& dist1, - Standard_Real& dist2, - gp_Pnt& pnt1, - gp_Pnt& pnt2) const -{ - myExtrem.TrimmedSquareDistances(dist1,dist2,pnt1,pnt2); -} - diff --git a/src/BRepExtrema/BRepExtrema_ExtPC.hxx b/src/BRepExtrema/BRepExtrema_ExtPC.hxx new file mode 100644 index 0000000000..631d1ac39e --- /dev/null +++ b/src/BRepExtrema/BRepExtrema_ExtPC.hxx @@ -0,0 +1,110 @@ +// This file is generated by WOK (CPPExt). +// Please do not edit this file; modify original file instead. +// The copyright and license terms as defined for the original file apply to +// this header file considered to be the "object code" form of the original source. + +#ifndef _BRepExtrema_ExtPC_HeaderFile +#define _BRepExtrema_ExtPC_HeaderFile + +#ifndef _Standard_HeaderFile +#include +#endif +#ifndef _Standard_Macro_HeaderFile +#include +#endif + +#ifndef _Extrema_ExtPC_HeaderFile +#include +#endif +#ifndef _Handle_BRepAdaptor_HCurve_HeaderFile +#include +#endif +#ifndef _Standard_Boolean_HeaderFile +#include +#endif +#ifndef _Standard_Integer_HeaderFile +#include +#endif +#ifndef _Standard_Real_HeaderFile +#include +#endif +class BRepAdaptor_HCurve; +class TopoDS_Vertex; +class TopoDS_Edge; +class gp_Pnt; + + +class BRepExtrema_ExtPC +{ + public: + + void* operator new(size_t,void* anAddress) + { + return anAddress; + } + void* operator new(size_t size) + { + return Standard::Allocate(size); + } + void operator delete(void *anAddress) + { + if (anAddress) Standard::Free((Standard_Address&)anAddress); + } + + + Standard_EXPORT BRepExtrema_ExtPC() + { + } + //! It calculates all the distances.
+ Standard_EXPORT BRepExtrema_ExtPC(const TopoDS_Vertex& V,const TopoDS_Edge& E); + + Standard_EXPORT void Initialize(const TopoDS_Edge& E); + //! An exception is raised if the fields have not been initialized.
+ Standard_EXPORT void Perform(const TopoDS_Vertex& V); + //! True if the distances are found.
+ Standard_EXPORT Standard_Boolean IsDone() const + { + return myExtPC.IsDone(); + } + //! Returns the number of extremum distances.
+ Standard_EXPORT Standard_Integer NbExt() const + { + return myExtPC.NbExt(); + } + //! Returns True if the th extremum distance is a minimum.
+ Standard_EXPORT Standard_Boolean IsMin(const Standard_Integer N) const + { + return myExtPC.IsMin(N); + } + //! Returns the value of the th extremum square distance.
+ Standard_EXPORT Standard_Real SquareDistance(const Standard_Integer N) const + { + return myExtPC.SquareDistance(N); + } + //! Returns the parameter on the edge of the th extremum distance.
+ Standard_EXPORT Standard_Real Parameter(const Standard_Integer N) const + { + return myExtPC.Point(N).Parameter(); + } + //! Returns the Point of the th extremum distance.
+ Standard_EXPORT gp_Pnt Point(const Standard_Integer N) const + { + return myExtPC.Point(N).Value(); + } + //! if the curve is a trimmed curve,
+ //! dist1 is a square distance between

and the point
+ //! of parameter FirstParameter and
+ //! dist2 is a square distance between

and the point
+ //! of parameter LastParameter .
+ Standard_EXPORT void TrimmedSquareDistances(Standard_Real& dist1,Standard_Real& dist2,gp_Pnt& pnt1,gp_Pnt& pnt2) const + { + myExtPC.TrimmedSquareDistances(dist1,dist2,pnt1,pnt2); + } + + private: + + Extrema_ExtPC myExtPC; + Handle_BRepAdaptor_HCurve myHC; +}; + +#endif diff --git a/src/BRepExtrema/BRepExtrema_ExtPF.cxx b/src/BRepExtrema/BRepExtrema_ExtPF.cxx index a30002cb87..ca3037cd9b 100755 --- a/src/BRepExtrema/BRepExtrema_ExtPF.cxx +++ b/src/BRepExtrema/BRepExtrema_ExtPF.cxx @@ -1,41 +1,27 @@ // File: BRepExtrema_ExtPF.cxx // Created: Wed Dec 15 16:48:53 1993 // Author: Christophe MARION -// // modified by MPS (june 96) : on utilise BRepClass_FaceClassifier seulement // si IsDone de Extrema est vrai -#include + +#include + #include #include -#include -#include #include #include -#include -#include #include -#include //======================================================================= //function : BRepExtrema_ExtPF //purpose : //======================================================================= -BRepExtrema_ExtPF::BRepExtrema_ExtPF() +BRepExtrema_ExtPF::BRepExtrema_ExtPF(const TopoDS_Vertex& TheVertex, const TopoDS_Face& TheFace, + const Extrema_ExtFlag TheFlag, const Extrema_ExtAlgo TheAlgo) { -} - -//======================================================================= -//function : BRepExtrema_ExtPF -//purpose : -//======================================================================= - -BRepExtrema_ExtPF::BRepExtrema_ExtPF - (const TopoDS_Vertex& V, - const TopoDS_Face& E) -{ - Initialize(E); - Perform(V, E); + Initialize(TheFace,TheFlag,TheAlgo); + Perform(TheVertex,TheFace); } //======================================================================= @@ -43,15 +29,18 @@ BRepExtrema_ExtPF::BRepExtrema_ExtPF //purpose : //======================================================================= -void BRepExtrema_ExtPF::Initialize(const TopoDS_Face& F) +void BRepExtrema_ExtPF::Initialize(const TopoDS_Face& TheFace, + const Extrema_ExtFlag TheFlag, const Extrema_ExtAlgo TheAlgo) { // cette surface doit etre en champ. Extrema ne fait // pas de copie et prend seulement un pointeur dessus. - mySurf.Initialize(F, Standard_False); - Standard_Real Tol = BRep_Tool::Tolerance(F); + mySurf.Initialize(TheFace, Standard_False); + const Standard_Real Tol = BRep_Tool::Tolerance(TheFace); Standard_Real U1, U2, V1, V2; - BRepTools::UVBounds(F, U1, U2, V1, V2); - myExtrem.Initialize(mySurf, U1, U2, V1, V2, Tol, Tol); + BRepTools::UVBounds(TheFace, U1, U2, V1, V2); + myExtPS.SetFlag(TheFlag); + myExtPS.SetAlgo(TheAlgo); + myExtPS.Initialize(mySurf, U1, U2, V1, V2, Tol, Tol); } //======================================================================= @@ -59,95 +48,31 @@ void BRepExtrema_ExtPF::Initialize(const TopoDS_Face& F) //purpose : //======================================================================= -void BRepExtrema_ExtPF::Perform(const TopoDS_Vertex& V, - const TopoDS_Face& E) +void BRepExtrema_ExtPF::Perform(const TopoDS_Vertex& TheVertex, const TopoDS_Face& TheFace) { mySqDist.Clear(); myPoints.Clear(); - gp_Pnt P = BRep_Tool::Pnt(V); - myExtrem.Perform(P); - // exploration des points et classification: - if (myExtrem.IsDone()) { - BRepClass_FaceClassifier classifier; - gp_Pnt2d Puv; - Standard_Real U1, U2; - TopAbs_State state; - Standard_Real Tol = BRep_Tool::Tolerance(E); - mynbext = 0; - for (Standard_Integer i = 1; i <= myExtrem.NbExt(); i++) { - myExtrem.Point(i).Parameter(U1, U2); - Puv.SetCoord(U1, U2); - classifier.Perform(E, Puv, Tol); - state = classifier.State(); - if(state == TopAbs_ON || state == TopAbs_IN) { - mynbext++; - mySqDist.Append(myExtrem.SquareDistance(i)); - myPoints.Append(myExtrem.Point(i)); + const gp_Pnt P = BRep_Tool::Pnt(TheVertex); + myExtPS.Perform(P); + + // Exploration of points and classification + if (myExtPS.IsDone()) + { + BRepClass_FaceClassifier classifier; + Standard_Real U1, U2; + const Standard_Real Tol = BRep_Tool::Tolerance(TheFace); + for (Standard_Integer i = 1; i <= myExtPS.NbExt(); i++) + { + myExtPS.Point(i).Parameter(U1, U2); + const gp_Pnt2d Puv(U1, U2); + classifier.Perform(TheFace, Puv, Tol); + const TopAbs_State state = classifier.State(); + if(state == TopAbs_ON || state == TopAbs_IN) + { + mySqDist.Append(myExtPS.SquareDistance(i)); + myPoints.Append(myExtPS.Point(i)); + } } } - } -} -//======================================================================= -//function : IsDone -//purpose : -//======================================================================= - -Standard_Boolean BRepExtrema_ExtPF::IsDone()const -{ - return myExtrem.IsDone(); -} - -//======================================================================= -//function : NbExt -//purpose : -//======================================================================= - -Standard_Integer BRepExtrema_ExtPF::NbExt() const -{ - if(!myExtrem.IsDone()) StdFail_NotDone::Raise(); - return mynbext; -} - - -//======================================================================= -//function : Value -//purpose : -//======================================================================= - -Standard_Real BRepExtrema_ExtPF::SquareDistance - (const Standard_Integer N) const -{ - if(!myExtrem.IsDone()) StdFail_NotDone::Raise(); - if ((N < 1) || (N > mynbext)) Standard_OutOfRange::Raise(); - return mySqDist.Value(N); -} - -//======================================================================= -//function : Parameters -//purpose : -//======================================================================= - - -void BRepExtrema_ExtPF::Parameter(const Standard_Integer N, - Standard_Real& U, - Standard_Real& V) const -{ - if(!myExtrem.IsDone()) StdFail_NotDone::Raise(); - if ((N < 1) || (N > mynbext)) Standard_OutOfRange::Raise(); - myPoints.Value(N).Parameter(U, V); -} - -//======================================================================= -//function : Point -//purpose : -//======================================================================= - -gp_Pnt BRepExtrema_ExtPF::Point - (const Standard_Integer N) const -{ - if(!myExtrem.IsDone()) StdFail_NotDone::Raise(); - if ((N < 1) || (N > mynbext)) Standard_OutOfRange::Raise(); - gp_Pnt P = myPoints.Value(N).Value(); - return P; } diff --git a/src/BRepExtrema/BRepExtrema_ExtPF.hxx b/src/BRepExtrema/BRepExtrema_ExtPF.hxx new file mode 100644 index 0000000000..6e8ac30ccf --- /dev/null +++ b/src/BRepExtrema/BRepExtrema_ExtPF.hxx @@ -0,0 +1,139 @@ +// File generated by CPPExt (Value) +// +// Copyright (C) 1991 - 2000 by +// Matra Datavision SA. All rights reserved. +// +// Copyright (C) 2001 - 2004 by +// Open CASCADE SA. All rights reserved. +// +// This file is part of the Open CASCADE Technology software. +// +// This software may be distributed and/or modified under the terms and +// conditions of the Open CASCADE Public License as defined by Open CASCADE SA +// and appearing in the file LICENSE included in the packaging of this file. +// +// This software is distributed on an "AS IS" basis, without warranty of any +// kind, and Open CASCADE SA hereby disclaims all such warranties, +// including without limitation, any warranties of merchantability, fitness +// for a particular purpose or non-infringement. Please see the License for +// the specific terms and conditions governing rights and limitations under the +// License. + +#ifndef _BRepExtrema_ExtPF_HeaderFile +#define _BRepExtrema_ExtPF_HeaderFile + +#ifndef _Standard_HeaderFile +#include +#endif +#ifndef _Standard_Macro_HeaderFile +#include +#endif + +#ifndef _Extrema_ExtPS_HeaderFile +#include +#endif +#ifndef _Standard_Integer_HeaderFile +#include +#endif +#ifndef _TColStd_SequenceOfReal_HeaderFile +#include +#endif +#ifndef _Extrema_SequenceOfPOnSurf_HeaderFile +#include +#endif +#ifndef _BRepAdaptor_Surface_HeaderFile +#include +#endif +#ifndef _Extrema_ExtFlag_HeaderFile +#include +#endif +#ifndef _Extrema_ExtAlgo_HeaderFile +#include +#endif +#ifndef _Standard_Boolean_HeaderFile +#include +#endif +#ifndef _Standard_Real_HeaderFile +#include +#endif +class TopoDS_Vertex; +class TopoDS_Face; +class gp_Pnt; + + +class BRepExtrema_ExtPF +{ + public: + + void* operator new(size_t,void* anAddress) + { + return anAddress; + } + void* operator new(size_t size) + { + return Standard::Allocate(size); + } + void operator delete(void *anAddress) + { + if (anAddress) Standard::Free((Standard_Address&)anAddress); + } + + Standard_EXPORT BRepExtrema_ExtPF() + {} + //! It calculates all the distances.
+ Standard_EXPORT BRepExtrema_ExtPF(const TopoDS_Vertex& TheVertex,const TopoDS_Face& TheFace, + const Extrema_ExtFlag TheFlag = Extrema_ExtFlag_MINMAX, + const Extrema_ExtAlgo TheAlgo = Extrema_ExtAlgo_Grad); + + Standard_EXPORT void Initialize(const TopoDS_Face& TheFace, + const Extrema_ExtFlag TheFlag = Extrema_ExtFlag_MINMAX, + const Extrema_ExtAlgo TheAlgo = Extrema_ExtAlgo_Grad); + + //! An exception is raised if the fields have not been initialized.
+ //! Be careful: this method uses the Face only for classify not for the fields.
+ Standard_EXPORT void Perform(const TopoDS_Vertex& TheVertex,const TopoDS_Face& TheFace); + //! True if the distances are found.
+ Standard_EXPORT Standard_Boolean IsDone() const + { + return myExtPS.IsDone(); + } + //! Returns the number of extremum distances.
+ Standard_EXPORT Standard_Integer NbExt() const + { + return myPoints.Length(); + } + //! Returns the value of the th extremum square distance.
+ Standard_EXPORT Standard_Real SquareDistance(const Standard_Integer N) const + { + return mySqDist.Value(N); + } + //! Returns the parameters on the Face of the th extremum distance.
+ Standard_EXPORT void Parameter(const Standard_Integer N,Standard_Real& U,Standard_Real& V) const + { + myPoints.Value(N).Parameter(U, V); + } + //! Returns the Point of the th extremum distance.
+ Standard_EXPORT gp_Pnt Point(const Standard_Integer N) const + { + return myPoints.Value(N).Value(); + } + + Standard_EXPORT void SetFlag(const Extrema_ExtFlag F) + { + myExtPS.SetFlag(F); + } + + Standard_EXPORT void SetAlgo(const Extrema_ExtAlgo A) + { + myExtPS.SetAlgo(A); + } + + private: + + Extrema_ExtPS myExtPS; + TColStd_SequenceOfReal mySqDist; + Extrema_SequenceOfPOnSurf myPoints; + BRepAdaptor_Surface mySurf; +}; + +#endif diff --git a/src/BRepExtrema/BRepExtrema_Poly.cxx b/src/BRepExtrema/BRepExtrema_Poly.cxx index bcaa14f660..00d423c81e 100755 --- a/src/BRepExtrema/BRepExtrema_Poly.cxx +++ b/src/BRepExtrema/BRepExtrema_Poly.cxx @@ -1,9 +1,9 @@ // File: BRepExtrema_Poly.cxx // Created: Fri Sep 8 11:03:14 1995 // Author: Christophe MARION -// -#include +#include + #include #include #include @@ -17,56 +17,58 @@ //purpose : //======================================================================= -Standard_Boolean BRepExtrema_Poly::Distance (const TopoDS_Shape& S1, - const TopoDS_Shape& S2, - gp_Pnt& P1, - gp_Pnt& P2, - Standard_Real& dist) +Standard_Boolean BRepExtrema_Poly::Distance (const TopoDS_Shape& S1, const TopoDS_Shape& S2, + gp_Pnt& P1, gp_Pnt& P2, Standard_Real& dist) { - Standard_Real dCur; dist = Precision::Infinite(); - Standard_Integer i,i1,i2,n; - TopExp_Explorer exFace; - Handle(Poly_Triangulation) Tr; - TopLoc_Location L; - Standard_Integer nbn1 = 0; + TopLoc_Location L; + Handle(Poly_Triangulation) Tr; + TopExp_Explorer exFace; + + Standard_Integer nbn1 = 0; for (exFace.Init(S1, TopAbs_FACE); exFace.More(); - exFace.Next()) { + exFace.Next()) + { const TopoDS_Face& F = TopoDS::Face(exFace.Current()); Tr = BRep_Tool::Triangulation(F,L); if (!Tr.IsNull()) nbn1 += Tr->NbNodes(); } + if (nbn1 == 0) return Standard_False; + Standard_Integer nbn2 = 0; - for (exFace.Init(S2, TopAbs_FACE); exFace.More(); - exFace.Next()) { + exFace.Next()) + { const TopoDS_Face& F = TopoDS::Face(exFace.Current()); Tr = BRep_Tool::Triangulation(F,L); if (!Tr.IsNull()) nbn2 += Tr->NbNodes(); } + if (nbn2 == 0) return Standard_False; - if (nbn1 == 0 || nbn2 == 0) return Standard_False; + Standard_Integer i,n; TColgp_Array1OfPnt TP1(1,nbn1); nbn1 = 0; for (exFace.Init(S1, TopAbs_FACE); exFace.More(); - exFace.Next()) { + exFace.Next()) + { const TopoDS_Face& F = TopoDS::Face(exFace.Current()); Tr = BRep_Tool::Triangulation(F,L); - if (!Tr.IsNull()) { + if (!Tr.IsNull()) + { const TColgp_Array1OfPnt& Nod = Tr->Nodes(); n = Tr->NbNodes(); - - for (i = 1;i <= n; i++) { - nbn1++; - TP1.SetValue(nbn1,Nod(i).Transformed(L)); + for (i = 1; i <= n; i++) + { + nbn1++; + TP1.SetValue(nbn1,Nod(i).Transformed(L)); } } } @@ -76,34 +78,37 @@ Standard_Boolean BRepExtrema_Poly::Distance (const TopoDS_Shape& S1, for (exFace.Init(S2, TopAbs_FACE); exFace.More(); - exFace.Next()) { + exFace.Next()) + { const TopoDS_Face& F = TopoDS::Face(exFace.Current()); Tr = BRep_Tool::Triangulation(F,L); - if (!Tr.IsNull()) { + if (!Tr.IsNull()) + { const TColgp_Array1OfPnt& Nod = Tr->Nodes(); n = Tr->NbNodes(); - - for (i = 1;i <= n; i++) { - nbn2++; - TP2.SetValue(nbn2,Nod(i).Transformed(L)); + for (i = 1; i <= n; i++) + { + nbn2++; + TP2.SetValue(nbn2,Nod(i).Transformed(L)); } } } - - for (i1 = 1; i1 <= nbn1; i1++) { - gp_Pnt& PP1 = TP1(i1); - - for (i2 = 1; i2 <= nbn2; i2++) { - gp_Pnt& PP2 = TP2(i2); - - dCur = PP1.Distance(PP2); - if (dist > dCur) { - P1 = PP1; - P2 = PP2; - dist = dCur; + + Standard_Integer i1,i2; + for (i1 = 1; i1 <= nbn1; i1++) + { + const gp_Pnt& PP1 = TP1(i1); + for (i2 = 1; i2 <= nbn2; i2++) + { + const gp_Pnt& PP2 = TP2(i2); + const Standard_Real dCur = PP1.Distance(PP2); + if (dist > dCur) + { + P1 = PP1; + P2 = PP2; + dist = dCur; } } } return Standard_True; } - diff --git a/src/BRepExtrema/BRepExtrema_Poly.hxx b/src/BRepExtrema/BRepExtrema_Poly.hxx new file mode 100644 index 0000000000..41095abe29 --- /dev/null +++ b/src/BRepExtrema/BRepExtrema_Poly.hxx @@ -0,0 +1,34 @@ +// This file is generated by WOK (CPPExt). +// Please do not edit this file; modify original file instead. +// The copyright and license terms as defined for the original file apply to +// this header file considered to be the "object code" form of the original source. + +#ifndef _BRepExtrema_Poly_HeaderFile +#define _BRepExtrema_Poly_HeaderFile + +#ifndef _Standard_HeaderFile +#include +#endif +#ifndef _Standard_Macro_HeaderFile +#include +#endif + +#ifndef _Standard_Boolean_HeaderFile +#include +#endif +#ifndef _Standard_Real_HeaderFile +#include +#endif +class TopoDS_Shape; +class gp_Pnt; + + +class BRepExtrema_Poly +{ + public: + + //! returns Standard_True if OK.
+ Standard_EXPORT static Standard_Boolean Distance(const TopoDS_Shape& S1,const TopoDS_Shape& S2,gp_Pnt& P1,gp_Pnt& P2,Standard_Real& dist); +}; + +#endif diff --git a/src/BRepExtrema/BRepExtrema_SeqOfSolution.hxx b/src/BRepExtrema/BRepExtrema_SeqOfSolution.hxx new file mode 100644 index 0000000000..3c07a20a43 --- /dev/null +++ b/src/BRepExtrema/BRepExtrema_SeqOfSolution.hxx @@ -0,0 +1,18 @@ +// This file is generated by WOK (CPPExt). +// Please do not edit this file; modify original file instead. +// The copyright and license terms as defined for the original file apply to +// this header file considered to be the "object code" form of the original source. + +#ifndef _BRepExtrema_SeqOfSolution_HeaderFile +#define _BRepExtrema_SeqOfSolution_HeaderFile + +#ifndef _NCollection_Sequence_HeaderFile +#include +#endif +#ifndef _BRepExtrema_SolutionElem_HeaderFile +#include +#endif + +typedef NCollection_Sequence BRepExtrema_SeqOfSolution; + +#endif diff --git a/src/BRepExtrema/BRepExtrema_SolutionElem.hxx b/src/BRepExtrema/BRepExtrema_SolutionElem.hxx new file mode 100644 index 0000000000..1bf1a19738 --- /dev/null +++ b/src/BRepExtrema/BRepExtrema_SolutionElem.hxx @@ -0,0 +1,156 @@ +// This file is generated by WOK (CPPExt). +// Please do not edit this file; modify original file instead. +// The copyright and license terms as defined for the original file apply to +// this header file considered to be the "object code" form of the original source. + +#ifndef _BRepExtrema_SolutionElem_HeaderFile +#define _BRepExtrema_SolutionElem_HeaderFile + +#ifndef _Standard_HeaderFile +#include +#endif +#ifndef _Standard_Macro_HeaderFile +#include +#endif + +#ifndef _Standard_Real_HeaderFile +#include +#endif +#ifndef _gp_Pnt_HeaderFile +#include +#endif +#ifndef _BRepExtrema_SupportType_HeaderFile +#include +#endif +#ifndef _TopoDS_Vertex_HeaderFile +#include +#endif +#ifndef _TopoDS_Edge_HeaderFile +#include +#endif +#ifndef _TopoDS_Face_HeaderFile +#include +#endif +class gp_Pnt; +class TopoDS_Vertex; +class TopoDS_Edge; +class TopoDS_Face; + + +//! This class is used to store information relative to the
+//! minimum distance between two shapes.
+class BRepExtrema_SolutionElem +{ + public: + + void* operator new(size_t,void* anAddress) + { + return anAddress; + } + void* operator new(size_t size) + { + return Standard::Allocate(size); + } + void operator delete(void *anAddress) + { + if (anAddress) Standard::Free((Standard_Address&)anAddress); + } + + + Standard_EXPORT BRepExtrema_SolutionElem() + : myDist(0.), myPoint(0.,0.,0.), mySupType(BRepExtrema_IsVertex), myPar1(0.), myPar2(0.) + { + } + //! initialisation of the fields
+ //! This constructor is used when the solution of a distance is a Vertex.
+ //! The different initialized fields are:
+ //! _ the distance d
+ //! _ the solution point
+ //! _ the type of solution
+ //! _ and the Vertex.
+ Standard_EXPORT BRepExtrema_SolutionElem(const Standard_Real d,const gp_Pnt& Pt,const BRepExtrema_SupportType SolType,const TopoDS_Vertex& vertex) + : myDist(d), myPoint(Pt), mySupType(SolType), myVertex(vertex), myPar1(0.), myPar2(0.) + { + } + //! initialisation of the fiels.
+ //! This constructor is used when the solution of distance is on an Edge.
+ //! The different initialized fields are:
+ //! _ the distance d,
+ //! _ the solution point,
+ //! _ the type of solution,
+ //! _ the Edge,
+ //! _ and the parameter t to locate the solution.
+ Standard_EXPORT BRepExtrema_SolutionElem(const Standard_Real d,const gp_Pnt& Pt,const BRepExtrema_SupportType SolType,const TopoDS_Edge& edge,const Standard_Real t) + : myDist(d), myPoint(Pt), mySupType(SolType), myEdge(edge), myPar1(t), myPar2(0.) + { + } + //! initialisation of the fields
+ //! This constructor is used when the solution of distance is in
+ //! a Face. The different initialized fields are:
+ //! _ the distance d,
+ //! _ the solution point,
+ //! _ the type of solution,
+ //! _ the Face,
+ //! _ and the parameter u et v to locate the solution.
+ Standard_EXPORT BRepExtrema_SolutionElem(const Standard_Real d,const gp_Pnt& Pt,const BRepExtrema_SupportType SolType,const TopoDS_Face& face,const Standard_Real u,const Standard_Real v) + : myDist(d), myPoint(Pt), mySupType(SolType), myFace(face), myPar1(u), myPar2(v) + { + } + //! returns the value of the minimum distance.
+ Standard_EXPORT Standard_Real Dist() const + { + return myDist; + } + //! returns the solution point.
+ Standard_EXPORT const gp_Pnt & Point() const + { + return myPoint; + } + //! returns the Support type :
+ //! IsVertex => The solution is a vertex.
+ //! IsOnEdge => The solution belongs to an Edge.
+ //! IsInFace => The solution is inside a Face.
+ Standard_EXPORT BRepExtrema_SupportType SupportKind() const + { + return mySupType; + } + //! returns the vertex if the solution is a Vertex.
+ Standard_EXPORT const TopoDS_Vertex & Vertex() const + { + return myVertex; + } + //! returns the vertex if the solution is an Edge.
+ Standard_EXPORT const TopoDS_Edge & Edge() const + { + return myEdge; + } + //! returns the vertex if the solution is an Face.
+ Standard_EXPORT const TopoDS_Face & Face() const + { + return myFace; + } + //! returns the parameter t if the solution is on Edge.
+ Standard_EXPORT void EdgeParameter(Standard_Real& par1) const + { + par1 = myPar1; + } + //! returns the parameters u et v if the solution is in a Face.
+ Standard_EXPORT void FaceParameter(Standard_Real& par1,Standard_Real& par2) const + { + par1 = myPar1; + par2 = myPar2; + } + + private: + + Standard_Real myDist; + gp_Pnt myPoint; + BRepExtrema_SupportType mySupType; + TopoDS_Vertex myVertex; + TopoDS_Edge myEdge; + TopoDS_Face myFace; + Standard_Real myPar1; + Standard_Real myPar2; +}; + +#endif diff --git a/src/BRepExtrema/BRepExtrema_SupportType.hxx b/src/BRepExtrema/BRepExtrema_SupportType.hxx new file mode 100644 index 0000000000..a3d03e65c9 --- /dev/null +++ b/src/BRepExtrema/BRepExtrema_SupportType.hxx @@ -0,0 +1,20 @@ +// This file is generated by WOK (CPPExt). +// Please do not edit this file; modify original file instead. +// The copyright and license terms as defined for the original file apply to +// this header file considered to be the "object code" form of the original source. + +#ifndef _BRepExtrema_SupportType_HeaderFile +#define _BRepExtrema_SupportType_HeaderFile + +enum BRepExtrema_SupportType +{ + BRepExtrema_IsVertex, + BRepExtrema_IsOnEdge, + BRepExtrema_IsInFace +}; + +#ifndef _Standard_PrimitiveTypes_HeaderFile +#include +#endif + +#endif diff --git a/src/BRepExtrema/FILES b/src/BRepExtrema/FILES new file mode 100644 index 0000000000..87b4eceb2b --- /dev/null +++ b/src/BRepExtrema/FILES @@ -0,0 +1,19 @@ +BRepExtrema_DistanceSS.hxx +BRepExtrema_DistanceSS.cxx +BRepExtrema_DistShapeShape.hxx +BRepExtrema_DistShapeShape.cxx +BRepExtrema_ExtCC.hxx +BRepExtrema_ExtCC.cxx +BRepExtrema_ExtCF.hxx +BRepExtrema_ExtCF.cxx +BRepExtrema_ExtFF.hxx +BRepExtrema_ExtFF.cxx +BRepExtrema_ExtPC.hxx +BRepExtrema_ExtPC.cxx +BRepExtrema_ExtPF.hxx +BRepExtrema_ExtPF.cxx +BRepExtrema_Poly.hxx +BRepExtrema_Poly.cxx +BRepExtrema_SeqOfSolution.hxx +BRepExtrema_SolutionElem.hxx +BRepExtrema_SupportType.hxx diff --git a/src/Bnd/Bnd.cdl b/src/Bnd/Bnd.cdl index a34e294f26..7b473485d2 100755 --- a/src/Bnd/Bnd.cdl +++ b/src/Bnd/Bnd.cdl @@ -47,7 +47,8 @@ package Bnd uses Standard, TCollection, TColStd, - gp + gp, + MMgt is class Box; @@ -59,6 +60,13 @@ is class Box; (Box from Bnd, Array1OfBox from Bnd); + class Sphere; + class Array1OfSphere instantiates Array1 from TCollection + (Sphere from Bnd); + class HArray1OfSphere instantiates HArray1 from TCollection + (Sphere from Bnd, + Array1OfSphere from Bnd); + class Box2d; ---Purpose: A rectangle parallel to the main axes. diff --git a/src/Bnd/Bnd_Sphere.cdl b/src/Bnd/Bnd_Sphere.cdl new file mode 100644 index 0000000000..15f297823b --- /dev/null +++ b/src/Bnd/Bnd_Sphere.cdl @@ -0,0 +1,86 @@ +-- File: Bnd_Sphere.cdl +-- Created: Fri Dec 3 17:39:44 2010 +-- Author: Artem SHAL +---Copyright: OPEN CASCADE 2010 + +class Sphere from Bnd + + ---Purpose: This class represents a bounding sphere of a geometric entity + -- (triangle, segment of line or whatever else). + +uses XYZ from gp + +is + + Create returns Sphere; + ---Purpose: Empty constructor + + Create (theCntr : XYZ from gp; theRad : Real; theU : Integer; theV : Integer) + returns Sphere; + ---Purpose: Constructor of a definite sphere + + U (me) returns Integer; + ---C++: inline + ---Purpose: Returns the U parameter on shape + + V (me) returns Integer; + ---C++: inline + ---Purpose: Returns the V parameter on shape + + IsValid (me) returns Boolean; + ---C++: inline + ---Purpose: Returns validity status, indicating that this + -- sphere corresponds to a real entity + + SetValid (me : in out; isValid : Boolean); + ---C++: inline + + Center (me) returns XYZ from gp; + ---C++: inline + ---C++: return const & + ---Purpose: Returns center of sphere object + + Radius (me) returns Real; + ---C++: inline + ---Purpose: Returns the radius value + + Distances (me; theXYZ : XYZ from gp; theMin : in out Real; theMax : in out Real) is static; + ---Purpose: Calculate and return minimal and maximal distance to sphere. + -- NOTE: This function is tightly optimized; any modifications + -- may affect performance! + + SquareDistances (me; theXYZ : XYZ from gp; theMin : in out Real; theMax : in out Real) is static; + ---Purpose: Calculate and return minimal and maximal distance to sphere. + -- NOTE: This function is tightly optimized; any modifications + -- may affect performance! + + Project (me; theNode : XYZ from gp; theProjNode : in out XYZ from gp; theDist : in out Real; theInside : in out Boolean) + ---Purpose: Projects a point on entity. + -- Returns true if success + returns Boolean; + + Distance (me; theNode : XYZ from gp) + returns Real; + + SquareDistance (me; theNode : XYZ from gp) + returns Real; + + Add (me : in out; theOther : Sphere from Bnd); + + IsOut (me; theOther : Sphere from Bnd) + returns Boolean; + + IsOut (me; thePnt : XYZ from gp; theMaxDist : in out Real) + returns Boolean; + + SquareExtent (me) returns Real; + +fields + + myCenter : XYZ from gp; + myRadius : Real; + myIsValid : Boolean; + myU : Integer; + myV : Integer; + +end Sphere; diff --git a/src/Bnd/Bnd_Sphere.cxx b/src/Bnd/Bnd_Sphere.cxx new file mode 100644 index 0000000000..5217d4818a --- /dev/null +++ b/src/Bnd/Bnd_Sphere.cxx @@ -0,0 +1,102 @@ +#include + +Bnd_Sphere::Bnd_Sphere() + : myCenter (0., 0., 0.), + myRadius (0.), + myIsValid (Standard_False), + myU (0), + myV (0) +{} + +Bnd_Sphere::Bnd_Sphere( const gp_XYZ& theCenter, const Standard_Real theRadius, + const Standard_Integer theU, const Standard_Integer theV ) + : myCenter (theCenter), + myRadius (theRadius), + myIsValid (Standard_False), + myU (theU), + myV (theV) +{} + +void Bnd_Sphere::SquareDistances( const gp_XYZ& theXYZ, + Standard_Real& theMin, Standard_Real& theMax ) const +{ + theMax = ( theXYZ - myCenter ).SquareModulus(); + theMin = ( theMax - myRadius <0 ? 0.0 : theMax - myRadius * myRadius ); + theMax += myRadius * myRadius; +} + +void Bnd_Sphere::Distances( const gp_XYZ& theXYZ, + Standard_Real& theMin, Standard_Real& theMax ) const +{ + theMax = ( theXYZ - myCenter ).Modulus(); + theMin = ( theMax - myRadius <0 ? 0.0 : theMax - myRadius ); + theMax += myRadius; +} + +Standard_Boolean Bnd_Sphere::Project(const gp_XYZ& theNode, gp_XYZ& theProjNode, Standard_Real& theDist, Standard_Boolean& theInside) const +{ + theProjNode = myCenter; + theDist = ( theNode - theProjNode ).Modulus(); + theInside = Standard_True; + return Standard_True; +} + +Standard_Real Bnd_Sphere::Distance(const gp_XYZ& theNode) const +{ + return ( theNode - myCenter ).Modulus(); +} + +Standard_Real Bnd_Sphere::SquareDistance(const gp_XYZ& theNode) const +{ + return ( theNode - myCenter ).SquareModulus(); +} + +void Bnd_Sphere::Add( const Bnd_Sphere& theOther) +{ + if ( myRadius < 0.0 ) + { + // not initialised yet + *this = theOther; + return; + } + + const Standard_Real aDist = (myCenter - theOther.myCenter).Modulus(); + if ( myRadius + aDist <= theOther.myRadius ) + { + // the other sphere is larger and encloses this + *this = theOther; + return; + } + + if ( theOther.myRadius + aDist <= myRadius ) + return; // this sphere encloses other + + // expansion + const Standard_Real dfR = ( aDist + myRadius + theOther.myRadius ) * 0.5; + const Standard_Real aParamOnDiam = ( dfR - myRadius ) / aDist; + myCenter = myCenter * ( 1.0 - aParamOnDiam ) + theOther.myCenter * aParamOnDiam; + myRadius = dfR; + myIsValid = Standard_False; +} + +Standard_Boolean Bnd_Sphere::IsOut( const Bnd_Sphere& theOther ) const +{ + return (myCenter - theOther.myCenter).SquareModulus() > (myRadius + theOther.myRadius) * (myRadius + theOther.myRadius); +} + +Standard_Boolean Bnd_Sphere::IsOut( const gp_XYZ& theXYZ, + Standard_Real& theMaxDist) const +{ + Standard_Real aCurMinDist, aCurMaxDist; + Distances( theXYZ, aCurMinDist, aCurMaxDist ); + if ( aCurMinDist > theMaxDist ) + return Standard_True; + if( myIsValid && aCurMaxDist < theMaxDist ) + theMaxDist = aCurMaxDist; + return Standard_False; +} + +Standard_Real Bnd_Sphere::SquareExtent() const +{ + return 4 * myRadius * myRadius; +} diff --git a/src/Bnd/Bnd_Sphere.lxx b/src/Bnd/Bnd_Sphere.lxx new file mode 100644 index 0000000000..5e48d30a28 --- /dev/null +++ b/src/Bnd/Bnd_Sphere.lxx @@ -0,0 +1,30 @@ + +inline Standard_Integer Bnd_Sphere::U() const +{ + return myU; +} + +inline Standard_Integer Bnd_Sphere::V() const +{ + return myV; +} + +inline Standard_Boolean Bnd_Sphere::IsValid() const +{ + return myIsValid; +} + +inline void Bnd_Sphere::SetValid(const Standard_Boolean isValid) +{ + myIsValid = isValid; +} + +inline const gp_XYZ& Bnd_Sphere::Center() const +{ + return myCenter; +} + +inline Standard_Real Bnd_Sphere::Radius() const +{ + return myRadius; +} diff --git a/src/Extrema/Extrema.cdl b/src/Extrema/Extrema.cdl index b2356f6fe9..7739714698 100755 --- a/src/Extrema/Extrema.cdl +++ b/src/Extrema/Extrema.cdl @@ -30,10 +30,15 @@ uses Adaptor3d, Adaptor2d, Geom, - Geom2d + Geom2d, + Bnd is + enumeration ExtFlag is ExtFlag_MIN, ExtFlag_MAX, ExtFlag_MINMAX; + + enumeration ExtAlgo is ExtAlgo_Grad, ExtAlgo_Tree; + class CurveTool; class Curve2dTool; @@ -70,6 +75,7 @@ is private class FuncExtPS; class GenExtPS; class GenLocateExtPS; + imported HUBTreeOfSphere; ---------------------------------------------- -- generic classes for CURVE-CURVE extremas: diff --git a/src/Extrema/Extrema_ExtPS.cdl b/src/Extrema/Extrema_ExtPS.cdl index 4db7c281fe..d56de0370a 100755 --- a/src/Extrema/Extrema_ExtPS.cdl +++ b/src/Extrema/Extrema_ExtPS.cdl @@ -20,7 +20,9 @@ uses SequenceOfReal from TColStd, Surface from Adaptor3d, SurfacePtr from Adaptor3d, - GenExtPS from Extrema + GenExtPS from Extrema, + ExtFlag from Extrema, + ExtAlgo from Extrema -- ExtPExtS from Extrema, -- ExtPRevS from Extrema @@ -35,7 +37,9 @@ is Create returns ExtPS; - Create (P: Pnt from gp; S: Surface from Adaptor3d; TolU,TolV: Real) + Create (P: Pnt from gp; S: Surface from Adaptor3d; TolU,TolV: Real; + F : ExtFlag from Extrema = Extrema_ExtFlag_MINMAX; + A : ExtAlgo from Extrema = Extrema_ExtAlgo_Grad) returns ExtPS; ---Purpose: It calculates all the distances. -- NbU and NbV are used to locate the close points @@ -48,7 +52,9 @@ is Create (P: Pnt from gp; S: Surface from Adaptor3d; Uinf, Usup, Vinf, Vsup: Real; - TolU,TolV: Real) + TolU,TolV: Real; + F : ExtFlag from Extrema = Extrema_ExtFlag_MINMAX; + A : ExtAlgo from Extrema = Extrema_ExtAlgo_Grad) returns ExtPS; ---Purpose: It calculates all the distances. -- NbU and NbV are used to locate the close points @@ -114,6 +120,12 @@ is -- dUlVl is a square distance between

and the point -- of parameter LastUParameter and LastVParameter . is static; + + SetFlag(me : in out; F : ExtFlag from Extrema) + is static; + + SetAlgo(me : in out; A : ExtAlgo from Extrema) + is static; Bidon(me) returns SurfacePtr from Adaptor3d diff --git a/src/Extrema/Extrema_ExtPS.cxx b/src/Extrema/Extrema_ExtPS.cxx index 015d5996d6..290e5b6539 100755 --- a/src/Extrema/Extrema_ExtPS.cxx +++ b/src/Extrema/Extrema_ExtPS.cxx @@ -52,6 +52,9 @@ static Standard_Boolean IsoIsDeg (const Adaptor3d_Surface& S, if(Step < Precision::PConfusion()) { return Standard_False; } + if(Step < Precision::PConfusion()) { + return Standard_False; + } D1NormMax=0.; for (T=U1;T<=U2;T=T+Step) { @@ -68,6 +71,9 @@ static Standard_Boolean IsoIsDeg (const Adaptor3d_Surface& S, if(Step < Precision::PConfusion()) { return Standard_False; } + if(Step < Precision::PConfusion()) { + return Standard_False; + } D1NormMax=0.; for (T=V1;T<=V2;T=T+Step) { @@ -126,9 +132,13 @@ Extrema_ExtPS::Extrema_ExtPS() Extrema_ExtPS::Extrema_ExtPS(const gp_Pnt& P, const Adaptor3d_Surface& S, const Standard_Real TolU, - const Standard_Real TolV) + const Standard_Real TolV, + const Extrema_ExtFlag F, + const Extrema_ExtAlgo A) { + myExtPS.SetFlag(F); + myExtPS.SetAlgo(A); Initialize(S, S.FirstUParameter(), S.LastUParameter(), S.FirstVParameter(), S.LastVParameter(), TolU, TolV); @@ -147,9 +157,13 @@ Extrema_ExtPS::Extrema_ExtPS(const gp_Pnt& P, const Standard_Real Vinf, const Standard_Real Vsup, const Standard_Real TolU, - const Standard_Real TolV) + const Standard_Real TolV, + const Extrema_ExtFlag F, + const Extrema_ExtAlgo A) { + myExtPS.SetFlag(F); + myExtPS.SetAlgo(A); Initialize(S, Uinf, Usup, Vinf, Vsup, TolU, TolV); Perform(P); } @@ -336,3 +350,13 @@ void Extrema_ExtPS::TrimmedSquareDistances(Standard_Real& dUfVf, PUlVf = P21; PUlVl = P22; } + +void Extrema_ExtPS::SetFlag(const Extrema_ExtFlag F) +{ + myExtPS.SetFlag(F); +} + +void Extrema_ExtPS::SetAlgo(const Extrema_ExtAlgo A) +{ + myExtPS.SetAlgo(A); +} \ No newline at end of file diff --git a/src/Extrema/Extrema_GenExtPS.cdl b/src/Extrema/Extrema_GenExtPS.cdl index fa3b101ac9..fcf936e616 100755 --- a/src/Extrema/Extrema_GenExtPS.cdl +++ b/src/Extrema/Extrema_GenExtPS.cdl @@ -13,10 +13,15 @@ class GenExtPS from Extrema uses POnSurf from Extrema, Pnt from gp, - HArray2OfPnt from TColgp, FuncExtPS from Extrema, Surface from Adaptor3d, - SurfacePtr from Adaptor3d + SurfacePtr from Adaptor3d, + HUBTreeOfSphere from Extrema, + ExtFlag from Extrema, + ExtAlgo from Extrema, + HArray1OfSphere from Bnd, + Vector from math, + HArray2OfPnt from TColgp raises NotDone from StdFail, OutOfRange from Standard, @@ -27,7 +32,7 @@ is Create returns GenExtPS; - Create (P: Pnt; S: Surface from Adaptor3d; NbU,NbV: Integer; TolU,TolV: Real) + Create (P: Pnt; S: Surface from Adaptor3d; NbU,NbV: Integer; TolU,TolV: Real; F : ExtFlag from Extrema = Extrema_ExtFlag_MINMAX; A : ExtAlgo from Extrema = Extrema_ExtAlgo_Grad) returns GenExtPS; ---Purpose: It calculates all the distances. -- The function F(u,v)=distance(P,S(u,v)) has an @@ -44,7 +49,7 @@ is Create (P: Pnt; S: Surface from Adaptor3d; NbU,NbV: Integer; - Umin, Usup, Vmin, Vsup: Real; TolU,TolV: Real) + Umin, Usup, Vmin, Vsup: Real; TolU,TolV: Real; F : ExtFlag from Extrema = Extrema_ExtFlag_MINMAX; A : ExtAlgo from Extrema = Extrema_ExtAlgo_Grad) returns GenExtPS; ---Purpose: It calculates all the distances. -- The function F(u,v)=distance(P,S(u,v)) has an @@ -77,6 +82,12 @@ is -- been initialized. raises TypeMismatch from Standard is static; + + SetFlag(me : in out; F : ExtFlag from Extrema) + is static; + + SetAlgo(me : in out; A : ExtAlgo from Extrema) + is static; IsDone (me) returns Boolean @@ -107,6 +118,12 @@ is Bidon(me) returns SurfacePtr from Adaptor3d is static private; + + BuildTree(me : in out) + is static private; + + FindSolution(me: in out; P : Pnt from gp; UV : Vector from math; PasU, PasV : Real; f : ExtFlag from Extrema) + is static private; fields myDone : Boolean; @@ -117,10 +134,14 @@ fields myvsup : Real; myusample : Integer; myvsample : Integer; - mypoints : HArray2OfPnt from TColgp; mytolu : Real; mytolv : Real; + mypoints : HArray2OfPnt from TColgp; + mySphereUBTree : HUBTreeOfSphere from Extrema; + mySphereArray : HArray1OfSphere from Bnd; myF : FuncExtPS from Extrema; myS : SurfacePtr from Adaptor3d; + myFlag : ExtFlag from Extrema; + myAlgo : ExtAlgo from Extrema; end GenExtPS; diff --git a/src/Extrema/Extrema_GenExtPS.cxx b/src/Extrema/Extrema_GenExtPS.cxx index 06d3f1fa1c..1a1b13231c 100755 --- a/src/Extrema/Extrema_GenExtPS.cxx +++ b/src/Extrema/Extrema_GenExtPS.cxx @@ -16,55 +16,182 @@ #include #include #include +#include +#include +#include +#include +#include +//IMPLEMENT_HARRAY1(Extrema_HArray1OfSphere) + + +class Bnd_SphereUBTreeSelector : public Extrema_UBTreeOfSphere::Selector +{ + public: + + Bnd_SphereUBTreeSelector (const Handle(Bnd_HArray1OfSphere)& theSphereArray, +Bnd_Sphere& theSol) + : myXYZ(0,0,0), + mySphereArray(theSphereArray), + mySol(theSol) + { + //myXYZ = gp_Pnt(0, 0, 0); + } + + void DefineCheckPoint( const gp_Pnt& theXYZ ) + { myXYZ = theXYZ; } + + Bnd_Sphere& Sphere() const + { return mySol; } + + virtual Standard_Boolean Reject( const Bnd_Sphere &theBnd ) const = 0; + + virtual Standard_Boolean Accept(const Standard_Integer& theObj) = 0; + + protected: + gp_Pnt myXYZ; + const Handle(Bnd_HArray1OfSphere)& mySphereArray; + Bnd_Sphere& mySol; + +}; + +class Bnd_SphereUBTreeSelectorMin : public Bnd_SphereUBTreeSelector +{ +public: + Bnd_SphereUBTreeSelectorMin (const Handle(Bnd_HArray1OfSphere)& theSphereArray, + Bnd_Sphere& theSol) + : Bnd_SphereUBTreeSelector(theSphereArray, theSol), + myMinDist(RealLast()) + {} + + void SetMinDist( const Standard_Real theMinDist ) + { myMinDist = theMinDist; } + + Standard_Real MinDist() const + { return myMinDist; } + + Standard_Boolean Reject( const Bnd_Sphere &theBnd ) const + { + Bnd_SphereUBTreeSelectorMin* me = + const_cast(this); + // myMinDist is decreased each time a nearer object is found + return theBnd.IsOut( myXYZ.XYZ(), me->myMinDist ); + } + + Standard_Boolean Accept(const Standard_Integer&); + +private: + Standard_Real myMinDist; +}; + +Standard_Boolean Bnd_SphereUBTreeSelectorMin::Accept(const Standard_Integer& theInd) +{ + const Bnd_Sphere& aSph = mySphereArray->Value(theInd); + Standard_Real aCurDist; + + if ( (aCurDist = aSph.SquareDistance(myXYZ.XYZ())) < mySol.SquareDistance(myXYZ.XYZ()) ) + { + mySol = aSph; + if ( aCurDist < myMinDist ) + myMinDist = aCurDist; + + return Standard_True; + } + + return Standard_False; +} + +class Bnd_SphereUBTreeSelectorMax : public Bnd_SphereUBTreeSelector +{ +public: + Bnd_SphereUBTreeSelectorMax (const Handle(Bnd_HArray1OfSphere)& theSphereArray, + Bnd_Sphere& theSol) + : Bnd_SphereUBTreeSelector(theSphereArray, theSol), + myMaxDist(0) + {} + + void SetMaxDist( const Standard_Real theMaxDist ) + { myMaxDist = theMaxDist; } + + Standard_Real MaxDist() const + { return myMaxDist; } + + Standard_Boolean Reject( const Bnd_Sphere &theBnd ) const + { + Bnd_SphereUBTreeSelectorMax* me = + const_cast(this); + // myMaxDist is decreased each time a nearer object is found + return theBnd.IsOut( myXYZ.XYZ(), me->myMaxDist ); + } + + Standard_Boolean Accept(const Standard_Integer&); + +private: + Standard_Real myMaxDist; +}; + +Standard_Boolean Bnd_SphereUBTreeSelectorMax::Accept(const Standard_Integer& theInd) +{ + const Bnd_Sphere& aSph = mySphereArray->Value(theInd); + Standard_Real aCurDist; + + if ( (aCurDist = aSph.SquareDistance(myXYZ.XYZ())) > mySol.SquareDistance(myXYZ.XYZ()) ) + { + mySol = aSph; + if ( aCurDist > myMaxDist ) + myMaxDist = aCurDist; + + return Standard_True; + } + + return Standard_False; +} //============================================================================= /*----------------------------------------------------------------------------- -Fonction: - Recherche de toutes les distances extremales entre le point P et la surface - S a partir d'un echantillonnage (NbU,NbV). +Function: + Find all extremum distances between point P and surface + S using sampling (NbU,NbV). -Methode: - L'algorithme part de l'hypothese que l'echantillonnage est suffisamment fin +Method: + The algorithm bases on the hypothesis that sampling is precise enough pour que, s'il existe N distances extremales entre le point et la surface, alors il existe aussi N extrema entre le point et la grille. - Ainsi, l'algorithme consiste a partir des extrema de la grille pour trouver - les extrema de la surface. - Les extrema sont calcules par l'algorithme math_FunctionSetRoot avec les - arguments suivants: - - F: Extrema_FuncExtPS cree a partir de P et S, - - UV: math_Vector dont les composantes sont les parametres de l'extremum sur - la grille, - - Tol: Min(TolU,TolV), (Prov.:math_FunctionSetRoot n'autorise pas un vecteur) - - UVinf: math_Vector dont les composantes sont les bornes inferieures de u et - v, - - UVsup: math_Vector dont les composantes sont les bornes superieures de u et - v. + So, the algorithm consists in starting from extrema of the grid to find the + extrema of the surface. + The extrema are calculated by the algorithm math_FunctionSetRoot with the + following arguments: + - F: Extrema_FuncExtPS created from P and S, + - UV: math_Vector the components which of are parameters of the extremum on the + grid, + - Tol: Min(TolU,TolV), (Prov.:math_FunctionSetRoot does not autorize a vector) + - UVinf: math_Vector the components which of are lower limits of u and v, + - UVsup: math_Vector the components which of are upper limits of u and v. -Traitement: - a- Constitution du tableau des distances (TbDist(0,NbU+1,0,NbV+1)): - Le tableau est volontairement etendu; les lignes 0 et NbU+1 et les - colonnes 0 et NbV+1 seront initialisees a RealFirst() ou RealLast() - pour simplifier les tests effectues dans l'etape b - (on n'a pas besoin de tester si le point est sur un bord de la grille). - b- Calcul des extrema: - On recherche d'abord les minima et ensuite les maxima. Ces 2 traitements - se passent de facon similaire: - b.a- Initialisations: - - des 'bords' du tableau TbDist (a RealLast() dans le cas des minima - et a RealLast() dans le cas des maxima), - - du tableau TbSel(0,NbU+1,0,NbV+1) de selection des points pour un - calcul d'extremum local (a 0). Lorsqu'un point sera selectionne, - il ne sera plus selectionnable, ainsi que ses points adjacents - (8 au maximum). Les adresses correspondantes seront mises a 1. - b.b- Calcul des minima (ou maxima): - On boucle sur toutes les distances du tableau TbDist: - - recherche d'un minimum (ou maximum) sur la grille, - - calcul de l'extremum sur la surface, - - mise a jour du tableau TbSel. +Processing: + a- Creation of the table of distances (TbDist(0,NbU+1,0,NbV+1)): + The table is expanded at will; lines 0 and NbU+1 and + columns 0 and NbV+1 are initialized at RealFirst() or RealLast() + to simplify the tests carried out at stage b + (there is no need to test if the point is on border of the grid). + b- Calculation of extrema: + First the minimums and then the maximums are found. These 2 procedured + pass in a similar way: + b.a- Initialization: + - 'borders' of table TbDist (RealLast() in case of minimums + and RealLast() in case of maximums), + - table TbSel(0,NbU+1,0,NbV+1) of selection of points for + calculation of local extremum (0). When a point will selected, + it will not be selectable, as well as the ajacent points + (8 at least). The corresponding addresses will be set to 1. + b.b- Calculation of minimums (or maximums): + All distances from table TbDist are parsed in a loop: + - search minimum (or maximum) in the grid, + - calculate extremum on the surface, + - update table TbSel. -----------------------------------------------------------------------------*/ static Standard_Boolean IsoIsDeg (const Adaptor3d_Surface& S, @@ -117,6 +244,8 @@ Extrema_GenExtPS::Extrema_GenExtPS() { myDone = Standard_False; myInit = Standard_False; + myFlag = Extrema_ExtFlag_MINMAX; + myAlgo = Extrema_ExtAlgo_Grad; } @@ -125,8 +254,10 @@ Extrema_GenExtPS::Extrema_GenExtPS (const gp_Pnt& P, const Standard_Integer NbU, const Standard_Integer NbV, const Standard_Real TolU, - const Standard_Real TolV) -: myF (P,S) + const Standard_Real TolV, + const Extrema_ExtFlag F, + const Extrema_ExtAlgo A) + : myF (P,S), myFlag(F), myAlgo(A) { Initialize(S, NbU, NbV, TolU, TolV); Perform(P); @@ -141,8 +272,10 @@ Extrema_GenExtPS::Extrema_GenExtPS (const gp_Pnt& P, const Standard_Real Vmin, const Standard_Real Vsup, const Standard_Real TolU, - const Standard_Real TolV) -: myF (P,S) + const Standard_Real TolV, + const Extrema_ExtFlag F, + const Extrema_ExtAlgo A) + : myF (P,S), myFlag(F), myAlgo(A) { Initialize(S, NbU, NbV, Umin, Usup, Vmin, Vsup, TolU, TolV); Perform(P); @@ -189,15 +322,12 @@ void Extrema_GenExtPS::Initialize(const Adaptor3d_Surface& S, myF.Initialize(S); - mypoints = new TColgp_HArray2OfPnt(0,myusample+1,0,myvsample+1); - -/* -a- Constitution du tableau des distances (TbDist(0,myusample+1,0,myvsample+1)): - --------------------------------------------------------------- -*/ - -// Parametrage de l echantillon + mySphereUBTree.Clear(); + if(myAlgo == Extrema_ExtAlgo_Grad) + { + //If flag was changed and extrema not reinitialized Extrema would fail + mypoints = new TColgp_HArray2OfPnt(0,myusample+1,0,myvsample+1); Standard_Real PasU = myusup - myumin; Standard_Real PasV = myvsup - myvmin; Standard_Real U0 = PasU / myusample / 100.; @@ -218,24 +348,168 @@ a- Constitution du tableau des distances (TbDist(0,myusample+1,0,myvsample+1)): mypoints->SetValue(NoU,NoV,P1); } } -} - - - -void Extrema_GenExtPS::Perform(const gp_Pnt& P) -{ - myDone = Standard_False; - myF.SetPoint(P); + } + //mypoints = new TColgp_HArray2OfPnt(0,myusample+1,0,myvsample+1); /* -b- Calcul des minima: - ----------------- - b.a) Initialisations: +a- Constitution du tableau des distances (TbDist(0,myusample+1,0,myvsample+1)): + --------------------------------------------------------------- */ // Parametrage de l echantillon + +} + +void Extrema_GenExtPS::BuildTree() +{ + if(mySphereUBTree.IsEmpty()) + { + Standard_Real PasU = myusup - myumin; + Standard_Real PasV = myvsup - myvmin; + Standard_Real U0 = PasU / myusample / 100.; + Standard_Real V0 = PasV / myvsample / 100.; + gp_Pnt P1; + PasU = (PasU - U0) / (myusample - 1); + PasV = (PasV - V0) / (myvsample - 1); + U0 = U0/2. + myumin; + V0 = V0/2. + myvmin; + + // Calcul des distances + + Standard_Integer NoU, NoV; + //mySphereUBTree.Clear(); + Extrema_UBTreeFillerOfSphere aFiller(mySphereUBTree.ChangeTree()); + Standard_Integer i = myusample * myvsample; + Standard_Real U, V; + /*for ( NoU = 1; NoU <= myusample; NoU++) { + for ( NoV = 1; NoV <= myvsample; NoV++) { + i++; + } + }*/ + mySphereArray = new Bnd_HArray1OfSphere(0, i); + i = 0; + for ( NoU = 1, U = U0; NoU <= myusample; NoU++, U += PasU) { + for ( NoV = 1, V = V0; NoV <= myvsample; NoV++, V += PasV) { + P1 = myS->Value(U, V); + //mypoints->SetValue(NoU, NoV, P1); + Bnd_Sphere aSph(P1.XYZ(), 0/*mytolu < mytolv ? mytolu : mytolv*/, NoU, NoV); + aFiller.Add(i, aSph); + mySphereArray->SetValue( i, aSph ); + i++; + } + } + aFiller.Fill(); + } +} + +void Extrema_GenExtPS::FindSolution(const gp_Pnt& P, const math_Vector& UV, const Standard_Real PasU, const Standard_Real PasV, const Extrema_ExtFlag f) +{ + math_Vector Tol(1,2); + Tol(1) = mytolu; + Tol(2) = mytolv; + + math_Vector UVinf(1,2), UVsup(1,2); + UVinf(1) = myumin; + UVinf(2) = myvmin; + UVsup(1) = myusup; + UVsup(2) = myvsup; + + math_Vector errors(1,2); + math_Vector root(1, 2); + Standard_Real eps = 1.e-9; + Standard_Integer nbsubsample = 11; + + Standard_Integer aNbMaxIter = 100; + + if (myF.HasDegIso()) + aNbMaxIter = 150; + + math_FunctionSetRoot S (myF,UV,Tol,UVinf,UVsup, aNbMaxIter); + if(S.IsDone()) { + root = S.Root(); + myF.Value(root, errors); + if(f == Extrema_ExtFlag_MIN) + { + if(Abs(errors(1)) > eps || Abs(errors(2)) > eps) { + //try to improve solution on subgrid of sample points + gp_Pnt PSol = myS->Value(root(1), root(2)); + Standard_Real DistSol = P.SquareDistance(PSol); + + Standard_Real u1 = Max(UV(1) - PasU, myumin), u2 = Min(UV(1) + PasU, myusup); + Standard_Real v1 = Max(UV(2) - PasV, myvmin), v2 = Min(UV(2) + PasV, myvsup); + + if(u2 - u1 < 2.*PasU) { + if(Abs(u1 - myumin) < 1.e-9) { + u2 = u1 + 2.*PasU; + u2 = Min(u2, myusup); + } + if(Abs(u2 - myusup) < 1.e-9) { + u1 = u2 - 2.*PasU; + u1 = Max(u1, myumin); + } + } + + if(v2 - v1 < 2.*PasV) { + if(Abs(v1 - myvmin) < 1.e-9) { + v2 = v1 + 2.*PasV; + v2 = Min(v2, myvsup); + } + if(Abs(v2 - myvsup) < 1.e-9) { + v1 = v2 - 2.*PasV; + v1 = Max(v1, myvmin); + } + } + + Standard_Real du = (u2 - u1)/(nbsubsample-1); + Standard_Real dv = (v2 - v1)/(nbsubsample-1); + Standard_Real u, v; + Standard_Real dist; + + Standard_Boolean NewSolution = Standard_False; + Standard_Integer Nu, Nv; + for (Nu = 1, u = u1; Nu < nbsubsample; Nu++, u += du) { + for (Nv = 1, v = v1; Nv < nbsubsample; Nv++, v += dv) { + gp_Pnt Puv = myS->Value(u, v); + dist = P.SquareDistance(Puv); + + if(dist < DistSol) { + UV(1) = u; + UV(2) = v; + NewSolution = Standard_True; + DistSol = dist; + } + } + } + + if(NewSolution) { + //try to precise + math_FunctionSetRoot S (myF,UV,Tol,UVinf,UVsup, aNbMaxIter); + } + + } + } + } + myDone = Standard_True; +} + +void Extrema_GenExtPS::SetFlag(const Extrema_ExtFlag F) +{ + myFlag = F; +} + +void Extrema_GenExtPS::SetAlgo(const Extrema_ExtAlgo A) +{ + myAlgo = A; +} + +void Extrema_GenExtPS::Perform(const gp_Pnt& P) +{ + //BuildTree(); + myDone = Standard_False; + myF.SetPoint(P); + Standard_Real PasU = myusup - myumin; Standard_Real PasV = myvsup - myvmin; Standard_Real U, U0 = PasU / myusample / 100.; @@ -245,211 +519,123 @@ b- Calcul des minima: U0 = U0/2.+myumin; V0 = V0/2.+myvmin; -// - generales - math_Vector Tol(1, 2); - Tol(1) = mytolu; - Tol(2) = mytolv; - math_Vector UV(1,2), UVinf(1,2), UVsup(1,2); - UVinf(1) = myumin; - UVinf(2) = myvmin; - UVsup(1) = myusup; - UVsup(2) = myvsup; + //math_Vector Tol(1, 2); + math_Vector UV(1,2); -// - des 'bords' du tableau mytbdist - Standard_Integer NoU,NoV; + if(myAlgo == Extrema_ExtAlgo_Grad) + { + Standard_Integer NoU,NoV; - TColStd_Array2OfReal TheDist(0, myusample+1, 0, myvsample+1); - for ( NoU = 1, U = U0; NoU <= myusample; NoU++, U += PasU) { - for ( NoV = 1, V = V0; NoV <= myvsample; NoV++, V += PasV) { - TheDist(NoU, NoV) = P.SquareDistance(mypoints->Value(NoU, NoV)); + TColStd_Array2OfReal TheDist(0, myusample+1, 0, myvsample+1); + for ( NoU = 1, U = U0; NoU <= myusample; NoU++, U += PasU) { + for ( NoV = 1, V = V0; NoV <= myvsample; NoV++, V += PasV) { + TheDist(NoU, NoV) = P.SquareDistance(mypoints->Value(NoU, NoV)); + } + } + + TColStd_Array2OfInteger TbSel(0,myusample+1,0,myvsample+1); + TbSel.Init(0); + + Standard_Real Dist; + + if(myFlag == Extrema_ExtFlag_MIN || myFlag == Extrema_ExtFlag_MINMAX) + { + for (NoV = 0; NoV <= myvsample+1; NoV++) { + TheDist(0,NoV) = RealLast(); + TheDist(myusample+1,NoV) = RealLast(); + } + for (NoU = 1; NoU <= myusample; NoU++) { + TheDist(NoU,0) = RealLast(); + TheDist(NoU,myvsample+1) = RealLast(); + } + for (NoU = 1; NoU <= myusample; NoU++) { + for (NoV = 1; NoV <= myvsample; NoV++) { + if (TbSel(NoU,NoV) == 0) { + Dist = TheDist(NoU,NoV); + if ((TheDist(NoU-1,NoV-1) >= Dist) && + (TheDist(NoU-1,NoV ) >= Dist) && + (TheDist(NoU-1,NoV+1) >= Dist) && + (TheDist(NoU ,NoV-1) >= Dist) && + (TheDist(NoU ,NoV+1) >= Dist) && + (TheDist(NoU+1,NoV-1) >= Dist) && + (TheDist(NoU+1,NoV ) >= Dist) && + (TheDist(NoU+1,NoV+1) >= Dist)) { + //Create array of UV vectors to calculate min + UV(1) = U0 + (NoU - 1) * PasU; + UV(2) = V0 + (NoV - 1) * PasV; + FindSolution(P, UV, PasU, PasV, Extrema_ExtFlag_MIN); + } + } + } + } + } + + if(myFlag == Extrema_ExtFlag_MAX || myFlag == Extrema_ExtFlag_MINMAX) + { + for (NoV = 0; NoV <= myvsample+1; NoV++) { + TheDist(0,NoV) = RealFirst(); + TheDist(myusample+1,NoV) = RealFirst(); + } + for (NoU = 1; NoU <= myusample; NoU++) { + TheDist(NoU,0) = RealFirst(); + TheDist(NoU,myvsample+1) = RealFirst(); + } + for (NoU = 1; NoU <= myusample; NoU++) { + for (NoV = 1; NoV <= myvsample; NoV++) { + if (TbSel(NoU,NoV) == 0) { + Dist = TheDist(NoU,NoV); + if ((TheDist(NoU-1,NoV-1) <= Dist) && + (TheDist(NoU-1,NoV ) <= Dist) && + (TheDist(NoU-1,NoV+1) <= Dist) && + (TheDist(NoU ,NoV-1) <= Dist) && + (TheDist(NoU ,NoV+1) <= Dist) && + (TheDist(NoU+1,NoV-1) <= Dist) && + (TheDist(NoU+1,NoV ) <= Dist) && + (TheDist(NoU+1,NoV+1) <= Dist)) { + //Create array of UV vectors to calculate max + UV(1) = U0 + (NoU - 1) * PasU; + UV(2) = V0 + (NoV - 1) * PasV; + FindSolution(P, UV, PasU, PasV, Extrema_ExtFlag_MAX); + } + } + } + } } } - - for (NoV = 0; NoV <= myvsample+1; NoV++) { - TheDist(0,NoV) = RealLast(); - TheDist(myusample+1,NoV) = RealLast(); - } - for (NoU = 1; NoU <= myusample; NoU++) { - TheDist(NoU,0) = RealLast(); - TheDist(NoU,myvsample+1) = RealLast(); - } + else + { + BuildTree(); + if(myFlag == Extrema_ExtFlag_MIN || myFlag == Extrema_ExtFlag_MINMAX) + { + Bnd_Sphere aSol = mySphereArray->Value(0); + Bnd_SphereUBTreeSelectorMin aSelector(mySphereArray, aSol); + //aSelector.SetMaxDist( RealLast() ); + aSelector.DefineCheckPoint( P ); + Standard_Integer aNbSel = mySphereUBTree.Select( aSelector ); + //TODO: check if no solution in binary tree + Bnd_Sphere& aSph = aSelector.Sphere(); -// - du tableau TbSel(0,myusample+1,0,myvsample+1) de selection des points - TColStd_Array2OfInteger TbSel(0,myusample+1,0,myvsample+1); - TbSel.Init(0); -/* - b.b) Calcul des minima: -*/ -// - recherche d un minimum sur la grille - math_Vector errors(1,2); - math_Vector root(1, 2); - Standard_Real eps = 1.e-9; - Standard_Integer nbsubsample = 11; - Standard_Integer Nu, Nv; - Standard_Real Dist; - for (NoU = 1; NoU <= myusample; NoU++) { - for (NoV = 1; NoV <= myvsample; NoV++) { - if (TbSel(NoU,NoV) == 0) { - Dist = TheDist(NoU,NoV); - if ((TheDist(NoU-1,NoV-1) >= Dist) && - (TheDist(NoU-1,NoV ) >= Dist) && - (TheDist(NoU-1,NoV+1) >= Dist) && - (TheDist(NoU ,NoV-1) >= Dist) && - (TheDist(NoU ,NoV+1) >= Dist) && - (TheDist(NoU+1,NoV-1) >= Dist) && - (TheDist(NoU+1,NoV ) >= Dist) && - (TheDist(NoU+1,NoV+1) >= Dist)) { + UV(1) = U0 + (aSph.U() - 1) * PasU; + UV(2) = V0 + (aSph.V() - 1) * PasV; -// - calcul de l extremum sur la surface: - UV(1) = U0 + (NoU - 1) * PasU; - UV(2) = V0 + (NoV - 1) * PasV; -// Modified by skv - Thu Sep 30 15:21:07 2004 OCC593 Begin -// math_FunctionSetRoot S (myF,UV,Tol,UVinf,UVsup); - // Default value for math_FunctionSetRoot. - Standard_Integer aNbMaxIter = 100; + FindSolution(P, UV, PasU, PasV, Extrema_ExtFlag_MIN); + } + if(myFlag == Extrema_ExtFlag_MAX || myFlag == Extrema_ExtFlag_MINMAX) + { + Bnd_Sphere aSol = mySphereArray->Value(0); + Bnd_SphereUBTreeSelectorMax aSelector(mySphereArray, aSol); + //aSelector.SetMaxDist( RealLast() ); + aSelector.DefineCheckPoint( P ); + Standard_Integer aNbSel = mySphereUBTree.Select( aSelector ); + //TODO: check if no solution in binary tree + Bnd_Sphere& aSph = aSelector.Sphere(); - if (myF.HasDegIso()) - aNbMaxIter = 150; + UV(1) = U0 + (aSph.U() - 1) * PasU; + UV(2) = V0 + (aSph.V() - 1) * PasV; - math_FunctionSetRoot S (myF,UV,Tol,UVinf,UVsup, aNbMaxIter); - if(S.IsDone()) { - root = S.Root(); - myF.Value(root, errors); - if(Abs(errors(1)) > eps || Abs(errors(2)) > eps) { - //try to improve solution on subgrid of sample points - gp_Pnt PSol = myS->Value(root(1), root(2)); - Standard_Real DistSol = P.SquareDistance(PSol); - - Standard_Real u1 = Max(UV(1) - PasU, myumin), u2 = Min(UV(1) + PasU, myusup); - Standard_Real v1 = Max(UV(2) - PasV, myvmin), v2 = Min(UV(2) + PasV, myvsup); - - if(u2 - u1 < 2.*PasU) { - if(Abs(u1 - myumin) < 1.e-9) { - u2 = u1 + 2.*PasU; - u2 = Min(u2, myusup); - } - if(Abs(u2 - myusup) < 1.e-9) { - u1 = u2 - 2.*PasU; - u1 = Max(u1, myumin); - } - } - - if(v2 - v1 < 2.*PasV) { - if(Abs(v1 - myvmin) < 1.e-9) { - v2 = v1 + 2.*PasV; - v2 = Min(v2, myvsup); - } - if(Abs(v2 - myvsup) < 1.e-9) { - v1 = v2 - 2.*PasV; - v1 = Max(v1, myvmin); - } - } - - Standard_Real du = (u2 - u1)/(nbsubsample-1); - Standard_Real dv = (v2 - v1)/(nbsubsample-1); - Standard_Real u, v; - Standard_Real dist; - - Standard_Boolean NewSolution = Standard_False; - for (Nu = 1, u = u1; Nu < nbsubsample; Nu++, u += du) { - for (Nv = 1, v = v1; Nv < nbsubsample; Nv++, v += dv) { - gp_Pnt Puv = myS->Value(u, v); - dist = P.SquareDistance(Puv); - - if(dist < DistSol) { - UV(1) = u; - UV(2) = v; - NewSolution = Standard_True; - DistSol = dist; - } - } - } - if(NewSolution) { - //try to precise - math_FunctionSetRoot S (myF,UV,Tol,UVinf,UVsup, aNbMaxIter); - } - - } - } -// Modified by skv - Thu Sep 30 15:21:07 2004 OCC593 End - -// - mise a jour du tableau TbSel - for (Nu = NoU-1; Nu <= NoU+1; Nu++) { - for (Nv = NoV-1; Nv <= NoV+1; Nv++) { - TbSel(Nu,Nv) = 1; - } - } - } - } // if (TbSel(NoU,NoV) - } // for (NoV = 1; ... - } // for (NoU = 1; ... -/* -c- Calcul des maxima: - ----------------- - c.a) Initialisations: -*/ -// - des 'bords' du tableau mytbdist - for (NoV = 0; NoV <= myvsample+1; NoV++) { - TheDist(0,NoV) = RealFirst(); - TheDist(myusample+1,NoV) = RealFirst(); - } - for (NoU = 1; NoU <= myusample; NoU++) { - TheDist(NoU,0) = RealFirst(); - TheDist(NoU,myvsample+1) = RealFirst(); - } - -// - du tableau TbSel(0,myusample+1,0,myvsample+1) de selection des points - for (NoU = 0; NoU <= myusample+1; NoU++) { - for (NoV = 0; NoV <= myvsample+1; NoV++) { - TbSel(NoU,NoV) = 0; + FindSolution(P, UV, PasU, PasV, Extrema_ExtFlag_MAX); } } -/* - c.b) Calcul des maxima: -*/ -// - recherche d un maximum sur la grille - for (NoU = 1; NoU <= myusample; NoU++) { - for (NoV = 1; NoV <= myvsample; NoV++) { - if (TbSel(NoU,NoV) == 0) { - Dist = TheDist(NoU,NoV); - if ((TheDist(NoU-1,NoV-1) <= Dist) && - (TheDist(NoU-1,NoV ) <= Dist) && - (TheDist(NoU-1,NoV+1) <= Dist) && - (TheDist(NoU ,NoV-1) <= Dist) && - (TheDist(NoU ,NoV+1) <= Dist) && - (TheDist(NoU+1,NoV-1) <= Dist) && - (TheDist(NoU+1,NoV ) <= Dist) && - (TheDist(NoU+1,NoV+1) <= Dist)) { - -// - calcul de l extremum sur la surface: - UV(1) = U0 + (NoU - 1) * PasU; - UV(2) = V0 + (NoV - 1) * PasV; -// Modified by skv - Thu Sep 30 15:21:07 2004 OCC593 Begin -// math_FunctionSetRoot S (myF,UV,Tol,UVinf,UVsup); - // Default value for math_FunctionSetRoot. - Standard_Integer aNbMaxIter = 100; - - if (myF.HasDegIso()) - aNbMaxIter = 150; - - math_FunctionSetRoot S (myF,UV,Tol,UVinf,UVsup, aNbMaxIter); - if(S.IsDone()) { - root = S.Root(); - myF.Value(root, errors); - } -// Modified by skv - Thu Sep 30 15:21:07 2004 OCC593 End - -// - mise a jour du tableau TbSel - for (Nu = NoU-1; Nu <= NoU+1; Nu++) { - for (Nv = NoV-1; Nv <= NoV+1; Nv++) { - TbSel(Nu,Nv) = 1; - } - } - } - } // if (TbSel(NoU,NoV)) - } // for (NoV = 1; ...) - } // for (NoU = 1; ...) - myDone = Standard_True; } //============================================================================= @@ -476,4 +662,3 @@ Extrema_POnSurf Extrema_GenExtPS::Point (const Standard_Integer N) const return myF.Point(N); } //============================================================================= - diff --git a/src/Extrema/Extrema_HUBTreeOfSphere.cxx b/src/Extrema/Extrema_HUBTreeOfSphere.cxx new file mode 100644 index 0000000000..7efecee57f --- /dev/null +++ b/src/Extrema/Extrema_HUBTreeOfSphere.cxx @@ -0,0 +1,8 @@ +// File: BestFitBnd_HUBTreeOfSphere.cxx +// Created: Thu Mar 17 14:30:42 2005 +// Author: OPEN CASCADE Support +// Copyright: OPEN CASCADE SA 2005 + +#include + +IMPLEMENT_HUBTREE(Extrema_HUBTreeOfSphere,MMgt_TShared) diff --git a/src/Extrema/Extrema_HUBTreeOfSphere.hxx b/src/Extrema/Extrema_HUBTreeOfSphere.hxx new file mode 100644 index 0000000000..3ac845c289 --- /dev/null +++ b/src/Extrema/Extrema_HUBTreeOfSphere.hxx @@ -0,0 +1,17 @@ +// File: BestFitBnd_HUBTreeOfSphere.hxx +// Created: Thu Mar 17 14:30:42 2005 +// Author: OPEN CASCADE Support +// Copyright: OPEN CASCADE SA 2005 + +#ifndef _Extrema_HUBTreeOfSphere_HeaderFile +#define _Extrema_HUBTreeOfSphere_HeaderFile + +#include +#include +#include + +typedef NCollection_UBTree Extrema_UBTreeOfSphere; +typedef NCollection_UBTreeFiller Extrema_UBTreeFillerOfSphere; +DEFINE_HUBTREE(Extrema_HUBTreeOfSphere, Standard_Integer, Bnd_Sphere, MMgt_TShared) + +#endif //_Extrema_HUBTreeOfSphere_HeaderFile diff --git a/src/Extrema/FILES b/src/Extrema/FILES new file mode 100644 index 0000000000..d9705ffca9 --- /dev/null +++ b/src/Extrema/FILES @@ -0,0 +1,2 @@ +Extrema_HUBTreeOfSphere.hxx +Extrema_HUBTreeOfSphere.cxx