Beispiel #1
0
def move(orig_pypt, location_pypt, occtopology):
    """
    This function moves an OCCtopology from the orig_pypt to the location_pypt.
 
    Parameters
    ----------        
    orig_pypt : tuple of floats
        The OCCtopology will move in reference to this point.
        A pypt is a tuple that documents the xyz coordinates of a pt e.g. (x,y,z)
        
    location_pypt : tuple of floats
        The destination of where the OCCtopology will be moved in relation to the orig_pypt.
        A pypt is a tuple that documents the xyz coordinates of a pt e.g. (x,y,z)
        
    occtopology : OCCtopology
        The OCCtopology to be moved.
        OCCtopology includes: OCCshape, OCCcompound, OCCcompsolid, OCCsolid, OCCshell, OCCface, OCCwire, OCCedge, OCCvertex 

    Returns
    -------
    moved topology : OCCtopology (OCCshape)
        The moved OCCtopology.
    """
    gp_ax31 = gp_Ax3(gp_Pnt(orig_pypt[0], orig_pypt[1], orig_pypt[2]), gp_DZ())
    gp_ax32 = gp_Ax3(gp_Pnt(location_pypt[0], location_pypt[1], location_pypt[2]), gp_DZ())
    aTrsf = gp_Trsf()
    aTrsf.SetTransformation(gp_ax32,gp_ax31)
    trsf_brep = BRepBuilderAPI_Transform(aTrsf)
    trsf_brep.Perform(occtopology, True)
    trsf_shp = trsf_brep.Shape()
    return trsf_shp
Beispiel #2
0
def make_ellipsoid(focus1, focus2, major_axis):
    """
    @param focus1: length 3 sequence giving first focus location
    @param focus2: length 3 sequence giving second focus location
    @param path_length: major axis length
    """
    f1 = numpy.asarray(focus1)
    f2 = numpy.asarray(focus2)
    direction = -(f1 - f2)
    centre = (f1 + f2)/2.
    sep = numpy.sqrt((direction**2).sum())
    minor_axis = numpy.sqrt( major_axis**2 - (sep/2.)**2 )
    
    sphere = BRepPrimAPI.BRepPrimAPI_MakeSphere(minor_axis)
    
    scale = gp.gp_GTrsf()
    scale.SetValue(3,3, major_axis/minor_axis)
    
    ellipse = BRepBuilderAPI.BRepBuilderAPI_GTransform(sphere.Shape(), scale)
    
    loc = gp.gp_Ax3()
    loc.SetLocation(gp.gp_Pnt(*centre))
    loc.SetDirection(gp.gp_Dir(*direction))
    
    tr = gp.gp_Trsf()
    tr.SetTransformation(loc, gp.gp_Ax3())
    
    trans = BRepBuilderAPI.BRepBuilderAPI_Transform(ellipse.Shape(), tr)
    shape = toshape(trans)
    return shape
Beispiel #3
0
    def _calcTransforms(self):
        """Computes transformation matrices to convert between coordinates

        Computes transformation matrices to convert between local and global
        coordinates.
        """
        # r is the forward transformation matrix from world to local coordinates
        # ok i will be really honest, i cannot understand exactly why this works
        # something bout the order of the translation and the rotation.
        # the double-inverting is strange, and I don't understand it.
        forward = Matrix()
        inverse = Matrix()

        global_coord_system = gp_Ax3()
        local_coord_system = gp_Ax3(gp_Pnt(*self.origin.toTuple()),
                                    gp_Dir(*self.zDir.toTuple()),
                                    gp_Dir(*self.xDir.toTuple()))

        forward.wrapped.SetTransformation(global_coord_system,
                                          local_coord_system)

        inverse.wrapped.SetTransformation(local_coord_system,
                                          global_coord_system)

        # TODO verify if this is OK
        self.lcs = local_coord_system
        self.rG = inverse
        self.fG = forward
Beispiel #4
0
def move(orig_pypt, location_pypt, occtopology):
    """
    This function moves an OCCtopology from the orig_pypt to the location_pypt.
 
    Parameters
    ----------        
    orig_pypt : tuple of floats
        The OCCtopology will move in reference to this point.
        A pypt is a tuple that documents the xyz coordinates of a pt e.g. (x,y,z)
        
    location_pypt : tuple of floats
        The destination of where the OCCtopology will be moved in relation to the orig_pypt.
        A pypt is a tuple that documents the xyz coordinates of a pt e.g. (x,y,z)
        
    occtopology : OCCtopology
        The OCCtopology to be moved.
        OCCtopology includes: OCCshape, OCCcompound, OCCcompsolid, OCCsolid, OCCshell, OCCface, OCCwire, OCCedge, OCCvertex 

    Returns
    -------
    moved topology : OCCtopology (OCCshape)
        The moved OCCtopology.
    """
    gp_ax31 = gp_Ax3(gp_Pnt(orig_pypt[0], orig_pypt[1], orig_pypt[2]), gp_DZ())
    gp_ax32 = gp_Ax3(
        gp_Pnt(location_pypt[0], location_pypt[1], location_pypt[2]), gp_DZ())
    aTrsf = gp_Trsf()
    aTrsf.SetTransformation(gp_ax32, gp_ax31)
    trsf_brep = BRepBuilderAPI_Transform(aTrsf)
    trsf_brep.Perform(occtopology, True)
    trsf_shp = trsf_brep.Shape()
    return trsf_shp
Beispiel #5
0
def wavefront_xyz(x, y, z, axs=gp_Ax3()):
    phas = surf_spl(x, y, z)

    trf = gp_Trsf()
    trf.SetTransformation(axs, gp_Ax3())
    loc_face = TopLoc_Location(trf)
    phas.Location(loc_face)
    return phas
Beispiel #6
0
def move(orig_pt, location_pt, occshape):
    gp_ax31 = gp_Ax3(gp_Pnt(orig_pt[0], orig_pt[1], orig_pt[2]), gp_DZ())
    gp_ax32 = gp_Ax3(gp_Pnt(location_pt[0], location_pt[1], location_pt[2]),
                     gp_DZ())
    aTrsf = gp_Trsf()
    aTrsf.SetTransformation(gp_ax32, gp_ax31)
    trsf_brep = BRepBuilderAPI_Transform(aTrsf)
    trsf_brep.Perform(occshape, True)
    trsf_shp = trsf_brep.Shape()
    return trsf_shp
Beispiel #7
0
def make_cylinder_2(start, end, radius):
    start = numpy.asarray(start)
    end = numpy.asarray(end)
    direction = end-start
    length = numpy.sqrt((direction**2).sum())
    cyl = BRepPrimAPI.BRepPrimAPI_MakeCylinder(radius, length)
    ax = gp.gp_Ax3(gp.gp_Pnt(*start), gp.gp_Dir(*direction))
    trans = gp.gp_Trsf()
    trans.SetTransformation(ax, gp.gp_Ax3())
    t_cyl = BRepBuilderAPI.BRepBuilderAPI_Transform(cyl.Shape(), trans)
    return toshape(t_cyl)
Beispiel #8
0
def make_box(position, direction, x_axis, dx, dy, dz):
    box = BRepPrimAPI.BRepPrimAPI_MakeBox(gp.gp_Pnt(-dx/2., -dy/2., 0.0),
                                          dx, dy, -dz)
    ax = gp.gp_Ax2(gp.gp_Pnt(*position), 
                   gp.gp_Dir(*direction),
                   gp.gp_Dir(*x_axis))
    ax3 = gp.gp_Ax3()
    trans = gp.gp_Trsf()
    trans.SetTransformation(gp.gp_Ax3(ax), ax3)
    t_box = BRepBuilderAPI.BRepBuilderAPI_Transform(box.Shape(), trans)
    return toshape(t_box)
