(self)
| 72 | return np.array(lines) |
| 73 | |
| 74 | def create_line_mesh(self): |
| 75 | first_points = self.points[self.lines[:, 0], :] |
| 76 | second_points = self.points[self.lines[:, 1], :] |
| 77 | line_segments = second_points - first_points |
| 78 | line_segments_unit, line_lengths = normalized(line_segments) |
| 79 | |
| 80 | z_axis = np.array([0, 0, 1]) |
| 81 | # Create triangular mesh cylinder segments of line |
| 82 | for i in range(line_segments_unit.shape[0]): |
| 83 | line_segment = line_segments_unit[i, :] |
| 84 | line_length = line_lengths[i] |
| 85 | # get axis angle rotation to allign cylinder with line segment |
| 86 | axis, angle = align_vector_to_another(z_axis, line_segment) |
| 87 | # Get translation vector |
| 88 | translation = first_points[i, :] + \ |
| 89 | line_segment * line_length * 0.5 |
| 90 | # create cylinder and apply transformations |
| 91 | cylinder_segment = o3d.geometry.TriangleMesh.create_cylinder( |
| 92 | self.radius, line_length) |
| 93 | cylinder_segment = cylinder_segment.translate(translation, |
| 94 | relative=False) |
| 95 | if axis is not None: |
| 96 | axis_a = axis * angle |
| 97 | cylinder_segment = cylinder_segment.rotate( |
| 98 | R=o3d.geometry.get_rotation_matrix_from_axis_angle( |
| 99 | axis_a)) # center=True) |
| 100 | # cylinder_segment = cylinder_segment.rotate( |
| 101 | # axis_a, center=True, |
| 102 | # type=o3d.geometry.RotationType.AxisAngle) |
| 103 | # color cylinder |
| 104 | color = self.colors if self.colors.ndim == 1 \ |
| 105 | else self.colors[i, :] |
| 106 | cylinder_segment.paint_uniform_color(color) |
| 107 | |
| 108 | self.cylinder_segments.append(cylinder_segment) |
| 109 | |
| 110 | def add_line(self, vis): |
| 111 | """Adds this line to the visualizer.""" |
no test coverage detected