Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-09-17 09:19:50

0001 // Copyright (c) 1999-2014 OPEN CASCADE SAS
0002 //
0003 // This file is part of Open CASCADE Technology software library.
0004 //
0005 // This library is free software; you can redistribute it and/or modify it under
0006 // the terms of the GNU Lesser General Public License version 2.1 as published
0007 // by the Free Software Foundation, with special exception defined in the file
0008 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
0009 // distribution for complete text of the license and disclaimer of any warranty.
0010 //
0011 // Alternatively, this file may be used under the terms of Open CASCADE
0012 // commercial license or contractual agreement.
0013 
0014 #ifndef _BRepExtrema_DistShapeShape_HeaderFile
0015 #define _BRepExtrema_DistShapeShape_HeaderFile
0016 
0017 #include <Bnd_Box.hxx>
0018 #include <NCollection_Array1.hxx>
0019 #include <NCollection_Sequence.hxx>
0020 #include <BRepExtrema_SolutionElem.hxx>
0021 #include <BRepExtrema_SupportType.hxx>
0022 #include <Extrema_ExtAlgo.hxx>
0023 #include <Extrema_ExtFlag.hxx>
0024 #include <Message_ProgressRange.hxx>
0025 #include <TopoDS_Shape.hxx>
0026 #include <Standard_OStream.hxx>
0027 #include <Standard_DefineAlloc.hxx>
0028 #include <TopTools_ShapeMapHasher.hxx>
0029 #include <NCollection_IndexedMap.hxx>
0030 
0031 //! This class provides tools to compute minimum distance
0032 //! between two Shapes (Compound,CompSolid, Solid, Shell, Face, Wire, Edge, Vertex).
0033 class BRepExtrema_DistShapeShape
0034 {
0035 public:
0036   DEFINE_STANDARD_ALLOC
0037 
0038   //! create empty tool
0039   Standard_EXPORT BRepExtrema_DistShapeShape();
0040 
0041   //! create tool and computation of the minimum distance (value and pair of points)
0042   //! using default deflection in single thread mode.
0043   //! Default deflection value is Precision::Confusion().
0044   //! @param Shape1 - the first shape for distance computation
0045   //! @param Shape2 - the second shape for distance computation
0046   //! @param F and @param A are not used in computation and are obsolete.
0047   //! @param theRange - the progress indicator of algorithm
0048   Standard_EXPORT BRepExtrema_DistShapeShape(
0049     const TopoDS_Shape&          Shape1,
0050     const TopoDS_Shape&          Shape2,
0051     const Extrema_ExtFlag        F        = Extrema_ExtFlag_MINMAX,
0052     const Extrema_ExtAlgo        A        = Extrema_ExtAlgo_Grad,
0053     const Message_ProgressRange& theRange = Message_ProgressRange());
0054   //! create tool and computation of the minimum distance
0055   //! (value and pair of points) in single thread mode.
0056   //! Default deflection value is Precision::Confusion().
0057   //! @param Shape1 - the first shape for distance computation
0058   //! @param Shape2 - the second shape for distance computation
0059   //! @param theDeflection - the presition of distance computation
0060   //! @param F and @param A are not used in computation and are obsolete.
0061   //! @param theRange - the progress indicator of algorithm
0062   Standard_EXPORT BRepExtrema_DistShapeShape(
0063     const TopoDS_Shape&          Shape1,
0064     const TopoDS_Shape&          Shape2,
0065     const double                 theDeflection,
0066     const Extrema_ExtFlag        F        = Extrema_ExtFlag_MINMAX,
0067     const Extrema_ExtAlgo        A        = Extrema_ExtAlgo_Grad,
0068     const Message_ProgressRange& theRange = Message_ProgressRange());
0069 
0070   //! Sets deflection to computation of the minimum distance
0071   void SetDeflection(const double theDeflection) { myEps = theDeflection; }
0072 
0073   //! load first shape into extrema
0074   Standard_EXPORT void LoadS1(const TopoDS_Shape& Shape1);
0075 
0076   //! load second shape into extrema
0077   Standard_EXPORT void LoadS2(const TopoDS_Shape& Shape1);
0078 
0079   //! computation of the minimum distance (value and
0080   //!          couple of points). Parameter theDeflection is used
0081   //!          to specify a maximum deviation of extreme distances
0082   //!          from the minimum one.
0083   //!          Returns IsDone status.
0084   //! theRange - the progress indicator of algorithm
0085   Standard_EXPORT bool Perform(const Message_ProgressRange& theRange = Message_ProgressRange());
0086 
0087   //! True if the minimum distance is found.
0088   bool IsDone() const { return myIsDone; }
0089 
0090   //! Returns the number of solutions satisfying the minimum distance.
0091   int NbSolution() const { return mySolutionsShape1.Length(); }
0092 
0093   //! Returns the value of the minimum distance.
0094   Standard_EXPORT double Value() const;
0095 
0096   //! True if one of the shapes is a solid and the other shape
0097   //! is completely or partially inside the solid.
0098   bool InnerSolution() const { return myInnerSol; }
0099 
0100   //! Returns the Point corresponding to the <N>th solution on the first Shape
0101   const gp_Pnt& PointOnShape1(const int N) const { return mySolutionsShape1.Value(N).Point(); }
0102 
0103   //! Returns the Point corresponding to the <N>th solution on the second Shape
0104   const gp_Pnt& PointOnShape2(const int N) const { return mySolutionsShape2.Value(N).Point(); }
0105 
0106   //! gives the type of the support where the Nth solution on the first shape is situated:
0107   //!   IsVertex => the Nth solution on the first shape is a Vertex
0108   //!   IsOnEdge => the Nth soluion on the first shape is on a Edge
0109   //!   IsInFace => the Nth solution on the first shape is inside a face
0110   //! the corresponding support is obtained by the method SupportOnShape1
0111   BRepExtrema_SupportType SupportTypeShape1(const int N) const
0112   {
0113     return mySolutionsShape1.Value(N).SupportKind();
0114   }
0115 
0116   //! gives the type of the support where the Nth solution on the second shape is situated:
0117   //!   IsVertex => the Nth solution on the second shape is a Vertex
0118   //!   IsOnEdge => the Nth soluion on the secondt shape is on a Edge
0119   //!   IsInFace => the Nth solution on the second shape is inside a face
0120   //! the corresponding support is obtained by the method SupportOnShape2
0121   BRepExtrema_SupportType SupportTypeShape2(const int N) const
0122   {
0123     return mySolutionsShape2.Value(N).SupportKind();
0124   }
0125 
0126   //! gives the support where the Nth solution on the first shape is situated.
0127   //! This support can be a Vertex, an Edge or a Face.
0128   Standard_EXPORT TopoDS_Shape SupportOnShape1(const int N) const;
0129 
0130   //! gives the support where the Nth solution on the second shape is situated.
0131   //! This support can be a Vertex, an Edge or a Face.
0132   Standard_EXPORT TopoDS_Shape SupportOnShape2(const int N) const;
0133 
0134   //! gives the corresponding parameter t if the Nth solution
0135   //! is situated on an Edge of the first shape
0136   Standard_EXPORT void ParOnEdgeS1(const int N, double& t) const;
0137 
0138   //! gives the corresponding parameter t if the Nth solution
0139   //! is situated on an Edge of the first shape
0140   Standard_EXPORT void ParOnEdgeS2(const int N, double& t) const;
0141 
0142   //! gives the corresponding parameters (U,V) if the Nth solution
0143   //! is situated on an face of the first shape
0144   Standard_EXPORT void ParOnFaceS1(const int N, double& u, double& v) const;
0145 
0146   //! gives the corresponding parameters (U,V) if the Nth solution
0147   //! is situated on an Face of the second shape
0148   Standard_EXPORT void ParOnFaceS2(const int N, double& u, double& v) const;
0149 
0150   //! Prints on the stream o information on the current state of the object.
0151   Standard_EXPORT void Dump(Standard_OStream& o) const;
0152 
0153   //! Sets unused parameter
0154   //! Obsolete
0155   void SetFlag(const Extrema_ExtFlag F) { myFlag = F; }
0156 
0157   //! Sets unused parameter
0158   //! Obsolete
0159   void SetAlgo(const Extrema_ExtAlgo A) { myAlgo = A; }
0160 
0161   //! If isMultiThread == true then computation will be performed in parallel.
0162   void SetMultiThread(bool theIsMultiThread) { myIsMultiThread = theIsMultiThread; }
0163 
0164   //! Returns true then computation will be performed in parallel
0165   //! Default value is false
0166   bool IsMultiThread() const { return myIsMultiThread; }
0167 
0168 private:
0169   //! computes the minimum distance between two maps of shapes (Face,Edge,Vertex)
0170   bool DistanceMapMap(const NCollection_IndexedMap<TopoDS_Shape, TopTools_ShapeMapHasher>& Map1,
0171                       const NCollection_IndexedMap<TopoDS_Shape, TopTools_ShapeMapHasher>& Map2,
0172                       const NCollection_Array1<Bnd_Box>&                                   LBox1,
0173                       const NCollection_Array1<Bnd_Box>&                                   LBox2,
0174                       const Message_ProgressRange& theRange);
0175 
0176   //! computes the minimum distance between two maps of vertices
0177   bool DistanceVertVert(
0178     const NCollection_IndexedMap<TopoDS_Shape, TopTools_ShapeMapHasher>& theMap1,
0179     const NCollection_IndexedMap<TopoDS_Shape, TopTools_ShapeMapHasher>& theMap2,
0180     const Message_ProgressRange&                                         theRange);
0181 
0182   bool SolidTreatment(const TopoDS_Shape&                                                  theShape,
0183                       const NCollection_IndexedMap<TopoDS_Shape, TopTools_ShapeMapHasher>& theMap,
0184                       const Message_ProgressRange& theRange);
0185 
0186 private:
0187   double                                                        myDistRef;
0188   bool                                                          myIsDone;
0189   NCollection_Sequence<BRepExtrema_SolutionElem>                mySolutionsShape1;
0190   NCollection_Sequence<BRepExtrema_SolutionElem>                mySolutionsShape2;
0191   bool                                                          myInnerSol;
0192   double                                                        myEps;
0193   TopoDS_Shape                                                  myShape1;
0194   TopoDS_Shape                                                  myShape2;
0195   NCollection_IndexedMap<TopoDS_Shape, TopTools_ShapeMapHasher> myMapV1;
0196   NCollection_IndexedMap<TopoDS_Shape, TopTools_ShapeMapHasher> myMapV2;
0197   NCollection_IndexedMap<TopoDS_Shape, TopTools_ShapeMapHasher> myMapE1;
0198   NCollection_IndexedMap<TopoDS_Shape, TopTools_ShapeMapHasher> myMapE2;
0199   NCollection_IndexedMap<TopoDS_Shape, TopTools_ShapeMapHasher> myMapF1;
0200   NCollection_IndexedMap<TopoDS_Shape, TopTools_ShapeMapHasher> myMapF2;
0201   bool                                                          myIsInitS1;
0202   bool                                                          myIsInitS2;
0203   Extrema_ExtFlag                                               myFlag;
0204   Extrema_ExtAlgo                                               myAlgo;
0205   NCollection_Array1<Bnd_Box>                                   myBV1;
0206   NCollection_Array1<Bnd_Box>                                   myBV2;
0207   NCollection_Array1<Bnd_Box>                                   myBE1;
0208   NCollection_Array1<Bnd_Box>                                   myBE2;
0209   NCollection_Array1<Bnd_Box>                                   myBF1;
0210   NCollection_Array1<Bnd_Box>                                   myBF2;
0211   bool                                                          myIsMultiThread;
0212 };
0213 
0214 #endif