Beispiel #9
0
def make_cylinder(position, direction, radius, length, offset, x_axis):
    cyl_ax = gp.gp_Ax2(gp.gp_Pnt(offset,0,0), 
                       gp.gp_Dir(0,0,1), 
                       gp.gp_Dir(1,0,0))
    cyl = BRepPrimAPI.BRepPrimAPI_MakeCylinder(cyl_ax, radius, length)
    ax = gp.gp_Ax2(gp.gp_Pnt(*position), 
                   gp.gp_Dir(*direction),
                   gp.gp_Dir(*x_axis))
    ax3 = gp.gp_Ax3()
    trans = gp.gp_Trsf()
    trans.SetTransformation(gp.gp_Ax3(ax), ax3)
    t_cyl = BRepBuilderAPI.BRepBuilderAPI_Transform(cyl.Shape(), trans)
    print(position, direction, radius, length)
    return toshape(t_cyl)
Beispiel #10
0
def wavefront(rxy=[1000, 1000], axs=gp_Ax3()):
    px = np.linspace(-1, 1, 100) * 10
    py = np.linspace(-1, 1, 100) * 10
    mesh = np.meshgrid(px, py)

    rx_0 = curvature(mesh[0], rxy[0], 0)
    ry_0 = curvature(mesh[1], rxy[1], 0)
    ph_0 = rx_0 + ry_0
    phas = surf_spl(*mesh, ph_0)

    trf = gp_Trsf()
    trf.SetTransformation(axs, gp_Ax3())
    loc_face = TopLoc_Location(trf)
    phas.Location(loc_face)
    return phas
Beispiel #11
0
def position_shape(shape, centre, direction, x_axis):
    ax = gp.gp_Ax3()
    ax.SetLocation(gp.gp_Pnt(*centre))
    ax.SetDirection(gp.gp_Dir(*direction))
    ax.SetXDirection(gp.gp_Dir(*x_axis))
    
    tr = gp.gp_Trsf()
    tr.SetTransformation(ax, gp.gp_Ax3())
    
    loc = TopLoc.TopLoc_Location(tr)
    
    shape.Location(loc)
    #trans = BRepBuilderAPI.BRepBuilderAPI_Transform(shape, tr)
    #return toshape(trans)
    return shape
Beispiel #12
0
 def _set_active_plane(self, value):
     if value == self._active_plane:
         return
     if value == 2:
         axis = gp_Ax3(gp_Pnt_([0, 0, 0]), gp_Dir(0, 0, 1), gp_Dir(1, 0, 0))
     elif value == 1:
         axis = gp_Ax3(gp_Pnt_([0, 0, 0]), gp_Dir(0, 1, 0), gp_Dir(0, 0, 1))
     elif value == 0:
         axis = gp_Ax3(gp_Pnt_([0, 0, 0]), gp_Dir(1, 0, 0), gp_Dir(0, 1, 0))
     self._active_plane = value
     appdata.set('active_plane', value)
     self.viewer.SetPrivilegedPlane(axis)
     # TODO: 0.3: these should probably be called through signals
     self._update_input()
     self.update_preview()
def points_from_intersection(event=None):
    '''
    @param display:
    '''
    plane = gp_Pln(gp_Ax3(gp_XOY()))
    minor_radius, major_radius = 5., 8.
    ellips = gp_Elips(gp_YOZ(), major_radius, minor_radius)
    intersection = IntAna_IntConicQuad(ellips,
                                       plane,
                                       precision_Angular(),
                                       precision_Confusion())
    a_plane = GC_MakePlane(plane).Value()
    a_surface = Geom_RectangularTrimmedSurface(a_plane, - 8., 8., - 12., 12.,
                                               True, True)
    display.DisplayShape(a_surface, update=True)

    anEllips = GC_MakeEllipse(ellips).Value()
    display.DisplayShape(anEllips)

    if intersection.IsDone():
        nb_results = intersection.NbPoints()
        if nb_results > 0:
            for i in range(1, nb_results + 1):
                P = intersection.Point(i)
                pstring = "P%i" % i
                display.DisplayShape(P)
                display.DisplayMessage(P, pstring)
Beispiel #14
0
def pipe(event=None):
  CurvePoles = TColgp_Array1OfPnt(1,6)
  pt1 = gp_Pnt(0.,0.,0.);
  pt2 = gp_Pnt(20.,50.,0.);
  pt3 = gp_Pnt(60.,100.,0.);
  pt4 = gp_Pnt(150.,0.,0.);
  CurvePoles.SetValue(1, pt1)
  CurvePoles.SetValue(2, pt2)
  CurvePoles.SetValue(3, pt3)
  CurvePoles.SetValue(4, pt4)

  curve = Geom_BezierCurve(CurvePoles)
  print type(curve)
  E = BRepBuilderAPI_MakeEdge(curve.GetHandle()).Edge()
  W = BRepBuilderAPI_MakeWire(E).Wire()
   
  #ais1 = AIS_Shape(W)
  #self.interactive_context.Display(ais1,1)
   
  c = gp_Circ(gp_Ax2(gp_Pnt(0.,0.,0.),gp_Dir(0.,1.,0.)),10.)
  Ec = BRepBuilderAPI_MakeEdge(c).Edge()
  Wc = BRepBuilderAPI_MakeWire(Ec).Wire()

  #ais3 = AIS_Shape(Wc)
  #self.interactive_context.Display(ais3,1)
   
  F = BRepBuilderAPI_MakeFace(gp_Pln(gp_Ax3(gp.gp().ZOX())),Wc,1).Face()
  MKPipe = BRepOffsetAPI_MakePipe(W,F)
  MKPipe.Build()
  display.DisplayShape(MKPipe.Shape())
def align_planes_byNormal(shp_add, normalDir_base, normalDir_add):
    """[summary]

    Arguments:
        shp_add {topoDS_Shape} -- [description]
        normalDir_base {gp_Dir} -- [description]
        normalDir_add {gp_Dir} -- [description]
        rotateAng [deg]{float} -- [description]
    """
    if not normalDir_base.IsParallel(normalDir_add, radians(0.01)):
        rotateAxDir = normalDir_base.Crossed(normalDir_add)
        # determin rotate angle
        rotRelAng = degrees(
            normalDir_base.AngleWithRef(normalDir_add, rotateAxDir))
        if rotRelAng > 89.99:
            rotRelAng -= 180
        elif rotRelAng < -89.99:
            rotRelAng += 180

        rotateAx1 = gp_Ax1(centerOfMass(shp_add), rotateAxDir)
        ax3 = gp_Ax3(gp_Pnt(0, 0, 0), gp_Dir(0, 0, 1))
        ax3 = ax3.Rotated(rotateAx1, radians(rotRelAng))
        shp2Trsf = gp_Trsf()
        shp2Trsf.SetTransformation(ax3)
        shp2Toploc = TopLoc_Location(shp2Trsf)
        shp_add.Move(shp2Toploc)
    else:
        logging.debug("Planes are already parallel to each other")
