
Sat, 05/20/2017 - 02:49
Forums:
Hi,
I am trying to convert some surfaces with boundaries/contours to meshes. I understand how to create a surface (thanks to the constructors of Geom_BSPSurface, Geom_Plane, Geom_ConicalSurface, Geom_SphericalSurface, Geom_ToroidalSurface ...) but I do not understand how to set the constraints on the boundaries/contours : I have boundaries compound by BSP curves, lines, ellipses, ... How can I add these boundaries on my surface so I can tessellate it to eventually get a mesh ?
Best regards,
MLR
Mon, 05/22/2017 - 15:42
Hi Marc,
It depends on the type of the constrained curves:
If the curves are given in 2D, as curves in the parametric space of the surface, then you can use BRepBuilderAPI_MakeEdge and BRepBuilderAPI_Makeface to construct the faces from the surfaces.
I have made an example : CurveOnSurface
If the curves are defined as 3D-curves (unrelated to the surfaces) you first have to project the 3D curves on the surface to obtain a parametric curve on the surface.
To get a triangulation of a shape see example: MakeMeshFromShape
Hope this points you in the right direction? :)
Best regards,
Guido
Sat, 05/20/2017 - 10:35
Thanks a lot Guido !
I better understand (I think) the way to set the boundaries. I "just" have to implement that now :).
The tessellation process is more explicit too : I identified the BRepMesh_IncrementalMesh class but I had no idea how to parse the triangles.
I will try that on monday now, have a nice WE.
Marc
Mon, 05/22/2017 - 15:42
Hi Marc, Thank you for your replay!
I have made the code a bit more generic.
There is a function: OCTopoDS_Face face = FaceFromSurfaceAndCurves(cylinder, new OCGeom2d_Curve[] { lTop, lBottom, lLeft, lRight });
See: CurveOnSurface
Have a nice WK too :)
Guido
Thu, 06/01/2017 - 18:54
Hi,
The code is working pretty well ! Thanks a lot it has been fast to develop with your example. I used it (modifying it a bit) to manage various kind of surfaces & boundaries.
But ... :) ... using the process to cut planes is OK but when I try to do that with BSP surfaces, the tessellation is not working any more.
You can find below 3 parts of simplified code :
- one to generate the wire of a closed boundary (TopoDS_Wire)
- one to generate the BRep surface (topoDS_Face) adding the boundaries
- one to tessellate the BRep surface
As you can see I did not project the curves (which are all "Geom_Curve") on my surface (I store all the surfaces as "Geom_Surface") before creating the wire for the boundary. I tried to do it but without success.
I was wondering if this is the reason why the tessellation fails (the surface is created, the wires for the boundaries seems to be OK too but the result of triangulation is NULL). Have you got any idea to solve this issue ? By the way, without boundaries the tessellation is working.
Fri, 06/02/2017 - 11:34
Hi Marc,
I am not sure,but I think the inner boundaries are not related to the surface. (has PCurve on surface)
In my example the edges of the boundary and edges of the innner wires are already related to the surface.
If surface is a plane I think BRepBuilderAPI_MakeFace can handle direct without PCurve.
If you attach a more complete code snipped, I can see if I can make it work?
Best regards,
Guido
Thu, 06/08/2017 - 19:10
Hi,
I can eventually tessellate planes & others surfaces but the major issue I have got is to represent the curves (& surfaces but mostly the curves) in OCC.
I have to manage the following surfaces: BSplineSurfaces, Planes, Cones, Cylinders, Torus, Sphere, ruled surface, revolution, projection.
And boundaries can be set as combination of various kind of curves : BSplineCurve, polyline, ellipse, segment, and a "complex curve" which is a combination of any kind of curve.
I have chosen to store all the surfaces as "Geom_Surface". To do that I'd like to use the following classes or methods :
I have chosen to store all the curves as "Geom_Curve". To do that I use the following process
I then apply the meshing process defined earlier in this thread without having to look at the type of surface/curve, everything "should" become generic (it will be great when everything will work ;) ).
What do you think about this representation and construction method ?
Best regards,
Marc
Wed, 07/05/2017 - 17:01
Hi,
I have done a "generic" code to address any kind of surface I give to my program as Geom_Surface and to tessellate it (using its boundaries first to create a TopoDS_Face). Most of the surfaces seem to be tessellated a good way, but some of them are doing all the process (from Geom_Surface to TopoDS_Face) but triangulation fails (the result is empy - isNull() is true). It is difficult for me to know where I should look to solve that issue since no error message is given by Triangulation. Have you got any idea ? (modifying the parameters of tessellation ?)
Sometimes it fails while creating the projected boundary : BuildCurve3D raises an access violation on NULL address but everything goes well till BRepBuilderAPI_MakeEdge. What kind of test should I do on BRepBuilderAPI_MakeEdge to check Edge validity before asking for BuildCurve3D ? Am I doing the process the right way ?
Here is my source code to process the Geom_Surface with its boundaries (array of Geom_Curve) into vertices & faces. It is a bit "raw" but should illustrate well the full process.
Wed, 06/07/2017 - 18:14
I won't be able to send you code before next wednesday :'( ... I will try to write you a full (but simple) example of what I'd like to do on wednesday. Thanks again for the help.
EDIT : It seems I do not understand well the process to create the boundaries on surfaces from Geom_Curve objects. I tried to project the curves on the surface to create the boundaries but it was not really efficient. To summarize : I have an object (Geom_Surface) & some boundaries (Geom_Curves) and I would like to cut the surface with the boundaries (I have uploaded a drawing to illustrate the process I would like to achieve). I have implemented the process following your advises :
- get the surface & boundaries and store them
- convert each boundary as a wire (*)
- using BRepBuilderAPI_MakeEdge to get edges from each curve of the boundary
- ShapeAnalysis_FreeBounds::ConnectEdgesToWires to create a single wire (and ShapeAnalysis_FreeBounds::SplitWires to get the first closed wire)
- create a Face using BRepBuilderAPI_MakeFace and add each boundary as wire (with the Add method)
- then I tessellate the face using BRepMesh_IncrementalMesh & BRep_Tool::Triangulation
(*) I tried to use BOPTools_AlgoTools2D::MakePCurveOnFace to project the Geom_curve as Geom2d_curve (inspired by the following post : https://www.opencascade.com/content/topodsedge-built-geom2dcurve-and-geomsurface-has-not-pcurve-face but It is not working on planes any more :), and it gives a result on BSP surfaces but not the one I waited for; when I "mesh" it, only the boundaries are used to create the triangles, it seems to not take into account the BSplineSurface).
It is quite difficult to get a source code from my project since it is developed to be quite generic and create the surfaces/curves from files (surfaces & curves creation checked displaying them in the open cascade MFC sample app Geometry). I will try to create an example in a single file and post it there asap.
Do you think I am on the right way to apply boundaries on any kind of surfaces to tessellate them or should I rewrite the full process ?
re - EDIT ! Eventually, it seems that tessellation is working with other surfaces than planes when projection is done ... I did set the angle degeneration too high in BRepMesh_IncrementalMesh !
Tue, 07/11/2017 - 11:26
Eventually I identified one of the surface I import which raises an exception in the program. I wrote a code to set it as raw data and do the process I would like to achieve. You may be able to see better where is my mistake (because I must be doing one but no way to have a clue on that !).
The code should generate a tessellated "Arc" of cylinder as final result (if using the triangles & nodes arrays).
You can find the full source code below. The exception is raised while trying to call BuildCurve3D (for the first curve, the first segment):
Mon, 07/17/2017 - 17:44
Hi,
I am beginning to understand which is not working (but not why for the moment :) ).
I tried various way of projecting the curves on surfaces using BRep_Tool::CurveOnSurface / BOPTools_AlgoTools2D::MakePCurveOnFace / GeomProjLib::Project + GeomProjLib::Curve2D and it seems the first one is faster than the others BUT, for some reasons I cannot explain, using it for cylindrical surfaces will crash the program (as far as I want to buildCurve3D from the resulting Edges). I use GeomProjLib for cylindrical surface and it seems to work quite well for some of them.
Have you ever encounter this issue projecting on this kind of surfaces ?
Tue, 07/18/2017 - 14:59
If you can isolate the problem for witch surface and curve it goes wrong, I can have a look?
Wed, 07/19/2017 - 09:33
Hi Guido,
You can find an example of the surface which does not work well with the process I developed in one of my previous post. I replaced BOPTools_AlgoTools2D::MakePCurveOnFace by BRep_Tool::CurveOnSurface, but then the resulting 2D curve is null. All the curves I use are defined so they are already described to be on the surface (but I still need to project them to process BRepBuilderAPI_MakeFace) since they are from another BRep description (but not using the same surface description as OpenCascade does). I will post you the OBJ export so you can view the result if it is working for you. I think the process I developed should not be the correct one to address any kind of surfaces (when you look at it what do you think about the way I project on surface & create the boundaries/triangulation ?).
NB : As most of my cylinder surfaces are described with simple boundary (arc of ellipse, segment following the axis of the cylinder, arc of ellipse , segment following the cylinder axis), I just created a GeomFill::Surface between the 2 arcs of ellipse. But this is more a trick than a solution. This enables me to get more surfaces but not all of them.
Best regards
Marc
Tue, 12/19/2017 - 18:05
Hi,
Back on this issue ! I isolated a simple case : projection of a circle on a cylinder.
I just cannot understand why I cannot project an ellipse on a cylindrical surface ? I tried to but the Geom2d_Curve returned is always empty (null).
The little section of code I used to test that is the following one : I create a cylindrical surface and an ellipse with exactly the same parameters (axis, radius, center).
But the ellipse projection fails : bottom2D is always null ! :( "Something is rotten in the state of Denmark" :). Seriously, may I use another method to project any curve on my cylinder (projection of segments on cylinder is null too), or should I create the cylinder surface another way ?
I hope someone could help me ( Guido :) ? )
Thu, 12/21/2017 - 01:39
Hi Marc,
In your example (above), there is no relation between the Edge and the Face. The edge is "on" the surface but they are unrelated.
To get the "CurveOnSurface" you have to project the edge on the Face. the result is an new edge that contains a CurveOnSurface on the surface of the face.
Here is the example: EdgeOnFace
The edge now contains a 3DCurve(Ellipse with same radii) and a CurveOnSurface(BSplineCurve) (see dump below)
the curve on surface is theoretical a 2D straight line in the parametric space of the surface from (0,0) to (2*PI,0)
But in the dump below you can see that the projection has made a BSplineCurve representation of the straight line.
Hopes it get you on track?
Best regards, Guido
Dump:
Shape : 2, FORWARD
Dump of 2 TShapes
-----------------
Flags : Free, Modified, Checked, Orientable, Closed, Infinite, Convex
TShape # 1 : EDGE 0101000 0000000129C3A0F0
+2 -2
Tolerance : 0.0001
same parametrisation of curves
same range on curves
- Curve 3D : 1, range : 0 6.28319
- PCurve : 1 on surface 1, range : 0 6.28319
UV Points : 0, 0 6.28319, 0
TShape # 2 : VERTEX 0101101 000000012A2A8E70
Tolerance : 0.0001
- Point 3D : 1, 0, 0
-------
Dump of 1 Curve2ds
-------
1 : Trimmed curve
Parameters : 0 6.28319
Basis curve :
BSplineCurve
Degree 1, 2 Poles, 2 KnotsPoles :
1 : 0, 0
2 : 6.28319, 0
Knots :
1 : 0 2
2 : 6.28319 2
-------
Dump of 1 Curves
-------
1 : Ellipse
Center :0, 0, 0
Axis :0, 0, 1
XAxis :1, 0, -0
YAxis :-0, 1, 0
Radii :1, 1
-------
Dump of 0 Polygon3Ds
-------
-------
Dump of 0 PolygonOnTriangulations
-------
-------
Dump of 1 surfaces
-------
1 : CylindricalSurface
Origin :0, 0, 0
Axis :0, 0, 1
XAxis :1, 0, -0
YAxis :-0, 1, 0
Radius :1
-------
Dump of 0 Triangulations
-------
-------
Dump of 0 Locations
-------
Thu, 12/21/2017 - 16:32
Thanks a lot for your help ! I try that immediately.
Thu, 12/21/2017 - 16:32
2D curves are all generated properly ! Thanks again.
I now try to generate wires from these curves to generate a finite surface but it seems I still misunderstood something. Here is the code I wrote :
The triangulation does not work even if wires are generated :(. I tried on other surfaces and tessellation is never generated while using the normalProjection method on boundary curves.