Tesseract 0.28.4
Loading...
Searching...
No Matches
utils.h File Reference

Common Tesseract Utility Functions. More...

#include <tesseract/common/macros.h>
#include <array>
#include <vector>
#include <set>
#include <string>
#include <sstream>
#include <stdexcept>
#include <random>
#include <algorithm>
#include <unordered_set>
#include <cstdint>
#include <cstring>
#include <type_traits>
#include <Eigen/Core>
#include <Eigen/Geometry>
#include <tesseract/common/allowed_collision_matrix.h>
#include <filesystem>

Namespaces

namespace  tesseract::common
 Namespace owning boost's hash_is_avalanching, and defined iff boost has the trait at all.
 

Functions

template<typename... Args>
std::string tesseract::common::strFormat (const std::string &format, Args... args)
 
template<typename T >
void tesseract::common::appendBytes (std::vector< std::uint8_t > &buf, const T &value)
 Append the raw bytes of a trivially-copyable value to a byte buffer (native byte order).
 
template<typename T >
T tesseract::common::readBytes (const std::vector< std::uint8_t > &buf, std::size_t &offset)
 Read a trivially-copyable value from a byte buffer at offset, advancing it.
 
std::string tesseract::common::fileToString (const std::filesystem::path &filepath)
 Read in the contents of the file into a string.
 
void tesseract::common::twistChangeRefPoint (Eigen::Ref< Eigen::VectorXd > twist, const Eigen::Ref< const Eigen::Vector3d > &ref_point)
 Change the reference point of the provided Twist.
 
void tesseract::common::twistChangeBase (Eigen::Ref< Eigen::VectorXd > twist, const Eigen::Isometry3d &change_base)
 Change the base coordinate system of the Twist.
 
void tesseract::common::jacobianChangeBase (Eigen::Ref< Eigen::MatrixXd > jacobian, const Eigen::Isometry3d &change_base)
 Change the base coordinate system of the jacobian.
 
void tesseract::common::jacobianChangeRefPoint (Eigen::Ref< Eigen::MatrixXd > jacobian, const Eigen::Ref< const Eigen::Vector3d > &ref_point)
 Change the reference point of the jacobian.
 
Eigen::VectorXd tesseract::common::concat (const Eigen::VectorXd &a, const Eigen::VectorXd &b)
 Concatenate two vector.
 
Eigen::Vector3d tesseract::common::calcRotationalError (const Eigen::Ref< const Eigen::Matrix3d > &R)
 Calculate the rotation error vector given a rotation error matrix where the angle is between [-pi, pi].
 
Eigen::VectorXd tesseract::common::calcTransformError (const Eigen::Isometry3d &t1, const Eigen::Isometry3d &t2)
 Calculate error between two transforms expressed in t1 coordinate system.
 
Eigen::VectorXd tesseract::common::calcJacobianTransformErrorDiff (const Eigen::Isometry3d &target, const Eigen::Isometry3d &source, const Eigen::Isometry3d &source_perturbed)
 Calculate jacobian transform error difference expressed in the target frame coordinate system.
 
Eigen::VectorXd tesseract::common::calcJacobianTransformErrorDiff (const Eigen::Isometry3d &target, const Eigen::Isometry3d &source, const Eigen::Isometry3d &source_perturbed, const Eigen::Ref< const Eigen::VectorXd > &lower_tolerance, const Eigen::Ref< const Eigen::VectorXd > &upper_tolerance)
 Calculate jacobian transform error difference with optional per-component dead-band tolerances.
 
Eigen::VectorXd tesseract::common::calcJacobianTransformErrorDiff (const Eigen::Isometry3d &target, const Eigen::Isometry3d &target_perturbed, const Eigen::Isometry3d &source, const Eigen::Isometry3d &source_perturbed)
 Calculate jacobian transform error difference expressed in the target frame coordinate system.
 
Eigen::VectorXd tesseract::common::calcJacobianTransformErrorDiff (const Eigen::Isometry3d &target, const Eigen::Isometry3d &target_perturbed, const Eigen::Isometry3d &source, const Eigen::Isometry3d &source_perturbed, const Eigen::Ref< const Eigen::VectorXd > &lower_tolerance, const Eigen::Ref< const Eigen::VectorXd > &upper_tolerance)
 Calculate jacobian transform error difference (dynamic target) with optional per-component dead-band tolerances.
 
void tesseract::common::applyTolerances (Eigen::Ref< Eigen::VectorXd > v, const Eigen::Ref< const Eigen::VectorXd > &lower_tolerance, const Eigen::Ref< const Eigen::VectorXd > &upper_tolerance)
 Apply a per-component dead-band tolerance to an error vector in place.
 
Eigen::Vector4d tesseract::common::computeRandomColor ()
 This computes a random color RGBA [0, 1] with alpha set to 1.
 
void tesseract::common::printNestedException (const std::exception &e, int level=0)
 Print a nested exception.
 
std::string tesseract::common::getTempPath ()
 Get the host temp directory path.
 
bool tesseract::common::isNumeric (const std::string &s)
 Determine if a string is a number.
 
bool tesseract::common::isNumeric (const std::vector< std::string > &sv)
 Determine if each string in vector is a number.
 
Eigen::VectorXd tesseract::common::generateRandomNumber (const Eigen::Ref< const Eigen::MatrixX2d > &limits)
 Given a set of limits it will generate a vector of random numbers between the limit.
 
void tesseract::common::ltrim (std::string &s)
 Left trim string.
 
void tesseract::common::rtrim (std::string &s)
 Right trim string.
 
