1 // Created on: 1994-03-25
2 // Created by: Jean Marc LACHAUME
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 #include <DBRep_IsoBuilder.ixx>
19 #include <Precision.hxx>
20 #include <BRepTools.hxx>
21 #include <BRep_Tool.hxx>
22 #include <Geom2dAdaptor_Curve.hxx>
23 #include <Geom2dHatch_Intersector.hxx>
24 #include <Geom2d_Curve.hxx>
25 #include <Geom2d_Line.hxx>
26 #include <Geom2d_TrimmedCurve.hxx>
27 #include <HatchGen_Domain.hxx>
28 #include <Precision.hxx>
29 #include <TopAbs_ShapeEnum.hxx>
30 #include <TopExp_Explorer.hxx>
32 #include <TopoDS_Edge.hxx>
33 #include <gp_Dir2d.hxx>
34 #include <gp_Pnt2d.hxx>
36 // Modified by Sergey KHROMOV - Thu Nov 9 12:08:37 2000
37 static Standard_Real IntersectorConfusion = 1.e-10 ; // -8 ;
38 static Standard_Real IntersectorTangency = 1.e-10 ; // -8 ;
39 // Modified by Sergey KHROMOV - Thu Nov 9 12:08:38 2000
40 static Standard_Real HatcherConfusion2d = 1.e-8 ;
41 static Standard_Real HatcherConfusion3d = 1.e-8 ;
43 //=======================================================================
44 // Function : DBRep_IsoBuilder
45 // Purpose : Constructeur.
46 //=======================================================================
48 DBRep_IsoBuilder::DBRep_IsoBuilder (const TopoDS_Face& TopologicalFace,
49 const Standard_Real Infinite,
50 const Standard_Integer NbIsos) :
51 Geom2dHatch_Hatcher (Geom2dHatch_Intersector (IntersectorConfusion,
57 myInfinite (Infinite) ,
71 //-----------------------------------------------------------------------
72 // If the Min Max bounds are infinite, there are bounded to Infinite
74 //-----------------------------------------------------------------------
76 BRepTools::UVBounds (TopologicalFace, myUMin, myUMax, myVMin, myVMax) ;
77 Standard_Boolean InfiniteUMin = Precision::IsNegativeInfinite (myUMin) ;
78 Standard_Boolean InfiniteUMax = Precision::IsPositiveInfinite (myUMax) ;
79 Standard_Boolean InfiniteVMin = Precision::IsNegativeInfinite (myVMin) ;
80 Standard_Boolean InfiniteVMax = Precision::IsPositiveInfinite (myVMax) ;
81 if (InfiniteUMin && InfiniteUMax) {
84 } else if (InfiniteUMin) {
85 myUMin = myUMax - Infinite ;
86 } else if (InfiniteUMax) {
87 myUMax = myUMin + Infinite ;
89 if (InfiniteVMin && InfiniteVMax) {
92 } else if (InfiniteVMin) {
93 myVMin = myVMax - Infinite ;
94 } else if (InfiniteVMax) {
95 myVMax = myVMin + Infinite ;
98 //-----------------------------------------------------------------------
99 // Retreiving the edges and loading them into the hatcher.
100 //-----------------------------------------------------------------------
102 TopExp_Explorer ExpEdges;
103 for (ExpEdges.Init (TopologicalFace, TopAbs_EDGE); ExpEdges.More(); ExpEdges.Next())
105 const TopoDS_Edge& TopologicalEdge = TopoDS::Edge (ExpEdges.Current());
106 Standard_Real U1, U2;
107 const Handle(Geom2d_Curve) PCurve = BRep_Tool::CurveOnSurface (TopologicalEdge, TopologicalFace, U1, U2);
112 cout << "DBRep_IsoBuilder : PCurve is null\n";
119 cout << "DBRep_IsoBuilder PCurve : U1==U2\n";
124 //-- Test if a TrimmedCurve is necessary
125 if (Abs(PCurve->FirstParameter()-U1)<= Precision::PConfusion()
126 && Abs(PCurve->LastParameter()-U2)<= Precision::PConfusion())
128 AddElement (PCurve, TopologicalEdge.Orientation());
132 if (!PCurve->IsPeriodic())
134 Handle (Geom2d_TrimmedCurve) TrimPCurve = Handle(Geom2d_TrimmedCurve)::DownCast (PCurve);
135 if (!TrimPCurve.IsNull())
137 if (TrimPCurve->BasisCurve()->FirstParameter() - U1 > Precision::PConfusion() ||
138 TrimPCurve->BasisCurve()->FirstParameter() - U2 > Precision::PConfusion() ||
139 U1 - TrimPCurve->BasisCurve()->LastParameter() > Precision::PConfusion() ||
140 U2 - TrimPCurve->BasisCurve()->LastParameter() > Precision::PConfusion())
142 AddElement (PCurve, TopologicalEdge.Orientation());
144 cout << "DBRep_IsoBuilder TrimPCurve : parameters out of range\n";
145 cout << " U1(" << U1 << "), Umin(" << PCurve->FirstParameter()
146 << "), U2(" << U2 << "), Umax(" << PCurve->LastParameter() << ")\n";
153 if (PCurve->FirstParameter() - U1 > Precision::PConfusion())
156 cout << "DBRep_IsoBuilder PCurve : parameters out of range\n";
157 cout << " U1(" << U1 << "), Umin(" << PCurve->FirstParameter() << ")\n";
159 U1 = PCurve->FirstParameter();
161 if (PCurve->FirstParameter() - U2 > Precision::PConfusion())
164 cout << "DBRep_IsoBuilder PCurve : parameters out of range\n";
165 cout << " U2(" << U2 << "), Umin(" << PCurve->FirstParameter() << ")\n";
167 U2 = PCurve->FirstParameter();
169 if (U1 - PCurve->LastParameter() > Precision::PConfusion())
172 cout << "DBRep_IsoBuilder PCurve : parameters out of range\n";
173 cout << " U1(" << U1 << "), Umax(" << PCurve->LastParameter() << ")\n";
175 U1 = PCurve->LastParameter();
177 if (U2 - PCurve->LastParameter() > Precision::PConfusion())
180 cout << "DBRep_IsoBuilder PCurve : parameters out of range\n";
181 cout << " U2(" << U2 << "), Umax(" << PCurve->LastParameter() << ")\n";
183 U2 = PCurve->LastParameter();
188 // if U1 and U2 coincide-->do nothing
189 if (Abs (U1 - U2) <= Precision::PConfusion()) continue;
190 Handle (Geom2d_TrimmedCurve) TrimPCurve = new Geom2d_TrimmedCurve (PCurve, U1, U2);
191 AddElement (TrimPCurve, TopologicalEdge.Orientation());
195 //-----------------------------------------------------------------------
196 // Loading and trimming the hatchings.
197 //-----------------------------------------------------------------------
199 Standard_Integer IIso ;
200 Standard_Real DeltaU = Abs (myUMax - myUMin) ;
201 Standard_Real DeltaV = Abs (myVMax - myVMin) ;
202 Standard_Real confusion = Min (DeltaU, DeltaV) * HatcherConfusion3d ;
203 Confusion3d (confusion) ;
205 Standard_Real StepU = DeltaU / (Standard_Real) NbIsos ;
206 if (StepU > confusion) {
207 Standard_Real UPrm = myUMin + StepU / 2. ;
208 gp_Dir2d Dir (0., 1.) ;
209 for (IIso = 1 ; IIso <= NbIsos ; IIso++) {
210 myUPrm(IIso) = UPrm ;
211 gp_Pnt2d Ori (UPrm, 0.) ;
212 Geom2dAdaptor_Curve HCur (new Geom2d_Line (Ori, Dir)) ;
213 myUInd(IIso) = AddHatching (HCur) ;
218 Standard_Real StepV = DeltaV / (Standard_Real) NbIsos ;
219 if (StepV > confusion) {
220 Standard_Real VPrm = myVMin + StepV / 2. ;
221 gp_Dir2d Dir (1., 0.) ;
222 for (IIso = 1 ; IIso <= NbIsos ; IIso++) {
223 myVPrm(IIso) = VPrm ;
224 gp_Pnt2d Ori (0., VPrm) ;
225 Geom2dAdaptor_Curve HCur (new Geom2d_Line (Ori, Dir)) ;
226 myVInd(IIso) = AddHatching (HCur) ;
231 //-----------------------------------------------------------------------
233 //-----------------------------------------------------------------------
238 for (IIso = 1 ; IIso <= NbIsos ; IIso++)
240 Standard_Integer Index ;
242 Index = myUInd(IIso) ;
245 if (TrimDone (Index) && !TrimFailed (Index))
247 ComputeDomains (Index);
249 myNbDom = myNbDom + Geom2dHatch_Hatcher::NbDomains (Index) ;
253 Index = myVInd(IIso) ;
256 if (TrimDone (Index) && !TrimFailed (Index))
258 ComputeDomains (Index);
260 myNbDom = myNbDom + Geom2dHatch_Hatcher::NbDomains (Index) ;
266 //=======================================================================
267 // Function : LoadIsos
268 // Purpose : Loading of the isoparametric curves in the Data Structure
269 // of a drawable face.
270 //=======================================================================
272 void DBRep_IsoBuilder::LoadIsos (const Handle(DBRep_Face)& Face) const
274 Standard_Integer NumIso = 0 ;
276 for (Standard_Integer UIso = myUPrm.Lower() ; UIso <= myUPrm.Upper() ; UIso++) {
277 Standard_Integer UInd = myUInd.Value (UIso) ;
279 Standard_Real UPrm = myUPrm.Value (UIso) ;
280 if (!IsDone (UInd)) {
281 cout << "DBRep_IsoBuilder:: U iso of parameter: " << UPrm ;
282 switch (Status (UInd)) {
283 case HatchGen_NoProblem : cout << " No Problem" << endl ; break ;
284 case HatchGen_TrimFailure : cout << " Trim Failure" << endl ; break ;
285 case HatchGen_TransitionFailure : cout << " Transition Failure" << endl ; break ;
286 case HatchGen_IncoherentParity : cout << " Incoherent Parity" << endl ; break ;
287 case HatchGen_IncompatibleStates : cout << " Incompatible States" << endl ; break ;
290 Standard_Integer NbDom = Geom2dHatch_Hatcher::NbDomains (UInd) ;
291 for (Standard_Integer IDom = 1 ; IDom <= NbDom ; IDom++) {
292 const HatchGen_Domain& Dom = Domain (UInd, IDom) ;
293 Standard_Real V1 = Dom.HasFirstPoint() ? Dom.FirstPoint().Parameter() : myVMin - myInfinite ;
294 Standard_Real V2 = Dom.HasSecondPoint() ? Dom.SecondPoint().Parameter() : myVMax + myInfinite ;
296 Face->Iso (NumIso, GeomAbs_IsoU, UPrm, V1, V2) ;
302 for (Standard_Integer VIso = myVPrm.Lower() ; VIso <= myVPrm.Upper() ; VIso++) {
303 Standard_Integer VInd = myVInd.Value (VIso) ;
305 Standard_Real VPrm = myVPrm.Value (VIso) ;
306 if (!IsDone (VInd)) {
307 cout << "DBRep_IsoBuilder:: V iso of parameter: " << VPrm ;
308 switch (Status (VInd)) {
309 case HatchGen_NoProblem : cout << " No Problem" << endl ; break ;
310 case HatchGen_TrimFailure : cout << " Trim Failure" << endl ; break ;
311 case HatchGen_TransitionFailure : cout << " Transition Failure" << endl ; break ;
312 case HatchGen_IncoherentParity : cout << " Incoherent Parity" << endl ; break ;
313 case HatchGen_IncompatibleStates : cout << " Incompatible States" << endl ; break ;
316 Standard_Integer NbDom = Geom2dHatch_Hatcher::NbDomains (VInd) ;
317 for (Standard_Integer IDom = 1 ; IDom <= NbDom ; IDom++) {
318 const HatchGen_Domain& Dom = Domain (VInd, IDom) ;
319 Standard_Real U1 = Dom.HasFirstPoint() ? Dom.FirstPoint().Parameter() : myVMin - myInfinite ;
320 Standard_Real U2 = Dom.HasSecondPoint() ? Dom.SecondPoint().Parameter() : myVMax + myInfinite ;
322 Face->Iso (NumIso, GeomAbs_IsoV, VPrm, U1, U2) ;