IMP  2.2.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 
16 IMPKINEMATICS_BEGIN_NAMESPACE
17 
18 /*
19  A class that hold DOF values for DOFs
20  */
21 class IMPKINEMATICSEXPORT DOFValues : public std::vector<double> {
22  public:
23  // Constructor from DOFs
24  DOFValues(const DOFs& dofs) {
25  reserve(dofs.size());
26  for (unsigned int i = 0; i < dofs.size(); i++)
27  push_back(dofs[i]->get_value());
28  }
29 
30  // Empty Constructor
31  DOFValues() {}
32 
33  // TODO: provide an option for more general distance definition
34  // through RRT class
35  double get_distance2(const DOFValues& other_dof_values) const {
36  double dist = 0.0;
37  for (unsigned int i = 0; i < size(); i++) {
38  double diff = ((*this)[i] - other_dof_values[i]);
39  dist += (diff * diff);
40  }
41  return dist / size();
42  }
43 
44  double get_distance(const DOFValues& other_dof_values) const {
45  return sqrt(get_distance2(other_dof_values));
46  }
47 
48  public:
49  IMP_SHOWABLE_INLINE(DOFValues, {
50  out << "[";
51  if (size() > 0) {
52  out << operator[](0);
53  }
54  for (unsigned int i = 1; i < size(); i++) {
55  out << "," << operator[](i);
56  }
57  out << "]";
58  });
59 };
60 
62 
63 IMPKINEMATICS_END_NAMESPACE
64 
65 #endif /* IMPKINEMATICS_DOF_VALUES_H */
single degree of freedom
#define IMP_VALUES(Name, PluralName)
Define the type for storing sets of values.
#define IMP_SHOWABLE_INLINE(Name, how_to_show)
Declare the methods needed by an object that can be printed.
double get_distance(const Plane3D &pln, const Vector3D &p)
Return the distance between a plane and a point in 3D.
Definition: Plane3D.h:67
IMP::base::Vector< IMP::base::Pointer< DOF > > DOFs
Definition: DOF.h:70