Ejemplo n.º 1
0
    def preview(self, inp, direction):
        if self.step == 0:
            self.previous_data = [inp]
            return [BRepBuilderAPI.BRepBuilderAPI_MakeVertex(inp).Vertex()]
        elif self.step == 1:
            point0 = self.previous_data[0]
            point1 = inp
            # checking if the previous points are identical: This is necessary
            # before continuing in order to avoid a crash on Windows
            if point0 == point1:
                raise InvalidInputException
            dirvec = vec(0, 0, 0)
            dirvec[direction] = 1
            axis = gp.gp_Ax2(point0, dirvec.to_gp_Dir())

            d = point0 - inp
            d[direction] = 0
            dist = d.length()

            a = Geom.Geom_Circle(axis, dist).GetHandle()
            b = BRepBuilderAPI.BRepBuilderAPI_MakeEdge(a).Edge()
            c = BRepBuilderAPI.BRepBuilderAPI_MakeWire(b).Wire()
            d = BRepBuilderAPI.BRepBuilderAPI_MakeFace(c).Face()
            self._final = [d]
            return self._final
Ejemplo n.º 2
0
def normalEdgesAlongEdge(edge, length , interval):
	"compute an edge having length at the specified parameter on the supplied curve:"

	edgeList = [];
	
	ew = Wrappers.Edge(edge);
	zDir = gp.gp().DZ();
	zVec = gp.gp_Vec(zDir);
	
	curve = ew.curve;
	pStart = ew.firstParameter;
	pEnd = ew.lastParameter;
	
	for p in Wrappers.frange6(pStart,pEnd,interval):
		tangent = gp.gp_Vec();
		tanpoint = gp.gp_Pnt();
		curve.D1(p,tanpoint,tangent );
		axis = gp.gp_Ax1(tanpoint, gp.gp_Dir(tangent.Crossed(zVec) ) );
	
		line = Geom.Geom_Line(axis );
		e = BRepBuilderAPI.BRepBuilderAPI_MakeEdge(line.GetHandle(),0, length).Edge();	
		if e:
			edgeList.append(e);
			
	return edgeList;
Ejemplo n.º 3
0
def make_true_para(FL, rmin, rmax):
    """
    makes a parabloid, with rotation axis along Z and focus
    at the origin
    """
    ax = gp.gp_Ax2(gp.gp_Pnt(0.,0.,-FL), #origin
                   gp.gp_Dir(1.,0.,0.), #main direction is Z
                   gp.gp_Dir(0.,0.,1.)) #X Direction is X
    para = Geom.Geom_Parabola(ax, FL)
    h_para = Geom.Handle_Geom_Parabola(para)
    
    ax2 = gp.gp_Ax2(gp.gp_Pnt(0,0,0), #origin
                   gp.gp_Dir(0.,0.,1.), #main direction is Z
                   gp.gp_Dir(1.,0.,0.)) #X Direction is X
    
    pbl_shape = BRepPrimAPI.BRepPrimAPI_MakeRevolution(ax2, h_para,
                                                       rmin, rmax)
    return pbl_shape.Shape()
