summaryrefslogtreecommitdiff
path: root/src/ShapeFix/ShapeFix_WireSegment.cxx
blob: 53473a981b83051fafe918d6d6a2edbbf2068d38 (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
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
// File:	ShapeFix_WireSegment.cxx
// Created:	Tue Apr 27 17:30:20 1999
// Author:	Pavel DURANDIN
//		<pdn@nnov.matra-dtv.fr>


#include <ShapeFix_WireSegment.ixx>
#include <ShapeAnalysis_Edge.hxx>
#include <TopoDS_Edge.hxx>

//=======================================================================
//function : ShapeFix_WireSegment
//purpose  : 
//=======================================================================

ShapeFix_WireSegment::ShapeFix_WireSegment()
{
  Clear();
  myOrient = TopAbs_FORWARD;
}

//=======================================================================
//function : ShapeFix_WireSegment
//purpose  : 
//=======================================================================

ShapeFix_WireSegment::ShapeFix_WireSegment(const Handle(ShapeExtend_WireData)& wire,
					   const TopAbs_Orientation ori)
{
  Load ( wire );
  myOrient = ori;
}

//=======================================================================
//function : Clear
//purpose  : 
//=======================================================================

void ShapeFix_WireSegment::Clear()
{
  myWire = new ShapeExtend_WireData;
  myWire->ManifoldMode() = Standard_False;
  myIUMin = new TColStd_HSequenceOfInteger;
  myIUMax = new TColStd_HSequenceOfInteger;
  myIVMin = new TColStd_HSequenceOfInteger;
  myIVMax = new TColStd_HSequenceOfInteger;
  myVertex = TopoDS_Vertex();
}

//=======================================================================
//function : Load
//purpose  : 
//=======================================================================

void ShapeFix_WireSegment::Load (const Handle(ShapeExtend_WireData)& wire)
{
//  myWire = wire;
  Clear();
  myWire->ManifoldMode() = wire->ManifoldMode();
  for ( Standard_Integer i=1; i <= wire->NbEdges(); i++ ) 
    AddEdge ( i, wire->Edge(i) );
}

//=======================================================================
//function : WireData
//purpose  : 
//=======================================================================

const Handle(ShapeExtend_WireData)& ShapeFix_WireSegment::WireData() const
{
  return myWire;
}

//=======================================================================
//function : Orientation
//purpose  : 
//=======================================================================

void ShapeFix_WireSegment::Orientation(const TopAbs_Orientation ori)
{
  myOrient = ori;
}

//=======================================================================
//function : Orientation
//purpose  : 
//=======================================================================

TopAbs_Orientation ShapeFix_WireSegment::Orientation() const
{
  return myOrient;
}

//=======================================================================
//function : FirstVertex
//purpose  : 
//=======================================================================

TopoDS_Vertex ShapeFix_WireSegment::FirstVertex() const
{
  ShapeAnalysis_Edge sae;
  return sae.FirstVertex (myWire->Edge(1));
}

//=======================================================================
//function : LastVertex
//purpose  : 
//=======================================================================

TopoDS_Vertex ShapeFix_WireSegment::LastVertex() const
{
  ShapeAnalysis_Edge sae;
  return sae.LastVertex (myWire->Edge(myWire->NbEdges()));
}

//=======================================================================
//function : IsClosed
//purpose  : 
//=======================================================================

Standard_Boolean ShapeFix_WireSegment::IsClosed() const
{
  TopoDS_Vertex v;
  v = FirstVertex();
  return v.IsSame(LastVertex());
}

//=======================================================================
// WORK with EDGES and PATCH INDICES
//=======================================================================

#define MININD        -32000
#define MAXIND         32000

//=======================================================================
//function : NbEdges
//purpose  : 
//=======================================================================

Standard_Integer ShapeFix_WireSegment::NbEdges() const
{
  return  myWire->NbEdges();
}

//=======================================================================
//function : Edge
//purpose  : 
//=======================================================================

TopoDS_Edge ShapeFix_WireSegment::Edge (const Standard_Integer i) const
{
 
  return  myWire->Edge(i);
}

//=======================================================================
//function : SetEdge
//purpose  : 
//=======================================================================

void ShapeFix_WireSegment::SetEdge (const Standard_Integer i, 
				    const TopoDS_Edge &edge) 
{
  myWire->Set ( edge, i );
}

//=======================================================================
//function : AddEdge
//purpose  : 
//=======================================================================

void ShapeFix_WireSegment::AddEdge (const Standard_Integer i, 
				    const TopoDS_Edge &edge) 
{
  AddEdge ( i, edge, MININD, MAXIND, MININD, MAXIND );
}

//=======================================================================
//function : AddEdge
//purpose  : 
//=======================================================================

void ShapeFix_WireSegment::AddEdge (const Standard_Integer i, 
				    const TopoDS_Edge &edge,
				    const Standard_Integer iumin,
				    const Standard_Integer iumax,
				    const Standard_Integer ivmin,
				    const Standard_Integer ivmax) 
{
  myWire->Add ( edge, i );
  if ( i ==0 ) {
    myIUMin->Append ( iumin );
    myIUMax->Append ( iumax );
    myIVMin->Append ( ivmin );
    myIVMax->Append ( ivmax );
  }
  else {
    myIUMin->InsertBefore ( i, iumin );
    myIUMax->InsertBefore ( i, iumax );
    myIVMin->InsertBefore ( i, ivmin );
    myIVMax->InsertBefore ( i, ivmax );
  }
}

//=======================================================================
//function : SetPatchIndex
//purpose  : 
//=======================================================================

void ShapeFix_WireSegment::SetPatchIndex (const Standard_Integer i, 
					  const Standard_Integer iumin,
					  const Standard_Integer iumax,
					  const Standard_Integer ivmin,
					  const Standard_Integer ivmax) 
{
  myIUMin->SetValue ( i, iumin );
  myIUMax->SetValue ( i, iumax );
  myIVMin->SetValue ( i, ivmin );
  myIVMax->SetValue ( i, ivmax );
}

//=======================================================================
//function : DefineIUMin
//purpose  : 
//=======================================================================

void ShapeFix_WireSegment::DefineIUMin (const Standard_Integer i, 
					const Standard_Integer iumin) 
{
  if ( myIUMin->Value(i) < iumin ) myIUMin->SetValue ( i, iumin );
#ifdef DEB
  if ( myIUMin->Value(i) > myIUMax->Value(i) )
    cout << "Warning: ShapeFix_WireSegment::DefineIUMin: indexation error" << endl;
#endif
}

//=======================================================================
//function : DefineIUMax
//purpose  : 
//=======================================================================

void ShapeFix_WireSegment::DefineIUMax (const Standard_Integer i, 
					const Standard_Integer iumax) 
{
  if ( myIUMax->Value(i) > iumax ) myIUMax->SetValue ( i, iumax );
#ifdef DEB
  Standard_Integer iun = myIUMin->Value(i), iux = myIUMax->Value(i);
  if ( iun > iux )
    cout << "Warning: ShapeFix_WireSegment::DefineIUMax: indexation error" << endl;
#endif
}

//=======================================================================
//function : DefineIVMin
//purpose  : 
//=======================================================================

void ShapeFix_WireSegment::DefineIVMin (const Standard_Integer i, 
					const Standard_Integer ivmin) 
{
  if ( myIVMin->Value(i) < ivmin ) myIVMin->SetValue ( i, ivmin );
#ifdef DEB
  Standard_Integer ivn = myIVMin->Value(i), ivx = myIVMax->Value(i);
  if ( ivn > ivx )
    cout << "Warning: ShapeFix_WireSegment::DefineIVMin: indexation error" << endl;
#endif
}

//=======================================================================
//function : DefineIVMax
//purpose  : 
//=======================================================================

void ShapeFix_WireSegment::DefineIVMax (const Standard_Integer i, 
					const Standard_Integer ivmax) 
{
  if ( myIVMax->Value(i) > ivmax ) myIVMax->SetValue ( i, ivmax );
#ifdef DEB
  Standard_Integer ivn = myIVMin->Value(i), ivx = myIVMax->Value(i);
  if ( ivn > ivx )
    cout << "Warning: ShapeFix_WireSegment::DefineIVMax: indexation error" << endl;
#endif
}

//=======================================================================
//function : GetPatchIndex
//purpose  : 
//=======================================================================

void ShapeFix_WireSegment::GetPatchIndex (const Standard_Integer i, 
					  Standard_Integer &iumin,
					  Standard_Integer &iumax,
					  Standard_Integer &ivmin,
					  Standard_Integer &ivmax) const
{
  iumin = myIUMin->Value(i);
  iumax = myIUMax->Value(i);
  ivmin = myIVMin->Value(i);
  ivmax = myIVMax->Value(i);
}

//=======================================================================
//function : CheckPatchIndex
//purpose  : 
//=======================================================================

Standard_Boolean ShapeFix_WireSegment::CheckPatchIndex (const Standard_Integer i) const
{
  Standard_Integer dU = myIUMax->Value(i) - myIUMin->Value(i);
  Standard_Integer dV = myIVMax->Value(i) - myIVMin->Value(i);
  Standard_Boolean ok = ( dU ==0 || dU ==1 ) && ( dV ==0 || dV ==1 );
#ifdef DEB
  if ( ! ok )
    cout << "Warning: ShapeFix_WireSegment::CheckPatchIndex: incomplete indexation" << endl;
#endif
  return ok;
}

//=======================================================================
//function : SetVertex
//purpose  : 
//=======================================================================

void ShapeFix_WireSegment::SetVertex(const TopoDS_Vertex& theVertex)
{
  myVertex = theVertex;
  //SetVertex(theVertex, MININD, MAXIND, MININD, MAXIND);
}

/*//=======================================================================
//function : SetVertex
//purpose  : 
//=======================================================================

void ShapeFix_WireSegment::SetVertex(const TopoDS_Vertex& theVertex,
				     Standard_Integer iumin,
				     Standard_Integer iumax,
				     Standard_Integer ivmin,
				     Standard_Integer ivmax)
  myVertex = theVertex;
  myIUMin->Append ( iumin );
  myIUMax->Append ( iumax );
  myIVMin->Append ( ivmin );
  myIVMax->Append ( ivmax );
}
*/
//=======================================================================
//function : GetVertex
//purpose  : 
//=======================================================================

TopoDS_Vertex ShapeFix_WireSegment::GetVertex() const
{
  return myVertex;
}

//=======================================================================
//function : IsVertex
//purpose  : 
//=======================================================================

Standard_Boolean ShapeFix_WireSegment::IsVertex() const
{
  return !myVertex.IsNull();
}