|
Packit |
ea1746 |
/* Ceres Solver - A fast non-linear least squares minimizer
|
|
Packit |
ea1746 |
* Copyright 2015 Google Inc. All rights reserved.
|
|
Packit |
ea1746 |
* http://ceres-solver.org/
|
|
Packit |
ea1746 |
*
|
|
Packit |
ea1746 |
* Redistribution and use in source and binary forms, with or without
|
|
Packit |
ea1746 |
* modification, are permitted provided that the following conditions are met:
|
|
Packit |
ea1746 |
*
|
|
Packit |
ea1746 |
* - Redistributions of source code must retain the above copyright notice,
|
|
Packit |
ea1746 |
* this list of conditions and the following disclaimer.
|
|
Packit |
ea1746 |
* - Redistributions in binary form must reproduce the above copyright notice,
|
|
Packit |
ea1746 |
* this list of conditions and the following disclaimer in the documentation
|
|
Packit |
ea1746 |
* and/or other materials provided with the distribution.
|
|
Packit |
ea1746 |
* - Neither the name of Google Inc. nor the names of its contributors may be
|
|
Packit |
ea1746 |
* used to endorse or promote products derived from this software without
|
|
Packit |
ea1746 |
* specific prior written permission.
|
|
Packit |
ea1746 |
*
|
|
Packit |
ea1746 |
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
Packit |
ea1746 |
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
Packit |
ea1746 |
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
Packit |
ea1746 |
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
|
Packit |
ea1746 |
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
Packit |
ea1746 |
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
Packit |
ea1746 |
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
Packit |
ea1746 |
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
Packit |
ea1746 |
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
Packit |
ea1746 |
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
Packit |
ea1746 |
* POSSIBILITY OF SUCH DAMAGE.
|
|
Packit |
ea1746 |
*
|
|
Packit |
ea1746 |
* Author: mierle@gmail.com (Keir Mierle)
|
|
Packit |
ea1746 |
*
|
|
Packit |
ea1746 |
* A minimal C API for Ceres. Not all functionality is included. This API is
|
|
Packit |
ea1746 |
* not intended for clients of Ceres, but is instead intended for easing the
|
|
Packit |
ea1746 |
* process of binding Ceres to other languages.
|
|
Packit |
ea1746 |
*
|
|
Packit |
ea1746 |
* Currently this is a work in progress.
|
|
Packit |
ea1746 |
*/
|
|
Packit |
ea1746 |
|
|
Packit |
ea1746 |
#ifndef CERES_PUBLIC_C_API_H_
|
|
Packit |
ea1746 |
#define CERES_PUBLIC_C_API_H_
|
|
Packit |
ea1746 |
|
|
Packit |
ea1746 |
#include "ceres/internal/port.h"
|
|
Packit |
ea1746 |
#include "ceres/internal/disable_warnings.h"
|
|
Packit |
ea1746 |
|
|
Packit |
ea1746 |
#ifdef __cplusplus
|
|
Packit |
ea1746 |
extern "C" {
|
|
Packit |
ea1746 |
#endif
|
|
Packit |
ea1746 |
|
|
Packit |
ea1746 |
/* Init the Ceres private data. Must be called before anything else. */
|
|
Packit |
ea1746 |
CERES_EXPORT void ceres_init();
|
|
Packit |
ea1746 |
|
|
Packit |
ea1746 |
/* Equivalent to CostFunction::Evaluate() in the C++ API.
|
|
Packit |
ea1746 |
*
|
|
Packit |
ea1746 |
* The user may keep private information inside the opaque user_data object.
|
|
Packit |
ea1746 |
* The pointer here is the same one passed in the ceres_add_residual_block().
|
|
Packit |
ea1746 |
*/
|
|
Packit |
ea1746 |
typedef int (*ceres_cost_function_t)(void* user_data,
|
|
Packit |
ea1746 |
double** parameters,
|
|
Packit |
ea1746 |
double* residuals,
|
|
Packit |
ea1746 |
double** jacobians);
|
|
Packit |
ea1746 |
|
|
Packit |
ea1746 |
/* Equivalent to LossFunction::Evaluate() from the C++ API. */
|
|
Packit |
ea1746 |
typedef void (*ceres_loss_function_t)(void* user_data,
|
|
Packit |
ea1746 |
double squared_norm,
|
|
Packit |
ea1746 |
double out[3]);
|
|
Packit |
ea1746 |
|
|
Packit |
ea1746 |
/* Create callback data for Ceres' stock loss functions.
|
|
Packit |
ea1746 |
*
|
|
Packit |
ea1746 |
* Ceres has several loss functions available by default, and these functions
|
|
Packit |
ea1746 |
* expose those to the C API. To use the stock loss functions, call
|
|
Packit |
ea1746 |
* ceres_create_*_loss_data(), which internally creates an instance of one of
|
|
Packit |
ea1746 |
* the stock loss functions (for example ceres::CauchyLoss), and pass the
|
|
Packit |
ea1746 |
* returned "loss_function_data" along with the ceres_stock_loss_function to
|
|
Packit |
ea1746 |
* ceres_add_residual_block().
|
|
Packit |
ea1746 |
*
|
|
Packit |
ea1746 |
* For example:
|
|
Packit |
ea1746 |
*
|
|
Packit |
ea1746 |
* void* cauchy_loss_function_data =
|
|
Packit |
ea1746 |
* ceres_create_cauchy_loss_function_data(1.2, 0.0);
|
|
Packit |
ea1746 |
* ceres_problem_add_residual_block(
|
|
Packit |
ea1746 |
* problem,
|
|
Packit |
ea1746 |
* my_cost_function,
|
|
Packit |
ea1746 |
* my_cost_function_data,
|
|
Packit |
ea1746 |
* ceres_stock_loss_function,
|
|
Packit |
ea1746 |
* cauchy_loss_function_data,
|
|
Packit |
ea1746 |
* 1,
|
|
Packit |
ea1746 |
* 2,
|
|
Packit |
ea1746 |
* parameter_sizes,
|
|
Packit |
ea1746 |
* parameter_pointers);
|
|
Packit |
ea1746 |
* ...
|
|
Packit |
ea1746 |
* ceres_free_stock_loss_function_data(cauchy_loss_function_data);
|
|
Packit |
ea1746 |
*
|
|
Packit |
ea1746 |
* See loss_function.h for the details of each loss function.
|
|
Packit |
ea1746 |
*/
|
|
Packit |
ea1746 |
CERES_EXPORT void* ceres_create_huber_loss_function_data(double a);
|
|
Packit |
ea1746 |
CERES_EXPORT void* ceres_create_softl1_loss_function_data(double a);
|
|
Packit |
ea1746 |
CERES_EXPORT void* ceres_create_cauchy_loss_function_data(double a);
|
|
Packit |
ea1746 |
CERES_EXPORT void* ceres_create_arctan_loss_function_data(double a);
|
|
Packit |
ea1746 |
CERES_EXPORT void* ceres_create_tolerant_loss_function_data(double a, double b);
|
|
Packit |
ea1746 |
|
|
Packit |
ea1746 |
/* Free the given stock loss function data. */
|
|
Packit |
ea1746 |
CERES_EXPORT void ceres_free_stock_loss_function_data(void* loss_function_data);
|
|
Packit |
ea1746 |
|
|
Packit |
ea1746 |
/* This is an implementation of ceres_loss_function_t contained within Ceres
|
|
Packit |
ea1746 |
* itself, intended as a way to access the various stock Ceres loss functions
|
|
Packit |
ea1746 |
* from the C API. This should be passed to ceres_add_residual() below, in
|
|
Packit |
ea1746 |
* combination with a user_data pointer generated by
|
|
Packit |
ea1746 |
* ceres_create_stock_loss_function() above. */
|
|
Packit |
ea1746 |
CERES_EXPORT void ceres_stock_loss_function(void* user_data,
|
|
Packit |
ea1746 |
double squared_norm,
|
|
Packit |
ea1746 |
double out[3]);
|
|
Packit |
ea1746 |
|
|
Packit |
ea1746 |
/* Equivalent to Problem from the C++ API. */
|
|
Packit |
ea1746 |
struct ceres_problem_s;
|
|
Packit |
ea1746 |
typedef struct ceres_problem_s ceres_problem_t;
|
|
Packit |
ea1746 |
|
|
Packit |
ea1746 |
struct ceres_residual_block_id_s;
|
|
Packit |
ea1746 |
typedef struct ceres_residual_block_id_s ceres_residual_block_id_t;
|
|
Packit |
ea1746 |
|
|
Packit |
ea1746 |
/* Create and destroy a problem */
|
|
Packit |
ea1746 |
/* TODO(keir): Add options for the problem. */
|
|
Packit |
ea1746 |
CERES_EXPORT ceres_problem_t* ceres_create_problem();
|
|
Packit |
ea1746 |
CERES_EXPORT void ceres_free_problem(ceres_problem_t* problem);
|
|
Packit |
ea1746 |
|
|
Packit |
ea1746 |
/* Add a residual block. */
|
|
Packit |
ea1746 |
CERES_EXPORT ceres_residual_block_id_t* ceres_problem_add_residual_block(
|
|
Packit |
ea1746 |
ceres_problem_t* problem,
|
|
Packit |
ea1746 |
ceres_cost_function_t cost_function,
|
|
Packit |
ea1746 |
void* cost_function_data,
|
|
Packit |
ea1746 |
ceres_loss_function_t loss_function,
|
|
Packit |
ea1746 |
void* loss_function_data,
|
|
Packit |
ea1746 |
int num_residuals,
|
|
Packit |
ea1746 |
int num_parameter_blocks,
|
|
Packit |
ea1746 |
int* parameter_block_sizes,
|
|
Packit |
ea1746 |
double** parameters);
|
|
Packit |
ea1746 |
|
|
Packit |
ea1746 |
CERES_EXPORT void ceres_solve(ceres_problem_t* problem);
|
|
Packit |
ea1746 |
|
|
Packit |
ea1746 |
/* TODO(keir): Figure out a way to pass a config in. */
|
|
Packit |
ea1746 |
|
|
Packit |
ea1746 |
#ifdef __cplusplus
|
|
Packit |
ea1746 |
}
|
|
Packit |
ea1746 |
#endif
|
|
Packit |
ea1746 |
|
|
Packit |
ea1746 |
#include "ceres/internal/reenable_warnings.h"
|
|
Packit |
ea1746 |
|
|
Packit |
ea1746 |
#endif /* CERES_PUBLIC_C_API_H_ */
|