Beispiel #16
0
def points_from_intersection():
    '''
    @param display:
    '''
    plane = gp_Pln(gp_Ax3(gp_XOY()))
    minor_radius, major_radius = 5., 8.
    ellips = gp_Elips(gp_YOZ(), major_radius, minor_radius)
    intersection = IntAna_IntConicQuad(ellips, plane, precision_Angular(),
                                       precision_Confusion())
    a_plane = GC_MakePlane(plane).Value()
    a_surface = Geom_RectangularTrimmedSurface(a_plane, -8., 8., -12., 12.,
                                               True, True)
    display.DisplayShape(a_surface, update=True)

    anEllips = GC_MakeEllipse(ellips).Value()
    display.DisplayShape(anEllips)

    if intersection.IsDone():
        nb_results = intersection.NbPoints()
        if nb_results > 0:
            for i in range(1, nb_results + 1):
                P = intersection.Point(i)
                pstring = "P%i" % i
                display.DisplayShape(P)
                display.DisplayMessage(P, pstring)
def test_project_curve_to_plane():
    # Projects a line of length 1 from above the XOY plane, and tests points
    # on the resulting line
    from OCC.Geom import Geom_Plane, Geom_TrimmedCurve
    from OCC.GC import GC_MakeSegment
    from OCC.gp import gp_Ax3, gp_XOY, gp_Pnt, gp_Dir
    XOY = Geom_Plane(gp_Ax3(gp_XOY()))
    curve = GC_MakeSegment(gp_Pnt(0, 0, 5),
                           gp_Pnt(1, 0, 5)).Value()
    direction = gp_Dir(0, 0, 1)

    Hproj_curve = act.project_curve_to_plane(curve, XOY.GetHandle(),
                                            direction)

    proj_curve = Hproj_curve.GetObject()

    # The start and end points of the curve
    p1 = proj_curve.Value(0)
    p2 = proj_curve.Value(1)

    p1_array = np.array([p1.X(), p1.Y(), p1.Z()])
    p2_array = np.array([p2.X(), p2.Y(), p2.Z()])

    # The expected start and end points
    start = np.array([0, 0, 0])
    end = np.array([1, 0, 0])

    # Assert that neither points have a Y or Z component, and that
    assert((np.all(p1_array == start) and np.all(p2_array == end)) or
           (np.all(p1_array == end) and np.all(p2_array == start)))
Beispiel #18
0
    def makeHelix(cls,
                  pitch,
                  height,
                  radius,
                  center=Vector(0, 0, 0),
                  dir=Vector(0, 0, 1),
                  angle=360.0,
                  lefthand=False):
        """
        Make a helix with a given pitch, height and radius
        By default a cylindrical surface is used to create the helix. If
        the fourth parameter is set (the apex given in degree) a conical surface is used instead'
        """

        # 1. build underlying cylindrical/conical surface
        if angle == 360.:
            geom_surf = Geom_CylindricalSurface(
                gp_Ax3(center.toPnt(), dir.toDir()), radius)
        else:
            geom_surf = Geom_ConicalSurface(
                gp_Ax3(center.toPnt(), dir.toDir()),
                angle * DEG2RAD,  # TODO why no orientation?
                radius)

        # 2. construct an semgent in the u,v domain
        if lefthand:
            geom_line = Geom2d_Line(gp_Pnt2d(0.0, 0.0),
                                    gp_Dir2d(-2 * pi, pitch))
        else:
            geom_line = Geom2d_Line(gp_Pnt2d(0.0, 0.0),
                                    gp_Dir2d(2 * pi, pitch))

        # 3. put it together into a wire
        n_turns = height / pitch
        u_start = geom_line.Value(0.)
        u_stop = geom_line.Value(sqrt(n_turns * ((2 * pi)**2 + pitch**2)))
        geom_seg = GCE2d_MakeSegment(u_start, u_stop).Value()

        e = BRepBuilderAPI_MakeEdge(geom_seg, geom_surf.GetHandle()).Edge()

        # 4. Convert to wire and fix building 3d geom from 2d geom
        w = BRepBuilderAPI_MakeWire(e).Wire()
        breplib_BuildCurves3d(w)

        return cls(w)
Beispiel #19
0
    def _makeSlice(self, shapeToSlice, zLevel):

        s = Slice()

        #used to determine if a slice is identical to others.
        s.hatchDir = self.hatchReversed
        s.fillWidth = self.options.filling.fillWidth

        #change if layers are variable thickness
        s.sliceHeight = self.options.layerHeight
        s.zLevel = zLevel

        #make a cutting plane
        p = gp.gp_Pnt(0, 0, zLevel)

        origin = gp.gp_Pnt(0, 0, zLevel - 1)
        csys = gp.gp_Ax3(p, gp.gp().DZ())
        cuttingPlane = gp.gp_Pln(csys)
        bff = BRepBuilderAPI.BRepBuilderAPI_MakeFace(cuttingPlane)
        face = bff.Face()

        #odd, a halfspace is faster than a box?
        hs = BRepPrimAPI.BRepPrimAPI_MakeHalfSpace(face, origin)
        hs.Build()
        halfspace = hs.Solid()

        #make the cut
        bc = BRepAlgoAPI.BRepAlgoAPI_Cut(shapeToSlice, halfspace)
        cutShape = bc.Shape()

        foundFace = False
        for face in Topo(cutShape).faces():
            if self._isAtZLevel(zLevel, face):
                foundFace = True
                log.debug("Face is at zlevel" + str(zLevel))
                s.addFace(face)
                #TestDisplay.display.showShape(face);

                log.debug("Face" + str(face))

        if self.options.useSliceFactoring:
            mySum = s.getCheckSum()
            #print 'Slice Created, Checksum is',mySum;
            for otherSlice in self.slices:
                #print "Slice Checksum=",otherSlice.getCheckSum();
                if mySum == otherSlice.getCheckSum():
                    log.info(
                        "This slice matches another one exactly. using that so we can save time."
                    )
                    return otherSlice.copyToZ(zLevel)

        if not foundFace:
            log.warn("No faces found after slicing at zLevel " + str(zLevel) +
                     " !. Skipping This layer completely")
            return None
        else:
            return s
Beispiel #20
0
def axis():
    p1 = gp_Pnt(2., 3., 4.)
    d = gp_Dir(4., 5., 6.)
    a = gp_Ax3(p1, d)
    a_IsDirect = a.Direct()
    a_XDirection = a.XDirection()
    a_YDirection = a.YDirection()

    p2 = gp_Pnt(5., 3., 4.)
    a2 = gp_Ax3(p2, d)
    a2.YReverse()
    # axis3 is now left handed
    a2_IsDirect = a2.Direct()
    a2_XDirection = a2.XDirection()
    a2_YDirection = a2.YDirection()
    display.DisplayShape(p1, update=True)
    display.DisplayShape(p2, update=True)
    display.DisplayMessage(p1, "P1")
    display.DisplayMessage(p2, "P2")
def axis():
    p1 = gp_Pnt(2., 3., 4.)
    d = gp_Dir(4., 5., 6.)
    a = gp_Ax3(p1, d)
    a_IsDirect = a.Direct()
    a_XDirection = a.XDirection()
    a_YDirection = a.YDirection()

    p2 = gp_Pnt(5., 3., 4.)
    a2 = gp_Ax3(p2, d)
    a2.YReverse()
    # axis3 is now left handed
    a2_IsDirect = a2.Direct()
    a2_XDirection = a2.XDirection()
    a2_YDirection = a2.YDirection()
    display.DisplayShape(p1, update=True)
    display.DisplayShape(p2, update=True)
    display.DisplayMessage(p1, "P1")
    display.DisplayMessage(p2, "P2")
