当前位置: 首页>>代码示例>>Python>>正文


Python Topology.Topo类代码示例

本文整理汇总了Python中OCC.Utils.Topology.Topo的典型用法代码示例。如果您正苦于以下问题:Python Topo类的具体用法?Python Topo怎么用?Python Topo使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了Topo类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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


注:本文中的OCC.Utils.Topology.Topo类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。