CPPxDIC
C++ Digital Image Correlation library for fingertip 3D reconstruction
Loading...
Searching...
No Matches
Utils Class Reference

Utility functions for CPPXDIC Equivalent to various utility functions in Matlab xDIC. More...

#include <utils.h>

Classes

struct  CameraParameters
 
struct  RigidTransform
 

Static Public Member Functions

static bool dicCheck (const Config &config)
 Utility functions implementation for CPPXDIC.
 
static bool fileExists (const std::string &path)
 
static bool directoryExists (const std::string &path)
 
static std::vector< std::string > findFiles (const std::string &directory, const std::string &pattern)
 
static std::string formatString (const std::string &format,...)
 
static std::vector< std::string > split (const std::string &str, char delimiter)
 
static bool importVid (const Config &config, int trial, int stereopair, std::vector< std::string > &cam1Frames, std::vector< std::string > &cam2Frames, int maxFrames=0)
 
static bool importRawVid (const Config &config, int trial, int stereopair, int frameStart, int frameEnd, int frameJump, std::vector< std::string > &cam1Frames, std::vector< std::string > &cam2Frames, int maxFrames=0)
 
static bool loadROIFromMat (const Config &config, int trial, int stereopair, std::string &roiJsonPath, std::string &roiMaskImagePath)
 
static bool loadSeedFromMat (const Config &config, int trial, int stereopair, std::string &seedJsonPath)
 
static bool loadCameraParameters (const std::string &mat_path, CameraParameters &params)
 Load camera calibration parameters from MATLAB .mat file Matches MATLAB: load('cameraCBparameters_cam_X.mat') Expects structure 'cameraCBparameters' with field 'cameraParameters'.
 
static void undistortPoints (const std::vector< cv::Point2d > &points_in, const CameraParameters &params, std::vector< cv::Point2d > &points_out)
 Undistort 2D points using camera parameters Matches MATLAB: undistortPoints(points, cameraParameters)
 
static cv::Point2d undistortPoint (const cv::Point2d &point_in, const CameraParameters &params)
 Undistort single 2D point.
 
static bool DLT11Calibration (const double *P2, const double *P3, size_t N, std::vector< double > &L)
 Compute DLT (Direct Linear Transformation) 11 parameters from 2D-3D point correspondences Matches MATLAB: L = DLT11Calibration(P2, P3) Solves the 2Nx11 least squares system M \ P2array for 11 DLT parameters.
 
static bool computeRigidTransform (const std::vector< Eigen::Vector3d > &points_from, const std::vector< Eigen::Vector3d > &points_to, RigidTransform &transform)
 Compute optimal rigid body transformation between two point clouds Matches MATLAB: rigidTransformation(Pfrom, Pto) Uses SVD-based least squares minimization.
 
static std::vector< Eigen::Vector3d > applyRigidTransform (const std::vector< Eigen::Vector3d > &points_in, const RigidTransform &transform)
 Apply rigid transformation to point cloud points_out = R * points_in + t.
 
static void setCameraPairs (const std::vector< std::pair< int, int > > &camera_pairs)
 Register the process-wide stereopair -> (cam_first, cam_second) table.
 
static const std::vector< std::pair< int, int > > & cameraPairs ()
 Currently registered stereopair table (see setCameraPairs).
 
static void getCamerasForPair (int stereopair, int &cam_first, int &cam_second)
 Get camera numbers for a given stereopair using the registered table (setCameraPairs).
 
static void getCamerasForPair (int stereopair, const std::vector< std::pair< int, int > > &camera_pairs, int &cam_first, int &cam_second)
 Get camera numbers for a given stereopair using config camera_pairs mapping.
 
static std::string buildBaseDataPath (const Config &config, bool with_data_or_dic_path=false, bool with_rawdata=false, bool with_speckles=false)
 Build base data path.
 
static std::string buildOutputUntilTrialDir (const Config &config, int trial)
 Build output dir until Trial folder.
 
static std::string buildOutputUntilPhaseDir (const Config &config, int trial)
 Build output dir until the Phase folder.
 
static std::string buildPath (const Config &config, bool with_data_or_dic_path=false, bool with_rawdata=false, bool with_speckles=false, bool with_material=false, bool with_video=false, bool with_protocol=false, bool with_calib=false)
 Build the path based on activated parameters and return the proper string.
 
static std::string buildUntilMaterialDir (const Config &config, bool with_data_or_dic_path, bool with_rawdata, bool with_speckles)
 Build path until material folder.
 
static std::string buildOutputUntilMaterialDir (const Config &config)
 Build output path until material folder.
 
