Ejemplo n.º 1
0
def makeOffsetTestWire():
    "creates difficult test cases for offsetting"
    p1 = OCCUtil.pnt(11.0, 0)
    p2 = OCCUtil.pnt(7.0, 8.0)
    p3 = OCCUtil.pnt(7.0, 12.0)
    p4 = OCCUtil.pnt(17.0, 22.0)
    p5 = OCCUtil.pnt(0.0, 22.0)
    p6 = OCCUtil.pnt(3.0, 17.0)
    p7 = OCCUtil.pnt(4.0, 8.0)
    c1 = OCCUtil.pnt(10.0, 18.5)
    c2 = OCCUtil.pnt(6.0, 3.0)

    edges = []
    edges.append(OCCUtil.edgeFromTwoPoints(p1, p2))
    edges.append(OCCUtil.edgeFromTwoPoints(p2, p3))

    circle = GC.GC_MakeArcOfCircle(p3, c1, p4)
    #circle through 3 points
    e2 = BRepBuilderAPI.BRepBuilderAPI_MakeEdge(circle.Value()).Edge()
    edges.append(e2)

    edges.append(OCCUtil.edgeFromTwoPoints(p4, p5))
    edges.append(OCCUtil.edgeFromTwoPoints(p5, p6))
    edges.append(OCCUtil.edgeFromTwoPoints(p6, p7))

    circle = GC.GC_MakeArcOfCircle(p1, c2, p7)
    #circle through 3 points
    e3 = BRepBuilderAPI.BRepBuilderAPI_MakeEdge(circle.Value()).Edge()
    edges.append(e3)

    return OCCUtil.wireFromEdges(edges)
Ejemplo n.º 2
0
def makeOffsetTestWire():
    "creates difficult test cases for offsetting"
    p1 = OCCUtil.pnt(11.0,0);
    p2 = OCCUtil.pnt(7.0,8.0);
    p3 = OCCUtil.pnt(7.0,12.0);
    p4 = OCCUtil.pnt(17.0,22.0);
    p5 = OCCUtil.pnt(0.0,22.0);
    p6 = OCCUtil.pnt(3.0,17.0);
    p7 = OCCUtil.pnt(4.0,8.0 );
    c1 = OCCUtil.pnt(10.0,18.5);
    c2 = OCCUtil.pnt(6.0,3.0);
    
    edges = [];
    edges.append( OCCUtil.edgeFromTwoPoints( p1, p2 ));
    edges.append( OCCUtil.edgeFromTwoPoints( p2, p3 ));
    
    circle = GC.GC_MakeArcOfCircle(p3, c1, p4); #circle through 3 points
    e2 = BRepBuilderAPI.BRepBuilderAPI_MakeEdge(circle.Value()).Edge();
    edges.append(e2);
    
    edges.append( OCCUtil.edgeFromTwoPoints( p4, p5 ));
    edges.append( OCCUtil.edgeFromTwoPoints( p5, p6 ));
    edges.append( OCCUtil.edgeFromTwoPoints( p6, p7 ));

    circle = GC.GC_MakeArcOfCircle(p1, c2, p7 ); #circle through 3 points
    e3 = BRepBuilderAPI.BRepBuilderAPI_MakeEdge(circle.Value() ).Edge();
    edges.append(e3);

    return OCCUtil.wireFromEdges(edges);
Ejemplo n.º 3
0
def testSplitWire2():
	"intersections on different edges. one edge completely inside"
	
	e1 = OCCUtil.edgeFromTwoPoints(gp.gp_Pnt(0,0,0),gp.gp_Pnt(2,0,0));
	e2 = OCCUtil.edgeFromTwoPoints(gp.gp_Pnt(2,0,0),gp.gp_Pnt(5,0,0));
	e3 = OCCUtil.edgeFromTwoPoints(gp.gp_Pnt(5,0,0),gp.gp_Pnt(6,0,0));
	
	
	#trick here. after building a wire, the edges change identity.
	#evidently, BRepBuilder_MakeWire makes copies of the underliying edges.
	
	w = OCCUtil.wireFromEdges([e1,e2,e3]);
	ee = Wrappers.Wire(w).edgesAsList();
	#print "Original Edges: %d %d %d " % ( ee[0].__hash__(),ee[1].__hash__(),ee[2].__hash__());
	p1 = PointOnAnEdge(ee[0],1.0,gp.gp_Pnt(1.0,0,0));
	p2 = PointOnAnEdge(ee[2],0.5,gp.gp_Pnt(5.0,0,0));
	
	
	ee = splitWire(w,[p2,p1]);
	
	assert len(ee) == 1;
	
	length = 0;
	for e in ee[0]:
		ew = Wrappers.Edge(e);
		length += ew.distanceBetweenEnds();
	#print "length=%0.3f" % length;
	assert length == 4.5;
