Skip to content

Commit

Permalink
feat(visualization): mask for unused voxels (#18)
Browse files Browse the repository at this point in the history
* feat(visualization): mask for unused voxels
* fix(ci): fix black issue
* fix(visualization): fix unused voxels representation
  • Loading branch information
pmokeev authored Nov 21, 2023
1 parent ba08840 commit 2b34824
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 6 deletions.
25 changes: 19 additions & 6 deletions octreelib/grid/grid.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,24 +161,37 @@ def visualize(self, config: VisualizationConfig = VisualizationConfig()) -> None
plot = k3d.Plot()
random.seed(config.seed)
poses_numbers = self.__pose_voxel_coordinates.keys()
unused_voxel_color = 0x000000 # Black

if config.type is GridVisualizationType.POSE:
for pose_number in poses_numbers:
color = random.randrange(0, 0xFFFFFF)
points = self.get_points(pose_number=pose_number)
leaves = self.get_leaf_points(pose_number=pose_number)
for leaf in leaves:
if leaf.id in config.unused_voxels:
plot += k3d.points(
positions=leaf.get_points(),
point_size=config.point_size,
color=unused_voxel_color,
)

plot += k3d.points(
positions=points,
point_size=config.point_size,
color=color,
)
continue

plot += k3d.points(
positions=leaf.get_points(),
point_size=config.point_size,
color=color,
)
elif config.type is GridVisualizationType.VOXEL:
voxels_colors = {}
for pose_number in poses_numbers:
leaves = self.get_leaf_points(pose_number=pose_number)
for leaf in leaves:
if leaf.id not in voxels_colors.keys():
color = random.randrange(0, 0xFFFFFF)
if leaf.id in config.unused_voxels:
color = unused_voxel_color

voxels_colors[leaf.id] = color

plot += k3d.points(
Expand Down
2 changes: 2 additions & 0 deletions octreelib/grid/grid_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ class VisualizationConfig:
line_color: Represents color of voxels lines in Grid
visualization_filepath: Path to produced `.html` file
visualization_seed: Represents random seed for generating colors
unused_voxels: Represents list of voxels which were unused on optimisation stage
"""

type: GridVisualizationType = GridVisualizationType.VOXEL
Expand All @@ -44,6 +45,7 @@ class VisualizationConfig:
line_color: int = 0xFF0000
filepath: str = "visualization.html"
seed: int = 0
unused_voxels: List[int] = field(default_factory=list)


@dataclass
Expand Down

0 comments on commit 2b34824

Please sign in to comment.