示例#1
0
def drillWithHoles(shape):
    "returns a shape with a bunch of spheres removed from it"
    box = Bnd.Bnd_Box()
    b = BRepBndLib.BRepBndLib()
    b.Add(shape, box)

    cShape = shape
    (xMin, yMin, zMin, xMax, yMax, zMax) = box.Get()

    d = 0.05 * ((xMax - xMin))
    di = 4.0 * d
    c = 0

    #drill holes in a rectangular grid
    for x in frange6(xMin, xMax, di):
        for y in frange6(yMin, yMax, di):
            for z in frange6(zMin, zMax, di):
                c += 1
                print "Inter %d " % c
                #make a sphere
                center = gp.gp_Pnt(x, y, z)
                hole = BRepPrimAPI.BRepPrimAPI_MakeSphere(center, d).Shape()
                cut = BRepAlgoAPI.BRepAlgoAPI_Cut(cShape, hole)
                cut.SetOperation(3)
                #3 is cut21
                tmp = cut.Shape()
                #store the newly cut shape
                if cut.ErrorStatus() != 0:
                    print "Error %d cutting" % cut.ErrorStatus()
                else:
                    print "Success!"
                    cShape = tmp
    return cShape
示例#2
0
    def getBoundingBox(self):
        '''
    Returns Bounding Box of this solid

    The bounds are returns in an array [xmin, ymin, zmin, xmax, ymax, zmax]
    '''
        box = Bnd.Bnd_Box()
        b = BRepBndLib.BRepBndLib()
        b.Add(self.shape, box)
        return box.Get()
示例#3
0
def boundingBox(shapeList):
    "get a bounding box for a list of shapes"
    box = Bnd.Bnd_Box()
    b = BRepBndLib.BRepBndLib()

    for s in shapeList:
        b.Add(s, box)

    bounds = box.Get()
    return bounds
示例#4
0
    def __init__(self, shape):
        self.shape = shape

        box = Bnd.Bnd_Box()
        b = BRepBndLib.BRepBndLib()
        b.Add(shape, box)

        self.bounds = box.Get()
        self.xMin = self.bounds[0]
        self.xMax = self.bounds[3]
        self.xDim = abs(self.xMax - self.xMin)
        self.yMin = self.bounds[1]
        self.yMax = self.bounds[4]
        self.yDim = abs(self.yMax - self.yMin)
        self.zMin = self.bounds[2]
        self.zMax = self.bounds[5]
        self.zDim = abs(self.zMax - self.zMin)
示例#5
0
    def getBounds(self):
        "Get the bounds of all the faces"
        t = Timer()
        box = Bnd.Bnd_Box()
        b = BRepBndLib.BRepBndLib()

        for f in hSeqIterator(s.faces):
            b.Add(f, box)

        bounds = box.Get()
        xMin = bounds[0]
        xMax = bounds[3]
        yMin = bounds[1]
        yMax = bounds[4]
        zMin = bounds[2]
        zMax = bounds[5]
        return [xMin, xMax, yMin, yMax, zMin, zMax]
示例#6
0
    def computeBounds(self):
        "Get the bounds of all the faces"
        if self.bounds == None:
            box = Bnd.Bnd_Box()
            b = BRepBndLib.BRepBndLib()

            for f in OCCUtil.hSeqIterator(s.faces):
                b.Add(f, box)

            bounds = box.Get()
            xMin = bounds[0]
            xMax = bounds[3]
            yMin = bounds[1]
            yMax = bounds[4]
            zMin = bounds[2]
            zMax = bounds[5]
            self.bounds = [xMin, xMax, yMin, yMax, zMin, zMax]
        return self.bounds
