1 // Created on: 1993-07-13
2 // Created by: Yves FRICAUD
3 // Copyright (c) 1993-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.
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>
39 #include <Standard_OutOfRange.hxx>
40 #include <TColGeom2d_SequenceOfGeometry.hxx>
42 static void CutSketch (MAT2d_SequenceOfSequenceOfGeometry& Figure,
43 MAT2d_DataMapOfBiIntInteger& NbSect);
46 //=============================================================================
47 //function : BRepMAT2d_BisectingLocus
48 //purpose : Constructeur vide.
49 //=============================================================================
50 BRepMAT2d_BisectingLocus::BRepMAT2d_BisectingLocus()
55 //=============================================================================
57 //purpose : Calcul de la carte des lieux bisecteurs sur le contour defini par
59 //=============================================================================
60 void BRepMAT2d_BisectingLocus::Compute(BRepMAT2d_Explorer& anExplo,
61 const Standard_Integer IndexLine,
63 const GeomAbs_JoinType aJoinType,
64 const Standard_Boolean IsOpenResult)
66 MAT2d_Mat2d TheMAT( IsOpenResult );
67 Handle(MAT_ListOfBisector) TheRoots = new MAT_ListOfBisector();
68 MAT2d_SequenceOfSequenceOfGeometry Figure;
72 nbContours = anExplo.NumberOfContours();
74 //---------------------------------
75 // Lecture des donnees de anExplo.
76 //---------------------------------
77 for (i = 1; i <= anExplo.NumberOfContours(); i++) {
78 TColGeom2d_SequenceOfGeometry Line;
80 for (anExplo.Init(i); anExplo.More(); anExplo.Next()) {
81 Figure.ChangeValue(i).Append(anExplo.Value());
85 //-----------------------
86 // Decoupage des courbes.
87 //-----------------------
88 CutSketch(Figure,nbSect);
90 //----------------------------------------------------------
91 // Construction du circuit sur lequel est calcule la carte.
92 //----------------------------------------------------------
93 Handle(MAT2d_Circuit) ACircuit = new MAT2d_Circuit(aJoinType, IsOpenResult);
94 // Modified by Sergey KHROMOV - Wed Mar 6 17:43:47 2002 Begin
95 // ACircuit->Perform(Figure,IndexLine,(aSide == MAT_Left));
96 ACircuit->Perform(Figure,anExplo.GetIsClosed(), IndexLine,(aSide == MAT_Left));
97 // Modified by Sergey KHROMOV - Wed Mar 6 17:43:48 2002 End
99 // -----------------------
100 // Initialistion du Tool.
101 // -----------------------
102 theTool.Sense(aSide);
103 theTool.SetJoinType(aJoinType);
104 theTool.InitItems(ACircuit);
106 // --------------------------------------------
107 // Initialisation et execution de l algorithme.
108 // --------------------------------------------
110 TheMAT.CreateMatOpen(theTool);
112 TheMAT.CreateMat(theTool);
114 isDone = TheMAT.IsDone(); if (!isDone) return;
116 // ----------------------------------------------------------------
117 // Recuperation du resultat de l algorithme et creation du graphe.
118 // ----------------------------------------------------------------
119 for (TheMAT.Init(); TheMAT.More(); TheMAT.Next()) {
120 TheRoots->BackAdd(TheMAT.Bisector());
123 theGraph = new MAT_Graph();
124 theGraph->Perform(TheMAT.SemiInfinite(),
126 theTool.NumberOfItems(),
127 TheMAT.NumberOfBisectors());
129 //-----------------------------------------------------------------------
130 // Fusion des elements de base doubles si plusieurs lignes dans Exploset.
131 //-----------------------------------------------------------------------
132 if (anExplo.NumberOfContours() > 1) {
133 MAT_DataMapOfIntegerBasicElt NewMap;
134 Standard_Integer IndexLast = 1;
136 //-----------------------------------------------------------------------
137 // Construction de NewMap dont les elements sont ordonnes suivant les
138 // lignes du contour et qui ne contient pas d element dupliques.
139 // em meme temps fusion des arcs dupliques et mise a jour des noeuds.
140 //-----------------------------------------------------------------------
141 for ( i = 1; i <= anExplo.NumberOfContours(); i++) {
142 RenumerationAndFusion(i,
143 theTool.Circuit()->LineLength(i),
148 //-----------------------------------------------------------------------
149 // Chargement dans le graph de la nouvelle map.
150 // et compactage de la map des Arcs (ie Elimination des trous du a la
151 // fusion d arcs ).et de celle des Nodes.
152 //-----------------------------------------------------------------------
153 theGraph->ChangeBasicElts(NewMap);
154 theGraph->CompactArcs();
155 theGraph->CompactNodes();
159 //=============================================================================
160 //function : RenumerationAndFusion
162 //=============================================================================
163 void BRepMAT2d_BisectingLocus::RenumerationAndFusion
164 (const Standard_Integer ILine,
165 const Standard_Integer LengthLine,
166 Standard_Integer& IndexLast,
167 MAT_DataMapOfIntegerBasicElt& NewMap)
169 Standard_Integer IndFirst;
170 Standard_Integer i,j;
171 Standard_Integer GeomIndexArc1,GeomIndexArc2,GeomIndexArc3,GeomIndexArc4;
172 Standard_Boolean MergeArc1,MergeArc2;
174 for ( i = 1; i <= LengthLine; i++) {
175 const TColStd_SequenceOfInteger& S = theTool.Circuit()->RefToEqui(ILine,i);
177 IndFirst = S.Value(1);
178 NewMap.Bind(IndexLast,theGraph->ChangeBasicElt(IndFirst));
181 for(j = 2; j <= S.Length(); j++){
182 theGraph->FusionOfBasicElts(IndFirst,
191 theTool.BisecFusion(GeomIndexArc1,GeomIndexArc2);
194 theTool.BisecFusion(GeomIndexArc3,GeomIndexArc4);
200 //=============================================================================
203 //=============================================================================
204 Standard_Boolean BRepMAT2d_BisectingLocus::IsDone() const
209 //=============================================================================
212 //=============================================================================
213 Handle(MAT_Graph) BRepMAT2d_BisectingLocus::Graph() const
218 //=============================================================================
219 //function : NumberOfContours
221 //=============================================================================
222 Standard_Integer BRepMAT2d_BisectingLocus::NumberOfContours () const
227 //=============================================================================
228 //function : NumberOfElts
230 //=============================================================================
231 Standard_Integer BRepMAT2d_BisectingLocus::NumberOfElts
232 (const Standard_Integer IndLine) const
234 return theTool.Circuit()->LineLength(IndLine);
237 //=============================================================================
238 //function : NumberOfSect
240 //=============================================================================
241 Standard_Integer BRepMAT2d_BisectingLocus::NumberOfSections
242 (const Standard_Integer IndLine,
243 const Standard_Integer Index )
246 MAT2d_BiInt B(IndLine,Index);
250 //=============================================================================
251 //function : BasicElt
253 //=============================================================================
254 Handle(MAT_BasicElt) BRepMAT2d_BisectingLocus::BasicElt
255 (const Standard_Integer IndLine,
256 const Standard_Integer Index )
260 Standard_Integer Ind = Index;
262 for (i = 1 ; i < IndLine ; i++){
263 Ind = Ind + theTool.Circuit()->LineLength(i);
265 return theGraph->BasicElt(Ind);
269 //=============================================================================
272 //=============================================================================
273 Bisector_Bisec BRepMAT2d_BisectingLocus::GeomBis (const Handle(MAT_Arc)& anArc,
274 Standard_Boolean& Reverse)
277 Reverse = Standard_False;
279 Handle(Geom2d_Curve) Bis = theTool.GeomBis(anArc->GeomIndex()).Value();
281 if (Bis->FirstParameter() <= -Precision::Infinite()) {
282 Reverse = Standard_True;
284 else if (Bis->LastParameter() < Precision::Infinite()) {
285 gp_Pnt2d PF = Bis->Value(Bis->FirstParameter());
286 gp_Pnt2d PL = Bis->Value(Bis->LastParameter());
287 gp_Pnt2d PNode = GeomElt(anArc->FirstNode());
288 if (PNode.SquareDistance(PF) > PNode.SquareDistance(PL))
289 Reverse = Standard_True;
291 return theTool.GeomBis(anArc->GeomIndex());
294 //=============================================================================
297 //=============================================================================
298 Handle(Geom2d_Geometry) BRepMAT2d_BisectingLocus::GeomElt
299 (const Handle(MAT_BasicElt)& aBasicElt) const
301 return theTool.GeomElt(aBasicElt->GeomIndex());
305 //=============================================================================
308 //=============================================================================
309 gp_Pnt2d BRepMAT2d_BisectingLocus::GeomElt(const Handle(MAT_Node)& aNode) const
311 return theTool.GeomPnt(aNode->GeomIndex());
315 //=============================================================================
316 //function : CutSketch
318 //=============================================================================
319 static void CutSketch (MAT2d_SequenceOfSequenceOfGeometry& Figure,
320 MAT2d_DataMapOfBiIntInteger& NbSect)
322 MAT2d_CutCurve Cuter;
323 Standard_Integer i,j,k,ico;
324 Standard_Integer ICurveInit;
325 Standard_Integer NbSection;
327 for ( i = 1; i <= Figure.Length(); i++) {
328 TColGeom2d_SequenceOfGeometry& Contour = Figure.ChangeValue(i);
331 for ( j = 1; j <= Contour.Length(); j++) {
333 Cuter.Perform(Handle(Geom2d_Curve)::DownCast(Contour.ChangeValue(j)));
335 if (!Cuter.UnModified()) {
337 NbSection = Cuter.NbCurves();
338 for ( k = 1; k <= NbSection; k++) {
339 Contour.InsertAfter(j,Cuter.Value(k));
345 MAT2d_BiInt B(i,ICurveInit);
346 NbSect.Bind(B,NbSection);