diff --git a/apps/specular_estimation/src/Ceres.h b/apps/specular_estimation/src/Ceres.h index 391df8444ee1a42a7aa17cfe5f163f5433ba9c88..b89cbe425b01af15d5d49b66103e90cd0f2d4dfa 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!