diff --git a/include/Analogs.h b/include/Analogs.h index 3ab05441..ecf405fa 100644 --- a/include/Analogs.h +++ b/include/Analogs.h @@ -38,7 +38,8 @@ class EZC3D_API ezc3d::DataNS::AnalogsNS::Analogs{ /// /// Write all the subframes to a file by calling sequentially the write method of each subframe /// - void write(std::fstream &f) const; + void write( + std::fstream &f) const; //---- SUBFRAME ----// @@ -55,7 +56,8 @@ class EZC3D_API ezc3d::DataNS::AnalogsNS::Analogs{ /// \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); + void nbSubframes( + size_t nbSubframes); /// /// \brief Get a particular subframe of index idx from the analogous data set @@ -66,7 +68,8 @@ class EZC3D_API ezc3d::DataNS::AnalogsNS::Analogs{ /// /// Throw a std::out_of_range exception if idx is larger than the number of subframes /// - const ezc3d::DataNS::AnalogsNS::SubFrame& subframe(size_t idx) const; + const ezc3d::DataNS::AnalogsNS::SubFrame& subframe( + size_t idx) const; /// /// \brief Get a particular subframe of index idx from the analogous data set in order to be modified by the caller @@ -78,7 +81,8 @@ class EZC3D_API ezc3d::DataNS::AnalogsNS::Analogs{ /// /// Throw a std::out_of_range exception if idx is larger than the number of subframes /// - ezc3d::DataNS::AnalogsNS::SubFrame& subframe(size_t idx); + ezc3d::DataNS::AnalogsNS::SubFrame& subframe( + size_t idx); /// /// \brief Add/replace a subframe to the analogous data set @@ -92,7 +96,9 @@ class EZC3D_API ezc3d::DataNS::AnalogsNS::Analogs{ /// If idx is larger than the number of subframes, it resize the analogous data set accordingly and add the subframe /// where it belongs but leaves the other created subframes empty. /// - void subframe(const ezc3d::DataNS::AnalogsNS::SubFrame& subframe, size_t idx = SIZE_MAX); + void subframe( + const ezc3d::DataNS::AnalogsNS::SubFrame& subframe, + size_t idx = SIZE_MAX); /// /// \brief Get all the subframes from the analogous data set diff --git a/include/Channel.h b/include/Channel.h index 237a826f..8a48a42b 100644 --- a/include/Channel.h +++ b/include/Channel.h @@ -25,7 +25,8 @@ class EZC3D_API ezc3d::DataNS::AnalogsNS::Channel{ /// \brief Copy an analog channel /// \param channel The channel to copy /// - Channel(const ezc3d::DataNS::AnalogsNS::Channel &channel); + Channel( + const ezc3d::DataNS::AnalogsNS::Channel &channel); //---- STREAM ----// @@ -44,7 +45,8 @@ class EZC3D_API ezc3d::DataNS::AnalogsNS::Channel{ /// /// Write the value of the analog data to a file /// - void write(std::fstream &f) const; + void write( + std::fstream &f) const; //---- DATA ----// @@ -61,7 +63,8 @@ class EZC3D_API ezc3d::DataNS::AnalogsNS::Channel{ /// \brief Set the value of the analog data /// \param value The value of the analog data /// - void data(float value); + void data( + float value); /// /// \brief Return if the channel is empty diff --git a/include/Data.h b/include/Data.h index 5a33522b..49c9f57d 100644 --- a/include/Data.h +++ b/include/Data.h @@ -28,8 +28,9 @@ class EZC3D_API ezc3d::DataNS::Data{ /// \param c3d Reference to the c3d to copy the data in /// \param file File to copy the data from /// - Data(ezc3d::c3d &c3d, - std::fstream &file); + Data( + ezc3d::c3d &c3d, + std::fstream &file); //---- STREAM ----// @@ -48,7 +49,8 @@ class EZC3D_API ezc3d::DataNS::Data{ /// /// Write all the data to a file by calling sequentially all the write method for all the frames /// - void write(std::fstream &f) const; + void write( + std::fstream &f) const; //---- FRAME ----// @@ -70,7 +72,8 @@ class EZC3D_API ezc3d::DataNS::Data{ /// /// Throw a std::out_of_range exception if idx is larger than the number of frames /// - const ezc3d::DataNS::Frame& frame(size_t idx) const; + const ezc3d::DataNS::Frame& frame( + size_t idx) const; /// /// \brief Get the frame of index idx in order to be modified by the caller @@ -83,7 +86,8 @@ class EZC3D_API ezc3d::DataNS::Data{ /// Throw a std::out_of_range exception if idx is larger than the number of frames /// /// - ezc3d::DataNS::Frame& frame(size_t idx); + ezc3d::DataNS::Frame& frame( + size_t idx); /// /// \brief Add/replace a frame to the data set @@ -97,7 +101,9 @@ class EZC3D_API ezc3d::DataNS::Data{ /// If idx is outside the data set, it resize the data set accordingly and add the frame where it belongs /// but leaves the other created frames empty. /// - void frame(const ezc3d::DataNS::Frame& frame, size_t idx = SIZE_MAX); + void frame( + const ezc3d::DataNS::Frame& frame, + size_t idx = SIZE_MAX); /// /// \brief Get all the frames from the data set diff --git a/include/Frame.h b/include/Frame.h index 296c4ff2..aa74d865 100644 --- a/include/Frame.h +++ b/include/Frame.h @@ -39,7 +39,8 @@ class EZC3D_API ezc3d::DataNS::Frame{ /// /// Write the frame to a file by calling sequentially the write method for points and analogs /// - void write(std::fstream &f) const; + void write( + std::fstream &f) const; //---- POINTS ----// @@ -88,26 +89,31 @@ class EZC3D_API ezc3d::DataNS::Frame{ /// \brief Add a frame by copying a sent frame /// \param frame The frame to copy /// - void add(const ezc3d::DataNS::Frame &frame); + void add( + const ezc3d::DataNS::Frame &frame); /// /// \brief Add points to a frame /// \param points The 3D points to add /// - void add(const ezc3d::DataNS::Points3dNS::Points &points); + void add( + const ezc3d::DataNS::Points3dNS::Points &points); /// /// \brief Add analogs to a frame /// \param analogs The analogous data to add /// - void add(const ezc3d::DataNS::AnalogsNS::Analogs &analogs); + void add( + const ezc3d::DataNS::AnalogsNS::Analogs &analogs); /// /// \brief Add points and analogs to a frame /// \param points The 3D points to add /// \param analogs The analogous data to add /// - void add(const ezc3d::DataNS::Points3dNS::Points &points, const ezc3d::DataNS::AnalogsNS::Analogs &analogs); + void add( + const ezc3d::DataNS::Points3dNS::Points &points, + const ezc3d::DataNS::AnalogsNS::Analogs &analogs); /// /// \brief Return if the frame is empty diff --git a/include/Group.h b/include/Group.h index 26b864f7..05fa149a 100644 --- a/include/Group.h +++ b/include/Group.h @@ -21,7 +21,9 @@ class EZC3D_API ezc3d::ParametersNS::GroupNS::Group{ /// \param name The name of the group of parameter /// \param description The description of the group of parameter /// - Group(const std::string &name = "", const std::string &description = ""); + Group( + const std::string &name = "", + const std::string &description = ""); //---- STREAM ----// @@ -70,7 +72,7 @@ class EZC3D_API ezc3d::ParametersNS::GroupNS::Group{ /// \brief Set the name of the group /// \param name The name of the group /// - void name(const std::string name); + void name(const std::string& name); /// /// \brief Get the description of the group @@ -82,7 +84,7 @@ class EZC3D_API ezc3d::ParametersNS::GroupNS::Group{ /// \brief Set the description of the group /// \param description The description of the group /// - void description(const std::string description); + void description(const std::string& description); /// /// \brief Get the locking status of the group @@ -111,6 +113,14 @@ class EZC3D_API ezc3d::ParametersNS::GroupNS::Group{ /// size_t nbParameters() const; + /// + /// \brief Return if a parameter of a specific name exists + /// \param parameterName The parameter name to return + /// \return If the parameter exists (true) or not (false) + /// + bool isParameter( + const std::string& parameterName) const; + /// /// \brief Get the index of a parameter in the group /// \param parameterName Name of the parameter @@ -120,7 +130,7 @@ class EZC3D_API ezc3d::ParametersNS::GroupNS::Group{ /// /// Throw a std::invalid_argument if parameterName is not found /// - size_t parameterIdx(std::string parameterName) const; + size_t parameterIdx(const std::string& parameterName) const; /// /// \brief Get a particular parameter of index idx from the group @@ -152,7 +162,8 @@ class EZC3D_API ezc3d::ParametersNS::GroupNS::Group{ /// /// Throw a std::invalid_argument if parameterName is not found /// - const ezc3d::ParametersNS::GroupNS::Parameter& parameter(std::string parameterName) const; + const ezc3d::ParametersNS::GroupNS::Parameter& parameter( + const std::string& parameterName) const; /// /// \brief Get a particular parameter with the name parameterName from the group in the form of a non-const reference. @@ -164,7 +175,8 @@ class EZC3D_API ezc3d::ParametersNS::GroupNS::Group{ /// /// Throw a std::invalid_argument if parameterName is not found /// - ezc3d::ParametersNS::GroupNS::Parameter& parameter(std::string parameterName); + ezc3d::ParametersNS::GroupNS::Parameter& parameter( + const std::string& parameterName); /// /// \brief Add a parameter to the group from a C3D file @@ -174,10 +186,11 @@ class EZC3D_API ezc3d::ParametersNS::GroupNS::Group{ /// \param nbCharInName The number of character of the parameter name /// \return /// - int parameter(c3d &c3d, - const Parameters ¶ms, - std::fstream &file, - int nbCharInName); + int parameter( + c3d &c3d, + const Parameters ¶ms, + std::fstream &file, + int nbCharInName); /// /// \brief Add/replace a parameter to the group @@ -185,7 +198,8 @@ class EZC3D_API ezc3d::ParametersNS::GroupNS::Group{ /// /// If the parameter sent does not exist in the group, it is appended. Otherwise it is replaced /// - void parameter(const ezc3d::ParametersNS::GroupNS::Parameter& parameter); + void parameter( + const ezc3d::ParametersNS::GroupNS::Parameter& parameter); /// /// \brief Get all the parameter from the group diff --git a/include/Header.h b/include/Header.h index 15db91c6..c7304a3c 100644 --- a/include/Header.h +++ b/include/Header.h @@ -26,8 +26,9 @@ class EZC3D_API ezc3d::Header{ /// \param c3d C3D reference to copy the data in /// \param file Already opened fstream file with read access /// - Header(c3d &c3d, - std::fstream &file); + Header( + c3d &c3d, + std::fstream &file); //---- STREAM ----// @@ -42,15 +43,18 @@ class EZC3D_API ezc3d::Header{ /// \param f Already opened fstream file with write access /// \param dataStartPosition Returns the byte where to put the data start parameter /// - void write(std::fstream &f, std::streampos &dataStartPosition) const; + void write( + std::fstream &f, + std::streampos &dataStartPosition) const; /// /// \brief Read and store a header from an opened C3D file /// \param c3d C3D reference to copy the data in /// \param file The file stream already opened with read access /// - void read(c3d &c3d, - std::fstream &file); + void read( + c3d &c3d, + std::fstream &file); //---- HEADER ----// @@ -82,7 +86,9 @@ class EZC3D_API ezc3d::Header{ /// \param file opened file stream to be read /// \return The processor type as specified in the c3d file (83-Intel, 84-DEC, 85-MIPS) /// - PROCESSOR_TYPE readProcessorType(c3d &c3d, std::fstream &file); + PROCESSOR_TYPE readProcessorType( + c3d &c3d, + std::fstream &file); protected: size_t _checksum; ///< Byte 1.2 @@ -132,7 +138,8 @@ class EZC3D_API ezc3d::Header{ /// \brief Set the number of analogs /// \param nbOfAnalogs The number of analogs /// - void nbAnalogs(size_t nbOfAnalogs); + void nbAnalogs( + size_t nbOfAnalogs); /// /// \brief Get the number of recorded analogs @@ -169,7 +176,8 @@ class EZC3D_API ezc3d::Header{ /// \brief Set the first frame /// \param frame /// - void firstFrame(size_t frame); + void firstFrame( + size_t frame); /// /// \brief Get the last frame @@ -181,7 +189,8 @@ class EZC3D_API ezc3d::Header{ /// \brief Set the last frame /// \param frame /// - void lastFrame(size_t frame); + void lastFrame( + size_t frame); protected: size_t _nbMaxInterpGap; ///< Byte 6 @@ -237,7 +246,8 @@ class EZC3D_API ezc3d::Header{ /// \brief Set the number of analog by frame /// \param nbOfAnalogsByFrame The number of analog by frame /// - void nbAnalogByFrame(size_t nbOfAnalogsByFrame); + void nbAnalogByFrame( + size_t nbOfAnalogsByFrame); protected: float _frameRate; ///< Byte 11-12 @@ -255,7 +265,8 @@ class EZC3D_API ezc3d::Header{ /// \brief Set the points frame rate in Hz /// \param pointFrameRate The points frame rate in Hz /// - void frameRate(float pointFrameRate); + void frameRate( + float pointFrameRate); protected: int _emptyBlock1; ///< Byte 13-147 @@ -373,7 +384,8 @@ class EZC3D_API ezc3d::Header{ /// /// Throw a std::out_of_range exception if idx is larger than the number of events /// - float eventsTime(size_t idx) const; + float eventsTime( + size_t idx) const; /// /// \brief Get the display flags @@ -394,7 +406,8 @@ class EZC3D_API ezc3d::Header{ /// /// Throw a std::out_of_range exception if idx is larger than the number of events /// - size_t eventsDisplay(size_t idx) const; + size_t eventsDisplay( + size_t idx) const; /// /// \brief Get the event labels @@ -409,7 +422,8 @@ class EZC3D_API ezc3d::Header{ /// /// Throw a std::out_of_range exception if idx is larger than the number of events /// - const std::string& eventsLabel(size_t idx) const; + const std::string& eventsLabel( + size_t idx) const; }; diff --git a/include/Parameter.h b/include/Parameter.h index fe8bfe24..e9ec3476 100644 --- a/include/Parameter.h +++ b/include/Parameter.h @@ -21,7 +21,9 @@ class EZC3D_API ezc3d::ParametersNS::GroupNS::Parameter{ /// \param name The name of the parameter /// \param description The description of the parameter /// - Parameter(const std::string &name = "", const std::string &description = ""); + Parameter( + const std::string &name = "", + const std::string &description = ""); //---- STREAM ----// @@ -39,7 +41,10 @@ class EZC3D_API ezc3d::ParametersNS::GroupNS::Parameter{ /// /// Write the parameter and its values to a file /// - void write(std::fstream &f, int groupIdx, std::streampos &dataStartPosition) const; + void write( + std::fstream &f, + int groupIdx, + std::streampos &dataStartPosition) const; protected: /// @@ -50,7 +55,10 @@ class EZC3D_API ezc3d::ParametersNS::GroupNS::Parameter{ /// \param cmp Internal variable that keep track where it is in the parameter recursive calls. It should be set to 0 when called the first time. /// \return The internal variable cmp. It should be ignore by the user. /// - size_t writeImbricatedParameter(std::fstream &f, const std::vector &dim, size_t currentIdx=0, size_t cmp=0) const; + size_t writeImbricatedParameter( + std::fstream &f, + const std::vector &dim, + size_t currentIdx=0, size_t cmp=0) const; public: /// @@ -61,10 +69,11 @@ class EZC3D_API ezc3d::ParametersNS::GroupNS::Parameter{ /// \param nbCharInName The number of character of the parameter name /// \return The position in the file of the next Group/Parameter /// - int read(c3d &c3d, - const Parameters ¶ms, - std::fstream &file, - int nbCharInName); + int read( + c3d &c3d, + const Parameters ¶ms, + std::fstream &file, + int nbCharInName); //---- METADATA ----// @@ -85,7 +94,8 @@ class EZC3D_API ezc3d::ParametersNS::GroupNS::Parameter{ /// \brief Set the name of the parameter /// \param name The name of the parameter /// - void name(const std::string name); + void name( + const std::string& name); /// /// \brief Get the description of the parameter @@ -97,7 +107,8 @@ class EZC3D_API ezc3d::ParametersNS::GroupNS::Parameter{ /// \brief Set the description of the parameter /// \param description The description of the parameter /// - void description(const std::string description); + void description( + const std::string& description); /// /// \brief Get the locking status of the parameter @@ -141,7 +152,9 @@ class EZC3D_API ezc3d::ParametersNS::GroupNS::Parameter{ /// equals the dataSize. For example, if dimension == {2, 3, 4}, a consistent dataSize would be /// 24 (2*3*4). /// - bool isDimensionConsistent(size_t dataSize, const std::vector& dimension) const; + bool isDimensionConsistent( + size_t dataSize, + const std::vector& dimension) const; //---- DATA ----// @@ -210,7 +223,8 @@ class EZC3D_API ezc3d::ParametersNS::GroupNS::Parameter{ /// /// Set the scalar value for a parameter assuming this value is an integer. /// - void set(int data); + void set( + int data); /// /// \brief Set the size_t scalar value as integer for the parameter @@ -218,7 +232,8 @@ class EZC3D_API ezc3d::ParametersNS::GroupNS::Parameter{ /// /// Set the scalar value as integer for a parameter assuming this value is an size_t. /// - void set(size_t data); + void set( + size_t data); /// /// \brief Set the integer vector of values for the parameter @@ -229,7 +244,9 @@ class EZC3D_API ezc3d::ParametersNS::GroupNS::Parameter{ /// If no dimension mapping is provided, it assumes to be a scalar if the data is the size of 1 or a vector /// if the data has a size higher than 1. /// - void set(const std::vector& data, const std::vector& dimension = {}); + void set( + const std::vector& data, + const std::vector& dimension = {}); /// /// \brief Set the float scalar value for the parameter @@ -237,7 +254,8 @@ class EZC3D_API ezc3d::ParametersNS::GroupNS::Parameter{ /// /// Set the scalar value for a parameter assuming this value is a float. /// - void set(float data); + void set( + float data); /// /// \brief Set the double scalar value as float for the parameter @@ -245,7 +263,8 @@ class EZC3D_API ezc3d::ParametersNS::GroupNS::Parameter{ /// /// Set the scalar value as a flot for a parameter assuming this value is a double. /// - void set(double data); + void set( + double data); /// /// \brief Set the float vector of values for the parameter @@ -256,13 +275,16 @@ class EZC3D_API ezc3d::ParametersNS::GroupNS::Parameter{ /// If no dimension mapping is provided, it assumes to be a scalar if the data is the size of 1 or a vector /// if the data has a size higher than 1. /// - void set(const std::vector& data, const std::vector& dimension = {}); + void set( + const std::vector& data, + const std::vector& dimension = {}); /// /// \brief Set the single string value for the parameter /// \param data The string data /// - void set(const std::string& data); + void set( + const std::string& data); /// /// \brief Set the vector of strings for the parameter @@ -273,7 +295,9 @@ class EZC3D_API ezc3d::ParametersNS::GroupNS::Parameter{ /// If no dimension mapping is provided, it assumes to be a single string if the data is the size of 1 or a vector /// if the data has a size higher than 1. /// - void set(const std::vector& data, const std::vector& dimension = {}); + void set( + const std::vector& data, + const std::vector& dimension = {}); }; diff --git a/include/Parameters.h b/include/Parameters.h index bc7f0e89..d8a725cd 100644 --- a/include/Parameters.h +++ b/include/Parameters.h @@ -26,8 +26,9 @@ class EZC3D_API ezc3d::ParametersNS::Parameters{ /// \param c3d C3D reference to copy the data in /// \param file Already opened fstream file with read access /// - Parameters(c3d &c3d, - std::fstream &file); + Parameters( + c3d &c3d, + std::fstream &file); protected: /// @@ -47,7 +48,9 @@ class EZC3D_API ezc3d::ParametersNS::Parameters{ /// \param f Already opened fstream file with write access /// \param dataStartPosition Returns the byte where to put the data start parameter /// - void write(std::fstream &f, std::streampos &dataStartPosition) const; + void write( + std::fstream &f, + std::streampos &dataStartPosition) const; //---- PARAMETER METADATA ----// @@ -108,6 +111,14 @@ class EZC3D_API ezc3d::ParametersNS::Parameters{ /// size_t nbGroups() const; + /// + /// \brief Return if a group of a specific name exists + /// \param groupName The group name to return + /// \return If the group exists (true) or not (false) + /// + bool isGroup( + const std::string& groupName) const; + /// /// \brief Get the index of a group in the group holder /// \param groupName Name of the group @@ -117,7 +128,8 @@ class EZC3D_API ezc3d::ParametersNS::Parameters{ /// /// Throw a std::invalid_argument if groupName is not found /// - size_t groupIdx(const std::string& groupName) const; + size_t groupIdx( + const std::string& groupName) const; /// /// \brief Get a particular group of index idx from the group holder @@ -128,7 +140,8 @@ class EZC3D_API ezc3d::ParametersNS::Parameters{ /// /// Throw a std::out_of_range exception if idx is larger than the number of groups /// - const ezc3d::ParametersNS::GroupNS::Group& group(size_t idx) const; + const ezc3d::ParametersNS::GroupNS::Group& group( + size_t idx) const; /// /// \brief Get a particular group of index idx from the group holder in order to be modified by the caller @@ -140,7 +153,8 @@ class EZC3D_API ezc3d::ParametersNS::Parameters{ /// /// Throw a std::out_of_range exception if idx is larger than the number of groups /// - ezc3d::ParametersNS::GroupNS::Group& group(size_t idx); + ezc3d::ParametersNS::GroupNS::Group& group( + size_t idx); /// /// \brief Get a particular group with the name groupName from the group holder @@ -149,7 +163,8 @@ class EZC3D_API ezc3d::ParametersNS::Parameters{ /// /// Throw a std::invalid_argument if groupName is not found /// - const ezc3d::ParametersNS::GroupNS::Group& group(const std::string& groupName) const; + const ezc3d::ParametersNS::GroupNS::Group& group( + const std::string& groupName) const; /// /// \brief Get a particular group with the name groupName from the group holder @@ -158,7 +173,8 @@ class EZC3D_API ezc3d::ParametersNS::Parameters{ /// /// Throw a std::invalid_argument if groupName is not found /// - ezc3d::ParametersNS::GroupNS::Group& group(const std::string& groupName); + ezc3d::ParametersNS::GroupNS::Group& group( + const std::string& groupName); /// /// \brief Add/replace a group in the group holder @@ -166,7 +182,8 @@ class EZC3D_API ezc3d::ParametersNS::Parameters{ /// /// If the group sent does not exist in the group holder, it is appended. Otherwise it is replaced /// - void group(const ezc3d::ParametersNS::GroupNS::Group& group); + void group( + const ezc3d::ParametersNS::GroupNS::Group& group); /// /// \brief Get all groups the group holder with read-only access diff --git a/include/Point.h b/include/Point.h index 52d539c4..deb9867f 100644 --- a/include/Point.h +++ b/include/Point.h @@ -25,7 +25,8 @@ class EZC3D_API ezc3d::DataNS::Points3dNS::Point{ /// \brief Copy a 3D point /// \param point The point to copy /// - Point(const ezc3d::DataNS::Points3dNS::Point& point); + Point( + const ezc3d::DataNS::Points3dNS::Point& point); //---- STREAM ----// @@ -44,7 +45,8 @@ class EZC3D_API ezc3d::DataNS::Points3dNS::Point{ /// /// Write the values of the point to a file /// - void write(std::fstream &f) const; + void write( + std::fstream &f) const; //---- DATA ----// @@ -76,7 +78,8 @@ class EZC3D_API ezc3d::DataNS::Points3dNS::Point{ /// \brief Set the X component of the 3D point /// \param x The X component of the 3d point /// - void x(float x); + void x( + float x); /// /// \brief Get the Y component of the 3D point @@ -88,7 +91,8 @@ class EZC3D_API ezc3d::DataNS::Points3dNS::Point{ /// \brief Set the Y component of the 3D point /// \param y The Y component of the 3d point /// - void y(float y); + void y( + float y); /// /// \brief Get the Z component of the 3D point @@ -100,7 +104,8 @@ class EZC3D_API ezc3d::DataNS::Points3dNS::Point{ /// \brief Set the Z component of the 3D point /// \param z The Z component of the 3d point /// - void z(float z); + void z( + float z); /// /// \brief Get the residual component of the 3D point @@ -112,7 +117,8 @@ class EZC3D_API ezc3d::DataNS::Points3dNS::Point{ /// \brief Set the residualZ component of the 3D point /// \param residual The residual component of the 3d point /// - void residual(float residual); + void residual( + float residual); /// /// \brief Return if the point is empty diff --git a/include/Points.h b/include/Points.h index 2dbc4a6e..527264cf 100644 --- a/include/Points.h +++ b/include/Points.h @@ -25,7 +25,8 @@ class EZC3D_API ezc3d::DataNS::Points3dNS::Points{ /// \brief Create an empty holder for 3D points preallocating the size of it /// \param nbPoints Number of 3D points to be in the holder /// - Points(size_t nbPoints); + Points( + size_t nbPoints); //---- STREAM ----// @@ -44,7 +45,8 @@ class EZC3D_API ezc3d::DataNS::Points3dNS::Points{ /// /// Write all the points to a file by calling sequentially the write method of each point /// - void write(std::fstream &f) const; + void write( + std::fstream &f) const; //---- POINT ----// @@ -64,7 +66,8 @@ class EZC3D_API ezc3d::DataNS::Points3dNS::Points{ /// /// Throw a std::out_of_range exception if idx is larger than the number of frames /// - const ezc3d::DataNS::Points3dNS::Point& point(size_t idx) const; + const ezc3d::DataNS::Points3dNS::Point& point( + size_t idx) const; /// /// \brief Get a particular point of index idx from the 3D points data in order to be modified by the caller @@ -76,7 +79,8 @@ class EZC3D_API ezc3d::DataNS::Points3dNS::Points{ /// /// Throw a std::out_of_range exception if idx is larger than the number of frames /// - ezc3d::DataNS::Points3dNS::Point& point(size_t idx); + ezc3d::DataNS::Points3dNS::Point& point( + size_t idx); /// /// \brief Add/replace a point to the points data set @@ -90,7 +94,9 @@ class EZC3D_API ezc3d::DataNS::Points3dNS::Points{ /// If idx is larger than the number of points, it resize the points accordingly and add the point /// where it belongs but leaves the other created points empty. /// - void point(const ezc3d::DataNS::Points3dNS::Point& point, size_t idx = SIZE_MAX); + void point( + const ezc3d::DataNS::Points3dNS::Point& point, + size_t idx = SIZE_MAX); /// /// \brief Get all the points from the 3D points data diff --git a/include/Subframe.h b/include/Subframe.h index 0533c7b2..d9f6f14c 100644 --- a/include/Subframe.h +++ b/include/Subframe.h @@ -38,7 +38,8 @@ class EZC3D_API ezc3d::DataNS::AnalogsNS::SubFrame{ /// /// Write the subframe to a file by calling sequentially the write method of all of the analog channels /// - void write(std::fstream &f) const; + void write( + std::fstream &f) const; //---- CHANNELS ----// @@ -55,7 +56,8 @@ class EZC3D_API ezc3d::DataNS::AnalogsNS::SubFrame{ /// \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); + void nbChannels( + size_t nChannels); /// /// \brief Get a particular analog channel of index idx from the analogous data @@ -66,7 +68,8 @@ class EZC3D_API ezc3d::DataNS::AnalogsNS::SubFrame{ /// /// Throw a std::out_of_range exception if idx is larger than the number of channels /// - const ezc3d::DataNS::AnalogsNS::Channel& channel(size_t idx) const; + const ezc3d::DataNS::AnalogsNS::Channel& channel( + size_t idx) const; /// /// \brief Get a particular analog channel of index idx from the analogous data with write access @@ -78,7 +81,8 @@ class EZC3D_API ezc3d::DataNS::AnalogsNS::SubFrame{ /// /// Throw a std::out_of_range exception if idx is larger than the number of channels /// - ezc3d::DataNS::AnalogsNS::Channel& channel(size_t idx); + ezc3d::DataNS::AnalogsNS::Channel& channel( + size_t idx); /// /// \brief Add/replace a channel to the analog subframe data set @@ -92,7 +96,9 @@ class EZC3D_API ezc3d::DataNS::AnalogsNS::SubFrame{ /// If idx is larger than the number of channels, it resize the subframe accordingly and add the channel /// where it belongs but leaves the other created channels empty. /// - void channel(const ezc3d::DataNS::AnalogsNS::Channel& channel, size_t idx = SIZE_MAX); + void channel( + const ezc3d::DataNS::AnalogsNS::Channel& channel, + size_t idx = SIZE_MAX); /// /// \brief Get all the analog channels from the analogous data diff --git a/include/ezc3d.h b/include/ezc3d.h index f2a8632e..3e01eda1 100644 --- a/include/ezc3d.h +++ b/include/ezc3d.h @@ -443,7 +443,9 @@ class EZC3D_API ezc3d::c3d { /// /// Throw a std::invalid_argument if the name of the parameter is not specified /// - void parameter(const std::string &groupName, const ezc3d::ParametersNS::GroupNS::Parameter ¶meter); + void parameter( + const std::string &groupName, + const ezc3d::ParametersNS::GroupNS::Parameter ¶meter); /// /// \brief Lock a particular group named groupName @@ -451,7 +453,8 @@ class EZC3D_API ezc3d::c3d { /// /// Throw a std::invalid_argument exception if the group name does not exist /// - void lockGroup(const std::string &groupName); + void lockGroup( + const std::string &groupName); /// /// \brief Unlock a particular group named groupName @@ -459,7 +462,8 @@ class EZC3D_API ezc3d::c3d { /// /// Throw a std::invalid_argument exception if the group name does not exist /// - void unlockGroup(const std::string &groupName); + void unlockGroup( + const std::string &groupName); /// /// \brief Add/replace a frame to the data set @@ -482,7 +486,9 @@ class EZC3D_API ezc3d::c3d { /// Throw a std::runtime_error if at least a point was added to the frame but POINT:RATE is equal to 0 /// and/or if at least an analog data was added to the frame and ANALOG:RATE is equal to 0 /// - void frame(const ezc3d::DataNS::Frame &frame, size_t idx = SIZE_MAX); + void frame( + const ezc3d::DataNS::Frame &frame, + size_t idx = SIZE_MAX); /// /// \brief Create a point to the data set of name name @@ -495,7 +501,8 @@ class EZC3D_API ezc3d::c3d { /// /// Throw the same errors as updateParameter as it calls it after the point is created /// - void point(const std::string &name); + void point( + const std::string &name); /// /// \brief Add a new point to the data set @@ -510,7 +517,9 @@ class EZC3D_API ezc3d::c3d { /// /// Moreover it throws the same errors as updateParameter as it calls it after the point is added /// - void point(const std::string &pointName, const std::vector &frames); + void point( + const std::string &pointName, + const std::vector &frames); /// /// \brief Add a new point to the data set @@ -525,7 +534,9 @@ class EZC3D_API ezc3d::c3d { /// /// Moreover it throws the same errors as updateParameter as it calls it after the point is added /// - void point(const std::vector &pointNames, const std::vector &frames); + void point( + const std::vector &pointNames, + const std::vector &frames); /// /// \brief Create a channel of analog data to the data set of name name @@ -538,7 +549,8 @@ class EZC3D_API ezc3d::c3d { /// /// Throw the same errors as updateParameter as it calls it after the channel is created /// - void analog(const std::string &name); + void analog( + const std::string &name); /// /// \brief Add a new channel to the data set @@ -554,7 +566,9 @@ class EZC3D_API ezc3d::c3d { /// /// Moreover it throws the same errors as updateParameter as it calls it after the channel is added /// - void analog(std::string channelName, const std::vector &frames); + void analog( + std::string channelName, + const std::vector &frames); /// /// \brief Add a new channel to the data set @@ -570,7 +584,9 @@ class EZC3D_API ezc3d::c3d { /// /// Moreover it throws the same errors as updateParameter as it calls it after the channel is added /// - void analog(const std::vector& channelNames, const std::vector &frames); + void analog( + const std::vector& channelNames, + const std::vector &frames); // ---- UPDATER ---- // @@ -588,7 +604,9 @@ class EZC3D_API ezc3d::c3d { /// Throw a std::runtime_error if newPoints or newAnalogs was added while the data set is not empty. /// If you want to add a new point after having data in the data set, you must use the frame method. /// - void updateParameters(const std::vector &newPoints = std::vector(), const std::vector &newAnalogs = std::vector()); + void updateParameters( + const std::vector &newPoints = std::vector(), + const std::vector &newAnalogs = std::vector()); }; diff --git a/src/Analogs.cpp b/src/Analogs.cpp index 05a6694e..bee4864a 100644 --- a/src/Analogs.cpp +++ b/src/Analogs.cpp @@ -9,39 +9,36 @@ #include "Analogs.h" -ezc3d::DataNS::AnalogsNS::Analogs::Analogs() -{ - +ezc3d::DataNS::AnalogsNS::Analogs::Analogs() { } -void ezc3d::DataNS::AnalogsNS::Analogs::print() const -{ - for (size_t i = 0; i < nbSubframes(); ++i){ +void ezc3d::DataNS::AnalogsNS::Analogs::print() const { + for (size_t i = 0; i < nbSubframes(); ++i) { std::cout << "Subframe = " << i << std::endl; subframe(i).print(); std::cout << std::endl; } } -void ezc3d::DataNS::AnalogsNS::Analogs::write(std::fstream &f) const -{ - for (size_t i = 0; i < nbSubframes(); ++i){ +void ezc3d::DataNS::AnalogsNS::Analogs::write( + std::fstream &f) const { + for (size_t i = 0; i < nbSubframes(); ++i) { subframe(i).write(f); } } -size_t ezc3d::DataNS::AnalogsNS::Analogs::nbSubframes() const -{ +size_t ezc3d::DataNS::AnalogsNS::Analogs::nbSubframes() const { return _subframe.size(); } -void ezc3d::DataNS::AnalogsNS::Analogs::nbSubframes(size_t nbSubframes) -{ +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 -{ +const ezc3d::DataNS::AnalogsNS::SubFrame& +ezc3d::DataNS::AnalogsNS::Analogs::subframe( + size_t idx) const { try { return _subframe.at(idx); } catch(std::out_of_range) { @@ -52,8 +49,9 @@ const ezc3d::DataNS::AnalogsNS::SubFrame& ezc3d::DataNS::AnalogsNS::Analogs::sub } } -ezc3d::DataNS::AnalogsNS::SubFrame &ezc3d::DataNS::AnalogsNS::Analogs::subframe(size_t idx) -{ +ezc3d::DataNS::AnalogsNS::SubFrame& +ezc3d::DataNS::AnalogsNS::Analogs::subframe( + size_t idx) { try { return _subframe.at(idx); } catch(std::out_of_range) { @@ -64,26 +62,30 @@ ezc3d::DataNS::AnalogsNS::SubFrame &ezc3d::DataNS::AnalogsNS::Analogs::subframe( } } -void ezc3d::DataNS::AnalogsNS::Analogs::subframe(const ezc3d::DataNS::AnalogsNS::SubFrame& subframe, size_t idx) -{ - if (idx == SIZE_MAX) +void ezc3d::DataNS::AnalogsNS::Analogs::subframe( + const ezc3d::DataNS::AnalogsNS::SubFrame& subframe, + size_t idx) { + if (idx == SIZE_MAX) { _subframe.push_back(subframe); - else{ - if (idx >= nbSubframes()) + } + else { + if (idx >= nbSubframes()) { _subframe.resize(idx+1); + } _subframe[idx] = subframe; } } -const std::vector &ezc3d::DataNS::AnalogsNS::Analogs::subframes() const -{ +const std::vector& +ezc3d::DataNS::AnalogsNS::Analogs::subframes() const { return _subframe; } -bool ezc3d::DataNS::AnalogsNS::Analogs::isempty() const -{ - for (SubFrame subframe : subframes()) - if (!subframe.isempty()) +bool ezc3d::DataNS::AnalogsNS::Analogs::isempty() const { + for (SubFrame subframe : subframes()) { + if (!subframe.isempty()) { return false; + } + } return true; } diff --git a/src/Channel.cpp b/src/Channel.cpp index 9b6fd668..8aa3a8c5 100644 --- a/src/Channel.cpp +++ b/src/Channel.cpp @@ -9,41 +9,36 @@ #include "Channel.h" -ezc3d::DataNS::AnalogsNS::Channel::Channel() -{ +ezc3d::DataNS::AnalogsNS::Channel::Channel() { } -ezc3d::DataNS::AnalogsNS::Channel::Channel(const ezc3d::DataNS::AnalogsNS::Channel &channel) : - _data(channel._data) -{ - +ezc3d::DataNS::AnalogsNS::Channel::Channel( + const ezc3d::DataNS::AnalogsNS::Channel &channel) : + _data(channel._data) { } -void ezc3d::DataNS::AnalogsNS::Channel::print() const -{ +void ezc3d::DataNS::AnalogsNS::Channel::print() const { std::cout << "Analog = " << data() << std::endl; } -void ezc3d::DataNS::AnalogsNS::Channel::write(std::fstream &f) const -{ +void ezc3d::DataNS::AnalogsNS::Channel::write(std::fstream &f) const { f.write(reinterpret_cast(&_data), ezc3d::DATA_TYPE::FLOAT); } -float ezc3d::DataNS::AnalogsNS::Channel::data() const -{ +float ezc3d::DataNS::AnalogsNS::Channel::data() const { return _data; } -void ezc3d::DataNS::AnalogsNS::Channel::data(float v) -{ +void ezc3d::DataNS::AnalogsNS::Channel::data(float v) { _data = v; } -bool ezc3d::DataNS::AnalogsNS::Channel::isempty() const -{ - if (static_cast(data()) == 0.0) +bool ezc3d::DataNS::AnalogsNS::Channel::isempty() const { + if (static_cast(data()) == 0.0) { return true; - else + } + else { return false; + } } diff --git a/src/Data.cpp b/src/Data.cpp index 9b220da7..2a84eff6 100644 --- a/src/Data.cpp +++ b/src/Data.cpp @@ -11,41 +11,53 @@ #include "Header.h" #include "Parameters.h" -ezc3d::DataNS::Data::Data() -{ - +ezc3d::DataNS::Data::Data() { } -ezc3d::DataNS::Data::Data(ezc3d::c3d &c3d, std::fstream &file) -{ +ezc3d::DataNS::Data::Data( + ezc3d::c3d &c3d, std::fstream &file) { // Firstly move the pointer to the data start position - file.seekg( static_cast(c3d.header().dataStart()-1)*512, std::ios::beg); + file.seekg(static_cast(c3d.header().dataStart()-1)*512, std::ios::beg); // Get names of the data std::vector pointNames; if (c3d.header().nb3dPoints() > 0) - pointNames = c3d.parameters().group("POINT").parameter("LABELS").valuesAsString(); + pointNames = c3d.parameters() + .group("POINT").parameter("LABELS") + .valuesAsString(); std::vector analogNames; if (c3d.header().nbAnalogs() > 0) - analogNames = c3d.parameters().group("ANALOG").parameter("LABELS").valuesAsString(); + analogNames = c3d.parameters() + .group("ANALOG").parameter("LABELS") + .valuesAsString(); // Read the data PROCESSOR_TYPE processorType(c3d.parameters().processorType()); float pointScaleFactor(-1); if (c3d.header().nb3dPoints()) - pointScaleFactor = c3d.parameters().group("POINT").parameter("SCALE").valuesAsFloat()[0]; + pointScaleFactor = c3d.parameters() + .group("POINT").parameter("SCALE") + .valuesAsFloat()[0]; std::vector analogScaleFactors; if (c3d.header().nbAnalogs()) - analogScaleFactors = c3d.parameters().group("ANALOG").parameter("SCALE").valuesAsFloat(); - float analogGeneralFactor(c3d.parameters().group("ANALOG").parameter("GEN_SCALE").valuesAsFloat()[0]); - std::vector analogZeroOffset(c3d.parameters().group("ANALOG").parameter("OFFSET").valuesAsInt()); + analogScaleFactors = c3d.parameters() + .group("ANALOG").parameter("SCALE") + .valuesAsFloat(); + float analogGeneralFactor(c3d.parameters() + .group("ANALOG").parameter("GEN_SCALE") + .valuesAsFloat()[0]); + std::vector analogZeroOffset( + c3d.parameters() + .group("ANALOG").parameter("OFFSET") + .valuesAsInt()); for (size_t j = 0; j < c3d.header().nbFrames(); ++j){ if (file.eof()) break; ezc3d::DataNS::Frame f; // Read point 3d - ezc3d::DataNS::Points3dNS::Points ptsAtAFrame(c3d.header().nb3dPoints()); + ezc3d::DataNS::Points3dNS::Points ptsAtAFrame( + c3d.header().nb3dPoints()); for (size_t i = 0; i < c3d.header().nb3dPoints(); ++i){ ezc3d::DataNS::Points3dNS::Point pt; if (c3d.header().scaleFactor() < 0){ // if it is float @@ -54,14 +66,27 @@ ezc3d::DataNS::Data::Data(ezc3d::c3d &c3d, std::fstream &file) pt.z(c3d.readFloat(processorType, file)); pt.residual(c3d.readFloat(processorType, file)); } else { - pt.x(static_cast(c3d.readInt(processorType, file, ezc3d::DATA_TYPE::WORD)) * pointScaleFactor); - pt.y(static_cast(c3d.readInt(processorType, file, ezc3d::DATA_TYPE::WORD)) * pointScaleFactor); - pt.z(static_cast(c3d.readInt(processorType, file, ezc3d::DATA_TYPE::WORD)) * pointScaleFactor); - pt.residual(static_cast(c3d.readInt(processorType, file, ezc3d::DATA_TYPE::WORD)) * pointScaleFactor); + pt.x(static_cast( + c3d.readInt( + processorType, file, ezc3d::DATA_TYPE::WORD)) + * pointScaleFactor); + pt.y(static_cast( + c3d.readInt( + processorType, file, ezc3d::DATA_TYPE::WORD)) + * pointScaleFactor); + pt.z(static_cast( + c3d.readInt( + processorType, file, ezc3d::DATA_TYPE::WORD)) + * pointScaleFactor); + pt.residual(static_cast( + c3d.readInt(processorType, + file, ezc3d::DATA_TYPE::WORD)) + * pointScaleFactor); } ptsAtAFrame.point(pt, i); } - f.add(ptsAtAFrame); // modified by pts_tp which is an nonconst ref to internal points + // modified by pts_tp which is an nonconst ref to internal points + f.add(ptsAtAFrame); // Read analogs ezc3d::DataNS::AnalogsNS::Analogs analog; @@ -72,9 +97,15 @@ ezc3d::DataNS::Data::Data(ezc3d::c3d &c3d, std::fstream &file) for (size_t i = 0; i < c3d.header().nbAnalogs(); ++i){ ezc3d::DataNS::AnalogsNS::Channel c; if (c3d.header().scaleFactor() < 0) // if it is float - c.data( (c3d.readFloat(processorType, file) - analogZeroOffset[i]) * analogScaleFactors[i] * analogGeneralFactor ); + c.data( (c3d.readFloat(processorType, file) + - analogZeroOffset[i]) + * analogScaleFactors[i] * analogGeneralFactor ); else - c.data( (static_cast(c3d.readInt(processorType, file, ezc3d::DATA_TYPE::WORD)) - analogZeroOffset[i]) * analogScaleFactors[i] * analogGeneralFactor ); // * scaleFactor); + c.data( (static_cast( + c3d.readInt(processorType, file, + ezc3d::DATA_TYPE::WORD)) + - analogZeroOffset[i]) + * analogScaleFactors[i] * analogGeneralFactor ); sub.channel(c, i); } analog.subframe(sub, k); @@ -86,7 +117,8 @@ ezc3d::DataNS::Data::Data(ezc3d::c3d &c3d, std::fstream &file) // remove the trailing empty frames if they exist size_t nFrames(_frames.size()); if (nFrames > 0) - for (size_t i=0; i &ezc3d::DataNS::Data::frames() const -{ +const std::vector &ezc3d::DataNS::Data::frames() const { return _frames; } diff --git a/src/Frame.cpp b/src/Frame.cpp index 578de52f..66773b69 100644 --- a/src/Frame.cpp +++ b/src/Frame.cpp @@ -9,66 +9,64 @@ #include "Frame.h" -ezc3d::DataNS::Frame::Frame() -{ - _points = std::shared_ptr(new ezc3d::DataNS::Points3dNS::Points()); - _analogs = std::shared_ptr(new ezc3d::DataNS::AnalogsNS::Analogs()); +ezc3d::DataNS::Frame::Frame() { + _points = std::shared_ptr( + new ezc3d::DataNS::Points3dNS::Points()); + _analogs = std::shared_ptr( + new ezc3d::DataNS::AnalogsNS::Analogs()); } -void ezc3d::DataNS::Frame::print() const -{ +void ezc3d::DataNS::Frame::print() const { points().print(); analogs().print(); } -void ezc3d::DataNS::Frame::write(std::fstream &f) const -{ +void ezc3d::DataNS::Frame::write( + std::fstream &f) const { points().write(f); analogs().write(f); } -const ezc3d::DataNS::Points3dNS::Points& ezc3d::DataNS::Frame::points() const -{ +const ezc3d::DataNS::Points3dNS::Points& ezc3d::DataNS::Frame::points() const { return *_points; } -ezc3d::DataNS::Points3dNS::Points &ezc3d::DataNS::Frame::points() -{ +ezc3d::DataNS::Points3dNS::Points &ezc3d::DataNS::Frame::points() { return *_points; } -const ezc3d::DataNS::AnalogsNS::Analogs& ezc3d::DataNS::Frame::analogs() const -{ +const ezc3d::DataNS::AnalogsNS::Analogs& ezc3d::DataNS::Frame::analogs() const { return *_analogs; } -ezc3d::DataNS::AnalogsNS::Analogs &ezc3d::DataNS::Frame::analogs() -{ +ezc3d::DataNS::AnalogsNS::Analogs &ezc3d::DataNS::Frame::analogs() { return *_analogs; } -void ezc3d::DataNS::Frame::add(const ezc3d::DataNS::Frame &frame) -{ +void ezc3d::DataNS::Frame::add( + const ezc3d::DataNS::Frame &frame) { add(frame.points(), frame.analogs()); } -void ezc3d::DataNS::Frame::add(const ezc3d::DataNS::Points3dNS::Points &point3d_frame) -{ - _points = std::shared_ptr(new ezc3d::DataNS::Points3dNS::Points(point3d_frame)); +void ezc3d::DataNS::Frame::add( + const ezc3d::DataNS::Points3dNS::Points &point3d_frame) { + _points = std::shared_ptr( + new ezc3d::DataNS::Points3dNS::Points(point3d_frame)); } -void ezc3d::DataNS::Frame::add(const ezc3d::DataNS::AnalogsNS::Analogs &analogs_frame) -{ - _analogs = std::shared_ptr(new ezc3d::DataNS::AnalogsNS::Analogs(analogs_frame)); +void ezc3d::DataNS::Frame::add( + const ezc3d::DataNS::AnalogsNS::Analogs &analogs_frame) { + _analogs = std::shared_ptr( + new ezc3d::DataNS::AnalogsNS::Analogs(analogs_frame)); } -void ezc3d::DataNS::Frame::add(const ezc3d::DataNS::Points3dNS::Points &point3d_frame, const ezc3d::DataNS::AnalogsNS::Analogs &analog_frame) -{ +void ezc3d::DataNS::Frame::add( + const ezc3d::DataNS::Points3dNS::Points &point3d_frame, + const ezc3d::DataNS::AnalogsNS::Analogs &analog_frame) { add(point3d_frame); add(analog_frame); } -bool ezc3d::DataNS::Frame::isempty() const -{ +bool ezc3d::DataNS::Frame::isempty() const { return points().isempty() && analogs().isempty(); } diff --git a/src/Group.cpp b/src/Group.cpp index caa3e494..34a5ab7b 100644 --- a/src/Group.cpp +++ b/src/Group.cpp @@ -10,16 +10,16 @@ #include "Group.h" #include "Parameters.h" -ezc3d::ParametersNS::GroupNS::Group::Group(const std::string &name, const std::string &description) : +ezc3d::ParametersNS::GroupNS::Group::Group( + const std::string &name, + const std::string &description) : _name(name), _description(description), - _isLocked(false) -{ + _isLocked(false) { } -void ezc3d::ParametersNS::GroupNS::Group::print() const -{ +void ezc3d::ParametersNS::GroupNS::Group::print() const { std::cout << "groupName = " << name() << std::endl; std::cout << "isLocked = " << isLocked() << std::endl; std::cout << "desc = " << description() << std::endl; @@ -30,31 +30,38 @@ void ezc3d::ParametersNS::GroupNS::Group::print() const } } -void ezc3d::ParametersNS::GroupNS::Group::write(std::fstream &f, int groupIdx, std::streampos &dataStartPosition) const -{ +void ezc3d::ParametersNS::GroupNS::Group::write( + std::fstream &f, + int groupIdx, + std::streampos &dataStartPosition) const { int nCharName(static_cast(name().size())); if (isLocked()) nCharName *= -1; - f.write(reinterpret_cast(&nCharName), 1*ezc3d::DATA_TYPE::BYTE); + f.write(reinterpret_cast(&nCharName), + 1*ezc3d::DATA_TYPE::BYTE); if (isLocked()) nCharName *= -1; f.write(reinterpret_cast(&groupIdx), 1*ezc3d::DATA_TYPE::BYTE); f.write(ezc3d::toUpper(name()).c_str(), nCharName*ezc3d::DATA_TYPE::BYTE); - // It is not possible already to know in how many bytes the next parameter is + // It is not possible already to know in + // how many bytes the next parameter is int blank(0); std::streampos pos(f.tellg()); f.write(reinterpret_cast(&blank), 2*ezc3d::DATA_TYPE::BYTE); int nCharGroupDescription(static_cast(description().size())); - f.write(reinterpret_cast(&nCharGroupDescription), 1*ezc3d::DATA_TYPE::BYTE); - f.write(description().c_str(), nCharGroupDescription*ezc3d::DATA_TYPE::BYTE); + f.write(reinterpret_cast(&nCharGroupDescription), + 1*ezc3d::DATA_TYPE::BYTE); + f.write(description().c_str(), + nCharGroupDescription*ezc3d::DATA_TYPE::BYTE); std::streampos currentPos(f.tellg()); // Go back at the left blank space and write the current position f.seekg(pos); int nCharToNext = int(currentPos - pos); - f.write(reinterpret_cast(&nCharToNext), 2*ezc3d::DATA_TYPE::BYTE); + f.write(reinterpret_cast(&nCharToNext), + 2*ezc3d::DATA_TYPE::BYTE); f.seekg(currentPos); std::streampos defaultDataStartPosition(-1); @@ -65,128 +72,158 @@ void ezc3d::ParametersNS::GroupNS::Group::write(std::fstream &f, int groupIdx, s parameter(i).write(f, -groupIdx, defaultDataStartPosition); } -int ezc3d::ParametersNS::GroupNS::Group::read(ezc3d::c3d &c3d, const ezc3d::ParametersNS::Parameters ¶ms, - std::fstream &file, int nbCharInName) -{ +int ezc3d::ParametersNS::GroupNS::Group::read( + ezc3d::c3d &c3d, + const ezc3d::ParametersNS::Parameters ¶ms, + std::fstream &file, int nbCharInName) { if (nbCharInName < 0) _isLocked = true; else _isLocked = false; // Read name of the group - _name.assign(c3d.readString(file, static_cast(abs(nbCharInName) * ezc3d::DATA_TYPE::BYTE))); + _name.assign( + c3d.readString( + file, static_cast( + abs(nbCharInName) * ezc3d::DATA_TYPE::BYTE))); // number of byte to the next group from here - size_t offsetNext(c3d.readUint(params.processorType(), file, 2*ezc3d::DATA_TYPE::BYTE)); + size_t offsetNext( + c3d.readUint( + params.processorType(), file, 2*ezc3d::DATA_TYPE::BYTE)); // Compute the position of the element in the file int nextParamByteInFile; if (offsetNext == 0) nextParamByteInFile = 0; else - nextParamByteInFile = static_cast(static_cast(file.tellg()) + offsetNext - ezc3d::DATA_TYPE::WORD); + nextParamByteInFile = static_cast( + static_cast( + file.tellg()) + offsetNext - ezc3d::DATA_TYPE::WORD); // Byte 5+nbCharInName ==> Number of characters in group description - int nbCharInDesc(c3d.readInt(params.processorType(), file, 1*ezc3d::DATA_TYPE::BYTE)); + int nbCharInDesc( + c3d.readInt( + params.processorType(), file, 1*ezc3d::DATA_TYPE::BYTE)); // Byte 6+nbCharInName ==> Group description if (nbCharInDesc) - _description = c3d.readString(file, static_cast(nbCharInDesc)); + _description = c3d.readString( + file, static_cast(nbCharInDesc)); // Return how many bytes return nextParamByteInFile; } -const std::string& ezc3d::ParametersNS::GroupNS::Group::name() const -{ +const std::string& ezc3d::ParametersNS::GroupNS::Group::name() const { return _name; } -void ezc3d::ParametersNS::GroupNS::Group::name(const std::string name) -{ +void ezc3d::ParametersNS::GroupNS::Group::name( + const std::string &name) { _name = name; } -const std::string& ezc3d::ParametersNS::GroupNS::Group::description() const -{ +const std::string& ezc3d::ParametersNS::GroupNS::Group::description() const { return _description; } -void ezc3d::ParametersNS::GroupNS::Group::description(const std::string description) -{ +void ezc3d::ParametersNS::GroupNS::Group::description( + const std::string &description) { _description = description; } -bool ezc3d::ParametersNS::GroupNS::Group::isLocked() const -{ +bool ezc3d::ParametersNS::GroupNS::Group::isLocked() const { return _isLocked; } -void ezc3d::ParametersNS::GroupNS::Group::lock() -{ +void ezc3d::ParametersNS::GroupNS::Group::lock() { _isLocked = true; } -void ezc3d::ParametersNS::GroupNS::Group::unlock() -{ +void ezc3d::ParametersNS::GroupNS::Group::unlock() { _isLocked = false; } -size_t ezc3d::ParametersNS::GroupNS::Group::nbParameters() const -{ +size_t ezc3d::ParametersNS::GroupNS::Group::nbParameters() const { return _parameters.size(); } -size_t ezc3d::ParametersNS::GroupNS::Group::parameterIdx(std::string parameterName) const +bool ezc3d::ParametersNS::GroupNS::Group::isParameter( + const std::string ¶meterName) const { + try { + parameterIdx(parameterName); + return true; + } catch (std::invalid_argument) { + return false; + } +} + +size_t ezc3d::ParametersNS::GroupNS::Group::parameterIdx( + const std::string ¶meterName) const { for (size_t i = 0; i < nbParameters(); ++i) if (!parameter(i).name().compare(parameterName)) return i; - throw std::invalid_argument("Group::parameterIdx could not find " + parameterName + - " in the group " + name()); + throw std::invalid_argument( + "Group::parameterIdx could not find " + + parameterName + " in the group " + name()); } -const ezc3d::ParametersNS::GroupNS::Parameter &ezc3d::ParametersNS::GroupNS::Group::parameter(size_t idx) const -{ +const ezc3d::ParametersNS::GroupNS::Parameter +&ezc3d::ParametersNS::GroupNS::Group::parameter( + size_t idx) const { try { return _parameters.at(idx); } catch(std::out_of_range) { - throw std::out_of_range("Groups::parameter method is trying to access the parameter " - + std::to_string(idx) + - " while the maximum number of parameter is " - + std::to_string(nbParameters()) + " in the group " + name() + "."); + throw std::out_of_range( + "Groups::parameter method is trying " + "to access the parameter " + + std::to_string(idx) + + " while the maximum number of parameter is " + + std::to_string(nbParameters()) + + " in the group " + name() + "."); } } -ezc3d::ParametersNS::GroupNS::Parameter &ezc3d::ParametersNS::GroupNS::Group::parameter(size_t idx) -{ +ezc3d::ParametersNS::GroupNS::Parameter +&ezc3d::ParametersNS::GroupNS::Group::parameter( + size_t idx) { try { return _parameters.at(idx); } catch(std::out_of_range) { - throw std::out_of_range("Groups::parameter method is trying to access the parameter " - + std::to_string(idx) + - " while the maximum number of parameters is " - + std::to_string(nbParameters()) + " in the group " + name() + "."); + throw std::out_of_range( + "Groups::parameter method is trying " + "to access the parameter " + + std::to_string(idx) + + " while the maximum number of parameters is " + + std::to_string(nbParameters()) + + " in the group " + name() + "."); } } -const ezc3d::ParametersNS::GroupNS::Parameter &ezc3d::ParametersNS::GroupNS::Group::parameter(std::string parameterName) const -{ +const ezc3d::ParametersNS::GroupNS::Parameter +&ezc3d::ParametersNS::GroupNS::Group::parameter( + const std::string ¶meterName) const { return parameter(parameterIdx(parameterName)); } -ezc3d::ParametersNS::GroupNS::Parameter &ezc3d::ParametersNS::GroupNS::Group::parameter(std::string parameterName) -{ +ezc3d::ParametersNS::GroupNS::Parameter +&ezc3d::ParametersNS::GroupNS::Group::parameter( + const std::string ¶meterName) { return parameter(parameterIdx(parameterName)); } -int ezc3d::ParametersNS::GroupNS::Group::parameter(ezc3d::c3d &c3d, const Parameters ¶ms, std::fstream &file, int nbCharInName) -{ +int ezc3d::ParametersNS::GroupNS::Group::parameter( + ezc3d::c3d &c3d, + const Parameters ¶ms, + std::fstream &file, + int nbCharInName) { ezc3d::ParametersNS::GroupNS::Parameter p; int nextParamByteInFile = p.read(c3d, params, file, nbCharInName); parameter(p); return nextParamByteInFile; } -void ezc3d::ParametersNS::GroupNS::Group::parameter(const ezc3d::ParametersNS::GroupNS::Parameter &p) -{ +void ezc3d::ParametersNS::GroupNS::Group::parameter( + const ezc3d::ParametersNS::GroupNS::Parameter &p) { if (p.type() == ezc3d::DATA_TYPE::NO_DATA_TYPE) throw std::runtime_error("Data type is not set"); @@ -202,7 +239,7 @@ void ezc3d::ParametersNS::GroupNS::Group::parameter(const ezc3d::ParametersNS::G _parameters[alreadyExistIdx] = p; } -const std::vector &ezc3d::ParametersNS::GroupNS::Group::parameters() const -{ +const std::vector +&ezc3d::ParametersNS::GroupNS::Group::parameters() const { return _parameters; } diff --git a/src/Header.cpp b/src/Header.cpp index 1de55772..ba79aeb0 100644 --- a/src/Header.cpp +++ b/src/Header.cpp @@ -30,14 +30,15 @@ ezc3d::Header::Header(): _keyLabelPresent(0), _firstBlockKeyLabel(0), _fourCharPresent(0x3039), - _nbEvents(0) -{ + _nbEvents(0) { _eventsTime.resize(18); _eventsDisplay.resize(9); _eventsLabel.resize(18); } -ezc3d::Header::Header(ezc3d::c3d &c3d, std::fstream &file) : +ezc3d::Header::Header( + ezc3d::c3d &c3d, + std::fstream &file) : _nbOfZerosBeforeHeader(0), _parametersAddress(2), _checksum(0), @@ -57,18 +58,18 @@ ezc3d::Header::Header(ezc3d::c3d &c3d, std::fstream &file) : _keyLabelPresent(0), _firstBlockKeyLabel(0), _fourCharPresent(0x3039), - _nbEvents(0) -{ + _nbEvents(0) { _eventsTime.resize(18); _eventsDisplay.resize(9); _eventsLabel.resize(18); read(c3d, file); } -void ezc3d::Header::print() const{ +void ezc3d::Header::print() const { std::cout << "HEADER" << std::endl; std::cout << "nb3dPoints = " << nb3dPoints() << std::endl; - std::cout << "nbAnalogsMeasurement = " << nbAnalogsMeasurement() << std::endl; + std::cout << "nbAnalogsMeasurement = " + << nbAnalogsMeasurement() << std::endl; std::cout << "nbAnalogs = " << nbAnalogs() << std::endl; std::cout << "firstFrame = " << firstFrame() << std::endl; std::cout << "lastFrame = " << lastFrame() << std::endl; @@ -83,83 +84,114 @@ void ezc3d::Header::print() const{ std::cout << "fourCharPresent = " << fourCharPresent() << std::endl; std::cout << "nbEvents = " << nbEvents() << std::endl; for (size_t i=0; i < eventsTime().size(); ++i) - std::cout << "eventsTime[" << i << "] = " << eventsTime(i) << std::endl; + std::cout << "eventsTime[" << i << "] = " + << eventsTime(i) << std::endl; for (size_t i=0; i < eventsDisplay().size(); ++i) - std::cout << "eventsDisplay[" << i << "] = " << eventsDisplay(i) << std::endl; + std::cout << "eventsDisplay[" << i << "] = " + << eventsDisplay(i) << std::endl; for (size_t i=0; i < eventsLabel().size(); ++i) - std::cout << "eventsLabel[" << i << "] = " << eventsLabel(i) << std::endl; + std::cout << "eventsLabel[" << i << "] = " + << eventsLabel(i) << std::endl; std::cout << std::endl; } -void ezc3d::Header::write(std::fstream &f, std::streampos &dataStartPosition) const -{ +void ezc3d::Header::write( + std::fstream &f, + std::streampos &dataStartPosition) const { // write the checksum byte and the start point of header int parameterAddessDefault(2); - f.write(reinterpret_cast(¶meterAddessDefault), ezc3d::BYTE); + f.write(reinterpret_cast( + ¶meterAddessDefault), ezc3d::BYTE); int checksum(0x50); f.write(reinterpret_cast(&checksum), ezc3d::BYTE); // Number of data - f.write(reinterpret_cast(&_nb3dPoints), 1*ezc3d::DATA_TYPE::WORD); - f.write(reinterpret_cast(&_nbAnalogsMeasurement), 1*ezc3d::DATA_TYPE::WORD); + f.write(reinterpret_cast(&_nb3dPoints), + 1*ezc3d::DATA_TYPE::WORD); + f.write(reinterpret_cast(&_nbAnalogsMeasurement), + 1*ezc3d::DATA_TYPE::WORD); // Idx of first and last frame size_t firstFrame(_firstFrame + 1); // 1-based! size_t lastFrame(_lastFrame + 1); // 1-based! if (lastFrame > 0xFFFF) - lastFrame = 0xFFFF; // Combine this with group("POINT").parameter("FRAMES") = -1 - f.write(reinterpret_cast(&firstFrame), 1*ezc3d::DATA_TYPE::WORD); - f.write(reinterpret_cast(&lastFrame), 1*ezc3d::DATA_TYPE::WORD); + // Combine this with group("POINT").parameter("FRAMES") = -1 + lastFrame = 0xFFFF; + f.write(reinterpret_cast(&firstFrame), + 1*ezc3d::DATA_TYPE::WORD); + f.write(reinterpret_cast(&lastFrame), + 1*ezc3d::DATA_TYPE::WORD); // Some info - f.write(reinterpret_cast(&_nbMaxInterpGap), 1*ezc3d::DATA_TYPE::WORD); - f.write(reinterpret_cast(&_scaleFactor), 2*ezc3d::DATA_TYPE::WORD); + f.write(reinterpret_cast(&_nbMaxInterpGap), + 1*ezc3d::DATA_TYPE::WORD); + f.write(reinterpret_cast(&_scaleFactor), + 2*ezc3d::DATA_TYPE::WORD); // Parameters of analog data dataStartPosition = f.tellg(); - f.write(reinterpret_cast(&_dataStart), 1*ezc3d::DATA_TYPE::WORD); // To be changed when we know where the data are - f.write(reinterpret_cast(&_nbAnalogByFrame), 1*ezc3d::DATA_TYPE::WORD); + // dataStartPosition is to be changed when we know where the data are + f.write(reinterpret_cast(&_dataStart), + 1*ezc3d::DATA_TYPE::WORD); + f.write(reinterpret_cast(&_nbAnalogByFrame), + 1*ezc3d::DATA_TYPE::WORD); float frameRate(_frameRate); - f.write(reinterpret_cast(&frameRate), 2*ezc3d::DATA_TYPE::WORD); + f.write(reinterpret_cast(&frameRate), + 2*ezc3d::DATA_TYPE::WORD); for (int i=0; i<135; ++i) - f.write(reinterpret_cast(&_emptyBlock1), 1*ezc3d::DATA_TYPE::WORD); + f.write(reinterpret_cast(&_emptyBlock1), + 1*ezc3d::DATA_TYPE::WORD); // Parameters of keys - f.write(reinterpret_cast(&_keyLabelPresent), 1*ezc3d::DATA_TYPE::WORD); - f.write(reinterpret_cast(&_firstBlockKeyLabel), 1*ezc3d::DATA_TYPE::WORD); - f.write(reinterpret_cast(&_fourCharPresent), 1*ezc3d::DATA_TYPE::WORD); + f.write(reinterpret_cast(&_keyLabelPresent), + 1*ezc3d::DATA_TYPE::WORD); + f.write(reinterpret_cast(&_firstBlockKeyLabel), + 1*ezc3d::DATA_TYPE::WORD); + f.write(reinterpret_cast(&_fourCharPresent), + 1*ezc3d::DATA_TYPE::WORD); // Parameters of events - f.write(reinterpret_cast(&_nbEvents), 1*ezc3d::DATA_TYPE::WORD); - f.write(reinterpret_cast(&_emptyBlock2), 1*ezc3d::DATA_TYPE::WORD); + f.write(reinterpret_cast(&_nbEvents), + 1*ezc3d::DATA_TYPE::WORD); + f.write(reinterpret_cast(&_emptyBlock2), + 1*ezc3d::DATA_TYPE::WORD); for (unsigned int i = 0; i < _eventsTime.size(); ++i) - f.write(reinterpret_cast(&_eventsTime[i]), 2*ezc3d::DATA_TYPE::WORD); + f.write(reinterpret_cast(&_eventsTime[i]), + 2*ezc3d::DATA_TYPE::WORD); for (unsigned int i = 0; i < _eventsDisplay.size(); ++i) - f.write(reinterpret_cast(&_eventsDisplay[i]), 1*ezc3d::DATA_TYPE::WORD); - f.write(reinterpret_cast(&_emptyBlock3), 1*ezc3d::DATA_TYPE::WORD); + f.write(reinterpret_cast(&_eventsDisplay[i]), + 1*ezc3d::DATA_TYPE::WORD); + f.write(reinterpret_cast(&_emptyBlock3), + 1*ezc3d::DATA_TYPE::WORD); for (unsigned int i = 0; i < _eventsLabel.size(); ++i){ const char* event = _eventsLabel[i].c_str(); f.write(event, 2*ezc3d::DATA_TYPE::WORD); } for (int i=0; i<22; ++i) - f.write(reinterpret_cast(&_emptyBlock4), 1*ezc3d::DATA_TYPE::WORD); + f.write(reinterpret_cast(&_emptyBlock4), + 1*ezc3d::DATA_TYPE::WORD); } void ezc3d::Header::read(ezc3d::c3d &c3d, std::fstream &file) { // Parameter address assuming Intel processor - _parametersAddress = c3d.readUint(PROCESSOR_TYPE::INTEL, file, 1*ezc3d::DATA_TYPE::BYTE, 0, std::ios::beg); + _parametersAddress = c3d.readUint(PROCESSOR_TYPE::INTEL, file, + 1*ezc3d::DATA_TYPE::BYTE, 0, + std::ios::beg); - // For some reason, some Vicon's file has lot of "0" at the beginning of the file + // For some reason, some Vicon's file has lot of "0" at the beginning + // of the file // This part loop up to the point no 0 is found while (!_parametersAddress){ - _parametersAddress = c3d.readUint(PROCESSOR_TYPE::INTEL,file, 1*ezc3d::DATA_TYPE::BYTE); + _parametersAddress = c3d.readUint(PROCESSOR_TYPE::INTEL,file, + 1*ezc3d::DATA_TYPE::BYTE); if (file.eof()) throw std::ios_base::failure("File is empty"); ++_nbOfZerosBeforeHeader; } - _checksum = c3d.readUint(PROCESSOR_TYPE::INTEL, file, 1*ezc3d::DATA_TYPE::BYTE); + _checksum = c3d.readUint(PROCESSOR_TYPE::INTEL, file, + 1*ezc3d::DATA_TYPE::BYTE); if (_checksum != 0x50) // If checkbyte is wrong throw std::ios_base::failure("File must be a valid c3d file"); @@ -167,63 +199,87 @@ void ezc3d::Header::read(ezc3d::c3d &c3d, std::fstream &file) ezc3d::PROCESSOR_TYPE processorType(readProcessorType(c3d, file)); // Number of data - _nb3dPoints = c3d.readUint(processorType, file, 1*ezc3d::DATA_TYPE::WORD); - _nbAnalogsMeasurement = c3d.readUint(processorType, file, 1*ezc3d::DATA_TYPE::WORD); + _nb3dPoints = c3d.readUint(processorType, file, + 1*ezc3d::DATA_TYPE::WORD); + _nbAnalogsMeasurement = c3d.readUint(processorType, file, + 1*ezc3d::DATA_TYPE::WORD); // Idx of first and last frame - _firstFrame = c3d.readUint(processorType, file, 1*ezc3d::DATA_TYPE::WORD); - if (_firstFrame != 0) // First frame is 1-based, but some forgot hence they put 0.. + _firstFrame = c3d.readUint(processorType, file, + 1*ezc3d::DATA_TYPE::WORD); + // First frame is 1-based, but some forgot hence they put 0.. + if (_firstFrame != 0) _firstFrame -= 1; _lastFrame = c3d.readUint(processorType, file, 1*ezc3d::DATA_TYPE::WORD); - if (_lastFrame != 0) // Last frame is 1-based, but some forgot hence they put 0.. + // Last frame is 1-based, but some forgot hence they put 0.. + if (_lastFrame != 0) _lastFrame -= 1; // Some info - _nbMaxInterpGap = c3d.readUint(processorType, file, 1*ezc3d::DATA_TYPE::WORD); - _scaleFactor = c3d.readFloat(processorType, file, 2*ezc3d::DATA_TYPE::WORD); + _nbMaxInterpGap = c3d.readUint(processorType, file, + 1*ezc3d::DATA_TYPE::WORD); + _scaleFactor = c3d.readFloat(processorType, file, + 2*ezc3d::DATA_TYPE::WORD); // Parameters of analog data - _dataStart = c3d.readUint(processorType, file, 1*ezc3d::DATA_TYPE::WORD); - _nbAnalogByFrame = c3d.readUint(processorType, file, 1*ezc3d::DATA_TYPE::WORD); + _dataStart = c3d.readUint(processorType, file, + 1*ezc3d::DATA_TYPE::WORD); + _nbAnalogByFrame = c3d.readUint(processorType, file, + 1*ezc3d::DATA_TYPE::WORD); _frameRate = c3d.readFloat(processorType, file); - _emptyBlock1 = c3d.readInt(processorType, file, 135*ezc3d::DATA_TYPE::WORD); + _emptyBlock1 = c3d.readInt(processorType, file, + 135*ezc3d::DATA_TYPE::WORD); // Parameters of keys - _keyLabelPresent = c3d.readUint(processorType, file, 1*ezc3d::DATA_TYPE::WORD); - _firstBlockKeyLabel = c3d.readUint(processorType, file, 1*ezc3d::DATA_TYPE::WORD); - _fourCharPresent = c3d.readUint(processorType, file, 1*ezc3d::DATA_TYPE::WORD); + _keyLabelPresent = c3d.readUint(processorType, file, + 1*ezc3d::DATA_TYPE::WORD); + _firstBlockKeyLabel = c3d.readUint(processorType, file, + 1*ezc3d::DATA_TYPE::WORD); + _fourCharPresent = c3d.readUint(processorType, file, + 1*ezc3d::DATA_TYPE::WORD); // Parameters of events - _nbEvents = c3d.readUint(processorType, file, 1*ezc3d::DATA_TYPE::WORD); - _emptyBlock2 = c3d.readInt(processorType, file, 1*ezc3d::DATA_TYPE::WORD); + _nbEvents = c3d.readUint(processorType, file, + 1*ezc3d::DATA_TYPE::WORD); + _emptyBlock2 = c3d.readInt(processorType, file, + 1*ezc3d::DATA_TYPE::WORD); for (unsigned int i = 0; i < _eventsTime.size(); ++i) _eventsTime[i] = c3d.readFloat(processorType, file); for (unsigned int i = 0; i < _eventsDisplay.size(); ++i) - _eventsDisplay[i] = c3d.readUint(processorType, file, 1*ezc3d::DATA_TYPE::WORD); - _emptyBlock3 = c3d.readInt(processorType, file, 1*ezc3d::DATA_TYPE::WORD); + _eventsDisplay[i] = c3d.readUint(processorType, file, + 1*ezc3d::DATA_TYPE::WORD); + _emptyBlock3 = c3d.readInt(processorType, file, + 1*ezc3d::DATA_TYPE::WORD); for (unsigned int i = 0; i<_eventsLabel.size(); ++i) - _eventsLabel[i] = c3d.readString(file, 2*ezc3d::DATA_TYPE::WORD); - _emptyBlock4 = c3d.readInt(processorType, file, 22*ezc3d::DATA_TYPE::WORD); + _eventsLabel[i] = c3d.readString(file, + 2*ezc3d::DATA_TYPE::WORD); + _emptyBlock4 = c3d.readInt(processorType, file, + 22*ezc3d::DATA_TYPE::WORD); } -size_t ezc3d::Header::nbOfZerosBeforeHeader() const -{ +size_t ezc3d::Header::nbOfZerosBeforeHeader() const { return _nbOfZerosBeforeHeader; } -size_t ezc3d::Header::parametersAddress() const -{ +size_t ezc3d::Header::parametersAddress() const { return _parametersAddress; } -ezc3d::PROCESSOR_TYPE ezc3d::Header::readProcessorType(c3d &c3d, std::fstream &file) -{ +ezc3d::PROCESSOR_TYPE ezc3d::Header::readProcessorType( + c3d &c3d, std::fstream &file) { // Remember the current position of the cursor std::streampos dataPos = file.tellg(); // Read the processor type (assuming Intel type) - size_t parametersAddress(c3d.readUint(PROCESSOR_TYPE::INTEL, file, 1*ezc3d::DATA_TYPE::BYTE, 0, std::ios::beg)); - size_t processorType = c3d.readUint(PROCESSOR_TYPE::INTEL, file, 1*ezc3d::DATA_TYPE::BYTE, static_cast(256*ezc3d::DATA_TYPE::WORD*(parametersAddress-1)) + 3*ezc3d::DATA_TYPE::BYTE, std::ios::beg); + size_t parametersAddress( + c3d.readUint( + PROCESSOR_TYPE::INTEL, file, 1*ezc3d::DATA_TYPE::BYTE, + 0, std::ios::beg)); + size_t processorType = c3d.readUint( + PROCESSOR_TYPE::INTEL, file, 1*ezc3d::DATA_TYPE::BYTE, + static_cast( + 256*ezc3d::DATA_TYPE::WORD*(parametersAddress-1)) + + 3*ezc3d::DATA_TYPE::BYTE, std::ios::beg); // Put back the cursor in the file file.seekg(dataPos); @@ -238,190 +294,170 @@ ezc3d::PROCESSOR_TYPE ezc3d::Header::readProcessorType(c3d &c3d, std::fstream &f throw std::runtime_error("Could not read the processor type"); } -size_t ezc3d::Header::checksum() const -{ +size_t ezc3d::Header::checksum() const { return _checksum; } -size_t ezc3d::Header::nb3dPoints() const -{ +size_t ezc3d::Header::nb3dPoints() const { return _nb3dPoints; } -void ezc3d::Header::nb3dPoints(size_t numberOfPoints) -{ +void ezc3d::Header::nb3dPoints( + size_t numberOfPoints) { _nb3dPoints = numberOfPoints; } -size_t ezc3d::Header::nbAnalogs() const -{ +size_t ezc3d::Header::nbAnalogs() const { if (_nbAnalogByFrame == 0) return 0; else return _nbAnalogsMeasurement / _nbAnalogByFrame; } -void ezc3d::Header::nbAnalogs(size_t nbOfAnalogs) -{ +void ezc3d::Header::nbAnalogs( + size_t nbOfAnalogs) { _nbAnalogsMeasurement = nbOfAnalogs * _nbAnalogByFrame; } -size_t ezc3d::Header::nbAnalogsMeasurement() const -{ +size_t ezc3d::Header::nbAnalogsMeasurement() const { return _nbAnalogsMeasurement; } -size_t ezc3d::Header::nbFrames() const -{ +size_t ezc3d::Header::nbFrames() const { if (nb3dPoints() == 0 && nbAnalogs() == 0) return 0; else return _lastFrame - _firstFrame + 1; } -size_t ezc3d::Header::firstFrame() const -{ +size_t ezc3d::Header::firstFrame() const { return _firstFrame; } -void ezc3d::Header::firstFrame(size_t frame) -{ +void ezc3d::Header::firstFrame( + size_t frame) { _firstFrame = frame; } -size_t ezc3d::Header::lastFrame() const -{ +size_t ezc3d::Header::lastFrame() const { return _lastFrame; } -void ezc3d::Header::lastFrame(size_t frame) -{ +void ezc3d::Header::lastFrame( + size_t frame) { _lastFrame = frame; } -size_t ezc3d::Header::nbMaxInterpGap() const -{ +size_t ezc3d::Header::nbMaxInterpGap() const { return _nbMaxInterpGap; } -float ezc3d::Header::scaleFactor() const -{ +float ezc3d::Header::scaleFactor() const { return _scaleFactor; } -size_t ezc3d::Header::dataStart() const -{ +size_t ezc3d::Header::dataStart() const { return _dataStart; } -size_t ezc3d::Header::nbAnalogByFrame() const -{ +size_t ezc3d::Header::nbAnalogByFrame() const { return _nbAnalogByFrame; } -void ezc3d::Header::nbAnalogByFrame(size_t nbOfAnalogsByFrame) -{ +void ezc3d::Header::nbAnalogByFrame( + size_t nbOfAnalogsByFrame) { size_t analogs(nbAnalogs()); _nbAnalogByFrame = nbOfAnalogsByFrame; nbAnalogs(analogs); } -float ezc3d::Header::frameRate() const -{ +float ezc3d::Header::frameRate() const { return _frameRate; } -void ezc3d::Header::frameRate(float pointFrameRate) -{ +void ezc3d::Header::frameRate( + float pointFrameRate) { _frameRate = pointFrameRate; } -int ezc3d::Header::emptyBlock1() const -{ +int ezc3d::Header::emptyBlock1() const { return _emptyBlock1; } -int ezc3d::Header::emptyBlock2() const -{ +int ezc3d::Header::emptyBlock2() const { return _emptyBlock2; } -int ezc3d::Header::emptyBlock3() const -{ +int ezc3d::Header::emptyBlock3() const { return _emptyBlock3; } -int ezc3d::Header::emptyBlock4() const -{ +int ezc3d::Header::emptyBlock4() const { return _emptyBlock4; } -size_t ezc3d::Header::keyLabelPresent() const -{ +size_t ezc3d::Header::keyLabelPresent() const { return _keyLabelPresent; } -size_t ezc3d::Header::firstBlockKeyLabel() const -{ +size_t ezc3d::Header::firstBlockKeyLabel() const { return _firstBlockKeyLabel; } -size_t ezc3d::Header::fourCharPresent() const -{ +size_t ezc3d::Header::fourCharPresent() const { return _fourCharPresent; } -size_t ezc3d::Header::nbEvents() const -{ +size_t ezc3d::Header::nbEvents() const { return _nbEvents; } -const std::vector& ezc3d::Header::eventsTime() const -{ +const std::vector& ezc3d::Header::eventsTime() const { return _eventsTime; } -float ezc3d::Header::eventsTime(size_t idx) const -{ +float ezc3d::Header::eventsTime(size_t idx) const { try { return _eventsTime.at(idx); } catch(std::out_of_range) { - throw std::out_of_range("Header::eventsTime method is trying to access the event " - + std::to_string(idx) + - " while the maximum number of events is " - + std::to_string(nbEvents()) + "."); + throw std::out_of_range( + "Header::eventsTime method is trying to access the event " + + std::to_string(idx) + + " while the maximum number of events is " + + std::to_string(nbEvents()) + "."); } } -std::vector ezc3d::Header::eventsDisplay() const -{ +std::vector ezc3d::Header::eventsDisplay() const { return _eventsDisplay; } -size_t ezc3d::Header::eventsDisplay(size_t idx) const{ +size_t ezc3d::Header::eventsDisplay( + size_t idx) const { try { return _eventsDisplay.at(idx); } catch(std::out_of_range) { - throw std::out_of_range("Header::eventsDisplay method is trying to access the event " - + std::to_string(idx) + - " while the maximum number of events is " - + std::to_string(nbEvents()) + "."); + throw std::out_of_range( + "Header::eventsDisplay method is trying " + "to access the event " + + std::to_string(idx) + + " while the maximum number of events is " + + std::to_string(nbEvents()) + "."); } } -const std::vector& ezc3d::Header::eventsLabel() const -{ +const std::vector& ezc3d::Header::eventsLabel() const { return _eventsLabel; } -const std::string& ezc3d::Header::eventsLabel(size_t idx) const -{ +const std::string& ezc3d::Header::eventsLabel(size_t idx) const { try { return _eventsLabel.at(idx); } catch(std::out_of_range) { - throw std::out_of_range("Header::eventsLabel method is trying to access the event " - + std::to_string(idx) + - " while the maximum number of events is " - + std::to_string(nbEvents()) + "."); + throw std::out_of_range( + "Header::eventsLabel method is trying to access the event " + + std::to_string(idx) + + " while the maximum number of events is " + + std::to_string(nbEvents()) + "."); } } diff --git a/src/Parameter.cpp b/src/Parameter.cpp index 670c7d54..5ad951c9 100644 --- a/src/Parameter.cpp +++ b/src/Parameter.cpp @@ -10,66 +10,82 @@ #include "Parameter.h" #include "Parameters.h" -ezc3d::ParametersNS::GroupNS::Parameter::Parameter(const std::string &name, const std::string &description) : +ezc3d::ParametersNS::GroupNS::Parameter::Parameter( + const std::string &name, + const std::string &description) : _name(name), _description(description), _isLocked(false), _data_type(ezc3d::DATA_TYPE::NO_DATA_TYPE), - _isEmpty(true) -{ + _isEmpty(true) { } -void ezc3d::ParametersNS::GroupNS::Parameter::print() const -{ +void ezc3d::ParametersNS::GroupNS::Parameter::print() const { std::cout << "parameterName = " << name() << std::endl; std::cout << "isLocked = " << isLocked() << std::endl; // Data are not separated according to _dimension, which could help to read if (_data_type == DATA_TYPE::CHAR) for (unsigned int i = 0; i < _param_data_string.size(); ++i) - std::cout << "param_data_string[" << i << "] = " << _param_data_string[i] << std::endl; + std::cout << "param_data_string[" << i << "] = " + << _param_data_string[i] << std::endl; if (_data_type == DATA_TYPE::BYTE) for (unsigned int i = 0; i < _param_data_int.size(); ++i) - std::cout << "param_data[" << i << "] = " << _param_data_int[i] << std::endl; + std::cout << "param_data[" << i << "] = " + << _param_data_int[i] << std::endl; if (_data_type == DATA_TYPE::INT) for (unsigned int i = 0; i < _param_data_int.size(); ++i) - std::cout << "param_data[" << i << "] = " << _param_data_int[i] << std::endl; + std::cout << "param_data[" << i << "] = " + << _param_data_int[i] << std::endl; if (_data_type == DATA_TYPE::FLOAT) for (unsigned int i = 0; i < _param_data_float.size(); ++i) - std::cout << "param_data[" << i << "] = " << _param_data_float[i] << std::endl; + std::cout << "param_data[" << i << "] = " + << _param_data_float[i] << std::endl; std::cout << "description = " << _description << std::endl; } -void ezc3d::ParametersNS::GroupNS::Parameter::write(std::fstream &f, int groupIdx, std::streampos &dataStartPosition) const -{ +void ezc3d::ParametersNS::GroupNS::Parameter::write( + std::fstream &f, + int groupIdx, + std::streampos &dataStartPosition) const { int nCharName(static_cast(name().size())); if (isLocked()) nCharName *= -1; - f.write(reinterpret_cast(&nCharName), 1*ezc3d::DATA_TYPE::BYTE); + f.write(reinterpret_cast(&nCharName), + 1*ezc3d::DATA_TYPE::BYTE); if (isLocked()) nCharName *= -1; - f.write(reinterpret_cast(&groupIdx), 1*ezc3d::DATA_TYPE::BYTE); - f.write(ezc3d::toUpper(name()).c_str(), nCharName*ezc3d::DATA_TYPE::BYTE); + f.write(reinterpret_cast(&groupIdx), + 1*ezc3d::DATA_TYPE::BYTE); + f.write(ezc3d::toUpper(name()).c_str(), + nCharName*ezc3d::DATA_TYPE::BYTE); - // It is not possible already to know in how many bytes the next parameter is + // It is not possible already to know in how many + // bytes the next parameter is int blank(0); std::streampos pos(f.tellg()); - f.write(reinterpret_cast(&blank), 2*ezc3d::DATA_TYPE::BYTE); + f.write(reinterpret_cast(&blank), + 2*ezc3d::DATA_TYPE::BYTE); // Write the parameter values - f.write(reinterpret_cast(&_data_type), 1*ezc3d::DATA_TYPE::BYTE); + f.write(reinterpret_cast(&_data_type), + 1*ezc3d::DATA_TYPE::BYTE); size_t size_dim(_dimension.size()); // If it is a scalar, store it as so - if (_dimension.size() == 1 && _dimension[0] == 1 && _data_type != DATA_TYPE::CHAR){ + if (_dimension.size() == 1 && _dimension[0] == 1 + && _data_type != DATA_TYPE::CHAR){ int _size_dim(0); - f.write(reinterpret_cast(&_size_dim), 1*ezc3d::DATA_TYPE::BYTE); + f.write(reinterpret_cast(&_size_dim), + 1*ezc3d::DATA_TYPE::BYTE); } else{ - f.write(reinterpret_cast(&size_dim), 1*ezc3d::DATA_TYPE::BYTE); + f.write(reinterpret_cast(&size_dim), + 1*ezc3d::DATA_TYPE::BYTE); for (unsigned int i=0; i<_dimension.size(); ++i) - f.write(reinterpret_cast(&_dimension[i]), 1*ezc3d::DATA_TYPE::BYTE); + f.write(reinterpret_cast(&_dimension[i]), + 1*ezc3d::DATA_TYPE::BYTE); } int hasSize(0); @@ -81,15 +97,23 @@ void ezc3d::ParametersNS::GroupNS::Parameter::write(std::fstream &f, int groupId if (hasSize > 0){ if (_data_type == DATA_TYPE::CHAR){ if (_dimension.size() == 1){ - f.write(_param_data_string[0].c_str(), static_cast(_param_data_string[0].size())*static_cast(DATA_TYPE::BYTE)); + f.write(_param_data_string[0].c_str(), + static_cast( + _param_data_string[0].size()) + * static_cast(DATA_TYPE::BYTE)); } else { writeImbricatedParameter(f, _dimension, 1); } } else { - if (static_cast(dataStartPosition) != -1 && !_name.compare("DATA_START")){ // -1 means that it is not the POINT group - // This is a special case defined in the standard where you write the number of blocks up to the data + if (static_cast(dataStartPosition) != -1 + && !_name.compare("DATA_START")){ + // -1 means that it is not the POINT group + + // This is a special case defined in the standard where you write + // the number of blocks up to the data dataStartPosition = f.tellg(); - f.write(reinterpret_cast(&blank), 2*ezc3d::DATA_TYPE::BYTE); + f.write(reinterpret_cast(&blank), + 2*ezc3d::DATA_TYPE::BYTE); } else writeImbricatedParameter(f, _dimension); } @@ -97,30 +121,43 @@ void ezc3d::ParametersNS::GroupNS::Parameter::write(std::fstream &f, int groupId // Write description of the parameter int nCharDescription(static_cast(description().size())); - f.write(reinterpret_cast(&nCharDescription), 1*ezc3d::DATA_TYPE::BYTE); - f.write(description().c_str(), nCharDescription*ezc3d::DATA_TYPE::BYTE); + f.write(reinterpret_cast(&nCharDescription), + 1*ezc3d::DATA_TYPE::BYTE); + f.write(description().c_str(), + nCharDescription*ezc3d::DATA_TYPE::BYTE); // Go back at the left blank space and write the current position std::streampos currentPos(f.tellg()); f.seekg(pos); int nCharToNext = int(currentPos - pos); - f.write(reinterpret_cast(&nCharToNext), 2*ezc3d::DATA_TYPE::BYTE); + f.write(reinterpret_cast(&nCharToNext), + 2*ezc3d::DATA_TYPE::BYTE); f.seekg(currentPos); } -size_t ezc3d::ParametersNS::GroupNS::Parameter::writeImbricatedParameter(std::fstream &f, const std::vector& dim, size_t currentIdx, size_t cmp) const{ +size_t ezc3d::ParametersNS::GroupNS::Parameter::writeImbricatedParameter( + std::fstream &f, + const std::vector& dim, + size_t currentIdx, size_t cmp) const { for (size_t i=0; i(&(_param_data_int[cmp])), static_cast(_data_type)); + f.write(reinterpret_cast(&(_param_data_int[cmp])), + static_cast(_data_type)); else if (_data_type == DATA_TYPE::INT) - f.write(reinterpret_cast(&(_param_data_int[cmp])), static_cast(_data_type)); + f.write(reinterpret_cast(&(_param_data_int[cmp])), + static_cast(_data_type)); else if (_data_type == DATA_TYPE::FLOAT) - f.write(reinterpret_cast(&(_param_data_float[cmp])), static_cast(_data_type)); + f.write(reinterpret_cast( + &(_param_data_float[cmp])), + static_cast(_data_type)); else if (_data_type == DATA_TYPE::CHAR){ - f.write(_param_data_string[cmp].c_str(), static_cast(_param_data_string[cmp].size())*static_cast(DATA_TYPE::BYTE)); + f.write(_param_data_string[cmp].c_str(), + static_cast(_param_data_string[cmp].size()) + * static_cast(DATA_TYPE::BYTE)); const char buffer = ' '; - for (size_t j=_param_data_string[cmp].size(); j<_dimension[0]; ++j) + for (size_t j=_param_data_string[cmp].size() + ; j<_dimension[0]; ++j) f.write(&buffer, static_cast(DATA_TYPE::BYTE)); } ++cmp; @@ -130,27 +167,35 @@ size_t ezc3d::ParametersNS::GroupNS::Parameter::writeImbricatedParameter(std::fs return cmp; } -int ezc3d::ParametersNS::GroupNS::Parameter::read(ezc3d::c3d &c3d, const Parameters ¶ms, std::fstream &file, int nbCharInName) -{ +int ezc3d::ParametersNS::GroupNS::Parameter::read( + ezc3d::c3d &c3d, + const Parameters ¶ms, + std::fstream &file, + int nbCharInName) { if (nbCharInName < 0) _isLocked = true; else _isLocked = false; // Read name of the group - _name = c3d.readString(file, static_cast(abs(nbCharInName) * ezc3d::DATA_TYPE::BYTE)); + _name = c3d.readString(file, + static_cast(abs(nbCharInName) + * ezc3d::DATA_TYPE::BYTE)); // number of byte to the next group from here - int offsetNext(static_cast(c3d.readUint(params.processorType(), file, 2*ezc3d::DATA_TYPE::BYTE))); + int offsetNext(static_cast(c3d.readUint(params.processorType(), file, + 2*ezc3d::DATA_TYPE::BYTE))); // Compute the position of the element in the file int nextParamByteInFile; if (offsetNext == 0) nextParamByteInFile = 0; else - nextParamByteInFile = static_cast(file.tellg()) + offsetNext - ezc3d::DATA_TYPE::WORD; + nextParamByteInFile = static_cast(file.tellg()) + + offsetNext - ezc3d::DATA_TYPE::WORD; // -1 sizeof(char), 1 byte, 2 int, 4 float - int lengthInByte(c3d.readInt(params.processorType(), file, 1*ezc3d::DATA_TYPE::BYTE)); + int lengthInByte(c3d.readInt(params.processorType(), file, + 1*ezc3d::DATA_TYPE::BYTE)); if (lengthInByte == -1) _data_type = DATA_TYPE::CHAR; else if (lengthInByte == 1) @@ -163,76 +208,85 @@ int ezc3d::ParametersNS::GroupNS::Parameter::read(ezc3d::c3d &c3d, const Paramet throw std::ios_base::failure ("Parameter type unrecognized"); // number of dimension of parameter (0 for scalar) - int nDimensions(c3d.readInt(params.processorType(), file, 1*ezc3d::DATA_TYPE::BYTE)); - if (nDimensions == 0 && _data_type != DATA_TYPE::CHAR) // In the special case of a scalar + int nDimensions(c3d.readInt(params.processorType(), file, + 1*ezc3d::DATA_TYPE::BYTE)); + if (nDimensions == 0 && _data_type != DATA_TYPE::CHAR) + // In the special case of a scalar _dimension.push_back(1); else // otherwise it's a matrix for (int i=0; i(_data_type), _dimension, _param_data_int); + c3d.readParam(params.processorType(), file, + static_cast(_data_type), _dimension, + _param_data_int); else if (_data_type == DATA_TYPE::INT) - c3d.readParam(params.processorType(), file, static_cast(_data_type), _dimension, _param_data_int); + c3d.readParam(params.processorType(), file, + static_cast(_data_type), _dimension, + _param_data_int); else if (_data_type == DATA_TYPE::FLOAT) - c3d.readParam(params.processorType(), file, _dimension, _param_data_float); + c3d.readParam(params.processorType(), file, _dimension, + _param_data_float); // Byte 5+nbCharInName ==> Number of characters in group description - int nbCharInDesc(c3d.readInt(params.processorType(), file, 1*ezc3d::DATA_TYPE::BYTE)); + int nbCharInDesc(c3d.readInt(params.processorType(), file, + 1*ezc3d::DATA_TYPE::BYTE)); // Byte 6+nbCharInName ==> Group description if (nbCharInDesc) - _description = c3d.readString(file, static_cast(nbCharInDesc)); + _description = c3d.readString( + file, static_cast(nbCharInDesc)); setEmptyFlag(); // Return how many bytes return nextParamByteInFile; } -const std::string& ezc3d::ParametersNS::GroupNS::Parameter::name() const -{ +const std::string& ezc3d::ParametersNS::GroupNS::Parameter::name() const { return _name; } -void ezc3d::ParametersNS::GroupNS::Parameter::name(const std::string paramName) -{ +void ezc3d::ParametersNS::GroupNS::Parameter::name( + const std::string ¶mName) { _name = paramName; } -const std::string& ezc3d::ParametersNS::GroupNS::Parameter::description() const -{ +const std::string& +ezc3d::ParametersNS::GroupNS::Parameter::description() const { return _description; } -void ezc3d::ParametersNS::GroupNS::Parameter::description(const std::string description) -{ +void ezc3d::ParametersNS::GroupNS::Parameter::description( + const std::string &description) { _description = description; } -bool ezc3d::ParametersNS::GroupNS::Parameter::isLocked() const -{ +bool ezc3d::ParametersNS::GroupNS::Parameter::isLocked() const { return _isLocked; } -void ezc3d::ParametersNS::GroupNS::Parameter::lock() -{ +void ezc3d::ParametersNS::GroupNS::Parameter::lock() { _isLocked = true; } -void ezc3d::ParametersNS::GroupNS::Parameter::unlock() -{ +void ezc3d::ParametersNS::GroupNS::Parameter::unlock() { _isLocked = false; } -const std::vector ezc3d::ParametersNS::GroupNS::Parameter::dimension() const -{ +const std::vector +ezc3d::ParametersNS::GroupNS::Parameter::dimension() const { return _dimension; } -bool ezc3d::ParametersNS::GroupNS::Parameter::isDimensionConsistent(size_t dataSize, const std::vector &dimension) const { +bool ezc3d::ParametersNS::GroupNS::Parameter::isDimensionConsistent( + size_t dataSize, + const std::vector &dimension) const { if (dataSize == 0){ int dim(1); for (unsigned int i=0; i()={data}); } -void ezc3d::ParametersNS::GroupNS::Parameter::set(size_t data) -{ +void ezc3d::ParametersNS::GroupNS::Parameter::set(size_t data) { set(static_cast(data)); } -void ezc3d::ParametersNS::GroupNS::Parameter::set(const std::vector &data, const std::vector &dimension) -{ +void ezc3d::ParametersNS::GroupNS::Parameter::set( + const std::vector &data, + const std::vector &dimension) { std::vector dimensionCopy; if (dimension.size() == 0){ dimensionCopy.push_back(data.size()); @@ -284,25 +335,25 @@ void ezc3d::ParametersNS::GroupNS::Parameter::set(const std::vector &data, dimensionCopy = dimension; } if (!isDimensionConsistent(data.size(), dimensionCopy)) - throw std::range_error("Dimension of the data does not correspond to sent dimensions"); + throw std::range_error( + "Dimension of the data does not correspond to sent dimensions"); _data_type = ezc3d::DATA_TYPE::INT; _param_data_int = data; _dimension = dimensionCopy; setEmptyFlag(); } -void ezc3d::ParametersNS::GroupNS::Parameter::set(float data) -{ +void ezc3d::ParametersNS::GroupNS::Parameter::set(float data) { set(std::vector()={data}); } -void ezc3d::ParametersNS::GroupNS::Parameter::set(double data) -{ +void ezc3d::ParametersNS::GroupNS::Parameter::set(double data) { set(std::vector()={static_cast(data)}); } -void ezc3d::ParametersNS::GroupNS::Parameter::set(const std::vector &data, const std::vector &dimension) -{ +void ezc3d::ParametersNS::GroupNS::Parameter::set( + const std::vector &data, + const std::vector &dimension) { std::vector dimensionCopy; if (dimension.size() == 0){ dimensionCopy.push_back(data.size()); @@ -310,7 +361,8 @@ void ezc3d::ParametersNS::GroupNS::Parameter::set(const std::vector &data dimensionCopy = dimension; } if (!isDimensionConsistent(data.size(), dimensionCopy)) - throw std::range_error("Dimension of the data does not correspond to sent dimensions"); + throw std::range_error( + "Dimension of the data does not correspond to sent dimensions"); _data_type = ezc3d::DATA_TYPE::FLOAT; _param_data_float = data; @@ -318,13 +370,14 @@ void ezc3d::ParametersNS::GroupNS::Parameter::set(const std::vector &data setEmptyFlag(); } -void ezc3d::ParametersNS::GroupNS::Parameter::set(const std::string& data) -{ +void ezc3d::ParametersNS::GroupNS::Parameter::set( + const std::string& data) { set(std::vector() = {data}); } -void ezc3d::ParametersNS::GroupNS::Parameter::set(const std::vector &data, const std::vector &dimension) -{ +void ezc3d::ParametersNS::GroupNS::Parameter::set( + const std::vector &data, + const std::vector &dimension) { std::vector dimensionCopy; if (dimension.size() == 0){ dimensionCopy.push_back(data.size()); @@ -332,7 +385,8 @@ void ezc3d::ParametersNS::GroupNS::Parameter::set(const std::vector dimensionCopy = dimension; } if (!isDimensionConsistent(data.size(), dimensionCopy)) - throw std::range_error("Dimension of the data does not correspond to sent dimensions"); + throw std::range_error( + "Dimension of the data does not correspond to sent dimensions"); // Insert the length of the longest string size_t first_dim(0); for (unsigned int i=0; i setEmptyFlag(); } -const std::vector &ezc3d::ParametersNS::GroupNS::Parameter::valuesAsByte() const -{ +const std::vector& +ezc3d::ParametersNS::GroupNS::Parameter::valuesAsByte() const { if (!_isEmpty && _data_type != DATA_TYPE::BYTE) throw std::invalid_argument(_name + " parameter is not a BYTE"); return _param_data_int; } -const std::vector &ezc3d::ParametersNS::GroupNS::Parameter::valuesAsInt() const -{ +const std::vector& +ezc3d::ParametersNS::GroupNS::Parameter::valuesAsInt() const { if (!_isEmpty && _data_type != DATA_TYPE::INT) throw std::invalid_argument(_name + " parameter is not an INT"); return _param_data_int; } -const std::vector &ezc3d::ParametersNS::GroupNS::Parameter::valuesAsFloat() const -{ +const std::vector& +ezc3d::ParametersNS::GroupNS::Parameter::valuesAsFloat() const { if (!_isEmpty && _data_type != DATA_TYPE::FLOAT) throw std::invalid_argument(_name + " parameter is not a FLOAT"); return _param_data_float; } -const std::vector& ezc3d::ParametersNS::GroupNS::Parameter::valuesAsString() const -{ +const std::vector& +ezc3d::ParametersNS::GroupNS::Parameter::valuesAsString() const { if (!_isEmpty && _data_type != DATA_TYPE::CHAR) throw std::invalid_argument(_name + " parameter is not string"); return _param_data_string; } - - diff --git a/src/Parameters.cpp b/src/Parameters.cpp index 985fba5a..7b53d571 100644 --- a/src/Parameters.cpp +++ b/src/Parameters.cpp @@ -14,27 +14,37 @@ ezc3d::ParametersNS::Parameters::Parameters(): _parametersStart(1), _checksum(0x50), _nbParamBlock(0), - _processorType(PROCESSOR_TYPE::NO_PROCESSOR_TYPE) -{ + _processorType(PROCESSOR_TYPE::NO_PROCESSOR_TYPE) { setMandatoryParameters(); } -ezc3d::ParametersNS::Parameters::Parameters(ezc3d::c3d &c3d, std::fstream &file) : +ezc3d::ParametersNS::Parameters::Parameters( + ezc3d::c3d &c3d, + std::fstream &file) : _parametersStart(0), _checksum(0), _nbParamBlock(0), - _processorType(PROCESSOR_TYPE::NO_PROCESSOR_TYPE) -{ - setMandatoryParameters(); - + _processorType(PROCESSOR_TYPE::NO_PROCESSOR_TYPE) { // Read the Parameters Header (assuming Intel processor) - _parametersStart = c3d.readUint(processorType(), file, 1*ezc3d::DATA_TYPE::BYTE, static_cast(256*ezc3d::DATA_TYPE::WORD*(c3d.header().parametersAddress()-1) + c3d.header().nbOfZerosBeforeHeader()), std::ios::beg); - _checksum = c3d.readUint(processorType(), file, 1*ezc3d::DATA_TYPE::BYTE); - _nbParamBlock = c3d.readUint(processorType(), file, 1*ezc3d::DATA_TYPE::BYTE); - size_t processorTypeId = c3d.readUint(processorType(), file, 1*ezc3d::DATA_TYPE::BYTE); + _parametersStart = c3d.readUint( + processorType(), + file, + 1*ezc3d::DATA_TYPE::BYTE, static_cast( + 256*ezc3d::DATA_TYPE::WORD*( + c3d.header().parametersAddress()-1) + + c3d.header().nbOfZerosBeforeHeader()), + std::ios::beg); + _checksum = c3d.readUint( + processorType(), file, 1*ezc3d::DATA_TYPE::BYTE); + _nbParamBlock = c3d.readUint( + processorType(), file, 1*ezc3d::DATA_TYPE::BYTE); + size_t processorTypeId = c3d.readUint( + processorType(), file, 1*ezc3d::DATA_TYPE::BYTE); if (_checksum == 0 && _parametersStart == 0){ - // In theory, if this happens, this is a bad c3d formatting and should return an error, but for some reason - // Qualisys decided that they would not comply to the standard. Therefore set put "_parameterStart" and "_checksum" to 0 + // In theory, if this happens, this is a bad c3d formatting and should + // return an error, but for some reason Qualisys decided that they + // would not comply to the standard. + // Therefore set put "_parameterStart" and "_checksum" to 0 // This is a patch for Qualisys bad formatting c3d _parametersStart = 1; _checksum = 0x50; @@ -48,21 +58,29 @@ ezc3d::ParametersNS::Parameters::Parameters(ezc3d::c3d &c3d, std::fstream &file) _processorType = ezc3d::PROCESSOR_TYPE::DEC; else if (processorTypeId == 86){ _processorType = ezc3d::PROCESSOR_TYPE::MIPS; - throw std::runtime_error("MIPS processor type not supported yet, please open a GitHub issue to report that you want this feature!"); + throw std::runtime_error( + "MIPS processor type not supported yet, please open a " + "GitHub issue to report that you want this feature!"); } else throw std::runtime_error("Could not read the processor type"); // Read parameter or group - std::streampos nextParamByteInFile(static_cast(file.tellg()) + static_cast(_parametersStart) - ezc3d::DATA_TYPE::BYTE); + std::streampos nextParamByteInFile( + static_cast(file.tellg()) + + static_cast(_parametersStart) - ezc3d::DATA_TYPE::BYTE); while (nextParamByteInFile) { - // Check if we spontaneously got to the next parameter. Otherwise c3d is messed up + // Check if we spontaneously got to the next parameter. + // Otherwise c3d is messed up if (file.tellg() != nextParamByteInFile) throw std::ios_base::failure("Bad c3d formatting"); - // Nb of char in the group name, locked if negative, 0 if we finished the section - int nbCharInName(c3d.readInt(processorType(), file, 1*ezc3d::DATA_TYPE::BYTE)); + // Nb of char in the group name, locked if negative, + // 0 if we finished the section + int nbCharInName( + c3d.readInt( + processorType(), file, 1*ezc3d::DATA_TYPE::BYTE)); if (nbCharInName == 0) break; int id(c3d.readInt(processorType(), file, 1*ezc3d::DATA_TYPE::BYTE)); @@ -71,165 +89,183 @@ ezc3d::ParametersNS::Parameters::Parameters(ezc3d::c3d &c3d, std::fstream &file) for (size_t i = _groups.size(); i < static_cast(abs(id)); ++i) _groups.push_back(ezc3d::ParametersNS::GroupNS::Group()); - // Group ID always negative for groups and positive parameter of group ID - if (id < 0) - nextParamByteInFile = group(static_cast(abs(id)-1)).read(c3d, *this, file, nbCharInName); - else - nextParamByteInFile = group(static_cast(id-1)).parameter(c3d, *this, file, nbCharInName); + // Group ID always negative for groups + // and positive parameter of group ID + if (id < 0) { + nextParamByteInFile = group( + static_cast + (abs(id)-1)).read(c3d, *this, file, nbCharInName); + } + else { + nextParamByteInFile = group( + static_cast(id-1)).parameter( + c3d, *this, file, nbCharInName); + } } + + // If some mandatory groups/parameters are not set by having a non + // compliant C3D, fix it + setMandatoryParameters(); } -void ezc3d::ParametersNS::Parameters::setMandatoryParameters() -{ +void ezc3d::ParametersNS::Parameters::setMandatoryParameters() { // Mandatory groups { - ezc3d::ParametersNS::GroupNS::Group grp("POINT", ""); - { + if (!isGroup("POINT")){ + group(ezc3d::ParametersNS::GroupNS::Group ("POINT")); + } + + ezc3d::ParametersNS::GroupNS::Group& grp(group("POINT")); + if (!grp.isParameter("USED")){ ezc3d::ParametersNS::GroupNS::Parameter p("USED", ""); p.set(0); p.lock(); grp.parameter(p); } - { + if (!grp.isParameter("SCALE")){ ezc3d::ParametersNS::GroupNS::Parameter p("SCALE", ""); p.set(-1.0); p.lock(); grp.parameter(p); } - { + if (!grp.isParameter("RATE")){ ezc3d::ParametersNS::GroupNS::Parameter p("RATE", ""); p.set(0.0); p.lock(); grp.parameter(p); } - { + if (!grp.isParameter("DATA_START")){ ezc3d::ParametersNS::GroupNS::Parameter p("DATA_START", ""); p.set(0); p.lock(); grp.parameter(p); } - { + if (!grp.isParameter("FRAMES")){ ezc3d::ParametersNS::GroupNS::Parameter p("FRAMES", ""); p.set(0); p.lock(); grp.parameter(p); } - { + if (!grp.isParameter("LABELS")){ ezc3d::ParametersNS::GroupNS::Parameter p("LABELS", ""); p.set(std::vector()={}); grp.parameter(p); } - { + if (!grp.isParameter("DESCRIPTIONS")){ ezc3d::ParametersNS::GroupNS::Parameter p("DESCRIPTIONS", ""); p.set(std::vector()={}); grp.parameter(p); } - { + if (!grp.isParameter("UNITS")){ ezc3d::ParametersNS::GroupNS::Parameter p("UNITS", ""); p.set(std::vector()={}); grp.parameter(p); } - group(grp); } { - ezc3d::ParametersNS::GroupNS::Group grp("ANALOG", ""); - { + if (!isGroup("ANALOG")){ + group(ezc3d::ParametersNS::GroupNS::Group ("ANALOG")); + } + + ezc3d::ParametersNS::GroupNS::Group& grp(group("ANALOG")); + if (!grp.isParameter("USED")){ ezc3d::ParametersNS::GroupNS::Parameter p("USED", ""); p.set(0); p.lock(); grp.parameter(p); } - { + if (!grp.isParameter("LABELS")){ ezc3d::ParametersNS::GroupNS::Parameter p("LABELS", ""); p.set(std::vector()={}); grp.parameter(p); } - { + if (!grp.isParameter("DESCRIPTIONS")){ ezc3d::ParametersNS::GroupNS::Parameter p("DESCRIPTIONS", ""); p.set(std::vector()={}); grp.parameter(p); } - { + if (!grp.isParameter("GEN_SCALE")){ ezc3d::ParametersNS::GroupNS::Parameter p("GEN_SCALE", ""); p.set(1.0); grp.parameter(p); } - { + if (!grp.isParameter("SCALE")){ ezc3d::ParametersNS::GroupNS::Parameter p("SCALE", ""); p.set(std::vector()={}); grp.parameter(p); } - { + if (!grp.isParameter("OFFSET")){ ezc3d::ParametersNS::GroupNS::Parameter p("OFFSET", ""); p.set(std::vector()={}); grp.parameter(p); } - { + if (!grp.isParameter("UNITS")){ ezc3d::ParametersNS::GroupNS::Parameter p("UNITS", ""); p.set(std::vector()={}); grp.parameter(p); } - { + if (!grp.isParameter("RATE")){ ezc3d::ParametersNS::GroupNS::Parameter p("RATE", ""); p.set(0.0); p.lock(); grp.parameter(p); } - { + if (!grp.isParameter("FORMAT")){ ezc3d::ParametersNS::GroupNS::Parameter p("FORMAT", ""); p.set(std::vector()={}); grp.parameter(p); } - { + if (!grp.isParameter("BITS")){ ezc3d::ParametersNS::GroupNS::Parameter p("BITS", ""); p.set(std::vector()={}); grp.parameter(p); } - group(grp); } { - ezc3d::ParametersNS::GroupNS::Group grp("FORCE_PLATFORM", ""); - { + if (!isGroup("FORCE_PLATFORM")){ + group(ezc3d::ParametersNS::GroupNS::Group ("FORCE_PLATFORM")); + } + + ezc3d::ParametersNS::GroupNS::Group& grp(group("FORCE_PLATFORM")); + if (!grp.isParameter("USED")){ ezc3d::ParametersNS::GroupNS::Parameter p("USED", ""); p.set(0); grp.parameter(p); } - { + if (!grp.isParameter("TYPE")){ ezc3d::ParametersNS::GroupNS::Parameter p("TYPE", ""); p.set(std::vector()={}); grp.parameter(p); } - { + if (!grp.isParameter("ZERO")){ ezc3d::ParametersNS::GroupNS::Parameter p("ZERO", ""); p.set(std::vector()={1,0}); grp.parameter(p); } - { + if (!grp.isParameter("CORNERS")){ ezc3d::ParametersNS::GroupNS::Parameter p("CORNERS", ""); p.set(std::vector()={}); grp.parameter(p); } - { + if (!grp.isParameter("ORIGIN")){ ezc3d::ParametersNS::GroupNS::Parameter p("ORIGIN", ""); p.set(std::vector()={}); grp.parameter(p); } - { + if (!grp.isParameter("CHANNEL")){ ezc3d::ParametersNS::GroupNS::Parameter p("CHANNEL", ""); p.set(std::vector()={}); grp.parameter(p); } - { + if (!grp.isParameter("CAL_MATRIX")){ ezc3d::ParametersNS::GroupNS::Parameter p("CAL_MATRIX", ""); p.set(std::vector()={}); grp.parameter(p); } - group(grp); } } -void ezc3d::ParametersNS::Parameters::print() const -{ +void ezc3d::ParametersNS::Parameters::print() const { std::cout << "Parameters header" << std::endl; std::cout << "parametersStart = " << parametersStart() << std::endl; std::cout << "nbParamBlock = " << nbParamBlock() << std::endl; @@ -243,8 +279,9 @@ void ezc3d::ParametersNS::Parameters::print() const std::cout << std::endl; } -void ezc3d::ParametersNS::Parameters::write(std::fstream &f, std::streampos &dataStartPosition) const -{ +void ezc3d::ParametersNS::Parameters::write( + std::fstream &f, + std::streampos &dataStartPosition) const { // Write the header of parameters f.write(reinterpret_cast(&_parametersStart), ezc3d::BYTE); int checksum(0x50); @@ -276,75 +313,88 @@ void ezc3d::ParametersNS::Parameters::write(std::fstream &f, std::streampos &dat f.seekg(currentPos); } -size_t ezc3d::ParametersNS::Parameters::parametersStart() const -{ +size_t ezc3d::ParametersNS::Parameters::parametersStart() const { return _parametersStart; } -size_t ezc3d::ParametersNS::Parameters::checksum() const -{ +size_t ezc3d::ParametersNS::Parameters::checksum() const { return _checksum; } -size_t ezc3d::ParametersNS::Parameters::nbParamBlock() const -{ +size_t ezc3d::ParametersNS::Parameters::nbParamBlock() const { return _nbParamBlock; } -ezc3d::PROCESSOR_TYPE ezc3d::ParametersNS::Parameters::processorType() const -{ +ezc3d::PROCESSOR_TYPE ezc3d::ParametersNS::Parameters::processorType() const { return _processorType; } -size_t ezc3d::ParametersNS::Parameters::nbGroups() const -{ +size_t ezc3d::ParametersNS::Parameters::nbGroups() const { return _groups.size(); } -size_t ezc3d::ParametersNS::Parameters::groupIdx(const std::string &groupName) const +bool ezc3d::ParametersNS::Parameters::isGroup( + const std::string &groupName) const { + try { + groupIdx(groupName); + return true; + } catch (std::invalid_argument) { + return false; + } +} + +size_t ezc3d::ParametersNS::Parameters::groupIdx( + const std::string &groupName) const { for (size_t i = 0; i < nbGroups(); ++i) if (!group(i).name().compare(groupName)) return i; - throw std::invalid_argument("Parameters::groupIdx could not find " + groupName); + throw std::invalid_argument( + "Parameters::groupIdx could not find " + groupName); } -const ezc3d::ParametersNS::GroupNS::Group &ezc3d::ParametersNS::Parameters::group(size_t idx) const -{ +const ezc3d::ParametersNS::GroupNS::Group& +ezc3d::ParametersNS::Parameters::group( + size_t idx) const { try { return _groups.at(idx); } catch(std::out_of_range) { - throw std::out_of_range("Parameters::group method is trying to access the group " - + std::to_string(idx) + - " while the maximum number of groups is " - + std::to_string(nbGroups()) + "."); + throw std::out_of_range( + "Parameters::group method is trying to access the group " + + std::to_string(idx) + + " while the maximum number of groups is " + + std::to_string(nbGroups()) + "."); } } -ezc3d::ParametersNS::GroupNS::Group &ezc3d::ParametersNS::Parameters::group(size_t idx) -{ +ezc3d::ParametersNS::GroupNS::Group& +ezc3d::ParametersNS::Parameters::group( + size_t idx) { try { return _groups.at(idx); } catch(std::out_of_range) { - throw std::out_of_range("Parameters::group method is trying to access the group " - + std::to_string(idx) + - " while the maximum number of groups is " - + std::to_string(nbGroups()) + "."); + throw std::out_of_range( + "Parameters::group method is trying to access the group " + + std::to_string(idx) + + " while the maximum number of groups is " + + std::to_string(nbGroups()) + "."); } } -const ezc3d::ParametersNS::GroupNS::Group &ezc3d::ParametersNS::Parameters::group(const std::string &groupName) const -{ +const ezc3d::ParametersNS::GroupNS::Group& +ezc3d::ParametersNS::Parameters::group( + const std::string &groupName) const { return group(groupIdx(groupName)); } -ezc3d::ParametersNS::GroupNS::Group &ezc3d::ParametersNS::Parameters::group(const std::string &groupName) -{ +ezc3d::ParametersNS::GroupNS::Group& +ezc3d::ParametersNS::Parameters::group( + const std::string &groupName) { return group(groupIdx(groupName)); } -void ezc3d::ParametersNS::Parameters::group(const ezc3d::ParametersNS::GroupNS::Group &g) -{ +void ezc3d::ParametersNS::Parameters::group( + const ezc3d::ParametersNS::GroupNS::Group &g) { // If the group already exist, override and merge size_t alreadyExtIdx(SIZE_MAX); for (size_t i = 0; i < nbGroups(); ++i) @@ -358,7 +408,7 @@ void ezc3d::ParametersNS::Parameters::group(const ezc3d::ParametersNS::GroupNS:: } } -const std::vector &ezc3d::ParametersNS::Parameters::groups() const -{ +const std::vector& +ezc3d::ParametersNS::Parameters::groups() const { return _groups; } diff --git a/src/Point.cpp b/src/Point.cpp index cf8e4bc6..b27afec6 100644 --- a/src/Point.cpp +++ b/src/Point.cpp @@ -14,8 +14,8 @@ ezc3d::DataNS::Points3dNS::Point::Point() _data.resize(4); } -ezc3d::DataNS::Points3dNS::Point::Point(const ezc3d::DataNS::Points3dNS::Point &p) -{ +ezc3d::DataNS::Points3dNS::Point::Point( + const ezc3d::DataNS::Points3dNS::Point &p) { _data.resize(4); x(p.x()); y(p.y()); @@ -23,71 +23,64 @@ ezc3d::DataNS::Points3dNS::Point::Point(const ezc3d::DataNS::Points3dNS::Point & residual(0); } -void ezc3d::DataNS::Points3dNS::Point::print() const -{ - std::cout << " Position = [" << x() << ", " << y() << ", " << z() << "]; Residual = " << residual() << std::endl; +void ezc3d::DataNS::Points3dNS::Point::print() const { + std::cout << " Position = [" << x() << ", " << y() << ", " << z() + << "]; Residual = " << residual() << std::endl; } -void ezc3d::DataNS::Points3dNS::Point::write(std::fstream &f) const -{ +void ezc3d::DataNS::Points3dNS::Point::write(std::fstream &f) const { f.write(reinterpret_cast(&_data[0]), ezc3d::DATA_TYPE::FLOAT); f.write(reinterpret_cast(&_data[1]), ezc3d::DATA_TYPE::FLOAT); f.write(reinterpret_cast(&_data[2]), ezc3d::DATA_TYPE::FLOAT); f.write(reinterpret_cast(&_data[3]), ezc3d::DATA_TYPE::FLOAT); } -const std::vector ezc3d::DataNS::Points3dNS::Point::data() const -{ +const std::vector ezc3d::DataNS::Points3dNS::Point::data() const { return _data; } -std::vector ezc3d::DataNS::Points3dNS::Point::data() -{ +std::vector ezc3d::DataNS::Points3dNS::Point::data() { return _data; } -float ezc3d::DataNS::Points3dNS::Point::x() const -{ +float ezc3d::DataNS::Points3dNS::Point::x() const { return _data[0]; } -void ezc3d::DataNS::Points3dNS::Point::x(float x) -{ +void ezc3d::DataNS::Points3dNS::Point::x( + float x) { _data[0] = x; } -float ezc3d::DataNS::Points3dNS::Point::y() const -{ +float ezc3d::DataNS::Points3dNS::Point::y() const { return _data[1]; } -void ezc3d::DataNS::Points3dNS::Point::y(float y) -{ +void ezc3d::DataNS::Points3dNS::Point::y( + float y) { _data[1] = y; } -float ezc3d::DataNS::Points3dNS::Point::z() const -{ +float ezc3d::DataNS::Points3dNS::Point::z() const { return _data[2]; } -void ezc3d::DataNS::Points3dNS::Point::z(float z) -{ +void ezc3d::DataNS::Points3dNS::Point::z( + float z) { _data[2] = z; } -float ezc3d::DataNS::Points3dNS::Point::residual() const -{ +float ezc3d::DataNS::Points3dNS::Point::residual() const { return _data[3]; } -void ezc3d::DataNS::Points3dNS::Point::residual(float residual){ +void ezc3d::DataNS::Points3dNS::Point::residual( + float residual) { _data[3] = residual; } -bool ezc3d::DataNS::Points3dNS::Point::isempty() const -{ +bool ezc3d::DataNS::Points3dNS::Point::isempty() const { if (static_cast(x()) == 0.0 && static_cast(y()) == 0.0 && static_cast(z()) == 0.0 && diff --git a/src/Points.cpp b/src/Points.cpp index 91808517..8f15d4fc 100644 --- a/src/Points.cpp +++ b/src/Points.cpp @@ -10,59 +10,60 @@ #include "Points.h" // Point3d data -ezc3d::DataNS::Points3dNS::Points::Points() -{ - +ezc3d::DataNS::Points3dNS::Points::Points() { } -ezc3d::DataNS::Points3dNS::Points::Points(size_t nbPoints) -{ +ezc3d::DataNS::Points3dNS::Points::Points( + size_t nbPoints) { _points.resize(nbPoints); } -void ezc3d::DataNS::Points3dNS::Points::print() const -{ +void ezc3d::DataNS::Points3dNS::Points::print() const { for (size_t i = 0; i < nbPoints(); ++i) point(i).print(); } -void ezc3d::DataNS::Points3dNS::Points::write(std::fstream &f) const -{ +void ezc3d::DataNS::Points3dNS::Points::write( + std::fstream &f) const { for (size_t i = 0; i < nbPoints(); ++i) point(i).write(f); } -size_t ezc3d::DataNS::Points3dNS::Points::nbPoints() const -{ +size_t ezc3d::DataNS::Points3dNS::Points::nbPoints() const { return _points.size(); } -const ezc3d::DataNS::Points3dNS::Point& ezc3d::DataNS::Points3dNS::Points::point(size_t idx) const -{ +const ezc3d::DataNS::Points3dNS::Point& +ezc3d::DataNS::Points3dNS::Points::point( + size_t idx) const { try { return _points.at(idx); } catch(std::out_of_range) { - throw std::out_of_range("Points::point method is trying to access the point " - + std::to_string(idx) + - " while the maximum number of points is " - + std::to_string(nbPoints()) + "."); + throw std::out_of_range( + "Points::point method is trying to access the point " + + std::to_string(idx) + + " while the maximum number of points is " + + std::to_string(nbPoints()) + "."); } } -ezc3d::DataNS::Points3dNS::Point &ezc3d::DataNS::Points3dNS::Points::point(size_t idx) -{ +ezc3d::DataNS::Points3dNS::Point& +ezc3d::DataNS::Points3dNS::Points::point( + size_t idx) { try { return _points.at(idx); } catch(std::out_of_range) { - throw std::out_of_range("Points::point method is trying to access the point " - + std::to_string(idx) + - " while the maximum number of points is " - + std::to_string(nbPoints()) + "."); + throw std::out_of_range( + "Points::point method is trying to access the point " + + std::to_string(idx) + + " while the maximum number of points is " + + std::to_string(nbPoints()) + "."); } } -void ezc3d::DataNS::Points3dNS::Points::point(const ezc3d::DataNS::Points3dNS::Point &point, size_t idx) -{ +void ezc3d::DataNS::Points3dNS::Points::point( + const ezc3d::DataNS::Points3dNS::Point &point, + size_t idx) { if (idx == SIZE_MAX) _points.push_back(point); else{ @@ -72,13 +73,12 @@ void ezc3d::DataNS::Points3dNS::Points::point(const ezc3d::DataNS::Points3dNS::P } } -const std::vector &ezc3d::DataNS::Points3dNS::Points::points() const -{ +const std::vector& +ezc3d::DataNS::Points3dNS::Points::points() const { return _points; } -bool ezc3d::DataNS::Points3dNS::Points::isempty() const -{ +bool ezc3d::DataNS::Points3dNS::Points::isempty() const { for (Point point : points()) if (!point.isempty()) return false; diff --git a/src/Subframe.cpp b/src/Subframe.cpp index b88e2350..c7d07cd7 100644 --- a/src/Subframe.cpp +++ b/src/Subframe.cpp @@ -9,61 +9,62 @@ #include "Subframe.h" -ezc3d::DataNS::AnalogsNS::SubFrame::SubFrame() -{ +ezc3d::DataNS::AnalogsNS::SubFrame::SubFrame() { } -void ezc3d::DataNS::AnalogsNS::SubFrame::print() const -{ +void ezc3d::DataNS::AnalogsNS::SubFrame::print() const { for (size_t i = 0; i < nbChannels(); ++i){ channel(i).print(); } } -void ezc3d::DataNS::AnalogsNS::SubFrame::write(std::fstream &f) const -{ +void ezc3d::DataNS::AnalogsNS::SubFrame::write( + std::fstream &f) const { for (size_t i = 0; i < nbChannels(); ++i){ channel(i).write(f); } } -size_t ezc3d::DataNS::AnalogsNS::SubFrame::nbChannels() const -{ +size_t ezc3d::DataNS::AnalogsNS::SubFrame::nbChannels() const { return _channels.size(); } -void ezc3d::DataNS::AnalogsNS::SubFrame::nbChannels(size_t nChannels) -{ +void ezc3d::DataNS::AnalogsNS::SubFrame::nbChannels( + size_t nChannels) { _channels.resize(nChannels); } -const ezc3d::DataNS::AnalogsNS::Channel &ezc3d::DataNS::AnalogsNS::SubFrame::channel(size_t idx) const -{ +const ezc3d::DataNS::AnalogsNS::Channel& +ezc3d::DataNS::AnalogsNS::SubFrame::channel(size_t idx) const { try { return _channels.at(idx); } catch(std::out_of_range) { - throw std::out_of_range("Subframe::channel method is trying to access the channel " - + std::to_string(idx) + - " while the maximum number of channels is " - + std::to_string(nbChannels()) + "."); + throw std::out_of_range( + "Subframe::channel method is trying to access the channel " + + std::to_string(idx) + + " while the maximum number of channels is " + + std::to_string(nbChannels()) + "."); } } -ezc3d::DataNS::AnalogsNS::Channel &ezc3d::DataNS::AnalogsNS::SubFrame::channel(size_t idx) -{ +ezc3d::DataNS::AnalogsNS::Channel& +ezc3d::DataNS::AnalogsNS::SubFrame::channel( + size_t idx) { try { return _channels.at(idx); } catch(std::out_of_range) { - throw std::out_of_range("Subframe::channel method is trying to access the channel " - + std::to_string(idx) + - " while the maximum number of channels is " - + std::to_string(nbChannels()) + "."); + throw std::out_of_range( + "Subframe::channel method is trying to access the channel " + + std::to_string(idx) + + " while the maximum number of channels is " + + std::to_string(nbChannels()) + "."); } } -void ezc3d::DataNS::AnalogsNS::SubFrame::channel(const ezc3d::DataNS::AnalogsNS::Channel &channel, size_t idx) -{ +void ezc3d::DataNS::AnalogsNS::SubFrame::channel( + const ezc3d::DataNS::AnalogsNS::Channel &channel, + size_t idx) { if (idx == SIZE_MAX) _channels.push_back(channel); else{ @@ -73,13 +74,12 @@ void ezc3d::DataNS::AnalogsNS::SubFrame::channel(const ezc3d::DataNS::AnalogsNS: } } -const std::vector &ezc3d::DataNS::AnalogsNS::SubFrame::channels() const -{ +const std::vector& +ezc3d::DataNS::AnalogsNS::SubFrame::channels() const { return _channels; } -bool ezc3d::DataNS::AnalogsNS::SubFrame::isempty() const -{ +bool ezc3d::DataNS::AnalogsNS::SubFrame::isempty() const { for (Channel channel : channels()) if (!channel.isempty()) return false; diff --git a/src/ezc3d.cpp b/src/ezc3d.cpp index 0a3b52a6..59f5091b 100644 --- a/src/ezc3d.cpp +++ b/src/ezc3d.cpp @@ -13,7 +13,8 @@ #include "Parameters.h" -void ezc3d::removeTrailingSpaces(std::string& s){ +void ezc3d::removeTrailingSpaces( + std::string& s) { // Remove the spaces at the end of the strings for (int i = static_cast(s.size()); i >= 0; --i) if (s.size() > 0 && s[s.size()-1] == ' ') @@ -22,7 +23,8 @@ void ezc3d::removeTrailingSpaces(std::string& s){ break; } -std::string ezc3d::toUpper(const std::string &str){ +std::string ezc3d::toUpper( + const std::string &str) { std::string new_str = str; std::transform(new_str.begin(), new_str.end(), new_str.begin(), ::toupper); return new_str; @@ -31,23 +33,23 @@ std::string ezc3d::toUpper(const std::string &str){ ezc3d::c3d::c3d(): _filePath(""), m_nByteToRead_float(4*ezc3d::DATA_TYPE::BYTE), - m_nByteToReadMax_int(100) -{ + m_nByteToReadMax_int(100) { c_float = new char[m_nByteToRead_float + 1]; c_float_tp = new char[m_nByteToRead_float + 1]; c_int = new char[m_nByteToReadMax_int + 1]; c_int_tp = new char[m_nByteToReadMax_int + 1]; _header = std::shared_ptr(new ezc3d::Header()); - _parameters = std::shared_ptr(new ezc3d::ParametersNS::Parameters()); + _parameters = std::shared_ptr( + new ezc3d::ParametersNS::Parameters()); _data = std::shared_ptr(new ezc3d::DataNS::Data()); } -ezc3d::c3d::c3d(const std::string &filePath): +ezc3d::c3d::c3d( + const std::string &filePath): _filePath(filePath), m_nByteToRead_float(4*ezc3d::DATA_TYPE::BYTE), - m_nByteToReadMax_int(100) -{ + m_nByteToReadMax_int(100) { std::fstream stream(_filePath, std::ios::in | std::ios::binary); c_float = new char[m_nByteToRead_float + 1]; c_float_tp = new char[m_nByteToRead_float + 1]; @@ -59,38 +61,40 @@ ezc3d::c3d::c3d(const std::string &filePath): // Read all the section _header = std::shared_ptr(new ezc3d::Header(*this, stream)); - _parameters = std::shared_ptr(new ezc3d::ParametersNS::Parameters(*this, stream)); + _parameters = std::shared_ptr( + new ezc3d::ParametersNS::Parameters(*this, stream)); - // header may be inconsistent with the parameters, so it must be update to make sure sizes are consistent + // header may be inconsistent with the parameters, so it must be + // update to make sure sizes are consistent updateHeader(); // Now read the data - _data = std::shared_ptr(new ezc3d::DataNS::Data(*this, stream)); + _data = std::shared_ptr( + new ezc3d::DataNS::Data(*this, stream)); - // Parameters and header may be inconsistent with data, so reprocess them if needed + // Parameters and header may be inconsistent with data, + // so reprocess them if needed updateParameters(); // Close the file stream.close(); } -ezc3d::c3d::~c3d() -{ +ezc3d::c3d::~c3d() { delete c_float; delete c_float_tp; delete c_int; delete c_int_tp; } -void ezc3d::c3d::print() const -{ +void ezc3d::c3d::print() const { header().print(); parameters().print(); data().print(); } -void ezc3d::c3d::write(const std::string& filePath) const -{ +void ezc3d::c3d::write( + const std::string& filePath) const { std::fstream f(filePath, std::ios::out | std::ios::binary); // Write the header @@ -98,9 +102,12 @@ void ezc3d::c3d::write(const std::string& filePath) const header().write(f, dataStartHeader); // Write the parameters - // We must copy parameters since there is no way to make sure that the number of frames is not higher than 0xFFFF + // We must copy parameters since there is no way to make sure that the + // number of frames is not higher than 0xFFFF ezc3d::ParametersNS::Parameters params(parameters()); - int nFrames(this->parameters().group("POINT").parameter("FRAMES").valuesAsInt()[0]); + int nFrames(this->parameters() + .group("POINT").parameter("FRAMES") + .valuesAsInt()[0]); if (nFrames > 0xFFFF){ ezc3d::ParametersNS::GroupNS::Parameter frames("FRAMES"); frames.set(-1); @@ -119,8 +126,8 @@ void ezc3d::c3d::write(const std::string& filePath) const f.close(); } -void ezc3d::c3d::resizeCharHolder(unsigned int nByteToRead) -{ +void ezc3d::c3d::resizeCharHolder( + unsigned int nByteToRead) { delete[] c_int; delete[] c_int_tp; m_nByteToReadMax_int = nByteToRead; @@ -128,23 +135,31 @@ void ezc3d::c3d::resizeCharHolder(unsigned int nByteToRead) c_int_tp = new char[m_nByteToReadMax_int + 1]; } -void ezc3d::c3d::readFile(std::fstream &file, unsigned int nByteToRead, char * c, int nByteFromPrevious, - const std::ios_base::seekdir &pos) -{ +void ezc3d::c3d::readFile( + std::fstream &file, + unsigned int nByteToRead, + char * c, + int nByteFromPrevious, + const std::ios_base::seekdir &pos) { if (pos != 1) file.seekg (nByteFromPrevious, pos); // Move to number analogs file.read (c, nByteToRead); c[nByteToRead] = '\0'; // Make sure last char is NULL } -unsigned int ezc3d::c3d::hex2uint(const char * val, unsigned int len){ +unsigned int ezc3d::c3d::hex2uint( + const char * val, + unsigned int len) { int ret(0); for (unsigned int i = 0; i < len; i++) - ret |= static_cast(static_cast(val[i])) * static_cast(pow(0x100, i)); + ret |= static_cast(static_cast(val[i])) + * static_cast(pow(0x100, i)); return static_cast(ret); } -int ezc3d::c3d::hex2int(const char * val, unsigned int len){ +int ezc3d::c3d::hex2int( + const char * val, + unsigned int len) { unsigned int tp(hex2uint(val, len)); // convert to signed int @@ -163,22 +178,29 @@ int ezc3d::c3d::hex2int(const char * val, unsigned int len){ return out; } -void ezc3d::c3d::writeDataStart(std::fstream &f, const std::streampos &dataStartPosition, const DATA_TYPE& type) const -{ - // Go back to data start blank space and write the current position (assuming current is the position of data!) +void ezc3d::c3d::writeDataStart( + std::fstream &f, + const std::streampos &dataStartPosition, + const DATA_TYPE& type) const { + // Go back to data start blank space and write the current + // position (assuming current is the position of data!) std::streampos dataPos = f.tellg(); f.seekg(dataStartPosition); if (int(dataPos) % 512 > 0) - throw std::out_of_range("Something went wrong in the positioning of the pointer for writting the data. " - "Please report this error."); + throw std::out_of_range( + "Something went wrong in the positioning of the pointer " + "for writting the data. Please report this error."); int nBlocksToNext = int(dataPos)/512 + 1; // DATA_START is 1-based f.write(reinterpret_cast(&nBlocksToNext), type); f.seekg(dataPos); } -int ezc3d::c3d::readInt(PROCESSOR_TYPE processorType, std::fstream &file, unsigned int nByteToRead, int nByteFromPrevious, - const std::ios_base::seekdir &pos) -{ +int ezc3d::c3d::readInt( + PROCESSOR_TYPE processorType, + std::fstream &file, + unsigned int nByteToRead, + int nByteFromPrevious, + const std::ios_base::seekdir &pos) { if (nByteToRead > m_nByteToReadMax_int) resizeCharHolder(nByteToRead); @@ -200,9 +222,12 @@ int ezc3d::c3d::readInt(PROCESSOR_TYPE processorType, std::fstream &file, unsign return out; } -size_t ezc3d::c3d::readUint(PROCESSOR_TYPE processorType, std::fstream &file, unsigned int nByteToRead, int nByteFromPrevious, - const std::ios_base::seekdir &pos) -{ +size_t ezc3d::c3d::readUint( + PROCESSOR_TYPE processorType, + std::fstream &file, + unsigned int nByteToRead, + int nByteFromPrevious, + const std::ios_base::seekdir &pos) { if (nByteToRead > m_nByteToReadMax_int) resizeCharHolder(nByteToRead); @@ -225,9 +250,11 @@ size_t ezc3d::c3d::readUint(PROCESSOR_TYPE processorType, std::fstream &file, un return out; } -float ezc3d::c3d::readFloat(PROCESSOR_TYPE processorType, std::fstream &file, int nByteFromPrevious, - const std::ios_base::seekdir &pos) -{ +float ezc3d::c3d::readFloat( + PROCESSOR_TYPE processorType, + std::fstream &file, + int nByteFromPrevious, + const std::ios_base::seekdir &pos) { readFile(file, m_nByteToRead_float, c_float, nByteFromPrevious, pos); float out; if (processorType == PROCESSOR_TYPE::INTEL) { @@ -253,9 +280,11 @@ float ezc3d::c3d::readFloat(PROCESSOR_TYPE processorType, std::fstream &file, in return out; } -std::string ezc3d::c3d::readString(std::fstream &file, unsigned int nByteToRead, int nByteFromPrevious, - const std::ios_base::seekdir &pos) -{ +std::string ezc3d::c3d::readString( + std::fstream &file, + unsigned int nByteToRead, + int nByteFromPrevious, + const std::ios_base::seekdir &pos) { if (nByteToRead > m_nByteToReadMax_int) resizeCharHolder(nByteToRead); @@ -266,34 +295,45 @@ std::string ezc3d::c3d::readString(std::fstream &file, unsigned int nByteToRead, return out; } -void ezc3d::c3d::readParam(PROCESSOR_TYPE processorType, std::fstream &file, unsigned int dataLenghtInBytes, const std::vector &dimension, - std::vector ¶m_data, size_t currentIdx) -{ +void ezc3d::c3d::readParam( + PROCESSOR_TYPE processorType, + std::fstream &file, + unsigned int dataLenghtInBytes, + const std::vector &dimension, + std::vector ¶m_data, size_t currentIdx) { for (size_t i = 0; i < dimension[currentIdx]; ++i) if (currentIdx == dimension.size()-1) - param_data.push_back (readInt(processorType, file, dataLenghtInBytes*ezc3d::DATA_TYPE::BYTE)); + param_data.push_back ( + readInt(processorType, file, + dataLenghtInBytes*ezc3d::DATA_TYPE::BYTE)); else - readParam(processorType, file, dataLenghtInBytes, dimension, param_data, currentIdx + 1); + readParam(processorType, file, dataLenghtInBytes, dimension, + param_data, currentIdx + 1); } -void ezc3d::c3d::readParam(PROCESSOR_TYPE processorType, std::fstream &file, const std::vector &dimension, - std::vector ¶m_data, size_t currentIdx) -{ +void ezc3d::c3d::readParam( + PROCESSOR_TYPE processorType, + std::fstream &file, + const std::vector &dimension, + std::vector ¶m_data, size_t currentIdx) { for (size_t i = 0; i < dimension[currentIdx]; ++i) if (currentIdx == dimension.size()-1) param_data.push_back (readFloat(processorType, file)); else - readParam(processorType, file, dimension, param_data, currentIdx + 1); + readParam(processorType, file, dimension, + param_data, currentIdx + 1); } -void ezc3d::c3d::readParam(std::fstream &file, const std::vector &dimension, - std::vector ¶m_data_string) -{ +void ezc3d::c3d::readParam( + std::fstream &file, + const std::vector &dimension, + std::vector ¶m_data_string) { std::vector param_data_string_tp; _readMatrix(file, dimension, param_data_string_tp); // Vicon c3d stores text length on first dimension, I am not sure if - // this is a standard or a custom made stuff. I implemented it like that for now + // this is a standard or a custom made stuff. + // I implemented it like that for now if (dimension.size() == 1){ if (dimension[0] != 0) { std::string tp; @@ -307,11 +347,11 @@ void ezc3d::c3d::readParam(std::fstream &file, const std::vector &dimens _dispatchMatrix(dimension, param_data_string_tp, param_data_string); } -size_t ezc3d::c3d::_dispatchMatrix(const std::vector &dimension, - const std::vector ¶m_data_in, - std::vector ¶m_data_out, size_t idxInParam, - size_t currentIdx) -{ +size_t ezc3d::c3d::_dispatchMatrix( + const std::vector &dimension, + const std::vector ¶m_data_in, + std::vector ¶m_data_out, size_t idxInParam, + size_t currentIdx) { for (size_t i = 0; i < dimension[currentIdx]; ++i) if (currentIdx == dimension.size()-1){ std::string tp; @@ -323,13 +363,16 @@ size_t ezc3d::c3d::_dispatchMatrix(const std::vector &dimension, param_data_out.push_back(tp); } else - idxInParam = _dispatchMatrix(dimension, param_data_in, param_data_out, idxInParam, currentIdx + 1); + idxInParam = _dispatchMatrix( + dimension, param_data_in, param_data_out, + idxInParam, currentIdx + 1); return idxInParam; } -void ezc3d::c3d::_readMatrix(std::fstream &file, const std::vector &dimension, - std::vector ¶m_data, size_t currentIdx) -{ +void ezc3d::c3d::_readMatrix( + std::fstream &file, + const std::vector &dimension, + std::vector ¶m_data, size_t currentIdx) { for (size_t i = 0; i < dimension[currentIdx]; ++i) if (currentIdx == dimension.size()-1) param_data.push_back(readString(file, ezc3d::DATA_TYPE::BYTE)); @@ -337,52 +380,49 @@ void ezc3d::c3d::_readMatrix(std::fstream &file, const std::vector &dime _readMatrix(file, dimension, param_data, currentIdx + 1); } -const ezc3d::Header& ezc3d::c3d::header() const -{ +const ezc3d::Header& ezc3d::c3d::header() const { return *_header; } -const ezc3d::ParametersNS::Parameters& ezc3d::c3d::parameters() const -{ +const ezc3d::ParametersNS::Parameters& ezc3d::c3d::parameters() const { return *_parameters; } -const ezc3d::DataNS::Data& ezc3d::c3d::data() const -{ +const ezc3d::DataNS::Data& ezc3d::c3d::data() const { return *_data; } -const std::vector &ezc3d::c3d::pointNames() const -{ +const std::vector &ezc3d::c3d::pointNames() const { return parameters().group("POINT").parameter("LABELS").valuesAsString(); } -size_t ezc3d::c3d::pointIdx(const std::string &pointName) const -{ +size_t ezc3d::c3d::pointIdx( + const std::string &pointName) const { const std::vector ¤tNames(pointNames()); for (size_t i = 0; i < currentNames.size(); ++i) if (!currentNames[i].compare(pointName)) return i; - throw std::invalid_argument("ezc3d::pointIdx could not find " + pointName + " in the points data set."); + throw std::invalid_argument("ezc3d::pointIdx could not find " + + pointName + " in the points data set."); } -const std::vector &ezc3d::c3d::channelNames() const -{ +const std::vector &ezc3d::c3d::channelNames() const { return parameters().group("ANALOG").parameter("LABELS").valuesAsString(); } -size_t ezc3d::c3d::channelIdx(const std::string &channelName) const -{ +size_t ezc3d::c3d::channelIdx( + const std::string &channelName) const { const std::vector ¤tNames(channelNames()); for (size_t i = 0; i < currentNames.size(); ++i) if (!currentNames[i].compare(channelName)) return i; - throw std::invalid_argument("ezc3d::channelIdx could not find " + channelName + - " in the analogous data set"); + throw std::invalid_argument("ezc3d::channelIdx could not find " + + channelName + " in the analogous data set"); } -void ezc3d::c3d::parameter(const std::string &groupName, const ezc3d::ParametersNS::GroupNS::Parameter &p) -{ +void ezc3d::c3d::parameter( + const std::string &groupName, + const ezc3d::ParametersNS::GroupNS::Parameter &p) { if (!p.name().compare("")){ throw std::invalid_argument("Parameter must have a name"); } @@ -397,51 +437,72 @@ void ezc3d::c3d::parameter(const std::string &groupName, const ezc3d::Parameters _parameters->group(idx).parameter(p); - // Do a sanity check on the header if important stuff like number of frames or number of elements is changed + // Do a sanity check on the header if important stuff like number + // of frames or number of elements is changed updateHeader(); } -void ezc3d::c3d::lockGroup(const std::string &groupName) -{ +void ezc3d::c3d::lockGroup( + const std::string &groupName) { _parameters->group(groupName).lock(); } -void ezc3d::c3d::unlockGroup(const std::string &groupName) -{ +void ezc3d::c3d::unlockGroup( + const std::string &groupName) { _parameters->group(groupName).unlock(); } -void ezc3d::c3d::frame(const ezc3d::DataNS::Frame &f, size_t idx) -{ +void ezc3d::c3d::frame( + const ezc3d::DataNS::Frame &f, + size_t idx) { // Make sure f.points().points() is the same as data.f[ANY].points() - size_t nPoints(static_cast(parameters().group("POINT").parameter("USED").valuesAsInt()[0])); + size_t nPoints(static_cast(parameters().group("POINT") + .parameter("USED").valuesAsInt()[0])); if (nPoints != 0 && f.points().nbPoints() != nPoints) - throw std::runtime_error("Number of points in POINT:USED parameter must equal" - "the number of points sent in the frame"); + throw std::runtime_error( + "Number of points in POINT:USED parameter must equal" + "the number of points sent in the frame"); - std::vector labels(parameters().group("POINT").parameter("LABELS").valuesAsString()); + std::vector labels(parameters().group("POINT") + .parameter("LABELS").valuesAsString()); for (size_t i=0; i 0 && static_cast(parameters().group("POINT").parameter("RATE").valuesAsFloat()[0]) == 0.0){ - throw std::runtime_error("Point frame rate must be specified if you add some"); + if (f.points().nbPoints() > 0 + && static_cast(parameters() + .group("POINT") + .parameter("RATE") + .valuesAsFloat()[0]) == 0.0) { + throw std::runtime_error( + "Point frame rate must be specified if you add some"); } - if (f.analogs().nbSubframes() > 0 && static_cast(parameters().group("ANALOG").parameter("RATE").valuesAsFloat()[0]) == 0.0){ - throw std::runtime_error("Analog frame rate must be specified if you add some"); + if (f.analogs().nbSubframes() > 0 + && static_cast(parameters() + .group("ANALOG") + .parameter("RATE") + .valuesAsFloat()[0]) == 0.0) { + throw std::runtime_error( + "Analog frame rate must be specified if you add some"); } - size_t nAnalogs(static_cast(parameters().group("ANALOG").parameter("USED").valuesAsInt()[0])); + size_t nAnalogs(static_cast(parameters() + .group("ANALOG") + .parameter("USED") + .valuesAsInt()[0])); size_t subSize(f.analogs().nbSubframes()); if (subSize != 0){ size_t nChannel(f.analogs().subframe(0).nbChannels()); size_t nAnalogByFrames(header().nbAnalogByFrame()); if (!(nAnalogs==0 && nAnalogByFrames==0) && nChannel != nAnalogs ) - throw std::runtime_error("Number of analogs in ANALOG:USED parameter must equal " - "the number of analogs sent in the frame"); + throw std::runtime_error( + "Number of analogs in ANALOG:USED parameter must equal " + "the number of analogs sent in the frame"); } // Replace the jth frame @@ -449,7 +510,8 @@ void ezc3d::c3d::frame(const ezc3d::DataNS::Frame &f, size_t idx) updateParameters(); } -void ezc3d::c3d::point(const std::string &name){ +void ezc3d::c3d::point( + const std::string &name) { if (data().nbFrames() > 0){ std::vector dummy_frames; ezc3d::DataNS::Points3dNS::Points dummy_pts; @@ -465,17 +527,21 @@ void ezc3d::c3d::point(const std::string &name){ } } -void ezc3d::c3d::point(const std::string& pointName, const std::vector& frames){ +void ezc3d::c3d::point( + const std::string& pointName, + const std::vector& frames) { std::vector names; names.push_back(pointName); point(names, frames); } -void ezc3d::c3d::point(const std::vector& ptsNames, const std::vector& frames) -{ +void ezc3d::c3d::point( + const std::vector& ptsNames, + const std::vector& frames) { if (frames.size() == 0 || frames.size() != data().nbFrames()) - throw std::invalid_argument("Size of the array of frames must equal the number of frames already " - "present in the data set"); + throw std::invalid_argument( + "Size of the array of frames must equal the number of " + "frames already present in the data set"); if (frames[0].points().nbPoints() == 0) throw std::invalid_argument("Points in the frames cannot be empty"); @@ -484,7 +550,9 @@ void ezc3d::c3d::point(const std::vector& ptsNames, const std::vect for (size_t idx = 0; idxframe(f).points().point(frames[f].points().point(idx)); @@ -492,8 +560,8 @@ void ezc3d::c3d::point(const std::vector& ptsNames, const std::vect updateParameters(ptsNames); } -void ezc3d::c3d::analog(const std::string &name) -{ +void ezc3d::c3d::analog( + const std::string &name) { if (data().nbFrames() > 0){ std::vector dummy_frames; ezc3d::DataNS::AnalogsNS::SubFrame dummy_subframes; @@ -511,21 +579,25 @@ void ezc3d::c3d::analog(const std::string &name) } } -void ezc3d::c3d::analog(std::string channelName, const std::vector &frames) -{ +void ezc3d::c3d::analog( + std::string channelName, + const std::vector &frames) { std::vector names; names.push_back(channelName); analog(names, frames); } -void ezc3d::c3d::analog(const std::vector &chanNames, const std::vector &frames) -{ +void ezc3d::c3d::analog( + const std::vector &chanNames, + const std::vector &frames) { if (frames.size() != data().nbFrames()) - throw std::invalid_argument("Size of the array of frames must equal the number of frames already " - "present in the data set"); + throw std::invalid_argument( + "Size of the array of frames must equal the number of " + "frames already present in the data set"); if (frames[0].analogs().nbSubframes() != header().nbAnalogByFrame()) - throw std::invalid_argument("Size of the subframes in the frames must equal the number of subframes " - "already present in the data set"); + throw std::invalid_argument( + "Size of the subframes in the frames must equal the " + "number of subframes already present in the data set"); if (frames[0].analogs().subframe(0).nbChannels() == 0) throw std::invalid_argument("Channels in the frame cannot be empty"); @@ -533,63 +605,103 @@ void ezc3d::c3d::analog(const std::vector &chanNames, const std::ve for (size_t idx = 0; idx < chanNames.size(); ++idx){ for (size_t i=0; iframe(f).analogs().subframe(sf).channel(frames[f].analogs().subframe(sf).channel(idx)); + _data->frame(f).analogs().subframe(sf) + .channel(frames[f].analogs().subframe(sf).channel(idx)); } } } updateParameters({}, chanNames); } -void ezc3d::c3d::updateHeader() -{ +void ezc3d::c3d::updateHeader() { // Parameter is always consider as the right value. - if (static_cast(parameters().group("POINT").parameter("FRAMES").valuesAsInt()[0]) != header().nbFrames()){ - // If there is a discrepancy between them, change the header, while keeping the firstFrame value - _header->lastFrame(static_cast(parameters().group("POINT").parameter("FRAMES").valuesAsInt()[0]) + _header->firstFrame() - 1); + if (static_cast(parameters() + .group("POINT").parameter("FRAMES") + .valuesAsInt()[0]) != header().nbFrames()){ + // If there is a discrepancy between them, change the header, + // while keeping the firstFrame value + _header->lastFrame( + static_cast(parameters() + .group("POINT").parameter("FRAMES") + .valuesAsInt()[0]) + + _header->firstFrame() - 1); } - float pointRate(parameters().group("POINT").parameter("RATE").valuesAsFloat()[0]); + float pointRate(parameters() + .group("POINT") + .parameter("RATE").valuesAsFloat()[0]); float buffer(10000); // For decimal truncature - if (static_cast(pointRate*buffer) != static_cast(header().frameRate()*buffer)){ + if (static_cast(pointRate*buffer) != static_cast( + header().frameRate()*buffer)){ // If there are points but the rate don't match keep the one from header - if (static_cast(parameters().group("POINT").parameter("RATE").valuesAsFloat()[0]) == 0.0 && parameters().group("POINT").parameter("USED").valuesAsInt()[0] != 0){ + if (static_cast(parameters() + .group("POINT").parameter("RATE") + .valuesAsFloat()[0]) + == 0.0 && parameters() + .group("POINT") + .parameter("USED").valuesAsInt()[0] != 0){ ezc3d::ParametersNS::GroupNS::Parameter rate("RATE"); rate.set(header().frameRate()); parameter("POINT", rate); } else _header->frameRate(pointRate); } - if (static_cast(parameters().group("POINT").parameter("USED").valuesAsInt()[0]) != header().nb3dPoints()){ - _header->nb3dPoints(static_cast(parameters().group("POINT").parameter("USED").valuesAsInt()[0])); + if (static_cast(parameters() + .group("POINT").parameter("USED") + .valuesAsInt()[0]) != header().nb3dPoints()){ + _header->nb3dPoints(static_cast( + parameters() + .group("POINT").parameter("USED") + .valuesAsInt()[0])); } - // Compare the subframe with data when possible, otherwise go with the parameters - if (_data != nullptr && data().nbFrames() > 0 && data().frame(0).analogs().nbSubframes() != 0) { - if (data().frame(0).analogs().nbSubframes() != static_cast(header().nbAnalogByFrame())) + // Compare the subframe with data when possible, + // otherwise go with the parameters + if (_data != nullptr && data().nbFrames() > 0 + && data().frame(0).analogs().nbSubframes() != 0) { + if (data().frame(0).analogs().nbSubframes() + != static_cast(header().nbAnalogByFrame())) _header->nbAnalogByFrame(data().frame(0).analogs().nbSubframes()); } else { if (static_cast(pointRate) == 0){ if (static_cast(header().nbAnalogByFrame()) != 1) _header->nbAnalogByFrame(1); } else { - if (static_cast(parameters().group("ANALOG").parameter("RATE").valuesAsFloat()[0] / pointRate) != static_cast(header().nbAnalogByFrame())) - _header->nbAnalogByFrame(static_cast(parameters().group("ANALOG").parameter("RATE").valuesAsFloat()[0] / pointRate)); + if (static_cast(parameters() + .group("ANALOG").parameter("RATE") + .valuesAsFloat()[0] / pointRate) + != static_cast(header().nbAnalogByFrame())) + _header->nbAnalogByFrame( + static_cast( + parameters() + .group("ANALOG").parameter("RATE") + .valuesAsFloat()[0] / pointRate)); } } - if (static_cast(parameters().group("ANALOG").parameter("USED").valuesAsInt()[0]) != header().nbAnalogs()) - _header->nbAnalogs(static_cast(parameters().group("ANALOG").parameter("USED").valuesAsInt()[0])); + if (static_cast(parameters() + .group("ANALOG").parameter("USED") + .valuesAsInt()[0]) != header().nbAnalogs()) + _header->nbAnalogs( + static_cast(parameters() + .group("ANALOG").parameter("USED") + .valuesAsInt()[0])); } -void ezc3d::c3d::updateParameters(const std::vector &newPoints, const std::vector &newAnalogs) -{ +void ezc3d::c3d::updateParameters( + const std::vector &newPoints, + const std::vector &newAnalogs) { // If frames has been added - ezc3d::ParametersNS::GroupNS::Group& grpPoint(_parameters->group(parameters().groupIdx("POINT"))); + ezc3d::ParametersNS::GroupNS::Group& grpPoint( + _parameters->group(parameters().groupIdx("POINT"))); size_t nFrames(data().nbFrames()); - if (nFrames != static_cast(grpPoint.parameter("FRAMES").valuesAsInt()[0])){ + if (nFrames != static_cast( + grpPoint.parameter("FRAMES").valuesAsInt()[0])){ size_t idx(grpPoint.parameterIdx("FRAMES")); grpPoint.parameter(idx).set(nFrames); } @@ -599,8 +711,11 @@ void ezc3d::c3d::updateParameters(const std::vector &newPoints, con if (data().nbFrames() > 0) nPoints = data().frame(0).points().nbPoints(); else - nPoints = parameters().group("POINT").parameter("LABELS").valuesAsString().size() + newPoints.size(); - if (nPoints != static_cast(grpPoint.parameter("USED").valuesAsInt()[0])){ + nPoints = parameters() + .group("POINT").parameter("LABELS") + .valuesAsString().size() + newPoints.size(); + if (nPoints != static_cast( + grpPoint.parameter("USED").valuesAsInt()[0])){ grpPoint.parameter("USED").set(nPoints); size_t idxLabels(grpPoint.parameterIdx("LABELS")); @@ -614,10 +729,16 @@ void ezc3d::c3d::updateParameters(const std::vector &newPoints, con for (size_t i = 0; i < nPoints; ++i){ std::string name; if (data().nbFrames() == 0){ - if (i < parameters().group("POINT").parameter("LABELS").valuesAsString().size()) - name = parameters().group("POINT").parameter("LABELS").valuesAsString()[i]; + if (i < parameters() + .group("POINT").parameter("LABELS") + .valuesAsString().size()) + name = parameters() + .group("POINT").parameter("LABELS") + .valuesAsString()[i]; else - name = newPoints[i - parameters().group("POINT").parameter("LABELS").valuesAsString().size()]; + name = newPoints[i - parameters() + .group("POINT").parameter("LABELS") + .valuesAsString().size()]; } else { name = ptsNames[i]; removeTrailingSpaces(name); @@ -632,7 +753,8 @@ void ezc3d::c3d::updateParameters(const std::vector &newPoints, con } // If analogous data has been added - ezc3d::ParametersNS::GroupNS::Group& grpAnalog(_parameters->group(parameters().groupIdx("ANALOG"))); + ezc3d::ParametersNS::GroupNS::Group& grpAnalog( + _parameters->group(parameters().groupIdx("ANALOG"))); size_t nAnalogs; if (data().nbFrames() > 0){ if (data().frame(0).analogs().nbSubframes() > 0) @@ -640,26 +762,39 @@ void ezc3d::c3d::updateParameters(const std::vector &newPoints, con else nAnalogs = 0; } else - nAnalogs = parameters().group("ANALOG").parameter("LABELS").valuesAsString().size() + newAnalogs.size(); + nAnalogs = parameters() + .group("ANALOG").parameter("LABELS") + .valuesAsString().size() + newAnalogs.size(); - // Should always be greater than 0..., but we have to take in account Optotrak lazyness + // Should always be greater than 0..., but we have to take in + // account Optotrak lazyness if (parameters().group("ANALOG").nbParameters()){ - if (nAnalogs != static_cast(grpAnalog.parameter("USED").valuesAsInt()[0])){ + if (nAnalogs != static_cast( + grpAnalog.parameter("USED").valuesAsInt()[0])){ grpAnalog.parameter("USED").set(nAnalogs); - size_t idxLabels(static_cast(grpAnalog.parameterIdx("LABELS"))); - size_t idxDescriptions(static_cast(grpAnalog.parameterIdx("DESCRIPTIONS"))); + size_t idxLabels(static_cast( + grpAnalog.parameterIdx("LABELS"))); + size_t idxDescriptions(static_cast( + grpAnalog.parameterIdx("DESCRIPTIONS"))); std::vector labels; std::vector descriptions; std::vector chanNames(channelNames()); - chanNames.insert( chanNames.end(), newAnalogs.begin(), newAnalogs.end() ); + chanNames.insert( + chanNames.end(), newAnalogs.begin(), newAnalogs.end() ); for (size_t i = 0; i &newPoints, con grpAnalog.parameter(idxDescriptions).set(descriptions); size_t idxScale(grpAnalog.parameterIdx("SCALE")); - std::vector scales(grpAnalog.parameter(idxScale).valuesAsFloat()); - for (size_t i = grpAnalog.parameter(idxScale).valuesAsFloat().size(); i < nAnalogs; ++i) + std::vector scales(grpAnalog.parameter( + idxScale).valuesAsFloat()); + for (size_t i = grpAnalog.parameter( + idxScale).valuesAsFloat().size(); i < nAnalogs; ++i) scales.push_back(1); grpAnalog.parameter(idxScale).set(scales); size_t idxOffset(grpAnalog.parameterIdx("OFFSET")); - std::vector offset(grpAnalog.parameter(idxOffset).valuesAsInt()); - for (size_t i = grpAnalog.parameter(idxOffset).valuesAsInt().size(); i < nAnalogs; ++i) + std::vector offset( + grpAnalog.parameter(idxOffset).valuesAsInt()); + for (size_t i = grpAnalog.parameter(idxOffset).valuesAsInt().size() + ; i < nAnalogs; ++i) offset.push_back(0); grpAnalog.parameter(idxOffset).set(offset); size_t idxUnits(grpAnalog.parameterIdx("UNITS")); - std::vector units(grpAnalog.parameter(idxUnits).valuesAsString()); - for (size_t i = grpAnalog.parameter(idxUnits).valuesAsString().size(); i < nAnalogs; ++i) + std::vector units(grpAnalog.parameter( + idxUnits).valuesAsString()); + for (size_t i = grpAnalog.parameter(idxUnits) + .valuesAsString().size(); i < nAnalogs; ++i) units.push_back("V"); grpAnalog.parameter(idxUnits).set(units); }