For all issues regarding the Forums use, please, refer to the Forum Rules.

Our Solutions

Need professional assistance?
Consider our:

Support Offerings

 

Need to speed up your development?
Have a look at our:

Samples & Tools

 

Need some functionality extending standard OCCT capabilities?
Check out our:

Adv. Components

Related pages

Advice for newbie

Nick Torkos's picture
Forums: 

I've just started using this tool and am excited about the possibilities.

My first test was to add code into an MFC app I'm working on to try out the boolean operations.

Here is the test:
TopoDS_Shape theBox = BRepPrimAPI_MakeBox(200,40,40);
TopoDS_Shape theSphere = BRepPrimAPI_MakeSphere(gp_Pnt(100,20,20),80);
TopoDS_Shape ShapeCut = BRepAlgoAPI_Cut(theSphere,theBox);

The first two lines seem to work fine, but the Cut command gives me an assert:
Unhandled exception at 0x7c81eb33 in ZEditor.exe: Microsoft C++ exception: StdFail_NotDone @ 0x0012eb7c.

Any idea what I did (or forgot to do?)

NT

Nick Torkos's picture

Okay, I managed to get past this with the following code:

TopoDS_Shape theBox = BRepPrimAPI_MakeBox(200,40,40);
TopoDS_Shape theSphere = BRepPrimAPI_MakeSphere(gp_Pnt(100,20,20),80);
TopoDS_Shape ShapeCut;
BRepAlgoAPI_Cut aCutOperation(theBox, theSphere);
if (aCutOperation.IsDone()) { // triangulate}

Now I have trouble triangulating.
The code I am using is as follows (which I got from the forum):

ShapeCut = aCutOperation.Shape();
for ( TopExp_Explorer ex( ShapeCut, TopAbs_FACE ) ; ex.More(); ex.Next() )
{
TopoDS_Face F = TopoDS::Face(ex.Current());
// Get triangulation
TopLoc_Location L;
Handle (Poly_Triangulation) facing = BRep_Tool::Triangulation(F,L);
const Poly_Array1OfTriangle & triangles = facing->Triangles();
const TColgp_Array1OfPnt & nodes = facing->Nodes();
for ( int i=triangles.Upper(); i >= triangles.Lower()+1; --i ) // (indeksy 1...N)
{
Poly_Triangle triangle = triangles(i);

Standard_Integer node1,node2,node3;
triangle.Get(node1, node2, node3);

gp_Pnt v1 = nodes(node1);
gp_Pnt v2 = nodes(node2);
gp_Pnt v3 = nodes(node3);
// now we need to transform vertices
// don't forget about face orientation :)
}

I am using my own renderer, so am not using any of open cascade's display functionality. Should I be using another function as well? I read somewhere that I might be able to use BRepMesh::IncrementalMesh, but am not sure how to use it in this setup.

Patrik Müller's picture

Hi Nick,

could you give us further informations about your problem with triangulation?

Greets,

Patrik

Nick Torkos's picture

Oh, sorry. I wasn't getting any data. I think I figured that out.
My current problem involves getting mesh data from a sphere. What is the best way to do that?
If you know something is a sphere in advance it is pretty easy to triangulate it. However, the method I am using is as follows:

m_shape = BRepPrimAPI_MakeSphere(radius);
BRepMesh::Mesh(m_shape,0.1);
{
PVERTEX V1, V2;
TopExp_Explorer ex;
for ( ex.Init( m_shape, TopAbs_FACE ) ; ex.More(); ex.Next() )
{
TopoDS_Face F = TopoDS::Face(ex.Current());
// Get triangulation
TopLoc_Location L;
Handle (Poly_Triangulation) facing = BRep_Tool::Triangulation(F,L);
const Poly_Array1OfTriangle & triangles = facing->Triangles();
const TColgp_Array1OfPnt & nodes = facing->Nodes();
if (!facing.IsNull())
{
for ( int i=facing->NbTriangles(); i >= 1; --i ) // (indeksy 1...N)
{
Poly_Triangle triangle = triangles(i);

Standard_Integer node1,node2,node3;
triangle.Get(node1, node2, node3);

gp_Pnt v1 = nodes(node1);
gp_Pnt v2 = nodes(node2);
gp_Pnt v3 = nodes(node3);

// do my own render of the circle

The mesh comes out, but it isn't very pretty. Is there a different way to do this if your object is a known primitive like a box or a sphere? If not, what is a good number for getting a decent looking mesh of a sphere, given that I have an idea of how dense I want the polys, and I want the triangles to look better.

Final question is that the line :
if (!facing.IsNull())

fails if the radius is about 1.68 or greater. Not sure why.

Patrik Müller's picture

Hi Nick,

there are several possibilities to check for known primitives (esp. spheres):
- http://www.opencascade.org/org/forum/thread_9601/ (Shapetype)
- a second possiblity would eb the "canonical recognition" toolkit from OCCT. I think Pavel could give you further informations?

So if you know your shape is a sphere I would triangulate it without OCCs triangulation tools - how to triangulate a sphere shouldn't be a large problem...

Greets,

Patrik

oumaia's picture

I wanted to make sections, but I found the same error Nick Torkos.
I used the method isdone () but I havn't understand why the section does not made for some shape

oumaia's picture

hello,
I found the solution.
I have used BRepAlgo_Section instead BRepAlgoAPI_Section

rtfiya's picture

Hi Nick,I am also new here.Sorry if i am not able to help you at this time.:(
[url=http://www.stop-painting.com] floor tape [/url]

Contact us

Attention: DO NOT use this form for all kind of request for the removal of your personal data. Please follow this link for such cases.