From a5cc3bcd46c4a1ff3d5317ddfbfb822bdf9fab45 Mon Sep 17 00:00:00 2001 From: Valenza Florian <fvalenza@laas.fr> Date: Fri, 5 Feb 2016 17:02:30 +0100 Subject: [PATCH] [C++][Frame] Moved the generation of random string in a new file. Modified the default constructor of frame to produce unique frame (as long as the random strings generated are unique) --- CMakeLists.txt | 1 + src/multibody/model.hpp | 1 + src/multibody/model.hxx | 13 +----------- src/spatial/frame.hpp | 3 ++- src/tools/string-generator.hpp | 39 ++++++++++++++++++++++++++++++++++ 5 files changed, 44 insertions(+), 13 deletions(-) create mode 100644 src/tools/string-generator.hpp diff --git a/CMakeLists.txt b/CMakeLists.txt index b8e97d824..9e86d1c45 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -83,6 +83,7 @@ SET(${PROJECT_NAME}_MATH_HEADERS SET(${PROJECT_NAME}_TOOLS_HEADERS tools/timer.hpp + tools/string-generator.hpp ) SET(${PROJECT_NAME}_SPATIAL_HEADERS diff --git a/src/multibody/model.hpp b/src/multibody/model.hpp index 24d7f8fdc..e43c03d7f 100644 --- a/src/multibody/model.hpp +++ b/src/multibody/model.hpp @@ -27,6 +27,7 @@ #include "pinocchio/spatial/inertia.hpp" #include "pinocchio/spatial/frame.hpp" #include "pinocchio/multibody/joint/joint-variant.hpp" +#include "pinocchio/tools/string-generator.hpp" #include <iostream> EIGEN_DEFINE_STL_VECTOR_SPECIALIZATION(se3::SE3) diff --git a/src/multibody/model.hxx b/src/multibody/model.hxx index 4e154279b..16d182119 100644 --- a/src/multibody/model.hxx +++ b/src/multibody/model.hxx @@ -43,18 +43,7 @@ namespace se3 return os; } - inline std::string random (const int len) - { - std::string res; - static const char alphanum[] = - "0123456789" - "ABCDEFGHIJKLMNOPQRSTUVWXYZ" - "abcdefghijklmnopqrstuvwxyz"; - - for (int i=0; i<len;++i) - res += alphanum[((size_t)std::rand() % (sizeof(alphanum) - 1))]; - return res; - } + template<typename D> Model::Index Model::addBody (Index parent, const JointModelBase<D> & j, const SE3 & placement, diff --git a/src/spatial/frame.hpp b/src/spatial/frame.hpp index ee4918866..45584baf1 100644 --- a/src/spatial/frame.hpp +++ b/src/spatial/frame.hpp @@ -23,6 +23,7 @@ #include "pinocchio/spatial/force.hpp" #include "pinocchio/spatial/motion.hpp" #include "pinocchio/spatial/inertia.hpp" +#include "pinocchio/tools/string-generator.hpp" #include <iostream> namespace se3 @@ -31,7 +32,7 @@ struct Frame { typedef std::size_t Index; - Frame() : name(), parent_id(), frame_placement() + Frame() : name(random(8)), parent_id(), frame_placement() { } diff --git a/src/tools/string-generator.hpp b/src/tools/string-generator.hpp new file mode 100644 index 000000000..8930cc739 --- /dev/null +++ b/src/tools/string-generator.hpp @@ -0,0 +1,39 @@ +// +// Copyright (c) 2016 CNRS +// +// This file is part of Pinocchio +// Pinocchio is free software: you can redistribute it +// and/or modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation, either version +// 3 of the License, or (at your option) any later version. +// +// Pinocchio is distributed in the hope that it will be +// useful, but WITHOUT ANY WARRANTY; without even the implied warranty +// of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Lesser Public License for more details. You should have +// received a copy of the GNU Lesser General Public License along with +// Pinocchio If not, see +// <http://www.gnu.org/licenses/>. + +#ifndef __se3_string_generator_hpp__ +#define __se3_string_generator_hpp__ + +#include <iostream> +namespace se3 +{ + +inline std::string random (const int len) + { + std::string res; + static const char alphanum[] = + "0123456789" + "ABCDEFGHIJKLMNOPQRSTUVWXYZ" + "abcdefghijklmnopqrstuvwxyz"; + + for (int i=0; i<len;++i) + res += alphanum[((size_t)std::rand() % (sizeof(alphanum) - 1))]; + return res; + } +} + +#endif // __se3_string_generator_hpp__ -- GitLab