Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-10-27 09:37:20

0001 // Created on: 2008-05-26
0002 // Created by: Ekaterina SMIRNOVA
0003 // Copyright (c) 2008-2014 OPEN CASCADE SAS
0004 //
0005 // This file is part of Open CASCADE Technology software library.
0006 //
0007 // This library is free software; you can redistribute it and/or modify it under
0008 // the terms of the GNU Lesser General Public License version 2.1 as published
0009 // by the Free Software Foundation, with special exception defined in the file
0010 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
0011 // distribution for complete text of the license and disclaimer of any warranty.
0012 //
0013 // Alternatively, this file may be used under the terms of Open CASCADE
0014 // commercial license or contractual agreement.
0015 
0016 #ifndef BRepMesh_CircleInspector_HeaderFile
0017 #define BRepMesh_CircleInspector_HeaderFile
0018 
0019 #include <IMeshData_Types.hxx>
0020 #include <BRepMesh_Circle.hxx>
0021 #include <gp_XY.hxx>
0022 #include <NCollection_CellFilter.hxx>
0023 
0024 //! Auxiliary class to find circles shot by the given point.
0025 class BRepMesh_CircleInspector
0026 {
0027 public:
0028   static constexpr int Dimension = 2;
0029 
0030   typedef gp_XY Point;
0031   typedef int   Target;
0032 
0033   static double Coord(int i, const Point& thePnt) { return thePnt.Coord(i + 1); }
0034 
0035   static Point Shift(const Point& thePnt, double theTol)
0036   {
0037     return Point(thePnt.X() + theTol, thePnt.Y() + theTol);
0038   }
0039 
0040   //! Constructor.
0041   //! @param theTolerance tolerance to be used for identification of shot circles.
0042   //! @param theReservedSize size to be reserved for vector of circles.
0043   //! @param theAllocator memory allocator to be used by internal collections.
0044   BRepMesh_CircleInspector(const double                                 theTolerance,
0045                            const int                                    theReservedSize,
0046                            const occ::handle<NCollection_IncAllocator>& theAllocator)
0047       : mySqTolerance(theTolerance * theTolerance),
0048         myResIndices(theAllocator),
0049         myCircles(theReservedSize, theAllocator)
0050   {
0051   }
0052 
0053   //! Adds the circle to vector of circles at the given position.
0054   //! @param theIndex position of circle in the vector.
0055   //! @param theCircle circle to be added.
0056   void Bind(const int theIndex, const BRepMesh_Circle& theCircle)
0057   {
0058     myCircles.SetValue(theIndex, theCircle);
0059   }
0060 
0061   //! Resutns vector of registered circles.
0062   const IMeshData::VectorOfCircle& Circles() const { return myCircles; }
0063 
0064   //! Returns circle with the given index.
0065   //! @param theIndex index of circle.
0066   //! @return circle with the given index.
0067   BRepMesh_Circle& Circle(const int theIndex) { return myCircles(theIndex); }
0068 
0069   //! Set reference point to be checked.
0070   //! @param thePoint bullet point.
0071   void SetPoint(const gp_XY& thePoint)
0072   {
0073     myResIndices.Clear();
0074     myPoint = thePoint;
0075   }
0076 
0077   //! Returns list of circles shot by the reference point.
0078   IMeshData::ListOfInteger& GetShotCircles() { return myResIndices; }
0079 
0080   //! Performs inspection of a circle with the given index.
0081   //! @param theTargetIndex index of a circle to be checked.
0082   //! @return status of the check.
0083   NCollection_CellFilter_Action Inspect(const int theTargetIndex)
0084   {
0085     BRepMesh_Circle& aCircle = myCircles(theTargetIndex);
0086     const double&    aRadius = aCircle.Radius();
0087     if (aRadius < 0.)
0088       return CellFilter_Purge;
0089 
0090     gp_XY& aLoc = const_cast<gp_XY&>(aCircle.Location());
0091 
0092     const double aDX = myPoint.ChangeCoord(1) - aLoc.ChangeCoord(1);
0093     const double aDY = myPoint.ChangeCoord(2) - aLoc.ChangeCoord(2);
0094 
0095     // This check is wrong. It is better to use
0096     //
0097     //   const double aR = aRadius + aToler;
0098     //   if ((aDX * aDX + aDY * aDY) <= aR * aR)
0099     //   {
0100     //     ...
0101     //   }
0102 
0103     // where aToler = sqrt(mySqTolerance). Taking into account the fact
0104     // that the input parameter of the class (see constructor) is linear
0105     //(not quadratic) tolerance there is no point in square root computation.
0106     // Simply, we do not need to compute square of the input tolerance and to
0107     // assign it to mySqTolerance. The input linear tolerance is needed to be used.
0108 
0109     // However, this change leads to hangs the test case "perf mesh bug27119".
0110     // So, this correction is better to be implemented in the future.
0111 
0112     if ((aDX * aDX + aDY * aDY) - (aRadius * aRadius) <= mySqTolerance)
0113       myResIndices.Append(theTargetIndex);
0114 
0115     return CellFilter_Keep;
0116   }
0117 
0118   //! Checks indices for equality.
0119   static bool IsEqual(const int theIndex, const int theTargetIndex)
0120   {
0121     return (theIndex == theTargetIndex);
0122   }
0123 
0124 private:
0125   double                    mySqTolerance;
0126   IMeshData::ListOfInteger  myResIndices;
0127   IMeshData::VectorOfCircle myCircles;
0128   gp_XY                     myPoint;
0129 };
0130 
0131 #endif