Ejemplo n.º 4
0
def makeHeartWire():
    "make a heart wire"
    e1 = OCCUtil.edgeFromTwoPoints(gp.gp_Pnt(0,0,0), gp.gp_Pnt(4.0,4.0,0));
    circle = gp.gp_Circ(gp.gp_Ax2(gp.gp_Pnt(2,4,0),gp.gp().DZ()),2);
    e2 = BRepBuilderAPI.BRepBuilderAPI_MakeEdge(circle, gp.gp_Pnt(4,4,0),gp.gp_Pnt(0,4,0)).Edge();
    circle = gp.gp_Circ(gp.gp_Ax2(gp.gp_Pnt(-2,4,0),gp.gp().DZ()),2);
    e3 = BRepBuilderAPI.BRepBuilderAPI_MakeEdge(circle, gp.gp_Pnt(0,4,0),gp.gp_Pnt(-4,4,0)).Edge();
    e4 = OCCUtil.edgeFromTwoPoints(gp.gp_Pnt(-4,4,0), gp.gp_Pnt(0,0,0));
    return OCCUtil.wireFromEdges([e1,e2,e3,e4]);
Ejemplo n.º 5
0
def makeHeartWire():
    "make a heart wire"
    e1 = OCCUtil.edgeFromTwoPoints(gp.gp_Pnt(0, 0, 0), gp.gp_Pnt(4.0, 4.0, 0))
    circle = gp.gp_Circ(gp.gp_Ax2(gp.gp_Pnt(2, 4, 0),
                                  gp.gp().DZ()), 2)
    e2 = BRepBuilderAPI.BRepBuilderAPI_MakeEdge(circle, gp.gp_Pnt(4, 4, 0),
                                                gp.gp_Pnt(0, 4, 0)).Edge()
    circle = gp.gp_Circ(gp.gp_Ax2(gp.gp_Pnt(-2, 4, 0),
                                  gp.gp().DZ()), 2)
    e3 = BRepBuilderAPI.BRepBuilderAPI_MakeEdge(circle, gp.gp_Pnt(0, 4, 0),
                                                gp.gp_Pnt(-4, 4, 0)).Edge()
    e4 = OCCUtil.edgeFromTwoPoints(gp.gp_Pnt(-4, 4, 0), gp.gp_Pnt(0, 0, 0))
    return OCCUtil.wireFromEdges([e1, e2, e3, e4])
