Austin Schuh | 70cc955 | 2019-01-21 19:46:48 -0800 | [diff] [blame^] | 1 | // Ceres Solver - A fast non-linear least squares minimizer |
| 2 | // Copyright 2018 Google Inc. All rights reserved. |
| 3 | // http://ceres-solver.org/ |
| 4 | // |
| 5 | // Redistribution and use in source and binary forms, with or without |
| 6 | // modification, are permitted provided that the following conditions are met: |
| 7 | // |
| 8 | // * Redistributions of source code must retain the above copyright notice, |
| 9 | // this list of conditions and the following disclaimer. |
| 10 | // * Redistributions in binary form must reproduce the above copyright notice, |
| 11 | // this list of conditions and the following disclaimer in the documentation |
| 12 | // and/or other materials provided with the distribution. |
| 13 | // * Neither the name of Google Inc. nor the names of its contributors may be |
| 14 | // used to endorse or promote products derived from this software without |
| 15 | // specific prior written permission. |
| 16 | // |
| 17 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
| 18 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 19 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
| 20 | // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE |
| 21 | // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
| 22 | // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
| 23 | // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
| 24 | // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
| 25 | // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
| 26 | // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
| 27 | // POSSIBILITY OF SUCH DAMAGE. |
| 28 | // |
| 29 | // Author: mierle@gmail.com (Keir Mierle) |
| 30 | |
| 31 | #ifndef CERES_PUBLIC_EVALUATION_CALLBACK_H_ |
| 32 | #define CERES_PUBLIC_EVALUATION_CALLBACK_H_ |
| 33 | |
| 34 | #include "ceres/internal/port.h" |
| 35 | |
| 36 | namespace ceres { |
| 37 | |
| 38 | // Using this callback interface, Ceres can notify you when it is about to |
| 39 | // evaluate the residuals or jacobians. With the callback, you can share |
| 40 | // computation between residual blocks by doing the shared computation in |
| 41 | // PrepareForEvaluation() before Ceres calls CostFunction::Evaluate() on all |
| 42 | // the residuals. It also enables caching results between a pure residual |
| 43 | // evaluation and a residual & jacobian evaluation, via the |
| 44 | // new_evaluation_point argument. |
| 45 | // |
| 46 | // One use case for this callback is if the cost function compute is moved to |
| 47 | // the GPU. In that case, the prepare call does the actual cost function |
| 48 | // evaluation, and subsequent calls from Ceres to the actual cost functions |
| 49 | // merely copy the results from the GPU onto the corresponding blocks for Ceres |
| 50 | // to plug into the solver. |
| 51 | // |
| 52 | // NOTE: Ceres provides no mechanism to share data other than the notification |
| 53 | // from the callback. Users must provide access to pre-computed shared data to |
| 54 | // their cost functions behind the scenes; this all happens without Ceres |
| 55 | // knowing. One approach is to put a pointer to the shared data in each cost |
| 56 | // function (recommended) or to use a global shared variable (discouraged; |
| 57 | // bug-prone). As far as Ceres is concerned, it is evaluating cost functions |
| 58 | // like any other; it just so happens that behind the scenes the cost functions |
| 59 | // reuse pre-computed data to execute faster. |
| 60 | class CERES_EXPORT EvaluationCallback { |
| 61 | public: |
| 62 | virtual ~EvaluationCallback() {} |
| 63 | |
| 64 | // Called before Ceres requests residuals or jacobians for a given setting of |
| 65 | // the parameters. User parameters (the double* values provided to the cost |
| 66 | // functions) are fixed until the next call to PrepareForEvaluation(). If |
| 67 | // new_evaluation_point == true, then this is a new point that is different |
| 68 | // from the last evaluated point. Otherwise, it is the same point that was |
| 69 | // evaluated previously (either jacobian or residual) and the user can use |
| 70 | // cached results from previous evaluations. |
| 71 | virtual void PrepareForEvaluation(bool evaluate_jacobians, |
| 72 | bool new_evaluation_point) = 0; |
| 73 | }; |
| 74 | |
| 75 | } // namespace ceres |
| 76 | |
| 77 | #endif // CERES_PUBLIC_EVALUATION_CALLBACK_H_ |