IMP  2.4.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-2015 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 /*
20  A class that hold DOF values for DOFs
21  */
22 class IMPKINEMATICSEXPORT DOFValues : public std::vector<double> {
23  public:
24  // Constructor from DOFs
25  DOFValues(const DOFs& dofs) {
26  reserve(dofs.size());
27  for (unsigned int i = 0; i < dofs.size(); i++)
28  push_back(dofs[i]->get_value());
29  }
30 
31  // Empty Constructor
32  DOFValues() {}
33 
34  // TODO: provide an option for more general distance definition
35  // through RRT class
36  double get_distance2(const DOFValues& other_dof_values) const {
37  double dist = 0.0;
38  for(unsigned int i=0; i<size(); i++) {
39  double diff1 = ((*this)[i] - other_dof_values[i]);
40  double diff2 = std::fabs(diff1 - 2.0*IMP::algebra::PI);
41  double diff3 = std::fabs(diff1 + 2.0*IMP::algebra::PI);
42  double diff = std::min(std::fabs(diff1), std::min(diff2, diff3));
43  dist += (diff*diff);
44  }
45  return dist / size();
46  }
47 
48  double get_distance2(const DOFValues& other_dof_values,
49  const std::vector<bool>& active_dofs) const {
50  double dist = 0.0;
51  unsigned int asize = 0;
52  for(unsigned int i=0; i<size(); i++) {
53  if(active_dofs.size() == 0 || active_dofs[i]) {
54  double diff1 = ((*this)[i] - other_dof_values[i]);
55  double diff2 = std::fabs(diff1 - 2.0*IMP::algebra::PI);
56  double diff3 = std::fabs(diff1 + 2.0*IMP::algebra::PI);
57  double diff = std::min(std::fabs(diff1), std::min(diff2, diff3));
58  dist += (diff*diff);
59  asize++;
60  }
61  }
62  return dist / asize;
63  }
64 
65  double get_distance(const DOFValues& other_dof_values) const {
66  return sqrt(get_distance2(other_dof_values));
67  }
68 
69  double get_distance(const DOFValues& other_dof_values,
70  const std::vector<bool>& active_dofs) const {
71  return sqrt(get_distance2(other_dof_values, active_dofs));
72  }
73 
74  public:
75  IMP_SHOWABLE_INLINE(DOFValues, {
76  out << "[";
77  if (size() > 0) {
78  out << operator[](0);
79  }
80  for (unsigned int i = 1; i < size(); i++) {
81  out << "," << operator[](i);
82  }
83  out << "]";
84  });
85 };
86 
88 
89 IMPKINEMATICS_END_NAMESPACE
90 
91 #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
#define IMP_VALUES(Name, PluralName)
Define the type for storing sets of values.
Definition: value_macros.h:23
double get_distance(const Plane3D &pln, const Vector3D &p)
Return the distance between a plane and a point in 3D.
Definition: Plane3D.h:71
Various useful constants.
IMP::base::Vector< IMP::base::Pointer< DOF > > DOFs
Definition: DOF.h:70