MinActiveStoppingCriterion.h
1 /*
2  * Medical Image Registration ToolKit (MIRTK)
3  *
4  * Copyright 2013-2015 Imperial College London
5  * Copyright 2013-2015 Andreas Schuh
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  */
19 
20 #ifndef MIRTK_MinActiveStoppingCriterion_H
21 #define MIRTK_MinActiveStoppingCriterion_H
22 
23 #include "mirtk/StoppingCriterion.h"
24 
25 
26 namespace mirtk {
27 
28 
29 /**
30  * Stops mesh deformation when the ratio of active nodes drops below a threshold
31  */
33 {
34  mirtkObjectMacro(MinActiveStoppingCriterion);
35 
36  // ---------------------------------------------------------------------------
37  // Attributes
38 
39  /// Minimum ratio of active nodes
40  mirtkPublicAttributeMacro(double, Threshold);
41 
42  /// Number of iterations a node must be inactive to be labeled passive for
43  /// the remainder of the iterative optimization process
44  mirtkReadOnlyAttributeMacro(int, StreakOfPassiveIterations);
45 
46  /// Current ratio of active nodes
47  mirtkReadOnlyAttributeMacro(double, Active);
48 
49  /// Copy attributes of this class from another instance
50  void CopyAttributes(const MinActiveStoppingCriterion &other);
51 
52  // ---------------------------------------------------------------------------
53  // Construction/Destruction
54 public:
55 
56  /// Constructor
58 
59  /// Copy constructor
61 
62  /// Assignment operator
64 
65  /// Create new copy of this instance
66  virtual StoppingCriterion *New() const;
67 
68  /// Destructor
70 
71  /// Initialize stopping criterion after input and parameters are set
72  virtual void Initialize();
73 
74  // ---------------------------------------------------------------------------
75  // Evaluation
76 
77  /// Test stopping criterion
78  ///
79  /// \param[in] iter Current number of iterations.
80  /// \param[in] value Objective function value at current iteration (unused).
81  /// \param[in] delta Last change of objective function parameters.
82  ///
83  /// \returns Whether stopping criterion is fulfilled.
84  virtual bool Fulfilled(int iter, double value, const double *delta);
85 
86  // ---------------------------------------------------------------------------
87  // Logging
88 
89  /// Print current stopping criterion status / value
90  ///
91  /// This function must be called after Fulfilled, which should update any
92  /// cached values that are needed by this function to avoid a costly
93  /// reevaluation of the stopping criterion.
94  ///
95  /// \note The printed string is expected to be considerably short and must
96  /// not end with a newline or space characters.
97  virtual void Print(ostream &) const;
98 
99 };
100 
101 
102 } // namespace mirtk
103 
104 #endif // MIRTK_MinActiveStoppingCriterion_H
virtual ~MinActiveStoppingCriterion()
Destructor.
virtual void Initialize()
Initialize stopping criterion after input and parameters are set.
virtual void Print(ostream &) const
MinActiveStoppingCriterion & operator=(const MinActiveStoppingCriterion &)
Assignment operator.
MinActiveStoppingCriterion(const ObjectiveFunction *=NULL)
Constructor.
Definition: IOConfig.h:41
virtual bool Fulfilled(int iter, double value, const double *delta)
virtual StoppingCriterion * New() const
Create new copy of this instance.