1 // Created on: 1998-06-03
2 // Created by: data exchange team
3 // Copyright (c) 1998-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 #ifndef _ShapeAnalysis_WireOrder_HeaderFile
18 #define _ShapeAnalysis_WireOrder_HeaderFile
20 #include <Standard.hxx>
21 #include <Standard_DefineAlloc.hxx>
22 #include <Standard_Handle.hxx>
24 #include <Standard_Boolean.hxx>
25 #include <TColStd_HArray1OfInteger.hxx>
26 #include <TColgp_HSequenceOfXY.hxx>
27 #include <TColgp_HSequenceOfXYZ.hxx>
28 #include <Standard_Real.hxx>
29 #include <Standard_Integer.hxx>
33 // resolve name collisions with X11 headers
38 //! This class is intended to control and, if possible, redefine
39 //! the order of a list of edges which define a wire
40 //! Edges are not given directly, but as their bounds (start,end)
42 //! This allows to use this tool, either on existing wire, or on
43 //! data just taken from a file (coordinates are easy to get)
45 //! It can work, either in 2D, or in 3D, or miscible mode
46 //! The tolerance for each mode is fixed
48 //! Two phases : firstly add the couples (start, end)
49 //! secondly perform then get the result
50 class ShapeAnalysis_WireOrder
57 Standard_EXPORT ShapeAnalysis_WireOrder();
59 //! Creates a WireOrder.
60 //! Flag <theMode3D> defines 3D or 2d mode.
61 //! Flag <theModeBoth> defines miscible mode and the flag <theMode3D> is ignored.
62 //! Warning: Parameter <theTolerance> is not used in algorithm.
63 Standard_EXPORT ShapeAnalysis_WireOrder (const Standard_Boolean theMode3D,
64 const Standard_Real theTolerance,
65 const Standard_Boolean theModeBoth = Standard_False);
68 //! Clears the edge list if the mode (<theMode3D> or <theModeBoth> ) changes.
69 //! Clears the connexion list.
70 //! Warning: Parameter <theTolerance> is not used in algorithm.
71 Standard_EXPORT void SetMode (const Standard_Boolean theMode3D,
72 const Standard_Real theTolerance,
73 const Standard_Boolean theModeBoth = Standard_False);
75 //! Returns the working tolerance
76 Standard_EXPORT Standard_Real Tolerance() const;
78 //! Clears the list of edges, but not mode and tol
79 Standard_EXPORT void Clear();
81 //! Adds a couple of points 3D (start, end)
82 Standard_EXPORT void Add (const gp_XYZ& theStart3d, const gp_XYZ& theEnd3d);
84 //! Adds a couple of points 2D (start, end)
85 Standard_EXPORT void Add (const gp_XY& theStart2d, const gp_XY& theEnd2d);
87 //! Adds a couple of points 3D and 2D (start, end)
88 Standard_EXPORT void Add (const gp_XYZ& theStart3d,
89 const gp_XYZ& theEnd3d,
90 const gp_XY& theStart2d,
91 const gp_XY& theEnd2d);
93 //! Returns the count of added couples of points (one per edges)
94 Standard_EXPORT Standard_Integer NbEdges() const;
96 //! If this mode is True method perform does not sort edges of
97 //! different loops. The resulting order is first loop, second
99 Standard_EXPORT Standard_Boolean& KeepLoopsMode();
101 //! Computes the better order
102 //! Optimised if the couples were already in order
103 //! The criterium is : two couples in order if distance between
104 //! end-prec and start-cur is less then starting tolerance <tol>
105 //! Else, the smallest distance is reached
106 //! Warning: Parameter <closed> not used
107 Standard_EXPORT void Perform (const Standard_Boolean closed = Standard_True);
109 //! Tells if Perform has been done
110 //! Else, the following methods returns original values
111 Standard_EXPORT Standard_Boolean IsDone() const;
113 //! Returns the status of the order (0 if not done) :
114 //! 0 : all edges are direct and in sequence
115 //! 1 : all edges are direct but some are not in sequence
116 //! -1 : some edges are reversed, but no gap remain
117 //! 3 : edges in sequence are just shifted in forward or reverse manner
118 Standard_EXPORT Standard_Integer Status() const;
120 //! Returns the number of original edge which correspond to the
121 //! newly ordered number <n>
122 //! Warning : the returned value is NEGATIVE if edge should be reversed
123 Standard_EXPORT Standard_Integer Ordered (const Standard_Integer theIdx) const;
125 //! Returns the values of the couple <num>, as 3D values
126 Standard_EXPORT void XYZ (const Standard_Integer theIdx, gp_XYZ& theStart3D, gp_XYZ& theEnd3D) const;
128 //! Returns the values of the couple <num>, as 2D values
129 Standard_EXPORT void XY (const Standard_Integer theIdx, gp_XY& theStart2D, gp_XY& theEnd2D) const;
131 //! Returns the gap between a couple and its preceding
132 //! <num> is considered ordered
133 //! If <num> = 0 (D), returns the greatest gap found
134 Standard_EXPORT Standard_Real Gap (const Standard_Integer num = 0) const;
136 //! Determines the chains inside which successive edges have a gap
137 //! less than a given value. Queried by NbChains and Chain
138 Standard_EXPORT void SetChains (const Standard_Real gap);
140 //! Returns the count of computed chains
141 Standard_EXPORT Standard_Integer NbChains() const;
143 //! Returns, for the chain n0 num, starting and ending numbers of
144 //! edges. In the list of ordered edges (see Ordered for originals)
145 Standard_EXPORT void Chain (const Standard_Integer num, Standard_Integer& n1, Standard_Integer& n2) const;
147 //! Determines the couples of edges for which end and start fit
148 //! inside a given gap. Queried by NbCouples and Couple
149 //! Warning: function isn't implemented
150 Standard_EXPORT void SetCouples (const Standard_Real gap);
152 //! Returns the count of computed couples
153 Standard_EXPORT Standard_Integer NbCouples() const;
155 //! Returns, for the couple n0 num, the two implied edges
156 //! In the list of ordered edges
157 Standard_EXPORT void Couple (const Standard_Integer num, Standard_Integer& n1, Standard_Integer& n2) const;
162 // the mode in which the algorithm works
170 Handle(TColStd_HArray1OfInteger) myOrd;
171 Handle(TColStd_HArray1OfInteger) myChains;
172 Handle(TColStd_HArray1OfInteger) myCouples;
173 Handle(TColgp_HSequenceOfXYZ) myXYZ;
174 Handle(TColgp_HSequenceOfXY) myXY;
177 Standard_Integer myStat;
178 Standard_Boolean myKeepLoops;
182 #endif // _ShapeAnalysis_WireOrder_HeaderFile