IMP  2.1.1
The Integrative Modeling Platform
directional_DOFs.h
Go to the documentation of this file.
1 /**
2  * \file kinematics/directional_DOFs.h
3  * \brief
4  * \authors Dina Schneidman, Barak Raveh
5  *
6  * Copyright 2007-2013 IMP Inventors. All rights reserved.
7  *
8  */
9 
10 #ifndef IMPKINEMATICS_DIRECTIONAL_DO_FS_H
11 #define IMPKINEMATICS_DIRECTIONAL_DO_FS_H
12 
13 #include "DOF.h"
14 
15 IMPKINEMATICS_BEGIN_NAMESPACE
16 
17 /*
18  this is a linear one.
19  we may want to make it more general. this will require
20  turning it into virtual class
21 */
22 class IMPKINEMATICSEXPORT DirectionalDOF {
23 public:
24  DirectionalDOF(const DOFs& dofs): dofs_(dofs) {}
25 
26  void set_end_points(const DOFValues& q1, const DOFValues& q2) {
27  endpoint1_ = q1;
28  endpoint2_ = q2;
29  current_delta_.resize(dofs_.size());
30  // TODO: check that the size of dofs_, q1 and q2 is the same
31  // IMP_CHECK...
32 
33  // determine step size based on each DOF
34  step_number_ = 0;
35  for(unsigned int i=0; i<dofs_.size(); i++) {
36  int dof_step_number =
37  dofs_[i]->get_number_of_steps(endpoint1_[i], endpoint2_[i]);
38  if(dof_step_number > step_number_)
39  step_number_ = dof_step_number;
40  }
41 
42  for(unsigned int i=0; i<dofs_.size(); i++) {
43  current_delta_[i] = (endpoint2_[i] - endpoint1_[i])/step_number_;
44  }
45 
46  current_step_number_ = 0;
47  delta_ = 1.0/step_number_;
48  value_ = 0.0;
49  }
50 
51  // return current DOF
52  DOFValues get_dofs_values() {
53  DOFValues ret = endpoint1_;
54  for(unsigned int i=0; i<ret.size(); i++) {
55  ret[i]+= current_step_number_ * current_delta_[i];
56  }
57  return ret;
58  }
59 
60  double get_value() const { return value_; }
61 
62 
63 #ifndef SWIG
64  void operator++(int) {
65  current_step_number_++;
66  value_ += delta_;
67  }
68  void operator--(int) {
69  current_step_number_--;
70  value_ -= delta_;
71  }
72 #endif
73 
74 protected:
75  DOFs dofs_; // can be a pointer
76  DOFValues endpoint1_;
77  DOFValues endpoint2_;
78 
79  // step size for each DOF for endpoint1 and endpoint2
80  DOFValues current_delta_;
81 
82  // step number based on current_delta_
83  int step_number_;
84 
85  // counter for step_number_
86  int current_step_number_;
87 
88  // follows curr_step_number_ between 0 and 1
89  double value_;
90 
91  // delta for value
92  double delta_;
93 
94  public:
95  IMP_SHOWABLE_INLINE(DirectionalDOF, {
96  out << "(direction dof from " << endpoint1_ << " to " << endpoint2_
97  << " ; step number " << current_step_number_ << ")";
98  });
99 
100 };
101 
102 IMP_VALUES(DirectionalDOF, DirectionalDOFs);
103 
104 IMPKINEMATICS_END_NAMESPACE
105 
106 #endif /* IMPKINEMATICS_DIRECTIONAL_DO_FS_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.
IMP::base::Vector< IMP::base::Pointer< DOF > > DOFs
Definition: DOF.h:73