Ejemplo n.º 6
0
	def _compute(self):
		(p1,p,p2) = (self.p1,self.closestParam, self.p2); #p1 < p < p2
		
		#i think this works well for small distance. not as well if d is large.
	
		if (p - p1) < (2.0)*self.distanceFromStartPoint:
			#TODO: this code is nearly same as the branch below but with p1 and p2 swapped,
			#connect to start vertex
			self.connectingPoint = self.edgeStart;
			self.connectingParm = p1;
			
			#compute shortened edge
			e1 = OCCUtil.edgeFromTwoPointsOnCurve(self.handleCurve,p1+self.trackWidth,p2);
			self.otherEdges = [e1];
			
			#enter the wire by connecting start to vertex directly			
			self.connectingEdges = [ OCCUtil.edgeFromTwoPoints(self.startPoint,self.connectingPoint) ];
			
		elif (p2 - p )< (2.0)*self.distanceFromStartPoint:
			#connect to end vertex
			self.connectingPoint = self.edgeEnd;
			self.connectingParm = p2;
			
			#compute shortened edge
			e1 = OCCUtil.edgeFromTwoPointsOnCurve(self.handleCurve,p1,p2-self.trackWidth);
			self.otherEdges = [e1];
			
			#enter the wire by connecting start to vertex directly			
			self.connectingEdges = [ OCCUtil.edgeFromTwoPoints(self.startPoint,self.connectingPoint) ];			
		else:
			#connect to middle of the edge
			self.connectingEdges = [];
			firstEdge = None;
			#which end is closer?
			if (p - p1) > (p2 - p ): #p2 is closer 
				pTarget = p + (2.0)*self.distanceFromStartPoint;
				pEnd = pTarget - self.trackWidth;
				secondEdge = OCCUtil.edgeFromTwoPointsOnCurve(self.handleCurve,pTarget,p2);
				self.otherEdges = [OCCUtil.edgeFromTwoPointsOnCurve(self.handleCurve,p1,pEnd) ];
			else: #p1 is closer
				pTarget = p - (2.0)*self.distanceFromStartPoint;
				pEnd = pTarget + self.trackWidth;
				secondEdge = OCCUtil.edgeFromTwoPointsOnCurve(self.handleCurve,p1,pTarget);
				self.otherEdges = [OCCUtil.edgeFromTwoPointsOnCurve(self.handleCurve,pEnd,p2) ];
				
			self.connectingParam = pTarget;
			self.connectingPoint = self.curve.Value(pTarget);
			self.connectingEdges.append( OCCUtil.edgeFromTwoPoints(self.startPoint, self.connectingPoint));
			self.connectingEdges.append(secondEdge);
Ejemplo n.º 7
0
def makeWireFromPointList(points):
    
    edges = [];
    for (p,q) in Util.ntuples(points,2,True):
        print p,q
        edges.append(OCCUtil.edgeFromTwoPoints(OCCUtil.pnt(p[0],p[1]),OCCUtil.pnt(q[0],q[1])));
    return OCCUtil.wireFromEdges(edges);
Ejemplo n.º 8
0
def testSplitWire1():
	"""
		Test split wire function. there are two main cases:
		wires with intersection on different edges,
		and a wire with a single edge split in many places
	"""
		
	#case 1: a single edge with lots of intersections along its length
	e  = OCCUtil.edgeFromTwoPoints( gp.gp_Pnt(0,0,0),gp.gp_Pnt(5,0,0));
	w = OCCUtil.wireFromEdges([e]);
	
	#out of order on purpose
	p1 = PointOnAnEdge(e,1.0,gp.gp_Pnt(1.0,0,0));
	p3 = PointOnAnEdge(e,3.0,gp.gp_Pnt(3.0,0,0));
	p2 = PointOnAnEdge(e,2.0,gp.gp_Pnt(2.0,0,0));	
	p4 = PointOnAnEdge(e,4.0,gp.gp_Pnt(4.0,0,0));
	ee = splitWire(w,[p1,p3,p2,p4] );

	assert len(ee) ==  2;
	length = 0;
	for e in ee:
		ew = Wrappers.Edge(e[0]);
		length += ew.distanceBetweenEnds();

	assert length == 2.0;
Ejemplo n.º 9
0
def makeWireFromPointList(points):

    edges = []
    for (p, q) in Util.ntuples(points, 2, True):
        print p, q
        edges.append(
            OCCUtil.edgeFromTwoPoints(OCCUtil.pnt(p[0], p[1]),
                                      OCCUtil.pnt(q[0], q[1])))
    return OCCUtil.wireFromEdges(edges)