static std::string buildProtocolDir (const Config &config, bool with_data_or_dic_path=false, bool with_rawdata=false, bool with_speckles=false, bool with_material=false)
 Build protocol path.
 
static std::string buildVideoDir (const Config &config, bool with_data_or_dic_path=false, bool with_rawdata=false, bool with_speckles=false, bool with_material=false)
 Build the video path.
 
static std::string buildCalibDir (const Config &config)
 Build the calib path.
 
static std::string buildPath (const cppxdic::BaseParameters &parameters, bool with_material=false, bool with_trial=false, bool with_phase=false, bool with_cache=false)
 Build the path based on activated parameters and return the proper string.
 
static std::string buildOutputPath (const cppxdic::BaseParameters &parameters)
 Build the output path.
 
static std::string buildOutputCachePath (const cppxdic::BaseParameters &parameters)
 Build the output cache path.
 
static std::string likeRoiOrSeedPath (const std::string &path, const std::string_view &prefix, const std::string &reftrial, const std::string &phase, int stereopair, const std::string &extension)
 
static std::string likeRoiPath (const std::string &path, const std::string &reftrial, const std::string &phase, int stereopair, const std::string &extension)
 
static std::string likeSeedPath (const std::string &path, const std::string &reftrial, const std::string &phase, int stereopair, const std::string &extension)
 
static std::string buildRoiFilePath (const cppxdic::BaseParameters &parameters, std::string reftrial, int stereopair, const std::string &extension=".mat")
 Build the roi file path.
 
static std::string buildSeedFilePath (const cppxdic::BaseParameters &parameters, std::string reftrial, int stereopair, const std::string &extension=".mat")
 Build the seed file path.
 
static std::string buildMatchingFilePath (const cppxdic::BaseParameters &parameters, std::string reftrial, int stereopair, const std::string &extension=".bin")
 Build the matching file path.
 
static std::string buildDic3DCombinedFilePath (const std::string pathdir, int num_pair, const std::string &ext)
 
static std::string buildDic3DPPresultsFilePath (const std::string pathdir, int num_pair, const std::string &fileversion, const std::string &ext)
 
static std::string buildVizPath (const std::string pathdir, const std::string filename)
 
static std::string buildDic2DPairResultsFilePath (const std::string pathdir, int cam_1, int cam_2, const std::string &extension)
 
static std::string buildNcorrFilePath (const std::string pathdir, int cam_1, int cam_2=-1, const std::string &extension=".bin")
 

Detailed Description

Utility functions for CPPXDIC Equivalent to various utility functions in Matlab xDIC.

Definition at line 17 of file utils.h.

Member Function Documentation

◆ applyRigidTransform()

std::vector< Eigen::Vector3d > Utils::applyRigidTransform ( const std::vector< Eigen::Vector3d > &  points_in,
const RigidTransform &  transform 
)
static

Apply rigid transformation to point cloud points_out = R * points_in + t.

Definition at line 1140 of file utils.cpp.

◆ buildBaseDataPath()

std::string Utils::buildBaseDataPath ( const Config &  config,
bool  with_data_or_dic_path = false,
bool  with_rawdata = false,
bool  with_speckles = false 
)
static

Build base data path.

Parameters
configThe base configuration class (required)
with_data_or_dic_pathWhether to include data/dic path in the path (required)
with_rawdataWhether to include rawdata in the path (default as false)
with_specklesWhether to include speckles in the path (default as false)
Returns
The constructed path string

Definition at line 1162 of file utils.cpp.

◆ buildCalibDir()

std::string Utils::buildCalibDir ( const Config &  config)
static

Build the calib path.

Parameters
configThe base configuration class (required)
Returns
The constructed path string

Definition at line 1257 of file utils.cpp.

◆ buildDic2DPairResultsFilePath()

std::string Utils::buildDic2DPairResultsFilePath ( const std::string  pathdir,
int  cam_1,
int  cam_2,
const std::string &  extension 
)
static

Definition at line 1357 of file utils.cpp.

◆ buildDic3DCombinedFilePath()

std::string Utils::buildDic3DCombinedFilePath ( const std::string  pathdir,
int  num_pair,
const std::string &  ext 
)
static

Definition at line 1341 of file utils.cpp.

◆ buildDic3DPPresultsFilePath()

std::string Utils::buildDic3DPPresultsFilePath ( const std::string  pathdir,
int  num_pair,
const std::string &  fileversion,
const std::string &  ext 
)
static

Definition at line 1346 of file utils.cpp.