Beispiel #22
0
	def _makeSlice(self,shapeToSlice,zLevel):

		s = Slice();

		#used to determine if a slice is identical to others.
		s.hatchDir = self.hatchReversed;
		s.fillWidth = self.options.filling.fillWidth;
		
		#change if layers are variable thickness
		s.sliceHeight = self.options.layerHeight;		
		s.zLevel = zLevel;

		#make a cutting plane
		p = gp.gp_Pnt ( 0,0,zLevel );
			
		origin = gp.gp_Pnt(0,0,zLevel-1);
		csys = gp.gp_Ax3(p,gp.gp().DZ())
		cuttingPlane = gp.gp_Pln(csys);	
		bff = BRepBuilderAPI.BRepBuilderAPI_MakeFace(cuttingPlane);
		face = bff.Face();
		
		#odd, a halfspace is faster than a box?
		hs = BRepPrimAPI.BRepPrimAPI_MakeHalfSpace(face,origin);
		hs.Build();	
		halfspace = hs.Solid();
				
		#make the cut
		bc = BRepAlgoAPI.BRepAlgoAPI_Cut(shapeToSlice,halfspace);
		cutShape = bc.Shape();
		
		foundFace = False;
		for face in Topo(cutShape).faces():
			if self._isAtZLevel(zLevel,face):
				foundFace = True;
				log.debug( "Face is at zlevel" + str(zLevel) );
				s.addFace(face);
				TestDisplay.display.showShape(face);
				
				log.debug("Face" + str(face) );

				
		if self.options.useSliceFactoring:
			mySum = s.getCheckSum();
			#print 'Slice Created, Checksum is',mySum;
			for otherSlice in self.slices:
				#print "Slice Checksum=",otherSlice.getCheckSum();
				if mySum == otherSlice.getCheckSum():
					log.info("This slice matches another one exactly. using that so we can save time.");
					return otherSlice.copyToZ(zLevel);
				
		if not foundFace:
			log.warn("No faces found after slicing at zLevel " + str(zLevel) + " !. Skipping This layer completely");
			return None;
		else:		
			return s;		
Beispiel #23
0
def def_ax(x, y, z, lx=150, ly=200, dx=0, dy=0, dz=0):
    axs = gp_Ax3(gp_Pnt(x, y, z), gp_Dir(0, 0, 1), gp_Dir(1, 0, 0))
    a_x = gp_Ax1(gp_Pnt(x, y, z), axs.XDirection())
    a_y = gp_Ax1(gp_Pnt(x, y, z), axs.YDirection())
    a_z = gp_Ax1(gp_Pnt(x, y, z), axs.Direction())
    rot_axs(axs, a_x, dx)
    rot_axs(axs, a_y, dy)
    rot_axs(axs, a_z, dz)
    pln = BRepBuilderAPI_MakeFace(gp_Pln(axs), -lx / 2, lx / 2, -ly / 2,
                                  ly / 2).Face()
    return axs, pln
Beispiel #24
0
def reflect_axs2(beam, surf, axs=gp_Ax3(), indx=1):
    p0, v0 = beam.Location(), dir_to_vec(beam.Direction())
    h_surf = BRep_Tool.Surface(surf)
    ray = Geom_Line(gp_Lin(p0, vec_to_dir(v0)))
    if GeomAPI_IntCS(ray.GetHandle(), h_surf).NbPoints() == 0:
        return beam, beam, None
    elif GeomAPI_IntCS(ray.GetHandle(), h_surf).NbPoints() == 1:
        return beam, beam, None
    GeomAPI_IntCS(ray.GetHandle(), h_surf).IsDone()
    u, v, w = GeomAPI_IntCS(ray.GetHandle(), h_surf).Parameters(indx)
    p1, vx, vy = gp_Pnt(), gp_Vec(), gp_Vec()
    GeomLProp_SurfaceTool.D1(h_surf, u, v, p1, vx, vy)
    vz = vx.Crossed(vy)
    vx.Normalize()
    vy.Normalize()
    vz.Normalize()
    v1 = v0.Mirrored(gp_Ax2(p1, vec_to_dir(vz), vec_to_dir(vx)))
    norm_ax = gp_Ax3(p1, vec_to_dir(vz), vec_to_dir(vx))
    beam_ax = gp_Ax3(p1, vec_to_dir(v1), beam.XDirection().Reversed())
    return beam_ax, norm_ax, 1
Beispiel #25
0
    def _computeSlice(self, zLevel, layerNo, fillAngle):

        cSlice = Slice()
        cSlice.zLevel = zLevel
        cSlice.layerNo = layerNo
        cSlice.fillAngle = fillAngle
        cSlice.thickness = self.options.layerHeight

        #make a cutting plane
        p = gp.gp_Pnt(0, 0, zLevel)

        csys = gp.gp_Ax3(p, gp.gp().DZ())
        cuttingPlane = gp.gp_Pln(csys)

        #makeSection will use the old reliable way that will get a face from each cut.
        #makeSection2 will use BRepAlgoaPI_Section, but has problems ordering the edges correctly.
        newFaces = self.makeSection(cuttingPlane, self.solid.shape, zLevel)
        for f in newFaces:
            cSlice.addFace(Face(f))
        #bff = BRepBuilderAPI.BRepBuilderAPI_MakeFace(cuttingPlane);
        #face = bff.Face();

        #odd, a halfspace is faster than a box?
        #hs = BRepPrimAPI.BRepPrimAPI_MakeHalfSpace(face,origin);
        #hs.Build();
        #halfspace = hs.Solid();

        #make the cut
        #bc = BRepAlgoAPI.BRepAlgoAPI_Cut(self.solid.shape,halfspace);
        #cutShape = bc.Shape();

        #for face in Topo(cutShape).faces():
        #    if OCCUtil.isFaceAtZLevel(zLevel,face):
        #        cSlice.addFace(Face(face));
        #        break;

        mySum = cSlice.computeFingerPrint()

        #
        #uncomment to enable layer copying.
        #
        #check for identical slices. return matching ones if found.
        if self.sliceMap.has_key(mySum):
            #print "i can copy this layer!"
            return self.sliceMap[mySum].copyToZ(zLevel, layerNo)

        self.sliceMap[mySum] = cSlice
        #print "This slice has %d faces." % len(cSlice.faces)

        if self.options.fillingEnabled:
            self._fillSlice(cSlice)

        return cSlice
Beispiel #26
0
def surf_spl(px, py, pz, axs=gp_Ax3()):
    nx, ny = px.shape
    pnt_2d = TColgp_Array2OfPnt(1, nx, 1, ny)
    for row in range (pnt_2d.LowerRow(), pnt_2d.UpperRow()+1):
        for col in range (pnt_2d.LowerCol(), pnt_2d.UpperCol()+1):
            i,j = row-1, col-1
            pnt = gp_Pnt (px[i, j], py[i, j], pz[i, j])
            pnt_2d.SetValue(row, col, pnt)
    curv = GeomAPI_PointsToBSplineSurface(pnt_2d, 3, 8, GeomAbs_G2, 0.001).Surface()
    surf = BRepBuilderAPI_MakeFace(curv, 1e-6).Face()
    surf = surf_trf (axs, surf)
    return surf
