예제 #1
0
 def test_loop_faces(self):
     b = get_test_box_shape()
     t = Topo(b)
     i = 0
     for face in t.faces():
         i += 1
         assert(isinstance(face, TopoDS_Face))
     assert(i == 6)
예제 #2
0
 def test_loop_edges(self):
     b = get_test_box_shape()
     t = Topo(b)
     i = 0
     for face in t.edges():
         i += 1
         assert(isinstance(face, TopoDS_Edge))
     assert(i == 12)
예제 #3
0
 def test_creat_face(self):
     # create a box
     b = get_test_box_shape()
     # take the first edge
     t = Topo(b)
     wire = next(t.wires())
     my_wire = Wire(wire)
     assert not my_wire.IsNull()
     assert my_wire.tolerance == 1e-06
예제 #4
0
 def test_creat_face(self):
     # create a box
     b = get_test_box_shape()
     # take the first edge
     t = Topo(b)
     wire = t.wires().next()
     my_wire = Wire(wire)
     assert not my_wire.IsNull()
     assert my_wire.tolerance == 1e-06
예제 #5
0
 def test_creat_edge(self):
     # create a box
     b = get_test_box_shape()
     # take the first edge
     t = Topo(b)
     edge_0 = next(t.edges())  # it's a TopoDS_Edge
     assert not edge_0.IsNull()
     # then create an edge
     my_edge = Edge(edge_0)
     assert not my_edge.IsNull()
     assert my_edge.tolerance == 1e-06
     assert my_edge.type == 'line'
     assert my_edge.length() == 30.
예제 #6
0
 def test_creat_edge(self):
     # create a box
     b = get_test_box_shape()
     # take the first edge
     t = Topo(b)
     edge_0 = t.edges().next()  # it's a TopoDS_Edge
     assert not edge_0.IsNull()
     # then create an edge
     my_edge = Edge(edge_0)
     assert not my_edge.IsNull()
     assert my_edge.tolerance == 1e-06
     assert my_edge.type == 'line'
     assert my_edge.length() == 30.
예제 #7
0
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(next(edges_a)), Edge(next(edges_a))
        b1, b2 = Edge(next(edges_b)), Edge(next(edges_b))
        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
예제 #8
0
 def test_get_numbers_of_members(self):
     b = get_test_box_shape()
     t = Topo(b)
     assert(t.number_of_faces() == 6)
     assert(t.number_of_edges() == 12)
     assert(t.number_of_vertices() == 8)
     assert(t.number_of_wires() == 6)
     assert(t.number_of_solids() == 1)
     assert(t.number_of_shells() == 1)
     assert(t.number_of_compounds() == 0)
     assert(t.number_of_comp_solids() == 0)
예제 #9
0
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
예제 #10
0
def get_children(children_genotype):
    res = [0 for _ in children_genotype]
    for i in range(len(children_genotype)):
        b = time.time()
        res[i] = Topo(children_genotype[i])
        print('i = {0} and time = {1}'.format(i, time.time() - b))
    return res
예제 #11
0
def get_population(pop_len, geno_len):
    res = [0 for _ in range(pop_len)]
    for i in range(pop_len):
        b = time.time()
        res[i] = Topo(get_genotypes(geno_len))
        print('i = {0} and time = {1}'.format(i, time.time() - b))
    return res
예제 #12
0
    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
예제 #13
0
 def test_edges_out_of_scope(self):
     # check pointers going out of scope
     face = next(self.topo.faces())
     _edges = []
     for edg in Topo(face).edges():
         _edges.append(edg)
     for edg in _edges:
         assert not edg.IsNull()
예제 #14
0
    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
예제 #15
0
    def analyse(self):
        """

        :return:
        """
        ss = ShapeAnalysis_Shell(self)
        if ss.HasFreeEdges():
            bad_edges = [e for e in Topo(ss.BadEdges()).edges()]
        return bad_edges
