Skip to content

Commit

Permalink
Add save perspective
Browse files Browse the repository at this point in the history
 - add feature to save current perspective for next point cloud load
 - activate and deactivate via menu action

Closes: #24
  • Loading branch information
ch-sa committed Oct 13, 2021
1 parent 5b902e6 commit 37b878e
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 0 deletions.
26 changes: 26 additions & 0 deletions labelCloud/control/pcd_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,18 @@
from .config_manager import config
from .label_manager import LabelManager

from dataclasses import dataclass

if TYPE_CHECKING:
from view.gui import GUI


@dataclass
class Perspective:
zoom: float
rotation: Tuple[float, float, float]


def color_pointcloud(points, z_min, z_max):
palette = np.loadtxt("labelCloud/ressources/rocket-palette.txt")
palette_len = len(palette) - 1
Expand Down Expand Up @@ -49,6 +57,7 @@ def __init__(self):
# Point cloud control
self.pointcloud = None
self.collected_object_classes = set()
self.saved_perspective: Perspective = None

def read_pointcloud_folder(self):
"""Checks point cloud folder and sets self.pcds to all valid point cloud file names."""
Expand Down Expand Up @@ -137,6 +146,17 @@ def save_labels_into_file(self, bboxes: List[BBox]):
else:
print("No point clouds to save labels for!")

def save_current_perspective(self, active: bool = True) -> None:
if active:
self.saved_perspective = Perspective(
zoom=self.pointcloud.trans_z,
rotation=tuple(self.pointcloud.get_rotations()),
)
print(f"Saved current perspective ({self.saved_perspective}).")
else:
self.saved_perspective = None
print("Reset saved perspective.")

# MANIPULATOR
def load_pointcloud(self, path_to_pointcloud: str) -> PointCloud:
print("=" * 20, "Loading", ntpath.basename(path_to_pointcloud), "=" * 20)
Expand Down Expand Up @@ -180,6 +200,12 @@ def load_pointcloud(self, path_to_pointcloud: str) -> PointCloud:

tmp_pcd.init_translation = -self.current_o3d_pcd.get_center() - [0, 0, diagonal]

if self.saved_perspective != None:
tmp_pcd.init_translation = tuple(
list(tmp_pcd.init_translation[:2]) + [self.saved_perspective.zoom]
)
tmp_pcd.set_rotations(*self.saved_perspective.rotation)

tmp_pcd.reset_translation()
tmp_pcd.print_details()
if self.pointcloud is not None: # Skip first pcd to intialize OpenGL first
Expand Down
10 changes: 10 additions & 0 deletions labelCloud/model/point_cloud.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,11 @@ def set_rot_y(self, angle):
def set_rot_z(self, angle):
self.rot_z = angle % 360

def set_rotations(self, x: float, y: float, z: float):
self.rot_x = x % 360
self.rot_y = y % 360
self.rot_z = z % 360

def set_trans_x(self, val):
self.trans_x = val

Expand All @@ -82,6 +87,11 @@ def set_trans_y(self, val):
def set_trans_z(self, val):
self.trans_z = val

def set_translations(self, x: float, y: float, z: float):
self.trans_x = x
self.trans_y = y
self.trans_z = z

# MANIPULATORS

def transform_data(self):
Expand Down
12 changes: 12 additions & 0 deletions labelCloud/ressources/interface.ui
Original file line number Diff line number Diff line change
Expand Up @@ -1538,6 +1538,7 @@ QListWidget#label_list::item:selected {
<addaction name="action_zrotationonly"/>
<addaction name="action_showfloor"/>
<addaction name="action_showorientation"/>
<addaction name="action_saveperspective"/>
<addaction name="action_alignpcd"/>
<addaction name="action_changesettings"/>
</widget>
Expand Down Expand Up @@ -1614,6 +1615,17 @@ QListWidget#label_list::item:selected {
<string>Show Orientation</string>
</property>
</action>
<action name="action_saveperspective">
<property name="checkable">
<bool>true</bool>
</property>
<property name="checked">
<bool>false</bool>
</property>
<property name="text">
<string>Save current Perspective</string>
</property>
</action>
<action name="action_alignpcd">
<property name="checkable">
<bool>true</bool>
Expand Down
6 changes: 6 additions & 0 deletions labelCloud/view/gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,9 @@ def __init__(self, control: "Controller"):
self.action_showorientation = self.findChild(
QtWidgets.QAction, "action_showorientation"
)
self.action_saveperspective = self.findChild(
QtWidgets.QAction, "action_saveperspective"
)
self.action_alignpcd = self.findChild(QtWidgets.QAction, "action_alignpcd")
self.action_change_settings = self.findChild(
QtWidgets.QAction, "action_changesettings"
Expand Down Expand Up @@ -296,6 +299,9 @@ def connect_events(self):
self.action_zrotation.toggled.connect(set_zrotation_only)
self.action_showfloor.toggled.connect(set_floor_visibility)
self.action_showorientation.toggled.connect(set_orientation_visibility)
self.action_saveperspective.toggled.connect(
lambda state: self.controller.pcd_manager.save_current_perspective(state)
)
self.action_alignpcd.toggled.connect(
self.controller.align_mode.change_activation
)
Expand Down

0 comments on commit 37b878e

Please sign in to comment.