<commit_before>//
// Copyright (c) 2016 CNRS
// Author: NMansard from <NAME>
//
//

// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// 1. Redistributions of source code must retain the above copyright
//    notice, this list of conditions and the following disclaimer.
//
// 2. Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
// DAMAGE.

#ifndef HPP_PINOCCHIO_DEVICE_HH
#define HPP_PINOCCHIO_DEVICE_HH

#include <boost/thread/condition_variable.hpp>
#include <boost/thread/mutex.hpp>
#include <hpp/pinocchio/config.hh>
#include <hpp/pinocchio/deprecated.hh>
#include <hpp/pinocchio/device-data.hh>
#include <hpp/pinocchio/device-sync.hh>
#include <hpp/pinocchio/extra-config-space.hh>
#include <hpp/pinocchio/frame.hh>
#include <hpp/pinocchio/fwd.hh>
#include <hpp/pinocchio/pool.hh>
#include <hpp/util/debug.hh>
#include <hpp/util/serialization-fwd.hh>
#include <iostream>
#include <list>
#include <vector>

namespace hpp {
namespace pinocchio {

/// \brief Robot with geometric and dynamic pinocchio

/// The creation of the device is done by Device::create(const
/// std::string name).  This function returns a shared pointer
/// to the newly created object.  \sa Smart pointers
/// documentation:
/// http://www.boost.org/libs/smart_ptr/smart_ptr.htm
class HPP_PINOCCHIO_DLLAPI Device : public AbstractDevice {
  friend class Joint;
  friend class Frame;
  friend class DeviceSync;
  friend class CollisionObject;
  friend class CenterOfMassComputation;

 public:
  /// Collision pairs between bodies
  typedef std::pair<JointPtr_t, JointPtr_t> CollisionPair_t;
  typedef std::list<CollisionPair_t> CollisionPairs_t;

  // -----------------------------------------------------------------------
  /// \name Construction, copy and destruction
  /// \{
  virtual ~Device();

  /// \brief Clone as a CkwsDevice
  /// The pinocchio model is not copied (only copy the pointer).
  /// A new Pinocchio "data" is created.
  /// As the model is not copied, cloning is a non constant operation. \sa
  /// cloneConst
  virtual DevicePtr_t clone() const { return createCopy(weakPtr_.lock()); }
  /// \brief Clone as a CkwsDevice
  /// Both pinocchio objects model and data are copied.
  /// TODO: this method is not implemented yet (assert if called)
  DevicePtr_t cloneConst() const { return createCopyConst(weakPtr_.lock()); }

  DevicePtr_t self() const { return weakPtr_.lock(); }

  /// Get name of device
  const std::string& name() const { return name_; }

  /// \brief Creation of a new device
  /// \return a shared pointer to the new device
  /// \param name Name of the device
  static DevicePtr_t create(const std::string& name);

  /// \brief Copy of a device
  /// \return A shared pointer to new device.
  /// \param device Device to be copied.
  /// The pinocchio model is not copied (only copy the pointer).
  /// A new Pinocchio "data" is created.
  static DevicePtr_t createCopy(const DevicePtr_t& device);
  static DevicePtr_t createCopyConst(const DeviceConstPtr_t& device);

  /// \}
  // -----------------------------------------------------------------------
  /// \name Set pinocchio models and datas
  /// \{

  /// Set pinocchio model.
  void setModel(ModelPtr_t modelPtr) { model_ = modelPtr; }

  /// Set pinocchio geom.
  void setGeomModel(GeomModelPtr_t geomModelPtr) { geomModel_ = geomModelPtr; }

  /// Set Pinocchio data corresponding to model
  void setData(DataPtr_t dataPtr) {
    d().data_ = dataPtr;
    resizeState();
  }
  /// Create Pinocchio data from model.
  void createData();

