Beispiel #1
0
    def test_dent(self):
        """Simple parallel event
        """
        conv = ToPointsAndSegments()

        lines = [[[0., 0.], [10., 0.]], [[10., 0.], [10., 10.]],
                 [[10., 10.], [1., 10.]], [[1., 10.], [1., 7.]],
                 [[1., 7.], [3., 7.]], [[3., 7.], [3., 6.5]],
                 [[3., 6.5], [0., 6.5]], [[0., 6.5], [0., 0.]]]
        for line in lines:
            start, end = map(tuple, line)
            conv.add_point(start)
            conv.add_point(end)
            conv.add_segment(start, end)
        skel = calc_skel(conv, pause=PAUSE, output=OUTPUT, shrink=True)
        # check the amount of skeleton nodes
        assert len(skel.sk_nodes) == 16, len(skel.sk_nodes)
        # check the amount of segments in the skeleton
        assert len(skel.segments()) == 23, len(skel.segments())
        # check the amount of kinetic vertices that are (not) stopped
        not_stopped = filter(lambda v: v.stops_at is None, skel.vertices)
        stopped = filter(lambda v: v.stops_at is not None, skel.vertices)
        assert len(not_stopped) == 6, len(not_stopped)
        assert len(stopped) == 17, len(stopped)
        # check cross relationship between kinetic vertices and skeleton nodes
        for v in skel.vertices:
            assert at_same_location((v.start_node, v), v.starts_at)
            if v.stops_at is not None and not v.inf_fast:
                assert at_same_location((v.stop_node, v), v.stops_at), \
                    "{} {} {}".format(id(v),
                                      v.stop_node.pos,
                                      v.position_at(v.stops_at) )
Beispiel #2
0
 def test_T_capital_T(self):
     """Capital T, has more than one triangle in parallel fan
     """
     #    T
     ring = [(15.5055, 28.7004), (20.8063, 28.7004), (20.8063, 44.1211), (26.7445, 44.1211), (26.7445, 47.8328), (9.5668, 47.8328), (9.5668, 44.1211), (15.5055, 44.1211), (15.5055, 28.7004)]
     conv = ToPointsAndSegments()
     conv.add_polygon([ring])
     skel = calc_skel(conv, pause=PAUSE, output=OUTPUT)
     # check the amount of segments in the skeleton
     assert len(skel.segments()) == 21, len(skel.segments())
     # check the amount of skeleton nodes
     assert len(skel.sk_nodes) == 14, len(skel.sk_nodes)
     # check the amount of kinetic vertices that are (not) stopped
     not_stopped = filter(lambda v: v.stops_at is None, skel.vertices)
     stopped = filter(lambda v: v.stops_at is not None, skel.vertices)
     assert len(not_stopped) == 8, len(not_stopped)
     assert len(stopped) == 13, len(stopped)
     # check cross relationship between kinetic vertices and skeleton nodes
     for v in skel.vertices:
         assert at_same_location((v.start_node, v), v.starts_at)
         if v.stops_at is not None and not v.inf_fast:
             assert at_same_location((v.stop_node, v), v.stops_at), \
                 "{} {} {}".format(id(v),
                                   v.stop_node.pos,
                                   v.position_at(v.stops_at) )
Beispiel #3
0
 def test_L_2(self):
     poly = [[(5, 0), (5, -1), (5, -2), (5, -3), (5, -4), (5, -5), (7, -5),
              (7, 0), (8, 0), (9, 0), (10, 0), (11, 0), (11, 1), (5, 1),
              (5, 0)]]
     # convert to triangulation input
     conv = ToPointsAndSegments()
     conv.add_polygon(poly)
     # skeletonize / offset
     skel = calc_skel(conv, pause=PAUSE, output=OUTPUT)
     # check the amount of segments in the skeleton
     assert len(skel.segments()) == 40, len(skel.segments())
     # check the amount of skeleton nodes
     assert len(skel.sk_nodes) == 27, len(skel.sk_nodes)
     # check the amount of kinetic vertices that are (not) stopped
     assert len(filter(lambda v: v.stops_at is None, skel.vertices)) == 11
     assert len(filter(lambda v: v.stops_at is not None,
                       skel.vertices)) == 29
     # check cross relationship between kinetic vertices and skeleton nodes
     for v in skel.vertices:
         assert at_same_location((v.start_node, v), v.starts_at)
         if v.stops_at is not None and not v.inf_fast:
             assert at_same_location((v.stop_node, v), v.stops_at), \
                 "{} {} {}".format(id(v),
                                   v.stop_node.pos,
                                   v.position_at(v.stops_at) )
