本文整理汇总了Python中OCC.Utils.Topology.Topo类的典型用法代码示例。如果您正苦于以下问题:Python Topo类的具体用法?Python Topo怎么用?Python Topo使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Topo类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: on_change_selection
def on_change_selection(self):
new_id = self.edge_id
input = self.input
label = self.label
if not all((input, label)): return
input_shape = input.shape
sel_label = self.label.FindChild(4)
selector = TNaming.TNaming_Selector(sel_label)
self.selector = selector
topo = Topo(input_shape)
self._n_edges = topo.number_of_edges()
for i,edge in enumerate(topo.edges()):
if i==new_id:
selector.Select(edge, input_shape)
print "got selection!"
break
else:
print "no selection"
self.modified = False
self.modified = True
开发者ID:mortbauer,项目名称:pythonocc,代码行数:26,代码来源:occ_model.py
示例2: offset_cube
def offset_cube(event=None):
# smoothed
# S1 = BRepPrimAPI_MakeBox(150,200,110).Shape()
# offsetA = BRepOffsetAPI_MakeOffsetShape(S1,60,0.01)
# display.EraseAll()
# display.Context
# display.DisplayColoredShape(S1, 'BLUE')
# offA = display.DisplayColoredShape(offsetA.Shape(), 'GREEN')
# display.Context.SetTransparency( offA, 0.3 )
# sharp
S2 = BRepPrimAPI_MakeBox(gp_Pnt(300,0,0),220,140,180).Shape()
offsetB = BRepOffsetAPI_MakeOffsetShape(S2,-20,0.01,BRepOffset_Skin,False,False,GeomAbs_Arc)
offB = display.DisplayColoredShape(S2, 'BLUE')
display.Context.SetTransparency( offB, 0.3 )
display.DisplayColoredShape(offsetB.Shape(), 'GREEN')
from OCC.TCollection import TCollection_ExtendedString
topo = Topo(S2)
faces = topo.faces()
# faceA, faceB = topo.faces_from_edge(topo.edges().next())
faceA = faces.next()
faces.next();faces.next(); faces.next()
faceB = faces.next()
dim = AIS_LengthDimension(faceA, faceB, 120, TCollection_ExtendedString('jelle'))
dim.SetValue(30)
display.Context.Display(dim.GetHandle())
display.FitAll()
开发者ID:dbarbier,项目名称:pythonocc,代码行数:30,代码来源:topology_local_operations.py
示例3: makeOffsets
def makeOffsets(wire,d=True):
numOffsets = 0;
if d: display.DisplayColoredShape(startWire,'YELLOW');
STEP = 0.5;
for offset in Util.frange6(0.5,4.0,STEP):
#print "offsetting by %0.3f" % offset
o = OCCUtil.offsetWire(startWire,offset*(-1.0));
numOffsets+=1;
if d: display.DisplayColoredShape(o, 'RED');
o2 = OCCUtil.offsetWire(startWire,offset*(-1.0) + (STEP/2.0) );
numOffsets+=1;
#create a naive centerline by setting in( which could conflict with others )
#if d: display.DisplayColoredShape(o2,'GREEN');
#now offset back out to create centerline. if the result is a compound, then we must offset each member wire
if o.ShapeType() == TopAbs.TopAbs_COMPOUND:
t = Topo(o);
for w in t.wires():
w2 = OCCUtil.offsetWire(w,STEP*(0.5));
numOffsets+=1;
if d: display.DisplayColoredShape(w2, 'BLUE');
else: #wire
o2 = OCCUtil.offsetWire(OCCUtil.cast(o),STEP*(0.5));
numOffsets+=1;
if d: display.DisplayColoredShape(o2, 'WHITE');
return numOffsets;
开发者ID:adam-urbanczyk,项目名称:emcfab,代码行数:30,代码来源:testOffsets.py
示例4: makeSection2
def makeSection2(self, cuttingPlane, shapeToSection, zLevel):
"""
Uses BrepSection Algo. this generally returns a list of wires, not a face
"""
# section is certainly faster, but produces only edges.
# those have to be re-organized into wires, probably
# using ShapeAnalysis_WireOrder
face = BRepBuilderAPI.BRepBuilderAPI_MakeFace(cuttingPlane).Shape()
# Computes Shape/Plane intersection
section = BRepAlgoAPI.BRepAlgoAPI_Section(self.solid.shape, face)
# section = BRepAlgo.BRepAlgo_Section(self.solid.shape,face);
section.Build()
if section.IsDone():
# Topology.dumpTopology(section.Shape());
# what we got back was a compound of edges
t = Topo(section.Shape())
wb = OCCUtil.MultiWireBuilder()
for e in t.edges():
wb.addEdge(e)
wires = wb.getWires()
print wires
for w in wires:
Topology.dumpTopology(w)
return wires
else:
raise Exception("Could not compute Section!")
开发者ID:adam-urbanczyk,项目名称:emcfab,代码行数:28,代码来源:Slicer.py
示例5: test_brepfeat_prism
def test_brepfeat_prism(self):
print 'Test: brepfeat prism'
box = BRepPrimAPI_MakeBox(400, 250, 300).Shape()
faces = Topo(box).faces()
for i in range(5):
face = faces.next()
srf = BRep_Tool_Surface(face)
c = gp_Circ2d(gp_Ax2d(gp_Pnt2d(200, 130),
gp_Dir2d(1, 0)), 75)
circle = Geom2d_Circle(c).GetHandle()
wire = BRepBuilderAPI_MakeWire()
wire.Add(BRepBuilderAPI_MakeEdge(circle, srf, 0., pi).Edge())
wire.Add(BRepBuilderAPI_MakeEdge(circle, srf, pi, 2.*pi).Edge())
wire.Build()
mkf = BRepBuilderAPI_MakeFace()
mkf.Init(srf, False, TolDegen)
mkf.Add(wire.Wire())
mkf.Build()
self.assertTrue(mkf.IsDone())
prism = BRepFeat_MakeDPrism(box, mkf.Face(), face, 100, True, True)
prism.Perform(400)
self.assertTrue(prism.IsDone())
开发者ID:imclab,项目名称:pythonocc,代码行数:25,代码来源:topology_local_operations_unittest.py
示例6: test_thick_solid
def test_thick_solid(self):
print 'Test: thick solid'
S = BRepPrimAPI_MakeBox(150, 200, 110).Shape()
topo = Topo(S)
vert = topo.vertices().next()
shapes = TopTools_ListOfShape()
for f in topo.faces_from_vertex(vert):
shapes.Append(f)
_thick_solid = BRepOffsetAPI_MakeThickSolid(S, shapes, 15, 0.01)
self.assertTrue(_thick_solid.IsDone())
开发者ID:imclab,项目名称:pythonocc,代码行数:10,代码来源:topology_local_operations_unittest.py
示例7: nearestVertices
def nearestVertices(wireList,point,tolerance=9999999.0):
points = [];
for w in wireList:
tw = Topo(w);
for v in tw.vertices():
p = brepTool.Pnt(v);
d = point.Distance(p)
if d < tolerance:
points.append((w,v,p,d));
#sort
return sorted(points,key=lambda v: v[3])
开发者ID:adam-urbanczyk,项目名称:emcfab,代码行数:13,代码来源:OCCUtil.py
示例8: thick_solid
def thick_solid(event=None):
S = BRepPrimAPI_MakeBox(150,200,110).Shape()
topo = Topo(S)
vert = topo.vertices().next()
shapes = TopTools_ListOfShape()
for f in topo.faces_from_vertex(vert):
shapes.Append(f)
_thick_solid = BRepOffsetAPI_MakeThickSolid(S,shapes, 15,0.01)
display.EraseAll()
display.DisplayShape(_thick_solid.Shape())
开发者ID:dbarbier,项目名称:pythonocc,代码行数:13,代码来源:topology_local_operations.py
示例9: LoopWirePairs
class LoopWirePairs(object):
'''
for looping through consequtive wires
assures that the returned edge pairs are ordered
'''
def __init__(self, wireA, wireB):
self.wireA = wireA
self.wireB = wireB
self.we_A = WireExplorer(self.wireA)
self.we_B = WireExplorer(self.wireB)
self.tp_A = Topo(self.wireA)
self.tp_B = Topo(self.wireB)
self.bt = BRep_Tool
self.vertsA = [v for v in self.we_A.ordered_vertices()]
self.vertsB = [v for v in self.we_B.ordered_vertices()]
self.edgesA = [v for v in WireExplorer(wireA).ordered_edges()]
self.edgesB = [v for v in WireExplorer(wireB).ordered_edges()]
self.pntsB = [self.bt.Pnt(v) for v in self.vertsB]
self.number_of_vertices = len(self.vertsA)
self.index = 0
def closest_point(self, vertexFromWireA):
pt = self.bt.Pnt(vertexFromWireA)
distances = [pt.Distance(i) for i in self.pntsB]
indx_max_dist = distances.index(min(distances))
return self.vertsB[indx_max_dist]
def next(self):
if self.index == self.number_of_vertices:
raise StopIteration
vert = self.vertsA[self.index]
closest = self.closest_point(vert)
edges_a = self.tp_A.edges_from_vertex(vert)
edges_b = self.tp_B.edges_from_vertex(closest)
a1, a2 = Edge(edges_a.next()),Edge(edges_a.next())
b1, b2 = Edge(edges_b.next()),Edge(edges_b.next())
mpA = a1.mid_point()
self.index +=1
if mpA.Distance(b1.mid_point()) < mpA.Distance(b2.mid_point()):
return iter([a1, a2]), iter([b1,b2])
else:
return iter([a1, a2]), iter([b2,b1])
def __iter__(self):
return self
开发者ID:gideonmay,项目名称:pythonocc-core,代码行数:51,代码来源:Iteration.py
示例10: glue_solids
def glue_solids(event=None):
# Without common edges
S1 = BRepPrimAPI_MakeBox(gp_Pnt(500.,500.,0.),gp_Pnt(100.,250.,300.)).Shape()
facesA = Topo(S1).faces()
F1 = [facesA.next() for i in range(5)][-1]
S2 = BRepPrimAPI_MakeBox(gp_Pnt(400.,400.,300.),gp_Pnt(200.,300.,500.)).Shape()
facesB = Topo(S2).faces()
F2 = [facesB.next() for i in range(4)][-1]
glue1 = BRepFeat_Gluer(S2,S1)
glue1.Bind(F2,F1)
display.EraseAll()
display.DisplayShape(glue1.Shape())
开发者ID:dbarbier,项目名称:pythonocc,代码行数:14,代码来源:topology_local_operations.py
示例11: display
def display(topo):
# http://www.opencascade.org/org/forum/thread_18374/
# http://adl.serveftp.org/lab/opencascade/pdf/visu.pdf
# shape = displays[curr_tab].DisplayShape(topo, update=False).GetObject()
# shape.SetDisplayMode(0)
# displays[curr_tab].DisplayColoredShape(topo, 'BLUE', False)
mat = Graphic3d_MaterialAspect(Graphic3d_NOM_SILVER)
displays[curr_tab].DisplayShape(topo, material=mat, update=False)
t = Topo(topo)
wires = t.wires()
for w in wires:
# print w
# displays[curr_tab].DisplayColoredShape(w, 'BLACK', False)
edges.append(w)
开发者ID:julienbld,项目名称:pycado,代码行数:15,代码来源:nspace.py
示例12: test_draft_angle
def test_draft_angle(self):
print 'Test: draft angle'
S = BRepPrimAPI_MakeBox(200.,300.,150.).Shape()
adraft = BRepOffsetAPI_DraftAngle(S)
topo = Topo(S)
for f in topo.faces():
surf = Handle_Geom_Plane_DownCast(BRep_Tool_Surface(f)).GetObject()
dirf = surf.Pln().Axis().Direction()
print 'direction',dirf.Coord()
ddd = gp_Dir(0,0,1)
if dirf.IsNormal(ddd, Precision_Angular()):
adraft.Add(f, ddd, math.radians(15), gp_Pln(gp_Ax3(gp_XOY())))
adraft.Build()
self.assertTrue(adraft.IsDone())
开发者ID:dbarbier,项目名称:pythonocc,代码行数:15,代码来源:topology_building_unittest.py
示例13: test_glue_solids
def test_glue_solids(self):
print 'Test: glue solids'
# Without common edges
S1 = BRepPrimAPI_MakeBox(gp_Pnt(500., 500., 0.),
gp_Pnt(100., 250., 300.)).Shape()
facesA = Topo(S1).faces()
F1 = [facesA.next() for i in range(5)][-1]
S2 = BRepPrimAPI_MakeBox(gp_Pnt(400., 400., 300.),
gp_Pnt(200., 300., 500.)).Shape()
facesB = Topo(S2).faces()
F2 = [facesB.next() for i in range(4)][-1]
glue1 = BRepFeat_Gluer(S2, S1)
glue1.Bind(F2, F1)
glue1.Build()
self.assertTrue(glue1.IsDone())
开发者ID:imclab,项目名称:pythonocc,代码行数:15,代码来源:topology_local_operations_unittest.py
示例14: brepfeat_prism
def brepfeat_prism(event=None):
box = BRepPrimAPI_MakeBox(400,250,300).Shape()
faces = Topo(box).faces()
for i in range(5):
face = faces.next()
srf = BRep_Tool_Surface(face)
c = gp_Circ2d(gp_Ax2d(gp_Pnt2d(200,130),
gp_Dir2d(1,0)),
75
)
circle = Geom2d_Circle(c).GetHandle()
wire = BRepBuilderAPI_MakeWire()
wire.Add( BRepBuilderAPI_MakeEdge( circle, srf, 0., pi ).Edge() )
wire.Add( BRepBuilderAPI_MakeEdge( circle, srf, pi, 2.*pi ).Edge() )
wire.Build()
display.DisplayShape(wire.Wire())
mkf = BRepBuilderAPI_MakeFace()
mkf.Init(srf, False , 1e-6)
mkf.Add(wire.Wire())
mkf.Build()
# bit obscure why this is nessecary...
# segfaults without...
new_face = mkf.Face()
BRepLib_BuildCurves3d(new_face)
display.DisplayShape(new_face)
prism = BRepFeat_MakeDPrism(box,
mkf.Face(),
face,
#gp_Dir(10,0,0),
100,
True,
True
)
prism.Perform(400)
display.EraseAll()
display.DisplayShape(prism.Shape())
display.DisplayColoredShape(wire.Wire(), 'RED')
开发者ID:dbarbier,项目名称:pythonocc,代码行数:48,代码来源:topology_local_operations.py
示例15: read_file
def read_file(self):
h_doc = TDocStd.Handle_TDocStd_Document()
# print "Empty Doc?", h_doc.IsNull()
# Create the application
app = XCAFApp.GetApplication().GetObject()
app.NewDocument(TCollection.TCollection_ExtendedString("MDTV-CAF"), h_doc)
# Get root assembly
doc = h_doc.GetObject()
h_shape_tool = XCAFDoc.XCAFDoc_DocumentTool_shapetool(doc.Main())
l_Colors = XCAFDoc.XCAFDoc_DocumentTool_colortool(doc.Main())
l_Layers = XCAFDoc.XCAFDoc_DocumentTool_layertool(doc.Main())
l_materials = XCAFDoc.XCAFDoc_DocumentTool_materialtool(doc.Main())
STEPReader = STEPCAFControl_Reader()
STEPReader.SetColorMode(True)
STEPReader.SetLayerMode(True)
STEPReader.SetNameMode(True)
STEPReader.SetMatMode(True)
status = STEPReader.ReadFile(str(self.filename))
if status == IFSelect_RetDone:
STEPReader.Transfer(doc.GetHandle())
Labels = TDF_LabelSequence()
ColorLabels = TDF_LabelSequence()
# TopoDS_Shape aShape;
shape_tool = h_shape_tool.GetObject()
h_shape_tool.GetObject().GetFreeShapes(Labels)
print "Number of shapes at root :%i" % Labels.Length()
for i in range(Labels.Length()):
sub_shapes_labels = TDF_LabelSequence()
print "Is Assembly?", shape_tool.isassembly(Labels.Value(i + 1))
sub_shapes = shape_tool.getsubshapes(Labels.Value(i + 1), sub_shapes_labels)
print "Number of subshapes in the assemly :%i" % sub_shapes_labels.Length()
l_Colors.GetObject().GetColors(ColorLabels)
print "Number of colors=%i" % ColorLabels.Length()
# if(CL_Len>0):
# ColorTool->GetColor(ColorLabels.Value(1),DefaultColor);
for i in range(Labels.Length()):
print Labels.Value(i + 1)
aShape = h_shape_tool.GetObject().getshape(Labels.Value(i + 1))
m = l_Layers.GetObject().GetLayers(aShape)
if aShape.ShapeType() == TopAbs_COMPOUND:
t = Topo(aShape)
for t in t.solids():
self._shapes.append(t)
return True
开发者ID:reiniervandijk,项目名称:pythonocc,代码行数:48,代码来源:STEP.py
示例16: draft_angle
def draft_angle(event=None):
S = BRepPrimAPI_MakeBox(200.,300.,150.).Shape()
adraft = BRepOffsetAPI_DraftAngle(S)
topo = Topo(S)
for f in topo.faces():
surf = Handle_Geom_Plane_DownCast(BRep_Tool_Surface(f)).GetObject()
dirf = surf.Pln().Axis().Direction()
print 'direction',dirf.Coord()
ddd = gp_Dir(0,0,1)
if dirf.IsNormal(ddd, Precision_Angular()):
adraft.Add(f, ddd, math.radians(15), gp_Pln(gp_Ax3(gp_XOY())))
adraft.Build()
display.EraseAll()
display.DisplayShape(adraft.Shape())
开发者ID:dbarbier,项目名称:pythonocc,代码行数:16,代码来源:topology_building.py
示例17: __init__
def __init__(self, wireA, wireB):
self.wireA = wireA
self.wireB = wireB
self.we_A = WireExplorer(self.wireA)
self.we_B = WireExplorer(self.wireB)
self.tp_A = Topo(self.wireA)
self.tp_B = Topo(self.wireB)
self.bt = BRep_Tool()
self.vertsA = [v for v in self.we_A.ordered_vertices()]
self.vertsB = [v for v in self.we_B.ordered_vertices()]
self.edgesA = [v for v in WireExplorer(wireA).ordered_edges()]
self.edgesB = [v for v in WireExplorer(wireB).ordered_edges()]
self.pntsB = [self.bt.Pnt(v) for v in self.vertsB]
self.number_of_vertices = len(self.vertsA)
self.index = 0
开发者ID:ashoka2015,项目名称:pythonocc,代码行数:17,代码来源:Iteration.py
示例18: test_brep_feat_local_pipe
def test_brep_feat_local_pipe(self):
print 'Test: brep_feat local pipe'
S = BRepPrimAPI_MakeBox(400., 250., 300.).Shape()
faces = Topo(S).faces()
faces.next()
F1 = faces.next()
surf = BRep_Tool_Surface(F1)
MW1 = BRepBuilderAPI_MakeWire()
p1 = gp_Pnt2d(100., 100.)
p2 = gp_Pnt2d(200., 100.)
aline = GCE2d_MakeLine(p1, p2).Value()
MW1.Add(BRepBuilderAPI_MakeEdge(aline, surf, 0., p1.Distance(p2)).Edge())
p1 = gp_Pnt2d(200., 100.)
p2 = gp_Pnt2d(150., 200.)
aline = GCE2d_MakeLine(p1, p2).Value()
MW1.Add(BRepBuilderAPI_MakeEdge(aline, surf, 0., p1.Distance(p2)).Edge())
p1 = gp_Pnt2d(150., 200.)
p2 = gp_Pnt2d(100., 100.)
aline = GCE2d_MakeLine(p1, p2).Value()
MW1.Add(BRepBuilderAPI_MakeEdge(aline, surf, 0., p1.Distance(p2)).Edge())
MKF1 = BRepBuilderAPI_MakeFace()
MKF1.Init(surf, False, TolDegen)
MKF1.Add(MW1.Wire())
FP = MKF1.Face()
BRepLib_BuildCurves3d(FP)
CurvePoles = TColgp_Array1OfPnt(1, 3)
CurvePoles.SetValue(1, gp_Pnt(150., 0., 150.))
CurvePoles.SetValue(2, gp_Pnt(200., -100., 150.))
CurvePoles.SetValue(3, gp_Pnt(150., -200., 150.))
curve = Geom_BezierCurve(CurvePoles)
E = BRepBuilderAPI_MakeEdge(curve.GetHandle()).Edge()
W = BRepBuilderAPI_MakeWire(E).Wire()
MKPipe = BRepFeat_MakePipe(S, FP, F1, W, 1, True)
MKPipe.Perform()
self.assertTrue(MKPipe.IsDone())
开发者ID:imclab,项目名称:pythonocc,代码行数:44,代码来源:topology_local_operations_unittest.py
示例19: update_naming
def update_naming(self, make_shape):
label = self.label
shape = make_shape.Shape()
input_shape = make_shape.Shape()
builder = TNaming.TNaming_Builder(label)
builder.Generated(input_shape, shape)
#FindChild creates a new label, if one doesn't exist.
#Label entry numbers are not necessarily incremental.
#They are more like dictionary keys.
gen_label = label.FindChild(1)
mod_label = label.FindChild(2)
del_label = label.FindChild(3)
gen_builder = TNaming.TNaming_Builder(gen_label)
mod_builder = TNaming.TNaming_Builder(mod_label)
del_builder = TNaming.TNaming_Builder(del_label)
topo = Topo(input_shape)
for face in topo.faces():
gen_shapes = make_shape.Generated(face)
itr = TopTools.TopTools_ListIteratorOfListOfShape(gen_shapes)
while itr.More():
this = itr.Value()
gen_builder.Generated(face, this)
print "generated", face, this
itr.Next()
for face in topo.faces():
mod_shapes = make_shape.Modified(face)
itr = TopTools.TopTools_ListIteratorOfListOfShape(mod_shapes)
while itr.More():
this = itr.Value()
mod_builder.Modified(face, this)
print "modified", face, this
itr.Next()
for face in topo.faces():
if make_shape.IsDeleted(face):
del_builder.Delete(face)
开发者ID:mortbauer,项目名称:pythonocc,代码行数:43,代码来源:occ_model.py
示例20: offsetOnceSimple
def offsetOnceSimple(self,distance):
bo = BRepOffsetAPI.BRepOffsetAPI_MakeOffset();
map(bo.AddWire, self.lastWires);
print "%d wires to offset at step 1, distance = %0.3f" % ( len(self.lastWires),distance);
bo.Perform(distance*(0.5),0.0);
result1 = Topo(bo.Shape());
returnList= [];
#compound result can be a compound of edges and/or wires. weird weird
for c in OCCUtil.childShapes(bo.Shape() ):
display.DisplayColoredShape(c,'BLUE')
if c.ShapeType() == TopAbs.TopAbs_WIRE:
returnList.append(c); #these are actually the wires we want to keep
elif c.ShapeType() == TopAbs.TopAbs_EDGE:
w = OCCUtil.wireFromEdges([c])
returnList.append(w);
else:
print "Warning: compound resulting from offset i am confused about-- not an edge or a wire."
#for each original edge, compute its descendant edges
#self.edgeMap will contain entries with the original edges, pointing to the generated
#edges and the corresponding wire:
# e1 --> [ (e2, w2 ), (e3 , w3 ) ];
for w in self.lastWires:
originalWire = Topo(w);
for oe in originalWire.edges():
self.edgeMap[oe.__hash__()] = [];
#find generated values from first transformation
generatedStep1 = OCCUtil.listFromTopToolsListOfShape(bo.Generated(oe));
for ne in generatedStep1:
#get wire this belongs to this returns a list but how could there ever be more than one?
gwires = []
for g in result1.wires_from_edge(ne):
gwires.append(g);
self.edgeMap[oe.__hash__()].append ( (ne,gwires[0] ));
self.lastWires = returnList;
self.otherWires.extend(returnList);
return returnList;
开发者ID:adam-urbanczyk,项目名称:emcfab,代码行数:41,代码来源:OffsetMap.py
注:本文中的OCC.Utils.Topology.Topo类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论