added some extra logging
This commit is contained in:
@@ -138,6 +138,7 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
std::vector<size_t> queryRange(const Vec2& center, float radius) const {
|
std::vector<size_t> queryRange(const Vec2& center, float radius) const {
|
||||||
|
TIME_FUNCTION;
|
||||||
std::vector<size_t> results;
|
std::vector<size_t> results;
|
||||||
float radiusSq = radius * radius;
|
float radiusSq = radius * radius;
|
||||||
|
|
||||||
@@ -198,6 +199,7 @@ public:
|
|||||||
|
|
||||||
//get id from position (optional radius, picks first found. radius of 0 becomes epsilon if none are found)
|
//get id from position (optional radius, picks first found. radius of 0 becomes epsilon if none are found)
|
||||||
size_t getPositionVec(const Vec2& pos, float radius = 0.0f) {
|
size_t getPositionVec(const Vec2& pos, float radius = 0.0f) {
|
||||||
|
TIME_FUNCTION;
|
||||||
if (radius == 0.0f) {
|
if (radius == 0.0f) {
|
||||||
// Exact match - use spatial grid to find the cell
|
// Exact match - use spatial grid to find the cell
|
||||||
Vec2 gridPos = spatialGrid.worldToGrid(pos);
|
Vec2 gridPos = spatialGrid.worldToGrid(pos);
|
||||||
|
|||||||
@@ -114,6 +114,7 @@ private:
|
|||||||
|
|
||||||
// Helper function to convert frame to RGB format
|
// Helper function to convert frame to RGB format
|
||||||
static std::vector<uint8_t> frameToRGB(const frame& frm) {
|
static std::vector<uint8_t> frameToRGB(const frame& frm) {
|
||||||
|
TIME_FUNCTION;
|
||||||
if (frm.empty()) {
|
if (frm.empty()) {
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
@@ -179,9 +180,8 @@ private:
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
// New method for video objects
|
// New method for video objects
|
||||||
static bool saveAVI(const std::string& filename,
|
static bool saveAVI(const std::string& filename,const video& vid,float fps = 0.0f) {
|
||||||
const video& vid,
|
TIME_FUNCTION;
|
||||||
float fps = 0.0f) {
|
|
||||||
if (vid.empty()) {
|
if (vid.empty()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -204,6 +204,7 @@ public:
|
|||||||
static bool saveAVI(const std::string& filename,
|
static bool saveAVI(const std::string& filename,
|
||||||
const std::vector<std::vector<uint8_t>>& frames,
|
const std::vector<std::vector<uint8_t>>& frames,
|
||||||
int width, int height, float fps = 30.0f) {
|
int width, int height, float fps = 30.0f) {
|
||||||
|
TIME_FUNCTION;
|
||||||
if (frames.empty() || width <= 0 || height <= 0 || fps <= 0) {
|
if (frames.empty() || width <= 0 || height <= 0 || fps <= 0) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -382,6 +383,7 @@ public:
|
|||||||
static bool saveAVI(const std::string& filename,
|
static bool saveAVI(const std::string& filename,
|
||||||
const std::vector<frame>& frames,
|
const std::vector<frame>& frames,
|
||||||
float fps = 30.0f) {
|
float fps = 30.0f) {
|
||||||
|
TIME_FUNCTION;
|
||||||
if (frames.empty() || fps <= 0) {
|
if (frames.empty() || fps <= 0) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -414,6 +416,7 @@ public:
|
|||||||
const std::vector<std::string>& frameFiles,
|
const std::vector<std::string>& frameFiles,
|
||||||
int width, int height,
|
int width, int height,
|
||||||
float fps = 30.0f) {
|
float fps = 30.0f) {
|
||||||
|
TIME_FUNCTION;
|
||||||
std::vector<std::vector<uint8_t>> frames;
|
std::vector<std::vector<uint8_t>> frames;
|
||||||
frames.reserve(frameFiles.size());
|
frames.reserve(frameFiles.size());
|
||||||
|
|
||||||
|
|||||||
@@ -8,6 +8,7 @@
|
|||||||
#include <memory>
|
#include <memory>
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
#include "../timing_decorator.hpp"
|
||||||
|
|
||||||
class video {
|
class video {
|
||||||
private:
|
private:
|
||||||
@@ -21,6 +22,7 @@ private:
|
|||||||
// Compress frame using differential encoding
|
// Compress frame using differential encoding
|
||||||
std::vector<std::pair<uint8_t, uint32_t>> compress_with_differential(
|
std::vector<std::pair<uint8_t, uint32_t>> compress_with_differential(
|
||||||
const frame& current_frame, const frame* previous_frame = nullptr) const {
|
const frame& current_frame, const frame* previous_frame = nullptr) const {
|
||||||
|
TIME_FUNCTION;
|
||||||
|
|
||||||
if (previous_frame == nullptr) {
|
if (previous_frame == nullptr) {
|
||||||
// First frame - compress normally
|
// First frame - compress normally
|
||||||
@@ -49,6 +51,7 @@ private:
|
|||||||
// Decompress differential frame
|
// Decompress differential frame
|
||||||
frame decompress_differential(const std::vector<std::pair<uint8_t, uint32_t>>& compressed_diff,
|
frame decompress_differential(const std::vector<std::pair<uint8_t, uint32_t>>& compressed_diff,
|
||||||
const frame& previous_frame) const {
|
const frame& previous_frame) const {
|
||||||
|
TIME_FUNCTION;
|
||||||
|
|
||||||
frame diff_frame;
|
frame diff_frame;
|
||||||
diff_frame.decompress_rle(compressed_diff);
|
diff_frame.decompress_rle(compressed_diff);
|
||||||
@@ -108,6 +111,7 @@ public:
|
|||||||
|
|
||||||
// Add a frame to the video sequence
|
// Add a frame to the video sequence
|
||||||
void add_frame(const frame& new_frame) {
|
void add_frame(const frame& new_frame) {
|
||||||
|
TIME_FUNCTION;
|
||||||
// Validate frame dimensions and channels
|
// Validate frame dimensions and channels
|
||||||
if (new_frame.width() != width_ || new_frame.height() != height_) {
|
if (new_frame.width() != width_ || new_frame.height() != height_) {
|
||||||
throw std::invalid_argument("Frame dimensions must match video dimensions");
|
throw std::invalid_argument("Frame dimensions must match video dimensions");
|
||||||
@@ -133,6 +137,7 @@ public:
|
|||||||
|
|
||||||
// Get a specific frame
|
// Get a specific frame
|
||||||
frame get_frame(size_t index) const {
|
frame get_frame(size_t index) const {
|
||||||
|
TIME_FUNCTION;
|
||||||
if (index >= compressed_frames_.size()) {
|
if (index >= compressed_frames_.size()) {
|
||||||
throw std::out_of_range("Frame index out of range");
|
throw std::out_of_range("Frame index out of range");
|
||||||
}
|
}
|
||||||
@@ -154,6 +159,7 @@ public:
|
|||||||
|
|
||||||
// Get multiple frames as a sequence
|
// Get multiple frames as a sequence
|
||||||
std::vector<frame> get_frames(size_t start_index, size_t count) const {
|
std::vector<frame> get_frames(size_t start_index, size_t count) const {
|
||||||
|
TIME_FUNCTION;
|
||||||
if (start_index >= compressed_frames_.size()) {
|
if (start_index >= compressed_frames_.size()) {
|
||||||
throw std::out_of_range("Start index out of range");
|
throw std::out_of_range("Start index out of range");
|
||||||
}
|
}
|
||||||
@@ -189,6 +195,7 @@ public:
|
|||||||
|
|
||||||
// Replace a frame
|
// Replace a frame
|
||||||
void replace_frame(size_t index, const frame& new_frame) {
|
void replace_frame(size_t index, const frame& new_frame) {
|
||||||
|
TIME_FUNCTION;
|
||||||
if (index >= compressed_frames_.size()) {
|
if (index >= compressed_frames_.size()) {
|
||||||
throw std::out_of_range("Frame index out of range");
|
throw std::out_of_range("Frame index out of range");
|
||||||
}
|
}
|
||||||
@@ -226,6 +233,7 @@ public:
|
|||||||
|
|
||||||
// Enable/disable differential encoding
|
// Enable/disable differential encoding
|
||||||
void set_differential_encoding(bool enabled) {
|
void set_differential_encoding(bool enabled) {
|
||||||
|
TIME_FUNCTION;
|
||||||
if (use_differential_encoding_ == enabled) {
|
if (use_differential_encoding_ == enabled) {
|
||||||
return; // No change needed
|
return; // No change needed
|
||||||
}
|
}
|
||||||
@@ -246,11 +254,13 @@ public:
|
|||||||
|
|
||||||
// Get video duration in seconds
|
// Get video duration in seconds
|
||||||
double duration() const noexcept {
|
double duration() const noexcept {
|
||||||
|
TIME_FUNCTION;
|
||||||
return compressed_frames_.size() / fps_;
|
return compressed_frames_.size() / fps_;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Calculate total compressed size in bytes
|
// Calculate total compressed size in bytes
|
||||||
size_t total_compressed_size() const noexcept {
|
size_t total_compressed_size() const noexcept {
|
||||||
|
TIME_FUNCTION;
|
||||||
size_t total = 0;
|
size_t total = 0;
|
||||||
for (const auto& compressed_frame : compressed_frames_) {
|
for (const auto& compressed_frame : compressed_frames_) {
|
||||||
total += compressed_frame.size() * sizeof(std::pair<uint8_t, uint32_t>);
|
total += compressed_frame.size() * sizeof(std::pair<uint8_t, uint32_t>);
|
||||||
@@ -260,11 +270,13 @@ public:
|
|||||||
|
|
||||||
// Calculate total uncompressed size in bytes
|
// Calculate total uncompressed size in bytes
|
||||||
size_t total_uncompressed_size() const noexcept {
|
size_t total_uncompressed_size() const noexcept {
|
||||||
|
TIME_FUNCTION;
|
||||||
return compressed_frames_.size() * width_ * height_ * channels_.size();
|
return compressed_frames_.size() * width_ * height_ * channels_.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Calculate overall compression ratio
|
// Calculate overall compression ratio
|
||||||
double overall_compression_ratio() const noexcept {
|
double overall_compression_ratio() const noexcept {
|
||||||
|
TIME_FUNCTION;
|
||||||
if (empty()) {
|
if (empty()) {
|
||||||
return 1.0;
|
return 1.0;
|
||||||
}
|
}
|
||||||
@@ -277,6 +289,7 @@ public:
|
|||||||
|
|
||||||
// Calculate average frame compression ratio
|
// Calculate average frame compression ratio
|
||||||
double average_frame_compression_ratio() const {
|
double average_frame_compression_ratio() const {
|
||||||
|
TIME_FUNCTION;
|
||||||
if (empty()) {
|
if (empty()) {
|
||||||
return 1.0;
|
return 1.0;
|
||||||
}
|
}
|
||||||
@@ -292,6 +305,7 @@ public:
|
|||||||
|
|
||||||
// Get compression statistics
|
// Get compression statistics
|
||||||
struct compression_stats {
|
struct compression_stats {
|
||||||
|
TIME_FUNCTION;
|
||||||
size_t total_frames;
|
size_t total_frames;
|
||||||
size_t total_compressed_bytes;
|
size_t total_compressed_bytes;
|
||||||
size_t total_uncompressed_bytes;
|
size_t total_uncompressed_bytes;
|
||||||
@@ -301,6 +315,7 @@ public:
|
|||||||
};
|
};
|
||||||
|
|
||||||
compression_stats get_compression_stats() const {
|
compression_stats get_compression_stats() const {
|
||||||
|
TIME_FUNCTION;
|
||||||
compression_stats stats;
|
compression_stats stats;
|
||||||
stats.total_frames = compressed_frames_.size();
|
stats.total_frames = compressed_frames_.size();
|
||||||
stats.total_compressed_bytes = total_compressed_size();
|
stats.total_compressed_bytes = total_compressed_size();
|
||||||
@@ -313,6 +328,7 @@ public:
|
|||||||
|
|
||||||
// Extract a sub-video
|
// Extract a sub-video
|
||||||
video subvideo(size_t start_frame, size_t frame_count) const {
|
video subvideo(size_t start_frame, size_t frame_count) const {
|
||||||
|
TIME_FUNCTION;
|
||||||
if (start_frame >= compressed_frames_.size()) {
|
if (start_frame >= compressed_frames_.size()) {
|
||||||
throw std::out_of_range("Start frame out of range");
|
throw std::out_of_range("Start frame out of range");
|
||||||
}
|
}
|
||||||
@@ -329,6 +345,7 @@ public:
|
|||||||
|
|
||||||
// Append another video (must have same dimensions and channels)
|
// Append another video (must have same dimensions and channels)
|
||||||
void append_video(const video& other) {
|
void append_video(const video& other) {
|
||||||
|
TIME_FUNCTION;
|
||||||
if (other.width_ != width_ || other.height_ != height_ || other.channels_ != channels_) {
|
if (other.width_ != width_ || other.height_ != height_ || other.channels_ != channels_) {
|
||||||
throw std::invalid_argument("Videos must have same dimensions and channels");
|
throw std::invalid_argument("Videos must have same dimensions and channels");
|
||||||
}
|
}
|
||||||
@@ -349,6 +366,7 @@ public:
|
|||||||
|
|
||||||
// Save/Load functionality (basic serialization)
|
// Save/Load functionality (basic serialization)
|
||||||
std::vector<uint8_t> serialize() const {
|
std::vector<uint8_t> serialize() const {
|
||||||
|
TIME_FUNCTION;
|
||||||
// Simple serialization format:
|
// Simple serialization format:
|
||||||
// [header][compressed_frame_data...]
|
// [header][compressed_frame_data...]
|
||||||
// Header: width(4), height(4), channels_count(1), channels_data(n), fps(8), frame_count(4)
|
// Header: width(4), height(4), channels_count(1), channels_data(n), fps(8), frame_count(4)
|
||||||
@@ -394,6 +412,7 @@ public:
|
|||||||
|
|
||||||
// Deserialize from byte data
|
// Deserialize from byte data
|
||||||
static video deserialize(const std::vector<uint8_t>& data) {
|
static video deserialize(const std::vector<uint8_t>& data) {
|
||||||
|
TIME_FUNCTION;
|
||||||
if (data.size() < 4 + 4 + 1 + 8 + 1 + 4) { // Minimum header size
|
if (data.size() < 4 + 4 + 1 + 8 + 1 + 4) { // Minimum header size
|
||||||
throw std::invalid_argument("Invalid video data: too short");
|
throw std::invalid_argument("Invalid video data: too short");
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user