0030058: Visualization, Select3D_SensitivePrimitiveArray - the selection is not fast...
[occt.git] / src / ShapeFix / ShapeFix_WireSegment.cxx
CommitLineData
b311480e 1// Created on: 1999-04-27
2// Created by: Pavel DURANDIN
3// Copyright (c) 1999-1999 Matra Datavision
973c2be1 4// Copyright (c) 1999-2014 OPEN CASCADE SAS
b311480e 5//
973c2be1 6// This file is part of Open CASCADE Technology software library.
b311480e 7//
d5f74e42 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
973c2be1 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.
b311480e 13//
973c2be1 14// Alternatively, this file may be used under the terms of Open CASCADE
15// commercial license or contractual agreement.
7fd59977 16
42cf5bc1 17
7fd59977 18#include <ShapeAnalysis_Edge.hxx>
42cf5bc1 19#include <ShapeExtend_WireData.hxx>
20#include <ShapeFix_WireSegment.hxx>
7fd59977 21#include <TopoDS_Edge.hxx>
42cf5bc1 22#include <TopoDS_Vertex.hxx>
23#include <TopoDS_Wire.hxx>
7fd59977 24
25//=======================================================================
26//function : ShapeFix_WireSegment
27//purpose :
28//=======================================================================
7fd59977 29ShapeFix_WireSegment::ShapeFix_WireSegment()
30{
31 Clear();
32 myOrient = TopAbs_FORWARD;
33}
34
35//=======================================================================
36//function : ShapeFix_WireSegment
37//purpose :
38//=======================================================================
39
40ShapeFix_WireSegment::ShapeFix_WireSegment(const Handle(ShapeExtend_WireData)& wire,
41 const TopAbs_Orientation ori)
42{
43 Load ( wire );
44 myOrient = ori;
45}
46
47//=======================================================================
48//function : Clear
49//purpose :
50//=======================================================================
51
52void ShapeFix_WireSegment::Clear()
53{
54 myWire = new ShapeExtend_WireData;
55 myWire->ManifoldMode() = Standard_False;
56 myIUMin = new TColStd_HSequenceOfInteger;
57 myIUMax = new TColStd_HSequenceOfInteger;
58 myIVMin = new TColStd_HSequenceOfInteger;
59 myIVMax = new TColStd_HSequenceOfInteger;
60 myVertex = TopoDS_Vertex();
61}
62
63//=======================================================================
64//function : Load
65//purpose :
66//=======================================================================
67
68void ShapeFix_WireSegment::Load (const Handle(ShapeExtend_WireData)& wire)
69{
70// myWire = wire;
71 Clear();
72 myWire->ManifoldMode() = wire->ManifoldMode();
73 for ( Standard_Integer i=1; i <= wire->NbEdges(); i++ )
74 AddEdge ( i, wire->Edge(i) );
75}
76
77//=======================================================================
78//function : WireData
79//purpose :
80//=======================================================================
81
82const Handle(ShapeExtend_WireData)& ShapeFix_WireSegment::WireData() const
83{
84 return myWire;
85}
86
87//=======================================================================
88//function : Orientation
89//purpose :
90//=======================================================================
91
92void ShapeFix_WireSegment::Orientation(const TopAbs_Orientation ori)
93{
94 myOrient = ori;
95}
96
97//=======================================================================
98//function : Orientation
99//purpose :
100//=======================================================================
101
102TopAbs_Orientation ShapeFix_WireSegment::Orientation() const
103{
104 return myOrient;
105}
106
107//=======================================================================
108//function : FirstVertex
109//purpose :
110//=======================================================================
111
112TopoDS_Vertex ShapeFix_WireSegment::FirstVertex() const
113{
114 ShapeAnalysis_Edge sae;
115 return sae.FirstVertex (myWire->Edge(1));
116}
117
118//=======================================================================
119//function : LastVertex
120//purpose :
121//=======================================================================
122
123TopoDS_Vertex ShapeFix_WireSegment::LastVertex() const
124{
125 ShapeAnalysis_Edge sae;
126 return sae.LastVertex (myWire->Edge(myWire->NbEdges()));
127}
128
129//=======================================================================
130//function : IsClosed
131//purpose :
132//=======================================================================
133
134Standard_Boolean ShapeFix_WireSegment::IsClosed() const
135{
136 TopoDS_Vertex v;
137 v = FirstVertex();
138 return v.IsSame(LastVertex());
139}
140
141//=======================================================================
142// WORK with EDGES and PATCH INDICES
143//=======================================================================
144
145#define MININD -32000
146#define MAXIND 32000
147
148//=======================================================================
149//function : NbEdges
150//purpose :
151//=======================================================================
152
153Standard_Integer ShapeFix_WireSegment::NbEdges() const
154{
155 return myWire->NbEdges();
156}
157
158//=======================================================================
159//function : Edge
160//purpose :
161//=======================================================================
162
163TopoDS_Edge ShapeFix_WireSegment::Edge (const Standard_Integer i) const
164{
165
166 return myWire->Edge(i);
167}
168
169//=======================================================================
170//function : SetEdge
171//purpose :
172//=======================================================================
173
174void ShapeFix_WireSegment::SetEdge (const Standard_Integer i,
175 const TopoDS_Edge &edge)
176{
177 myWire->Set ( edge, i );
178}
179
180//=======================================================================
181//function : AddEdge
182//purpose :
183//=======================================================================
184
185void ShapeFix_WireSegment::AddEdge (const Standard_Integer i,
186 const TopoDS_Edge &edge)
187{
188 AddEdge ( i, edge, MININD, MAXIND, MININD, MAXIND );
189}
190
191//=======================================================================
192//function : AddEdge
193//purpose :
194//=======================================================================
195
196void ShapeFix_WireSegment::AddEdge (const Standard_Integer i,
197 const TopoDS_Edge &edge,
198 const Standard_Integer iumin,
199 const Standard_Integer iumax,
200 const Standard_Integer ivmin,
201 const Standard_Integer ivmax)
202{
203 myWire->Add ( edge, i );
204 if ( i ==0 ) {
205 myIUMin->Append ( iumin );
206 myIUMax->Append ( iumax );
207 myIVMin->Append ( ivmin );
208 myIVMax->Append ( ivmax );
209 }
210 else {
211 myIUMin->InsertBefore ( i, iumin );
212 myIUMax->InsertBefore ( i, iumax );
213 myIVMin->InsertBefore ( i, ivmin );
214 myIVMax->InsertBefore ( i, ivmax );
215 }
216}
217
218//=======================================================================
219//function : SetPatchIndex
220//purpose :
221//=======================================================================
222
223void ShapeFix_WireSegment::SetPatchIndex (const Standard_Integer i,
224 const Standard_Integer iumin,
225 const Standard_Integer iumax,
226 const Standard_Integer ivmin,
227 const Standard_Integer ivmax)
228{
229 myIUMin->SetValue ( i, iumin );
230 myIUMax->SetValue ( i, iumax );
231 myIVMin->SetValue ( i, ivmin );
232 myIVMax->SetValue ( i, ivmax );
233}
234
235//=======================================================================
236//function : DefineIUMin
237//purpose :
238//=======================================================================
239
240void ShapeFix_WireSegment::DefineIUMin (const Standard_Integer i,
241 const Standard_Integer iumin)
242{
243 if ( myIUMin->Value(i) < iumin ) myIUMin->SetValue ( i, iumin );
0797d9d3 244#ifdef OCCT_DEBUG
7fd59977 245 if ( myIUMin->Value(i) > myIUMax->Value(i) )
246 cout << "Warning: ShapeFix_WireSegment::DefineIUMin: indexation error" << endl;
247#endif
248}
249
250//=======================================================================
251//function : DefineIUMax
252//purpose :
253//=======================================================================
254
255void ShapeFix_WireSegment::DefineIUMax (const Standard_Integer i,
256 const Standard_Integer iumax)
257{
258 if ( myIUMax->Value(i) > iumax ) myIUMax->SetValue ( i, iumax );
0797d9d3 259#ifdef OCCT_DEBUG
7fd59977 260 Standard_Integer iun = myIUMin->Value(i), iux = myIUMax->Value(i);
261 if ( iun > iux )
262 cout << "Warning: ShapeFix_WireSegment::DefineIUMax: indexation error" << endl;
263#endif
264}
265
266//=======================================================================
267//function : DefineIVMin
268//purpose :
269//=======================================================================
270
271void ShapeFix_WireSegment::DefineIVMin (const Standard_Integer i,
272 const Standard_Integer ivmin)
273{
274 if ( myIVMin->Value(i) < ivmin ) myIVMin->SetValue ( i, ivmin );
0797d9d3 275#ifdef OCCT_DEBUG
7fd59977 276 Standard_Integer ivn = myIVMin->Value(i), ivx = myIVMax->Value(i);
277 if ( ivn > ivx )
278 cout << "Warning: ShapeFix_WireSegment::DefineIVMin: indexation error" << endl;
279#endif
280}
281
282//=======================================================================
283//function : DefineIVMax
284//purpose :
285//=======================================================================
286
287void ShapeFix_WireSegment::DefineIVMax (const Standard_Integer i,
288 const Standard_Integer ivmax)
289{
290 if ( myIVMax->Value(i) > ivmax ) myIVMax->SetValue ( i, ivmax );
0797d9d3 291#ifdef OCCT_DEBUG
7fd59977 292 Standard_Integer ivn = myIVMin->Value(i), ivx = myIVMax->Value(i);
293 if ( ivn > ivx )
294 cout << "Warning: ShapeFix_WireSegment::DefineIVMax: indexation error" << endl;
295#endif
296}
297
298//=======================================================================
299//function : GetPatchIndex
300//purpose :
301//=======================================================================
302
303void ShapeFix_WireSegment::GetPatchIndex (const Standard_Integer i,
304 Standard_Integer &iumin,
305 Standard_Integer &iumax,
306 Standard_Integer &ivmin,
307 Standard_Integer &ivmax) const
308{
309 iumin = myIUMin->Value(i);
310 iumax = myIUMax->Value(i);
311 ivmin = myIVMin->Value(i);
312 ivmax = myIVMax->Value(i);
313}
314
315//=======================================================================
316//function : CheckPatchIndex
317//purpose :
318//=======================================================================
319
320Standard_Boolean ShapeFix_WireSegment::CheckPatchIndex (const Standard_Integer i) const
321{
322 Standard_Integer dU = myIUMax->Value(i) - myIUMin->Value(i);
323 Standard_Integer dV = myIVMax->Value(i) - myIVMin->Value(i);
324 Standard_Boolean ok = ( dU ==0 || dU ==1 ) && ( dV ==0 || dV ==1 );
0797d9d3 325#ifdef OCCT_DEBUG
7fd59977 326 if ( ! ok )
327 cout << "Warning: ShapeFix_WireSegment::CheckPatchIndex: incomplete indexation" << endl;
328#endif
329 return ok;
330}
331
332//=======================================================================
333//function : SetVertex
334//purpose :
335//=======================================================================
336
337void ShapeFix_WireSegment::SetVertex(const TopoDS_Vertex& theVertex)
338{
339 myVertex = theVertex;
340 //SetVertex(theVertex, MININD, MAXIND, MININD, MAXIND);
341}
342
343/*//=======================================================================
344//function : SetVertex
345//purpose :
346//=======================================================================
347
348void ShapeFix_WireSegment::SetVertex(const TopoDS_Vertex& theVertex,
349 Standard_Integer iumin,
350 Standard_Integer iumax,
351 Standard_Integer ivmin,
352 Standard_Integer ivmax)
353 myVertex = theVertex;
354 myIUMin->Append ( iumin );
355 myIUMax->Append ( iumax );
356 myIVMin->Append ( ivmin );
357 myIVMax->Append ( ivmax );
358}
359*/
360//=======================================================================
361//function : GetVertex
362//purpose :
363//=======================================================================
364
365TopoDS_Vertex ShapeFix_WireSegment::GetVertex() const
366{
367 return myVertex;
368}
369
370//=======================================================================
371//function : IsVertex
372//purpose :
373//=======================================================================
374
375Standard_Boolean ShapeFix_WireSegment::IsVertex() const
376{
377 return !myVertex.IsNull();
378}