Ejemplo n.º 10
0
    def makePeriodic(self, center, positive=1.0):
        """
			center is the center of the first hex, as an (x,y,z) tuple.
			positive is 1 for the upper portion, -1 for the lower portion
			
			makes the upper part of a periodic hex pattern.
			
			Note that the upper and lower flats are adjusted
			for line width, so that they can be stacked and allow
			double-drawing of the horizontal flats. this offset is controlled by
			the linewidth parameter.
			the points are numbered below
			
			    (2)  (3)
			     /-----\
			____/   +   \_____
		   (0) (1)      (4)   (5)
		"""
        cX = center[0]
        cY = center[1]
        cZ = center[2]
        (XA, YA) = self.lineWidthAdjust()
        baselineY = (cY + YA) * positive
        topY = (cY + (self.width / 2.0 - YA)) * positive

        p0 = gp.gp_Pnt(cX - self.cartesianSpacing()[0], baselineY, cZ)
        p1 = gp.gp_Pnt(cX - self.centerToCorner() + XA, baselineY, cZ)
        p2 = gp.gp_Pnt(cX - self.halfAflat() - XA, topY, cZ)
        p3 = gp.gp_Pnt(cX + self.halfAflat() + XA, topY, cZ)
        p4 = gp.gp_Pnt(cX + self.centerToCorner() - XA, baselineY, cZ)
        p5 = gp.gp_Pnt(cX + self.cartesianSpacing()[0], baselineY, cZ)

        #make the edges and the wires
        edges = []
        edges.append(OCCUtil.edgeFromTwoPoints(p0, p1))
        edges.append(OCCUtil.edgeFromTwoPoints(p1, p2))
        edges.append(OCCUtil.edgeFromTwoPoints(p2, p3))
        edges.append(OCCUtil.edgeFromTwoPoints(p3, p4))
        edges.append(OCCUtil.edgeFromTwoPoints(p4, p5))

        wire = OCCUtil.wireFromEdges(edges)
        return wire
Ejemplo n.º 11
0
def TestWireJoiner():
    wire = TestObjects.makeOffsetTestWire()
    conditions = []

    #each test condition is two points, representing an edge
    #that was drawn last.
    #in these tests, the red curve is the trimmed one, and the green is the original.
    #the yellow markers on the leadin edges and the joining segment is closer to the end

    #in each case, the solution found should minimize overlap and trim the other edge
    #as necessary.

    conditions.append((gp.gp_Pnt(11.2, 1.0, 0), gp.gp_Pnt(11.2, 0.0, 0)))
    conditions.append((gp.gp_Pnt(11.2, -1.0, 0), gp.gp_Pnt(11.2, 0.0, 0)))
    conditions.append((gp.gp_Pnt(15.2, 0.0, 0), gp.gp_Pnt(11.2, 0.0, 0)))
    conditions.append((gp.gp_Pnt(11.2, -3.0, 0), gp.gp_Pnt(11.2, -1.0, 0)))
    conditions.append((gp.gp_Pnt(20.2, 19.0, 0), gp.gp_Pnt(20.2, 20.0, 0)))
    conditions.append((gp.gp_Pnt(30.2, 25.0, 0), gp.gp_Pnt(20.2, 20.0, 0)))

    for (startPoint, endPoint) in conditions:
        display.EraseAll()
        display.DisplayColoredShape(wire, 'GREEN')
        initVector = OCCUtil.edgeFromTwoPoints(startPoint, endPoint)
        display.DisplayColoredShape(
            OCCUtil.edgeFromTwoPoints(startPoint, endPoint), 'BLUE')
        display.DisplayColoredShape(TestObjects.makeEdgeIndicator(initVector))
        vec = gp.gp_Vec(startPoint, endPoint)
        jrequest = JointRequest(endPoint, vec, 0.8, wire)
        wj = WireJoiner(jrequest, 4.0)
        #this is a huge tolerance, but helps for testing
        solution = wj.build()
        display.DisplayColoredShape(solution.wire, 'RED')
        entryEdge = OCCUtil.edgeFromTwoPoints(endPoint, solution.entryPoint)
        display.DisplayColoredShape(TestObjects.makeEdgeIndicator(entryEdge))
        if solution.isJoint:
            display.DisplayColoredShape(entryEdge, 'WHITE')
        else:
            display.DisplayColoredShape(entryEdge, 'YELLOW')
        time.sleep(5)