Ejemplo n.º 4
0
def make_spherical_lens2(CT1, CT2, diameter, 
                         curvature1, curvature2, 
                        centre, direction, x_axis):
    cax = gp.gp_Ax2(gp.gp_Pnt(0,0,CT1-curvature1),
                    gp.gp_Dir(0,sign(curvature1),0),
                    gp.gp_Dir(1,0,0))
    circ = Geom.Geom_Circle(cax, abs(curvature1))
    h_circ = Geom.Handle_Geom_Circle(circ)
    
    cax2 = gp.gp_Ax2(gp.gp_Pnt(0,0,CT2-curvature2),
                    gp.gp_Dir(0,-sign(curvature2),0),
                    gp.gp_Dir(1,0,0))
    circ2 = Geom.Geom_Circle(cax2, abs(curvature2))
    h_circ2 = Geom.Handle_Geom_Circle(circ2)
    
    r = diameter/2.
    
    h2 = CT1 - curvature1 + numpy.sqrt(curvature1**2 - r**2)*sign(curvature1)
    h3 = CT2 - curvature2 + numpy.sqrt(curvature2**2 - r**2)*sign(curvature2)
    p1 = gp.gp_Pnt(0,0,CT1)
    p2 = gp.gp_Pnt(r,0,h2)
    p3 = gp.gp_Pnt(r,0,h3)
    p4 = gp.gp_Pnt(0,0,CT2)
    
    e1 = BRepBuilderAPI.BRepBuilderAPI_MakeEdge(h_circ, p1, p2)    
    e2 = BRepBuilderAPI.BRepBuilderAPI_MakeEdge(p2,p3)
    e3 = BRepBuilderAPI.BRepBuilderAPI_MakeEdge(h_circ2, p3,p4)
    e4 = BRepBuilderAPI.BRepBuilderAPI_MakeEdge(p4,p1)
    
    wire = BRepBuilderAPI.BRepBuilderAPI_MakeWire()
    for e in (e1,e2,e3,e4):
        print(e)
        wire.Add(e.Edge())
    
    face = BRepBuilderAPI.BRepBuilderAPI_MakeFace(wire.Wire())
    
    ax = gp.gp_Ax1(gp.gp_Pnt(0,0,0),
                   gp.gp_Dir(0,0,1))
    solid = BRepPrimAPI.BRepPrimAPI_MakeRevol(face.Shape(), ax)
    
    return position_shape(toshape(solid), centre, direction, x_axis)
Ejemplo n.º 5
0
def make_spherical_lens(CT, diameter, curvature, 
                        centre, direction, x_axis):
    cax = gp.gp_Ax2(gp.gp_Pnt(0,0,CT-curvature),
                    gp.gp_Dir(0,1,0),
                    gp.gp_Dir(1,0,0))
    circ = Geom.Geom_Circle(cax, curvature)
    h_circ = Geom.Handle_Geom_Circle(circ)
    
    r = diameter/2.
    h2 = CT - curvature + numpy.sqrt(curvature**2 - r**2)
    p1 = gp.gp_Pnt(0,0,CT)
    p2 = gp.gp_Pnt(r,0,h2)
    p3 = gp.gp_Pnt(r,0,0)
    p4 = gp.gp_Pnt(0,0,0)
    
    #ps = p1,p2,p3,p4
    #vs = [BRepBuilderAPI.BRepBuilderAPI_MakeVertex(p) for p in ps]
    
    e1 = BRepBuilderAPI.BRepBuilderAPI_MakeEdge(h_circ, p1,
                                                p2)    
    e2 = BRepBuilderAPI.BRepBuilderAPI_MakeEdge(p2,p3)
    e3 = BRepBuilderAPI.BRepBuilderAPI_MakeEdge(p3,p4)
    e4 = BRepBuilderAPI.BRepBuilderAPI_MakeEdge(p4,p1)
    
    wire = BRepBuilderAPI.BRepBuilderAPI_MakeWire()
    for e in (e1,e2,e3,e4):
        print(e)
        wire.Add(e.Edge())
    
    face = BRepBuilderAPI.BRepBuilderAPI_MakeFace(wire.Wire())
    
    ax = gp.gp_Ax1(gp.gp_Pnt(0,0,0),
                   gp.gp_Dir(0,0,1))
    solid = BRepPrimAPI.BRepPrimAPI_MakeRevol(face.Shape(), ax)
    
    return position_shape(toshape(solid), centre, direction, x_axis)