def second_derivative(h_surf, u=0, v=0):
    p1 = gp_Pnt()
    pu, pv = gp_Vec(), gp_Vec()
    puu, pvv = gp_Vec(), gp_Vec()
    puv = gp_Vec()
    prop = GeomLProp_SLProps(h_surf, u, v, 1, 1)
    GeomLProp_SurfaceTool.D2(h_surf, u, v, p1, pu, pv, puu, pvv, puv)
    e0 = pu.Crossed(pv)
    pu.Normalize()
    pv.Normalize()
    e0.Normalize()
    puu.Normalize()
    pvv.Normalize()
    puv.Normalize()
    print(p1)
    print("pu", pu)
    print("pv", pv)
    print("e0", e0)
    print("puu", puu)
    print("pvv", pvv)
    print("puv", puv)

    first_form = np.array([[pu.Dot(pu), pu.Dot(pv)], [pv.Dot(pu), pv.Dot(pv)]])
    secnd_form = np.array([[e0.Dot(puu), e0.Dot(puv)],
                           [e0.Dot(puv), e0.Dot(pvv)]])

    print(first_form)
    print(secnd_form)
    print(prop.GaussianCurvature())
    print(prop.MeanCurvature())
    d1, d2 = gp_Dir(), gp_Dir()
    prop.CurvatureDirections(d1, d2)
    a1 = gp_Ax3()
    v1 = dir_to_vec(d1)
    v2 = dir_to_vec(d2)
    if pu.IsParallel(v1, 1 / 1000):
        c1 = prop.MaxCurvature()
        c2 = prop.MinCurvature()
        print(v1.Dot(pu), v1.Dot(pv))
        print(v2.Dot(pu), v2.Dot(pv))
    else:
        c1 = prop.MinCurvature()
        c2 = prop.MaxCurvature()
        print(v1.Dot(pu), v1.Dot(pv))
        print(v2.Dot(pu), v2.Dot(pv))
    print(c1, 1 / c1)
    print(c2, 1 / c2)

    px = np.linspace(-1, 1, 100) * 100
    p1_y = px**2 / c1
    p2_y = px**2 / c1
    curv1 = curv_spl(px, p1_y)
    curv2 = curv_spl(px, p2_y)
Beispiel #28
0
    def _computeSlice(self, zLevel, layerNo, fillAngle):

        cSlice = Slice()
        cSlice.zLevel = zLevel
        cSlice.layerNo = layerNo
        cSlice.fillAngle = fillAngle
        cSlice.thickness = self.options.layerHeight

        # make a cutting plane
        p = gp.gp_Pnt(0, 0, zLevel)

        csys = gp.gp_Ax3(p, gp.gp().DZ())
        cuttingPlane = gp.gp_Pln(csys)

        # makeSection will use the old reliable way that will get a face from each cut.
        # makeSection2 will use BRepAlgoaPI_Section, but has problems ordering the edges correctly.
        newFaces = self.makeSection(cuttingPlane, self.solid.shape, zLevel)
        for f in newFaces:
            cSlice.addFace(Face(f))
        # bff = BRepBuilderAPI.BRepBuilderAPI_MakeFace(cuttingPlane);
        # face = bff.Face();

        # odd, a halfspace is faster than a box?
        # hs = BRepPrimAPI.BRepPrimAPI_MakeHalfSpace(face,origin);
        # hs.Build();
        # halfspace = hs.Solid();

        # make the cut
        # bc = BRepAlgoAPI.BRepAlgoAPI_Cut(self.solid.shape,halfspace);
        # cutShape = bc.Shape();

        # for face in Topo(cutShape).faces():
        #    if OCCUtil.isFaceAtZLevel(zLevel,face):
        #        cSlice.addFace(Face(face));
        #        break;

        mySum = cSlice.computeFingerPrint()

        #
        # uncomment to enable layer copying.
        #
        # check for identical slices. return matching ones if found.
        if self.sliceMap.has_key(mySum):
            # print "i can copy this layer!"
            return self.sliceMap[mySum].copyToZ(zLevel, layerNo)

        self.sliceMap[mySum] = cSlice
        # print "This slice has %d faces." % len(cSlice.faces)

        if self.options.fillingEnabled:
            self._fillSlice(cSlice)

        return cSlice
Beispiel #29
0
def make_ellipsoid_2(focus1, focus2, major_axis):
    f1 = numpy.asarray(focus1)
    f2 = numpy.asarray(focus2)
    direction = -(f1 - f2)
    centre = (f1 + f2)/2.
    sep = numpy.sqrt((direction**2).sum())
    minor_axis = numpy.sqrt( major_axis**2 - (sep/2.)**2 )
    
    el = gp.gp_Elips(gp.gp_Ax2(gp.gp_Pnt(0,0,0), gp.gp_Dir(1,0,0)), 
                          major_axis, minor_axis)
    edge1 = BRepBuilderAPI.BRepBuilderAPI_MakeEdge(el, 
                                                  gp.gp_Pnt(0,0,major_axis),
                                                  gp.gp_Pnt(0,0,-major_axis))
    edge2 = BRepBuilderAPI.BRepBuilderAPI_MakeEdge(gp.gp_Pnt(0,0,-major_axis),
                                                  gp.gp_Pnt(0,0,major_axis))
    
    wire = BRepBuilderAPI.BRepBuilderAPI_MakeWire()
    wire.Add(edge1.Edge())
    wire.Add(edge2.Edge())
    
    face = BRepBuilderAPI.BRepBuilderAPI_MakeFace(wire.Wire())
    
    el = BRepPrimAPI.BRepPrimAPI_MakeRevol(face.Shape(), 
                                           gp.gp_Ax1(gp.gp_Pnt(0,0,0),
                                                     gp.gp_Dir(0,0,1)),
                                           numpy.pi*2)
    
    loc = gp.gp_Ax3()
    loc.SetLocation(gp.gp_Pnt(*centre))
    loc.SetDirection(gp.gp_Dir(*direction))
    
    tr = gp.gp_Trsf()
    tr.SetTransformation(loc, gp.gp_Ax3())
    
    trans = BRepBuilderAPI.BRepBuilderAPI_Transform(el.Shape(), tr)
    shape = toshape(trans)
    return shape
    def _makeSlice(self, shapeToSlice, zLevel):
        s = Slice()

        #change if layers are variable thickness
        s.sliceHeight = self.sliceHeight
        s.zLevel = zLevel

        #make a cutting plane
        p = gp.gp_Pnt(0, 0, zLevel)

        origin = gp.gp_Pnt(0, 0, zLevel - 1)
        csys = gp.gp_Ax3(p, gp.gp().DZ())
        cuttingPlane = gp.gp_Pln(csys)
        bff = BRepBuilderAPI.BRepBuilderAPI_MakeFace(cuttingPlane)
        face = bff.Face()

        #odd, a halfspace is faster than a box?
        hs = BRepPrimAPI.BRepPrimAPI_MakeHalfSpace(face, origin)
        hs.Build()
        halfspace = hs.Solid()

        #make the cut
        bc = BRepAlgoAPI.BRepAlgoAPI_Cut(shapeToSlice, halfspace)
        cutShape = bc.Shape()

        #search the shape for faces at the specified zlevel
        texp = TopExp.TopExp_Explorer()
        texp.Init(cutShape, TopAbs.TopAbs_FACE)
        foundFace = False
        while (texp.More()):
            face = ts.Face(texp.Current())
            if self._isAtZLevel(zLevel, face):
                foundFace = True
                logging.debug("Face is at zlevel" + str(zLevel))
                s.addFace(face, self.saveSliceFaces)
            texp.Next()

        #free memory
        face.Nullify()
        bc.Destroy()
        texp.Clear()
        texp.Destroy()

        if not foundFace:
            logging.warn("No faces found after slicing at zLevel " +
                         str(zLevel) + " !. Skipping This layer completely")
            return None
        else:
            return s
