Exemplo 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
Exemplo 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)
Exemplo n.º 3
0
    def make_solid(self):
        """Convert the current shape to a solid.

        Returns
        -------
        None

        """
        self.shape = BRepBuilderAPI_MakeSolid(self.shape).Solid()
Exemplo n.º 4
0
def _unify_solid(proto):
    mkSolid = BRepBuilderAPI_MakeSolid()
    explorer = TopExp_Explorer()

    explorer.Init(proto.Shape(), TopAbs_SHELL)
    while explorer.More():
        mkSolid.Add(_unify_shell(Shape(explorer.Current())).Shell())
        explorer.Next()

    mkSolid.Build()
    return Shape(mkSolid.Shape())
Exemplo n.º 5
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())
Exemplo n.º 6
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
Exemplo n.º 7
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
Exemplo n.º 8
0
def MakeSolidFromShell(shell):
    ms = BRepBuilderAPI_MakeSolid()
    ms.Add(topods.Shell(shell))
    solid = ms.Solid()
    return solid
Exemplo n.º 9
0
def make_solid(*args):
    sld = BRepBuilderAPI_MakeSolid(*args)
    with assert_isdone(sld, 'failed to produce solid'):
        result = sld.Solid()
        sld.Delete()
        return result
Exemplo n.º 10
0
    px = np.linspace(-1, 1, 100) * 150
    py = np.linspace(-1, 1, 200) * 150
    axis1 = gp_Ax3(gp_Pnt(0, 0, -5), gp_Dir(0.0, 0.05, 0.9))
    mesh1 = np.meshgrid(px, py)
    data1 = mesh1[0]**2 / 1000 + mesh1[1]**2 / 2000
    surf1, face1, shel1 = spl_face(*mesh1, data1, axis1)

    px = np.linspace(-1, 1, 100) * 150
    py = np.linspace(-1, 1, 200) * 150
    axis2 = gp_Ax3(gp_Pnt(0, 0, 5), gp_Dir(0.1, 0.05, 0.9))
    mesh2 = np.meshgrid(px, py)
    data2 = mesh2[0]**2 / 2000 - mesh2[1]**2 / 1000
    surf2, face2, shel2 = spl_face(*mesh2, data2, axis2)

    solid = BRepBuilderAPI_MakeSolid(shel1, shel2).Solid()
    surf_face1 = BRep_Tool.Surface(face1)
    surf_face2 = BRep_Tool.Surface(face2)
    intss = GeomAPI_IntSS(surf_face1, surf_face2, 0.1)
    print(intss.NbLines())
    intss_curv1 = intss.Line(1)

    obj = plotocc(touch=True)
    obj.show_axs_pln(axis1, scale=50, name="Axis1")
    obj.show_axs_pln(axis2, scale=50, name="Axis2")
    obj.display.DisplayShape(surf1, color="RED", transparency=0.9)
    obj.display.DisplayShape(surf2, color="BLUE", transparency=0.9)
    obj.display.DisplayShape(solid, color="GREEN", transparency=0.9)
    obj.display.DisplayShape(intss_curv1)
    obj.export_stp(solid)
    obj.export_stl(solid, linear_deflection=0.1, angular_deflection=0.1)
Exemplo n.º 11
0
      def getShape(self, pos, rotation) :
          import cadquery as cq
          #from OCC.Core.gp import gp_Ax2, gp_Pnt, gp_Dir
          from OCC.Core.BRepBuilderAPI import BRepBuilderAPI_MakePolygon
          from OCC.Core.BRepBuilderAPI import BRepBuilderAPI_MakeSolid
          from OCC.Core.BRepBuilderAPI import BRepBuilderAPI_Sewing
          from OCC.Core.BRepAlgoAPI import BRepAlgoAPI_Cut
          from OCC.Core.TopoDS import topods

          print("Get Shape gPolyhedra")
          x = pos[0]
          y = pos[1]
          z = pos[2]
          
          sewing = BRepBuilderAPI_Sewing()
          # Add top polygon
          print('top polygon')
          top = regPolygon(self.Num, self.Zplanes[0][1], \
                             self.Zplanes[0][2])
          maxR = self.Zplanes[0][1]
          height = self.Zplanes[0][2]
          sewing.Add(makeFace(top))
          n = len(self.Zplanes)
          for i in range(1,n) :
              bot = regPolygon(self.Num, self.Zplanes[i][1], \
                             self.Zplanes[i][2])
              if self.Zplanes[i][1] > maxR :
                 maxR = self.Zplanes[i][1] 
              height = height + self.Zplanes[i][2]   
              for i in range(0, self.Num) :
                  face = makeFace([top[i],top[i+1],bot[i+1],bot[i]])
                  sewing.Add(face)
              top = bot    
          # Add bottom polygon
          print('bottom polygon')
          sewing.Add(makeFace(bot))
          sewing.Perform()
          sewedShape = sewing.SewedShape()
          outer = BRepBuilderAPI_MakeSolid(topods.Shell(sewedShape))

          sewing = BRepBuilderAPI_Sewing()
          # Add top polygon
          print('top polygon')
          top = regPolygon(self.Num, self.Zplanes[0][0], \
                             self.Zplanes[0][2])
          sewing.Add(makeFace(top))
          n = len(self.Zplanes)
          for i in range(1,n) :
              bot = regPolygon(self.Num, self.Zplanes[i][0], \
                             self.Zplanes[i][2])
              for i in range(0, self.Num) :
                  face = makeFace([top[i],top[i+1],bot[i+1],bot[i]])
                  sewing.Add(face)
              top = bot    
          # Add bottom polygon
          print('bottom polygon')
          sewing.Add(makeFace(bot))
          sewing.Perform()
          sewedShape = sewing.SewedShape()
          inner = BRepBuilderAPI_MakeSolid(topods.Shell(sewedShape))
          poly  = BRepAlgoAPI_Cut(outer.Shape(), inner.Shape()).Shape()
          if self.Sector.completeRev() == False :
             print("Need to section")
             if self.Sector.less90() == True :
                print("Common")
                shape = self.Sector.makeCommon(maxR, height, poly) 
             else :
                print("Cut") 
                shape = self.Sector.makeCut(maxR, height, poly)
             if self.Sector.getStart() == 0 :
                return shape
             else :
                return self.Sector.rotate(shape)
          return poly.Shape()