1 // Created on: 1994-12-16
2 // Created by: Laurent BUCHARD
3 // Copyright (c) 1994-1999 Matra Datavision
4 // Copyright (c) 1999-2014 OPEN CASCADE SAS
6 // This file is part of Open CASCADE Technology software library.
8 // This library is free software; you can redistribute it and/or modify it under
9 // the terms of the GNU Lesser General Public License version 2.1 as published
10 // by the Free Software Foundation, with special exception defined in the file
11 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
12 // distribution for complete text of the license and disclaimer of any warranty.
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
17 // Modified by skv - Fri Jul 14 17:03:47 2006 OCC12627
19 #include <Geom2dAdaptor_Curve.hxx>
20 #include <Geom2dHatch_Element.hxx>
21 #include <Geom2dHatch_Elements.hxx>
23 #include <gp_Lin2d.hxx>
24 #include <gp_Pnt2d.hxx>
25 #include <gp_Vec2d.hxx>
26 #include <Standard_DomainError.hxx>
27 #include <Standard_Integer.hxx>
28 #include <Standard_NoSuchObject.hxx>
29 #include <TColStd_MapIntegerHasher.hxx>
30 #include <TopAbs_Orientation.hxx>
31 #include <Precision.hxx>
33 static const Standard_Real Probing_Start = 0.123;
34 static const Standard_Real Probing_End = 0.8;
35 static const Standard_Real Probing_Step = 0.2111;
37 Geom2dHatch_Elements::Geom2dHatch_Elements(const Geom2dHatch_Elements& )
40 std::cout<<" Magic Constructor in Geom2dHatch_Elements:: "<<std::endl;
44 Geom2dHatch_Elements::Geom2dHatch_Elements()
49 myCurEdgePar = Probing_Start;
52 void Geom2dHatch_Elements::Clear()
57 Standard_Boolean Geom2dHatch_Elements::IsBound(const Standard_Integer K) const
59 return(myMap.IsBound(K));
62 Standard_Boolean Geom2dHatch_Elements::UnBind(const Standard_Integer K)
64 return(myMap.UnBind(K));
67 Standard_Boolean Geom2dHatch_Elements::Bind(const Standard_Integer K,const Geom2dHatch_Element& I)
69 return(myMap.Bind(K,I));
72 const Geom2dHatch_Element& Geom2dHatch_Elements::Find(const Standard_Integer K) const
74 return(myMap.Find(K));
77 Geom2dHatch_Element& Geom2dHatch_Elements::ChangeFind(const Standard_Integer K)
79 return(myMap.ChangeFind(K));
82 //=======================================================================
83 //function : CheckPoint
85 //=======================================================================
87 Standard_Boolean Geom2dHatch_Elements::CheckPoint(gp_Pnt2d&)
92 //=======================================================================
95 //=======================================================================
97 Standard_Boolean Geom2dHatch_Elements::Reject(const gp_Pnt2d&) const {
98 return Standard_False;
101 //=======================================================================
104 //=======================================================================
106 Standard_Boolean Geom2dHatch_Elements::Segment(const gp_Pnt2d& P,
111 myCurEdgePar = Probing_Start;
112 return OtherSegment(P, L, Par);
115 //=======================================================================
118 //=======================================================================
120 Standard_Boolean Geom2dHatch_Elements::OtherSegment (const gp_Pnt2d& P,
124 Geom2dHatch_DataMapIteratorOfMapOfElements Itertemp;
127 for (Itertemp.Initialize (myMap), i = 1; Itertemp.More(); Itertemp.Next(), i++)
132 void *ptrmyMap = (void *)(&myMap);
133 Geom2dHatch_Element& Item = ((Geom2dHatch_MapOfElements*)ptrmyMap)->ChangeFind (Itertemp.Key());
134 Geom2dAdaptor_Curve& E = Item.ChangeCurve();
135 TopAbs_Orientation Or = Item.Orientation();
136 if (Or == TopAbs_FORWARD || Or == TopAbs_REVERSED)
138 Standard_Real aFPar = E.FirstParameter(), aLPar = E.LastParameter();
139 if (Precision::IsNegativeInfinite (aFPar))
141 if (Precision::IsPositiveInfinite (aLPar))
149 else if (Precision::IsPositiveInfinite (aLPar))
152 for (; myCurEdgePar < Probing_End; myCurEdgePar += Probing_Step)
154 Standard_Real aParam = myCurEdgePar * aFPar + (1. - myCurEdgePar) * aLPar;
157 E.D1 (aParam, aPOnC, aTanVec);
158 gp_Vec2d aLinVec (P, aPOnC);
159 Par = aLinVec.SquareMagnitude();
160 if (Par > Precision::SquarePConfusion())
162 gp_Dir2d aLinDir (aLinVec);
163 Standard_Real aTanMod = aTanVec.SquareMagnitude();
164 if (aTanMod < Precision::SquarePConfusion())
167 aTanVec /= Sqrt (aTanMod);
168 Standard_Real aSinA = aTanVec.Crossed (aLinDir);
169 if (Abs (aSinA) < 0.001)
171 // too small angle - line and edge may be considered
172 // as tangent which is bad for classifier
173 if (myCurEdgePar + Probing_Step < Probing_End)
177 L = gp_Lin2d (P, aLinDir);
179 aPOnC = E.Value (aFPar);
180 if (L.SquareDistance (aPOnC) > Precision::SquarePConfusion())
182 aPOnC = E.Value (aLPar);
183 if (L.SquareDistance (aPOnC) > Precision::SquarePConfusion())
185 myCurEdgePar += Probing_Step;
186 if (myCurEdgePar >= Probing_End)
189 myCurEdgePar = Probing_Start;
192 return Standard_True;
199 myCurEdgePar = Probing_Start;
203 L = gp_Lin2d (P, gp_Dir2d (1, 0));
205 return Standard_False;
208 //=======================================================================
209 //function : InitWires
211 //=======================================================================
213 void Geom2dHatch_Elements::InitWires() {
217 //=======================================================================
218 //function : RejectWire NYI
220 //=======================================================================
222 Standard_Boolean Geom2dHatch_Elements::RejectWire(const gp_Lin2d& ,
223 const Standard_Real) const
225 return Standard_False;
228 //=======================================================================
229 //function : InitEdges
231 //=======================================================================
233 void Geom2dHatch_Elements::InitEdges() {
235 Iter.Initialize(myMap);
238 //=======================================================================
239 //function : RejectEdge NYI
241 //=======================================================================
243 Standard_Boolean Geom2dHatch_Elements::RejectEdge(const gp_Lin2d& ,
244 const Standard_Real ) const
246 return Standard_False;
250 //=======================================================================
251 //function : CurrentEdge
253 //=======================================================================
255 void Geom2dHatch_Elements::CurrentEdge(Geom2dAdaptor_Curve& E,
256 TopAbs_Orientation& Or) const
258 void *ptrmyMap = (void *)(&myMap);
259 Geom2dHatch_Element& Item=((Geom2dHatch_MapOfElements*)ptrmyMap)->ChangeFind(Iter.Key());
261 E = Item.ChangeCurve();
262 Or= Item.Orientation();
264 E.Edge() = TopoDS::Edge(myEExplorer.Current());
266 Or = E.Edge().Orientation();
271 //=======================================================================
272 //function : MoreWires
274 //=======================================================================
276 Standard_Boolean Geom2dHatch_Elements::MoreWires() const
278 return (NumWire == 0);
281 //=======================================================================
282 //function : NextWire
284 //=======================================================================
286 void Geom2dHatch_Elements::NextWire() {
290 //=======================================================================
291 //function : MoreEdges
293 //=======================================================================
295 Standard_Boolean Geom2dHatch_Elements::MoreEdges() const {
299 //=======================================================================
300 //function : NextEdge
302 //=======================================================================
304 void Geom2dHatch_Elements::NextEdge() {