Ejemplo n.º 12
0
def TestWireJoiner():
    wire = TestObjects.makeOffsetTestWire()
    conditions = []

    # each test condition is two points, representing an edge
    # that was drawn last.
    # in these tests, the red curve is the trimmed one, and the green is the original.
    # the yellow markers on the leadin edges and the joining segment is closer to the end

    # in each case, the solution found should minimize overlap and trim the other edge
    # as necessary.

    conditions.append((gp.gp_Pnt(11.2, 1.0, 0), gp.gp_Pnt(11.2, 0.0, 0)))
    conditions.append((gp.gp_Pnt(11.2, -1.0, 0), gp.gp_Pnt(11.2, 0.0, 0)))
    conditions.append((gp.gp_Pnt(15.2, 0.0, 0), gp.gp_Pnt(11.2, 0.0, 0)))
    conditions.append((gp.gp_Pnt(11.2, -3.0, 0), gp.gp_Pnt(11.2, -1.0, 0)))
    conditions.append((gp.gp_Pnt(20.2, 19.0, 0), gp.gp_Pnt(20.2, 20.0, 0)))
    conditions.append((gp.gp_Pnt(30.2, 25.0, 0), gp.gp_Pnt(20.2, 20.0, 0)))

    for (startPoint, endPoint) in conditions:
        display.EraseAll()
        display.DisplayColoredShape(wire, "GREEN")
        initVector = OCCUtil.edgeFromTwoPoints(startPoint, endPoint)
        display.DisplayColoredShape(OCCUtil.edgeFromTwoPoints(startPoint, endPoint), "BLUE")
        display.DisplayColoredShape(TestObjects.makeEdgeIndicator(initVector))
        vec = gp.gp_Vec(startPoint, endPoint)
        jrequest = JointRequest(endPoint, vec, 0.8, wire)
        wj = WireJoiner(jrequest, 4.0)
        # this is a huge tolerance, but helps for testing
        solution = wj.build()
        display.DisplayColoredShape(solution.wire, "RED")
        entryEdge = OCCUtil.edgeFromTwoPoints(endPoint, solution.entryPoint)
        display.DisplayColoredShape(TestObjects.makeEdgeIndicator(entryEdge))
        if solution.isJoint:
            display.DisplayColoredShape(entryEdge, "WHITE")
        else:
            display.DisplayColoredShape(entryEdge, "YELLOW")
        time.sleep(5)
Ejemplo n.º 13
0
	def _makeHatchLines(self):
		"""
			make straight hatch lines.
			TODO: need to use fillAngle to rotate the lines as well. Trsf object 
		"""
		xMin = self.bounds[0] - ( self.HATCH_PADDING);
		yMin = self.bounds[1] - ( self.HATCH_PADDING);		 
		xMax = self.bounds[2] + (self.HATCH_PADDING);
		yMax = self.bounds[3] + (self.HATCH_PADDING) ;
		wires = [];
		for y in Util.frange6(yMin,yMax,self.spacing):
			e = OCCUtil.edgeFromTwoPoints(gp.gp_Pnt(xMin,y,self.zLevel),gp.gp_Pnt(xMax,y,self.zLevel));
			wires.append(OCCUtil.wireFromEdges([e]));
		return wires;
Ejemplo n.º 14
0
def testLineDirection():
    p1 = gp.gp_Pnt(0,0,0);
    p2 = gp.gp_Pnt(1,0,0);
    p3 = gp.gp_Pnt(-1,0,0);
    e1 = OCCUtil.edgeFromTwoPoints(p1,p2);
    e2 = OCCUtil.edgeFromTwoPoints(p1,p3);
    
    (hCurve1, startp1, endp1) = brepTool.Curve(e1);
    (hCurve2, startp2, endp2) = brepTool.Curve(e2);
    curve1 = hCurve1.GetObject();
    
    q1 = gp.gp_Pnt();
    v1 = gp.gp_Vec();
    q2 = gp.gp_Pnt();
    v2 = gp.gp_Vec();  
    curve1 = GeomAdaptor.GeomAdaptor_Curve(hCurve1);
    curve2 = GeomAdaptor.GeomAdaptor_Curve(hCurve2);
    
    curve1.D1(endp1,q1,v1);
    curve2.D1(endp2,q2,v2);
    
    print v2.Angle(v1);
    print v1.Magnitude(),v1.X(), v1.Y(), v1.Z();
    print v2.Magnitude(),v2.X(), v2.Y(), v2.Z();