예제 #16
0
def fit_plane_through_face_vertices(_face):
    """
    :param _face:   OCC.KBE.face.Face instance
    :return:        Geom_Plane
    """
    from OCC.GeomPlate import GeomPlate_BuildAveragePlane

    uvs_from_vertices = [
        _face.project_vertex(vertex2pnt(i)) for i in Topo(_face).vertices()
    ]
    normals = [
        gp_Vec(_face.DiffGeom.normal(*uv[0])) for uv in uvs_from_vertices
    ]
    points = [i[1] for i in uvs_from_vertices]

    NORMALS = TColgp_SequenceOfVec()
    [NORMALS.Append(i) for i in normals]
    POINTS = to_tcol_(points, TColgp_HArray1OfPnt)

    pl = GeomPlate_BuildAveragePlane(NORMALS, POINTS).Plane().GetObject()
    vec = gp_Vec(pl.Location(), _face.GlobalProperties.centre())
    pt = (pl.Location().as_vec() + vec).as_pnt()
    pl.SetLocation(pt)
    return pl
예제 #17
0
 def shells(self):
     return (Shell(sh) for sh in Topo(self))
예제 #18
0
#    Curve.graphic
#===========================================================================
    def show(self, poles=False, vertices=False, knots=False):
        '''
        poles, knots, should render all slightly different.
        here's how...

        http://www.opencascade.org/org/forum/thread_1125/
        '''
        show = super(Edge, self).show()

    def update(self, context):
        '''updates the graphic presentation when called
        '''
        raise NotImplementedError

    @property
    def color(self, *rgb):
        '''color descriptor for the curve
        '''
        raise NotImplementedError

if __name__ == '__main__':
    from OCC.BRepPrimAPI import *
    from Topology import Topo
    b = BRepPrimAPI_MakeBox(10, 20, 30).Shape()
    t = Topo(b)
    ed = t.edges().next()
    my_e = Edge(ed)
    print(my_e.tolerance)
예제 #19
0
 def setUp(self):
     self.topo = Topo(get_test_box_shape())
     assert self.topo
