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 Standard_Boolean IsOpenResult)
64 Handle(MAT_ListOfBisector) TheRoots = new MAT_ListOfBisector();
65 MAT2d_SequenceOfSequenceOfGeometry Figure;
69 nbContours = anExplo.NumberOfContours();
71 //---------------------------------
72 // Lecture des donnees de anExplo.
73 //---------------------------------
74 for (i = 1; i <= anExplo.NumberOfContours(); i++) {
75 TColGeom2d_SequenceOfGeometry Line;
77 for (anExplo.Init(i); anExplo.More(); anExplo.Next()) {
78 Figure.ChangeValue(i).Append(anExplo.Value());
82 //-----------------------
83 // Decoupage des courbes.
84 //-----------------------
85 CutSketch(Figure,nbSect);
87 //----------------------------------------------------------
88 // Construction du circuit sur lequel est calcule la carte.
89 //----------------------------------------------------------
90 Handle(MAT2d_Circuit) ACircuit = new MAT2d_Circuit(IsOpenResult);
91 // Modified by Sergey KHROMOV - Wed Mar 6 17:43:47 2002 Begin
92 // ACircuit->Perform(Figure,IndexLine,(aSide == MAT_Left));
93 ACircuit->Perform(Figure,anExplo.GetIsClosed(), IndexLine,(aSide == MAT_Left));
94 // Modified by Sergey KHROMOV - Wed Mar 6 17:43:48 2002 End
96 // -----------------------
97 // Initialistion du Tool.
98 // -----------------------
100 theTool.InitItems(ACircuit);
102 // --------------------------------------------
103 // Initialisation et execution de l algorithme.
104 // --------------------------------------------
105 TheMAT.CreateMat(theTool);
107 isDone = TheMAT.IsDone(); if (!isDone) return;
109 // ----------------------------------------------------------------
110 // Recuperation du resultat de l algorithme et creation du graphe.
111 // ----------------------------------------------------------------
112 for (TheMAT.Init(); TheMAT.More(); TheMAT.Next()) {
113 TheRoots->BackAdd(TheMAT.Bisector());
116 theGraph = new MAT_Graph();
117 theGraph->Perform(TheMAT.SemiInfinite(),
119 theTool.NumberOfItems(),
120 TheMAT.NumberOfBisectors());
122 //-----------------------------------------------------------------------
123 // Fusion des elements de base doubles si plusieurs lignes dans Exploset.
124 //-----------------------------------------------------------------------
125 if (anExplo.NumberOfContours() > 1) {
126 MAT_DataMapOfIntegerBasicElt NewMap;
127 Standard_Integer IndexLast = 1;
129 //-----------------------------------------------------------------------
130 // Construction de NewMap dont les elements sont ordonnes suivant les
131 // lignes du contour et qui ne contient pas d element dupliques.
132 // em meme temps fusion des arcs dupliques et mise a jour des noeuds.
133 //-----------------------------------------------------------------------
134 for ( i = 1; i <= anExplo.NumberOfContours(); i++) {
135 RenumerationAndFusion(i,
136 theTool.Circuit()->LineLength(i),
141 //-----------------------------------------------------------------------
142 // Chargement dans le graph de la nouvelle map.
143 // et compactage de la map des Arcs (ie Elimination des trous du a la
144 // fusion d arcs ).et de celle des Nodes.
145 //-----------------------------------------------------------------------
146 theGraph->ChangeBasicElts(NewMap);
147 theGraph->CompactArcs();
148 theGraph->CompactNodes();
152 //=============================================================================
153 //function : RenumerationAndFusion
155 //=============================================================================
156 void BRepMAT2d_BisectingLocus::RenumerationAndFusion
157 (const Standard_Integer ILine,
158 const Standard_Integer LengthLine,
159 Standard_Integer& IndexLast,
160 MAT_DataMapOfIntegerBasicElt& NewMap)
162 Standard_Integer IndFirst;
163 Standard_Integer i,j;
164 Standard_Integer GeomIndexArc1,GeomIndexArc2,GeomIndexArc3,GeomIndexArc4;
165 Standard_Boolean MergeArc1,MergeArc2;
167 for ( i = 1; i <= LengthLine; i++) {
168 const TColStd_SequenceOfInteger& S = theTool.Circuit()->RefToEqui(ILine,i);
170 IndFirst = S.Value(1);
171 NewMap.Bind(IndexLast,theGraph->ChangeBasicElt(IndFirst));
174 for(j = 2; j <= S.Length(); j++){
175 theGraph->FusionOfBasicElts(IndFirst,
184 theTool.BisecFusion(GeomIndexArc1,GeomIndexArc2);
187 theTool.BisecFusion(GeomIndexArc3,GeomIndexArc4);
193 //=============================================================================
196 //=============================================================================
197 Standard_Boolean BRepMAT2d_BisectingLocus::IsDone() const
202 //=============================================================================
205 //=============================================================================
206 Handle(MAT_Graph) BRepMAT2d_BisectingLocus::Graph() const
211 //=============================================================================
212 //function : NumberOfContours
214 //=============================================================================
215 Standard_Integer BRepMAT2d_BisectingLocus::NumberOfContours () const
220 //=============================================================================
221 //function : NumberOfElts
223 //=============================================================================
224 Standard_Integer BRepMAT2d_BisectingLocus::NumberOfElts
225 (const Standard_Integer IndLine) const
227 return theTool.Circuit()->LineLength(IndLine);
230 //=============================================================================
231 //function : NumberOfSect
233 //=============================================================================
234 Standard_Integer BRepMAT2d_BisectingLocus::NumberOfSections
235 (const Standard_Integer IndLine,
236 const Standard_Integer Index )
239 MAT2d_BiInt B(IndLine,Index);
243 //=============================================================================
244 //function : BasicElt
246 //=============================================================================
247 Handle(MAT_BasicElt) BRepMAT2d_BisectingLocus::BasicElt
248 (const Standard_Integer IndLine,
249 const Standard_Integer Index )
253 Standard_Integer Ind = Index;
255 for (i = 1 ; i < IndLine ; i++){
256 Ind = Ind + theTool.Circuit()->LineLength(i);
258 return theGraph->BasicElt(Ind);
262 //=============================================================================
265 //=============================================================================
266 Bisector_Bisec BRepMAT2d_BisectingLocus::GeomBis (const Handle(MAT_Arc)& anArc,
267 Standard_Boolean& Reverse)
270 Reverse = Standard_False;
272 Handle(Geom2d_Curve) Bis = theTool.GeomBis(anArc->GeomIndex()).Value();
274 if (Bis->FirstParameter() <= -Precision::Infinite()) {
275 Reverse = Standard_True;
277 else if (Bis->LastParameter() < Precision::Infinite()) {
278 gp_Pnt2d PF = Bis->Value(Bis->FirstParameter());
279 gp_Pnt2d PL = Bis->Value(Bis->LastParameter());
280 gp_Pnt2d PNode = GeomElt(anArc->FirstNode());
281 if (PNode.SquareDistance(PF) > PNode.SquareDistance(PL))
282 Reverse = Standard_True;
284 return theTool.GeomBis(anArc->GeomIndex());
287 //=============================================================================
290 //=============================================================================
291 Handle(Geom2d_Geometry) BRepMAT2d_BisectingLocus::GeomElt
292 (const Handle(MAT_BasicElt)& aBasicElt) const
294 return theTool.GeomElt(aBasicElt->GeomIndex());
298 //=============================================================================
301 //=============================================================================
302 gp_Pnt2d BRepMAT2d_BisectingLocus::GeomElt(const Handle(MAT_Node)& aNode) const
304 return theTool.GeomPnt(aNode->GeomIndex());
308 //=============================================================================
309 //function : CutSketch
311 //=============================================================================
312 static void CutSketch (MAT2d_SequenceOfSequenceOfGeometry& Figure,
313 MAT2d_DataMapOfBiIntInteger& NbSect)
315 MAT2d_CutCurve Cuter;
316 Standard_Integer i,j,k,ico;
317 Standard_Integer ICurveInit;
318 Standard_Integer NbSection;
320 for ( i = 1; i <= Figure.Length(); i++) {
321 TColGeom2d_SequenceOfGeometry& Contour = Figure.ChangeValue(i);
324 for ( j = 1; j <= Contour.Length(); j++) {
326 Cuter.Perform(Handle(Geom2d_Curve)::DownCast(Contour.ChangeValue(j)));
328 if (!Cuter.UnModified()) {
330 NbSection = Cuter.NbCurves();
331 for ( k = 1; k <= NbSection; k++) {
332 Contour.InsertAfter(j,Cuter.Value(k));
338 MAT2d_BiInt B(i,ICurveInit);
339 NbSect.Bind(B,NbSection);