Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-07-29 09:14:41

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 : public NCollection_CellFilter_InspectorXY
0026 {
0027 public:
0028   typedef Standard_Integer Target;
0029 
0030   //! Constructor.
0031   //! @param theTolerance tolerance to be used for identification of shot circles.
0032   //! @param theReservedSize size to be reserved for vector of circles.
0033   //! @param theAllocator memory allocator to be used by internal collections.
0034   BRepMesh_CircleInspector(const Standard_Real                     theTolerance,
0035                            const Standard_Integer                  theReservedSize,
0036                            const Handle(NCollection_IncAllocator)& theAllocator)
0037       : mySqTolerance(theTolerance * theTolerance),
0038         myResIndices(theAllocator),
0039         myCircles(theReservedSize, theAllocator)
0040   {
0041   }
0042 
0043   //! Adds the circle to vector of circles at the given position.
0044   //! @param theIndex position of circle in the vector.
0045   //! @param theCircle circle to be added.
0046   void Bind(const Standard_Integer theIndex, const BRepMesh_Circle& theCircle)
0047   {
0048     myCircles.SetValue(theIndex, theCircle);
0049   }
0050 
0051   //! Resutns vector of registered circles.
0052   const IMeshData::VectorOfCircle& Circles() const { return myCircles; }
0053 
0054   //! Returns circle with the given index.
0055   //! @param theIndex index of circle.
0056   //! @return circle with the given index.
0057   BRepMesh_Circle& Circle(const Standard_Integer theIndex) { return myCircles(theIndex); }
0058 
0059   //! Set reference point to be checked.
0060   //! @param thePoint bullet point.
0061   void SetPoint(const gp_XY& thePoint)
0062   {
0063     myResIndices.Clear();
0064     myPoint = thePoint;
0065   }
0066 
0067   //! Returns list of circles shot by the reference point.
0068   IMeshData::ListOfInteger& GetShotCircles() { return myResIndices; }
0069 
0070   //! Performs inspection of a circle with the given index.
0071   //! @param theTargetIndex index of a circle to be checked.
0072   //! @return status of the check.
0073   NCollection_CellFilter_Action Inspect(const Standard_Integer theTargetIndex)
0074   {
0075     BRepMesh_Circle&     aCircle = myCircles(theTargetIndex);
0076     const Standard_Real& aRadius = aCircle.Radius();
0077     if (aRadius < 0.)
0078       return CellFilter_Purge;
0079 
0080     gp_XY& aLoc = const_cast<gp_XY&>(aCircle.Location());
0081 
0082     const Standard_Real aDX = myPoint.ChangeCoord(1) - aLoc.ChangeCoord(1);
0083     const Standard_Real aDY = myPoint.ChangeCoord(2) - aLoc.ChangeCoord(2);
0084 
0085     // This check is wrong. It is better to use
0086     //
0087     //   const Standard_Real aR = aRadius + aToler;
0088     //   if ((aDX * aDX + aDY * aDY) <= aR * aR)
0089     //   {
0090     //     ...
0091     //   }
0092 
0093     // where aToler = sqrt(mySqTolerance). Taking into account the fact
0094     // that the input parameter of the class (see constructor) is linear
0095     //(not quadratic) tolerance there is no point in square root computation.
0096     // Simply, we do not need to compute square of the input tolerance and to
0097     // assign it to mySqTolerance. The input linear tolerance is needed to be used.
0098 
0099     // However, this change leads to hangs the test case "perf mesh bug27119".
0100     // So, this correction is better to be implemented in the future.
0101 
0102     if ((aDX * aDX + aDY * aDY) - (aRadius * aRadius) <= mySqTolerance)
0103       myResIndices.Append(theTargetIndex);
0104 
0105     return CellFilter_Keep;
0106   }
0107 
0108   //! Checks indices for equality.
0109   static Standard_Boolean IsEqual(const Standard_Integer theIndex,
0110                                   const Standard_Integer theTargetIndex)
0111   {
0112     return (theIndex == theTargetIndex);
0113   }
0114 
0115 private:
0116   Standard_Real             mySqTolerance;
0117   IMeshData::ListOfInteger  myResIndices;
0118   IMeshData::VectorOfCircle myCircles;
0119   gp_XY                     myPoint;
0120 };
0121 
0122 #endif