Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 10:03:13

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