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.
17 # include <BRepMAT2d_BisectingLocus.ixx>
19 # include <MAT2d_Mat2d.hxx>
20 # include <MAT2d_Tool2d.hxx>
21 # include <MAT2d_Circuit.hxx>
22 # include <MAT2d_CutCurve.hxx>
23 # include <MAT2d_BiInt.hxx>
24 # include <MAT2d_SequenceOfSequenceOfGeometry.hxx>
25 # include <MAT_Graph.hxx>
26 # include <MAT_Arc.hxx>
27 # include <MAT_BasicElt.hxx>
28 # include <MAT_Node.hxx>
29 # include <MAT_Bisector.hxx>
30 # include <MAT_ListOfBisector.hxx>
31 # include <MAT_DataMapOfIntegerBasicElt.hxx>
32 # include <MAT_DataMapIteratorOfDataMapOfIntegerBasicElt.hxx>
33 # include <Geom2d_Curve.hxx>
34 # include <gp_Pnt2d.hxx>
35 # include <TColGeom2d_SequenceOfGeometry.hxx>
36 # include <Precision.hxx>
38 #include <Standard_OutOfRange.hxx>
40 static void CutSketch (MAT2d_SequenceOfSequenceOfGeometry& Figure,
41 MAT2d_DataMapOfBiIntInteger& NbSect);
44 //=============================================================================
45 //function : BRepMAT2d_BisectingLocus
46 //purpose : Constructeur vide.
47 //=============================================================================
48 BRepMAT2d_BisectingLocus::BRepMAT2d_BisectingLocus()
53 //=============================================================================
55 //purpose : Calcul de la carte des lieux bisecteurs sur le contour defini par
57 //=============================================================================
58 void BRepMAT2d_BisectingLocus::Compute(BRepMAT2d_Explorer& anExplo,
59 const Standard_Integer IndexLine,
61 const GeomAbs_JoinType aJoinType,
62 const Standard_Boolean IsOpenResult)
64 MAT2d_Mat2d TheMAT( IsOpenResult );
65 Handle(MAT_ListOfBisector) TheRoots = new MAT_ListOfBisector();
66 MAT2d_SequenceOfSequenceOfGeometry Figure;
70 nbContours = anExplo.NumberOfContours();
72 //---------------------------------
73 // Lecture des donnees de anExplo.
74 //---------------------------------
75 for (i = 1; i <= anExplo.NumberOfContours(); i++) {
76 TColGeom2d_SequenceOfGeometry Line;
78 for (anExplo.Init(i); anExplo.More(); anExplo.Next()) {
79 Figure.ChangeValue(i).Append(anExplo.Value());
83 //-----------------------
84 // Decoupage des courbes.
85 //-----------------------
86 CutSketch(Figure,nbSect);
88 //----------------------------------------------------------
89 // Construction du circuit sur lequel est calcule la carte.
90 //----------------------------------------------------------
91 Handle(MAT2d_Circuit) ACircuit = new MAT2d_Circuit(aJoinType, IsOpenResult);
92 // Modified by Sergey KHROMOV - Wed Mar 6 17:43:47 2002 Begin
93 // ACircuit->Perform(Figure,IndexLine,(aSide == MAT_Left));
94 ACircuit->Perform(Figure,anExplo.GetIsClosed(), IndexLine,(aSide == MAT_Left));
95 // Modified by Sergey KHROMOV - Wed Mar 6 17:43:48 2002 End
97 // -----------------------
98 // Initialistion du Tool.
99 // -----------------------
100 theTool.Sense(aSide);
101 theTool.SetJoinType(aJoinType);
102 theTool.InitItems(ACircuit);
104 // --------------------------------------------
105 // Initialisation et execution de l algorithme.
106 // --------------------------------------------
108 TheMAT.CreateMatOpen(theTool);
110 TheMAT.CreateMat(theTool);
112 isDone = TheMAT.IsDone(); if (!isDone) return;
114 // ----------------------------------------------------------------
115 // Recuperation du resultat de l algorithme et creation du graphe.
116 // ----------------------------------------------------------------
117 for (TheMAT.Init(); TheMAT.More(); TheMAT.Next()) {
118 TheRoots->BackAdd(TheMAT.Bisector());
121 theGraph = new MAT_Graph();
122 theGraph->Perform(TheMAT.SemiInfinite(),
124 theTool.NumberOfItems(),
125 TheMAT.NumberOfBisectors());
127 //-----------------------------------------------------------------------
128 // Fusion des elements de base doubles si plusieurs lignes dans Exploset.
129 //-----------------------------------------------------------------------
130 if (anExplo.NumberOfContours() > 1) {
131 MAT_DataMapOfIntegerBasicElt NewMap;
132 Standard_Integer IndexLast = 1;
134 //-----------------------------------------------------------------------
135 // Construction de NewMap dont les elements sont ordonnes suivant les
136 // lignes du contour et qui ne contient pas d element dupliques.
137 // em meme temps fusion des arcs dupliques et mise a jour des noeuds.
138 //-----------------------------------------------------------------------
139 for ( i = 1; i <= anExplo.NumberOfContours(); i++) {
140 RenumerationAndFusion(i,
141 theTool.Circuit()->LineLength(i),
146 //-----------------------------------------------------------------------
147 // Chargement dans le graph de la nouvelle map.
148 // et compactage de la map des Arcs (ie Elimination des trous du a la
149 // fusion d arcs ).et de celle des Nodes.
150 //-----------------------------------------------------------------------
151 theGraph->ChangeBasicElts(NewMap);
152 theGraph->CompactArcs();
153 theGraph->CompactNodes();
157 //=============================================================================
158 //function : RenumerationAndFusion
160 //=============================================================================
161 void BRepMAT2d_BisectingLocus::RenumerationAndFusion
162 (const Standard_Integer ILine,
163 const Standard_Integer LengthLine,
164 Standard_Integer& IndexLast,
165 MAT_DataMapOfIntegerBasicElt& NewMap)
167 Standard_Integer IndFirst;
168 Standard_Integer i,j;
169 Standard_Integer GeomIndexArc1,GeomIndexArc2,GeomIndexArc3,GeomIndexArc4;
170 Standard_Boolean MergeArc1,MergeArc2;
172 for ( i = 1; i <= LengthLine; i++) {
173 const TColStd_SequenceOfInteger& S = theTool.Circuit()->RefToEqui(ILine,i);
175 IndFirst = S.Value(1);
176 NewMap.Bind(IndexLast,theGraph->ChangeBasicElt(IndFirst));
179 for(j = 2; j <= S.Length(); j++){
180 theGraph->FusionOfBasicElts(IndFirst,
189 theTool.BisecFusion(GeomIndexArc1,GeomIndexArc2);
192 theTool.BisecFusion(GeomIndexArc3,GeomIndexArc4);
198 //=============================================================================
201 //=============================================================================
202 Standard_Boolean BRepMAT2d_BisectingLocus::IsDone() const
207 //=============================================================================
210 //=============================================================================
211 Handle(MAT_Graph) BRepMAT2d_BisectingLocus::Graph() const
216 //=============================================================================
217 //function : NumberOfContours
219 //=============================================================================
220 Standard_Integer BRepMAT2d_BisectingLocus::NumberOfContours () const
225 //=============================================================================
226 //function : NumberOfElts
228 //=============================================================================
229 Standard_Integer BRepMAT2d_BisectingLocus::NumberOfElts
230 (const Standard_Integer IndLine) const
232 return theTool.Circuit()->LineLength(IndLine);
235 //=============================================================================
236 //function : NumberOfSect
238 //=============================================================================
239 Standard_Integer BRepMAT2d_BisectingLocus::NumberOfSections
240 (const Standard_Integer IndLine,
241 const Standard_Integer Index )
244 MAT2d_BiInt B(IndLine,Index);
248 //=============================================================================
249 //function : BasicElt
251 //=============================================================================
252 Handle(MAT_BasicElt) BRepMAT2d_BisectingLocus::BasicElt
253 (const Standard_Integer IndLine,
254 const Standard_Integer Index )
258 Standard_Integer Ind = Index;
260 for (i = 1 ; i < IndLine ; i++){
261 Ind = Ind + theTool.Circuit()->LineLength(i);
263 return theGraph->BasicElt(Ind);
267 //=============================================================================
270 //=============================================================================
271 Bisector_Bisec BRepMAT2d_BisectingLocus::GeomBis (const Handle(MAT_Arc)& anArc,
272 Standard_Boolean& Reverse)
275 Reverse = Standard_False;
277 Handle(Geom2d_Curve) Bis = theTool.GeomBis(anArc->GeomIndex()).Value();
279 if (Bis->FirstParameter() <= -Precision::Infinite()) {
280 Reverse = Standard_True;
282 else if (Bis->LastParameter() < Precision::Infinite()) {
283 gp_Pnt2d PF = Bis->Value(Bis->FirstParameter());
284 gp_Pnt2d PL = Bis->Value(Bis->LastParameter());
285 gp_Pnt2d PNode = GeomElt(anArc->FirstNode());
286 if (PNode.SquareDistance(PF) > PNode.SquareDistance(PL))
287 Reverse = Standard_True;
289 return theTool.GeomBis(anArc->GeomIndex());
292 //=============================================================================
295 //=============================================================================
296 Handle(Geom2d_Geometry) BRepMAT2d_BisectingLocus::GeomElt
297 (const Handle(MAT_BasicElt)& aBasicElt) const
299 return theTool.GeomElt(aBasicElt->GeomIndex());
303 //=============================================================================
306 //=============================================================================
307 gp_Pnt2d BRepMAT2d_BisectingLocus::GeomElt(const Handle(MAT_Node)& aNode) const
309 return theTool.GeomPnt(aNode->GeomIndex());
313 //=============================================================================
314 //function : CutSketch
316 //=============================================================================
317 static void CutSketch (MAT2d_SequenceOfSequenceOfGeometry& Figure,
318 MAT2d_DataMapOfBiIntInteger& NbSect)
320 MAT2d_CutCurve Cuter;
321 Standard_Integer i,j,k,ico;
322 Standard_Integer ICurveInit;
323 Standard_Integer NbSection;
325 for ( i = 1; i <= Figure.Length(); i++) {
326 TColGeom2d_SequenceOfGeometry& Contour = Figure.ChangeValue(i);
329 for ( j = 1; j <= Contour.Length(); j++) {
331 Cuter.Perform(Handle(Geom2d_Curve)::DownCast(Contour.ChangeValue(j)));
333 if (!Cuter.UnModified()) {
335 NbSection = Cuter.NbCurves();
336 for ( k = 1; k <= NbSection; k++) {
337 Contour.InsertAfter(j,Cuter.Value(k));
343 MAT2d_BiInt B(i,ICurveInit);
344 NbSect.Bind(B,NbSection);