0024649: Update user's guide for Boolean operations
[occt.git] / dox / user_guides / modeling_algos / modeling_algos.md
CommitLineData
ba06f8bb 1Modeling Algorithms {#occt_user_guides__modeling_algos}
72b7576f 2=========================
3
e5bd0d98 4@tableofcontents
5
72b7576f 6@section occt_modalg_1 Introduction
7
8@subsection occt_modalg_1_1 The Modeling Algorithms Module
9
10
11This manual explains how to use the Modeling Algorithms. It provides basic documentation on modeling algorithms. For advanced information on Modeling Algorithms, see our offerings on our web site at <a href="http://www.opencascade.org/support/training/">www.opencascade.org/support/training/</a>
12
13The Modeling Algorithms module brings together a wide range of topological algorithms used in modeling. Along with these tools, you will find the geometric algorithms, which they call.
14
15The algorithms available are divided into:
16 * Geometric tools
17 * Topological tools
18 * The Topology API
19
20@subsection occt_modalg_1_2 The Topology API
21
dba69de2 22The Topology API of Open CASCADE Technology (**OCCT**) includes the following six packages:
72b7576f 23
24 * BRepAlgoAPI
25 * BRepBuilderAPI
26 * BRepFilletAPI
27 * BRepFeat
28 * BRepOffsetAPI
29 * BRepPrimAPI
30
31The classes in these six packages provide the user with a simple and powerful interface.
32 * A simple interface: a function call works ideally,
33 * A powerful interface: including error handling and access to extra information provided by the algorithms.
34
35As an example, the class BRepBuilderAPI_MakeEdge can be used to create a linear edge from two points.
36
37~~~~~
38gp_Pnt P1(10,0,0), P2(20,0,0);
39TopoDS_Edge E = BRepBuilderAPI_MakeEdge(P1,P2);
40~~~~~
41
42This is the simplest way to create edge E from two points P1, P2, but the developer can test for errors when he is not as confident of the data as in the previous example.
43
44~~~~~
45#include <gp_Pnt.hxx>
46#include <TopoDS_Edge.hxx>
47#include <BRepBuilderAPI_MakeEdge.hxx>
48void EdgeTest()
49{
50gp_Pnt P1;
51gp_Pnt P2;
52BRepBuilderAPI_MakeEdge ME(P1,P2);
53if (!ME.IsDone())
54{
55// doing ME.Edge() or E = ME here
56// would raise StdFail_NotDone
57Standard_DomainError::Raise
58(“ProcessPoints::Failed to createan edge”);
59}
60TopoDS_Edge E = ME;
61}
62~~~~~
63
64In this example an intermediary object ME has been introduced. This can be tested for the completion of the function before accessing the result. More information on **error handling** in the topology programming interface can be found in the next section.
65
66BRepBuilderAPI_MakeEdge provides valuable information. For example, when creating an edge from two points, two vertices have to be created from the points. Sometimes you may be interested in getting these vertices quickly without exploring the new edge. Such information can be provided when using a class. The following example shows a function creating an edge and two vertices from two points.
67
68~~~~~
e5bd0d98 69void MakeEdgeAndVertices(const gp_Pnt& P1,
70const gp_Pnt& P2,
71TopoDS_Edge& E,
72TopoDS_Vertex& V1,
73TopoDS_Vertex& V2)
72b7576f 74{
75BRepBuilderAPI_MakeEdge ME(P1,P2);
76if (!ME.IsDone()) {
77Standard_DomainError::Raise
78(“MakeEdgeAndVerices::Failed to create an edge”);
79}
80E = ME;
81V1 = ME.Vextex1();
82V2 = ME.Vertex2();
83~~~~~
84
85The BRepBuilderAPI_MakeEdge class provides the two methods Vertex1 and Vertex2, which return the two vertices used to create the edge.
86
87How can BRepBuilderAPI_MakeEdge be both a function and a class? It can do this because it uses the casting capabilities of C++. The BRepBuilderAPI_MakeEdge class has a method called Edge; in the previous example the line E = ME could have been written.
88
89~~~~~
90E = ME.Edge();
91~~~~~
92
dba69de2 93This instruction tells the C++ compiler that there is an **implicit casting** of a *BRepBuilderAPI_MakeEdge* into a *TopoDS_Edge* using the *Edge* method. It means this method is automatically called when a *BRepBuilderAPI_MakeEdge* is found where a *TopoDS_Edge* is required.
72b7576f 94
95This feature allows you to provide classes, which have the simplicity of function calls when required and the power of classes when advanced processing is necessary. All the benefits of this approach are explained when describing the topology programming interface classes.
96
97
98@subsubsection occt_modalg_1_2_1 Error Handling in the Topology API
99
100A method can report an error in the two following situations:
101 * The data or arguments of the method are incorrect, i.e. they do not respect the restrictions specified by the methods in its specifications. Typical example: creating a linear edge from two identical points is likely to lead to a zero divide when computing the direction of the line.
102 * Something unexpected happened. This situation covers every error not included in the first category. Including: interruption, programming errors in the method or in another method called by the first method, bad specifications of the arguments (i.e. a set of arguments that was not expected to fail).
103
104The second situation is supposed to become increasingly exceptional as a system is debugged and it is handled by the **exception mechanism**. Using exceptions avoids handling error statuses in the call to a method: a very cumbersome style of programming.
105
dba69de2 106In the first situation, an exception is also supposed to be raised because the calling method should have verified the arguments and if it did not do so, there is a bug. For example if before calling *MakeEdge* you are not sure that the two points are non-identical, this situation must be tested.
72b7576f 107
108Making those validity checks on the arguments can be tedious to program and frustrating as you have probably correctly surmised that the method will perform the test twice. It does not trust you.
109As the test involves a great deal of computation, performing it twice is also time-consuming.
110
dba69de2 111Consequently, you might be tempted to adopt the highly inadvisable style of programming illustrated in the following example:
72b7576f 112
113~~~~~
114#include <Standard_ErrorHandler.hxx>
115try {
116TopoDS_Edge E = BRepBuilderAPI_MakeEdge(P1,P2);
117// go on with the edge
118}
119catch {
120// process the error.
121}
122~~~~~
123
dba69de2 124To help the user, the Topology API classes only raise the exception *StdFail_NotDone*. Any other exception means that something happened which was unforeseen in the design of this API.
72b7576f 125
dba69de2 126The *NotDone* exception is only raised when the user tries to access the result of the computation and the original data is corrupted. At the construction of the class instance, if the algorithm cannot be completed, the internal flag *NotDone* is set. This flag can be tested and in some situations a more complete description of the error can be queried. If the user ignores the *NotDone* status and tries to access the result, an exception is raised.
72b7576f 127
128~~~~~
129BRepBuilderAPI_MakeEdge ME(P1,P2);
130if (!ME.IsDone()) {
131// doing ME.Edge() or E = ME here
132// would raise StdFail_NotDone
133Standard_DomainError::Raise
134(“ProcessPoints::Failed to create an edge”);
135}
136TopoDS_Edge E = ME;
137~~~~~
138
139@section occt_modalg_2 Geometric Tools
140
141@subsection occt_modalg_2_1 Overview
142
143Open CASCADE Technology geometric tools include:
144
145 * Computation of intersections
146 * Interpolation laws
147 * Computation of curves and surfaces from constraints
148 * Computation of lines and circles from constraints
149 * Projections
150
151@subsection occt_modalg_2_2 Intersections
152
dba69de2 153The *Geom2dAPI_InterCurveCurve* class allows the evaluation of the intersection points (*gp_Pnt2d*) between two geometric curves (*Geom2d_Curve*) and the evaluation of the points of self-intersection of a curve.
72b7576f 154
e5bd0d98 155@image html /user_guides/modeling_algos/images/modeling_algos_image003.png "Intersection and self-intersection of curves"
156@image latex /user_guides/modeling_algos/images/modeling_algos_image003.png "Intersection and self-intersection of curves"
72b7576f 157
158In both cases, the algorithm requires a value for the tolerance (Standard_Real) for the confusion between two points. The default tolerance value used in all constructors is *1.0e-6.*
159
e5bd0d98 160@image html /user_guides/modeling_algos/images/modeling_algos_image004.png "Intersection and tangent intersection"
161@image latex /user_guides/modeling_algos/images/modeling_algos_image004.png "Intersection and tangent intersection"
72b7576f 162
163The algorithm returns a point in the case of an intersection and a segment in the case of tangent intersection.
164
165@subsubsection occt_modalg_2_2_1 Geom2dAPI_InterCurveCurve
166
167This class may be instantiated either for intersection of curves C1 and C2.
168~~~~~
169Geom2dAPI_InterCurveCurve Intersector(C1,C2,tolerance);
170~~~~~
171
172or for self-intersection of curve C3.
173~~~~~
174Geom2dAPI_InterCurveCurve Intersector(C3,tolerance);
175~~~~~
176
177~~~~~
178Standard_Integer N = Intersector.NbPoints();
179~~~~~
180Calls the number of intersection points
181
182To select the desired intersection point, pass an integer index value in argument.
183~~~~~
184gp_Pnt2d P = Intersector.Point(Index);
185~~~~~
186
dba69de2 187To call the number of intersection segments, use
72b7576f 188~~~~~
189Standard_Integer M = Intersector.NbSegments();
190~~~~~
191
72b7576f 192To select the desired intersection segment pass integer index values in argument.
193~~~~~
194Handle(Geom2d_Curve) Seg1, Seg2;
195Intersector.Segment(Index,Seg1,Seg2);
196// if intersection of 2 curves
197Intersector.Segment(Index,Seg1);
198// if self-intersection of a curve
199~~~~~
200
201If you need access to a wider range of functionalities the following method will return the algorithmic object for the calculation of intersections:
202
203~~~~~
e5bd0d98 204Geom2dInt_GInter& TheIntersector = Intersector.Intersector();
72b7576f 205~~~~~
206
207@subsubsection occt_modalg_2_2_2 Intersection of Curves and Surfaces
dba69de2 208The *GeomAPI_IntCS* class is used to compute the intersection points between a curve and a surface.
72b7576f 209
210This class is instantiated as follows:
211~~~~~
212GeomAPI_IntCS Intersector(C, S);
213~~~~~
214
e5bd0d98 215To call the number of intersection points, use:
72b7576f 216~~~~~
217Standard_Integer nb = Intersector.NbPoints();
218~~~~~
e5bd0d98 219
72b7576f 220
221~~~~~
e5bd0d98 222gp_Pnt& P = Intersector.Point(Index);
72b7576f 223~~~~~
224
dba69de2 225Where *Index* is an integer between 1 and *nb*, calls the intersection points.
72b7576f 226
227@subsubsection occt_modalg_2_2_3 Intersection of two Surfaces
dba69de2 228The *GeomAPI_IntSS* class is used to compute the intersection of two surfaces from *Geom_Surface* with respect to a given tolerance.
72b7576f 229
230This class is instantiated as follows:
231~~~~~
232GeomAPI_IntSS Intersector(S1, S2, Tolerance);
233~~~~~
dba69de2 234Once the *GeomAPI_IntSS* object has been created, it can be interpreted.
72b7576f 235
236~~~~~
237Standard_Integer nb = Intersector. NbLines();
238~~~~~
239Calls the number of intersection curves.
240
241~~~~~
242Handle(Geom_Curve) C = Intersector.Line(Index)
243~~~~~
dba69de2 244Where *Index* is an integer between 1 and *nb*, calls the intersection curves.
72b7576f 245
246@subsection occt_modalg_2_3 Interpolations
247*Interpolation* provides functionalities for interpolating BSpline curves, whether in 2D, using *Geom2dAPI_Interpolate*, or 3D using *GeomAPI_Interpolate*.
248
249
250@subsubsection occt_modalg_2_3_1 Geom2dAPI_Interpolate
dba69de2 251This class is used to interpolate a BSplineCurve passing through an array of points. If tangency is not requested at the point of interpolation, continuity will be *C2*. If tangency is requested at the point, continuity will be *C1*. If Periodicity is requested, the curve will be closed and the junction will be the first point given. The curve will then have a continuity of *C1* only.
72b7576f 252This class may be instantiated as follows:
253~~~~~
254Geom2dAPI_Interpolate
e5bd0d98 255(const Handle_TColgp_HArray1OfPnt2d& Points,
72b7576f 256const Standard_Boolean PeriodicFlag,
257const Standard_Real Tolerance);
258
259Geom2dAPI_Interpolate Interp(Points, Standard_False,
dba69de2 260 Precision::Confusion());
72b7576f 261~~~~~
262
263
264It is possible to call the BSpline curve from the object defined above it.
265~~~~~
266Handle(Geom2d_BSplineCurve) C = Interp.Curve();
267~~~~~
268
dba69de2 269Note that the *Handle(Geom2d_BSplineCurve)* operator has been redefined by the method *Curve()*. Consequently, it is unnecessary to pass via the construction of an intermediate object of the *Geom2dAPI_Interpolate* type and the following syntax is correct.
72b7576f 270
271~~~~~
272Handle(Geom2d_BSplineCurve) C =
273Geom2dAPI_Interpolate(Points,
dba69de2 274 Standard_False,
275 Precision::Confusion());
72b7576f 276~~~~~
277
278@subsubsection occt_modalg_2_3_2 GeomAPI_Interpolate
279
280This class may be instantiated as follows:
281~~~~~
282GeomAPI_Interpolate
e5bd0d98 283(const Handle_TColgp_HArray1OfPnt& Points,
72b7576f 284const Standard_Boolean PeriodicFlag,
285const Standard_Real Tolerance);
286
287GeomAPI_Interpolate Interp(Points, Standard_False,
dba69de2 288 Precision::Confusion());
72b7576f 289~~~~~
290
291It is possible to call the BSpline curve from the object defined above it.
292~~~~~
293Handle(Geom_BSplineCurve) C = Interp.Curve();
294~~~~~
dba69de2 295Note that the *Handle(Geom_BSplineCurve)* operator has been redefined by the method *Curve()*. Thus, it is unnecessary to pass via the construction of an intermediate object of the *GeomAPI_Interpolate* type and the following syntax is correct.
72b7576f 296
297Handle(Geom_BSplineCurve) C =
298 GeomAPI_Interpolate(Points,
299 Standard_False,
300 1.0e-7);
301
302Boundary conditions may be imposed with the method Load.
303~~~~~
304GeomAPI_Interpolate AnInterpolator
305(Points, Standard_False, 1.0e-5);
306AnInterpolator.Load (StartingTangent, EndingTangent);
307~~~~~
308
309@subsection occt_modalg_2_4 Lines and Circles from Constraints
310
dba69de2 311There are two packages to create lines and circles from constraints: *Geom2dGcc* and *GccAna*. *Geom2dGcc* deals with reference-handled geometric objects from the *Geom2d* package, while *GccAna* deals with value-handled geometric objects from the *gp* package.
72b7576f 312
313The *Geom2dGcc* package solves geometric constructions of lines and circles expressed by constraints such as tangency or parallelism, that is, a constraint expressed in geometric terms. As a simple example the following figure shows a line which is constrained to pass through a point and be tangent to a circle.
314
e5bd0d98 315@image html /user_guides/modeling_algos/images/modeling_algos_image005.png "A constrained line"
316@image latex /user_guides/modeling_algos/images/modeling_algos_image005.png "A constrained line"
72b7576f 317
dba69de2 318The *Geom2dGcc* package focuses on algorithms; it is useful for finding results, but it does not offer any management or modification functions, which could be applied to the constraints or their arguments. This package is designed to offer optimum performance, both in rapidity and precision. Trivial cases (for example, a circle centered on one point and passing through another) are not treated.
72b7576f 319
dba69de2 320The *Geom2dGcc* package deals only with 2d objects from the *Geom2d* package. These objects are the points, lines and circles available.
72b7576f 321
dba69de2 322All other lines such as Bezier curves and conic sections except for circles are considered general curves and must be differentiable twice.
72b7576f 323
dba69de2 324The *GccAna* package deals with points, lines, and circles from the *gp* package. Apart from constructors for lines and circles, it also allows the creation of conics from the bisection of other geometric objects.
72b7576f 325
326@subsection occt_modalg_2_5 Provided algorithms
327
328The following analytic algorithms using value-handled entities for creation of 2D lines or circles with geometric constraints are available:
329
330 * circle tangent to three elements (lines, circles, curves, points),
331 * circle tangent to two elements and having a radius,
332 * circle tangent to two elements and centered on a third element,
333 * circle tangent to two elements and centered on a point,
334 * circle tangent to one element and centered on a second,
335 * bisector of two points,
336 * bisector of two lines,
337 * bisector of two circles,
338 * bisector of a line and a point,
339 * bisector of a circle and a point,
340 * bisector of a line and a circle,
341 * line tangent to two elements (points, circles, curves),
342 * line tangent to one element and parallel to a line,
343 * line tangent to one element and perpendicular to a line,
344 * line tangent to one element and forming angle with a line.
345
346@subsection occt_modalg_2_6 Types of algorithms
347There are three categories of available algorithms, which complement each other:
348 * analytic,
349 * geometric,
350 * iterative.
351
352An analytic algorithm will solve a system of equations, whereas a geometric algorithm works with notions of parallelism, tangency, intersection and so on.
353
354Both methods can provide solutions. An iterative algorithm, however, seeks to refine an approximate solution.
355
356@subsection occt_modalg_2_7 Performance factors
357
358The appropriate algorithm is the one, which reaches a solution of the required accuracy in the least time. Only the solutions actually requested by the user should be calculated. A simple means to reduce the number of solutions is the notion of a &quot;qualifier&quot;. There are four qualifiers, which are:
359
360 * Unqualified: the position of the solution is undefined with respect to this argument.
361 * Enclosing: the solution encompasses this argument.
362 * Enclosed: the solution is encompassed by this argument.
363 * Outside: the solution and argument are outside each other.
364
365
366@subsection occt_modalg_2_8 Conventions
367
368@subsubsection occt_modalg_2_8_1 Exterior/Interior
369It is not hard to define the interior and exterior of a circle. As is shown in the following diagram, the exterior is indicated by the sense of the binormal, that is to say the right side according to the sense of traversing the circle. The left side is therefore the interior (or &quot;material&quot;).
370
e5bd0d98 371@image html /user_guides/modeling_algos/images/modeling_algos_image006.png "Exterior/Interior of a Circle"
372@image latex /user_guides/modeling_algos/images/modeling_algos_image006.png "Exterior/Interior of a Circle"
72b7576f 373
374By extension, the interior of a line or any open curve is defined as the left side according to the passing direction, as shown in the following diagram:
375
e5bd0d98 376@image html /user_guides/modeling_algos/images/modeling_algos_image007.png "Exterior/Interior of a Line and a Curve"
377@image latex /user_guides/modeling_algos/images/modeling_algos_image007.png "Exterior/Interior of a Line and a Curve"
72b7576f 378
379@subsubsection occt_modalg_2_8_2 Orientation of a Line
380It is sometimes necessary to define in advance the sense of travel along a line to be created. This sense will be from first to second argument.
381
382The following figure shows a line, which is first tangent to circle C1 which is interior to the line, and then passes through point P1.
383
e5bd0d98 384@image html /user_guides/modeling_algos/images/modeling_algos_image008.png "An Oriented Line"
385@image latex /user_guides/modeling_algos/images/modeling_algos_image008.png "An Oriented Line"
72b7576f 386
387@subsection occt_modalg_2_9 Examples
388
389@subsubsection occt_modalg_2_9_1 Line tangent to two circles
390The following four diagrams illustrate four cases of using qualifiers in the creation of a line. The fifth shows the solution if no qualifiers are given.
391
392Note that the qualifier &quot;Outside&quot; is used to mean &quot;Mutually exterior&quot;.
393
394**Example 1 Case 1**
395
e5bd0d98 396@image html /user_guides/modeling_algos/images/modeling_algos_image009.png "Both circles outside"
397@image latex /user_guides/modeling_algos/images/modeling_algos_image009.png "Both circles outside"
72b7576f 398
399Constraints:
400Tangent and Exterior to C1.
401Tangent and Exterior to C2.
402
403Syntax:
404
405~~~~~
406GccAna_Lin2d2Tan
407 Solver(GccEnt::Outside(C1),
408 GccEnt::Outside(C2),
409 Tolerance);
410~~~~~
411
412**Example 1 Case 2**
413
e5bd0d98 414@image html /user_guides/modeling_algos/images/modeling_algos_image010.png "Both circles enclosed"
415@image latex /user_guides/modeling_algos/images/modeling_algos_image010.png "Both circles enclosed"
72b7576f 416
417Constraints:
418Tangent and Including C1.
419Tangent and Including C2.
420
421Syntax:
422
423~~~~~
424GccAna_Lin2d2Tan
425 Solver(GccEnt::Enclosing(C1),
426 GccEnt::Enclosing(C2),
427 Tolerance);
428~~~~~
429
430**Example 1 Case 3**
431
e5bd0d98 432@image html /user_guides/modeling_algos/images/modeling_algos_image011.png "C1 enclosed, C2 outside"
433@image latex /user_guides/modeling_algos/images/modeling_algos_image011.png "C1 enclosed, C2 outside"
72b7576f 434
435Constraints:
436Tangent and Including C1.
437Tangent and Exterior to C2.
438
439Syntax:
440~~~~~
441GccAna_Lin2d2Tan
442 Solver(GccEnt::Enclosing(C1),
443 GccEnt::Outside(C2),
444 Tolerance);
445~~~~~
446
447**Example 1 Case 4**
448
e5bd0d98 449@image html /user_guides/modeling_algos/images/modeling_algos_image012.png "C1 outside, C2 enclosed"
450@image latex /user_guides/modeling_algos/images/modeling_algos_image012.png "C1 outside, C2 enclosed"
72b7576f 451Constraints:
452Tangent and Exterior to C1.
453Tangent and Including C2.
454
455Syntax:
456~~~~~
457GccAna_Lin2d2Tan
458 Solver(GccEnt::Outside(C1),
459 GccEnt::Enclosing(C2),
460 Tolerance);
461~~~~~
462
463**Example 1 Case 5**
464
e5bd0d98 465@image html /user_guides/modeling_algos/images/modeling_algos_image013.png "With no qualifiers specified"
466@image latex /user_guides/modeling_algos/images/modeling_algos_image013.png "With no qualifiers specified"
72b7576f 467
468Constraints:
469Tangent and Undefined with respect to C1.
470Tangent and Undefined with respect to C2.
471
472Syntax:
473~~~~~
474GccAna_Lin2d2Tan
475 Solver(GccEnt::Unqualified(C1),
476 GccEnt::Unqualified(C2),
477 Tolerance);
478~~~~~
479
480@subsubsection occt_modalg_2_9_2 Circle of given radius tangent to two circles
481The following four diagrams show the four cases in using qualifiers in the creation of a circle.
482
483**Example 2 Case 1**
e5bd0d98 484@image html /user_guides/modeling_algos/images/modeling_algos_image014.png "Both solutions outside"
485@image latex /user_guides/modeling_algos/images/modeling_algos_image014.png "Both solutions outside"
72b7576f 486
487Constraints:
488Tangent and Exterior to C1.
489Tangent and Exterior to C2.
490
491Syntax:
492~~~~~
493GccAna_Circ2d2TanRad
494 Solver(GccEnt::Outside(C1),
495 GccEnt::Outside(C2), Rad, Tolerance);
496~~~~~
497
498**Example 2 Case 2**
499
e5bd0d98 500@image html /user_guides/modeling_algos/images/modeling_algos_image015.png "C2 encompasses C1"
501@image latex /user_guides/modeling_algos/images/modeling_algos_image015.png "C2 encompasses C1"
72b7576f 502
503Constraints:
504Tangent and Exterior to C1.
505Tangent and Included by C2.
506
507Syntax:
508~~~~~
509GccAna_Circ2d2TanRad
510 Solver(GccEnt::Outside(C1),
511 GccEnt::Enclosed(C2), Rad, Tolerance);
512~~~~~
513
514**Example 2 Case 3**
e5bd0d98 515@image html /user_guides/modeling_algos/images/modeling_algos_image016.png "Solutions enclose C2"
516@image latex /user_guides/modeling_algos/images/modeling_algos_image016.png "Solutions enclose C2"
72b7576f 517
518Constraints:
519Tangent and Exterior to C1.
520Tangent and Including C2.
521
522Syntax:
523~~~~~
524GccAna_Circ2d2TanRad
525 Solver(GccEnt::Outside(C1),
526 GccEnt::Enclosing(C2), Rad, Tolerance);
527~~~~~
528
529**Example 2 Case 4**
e5bd0d98 530@image html /user_guides/modeling_algos/images/modeling_algos_image017.png "Solutions enclose C1"
531@image latex /user_guides/modeling_algos/images/modeling_algos_image017.png "Solutions enclose C1"
72b7576f 532
533Constraints:
534Tangent and Enclosing C1.
535Tangent and Enclosing C2.
536
537Syntax:
538~~~~~
539GccAna_Circ2d2TanRad
540 Solver(GccEnt::Enclosing(C1),
541 GccEnt::Enclosing(C2), Rad, Tolerance);
542~~~~~
543
544**Example 2 Case 5**
dba69de2 545
546The following syntax will give all the circles of radius *Rad*, which are tangent to *C1* and *C2* without discrimination of relative position:
72b7576f 547
548~~~~~
549GccAna_Circ2d2TanRad Solver(GccEnt::Unqualified(C1),
550 GccEnt::Unqualified(C2),
551 Rad,Tolerance);
552~~~~~
553
554@subsection occt_modalg_2_10 Algorithms
555
556The objects created by this toolkit are non-persistent.
557
558@subsubsection occt_modalg_2_10_1 Qualifiers
559The *GccEnt* package contains the following package methods:
560 * Unqualified,
561 * Enclosing,
562 * Enclosed,
563 * Outside.
564
565This enables creation of expressions, for example:
566~~~~~
567GccAna_Circ2d2TanRad
568 Solver(GccEnt::Outside(C1),
569 GccEnt::Enclosing(C2), Rad, Tolerance);
570~~~~~
571
572The objective in this case is to find all circles of radius *Rad*, which are tangent to both circle *C1* and *C2*, C1 being outside and C2 being inside.
573
574@subsubsection occt_modalg_2_10_2 General Remarks about Algorithms
575
576We consider the following to be the case:
577 * If a circle passes through a point then the circle is tangential to it.
578 * A distinction is made between the trivial case of the center at a point and the complex case of the center on a line.
579
580@subsubsection occt_modalg_2_10_3 Analytic Algorithms
dba69de2 581*GccAna* package implements analytic algorithms. It deals only with points, lines, and circles from *gp* package. Here is a list of the services offered:
582
583#### Creation of a Line
72b7576f 584
72b7576f 585
586~~~~~
e5bd0d98 587Tangent ( point | circle ) & Parallel ( line )
588Tangent ( point | circle ) & Perpendicular ( line | circle )
589Tangent ( point | circle ) & Oblique ( line )
72b7576f 590Tangent ( 2 { point | circle } )
591Bisector( line | line )
592~~~~~
593
dba69de2 594#### Creation of Conics
595
72b7576f 596
597~~~~~
598Bisector ( point | point )
599Bisector ( line | point )
600Bisector ( circle | point )
601Bisector ( line | line )
602Bisector ( circle | line )
603Bisector ( circle | circle )
604~~~~~
605
dba69de2 606#### Creation of a Circle
607
72b7576f 608~~~~~
e5bd0d98 609Tangent ( point | line | circle ) & Center ( point )
72b7576f 610Tangent ( 3 { point | line | circle } )
e5bd0d98 611Tangent ( 2 { point | line | circle } ) & Radius ( real )
612Tangent ( 2 { point | line | circle } ) & Center ( line | circle )
613Tangent ( point | line | circle ) & Center ( line | circle ) & Radius ( real )
72b7576f 614~~~~~
615
616For each algorithm, the tolerance (and angular tolerance if appropriate) is given as an argument. Calculation is done with the highest precision available from the hardware.
617
618@subsubsection occt_modalg_2_10_4 Geometric Algorithms
619
4ee1bdf4 620*Geom2dGcc* package offers algorithms, which produce 2d lines or circles with geometric constraints. For arguments, it takes curves for which an approximate solution is not requested. A tolerance value on the result is given as a starting parameter. The following services are provided:
72b7576f 621
dba69de2 622#### Creation of a Circle
72b7576f 623
624~~~~~
e5bd0d98 625Tangent ( curve ) & Center ( point )
626Tangent ( curve , point | line | circle | curve ) & Radius ( real )
627Tangent ( 2 {point | line | circle} ) & Center ( curve )
628Tangent ( curve ) & Center ( line | circle | curve ) & Radius ( real )
629Tangent ( point | line | circle ) & Center ( curve ) & Radius ( real )
72b7576f 630~~~~~
631
632All calculations will be done to the highest precision available from the hardware.
633
634@subsubsection occt_modalg_2_10_5 Iterative Algorithms
dba69de2 635*Geom2dGcc* package offers iterative algorithms find a solution by refining an approximate solution. It produces 2d lines or circles with geometric constraints. For all geometric arguments except points, an approximate solution may be given as a starting parameter. The tolerance or angular tolerance value is given as an argument. The following services are provided:
636
637#### Creation of a Line
72b7576f 638
72b7576f 639~~~~~
e5bd0d98 640Tangent ( curve ) & Oblique ( line )
72b7576f 641Tangent ( curve , { point | circle | curve } )
642~~~~~
643
dba69de2 644#### Creation of a Circle
72b7576f 645
646~~~~~
647Tangent ( curve , 2 { point | circle | curve } )
648Tangent ( curve , { point | circle | curve } )
e5bd0d98 649& Center ( line | circle | curve )
72b7576f 650~~~~~
651
652@subsection occt_modalg_2_1 Curves and Surfaces from Constraints
653
654@subsubsection occt_modalg_2_1_1 Fair Curve
655
656*FairCurve* package provides a set of classes to create faired 2D curves or 2D curves with minimal variation in curvature.
657
dba69de2 658#### Creation of Batten Curves
659
72b7576f 660The class Batten allows producing faired curves defined on the basis of one or more constraints on each of the two reference points. These include point, angle of tangency and curvature settings.
661The following constraint orders are available:
662
663 * 0 the curve must pass through a point
664 * 1 the curve must pass through a point and have a given tangent
665 * 2 the curve must pass through a point, have a given tangent and a given curvature.
666
667Only 0 and 1 constraint orders are used.
668The function Curve returns the result as a 2D BSpline curve.
669
dba69de2 670#### Creation of Minimal Variation Curves
671
672The class *MinimalVariation* allows producing curves with minimal variation in curvature at each reference point. The following constraint orders are available:
72b7576f 673
674 * 0 the curve must pass through a point
675 * 1 the curve must pass through a point and have a given tangent
676 * 2 the curve must pass through a point, have a given tangent and a given curvature.
677
678Constraint orders of 0, 1 and 2 can be used. The algorithm minimizes tension, sagging and jerk energy.
679
680The function *Curve* returns the result as a 2D BSpline curve.
681
dba69de2 682#### Specifying the length of the curve
683
72b7576f 684If you want to give a specific length to a batten curve, use:
685
686~~~~~
687b.SetSlidingFactor(L / b.SlidingOfReference())
688~~~~~
689where *b* is the name of the batten curve object
690
dba69de2 691#### Limitations
692
72b7576f 693Free sliding is generally more aesthetically pleasing than constrained sliding.
694However, the computation can fail with values such as angles greater than p/2, because in this case, the length is theoretically infinite.
695
696In other cases, when sliding is imposed and the sliding factor is too large, the batten can collapse.
697
dba69de2 698#### Computation Time
699
72b7576f 700The constructor parameters, *Tolerance* and *NbIterations*, control how precise the computation is, and how long it will take.
701
702@subsubsection occt_modalg_2_11_2 Surfaces from Boundary Curves
703
704The *GeomFill* package provides the following services for creating surfaces from boundary curves:
705
dba69de2 706#### Creation of Bezier surfaces
707
72b7576f 708The class *BezierCurves* allows producing a Bezier surface from contiguous Bezier curves. Note that problems may occur with rational Bezier Curves.
709
dba69de2 710#### Creation of BSpline surfaces
711
72b7576f 712The class *BSplineCurves* allows producing a BSpline surface from contiguous BSpline curves. Note that problems may occur with rational BSplines.
713
dba69de2 714#### Creation of a Pipe
715
716The class *Pipe* allows producing a pipe by sweeping a curve (the section) along another curve (the path). The result is a BSpline surface.
717
718#### Filling a contour
72b7576f 719
72b7576f 720The class *GeomFill_ConstrainedFilling* allows filling a contour defined by two, three or four curves as well as by tangency constraints. The resulting surface is a BSpline.
721
dba69de2 722#### Creation of a Boundary
723
72b7576f 724The class *GeomFill_SimpleBound* allows you defining a boundary for the surface to be constructed.
725
dba69de2 726#### Creation of a Boundary with an adjoining surface
727
72b7576f 728The class *GeomFill_BoundWithSurf* allows defining a boundary for the surface to be constructed. This boundary will already be joined to another surface.
729
dba69de2 730#### Filling styles
731
72b7576f 732The enumerations *FillingStyle* specify the styles used to build the surface. These include:
733
734 * *Stretch* - the style with the flattest patches
735 * *Coons* - a rounded style with less depth than *Curved*
736 * *Curved* - the style with the most rounded patches.
737
e5bd0d98 738@image html /user_guides/modeling_algos/images/modeling_algos_image018.png "Intersecting filleted edges with different radii leave a gap, is filled by a surface"
739@image latex /user_guides/modeling_algos/images/modeling_algos_image018.png "Intersecting filleted edges with different radii leave a gap, is filled by a surface"
72b7576f 740
741
742@subsubsection occt_modalg_2_11_3 Surfaces from curve and point constraints
743The *GeomPlate* package provides the following services for creating surfaces respecting curve and point constraints:
744
dba69de2 745#### Definition of a Framework
746
72b7576f 747The class *BuildPlateSurface* allows creating a framework to build surfaces according to curve and point constraints as well as tolerance settings. The result is returned with the function *Surface*.
748
749Note that you do not have to specify an initial surface at the time of construction. It can be added later or, if none is loaded, a surface will be computed automatically.
750
dba69de2 751#### Definition of a Curve Constraint
752
72b7576f 753The class *CurveConstraint* allows defining curves as constraints to the surface, which you want to build.
754
dba69de2 755#### Definition of a Point Constraint
756
72b7576f 757The class *PointConstraint* allows defining points as constraints to the surface, which you want to build.
758
dba69de2 759#### Applying Geom_Surface to Plate Surfaces
760
72b7576f 761The class *Surface* allows describing the characteristics of plate surface objects returned by **BuildPlateSurface::Surface** using the methods of *Geom_Surface*
762
dba69de2 763#### Approximating a Plate surface to a BSpline
72b7576f 764
dba69de2 765The class *MakeApprox* allows converting a *GeomPlate* surface into a *Geom_BSplineSurface*.
72b7576f 766
e5bd0d98 767@image html /user_guides/modeling_algos/images/modeling_algos_image019.png "Surface generated from four curves and a point"
768@image latex /user_guides/modeling_algos/images/modeling_algos_image019.png "Surface generated from four curves and a point"
72b7576f 769
dba69de2 770Let us create a Plate surface and approximate it from a polyline as a curve constraint and a point constraint
72b7576f 771
772~~~~~
773Standard_Integer NbCurFront=4,
774NbPointConstraint=1;
775gp_Pnt P1(0.,0.,0.);
776gp_Pnt P2(0.,10.,0.);
777gp_Pnt P3(0.,10.,10.);
778gp_Pnt P4(0.,0.,10.);
779gp_Pnt P5(5.,5.,5.);
780BRepBuilderAPI_MakePolygon W;
781W.Add(P1);
782W.Add(P2);
783W.Add(P3);
784W.Add(P4);
785W.Add(P1);
786// Initialize a BuildPlateSurface
787GeomPlate_BuildPlateSurface BPSurf(3,15,2);
788// Create the curve constraints
789BRepTools_WireExplorer anExp;
790for(anExp.Init(W); anExp.More(); anExp.Next())
791{
792TopoDS_Edge E = anExp.Current();
793Handle(BRepAdaptor_HCurve) C = new
794BRepAdaptor_HCurve();
795C-ChangeCurve().Initialize(E);
796Handle(BRepFill_CurveConstraint) Cont= new
797BRepFill_CurveConstraint(C,0);
798BPSurf.Add(Cont);
799}
800// Point constraint
801Handle(GeomPlate_PointConstraint) PCont= new
802GeomPlate_PointConstraint(P5,0);
803BPSurf.Add(PCont);
804// Compute the Plate surface
805BPSurf.Perform();
806// Approximation of the Plate surface
807Standard_Integer MaxSeg=9;
808Standard_Integer MaxDegree=8;
809Standard_Integer CritOrder=0;
810Standard_Real dmax,Tol;
811Handle(GeomPlate_Surface) PSurf = BPSurf.Surface();
812dmax = Max(0.0001,10*BPSurf.G0Error());
813Tol=0.0001;
814GeomPlate_MakeApprox
815Mapp(PSurf,Tol,MaxSeg,MaxDegree,dmax,CritOrder);
816Handle (Geom_Surface) Surf (Mapp.Surface());
817// create a face corresponding to the approximated Plate
818Surface
819Standard_Real Umin, Umax, Vmin, Vmax;
820PSurf-Bounds( Umin, Umax, Vmin, Vmax);
821BRepBuilderAPI_MakeFace MF(Surf,Umin, Umax, Vmin, Vmax);
822~~~~~
823
824@subsection occt_modalg_2_12 Projections
825This package provides functionality for projecting points onto 2D and 3D curves and surfaces.
826
827@subsubsection occt_modalg_2_12_1 Projection of a Point onto a Curve
828*Geom2dAPI_ProjectPointOnCurve* allows calculation of all the normals projected from a point (*gp_Pnt2d*) onto a geometric curve (*Geom2d_Curve*). The calculation may be restricted to a given domain.
829
830
e5bd0d98 831@image html /user_guides/modeling_algos/images/modeling_algos_image020.png "Normals from a point to a curve"
832@image latex /user_guides/modeling_algos/images/modeling_algos_image020.png "Normals from a point to a curve"
dba69de2 833
72b7576f 834
72b7576f 835The curve does not have to be a *Geom2d_TrimmedCurve*. The algorithm will function with any
836class inheriting Geom2d_Curve.
837
838@subsubsection occt_modalg_2_12_2 Geom2dAPI_ProjectPointOnCurve
839This class may be instantiated as in the following example:
840
841~~~~~
842gp_Pnt2d P;
843Handle(Geom2d_BezierCurve) C =
844 new Geom2d_BezierCurve(args);
845Geom2dAPI_ProjectPointOnCurve Projector (P, C);
846~~~~~
847
4ee1bdf4 848To restrict the search for normals to a given domain <i>[U1,U2]</i>, use the following constructor:
72b7576f 849~~~~~
850Geom2dAPI_ProjectPointOnCurve Projector (P, C, U1, U2);
851~~~~~
852Having thus created the *Geom2dAPI_ProjectPointOnCurve* object, we can now interrogate it.
853
dba69de2 854#### Calling the number of solution points
855
72b7576f 856~~~~~
857Standard_Integer NumSolutions = Projector.NbPoints();
858~~~~~
859
dba69de2 860#### Calling the location of a solution point
861
72b7576f 862The solutions are indexed in a range from *1* to *Projector.NbPoints()*. The point, which corresponds to a given *Index* may be found:
863~~~~~
864gp_Pnt2d Pn = Projector.Point(Index);
865~~~~~
866
dba69de2 867#### Calling the parameter of a solution point
868
72b7576f 869For a given point corresponding to a given *Index*:
870
871~~~~~
872Standard_Real U = Projector.Parameter(Index);
873~~~~~
874
875This can also be programmed as:
876
877~~~~~
878Standard_Real U;
879Projector.Parameter(Index,U);
880~~~~~
881
dba69de2 882#### Calling the distance between the start and end points
883
72b7576f 884We can find the distance between the initial point and a point, which corresponds to the given *Index*:
885
886~~~~~
887Standard_Real D = Projector.Distance(Index);
888~~~~~
889
dba69de2 890#### Calling the nearest solution point
891
72b7576f 892
893This class offers a method to return the closest solution point to the starting point. This solution is accessed as follows:
894~~~~~
895gp_Pnt2d P1 = Projector.NearestPoint();
896~~~~~
897
dba69de2 898#### Calling the parameter of the nearest solution point
899
72b7576f 900~~~~~
901Standard_Real U = Projector.LowerDistanceParameter();
902~~~~~
903
dba69de2 904#### Calling the minimum distance from the point to the curve
905
72b7576f 906~~~~~
907Standard_Real D = Projector.LowerDistance();
908~~~~~
909
910@subsubsection occt_modalg_2_12_3 Redefined operators
911
912Some operators have been redefined to find the closest solution.
913
914*Standard_Real()* returns the minimum distance from the point to the curve.
915
916~~~~~
917Standard_Real D = Geom2dAPI_ProjectPointOnCurve (P,C);
918~~~~~
919
920*Standard_Integer()* returns the number of solutions.
921
922~~~~~
923Standard_Integer N =
924Geom2dAPI_ProjectPointOnCurve (P,C);
925~~~~~
926
927*gp_Pnt2d()* returns the nearest solution point.
928
929~~~~~
930gp_Pnt2d P1 = Geom2dAPI_ProjectPointOnCurve (P,C);
931~~~~~
932
933Using these operators makes coding easier when you only need the nearest point. Thus:
934~~~~~
935Geom2dAPI_ProjectPointOnCurve Projector (P, C);
936gp_Pnt2d P1 = Projector.NearestPoint();
937~~~~~
938can be written more concisely as:
939~~~~~
940gp_Pnt2d P1 = Geom2dAPI_ProjectPointOnCurve (P,C);
941~~~~~
942However, note that in this second case no intermediate *Geom2dAPI_ProjectPointOnCurve* object is created, and thus it is impossible to have access to other solution points.
943
944
945@subsubsection occt_modalg_2_12_4 Access to lower-level functionalities
946
947If you want to use the wider range of functionalities available from the *Extrema* package, a call to the *Extrema()* method will return the algorithmic object for calculating extrema. For example:
948
949~~~~~
e5bd0d98 950Extrema_ExtPC2d& TheExtrema = Projector.Extrema();
72b7576f 951~~~~~
952
953@subsubsection occt_modalg_2_12_5 GeomAPI_ProjectPointOnCurve
954
955This class is instantiated as in the following example:
956~~~~~
957gp_Pnt P;
958Handle(Geom_BezierCurve) C =
959 new Geom_BezierCurve(args);
960GeomAPI_ProjectPointOnCurve Projector (P, C);
961~~~~~
962If you wish to restrict the search for normals to the given domain [U1,U2], use the following constructor:
963~~~~~
964GeomAPI_ProjectPointOnCurve Projector (P, C, U1, U2);
965~~~~~
966Having thus created the *GeomAPI_ProjectPointOnCurve* object, you can now interrogate it.
967
dba69de2 968#### Calling the number of solution points
969
72b7576f 970~~~~~
971Standard_Integer NumSolutions = Projector.NbPoints();
972~~~~~
973
dba69de2 974#### Calling the location of a solution point
975
72b7576f 976The solutions are indexed in a range from 1 to *Projector.NbPoints()*. The point, which corresponds to a given index, may be found:
977~~~~~
978gp_Pnt Pn = Projector.Point(Index);
979~~~~~
980
dba69de2 981#### Calling the parameter of a solution point
982
72b7576f 983For a given point corresponding to a given index:
984
985~~~~~
986Standard_Real U = Projector.Parameter(Index);
987~~~~~
988
989This can also be programmed as:
990~~~~~
991Standard_Real U;
992Projector.Parameter(Index,U);
993~~~~~
994
dba69de2 995#### Calling the distance between the start and end point
996
72b7576f 997The distance between the initial point and a point, which corresponds to a given index, may be found:
998~~~~~
999Standard_Real D = Projector.Distance(Index);
1000~~~~~
1001
dba69de2 1002#### Calling the nearest solution point
1003
72b7576f 1004This class offers a method to return the closest solution point to the starting point. This solution is accessed as follows:
1005~~~~~
1006gp_Pnt P1 = Projector.NearestPoint();
1007~~~~~
1008
dba69de2 1009#### Calling the parameter of the nearest solution point
1010
72b7576f 1011~~~~~
1012Standard_Real U = Projector.LowerDistanceParameter();
1013~~~~~
1014
dba69de2 1015#### Calling the minimum distance from the point to the curve
1016
72b7576f 1017~~~~~
1018Standard_Real D = Projector.LowerDistance();
1019~~~~~
1020
dba69de2 1021#### Redefined operators
1022
72b7576f 1023Some operators have been redefined to find the nearest solution.
1024
1025*Standard_Real()* returns the minimum distance from the point to the curve.
1026
1027~~~~~
1028Standard_Real D = GeomAPI_ProjectPointOnCurve (P,C);
1029~~~~~
1030
1031*Standard_Integer()* returns the number of solutions.
1032~~~~~
1033Standard_Integer N = GeomAPI_ProjectPointOnCurve (P,C);
1034~~~~~
1035
1036*gp_Pnt2d()* returns the nearest solution point.
1037
1038~~~~~
1039gp_Pnt P1 = GeomAPI_ProjectPointOnCurve (P,C);
1040~~~~~
1041Using these operators makes coding easier when you only need the nearest point. In this way,
1042
1043~~~~~
1044GeomAPI_ProjectPointOnCurve Projector (P, C);
1045gp_Pnt P1 = Projector.NearestPoint();
1046~~~~~
1047
1048can be written more concisely as:
1049~~~~~
1050gp_Pnt P1 = GeomAPI_ProjectPointOnCurve (P,C);
1051~~~~~
1052In the second case, however, no intermediate *GeomAPI_ProjectPointOnCurve* object is created, and it is impossible to access other solutions points.
1053
dba69de2 1054#### Access to lower-level functionalities
1055
1056If you want to use the wider range of functionalities available from the *Extrema* package, a call to the *Extrema()* method will return the algorithmic object for calculating the extrema. For example:
72b7576f 1057
1058~~~~~
e5bd0d98 1059Extrema_ExtPC& TheExtrema = Projector.Extrema();
72b7576f 1060~~~~~
1061
1062@subsubsection occt_modalg_2_12_6 Projection of a Point on a Surface
1063
1064*GeomAPI_ProjectPointOnSurf* class allows calculation of all normals projected from a point from *gp_Pnt* onto a geometric surface from Geom_Surface.
1065
e5bd0d98 1066@image html /user_guides/modeling_algos/images/modeling_algos_image021.png "Projection of normals from a point to a surface"
1067@image latex /user_guides/modeling_algos/images/modeling_algos_image021.png "Projection of normals from a point to a surface"
72b7576f 1068
72b7576f 1069Note that the surface does not have to be of *Geom_RectangularTrimmedSurface* type.
1070The algorithm will function with any class inheriting Geom_Surface.
1071
1072*GeomAPI_ProjectPointOnSurf* is instantiated as in the following example:
1073~~~~~
1074gp_Pnt P;
1075Handle (Geom_Surface) S = new Geom_BezierSurface(args);
1076GeomAPI_ProjectPointOnSurf Proj (P, S);
1077~~~~~
1078
1079To restrict the search for normals within the given rectangular domain [U1, U2, V1, V2], use the following constructor:
1080
1081~~~~~
1082GeomAPI_ProjectPointOnSurf Proj (P, S, U1, U2, V1, V2);
1083~~~~~
1084
1085The values of U1, U2, V1 and V2 lie at or within their maximum and minimum limits, i.e.:
1086~~~~~
1087Umin <= U1 < U2 <= Umax
1088Vmin <= V1 < V2 <= Vmax
1089~~~~~
1090Having thus created the *GeomAPI_ProjectPointOnSurf* object, you can interrogate it.
1091
dba69de2 1092#### Calling the number of solution points
72b7576f 1093
1094~~~~~
1095Standard_Integer NumSolutions = Proj.NbPoints();
1096~~~~~
1097
dba69de2 1098#### Calling the location of a solution point
1099
72b7576f 1100The solutions are indexed in a range from 1 to *Proj.NbPoints()*. The point corresponding to the given index may be found:
1101
1102~~~~~
1103gp_Pnt Pn = Proj.Point(Index);
1104~~~~~
1105
dba69de2 1106#### Calling the parameters of a solution point
1107
72b7576f 1108For a given point corresponding to the given index:
1109
1110~~~~~
1111Standard_Real U,V;
1112Proj.Parameters(Index, U, V);
1113~~~~~
1114
dba69de2 1115#### Calling the distance between the start and end point
1116
72b7576f 1117
1118The distance between the initial point and a point corresponding to the given index may be found:
1119~~~~~
1120Standard_Real D = Projector.Distance(Index);
1121~~~~~
1122
dba69de2 1123#### Calling the nearest solution point
1124
72b7576f 1125This class offers a method, which returns the closest solution point to the starting point. This solution is accessed as follows:
1126~~~~~
1127gp_Pnt P1 = Proj.NearestPoint();
1128~~~~~
1129
dba69de2 1130#### Calling the parameters of the nearest solution point
1131
72b7576f 1132~~~~~
1133Standard_Real U,V;
1134Proj.LowerDistanceParameters (U, V);
1135~~~~~
1136
dba69de2 1137#### Calling the minimum distance from a point to the surface
1138
72b7576f 1139~~~~~
1140Standard_Real D = Proj.LowerDistance();
1141~~~~~
1142
dba69de2 1143#### Redefined operators
1144
72b7576f 1145Some operators have been redefined to help you find the nearest solution.
1146
1147*Standard_Real()* returns the minimum distance from the point to the surface.
1148
1149~~~~~
1150Standard_Real D = GeomAPI_ProjectPointOnSurf (P,S);
1151~~~~~
1152
1153*Standard_Integer()* returns the number of solutions.
1154
1155~~~~~
1156Standard_Integer N = GeomAPI_ProjectPointOnSurf (P,S);
1157~~~~~
1158
1159*gp_Pnt2d()* returns the nearest solution point.
1160
1161~~~~~
1162gp_Pnt P1 = GeomAPI_ProjectPointOnSurf (P,S);
1163~~~~~
1164
1165Using these operators makes coding easier when you only need the nearest point. In this way,
1166
1167~~~~~
1168GeomAPI_ProjectPointOnSurface Proj (P, S);
1169gp_Pnt P1 = Proj.NearestPoint();
1170~~~~~
1171
1172can be written more concisely as:
1173
1174~~~~~
1175gp_Pnt P1 = GeomAPI_ProjectPointOnSurface (P,S);
1176~~~~~
1177
1178In the second case, however, no intermediate *GeomAPI_ProjectPointOnSurf* object is created, and it is impossible to access other solution points.
1179
1180@subsubsection occt_modalg_2_12_7 Access to lower-level functionalities
1181
dba69de2 1182If you want to use the wider range of functionalities available from the *Extrema* package, a call to the *Extrema()* method will return the algorithmic object for calculating the extrema as follows:
72b7576f 1183
1184~~~~~
e5bd0d98 1185Extrema_ExtPS& TheExtrema = Proj.Extrema();
72b7576f 1186~~~~~
1187
1188
1189@subsubsection occt_modalg_2_12_8 Switching from 2d and 3d Curves
1190The To2d and To3d methods are used to;
1191
dba69de2 1192 * build a 2d curve from a 3d *Geom_Curve* lying on a *gp_Pln* plane
1193 * build a 3d curve from a *Geom2d_Curve* and a *gp_Pln* plane.
72b7576f 1194
1195These methods are called as follows:
1196~~~~~
1197Handle(Geom2d_Curve) C2d = GeomAPI::To2d(C3d, Pln);
1198Handle(Geom_Curve) C3d = GeomAPI::To3d(C2d, Pln);
1199~~~~~
1200
1201
1202@section occt_modalg_3 Topological Tools
1203
1204Open CASCADE Technology topological tools include:
1205
1206 * Standard topological objects combining topological data structure and boundary representation
1207 * Geometric Transformations
1208 * Conversion to NURBS geometry
1209 * Finding Planes
1210 * Duplicating Shapes
1211 * Checking Validity
1212
1213
1214@subsection occt_modalg_3_1 Creation of Standard Topological Objects
1215
1216The standard topological objects include
1217 * Vertices
1218 * Edges
1219 * Wires
1220 * Faces
1221 * Shells
1222 * Solids.
1223
1224There are two root classes for their construction and modification:
1225* The deferred class *BRepBuilderAPI_MakeShape* is the root of all *BRepBuilderAPI* classes, which build shapes. It inherits from the class *BRepBuilderAPI_Command* and provides a field to store the constructed shape.
1226* The deferred *BRepBuilderAPI_ModifyShape* is used as a root for the shape modifications. It inherits *BRepBuilderAPI_MakeShape* and implements the methods used to trace the history of all sub-shapes.
1227
1228@subsubsection occt_modalg_3_1_1 Vertex
1229
1230*BRepBuilderAPI_MakeVertex* creates a new vertex from a 3D point from gp.
1231~~~~~
1232gp_Pnt P(0,0,10);
1233TopoDS_Vertex V = BRepBuilderAPI_MakeVertex(P);
1234~~~~~
1235
1236This class always creates a new vertex and has no other methods.
1237
1238@subsubsection occt_modalg_3_1_2 Edge
1239
1240Use *BRepBuilderAPI_MakeEdge* to create from a curve and vertices. The basic method is to construct an edge from a curve, two vertices, and two parameters. All other constructions are derived from this one. The basic method and its arguments are described first, followed by the other methods. The BRepBuilderAPI_MakeEdge class can provide extra information and return an error status.
1241
dba69de2 1242#### Basic Edge construction
72b7576f 1243
1244~~~~~
1245Handle(Geom_Curve) C = ...; // a curve
1246TopoDS_Vertex V1 = ...,V2 = ...;// two Vertices
1247Standard_Real p1 = ..., p2 = ..;// two parameters
1248TopoDS_Edge E = BRepBuilderAPI_MakeEdge(C,V1,V2,p1,p2);
1249~~~~~
1250
1251where C is the domain of the edge; V1 is the first vertex oriented FORWARD; V2 is the second vertex oriented REVERSED; p1 and p2 are the parameters for the vertices V1 and V2 on the curve. The default tolerance is associated with this edge.
1252
e5bd0d98 1253@image html /user_guides/modeling_algos/images/modeling_algos_image022.png "Basic Edge Construction"
1254@image latex /user_guides/modeling_algos/images/modeling_algos_image022.png "Basic Edge Construction"
72b7576f 1255
1256The following rules apply to the arguments:
1257
1258**The curve**
1259 * Must not be a Null Handle.
1260 * If the curve is a trimmed curve, the basis curve is used.
1261
1262**The vertices**
1263 * Can be null shapes. When V1 or V2 is Null the edge is open in the corresponding direction and the corresponding parameter p1 or p2 must be infinite (i.e p1 is RealFirst(), p2 is RealLast()).
1264 * Must be different vertices if they have different 3d locations and identical vertices if they have the same 3d location (identical vertices are used when the curve is closed).
1265
1266**The parameters**
1267 * Must be increasing and in the range of the curve, i.e.:
e5bd0d98 1268
72b7576f 1269~~~~~
1270 C->FirstParameter() <= p1 < p2 <= C->LastParameter()
1271~~~~~
1272
e5bd0d98 1273 * If the parameters are decreasing, the Vertices are switched, i.e. V2 becomes V1 and V1 becomes V2.
1274 * On a periodic curve the parameters p1 and p2 are adjusted by adding or subtracting the period to obtain p1 in the range of the curve and p2 in the range p1 < p2 <= p1+ Period. So on a parametric curve p2 can be greater than the second parameter, see the figure below.
1275 * Can be infinite but the corresponding vertex must be Null (see above).
1276 * The distance between the Vertex 3d location and the point evaluated on the curve with the parameter must be lower than the default precision.
72b7576f 1277
1278The figure below illustrates two special cases, a semi-infinite edge and an edge on a periodic curve.
1279
e5bd0d98 1280@image html /user_guides/modeling_algos/images/modeling_algos_image023.png "Infinite and Periodic Edges"
1281@image latex /user_guides/modeling_algos/images/modeling_algos_image023.png "Infinite and Periodic Edges"
72b7576f 1282
1283
dba69de2 1284#### Other Edge constructions
1285
72b7576f 1286*BRepBuilderAPI_MakeEdge* class provides methods, which are all simplified calls of the previous one:
1287
1288 * The parameters can be omitted. They are computed by projecting the vertices on the curve.
1289 * 3d points (Pnt from gp) can be given in place of vertices. Vertices are created from the points. Giving vertices is useful when creating connected vertices.
1290 * The vertices or points can be omitted if the parameters are given. The points are computed by evaluating the parameters on the curve.
1291 * The vertices or points and the parameters can be omitted. The first and the last parameters of the curve are used.
1292
1293The five following methods are thus derived from the basic construction:
1294
1295~~~~~
1296Handle(Geom_Curve) C = ...; // a curve
1297TopoDS_Vertex V1 = ...,V2 = ...;// two Vertices
1298Standard_Real p1 = ..., p2 = ..;// two parameters
1299gp_Pnt P1 = ..., P2 = ...;// two points
1300TopoDS_Edge E;
1301// project the vertices on the curve
1302E = BRepBuilderAPI_MakeEdge(C,V1,V2);
1303// Make vertices from points
1304E = BRepBuilderAPI_MakeEdge(C,P1,P2,p1,p2);
1305// Make vertices from points and project them
1306E = BRepBuilderAPI_MakeEdge(C,P1,P2);
1307// Computes the points from the parameters
1308E = BRepBuilderAPI_MakeEdge(C,p1,p2);
1309// Make an edge from the whole curve
1310E = BRepBuilderAPI_MakeEdge(C);
1311~~~~~
1312
1313
1314Six methods (the five above and the basic method) are also provided for curves from the gp package in place of Curve from Geom. The methods create the corresponding Curve from Geom and are implemented for the following classes:
1315
dba69de2 1316*gp_Lin* creates a *Geom_Line*
1317*gp_Circ* creates a *Geom_Circle*
1318*gp_Elips* creates a *Geom_Ellipse*
1319*gp_Hypr* creates a *Geom_Hyperbola*
1320*gp_Parab* creates a *Geom_Parabola*
72b7576f 1321
1322There are also two methods to construct edges from two vertices or two points. These methods assume that the curve is a line; the vertices or points must have different locations.
1323
1324~~~~~
1325
1326TopoDS_Vertex V1 = ...,V2 = ...;// two Vertices
1327gp_Pnt P1 = ..., P2 = ...;// two points
1328TopoDS_Edge E;
1329
1330// linear edge from two vertices
1331E = BRepBuilderAPI_MakeEdge(V1,V2);
1332
1333// linear edge from two points
1334E = BRepBuilderAPI_MakeEdge(P1,P2);
1335~~~~~
1336
dba69de2 1337#### Other information and error status
1338
1339If *BRepBuilderAPI_MakeEdge* is used as a class, it can provide two vertices. This is useful when the vertices were not provided as arguments, for example when the edge was constructed from a curve and parameters. The two methods *Vertex1* and *Vertex2* return the vertices. Note that the returned vertices can be null if the edge is open in the corresponding direction.
72b7576f 1340
1341The *Error* method returns a term of the *BRepBuilderAPI_EdgeError* enumeration. It can be used to analyze the error when *IsDone* method returns False. The terms are:
1342
1343 * **EdgeDone** - No error occurred, *IsDone* returns True.
1344 * **PointProjectionFailed** - No parameters were given, but the projection of the 3D points on the curve failed. This happens if the point distance to the curve is greater than the precision.
1345 * **ParameterOutOfRange** - The given parameters are not in the range *C->FirstParameter()*, *C->LastParameter()*
1346 * **DifferentPointsOnClosedCurve** - The two vertices or points have different locations but they are the extremities of a closed curve.
1347 * **PointWithInfiniteParameter** - A finite coordinate point was associated with an infinite parameter (see the Precision package for a definition of infinite values).
1348 * **DifferentsPointAndParameter** - The distance of the 3D point and the point evaluated on the curve with the parameter is greater than the precision.
1349 * **LineThroughIdenticPoints** - Two identical points were given to define a line (construction of an edge without curve), *gp::Resolution* is used to test confusion .
1350
1351The following example creates a rectangle centered on the origin of dimensions H, L with fillets of radius R. The edges and the vertices are stored in the arrays *theEdges* and *theVertices*. We use class *Array1OfShape* (i.e. not arrays of edges or vertices). See the image below.
1352
e5bd0d98 1353@image html /user_guides/modeling_algos/images/modeling_algos_image024.png "Creating a Wire"
1354@image latex /user_guides/modeling_algos/images/modeling_algos_image024.png "Creating a Wire"
72b7576f 1355
1356~~~~~
1357#include <BRepBuilderAPI_MakeEdge.hxx>
1358#include <TopoDS_Shape.hxx>
1359#include <gp_Circ.hxx>
1360#include <gp.hxx>
1361#include <TopoDS_Wire.hxx>
1362#include <TopTools_Array1OfShape.hxx>
1363#include <BRepBuilderAPI_MakeWire.hxx>
1364
1365// Use MakeArc method to make an edge and two vertices
1366void MakeArc(Standard_Real x,Standard_Real y,
1367Standard_Real R,
1368Standard_Real ang,
e5bd0d98 1369TopoDS_Shape& E,
1370TopoDS_Shape& V1,
1371TopoDS_Shape& V2)
72b7576f 1372{
1373gp_Ax2 Origin = gp::XOY();
1374gp_Vec Offset(x, y, 0.);
1375Origin.Translate(Offset);
1376BRepBuilderAPI_MakeEdge
1377ME(gp_Circ(Origin,R), ang, ang+PI/2);
1378E = ME;
1379V1 = ME.Vertex1();
1380V2 = ME.Vertex2();
1381}
1382
1383TopoDS_Wire MakeFilletedRectangle(const Standard_Real H,
1384const Standard_Real L,
1385const Standard_Real R)
1386{
1387TopTools_Array1OfShape theEdges(1,8);
1388TopTools_Array1OfShape theVertices(1,8);
1389
1390// First create the circular edges and the vertices
1391// using the MakeArc function described above.
1392void MakeArc(Standard_Real, Standard_Real,
1393Standard_Real, Standard_Real,
e5bd0d98 1394TopoDS_Shape&, TopoDS_Shape&, TopoDS_Shape&);
72b7576f 1395
1396Standard_Real x = L/2 - R, y = H/2 - R;
1397MakeArc(x,-y,R,3.*PI/2.,theEdges(2),theVertices(2),
1398theVertices(3));
1399MakeArc(x,y,R,0.,theEdges(4),theVertices(4),
1400theVertices(5));
1401MakeArc(-x,y,R,PI/2.,theEdges(6),theVertices(6),
1402theVertices(7));
1403MakeArc(-x,-y,R,PI,theEdges(8),theVertices(8),
1404theVertices(1));
1405// Create the linear edges
1406for (Standard_Integer i = 1; i <= 7; i += 2)
1407{
1408theEdges(i) = BRepBuilderAPI_MakeEdge
1409(TopoDS::Vertex(theVertices(i)),TopoDS::Vertex
1410(theVertices(i+1)));
1411}
1412// Create the wire using the BRepBuilderAPI_MakeWire
1413BRepBuilderAPI_MakeWire MW;
1414for (i = 1; i <= 8; i++)
1415{
1416MW.Add(TopoDS::Edge(theEdges(i)));
1417}
1418return MW.Wire();
1419}
1420~~~~~
1421
1422@subsubsection occt_modalg_3_1_3 Edge 2D
1423
1424Use *BRepBuilderAPI_MakeEdge2d* class to make edges on a working plane from 2d curves. The working plane is a default value of the *BRepBuilderAPI* package (see the *Plane* methods).
1425
1426*BRepBuilderAPI_MakeEdge2d* class is strictly similar to BRepBuilderAPI_MakeEdge, but it uses 2D geometry from gp and Geom2d instead of 3D geometry.
1427
1428@subsubsection occt_modalg_3_1_4 Polygon
1429
1430*BRepBuilderAPI_MakePolygon* class is used to build polygonal wires from vertices or points. Points are automatically changed to vertices as in *BRepBuilderAPI_MakeEdge*.
1431
1432The basic usage of *BRepBuilderAPI_MakePolygon* is to create a wire by adding vertices or points using the Add method. At any moment, the current wire can be extracted. The close method can be used to close the current wire. In the following example, a closed wire is created from an array of points.
1433
1434~~~~~
1435#include <TopoDS_Wire.hxx>
1436#include <BRepBuilderAPI_MakePolygon.hxx>
1437#include <TColgp_Array1OfPnt.hxx>
1438
e5bd0d98 1439TopoDS_Wire ClosedPolygon(const TColgp_Array1OfPnt& Points)
72b7576f 1440{
1441BRepBuilderAPI_MakePolygon MP;
1442for(Standard_Integer i=Points.Lower();i=Points.Upper();i++)
1443{
1444MP.Add(Points(i));
1445}
1446MP.Close();
1447return MP;
1448}
1449~~~~~
1450
1451Short-cuts are provided for 2, 3, or 4 points or vertices. Those methods have a Boolean last argument to tell if the polygon is closed. The default value is False.
1452
1453Two examples:
1454
1455Example of a closed triangle from three vertices:
1456~~~~~
1457TopoDS_Wire W = BRepBuilderAPI_MakePolygon(V1,V2,V3,Standard_True);
1458~~~~~
1459
1460Example of an open polygon from four points:
1461~~~~~
1462TopoDS_Wire W = BRepBuilderAPI_MakePolygon(P1,P2,P3,P4);
1463~~~~~
1464
dba69de2 1465*BRepBuilderAPI_MakePolygon* class maintains a current wire. The current wire can be extracted at any moment and the construction can proceed to a longer wire. After each point insertion, the class maintains the last created edge and vertex, which are returned by the methods *Edge, FirstVertex* and *LastVertex*.
72b7576f 1466
dba69de2 1467When the added point or vertex has the same location as the previous one it is not added to the current wire but the most recently created edge becomes Null. The *Added* method can be used to test this condition. The *MakePolygon* class never raises an error. If no vertex has been added, the *Wire* is *Null*. If two vertices are at the same location, no edge is created.
72b7576f 1468
1469@subsubsection occt_modalg_3_1_5 Face
1470
1471Use *BRepBuilderAPI_MakeFace* class to create a face from a surface and wires. An underlying surface is constructed from a surface and optional parametric values. Wires can be added to the surface. A planar surface can be constructed from a wire. An error status can be returned after face construction.
1472
dba69de2 1473#### Basic face construction
72b7576f 1474
1475A face can be constructed from a surface and four parameters to determine a limitation of the UV space. The parameters are optional, if they are omitted the natural bounds of the surface are used. Up to four edges and vertices are created with a wire. No edge is created when the parameter is infinite.
1476
1477~~~~~
1478Handle(Geom_Surface) S = ...; // a surface
1479Standard_Real umin,umax,vmin,vmax; // parameters
1480TopoDS_Face F = BRepBuilderAPI_MakeFace(S,umin,umax,vmin,vmax);
1481~~~~~
1482
e5bd0d98 1483@image html /user_guides/modeling_algos/images/modeling_algos_image025.png "Basic Face Construction"
1484@image latex /user_guides/modeling_algos/images/modeling_algos_image025.png "Basic Face Construction"
72b7576f 1485
1486To make a face from the natural boundary of a surface, the parameters are not required:
1487
1488~~~~~
1489Handle(Geom_Surface) S = ...; // a surface
1490TopoDS_Face F = BRepBuilderAPI_MakeFace(S);
1491~~~~~
1492
1493Constraints on the parameters are similar to the constraints in *BRepBuilderAPI_MakeEdge*.
dba69de2 1494 * *umin,umax (vmin,vmax)* must be in the range of the surface and must be increasing.
1495 * On a *U (V)* periodic surface *umin* and *umax (vmin,vmax)* are adjusted.
1496 * *umin, umax, vmin, vmax* can be infinite. There will be no edge in the corresponding direction.
1497
72b7576f 1498
dba69de2 1499#### Other face constructions
72b7576f 1500
72b7576f 1501The two basic constructions (from a surface and from a surface and parameters) are implemented for all the gp package surfaces, which are transformed in the corresponding Surface from Geom.
1502
e5bd0d98 1503| gp package surface | | Geom package surface |
dba69de2 1504| :------------------- | :----------- | :------------- |
1505| *gp_Pln* | | *Geom_Plane* |
1506| *gp_Cylinder* | | *Geom_CylindricalSurface* |
1507| *gp_Cone* | creates a | *Geom_ConicalSurface* |
1508| *gp_Sphere* | | *Geom_SphericalSurface* |
1509| *gp_Torus* | | *Geom_ToroidalSurface* |
72b7576f 1510
1511Once a face has been created, a wire can be added using the Add method. For example, the following code creates a cylindrical surface and adds a wire.
1512
1513~~~~~
1514gp_Cylinder C = ..; // a cylinder
1515TopoDS_Wire W = ...;// a wire
1516BRepBuilderAPI_MakeFace MF(C);
1517MF.Add(W);
1518TopoDS_Face F = MF;
1519~~~~~
1520
dba69de2 1521More than one wire can be added to a face, provided that they do not cross each other and they define only one area on the surface. (Note that this is not checked). The edges on a Face must have a parametric curve description.
72b7576f 1522
1523If there is no parametric curve for an edge of the wire on the Face it is computed by projection.
1524
1525For one wire, a simple syntax is provided to construct the face from the surface and the wire. The above lines could be written:
1526
1527~~~~~
1528TopoDS_Face F = BRepBuilderAPI_MakeFace(C,W);
1529~~~~~
1530
1531A planar face can be created from only a wire, provided this wire defines a plane. For example, to create a planar face from a set of points you can use *BRepBuilderAPI_MakePolygon* and *BRepBuilderAPI_MakeFace*.
1532
1533~~~~~
1534#include <TopoDS_Face.hxx>
1535#include <TColgp_Array1OfPnt.hxx>
1536#include <BRepBuilderAPI_MakePolygon.hxx>
1537#include <BRepBuilderAPI_MakeFace.hxx>
1538
e5bd0d98 1539TopoDS_Face PolygonalFace(const TColgp_Array1OfPnt& thePnts)
72b7576f 1540{
1541BRepBuilderAPI_MakePolygon MP;
1542for(Standard_Integer i=thePnts.Lower();
1543i<=thePnts.Upper(); i++)
1544{
1545MP.Add(thePnts(i));
1546}
1547MP.Close();
1548TopoDS_Face F = BRepBuilderAPI_MakeFace(MP.Wire());
1549return F;
1550}
1551~~~~~
1552
dba69de2 1553The last use of *MakeFace* is to copy an existing face to add new wires. For example the following code adds a new wire to a face:
72b7576f 1554
1555~~~~~
1556TopoDS_Face F = ...; // a face
1557TopoDS_Wire W = ...; // a wire
1558F = BRepBuilderAPI_MakeFace(F,W);
1559~~~~~
1560
dba69de2 1561To add more than one wire an instance of the *BRepBuilderAPI_MakeFace* class can be created with the face and the first wire and the new wires inserted with the Add method.
72b7576f 1562
1563Error status
1564------------
1565The Error method returns an error status, which is a term from the *BRepBuilderAPI_FaceError* enumeration.
1566
1567* *FaceDone* - no error occurred.
1568* *NoFace* - no initialization of the algorithm; an empty constructor was used.
1569* *NotPlanar* - no surface was given and the wire was not planar.
1570* *CurveProjectionFailed* - no curve was found in the parametric space of the surface for an edge.
dba69de2 1571* *ParametersOutOfRange* - the parameters *umin, umax, vmin, vmax* are out of the surface.
72b7576f 1572
1573@subsubsection occt_modalg_3_1_6 Wire
1574The wire is a composite shape built not from a geometry, but by the assembly of edges. *BRepBuilderAPI_MakeWire* class can build a wire from one or more edges or connect new edges to an existing wire.
1575
1576Up to four edges can be used directly, for example:
1577
1578~~~~~
1579TopoDS_Wire W = BRepBuilderAPI_MakeWire(E1,E2,E3,E4);
1580~~~~~
1581
1582For a higher or unknown number of edges the Add method must be used; for example, to build a wire from an array of shapes (to be edges).
1583
1584~~~~~
1585TopTools_Array1OfShapes theEdges;
1586BRepBuilderAPI_MakeWire MW;
1587for (Standard_Integer i = theEdge.Lower();
1588i <= theEdges.Upper(); i++)
1589MW.Add(TopoDS::Edge(theEdges(i));
1590TopoDS_Wire W = MW;
1591~~~~~
1592
1593The class can be constructed with a wire. A wire can also be added. In this case, all the edges of the wires are added. For example to merge two wires:
1594
1595~~~~~
1596#include <TopoDS_Wire.hxx>
1597#include <BRepBuilderAPI_MakeWire.hxx>
1598
e5bd0d98 1599TopoDS_Wire MergeWires (const TopoDS_Wire& W1,
1600const TopoDS_Wire& W2)
72b7576f 1601{
1602BRepBuilderAPI_MakeWire MW(W1);
1603MW.Add(W2);
1604return MW;
1605}
1606~~~~~
1607
1608*BRepBuilderAPI_MakeWire* class connects the edges to the wire. When a new edge is added if one of its vertices is shared with the wire it is considered as connected to the wire. If there is no shared vertex, the algorithm searches for a vertex of the edge and a vertex of the wire, which are at the same location (the tolerances of the vertices are used to test if they have the same location). If such a pair of vertices is found, the edge is copied with the vertex of the wire in place of the original vertex. All the vertices of the edge can be exchanged for vertices from the wire. If no connection is found the wire is considered to be disconnected. This is an error.
1609
1610BRepBuilderAPI_MakeWire class can return the last edge added to the wire (Edge method). This edge can be different from the original edge if it was copied.
1611
1612The Error method returns a term of the *BRepBuilderAPI_WireError* enumeration:
1613*WireDone* - no error occurred.
1614*EmptyWire* - no initialization of the algorithm, an empty constructor was used.
dba69de2 1615*DisconnectedWire* - the last added edge was not connected to the wire.
72b7576f 1616*NonManifoldWire* - the wire with some singularity.
1617
1618@subsubsection occt_modalg_3_1_7 Shell
1619The shell is a composite shape built not from a geometry, but by the assembly of faces.
1620Use *BRepBuilderAPI_MakeShell* class to build a Shell from a set of Faces. What may be important is that each face should have the required continuity. That is why an initial surface is broken up into faces.
1621
1622@subsubsection occt_modalg_3_1_8 Solid
1623The solid is a composite shape built not from a geometry, but by the assembly of shells. Use *BRepBuilderAPI_MakeSolid* class to build a Solid from a set of Shells. Its use is similar to the use of the MakeWire class: shells are added to the solid in the same way that edges are added to the wire in MakeWire.
1624
1625
1626@subsubsection occt_modalg_3_2 Modification Operators
1627
1628@subsubsection occt_modalg_3_2_1 Transformation
1629*BRepBuilderAPI_Transform* class can be used to apply a transformation to a shape (see class *gp_Trsf*). The methods have a boolean argument to copy or share the original shape, as long as the transformation allows (it is only possible for direct isometric transformations). By default, the original shape is shared.
1630
1631The following example deals with the rotation of shapes.
1632
1633~~~~~
1634
1635TopoDS_Shape myShape1 = ...;
1636// The original shape 1
1637TopoDS_Shape myShape2 = ...;
1638// The original shape2
1639gp_Trsf T;
1640T.SetRotation(gp_Ax1(gp_Pnt(0.,0.,0.),gp_Vec(0.,0.,1.)),
16412.*PI/5.);
1642BRepBuilderAPI_Transformation theTrsf(T);
1643theTrsf.Perform(myShape1);
1644TopoDS_Shape myNewShape1 = theTrsf.Shape()
1645theTrsf.Perform(myShape2,Standard_True);
1646// Here duplication is forced
1647TopoDS_Shape myNewShape2 = theTrsf.Shape()
1648~~~~~
1649
1650@subsubsection occt_modalg_3_2_2 Duplication
1651
dba69de2 1652Use the *BRepBuilderAPI_Copy* class to duplicate a shape. A new shape is thus created.
72b7576f 1653In the following example, a solid is copied:
1654
1655~~~~~
1656TopoDS Solid MySolid;
1657....// Creates a solid
1658
1659TopoDS_Solid myCopy = BRepBuilderAPI_Copy(mySolid);
1660~~~~~
1661
1662@section occt_modalg_4 Construction of Primitives
1663@subsection occt_modalg_4_1 Making Primitives
1664@subsubsection occt_modalg_4_1_1 Box
1665
1666BRepPrimAPI_MakeBox class allows building a parallelepiped box. The result is either a Shell or a Solid. There are four ways to build a box:
1667
1668* From three dimensions dx,dy,dz. The box is parallel to the axes and extends for [0,dx] [0,dy] [0,dz].
1669* From a point and three dimensions. The same as above but the point is the new origin.
1670* From two points, the box is parallel to the axes and extends on the intervals defined by the coordinates of the two points.
1671* From a system of axes (gp_Ax2) and three dimensions. Same as the first way but the box is parallel to the given system of axes.
1672
1673An error is raised if the box is flat in any dimension using the default precision. The following code shows how to create a box:
1674~~~~~
1675TopoDS_Solid theBox = BRepPrimAPI_MakeBox(10.,20.,30.);
1676~~~~~
1677
1678The four methods to build a box are shown in the figure:
1679
e5bd0d98 1680@image html /user_guides/modeling_algos/images/modeling_algos_image026.png "Making Boxes"
1681@image latex /user_guides/modeling_algos/images/modeling_algos_image026.png "Making Boxes"
72b7576f 1682
1683@subsubsection occt_modalg_4_1_2 Wedge
dba69de2 1684*BRepPrimAPI_MakeWedge* class allows building a wedge, which is a slanted box, i.e. a box with angles. The wedge is constructed in much the same way as a box i.e. from three dimensions dx,dy,dz plus arguments or from an axis system, three dimensions, and arguments.
72b7576f 1685
1686The following figure shows two ways to build wedges. One is to add an ltx dimension, which is the length in x of the face at dy. The second is to add xmin, xmax, zmin, zmax to describe the face at dy.
1687
1688The first method is a particular case of the second with xmin = 0, xmax = ltx, zmin = 0, zmax = dz.
1689To make a centered pyramid you can use xmin = xmax = dx / 2, zmin = zmax = dz / 2.
1690
e5bd0d98 1691@image html /user_guides/modeling_algos/images/modeling_algos_image027.png "Making Wedges"
1692@image latex /user_guides/modeling_algos/images/modeling_algos_image027.png "Making Wedges"
72b7576f 1693
1694@subsubsection occt_modalg_4_1_3 Rotation object
dba69de2 1695*BRepPrimAPI_MakeOneAxis* is a deferred class used as a root class for all classes constructing rotational primitives. Rotational primitives are created by rotating a curve around an axis. They cover the cylinder, the cone, the sphere, the torus, and the revolution, which provides all other curves.
72b7576f 1696
1697The particular constructions of these primitives are described, but they all have some common arguments, which are:
1698
1699 * A system of coordinates, where the Z axis is the rotation axis..
1700 * An angle in the range [0,2*PI].
1701 * A vmin, vmax parameter range on the curve.
1702
1703The result of the OneAxis construction is a Solid, a Shell, or a Face. The face is the face covering the rotational surface. Remember that you will not use the OneAxis directly but one of the derived classes, which provide improved constructions. The following figure illustrates the OneAxis arguments.
1704
e5bd0d98 1705@image html /user_guides/modeling_algos/images/modeling_algos_image028.png "MakeOneAxis arguments"
1706@image latex /user_guides/modeling_algos/images/modeling_algos_image028.png "MakeOneAxis arguments"
72b7576f 1707
1708@subsubsection occt_modalg_4_1_4 Cylinder
dba69de2 1709*BRepPrimAPI_MakeCylinder* class allows creating cylindrical primitives. A cylinder is created either in the default coordinate system or in a given coordinate system (gp_Ax2). There are two constructions:
72b7576f 1710
1711 * Radius and height, to build a full cylinder.
1712 * Radius, height and angle to build a portion of a cylinder.
1713
1714The following code builds the cylindrical face of the figure, which is a quarter of cylinder along the Y axis with the origin at X,Y,Z, a length of DY, and a radius R.
1715
1716~~~~~
1717
1718Standard_Real X = 20, Y = 10, Z = 15, R = 10, DY = 30;
1719// Make the system of coordinates
1720gp_Ax2 axes = gp::ZOX();
1721axes.Translate(gp_Vec(X,Y,Z));
1722TopoDS_Face F =
1723BRepPrimAPI_MakeCylinder(axes,R,DY,PI/2.);
1724~~~~~
e5bd0d98 1725@image html /user_guides/modeling_algos/images/modeling_algos_image029.png "Cylinder"
1726@image latex /user_guides/modeling_algos/images/modeling_algos_image029.png "Cylinder"
72b7576f 1727
1728@subsubsection occt_modalg_4_1_5 Cone
dba69de2 1729*BRepPrimAPI_MakeCone* class allows creating conical primitives. Like a cylinder, a cone is created either in the default coordinate system or in a given coordinate system (gp_Ax2). There are two constructions:
72b7576f 1730
1731 * Two radii and height, to build a full cone. One of the radii can be null to make a sharp cone.
1732 * Radii, height and angle to build a truncated cone.
1733
1734The following code builds the solid cone of the figure, which is located in the default system with radii R1 and R2 and height H.
1735
1736~~~~~
1737Standard_Real R1 = 30, R2 = 10, H = 15;
1738TopoDS_Solid S = BRepPrimAPI_MakeCone(R1,R2,H);
1739~~~~~
1740
e5bd0d98 1741@image html /user_guides/modeling_algos/images/modeling_algos_image030.png "Cone"
1742@image latex /user_guides/modeling_algos/images/modeling_algos_image030.png "Cone"
72b7576f 1743
1744@subsubsection occt_modalg_4_1_6 Sphere
dba69de2 1745*BRepPrimAPI_MakeSphere* class allows creating spherical primitives. Like a cylinder, a sphere is created either in the default coordinate system or in a given coordinate system (gp_Ax2). There are four constructions:
72b7576f 1746
1747 * From a radius - builds a full sphere.
1748 * From a radius and an angle - builds a lune (digon).
1749 * From a radius and two angles - builds a wraparound spherical segment between two latitudes. The angles a1, a2 must follow the relation: PI/2 <= a1 < a2 <= PI/2.
1750 * From a radius and three angles - a combination of two previous methods builds a portion of spherical segment.
1751
1752The following code builds four spheres from a radius and three angles.
1753
1754~~~~~
1755Standard_Real R = 30, ang =
1756 PI/2, a1 = -PI/2.3, a2 = PI/4;
1757TopoDS_Solid S1 = BRepPrimAPI_MakeSphere(R);
1758TopoDS_Solid S2 = BRepPrimAPI_MakeSphere(R,ang);
1759TopoDS_Solid S3 = BRepPrimAPI_MakeSphere(R,a1,a2);
1760TopoDS_Solid S4 = BRepPrimAPI_MakeSphere(R,a1,a2,ang);
1761~~~~~
1762
1763Note that we could equally well choose to create Shells instead of Solids.
1764
e5bd0d98 1765@image html /user_guides/modeling_algos/images/modeling_algos_image031.png "Examples of Spheres"
1766@image latex /user_guides/modeling_algos/images/modeling_algos_image031.png "Examples of Spheres"
72b7576f 1767
1768
1769@subsubsection occt_modalg_4_1_7 Torus
dba69de2 1770*BRepPrimAPI_MakeTorus* class allows creating toroidal primitives. Like the other primitives, a torus is created either in the default coordinate system or in a given coordinate system (gp_Ax2). There are four constructions similar to the sphere constructions:
72b7576f 1771
1772 * Two radii - builds a full torus.
1773 * Two radii and an angle - builds an angular torus segment.
1774 * Two radii and two angles - builds a wraparound torus segment between two radial planes. The angles a1, a2 must follow the relation 0 < a2 - a1 < 2*PI.
1775 * Two radii and three angles - a combination of two previous methods builds a portion of torus segment.
1776
e5bd0d98 1777@image html /user_guides/modeling_algos/images/modeling_algos_image032.png "Examples of Tori"
1778@image latex /user_guides/modeling_algos/images/modeling_algos_image032.png "Examples of Tori"
72b7576f 1779
1780The following code builds four toroidal shells from two radii and three angles.
1781
1782~~~~~
1783Standard_Real R1 = 30, R2 = 10, ang = PI, a1 = 0,
1784 a2 = PI/2;
1785TopoDS_Shell S1 = BRepPrimAPI_MakeTorus(R1,R2);
1786TopoDS_Shell S2 = BRepPrimAPI_MakeTorus(R1,R2,ang);
1787TopoDS_Shell S3 = BRepPrimAPI_MakeTorus(R1,R2,a1,a2);
1788TopoDS_Shell S4 =
1789 BRepPrimAPI_MakeTorus(R1,R2,a1,a2,ang);
1790~~~~~
1791
1792Note that we could equally well choose to create Solids instead of Shells.
1793
1794@subsubsection occt_modalg_4_1_8 Revolution
dba69de2 1795*BRepPrimAPI_MakeRevolution* class allows building a uniaxial primitive from a curve. As other uniaxial primitives it can be created in the default coordinate system or in a given coordinate system.
72b7576f 1796
1797The curve can be any *Geom_Curve*, provided it is planar and lies in the same plane as the Z-axis of local coordinate system. There are four modes of construction:
1798
1799 * From a curve, use the full curve and make a full rotation.
1800 * From a curve and an angle of rotation.
1801 * From a curve and two parameters to trim the curve. The two parameters must be growing and within the curve range.
1802 * From a curve, two parameters, and an angle. The two parameters must be growing and within the curve range.
1803
1804
1805@subsection occt_modalg_4_2 Sweeping: Prism, Revolution and Pipe
1806@subsubsection occt_modalg_4_2_1 Sweeping
1807
1808Sweeps are the objects you obtain by sweeping a **profile** along a **path**. The profile can be of any topology. The path is usually a curve or a wire. The profile generates objects according to the following rules:
1809
1810 * Vertices generate Edges
1811 * Edges generate Faces.
1812 * Wires generate Shells.
1813 * Faces generate Solids.
1814 * Shells generate Composite Solids
1815
1816It is forbidden to sweep Solids and Composite Solids. A Compound generates a Compound with the sweep of all its elements.
1817
e5bd0d98 1818@image html /user_guides/modeling_algos/images/modeling_algos_image033.png "Generating a sweep"
1819@image latex /user_guides/modeling_algos/images/modeling_algos_image033.png "Generating a sweep"
72b7576f 1820
1821*BRepPrimAPI_MakeSweep class* is a deferred class used as a root of the the following sweep classes:
1822* *BRepPrimAPI_MakePrism* - produces a linear sweep
1823* *BRepPrimAPI_MakeRevol* - produces a rotational sweep
1824* *BRepPrimAPI_MakePipe* - produces a general sweep.
1825
1826
1827@subsubsection occt_modalg_4_2_2 Prism
dba69de2 1828*BRepPrimAPI_MakePrism* class allows creating a linear **prism** from a shape and a vector or a direction.
72b7576f 1829* A vector allows creating a finite prism;
1830* A direction allows creating an infinite or semi-infinite prism. The semi-infinite or infinite prism is toggled by a Boolean argument. All constructors have a boolean argument to copy the original shape or share it (by default).
dba69de2 1831
e5bd0d98 1832The following code creates a finite, an infinite and a semi-infinite solid using a face, a direction and a length.
1833
72b7576f 1834~~~~~
1835TopoDS_Face F = ..; // The swept face
1836gp_Dir direc(0,0,1);
1837Standard_Real l = 10;
1838// create a vector from the direction and the length
1839gp_Vec v = direc;
1840v *= l;
1841TopoDS_Solid P1 = BRepPrimAPI_MakePrism(F,v);
1842// finite
1843TopoDS_Solid P2 = BRepPrimAPI_MakePrism(F,direc);
1844// infinite
1845TopoDS_Solid P3 = BRepPrimAPI_MakePrism(F,direc,Standard_False);
1846// semi-infinite
1847~~~~~
1848
e5bd0d98 1849@image html /user_guides/modeling_algos/images/modeling_algos_image034.png "Finite, infinite, and semi-infinite prisms"
1850@image latex /user_guides/modeling_algos/images/modeling_algos_image034.png "Finite, infinite, and semi-infinite prisms"
72b7576f 1851
1852@subsubsection occt_modalg_4_2_3 Rotation
dba69de2 1853*BRepPrimAPI_MakeRevol* class allows creating a rotational sweep from a shape, an axis (gp_Ax1), and an angle. The angle has a default value of 2*PI which means a closed revolution.
72b7576f 1854
dba69de2 1855*BRepPrimAPI_MakeRevol* constructors have a last argument to copy or share the original shape. The following code creates a a full and a partial rotation using a face, an axis and an angle.
72b7576f 1856
1857~~~~~
1858TopoDS_Face F = ...; // the profile
1859gp_Ax1 axis(gp_Pnt(0,0,0),gp_Dir(0,0,1));
1860Standard_Real ang = PI/3;
1861TopoDS_Solid R1 = BRepPrimAPI_MakeRevol(F,axis);
1862// Full revol
1863TopoDS_Solid R2 = BRepPrimAPI_MakeRevol(F,axis,ang);
1864~~~~~
1865
e5bd0d98 1866@image html /user_guides/modeling_algos/images/modeling_algos_image035.png "Full and partial rotation"
1867@image latex /user_guides/modeling_algos/images/modeling_algos_image035.png "Full and partial rotation"
72b7576f 1868
1869@section occt_modalg_5 Boolean Operations
1870
1871Boolean operations are used to create new shapes from the combinations of two shapes.
1a457208 1872See @ref occt_user_guides__boolean_operations "Boolean Operations" for detailed documentation.
dba69de2 1873
e5bd0d98 1874| Operation | Result |
1875| :---- | :------ |
dba69de2 1876| Fuse | all points in S1 or S2 |
1877| Common | all points in S1 and S2 |
1878| Cut S1 by S2| all points in S1 and not in S2 |
72b7576f 1879
1880BRepAlgoAPI_BooleanOperation class is the deferred root class for Boolean operations.
1881
e5bd0d98 1882@image html /user_guides/modeling_algos/images/modeling_algos_image036.png "Boolean Operations"
1883@image latex /user_guides/modeling_algos/images/modeling_algos_image036.png "Boolean Operations"
72b7576f 1884
1885@subsection occt_modalg_5_1 Fuse
1886
dba69de2 1887*BRepAlgoAPI_Fuse* performs the Fuse operation.
e5bd0d98 1888
72b7576f 1889~~~~~
1890TopoDS_Shape A = ..., B = ...;
1891TopoDS_Shape S = BRepAlgoAPI_Fuse(A,B);
1892~~~~~
1893
1894@subsection occt_modalg_5_2 Common
e5bd0d98 1895
dba69de2 1896*BRepAlgoAPI_Common* performs the Common operation.
72b7576f 1897
1898~~~~~
1899TopoDS_Shape A = ..., B = ...;
1900TopoDS_Shape S = BRepAlgoAPI_Common(A,B);
1901~~~~~
1902
1903@subsection occt_modalg_5_3 Cut
dba69de2 1904*BRepAlgoAPI_Cut* performs the Cut operation.
72b7576f 1905
1906~~~~~
1907TopoDS_Shape A = ..., B = ...;
1908TopoDS_Shape S = BRepAlgoAPI_Cut(A,B);
1909~~~~~
1910
1911@subsection occt_modalg_5_4 Section
1912
dba69de2 1913*BRepAlgoAPI_Section* performs the section, described as a *TopoDS_Compound* made of *TopoDS_Edge*.
72b7576f 1914
e5bd0d98 1915@image html /user_guides/modeling_algos/images/modeling_algos_image037.png "Section operation"
1916@image latex /user_guides/modeling_algos/images/modeling_algos_image037.png "Section operation"
72b7576f 1917
1918~~~~~
1919TopoDS_Shape A = ..., TopoDS_ShapeB = ...;
1920TopoDS_Shape S = BRepAlgoAPI_Section(A,B);
1921~~~~~
1922
1923@section occt_modalg_6 Fillets and Chamfers
1924@subsection occt_modalg_6_1 Fillets
1925@subsection occt_modalg_6_1_1 Fillet on shape
1926
1927A fillet is a smooth face replacing a sharp edge.
1928
1929*BRepFilletAPI_MakeFillet* class allows filleting a shape.
1930
1931To produce a fillet, it is necessary to define the filleted shape at the construction of the class and add fillet descriptions using the *Add* method.
72b7576f 1932
dba69de2 1933A fillet description contains an edge and a radius. The edge must be shared by two faces. The fillet is automatically extended to all edges in a smooth continuity with the original edge. It is not an error to add a fillet twice, the last description holds.
1934
e5bd0d98 1935@image html /user_guides/modeling_algos/images/modeling_algos_image038.png "Filleting two edges using radii r1 and r2."
1936@image latex /user_guides/modeling_algos/images/modeling_algos_image038.png "Filleting two edges using radii r1 and r2."
72b7576f 1937
1938In the following example a filleted box with dimensions a,b,c and radius r is created.
1939
dba69de2 1940### Constant radius
1941
72b7576f 1942
1943~~~~~
1944#include <TopoDS_Shape.hxx>
1945#include <TopoDS.hxx>
1946#include <BRepPrimAPI_MakeBox.hxx>
1947#include <TopoDS_Solid.hxx>
1948#include <BRepFilletAPI_MakeFillet.hxx>
1949#include <TopExp_Explorer.hxx>
1950
1951TopoDS_Shape FilletedBox(const Standard_Real a,
1952 const Standard_Real b,
1953 const Standard_Real c,
1954 const Standard_Real r)
1955{
1956 TopoDS_Solid Box = BRepPrimAPI_MakeBox(a,b,c);
1957 BRepFilletAPI_MakeFillet MF(Box);
1958
1959 // add all the edges to fillet
1960 TopExp_Explorer ex(Box,TopAbs_EDGE);
1961 while (ex.More())
1962 {
1963 MF.Add(r,TopoDS::Edge(ex.Current()));
1964 ex.Next();
1965 }
1966 return MF.Shape();
1967 }
1968~~~~~
1969
e5bd0d98 1970@image html /user_guides/modeling_algos/images/modeling_algos_image039.png "Fillet with constant radius"
1971@image latex /user_guides/modeling_algos/images/modeling_algos_image039.png "Fillet with constant radius"
dba69de2 1972
1973#### Changing radius
72b7576f 1974
72b7576f 1975
1976~~~~~
1977void CSampleTopologicalOperationsDoc::OnEvolvedblend1()
1978{
1979 TopoDS_Shape theBox = BRepPrimAPI_MakeBox(200,200,200);
1980
1981 BRepFilletAPI_MakeFillet Rake(theBox);
1982 ChFi3d_FilletShape FSh = ChFi3d_Rational;
1983 Rake.SetFilletShape(FSh);
1984
1985 TColgp_Array1OfPnt2d ParAndRad(1, 6);
1986 ParAndRad(1).SetCoord(0., 10.);
1987 ParAndRad(1).SetCoord(50., 20.);
1988 ParAndRad(1).SetCoord(70., 20.);
1989 ParAndRad(1).SetCoord(130., 60.);
1990 ParAndRad(1).SetCoord(160., 30.);
1991 ParAndRad(1).SetCoord(200., 20.);
1992
1993 TopExp_Explorer ex(theBox,TopAbs_EDGE);
1994 Rake.Add(ParAndRad, TopoDS::Edge(ex.Current()));
1995 TopoDS_Shape evolvedBox = Rake.Shape();
1996}
1997~~~~~
1998
e5bd0d98 1999@image html /user_guides/modeling_algos/images/modeling_algos_image040.png "Fillet with changing radius"
2000@image latex /user_guides/modeling_algos/images/modeling_algos_image040.png "Fillet with changing radius"
72b7576f 2001
2002@subsection occt_modalg_6_1_2 Chamfer
2003
2004A chamfer is a rectilinear edge replacing a sharp vertex of the face.
2005
2006The use of *BRepFilletAPI_MakeChamfer* class is similar to the use of *BRepFilletAPI_MakeFillet*, except for the following:
dba69de2 2007* The surfaces created are ruled and not smooth.
2008* The *Add* syntax for selecting edges requires one or two distances, one edge and one face (contiguous to the edge).
72b7576f 2009
2010~~~~~
2011Add(dist, E, F)
2012Add(d1, d2, E, F) with d1 on the face F.
2013~~~~~
2014
e5bd0d98 2015@image html /user_guides/modeling_algos/images/modeling_algos_image041.png "Chamfer"
2016@image latex /user_guides/modeling_algos/images/modeling_algos_image041.png "Chamfer"
72b7576f 2017
2018@subsection occt_modalg_6_1_3 Fillet on a planar face
2019
dba69de2 2020*BRepFilletAPI_MakeFillet2d* class allows constructing fillets and chamfers on planar faces.
72b7576f 2021To create a fillet on planar face: define it, indicate, which vertex is to be deleted, and give the fillet radius with *AddFillet* method.
dba69de2 2022
72b7576f 2023A chamfer can be calculated with *AddChamfer* method. It can be described by
2024 * two edges and two distances
2025 * one edge, one vertex, one distance and one angle.
2026Fillets and chamfers are calculated when addition is complete.
2027
2028If face F2 is created by 2D fillet and chamfer builder from face F1, the builder can be rebuilt (the builder recovers the status it had before deletion). To do so, use the following syntax:
2029~~~~~
2030BRepFilletAPI_MakeFillet2d builder;
2031builder.Init(F1,F2);
2032~~~~~
2033
2034Planar Fillet
2035-------------
2036
2037~~~~~
2038#include “BRepPrimAPI_MakeBox.hxx”
2039#include “TopoDS_Shape.hxx”
2040#include “TopExp_Explorer.hxx”
2041#include “BRepFilletAPI_MakeFillet2d.hxx”
2042#include “TopoDS.hxx”
2043#include “TopoDS_Solid.hxx”
2044
2045TopoDS_Shape FilletFace(const Standard_Real a,
2046 const Standard_Real b,
2047 const Standard_Real c,
2048 const Standard_Real r)
2049
2050{
2051 TopoDS_Solid Box = BRepPrimAPI_MakeBox (a,b,c);
2052 TopExp_Explorer ex1(Box,TopAbs_FACE);
2053
e5bd0d98 2054 const TopoDS_Face& F = TopoDS::Face(ex1.Current());
72b7576f 2055 BRepFilletAPI_MakeFillet2d MF(F);
2056 TopExp_Explorer ex2(F, TopAbs_VERTEX);
2057 while (ex2.More())
2058 {
2059 MF.AddFillet(TopoDS::Vertex(ex2.Current()),r);
2060 ex2.Next();
2061 }
2062 // while...
2063 return MF.Shape();
2064}
2065~~~~~
2066
2067@section occt_modalg_7 Offsets, Drafts, Pipes and Evolved shapes
2068@subsection occt_modalg_7_1 Shelling
2069
2070Shelling is used to offset given faces of a solid by a specific value. It rounds or intersects adjacent faces along its edges depending on the convexity of the edge.
2071
2072The constructor *BRepOffsetAPI_MakeThickSolid* shelling operator takes the solid, the list of faces to remove and an offset value as input.
2073
2074~~~~~
2075TopoDS_Solid SolidInitial = ...;
2076
2077Standard_Real Of = ...;
2078TopTools_ListOfShape LCF;
2079TopoDS_Shape Result;
2080Standard_Real Tol = Precision::Confusion();
2081
2082for (Standard_Integer i = 1 ;i <= n; i++) {
2083 TopoDS_Face SF = ...; // a face from SolidInitial
2084 LCF.Append(SF);
2085}
2086
2087Result = BRepOffsetAPI_MakeThickSolid (SolidInitial,
2088 LCF,
2089 Of,
2090 Tol);
2091~~~~~
2092
e5bd0d98 2093@image html /user_guides/modeling_algos/images/modeling_algos_image042.png "Shelling"
2094@image latex /user_guides/modeling_algos/images/modeling_algos_image042.png "Shelling"
72b7576f 2095
2096
2097@subsection occt_modalg_7_2 Draft Angle
2098
2099*BRepOffsetAPI_DraftAngle* class allows modifying a shape by applying draft angles to its planar, cylindrical and conical faces.
72b7576f 2100
dba69de2 2101
2102The class is created or initialized from a shape, then faces to be modified are added; for each face, three arguments are used:
72b7576f 2103 * Direction: the direction with which the draft angle is measured
2104 * Angle: value of the angle
2105 * Neutral plane: intersection between the face and the neutral plane is invariant.
2106
2107The following code places a draft angle on several faces of a shape; the same direction, angle and neutral plane are used for each face:
2108
2109~~~~~
2110TopoDS_Shape myShape = ...
2111// The original shape
2112TopTools_ListOfShape ListOfFace;
2113// Creation of the list of faces to be modified
2114...
2115
2116gp_Dir Direc(0.,0.,1.);
2117// Z direction
2118Standard_Real Angle = 5.*PI/180.;
2119// 5 degree angle
2120gp_Pln Neutral(gp_Pnt(0.,0.,5.), Direc);
2121// Neutral plane Z=5
2122BRepOffsetAPI_DraftAngle theDraft(myShape);
2123TopTools_ListIteratorOfListOfShape itl;
2124for (itl.Initialize(ListOfFace); itl.More(); itl.Next()) {
2125 theDraft.Add(TopoDS::Face(itl.Value()),Direc,Angle,Neutral);
2126 if (!theDraft.AddDone()) {
2127 // An error has occurred. The faulty face is given by // ProblematicShape
2128 break;
2129 }
2130}
2131if (!theDraft.AddDone()) {
2132 // An error has occurred
2133 TopoDS_Face guilty = theDraft.ProblematicShape();
2134 ...
2135}
2136theDraft.Build();
2137if (!theDraft.IsDone()) {
2138 // Problem encountered during reconstruction
2139 ...
2140}
2141else {
2142 TopoDS_Shape myResult = theDraft.Shape();
2143 ...
2144}
2145~~~~~
2146
e5bd0d98 2147@image html /user_guides/modeling_algos/images/modeling_algos_image043.png "DraftAngle"
2148@image latex /user_guides/modeling_algos/images/modeling_algos_image043.png "DraftAngle"
72b7576f 2149
2150@subsection occt_modalg_7_3 Pipe Constructor
2151
2152*BRepOffsetAPI_MakePipe* class allows creating a pipe from a Spine, which is a Wire and a Profile which is a Shape. This implementation is limited to spines with smooth transitions, sharp transitions are precessed by *BRepOffsetAPI_MakePipeShell*. To be more precise the continuity must be G1, which means that the tangent must have the same direction, though not necessarily the same magnitude, at neighboring edges.
dba69de2 2153
72b7576f 2154The angle between the spine and the profile is preserved throughout the pipe.
2155
2156~~~~~
2157TopoDS_Wire Spine = ...;
2158TopoDS_Shape Profile = ...;
2159TopoDS_Shape Pipe = BRepOffsetAPI_MakePipe(Spine,Profile);
2160~~~~~
2161
e5bd0d98 2162@image html /user_guides/modeling_algos/images/modeling_algos_image044.png "Example of a Pipe"
2163@image latex /user_guides/modeling_algos/images/modeling_algos_image044.png "Example of a Pipe"
72b7576f 2164
2165@subsection occt_modalg_7_4 Evolved Solid
2166
2167*BRepOffsetAPI_MakeEvolved* class allows creating an evolved solid from a Spine (planar face or wire) and a profile (wire).
dba69de2 2168
72b7576f 2169The evolved solid is an unlooped sweep generated by the spine and the profile.
dba69de2 2170
72b7576f 2171The evolved solid is created by sweeping the profile’s reference axes on the spine. The origin of the axes moves to the spine, the X axis and the local tangent coincide and the Z axis is normal to the face.
2172
2173The reference axes of the profile can be defined following two distinct modes:
2174
2175* The reference axes of the profile are the origin axes.
2176* The references axes of the profile are calculated as follows:
2177 + the origin is given by the point on the spine which is the closest to the profile
2178 + the X axis is given by the tangent to the spine at the point defined above
2179 + the Z axis is the normal to the plane which contains the spine.
2180
2181~~~~~
2182TopoDS_Face Spine = ...;
2183TopoDS_Wire Profile = ...;
2184TopoDS_Shape Evol =
2185BRepOffsetAPI_MakeEvolved(Spine,Profile);
2186~~~~~
2187
2188@section occt_modalg_8 Sewing operators
2189@subsection occt_modalg_8_1 Sewing
2190
2191*BRepOffsetAPI_Sewing* class allows sewing TopoDS Shapes together along their common edges. The edges can be partially shared as in the following example.
2192
e5bd0d98 2193@image html /user_guides/modeling_algos/images/modeling_algos_image045.png "Shapes with partially shared edges"
2194@image latex /user_guides/modeling_algos/images/modeling_algos_image045.png "Shapes with partially shared edges"
72b7576f 2195
dba69de2 2196The constructor takes as arguments the tolerance (default value is 10-6) and a flag, which is used to mark the degenerate shapes.
2197
72b7576f 2198The following methods are used in this class:
2199* *Add* adds shapes, as it is needed;
2200* *Perform* forces calculation of the sewed shape.
2201* *SewedShape* returns the result.
dba69de2 2202
72b7576f 2203Additional methods can be used to give information on the number of free boundaries, multiple edges and degenerate shapes.
2204
2205@subsection occt_modalg_8_2 Find Contiguous Edges
2206*BRepOffsetAPI_FindContiguousEdges* class is used to find edges, which coincide among a set of shapes within the given tolerance; these edges can be analyzed for tangency, continuity (C1, G2, etc.)...
2207
2208The constructor takes as arguments the tolerance defining the edge proximity (10-6 by default) and a flag used to mark degenerated shapes.
dba69de2 2209
72b7576f 2210The following methods are used in this class:
2211* *Add* adds shapes, which are to be analyzed;
2212* *NbEdges* returns the total number of edges;
2213* *NbContiguousEdges* returns the number of contiguous edges within the given tolerance as defined above;
2214* *ContiguousEdge* takes an edge number as an argument and returns the *TopoDS* edge contiguous to another edge;
2215* *ContiguousEdgeCouple* gives all edges or sections, which are common to the edge with the number given above.
2216* *SectionToBoundary* finds the original edge on the original shape from the section.
2217
2218@section occt_modalg_9 Features
2219
2220@subsection occt_modalg_9_1 The BRepFeat Classes and their use
dba69de2 2221*BRepFeat* package is used to manipulate extensions of the classical boundary representation of shapes closer to features. In that sense, *BRepFeat* is an extension of *BRepBuilderAPI* package.
72b7576f 2222
2223@subsubsection occt_modalg_9_1_1 Form classes
dba69de2 2224The *Form* from *BRepFeat* class is a deferred class used as a root for form features. It inherits *MakeShape* from *BRepBuilderAPI* and provides implementation of methods keep track of all sub-shapes.
72b7576f 2225
dba69de2 2226#### MakePrism
2227
2228*MakePrism* from *BRepFeat* class is used to build a prism interacting with a shape. It is created or initialized from
72b7576f 2229 * a shape (the basic shape),
2230 * the base of the prism,
2231 * a face (the face of sketch on which the base has been defined and used to determine whether the base has been defined on the basic shape or not),
2232 * a direction,
2233 * a Boolean indicating the type of operation (fusion=protrusion or cut=depression) on the basic shape,
2234 * another Boolean indicating if the self-intersections have to be found (not used in every case).
2235
2236There are six Perform methods:
e5bd0d98 2237| Method | Description |
2238| :---------------------- | :------------------------------------- |
dba69de2 2239| *Perform(Height)* | The resulting prism is of the given length. |
2240| *Perform(Until)* | The prism is defined between the position of the base and the given face. |
2241| *Perform(From, Until)* | The prism is defined between the two faces From and Until. |
2242| *PerformUntilEnd()* | The prism is semi-infinite, limited by the actual position of the base. |
2243| *PerformFromEnd(Until)* | The prism is semi-infinite, limited by the face Until. |
2244| *PerformThruAll()* | The prism is infinite. In the case of a depression, the result is similar to a cut with an infinite prism. In the case of a protrusion, infinite parts are not kept in the result. |
72b7576f 2245
dba69de2 2246**Note** that *Add* method can be used before *Perform* methods to indicate that a face generated by an edge slides onto a face of the base shape.
72b7576f 2247
2248In the following sequence, a protrusion is performed, i.e. a face of the shape is changed into a prism.
2249
2250~~~~~
dba69de2 2251TopoDS_Shape Sbase = ...; // an initial shape
72b7576f 2252TopoDS_Face Fbase = ....; // a base of prism
2253
2254gp_Dir Extrusion (.,.,.);
2255
2256// An empty face is given as the sketch face
2257
2258BRepFeat_MakePrism thePrism(Sbase, Fbase, TopoDS_Face(), Extrusion, Standard_True, Standard_True);
2259
2260thePrism, Perform(100.);
2261if (thePrism.IsDone()) {
2262 TopoDS_Shape theResult = thePrism;
2263 ...
2264}
2265~~~~~
2266
e5bd0d98 2267@image html /user_guides/modeling_algos/images/modeling_algos_image047.png "Fusion with MakePrism"
2268@image latex /user_guides/modeling_algos/images/modeling_algos_image047.png "Fusion with MakePrism"
dba69de2 2269
e5bd0d98 2270@image html /user_guides/modeling_algos/images/modeling_algos_image048.png "Creating a prism between two faces with Perform(From, Until)"
2271@image latex /user_guides/modeling_algos/images/modeling_algos_image048.png "Creating a prism between two faces with Perform(From, Until)"
72b7576f 2272
dba69de2 2273#### MakeDPrism
72b7576f 2274
dba69de2 2275*MakeDPrism* from *BRepFeat* class is used to build draft prism topologies interacting with a basis shape . These can be depressions or protrusions. A class object is created or initialized from
72b7576f 2276 * a shape (basic shape),
2277 * the base of the prism,
2278 * a face (face of sketch on which the base has been defined and used to determine whether the base has been defined on the basic shape or not),
2279 * an angle,
2280 * a Boolean indicating the type of operation (fusion=protrusion or cut=depression) on the basic shape,
2281 * another Boolean indicating if self-intersections have to be found (not used in every case).
2282
2283Evidently the input data for MakeDPrism are the same as for MakePrism except for a new parameter Angle and a missing parameter Direction: the direction of the prism generation is determined automatically as the normal to the base of the prism.
2284The semantics of draft prism feature creation is based on the construction of shapes:
2285 * along a length
2286 * up to a limiting face
2287 * from a limiting face to a height.
2288
2289The shape defining construction of the draft prism feature can be either the supporting edge or the concerned area of a face.
2290
2291In case of the supporting edge, this contour can be attached to a face of the basis shape by binding. When the contour is bound to this face, the information that the contour will slide on the face becomes available to the relevant class methods.
2292In case of the concerned area of a face, it is possible to cut it out and move it to a different height, which will define the limiting face of a protrusion or depression direction .
2293
2294The *Perform* methods are the same as for *MakePrism*.
2295
2296~~~~~
2297TopoDS_Shape S = BRepPrimAPI_MakeBox(400.,250.,300.);
2298TopExp_Explorer Ex;
2299Ex.Init(S,TopAbs_FACE);
2300Ex.Next();
2301Ex.Next();
2302Ex.Next();
2303Ex.Next();
2304Ex.Next();
2305TopoDS_Face F = TopoDS::Face(Ex.Current());
2306Handle(Geom_Surface) surf = BRep_Tool::Surface(F);
2307gp_Circ2d
2308c(gp_Ax2d(gp_Pnt2d(200.,130.),gp_Dir2d(1.,0.)),50.);
2309BRepBuilderAPI_MakeWire MW;
2310Handle(Geom2d_Curve) aline = new Geom2d_Circle(c);
2311MW.Add(BRepBuilderAPI_MakeEdge(aline,surf,0.,PI));
2312MW.Add(BRepBuilderAPI_MakeEdge(aline,surf,PI,2.*PI));
2313BRepBuilderAPI_MakeFace MKF;
2314MKF.Init(surf,Standard_False);
2315MKF.Add(MW.Wire());
2316TopoDS_Face FP = MKF.Face();
2317BRepLib::BuildCurves3d(FP);
2318BRepFeat_MakeDPrism MKDP (S,FP,F,10*PI180,Standard_True,
2319 Standard_True);
2320MKDP.Perform(200);
2321TopoDS_Shape res1 = MKDP.Shape();
2322~~~~~
2323
e5bd0d98 2324@image html /user_guides/modeling_algos/images/modeling_algos_image049.png "A tapered prism"
2325@image latex /user_guides/modeling_algos/images/modeling_algos_image049.png "A tapered prism"
dba69de2 2326
2327#### MakeRevol
72b7576f 2328
dba69de2 2329The *MakeRevol* from *BRepFeat* class is used to build a revolution interacting with a
72b7576f 2330shape. It is created or initialized from
2331
2332 * a shape (the basic shape,)
2333 * the base of the revolution,
2334 * a face (the face of sketch on which the base has been defined and used to determine whether the base has been defined on the basic shape or not),
2335 * an axis of revolution,
2336 * a boolean indicating the type of operation (fusion=protrusion or cut=depression) on the basic shape,
2337 * another boolean indicating whether the self-intersections have to be found (not used in every case).
2338
2339There are four Perform methods:
e5bd0d98 2340| Method | Description |
2341| :--------------- | :------------ |
dba69de2 2342| *Perform(Angle)* | The resulting revolution is of the given magnitude. |
2343| *Perform(Until)* | The revolution is defined between the actual position of the base and the given face. |
2344| *Perform(From, Until)* | The revolution is defined between the two faces, From and Until. |
2345| *PerformThruAll()* | The result is similar to Perform(2*PI). |
2346
2347**Note** that *Add* method can be used before *Perform* methods to indicate that a face generated by an edge slides onto a face of the base shape.
72b7576f 2348
2349
2350In the following sequence, a face is revolved and the revolution is limited by a face of the base shape.
2351
2352~~~~~
dba69de2 2353TopoDS_Shape Sbase = ...; // an initial shape
72b7576f 2354TopoDS_Face Frevol = ....; // a base of prism
2355TopoDS_Face FUntil = ....; // face limiting the revol
2356
2357gp_Dir RevolDir (.,.,.);
2358gp_Ax1 RevolAx(gp_Pnt(.,.,.), RevolDir);
2359
2360// An empty face is given as the sketch face
2361
2362BRepFeat_MakeRevol theRevol(Sbase, Frevol, TopoDS_Face(), RevolAx, Standard_True, Standard_True);
2363
2364theRevol.Perform(FUntil);
2365if (theRevol.IsDone()) {
2366 TopoDS_Shape theResult = theRevol;
2367 ...
2368}
2369~~~~~
2370
dba69de2 2371#### MakePipe
2372
72b7576f 2373This method constructs compound shapes with pipe features: depressions or protrusions. A class object is created or initialized from
2374 * a shape (basic shape),
2375 * a base face (profile of the pipe)
2376 * a face (face of sketch on which the base has been defined and used to determine whether the base has been defined on the basic shape or not),
2377 * a spine wire
2378 * a Boolean indicating the type of operation (fusion=protrusion or cut=depression) on the basic shape,
2379 * another Boolean indicating if self-intersections have to be found (not used in every case).
2380
2381There are three Perform methods:
e5bd0d98 2382| Method | Description |
2383| :-------- | :---------- |
dba69de2 2384| *Perform()* | The pipe is defined along the entire path (spine wire) |
2385| *Perform(Until)* | The pipe is defined along the path until a given face |
2386| *Perform(From, Until)* | The pipe is defined between the two faces From and Until |
72b7576f 2387
2388~~~~~
2389TopoDS_Shape S = BRepPrimAPI_MakeBox(400.,250.,300.);
2390TopExp_Explorer Ex;
2391Ex.Init(S,TopAbs_FACE);
2392Ex.Next();
2393Ex.Next();
2394TopoDS_Face F1 = TopoDS::Face(Ex.Current());
2395Handle(Geom_Surface) surf = BRep_Tool::Surface(F1);
2396BRepBuilderAPI_MakeWire MW1;
2397gp_Pnt2d p1,p2;
2398p1 = gp_Pnt2d(100.,100.);
2399p2 = gp_Pnt2d(200.,100.);
2400Handle(Geom2d_Line) aline = GCE2d_MakeLine(p1,p2).Value();
2401
2402MW1.Add(BRepBuilderAPI_MakeEdge(aline,surf,0.,p1.Distance(p2)));
2403p1 = p2;
2404p2 = gp_Pnt2d(150.,200.);
2405aline = GCE2d_MakeLine(p1,p2).Value();
2406
2407MW1.Add(BRepBuilderAPI_MakeEdge(aline,surf,0.,p1.Distance(p2)));
2408p1 = p2;
2409p2 = gp_Pnt2d(100.,100.);
2410aline = GCE2d_MakeLine(p1,p2).Value();
2411
2412MW1.Add(BRepBuilderAPI_MakeEdge(aline,surf,0.,p1.Distance(p2)));
2413BRepBuilderAPI_MakeFace MKF1;
2414MKF1.Init(surf,Standard_False);
2415MKF1.Add(MW1.Wire());
2416TopoDS_Face FP = MKF1.Face();
2417BRepLib::BuildCurves3d(FP);
2418TColgp_Array1OfPnt CurvePoles(1,3);
2419gp_Pnt pt = gp_Pnt(150.,0.,150.);
2420CurvePoles(1) = pt;
2421pt = gp_Pnt(200.,100.,150.);
2422CurvePoles(2) = pt;
2423pt = gp_Pnt(150.,200.,150.);
2424CurvePoles(3) = pt;
2425Handle(Geom_BezierCurve) curve = new Geom_BezierCurve
2426(CurvePoles);
2427TopoDS_Edge E = BRepBuilderAPI_MakeEdge(curve);
2428TopoDS_Wire W = BRepBuilderAPI_MakeWire(E);
2429BRepFeat_MakePipe MKPipe (S,FP,F1,W,Standard_False,
2430Standard_True);
2431MKPipe.Perform();
2432TopoDS_Shape res1 = MKPipe.Shape();
2433~~~~~
2434
e5bd0d98 2435@image html /user_guides/modeling_algos/images/modeling_algos_image050.png "Pipe depression"
2436@image latex /user_guides/modeling_algos/images/modeling_algos_image050.png "Pipe depression"
dba69de2 2437
2438
72b7576f 2439
2440@subsubsection occt_modalg_9_1_2 Linear Form
dba69de2 2441
72b7576f 2442*MakeLinearForm* class creates a rib or a groove along a planar surface.
dba69de2 2443
72b7576f 2444The semantics of mechanical features is built around giving thickness to a contour. This thickness can either be symmetrical - on one side of the contour - or dissymmetrical - on both sides. As in the semantics of form features, the thickness is defined by construction of shapes in specific contexts.
2445
2446The development contexts differ, however, in the case of mechanical features.
2447Here they include extrusion:
2448 * to a limiting face of the basis shape;
2449 * to or from a limiting plane;
2450 * to a height.
2451A class object is created or initialized from
2452 * a shape (basic shape);
2453 * a wire (base of rib or groove);
2454 * a plane (plane of the wire);
2455 * direction1 (a vector along which thickness will be built up);
2456 * direction2 (vector opposite to the previous one along which thickness will be built up, may be null);
2457 * a Boolean indicating the type of operation (fusion=rib or cut=groove) on the basic shape;
2458 * another Boolean indicating if self-intersections have to be found (not used in every case).
2459
dba69de2 2460There is one *Perform()* method, which performs a prism from the wire along the *direction1* and *direction2* interacting with base shape *Sbase*. The height of the prism is *Magnitude(Direction1)+Magnitude(direction2)*.
72b7576f 2461
2462~~~~~
2463BRepBuilderAPI_MakeWire mkw;
2464gp_Pnt p1 = gp_Pnt(0.,0.,0.);
2465gp_Pnt p2 = gp_Pnt(200.,0.,0.);
2466mkw.Add(BRepBuilderAPI_MakeEdge(p1,p2));
2467p1 = p2;
2468p2 = gp_Pnt(200.,0.,50.);
2469mkw.Add(BRepBuilderAPI_MakeEdge(p1,p2));
2470p1 = p2;
2471p2 = gp_Pnt(50.,0.,50.);
2472mkw.Add(BRepBuilderAPI_MakeEdge(p1,p2));
2473p1 = p2;
2474p2 = gp_Pnt(50.,0.,200.);
2475mkw.Add(BRepBuilderAPI_MakeEdge(p1,p2));
2476p1 = p2;
2477p2 = gp_Pnt(0.,0.,200.);
2478mkw.Add(BRepBuilderAPI_MakeEdge(p1,p2));
2479p1 = p2;
2480mkw.Add(BRepBuilderAPI_MakeEdge(p2,gp_Pnt(0.,0.,0.)));
2481TopoDS_Shape S = BRepBuilderAPI_MakePrism(BRepBuilderAPI_MakeFace
2482 (mkw.Wire()),gp_Vec(gp_Pnt(0.,0.,0.),gp_P
dba69de2 2483 nt(0.,100.,0.)));
72b7576f 2484TopoDS_Wire W = BRepBuilderAPI_MakeWire(BRepBuilderAPI_MakeEdge(gp_Pnt
2485 (50.,45.,100.),
2486gp_Pnt(100.,45.,50.)));
2487Handle(Geom_Plane) aplane =
2488 new Geom_Plane(gp_Pnt(0.,45.,0.), gp_Vec(0.,1.,0.));
2489BRepFeat_MakeLinearForm aform(S, W, aplane, gp_Dir
2490 (0.,5.,0.), gp_Dir(0.,-3.,0.), 1, Standard_True);
2491aform.Perform();
2492TopoDS_Shape res = aform.Shape();
2493~~~~~
2494
e5bd0d98 2495@image html /user_guides/modeling_algos/images/modeling_algos_image051.png "Creating a rib"
2496@image latex /user_guides/modeling_algos/images/modeling_algos_image051.png "Creating a rib"
72b7576f 2497
2498@subsubsection occt_modalg_9_1_3 Gluer
2499
dba69de2 2500The *Gluer* from *BRepFeat* class allows gluing two solids along faces. The contact faces of the glued shape must not have parts outside the contact faces of the basic shape.
72b7576f 2501The class is created or initialized from two shapes: the “glued” shape and the basic shape (on which the other shape is glued).
dba69de2 2502Two *Bind* methods are used to bind a face of the glued shape to a face of the basic shape and an edge of the glued shape to an edge of the basic shape.
72b7576f 2503
dba69de2 2504**Note** that every face and edge has to be bounded, if two edges of two glued faces are coincident they must be explicitly bounded.
72b7576f 2505
2506~~~~~
2507TopoDS_Shape Sbase = ...; // the basic shape
2508TopoDS_Shape Sglued = ...; // the glued shape
2509
2510TopTools_ListOfShape Lfbase;
2511TopTools_ListOfShape Lfglued;
2512// Determination of the glued faces
2513...
2514
2515BRepFeat_Gluer theGlue(Sglue, Sbase);
2516TopTools_ListIteratorOfListOfShape itlb(Lfbase);
2517TopTools_ListIteratorOfListOfShape itlg(Lfglued);
2518for (; itlb.More(); itlb.Next(), itlg(Next()) {
e5bd0d98 2519const TopoDS_Face& f1 = TopoDS::Face(itlg.Value());
2520const TopoDS_Face& f2 = TopoDS::Face(itlb.Value());
72b7576f 2521theGlue.Bind(f1,f2);
2522// for example, use the class FindEdges from LocOpe to
2523// determine coincident edges
2524LocOpe_FindEdge fined(f1,f2);
2525for (fined.InitIterator(); fined.More(); fined.Next()) {
2526theGlue.Bind(fined.EdgeFrom(),fined.EdgeTo());
2527}
2528}
2529theGlue.Build();
2530if (theGlue.IsDone() {
2531TopoDS_Shape theResult = theGlue;
2532...
2533}
2534~~~~~
2535
dba69de2 2536@subsubsection occt_modalg_9_1_4 Split Shape
72b7576f 2537
dba69de2 2538*SplitShape* from *BRepFeat* class is used to split faces of a shape with wires or edges. The shape containing the new entities is rebuilt, sharing the unmodified ones.
72b7576f 2539
2540The class is created or initialized from a shape (the basic shape).
2541Three Add methods are available:
e5bd0d98 2542* *Add(Wire, Face)* - adds a new wire on a face of the basic shape.
2543* *Add(Edge, Face)* - adds a new edge on a face of the basic shape.
2544* *Add(EdgeNew, EdgeOld)* - adds a new edge on an existing one (the old edge must contain the new edge).
72b7576f 2545
2546**Note** The added wires and edges must define closed wires on faces or wires located between two existing edges. Existing edges must not be intersected.
2547
2548~~~~~
2549TopoDS_Shape Sbase = ...; // basic shape
2550TopoDS_Face Fsplit = ...; // face of Sbase
2551TopoDS_Wire Wsplit = ...; // new wire contained in Fsplit
2552BRepFeat_SplitShape Spls(Sbase);
2553Spls.Add(Wsplit, Fsplit);
2554TopoDS_Shape theResult = Spls;
2555...
2556~~~~~
2557
2558
2559@section occt_modalg_10 Hidden Line Removal
2560
2561To provide the precision required in industrial design, drawings need to offer the possibility of removing lines, which are hidden in a given projection.
2562
dba69de2 2563For this the Hidden Line Removal component provides two algorithms: *HLRBRep_Algo* and *HLRBRep_PolyAlgo*.
72b7576f 2564
2565These algorithms are based on the principle of comparing each edge of the shape to be visualized with each of its faces, and calculating the visible and the hidden parts of each edge. Note that these are not the algorithms used in generating shading, which calculate the visible and hidden parts of each face in a shape to be visualized by comparing each face in the shape with every other face in the same shape.
2566These algorithms operate on a shape and remove or indicate edges hidden by faces. For a given projection, they calculate a set of lines characteristic of the object being represented. They are also used in conjunction with extraction utilities, which reconstruct a new, simplified shape from a selection of the results of the calculation. This new shape is made up of edges, which represent the shape visualized in the projection.
2567
dba69de2 2568*HLRBRep_Algo* takes the shape itself into account whereas *HLRBRep_PolyAlgo* works with a polyhedral simplification of the shape. When you use *HLRBRep_Algo*, you obtain an exact result, whereas, when you use *HLRBRep_PolyAlgo*, you reduce the computation time.
72b7576f 2569
dba69de2 2570No smoothing algorithm is provided. Consequently, a polyhedron will be treated as such and the algorithms will give the results in form of line segments conforming to the mathematical definition of the polyhedron. This is always the case with *HLRBRep_PolyAlgo*.
72b7576f 2571
dba69de2 2572*HLRBRep_Algo* and *HLRBRep_PolyAlgo* can deal with any kind of object, for example, assemblies of volumes, surfaces, and lines, as long as there are no unfinished objects or points within it.
72b7576f 2573
2574However, there some restrictions in HLR use:
2575 * Points are not processed;
2576 * Z-clipping planes are not used;
2577 * Infinite faces or lines are not processed.
2578
2579
e5bd0d98 2580@image html /user_guides/modeling_algos/images/modeling_algos_image052.png "Sharp, smooth and sewn edges in a simple screw shape"
2581@image latex /user_guides/modeling_algos/images/modeling_algos_image052.png "Sharp, smooth and sewn edges in a simple screw shape"
72b7576f 2582
e5bd0d98 2583@image html /user_guides/modeling_algos/images/modeling_algos_image053.png "Outline edges and isoparameters in the same shape"
2584@image latex /user_guides/modeling_algos/images/modeling_algos_image053.png "Outline edges and isoparameters in the same shape"
72b7576f 2585
e5bd0d98 2586@image html /user_guides/modeling_algos/images/modeling_algos_image054.png "A simple screw shape seen with shading"
2587@image latex /user_guides/modeling_algos/images/modeling_algos_image054.png "A simple screw shape seen with shading"
72b7576f 2588
e5bd0d98 2589@image html /user_guides/modeling_algos/images/modeling_algos_image055.png "An extraction showing hidden sharp edges"
2590@image latex /user_guides/modeling_algos/images/modeling_algos_image055.png "An extraction showing hidden sharp edges"
72b7576f 2591
2592
72b7576f 2593The following services are related to Hidden Lines Removal :
2594
dba69de2 2595### Loading Shapes
2596
72b7576f 2597To pass a *TopoDS_Shape* to an *HLRBRep_Algo* object, use *HLRBRep_Algo::Add*. With an *HLRBRep_PolyAlgo* object, use *HLRBRep_PolyAlgo::Load*. If you wish to add several shapes, use Add or Load as often as necessary.
2598
dba69de2 2599### Setting view parameters
2600
2601*HLRBRep_Algo::Projector* and *HLRBRep_PolyAlgo::Projector* set a projector object which defines the parameters of the view. This object is an *HLRAlgo_Projector*.
2602
2603### Computing the projections
2604
2605*HLRBRep_PolyAlgo::Update* launches the calculation of outlines of the shape visualized by the *HLRBRep_PolyAlgo* framework.
72b7576f 2606
dba69de2 2607In the case of *HLRBRep_Algo*, use *HLRBRep_Algo::Update*. With this algorithm, you must also call the method *HLRBRep_Algo::Hide* to calculate visible and hidden lines of the shape to be visualized. With an *HLRBRep_PolyAlgo* object, visible and hidden lines are computed by *HLRBRep_PolyHLRToShape*.
72b7576f 2608
dba69de2 2609### Extracting edges
2610
2611The classes *HLRBRep_HLRToShape* and *HLRBRep_PolyHLRToShape* present a range of extraction filters for an *HLRBRep_Algo object* and an *HLRBRep_PolyAlgo* object, respectively. They highlight the type of edge from the results calculated by the algorithm on a shape. With both extraction classes, you can highlight the following types of output:
72b7576f 2612 * visible/hidden sharp edges;
2613 * visible/hidden smooth edges;
2614 * visible/hidden sewn edges;
2615 * visible/hidden outline edges.
2616
2617To perform extraction on an *HLRBRep_PolyHLRToShape* object, use *HLRBRep_PolyHLRToShape::Update* function.
dba69de2 2618
72b7576f 2619For an *HLRBRep_HLRToShape* object built from an *HLRBRepAlgo* object you can also highlight:
2620 * visible isoparameters and
2621 * hidden isoparameters.
2622
dba69de2 2623@subsection occt_modalg_10_1 Examples
2624
2625### HLRBRep_Algo
72b7576f 2626
72b7576f 2627~~~~~
2628// Build The algorithm object
2629myAlgo = new HLRBRep_Algo();
2630
2631// Add Shapes into the algorithm
2632TopTools_ListIteratorOfListOfShape anIterator(myListOfShape);
2633for (;anIterator.More();anIterator.Next())
2634myAlgo-Add(anIterator.Value(),myNbIsos);
2635
2636// Set The Projector (myProjector is a
2637HLRAlgo_Projector)
2638myAlgo-Projector(myProjector);
2639
2640// Build HLR
2641myAlgo->Update();
2642
2643// Set The Edge Status
2644myAlgo->Hide();
2645
2646// Build the extraction object :
2647HLRBRep_HLRToShape aHLRToShape(myAlgo);
2648
2649// extract the results :
dba69de2 2650TopoDS_Shape VCompound = aHLRToShape.VCompound();
2651TopoDS_Shape Rg1LineVCompound =
72b7576f 2652aHLRToShape.Rg1LineVCompound();
dba69de2 2653TopoDS_Shape RgNLineVCompound =
72b7576f 2654aHLRToShape.RgNLineVCompound();
dba69de2 2655TopoDS_Shape OutLineVCompound =
72b7576f 2656aHLRToShape.OutLineVCompound();
dba69de2 2657TopoDS_Shape IsoLineVCompound =
72b7576f 2658aHLRToShape.IsoLineVCompound();
dba69de2 2659TopoDS_Shape HCompound = aHLRToShape.HCompound();
2660TopoDS_Shape Rg1LineHCompound =
72b7576f 2661aHLRToShape.Rg1LineHCompound();
dba69de2 2662TopoDS_Shape RgNLineHCompound =
72b7576f 2663aHLRToShape.RgNLineHCompound();
dba69de2 2664TopoDS_Shape OutLineHCompound =
72b7576f 2665aHLRToShape.OutLineHCompound();
dba69de2 2666TopoDS_Shape IsoLineHCompound =
72b7576f 2667aHLRToShape.IsoLineHCompound();
2668~~~~~
2669
dba69de2 2670### HLRBRep_PolyAlgo
2671
72b7576f 2672
2673~~~~~
2674
2675// Build The algorithm object
2676myPolyAlgo = new HLRBRep_PolyAlgo();
2677
2678// Add Shapes into the algorithm
2679TopTools_ListIteratorOfListOfShape
2680anIterator(myListOfShape);
2681for (;anIterator.More();anIterator.Next())
2682myPolyAlgo-Load(anIterator.Value());
2683
2684// Set The Projector (myProjector is a
2685HLRAlgo_Projector)
2686myPolyAlgo->Projector(myProjector);
2687
2688// Build HLR
2689myPolyAlgo->Update();
2690
2691// Build the extraction object :
2692HLRBRep_PolyHLRToShape aPolyHLRToShape;
2693aPolyHLRToShape.Update(myPolyAlgo);
2694
2695// extract the results :
2696TopoDS_Shape VCompound =
2697aPolyHLRToShape.VCompound();
2698TopoDS_Shape Rg1LineVCompound =
2699aPolyHLRToShape.Rg1LineVCompound();
2700TopoDS_Shape RgNLineVCompound =
2701aPolyHLRToShape.RgNLineVCompound();
2702TopoDS_Shape OutLineVCompound =
2703aPolyHLRToShape.OutLineVCompound();
2704TopoDS_Shape HCompound =
2705aPolyHLRToShape.HCompound();
2706TopoDS_Shape Rg1LineHCompound =
2707aPolyHLRToShape.Rg1LineHCompound();
2708TopoDS_Shape RgNLineHCompound =
2709aPolyHLRToShape.RgNLineHCompound();
2710TopoDS_Shape OutLineHCompound =
2711aPolyHLRToShape.OutLineHCompound();
2712~~~~~
2713
dba69de2 2714@section occt_modalg_10_2 Meshing of Shapes
72b7576f 2715
2716The *HLRBRep_PolyAlgo* algorithm works with triangulation of shapes. This is provided by the function *BRepMesh::Mesh*, which adds a triangulation of the shape to its topological data structure. This triangulation is computed with a given deflection.
2717
2718~~~~~
2719Standard_Real radius=10. ;
2720Standard_Real height=25. ;
2721BRepBuilderAPI_MakeCylinder myCyl (radius, height) ;
2722TopoDS_Shape myShape = myCyl.Shape() ;
2723Standard_Real Deflection = 0.01 ;
2724BRepMesh::Mesh (myShape, Deflection);
2725~~~~~
2726
2727Meshing covers a shape with a triangular mesh. Other than hidden line removal, you can use meshing to transfer the shape to another tool: a manufacturing tool, a shading algorithm, a finite element algorithm, or a collision algorithm, for example.
2728
2729You can obtain information on the shape by first exploring it. To then access triangulation of a face in the shape, use *BRepTool::Triangulation*. To access a polygon which is the approximation of an edge of the face, use *BRepTool::PolygonOnTriangulation*.