Skip to content

Instantly share code, notes, and snippets.

View agirault's full-sized avatar
👨‍💻

Alexis Girault agirault

👨‍💻
View GitHub Profile
@agirault
agirault / homography_screenreality
Created December 11, 2014 00:40
homography screenReality
//-- Matrix
float modelview[16];
float projection[16];
glGetFloatv (GL_MODELVIEW_MATRIX, modelview);
glGetFloatv (GL_PROJECTION_MATRIX, projection);
cv::Mat modelM(4,4,CV_32FC2,modelview);
cv::Mat projM(4,4,CV_32FC2,projection);
cv::Mat M = projM*modelM;
std::cout<<M<<std::endl;
function [histout,costdata, x] = linesearch(x0,f,g,tolPos,tolGrad,maxit)
% LINESEARCH finds the minimum of an objective function using
% - Steepest descent Algorithm
% - Armijo as a condition for sufficient decrease (could try Wolf?)
% - Step length selection
%
% INPUT:
% - x0 = initial iterate position
% - f = objective function,
% - g = grad f (COLUMN vector)
template <class T, unsigned int VImageDimension >
void VectorImageUtils< T, VImageDimension >::HFieldToDeformationFieldImageFilter(typename DeformationImageType::Pointer itkImage)
{
ImageRegionConstIteratorWithIndex<DeformationImageType> it = ImageRegionConstIteratorWithIndex<DeformationImageType>(
itkImage, itkImage->GetRequestedRegion());
for(it.GoToBegin();!it.IsAtEnd(); ++it)
{
typename DeformationImageType::PixelType displacementValue;
//
// to ITK 3D
//
template <class T, unsigned int VImageDimension >
typename DeformationImageType::Pointer VectorImageUtils< T, VImageDimension >::convertToITK( const VectorImageType3D* im)
{
/* DeformationImageType instead of ITKVectorImage<T,VImageDimension>::Type
**
** We defined DeformationImageType like this in VectorImageUtils.h :
//PolyData
ShapePopulationData * Mesh = new ShapePopulationData;
Mesh->ReadMesh(a_filePath);
m_meshList.push_back(Mesh);
//Polydata Mapper
vtkSmartPointer<vtkPolyDataMapper> mapper = vtkSmartPointer<vtkPolyDataMapper>::New();
#if (VTK_MAJOR_VERSION < 6)
mapper->SetInputConnection(Mesh->GetPolyData()->GetProducerPort());
#else
@agirault
agirault / PhiCubicModel.m
Created March 26, 2014 15:20
minimize phi(alpha) using a cubic model - linesearch with step length selection
M1 = [alpha_prev^2, -alpha_cur^2; -alpha_prev^3, alpha_cur^3];
M2 = [phi_alpha - phi_0 - phiP_0*alpha_cur; phi_prev - phi_0 - phiP_0*alpha_prev];
M = M1 * M2 * 1/(alpha_prev^2 * alpha_cur^2 * (alpha_cur - alpha_prev));
a = M(1);
b = M(2);
alpha = (-b + sqrt(b*b - 3*a*phiP_0))/(3*a);
#ifndef C_SOLVER_STEP_LENGTH_SELECTION_TXX
#define C_SOLVER_STEP_LENGTH_SELECTION_TXX
template < class TState >
CSolverStepLengthSelection< TState>::CSolverStepLengthSelection()
: DefaultMinGradAllowed( 0.0001 ),
DefaultMinDisplacementAllowed( 0.001 ),
DefaultDecreaseConstant( 0.0001 ),
#ifndef C_SOLVER_STEP_LENGTH_SELECTION_H
#define C_SOLVER_STEP_LENGTH_SELECTION_H
#include "CALATKCommon.h"
#include "CObjectiveFunction.h"
#include "CSolver.h"
namespace CALATK
@agirault
agirault / Modif&Errors.cpp
Created March 24, 2014 18:19
compilation errors after creating new solver to be added to the CSolverFactory for calaTK
=> MODIFICATIONS
/* In CSolverFactory.h */
+ #include "CSolverStepLengthSelection.h"
+ typedef CSolverStepLengthSelection< TState > SolverStepLengthSelection;
+ enum NumericSolverType {StepLengthSelection, LineSearchUnconstrained, LineSearchConstrained, IpOpt, LBFGS, NLOPT };
- enum NumericSolverType {LineSearchUnconstrained, LineSearchConstrained, IpOpt, LBFGS, NLOPT };
/* In CSolverFactory.txx */
CSolverFactory< TState >::CreateNewSolver( NumericSolverType solver )
# Compute -G arg for configuring external projects with the same CMake generator:
if(CMAKE_EXTRA_GENERATOR)
set(gen "${CMAKE_EXTRA_GENERATOR} - ${CMAKE_GENERATOR}")
else()
set(gen "${CMAKE_GENERATOR}")
endif()