NVIDIA Holoscan SDK v2.7.0
Holoscan v2.7.0

Program Listing for File holoviz.hpp

Return to documentation for file (include/holoscan/operators/holoviz/holoviz.hpp)

Copy
Copied!
            

/* * SPDX-FileCopyrightText: Copyright (c) 2022-2024 NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #ifndef INCLUDE_HOLOSCAN_OPERATORS_HOLOVIZ_HOLOVIZ_HPP #define INCLUDE_HOLOSCAN_OPERATORS_HOLOVIZ_HOLOVIZ_HPP #include <array> #include <memory> #include <optional> #include <string> #include <vector> #include "holoscan/core/conditions/gxf/boolean.hpp" #include "holoscan/core/io_context.hpp" #include "holoscan/core/io_spec.hpp" #include "holoscan/core/operator.hpp" #include "holoscan/core/operator_spec.hpp" #include "holoscan/core/resources/gxf/allocator.hpp" #include "holoscan/utils/cuda_stream_handler.hpp" #include <holoviz/callbacks.hpp> namespace holoscan::viz { typedef void* InstanceHandle; } // namespace holoscan::viz namespace holoscan::ops { // forward declaration struct BufferInfo; class HolovizOp : public Operator { public: HOLOSCAN_OPERATOR_FORWARD_ARGS(HolovizOp) HolovizOp() = default; void setup(OperatorSpec& spec) override; void initialize() override; void start() override; void compute(InputContext& op_input, OutputContext& op_output, ExecutionContext& context) override; void stop() override; enum class InputType { UNKNOWN, COLOR, COLOR_LUT, POINTS, LINES, LINE_STRIP, TRIANGLES, CROSSES, RECTANGLES, OVALS, TEXT, DEPTH_MAP, DEPTH_MAP_COLOR, POINTS_3D, LINES_3D, LINE_STRIP_3D, TRIANGLES_3D, }; enum class ImageFormat { R8_UINT, R8_SINT, R8_UNORM, R8_SNORM, R8_SRGB, R16_UINT, R16_SINT, R16_UNORM, R16_SNORM, R16_SFLOAT, R32_UINT, R32_SINT, R32_SFLOAT, R8G8B8_UNORM, R8G8B8_SNORM, R8G8B8_SRGB, R8G8B8A8_UNORM, R8G8B8A8_SNORM, R8G8B8A8_SRGB, R16G16B16A16_UNORM, R16G16B16A16_SNORM, R16G16B16A16_SFLOAT, R32G32B32A32_SFLOAT, D16_UNORM, X8_D24_UNORM, D32_SFLOAT, A2B10G10R10_UNORM_PACK32, A2R10G10B10_UNORM_PACK32, B8G8R8A8_UNORM, B8G8R8A8_SRGB, A8B8G8R8_UNORM_PACK32, A8B8G8R8_SRGB_PACK32, Y8U8Y8V8_422_UNORM, U8Y8V8Y8_422_UNORM, Y8_U8V8_2PLANE_420_UNORM, Y8_U8V8_2PLANE_422_UNORM, Y8_U8_V8_3PLANE_420_UNORM, Y8_U8_V8_3PLANE_422_UNORM, Y16_U16V16_2PLANE_420_UNORM, Y16_U16V16_2PLANE_422_UNORM, Y16_U16_V16_3PLANE_420_UNORM, Y16_U16_V16_3PLANE_422_UNORM, AUTO_DETECT = -1 }; enum class YuvModelConversion { YUV_601, YUV_709, YUV_2020, }; enum class YuvRange { ITU_FULL, ITU_NARROW, }; enum class ChromaLocation { COSITED_EVEN, MIDPOINT, }; enum class DepthMapRenderMode { POINTS, LINES, TRIANGLES }; enum class ColorSpace { SRGB_NONLINEAR, EXTENDED_SRGB_LINEAR, BT2020_LINEAR, HDR10_ST2084, PASS_THROUGH, BT709_LINEAR, AUTO = -1, }; struct InputSpec { InputSpec() = default; InputSpec(const std::string& tensor_name, InputType type) : tensor_name_(tensor_name), type_(type) {} InputSpec(const std::string& tensor_name, const std::string& type_str); explicit InputSpec(const std::string& yaml_description); explicit operator bool() const noexcept { return !tensor_name_.empty(); } std::string description() const; std::string tensor_name_; InputType type_ = InputType::UNKNOWN; float opacity_ = 1.F; int32_t priority_ = 0; ImageFormat image_format_ = ImageFormat::AUTO_DETECT; YuvModelConversion yuv_model_conversion_ = YuvModelConversion::YUV_601; YuvRange yuv_range_ = YuvRange::ITU_FULL; ChromaLocation x_chroma_location_ = ChromaLocation::COSITED_EVEN; ChromaLocation y_chroma_location_ = ChromaLocation::COSITED_EVEN; std::vector<float> color_{1.F, 1.F, 1.F, 1.F}; float line_width_ = 1.F; float point_size_ = 1.F; std::vector<std::string> text_; DepthMapRenderMode depth_map_render_mode_ = DepthMapRenderMode::POINTS; struct View { float offset_x_ = 0.F, offset_y_ = 0.F; float width_ = 1.F, height_ = 1.F; std::optional<std::array<float, 16>> matrix_; }; std::vector<View> views_; }; using Key = viz::Key; using KeyAndButtonAction = viz::KeyAndButtonAction; using KeyModifiers = viz::KeyModifiers; using MouseButton = viz::MouseButton; using KeyCallbackFunction = std::function<void(Key key, KeyAndButtonAction action, KeyModifiers modifiers)>; using UnicodeCharCallbackFunction = std::function<void(uint32_t code_point)>; using MouseButtonCallbackFunction = std::function<void(MouseButton button, KeyAndButtonAction action, KeyModifiers modifiers)>; using ScrollCallbackFunction = std::function<void(double x_offset, double y_offset)>; using CursorPosCallbackFunction = std::function<void(double x_pos, double y_pos)>; using FramebufferSizeCallbackFunction = std::function<void(int width, int height)>; using WindowSizeCallbackFunction = std::function<void(int width, int height)>; using LayerCallbackFunction = std::function<void(const std::vector<holoscan::gxf::Entity>& inputs)>; private: bool enable_conditional_port(const std::string& name, bool set_none_condition_on_disabled = false); void set_input_spec(const InputSpec& input_spec); void set_input_spec_geometry(const InputSpec& input_spec); void read_frame_buffer(InputContext& op_input, OutputContext& op_output, ExecutionContext& context); void render_color_image(const InputSpec& input_spec, BufferInfo& buffer_info); void render_geometry(const ExecutionContext& context, const InputSpec& input_spec, BufferInfo& buffer_info); void render_depth_map(InputSpec* const input_spec_depth_map, const BufferInfo& buffer_info_depth_map, InputSpec* const input_spec_depth_map_color, const BufferInfo& buffer_info_depth_map_color); Parameter<holoscan::IOSpec*> render_buffer_input_; Parameter<holoscan::IOSpec*> render_buffer_output_; Parameter<holoscan::IOSpec*> camera_pose_output_; Parameter<std::vector<InputSpec>> tensors_; Parameter<std::vector<std::vector<float>>> color_lut_; Parameter<std::string> window_title_; Parameter<std::string> display_name_; Parameter<uint32_t> width_; Parameter<uint32_t> height_; Parameter<float> framerate_; Parameter<bool> use_exclusive_display_; Parameter<bool> fullscreen_; Parameter<bool> headless_; Parameter<bool> framebuffer_srgb_; Parameter<bool> vsync_; Parameter<ColorSpace> display_color_space_; Parameter<std::shared_ptr<BooleanCondition>> window_close_scheduling_term_; Parameter<std::shared_ptr<BooleanCondition>> window_close_condition_; Parameter<std::shared_ptr<Allocator>> allocator_; Parameter<std::string> font_path_; Parameter<std::string> camera_pose_output_type_; Parameter<std::array<float, 3>> camera_eye_; Parameter<std::array<float, 3>> camera_look_at_; Parameter<std::array<float, 3>> camera_up_; holoscan::Parameter<KeyCallbackFunction> key_callback_; holoscan::Parameter<UnicodeCharCallbackFunction> unicode_char_callback_; holoscan::Parameter<MouseButtonCallbackFunction> mouse_button_callback_; holoscan::Parameter<ScrollCallbackFunction> scroll_callback_; holoscan::Parameter<CursorPosCallbackFunction> cursor_pos_callback_; holoscan::Parameter<FramebufferSizeCallbackFunction> framebuffer_size_callback_; holoscan::Parameter<WindowSizeCallbackFunction> window_size_callback_; holoscan::Parameter<LayerCallbackFunction> layer_callback_; // internal state viz::InstanceHandle instance_ = nullptr; std::vector<float> lut_; std::vector<InputSpec> initial_input_spec_; CudaStreamHandler cuda_stream_handler_; bool render_buffer_input_enabled_ = false; bool render_buffer_output_enabled_ = false; bool camera_pose_output_enabled_ = false; bool is_first_tick_ = true; static std::remove_pointer_t<viz::KeyCallbackFunction> key_callback_handler; static std::remove_pointer_t<viz::UnicodeCharCallbackFunction> unicode_char_callback_handler; static std::remove_pointer_t<viz::MouseButtonCallbackFunction> mouse_button_callback_handler; static std::remove_pointer_t<viz::ScrollCallbackFunction> scroll_callback_handler; static std::remove_pointer_t<viz::CursorPosCallbackFunction> cursor_pos_callback_handler; static std::remove_pointer_t<viz::FramebufferSizeCallbackFunction> framebuffer_size_callback_handler; static std::remove_pointer_t<viz::WindowSizeCallbackFunction> window_size_callback_handler; std::array<float, 3> camera_eye_cur_; //< current camera eye position std::array<float, 3> camera_look_at_cur_; //< current camera look at position std::array<float, 3> camera_up_cur_; //< current camera up vector }; } // namespace holoscan::ops #endif/* INCLUDE_HOLOSCAN_OPERATORS_HOLOVIZ_HOLOVIZ_HPP */

© Copyright 2022-2024, NVIDIA. Last updated on Dec 2, 2024.