Skip to main content

GetMasks2DAutomask Struct

Segment an image using SAM2 automasking with grid-based point generation. More...

Declaration

struct moveit_pro::behaviors::GetMasks2DAutomask { ... }

Included Headers

#include <sam2_automasking.hpp>

Base struct

classAsyncBehaviorBase

A base class for behaviors which need to asynchronously run a function that might take a long time to complete. More...

Public Constructors Index

GetMasks2DAutomask (const std::string &name, const BT::NodeConfiguration &config, const std::shared_ptr< moveit_pro::behaviors::BehaviorContext > &shared_resources, std::unique_ptr< InferenceHandle > inference_handle=std::make_unique< SAM2AutomaskHandle >())

Constructor for SAM2 automasking behavior. More...

Public Destructor Index

~GetMasks2DAutomask () override

Private Member Functions Index

tl::expected< bool, std::string >doWork () override

Execute automasking. More...

tl::expected< void, std::string >doHalt () override

Cancel an in-flight SAM2 automasking inference via the inference handle. More...

std::shared_future< tl::expected< bool, std::string > > &getFuture () override

Classes derived from AsyncBehaviorBase must implement getFuture() More...

Private Member Attributes Index

std::unique_ptr< InferenceHandle >inference_handle_
std::optional< internal::Sam2AutomaskModelPorts >latched_ports_
boolcpu_fallback_warning_published_ { false }
std::shared_future< tl::expected< bool, std::string > >future_

Classes derived from AsyncBehaviorBase must have this shared_future as a class member. More...

Public Static Functions Index

static BT::PortsListprovidedPorts ()

Provides port definitions for BehaviorTree. More...

static BT::KeyValueVectormetadata ()

Provides behavior metadata for UI. More...

Description

Segment an image using SAM2 automasking with grid-based point generation.

This behavior automatically segments an image by generating a uniform grid of points and running SAM2 inference on each point. Applies NMS to remove overlapping masks and splits disconnected components.

Data Port NamePort TypeObject Type
imageinputsensor_msgs::msg::Image
grid_sizeinputint
score_thresholdinputfloat
nms_thresholdinputfloat
min_component_areainputint
model_bundle_manifestinputstd::string
runtime_idinputstd::string
model_packageinputstd::string
masks2doutputstd::vector<moveit_studio_vision_msgs::msg::Mask2D>
mask_countoutputint

Definition at line 87 of file sam2_automasking.hpp.

Public Constructors

GetMasks2DAutomask()

moveit_pro::behaviors::GetMasks2DAutomask::GetMasks2DAutomask (const std::string & name, const BT::NodeConfiguration & config, const std::shared_ptr< moveit_pro::behaviors::BehaviorContext > & shared_resources, std::unique_ptr< InferenceHandle > inference_handle=std::make_unique< SAM2AutomaskHandle >())

Constructor for SAM2 automasking behavior.

Parameters
name

Behavior instance name

config

Behavior configuration

shared_resources

Shared behavior resources

inference_handle

Custom inference implementation (default uses SAM2AutomaskHandle)

Declaration at line 190 of file sam2_automasking.hpp, definition at line 216 of file sam2_automasking.cpp.

Public Destructor

~GetMasks2DAutomask()

moveit_pro::behaviors::GetMasks2DAutomask::~GetMasks2DAutomask ()

Definition at line 194 of file sam2_automasking.hpp.

Private Member Functions

doHalt()

tl::expected< void, std::string > moveit_pro::behaviors::GetMasks2DAutomask::doHalt ()
virtual

Cancel an in-flight SAM2 automasking inference via the inference handle.

Forwards to InferenceHandle::requestTerminate(), which cancels the pipeline at the next per-graph boundary. doWork() is responsible for calling clearTerminate() and notifyCanHalt() before invoking predict() so this halt is observable.

Declaration at line 221 of file sam2_automasking.hpp, definition at line 419 of file sam2_automasking.cpp.

doWork()

tl::expected< bool, std::string > moveit_pro::behaviors::GetMasks2DAutomask::doWork ()
virtual

Execute automasking.

Returns

Success or error message

Declaration at line 213 of file sam2_automasking.hpp, definition at line 269 of file sam2_automasking.cpp.

getFuture()

std::shared_future< tl::expected< bool, std::string > > & moveit_pro::behaviors::GetMasks2DAutomask::getFuture ()
inline virtual

Classes derived from AsyncBehaviorBase must implement getFuture()

Definition at line 235 of file sam2_automasking.hpp.

Private Member Attributes

cpu_fallback_warning_published_

bool moveit_pro::behaviors::GetMasks2DAutomask::cpu_fallback_warning_published_ { false }

True once the CPU-inference warning has been published, so it fires once per behavior instance rather than on every tick (load() is idempotent and called from every doWork()); the model latches at first load, so the served device cannot change afterwards.

Definition at line 232 of file sam2_automasking.hpp.

future_

std::shared_future<tl::expected<bool, std::string> > moveit_pro::behaviors::GetMasks2DAutomask::future_

Classes derived from AsyncBehaviorBase must have this shared_future as a class member.

Definition at line 241 of file sam2_automasking.hpp.

inference_handle_

std::unique_ptr<InferenceHandle> moveit_pro::behaviors::GetMasks2DAutomask::inference_handle_

Definition at line 222 of file sam2_automasking.hpp.

latched_ports_

std::optional<internal::Sam2AutomaskModelPorts> moveit_pro::behaviors::GetMasks2DAutomask::latched_ports_

The model-selecting port values this instance loaded with, empty until the first load. The model latches: a later tick naming different values fails the Behavior rather than swapping models mid-run.

Definition at line 227 of file sam2_automasking.hpp.

Public Static Functions

metadata()

BT::KeyValueVector moveit_pro::behaviors::GetMasks2DAutomask::metadata ()
static

Provides behavior metadata for UI.

Returns

Metadata key-value pairs

Declaration at line 206 of file sam2_automasking.hpp, definition at line 260 of file sam2_automasking.cpp.

providedPorts()

BT::PortsList moveit_pro::behaviors::GetMasks2DAutomask::providedPorts ()
static

Provides port definitions for BehaviorTree.

Returns

List of input and output ports

Declaration at line 200 of file sam2_automasking.hpp, definition at line 226 of file sam2_automasking.cpp.


The documentation for this struct was generated from the following files:


Generated via doxygen2docusaurus 2.2.2 by Doxygen 1.9.8.