本文整理汇总了Python中OCC.gp.gp_Trsf函数的典型用法代码示例。如果您正苦于以下问题:Python gp_Trsf函数的具体用法?Python gp_Trsf怎么用?Python gp_Trsf使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了gp_Trsf函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _cut_finger_notch
def _cut_finger_notch(front, dx, dz):
finger_width = 2.0
finger_height = 1.0
front = _cut(front, _box(_pnt(dx / 2. - finger_width / 2., 0, dz - finger_height),
finger_width, THICKNESS_0, finger_height))
cyl = BRepPrimAPI_MakeCylinder(finger_width / 2.0, THICKNESS_0).Shape()
tr = gp.gp_Trsf()
tr.SetRotation(gp.gp_Ax1(gp.gp_Pnt(0, 0, 0), gp.gp_Dir(1, 0, 0)), math.pi / 2.0)
tr2 = gp.gp_Trsf()
tr2.SetTranslation(gp.gp_Vec(dx / 2., THICKNESS_0, dz - finger_height))
tr2.Multiply(tr)
cyl = BRepBuilderAPI_Transform(cyl, tr2, True).Shape()
front = _cut(front, cyl)
return front
示例2: scale
def scale(occtopology, scale_factor, ref_pypt):
"""
This function uniformly scales an OCCtopology based on the reference point and the scale factor.
Parameters
----------
occtopology : OCCtopology
The OCCtopology to be scaled.
OCCtopology includes: OCCshape, OCCcompound, OCCcompsolid, OCCsolid, OCCshell, OCCface, OCCwire, OCCedge, OCCvertex
scale_factor : float
The scale factor.
ref_pypt : tuple of floats
The OCCtopology will scale in reference to this point.
A pypt is a tuple that documents the xyz coordinates of a pt e.g. (x,y,z)
Returns
-------
scaled topology : OCCtopology (OCCshape)
The scaled OCCtopology.
"""
xform = gp_Trsf()
gp_pnt = construct.make_gppnt(ref_pypt)
xform.SetScale(gp_pnt, scale_factor)
brep = BRepBuilderAPI_Transform(xform)
brep.Perform(occtopology, True)
trsfshape = brep.Shape()
return trsfshape
示例3: rotate
def rotate(occtopology, rot_pypt, pyaxis, degree):
"""
This function rotates an OCCtopology based on the rotation point, an axis and the rotation degree.
Parameters
----------
occtopology : OCCtopology
The OCCtopology to be rotated.
OCCtopology includes: OCCshape, OCCcompound, OCCcompsolid, OCCsolid, OCCshell, OCCface, OCCwire, OCCedge, OCCvertex
rot_pypt : tuple of floats
The OCCtopology will rotate in reference to this point.
A pypt is a tuple that documents the xyz coordinates of a pt e.g. (x,y,z)
pyaxis : tuple of floats
The OCCtopology will rotate along this axis.
A pyaxis is a tuple that documents the xyz of a direction e.g. (x,y,z)
degree : float
The degree of rotation.
Returns
-------
rotated topology : OCCtopology (OCCshape)
The rotated OCCtopology.
"""
from math import radians
gp_ax3 = gp_Ax1(gp_Pnt(rot_pypt[0], rot_pypt[1], rot_pypt[2]), gp_Dir(pyaxis[0], pyaxis[1], pyaxis[2]))
aTrsf = gp_Trsf()
aTrsf.SetRotation(gp_ax3, radians(degree))
rot_brep = BRepBuilderAPI_Transform(aTrsf)
rot_brep.Perform(occtopology, True)
rot_shape = rot_brep.Shape()
return rot_shape
示例4: move
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
示例5: copyToZ
def copyToZ(self, z, layerNo):
"makes a copy of this slice, transformed to the specified z height"
theCopy = Slice()
theCopy.zLevel = z
theCopy.fillAngle = self.fillAngle
theCopy.layerNo = layerNo
theCopy.thickness = self.thickness
# make transformation
p1 = gp.gp_Pnt(0, 0, 0)
p2 = gp.gp_Pnt(0, 0, z)
xform = gp.gp_Trsf()
xform.SetTranslation(p1, p2)
bt = BRepBuilderAPI.BRepBuilderAPI_Transform(xform)
# copy all of the faces
for f in self.faces:
bt.Perform(f.face, True)
newFace = Face(OCCUtil.cast(bt.Shape()))
# copy shells
for shell in f.shellWires:
# print shell
bt.Perform(shell, True)
newFace.shellWires.append(OCCUtil.cast(bt.Shape()))
# copy fillWires
for fill in f.fillWires:
bt.Perform(fill, True)
newFace.shellWires.append(OCCUtil.cast(bt.Shape()))
theCopy.addFace(newFace)
return theCopy
示例6: occ
def occ(display):
'''
display, start_display, add_menu, add_function_to_menu = init_display()
my_box = BRepPrimAPI_MakeBox(10., 20., 30.).Shape()
display.DisplayShape(my_box, update=True)
#start_display()
'''
display.EraseAll()
ais_boxshp = build_shape(display)
ax1 = gp_Ax1(gp_Pnt(25., 25., 25.), gp_Dir(0., 0., 1.))
aCubeTrsf = gp_Trsf()
angle = 0.0
tA = time.time()
n_rotations = 200
for i in range(n_rotations):
aCubeTrsf.SetRotation(ax1, angle)
aCubeToploc = TopLoc_Location(aCubeTrsf)
display.Context.SetLocation(ais_boxshp, aCubeToploc)
display.Context.UpdateCurrentViewer()
angle += 2*pi / n_rotations
print("%i rotations took %f" % (n_rotations, time.time() - tA))
示例7: get_transform
def get_transform(self):
d = self.declaration
t = gp_Trsf()
#: TODO: Order matters... how to configure it???
if d.mirror:
try:
p,v = d.mirror
except ValueError:
raise ValueError("You must specify a tuple containing a (point,direction)")
t.SetMirror(gp_Ax1(gp_Pnt(*p),
gp_Dir(*v)))
if d.scale:
try:
p,s = d.scale
except ValueError:
raise ValueError("You must specify a tuple containing a (point,scale)")
t.SetScale(gp_Pnt(*p),s)
if d.translate:
t.SetTranslation(gp_Vec(*d.translate))
if d.rotate:
try:
p,v,a = d.rotate
except ValueError:
raise ValueError("You must specify a tuple containing a (point,direction,angle)")
t.SetRotation(gp_Ax1(gp_Pnt(*p),
gp_Dir(*v)),a)
return t
示例8: copyToZ
def copyToZ(self, z):
"makes a copy of this slice, transformed to the specified z height"
theCopy = Slice()
theCopy.zLevel = z
theCopy.zHeight = self.zHeight
theCopy.sliceHeight = self.sliceHeight
theCopy.fillWidth = self.fillWidth
theCopy.hatchDir = self.hatchDir
theCopy.checkSum = self.checkSum
# make transformation
p1 = gp.gp_Pnt(0, 0, 0)
p2 = gp.gp_Pnt(0, 0, z)
xform = gp.gp_Trsf()
xform.SetTranslation(p1, p2)
bt = BRepBuilderAPI.BRepBuilderAPI_Transform(xform)
# copy all of the faces
for f in hSeqIterator(self.faces):
bt.Perform(f, True)
theCopy.addFace(Wrappers.cast(bt.Shape()))
# copy all of the fillWires
for w in hSeqIterator(self.fillWires):
bt.Perform(w, True)
# TestDisplay.display.showShape(bt.Shape() );
theCopy.fillWires.Append(Wrappers.cast(bt.Shape()))
# copy all of the fillEdges
for e in hSeqIterator(self.fillEdges):
bt.Perform(e, True)
# TestDisplay.display.showShape(bt.Shape() );
theCopy.fillEdges.Append(Wrappers.cast(bt.Shape()))
return theCopy
示例9: _add_stuff_changed
def _add_stuff_changed(self, old, new):
for i in xrange(20):
brep = BRepPrimAPI_MakeCylinder(random.random()*50, random.random()*50).Shape()
trsf = gp_Trsf()
trsf.SetTranslation(gp_Vec(random.random()*100, random.random()*100, random.random()*100))
brep.Move(TopLoc_Location(trsf))
self.shapes.append(brep)
示例10: rotate
def rotate(brep, axe, degree, copy=False):
"""Rotates the brep
Originally from pythonocc-utils : might add dependency on this?
Parameters
----------
brep : shape to rotate
axe : axis of rotation
degree : Number of degrees to rotate through
copy : bool (default=False)
Returns
-------
BRepBuilderAPI_Transform.Shape : Shape handle
The handle to the rotated shape
"""
trns = gp_Trsf()
trns.SetRotation(axe, np.radians(degree))
brep_trns = BRepBuilderAPI_Transform(brep, trns, copy)
brep_trns.Build()
return brep_trns.Shape()
示例11: add_labels
def add_labels(product,lr,st):
if product.links:
for link in product.links:
if link.product.doc_id != product.doc_id:
if not link.product.label_reference:
lr_2 = TDF_LabelSequence()
si = StepImporter(link.product.doc_path)
shape_tool = si.shape_tool
shape_tool.GetFreeShapes(lr_2)
add_labels(link.product, lr_2.Value(1), shape_tool)
link.product.label_reference = lr_2.Value(1)
# FIXME: free memory
del si
gc.collect()
for d in range(link.quantity):
transformation = gp_Trsf()
loc = link.locations[d]
transformation.SetValues(loc.x1, loc.x2, loc.x3, loc.x4,
loc.y1, loc.y2, loc.y3, loc.y4,
loc.z1, loc.z2, loc.z3, loc.z4,
1, 1)
new_label = st.AddComponent(lr, link.product.label_reference,
TopLoc_Location(transformation))
set_label_name(new_label, link.names[d])
示例12: translate
def translate(self, vec):
tr = gp_Trsf()
tr.SetTranslation(gp_Vec(*vec))
loc = TopLoc_Location(tr)
self.shape.Move(loc)
self.__extract_curves()
return self
示例13: scale
def scale(self, scale):
tr = gp_Trsf()
#tr.SetScale(gp_Pnt(*point), scale)
tr.SetScaleFactor(scale)
self.shape = BRepBuilderAPI_Transform(self.shape, tr).Shape()
self.__extract_curves()
return self
示例14: init_display
def init_display(backend_str=None, size=(1000, 600)):
QtCore, QtGui, QtWidgets, QtOpenGL = get_qt_modules()
class MainWindow(QtWidgets.QMainWindow):
def __init__(self, *args):
QtWidgets.QMainWindow.__init__(self, *args)
self.resize(size[0], size[1])
self.Viewer = qtViewer2(self)
self.setCentralWidget(self.Viewer)
self.centerOnScreen()
def centerOnScreen(self):
'''Centers the window on the screen.'''
resolution = QtWidgets.QDesktopWidget().screenGeometry()
self.move((resolution.width() / 2) - (self.frameSize().width() / 2),
(resolution.height() / 2) - (self.frameSize().height() / 2))
# following couple of lines is a twek to enable ipython --gui='qt'
app = QtWidgets.QApplication.instance() # checks if QApplication already exists
if not app: # create QApplication if it doesnt exist
app = QtWidgets.QApplication(sys.argv)
win = MainWindow()
win.show()
win.Viewer.InitDriver()
display = win.Viewer._display
# background gradient
display.set_bg_gradient_color(206, 215, 222, 128, 128, 128)
# display black trihedron
display.display_trihedron()
def start_display():
win.raise_() # make the application float to the top
app.exec_()
win.display = display
win.show()
win.Viewer.init2()
# create and add shapes
box = BRepPrimAPI.BRepPrimAPI_MakeBox(60, 30, 10).Shape()
cyl = BRepPrimAPI.BRepPrimAPI_MakeCylinder(25, 40).Shape()
tr = gp.gp_Trsf()
tr.SetTranslation(gp.gp_Vec(0, 50, 0))
loc = TopLoc.TopLoc_Location(tr)
moved_box = box.Moved(loc)
# these shapes can be deleted by selecting them and pressing 'Del':
win.Viewer.doc_ctrl.add(box)
win.Viewer.doc_ctrl.add(cyl)
# this shape cannot be deleted in this implementation:
win.Viewer.doc_ctrl.add(moved_box)
win.Viewer.repaint(Update=False)
display.FitAll()
return display, start_display
示例15: translate
def translate(self, target):
transform = gp.gp_Trsf()
transform.SetTranslation(gp.gp_Vec(*target))
# FIXME: this needs some explanation... should it be here?
needle_transform = BRepTransform(self.needle, transform, False)
needle_transform.Build()
self.needle = needle_transform.Shape()