0031668: Visualization - WebGL sample doesn't work on Emscripten 1.39
[occt.git] / src / BRepAlgo / BRepAlgo_Section.hxx
1 // Created on: 1994-02-18
2 // Created by: Remi LEQUETTE
3 // Copyright (c) 1994-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 _BRepAlgo_Section_HeaderFile
18 #define _BRepAlgo_Section_HeaderFile
19
20 #include <Standard.hxx>
21 #include <Standard_DefineAlloc.hxx>
22 #include <Standard_Handle.hxx>
23
24 #include <Standard_Boolean.hxx>
25 #include <BRepAlgo_BooleanOperation.hxx>
26 class TopoDS_Shape;
27 class gp_Pln;
28 class Geom_Surface;
29
30
31 //! Construction of the section lines between two shapes.
32 //! For this Boolean operation, each face of the first
33 //! shape is intersected by each face of the second
34 //! shape. The resulting intersection edges are brought
35 //! together into a compound object, but not chained or
36 //! grouped into wires.
37 //! Computation of the intersection of two Shapes or Surfaces
38 //! The two parts involved in this Boolean operation may
39 //! be defined from geometric surfaces: the most common
40 //! use is the computation of the planar section of a shape.
41 //! A Section object provides the framework for:
42 //! - defining the shapes to be intersected, and the
43 //! computation options,
44 //! - implementing the construction algorithm, and
45 //! - consulting the result.
46 //! Example : giving two shapes S1,S2 accessing faces,
47 //! let compute the section edges R on S1,S2,
48 //! performing approximation on new curves,
49 //! performing PCurve on part 1 but not on part 2 :
50 //! Standard_Boolean PerformNow = Standard_False;
51 //! BRepBoolAPI_Section S(S1,S2,PerformNow);
52 //! S.ComputePCurveOn1(Standard_True);
53 //! S.Approximation(Standard_True);
54 //! S.Build();
55 //! TopoDS_Shape R = S.Shape();
56 //! On Null Shapes of geometries, NotDone() is called.
57 class Standard_DEPRECATED("This class is deprecated - BRepAlgoAPI_Section should be used instead")
58   BRepAlgo_Section  : public BRepAlgo_BooleanOperation
59 {
60 public:
61
62   DEFINE_STANDARD_ALLOC
63
64   
65   Standard_EXPORT BRepAlgo_Section(const TopoDS_Shape& Sh1, const TopoDS_Shape& Sh2, const Standard_Boolean PerformNow = Standard_True);
66   
67   Standard_EXPORT BRepAlgo_Section(const TopoDS_Shape& Sh, const gp_Pln& Pl, const Standard_Boolean PerformNow = Standard_True);
68   
69   Standard_EXPORT BRepAlgo_Section(const TopoDS_Shape& Sh, const Handle(Geom_Surface)& Sf, const Standard_Boolean PerformNow = Standard_True);
70   
71   Standard_EXPORT BRepAlgo_Section(const Handle(Geom_Surface)& Sf, const TopoDS_Shape& Sh, const Standard_Boolean PerformNow = Standard_True);
72   
73   //! This and the above algorithms construct a framework for computing the section lines of
74   //! - the two shapes Sh1 and Sh2, or
75   //! - the shape Sh and the plane Pl, or
76   //! - the shape Sh and the surface Sf, or
77   //! - the surface Sf and the shape Sh, or
78   //! - the two surfaces Sf1 and Sf2,
79   //! and builds the result if PerformNow equals true, its
80   //! default value. If PerformNow equals false, the
81   //! intersection will be computed later by the function Build.
82   //! The constructed shape will be returned by the
83   //! function Shape. This is a compound object
84   //! composed of edges. These intersection edges may be built:
85   //! - on new intersection lines, or
86   //! - on coincident portions of edges in the two intersected shapes.
87   //! These intersection edges are independent: they
88   //! are not chained or grouped in wires.
89   //! If no intersection edge exists, the result is an empty compound object.
90   //! Note that other objects than TopoDS_Shape
91   //! shapes involved in these syntaxes are converted
92   //! into faces or shells before performing the
93   //! computation of the intersection. A shape resulting
94   //! from this conversion can be retrieved with the
95   //! function Shape1 or Shape2.
96   //! Parametric 2D curves on intersection edges
97   //! No parametric 2D curve (pcurve) is defined for
98   //! each elementary edge of the result. To attach such
99   //! parametric curves to the constructed edges you
100   //! may use a constructor with the PerformNow flag
101   //! equal to false; then you use:
102   //! - the function ComputePCurveOn1 to ask for the
103   //! additional computation of a pcurve in the
104   //! parametric space of the first shape,
105   //! - the function ComputePCurveOn2 to ask for the
106   //! additional computation of a pcurve in the
107   //! parametric space of the second shape,
108   //! - in the end, the function Build to construct the result.
109   //! Note that as a result, pcurves will only be added on
110   //! edges built on new intersection lines.
111   //! Approximation of intersection edges
112   //! The underlying 3D geometry attached to each
113   //! elementary edge of the result is:
114   //! - analytic where possible, provided the
115   //! corresponding geometry corresponds to a type
116   //! of analytic curve defined in the Geom package;
117   //! for example, the intersection of a cylindrical
118   //! shape with a plane gives an ellipse or a circle;
119   //! - or elsewhere, given as a succession of points
120   //! grouped together in a BSpline curve of degree 1.
121   //! If you prefer to have an attached 3D geometry
122   //! which is a BSpline approximation of the computed
123   //! set of points on computed elementary intersection
124   //! edges whose underlying geometry is not analytic,
125   //! you may use a constructor with the PerformNow
126   //! flag equal to false. Then you use:
127   //! - the function Approximation to ask for this
128   //! computation option, and
129   //! - the function Build to construct the result.
130   //! Note that as a result, approximations will only be
131   //! computed on edges built on new intersection lines.
132   //! Example
133   //! You may also combine these computation options.
134   //! In the following example:
135   //! - each elementary edge of the computed
136   //! intersection, built on a new intersection line,
137   //! which does not correspond to an analytic Geom
138   //! curve, will be approximated by a BSpline curve
139   //! whose degree is not greater than 8.
140   //! - each elementary edge built on a new intersection line, will have:
141   //! - a pcurve in the parametric space of the shape S1,
142   //! - no pcurve in the parametric space of the shape S2.
143   //! // TopoDS_Shape S1 = ... , S2 = ... ;
144   //! Standard_Boolean PerformNow = Standard_False;
145   //! BRepAlgo_Section S ( S1, S2, PerformNow );
146   //! S.ComputePCurveOn1 (Standard_True);
147   //! S.Approximation (Standard_True);
148   //! S.Build();
149   //! TopoDS_Shape R = S.Shape();
150   Standard_EXPORT BRepAlgo_Section(const Handle(Geom_Surface)& Sf1, const Handle(Geom_Surface)& Sf2, const Standard_Boolean PerformNow = Standard_True);
151   
152   //! Initializes the first part
153   Standard_EXPORT void Init1 (const TopoDS_Shape& S1);
154   
155   //! Initializes the first part
156   Standard_EXPORT void Init1 (const gp_Pln& Pl);
157   
158   //! Initializes the first part
159   Standard_EXPORT void Init1 (const Handle(Geom_Surface)& Sf);
160   
161   //! initialize second part
162   Standard_EXPORT void Init2 (const TopoDS_Shape& S2);
163   
164   //! Initializes the second part
165   Standard_EXPORT void Init2 (const gp_Pln& Pl);
166   
167   //! This and the above algorithms
168   //! reinitialize the first and the second parts on which
169   //! this algorithm is going to perform the intersection
170   //! computation. This is done with either: the surface
171   //! Sf, the plane Pl or the shape Sh.
172   //! You use the function Build to construct the result.
173   Standard_EXPORT void Init2 (const Handle(Geom_Surface)& Sf);
174   
175   //! Defines an option for computation of further
176   //! intersections. This computation will be performed by
177   //! the function Build in this framework.
178   //! By default, the underlying 3D geometry attached to
179   //! each elementary edge of the result of a computed intersection is:
180   //! - analytic where possible, provided the
181   //! corresponding geometry corresponds to a type of
182   //! analytic curve defined in the Geom package; for
183   //! example the intersection of a cylindrical shape with
184   //! a plane gives an ellipse or a circle;
185   //! - or elsewhere, given as a succession of points
186   //! grouped together in a BSpline curve of degree 1. If
187   //! Approx equals true, when further computations are
188   //! performed in this framework with the function
189   //! Build, these edges will have an attached 3D
190   //! geometry which is a BSpline approximation of the
191   //! computed set of points.
192   //! Note that as a result, approximations will be computed
193   //! on edges built only on new intersection lines.
194   Standard_EXPORT void Approximation (const Standard_Boolean B);
195   
196   //! Indicates if the Pcurve must be (or not) performed on first part.
197   Standard_EXPORT void ComputePCurveOn1 (const Standard_Boolean B);
198   
199   //! Define options for the computation of further
200   //! intersections which will be performed by the function
201   //! Build in this framework.
202   //! By default, no parametric 2D curve (pcurve) is defined
203   //! for the elementary edges of the result.
204   //! If ComputePCurve1 equals true, further computations
205   //! performed in this framework with the function Build
206   //! will attach an additional pcurve in the parametric
207   //! space of the first shape to the constructed edges.
208   //! If ComputePCurve2 equals true, the additional pcurve
209   //! will be attached to the constructed edges in the
210   //! parametric space of the second shape.
211   //! These two functions may be used together.
212   //! Note that as a result, pcurves will only be added onto
213   //! edges built on new intersection lines.
214   Standard_EXPORT void ComputePCurveOn2 (const Standard_Boolean B);
215   
216   //! Performs the computation of the section lines
217   //! between the two parts defined at the time of
218   //! construction of this framework or reinitialized with the
219   //! Init1 and Init2 functions.
220   //! The constructed shape will be returned by the function
221   //! Shape. This is a compound object composed of
222   //! edges. These intersection edges may be built:
223   //! - on new intersection lines, or
224   //! - on coincident portions of edges in the two intersected shapes.
225   //! These intersection edges are independent: they are
226   //! not chained or grouped into wires.
227   //! If no intersection edge exists, the result is an empty compound object.
228   //! The shapes involved in the construction of the section
229   //! lines can be retrieved with the function Shape1 or
230   //! Shape2. Note that other objects than
231   //! TopoDS_Shape shapes given as arguments at the
232   //! construction time of this framework, or to the Init1 or
233   //! Init2 function, are converted into faces or shells
234   //! before performing the computation of the intersection.
235   //! Parametric 2D curves on intersection edges
236   //! No parametric 2D curve (pcurve) is defined for the
237   //! elementary edges of the result. To attach parametric
238   //! curves like this to the constructed edges you have to use:
239   //! - the function ComputePCurveOn1 to ask for the
240   //! additional computation of a pcurve in the
241   //! parametric space of the first shape,
242   //! - the function ComputePCurveOn2 to ask for the
243   //! additional computation of a pcurve in the
244   //! parametric space of the second shape.
245   //! This must be done before calling this function.
246   //! Note that as a result, pcurves are added on edges
247   //! built on new intersection lines only.
248   //! Approximation of intersection edges
249   //! The underlying 3D geometry attached to each
250   //! elementary edge of the result is:
251   //! - analytic where possible provided the corresponding
252   //! geometry corresponds to a type of analytic curve
253   //! defined in the Geom package; for example, the
254   //! intersection of a cylindrical shape with a plane
255   //! gives an ellipse or a circle; or
256   //! - elsewhere, given as a succession of points grouped
257   //! together in a BSpline curve of degree 1.
258   //! If, on computed elementary intersection edges whose
259   //! underlying geometry is not analytic, you prefer to
260   //! have an attached 3D geometry which is a BSpline
261   //! approximation of the computed set of points, you have
262   //! to use the function Approximation to ask for this
263   //! computation option before calling this function.
264   //! You may also have combined these computation
265   //! options: look at the example given above to illustrate
266   //! the use of the constructors.
267   Standard_EXPORT void Build() Standard_OVERRIDE;
268   
269   //! Identifies the ancestor faces of the new
270   //! intersection edge E resulting from the last
271   //! computation performed in this framework, that is,
272   //! the faces of the two original shapes on which the edge E lies:
273   //! - HasAncestorFaceOn1 gives the ancestor face
274   //! in the first shape, and
275   //! These functions return:
276   //! - true if an ancestor face F is found, or
277   //! - false if not.
278   //! An ancestor face is identifiable for the edge E if the
279   //! three following conditions are satisfied:
280   //! - the first part on which this algorithm performed
281   //! its last computation is a shape, that is, it was not
282   //! given as a surface or a plane at the time of
283   //! construction of this algorithm or at a later time by
284   //! the Init1 function,
285   //! - E is one of the elementary edges built by the last
286   //! computation of this section algorithm,
287   //! - the edge E is built on an intersection curve. In
288   //! other words, E is a new edge built on the
289   //! intersection curve, not on edges belonging to the
290   //! intersecting shapes.
291   //! To use these functions properly, you have to test
292   //! the returned Boolean value before using the
293   //! ancestor face: F is significant only if the returned
294   //! Boolean value equals true.
295   Standard_EXPORT Standard_Boolean HasAncestorFaceOn1 (const TopoDS_Shape& E, TopoDS_Shape& F) const;
296   
297   //! Identifies the ancestor faces of the new
298   //! intersection edge E resulting from the last
299   //! computation performed in this framework, that is,
300   //! the faces of the two original shapes on which the edge E lies:
301   //! - HasAncestorFaceOn2 gives the ancestor face in the second shape.
302   //! These functions return:
303   //! - true if an ancestor face F is found, or
304   //! - false if not.
305   //! An ancestor face is identifiable for the edge E if the
306   //! three following conditions are satisfied:
307   //! - the first part on which this algorithm performed
308   //! its last computation is a shape, that is, it was not
309   //! given as a surface or a plane at the time of
310   //! construction of this algorithm or at a later time by
311   //! the Init1 function,
312   //! - E is one of the elementary edges built by the last
313   //! computation of this section algorithm,
314   //! - the edge E is built on an intersection curve. In
315   //! other words, E is a new edge built on the
316   //! intersection curve, not on edges belonging to the
317   //! intersecting shapes.
318   //! To use these functions properly, you have to test
319   //! the returned Boolean value before using the
320   //! ancestor face: F is significant only if the returned
321   //! Boolean value equals true.
322   Standard_EXPORT Standard_Boolean HasAncestorFaceOn2 (const TopoDS_Shape& E, TopoDS_Shape& F) const;
323
324
325
326
327 protected:
328
329
330
331
332
333 private:
334
335   
336   Standard_EXPORT virtual void InitParameters() Standard_OVERRIDE;
337
338
339   Standard_Boolean myS1Changed;
340   Standard_Boolean myS2Changed;
341   Standard_Boolean myApproxChanged;
342   Standard_Boolean myPCurve1Changed;
343   Standard_Boolean myPCurve2Changed;
344   Standard_Boolean myshapeisnull;
345
346
347 };
348
349
350
351
352
353
354
355 #endif // _BRepAlgo_Section_HeaderFile