# Make Face with Hole

Hello

I try to make face with hole.
But sometimes it miscalculated.

http://www.fisco21.com/img/OCC/20090213-1.jpg

The orientation of wire might have the cause of miscalculation,
so I tried to reverse the orientation of a hole and that lead to get the desired results.
But sometimes it still miscalculated in another data.

So, I program a simple code to examine the condition of the miscalculation. (OCC 6.3.0 VS6 WinXp)
The code is to create wire of square with a hole.
The squre with hole is rotated with 15 degrees each and call makeFaceWidthHole function.

void OnDebug_test2(Handle_AIS_InteractiveContext myAISContext)
{
static double xx[] = { -1, 1, 1, -1, -1};
static double yy[] = { -1, -1, 1, 1, -1};

TopoDS_Wire aOuter;
{
BRepBuilderAPI_MakePolygon MP;
for ( int i=0; i gp_Pnt aPnt( xx[i]*50, yy[i]*50+50, 0 );
}
MP.Close();
aOuter = MP;
}
TopoDS_Wire aInner;
{
BRepBuilderAPI_MakePolygon MP;
for ( int i=0; i gp_Pnt aPnt( xx[i]*25, yy[i]*25+50, 0 );
}
MP.Close();
aInner = MP;
}
for ( double th=0.0; th TopoDS_Shape aRotatedOuter, aRotatedInner;
{
gp_Trsf aTrsf;
aTrsf.SetRotation( gp::OX(), th * Standard_PI/180.0 );
aRotatedOuter = BRepBuilderAPI_Transform( aOuter, aTrsf, Standard_True );
aRotatedInner = BRepBuilderAPI_Transform( aInner, aTrsf, Standard_True );
}
makeFaceWithHole( myAISContext, TopoDS::Wire(aRotatedOuter), TopoDS::Wire(aRotatedInner) );
}
}

static makeFaceWithHole( Handle_AIS_InteractiveContext myAISContext, TopoDS_Wire tFrame, TopoDS_Wire tHole )
{
TopoDS_Face tFace = BRepBuilderAPI_MakeFace( tFrame );
BRepBuilderAPI_MakeFace MF( tFace );
if ( MF.IsDone()) {
Handle(AIS_Shape) aShape = new AIS_Shape(MF.Shape());
myAISContext->SetDisplayMode(aShape,1);
myAISContext->Display(aShape);
}
}

I paint the miscalculated plane with red.

http://www.fisco21.com/img/OCC/20090213-2.jpg

I am at a loss as it seems to randomly miscalculated.
Surprisingly the execution of this sample program at Vista c2d machine, has different results( miscalculated at different angles ).
It also goes different between debug and release occ dlls.
Any help will welcome.

According to the documentation, the way you are adding the other wire as a hole is correct. Since you are using planar surfaces, you could try creating a face from tHole and calculate its normal. Compare that normal with the one of tFrame. If they are opposite, extract the wire from the face created from tHole (could probably have a different orientation than it originally had) and add it to tFrame (you can use BRep_Builder here). If both normals are the same, do the same process, but reverse the wire before adding it to tFrame.

Let me know if that works reliably for you.

I tried Shape healing(ShapeFix_Shape) before display.

static makeFaceWithHole( Handle_AIS_InteractiveContext myAISContext, TopoDS_Wire tFrame, TopoDS_Wire tHole )
{
TopoDS_Face tFace = BRepBuilderAPI_MakeFace( tFrame );
BRepBuilderAPI_MakeFace MF( tFace );
if ( MF.IsDone()) {
Handle(ShapeFix_Shape) sfs = new ShapeFix_Shape;
sfs->Init ( MF.Shape() );
sfs->Perform();
Handle(AIS_Shape) aShape = new AIS_Shape(sfs->Shape());
myAISContext->Display(aShape);
}
}

and I finally get the desired resuls.
In pursuit of a cause is desirable well, but there is not much time.
So, I go to the next stage, projection to the sphere.

Thank you.

Hi Kazumasa,
I saw your OccViewer and I think it is intereting.
I'm using OccCoin3dViewer but I do not like its interface too much.
Where did you find yours?
Best regards, Frank.