summaryrefslogtreecommitdiff
path: root/inc/MAT2d_BisectingLocus.gxx
blob: 63e644cc5c4efe31d99eb92c7b1ae42fdd93f865 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
// File:	MAT2d_BisectingLocus.gxx
// Created:	Tue Jul 13 15:10:17 1993
// Author:	Yves FRICAUD
//		<yfr@phylox>


# include <MAT2d_Mat2d.hxx>
# include <MAT2d_Tool2d.hxx>
# include <MAT2d_Circuit.hxx>
# include <MAT2d_CutCurve.hxx>
# include <MAT2d_BiInt.hxx>
# include <MAT2d_SequenceOfSequenceOfGeometry.hxx>
# include <MAT_Graph.hxx>
# include <MAT_Arc.hxx>
# include <MAT_BasicElt.hxx>
# include <MAT_Node.hxx>
# include <MAT_Bisector.hxx>
# include <MAT_ListOfBisector.hxx>
# include <MAT_DataMapOfIntegerBasicElt.hxx>
# include <MAT_DataMapIteratorOfDataMapOfIntegerBasicElt.hxx>
# include <Geom2d_Curve.hxx>
# include <gp_Pnt2d.hxx>
# include <TColGeom2d_SequenceOfGeometry.hxx>
# include <Precision.hxx>

#include <Standard_OutOfRange.hxx>

static void CutSketch (MAT2d_SequenceOfSequenceOfGeometry&    Figure,
		       MAT2d_DataMapOfBiIntInteger&           NbSect);


//=============================================================================
//function : MAT2d_BisectingLocus
//purpose  : Constructeur vide.
//=============================================================================
MAT2d_BisectingLocus::MAT2d_BisectingLocus()
{
}


//=============================================================================
//function : Compute
//purpose  : Calcul de la carte des lieux bisecteurs sur le contour defini par
//           <anExplo>.
//=============================================================================
void MAT2d_BisectingLocus::Compute(      Explorer&        anExplo,
				   const Standard_Integer IndexLine,
				   const MAT_Side         aSide    ) 
{
  MAT2d_Mat2d                        TheMAT;
  Handle(MAT_ListOfBisector)         TheRoots = new MAT_ListOfBisector();
  MAT2d_SequenceOfSequenceOfGeometry Figure;
  Standard_Integer                   i;

  nbSect.Clear();
  nbContours = anExplo.NumberOfContours();

  //---------------------------------
  // Lecture des donnees de anExplo.
  //---------------------------------
  for (i = 1; i <= anExplo.NumberOfContours(); i++) {
    TColGeom2d_SequenceOfGeometry      Line;
    Figure.Append(Line);
    for (anExplo.Init(i); anExplo.More(); anExplo.Next()) {
      Figure.ChangeValue(i).Append(anExplo.Value());
    }
  }

  //-----------------------
  // Decoupage des courbes.
  //-----------------------
  CutSketch(Figure,nbSect);

  //----------------------------------------------------------
  // Construction du circuit sur lequel est calcule la carte.
  //----------------------------------------------------------
  Handle(MAT2d_Circuit) ACircuit = new MAT2d_Circuit();
//  Modified by Sergey KHROMOV - Wed Mar  6 17:43:47 2002 Begin
//   ACircuit->Perform(Figure,IndexLine,(aSide == MAT_Left));
  ACircuit->Perform(Figure,anExplo.GetIsClosed(), IndexLine,(aSide == MAT_Left));
//  Modified by Sergey KHROMOV - Wed Mar  6 17:43:48 2002 End

  // -----------------------
  // Initialistion du Tool.
  // -----------------------
  theTool.Sense(aSide);
  theTool.InitItems(ACircuit);

  // --------------------------------------------
  // Initialisation et execution de l algorithme.
  // --------------------------------------------
  TheMAT.CreateMat(theTool);

  isDone = TheMAT.IsDone(); if (!isDone) return;

  // ----------------------------------------------------------------
  // Recuperation du resultat de l algorithme et creation du graphe.
  // ----------------------------------------------------------------
  for (TheMAT.Init(); TheMAT.More(); TheMAT.Next()) {
    TheRoots->BackAdd(TheMAT.Bisector());
  }

  theGraph = new MAT_Graph();
  theGraph->Perform(TheMAT.SemiInfinite(),
		    TheRoots, 
		    theTool.NumberOfItems(), 
		    TheMAT.NumberOfBisectors());

  //-----------------------------------------------------------------------
  // Fusion des elements de base doubles si plusieurs lignes dans Exploset.
  //-----------------------------------------------------------------------
  if (anExplo.NumberOfContours() > 1) {
    MAT_DataMapOfIntegerBasicElt NewMap;
    Standard_Integer             IndexLast  = 1;

    //-----------------------------------------------------------------------
    // Construction de NewMap dont les elements sont ordonnes suivant les
    // lignes du contour et qui ne contient pas d element dupliques.
    // em meme temps fusion des arcs dupliques et mise a jour des noeuds.
    //-----------------------------------------------------------------------
    for ( i = 1; i <= anExplo.NumberOfContours(); i++) {
      RenumerationAndFusion(i,
			    theTool.Circuit()->LineLength(i),
			    IndexLast,
			    NewMap);
    }

    //-----------------------------------------------------------------------
    // Chargement dans le graph de la nouvelle map.
    // et compactage de la map des Arcs (ie  Elimination des trous du a la
    // fusion d arcs ).et  de celle des Nodes.
    //-----------------------------------------------------------------------
    theGraph->ChangeBasicElts(NewMap);    
    theGraph->CompactArcs();
    theGraph->CompactNodes();
  }
}