def draft_angle(event=None):
    S = BRepPrimAPI_MakeBox(200., 300., 150.).Shape()
    adraft = BRepOffsetAPI_DraftAngle(S)
    topExp = TopExp_Explorer()
    topExp.Init(S, TopAbs_FACE)
    while topExp.More():
        face = topods_Face(topExp.Current())
        surf = Handle_Geom_Plane_DownCast(BRep_Tool_Surface(face)).GetObject()
        dirf = surf.Pln().Axis().Direction()
        ddd = gp_Dir(0, 0, 1)
        if dirf.IsNormal(ddd, precision_Angular()):
            adraft.Add(face, ddd, math.radians(15), gp_Pln(gp_Ax3(gp_XOY())))
        topExp.Next()
    adraft.Build()
    display.DisplayShape(adraft.Shape(), update=True)
Beispiel #32
0
def draft_angle(event=None):
    S = BRepPrimAPI_MakeBox(200., 300., 150.).Shape()
    adraft = BRepOffsetAPI_DraftAngle(S)
    topExp = TopExp_Explorer()
    topExp.Init(S, TopAbs_FACE)
    while topExp.More():
        face = topods_Face(topExp.Current())
        surf = Handle_Geom_Plane_DownCast(BRep_Tool_Surface(face)).GetObject()
        dirf = surf.Pln().Axis().Direction()
        ddd = gp_Dir(0, 0, 1)
        if dirf.IsNormal(ddd, precision_Angular()):
            adraft.Add(face, ddd, math.radians(15), gp_Pln(gp_Ax3(gp_XOY())))
        topExp.Next()
    adraft.Build()
    display.DisplayShape(adraft.Shape(), update=True)
Beispiel #33
0
	def _makeSlice(self,shapeToSlice,zLevel):
		s = Slice();
		
		#change if layers are variable thickness
		s.sliceHeight = self.sliceHeight;		
		s.zLevel = zLevel;

		#make a cutting plane
		p = gp.gp_Pnt ( 0,0,zLevel );
			
		origin = gp.gp_Pnt(0,0,zLevel-1);
		csys = gp.gp_Ax3(p,gp.gp().DZ())
		cuttingPlane = gp.gp_Pln(csys);	
		bff = BRepBuilderAPI.BRepBuilderAPI_MakeFace(cuttingPlane);
		face = bff.Face();
		
		#odd, a halfspace is faster than a box?
		hs = BRepPrimAPI.BRepPrimAPI_MakeHalfSpace(face,origin);
		hs.Build();	
		halfspace = hs.Solid();
				
		#make the cut
		bc = BRepAlgoAPI.BRepAlgoAPI_Cut(shapeToSlice,halfspace);
		cutShape = bc.Shape();
		
		#search the shape for faces at the specified zlevel
		texp = TopExp.TopExp_Explorer();
		texp.Init(cutShape,TopAbs.TopAbs_FACE);
		foundFace = False;
		while ( texp.More() ):
			face = ts.Face(texp.Current());
			if self._isAtZLevel(zLevel,face):
				foundFace = True;
				logging.debug( "Face is at zlevel" + str(zLevel) );
				s.addFace(face,self.saveSliceFaces);
			texp.Next();
		
		#free memory
		face.Nullify();
		bc.Destroy();
		texp.Clear();
		texp.Destroy();
			
		if not foundFace:
			logging.warn("No faces found after slicing at zLevel " + str(zLevel) + " !. Skipping This layer completely");
			return None;
		else:				
			return s;		
Beispiel #34
0
    def mirrorInPlane(self, listOfShapes, axis='X'):

        local_coord_system = gp_Ax3(self.origin.toPnt(), self.zDir.toDir(),
                                    self.xDir.toDir())
        T = gp_Trsf()

        if axis == 'X':
            T.SetMirror(
                gp_Ax1(self.origin.toPnt(), local_coord_system.XDirection()))
        elif axis == 'Y':
            T.SetMirror(
                gp_Ax1(self.origin.toPnt(), local_coord_system.YDirection()))
        else:
            raise NotImplementedError

        resultWires = []
        for w in listOfShapes:
            mirrored = w.transformShape(Matrix(T))

            # attemp stitching of the wires
            resultWires.append(mirrored)

        return resultWires
Beispiel #35
0
def face():
    p1 = gp_Pnt()
    p2 = gp_Pnt()
    p3 = gp_Pnt()
    p4 = gp_Pnt()
    p5 = gp_Pnt()
    p6 = gp_Pnt()

    # The white Face
    sphere = gp_Sphere(gp_Ax3(gp_Pnt(0, 0, 0), gp_Dir(1, 0, 0)), 150)
    green_face = BRepBuilderAPI_MakeFace(sphere, 0.1, 0.7, 0.2, 0.9)

    # The red face
    p1.SetCoord(-15, 200, 10)
    p2.SetCoord(5, 204, 0)
    p3.SetCoord(15, 200, 0)
    p4.SetCoord(-15, 20, 15)
    p5.SetCoord(-5, 20, 0)
    p6.SetCoord(15, 20, 35)
    array = TColgp_Array2OfPnt(1, 3, 1, 2)
    array.SetValue(1, 1, p1)
    array.SetValue(2, 1, p2)
    array.SetValue(3, 1, p3)
    array.SetValue(1, 2, p4)
    array.SetValue(2, 2, p5)
    array.SetValue(3, 2, p6)
    curve = GeomAPI_PointsToBSplineSurface(array, 3, 8, GeomAbs_C2, 0.001).Surface()
    red_face = BRepBuilderAPI_MakeFace(curve, 1e-6)

    #The brown face
    circle = gp_Circ(gp_Ax2(gp_Pnt(0, 0, 0), gp_Dir(1, 0, 0)), 80)
    Edge1 = BRepBuilderAPI_MakeEdge(circle, 0, math.pi)
    Edge2 = BRepBuilderAPI_MakeEdge(gp_Pnt(0, 0, -80), gp_Pnt(0, -10, 40))
    Edge3 = BRepBuilderAPI_MakeEdge(gp_Pnt(0, -10, 40), gp_Pnt(0, 0, 80))

    ##TopoDS_Wire YellowWire
    MW1 = BRepBuilderAPI_MakeWire(Edge1.Edge(), Edge2.Edge(), Edge3.Edge())
    if MW1.IsDone():
        yellow_wire = MW1.Wire()
    brown_face = BRepBuilderAPI_MakeFace(yellow_wire)

    #The pink face
    p1.SetCoord(35, -200, 40)
    p2.SetCoord(50, -204, 30)
    p3.SetCoord(65, -200, 30)
    p4.SetCoord(35, -20, 45)
    p5.SetCoord(45, -20, 30)
    p6.SetCoord(65, -20, 65)
    array2 = TColgp_Array2OfPnt(1, 3, 1, 2)
    array2.SetValue(1, 1, p1)
    array2.SetValue(2, 1, p2)
    array2.SetValue(3, 1, p3)
    array2.SetValue(1, 2, p4)
    array2.SetValue(2, 2, p5)
    array2.SetValue(3, 2, p6)
    BSplineSurf = GeomAPI_PointsToBSplineSurface(array2, 3, 8, GeomAbs_C2,
                                                 0.001)
    aFace = BRepBuilderAPI_MakeFace(BSplineSurf.Surface(), 1e-6).Face()
    ##
    ##//2d lines
    P12d = gp_Pnt2d(0.9, 0.1)
    P22d = gp_Pnt2d(0.2, 0.7)
    P32d = gp_Pnt2d(0.02, 0.1)
    ##
    line1 = Geom2d_Line(P12d, gp_Dir2d((0.2-0.9), (0.7-0.1)))
    line2 = Geom2d_Line(P22d, gp_Dir2d((0.02-0.2), (0.1-0.7)))
    line3 = Geom2d_Line(P32d, gp_Dir2d((0.9-0.02), (0.1-0.1)))
    ##
    ##//Edges are on the BSpline surface
    Edge1 = BRepBuilderAPI_MakeEdge(line1.GetHandle(), BSplineSurf.Surface(),
                                    0, P12d.Distance(P22d)).Edge()
    Edge2 = BRepBuilderAPI_MakeEdge(line2.GetHandle(), BSplineSurf.Surface(),
                                    0, P22d.Distance(P32d)).Edge()
    Edge3 = BRepBuilderAPI_MakeEdge(line3.GetHandle(), BSplineSurf.Surface(),
                                    0, P32d.Distance(P12d)).Edge()
    ##
    Wire1 = BRepBuilderAPI_MakeWire(Edge1, Edge2, Edge3).Wire()
    Wire1.Reverse()
    pink_face = BRepBuilderAPI_MakeFace(aFace, Wire1).Face()
    breplib_BuildCurves3d(pink_face)

    display.DisplayColoredShape(green_face.Face(), 'GREEN')
    display.DisplayColoredShape(red_face.Face(), 'RED')
    display.DisplayColoredShape(pink_face, Quantity_Color(Quantity_NOC_PINK))
    display.DisplayColoredShape(brown_face.Face(), 'BLUE')
    display.DisplayColoredShape(yellow_wire, 'YELLOW', update=True)
