0033661: Data Exchange, Step Import - Tessellated GDTs are not imported
[occt.git] / src / ApproxInt / ApproxInt_KnotTools.hxx
1 // Copyright (c) 1999-2014 OPEN CASCADE SAS
2 //
3 // This file is part of Open CASCADE Technology software library.
4 //
5 // This library is free software; you can redistribute it and/or modify it under
6 // the terms of the GNU Lesser General Public License version 2.1 as published
7 // by the Free Software Foundation, with special exception defined in the file
8 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
9 // distribution for complete text of the license and disclaimer of any warranty.
10 //
11 // Alternatively, this file may be used under the terms of Open CASCADE
12 // commercial license or contractual agreement.
13
14 #ifndef _ApproxInt_KnotTools_HeaderFile
15 #define _ApproxInt_KnotTools_HeaderFile
16
17 #include <Standard_DefineAlloc.hxx>
18 #include <Standard_Macro.hxx>
19 #include <Standard_Boolean.hxx>
20 #include <Standard_Real.hxx>
21 #include <Standard_Integer.hxx>
22 #include <TColgp_Array1OfPnt2d.hxx>
23 #include <NCollection_Sequence.hxx>
24 #include <NCollection_List.hxx>
25 #include <math_Vector.hxx>
26 #include <TColgp_Array1OfPnt.hxx>
27 #include <TColStd_Array1OfReal.hxx>
28 #include <NCollection_LocalArray.hxx>
29 #include <NCollection_Vector.hxx>
30 #include <Approx_ParametrizationType.hxx>
31
32 class IntPatch_WLine;
33
34 // Corresponds for debug information output.
35 // Debug information is also printed when OCCT_DEBUG defined.
36 //#define APPROXINT_KNOTTOOLS_DEBUG
37
38 //! This class intended to build knots sequence on discrete set of points for further approximation into bspline curve.
39 //!
40 //! Short description of algorithm:
41 //! 1) Build discrete curvature on points set.
42 //! 2) According to special rules build draft knots sequence.
43 //! 3) Filter draft sequence to build output sequence.
44 //!
45 //! For more details look at:
46 //! Anshuman Razdan - Knot Placement for B-Spline curve Approximation.
47 class ApproxInt_KnotTools
48 {
49 public:
50
51   DEFINE_STANDARD_ALLOC
52
53   //! Main function to build optimal knot sequence.
54   //! At least one set from (thePntsXYZ, thePntsU1V1, thePntsU2V2) should exist.
55   //! @param thePntsXYZ - Set of 3d points.
56   //! @param thePntsU1V1 - Set of 2d points.
57   //! @param thePntsU2V2 - Set of 2d points.
58   //! @param thePars - Expected parameters associated with set.
59   //! @param theApproxXYZ - Flag, existence of 3d set.
60   //! @param theApproxU1V1 - Flag existence of first 2d set.
61   //! @param theApproxU2V2 - Flag existence of second 2d set.
62   //! @param theMinNbPnts - Minimal number of points per knot interval.
63   //! @param theKnots - output knots sequence.
64   Standard_EXPORT static void BuildKnots(const TColgp_Array1OfPnt& thePntsXYZ,
65                                          const TColgp_Array1OfPnt2d& thePntsU1V1,
66                                          const TColgp_Array1OfPnt2d& thePntsU2V2,
67                                          const math_Vector& thePars,
68                                          const Standard_Boolean theApproxXYZ,
69                                          const Standard_Boolean theApproxU1V1,
70                                          const Standard_Boolean theApproxU2V2,
71                                          const Standard_Integer theMinNbPnts,
72                                          NCollection_Vector<Standard_Integer>& theKnots);
73
74   //! Builds discrete curvature
75   Standard_EXPORT static void BuildCurvature(
76     const NCollection_LocalArray<Standard_Real>& theCoords,
77     const Standard_Integer theDim,
78     const math_Vector& thePars,
79     TColStd_Array1OfReal& theCurv,
80     Standard_Real& theMaxCurv);
81
82   //! Defines preferable parametrization type for theWL 
83   Standard_EXPORT static Approx_ParametrizationType DefineParType(const Handle(IntPatch_WLine)& theWL,
84     const Standard_Integer theFpar, const Standard_Integer theLpar,
85     const Standard_Boolean theApproxXYZ,
86     const Standard_Boolean theApproxU1V1,
87     const Standard_Boolean theApproxU2V2);
88
89
90 private:
91
92   //! Compute indices of knots:
93   //!
94   //! I: Build discrete curvature in points set,
95   //! using outer product of two vectors.
96   //!
97   //! II: Put knots in points which has extremity on discrete curvature.
98   //!
99   //! III: Put knots in monotone intervals of curvature.
100   //!
101   //! IV: Put additional knots near extrema points.
102   static void ComputeKnotInds(const NCollection_LocalArray<Standard_Real>& theCoords,
103                               const Standard_Integer theDim,
104                               const math_Vector& thePars,
105                               NCollection_Sequence<Standard_Integer>& theInds);
106
107   //! Insert knots before index I.
108   //!
109   //! I: Check curvature change:
110   //! if ( maxCurvature / minCurvature ) of current interval greater than 
111   //! threshold value, then stop and use upper index as knot.
112   //!
113   //! II: Check midpoint criteria:
114   //! If exist point between two knot indices with angle greater than
115   //! threshold value, then stop and put this index as knot.
116   static Standard_Boolean InsKnotBefI(const Standard_Integer theI,
117                                       const TColStd_Array1OfReal& theCurv,
118                                       const NCollection_LocalArray<Standard_Real>& theCoords,
119                                       const Standard_Integer theDim, 
120                                       NCollection_Sequence<Standard_Integer>& theInds,
121                                       const Standard_Boolean ChkCurv);
122
123   //! Perform knots filtration.
124   //!
125   //! I: Filter too big number of points per knot interval.
126   //!
127   //! II: Filter points with too small amount of points per knot interval.
128   //!
129   //! III: Fill Last Knot.
130   static void FilterKnots(NCollection_Sequence<Standard_Integer>& theInds, 
131                           const Standard_Integer theMinNbPnts,
132                           NCollection_Vector<Standard_Integer>& theLKnots);
133 };
134
135 #endif