diff --git a/include/Analogs.h b/include/Analogs.h index 911385e8..682138e1 100644 --- a/include/Analogs.h +++ b/include/Analogs.h @@ -21,12 +21,6 @@ class EZC3D_API ezc3d::DataNS::AnalogsNS::Analogs{ /// Analogs(); - /// - /// \brief Create an empty holder for the analogous data preallocating the size of it - /// \param nbSubframes The number of subframes to be in the holder - /// - Analogs(size_t nbSubframes); - //---- STREAM ----// public: @@ -57,6 +51,12 @@ class EZC3D_API ezc3d::DataNS::AnalogsNS::Analogs{ /// size_t nbSubframes() const; + /// + /// \brief Resize the number of subframes. Warning, this function drops data if subframes is downsized + /// \param nbSubframes The number of subframes to be in the holder + /// + void nbSubframes(size_t nbSubframes); + /// /// \brief Get a particular subframe of index idx from the analogous data set /// \param idx The index of the subframe diff --git a/include/Subframe.h b/include/Subframe.h index 4fdca277..48780ad2 100644 --- a/include/Subframe.h +++ b/include/Subframe.h @@ -21,12 +21,6 @@ class EZC3D_API ezc3d::DataNS::AnalogsNS::SubFrame{ /// SubFrame(); - /// - /// \brief Create an empty subframe for analogous data, allocating the number of channels - /// \param nChannels Number of channels in the subframe - /// - SubFrame(size_t nChannels); - //---- STREAM ----// public: @@ -57,6 +51,12 @@ class EZC3D_API ezc3d::DataNS::AnalogsNS::SubFrame{ /// size_t nbChannels() const; + /// + /// \brief Resize the number of channels. Warning, this function drops data if channels are downsized. + /// \param nChannels Number of channels in the subframe + /// + void nbChannels(size_t nChannels); + /// /// \brief Get the index of a analog channel in the subframe /// \param channelName Name of the analog channel diff --git a/src/Analogs.cpp b/src/Analogs.cpp index c621e8db..558304df 100644 --- a/src/Analogs.cpp +++ b/src/Analogs.cpp @@ -14,11 +14,6 @@ ezc3d::DataNS::AnalogsNS::Analogs::Analogs() } -ezc3d::DataNS::AnalogsNS::Analogs::Analogs(size_t nbSubframes) -{ - _subframe.resize(nbSubframes); -} - void ezc3d::DataNS::AnalogsNS::Analogs::print() const { for (size_t i = 0; i < nbSubframes(); ++i){ @@ -40,6 +35,11 @@ size_t ezc3d::DataNS::AnalogsNS::Analogs::nbSubframes() const return _subframe.size(); } +void ezc3d::DataNS::AnalogsNS::Analogs::nbSubframes(size_t nbSubframes) +{ + _subframe.resize(nbSubframes); +} + const ezc3d::DataNS::AnalogsNS::SubFrame& ezc3d::DataNS::AnalogsNS::Analogs::subframe(size_t idx) const { try { diff --git a/src/Data.cpp b/src/Data.cpp index cb30c59f..466f4468 100644 --- a/src/Data.cpp +++ b/src/Data.cpp @@ -58,9 +58,11 @@ ezc3d::DataNS::Data::Data(ezc3d::c3d &file) _frames[j].add(ptsAtAFrame); // modified by pts_tp which is an nonconst ref to internal points // Read analogs - ezc3d::DataNS::AnalogsNS::Analogs analog(file.header().nbAnalogByFrame()); + ezc3d::DataNS::AnalogsNS::Analogs analog; + analog.nbSubframes(file.header().nbAnalogByFrame()); for (size_t k = 0; k < file.header().nbAnalogByFrame(); ++k){ - ezc3d::DataNS::AnalogsNS::SubFrame sub(file.header().nbAnalogs()); + ezc3d::DataNS::AnalogsNS::SubFrame sub; + sub.nbChannels(file.header().nbAnalogs()); for (size_t i = 0; i < file.header().nbAnalogs(); ++i){ ezc3d::DataNS::AnalogsNS::Channel c; c.data(file.readFloat()); diff --git a/src/Subframe.cpp b/src/Subframe.cpp index 92d1595b..d69fb17c 100644 --- a/src/Subframe.cpp +++ b/src/Subframe.cpp @@ -14,11 +14,6 @@ ezc3d::DataNS::AnalogsNS::SubFrame::SubFrame() } -ezc3d::DataNS::AnalogsNS::SubFrame::SubFrame(size_t nChannels) -{ - _channels.resize(nChannels); -} - void ezc3d::DataNS::AnalogsNS::SubFrame::print() const { for (size_t i = 0; i < nbChannels(); ++i){ @@ -38,6 +33,11 @@ size_t ezc3d::DataNS::AnalogsNS::SubFrame::nbChannels() const return _channels.size(); } +void ezc3d::DataNS::AnalogsNS::SubFrame::nbChannels(size_t nChannels) +{ + _channels.resize(nChannels); +} + size_t ezc3d::DataNS::AnalogsNS::SubFrame::channelIdx(const std::string &channelName) const { for (size_t i = 0; i < nbChannels(); ++i) diff --git a/test/test_ezc3d.cpp b/test/test_ezc3d.cpp index 0a05482c..53f7010e 100644 --- a/test/test_ezc3d.cpp +++ b/test/test_ezc3d.cpp @@ -30,6 +30,7 @@ struct c3dTestStruct{ size_t nFrames = SIZE_MAX; size_t nPoints = SIZE_MAX; float nSubframes = -1; + float dummyForByteAlignment = -1; // Because of float precision, 4 bytes must be padded here due to the odd numer of float variables std::vector pointNames; size_t nAnalogs = SIZE_MAX; @@ -705,7 +706,6 @@ TEST(c3dModifier, specificAnalog){ EXPECT_THROW(new_c3d.c3d.analog(frames), std::invalid_argument); // Wrong number of channels - EXPECT_NO_THROW(ezc3d::DataNS::AnalogsNS::SubFrame(0)); for (size_t f = 0; f < new_c3d.nFrames; ++f){ ezc3d::DataNS::Frame frame; ezc3d::DataNS::AnalogsNS::Analogs analogs; @@ -942,7 +942,8 @@ TEST(c3dModifier, addFrames){ ezc3d::DataNS::Frame stupidFrameAnalog; ezc3d::DataNS::AnalogsNS::Analogs stupidAnalogs(new_c3d.c3d.data().frame(0).analogs()); - ezc3d::DataNS::AnalogsNS::SubFrame stupidSubframe(new_c3d.nAnalogs-1); + ezc3d::DataNS::AnalogsNS::SubFrame stupidSubframe; + stupidSubframe.nbChannels(new_c3d.nAnalogs-1); stupidAnalogs.subframe(stupidSubframe); stupidFrameAnalog.add(stupidPoints, stupidAnalogs); EXPECT_THROW(new_c3d.c3d.frame(stupidFrameAnalog), std::runtime_error); // Wrong frame rate for analogs @@ -952,7 +953,8 @@ TEST(c3dModifier, addFrames){ new_c3d.c3d.parameter("ANALOG", analogRate); EXPECT_THROW(new_c3d.c3d.frame(stupidFrameAnalog), std::runtime_error); - ezc3d::DataNS::AnalogsNS::SubFrame notSoStupidSubframe(new_c3d.nAnalogs); + ezc3d::DataNS::AnalogsNS::SubFrame notSoStupidSubframe; + notSoStupidSubframe.nbChannels(new_c3d.nAnalogs); stupidAnalogs.subframe(notSoStupidSubframe, 0); stupidFrameAnalog.add(stupidPoints, stupidAnalogs); EXPECT_NO_THROW(new_c3d.c3d.frame(stupidFrameAnalog));