//=============================================================================
//function : RenumerationAndFusion
//purpose  :
//=============================================================================
void MAT2d_BisectingLocus::RenumerationAndFusion
  (const Standard_Integer              ILine,
   const Standard_Integer              LengthLine,
         Standard_Integer&             IndexLast,
         MAT_DataMapOfIntegerBasicElt& NewMap)
{
  Standard_Integer IndFirst;
  Standard_Integer i,j;
  Standard_Integer GeomIndexArc1,GeomIndexArc2,GeomIndexArc3,GeomIndexArc4;
  Standard_Boolean MergeArc1,MergeArc2;

  for ( i = 1; i <= LengthLine; i++) {
    const TColStd_SequenceOfInteger& S = theTool.Circuit()->RefToEqui(ILine,i);

    IndFirst = S.Value(1);
    NewMap.Bind(IndexLast,theGraph->ChangeBasicElt(IndFirst));
    IndexLast++;

    for(j = 2; j <= S.Length(); j++){
      theGraph->FusionOfBasicElts(IndFirst,
				  S.Value(j),
				  MergeArc1,
				  GeomIndexArc1,
				  GeomIndexArc2,
				  MergeArc2,
				  GeomIndexArc3,
				  GeomIndexArc4);
      if(MergeArc1) {
	theTool.BisecFusion(GeomIndexArc1,GeomIndexArc2);
      }
      if(MergeArc2) {
	theTool.BisecFusion(GeomIndexArc3,GeomIndexArc4);
      }
    }
  }
}

//=============================================================================
//function : IsDone
//Purpose  : 
//=============================================================================
Standard_Boolean MAT2d_BisectingLocus::IsDone() const
{
  return isDone;
}

//=============================================================================
//function : Graph
//
//=============================================================================
Handle(MAT_Graph) MAT2d_BisectingLocus::Graph() const
{
  return theGraph;
}

//=============================================================================
//function : NumberOfContours
//
//=============================================================================
Standard_Integer MAT2d_BisectingLocus::NumberOfContours () const
{
  return nbContours;
}

