1 Modeling Data {#user_guides__modeling_data}
2 ========================
4 @section occt_modat_1 Introduction
6 Modeling Data supplies data structures to represent 2D and 3D geometric models. This manual explains how to use Modeling Data. For advanced information on modeling data, see our offerings on our web site at <a href="http://www.opencascade.org/support/training/">www.opencascade.org/support/training/</a>
10 @section occt_modat_1 Geometry Utilities
12 Geometry Utilities provide the following services:
13 * Creation of shapes by interpolation and approximation
14 * Direct construction of shapes
15 * Conversion of curves and surfaces to Bspline curves and surfaces
16 * Computation of the coordinates of points on 2D and 3D curves
17 * Calculation of extrema between shapes.
19 @subsection occt_modat_1_1 Interpolations and Approximations
21 In modeling, it is often required to approximate or interpolate points into curves and surfaces. In interpolation, the process is complete when the curve or surface passes through all the points; in approximation, when it is as close to these points as possible. This component provides both high and low level services to approximate or interpolate points into curves and surfaces. The lower level services allow performing parallel approximation of groups of points into groups of Bezier or B-spline curves.
23 @subsubsection occt_modat_1_1_1 Analysis of a set of points
25 The class *PEquation* from *GProp* package allows analyzng a collection or cloud of points and verifying if they are coincident, collinear or coplanar within a given precision. If they are, the algorithm computes the mean point, the mean line or the mean plane of the points. If they are not, the algorithm computes the minimal box, which includes all the points.
27 @subsubsection occt_modat_1_1_2 Basic Interpolation and Approximation
29 Packages *Geom2dAPI* and *GeomAPI* provide simple methods for approximation and interpolation with minimal programming
33 The class *Interpolate* from *Geom2dAPI* package allows building a constrained 2D BSpline curve, defined by a table of points through which the curve passes. If required, the parameter values and vectors of the tangents can be given for each point in the table.
37 The class *Interpolate* from *GeomAPI* package allows building a constrained 3D BSpline curve, defined by a table of points through which the curve passes. If required, the parameter values and vectors of the tangents can be given for each point in the table.
39 ![](/user_guides/modeling_data/images/modeling_data_image003.jpg "Approximation of a BSpline from scattered points")
41 This class may be instantiated as follows:
43 GeomAPI_Interpolate Interp(Points);
46 From this object, the BSpline curve may be requested as follows:
48 Handle(Geom_BSplineCurve) C = Interp.Curve();
53 The class *PointsToBSpline* from *Geom2dAPI* package allows building a 2DBSpline curve, which approximates a set of points. You have to define the lowest and highest degree of the curve, its continuity and a tolerance value for it.The tolerance value is used to check that points are not too close to each other, or tangential vectors not too small. The resulting BSpline curve will beC2 or second degree continuous, except where a tangency constraint is defined on a point through which the curve passes. In this case, it will be only C1continuous.
57 The class *PointsToBSpline* from GeomAPI package allows building a 3D BSplinecurve, which approximates a set of points. It is necessary to define the lowest and highest degree of the curve, its continuity and tolerance. The tolerance value is used to check that points are not too close to each other,or that tangential vectors are not too small.
59 The resulting BSpline curve will be C2 or second degree continuous, except where a tangency constraint is defined on a point, through which the curve passes. In this case, it will be only C1 continuous. This class is instantiated as follows:
62 GeomAPI_PointsToBSpline
63 Approx(Points,DegMin,DegMax,Continuity, Tol);
66 From this object, the BSpline curve may be requested as follows:
68 Handle(Geom_BSplineCurve) K = Approx.Curve();
73 The class **PointsToBSplineSurface** from GeomAPI package allows building a BSpline surface, which approximates or interpolates a set of points.
75 @subsubsection occt_modat_1_1_3 Advanced Approximation
77 Packages *AppDef* and *AppParCurves* provide low-level functions, allowing more control over the approximations.
79 Approximation by multiple point constraints
80 -------------------------------------------
81 *AppDef* package provides low-level tools to allow parallel approximation of groups of points into Bezier or B-Spline curves using multiple point constraints.
83 The following low level services are provided:
84 * Definition of an array of point constraints:
85 The class *MultiLine* allows defining a given number of multipoint constraints in order to build the multi-line, multiple lines passing through ordered multiple point constraints.
87 ![](/user_guides/modeling_data/images/modeling_data_image004.jpg "Definition of a MultiLine using Multiple Point Constraints")
90 * *Pi*, *Qi*, *Ri* ... *Si* can be 2D or 3Dpoints.
91 * Defined as a group: *Pn*, *Qn*, *Rn,* ... *Sn* form a MultipointConstraint. They possess the same passage, tangency and curvature constraints.
92 * *P1*, *P2*, ... *Pn*, or the *Q*, *R*, ... or *S* series represent the lines to be approximated.
94 * Definition of a set of point constraints:
95 The class **MultiPointConstraint** allows defining a multiple point constraint and computing the approximation of sets of points to several curves.
97 * Computation of an approximation of a Bezier curve from a set of points:
98 The class *Compute* allows making an approximation of a set of points to a Bezier curve
100 * Computation of an approximation of a BSpline curve from a set of points:
101 The class **BSplineCompute** allows making an approximation of a set of points to a BSpline curve.
103 * Definition of Variational Criteria:
104 The class *TheVariational* allows fairing the approximation curve to a given number of points using a least squares method in conjunction with a variational criterion, usually the weights at each constraint point.
106 Approximation by parametric or geometric constraints
107 ----------------------------------------------------
109 *AppParCurves* package provides low-level tools to allow parallel approximation of groups of points into Bezier or B-Spline curve with parametric or geometric constraints, such as a requirement for the curve to pass through given points, or to have a given tangency or curvature at a particular point.
111 The algorithms used include:
112 - the least squares method
113 - a search for the best approximation within a given tolerance value.
115 The following low-level services are provided:
117 * Association of an index to an object:
118 The class *ConstraintCouple* allows you associating an index to an object to compute faired curves using *AppDef_TheVariational*.
120 * Definition of a set of approximations of Bezier curves:
121 The class *MultiCurve* allows defining the approximation of a multi-line made up of multiple Bezier curves.
123 * Definition of a set of approximations of BSpline curves:
124 The class *MultiBSpCurve* allows defining the approximation of a multi-line made up of multiple BSpline curves.
126 * Definition of points making up a set of point constraints
127 The class *MultiPoint* allows defining groups of 2D or 3D points making up a multi-line.
129 @subsection occt_modat_1_2 Direct Construction
131 Direct Construction methods from *gce*, *GC* and *GCE2d* packages provide simplified algorithms to build elementary geometric entities such as lines, circles and curves. They complement the reference definitions provided by the *gp*, *Geom* and *Geom2d *packages.
133 For example, to construct a circle from a point and a radius using the *gp* package, it is necessary to construct axis *Ax2d* before creating the circle. If *gce* package is used, and *Ox* is taken for the axis, it is possible to create a circle directly from a point and a radius.
135 @subsubsection occt_modat_1_2_1 Non-persistent entities
137 The following algorithms used to build entities from non-persistent *gp* entities are provided by *gce* package.
138 - 2D line parallel to another at a distance,
139 - 2D line parallel to another passing through a point,
140 - 2D circle passing through two points,
141 - 2D circle parallel to another at a distance,
142 - 2D circle parallel to another passing through a point,
143 - 2D circle passing through three points,
144 - 2D circle from a center and a radius,
145 - 2D hyperbola from five points,
146 - 2D hyperbola from a center and two apexes,
147 - 2D ellipse from five points,
148 - 2D ellipse from a center and two apexes,
149 - 2D parabola from three points,
150 - 2D parabola from a center and an apex,
151 - line parallel to another passing through a point,
152 - line passing through two points,
153 - circle coaxial to another passing through a point,
154 - circle coaxial to another at a given distance,
155 - circle passing through three points,
156 - circle with its center, radius, and normal to the plane,
157 - circle with its axis (center + normal),
158 - hyperbola with its center and two apexes,
159 - ellipse with its center and two apexes,
160 - plane passing through three points,
161 - plane from its normal,
162 - plane parallel to another plane at a given distance,
163 - plane parallel to another passing through a point,
164 - plane from an array of points,
165 - cylinder from a given axis and a given radius,
166 - cylinder from a circular base,
167 - cylinder from three points,
168 - cylinder parallel to another cylinder at a given distance,
169 - cylinder parallel to another cylinder passing through a point,
170 - cone from four points,
171 - cone from a given axis and two passing points,
172 - cone from two points (an axis) and two radii,
173 - cone parallel to another at a given distance,
174 - cone parallel to another passing through a point,
175 - all transformations (rotations, translations, mirrors,scaling transformations, etc.).
177 Each class from *gp* package, such as *Circ, Circ2d, Mirror, Mirror2d*, etc., has the corresponding *MakeCirc, MakeCirc2d, MakeMirror, MakeMirror2d*, etc. class from *gce* package.
179 It is possible to create a point using a *gce* package class, then question it to recover the corresponding *gp* object.
182 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
183 gp_Pnt2d Point1,Point2;
185 //Initialization of Point1 and Point2
186 gce_MakeLin2d L = gce_MakeLin2d(Point1,Point2);
187 if (L.Status() == gce_Done() ){
188 gp_Lin2d l = L.Value();
190 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
191 This is useful if you are uncertain as to whether the arguments can create the *gp* object without raising an exception. In the case above, if *Point1* and *Point2* are closer than the tolerance value required by *MakeLin2d*, the function *Status* will return the enumeration *gce_ConfusedPoint*. This tells you why the *gp* object cannot be created. If you know that the points *Point1* and *Point2*are separated by the value exceeding the tolerance value, then you may create the *gp* object directly, as follows:
195 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
196 gp_Lin2d l = gce_MakeLin2d(Point1,Point2);
197 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
199 @subsubsection occt_modat_1_2_2 Persistent entities
201 *GC* and *GCE2d* packages provides an implementation of algorithms used to build entities from *Geom* and *Geom2D* packages. They implement the same algorithms as the *gce* package but create **persistent** entities, and also contain algorithms for trimmed surfaces and curves. The following algorithms are available:
202 - arc of a circle trimmed by two points,
203 - arc of a circle trimmed by two parameters,
204 - arc of a circle trimmed by one point and one parameter,
205 - arc of an ellipse from an ellipse trimmed by two points,
206 - arc of an ellipse from an ellipse trimmed by two parameters,
207 - arc of an ellipse from an ellipse trimmed by one point and one parameter,
208 - arc of a parabola from a parabola trimmed by two points,
209 - arc of a parabola from a parabola trimmed by two parameters,
210 - arc of a parabola from a parabola trimmed by one point and one parameter,
211 - arc of a hyperbola from a hyperbola trimmed by two points,
212 - arc of a hyperbola from a hyperbola trimmed by two parameters,
213 - arc of a hyperbola from a hyperbola trimmed by one point and one parameter,
214 - segment of a line from two points,
215 - segment of a line from two parameters,
216 - segment of a line from one point and one parameter,
217 - trimmed cylinder from a circular base and a height,
218 - trimmed cylinder from three points,
219 - trimmed cylinder from an axis, a radius, and a height,
220 - trimmed cone from four points,
221 - trimmed cone from two points (an axis) and a radius,
222 - trimmed cone from two coaxial circles.
224 Each class from *GCE2d* package, such as *Circle, Ellipse, Mirror*, etc., has the corresponding *MakeCircle, MakeEllipse, MakeMirror*, etc. class from *Geom2d* package.
225 Besides, the class *MakeArcOfCircle* returns an object of type *TrimmedCurve* from *Geom2d*.
227 Each class from *GC* package, such as *Circle, Ellipse, Mirror*, etc., has the corresponding *MakeCircle, MakeEllipse, MakeMirror*, etc. class from *Geom* package.
228 The following classes return objects of type *TrimmedCurve* from *Geom*:
231 - *MakeArcOfHyperbola*
232 - *MakeArcOfParabola*
235 @subsection occt_modat_1_3 Conversion to and from BSplines
237 The following algorithms to convert geometric curves or surfaces into their BSpline or Bezier equivalents are provided by *GeomConvert*, *Geom2dConvert* and *Convert* packages:
238 - Conversion of a conic into a rational BSpline.
239 - Conversion of an elementary surface into a rational Bspline.
240 - Conversion of a BSpline or Bezier curve into two or more Bezier curves or surfaces.
241 - Conversion of a BSpline curve or surface into two or more BSplinecurves or surfaces with constraints on continuity.
242 - Conversion of a set of joining Bezier curves into a BSplinecurve.
243 - Conversion of a polynomial representation into a BSpline curve.
245 @subsection occt_modat_1_4 Points on Curves
247 The following characteristic points exist on parameterized curves in 3d space:
248 - points equally spaced on a curve,
249 - points distributed along a curve with equal chords,
250 - a point at a given distance from another point on a curve.
252 *GCPnts* package provides algorithms to calculate such points:
253 - *AbscissaPoint* calculates a point on a curve at a given distance from another point on the curve.
254 - *UniformAbscissa* calculates a set of points at a given abscissa on a curve.
255 - *UniformDeflection* calculates a set of points at maximum constant deflection between the curve and the polygon that results from the computed points.
257 Example: Visualizing a curve.
258 -----------------------------
260 Let us take an adapted curve **C**, i.e. an object which is an interface between the services provided by either a 2D curve from the package Geom2d (in case of an Adaptor_Curve2d curve) or a 3D curve from the package Geom (in case of an Adaptor_Curve curve), and the services required on the curve by the computation algorithm. The adapted curve is created in the following way:
263 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
264 Handle(Geom2d_Curve) mycurve = ... ;
265 Geom2dAdaptor_Curve C (mycurve) ;
266 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
269 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
270 Handle(Geom_Curve) mycurve = ... ;
271 GeomAdaptor_Curve C (mycurve) ;
272 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
274 The algorithm is then constructed with this object:
276 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
277 GCPnts_UniformDeflection myAlgo () ;
278 Standard_Real Deflection = ... ;
279 myAlgo.Initialize ( C , Deflection ) ;
280 if ( myAlgo.IsDone() )
282 Standard_Integer nbr = myAlgo.NbPoints() ;
283 Standard_Real param ;
284 for ( Standard_Integer i = 1 ; i = nbr ; i++ )
286 param = myAlgo.Parameter (i) ;
290 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
293 @subsection occt_modat_1_5 Extrema
295 The classes to calculate the minimum distance between points, curves, and surfaces in 2d and 3d are provided by *GeomAPI* and *Geom2dAPI* packages.
297 These packages calculate the extrema of distance between:
299 - point and a surface,
301 - a curve and a surface,
304 @subsubsection occt_modat_1_5_1 Extrema between Curves
306 The *Geom2dAPI_ExtremaCurveCurve* class allows calculation of all extrema between two 2D geometric curves. Extrema are the lengths of the segments orthogonal to two curves.
308 The *GeomAPI_ExtremaCurveCurve* class allows calculation of all extrema between two 3D geometric curves. Extrema are the lengths of the segments orthogonal to two curves.
310 @subsubsection occt_modat_1_5_2 Extrema between Curve and Surface
312 The *GeomAPI_ExtremaCurveSurface* class allows calculation of all extrema between a 3D curve and a surface. Extrema are the lengths of the segments orthogonal to the curve and the surface.
314 @subsubsection occt_modat_1_5_3 Extrema between Surfaces
316 The *GeomAPI_ExtremaSurfaceSurface* class allows calculation of all extrema between two surfaces. Extrema are the lengths of the segments orthogonal to two surfaces.
318 @section occt_modat_2 2D Geometry
320 *Geom2d* package defines geometric objects in 2dspace. All geometric entities are STEP processed. The objects are non-persistent and are handled by reference. The following objects are available:
325 - vector with magnitude,
329 - conic: circle, ellipse, hyperbola, pparabola,
330 - rounded curve: trimmed curve, NURBS curve, Bezier curve.
333 Before creating a geometric object, it is necessary to decide how the object is handled.
334 The objects provided by *Geom2d* package are handled by reference rather than by value. Copying an instance copies the handle, not the object, so that a change to one instance is reflected in each occurrence of it.
335 If a set of object instances is needed rather than a single object instance, *TColGeom2d* package can be used. This package provides standard and frequently used instantiations of one-dimensional arrays and sequences for curves from *Geom2d* package. All objects are available in two versions:
336 - handled by reference and
339 @section occt_modat_3 3D Geometry
341 The *Geom* package defines geometric objects in 3d space and contains all basic geometric transformations, such as identity, rotation, translation, mirroring, scale transformations, combinations of transformations, etc. as well as special functions depending on the reference definition of the geometric object (e.g. addition of a control point on a B-Spline curve,modification of a curve, etc.). All geometrical entities are STEP processed. The following non-persistent and reference-handled objects are available:
346 - Vector with magnitude
350 - Conic: circle, ellipse, hyperbola, parabola
352 - Elementary surface: plane, cylinder, cone, sphere, torus
353 - Bounded curve: trimmed curve, NURBS curve, Bezier curve
354 - Bounded surface: rectangular trimmed surface, NURBS surface,Bezier surface
355 - Swept surface: surface of linear extrusion, surface of revolution
358 If a set of object instances is needed rather than a single object instance, *TColGeom* package can be used. This package provides instantiations of one- and two-dimensional arrays and sequences for curves from *Geom* package. All objects are available in two versions:
359 - handled by reference and
362 @subsection occt_modat_4 Local Properties of Curves and Surfaces
364 Packages **GeomLProp**, **Geom2dLProp** provide algorithms calculating the local properties of curves and surfaces
366 A curve (for one parameter) has the following local properties:
372 - Center of curvature.
374 A surface (for two parameters U and V) has the following local properties:
376 - derivative for U and V)
377 - tangent line (for U and V)
381 - main directions of curvature
385 The following methods are available:
386 * *CLProps* - calculates the local properties of a curve (tangency, curvature,normal);
387 * *CurAndInf2d* - calculates the maximum and minimum curvatures and the inflection points of 2d curves;
388 * *SLProps* - calculates the local properties of a surface (tangency, the normal and curvature).
389 * *Continuity* - calculates regularity at the junction of two curves.
391 Note that the B-spline curve and surface are accepted but they are not cut into pieces of the desired continuity. It is the global continuity, which is seen.
394 @section occt_modat_5 Topology
396 Open CASCADE Technology Topology allows accessing and manipulating objects data without dealing with their 2D or 3D representations. Whereas OCCT Geometry provides a description of objects in terms of coordinates or parametric values, Topology describes data structures of objects in parametric space. These descriptions use location in and restriction of parts of this space.
398 To provide its descriptions, OCCT abstract topology offers the following services:
399 - Keeping track of Location of shapes
400 - Naming shapes, sub-shapes, their orientations and states
401 - Manipulating shapes and sub-shapes
402 - Exploring topological data structures
403 - Using lists and maps of shapes
406 @subsection occt_modat_5_1 Shape Location
408 A local coordinate system can be viewed as either of the following:
409 - A right-handed trihedron with an origin and three orthonormal vectors. The **gp_Ax2** package corresponds to this definition.
410 - A transformation of a +1 determinant, allowing the transformation of coordinates between local and global references frames. This corresponds to the **gp_Trsf**.
412 *TopLoc* package distinguishes two notions:
413 - *TopLoc_Datum3D* class provides the elementary reference coordinate, represented by a right-handed orthonormal system of axes or by a right-handed unitary transformation.
414 - *TopLoc_Location* class provides the composite reference coordinate made from elementary ones. It is a marker composed of a chain of references to elementary markers. The resulting cumulative transformation is stored in order to avoid recalculating the sum of the transformations for the whole list.
416 ![](/user_guides/modeling_data/images/modeling_data_image005.jpg "Structure of TopLoc_Location")
418 Two reference coordinates are equal if they are made up of the same elementary coordinates in the same order. There is no numerical comparison. Two coordinates can thus correspond to the same transformation without being equal if they were not built from the same elementary coordinates.
420 For example, consider three elementary coordinates:
422 The composite coordinates are:
428 **NOTE** C3 and C4 are equal because they are both R1 * R2 * R3.
430 The TopLoc package is chiefly targeted at the topological data structure, but it can be used for other purposes.
432 Change of coordinates
433 ---------------------
435 *TopLoc_Datum3D* class represents a change of elementary coordinates. Such changes must be shared so this class inherits from *MMgt_TShared*. The coordinate is represented by a transformation *gp_Trsfpackage*. This transformation has no scaling factor.
438 @subsection occt_modat_5_2 Naming shapes, sub-shapes, their orientation and state
440 The **TopAbs** package provides general enumerations describing the basic concepts of topology and methods to handle these enumerations. It contains no classes. This package has been separated from the rest of the topology because the notions it contains are sufficiently general to be used by all topological tools. This avoids redefinition of enumerations by remaining independent of modeling resources. The TopAbs package defines three notions:
441 - Topological type (TopAbs_ShapeEnum)
442 - Orietation (TopAbs_Orientation)
446 @subsubsection occt_modat_5_2_1 Topological types
448 TopAbs contains the *TopAbs_ShapeEnum* enumeration,which lists the different topological types:
449 - COMPOUND - a group of any type of topological objects.
450 - COMPSOLID - a composite solid is a set of solids connected by their faces. It expands the notions of WIRE and SHELL to solids.
451 - SOLID - a part of space limited by shells. It is three dimensional.
452 - SHELL - a set of faces connected by their edges. A shell can be open or closed.
453 - FACE - in 2D it is a part of a plane; in 3D it is a part of a surface. Its geometry is constrained (trimmed) by contours. It is two dimensional.
454 - WIRE - a set of edges connected by their vertices. It can be an open or closed contour depending on whether the edges are linked or not.
455 - EDGE - a topological element corresponding to a restrained curve. An edge is generally limited by vertices. It has one dimension.
456 - VERTEX - a topological element corresponding to a point. It has zero dimension.
457 - SHAPE - a generic term covering all of the above.
459 A topological model can be considered as a graph of objects with adjacency relationships. When modeling a part in 2D or 3D space it must belong to one of the categories listed in the ShapeEnum enumeration. The TopAbspackage lists all the objects, which can be found in any model. It cannot be extended but a subset can be used. For example, the notion of solid is useless in 2D.
461 The terms of the enumeration appear in order from the most complex to the most simple, because objects can contain simpler objects in their description. For example, a face references its wires, edges, and vertices.
462 ![](/user_guides/modeling_data/images/modeling_data_image006.jpg "ShapeEnum")
464 @subsubsection occt_modat_5_2_2 Orientation
466 The notion of orientation is represented by the **TopAbs_Orientation** enumeration. Orientation is a generalized notion of the sense of direction found in various modelers. This is used when a shape limits a geometric domain; and is closely linked to the notion of boundary. The three cases are the following:
467 - Curve limited by a vertex.
468 - Surface limited by an edge.
469 - Space limited by a face.
471 In each case the topological form used as the boundary of a geometric domain of a higher dimension defines two local regions of which one is arbitrarily considered as the **default region**.
473 For a curve limited by a vertex the default region is the set of points with parameters greater than the vertex. That is to say it is the part of the curve after the vertex following the natural direction along the curve.
475 For a surface limited by an edge the default region is on the left of the edge following its natural direction. More precisely it is the region pointed to by the vector product of the normal vector to the surface and the vector tangent to the curve.
477 For a space limited by a face the default region is found on the negative side of the normal to the surface.
479 Based on this default region the orientation allows definition of the region to be kept, which is called the *interior* or *material*. There are four orientations defining the interior.
481 |FORWARD | The interior is the default region.|
482 |REVERSED | The interior is the region complementary to the default.|
483 |INTERNAL | The interior includes both regions. The boundary lies inside the material. For example a surface inside a solid.|
484 |EXTERNAL | The interior includes neither region. The boundary lies outside the material. For example an edge in a wire-frame model.|
486 ![](/user_guides/modeling_data/images/modeling_data_image007.jpg "Four Orientations")
488 The notion of orientation is a very general one, and it can be used in any context where regions or boundaries appear. Thus, for example, when describing the intersection of an edge and a contour it is possible to describe not only the vertex of intersection but also how the edge crosses the contour considering it as a boundary. The edge would therefore be divided into two regions - exterior and interior - with the intersection vertex as the boundary. Thus an orientation can be associated with an intersection vertex as in the following figure:
490 |FORWARD | Entering |
491 |REVERSED | Exiting |
492 |INTERNAL | Touching from inside |
493 |EXTERNAL | Touching from outside |
495 ![](/user_guides/modeling_data/images/modeling_data_image008.jpg "Four orientations of intersection vertices")
498 Along with the Orientation enumeration the *TopAbs* package defines four methods:
500 @subsubsection occt_modat_5_2_3 State
502 The **TopAbs_State** enumeration described the position of a vertex or a set of vertices with respect to a region. There are four terms:
503 |IN | The point is interior. |
504 |OUT | The point is exterior. |
505 |ON | The point is on the boundary(within tolerance). |
506 |UNKNOWN | The state of the point is indeterminate. |
507 The UNKNOWN term has been introduced because this enumeration is often used to express the result of a calculation, which can fail. This term can be used when it is impossible to know if a point is inside or outside, which is the case with an open wire or face.
509 ![](/user_guides/modeling_data/images/modeling_data_image009.jpg "The four states")
511 The State enumeration can also be used to specify various parts of an object. The following figure shows the parts of an edge intersecting a face.
513 ![](/user_guides/modeling_data/images/modeling_data_image010.jpg "State specifies the parts of an edge intersecting a face")
515 @subsection occt_modat_5_3 Manipulating shapes and sub-shapes
517 The *TopoDS* package describes the topological data structure with the following characteristics:
518 - reference to an abstract shape with neither orientation nor location.
519 - Access to the data structure through the tool classes.
521 As stated above, OCCT Topology describes data structures of objects in parametric space. These descriptions use localization in and restriction of parts of this space. The types of shapes, which can be described in these terms, are the vertex, the face and the shape. The vertex is defined in terms of localization in parametric space, and the face and shape, in terms of restriction of this space.
523 OCCT topological descriptions also allow the simple shapes defined in these terms to be combined into sets. For example, a set of edges forms a wire; a set of faces forms a shell, and a set of solids forms a composite solid (CompSolid in Open CASCADE Technology). You can also combine shapes of either sort into compounds. Finally, you can give a shape an orientation and a location.
525 Listing shapes in order of complexity from vertex to composite solid leads us to the notion of the data structure as knowledge of how to break a shape down into a set of simpler shapes. This is in fact, the purpose of the *TopoDS* package.
527 The model of a shape is a shareable data structure because it can be used by other shapes. (An edge can be used by more than one face of a solid). A shareable data structure is handled by reference. When a simple reference is insufficient, two pieces of information are added - an orientation and a local coordinate reference.
528 - An orientation tells how the referenced shape is used in a boundary (*Orientation* from *TopAbs*).
529 - A local reference coordinate (*Location* from *TopLoc*) allows referencing a shape at a position different from that of its definition.
531 The **TopoDS_TShape** class is the root of all shape descriptions. It contains a list of shapes. Classes inheriting **TopoDS_TShape** can carry the description of a geometric domain if necessary (for example, a geometric point associated with a TVertex). A **TopoDS_TShape** is a description of a shape in its definition frame of reference. This class is manipulated by reference.
533 The **TopoDS_Shape** class describes a reference to a shape. It contains a reference to an underlying abstract shape, an orientation,and a local reference coordinate. This class is manipulated by value and thus cannot be shared.
535 The class representing the underlying abstract shape is never referenced directly. The *TopoDS_Shape* class is always used to refer to it.
537 The information specific to each shape (the geometric support) is always added by inheritance to classes deriving from **TopoDS_TShape**.The following figures show the example of a shell formed from two faces connected by an edge.
539 ![](/user_guides/modeling_data/images/modeling_data_image011.jpg "Structure of a shell formed from two faces")
541 ![](/user_guides/modeling_data/images/modeling_data_image012.jpg "Data structure of the above shell")
543 In the previous diagram, the shell is described by the underlying shape TS, and the faces by TF1 and TF2. There are seven edges from TE1 to TE7 and six vertices from TV1 to TV6.
545 The wire TW1 references the edges from TE1 to TE4; TW2 references from TE4 to TE7.
547 The vertices are referenced by the edges as follows:TE1(TV1,TV4), TE2(TV1,TV2), TE3(TV2,TV3), TE4(TV3,TV4), TE5(TV4,TV5), TE6(T5,TV6),TE7(TV3,TV6).
549 **Note** that this data structure does not contain any *back references*. All references go from more complex underlying shapes to less complex ones. The techniques used to access the information are described later. The data structure is as compact as possible. Sub-objects can be shared among different objects.
551 Two very similar objects, perhaps two versions of the same object, might share identical sub-objects. The usage of local coordinates in the data structure allows the description of a repetitive sub-structure to be shared.
553 The compact data structure avoids the loss of information associated with copy operations which are usually used in creating a new version of an object or when applying a coordinate change.
555 The following figure shows a data structure containing two versions of a solid. The second version presents a series of identical holes bored at different positions. The data structure is compact and yet keeps all information on the sub-elements.
557 The three references from *TSh2* to the underlying face *TFcyl* have associated local coordinate systems, which correspond to the successive positions of the hole.
558 ![](/user_guides/modeling_data/images/modeling_data_image013.jpg "Data structure containing two versions of a solid")
560 Classes inheriting TopoDS_Shape
561 ------------------------------
562 *TopoDS* is based on class *TopoDS_Shape* and the class defining its underlying shape. This has certain advantages, but the major drawback is that these classes are too general. Different shapes they could represent do not type them (Vertex, Edge, etc.) hence it is impossible to introduce checks to avoid incoherences such as inserting a face in an edge.
564 *TopoDS* package offers two sets of classes, one set inheriting the underlying shape with neither orientation nor location and the other inheriting *TopoDS_Shape*, which represent the standard topological shapes enumerated in *TopAbs* package.
566 The following classes inherit Shape : *TopoDS_Vertex, TopoDS_Edge, TopoDS_Wire, TopoDS_Face, TopoDS_Shell, TopoDS_Solid,TopoDS_CompSolid,* and *TopoDS_Compound*. In spite of the similarity of names with those inheriting from **TopoDS_TShape** there is a profound difference in the way they are used.
568 *TopoDS_Shape* class and the classes, which inherit from it, are the natural means to manipulate topological objects. *TopoDS_TShape* classes are hidden. *TopoDS_TShape* describes a class in its original local coordinate system without orientation. *TopoDS_Shape* is a reference to *TopoDS_TShape* with an orientation and a local reference.
570 *TopoDS_TShape* class is deferred; *TopoDS_Shape* class is not. Using *TopoDS_Shape* class allows manipulation of topological objects without knowing their type. It is a generic form. Purely topological algorithms often use the *TopoDS_Shape* class.
572 *TopoDS_TShape* class is manipulated by reference; TopoDS_Shape class by value. A TopoDS_Shape is nothing more than a reference enhanced with an orientation and a local coordinate. The sharing of *TopoDS_Shapes* is meaningless. What is important is the sharing of the underlying *TopoDS_TShapes*. Assignment or passage in argument does not copy the data structure: this only creates new *TopoDS_Shapes* which refer to the same *TopoDS_TShape*.
574 Although classes inheriting *TopoDS_TShape* are used for adding extra information, extra fields should not be added in a class inheriting from TopoDS_Shape. Classes inheriting from TopoDS_Shape serve only to specialize a reference in order to benefit from static type control (carried out by the compiler). For example, a routine that receives a *TopoDS_Face* in argument is more precise for the compiler than the one, which receives a *TopoDS_Shape*. It is pointless to derive other classes than those found inTopoDS. All references to a topological data structure are made with the Shape class and its inheritors defined in *TopoDS*.
576 There are no constructors for the classes inheriting from the *TopoDS_Shape* class, otherwise the type control would disappear through **implicit casting** (a characteristic of C++). The TopoDS package provides package methods for **casting** an object of the TopoDS_Shape class in one of these sub-classes, with type verification.
578 The following example shows a routine receiving an argument of the *TopoDS_Shape* type, then putting it into a variable V if it is a vertex or calling the method ProcessEdge if it is an edge.
582 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
583 #include TopoDS_Vertex.hxx
584 #include TopoDS_Edge.hxx
585 #include TopoDS_Shape.hxx
588 voidProcessEdge(const TopoDS_Edge&);
590 voidProcess(const TopoDS_Shape& aShape) {
591 if (aShape.Shapetype() == TopAbs_VERTEX) {
593 V = TopoDS::Vertex(aShape); // Also correct
594 TopoDS_Vertex V2 = aShape;// Rejected by compiler
595 TopoDS_Vertex V3 = TopoDS::Vertex(aShape); // Correct
597 else if (aShape.ShapeType() == TopAbs_EDGE){
598 ProcessEdge(aShape) ;// Thisis rejected
599 ProcessEdge(TopoDS::Edge(aShape)) ; // Correct
602 cout *Neither a vertex nor an edge ?* ;
603 ProcessEdge(TopoDS::Edge(aShape)) ;
604 // OK for compiler but anexception will be raised at run-time
607 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
611 @subsection occt_modat_5_4 Exploration of Topological Data Structures
613 The *TopExp* package provides tools for exploring the data structure described with the *TopoDS* package. Exploring a topological structure means finding all sub-objects of a given type, for example, finding all the faces of a solid.
615 The TopExp package provides the class *TopExp_Explorer* to find all sub-objects of a given type. An explorer is built with:
616 - The shape to be explored.
617 - The type of shapes to be found e.g. VERTEX, EDGE with the exception of SHAPE, which is not allowed.
618 - The type of Shapes to avoid. e.g. SHELL, EDGE. By default, this type is SHAPE. This default value means that there is no restriction on the exploration.
622 The Explorer visits the whole structure in order to find the shapes of the requested type not contained in the type to avoid. The example below shows how to find all faces in the shape *S*:
625 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
629 for (Ex.Init(S,TopAbs_FACE); Ex.More(); Ex.Next()) {
630 ProcessFace(Ex.Current());
633 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
635 To find all the vertices which are not in an edge:
638 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
639 for (Ex.Init(S,TopAbs_VERTEX,TopAbs_EDGE); ...)
640 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
643 To find all the faces in a SHELL, then all the faces not in a SHELL:
648 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
650 TopExp_Explorer Ex1, Ex2;
652 for (Ex1.Init(S,TopAbs_SHELL);Ex1.More(); Ex1.Next()){
654 for (Ex2.Init(Ex1.Current(),TopAbs_FACE);Ex2.More();
656 //visit all the faces of the current shell
657 ProcessFaceinAshell(Ex2.Current());
661 for(Ex1.Init(S,TopAbs_FACE,TopAbs_SHELL);Ex1.More(); Ex1.Next()){
662 // visit all faces not ina shell.
663 ProcessFace(Ex1.Current());
666 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
668 The Explorer presumes that objects contain only objects of an equal or inferior type. For example, if searching for faces it does not lookat wires, edges, or vertices to see if they contain faces.
670 The *MapShapes* method from *TopExp* package allows filling a Map. An exploration using the Explorer class can visit an object more than once if it is referenced more than once. For example, an edge of a solid is generally referenced by two faces. To process objects only once, they have to be placed in a Map.
673 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
674 void TopExp::MapShapes (const TopoDS_Shape& S,
675 const TopAbs_ShapeEnum T,
676 TopTools_IndexedMapOfShape& M)
678 TopExp_Explorer Ex(S,T);
684 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
686 In the following example all faces and all edges of an object are drawn in accordance with the following rules:
687 - The faces are represented by a network of *NbIso* iso-parametric lines with *FaceIsoColor* color.
688 - The edges are drawn in a color, which indicates the number of faces sharing the edge:
689 1. FreeEdgeColor for edges, which do not belong to a face (i.e. wireframe element).
690 2. BorderEdgeColor for an edge belonging to a single face.
691 3. SharedEdgeColor for an edge belonging to more than one face.
692 - The methods **DrawEdge** and **DrawFaceIso** are also available to display individual edges and faces.
694 The following steps are performed:
695 1. Storing the edges in a map and create in parallel an array of integers to count the number of faces sharing the edge. This array is initialized to zero.
696 2. Exploring the faces. Each face is drawn.
697 3. Exploring the edges and for each of them increment the counter of faces in the array.
698 4. From the Map of edges, drawing each edge with the color corresponding to the number of faces.
702 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
703 void DrawShape ( const TopoDS_Shape& aShape,
704 const Standard_Integer nbIsos,
705 const Color FaceIsocolor,
706 const Color FreeEdgeColor,
707 const Color BorderEdgeColor,
708 const Color SharedEdgeColor)
710 // Store the edges in aMap.
711 TopTools_IndexedMapOfShape edgemap;
712 TopExp::MapShapes(aShape,TopAbs_EDGE,edgeMap);
713 // Create an array set to zero.
714 TColStd_Array1OfInteger faceCount(1,edgeMap.Extent());
716 // Explore the faces.
717 TopExp_Explorer expFace(aShape,TopAbs_FACE);
718 while (expFace.More()) {
719 //Draw the current face.
720 DrawFaceIsos(TopoDS::Face(expFace.Current()),nbIsos,FaceIsoColor);
721 // Explore the edges ofthe face.
722 TopExp_Explorer expEdge(expFace.Current(),TopAbs_EDGE);
723 while (expEdge.More()) {
724 //Increment the face count for this edge.
725 faceCount(edgemap.FindIndex(expEdge.Current()))++;
730 //Draw the edges of theMap
732 for (i=1;i=edgemap.Extent();i++) {
733 switch (faceCount(i)) {
735 DrawEdge(TopoDS::Edge(edgemap(i)),FreeEdgeColor);
738 DrawEdge(TopoDS::Edge(edgemap(i)),BorderEdgeColor);
741 DrawEdge(TopoDS::Edge(edgemap(i)),SharedEdgeColor);
746 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
748 @subsection occt_modat_5_5 Lists and Maps of Shapes
750 **TopTools** package contains tools for exploiting the *TopoDS* data structure. It is an instantiation of the tools from *TCollection* package with the Shape classes of *TopoDS*.
752 | *TopTools_Array1OfShape, HArray1OfShape* | Instantiation of the *TCollection_Array1* and *TCollection_HArray1* with *TopoDS_Shape*. |
753 | *TopTools_SequenceOfShape* | Instantiation of the *TCollection_Sequence* with *TopoDS_Shape*. |
754 | *TopTools_MapOfShape* | Instantiation of the *TCollection_Map*. Allows the construction of sets of shapes. |
755 | *TopTools_IndexedMapOfShape* | Instantiation of the *TCollection_IndexedMap*. Allows the construction of tables of shapes and other data structures. |
757 With a **TopTools_Map**, a set of references to Shapes can be kept without duplication.
758 The following example program counts the size of a data structure as a number of TShapes.
761 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
762 #include TopoDS_Iterator.hxx
763 Standard_Integer Size(const TopoDS_Shape& aShape)
765 // This is a recursive method.
766 // The size of a shape is1 + the sizes of the subshapes.
768 Standard_Integer size = 1;
769 for (It.Initialize(aShape);It.More();It.Next()) {
770 size += Size(It.Value());
774 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
776 This program is incorrect if there is sharing in the data structure.
777 Thus for a contour of four edges it should count 1 wire + 4 edges +4 vertices
778 with the result 9, but as the vertices are each shared by two edges this program will return 13.
779 One solution is to put all the Shapes in a Map so as to avoid counting them twice, as in the following example:
782 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
783 #include TopoDS_Iterator.hxx
784 #includeTopTools_MapOfShape.hxx
786 void MapShapes(const TopoDS_Shape& aShape,
787 TopTools_MapOfShape& aMap)
789 //This is a recursive auxiliary method. It stores all subShapes of aShape in a Map.
790 if (aMap.Add(aShape)) {
791 //Add returns True if aShape was not already in the Map.
793 for (It.Initialize(aShape);It.More();It.Next()){
794 MapShapes(It.Value(),aMap);
799 Standard_Integer Size(const TopoDS_Shape& aShape)
801 // Store Shapes in a Mapand return the size.
802 TopTools_MapOfShape M;
806 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
808 **Note** For more details about Maps see the TCollection documentation.(Foundation Classes Reference Manual)
810 The following example is more ambitious and writes a program which copies a data structure using an IndexedMap. The copy is an identical structure but it shares nothing with the original. The principal algorithm is as follows:
811 - All Shapes in the structure are put into an IndexedMap.
812 - A table of Shapes is created in parallel with the map to receive the copies.
813 - The structure is copied using the auxiliary recursive function,which copies from the map to the array.
817 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
818 #include TopoDS_Shape.hxx
819 #include TopoDS_Iterator.hxx
820 #include TopTools_IndexedMapOfShape.hxx
821 #include TopTools_Array1OfShape.hxx
822 #include TopoDS_Location.hxx
824 TopoDS_Shape Copy(const TopoDS_Shape& aShape,
825 const TopoDS_Builder& aBuilder)
827 // Copies the wholestructure of aShape using aBuilder.
828 // Stores all thesub-Shapes in an IndexedMap.
829 TopTools_IndexedMapOfShape theMap;
833 TopLoc_Location Identity;
835 S.Location(Identity);
836 S.Orientation(TopAbs_FORWARD);
838 for (i=1; i= theMap.Extent(); i++) {
839 for(It.Initialize(theMap(i)); It.More(); It.Next()) {
841 S.Location(Identity);
842 S.Orientation(TopAbs_FORWARD);
847 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
850 In the above example, the index *i* is that of the first object not treated in the Map. When *i* reaches the same size as the Map this means that everything has been treated. The treatment consists of inserting in the Map all the sub-objects, if they are not yet in the Map, they are inserted with an index greater than *i*.
852 **Note** that the objects are inserted with a local reference set to the identity and a FORWARD orientation. Only the underlying TShape is of great interest.
855 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
856 //Create an array to store the copies.
857 TopTools_Array1OfShapetheCopies(1,theMap.Extent());
859 // Use a recursivefunction to copy the first element.
860 void AuxiliaryCopy (Standard_Integer,
861 const TopTools_IndexedMapOfShape &,
862 TopTools_Array1OfShape &,
863 const TopoDS_Builder&);
865 AuxiliaryCopy(1,theMap,theCopies,aBuilder);
867 // Get the result with thecorrect local reference and orientation.
869 S.Location(aShape.Location());
870 S.Orientation(aShape.Orientation());
872 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
874 Below is the auxiliary function, which copies the element of rank *i* from the map to the table. This method checks if the object has been copied; if not copied, then an empty copy is performed into the table and the copies of all the sub-elements are inserted by finding their rank in the map.
877 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
878 void AuxiliaryCopy(Standard_Integer index,
879 const TopTools_IndexedMapOfShapes&sources,
880 TopTools_Array1OfShape&copies,
881 const TopoDS_Builder&aBuilder)
883 //If the copy is a null Shape the copy is not done.
884 if (copies(index).IsNull()) {
885 copies(index) =sources(index).EmptyCopied();
886 //Insert copies of the sub-shapes.
889 TopLoc_Location Identity;
890 for(It.Initialize(sources(index)),It.More(), It.Next ()) {
892 S.Location(Identity);
893 S.Orientation(TopAbs_FORWARD);
894 AuxiliaryCopy(sources.FindIndex(S),sources,copies,aBuilder);
895 S.Location(It.Value().Location());S.Orientation(It.Value().Orientation()); aBuilder.Add(copies(index),S);
899 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
901 @subsubsection occt_modat_5_5_1 Wire Explorer
903 BRepTools_WireExplorer class can access edges of a wire in their order of connection.
905 For example, in the wire in the image we want to recuperate the edges in the order {e1, e2, e3,e4, e5} :
907 ![](/user_guides/modeling_data/images/modeling_data_image014.jpg "A wire composed of 6 edges.")
909 TopExp_Explorer, however, recuperates the lines in any order.
913 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
915 BRepTools_WireExplorer Ex;
916 for(Ex.Init(W); Ex.More(); Ex.Next()) {
917 ProcessTheCurrentEdge(Ex.Current());
918 ProcessTheVertexConnectingTheCurrentEdgeToThePrevious
919 One(Ex.CurrentVertex());
921 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~