1 // File: MeshAlgo_CircleTool.cxx
2 // Created: Tue Jun 15 19:10:25 1993
3 // Author: Didier PIFFAULT
6 #include <MeshAlgo_CircleTool.ixx>
8 #include <Precision.hxx>
9 #include <MeshAlgo_Circ.hxx>
10 #include <MeshAlgo_CircleInspector.hxx>
13 //=======================================================================
14 //function : MeshAlgo_CircleInspector
15 //purpose : Constructor
17 //=======================================================================
19 MeshAlgo_CircleInspector::MeshAlgo_CircleInspector (Standard_Real theTol,
20 Standard_Integer nbComp,
21 const MeshDS_BaseAllocator& theAlloc)
22 : myTol(theTol*theTol),
26 // myTol = theTol*theTol;
29 //=======================================================================
33 //=======================================================================
34 NCollection_CellFilter_Action MeshAlgo_CircleInspector::Inspect (const Standard_Integer theTarget)
36 const MeshAlgo_Circ& Circ = myInitCircle(theTarget);
37 Standard_Real R = Circ.Radius();
39 return CellFilter_Purge;
41 const gp_XY& aLoc=Circ.Location();
42 dx=myCurrent.X()-aLoc.X();
43 dy=myCurrent.Y()-aLoc.Y();
44 if ((dx*dx+dy*dy)-(R*R) <= myTol)
45 myResInd.Append(theTarget);
46 return CellFilter_Keep;
50 //=======================================================================
51 //function : MeshAlgo_CircleTool
53 //=======================================================================
54 MeshAlgo_CircleTool::MeshAlgo_CircleTool(const MeshDS_BaseAllocator& theAlloc)
55 : Tolerance(Precision::PConfusion()),
57 CellFilter(10, theAlloc),
58 Selector(Tolerance,64,theAlloc)
60 Tolerance=Tolerance*Tolerance;
63 //=======================================================================
64 //function : MeshAlgo_CircleTool
66 //=======================================================================
67 MeshAlgo_CircleTool::MeshAlgo_CircleTool(const Standard_Integer nbComp,
68 const MeshDS_BaseAllocator& theAlloc)
69 : Tolerance(Precision::PConfusion()),
71 CellFilter(10, theAlloc),
72 Selector(Tolerance,Max(nbComp,64),theAlloc)
74 Tolerance=Tolerance*Tolerance;
78 //=======================================================================
79 //function : Initialize
81 //=======================================================================
82 void MeshAlgo_CircleTool::Initialize(const Standard_Integer /*nbComp*/)
84 Tolerance=Precision::PConfusion();
85 Tolerance=Tolerance*Tolerance;
88 void MeshAlgo_CircleTool::SetCellSize(const Standard_Real theSize)
90 CellFilter.Reset(theSize, Allocator);
93 void MeshAlgo_CircleTool::SetCellSize(const Standard_Real theXSize,
94 const Standard_Real theYSize)
96 Standard_Real aCellSize[2];
97 aCellSize[0] = theXSize;
98 aCellSize[1] = theYSize;
100 CellFilter.Reset(aCellSize, Allocator);
104 void MeshAlgo_CircleTool::SetMinMaxSize(const gp_XY& theMin,
111 //=======================================================================
114 //=======================================================================
115 void MeshAlgo_CircleTool::Add(const gp_Circ2d& theCirc,
116 const Standard_Integer theIndex)
118 gp_XY aCoord(theCirc.Location().Coord());
119 Standard_Real R = theCirc.Radius();
120 MeshAlgo_Circ aCir(aCoord, R);
123 Standard_Real xMax=Min(aCoord.X()+R,FaceMax.X());
124 Standard_Real xMin=Max(aCoord.X()-R,FaceMin.X());
125 Standard_Real yMax=Min(aCoord.Y()+R,FaceMax.Y());
126 Standard_Real yMin=Max(aCoord.Y()-R,FaceMin.Y());
128 gp_XY MinPnt(xMin,yMin);
129 gp_XY MaxPnt(xMax,yMax);
131 CellFilter.Add(theIndex, MinPnt, MaxPnt);
132 Selector.Add(theIndex, aCir);
135 //=======================================================================
138 //=======================================================================
139 Standard_Boolean MeshAlgo_CircleTool::Add(const gp_XY& p1,
142 const Standard_Integer theIndex)
144 gp_XY m1((p1.X()+p2.X())/2., (p1.Y()+p2.Y())/2.);
145 gp_XY m2((p2.X()+p3.X())/2., (p2.Y()+p3.Y())/2.);
146 gp_XY m3((p3.X()+p1.X())/2., (p3.Y()+p1.Y())/2.);
147 Standard_Real dx=m1.X()-m2.X();
148 Standard_Real dy=m1.Y()-m2.Y();
149 Standard_Real d12=(dx*dx)+(dy*dy);
152 Standard_Real d23=(dx*dx)+(dy*dy);
155 Standard_Real d31=(dx*dx)+(dy*dy);
156 gp_XY pl11, pl12, pl21, pl22;
158 if (d12>d23 && d12>d31) {
161 if (dy!=0. || dx!=0.) {
163 pl12 = gp_XY(dy, dx);
165 else return Standard_False;
169 if (dy!=0. || dx!=0.) {
171 pl22 = gp_XY(dy, dx);
173 else return Standard_False;
179 if (dy!=0. || dx!=0.) {
181 pl12 = gp_XY(dy, dx);
183 else return Standard_False;
187 if (dy!=0. || dx!=0.) {
189 pl22 = gp_XY(dy, dx);
191 else return Standard_False;
196 if (dy!=0. || dx!=0.) {
198 pl12 = gp_XY(dy, dx);
200 else return Standard_False;
204 if (dy!=0. || dx!=0.) {
206 pl22 = gp_XY(dy, dx);
208 else return Standard_False;
212 gp_XY aVecO1O2 = pl21 - pl11;
213 Standard_Real aCrossD1D2 = pl12 ^ pl22;
214 Standard_Real theSinAngle = Abs(aCrossD1D2);
215 if (theSinAngle < gp::Resolution())
216 return Standard_False;
217 Standard_Real theParam1 = (aVecO1O2 ^ pl22) / aCrossD1D2;
218 gp_XY pInt = pl11+pl12*theParam1;
221 Standard_Real R = Sqrt(dx*dx+dy*dy);
222 MeshAlgo_Circ aCir(pInt, R);
225 Standard_Real xMax=Min(pInt.X()+R,FaceMax.X());
226 Standard_Real xMin=Max(pInt.X()-R,FaceMin.X());
227 Standard_Real yMax=Min(pInt.Y()+R,FaceMax.Y());
228 Standard_Real yMin=Max(pInt.Y()-R,FaceMin.Y());
230 gp_XY MinPnt(xMin,yMin);
231 gp_XY MaxPnt(xMax,yMax);
233 CellFilter.Add(theIndex, MinPnt, MaxPnt);
235 Selector.Add(theIndex, aCir);
236 return Standard_True;
239 //=======================================================================
242 //=======================================================================
243 void MeshAlgo_CircleTool::Delete(const Standard_Integer theIndex)
245 MeshAlgo_Circ& Circ = Selector.GetCirc(theIndex);
246 if(Circ.Radius() > 0.) {
251 //=======================================================================
254 //=======================================================================
255 MeshDS_ListOfInteger& MeshAlgo_CircleTool::Select(const gp_XY& thePnt)
257 Selector.ClerResList();
258 Selector.SetCurrent(thePnt);
259 CellFilter.Inspect (thePnt, Selector);
260 return Selector.GetCoincidentInd();
263 void MeshAlgo_CircleTool::MocAdd(const Standard_Integer theIndex)
265 gp_XY nullPnt(0.,0.);
266 MeshAlgo_Circ theNullCir(nullPnt, -1.);
267 Selector.Add(theIndex, theNullCir);