Beispiel #4
0
    def test_handle_fan_cw(self):
        import json
        s = """{
"type": "FeatureCollection",
"crs": { "type": "name", "properties": { "name": "urn:ogc:def:crs:EPSG::28992" } },
                                                                                             
"features": [
             
{ "type": "Feature", "properties": { "id": 140092307709904.000000, "side": 1 }, "geometry": { "type": "LineString", "coordinates": [ [ -0.95871967752, -0.627450761189 ], [ -0.98800624377, -0.432206986189 ] ] } },
{ "type": "Feature", "properties": { "id": 140092307712976.000000, "side": 2 }, "geometry": { "type": "LineString", "coordinates": [ [ -0.98800624377, -0.432206986189 ], [ -0.985872786033, -0.431940303972 ] ] } },
{ "type": "Feature", "properties": { "id": 140092307713104.000000, "side": 1 }, "geometry": { "type": "LineString", "coordinates": [ [ -0.993971487578, -0.378572900681 ], [ -1.02090042121, -0.181094054061 ] ] } },
{ "type": "Feature", "properties": { "id": 140092307782672.000000, "side": 1 }, "geometry": { "type": "LineString", "coordinates": [ [ -0.985872786033, -0.431940303972 ], [ -0.991522629252, -0.37826679339 ] ] } },
{ "type": "Feature", "properties": { "id": 140092307782672.000000, "side": 2 }, "geometry": { "type": "LineString", "coordinates": [ [ -0.991522629252, -0.37826679339 ], [ -0.993971487578, -0.378572900681 ] ] } },
             
{ "type": "Feature", "properties": { "id": 140092307713104.000000, "side": 1 }, "geometry": { "type": "LineString", "coordinates": [ [ -1.02090042121, -0.181094054061 ], [5, 0] ] } },
{ "type": "Feature", "properties": { "id": 140092307709904.000000, "side": 1 }, "geometry": { "type": "LineString", "coordinates": [ [ -0.95871967752, -0.627450761189 ], [5,0]] } }
]
}"""
        x = json.loads(s)
        # parse segments from geo-json
        segments = []
        for y in x['features']:
            segments.append(tuple(map(tuple, y['geometry']['coordinates'])))
        # convert to triangulation input
        conv = ToPointsAndSegments()
        for line in segments:
            conv.add_point(line[0])
            conv.add_point(line[1])
            conv.add_segment(*line)
        # skeletonize / offset
        skel = calc_skel(conv, pause=PAUSE, output=OUTPUT)
        # check the amount of skeleton nodes
        assert len(skel.sk_nodes) == 14, len(skel.sk_nodes)
        # check the amount of segments in the skeleton
        assert len(skel.segments()) == 20, len(skel.segments())
        # check the amount of kinetic vertices that are (not) stopped
        not_stopped = filter(lambda v: v.stops_at is None, skel.vertices)
        stopped = filter(lambda v: v.stops_at is not None, skel.vertices)
        assert len(not_stopped) == 5, len(not_stopped)
        assert len(stopped) == 15, len(stopped)
        # check cross relationship between kinetic vertices and skeleton nodes
        for v in skel.vertices:
            assert at_same_location((v.start_node, v), v.starts_at)
            if v.stops_at is not None and not v.inf_fast:
                assert at_same_location((v.stop_node, v), v.stops_at), \
                    "{} {} {}".format(id(v),
                                      v.stop_node.pos,
                                      v.position_at(v.stops_at) )
