This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// https://github.com/libigl/libigl/blob/master/include/igl/project_to_line.cpp | |
auto projectionOnSegment = [&](const Vector3 & p, const Vector3 & s, const Vector3 & d){ | |
Real px = p[0], py = p[1], pz = p[2]; | |
Real sx = s[0], sy = s[1], sz = s[2]; | |
Real dx = d[0], dy = d[1], dz = d[2]; | |
Real dms[3], smp[3]; | |
dms[0] = dx-sx; dms[1] = dy-sy; dms[2] = dz-sz; | |
Real v_sqrlen = dms[0]*dms[0] + dms[1]*dms[1] + dms[2]*dms[2]; assert(v_sqrlen != 0); | |
smp[0] = sx-px; smp[1] = sy-py; smp[2] = sz-pz; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Source: https://github.com/samkusin/gamelabs/tree/master/voronoi | |
// with a bug fix (ennetws) | |
/* Usage: | |
using namespace cinekine; | |
... | |
voronoi::Sites sites; | |
for(int i = 0; i < 5; i++) sites.push_back(voronoi::Vertex(rand()*xBound/RAND_MAX,rand()*yBound/RAND_MAX)); | |
... | |
voronoi::Graph graph = voronoi::build(std::move(sites), xBound, yBound); | |
... |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Portable version of powercrust, adapted from https://github.com/timhutton/vtkpowercrust | |
/*=================================================================================================== | |
vtkPowerCrustSurfaceReconstruction algorithm reconstructs surfaces from unorganized point data. | |
Copyright (C) 2014 Arash Akbarinia, Tim Hutton, Bruce Lamond Dieter Pfeffer, Oliver Moss | |
====================================================================================================*/ | |
/* | |
#include "CellArray.h" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
template<class Vector3> | |
std::pair<Vector3, Vector3> best_plane_from_points(const std::vector<Vector3> & c) | |
{ | |
// copy coordinates to matrix in Eigen format | |
size_t num_atoms = c.size(); | |
Eigen::Matrix< Vector3::Scalar, Eigen::Dynamic, Eigen::Dynamic > coord(3, num_atoms); | |
for (size_t i = 0; i < num_atoms; ++i) coord.col(i) = c[i]; | |
// calculate centroid | |
Vector3 centroid(coord.row(0).mean(), coord.row(1).mean(), coord.row(2).mean()); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Install NuGet to run inside VS | |
# Get VC project files | |
$include = @("*.vcxproj","*.sln") | |
$projectFiles = gci . -recurse -force -include $include | |
foreach ($file in $projectFiles) { | |
(get-content $file) | % { $_ -creplace 'Win32', 'x64' } | set-content $file | |
(get-content $file) | % { $_ -creplace '%40QMAKE_SUBSYSTEM_SUFFIX%40', '' } | set-content $file | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 2D Near Isometric Deformations - | |
# code from : http://www.cs.technion.ac.il/~cggc/Upload/Projects/KVFDeformation/index.html | |
QT += core gui opengl | |
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets | |
TEMPLATE = app | |
TARGET = KVF_deform | |
INCLUDEPATH += . ./include |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Adapted from: https://github.com/flexible-collision-library/fcl | |
#include <Eigen/Geometry> | |
namespace Intersect{ | |
typedef double Scalar; | |
typedef Eigen::Vector3d Vector3; | |
const Scalar EPSILON = 1e-5; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
template<typename Scalar, typename Container> | |
inline static Eigen::Matrix<Scalar,-1,-1> toEigenMatrix( const Container& vectors ){ | |
typedef typename Container::value_type VectorType; | |
typedef typename VectorType::value_type Scalar; | |
Eigen::Matrix<Scalar,-1,-1> M(vectors.size(), vectors.front().size()); | |
for(size_t i = 0; i < vectors.size(); i++) | |
for(size_t j = 0; j < vectors.front().size(); j++) | |
M(i,j) = vectors[i][j]; | |
return M; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
template<typename Vector, typename Container> | |
Vector geometric_median( const Container& data, int iterations = 200 ) | |
{ | |
size_t N = data.size(); | |
if(N < 3) return data.front(); | |
size_t dim = data.front().size(); | |
std::vector<Vector> A (2, (data[0] + data[1]) / Scalar(2)); | |
for(int it = 0; it < iterations; it++){ | |
Vector numerator; for(size_t i = 0; i < dim; i++) numerator[i] = 0; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
inline QVector<QColor> rndColors(int count){ | |
QVector<QColor> colors; | |
float currentHue = 0.0; | |
for (int i = 0; i < count; i++){ | |
colors.push_back( QColor::fromHslF(currentHue, 1.0, 0.5) ); | |
currentHue += 0.618033988749895f; | |
currentHue = std::fmod(currentHue, 1.0f); | |
} | |
return colors; | |
} |