def face():
    p1 = gp_Pnt()
    p2 = gp_Pnt()
    p3 = gp_Pnt()
    p4 = gp_Pnt()
    p5 = gp_Pnt()
    p6 = gp_Pnt()

    # The white Face
    sphere = gp_Sphere(gp_Ax3(gp_Pnt(0, 0, 0), gp_Dir(1, 0, 0)), 150)
    green_face = BRepBuilderAPI_MakeFace(sphere, 0.1, 0.7, 0.2, 0.9)

    # The red face
    p1.SetCoord(-15, 200, 10)
    p2.SetCoord(5, 204, 0)
    p3.SetCoord(15, 200, 0)
    p4.SetCoord(-15, 20, 15)
    p5.SetCoord(-5, 20, 0)
    p6.SetCoord(15, 20, 35)
    array = TColgp_Array2OfPnt(1, 3, 1, 2)
    array.SetValue(1, 1, p1)
    array.SetValue(2, 1, p2)
    array.SetValue(3, 1, p3)
    array.SetValue(1, 2, p4)
    array.SetValue(2, 2, p5)
    array.SetValue(3, 2, p6)
    curve = GeomAPI_PointsToBSplineSurface(array, 3, 8, GeomAbs_C2,
                                           0.001).Surface()
    red_face = BRepBuilderAPI_MakeFace(curve, 1e-6)

    #The brown face
    circle = gp_Circ(gp_Ax2(gp_Pnt(0, 0, 0), gp_Dir(1, 0, 0)), 80)
    Edge1 = BRepBuilderAPI_MakeEdge(circle, 0, math.pi)
    Edge2 = BRepBuilderAPI_MakeEdge(gp_Pnt(0, 0, -80), gp_Pnt(0, -10, 40))
    Edge3 = BRepBuilderAPI_MakeEdge(gp_Pnt(0, -10, 40), gp_Pnt(0, 0, 80))

    ##TopoDS_Wire YellowWire
    MW1 = BRepBuilderAPI_MakeWire(Edge1.Edge(), Edge2.Edge(), Edge3.Edge())
    if MW1.IsDone():
        yellow_wire = MW1.Wire()
    brown_face = BRepBuilderAPI_MakeFace(yellow_wire)

    #The pink face
    p1.SetCoord(35, -200, 40)
    p2.SetCoord(50, -204, 30)
    p3.SetCoord(65, -200, 30)
    p4.SetCoord(35, -20, 45)
    p5.SetCoord(45, -20, 30)
    p6.SetCoord(65, -20, 65)
    array2 = TColgp_Array2OfPnt(1, 3, 1, 2)
    array2.SetValue(1, 1, p1)
    array2.SetValue(2, 1, p2)
    array2.SetValue(3, 1, p3)
    array2.SetValue(1, 2, p4)
    array2.SetValue(2, 2, p5)
    array2.SetValue(3, 2, p6)
    BSplineSurf = GeomAPI_PointsToBSplineSurface(array2, 3, 8, GeomAbs_C2,
                                                 0.001)
    aFace = BRepBuilderAPI_MakeFace(BSplineSurf.Surface(), 1e-6).Face()
    ##
    ##//2d lines
    P12d = gp_Pnt2d(0.9, 0.1)
    P22d = gp_Pnt2d(0.2, 0.7)
    P32d = gp_Pnt2d(0.02, 0.1)
    ##
    line1 = Geom2d_Line(P12d, gp_Dir2d((0.2-0.9), (0.7-0.1)))
    line2 = Geom2d_Line(P22d, gp_Dir2d((0.02-0.2), (0.1-0.7)))
    line3 = Geom2d_Line(P32d, gp_Dir2d((0.9-0.02), (0.1-0.1)))
    ##
    ##//Edges are on the BSpline surface
    Edge1 = BRepBuilderAPI_MakeEdge(line1.GetHandle(), BSplineSurf.Surface(),
                                    0, P12d.Distance(P22d)).Edge()
    Edge2 = BRepBuilderAPI_MakeEdge(line2.GetHandle(), BSplineSurf.Surface(),
                                    0, P22d.Distance(P32d)).Edge()
    Edge3 = BRepBuilderAPI_MakeEdge(line3.GetHandle(), BSplineSurf.Surface(),
                                    0, P32d.Distance(P12d)).Edge()
    ##
    Wire1 = BRepBuilderAPI_MakeWire(Edge1, Edge2, Edge3).Wire()
    Wire1.Reverse()
    pink_face = BRepBuilderAPI_MakeFace(aFace, Wire1).Face()
    breplib_BuildCurves3d(pink_face)

    display.DisplayColoredShape(green_face.Face(), 'GREEN')
    display.DisplayColoredShape(red_face.Face(), 'RED')
    display.DisplayColoredShape(pink_face, Quantity_Color(Quantity_NOC_PINK))
    display.DisplayColoredShape(brown_face.Face(), 'BLUE')
    display.DisplayColoredShape(yellow_wire, 'YELLOW', update=True)
Beispiel #37
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:
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())
        # We want the highest Z face, so compare this to the previous faces
        aPnt = aPlane.Location()
        aZ = aPnt.Z()
        if aZ > zMax:
            zMax = aZ
            faceToRemove = aFace

    aFaceExplorer.Next()

facesToRemove = TopTools_ListOfShape()
facesToRemove.Append(faceToRemove)

myBody = BRepOffsetAPI_MakeThickSolid(myBody.Shape(), facesToRemove, -thickness / 50.0, 0.001)

# Set up our surfaces for the threading on the neck
neckAx2_Ax3 = gp_Ax3(neckLocation, gp_DZ())
aCyl1 = Geom_CylindricalSurface(neckAx2_Ax3, myNeckRadius * 0.99)
aCyl2 = Geom_CylindricalSurface(neckAx2_Ax3, myNeckRadius * 1.05)

# Set up the curves for the threads on the bottle's neck
aPnt = gp_Pnt2d(2.0 * math.pi, myNeckHeight / 2.0)
aDir = gp_Dir2d(2.0 * math.pi, myNeckHeight / 4.0)
anAx2d = gp_Ax2d(aPnt, aDir)

