本文整理汇总了Python中Wrappers.cast方法的典型用法代码示例。如果您正苦于以下问题:Python Wrappers.cast方法的具体用法?Python Wrappers.cast怎么用?Python Wrappers.cast使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Wrappers
的用法示例。
在下文中一共展示了Wrappers.cast方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: copyToZ
# 需要导入模块: import Wrappers [as 别名]
# 或者: from Wrappers import cast [as 别名]
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
示例2: makeHexArray
# 需要导入模块: import Wrappers [as 别名]
# 或者: from Wrappers import cast [as 别名]
def makeHexArray(self,bottomLeftCenter, countX, countY ):
"""
makes an array of hexagons
bottomLeftCenter is the center of the top left hex, as a three-element tuple
countX is the number of hexes in the x direction
countY is the number of hexes in the y direction
returns a list of wires representing a hexagon fill pattern
"""
pattern = self.makePeriodic(bottomLeftCenter);
wireBuilder = BRepBuilderAPI.BRepBuilderAPI_MakeWire(pattern);
#make horizontal array
tsf = gp.gp_Trsf();
pDist = 2.0 * self.cartesianSpacing()[0];
tsf.SetTranslation(gp.gp_Pnt(0,0,0),gp.gp_Pnt(pDist ,0,0));
tx = BRepBuilderAPI.BRepBuilderAPI_Transform(tsf);
currentShape = pattern;
for i in range(1,int((countX/2)+1)):
tx.Perform(currentShape,False);
currentShape = tx.Shape();
#display.DisplayShape(currentShape);
wireBuilder.Add(Wrappers.cast(currentShape));
#create an array by alternately offsetting one cell right and
#moving down
topHalf = wireBuilder.Wire();
#topHalf= approximatedWire(topHalf);
wires=[];
wires.append(topHalf);
dY = self.cartesianSpacing()[1]/2.0;
dX = self.cartesianSpacing()[0];
####TODO// performance note. This method takes about 31ms to compute 1000x1000 hex.
# pretty good, except that nearly 50% of the time is spent in makeTransform!!!
# a much better method would be to use the same transform object somehow
for i in range(1,int(countY*2)):
if i % 2 == 0:
t = makeTransform(0,dY*i,0);
else:
t = makeTransform(dX,dY*i,0);
t.Perform(topHalf,False);
w = Wrappers.cast(t.Shape());
#approximate the wire
#wires.append ( approximatedWire(w));
wires.append( w);
#display.DisplayShape(wires);
return wires;
示例3: addWire
# 需要导入模块: import Wrappers [as 别名]
# 或者: from Wrappers import cast [as 别名]
def addWire(self,wire,type):
"add all the edges of a wire. They will be connected together."
"type is the node type for each edge"
#for finding an edge node
wr = Wrappers.Wire(wire);
self.edgeSeq = wr.edgesAsSequence();
firstNode = None;
lastNode = None;
last = None;
for i in range(1,self.edgeSeq.Length()+1):
edge = Wrappers.cast(self.edgeSeq.Value(i));
te = Wrappers.Edge(edge);
newnode = EdgeNode(te,type);
self.addNode(newnode);
if last:
self.linkPrev( newnode,last);
self.linkNext(last,newnode );
last = newnode;
if i == 1:
firstNode = newnode;
if i == self.edgeSeq.Length():
lastNode = newnode;
#link last and first edge if the wire is closed
if wire.Closed():
self.linkPrev( firstNode,lastNode);
self.linkNext( lastNode,firstNode);
示例4: addBoundaryWire
# 需要导入模块: import Wrappers [as 别名]
# 或者: from Wrappers import cast [as 别名]
def addBoundaryWire(self,wire):
#for finding an edge node
wr = Wrappers.Wire(wire);
eS = wr.edgesAsSequence();
for i in range(1,eS.Length()+1):
e = Wrappers.cast(eS.Value(i));
self.addSingleBoundaryEdge(e);
示例5: loopWire
# 需要导入模块: import Wrappers [as 别名]
# 或者: from Wrappers import cast [as 别名]
def loopWire(w):
topexp = TopExp.TopExp_Explorer();
topexp.Init(w,TopAbs.TopAbs_EDGE);
edges = [];
while topexp.More():
currentEdge = Wrappers.cast(topexp.Current());
edges.append(currentEdge);
topexp.Next();
return edges;
示例6: addWire
# 需要导入模块: import Wrappers [as 别名]
# 或者: from Wrappers import cast [as 别名]
def addWire(self,wire,type):
"add all the edges of a wire. They will be connected together."
"each edge is added at its full length"
#for finding an edge node
wr = Wrappers.Wire(wire);
eS = wr.edgesAsSequence();
for i in range(1,eS.Length()+1):
e = Wrappers.cast(eS.Value(i));
self.addEdge(e,type);
示例7: boundarypixmapFromFace
# 需要导入模块: import Wrappers [as 别名]
# 或者: from Wrappers import cast [as 别名]
def boundarypixmapFromFace(face):
"""
creates a pixel map containing only the boundaries of the object.
the shape is approximated with straight lines, and vertices are marked
with different values to help re-construct the lines later on.
Some c++ optimizaion woudl really speed this up.
"""
PIXEL = 0.02;
DEFLECTION = PIXEL / 4.0;
#get bounding box
(xMin,yMin,zMin,xMax,yMax,zMax) = boundingBox([face]);
#make pixmap
pixmap = pixmaptest.pixmap((xMin,yMin),(xMax,yMax),PIXEL);
#approximate each wire with a set of segments
bb = TopExp.TopExp_Explorer();
bb.Init(face,TopAbs.TopAbs_WIRE);
while bb.More():
#print "plotting wire"
w = Wrappers.Wire(Wrappers.cast(bb.Current()));
#divide the edge into discrete segments
lastPnt = None;
for e in w.edges2():
#for each edge, set vertices, and compute points on the edge
ew = Wrappers.Edge(e);
lastPnt = None;
for pnt in ew.discretePoints(DEFLECTION):
pixmap.set(tP(pnt),2);
#plot the line
if lastPnt != None: pixmap.drawLine(tP(lastPnt),tP(pnt) );
lastPnt = pnt;
bb.Next();
return pixmap;
示例8: splitWire
# 需要导入模块: import Wrappers [as 别名]
# 或者: from Wrappers import cast [as 别名]
def splitWire(wire, ipoints):
"""
ipoints is a list of intersection points.
returns a list of wires inside the intersection point
BASELINE PERFORMANCE: 11 ms per call for splitwiretest
"""
#load original wire
#we make an important assumption that the wire is organized from
#left to right or from right to left, and starts outside the boundaries.
#this allows the scanline algorithm to define which segments are 'inside'
#wr = Wrappers.Wire(wire);
#assume edges are in ascending x order also
#very interesting OCC weird thing: topexp is much faster than wireexplorer
topexp = TopExp.TopExp_Explorer();
topexp.Init(wire,TopAbs.TopAbs_EDGE);
#sort intersection points by ascending X location
ix = sorted(ipoints,key = lambda p: p.point.X() );
inside = False;
edges = []; #a list of edges for the current wire.
iEdge = 0;
iIntersection=0;
#TODO: handle odd number of intersections
#the last parameter on the current edge.
#it is either the first parameter on the current edge,
#or the last intersection point on the edge.
currentEdge = Wrappers.cast(topexp.Current());
currentEdgeBounds = brepTool.Range(currentEdge);
startParam = currentEdgeBounds[0];
#print "handling %d intersections" % len(ix)
while iIntersection < len(ix) and ( topexp.More() ) :
currentIntersection = ix[iIntersection];
if hashE(currentEdge) == currentIntersection.hash:
#current edge matches intersection point
if inside:
#transition to outside: add this part edge
currentEdgeBounds = brepTool.Range(currentEdge);
newEdge = Wrappers.trimmedEdge(currentEdge,startParam,currentIntersection.param);
#TestDisplay.display.showShape(newEdge);
edges.append(newEdge);
#move to next point, store last intersection
iIntersection += 1;
startParam = currentIntersection.param;
inside = not inside;
else:
#edges do not match
if inside:
currentEdgeBounds = brepTool.Range(currentEdge);
if startParam == currentEdgeBounds[0]:
edges.append(currentEdge);
else:
newEdge = Wrappers.trimmedEdge(currentEdge,startParam, currentEdgeBounds[1] );
edges.append(newEdge);
#move to next edge
topexp.Next();
currentEdge = Wrappers.cast(topexp.Current());
startParam = currentEdgeBounds[0];
#print "returning %d edges" % len(edges)
return edges;
示例9: splitWire
# 需要导入模块: import Wrappers [as 别名]
# 或者: from Wrappers import cast [as 别名]
def splitWire(wire, ipoints):
"""
ipoints is a list of intersection points.
returns a list of wires inside the intersection point
this method must also work for a 'wire' consisting of a single
edge. more than one intersection point can be on each edge,
but all of the ipoints are expected to be on edges in the provided wire.
BASELINE PERFORMANCE: 11 ms per call for splitwiretest
returns a list of lists.
each element in the top list is a chain of connected edges.
each element in that list is an edge ( or part of an edge )
so, for example, suppose you compute a wire that has 100 edges, and there are 4 intersection points.
in this case, there will be two elements returned, and each element would contain a list of edges
between the two segments.
---E1---+---E2---+-X-E3---+---E4--X--+---E5---
will return [ [E1,E2], [ E3,E4 ] ]
"""
topexp = TopExp.TopExp_Explorer()
topexp.Init(wire, TopAbs.TopAbs_EDGE)
# sort intersection points by ascending X location
ix = sorted(ipoints, key=lambda p: p.point.X())
edgeList = []
assert (len(ipoints) % 2) == 0
for i in range(0, len(ipoints), 2):
# process intersection points in pairs
# TODO: this could be done more cleanly with a pairwise iterator
currentIntersection = ix[i]
nextIntersection = ix[i + 1]
# if they are on the same edge, simply add a trimmed edge.
# in this case,
if currentIntersection.hash == nextIntersection.hash:
edgeList.append(
[Wrappers.trimmedEdge(currentIntersection.edge, currentIntersection.param, nextIntersection.param)]
)
else:
# intersections are not on the same edge.
# add the fraction of the first edge
(bp, ep) = brepTool.Range(currentIntersection.edge)
edges = []
# print "adding piece of start edge."
edges.append(Wrappers.trimmedEdge(currentIntersection.edge, currentIntersection.param, ep))
# pick up whole edges between the first intersection and the next one
# loop till current edge is same as current intersection
while topexp.Current().__hash__() != currentIntersection.hash:
topexp.Next()
# advance to next edge
topexp.Next()
# add edges till current edge is same as next intersection
# most of the performance suckage is happening here, with gc associated with these
# edge objects. If that gets fixed, we'll get a huge speed boost. about 33% of total time is saved.
while topexp.Current().__hash__() != nextIntersection.hash:
edge = Wrappers.cast(topexp.Current())
edges.append(edge)
# print "adding middle edge"
topexp.Next()
# add the last edge
(bp, ep) = brepTool.Range(nextIntersection.edge)
edges.append(Wrappers.trimmedEdge(nextIntersection.edge, bp, nextIntersection.param))
# print "adding last piece of edge"
edgeList.append(edges)
return edgeList