Beispiel #5
0
 def test_square(self):
     conv = ToPointsAndSegments()
     polygon = [[(0, 0), (10, 0), (10, 10), (0, 10), (0, 0)]]
     conv.add_polygon(polygon)
     skel = calc_skel(conv, pause=PAUSE, output=OUTPUT)
     # check the amount of segments in the skeleton
     assert len(skel.segments()) == (4 + 4), len(skel.segments())
     # check the amount of skeleton nodes
     assert len(skel.sk_nodes) == 5, len(skel.sk_nodes)
     # check the amount of kinetic vertices that are (not) stopped
     assert len(filter(lambda v: v.stops_at is None, skel.vertices)) == 4
     assert len(filter(lambda v: v.stops_at is not None,
                       skel.vertices)) == 4
     # check cross relationship between kinetic vertices and skeleton nodes
     for v in skel.vertices:
         assert at_same_location((v.start_node, v), v.starts_at)
         if v.stops_at is not None:
             assert at_same_location((v.stop_node, v), v.stops_at)
Beispiel #6
0
 def test_rectangle(self):
     conv = ToPointsAndSegments()
     polygon = [[(0, 0), (10, 0), (10, 5), (0, 5), (0, 0)]]
     conv.add_polygon(polygon)
     skel = calc_skel(conv, pause=PAUSE, output=OUTPUT)
     # check the amount of segments in the skeleton
     assert len(skel.segments()) == (5 + 4), len(skel.segments())
     # check the amount of skeleton nodes
     assert len(skel.sk_nodes) == 6, len(skel.sk_nodes)
     # check the amount of kinetic vertices that are (not) stopped
     assert len(filter(lambda v: v.stops_at is None, skel.vertices)) == 4
     assert len(filter(lambda v: v.stops_at is not None,
                       skel.vertices)) == 5
     # check cross relationship between kinetic vertices and skeleton nodes
     for v in skel.vertices:
         assert at_same_location((v.start_node, v), v.starts_at)
         if v.stops_at is not None and not v.inf_fast:
             assert at_same_location(
                 (v.stop_node, v),
                 v.stops_at), "{} {} {}".format(id(v), v.stop_node.pos,
                                                v.position_at(v.stops_at))
Beispiel #7
0
    def test_dent_unequal_wavefront_side_flipped_y(self):
        """Simple parallel event, starting from wavefront side
        """
        def flip_y(pt):
            return (pt[0], -pt[1])

        conv = ToPointsAndSegments()
        lines = [[[51046.4, 391515.7], [51046.3, 391516.65]],
                 [[51047.95, 391513.05], [51047.55, 391515.85]],
                 [[51047.55, 391515.85], [51046.4, 391515.7]],
                 [[51047.45, 391516.8], [51046.9, 391520.8]],
                 [[51046.3, 391516.65], [51047.45, 391516.8]],
                 [[51055, 391521], [51057, 391514]],
                 [[
                     51046.9,
                     391520.8,
                 ], [51055, 391521]], [[51047.95, 391513.05], [51057, 391514]]]
        for line in lines:
            start, end = map(tuple, map(flip_y, line))
            conv.add_point(start)
            conv.add_point(end)
            conv.add_segment(start, end)
        skel = calc_skel(conv, pause=PAUSE, output=OUTPUT, shrink=True)
        #
        # check the amount of skeleton nodes
        assert len(skel.sk_nodes) == 16, len(skel.sk_nodes)
        # check the amount of segments in the skeleton
        assert len(skel.segments()) == 23, len(skel.segments())
        # check the amount of kinetic vertices that are (not) stopped
        assert len(filter(lambda v: v.stops_at is None, skel.vertices)) == 6
        assert len(filter(lambda v: v.stops_at is not None,
                          skel.vertices)) == 13 + 4
        # check cross relationship between kinetic vertices and skeleton nodes
        for v in skel.vertices:
            assert at_same_location((v.start_node, v), v.starts_at)
            if v.stops_at is not None and not v.inf_fast:
                assert at_same_location(
                    (v.stop_node, v),
                    v.stops_at), "{} {} {}".format(id(v), v.stop_node.pos,
                                                   v.position_at(v.stops_at))