예제 #20
0
class TestTopo(unittest.TestCase):
    def setUp(self):
        self.topo = Topo(get_test_box_shape())
        assert self.topo

    def test_loop_faces(self):
        i = 0
        for face in self.topo.faces():
            i += 1
            assert(isinstance(face, TopoDS_Face))
        assert(i == 6)

    def test_loop_edges(self):
        i = 0
        for face in self.topo.edges():
            i += 1
            assert(isinstance(face, TopoDS_Edge))
        assert(i == 12)

    def number_of_topological_entities(self):
        assert(self.topo.number_of_faces() == 6)
        assert(self.topo.number_of_edges() == 12)
        assert(self.topo.number_of_vertices() == 8)
        assert(self.topo.number_of_wires() == 6)
        assert(self.topo.number_of_solids() == 1)
        assert(self.topo.number_of_shells() == 1)
        assert(self.topo.number_of_compounds() == 0)
        assert(self.topo.number_of_comp_solids() == 0)

    def test_nested_iteration(self):
        '''check nested looping'''
        for f in self.topo.faces():
            for e in self.topo.edges():
                assert isinstance(f, TopoDS_Face)
                assert isinstance(e, TopoDS_Edge)

    def test_kept_reference(self):
        '''did we keep a reference after looping several time through a list
        of topological entities?'''
        _tmp = []
        _faces = [i for i in self.topo.faces()]
        for f in _faces:
            _tmp.append(0 == f.IsNull())
        for f in _faces:
            _tmp.append(0 == f.IsNull())
        self.assert_(all(_tmp))

    def test_edge_face(self):
        edg = self.topo.edges().next()
        face = self.topo.faces().next()
        faces_from_edge = [i for i in self.topo.faces_from_edge(edg)]
        self.assert_(len(faces_from_edge) == self.topo.number_of_faces_from_edge(edg))
        edges_from_face = [i for i in self.topo.edges_from_face(face)]
        self.assert_(len(edges_from_face) == self.topo.number_of_edges_from_face(face))

    def test_edge_wire(self):
        edg = self.topo.edges().next()
        wire = self.topo.wires().next()
        wires_from_edge = [i for i in self.topo.wires_from_edge(edg)]
        self.assert_(len(wires_from_edge) == self.topo.number_of_wires_from_edge(edg))
        edges_from_wire = [i for i in self.topo.edges_from_wire(wire)]
        self.assert_(len(edges_from_wire) == self.topo.number_of_edges_from_wire(wire))

    def test_vertex_edge(self):
        vert = self.topo.vertices().next()
        edge = self.topo.edges().next()
        verts_from_edge = [i for i in self.topo.vertices_from_edge(edge)]
        self.assert_(len(verts_from_edge) == self.topo.number_of_vertices_from_edge(edge))
        edges_from_vert = [i for i in self.topo.edges_from_vertex(vert)]
        self.assert_(len(edges_from_vert) == self.topo.number_of_edges_from_vertex(vert))

    def test_vertex_face(self):
        vert = self.topo.vertices().next()
        face = self.topo.faces().next()
        faces_from_vertex = [i for i in self.topo.faces_from_vertex(vert)]
        self.assert_(len(faces_from_vertex) == self.topo.number_of_faces_from_vertex(vert))
        verts_from_face = [i for i in self.topo.vertices_from_face(face)]
        self.assert_(len(verts_from_face) == self.topo.number_of_vertices_from_face(face))

    def test_face_solid(self):
        face = self.topo.faces().next()
        solid = self.topo.solids().next()
        faces_from_solid = [i for i in self.topo.faces_from_solids(solid)]
        self.assert_(len(faces_from_solid) == self.topo.number_of_faces_from_solids(solid))
        solids_from_face = [i for i in self.topo.solids_from_face(face)]
        self.assert_(len(solids_from_face) == self.topo.number_of_solids_from_face(face))

    def test_wire_face(self):
        wire = self.topo.wires().next()
        face = self.topo.faces().next()
        faces_from_wire = [i for i in self.topo.faces_from_wire(wire)]
        self.assert_(len(faces_from_wire) == self.topo.number_of_faces_from_wires(wire))
        wires_from_face = [i for i in self.topo.wires_from_face(face)]
        self.assert_(len(wires_from_face) == self.topo.number_of_wires_from_face(face))

    def test_edges_out_of_scope(self):
        # check pointers going out of scope
        face = self.topo.faces().next()
        _edges = []
        for edg in Topo(face).edges():
            _edges.append(edg)
        for edg in _edges:
            assert not edg.IsNull()

    def test_wires_out_of_scope(self):
        # check pointers going out of scope
        wire = self.topo.wires().next()
        _edges, _vertices = [], []
        for edg in WireExplorer(wire).ordered_edges():
            _edges.append(edg)
        for edg in _edges:
            assert not edg.IsNull()
        for vert in WireExplorer(wire).ordered_vertices():
            _vertices.append(vert)
        for v in _vertices:
            assert not v.IsNull()
예제 #21
0
 def topo(self):
     if self._topo is not None:
         return self._topo
     else:
         self._topo = Topo(self)
         return self._topo
예제 #22
0
 def Edges(self):
     return Topo(self, True).edges()
예제 #23
0
 def Wires(self):
     """
     :return:
     """
     return Topo(self, True).wires()
예제 #24
0
    def Faces(self):
        """

        :return:
        """
        return Topo(self, True).faces()
