Skip to content

Commit

Permalink
adding missing files from modules
Browse files Browse the repository at this point in the history
  • Loading branch information
ppiecuch committed Nov 20, 2023
1 parent e0d5278 commit eeeb17e
Show file tree
Hide file tree
Showing 9 changed files with 736 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
## IGL copyleft subdirectory

Functions in the `include/igl/copyleft/` subdirectory are in the
`igl::copyleft::` namespace to indicate that they are under a more aggressive
[copyleft](https://en.wikipedia.org/wiki/Copyleft) than
[MPL2](https://en.wikipedia.org/wiki/Mozilla_Public_License) used for the main
`include/igl` directory and `igl::` namespace. Most notably, this subdirectory
includes code that is under
[GPL](https://en.wikipedia.org/wiki/GNU_General_Public_License).

Typically a company planning on developing software without releasing its
source code will avoid or purchase licenses for such dependencies. If you do
obtain such a license for the dependencies employed here, you are free to use
the libigl functions here as per their MPL2 license.
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
// This file is part of libigl, a simple c++ geometry processing library.
//
// Copyright (C) 2015 Alec Jacobson <alecjacobson@gmail.com>
//
// This Source Code Form is subject to the terms of the Mozilla Public License
// v. 2.0. If a copy of the MPL was not distributed with this file, You can
// obtain one at http://mozilla.org/MPL/2.0/.
#include "assign_scalar.h"

IGL_INLINE void igl::copyleft::cgal::assign_scalar(
const CGAL::Epeck::FT & cgal,
CGAL::Epeck::FT & d)
{
d = cgal;
}

IGL_INLINE void igl::copyleft::cgal::assign_scalar(
const CGAL::Epeck::FT & _cgal,
double & d)
{
// FORCE evaluation of the exact type otherwise interval might be huge.
const CGAL::Epeck::FT cgal = _cgal.exact();
const auto interval = CGAL::to_interval(cgal);
d = interval.first;
do {
const double next = nextafter(d, interval.second);
if (CGAL::abs(cgal-d) < CGAL::abs(cgal-next)) break;
d = next;
} while (d < interval.second);
}

IGL_INLINE void igl::copyleft::cgal::assign_scalar(
const CGAL::Epeck::FT & _cgal,
float& d)
{
// FORCE evaluation of the exact type otherwise interval might be huge.
const CGAL::Epeck::FT cgal = _cgal.exact();
const auto interval = CGAL::to_interval(cgal);
d = interval.first;
do {
const float next = nextafter(d, float(interval.second));
if (CGAL::abs(cgal-d) < CGAL::abs(cgal-next)) break;
d = next;
} while (d < float(interval.second));
}

IGL_INLINE void igl::copyleft::cgal::assign_scalar(
const double & c,
double & d)
{
d = c;
}

IGL_INLINE void igl::copyleft::cgal::assign_scalar(
const float& c,
float& d)
{
d = c;
}

IGL_INLINE void igl::copyleft::cgal::assign_scalar(
const float& c,
double& d)
{
d = c;
}

IGL_INLINE void igl::copyleft::cgal::assign_scalar(
const CGAL::Exact_predicates_exact_constructions_kernel_with_sqrt::FT & cgal,
CGAL::Exact_predicates_exact_constructions_kernel_with_sqrt::FT & d)
{
d = cgal;
}

IGL_INLINE void igl::copyleft::cgal::assign_scalar(
const CGAL::Exact_predicates_exact_constructions_kernel_with_sqrt::FT & cgal,
double & d)
{
const auto interval = CGAL::to_interval(cgal);
d = interval.first;
do {
const double next = nextafter(d, interval.second);
if (CGAL::abs(cgal-d) < CGAL::abs(cgal-next)) break;
d = next;
} while (d < interval.second);
}

IGL_INLINE void igl::copyleft::cgal::assign_scalar(
const CGAL::Exact_predicates_exact_constructions_kernel_with_sqrt::FT & cgal,
float& d)
{
const auto interval = CGAL::to_interval(cgal);
d = interval.first;
do {
const float next = nextafter(d, float(interval.second));
if (CGAL::abs(cgal-d) < CGAL::abs(cgal-next)) break;
d = next;
} while (d < float(interval.second));
}

#ifndef WIN32

IGL_INLINE void igl::copyleft::cgal::assign_scalar(
const CGAL::Simple_cartesian<mpq_class>::FT & cgal,
CGAL::Simple_cartesian<mpq_class>::FT & d)
{
d = cgal;
}

IGL_INLINE void igl::copyleft::cgal::assign_scalar(
const CGAL::Simple_cartesian<mpq_class>::FT & cgal,
double & d)
{
const auto interval = CGAL::to_interval(cgal);
d = interval.first;
do {
const double next = nextafter(d, interval.second);
if (CGAL::abs(cgal-d) < CGAL::abs(cgal-next)) break;
d = next;
} while (d < interval.second);
}

IGL_INLINE void igl::copyleft::cgal::assign_scalar(
const CGAL::Simple_cartesian<mpq_class>::FT & cgal,
float& d)
{
const auto interval = CGAL::to_interval(cgal);
d = interval.first;
do {
const float next = nextafter(d, float(interval.second));
if (CGAL::abs(cgal-d) < CGAL::abs(cgal-next)) break;
d = next;
} while (d < float(interval.second));
}

#endif // WIN32
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
// This file is part of libigl, a simple c++ geometry processing library.
//
// Copyright (C) 2015 Alec Jacobson <alecjacobson@gmail.com>
//
// This Source Code Form is subject to the terms of the Mozilla Public License
// v. 2.0. If a copy of the MPL was not distributed with this file, You can
// obtain one at http://mozilla.org/MPL/2.0/.
#ifndef IGL_COPYLEFT_CGAL_ASSIGN_SCALAR_H
#define IGL_COPYLEFT_CGAL_ASSIGN_SCALAR_H
#include "../../igl_inline.h"
#include <CGAL/Exact_predicates_exact_constructions_kernel.h>
#include <CGAL/Exact_predicates_exact_constructions_kernel_with_sqrt.h>
#ifndef WIN32
#include <CGAL/gmpxx.h>
#endif

namespace igl
{
namespace copyleft
{
namespace cgal
{
// Inputs:
// cgal cgal scalar
// Outputs:
// d output scalar
IGL_INLINE void assign_scalar(
const CGAL::Epeck::FT & cgal,
CGAL::Epeck::FT & d);
IGL_INLINE void assign_scalar(
const CGAL::Epeck::FT & cgal,
double & d);
IGL_INLINE void assign_scalar(
const CGAL::Epeck::FT & cgal,
float& d);
IGL_INLINE void assign_scalar(
const double & c,
double & d);
IGL_INLINE void assign_scalar(
const float& c,
float & d);
IGL_INLINE void assign_scalar(
const float& c,
double& d);

IGL_INLINE void assign_scalar(
const CGAL::Exact_predicates_exact_constructions_kernel_with_sqrt::FT & cgal,
CGAL::Exact_predicates_exact_constructions_kernel_with_sqrt::FT & d);
IGL_INLINE void assign_scalar(
const CGAL::Exact_predicates_exact_constructions_kernel_with_sqrt::FT & cgal,
double & d);
IGL_INLINE void assign_scalar(
const CGAL::Exact_predicates_exact_constructions_kernel_with_sqrt::FT & cgal,
float& d);

#ifndef WIN32
IGL_INLINE void assign_scalar(
const CGAL::Simple_cartesian<mpq_class>::FT & cgal,
CGAL::Simple_cartesian<mpq_class>::FT & d);
IGL_INLINE void assign_scalar(
const CGAL::Simple_cartesian<mpq_class>::FT & cgal,
double & d);
IGL_INLINE void assign_scalar(
const CGAL::Simple_cartesian<mpq_class>::FT & cgal,
float& d);
#endif // WIN32

}
}
}
#ifndef IGL_STATIC_LIBRARY
# include "assign_scalar.cpp"
#endif
#endif
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
// This file is part of libigl, a simple c++ geometry processing library.
//
// Copyright (C) 2017 Alec Jacobson <alecjacobson@gmail.com>
//
// This Source Code Form is subject to the terms of the Mozilla Public License
// v. 2.0. If a copy of the MPL was not distributed with this file, You can
// obtain one at http://mozilla.org/MPL/2.0/.
#include "convex_hull.h"
#include "../../ismember.h"
#include "polyhedron_to_mesh.h"
#include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
#include <CGAL/Polyhedron_3.h>
#include <CGAL/Surface_mesh.h>
#include <CGAL/convex_hull_3.h>
#include <vector>

template <
typename DerivedV,
typename DerivedW,
typename DerivedG>
IGL_INLINE void igl::copyleft::cgal::convex_hull(
const Eigen::MatrixBase<DerivedV> & V,
Eigen::PlainObjectBase<DerivedW> & W,
Eigen::PlainObjectBase<DerivedG> & G)
{
typedef CGAL::Exact_predicates_inexact_constructions_kernel K;
switch(V.cols())
{
case 3:
{
typedef K::Point_3 Point_3;
//typedef CGAL::Delaunay_triangulation_3<K> Delaunay;
//typedef Delaunay::Vertex_handle Vertex_handle;
//typedef CGAL::Surface_mesh<Point_3> Surface_mesh;
typedef CGAL::Polyhedron_3<K> Polyhedron_3;
std::vector<Point_3> points(V.rows());
for(int i = 0;i<V.rows();i++)
{
points[i] = Point_3(V(i,0),V(i,1),V(i,2));
}
Polyhedron_3 poly;
CGAL::convex_hull_3(points.begin(),points.end(),poly);
assert(poly.is_pure_triangle() && "Assuming CGAL outputs a triangle mesh");
polyhedron_to_mesh(poly,W,G);
break;
}
case 2:
{
typedef K::Point_2 Point_2;
std::vector<Point_2> points(V.rows());
std::vector<Point_2> result;
for(int i = 0;i<V.rows();i++)
{
points[i] = Point_2(V(i,0),V(i,1));
}
CGAL::convex_hull_2(points.begin(),points.end(),std::back_inserter(result));
W.resize(result.size(),2);
G.resize(result.size(),2);
for(int i = 0;i<result.size();i++)
{
W(i,0) = result[i].x();
W(i,1) = result[i].y();
G(i,0) = i;
G(i,1) = (i+1)%result.size();
}
break;
}
}
}

template <
typename DerivedV,
typename DerivedF>
IGL_INLINE void igl::copyleft::cgal::convex_hull(
const Eigen::MatrixBase<DerivedV> & V,
Eigen::PlainObjectBase<DerivedF> & F)
{
Eigen::Matrix<typename DerivedV::Scalar, Eigen::Dynamic, Eigen::Dynamic> W;
Eigen::Matrix<typename DerivedF::Scalar, Eigen::Dynamic, Eigen::Dynamic> G;
convex_hull(V,W,G);
// This is a lazy way to reindex into the original mesh
Eigen::Matrix<bool,Eigen::Dynamic,1> I;
Eigen::VectorXi J;
igl::ismember_rows(W,V,I,J);
assert(I.all() && "Should find all W in V");
F.resizeLike(G);
for(int f = 0;f<G.rows();f++)
{
for(int c = 0;c<3;c++)
{
F(f,c) = J(G(f,c));
}
}
}

#ifdef IGL_STATIC_LIBRARY
// Explicit template instantiation
// generated by autoexplicit.sh
template void igl::copyleft::cgal::convex_hull<Eigen::Matrix<double, -1, -1, 0, -1, -1>, Eigen::Matrix<int, -1, -1, 0, -1, -1> >(Eigen::MatrixBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> > const&, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, -1, 0, -1, -1> >&);
// generated by autoexplicit.sh
template void igl::copyleft::cgal::convex_hull<Eigen::Matrix<double, -1, 3, 0, -1, 3>, Eigen::Matrix<int, -1, -1, 0, -1, -1> >(Eigen::MatrixBase<Eigen::Matrix<double, -1, 3, 0, -1, 3> > const&, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, -1, 0, -1, -1> >&);
template void igl::copyleft::cgal::convex_hull<Eigen::Matrix<double, -1, -1, 0, -1, -1>, Eigen::Matrix<double, -1, -1, 0, -1, -1>, Eigen::Matrix<int, -1, -1, 0, -1, -1> >(Eigen::MatrixBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> > const&, Eigen::PlainObjectBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> >&, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, -1, 0, -1, -1> >&);
template void igl::copyleft::cgal::convex_hull<Eigen::Matrix<double, -1, 2, 0, -1, 2>, Eigen::Matrix<double, -1, 2, 0, -1, 2>, Eigen::Matrix<int, -1, -1, 0, -1, -1> >(Eigen::MatrixBase<Eigen::Matrix<double, -1, 2, 0, -1, 2> > const&, Eigen::PlainObjectBase<Eigen::Matrix<double, -1, 2, 0, -1, 2> >&, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, -1, 0, -1, -1> >&);
#endif
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
// This file is part of libigl, a simple c++ geometry processing library.
//
// Copyright (C) 2017 Alec Jacobson <alecjacobson@gmail.com>
//
// This Source Code Form is subject to the terms of the Mozilla Public License
// v. 2.0. If a copy of the MPL was not distributed with this file, You can
// obtain one at http://mozilla.org/MPL/2.0/.
#ifndef IGL_COPYLEFT_CGAL_CONVEX_HULL_H
#define IGL_COPYLEFT_CGAL_CONVEX_HULL_H
#include "../../igl_inline.h"
#include <Eigen/Core>

namespace igl
{
namespace copyleft
{
namespace cgal
{
// Given a set of points (V), compute the convex hull as a triangle mesh (W,G)
//
// Inputs:
// V #V by 3 list of input points
// Outputs:
// W #W by 3 list of convex hull points
// G #G by 3 list of triangle indices into W
template <
typename DerivedV,
typename DerivedW,
typename DerivedG>
IGL_INLINE void convex_hull(
const Eigen::MatrixBase<DerivedV> & V,
Eigen::PlainObjectBase<DerivedW> & W,
Eigen::PlainObjectBase<DerivedG> & G);
// Given a set of points (V), compute the convex hull as a triangle mesh (F)
// over input vertex set (V)
//
// Inputs:
// V #V by 3 list of input points
// Outputs:
// F #F by 3 list of triangle indices into V
//
template <
typename DerivedV,
typename DerivedF>
IGL_INLINE void convex_hull(
const Eigen::MatrixBase<DerivedV> & V,
Eigen::PlainObjectBase<DerivedF> & F);
}
}
}

#ifndef IGL_STATIC_LIBRARY
# include "convex_hull.cpp"
#endif

#endif
Loading

0 comments on commit eeeb17e

Please sign in to comment.