Beispiel #1
0
    def initialize_status(self):
        sweep_ray = Ray(self.origin, self.event_queue[0].p)
        i = 0
        for ep in self.event_queue:
            if ep.type == DEFAULT_VERTEX:
                segment = Segment(ep.p, ep.twin.p)
                intersection_point = sweep_ray.intersection(segment)

                if len(intersection_point) > 0:
                    # If the segments first point is the current event-point
                    if intersection_point[
                            0] == ep.p:  # if the point is on the initial ray
                        if len(
                                Ray(self.origin, self.event_queue[
                                    i + 1].p).intersection(segment)
                        ) > 0:  #if the point was a start point
                            self.initialize_segment(ep, intersection_point)
                        else:
                            self.initialize_segment(ep.twin,
                                                    intersection_point)
                    else:
                        self.initialize_segment(ep.twin, intersection_point)
                else:
                    # Event-points not hit by the ray gets a type
                    ep.type = START_VERTEX
                    ep.twin.type = END_VERTEX
            i += 1
Beispiel #2
0
    def perform_sweep(self):
        print("\nStatus at start: " + str(len(self.status)))

        for ep in self.event_queue:
            print("\nStatus: " + str(len(self.status)))

            if ep.type == START_VERTEX:
                print("START_VERTEX")
                status_segment = StatusSegment(ep, ep.twin, self.origin)

                print("current segment: " + str(status_segment.segment) +
                      str(status_segment.current_distance))

                ep.status_segment = status_segment
                ep.twin.status_segment = status_segment
                if self.status.__len__() == 0:
                    self.status.update(
                        {status_segment.current_distance: status_segment})
                    self.visibility_polygon.append(ep.p)
                    print("empty status. Append")
                else:
                    first_in_status = self.status.peekitem(index=0)

                    print("first in status and distance: " +
                          str(first_in_status[1].segment) + ": " +
                          str(first_in_status[1].current_distance))

                    current_ray = Ray(self.origin, ep.p)
                    intersection_point = current_ray.intersection(
                        first_in_status[1].segment)
                    first_in_status[1].current_distance = distance(
                        intersection_point[0], self.origin)
                    print("First in status new distance: " +
                          str(first_in_status[1].current_distance))
                    self.status.update(
                        {status_segment.current_distance:
                         status_segment})  # insert the new segment to status
                    self.status.__delitem__(first_in_status[0])
                    self.status.update({
                        first_in_status[1].current_distance:
                        first_in_status[1]
                    })  #update the key distance to the origin
                    new_first_in_status = self.status.peekitem(index=0)
                    if new_first_in_status[1] != first_in_status[1]:
                        self.visibility_polygon.append(intersection_point[0])
                        self.visibility_polygon.append(ep.p)
                        print("normal status. Append")

            elif ep.type == END_VERTEX:
                print("END_VERTEX")
                first_in_status = self.status.peekitem(index=0)
                print("first in status and distance: " +
                      str(first_in_status[1].segment) + ": " +
                      str(first_in_status[1].current_distance))
                self.status.__delitem__(ep.status_segment.current_distance)
                print("ep status segment and distance: " +
                      str(ep.status_segment.segment) + ": " +
                      str(ep.status_segment.current_distance))
                if self.status.__len__() == 0:
                    self.visibility_polygon.append(ep.p)
                    print("empty status. Append")
                else:
                    new_first_in_status = self.status.peekitem(index=0)
                    if new_first_in_status[1] != first_in_status[1]:
                        current_ray = Ray(self.origin, ep.p)
                        intersection_point = current_ray.intersection(
                            new_first_in_status[1].segment)
                        self.visibility_polygon.append(ep.p)
                        self.visibility_polygon.append(intersection_point[0])
                        print("normal status. Append")