aMajor = 2.0 * math.pi
aMinor = myNeckHeight / 10.0

anEllipse1 = Geom2d_Ellipse(anAx2d, aMajor, aMinor)
anEllipse2 = Geom2d_Ellipse(anAx2d, aMajor, aMinor / 4.0)

anArc1 = Geom2d_TrimmedCurve(Handle_Geom2d_Ellipse(anEllipse1), 0, math.pi)
Beispiel #40
0
def round_tooth(wedge):
    round_x = 2.6
    round_z = 0.06 * pitch
    round_radius = pitch

    # Determine where the circle used for rounding has to start and stop
    p2d_1 = gp_Pnt2d(top_radius - round_x, 0)
    p2d_2 = gp_Pnt2d(top_radius, round_z)

    # Construct the rounding circle
    round_circle = GccAna_Circ2d2TanRad(p2d_1, p2d_2, round_radius, 0.01)
    if (round_circle.NbSolutions() != 2):
        exit(-2)

    round_circle_2d_1 = round_circle.ThisSolution(1)
    round_circle_2d_2 = round_circle.ThisSolution(2)

    if (round_circle_2d_1.Position().Location().Coord()[1] >= 0):
        round_circle_2d = round_circle_2d_1
    else:
        round_circle_2d = round_circle_2d_2

    # Remove the arc used for rounding
    trimmed_circle = GCE2d_MakeArcOfCircle(round_circle_2d, p2d_1,
                                           p2d_2).Value()

    # Calculate extra points used to construct lines
    p1 = gp_Pnt(p2d_1.X(), 0, p2d_1.Y())
    p2 = gp_Pnt(p2d_2.X(), 0, p2d_2.Y())
    p3 = gp_Pnt(p2d_2.X() + 1, 0, p2d_2.Y())
    p4 = gp_Pnt(p2d_2.X() + 1, 0, p2d_1.Y() - 1)
    p5 = gp_Pnt(p2d_1.X(), 0, p2d_1.Y() - 1)

    # Convert the arc and four extra lines into 3D edges
    plane = gp_Pln(gp_Ax3(gp_Origin(), gp_DY().Reversed(), gp_DX()))
    arc1 = BRepBuilderAPI_MakeEdge(geomapi_To3d(trimmed_circle, plane)).Edge()
    lin1 = BRepBuilderAPI_MakeEdge(p2, p3).Edge()
    lin2 = BRepBuilderAPI_MakeEdge(p3, p4).Edge()
    lin3 = BRepBuilderAPI_MakeEdge(p4, p5).Edge()
    lin4 = BRepBuilderAPI_MakeEdge(p5, p1).Edge()

    # Make a wire composed of the edges
    round_wire = BRepBuilderAPI_MakeWire(arc1)
    round_wire.Add(lin1)
    round_wire.Add(lin2)
    round_wire.Add(lin3)
    round_wire.Add(lin4)

    # Turn the wire into a face
    round_face = BRepBuilderAPI_MakeFace(round_wire.Wire()).Shape()

    # Revolve the face around the Z axis over the tooth angle
    rounding_cut_1 = BRepPrimAPI_MakeRevol(round_face, gp_OZ(),
                                           tooth_angle).Shape()

    # Construct a mirrored copy of the first cutting shape
    mirror = gp_Trsf()
    mirror.SetMirror(gp_XOY())
    mirrored_cut_1 = BRepBuilderAPI_Transform(rounding_cut_1, mirror,
                                              True).Shape()

    # and translate it so that it ends up on the other side of the wedge
    translate = gp_Trsf()
    translate.SetTranslation(gp_Vec(0, 0, thickness))
    rounding_cut_2 = BRepBuilderAPI_Transform(mirrored_cut_1, translate,
                                              False).Shape()

    # Cut the wedge using the first and second cutting shape
    cut_1 = BRepAlgoAPI_Cut(wedge, rounding_cut_1).Shape()
    cut_2 = BRepAlgoAPI_Cut(cut_1, rounding_cut_2).Shape()

    return cut_2
canvas.Init3dViewer()
viewer = canvas._3dDisplay
print viewer

box = BRepPrimAPI.BRepPrimAPI_MakeBox(20,30,40)

ax = gp_Ax2()
ax.Translate(gp_Vec(50,50,50))

cyl_len = 40
radius = 10
angle = pi*1.5

cyl = BRepPrimAPI.BRepPrimAPI_MakeCylinder(radius, cyl_len)

ax = gp_Ax3()
ax.SetLocation(gp_Pnt(50,60,70))
ax.SetDirection(gp_Dir(gp_Vec(1,1,1)))
trans = gp_Trsf()
trans.SetTransformation(ax)

t_cyl = BRepBuilderAPI.BRepBuilderAPI_Transform(cyl.Shape(), trans)

viewer.DisplayShape(box.Shape())
viewer.DisplayShape(t_cyl.Shape())

app.MainLoop()

##Building the resulting compund
#aRes = TopoDS.TopoDS_Compound()
#aBuilder = BRep.BRep_Builder()
Beispiel #42
0
 def get_transform(self):
     d = self.declaration
     t = gp_Trsf()
     #p = d.position
     t.SetTransformation(gp_Ax3(d.axis))  #gp_Vec(p.X(), p.Y(), p.Z()))
     return t
Beispiel #43
0
if __name__ == '__main__':
    argvs = sys.argv
    parser = OptionParser()
    parser.add_option("--px", dest="px", default=0.0, type="float")
    parser.add_option("--dx", dest="dx", default=0.0, type="float")
    parser.add_option("--py", dest="py", default=0.0, type="float")
    parser.add_option("--dy", dest="dy", default=0.0, type="float")
    opt, argc = parser.parse_args(argvs)

    ax, pln = def_ax(0, 0, 0, lx=100, ly=100)
    m1_ax, m1_pln = def_ax(0, 0, 470, dx=-45)
    m2_ax, m2_pln = def_ax(0, -250, 470, dx=45, dy=180)
    wg_ax, wg_pln = def_ax(0, -250, 470 + 360, lx=100, ly=100, dy=0)

    ax0 = gp_Ax3(gp_Pnt(opt.px, opt.py, 0), gp_Dir(0, 0, 1), gp_Dir(1, 0, 0))
    rot_axs(ax0, gp_Ax1(ax0.Location(), ax0.XDirection()), opt.dx)
    rot_axs(ax0, gp_Ax1(ax0.Location(), ax0.YDirection()), opt.dy)
    pnt = ax0.Location()
    vec = dir_to_vec(ax0.Direction())

    m1_pnt, m1_vec = reflect(pnt, vec, m1_ax)
    m2_pnt, m2_vec = reflect(m1_pnt, m1_vec, m2_ax)
    wg_pnt, wg_vec = reflect(m2_pnt, m2_vec, wg_ax)
    wg_vec.Reverse()
    wg_p = wg_ax.Location()
    print(np.rad2deg(get_angle(wg_ax, wg_vec, dir_to_vec(wg_ax.Direction()))))
    print(wg_pnt.X() - wg_p.X(), wg_pnt.Y() - wg_p.Y())
    """
    display, start_display, add_menu, add_function_to_menu = init_display()
    display.DisplayShape (pnt)
 def CreateConstructionGeometry(self):
     """
     Creates the plane and vector used for projecting wetted area
     """
     self.XoY_Plane = Geom_Plane(gp_Ax3(gp_XOY()))
     self.ProjVectorZ = gp_Dir(0, 0, 1)