Esempio n. 1
0
    def generate_solid(self):
        """
        Generate an assembled solid shaft using the BRepBuilderAPI_MakeSolid  
        algorithm. This method requires PythonOCC to be installed.

        :raises RuntimeError: if the assembling of the solid shaft is not 
            completed successfully
        :return: solid shaft
        :rtype: OCC.Core.TopoDS.TopoDS_Solid
        """
        ext = os.path.splitext(self.filename)[1][1:]
        if ext == 'stl':
            shaft_compound = read_stl_file(self.filename)
        elif ext == 'iges':
            iges_reader = IGESControl_Reader()
            iges_reader.ReadFile(self.filename)
            iges_reader.TransferRoots()
            shaft_compound = iges_reader.Shape()
        else:
            raise Exception('The shaft file is not in iges/stl formats')
        sewer = BRepBuilderAPI_Sewing(1e-2)
        sewer.Add(shaft_compound)
        sewer.Perform()
        result_sewed_shaft = sewer.SewedShape()
        shaft_solid_maker = BRepBuilderAPI_MakeSolid()
        shaft_solid_maker.Add(OCC.Core.TopoDS.topods_Shell(result_sewed_shaft))
        if not shaft_solid_maker.IsDone():
            raise RuntimeError('Unsuccessful assembling of solid shaft')
        shaft_solid = shaft_solid_maker.Solid()
        return shaft_solid
Esempio n. 2
0
def extrusion_to_solid(extrusion, name):
    from OCC.Core.BRepBuilderAPI import BRepBuilderAPI_Sewing, BRepBuilderAPI_MakeSolid
    from OCC.Core.TopoDS import topods
    from OCC.Core.BRepGProp import brepgprop_VolumeProperties
    from OCC.Core.GProp import GProp_GProps
    from OCCUtils.Topology import Topo
    d = extrusion_to_ruled_surfaces(extrusion, cap=True)
    sew = BRepBuilderAPI_Sewing()

    make_solid = BRepBuilderAPI_MakeSolid()
    faces = {}
    for k in d.keys():
        faces[name + '_' + k] = d[k]
        sew.Add(d[k].Shape())
    sew.Perform()
    shell = sew.SewedShape()
    make_solid.Add(topods.Shell(shell))
    gp = GProp_GProps()

    #make_solid.Add(shell)
    solid = make_solid.Solid()
    brepgprop_VolumeProperties(shell, gp)
    print gp.Mass()

    return Part(name, faces, solid)
Esempio n. 3
0
def _make_solid(shells):
    if not isinstance(shells, (list, tuple)):
        shells = [shells]

    algo = BRepBuilderAPI_MakeSolid()

    for s in shells:
        algo.Add(s.Shell())

    fixer = ShapeFix_Solid(algo.Solid())
    fixer.Perform()
    return Shape(fixer.Solid())
Esempio n. 4
0
def named_cartesian_box(xmin=-10.,
                        xmax=10.,
                        ymin=-10.,
                        ymax=10.,
                        zmin=-10.,
                        zmax=10.):
    from youbastard.geometry.Polyline3D import Polyline3D
    from OCC.Core.BRepBuilderAPI import BRepBuilderAPI_Sewing, BRepBuilderAPI_MakeSolid
    from OCC.Core.TopoDS import topods
    from OCC.Core.BRepPrimAPI import BRepPrimAPI_MakeBox
    p0 = Point((xmin, ymin, zmin))
    p1 = Point((xmin, ymax, zmin))
    p2 = Point((xmax, ymax, zmin))
    p3 = Point((xmax, ymin, zmin))
    p4 = Point((xmin, ymin, zmax))
    p5 = Point((xmin, ymax, zmax))
    p6 = Point((xmax, ymax, zmax))
    p7 = Point((xmax, ymin, zmax))

    pol_Xmin = Polyline3D([p0, p1, p5, p4, p0][::-1])
    pol_Xmax = Polyline3D([p2, p3, p7, p6, p2][::-1])
    pol_Ymin = Polyline3D([p1, p2, p6, p5, p1][::-1])
    pol_Ymax = Polyline3D([p0, p4, p7, p3, p0][::-1])
    pol_Zmin = Polyline3D([p0, p3, p2, p1, p0][::-1])
    pol_Zmax = Polyline3D([p5, p6, p7, p4, p5][::-1])

    dicoface = {
        'Xmin': face_polyline3d(pol_Xmin).Shape(),
        'Xmax': face_polyline3d(pol_Xmax).Shape(),
        'Ymin': face_polyline3d(pol_Ymin).Shape(),
        'Ymax': face_polyline3d(pol_Ymax).Shape(),
        'Zmin': face_polyline3d(pol_Zmin).Shape(),
        'Zmax': face_polyline3d(pol_Zmax).Shape()
    }
    sew = BRepBuilderAPI_Sewing()

    make_solid = BRepBuilderAPI_MakeSolid()
    for k in dicoface.keys():
        sew.Add(dicoface[k])
    sew.Perform()
    shell = sew.SewedShape()
    make_solid.Add(topods.Shell(shell))
    box = make_solid.Solid()
    box = BRepPrimAPI_MakeBox(gp_Pnt(xmin, ymin, zmin),
                              gp_Pnt(xmax, ymax, zmax))
    return box, dicoface
Esempio n. 5
0
def reconstruct_object(array):
    from OCC.Core.BRepBuilderAPI import BRepBuilderAPI_Sewing, BRepBuilderAPI_MakeSolid
    from OCC.Core.BRepGProp import brepgprop_VolumeProperties
    from OCC.Core.GProp import GProp_GProps
    from OCC.Core.TopoDS import topods
    obj = BRepBuilderAPI_Sewing()
    for i, si in enumerate(array):
        obj.Add(si)
    obj.Perform()
    shell = obj.SewedShape()
    make_solid = BRepBuilderAPI_MakeSolid()
    make_solid.Add(topods.Shell(shell))
    gp = GProp_GProps()

    #make_solid.Add(shell)
    solid = make_solid.Solid()
    brepgprop_VolumeProperties(shell, gp)
    print 'RECONSTRUCTED SOLID VOLUME :'
    print gp.Mass()
    return solid
Esempio n. 6
0
def MakeSolidFromShell(shell):
    ms = BRepBuilderAPI_MakeSolid()
    ms.Add(topods.Shell(shell))
    solid = ms.Solid()
    return solid
Esempio n. 7
0
def make_solid(*args):
    sld = BRepBuilderAPI_MakeSolid(*args)
    with assert_isdone(sld, 'failed to produce solid'):
        result = sld.Solid()
        sld.Delete()
        return result