IMP logo
IMP Reference Guide  2.7.0
The Integrative Modeling Platform
DOFValues.h
Go to the documentation of this file.
1 /**
2  * \file IMP/kinematics/DOFValues.h
3  * \brief a simple class for storage of DOF values.
4  *
5  * \authors Dina Schneidman, Barak Raveh
6  *
7  * Copyright 2007-2017 IMP Inventors. All rights reserved.
8  *
9  */
10 
11 #ifndef IMPKINEMATICS_DOF_VALUES_H
12 #define IMPKINEMATICS_DOF_VALUES_H
13 
14 #include "DOF.h"
15 #include <IMP/algebra/constants.h>
16 
17 IMPKINEMATICS_BEGIN_NAMESPACE
18 
19 //! A class that holds DOF values for DOFs
20 class IMPKINEMATICSEXPORT DOFValues : public std::vector<double> {
21  public:
22  //! Constructor from DOFs
23  DOFValues(const DOFs& dofs) {
24  reserve(dofs.size());
25  for (unsigned int i = 0; i < dofs.size(); i++)
26  push_back(dofs[i]->get_value());
27  }
28 
29  //! Empty Constructor
30  DOFValues() {}
31 
32  // TODO: provide an option for more general distance definition
33  // through RRT class
34  double get_distance2(const DOFValues& other_dof_values) const {
35  double dist = 0.0;
36  for(unsigned int i=0; i<size(); i++) {
37  double diff1 = ((*this)[i] - other_dof_values[i]);
38  double diff2 = std::fabs(diff1 - 2.0*IMP::algebra::PI);
39  double diff3 = std::fabs(diff1 + 2.0*IMP::algebra::PI);
40  double diff = std::min(std::fabs(diff1), std::min(diff2, diff3));
41  dist += (diff*diff);
42  }
43  return dist / size();
44  }
45 
46  double get_distance2(const DOFValues& other_dof_values,
47  const std::vector<bool>& active_dofs) const {
48  double dist = 0.0;
49  unsigned int asize = 0;
50  for(unsigned int i=0; i<size(); i++) {
51  if(active_dofs.size() == 0 || active_dofs[i]) {
52  double diff1 = ((*this)[i] - other_dof_values[i]);
53  double diff2 = std::fabs(diff1 - 2.0*IMP::algebra::PI);
54  double diff3 = std::fabs(diff1 + 2.0*IMP::algebra::PI);
55  double diff = std::min(std::fabs(diff1), std::min(diff2, diff3));
56  dist += (diff*diff);
57  asize++;
58  }
59  }
60  return dist / asize;
61  }
62 
63  double get_distance(const DOFValues& other_dof_values) const {
64  return sqrt(get_distance2(other_dof_values));
65  }
66 
67  double get_distance(const DOFValues& other_dof_values,
68  const std::vector<bool>& active_dofs) const {
69  return sqrt(get_distance2(other_dof_values, active_dofs));
70  }
71 
72  public:
73  IMP_SHOWABLE_INLINE(DOFValues, {
74  out << "[";
75  if (size() > 0) {
76  out << operator[](0);
77  }
78  for (unsigned int i = 1; i < size(); i++) {
79  out << "," << operator[](i);
80  }
81  out << "]";
82  });
83 };
84 
86 
87 IMPKINEMATICS_END_NAMESPACE
88 
89 #endif /* IMPKINEMATICS_DOF_VALUES_H */
#define IMP_SHOWABLE_INLINE(Name, how_to_show)
Declare the methods needed by an object that can be printed.
static const double PI
the constant pi
single degree of freedom
DOFValues()
Empty Constructor.
Definition: DOFValues.h:30
#define IMP_VALUES(Name, PluralName)
Define the type for storing sets of values.
Definition: value_macros.h:23
DOFValues(const DOFs &dofs)
Constructor from DOFs.
Definition: DOFValues.h:23
A class that holds DOF values for DOFs.
Definition: DOFValues.h:20
Various useful constants.
double get_distance(const Line3D &s, const Vector3D &p)
Get closest distance between a line and a point.