diff options
Diffstat (limited to 'internal/ceres/residual_block.h')
-rw-r--r-- | internal/ceres/residual_block.h | 28 |
1 files changed, 26 insertions, 2 deletions
diff --git a/internal/ceres/residual_block.h b/internal/ceres/residual_block.h index e0a06e7..9c3671b 100644 --- a/internal/ceres/residual_block.h +++ b/internal/ceres/residual_block.h @@ -34,11 +34,13 @@ #ifndef CERES_INTERNAL_RESIDUAL_BLOCK_H_ #define CERES_INTERNAL_RESIDUAL_BLOCK_H_ +#include <string> #include <vector> #include "ceres/cost_function.h" #include "ceres/internal/port.h" #include "ceres/internal/scoped_ptr.h" +#include "ceres/stringprintf.h" #include "ceres/types.h" namespace ceres { @@ -64,9 +66,13 @@ class ParameterBlock; // loss functions, and parameter blocks. class ResidualBlock { public: + // Construct the residual block with the given cost/loss functions. Loss may + // be null. The index is the index of the residual block in the Program's + // residual_blocks array. ResidualBlock(const CostFunction* cost_function, const LossFunction* loss_function, - const vector<ParameterBlock*>& parameter_blocks); + const vector<ParameterBlock*>& parameter_blocks, + int index); // Evaluates the residual term, storing the scalar cost in *cost, the residual // components in *residuals, and the jacobians between the parameters and @@ -87,11 +93,16 @@ class ResidualBlock { // parameterizations applied already; for example, the jacobian for a // 4-dimensional quaternion parameter using the "QuaternionParameterization" // is num_residuals by 3 instead of num_residuals by 4. - bool Evaluate(double* cost, + // + // apply_loss_function as the name implies allows the user to switch + // the application of the loss function on and off. + bool Evaluate(bool apply_loss_function, + double* cost, double* residuals, double** jacobians, double* scratch) const; + const CostFunction* cost_function() const { return cost_function_; } const LossFunction* loss_function() const { return loss_function_; } @@ -112,10 +123,23 @@ class ResidualBlock { // The minimum amount of scratch space needed to pass to Evaluate(). int NumScratchDoublesForEvaluate() const; + // This residual block's index in an array. + int index() const { return index_; } + void set_index(int index) { index_ = index; } + + string ToString() { + return StringPrintf("{residual block; index=%d}", index_); + } + private: const CostFunction* cost_function_; const LossFunction* loss_function_; scoped_array<ParameterBlock*> parameter_blocks_; + + // The index of the residual, typically in a Program. This is only to permit + // switching from a ResidualBlock* to an index in the Program's array, needed + // to do efficient removals. + int32 index_; }; } // namespace internal |