Code Snippets

All code snippets typically require C++11.

Simple 3d Plane RANSAC

This code robustly fits a 3-dimensional plane through a given point cloud using the RANSAC algorithm. The implementation is rather straightforward, yet it can easily be adapted to other fitting problems.

Download

Example usage...

Expected output of this program:

$ g++ -std=c++11 -I/usr/include/eigen3 main.cpp && ./a.out
 
Ground truth plane: n=-0.19245 -0.19245  0.96225 d=-0.7698
Ransac computed plane: n= 0.193933  0.190752 -0.962291 d=0.769292

Simple 2d Marching Squares

  • A simple implementation of the marching squares algorithm in 2d.
  • Depends on the Eigen Library.
  • The function to evaluate the iso surface can be provided by the user.
  • The algorithm yields the triangles of the ‘inside’ part, as well as a number of line segments forming the border.

Download

Simple Numerical Differentiation with Eigen

Download

https://github.com/cfneuhaus/snippets/blob/master/NumJac.h

Usage example:

#include <iostream>
#include <Eigen/Core>
#include "NumJac.h"

Eigen::Vector2d f(const Eigen::Vector3d& x)
{
    Eigen::Vector2d ret;
    ret << x(0)*x(0)+5.0*x(1)+x(2),
           x(0)+7.0*x(2);
    return ret;
}

int main()
{
    const Eigen::Matrix<double,2,3> jac=numJacobian(f,Eigen::Vector3d(1,2,3));
    std::cout << jac << std::endl;
}

Find In File/Source Scripts for Linux Bash

Find in Files (fif):

#!/bin/sh
 
find . \( -name '*' \) -print0 -follow 2>/dev/null | grep -z -Z -v -e '/CVS/' -e '/SCCS/' -e '/\.svn/' -e '/_darcs/' | xargs -0 egrep --color=auto -H -n -s -i -I -e $*

Find in Source (fis):

#!/bin/sh

find . \( -name '*.py' -o -name '*.h' -o -name '*.hxx' -o -name '*.hpp' -o -name '*.hh' -o -name '*.h++' -o -name '*.H' -o -name '*.tlh' -o -name '*.cpp' -o -name '*.cc' -o -name '*.C' -o -name '*.c++' -o -name '*.cxx' -o -name '*.ocl' -o -name '*.inl' -o -name '*.idl' -o -name '*.c' -o -name '*.m' -o -name '*.mm' -o -name '*.M' \) -print -follow 2>/dev/null | grep -v -e '/CVS/' -e '/SCCS/' -e '/\.svn/' -e '/_darcs/' | sed "s/ /\\\ /g" | xargs egrep --color=auto -H -n -s -i -e "$1"