CPPxDIC
C++ Digital Image Correlation library for fingertip 3D reconstruction
Loading...
Searching...
No Matches
config.h
Go to the documentation of this file.
1
6#ifndef CONFIG_H
7#define CONFIG_H
8
9#include <string>
10#include <vector>
11
16struct StepConfig {
17 std::string analysis_type = "regular";
18 int radius = 40;
19 int spacing = 10;
20 double cutoff_diffnorm = 1e-5;
24 std::string seed_type = "seed";
25 bool auto_update = true;
27 std::vector<int> initial_seed; // empty = auto
28};
29
30class Config {
31public:
32 // Global parameters (from global_param.m)
33 std::vector<std::string> frictional_conditions = {"glass", "coating", "coating_oil"};
34 int num_pair = 2; // Number of stereopairs
35 // Camera pairs: per-pair (cam_first, cam_second) mapping
36 // Default matches MATLAB import_raw_vid: pair1=(1,2), pair2=(4,3)
37 std::vector<std::pair<int, int>> camera_pairs = {{1, 2}, {4, 3}};
38 // Mirrored (MNG) rig settings, from theGlobalSettings_MNG.m. Only used when the
39 // executable is built with -DXDIC_MODE=mirrored.
40 int mirrored_num_pair = 7; // Npair: 8 views -> 7 overlapping stereopairs
41 std::vector<int> mirrored_cam_order = {2, 1, 4, 3}; // cam_order: physical camera per view slot
42 double robot_sample_freq = 1000.0; // robot sampling frequency (Hz)
43 double vid_sample_freq = 50.0; // image sampling frequency (Hz)
44
45 // Path definitions
46 std::string base_path = "/Users/jaoga/devlab/MultiDIC";
47 std::string data_path; // location of the video files and protocol files
48 std::string dic_path; // location of the output data from DIC
49
50 // Processing flags
51 bool im_filter_mode = true;
52 // Grayscale saturation (satur.m: clip pixels above limit_grayscale) applied to
53 // every imported frame before ROI/matching/tracking. Set false for videos that
54 // were already filtered/normalised upstream (e.g. MNG rigs), where clipping
55 // would flatten the speckle contrast and make ncorr diverge.
56 bool im_saturation_mode = true;
57 // When true, idx_frame_start/idx_frame_end/frame_jump are authoritative and the
58 // protocol-derived per-phase window (loading/slide/relax from the protocol .mat)
59 // is NOT applied. Default false keeps the historical protocol-driven behaviour.
60 bool force_frame_window = false;
61 bool automatic_process = true; // automatic processing flag
62 bool parallel_processing = true; // parallel processing flag
63
64 // DIC parameters (from dic_param.m)
65 std::string subject_id = "S09"; // Subject identifier
66 std::string phase_id = "loading"; // Phase identifier
67 int material_id = 2; // Material identifier
68 std::vector<int> nfcond_set = {5}; // Number of conditions
69 std::vector<double> spddxlcond_set = {0.04, 0.08}; // Speed conditions
70
71 // Calibration settings
72 std::string calib_folder_set = "2";
73
74 // Reference trial number
75 int ref_trial_id = 5;
76
77 // Frame settings
79 int idx_frame_end = 150;
80 int frame_jump = 1;
81
82 // Visualization settings (equivalent to MATLAB optStructPlot)
83 bool showvisu = false; // Boolean for visualization
84 bool debug_mode = false; // Debug mode flag
85
86 // Logging settings (consumed by main() to configure cppxdic::log)
87 std::string log_level = ""; // "" = unset; trace|debug|info|warn|error|off (console threshold)
88 std::string log_file = ""; // "" = no log file; path to write a full-detail log
89
90 // Plot map settings
91 bool mapLogic = true; // Enable 3D map plotting
92 std::vector<std::string> plotopt = {"Epc1", "Epc2"}; // Face measurement plot options
93 std::string deftype = "both"; // Derivative order: 'cum'|'rate'|'both'
94 std::string viewplot =
95 "below"; // Initial plot perspective: 'lateralR'|'below'|'lateralL'|'front'
96 bool contactAreaLogic = false; // Contact area delimitation
97 bool gapLogic = true; // Suppress stitched pair boundary
98 double maxCorrCoeff = 10.0; // Max admissible correlation coefficient
99 std::string format = "small"; // Plot format: 'small'|'normal'
100
101 // Filtering settings
102 bool smoothTimeLogic = true; // Smooth time of the maps
103 double filterFreq = 5.0; // Cut-off frequency (Hz)
104 bool smoothSpaceLogic = true; // Smooth space of the maps
105 int smoothPar_n = 30; // Space filtering parameter 1
106 double smoothPar_sigma = 2.0; // Space filtering parameter 2
107
108 // Additional plot settings
109 bool showRobotLogic = true; // Plot kinematic/dynamic data
110 bool showImgLogic = false; // Plot image
111 int camNbr = 0; // Camera number (0 or specific camera)
112 bool tracesLogic = false; // Plot traces (deprecated)
113
114 // Plot appearance settings
115 double FaceAlpha = 1.0; // Face transparency (0-1)
116 std::string lineColor = "none"; // Line color: 'none'|'k'|'b', etc.
117 double quiverScaleFactor = 20.0; // Arrow scale factor for vector plots
118
119 // Output/Export settings
120 std::string export_format = "vtk"; // Export format: 'vtk'|'ply'|'csv'
121 bool export_each_frame = false; // Export each frame separately
122 std::vector<int> export_frame_list; // Specific frames to export (empty = all)
123
124 // File version and naming
125 std::string fileversion = "v2"; // Deformation file version
126
127 // Output format control (legacy flags removed — use data_format instead)
128
129 // Units and subregion
130 double units_per_pixel = 0.2; // e.g., mm per pixel
131 int subregion_radius = 20; // default subset radius (pixels)
132 // Grayscale saturation limit. 0 (default) = automatic: 70 for subjects whose
133 // id number is < 8 (S01..S07), 100 otherwise (legacy MATLAB rule); any positive
134 // value is used as-is regardless of the subject id.
136
137 // Step-level DIC parameters (loaded from dic_params.txt)
138 StepConfig step_d; // Step D: initial tracking
139 StepConfig step_e = [] { // Step E: matching (larger radius by default)
140 StepConfig c;
141 c.radius = 60; // MATLAB: subset_radius_ncorr_matching = 60
142 return c;
143 }();
144 StepConfig step_f; // Step F: combined/final
145
146 // Step E specific parameters (3D reconstruction)
147 // Step E stitching of the per-pair 3D surfaces: "geometric" (MATLAB-faithful overlap
148 // removal + boundary zipping; O(iterations x boundary x faces), can take many hours
149 // on multi-pair rigs with large overlaps) or "simple" (plain append of all pairs,
150 // overlaps kept). Only used when every pair of the trial was reconstructed.
151 std::string step_e_stitch_mode = "geometric";
152 // Accelerate the geometric stitcher's ray casts with an AABB hierarchy over the
153 // faces. Exact (same hits, same result) — it only avoids testing triangles the ray
154 // cannot reach. Off by default while it is being validated against the brute-force
155 // path; on multi-pair rigs the brute-force ray casts dominate Step E.
156 bool step_e_ray_bvh = false;
158 false; // Remove distortion from 2D points (MATLAB default: false)
160 true; // Replace bad correlation subsets (MATLAB step2_dic_finish: active, but slow)
161
162 // Step F specific parameters (deformation analysis)
163 bool step_f_temporal_filtering = true; // Enable temporal filtering of displacements
164 double step_f_freq_filt = 10.0; // Low-pass cutoff frequency (Hz) for temporal filter
165 bool step_f_compute_rbm = false; // Compute rigid body motion (RBM) and ARBM deformation
166
167 // Data format for pipeline I/O: "mat", "bin", or "json"
168 std::string data_format = "mat";
169
170 // NCorr-specific parameters (loaded from ncorr_params.txt)
171 int ncorr_scalefactor = 3; // Scale factor
172 std::string ncorr_interp = "quintic_bspline_precompute"; // Interpolation method
173 std::string ncorr_subregion = "circle"; // Subregion shape
174 std::string ncorr_dic_config = "no_update"; // DIC config mode
175 bool ncorr_no_update = true; // Step-D tracking preset: true = NO_UPDATE (fixed ref within a
176 // segment, the long-standing default); false = KEEP_MOST_POINTS
177 // (with cutoff_corrcoef=0.5 -> MATLAB-style correlation-based
178 // reference updates)
179 int ncorr_fixed_step_ref = 0; // >0: force a reference change every N frames (MATLAB ncorr
180 // step analysis, step_ref_change semantics); 0 = off
181 double ncorr_cutoff_corrcoef = 10.0; // Correlation cutoff
182 std::string ncorr_roi_update_mode = "none"; // ROI update mode
183 std::string ncorr_accumulation_mode = "none"; // Accumulation mode
184 bool ncorr_save_disps_steps = false; // Save intermediate disps
185 bool ncorr_perspective_interp = false; // Eulerian perspective-change interpolation:
186 // false = bicubic CUBIC_KEYS (historical workaround for
187 // the FFT-bcoef border bias, kept as default);
188 // true = biquintic B-spline (MATLAB ncorr behavior; safe
189 // since the recursive bcoef filter fix)
190 std::string ncorr_units = "mm"; // Units string
191 // Seed-quality gates (ncorr_params.txt). A seed whose optimised solution exceeds
192 // either gate is rejected -> "could not seed any current image". Defaults match
193 // CppNCorr's own defaults; before these were wired through, the engine defaults
194 // (0.1 / 0.5) always applied whatever the config said.
195 bool ncorr_seeds_are_optimized = false; // seeds already optimised (skip seed optimisation)
196 double ncorr_cutoff_max_diffnorm = 0.1; // max diffnorm accepted for a seed
197 double ncorr_cutoff_max_corrcoef = 0.5; // max corrcoef accepted for a TRACKING seed
198 // Looser gate for inter-view MATCHING seeds (cam1->cam2 / view1->view2 at the
199 // reference frame): different perspectives correlate worse than consecutive
200 // frames (MNG mirrored rig pair 1: 0.51, rejected by the 0.5 tracking gate).
202 int ncorr_threads = 4; // Number of threads
204 false; // Use exact_matlab_DIC_analysis_* (mirrors MATLAB ncorr_alg_addanalysis chain
205 // composition) instead of matlab_DIC_analysis_* (which has a chain-induced jump at
206 // the first segment boundary).
207
208 // DIC engine backend: "cuncorr" runs the cuNCorr engine (CUDA if a device is present,
209 // else its CPU backend — numerically identical); "ncorr" uses the legacy CppNCorr path.
210 // cuNCorr is a different algorithm from CppNCorr, so switching changes the DIC numbers.
211 std::string dic_engine = "cuncorr";
212 int cuncorr_seed_search = 15; // cuNCorr coarse seed search radius in pixels
213
214 // Visualization: VTK export options
215 std::string vtk_format = "ascii"; // VTK format: ascii|binary
216 bool vtk_include_scalars = true; // Include scalar data in VTK
217 bool vtk_include_vectors = true; // Include vector data in VTK
218
219 // Visualization: PLY export options
220 std::string ply_format = "ascii"; // PLY format: ascii|binary
221 bool ply_include_colors = true; // Include colors in PLY
222
223 // Visualization: CSV export options
224 std::string csv_delimiter = ","; // CSV delimiter
225 bool csv_include_header = true; // Include header in CSV
226
227 // Visualization: Video options
228 bool generate_videos = false; // Generate videos
229 int video_fps = 10; // Video FPS
230 std::string video_codec = "MJPG"; // Video codec
231 int video_quality = 90; // Video quality (0-100)
232 double video_alpha = 1.0; // Video transparency
233
234 // Visualization: Colormap options
235 std::string colormap = "jet"; // Colormap name
236 std::string colormap_range_mode = "auto"; // Range mode: auto|manual
237 double colormap_min = 0.0; // Manual colormap min
238 double colormap_max = 1.0; // Manual colormap max
239 int colormap_levels = 256; // Number of color levels
240
241 // Visualization: Statistics options
242 bool generate_summary_stats = true; // Generate summary statistics
243 std::string stats_format = "txt"; // Stats format: txt|csv|json
244 bool stats_per_frame = true; // Per-frame statistics
245 bool stats_spatial = true; // Spatial statistics
246 bool stats_temporal = true; // Temporal statistics
247
248 // Visualization: Advanced options
249 double mesh_decimation = 1.0; // Mesh decimation factor (1.0 = no decimation)
250 bool mesh_smoothing = false; // Enable mesh smoothing
251 int mesh_smoothing_iterations = 10; // Smoothing iterations
252 bool show_axes = true; // Show axes in visualization
253 bool show_colorbar = true; // Show colorbar
254 bool show_grid = false; // Show grid
255 std::string background_color = "white"; // Background color
256
257 // Derived parameters
258 std::string material; // Material name from frictional_conditions
259
260 // Methods
261 Config(); // Constructor to set defaults
262 void updateVariables(); // Derive material name etc.
263
264 // Parameter file loading methods
265 bool loadFromDicParamsFile(const std::string& filepath = "dic_params.txt");
266 bool loadFromNcorrParamsFile(const std::string& filepath = "ncorr_params.txt");
267 bool loadFromVisualizationParamsFile(const std::string& filepath = "visualization_params.txt");
268
282 bool loadFromConfigFile(const std::string& filepath = "config/default.cfg");
283
284 // Command-line override methods
285 void overrideSubject(const std::string& subject);
286 void overrideRefTrial(int trial);
287
288private:
289 void setDefaultPaths();
290 std::string parseConfigValue(const std::string& line, const std::string& key);
291 std::vector<std::string> parseStringList(const std::string& value);
292 std::vector<int> parseIntList(const std::string& value);
293 std::vector<double> parseDoubleList(const std::string& value);
294 bool parseBool(const std::string& value);
295};
296
297#endif // CONFIG_H
StepConfig step_e
Definition config.h:139
double smoothPar_sigma
Definition config.h:106
std::string dic_engine
Definition config.h:211
int mirrored_num_pair
Definition config.h:40
bool vtk_include_vectors
Definition config.h:217
bool showRobotLogic
Definition config.h:109
bool gapLogic
Definition config.h:97
int ref_trial_id
Definition config.h:75
bool generate_videos
Definition config.h:228
bool mesh_smoothing
Definition config.h:250
std::string dic_path
Definition config.h:48
bool step_e_distortion_removal
Definition config.h:157
void overrideSubject(const std::string &subject)
Definition config.cpp:622
std::string colormap
Definition config.h:235
std::vector< int > export_frame_list
Definition config.h:122
bool showvisu
Definition config.h:83
bool im_filter_mode
Definition config.h:51
double colormap_max
Definition config.h:238
bool mapLogic
Definition config.h:91
bool ncorr_perspective_interp
Definition config.h:185
bool step_f_compute_rbm
Definition config.h:165
std::string ncorr_roi_update_mode
Definition config.h:182
double vid_sample_freq
Definition config.h:43
bool step_e_ray_bvh
Definition config.h:156
std::string stats_format
Definition config.h:243
std::vector< int > mirrored_cam_order
Definition config.h:41
bool ncorr_seeds_are_optimized
Definition config.h:195
std::string viewplot
Definition config.h:94
int ncorr_threads
Definition config.h:202
std::string subject_id
Definition config.h:65
bool tracesLogic
Definition config.h:112
std::string format
Definition config.h:99
StepConfig step_f
Definition config.h:144
double colormap_min
Definition config.h:237
std::string step_e_stitch_mode
Definition config.h:151
bool ply_include_colors
Definition config.h:221
std::string ply_format
Definition config.h:220
void updateVariables()
Definition config.cpp:18
double step_f_freq_filt
Definition config.h:164
std::string material
Definition config.h:258
bool contactAreaLogic
Definition config.h:96
std::string ncorr_units
Definition config.h:190
bool loadFromDicParamsFile(const std::string &filepath="dic_params.txt")
Definition config.cpp:124
bool loadFromConfigFile(const std::string &filepath="config/default.cfg")
Load a single unified config file (the middle tier of the override chain).
Definition config.cpp:607
std::vector< std::pair< int, int > > camera_pairs
Definition config.h:37
int idx_frame_start
Definition config.h:78
int material_id
Definition config.h:67
std::string vtk_format
Definition config.h:215
int video_quality
Definition config.h:231
bool parallel_processing
Definition config.h:62
bool ncorr_save_disps_steps
Definition config.h:184
std::string export_format
Definition config.h:120
bool stats_temporal
Definition config.h:246
bool step_f_temporal_filtering
Definition config.h:163
int num_pair
Definition config.h:34
double filterFreq
Definition config.h:103
void overrideRefTrial(int trial)
Definition config.cpp:628
bool smoothTimeLogic
Definition config.h:102
double ncorr_cutoff_max_corrcoef
Definition config.h:197
std::string background_color
Definition config.h:255
bool show_colorbar
Definition config.h:253
std::vector< std::string > plotopt
Definition config.h:92
bool debug_mode
Definition config.h:84
int colormap_levels
Definition config.h:239
int ncorr_scalefactor
Definition config.h:171
bool loadFromNcorrParamsFile(const std::string &filepath="ncorr_params.txt")
Definition config.cpp:345
int subregion_radius
Definition config.h:131
std::string phase_id
Definition config.h:66
double video_alpha
Definition config.h:232
std::string colormap_range_mode
Definition config.h:236
int limit_grayscale
Definition config.h:135
bool smoothSpaceLogic
Definition config.h:104
int frame_jump
Definition config.h:80
int video_fps
Definition config.h:229
std::string base_path
Definition config.h:46
std::string fileversion
Definition config.h:125
int mesh_smoothing_iterations
Definition config.h:251
bool show_axes
Definition config.h:252
std::string csv_delimiter
Definition config.h:224
bool generate_summary_stats
Definition config.h:242
std::vector< int > nfcond_set
Definition config.h:68
std::string calib_folder_set
Definition config.h:72
bool ncorr_no_update
Definition config.h:175
double quiverScaleFactor
Definition config.h:117
double maxCorrCoeff
Definition config.h:98
Config()
Configuration implementation for CPPXDIC.
Definition config.cpp:13
bool automatic_process
Definition config.h:61
std::string ncorr_accumulation_mode
Definition config.h:183
bool vtk_include_scalars
Definition config.h:216
bool csv_include_header
Definition config.h:225
bool im_saturation_mode
Definition config.h:56
StepConfig step_d
Definition config.h:138
std::string ncorr_dic_config
Definition config.h:174
bool showImgLogic
Definition config.h:110
bool loadFromVisualizationParamsFile(const std::string &filepath="visualization_params.txt")
Definition config.cpp:426
int camNbr
Definition config.h:111
bool stats_spatial
Definition config.h:245
double robot_sample_freq
Definition config.h:42
std::string deftype
Definition config.h:93
bool ncorr_use_exact_matlab
Definition config.h:203
std::string log_level
Definition config.h:87
int idx_frame_end
Definition config.h:79
std::string ncorr_subregion
Definition config.h:173
std::string data_path
Definition config.h:47
std::string video_codec
Definition config.h:230
double ncorr_cutoff_max_diffnorm
Definition config.h:196
bool force_frame_window
Definition config.h:60
std::vector< double > spddxlcond_set
Definition config.h:69
std::vector< std::string > frictional_conditions
Definition config.h:33
bool step_d_replacebadcorr
Definition config.h:159
bool export_each_frame
Definition config.h:121
bool show_grid
Definition config.h:254
std::string ncorr_interp
Definition config.h:172
double mesh_decimation
Definition config.h:249
std::string data_format
Definition config.h:168
std::string log_file
Definition config.h:88
int ncorr_fixed_step_ref
Definition config.h:179
double FaceAlpha
Definition config.h:115
double units_per_pixel
Definition config.h:130
int smoothPar_n
Definition config.h:105
int cuncorr_seed_search
Definition config.h:212
std::string lineColor
Definition config.h:116
double ncorr_matching_cutoff_max_corrcoef
Definition config.h:201
double ncorr_cutoff_corrcoef
Definition config.h:181
bool stats_per_frame
Definition config.h:244
Configuration class for CPPXDIC Handles loading and managing parameters equivalent to Matlab global_p...
Definition config.h:16
double cutoff_diffnorm
Definition config.h:20
std::vector< int > initial_seed
Definition config.h:27
bool auto_update
Definition config.h:25
int cutoff_iteration
Definition config.h:21
int spacing
Definition config.h:19
std::string analysis_type
Definition config.h:17
std::string seed_type
Definition config.h:24
bool high_strain_enabled
Definition config.h:23
int total_threads
Definition config.h:22
int radius
Definition config.h:18
int step_ref_change
Definition config.h:26