  /// Set Pinocchio geomData corresponding to model
  void setGeomData(GeomDataPtr_t geomDataPtr) {
    d().geomData_ = geomDataPtr;
    resizeState();
  }
  /// Create Pinocchio geomData from model.
  void createGeomData();

  /// Remove some joints from the configuration space.
  virtual void removeJoints(const std::vector<std::string>& jointNames,
                            Configuration_t referenceConfig);

  /// \}
  // -----------------------------------------------------------------------
  /// \name Joints
  /// \{

  /// This struct defines a linear relation between two joint values.
  ///
  /// The configuration of \c JointConstraint::joint is expected to be \f$
  /// q_{joint} = multiplier * q_{reference} + offset\f$.
  /// where \f$q_{reference}\f$ is the configuration of
  /// JointLinearConstraint::reference joint.
  struct JointLinearConstraint {
    value_type offset, multiplier;
    JointPtr_t joint, reference;
  };

  /// Get root joint
  JointPtr_t rootJoint() const;

  /// Get root frame
  Frame rootFrame() const;

  /// Get number of joints
  size_type nbJoints() const;

  /// Access i-th joint
  JointPtr_t jointAt(const size_type& i) const;

  /// Get the joint at configuration rank r
  /// \return  joint j such that j->rankInConfiguration () <=
  ///          r < j->rankInConfiguration () + j->configSize ()
  JointPtr_t getJointAtConfigRank(const size_type& r) const;

  /// Get the joint at velocity rank r
  /// \return  joint j such that j->rankInVelocity () <=
  ///          r < j->rankInVelocity () + j->numberDof ()
  JointPtr_t getJointAtVelocityRank(const size_type& r) const;
<commit_msg>Add clearer docs for methods about joint index<commit_after>//
// Copyright (c) 2016 CNRS
// Author: NMansard from <NAME>
//
//

// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// 1. Redistributions of source code must retain the above copyright
//    notice, this list of conditions and the following disclaimer.
//
// 2. Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
// DAMAGE.

#ifndef HPP_PINOCCHIO_DEVICE_HH
#define HPP_PINOCCHIO_DEVICE_HH

#include <boost/thread/condition_variable.hpp>
#include <boost/thread/mutex.hpp>
#include <hpp/pinocchio/config.hh>
#include <hpp/pinocchio/deprecated.hh>
#include <hpp/pinocchio/device-data.hh>
#include <hpp/pinocchio/device-sync.hh>
#include <hpp/pinocchio/extra-config-space.hh>
#include <hpp/pinocchio/frame.hh>
#include <hpp/pinocchio/fwd.hh>
#include <hpp/pinocchio/pool.hh>
#include <hpp/util/debug.hh>
#include <hpp/util/serialization-fwd.hh>
#include <iostream>
#include <list>
#include <vector>

namespace hpp {
namespace pinocchio {

/// \brief Robot with geometric and dynamic pinocchio

/// The creation of the device is done by Device::create(const
/// std::string name).  This function returns a shared pointer
/// to the newly created object.  \sa Smart pointers
/// documentation:
/// http://www.boost.org/libs/smart_ptr/smart_ptr.htm
class HPP_PINOCCHIO_DLLAPI Device : public AbstractDevice {
  friend class Joint;
  friend class Frame;
  friend class DeviceSync;
  friend class CollisionObject;
  friend class CenterOfMassComputation;

 public:
  /// Collision pairs between bodies
  typedef std::pair<JointPtr_t, JointPtr_t> CollisionPair_t;
  typedef std::list<CollisionPair_t> CollisionPairs_t;

  // -----------------------------------------------------------------------
  /// \name Construction, copy and destruction
  /// \{
  virtual ~Device();

