Geom_SurfaceOfRevolution...How to Store the created surface!

Hi

I want to create a surface of revolution using Geom_SurfaceOfRevolution. I tried using the following code:

Handle(Geom_TrimmedCurve) NoseArc = GC_MakeArcOfCircle(NCproj,gp_Vec(NCproj,gp_Pnt(0,0,0)),gp_Pnt(0,0,0)).Value();
Handle(Geom_Surface) Nose2 = Geom_SurfaceOfRevolution(NoseArc,gp_Ax1(gp_Pnt(0,0,0),gp_Dir()));

But this gives the error C2240: cannot convert from Geom_SurfaceOfRevolution to Handle_Geom_Surface
No constructor could take the source type, or constructor overload resolution was ambiguous

How do I solve this problem. Thanks
Regards
Nitin

Francois Lauzon's picture

Hello Nitin,
looks like your missing the new operator:

Handle(Geom_Surface) Nose2 = new Geom_SurfaceOfRevolution(NoseArc,gp_Ax1(gp_Pnt(0,0,0),gp_Dir()));

Good luck,
Francois.

Nitin's picture

Hi Francois
Thanks for the reply.
Well now that I do get a Geom_Surface, I need to change it into a TopoDS_Face to display it. I tried using the BRep_Builder::MakeFace function in the following code.

TopoDS_Face NoseFace;
Standard_Real Tol = 1e-7;
BRep_Builder::MakeFace(NoseFace, Nose2, Tol);

But I get the following error:
Error C2352: "BRep_Builder::MakeFace" : Illegal Call of non-static member function

Is there a different syntax for using the BRep_Builder::MakeFace function??
Regards
Nitin

Kustaa Nyholm's picture

From both of your questions it looks like you are struggling with basic C++ concepts, maybe refresh course is in order. Granted C++ error messages are not always most helpful, but this seems to be spot on:

The error message tells you that it is a non static function, hence you need an instance of 'BRepBuilder'.

So the call should be something like:

myBrepBuilder->MakeFace(NoseFace, Nose2, Tol);

This is not OCC issue, pure C++ language knowledge. Unfortunately I'm not familiar very familiar with OCC, so someone else needs to tell where you get one( instance of BRepBuilder), could be as simple as as creating a variable on the stack or instantiate one using 'new'.

br Kusti

Nitin's picture

Hi Kustaa
Yes I am new to programming and C++. And I do know that I need to instantiate BRep_Builder.
But I have tried the call you mentioned. Its just that whenever I use BRep_Builder it does not recognise it as a class but as a static const int variable. So its not possible to instantiate it if it is not recognised as a class.

Maybe some of the questions sound silly, but I guess one only learns by interacting with people who can help them learn and become better with every experience.
regards
Nitin

Kustaa Nyholm's picture

I did not try to imply that the questions are silly, just that they come across being rather fundamental issues and both C++ and OCC are rather complex at every level so it was a friendly poke in case you were too green or ambitious. Nothing wrong being either.

Been a while since I used C++ everyday but if this literally true: "whenever I use BRep_Builder it does not recognise it as a class but as a static const int variable." it sounds like 'implicit int' in C and could suggest that you are missing a header ie BRep_Builder is not defined in that context, or could be namespace issue. But again, I'm out of practice with C++ and OCC so better if someone helps you.

br Kusti

Roman Lygin's picture

Nitin,

Not to be offensive in anyway but there are more efficient ways *before* asking people - spend your time on self-eduction by reading books and articles. That will pay off - you will ramp up faster and learn how to solve most problems faster.

Roman

Nitin's picture

Hi Roman
Thanks for the advice. And Yes I have been doing that. Maybe I m not able to put my questions in a better way, but they are genuine problems that I have tried every way to solve before asking you guys.

In this case, I have defined BRep_Builder header file but it still does not recognise it as a class while I try to create an instance of it. Its always recognises it as static const int.

Regards
Nitin

Roman Lygin's picture

