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