summaryrefslogtreecommitdiff
path: root/src/MAT/MAT_Zone.cxx
blob: d859e0826177f33f6a991986332dabf8fdeb1c4e (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
// File:	MAT_BasicElt.cxx
// Created:	Wed May  5 10:11:24 1993
// Author:	Yves FRICAUD
//		<yfr@phylox>


#include <MAT_Zone.ixx>
#include <MAT_BasicElt.hxx>
#include <MAT_SequenceOfArc.hxx>
#include <MAT_Node.hxx>

//========================================================================
// function:
// purpose :
//========================================================================
MAT_Zone::MAT_Zone ()
{}

//========================================================================
// function:
// purpose :
//========================================================================
MAT_Zone::MAT_Zone(const Handle(MAT_BasicElt)& aBasicElt) 
{
  Perform (aBasicElt);
}

//========================================================================
// function: Perform
// purpose :
//========================================================================
void MAT_Zone::Perform (const Handle(MAT_BasicElt)& aBasicElt) 
{
  Handle (MAT_Node)       NextNode, StartNode;
  Handle (MAT_Arc)        CurrentArc;

  limited = Standard_True;
  frontier.Clear();
  // ------------------------------------------------------------------------
  // Si le premier arc correspondant a la zone est Null => Sequence vide.
  // ------------------------------------------------------------------------
  if (aBasicElt->EndArc().IsNull()) return;

  // ----------------------------
  // Angle rentrant => Zone Vide.
  // ----------------------------
  // if(aBasicElt->EndArc() == aBasicElt->StartArc()) return;

  // --------------------------------
  // Initialisation de la frontier.
  // --------------------------------
  CurrentArc = aBasicElt->EndArc();
  frontier.Append(CurrentArc);

  // --------------------------------------------------------------------------  
  // Determination du premier noeud qui permet de construire la zone en tournant
  // surla gauche.
  // --------------------------------------------------------------------------
  NextNode  = NodeForTurn(CurrentArc,aBasicElt,MAT_Left);
  StartNode = CurrentArc->TheOtherNode(NextNode);

  // -------------------------------------------------------------------------
  // Exploration du Graph toujours sur les arcs voisins a gauche jusqu'a
  // - retour sur la Figure .
  // - l acces a un noeud infini .
  // (Ces deux  cas correspondent a des noeuds pendants.)
  // - retour sur l arc de depart si le basicElt est ferme.
  // -------------------------------------------------------------------------
  
  while (!NextNode->PendingNode() && (NextNode != StartNode)) {
    CurrentArc = CurrentArc->Neighbour(NextNode,MAT_Left);
    frontier.Append(CurrentArc);
    NextNode   = CurrentArc->TheOtherNode(NextNode);
  }

  // -----------------------------------------------------------------------
  // Si NextNode est a l infini : exploration du graph a partir du StartArc 
  //   sur <aBasicElt>.
  //   exploration sur les arcs voisins a droite.
  // Sinon => Fin.
  // -----------------------------------------------------------------------

  if (NextNode->Infinite()) {
    limited    = Standard_False;
    CurrentArc = aBasicElt->StartArc();  
    frontier.Append(CurrentArc);
    // --------------------------------------------------------------------------
    // Determination du premier noeud qui permet de construire la zone en 
    //tournan surla droite.
    // --------------------------------------------------------------------------
    NextNode = NodeForTurn(CurrentArc,aBasicElt,MAT_Right);
    
    // -----------------------------------------------------
    // Cette branche est aussi terminee par un noeud infini.
    // -----------------------------------------------------
    while (!NextNode->Infinite()) {
      CurrentArc = CurrentArc->Neighbour(NextNode,MAT_Right);
      frontier.Append(CurrentArc);
      NextNode   = CurrentArc->TheOtherNode(NextNode);
    }
  }
}

//========================================================================
// function: NumberOfArcs
// purpose :
//========================================================================
Standard_Integer  MAT_Zone::NumberOfArcs()const 
{
  return frontier.Length();
}

//========================================================================
// function: ArcOnFrontier
// purpose :
//========================================================================
Handle(MAT_Arc)  MAT_Zone::ArcOnFrontier(const Standard_Integer Index)const 
{
  return frontier.Value(Index);
}

//========================================================================
// function: NoEmptyZone
// purpose :
//========================================================================
Standard_Boolean  MAT_Zone::NoEmptyZone()const 
{
   return (!frontier.IsEmpty());
}

//========================================================================
// function: Limited
// purpose :
//========================================================================
Standard_Boolean  MAT_Zone::Limited()const 
{
   return limited;
}

//========================================================================
// function:
// purpose :
//========================================================================
Handle(MAT_Node) MAT_Zone::NodeForTurn (const Handle(MAT_Arc)&      anArc,
					const Handle(MAT_BasicElt)& aBE,
					const MAT_Side              aSide) 
     const
{
  Handle(MAT_Arc)  NeighbourArc;
  Handle(MAT_Node) NodeSol     ;

  NodeSol      = anArc->FirstNode();
  NeighbourArc = anArc->Neighbour(NodeSol,aSide);
  if (NeighbourArc.IsNull()) {    
    NodeSol      = anArc->SecondNode();
    NeighbourArc = anArc->Neighbour(NodeSol,aSide);
  }
  if (NeighbourArc.IsNull()) {
    return NodeSol;
  }
  if (NeighbourArc->FirstElement() == aBE) {
    return NodeSol;
  }
  else if (NeighbourArc->SecondElement() == aBE) { 
    return NodeSol;
  }
  else {
    return anArc->TheOtherNode(NodeSol);
  }
}