#include "BRep_Builder.hxx"
#include "TopoDS_Face.hxx"
...

Handle(Geom_Surface) Nose2 = new Geom_SurfaceOfRevolution(NoseArc,gp_Ax1(gp_Pnt(0,0,0),gp_Dir()));
BRep_Builder aBuilder;
TopoDS_Face NoseFace;
Standard_Real Tol = 1e-7;
aBuilder.MakeFace(NoseFace, Nose2, Tol);

For C2352 details see here - http://msdn.microsoft.com/en-us/library/2x426hte%28v=VS.90%29.aspx. It gives an example of a wrong usage of an ordinary method as static method.

Hope this helps.
Roman

Nitin's picture

Hi
Thanks Roman. I had done exactly the same thing and gone through the same link that you have provided.
But on using this code, the sample compiles successfully but does not show the created surface.

This is my code:

Handle(Geom_Curve) NoseArc = GC_MakeArcOfCircle(NCproj,gp_Vec(NCproj,gp_Pnt(0,0,0)),gp_Pnt(0,0,0)).Value();
Handle(Geom_Surface) Nose2 = new Geom_SurfaceOfRevolution(NoseArc,gp_Ax1(gp_Pnt(0,0,0),gp_Dir()));
BRep_Builder aBuilder;
Standard_Real Tol = 1e-7;
TopoDS_Face NoseFace1;
aBuilder.MakeFace(NoseFace1, Nose2, Tol);
Handle(AIS_Shape) myNose = new AIS_Shape(NoseFace1);
myAISContext->Display(myNose,Standard_False);

I also tried using the BRepPrimAPI_MakeRevol class but it gives an Unhandled exception on the following line: aBuilder.MakeEdge(NoseEdge, NoseArc, Tol)

Regards
Nitin

Roman Lygin's picture

Nitin,
You need to eat elephant bit by bit. Now, when you are done with compilation you should learn what you did wrong to understand your initial error. Your run-time failure has nothing to do with compilation which is fine now.

Now regarding the run-time failure - you try to display a wrong face (NoseFace1) - it only has an underlying surface (Nose2) and has no bounding wire. To understand basic requirements to OCC model - you should read Modeling Data User's Guide and might want to check these series of blog posts - http://opencascade.blogspot.com/2009/02/topology-and-geometry-in-open-ca....

(Note also that your passed a zero direction into Geom_SurfaceOfRevolution!)

The easiest way for you will be to create a revolved surface with BRepPrimAPI_MakeRevol from the edge.

TopoDS_Edge anEdge = BRepBuilderAPI_MakeEdge (NoseArc);
TopoDS_Shape NoseShape = BRepPrimAPI_MakeRevol (anEdge, gp_Ax1 (gp_Pnt(0,0,0), gp_Dir(0,0,1)));
Handle(AIS_Shape) myNose = new AIS_Shape(NoseShape);
myAISContext->Display(myNose,Standard_False);

And never hesitate to use debugger to understand where your exception happens ;-).

HTH.
Roman

Nitin's picture

Hi Roman
Thanks for the reply.

Well it now gives me an exception in the afxtls.cpp file at the line: LeaveCriticalSection(&m_sect);
And since I need to revolve the arc around x-axis I changed the direction to gp_Dir(1,0,0). But then it gives me an exeption in winmdi.cpp at the following line: return ::DefMDIChildProc(m_hWnd, nMsg, wParam, lParam);

I think the problem is with making the arc. The arc I am trying to create is not a part of a circle. I just want to create an arc between two points. Maybe that is the problem because an exception is thrown in OCC_3dView when I try to display the arc.

I have attached a figure of an aircraft model. I am trying to build its nose. I need to create a a surface which covers the flat surface shown and goes upto the point shown, like a hemisphere. But the point is not coincident with the axis of the face.

Please give me a suggestion as to how I can build this type of geometry. Now I think that even revolving would not work because the point is not on the axis of the face.

Regards
Nitin

Attachments: