0028599: Replacement of old Boolean operations with new ones in BRepProj_Projection...
[occt.git] / src / IntPolyh / IntPolyh_Intersection.hxx
1 // Created on: 1999-03-03
2 // Created by: Fabrice SERVANT
3 // Copyright (c) 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 _IntPolyh_Intersection_HeaderFile
18 #define _IntPolyh_Intersection_HeaderFile
19
20 #include <Standard.hxx>
21 #include <Standard_DefineAlloc.hxx>
22 #include <Standard_Handle.hxx>
23
24 #include <IntPolyh_ArrayOfPointNormal.hxx>
25 #include <IntPolyh_ArrayOfSectionLines.hxx>
26 #include <IntPolyh_ArrayOfTangentZones.hxx>
27 #include <IntPolyh_ListOfCouples.hxx>
28 #include <IntPolyh_PMaillageAffinage.hxx>
29 #include <TColStd_Array1OfReal.hxx>
30 #include <Standard_Boolean.hxx>
31 #include <Standard_Real.hxx>
32 class Adaptor3d_HSurface;
33
34 //! API algorithm for intersection of two surfaces by intersection
35 //! of their triangulations.
36 //!
37 //! Algorithm provides possibility to intersect surfaces as without
38 //! the precomputed sampling as with it.
39 //!
40 //! If the numbers of sampling points are not given, it will build the
41 //! net of 10x10 sampling points for each surface.
42 //!
43 //! The intersection is done inside constructors.
44 //! Before obtaining the results of intersection it is necessary to check
45 //! if intersection has been performed correctly. It can be done by calling
46 //! the *IsDone()* method.
47 //!
48 //! The results of intersection are the intersection lines and points.
49 class IntPolyh_Intersection
50 {
51 public:
52
53   DEFINE_STANDARD_ALLOC
54
55 public: //! @name Constructors
56
57   //! Constructor for intersection of two surfaces with default parameters.
58   //! Performs intersection.
59   Standard_EXPORT IntPolyh_Intersection(const Handle(Adaptor3d_HSurface)& theS1,
60                                         const Handle(Adaptor3d_HSurface)& theS2);
61
62   //! Constructor for intersection of two surfaces with the given
63   //! size of the sampling nets:
64   //! - <theNbSU1> x <theNbSV1> - for the first surface <theS1>;
65   //! - <theNbSU2> x <theNbSV2> - for the second surface <theS2>.
66   //! Performs intersection.
67   Standard_EXPORT IntPolyh_Intersection(const Handle(Adaptor3d_HSurface)& theS1,
68                                         const Standard_Integer            theNbSU1,
69                                         const Standard_Integer            theNbSV1,
70                                         const Handle(Adaptor3d_HSurface)& theS2,
71                                         const Standard_Integer            theNbSU2,
72                                         const Standard_Integer            theNbSV2);
73
74   //! Constructor for intersection of two surfaces with the precomputed sampling.
75   //! Performs intersection.
76   Standard_EXPORT IntPolyh_Intersection(const Handle(Adaptor3d_HSurface)& theS1,
77                                         const TColStd_Array1OfReal&       theUPars1,
78                                         const TColStd_Array1OfReal&       theVPars1,
79                                         const Handle(Adaptor3d_HSurface)& theS2,
80                                         const TColStd_Array1OfReal&       theUPars2,
81                                         const TColStd_Array1OfReal&       theVPars2);
82
83
84 public: //! @name Getting the results
85
86   //! Returns state of the operation
87   Standard_Boolean IsDone() const
88   {
89     return myIsDone;
90   }
91
92   //! Returns the number of section lines
93   Standard_Integer NbSectionLines() const
94   {
95     return mySectionLines.NbItems();
96   }
97
98   //! Returns the number of points in the given line
99   Standard_Integer NbPointsInLine(const Standard_Integer IndexLine) const
100   {
101     return mySectionLines[IndexLine-1].NbStartPoints();
102   }
103
104   // Returns number of tangent zones
105   Standard_Integer NbTangentZones() const
106   {
107     return myTangentZones.NbItems();
108   }
109
110   //! Returns number of points in tangent zone
111   Standard_Integer NbPointsInTangentZone(const Standard_Integer) const
112   {
113     return 1;
114   }
115
116   //! Gets the parameters of the point in section line
117   Standard_EXPORT void GetLinePoint(const Standard_Integer IndexLine,
118                                     const Standard_Integer IndexPoint,
119                                     Standard_Real& x, Standard_Real& y, Standard_Real& z,
120                                     Standard_Real& u1, Standard_Real& v1,
121                                     Standard_Real& u2, Standard_Real& v2,
122                                     Standard_Real& incidence) const;
123
124   //! Gets the parameters of the point in tangent zone
125   Standard_EXPORT void GetTangentZonePoint(const Standard_Integer IndexLine,
126                                            const Standard_Integer IndexPoint,
127                                            Standard_Real& x, Standard_Real& y, Standard_Real& z,
128                                            Standard_Real& u1, Standard_Real& v1,
129                                            Standard_Real& u2, Standard_Real& v2) const;
130
131
132 private: //! @name Performing the intersection
133
134   //! Compute the intersection by first making the sampling of the surfaces.
135   Standard_EXPORT void Perform();
136
137   //! Compute the intersection on the precomputed sampling.
138   Standard_EXPORT void Perform(const TColStd_Array1OfReal& theUPars1,
139                                const TColStd_Array1OfReal& theVPars1,
140                                const TColStd_Array1OfReal& theUPars2,
141                                const TColStd_Array1OfReal& theVPars2);
142
143   //! Performs the default (standard) intersection of the triangles
144   Standard_EXPORT Standard_Boolean PerformStd(const TColStd_Array1OfReal& theUPars1,
145                                               const TColStd_Array1OfReal& theVPars1,
146                                               const TColStd_Array1OfReal& theUPars2,
147                                               const TColStd_Array1OfReal& theVPars2,
148                                               const Standard_Real         theDeflTol1,
149                                               const Standard_Real         theDeflTol2,
150                                               IntPolyh_PMaillageAffinage& theMaillageS,
151                                               Standard_Integer&           theNbCouples);
152
153   //! Performs the advanced intersection of the triangles - four intersection with
154   //! different shifts of the sampling points.
155   Standard_EXPORT Standard_Boolean PerformAdv(const TColStd_Array1OfReal& theUPars1,
156                                               const TColStd_Array1OfReal& theVPars1,
157                                               const TColStd_Array1OfReal& theUPars2,
158                                               const TColStd_Array1OfReal& theVPars2,
159                                               const Standard_Real         theDeflTol1,
160                                               const Standard_Real         theDeflTol2,
161                                               IntPolyh_PMaillageAffinage& theMaillageFF,
162                                               IntPolyh_PMaillageAffinage& theMaillageFR,
163                                               IntPolyh_PMaillageAffinage& theMaillageRF,
164                                               IntPolyh_PMaillageAffinage& theMaillageRR,
165                                               Standard_Integer&           theNbCouples);
166
167   //! Performs the advanced intersection of the triangles.
168   Standard_EXPORT Standard_Boolean PerformMaillage(const TColStd_Array1OfReal& theUPars1,
169                                                    const TColStd_Array1OfReal& theVPars1,
170                                                    const TColStd_Array1OfReal& theUPars2,
171                                                    const TColStd_Array1OfReal& theVPars2,
172                                                    const Standard_Real         theDeflTol1,
173                                                    const Standard_Real         theDeflTol2,
174                                                    IntPolyh_PMaillageAffinage& theMaillage);
175
176   //! Performs the advanced intersection of the triangles.
177   Standard_EXPORT Standard_Boolean PerformMaillage(const TColStd_Array1OfReal& theUPars1,
178                                                    const TColStd_Array1OfReal& theVPars1,
179                                                    const TColStd_Array1OfReal& theUPars2,
180                                                    const TColStd_Array1OfReal& theVPars2,
181                                                    const Standard_Real         theDeflTol1,
182                                                    const Standard_Real         theDeflTol2,
183                                                    const IntPolyh_ArrayOfPointNormal& thePoints1,
184                                                    const IntPolyh_ArrayOfPointNormal& thePoints2,
185                                                    const Standard_Boolean      theIsFirstFwd,
186                                                    const Standard_Boolean      theIsSecondFwd,
187                                                    IntPolyh_PMaillageAffinage& theMaillage);
188
189   //! Clears the arrays from the duplicate couples, keeping only one instance of it.
190   Standard_EXPORT void MergeCouples(IntPolyh_ListOfCouples& theArrayFF,
191                                     IntPolyh_ListOfCouples& theArrayFR,
192                                     IntPolyh_ListOfCouples& theArrayRF,
193                                     IntPolyh_ListOfCouples& theArrayRR) const;
194
195
196 private: //! @name Fields
197
198   // Inputs
199   Handle(Adaptor3d_HSurface) mySurf1;          //!< First surface
200   Handle(Adaptor3d_HSurface) mySurf2;          //!< Second surface
201   Standard_Integer myNbSU1;                    //!< Number of samples in U direction for first surface
202   Standard_Integer myNbSV1;                    //!< Number of samples in V direction for first surface
203   Standard_Integer myNbSU2;                    //!< Number of samples in U direction for second surface
204   Standard_Integer myNbSV2;                    //!< Number of samples in V direction for second surface
205   // Results
206   Standard_Boolean myIsDone;                   //!< State of the operation
207   IntPolyh_ArrayOfSectionLines mySectionLines; //!< Section lines
208   IntPolyh_ArrayOfTangentZones myTangentZones; //!< Tangent zones
209 };
210
211 #endif // _IntPolyh_Intersection_HeaderFile