Skip to content

Instantly share code, notes, and snippets.

View agirault's full-sized avatar
👨‍💻

Alexis Girault agirault

👨‍💻
View GitHub Profile
size_t found = m_FilePath.find_last_of("/\\");
m_FileDir = str.substr(0,found);
m_FileName = str.substr(found+1);
# 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()
@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 )
#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
#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 ),
@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);
//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
//
// 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 :
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;
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)