◆ buildMatchingFilePath()

std::string Utils::buildMatchingFilePath ( const cppxdic::BaseParameters &  parameters,
std::string  reftrial,
int  stereopair,
const std::string &  extension = ".bin" 
)
static

Build the matching file path.

Parameters
parametersThe base parameters structure (required)
reftrialThe reference trial number (required)
stereopairThe stereopair number (required)
extensionThe file extension (default as ".mat")
Returns
The constructed path string

Definition at line 1334 of file utils.cpp.

◆ buildNcorrFilePath()

std::string Utils::buildNcorrFilePath ( const std::string  pathdir,
int  cam_1,
int  cam_2 = -1,
const std::string &  extension = ".bin" 
)
static

Definition at line 1363 of file utils.cpp.

◆ buildOutputCachePath()

std::string Utils::buildOutputCachePath ( const cppxdic::BaseParameters &  parameters)
static

Build the output cache path.

Parameters
parametersThe base parameters structure (required)
Returns
The constructed path string

Definition at line 1290 of file utils.cpp.

◆ buildOutputPath()

std::string Utils::buildOutputPath ( const cppxdic::BaseParameters &  parameters)
static

Build the output path.

Parameters
parametersThe base parameters structure (required)
Returns
The constructed path string

Definition at line 1286 of file utils.cpp.

◆ buildOutputUntilMaterialDir()

std::string Utils::buildOutputUntilMaterialDir ( const Config &  config)
static

Build output path until material folder.

Parameters
configThe base configuration class (required)
Returns
The constructed path string

Definition at line 1237 of file utils.cpp.

◆ buildOutputUntilPhaseDir()

std::string Utils::buildOutputUntilPhaseDir ( const Config &  config,
int  trial 
)
static

Build output dir until the Phase folder.

Parameters
configThe base configuration class (required)
trialThe trial number
Returns
The constructed path string

Definition at line 1195 of file utils.cpp.

◆ buildOutputUntilTrialDir()

std::string Utils::buildOutputUntilTrialDir ( const Config &  config,
int  trial 
)
static

Build output dir until Trial folder.

Parameters
configThe base configuration class (required)
trialThe trial number
Returns
The constructed path string

Definition at line 1186 of file utils.cpp.

◆ buildPath() [1/2]

std::string Utils::buildPath ( const Config &  config,
bool  with_data_or_dic_path = false,
bool  with_rawdata = false,
bool  with_speckles = false,
bool  with_material = false,
bool  with_video = false,
bool  with_protocol = false,
bool  with_calib = false 
)
static

Build the path based on activated parameters and return the proper string.

Parameters
configThe base configuration class (required)
with_data_or_dic_pathWhether to include data/dic path in the path (required)
with_rawdataWhether to include rawdata in the path (default as false)
with_specklesWhether to include speckles in the path (default as false)
with_materialWhether to include material in the path (default as false)
with_videoWhether to include video in the path (default as false)
with_protocolWhether to include protocol in the path (default as false)
with_calibWhether to include calib and calib folder set in the path (default as false)
Returns
The constructed path string

Definition at line 1204 of file utils.cpp.

◆ buildPath() [2/2]

std::string Utils::buildPath ( const cppxdic::BaseParameters &  parameters,
bool  with_material = false,
bool  with_trial = false,
bool  with_phase = false,
bool  with_cache = false 
)
static

Build the path based on activated parameters and return the proper string.

Parameters
parametersThe base parameters structure (required)
with_materialWhether to include material in the path (default as false)
with_trialWhether to include trial in the path (default as false)
with_phaseWhether to include phase in the path (default as false)
with_cacheWhether to include cache in the path (default as false)
Returns
The constructed path string

Definition at line 1263 of file utils.cpp.

◆ buildProtocolDir()

std::string Utils::buildProtocolDir ( const Config &  config,
bool  with_data_or_dic_path = false,
bool  with_rawdata = false,
bool  with_speckles = false,
bool  with_material = false 
)
static

Build protocol path.

Parameters
configThe base configuration class (required)
with_data_or_dic_pathWhether to include data/dic path in the path (required)
with_rawdataWhether to include rawdata in the path (default as false)
with_specklesWhether to include speckles in the path (default as false)
with_materialWhether to include material in the path (default as false)
Returns
The constructed path string

Definition at line 1241 of file utils.cpp.

◆ buildRoiFilePath()

std::string Utils::buildRoiFilePath ( const cppxdic::BaseParameters &  parameters,
std::string  reftrial,
int  stereopair,
const std::string &  extension = ".mat" 
)
static

