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

BRepAlgoAPI_Cut Problems

chenyao's picture
Forums: 

Hi everyone,

I'm trying to use BRepAlgoAPI_Cut but there is something dosent work. I'm trying to make a simple cube with an hole, a cylinder one.

Please take e look to the following code :

Create a cube:
void CSampleViewer3dDoc::OnBaseBox()
{
CNewBaseBoxDlg Dlg;
if(Dlg.DoModal()!=IDOK) return;
BRepPrimAPI_MakeBox B(gp_Pnt(Dlg.m_x, Dlg.m_y, Dlg.m_z), Dlg.m_w, Dlg.m_l, Dlg.m_h);
aBaseBox = new AIS_Shape(B.Shape());
myAISContext->SetColor(aBaseBox,Quantity_NOC_MATRABLUE);
myAISContext->SetMaterial(aBaseBox,Graphic3d_NOM_PLASTIC);
myAISContext->SetDisplayMode(aBaseBox,1);
myAISContext->Display(aBaseBox);

Fit();
}

Create a cylinder and cut
void CSampleViewer3dDoc::OnShapeHole()
{
CNewBaseCylinderDlg Dlg;
if(Dlg.DoModal()!=IDOK) return;

BRepPrimAPI_MakeCylinder B(((Dlg.m_x, Dlg.m_y, Dlg.m_z),(Dlg.m_x1, Dlg.m_y1, Dlg.m_z1)), Dlg.m_h, Dlg.m_r);
Handle(AIS_Shape) aHoleCyl = new AIS_Shape(B.Shape());
myAISContext->SetDisplayMode(aHoleCyl,1);
myAISContext->SetColor(aHoleCyl,Quantity_NOC_MATRABLUE);
myAISContext->SetMaterial(aHoleCyl,Graphic3d_NOM_PLASTIC);
myAISContext->SetDisplayMode(aHoleCyl,1);
myAISContext->Display(aHoleCyl);

Fit();
Sleep(500);

TopoDS_Shape Cut = BRepAlgoAPI_Cut(aBaseBox,aHoleCyl);

Handle (AIS_Shape) ais18 = new AIS_Shape(Cut);
myAISContext->SetColor(ais18,Quantity_NOC_CORAL2);
myAISContext->SetMaterial(ais18,Graphic3d_NOM_PLASTIC);
myAISContext->Display(ais18);

Fit()
}

And there is an error:

error C2665: 'BRepAlgoAPI_Cut::BRepAlgoAPI_Cut' : none of the 3 overloads could convert all the argument types

Appreciate for your help.

heXus's picture

Error in this: "TopoDS_Shape Cut = BRepAlgoAPI_Cut(aBaseBox,aHoleCyl);"

"aBaseBox" and "aHoleCyl" is "AIS_Shape", but must be a "TopoDS_Shape".
You must use yors "B" from "BRepPrimAPI_MakeBox" and "BRepPrimAPI_MakeCylinder".

Sample:

BRepPrimAPI_MakeBox myBox(gp_Pnt(Dlg.m_x, Dlg.m_y, Dlg.m_z), Dlg.m_w, Dlg.m_l, Dlg.m_h);
BRepPrimAPI_MakeCylinder myCyl(((Dlg.m_x, Dlg.m_y, Dlg.m_z),(Dlg.m_x1, Dlg.m_y1, Dlg.m_z1)), Dlg.m_h, Dlg.m_r);

TopoDS_Shape Cut = BRepAlgoAPI_Cut(myBox, myCyl);

chenyao's picture

Appreciate for your advise. Unluckly, there is the same error message when I rebuild it.
Attached is the .cpp file.

Attachments: 
heXus's picture

I do not compile your file. It's big and may contain more than one error with Cut operation :)

So, I wrote a working sample for you. Try this:
////////////////
// vars
Standard_Real cylRadius = 15.;
Standard_Real cylH = 150.;

Standard_Real boxL = 100.;
Standard_Real boxW = 80.;
Standard_Real boxH = 50.;

TopoDS_Shape resultBox;

// make Box
BRepPrimAPI_MakeBox myBox( gp_Pnt( 0, 0, 0 ), boxL, boxW, boxH );

// make axis of direction for cylinder
gp_Ax2 cylAx2(gp_Pnt( 50, 50, 0 ), gp_Dir( gp_Vec( gp_Pnt(0,0,0), gp_Pnt(0,0,100) ) ) );

