Mesh algorithm in Opencascade__opencascade knowledge

Source: Internet
Author: User

Abstract. Rendering a generic surface is a two steps Process:first, computing the points that would form the mesh of the surface and Then, send this mesh to 3D API. Use the triangle to triangulate the parametric spaces and then lifting map to the model 3D spaces. This is the main method to visualize the generic shaded surface. This is paper show the Opencascade triangulation of the parametric spaces and the map Result:mesh in 3D model spaces. Use the method can visualize a generic surface.

Key words. Delaunay triangulation, tessellation, Mesh, Opencascade, Shaded Surface

1. Introduction

The visualization of a surface is slightly more complex than the visual algorithm of a curve. The general idea is very well understood, that is, the parameters of the space triangulation, and then the split results mapped to three-dimensional space, the surface of the grid data.

Because of the strong convex package of B-spline surface, the parametric space can be divided into three-dimensional space by triangulation. This can realize the visualization of the surface, but some problems need to be dealt with, such as the surface of the hole, discrete precision control of the surface.

Because the Opencascade uses the boundary representation (BREP), the parameter range of the surface can be obtained by Face,wire,edge, if there is a hole on the surface, the parameter representation of the opening on the surface can be obtained by the pcurve of the edge. By triangulation the obtained parameter space and mapping it into three-dimensional space, we can visualize the shape represented by the boundary.

The use of triangular meshes to approximate the actual shape's precision can be achieved by increasing or decreasing points in the parameter space. When the parameter space is divided, the surface mapped to the three-dimensional space is more approximate to the real surface, and when the parameter space is divided, the surface mapped to the three-dimensional space is more rough.

In this paper, the triangulation results of the parametric space of the surface in the Opencascade are shown to analyze and understand the algorithm.

2. Opencascade brep Shape

The boundary notation (BREP) of entities in Opencascade is:

U Compsolid is composed of solid of surface sharing;

U SOLID (Cylinder, Cone, Sphere, torus, etc.) the body (shells) separated by Volume;

The U-Shell is composed of faces connected by side edges;

The u Face is a map (map) that maps from the parameter UV space of the rectangle to the 3D space. (Cylinder: [0, 2*pi] x[0, H]-> r3,cone, Sphere, Torus, Bézier Surface, NURBS Surface, etc.)

The boundary of U face is composed of wire;

U wire consists of connected edges;

The u Edge is also a map that maps from the one-dimensional parametric space u to 3D space. (Bézier ' s Curve: [0,1]-> R3, NURBS Curve, etc.)

U vertex is used to limit the edge;

The boundary notation (brep) forms a graph structure (a Vertex of graph) between different shapes (Compsolid, Solid, Shell, Face, Wire, Edge, structure), as shown in the following figure:

Figure 2.1 Shape Brep in Opencascade

The tree structure that represents the boundary representation of the above graph is shown in the following figure. As the diagram shows, some structures are shared several times. Use class Topods_shape to save this structure in Opencascade.

Figure 2.2 Graph structure of the Brep Shape

3. How the Mesh is generated

Opencascade can traverse compsolid different child shapes. First of all, the edge is discretized, the implementation of the pseudo code is as follows:

For (Topexp_explorer edgeexp (Thecompsolid, Topabs_edge);
Edgeexp.more ();
Edgeexp.next ())
{
The u-interval of the EDGE is subdivided into
Segments with respect to the edge length and
Deflection in 3d-space. By the map, the segments
Of the u-interval give the segments in 3d-space.
Const topods_edge& theEDGE = Topods::edge (Edgeexp.current ());
Brepadaptor_curve BAC (theEDGE);

Gcpnts_tangentialdeflection Thepointsoncurve;
Thepointsoncurve.initialize (BAC, adeflection, cdeflection);
standard_real u = 0.0;
GP_PNT Apoint;
for (Standard_integer i = 1; I <= thepointsoncurve.nbpoints (); ++i)
{
U = thepointsoncurve.parameter (i);
Apoint = Thepointsoncurve.value (i);
}
}

Use the above algorithm to disperse each edge, as shown in the following illustration:

Figure 3.1 Creation of U-mesh and 3d-mesh for each EDGE

When there is a hole on the surface, the information of the opening can be obtained by wire. For each edge of the wire that makes up the hole, the parameters of the Pcurve can be unified to the UV parameter space of the surface through the curve on the surface. The implementation pseudocode looks like this: for (Topexp_explorer faceexp (Thecompsolid, topabs_face);
Faceexp.more ();
Faceexp.next ())
{
For (Topexp_explorer Wireexp (Faceexp.current (), topabs_wire);
Wireexp.more ();
Wireexp.next ())
{
For (Topexp_explorer Edgeexp (Wireexp.current (), Topabs_edge);
Edgeexp.more ();
Edgeexp.next ())
{
The U-mesh of the EDGE is assembled after scaling in the
Uv-domain to constitute the WIRE.
Standard_real thefirst = 0.0;
Standard_real thelast = 0.0;
GP_PNT2D THEUV;

Handle_geom2d_curve Thepcurve =
Brep_tool::curveonsurface (theEDGE, Theface, Thefirst, thelast);

THEUV = Thepcurve.value (thefirst);
}
}
}

Figure 3.2 Hole in parametric UV spaces

Wire The parameter space of the limited surface to triangulation, if there is a hole in the information, then the formation of holes in the wire inner triangle removed. By mapping the triangulation of parametric space to three-dimensional space, the triangular mesh of the surface can be obtained. As shown in the following illustration:

Figure 3.3 Hole in Surface

The compsolid is divided into each face of the composition, and finally the compsolid grid is obtained. The implementation pseudocode looks like this: for (Topexp_explorer faceexp (Thecompsolid, topabs_face);
Faceexp.more ();
Faceexp.next ())
{
The 3d-mesh of the assembled to form the
Boundary of the SOLID.
}

Figure 3.4 Mesh of the Shape

4. Deflection Control

The shape is approximated by a triangular mesh, so the higher the discrete precision, the more realistic the display, but the larger the amount of data produced; the lower the discrete precision, the more distorted the display, but the smaller the amount of data produced. As Shakespeare said: to being or not to be:that is the question. In the face of choice, do not go to extremes, the golden mean is also a good solution. To balance the display of fidelity with the size of the data, the algorithm for entity triangulation needs to be considered.

In the Opencascade, the mesh data of the triangulation of the surface are stored in the class poly_triangulation, also including the partition of the parameter space of the surface, and the parameter node data is uvnodes. The following code shows the visualization of the parametric space triangulation results for a surface:

osg::geode* Builduvmesh (const handle_poly_triangulation& Themesh)
{
osg::ref_ptr<osg::geode> Thegeode = new Osg::geode ();
osg::ref_ptr<osg::geometry> thetriangles = new Osg::geometry ();
osg::ref_ptr<osg::vec3array> thevertices = new Osg::vec3array ();

for (Standard_integer t = 1; t <= themesh->nbtriangles (); ++t)
{
Const poly_triangle& Thetriangle = Themesh->triangles (). Value (t);

GP_PNT2D theUV1 = Themesh->uvnodes (). Value (Thetriangle (1));
GP_PNT2D theUV2 = Themesh->uvnodes (). Value (Thetriangle (2));
GP_PNT2D theUV3 = Themesh->uvnodes (). Value (Thetriangle (3));

Thevertices->push_back (OSG::VEC3 (theuv1.x (), 0.0, theuv1.y ()));
Thevertices->push_back (OSG::VEC3 (theuv2.x (), 0.0, theuv2.y ()));
Thevertices->push_back (OSG::VEC3 (theuv3.x (), 0.0, theuv3.y ()));
}

Thetriangles->setvertexarray (thevertices. get ());
Thetriangles->addprimitiveset (
New OSG::D rawarrays (osg::P rimitiveset::triangles, 0, Thevertices->size ()));

Osgutil::smoothingvisitor SMV;
Smv.smooth (*thetriangles);

Thegeode->adddrawable (Thetriangles);

return Thegeode.release ();
}

The triangulation of the spherical parameter space is shown as shown in the following figure. We know the range of the parameter space from 0 to 2pi,v from-PI/2 to PI/2 from the parametric equation of spherical surface.

It can also be seen from the diagram that the parametric space of the spherical surface is split, and only a few points are added in the v direction, while the U direction does not increase.

Figure 4.1 Triangulation of the Sphere parametric space

When the discrete precision is added, the display is more realistic but produces more grid data, as shown in the following illustration:

Figure 4.2 Triangulation of the Sphere

From the above, we know that the more detailed the parameter space is, the more realistic the display effect is. It is also known from the above diagram that the parameters of the Opencascade to the spherical surface are not uniformly divided, and there are dense regions and relatively sparse regions. If the parameter space is divided evenly and mapped to the three-dimensional surface of the space, the display effect is not very uniform. The following figure shows an ideal split grid for the spherical surface:

Figure 4.3 triangulation of the Sphere generated by Netgen

Figure 4.4 Triangulation of the Sphere

It can be seen from the graph that after the parameter space is divided evenly, the mapping to the three-dimensional space, at the two poles of the sphere, shows some dense, near the track line, relatively sparse.

The same surface, when the split is dense, the display is exquisite, as shown in the following figure:

Figure 4.5 Triangulation of a Shape by Netgen

The results obtained in the Opencascade are shown in the following figure:

Figure 4.6 Triangulation of a Shape by Opencascade

In the Opencascade, only the edges of the discrete points of the triangle, there is no optimization, but for the display is also good, and the amount of data is very small. When the program is dealing with a lot of models, reduce the number of triangular grids, will significantly improve the display speed. Therefore, it is necessary to select a compromise and harmonious algorithm according to the actual needs in the mesh generation of the entity. Where to the mesh quality requirements (such as for the finite element analysis), the model is small, can be divided into fine entity, if the model is very large, and high demand for the display speed, in the mesh algorithm can choose to generate a small amount of data algorithm.

The rendering mode of the above shape is shown in the following illustration. Although there are many slender triangles in the split, it is sufficient to display the vertex method of the mesh when it is correctly set. The number of triangles is obviously much less.

Figure 4.7 Shaded mode of the Shape

Figure 4.8 Shaded Mode in Opencascade

5. Conclusions

After the parametric space triangulation of the surface in the shape is mapped to three-dimensional space, the shape of the mesh is obtained. When there is a hole in the shape, the data of the hole can be obtained by means of the boundary notation. Through the curve pcurve on the surface, the hole and the surface can be unified into the parameter space to split.

The quality of grid and the control of discrete precision is a problem. Mesh the shapes as needed. When the parameter space is evenly split, the resulting surface is not necessarily uniform. Therefore, there should also be a similar algorithm to the curve discretization, that is, in the larger curvature of the place, the density of split, in a very flat, split coarse. This will strike a balance between the display and the speed.

6. References

1. Alain perronnet. Nef:a Mesher based on Opencascade C.A.D software

Https://www.ljll.math.upmc.fr/~perronnet/mit/mit.html

2. Kelly Dempski. Focus on Curves and Su

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.