1 // File: BRepMesh_CircleTool.cxx
2 // Created: Tue Jun 15 19:10:25 1993
3 // Author: Didier PIFFAULT
6 #include <BRepMesh_CircleTool.ixx>
8 #include <Precision.hxx>
9 #include <BRepMesh_Circ.hxx>
10 #include <BRepMesh_CircleInspector.hxx>
11 #include <BRepMesh_BaseAllocator.hxx>
14 //=======================================================================
15 //function : BRepMesh_CircleInspector
16 //purpose : Constructor
18 //=======================================================================
20 BRepMesh_CircleInspector::BRepMesh_CircleInspector (Standard_Real theTol,
21 Standard_Integer nbComp,
22 const BRepMesh_BaseAllocator& theAlloc)
23 : myTol(theTol*theTol),
27 // myTol = theTol*theTol;
30 //=======================================================================
34 //=======================================================================
35 NCollection_CellFilter_Action BRepMesh_CircleInspector::Inspect (const Standard_Integer theTarget)
37 const BRepMesh_Circ& Circ = myInitCircle(theTarget);
38 Standard_Real R = Circ.Radius();
40 return CellFilter_Purge;
42 const gp_XY& aLoc=Circ.Location();
43 dx=myCurrent.X()-aLoc.X();
44 dy=myCurrent.Y()-aLoc.Y();
45 if ((dx*dx+dy*dy)-(R*R) <= myTol)
46 myResInd.Append(theTarget);
47 return CellFilter_Keep;
51 //=======================================================================
52 //function : BRepMesh_CircleTool
54 //=======================================================================
55 BRepMesh_CircleTool::BRepMesh_CircleTool(const BRepMesh_BaseAllocator& theAlloc)
56 : Tolerance(Precision::PConfusion()),
58 CellFilter(10, theAlloc),
59 Selector(Tolerance,64,theAlloc)
61 Tolerance=Tolerance*Tolerance;
64 //=======================================================================
65 //function : BRepMesh_CircleTool
67 //=======================================================================
68 BRepMesh_CircleTool::BRepMesh_CircleTool(const Standard_Integer nbComp,
69 const BRepMesh_BaseAllocator& theAlloc)
70 : Tolerance(Precision::PConfusion()),
72 CellFilter(10, theAlloc),
73 Selector(Tolerance,Max(nbComp,64),theAlloc)
75 Tolerance=Tolerance*Tolerance;
79 //=======================================================================
80 //function : Initialize
82 //=======================================================================
83 void BRepMesh_CircleTool::Initialize(const Standard_Integer /*nbComp*/)
85 Tolerance=Precision::PConfusion();
86 Tolerance=Tolerance*Tolerance;
89 void BRepMesh_CircleTool::SetCellSize(const Standard_Real theSize)
91 CellFilter.Reset(theSize, Allocator);
94 void BRepMesh_CircleTool::SetCellSize(const Standard_Real theXSize,
95 const Standard_Real theYSize)
97 Standard_Real aCellSize[2];
98 aCellSize[0] = theXSize;
99 aCellSize[1] = theYSize;
101 CellFilter.Reset(aCellSize, Allocator);
105 void BRepMesh_CircleTool::SetMinMaxSize(const gp_XY& theMin,
112 //=======================================================================
115 //=======================================================================
116 void BRepMesh_CircleTool::Add(const gp_Circ2d& theCirc,
117 const Standard_Integer theIndex)
119 gp_XY aCoord(theCirc.Location().Coord());
120 Standard_Real R = theCirc.Radius();
121 BRepMesh_Circ aCir(aCoord, R);
124 Standard_Real xMax=Min(aCoord.X()+R,FaceMax.X());
125 Standard_Real xMin=Max(aCoord.X()-R,FaceMin.X());
126 Standard_Real yMax=Min(aCoord.Y()+R,FaceMax.Y());
127 Standard_Real yMin=Max(aCoord.Y()-R,FaceMin.Y());
129 gp_XY MinPnt(xMin,yMin);
130 gp_XY MaxPnt(xMax,yMax);
132 CellFilter.Add(theIndex, MinPnt, MaxPnt);
133 Selector.Add(theIndex, aCir);
136 //=======================================================================
139 //=======================================================================
140 Standard_Boolean BRepMesh_CircleTool::Add(const gp_XY& p1,
143 const Standard_Integer theIndex)
145 gp_XY m1((p1.X()+p2.X())/2., (p1.Y()+p2.Y())/2.);
146 gp_XY m2((p2.X()+p3.X())/2., (p2.Y()+p3.Y())/2.);
147 gp_XY m3((p3.X()+p1.X())/2., (p3.Y()+p1.Y())/2.);
148 Standard_Real dx=m1.X()-m2.X();
149 Standard_Real dy=m1.Y()-m2.Y();
150 Standard_Real d12=(dx*dx)+(dy*dy);
153 Standard_Real d23=(dx*dx)+(dy*dy);
156 Standard_Real d31=(dx*dx)+(dy*dy);
157 gp_XY pl11, pl12, pl21, pl22;
159 if (d12>d23 && d12>d31) {
162 if (dy!=0. || dx!=0.) {
164 pl12 = gp_XY(dy, dx);
166 else return Standard_False;
170 if (dy!=0. || dx!=0.) {
172 pl22 = gp_XY(dy, dx);
174 else return Standard_False;
180 if (dy!=0. || dx!=0.) {
182 pl12 = gp_XY(dy, dx);
184 else return Standard_False;
188 if (dy!=0. || dx!=0.) {
190 pl22 = gp_XY(dy, dx);
192 else return Standard_False;
197 if (dy!=0. || dx!=0.) {
199 pl12 = gp_XY(dy, dx);
201 else return Standard_False;
205 if (dy!=0. || dx!=0.) {
207 pl22 = gp_XY(dy, dx);
209 else return Standard_False;
213 gp_XY aVecO1O2 = pl21 - pl11;
214 Standard_Real aCrossD1D2 = pl12 ^ pl22;
215 Standard_Real theSinAngle = Abs(aCrossD1D2);
216 if (theSinAngle < gp::Resolution())
217 return Standard_False;
218 Standard_Real theParam1 = (aVecO1O2 ^ pl22) / aCrossD1D2;
219 gp_XY pInt = pl11+pl12*theParam1;
222 Standard_Real R = Sqrt(dx*dx+dy*dy);
223 BRepMesh_Circ aCir(pInt, R);
226 Standard_Real xMax=Min(pInt.X()+R,FaceMax.X());
227 Standard_Real xMin=Max(pInt.X()-R,FaceMin.X());
228 Standard_Real yMax=Min(pInt.Y()+R,FaceMax.Y());
229 Standard_Real yMin=Max(pInt.Y()-R,FaceMin.Y());
231 gp_XY MinPnt(xMin,yMin);
232 gp_XY MaxPnt(xMax,yMax);
234 CellFilter.Add(theIndex, MinPnt, MaxPnt);
236 Selector.Add(theIndex, aCir);
237 return Standard_True;
240 //=======================================================================
243 //=======================================================================
244 void BRepMesh_CircleTool::Delete(const Standard_Integer theIndex)
246 BRepMesh_Circ& Circ = Selector.GetCirc(theIndex);
247 if(Circ.Radius() > 0.) {
252 //=======================================================================
255 //=======================================================================
256 BRepMesh_ListOfInteger& BRepMesh_CircleTool::Select(const gp_XY& thePnt)
258 Selector.ClerResList();
259 Selector.SetCurrent(thePnt);
260 CellFilter.Inspect (thePnt, Selector);
261 return Selector.GetCoincidentInd();
264 void BRepMesh_CircleTool::MocAdd(const Standard_Integer theIndex)
266 gp_XY nullPnt(0.,0.);
267 BRepMesh_Circ theNullCir(nullPnt, -1.);
268 Selector.Add(theIndex, theNullCir);