Build the roi file path.

Parameters
parametersThe base parameters structure (required)
reftrialThe reference trial number (required)
stereopairThe stereopair number (required)
extensionThe file extension (default as ".mat")
Returns
The constructed path string

Definition at line 1323 of file utils.cpp.

◆ buildSeedFilePath()

std::string Utils::buildSeedFilePath ( const cppxdic::BaseParameters &  parameters,
std::string  reftrial,
int  stereopair,
const std::string &  extension = ".mat" 
)
static

Build the seed file path.

Parameters
parametersThe base parameters structure (required)
reftrialThe reference trial number (required)
stereopairThe stereopair number (required)
extensionThe file extension (default as ".mat")
Returns
The constructed path string

Definition at line 1328 of file utils.cpp.

◆ buildUntilMaterialDir()

std::string Utils::buildUntilMaterialDir ( const Config &  config,
bool  with_data_or_dic_path,
bool  with_rawdata,
bool  with_speckles 
)
static

Build path until material folder.

Parameters
configThe base configuration class (required)
with_data_or_dic_pathWhether to include data/dic path in the path (required)
with_rawdataWhether to include rawdata in the path (default as false)
with_specklesWhether to include speckles in the path (default as false)
Returns
The constructed path string

Definition at line 1229 of file utils.cpp.

◆ buildVideoDir()

std::string Utils::buildVideoDir ( const Config &  config,
bool  with_data_or_dic_path = false,
bool  with_rawdata = false,
bool  with_speckles = false,
bool  with_material = false 
)
static

Build the video path.

Parameters
configThe base configuration class (required)
with_data_or_dic_pathWhether to include data/dic path in the path (required)
with_rawdataWhether to include rawdata in the path (default as false)
with_specklesWhether to include speckles in the path (default as false)
with_materialWhether to include material in the path (default as false)
Returns
The constructed path string

Definition at line 1249 of file utils.cpp.

◆ buildVizPath()

std::string Utils::buildVizPath ( const std::string  pathdir,
const std::string  filename 
)
static

Definition at line 1353 of file utils.cpp.

◆ cameraPairs()

const std::vector< std::pair< int, int > > & Utils::cameraPairs ( )
static

Currently registered stereopair table (see setCameraPairs).

Definition at line 250 of file utils.cpp.

◆ computeRigidTransform()

bool Utils::computeRigidTransform ( const std::vector< Eigen::Vector3d > &  points_from,
const std::vector< Eigen::Vector3d > &  points_to,
RigidTransform &  transform 
)
static

Compute optimal rigid body transformation between two point clouds Matches MATLAB: rigidTransformation(Pfrom, Pto) Uses SVD-based least squares minimization.

Parameters
points_fromSource point cloud to be transformed
points_toTarget point cloud
transformOutput: rotation R and translation t such that points_transformed = R * points_from + t
Returns
true if successful

Definition at line 1060 of file utils.cpp.

◆ dicCheck()

bool Utils::dicCheck ( const Config &  config)
static

Utility functions implementation for CPPXDIC.

Definition at line 23 of file utils.cpp.

◆ directoryExists()

bool Utils::directoryExists ( const std::string &  path)
static

Definition at line 189 of file utils.cpp.

◆ DLT11Calibration()

bool Utils::DLT11Calibration ( const double *  P2,
const double *  P3,
size_t  N,
std::vector< double > &  L 
)
static

Compute DLT (Direct Linear Transformation) 11 parameters from 2D-3D point correspondences Matches MATLAB: L = DLT11Calibration(P2, P3) Solves the 2Nx11 least squares system M \ P2array for 11 DLT parameters.

Parameters
P22D image points (Nx2 row-major: [u1,v1, u2,v2, ...])
P33D world points (Nx3 row-major: [X1,Y1,Z1, X2,Y2,Z2, ...])
NNumber of point correspondences
LOutput: 11 DLT parameters
Returns
true if successful

Definition at line 999 of file utils.cpp.

◆ fileExists()

bool Utils::fileExists ( const std::string &  path)
static

Definition at line 185 of file utils.cpp.

◆ findFiles()

std::vector< std::string > Utils::findFiles ( const std::string &  directory,
const std::string &  pattern 
)
static

Definition at line 193 of file utils.cpp.

◆ formatString()

static std::string Utils::formatString ( const std::string &  format,
  ... 
)
static

◆ getCamerasForPair() [1/2]

void Utils::getCamerasForPair ( int  stereopair,
const std::vector< std::pair< int, int > > &  camera_pairs,
int &  cam_first,
int &  cam_second 
)
static

