Beispiel #1
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)
Beispiel #2
0
 def __init__(self, shape):
     if not shape.IsNull():
         if not shape.ShapeType() == Shape.SHELL:
             raise TypeError('Shape is not a TopoDS_Shell.')
         if not isinstance(shape, TopoDS_Shell):
             shape = topods.Shell(shape)
     super(Shell, self).__init__(shape)
Beispiel #3
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
Beispiel #4
0
    def combine_faces(compshape, sew_tolerance):
        """
        Method to combine faces in a shell by adding connectivity and continuity
        :param compshape: TopoDS_Shape
        :param sew_tolerance: tolerance for sewing
        :return: Topo_Shell
        """

        offsew = BRepOffsetAPI_FindContigousEdges(sew_tolerance)
        sew = BRepBuilderAPI_Sewing(sew_tolerance)

        face_explorers = TopExp_Explorer(compshape, TopAbs_FACE)
        n_faces = 0
        # cycle on Faces
        while face_explorers.More():
            tface = topods.Face(face_explorers.Current())
            sew.Add(tface)
            offsew.Add(tface)
            n_faces += 1
            face_explorers.Next()

        offsew.Perform()
        offsew.Dump()
        sew.Perform()
        shell = sew.SewedShape()
        sew.Dump()

        shell = topods.Shell(shell)
        shell_fixer = ShapeFix_Shell()
        shell_fixer.FixFaceOrientation(shell)
        """
        if shell_fixer.Perform():
            print("{} shells fixed! ".format(shell_fixer.NbShells()))
        else:
            print "Shells not fixed! "

        new_shell = shell_fixer.Shell()

        if brepalgo_IsValid(new_shell):
            print "Shell valid! "
        else:
            print "Shell failed! "
        """
        return new_shell
Beispiel #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
Beispiel #6
0
 def Shell(self): return topods.Shell(self._shp)
 def Solid(self): return topods.Solid(self._shp)
def MakeSolidFromShell(shell):
    ms = BRepBuilderAPI_MakeSolid()
    ms.Add(topods.Shell(shell))
    solid = ms.Solid()
    return solid
Beispiel #8
0
    def parse_shape(self, filename):
        """
        Method to parse a Shape with multiple objects (1 compound = multi-shells
        and 1 shell = multi-faces)
        It returns a list of matrix with all the coordinates of control points
        of each Face and a second list with all the control points related to
        Edges of each Face.

        :param str filename: the input filename.

        :return: list of (mesh_points: `n_points`-by-3 matrix containing
        the coordinates of the control points of the Face (surface),
                 edge_points: it is a list of numpy.narray)
        :rtype: a list of shells

        """
        self.infile = filename
        self.shape = self.load_shape_from_file(filename)

        self.check_topology()

        # parse and get control points
        l_shells = []  # an empty list of shells
        n_shells = 0

        if self.check_topo == 0:

            shells_explorer = TopExp_Explorer(self.shape, TopAbs_SHELL)

            # cycle on shells
            while shells_explorer.More():
                topo_shell = topods.Shell(shells_explorer.Current())
                shell_faces_explorer = TopExp_Explorer(topo_shell, TopAbs_FACE)
                l_faces = []  # an empty list of faces per shell

                # cycle on faces
                while shell_faces_explorer.More():
                    topo_face = topods.Face(shell_faces_explorer.Current())
                    mesh_point, edge_point = self.parse_face(topo_face)
                    l_faces.append((mesh_point, edge_point))
                    shell_faces_explorer.Next()

                l_shells.append(l_faces)
                n_shells += 1
                shells_explorer.Next()

        else:
            # cycle only on faces
            shell_faces_explorer = TopExp_Explorer(self.shape, TopAbs_FACE)
            l_faces = []  # an empty list of faces per shell

            while shell_faces_explorer.More():
                topo_face = topods.Face(shell_faces_explorer.Current())
                mesh_point, edge_point = self.parse_face(topo_face)
                l_faces.append((mesh_point, edge_point))
                shell_faces_explorer.Next()

            l_shells.append(l_faces)
            n_shells += 1

        return l_shells
Beispiel #9
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()