|
10 | 10 |
|
11 | 11 | namespace shapeworks { |
12 | 12 |
|
| 13 | +/** |
| 14 | + * \class Constraint |
| 15 | + * \ingroup Group-Constraints |
| 16 | + * |
| 17 | + * This class is the general constraint class. Each instance represents a single constraint, either cutting-plane, sphere or free-form. They all inherit from this class. This class containts all the infrastructure to handle gradients and evaluations, which is shared among all constraint types. |
| 18 | + * NOTE: Not actually using the augmented lagrangian. We are using quadratic penalty and not lagrangian because it works better. |
| 19 | + * |
| 20 | + */ |
| 21 | + |
13 | 22 | class Constraint { |
14 | 23 | public: |
| 24 | + /// Returns if pt in vnl_vector format is violated by the constraint |
15 | 25 | bool isViolated(const vnl_vector<double> &pt) const { return isViolated(Eigen::Vector3d(pt[0], pt[1], pt[2])); } |
| 26 | + /// Returns if pt in Eigen format is violated by the constraint |
16 | 27 | virtual bool isViolated(const Eigen::Vector3d &pt) const = 0; |
| 28 | + /// Prints the constraint neatly |
17 | 29 | virtual void print() const = 0; |
18 | 30 |
|
19 | 31 | // For augmented lagrangian |
20 | | - void setZ(double inz) { z_ = inz; } |
21 | | - double getZ() { return z_; } |
| 32 | + /// Initializes mu |
22 | 33 | void setMus(std::vector<double> inmu) { mus_ = inmu; } |
| 34 | + /// Gets mu |
23 | 35 | std::vector<double> getMus() { return mus_; } |
24 | | - void setLambda(double inLambda) { lambda_ = inLambda; } |
25 | | - double getLambda() { return lambda_; } |
26 | 36 |
|
| 37 | + /// Returns the gradient of the constraint |
27 | 38 | virtual Eigen::Vector3d constraintGradient(const Eigen::Vector3d &pt) const = 0; |
| 39 | + /// Returns the evaluation on the constraint, i.e. the signed distance to the constraint boundary |
28 | 40 | virtual double constraintEval(const Eigen::Vector3d &pt) const = 0; |
29 | 41 |
|
30 | | - void updateZ(const Eigen::Vector3d &pt, double C); |
31 | | - |
| 42 | + /// Updates the value of mu according to the augmented lagrangian update |
32 | 43 | void updateMu(const Eigen::Vector3d &pt, double C, size_t index); |
33 | 44 |
|
| 45 | + /// Computes the lagrangian gradient based on lagrangian inequality equations. NOTE: Not actually lagrangian. We are using quadratic penalty and not lagrangian because it works better. |
34 | 46 | Eigen::Vector3d lagragianGradient(const Eigen::Vector3d &pt, double C, size_t index) const; |
35 | 47 |
|
36 | 48 | protected: |
| 49 | + /// Returns the sign of the double |
37 | 50 | int sgn(double val) { return (double(0) < val) - (val < double(0)); } |
38 | 51 |
|
39 | 52 | // For augmented lagrangian |
| 53 | + /// Mu is the lagrangian momentum term |
40 | 54 | std::vector<double> mus_; |
41 | | - double z_; |
42 | | - double lambda_; |
43 | 55 | }; |
44 | 56 |
|
45 | 57 | } // namespace shapeworks |
0 commit comments