Ejemplo n.º 6
0
def normalEdgeAtParameter(edge, param, length ):
	"compute an edge having length at the specified parameter on the supplied curve:"

	ew = Wrappers.Edge(edge);
	zDir = gp.gp().DZ();
	zVec = gp.gp_Vec(zDir);
	
	tangent = gp.gp_Vec();
	tanpoint = gp.gp_Pnt();
	
	curve = ew.curve;
	curve.D1(param,tanpoint,tangent );
	axis = gp.gp_Ax1(tanpoint, gp.gp_Dir(tangent.Crossed(zVec) ) );
	
	line = Geom.Geom_Line(axis );
	return  BRepBuilderAPI.BRepBuilderAPI_MakeEdge(line.GetHandle(),0, length).Edge();
Ejemplo n.º 7
0
from viewer import view

from OCC import Geom, GeomAPI, gp, BRepBuilderAPI, BRep, TopoDS

radius = 25.0
sph = Geom.Geom_SphericalSurface(gp.gp_Ax3(), radius)
h_sph = Geom.Handle_Geom_SphericalSurface(sph)

c_rad = 12.0  #cylinder radius
cyl = Geom.Geom_CylindricalSurface(gp.gp_Ax3(), c_rad)
h_cyl = Geom.Handle_Geom_CylindricalSurface(cyl)

intersect = GeomAPI.GeomAPI_IntSS(h_sph, h_cyl, 1e-7)

edges = (BRepBuilderAPI.BRepBuilderAPI_MakeEdge(intersect.Line(i))
         for i in xrange(1,
                         intersect.NbLines() + 1))

wires = [BRepBuilderAPI.BRepBuilderAPI_MakeWire(e.Edge()) for e in edges]

g_sph = gp.gp_Sphere(gp.gp_Ax3(), radius)
faces = [BRepBuilderAPI.BRepBuilderAPI_MakeFace(w.Wire()) for w in wires]
cyl_face = BRepBuilderAPI.BRepBuilderAPI_MakeFace(h_cyl)
#cyl_face.Add(wires[0].Wire())
#cyl_face.Add(wires[1].Wire())

#shell = TopoDS.TopoDS_Shell()
shell_builder = BRep.BRep_Builder()
#shell_builder.MakeShell(shell)
#shell_builder.Add(shell, cyl_face.Shape())
#for f in faces:
Ejemplo n.º 8
0
from OCC import Geom, gp, GeomAPI, BRepBuilderAPI, BRepPrimAPI, BRepAlgoAPI,\
        STEPControl

from viewer import view

EFL = 50.8

ax = gp.gp_Ax2(
    gp.gp_Pnt(0., 0., 0.),  #origin
    gp.gp_Dir(1., 0., 0.),  #main direction is Z
    gp.gp_Dir(0., 0., 1.))  #X Direction is X
FL = EFL / 2.  #focal length

para = Geom.Geom_Parabola(ax, FL)

h_para = Geom.Handle_Geom_Parabola(para)

radius = 25.4

outside = EFL + radius
length = (outside**2) / (4. * FL)

ax2 = gp.gp_Ax2(
    gp.gp_Pnt(0, 0, 0),  #origin
    gp.gp_Dir(0., 0., 1.),  #main direction is X
    gp.gp_Dir(1., 0., 0.))  #X Direction is Z

pbl_shape = BRepPrimAPI.BRepPrimAPI_MakeRevolution(ax2, h_para, 1.0, outside)

ax3 = gp.gp_Ax2(
    gp.gp_Pnt(EFL, 0, 0),  #origin
Ejemplo n.º 9
0
from OCC import Geom, BRepBuilderAPI, gp
from viewer import view
import numpy

curvature = 50.0

ax = gp.gp_Ax2(gp.gp_Pnt(0, 0, 0), gp.gp_Dir(0, 1, 0), gp.gp_Dir(1, 0, 0))
circ = Geom.Geom_Circle(ax, curvature)
h_circ = Geom.Handle_Geom_Circle(circ)

angle = 1.3
p1 = gp.gp_Pnt(0, 0, curvature)
p2 = gp.gp_Pnt(curvature, 0, 0)

edge = BRepBuilderAPI.BRepBuilderAPI_MakeEdge(h_circ, p1, p2)

view(edge.Shape())