Get camera numbers for a given stereopair using config camera_pairs mapping.

Parameters
stereopairThe stereopair number (1-indexed)
camera_pairsVector of (cam_first, cam_second) pairs from config
cam_firstOutput: first camera number
cam_secondOutput: second camera number

Definition at line 258 of file utils.cpp.

◆ getCamerasForPair() [2/2]

void Utils::getCamerasForPair ( int  stereopair,
int &  cam_first,
int &  cam_second 
)
static

Get camera numbers for a given stereopair using the registered table (setCameraPairs).

Pairs beyond the table fall back to (2N-1, 2N).

Parameters
stereopairThe stereopair number (1-indexed)
cam_firstOutput: first camera number
cam_secondOutput: second camera number

Definition at line 254 of file utils.cpp.

◆ importRawVid()

bool Utils::importRawVid ( const Config &  config,
int  trial,
int  stereopair,
int  frameStart,
int  frameEnd,
int  frameJump,
std::vector< std::string > &  cam1Frames,
std::vector< std::string > &  cam2Frames,
int  maxFrames = 0 
)
static

Definition at line 349 of file utils.cpp.

◆ importVid()

bool Utils::importVid ( const Config &  config,
int  trial,
int  stereopair,
std::vector< std::string > &  cam1Frames,
std::vector< std::string > &  cam2Frames,
int  maxFrames = 0 
)
static

Definition at line 468 of file utils.cpp.

◆ likeRoiOrSeedPath()

std::string Utils::likeRoiOrSeedPath ( const std::string &  path,
const std::string_view &  prefix,
const std::string &  reftrial,
const std::string &  phase,
int  stereopair,
const std::string &  extension 
)
static

Definition at line 1294 of file utils.cpp.

◆ likeRoiPath()

std::string Utils::likeRoiPath ( const std::string &  path,
const std::string &  reftrial,
const std::string &  phase,
int  stereopair,
const std::string &  extension 
)
static

Definition at line 1303 of file utils.cpp.

◆ likeSeedPath()

std::string Utils::likeSeedPath ( const std::string &  path,
const std::string &  reftrial,
const std::string &  phase,
int  stereopair,
const std::string &  extension 
)
static

Definition at line 1309 of file utils.cpp.

◆ loadCameraParameters()

bool Utils::loadCameraParameters ( const std::string &  mat_path,
CameraParameters &  params 
)
static

Load camera calibration parameters from MATLAB .mat file Matches MATLAB: load('cameraCBparameters_cam_X.mat') Expects structure 'cameraCBparameters' with field 'cameraParameters'.

Definition at line 804 of file utils.cpp.

◆ loadROIFromMat()

bool Utils::loadROIFromMat ( const Config &  config,
int  trial,
int  stereopair,
std::string &  roiJsonPath,
std::string &  roiMaskImagePath 
)
static

Definition at line 596 of file utils.cpp.

◆ loadSeedFromMat()

bool Utils::loadSeedFromMat ( const Config &  config,
int  trial,
int  stereopair,
std::string &  seedJsonPath 
)
static

Definition at line 670 of file utils.cpp.

◆ setCameraPairs()

void Utils::setCameraPairs ( const std::vector< std::pair< int, int > > &  camera_pairs)
static

Register the process-wide stereopair -> (cam_first, cam_second) table.

Called once with Config::camera_pairs after the configuration is resolved (main.cpp / DicAnalysis ctor). Every getCamerasForPair(stereopair, ...) call then honours the configured mapping instead of the legacy {1,2 ; 4,3} hard-coded table. Passing an empty vector restores the legacy default.

Definition at line 246 of file utils.cpp.

◆ split()

std::vector< std::string > Utils::split ( const std::string &  str,
char  delimiter 
)
static

Definition at line 224 of file utils.cpp.

◆ undistortPoint()

cv::Point2d Utils::undistortPoint ( const cv::Point2d &  point_in,
const CameraParameters &  params 
)
static

Undistort single 2D point.

Definition at line 934 of file utils.cpp.

◆ undistortPoints()

void Utils::undistortPoints ( const std::vector< cv::Point2d > &  points_in,
const CameraParameters &  params,
std::vector< cv::Point2d > &  points_out 
)
static

Undistort 2D points using camera parameters Matches MATLAB: undistortPoints(points, cameraParameters)

Parameters
points_inInput 2D points (Nx2)
paramsCamera calibration parameters
points_outOutput undistorted 2D points (Nx2)

Definition at line 911 of file utils.cpp.


The documentation for this class was generated from the following files: