Implementation:Facebookresearch Habitat lab UserMask
| Knowledge Sources | |
|---|---|
| Domains | Embodied_AI, Human_in_the_Loop |
| Last Updated | 2026-02-15 00:00 GMT |
Overview
UserMask defines the Mask and Users classes that provide bitmask-based user targeting and user set management for the Habitat HITL multi-user framework.
Description
This module provides two core classes for managing multiple users in HITL applications:
- Mask (IntFlag): A bitmask type that represents a set of user indices. It supports standard bitwise operations (|, &, ^, ~) for combining and filtering user sets. Key static methods include:
- from_index(index): Creates a mask for a single user index.
- from_indices(indices): Creates a mask for multiple user indices.
- all_except_index(index): Creates a mask for all users except one.
- all_except_indices(indices): Creates a mask for all users except a list.
- Predefined constants: NONE (0), ALL (~0), and MAX_VALUE (32).
- Users: Manages a bounded set of users with activation/deactivation semantics. Users start inactive and can be activated individually. The class provides:
- indices(user_mask): A generator yielding active user indices that match the given mask.
- activate_user(user_index) / deactivate_user(user_index): Toggle user activity.
- to_index_list(user_mask): Convert a mask to a list of active user indices.
- max_user_count and active_user_count properties.
The bitmask approach allows efficient user targeting in multi-user scenarios, such as sending rendering data or messages to specific subsets of users.
Usage
Use Mask wherever you need to specify which users should receive a message, see a visual element, or be affected by an operation. Use Users to manage the set of active users and iterate over them efficiently.
Code Reference
Source Location
- Repository: Facebookresearch_Habitat_lab
- File: habitat-hitl/habitat_hitl/core/user_mask.py
- Lines: 1-128
Signature
class Mask(IntFlag):
NONE: Final[int] = 0
ALL: Final[int] = ~0
MAX_VALUE: Final[int] = 32
@staticmethod
def from_index(index: int) -> Mask:
...
@staticmethod
def from_indices(indices: List[int]) -> Mask:
...
@staticmethod
def all_except_index(index: int) -> Mask:
...
@staticmethod
def all_except_indices(indices: List[int]) -> Mask:
...
class Users:
def __init__(self, max_user_count: int, activate_users: bool = False) -> None:
...
def indices(self, user_mask: Mask) -> Generator[int, Any, None]:
...
def activate_user(self, user_index: int) -> None:
...
def deactivate_user(self, user_index: int) -> None:
...
def to_index_list(self, user_mask: Mask) -> List[int]:
...
@property
def max_user_count(self) -> int:
...
@property
def active_user_count(self) -> int:
...
Import
from habitat_hitl.core.user_mask import Mask, Users
I/O Contract
Inputs (Users.__init__)
| Name | Type | Required | Description |
|---|---|---|---|
| max_user_count | int | Yes | Maximum number of users (0 to 32). |
| activate_users | bool | No | If True, all users are initially active. Defaults to False. |
Outputs
| Name | Type | Description |
|---|---|---|
| Mask.from_index(i) | Mask | A bitmask with only user index i set. |
| Mask.from_indices(lst) | Mask | A bitmask with all listed user indices set. |
| Users.indices(mask) | Generator[int] | Generator yielding active user indices matching the mask. |
| Users.max_user_count | int | The maximum user count for this Users instance. |
| Users.active_user_count | int | The number of currently active users. |
Usage Examples
Basic Usage
from habitat_hitl.core.user_mask import Mask, Users
# Create a user set with 4 users, all initially active
users = Users(max_user_count=4, activate_users=True)
# Create masks for specific users
user_0_mask = Mask.from_index(0)
users_1_and_2 = Mask.from_indices([1, 2])
all_except_0 = Mask.all_except_index(0)
# Iterate over active users matching a mask
for user_index in users.indices(users_1_and_2):
print(f"Processing user {user_index}")
# Deactivate a user
users.deactivate_user(2)
print(f"Active users: {users.active_user_count}")
# Combine masks with bitwise operators
combined = user_0_mask | users_1_and_2
for user_index in users.indices(combined):
print(f"User {user_index} in combined mask")