头文件 calculateBufferSize.h
#ifndef CALCULATE_BUFFER_SIZE
#define CALCULATE_BUFFER_SIZE
#include <mutex>
#include <memory>
#include <iostream>
#include <glm/glm.hpp>
class CalculateBufferSize {
public:
typedef std::shared_ptr<CalculateBufferSize> Ptr;
CalculateBufferSize(){
image_number = 20;
image_width = 1920;
image_height = 1080;
// 计算空间大小bytes,申请内存空间
image_size = image_width * image_height * 3ULL; // 单张彩色图大小
mask_size = image_width * image_height * 1ULL; // 单张mask图大小
mask_dt_size = image_width * image_height * sizeof(float); // 单张mask图大小
all_images_size = image_size * image_number;
all_masks_size = mask_size * image_number;
all_masks_dt_size = mask_dt_size * image_number;
buffer_size = all_images_size + all_masks_size + all_masks_dt_size * 2;
real_KRt44_size = sizeof(glm::mat4);
all_real_KRt44_size = real_KRt44_size * image_number;
real_Rt44_size = sizeof(glm::mat4);
all_real_Rt44_size = real_Rt44_size * image_number;
mp_real_K44_size = sizeof(glm::mat4);
all_mp_real_K44_size = mp_real_K44_size * image_number;
buffer_real_P_size = all_real_KRt44_size + all_real_Rt44_size + all_mp_real_K44_size;
};
~CalculateBufferSize(){};
CalculateBufferSize(CalculateBufferSize &) = delete; // 禁用拷贝构造
CalculateBufferSize& operator=(const CalculateBufferSize &) = delete; // 禁用赋值
static Ptr GetInstance() {
if(m_CalculateBufferSize == nullptr) {
std::lock_guard<std::mutex> lk(m_mutex);
if(m_CalculateBufferSize == nullptr) {
m_CalculateBufferSize = std::shared_ptr<CalculateBufferSize>(new CalculateBufferSize());
}
}
return m_CalculateBufferSize;
}
uint64_t image_number;
uint64_t image_width;
uint64_t image_height;
// 计算空间大小bytes,申请内存空间
uint64_t image_size ; // 单张彩色图大小
uint64_t mask_size; // 单张mask图大小
uint64_t mask_dt_size; // 单张mask图大小
uint64_t all_images_size;
uint64_t all_masks_size ;
uint64_t all_masks_dt_size ;
uint64_t buffer_size ;
uint64_t real_KRt44_size ;
uint64_t all_real_KRt44_size ;
uint64_t real_Rt44_size ;
uint64_t all_real_Rt44_size ;
uint64_t mp_real_K44_size;
uint64_t all_mp_real_K44_size;
uint64_t buffer_real_P_size ;
private:
static Ptr m_CalculateBufferSize;
static std::mutex m_mutex;
};
CalculateBufferSize::Ptr CalculateBufferSize::m_CalculateBufferSize = nullptr;
std::mutex CalculateBufferSize::m_mutex;
#endif
测试 main.cpp
#include <iostream>
#include "calculateBufferSize.h"
using namespace std;
int main(){
std::cout<<"begin"<<std::endl;
CalculateBufferSize::Ptr test = CalculateBufferSize::GetInstance();
std::cout<<"buffer_size:"<<test->buffer_size<<std::endl;
std::cout<<"image_number:"<<test->image_number<<std::endl;
}
cmake
cmake_minimum_required (VERSION 2.8)
project (template)
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/modules/")
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
# find the required packages
find_package(GLM REQUIRED)
message(STATUS "GLM included at ${GLM_INCLUDE_DIR}")
include_directories(${CMAKE_SOURCE_DIR}/include)
set (CMAKE_CXX_LINK_EXECUTABLE "${CMAKE_CXX_LINK_EXECUTABLE} -ldl")
add_executable(testStatic testStatic.cpp)
标签:real,uint64,静态,成员,mask,C++,CalculateBufferSize,image,size
From: https://www.cnblogs.com/xiaohuidi/p/17028610.html