Ejemplo n.º 15
0
def testLineDirection():
    p1 = gp.gp_Pnt(0, 0, 0)
    p2 = gp.gp_Pnt(1, 0, 0)
    p3 = gp.gp_Pnt(-1, 0, 0)
    e1 = OCCUtil.edgeFromTwoPoints(p1, p2)
    e2 = OCCUtil.edgeFromTwoPoints(p1, p3)

    (hCurve1, startp1, endp1) = brepTool.Curve(e1)
    (hCurve2, startp2, endp2) = brepTool.Curve(e2)
    curve1 = hCurve1.GetObject()

    q1 = gp.gp_Pnt()
    v1 = gp.gp_Vec()
    q2 = gp.gp_Pnt()
    v2 = gp.gp_Vec()
    curve1 = GeomAdaptor.GeomAdaptor_Curve(hCurve1)
    curve2 = GeomAdaptor.GeomAdaptor_Curve(hCurve2)

    curve1.D1(endp1, q1, v1)
    curve2.D1(endp2, q2, v2)

    print v2.Angle(v1)
    print v1.Magnitude(), v1.X(), v1.Y(), v1.Z()
    print v2.Magnitude(), v2.X(), v2.Y(), v2.Z()
Ejemplo n.º 16
0
    def _makeHatchLines(self):
        """
			make straight hatch lines.
			TODO: need to use fillAngle to rotate the lines as well. Trsf object 
		"""
        xMin = self.bounds[0] - (self.HATCH_PADDING)
        yMin = self.bounds[1] - (self.HATCH_PADDING)
        xMax = self.bounds[2] + (self.HATCH_PADDING)
        yMax = self.bounds[3] + (self.HATCH_PADDING)
        wires = []
        for y in Util.frange6(yMin, yMax, self.spacing):
            e = OCCUtil.edgeFromTwoPoints(gp.gp_Pnt(xMin, y, self.zLevel),
                                          gp.gp_Pnt(xMax, y, self.zLevel))
            wires.append(OCCUtil.wireFromEdges([e]))
        return wires
Ejemplo n.º 17
0
    def _compute(self):
        (p1, p, p2) = (self.p1, self.closestParam, self.p2)
        #p1 < p < p2

        #i think this works well for small distance. not as well if d is large.

        if (p - p1) < (2.0) * self.distanceFromStartPoint:
            #TODO: this code is nearly same as the branch below but with p1 and p2 swapped,
            #connect to start vertex
            self.connectingPoint = self.edgeStart
            self.connectingParm = p1

            #compute shortened edge
            e1 = OCCUtil.edgeFromTwoPointsOnCurve(self.handleCurve,
                                                  p1 + self.trackWidth, p2)
            self.otherEdges = [e1]

            #enter the wire by connecting start to vertex directly
            self.connectingEdges = [
                OCCUtil.edgeFromTwoPoints(self.startPoint,
                                          self.connectingPoint)
            ]

        elif (p2 - p) < (2.0) * self.distanceFromStartPoint:
            #connect to end vertex
            self.connectingPoint = self.edgeEnd
            self.connectingParm = p2

            #compute shortened edge
            e1 = OCCUtil.edgeFromTwoPointsOnCurve(self.handleCurve, p1,
                                                  p2 - self.trackWidth)
            self.otherEdges = [e1]

            #enter the wire by connecting start to vertex directly
            self.connectingEdges = [
                OCCUtil.edgeFromTwoPoints(self.startPoint,
                                          self.connectingPoint)
            ]
        else:
            #connect to middle of the edge
            self.connectingEdges = []
            firstEdge = None
            #which end is closer?
            if (p - p1) > (p2 - p):  #p2 is closer
                pTarget = p + (2.0) * self.distanceFromStartPoint
                pEnd = pTarget - self.trackWidth
                secondEdge = OCCUtil.edgeFromTwoPointsOnCurve(
                    self.handleCurve, pTarget, p2)
                self.otherEdges = [
                    OCCUtil.edgeFromTwoPointsOnCurve(self.handleCurve, p1,
                                                     pEnd)
                ]
            else:  #p1 is closer
                pTarget = p - (2.0) * self.distanceFromStartPoint
                pEnd = pTarget + self.trackWidth
                secondEdge = OCCUtil.edgeFromTwoPointsOnCurve(
                    self.handleCurve, p1, pTarget)
                self.otherEdges = [
                    OCCUtil.edgeFromTwoPointsOnCurve(self.handleCurve, pEnd,
                                                     p2)
                ]

            self.connectingParam = pTarget
            self.connectingPoint = self.curve.Value(pTarget)
            self.connectingEdges.append(
                OCCUtil.edgeFromTwoPoints(self.startPoint,
                                          self.connectingPoint))
            self.connectingEdges.append(secondEdge)
