1 from __future__
import division
5 from object.ExtendedSegment
import ExtendedSegment
47 dist = np.sqrt((x2 - x1)**2 + (y2 - y1)**2)
56 return math.hypot(px - x1, py - y1)
58 t = ((px - x1) * dx + (py - y1) * dy) / (dx * dx + dy * dy)
72 return math.hypot(dx, dy)
77 coefficient = np.array([[m1, 1], [m2, 1]])
78 known_term = np.array([q1, q2])
79 x = np.linalg.solve(coefficient, known_term)
92 delta = dx2 * dy1 - dy2 * dx1
96 s = (dx1 * (y21 - y11) + dy1 * (x11 - x21)) / delta
97 t = (dx2 * (y11 - y21) + dy2 * (x21 - x11)) / (-delta)
98 return (0 <= s <= 1)
and (0 <= t <= 1)
116 return min(distances)
126 angle = math.radians(90.0)
132 for index, wall
in enumerate(wall_list):
133 cluster = cluster_centers[index]
134 wall.set_angular_cluster(cluster)
145 for index, wall1
in enumerate(wall_list):
146 if wall1.spatial_cluster
is None:
148 for wall2
in wall_list[index + 1:]:
150 if(wall2.spatial_cluster
is None)
and (wall1.angular_cluster == wall2.angular_cluster):
152 wall2.set_spatial_cluster(index)
155 wall1.set_spatial_cluster(index)
159 for wall2
in wall_list:
161 if(wall2.spatial_cluster
is None)
and (wall1.angular_cluster == wall2.angular_cluster):
163 wall2.set_spatial_cluster(wall1.spatial_cluster)
166 if(wall2.spatial_cluster
is not None)
and (wall2.spatial_cluster != wall1.spatial_cluster)
and (wall1.angular_cluster == wall2.angular_cluster) and(
lateral_separation(wall1, wall2) < threshold):
168 if m.spatial_cluster == wall2.spatial_cluster:
169 m.set_spatial_cluster(wall1.spatial_cluster)
188 d = wall1.angular_cluster
193 q1 = mid1_y - (m_perp * mid1_x)
194 q2 = mid2_y - (m * mid2_x)
200 mid2_projected_x = mid2_projected[0]
201 mid2_projected_y = mid2_projected[1]
202 return length(mid1_x, mid1_y, mid2_projected_x, mid2_projected_y)
206 return length(mid1_x, mid1_y, mid1_x, mid2_y)
228 d = wall1.angular_cluster
233 q1 = mid1_y - (m_perp * mid1_x)
234 q2 = mid2_y - (m * mid2_x)
239 mid2_projected_x = mid2_projected[0]
240 mid2_projected_y = mid2_projected[1]
241 return mid2_projected_x, mid2_projected_y
245 return mid2_x, mid1_y
252 for wall
in walls_list:
253 x_coordinates.append(float(wall.x1))
254 x_coordinates.append(float(wall.x2))
255 y_coordinates.append(float(wall.y1))
256 y_coordinates.append(float(wall.y2))
257 xmin = min(x_coordinates)
258 xmax = max(x_coordinates)
259 ymin = min(y_coordinates)
260 ymax = max(y_coordinates)
263 return np.array([xmin, xmax, ymin, ymax])
271 for index, segment
in enumerate(extended_segments):
276 for segment2
in extended_segments:
290 points.sort(key=
lambda x: (x[0], x[1]))
291 for i, point
in enumerate(points):
293 if i < len(points)-1:
296 if not ((point[0] == next[0])
and (point[1] == next[1])):
297 edge =
Segment(point[0], point[1], next[0], next[1])
298 edge.set_angular_cluster(segment.angular_cluster)
300 edge.set_spatial_cluster(segment.spatial_cluster)
308 if(x1 != x2)
and (x3 != x4):
319 point = np.array([x1,y])
325 point = np.array([x3,y])
330 for edge
in edges_th1:
331 if (edge.angular_cluster, edge.spatial_cluster)
in border_lines:
343 spatial_cluster = edge.spatial_cluster
344 for wall
in wall_list:
346 if wall.spatial_cluster == spatial_cluster:
347 point1 =
project_point(wall.x1, wall.y1, edge.x1, edge.y1, edge.x2, edge.y2)
348 point2 =
project_point(wall.x2, wall.y2, edge.x1, edge.y1, edge.x2, edge.y2)
352 tmp.sort(key=
lambda x: (x[0], x[1]))
354 tmp2 = [tmp[0][0], tmp[0][1], tmp[1][0], tmp[1][1]]
358 projections.append(tmp2)
361 projections[:] = [tup
for tup
in projections
if not included(tup, projections)]
368 if length(edge.x1, edge.y1, edge.x2, edge.y2) >= 20:
369 weight = coverage /
length(edge.x1, edge.y1, edge.x2, edge.y2)
371 weight = coverage /
length(edge.x1, edge.y1, edge.x2, edge.y2)
373 edge.set_weight(weight)
382 point = np.array([x2, y1])
386 point = np.array([x1, y2])
391 q_perp = y1 - m_perp*x1
399 for seg2
in projections:
410 for seg2
in segment_list:
416 if(x1 == x2 == x3 == x4)
and (y1 >= y3)
and (y2 <= y4):
418 if(x1 > x3)
and (x2 <= x4):
420 if(x1 >= x3)
and (x2 < x4):
428 for seg1
in projections:
433 for seg2
in projections:
439 if(x1 == x2 == x3 == x4)
and (y1 < y3)
and (y3 <= y2 < y4):
440 union = [x1, y1, x2, y4]
441 projections.append(union)
442 projections.remove(seg1)
443 projections.remove(seg2)
445 if(x1 < x3)
and (x3 <= x2 < x4):
446 union = [x1, y1, x4, y4]
447 projections.append(union)
448 projections.remove(seg1)
449 projections.remove(seg2)
461 for segment
in projections:
466 if x1 == x2 == x3 == x4:
467 if (y3 <= y1)
and (y4 >= y2):
469 if (y3 >= y1)
and (y4 <= y2):
471 if (y1 < y3 < y2)
and (y4 > y2):
473 if (y3 < y1)
and (y1 < y4 <y2):
476 if(x3 <= x1)
and (x4 >= x2):
477 return length(x1, y1, x2, y2)
478 if(x3 >= x1)
and (x4 <= x2):
479 coverage +=
length(x3, y3, x4, y4)
480 if(x1 < x3 < x2)
and (x4 > x2):
481 coverage +=
length(x3, y3, x2, y2)
482 if(x3 < x1)
and (x1 < x4 < x2):
483 coverage +=
length(x1, y1, x4, y4)
495 if (edge != edge1)
and (((x1 == x)
and (y1 == y))
or ((x2 == x)
and (y2 == y))):
510 if(x1 == x2)
and (x3 == x4):
512 if ((x1 == x2)
and (x3 != x4))
or ((x1 != x2)
and (x3 == x4)):
516 if abs(m1-m2) < epsilon:
526 for ang, l
in zip(angular_ordered, label):
527 for index, segment
in enumerate(ang):
529 segment.set_wall_cluster(l[index] + c)
533 segment.set_wall_cluster(l[index])
537 for ang
in angular_ordered:
539 walls.append(segment)
544 extended_segments_v2 = []
546 for segment
in extended_segments:
547 if segment.weight > threshold:
548 extended_segments_v2.append(segment)
550 removed.append(segment)
551 return extended_segments_v2, removed
555 extended_segments_v2 = []
556 for segment
in extended_segments:
557 if param < segment.weight <= threshold:
558 extended_segments_v2.append(segment)
559 return extended_segments_v2
571 return x_min, x_max, y_min, y_max
575 dist = math.sqrt((p1[0] - p2[0]) * (p1[0] - p2[0]) + (p1[1] - p2[1]) * (p1[1] - p2[1]))
580 if x1 - 10 <= vertex[0] <= x2 + 10
and y1 - 10 <= vertex[1] <= y2 + 10:
586 x_min, x_max, y_min, y_max = size[0] + 20, 0, size[1] + 20, 0
588 if wall.spatial_cluster == line.spatial_cluster:
589 x_min, x_max, y_min, y_max =
check_pos(x_min, x_max, y_min, y_max, wall.x1, wall.y1)
590 x_min, x_max, y_min, y_max =
check_pos(x_min, x_max, y_min, y_max, wall.x2, wall.y2)
591 x1, x2, y1, y2 = x_min, x_max, y_min, y_max
604 if line.x2 - line.x1 == 0:
605 point1 = np.array([line.x2, y_min])
606 point2 = np.array([line.x2, y_max])
607 point1_real = np.array([x1, y1])
608 point2_real = np.array([x2, y2])
610 m = (line.y2 - line.y1)/(line.x2 - line.x1)
611 q = line.y1 - m * line.x1
612 if x_max - x_min > y_max - y_min:
613 y_for_x_min = m * x_min + q
614 y_for_x_max = m * x_max + q
617 point1 = np.array([x_min, y_for_x_min])
618 point2 = np.array([x_max, y_for_x_max])
619 point1_real = np.array([x1, y1])
620 point2_real = np.array([x2, y2])
622 x_for_y_min = (y_min - q)/m
623 x_for_y_max = (y_max - q)/m
626 point1 = np.array([x_for_y_min, y_min])
627 point2 = np.array([x_for_y_max, y_max])
628 point1_real = np.array([x1, y1])
629 point2_real = np.array([x2, y2])
631 for l
in extended_lines:
632 if segments_intersect(l.x1, l.y1, l.x2, l.y2, point1[0], point1[1], point2[0], point2[1]):
633 vertex =
intersection(l.x1, l.y1, l.x2, l.y2, point1[0], point1[1], point2[0], point2[1])
635 vertices.append(vertex)
636 if len(vertices) >= 2:
641 if d1
is None or d < d1:
644 for i, v
in enumerate(vertices):
645 if v[0] == n1[0]
and v[1] == n1[1]:
649 if d2
is None or d < d2:
652 if n1[0] - n2[0] == 0:
660 m = (line.y2 - line.y1) / (line.x2 - line.x1)
661 q = line.y1 - m * line.x1
664 n1[1] = m * n1[0] + q
666 n2[1] = m * n2[0] + q
669 n1[1] = m * n1[0] + q
671 n2[1] = m * n2[0] + q
672 short_line =
ExtendedSegment(n1, n2, line.angular_cluster, line.spatial_cluster)