From 450e1b040a70ce09ffe72c2c84ba9876692fcfd9 Mon Sep 17 00:00:00 2001 From: tw00275 <tw00275@surrey.ac.uk> Date: Sun, 24 Jun 2018 21:14:16 +0100 Subject: [PATCH] Rearranged Ceres code --- apps/specular_estimation/src/Ceres.h | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/apps/specular_estimation/src/Ceres.h b/apps/specular_estimation/src/Ceres.h index 391df84..b89cbe4 100644 --- a/apps/specular_estimation/src/Ceres.h +++ b/apps/specular_estimation/src/Ceres.h @@ -58,15 +58,13 @@ struct CostFunctor { template <typename T> bool operator()(const T* const SpecularIntensity, const T* const SpecularPower, T* residualValue) const { - double value = function(SpecularIntensity, SpecularPower); - //residual[0] = x[0]; - residualValue[0] = value; + residualValue[0] = function(SpecularIntensity, SpecularPower); return true; } //template <typename T> T function(T* v1, T* v2) { - template <typename T> T function(T* SpecularIntensity, T* SpecularPower) { + template <typename T> T function(T* SpecularIntensity, T* SpecularPower) { //Use GLuint for something //bufferID @@ -133,6 +131,11 @@ struct CostFunctor { return totalResidual; } + // Factory to hide the construction of the CostFunction object from the client code + /*static ceres::CostFunction* Create(SpecularIntensity, SpecularPower, residualValue, residual, residuals, totalResidual, residualImage, calculateResidual, depthProjectionMatrix, depthViewMatrix, width, height, position, horizontalAngle, verticalAngle, FoV, lightInvDir, lightDirections, textureImages, lightNumber, numberOfLights, SpecularIntensityID, SpecularPowerID, programID, ModelMatrixID, ViewMatrixID, DepthBiasID, lightInvDirID, Texture, TextureID, depthTexture, ShadowMapID, vertexbuffer, uvbuffer, normalbuffer, elementbuffer, indices, MatrixID, modelPath) { + return (new ceres::AutoDiffCostFunction<CostFunctor, 1, 1, 1>(new CostFunctor(SpecularIntensity, SpecularPower, residualValue, residual, residuals, totalResidual, residualImage, calculateResidual, depthProjectionMatrix, depthViewMatrix, width, height, position, horizontalAngle, verticalAngle, FoV, lightInvDir, lightDirections, textureImages, lightNumber, numberOfLights, SpecularIntensityID, SpecularPowerID, programID, ModelMatrixID, ViewMatrixID, DepthBiasID, lightInvDirID, Texture, TextureID, depthTexture, ShadowMapID, vertexbuffer, uvbuffer, normalbuffer, elementbuffer, indices, MatrixID, modelPath))); + }*/ + // Access variables in struct //private: @@ -233,7 +236,8 @@ void specularMinimisation(double& SpecularIntensity, double& SpecularPower, doub // Set up the only cost function (also known as residual). This uses auto-differentiation to obtain the derivative (jacobian). // AutoDiffCostFunction<CostFunctor, (Dimensions of Residual), (Dimensions of Variables)> - ceres::CostFunction* cost_function = new AutoDiffCostFunction<CostFunctor, 1, 2>(new CostFunctor(SpecularIntensity, SpecularPower, residualValue, residual, residuals, totalResidual, residualImage, calculateResidual, depthProjectionMatrix, depthViewMatrix, width, height, position, horizontalAngle, verticalAngle, FoV, lightInvDir, lightDirections, textureImages, lightNumber, numberOfLights, SpecularIntensityID, SpecularPowerID, programID, ModelMatrixID, ViewMatrixID, DepthBiasID, lightInvDirID, Texture, TextureID, depthTexture, ShadowMapID, vertexbuffer, uvbuffer, normalbuffer, elementbuffer, indices, MatrixID, modelPath)); + ceres::CostFunction* cost_function = new AutoDiffCostFunction<CostFunctor, 1, 1, 1>(new CostFunctor(SpecularIntensity, SpecularPower, residualValue, residual, residuals, totalResidual, residualImage, calculateResidual, depthProjectionMatrix, depthViewMatrix, width, height, position, horizontalAngle, verticalAngle, FoV, lightInvDir, lightDirections, textureImages, lightNumber, numberOfLights, SpecularIntensityID, SpecularPowerID, programID, ModelMatrixID, ViewMatrixID, DepthBiasID, lightInvDirID, Texture, TextureID, depthTexture, ShadowMapID, vertexbuffer, uvbuffer, normalbuffer, elementbuffer, indices, MatrixID, modelPath)); + //ceres::CostFunction* cost_function = CostFunctor::Create(SpecularIntensity, SpecularPower, residualValue, residual, residuals, totalResidual, residualImage, calculateResidual, depthProjectionMatrix, depthViewMatrix, width, height, position, horizontalAngle, verticalAngle, FoV, lightInvDir, lightDirections, textureImages, lightNumber, numberOfLights, SpecularIntensityID, SpecularPowerID, programID, ModelMatrixID, ViewMatrixID, DepthBiasID, lightInvDirID, Texture, TextureID, depthTexture, ShadowMapID, vertexbuffer, uvbuffer, normalbuffer, elementbuffer, indices, MatrixID, modelPath); problem.AddResidualBlock(cost_function, NULL, &SpecularIntensity, &SpecularPower); // Run the solver! -- GitLab