Skip to content

Commit 32fe979

Browse files
committed
Update for int and size_t
1 parent 821520a commit 32fe979

File tree

1 file changed

+29
-32
lines changed

1 file changed

+29
-32
lines changed

OpenSim/Common/XsensDataReader.cpp

Lines changed: 29 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ XsensDataReader* XsensDataReader::clone() const {
2121

2222
typedef struct XsensDataReader::XsensIMU {
2323
std::string name;
24-
int data_size;
24+
size_t data_size;
2525
std::string rotation_format;
2626
std::map<std::string, std::string> comments;
2727
std::map<std::string, size_t> header;
@@ -55,12 +55,12 @@ DataAdapter::OutputTables XsensDataReader::extendRead(
5555
_settings.get_rotation_representation();
5656
const std::string prefix = _settings.get_trial_prefix();
5757

58-
const int n_imus = _settings.getProperty_ExperimentalSensors().size();
58+
const size_t n_imus = _settings.getProperty_ExperimentalSensors().size();
5959

6060
// Prepare all the file handles
6161
// format: name, filename
6262
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) {
6464
std::string prefix = _settings.get_trial_prefix();
6565
const ExperimentalSensor& nextItem =
6666
_settings.get_ExperimentalSensors(index);
@@ -109,7 +109,7 @@ DataAdapter::OutputTables XsensDataReader::extendRead(
109109
tokens = FileAdapter::tokenize(line, delimiter);
110110
// Process each header in the line
111111
for (const auto& token : tokens) {
112-
int tokenIndex = std::distance(tokens.begin(),
112+
size_t tokenIndex = std::distance(tokens.begin(),
113113
std::find(tokens.begin(), tokens.end(), token));
114114
imu.header.insert({token, tokenIndex});
115115
}
@@ -166,7 +166,7 @@ DataAdapter::OutputTables XsensDataReader::extendRead(
166166
imu.rotation_format + "\" and delimiter: \"" +
167167
delimiter + "\"");
168168
std::vector<std::string> next_row;
169-
int row_count = 0;
169+
size_t row_count = 0;
170170
while (!(next_row = FileAdapter::getNextLine(
171171
stream, delimiter + "\r"))
172172
.empty()) {
@@ -222,7 +222,6 @@ DataAdapter::OutputTables XsensDataReader::extendRead(
222222
if (found_rot_mat) {
223223
// Create Mat33 then convert into Quaternion
224224
SimTK::Mat33 imu_matrix{SimTK::NaN};
225-
int matrix_entry_index = 0;
226225
imu_matrix[0][0] = OpenSim::IO::stod(
227226
next_row[imu.header.at(rot_mat_h[0])]);
228227
imu_matrix[1][0] = OpenSim::IO::stod(
@@ -254,7 +253,7 @@ DataAdapter::OutputTables XsensDataReader::extendRead(
254253

255254
// Ensure all files have the same size, update rate, and rotation
256255
// format
257-
std::vector<int> line_lengths(imus.size());
256+
std::vector<size_t> line_lengths(imus.size());
258257
std::vector<double> update_rates(imus.size());
259258
std::vector<std::string> rotation_formats(imus.size());
260259

@@ -293,29 +292,30 @@ DataAdapter::OutputTables XsensDataReader::extendRead(
293292
"format!");
294293

295294
// These have all been checked for uniformity
296-
const int n_lines = line_lengths[0];
295+
const size_t n_lines = line_lengths[0];
297296
const double sampling_rate = update_rates[0];
298297
const std::string rotation_format = rotation_formats[0];
299298

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!");
300302
// Will read data into pre-allocated Matrices in-memory rather than
301303
// 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; });
319319

320320
// We use a vector of row indices to transform over the rows (i.e., the time
321321
// steps)
@@ -340,18 +340,15 @@ DataAdapter::OutputTables XsensDataReader::extendRead(
340340
n_imus, SimTK::Vec3(SimTK::NaN));
341341
const bool has_quat = std::all_of(
342342
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;
345344
});
346345
const bool has_euler = std::all_of(
347346
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;
350348
});
351349
const bool has_rot_mat = std::all_of(
352350
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;
355352
});
356353
if (has_acc) {
357354
std::transform(imus.begin(), imus.end(),
@@ -403,7 +400,7 @@ DataAdapter::OutputTables XsensDataReader::extendRead(
403400

404401
const double timeIncrement = 1.0 / sampling_rate;
405402
const auto times =
406-
createVectorLinspaceInterval(n_lines, 0.0, timeIncrement);
403+
createVectorLinspaceInterval(static_cast<int>(n_lines), 0.0, timeIncrement);
407404
// Zero data matrices if the data is not found
408405
if (!has_acc) { linearAccelerationData.resize(0, n_imus); }
409406
if (!has_mag) { magneticHeadingData.resize(0, n_imus); }

0 commit comments

Comments
 (0)