#include "drake/geometry/meshcat_point_cloud_visualizer.h" #include #include #include #include #include "drake/common/extract_double.h" #include "drake/geometry/utilities.h" #include "drake/perception/point_cloud.h" namespace drake { namespace geometry { template MeshcatPointCloudVisualizer::MeshcatPointCloudVisualizer( std::shared_ptr meshcat, std::string path, double publish_period) : systems::LeafSystem( systems::SystemTypeTag{}), meshcat_(std::move(meshcat)), path_(std::move(path)), publish_period_(publish_period) { DRAKE_DEMAND(meshcat_ != nullptr); DRAKE_DEMAND(publish_period >= 0.0); this->DeclarePeriodicPublishEvent( publish_period, 0.0, &MeshcatPointCloudVisualizer::UpdateMeshcat); this->DeclareForcedPublishEvent( &MeshcatPointCloudVisualizer::UpdateMeshcat); cloud_input_port_ = this->DeclareAbstractInputPort("cloud", Value()) .get_index(); pose_input_port_ = this->DeclareAbstractInputPort( "X_ParentCloud", Value>{}) .get_index(); } template template MeshcatPointCloudVisualizer::MeshcatPointCloudVisualizer( const MeshcatPointCloudVisualizer& other) : MeshcatPointCloudVisualizer(other.meshcat_, other.path_, other.publish_period_) { set_point_size(other.point_size_); set_default_rgba(other.default_rgba_); } template void MeshcatPointCloudVisualizer::Delete() const { meshcat_->Delete(path_); } template systems::EventStatus MeshcatPointCloudVisualizer::UpdateMeshcat( const systems::Context& context) const { const auto& cloud = cloud_input_port().template Eval(context); meshcat_->SetObject(path_, cloud, point_size_, default_rgba_); const math::RigidTransformd X_ParentCloud = pose_input_port().HasValue(context) ? internal::convert_to_double( pose_input_port().template Eval>( context)) : math::RigidTransformd::Identity(); meshcat_->SetTransform(path_, X_ParentCloud); return systems::EventStatus::Succeeded(); } } // namespace geometry } // namespace drake DRAKE_DEFINE_CLASS_TEMPLATE_INSTANTIATIONS_ON_DEFAULT_NONSYMBOLIC_SCALARS( class ::drake::geometry::MeshcatPointCloudVisualizer)