b311480e |
1 | // Created on: 1993-07-13 |
2 | // Created by: Yves FRICAUD |
3 | // Copyright (c) 1993-1999 Matra Datavision |
973c2be1 |
4 | // Copyright (c) 1999-2014 OPEN CASCADE SAS |
b311480e |
5 | // |
973c2be1 |
6 | // This file is part of Open CASCADE Technology software library. |
b311480e |
7 | // |
d5f74e42 |
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 |
973c2be1 |
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. |
b311480e |
13 | // |
973c2be1 |
14 | // Alternatively, this file may be used under the terms of Open CASCADE |
15 | // commercial license or contractual agreement. |
7fd59977 |
16 | |
7fd59977 |
17 | |
42cf5bc1 |
18 | #include <Bisector_Bisec.hxx> |
19 | #include <BRepMAT2d_BisectingLocus.hxx> |
20 | #include <BRepMAT2d_Explorer.hxx> |
21 | #include <Geom2d_Geometry.hxx> |
22 | #include <Geom2d_TrimmedCurve.hxx> |
23 | #include <gp_Pnt2d.hxx> |
24 | #include <MAT2d_BiInt.hxx> |
25 | #include <MAT2d_Circuit.hxx> |
26 | #include <MAT2d_CutCurve.hxx> |
27 | #include <MAT2d_Mat2d.hxx> |
28 | #include <MAT2d_SequenceOfSequenceOfGeometry.hxx> |
29 | #include <MAT2d_Tool2d.hxx> |
30 | #include <MAT_Arc.hxx> |
31 | #include <MAT_BasicElt.hxx> |
32 | #include <MAT_Bisector.hxx> |
33 | #include <MAT_DataMapIteratorOfDataMapOfIntegerBasicElt.hxx> |
34 | #include <MAT_DataMapOfIntegerBasicElt.hxx> |
35 | #include <MAT_Graph.hxx> |
36 | #include <MAT_ListOfBisector.hxx> |
37 | #include <MAT_Node.hxx> |
38 | #include <Precision.hxx> |
7fd59977 |
39 | #include <Standard_OutOfRange.hxx> |
42cf5bc1 |
40 | #include <TColGeom2d_SequenceOfGeometry.hxx> |
92efcf78 |
41 | #include <Geom2d_Curve.hxx> |
7fd59977 |
42 | |
43 | static void CutSketch (MAT2d_SequenceOfSequenceOfGeometry& Figure, |
44 | MAT2d_DataMapOfBiIntInteger& NbSect); |
45 | |
46 | |
47 | //============================================================================= |
47cbf134 |
48 | //function : BRepMAT2d_BisectingLocus |
7fd59977 |
49 | //purpose : Constructeur vide. |
50 | //============================================================================= |
47cbf134 |
51 | BRepMAT2d_BisectingLocus::BRepMAT2d_BisectingLocus() |
d533dafb |
52 | : isDone(Standard_False), |
53 | nbContours(0) |
7fd59977 |
54 | { |
55 | } |
56 | |
57 | |
58 | //============================================================================= |
59 | //function : Compute |
60 | //purpose : Calcul de la carte des lieux bisecteurs sur le contour defini par |
61 | // <anExplo>. |
62 | //============================================================================= |
6a442250 |
63 | void BRepMAT2d_BisectingLocus::Compute(BRepMAT2d_Explorer& anExplo, |
64 | const Standard_Integer IndexLine, |
65 | const MAT_Side aSide, |
c19dd45e |
66 | const GeomAbs_JoinType aJoinType, |
6a442250 |
67 | const Standard_Boolean IsOpenResult) |
7fd59977 |
68 | { |
0e0f7a7c |
69 | MAT2d_Mat2d TheMAT( IsOpenResult ); |
7fd59977 |
70 | Handle(MAT_ListOfBisector) TheRoots = new MAT_ListOfBisector(); |
71 | MAT2d_SequenceOfSequenceOfGeometry Figure; |
72 | Standard_Integer i; |
73 | |
74 | nbSect.Clear(); |
6b121e2b |
75 | theGraph = new MAT_Graph(); |
7fd59977 |
76 | nbContours = anExplo.NumberOfContours(); |
6b121e2b |
77 | if (nbContours == 0) |
78 | { |
79 | return; |
80 | } |
7fd59977 |
81 | |
82 | //--------------------------------- |
83 | // Lecture des donnees de anExplo. |
84 | //--------------------------------- |
85 | for (i = 1; i <= anExplo.NumberOfContours(); i++) { |
86 | TColGeom2d_SequenceOfGeometry Line; |
87 | Figure.Append(Line); |
88 | for (anExplo.Init(i); anExplo.More(); anExplo.Next()) { |
89 | Figure.ChangeValue(i).Append(anExplo.Value()); |
90 | } |
91 | } |
92 | |
93 | //----------------------- |
94 | // Decoupage des courbes. |
95 | //----------------------- |
96 | CutSketch(Figure,nbSect); |
97 | |
98 | //---------------------------------------------------------- |
99 | // Construction du circuit sur lequel est calcule la carte. |
100 | //---------------------------------------------------------- |
c19dd45e |
101 | Handle(MAT2d_Circuit) ACircuit = new MAT2d_Circuit(aJoinType, IsOpenResult); |
7fd59977 |
102 | // Modified by Sergey KHROMOV - Wed Mar 6 17:43:47 2002 Begin |
103 | // ACircuit->Perform(Figure,IndexLine,(aSide == MAT_Left)); |
104 | ACircuit->Perform(Figure,anExplo.GetIsClosed(), IndexLine,(aSide == MAT_Left)); |
105 | // Modified by Sergey KHROMOV - Wed Mar 6 17:43:48 2002 End |
106 | |
107 | // ----------------------- |
108 | // Initialistion du Tool. |
109 | // ----------------------- |
110 | theTool.Sense(aSide); |
c19dd45e |
111 | theTool.SetJoinType(aJoinType); |
7fd59977 |
112 | theTool.InitItems(ACircuit); |
113 | |
114 | // -------------------------------------------- |
115 | // Initialisation et execution de l algorithme. |
116 | // -------------------------------------------- |
0e0f7a7c |
117 | if (IsOpenResult) |
118 | TheMAT.CreateMatOpen(theTool); |
119 | else |
120 | TheMAT.CreateMat(theTool); |
7fd59977 |
121 | |
122 | isDone = TheMAT.IsDone(); if (!isDone) return; |
123 | |
124 | // ---------------------------------------------------------------- |
125 | // Recuperation du resultat de l algorithme et creation du graphe. |
126 | // ---------------------------------------------------------------- |
127 | for (TheMAT.Init(); TheMAT.More(); TheMAT.Next()) { |
128 | TheRoots->BackAdd(TheMAT.Bisector()); |
129 | } |
130 | |
7fd59977 |
131 | theGraph->Perform(TheMAT.SemiInfinite(), |
132 | TheRoots, |
133 | theTool.NumberOfItems(), |
134 | TheMAT.NumberOfBisectors()); |
135 | |
136 | //----------------------------------------------------------------------- |
137 | // Fusion des elements de base doubles si plusieurs lignes dans Exploset. |
138 | //----------------------------------------------------------------------- |
139 | if (anExplo.NumberOfContours() > 1) { |
140 | MAT_DataMapOfIntegerBasicElt NewMap; |
141 | Standard_Integer IndexLast = 1; |
142 | |
143 | //----------------------------------------------------------------------- |
144 | // Construction de NewMap dont les elements sont ordonnes suivant les |
145 | // lignes du contour et qui ne contient pas d element dupliques. |
146 | // em meme temps fusion des arcs dupliques et mise a jour des noeuds. |
147 | //----------------------------------------------------------------------- |
148 | for ( i = 1; i <= anExplo.NumberOfContours(); i++) { |
149 | RenumerationAndFusion(i, |
150 | theTool.Circuit()->LineLength(i), |
151 | IndexLast, |
152 | NewMap); |
153 | } |
154 | |
155 | //----------------------------------------------------------------------- |
156 | // Chargement dans le graph de la nouvelle map. |
157 | // et compactage de la map des Arcs (ie Elimination des trous du a la |
158 | // fusion d arcs ).et de celle des Nodes. |
159 | //----------------------------------------------------------------------- |
160 | theGraph->ChangeBasicElts(NewMap); |
161 | theGraph->CompactArcs(); |
162 | theGraph->CompactNodes(); |
163 | } |
164 | } |
165 | |
166 | //============================================================================= |
167 | //function : RenumerationAndFusion |
168 | //purpose : |
169 | //============================================================================= |
47cbf134 |
170 | void BRepMAT2d_BisectingLocus::RenumerationAndFusion |
7fd59977 |
171 | (const Standard_Integer ILine, |
172 | const Standard_Integer LengthLine, |
173 | Standard_Integer& IndexLast, |
174 | MAT_DataMapOfIntegerBasicElt& NewMap) |
175 | { |
176 | Standard_Integer IndFirst; |
177 | Standard_Integer i,j; |
178 | Standard_Integer GeomIndexArc1,GeomIndexArc2,GeomIndexArc3,GeomIndexArc4; |
179 | Standard_Boolean MergeArc1,MergeArc2; |
180 | |
181 | for ( i = 1; i <= LengthLine; i++) { |
182 | const TColStd_SequenceOfInteger& S = theTool.Circuit()->RefToEqui(ILine,i); |
183 | |
184 | IndFirst = S.Value(1); |
185 | NewMap.Bind(IndexLast,theGraph->ChangeBasicElt(IndFirst)); |
186 | IndexLast++; |
187 | |
188 | for(j = 2; j <= S.Length(); j++){ |
189 | theGraph->FusionOfBasicElts(IndFirst, |
190 | S.Value(j), |
191 | MergeArc1, |
192 | GeomIndexArc1, |
193 | GeomIndexArc2, |
194 | MergeArc2, |
195 | GeomIndexArc3, |
196 | GeomIndexArc4); |
197 | if(MergeArc1) { |
198 | theTool.BisecFusion(GeomIndexArc1,GeomIndexArc2); |
199 | } |
200 | if(MergeArc2) { |
201 | theTool.BisecFusion(GeomIndexArc3,GeomIndexArc4); |
202 | } |
203 | } |
204 | } |
205 | } |
206 | |
207 | //============================================================================= |
208 | //function : IsDone |
209 | //Purpose : |
210 | //============================================================================= |
47cbf134 |
211 | Standard_Boolean BRepMAT2d_BisectingLocus::IsDone() const |
7fd59977 |
212 | { |
213 | return isDone; |
214 | } |
215 | |
216 | //============================================================================= |
217 | //function : Graph |
218 | // |
219 | //============================================================================= |
47cbf134 |
220 | Handle(MAT_Graph) BRepMAT2d_BisectingLocus::Graph() const |
7fd59977 |
221 | { |
222 | return theGraph; |
223 | } |
224 | |
225 | //============================================================================= |
226 | //function : NumberOfContours |
227 | // |
228 | //============================================================================= |
47cbf134 |
229 | Standard_Integer BRepMAT2d_BisectingLocus::NumberOfContours () const |
7fd59977 |
230 | { |
231 | return nbContours; |
232 | } |
233 | |
234 | //============================================================================= |
235 | //function : NumberOfElts |
236 | // |
237 | //============================================================================= |
47cbf134 |
238 | Standard_Integer BRepMAT2d_BisectingLocus::NumberOfElts |
7fd59977 |
239 | (const Standard_Integer IndLine) const |
240 | { |
241 | return theTool.Circuit()->LineLength(IndLine); |
242 | } |
243 | |
244 | //============================================================================= |
245 | //function : NumberOfSect |
246 | // |
247 | //============================================================================= |
47cbf134 |
248 | Standard_Integer BRepMAT2d_BisectingLocus::NumberOfSections |
7fd59977 |
249 | (const Standard_Integer IndLine, |
250 | const Standard_Integer Index ) |
251 | const |
252 | { |
253 | MAT2d_BiInt B(IndLine,Index); |
254 | return nbSect(B); |
255 | } |
256 | |
257 | //============================================================================= |
258 | //function : BasicElt |
259 | // |
260 | //============================================================================= |
47cbf134 |
261 | Handle(MAT_BasicElt) BRepMAT2d_BisectingLocus::BasicElt |
7fd59977 |
262 | (const Standard_Integer IndLine, |
263 | const Standard_Integer Index ) |
264 | const |
265 | { |
266 | Standard_Integer i; |
267 | Standard_Integer Ind = Index; |
268 | |
269 | for (i = 1 ; i < IndLine ; i++){ |
270 | Ind = Ind + theTool.Circuit()->LineLength(i); |
271 | } |
272 | return theGraph->BasicElt(Ind); |
273 | } |
274 | |
275 | |
276 | //============================================================================= |
277 | //function : GeomBis |
278 | // |
279 | //============================================================================= |
47cbf134 |
280 | Bisector_Bisec BRepMAT2d_BisectingLocus::GeomBis (const Handle(MAT_Arc)& anArc, |
7fd59977 |
281 | Standard_Boolean& Reverse) |
282 | const |
283 | { |
284 | Reverse = Standard_False; |
285 | |
5b111128 |
286 | Handle(Geom2d_Curve) Bis (theTool.GeomBis(anArc->GeomIndex()).Value()); |
7fd59977 |
287 | |
288 | if (Bis->FirstParameter() <= -Precision::Infinite()) { |
289 | Reverse = Standard_True; |
290 | } |
291 | else if (Bis->LastParameter() < Precision::Infinite()) { |
292 | gp_Pnt2d PF = Bis->Value(Bis->FirstParameter()); |
293 | gp_Pnt2d PL = Bis->Value(Bis->LastParameter()); |
294 | gp_Pnt2d PNode = GeomElt(anArc->FirstNode()); |
295 | if (PNode.SquareDistance(PF) > PNode.SquareDistance(PL)) |
296 | Reverse = Standard_True; |
297 | } |
298 | return theTool.GeomBis(anArc->GeomIndex()); |
299 | } |
300 | |
301 | //============================================================================= |
302 | //function : GeomElt |
303 | // |
304 | //============================================================================= |
47cbf134 |
305 | Handle(Geom2d_Geometry) BRepMAT2d_BisectingLocus::GeomElt |
7fd59977 |
306 | (const Handle(MAT_BasicElt)& aBasicElt) const |
307 | { |
308 | return theTool.GeomElt(aBasicElt->GeomIndex()); |
309 | } |
310 | |
311 | |
312 | //============================================================================= |
313 | //function : GeomElt |
314 | // |
315 | //============================================================================= |
47cbf134 |
316 | gp_Pnt2d BRepMAT2d_BisectingLocus::GeomElt(const Handle(MAT_Node)& aNode) const |
7fd59977 |
317 | { |
318 | return theTool.GeomPnt(aNode->GeomIndex()); |
319 | } |
320 | |
321 | |
322 | //============================================================================= |
323 | //function : CutSketch |
324 | // |
325 | //============================================================================= |
326 | static void CutSketch (MAT2d_SequenceOfSequenceOfGeometry& Figure, |
327 | MAT2d_DataMapOfBiIntInteger& NbSect) |
328 | { |
329 | MAT2d_CutCurve Cuter; |
330 | Standard_Integer i,j,k,ico; |
331 | Standard_Integer ICurveInit; |
332 | Standard_Integer NbSection; |
333 | |
334 | for ( i = 1; i <= Figure.Length(); i++) { |
335 | TColGeom2d_SequenceOfGeometry& Contour = Figure.ChangeValue(i); |
336 | ICurveInit = 0; |
337 | |
338 | for ( j = 1; j <= Contour.Length(); j++) { |
339 | ICurveInit++; |
340 | Cuter.Perform(Handle(Geom2d_Curve)::DownCast(Contour.ChangeValue(j))); |
341 | NbSection = 1; |
342 | if (!Cuter.UnModified()) { |
343 | ico = j; |
344 | NbSection = Cuter.NbCurves(); |
345 | for ( k = 1; k <= NbSection; k++) { |
346 | Contour.InsertAfter(j,Cuter.Value(k)); |
347 | j++; |
348 | } |
349 | Contour.Remove(ico); |
350 | j--; |
351 | } |
352 | MAT2d_BiInt B(i,ICurveInit); |
353 | NbSect.Bind(B,NbSection); |
354 | } |
355 | } |
356 | } |
357 | |