Skip to content

Commit

Permalink
Merge pull request #28 from ch-sa/ch/save-perspective
Browse files Browse the repository at this point in the history
Keep the perspective when changing point clouds
  • Loading branch information
ch-sa authored Oct 19, 2021
2 parents 5b902e6 + 3fad6e3 commit 36ca070
Show file tree
Hide file tree
Showing 8 changed files with 205 additions and 127 deletions.
9 changes: 6 additions & 3 deletions config.ini
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ show_orientation = True
background_color = 100, 100, 100
; number of decimal places shown for the parameters of the active bounding box
viewing_precision = 2
; near and far clipping plane for OpenGL (where objects are visible, in meter)
near_plane=0.1
far_plane=300
; near and far clipping plane for opengl (where objects are visible, in meter)
near_plane = 0.1
far_plane = 300
; keep last perspective between point clouds
keep_perspective = False

29 changes: 29 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,10 +146,24 @@ 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)

if config.getboolean("USER_INTERFACE", "keep_perspective"):
self.save_current_perspective()

if (
os.path.splitext(path_to_pointcloud)[1] == ".bin"
): # Loading binary pcds with numpy
Expand Down Expand Up @@ -180,6 +203,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
4 changes: 3 additions & 1 deletion labelCloud/ressources/default_config.ini
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,6 @@ background_color = 100, 100, 100
viewing_precision = 2
; near and far clipping plane for OpenGL (where objects are visible, in meter)
near_plane=0.1
far_plane=300
far_plane=300
; keep last perspective between point clouds
keep_perspective = False
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
Loading

0 comments on commit 36ca070

Please sign in to comment.