示例#7
0
def drillWithHolesFaster(shape):
    "returns a shape with a bunch of spheres removed from it"
    box = Bnd.Bnd_Box()
    b = BRepBndLib.BRepBndLib()
    b.Add(shape, box)

    (xMin, yMin, zMin, xMax, yMax, zMax) = box.Get()

    d = 0.05 * ((xMax - xMin))
    di = 3.0 * d
    vec = gp.gp_Vec(gp.gp_Pnt(0, 0, 0), gp.gp_Pnt(0, 0, d))
    cp = None
    compound = TopoDS.TopoDS_Compound()
    builder = BRep.BRep_Builder()
    builder.MakeCompound(compound)
    #drill holes in a rectangular grid
    for x in frange6(xMin, xMax, di):
        for y in frange6(yMin, yMax, di):
            for z in frange6(zMin, zMax, di):
                #make a sphere
                center = gp.gp_Pnt(x, y, z)
                hole = BRepPrimAPI.BRepPrimAPI_MakeSphere(center, d).Shape()
                #lets see if a square hole is faster!
                #w = squareWire(center,d );
                #hb = BRepPrimAPI.BRepPrimAPI_MakePrism(w,vec,False,True);
                #hb.Build();
                #hole = hb.Shape();
                builder.Add(compound, hole)

    display.DisplayShape(compound)
    q = time.clock()
    cut = BRepAlgoAPI.BRepAlgoAPI_Cut(shape, compound)
    if cut.ErrorStatus() == 0:
        print "Cut Took %0.3f sec." % (time.clock() - q)
        return cut.Shape()
    else:
        print "Error Cutting: %d" % cut.ErrorStatus()
        return shape
示例#8
0
def boundingBoxForCurve(curve):
    box = Bnd.Bnd_Box2d()
    BndLib.BndLib_Add2dCurve().Add(Geom2dAdaptor.Geom2dAdaptor_Curve(curve),
                                   0.001, box)
    return box
示例#9
0
def computePixelGrid(face, resolution=0.1):
    """
	   makes a pixel grid of a face at the requested resolution."
		A dictionary is used to store the values.
	"""
    box = Bnd.Bnd_Box()
    b = BRepBndLib.BRepBndLib()
    b.Add(face, box)
    TOLERANCE = 5
    bounds = box.Get()
    xMin = bounds[0]
    xMax = bounds[3]
    xDim = abs(xMax - xMin)
    yMin = bounds[1]
    yMax = bounds[4]
    yDim = abs(yMax - yMin)
    zMin = bounds[2]
    pixelTable = {}

    for y in Wrappers.frange6(yMin, yMax, resolution):
        #create a horizontal scan line
        edge = Wrappers.edgeFromTwoPoints(gp.gp_Pnt(xMin - TOLERANCE, y, zMin),
                                          gp.gp_Pnt(xMax + TOLERANCE, y, zMin))

        #get list of wires from the face
        #TODO:// this should be encapsulated by a face abstraction
        wires = []
        ow = brt.OuterWire(face)
        wires.append(ow)
        for w in Topo(face).wires():
            if not w.IsSame(ow):
                wires.append(w)

        #compute intersection points with each wire
        #this is a hack because i know how to make edges from lines
        #but really, it would be better to do 2d here and use
        #Geom2dAPI_InterCurveCurve
        xIntersections = []
        for w in wires:
            #display.DisplayShape(w);
            brp = BRepExtrema.BRepExtrema_DistShapeShape()
            #display.DisplayShape(edge);
            brp.LoadS1(w)
            brp.LoadS2(edge)

            if brp.Perform() and brp.Value() < 0.01:
                for k in range(1, brp.NbSolution() + 1):
                    if brp.SupportTypeShape1(
                            k) == BRepExtrema.BRepExtrema_IsOnEdge:
                        xIntersections.append(brp.PointOnShape1(k).X())

        if len(xIntersections) == 0:
            print "No intersection found."
            continue
        #else:
        #print "there are %d intersections " % len(xIntersections);
        #sort intersection points by x value
        xIntersections.sort()

        #fill pixel table with values on surface based on scanlines
        #TODO: for now ignore horizontals and edge vertices, this is just a test
        #better to use a generator here too
        #also need to implement edge table of scanline fill
        if (len(xIntersections) % 2 == 0):
            i = 0
            inside = False
            cx = xMin

            #print xIntersections;
            while i < len(xIntersections):
                cint = xIntersections[i]
                if inside:
                    while cx < cint:
                        key = (cx, y)
                        pixelTable[key] = 1
                        #print cx;
                        cx += resolution
                else:
                    while cx < cint:
                        cx += resolution
                        #print cx;
                        continue

                i += 1
                inside = not inside
        else:
            print "Odd number of intersections encountred."

    #displayPixelGrid(pixelTable);
    return pixelTable