  /// \brief Clone as a CkwsDevice
  /// The pinocchio model is not copied (only copy the pointer).
  /// A new Pinocchio "data" is created.
  /// As the model is not copied, cloning is a non constant operation. \sa
  /// cloneConst
  virtual DevicePtr_t clone() const { return createCopy(weakPtr_.lock()); }
  /// \brief Clone as a CkwsDevice
  /// Both pinocchio objects model and data are copied.
  /// TODO: this method is not implemented yet (assert if called)
  DevicePtr_t cloneConst() const { return createCopyConst(weakPtr_.lock()); }

  DevicePtr_t self() const { return weakPtr_.lock(); }

  /// Get name of device
  const std::string& name() const { return name_; }

  /// \brief Creation of a new device
  /// \return a shared pointer to the new device
  /// \param name Name of the device
  static DevicePtr_t create(const std::string& name);

  /// \brief Copy of a device
  /// \return A shared pointer to new device.
  /// \param device Device to be copied.
  /// The pinocchio model is not copied (only copy the pointer).
  /// A new Pinocchio "data" is created.
  static DevicePtr_t createCopy(const DevicePtr_t& device);
  static DevicePtr_t createCopyConst(const DeviceConstPtr_t& device);

  /// \}
  // -----------------------------------------------------------------------
  /// \name Set pinocchio models and datas
  /// \{

  /// Set pinocchio model.
  void setModel(ModelPtr_t modelPtr) { model_ = modelPtr; }

  /// Set pinocchio geom.
  void setGeomModel(GeomModelPtr_t geomModelPtr) { geomModel_ = geomModelPtr; }

  /// Set Pinocchio data corresponding to model
  void setData(DataPtr_t dataPtr) {
    d().data_ = dataPtr;
    resizeState();
  }
  /// Create Pinocchio data from model.
  void createData();

  /// Set Pinocchio geomData corresponding to model
  void setGeomData(GeomDataPtr_t geomDataPtr) {
    d().geomData_ = geomDataPtr;
    resizeState();
  }
  /// Create Pinocchio geomData from model.
  void createGeomData();

  /// Remove some joints from the configuration space.
  virtual void removeJoints(const std::vector<std::string>& jointNames,
                            Configuration_t referenceConfig);

  /// \}
  // -----------------------------------------------------------------------
  /// \name Joints
  /// \{

  /// This struct defines a linear relation between two joint values.
  ///
  /// The configuration of \c JointConstraint::joint is expected to be \f$
  /// q_{joint} = multiplier * q_{reference} + offset\f$.
  /// where \f$q_{reference}\f$ is the configuration of
  /// JointLinearConstraint::reference joint.
  struct JointLinearConstraint {
    value_type offset, multiplier;
    JointPtr_t joint, reference;
  };

  /// Get root joint
  JointPtr_t rootJoint() const;

  /// Get root frame
  Frame rootFrame() const;

  /// Get number of joints
  /// \note "universe" is not included in the count
  size_type nbJoints() const;

  /// Access i-th joint
  /// \param i index of joint in device. This is 1 less than index of joint
  ///        in pinocchio vector of joints (pinocchio::ModelTpl::joints)
  ///        since "universe" is not included as index 0
  JointPtr_t jointAt(const size_type& i) const;

  /// Get the joint at configuration rank r
  /// \return  joint j such that j->rankInConfiguration () <=
  ///          r < j->rankInConfiguration () + j->configSize ()
  JointPtr_t getJointAtConfigRank(const size_type& r) const;

  /// Get the joint at velocity rank r
  /// \return  joint j such that j->rankInVelocity () <=
  ///          r < j->rankInVelocity () + j->numberDof ()
  JointPtr_t getJointAtVelocityRank(const size_type& r) const;

{'fraction_non_alphanumeric': 0.13658881811748053, 'fraction_numerical': 0.0011008885743492962, 'mean_word_length': 2.8656534954407293, 'pattern_counts': {'":': 0, '<': 49, '<?xml version=': 0, '>': 53, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3689826', 'n_tokens_mistral': 3754, 'n_tokens_neox': 3522, 'n_words': 1330}