pythonCascade Sample Problems

Triangulation

 

        self.Initialize()

        self.interactive_context.EraseAll(0,1)

 

        theBox = BRepPrimAPI_MakeBox(200,60,60).Shape()

        theSphere = BRepPrimAPI_MakeSphere(gp_Pnt(100,20,20),80).Shape()

        ShapeFused = BRepAlgoAPI_Fuse(theSphere,theBox).Shape()

        BRepMesh().Mesh(ShapeFused,1)

 

        aSection = AIS_Shape(ShapeFused)

 

        self.interactive_context.SetDisplayMode(aSection,1)

        self.interactive_context.SetMaterial(aSection,Graphic3d_NOM_GOLD,0)

        self.interactive_context.SetColor(aSection,Quantity_NOC_RED,0)

        self.interactive_context.SetTransparency(aSection,0.1,0)

        self.interactive_context.Display(aSection,1)

 

        builder = BRep_Builder()

        Comp = TopoDS_Compound()

        builder.MakeCompound(Comp)

       

 

        ex = TopExp_Explorer(ShapeFused,TopAbs_FACE)

        while ex.More():

            F = TopoDS().Face(ex.Current())

            L = TopLoc_Location()       

            facing = BRep_Tool().Triangulation(F,L)

            tab = facing.Nodes()

            tri = facing.Triangles()

            for trian  in tri:

                index1,index2,index3 = trian.Get()

                for j in range(1,4):

                    if j == 1:

                        M,N = index1-1,index2-1

                    elif j == 2:

                        N = index3 -1

                    else:

                        M = index2 - 1

                    ME = BRepBuilderAPI_MakeEdge(tab[M],tab[N])

                    if ME.IsDone():

                        builder.Add(Comp,ME.Edge())

 

            ex.Next()

 

        atriangulation = AIS_Shape(Comp)

        self.interactive_context.SetDisplayMode(atriangulation,1)

        self.interactive_context.SetColor(atriangulation,Quantity_NOC_RED,0)

        self.interactive_context.Display(atriangulation,1)

           

 

 

        self.view.FitAll(0.01,0)

        self.view.ZFitAll(0.01)

        self.view.Redraw()