2 #include "trajopt/configuration_space.hpp"
9 vector<ConfigurationPtr> m_configs;
10 vector<int> m_startInds;
13 vector<ConfigurationPtr> configs;
14 configs.push_back(config0);
15 configs.push_back(config1);
21 void Init(
const vector<ConfigurationPtr>& configs) {
24 BOOST_FOREACH(
const ConfigurationPtr& config, m_configs) {
25 m_startInds.push_back(startInd);
26 startInd += config->GetDOF();
29 virtual void SetDOFValues(
const DblVec& dofs) {
31 BOOST_FOREACH(
const ConfigurationPtr& config, m_configs) {
32 int d = config->GetDOF();
33 DblVec part_dofs(dofs.begin()+n, dofs.begin()+n+d);
34 config->SetDOFValues(part_dofs);
38 virtual void GetDOFLimits(DblVec& lower, DblVec& upper)
const {
41 BOOST_FOREACH(
const ConfigurationPtr& config, m_configs) {
42 DblVec part_lower, part_upper;
43 config->GetDOFLimits(part_lower, part_upper);
44 lower.insert(lower.end(), part_lower.begin(), part_lower.end());
45 upper.insert(upper.end(), part_upper.begin(), part_upper.end());
49 virtual DblVec GetDOFValues() {
51 BOOST_FOREACH(
const ConfigurationPtr& config, m_configs) {
52 DblVec part_vals = config->GetDOFValues();
53 out.insert(out.end(), part_vals.begin(), part_vals.end());
57 virtual int GetDOF()
const {
59 BOOST_FOREACH(
const ConfigurationPtr& config, m_configs) {
60 out += config->GetDOF();
64 virtual OpenRAVE::EnvironmentBasePtr GetEnv() {
return m_configs[0]->GetEnv();}
67 static const int PART_FACTOR = 1024;
68 virtual DblMatrix PositionJacobian(
int link_ind,
const OR::Vector& pt)
const {
69 int i_part = link_ind / PART_FACTOR;
70 DblMatrix out = MatrixXd::Zero(3, GetDOF());
71 int i_startDof = m_startInds[i_part];
72 out.block(0, i_startDof, 3, m_configs[i_part]->GetDOF()) = m_configs[i_part]->PositionJacobian(link_ind%PART_FACTOR, pt);
75 virtual DblMatrix RotationJacobian(
int link_ind)
const {PRINT_AND_THROW(
"not implemented");}
76 virtual bool DoesAffect(
const KinBody::Link& link) {
78 BOOST_FOREACH(ConfigurationPtr& config, m_configs) {
79 out |= config->DoesAffect(link);
83 virtual std::vector<KinBody::LinkPtr> GetAffectedLinks() {
84 std::vector<KinBody::LinkPtr> out;
85 BOOST_FOREACH(ConfigurationPtr& config, m_configs) {
86 std::vector<KinBody::LinkPtr> part_links = config->GetAffectedLinks();
87 out.insert(out.end(), part_links.begin(), part_links.end());
92 virtual void GetAffectedLinks(std::vector<KinBody::LinkPtr>& links,
bool only_with_geom, vector<int>& link_inds) {
96 BOOST_FOREACH(ConfigurationPtr& config, m_configs) {
97 std::vector<KinBody::LinkPtr> part_links;
98 vector<int> part_link_inds;
99 config->GetAffectedLinks(part_links, only_with_geom, part_link_inds);
100 BOOST_FOREACH(
int& i, part_link_inds) i += PART_FACTOR*i_part;
101 links.insert(links.end(), part_links.begin(), part_links.end());
102 link_inds.insert(link_inds.end(), part_link_inds.begin(), part_link_inds.end());
106 virtual vector<OpenRAVE::KinBodyPtr> GetBodies() {
107 vector<OpenRAVE::KinBodyPtr> out;
108 for (
int i=0; i < m_configs.size(); ++i) {
109 vector<OpenRAVE::KinBodyPtr> newvec;
110 out.insert(out.end(), newvec.begin(), newvec.end());
114 virtual DblVec RandomDOFValues() {
115 PRINT_AND_THROW(
"not implemented");
119 vector<SaverPtr> savers;
121 savers.reserve(self->m_configs.size());
122 for (
int i=0; i <
self->m_configs.size(); ++i) {
123 savers.push_back(self->m_configs[i]->Save());