0030694: Data Exchange - support non-standard GB2312-encoded STEP files
[occt.git] / src / BRepMesh / BRepMesh_CircleInspector.hxx
CommitLineData
b311480e 1// Created on: 2008-05-26
2// Created by: Ekaterina SMIRNOVA
973c2be1 3// Copyright (c) 2008-2014 OPEN CASCADE SAS
b311480e 4//
973c2be1 5// This file is part of Open CASCADE Technology software library.
b311480e 6//
d5f74e42 7// This library is free software; you can redistribute it and/or modify it under
8// the terms of the GNU Lesser General Public License version 2.1 as published
973c2be1 9// by the Free Software Foundation, with special exception defined in the file
10// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
11// distribution for complete text of the license and disclaimer of any warranty.
b311480e 12//
973c2be1 13// Alternatively, this file may be used under the terms of Open CASCADE
14// commercial license or contractual agreement.
0d88155b
O
15
16#ifndef BRepMesh_CircleInspector_Header
17#define BRepMesh_CircleInspector_Header
18
7bd071ed 19#include <IMeshData_Types.hxx>
fc9b36d6 20#include <BRepMesh_Circle.hxx>
0d88155b
O
21#include <Precision.hxx>
22#include <gp_XY.hxx>
23#include <gp_XYZ.hxx>
0d88155b 24#include <NCollection_CellFilter.hxx>
0d88155b 25
fc9b36d6 26//! Auxilary class to find circles shot by the given point.
0d88155b
O
27class BRepMesh_CircleInspector : public NCollection_CellFilter_InspectorXY
28{
29public:
30 typedef Standard_Integer Target;
0d88155b 31
fc9b36d6 32 //! Constructor.
848fa7e3 33 //! @param theTolerance tolerance to be used for identification of shot circles.
34 //! @param theReservedSize size to be reserved for vector of circles.
35 //! @param theAllocator memory allocator to be used by internal collections.
be5c3602 36 BRepMesh_CircleInspector(
848fa7e3 37 const Standard_Real theTolerance,
38 const Standard_Integer theReservedSize,
39 const Handle(NCollection_IncAllocator)& theAllocator)
7bd071ed 40 : mySqTolerance(theTolerance*theTolerance),
fc9b36d6 41 myResIndices(theAllocator),
7bd071ed 42 myCircles(theReservedSize, theAllocator)
0d88155b 43 {
0d88155b
O
44 }
45
fc9b36d6 46 //! Adds the circle to vector of circles at the given position.
848fa7e3 47 //! @param theIndex position of circle in the vector.
48 //! @param theCircle circle to be added.
fc9b36d6 49 inline void Bind(const Standard_Integer theIndex,
50 const BRepMesh_Circle& theCircle)
0d88155b 51 {
fc9b36d6 52 myCircles.SetValue(theIndex, theCircle);
0d88155b
O
53 }
54
fc9b36d6 55 //! Resutns vector of registered circles.
7bd071ed 56 inline const IMeshData::VectorOfCircle& Circles() const
0d88155b 57 {
fc9b36d6 58 return myCircles;
0d88155b
O
59 }
60
fc9b36d6 61 //! Returns circle with the given index.
848fa7e3 62 //! @param theIndex index of circle.
63 //! @return circle with the given index.
fc9b36d6 64 inline BRepMesh_Circle& Circle(const Standard_Integer theIndex)
0d88155b 65 {
fc9b36d6 66 return myCircles(theIndex);
0d88155b
O
67 }
68
fc9b36d6 69 //! Set reference point to be checked.
848fa7e3 70 //! @param thePoint bullet point.
fc9b36d6 71 inline void SetPoint(const gp_XY& thePoint)
72 {
73 myResIndices.Clear();
74 myPoint = thePoint;
0d88155b
O
75 }
76
fc9b36d6 77 //! Returns list of circles shot by the reference point.
7bd071ed 78 inline IMeshData::ListOfInteger& GetShotCircles()
0d88155b 79 {
fc9b36d6 80 return myResIndices;
0d88155b
O
81 }
82
fc9b36d6 83 //! Performs inspection of a circle with the given index.
848fa7e3 84 //! @param theTargetIndex index of a circle to be checked.
85 //! @return status of the check.
7bd071ed 86 inline NCollection_CellFilter_Action Inspect(
87 const Standard_Integer theTargetIndex)
88 {
89 BRepMesh_Circle& aCircle = myCircles(theTargetIndex);
90 const Standard_Real& aRadius = aCircle.Radius();
91 if (aRadius < 0.)
92 return CellFilter_Purge;
93
94 gp_XY& aLoc = const_cast<gp_XY&>(aCircle.Location());
95
96 const Standard_Real aDX = myPoint.ChangeCoord(1) - aLoc.ChangeCoord(1);
97 const Standard_Real aDY = myPoint.ChangeCoord(2) - aLoc.ChangeCoord(2);
98
99 //This check is wrong. It is better to use
100 //
101 // const Standard_Real aR = aRadius + aToler;
102 // if ((aDX * aDX + aDY * aDY) <= aR * aR)
103 // {
104 // ...
105 // }
106
107 //where aToler = sqrt(mySqTolerance). Taking into account the fact
108 //that the input parameter of the class (see constructor) is linear
109 //(not quadratic) tolerance there is no point in square root computation.
110 //Simply, we do not need to compute square of the input tolerance and to
111 //assign it to mySqTolerance. The input linear tolerance is needed to be used.
112
113 //However, this change leads to hangs the test case "perf mesh bug27119".
114 //So, this correction is better to be implemented in the future.
115
116 if ((aDX * aDX + aDY * aDY) - (aRadius * aRadius) <= mySqTolerance)
117 myResIndices.Append(theTargetIndex);
118
119 return CellFilter_Keep;
120 }
0d88155b 121
fc9b36d6 122 //! Checks indices for equlity.
be5c3602 123 static Standard_Boolean IsEqual(
fc9b36d6 124 const Standard_Integer theIndex,
125 const Standard_Integer theTargetIndex)
0d88155b 126 {
fc9b36d6 127 return (theIndex == theTargetIndex);
0d88155b
O
128 }
129
130private:
7bd071ed 131 Standard_Real mySqTolerance;
132 IMeshData::ListOfInteger myResIndices;
133 IMeshData::VectorOfCircle myCircles;
134 gp_XY myPoint;
0d88155b
O
135};
136
137#endif