IMP  2.3.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-2014 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  }
46  return dist / size();
47  }
48 
49  double get_distance(const DOFValues& other_dof_values) const {
50  return sqrt(get_distance2(other_dof_values));
51  }
52 
53  public:
54  IMP_SHOWABLE_INLINE(DOFValues, {
55  out << "[";
56  if (size() > 0) {
57  out << operator[](0);
58  }
59  for (unsigned int i = 1; i < size(); i++) {
60  out << "," << operator[](i);
61  }
62  out << "]";
63  });
64 };
65 
67 
68 IMPKINEMATICS_END_NAMESPACE
69 
70 #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