diff --git a/src/Board.cpp b/src/Board.cpp index d69598c6..9d44c474 100755 --- a/src/Board.cpp +++ b/src/Board.cpp @@ -8,15 +8,13 @@ #include "Frame.hpp" #include "logger.h" -Board::Board() {} - /** - * @brief Initialize parameters of the board + * @brief Initialize Board object * * @param config_path path to the configuration file * @param board_idx index of the board */ -void Board::initParams(const std::string config_path, const int board_idx) { +Board::Board(const std::string config_path, const int board_idx) { std::vector number_x_square_per_board, number_y_square_per_board; std::vector square_size_per_board; std::vector boards_index; diff --git a/src/Board.hpp b/src/Board.hpp old mode 100755 new mode 100644 index 57276499..ce00ec7f --- a/src/Board.hpp +++ b/src/Board.hpp @@ -19,7 +19,7 @@ class Frame; * - frames where these 3D boards are observed */ -class Board { +class Board final { public: // Parameters int nb_x_square_, nb_y_square_, res_x_, res_y_; @@ -43,9 +43,9 @@ class Board { cv::Ptr charuco_board_; // vector of charuco boards // Functions - Board(); + Board() = delete; ~Board(){}; - void initParams(const std::string config, const int board_idx); + Board(const std::string config, const int board_idx); void insertNewBoard(std::shared_ptr new_board); void insertNewFrame(std::shared_ptr new_frame); }; diff --git a/src/BoardObs.cpp b/src/BoardObs.cpp index 7172c82c..f138a6a1 100644 --- a/src/BoardObs.cpp +++ b/src/BoardObs.cpp @@ -9,10 +9,8 @@ #include "geometrytools.hpp" #include "logger.h" -BoardObs::BoardObs() {} - /** - * @brief Initialize the board observation + * @brief Initialize the board observation object * * @param camera_id camera index of the camera observing the board * @param frame_id frame in which the board is visible @@ -22,19 +20,13 @@ BoardObs::BoardObs() {} * @param cam camera observing the board * @param board_3d 3D board corresponding to the observation */ -void BoardObs::init(const int camera_id, const int frame_id, const int board_id, - const std::vector pts_2d, - const std::vector charuco_id, - std::shared_ptr cam, - std::shared_ptr board_3d) { - frame_id_ = frame_id; - camera_id_ = camera_id; - board_id_ = board_id; - pts_2d_ = pts_2d; - charuco_id_ = charuco_id; - cam_ = cam; - board_3d_ = board_3d; -} +BoardObs::BoardObs(const int camera_id, const int frame_id, const int board_id, + const std::vector pts_2d, + const std::vector charuco_id, + std::shared_ptr cam, std::shared_ptr board_3d) + : frame_id_(frame_id), camera_id_(camera_id), board_id_(board_id), + pts_2d_(pts_2d), charuco_id_(charuco_id), cam_(cam), + board_3d_(board_3d){}; /** * @brief Get pose vector of the observed board diff --git a/src/BoardObs.hpp b/src/BoardObs.hpp index 47709d27..71002961 100644 --- a/src/BoardObs.hpp +++ b/src/BoardObs.hpp @@ -20,7 +20,7 @@ class Board; * camera observing the board. * */ -class BoardObs { +class BoardObs final { public: // Indexing int frame_id_; @@ -45,12 +45,12 @@ class BoardObs { bool valid_ = true; // Functions - BoardObs(); + BoardObs() = delete; ~BoardObs() { delete[] pose_; }; - void init(const int camera_id, const int frame_id, const int board_id, - const std::vector pts_2d, - const std::vector charuco_id, std::shared_ptr cam, - std::shared_ptr board_3d); + BoardObs(const int camera_id, const int frame_id, const int board_id, + const std::vector pts_2d, + const std::vector charuco_id, std::shared_ptr cam, + std::shared_ptr board_3d); void getPoseVec(cv::Mat &R, cv::Mat &T) const; cv::Mat getPoseMat() const; void setPoseMat(const cv::Mat Pose); diff --git a/src/Calibration.cpp b/src/Calibration.cpp index 46108b56..f772a9c4 100644 --- a/src/Calibration.cpp +++ b/src/Calibration.cpp @@ -9,14 +9,12 @@ #include "logger.h" #include "point_refinement.h" -Calibration::Calibration() {} - /** * @brief Initialize the number of cameras and the 3D Boards * * @param config_path path to the configuration file */ -void Calibration::initialization(const std::string config_path) { +Calibration::Calibration(const std::string config_path) { cv::FileStorage fs; // cv::FileStorage to read calibration params from file int distortion_model; std::vector distortion_per_camera; @@ -87,9 +85,8 @@ void Calibration::initialization(const std::string config_path) { // Initialize Cameras for (int i = 0; i < nb_camera_; i++) { - std::shared_ptr new_cam = std::make_shared(); - new_cam->cam_idx_ = i; - new_cam->distortion_model_ = distortion_per_camera[i]; + std::shared_ptr new_cam = + std::make_shared(i, distortion_per_camera[i]); cams_[i] = new_cam; } @@ -117,9 +114,8 @@ void Calibration::initialization(const std::string config_path) { // Initialize the 3D boards for (int i = 0; i < nb_board_; i++) { // Initialize board - std::shared_ptr new_board = std::make_shared(); + std::shared_ptr new_board = std::make_shared(config_path, i); boards_3d_[i] = new_board; - boards_3d_[i]->initParams(config_path, i); LOG_DEBUG << "Here1"; // Prepare the 3D pts of the boards for (int y = 0; y < boards_3d_[i]->nb_y_square_ - 1; y++) { @@ -435,9 +431,9 @@ void Calibration::insertNewBoard(const int cam_idx, const int frame_idx, const std::vector pts_2d, const std::vector charuco_idx, const std::string frame_path) { - std::shared_ptr new_board = std::make_shared(); - new_board->init(cam_idx, frame_idx, board_idx, pts_2d, charuco_idx, - cams_[cam_idx], boards_3d_[board_idx]); + std::shared_ptr new_board = std::make_shared( + cam_idx, frame_idx, board_idx, pts_2d, charuco_idx, cams_[cam_idx], + boards_3d_[board_idx]); // Add new board in the board list board_observations_[board_observations_.size()] = new_board; @@ -457,9 +453,7 @@ void Calibration::insertNewBoard(const int cam_idx, const int frame_idx, frames_[frame_idx]->frame_path_[cam_idx] = frame_path; } else { std::shared_ptr newFrame = - std::make_shared(); // declare new frame in heap - newFrame->frame_idx_ = frame_idx; - newFrame->frame_path_[cam_idx] = frame_path; + std::make_shared(frame_idx, cam_idx, frame_path); frames_[frame_idx] = newFrame; // Initialize the Frame if key does not exist frames_[frame_idx]->insertNewBoard(new_board); cams_[cam_idx]->insertNewFrame(newFrame); @@ -475,10 +469,9 @@ void Calibration::insertNewBoard(const int cam_idx, const int frame_idx, // insert in list cams_obs_[cam_frame_idx]->insertNewBoard(new_board); } else { - std::shared_ptr new_cam_obs = std::make_shared(); - ; + std::shared_ptr new_cam_obs = + std::make_shared(new_board); cams_obs_[cam_frame_idx] = new_cam_obs; - cams_obs_[cam_frame_idx]->insertNewBoard(new_board); // add the observation frames_[frame_idx]->insertNewCamObs(new_cam_obs); } } @@ -731,9 +724,8 @@ void Calibration::init3DObjects() { // Declare a new 3D object std::shared_ptr newObject3D = - std::make_shared(); // declare new object 3D in heap - newObject3D->initializeObject3D(connect_comp[i].size(), ref_board_id, i, - boards_3d_[ref_board_id]->color_); + std::make_shared(connect_comp[i].size(), ref_board_id, i, + boards_3d_[ref_board_id]->color_); int pts_count = 0; // Compute the shortest path between the reference and the other board @@ -804,8 +796,8 @@ void Calibration::init3DObjectObs(const int object_idx) { // Declare the 3D object observed in this camera observation // Keep in mind that a single object can be observed in one image - std::shared_ptr object_obs = std::make_shared(); - object_obs->initializeObject(object_3d_[object_idx], object_idx); + std::shared_ptr object_obs = + std::make_shared(object_3d_[object_idx], object_idx); // Check the boards observing this camera std::map> current_board_obs = @@ -1048,8 +1040,7 @@ void Calibration::initCameraGroup() { // Declare a new camera group std::shared_ptr new_camera_group = - std::make_shared(); - new_camera_group->initializeCameraGroup(id_ref_cam, i); + std::make_shared(id_ref_cam, i); // Compute the shortest path between the reference and the other cams for (int j = 0; j < connect_comp[i].size(); j++) { @@ -1096,8 +1087,8 @@ void Calibration::initCameraGroupObs(const int camera_group_idx) { it_frame != frames_.end(); ++it_frame) { int current_frame_id = it_frame->second->frame_idx_; std::shared_ptr new_cam_group_obs = - std::make_shared(); // declare a new observation - new_cam_group_obs->insertCameraGroup(cam_group_[camera_group_idx]); + std::make_shared( + cam_group_[camera_group_idx]); // declare a new observation std::map> current_object_obs = it_frame->second->object_observations_; @@ -1563,8 +1554,7 @@ void Calibration::mergeCameraGroup() { // initialize the camera group std::shared_ptr new_camera_group = - std::make_shared(); - new_camera_group->initializeCameraGroup(id_ref_cam, i); + std::make_shared(id_ref_cam, i); // Iterate through the camera groups and add all the cameras individually in // the new group for (std::map>::iterator it_group = @@ -1829,10 +1819,8 @@ void Calibration::mergeObjects() { object_pose_to_ref[current_object_id] = transform; } // initialize the object - std::shared_ptr newObject3D = - std::make_shared(); // declare new object 3D in heap - newObject3D->initializeObject3D(nb_board_in_obj, ref_board_id, i, - boards_3d_[ref_board_id]->color_); + std::shared_ptr newObject3D = std::make_shared( + nb_board_in_obj, ref_board_id, i, boards_3d_[ref_board_id]->color_); int pts_count = 0; // Iterate through the objects and add all of them individually in the new // object diff --git a/src/Calibration.hpp b/src/Calibration.hpp index ddc9382d..f48271ac 100644 --- a/src/Calibration.hpp +++ b/src/Calibration.hpp @@ -28,7 +28,7 @@ * * Centralization of all the data to perform the calibration. */ -class Calibration { +class Calibration final { public: // Parameters int nb_camera_, nb_board_; @@ -133,9 +133,9 @@ class Calibration { void merge3DObjects(); // Functions - Calibration(); + Calibration() = delete; ~Calibration(){}; - void initialization( + Calibration( const std::string config_path); // initialize the charuco pattern, nb // of cameras, nb of boards etc. void boardExtraction(); diff --git a/src/Camera.cpp b/src/Camera.cpp index b9fcae17..1692eadb 100644 --- a/src/Camera.cpp +++ b/src/Camera.cpp @@ -8,7 +8,8 @@ #include "OptimizationCeres.h" #include "logger.h" -Camera::Camera() {} +Camera::Camera(const int cam_idx, const int distortion_model) + : cam_idx_(cam_idx), distortion_model_(distortion_model){}; /** * @brief Get camera matrix (K) diff --git a/src/Camera.hpp b/src/Camera.hpp old mode 100755 new mode 100644 index 08d03894..a06b9f0c --- a/src/Camera.hpp +++ b/src/Camera.hpp @@ -21,7 +21,7 @@ * - boards observation * - object observation */ -class Camera { +class Camera final { public: // datastructure for this camera std::map> @@ -44,7 +44,8 @@ class Camera { int cam_idx_; // Functions - Camera(); + Camera() = delete; + Camera(const int cam_idx, const int distortion_model); ~Camera() { delete[] intrinsics_; }; void insertNewBoard(std::shared_ptr newBoard); void insertNewFrame(std::shared_ptr newFrame); diff --git a/src/CameraGroup.cpp b/src/CameraGroup.cpp index a89c66b4..be021475 100644 --- a/src/CameraGroup.cpp +++ b/src/CameraGroup.cpp @@ -9,21 +9,16 @@ #include "CameraGroup.hpp" #include "logger.h" -CameraGroup::CameraGroup() {} - /** - * @brief Initialize the camera group + * @brief Initialize the camera group object * * Set the index of the reference camera and the index of the camera group. * * @param id_ref_cam index of the reference camera * @param cam_group_idx index of the camera group */ -void CameraGroup::initializeCameraGroup(const int id_ref_cam, - const int cam_group_idx) { - id_ref_cam_ = id_ref_cam; - cam_group_idx_ = cam_group_idx; -} +CameraGroup::CameraGroup(const int id_ref_cam, const int cam_group_idx) + : id_ref_cam_(id_ref_cam), cam_group_idx_(cam_group_idx){}; /** * @brief Insert a new camera in the group diff --git a/src/CameraGroup.hpp b/src/CameraGroup.hpp old mode 100755 new mode 100644 index cb09e962..57ebd773 --- a/src/CameraGroup.hpp +++ b/src/CameraGroup.hpp @@ -23,7 +23,7 @@ * - object observation * - reference camera in the group */ -class CameraGroup { +class CameraGroup final { public: // datastructure for this camera group std::map> @@ -44,9 +44,9 @@ class CameraGroup { int cam_group_idx_; // Functions - CameraGroup(); + CameraGroup() = delete; ~CameraGroup(); - void initializeCameraGroup(const int id_ref_cam, const int cam_group_idx); + CameraGroup(const int id_ref_cam, const int cam_group_idx); void insertCamera(std::shared_ptr new_camera); void insertNewObjectObservation( std::shared_ptr new_object_observation); diff --git a/src/CameraGroupObs.cpp b/src/CameraGroupObs.cpp index 8e1fd92e..d80e1e29 100644 --- a/src/CameraGroupObs.cpp +++ b/src/CameraGroupObs.cpp @@ -8,15 +8,12 @@ #include "CameraGroupObs.hpp" -CameraGroupObs::CameraGroupObs() {} - /** * @brief Associate this observation with its respective camera group * * @param new_cam_group camera group to be added */ -void CameraGroupObs::insertCameraGroup( - std::shared_ptr new_cam_group) { +CameraGroupObs::CameraGroupObs(std::shared_ptr new_cam_group) { cam_group_ = new_cam_group; cam_group_idx_ = new_cam_group->cam_group_idx_; } diff --git a/src/CameraGroupObs.hpp b/src/CameraGroupObs.hpp old mode 100755 new mode 100644 index 5c1876a5..28cd7035 --- a/src/CameraGroupObs.hpp +++ b/src/CameraGroupObs.hpp @@ -18,7 +18,7 @@ class CameraGroup; * - 3D object observations from this camera group observation * - camera group corresponding to this observation */ -class CameraGroupObs { +class CameraGroupObs final { public: // Objects std::vector object_idx_; // index of the visible 3d objects @@ -32,9 +32,9 @@ class CameraGroupObs { std::weak_ptr cam_group_; // Functions - CameraGroupObs(); + CameraGroupObs() = delete; ~CameraGroupObs(); - void insertCameraGroup(std::shared_ptr new_cam_group); + CameraGroupObs(std::shared_ptr new_cam_group); void insertObjectObservation(std::shared_ptr new_object_observation); void computeObjectsPose(); diff --git a/src/CameraObs.cpp b/src/CameraObs.cpp index cdc12e97..602837de 100755 --- a/src/CameraObs.cpp +++ b/src/CameraObs.cpp @@ -6,7 +6,9 @@ #include "CameraObs.hpp" -CameraObs::CameraObs() {} +CameraObs::CameraObs(std::shared_ptr new_board) { + insertNewBoard(new_board); +} /** * @brief Insert new board observation in the camera observation diff --git a/src/CameraObs.hpp b/src/CameraObs.hpp old mode 100755 new mode 100644 index acaa7aef..41796d76 --- a/src/CameraObs.hpp +++ b/src/CameraObs.hpp @@ -17,7 +17,7 @@ class Camera; * * A camera observation contains all the board/object observed by the camera */ -class CameraObs { +class CameraObs final { public: // Boards std::vector board_idx_; // index of the visible 3D boards @@ -31,8 +31,9 @@ class CameraObs { object_observations_; // Objects stored // Functions - CameraObs(); + CameraObs() = delete; ~CameraObs(){}; + CameraObs(std::shared_ptr new_board); void insertNewBoard(std::shared_ptr new_board); void insertNewObject(std::shared_ptr new_object); }; diff --git a/src/Frame.cpp b/src/Frame.cpp index c77353bc..98ad0e48 100644 --- a/src/Frame.cpp +++ b/src/Frame.cpp @@ -6,7 +6,11 @@ #include "Frame.hpp" -Frame::Frame() {} +Frame::Frame(const int frame_idx, const int cam_idx, + const std::string frame_path) { + frame_idx_ = frame_idx; + frame_path_[cam_idx] = frame_path; +} /** * @brief Insert new board observation in this frame diff --git a/src/Frame.hpp b/src/Frame.hpp old mode 100755 new mode 100644 index 278206a1..8ae282c9 --- a/src/Frame.hpp +++ b/src/Frame.hpp @@ -19,7 +19,7 @@ * A frame is all the observation from all the synchronized cameras at a given * time. */ -class Frame { +class Frame final { public: int frame_idx_; @@ -47,8 +47,9 @@ class Frame { std::map frame_path_; // camera_id // path // Functions - Frame(); + Frame() = delete; ~Frame(){}; + Frame(const int frame_idx, const int cam_idx, const std::string frame_path); void insertNewBoard(std::shared_ptr newBoard); void insertNewCamObs(std::shared_ptr newCamObs); void insertNewObject(std::shared_ptr new_object); diff --git a/src/Graph.hpp b/src/Graph.hpp old mode 100755 new mode 100644 index 1dafaf63..68339176 --- a/src/Graph.hpp +++ b/src/Graph.hpp @@ -14,7 +14,7 @@ * Relies on boost. Reference: * https://www.boost.org/doc/libs/1_75_0/libs/graph/example/dijkstra-example.cpp */ -class Graph { +class Graph final { public: // edge weight typedef boost::property EdgeWeightProperty; diff --git a/src/Object3D.cpp b/src/Object3D.cpp index 20856a17..2606ae9b 100644 --- a/src/Object3D.cpp +++ b/src/Object3D.cpp @@ -11,8 +11,6 @@ #include "geometrytools.hpp" #include "logger.h" -Object3D::Object3D() {} - /** * @brief Insert a new object observation for this 3D object * @@ -30,15 +28,10 @@ void Object3D::insertNewObject(std::shared_ptr new_object) { * @param obj_id object id * @param color color of the 3D object */ -void Object3D::initializeObject3D(const int nb_boards, const int ref_board_id, - const int obj_id, - const std::vector color) { - nb_boards_ = nb_boards; - ref_board_id_ = ref_board_id; - obj_id_ = obj_id; - nb_pts_ = 0; - color_ = color; -} +Object3D::Object3D(const int nb_boards, const int ref_board_id, + const int obj_id, const std::vector color) + : nb_boards_(nb_boards), ref_board_id_(ref_board_id), obj_id_(obj_id), + nb_pts_(0), color_(color){}; /** * @brief Insert a new board in the object diff --git a/src/Object3D.hpp b/src/Object3D.hpp index a1ec3c92..830199e8 100644 --- a/src/Object3D.hpp +++ b/src/Object3D.hpp @@ -22,7 +22,7 @@ class Camera; * - observation of these objects * - frames where these 3D objects are observed */ -class Object3D { +class Object3D final { public: // Parameters int nb_boards_; // number of boards constituting the 3D object @@ -52,10 +52,10 @@ class Object3D { std::map> frames_; // Functions - Object3D(); + Object3D() = delete; ~Object3D(); - void initializeObject3D(const int nb_boards, const int ref_board_id, - const int obj_id, const std::vector color); + Object3D(const int nb_boards, const int ref_board_id, const int obj_id, + const std::vector color); void insertBoardInObject(std::shared_ptr new_board); void insertNewObject(std::shared_ptr new_object); void insertNewFrame(std::shared_ptr new_frame); diff --git a/src/Object3DObs.cpp b/src/Object3DObs.cpp index 19899102..ff339ae0 100644 --- a/src/Object3DObs.cpp +++ b/src/Object3DObs.cpp @@ -9,19 +9,15 @@ #include "geometrytools.hpp" #include "logger.h" -Object3DObs::Object3DObs() {} - /** * @brief initialize the object in the observation (what board is observed) * * @param new_obj_obs object to be added * @param object_idx object index */ -void Object3DObs::initializeObject(std::shared_ptr obj_obs, - const int object_idx) { - object_3d_ = obj_obs; - object_3d_id_ = object_idx; -} +Object3DObs::Object3DObs(std::shared_ptr obj_obs, + const int object_idx) + : object_3d_(obj_obs), object_3d_id_(object_idx){}; /** * @brief Insert a new board in the object diff --git a/src/Object3DObs.hpp b/src/Object3DObs.hpp index 5df45dbe..ade394d8 100644 --- a/src/Object3DObs.hpp +++ b/src/Object3DObs.hpp @@ -27,7 +27,7 @@ class Object3D; * - frame index * - object 3D index */ -class Object3DObs { +class Object3DObs final { public: // Indexing int frame_id_; @@ -64,10 +64,9 @@ class Object3DObs { bool valid_ = true; // Functions - Object3DObs(); + Object3DObs() = delete; ~Object3DObs(); - void initializeObject(std::shared_ptr obj_obs, - const int object_idx); + Object3DObs(std::shared_ptr obj_obs, const int object_idx); void insertNewBoardObs(std::shared_ptr new_board_obs); void getPoseVec(cv::Mat &R, cv::Mat &T) const; cv::Mat getPoseMat() const; diff --git a/src/main_calibrate.cpp b/src/main_calibrate.cpp index d98d4699..3e36fed5 100644 --- a/src/main_calibrate.cpp +++ b/src/main_calibrate.cpp @@ -14,8 +14,7 @@ void runCalibrationWorkflow(std::string config_path) { // Instantiate the calibration and initialize the parameters - Calibration Calib; - Calib.initialization(config_path); + Calibration Calib(config_path); Calib.boardExtraction(); LOG_INFO << "Board extraction done!"; diff --git a/tests/test_calibration.cpp b/tests/test_calibration.cpp index dfa9b2ae..6b7fcf8b 100644 --- a/tests/test_calibration.cpp +++ b/tests/test_calibration.cpp @@ -34,8 +34,7 @@ double getRotationError(cv::Mat a, cv::Mat b) { Calibration calibrate(std::string config_path) { // calibrate - Calibration Calib; - Calib.initialization(config_path); + Calibration Calib(config_path); Calib.boardExtraction(); Calib.initIntrinsic(); Calib.calibrate3DObjects();