// make cylinder
BRepPrimAPI_MakeCylinder myCyl( cylAx2, cylRadius, cylH );

// make Cut operation and get result
resultBox = BRepAlgoAPI_Cut( myBox, myCyl.Shape() );

// show myBox
Handle(AIS_Shape) myBoxAIS = new AIS_Shape( myBox );
myAISContext->SetColor( myBoxAIS, Quantity_NOC_RED );
myAISContext->SetMaterial( myBoxAIS, Graphic3d_NOM_SHINY_PLASTIC );
myAISContext->SetDisplayMode( myBoxAIS, AIS_Shaded );
myAISContext->SetCurrentObject( myBoxAIS, Standard_True);
myAISContext->Display( myBoxAIS );

// wait
Sleep(1500);

// show myCyl
Handle(AIS_Shape) myCylAIS = new AIS_Shape( myCyl );
myAISContext->SetColor( myCylAIS, Quantity_NOC_GREEN );
myAISContext->SetMaterial( myCylAIS, Graphic3d_NOM_SHINY_PLASTIC );
myAISContext->SetDisplayMode( myCylAIS, AIS_Shaded );
myAISContext->SetCurrentObject( myCylAIS, Standard_True);
myAISContext->Display( myCylAIS );

// wait
Sleep(1500);

// delete objects
myAISContext->Erase( myBoxAIS );
myAISContext->Erase( myCylAIS );

// show result of Cut
Handle(AIS_Shape) resultBoxAIS = new AIS_Shape( resultBox );
myAISContext->SetColor( resultBoxAIS, Quantity_NOC_MATRABLUE );
myAISContext->SetMaterial( resultBoxAIS, Graphic3d_NOM_SHINY_PLASTIC );
myAISContext->SetDisplayMode( resultBoxAIS, AIS_Shaded );
myAISContext->SetCurrentObject( resultBoxAIS, Standard_True);
myAISContext->Display( resultBoxAIS );

// THE END

////////////////

chenyao's picture

Thanks for your kindly help. My programe's condition is creating the box and cylinder in two functions, and cut function is in the made cylinder function; consider that the BRepAlgoAPI_Cut could not identify the handle box,so I define the handle of the box. I don't know whether it is available or not.

heXus's picture

If you want use 2 functions, you must define "TopoDS_Shape myBox" in global section.
For example in "*.h" file:

....
private:
TopoDS_Shape myBox;
....

And then use it in your functions. Or, you may use function which returns a TopoDS_Shape and use this function in other functions. Example:

TopoDS_Shape MyClass::getMyBox()
{
...
TopoDS_Shape box = BRepPrimAPI_MakeBox(gp_Pnt(Dlg.m_x, Dlg.m_y, Dlg.m_z), Dlg.m_w, Dlg.m_l, Dlg.m_h);

return box;
}

void MyClass::someFunction()
{
...
resultBox = BRepAlgoAPI_Cut( getMyBox(), myCyl.Shape() );

}

chenyao's picture

sorry to reply too late. I tried your method.But there are errors on defined "TopoDS_Shape MyClass::getMyBox()",the error is :
overloaded function differs only by return type from 'void CSampleViewer3dDoc::OnBaseBox(void)

I think the problem can be simplied as :how BRepAlgoAPI_Cut can transfer the box which in getMyBox()?

heXus's picture

Did you rename "MyClass" to your class's name like "CSampleViewer3dDoc"?
You make some errors in class construction. Please read chapter "Object Oriented Programming" on http://www.cplusplus.com/doc/tutorial/

chenyao's picture

Yeah, I'm sure.But there is an error:
'TopoDS_Shape CSampleViewer3dDoc::OnBaseBox(void)' : overloaded function differs only by return type from 'void CSampleViewer3dDoc::OnBaseBox(void)'
May I get your msn and have a chat online? My msn:chenyao3505@hotmail.com
Appreciate for your help.

heXus's picture

I don't have msn. You can contact with me by using Jabber, ICQ, or Skype.
Jabber: heXus at jabber dot org
ICQ: 2 66 66 94 16
Skype name: heXus® //(symbol "®" required)

heXus's picture

Also check your "*.h" file for definition of "OnBaseBox(void)" function. You must have in class "CSampleViewer3dDoc" this definition:

// in includes
#include

// in your "*.h" file where class's functions is.
TopoDS_Shape OnBaseBox(void);

I think, error happens because you have definition like this:

void OnBaseBox(void);

but must be "TopoDS_Shape OnBaseBox(void);".

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.