blob: 2ca055448c398d6523cfaada6a1b017f219d1ae3 [file] [log] [blame]
Keir Mierle8ebb0732012-04-30 23:09:08 -07001// Ceres Solver - A fast non-linear least squares minimizer
2// Copyright 2010, 2011, 2012 Google Inc. All rights reserved.
3// http://code.google.com/p/ceres-solver/
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: keir@google.com (Keir Mierle)
30//
31// This is the implementation of the public Problem API. The pointer to
32// implementation (PIMPL) idiom makes it possible for Ceres internal code to
33// refer to the private data members without needing to exposing it to the
34// world. An alternative to PIMPL is to have a factory which returns instances
35// of a virtual base class; while that approach would work, it requires clients
36// to always put a Problem object into a scoped pointer; this needlessly muddies
37// client code for little benefit. Therefore, the PIMPL comprise was chosen.
38
39#ifndef CERES_PUBLIC_PROBLEM_IMPL_H_
40#define CERES_PUBLIC_PROBLEM_IMPL_H_
41
42#include <map>
43#include <vector>
44
45#include "ceres/internal/macros.h"
46#include "ceres/internal/port.h"
47#include "ceres/internal/scoped_ptr.h"
48#include "ceres/problem.h"
49#include "ceres/types.h"
50
51namespace ceres {
52
53class CostFunction;
54class LossFunction;
55class LocalParameterization;
56
57namespace internal {
58
59class Program;
60class ResidualBlock;
61
62class ProblemImpl {
63 public:
64 typedef map<double*, ParameterBlock*> ParameterMap;
65
66 ProblemImpl();
67 explicit ProblemImpl(const Problem::Options& options);
68
69 ~ProblemImpl();
70
71 // See the public problem.h file for description of these methods.
72 ResidualBlockId AddResidualBlock(CostFunction* cost_function,
73 LossFunction* loss_function,
74 const vector<double*>& parameter_blocks);
75 ResidualBlockId AddResidualBlock(CostFunction* cost_function,
76 LossFunction* loss_function,
77 double* x0);
78 ResidualBlockId AddResidualBlock(CostFunction* cost_function,
79 LossFunction* loss_function,
80 double* x0, double* x1);
81 ResidualBlockId AddResidualBlock(CostFunction* cost_function,
82 LossFunction* loss_function,
83 double* x0, double* x1, double* x2);
84 ResidualBlockId AddResidualBlock(CostFunction* cost_function,
85 LossFunction* loss_function,
86 double* x0, double* x1, double* x2,
87 double* x3);
88 ResidualBlockId AddResidualBlock(CostFunction* cost_function,
89 LossFunction* loss_function,
90 double* x0, double* x1, double* x2,
91 double* x3, double* x4);
92 ResidualBlockId AddResidualBlock(CostFunction* cost_function,
93 LossFunction* loss_function,
94 double* x0, double* x1, double* x2,
95 double* x3, double* x4, double* x5);
96 void AddParameterBlock(double* values, int size);
97 void AddParameterBlock(double* values,
98 int size,
99 LocalParameterization* local_parameterization);
100 void SetParameterBlockConstant(double* values);
101 void SetParameterBlockVariable(double* values);
102 void SetParameterization(double* values,
103 LocalParameterization* local_parameterization);
104 int NumParameterBlocks() const;
105 int NumParameters() const;
106 int NumResidualBlocks() const;
107 int NumResiduals() const;
108
109 const Program& program() const { return *program_; }
110 Program* mutable_program() { return program_.get(); }
111
112 const ParameterMap& parameter_map() const { return parameter_block_map_; }
113
114 private:
115 const Problem::Options options_;
116
117 // The mapping from user pointers to parameter blocks.
118 map<double*, ParameterBlock*> parameter_block_map_;
119
120 internal::scoped_ptr<internal::Program> program_;
Sameer Agarwal237d6592012-05-30 20:34:49 -0700121 CERES_DISALLOW_COPY_AND_ASSIGN(ProblemImpl);
Keir Mierle8ebb0732012-04-30 23:09:08 -0700122};
123
124} // namespace internal
125} // namespace ceres
126
127#endif // CERES_PUBLIC_PROBLEM_IMPL_H_