@@ -21,7 +21,7 @@ XsensDataReader* XsensDataReader::clone() const {
21
21
22
22
typedef struct XsensDataReader ::XsensIMU {
23
23
std::string name;
24
- int data_size;
24
+ size_t data_size;
25
25
std::string rotation_format;
26
26
std::map<std::string, std::string> comments;
27
27
std::map<std::string, size_t > header;
@@ -55,12 +55,12 @@ DataAdapter::OutputTables XsensDataReader::extendRead(
55
55
_settings.get_rotation_representation ();
56
56
const std::string prefix = _settings.get_trial_prefix ();
57
57
58
- const int n_imus = _settings.getProperty_ExperimentalSensors ().size ();
58
+ const size_t n_imus = _settings.getProperty_ExperimentalSensors ().size ();
59
59
60
60
// Prepare all the file handles
61
61
// format: name, filename
62
62
std::vector<std::pair<std::string, std::string>> imuFiles;
63
- for (int index = 0 ; index < n_imus; ++index ) {
63
+ for (size_t index = 0 ; index < n_imus; ++index ) {
64
64
std::string prefix = _settings.get_trial_prefix ();
65
65
const ExperimentalSensor& nextItem =
66
66
_settings.get_ExperimentalSensors (index );
@@ -109,7 +109,7 @@ DataAdapter::OutputTables XsensDataReader::extendRead(
109
109
tokens = FileAdapter::tokenize (line, delimiter);
110
110
// Process each header in the line
111
111
for (const auto & token : tokens) {
112
- int tokenIndex = std::distance (tokens.begin (),
112
+ size_t tokenIndex = std::distance (tokens.begin (),
113
113
std::find (tokens.begin (), tokens.end (), token));
114
114
imu.header .insert ({token, tokenIndex});
115
115
}
@@ -166,7 +166,7 @@ DataAdapter::OutputTables XsensDataReader::extendRead(
166
166
imu.rotation_format + " \" and delimiter: \" " +
167
167
delimiter + " \" " );
168
168
std::vector<std::string> next_row;
169
- int row_count = 0 ;
169
+ size_t row_count = 0 ;
170
170
while (!(next_row = FileAdapter::getNextLine (
171
171
stream, delimiter + " \r " ))
172
172
.empty ()) {
@@ -222,7 +222,6 @@ DataAdapter::OutputTables XsensDataReader::extendRead(
222
222
if (found_rot_mat) {
223
223
// Create Mat33 then convert into Quaternion
224
224
SimTK::Mat33 imu_matrix{SimTK::NaN};
225
- int matrix_entry_index = 0 ;
226
225
imu_matrix[0 ][0 ] = OpenSim::IO::stod (
227
226
next_row[imu.header .at (rot_mat_h[0 ])]);
228
227
imu_matrix[1 ][0 ] = OpenSim::IO::stod (
@@ -254,7 +253,7 @@ DataAdapter::OutputTables XsensDataReader::extendRead(
254
253
255
254
// Ensure all files have the same size, update rate, and rotation
256
255
// format
257
- std::vector<int > line_lengths (imus.size ());
256
+ std::vector<size_t > line_lengths (imus.size ());
258
257
std::vector<double > update_rates (imus.size ());
259
258
std::vector<std::string> rotation_formats (imus.size ());
260
259
@@ -293,29 +292,30 @@ DataAdapter::OutputTables XsensDataReader::extendRead(
293
292
" format!" );
294
293
295
294
// These have all been checked for uniformity
296
- const int n_lines = line_lengths[0 ];
295
+ const size_t n_lines = line_lengths[0 ];
297
296
const double sampling_rate = update_rates[0 ];
298
297
const std::string rotation_format = rotation_formats[0 ];
299
298
299
+ OPENSIM_THROW_IF (
300
+ (n_lines > static_cast <size_t >(std::numeric_limits<int >::max ())),
301
+ IOError, " Too many lines present in the data files!" );
300
302
// Will read data into pre-allocated Matrices in-memory rather than
301
303
// appendRow on the fly to avoid the overhead of
302
- SimTK::Matrix_<SimTK::Quaternion> rotationsData{n_lines, n_imus};
303
- SimTK::Matrix_<SimTK::Vec3> linearAccelerationData{n_lines, n_imus};
304
- SimTK::Matrix_<SimTK::Vec3> magneticHeadingData{n_lines, n_imus};
305
- SimTK::Matrix_<SimTK::Vec3> angularVelocityData{n_lines, n_imus};
306
-
307
- const bool has_acc =
308
- std::all_of (imus.begin (), imus.end (), [&n_lines](const auto & imu) {
309
- return imu.acc .size () == static_cast <std::size_t >(n_lines);
310
- });
311
- const bool has_gyr =
312
- std::all_of (imus.begin (), imus.end (), [&n_lines](const auto & imu) {
313
- return imu.gyr .size () == static_cast <std::size_t >(n_lines);
314
- });
315
- const bool has_mag =
316
- std::all_of (imus.begin (), imus.end (), [&n_lines](const auto & imu) {
317
- return imu.mag .size () == static_cast <std::size_t >(n_lines);
318
- });
304
+ SimTK::Matrix_<SimTK::Quaternion> rotationsData{
305
+ static_cast <int >(n_lines), n_imus};
306
+ SimTK::Matrix_<SimTK::Vec3> linearAccelerationData{
307
+ static_cast <int >(n_lines), n_imus};
308
+ SimTK::Matrix_<SimTK::Vec3> magneticHeadingData{
309
+ static_cast <int >(n_lines), n_imus};
310
+ SimTK::Matrix_<SimTK::Vec3> angularVelocityData{
311
+ static_cast <int >(n_lines), n_imus};
312
+
313
+ const bool has_acc = std::all_of (imus.begin (), imus.end (),
314
+ [&n_lines](const auto & imu) { return imu.acc .size () == n_lines; });
315
+ const bool has_gyr = std::all_of (imus.begin (), imus.end (),
316
+ [&n_lines](const auto & imu) { return imu.gyr .size () == n_lines; });
317
+ const bool has_mag = std::all_of (imus.begin (), imus.end (),
318
+ [&n_lines](const auto & imu) { return imu.mag .size () == n_lines; });
319
319
320
320
// We use a vector of row indices to transform over the rows (i.e., the time
321
321
// steps)
@@ -340,18 +340,15 @@ DataAdapter::OutputTables XsensDataReader::extendRead(
340
340
n_imus, SimTK::Vec3 (SimTK::NaN));
341
341
const bool has_quat = std::all_of (
342
342
imus.begin (), imus.end (), [&n_lines](const auto & imu) {
343
- return imu.quat .size () ==
344
- static_cast <std::size_t >(n_lines);
343
+ return imu.quat .size () == n_lines;
345
344
});
346
345
const bool has_euler = std::all_of (
347
346
imus.begin (), imus.end (), [&n_lines](const auto & imu) {
348
- return imu.euler .size () ==
349
- static_cast <std::size_t >(n_lines);
347
+ return imu.euler .size () == n_lines;
350
348
});
351
349
const bool has_rot_mat = std::all_of (
352
350
imus.begin (), imus.end (), [&n_lines](const auto & imu) {
353
- return imu.rot_mat .size () ==
354
- static_cast <std::size_t >(n_lines);
351
+ return imu.rot_mat .size () == n_lines;
355
352
});
356
353
if (has_acc) {
357
354
std::transform (imus.begin (), imus.end (),
@@ -403,7 +400,7 @@ DataAdapter::OutputTables XsensDataReader::extendRead(
403
400
404
401
const double timeIncrement = 1.0 / sampling_rate;
405
402
const auto times =
406
- createVectorLinspaceInterval (n_lines, 0.0 , timeIncrement);
403
+ createVectorLinspaceInterval (static_cast < int >( n_lines) , 0.0 , timeIncrement);
407
404
// Zero data matrices if the data is not found
408
405
if (!has_acc) { linearAccelerationData.resize (0 , n_imus); }
409
406
if (!has_mag) { magneticHeadingData.resize (0 , n_imus); }
0 commit comments