// Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. // Associated header // #include "k4awindowset.h" // System headers // // Library headers // // Project headers // #include "k4aaudiowindow.h" #include "k4acolorimageconverter.h" #include "k4adepthimageconverter.h" #include "k4aimguiextensions.h" #include "k4aimugraphdatagenerator.h" #include "k4aimuwindow.h" #include "k4ainfraredimageconverter.h" #include "k4apointcloudwindow.h" #include "k4awindowmanager.h" using namespace k4aviewer; namespace { template void CreateVideoWindow(const char *sourceIdentifier, const char *windowTitle, K4ADataSource &cameraDataSource, std::shared_ptr> &&imageSource) { std::string title = std::string(sourceIdentifier) + ": " + windowTitle; cameraDataSource.RegisterObserver(imageSource); std::unique_ptr window( std14::make_unique>(std::move(title), imageSource)); K4AWindowManager::Instance().AddWindow(std::move(window)); } } // namespace void K4AWindowSet::ShowModeSelector(ViewType *viewType, bool enabled, bool pointCloudViewerEnabled, const std::function &changeViewFn) { ImGui::Text("View Mode"); const ViewType oldViewType = *viewType; bool modeClicked = false; modeClicked |= ImGuiExtensions::K4ARadioButton("2D", reinterpret_cast(viewType), static_cast(ViewType::Normal), enabled); ImGui::SameLine(); modeClicked |= ImGuiExtensions::K4ARadioButton("3D", reinterpret_cast(viewType), static_cast(ViewType::PointCloudViewer), pointCloudViewerEnabled && enabled); ImGuiExtensions::K4AShowTooltip("Requires depth camera!", !pointCloudViewerEnabled); if (modeClicked && oldViewType != *viewType) { changeViewFn(*viewType); } } void K4AWindowSet::StartNormalWindows(const char *sourceIdentifier, K4ADataSource *cameraDataSource, K4ADataSource *imuDataSource, std::shared_ptr &µphoneDataSource, bool enableDepthCamera, k4a_depth_mode_t depthMode, bool enableColorCamera, k4a_image_format_t colorFormat, k4a_color_resolution_t colorResolution) { if (cameraDataSource != nullptr) { if (enableDepthCamera) { CreateVideoWindow(sourceIdentifier, "Infrared Camera", *cameraDataSource, std::make_shared>( std14::make_unique(depthMode))); // K4A_DEPTH_MODE_PASSIVE_IR doesn't support actual depth // if (depthMode != K4A_DEPTH_MODE_PASSIVE_IR) { CreateVideoWindow(sourceIdentifier, "Depth Camera", *cameraDataSource, std::make_shared>( std14::make_unique(depthMode))); } } if (enableColorCamera) { constexpr char colorWindowTitle[] = "Color Camera"; switch (colorFormat) { case K4A_IMAGE_FORMAT_COLOR_YUY2: CreateVideoWindow( sourceIdentifier, colorWindowTitle, *cameraDataSource, std::make_shared>( K4AColorImageConverterFactory::Create(colorResolution))); break; case K4A_IMAGE_FORMAT_COLOR_MJPG: CreateVideoWindow( sourceIdentifier, colorWindowTitle, *cameraDataSource, std::make_shared>( K4AColorImageConverterFactory::Create(colorResolution))); break; case K4A_IMAGE_FORMAT_COLOR_BGRA32: CreateVideoWindow( sourceIdentifier, colorWindowTitle, *cameraDataSource, std::make_shared>( K4AColorImageConverterFactory::Create(colorResolution))); break; case K4A_IMAGE_FORMAT_COLOR_NV12: CreateVideoWindow( sourceIdentifier, colorWindowTitle, *cameraDataSource, std::make_shared>( K4AColorImageConverterFactory::Create(colorResolution))); break; default: K4AViewerErrorManager::Instance().SetErrorStatus("Invalid color mode!"); } } } // Build a collection of the graph-type windows we're using so the window manager knows it can group them // in the same section // std::vector> graphWindows; if (imuDataSource != nullptr) { std::string title = std::string(sourceIdentifier) + ": IMU Data"; auto imuGraphDataGenerator = std::make_shared(); imuDataSource->RegisterObserver(std::static_pointer_cast(imuGraphDataGenerator)); graphWindows.emplace_back(std14::make_unique(std::move(title), std::move(imuGraphDataGenerator))); } if (microphoneDataSource != nullptr) { std::string micTitle = std::string(sourceIdentifier) + ": Microphone Data"; graphWindows.emplace_back(std::unique_ptr( std14::make_unique(std::move(micTitle), std::move(microphoneDataSource)))); } if (!graphWindows.empty()) { K4AWindowManager::Instance().AddWindowGroup(std::move(graphWindows)); } } void K4AWindowSet::StartPointCloudWindow(const char *sourceIdentifier, const k4a::calibration &calibrationData, K4ADataSource *cameraDataSource, bool enableColorPointCloud) { std::string pointCloudTitle = std::string(sourceIdentifier) + ": Point Cloud Viewer"; auto captureSource = std::make_shared(); cameraDataSource->RegisterObserver(captureSource); auto &wm = K4AWindowManager::Instance(); wm.AddWindow(std14::make_unique(std::move(pointCloudTitle), enableColorPointCloud, std::move(captureSource), calibrationData)); }