VOXL OpenVINS Server 1.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 Zauberflote
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#include "CameraQueueFusion.h"
30
31namespace voxl
32{
33
34 // ============================================================================
35 // CAMERA MANAGER CLASS
36 // ============================================================================
37
38 /**
39 * @class CameraManager
40 * @brief Manages all camera instances in the system
41 *
42 * This class is responsible for creating, initializing, and managing
43 * all camera instances. It provides a centralized point for camera
44 * configuration and access using the singleton pattern.
45 *
46 * The CameraManager provides:
47 * - Centralized camera lifecycle management
48 * - Thread-safe camera access
49 * - Automatic camera type detection and creation
50 * - Resource cleanup and shutdown
51 * - Camera configuration validation
52 *
53 * Key features:
54 * - Singleton pattern for global access
55 * - Template-based camera creation for extensibility
56 * - Thread-safe operations with mutex protection
57 * - Automatic resource management
58 * - Support for multiple camera types
59 */
61 {
62 public:
63 /**
64 * @brief Get the singleton instance of the CameraManager
65 *
66 * Returns the single instance of the CameraManager, creating it
67 * if it doesn't exist (lazy initialization).
68 *
69 * @return Reference to the CameraManager instance
70 */
71 static CameraManager &getInstance();
72
73 /**
74 * @brief Initialize the camera manager with camera configurations
75 *
76 * Sets up the camera manager with the provided camera configurations.
77 * This method creates and initializes all cameras based on their
78 * configuration information.
79 *
80 * @param camera_configs Vector of camera configurations
81 * @return True if successful, false otherwise
82 */
83 bool initialize(const std::vector<cam_info> &camera_configs);
84
85 /**
86 * @brief Shut down all cameras and clean up resources
87 *
88 * Performs a clean shutdown of all camera instances, disconnecting
89 * them from their data sources and freeing allocated resources.
90 */
91 void shutdown();
92
93 /**
94 * @brief Get a camera by its ID
95 *
96 * Retrieves a specific camera instance by its unique identifier.
97 *
98 * @param camera_id The ID of the camera to retrieve
99 * @return Shared pointer to the camera, or nullptr if not found
100 */
101 std::shared_ptr<CameraBase> getCamera(size_t camera_id);
102
103 /**
104 * @brief Get all cameras
105 *
106 * Returns a vector containing all managed camera instances.
107 *
108 * @return Vector of camera shared pointers
109 */
110 std::vector<std::shared_ptr<CameraBase>> getAllCameras();
111
112 /**
113 * @brief Get the number of cameras
114 *
115 * Returns the total number of cameras currently managed by the system.
116 *
117 * @return Number of cameras managed
118 */
119 size_t getCameraCount() const;
120
121 /**
122 * @brief Check if the camera manager is initialized
123 *
124 * Determines whether the camera manager has been successfully
125 * initialized with camera configurations.
126 *
127 * @return True if initialized, false otherwise
128 */
129 bool isInitialized() const;
130
131 private:
132 /**
133 * @brief Private constructor (singleton pattern)
134 */
135 CameraManager() = default;
136
137 /**
138 * @brief Private destructor (singleton pattern)
139 */
141
142 /**
143 * @brief Deleted copy constructor (singleton pattern)
144 */
145 CameraManager(const CameraManager &) = delete;
146
147 /**
148 * @brief Deleted assignment operator (singleton pattern)
149 */
150 CameraManager &operator=(const CameraManager &) = delete;
151
152 /**
153 * @brief Create and connect a specific type of camera
154 *
155 * Template method that creates and connects a camera of the specified
156 * type. This allows for extensibility to support different camera
157 * implementations while maintaining a consistent interface.
158 *
159 * @tparam CameraType The type of camera to create (MonoCamera, StereoCamera, etc.)
160 * @param config Camera configuration
161 * @return True if camera was successfully created and connected, false otherwise
162 */
163 template <typename CameraType>
164 bool createAndConnectCamera(const cam_info &config);
165
166 // ============================================================================
167 // PRIVATE MEMBER VARIABLES
168 // ============================================================================
169
170 /** @brief Collection of camera instances by ID */
171 std::unordered_map<size_t, std::shared_ptr<CameraBase>> cameras_;
172
173 /**
174 * @brief Mutex for thread-safe operations
175 *
176 * Mutable to allow locking in const methods
177 */
178 mutable std::mutex mutex_;
179
180 /** @brief Flag indicating if the manager has been initialized */
181 bool initialized_{false};
182 };
183
184} // namespace voxl
Base class for camera implementations in VOXL OpenVINS.
Camera queue fusion system for VOXL OpenVINS.
Monocular camera implementation for VOXL OpenVINS.
Stereo camera implementation for VOXL OpenVINS.
Manages all camera instances in the system.
std::shared_ptr< CameraBase > getCamera(size_t camera_id)
Get a camera by its ID.
void shutdown()
Shut down all cameras and clean up resources.
size_t getCameraCount() const
Get the number of cameras.
bool isInitialized() const
Check if the camera manager is initialized.
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:198