예제 #25
0
class TestTopo(unittest.TestCase):
    def setUp(self):
        self.topo = Topo(get_test_box_shape())
        assert self.topo

    def test_loop_faces(self):
        i = 0
        for face in self.topo.faces():
            i += 1
            assert (isinstance(face, TopoDS_Face))
        assert (i == 6)

    def test_loop_edges(self):
        i = 0
        for face in self.topo.edges():
            i += 1
            assert (isinstance(face, TopoDS_Edge))
        assert (i == 12)

    def number_of_topological_entities(self):
        assert (self.topo.number_of_faces() == 6)
        assert (self.topo.number_of_edges() == 12)
        assert (self.topo.number_of_vertices() == 8)
        assert (self.topo.number_of_wires() == 6)
        assert (self.topo.number_of_solids() == 1)
        assert (self.topo.number_of_shells() == 1)
        assert (self.topo.number_of_compounds() == 0)
        assert (self.topo.number_of_comp_solids() == 0)

    def test_nested_iteration(self):
        '''check nested looping'''
        for f in self.topo.faces():
            for e in self.topo.edges():
                assert isinstance(f, TopoDS_Face)
                assert isinstance(e, TopoDS_Edge)

    def test_kept_reference(self):
        '''did we keep a reference after looping several time through a list
        of topological entities?'''
        _tmp = []
        _faces = [i for i in self.topo.faces()]
        for f in _faces:
            _tmp.append(0 == f.IsNull())
        for f in _faces:
            _tmp.append(0 == f.IsNull())
        self.assertTrue(all(_tmp))

    def test_edge_face(self):
        edg = next(self.topo.edges())
        face = next(self.topo.faces())
        faces_from_edge = [i for i in self.topo.faces_from_edge(edg)]
        self.assertTrue(
            len(faces_from_edge) == self.topo.number_of_faces_from_edge(edg))
        edges_from_face = [i for i in self.topo.edges_from_face(face)]
        self.assertTrue(
            len(edges_from_face) == self.topo.number_of_edges_from_face(face))

    def test_edge_wire(self):
        edg = next(self.topo.edges())
        wire = next(self.topo.wires())
        wires_from_edge = [i for i in self.topo.wires_from_edge(edg)]
        self.assertTrue(
            len(wires_from_edge) == self.topo.number_of_wires_from_edge(edg))
        edges_from_wire = [i for i in self.topo.edges_from_wire(wire)]
        self.assertTrue(
            len(edges_from_wire) == self.topo.number_of_edges_from_wire(wire))

    def test_vertex_edge(self):
        vert = next(self.topo.vertices())
        edge = next(self.topo.edges())
        verts_from_edge = [i for i in self.topo.vertices_from_edge(edge)]
        self.assertTrue(
            len(verts_from_edge) == self.topo.number_of_vertices_from_edge(
                edge))
        edges_from_vert = [i for i in self.topo.edges_from_vertex(vert)]
        self.assertTrue(
            len(edges_from_vert) == self.topo.number_of_edges_from_vertex(
                vert))

    def test_vertex_face(self):
        vert = next(self.topo.vertices())
        face = next(self.topo.faces())
        faces_from_vertex = [i for i in self.topo.faces_from_vertex(vert)]
        self.assertTrue(
            len(faces_from_vertex) == self.topo.number_of_faces_from_vertex(
                vert))
        verts_from_face = [i for i in self.topo.vertices_from_face(face)]
        self.assertTrue(
            len(verts_from_face) == self.topo.number_of_vertices_from_face(
                face))

    def test_face_solid(self):
        face = next(self.topo.faces())
        solid = next(self.topo.solids())
        faces_from_solid = [i for i in self.topo.faces_from_solids(solid)]
        self.assertTrue(
            len(faces_from_solid) == self.topo.number_of_faces_from_solids(
                solid))
        solids_from_face = [i for i in self.topo.solids_from_face(face)]
        self.assertTrue(
            len(solids_from_face) == self.topo.number_of_solids_from_face(
                face))

    def test_wire_face(self):
        wire = next(self.topo.wires())
        face = next(self.topo.faces())
        faces_from_wire = [i for i in self.topo.faces_from_wire(wire)]
        self.assertTrue(
            len(faces_from_wire) == self.topo.number_of_faces_from_wires(wire))
        wires_from_face = [i for i in self.topo.wires_from_face(face)]
        self.assertTrue(
            len(wires_from_face) == self.topo.number_of_wires_from_face(face))

    def test_edges_out_of_scope(self):
        # check pointers going out of scope
        face = next(self.topo.faces())
        _edges = []
        for edg in Topo(face).edges():
            _edges.append(edg)
        for edg in _edges:
            assert not edg.IsNull()

    def test_wires_out_of_scope(self):
        # check pointers going out of scope
        wire = next(self.topo.wires())
        _edges, _vertices = [], []
        for edg in WireExplorer(wire).ordered_edges():
            _edges.append(edg)
        for edg in _edges:
            assert not edg.IsNull()
        for vert in WireExplorer(wire).ordered_vertices():
            _vertices.append(vert)
        for v in _vertices:
            assert not v.IsNull()
예제 #26
0
 def setUp(self):
     self.topo = Topo(get_test_box_shape())
     assert self.topo