Ejemplo n.º 18
0
    def followWires(self, startNearPoint, pathWidth):

        outputWires = self.outputWires

        #list wires we must draw. we want to connect them in a sane order
        #make sure to start at a point far outside the face so we start outside!
        toDraw = self.originalWires + self.otherWires

        #find starting vertex and wire
        #must start on outer wire only
        lastPoint = startNearPoint
        initialPoint = OCCUtil.nearestVertex(self.originalWires,
                                             startNearPoint)
        lastVector = gp.gp_Vec((gp.gp_Pnt(0, 0, 0)), startNearPoint)

        #assume initial vector is sideways for now.  At the beginning of a layer, the start vector is not relevant,
        #so anythign will work i think. here we assume the first vector is from the origin

        if initialPoint is None:
            raise Exception(
                "Cannot find initial starting point on outer wire!")

        (currentWire, currentVertex, currentPoint,
         distance) = OCCUtil.nearestVertex(self.originalWires, startNearPoint)

        while len(toDraw) > 0:

            currentPoint = brepTool.Pnt(currentVertex)
            toDraw.remove(currentWire)

            #trim the wire at this point
            #TODO: simplify syntax for this!
            jrequest = WireJoiner.JointRequest(lastPoint, lastVector,
                                               pathWidth, currentWire)
            wj = WireJoiner.WireJoiner(jrequest, pathWidth * (2.0))
            solution = wj.build()

            trimmedWire = solution.wire
            trimmedEdge = solution.trimmedEdge
            trimmedPoint = solution.trimmedPoint
            trimmedVec = solution.trimmedVec

            joinEdge = OCCUtil.edgeFromTwoPoints(lastPoint, currentPoint)
            joinWire = OCCUtil.wireFromEdges([joinEdge])
            outputWires.append(joinWire)

            if solution.isJoint:
                #display.DisplayColoredShape(joinWire,'RED');
                pass
            else:
                #display.DisplayColoredShape(joinWire,'YELLOW');
                pass
            outputWires.append(trimmedWire)
            #display.DisplayColoredShape(trimmedWire,'GREEN');

            #look for another edge which was created by the trimmedEdge. this is where we should search for a connecting point.
            (nextVertex, nextEdge,
             nextWire) = self.getNextEdge(trimmedEdge, trimmedPoint)

            if nextVertex:
                #connect edges and chain to the this wire
                currentVertex = nextVertex
                currentWire = nextWire
            else:
                #no next edge found. find next closest wire to last point, but don't connect it
                #here we should assume the next move is a rapid and not connect it.
                result = OCCUtil.nearestVertex(toDraw, currentPoint)
                if result:
                    (currentWire, currentVertex, point, distance) = result
                    lastPoint = trimmedPoint
                else:
                    #couldnt find next vertex either -- not sure this should ever happen?
                    #TODO this is a total hack, need to fix the loop to avoid this extra check
                    if len(toDraw) > 0:
                        raise Exception(
                            "Could not find a next vertex, but there are wires left. how did this happen?"
                        )
                    else:
                        break
            lastPoint = trimmedPoint
            lastVector = trimmedVec