Beispiel #8
0
 def test_dent_unequal_bottom(self):
     conv = ToPointsAndSegments()
     polygon = [[(-0.5, 0), (10., 0), (10, 20), (0, 20.), (0, 11.),
                 (-1, 11), (-1, 10), (-0.5, 10), (-0.5, 0)]]
     conv.add_polygon(polygon)
     skel = calc_skel(conv, pause=PAUSE, output=OUTPUT)
     # check the amount of segments in the skeleton
     assert len(skel.segments()) == (13 + 8), len(skel.segments())
     # check the amount of skeleton nodes
     assert len(skel.sk_nodes) == 14, len(skel.sk_nodes)
     # check the amount of kinetic vertices that are (not) stopped
     assert len(filter(lambda v: v.stops_at is None, skel.vertices)) == 8
     assert len(filter(lambda v: v.stops_at is not None,
                       skel.vertices)) == 13
     # check cross relationship between kinetic vertices and skeleton nodes
     for v in skel.vertices:
         assert at_same_location((v.start_node, v), v.starts_at)
         if v.stops_at is not None and not v.inf_fast:
             assert at_same_location((v.stop_node, v), v.stops_at), \
                 "{} {} {}".format(id(v),
                                   v.stop_node.pos,
                                   v.position_at(v.stops_at) )
Beispiel #9
0
            def test(self):
                if INTERACTIVE:
                    skel = calc_skel(
                        data,
                        pause=True,
                        output=True,
                        internal_only=False,
                        shrink=True
                        #                        data, pause=False, output=False, internal_only=False, shrink=True
                    )
                else:
                    skel = calc_skel(data)
                # check the amount of segments in the skeleton
                self.assertEqual(len(skel.segments()), total)
                # check the amount of skeleton nodes
                self.assertEqual(len(skel.sk_nodes), node)
                # # check the amount of kinetic vertices that are (not) stopped
                not_stopped = [v for v in skel.vertices if v.stops_at is None]
                stopped = [
                    v for v in skel.vertices if v.stops_at is not None
                    and v.start_node is not v.stop_node
                ]
                self.assertEqual(len(not_stopped), infinite)
                self.assertEqual(len(stopped), total - infinite)
                # check cross relationship between kinetic vertices and skeleton nodes
                for v in skel.vertices:
                    # exact same starting location
                    if abs(v.velocity[0]) < 100 and abs(
                            v.velocity[1]
                    ) < 100:  # check only 'slow' moving vertices
                        self.assertTrue(
                            at_same_location([v.start_node, v], v.starts_at),
                            "{} [{}] {} does not have correct start_node(!) position"
                            .format(id(v), v.info, v.velocity))
                    # quite close at the stop node (given the vertex + its direction/speed)
                    if True and v.stops_at is not None and not v.inf_fast and (
                            abs(v.velocity[0]) < 100
                            and abs(v.velocity[1]) < 100):
                        d = dist(
                            v.stop_node.position_at(v.stops_at),
                            v.position_at(v.stops_at),
                        )
                        self.assertAlmostEqual(
                            d, 0.0, 2,
                            "{} [{}] velocity '{}' does not have correct stop_node position -- dist: {}"
                            .format(id(v), v.info, v.velocity, d))

                        # self.assertTrue(at_same_location([v.stop_node, v], v.stops_at),
                        #     '{} != {}; {}'.format(v.stop_node.position_at(v.stops_at), v.position_at(v.stops_at),
                        #     dist(v.stop_node.position_at(v.stops_at), v.position_at(v.stops_at)))
                        #     )
                if EXPENSIVE_POST_CONDITION == True:
                    # check that we do not have any self intersections between segments
                    self.assertFalse(
                        segments_intersecting(skel.segments()),
                        "intersection between straight skeleton segments found",
                    )
                    # offset segments should not intersect
                    # (FIXME: these use left_at of kinetic vertices, also check right_at)
                    last_evt_time = max(v.stops_at for v in skel.vertices
                                        if v.stops_at is not None)
                    offset_segments = [
                        (line[0], line[1])
                        for line in calc_offsets(skel, last_evt_time, 25)
                    ]
                    self.assertFalse(
                        segments_intersecting(offset_segments),
                        "Intersection in offsets found",
                    )