Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use HIDE_SYMBOLS_BY_DEFAULT, fix MovingWindowFilter #566

Merged
merged 5 commits into from
Nov 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ set(FAKE_INSTALL_PREFIX "${CMAKE_BINARY_DIR}/fake/install")
# Configure the build
#============================================================================
gz_configure_build(QUIT_IF_BUILD_ERRORS
HIDE_SYMBOLS_BY_DEFAULT
COMPONENTS eigen3)


Expand Down
115 changes: 114 additions & 1 deletion include/gz/math/MovingWindowFilter.hh
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ namespace gz
///
/// The default window size is 4.
template< typename T>
class GZ_MATH_VISIBLE MovingWindowFilter
class MovingWindowFilter
{
/// \brief Constructor
public: MovingWindowFilter(unsigned int _windowSize = 4);
Expand Down Expand Up @@ -90,6 +90,119 @@ namespace gz
using MovingWindowFilterVector3f = MovingWindowFilter<Vector3f>;
using MovingWindowFilterVector3d = MovingWindowFilter<Vector3d>;
}

//////////////////////////////////////////////////
template<typename T>
MovingWindowFilter<T>::MovingWindowFilter(unsigned int _windowSize)
{
this->SetWindowSize(_windowSize);
}

//////////////////////////////////////////////////
template<typename T>
void MovingWindowFilter<T>::Update(const T _val)
{
// update sum and sample size with incoming _val

// keep running sum
this->sum += _val;

// shift pointer, wrap around if end has been reached.
++this->valIter;
if (this->valIter == this->valHistory.end())
{
// reset iterator to beginning of queue
this->valIter = this->valHistory.begin();
}

// increment sample size
++this->samples;

if (this->samples > this->valWindowSize)
{
// subtract old value if buffer already filled
this->sum -= (*this->valIter);
// put new value into queue
(*this->valIter) = _val;
// reduce sample size
--this->samples;
}
else
{
// put new value into queue
(*this->valIter) = _val;
}
}

//////////////////////////////////////////////////
template<typename T>
void MovingWindowFilter<T>::SetWindowSize(const unsigned int _n)
{
this->valWindowSize = _n;
this->valHistory = std::vector<T>(_n, T());
this->valIter = this->valHistory.begin();
this->sum = T();
this->samples = 0;
}

//////////////////////////////////////////////////
template<typename T>
unsigned int MovingWindowFilter<T>::WindowSize() const
{
return this->valWindowSize;
}

//////////////////////////////////////////////////
template<typename T>
bool MovingWindowFilter<T>::WindowFilled() const
{
return this->samples == this->valWindowSize;
}

//////////////////////////////////////////////////
template<>
inline gz::math::Vector3i
MovingWindowFilter<gz::math::Vector3i>::Value() const
{
auto value = this->sum / this->samples;
return value;
}

//////////////////////////////////////////////////
template<>
inline gz::math::Vector3f
MovingWindowFilter<gz::math::Vector3f>::Value() const
{
gz::math::Vector3f divisor;
divisor = static_cast<float>(this->samples);
auto value = this->sum / divisor;
return value;
}

//////////////////////////////////////////////////
template<>
inline gz::math::Vector3d
MovingWindowFilter<gz::math::Vector3d>::Value() const
{
auto value = this->sum / this->samples;
return value;
}

//////////////////////////////////////////////////
template<typename T>
T MovingWindowFilter<T>::Value() const
{
if (std::is_integral_v<T>)
{
auto value = this->sum / this->samples;
return T(value);
}
else
{
auto value = this->sum / static_cast<double>(this->samples);
return T(value);
}
}
} // namespace math
} // namespace gz
#endif
149 changes: 0 additions & 149 deletions src/MovingWindowFilter.cc

This file was deleted.