//=============================================================================
//function : NumberOfElts
//
//=============================================================================
Standard_Integer MAT2d_BisectingLocus::NumberOfElts 
 (const Standard_Integer IndLine) const
{
  return theTool.Circuit()->LineLength(IndLine);
}

//=============================================================================
//function : NumberOfSect
//
//=============================================================================
Standard_Integer MAT2d_BisectingLocus::NumberOfSections
(const Standard_Integer IndLine,
 const Standard_Integer Index  ) 
     const
{
  MAT2d_BiInt B(IndLine,Index);
  return nbSect(B);
}

//=============================================================================
//function : BasicElt
//
//=============================================================================
Handle(MAT_BasicElt) MAT2d_BisectingLocus::BasicElt 
       (const Standard_Integer IndLine,
	const Standard_Integer Index  ) 
     const
{
  Standard_Integer i;
  Standard_Integer Ind = Index;

  for (i = 1 ; i < IndLine ; i++){
    Ind = Ind + theTool.Circuit()->LineLength(i);
  }
  return theGraph->BasicElt(Ind);
}


//=============================================================================
//function : GeomBis
//
//=============================================================================
Bisector_Bisec  MAT2d_BisectingLocus::GeomBis (const Handle(MAT_Arc)&  anArc,
					             Standard_Boolean& Reverse) 
const 
{
  Reverse = Standard_False;

  Handle(Geom2d_Curve) Bis = theTool.GeomBis(anArc->GeomIndex()).Value();

  if (Bis->FirstParameter() <= -Precision::Infinite()) {
    Reverse = Standard_True;
  }
  else if (Bis->LastParameter() < Precision::Infinite()) {
    gp_Pnt2d PF    = Bis->Value(Bis->FirstParameter());
    gp_Pnt2d PL    = Bis->Value(Bis->LastParameter());
    gp_Pnt2d PNode = GeomElt(anArc->FirstNode());
    if (PNode.SquareDistance(PF) > PNode.SquareDistance(PL)) 
      Reverse = Standard_True;
  }
  return theTool.GeomBis(anArc->GeomIndex());
}

//=============================================================================
//function : GeomElt
//
//=============================================================================
Handle(Geom2d_Geometry)  MAT2d_BisectingLocus::GeomElt
                           (const Handle(MAT_BasicElt)& aBasicElt) const
{
  return  theTool.GeomElt(aBasicElt->GeomIndex());
}


//=============================================================================
//function : GeomElt
//
//=============================================================================
gp_Pnt2d  MAT2d_BisectingLocus::GeomElt(const Handle(MAT_Node)& aNode) const
{
  return theTool.GeomPnt(aNode->GeomIndex());
}


//=============================================================================
//function : CutSketch
//
//=============================================================================
static void CutSketch (MAT2d_SequenceOfSequenceOfGeometry&    Figure,
		       MAT2d_DataMapOfBiIntInteger&           NbSect)
{
  MAT2d_CutCurve   Cuter;
  Standard_Integer i,j,k,ico;
  Standard_Integer ICurveInit;
  Standard_Integer NbSection;

  for ( i = 1; i <= Figure.Length(); i++) {
    TColGeom2d_SequenceOfGeometry& Contour = Figure.ChangeValue(i);  
    ICurveInit = 0;

    for ( j = 1; j <= Contour.Length(); j++) {
      ICurveInit++;
      Cuter.Perform(Handle(Geom2d_Curve)::DownCast(Contour.ChangeValue(j)));
      NbSection = 1;
      if (!Cuter.UnModified()) {
	ico    = j;
	NbSection = Cuter.NbCurves();
	for ( k = 1; k <= NbSection; k++) {
	  Contour.InsertAfter(j,Cuter.Value(k));
	  j++;
	}
	Contour.Remove(ico);
	j--;
      }
      MAT2d_BiInt B(i,ICurveInit);
      NbSect.Bind(B,NbSection);
    }
  }
}