void tesseract::common::trim (std::string &s)
 Trim left and right of string.
 
template<typename T >
bool tesseract::common::isIdentical (const std::vector< T > &vec1, const std::vector< T > &vec2, bool ordered=true, const std::function< bool(const T &, const T &)> &equal_pred=[](const T &v1, const T &v2) { return v1==v2;}, const std::function< bool(const T &, const T &)> &comp=[](const T &v1, const T &v2) { return v1< v2;})
 Check if two vector of strings are identical.
 
template<typename KeyValueContainerType , typename ValueType >
bool tesseract::common::isIdenticalMap (const KeyValueContainerType &map_1, const KeyValueContainerType &map_2, const std::function< bool(const ValueType &, const ValueType &)> &value_eq=[](const ValueType &v1, const ValueType &v2) { return v1==v2;})
 Checks if 2 maps are identical.
 
template<typename ValueType >
bool tesseract::common::isIdenticalSet (const std::set< ValueType > &set_1, const std::set< ValueType > &set_2, const std::function< bool(const ValueType &, const ValueType &)> &value_eq=[](const ValueType &v1, const ValueType &v2) { return v1==v2;})
 Checks if 2 sets are identical.
 
template<typename ValueType , std::size_t Size>
bool tesseract::common::isIdenticalArray (const std::array< ValueType, Size > &array_1, const std::array< ValueType, Size > &array_2, const std::function< bool(const ValueType &, const ValueType &)> &value_eq=[](const ValueType &v1, const ValueType &v2) { return v1==v2;})
 Checks if 2 arrays are identical.
 
template<typename T >
bool tesseract::common::pointersEqual (const std::shared_ptr< T > &p1, const std::shared_ptr< T > &p2)
 Checks if 2 pointers point to objects that are ==.
 
template<typename T >
bool tesseract::common::pointersComparison (const std::shared_ptr< T > &p1, const std::shared_ptr< T > &p2)
 Comparison operator for the objects 2 points point to.
 
std::string tesseract::common::getTimestampString ()
 Get Timestamp string.
 
void tesseract::common::reorder (Eigen::Ref< Eigen::VectorXd > v, std::vector< Eigen::Index > order)
 Reorder Eigen::VectorXd implace given index list.
 
int tesseract::common::QueryStringValue (const tinyxml2::XMLElement *xml_element, std::string &value)
 Query a string value from xml element.
 
int tesseract::common::QueryStringText (const tinyxml2::XMLElement *xml_element, std::string &text)
 Query a string Text from xml element.
 
int tesseract::common::QueryStringValue (const tinyxml2::XMLAttribute *xml_attribute, std::string &value)
 Query a string value from xml attribute.
 
int tesseract::common::QueryStringAttribute (const tinyxml2::XMLElement *xml_element, const char *name, std::string &value)
 Query a string attribute from an xml element.
 
std::string tesseract::common::StringAttribute (const tinyxml2::XMLElement *xml_element, const char *name, std::string default_value)
 Get string attribute if exist. If it does not exist it returns the default value.
 
int tesseract::common::QueryStringAttributeRequired (const tinyxml2::XMLElement *xml_element, const char *name, std::string &value)
 Query a string attribute from an xml element and print error log.
 
int tesseract::common::QueryDoubleAttributeRequired (const tinyxml2::XMLElement *xml_element, const char *name, double &value)
 Query a double attribute from an xml element and print error log.
 
int tesseract::common::QueryIntAttributeRequired (const tinyxml2::XMLElement *xml_element, const char *name, int &value)
 Query a int attribute from an xml element and print error log.
 
bool tesseract::common::almostEqualRelativeAndAbs (double a, double b, double max_diff=1e-6, double max_rel_diff=std::numeric_limits< double >::epsilon())
 Check if two double are relatively equal.
 
bool tesseract::common::almostEqualRelativeAndAbs (const Eigen::Ref< const Eigen::VectorXd > &v1, const Eigen::Ref< const Eigen::VectorXd > &v2, double max_diff=1e-6, double max_rel_diff=std::numeric_limits< double >::epsilon())
 Check if two Eigen VectorXd are relatively and absolute equal.
 
bool tesseract::common::almostEqualRelativeAndAbs (const Eigen::Ref< const Eigen::VectorXd > &v1, const Eigen::Ref< const Eigen::VectorXd > &v2, const Eigen::Ref< const Eigen::VectorXd > &max_diff, const Eigen::Ref< const Eigen::VectorXd > &max_rel_diff)
 Check if two Eigen VectorXd are relatively and absolute equal.
 
template<typename FloatType >
bool tesseract::common::toNumeric (const std::string &s, FloatType &value)
 Convert a string to a numeric value type.
 
template<class T , class Hash = std::hash<T>, class Eq = std::equal_to<T>>
void tesseract::common::removeDuplicates (std::vector< T > &v)
 Remove duplicates and keep first.
 
std::vector< LinkIdtesseract::common::getAllowedCollisions (const std::vector< LinkId > &link_ids, const AllowedCollisionEntries &acm_entries, bool remove_duplicates=true)
 Gets allowed collisions for a set of link ids.
 
template<typename To , typename From >
To tesseract::common::numeric_cast (From value)
 Safely cast a number from one type to another, checking for overflow and underflow.
 

Variables

thread_local std::mt19937 tesseract::common::mersenne { std::random_device{}() }
 Random number generator, one independently seeded instance per thread.
 

Detailed Description

Common Tesseract Utility Functions.

Author
Levi Armstrong
Date
January 18, 2018
License
Software License Agreement (Apache License)
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.