0031002: Documentation - update Overview for 7.4.0
[occt.git] / dox / user_guides / shape_healing / shape_healing.md
CommitLineData
ba06f8bb 1Shape Healing {#occt_user_guides__shape_healing}
72b7576f 2===================
e5bd0d98 3
4@tableofcontents
5
72b7576f 6@section occt_shg_1 Overview
7
e2b55410 8@subsection occt_shg_1_1 Introduction
9
7863dabb 10This manual explains how to use Shape Healing. It provides basic documentation on its operation. For advanced information on Shape Healing and its applications, see our <a href="https://www.opencascade.com/content/tutorial-learning">E-learning & Training</a> offerings.
72b7576f 11
12The **Shape Healing** toolkit provides a set of tools to work on the geometry and topology of Open CASCADE Technology (**OCCT**) shapes. Shape Healing adapts shapes so as to make them as appropriate for use by Open CASCADE Technology as possible.
e2b55410 13
14@subsection occt_shg_1_2 Examples of use
15
16Here are a few examples of typical problems with illustrations of how Shape Healing deals with them:
17
18#### Face with missing seam edge
19
20The problem: Face on a periodical surface is limited by wires which make a full trip around the surface. These wires are closed in 3d but not closed in parametric space of the surface. This is not valid in Open CASCADE.
21The solution: Shape Healing fixes this face by inserting seam edge which combines two open wires and thus closes the parametric space. Note that internal wires are processed correctly.
22
23#### Wrong orientation of wires
24The problem: Wires on face have incorrect orientation, so that interior and outer parts of the face are mixed.
25The solution: Shape Healing recovers correct orientation of wires.
26
27#### Self-intersecting wire
28The problem: Face is invalid because its boundary wire has self-intersection (on two adjacent edges)
29The solution: Shape Healing cuts intersecting edges at intersection points thus making boundary valid.
30
31#### Lacking edge
32The problem: There is a gap between two edges in the wire, so that wire is not closed
33The solution: Shape Healing closes a gap by inserting lacking edge.
34
35@subsection occt_shg_1_3 Toolkit Structure
36
72b7576f 37**Shape Healing** currently includes several packages that are designed to help you to:
38 * analyze shape characteristics and, in particular, identify shapes that do not comply with Open CASCADE Technology validity rules
39 * fix some of the problems shapes may have
dba69de2 40 * upgrade shape characteristics for users needs, for example a C0 supporting surface can be upgraded so that it becomes C1 continuous.
72b7576f 41
42The following diagram shows dependencies of API packages:
3d68eaf5 43
d6b4d3d0 44@figure{/user_guides/shape_healing/images/shape_healing_image009.svg,"Shape Healing packages",420}
72b7576f 45
46Each sub-domain has its own scope of functionality:
3f812249 47* analysis -- exploring shape properties, computing shape features, detecting violation of OCCT requirements (shape itself is not modified);
48* fixing -- fixing shape to meet the OCCT requirements (the shape may change its original form: modifying, removing, constructing sub-shapes, etc.);
49* upgrade -- shape improvement for better usability in Open CASCADE Technology or other algorithms (the shape is replaced with a new one, but geometrically they are the same);
50* customization -- modifying shape representation to fit specific needs (shape is not modified, only the form of its representation is modified);
51* processing -- mechanism of managing shape modification via a user-editable resource file.
72b7576f 52
07f2b741 53Message management is used for creating messages, filling them with various parameters and storing them in the trace file. This tool provides functionality for attaching messages to the shapes for deferred analysis of various run-time events. In this document only general principles of using Shape Healing will be described. For more detailed information, see the corresponding header files.
dba69de2 54
72b7576f 55Tools responsible for analysis, fixing and upgrading of shapes can give the information about how these operations were performed. This information can be obtained by the user with the help of mechanism of status querying.
56
e2b55410 57@subsection occt_shg_1_4 Querying the statuses
72b7576f 58
59Each fixing and upgrading tool has its own status, which is reset when their methods are called. The status can contain several flags, which give the information about how the method was performed. For exploring the statuses, a set of methods named *Status...()* is provided. These methods accept enumeration *ShapeExtend_Status* and return True if the status has the corresponding flag set. The meaning of flags for each method is described below.
dba69de2 60
72b7576f 61The status may contain a set of Boolean flags (internally represented by bits). Flags are coded by enumeration ShapeExtend_Status. This enumeration provides the following families of statuses:
3f812249 62* *ShapeExtend_OK* -- The situation is OK, no operation is necessary and has not been performed.
63* *ShapeExtend_DONE* -- The operation has been successfully performed.
64* *ShapeExtend_FAIL* -- An error has occurred during operation.
72b7576f 65
66It is possible to test the status for the presence of some flag(s), using Status...() method(s) provided by the class:
67
68~~~~~
69if ( object.Status.. ( ShapeExtend_DONE ) ) {// something was done
70}
71~~~~~
72
d3013f55 738 'DONE' and 8 'FAIL' flags, named ShapeExtend_DONE1 ... ShapeExtend_FAIL8, are defined for a detailed analysis of the encountered situation. Each method assigns its own meaning to each flag, documented in the header for that method. There are also three enumerative values used for testing several flags at a time:
3f812249 74* *ShapeExtend_OK* -- if no flags have been set;
75* *ShapeExtend_DONE* -- if at least one ShapeExtend_DONEi has been set;
76* *ShapeExtend_FAIL* -- if at least one ShapeExtend_FAILi has been set.
72b7576f 77
78@section occt_shg_2 Repair
79
dba69de2 80Algorithms for fixing problematic (violating the OCCT requirements) shapes are placed in package *ShapeFix*.
81
82Each class of package *ShapeFix* deals with one certain type of shapes or with some family of problems.
83
84There is no necessity for you to detect problems before using *ShapeFix* because all components of package *ShapeFix* make an analysis of existing problems before fixing them by a corresponding tool from package of *ShapeAnalysis* and then fix the discovered problems.
85
86The *ShapeFix* package currently includes functions that:
72b7576f 87 * add a 2D curve or a 3D curve where one is missing,
88 * correct a deviation of a 2D curve from a 3D curve when it exceeds a given tolerance value,
89 * limit the tolerance value of shapes within a given range,
90 * set a given tolerance value for shapes,
91 * repair the connections between adjacent edges of a wire,
3f812249 92 * correct self-intersecting wires,
72b7576f 93 * add seam edges,
94 * correct gaps between 3D and 2D curves,
95 * merge and remove small edges,
96 * correct orientation of shells and solids.
97
98@subsection occt_shg_2_1 Basic Shape Repair
99
100The simplest way for fixing shapes is to use classes *ShapeFix_Shape* and *ShapeFix_Wireframe* on a whole shape with default parameters. A combination of these tools can fix most of the problems that shapes may have.
101The sequence of actions is as follows :
102
1031. Create tool *ShapeFix_Shape* and initialize it by shape:
dc244065 104
105 Handle(ShapeFix_Shape) sfs = new ShapeFix_Shape;
106 sfs->Init ( shape );
107
1082. Set the basic precision, the maximum allowed tolerance, the minimal allowed tolerance:
109
110 sfs->SetPrecision ( Prec );
111 sfs->SetMaxTolerance ( maxTol );
112 sfs->SetMinTolerance ( mintol );
113
3f812249 114 where:
115 * *Prec* -- basic precision.
116 * *maxTol* -- maximum allowed tolerance. All problems will be detected for cases when a dimension of invalidity is larger than the basic precision or a tolerance of sub-shape on that problem is detected.
117 The maximum tolerance value limits the increasing tolerance for fixing a problem such as fix of not connected and self-intersected wires. If a value larger than the maximum allowed tolerance is necessary for correcting a detected problem the problem can not be fixed.
118 The maximal tolerance is not taking into account during computation of tolerance of edges in *ShapeFix_SameParameter()* method and *ShapeFix_Edge::FixVertexTolerance()* method.
dc244065 119 See @ref occt_shg_2_3_8 for details.
3f812249 120 * *minTol* -- minimal allowed tolerance. It defines the minimal allowed length of edges. Detected edges having length less than the specified minimal tolerance will be removed if *ModifyTopologyMode* in Repairing tool for wires is set to true.
dc244065 121 See @ref occt_shg_2_3_7 for details.
122
72b7576f 1233. Launch fixing:
dc244065 124
125 sfs->Perform();
126
72b7576f 1274. Get the result:
dc244065 128
129 TopoDS_Shape aResult = sfs->Shape();
130
131 In some cases using only *ShapeFix_Shape* can be insufficient. It is possible to use tools for merging and removing small edges and fixing gaps between 2D and 3D curves.
132
72b7576f 1335. Create *ShapeFix_Wireframe* tool and initialize it by shape:
72b7576f 134~~~~~
135Handle(ShapeFix_Wirefarme) SFWF = new ShapeFix_Wirefarme(shape);
136Or
137Handle(ShapeFix_Wirefarme) SFWF = new ShapeFix_Wirefarme;
138SFWF->Load(shape);
139~~~~~
72b7576f 1406. Set the basic precision and the maximum allowed tolerance:
141~~~~~
142sfs->SetPrecision ( Prec );
143sfs->SetMaxTolerance ( maxTol );
144~~~~~
dba69de2 145See the description for *Prec* and *maxTol* above.
72b7576f 1467. Merge and remove small edges:
147~~~~~
4ee1bdf4 148SFWF->DropSmallEdgesMode() = Standard_True;
149SFWF->FixSmallEdges();
72b7576f 150~~~~~
72b7576f 151**Note:** Small edges are not removed with the default mode, but in many cases removing small edges is very useful for fixing a shape.
72b7576f 1528. Fix gaps for 2D and 3D curves
153~~~~~
4ee1bdf4 154SFWF->FixWireGaps();
72b7576f 155~~~~~
72b7576f 1569. Get the result
157~~~~~
4ee1bdf4 158TopoDS_Shape Result = SFWF->Shape();
72b7576f 159~~~~~
160
161
162@subsection occt_shg_2_2 Shape Correction.
163
164If you do not want to make fixes on the whole shape or make a definite set of fixes you can set flags for separate fix cases (marking them ON or OFF) and you can also use classes for fixing specific types of sub-shapes such as solids, shells, faces, wires, etc.
dba69de2 165
72b7576f 166For each type of sub-shapes there are specific types of fixing tools such as *ShapeFix_Solid, ShapeFix_Shell, ShapeFix_Face, ShapeFix_Wire,* etc.
167
168@subsubsection occt_shg_2_2_1 Fixing sub-shapes
3f812249 169If you want to make a fix on one sub-shape of a certain shape it is possible to take the following steps:
170 * create a tool for a specified sub-shape type and initialize this tool by the sub-shape;
72b7576f 171 * create a tool for rebuilding the shape and initialize it by the whole shape (section 5.1);
3f812249 172 * set a tool for rebuilding the shape in the tool for fixing the sub-shape;
173 * fix the sub-shape;
174 * get the resulting whole shape containing a new corrected sub-shape.
72b7576f 175
dba69de2 176For example, in the following way it is possible to fix face *Face1* of shape *Shape1*:
72b7576f 177
178~~~~~
179//create tools for fixing a face
dba69de2 180Handle(ShapeFix_Face) SFF= new ShapeFix_Face;
72b7576f 181
182// create tool for rebuilding a shape and initialize it by shape
dba69de2 183Handle(ShapeBuild_ReShape) Context = new ShapeBuild_ReShape;
4ee1bdf4 184Context->Apply(Shape1);
72b7576f 185
186//set a tool for rebuilding a shape in the tool for fixing
4ee1bdf4 187SFF->SetContext(Context);
dba69de2 188
72b7576f 189//initialize the fixing tool by one face
4ee1bdf4 190SFF->Init(Face1);
72b7576f 191
192//fix the set face
4ee1bdf4 193SFF->Perform();
dba69de2 194
72b7576f 195//get the result
4ee1bdf4 196TopoDS_Shape NewShape = Context->Apply(Shape1);
72b7576f 197//Resulting shape contains the fixed face.
198~~~~~
199
200A set of required fixes and invalid sub-shapes can be obtained with the help of tools responsible for the analysis of shape validity (section 3.2).
201
202@subsection occt_shg_2_3 Repairing tools
203
204Each class of package ShapeFix deals with one certain type of shapes or with a family of problems. Each repairing tool makes fixes for the specified shape and its sub-shapes with the help of method *Perform()* containing an optimal set of fixes. The execution of these fixes in the method Perform can be managed with help of a set of control flags (fixes can be either forced or forbidden).
205
206@subsubsection occt_shg_2_3_1 General Workflow
207
208The following sequence of actions should be applied to perform fixes:
2091. Create a tool.
2102. Set the following values:
dba69de2 211 + the working precision by method *SetPrecision()* (default 1.e-7)
72b7576f 212 + set the maximum allowed tolerance by method *SetMaxTolerance()* (by default it is equal to the working precision).
213 + set the minimum tolerance by method *SetMinTolerance()* (by default it is equal to the working precision).
214 + set a tool for rebuilding shapes after the modification (tool *ShapeBuild_ReShape*) by method *SetContext()*. For separate faces, wires and edges this tool is set optionally.
215 + to force or forbid some of fixes, set the corresponding flag to 0 or 1.
2163. Initialize the tool by the shape with the help of methods Init or Load
2174. Use method *Perform()* or create a custom set of fixes.
2185. Check the statuses of fixes by the general method *Status* or specialized methods *Status_*(for example *StatusSelfIntersection* (*ShapeExtentd_DONE*)). See the description of statuses below.
2196. Get the result in two ways :
220 - with help of a special method *Shape(),Face(),Wire().Edge()*.
221 - from the rebuilding tool by method *Apply* (for access to rebuilding tool use method *Context()*):
222~~~~~
4ee1bdf4 223 TopoDS_Shape resultShape = fixtool->Context()->Apply(initialShape);
72b7576f 224~~~~~
225Modification fistory for the shape and its sub-shapes can be obtained from the tool for shape re-building (*ShapeBuild_ReShape*).
226
227~~~~~
4ee1bdf4 228TopoDS_Shape modifsubshape = fixtool->Context() -> Apply(initsubshape);
72b7576f 229~~~~~
230
231
232@subsubsection occt_shg_2_3_2 Flags Management
233
234The flags *Fix...Mode()* are used to control the execution of fixing procedures from the API fixing methods. By default, these flags have values equal to -1, this means that the corresponding procedure will either be called or not called, depending on the situation. If the flag is set to 1, the procedure is executed anyway; if the flag is 0, the procedure is not executed. The name of the flag corresponds to the fixing procedure that is controlled. For each fixing tool there exists its own set of flags. To set a flag to the desired value, get a tool containing this flag and set the flag to the required value.
235
236For example, it is possible to forbid performing fixes to remove small edges - *FixSmall*
237
238~~~~~
239Handle(ShapeFix_Shape) Sfs = new ShapeFix_Shape(shape);
4ee1bdf4 240Sfs-> FixWireTool ()->FixSmallMode () =0;
241if(Sfs->Perform())
242 TopoDS_Shape resShape = Sfs->Shape();
72b7576f 243~~~~~
244
245
246@subsubsection occt_shg_2_3_3 Repairing tool for shapes
247
dba69de2 248Class *ShapeFix_Shape* allows using repairing tools for all sub-shapes of a shape. It provides access to all repairing tools for fixing sub-shapes of the specified shape and to all control flags from these tools.
72b7576f 249
250For example, it is possible to force the removal of invalid 2D curves from a face.
251
252~~~~~
253TopoDS_Face face … // face with invalid 2D curves.
254//creation of tool and its initialization by shape.
255Handle(ShapeFix_Shape) sfs = new ShapeFix_Shape(face);
256//set work precision and max allowed tolerance.
257sfs->SetPrecision(prec);
258sfs->SetMaxTolerance(maxTol);
259//set the value of flag for forcing the removal of 2D curves
4ee1bdf4 260sfs->FixWireTool()->FixRemovePCurveMode() =1;
72b7576f 261//reform fixes
262sfs->Perform();
263//getting the result
264if(sfs->Status(ShapeExtend_DONE) ) {
4ee1bdf4 265 cout << "Shape was fixed" << endl;
72b7576f 266 TopoDS_Shape resFace = sfs->Shape();
267}
268else if(sfs->Status(ShapeExtend_FAIL)) {
4ee1bdf4 269cout<< "Shape could not be fixed" << endl;
72b7576f 270}
271else if(sfs->Status(ShapeExtent_OK)) {
4ee1bdf4 272cout<< "Initial face is valid with specified precision ="<< precendl;
72b7576f 273}
274~~~~~
275
276@subsubsection occt_shg_2_3_4 Repairing tool for solids
277
278Class *ShapeFix_Solid* allows fixing solids and building a solid from a shell to obtain a valid solid with a finite volume. The tool *ShapeFix_Shell* is used for correction of shells belonging to a solid.
279
280This tool has the following control flags:
3f812249 281* *FixShellMode* -- Mode for applying fixes of ShapeFix_Shell, True by default.
282* *CreateOpenShellMode* -- If it is equal to true solids are created from open shells, else solids are created from closed shells only, False by default.
72b7576f 283
284@subsubsection occt_shg_2_3_5 Repairing tool for shells
dba69de2 285Class *ShapeFix_Shell* allows fixing wrong orientation of faces in a shell. It changes the orientation of faces in the shell so that all faces in the shell have coherent orientations. If it is impossible to orient all faces in the shell (like in case of Mebious tape), then a few manifold or non-manifold shells will be created depending on the specified Non-manifold mode. The *ShapeFix_Face* tool is used to correct faces in the shell.
72b7576f 286This tool has the following control flags:
3f812249 287* *FixFaceMode* -- mode for applying the fixes of *ShapeFix_Face*, *True* by default.
288* *FixOrientationMode* -- mode for applying a fix for the orientation of faces in the shell.
72b7576f 289
290@subsubsection occt_shg_2_3_6 Repairing tool for faces
291
dba69de2 292Class *ShapeFix_Face* allows fixing the problems connected with wires of a face. It allows controlling the creation of a face (adding wires), and fixing wires by means of tool *ShapeFix_Wire*.
72b7576f 293When a wire is added to a face, it can be reordered and degenerated edges can be fixed. This is performed or not depending on the user-defined flags (by default, False).
294The following fixes are available:
295 * fixing of wires orientation on the face. If the face has no wire, the natural bounds are computed. If the face is on a spherical surface and has two or more wires on it describing holes, the natural bounds are added. In case of a single wire, it is made to be an outer one. If the face has several wires, they are oriented to lay one outside another (if possible). If the supporting surface is periodic, 2D curves of internal wires can be shifted on integer number of periods to put them inside the outer wire.
dba69de2 296 * fixing the case when the face on the closed surface is defined by a set of closed wires, and the seam is missing (this is not valid in OCCT). In that case, these wires are connected by means of seam edges into the same wire.
72b7576f 297
298This tool has the following control flags:
3f812249 299* *FixWireMode* -- mode for applying fixes of a wire, True by default.
300* *FixOrientationMode* -- mode for orienting a wire to border a limited square, True by default.
301* *FixAddNaturalBoundMode* -- mode for adding natural bounds to a face, False by default.
302* *FixMissingSeamMode* -- mode to fix a missing seam, True by default. If True, tries to insert a seam.
303* *FixSmallAreaWireMode* -- mode to fix a small-area wire, False by default. If True, drops wires bounding small areas.
72b7576f 304
305~~~~~
306
307TopoDS_Face face = ...;
308TopoDS_Wire wire = ...;
309
310//Creates a tool and adds a wire to the face
311ShapeFix_Face sff (face);
312sff.Add (wire);
313
314//use method Perform to fix the wire and the face
315sff.Perfom();
316
317//or make a separate fix for the orientation of wire on the face
318sff.FixOrientation();
319
320//Get the resulting face
321TopoDS_Face newface = sff.Face();
322~~~~~
323
dba69de2 324@subsubsection occt_shg_2_3_7 Repairing tool for wires
72b7576f 325
dba69de2 326Class *ShapeFix_Wire* allows fixing a wire. Its method *Perform()* performs all the available fixes in addition to the geometrical filling of gaps. The geometrical filling of gaps can be made with the help of the tool for fixing the wireframe of shape *ShapeFix_Wireframe*.
72b7576f 327
328The fixing order and the default behavior of *Perform()* is as follows:
dba69de2 329 * Edges in the wire are reordered by *FixReorder*. Most of fixing methods expect edges in a wire to be ordered, so it is necessary to make call to *FixReorder()* before making any other fixes. Even if it is forbidden, the analysis of whether the wire is ordered or not is performed anyway.
330 * Small edges are removed by *FixSmall* .
331 * Edges in the wire are connected (topologically) by *FixConnected* (if the wire is ordered).
332 * Edges (3Dcurves and 2D curves) are fixed by *FixEdgeCurves* (without *FixShifted* if the wire is not ordered).
333 * Degenerated edges are added by *FixDegenerated*(if the wire is ordered).
334 * Self-intersection is fixed by *FixSelfIntersection* (if the wire is ordered and *ClosedMode* is True).
335 * Lacking edges are fixed by *FixLacking* (if the wire is ordered).
336
337 The flag *ClosedWireMode* specifies whether the wire is (or should be) closed or not. If that flag is True (by default), fixes that require or force connection between edges are also executed for the last and the first edges.
338
339The fixing methods can be turned on/off by using their corresponding control flags:
340* *FixReorderMode,*
341* *FixSmallMode,*
342* *FixConnectedMode,*
343* *FixEdgeCurvesMode,*
344* *FixDegeneratedMode,*
345* *FixSelfIntersectionMode*
72b7576f 346
347Some fixes can be made in three ways:
348 * Increasing the tolerance of an edge or a vertex.
349 * Changing topology (adding/removing/replacing an edge in the wire and/or replacing the vertex in the edge, copying the edge etc.).
3f812249 350 * Changing geometry (shifting a vertex or adjusting ends of an edge curve to vertices, or recomputing a 3D curve or 2D curves of the edge).
72b7576f 351
352When it is possible to make a fix in more than one way (e.g., either by increasing the tolerance or shifting a vertex), it is chosen according to the user-defined flags:
3f812249 353* *ModifyTopologyMode* -- allows modifying topology, False by default.
354* *ModifyGeometryMode* -- allows modifying geometry. Now this flag is used only in fixing self-intersecting edges (allows to modify 2D curves) and is True by default.
72b7576f 355
dba69de2 356#### Fixing disordered edges
357
358*FixReorder* is necessary for most other fixes (but is not necessary for Open CASCADE Technology). It checks whether edges in the wire go in a sequential order (the end of a preceding edge is the start of a following one). If it is not so, an attempt to reorder the edges is made.
72b7576f 359
dba69de2 360#### Fixing small edges
361
362*FixSmall* method searches for the edges, which have a length less than the given value (degenerated edges are ignored). If such an edge is found, it is removed provided that one of the following conditions is satisfied:
72b7576f 363 * both end vertices of that edge are one and the same vertex,
364 * end vertices of the edge are different, but the flag *ModifyTopologyMode* is True. In the latter case, method *FixConnected* is applied to the preceding and the following edges to ensure their connection.
365
dba69de2 366#### Fixing disconnected edges
367
368*FixConnected* method forces two adjacent edges to share the same common vertex (if they do not have a common one). It checks whether the end vertex of the preceding edge coincides with the start vertex of the following edge with the given precision, and then creates a new vertex and sets it as a common vertex for the fixed edges. At that point, edges are copied, hence the wire topology is changed (regardless of the *ModifyTopologyMode* flag). If the vertices do not coincide, this method fails.
369
370#### Fixing the consistency of edge curves
371
372*FixEdgeCurves* method performs a set of fixes dealing with 3D curves and 2D curves of edges in a wire.
373
374These fixes will be activated with the help of a set of fixes from the repairing tool for edges called *ShapeFix_Edge*. Each of these fixes can be forced or forbidden by means of setting the corresponding flag to either True or False.
375
376The mentioned fixes and the conditions of their execution are:
3f812249 377 * fixing a disoriented 2D curve by call to *ShapeFix_Edge::FixReversed2d* -- if not forbidden by flag *FixReversed2dMode*;
378 * removing a wrong 2D curve by call to *ShapeFix_Edge::FixRemovePCurve* -- only if forced by flag *FixRemovePCurveMode*;
379 * fixing a missing 2D curve by call to *ShapeFix_Edge::FixAddPCurve* -- if not forbidden by flag *FixAddPCurveMode*;
380 * removing a wrong 3D curve by call to *ShapeFix_Edge::FixRemoveCurve3d* -- only if forced by flag *FixRemoveCurve3dMode*;
381 * fixing a missing 3D curve by call to *ShapeFix_Edge::FixAddCurve3d* -- if not forbidden by flag *FixAddCurve3dMode*;
382 * fixing 2D curves of seam edges -- if not forbidden by flag *FixSeamMode*;
383 * fixing 2D curves which can be shifted at an integer number of periods on the closed surface by call to *ShapeFix_Edge::FixShifted* -- if not forbidden by flag *FixShiftedMode*.
dba69de2 384
385This fix is required if 2D curves of some edges in a wire lying on a closed surface were recomputed from 3D curves. In that case, the 2D curve for the edge, which goes along the seam of the surface, can be incorrectly shifted at an integer number of periods. The method *FixShifted* detects such cases and shifts wrong 2D curves back, ensuring that the 2D curves of the edges in the wire are connected.
386
3f812249 387 * fixing the SameParameter problem by call to *ShapeFix_Edge::FixSameParameter* -- if not forbidden by flag *FixSameParameterMode*.
dba69de2 388
72b7576f 389
dba69de2 390#### Fixing degenerated edges
391
392*FixDegenerated* method checks whether an edge in a wire lies on a degenerated point of the supporting surface, or whether there is a degenerated point between the edges. If one of these cases is detected for any edge, a new degenerated edge is created and it replaces the current edge in the first case or is added to the wire in the second case. The newly created degenerated edge has a straight 2D curve, which goes from the end of the 2D curve of the preceding edge to the start of the following one.
72b7576f 393
dba69de2 394#### Fixing intersections of 2D curves of the edges
395
396*FixSelfIntersection* method detects and fixes the following problems:
72b7576f 397 * self-intersection of 2D curves of individual edges. If the flag *ModifyGeometryMode()* is False this fix will be performed by increasing the tolerance of one of end vertices to a value less then *MaxTolerance()*.
398 * intersection of 2D curves of each of the two adjacent edges (except the first and the last edges if the flag ClosedWireMode is False). If such intersection is found, the common vertex is modified in order to comprise the intersection point. If the flag *ModifyTopologyMode* is False this fix will be performed by increasing the tolerance of the vertex to a value less then *MaxTolerance()*.
dba69de2 399 * intersection of 2D curves of non-adjacent edges. If such intersection is found the tolerance of the nearest vertex is increased to comprise the intersection point. If such increase cannot be done with a tolerance less than *MaxTolerance* this fix will not be performed.
72b7576f 400
dba69de2 401#### Fixing a lacking edge
72b7576f 402
3f812249 403*FixLacking* method checks whether a wire is not closed in the parametric space of the surface (while it can be closed in 3D). This is done by checking whether the gap between 2D curves of each of the two adjacent edges in the wire is smaller than the tolerance of the corresponding vertex. The algorithm computes the gap between the edges, analyses positional relationship of the ends of these edges and (if possible) tries to insert a new edge into the gap or increases the tolerance.
dba69de2 404
405#### Fixing gaps in 2D and 3D wire by geometrical filling
406The following methods check gaps between the ends of 2D or 3D curves of adjacent edges:
407* Method *FixGap2d* moves the ends of 2D curves to the middle point.
408* Method *FixGaps3d* moves the ends of 3D curves to a common vertex.
409
410Boolean flag *FixGapsByRanges* is used to activate an additional mode applied before converting to B-Splines. When this mode is on, methods try to find the most precise intersection of curves, or the most precise projection of a target point, or an extremity point between two curves (to modify their parametric range accordingly). This mode is off by default. Independently of the additional mode described above, if gaps remain, these methods convert curves to B-Spline form and shift their ends if a gap is detected.
411
412#### Example: A custom set of fixes
72b7576f 413
72b7576f 414
415Let us create a custom set of fixes as an example.
416~~~~~
417TopoDS_Face face = ...;
418TopoDS_Wire wire = ...;
419Standard_Real precision = 1e-04;
420ShapeFix_Wire sfw (wire, face, precision);
421//Creates a tool and loads objects into it
422sfw.FixReorder();
4ee1bdf4 423//Orders edges in the wire so that each edge starts at the end of the one before it.
72b7576f 424sfw.FixConnected();
425//Forces all adjacent edges to share
426//the same vertex
427Standard_Boolean LockVertex = Standard_True;
4ee1bdf4 428 if (sfw.FixSmall (LockVertex, precision)) {
429 //Removes all edges which are shorter than the given precision and have the same vertex at both ends.
72b7576f 430}
4ee1bdf4 431 if (sfw.FixSelfIntersection()) {
432 //Fixes self-intersecting edges and intersecting adjacent edges.
433 cout <<"Wire was slightly self-intersecting. Repaired"<<endl;
72b7576f 434}
4ee1bdf4 435 if ( sfw.FixLacking ( Standard_False ) ) {
436 //Inserts edges to connect adjacent non-continuous edges.
72b7576f 437}
438TopoDS_Wire newwire = sfw.Wire();
439//Returns the corrected wire
440~~~~~
441
dba69de2 442#### Example: Correction of a wire
72b7576f 443
444Let us correct the following wire:
445
d6b4d3d0 446@figure{/user_guides/shape_healing/images/shape_healing_image013.png,"Initial shape",420}
72b7576f 447
67d7f07f 448It is necessary to apply the @ref occt_shg_3_1_2 "tools for the analysis of wire validity" to check that:
72b7576f 449* the edges are correctly oriented;
450* there are no edges that are too short;
451* there are no intersecting adjacent edges;
452and then immediately apply fixing tools.
453
454~~~~~
455TopoDS_Face face = ...;
456TopoDS_Wire wire = ...;
457Standard_Real precision = 1e-04;
458ShapeAnalysis_Wire saw (wire, face, precision);
459ShapeFix_Wire sfw (wire, face, precision);
460if (saw.CheckOrder()) {
461 cout<<“Some edges in the wire need to be reordered”<<endl;
462 // Two edges are incorrectly oriented
463 sfw.FixReorder();
464 cout<<“Reordering is done”<<endl;
465}
466// their orientation is corrected
467if (saw.CheckSmall (precision)) {
468 cout<<“Wire contains edge(s) shorter than “<<precision<<endl;
4ee1bdf4 469 // An edge that is shorter than the given tolerance is found.
72b7576f 470 Standard_Boolean LockVertex = Standard_True;
471 if (sfw.FixSmall (LockVertex, precision)) {
472 cout<<“Edges shorter than “<<precision<<“ have been removed”
473<<endl;
474 //The edge is removed
475 }
476}
477if (saw.CheckSelfIntersection()) {
478 cout<<“Wire has self-intersecting or intersecting
479adjacent edges”<<endl;
4ee1bdf4 480 // Two intersecting adjacent edges are found.
72b7576f 481 if (sfw.FixSelfIntersection()) {
482 cout<<“Wire was slightly self-intersecting. Repaired”<<endl;
4ee1bdf4 483 // The edges are cut at the intersection point so that they no longer intersect.
72b7576f 484 }
485}
486~~~~~
487
488As the result all failures have been fixed.
489
d6b4d3d0 490@figure{/user_guides/shape_healing/images/shape_healing_image014.png,"Resulting shape",420}
72b7576f 491
492@subsubsection occt_shg_2_3_8 Repairing tool for edges
493
494Class *ShapeFix_Edge* provides tools for fixing invalid edges. The following geometrical and/or topological inconsistencies are detected and fixed:
495 * missing 3D curve or 2D curve,
496 * mismatching orientation of a 3D curve and a 2D curve,
dba69de2 497 * incorrect SameParameter flag (curve deviation is greater than the edge tolerance).
72b7576f 498Each fixing method first checks whether the problem exists using methods of the *ShapeAnalysis_Edge* class. If the problem is not detected, nothing is done.
499This tool does not have the method *Perform()*.
500
501To see how this tool works, it is possible to take an edge, where the maximum deviation between the 3D curve and 2D curve P1 is greater than the edge tolerance.
502
d6b4d3d0 503@figure{/user_guides/shape_healing/images/shape_healing_image011.png,"Initial shape",420}
72b7576f 504
67d7f07f 505First it is necessary to apply the @ref occt_shg_3_1_3 "tool for checking the edge validity" to find that the maximum deviation between pcurve and 3D curve is greater than tolerance. Then we can use the repairing tool to increase the tolerance and make the deviation acceptable.
72b7576f 506
507~~~~~
508ShapeAnalysis_Edge sae;
509TopoDS_Face face = ...;
510TopoDS_Wire wire = ...;
511Standard_Real precision = 1e-04;
512ShapeFix_Edge sfe;
513Standard_Real maxdev;
514if (sae.CheckSameParameter (edge, maxdev)) {
515 cout<<“Incorrect SameParameter flag”<<endl;
516 cout<<“Maximum deviation “<<maxdev<< “, tolerance “
517<<BRep_Tool::Tolerance(edge)<<endl;
518 sfe.FixSameParameter();
519 cout<<“New tolerance “<<BRep_Tool::Tolerance(edge)<<endl;
520}
521~~~~~
522
d6b4d3d0 523@figure{/user_guides/shape_healing/images/shape_healing_image012.png,"Resulting shape",420}
72b7576f 524
525As the result, the edge tolerance has been increased.
526
527
528@subsubsection occt_shg_2_3_9 Repairing tool for the wireframe of a shape
529
4ee1bdf4 530Class *ShapeFix_Wireframe* provides methods for geometrical fixing of gaps and merging small edges in a shape. This class performs the following operations:
72b7576f 531 * fills gaps in the 2D and 3D wireframe of a shape.
532 * merges and removes small edges.
533
534Fixing of small edges can be managed with the help of two flags:
3f812249 535 * *ModeDropSmallEdges()* -- mode for removing small edges that can not be merged, by default it is equal to Standard_False.
536 * *LimitAngle* -- maximum possible angle for merging two adjacent edges, by default no limit angle is applied (-1).
72b7576f 537To perform fixes it is necessary to:
538 * create a tool and initialize it by shape,
539 * set the working precision problems will be detected with and the maximum allowed tolerance
540 * perform fixes
541
542~~~~~
543//creation of a tool
544Handle(ShapeFix_Wireframe) sfwf = new ShapeFix_Wireframe(shape);
4ee1bdf4 545//sets the working precision problems will be detected with and the maximum allowed tolerance
72b7576f 546sfwf->SetPrecision(prec);
547sfwf->SetMaxTolerance(maxTol);
548//fixing of gaps
549sfwf->FixWireGaps();
550//fixing of small edges
551//setting of the drop mode for the fixing of small edges and max possible angle between merged edges.
552sfwf->ModeDropSmallEdges = Standard_True;
553sfwf->SetLimliteAngle(angle);
554//performing the fix
555sfwf->FixSmallEdges();
556//getting the result
557TopoDS_Shape resShape = sfwf->Shape();
558~~~~~
559
560It is desirable that a shape is topologically correct before applying the methods of this class.
561
562@subsubsection occt_shg_2_3_10 Tool for removing small faces from a shape
563
564Class ShapeFix_FixSmallFaceThis tool is intended for dropping small faces from the shape. The following cases are processed:
565* Spot face: if the size of the face is less than the given precision;
566* Strip face: if the size of the face in one dimension is less then the given precision.
567
568The sequence of actions for performing the fix is the same as for the fixes described above:
569
570~~~~~
571//creation of a tool
572Handle(ShapeFix_FixSmallFace) sff = new ShapeFix_FixSmallFace(shape);
573//setting of tolerances
574sff->SetPrecision(prec);
575sff->SetMaxTolerance(maxTol);
576//performing fixes
577sff.Perform();
578//getting the result
579TopoDS_Shape resShape = sff.FixShape();
580~~~~~
581
dba69de2 582@subsubsection occt_shg_2_3_11 Tool to modify tolerances of shapes (Class ShapeFix_ShapeTolerance).
72b7576f 583
584This tool provides a functionality to set tolerances of a shape and its sub-shapes.
585In Open CASCADE Technology only vertices, edges and faces have tolerances.
586
587This tool allows processing each concrete type of sub-shapes or all types at a time.
588You set the tolerance functionality as follows:
589 * set a tolerance for sub-shapes, by method SetTolerance,
590 * limit tolerances with given ranges, by method LimitTolerance.
591
592~~~~~
593//creation of a tool
594ShapeFix_ShapeTolerance Sft;
595//setting a specified tolerance on shape and all of its sub-shapes.
596Sft.SetTolerance(shape,toler);
597//setting a specified tolerance for vertices only
598Sft.SetTolerance(shape,toler,TopAbs_VERTEX);
4ee1bdf4 599//limiting the tolerance on the shape and its sub-shapes between minimum and maximum tolerances
72b7576f 600Sft.LimitTolerance(shape,tolermin,tolermax);
601~~~~~
602
603
604@section occt_shg_3 Analysis
605
dba69de2 606@subsection occt_shg_3_1 Analysis of shape validity
72b7576f 607
608The *ShapeAnalysis* package provides tools for the analysis of topological shapes.
609It is not necessary to check a shape by these tools before the execution of repairing tools because these tools are used for the analysis before performing fixes inside the repairing tools.
610However, if you want, these tools can be used for detecting some of shape problems independently from the repairing tools.
dba69de2 611
612 It can be done in the following way:
72b7576f 613 * create an analysis tool.
614 * initialize it by shape and set a tolerance problems will be detected with if it is necessary.
615 * check the problem that interests you.
616
617~~~~~
618TopoDS_Face face = ...;
619ShapeAnalysis_Edge sae;
620//Creates a tool for analyzing an edge
621for(TopExp_Explorer Exp(face,TopAbs_EDGE);Exp.More();Exp.Next()) {
dba69de2 622 TopoDS_Edge edge = TopoDS::Edge (Exp.Current());
623 if (!sae.HasCurve3d (edge)) {
4ee1bdf4 624 cout <<"Edge has no 3D curve"<< endl; }
72b7576f 625}
626~~~~~
627
628@subsubsection occt_shg_3_1_1 Analysis of orientation of wires on a face.
629
630It is possible to check whether a face has an outer boundary with the help of method *ShapeAnalysis::IsOuterBound*.
631
632~~~~~
633TopoDS_Face face … //analyzed face
634if(!ShapeAnalysis::IsOuterBound(face)) {
4ee1bdf4 635cout<<"Face has not outer boundary"<<endl;
72b7576f 636}
637~~~~~
638
639@subsubsection occt_shg_3_1_2 Analysis of wire validity
640
641Class *ShapeAnalysis_Wire* is intended to analyze a wire. It provides functionalities both to explore wire properties and to check its conformance to Open CASCADE Technology requirements.
642These functionalities include:
643 * checking the order of edges in the wire,
644 * checking for the presence of small edges (with a length less than the given value),
645 * checking for the presence of disconnected edges (adjacent edges having different vertices),
646 * checking the consistency of edge curves,
647 * checking for the presence or missing of degenerated edges,
648 * checking for the presence of self-intersecting edges and intersecting edges (edges intersection is understood as intersection of their 2D curves),
3f812249 649 * checking for lacking edges to fill gaps in the surface parametric space,
72b7576f 650 * analyzing the wire orientation (to define the outer or the inner bound on the face),
651 * analyzing the orientation of the shape (edge or wire) being added to an already existing wire.
652
dba69de2 653**Note** that all checking operations except for the first one are based on the assumption that edges in the wire are ordered. Thus, if the wire is detected as non-ordered it is necessary to order it before calling other checking operations. This can be done, for example, with the help of the *ShapeFix_Wire::FixOrder()* method.
654
72b7576f 655This tool should be initialized with wire, face (or a surface with a location) or precision.
656Once the tool has been initialized, it is possible to perform the necessary checking operations. In order to obtain all information on a wire at a time the global method *Perform* is provided. It calls all other API checking operations to check each separate case.
dba69de2 657
72b7576f 658API methods check for corresponding cases only, the value and the status they return can be analyzed to understand whether the case was detected or not.
dba69de2 659
72b7576f 660Some methods in this class are:
661 * *CheckOrder* checks whether edges in the wire are in the right order
662 * *CheckConnected* checks whether edges are disconnected
663 * *CheckSmall* checks whether there are edges that are shorter than the given value
664 * *CheckSelfIntersection* checks, whether there are self-intersecting or adjacent intersecting edges. If the intersection takes place due to nonadjacent edges, it is not detected.
dba69de2 665
666This class maintains status management. Each API method stores the status of its last execution which can be queried by the corresponding *Status..()* method. In addition, each API method returns a Boolean value, which is True when a case being analyzed is detected (with the set *ShapeExtend_DONE* status), otherwise it is False.
72b7576f 667
668~~~~~
669TopoDS_Face face = ...;
670TopoDS_Wire wire = ...;
671Standard_Real precision = 1e-04;
672ShapeAnalysis_Wire saw (wire, face, precision);
673//Creates a tool and loads objects into it
674if (saw.CheckOrder()) {
4ee1bdf4 675 cout<<"Some edges in the wire need to be reordered"<<endl;
676 cout<<"Please ensure that all the edges are correctly ordered before further analysis"<<endl;
dba69de2 677 return;
72b7576f 678}
679if (saw.CheckSmall (precision)) {
4ee1bdf4 680 cout<<"Wire contains edge(s) shorter than "<<precisionendl;
72b7576f 681}
682if (saw.CheckConnected()) {
4ee1bdf4 683 cout<<"Wire is disconnected"<<endl;
72b7576f 684}
685if (saw.CheckSelfIntersection()) {
4ee1bdf4 686 cout<<"Wire has self-intersecting or intersecting adjacent edges"<< endl;
72b7576f 687}
688~~~~~
689
690@subsubsection occt_shg_3_1_3 Analysis of edge validity
691
692Class *ShapeAnalysis_Edge* is intended to analyze edges. It provides the following functionalities to work with an edge:
693 * querying geometrical representations (3D curve and pcurve(s) on a given face or surface),
694 * querying topological sub-shapes (bounding vertices),
695 * checking overlapping edges,
696 * analyzing the curves consistency:
697 + mutual orientation of the 3D curve and 2D curve (co-directions or opposite directions),
698 + correspondence of 3D and 2D curves to vertices.
699
700This class supports status management described above.
701
702~~~~~
703TopoDS_Face face = ...;
704ShapeAnalysis_Edge sae;
705//Creates a tool for analyzing an edge
706for(TopExp_Explorer Exp(face,TopAbs_EDGE);Exp.More();Exp.Next()) {
dba69de2 707 TopoDS_Edge edge = TopoDS::Edge (Exp.Current());
708 if (!sae.HasCurve3d (edge)) {
4ee1bdf4 709 cout << "Edge has no 3D curve" << endl;
dba69de2 710 }
711 Handle(Geom2d_Curve) pcurve;
712 Standard_Real cf, cl;
713 if (sae.PCurve (edge, face, pcurve, cf, cl, Standard_False)) {
714 //Returns the pcurve and its range on the given face
4ee1bdf4 715 cout<<"Pcurve range ["<<cf<<", "<<cl<<"]"<< endl;
dba69de2 716 }
717 Standard_Real maxdev;
718 if (sae.CheckSameParameter (edge, maxdev)) {
4ee1bdf4 719 //Checks the consistency of all the curves in the edge
720 cout<<"Incorrect SameParameter flag"<<endl;
dba69de2 721 }
4ee1bdf4 722 cout<<"Maximum deviation "<<maxdev<<", tolerance"
723 <<BRep_Tool::Tolerance(edge)<<endl;
72b7576f 724}
725//checks the overlapping of two edges
726if(sae.CheckOverlapping(edge1,edge2,prec,dist)) {
4ee1bdf4 727 cout<<"Edges are overlapped with tolerance = "<<prec<<endl;
728 cout<<"Domain of overlapping ="<<dist<<endl;
72b7576f 729}
730~~~~~
731
732@subsubsection occt_shg_3_1_4 Analysis of presence of small faces
733
734Class *ShapeAnalysis_CheckSmallFace* class is intended for analyzing small faces from the shape using the following methods:
735* *CheckSpotFace()* checks if the size of the face is less than the given precision;
736* *CheckStripFace* checks if the size of the face in one dimension is less than the given precision.
737
738~~~~~
739TopoDS_Shape shape … // checked shape
740//Creation of a tool
741ShapeAnalysis_CheckSmallFace saf;
742//exploring the shape on faces and checking each face
743Standard_Integer numSmallfaces =0;
744for(TopExp_Explorer aExp(shape,TopAbs_FACE); aExp.More(); aExp.Next()) {
745 TopoDS_Face face = TopoDS::Face(aexp.Current());
746 TopoDS_Edge E1,E2;
747if(saf.CheckSpotFace(face,prec) ||
748saf.CheckStripFace(face,E1,E2,prec))
749NumSmallfaces++;
750}
751if(numSmallfaces)
4ee1bdf4 752 cout<<"Number of small faces in the shape ="<< numSmallfaces <<endl;
72b7576f 753~~~~~
754
755@subsubsection occt_shg_3_1_5 Analysis of shell validity and closure
756
757Class *ShapeAnalysis_Shell* allows checking the orientation of edges in a manifold shell. With the help of this tool, free edges (edges entered into one face) and bad edges (edges entered into the shell twice with the same orientation) can be found. By occurrence of bad and free edges a conclusion about the shell validity and the closure of the shell can be made.
758
759~~~~~
760TopoDS_Shell shell // checked shape
761ShapeAnalysis_Shell sas(shell);
762//analysis of the shell , second parameter is set to True for //getting free edges,(default False)
763sas.CheckOrientedShells(shell,Standard_True);
764//getting the result of analysis
765if(sas.HasBadEdges()) {
766cout<<"Shell is invalid"<<endl;
767TopoDS_Compound badEdges = sas.BadEdges();
768}
769if(sas.HasFreeEdges()) {
770 cout<<"Shell is open"<<endl;
771 TopoDS_Compound freeEdges = sas.FreeEdges();
772}
773~~~~~
774
775@subsection occt_shg_3_2 Analysis of shape properties.
776@subsubsection occt_shg_3_2_1 Analysis of tolerance on shape
777
778Class *ShapeAnalysis_ShapeTolerance* allows computing tolerances of the shape and its sub-shapes. In Open CASCADE Technology only vertices, edges and faces have tolerances:
779
780This tool allows analyzing each concrete type of sub-shapes or all types at a time.
781The analysis of tolerance functionality is the following:
782 * computing the minimum, maximum and average tolerances of sub-shapes,
783 * finding sub-shapes with tolerances exceeding the given value,
784 * finding sub-shapes with tolerances in the given range.
785
786~~~~~
787TopoDS_Shape shape = ...;
788ShapeAnalysis_ShapeTolerance sast;
789Standard_Real AverageOnShape = sast.Tolerance (shape, 0);
4ee1bdf4 790cout<<"Average tolerance of the shape is "<<AverageOnShape<<endl;
72b7576f 791Standard_Real MinOnEdge = sast.Tolerance (shape,-1,TopAbs_EDGE);
4ee1bdf4 792cout<<"Minimum tolerance of the edges is "<<MinOnEdge<<endl;
72b7576f 793Standard_Real MaxOnVertex = sast.Tolerance (shape,1,TopAbs_VERTEX);
4ee1bdf4 794cout<<"Maximum tolerance of the vertices is "<<MaxOnVertex<<endl;
72b7576f 795Standard_Real MaxAllowed = 0.1;
4ee1bdf4 796if (MaxOnVertex > MaxAllowed) {
797 cout<<"Maximum tolerance of the vertices exceeds maximum allowed"<<endl;
72b7576f 798}
799~~~~~
800
801@subsubsection occt_shg_3_2_2 Analysis of free boundaries.
802
803Class ShapeAnalysis_FreeBounds is intended to analyze and output the free bounds of a shape. Free bounds are wires consisting of edges referenced only once by only one face in the shape.
804This class works on two distinct types of shapes when analyzing their free bounds:
805* Analysis of possible free bounds taking the specified tolerance into account. This analysis can be applied to a compound of faces. The analyzer of the sewing algorithm (*BRepAlgo_Sewing*) is used to forecast what free bounds would be obtained after the sewing of these faces is performed. The following method should be used for this analysis:
806~~~~~
807ShapeAnalysis_FreeBounds safb(shape,toler);
808~~~~~
809* Analysis of already existing free bounds. Actual free bounds (edges shared by the only face in the shell) are output in this case. *ShapeAnalysis_Shell* is used for that.
810~~~~~
811ShapeAnalysis_FreeBounds safb(shape);
812~~~~~
dba69de2 813
72b7576f 814When connecting edges into wires this algorithm tries to build wires of maximum length. Two options are provided for the user to extract closed sub-contours out of closed and/or open contours. Free bounds are returned as two compounds, one for closed and one for open wires. To obtain a result it is necessary to use methods:
815~~~~~
dba69de2 816TopoDS_Compound ClosedWires = safb.GetClosedWires();
72b7576f 817TopoDS_Compound OpenWires = safb.GetOpenWires();
818~~~~~
819This class also provides some static methods for advanced use: connecting edges/wires to wires, extracting closed sub-wires from wires, distributing wires into compounds for closed and open wires.
820
821~~~~~
822TopoDS_Shape shape = ...;
823Standard_Real SewTolerance = 1.e-03;
824//Tolerance for sewing
825Standard_Boolean SplitClosed = Standard_False;
826Standard_Boolean SplitOpen = Standard_True;
827//in case of analysis of possible free boundaries
828ShapeAnalysis_FreeBounds safb (shape, SewTolerance,
829SplitClosed, SplitOpen);
830//in case of analysis of existing free bounds
831ShapeAnalysis_FreeBounds safb (shape, SplitClosed, SplitOpen);
832//getting the results
833TopoDS_Compound ClosedWires = safb.GetClosedWires();
834//Returns a compound of closed free bounds
835TopoDS_Compound OpenWires = safb.GetClosedWires();
836//Returns a compound of open free bounds
837~~~~~
838
839@subsubsection occt_shg_3_2_3 Analysis of shape contents
840
dba69de2 841Class *ShapeAnalysis_ShapeContents* provides tools counting the number of sub-shapes and selecting a sub-shape by the following criteria:
842
72b7576f 843Methods for getting the number of sub-shapes:
844 * number of solids,
845 * number of shells,
846 * number of faces,
847 * number of edges,
848 * number of vertices.
dba69de2 849
72b7576f 850Methods for calculating the number of geometrical objects or sub-shapes with a specified type:
851 * number of free faces,
852 * number of free wires,
853 * number of free edges,
854 * number of C0 surfaces,
855 * number of C0 curves,
856 * number of BSpline surfaces,… etc
dba69de2 857
72b7576f 858and selecting sub-shapes by various criteria.
859
860The corresponding flags should be set to True for storing a shape by a specified criteria:
3f812249 861 * faces based on indirect surfaces -- *safc.MofifyIndirectMode() = Standard_True*;
862 * faces based on offset surfaces -- *safc.ModifyOffsetSurfaceMode() = Standard_True*;
863 * edges if their 3D curves are trimmed -- *safc.ModifyTrimmed3dMode() = Standard_True*;
864 * edges if their 3D curves and 2D curves are offset curves -- *safc.ModifyOffsetCurveMode() = Standard_True*;
865 * edges if their 2D curves are trimmed -- *safc.ModifyTrimmed2dMode() = Standard_True*;
72b7576f 866
867Let us, for example, select faces based on offset surfaces.
868
869~~~~~
870ShapeAnalysis_ShapeContents safc;
871//set a corresponding flag for storing faces based on the offset surfaces
872safc.ModifyOffsetSurfaceMode() = Standard_True;
873safc.Perform(shape);
874//getting the number of offset surfaces in the shape
875Standard_Integer NbOffsetSurfaces = safc.NbOffsetSurf();
876//getting the sequence of faces based on offset surfaces.
877Handle(TopTools_HSequenceOfShape) seqFaces = safc.OffsetSurfaceSec();
878~~~~~
879
880@section occt_shg_4 Upgrading
881
882Upgrading tools are intended for adaptation of shapes for better use by Open CASCADE Technology or for customization to particular needs, i.e. for export to another system. This means that not only it corrects and upgrades but also changes the definition of a shape with regard to its geometry, size and other aspects. Convenient API allows you to create your own tools to perform specific upgrading. Additional tools for particular cases provide an ability to divide shapes and surfaces according to certain criteria.
883
884@subsection occt_shg_4_1 Tools for splitting a shape according to a specified criterion
885
886@subsubsection occt_shg_4_1_1 Overview
887
888These tools provide such modifications when one topological object can be divided or converted to several ones according to specified criteria. Besides, there are high level API tools for particular cases which:
889 * Convert the geometry of shapes up to a given continuity,
890 * split revolutions by U to segments less than the given value,
891 * convert to Bezier surfaces and Bezier curves,
892 * split closed faces,
893 * convert C0 BSpline curve to a sequence of C1 BSpline curves.
dba69de2 894
72b7576f 895All tools for particular cases are based on general tools for shape splitting but each of them has its own tools for splitting or converting geometry in accordance with the specified criteria.
896
897General tools for shape splitting are:
898 * tool for splitting the whole shape,
899 * tool for splitting a face,
900 * tool for splitting wires.
dba69de2 901
72b7576f 902Tools for shape splitting use tools for geometry splitting:
903 * tool for splitting surfaces,
904 * tool for splitting 3D curves,
905 * tool for splitting 2D curves.
906
907@subsubsection occt_shg_4_1_2 Using tools available for shape splitting.
908If it is necessary to split a shape by a specified continuity, split closed faces in the shape, split surfaces of revolution in the shape by angle or to convert all surfaces, all 3D curves, all 2D curves in the shape to Bezier, it is possible to use the existing/available tools.
dba69de2 909
72b7576f 910The usual way to use these tools exception for the tool of converting a C0 BSpline curve is the following:
911 * a tool is created and initialized by shape.
912 * work precision for splitting and the maximum allowed tolerance are set
913 * the value of splitting criterion Is set (if necessary)
914 * splitting is performed.
915 * splitting statuses are obtained.
916 * result is obtained
917 * the history of modification of the initial shape and its sub-shapes is output (this step is optional).
918
919Let us, for example, split all surfaces and all 3D and 2D curves having a continuity of less the C2.
920
921~~~~~
922//create a tool and initializes it by shape.
923ShapeUpgrade_ShapeDivideContinuity ShapeDivedeCont(initShape);
924
925//set the working 3D and 2D precision and the maximum allowed //tolerance
926ShapeDivideCont.SetTolerance(prec);
927ShapeDivideCont.SetTolerance2D(prec2d);
928ShapeDivideCont.SetMaxTolerance(maxTol);
929
930//set the values of criteria for surfaces, 3D curves and 2D curves.
931ShapeDivideCont.SetBoundaryCriterion(GeomAbs_C2);
932ShapeDivideCont.SetPCurveCriterion(GeomAbs_C2);
933ShapeDivideCont.SetSurfaceCriterion(GeomAbs_C2);
934
935//perform the splitting.
936ShapeDivideCont.Perform();
937
938//check the status and gets the result
939if(ShapeDivideCont.Status(ShapeExtend_DONE)
940 TopoDS_Shape result = ShapeDivideCont.GetResult();
941//get the history of modifications made to faces
942for(TopExp_Explorer aExp(initShape,TopAbs_FACE); aExp.More(0; aExp.Next()) {
4ee1bdf4 943 TopoDS_Shape modifShape = ShapeDivideCont.GetContext()-> Apply(aExp.Current());
72b7576f 944}
945~~~~~
946
947@subsubsection occt_shg_4_1_3 Creation of a new tool for splitting a shape.
dba69de2 948To create a new splitting tool it is necessary to create tools for geometry splitting according to a desirable criterion. The new tools should be inherited from basic tools for geometry splitting. Then the new tools should be set into corresponding tools for shape splitting.
949 * a new tool for surface splitting should be set into the tool for face splitting
950 * new tools for splitting of 3D and 2D curves should be set into the splitting tool for wires.
951
952To change the value of criterion of shape splitting it is necessary to create a new tool for shape splitting that should be inherited from the general splitting tool for shapes.
72b7576f 953
954Let us split a shape according to a specified criterion.
955
956~~~~~
4ee1bdf4 957//creation of new tools for geometry splitting by a specified criterion.
958Handle(MyTools_SplitSurfaceTool) MySplitSurfaceTool = new MyTools_SplitSurfaceTool;
959Handle(MyTools_SplitCurve3DTool) MySplitCurve3Dtool = new MyTools_SplitCurve3DTool;
960Handle(MyTools_SplitCurve2DTool) MySplitCurve2Dtool = new MyTools_SplitCurve2DTool;
72b7576f 961
4ee1bdf4 962//creation of a tool for splitting the shape and initialization of that tool by shape.
72b7576f 963TopoDS_Shape initShape
964MyTools_ShapeDivideTool ShapeDivide (initShape);
965
4ee1bdf4 966//setting of work precision for splitting and maximum allowed tolerance.
72b7576f 967ShapeDivide.SetPrecision(prec);
968ShapeDivide.SetMaxTolerance(MaxTol);
969
4ee1bdf4 970//setting of new splitting geometry tools in the shape splitting tools
971Handle(ShapeUpgrade_FaceDivide) FaceDivide = ShapeDivide->GetSplitFaceTool();
972Handle(ShapeUpgrade_WireDivide) WireDivide = FaceDivide->GetWireDivideTool();
973FaceDivide->SetSplitSurfaceTool(MySplitSurfaceTool);
974WireDivide->SetSplitCurve3dTool(MySplitCurve3DTool);
975WireDivide->SetSplitCurve2dTool(MySplitCurve2DTool);
72b7576f 976
977//setting of the value criterion.
dba69de2 978 ShapeDivide.SetValCriterion(val);
979
72b7576f 980//shape splitting
981ShapeDivide.Perform();
982
983//getting the result
984TopoDS_Shape splitShape = ShapeDivide.GetResult();
985
986//getting the history of modifications of faces
987for(TopExp_Explorer aExp(initShape,TopAbs_FACE); aExp.More(0; aExp.Next()) {
4ee1bdf4 988TopoDS_Shape modifShape = ShapeDivide.GetContext()-> Apply(aExp.Current());
72b7576f 989}
990~~~~~
991
992@subsection occt_shg_4_2 General splitting tools.
993
994@subsubsection occt_shg_4_2_1 General tool for shape splitting
995
dba69de2 996Class *ShapeUpgrade_ShapeDivide* provides shape splitting and converting according to the given criteria. It performs these operations for each face with the given tool for face splitting (*ShapeUpgrade_FaceDivide* by default).
997
998This tool provides access to the tool for dividing faces with the help of the methods *SetSplitFaceTool* and *GetSpliFaceTool.*
72b7576f 999
1000@subsubsection occt_shg_4_2_2 General tool for face splitting
dba69de2 1001
1002Class *ShapeUpgrade_FaceDivide* divides a Face (edges in the wires, by splitting 3D and 2D curves, as well as the face itself, by splitting the supporting surface) according to the given criteria.
1003
72b7576f 1004The area of the face intended for division is defined by 2D curves of the wires on the Face.
1005All 2D curves are supposed to be defined (in the parametric space of the supporting surface).
1006The result is available after the call to the *Perform* method. It is a Shell containing all resulting Faces. All modifications made during the splitting operation are recorded in the external context (*ShapeBuild_ReShape*).
dba69de2 1007
1008This tool provides access to the tool for wire division and surface splitting by means of the following methods:
1009* *SetWireDivideTool,*
1010* *GetWireDivideTool,*
1011* *SetSurfaceSplitTool,*
1012* *GetSurfaceSplitTool*.
72b7576f 1013
1014@subsubsection occt_shg_4_2_3 General tool for wire splitting
1015Class *ShapeUpgrade_WireDivide* divides edges in the wire lying on the face or free wires or free edges with a given criterion. It splits the 3D curve and 2D curve(s) of the edge on the face. Other 2D curves, which may be associated with the edge, are simply copied. If the 3D curve is split then the 2D curve on the face is split as well, and vice-versa. The original shape is not modified. Modifications made are recorded in the context (*ShapeBuild_ReShape*).
dba69de2 1016
1017This tool provides access to the tool for dividing and splitting 3D and 2D curves by means of the following methods:
1018* *SetEdgeDivdeTool,*
1019* *GetEdgeDivideTool,*
1020* *SetSplitCurve3dTool,*
1021* *GetSplitCurve3dTool,*
1022* *SetSplitCurve2dTool,*
1023* *GetSplitCurve2dTool*
1024
1025and it also provides access to the mode for splitting edges by methods *SetEdgeMode* and *GetEdgeMode*.
1026
72b7576f 1027This mode sets whether only free edges, only shared edges or all edges are split.
1028
dba69de2 1029@subsubsection occt_shg_4_2_4 General tool for edge splitting
1030
72b7576f 1031Class *ShapeUpgrade_EdgeDivide* divides edges and their geometry according to the specified criteria. It is used in the wire-dividing tool.
dba69de2 1032
72b7576f 1033This tool provides access to the tool for dividing and splitting 3D and 2D curves by the following methods:
dba69de2 1034* *SetSplitCurve3dTool,*
1035* *GetSplitCurve3dTool,*
1036* *SetSplitCurve2dTool,*
1037* *GetSplitCurve2dTool*.
72b7576f 1038
1039@subsubsection occt_shg_4_2_5 General tools for geometry splitting
4ee1bdf4 1040
72b7576f 1041There are three general tools for geometry splitting.
1042 * General tool for surface splitting.(*ShapeUpgrade_SplitSurface*)
1043 * General tool for splitting 3D curves.(*ShapeUpgrade_SplitCurve3d*)
1044 * General tool for splitting 2D curves.(*ShapeUpgrade_SplitCurve2d*)
dba69de2 1045
72b7576f 1046All these tools are constructed the same way:
1047They have methods:
1048 * for initializing by geometry (method *Init*)
1049 * for splitting (method *Perform*)
1050 * for getting the status after splitting and the results:
3f812249 1051 + *Status* -- for getting the result status;
1052 + *ResSurface* -- for splitting surfaces;
1053 + *GetCurves* -- for splitting 3D and 2D curves.
72b7576f 1054During the process of splitting in the method *Perform* :
dba69de2 1055 * splitting values in the parametric space are computed according to a specified criterion (method *Compute*)
72b7576f 1056 * splitting is made in accordance with the values computed for splitting (method *Build*).
1057
3f812249 1058To create new tools for geometry splitting it is enough to inherit a new tool from the general tool for splitting a corresponding type of geometry and to redefine the method for computation of splitting values according to the specified criterion in them. (method *Compute*).
72b7576f 1059
1060Header file for the tool for surface splitting by continuity:
1061
1062~~~~~
1063class ShapeUpgrade_SplitSurfaceContinuity : public ShapeUpgrade_SplitSurface {
1064Standard_EXPORT ShapeUpgrade_SplitSurfaceContinuity();
1065
4ee1bdf4 1066//methods to set the criterion and the tolerance into the splitting tool
dba69de2 1067Standard_EXPORT void SetCriterion(const GeomAbs_Shape Criterion) ;
1068Standard_EXPORT void SetTolerance(const Standard_Real Tol) ;
72b7576f 1069
4ee1bdf4 1070//redefinition of method Compute
72b7576f 1071Standard_EXPORT virtual void Compute(const Standard_Boolean Segment) ;
1072Standard_EXPORT ~ShapeUpgrade_SplitSurfaceContinuity();
1073private:
1074GeomAbs_Shape myCriterion;
1075Standard_Real myTolerance;
1076Standard_Integer myCont;
1077};
1078~~~~~
1079
1080@subsection occt_shg_4_3 Specific splitting tools.
1081
1082@subsubsection occt_shg_4_3_1 Conversion of shape geometry to the target continuity
1083Class *ShapeUpgrade_ShapeDivideContinuity* allows converting geometry with continuity less than the specified continuity to geometry with target continuity. If converting is not possible than geometrical object is split into several ones, which satisfy the given criteria. A topological object based on this geometry is replaced by several objects based on the new geometry.
1084
1085~~~~~
1086ShapeUpgrade_ShapeDivideContinuity sdc (shape);
1087sdc.SetTolerance (tol3d);
1088sdc.SetTolerance3d (tol2d); // if known, else 1.e-09 is taken
1089sdc.SetBoundaryCriterion (GeomAbs_C2); // for Curves 3D
1090sdc.SetPCurveCriterion (GeomAbs_C2); // for Curves 2D
1091sdc.SetSurfaceCriterion (GeomAbs_C2); // for Surfaces
1092sdc.Perform ();
1093TopoDS_Shape bshape = sdc.Result();
4ee1bdf4 1094//.. to also get the correspondances before/after
72b7576f 1095Handle(ShapeBuild_ReShape) ctx = sdc.Context();
4ee1bdf4 1096//.. on a given shape
72b7576f 1097if (ctx.IsRecorded (sh)) {
dba69de2 1098 TopoDS_Shape newsh = ctx->Value (sh);
4ee1bdf4 1099// if there are several results, they are recorded inside a Compound.
72b7576f 1100// .. process as needed
1101}
1102~~~~~
1103
1104@subsubsection occt_shg_4_3_2 Splitting by angle
1105Class *ShapeUpgrade_ShapeDivideAngle* allows splitting all surfaces of revolution, cylindrical, toroidal, conical, spherical surfaces in the given shape so that each resulting segment covers not more than the defined angle (in radians).
1106
1107@subsubsection occt_shg_4_3_3 Conversion of 2D, 3D curves and surfaces to Bezier
1108
dba69de2 1109Class *ShapeUpgrade_ShapeConvertToBezier* is an API tool for performing a conversion of 3D, 2D curves to Bezier curves and surfaces to Bezier based surfaces (Bezier surface, surface of revolution based on Bezier curve, offset surface based on any of previous types).
1110
72b7576f 1111This tool provides access to various flags for conversion of different types of curves and surfaces to Bezier by methods:
dba69de2 1112* For 3D curves:
1113 * *Set3dConversion,*
1114 * *Get3dConversion,*
1115 * *Set3dLineConversion,*
1116 * *Get3dLineConversion,*
1117 * *Set3dCircleConversion,*
1118 * *Get3dCircleConversion,*
1119 * *Set3dConicConversion,*
1120 * *Get3dConicConversion*
1121* For 2D curves:
1122 * *Set2dConversion,*
1123 * *Get2dConversion*
1124* For surfaces :
1125 * *GetSurfaceConversion,*
1126 * *SetPlaneMode,*
1127 * *GetPlaneMode,*
1128 * *SetRevolutionMode,*
1129 * *GetRevolutionMode,*
1130 * *SetExtrusionMode,*
1131 * *GetExtrusionMode,*
1132 * *SetBSplineMode,*
1133 * *GetBSplineMode,*
72b7576f 1134
1135Let us attempt to produce a conversion of planes to Bezier surfaces.
1136~~~~~
1137//Creation and initialization of a tool.
1138ShapeUpgrade_ShapeConvertToBezier SCB (Shape);
1139//setting tolerances
4ee1bdf4 1140...
72b7576f 1141//setting mode for conversion of planes
1142SCB.SetSurfaceConversion (Standard_True);
1143SCB.SetPlaneMode(Standard_True);
1144SCB.Perform();
1145If(SCB.Status(ShapeExtend_DONE)
dba69de2 1146 TopoDS_Shape result = SCB.GetResult();
72b7576f 1147~~~~~
1148
1149@subsubsection occt_shg_4_3_4 Tool for splitting closed faces
1150
1151Class *ShapeUpgrade_ShapeDivideClosed* provides splitting of closed faces in the shape to a defined number of components by the U and V parameters. It topologically and (partially) geometrically processes closed faces and performs splitting with the help of class *ShapeUpgrade_ClosedFaceDivide*.
1152
1153~~~~~
1154TopoDS_Shape aShape = …;
1155ShapeUpgrade_ShapeDivideClosed tool (aShape );
1156Standard_Real closeTol = …;
1157tool.SetPrecision(closeTol);
1158Standard_Real maxTol = …;
1159tool.SetMaxTolerance(maxTol);
1160Standard_Integer NbSplitPoints = …;
1161tool.SetNbSplitPoints(num);
e5bd0d98 1162if ( ! tool.Perform() && tool.Status (ShapeExtend_FAIL) ) {
4ee1bdf4 1163 cout<<"Splitting of closed faces failed"<<endl;
dba69de2 1164 . . .
72b7576f 1165}
1166TopoDS_Shape aResult = tool.Result();
1167~~~~~
1168
1169@subsubsection occt_shg_4_3_5 Tool for splitting a C0 BSpline 2D or 3D curve to a sequence C1 BSpline curves
1170
1171The API methods for this tool is a package of methods *ShapeUpgrade::C0BSplineToSequenceOfC1BsplineCurve*, which converts a C0 B-Spline curve into a sequence of C1 B-Spline curves. This method splits a B-Spline at the knots with multiplicities equal to degree, it does not use any tolerance and therefore does not change the geometry of the B-Spline. The method returns True if C0 B-Spline was successfully split, otherwise returns False (if BS is C1 B-Spline).
1172
1173@subsubsection occt_shg_4_3_6 Tool for splitting faces
1174
1175*ShapeUpgrade_ShapeDivideArea* can work with compounds, solids, shells and faces.
dba69de2 1176During the work this tool examines each face of a specified shape and if the face area exceeds the specified maximal area, this face is divided. Face splitting is performed in the parametric space of this face. The values of splitting in U and V directions are calculated with the account of translation of the bounding box form parametric space to 3D space.
1177
1178Such calculations are necessary to avoid creation of strip faces. In the process of splitting the holes on the initial face are taken into account. After the splitting all new faces are checked by area again and the splitting procedure is repeated for the faces whose area still exceeds the max allowed area. Sharing between faces in the shape is preserved and the resulting shape is of the same type as the source shape.
1179
72b7576f 1180An example of using this tool is presented in the figures below:
1181
d6b4d3d0 1182@figure{/user_guides/shape_healing/images/shape_healing_image003.png,"Source Face",240}
72b7576f 1183
d6b4d3d0 1184@figure{/user_guides/shape_healing/images/shape_healing_image004.png,"Resulting shape",240}
72b7576f 1185
1186
1187*ShapeUpgrade_ShapeDivideArea* is inherited from the base class *ShapeUpgrade_ShapeDivide* and should be used in the following way:
1188* This class should be initialized on a shape with the help of the constructor or method *Init()* from the base class.
1189* The maximal allowed area should be specified by the method *MaxArea()*.
1190* To produce a splitting use method Perform from the base class.
1191* The result shape can be obtained with the help the method *Result()*.
1192
1193~~~~~
1194ShapeUpgrade_ShapeDivideArea tool (inputShape);
1195tool.MaxArea() = aMaxArea;
1196tool.Perform();
1197if(tool.Status(ShapeExtend_DONE)) {
dba69de2 1198 TopoDS_Shape ResultShape = tool.Result();
1199 ShapeFix::SameParameter ( ResultShape, Standard_False );
72b7576f 1200}
1201~~~~~
1202
1203**Note** that the use of method *ShapeFix::SameParameter* is necessary, otherwise the parameter edges obtained as a result of splitting can be different.
1204
dba69de2 1205#### Additional methods
1206
72b7576f 1207* Class *ShapeUpgrade_FaceDivideArea* inherited from *ShapeUpgrade_FaceDivide* is intended for splitting a face by the maximal area criterion.
1208* Class *ShapeUpgrade_SplitSurfaceArea* inherited from *ShapeUpgrade_SplitSurface* calculates the parameters of face splitting in the parametric space.
1209
1210
1211@subsection occt_shg_4_4 Customization of shapes
1212
1213Customization tools are intended for adaptation of shape geometry in compliance with the customer needs. They modify a geometrical object to another one in the shape.
1214
1215To implement the necessary shape modification it is enough to initialize the appropriate tool by the shape and desirable parameters and to get the resulting shape. For example for conversion of indirect surfaces in the shape do the following:
1216
1217~~~~~
1218TopoDS_Shape initialShape ..
1219TopoDS_Shape resultShape = ShapeCustom::DirectFaces(initialShape);
1220~~~~~
1221
dba69de2 1222@subsubsection occt_shg_4_4_1 Conversion of indirect surfaces.
72b7576f 1223
1224~~~~~
1225ShapeCustom::DirectFaces
1226 static TopoDS_Shape DirectFaces(const TopoDS_Shape& S);
1227~~~~~
1228
4ee1bdf4 1229This method provides conversion of indirect elementary surfaces (elementary surfaces with left-handed coordinate systems) in the shape into direct ones. New 2d curves (recomputed for converted surfaces) are added to the same edges being shared by both the resulting shape and the original shape *S*.
72b7576f 1230
dba69de2 1231@subsubsection occt_shg_4_4_2 Shape Scaling
72b7576f 1232
1233~~~~~
1234ShapeCustom::ScaleShape
1235 TopoDS_Shape ShapeCustom::ScaleShape(const TopoDS_Shape& S,
1236 const Standard_Real scale);
1237~~~~~
1238
1239This method returns a new shape, which is a scaled original shape with a coefficient equal to the specified value of scale. It uses the tool *ShapeCustom_TrsfModification*.
1240
dba69de2 1241@subsubsection occt_shg_4_4_3 Conversion of curves and surfaces to BSpline
1242
1243*ShapeCustom_BSplineRestriction* allows approximation of surfaces, curves and 2D curves with a specified degree, maximum number of segments, 2d tolerance and 3d tolerance. If the approximation result cannot be achieved with the specified continuity, the latter can be reduced.
72b7576f 1244
1245The method with all parameters looks as follows:
1246~~~~~
1247ShapeCustom::BsplineRestriction
e5bd0d98 1248 TopoDS_Shape ShapeCustom::BSplineRestriction (const TopoDS_Shape& S,
72b7576f 1249 const Standard_Real Tol3d, const Standard_Real Tol2d,
1250 const Standard_Integer MaxDegree,
1251 const Standard_Integer MaxNbSegment,
1252 const GeomAbs_Shape Continuity3d,
1253 const GeomAbs_Shape Continuity2d,
1254 const Standard_Boolean Degree,
1255 const Standard_Boolean Rational,
e5bd0d98 1256 const Handle(ShapeCustom_RestrictionParameters)& aParameters)
72b7576f 1257~~~~~
1258
dba69de2 1259It returns a new shape with all surfaces, curves and 2D curves of BSpline/Bezier type or based on them, converted with a degree less than *MaxDegree* or with a number of spans less then *NbMaxSegment* depending on the priority parameter *Degree*. If this parameter is equal to True then *Degree* will be increased to the value *GmaxDegree*, otherwise *NbMaxSegments* will be increased to the value *GmaxSegments*. *GmaxDegree* and *GMaxSegments* are the maximum possible degree and the number of spans correspondingly. These values will be used in cases when an approximation with specified parameters is impossible and either *GmaxDegree* or *GMaxSegments* is selected depending on the priority.
1260
4ee1bdf4 1261Note that if approximation is impossible with *GMaxDegree*, even then the number of spans can exceed the specified *GMaxSegment*. *Rational* specifies whether Rational BSpline/Bezier should be converted into polynomial B-Spline.
dba69de2 1262
72b7576f 1263Also note that the continuity of surfaces in the resulting shape can be less than the given value.
1264
dba69de2 1265#### Flags
1266
72b7576f 1267To convert other types of curves and surfaces to BSpline with required parameters it is necessary to use flags from class ShapeCustom_RestrictionParameters, which is just a container of flags.
1268The following flags define whether a specified-type geometry has been converted to BSpline with the required parameters:
4ee1bdf4 1269* *ConvertPlane,*
1270* *ConvertBezierSurf,*
1271* *ConvertRevolutionSurf,*
1272* *ConvertExtrusionSurf,*
dba69de2 1273* *ConvertOffsetSurf,*
3f812249 1274* *ConvertCurve3d,* -- for conversion of all types of 3D curves.
1275* *ConvertOffsetCurv3d,* -- for conversion of offset 3D curves.
1276* *ConvertCurve2d,* -- for conversion of all types of 2D curves.
1277* *ConvertOffsetCurv2d,* -- for conversion of offset 2D curves.
1278* *SegmentSurfaceMode* -- defines whether the surface would be approximated within the boundaries of the face lying on this surface.
72b7576f 1279
72b7576f 1280
dba69de2 1281
1282@subsubsection occt_shg_4_4_4 Conversion of elementary surfaces into surfaces of revolution
72b7576f 1283
1284~~~~~
1285ShapeCustom::ConvertToRevolution()
1286 TopoDS_Shape ShapeCustom::ConvertToRevolution(const TopoDS_Shape& S) ;
1287~~~~~
1288
dba69de2 1289This method returns a new shape with all elementary periodic surfaces converted to *Geom_SurfaceOfRevolution*. It uses the tool *ShapeCustom_ConvertToRevolution*.
72b7576f 1290
dba69de2 1291@subsubsection occt_shg_4_4_5 Conversion of elementary surfaces into Bspline surfaces
72b7576f 1292
1293~~~~~
1294ShapeCustom::ConvertToBSpline()
e5bd0d98 1295 TopoDS_Shape ShapeCustom::ConvertToBSpline( const TopoDS_Shape& S,
72b7576f 1296 const Standard_Boolean extrMode,
1297 const Standard_Boolean revolMode,
1298 const Standard_Boolean offsetMode);
dba69de2 1299~~~~~
1300
1301This method returns a new shape with all surfaces of linear extrusion, revolution and offset surfaces converted according to flags to *Geom_BSplineSurface* (with the same parameterization). It uses the tool *ShapeCustom_ConvertToBSpline*.
72b7576f 1302
dba69de2 1303@subsubsection occt_shg_4_4_6 Getting the history of modification of sub-shapes.
72b7576f 1304If, in addition to the resulting shape, you want to get the history of modification of sub-shapes you should not use the package methods described above and should use your own code instead:
13051. Create a tool that is responsible for the necessary modification.
dba69de2 13062. Create the tool *BRepTools_Modifier* that performs a specified modification in the shape.
72b7576f 13073. To get the history and to keep the assembly structure use the method *ShapeCustom::ApplyModifier*.
1308
1309
1310The general calling syntax for scaling is
1311~~~~~
1312TopoDS_Shape scaled_shape = ShapeCustom::ScaleShape(shape, scale);
1313~~~~~
1314
3f812249 1315Note that scale is a real value. You can refine your mapping process by using additional calls to follow shape mapping sub-shape by sub-shape. The following code along with pertinent includes can be used:
72b7576f 1316
1317~~~~~
1318p_Trsf T;
1319Standard_Real scale = 100; // for example!
1320T.SetScale (gp_Pnt (0, 0, 0), scale);
1321Handle(ShapeCustom_TrsfModification) TM = new
1322ShapeCustom_TrsfModification(T);
1323TopTools_DataMapOfShapeShape context;
1324BRepTools_Modifier MD;
1325TopoDS_Shape res = ShapeCustom::ApplyModifier (
1326Shape, TM, context,MD );
1327~~~~~
1328
1329The map, called context in our example, contains the history.
1330Substitutions are made one by one and all shapes are transformed.
3f812249 1331To determine what happens to a particular sub-shape, it is possible to use:
72b7576f 1332
1333~~~~~
1334TopoDS_Shape oneres = context.Find (oneshape);
1335//In case there is a doubt, you can also add:
1336if (context.IsBound(oneshape)) oneres = context.Find(oneshape);
1337//You can also sweep the entire data map by using:
1338TopTools_DataMapIteratorOfDataMapOfShapeShape
1339//To do this, enter:
1340for(TopTools_DataMapIteratorOfDataMapOfShapeShape
1341iter(context);iter(more ();iter.next ()) {
dba69de2 1342 TopoDs_Shape oneshape = iter.key ();
1343 TopoDs_Shape oneres = iter.value ();
72b7576f 1344}
1345~~~~~
1346
1347
dba69de2 1348@subsubsection occt_shg_4_4_7 Remove internal wires
72b7576f 1349
1350*ShapeUpgrade_RemoveInternalWires* tool removes internal wires with contour area less than the specified minimal area. It can work with compounds, solids, shells and faces.
dba69de2 1351
72b7576f 1352If the flag *RemoveFaceMode* is set to TRUE, separate faces or a group of faces with outer wires, which consist only of edges that belong to the removed internal wires, are removed (seam edges are not taken into account). Such faces can be removed only for a sewed shape.
dba69de2 1353
72b7576f 1354Internal wires can be removed by the methods *Perform*. Both methods *Perform* can not be carried out if the class has not been initialized by the shape. In such case the status of *Perform* is set to FAIL .
dba69de2 1355
72b7576f 1356The method *Perform* without arguments removes from all faces in the specified shape internal wires whose area is less than the minimal area.
dba69de2 1357
72b7576f 1358The other method *Perform* has a sequence of shapes as an argument. This sequence can contain faces or wires.
1359If the sequence of shapes contains wires, only the internal wires are removed.
dba69de2 1360
72b7576f 1361If the sequence of shapes contains faces, only the internal wires from these faces are removed.
dba69de2 1362
72b7576f 1363* The status of the performed operation can be obtained using method *Status()*;
1364* The resulting shape can be obtained using method *GetResult()*.
1365
1366An example of using this tool is presented in the figures below:
1367
d6b4d3d0 1368@figure{/user_guides/shape_healing/images/shape_healing_image005.png,"Source Face",240}
1369@figure{/user_guides/shape_healing/images/shape_healing_image006.png,"Resulting shape",240}
72b7576f 1370
1371After the processing three internal wires with contour area less than the specified minimal area have been removed. One internal face has been removed. The outer wire of this face consists of the edges belonging to the removed internal wires and a seam edge.
1372Two other internal faces have not been removed because their outer wires consist not only of edges belonging to the removed wires.
1373
d6b4d3d0 1374@figure{/user_guides/shape_healing/images/shape_healing_image007.png,"Source Face",240}
dba69de2 1375
d6b4d3d0 1376@figure{/user_guides/shape_healing/images/shape_healing_image008.png,"Resulting shape",240}
72b7576f 1377
1378After the processing six internal wires with contour area less than the specified minimal area have been removed. Six internal faces have been removed. These faces can be united into groups of faces. Each group of faces has an outer wire consisting only of edges belonging to the removed internal wires. Such groups of faces are also removed.
1379
1380The example of method application is also given below:
1381
1382~~~~~
4ee1bdf4 1383//Initialization of the class by shape.
72b7576f 1384Handle(ShapeUpgrade_RemoveInternalWires) aTool = new ShapeUpgrade_RemoveInternalWires(inputShape);
1385//setting parameters
4ee1bdf4 1386aTool->MinArea() = aMinArea;
1387aTool->RemoveFaceMode() = aModeRemoveFaces;
72b7576f 1388
1389//when method Perform is carried out on separate shapes.
4ee1bdf4 1390aTool->Perform(aSeqShapes);
72b7576f 1391
1392//when method Perform is carried out on whole shape.
4ee1bdf4 1393aTool->Perform();
72b7576f 1394//check status set after method Perform
4ee1bdf4 1395if(aTool->Status(ShapeExtend_FAIL) {
1396 cout<<"Operation failed"<< <<"\n";
dba69de2 1397 return;
72b7576f 1398}
1399
4ee1bdf4 1400if(aTool->Status(ShapeExtend_DONE1)) {
1401 const TopTools_SequenceOfShape& aRemovedWires =aTool->RemovedWires();
1402 cout<<aRemovedWires.Length()<<" internal wires were removed"<<"\n";
dba69de2 1403
1404 }
72b7576f 1405
4ee1bdf4 1406 if(aTool->Status(ShapeExtend_DONE2)) {
1407 const TopTools_SequenceOfShape& aRemovedFaces =aTool->RemovedFaces();
1408 cout<<aRemovedFaces.Length()<<" small faces were removed"<<"\n";
dba69de2 1409
1410 }
1411 //getting result shape
4ee1bdf4 1412 TopoDS_Shape res = aTool->GetResult();
72b7576f 1413~~~~~
1414
dba69de2 1415@subsubsection occt_shg_4_4_8 Conversion of surfaces
72b7576f 1416
1417Class ShapeCustom_Surface allows:
1418 * converting BSpline and Bezier surfaces to the analytical form (using method *ConvertToAnalytical())*
1419 * converting closed B-Spline surfaces to periodic ones.(using method *ConvertToPeriodic*)
1420
1421To convert surfaces to analytical form this class analyzes the form and the closure of the source surface and defines whether it can be approximated by analytical surface of one of the following types:
1422* *Geom_Plane,*
1423* *Geom_SphericalSurface,*
1424* *Geom_CylindricalSurface,*
1425* *Geom_ConicalSurface,*
1426* *Geom_ToroidalSurface*.
1427
1428The conversion is done only if the new (analytical) surface does not deviate from the source one more than by the given precision.
1429
1430~~~~~
1431Handle(Geom_Surface) initSurf;
1432ShapeCustom_Surface ConvSurf(initSurf);
1433//conversion to analytical form
dba69de2 1434Handle(Geom_Surface) newSurf = ConvSurf.ConvertToAnalytical(allowedtol,Standard_False);
72b7576f 1435//or conversion to a periodic surface
dba69de2 1436Handle(Geom_Surface) newSurf = ConvSurf.ConvertToPeriodic(Standard_False);
72b7576f 1437//getting the maximum deviation of the new surface from the initial surface
1438Standard_Real maxdist = ConvSurf.Gap();
1439~~~~~
1440
cef6867c 1441@subsubsection occt_shg_4_4_9 Unify Same Domain
1442
1443*ShapeUpgrade_UnifySameDomain* tool allows unifying all possible faces and edges of a shape, which lies on the same geometry. Faces/edges are considered as 'same-domain' if the neighboring faces/edges lie on coincident surfaces/curves. Such faces/edges can be unified into one face/edge.
1444This tool takes an input shape and returns a new one. All modifications of the initial shape are recorded during the operation.
1445
1446The following options are available:
1447
1448 * If the flag *UnifyFaces* is set to TRUE, *UnifySameDomain* tries to unify all possible faces;
1449 * If the flag *UnifyEdges* is set to TRUE, *UnifySameDomain* tries to unify all possible edges;
1450 * if the flag *ConcatBSplines* is set to TRUE, all neighboring edges, which lie on the BSpline or Bezier curves with C1 continuity on their common vertices will be merged into one common edge.
1451
1452By default, *UnifyFaces* and *UnifyEdges* are set to TRUE; *ConcatBSplines* is set to FALSE.
1453
1454The common methods of this tool are as follows:
1455
1456 * Method *Build()* is used to unify.
1457 * Method *Shape()* is used to get the resulting shape.
1458 * Method *Generated()* is used to get a new common shape from the old shape. If a group of edges has been unified into one common edge then method *Generated()* called on any edge from this group will return the common edge. The same goes for the faces.
1459
1460The example of the usage is given below:
1461~~~~~
1462 // 'Sh' is the initial shape
1463 ShapeUpgrade_UnifySameDomain USD(Sh, true, true, true); // UnifyFaces mode on, UnifyEdges mode on, ConcatBSplines mode on.
1464 USD.Build();
1465 //get the result
1466 TopoDS_Shape Result = USD.Shape();
1467 //Let Sh1 as a part of Sh
1468 //get the new (probably unified) shape form the Sh1
1469 TopoDS_Shape ResSh1 = USD.Generated(Sh1);
1470~~~~~
1471
72b7576f 1472@section occt_shg_5_ Auxiliary tools for repairing, analysis and upgrading
ba06f8bb 1473
72b7576f 1474@subsection occt_shg_5_1 Tool for rebuilding shapes
1475
cef6867c 1476 Class *ShapeBuild_ReShape* rebuilds a shape by making predefined substitutions on some of its components. During the first phase, it records requests to replace or remove some individual shapes. For each shape, the last given request is recorded. Requests may be applied as *Oriented* (i.e. only to an item with the same orientation) or not (the orientation of the replacing shape corresponds to that of the original one). Then these requests may be applied to any shape, which may contain one or more of these individual shapes.
dba69de2 1477
72b7576f 1478This tool has a flag for taking the location of shapes into account (for keeping the structure of assemblies) (*ModeConsiderLocation*). If this mode is equal to Standard_True, the shared shapes with locations will be kept. If this mode is equal to Standard_False, some different shapes will be produced from one shape with different locations after rebuilding. By default, this mode is equal to Standard_False.
dba69de2 1479
72b7576f 1480To use this tool for the reconstruction of shapes it is necessary to take the following steps:
14811. Create this tool and use method *Apply()* for its initialization by the initial shape. Parameter *until* sets the level of shape type and requests are taken into account up to this level only. Sub-shapes of the type standing beyond the *line* set by parameter until will not be rebuilt and no further exploration will be done
14822. Replace or remove sub-shapes of the initial shape. Each sub-shape can be replaced by a shape of the same type or by shape containing shapes of that type only (for example, *TopoDS_Edge* can be replaced by *TopoDS_Edge, TopoDS_Wire* or *TopoDS_Compound* containing *TopoDS_Edges*). If an incompatible shape type is encountered, it is ignored and flag FAIL1 is set in Status.
1483For a sub-shape it is recommended to use method *Apply* before methods *Replace* and *Remove*, because the sub-shape has already been changed for the moment by its previous modifications or modification of its sub-shape (for example *TopoDS_Edge* can be changed by a modification of its *TopoDS_Vertex*, etc.).
14843. Use method *Apply* for the initial shape again to get the resulting shape after all modifications have been made.
14854. Use method *Apply* to obtain the history of sub-shape modification.
1486
b60e8432 1487Additional method *IsNewShape* can be used to check if the shape has been recorded by *BRepTools_ReShape* tool as a value.
1488
72b7576f 1489**Note** that in fact class *ShapeBuild_ReShape* is an alias for class *BRepTools_ReShape*. They differ only in queries of statuses in the *ShapeBuild_ReShape* class.
1490
1491Let us use the tool to get the result shape after modification of sub-shapes of the initial shape:
1492
1493~~~~~
1494TopoDS_Shape initialShape…
1495//creation of a rebuilding tool
1496Handle(ShapeBuild_ReShape) Context = new ShapeBuild_ReShape.
1497
4ee1bdf4 1498//next step is optional. It can be used for keeping the assembly structure.
1499Context-> ModeConsiderLocation = Standard_True;
72b7576f 1500
1501//initialization of this tool by the initial shape
4ee1bdf4 1502Context->Apply(initialShape);
72b7576f 1503
4ee1bdf4 1504//getting the intermediate result for replacing subshape1 with the modified subshape1.
1505TopoDS_Shape tempshape1 = Context->Apply(subshape1);
72b7576f 1506
4ee1bdf4 1507//replacing the intermediate shape obtained from subshape1 with the newsubshape1.
1508Context->Replace(tempsubshape1,newsubshape1);
72b7576f 1509
3f812249 1510//for removing the sub-shape
4ee1bdf4 1511TopoDS_Shape tempshape2 = Context->Apply(subshape2);
1512Context->Remove(tempsubshape2);
72b7576f 1513
1514//getting the result and the history of modification
4ee1bdf4 1515TopoDS_Shape resultShape = Context->Apply(initialShape);
72b7576f 1516
3f812249 1517//getting the resulting sub-shape from the subshape1 of the initial shape.
4ee1bdf4 1518TopoDS_Shape result_subshape1 = Context->Apply(subshape1);
72b7576f 1519~~~~~
1520
1521@subsection occt_shg_5_2 Status definition
1522
4ee1bdf4 1523*ShapExtend_Status* is used to report the status after executing some methods that can either fail, do something, or do nothing. The status is a set of flags *DONEi* and *FAILi*. Any combination of them can be set at the same time. For exploring the status, enumeration is used.
dba69de2 1524
72b7576f 1525The values have the following meaning:
4ee1bdf4 1526
e5bd0d98 1527| Value | Meaning |
1528| :----- | :----------------- |
4ee1bdf4 1529| *OK,* | Nothing is done, everything OK |
1530| *DONE1,* | Something was done, case 1 |
1531| *DONE8*, | Something was done, case 8 |
1532| *DONE*, | Something was done (any of DONE#) |
1533| *FAIL1*, | The method failed, case 1 |
1534| *FAIL8*, | The method failed, case 8 |
1535| *FAIL* | The method failed (any of FAIL# occurred) |
72b7576f 1536
1537
1538@subsection occt_shg_5_3 Tool representing a wire
1539Class *ShapeExtend_WireData* provides a data structure necessary to work with the wire as with an ordered list of edges, and that is required for many algorithms. The advantage of this class is that it allows to work with incorrect wires.
dba69de2 1540
72b7576f 1541The object of the class *ShapeExtend_WireData* can be initialized by *TopoDS_Wire* and converted back to *TopoDS_Wire*.
dba69de2 1542
72b7576f 1543An edge in the wire is defined by its rank number. Operations of accessing, adding and removing an edge at/to the given rank number are provided. Operations of circular permutation and reversing (both orientations of all edges and the order of edges) are provided on the whole wire as well.
dba69de2 1544
72b7576f 1545This class also provides a method to check if the edge in the wire is a seam (if the wire lies on a face).
dba69de2 1546
72b7576f 1547Let us remove edges from the wire and define whether it is seam edge
1548
1549~~~~~
1550TopoDS_Wire ini = ..
1551Handle(ShapeExtend_Wire) asewd = new ShapeExtend_Wire(initwire);
1552//Removing edge Edge1 from the wire.
1553
1554Standard_Integer index_edge1 = asewd->Index(Edge1);
1555asewd.Remove(index_edge1);
1556//Definition of whether Edge2 is a seam edge
1557Standard_Integer index_edge2 = asewd->Index(Edge2);
1558asewd->IsSeam(index_edge2);
1559~~~~~
1560
1561
1562@subsection occt_shg_5_4 Tool for exploring shapes
1563Class *ShapeExtend_Explorer* is intended to explore shapes and convert different representations (list, sequence, compound) of complex shapes. It provides tools for:
1564 * obtaining the type of the shapes in the context of *TopoDS_Compound*,
1565 * exploring shapes in the context of *TopoDS_Compound*,
1566 * converting different representations of shapes (list, sequence, compound).
1567
1568@subsection occt_shg_5_5 Tool for attaching messages to objects
1569Class *ShapeExtend_MsgRegistrator* attaches messages to objects (generic Transient or shape). The objects of this class are transmitted to the Shape Healing algorithms so that they could collect messages occurred during shape processing. Messages are added to the Maps (stored as a field) that can be used, for instance, by Data Exchange processors to attach those messages to initial file entities.
1570
1571Let us send and get a message attached to object:
1572
1573~~~~~
1574Handle(ShapeExtend_MsgRegistrator) MessageReg = new ShapeExtend_MsgRegistrator;
1575//attaches messages to an object (shape or entity)
1576Message_Msg msg..
1577TopoDS_Shape Shape1…
4ee1bdf4 1578MessageReg->Send(Shape1,msg,Message_WARNING);
72b7576f 1579Handle(Standard_Transient) ent ..
4ee1bdf4 1580MessageReg->Send(ent,msg,Message_WARNING);
72b7576f 1581//gets messages attached to shape
4ee1bdf4 1582const ShapeExtend_DataMapOfShapeListOfMsg& msgmap = MessageReg->MapShape();
72b7576f 1583if (msgmap.IsBound (Shape1)) {
e5bd0d98 1584 const Message_ListOfMsg &msglist = msgmap.Find (Shape1);
72b7576f 1585 for (Message_ListIteratorOfListOfMsg iter (msglist);
1586iter.More(); iter.Next()) {
dba69de2 1587 Message_Msg msg = iter.Value();
1588 }
1589 }
72b7576f 1590~~~~~
1591
1592@subsection occt_shg_5_6 Tools for performance measurement
1593
1594Classes *MoniTool_Timer* and *MoniTool_TimerSentry* are used for measuring the performance of a current operation or any part of code, and provide the necessary API. Timers are used for debugging and performance optimizing purposes.
1595
1596Let us try to use timers in *XSDRAWIGES.cxx* and *IGESBRep_Reader.cxx* to analyse the performance of command *igesbrep*:
1597
1598~~~~~
1599XSDRAWIGES.cxx
1600 ...
1601 #include <MoniTool_Timer.hxx>
1602 #include <MoniTool_TimerSentry.hxx>
1603 ...
1604 MoniTool_Timer::ClearTimers();
1605 ...
1606 MoniTool_TimerSentry MTS("IGES_LoadFile");
1607 Standard_Integer status = Reader.LoadFile(fnom.ToCString());
1608 MTS.Stop();
1609 ...
1610 MoniTool_Timer::DumpTimers(cout);
1611 return;
1612
1613
1614IGESBRep_Reader.cxx
1615 ...
1616 #include <MoniTool_TimerSentry.hxx>
1617 ...
1618 Standard_Integer nb = theModel->NbEntities();
1619 ...
1620 for (Standard_Integer i=1; i<=nb; i++) {
1621 MoniTool_TimerSentry MTS("IGESToBRep_Transfer");
1622 ...
1623 try {
1624 TP.Transfer(ent);
1625 shape = TransferBRep::ShapeResult (theProc,ent);
1626 }
1627 ...
1628 }
1629~~~~~
1630
4ee1bdf4 1631The result of *DumpTimer()* after file translation is as follows:
1632
1633| TIMER | Elapsed | CPU User | CPU Sys | Hits |
1634| :--- | :---- | :----- | :---- | :---- |
1635| *IGES_LoadFile* | 1.0 sec | 0.9 sec | 0.0 sec | 1 |
1636| *IGESToBRep_Transfer* | 14.5 sec | 4.4 sec | 0.1 sec | 1311 |
72b7576f 1637
1638
1639@section occt_shg_6 Shape Processing
1640
1641@subsection occt_shg_6_1 Usage Workflow
1642
1643The Shape Processing module allows defining and applying the general Shape Processing as a customizable sequence of Shape Healing operators. The customization is implemented via the user-editable resource file, which defines the sequence of operators to be executed and their parameters.
dba69de2 1644
72b7576f 1645The Shape Processing functionality is implemented with the help of the *XSAlgo* interface. The main function *XSAlgo_AlgoContainer::ProcessShape()* does shape processing with specified tolerances and returns the resulting shape and associated information in the form of *Transient*.
1646
1647This function is used in the following way:
1648
1649~~~~~
1650TopoDS_Shape aShape = …;
1651Standard_Real Prec = …,
1652Standard_Real MaxTol = …;
1653TopoDS_Shape aResult;
1654Handle(Standard_Transient) info;
4ee1bdf4 1655TopoDS_Shape aResult = XSAlgo::AlgoContainer()->ProcessShape(aShape, Prec, MaxTol., "Name of ResourceFile", "NameSequence", info );
72b7576f 1656~~~~~
1657
1658Let us create a custom sequence of operations:
1659
dba69de2 16601. Create a resource file with the name *ResourceFile*, which includes the following string:
72b7576f 1661~~~~~
dba69de2 1662NameSequence.exec.op: MyOper
72b7576f 1663~~~~~
1664where *MyOper* is the name of operation.
72b7576f 16652. Input a custom parameter for this operation in the resource file, for example:
1666~~~~~
1667NameSequence.MyOper.Tolerance: 0.01
1668~~~~~
dba69de2 1669where *Tolerance* is the name of the parameter and 0.01 is its value.
72b7576f 16703. Add the following string into *void ShapeProcess_OperLibrary::Init()*:
72b7576f 1671~~~~~
1672ShapeProcess::RegisterOperator(;MyOper;,
1673new ShapeProcess_UOperator(myfunction));
1674~~~~~
1675where *myfunction* is a function which implements the operation.
72b7576f 16764. Create this function in *ShapeProcess_OperLibrary* as follows:
1677~~~~~
1678static Standard_Boolean myfunction (const
e5bd0d98 1679 Handle(ShapeProcess_Context)& context)
72b7576f 1680{
4ee1bdf4 1681 Handle(ShapeProcess_ShapeContext) ctx = Handle(ShapeProcess_ShapeContext)::DownCast(context);
dba69de2 1682 if(ctx.IsNull()) return Standard_False;
1683 TopoDS_Shape aShape = ctx->Result();
1684 //receive our parameter:
1685 Standard_Real toler;
1686 ctx->GetReal(;Tolerance;, toler);
72b7576f 1687~~~~~
dba69de2 16885. Make the necessary operations with *aShape* using the received value of parameter *Tolerance* from the resource file.
72b7576f 1689~~~~~
dba69de2 1690 return Standard_True;
72b7576f 1691}
1692~~~~~
dba69de2 16936. Define some operations (with their parameters) *MyOper1, MyOper2, MyOper3*, etc. and describe the corresponding functions in *ShapeProcess_OperLibrary*.
16947. Perform the required sequence using the specified name of operations and values of parameters in the resource file.
72b7576f 1695
1696For example: input of the following string:
1697~~~~~
dba69de2 1698NameSequence.exec.op: MyOper1,MyOper3
72b7576f 1699~~~~~
4ee1bdf4 1700means that the corresponding functions from *ShapeProcess_OperLibrary* will be performed with the original shape *aShape* using parameters defined for *MyOper1* and *MyOper3* in the resource file.
dba69de2 1701
72b7576f 1702It is necessary to note that these operations will be performed step by step and the result obtained after performing the first operation will be used as the initial shape for the second operation.
1703
1704@subsection occt_shg_6_2 Operators
dba69de2 1705
1706### DirectFaces
1707This operator sets all faces based on indirect surfaces, defined with left-handed coordinate systems as direct faces. This concerns surfaces defined by Axis Placement (Cylinders, etc). Such Axis Placement may be indirect, which is allowed in Cascade, but not allowed in some other systems. This operator reverses indirect placements and recomputes PCurves accordingly.
1708
1709### SameParameter
1710This operator is required after calling some other operators, according to the computations they do. Its call is explicit, so each call can be removed according to the operators, which are either called or not afterwards. This mainly concerns splitting operators that can split edges.
1711
1712The operator applies the computation *SameParameter* which ensures that various representations of each edge (its 3d curve, the pcurve on each of the faces on which it lies) give the same 3D point for the same parameter, within a given tolerance.
1713* For each edge coded as *same parameter*, deviation of curve representation is computed and if the edge tolerance is less than that deviation, the tolerance is increased so that it satisfies the deviation. No geometry modification, only an increase of tolerance is possible.
1714* For each edge coded as *not same parameter* the deviation is computed as in the first case. Then an attempt is made to achieve the edge equality to *same parameter* by means of modification of 2d curves. If the deviation of this modified edge is less than the original deviation then this edge is returned, otherwise the original edge (with non-modified 2d curves) is returned with an increased (if necessary) tolerance. Computation is done by call to the standard algorithm *BRepLib::SameParameter*.
1715
72b7576f 1716This operator can be called with the following parameters:
3f812249 1717 * *Boolean : Force* (optional) -- if True, encodes all edges as *not same parameter* then runs the computation. Else, the computation is done only for those edges already coded as *not same parameter*.
1718 * *Real : Tolerance3d* (optional) -- if not defined, the local tolerance of each edge is taken for its own computation. Else, this parameter gives the global tolerance for the whole shape.
dba69de2 1719
1720### BSplineRestriction
1721
1722This operator is used for conversion of surfaces, curves 2d curves to BSpline surfaces with a specified degree and a specified number of spans. It performs approximations on surfaces, curves and 2d curves with a specified degree, maximum number of segments, 2d tolerance, 3d tolerance. The specified continuity can be reduced if the approximation with a specified continuity was not done successfully.
1723
72b7576f 1724This operator can be called with the following parameters:
1725* *Boolean : SurfaceMode* allows considering the surfaces;
1726* *Boolean : Curve3dMode* allows considering the 3d curves;
1727* *Boolean : Curve2dMode* allows considering the 2d curves;
1728* *Real : Tolerance3d* defines 3d tolerance to be used in computation;
1729* *Real : Tolerance2d* defines 2d tolerance to be used when computing 2d curves;
1730* *GeomAbs_Shape (C0 G1 C1 G2 C2 CN) : Continuity3d* is the continuity required in 2d;
1731* *GeomAbs_Shape (C0 G1 C1 G2 C2 CN) : Continuity2d* is the continuity required in 3d;
1732* *Integer : RequiredDegree* gives the required degree;
1733* *Integer : RequiredNbSegments* gives the required number of segments;
1734* *Boolean : PreferDegree* if true, *RequiredDegree* has a priority, else *RequiredNbSegments* has a priority;
1735* *Boolean : RationalToPolynomial* serves for conversion of BSplines to polynomial form;
1736* *Integer : MaxDegree* gives the maximum allowed Degree, if *RequiredDegree* cannot be reached;
dba69de2 1737* *Integer : MaxNbSegments* gives the maximum allowed NbSegments, if *RequiredNbSegments* cannot be reached.
72b7576f 1738
dba69de2 1739The following flags allow managing the conversion of special types of curves or surfaces, in addition to BSpline. They are controlled by *SurfaceMode, Curve3dMode* or *Curve2dMode* respectively; by default, only BSplines and Bezier Geometries are considered:
1740* *Boolean : OffsetSurfaceMode*
1741* *Boolean : LinearExtrusionMode*
1742* *Boolean : RevolutionMode*
1743* *Boolean : OffsetCurve3dMode*
1744* *Boolean : OffsetCurve2dMode*
1745* *Boolean : PlaneMode*
1746* *Boolean : BezierMode*
1747* *Boolean : ConvCurve3dMode*
1748* *Boolean : ConvCurve2dMode*
1749
1750For each of the Mode parameters listed above, if it is True, the specified geometry is converted to BSpline, otherwise only its basic geometry is checked and converted (if necessary) keeping the original type of geometry (revolution, offset, etc).
1751
1752* *Boolean :SegmentSurfaceMode* has effect only for Bsplines and Bezier surfaces. When False a surface will be replaced by a Trimmed Surface, else new geometry will be created by splitting the original Bspline or Bezier surface.
1753
1754### ElementaryToRevolution
1755
1756This operator converts elementary periodic surfaces to SurfaceOfRevolution.
1757
1758### SplitAngle
1759
1760This operator splits surfaces of revolution, cylindrical, toroidal, conical, spherical surfaces in the given shape so that each resulting segment covers not more than the defined number of degrees.
1761
1762It can be called with the following parameters:
3f812249 1763* *Real : Angle* -- the maximum allowed angle for resulting faces;
1764* *Real : MaxTolerance* -- the maximum tolerance used in computations.
72b7576f 1765
dba69de2 1766### SurfaceToBSpline
1767This operator converts some specific types of Surfaces, to BSpline (according to parameters).
1768It can be called with the following parameters:
72b7576f 1769* *Boolean : LinearExtrusionMode* allows converting surfaces of Linear Extrusion;
1770* *Boolean : RevolutionMode* allows converting surfaces of Revolution;
1771* *Boolean : OffsetMode* allows converting Offset Surfaces
1772
dba69de2 1773### ToBezier
1774
1775This operator is used for data supported as Bezier only and converts various types of geometries to Bezier. It can be called with the following parameters used in computation of conversion :
72b7576f 1776* *Boolean : SurfaceMode*
1777* *Boolean : Curve3dMode*
1778* *Boolean : Curve2dMode*
1779* *Real : MaxTolerance*
dba69de2 1780* *Boolean : SegmentSurfaceMode* (default is True) has effect only for Bsplines and Bezier surfaces. When False a surface will be replaced by a Trimmed Surface, else new geometry will be created by splitting the original Bspline or Bezier surface.
72b7576f 1781
1782The following parameters are controlled by *SurfaceMode, Curve3dMode* or *Curve2dMode* (according to the case):
1783* *Boolean : Line3dMode*
1784* *Boolean : Circle3dMode*
1785* *Boolean : Conic3dMode*
1786* *Boolean : PlaneMode*
1787* *Boolean : RevolutionMode*
1788* *Boolean : ExtrusionMode*
1789* *Boolean : BSplineMode*
1790
dba69de2 1791### SplitContinuity
1792This operator splits a shape in order to have each geometry (surface, curve 3d, curve 2d) correspond the given criterion of continuity. It can be called with the following parameters:
72b7576f 1793* *Real : Tolerance3d*
1794* *Integer (GeomAbs_Shape ) : CurveContinuity*
1795* *Integer (GeomAbs_Shape ) : SurfaceContinuity*
1796* *Real : MaxTolerance*
1797
72b7576f 1798Because of algorithmic limitations in the operator *BSplineRestriction* (in some particular cases, this operator can produce unexpected C0 geometry), if *SplitContinuity* is called, it is recommended to call it after *BSplineRestriction*.
1799Continuity Values will be set as *GeomAbs_Shape* (i.e. C0 G1 C1 G2 C2 CN) besides direct integer values (resp. 0 1 2 3 4 5).
1800
dba69de2 1801### SplitClosedFaces
1802This operator splits faces, which are closed even if they are not revolutionary or cylindrical, conical, spherical, toroidal. This corresponds to BSpline or Bezier surfaces which can be closed (whether periodic or not), hence they have a seam edge. As a result, no more seam edges remain. The number of points allows to control the minimum count of faces to be produced per input closed face.
1803
72b7576f 1804This operator can be called with the following parameters:
1805* *Integer : NbSplitPoints* gives the number of points to use for splitting (the number of intervals produced is *NbSplitPoints+1*);
1806* *Real : CloseTolerance* tolerance used to determine if a face is closed;
1807* *Real : MaxTolerance* is used in the computation of splitting.
1808
dba69de2 1809### FixGaps
1810
1811This operator must be called when *FixFaceSize* and/or *DropSmallEdges* are called. Using Surface Healing may require an additional call to *BSplineRestriction* to ensure that modified geometries meet the requirements for BSpline.
72b7576f 1812This operators repairs geometries which contain gaps between edges in wires (always performed) or gaps on faces, controlled by parameter *SurfaceMode*, Gaps on Faces are fixed by using algorithms of Surface Healing
1813This operator can be called with the following parameters:
1814* *Real : Tolerance3d* sets the tolerance to reach in 3d. If a gap is less than this value, it is not fixed.
1815* *Boolean : SurfaceMode* sets the mode of fixing gaps between edges and faces (yes/no) ;
1816* *Integer : SurfaceAddSpans* sets the number of spans to add to the surface in order to fix gaps ;
1817* *GeomAbs_Shape (C0 G1 C1 G2 C2 CN) : SurfaceContinuity* sets the minimal continuity of a resulting surface ;
1818* *Integer : NbIterations* sets the number of iterations
1819* *Real : Beta* sets the elasticity coefficient for modifying a surface [1-1000] ;
1820* *Reals : Coeff1 to Coeff6* sets energy coefficients for modifying a surface [0-10000] ;
1821* *Real : MaxDeflection* sets maximal deflection of surface from an old position.
1822
1823This operator may change the original geometry. In addition, it is CPU consuming, and it may fail in some cases. Also **FixGaps** can help only when there are gaps obtained as a result of removal of small edges that can be removed by **DropSmallEdges** or **FixFaceSize**.
1824
dba69de2 1825### FixFaceSize
1826This operator removes faces, which are small in all directions (spot face) or small in one direction (strip face). It can be called with the parameter *Real : Tolerance*, which sets the minimal dimension, which is used to consider a face, is small enough to be removed.
1827
1828### DropSmallEdges
1829This operator drops edges in a wire, and merges them with adjacent edges, when they are smaller than the given value (*Tolerance3d*) and when the topology allows such merging (i.e. same adjacent faces for each of the merged edges). Free (non-shared by adjacent faces) small edges can be also removed in case if they share the same vertex Parameters.
1830
1831It can be called with the parameter *Real : Tolerance3d*, which sets the dimension used to determine if an edge is small.
72b7576f 1832
dba69de2 1833### FixShape
1834
1835This operator may be added for fixing invalid shapes. It performs various checks and fixes, according to the modes listed hereafter. Management of a set of fixes can be performed by flags as follows:
1836* if the flag for a fixing tool is set to 0 , it is not performed;
1837* if set to 1 , it is performed in any case;
1838* if not set, or set to -1 , for each shape to be applied on, a check is done to evaluate whether a fix is needed. The fix is performed if the check is positive.
1839
1840By default, the flags are not set, the checks are carried out each individual shape.
72b7576f 1841
72b7576f 1842This operator can be called with the following parameters:
1843* *Real : Tolerance3d* sets basic tolerance used for fixing;
1844* *Real : MaxTolerance3d* sets maximum allowed value for the resulting tolerance;
1845* *Real : MinTolerance3d* sets minimum allowed value for the resulting tolerance.
1846* *Boolean : FixFreeShellMode*
1847* *Boolean : FixFreeFaceMode*
1848* *Boolean : FixFreeWireMode*
1849* *Boolean : FixSameParameterMode*
1850* *Boolean : FixSolidMode*
1851* *Boolean : FixShellMode*
1852* *Boolean : FixFaceMode*
1853* *Boolean : FixWireMode*
1854* *Boolean : FixOrientationMode*
1855* *Boolean : FixMissingSeamMode*
1856* *Boolean : FixSmallAreaWireMode*
1857* *Boolean (not checked) : ModifyTopologyMode* specifies the mode for modifying topology. Should be False (default) for shapes with shells and can be True for free faces.
1858* *Boolean (not checked) : ModifyGeometryMode* specifies the mode for modifying geometry. Should be False if geometry is to be kept and True if it can be modified.
1859* *Boolean (not checked) : ClosedWireMode* specifies the mode for wires. Should be True for wires on faces and False for free wires.
1860* *Boolean (not checked) : PreferencePCurveMode (not used)* specifies the preference of 3d or 2d representations for an edge
1861* *Boolean : FixReorderMode*
1862* *Boolean : FixSmallMode*
1863* *Boolean : FixConnectedMode*
1864* *Boolean : FixEdgeCurvesMode*
1865* *Boolean : FixDegeneratedMode*
1866* *Boolean : FixLackingMode*
1867* *Boolean : FixSelfIntersectionMode*
1868* *Boolean : FixGaps3dMode*
1869* *Boolean : FixGaps2dMode*
1870* *Boolean : FixReversed2dMode*
1871* *Boolean : FixRemovePCurveMode*
1872* *Boolean : FixRemoveCurve3dMode*
1873* *Boolean : FixAddPCurveMode*
1874* *Boolean : FixAddCurve3dMode*
1875* *Boolean : FixSeamMode*
1876* *Boolean : FixShiftedMode*
1877* *Boolean : FixEdgeSameParameterMode*
1878* *Boolean : FixSelfIntersectingEdgeMode*
1879* *Boolean : FixIntersectingEdgesMode*
1880* *Boolean : FixNonAdjacentIntersectingEdgesMode*
1881
dba69de2 1882### SplitClosedEdges
1883This operator handles closed edges i.e. edges with one vertex. Such edges are not supported in some receiving systems. This operator splits topologically closed edges (i.e. edges having one vertex) into two edges. Degenerated edges and edges with a size of less than Tolerance are not processed.
72b7576f 1884
e5bd0d98 1885@section occt_shg_7 Messaging mechanism
72b7576f 1886
1887Various messages about modification, warnings and fails can be generated in the process of shape fixing or upgrade. The messaging mechanism allows generating messages, which will be sent to the chosen target medium a file or the screen. The messages may report failures and/or warnings or provide information on events such as analysis, fixing or upgrade of shapes.
1888
dba69de2 1889@subsection occt_shg_7_1 Message Gravity
72b7576f 1890Enumeration *Message_Gravity* is used for defining message gravity.
1891It provides the following message statuses:
3f812249 1892* *Message_FAIL* -- the message reports a fail;
1893* *Message_WARNING* -- the message reports a warning;
1894* *Message_INFO* -- the message supplies information.
72b7576f 1895
dba69de2 1896@subsection occt_shg_7_2 Tool for loading a message file into memory
72b7576f 1897Class *Message_MsgFile* allows defining messages by loading a custom message file into memory. It is necessary to create a custom message file before loading it into memory, as its path will be used as the argument to load it. Each message in the message file is identified by a key. The user can get the text content of the message by specifying the message key.
1898
dba69de2 1899### Format of the message file
1900
72b7576f 1901The message file is an ASCII file, which defines a set of messages. Each line of the file must have a length of less than 255 characters.
1902All lines in the file starting with the exclamation sign (perhaps preceded by spaces and/or tabs) are considered as comments and are ignored.
1903A message file may contain several messages. Each message is identified by its key (string).
4ee1bdf4 1904Each line in the file starting with the *dot* character (perhaps preceded by spaces and/or tabs) defines the key. The key is a string starting with a symbol placed after the dot and ending with the symbol preceding the ending of the newline character <i>\\n.</i>
1905All lines in the file after the key and before the next keyword (and which are not comments) define the message for that key. If the message consists of several lines, the message string will contain newline symbols <i>\\n</i> between each line (but not at the end).
1906
72b7576f 1907The following example illustrates the structure of a message file:
1908
1909~~~~~
1910!This is a sample message file
1911!------------------------------
1912!Messages for ShapeAnalysis package
1913!
1914.SampleKeyword
1915Your message string goes here
1916!
1917!...
1918!
4ee1bdf4 1919!End of the message file
72b7576f 1920~~~~~
1921
dba69de2 1922### Loading the message file
1923
72b7576f 1924A custom file can be loaded into memory using the method *Message_MsgFile::LoadFile*, taking as an argument the path to your file as in the example below:
1925~~~~~
1926Standard_CString MsgFilePath = ;(path)/sample.file;;
1927Message_MsgFile::LoadFile (MsgFilePath);
1928~~~~~
1929
dba69de2 1930@subsection occt_shg_7_3 Tool for managing filling messages
72b7576f 1931
1932The class *Message_Msg* allows using the message file loaded as a template. This class provides a tool for preparing the message, filling it with parameters, storing and outputting to the default trace file.
1933A message is created from a key: this key identifies the message to be created in the message file. The text of the message is taken from the loaded message file (class *Message_MsgFile* is used).
1934The text of the message can contain places for parameters, which are to be filled by the proper values when the message is prepared. These parameters can be of the following types:
3f812249 1935* string -- coded in the text as \%s,
1936* integer -- coded in the text as \%d,
1937* real -- coded in the text as \%f.
72b7576f 1938The parameter fields are filled by the message text by calling the corresponding methods *AddInteger, AddReal* and *AddString*. Both the original text of the message and the input text with substituted parameters are stored in the object. The prepared and filled message can be output to the default trace file. The text of the message (either original or filled) can be also obtained.
1939~~~~~
1940Message_Msg msg01 (;SampleKeyword;);
1941//Creates the message msg01, identified in the file by the keyword SampleKeyword
1942msg1.AddInteger (73);
1943msg1.AddString (;SampleFile;);
1944//fills out the code areas
1945~~~~~
1946
dba69de2 1947@subsection occt_shg_7_4 Tool for managing trace files
72b7576f 1948
4ee1bdf4 1949Class *Message_TraceFile* is intended to manage the trace file (or stream) for outputting messages and the current trace level. Trace level is an integer number, which is used when messages are sent. Generally, 0 means minimum, \> 0 various levels. If the current trace level is lower than the level of the message it is not output to the trace file. The trace level is to be managed and used by the users.
72b7576f 1950There are two ways of using trace files:
1951* define an object of *Message_TraceFile*, with its own definition (file name or cout, trace level), and use it where it is defined,
1952* use the default trace file (file name or cout, trace level), usable from anywhere.
1953Use the constructor method to define the target file and the level of the messages as in the example below:
1954~~~~~
1955Message_TraceFile myTF
4ee1bdf4 1956 (tracelevel, "tracefile.log", Standard_False);
72b7576f 1957~~~~~
1958The parameters are as follows:
1959* *tracelevel* is a Standard_Integer and modifies the level of messages. It has the following values and semantics:
1960 + 0: gives general information such as the start and end of process;
1961 + 1: gives exceptions raised and fail messages;
1962 + 2: gives the same information as 1 plus warning messages.
1963* *filename* is the string containing the path to the log file.
1964The Boolean set to False will rewrite the existing file. When set to True, new messages will be appended to the existing file.
1965
1966A new default log file can be added using method *SetDefault* with the same arguments as in the constructor.
1967The default trace level can be changed by using method *SetDefLevel*. In this way, the information received in the log file is modified.
1968It is possible to close the log file and set the default trace output to the screen display instead of the log file using the method *SetDefault* without any arguments.
1969
d6b4d3d0 1970