VOXL OpenVINS Server 0.7.0
Visual Inertial Odometry Server for VOXL Platform
Loading...
Searching...
No Matches
CameraManager.h
Go to the documentation of this file.
1/**
2 * @file CameraManager.h
3 * @brief Camera management system for VOXL OpenVINS
4 * @author Joao Leonardo Silva Cotta (@zauberflote1)
5 * @date 2025
6 * @version 1.0
7 *
8 * This header defines the CameraManager class, which provides centralized
9 * management of all camera instances in the VOXL OpenVINS system. It handles
10 * camera creation, initialization, and lifecycle management.
11 */
12
13#pragma once
14
15// Standard includes
16#include <memory>
17#include <vector>
18#include <unordered_map>
19#include <string>
20#include <mutex>
21#include <iostream>
22#include <thread>
23#include <unistd.h>
24
25// Local includes
26#include "CameraBase.h"
27#include "MonoCameraMinimal.h"
28#include "StereoCameraMinimal.h"
29
30namespace voxl
31{
32
33 // ============================================================================
34 // CAMERA MANAGER CLASS
35 // ============================================================================
36
37 /**
38 * @class CameraManager
39 * @brief Manages all camera instances in the system
40 *
41 * This class is responsible for creating, initializing, and managing
42 * all camera instances. It provides a centralized point for camera
43 * configuration and access using the singleton pattern.
44 *
45 * The CameraManager provides:
46 * - Centralized camera lifecycle management
47 * - Thread-safe camera access
48 * - Automatic camera type detection and creation
49 * - Resource cleanup and shutdown
50 * - Camera configuration validation
51 *
52 * Key features:
53 * - Singleton pattern for global access
54 * - Template-based camera creation for extensibility
55 * - Thread-safe operations with mutex protection
56 * - Automatic resource management
57 * - Support for multiple camera types
58 */
60 {
61 public:
62 /**
63 * @brief Get the singleton instance of the CameraManager
64 *
65 * Returns the single instance of the CameraManager, creating it
66 * if it doesn't exist (lazy initialization).
67 *
68 * @return Reference to the CameraManager instance
69 */
70 static CameraManager &getInstance();
71
72 /**
73 * @brief Initialize the camera manager with camera configurations
74 *
75 * Sets up the camera manager with the provided camera configurations.
76 * This method creates and initializes all cameras based on their
77 * configuration information.
78 *
79 * @param camera_configs Vector of camera configurations
80 * @return True if successful, false otherwise
81 */
82 bool initialize(const std::vector<cam_info> &camera_configs);
83
84 /**
85 * @brief Shut down all cameras and clean up resources
86 *
87 * Performs a clean shutdown of all camera instances, disconnecting
88 * them from their data sources and freeing allocated resources.
89 */
90 void shutdown();
91
92 /**
93 * @brief Get all cameras
94 *
95 * Returns a vector containing all managed camera instances.
96 *
97 * @return Vector of camera shared pointers
98 */
99 std::vector<std::shared_ptr<CameraBase>> getAllCameras();
100
101 private:
102 /**
103 * @brief Private constructor (singleton pattern)
104 */
105 CameraManager() = default;
106
107 /**
108 * @brief Private destructor (singleton pattern)
109 */
111
112 /**
113 * @brief Deleted copy constructor (singleton pattern)
114 */
115 CameraManager(const CameraManager &) = delete;
116
117 /**
118 * @brief Deleted assignment operator (singleton pattern)
119 */
120 CameraManager &operator=(const CameraManager &) = delete;
121
122 /**
123 * @brief Create and connect a specific type of camera
124 *
125 * Template method that creates and connects a camera of the specified
126 * type. This allows for extensibility to support different camera
127 * implementations while maintaining a consistent interface.
128 *
129 * @tparam CameraType The type of camera to create (MonoCamera, StereoCamera, etc.)
130 * @param config Camera configuration
131 * @return True if camera was successfully created and connected, false otherwise
132 */
133 template <typename CameraType>
134 bool createAndConnectCamera(const cam_info &config);
135
136 // ============================================================================
137 // PRIVATE MEMBER VARIABLES
138 // ============================================================================
139
140 /** @brief Collection of camera instances by ID */
141 std::unordered_map<size_t, std::shared_ptr<CameraBase>> cameras_;
142
143 /**
144 * @brief Mutex for thread-safe operations
145 *
146 * Mutable to allow locking in const methods
147 */
148 mutable std::mutex mutex_;
149
150 /** @brief Flag indicating if the manager has been initialized */
151 bool initialized_{false};
152 };
153
154} // namespace voxl
Base class for camera implementations in VOXL OpenVINS.
Monocular camera implementation for VOXL OpenVINS.
Stereo camera implementation for VOXL OpenVINS.
Manages all camera instances in the system.
void shutdown()
Shut down all cameras and clean up resources.
std::vector< std::shared_ptr< CameraBase > > getAllCameras()
Get all cameras.
bool initialize(const std::vector< cam_info > &camera_configs)
Initialize the camera manager with camera configurations.
static CameraManager & getInstance()
Get the singleton instance of the CameraManager.
Main namespace for VOXL OpenVINS server components.
Camera information and calibration data.
Definition VoxlCommon.h:146