diff options
Diffstat (limited to 'include/ceres/problem.h')
-rw-r--r-- | include/ceres/problem.h | 71 |
1 files changed, 55 insertions, 16 deletions
diff --git a/include/ceres/problem.h b/include/ceres/problem.h index 663616d..b1cb99a 100644 --- a/include/ceres/problem.h +++ b/include/ceres/problem.h @@ -1,5 +1,5 @@ // Ceres Solver - A fast non-linear least squares minimizer -// Copyright 2010, 2011, 2012 Google Inc. All rights reserved. +// Copyright 2013 Google Inc. All rights reserved. // http://code.google.com/p/ceres-solver/ // // Redistribution and use in source and binary forms, with or without @@ -39,11 +39,12 @@ #include <set> #include <vector> +#include "glog/logging.h" #include "ceres/internal/macros.h" #include "ceres/internal/port.h" #include "ceres/internal/scoped_ptr.h" #include "ceres/types.h" -#include "glog/logging.h" +#include "ceres/internal/disable_warnings.h" namespace ceres { @@ -117,14 +118,14 @@ typedef internal::ResidualBlock* ResidualBlockId; // problem.AddResidualBlock(new MyBinaryCostFunction(...), x2, x3); // // Please see cost_function.h for details of the CostFunction object. -class Problem { +class CERES_EXPORT Problem { public: - struct Options { + struct CERES_EXPORT Options { Options() : cost_function_ownership(TAKE_OWNERSHIP), loss_function_ownership(TAKE_OWNERSHIP), local_parameterization_ownership(TAKE_OWNERSHIP), - enable_fast_parameter_block_removal(false), + enable_fast_removal(false), disable_all_safety_checks(false) {} // These flags control whether the Problem object owns the cost @@ -138,17 +139,21 @@ class Problem { Ownership loss_function_ownership; Ownership local_parameterization_ownership; - // If true, trades memory for a faster RemoveParameterBlock() operation. + // If true, trades memory for faster RemoveResidualBlock() and + // RemoveParameterBlock() operations. // - // RemoveParameterBlock() takes time proportional to the size of the entire - // Problem. If you only remove parameter blocks from the Problem - // occassionaly, this may be acceptable. However, if you are modifying the - // Problem frequently, and have memory to spare, then flip this switch to + // By default, RemoveParameterBlock() and RemoveResidualBlock() take time + // proportional to the size of the entire problem. If you only ever remove + // parameters or residuals from the problem occassionally, this might be + // acceptable. However, if you have memory to spare, enable this option to // make RemoveParameterBlock() take time proportional to the number of - // residual blocks that depend on it. The increase in memory usage is an - // additonal hash set per parameter block containing all the residuals that - // depend on the parameter block. - bool enable_fast_parameter_block_removal; + // residual blocks that depend on it, and RemoveResidualBlock() take (on + // average) constant time. + // + // The increase in memory usage is twofold: an additonal hash set per + // parameter block containing all the residuals that depend on the parameter + // block; and a hash set in the problem containing all residuals. + bool enable_fast_removal; // By default, Ceres performs a variety of safety checks when constructing // the problem. There is a small but measurable performance penalty to @@ -276,7 +281,7 @@ class Problem { // residual blocks that depend on the parameter are also removed, as // described above in RemoveResidualBlock(). // - // If Problem::Options::enable_fast_parameter_block_removal is true, then the + // If Problem::Options::enable_fast_removal is true, then the // removal is fast (almost constant time). Otherwise, removing a parameter // block will incur a scan of the entire Problem object. // @@ -300,7 +305,7 @@ class Problem { // Hold the indicated parameter block constant during optimization. void SetParameterBlockConstant(double* values); - // Allow the indicated parameter to vary during optimization. + // Allow the indicated parameter block to vary during optimization. void SetParameterBlockVariable(double* values); // Set the local parameterization for one of the parameter blocks. @@ -312,6 +317,15 @@ class Problem { void SetParameterization(double* values, LocalParameterization* local_parameterization); + // Get the local parameterization object associated with this + // parameter block. If there is no parameterization object + // associated then NULL is returned. + const LocalParameterization* GetParameterization(double* values) const; + + // Set the lower/upper bound for the parameter with position "index". + void SetParameterLowerBound(double* values, int index, double lower_bound); + void SetParameterUpperBound(double* values, int index, double upper_bound); + // Number of parameter blocks in the problem. Always equals // parameter_blocks().size() and parameter_block_sizes().size(). int NumParameterBlocks() const; @@ -336,11 +350,34 @@ class Problem { // block, then ParameterBlockLocalSize = ParameterBlockSize. int ParameterBlockLocalSize(const double* values) const; + // Is the given parameter block present in this problem or not? + bool HasParameterBlock(const double* values) const; + // Fills the passed parameter_blocks vector with pointers to the // parameter blocks currently in the problem. After this call, // parameter_block.size() == NumParameterBlocks. void GetParameterBlocks(vector<double*>* parameter_blocks) const; + // Fills the passed residual_blocks vector with pointers to the + // residual blocks currently in the problem. After this call, + // residual_blocks.size() == NumResidualBlocks. + void GetResidualBlocks(vector<ResidualBlockId>* residual_blocks) const; + + // Get all the parameter blocks that depend on the given residual block. + void GetParameterBlocksForResidualBlock( + const ResidualBlockId residual_block, + vector<double*>* parameter_blocks) const; + + // Get all the residual blocks that depend on the given parameter block. + // + // If Problem::Options::enable_fast_removal is true, then + // getting the residual blocks is fast and depends only on the number of + // residual blocks. Otherwise, getting the residual blocks for a parameter + // block will incur a scan of the entire Problem object. + void GetResidualBlocksForParameterBlock( + const double* values, + vector<ResidualBlockId>* residual_blocks) const; + // Options struct to control Problem::Evaluate. struct EvaluateOptions { EvaluateOptions() @@ -430,4 +467,6 @@ class Problem { } // namespace ceres +#include "ceres/internal/reenable_warnings.h" + #endif // CERES_PUBLIC_PROBLEM_H_ |