Ejemplo n.º 19
0
    def followWires (self,startNearPoint,pathWidth):
        
        outputWires = self.outputWires;

        #list wires we must draw. we want to connect them in a sane order
        #make sure to start at a point far outside the face so we start outside!
        toDraw = self.originalWires + self.otherWires;

        #find starting vertex and wire
        #must start on outer wire only
        lastPoint = startNearPoint;
        initialPoint =  OCCUtil.nearestVertex(self.originalWires,startNearPoint);
        lastVector = gp.gp_Vec((gp.gp_Pnt(0,0,0)), startNearPoint);


        #assume initial vector is sideways for now.  At the beginning of a layer, the start vector is not relevant,
        #so anythign will work i think. here we assume the first vector is from the origin
        
        if initialPoint is None:
            raise Exception ("Cannot find initial starting point on outer wire!");

        (currentWire,currentVertex,currentPoint,distance) = OCCUtil.nearestVertex(self.originalWires,startNearPoint);


        while len(toDraw) > 0:

            currentPoint = brepTool.Pnt(currentVertex);    
            toDraw.remove(currentWire);                
                      
            #trim the wire at this point
            #TODO: simplify syntax for this!
            jrequest = WireJoiner.JointRequest( lastPoint,lastVector,pathWidth,currentWire);        
            wj = WireJoiner.WireJoiner(jrequest,pathWidth*(2.0) ); 
            solution = wj.build();            
            
            trimmedWire = solution.wire;
            trimmedEdge = solution.trimmedEdge;
            trimmedPoint = solution.trimmedPoint;
            trimmedVec = solution.trimmedVec;
            
     
            joinEdge = OCCUtil.edgeFromTwoPoints(lastPoint,currentPoint);
            joinWire = OCCUtil.wireFromEdges([joinEdge]);
            outputWires.append(joinWire);
            
            if solution.isJoint:
                #display.DisplayColoredShape(joinWire,'RED');
                pass;                
            else:
                #display.DisplayColoredShape(joinWire,'YELLOW');
                pass;
            outputWires.append(trimmedWire);
            #display.DisplayColoredShape(trimmedWire,'GREEN');
            
            #look for another edge which was created by the trimmedEdge. this is where we should search for a connecting point.
            (nextVertex,nextEdge,nextWire) = self.getNextEdge(trimmedEdge, trimmedPoint);

            if nextVertex:
                #connect edges and chain to the this wire
                currentVertex = nextVertex;
                currentWire = nextWire;
            else:
                #no next edge found. find next closest wire to last point, but don't connect it
                #here we should assume the next move is a rapid and not connect it.
                result = OCCUtil.nearestVertex(toDraw, currentPoint);
                if result:
                    (currentWire,currentVertex,point, distance) = result;
                    lastPoint = trimmedPoint;
                else:
                    #couldnt find next vertex either -- not sure this should ever happen?
                    #TODO this is a total hack, need to fix the loop to avoid this extra check
                    if len(toDraw) > 0:
                        raise Exception("Could not find a next vertex, but there are wires left. how did this happen?")
                    else:
                        break;
            lastPoint = trimmedPoint;
            lastVector = trimmedVec;    
Ejemplo n.º 20
0
	p1 = PointOnAnEdge(e1.edge,e1p ,e1.pointAtParameter(e1p));
	p2 = PointOnAnEdge(e2.edge,e2p ,e2.pointAtParameter(e2p));

	t = Util.Timer();
	ee = [];
	for i in range(1,1000):
		ee = splitWire(w,[p2,p1]);
		assert len(ee) == 1;
	
	print "Elapsed for 1000splits:",t.finishedString();
	#TestDisplay.display.showShape(ee);
	
if __name__=='__main__':
	print "Basic Wrappers and Utilities Module"

	e1 = OCCUtil.edgeFromTwoPoints(gp.gp_Pnt(0,0,0),gp.gp_Pnt(2,0,0));
	
	"""
	t = OCCUtil.Timer();
	for i in range(1,20000):
		ew = OCCUtil.Edge(e1);
	print "Create 10000 edgewrappers= %0.3f" % t.elapsed();
	print ew.firstParameter, ew.lastParameter;
	
	t = OCCUtil.Timer();
	for i in range(1,20000):
		(s,e) = brepTool.Range(e1);
	print "Get parameters 10000 times= %0.3f" % t.elapsed();
	print s,e
	"""