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 5 // 6 // This file is part of Open CASCADE Technology software library. 7 // 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. 13 // 14 // Alternatively, this file may be used under the terms of Open CASCADE 15 // commercial license or contractual agreement. 16 17 #ifndef _ShapeAnalysis_WireOrder_HeaderFile 18 #define _ShapeAnalysis_WireOrder_HeaderFile 19 20 #include <Standard.hxx> 21 #include <Standard_DefineAlloc.hxx> 22 #include <Standard_Handle.hxx> 23 24 #include <Standard_Boolean.hxx> 25 #include <TColStd_HArray1OfInteger.hxx> 26 #include <TColgp_HSequenceOfXYZ.hxx> 27 #include <Standard_Real.hxx> 28 #include <Standard_Integer.hxx> 29 class Standard_TypeMismatch; 30 class gp_XYZ; 31 class gp_XY; 32 33 // resolve name collisions with X11 headers 34 #ifdef Status 35 #undef Status 36 #endif 37 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) 41 //! 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) 44 //! 45 //! It can work, either in 2D, or in 3D, but not miscible 46 //! Warning about tolerance : according to the mode (2D/3D), it 47 //! must be given as 2D or 3D (i.e. metric) tolerance, uniform 48 //! on the whole list 49 //! 50 //! Two phases : firstly add the couples (start,end) 51 //! secondly perform then get the result 52 class ShapeAnalysis_WireOrder 53 { 54 public: 55 56 DEFINE_STANDARD_ALLOC 57 58 59 //! Empty constructor 60 Standard_EXPORT ShapeAnalysis_WireOrder(); 61 62 //! Creates a WireOrder in 3D (if mode3d is True) or 2D (if False) 63 //! with a tolerance 64 Standard_EXPORT ShapeAnalysis_WireOrder(const Standard_Boolean mode3d, const Standard_Real tol); 65 66 //! Sets new values. Clears the connexion list 67 //! If <mode3d> changes, also clears the edge list (else, doesn't) 68 Standard_EXPORT void SetMode (const Standard_Boolean mode3d, const Standard_Real tol); 69 70 //! Returns the working tolerance 71 Standard_EXPORT Standard_Real Tolerance() const; 72 73 //! Clears the list of edges, but not mode and tol 74 Standard_EXPORT void Clear(); 75 76 //! Adds a couple of points 3D (start,end) 77 Standard_EXPORT void Add (const gp_XYZ& start3d, const gp_XYZ& end3d); 78 79 //! Adds a couple of points 2D (start,end) 80 Standard_EXPORT void Add (const gp_XY& start2d, const gp_XY& end2d); 81 82 //! Returns the count of added couples of points (one per edges) 83 Standard_EXPORT Standard_Integer NbEdges() const; 84 85 //! If this mode is True method perform does not sort edges of 86 //! different loops. The resulting order is first loop, second 87 //! one etc... 88 Standard_EXPORT Standard_Boolean& KeepLoopsMode(); 89 90 //! Computes the better order 91 //! If <closed> is True (D) considers also closure 92 //! Optimised if the couples were already in order 93 //! The criterium is : two couples in order if distance between 94 //! end-prec and start-cur is less then starting tolerance <tol> 95 //! Else, the smallest distance is reached 96 //! Gap corresponds to a smallest distance greater than <tol> 97 Standard_EXPORT void Perform (const Standard_Boolean closed = Standard_True); 98 99 //! Tells if Perform has been done 100 //! Else, the following methods returns original values 101 Standard_EXPORT Standard_Boolean IsDone() const; 102 103 //! Returns the status of the order (0 if not done) : 104 //! 0 : all edges are direct and in sequence 105 //! 1 : all edges are direct but some are not in sequence 106 //! 2 : in addition, unresolved gaps remain 107 //! -1 : some edges are reversed, but no gap remain 108 //! -2 : some edges are reversed and some gaps remain 109 //! -10 : COULD NOT BE RESOLVED, Failure on Reorder 110 //! gap : regarding starting <tol> 111 Standard_EXPORT Standard_Integer Status() const; 112 113 //! Returns the number of original edge which correspond to the 114 //! newly ordered number <n> 115 //! Warning : the returned value is NEGATIVE if edge should be reversed 116 Standard_EXPORT Standard_Integer Ordered (const Standard_Integer n) const; 117 118 //! Returns the values of the couple <num>, as 3D values 119 Standard_EXPORT void XYZ (const Standard_Integer num, gp_XYZ& start3d, gp_XYZ& end3d) const; 120 121 //! Returns the values of the couple <num>, as 2D values 122 Standard_EXPORT void XY (const Standard_Integer num, gp_XY& start2d, gp_XY& end2d) const; 123 124 //! Returns the gap between a couple and its preceding 125 //! <num> is considered ordered 126 //! If <num> = 0 (D), returns the greatest gap found 127 Standard_EXPORT Standard_Real Gap (const Standard_Integer num = 0) const; 128 129 //! Determines the chains inside which successive edges have a gap 130 //! less than a given value. Queried by NbChains and Chain 131 Standard_EXPORT void SetChains (const Standard_Real gap); 132 133 //! Returns the count of computed chains 134 Standard_EXPORT Standard_Integer NbChains() const; 135 136 //! Returns, for the chain n0 num, starting and ending numbers of 137 //! edges. In the list of ordered edges (see Ordered for originals) 138 Standard_EXPORT void Chain (const Standard_Integer num, Standard_Integer& n1, Standard_Integer& n2) const; 139 140 //! Determines the couples of edges for which end and start fit 141 //! inside a given gap. Queried by NbCouples and Couple 142 Standard_EXPORT void SetCouples (const Standard_Real gap); 143 144 //! Returns the count of computed couples 145 Standard_EXPORT Standard_Integer NbCouples() const; 146 147 //! Returns, for the couple n0 num, the two implied edges 148 //! In the list of ordered edges 149 Standard_EXPORT void Couple (const Standard_Integer num, Standard_Integer& n1, Standard_Integer& n2) const; 150 151 152 153 154 protected: 155 156 157 158 159 160 private: 161 162 163 164 Standard_Boolean myKeepLoops; 165 Handle(TColStd_HArray1OfInteger) myOrd; 166 Handle(TColStd_HArray1OfInteger) myChains; 167 Handle(TColStd_HArray1OfInteger) myCouples; 168 Handle(TColgp_HSequenceOfXYZ) myXYZ; 169 Standard_Real myTol; 170 Standard_Real myGap; 171 Standard_Integer myStat; 172 Standard_Boolean myMode; 173 174 175 }; 176 177 178 179 180 181 182 183 #endif // _ShapeAnalysis_WireOrder_HeaderFile 184